Decompiled source of LabworksAmmoProvider v1.0.0

Mods/LabworksAmmoProvider.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BoneLib;
using BoneLib.BoneMenu;
using HarmonyLib;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.SceneStreaming;
using Il2CppSLZ.Marrow.Warehouse;
using LabworksAmmoProvider;
using MelonLoader;
using MelonLoader.Preferences;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Main), "LabworksAmmoProvider", "1.0.0", "Acanthi", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: AssemblyTitle("LabworksAmmoProvider")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LabworksAmmoProvider")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c6c65e58-766b-416d-a606-4b6a953312c7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LabworksAmmoProvider
{
	internal class AmmoTools
	{
		public static void SaveAmmo()
		{
			if ((Object)(object)AmmoInventory.Instance == (Object)null)
			{
				MelonLogger.Msg("AmmoInventory Instance is Null");
				return;
			}
			if (BonemenuAdder.ammo.Value == null)
			{
				MelonLogger.Msg("Ammo Value is Null");
				return;
			}
			List<int> list = new List<int>();
			list.Add(AmmoInventory.Instance.GetCartridgeCount("light"));
			list.Add(AmmoInventory.Instance.GetCartridgeCount("medium"));
			list.Add(AmmoInventory.Instance.GetCartridgeCount("heavy"));
			BonemenuAdder.ammo.Value = list;
			((MelonPreferences_Entry)BonemenuAdder.ammo).Save();
		}

		public static void ClearAmmo()
		{
			if ((Object)(object)AmmoInventory.Instance == (Object)null)
			{
				MelonLogger.Msg("AmmoInventory Instance is Null");
				return;
			}
			if (BonemenuAdder.ammo.Value == null)
			{
				MelonLogger.Msg("Ammo Value is Null");
				return;
			}
			AmmoInventory.Instance.ClearAmmo();
			BonemenuAdder.ammo.Value[0] = 0;
			BonemenuAdder.ammo.Value[1] = 0;
			BonemenuAdder.ammo.Value[2] = 0;
			((MelonPreferences_Entry)BonemenuAdder.ammo).Save();
		}

		public static void SetAmmo()
		{
			if ((Object)(object)AmmoInventory.Instance == (Object)null)
			{
				MelonLogger.Msg("AmmoInventory Instance is Null");
				return;
			}
			if (BonemenuAdder.ammo.Value == null)
			{
				MelonLogger.Msg("Ammo Value is Null");
				return;
			}
			List<int> value = BonemenuAdder.ammo.Value;
			AmmoInventory.Instance.ClearAmmo();
			AmmoInventory.Instance.AddCartridge(AmmoInventory.Instance.lightAmmoGroup, value[0]);
			AmmoInventory.Instance.AddCartridge(AmmoInventory.Instance.mediumAmmoGroup, value[1]);
			AmmoInventory.Instance.AddCartridge(AmmoInventory.Instance.heavyAmmoGroup, value[2]);
		}
	}
	internal class BonemenuAdder
	{
		private static MelonPreferences_Category category;

		public static Page MainPage;

		public static MelonPreferences_Entry<List<int>> ammo;

		public static void CreateBoneMenu()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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)
			category = MelonPreferences.CreateCategory("Labworks_Ammo_Provider");
			ammo = category.CreateEntry<List<int>>("ammo", new List<int> { 0, 0, 0 }, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			MainPage = Page.Root.CreatePage("Labworks Ammo Provider", Color.green, 0, true);
			MainPage.CreateFunction("Reset Ammo", Color.yellow, (Action)delegate
			{
				AmmoTools.ClearAmmo();
			});
			MainPage.CreateFunction("Force Save", Color.yellow, (Action)delegate
			{
				AmmoTools.SaveAmmo();
			});
			MainPage.CreateFunction("Force Load", Color.yellow, (Action)delegate
			{
				AmmoTools.SetAmmo();
			});
		}
	}
	public static class BuildInfo
	{
		public const string Name = "LabworksAmmoProvider";

		public const string Description = "Because Labworks Ammo Saver was taken ;)";

		public const string Author = "Acanthi";

		public const string Company = null;

		public const string Version = "1.0.0";

		public const string DownloadLink = null;
	}
	public class Main : MelonMod
	{
		internal static LevelInfo publicLevelInfo;

		internal static bool usePatchedSave;

		public override void OnLateInitializeMelon()
		{
			Hooking.OnLevelLoaded += LevelLoaded;
			BonemenuAdder.CreateBoneMenu();
		}

		private void LevelLoaded(LevelInfo info)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			publicLevelInfo = info;
		}

		public static void LoadingSave()
		{
			string text = publicLevelInfo.barcode.ToString();
			if (publicLevelInfo.title.ToString().ToLower().Contains("boneworks") && text != "volx4.LabWorksBoneworksPort.Level.BoneworksRedactedChamber" && text != "volx4.LabWorksBoneworksPort.Level.BoneworksMainMenu")
			{
				AmmoTools.SaveAmmo();
			}
		}

		public static void AwakeLoad()
		{
			string text = publicLevelInfo.barcode.ToString();
			if (publicLevelInfo.title.ToString().ToLower().Contains("boneworks") && text != "volx4.LabWorksBoneworksPort.Level.BoneworksRedactedChamber" && text != "volx4.LabWorksBoneworksPort.Level.BoneworksMainMenu")
			{
				AmmoTools.SetAmmo();
			}
		}
	}
}
namespace LabworksAmmoProvider.Patches
{
	[HarmonyPatch(typeof(AmmoInventory))]
	internal class AmmoInventoryPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		[HarmonyPriority(0)]
		public static void Awake(AmmoInventory __instance)
		{
			MelonLogger.Msg("[LabworksAmmoProvider] Loading ammo post-AmmoInventory.Awake...");
			Main.AwakeLoad();
		}
	}
	[HarmonyPatch(typeof(SceneStreamer), "Load", new Type[]
	{
		typeof(LevelCrateReference),
		typeof(LevelCrateReference)
	})]
	internal class OnLoadPatch
	{
		[HarmonyPrefix]
		public static void Load(LevelCrateReference level, LevelCrateReference loadLevel)
		{
			MelonLogger.Msg("[LabworksAmmoProvider] Saving ammo pre-load...");
			Main.LoadingSave();
		}
	}
}