Decompiled source of Mjolnir v0.5.0

plugins/Mjolnir.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyMetadata("AI_Assisted_Creation", "This assembly was created with the assistance of Generative AI (code generation).")]
[assembly: AssemblyMetadata("AI_Model_Vendor", "Anthropic (Claude)")]
[assembly: AssemblyVersion("0.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 PandheryaMjolnir
{
	[BepInPlugin("pandherya.mjolnir", "Mjolnir (Pandherya)", "0.5.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	[SynchronizationMode(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "pandherya.mjolnir";

		public const string ItemId = "MjolnirPandherya";

		public const string RpcRecall = "pandherya-mjolnir-recall";

		internal static ConfigEntry<bool> AutoEquip;

		internal static ConfigEntry<float> AutoRecallDistance;

		internal static ConfigEntry<float> SpinSpeed;

		internal static ConfigEntry<float> RotX;

		internal static ConfigEntry<float> RotY;

		internal static ConfigEntry<float> RotZ;

		internal static ConfigEntry<Eixo> SpinAxis;

		internal static ManualLogSource Log;

		internal static ConfigurationManagerAttributes Admin()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			return new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			};
		}

		private void Awake()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			AutoEquip = ((BaseUnityPlugin)this).Config.Bind<bool>("Mjolnir", "ReequiparAoVoltar", true, "true = ao voltar, a marreta é equipada de novo automaticamente.");
			AutoRecallDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Mjolnir", "DistanciaVoltaAutomatica", 80f, new ConfigDescription("Se ela passar dessa distância (m) sem acertar nada, volta sozinha.", (AcceptableValueBase)null, new object[1] { Admin() }));
			SpinSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Visual", "VelocidadeGiro", 900f, "Graus por segundo da cambalhota da marreta no ar (negativo = gira para trás).");
			SpinAxis = ((BaseUnityPlugin)this).Config.Bind<Eixo>("Visual", "EixoGiro2", Eixo.Faca, "Faca = cambalhota em pé, como faca arremessada; Vertical = deitada, como shuriken; Frente = como broca; Lateral = modo antigo.");
			RotX = ((BaseUnityPlugin)this).Config.Bind<float>("Visual", "AjusteGiroX", 0f, "Ajuste fino da inclinação do modelo (graus). Muda ao vivo, inclusive com ela voando.");
			RotY = ((BaseUnityPlugin)this).Config.Bind<float>("Visual", "AjusteGiroY", 0f, "Ajuste fino da inclinação do modelo (graus).");
			RotZ = ((BaseUnityPlugin)this).Config.Bind<float>("Visual", "AjusteGiroZ", 0f, "Ajuste fino da inclinação do modelo (graus). Ex.: 180 inverte o lado.");
			ConfigReload.Watch((BaseUnityPlugin)(object)this, ((BaseUnityPlugin)this).Config, "pandherya.mjolnir");
			PrefabManager.OnVanillaPrefabsAvailable += AddItem;
			new Harmony("pandherya.mjolnir").PatchAll(typeof(Plugin).Assembly);
		}

		private void AddItem()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			PrefabManager.OnVanillaPrefabsAvailable -= AddItem;
			try
			{
				ItemConfig val = new ItemConfig
				{
					Name = "Mjölnir",
					Description = "Forjada para um deus, encontrada por você. Arremesse com o ataque secundário: ela esmaga tudo em volta de onde cair e volta para as suas mãos, como se tivesse saudade. Floki diz que ela só volta porque ninguém mais aguenta você.",
					CraftingStation = "forge",
					MinStationLevel = 2
				};
				val.AddRequirement(new RequirementConfig("SledgeIron", 1, 0, false));
				val.AddRequirement(new RequirementConfig("Iron", 10, 5, true));
				val.AddRequirement(new RequirementConfig("TrophyEikthyr", 1, 0, false));
				ItemManager.Instance.AddItem(new CustomItem("MjolnirPandherya", "SledgeIron", val));
				Log.LogInfo((object)"Mjölnir registrado.");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Falha ao criar o Mjölnir: " + ex));
			}
		}

		internal static bool IsMjolnir(ItemData item)
		{
			if ((Object)(object)item?.m_dropPrefab != (Object)null)
			{
				return ((Object)item.m_dropPrefab).name == "MjolnirPandherya";
			}
			return false;
		}
	}
	public enum Eixo
	{
		Faca,
		Vertical,
		Frente,
		Lateral
	}
	internal static class R
	{
		public static readonly FieldRef<Character, Rigidbody> Body = AccessTools.FieldRefAccess<Character, Rigidbody>("m_body");

		public static readonly FieldRef<Character, ZSyncAnimation> ZAnim = AccessTools.FieldRefAccess<Character, ZSyncAnimation>("m_zanim");

		public static readonly FieldRef<Character, CharacterAnimEvent> AnimEvent = AccessTools.FieldRefAccess<Character, CharacterAnimEvent>("m_animEvent");

		public static readonly FieldRef<Character, ZNetView> CharNView = AccessTools.FieldRefAccess<Character, ZNetView>("m_nview");

		public static readonly FieldRef<Humanoid, VisEquipment> VisEq = AccessTools.FieldRefAccess<Humanoid, VisEquipment>("m_visEquipment");

		public static readonly FieldRef<Humanoid, Attack> CurAttack = AccessTools.FieldRefAccess<Humanoid, Attack>("m_currentAttack");

		public static readonly FieldRef<Humanoid, Attack> PrevAttack = AccessTools.FieldRefAccess<Humanoid, Attack>("m_previousAttack");

		public static readonly FieldRef<Humanoid, float> TimeSinceLastAttack = AccessTools.FieldRefAccess<Humanoid, float>("m_timeSinceLastAttack");

		public static readonly FieldRef<Humanoid, float> LastCombatTimer = AccessTools.FieldRefAccess<Humanoid, float>("m_lastCombatTimer");

		public static readonly FieldRef<Attack, ItemData> AttackWeapon = AccessTools.FieldRefAccess<Attack, ItemData>("m_weapon");

		public static readonly FieldRef<ItemDrop, ZNetView> DropNView = AccessTools.FieldRefAccess<ItemDrop, ZNetView>("m_nview");

		public static readonly FieldRef<Projectile, ZNetView> ProjNView = AccessTools.FieldRefAccess<Projectile, ZNetView>("m_nview");

		public static readonly FieldRef<Projectile, Character> ProjOwner = AccessTools.FieldRefAccess<Projectile, Character>("m_owner");

		public static readonly FieldRef<Projectile, ItemData> ProjWeapon = AccessTools.FieldRefAccess<Projectile, ItemData>("m_weapon");

		public static readonly FieldRef<Projectile, HitData> ProjOrigHit = AccessTools.FieldRefAccess<Projectile, HitData>("m_originalHitData");

		public static readonly MethodInfo ClearActionQueue = AccessTools.Method(typeof(Humanoid), "ClearActionQueue", (Type[])null, (Type[])null);

		public static readonly MethodInfo HaveQueuedChain = AccessTools.Method(typeof(Humanoid), "HaveQueuedChain", (Type[])null, (Type[])null);
	}
	[HarmonyPatch(typeof(Humanoid), "StartAttack")]
	internal static class Throw_StartAttack
	{
		private static bool Prefix(Humanoid __instance, ref bool __result, bool secondaryAttack)
		{
			if (!secondaryAttack)
			{
				return true;
			}
			ItemData currentWeapon = __instance.GetCurrentWeapon();
			if (!Plugin.IsMjolnir(currentWeapon))
			{
				return true;
			}
			try
			{
				R.ClearActionQueue.Invoke(__instance, null);
				bool flag = (bool)R.HaveQueuedChain.Invoke(__instance, null);
				if ((((Character)__instance).InAttack() && !flag) || ((Character)__instance).InDodge() || !((Character)__instance).CanMove() || ((Character)__instance).IsKnockedBack() || ((Character)__instance).IsStaggering() || ((Character)__instance).InMinorAction())
				{
					return true;
				}
				GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab("SpearFlint") : null);
				if ((Object)(object)val == (Object)null)
				{
					return true;
				}
				Attack val2 = R.CurAttack.Invoke(__instance);
				if (val2 != null)
				{
					val2.Stop();
					R.PrevAttack.Invoke(__instance) = val2;
					R.CurAttack.Invoke(__instance) = null;
				}
				Attack val3 = val.GetComponent<ItemDrop>().m_itemData.m_shared.m_secondaryAttack.Clone();
				if (!val3.Start(__instance, R.Body.Invoke((Character)(object)__instance), R.ZAnim.Invoke((Character)(object)__instance), R.AnimEvent.Invoke((Character)(object)__instance), R.VisEq.Invoke(__instance), currentWeapon, R.PrevAttack.Invoke(__instance), R.TimeSinceLastAttack.Invoke(__instance), __instance.GetAttackDrawPercentage()))
				{
					__result = false;
					return false;
				}
				R.CurAttack.Invoke(__instance) = val3;
				R.LastCombatTimer.Invoke(__instance) = 0f;
				__result = true;
				return false;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Arremesso falhou, usando ataque normal: " + ex.Message));
				return true;
			}
		}
	}
	[HarmonyPatch(typeof(Attack), "ProjectileAttackTriggered")]
	internal static class Throw_ProjectileTriggered
	{
		private static void Prefix(Attack __instance, ref EffectList __state)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			ItemData val = R.AttackWeapon.Invoke(__instance);
			if (Plugin.IsMjolnir(val))
			{
				__state = val.m_shared.m_triggerEffect;
				val.m_shared.m_triggerEffect = new EffectList();
			}
		}

		private static void Postfix(Attack __instance, EffectList __state)
		{
			//IL_003e: 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)
			//IL_008a: Expected O, but got Unknown
			ItemData val = R.AttackWeapon.Invoke(__instance);
			if (!Plugin.IsMjolnir(val))
			{
				return;
			}
			try
			{
				Projectile val2 = (((Object)(object)val.m_lastProjectile != (Object)null) ? val.m_lastProjectile.GetComponent<Projectile>() : null);
				if ((Object)(object)val2 != (Object)null)
				{
					val2.m_spawnOnHitEffects = new EffectList
					{
						m_effectPrefabs = ((IEnumerable<EffectData>)(((object)val2.m_spawnOnHitEffects?.m_effectPrefabs) ?? ((object)new EffectData[0]))).Concat((IEnumerable<EffectData>)(((object)__state?.m_effectPrefabs) ?? ((object)new EffectData[0]))).ToArray()
					};
					val2.m_aoe = val.m_shared.m_attack.m_attackRayWidth;
				}
			}
			finally
			{
				val.m_shared.m_triggerEffect = __state;
			}
		}
	}
	[HarmonyPatch(typeof(Attack), "FireProjectileBurst")]
	internal static class Throw_Visual
	{
		private static void Postfix(Attack __instance)
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			ItemData val = R.AttackWeapon.Invoke(__instance);
			GameObject val2 = val?.m_lastProjectile;
			if ((Object)(object)val2 == (Object)null || !Plugin.IsMjolnir(val))
			{
				return;
			}
			Transform val3 = val2.transform.Find("spear");
			if ((Object)(object)val3 != (Object)null)
			{
				ZNetScene.instance.Destroy(((Component)val3).gameObject);
			}
			Transform val4 = val.m_dropPrefab.transform.Find("attach");
			if ((Object)(object)val4 == (Object)null)
			{
				return;
			}
			Transform transform = new GameObject("mjolnir_giro").transform;
			transform.SetParent(val2.transform, false);
			Transform transform2 = new GameObject("mjolnir_inclinacao").transform;
			transform2.SetParent(transform, false);
			GameObject val5 = Object.Instantiate<GameObject>(((Component)val4).gameObject, transform2, false);
			Renderer[] componentsInChildren = val5.GetComponentsInChildren<Renderer>();
			if (componentsInChildren.Length != 0)
			{
				Bounds bounds = componentsInChildren[0].bounds;
				Renderer[] array = componentsInChildren;
				foreach (Renderer val6 in array)
				{
					((Bounds)(ref bounds)).Encapsulate(val6.bounds);
				}
				Transform transform3 = val5.transform;
				transform3.position += transform2.position - ((Bounds)(ref bounds)).center;
			}
			Spinny spinny = ((Component)transform).gameObject.AddComponent<Spinny>();
			spinny.Tilt = transform2;
			spinny.Apply();
		}
	}
	internal class Spinny : MonoBehaviour
	{
		internal Transform Tilt;

		internal void Apply()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Tilt == (Object)null))
			{
				Quaternion val = ((Plugin.SpinAxis.Value == Eixo.Faca) ? Quaternion.Euler(0f, 0f, 90f) : Quaternion.identity);
				Tilt.localRotation = val * Quaternion.Euler(Plugin.RotX.Value, Plugin.RotY.Value, Plugin.RotZ.Value);
			}
		}

		private void Update()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			Apply();
			Vector3 val = (Vector3)(Plugin.SpinAxis.Value switch
			{
				Eixo.Frente => Vector3.forward, 
				Eixo.Vertical => Vector3.up, 
				Eixo.Lateral => Vector3.right, 
				_ => Vector3.right, 
			});
			((Component)this).transform.Rotate(val, Plugin.SpinSpeed.Value * Time.deltaTime, (Space)1);
		}
	}
	[HarmonyPatch]
	internal static class Throw_ToolTier
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			yield return AccessTools.Method(typeof(Projectile), "OnHit", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(Projectile), "DoAOE", (Type[])null, (Type[])null);
		}

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			ConstructorInfo ctor = AccessTools.Constructor(typeof(HitData), new Type[0], false);
			MethodInfo fix = AccessTools.Method(typeof(Throw_ToolTier), "RestoreToolTier", (Type[])null, (Type[])null);
			foreach (CodeInstruction ci in instructions)
			{
				yield return ci;
				if (ci.opcode == OpCodes.Newobj && object.Equals(ci.operand, ctor))
				{
					yield return new CodeInstruction(OpCodes.Dup, (object)null);
					yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
					yield return new CodeInstruction(OpCodes.Call, (object)fix);
				}
			}
		}

		private static void RestoreToolTier(HitData hit, Projectile projectile)
		{
			HitData val = R.ProjOrigHit.Invoke(projectile);
			if (val != null && Plugin.IsMjolnir(R.ProjWeapon.Invoke(projectile)))
			{
				hit.m_toolTier = val.m_toolTier;
				hit.m_itemWorldLevel = val.m_itemWorldLevel;
			}
		}
	}
	[HarmonyPatch(typeof(Projectile), "SpawnOnHit")]
	internal static class Recall_SpawnOnHit
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			MethodInfo dropper = AccessTools.Method(typeof(ItemDrop), "DropItem", (Type[])null, (Type[])null);
			MethodInfo recaller = AccessTools.Method(typeof(Recall_SpawnOnHit), "IssueRecall", (Type[])null, (Type[])null);
			bool found = false;
			foreach (CodeInstruction ci in instructions)
			{
				yield return ci;
				if (CodeInstructionExtensions.Calls(ci, dropper))
				{
					found = true;
					yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
					yield return new CodeInstruction(OpCodes.Call, (object)recaller);
				}
			}
			if (!found)
			{
				Plugin.Log.LogWarning((object)"Mjölnir: não achei o DropItem no Projectile.SpawnOnHit — a marreta não vai voltar sozinha.");
			}
		}

		internal static ItemDrop IssueRecall(ItemDrop item, Projectile projectile)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Character val = R.ProjOwner.Invoke(projectile);
				if ((Object)(object)item != (Object)null && Plugin.IsMjolnir(item.m_itemData) && (Object)(object)val != (Object)null)
				{
					ZNetView val2 = R.CharNView.Invoke(val);
					ZNetView val3 = R.DropNView.Invoke(item);
					if ((Object)(object)val2 != (Object)null && (Object)(object)val3 != (Object)null && val3.IsValid())
					{
						val2.InvokeRPC("pandherya-mjolnir-recall", new object[1] { val3.GetZDO().m_uid });
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Volta do Mjölnir falhou: " + ex.Message));
			}
			return item;
		}
	}
	[HarmonyPatch(typeof(Projectile), "LateUpdate")]
	internal static class Recall_FarAway
	{
		private static void Postfix(Projectile __instance)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			ItemData spawnItem = __instance.m_spawnItem;
			if (spawnItem == null || !Plugin.IsMjolnir(spawnItem))
			{
				return;
			}
			ZNetView val = R.ProjNView.Invoke(__instance);
			if ((Object)(object)val == (Object)null || !val.IsValid() || !val.IsOwner())
			{
				return;
			}
			Character val2 = R.ProjOwner.Invoke(__instance);
			Transform val3 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).transform : (((Object)(object)Player.m_localPlayer != (Object)null) ? ((Component)Player.m_localPlayer).transform : null));
			float value = Plugin.AutoRecallDistance.Value;
			if (!((Object)(object)val3 == (Object)null))
			{
				Vector3 val4 = val3.position - ((Component)__instance).transform.position;
				if (!(((Vector3)(ref val4)).sqrMagnitude <= value * value))
				{
					Recall_SpawnOnHit.IssueRecall(ItemDrop.DropItem(spawnItem, 0, ((Component)__instance).transform.position, ((Component)__instance).transform.rotation), __instance);
					__instance.m_spawnItem = null;
					ZNetScene.instance.Destroy(((Component)__instance).gameObject);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Player), "Awake")]
	internal static class Recall_RegisterRpc
	{
		private static void Postfix(Player __instance)
		{
			try
			{
				ZNetView obj = R.CharNView.Invoke((Character)(object)__instance);
				if (obj != null)
				{
					obj.Register<ZDOID>("pandherya-mjolnir-recall", (Action<long, ZDOID>)delegate(long sender, ZDOID id)
					{
						//IL_0006: Unknown result type (might be due to invalid IL or missing references)
						Recall(__instance, id);
					});
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Registro do RPC do Mjölnir falhou: " + ex.Message));
			}
		}

		private static void Recall(Player player, ZDOID id)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = ZNetScene.instance.FindInstance(id);
			ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null);
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			val2.Pickup((Humanoid)(object)player);
			if (!Plugin.AutoEquip.Value || (Object)(object)player != (Object)(object)Player.m_localPlayer)
			{
				return;
			}
			foreach (ItemData allItem in ((Humanoid)player).GetInventory().GetAllItems())
			{
				if (Plugin.IsMjolnir(allItem) && !allItem.m_equipped)
				{
					((Humanoid)player).EquipItem(allItem, true);
					break;
				}
			}
		}
	}
	internal class ConfigReload : MonoBehaviour
	{
		private ConfigFile _cfg;

		private volatile bool _dirty;

		private float _at;

		internal static void Watch(BaseUnityPlugin plugin, ConfigFile cfg, string guid)
		{
			ConfigReload r = ((Component)plugin).gameObject.AddComponent<ConfigReload>();
			r._cfg = cfg;
			try
			{
				FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, guid + ".cfg");
				fileSystemWatcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.LastWrite;
				fileSystemWatcher.Changed += delegate
				{
					r._dirty = true;
				};
				fileSystemWatcher.Created += delegate
				{
					r._dirty = true;
				};
				fileSystemWatcher.Renamed += delegate
				{
					r._dirty = true;
				};
				fileSystemWatcher.EnableRaisingEvents = true;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Sem recarga automática do cfg: " + ex.Message));
			}
		}

		private void Update()
		{
			if (_dirty)
			{
				_dirty = false;
				_at = Time.time + 0.3f;
			}
			if (_at > 0f && Time.time >= _at)
			{
				_at = 0f;
				try
				{
					_cfg.Reload();
					Plugin.Log.LogInfo((object)"Config recarregada.");
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Falha ao recarregar cfg: " + ex.Message));
				}
			}
		}
	}
}