Decompiled source of StackBaseUnitShop v2.0.0

StackBaseUnitShop.dll

Decompiled a month 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 GameKit.Utilities;
using HarmonyLib;
using MelonLoader;
using Microsoft.CodeAnalysis;
using ScheduleOne.ItemFramework;
using ScheduleOne.UI.Phone.Delivery;
using ScheduleOne.UI.Shop;
using StackBaseUnitShop;
using StackBaseUnitShop.UI;
using StackBaseUnitShop.UI.UI;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[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), "StackBaseUnitShop", "2.0", "ToPin060", null)]
[assembly: MelonColor]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("StackBaseUnitShop")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+297570e94b95e735e3d6348d046e1bb86dbf4a1c")]
[assembly: AssemblyProduct("StackBaseUnitShop")]
[assembly: AssemblyTitle("StackBaseUnitShop")]
[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 StackBaseUnitShop
{
	public static class BuildInfo
	{
		public const string Name = "StackBaseUnitShop";

		public const string Description = "";

		public const string Author = "ToPin060";

		public const string Company = null;

		public const string Version = "2.0";

		public const string DownloadLink = null;
	}
	public class Core : MelonMod
	{
		[HarmonyPatch(typeof(ShopInterface), "Awake")]
		public static class ShopInterface_Awake_Patch
		{
			public static void Postfix(ShopInterface __instance)
			{
				UILogic.AddToogleSLButtonShops(__instance);
			}
		}

		[HarmonyPatch(typeof(DeliveryApp), "Start")]
		public static class DeliveryApp_Start_Patch
		{
			public static void Postfix(DeliveryApp __instance)
			{
				UILogic.AddToogleSLButtonDelivery(__instance);
			}
		}

		[HarmonyPatch(typeof(ShopInterface), "ListingClicked")]
		public static class ShopInterface_ListingClicked_Patch
		{
			public static bool Prefix(ShopInterface __instance, ListingUI listingUI)
			{
				if (listingUI.Listing.Item.IsPurchasable && listingUI.CanAddToCart())
				{
					int num = 1;
					if (__instance.AmountSelector.IsOpen)
					{
						num = __instance.AmountSelector.SelectedAmount;
					}
					else if (StackLimitLogic.UseSL && StackLimitLogic.isConsumableItem((ItemDefinition)(object)listingUI.Listing.Item))
					{
						num = ((ItemDefinition)listingUI.Listing.Item).StackLimit;
					}
					__instance.Cart.AddItem(listingUI.Listing, num);
					__instance.AddItemSound.Play();
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(CartEntry), "Initialize")]
		public static class CartEntry_Initialize_Patch
		{
			public static void Postfix(CartEntry __instance, Cart cart, ShopListing listing, int quantity)
			{
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Expected O, but got Unknown
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0084: Expected O, but got Unknown
				((UnityEventBase)__instance.IncrementButton.onClick).RemoveAllListeners();
				((UnityEventBase)__instance.DecrementButton.onClick).RemoveAllListeners();
				((UnityEvent)__instance.IncrementButton.onClick).AddListener((UnityAction)delegate
				{
					StackLimitLogic.onAddRemCartItem(isAdd: true, __instance, listing);
				});
				((UnityEvent)__instance.DecrementButton.onClick).AddListener((UnityAction)delegate
				{
					StackLimitLogic.onAddRemCartItem(isAdd: false, __instance, listing);
				});
			}
		}

		[HarmonyPatch(typeof(ListingEntry), "Initialize")]
		public static class ListingEntry_Initialize_Patch
		{
			public static void Postfix(ListingEntry __instance, ShopListing match)
			{
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Expected O, but got Unknown
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0084: Expected O, but got Unknown
				((UnityEventBase)__instance.IncrementButton.onClick).RemoveAllListeners();
				((UnityEventBase)__instance.DecrementButton.onClick).RemoveAllListeners();
				((UnityEvent)__instance.IncrementButton.onClick).AddListener((UnityAction)delegate
				{
					StackLimitLogic.onAddRemDeliveryItem(isAdd: true, __instance, (ItemDefinition)(object)match.Item);
				});
				((UnityEvent)__instance.DecrementButton.onClick).AddListener((UnityAction)delegate
				{
					StackLimitLogic.onAddRemDeliveryItem(isAdd: false, __instance, (ItemDefinition)(object)match.Item);
				});
			}
		}

		public override void OnInitializeMelon()
		{
			Melon<Core>.Logger.Msg("Initialized.");
		}
	}
	internal class StackLimitLogic
	{
		public static bool UseSL = true;

		public static void ToogleSLMod(ref Button button)
		{
			UseSL = !UseSL;
			if (UseSL)
			{
				((TMP_Text)((Component)button).GetComponentInChildren<TextMeshProUGUI>()).SetText("SL: On");
			}
			else
			{
				((TMP_Text)((Component)button).GetComponentInChildren<TextMeshProUGUI>()).SetText("SL: Off");
			}
		}

		public static void onAddRemCartItem(bool isAdd, CartEntry __instance, ShopListing listing)
		{
			int num = 1;
			if (UseSL && isConsumableItem((ItemDefinition)(object)__instance.Listing.Item))
			{
				num = ((ItemDefinition)__instance.Listing.Item).StackLimit;
			}
			if (isAdd)
			{
				__instance.Cart.AddItem(__instance.Listing, num);
			}
			else
			{
				__instance.Cart.RemoveItem(__instance.Listing, num);
			}
		}

		public static void onAddRemDeliveryItem(bool isAdd, ListingEntry __instance, ItemDefinition item)
		{
			int num = 1;
			if (UseSL && isConsumableItem(item))
			{
				num = item.StackLimit;
			}
			if (!isAdd)
			{
				num *= -1;
			}
			__instance.SetQuantity(__instance.SelectedQuantity + num, true);
		}

		public static bool isConsumableItem(ItemDefinition item)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Invalid comparison between Unknown and I4
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Invalid comparison between Unknown and I4
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Invalid comparison between Unknown and I4
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			if ((int)item.Category == 1)
			{
				return true;
			}
			if ((int)item.Category == 9)
			{
				return true;
			}
			if ((int)item.Category == 7)
			{
				return true;
			}
			if ((int)item.Category == 2 && !item.Name.Contains("pot") && !item.Name.Equals("Grow Tent"))
			{
				return true;
			}
			if ((int)item.Category == 3 && item.Name.Equals("Trash Bag"))
			{
				return true;
			}
			if ((int)item.Category == 0 && item.Name.Equals("Speed Grow"))
			{
				return true;
			}
			return false;
		}
	}
}
namespace StackBaseUnitShop.UI
{
	public static class UILogic
	{
		public static void AddToogleSLButtonShops(ShopInterface __instance)
		{
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Expected O, but got Unknown
			GameObject gameObject = ((Component)((Component)__instance).gameObject.transform.GetChild(0).GetChild(1)).gameObject;
			GameObject gameObject2 = ((Component)gameObject.transform.GetChild(3).GetChild(0)).gameObject;
			GameObject toogleSL = UIUtils.CreateButtonFromPrefabTM("toogleSL", "SL: On", gameObject2);
			((UnityEventBase)toogleSL.GetComponent<Button>().onClick).RemoveAllListeners();
			Object.Destroy((Object)(object)toogleSL.GetComponent<CategoryButton>());
			toogleSL.transform.SetParent(gameObject.transform);
			toogleSL.transform.localPosition = new Vector3(489f, 17.5f, 0f);
			Transforms.SetScale(toogleSL.transform, new Vector3(1f, 1f, 1f));
			((UnityEvent)toogleSL.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
			{
				Button button = toogleSL.GetComponent<Button>();
				StackLimitLogic.ToogleSLMod(ref button);
			});
		}

		public static void AddToogleSLButtonDelivery(DeliveryApp __instance)
		{
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Expected O, but got Unknown
			GameObject gameObject = ((Component)__instance).gameObject;
			GameObject gameObject2 = ((Component)gameObject.transform.GetChild(0).GetChild(1)).gameObject;
			GameObject gameObject3 = ((Component)gameObject.transform.GetChild(0).GetChild(2).GetChild(0)
				.GetChild(0)
				.GetChild(0)
				.GetChild(1)
				.GetChild(1)
				.GetChild(0)
				.GetChild(4)).gameObject;
			GameObject toogleSL = UIUtils.CreateButtonFromPrefab("toogleSL", "SL: On", gameObject3);
			toogleSL.GetComponentInChildren<Text>().fontSize = 42;
			((RectTransform)((Component)toogleSL.GetComponent<Button>()).transform).SetSizeWithCurrentAnchors((Axis)0, 60f);
			((UnityEventBase)toogleSL.GetComponent<Button>().onClick).RemoveAllListeners();
			toogleSL.transform.SetParent(gameObject2.transform);
			toogleSL.transform.SetLocalPositionAndRotation(new Vector3(543.9365f, -1.2f, 0f), new Quaternion(0f, 0f, 0f, 0f));
			Transforms.SetScale(toogleSL.transform, new Vector3(1f, 1f, 1f));
			((UnityEvent)toogleSL.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
			{
				Button button = toogleSL.GetComponent<Button>();
				StackLimitLogic.ToogleSLMod(ref button);
			});
		}
	}
}
namespace StackBaseUnitShop.UI.UI
{
	public static class UIUtils
	{
		public static GameObject CreateButtonFromPrefab(string name, string text, GameObject prefab, Color? fontColor = null, UnityAction onClick = null)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(prefab);
			((Object)val).name = name + "Button";
			Text componentInChildren = ((Component)val.transform).GetComponentInChildren<Text>();
			componentInChildren.text = text;
			if (fontColor.HasValue)
			{
				((Graphic)componentInChildren).color = fontColor.Value;
			}
			if (onClick != null)
			{
				Button component = val.GetComponent<Button>();
				((UnityEventBase)component.onClick).RemoveAllListeners();
				((UnityEvent)component.onClick).AddListener(onClick);
			}
			return val;
		}

		public static GameObject CreateButtonFromPrefabTM(string name, string text, GameObject prefab, Color? fontColor = null, UnityAction onClick = null)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(prefab);
			((Object)val).name = name + "Button";
			TextMeshProUGUI componentInChildren = ((Component)val.transform).GetComponentInChildren<TextMeshProUGUI>();
			((TMP_Text)componentInChildren).text = text;
			if (fontColor.HasValue)
			{
				((Graphic)componentInChildren).color = fontColor.Value;
			}
			if (onClick != null)
			{
				Button component = val.GetComponent<Button>();
				((UnityEventBase)component.onClick).RemoveAllListeners();
				((UnityEvent)component.onClick).AddListener(onClick);
			}
			return val;
		}
	}
}