Please disclose if any significant portion of your mod was created 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 ValheimMagnet v1.0.1
plugins/ValheimMagnet.dll
Decompiled 3 days agousing System; using System.Diagnostics; using System.Linq; 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.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("ValheimMagnet")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.1.0")] [assembly: AssemblyInformationalVersion("1.0.1+93c871d389bfcee64ef67603744971f7ef33d876")] [assembly: AssemblyProduct("ValheimMagnet")] [assembly: AssemblyTitle("ValheimMagnet")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.1.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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 ValheimMagnet { [BepInPlugin("valheimmagnet", "ValheimMagnet", "1.0.1")] [BepInProcess("valheim.exe")] public class MagnetPlugin : BaseUnityPlugin { private static ConfigEntry<bool> magnetOn; private static ConfigEntry<float> radius; private ConfigEntry<KeyboardShortcut> toggleKey; private Harmony harmony; private void Awake() { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Expected O, but got Unknown //IL_0075: Unknown result type (might be due to invalid IL or missing references) magnetOn = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Magnet on/off. Saved when toggled with the hotkey."); radius = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Radius", 8f, new ConfigDescription("Auto-pickup radius in metres while the magnet is on. Vanilla is 2.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 25f), Array.Empty<object>())); toggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "ToggleKey", new KeyboardShortcut((KeyCode)46, Array.Empty<KeyCode>()), "Hotkey that toggles the magnet."); harmony = Harmony.CreateAndPatchAll(typeof(MagnetPlugin), ((BaseUnityPlugin)this).Info.Metadata.GUID); } private void OnDestroy() { Harmony obj = harmony; if (obj != null) { obj.UnpatchSelf(); } } private void Update() { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if (ZInput.instance != null && !((Object)(object)localPlayer == (Object)null) && ((Character)localPlayer).TakeInput()) { KeyboardShortcut value = toggleKey.Value; if (ZInput.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey, false) && ((KeyboardShortcut)(ref value)).Modifiers.All((KeyCode m) => ZInput.GetKey(m, false))) { magnetOn.Value = !magnetOn.Value; ((Character)localPlayer).Message((MessageType)2, "Magnet: " + (magnetOn.Value ? $"ON ({radius.Value:0.#} m)" : "OFF"), 0, (Sprite)null, false); } } } [HarmonyPatch(typeof(Player), "AutoPickup")] [HarmonyPrefix] private static void SwapRange(Player __instance, out float? __state) { __state = null; if (magnetOn.Value && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer)) { __state = __instance.m_autoPickupRange; __instance.m_autoPickupRange = Mathf.Max(__instance.m_autoPickupRange, radius.Value); } } [HarmonyPatch(typeof(Player), "AutoPickup")] [HarmonyFinalizer] private static void RestoreRange(Player __instance, float? __state) { if (__state.HasValue) { __instance.m_autoPickupRange = __state.Value; } } } }