Decompiled source of MoreItemsInDevTools v3.0.3

Mods/MoreItemsInDevToolsML6.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.Json;
using BoneLib;
using BoneLib.BoneMenu;
using BoneLib.Notifications;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Bonelab;
using Il2CppSLZ.Marrow.Data;
using Il2CppSLZ.Marrow.Pool;
using Il2CppSLZ.Marrow.Warehouse;
using LabFusion.Network;
using LabFusion.Patching;
using LabFusion.RPC;
using MelonLoader;
using MelonLoader.Utils;
using MoreItemsInDevTools;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyDescription("Adds more items to list of items spawned by dev tools cheat")]
[assembly: AssemblyFileVersion("3.0.3")]
[assembly: AssemblyInformationalVersion("3.0.3")]
[assembly: AssemblyCopyright("Developed by doge15567")]
[assembly: AssemblyTrademark("")]
[assembly: MelonInfo(typeof(Main), "More Items in Dev Tools (Update BoneMenu)", "3.0.3", "doge15567", "https://thunderstore.io/c/bonelab/p/doge15567/MoreItemsInDevTools/")]
[assembly: MelonColor(255, 255, 255, 255)]
[assembly: MelonOptionalDependencies(new string[] { "LabFusion", "BoneLib" })]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("MoreItemsInDevToolsML6")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyProduct("MoreItemsInDevToolsML6")]
[assembly: AssemblyTitle("MoreItemsInDevToolsML6")]
[assembly: AssemblyVersion("3.0.3.0")]
namespace MoreItemsInDevTools
{
	internal class Bonemenu
	{
		private static Page _mainCategory;

		private static Page _presetCategory;

		private static FunctionElement _presetCategoryLink;

		public static PresetManager _presetManager = new PresetManager();

		public static void BonemenuSetup()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			_presetManager.OnStart();
			_mainCategory = Page.Root.CreatePage("MoreItemsInDevTools", Color.white, 0, true);
			_mainCategory.CreateFunction("Reload Presets from File", Color.yellow, (Action)delegate
			{
				_presetManager.LoadPresets();
				RebuildBonemenu();
			});
		}

		public static void BoneMenuNotif(NotificationType type, string content)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_0015: 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)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			Notifier.Send(new Notification
			{
				Title = NotificationText.op_Implicit("MoreItemsInDevTools"),
				Message = NotificationText.op_Implicit(content),
				Type = type,
				PopupLength = 3f,
				ShowTitleOnPopup = true
			});
		}

		public static void RebuildBonemenu()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			if (_presetCategory != null)
			{
				Menu.DestroyPage(_presetCategory);
				_mainCategory.Remove((Element)(object)_presetCategoryLink);
			}
			CheckForDefaultPreset();
			_presetCategory = _mainCategory.CreatePage("Presets", Color.white, 0, false);
			_presetCategoryLink = (FunctionElement)(object)_mainCategory.CreatePageLink(_presetCategory);
			_presetCategory.CreateFunction("Create New Preset", Color.green, (Action)delegate
			{
				string presetName = "Preset " + _presetManager.GetNumberOfPresets();
				_presetManager.LoadPresets();
				if (_presetManager.CreateNewPreset(presetName))
				{
					CreatePresetCatagory(_presetCategory, presetName);
				}
			});
			foreach (KeyValuePair<string, PresetData> preset in _presetManager.presets)
			{
				CreatePresetCatagory(_presetCategory, preset.Key);
			}
		}

		public static void CreatePresetCatagory(Page category, string presetName)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_00bd: 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)
			Page _category = category.CreatePage(presetName, Color.white, 0, false);
			PageLinkElement _categoryLink = category.CreatePageLink(_category);
			_presetManager.GetPresetData(presetName);
			_category.CreateFunction(presetName, Color.white, (Action)delegate
			{
			});
			_category.CreateFunction("Apply Preset", Color.cyan, (Action)delegate
			{
				_presetManager.LoadPresets();
				Main.SetCheatMenuItems(_presetManager.GetPresetData(presetName).Barcodes.ToArray());
			});
			_category.CreateFunction("Add Item", Color.green, (Action)delegate
			{
				string content = "";
				try
				{
					if ((Object)(object)Player.GetObjectInHand(Player.LeftHand) == (Object)null)
					{
						content = "Error: Nothing in left hand.";
						throw new Exception();
					}
					if ((Object)(object)Player.GetComponentInHand<Poolee>(Player.LeftHand).SpawnableCrate == (Object)null)
					{
						content = "Error: Object is not a spawnable, or is a prefab.";
						throw new Exception();
					}
					string iD = ((Scannable)Player.GetComponentInHand<Poolee>(Player.LeftHand).SpawnableCrate).Barcode.ID;
					_presetManager.AddBarcodeToPreset(presetName, iD);
					CreatePBarcodeCatagory(_category, iD);
					_presetManager.SavePresets();
				}
				catch (Exception)
				{
					BoneMenuNotif((NotificationType)2, content);
				}
			});
			if (presetName != "DEFAULT")
			{
				_category.CreateFunction("Remove Preset", Color.red, (Action)delegate
				{
					_presetManager.RemovePreset(presetName);
					Menu.DestroyPage(_category);
					category.Remove((Element)(object)_categoryLink);
					_presetManager.SavePresets();
					Menu.OpenPage(category);
				});
			}
			foreach (string barcode in _presetManager.GetPresetData(presetName).Barcodes)
			{
				CreatePBarcodeCatagory(_category, barcode);
			}
		}

		public static void CreatePBarcodeCatagory(Page category, string Barcode)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			Crate val = default(Crate);
			AssetWarehouse.Instance.TryGetCrate(new Barcode
			{
				ID = Barcode
			}, ref val);
			string title = ((Scannable)val).Title;
			Page _category = category.CreatePage(title, Color.white, 0, false);
			PageLinkElement _categoryLink = category.CreatePageLink(_category);
			_category.CreateFunction(title, Color.white, (Action)delegate
			{
			});
			_category.CreateFunction(Barcode, Color.white, (Action)delegate
			{
			});
			_category.CreateFunction("Remove Item", Color.red, (Action)delegate
			{
				_presetManager.RemoveBarcodeFromPreset(category.Name, Barcode);
				Menu.DestroyPage(_category);
				category.Remove((Element)(object)_categoryLink);
				Menu.OpenPage(category);
			});
		}

		public static void CheckForDefaultPreset()
		{
			if (!_presetManager.presets.ContainsKey("DEFAULT"))
			{
				BoneMenuNotif((NotificationType)2, "Error: No DEFAULT preset detected! Attempting to create a new one \n Organization of the JSON file might be mangled!");
				_presetManager.CreateNewPreset("DEFAULT");
			}
		}
	}
	internal class Main : MelonMod
	{
		internal const string Name = "More Items in Dev Tools (Update BoneMenu)";

		internal const string Description = "Adds more items to list of items spawned by dev tools cheat";

		internal const string Author = "doge15567";

		internal const string Company = "";

		internal const string Version = "3.0.3";

		internal const string DownloadLink = "https://thunderstore.io/c/bonelab/p/doge15567/MoreItemsInDevTools/";

		internal static Instance MelonLog;

		internal static Harmony Harmoney;

		internal static bool hasbonelib;

		internal static CheatTool playerCheatMenu;

		public static PresetManager _presetManager = new PresetManager();

		public static string[] currentPresetArray;

		public static CheatTool currentInstance;

		public override void OnInitializeMelon()
		{
			MelonLog = ((MelonBase)this).LoggerInstance;
			Harmoney = ((MelonBase)this).HarmonyInstance;
			MelonLog.Msg("Initalised Mod");
			_presetManager.OnStart();
			hasbonelib = false;
			hasbonelib = CheckIfAssemblyLoaded("BoneLib");
			if (hasbonelib)
			{
				BonelibSetup();
			}
		}

		private static void BonelibSetup()
		{
			Bonemenu.BonemenuSetup();
			Hooking.OnMarrowGameStarted += OnMarrowGameStartedHook;
		}

		public static void OnMarrowGameStartedHook()
		{
			Bonemenu.RebuildBonemenu();
		}

		public static void SetCheatMenuItems(string[] BarcodeStrArray)
		{
			//IL_0021: 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_0027: 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_0038: Expected O, but got Unknown
			//IL_003d: Expected O, but got Unknown
			currentPresetArray = BarcodeStrArray;
			playerCheatMenu = currentInstance;
			List<SpawnableCrateReference> list = new List<SpawnableCrateReference>();
			foreach (string iD in BarcodeStrArray)
			{
				list.Add(new SpawnableCrateReference
				{
					_barcode = new Barcode
					{
						ID = iD
					}
				});
			}
			playerCheatMenu.crates = Il2CppReferenceArray<SpawnableCrateReference>.op_Implicit(list.ToArray());
		}

		public static bool CheckIfAssemblyLoaded(string name)
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			for (int i = 0; i < assemblies.Length; i++)
			{
				if (assemblies[i].GetName().Name.ToLower() == name.ToLower())
				{
					return true;
				}
			}
			return false;
		}
	}
	public class PresetData
	{
		public List<string> Barcodes { get; set; }
	}
	public class PresetManager
	{
		public Dictionary<string, PresetData> presets;

		private string filePath = MelonEnvironment.UserDataDirectory + "/MoreItemsInDevTools.json";

		public readonly Dictionary<string, PresetData> DefaultJsonDict = new Dictionary<string, PresetData> { 
		{
			"DEFAULT",
			new PresetData
			{
				Barcodes = new List<string> { "c1534c5a-5747-42a2-bd08-ab3b47616467", "c1534c5a-6b38-438a-a324-d7e147616467", "c1534c5a-3813-49d6-a98c-f595436f6e73", "c1534c5a-c6a8-45d0-aaa2-2c954465764d" }
			}
		} };

		private JsonSerializerOptions prettyPrint = new JsonSerializerOptions
		{
			WriteIndented = true
		};

		public void OnStart()
		{
			LoadPresets();
			SavePresets();
		}

		public void LoadPresets()
		{
			if (File.Exists(filePath))
			{
				string json = File.ReadAllText(filePath);
				presets = JsonSerializer.Deserialize<Dictionary<string, PresetData>>(json);
			}
			else
			{
				presets = DefaultJsonDict;
				SavePresets();
			}
		}

		public void SavePresets()
		{
			string contents = JsonSerializer.Serialize(presets, prettyPrint);
			File.WriteAllText(filePath, contents);
		}

		public void CheckForDefaultPreset()
		{
			if (!presets.ContainsKey("DEFAULT"))
			{
				CreateNewPreset("DEFAULT");
			}
		}

		public void AddBarcodeToPreset(string presetName, string barcode)
		{
			if (presets.ContainsKey(presetName))
			{
				presets[presetName].Barcodes.Add(barcode);
				SavePresets();
			}
			else
			{
				Main.MelonLog.Error("Function AddBarcodeToPreset: Attempted to add a barcode to a preset that doesnt exist. (?????????)");
			}
		}

		public void RemoveBarcodeFromPreset(string presetName, string barcode)
		{
			if (presets.ContainsKey(presetName))
			{
				presets[presetName].Barcodes.Remove(barcode);
				SavePresets();
			}
			else
			{
				Main.MelonLog.Error("Function RemoveBarcodeToPreset: Attempted to remove a barcode to a preset that doesnt exist. (???).");
			}
		}

		public bool CreateNewPreset(string presetName)
		{
			if (!presets.ContainsKey(presetName))
			{
				presets.Add(presetName, new PresetData
				{
					Barcodes = new List<string> { "c1534c5a-5747-42a2-bd08-ab3b47616467", "c1534c5a-6b38-438a-a324-d7e147616467", "c1534c5a-3813-49d6-a98c-f595436f6e73", "c1534c5a-c6a8-45d0-aaa2-2c954465764d" }
				});
				SavePresets();
				return true;
			}
			Main.MelonLog.Msg("Function CreateNewPreset: Attempted to create a new preset with a pre-existing name.");
			return false;
		}

		public void RemovePreset(string presetName)
		{
			if (presets.ContainsKey(presetName))
			{
				presets.Remove(presetName);
				SavePresets();
			}
			else
			{
				Main.MelonLog.Msg("RemovePreset: Preset not found.");
			}
		}

		public PresetData GetPresetData(string presetName)
		{
			if (presets.ContainsKey(presetName))
			{
				return presets[presetName];
			}
			Main.MelonLog.Msg("GetPresetData: Preset not found.");
			return null;
		}

		public int GetNumberOfPresets()
		{
			return presets.Count;
		}
	}
}
namespace MoreItemsInDevTools.Patches
{
	[HarmonyPatch(typeof(CheatTool))]
	[HarmonyPatch("Start")]
	public class CheatToolPatch
	{
		private static bool Prefix(CheatTool __instance)
		{
			Main.currentInstance = __instance;
			Main._presetManager.CheckForDefaultPreset();
			Main._presetManager.LoadPresets();
			Main.SetCheatMenuItems(Main._presetManager.presets["DEFAULT"].Barcodes.ToArray());
			return true;
		}
	}
	[HarmonyPatch(typeof(AddDevMenuPatch), "OnSpawnDelegate")]
	public static class PreventFusionPatch
	{
		[HarmonyPrefix]
		public static bool Prefix(PopUpMenuView menu, Action originalDelegate)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_004a: Expected O, but got Unknown
			//IL_004c: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkInfo.HasServer)
			{
				return true;
			}
			CheatTool currentInstance = Main.currentInstance;
			Transform transform = ((Component)menu.radialPageView).transform;
			foreach (SpawnableCrateReference item in (Il2CppArrayBase<SpawnableCrateReference>)(object)currentInstance.crates)
			{
				Spawnable spawnable = new Spawnable
				{
					crateRef = new SpawnableCrateReference(((Scannable)((CrateReferenceT<SpawnableCrate>)(object)item).Crate).Barcode)
				};
				SpawnRequestInfo val = default(SpawnRequestInfo);
				val.spawnable = spawnable;
				val.position = transform.position;
				val.rotation = transform.rotation;
				NetworkAssetSpawner.Spawn(val);
			}
			return false;
		}
	}
}