Decompiled source of LootMania v1.0.0

LootMania.dll

Decompiled 11 months ago
using System;
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 LootMania.Component;
using LootMania.Patches;
using Unity.Netcode;
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("LootMania")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LootMania")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ce02e902-d269-45a5-8803-912b4e01b23b")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LootMania
{
	[BepInPlugin("Eltyo.LootMania", "LootMania", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "Eltyo.LootMania";

		private const string modName = "LootMania";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("Eltyo.LootMania");

		public static Plugin Instance;

		public static ConfigEntry<string> possibleItems;

		public static ManualLogSource logger;

		public static List<EnemyType> enemies;

		public static List<Item> items;

		private void Awake()
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			logger = Logger.CreateLogSource("Eltyo.LootMania");
			logger.LogInfo((object)"LootMania initiated!");
			harmony.PatchAll(typeof(Plugin));
			harmony.PatchAll(typeof(StartOfRoundPatch));
			harmony.PatchAll(typeof(RoundManagerPatch));
			MethodInfo methodInfo = AccessTools.Method(typeof(EnemyAI), "KillEnemyOnOwnerClient", (Type[])null, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(KillPatch), "patchKillEnemyOnOwnerClient", (Type[])null, (Type[])null);
			harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private void OnDestroy()
		{
			logger.LogInfo((object)"LootMania destroyed.");
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}

		public static string RemoveWhitespaces(string source)
		{
			return string.Join("", source.Split((string[]?)null, StringSplitOptions.RemoveEmptyEntries));
		}

		public static List<string> GetMobItems(string mobName)
		{
			foreach (ConfigDefinition key in ((BaseUnityPlugin)Instance).Config.Keys)
			{
				if (RemoveWhitespaces(key.Key.ToUpper()).Equals(mobName))
				{
					return ((BaseUnityPlugin)Instance).Config[key].BoxedValue.ToString().ToUpper().Split(new char[1] { ',' })
						.ToList();
				}
			}
			logger.LogInfo((object)"No mob found!");
			return new List<string>();
		}
	}
}
namespace LootMania.Patches
{
	internal class KillPatch
	{
		public class ItemToDrop
		{
			public int scrapValue;

			public Item scrapItem;

			public ItemToDrop(Item item, int value)
			{
				scrapValue = value;
				scrapItem = item;
			}
		}

		public static void patchKillEnemyOnOwnerClient(ref EnemyAI __instance, bool overrideDestroy = false)
		{
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: 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)
			if (!((Object)(object)((Component)__instance).gameObject.GetComponent<DroppedItemEnemy>() == (Object)null) || !((NetworkBehaviour)__instance).IsOwner)
			{
				return;
			}
			if (__instance is HoarderBugAI)
			{
				HoarderBugAI val = (HoarderBugAI)__instance;
				if (val.heldItem != null)
				{
					GrabbableObject itemGrabbableObject = val.heldItem.itemGrabbableObject;
					val.DropItemServerRpc(NetworkObjectReference.op_Implicit(((Component)itemGrabbableObject).GetComponent<NetworkObject>()), ((Component)__instance).transform.position, false);
				}
			}
			RoundManager instance = RoundManager.Instance;
			Plugin.logger.LogInfo((object)("Killed Mob Name: " + __instance.enemyType.enemyName.ToUpper()));
			Vector3 position = ((Component)__instance).transform.position + Vector3.up * 0.6f;
			List<ItemToDrop> itemsForMob = GetItemsForMob(Plugin.RemoveWhitespaces(__instance.enemyType.enemyName.ToUpper()));
			for (int i = 0; i < itemsForMob.Count; i++)
			{
				if ((Object)(object)itemsForMob[i].scrapItem.spawnPrefab != (Object)null)
				{
					DropItem(position, itemsForMob[i].scrapItem.spawnPrefab, itemsForMob[i].scrapValue, instance);
					continue;
				}
				Plugin.logger.LogWarning((object)"Item drop does not exist running default drop.");
				DropItem(position, instance.currentLevel.spawnableScrap[Random.Range(0, instance.currentLevel.spawnableScrap.Count)].spawnableItem.spawnPrefab, Random.Range(50, 150), instance);
			}
			((Component)__instance).gameObject.AddComponent<DroppedItemEnemy>();
		}

		private static void DropItem(Vector3 position, GameObject itemPrefab, int scrapValue, RoundManager instance)
		{
			//IL_0008: 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_0031: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			Transform spawnedScrapContainer = instance.spawnedScrapContainer;
			position += new Vector3(Random.Range(-0.8f, 0.8f), 0f, Random.Range(-0.8f, 0.8f));
			GameObject val = Object.Instantiate<GameObject>(itemPrefab, position, Quaternion.identity, spawnedScrapContainer);
			GrabbableObject component = val.GetComponent<GrabbableObject>();
			((Component)component).transform.rotation = Quaternion.Euler(component.itemProperties.restingRotation);
			component.fallTime = 0f;
			int num = scrapValue;
			if (instance.scrapValueMultiplier > 1f)
			{
				num = (int)((float)num * instance.scrapValueMultiplier);
			}
			component.itemProperties.isScrap = true;
			component.SetScrapValue(num);
			NetworkObject component2 = val.GetComponent<NetworkObject>();
			component2.Spawn(false);
			instance.SyncScrapValuesClientRpc(new List<NetworkObjectReference> { NetworkObjectReference.op_Implicit(component2) }.ToArray(), new List<int> { num }.ToArray());
			Plugin.logger.LogWarning((object)"Item drop synced.");
		}

		private static List<ItemToDrop> GetItemsForMob(string mobName)
		{
			List<ItemToDrop> list = new List<ItemToDrop>();
			List<string> mobItems = Plugin.GetMobItems(mobName);
			if (mobItems.Any() && mobItems != null)
			{
				for (int i = 0; i < mobItems.Count / 6; i++)
				{
					int num = 6 * i;
					string text = Plugin.RemoveWhitespaces(mobItems[num]);
					int num2 = int.Parse(Plugin.RemoveWhitespaces(mobItems[num + 1]));
					int num3 = int.Parse(Plugin.RemoveWhitespaces(mobItems[num + 2]));
					int num4 = int.Parse(Plugin.RemoveWhitespaces(mobItems[num + 3]));
					int num5 = int.Parse(Plugin.RemoveWhitespaces(mobItems[num + 4]));
					int num6 = int.Parse(Plugin.RemoveWhitespaces(mobItems[num + 5]));
					int num7 = Random.Range(1, 1000);
					if (num7 >= num6)
					{
						continue;
					}
					foreach (Item item in Plugin.items)
					{
						if (Plugin.RemoveWhitespaces(item.itemName.ToUpper()).Equals(Plugin.RemoveWhitespaces(text.ToUpper())))
						{
							num7 = 1;
							if (num2 < num3 && num2 > 0)
							{
								num7 = Random.Range(num2, num3);
							}
							for (int j = 0; j < num7; j++)
							{
								list.Add(new ItemToDrop(item, Random.Range(num4, num5)));
								Plugin.logger.LogInfo((object)"Item Added!");
							}
						}
					}
				}
			}
			else
			{
				Plugin.logger.LogInfo((object)"No Config Items Found For Mob!");
			}
			return list;
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void patchStart()
		{
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Expected O, but got Unknown
			Plugin.enemies = (from EnemyType e in Resources.FindObjectsOfTypeAll(typeof(EnemyType))
				where (Object)(object)e != (Object)null
				select e).ToList();
			Plugin.items = (from Item i in Resources.FindObjectsOfTypeAll(typeof(Item))
				where (Object)(object)i != (Object)null
				select i).ToList();
			List<string> list = Plugin.items.ConvertAll((Item i) => i.itemName);
			list.Sort();
			Plugin.possibleItems = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<string>("General", "ItemNames", "Notice The List Please", string.Join("|", list) ?? "");
			foreach (Item item in Plugin.items)
			{
				Plugin.logger.LogInfo((object)("ItemName: " + item.itemName));
			}
			foreach (EnemyType enemy in Plugin.enemies)
			{
				Plugin.logger.LogInfo((object)("MobName: " + enemy.enemyName));
				if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", enemy.enemyName)))
				{
					ConfigEntry<string> val = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<string>("Mobs", enemy.enemyName, "Old phone, 1, 3, 50, 80, 1000, Flask, 1, 1, 200, 400, 100", "The First setting is the item name.The Second setting is the minimum item drop amount.The Third setting is the max item drop amount.The Fourth setting is the minimum scrap value amount.The Fifth setting is the maximum scrap value amount.The Last setting is the chance of it dropping from 1-1000.You can add more items like all config entries do,up to however many you want(each has 2 item drops default).");
				}
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void patchStart()
		{
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Expected O, but got Unknown
			Plugin.enemies = (from EnemyType e in Resources.FindObjectsOfTypeAll(typeof(EnemyType))
				where (Object)(object)e != (Object)null
				select e).ToList();
			Plugin.items = (from Item i in Resources.FindObjectsOfTypeAll(typeof(Item))
				where (Object)(object)i != (Object)null
				select i).ToList();
			List<string> list = Plugin.items.ConvertAll((Item i) => i.itemName);
			list.Sort();
			Plugin.possibleItems = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<string>("General", "ItemNames", "Notice The List Please", string.Join("|", list) ?? "");
			foreach (Item item in Plugin.items)
			{
				Plugin.logger.LogInfo((object)("ItemName: " + item.itemName));
			}
			foreach (EnemyType enemy in Plugin.enemies)
			{
				Plugin.logger.LogInfo((object)("MobName: " + enemy.enemyName));
				if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", enemy.enemyName)))
				{
					ConfigEntry<string> val = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<string>("Mobs", enemy.enemyName, "Old phone, 1, 3, 50, 80, 1000, Flask, 1, 1, 200, 400, 100", "The First setting is the item name.The Second setting is the minimum item drop amount.The Third setting is the max item drop amount.The Fourth setting is the minimum scrap value amount.The Fifth setting is the maximum scrap value amount.The Last setting is the chance of it dropping from 1-1000.You can add more items like all config entries do,up to however many you want(each has 2 item drops default).");
				}
			}
		}
	}
}
namespace LootMania.Component
{
	internal class DroppedItemEnemy : MonoBehaviour
	{
		private void Awake()
		{
			Plugin.logger.LogInfo((object)"Enemy Object Drop Loaded.");
		}
	}
}