Decompiled source of ItemSpawnerTweaks v1.1.0

Sirdoggy.ItemSpawnerTweaks.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FistVR;
using FistVR.Ugc;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Sirdoggy.ItemSpawnerTweaks.Common;
using Sirdoggy.ItemSpawnerTweaks.Data;
using Sirdoggy.ItemSpawnerTweaks.Patches;
using Sirdoggy.ItemSpawnerTweaks.Tags;
using Sodalite.ModPanel;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("Sirdoggy")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Fixes and quality-of-life improvements for the item spawner")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("Sirdoggy.ItemSpawnerTweaks")]
[assembly: AssemblyTitle("ItemSpawnerTweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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 Sirdoggy.ItemSpawnerTweaks
{
	[BepInProcess("h3vr.exe")]
	[BepInPlugin("Sirdoggy.ItemSpawnerTweaks", "ItemSpawnerTweaks", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		internal static PluginConfig PluginConfig;

		internal static ExceptionCatcher ExceptionCatcher;

		public const string Id = "Sirdoggy.ItemSpawnerTweaks";

		public static string Name => "ItemSpawnerTweaks";

		public static string Version => "1.1.0";

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			PluginConfig = new PluginConfig(((BaseUnityPlugin)this).Info);
			ExceptionCatcher = new ExceptionCatcher(((BaseUnityPlugin)this).Logger);
			CoroutineRunner.Run(WaitForGM());
		}

		private IEnumerator WaitForGM()
		{
			yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)ManagerSingleton<GM>.Instance != (Object)null));
			int version_UpdateNumber = GM.Version_UpdateNumber;
			int version_AlphaNumber = GM.Version_AlphaNumber;
			int version_PatchNumber = GM.Version_PatchNumber;
			int version_BuildIndex = GM.Version_BuildIndex;
			Log.LogInfo((object)$"GM Versions: update '{version_UpdateNumber}', alpha '{version_AlphaNumber}', patch {version_PatchNumber}, 'build {version_BuildIndex}'");
			if (version_UpdateNumber < 120)
			{
				Log.LogFatal((object)("Incompatible version detected! You must update H3VR to at least " + $"U{120} to use this mod. You might need to change your game branch."));
				yield break;
			}
			ExceptionCatcher.Run(delegate
			{
				Harmony.CreateAndPatchAll(typeof(ItemSpawnerV2Patcher), (string)null);
			});
			ExceptionCatcher.Run(delegate
			{
				Harmony.CreateAndPatchAll(typeof(PreviewVaultFileOnHoverButtonPatcher), (string)null);
			});
			ExceptionCatcher.Run(delegate
			{
				Harmony.CreateAndPatchAll(typeof(VaultFileListPreviewPatcher), (string)null);
			});
			ExceptionCatcher.Run(delegate
			{
				Harmony.CreateAndPatchAll(typeof(VaultFileListLocalVaultPatcher), (string)null);
			});
			SceneManager.sceneLoaded += CleanupWeakCaches;
		}

		private void CleanupWeakCaches(Scene scene, LoadSceneMode loadSceneMode)
		{
			PreviewVaultFileOnHoverButtonPatcher.ButtonTagsCache.Clear();
		}
	}
	internal class PluginConfig
	{
		public ConfigEntry<ItemSpawnerDefaultPageDto> ItemSpawnerDefaultPage;

		public ConfigEntry<bool> OpenRelatedVaultFilesByDefault;

		public ConfigEntry<bool> OpenLocalVaultByDefault;

		public ConfigEntry<bool> PreviewVaultFilesOnHover;

		private const string ConfigFileName = "Sirdoggy.ItemSpawnerTweaks.cfg";

		private static ConfigFile _configFile;

		public PluginConfig(PluginInfo pluginInfo)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			_configFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "Sirdoggy.ItemSpawnerTweaks.cfg"), true);
			BindFields();
			UniversalModPanel.RegisterPluginSettings(pluginInfo, _configFile);
		}

		private void BindFields()
		{
			ItemSpawnerDefaultPage = _configFile.Bind<ItemSpawnerDefaultPageDto>("Item Spawner Settings", "Default open page", ItemSpawnerDefaultPageDto.Firearms, "Controls which item spawner page should be open by default. Set the value to 'WelcomePage' for vanilla behaviour.");
			OpenRelatedVaultFilesByDefault = _configFile.Bind<bool>("Item Spawner Settings", "Display related vault files by default", true, "Controls whether related vault files should be displayed in the item details panel by default. Set the value to 'false' for vanilla behaviour, which will display the tutorials list instead.");
			OpenLocalVaultByDefault = _configFile.Bind<bool>("Item Spawner Settings", "Open local vault folder by default", false, "When enabled, your local vault folder will be the default open folder instead of the home/root folder.");
			PreviewVaultFilesOnHover = _configFile.Bind<bool>("Item Spawner Settings", "Preview vault files on hover", true, "Enables previews of a vault files when hovering over them in the file list.");
		}
	}
}
namespace Sirdoggy.ItemSpawnerTweaks.Tags
{
	internal class ItemSpawnerV2Tag : MonoBehaviour
	{
		public VaultFile? LastSelectedVaultFile { get; set; }

		public long VaultFilePreviewCounter { get; set; }
	}
	internal class VaultFileButtonTag : MonoBehaviour
	{
		public ItemSpawnerV2 ItemSpawner { get; set; }

		public ItemSpawnerV2Tag ItemSpawnerTag { get; set; }

		public ItemSpawnerV2_VaultFileDetails VaultFileDetails => ItemSpawner.VaultFileDetails;

		public ItemSpawnerV2_VaultFileList VaultFileList => ItemSpawner.VaultFileList;

		public int ButtonIndexOnPage { get; set; }

		public bool ExecuteCodeOnHover { get; set; } = true;

		public long VaultFilePreviewCounterLocal { get; set; }

		public Coroutine? HideVaultFilePreviewCoroutine { get; set; }
	}
}
namespace Sirdoggy.ItemSpawnerTweaks.Patches
{
	[HarmonyWrapSafe]
	[HarmonyPatch(typeof(ItemSpawnerV2))]
	internal static class ItemSpawnerV2Patcher
	{
		private static OptionsPanel_ButtonSet? _topBarCategoryButtonSet;

		private static OptionsPanel_ButtonSet? _itemDetailsListModeButtonSet;

		private static FVRPointableButton? _saveLoadCategoryButton;

		private const int TopBarCategoryMainMenuIndex = 0;

		private const int TopBarCategoryFirearmsIndex = 1;

		private const int TopBarCategorySaveAndLoadButtonIndex = 6;

		private const int ItemDetailsListModeVaultFilesButtonIndex = 1;

		private static readonly FieldRef<ItemSpawnerV2, DetailsLinkedResourceMode> m_detailsLinkedResourceMode = AccessTools.FieldRefAccess<ItemSpawnerV2, DetailsLinkedResourceMode>("m_detailsLinkedResourceMode");

		private static readonly Action<ItemSpawnerV2, int> SetPageMode = ReflectionExtensions.Delegate<ItemSpawnerV2, int>("SetPageMode");

		[HarmonyPostfix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private static void Start_Postfix(ItemSpawnerV2 __instance)
		{
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Expected I4, but got Unknown
			Plugin.Log.LogInfo((object)"Setting initial item spawner preferences.");
			ItemSpawnerV2Tag itemSpawnerV2Tag = ((Component)__instance).GetComponent<ItemSpawnerV2Tag>();
			if ((Object)(object)itemSpawnerV2Tag == (Object)null)
			{
				itemSpawnerV2Tag = ((Component)__instance).gameObject.AddComponent<ItemSpawnerV2Tag>();
				((Object)itemSpawnerV2Tag).hideFlags = (HideFlags)61;
			}
			SaveUIReferences(__instance, itemSpawnerV2Tag);
			if (Plugin.PluginConfig.OpenRelatedVaultFilesByDefault.Value)
			{
				m_detailsLinkedResourceMode.Invoke(__instance) = (DetailsLinkedResourceMode)1;
				OptionsPanel_ButtonSet? itemDetailsListModeButtonSet = _itemDetailsListModeButtonSet;
				if (itemDetailsListModeButtonSet != null)
				{
					itemDetailsListModeButtonSet.SetSelectedButton(1);
				}
			}
			ItemSpawnerDefaultPageDto value = Plugin.PluginConfig.ItemSpawnerDefaultPage.Value;
			PageMode? val = value switch
			{
				ItemSpawnerDefaultPageDto.WelcomePage => (PageMode)0, 
				ItemSpawnerDefaultPageDto.Firearms => (PageMode)1, 
				ItemSpawnerDefaultPageDto.SaveAndLoad => (PageMode)7, 
				_ => null, 
			};
			int? num = value switch
			{
				ItemSpawnerDefaultPageDto.WelcomePage => 0, 
				ItemSpawnerDefaultPageDto.Firearms => 1, 
				ItemSpawnerDefaultPageDto.SaveAndLoad => 6, 
				_ => null, 
			};
			if (val.HasValue)
			{
				SetPageMode(__instance, (int)val.Value);
			}
			if (num.HasValue)
			{
				OptionsPanel_ButtonSet? topBarCategoryButtonSet = _topBarCategoryButtonSet;
				if (topBarCategoryButtonSet != null)
				{
					topBarCategoryButtonSet.SetSelectedButton(num.Value);
				}
			}
			Plugin.Log.LogInfo((object)"Finished setting initial item spawner preferences.");
		}

		private static void SaveUIReferences(ItemSpawnerV2 __instance, ItemSpawnerV2Tag tag)
		{
			Transform transform = ((Component)__instance).transform;
			Transform obj = transform.Find("Canvas/0_TopBar/BTN_Cat_7_Saved");
			_saveLoadCategoryButton = ((obj != null) ? ((Component)obj).GetComponent<FVRPointableButton>() : null);
			if ((Object)(object)_saveLoadCategoryButton == (Object)null)
			{
				Plugin.Log.LogError((object)"_saveLoadCategoryButton is null");
			}
			Transform obj2 = transform.Find("Canvas/0_TopBar/BTNSet_Cat");
			_topBarCategoryButtonSet = ((obj2 != null) ? ((Component)obj2).GetComponentInChildren<OptionsPanel_ButtonSet>(true) : null);
			if ((Object)(object)_topBarCategoryButtonSet == (Object)null)
			{
				Plugin.Log.LogError((object)"_topBarCategoryButtonSet is null");
			}
			Transform obj3 = transform.Find("Canvas/3_ItemDetailsPage/BTNSet_DetailListMode");
			_itemDetailsListModeButtonSet = ((obj3 != null) ? ((Component)obj3).GetComponentInChildren<OptionsPanel_ButtonSet>(true) : null);
			if ((Object)(object)_itemDetailsListModeButtonSet == (Object)null)
			{
				Plugin.Log.LogError((object)"_itemDetailsListModeButtonSet is null");
			}
			Transform val = transform.Find("Canvas/4_VaultFileList/VLG_FileList");
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)"vaultFileListGameO is null");
				return;
			}
			List<GameObject> allChildren = val.GetAllChildren();
			int num = 0;
			foreach (GameObject item in allChildren)
			{
				if (((Object)item).name.StartsWith("BTN_FileList"))
				{
					if ((Object)(object)item.GetComponent<VaultFileButtonTag>() == (Object)null)
					{
						VaultFileButtonTag vaultFileButtonTag = item.AddComponent<VaultFileButtonTag>();
						vaultFileButtonTag.ItemSpawner = __instance;
						vaultFileButtonTag.ItemSpawnerTag = tag;
						vaultFileButtonTag.ButtonIndexOnPage = num;
						((Object)vaultFileButtonTag).hideFlags = (HideFlags)61;
					}
					Plugin.Log.LogDebug((object)("Attached VaultFileButtonTag to: " + ((Object)item).name));
					num++;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("BTN_Details_PressTutorialVaultButton")]
		private static void BTN_Details_PressTutorialVaultButton_Postfix(ItemSpawnerV2 __instance)
		{
			if ((int)m_detailsLinkedResourceMode.Invoke(__instance) == 1)
			{
				OptionsPanel_ButtonSet? topBarCategoryButtonSet = _topBarCategoryButtonSet;
				if (topBarCategoryButtonSet != null)
				{
					topBarCategoryButtonSet.SetSelectedButton(6);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("SetPageMode")]
		private static void SetPageMode_Postfix(ItemSpawnerV2 __instance, int i)
		{
			if (i == 7)
			{
				CoroutineRunner.Run(ScheduleSetCategoryButtonSetToSaveLoad());
			}
		}

		private static IEnumerator ScheduleSetCategoryButtonSetToSaveLoad()
		{
			yield return (object)new WaitForSecondsRealtime(0.005f);
			OptionsPanel_ButtonSet? topBarCategoryButtonSet = _topBarCategoryButtonSet;
			if (topBarCategoryButtonSet != null)
			{
				topBarCategoryButtonSet.SetSelectedButton(6);
			}
		}
	}
	[HarmonyWrapSafe]
	[HarmonyPatch(typeof(FVRPointableButton))]
	internal static class PreviewVaultFileOnHoverButtonPatcher
	{
		private static readonly FieldRef<FVRPointableButton, bool> m_isBeingPointedAt = AccessTools.FieldRefAccess<FVRPointableButton, bool>("m_isBeingPointedAt");

		private static readonly FieldRef<ItemSpawnerV2_VaultFileList, VaultFile[]> _childItems = AccessTools.FieldRefAccess<ItemSpawnerV2_VaultFileList, VaultFile[]>("_childItems");

		private static readonly FieldRef<ItemSpawnerV2_VaultFileList, int> _currentPage = AccessTools.FieldRefAccess<ItemSpawnerV2_VaultFileList, int>("_currentPage");

		private static readonly FieldRef<ItemSpawnerV2_VaultFileList, ItemSpawnerV2_VaultFileListButton[]> _fileButtons = AccessTools.FieldRefAccess<ItemSpawnerV2_VaultFileList, ItemSpawnerV2_VaultFileListButton[]>("_fileButtons");

		private static readonly FieldRef<ItemSpawnerV2_VaultFileDetails, bool> _unsavedChanges = AccessTools.FieldRefAccess<ItemSpawnerV2_VaultFileDetails, bool>("_unsavedChanges");

		public static readonly Dictionary<FVRPointableButton, VaultFileButtonTag?> ButtonTagsCache = new Dictionary<FVRPointableButton, VaultFileButtonTag>();

		[HarmonyPrefix]
		[HarmonyPatch("Update")]
		private static void Update_Prefix(FVRPointableButton __instance)
		{
			if (!Plugin.PluginConfig.PreviewVaultFilesOnHover.Value)
			{
				return;
			}
			if (!ButtonTagsCache.TryGetValue(__instance, out VaultFileButtonTag value))
			{
				value = ((Component)__instance).GetComponent<VaultFileButtonTag>();
				ButtonTagsCache[__instance] = value;
				Plugin.Log.LogDebug((object)("[PreviewVaultFileOnHoverButtonPatcher] " + $"Caching buttonTag={value} for {__instance}"));
			}
			if ((Object)(object)value == (Object)null)
			{
				return;
			}
			ItemSpawnerV2Tag itemSpawnerTag = value.ItemSpawnerTag;
			if ((Object)(object)itemSpawnerTag == (Object)null || _unsavedChanges.Invoke(value.VaultFileDetails))
			{
				return;
			}
			if (m_isBeingPointedAt.Invoke(__instance))
			{
				if (value.ExecuteCodeOnHover)
				{
					value.ExecuteCodeOnHover = false;
					PreviewVaultFile(value, itemSpawnerTag);
				}
			}
			else if (!value.ExecuteCodeOnHover)
			{
				value.ExecuteCodeOnHover = true;
				value.HideVaultFilePreviewCoroutine = CoroutineRunner.Run(ScheduleHideVaultFilePreview(value, itemSpawnerTag));
			}
		}

		public static void PreviewVaultFile(VaultFileButtonTag tag, ItemSpawnerV2Tag spawnerTag)
		{
			if (tag.HideVaultFilePreviewCoroutine != null)
			{
				CoroutineRunner.Stop(tag.HideVaultFilePreviewCoroutine);
			}
			spawnerTag.VaultFilePreviewCounter++;
			tag.VaultFilePreviewCounterLocal = spawnerTag.VaultFilePreviewCounter;
			int num = _currentPage.Invoke(tag.VaultFileList) * _fileButtons.Invoke(tag.VaultFileList).Length + tag.ButtonIndexOnPage;
			VaultFile[] array = _childItems.Invoke(tag.VaultFileList);
			if (num < array.Length)
			{
				VaultFile val = array[num];
				if (val != null)
				{
					tag.VaultFileDetails.SetFile(val);
				}
			}
		}

		private static IEnumerator ScheduleHideVaultFilePreview(VaultFileButtonTag tag, ItemSpawnerV2Tag spawnerTag)
		{
			yield return (object)new WaitForSecondsRealtime(0.02f);
			HideVaultFilePreview(tag, spawnerTag);
		}

		public static void HideVaultFilePreview(VaultFileButtonTag tag, ItemSpawnerV2Tag spawnerTag)
		{
			if (spawnerTag.VaultFilePreviewCounter <= tag.VaultFilePreviewCounterLocal)
			{
				tag.VaultFileDetails.SetFile(spawnerTag.LastSelectedVaultFile);
			}
		}
	}
	[HarmonyWrapSafe]
	[HarmonyPatch(typeof(ItemSpawnerV2_VaultFileList))]
	internal static class VaultFileListLocalVaultPatcher
	{
		private static readonly FieldRef<ItemSpawnerV2_VaultFileList, ItemTreeNode<VaultFile>> _currentNode = AccessTools.FieldRefAccess<ItemSpawnerV2_VaultFileList, ItemTreeNode<VaultFile>>("_currentNode");

		private static readonly Action<ItemSpawnerV2_VaultFileList> CollectAndRedraw = ReflectionExtensions.Delegate<ItemSpawnerV2_VaultFileList>("CollectAndRedraw");

		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void Start_Postfix(ItemSpawnerV2_VaultFileList __instance)
		{
			if (Plugin.PluginConfig.OpenLocalVaultByDefault.Value)
			{
				UgcModule localVaultModule = UgcManager.LocalVaultModule;
				ItemTreeNode<VaultFile> val = ((localVaultModule != null) ? localVaultModule.GetRootNode<VaultFile>() : null);
				if (val != null)
				{
					Plugin.Log.LogDebug((object)("[VaultFileListLocalVaultPatcher] Got local vault node: " + ((ItemTreeNode)val).Name));
					_currentNode.Invoke(__instance) = val;
					CollectAndRedraw(__instance);
				}
			}
		}
	}
	[HarmonyWrapSafe]
	[HarmonyPatch(typeof(ItemSpawnerV2_VaultFileList))]
	internal static class VaultFileListPreviewPatcher
	{
		private static readonly FieldRef<ItemSpawnerV2_VaultFileList, ItemSpawnerV2> _spawner = AccessTools.FieldRefAccess<ItemSpawnerV2_VaultFileList, ItemSpawnerV2>("_spawner");

		private static readonly FieldRef<ItemSpawnerV2_VaultFileList, VaultFile[]> _childItems = AccessTools.FieldRefAccess<ItemSpawnerV2_VaultFileList, VaultFile[]>("_childItems");

		private static readonly FieldRef<ItemSpawnerV2_VaultFileList, int> _currentPage = AccessTools.FieldRefAccess<ItemSpawnerV2_VaultFileList, int>("_currentPage");

		private static readonly FieldRef<ItemSpawnerV2_VaultFileList, ItemSpawnerV2_VaultFileListButton[]> _fileButtons = AccessTools.FieldRefAccess<ItemSpawnerV2_VaultFileList, ItemSpawnerV2_VaultFileListButton[]>("_fileButtons");

		[HarmonyPrefix]
		[HarmonyPatch("BtnFileClicked")]
		private static void BtnFileClicked_Prefix(ItemSpawnerV2_VaultFileList __instance, int i)
		{
			ItemSpawnerV2Tag component = ((Component)_spawner.Invoke(__instance)).GetComponent<ItemSpawnerV2Tag>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				return;
			}
			int num = _currentPage.Invoke(__instance);
			ItemSpawnerV2_VaultFileListButton[] array = _fileButtons.Invoke(__instance);
			int num2 = num * array.Length + i;
			VaultFile[] array2 = _childItems.Invoke(__instance);
			if (num2 >= array2.Length)
			{
				VaultFileButtonTag component2 = ((Component)array[i]).GetComponent<VaultFileButtonTag>();
				if (!((Object)(object)component2 == (Object)null))
				{
					component2.ExecuteCodeOnHover = true;
					Plugin.Log.LogDebug((object)"[BtnFileClicked_Prefix] Set buttonTag.ExecuteCodeOnHover = true");
				}
			}
			else
			{
				VaultFile val = array2[num2];
				if (val != null)
				{
					component.LastSelectedVaultFile = val;
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("FocusFile")]
		private static void FocusFile_Prefix(ItemSpawnerV2_VaultFileList __instance, VaultFile file)
		{
			ItemSpawnerV2Tag component = ((Component)_spawner.Invoke(__instance)).GetComponent<ItemSpawnerV2Tag>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.LastSelectedVaultFile = file;
			}
		}
	}
}
namespace Sirdoggy.ItemSpawnerTweaks.Data
{
	internal enum ItemSpawnerDefaultPageDto
	{
		WelcomePage,
		Firearms,
		SaveAndLoad
	}
}
namespace Sirdoggy.ItemSpawnerTweaks.Common
{
	internal class CoroutineRunner : MonoBehaviour
	{
		private static CoroutineRunner _instance;

		public static Coroutine Run(IEnumerator coroutine)
		{
			//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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)_instance))
			{
				GameObject val = new GameObject("CoroutineRunner")
				{
					hideFlags = (HideFlags)61
				};
				Object.DontDestroyOnLoad((Object)val);
				_instance = val.AddComponent<CoroutineRunner>();
			}
			return ((MonoBehaviour)_instance).StartCoroutine(coroutine);
		}

		public static void Stop(Coroutine coroutine)
		{
			((MonoBehaviour)_instance).StopCoroutine(coroutine);
		}
	}
	internal class ExceptionCatcher
	{
		private readonly ManualLogSource _log;

		public ExceptionCatcher(ManualLogSource log)
		{
			_log = log;
		}

		public void Run(Action action)
		{
			try
			{
				action();
			}
			catch (Exception ex)
			{
				_log.LogError((object)ex);
			}
		}
	}
	internal static class TransformExtensions
	{
		public static List<GameObject> GetAllChildren(this Transform gameObject)
		{
			List<GameObject> list = new List<GameObject>();
			for (int i = 0; i < ((Component)gameObject).transform.childCount; i++)
			{
				GameObject gameObject2 = ((Component)((Component)gameObject).transform.GetChild(i)).gameObject;
				list.Add(gameObject2);
			}
			return list;
		}
	}
	internal static class ReflectionExtensions
	{
		public static Action<T> Delegate<T>(string methodName)
		{
			return (Action<T>)System.Delegate.CreateDelegate(typeof(Action<T>), AccessTools.Method(typeof(T), methodName, (Type[])null, (Type[])null));
		}

		public static Action<T, TParam1> Delegate<T, TParam1>(string methodName)
		{
			return (Action<T, TParam1>)System.Delegate.CreateDelegate(typeof(Action<T, TParam1>), AccessTools.Method(typeof(T), methodName, (Type[])null, (Type[])null));
		}
	}
}