Decompiled source of CustomOrderLimit v1.0.0

CustomOrderLimit.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using CustomOrderLimit;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using ScheduleOne.Economy;
using ScheduleOne.Persistence;
using ScheduleOne.UI.Phone;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Core), "CustomOrderLimit", "1.0.0", "BULLETBOT", "https://thunderstore.io/c/schedule-i/p/BULLETBOT/CustomOrderLimit")]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: HarmonyDontPatchAll]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CustomOrderLimit")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CustomOrderLimit")]
[assembly: AssemblyTitle("CustomOrderLimit")]
[assembly: NeutralResourcesLanguage("en-US")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CustomOrderLimit
{
	public class Core : MelonMod
	{
		internal const string modName = "CustomOrderLimit";

		internal static Core instance;

		internal int fixedItemLimit;

		private MelonPreferences_Category generalCategory;

		internal MelonPreferences_Entry<int> itemLimit;

		private void LimitNumberForItemLimit(int value)
		{
			bool flag = false;
			if (value < 1)
			{
				itemLimit.Value = 1;
				flag = true;
			}
			else if (value > 99)
			{
				itemLimit.Value = 99;
				flag = true;
			}
			if (flag)
			{
				generalCategory.SaveToFile(false);
			}
		}

		public override void OnInitializeMelon()
		{
			instance = this;
			fixedItemLimit = -1;
			generalCategory = MelonPreferences.CreateCategory("CustomOrderLimit");
			int num = 10;
			itemLimit = generalCategory.CreateEntry<int>("Item Limit", num, (string)null, $"Self-explanatory. Default value is {num}.", false, false, (ValueValidator)null, (string)null);
			LimitNumberForItemLimit(itemLimit.Value);
			((MelonEventBase<LemonAction<int, int>>)(object)itemLimit.OnEntryValueChanged).Subscribe((LemonAction<int, int>)delegate(int _, int value)
			{
				LimitNumberForItemLimit(value);
			}, 0, false);
			generalCategory.SaveToFile(false);
			((MelonBase)this).HarmonyInstance.PatchAll();
			((MelonBase)this).LoggerInstance.Msg("Initialized.");
		}
	}
}
namespace CustomOrderLimit.Patches
{
	[HarmonyPatch(typeof(LoadManager))]
	internal class LoadManagerPatch
	{
		[HarmonyPatch("StartGame")]
		[HarmonyPostfix]
		private static void StartGame()
		{
			Core.instance.fixedItemLimit = Core.instance.itemLimit.Value;
		}

		[HarmonyPatch("LoadAsClient")]
		[HarmonyPostfix]
		private static void LoadAsClient()
		{
			Core.instance.fixedItemLimit = Core.instance.itemLimit.Value;
		}

		[HarmonyPatch("LoadTutorialAsClient")]
		[HarmonyPostfix]
		private static void LoadTutorialAsClient()
		{
			Core.instance.fixedItemLimit = Core.instance.itemLimit.Value;
		}

		[HarmonyPatch("ExitToMenu")]
		[HarmonyPostfix]
		private static void ExitToMenu()
		{
			Core.instance.fixedItemLimit = -1;
		}
	}
	[HarmonyPatch(typeof(Supplier))]
	internal class SupplierPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPrefix]
		private static void Awake(ref float ___MaxOrderLimit)
		{
			___MaxOrderLimit *= (float)Core.instance.fixedItemLimit / 10f;
		}
	}
	[HarmonyPatch(typeof(PhoneShopInterface))]
	internal class PhoneShopInterfacePatch
	{
		private static IEnumerable<CodeInstruction> ApplyTranspiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldc_I4_S && (sbyte)list[i].operand == 10)
				{
					list[i] = new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(PhoneShopInterfacePatch), "GetItemLimit", (Type[])null, (Type[])null));
				}
			}
			return list.AsEnumerable();
		}

		internal static int GetItemLimit()
		{
			return Core.instance.fixedItemLimit;
		}

		[HarmonyPatch("CanConfirmOrder")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> CanConfirmOrder(IEnumerable<CodeInstruction> instructions)
		{
			return ApplyTranspiler(instructions);
		}

		[HarmonyPatch("UpdateOrderTotal")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> UpdateOrderTotal(IEnumerable<CodeInstruction> instructions)
		{
			return ApplyTranspiler(instructions);
		}
	}
}