Decompiled source of RandomItemGenerating v1.1.4

com.Nathrexeio.RandomItemGenerating.dll

Decompiled 19 hours 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.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using ItemSpawner;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using RandomItemGenerating;
using RandomItemGeneratingGUI;
using UnityEngine;
using UnityEngine.InputSystem;
using Zorro.Core;
using Zorro.Settings;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.Nathrexeio.RandomItemGenerating")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("com.Nathrexeio.RandomItemGenerating")]
[assembly: AssemblyTitle("RandomItemGenerating")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace RandomItemGenerating
{
	[BepInPlugin("com.Nathrexeio.RandomItemGenerating", "RandomItemGenerating", "1.1.4")]
	public class Plugin : BaseUnityPlugin
	{
		public enum SpawnInHandMode
		{
			Off,
			SpawnInHandLast,
			And3ItemSlots
		}

		private ConfigEntry<bool> configSpawnItems;

		private ConfigEntry<int> configSpawnIntervalSeconds;

		private ConfigEntry<bool> configSameItemForAll;

		private ConfigEntry<bool> configRemoveDuplicateChessPieces;

		private ConfigEntry<bool> configRemoveProblematicItems;

		private ConfigEntry<bool> configAddToBackpackNext;

		private ConfigEntry<string> configDisabledItems;

		public static ConfigEntry<SpawnInHandMode> configSpawnInHandMode;

		private ConfigEntry<KeyCode> configToggleKey;

		private static Plugin _instance;

		public const string Id = "com.Nathrexeio.RandomItemGenerating";

		public static bool SpawnItems
		{
			get
			{
				return Instance.configSpawnItems.Value;
			}
			set
			{
				Instance.configSpawnItems.Value = value;
			}
		}

		public static int SpawnIntervalSeconds
		{
			get
			{
				return Instance.configSpawnIntervalSeconds.Value;
			}
			set
			{
				Instance.configSpawnIntervalSeconds.Value = value;
			}
		}

		public static bool sameItemForAll
		{
			get
			{
				return Instance.configSameItemForAll.Value;
			}
			set
			{
				Instance.configSameItemForAll.Value = value;
			}
		}

		public static bool removeDuplicateChessPieces
		{
			get
			{
				return Instance.configRemoveDuplicateChessPieces.Value;
			}
			set
			{
				Instance.configRemoveDuplicateChessPieces.Value = value;
			}
		}

		public static bool removeProblematicItems
		{
			get
			{
				return Instance.configRemoveProblematicItems.Value;
			}
			set
			{
				Instance.configRemoveProblematicItems.Value = value;
			}
		}

		public static bool addToBackpackNext
		{
			get
			{
				return Instance.configAddToBackpackNext.Value;
			}
			set
			{
				Instance.configAddToBackpackNext.Value = value;
			}
		}

		public static string disabledItems
		{
			get
			{
				return Instance.configDisabledItems.Value;
			}
			set
			{
				Instance.configDisabledItems.Value = value;
			}
		}

		public static KeyCode toggleKey => Instance.configToggleKey.Value;

		internal static ManualLogSource Log { get; private set; }

		public static Plugin Instance
		{
			get
			{
				return _instance;
			}
			private set
			{
				_instance = value;
			}
		}

		public static string Name => "RandomItemGenerating";

		public static string Version => "1.1.4";

		private void Awake()
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Expected O, but got Unknown
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Expected O, but got Unknown
			configSpawnItems = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "SpawnItems", true, "If true, Items will spawn");
			configToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ToggleKey", (KeyCode)282, "The button to toggle the Configuration GUI.");
			configSpawnIntervalSeconds = ((BaseUnityPlugin)this).Config.Bind<int>("General", "SpawnTimerSeconds", 30, new ConfigDescription("The interval (in seconds) between item spawns.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(5, 300), Array.Empty<object>()));
			configSameItemForAll = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "SameItemForAll", false, "If true, all players receive the same item ID for the current spawn cycle.");
			configRemoveDuplicateChessPieces = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Filter&DisableUnusedDuplicateItems", true, "If true, this will filter and remove all duplicate chess pieces from the random spawn item pool");
			configRemoveProblematicItems = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ExlcudeProblematicItems", true, "If true, this will filter and remove the Skull, Golden Grappling Hook, and Scouts Honor from random spawn item pool");
			configAddToBackpackNext = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AddToBackpackAndFannypack", false, "If true, Items will also spawn in empty backpack or fannypack slots");
			configDisabledItems = ((BaseUnityPlugin)this).Config.Bind<string>("General", "DisabledItems", "ScoutsHonor;Skull;Cheat Compass 1;Cheat Compass;Warp Compass;ScoutmasterSoul;RitualDagger;Passport;ClimbingChalk", "A list of all the items that are disabled");
			configSpawnInHandMode = ((BaseUnityPlugin)this).Config.Bind<SpawnInHandMode>("General", "SpawnInHandMode", SpawnInHandMode.Off, "Off, Spawn In Hand for Tempslot, And 3 item slots");
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
			GameObject val = new GameObject("ItemSpawnerHost");
			val.AddComponent<global::ItemSpawner.ItemSpawner>();
			val.AddComponent<global::RandomItemGeneratingGUI.RandomItemGeneratingGUI>();
			Object.DontDestroyOnLoad((Object)(object)val);
			Harmony val2 = new Harmony("com.Nathrexeio.RandomItemGenerating");
			val2.PatchAll();
			MethodInfo methodInfo = AccessTools.Method(typeof(GoToAirport), "GoFromMainMenu", (Type[])null, (Type[])null);
			Log.LogWarning((object)$"GoFromMainMenu found: {methodInfo != null}");
			Patches obj = ((methodInfo != null) ? Harmony.GetPatchInfo((MethodBase)methodInfo) : null);
			Log.LogWarning((object)$"GoFromMainMenu postfixes: {obj?.Postfixes.Count ?? 0}");
		}
	}
}
namespace MyPatches
{
	[HarmonyPatch(typeof(PhotonNetwork), "JoinRoom")]
	public static class JoinRoomPatch
	{
		[HarmonyPostfix]
		public static void Postfix(string roomName, bool __result)
		{
			global::ItemSpawner.ItemSpawner.LastHostedThisLobby = false;
			CheckIfNeedCacheClass.CheckIfNeedCache();
		}
	}
	[HarmonyPatch(typeof(PhotonNetwork), "CreateRoom")]
	public static class CreateRoomPatch
	{
		[HarmonyPostfix]
		public static void PostFix(bool __result)
		{
			global::ItemSpawner.ItemSpawner.LastHostedThisLobby = true;
			CheckIfNeedCacheClass.CheckIfNeedCache();
		}
	}
	public static class CheckIfNeedCacheClass
	{
		public static void CheckIfNeedCache()
		{
			if (global::RandomItemGeneratingGUI.RandomItemGeneratingGUI.Instance.cacheNextNotOnTitle)
			{
				global::RandomItemGeneratingGUI.RandomItemGeneratingGUI.Instance.cacheNextNotOnTitle = false;
				global::RandomItemGeneratingGUI.RandomItemGeneratingGUI.Instance.CacheIcons();
				Plugin.Log.LogInfo((object)"Alright Cached Icons");
			}
		}
	}
}
namespace ItemSpawner
{
	public class ItemSpawner : MonoBehaviour
	{
		private static readonly Random random = new Random();

		public static List<Item> randomItemPool = new List<Item>(((DatabaseAsset<ItemDatabase, Item>)(object)SingletonAsset<ItemDatabase>.Instance).Objects);

		public static bool LastHostedThisLobby = false;

		private static int waitedFor = 0;

		public static ItemSpawner Instance { get; private set; }

		private void Start()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Plugin.Log.LogInfo((object)"Starting to spawn items soon");
			((MonoBehaviour)this).StartCoroutine(SpawnRoutine());
		}

		private IEnumerator SpawnRoutine()
		{
			while (true)
			{
				if (waitedFor < Plugin.SpawnIntervalSeconds)
				{
					yield return (object)new WaitForSeconds(1f);
					CheckIntervalChange();
					waitedFor++;
					continue;
				}
				waitedFor = 0;
				try
				{
					if (PhotonNetwork.LocalPlayer.IsMasterClient && LastHostedThisLobby && Plugin.SpawnItems)
					{
						SpawnARandomItem();
					}
				}
				catch (Exception ex)
				{
					Exception ex2 = ex;
					Plugin.Log.LogWarning((object)("[ERROR] Spawning logic failed: " + ex2.Message));
				}
			}
		}

		private void CheckIntervalChange()
		{
			if (Plugin.SpawnIntervalSeconds != global::RandomItemGeneratingGUI.RandomItemGeneratingGUI.guiSettingSpawnIntervalOld)
			{
				global::RandomItemGeneratingGUI.RandomItemGeneratingGUI.guiSettingSpawnIntervalOld = Plugin.SpawnIntervalSeconds;
				waitedFor = 0;
			}
		}

		public void SpawnARandomItem()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			try
			{
				Item item = new Item();
				if (global::RandomItemGeneratingGUI.RandomItemGeneratingGUI.spawningRandomItemPool.Length == 0)
				{
					return;
				}
				int num = 0;
				List<Character> list = Character.AllCharacters.Where((Character plr) => (Object)(object)plr != (Object)null && ((Component)plr).gameObject.activeSelf).ToList();
				for (int num2 = 0; num2 < list.Count; num2++)
				{
					if (num2 == 0 || !Plugin.sameItemForAll)
					{
						num = random.Next(0, global::RandomItemGeneratingGUI.RandomItemGeneratingGUI.spawningRandomItemPool.Length);
						item = global::RandomItemGeneratingGUI.RandomItemGeneratingGUI.spawningRandomItemPool[num];
					}
					Spawn(item, list[num2]);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Finding random item to spawn failed: " + ex.Message));
			}
		}

		public static void Spawn(Item item, Character player)
		{
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Expected O, but got Unknown
			if (!PhotonNetwork.IsConnected || !Object.op_Implicit((Object)(object)Character.localCharacter) || player.data.dead || player.data.fullyPassedOut)
			{
				return;
			}
			LootData component = ((Component)item).GetComponent<LootData>();
			try
			{
				if ((Object)(object)((Component)item).gameObject.GetComponent<Backpack>() != (Object)null && ((ItemSlot)player.player.backpackSlot).IsEmpty())
				{
					ItemSlot val = default(ItemSlot);
					player.player.AddItem(item.itemID, (ItemInstanceData)null, ref val);
					return;
				}
				bool flag = false;
				ItemSlot val2 = default(ItemSlot);
				for (int i = 0; i < player.player.itemSlots.Length; i++)
				{
					if (player.player.itemSlots[i].IsEmpty())
					{
						if (Plugin.configSpawnInHandMode.Value < Plugin.SpawnInHandMode.And3ItemSlots)
						{
							player.player.AddItem(item.itemID, (ItemInstanceData)null, ref val2);
						}
						else
						{
							player.refs.items.SpawnItemInHand(((Object)item).name);
						}
						player.refs.afflictions.UpdateWeight();
						flag = true;
						break;
					}
				}
				if (Plugin.addToBackpackNext && !flag && !((ItemSlot)player.player.backpackSlot).IsEmpty())
				{
					BackpackData val3 = default(BackpackData);
					((ItemSlot)player.player.backpackSlot).data.TryGetDataEntry<BackpackData>((DataEntryKey)7, ref val3);
					string prefabName = ((ItemSlot)player.player.backpackSlot).GetPrefabName();
					if (prefabName == "Fannypack" || prefabName == "Backpack")
					{
						for (int j = 0; j < val3.itemSlots.Length; j++)
						{
							if (val3.itemSlots[j].IsEmpty() && ((j <= 1 && prefabName == "Fannypack") || prefabName == "Backpack"))
							{
								item.data = new ItemInstanceData(Guid.NewGuid());
								ItemInstanceDataHandler.AddInstanceData(item.data);
								val3.itemSlots[j].SetItem(item, item.data);
								player.refs.afflictions.UpdateWeight();
								flag = true;
								break;
							}
						}
					}
					else
					{
						Plugin.Log.LogWarning((object)"BackpackData doesn't seem to exist here... hmm ");
					}
				}
				if (Plugin.configSpawnInHandMode.Value != Plugin.SpawnInHandMode.Off && !flag && player.player.tempFullSlot.IsEmpty())
				{
					player.refs.items.SpawnItemInHand(((Object)item).name);
				}
			}
			catch (Exception arg)
			{
				Plugin.Log.LogWarning((object)$"Finding random item to spawn failed for item '{((item != null) ? ((Object)item).name : null)}':\n{arg}");
			}
		}
	}
}
namespace RandomItemGeneratingGUI
{
	public class RandomItemGeneratingGUI : MonoBehaviour
	{
		private enum GUIPage
		{
			Items,
			Settings
		}

		private bool showGUI = false;

		private Rect GUIwindowRect = new Rect(100f, 100f, 1250f, 600f);

		private Vector2 scrollBarPosition;

		private List<Item> randomItemPool;

		private List<Item> FilteredItemPool;

		private GUIStyle tileStyle;

		private Texture2D tileBackgroundTexture;

		private GUIStyle centeredNameLabel;

		private GUIStyle iconStyle;

		private GUIStyle enabledButtonStyle;

		private GUIStyle disabledButtonStyle;

		private Texture2D enabledButtonTexture;

		private Texture2D disabledButtonTexture;

		private GUIStyle settingToggleStyle;

		private GUIPage currentPage = GUIPage.Items;

		private InputAction toggleGUI;

		private bool guiSettingSpawnItems = Plugin.SpawnItems;

		private bool guiSettingRemoveProblematicItems = Plugin.removeProblematicItems;

		private bool guiSettingRemoveDuplicateChessPieces = Plugin.removeDuplicateChessPieces;

		private bool guiSettingSameItemForAll = Plugin.sameItemForAll;

		private string guiSettingSpawnInterval = Plugin.SpawnIntervalSeconds.ToString();

		private List<string> guiSettingDisabledItems = Plugin.disabledItems.Split(';', StringSplitOptions.RemoveEmptyEntries).ToList();

		private bool guiSettingAddToBackpackNext = Plugin.addToBackpackNext;

		private string[] spawnInHandModeOptions = new string[3] { "Off", "Spawn In Hand for Tempslot", "And 3 item slots" };

		private int guiSettingSpawnInHandMode = (int)Plugin.configSpawnInHandMode.Value;

		private bool guiSettingRemoveDuplicateChessPiecesOld = Plugin.removeDuplicateChessPieces;

		private bool guiSettingRemoveProblematicItemsOld = Plugin.removeProblematicItems;

		public static int guiSettingSpawnIntervalOld = Plugin.SpawnIntervalSeconds;

		public static Item[] visableRandomItemPool;

		public static Item[] spawningRandomItemPool;

		private Texture2D[] itemIcons;

		private bool[] enabledItems;

		private string itemFilter = "";

		private string[] chessPieceNames = new string[18]
		{
			"C_Rook_f", "C_Bishop_m", "C_Bishop_m Variant", "C_Rook_f Variant", "C_Pawn_f", "C_King", "C_Knight", "C_Rook_m", "C_Queen", "C_Bishop_f",
			"C_Pawn_m", "C_Pawn_f Variant", "C_Rook_m Variant", "C_Knight Variant", "C_Bishop_f Variant", "C_Pawn_m Variant", "C_Queen Variant", "C_King Variant"
		};

		private string[] problemItemNames = new string[3] { "Skull", "ScoutsHonor", "RescueHook_Infinite" };

		private SettingsHandler settingsHandler;

		private int lastbugPhobiaSetting;

		private int lastColorblindSetting;

		public bool cacheNextNotOnTitle = false;

		public static RandomItemGeneratingGUI Instance { get; private set; }

		private void Awake()
		{
			Instance = this;
		}

		private void OnDestroy()
		{
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}

		private void OnEnable()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			toggleGUI = new InputAction("ToggleGUI", (InputActionType)1, "<Keyboard>/" + ((object)Plugin.toggleKey/*cast due to .constrained prefix*/).ToString().ToLower(), (string)null, (string)null, (string)null);
			toggleGUI.performed += Toggle;
			toggleGUI.Enable();
		}

		private void OnDisable()
		{
			toggleGUI.Disable();
			toggleGUI.performed -= Toggle;
			toggleGUI.Dispose();
		}

		private void Toggle(CallbackContext _)
		{
			CheckIconSettings();
			TrySaveConfig();
			showGUI = !showGUI;
		}

		private void OnGUI()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_0034: 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)
			InitializeGUIStyles();
			if (showGUI)
			{
				GUIwindowRect = GUI.Window(12345, GUIwindowRect, new WindowFunction(DrawWindow), "Random Item Generating");
			}
		}

		private void Start()
		{
			((MonoBehaviour)this).StartCoroutine(Initialize());
		}

		private IEnumerator Initialize()
		{
			yield return null;
			for (settingsHandler = SettingsHandler.Instance; settingsHandler == null; settingsHandler = SettingsHandler.Instance)
			{
				yield return null;
			}
			UpdateLastIconSettings();
			if (lastColorblindSetting == 1)
			{
				cacheNextNotOnTitle = true;
			}
			BuildCurrentItemPool();
		}

		private void CheckIconSettings()
		{
			if (settingsHandler != null)
			{
				if (lastbugPhobiaSetting != ((EnumSetting<OffOnMode>)(object)settingsHandler.GetSetting<BugPhobiaSetting>()).GetValue())
				{
					UpdateLastIconSettings();
					cacheNextNotOnTitle = true;
				}
				else if (lastColorblindSetting != ((EnumSetting<OffOnMode>)(object)settingsHandler.GetSetting<ColorblindSetting>()).GetValue())
				{
					UpdateLastIconSettings();
					cacheNextNotOnTitle = true;
				}
			}
		}

		private void UpdateLastIconSettings()
		{
			lastbugPhobiaSetting = ((EnumSetting<OffOnMode>)(object)settingsHandler.GetSetting<BugPhobiaSetting>()).GetValue();
			lastColorblindSetting = ((EnumSetting<OffOnMode>)(object)settingsHandler.GetSetting<ColorblindSetting>()).GetValue();
		}

		private void BuildCurrentItemPool()
		{
			randomItemPool = new List<Item>(((DatabaseAsset<ItemDatabase, Item>)(object)SingletonAsset<ItemDatabase>.Instance).Objects);
			if (guiSettingRemoveDuplicateChessPieces)
			{
				randomItemPool = randomItemPool.Where((Item item) => !chessPieceNames.Contains(((Object)item).name)).ToList();
			}
			if (guiSettingRemoveProblematicItems)
			{
				randomItemPool = randomItemPool.Where((Item item) => !problemItemNames.Contains(((Object)item).name)).ToList();
			}
			enabledItems = new bool[randomItemPool.Count];
			visableRandomItemPool = (Item[])(object)new Item[randomItemPool.Count];
			List<Item> list = new List<Item>();
			spawningRandomItemPool = (Item[])(object)new Item[randomItemPool.Count];
			for (int num = 0; num < randomItemPool.Count; num++)
			{
				visableRandomItemPool[num] = randomItemPool[num];
				if (guiSettingDisabledItems.Contains(((Object)visableRandomItemPool[num]).name))
				{
					enabledItems[num] = false;
					continue;
				}
				enabledItems[num] = true;
				list.Add(randomItemPool[num]);
			}
			spawningRandomItemPool = list.ToArray();
			CacheIcons();
		}

		public void CacheIcons()
		{
			itemIcons = (Texture2D[])(object)new Texture2D[randomItemPool.Count];
			for (int i = 0; i < randomItemPool.Count; i++)
			{
				try
				{
					Texture2D[] array = itemIcons;
					int num = i;
					ItemUIData uIData = randomItemPool[i].UIData;
					array[num] = ((uIData != null) ? uIData.GetIcon() : null);
				}
				catch (Exception)
				{
					itemIcons[i] = randomItemPool[i].UIData?.icon;
				}
			}
		}

		private void InitializeGUIStyles()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Expected O, but got Unknown
			//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_0147: 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_015d: Expected O, but got Unknown
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Expected O, but got Unknown
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Expected O, but got Unknown
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Expected O, but got Unknown
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Expected O, but got Unknown
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Expected O, but got Unknown
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Expected O, but got Unknown
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			if (tileStyle == null)
			{
				GUI.skin.label.fontSize = 18;
				GUI.skin.label.normal.textColor = Color.white;
				GUI.skin.button.fontSize = 18;
				GUI.skin.button.normal.textColor = Color.white;
				GUI.skin.textField.fontSize = 18;
				GUI.skin.textField.normal.textColor = Color.white;
				GUI.skin.toggle.fontSize = 18;
				GUI.skin.toggle.normal.textColor = Color.white;
				tileBackgroundTexture = new Texture2D(1, 1);
				tileBackgroundTexture.SetPixel(0, 0, new Color(0f, 0f, 1f, 0.15f));
				tileBackgroundTexture.Apply();
				tileStyle = new GUIStyle(GUI.skin.box);
				tileStyle.normal.background = tileBackgroundTexture;
				centeredNameLabel = new GUIStyle(GUI.skin.label)
				{
					alignment = (TextAnchor)4,
					wordWrap = true,
					fontSize = 16
				};
				iconStyle = new GUIStyle(GUI.skin.label)
				{
					alignment = (TextAnchor)4
				};
				enabledButtonTexture = new Texture2D(1, 1);
				enabledButtonTexture.SetPixel(0, 0, new Color(0f, 0.6f, 0f, 0.75f));
				enabledButtonTexture.Apply();
				disabledButtonTexture = new Texture2D(1, 1);
				disabledButtonTexture.SetPixel(0, 0, new Color(0.7f, 0f, 0f, 0.75f));
				disabledButtonTexture.Apply();
				enabledButtonStyle = new GUIStyle(GUI.skin.button);
				enabledButtonStyle.normal.background = enabledButtonTexture;
				disabledButtonStyle = new GUIStyle(GUI.skin.button);
				disabledButtonStyle.normal.background = disabledButtonTexture;
				enabledButtonStyle.hover.background = enabledButtonTexture;
				enabledButtonStyle.active.background = enabledButtonTexture;
				disabledButtonStyle.hover.background = disabledButtonTexture;
				disabledButtonStyle.active.background = disabledButtonTexture;
				settingToggleStyle = new GUIStyle(GUI.skin.toggle);
				settingToggleStyle.fontSize = 18;
				settingToggleStyle.wordWrap = true;
				settingToggleStyle.normal.textColor = Color.white;
				settingToggleStyle.hover.textColor = Color.white;
				settingToggleStyle.active.textColor = Color.white;
				settingToggleStyle.focused.textColor = Color.white;
				settingToggleStyle.onNormal.textColor = Color.white;
				settingToggleStyle.onHover.textColor = Color.white;
				settingToggleStyle.onActive.textColor = Color.white;
				settingToggleStyle.onFocused.textColor = Color.white;
			}
		}

		private void DrawWindow(int windowID)
		{
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.Space(5f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Items", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
			{
				currentPage = GUIPage.Items;
			}
			if (GUILayout.Button("Settings", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
			{
				currentPage = GUIPage.Settings;
			}
			GUILayout.FlexibleSpace();
			if (GUILayout.Button("Close", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }))
			{
				showGUI = false;
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(10f);
			if (currentPage == GUIPage.Items)
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.Label("Filter:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) });
				itemFilter = GUILayout.TextField(itemFilter, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(350f) });
				if (GUILayout.Button("Clear", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }))
				{
					itemFilter = "";
				}
				GUILayout.FlexibleSpace();
				GUILayout.EndHorizontal();
				GUILayout.Space(5f);
			}
			scrollBarPosition = GUILayout.BeginScrollView(scrollBarPosition, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.ExpandWidth(true),
				GUILayout.ExpandHeight(true)
			});
			if (currentPage == GUIPage.Items)
			{
				DrawItemGrid();
			}
			else if (currentPage == GUIPage.Settings)
			{
				DrawSettingsPage();
			}
			GUILayout.EndScrollView();
			GUILayout.Space(5f);
			if (currentPage == GUIPage.Items)
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (GUILayout.Button("Enable All", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
				{
					SetAllItems(enabled: true);
				}
				if (GUILayout.Button("Disable All", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
				{
					SetAllItems(enabled: false);
				}
				if (GUILayout.Button("Invert All", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
				{
					InvertAllItems();
				}
				if (GUILayout.Button("Save Config", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(120f) }))
				{
					TrySaveConfig();
				}
				GUILayout.FlexibleSpace();
				int enabledCount = GetEnabledCount();
				GUILayout.Label($"Enabled: {enabledCount}/{visableRandomItemPool.Length}", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(120f) });
				GUILayout.EndHorizontal();
			}
			GUILayout.Space(5f);
			GUI.DragWindow(new Rect(0f, 0f, ((Rect)(ref GUIwindowRect)).width - 80f, 25f));
		}

		private void TrySaveConfig()
		{
			int num = 0;
			if (guiSettingSpawnItems != Plugin.SpawnItems)
			{
				Plugin.SpawnItems = guiSettingSpawnItems;
				num = 1;
			}
			if (int.TryParse(guiSettingSpawnInterval, out var result))
			{
				if (result > 300 || result < 5)
				{
					guiSettingSpawnInterval = Plugin.SpawnIntervalSeconds.ToString();
				}
				else
				{
					Plugin.SpawnIntervalSeconds = result;
					num = 1;
				}
			}
			else
			{
				guiSettingSpawnInterval = Plugin.SpawnIntervalSeconds.ToString();
			}
			if (guiSettingSameItemForAll != Plugin.sameItemForAll)
			{
				Plugin.sameItemForAll = guiSettingSameItemForAll;
				num = 1;
			}
			if (guiSettingRemoveDuplicateChessPieces != Plugin.removeDuplicateChessPieces)
			{
				Plugin.removeDuplicateChessPieces = guiSettingRemoveDuplicateChessPieces;
				num = 1;
			}
			if (guiSettingRemoveProblematicItems != Plugin.removeProblematicItems)
			{
				Plugin.removeProblematicItems = guiSettingRemoveProblematicItems;
				num = 1;
			}
			if (guiSettingAddToBackpackNext != Plugin.addToBackpackNext)
			{
				Plugin.addToBackpackNext = guiSettingAddToBackpackNext;
				num = 1;
			}
			Plugin.SpawnInHandMode spawnInHandMode = (Plugin.SpawnInHandMode)guiSettingSpawnInHandMode;
			if (spawnInHandMode != Plugin.configSpawnInHandMode.Value)
			{
				Plugin.configSpawnInHandMode.Value = spawnInHandMode;
				num = 1;
			}
			for (int i = 0; i < enabledItems.Length; i++)
			{
				if (enabledItems[i] && guiSettingDisabledItems.Contains(((Object)visableRandomItemPool[i]).name))
				{
					guiSettingDisabledItems.Remove(((Object)visableRandomItemPool[i]).name);
					num = 2;
				}
				if (!enabledItems[i] && !guiSettingDisabledItems.Contains(((Object)visableRandomItemPool[i]).name))
				{
					guiSettingDisabledItems.Add(((Object)visableRandomItemPool[i]).name);
					num = 2;
				}
			}
			if (num == 2)
			{
				Plugin.disabledItems = string.Join(";", guiSettingDisabledItems);
				BuildCurrentItemPool();
			}
			if (num > 0)
			{
				((BaseUnityPlugin)Plugin.Instance).Config.Save();
			}
		}

		private void DrawItemGrid()
		{
			int num = 0;
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			for (int i = 0; i < visableRandomItemPool.Length; i++)
			{
				if (IsItemVisible(i))
				{
					if (num > 0 && num % 8 == 0)
					{
						GUILayout.EndHorizontal();
						GUILayout.Space(10f);
						GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
					}
					DrawItemTile(i);
					num++;
				}
			}
			GUILayout.EndHorizontal();
			if (num == 0)
			{
				GUILayout.Label("No items found.", Array.Empty<GUILayoutOption>());
			}
		}

		private void DrawSettingsPage()
		{
			GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(500f) });
			GUILayout.Label("Settings", Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			guiSettingSpawnItems = GUILayout.Toggle(guiSettingSpawnItems, "Spawn Items", settingToggleStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			GUILayout.Label("Seconds: ", Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			guiSettingSpawnInterval = GUILayout.TextField(guiSettingSpawnInterval, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) });
			GUILayout.Label("The interval (in seconds) between item spawns. (5-300)", Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			guiSettingSameItemForAll = GUILayout.Toggle(guiSettingSameItemForAll, "Same Item For All? If true, all players receive the same item ID for the current spawn cycle.", settingToggleStyle, Array.Empty<GUILayoutOption>());
			guiSettingRemoveDuplicateChessPieces = GUILayout.Toggle(guiSettingRemoveDuplicateChessPieces, "Filter & Disable Unused Duplicate Items", settingToggleStyle, Array.Empty<GUILayoutOption>());
			if (guiSettingRemoveDuplicateChessPiecesOld != guiSettingRemoveDuplicateChessPieces)
			{
				guiSettingRemoveDuplicateChessPiecesOld = guiSettingRemoveDuplicateChessPieces;
				BuildCurrentItemPool();
			}
			guiSettingRemoveProblematicItems = GUILayout.Toggle(guiSettingRemoveProblematicItems, "Filter & Disable Skull, ScoutsHonor, RescueHook_Infinite", settingToggleStyle, Array.Empty<GUILayoutOption>());
			if (guiSettingRemoveProblematicItemsOld != guiSettingRemoveProblematicItems)
			{
				guiSettingRemoveProblematicItemsOld = guiSettingRemoveProblematicItems;
				BuildCurrentItemPool();
			}
			guiSettingAddToBackpackNext = GUILayout.Toggle(guiSettingAddToBackpackNext, "Items will also spawn in empty backpack or fannypack slots", settingToggleStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Label("Items Spawning in Hand", Array.Empty<GUILayoutOption>());
			guiSettingSpawnInHandMode = GUILayout.Toolbar(guiSettingSpawnInHandMode, spawnInHandModeOptions, Array.Empty<GUILayoutOption>());
			GUILayout.EndVertical();
		}

		private void DrawItemTile(int index)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			bool flag = enabledItems[index];
			GUILayout.BeginVertical(tileStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(145f),
				GUILayout.Height(145f)
			});
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.FlexibleSpace();
			if ((Object)(object)itemIcons[index] != (Object)null)
			{
				Color color = GUI.color;
				GUI.color = (Color)(flag ? Color.white : new Color(0.25f, 0.25f, 0.25f, 1f));
				if (GUILayout.Button(GUIContent.none, GUIStyle.none, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(96f),
					GUILayout.Height(96f)
				}))
				{
					enabledItems[index] = !flag;
				}
				GUI.Label(GUILayoutUtility.GetLastRect(), (Texture)(object)itemIcons[index], iconStyle);
				GUI.color = color;
			}
			else
			{
				GUILayout.Box(GUIContent.none, GUIStyle.none, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(96f),
					GUILayout.Height(96f)
				});
			}
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
			GUILayout.Label(visableRandomItemPool[index].GetName(), centeredNameLabel, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(60f) });
			if (GUILayout.Button(flag ? "Enabled" : "Disabled", flag ? enabledButtonStyle : disabledButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
			{
				enabledItems[index] = !flag;
			}
			GUILayout.FlexibleSpace();
			GUILayout.EndVertical();
		}

		private void SetAllItems(bool enabled)
		{
			for (int i = 0; i < visableRandomItemPool.Length; i++)
			{
				if (IsItemVisible(i))
				{
					enabledItems[i] = enabled;
				}
			}
		}

		private void InvertAllItems()
		{
			for (int i = 0; i < visableRandomItemPool.Length; i++)
			{
				if (IsItemVisible(i))
				{
					if (enabledItems[i])
					{
						enabledItems[i] = false;
					}
					else
					{
						enabledItems[i] = true;
					}
				}
			}
		}

		private bool IsItemVisible(int index)
		{
			if (string.IsNullOrWhiteSpace(itemFilter))
			{
				return true;
			}
			string name = visableRandomItemPool[index].GetName();
			return name.IndexOf(itemFilter, StringComparison.OrdinalIgnoreCase) >= 0;
		}

		private int GetEnabledCount()
		{
			int num = 0;
			for (int i = 0; i < enabledItems.Length; i++)
			{
				if (enabledItems[i])
				{
					num++;
				}
			}
			return num;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}