Decompiled source of AutoAmmo v1.0.0

Mods/AutoAmmo.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using AutoAmmo;
using AutoAmmo.Utilities;
using BoneLib;
using BoneLib.BoneMenu;
using HarmonyLib;
using Il2CppSLZ.Bonelab;
using Il2CppSLZ.Bonelab.SaveData;
using Il2CppSLZ.Marrow;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "Auto Ammo", "1.0.0", "Camobiwon", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: MelonColor(255, 0, 255, 255)]
[assembly: MelonAuthorColor(255, 0, 100, 255)]
[assembly: RequiresPreviewFeatures]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("AutoAmmo")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AutoAmmo")]
[assembly: AssemblyTitle("AutoAmmo")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace AutoAmmo
{
	public static class BuildInfo
	{
		public const string Name = "Auto Ammo";

		public const string Author = "Camobiwon";

		public const string Version = "1.0.0";

		public const string Company = "Camobiwon";

		public const string DownloadLink = null;
	}
	public class Core : MelonMod
	{
		internal static Core Instance;

		internal static MelonPreferences_Category PrefsCategory { get; private set; }

		public static Page RootPage { get; private set; }

		private Core()
		{
			Instance = this;
		}

		public override void OnInitializeMelon()
		{
			PrefsCategory = MelonPreferences.CreateCategory("Auto Ammo");
			Mod.Initialize();
			SavePrefences();
		}

		internal static void SavePrefences()
		{
			PrefsCategory.SaveToFile(false);
		}

		public static void Log(object message)
		{
			((MelonBase)Instance).LoggerInstance.Msg(message?.ToString() ?? "null");
		}

		public static void Log(object message, ConsoleColor color)
		{
			((MelonBase)Instance).LoggerInstance.Msg(color, message?.ToString() ?? "null");
		}

		public static void Warn(object message)
		{
			((MelonBase)Instance).LoggerInstance.Warning(message?.ToString() ?? "null");
		}

		public static void Error(object message)
		{
			((MelonBase)Instance).LoggerInstance.Error(message?.ToString() ?? "null");
		}

		[Conditional("DEBUG")]
		internal static void DebugLog(object message)
		{
			Log(message);
		}

		[Conditional("DEBUG")]
		internal static void DebugWarn(object message)
		{
			Warn(message);
		}

		[Conditional("DEBUG")]
		internal static void DebugError(object message)
		{
			Error(message);
		}
	}
	[HarmonyPatch]
	internal class Mod
	{
		private static MelonPreferences_Entry<int> autoAmmo;

		private static MelonPreferences_Entry<bool> removeFromMenu;

		internal static void Initialize()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			autoAmmo = Core.PrefsCategory.CreateEntry<int>("Auto Ammo", 0, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			removeFromMenu = Core.PrefsCategory.CreateEntry<bool>("Remove From Menu", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			if (removeFromMenu.Value)
			{
				return;
			}
			Page obj = Page.Root.CreatePage("Auto Ammo", Color.yellow, 0, true);
			obj.CreateIntPref("Auto Ammo", Color.white, ref autoAmmo, 1000, 0, 1000000000);
			obj.CreateFunction($"+{10000} All Ammo", Color.white, (Action)delegate
			{
				AmmoInventory instance = AmmoInventory.Instance;
				instance.AddCartridge(instance.lightAmmoGroup, 10000);
				instance.AddCartridge(instance.mediumAmmoGroup, 10000);
				instance.AddCartridge(instance.heavyAmmoGroup, 10000);
			});
			obj.CreateFunction("Remove From BoneMenu", Color.red, (Action)delegate
			{
				Menu.DisplayDialog("Remove", "This will remove the page from BoneMenu on next bootup, preferences will still be saved and are acccessible at MelonPrefs.cfg. Confirm?", (Texture2D)null, (Action)delegate
				{
					removeFromMenu.Value = true;
					Core.SavePrefences();
				}, (Action)null);
			});
		}

		[HarmonyPatch(typeof(AmmoInventory), "Awake")]
		[HarmonyPatch(typeof(BonelabProgressionHelper), "RestoreAmmoCounts", new Type[]
		{
			typeof(PlayerProgression),
			typeof(string),
			typeof(bool),
			typeof(string[])
		})]
		[HarmonyPatch(typeof(Control_Gashapon), "SetupAmmo")]
		[HarmonyPostfix]
		private static void AddAmmo()
		{
			if (autoAmmo.Value > 0)
			{
				AmmoInventory instance = AmmoInventory.Instance;
				if ((Object)(object)instance != (Object)null)
				{
					instance.AddCartridge(instance.lightAmmoGroup, autoAmmo.Value);
					instance.AddCartridge(instance.mediumAmmoGroup, autoAmmo.Value);
					instance.AddCartridge(instance.heavyAmmoGroup, autoAmmo.Value);
				}
			}
		}
	}
}
namespace AutoAmmo.Utilities
{
	public static class MenuHelper
	{
		internal static IntElement CreateIntPref(this Page page, string name, Color color, ref MelonPreferences_Entry<int> value, int increment, int minValue, int maxValue, Action<int> callback = null, string prefName = null, int prefDefaultValue = 0)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return page.CreateIntPref(name, color, ref value, Core.PrefsCategory, increment, minValue, maxValue, callback, prefName, prefDefaultValue);
		}

		internal static FloatElement CreateFloatPref(this Page page, string name, Color color, ref MelonPreferences_Entry<float> value, float increment, float minValue, float maxValue, Action<float> callback = null, string prefName = null, float prefDefaultValue = 0f)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return page.CreateFloatPref(name, color, ref value, Core.PrefsCategory, increment, minValue, maxValue, callback, prefName, prefDefaultValue);
		}

		internal static BoolElement CreateBoolPref(this Page page, string name, Color color, ref MelonPreferences_Entry<bool> value, Action<bool> callback = null, string prefName = null, bool prefDefaultValue = false)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return page.CreateBoolPref(name, color, ref value, Core.PrefsCategory, callback, prefName, prefDefaultValue);
		}

		internal static EnumElement CreateEnumPref<T>(this Page page, string name, Color color, ref MelonPreferences_Entry<T> value, Action<Enum> callback = null, string prefName = null, Enum prefDefaultValue = null) where T : Enum
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return page.CreateEnumPref(name, color, ref value, Core.PrefsCategory, callback, prefName, prefDefaultValue);
		}

		internal static StringElement CreateStringPref(this Page page, string name, Color color, ref MelonPreferences_Entry<string> value, Action<string> callback = null, string prefName = null, string prefDefaultValue = null)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return page.CreateStringPref(name, color, ref value, Core.PrefsCategory, callback, prefName, prefDefaultValue);
		}

		public static IntElement CreateIntPref(this Page page, string name, Color color, ref MelonPreferences_Entry<int> value, MelonPreferences_Category prefCategory, int increment, int minValue, int maxValue, Action<int> callback = null, string prefName = null, int prefDefaultValue = 0)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (prefName == null)
			{
				prefName = name;
			}
			if (!prefCategory.HasEntry(prefName))
			{
				value = prefCategory.CreateEntry<int>(prefName, prefDefaultValue, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			}
			MelonPreferences_Entry<int> val = value;
			return page.CreateInt(name, color, val.Value, increment, minValue, maxValue, (Action<int>)delegate(int x)
			{
				val.Value = x;
				prefCategory.SaveToFile(false);
				Action<int> action = callback;
				if (action != null)
				{
					Extensions.InvokeActionSafe<int>(action, x);
				}
			});
		}

		public static FloatElement CreateFloatPref(this Page page, string name, Color color, ref MelonPreferences_Entry<float> value, MelonPreferences_Category prefCategory, float increment, float minValue, float maxValue, Action<float> callback = null, string prefName = null, float prefDefaultValue = 0f)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (prefName == null)
			{
				prefName = name;
			}
			if (!prefCategory.HasEntry(prefName))
			{
				value = prefCategory.CreateEntry<float>(prefName, prefDefaultValue, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			}
			MelonPreferences_Entry<float> val = value;
			return page.CreateFloat(name, color, val.Value, increment, minValue, maxValue, (Action<float>)delegate(float x)
			{
				val.Value = x;
				prefCategory.SaveToFile(false);
				Action<float> action = callback;
				if (action != null)
				{
					Extensions.InvokeActionSafe<float>(action, x);
				}
			});
		}

		public static BoolElement CreateBoolPref(this Page page, string name, Color color, ref MelonPreferences_Entry<bool> value, MelonPreferences_Category prefCategory, Action<bool> callback = null, string prefName = null, bool prefDefaultValue = false)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (prefName == null)
			{
				prefName = name;
			}
			if (!prefCategory.HasEntry(prefName))
			{
				value = prefCategory.CreateEntry<bool>(prefName, prefDefaultValue, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			}
			MelonPreferences_Entry<bool> val = value;
			return page.CreateBool(name, color, val.Value, (Action<bool>)delegate(bool x)
			{
				val.Value = x;
				prefCategory.SaveToFile(false);
				Action<bool> action = callback;
				if (action != null)
				{
					Extensions.InvokeActionSafe<bool>(action, x);
				}
			});
		}

		public static EnumElement CreateEnumPref<T>(this Page page, string name, Color color, ref MelonPreferences_Entry<T> value, MelonPreferences_Category prefCategory, Action<Enum> callback = null, string prefName = null, Enum prefDefaultValue = null) where T : Enum
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			if (prefName == null)
			{
				prefName = name;
			}
			if (!prefCategory.HasEntry(prefName))
			{
				value = prefCategory.CreateEntry<T>(prefName, (T)prefDefaultValue, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			}
			MelonPreferences_Entry<T> val = value;
			return page.CreateEnum(name, color, (Enum)val.Value, (Action<Enum>)delegate(Enum x)
			{
				val.Value = (T)x;
				prefCategory.SaveToFile(false);
				Action<Enum> action = callback;
				if (action != null)
				{
					Extensions.InvokeActionSafe<Enum>(action, x);
				}
			});
		}

		public static StringElement CreateStringPref(this Page page, string name, Color color, ref MelonPreferences_Entry<string> value, MelonPreferences_Category prefCategory, Action<string> callback = null, string prefName = null, string prefDefaultValue = null)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (prefName == null)
			{
				prefName = name;
			}
			if (!prefCategory.HasEntry(prefName))
			{
				value = prefCategory.CreateEntry<string>(prefName, prefDefaultValue, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			}
			MelonPreferences_Entry<string> val = value;
			StringElement obj = page.CreateString(name, color, val.Value, (Action<string>)delegate(string x)
			{
				val.Value = x;
				prefCategory.SaveToFile(false);
				Action<string> action = callback;
				if (action != null)
				{
					Extensions.InvokeActionSafe<string>(action, x);
				}
			});
			obj.Value = value.Value;
			return obj;
		}
	}
}