Decompiled source of HunterDropsGun v1.0.6

HunterDropsGun.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using HunterDropsGun.Patches;
using Photon.Pun;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("HunterDropsGun")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HunterDropsGun")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b0ccb596-270d-4d5e-8f4a-7bef5e4d4199")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HunterDropsGun
{
	[BepInPlugin("DougHRito.HunterDropsGun", "Hunter Drops Gun", "1.0.0.0")]
	public class HunterDropsGunBase : BaseUnityPlugin
	{
		private const string modGUID = "DougHRito.HunterDropsGun";

		private const string modName = "Hunter Drops Gun";

		private const string modVersion = "1.0.0.0";

		private const string DependencyGUID = "DougHRito-HunterGun-1.0.2";

		private readonly Harmony harmony = new Harmony("DougHRito.HunterDropsGun");

		public ConfigEntry<bool> _HunterGunInShop;

		public ConfigEntry<bool> _OnlyDropFromBerserkHunter;

		public ConfigEntry<int> _DropRate;

		public static HunterDropsGunBase Instance;

		public GameObject myPrefab;

		internal ManualLogSource mls;

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			if ((Object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("DougHRito.HunterDropsGun");
			mls.LogInfo((object)"The Dougin lives!");
			_HunterGunInShop = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "HunterGunInShop", true, "true = The Huntsman's rifle will appear in the shop to buy.");
			_OnlyDropFromBerserkHunter = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "OnlyDropFromBerserkHunter", false, "true = The Huntsman's rifle will only drop from a berserk hunter from the BerserkerEnemies mod, if you do not have this mod installed this will do nothing.");
			_DropRate = ((BaseUnityPlugin)this).Config.Bind<int>("General", "DropRate", 100, new ConfigDescription("Set the % chance that the rifle will drop from the Huntsman when he dies", (AcceptableValueBase)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			harmony.PatchAll(typeof(HunterDropsGunBase));
			harmony.PatchAll(typeof(EnemyParentPatch));
			harmony.PatchAll(typeof(ShopManagerPatches));
			((MonoBehaviour)this).StartCoroutine(FindGunPrefabAfterREPOLibLoads());
		}

		private IEnumerator FindGunPrefabAfterREPOLibLoads()
		{
			while ((Object)(object)myPrefab == (Object)null)
			{
				GameObject found = ((IEnumerable<GameObject>)Resources.FindObjectsOfTypeAll<GameObject>()).FirstOrDefault((Func<GameObject, bool>)((GameObject go) => ((Object)go).name == "Gun Hunter"));
				if ((Object)(object)found != (Object)null)
				{
					myPrefab = found;
					mls.LogInfo((object)"Found Gun Hunter prefab already loaded by REPOLib.");
					break;
				}
				yield return (object)new WaitForSeconds(1f);
			}
		}
	}
}
namespace HunterDropsGun.Patches
{
	[HarmonyPatch(typeof(EnemyParent))]
	internal class EnemyParentPatch
	{
		[HarmonyPatch("Despawn")]
		[HarmonyPostfix]
		private static void gunDropPatch(ref string ___enemyName, ref Enemy ___Enemy, ref float ___DespawnedTimer)
		{
			if (!(___enemyName == "Huntsman") || !(___DespawnedTimer > 310f))
			{
				return;
			}
			if (HunterDropsGunBase.Instance._OnlyDropFromBerserkHunter.Value)
			{
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				Assembly assembly = assemblies.FirstOrDefault((Assembly asm) => asm.GetName().Name == "BerserkerEnemies");
				if (assembly != null)
				{
					Type type = assembly.GetType("BerserkerController");
					if (!(type != null))
					{
						return;
					}
					Component componentInParent = ((Component)___Enemy).GetComponentInParent(type);
					if (!((Object)(object)componentInParent != (Object)null))
					{
						return;
					}
					FieldInfo field = type.GetField("isBerserkerFlag");
					bool flag = default(bool);
					int num;
					if (field != null)
					{
						object value = field.GetValue(componentInParent);
						if (value is bool)
						{
							flag = (bool)value;
							num = 1;
						}
						else
						{
							num = 0;
						}
					}
					else
					{
						num = 0;
					}
					if (((uint)num & (flag ? 1u : 0u)) != 0)
					{
						Debug.Log((object)flag);
						if (flag)
						{
							SpawnHuntsmansRifle(___Enemy);
						}
					}
				}
				else
				{
					Debug.LogWarning((object)"BerserkerEnemies mod not detected, did you forget to change the config? The rifle will currently drop from the Huntsman, if you want this off then you can disable the mod :)");
					SpawnHuntsmansRifle(___Enemy);
				}
			}
			else
			{
				SpawnHuntsmansRifle(___Enemy);
			}
		}

		public static void SpawnHuntsmansRifle(Enemy ___Enemy)
		{
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			int num = Random.Range(1, 101);
			if (num > HunterDropsGunBase.Instance._DropRate.Value)
			{
				return;
			}
			Transform val = ___Enemy.CustomValuableSpawnTransform;
			if ((Object)(object)val == (Object)null)
			{
				val = ___Enemy.CenterTransform;
			}
			if (!SemiFunc.IsMultiplayer())
			{
				if ((Object)(object)HunterDropsGunBase.Instance.myPrefab != (Object)null)
				{
					Object.Instantiate<GameObject>(HunterDropsGunBase.Instance.myPrefab, val.position, Quaternion.identity);
				}
				else
				{
					Debug.LogWarning((object)"Gun prefab not loaded — skipping drop.");
				}
			}
			else
			{
				PhotonNetwork.InstantiateRoomObject("Items/Gun Hunter", val.position, Quaternion.identity, (byte)0, (object[])null);
			}
		}
	}
	[HarmonyPatch(typeof(ShopManager))]
	public static class ShopManagerPatches
	{
		[HarmonyPatch("GetAllItemsFromStatsManager")]
		[HarmonyPostfix]
		private static void ShopManagerStartPrefix(ref List<Item> ___potentialItems)
		{
			if (!HunterDropsGunBase.Instance._HunterGunInShop.Value)
			{
				___potentialItems.RemoveAll((Item obj) => ((Object)obj).name == "Gun Hunter");
			}
		}
	}
}