Please disclose if your mod was created primarily using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of ValheimHotKeys v1.0.0
ValheimHotKeys.dll
Decompiled 2 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")] [assembly: AssemblyCompany("ValheimHotKeys")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyDescription("Configurable hotkeys for various Valheim actions.")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+71ea656b376d5dbfc6222a8ad93e441a71271761")] [assembly: AssemblyProduct("ValheimHotKeys")] [assembly: AssemblyTitle("ValheimHotKeys")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ValheimHotKeys { [HarmonyPatch] public static class HotKeyPatches { [HarmonyPatch(typeof(Hud), "Update")] [HarmonyPostfix] public static void Hud_Update_Postfix(Hud __instance) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) KeyboardShortcut value = Plugin.ToggleHUDConfig.Value; if (((KeyboardShortcut)(ref value)).IsDown() && (Object)(object)__instance.m_rootObject != (Object)null) { bool activeSelf = __instance.m_rootObject.activeSelf; __instance.m_rootObject.SetActive(!activeSelf); } } [HarmonyPatch(typeof(Player), "Update")] [HarmonyPostfix] public static void Player_Update_Postfix(Player __instance) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || !(bool)AccessTools.Method(typeof(Player), "TakeInput", (Type[])null, (Type[])null).Invoke(__instance, null)) { return; } for (int i = 0; i < 8; i++) { if (InputHelpers.IsDownPermissive(Plugin.HotbarConfigs[i].Value)) { __instance.UseHotbarItem(i + 1); return; } } for (int j = 0; j < Plugin.CustomItemBindings.Count; j++) { Plugin.ItemBinding value = Plugin.CustomItemBindings[j].Value; if (!InputHelpers.IsDownPermissive(value.Shortcut)) { continue; } string itemName = value.ItemName; if (string.IsNullOrEmpty(itemName)) { continue; } Inventory inventory = ((Humanoid)__instance).GetInventory(); List<ItemData> allItems = inventory.GetAllItems(); string searchName = itemName.ToLower(); List<ItemData> list = allItems.FindAll((ItemData iData) => Localization.instance.Localize(iData.m_shared.m_name).ToLower().Contains(searchName) || iData.m_shared.m_name.ToLower().Contains(searchName)); if (list.Count > 0) { ItemData val = list[0]; if (list.Count > 1) { int num = list.FindIndex((ItemData m) => m.m_equipped); if (num != -1) { val = list[(num + 1) % list.Count]; } } ((Humanoid)__instance).UseItem(inventory, val, true); break; } ZLog.LogWarning((object)("[ValheimHotKeys] No item matching '" + itemName + "' found in inventory.")); } } } public static class InputHelpers { public static bool IsDownPermissive(KeyboardShortcut shortcut) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Invalid comparison between Unknown and I4 //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) if ((int)((KeyboardShortcut)(ref shortcut)).MainKey == 0) { return false; } if (!Input.GetKeyDown(((KeyboardShortcut)(ref shortcut)).MainKey)) { return false; } foreach (KeyCode modifier in ((KeyboardShortcut)(ref shortcut)).Modifiers) { if (!Input.GetKey(modifier)) { return false; } } return true; } } [BepInPlugin("com.malafein.valheimhotkeys", "Valheim HotKeys", "1.0.0")] public class Plugin : BaseUnityPlugin { public class ItemBinding { public string ItemName = ""; public KeyboardShortcut Shortcut = KeyboardShortcut.Empty; public string Serialize() { if (string.IsNullOrEmpty(ItemName)) { return ""; } return ItemName + "|" + ((KeyboardShortcut)(ref Shortcut)).Serialize(); } public static ItemBinding Deserialize(string str) { //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) ItemBinding itemBinding = new ItemBinding(); if (string.IsNullOrEmpty(str)) { return itemBinding; } int num = str.LastIndexOf('|'); if (num == -1) { itemBinding.ItemName = str; return itemBinding; } itemBinding.ItemName = str.Substring(0, num); string text = str.Substring(num + 1); try { itemBinding.Shortcut = KeyboardShortcut.Deserialize(text); } catch { itemBinding.Shortcut = KeyboardShortcut.Empty; } return itemBinding; } } public class ConfigurationManagerAttributes { public Action<ConfigEntryBase> CustomDrawer; public bool? ShowMultilineText; public string DispName; public int? Order; public bool? HideDefaultButton; public bool? HideSettingName; } public const string ModGUID = "com.malafein.valheimhotkeys"; public const string ModName = "Valheim HotKeys"; public const string ModVersion = "1.0.0"; public static ConfigEntry<KeyboardShortcut> ToggleHUDConfig; public static ConfigEntry<KeyboardShortcut>[] HotbarConfigs = new ConfigEntry<KeyboardShortcut>[8]; public static List<ConfigEntry<ItemBinding>> CustomItemBindings = new List<ConfigEntry<ItemBinding>>(); private readonly Harmony harmony = new Harmony("com.malafein.valheimhotkeys"); private static ConfigEntryBase _waitingEntry; private static int _activationFrame = -1; private static int _forbiddenFrame = -1; private void Awake() { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Expected O, but got Unknown //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) TomlTypeConverter.AddConverter(typeof(ItemBinding), new TypeConverter { ConvertToObject = (string str, Type type) => ItemBinding.Deserialize(str), ConvertToString = (object obj, Type type) => ((ItemBinding)obj).Serialize() }); ToggleHUDConfig = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "ToggleHUD", new KeyboardShortcut((KeyCode)284, Array.Empty<KeyCode>()), "Hotkey to toggle the HUD visibility."); for (int i = 0; i < 8; i++) { int num = i + 1; HotbarConfigs[i] = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotbar", $"Slot{num}", new KeyboardShortcut((KeyCode)0, Array.Empty<KeyCode>()), $"Hotkey for hotbar slot {num}."); } for (int j = 0; j < 8; j++) { int num2 = j + 1; ConfigurationManagerAttributes configurationManagerAttributes = new ConfigurationManagerAttributes { CustomDrawer = DrawItemBindingElement, HideDefaultButton = false }; ItemBinding itemBinding = new ItemBinding(); switch (j) { case 0: itemBinding.ItemName = "Healing Mead"; itemBinding.Shortcut = new KeyboardShortcut((KeyCode)326, Array.Empty<KeyCode>()); break; case 1: itemBinding.ItemName = "Arrow"; itemBinding.Shortcut = new KeyboardShortcut((KeyCode)327, Array.Empty<KeyCode>()); break; } CustomItemBindings.Add(((BaseUnityPlugin)this).Config.Bind<ItemBinding>("Custom Item Bindings", $"Slot {num2}", itemBinding, new ConfigDescription($"Custom item binding for slot {num2}.", (AcceptableValueBase)null, new object[1] { configurationManagerAttributes }))); } ((BaseUnityPlugin)this).Logger.LogInfo((object)"Valheim HotKeys 1.0.0 is loading..."); harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Valheim HotKeys loaded!"); } private void DrawItemBindingElement(ConfigEntryBase entry) { //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_03a1: Unknown result type (might be due to invalid IL or missing references) //IL_03a6: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Invalid comparison between Unknown and I4 //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Invalid comparison between Unknown and I4 //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Invalid comparison between Unknown and I4 //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Invalid comparison between Unknown and I4 //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Invalid comparison between Unknown and I4 //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Invalid comparison between Unknown and I4 //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Invalid comparison between Unknown and I4 //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_0232: Invalid comparison between Unknown and I4 //IL_0225: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Unknown result type (might be due to invalid IL or missing references) //IL_0248: Invalid comparison between Unknown and I4 //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Invalid comparison between Unknown and I4 //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Invalid comparison between Unknown and I4 //IL_0277: Unknown result type (might be due to invalid IL or missing references) //IL_027e: Invalid comparison between Unknown and I4 //IL_0280: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Invalid comparison between Unknown and I4 //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_0290: Invalid comparison between Unknown and I4 //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Invalid comparison between Unknown and I4 //IL_0325: Unknown result type (might be due to invalid IL or missing references) //IL_032e: Unknown result type (might be due to invalid IL or missing references) //IL_0333: Unknown result type (might be due to invalid IL or missing references) //IL_029b: Unknown result type (might be due to invalid IL or missing references) //IL_02a2: Invalid comparison between Unknown and I4 //IL_02a4: Unknown result type (might be due to invalid IL or missing references) //IL_02ab: Invalid comparison between Unknown and I4 ConfigEntry<ItemBinding> val = (ConfigEntry<ItemBinding>)(object)entry; ItemBinding value = val.Value; GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>()); string text = GUILayout.TextField(value.ItemName, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) }); if (text != value.ItemName) { val.Value = new ItemBinding { ItemName = text, Shortcut = value.Shortcut }; } GUILayout.Space(10f); bool flag = _waitingEntry == entry; GUI.enabled = !flag; string text2 = (flag ? "Press any key..." : ((object)(KeyboardShortcut)(ref value.Shortcut)).ToString()); if (!flag && (string.IsNullOrEmpty(text2) || text2 == "None")) { text2 = "Click to bind"; } if (GUILayout.Button(text2, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(150f) })) { _waitingEntry = entry; _activationFrame = Time.frameCount; } GUI.enabled = true; if (flag) { if (GUILayout.Button("Cancel", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) })) { _waitingEntry = null; _forbiddenFrame = Time.frameCount; Event.current.Use(); } else { Event current = Event.current; if (Time.frameCount > _activationFrame && ((int)current.type == 4 || (int)current.type == 0 || (int)current.type == 12) && ((int)current.type == 12 || ((int)current.type != 1 && (int)current.type != 3 && (int)current.type != 6))) { KeyCode val2 = (KeyCode)0; if ((int)current.keyCode > 0) { val2 = current.keyCode; } else if (current.button >= 0 && current.button <= 6) { val2 = (KeyCode)(323 + current.button); } if ((int)val2 != 0 && (int)val2 != 323) { if ((int)val2 == 27) { _waitingEntry = null; current.Use(); } else if ((int)val2 != 306 && (int)val2 != 305 && (int)val2 != 304 && (int)val2 != 303 && (int)val2 != 308 && (int)val2 != 307 && (int)val2 != 310 && (int)val2 != 309) { List<KeyCode> list = new List<KeyCode>(); if (current.control) { list.Add((KeyCode)306); } if (current.shift) { list.Add((KeyCode)304); } if (current.alt) { list.Add((KeyCode)308); } val.Value = new ItemBinding { ItemName = value.ItemName, Shortcut = new KeyboardShortcut(val2, list.ToArray()) }; _waitingEntry = null; current.Use(); } } } } } else if (GUILayout.Button("Clear", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) }) && Time.frameCount != _forbiddenFrame) { val.Value = new ItemBinding { ItemName = "", Shortcut = KeyboardShortcut.Empty }; Event.current.Use(); } GUILayout.EndHorizontal(); } } }