Decompiled source of OtherLoaderPatched v1.4.0
patchers\Sirdoggy.OldOtherLoaderDisabler.dll
Decompiled 5 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using Microsoft.CodeAnalysis; using Mono.Cecil; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyCompany("Sirdoggy")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("Sirdoggy.OldOtherLoaderDisabler")] [assembly: AssemblyTitle("OldOtherLoaderDisabler")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.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] [Microsoft.CodeAnalysis.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] [Microsoft.CodeAnalysis.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 Sirdoggy.OldOtherLoaderDisabler { public static class Patcher { private const string OtherLoaderDirectoryName = "devyndamonster-OtherLoader"; private const string OtherLoaderDllFullName = "OtherLoader.dll"; private const string OtherLoaderDllFullNameDisabled = "OtherLoader.dll.old"; public static IEnumerable<string> TargetDLLs => Enumerable.Empty<string>(); public static void Initialize() { ManualLogSource val = Logger.CreateLogSource("OldOtherLoaderDisabler"); try { val.LogMessage((object)"Attempting to disable original OtherLoader. Looking for BepInEx/plugins/devyndamonster-OtherLoader/OtherLoader.dll"); string text = Directory.GetDirectories(Paths.PluginPath, "devyndamonster-OtherLoader", SearchOption.TopDirectoryOnly).FirstOrDefault(); if (text == null) { val.LogInfo((object)"Original OtherLoader not found in plugins directory"); return; } string text2 = Path.Combine(text, "OtherLoader.dll"); string text3 = Path.Combine(text, "OtherLoader.dll.old"); if (!File.Exists(text2)) { val.LogInfo((object)("Did not resolve 'OtherLoader.dll' from path " + text2)); return; } if (File.Exists(text3)) { File.Delete(text3); } File.Move(text2, text3); val.LogInfo((object)"Successfully disabled original OtherLoader"); } catch (Exception arg) { val.LogError((object)$"Exception when trying to disable original OtherLoader: {arg}"); } } public static void Patch(AssemblyDefinition _) { } } }
OtherLoader.dll
Decompiled 5 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Security; using System.Security.Permissions; using System.Text; using System.Threading; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using FistVR; using HarmonyLib; using Microsoft.CodeAnalysis; using OtherLoader.Common; using OtherLoader.Common.FVR; using OtherLoader.Common.Logging; using OtherLoader.ItemSpawner; using OtherLoader.ItemSpawner.CustomCategories; using OtherLoader.ItemSpawner.Patches; using OtherLoader.Loading; using OtherLoader.Loading.AssetLoaders; using OtherLoader.Loading.AssetLoaders.Implementations; using OtherLoader.Loading.Model; using OtherLoader.QuickbeltPanel; using OtherLoader.UnlockAllItems; using Sodalite; using Sodalite.Api; using Stratum; using Stratum.Extensions; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyCompany("OtherLoader")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("OtherLoader")] [assembly: AssemblyTitle("OtherLoader")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.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] [Microsoft.CodeAnalysis.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] [Microsoft.CodeAnalysis.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 OtherLoader { [CreateAssetMenu(menuName = "MeatKit/Otherloader/SpawnerEntry", fileName = "New Spawner Entry")] public class ItemSpawnerEntry : ScriptableObject { [Header("Item IDs")] [Tooltip("ItemID for the main object that will spawn")] public string MainObjectID; [Tooltip("ItemIDs for items that will spawn alongside the main object")] public List<string> SpawnWithIDs = new List<string>(); [Tooltip("ItemIDs for items that appear in the secondary items section")] public List<string> SecondaryObjectIDs = new List<string>(); [Header("[OPTIONAL] Populate ItemIDs using FVRObjects directly")] public FVRObject MainObjectObj; public List<FVRObject> SpawnWithObjs = new List<FVRObject>(); public List<FVRObject> SecondaryObjs = new List<FVRObject>(); [Header("Entry Path Properties")] [Tooltip("The path for the entry")] public string EntryPath; public PageMode Page; public ESubCategory SubCategory; [Header("Display Properties")] [Tooltip("The icon that will appear in the spawner for this entry")] public Sprite EntryIcon; [Tooltip("The name of the entry")] public string DisplayName; [Tooltip("Decides wether the entry will be visible in the spawner.\n Set to false if you only want the entry visible as a secondary")] public bool IsDisplayedInMainEntry; [Tooltip("A list modding tags to allow for sorting by mod groups in itemspawner")] public List<string> ModTags = new List<string>(); [Tooltip("A list of tutorial block IDs that will appear when this entry is selected")] public List<string> TutorialBlockIDs = new List<string>(); [Header("Misc Properties")] public bool UsesLargeSpawnPad; public bool UsesHugeSpawnPad; public bool IsReward; public static ItemSpawnerEntry CreateEmpty(string path) { ItemSpawnerEntry itemSpawnerEntry = ScriptableObject.CreateInstance<ItemSpawnerEntry>(); itemSpawnerEntry.EntryPath = path; return itemSpawnerEntry; } public void PopulateIDsFromObj() { if ((Object)(object)MainObjectObj != (Object)null) { MainObjectID = MainObjectObj.ItemID; OtherLogger.Log("Assigning ItemID from MainObject: " + MainObjectID, LogTag.BundleLoading); } foreach (FVRObject spawnWithObj in SpawnWithObjs) { if (!SpawnWithIDs.Contains(spawnWithObj.ItemID)) { SpawnWithIDs.Add(spawnWithObj.ItemID); } } foreach (FVRObject secondaryObj in SecondaryObjs) { if (!SecondaryObjectIDs.Contains(secondaryObj.ItemID)) { SecondaryObjectIDs.Add(secondaryObj.ItemID); } } } public bool IsCategoryEntry() { return string.IsNullOrEmpty(MainObjectID); } internal ESubCategory? GetSpawnerSubcategory() { //IL_0073: Unknown result type (might be due to invalid IL or missing references) string[] array = (from o in EntryPath.Split(new char[1] { '/' }) where Enum.IsDefined(typeof(ESubCategory), o) select o).ToArray(); if (array.Length == 0) { return null; } return ((IEnumerable<string>)array).Select((Func<string, ESubCategory>)((string o) => (ESubCategory)Enum.Parse(typeof(ESubCategory), o))).FirstOrDefault(); } internal EItemCategory? GetSpawnerCategory() { //IL_0073: Unknown result type (might be due to invalid IL or missing references) string[] array = (from o in EntryPath.Split(new char[1] { '/' }) where Enum.IsDefined(typeof(EItemCategory), o) select o).ToArray(); if (array.Length == 0) { return null; } return ((IEnumerable<string>)array).Select((Func<string, EItemCategory>)((string o) => (EItemCategory)Enum.Parse(typeof(EItemCategory), o))).FirstOrDefault(); } internal EItemCategory? GetSpawnerCategoryNew() { //IL_004d: Unknown result type (might be due to invalid IL or missing references) string[] array = EntryPath.Split(new char[1] { '/' }); if (array.Length < 2) { return null; } string value = array[1]; if (Enum.IsDefined(typeof(EItemCategory), value)) { return (EItemCategory)Enum.Parse(typeof(EItemCategory), value); } return null; } internal ESubCategory? GetSpawnerSubCategoryNew() { //IL_004d: Unknown result type (might be due to invalid IL or missing references) string[] array = EntryPath.Split(new char[1] { '/' }); if (array.Length < 2) { return null; } string value = array[1]; if (Enum.IsDefined(typeof(ESubCategory), value)) { return (ESubCategory)Enum.Parse(typeof(ESubCategory), value); } return null; } } public delegate void StatusUpdate(float progress); internal enum LoadOrderType { LoadFirst, LoadLast, LoadUnordered } internal enum BundleStatus { Waiting, CanLoad, Loading, Loaded, Unloaded } internal class BundleLoadStatus { public readonly string BundleId; public BundleStatus Status; public LoadOrderType LoadOrderType; public BundleLoadStatus(string bundleId, LoadOrderType loadOrderType) { BundleId = bundleId; LoadOrderType = loadOrderType; Status = BundleStatus.Waiting; } } public static class LoaderStatus { private class ModLoadOrderContainer { public List<BundleLoadStatus> loadFirst = new List<BundleLoadStatus>(); public List<BundleLoadStatus> loadUnordered = new List<BundleLoadStatus>(); public List<BundleLoadStatus> loadLast = new List<BundleLoadStatus>(); public Dictionary<string, BundleLoadStatus> bundleLoadStatusDic = new Dictionary<string, BundleLoadStatus>(); public void AddToLoadOrder(string bundleID, LoadOrderType loadOrderType) { BundleLoadStatus bundleLoadStatus = new BundleLoadStatus(bundleID, loadOrderType); if (bundleLoadStatusDic.ContainsKey(bundleID)) { BundleLoadStatus bundleLoadStatus2 = bundleLoadStatusDic[bundleID]; bundleLoadStatusDic.Remove(bundleID); loadFirst.Remove(bundleLoadStatus2); loadUnordered.Remove(bundleLoadStatus2); loadLast.Remove(bundleLoadStatus2); bundleLoadStatus.Status = BundleStatus.Unloaded; bundleLoadStatus.LoadOrderType = bundleLoadStatus2.LoadOrderType; if (bundleLoadStatus2.Status != BundleStatus.Loaded && bundleLoadStatus2.Status != BundleStatus.Unloaded) { OtherLogger.LogError("Tracking a late bundle, but the data bundle isn't already loaded! Data bundle status: " + bundleLoadStatus2.Status); } } else { if (loadOrderType == LoadOrderType.LoadFirst) { if (loadFirst.Count == 0 || loadFirst.All((BundleLoadStatus o) => o.Status == BundleStatus.Loaded || o.Status == BundleStatus.Unloaded)) { bundleLoadStatus.Status = BundleStatus.CanLoad; } if (loadUnordered.Count != 0 || loadLast.Count != 0) { OtherLogger.LogError("Mod is set to load first, but it looks like unordered or load last mods are already loading! BundleID (" + bundleID + ")"); loadUnordered.ForEach(delegate(BundleLoadStatus o) { OtherLogger.LogError("Load Unordered BundleID (" + o.BundleId + ")"); }); loadLast.ForEach(delegate(BundleLoadStatus o) { OtherLogger.LogError("Load Last BundleID (" + o.BundleId + ")"); }); } } if (loadOrderType == LoadOrderType.LoadUnordered) { if (loadFirst.Count == 0 || loadFirst.All((BundleLoadStatus o) => o.Status == BundleStatus.Loaded || o.Status == BundleStatus.Unloaded)) { bundleLoadStatus.Status = BundleStatus.CanLoad; } if (loadLast.Count != 0) { OtherLogger.LogError("Mod is set to load unordered, but it looks like load last mods are already loading! BundleID (" + bundleID + ")"); loadLast.ForEach(delegate(BundleLoadStatus o) { OtherLogger.LogError("Load Last BundleID (" + o.BundleId + ")"); }); } } if (loadOrderType == LoadOrderType.LoadLast && ((loadFirst.Count == 0 && loadUnordered.Count == 0 && loadLast.Count == 0) || (loadFirst.All((BundleLoadStatus o) => o.Status == BundleStatus.Loaded || o.Status == BundleStatus.Unloaded) && loadUnordered.All((BundleLoadStatus o) => o.Status == BundleStatus.Loaded || o.Status == BundleStatus.Unloaded) && loadLast.All((BundleLoadStatus o) => o.Status == BundleStatus.Loaded || o.Status == BundleStatus.Unloaded)))) { bundleLoadStatus.Status = BundleStatus.CanLoad; } } bundleLoadStatusDic.Add(bundleID, bundleLoadStatus); switch (loadOrderType) { case LoadOrderType.LoadFirst: loadFirst.Add(bundleLoadStatus); break; case LoadOrderType.LoadLast: loadLast.Add(bundleLoadStatus); break; case LoadOrderType.LoadUnordered: loadUnordered.Add(bundleLoadStatus); break; } } public bool CanBundleLoad(string bundleID) { BundleLoadStatus bundleLoadStatus = bundleLoadStatusDic[bundleID]; if (bundleLoadStatus.Status == BundleStatus.Loaded || bundleLoadStatus.Status == BundleStatus.Loading || bundleLoadStatus.Status == BundleStatus.Unloaded) { OtherLogger.LogError("Mod is already loading or loaded, but something is still asking to load it! BundleID (" + bundleID + ")"); return false; } return bundleLoadStatus.Status == BundleStatus.CanLoad; } public void MarkBundleAsLoaded(string bundleID, bool permanentlyLoaded) { BundleLoadStatus bundleLoadStatus = bundleLoadStatusDic[bundleID]; if (permanentlyLoaded) { bundleLoadStatus.Status = BundleStatus.Loaded; } else { bundleLoadStatus.Status = BundleStatus.Unloaded; } if (bundleLoadStatus.LoadOrderType == LoadOrderType.LoadFirst) { BundleLoadStatus bundleLoadStatus2 = loadFirst.FirstOrDefault((BundleLoadStatus o) => o.Status == BundleStatus.Waiting); if (bundleLoadStatus2 != null) { bundleLoadStatus2.Status = BundleStatus.CanLoad; } else if (loadUnordered.Count > 0) { loadUnordered.ForEach(delegate(BundleLoadStatus o) { o.Status = BundleStatus.CanLoad; }); } else if (loadLast.Count > 0) { loadLast[0].Status = BundleStatus.CanLoad; } } else if (bundleLoadStatus.LoadOrderType == LoadOrderType.LoadUnordered) { if (loadUnordered.All((BundleLoadStatus o) => o.Status == BundleStatus.Loaded || o.Status == BundleStatus.Unloaded) && loadLast.Count != 0) { loadLast[0].Status = BundleStatus.CanLoad; } } else if (bundleLoadStatus.LoadOrderType == LoadOrderType.LoadLast) { BundleLoadStatus bundleLoadStatus3 = loadLast.FirstOrDefault((BundleLoadStatus o) => o.Status == BundleStatus.Waiting); if (bundleLoadStatus3 != null) { bundleLoadStatus3.Status = BundleStatus.CanLoad; } } } public List<BundleLoadStatus> GetBundleDependencies(string bundleID) { List<BundleLoadStatus> list = new List<BundleLoadStatus>(); BundleLoadStatus bundleLoadStatus = bundleLoadStatusDic[bundleID]; if (bundleLoadStatus.LoadOrderType == LoadOrderType.LoadFirst) { foreach (BundleLoadStatus item in loadFirst) { if (item.BundleId == bundleID) { break; } if (!AnvilManager.m_bundles.m_lookup.ContainsKey(item.BundleId)) { list.Add(item); } } } else if (bundleLoadStatus.LoadOrderType == LoadOrderType.LoadUnordered) { foreach (BundleLoadStatus item2 in loadFirst) { if (!AnvilManager.m_bundles.m_lookup.ContainsKey(item2.BundleId)) { list.Add(item2); } } } else if (bundleLoadStatus.LoadOrderType == LoadOrderType.LoadLast) { foreach (BundleLoadStatus item3 in loadFirst) { if (!AnvilManager.m_bundles.m_lookup.ContainsKey(item3.BundleId)) { list.Add(item3); } } foreach (BundleLoadStatus item4 in loadUnordered) { if (!AnvilManager.m_bundles.m_lookup.ContainsKey(item4.BundleId)) { list.Add(item4); } } foreach (BundleLoadStatus item5 in loadLast) { if (item5.BundleId == bundleID) { break; } if (!AnvilManager.m_bundles.m_lookup.ContainsKey(item5.BundleId)) { list.Add(item5); } } } return list; } } private static Dictionary<string, float> trackedLoaders = new Dictionary<string, float>(); private static List<string> activeLoaders = new List<string>(); private static Dictionary<string, ModLoadOrderContainer> orderedLoadingLists = new Dictionary<string, ModLoadOrderContainer>(); public static float LoadStartTime; public static float LastLoadEventTime; private const float LoadTimeBuffer = 2f; public static int NumActiveLoaders => activeLoaders.Count; public static List<string> LoadingItems => new List<string>(activeLoaders); public static event StatusUpdate? ProgressUpdated; public static float GetLoaderProgress() { if (trackedLoaders.Count == 0) { return 0f; } float num = 0f; foreach (float value in trackedLoaders.Values) { num += value; } if (Time.realtimeSinceStartup - LastLoadEventTime > 2f) { return num / (float)trackedLoaders.Count; } return Mathf.Min(num / (float)trackedLoaders.Count, 0.99f); } internal static IEnumerator LoadTimeCoroutine() { LastLoadEventTime = Time.realtimeSinceStartup; float progress; for (progress = GetLoaderProgress(); progress < 1f; progress = GetLoaderProgress()) { yield return null; LoaderStatus.ProgressUpdated?.Invoke(progress); } LoaderStatus.ProgressUpdated?.Invoke(progress); OtherLogger.Log($"All items loaded, took {Time.realtimeSinceStartup - LoadStartTime:0.000} seconds!"); } internal static void AddActiveLoader(string bundleID) { if (!activeLoaders.Contains(bundleID)) { activeLoaders.Add(bundleID); } } internal static void RemoveActiveLoader(string bundleID, bool permanentlyLoaded) { if (activeLoaders.Contains(bundleID)) { activeLoaders.Remove(bundleID); string modPathFromUniqueID = GetModPathFromUniqueID(bundleID); orderedLoadingLists[modPathFromUniqueID].MarkBundleAsLoaded(bundleID, permanentlyLoaded); LastLoadEventTime = Time.realtimeSinceStartup; } } internal static void TrackLoader(string bundleID, LoadOrderType loadOrderType) { if (trackedLoaders.Count == 0) { LoadStartTime = Time.realtimeSinceStartup; OtherLoader.CoroutineStarter.Invoke(LoadTimeCoroutine()); } LastLoadEventTime = Time.realtimeSinceStartup; if (!trackedLoaders.ContainsKey(bundleID)) { trackedLoaders.Add(bundleID, 0f); } string modPathFromUniqueID = GetModPathFromUniqueID(bundleID); if (!orderedLoadingLists.ContainsKey(modPathFromUniqueID)) { OtherLogger.Log("Adding new load order entry for mod", LogTag.BundleLoading); orderedLoadingLists.Add(modPathFromUniqueID, new ModLoadOrderContainer()); } orderedLoadingLists[modPathFromUniqueID].AddToLoadOrder(bundleID, loadOrderType); OtherLogger.Log($"Tracking modded bundle ({bundleID}), Load Order ({loadOrderType})", LogTag.BundleLoading); } internal static bool CanOrderedModLoad(string bundleID) { string modPathFromUniqueID = GetModPathFromUniqueID(bundleID); if (!orderedLoadingLists.ContainsKey(modPathFromUniqueID)) { throw new Exception("Mod was not found in load order! BundleID: " + bundleID); } if (PluginConfig.MaxActiveLoaders <= 0 || NumActiveLoaders < PluginConfig.MaxActiveLoaders) { return orderedLoadingLists[modPathFromUniqueID].CanBundleLoad(bundleID); } return false; } internal static void PrintWaitingBundles(string bundleID) { OtherLogger.Log("Current Active Loaders: " + NumActiveLoaders); string modPathFromUniqueID = GetModPathFromUniqueID(bundleID); foreach (BundleLoadStatus item in (from o in orderedLoadingLists[modPathFromUniqueID].GetBundleDependencies(bundleID) where o.Status != BundleStatus.Loaded && o.Status != BundleStatus.Unloaded select o).ToList()) { OtherLogger.Log("Waiting on bundle: " + item.BundleId + ", Status: " + item.Status); } } internal static void UpdateProgress(string bundleID, float progress) { if (trackedLoaders.ContainsKey(bundleID)) { trackedLoaders[bundleID] = progress; } } internal static List<BundleLoadStatus> GetBundleDependencies(string bundleID) { string modPathFromUniqueID = GetModPathFromUniqueID(bundleID); return orderedLoadingLists[modPathFromUniqueID].GetBundleDependencies(bundleID); } private static string GetModPathFromUniqueID(string bundleID) { return bundleID.Split(new string[1] { " : " }, StringSplitOptions.None)[0].Trim(); } } [BepInPlugin("h3vr.otherloader", "OtherLoaderPatched", "1.4.0")] [BepInDependency("stratum", "1.1.0")] [BepInDependency("nrgill28.Sodalite", "1.4.1")] public class OtherLoader : StratumPlugin { private class DirectLoadMod { public readonly string Path; public readonly string LoadFirst; public readonly string LoadAny; public readonly string LoadLast; public DirectLoadMod(string path, string loadFirst, string loadAny, string loadLast) { Path = path; LoadFirst = loadFirst; LoadAny = loadAny; LoadLast = loadLast; base..ctor(); } } private const string OtherLoaderVersion = "1.4.0"; public static readonly Dictionary<string, ItemSpawnerEntry> SpawnerEntriesByID = new Dictionary<string, ItemSpawnerEntry>(); internal static readonly Dictionary<string, string> ManagedBundles = new Dictionary<string, string>(); internal static CoroutineStarter CoroutineStarter = null; private static readonly List<DirectLoadMod> DirectLoadMods = new List<DirectLoadMod>(); private void Awake() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Expected O, but got Unknown //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Expected O, but got Unknown PluginConfig.Initialize(); OtherLogger.Initialize(); CoroutineStarter = new CoroutineStarter(((MonoBehaviour)this).StartCoroutine); if (PluginConfig.ItemUnlocker != 0) { Harmony.CreateAndPatchAll(typeof(RewardUnlocksPatcher), (string)null); } Harmony.CreateAndPatchAll(typeof(AnvilRuntimeLoadingPatcher), (string)null); Harmony.CreateAndPatchAll(typeof(QuickbeltPanelPatcher), (string)null); Harmony.CreateAndPatchAll(typeof(ItemSpawnerV2InitialPatcher), (string)null); Harmony.CreateAndPatchAll(typeof(ItemSpawnerV2SimpleModePatcher), (string)null); if (PluginConfig.PreventSelectingModTagsFromHeldObject) { Harmony.CreateAndPatchAll(typeof(ItemSpawnerV2TagModePatcher), (string)null); } if (PluginConfig.AddUnloadButton) { WristMenuAPI.Buttons.Add(new WristMenuButton("Unload Bundles", (ButtonClickEvent)delegate { UnloadAllModdedBundles(); })); } } private void Start() { GM.SetRunningModded(); } public override void OnSetup(IStageContext<Empty> ctx) { ctx.Loaders.Add("icon", (FileSystemInfo _) => default(Empty)); } public override IEnumerator OnRuntime(IStageContext<IEnumerator> ctx) { ctx.Loaders.Add("item_data", MainLoader.BundlePrepareLate); ctx.Loaders.Add("item_first_late", (FileSystemInfo handle) => MainLoader.BundleRegisterLate(handle, LoadOrderType.LoadFirst)); ctx.Loaders.Add("item_unordered_late", (FileSystemInfo handle) => MainLoader.BundleRegisterLate(handle, LoadOrderType.LoadUnordered)); ctx.Loaders.Add("item_last_late", (FileSystemInfo handle) => MainLoader.BundleRegisterLate(handle, LoadOrderType.LoadLast)); ctx.Loaders.Add("item", (FileSystemInfo handle) => MainLoader.BundleLoadImmediate(handle, LoadOrderType.LoadFirst)); ctx.Loaders.Add("item_unordered", (FileSystemInfo handle) => MainLoader.BundleLoadImmediate(handle, LoadOrderType.LoadUnordered)); ctx.Loaders.Add("item_last", (FileSystemInfo handle) => MainLoader.BundleLoadImmediate(handle, LoadOrderType.LoadLast)); MainLoader.LoadLegacyBundles(CoroutineStarter); foreach (DirectLoadMod directLoadMod in DirectLoadMods) { MainLoader.BundleLoadDirectFromDirectory(CoroutineStarter, directLoadMod.Path, directLoadMod.LoadFirst.Split(new char[1] { ',' }), directLoadMod.LoadAny.Split(new char[1] { ',' }), directLoadMod.LoadLast.Split(new char[1] { ',' })); } DirectLoadMods.Clear(); LoaderStatus.ProgressUpdated += OnLoaderProgress; yield break; } private static void OnLoaderProgress(float progress) { if (!(progress < 1f)) { LoaderStatus.ProgressUpdated -= OnLoaderProgress; ItemManagerDebugger.TryPrintEntries(); SpawnerTilesDatabase.TryCreateTestCategories(); } } public static void RegisterDirectLoad(string path, string guid, string dependancies, string loadFirst, string loadAny, string loadLast) { DirectLoadMods.Add(new DirectLoadMod(path, loadFirst, loadAny, loadLast)); } private void UnloadAllModdedBundles() { foreach (string item in ManagedBundles.Keys.Where((string bundleID) => AnvilManager.m_bundles.m_lookup.ContainsKey(bundleID))) { OtherLogger.Log("Unloading bundle {" + item + "}"); AnvilCallback<AssetBundle> val = (AnvilCallback<AssetBundle>)(object)AnvilManager.m_bundles.m_lookup[item]; AnvilManager.m_bundles.m_loading.Remove((AnvilCallbackBase)(object)val); AnvilManager.m_bundles.m_lookup.Remove(item); val.Result.Unload(false); } } } internal static class PluginAssets { private const string PluginFolderName = "Sirdoggy-OtherLoaderPatched"; private static readonly string AssetsRelativePath = Path.Combine("Sirdoggy-OtherLoaderPatched", "assets"); private static readonly string AssetsFullPath = Path.Combine(Paths.PluginPath, AssetsRelativePath); public static readonly Sprite? UnknownFolder = SpriteMaker.CreateFromImage(Path.Combine(AssetsFullPath, "UnknownFolder.png")); } internal static class PluginConfig { public static bool AddUnloadButton; public static bool EnableLogTraces; public static bool ShowDebugItemSpawnerEntries; public static bool OptimizeMemory; public static int MaxActiveLoaders; public static ItemUnlockerMode ItemUnlocker; public static bool PreventSelectingModTagsFromHeldObject; public static ConfigEntry<bool> ColoredLogsMutable; public static ConfigEntry<LogTag> LogTagsMutable; private static ConfigFile _configFile; private const string ConfigFileName = "OtherLoaderPatched.cfg"; public static void Initialize() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown _configFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "OtherLoaderPatched.cfg"), true); AddUnloadButton = _configFile.Bind<bool>("Debug", "AddUnloadButton", false, "When true, and Sodalite is installed, you'll have a wrist menu button that can unload all modded asset bundles for testing purposes.").Value; EnableLogTraces = _configFile.Bind<bool>("Debug", "EnableLogTraces", false, "Affects performance, only enable when debugging. When true, method call traces will be included in logs.").Value; ShowDebugItemSpawnerEntries = _configFile.Bind<bool>("Debug", "ShowDebugItemSpawnerEntries", false, "When true, debug spawner entries will be added to the item spawner's custom categories tab.").Value; OptimizeMemory = _configFile.Bind<bool>("General", "OptimizeMemory", true, "When true, modded assets will be loaded on-demand instead of kept in memory.").Value; MaxActiveLoaders = _configFile.Bind<int>("General", "MaxActiveLoaders", 6, "Sets the number of mods that can be loading at once when first launching the game. Values less than 1 will result in all mods being loaded at the same time.").Value; ItemUnlocker = _configFile.Bind<ItemUnlockerMode>("General", "ItemUnlocker", ItemUnlockerMode.Disabled, "Cheat. Unlocks all reward/hidden items, including ones that can only spawn in T&H. Using this won't affect your H3VR save file.").Value; PreventSelectingModTagsFromHeldObject = _configFile.Bind<bool>("General", "PreventSelectingModTagsFromHeldObject", true, "ModTags will be skipped when using the 'Select Tags From Held Object' button.").Value; ColoredLogsMutable = _configFile.Bind<bool>("Logging", "ColoredLogs", true, "When true, logs will change colors depending on their LogTag."); LogTagsMutable = _configFile.Bind<LogTag>("Logging", "LogTags", LogTag.General, "Controls which types of logs should be enabled. Errors and warnings will always be logged, regardless of this setting."); } } } namespace OtherLoader.UnlockAllItems { public enum ItemUnlockerMode { Disabled, UnlockOnlyFirearmsAndAmmo, UnlockAllItems } [HarmonyPriority(600)] [HarmonyWrapSafe] internal static class RewardUnlocksPatcher { private static int _activeMethods; [HarmonyPatch(typeof(RewardUnlocks), "IsRewardUnlocked", new Type[] { typeof(ItemSpawnerID) })] [HarmonyPostfix] private static void IsRewardUnlocked_Postfix(ItemSpawnerID ID, ref bool __result) { if (_activeMethods == 0) { return; } if (!__result) { if (PluginConfig.ItemUnlocker == ItemUnlockerMode.UnlockOnlyFirearmsAndAmmo && !ID.IsFirearm() && !ID.IsAmmo()) { OtherLogger.Log("Reward item '" + ID.DisplayName + "' is not firearm or ammo, skipping...", LogTag.ItemUnlocker); return; } OtherLogger.Log("Game checked if '" + ID.DisplayName + "' is unlocked, returning true!", LogTag.ItemUnlocker); if (!ID.ModTags.Contains("GrantedByItemUnlocker")) { ID.ModTags = ID.ModTags.Concat(new <>z__ReadOnlySingleElementList<string>("GrantedByItemUnlocker")).ToList(); } } __result = true; } private static void AddActiveMethod() { Interlocked.Increment(ref _activeMethods); } private static void RemoveActiveMethod() { if (Interlocked.Decrement(ref _activeMethods) < 0) { Interlocked.Exchange(ref _activeMethods, 0); } } [HarmonyPatch(typeof(IM), "GenerateItemDBs")] [HarmonyPrefix] private static void GenerateItemDBs_Prefix() { AddActiveMethod(); } [HarmonyPatch(typeof(IM), "GenerateItemDBs")] [HarmonyFinalizer] private static Exception GenerateItemDBs_Finalizer(Exception __exception) { RemoveActiveMethod(); return __exception; } [HarmonyPatch(typeof(ItemSpawnerV2), "RedrawDetailsCanvas")] [HarmonyPrefix] private static void RedrawDetailsCanvas_Prefix() { AddActiveMethod(); } [HarmonyPatch(typeof(ItemSpawnerV2), "RedrawDetailsCanvas")] [HarmonyFinalizer] private static Exception RedrawDetailsCanvas_Finalizer(Exception __exception) { RemoveActiveMethod(); return __exception; } } } namespace OtherLoader.QuickbeltPanel { internal class QBslotPageController : MonoBehaviour { public OptionsPanel_ButtonSet QBslotButtonSet; public GameObject ButtonNextPage; public GameObject ButtonPreviousPage; public int currentPage; public void Start() { SetVisibility(); } public void SetButtons() { ButtonNextPage.SetActive(true); ButtonPreviousPage.SetActive(true); if (currentPage <= 0) { ButtonPreviousPage.SetActive(false); } int num = Mathf.CeilToInt((float)(QBslotButtonSet.ButtonsInSet.Length / 14)); if (currentPage >= num) { ButtonNextPage.SetActive(false); } } public void SetVisibility() { SetButtons(); FVRPointableButton[] buttonsInSet = QBslotButtonSet.ButtonsInSet; for (int i = 0; i < buttonsInSet.Length; i++) { ((Component)buttonsInSet[i]).gameObject.SetActive(false); } int num = currentPage * 14; int num2 = num + 14; for (int j = num; j < num2 && j < QBslotButtonSet.ButtonsInSet.Length; j++) { ((Component)QBslotButtonSet.ButtonsInSet[j]).gameObject.SetActive(true); } } public void GotoPreviousPage() { currentPage--; SetVisibility(); } public void GotoNextPage() { currentPage++; SetVisibility(); } } internal static class QuickbeltPanelPatcher { public const int QbsPerPage = 14; [HarmonyPatch(typeof(OptionsScreen_Quickbelt), "Awake")] [HarmonyPrefix] public static bool Patch_AddScreens(OptionsScreen_Quickbelt __instance) { //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Expected O, but got Unknown //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Expected O, but got Unknown //IL_0201: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Expected O, but got Unknown //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_0257: Expected O, but got Unknown OptionsScreen_Quickbelt __instance2 = __instance; QBslotPageController pageController = ((Component)__instance2).gameObject.AddComponent<QBslotPageController>(); pageController.QBslotButtonSet = __instance2.OBS_SlotStyle; GameObject gameObject = ((Component)__instance2.OBS_Handedness.ButtonsInSet[0]).gameObject; FVRPointableButton[] buttonsInSet = __instance2.OBS_SlotStyle.ButtonsInSet; for (int i = 0; i < buttonsInSet.Length; i++) { Object.Destroy((Object)(object)((Component)buttonsInSet[i]).gameObject); } __instance2.OBS_SlotStyle.ButtonsInSet = (FVRPointableButton[])(object)new FVRPointableButton[ManagerSingleton<GM>.Instance.QuickbeltConfigurations.Length]; for (int j = 0; j < __instance2.OBS_SlotStyle.ButtonsInSet.Length; j++) { int num = j % 14; int column = num % 4; int row = (int)Mathf.Floor((float)num / 4f); OtherLogger.Log("Adding QB " + ((Object)ManagerSingleton<GM>.Instance.QuickbeltConfigurations[j]).name, LogTag.BundleLoading); GameObject val = Object.Instantiate<GameObject>(gameObject, ((Component)__instance2.OBS_SlotStyle).transform, true); FVRPointableButton component = val.GetComponent<FVRPointableButton>(); __instance2.OBS_SlotStyle.ButtonsInSet[j] = component; string text = ((Object)ManagerSingleton<GM>.Instance.QuickbeltConfigurations[j]).name.Split(new char[1] { '_' }).Last(); Button uiButton = SetQBSlotOptionsPanelButton(val, row, column, text); ((UnityEvent)uiButton.onClick).AddListener((UnityAction)delegate { __instance2.SetSlotStyle(((Component)uiButton).transform.GetSiblingIndex()); }); ((UnityEvent)uiButton.onClick).AddListener((UnityAction)delegate { __instance2.OBS_SlotStyle.SetSelectedButton(((Component)uiButton).transform.GetSiblingIndex()); }); } Button val2 = SetQBSlotOptionsPanelButton(Object.Instantiate<GameObject>(gameObject, ((Component)__instance2.OBS_SlotStyle).transform, true), 3, 2, "Previous Page"); ((UnityEvent)val2.onClick).AddListener((UnityAction)delegate { pageController.GotoPreviousPage(); }); pageController.ButtonPreviousPage = ((Component)val2).gameObject; val2 = SetQBSlotOptionsPanelButton(Object.Instantiate<GameObject>(gameObject, ((Component)__instance2.OBS_SlotStyle).transform, true), 3, 3, "Next Page"); ((UnityEvent)val2.onClick).AddListener((UnityAction)delegate { pageController.GotoNextPage(); }); pageController.ButtonNextPage = ((Component)val2).gameObject; return true; } public static Button SetQBSlotOptionsPanelButton(GameObject button, int row, int column, string text) { //IL_0020: 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) float num = -100 + 125 * column; float num2 = -40 + -45 * row; button.transform.localPosition = new Vector3(num, num2, button.transform.localPosition.z); ((Component)button.gameObject.transform.GetChild(0)).GetComponent<Text>().text = text; Button component = button.GetComponent<Button>(); ((UnityEventBase)component.onClick).RemoveAllListeners(); return component; } [HarmonyPatch(typeof(FVRPlayerBody), "ConfigureQuickbelt")] [HarmonyPrefix] public static bool Patch_OutOfIndexPreventer(ref int index) { index = Mathf.Clamp(index, 0, ManagerSingleton<GM>.Instance.QuickbeltConfigurations.Length - 1); return true; } } } namespace OtherLoader.Loading { [HarmonyWrapSafe] internal static class AnvilRuntimeLoadingPatcher { [HarmonyPatch(typeof(AnvilManager), "GetAssetBundleAsyncInternal")] [HarmonyPrefix] private static bool GetAssetBundleAsyncInternal_Prefix(string bundle, ref AnvilCallback<AssetBundle> __result) { if (OtherLoader.ManagedBundles.TryGetValue(bundle, out string value)) { AnvilCallbackBase val = default(AnvilCallbackBase); if (AnvilManager.m_bundles.TryGetValue(bundle, ref val)) { OtherLogger.Log("Tried to load modded asset bundle, and it's already loaded: " + bundle, LogTag.BundleLoading); __result = val as AnvilCallback<AssetBundle>; return false; } OtherLogger.Log("Tried to load modded asset bundle, and it's not yet loaded: " + bundle, LogTag.BundleLoading); AnvilCallback<AssetBundle> val2 = UnityAssetBundleLoader.LoadAssetsFromBundlePatch(value); List<BundleLoadStatus> bundleDependencies = LoaderStatus.GetBundleDependencies(bundle); if (bundleDependencies.Count > 0) { OtherLogger.Log("Dependencies:", LogTag.BundleLoading); bundleDependencies.ForEach(delegate(BundleLoadStatus o) { OtherLogger.Log(OtherLoader.ManagedBundles[o.BundleId], LogTag.BundleLoading); }); AnvilCallback<AssetBundle> val3 = (val2.m_dependancy = UnityAssetBundleLoader.LoadAssetsFromBundlePatch(OtherLoader.ManagedBundles[bundleDependencies.Last().BundleId])); AnvilManager.m_bundles.Add(bundleDependencies.Last().BundleId, (AnvilCallbackBase)(object)val3); for (int num = bundleDependencies.Count - 2; num >= 0; num--) { val3.m_dependancy = UnityAssetBundleLoader.LoadAssetsFromBundlePatch(OtherLoader.ManagedBundles[bundleDependencies[num].BundleId]); val3 = val3.m_dependancy; AnvilManager.m_bundles.Add(bundleDependencies[num].BundleId, (AnvilCallbackBase)(object)val3); } } __result = val2; AnvilManager.m_bundles.Add(bundle, (AnvilCallbackBase)(object)__result); return false; } return true; } [HarmonyPatch(typeof(AnvilAsset), "GetGameObjectAsync")] [HarmonyPatch(typeof(AnvilAsset), "GetGameObject")] [HarmonyPrefix] public static bool SetBundlePatch(AnvilAsset __instance) { if (string.IsNullOrEmpty(__instance.m_anvilPrefab.Bundle)) { FVRObject val = (FVRObject)(object)((__instance is FVRObject) ? __instance : null); if ((Object)(object)val != (Object)null && IM.OD.TryGetValue(val.ItemID, out var value)) { __instance.m_anvilPrefab.Bundle = ((AnvilAsset)value).m_anvilPrefab.Bundle; } } return true; } } internal static class MainLoader { private static readonly IAssetBundleLoader[] AssetLoaders = new IAssetBundleLoader[13] { new MechanicalAccuracyChartLoader(), new FVRObjectLoader(), new RoundDisplayDataLoader(), new ItemSpawnerCategoryLoader(), new ItemSpawnerIdLoader(), new ItemSpawnerEntryLoader(), new HandlingGrabSetLoader(), new HandlingReleaseSetLoader(), new HandlingSlotSetLoader(), new BulletImpactSetLoader(), new AudioImpactSetLoader(), new TutorialBlockLoader(), new QuickBeltLoader() }; public static IEnumerator BundleLoadImmediate(FileSystemInfo handle, LoadOrderType loadOrder) { return LoadBundle(new TL("BundleLoadImmediate", LogTag.BundleLoading), handle, loadOrder, allowUnload: true); } public static IEnumerator BundlePrepareLate(FileSystemInfo handle) { return LoadBundle(new TL("BundlePrepareLate", LogTag.BundleLoading), handle, LoadOrderType.LoadFirst, allowUnload: false); } public static IEnumerator BundleRegisterLate(FileSystemInfo handle, LoadOrderType loadOrder) { TL oldTL = new TL("BundleRegisterLate", LogTag.BundleLoading); FileInfo fileInfo = ExtFileSystemInfo.ConsumeFile(handle); return RegisterLateBundle(oldTL, fileInfo.Name, fileInfo.FullName, loadOrder); } public static void BundleLoadDirectFromDirectory(CoroutineStarter starter, string directoryNameFull, string[] loadFirst, string[] loadAny, string[] loadLast) { TL oldTL = new TL("BundleLoadDirectFromDirectory", LogTag.BundleLoading); foreach (KeyValuePair<string, LoadOrderType> item in loadFirst.Select((string bundle) => new KeyValuePair<string, LoadOrderType>(bundle, LoadOrderType.LoadFirst)).Concat(loadAny.Select((string bundle) => new KeyValuePair<string, LoadOrderType>(bundle, LoadOrderType.LoadUnordered))).Concat(loadLast.Select((string bundle) => new KeyValuePair<string, LoadOrderType>(bundle, LoadOrderType.LoadLast)))) { if (!string.IsNullOrEmpty(item.Key)) { starter.Invoke(LoadBundleDirect(oldTL, directoryNameFull, item.Key, item.Value)); } } } public static void LoadLegacyBundles(CoroutineStarter starter) { string text = Application.dataPath.Replace("/h3vr_Data", "/LegacyVirtualObjects"); if (!Directory.Exists(text)) { Directory.CreateDirectory(text); } TL newTL = new TL("LoadLegacyBundles", LogTag.BundleLoading); newTL.Log("Loading bundles from legacy directory (" + text + ")"); List<string> list = Directory.GetDirectories(Paths.PluginPath, "LegacyVirtualObjects", SearchOption.AllDirectories).ToList(); list.Add(text); foreach (string item in list) { newTL.Log("Legacy folder found {" + item + "}"); string[] files = Directory.GetFiles(item, "*", SearchOption.AllDirectories); foreach (string text2 in files) { if (!(Path.GetFileName(text2) != Path.GetFileNameWithoutExtension(text2))) { BundleInfo bundleInfo = new BundleInfo(text2); IEnumerator enumerator2 = ExtIEnumerator.TryCatch<Exception>(LoadAssetsFromBundle(newTL, bundleInfo, LoadOrderType.LoadUnordered, allowUnload: true), (Action<Exception>)delegate(Exception exception) { newTL.LogError("Exception when loading legacy bundle {" + bundleInfo.Name + "}\n- " + exception.Message); LoaderStatus.UpdateProgress(bundleInfo.ID, 1f); LoaderStatus.RemoveActiveLoader(bundleInfo.ID, permanentlyLoaded: true); }); starter.Invoke(enumerator2); } } } } private static IEnumerator LoadBundle(TL oldTL, FileSystemInfo handle, LoadOrderType loadOrder, bool allowUnload) { TL newTL = oldTL.New("LoadBundle"); BundleInfo bundleInfo = new BundleInfo(ExtFileSystemInfo.ConsumeFile(handle)); newTL.Log($"Loading {{{bundleInfo.Name}}} with: loadOrder {{{loadOrder}}}, allowUnload {{{allowUnload}}}"); return ExtIEnumerator.TryCatch(LoadAssetsFromBundle(newTL, bundleInfo, loadOrder, allowUnload), (Action<Exception>)delegate(Exception exception) { newTL.LogError("Exception when loading bundle {" + bundleInfo.Name + "}\n- " + exception.Message); LoaderStatus.UpdateProgress(bundleInfo.ID, 1f); LoaderStatus.RemoveActiveLoader(bundleInfo.ID, permanentlyLoaded: true); }); } private static IEnumerator RegisterLateBundle(TL oldTL, string lateBundleName, string lateBundleFullPath, LoadOrderType loadOrder) { TL tL = oldTL.New("RegisterLateBundle"); string text = lateBundleName.Replace("late_", ""); BundleInfo bundleInfo = new BundleInfo(Path.Combine(Path.GetDirectoryName(lateBundleFullPath), text), lateBundleFullPath); OtherLoader.ManagedBundles[bundleInfo.ID] = bundleInfo.ContentFullPath; LoaderStatus.TrackLoader(bundleInfo.ID, loadOrder); AnvilCallbackBase item = default(AnvilCallbackBase); if (AnvilManager.m_bundles.TryGetValue(bundleInfo.ID, ref item)) { AnvilManager.m_bundles.m_lookup.Remove(bundleInfo.ID); AnvilManager.m_bundles.m_loading.Remove(item); tL.Log("Finished registering late bundle {" + lateBundleName + "}\n- This bundle will replace prepared bundle {" + text + "}"); } else { tL.LogError("Failed to register late bundle {" + lateBundleName + "}, there is no prepared bundle it can replace.\n- There should have been a prepared bundle {" + text + "}"); } yield return null; } private static IEnumerator LoadBundleDirect(TL oldTL, string directoryNameFull, string bundleName, LoadOrderType loadOrder) { TL newTL = oldTL.New("LoadBundleDirect"); BundleInfo bundleInfo = new BundleInfo(Path.Combine(directoryNameFull, bundleName)); newTL.Log("Starting direct load bundle {" + bundleInfo.Name + "}"); string text = "late_" + bundleName; string text2 = Path.Combine(directoryNameFull, text); IEnumerator onAfterLoadAsync = null; if (File.Exists(text2)) { onAfterLoadAsync = RegisterLateBundle(newTL, text, text2, loadOrder); } return ExtIEnumerator.TryCatch(LoadAssetsFromBundle(newTL, bundleInfo, loadOrder, allowUnload: false, onAfterLoadAsync), (Action<Exception>)delegate(Exception exception) { newTL.LogError("Exception when direct loading bundle {" + bundleInfo.Name + "}\n- " + exception.Message); LoaderStatus.UpdateProgress(bundleInfo.ID, 1f); LoaderStatus.RemoveActiveLoader(bundleInfo.ID, permanentlyLoaded: true); }); } private static IEnumerator LoadAssetsFromBundle(TL oldTL, BundleInfo bundleInfo, LoadOrderType loadOrder, bool allowUnload, IEnumerator? onAfterLoadAsync = null) { TL newTL = oldTL.New("LoadAssetsFromBundle"); LoaderStatus.TrackLoader(bundleInfo.ID, loadOrder); newTL.Log("Began tracking {" + bundleInfo.Name + "}, yielding to track others..."); yield return null; newTL.Log("Waiting until bundle {" + bundleInfo.Name + "} can load..."); yield return WaitUntilBundleCanLoad(newTL, bundleInfo); float loadingTime = Time.realtimeSinceStartup; LoaderStatus.AddActiveLoader(bundleInfo.ID); LoaderStatus.UpdateProgress(bundleInfo.ID, Random.Range(0.1f, 0.3f)); newTL.Log("Beginning async load of bundle {" + bundleInfo.Name + "}"); AnvilCallback<AssetBundle> assetBundle = UnityAssetBundleLoader.LoadAssetsFromBundlePatch(bundleInfo.ContentFullPath); yield return assetBundle; yield return RunAssetLoadersOnAssetBundle(newTL, assetBundle, bundleInfo); FinishBundleLoading(newTL, assetBundle, bundleInfo, allowUnload, loadingTime); if (onAfterLoadAsync != null) { yield return onAfterLoadAsync; } } private static IEnumerator WaitUntilBundleCanLoad(TL oldTL, BundleInfo bundleInfo) { TL newTL = oldTL.New("WaitUntilBundleCanLoad"); bool overTime = false; while (!LoaderStatus.CanOrderedModLoad(bundleInfo.ID)) { if (!overTime && Time.realtimeSinceStartup - LoaderStatus.LastLoadEventTime > 30f) { newTL.Log("Bundle {" + bundleInfo.Name + "} has been waiting a long time to load!"); LoaderStatus.PrintWaitingBundles(bundleInfo.ID); overTime = true; } yield return null; } } private static IEnumerator RunAssetLoadersOnAssetBundle(TL oldTL, AnvilCallback<AssetBundle> assetBundle, BundleInfo bundleInfo) { BundleInfo bundleInfo2 = bundleInfo; TL newTL = oldTL.New("RunAssetLoadersOnAssetBundle"); IAssetBundleLoader[] assetLoaders = AssetLoaders; foreach (IAssetBundleLoader loader in assetLoaders) { yield return ExtIEnumerator.TryCatch(loader.LoadAssetsFromBundle(assetBundle.Result, bundleInfo2.ID, bundleInfo2.PluginName), (Action<Exception>)delegate(Exception exception) { newTL.LogError("Exception when loader {" + loader.GetType().Name + "} was loading assets from bundle {" + bundleInfo2.Name + "}\n- " + exception.Message); }); } } private static void FinishBundleLoading(TL oldTL, AnvilCallback<AssetBundle> bundle, BundleInfo bundleInfo, bool allowUnload, float loadingTime) { TL tL = oldTL.New("FinishBundleLoading"); bool flag = PluginConfig.OptimizeMemory && allowUnload; string text = $"Completed loading bundle {{{bundleInfo.Name}}} in {Time.realtimeSinceStartup - loadingTime:0.000} seconds!"; string message = (flag ? (text + " Optimizing memory!") : text); tL.Log(message, LogTag.General); if (flag) { bundle.Result.Unload(false); } else { AnvilManager.m_bundles.Add(bundleInfo.ID, (AnvilCallbackBase)(object)bundle); } OtherLoader.ManagedBundles.Add(bundleInfo.ID, bundleInfo.ContentFullPath); LoaderStatus.UpdateProgress(bundleInfo.ID, 1f); LoaderStatus.RemoveActiveLoader(bundleInfo.ID, !flag); } } internal static class UnityAssetBundleLoader { public static AnvilCallback<AssetBundle> LoadAssetsFromBundlePatch(string fullBundlePath) { return new AnvilCallback<AssetBundle>((AsyncOperation)(object)AssetBundle.LoadFromFileAsync(fullBundlePath), (AnvilCallback<AssetBundle>)null); } } } namespace OtherLoader.Loading.Model { internal class BundleInfo { public readonly string Name; public readonly string ContentFullPath; public readonly string PluginName; private readonly string _fullDirectoryName; public string ID => _fullDirectoryName + "\\ : " + Name; public BundleInfo(FileInfo fileInfo) { Name = fileInfo.Name; _fullDirectoryName = fileInfo.DirectoryName; PluginName = RetrievePluginNameFromFullDirectoryName() ?? "UnknownPlugin"; ContentFullPath = fileInfo.FullName; } public BundleInfo(string bundleFullPath, string? bundleContentFullPathOverride = null) { Name = Path.GetFileName(bundleFullPath); _fullDirectoryName = Path.GetDirectoryName(bundleFullPath); PluginName = RetrievePluginNameFromFullDirectoryName() ?? "UnknownPlugin"; ContentFullPath = bundleContentFullPathOverride ?? bundleFullPath; } private string? RetrievePluginNameFromFullDirectoryName() { string path = Path.Combine(Paths.BepInExRootPath, "plugins"); string text = Path.GetFullPath(_fullDirectoryName).Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); string text2 = Path.GetFullPath(path).Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); if (!text.StartsWith(text2, StringComparison.OrdinalIgnoreCase)) { return null; } string[] array = text.Substring(text2.Length).TrimStart(new char[1] { Path.DirectorySeparatorChar }).Split(new char[1] { Path.DirectorySeparatorChar }); if (array.Length == 0) { return null; } return array[0]; } } } namespace OtherLoader.Loading.AssetLoaders { internal abstract class AssetBundleLoaderBase<T> : IAssetBundleLoader where T : Object { public IEnumerator LoadAssetsFromBundle(AssetBundle assetBundle, string bundleId, string pluginName) { AssetBundleRequest bundleRequest = assetBundle.LoadAllAssetsAsync<T>(); yield return bundleRequest; LoadAllAssetsFromBundleRequest(bundleRequest, bundleId, pluginName); } protected abstract void LoadAssetFromBundle(T asset, string bundleId, string pluginName); private void LoadAllAssetsFromBundleRequest(AssetBundleRequest bundleRequest, string bundleId, string pluginName) { Object[] allAssets = bundleRequest.allAssets; foreach (Object val in allAssets) { try { T asset = ((T)(object)((val is T) ? val : null)) ?? throw new InvalidOperationException("CastAsset is null"); LoadAssetFromBundle(asset, bundleId, pluginName); } catch (Exception arg) { OtherLogger.LogError($"Failed to load asset! Exception: {arg}"); } } } } internal interface IAssetBundleLoader { IEnumerator LoadAssetsFromBundle(AssetBundle assetBundle, string bundleId, string pluginName); } } namespace OtherLoader.Loading.AssetLoaders.Implementations { internal class AudioImpactSetLoader : AssetBundleLoaderBase<AudioImpactSet> { protected override void LoadAssetFromBundle(AudioImpactSet asset, string bundleId, string pluginName) { OtherLogger.Log("Loading new AudioImpactSet: " + ((Object)asset).name, LogTag.Assets); ManagerSingleton<SM>.Instance.AudioImpactSets = ManagerSingleton<SM>.Instance.AudioImpactSets.Concat(new <>z__ReadOnlySingleElementList<AudioImpactSet>(asset)).ToArray(); ManagerSingleton<SM>.Instance.m_impactDic = new Dictionary<ImpactType, Dictionary<MatSoundType, Dictionary<AudioImpactIntensity, AudioEvent>>>(); ManagerSingleton<SM>.Instance.generateImpactDictionary(); } } internal class BulletImpactSetLoader : AssetBundleLoaderBase<AudioBulletImpactSet> { protected override void LoadAssetFromBundle(AudioBulletImpactSet asset, string bundleId, string pluginName) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) OtherLogger.Log("Loading new bullet impact set entry: " + ((Object)asset).name, LogTag.Assets); ManagerSingleton<SM>.Instance.AudioBulletImpactSets = ManagerSingleton<SM>.Instance.AudioBulletImpactSets.Concat(new <>z__ReadOnlySingleElementList<AudioBulletImpactSet>(asset)).ToArray(); ManagerSingleton<SM>.Instance.m_bulletHitDic.Add(asset.Type, asset); } } internal class FVRObjectLoader : AssetBundleLoaderBase<FVRObject> { protected override void LoadAssetFromBundle(FVRObject asset, string bundleId, string pluginName) { OtherLogger.Log("Loading FVRObject with ID: " + asset.ItemID, LogTag.Assets); if (IM.OD.ContainsKey(asset.ItemID)) { OtherLogger.LogError("The ItemID of FVRObject is already used! Item will not be loaded! ItemID: " + asset.ItemID); return; } ((AnvilAsset)asset).m_anvilPrefab.Bundle = bundleId; LoadIntoObjectDatabase(asset); asset.IsModContent = true; OtherLogger.Log("Loaded FVRObject with ID: " + asset.ItemID, LogTag.Assets); } private void LoadIntoObjectDatabase(FVRObject fvrObject) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) FVRObject fvrObject2 = fvrObject; IM.OD.Add(fvrObject2.ItemID, fvrObject2); ManagerSingleton<IM>.Instance.odicTagCategory.CreateValueIfNewKey(fvrObject2.Category).Add(fvrObject2); ManagerSingleton<IM>.Instance.odicTagFirearmEra.CreateValueIfNewKey(fvrObject2.TagEra).Add(fvrObject2); ManagerSingleton<IM>.Instance.odicTagFirearmSize.CreateValueIfNewKey(fvrObject2.TagFirearmSize).Add(fvrObject2); ManagerSingleton<IM>.Instance.odicTagFirearmAction.CreateValueIfNewKey(fvrObject2.TagFirearmAction).Add(fvrObject2); ManagerSingleton<IM>.Instance.odicTagAttachmentMount.CreateValueIfNewKey(fvrObject2.TagAttachmentMount).Add(fvrObject2); ManagerSingleton<IM>.Instance.odicTagAttachmentFeature.CreateValueIfNewKey(fvrObject2.TagAttachmentFeature).Add(fvrObject2); fvrObject2.TagFirearmFeedOption.ForEach(delegate(OTagFirearmFeedOption o) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) ManagerSingleton<IM>.Instance.odicTagFirearmFeedOption.CreateValueIfNewKey(o).Add(fvrObject2); }); fvrObject2.TagFirearmFiringModes.ForEach(delegate(OTagFirearmFiringMode o) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) ManagerSingleton<IM>.Instance.odicTagFirearmFiringMode.CreateValueIfNewKey(o).Add(fvrObject2); }); fvrObject2.TagFirearmMounts.ForEach(delegate(OTagFirearmMount o) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) ManagerSingleton<IM>.Instance.odicTagFirearmMount.CreateValueIfNewKey(o).Add(fvrObject2); }); } } internal class HandlingGrabSetLoader : AssetBundleLoaderBase<HandlingGrabSet> { protected override void LoadAssetFromBundle(HandlingGrabSet asset, string bundleId, string pluginName) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) OtherLogger.Log("Loading new handling grab set entry: " + ((Object)asset).name, LogTag.Assets); ManagerSingleton<SM>.Instance.m_handlingGrabDic.Add(asset.Type, asset); } } internal class HandlingReleaseSetLoader : AssetBundleLoaderBase<HandlingReleaseSet> { protected override void LoadAssetFromBundle(HandlingReleaseSet asset, string bundleId, string pluginName) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) OtherLogger.Log("Loading new handling release set entry: " + ((Object)asset).name, LogTag.Assets); ManagerSingleton<SM>.Instance.m_handlingReleaseDic.Add(asset.Type, asset); } } internal class HandlingSlotSetLoader : AssetBundleLoaderBase<HandlingReleaseIntoSlotSet> { protected override void LoadAssetFromBundle(HandlingReleaseIntoSlotSet asset, string bundleId, string pluginName) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) OtherLogger.Log("Loading new handling QB slot set entry: " + ((Object)asset).name, LogTag.Assets); ManagerSingleton<SM>.Instance.m_handlingReleaseIntoSlotDic.Add(asset.Type, asset); } } internal class ItemSpawnerCategoryLoader : AssetBundleLoaderBase<ItemSpawnerCategoryDefinitions> { protected override void LoadAssetFromBundle(ItemSpawnerCategoryDefinitions categoryDefinitions, string bundleId, string pluginName) { new TL("LoadAssetFromBundle", LogTag.Assets).Log("Loading legacy ItemSpawnerCategoryDefinitions from plugin '" + pluginName + "'"); SpawnerTilesDatabase.RegisterLegacyCategories(categoryDefinitions); } } internal class ItemSpawnerEntryLoader : AssetBundleLoaderBase<ItemSpawnerEntry> { protected override void LoadAssetFromBundle(ItemSpawnerEntry entry, string bundleId, string pluginName) { TL tL = new TL("LoadAssetFromBundle", LogTag.Assets); tL.Log("Loading ItemSpawnerEntry from plugin '" + pluginName + "'\n- MainObjectID {" + entry.MainObjectID + "}\n- EntryPath {" + entry.EntryPath + "}\n- DisplayName {" + entry.DisplayName + "}" + $"\n- IsDisplayedInMainEntry {{{entry.IsDisplayedInMainEntry}}}"); ItemSpawnerID itemSpawnerID = SpawnerEntryToSpawnerIdConverter.Convert(tL, entry); if (!entry.IsCategoryEntry()) { ItemSpawnerIdRegisterer.Register(tL, itemSpawnerID, registerInTilesDatabase: false, unifyItemIDs: false); } if (entry.IsDisplayedInMainEntry) { SpawnerTilesDatabase.Register(entry); } else if (entry.IsCategoryEntry()) { OtherLogger.LogWarning("CategoryEntry has IsDisplayedInMainEntry set to false, it will not be displayed!"); } } } internal class ItemSpawnerIdLoader : AssetBundleLoaderBase<ItemSpawnerID> { protected override void LoadAssetFromBundle(ItemSpawnerID itemSpawnerID, string bundleId, string pluginName) { TL tL = new TL("LoadAssetFromBundle", LogTag.Assets); tL.Log("Loading ItemSpawnerID from plugin '" + pluginName + "'\n- ItemID {" + itemSpawnerID.ItemID + "}\n- MainObject.ItemID {" + itemSpawnerID.MainObject.ItemID + "}"); bool flag = ((pluginName == "Meat_banono-Meats_ASh12" || pluginName == "Meat_banono-Meats_ModulSIG") ? true : false); bool unifyItemIDs = flag; ItemSpawnerIdRegisterer.Register(tL, itemSpawnerID, registerInTilesDatabase: true, unifyItemIDs); } } internal class MechanicalAccuracyChartLoader : AssetBundleLoaderBase<FVRFireArmMechanicalAccuracyChart> { protected override void LoadAssetFromBundle(FVRFireArmMechanicalAccuracyChart asset, string bundleId, string pluginName) { foreach (MechanicalAccuracyEntry entry in asset.Entries) { LoadMechanicalAccuracyEntry(entry); } } private void LoadMechanicalAccuracyEntry(MechanicalAccuracyEntry entry) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) if (AM.SMechanicalAccuracyDic.ContainsKey(entry.Class)) { OtherLogger.LogError("Duplicate mechanical accuracy class found, will not use one of them! Make sure you're using unique mechanical accuracy classes!"); return; } AM.SMechanicalAccuracyDic.Add(entry.Class, entry); OtherLogger.Log("Loaded new mechanical accuracy entry: " + ((object)(FVRFireArmMechanicalAccuracyClass)(ref entry.Class)).ToString(), LogTag.Assets); } } internal class QuickBeltLoader : AssetBundleLoaderBase<GameObject> { protected override void LoadAssetFromBundle(GameObject asset, string bundleId, string pluginName) { if (IsPrefabAQuickBelt(asset)) { OtherLogger.Log("Adding QuickBelt " + ((Object)asset).name, LogTag.Assets); ManagerSingleton<GM>.Instance.QuickbeltConfigurations = ManagerSingleton<GM>.Instance.QuickbeltConfigurations.Concat(new <>z__ReadOnlySingleElementList<GameObject>(asset)).ToArray(); } } private static bool IsPrefabAQuickBelt(GameObject prefab) { string[] array = ((Object)prefab).name.Split(new char[1] { '_' }); if (array.Length > 1) { return array[^2] == "QuickBelt"; } return false; } } internal class RoundDisplayDataLoader : AssetBundleLoaderBase<FVRFireArmRoundDisplayData> { protected override void LoadAssetFromBundle(FVRFireArmRoundDisplayData asset, string bundleId, string pluginName) { AddRoundTypeIfNotExist(asset); AddRoundClassIfNotExist(asset); AddRoundDisplayData(asset); OtherLogger.Log("Loaded ammo type: " + ((object)(FireArmRoundType)(ref asset.Type)).ToString(), LogTag.Assets); } private void AddRoundTypeIfNotExist(FVRFireArmRoundDisplayData displayData) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) AM.STypeDic.CreateValueIfNewKey(displayData.Type); AM.STypeList.AddIfUnique(displayData.Type); } private void AddRoundClassIfNotExist(FVRFireArmRoundDisplayData displayData) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) AM.STypeClassLists.CreateValueIfNewKey(displayData.Type); DisplayDataClass[] classes = displayData.Classes; foreach (DisplayDataClass val in classes) { OtherLogger.Log("Loading ammo class: " + ((object)(FireArmRoundClass)(ref val.Class)).ToString(), LogTag.Assets); AM.STypeDic[displayData.Type][val.Class] = val; AM.STypeClassLists[displayData.Type].AddIfUnique(val.Class); } } private void AddRoundDisplayData(FVRFireArmRoundDisplayData displayData) { //IL_0006: 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_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) if (!AM.SRoundDisplayDataDic.ContainsKey(displayData.Type)) { AM.SRoundDisplayDataDic[displayData.Type] = displayData; return; } List<DisplayDataClass> list = AM.SRoundDisplayDataDic[displayData.Type].Classes.ToList(); list.AddRange(displayData.Classes); AM.SRoundDisplayDataDic[displayData.Type].Classes = list.ToArray(); } } internal class TutorialBlockLoader : AssetBundleLoaderBase<TutorialBlock> { protected override void LoadAssetFromBundle(TutorialBlock asset, string bundleId, string pluginName) { if (UsesLocalVideo(asset)) { LinkVideoToTutorialBlock(asset, bundleId); } IM.TutorialBlockDic[asset.ID] = asset; OtherLogger.Log("Loaded tutorial block with media path: " + asset.MediaRef.MediaPath.Path, LogTag.Assets); } private void LinkVideoToTutorialBlock(TutorialBlock tutorialBlock, string bundleId) { string videoFilePath = GetVideoFilePath(bundleId, tutorialBlock.ID); tutorialBlock.MediaRef.MediaPath.Path = videoFilePath; } private bool UsesLocalVideo(TutorialBlock tutorialBlock) { return string.IsNullOrEmpty(tutorialBlock.MediaRef.MediaPath.Path); } private string GetVideoFilePath(string bundleId, string tutorialBlockId) { throw new NotImplementedException(); } } } namespace OtherLoader.ItemSpawner { internal static class ItemSpawnerIdRegisterer { public static void Register(TL oldTL, ItemSpawnerID itemSpawnerID, bool registerInTilesDatabase, bool unifyItemIDs) { //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_02a0: Unknown result type (might be due to invalid IL or missing references) //IL_0224: Unknown result type (might be due to invalid IL or missing references) //IL_023c: Unknown result type (might be due to invalid IL or missing references) TL tL = oldTL.New("Register", LogTag.Assets); EnsureMainObjectIsNotNull(itemSpawnerID); if (unifyItemIDs) { itemSpawnerID.ItemID = itemSpawnerID.MainObject.ItemID; itemSpawnerID.MainObject.SpawnedFromId = itemSpawnerID.MainObject.ItemID; } if (IM.HasSpawnedID(itemSpawnerID.ItemID)) { tL.LogWarning("Can't register ItemSpawnerID with ID {" + itemSpawnerID.ItemID + "} because an ItemSpawnerID with this ID is already registered!"); return; } tL.Log("Registering new ItemSpawnerID\n- DisplayName {" + itemSpawnerID.DisplayName + "}\n- ItemID {" + itemSpawnerID.ItemID + "}" + $"\n- MainObject {{{itemSpawnerID.MainObject}}}" + $"\n- Category {{{itemSpawnerID.Category}}}" + $"\n- SubCategory {{{itemSpawnerID.SubCategory}}}" + $"\n- IsDisplayedInMainEntry {{{itemSpawnerID.IsDisplayedInMainEntry}}}" + $"\n- SecondObject {{{itemSpawnerID.SecondObject}}}" + $"\n- Secondaries count: {itemSpawnerID.Secondaries?.Length}" + $"\n- SecondariesByStringID count: {itemSpawnerID.Secondaries_ByStringID?.Count}"); ManagerSingleton<IM>.Instance.SpawnerIDDic[itemSpawnerID.ItemID] = itemSpawnerID; if (IM.CD.ContainsKey(itemSpawnerID.Category)) { IM.CD[itemSpawnerID.Category].Add(itemSpawnerID); } if (IM.SCD.ContainsKey(itemSpawnerID.SubCategory)) { IM.SCD[itemSpawnerID.SubCategory].Add(itemSpawnerID); } ItemSpawnerIdTagger.RegisterSpawnerIDIntoTagSystem(itemSpawnerID); if (itemSpawnerID.IsDisplayedInMainEntry) { if (!registerInTilesDatabase) { return; } if (Enum.IsDefined(typeof(EItemCategory), itemSpawnerID.Category)) { if (!Enum.IsDefined(typeof(ESubCategory), itemSpawnerID.SubCategory)) { ItemSpawnerEntry itemSpawnerEntry = ItemSpawnerEntry.CreateEmpty($"{itemSpawnerID.SubCategory}/" + itemSpawnerID.ItemID); itemSpawnerEntry.DisplayName = itemSpawnerID.DisplayName; itemSpawnerEntry.MainObjectID = itemSpawnerID.ItemID; itemSpawnerEntry.EntryIcon = itemSpawnerID.Sprite; SpawnerTilesDatabase.Register(itemSpawnerEntry); } } else { ItemSpawnerEntry itemSpawnerEntry2 = ItemSpawnerEntry.CreateEmpty($"{itemSpawnerID.Category}/" + $"{itemSpawnerID.SubCategory}/" + itemSpawnerID.ItemID); itemSpawnerEntry2.DisplayName = itemSpawnerID.DisplayName; itemSpawnerEntry2.MainObjectID = itemSpawnerID.ItemID; itemSpawnerEntry2.EntryIcon = itemSpawnerID.Sprite; SpawnerTilesDatabase.Register(itemSpawnerEntry2); } return; } foreach (List<string> value in ManagerSingleton<IM>.Instance.PageItemLists.Values) { value.Remove(itemSpawnerID.MainObject.ItemID); } } private static void EnsureMainObjectIsNotNull(ItemSpawnerID spawnerId) { if ((Object)(object)spawnerId.MainObject == (Object)null) { spawnerId.MainObject = spawnerId.Secondaries.Select((ItemSpawnerID o) => o.MainObject).FirstOrDefault((Func<FVRObject, bool>)((FVRObject o) => (Object)(object)o != (Object)null)); if ((Object)(object)spawnerId.MainObject == (Object)null) { throw new NullReferenceException("Could not select a secondary object for ItemSpawnerID, it will not appear in spawner: Display Name: " + spawnerId.DisplayName); } OtherLogger.Log("Assigning itemID from secondary object: " + spawnerId.MainObject.ItemID, LogTag.Assets); } } } internal static class ItemSpawnerIdTagger { public static void RegisterSpawnerIDIntoTagSystem(ItemSpawnerID spawnerID) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0026: 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_002e: Invalid comparison between Unknown and I4 //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Invalid comparison between Unknown and I4 //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Invalid comparison between Unknown and I4 //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) OtherLogger.Log("Attempting to tag " + spawnerID.ItemID, LogTag.ItemSpawnerTagging); PageMode spawnerPageForSpawnerId = GetSpawnerPageForSpawnerId(spawnerID); RegisterModTags(spawnerID, spawnerPageForSpawnerId); RegisterCategoryTags(spawnerID, spawnerPageForSpawnerId); if ((int)spawnerPageForSpawnerId == 1) { RegisterFirearmIntoMetaTagSystem(spawnerID.MainObject, spawnerPageForSpawnerId); } else if ((int)spawnerPageForSpawnerId == 3) { RegisterAttachmentIntoMetaTagSystem(spawnerID.MainObject, spawnerPageForSpawnerId); } else if ((int)spawnerPageForSpawnerId == 2) { RegisterAmmoIntoMetaTagSystem(spawnerID.MainObject, spawnerPageForSpawnerId); } } private static PageMode GetSpawnerPageForSpawnerId(ItemSpawnerID spawnerId) { if (!ShouldItemBeTaggedAsToolsToy(spawnerId)) { if (!ShouldItemBeTaggedAsMelee(spawnerId)) { if (!ShouldItemBeTaggedAsAmmo(spawnerId)) { if (!ShouldItemBeTaggedAsAttachment(spawnerId)) { if (!ShouldItemBeTaggedAsFirearm(spawnerId)) { return (PageMode)0; } return (PageMode)1; } return (PageMode)3; } return (PageMode)2; } return (PageMode)4; } return (PageMode)5; } private static void RegisterCategoryTags(ItemSpawnerID spawnerId, PageMode page) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) IM.AddMetaTag(((object)(EItemCategory)(ref spawnerId.Category)).ToString(), (TagType)2, spawnerId.ItemID, page); if ((int)spawnerId.SubCategory != 0) { IM.AddMetaTag(((object)(ESubCategory)(ref spawnerId.SubCategory)).ToString(), (TagType)3, spawnerId.ItemID, page); } } private static void RegisterModTags(ItemSpawnerID spawnerId, PageMode page) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) foreach (string modTag in spawnerId.ModTags) { IM.AddMetaTag(modTag, (TagType)50, spawnerId.ItemID, page); } IM.AddMetaTag("OtherLoader", (TagType)50, spawnerId.ItemID, page); } private static void RegisterFirearmIntoMetaTagSystem(FVRObject mainObject, PageMode page) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0047: 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_0071: 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_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: 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) FVRObject mainObject2 = mainObject; IM.AddMetaTag(((object)(OTagSet)(ref mainObject2.TagSet)).ToString(), (TagType)4, mainObject2.ItemID, page); if ((int)mainObject2.TagEra != 0) { IM.AddMetaTag(((object)(OTagEra)(ref mainObject2.TagEra)).ToString(), (TagType)6, mainObject2.ItemID, page); } if ((int)mainObject2.TagFirearmSize != 0) { IM.AddMetaTag(((object)(OTagFirearmSize)(ref mainObject2.TagFirearmSize)).ToString(), (TagType)5, mainObject2.ItemID, page); } if ((int)mainObject2.TagFirearmAction != 0) { IM.AddMetaTag(((object)(OTagFirearmAction)(ref mainObject2.TagFirearmAction)).ToString(), (TagType)7, mainObject2.ItemID, page); } if ((int)mainObject2.TagFirearmRoundPower != 0) { IM.AddMetaTag(((object)(OTagFirearmRoundPower)(ref mainObject2.TagFirearmRoundPower)).ToString(), (TagType)8, mainObject2.ItemID, page); } if ((int)mainObject2.TagFirearmCountryOfOrigin != 0) { IM.AddMetaTag(((object)(OTagFirearmCountryOfOrigin)(ref mainObject2.TagFirearmCountryOfOrigin)).ToString(), (TagType)10, mainObject2.ItemID, page); } if (mainObject2.TagFirearmFirstYear != 0) { IM.AddMetaTag(mainObject2.TagFirearmFirstYear.ToString(), (TagType)11, mainObject2.ItemID, page); } if ((int)mainObject2.MagazineType != 0) { IM.AddMetaTag(((object)(FireArmMagazineType)(ref mainObject2.MagazineType)).ToString(), (TagType)14, mainObject2.ItemID, page); } if (mainObject2.UsesRoundTypeFlag) { IM.AddMetaTag(((object)(FireArmRoundType)(ref mainObject2.RoundType)).ToString(), (TagType)9, mainObject2.ItemID, page); } mainObject2.TagFirearmFiringModes.ForEach(delegate(OTagFirearmFiringMode tag) { //IL_0000: 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) if ((int)tag != 0) { IM.AddMetaTag(((object)(OTagFirearmFiringMode)(ref tag)).ToString(), (TagType)12, mainObject2.ItemID, page); } }); mainObject2.TagFirearmFeedOption.ForEach(delegate(OTagFirearmFeedOption tag) { //IL_0000: 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) if ((int)tag != 0) { IM.AddMetaTag(((object)(OTagFirearmFeedOption)(ref tag)).ToString(), (TagType)13, mainObject2.ItemID, page); } }); mainObject2.TagFirearmMounts.ForEach(delegate(OTagFirearmMount tag) { //IL_0000: 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) if ((int)tag != 0) { IM.AddMetaTag(((object)(OTagFirearmMount)(ref tag)).ToString(), (TagType)15, mainObject2.ItemID, page); } }); } private static void RegisterAttachmentIntoMetaTagSystem(FVRObject mainObject, PageMode page) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0065: 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) IM.AddMetaTag(((object)(OTagSet)(ref mainObject.TagSet)).ToString(), (TagType)4, mainObject.ItemID, page); if ((int)mainObject.TagEra != 0) { IM.AddMetaTag(((object)(OTagEra)(ref mainObject.TagEra)).ToString(), (TagType)6, mainObject.ItemID, page); } if ((int)mainObject.TagAttachmentFeature != 0) { IM.AddMetaTag(((object)(OTagAttachmentFeature)(ref mainObject.TagAttachmentFeature)).ToString(), (TagType)16, mainObject.ItemID, page); } if ((int)mainObject.TagAttachmentMount != 0) { IM.AddMetaTag(((object)(OTagFirearmMount)(ref mainObject.TagAttachmentMount)).ToString(), (TagType)15, mainObject.ItemID, page); } } private static void RegisterAmmoIntoMetaTagSystem(FVRObject mainObject, PageMode page) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0065: 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) IM.AddMetaTag(((object)(OTagSet)(ref mainObject.TagSet)).ToString(), (TagType)4, mainObject.ItemID, page); if ((int)mainObject.TagEra != 0) { IM.AddMetaTag(((object)(OTagEra)(ref mainObject.TagEra)).ToString(), (TagType)6, mainObject.ItemID, page); } if ((int)mainObject.MagazineType != 0) { IM.AddMetaTag(((object)(FireArmMagazineType)(ref mainObject.MagazineType)).ToString(), (TagType)14, mainObject.ItemID, page); } if (mainObject.UsesRoundTypeFlag) { IM.AddMetaTag(((object)(FireArmRoundType)(ref mainObject.RoundType)).ToString(), (TagType)9, mainObject.ItemID, page); } } private static bool ShouldItemBeTaggedAsFirearm(ItemSpawnerID spawnerId) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Invalid comparison between Unknown and I4 //IL_0021: Unknown result type (might be due to invalid IL or missing references) if ((int)spawnerId.MainObject.Category != 1 && !spawnerId.IsFirearm()) { return !Enum.IsDefined(typeof(EItemCategory), spawnerId.Category); } return true; } private static bool ShouldItemBeTaggedAsToolsToy(ItemSpawnerID spawnerId) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Invalid comparison between Unknown and I4 //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Invalid comparison between Unknown and I4 //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Invalid comparison between Unknown and I4 //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Invalid comparison between Unknown and I4 if ((int)spawnerId.MainObject.Category != 20 && (int)spawnerId.MainObject.Category != 7 && (int)spawnerId.Category != 6) { return (int)ItemSubCategoryMapper.TryGetCategory(spawnerId.SubCategory).GetValueOrDefault() == 6; } return true; } private static bool ShouldItemBeTaggedAsMelee(ItemSpawnerID spawnerId) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Invalid comparison between Unknown and I4 //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Invalid comparison between Unknown and I4 //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Invalid comparison between Unknown and I4 if ((int)spawnerId.MainObject.Category != 10 && (int)spawnerId.Category != 5) { return (int)ItemSubCategoryMapper.TryGetCategory(spawnerId.SubCategory).GetValueOrDefault() == 5; } return true; } private static bool ShouldItemBeTaggedAsAmmo(ItemSpawnerID spawnerId) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Invalid comparison between Unknown and I4 //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Invalid comparison between Unknown and I4 EItemCategory category = spawnerId.Category; if (category - 7 <= 1 || category - 10 <= 1) { return true; } return false; } private static bool ShouldItemBeTaggedAsAttachment(ItemSpawnerID spawnerId) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Invalid comparison between Unknown and I4 //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Invalid comparison between Unknown and I4 if ((int)spawnerId.MainObject.Category != 5) { return (int)ItemSubCategoryMapper.TryGetCategory(spawnerId.SubCategory).GetValueOrDefault() == 4; } return true; } } internal static class SpawnerEntryToSpawnerIdConverter { public static ItemSpawnerID Convert(TL oldTL, ItemSpawnerEntry entry) { TL newTL = oldTL.New("Convert"); entry.PopulateIDsFromObj(); ItemSpawnerID val = ScriptableObject.CreateInstance<ItemSpawnerID>(); FVRObject val2 = entry.MainObjectObj; if ((Object)(object)val2 == (Object)null && !string.IsNullOrEmpty(entry.MainObjectID) && IM.OD.ContainsKey(entry.MainObjectID)) { val2 = IM.OD[entry.MainObjectID]; } AssignCategoriesForSpawnerID(newTL, val, entry); val.MainObject = val2; val.SecondObject = (from objID in entry.SpawnWithIDs where IM.OD.ContainsKey(objID) select IM.OD[objID]).FirstOrDefault(); val.DisplayName = entry.DisplayName; val.IsDisplayedInMainEntry = entry.IsDisplayedInMainEntry; val.ItemID = entry.MainObjectID; val.ModTags = entry.ModTags; val.Secondaries_ByStringID = entry.SecondaryObjectIDs.Where((string objID) => IM.OD.ContainsKey(objID)).ToList(); val.Secondaries = (ItemSpawnerID[])(object)new ItemSpawnerID[0]; val.Sprite = entry.EntryIcon; val.UsesLargeSpawnPad = entry.UsesLargeSpawnPad; val.UsesHugeSpawnPad = entry.UsesHugeSpawnPad; val.IsReward = entry.IsReward; val.TutorialBlocks = entry.TutorialBlockIDs; return val; } private static void AssignCategoriesForSpawnerID(TL newTL, ItemSpawnerID itemSpawnerID, ItemSpawnerEntry entry) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: 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) EItemCategory? spawnerCategoryNew = entry.GetSpawnerCategoryNew(); ESubCategory? spawnerSubCategoryNew = entry.GetSpawnerSubCategoryNew(); if (spawnerCategoryNew.HasValue) { itemSpawnerID.Category = spawnerCategoryNew.Value; itemSpawnerID.SubCategory = (ESubCategory)0; newTL.Log("Updated item categories:" + $"\n- Category {{{itemSpawnerID.Category}}} read from EntryPath" + $"\n- SubCategory {{{itemSpawnerID.SubCategory}}}"); } else if (spawnerSubCategoryNew.HasValue) { EItemCategory? val = ItemSubCategoryMapper.TryGetCategory(spawnerSubCategoryNew.Value); if (!val.HasValue) { itemSpawnerID.Category = (EItemCategory)0; itemSpawnerID.SubCategory = spawnerSubCategoryNew.Value; newTL.Log("Updated item categories:" + $"\n- Category {{{itemSpawnerID.Category}}} (failed to infer from SubCategory)" + $"\n- SubCategory {{{itemSpawnerID.SubCategory}}} read from EntryPath"); } else { itemSpawnerID.Category = val.Value; itemSpawnerID.SubCategory = spawnerSubCategoryNew.Value; newTL.Log("Updated item categories:" + $"\n- Category {{{itemSpawnerID.Category}}} inferred from SubCategory" + $"\n- SubCategory {{{itemSpawnerID.SubCategory}}} read from EntryPath"); } } else { itemSpawnerID.Category = (EItemCategory)entry.CreateCustomCategoryInt(); itemSpawnerID.SubCategory = (ESubCategory)0; newTL.Log("Updated item categories:" + $"\n- Category {{{itemSpawnerID.Category}}} (custom category)" + $"\n- SubCategory {{{itemSpawnerID.SubCategory}}}"); } } private static int CreateCustomCategoryInt(this ItemSpawnerEntry entry) { if (string.IsNullOrEmpty(entry.EntryPath)) { return 0; } string[] array = entry.EntryPath.Split(new char[1] { '/' }); return Hasher.HashStringToInt(entry.IsCategoryEntry() ? array[^1] : array[^2]); } } } namespace OtherLoader.ItemSpawner.Patches { [HarmonyWrapSafe] [HarmonyPatch(typeof(ItemSpawnerV2))] internal static class ItemSpawnerV2InitialPatcher { private static readonly Vector2 CustomCategoriesButtonDimensions = new Vector2(410f, 90f); [HarmonyPatch("Start")] [HarmonyPostfix] private static void Start_Postfix_CreateCustomCategoriesButton(ItemSpawnerV2 __instance) { //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_0213: Unknown result type (might be due to invalid IL or missing references) //IL_0224: Unknown result type (might be due to invalid IL or missing references) //IL_0241: Unknown result type (might be due to invalid IL or missing references) //IL_02b0: Unknown result type (might be due to invalid IL or missing references) //IL_02ba: Expected O, but got Unknown //IL_02c8: Unknown result type (might be due to invalid IL or missing references) //IL_02d2: Expected O, but got Unknown ItemSpawnerV2 __instance2 = __instance; if ((Object)(object)((Component)__instance2).GetComponent<CustomCategoriesController>() != (Object)null) { return; } Canvas componentInChildren = ((Component)__instance2).GetComponentInChildren<Canvas>(); if ((Object)(object)componentInChildren == (Object)null) { OtherLogger.LogError("Canvas not found"); return; } Transform val = ((Component)__instance2).transform.Find("Canvas/0_TopBar"); if ((Object)(object)val == (Object)null) { OtherLogger.LogError("0_TopBar not found"); return; } GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, ((Component)componentInChildren).transform); foreach (Transform item in val2.transform) { Object.Destroy((Object)(object)((Component)item).gameObject); } ((Object)val2).name = "OtherLoaderUIContainer"; val2.transform.localScale = Vector3.one; val2.transform.localPosition = new Vector3(-780f, 570f, 0f); RectTransform component = val2.GetComponent<RectTransform>(); if ((Object)(object)component != (Object)null) { component.sizeDelta = CustomCategoriesButtonDimensions; } GameObject gO_SimpleTiles_BackButton = __instance2.GO_SimpleTiles_BackButton; if ((Object)(object)gO_SimpleTiles_BackButton == (Object)null) { OtherLogger.LogError("templateButton is null"); Object.Destroy((Object)(object)val2); return; } GameObject val3 = Object.Instantiate<GameObject>(gO_SimpleTiles_BackButton, val2.transform); ((Object)val3).name = "BTN_OtherLoaderCustomCategories"; val3.transform.localScale = Vector3.one; val3.transform.localPosition = Vector3.zero; RectTransform component2 = val3.GetComponent<RectTransform>(); if ((Object)(object)component2 != (Object)null) { component2.sizeDelta = CustomCategoriesButtonDimensions; } BoxCollider component3 = val3.GetComponent<BoxCollider>(); if ((Object)(object)component3 != (Object)null) { component3.size = new Vector3(CustomCategoriesButtonDimensions.x, CustomCategoriesButtonDimensions.y, component3.size.z); } Transform val4 = val3.transform.Find("Backing"); if ((Object)(object)val4 == (Object)null) { OtherLogger.LogWarning("Backing of button not found, ignoring..."); } else { GameObject gameObject = ((Component)val4).gameObject; gameObject.transform.localScale = Vector3.one; val3.transform.localPosition = Vector3.zero; RectTransform component4 = gameObject.GetComponent<RectTransform>(); if ((Object)(object)component4 != (Object)null) { component4.sizeDelta = CustomCategoriesButtonDimensions; } } Text componentInChildren2 = val3.GetComponentInChildren<Text>(); if ((Object)(object)componentInChildren2 == (Object)null) { OtherLogger.LogError("Text component not found"); Object.Destroy((Object)(object)val2); return; } componentInChildren2.text = $"MODDED CATEGORIES ({SpawnerTilesDatabase.CustomCategoryCount})"; Button component5 = val3.GetComponent<Button>(); if ((Object)(object)component5 == (Object)null) { OtherLogger.LogError("Button component not found"); Object.Destroy((Object)(object)val2); return; } component5.onClick = new ButtonClickedEvent(); ((UnityEvent)component5.onClick).AddListener((UnityAction)delegate { OnCustomCategoriesButtonClicked(__instance2); }); val3.SetActive(true); CustomCategoriesController customCategoriesController = ((Component)__instance2).gameObject.AddComponent<CustomCategoriesController>(); ((Object)customCategoriesController).hideFlags = (HideFlags)61; customCategoriesController.Initialize(__instance2, val3); OtherLogger.Log("Custom categories button and controller patched into ItemSpawnerV2", LogTag.ItemSpawnerPatches); } private static void OnCustomCategoriesButtonClicked(ItemSpawnerV2 itemSpawner) { CustomCategoriesController component = ((Component)itemSpawner).GetComponent<CustomCategoriesController>(); if ((Object)(object)component == (Object)null) { return; } OtherLogger.Log("Custom Categories button clicked", LogTag.ItemSpawnerPatches); try { component.EnableCustomCategoryMode(); } catch (Exception arg) { OtherLogger.LogError($"OnCustomCategoriesButtonClicked exception: {arg}"); } } } [HarmonyWrapSafe] [HarmonyPatch(typeof(ItemSpawnerV2))] internal static class ItemSpawnerV2SimpleModePatcher { [HarmonyPatch("BTN_SetPageMode")] [HarmonyPrefix] private static void BTN_SetPageMode_Prefix(ItemSpawnerV2 __instance) { CustomCategoriesController component = ((Component)__instance).GetComponent<CustomCategoriesController>(); if (component != null && component.IsCustomCategoryModeActive) { component.DisableCustomCategoryMode(); } } [HarmonyPatch("RedrawSimpleCanvas")] [HarmonyPrefix] private static bool RedrawSimpleCanvas_Prefix(ItemSpawnerV2 __instance) { CustomCategoriesController component = ((Component)__instance).GetComponent<CustomCategoriesController>(); if (component == null || !component.IsCustomCategoryModeActive) { return true; } component.RedrawCustomTiles(); return false; } [HarmonyPatch("SimpleSelectTile")] [HarmonyPrefix] private static bool SimpleSelectTile_Prefix(ItemSpawnerV2 __instance, int i) { CustomCategoriesController component = ((Component)__instance).GetComponent<CustomCategoriesController>(); if (component == null || !component.IsCustomCategoryModeActive) { return true; } component.HandleClickOnTile(i); return false; } [HarmonyPatch("SimpleGoBack")] [HarmonyPrefix] private static bool SimpleGoBack_Prefix(ItemSpawnerV2 __instance) { CustomCategoriesController component = ((Component)__instance).GetComponent<CustomCategoriesController>(); if (component == null || !component.IsCustomCategoryModeActive) { return true; } component.GoToParentCategory(); return false; } [HarmonyPatch("SimpleNextPage")] [HarmonyPrefix] private static bool SimpleNextPage_Prefix(ItemSpawnerV2 __instance) { CustomCategoriesController component = ((Component)__instance).GetComponent<CustomCategoriesController>(); if (component == null || !component.IsCustomCategoryModeActive) { return true; } component.GoToNextPage(); return false; } [HarmonyPatch("SimplePrevage")] [HarmonyPrefix] private static bool SimplePrevage_Prefix(ItemSpawnerV2 __instance) { CustomCategoriesController component = ((Component)__instance).GetComponent<CustomCategoriesController>(); if (component == null || !component.IsCustomCategoryModeActive) { return true; } component.GoToPreviousPage(); return false; } } [HarmonyPatch(typeof(ItemSpawnerV2))] internal static class ItemSpawnerV2TagModePatcher { [HarmonyPatch("SelectTagsOnHeldObject")] [HarmonyPrefix] private static void SelectTagsOnHeldObject_Prefix(ItemSpawnerV2 __instance, ref List<string>? __state) { Dictionary<TagType, List<string>> selectedTagsForCurrentPage = GetSelectedTagsForCurrentPage(__instance); if (selectedTagsForCurrentPage == null) { OtherLogger.Log("No tags selected in prefix", LogTag.ItemSpawnerPatches); return; } if (!selectedTagsForCurrentPage.TryGetValue((TagType)50, out var value)) { OtherLogger.Log("No ModTags selected in prefix", LogTag.ItemSpawnerPatches); return; } OtherLogger.Log($"Saving ModTags to state count: {value.Count}", LogTag.ItemSpawnerPatches); __state = new List<string>(value); } [HarmonyPatch("SelectTagsOnHeldObject")] [HarmonyPostfix] private static void SelectTagsOnHeldObject_Postfix(ItemSpawnerV2 __instance, List<string>? __state) { Dictionary<TagType, List<string>> selectedTagsForCurrentPage = GetSelectedTagsForCurrentPage(__instance); if (selectedTagsForCurrentPage != null && selectedTagsForCurrentPage.ContainsKey((TagType)50)) { if (__state == null) { OtherLogger.Log("Removing ModTag key from selected tags", LogTag.ItemSpawnerPatches); selectedTagsForCurrentPage.Remove((TagType)50); } else { OtherLogger.Log($"Restoring ModTags from state count: {__state.Count}", LogTag.ItemSpawnerPatches); selectedTagsForCurrentPage[(TagType)50] = __state; } __instance.RedrawStandardCanvases(); } } private static Dictionary<TagType, List<string>>? GetSelectedTagsForCurrentPage(ItemSpawnerV2 itemSpawner) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) if (!itemSpawner.m_selectedTags.TryGetValue(itemSpawner.PMode, out var value)) { return null; } return value; } } } namespace OtherLoader.ItemSpawner.CustomCategories { internal class CustomCategoriesController : MonoBehaviour { public SpawnerTile.FolderTile CurrentSelectedFolderTile = SpawnerTilesDatabase.RootFolderTile; private readonly Dictionary<int, int> _pageNumberByTileLevel = new Dictionary<int, int> { [SpawnerTilesDatabase.RootFolderTile.Level] = 1 }; private ItemSpawnerV2 _itemSpawner; private GameObject _customCategoriesButtonGameO; private Transform? _switchToTagSearchButton; private SimpleDisplayLevel? _previousFirearmsPageDisplayLevel; private SearchMode? _previousSearchMode; private const PageMode PageModeCustomCategories = 1; private const int TilesPerPage = 18; public bool IsCustomCategoryModeActive { get; private set; } private int CurrentPageNumber { get { if (!_pageNumberByTileLevel.ContainsKey(CurrentSelectedFolderTile.Level)) { _pageNumberByTileLevel[CurrentSelectedFolderTile.Level] = 1; } return _pageNumberByTileLevel[CurrentSelectedFolderTile.Level]; } set { _pageNumberByTileLevel[CurrentSelectedFolderTile.Level] = value; } } public void Initialize(ItemSpawnerV2 itemSpawner, GameObject customCategoriesButtonGameO) { _itemSpawner = itemSpawner; _customCategoriesButtonGameO = customCategoriesButtonGameO; _switchToTagSearchButton = ((Component)itemSpawner).transform.Find("Canvas/1_SimpleTileList/BTN_SwitchToTagSearch"); if ((Object)(object)_switchToTagSearchButton == (Object)null) { OtherLogger.LogWarning("SwitchToTagSearchButton not found, ignoring..."); } AddCustomCategoryButtonToTopBarSet(); } private void AddCustomCategoryButtonToTopBarSet() { //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Expected O, but got Unknown try { FVRPointableButton component = _customCategoriesButtonGameO.GetComponent<FVRPointableButton>(); if ((Object)(object)component == (Object)null) { throw new Exception("fvrButton is null"); } Transform obj = ((Component)_itemSpawner).transform.Find("Canvas/0_TopBar/BTNSet_Cat"); OptionsPanel_ButtonSet topBarButtonSet = ((obj != null) ? ((Component)obj).GetComponent<OptionsPanel_ButtonSet>() : null); if ((Object)(object)topBarButtonSet == (Object)null) { throw new Exception("topBarButtonSet is null"); } topBarButtonSet.ButtonsInSet = topBarButtonSet.ButtonsInSet.Concat(new <>z__ReadOnlySingleElementList<FVRPointableButton>(component)).ToArray(); int buttonIndex = topBarButtonSet.ButtonsInSet.Length - 1; ((UnityEvent)component.Button.onClick).AddListener((UnityAction)delegate { topBarButtonSet.SetSelectedButton(buttonIndex); }); } catch (Exception arg) { OtherLogger.LogError($"AddCustomCategoryButtonToTopBarSet exception: {arg}"); } } public void EnableCustomCategoryMode() { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) IsCustomCategoryModeActive = true; Transform? switchToTagSearchButton = _switchToTagSearchButton; if (switchToTagSearchButton != null) { ((Component)switchToTagSearchButton).gameObject.SetActive(false); } _previousFirearmsPageDisplayLevel = _itemSpawner.m_displayLevel[(PageMode)1]; _itemSpawner.m_displayLevel[(PageMode)1] = (SimpleDisplayLevel)0; _previousSearchMode = _itemSpawner.SMode; _itemSpawner.SMode = (SearchMode)0; _itemSpawner.Boop(0); _itemSpawner.SetPageMode(1); } public void DisableCustomCategoryMode() { //IL_003d: 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_0065: Unknown result type (might be due to invalid IL or missing references) IsCustomCategoryModeActive = false; Transform? switchToTagSearchButton = _switchToTagSearchButton; if (switchToTagSearchButton != null) { ((Component)switchToTagSearchButton).gameObject.SetActive(true); } if (_previousFirearmsPageDisplayLevel.HasValue) { _itemSpawner.m_displayLevel[(PageMode)1] = _previousFirearmsPageDisplayLevel.Value; } if (_previousSearchMode.HasValue) { _itemSpawner.SMode = _previousSearchMode.Value; } } public void RedrawCustomTiles() { OtherLogger.Log("Custom cate