Decompiled source of moreThings v1.1.6

moreThings.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Utils;
using Modules;
using Newtonsoft.Json;
using ScheduleOne.DevUtilities;
using ScheduleOne.ItemFramework;
using ScheduleOne.ObjectScripts;
using ScheduleOne.Persistence;
using ScheduleOne.Persistence.Datas;
using ScheduleOne.Storage;
using ScheduleOne.UI.Phone;
using ScheduleOne.UI.Phone.Delivery;
using ScheduleOne.UI.Phone.ProductManagerApp;
using ScheduleOne.UI.Shop;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "moreThings", "1.0.0", "masterxxstabs", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: HarmonyDontPatchAll]
[assembly: AssemblyTitle("moreThings")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("moreThings")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c059bc93-339c-4454-ab3c-16d5fe22eaee")]
[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")]
public class Core : MelonMod
{
	private readonly List<IModModule> modules = new List<IModModule>();

	public override void OnApplicationStart()
	{
		try
		{
			MelonLogger.Msg("Loading More Things Modules...");
			if (ModuleManager.IsModuleEnabled("BackpackMod"))
			{
				modules.Add(new BackpackMod());
			}
			if (ModuleManager.IsModuleEnabled("StackModule"))
			{
				modules.Add(new stackModule());
			}
			if (ModuleManager.IsModuleEnabled("gunRunnersModule"))
			{
				modules.Add(new gunRunnersModule());
			}
			foreach (IModModule module in modules)
			{
				module.OnModInit();
			}
			MelonLogger.Msg($"Loaded {modules.Count} module(s).");
		}
		catch (Exception ex)
		{
			MelonLogger.Error("Error initializing modules: " + ex.Message);
		}
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		foreach (IModModule module in modules)
		{
			try
			{
				module.OnSceneLoaded(buildIndex, sceneName);
			}
			catch (Exception ex)
			{
				MelonLogger.Error("Error in OnSceneWasLoaded for module " + module.GetType().Name + ": " + ex.Message);
			}
		}
	}

	public override void OnUpdate()
	{
		foreach (IModModule module in modules)
		{
			try
			{
				module.OnUpdate();
			}
			catch (Exception ex)
			{
				MelonLogger.Error("Error in OnUpdate for module " + module.GetType().Name + ": " + ex.Message);
			}
		}
		if (Input.GetKeyDown((KeyCode)288))
		{
			ModuleManager.ToggleModule("BackpackMod");
		}
		if (Input.GetKeyDown((KeyCode)289))
		{
			ModuleManager.ToggleModule("StackModule");
		}
	}
}
namespace Modules;

public class gunRunnerUI
{
}
public static class ImageLoader
{
	public static Sprite LoadImage(string fileName)
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Expected O, but got Unknown
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), fileName);
		if (!File.Exists(text))
		{
			MelonLogger.Error("❌ Icon file not found: " + text);
			return null;
		}
		try
		{
			byte[] array = File.ReadAllBytes(text);
			Texture2D val = new Texture2D(2, 2);
			if (ImageConversion.LoadImage(val, array))
			{
				return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			}
			MelonLogger.Error("❌ Failed to decode image bytes.");
		}
		catch (Exception ex)
		{
			MelonLogger.Error("❌ Failed to load sprite: " + ex);
		}
		return null;
	}
}
internal interface IModModule
{
	void OnModInit();

	void OnSceneLoaded(int buildIndex, string sceneName);

	void OnUpdate();
}
public static class ModuleManager
{
	private static readonly string ConfigPath;

	private static Dictionary<string, bool> moduleStates;

	static ModuleManager()
	{
		ConfigPath = Path.Combine(MelonEnvironment.UserDataDirectory, "ModulesConfig.json");
		moduleStates = new Dictionary<string, bool>();
		LoadConfig();
	}

	public static bool IsModuleEnabled(string moduleName)
	{
		if (moduleStates.TryGetValue(moduleName, out var value))
		{
			return value;
		}
		moduleStates[moduleName] = true;
		SaveConfig();
		return true;
	}

	public static void ToggleModule(string moduleName)
	{
		if (moduleStates.ContainsKey(moduleName))
		{
			moduleStates[moduleName] = !moduleStates[moduleName];
		}
		else
		{
			moduleStates[moduleName] = false;
		}
		MelonLogger.Msg("[ModuleManager] Module '" + moduleName + "' is now " + (moduleStates[moduleName] ? "enabled" : "disabled") + ".");
		SaveConfig();
	}

	private static void LoadConfig()
	{
		if (!File.Exists(ConfigPath))
		{
			MelonLogger.Warning("[ModuleManager] Config file not found. Using default states.");
			return;
		}
		try
		{
			moduleStates = JsonConvert.DeserializeObject<Dictionary<string, bool>>(File.ReadAllText(ConfigPath)) ?? new Dictionary<string, bool>();
		}
		catch (Exception ex)
		{
			MelonLogger.Error("[ModuleManager] Failed to load config: " + ex.Message);
		}
	}

	private static void SaveConfig()
	{
		try
		{
			string contents = JsonConvert.SerializeObject((object)moduleStates, (Formatting)1);
			File.WriteAllText(ConfigPath, contents);
		}
		catch (Exception ex)
		{
			MelonLogger.Error("[ModuleManager] Failed to save config: " + ex.Message);
		}
	}
}
public class BackpackMod : IModModule
{
	[HarmonyPatch(typeof(SaveManager), "Save", new Type[] { })]
	public class SaveManagerPatch
	{
		[HarmonyPostfix]
		private static void SavePostfix()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			try
			{
				if ((Object)(object)backpackEntity == (Object)null)
				{
					MelonLogger.Warning("[BackpackMod] Backpack entity is null during save. skipping save");
				}
				ItemSet val = new ItemSet(backpackEntity.ItemSlots);
				File.WriteAllText(SavePath, val.GetJSON());
				MelonLogger.Msg("[BackpackMod] Backpack saved.");
			}
			catch (Exception ex)
			{
				MelonLogger.Error("[BackpackMod] Save error: " + ex);
			}
		}
	}

	private const int ROWS = 4;

	private const int COLUMNS = 3;

	private const KeyCode TOGGLE_KEY = 98;

	public static StorageEntity backpackEntity;

	private bool isInitialized;

	private const KeyCode saveKey = 286;

	private const KeyCode loadKey = 287;

	public static string SavePath => Path.Combine(MelonEnvironment.UserDataDirectory, "BackpackMod.json");

	public void OnModInit()
	{
		MelonLogger.Msg("[BackpackMod] Initialized");
	}

	public void OnSceneLoaded(int buildIndex, string sceneName)
	{
		if (sceneName != "Main")
		{
			if ((Object)(object)backpackEntity != (Object)null)
			{
				((Component)backpackEntity).gameObject.SetActive(false);
			}
			MelonLogger.Msg("[BackpackMod] Scene not gameplay, disabling.");
		}
		else
		{
			MelonCoroutines.Start(SetupBackpack());
		}
	}

	private IEnumerator SetupBackpack()
	{
		yield return (object)new WaitForSeconds(1f);
		try
		{
			StorageEntity[] array = Object.FindObjectsOfType<StorageEntity>();
			if (array == null || array.Length == 0)
			{
				MelonLogger.Error("[BackpackMod] No StorageEntity template found.");
				yield break;
			}
			backpackEntity = Object.Instantiate<StorageEntity>(array[0]);
			((Object)backpackEntity).name = "BackpackStorage";
			backpackEntity.StorageEntityName = "Backpack";
			backpackEntity.SlotCount = 12;
			backpackEntity.DisplayRowCount = 3;
			backpackEntity.MaxAccessDistance = 999f;
			backpackEntity.AccessSettings = (EAccessSettings)2;
			List<ItemSlot> list = new List<ItemSlot>();
			for (int i = 0; i < 12; i++)
			{
				list.Add(new ItemSlot());
			}
			backpackEntity.ItemSlots = list;
			LoadBackpack();
			isInitialized = true;
			MelonLogger.Msg("[BackpackMod] Setup complete.");
		}
		catch (Exception ex)
		{
			MelonLogger.Error("[BackpackMod] Error during setup: " + ex);
		}
	}

	public void OnUpdate()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		Scene activeScene = SceneManager.GetActiveScene();
		if (((Scene)(ref activeScene)).name != "Main" || !isInitialized)
		{
			return;
		}
		if (Input.GetKeyDown((KeyCode)98))
		{
			try
			{
				if (backpackEntity.IsOpened)
				{
					backpackEntity.Close();
				}
				else
				{
					backpackEntity.Open();
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Error("[BackpackMod] Toggle error: " + ex);
			}
		}
		if (Input.GetKeyDown((KeyCode)286))
		{
			SaveBackpack();
		}
		if (Input.GetKeyDown((KeyCode)287))
		{
			LoadBackpack();
		}
	}

	private void SaveBackpack()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		try
		{
			ItemSet val = new ItemSet(backpackEntity.ItemSlots);
			File.WriteAllText(SavePath, val.GetJSON());
			MelonLogger.Msg("[BackpackMod] Backpack saved.");
		}
		catch (Exception ex)
		{
			MelonLogger.Error("[BackpackMod] Save error: " + ex);
		}
	}

	private void LoadBackpack()
	{
		try
		{
			if (!File.Exists(SavePath))
			{
				MelonLogger.Warning("[BackpackMod] No save file found.");
				return;
			}
			string text = File.ReadAllText(SavePath);
			if (string.IsNullOrWhiteSpace(text))
			{
				MelonLogger.Error("[BackpackMod] Save file is empty or invalid.");
				return;
			}
			MelonLogger.Msg("[BackpackMod] Deserializing JSON: " + text);
			ItemInstance[] array = ItemSet.Deserialize(text);
			if (array == null)
			{
				MelonLogger.Error("[BackpackMod] Deserialization returned null.");
				return;
			}
			StorageEntity obj = backpackEntity;
			if (((obj != null) ? obj.ItemSlots : null) == null)
			{
				MelonLogger.Error("[BackpackMod] Backpack entity or item slots not initialized properly.");
				return;
			}
			for (int i = 0; i < array.Length && i < backpackEntity.ItemSlots.Count; i++)
			{
				ItemSlot val = backpackEntity.ItemSlots[i];
				if (val == null)
				{
					MelonLogger.Warning($"[BackpackMod] Item slot {i} is null.");
				}
				else
				{
					val.SetStoredItem(array[i], false);
				}
			}
			MelonLogger.Msg("[BackpackMod] Backpack loaded successfully.");
		}
		catch (Exception ex)
		{
			MelonLogger.Error("[BackpackMod] Load error: " + ex.Message);
		}
	}
}
public class gunRunnersModule : IModModule
{
	private const KeyCode TOGGLE_KEY = 103;

	private const KeyCode saveKey = 293;

	private const KeyCode loadKey = 292;

	private bool isInitialized;

	private GameObject appGO;

	private GameObject _gunRunnersApp;

	public void OnModInit()
	{
		MelonLogger.Msg("[GunRunnersModule] Initialized");
	}

	public void OnSceneLoaded(int buildIndex, string sceneName)
	{
		if (sceneName != "Main")
		{
			if ((Object)(object)appGO != (Object)null)
			{
				appGO.SetActive(false);
			}
			MelonLogger.Msg("[GunRunnersModule] Scene not gameplay, disabling.");
		}
		else
		{
			MelonCoroutines.Start(SetupApp());
		}
	}

	private IEnumerator SetupApp()
	{
		yield return (object)new WaitForSeconds(1f);
		try
		{
			Transform transform = ((Component)PlayerSingleton<AppsCanvas>.Instance.canvas).transform;
			Transform val = transform.Find("ProductManagerApp");
			if ((Object)(object)val == (Object)null)
			{
				MelonLogger.Error("ProductManagerApp template not found.");
				yield break;
			}
			appGO = Object.Instantiate<GameObject>(((Component)val).gameObject, transform);
			((Object)appGO).name = "GunRunnersApp";
			appGO.SetActive(false);
			ProductManagerApp component = appGO.GetComponent<ProductManagerApp>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
			}
			Transform obj = appGO.transform.Find("Container");
			RectTransform val2 = ((obj != null) ? ((Component)obj).GetComponent<RectTransform>() : null);
			if ((Object)(object)val2 != (Object)null)
			{
				foreach (Transform item in (Transform)val2)
				{
					Object.Destroy((Object)(object)((Component)item).gameObject);
				}
			}
			string imagePath = Path.Combine(MelonEnvironment.UserDataDirectory, "rifle_shipment.png");
			CreateAppIcon("GunRunnersIcon", "Gun Runners", imagePath, appGO);
			isInitialized = true;
			MelonLogger.Msg("[GunRunnersModule] Setup complete.");
		}
		catch (Exception ex)
		{
			MelonLogger.Error("[GunRunnersModule] Error during setup: " + ex);
		}
	}

	public void OnUpdate()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		Scene activeScene = SceneManager.GetActiveScene();
		if (((Scene)(ref activeScene)).name != "Main" || !isInitialized)
		{
			return;
		}
		if (Input.GetKeyDown((KeyCode)103))
		{
			try
			{
				if (appGO.activeSelf)
				{
					appGO.SetActive(false);
				}
				else
				{
					appGO.SetActive(true);
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Error("[GunRunnersModule] Toggle error: " + ex);
			}
		}
		if (Input.GetKeyDown((KeyCode)293))
		{
			SaveAppState();
		}
		if (Input.GetKeyDown((KeyCode)292))
		{
			LoadAppState();
		}
	}

	private void CreateAppIcon(string iconName, string labelText, string imagePath, GameObject appGO)
	{
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Expected O, but got Unknown
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Expected O, but got Unknown
		GameObject iconGrid = GameObject.Find("Player_Local/CameraContainer/Camera/OverlayCamera/GameplayMenu/Phone/phone/HomeScreen/AppIcons");
		if ((Object)(object)iconGrid == (Object)null)
		{
			MelonLogger.Error("AppIcons grid not found.");
			return;
		}
		foreach (Transform item in iconGrid.transform)
		{
			Transform val = item;
			if (((Object)val).name == iconName)
			{
				Object.Destroy((Object)(object)((Component)val).gameObject);
			}
		}
		GameObject val2 = Object.Instantiate<GameObject>(((Component)iconGrid.transform.GetChild(6)).gameObject, iconGrid.transform);
		((Object)val2).name = iconName;
		((Component)val2.transform.Find("Label")).GetComponent<Text>().text = labelText;
		Sprite val3 = LoadImage(imagePath);
		if ((Object)(object)val3 != (Object)null)
		{
			((Component)val2.transform.Find("Mask/Image")).GetComponent<Image>().sprite = val3;
		}
		Button component = val2.GetComponent<Button>();
		((UnityEventBase)component.onClick).RemoveAllListeners();
		((UnityEvent)component.onClick).AddListener((UnityAction)delegate
		{
			RemoveDuplicateIcon(labelText, iconGrid);
			appGO.SetActive(true);
			MelonLogger.Msg("Clicked icon: " + labelText + " - " + iconName);
			MelonLogger.Msg("Custom UI panel created and shown.");
			CreateCustomUIPanel(appGO.transform);
		});
		MelonLogger.Msg(iconName + " icon created.");
	}

	public GameObject CreateCustomUIPanel(Transform parent)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		//IL_0047: 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_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Expected O, but got Unknown
		MelonLogger.Msg("Creating custom UI panel...");
		GameObject panel = new GameObject("CustomUIPanel");
		panel.transform.SetParent(parent, false);
		panel.AddComponent<RectTransform>().sizeDelta = new Vector2(400f, 300f);
		panel.AddComponent<CanvasRenderer>();
		((Graphic)panel.AddComponent<Image>()).color = Color.gray;
		GameObject val = new GameObject("TitleText");
		val.transform.SetParent(panel.transform, false);
		RectTransform obj = val.AddComponent<RectTransform>();
		obj.anchoredPosition = new Vector2(0f, 120f);
		obj.sizeDelta = new Vector2(380f, 40f);
		Text obj2 = val.AddComponent<Text>();
		obj2.text = "Custom UI Panel";
		obj2.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
		obj2.fontSize = 24;
		obj2.alignment = (TextAnchor)4;
		((Graphic)obj2).color = Color.black;
		GameObject val2 = new GameObject("CloseButton");
		val2.transform.SetParent(panel.transform, false);
		RectTransform obj3 = val2.AddComponent<RectTransform>();
		obj3.anchoredPosition = new Vector2(0f, -100f);
		obj3.sizeDelta = new Vector2(200f, 50f);
		Button val3 = val2.AddComponent<Button>();
		((Graphic)val2.AddComponent<Image>()).color = Color.white;
		Text obj4 = val2.AddComponent<Text>();
		obj4.text = "Close";
		obj4.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
		obj4.fontSize = 20;
		obj4.alignment = (TextAnchor)4;
		((Graphic)obj4).color = Color.black;
		((UnityEvent)val3.onClick).AddListener((UnityAction)delegate
		{
			panel.SetActive(false);
		});
		MelonLogger.Msg("Custom UI panel created.");
		return panel;
	}

	private void ShowApp(GameObject appGO)
	{
		if ((Object)(object)appGO != (Object)null)
		{
			appGO.SetActive(true);
			appGO.transform.SetAsLastSibling();
		}
		else
		{
			MelonLogger.Error("App GameObject is null.");
		}
	}

	private void RemoveDuplicateIcon(string labelText, GameObject iconGrid)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Expected O, but got Unknown
		foreach (Transform item in iconGrid.transform)
		{
			Transform val = item;
			if (((Object)val).name == "AppIcon(Clone)")
			{
				Transform obj = ((Component)val).transform.Find("Label");
				object obj2;
				if (obj == null)
				{
					obj2 = null;
				}
				else
				{
					Text component = ((Component)obj).GetComponent<Text>();
					obj2 = ((component != null) ? component.text : null);
				}
				if ((string?)obj2 == labelText)
				{
					Object.Destroy((Object)(object)((Component)val).gameObject);
					MelonLogger.Msg("Removed duplicate icon '" + labelText + "'");
					break;
				}
			}
		}
	}

	private Sprite LoadImage(string fileName)
	{
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Expected O, but got Unknown
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), fileName);
		if (!File.Exists(text))
		{
			MelonLogger.Error("Icon file not found: " + text);
			return null;
		}
		try
		{
			byte[] array = File.ReadAllBytes(text);
			if (array == null || array.Length == 0)
			{
				MelonLogger.Error("Failed to load image data.");
				return null;
			}
			Texture2D val = new Texture2D(2, 2);
			if (ImageConversion.LoadImage(val, array))
			{
				return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			}
			MelonLogger.Error("Failed to load image into texture.");
		}
		catch (Exception ex)
		{
			MelonLogger.Error("Failed to load sprite: " + ex);
		}
		return null;
	}

	private void SaveAppState()
	{
		MelonLogger.Msg("[GunRunnersModule] App state saved.");
	}

	private void LoadAppState()
	{
		MelonLogger.Msg("[GunRunnersModule] App state loaded.");
	}
}
internal class stackModule : IModModule
{
	[HarmonyPatch(typeof(MixingStation), "Start")]
	private class MixingStationPatch
	{
		private static void Postfix(MixingStation __instance)
		{
			__instance.MixTimePerItem = 1;
			__instance.MaxMixQuantity = 80;
		}
	}

	[HarmonyPatch(typeof(DryingRack), "Awake")]
	private class DryingRackPatch
	{
		private static void Postfix(DryingRack __instance)
		{
			__instance.ItemCapacity = 80;
		}
	}

	[HarmonyPatch(typeof(ItemInstance), "get_StackLimit")]
	private class ItemInstanceStackLimitPatch
	{
		private static void Postfix(ItemInstance __instance, ref int __result)
		{
			__result = 80;
		}
	}

	[HarmonyPatch(typeof(ShopInterface), "ListingClicked")]
	public static class ShopInterface_ListingClicked_Patch
	{
		public static bool Prefix(ShopInterface __instance, ListingUI listingUI)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			if (listingUI.Listing.Item.IsPurchasable && listingUI.CanAddToCart())
			{
				int num = 1;
				if (__instance.AmountSelector.IsOpen)
				{
					num = __instance.AmountSelector.SelectedAmount;
				}
				else if (isStackableOffset((ItemDefinition)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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			((UnityEventBase)__instance.IncrementButton.onClick).RemoveAllListeners();
			((UnityEventBase)__instance.DecrementButton.onClick).RemoveAllListeners();
			int offset = 1;
			if (isStackableOffset((ItemDefinition)__instance.Listing.Item))
			{
				offset = ((ItemDefinition)__instance.Listing.Item).StackLimit;
			}
			((UnityEvent)__instance.IncrementButton.onClick).AddListener((UnityAction)delegate
			{
				__instance.Cart.AddItem(__instance.Listing, offset);
			});
			((UnityEvent)__instance.DecrementButton.onClick).AddListener((UnityAction)delegate
			{
				__instance.Cart.RemoveItem(__instance.Listing, -offset);
			});
		}
	}

	[HarmonyPatch(typeof(ListingEntry), "Initialize")]
	public static class ListingEntry_Initialize_Patch
	{
		public static void Postfix(ListingEntry __instance, ShopListing match)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			((UnityEventBase)__instance.IncrementButton.onClick).RemoveAllListeners();
			((UnityEventBase)__instance.DecrementButton.onClick).RemoveAllListeners();
			int offset = 1;
			if (isStackableOffset((ItemDefinition)match.Item))
			{
				offset = ((ItemDefinition)match.Item).StackLimit;
			}
			((UnityEvent)__instance.IncrementButton.onClick).AddListener((UnityAction)delegate
			{
				__instance.SetQuantity(__instance.SelectedQuantity + offset, true);
			});
			((UnityEvent)__instance.DecrementButton.onClick).AddListener((UnityAction)delegate
			{
				__instance.SetQuantity(__instance.SelectedQuantity - offset, true);
			});
		}
	}

	private const int DefaultStackSize = 20;

	private const int CustomStackSize = 80;

	public void OnModInit()
	{
		MelonLogger.Msg("[StackModule] Initialized");
	}

	public void OnSceneLoaded(int buildIndex, string sceneName)
	{
		if (sceneName != "Main")
		{
			MelonLogger.Msg("[StackModule] Scene not gameplay, disabling.");
		}
	}

	public void OnUpdate()
	{
	}

	public static bool isStackableOffset(ItemDefinition item)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Invalid comparison between Unknown and I4
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Invalid comparison between Unknown and I4
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Invalid comparison between Unknown and I4
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Invalid comparison between Unknown and I4
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Invalid comparison between Unknown and I4
		//IL_006f: 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;
	}
}