Decompiled source of InWorldDrops v1.0.0

InWorldDrops.dll

Decompiled 7 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 HarmonyLib;
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("EmoteWheel")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EmoteWheel")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b404dec9-2569-4583-8089-1bae71ce6300")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace InWorldDrops;

[BepInPlugin("com.Playboy.InWorldDrops", "InWorldDrops", "1.0.0")]
public class Main : BaseUnityPlugin
{
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	private class Patch_Shop_1
	{
		public static FieldInfo m_CategoryItemDicFieldInfo = typeof(ShopHandler).GetField("m_CategoryItemDic", BindingFlags.Instance | BindingFlags.NonPublic);

		private static void Postfix(ref ShopHandler __instance)
		{
			if (shopItemsDictionary.Count <= 0)
			{
				Dictionary<ShopItemCategory, List<ShopItem>> categoryItemDic = GetCategoryItemDic(__instance);
				AddDictionaryItems(categoryItemDic, (ShopItemCategory)1);
				AddDictionaryItems(categoryItemDic, (ShopItemCategory)2);
				AddDictionaryItems(categoryItemDic, (ShopItemCategory)3);
				AddDictionaryItems(categoryItemDic, (ShopItemCategory)7);
			}
		}

		private static void AddDictionaryItems(Dictionary<ShopItemCategory, List<ShopItem>> dictionary, ShopItemCategory category)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (dictionary.TryGetValue(category, out var value))
			{
				shopItemsDictionary[category] = value.ToList();
			}
		}

		public static Dictionary<ShopItemCategory, List<ShopItem>> GetCategoryItemDic(ShopHandler inst)
		{
			if (m_CategoryItemDicFieldInfo == null)
			{
				return null;
			}
			return (Dictionary<ShopItemCategory, List<ShopItem>>)m_CategoryItemDicFieldInfo.GetValue(inst);
		}
	}

	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	private class Patch_Spawn_1
	{
		public static float lastSpawnTime = 0f;

		private static readonly Random random = new Random();

		private static void Postfix(ref RoundArtifactSpawner __instance)
		{
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Expected O, but got Unknown
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time - lastSpawnTime < 10f)
			{
				return;
			}
			lastSpawnTime = Time.time;
			ShopItemCategory[] array = new ShopItemCategory[4];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			ShopItemCategory[] eligibleCategories = (ShopItemCategory[])(object)array;
			Dictionary<ShopItemCategory, List<ShopItem>> dictionary = shopItemsDictionary.Where((KeyValuePair<ShopItemCategory, List<ShopItem>> kvp) => eligibleCategories.Contains(kvp.Key) && kvp.Value.Count > 0).ToDictionary((KeyValuePair<ShopItemCategory, List<ShopItem>> kvp) => kvp.Key, (KeyValuePair<ShopItemCategory, List<ShopItem>> kvp) => kvp.Value);
			if (dictionary.Count == 0)
			{
				return;
			}
			List<PatrolGroup> list = new List<PatrolGroup>();
			list.Add((PatrolGroup)4);
			list.Add((PatrolGroup)0);
			List<PatrolPoint> pointsInGroups = Level.currentLevel.GetPointsInGroups(list);
			List<Vector3> list2 = new List<Vector3>();
			float num = 60f;
			int num2 = 0;
			foreach (PatrolPoint item in pointsInGroups)
			{
				Transform transform = ((Component)item).transform;
				ShopItemCategory key = eligibleCategories[random.Next(eligibleCategories.Length)];
				bool flag = true;
				foreach (Vector3 item2 in list2)
				{
					float num3 = Vector3.Distance(transform.position, item2);
					if (num3 < num)
					{
						flag = false;
						break;
					}
				}
				if (flag && shopItemsDictionary.ContainsKey(key) && shopItemsDictionary[key].Count != 0)
				{
					List<ShopItem> list3 = shopItemsDictionary[key];
					ShopItem val = list3[random.Next(list3.Count)];
					PickupHandler.CreatePickup(((ShopItem)(ref val)).ItemID, new ItemInstanceData(Guid.NewGuid()), transform.position, transform.rotation, Vector3.zero, Vector3.zero);
					list2.Add(transform.position);
					num2++;
				}
			}
		}
	}

	public static Harmony harmony;

	public static Dictionary<ShopItemCategory, List<ShopItem>> shopItemsDictionary = new Dictionary<ShopItemCategory, List<ShopItem>>();

	private void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		harmony = new Harmony("Playboy.InWorldDrops");
		harmony.PatchAll();
	}
}