Decompiled source of IncreaseBuyLimitIL2CPP v1.0.1

Mods\IncreaseBuyLimitIL2CPP.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.Money;
using Il2CppScheduleOne.UI.Phone.Delivery;
using Il2CppScheduleOne.UI.Shop;
using Il2CppSystem;
using Il2CppTMPro;
using IncreaseBuyLimit;
using MelonLoader;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(IncreaseBuyLimitMod), "IncreaseBuyLimit", "1.0.1", "lasersquid", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("IncreaseBuyLimitIL2CPP")]
[assembly: AssemblyConfiguration("IL2CPP")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+afa4a1019183c089c77fab21700eb9f2abdfb523")]
[assembly: AssemblyProduct("IncreaseBuyLimitIL2CPP")]
[assembly: AssemblyTitle("IncreaseBuyLimitIL2CPP")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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 IncreaseBuyLimit
{
	public class IncreaseBuyLimitMod : MelonMod
	{
		public Harmony harmony = new Harmony("com.lasersquid.increasebuylimit");

		public override void OnInitializeMelon()
		{
			((MelonBase)this).LoggerInstance.Msg("Initialized.");
		}
	}
	public class Sched1PatchesBase
	{
		public static object GetField(Type type, string fieldName, object target)
		{
			return AccessTools.Property(type, fieldName).GetValue(target);
		}

		public static void SetField(Type type, string fieldName, object target, object value)
		{
			AccessTools.Property(type, fieldName).SetValue(target, value);
		}

		public static object GetProperty(Type type, string fieldName, object target)
		{
			return AccessTools.Property(type, fieldName).GetValue(target);
		}

		public static void SetProperty(Type type, string fieldName, object target, object value)
		{
			AccessTools.Property(type, fieldName).SetValue(target, value);
		}

		public static object CallMethod(Type type, string methodName, object target, object[] args)
		{
			return AccessTools.Method(type, methodName, (Type[])null, (Type[])null).Invoke(target, args);
		}

		public static T CastTo<T>(object o) where T : class
		{
			if (!(o is T result))
			{
				return null;
			}
			return result;
		}

		public static bool Is<T>(object o)
		{
			return o is T;
		}

		public static T CastTo<T>(Object o) where T : Il2CppObjectBase
		{
			return ((Il2CppObjectBase)o).TryCast<T>();
		}

		public static bool Is<T>(Object o) where T : Il2CppObjectBase
		{
			return ((Il2CppObjectBase)o).TryCast<T>() != null;
		}

		public static UnityAction ToUnityAction(Action action)
		{
			return DelegateSupport.ConvertDelegate<UnityAction>((Delegate)action);
		}

		public static UnityAction<T> ToUnityAction<T>(Action<T> action)
		{
			return DelegateSupport.ConvertDelegate<UnityAction<T>>((Delegate)action);
		}
	}
	[HarmonyPatch]
	public class ShopPatches : Sched1PatchesBase
	{
		[HarmonyPatch(typeof(ShopAmountSelector), "OnValueChanged")]
		[HarmonyPrefix]
		public static bool OnValueChangedPrefix(ShopAmountSelector __instance, string value)
		{
			if (int.TryParse(value, out var result))
			{
				Sched1PatchesBase.SetProperty(typeof(ShopAmountSelector), "SelectedAmount", __instance, Mathf.Clamp(result, 1, 999999));
				__instance.InputField.SetTextWithoutNotify(__instance.SelectedAmount.ToString());
				return false;
			}
			Sched1PatchesBase.SetProperty(typeof(ShopAmountSelector), "SelectedAmount", __instance, 1);
			__instance.InputField.SetTextWithoutNotify(string.Empty);
			return false;
		}

		[HarmonyPatch(typeof(ShopAmountSelector), "OnSubmitted")]
		[HarmonyPrefix]
		public static bool OnSubmittedPrefix(ShopAmountSelector __instance, string value)
		{
			if (!__instance.IsOpen)
			{
				return false;
			}
			Sched1PatchesBase.CallMethod(typeof(ShopAmountSelector), "OnValueChanged", __instance, new object[1] { value });
			if (__instance.onSubmitted != null)
			{
				__instance.onSubmitted.Invoke(__instance.SelectedAmount);
			}
			__instance.Close();
			return false;
		}

		[HarmonyPatch(typeof(ShopAmountSelector), "Open")]
		[HarmonyPrefix]
		public static void OpenPrefix(ShopAmountSelector __instance)
		{
			//IL_0042: 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)
			if (__instance.InputField.characterLimit != 6)
			{
				__instance.InputField.characterLimit = 6;
				TMP_InputField inputField = __instance.InputField;
				inputField.pointSize -= 2f;
				Rect rect = __instance.Container.rect;
				float num = ((Rect)(ref rect)).width * 1.5f;
				__instance.Container.SetSizeWithCurrentAnchors((Axis)0, num);
			}
		}

		[HarmonyPatch(typeof(CartEntry), "Initialize")]
		[HarmonyPrefix]
		public static bool CartEntryInitializePrefix(CartEntry __instance, Cart cart, ShopListing listing, int quantity)
		{
			Sched1PatchesBase.SetProperty(typeof(CartEntry), "Cart", __instance, cart);
			Sched1PatchesBase.SetProperty(typeof(CartEntry), "Listing", __instance, listing);
			Sched1PatchesBase.SetProperty(typeof(CartEntry), "Quantity", __instance, quantity);
			Action action = delegate
			{
				Sched1PatchesBase.CallMethod(typeof(CartEntry), "ChangeAmount", __instance, new object[1] { 1 });
			};
			Action action2 = delegate
			{
				Sched1PatchesBase.CallMethod(typeof(CartEntry), "ChangeAmount", __instance, new object[1] { -1 });
			};
			Action action3 = delegate
			{
				Sched1PatchesBase.CallMethod(typeof(CartEntry), "ChangeAmount", __instance, new object[1] { -999999 });
			};
			((UnityEvent)__instance.IncrementButton.onClick).AddListener(Sched1PatchesBase.ToUnityAction(action));
			((UnityEvent)__instance.DecrementButton.onClick).AddListener(Sched1PatchesBase.ToUnityAction(action2));
			((UnityEvent)__instance.RemoveButton.onClick).AddListener(Sched1PatchesBase.ToUnityAction(action3));
			Sched1PatchesBase.CallMethod(typeof(CartEntry), "UpdateTitle", __instance, Array.Empty<object>());
			Sched1PatchesBase.CallMethod(typeof(CartEntry), "UpdatePrice", __instance, Array.Empty<object>());
			return false;
		}

		[HarmonyPatch(typeof(ListingEntry), "Initialize")]
		[HarmonyPrefix]
		public static bool ListingEntryInitializePrefix(ListingEntry __instance, ShopListing match)
		{
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			Sched1PatchesBase.SetProperty(typeof(ListingEntry), "MatchingListing", __instance, match);
			__instance.Icon.sprite = ((ItemDefinition)__instance.MatchingListing.Item).Icon;
			__instance.ItemNameLabel.text = ((ItemDefinition)__instance.MatchingListing.Item).Name;
			__instance.ItemPriceLabel.text = MoneyManager.FormatAmount(__instance.MatchingListing.Price, false, false);
			Action<string> action = delegate(string value)
			{
				Sched1PatchesBase.CallMethod(typeof(ListingEntry), "OnQuantityInputSubmitted", __instance, new object[1] { value });
			};
			Action<string> action2 = delegate
			{
				Sched1PatchesBase.CallMethod(typeof(ListingEntry), "ValidateInput", __instance, Array.Empty<object>());
			};
			Action action3 = delegate
			{
				Sched1PatchesBase.CallMethod(typeof(ListingEntry), "ChangeQuantity", __instance, new object[1] { 1 });
			};
			Action action4 = delegate
			{
				Sched1PatchesBase.CallMethod(typeof(ListingEntry), "ChangeQuantity", __instance, new object[1] { -1 });
			};
			((UnityEvent<string>)(object)__instance.QuantityInput.onSubmit).AddListener(Sched1PatchesBase.ToUnityAction(action));
			((UnityEvent<string>)(object)__instance.QuantityInput.onEndEdit).AddListener(Sched1PatchesBase.ToUnityAction(action2));
			((UnityEvent)__instance.IncrementButton.onClick).AddListener(Sched1PatchesBase.ToUnityAction(action3));
			((UnityEvent)__instance.DecrementButton.onClick).AddListener(Sched1PatchesBase.ToUnityAction(action4));
			__instance.QuantityInput.SetTextWithoutNotify(__instance.SelectedQuantity.ToString());
			__instance.RefreshLocked();
			if (__instance.QuantityInput.characterLimit != 6)
			{
				__instance.QuantityInput.characterLimit = 6;
				__instance.QuantityInput.textComponent.fontSize = 16;
				Sched1PatchesBase.CastTo<RectTransform>((Object)(object)((Component)__instance.QuantityInput).transform).sizeDelta = new Vector2(80f, 40f);
			}
			return false;
		}

		[HarmonyPatch(typeof(ListingEntry), "SetQuantity")]
		[HarmonyPrefix]
		public static bool SetQuantityPrefix(ListingEntry __instance, int quant, bool notify)
		{
			if (!__instance.MatchingListing.Item.IsPurchasable)
			{
				quant = 0;
			}
			Sched1PatchesBase.SetProperty(typeof(ListingEntry), "SelectedQuantity", __instance, Mathf.Clamp(quant, 0, 999999));
			__instance.QuantityInput.SetTextWithoutNotify(__instance.SelectedQuantity.ToString());
			if (notify && __instance.onQuantityChanged != null)
			{
				__instance.onQuantityChanged.Invoke();
			}
			return false;
		}

		[HarmonyPatch(typeof(ListingEntry), "OnQuantityInputSubmitted")]
		[HarmonyPrefix]
		public static bool OnQuantityInputSubmittedPrefix(ListingEntry __instance, string value)
		{
			if (int.TryParse(value, out var result))
			{
				__instance.SetQuantity(result, true);
				return false;
			}
			__instance.SetQuantity(0, true);
			return false;
		}

		[HarmonyPatch(typeof(ListingEntry), "ChangeQuantity")]
		[HarmonyPrefix]
		public static bool ChangeQuantityPrefix(ListingEntry __instance, int change)
		{
			__instance.SetQuantity(__instance.SelectedQuantity + change, true);
			return false;
		}

		[HarmonyPatch(typeof(ListingEntry), "ValidateInput")]
		[HarmonyPrefix]
		public static bool ValidateInputPrefix(ListingEntry __instance)
		{
			Sched1PatchesBase.CallMethod(typeof(ListingEntry), "OnQuantityInputSubmitted", __instance, new object[1] { __instance.QuantityInput.text });
			return false;
		}
	}
}