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 Gungnir v0.1.1
Gungnir.dll
Decompiled a day agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; 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.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("Gungnir")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+b8028169c78d3d7af4a99a6b976e03b7057a7d09")] [assembly: AssemblyProduct("Gungnir")] [assembly: AssemblyTitle("Gungnir")] [assembly: AssemblyVersion("1.0.0.0")] [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 Gungnir { [BepInPlugin("games.loxley.gungnir", "Gungnir", "0.1.1")] public class GungnirPlugin : BaseUnityPlugin { public const string PluginGUID = "games.loxley.gungnir"; public const string PluginName = "Gungnir"; public const string PluginVersion = "0.1.1"; public static ConfigEntry<float> Delay; public static ConfigEntry<float> OnlyBeyond; public static ConfigEntry<bool> ShowMessage; private void Awake() { //IL_006d: Unknown result type (might be due to invalid IL or missing references) Delay = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Delay", 1.5f, "Seconds after landing before the spear returns."); OnlyBeyond = ((BaseUnityPlugin)this).Config.Bind<float>("General", "OnlyBeyond", 0f, "Only return if the spear landed further than this (m) from you. 0 = always return."); ShowMessage = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowMessage", true, "Show a message when the spear returns."); new Harmony("games.loxley.gungnir").PatchAll(); } } public class ThrowOrigin : MonoBehaviour { public static readonly List<ThrowOrigin> InFlight = new List<ThrowOrigin>(); public Vector2i Slot; public bool WasEquipped; private void OnEnable() { InFlight.Add(this); } private void OnDisable() { InFlight.Remove(this); } } [HarmonyPatch(typeof(Game), "Shutdown")] internal static class RecallOnShutdown { private static void Prefix() { Recall(); } public static void Recall() { //IL_0088: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if (!Object.op_Implicit((Object)(object)localPlayer)) { return; } ThrowOrigin[] array = ThrowOrigin.InFlight.ToArray(); foreach (ThrowOrigin throwOrigin in array) { if (!Object.op_Implicit((Object)(object)throwOrigin)) { continue; } Projectile component = ((Component)throwOrigin).GetComponent<Projectile>(); ItemData val = (Object.op_Implicit((Object)(object)component) ? component.m_spawnItem : null); if (val == null) { continue; } Inventory inventory = ((Humanoid)localPlayer).GetInventory(); if ((inventory.GetItemAt(throwOrigin.Slot.x, throwOrigin.Slot.y) == null) ? inventory.AddItem(val, throwOrigin.Slot) : inventory.AddItem(val)) { component.m_spawnItem = null; ZNetView component2 = ((Component)component).GetComponent<ZNetView>(); if (Object.op_Implicit((Object)(object)component2) && component2.IsValid()) { component2.Destroy(); } else { Object.Destroy((Object)(object)((Component)component).gameObject); } } } } } [HarmonyPatch(typeof(Game), "ContinueLogout")] internal static class RecallOnLogout { private static void Prefix() { RecallOnShutdown.Recall(); } } public class Returning : MonoBehaviour { public Vector2i Slot; public bool WasEquipped; private float m_landed; private ItemDrop m_drop; private ZNetView m_nview; private void Awake() { m_drop = ((Component)this).GetComponent<ItemDrop>(); m_nview = ((Component)this).GetComponent<ZNetView>(); m_landed = Time.time; } private void Update() { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if (!Object.op_Implicit((Object)(object)localPlayer) || !Object.op_Implicit((Object)(object)m_drop) || !Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid() || !m_nview.IsOwner() || Time.time - m_landed < GungnirPlugin.Delay.Value) { return; } float num = Vector3.Distance(((Component)localPlayer).transform.position, ((Component)this).transform.position); if (GungnirPlugin.OnlyBeyond.Value > 0f && num < GungnirPlugin.OnlyBeyond.Value) { ((Behaviour)this).enabled = false; return; } Inventory inventory = ((Humanoid)localPlayer).GetInventory(); ItemData itemData = m_drop.m_itemData; if (!((inventory.GetItemAt(Slot.x, Slot.y) == null) ? inventory.AddItem(itemData, Slot) : inventory.AddItem(itemData))) { ((Behaviour)this).enabled = false; return; } if (WasEquipped) { ((Humanoid)localPlayer).EquipItem(itemData, false); } if (GungnirPlugin.ShowMessage.Value) { ((Character)localPlayer).Message((MessageType)1, "Returned: " + Localization.instance.Localize(itemData.m_shared.m_name), 0, itemData.GetIcon(), false); } m_nview.Destroy(); } } [HarmonyPatch(typeof(Projectile), "Setup")] internal static class RememberOrigin { private static void Postfix(Projectile __instance, Character owner, ItemData item) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) if (__instance.m_spawnItem != null && item != null && !((Object)(object)owner != (Object)(object)Player.m_localPlayer)) { ThrowOrigin throwOrigin = ((Component)__instance).gameObject.AddComponent<ThrowOrigin>(); throwOrigin.Slot = item.m_gridPos; throwOrigin.WasEquipped = item.m_equipped; } } } [HarmonyPatch(typeof(Projectile), "SpawnOnHit")] internal static class TagDrop { public static Projectile Current; private static void Prefix(Projectile __instance) { Current = __instance; } private static void Postfix() { Current = null; } } [HarmonyPatch(typeof(ItemDrop), "DropItem", new Type[] { typeof(ItemData), typeof(int), typeof(Vector3), typeof(Quaternion) })] internal static class AttachReturn { public static readonly int OwnerHash = StringExtensionMethods.GetStableHashCode("Gungnir_Owner"); public static readonly int SlotXHash = StringExtensionMethods.GetStableHashCode("Gungnir_SlotX"); public static readonly int SlotYHash = StringExtensionMethods.GetStableHashCode("Gungnir_SlotY"); public static readonly int EquippedHash = StringExtensionMethods.GetStableHashCode("Gungnir_Equipped"); private static void Postfix(ItemData item, ItemDrop __result) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) Projectile current = TagDrop.Current; if (!Object.op_Implicit((Object)(object)current) || !Object.op_Implicit((Object)(object)__result) || item != current.m_spawnItem) { return; } ThrowOrigin component = ((Component)current).GetComponent<ThrowOrigin>(); if (Object.op_Implicit((Object)(object)component)) { Returning returning = ((Component)__result).gameObject.AddComponent<Returning>(); returning.Slot = component.Slot; returning.WasEquipped = component.WasEquipped; ZNetView component2 = ((Component)__result).GetComponent<ZNetView>(); if (Object.op_Implicit((Object)(object)component2) && component2.IsValid()) { ZDO zDO = component2.GetZDO(); zDO.Set(OwnerHash, Game.instance.GetPlayerProfile().GetPlayerID()); zDO.Set(SlotXHash, component.Slot.x, false); zDO.Set(SlotYHash, component.Slot.y, false); zDO.Set(EquippedHash, component.WasEquipped); } } } } [HarmonyPatch(typeof(ItemDrop), "Awake")] internal static class ReattachOnLoad { private static void Postfix(ItemDrop __instance) { //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<Returning>())) { return; } ZNetView component = ((Component)__instance).GetComponent<ZNetView>(); if (Object.op_Implicit((Object)(object)component) && component.IsValid()) { ZDO zDO = component.GetZDO(); long num = zDO.GetLong(AttachReturn.OwnerHash, 0L); if (num != 0L && !((Object)(object)Game.instance == (Object)null) && num == Game.instance.GetPlayerProfile().GetPlayerID()) { Returning returning = ((Component)__instance).gameObject.AddComponent<Returning>(); returning.Slot = new Vector2i(zDO.GetInt(AttachReturn.SlotXHash, 0), zDO.GetInt(AttachReturn.SlotYHash, 0)); returning.WasEquipped = zDO.GetBool(AttachReturn.EquippedHash, false); } } } } }