Decompiled source of IMSBigBag v1.0.0

BepInEx/plugins/BigBag.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BigBag.Configuration;
using BigBag.Localization;
using HarmonyLib;
using Il2CppSystem.Collections.Generic;
using UnityEngine;
using UnityEngine.Localization.Settings;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("BigBag")]
[assembly: AssemblyDescription("Big Bag mod for Island Market Simulator by Ice Box Studio")]
[assembly: AssemblyCompany("Ice Box Studio")]
[assembly: AssemblyProduct("BigBag")]
[assembly: AssemblyCopyright("Copyright © 2026 Ice Box Studio All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5DC5CB15-271F-47F8-9755-B2A5A9738743")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BigBag
{
	[BepInPlugin("IceBoxStudio.IslandMarketSimulator.BigBag", "BigBag", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class BigBag : BasePlugin
	{
		public static BigBag _Instance;

		private Harmony _harmony;

		private bool patchesApplied;

		private const string ModConfigManagerApiTypeName = "ModConfigManager.Api.ModConfigManagerAPI";

		private const string ModConfigManagerRegisterMethodName = "RegisterPluginInfo";

		public static BigBag Instance => _Instance;

		internal static ManualLogSource Logger { get; private set; }

		public override void Load()
		{
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			_Instance = this;
			Logger = ((BasePlugin)this).Log;
			bool flag = default(bool);
			try
			{
				Logger.LogInfo((object)"=============================================");
				ManualLogSource logger = Logger;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(1, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("BigBag");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(LocalizationManager.Instance.GetLocalizedText("plugin.initializing"));
				}
				logger.LogInfo(val);
				ManualLogSource logger2 = Logger;
				val = new BepInExInfoLogInterpolatedStringHandler(54, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(LocalizationManager.Instance.GetLocalizedText("plugin.author_prefix"));
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Ice Box Studio(https://steamcommunity.com/id/ibox666/)");
				}
				logger2.LogInfo(val);
				ConfigManager.Initialize(((BasePlugin)this).Config);
				RegisterToModConfigManager();
				ApplyPatches();
				ManualLogSource logger3 = Logger;
				val = new BepInExInfoLogInterpolatedStringHandler(1, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("BigBag");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(LocalizationManager.Instance.GetLocalizedText("plugin.initialized"));
				}
				logger3.LogInfo(val);
				Logger.LogInfo((object)"=============================================");
			}
			catch (Exception ex)
			{
				ManualLogSource logger4 = Logger;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(9, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("BigBag");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" 初始化错误: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("\n");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.StackTrace);
				}
				logger4.LogError(val2);
			}
		}

		private void ApplyPatches()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (!patchesApplied)
			{
				try
				{
					_harmony = new Harmony("IceBoxStudio.IslandMarketSimulator.BigBag");
					_harmony.PatchAll();
					patchesApplied = true;
					return;
				}
				catch (Exception ex)
				{
					ManualLogSource logger = Logger;
					bool flag = default(bool);
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(10, 3, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("BigBag");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" 应用补丁错误: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\n");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.StackTrace);
					}
					logger.LogError(val);
					return;
				}
			}
			Logger.LogInfo((object)LocalizationManager.Instance.GetLocalizedText("plugin.patches_skipped"));
		}

		private void RegisterToModConfigManager()
		{
			Type type = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly assembly) => assembly.GetType("ModConfigManager.Api.ModConfigManagerAPI") != null)?.GetType("ModConfigManager.Api.ModConfigManagerAPI");
			if (!(type == null))
			{
				MethodInfo method = type.GetMethod("RegisterPluginInfo", BindingFlags.Static | BindingFlags.Public);
				if (!(method == null))
				{
					method.Invoke(null, new object[5]
					{
						"IceBoxStudio.IslandMarketSimulator.BigBag",
						LocalizationManager.Instance.GetLocalizedText("plugin.name"),
						"1.0.0",
						"Ice Box Studio",
						LocalizationManager.Instance.GetLocalizedText("plugin.description")
					});
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "IceBoxStudio.IslandMarketSimulator.BigBag";

		public const string PLUGIN_NAME = "BigBag";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace BigBag.Patches
{
	internal static class HeldItemPanelsPatch
	{
		private const int RaiseThreshold = 8;

		private static ItemManager _cachedManager = null;

		private static RectTransform _cachedHeldPanelRect = null;

		private static Vector2 _cachedHeldPanelBasePos = Vector2.zero;

		private static RectTransform _cachedEventPanelRect = null;

		private static Vector2 _cachedEventPanelBasePos = Vector2.zero;

		internal static void Apply(ItemManager itemManager)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)itemManager == (Object)null)
			{
				return;
			}
			if (itemManager.availableSlots <= 8)
			{
				RestoreBasePositions(itemManager);
				return;
			}
			EnsureCache(itemManager);
			float num = Mathf.Abs(itemManager.indicatorMoveValue);
			if (num < 1f)
			{
				num = 125f;
			}
			int num2 = CalculateBagRows(itemManager);
			float num3 = num * (float)num2;
			if ((Object)(object)_cachedHeldPanelRect != (Object)null)
			{
				_cachedHeldPanelRect.anchoredPosition = _cachedHeldPanelBasePos + new Vector2(0f, num3);
			}
			if ((Object)(object)_cachedEventPanelRect != (Object)null)
			{
				_cachedEventPanelRect.anchoredPosition = _cachedEventPanelBasePos + new Vector2(0f, num3);
			}
		}

		private static void RestoreBasePositions(ItemManager itemManager)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_cachedManager != (Object)(object)itemManager))
			{
				if ((Object)(object)_cachedHeldPanelRect != (Object)null)
				{
					_cachedHeldPanelRect.anchoredPosition = _cachedHeldPanelBasePos;
				}
				if ((Object)(object)_cachedEventPanelRect != (Object)null)
				{
					_cachedEventPanelRect.anchoredPosition = _cachedEventPanelBasePos;
				}
			}
		}

		private static void EnsureCache(ItemManager itemManager)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_cachedManager == (Object)(object)itemManager && (Object)(object)_cachedHeldPanelRect != (Object)null && (Object)(object)_cachedEventPanelRect != (Object)null)
			{
				return;
			}
			Transform val = FindCanvasRoot(itemManager);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			_cachedManager = itemManager;
			Transform val2 = FindChildByPrefix(val, "HeldItemPanels");
			if ((Object)(object)val2 != (Object)null)
			{
				RectTransform component = ((Component)val2).GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					_cachedHeldPanelRect = component;
					_cachedHeldPanelBasePos = component.anchoredPosition;
				}
			}
			Transform val3 = FindChildByPrefix(val, "ActiveEventPanel");
			if ((Object)(object)val3 != (Object)null)
			{
				RectTransform component2 = ((Component)val3).GetComponent<RectTransform>();
				if ((Object)(object)component2 != (Object)null)
				{
					_cachedEventPanelRect = component2;
					_cachedEventPanelBasePos = component2.anchoredPosition;
				}
			}
		}

		private static Transform FindCanvasRoot(ItemManager itemManager)
		{
			Transform val = null;
			if (itemManager.bagSlotImages != null && itemManager.bagSlotImages.Count > 0 && (Object)(object)itemManager.bagSlotImages[0] != (Object)null)
			{
				val = itemManager.bagSlotImages[0].transform;
			}
			else if ((Object)(object)itemManager.itemIndicatorImage != (Object)null)
			{
				val = ((Component)itemManager.itemIndicatorImage).transform;
			}
			else if ((Object)(object)itemManager.baseItemImage != (Object)null)
			{
				val = ((Component)itemManager.baseItemImage).transform;
			}
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Transform val2 = val;
			while ((Object)(object)val2 != (Object)null)
			{
				if ((Object)(object)((Component)val2).GetComponent<Canvas>() != (Object)null)
				{
					return val2;
				}
				val2 = val2.parent;
			}
			val2 = val;
			while ((Object)(object)val2.parent != (Object)null)
			{
				val2 = val2.parent;
			}
			return val2;
		}

		private static Transform FindChildByPrefix(Transform parent, string prefix)
		{
			for (int i = 0; i < parent.childCount; i++)
			{
				Transform child = parent.GetChild(i);
				if ((Object)(object)child != (Object)null && !string.IsNullOrEmpty(((Object)child).name) && ((Object)child).name.StartsWith(prefix))
				{
					return child;
				}
			}
			return null;
		}

		private static int CalculateBagRows(ItemManager itemManager)
		{
			int num = Mathf.Max(0, itemManager.availableSlots - 1);
			int valueOrDefault = (ConfigManager.Instance?.SlotsPerRow?.Value).GetValueOrDefault(5);
			valueOrDefault = Mathf.Max(2, valueOrDefault);
			int num2 = valueOrDefault - 1;
			if (num <= num2)
			{
				return 1;
			}
			int num3 = Mathf.CeilToInt((float)(num - num2) / (float)valueOrDefault);
			return 1 + Mathf.Max(0, num3);
		}
	}
	[HarmonyPatch(typeof(ItemManager), "InitItemManager")]
	internal static class HeldItemPanelsInitPatch
	{
		[HarmonyPostfix]
		private static void Postfix(ItemManager __instance)
		{
			HeldItemPanelsPatch.Apply(__instance);
		}
	}
	[HarmonyPatch(typeof(ItemManager), "HandleBagSlots")]
	internal static class HeldItemPanelsHandleBagSlotsPatch
	{
		[HarmonyPostfix]
		private static void Postfix(ItemManager __instance)
		{
			HeldItemPanelsPatch.Apply(__instance);
		}
	}
	[HarmonyPatch(typeof(ItemManager), "SwitchSlot")]
	internal static class HeldItemPanelsSwitchSlotPatch
	{
		[HarmonyPostfix]
		private static void Postfix(ItemManager __instance)
		{
			HeldItemPanelsPatch.Apply(__instance);
		}
	}
	[HarmonyPatch(typeof(ItemManager), "Update")]
	internal static class HeldItemPanelsUpdatePatch
	{
		[HarmonyPostfix]
		private static void Postfix(ItemManager __instance)
		{
			HeldItemPanelsPatch.Apply(__instance);
		}
	}
	internal static class BagPatch
	{
		private static ItemManager _indMgr;

		private static float _indBaseY;

		private static ItemManager _colorMgr;

		private static Color _indBaseColor;

		internal static int ResolveCapacity(int orig)
		{
			ConfigManager instance = ConfigManager.Instance;
			if (instance == null)
			{
				return orig;
			}
			int value;
			switch (orig)
			{
			case 3:
				value = instance.SmallBagCapacity.Value;
				break;
			case 4:
				value = instance.MediumBagCapacity.Value;
				break;
			case 5:
				value = instance.LargeBagCapacity.Value;
				break;
			default:
				return orig;
			}
			return Mathf.Max(0, value - 1);
		}

		internal static void EnsureSlots(ItemManager mgr, int count)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: 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_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)mgr == (Object)null || mgr.bagSlotImages == null || count <= 0 || mgr.bagSlotImages.Count == 0)
			{
				return;
			}
			GameObject val = mgr.bagSlotImages[0];
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Transform parent = val.transform.parent;
			RectTransform component = val.GetComponent<RectTransform>();
			Vector2 spacing = GetSpacing(mgr, mgr.indicatorMoveValue);
			if ((Object)(object)component != (Object)null)
			{
				for (int i = 1; i < mgr.bagSlotImages.Count; i++)
				{
					GameObject val2 = mgr.bagSlotImages[i];
					if (!((Object)(object)val2 == (Object)null))
					{
						RectTransform component2 = val2.GetComponent<RectTransform>();
						if ((Object)(object)component2 != (Object)null)
						{
							component2.anchoredPosition = component.anchoredPosition + SlotOffset(i, spacing);
						}
					}
				}
			}
			for (int j = mgr.bagSlotImages.Count; j < count; j++)
			{
				GameObject val3 = Object.Instantiate<GameObject>(val, parent);
				((Object)val3).name = "BagSlot_Expanded_" + j;
				val3.SetActive(false);
				mgr.bagSlotImages.Add(val3);
				RectTransform component3 = val3.GetComponent<RectTransform>();
				if ((Object)(object)component3 != (Object)null && (Object)(object)component != (Object)null)
				{
					component3.anchoredPosition = component.anchoredPosition + SlotOffset(j, spacing);
					component3.anchorMin = component.anchorMin;
					component3.anchorMax = component.anchorMax;
					component3.pivot = component.pivot;
					component3.sizeDelta = component.sizeDelta;
					((Transform)component3).localScale = ((Transform)component).localScale;
				}
			}
		}

		internal static void ResizeBagData(ItemManager mgr, int targetCount)
		{
			if (!((Object)(object)mgr == (Object)null))
			{
				if (targetCount < 0)
				{
					targetCount = 0;
				}
				List<GameObject> val = mgr.bagSlots ?? new List<GameObject>();
				List<GameObject> val2 = new List<GameObject>(targetCount);
				for (int i = 0; i < targetCount; i++)
				{
					val2.Add((i < val.Count) ? val[i] : null);
				}
				mgr.bagSlots = val2;
				mgr.availableSlots = targetCount + 1;
				if (mgr.currentSlotIndex >= mgr.availableSlots)
				{
					mgr.currentSlotIndex = mgr.availableSlots - 1;
				}
				if (mgr.currentSlotIndex < 0)
				{
					mgr.currentSlotIndex = 0;
				}
			}
		}

		internal static void RefreshSlots(ItemManager mgr, int activeCount)
		{
			if ((Object)(object)mgr == (Object)null || mgr.bagSlotImages == null)
			{
				return;
			}
			for (int i = 0; i < mgr.bagSlotImages.Count; i++)
			{
				GameObject val = mgr.bagSlotImages[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				bool flag = i < activeCount;
				val.SetActive(flag);
				Image component = val.GetComponent<Image>();
				if (!((Object)(object)component == (Object)null))
				{
					if (!flag)
					{
						component.sprite = mgr.defaultSprite;
						continue;
					}
					GameObject val2 = ((i < mgr.bagSlots.Count) ? mgr.bagSlots[i] : null);
					BaseItem val3 = (((Object)(object)val2 != (Object)null) ? val2.GetComponent<BaseItem>() : null);
					component.sprite = (((Object)(object)val3 != (Object)null && (Object)(object)val3.itemData != (Object)null) ? val3.itemData.iconSprite : mgr.defaultSprite);
				}
			}
		}

		internal static void SyncHeldItem(ItemManager mgr)
		{
			if (!((Object)(object)mgr == (Object)null))
			{
				if (mgr.currentSlotIndex == 0)
				{
					mgr.heldItem = mgr.baseSlotItem;
					return;
				}
				int num = mgr.currentSlotIndex - 1;
				mgr.heldItem = ((num >= 0 && num < mgr.bagSlots.Count) ? mgr.bagSlots[num] : null);
			}
		}

		internal static void RefreshIndicator(ItemManager mgr)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)mgr == (Object)null) && !((Object)(object)mgr.itemIndicatorImage == (Object)null))
			{
				ApplyColor(mgr);
				RectTransform rectTransform = ((Graphic)mgr.itemIndicatorImage).rectTransform;
				if ((Object)(object)_indMgr != (Object)(object)mgr)
				{
					_indBaseY = rectTransform.anchoredPosition.y;
					_indMgr = mgr;
				}
				if (mgr.currentSlotIndex == 0)
				{
					rectTransform.anchoredPosition = new Vector2(mgr.indicatorStartXValue, _indBaseY);
					return;
				}
				(int row, int col) tuple = SlotRowCol(mgr.currentSlotIndex - 1);
				int item = tuple.row;
				int item2 = tuple.col;
				float num = mgr.indicatorMoveValue * (float)(item2 + ((item == 0) ? 1 : 0)) + mgr.indicatorStartXValue;
				float num2 = _indBaseY + Mathf.Abs(mgr.indicatorMoveValue) * (float)item;
				rectTransform.anchoredPosition = new Vector2(num, num2);
			}
		}

		internal static void ApplyColor(ItemManager mgr)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)mgr == (Object)null) && !((Object)(object)mgr.itemIndicatorImage == (Object)null))
			{
				if ((Object)(object)_colorMgr != (Object)(object)mgr)
				{
					_indBaseColor = ((Graphic)mgr.itemIndicatorImage).color;
					_colorMgr = mgr;
				}
				string text = ConfigManager.Instance?.BagHighlightColor?.Value;
				if (string.IsNullOrWhiteSpace(text))
				{
					((Graphic)mgr.itemIndicatorImage).color = _indBaseColor;
				}
				else
				{
					Color val = default(Color);
					((Graphic)mgr.itemIndicatorImage).color = (ColorUtility.TryParseHtmlString(text, ref val) ? val : _indBaseColor);
				}
			}
		}

		private static (int row, int col) SlotRowCol(int bagSlotIndex)
		{
			int num = Mathf.Max(2, (ConfigManager.Instance?.SlotsPerRow?.Value).GetValueOrDefault(5));
			int num2 = num - 1;
			if (bagSlotIndex < num2)
			{
				return (0, bagSlotIndex);
			}
			int num3 = bagSlotIndex - num2;
			return (num3 / num + 1, num3 % num);
		}

		internal static Vector2 SlotOffset(int slotIndex, Vector2 spacing)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			(int row, int col) tuple = SlotRowCol(slotIndex);
			int item = tuple.row;
			int item2 = tuple.col;
			float num = spacing.x * (float)item2;
			if (item > 0)
			{
				num -= spacing.x;
			}
			return new Vector2(num, spacing.y * (float)item);
		}

		private static Vector2 GetSpacing(ItemManager mgr, float fallbackX)
		{
			//IL_00a7: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			float num = fallbackX;
			if ((Object)(object)mgr != (Object)null && mgr.bagSlotImages != null && mgr.bagSlotImages.Count > 1)
			{
				GameObject val = mgr.bagSlotImages[0];
				GameObject val2 = mgr.bagSlotImages[1];
				if ((Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null)
				{
					RectTransform component = val.GetComponent<RectTransform>();
					RectTransform component2 = val2.GetComponent<RectTransform>();
					if ((Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null)
					{
						float num2 = component2.anchoredPosition.x - component.anchoredPosition.x;
						if (Mathf.Abs(num2) > 0.01f)
						{
							num = num2;
						}
					}
				}
			}
			return new Vector2(num, Mathf.Abs(num));
		}
	}
	[HarmonyPatch(typeof(ItemManager), "InitItemManager")]
	internal static class ItemManagerInitPatch
	{
		[HarmonyPostfix]
		private static void Postfix(ItemManager __instance)
		{
			BagPatch.RefreshIndicator(__instance);
		}
	}
	[HarmonyPatch(typeof(ItemManager), "HandleBagSlots")]
	internal static class ItemManagerHandleBagSlotsPatch
	{
		[HarmonyPrefix]
		private static void Prefix(ItemManager __instance, ref int count)
		{
			count = BagPatch.ResolveCapacity(count);
			BagPatch.EnsureSlots(__instance, count);
		}
	}
	[HarmonyPatch(typeof(TestSave), "LoadItemManager")]
	internal static class TestSaveLoadItemManagerPatch
	{
		[HarmonyPostfix]
		private static void Postfix(TestSave __instance)
		{
			GameObject val = ((__instance != null) ? __instance.player : null);
			if (!((Object)(object)val == (Object)null))
			{
				PlayerSaveHelper component = val.GetComponent<PlayerSaveHelper>();
				ItemManager val2 = (((Object)(object)component != (Object)null) ? component.itemManager : null);
				if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.currentBag == (Object)null))
				{
					int num = BagPatch.ResolveCapacity(val2.currentBag.slotCapacity);
					BagPatch.EnsureSlots(val2, num);
					BagPatch.ResizeBagData(val2, num);
					BagPatch.RefreshSlots(val2, num);
					BagPatch.SyncHeldItem(val2);
					BagPatch.RefreshIndicator(val2);
				}
			}
		}
	}
	[HarmonyPatch(typeof(ItemManager), "SwitchSlot")]
	internal static class ItemManagerSwitchSlotPatch
	{
		[HarmonyPostfix]
		private static void Postfix(ItemManager __instance)
		{
			BagPatch.RefreshIndicator(__instance);
		}
	}
	[HarmonyPatch(typeof(ItemManager), "Update")]
	internal static class ItemManagerUpdatePatch
	{
		[HarmonyPostfix]
		private static void Postfix(ItemManager __instance)
		{
			BagPatch.ApplyColor(__instance);
		}
	}
}
namespace BigBag.Localization
{
	public static class LocalizationHelper
	{
		public static Dictionary<string, string> GetDefaultTranslations(string language)
		{
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			switch (language)
			{
			case "zh":
				dictionary.Add("plugin.initializing", "开始初始化...");
				dictionary.Add("plugin.author_prefix", "作者:");
				dictionary.Add("plugin.initialized", "初始化成功!");
				dictionary.Add("plugin.patches_skipped", "补丁已应用,跳过...");
				dictionary.Add("plugin.name", "大背包");
				dictionary.Add("plugin.description", "增加三种背包的背包容量并支持调整选择框颜色。");
				dictionary.Add("config.small_bag_capacity", "小型背包增加的格子数量\n24格为一行");
				dictionary.Add("config.medium_bag_capacity", "中型背包增加的格子数量\n24格为一行");
				dictionary.Add("config.large_bag_capacity", "大型背包增加的格子数量\n24格为一行");
				dictionary.Add("config.slots_per_row", "每行最大槽位数量\n24格为一行");
				dictionary.Add("config.bag_highlight_color", "背包高亮框颜色(留空使用游戏默认颜色,支持 #RRGGBB 或 #RRGGBBAA)");
				break;
			case "zh-TW":
				dictionary.Add("plugin.initializing", "開始初始化...");
				dictionary.Add("plugin.author_prefix", "作者:");
				dictionary.Add("plugin.initialized", "初始化成功!");
				dictionary.Add("plugin.patches_skipped", "補丁已套用,跳過...");
				dictionary.Add("plugin.name", "大背包");
				dictionary.Add("plugin.description", "增加三種背包的背包容量並支援調整選擇框顏色。");
				dictionary.Add("config.small_bag_capacity", "小型背包增加的格子數量\n24格為一行");
				dictionary.Add("config.medium_bag_capacity", "中型背包增加的格子數量\n24格為一行");
				dictionary.Add("config.large_bag_capacity", "大型背包增加的格子數量\n24格為一行");
				dictionary.Add("config.slots_per_row", "每行最大槽位數量\n24格為一行");
				dictionary.Add("config.bag_highlight_color", "背包高亮框顏色(留空使用遊戲預設顏色,支援 #RRGGBB 或 #RRGGBBAA)");
				break;
			case "en":
				dictionary.Add("plugin.initializing", "Initializing...");
				dictionary.Add("plugin.author_prefix", "Author: ");
				dictionary.Add("plugin.initialized", "Initialized successfully!");
				dictionary.Add("plugin.patches_skipped", "Patches already applied, skipping...");
				dictionary.Add("plugin.name", "Big Bag");
				dictionary.Add("plugin.description", "Increases the capacity of three bag types and supports adjusting the selection frame color.");
				dictionary.Add("config.small_bag_capacity", "Slots added by Small Bag\n24 slots per row");
				dictionary.Add("config.medium_bag_capacity", "Slots added by Medium Bag\n24 slots per row");
				dictionary.Add("config.large_bag_capacity", "Slots added by Large Bag\n24 slots per row");
				dictionary.Add("config.slots_per_row", "Max slots per row\n24 slots per row");
				dictionary.Add("config.bag_highlight_color", "Bag highlight color (leave empty to use the game default, supports #RRGGBB or #RRGGBBAA)");
				break;
			case "ja":
				dictionary.Add("plugin.initializing", "初期化中...");
				dictionary.Add("plugin.author_prefix", "作者: ");
				dictionary.Add("plugin.initialized", "初期化に成功しました!");
				dictionary.Add("plugin.patches_skipped", "パッチは適用済みです。スキップします...");
				dictionary.Add("plugin.name", "ビッグバッグ");
				dictionary.Add("plugin.description", "3種類のバッグ容量を増やし、選択枠の色も調整できます。");
				dictionary.Add("config.small_bag_capacity", "小型バッグで増えるスロット数\n24スロットで1行");
				dictionary.Add("config.medium_bag_capacity", "中型バッグで増えるスロット数\n24スロットで1行");
				dictionary.Add("config.large_bag_capacity", "大型バッグで増えるスロット数\n24スロットで1行");
				dictionary.Add("config.slots_per_row", "1行あたりの最大スロット数\n24スロットで1行");
				dictionary.Add("config.bag_highlight_color", "バッグのハイライト枠色(空欄でゲーム既定色、#RRGGBB または #RRGGBBAA 対応)");
				break;
			}
			return dictionary;
		}
	}
	public class LocalizationManager
	{
		private static LocalizationManager _instance;

		private readonly Dictionary<string, Dictionary<string, string>> _localizations = new Dictionary<string, Dictionary<string, string>>();

		private string _currentLocale = "zh";

		public static readonly string[] SupportedLanguages = new string[16]
		{
			"en", "tr", "fr", "es", "zh", "zh-TW", "de", "el", "pt-BR", "it",
			"ja", "pl", "pt-PT", "ru", "ko", "th"
		};

		public static LocalizationManager Instance => _instance ?? (_instance = new LocalizationManager());

		private LocalizationManager()
		{
			Initialize();
		}

		public void Initialize()
		{
			RefreshCurrentLocale();
			string[] supportedLanguages = SupportedLanguages;
			foreach (string text in supportedLanguages)
			{
				Dictionary<string, string> defaultTranslations = LocalizationHelper.GetDefaultTranslations(text);
				if (defaultTranslations != null && defaultTranslations.Count > 0)
				{
					_localizations[text] = defaultTranslations;
				}
			}
		}

		private void RefreshCurrentLocale()
		{
			if (PlayerPrefs.HasKey("Lang"))
			{
				int @int = PlayerPrefs.GetInt("Lang");
				ILocalesProvider availableLocales = LocalizationSettings.AvailableLocales;
				if (availableLocales != null && availableLocales.Locales != null && @int >= 0 && @int < availableLocales.Locales.Count)
				{
					string code = availableLocales.Locales[@int].Identifier.Code;
					_currentLocale = (_localizations.ContainsKey(code) ? code : "en");
				}
			}
		}

		public string GetLocalizedText(string key, params object[] args)
		{
			RefreshCurrentLocale();
			if (string.IsNullOrEmpty(_currentLocale) || !_localizations.ContainsKey(_currentLocale))
			{
				_currentLocale = "en";
			}
			if (_localizations.ContainsKey(_currentLocale) && _localizations[_currentLocale].TryGetValue(key, out var value))
			{
				if (args.Length == 0)
				{
					return value;
				}
				return string.Format(value, args);
			}
			if (_currentLocale != "en" && _localizations.ContainsKey("en") && _localizations["en"].TryGetValue(key, out var value2))
			{
				if (args.Length == 0)
				{
					return value2;
				}
				return string.Format(value2, args);
			}
			if (_localizations.ContainsKey("zh") && _localizations["zh"].TryGetValue(key, out var value3))
			{
				if (args.Length == 0)
				{
					return value3;
				}
				return string.Format(value3, args);
			}
			return key;
		}
	}
}
namespace BigBag.Configuration
{
	public class ConfigManager
	{
		private static ConfigManager _instance;

		private readonly ConfigFile _configFile;

		private readonly Dictionary<string, ConfigEntry<bool>> _boolConfigs = new Dictionary<string, ConfigEntry<bool>>();

		private readonly Dictionary<string, ConfigEntry<string>> _stringConfigs = new Dictionary<string, ConfigEntry<string>>();

		private readonly Dictionary<string, ConfigEntry<int>> _intConfigs = new Dictionary<string, ConfigEntry<int>>();

		private readonly Dictionary<string, ConfigEntry<float>> _floatConfigs = new Dictionary<string, ConfigEntry<float>>();

		private readonly Dictionary<string, ConfigEntry<KeyCode>> _keyCodeConfigs = new Dictionary<string, ConfigEntry<KeyCode>>();

		public static ConfigManager Instance => _instance;

		public ConfigEntry<int> SmallBagCapacity { get; private set; }

		public ConfigEntry<int> MediumBagCapacity { get; private set; }

		public ConfigEntry<int> LargeBagCapacity { get; private set; }

		public ConfigEntry<int> SlotsPerRow { get; private set; }

		public ConfigEntry<string> BagHighlightColor { get; private set; }

		private ConfigManager(ConfigFile configFile)
		{
			_configFile = configFile;
			InitializeDefaultConfigs();
		}

		public static void Initialize(ConfigFile configFile)
		{
			if (_instance == null)
			{
				_instance = new ConfigManager(configFile);
			}
		}

		private void InitializeDefaultConfigs()
		{
			SmallBagCapacity = RegisterIntMax("背包扩容 - Bag Capacity", "SmallBagCapacity", GetLocalizedDescription("config.small_bag_capacity"), 4, 1, 240);
			MediumBagCapacity = RegisterIntMax("背包扩容 - Bag Capacity", "MediumBagCapacity", GetLocalizedDescription("config.medium_bag_capacity"), 5, 1, 240);
			LargeBagCapacity = RegisterIntMax("背包扩容 - Bag Capacity", "LargeBagCapacity", GetLocalizedDescription("config.large_bag_capacity"), 6, 1, 240);
			SlotsPerRow = RegisterIntMax("背包扩容 - Bag Capacity", "SlotsPerRow", GetLocalizedDescription("config.slots_per_row"), 24, 1, 24);
			BagHighlightColor = RegisterString("背包高亮 - Bag Highlight", "BagHighlightColor", GetLocalizedDescription("config.bag_highlight_color"), "");
		}

		private string GetLocalizedDescription(string key)
		{
			return LocalizationManager.Instance?.GetLocalizedText(key) ?? key;
		}

		public ConfigEntry<bool> RegisterBool(string section, string key, string description, bool defaultValue)
		{
			ConfigEntry<bool> val = _configFile.Bind<bool>(section, key, defaultValue, description);
			_boolConfigs[key] = val;
			return val;
		}

		public ConfigEntry<string> RegisterString(string section, string key, string description, string defaultValue)
		{
			ConfigEntry<string> val = _configFile.Bind<string>(section, key, defaultValue, description);
			_stringConfigs[key] = val;
			return val;
		}

		public ConfigEntry<KeyCode> RegisterKeyCode(string section, string key, string description, KeyCode defaultValue)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			ConfigEntry<KeyCode> val = _configFile.Bind<KeyCode>(section, key, defaultValue, description);
			_keyCodeConfigs[key] = val;
			return val;
		}

		public ConfigEntry<int> RegisterInt(string section, string key, string description, int defaultValue)
		{
			ConfigEntry<int> val = _configFile.Bind<int>(section, key, defaultValue, description);
			_intConfigs[key] = val;
			return val;
		}

		public ConfigEntry<int> RegisterIntMax(string section, string key, string description, int defaultValue, int minValue, int maxValue)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			ConfigEntry<int> val = _configFile.Bind<int>(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<int>(minValue, maxValue), Array.Empty<object>()));
			_intConfigs[key] = val;
			return val;
		}

		public ConfigEntry<float> RegisterFloat(string section, string key, string description, float defaultValue)
		{
			ConfigEntry<float> val = _configFile.Bind<float>(section, key, defaultValue, description);
			_floatConfigs[key] = val;
			return val;
		}

		public ConfigEntry<float> RegisterFloatMax(string section, string key, string description, float defaultValue, float minValue, float maxValue)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			ConfigEntry<float> val = _configFile.Bind<float>(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<float>(minValue, maxValue), Array.Empty<object>()));
			_floatConfigs[key] = val;
			return val;
		}
	}
}