Decompiled source of ShopPlus v1.0.2

Zichen-ShopPlus-1.0.2.dll

Decompiled 2 weeks 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.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("Zichen-ShopPlus-1.0.2")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+70d29b0e67f7649c9f24c1882424d330cbb8303a")]
[assembly: AssemblyProduct("Zichen-ShopPlus-1.0.2")]
[assembly: AssemblyTitle("Zichen-ShopPlus-1.0.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[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;
		}
	}
}
[BepInPlugin("zichen.shopplus", "ShopPlus", "1.0.2")]
public class ShopPlusPlugin : BaseUnityPlugin
{
	[Serializable]
	private sealed class DebugShelfPlacementRecord
	{
		public string shopKey;

		public string levelName;

		public string narrativeName;

		public string sceneName;

		public string resourcePath;

		public string prefabName;

		public string lastAction;

		public string anchorName;

		public Vector3 anchorPosition;

		public Vector3 position;

		public Vector3 scale = Vector3.one;

		public float yaw;

		public string savedAtUtc;
	}

	private struct GroundPackLayout
	{
		public int PackCount;

		public int SlotsPerSet;

		public int RowsPerSet;

		public int TotalRows;

		public float FloorHeight;

		public float SpacingX;

		public float SpacingZ;

		public Vector3 GridCenter;

		public Vector3[] PackCenters;

		public Vector3 ExtractionPosition;

		public Vector3 SpawnReferencePosition;

		public Bounds ShopBounds;
	}

	private struct GroundPackSpawnSlot
	{
		public itemVolume VolumeType;

		public Vector3 Position;

		public Quaternion Rotation;
	}

	private struct GroundPackCategoryGroup
	{
		public itemVolume VolumeType;

		public int ItemCount;
	}

	private struct GroundPackPlacement
	{
		public itemVolume VolumeType;

		public int ItemCount;

		public Vector3 Center;

		public int Columns;

		public int Rows;

		public float SpacingX;

		public float SpacingZ;

		public float HalfWidth;

		public float HalfDepth;
	}

	private struct ShopItemLimitState
	{
		public int MaxAmountInShop;

		public int MaxAmount;

		public bool MaxPurchase;

		public int MaxPurchaseAmount;
	}

	[CompilerGenerated]
	private sealed class <AssignRandomFreeItemWhenReady>d__356 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public ShopPlusPlugin <>4__this;

		private int <attempt>5__2;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <AssignRandomFreeItemWhenReady>d__356(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			int num = <>1__state;
			ShopPlusPlugin shopPlusPlugin = <>4__this;
			switch (num)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<attempt>5__2 = 0;
				break;
			case 1:
				<>1__state = -1;
				<attempt>5__2++;
				break;
			}
			if (<attempt>5__2 < 15)
			{
				if (!shopPlusPlugin.IsRandomFreeItemRuntimeEnabled() || !SemiFunc.RunIsShop())
				{
					shopPlusPlugin.freeItemSelectionCoroutine = null;
					return false;
				}
				if (shopPlusPlugin.TryAssignRandomFreeItem())
				{
					shopPlusPlugin.freeItemSelectionCoroutine = null;
					return false;
				}
				<>2__current = FreeItemRetryDelay;
				<>1__state = 1;
				return true;
			}
			shopPlusPlugin.freeItemSelectionCoroutine = null;
			return false;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <AssignSyncedFreeItemWhenReady>d__357 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public ShopPlusPlugin <>4__this;

		public int photonViewId;

		public bool nativeScaleApplied;

		private int <attempt>5__2;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <AssignSyncedFreeItemWhenReady>d__357(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			int num = <>1__state;
			ShopPlusPlugin shopPlusPlugin = <>4__this;
			switch (num)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<attempt>5__2 = 0;
				break;
			case 1:
				<>1__state = -1;
				<attempt>5__2++;
				break;
			}
			if (<attempt>5__2 < 15)
			{
				if (!shopPlusPlugin.IsRandomFreeItemRuntimeEnabled() || !SemiFunc.RunIsShop())
				{
					shopPlusPlugin.freeItemSelectionCoroutine = null;
					return false;
				}
				if (shopPlusPlugin.TryAssignSyncedFreeItem(photonViewId, nativeScaleApplied))
				{
					shopPlusPlugin.freeItemSelectionCoroutine = null;
					return false;
				}
				<>2__current = FreeItemRetryDelay;
				<>1__state = 1;
				return true;
			}
			if ((Object)(object)Instance != (Object)null)
			{
				((BaseUnityPlugin)Instance).Logger.LogWarning((object)$"Failed to apply synced free shop item on this client. ViewID={photonViewId}");
			}
			shopPlusPlugin.freeItemSelectionCoroutine = null;
			return false;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	public const string PluginGuid = "zichen.shopplus";

	public const string PluginVersion = "1.0.2";

	public const string PluginName = "ShopPlus";

	private static ShopPlusPlugin Instance;

	private Harmony harmony;

	private const string InfoSection = "模组信息";

	private const string GlobalSection = "A.全局设置";

	private const string ShopItemFeaturesSection = "B.刷物和免单";

	private const string GroundPacksSection = "C.地面补货";

	private const string DebugSection = "D.调试选项";

	private const int MaxItemSpawnMultiplier = 3;

	private const int MaxGroundItemPackCount = 3;

	private const int MaxGroundItemVolumeCount = 20;

	private ConfigEntry<string> moduleNameInfo;

	private ConfigEntry<string> moduleVersionInfo;

	private ConfigEntry<bool> modEnabled;

	internal ConfigEntry<bool> shopItemFeaturesEnabled;

	internal ConfigEntry<int> itemSpawnMultiplier;

	internal ConfigEntry<bool> randomFreeItemEnabled;

	internal ConfigEntry<bool> groundItemPacksEnabled;

	internal ConfigEntry<int> groundItemPackCount;

	internal ConfigEntry<int> groundSmallItemCount;

	internal ConfigEntry<int> groundMediumItemCount;

	internal ConfigEntry<int> groundPowerCrystalCount;

	internal ConfigEntry<int> groundLargeHighItemCount;

	internal ConfigEntry<int> groundUpgradeItemCount;

	internal ConfigEntry<int> groundHealthPackCount;

	internal ConfigEntry<int> groundLargeItemCount;

	internal ConfigEntry<int> groundLargeWideItemCount;

	internal ConfigEntry<int> groundLargePlusItemCount;

	internal ConfigEntry<bool> debugGroundPackMarkers;

	private Coroutine freeItemSelectionCoroutine;

	private readonly List<ItemAttributes> freeItemCandidateBuffer = new List<ItemAttributes>(128);

	private DateTime lastLoadedConfigWriteTimeUtc = DateTime.MinValue;

	private int lastRuntimeConfigReloadFrame = -1;

	private Rect cachedFreeItemLabelRect;

	private int cachedFreeItemLabelFrame = -1;

	private static ItemAttributes currentFreeShopItem;

	private static int currentFreeShopItemOriginalValue = -1;

	private static Vector3 currentFreeShopItemOriginalScale = Vector3.one;

	private static bool currentFreeShopItemShouldRestoreOriginalState = true;

	private static bool currentFreeShopItemUsesNativeNetworkSync;

	private static ShopPlusFreeItemSync freeItemNetworkSync;

	private static GUIStyle freeItemLabelStyle;

	private static readonly Color FreeItemHighlightColor = new Color(0.32f, 1f, 0.48f, 1f);

	private static readonly Color FreeItemLabelBackgroundColor = new Color(0.18f, 0.92f, 0.35f, 0.95f);

	private static readonly WaitForSeconds FreeItemRetryDelay = new WaitForSeconds(0.2f);

	private static readonly Comparison<ItemAttributes> FreeItemCandidateComparison = CompareFreeItemCandidates;

	private const int FreeItemMaxValue = 10;

	private const int FreeItemMaxSelectionAttempts = 15;

	private const float FreeItemScaleMultiplier = 3f;

	private const string FreeItemPromptSuffix = " <color=#52FF7A>[FREE]</color>";

	private const string DebugShelfSection = "D.货架模型调试";

	private const string DebugShelfBundleFileName = "moreshopitems_assets.file";

	private const string DebugShelfPrefabName = "custom_soda_shelf";

	private const string DebugShelfPrimaryModelId = "custom_soda_shelf";

	private const string DebugShelfSecondaryModelId = "gouwujia_fbx";

	private const string DebugShelfSecondaryModelDisplayName = "gouwujia.fbx";

	private const string DebugShelfSecondaryModelFileName = "gouwujia.fbx";

	private const string DebugShelfPlacementFilePrefix = "debug-shelf-placement-";

	private const string DebugShelfLiveStateFilePrefix = "debug-shelf-current-";

	private const float DebugShelfMinScale = 0.25f;

	private const float DebugShelfMaxScale = 3.5f;

	private const int DebugShelfWindowId = 381126;

	private const KeyCode DebugShelfToggleKey = 282;

	private const float DebugShelfWindowWidth = 460f;

	private const float DebugShelfWindowHeight = 420f;

	private const string RepoProjectRootPath = "D:\\donetProjects\\repo\\Zichen-Mods\\Zichen-ShopPlus";

	private static readonly string RepoLocalMoreShopItemsBundlePath = "D:\\donetProjects\\repo\\_project_docs\\MODS_DECOMPILED_SOURCE_READ_ONLY\\Jettcodey-MoreShopItems_Updated\\3.3.0\\moreshopitems_assets.file";

	private static readonly string[] DebugShelfAnchorCandidates = new string[6] { "Soda Shelf", "Shop Magazine Stand (1)", "Candy Shelf", "Soda Machine (1)", "cashiers shelf", "Shop Magazine Stand" };

	private static readonly float[] DebugShelfMoveSteps = new float[5] { 0.01f, 0.05f, 0.1f, 0.25f, 0.5f };

	private static readonly float[] DebugShelfScaleSteps = new float[4] { 0.01f, 0.05f, 0.1f, 0.25f };

	private static readonly float[] DebugShelfYawSteps = new float[4] { 1f, 5f, 15f, 45f };

	private const float DebugShelfFineStepMultiplier = 0.1f;

	internal ConfigEntry<bool> debugShelfEnabled;

	internal ConfigEntry<bool> debugShelfPanelEnabled;

	private static AssetBundle debugShelfBundle;

	private static GameObject debugShelfPrefab;

	private static GameObject debugShelfInstance;

	private static GameObject debugShelfSecondaryInstance;

	private static string debugShelfResolvedBundlePath = string.Empty;

	private static string debugShelfLastError = string.Empty;

	private static string debugShelfSecondaryStatus = string.Empty;

	private static string debugShelfCurrentShopKey = string.Empty;

	private static string debugShelfCurrentLevelName = string.Empty;

	private static string debugShelfCurrentNarrativeName = string.Empty;

	private static string debugShelfCurrentSceneName = string.Empty;

	private static string debugShelfCurrentResourcePath = string.Empty;

	private static string debugShelfAnchorName = "none";

	private static Vector3 debugShelfAnchorPosition = Vector3.zero;

	private static Quaternion debugShelfAnchorRotation = Quaternion.identity;

	private static Rect debugShelfWindowRect = new Rect(18f, 18f, 460f, 420f);

	private static int debugShelfMoveStepIndex = 2;

	private static int debugShelfScaleStepIndex = 1;

	private static int debugShelfYawStepIndex = 1;

	private static bool debugShelfHasSavedPlacement;

	private static bool debugShelfPanelVisible;

	private static string debugShelfSelectedModelId = "custom_soda_shelf";

	private static bool debugShelfCursorStateCaptured;

	private static bool debugShelfPreviousCursorVisible;

	private static CursorLockMode debugShelfPreviousCursorLockMode;

	private static GUIStyle debugShelfBadgeStyle;

	private static GUIStyle debugShelfInfoStyle;

	private static GUIStyle debugShelfHeaderStyle;

	private static readonly FieldInfo ShopManagerItemVolumesField = typeof(ShopManager).GetField("itemVolumes", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static readonly FieldInfo ShopManagerShoppingListField = typeof(ShopManager).GetField("shoppingList", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static readonly FieldInfo ShopManagerItemSpawnTargetAmountField = typeof(ShopManager).GetField("itemSpawnTargetAmount", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static readonly FieldInfo ShopManagerItemConsumablesAmountField = typeof(ShopManager).GetField("itemConsumablesAmount", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static readonly FieldInfo ShopManagerItemUpgradesAmountField = typeof(ShopManager).GetField("itemUpgradesAmount", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static readonly FieldInfo ShopManagerItemHealthPacksAmountField = typeof(ShopManager).GetField("itemHealthPacksAmount", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static readonly FieldInfo ShopManagerPotentialItemsField = typeof(ShopManager).GetField("potentialItems", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static readonly FieldInfo ShopManagerPotentialItemConsumablesField = typeof(ShopManager).GetField("potentialItemConsumables", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static readonly FieldInfo ShopManagerPotentialItemUpgradesField = typeof(ShopManager).GetField("potentialItemUpgrades", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static readonly FieldInfo ShopManagerPotentialItemHealthPacksField = typeof(ShopManager).GetField("potentialItemHealthPacks", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static readonly FieldInfo ShopManagerPotentialSecretItemsField = typeof(ShopManager).GetField("potentialSecretItems", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static readonly FieldInfo ShopManagerItemValueMultiplierField = typeof(ShopManager).GetField("itemValueMultiplier", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static readonly FieldInfo ItemAttributesValueField = typeof(ItemAttributes).GetField("value", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static readonly FieldInfo ItemAttributesPromptNameField = typeof(ItemAttributes).GetField("promptName", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static readonly FieldInfo ExtractionPointIsShopField = typeof(ExtractionPoint).GetField("isShop", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static readonly FieldInfo RoomVolumeCheckInTruckField = typeof(RoomVolumeCheck).GetField("inTruck", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static readonly FieldInfo RoomVolumeCheckInExtractionPointField = typeof(RoomVolumeCheck).GetField("inExtractionPoint", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static readonly FieldInfo WorldSpaceUIValueTextField = typeof(WorldSpaceUIValue).GetField("text", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private const int GroundPackColumns = 11;

	private const float GroundPackMaxSpacing = 0.62f;

	private const float GroundPackMinSpacing = 0.38f;

	private const float GroundPackDesiredSpawnHeight = 1.25f;

	private const float GroundPackMinimumSpawnHeight = 0.45f;

	private const float GroundPackCeilingClearance = 0.55f;

	private const float GroundPackExtractionClearance = 3.65f;

	private const float GroundPackBoundsMargin = 0.38f;

	private const float GroundPackOccupiedClearanceFactor = 0.68f;

	private const float GroundPackOccupiedClearanceMin = 0.26f;

	private const float GroundPackOriginalVolumeClearance = 0.48f;

	private const int GroundPackRaycastHitBufferSize = 64;

	private static readonly float[] GroundPackFallbackAngles = new float[14]
	{
		0f, 24f, -24f, 48f, -48f, 72f, -72f, 96f, -96f, 120f,
		-120f, 144f, -144f, 180f
	};

	private static readonly List<GameObject> groundSpawnVolumeObjects = new List<GameObject>();

	private static readonly List<GameObject> groundPackMarkedItems = new List<GameObject>();

	private static readonly List<ItemVolume> sceneShopVolumeBuffer = new List<ItemVolume>(96);

	private static readonly List<ItemVolume> normalShopVolumeBuffer = new List<ItemVolume>(96);

	private static readonly List<Vector3> groundPackOccupiedPositionsBuffer = new List<Vector3>(256);

	private static readonly List<GroundPackSpawnSlot> pendingGroundPackSpawnSlots = new List<GroundPackSpawnSlot>(512);

	private static readonly Dictionary<itemVolume, int> groundPackCreatedCountsBuffer = new Dictionary<itemVolume, int>(16);

	private static readonly Dictionary<string, int> groundPackSkippedCountsBuffer = new Dictionary<string, int>(16);

	private static readonly Dictionary<string, int> groundPackUpgradeItemCountsBuffer = new Dictionary<string, int>(32);

	private static readonly List<Item> limitedItemReplacementCandidatesBuffer = new List<Item>(64);

	private static readonly Dictionary<string, ShopItemLimitState> originalShopItemLimitStates = new Dictionary<string, ShopItemLimitState>(128);

	private static readonly float[] groundPackHeightSampleBuffer = new float[5];

	private static readonly RaycastHit[] GroundPackFloorRaycastHits = (RaycastHit[])(object)new RaycastHit[64];

	private static readonly RaycastHit[] GroundPackCeilingRaycastHits = (RaycastHit[])(object)new RaycastHit[64];

	private static int groundPackCreateLogFrame = -1;

	private static int itemVolumeCollectionLogFrame = -1;

	private static int originalShopCurrency = -1;

	private static PropertyInfo worldSpaceUITextProperty;

	private static PropertyInfo worldSpaceUIColorProperty;

	private void Awake()
	{
		DetachFromManager();
		Instance = this;
		ResetConfigIfVersionChanged();
		BindConfig();
		ApplyHarmonyPatches();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"ShopPlus v1.0.2 loaded.");
	}

	private void OnDestroy()
	{
		Harmony obj = harmony;
		if (obj != null)
		{
			obj.UnpatchSelf();
		}
		if (Instance == this)
		{
			Instance = null;
		}
	}

	private void DetachFromManager()
	{
		try
		{
			((Component)this).transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Failed to mark plugin host persistent: " + ex.GetType().Name + ": " + ex.Message));
		}
	}

	private bool IsModEnabled()
	{
		if (modEnabled != null)
		{
			return modEnabled.Value;
		}
		return true;
	}

	private static bool IsStaticModEnabled()
	{
		ShopPlusPlugin instance = Instance;
		if (!((Object)(object)instance == (Object)null))
		{
			return instance.IsModEnabled();
		}
		return true;
	}

	private static bool ShouldRunMasterShopLogic()
	{
		if (IsStaticModEnabled() && SemiFunc.RunIsShop())
		{
			return !SemiFunc.IsNotMasterClient();
		}
		return false;
	}

	private bool AreShopItemFeaturesEnabled()
	{
		if (shopItemFeaturesEnabled != null)
		{
			return shopItemFeaturesEnabled.Value;
		}
		return true;
	}

	private static bool AreStaticShopItemFeaturesEnabled()
	{
		ShopPlusPlugin instance = Instance;
		if (!((Object)(object)instance == (Object)null))
		{
			return instance.AreShopItemFeaturesEnabled();
		}
		return true;
	}

	private static int GetConfiguredItemSpawnMultiplier()
	{
		if (!AreStaticShopItemFeaturesEnabled())
		{
			return 1;
		}
		return Mathf.Clamp((Instance?.itemSpawnMultiplier?.Value).GetValueOrDefault(1), 1, 3);
	}

	private bool IsRandomFreeItemRuntimeEnabled()
	{
		if (IsModEnabled() && AreShopItemFeaturesEnabled())
		{
			if (randomFreeItemEnabled != null)
			{
				return randomFreeItemEnabled.Value;
			}
			return true;
		}
		return false;
	}

	private static bool IsStaticRandomFreeItemEnabled()
	{
		ShopPlusPlugin instance = Instance;
		if (!((Object)(object)instance == (Object)null))
		{
			return instance.IsRandomFreeItemRuntimeEnabled();
		}
		return true;
	}

	private static bool IsDebugGroundPackMarkersEnabled()
	{
		ShopPlusPlugin instance = Instance;
		if ((Object)(object)instance != (Object)null && instance.debugGroundPackMarkers != null)
		{
			return instance.debugGroundPackMarkers.Value;
		}
		return false;
	}

	private static bool IsGroundPackEnabled()
	{
		ShopPlusPlugin instance = Instance;
		if ((Object)(object)instance != (Object)null && instance.groundItemPacksEnabled != null)
		{
			return instance.groundItemPacksEnabled.Value;
		}
		return false;
	}

	private static int GetConfiguredGroundPackCount()
	{
		return Mathf.Clamp((Instance?.groundItemPackCount?.Value).GetValueOrDefault(1), 1, 3);
	}

	private static int ClampGroundItemVolumeCount(ConfigEntry<int> entry, int fallback)
	{
		return Mathf.Clamp(entry?.Value ?? fallback, 0, 20);
	}

	private void BindConfig()
	{
		moduleNameInfo = BindReadOnlyInfo("模组名称", "商店扩展", "当前模组的中文名称。此处只是提示,不影响功能。", 1000);
		moduleVersionInfo = BindReadOnlyInfo("模组版本号", "1.0.2", "当前模组版本号。此处只是提示,不影响功能。", 990);
		modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("A.全局设置", "模组启用", true, ConfigDescriptionWithOrder("关闭后整个模组所有功能都不生效。默认开启。", 1005));
		int fallback = ReadIntConfigValue(((BaseUnityPlugin)this).Config.ConfigFilePath, "B.刷物和免单", "系统商店倍率", 1, 1, 3);
		fallback = ReadIntConfigValue(((BaseUnityPlugin)this).Config.ConfigFilePath, "B.刷物和免单", "物品刷出倍率", fallback, 1, 3);
		bool flag = ReadRandomFreeItemDefault(((BaseUnityPlugin)this).Config.ConfigFilePath);
		shopItemFeaturesEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("B.刷物和免单", "启用刷物和免单", true, ConfigDescriptionWithOrder("总开关:关闭后系统商店倍率按1倍处理,免单1件10k以内商品也不生效。默认开启。", 1000));
		itemSpawnMultiplier = ((BaseUnityPlugin)this).Config.Bind<int>("B.刷物和免单", "系统商店倍率", fallback, ConfigDescriptionWithOrder("只调整官方/原版商店刷物倍率,不影响 C.地面补货。1倍为原版,最多3倍。默认1倍。", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 3), 995));
		randomFreeItemEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("B.刷物和免单", "免单1件10k以内商品", flag, ConfigDescriptionWithOrder("开启后每次进入商店会随机挑选一件价格不高于10k的商店商品直接改成0元,并显示明显提示。默认开启。", 990));
		groundItemPacksEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("C.地面补货", "启用地面补货", true, ConfigDescriptionWithOrder("开启后独立在商店地面生成补货物品,不受 B.刷物和免单/系统商店倍率影响;关闭后完全不生成。默认开启。", 985));
		groundItemPackCount = ((BaseUnityPlugin)this).Config.Bind<int>("C.地面补货", "地面补货套数", 2, ConfigDescriptionWithOrder("每1套按配置分类数量生成一堆地面补货。最多3套。默认2套。", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 3), 980));
		groundUpgradeItemCount = BindGroundVolumeCount("升级药水数量", 20, "每套地面补货生成多少个升级药水/升级道具刷点。0为不生成,最多20。", 979);
		groundSmallItemCount = BindGroundVolumeCount("小型物品数量", 10, "每套地面补货生成多少个 small 小型物品刷点。0为不生成,最多20。", 978);
		groundMediumItemCount = BindGroundVolumeCount("中型物品数量", 10, "每套地面补货生成多少个 medium 中型物品刷点。0为不生成,最多20。", 977);
		groundPowerCrystalCount = BindGroundVolumeCount("能量水晶数量", 3, "每套地面补货生成多少个 power_crystal 能量水晶刷点。0为不生成,最多20。", 976);
		groundLargeHighItemCount = BindGroundVolumeCount("高大型物品数量", 2, "每套地面补货生成多少个 large_high 高大型物品刷点。0为不生成,最多20。", 975);
		groundHealthPackCount = BindGroundVolumeCount("医疗包数量", 5, "每套地面补货生成多少个 healthPack 医疗包/血包刷点。0为不生成,最多20。", 974);
		groundLargeItemCount = BindGroundVolumeCount("大型物品数量", 0, "每套地面补货生成多少个 large 大型物品刷点。0为不生成,最多20。", 973);
		groundLargeWideItemCount = BindGroundVolumeCount("宽大型物品数量", 0, "每套地面补货生成多少个 large_wide 宽大型物品刷点。0为不生成,最多20。", 972);
		groundLargePlusItemCount = BindGroundVolumeCount("超大型物品数量", 0, "每套地面补货生成多少个 large_plus 超大型物品刷点。0为不生成,最多20。", 971);
		debugGroundPackMarkers = ((BaseUnityPlugin)this).Config.Bind<bool>("D.调试选项", "显示地面补货标记", false, ConfigDescriptionWithOrder("开启后地面补货物品上方会显示蓝色分类标签(用于调试)。默认关闭。", 900));
		UpdateLoadedConfigWriteTime();
	}

	private ConfigEntry<int> BindGroundVolumeCount(string key, int defaultValue, string description, int order)
	{
		return ((BaseUnityPlugin)this).Config.Bind<int>("C.地面补货", key, defaultValue, ConfigDescriptionWithOrder(description, (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 20), order));
	}

	private void ResetConfigIfVersionChanged()
	{
		try
		{
			string configFilePath = ((BaseUnityPlugin)this).Config.ConfigFilePath;
			string text = ReadConfigPluginVersion(configFilePath);
			if (!string.IsNullOrWhiteSpace(text) && !(text == "1.0.2"))
			{
				ResetConfigFileToDefaults(configFilePath);
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Config version changed. Old config was reset to defaults.");
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Failed to reset config by version: " + ex.Message));
		}
	}

	private void ReloadRuntimeConfigForNextShop()
	{
		try
		{
			if (lastRuntimeConfigReloadFrame != Time.frameCount)
			{
				lastRuntimeConfigReloadFrame = Time.frameCount;
				string configFilePath = ((BaseUnityPlugin)this).Config.ConfigFilePath;
				DateTime dateTime = (File.Exists(configFilePath) ? File.GetLastWriteTimeUtc(configFilePath) : DateTime.MinValue);
				((BaseUnityPlugin)this).Config.Reload();
				lastLoadedConfigWriteTimeUtc = dateTime;
				((BaseUnityPlugin)this).Logger.LogInfo((object)$"Config reloaded for shop generation. fileTimeUtc={dateTime:O}");
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Failed to reload config for next shop: " + ex.Message));
		}
	}

	private static string ReadConfigPluginVersion(string configPath)
	{
		if (!File.Exists(configPath))
		{
			return null;
		}
		Match match = Regex.Match(File.ReadAllText(configPath), "(?m)^模组版本号\\s*=\\s*(.+?)\\s*$");
		if (!match.Success)
		{
			return null;
		}
		return match.Groups[1].Value.Trim();
	}

	private static bool ReadBoolConfigValue(string configPath, string section, string key, bool fallback)
	{
		if (!TryReadConfigValue(configPath, section, key, out var value) || !bool.TryParse(value, out var result))
		{
			return fallback;
		}
		return result;
	}

	private static bool ReadRandomFreeItemDefault(string configPath)
	{
		return ReadBoolConfigValue(configPath, "B.刷物和免单", "免单1件10k以内商品", ReadBoolConfigValue(configPath, "B.刷物和免单", "十元内随机免单", ReadBoolConfigValue(configPath, "A.全局设置", "十元内随机免单", fallback: true)));
	}

	private static int ReadIntConfigValue(string configPath, string section, string key, int fallback, int min, int max)
	{
		if (!TryReadConfigValue(configPath, section, key, out var value) || !int.TryParse(value, out var result))
		{
			return fallback;
		}
		return Mathf.Clamp(result, min, max);
	}

	private static bool TryReadConfigValue(string configPath, string section, string key, out string value)
	{
		value = null;
		if (!File.Exists(configPath))
		{
			return false;
		}
		string text = null;
		string[] array = File.ReadAllLines(configPath);
		for (int i = 0; i < array.Length; i++)
		{
			string text2 = array[i].Trim();
			if (text2.Length == 0 || text2.StartsWith("#", StringComparison.Ordinal))
			{
				continue;
			}
			if (text2.StartsWith("[", StringComparison.Ordinal) && text2.EndsWith("]", StringComparison.Ordinal))
			{
				text = text2.Substring(1, text2.Length - 2);
			}
			else if (!(text != section))
			{
				int num = text2.IndexOf('=');
				if (num >= 0 && !(text2.Substring(0, num).Trim() != key))
				{
					value = text2.Substring(num + 1).Trim();
					return true;
				}
			}
		}
		return false;
	}

	private void ResetConfigFileToDefaults(string configPath)
	{
		((BaseUnityPlugin)this).Config.Clear();
		if (File.Exists(configPath))
		{
			File.Delete(configPath);
		}
		((BaseUnityPlugin)this).Config.Reload();
	}

	private void UpdateLoadedConfigWriteTime()
	{
		string configFilePath = ((BaseUnityPlugin)this).Config.ConfigFilePath;
		lastLoadedConfigWriteTimeUtc = (File.Exists(configFilePath) ? File.GetLastWriteTimeUtc(configFilePath) : DateTime.MinValue);
	}

	private static ConfigDescription ConfigDescriptionWithOrder(string description, int order)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		return new ConfigDescription(description, (AcceptableValueBase)null, new object[1]
		{
			new ConfigurationManagerAttributes
			{
				Order = order
			}
		});
	}

	private static ConfigDescription ConfigDescriptionWithOrder(string description, AcceptableValueBase acceptableValues, int order)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		return new ConfigDescription(description, acceptableValues, new object[1]
		{
			new ConfigurationManagerAttributes
			{
				Order = order
			}
		});
	}

	private ConfigEntry<string> BindReadOnlyInfo(string key, string value, string description, int order)
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Expected O, but got Unknown
		ConfigEntry<string> obj = ((BaseUnityPlugin)this).Config.Bind<string>("模组信息", key, value, new ConfigDescription(description, (AcceptableValueBase)null, new object[1]
		{
			new ConfigurationManagerAttributes
			{
				Order = order,
				CustomDrawer = DrawInfo,
				ReadOnly = true
			}
		}));
		obj.Value = value;
		return obj;
	}

	private static void DrawInfo(ConfigEntryBase entry)
	{
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label(entry.Definition.Key, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
		GUILayout.Label(entry.BoxedValue?.ToString() ?? string.Empty, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(160f) });
		GUILayout.EndHorizontal();
	}

	private bool IsDebugShelfRuntimeEnabled()
	{
		return false;
	}

	private bool IsDebugShelfPanelRuntimeEnabled()
	{
		return false;
	}

	private static bool IsStaticDebugShelfEnabled()
	{
		ShopPlusPlugin instance = Instance;
		if ((Object)(object)instance != (Object)null)
		{
			return instance.IsDebugShelfRuntimeEnabled();
		}
		return false;
	}

	private static bool IsStaticDebugShelfPanelEnabled()
	{
		ShopPlusPlugin instance = Instance;
		if ((Object)(object)instance != (Object)null)
		{
			return instance.IsDebugShelfPanelRuntimeEnabled();
		}
		return false;
	}

	private void UpdateDebugShelfRuntime()
	{
		if (!SemiFunc.RunIsShop() || !IsDebugShelfRuntimeEnabled())
		{
			RestoreDebugShelfCursorState();
			debugShelfPanelVisible = false;
			if ((Object)(object)debugShelfInstance != (Object)null || (Object)(object)debugShelfSecondaryInstance != (Object)null)
			{
				DestroyDebugShelfInstances("left shop or feature disabled");
			}
			return;
		}
		if (IsDebugShelfPanelRuntimeEnabled() && Input.GetKeyDown((KeyCode)282))
		{
			debugShelfPanelVisible = !debugShelfPanelVisible;
			if (debugShelfPanelVisible)
			{
				CenterDebugShelfWindow();
				CaptureDebugShelfCursorStateIfNeeded();
			}
			else
			{
				RestoreDebugShelfCursorState();
			}
			if ((Object)(object)Instance != (Object)null)
			{
				((BaseUnityPlugin)Instance).Logger.LogInfo((object)string.Format("[ShelfDebug] Panel toggled {0} by key {1}.", debugShelfPanelVisible ? "open" : "closed", (object)(KeyCode)282));
			}
		}
		if (debugShelfPanelVisible)
		{
			ForceDebugShelfCursorUnlocked();
		}
		if ((Object)(object)debugShelfInstance == (Object)null)
		{
			EnsureDebugShelfSpawnedForCurrentShop();
		}
		else if (!debugShelfInstance.activeInHierarchy)
		{
			DestroyDebugShelfInstances("debug shelf instance became inactive");
		}
	}

	private static void EnsureDebugShelfSpawnedForCurrentShop()
	{
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: 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_009e: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: 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)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: 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_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: 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_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: 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)
		if (!IsStaticDebugShelfEnabled() || !SemiFunc.RunIsShop())
		{
			return;
		}
		UpdateDebugShelfContext();
		if ((Object)(object)debugShelfInstance != (Object)null && debugShelfCurrentShopKey == BuildCurrentDebugShelfShopKey())
		{
			return;
		}
		if (!TryLoadDebugShelfPrefab(out var failureReason))
		{
			debugShelfLastError = failureReason;
			((BaseUnityPlugin)Instance).Logger.LogWarning((object)("[ShelfDebug] " + failureReason));
			return;
		}
		debugShelfCurrentShopKey = BuildCurrentDebugShelfShopKey();
		DestroyDebugShelfInstances(null);
		if (!TryGetDebugShelfAnchor(out var anchorPosition, out var anchorRotation, out var anchorName))
		{
			anchorPosition = Vector3.zero;
			anchorRotation = Quaternion.identity;
			anchorName = "FallbackOrigin";
		}
		debugShelfAnchorPosition = anchorPosition;
		debugShelfAnchorRotation = anchorRotation;
		debugShelfAnchorName = anchorName;
		Vector3 position = anchorPosition;
		Vector3 val = Vector3.one;
		float num = NormalizeYaw(((Quaternion)(ref anchorRotation)).eulerAngles.y);
		debugShelfHasSavedPlacement = TryGetSavedDebugShelfPlacement("custom_soda_shelf", debugShelfCurrentShopKey, out var placement);
		if (debugShelfHasSavedPlacement && placement != null)
		{
			position = placement.position;
			val = ValidateDebugShelfScale(placement.scale);
			num = NormalizeYaw(placement.yaw);
		}
		debugShelfInstance = Object.Instantiate<GameObject>(debugShelfPrefab);
		((Object)debugShelfInstance).name = "ShopPlus_DebugShelf";
		PrepareDebugShelfVisualOnly(debugShelfInstance);
		ApplyDebugShelfTransform(position, num, val);
		EnsureSecondaryDebugShelfSpawned(anchorPosition, anchorRotation);
		debugShelfLastError = string.Empty;
		debugShelfSelectedModelId = "custom_soda_shelf";
		((BaseUnityPlugin)Instance).Logger.LogInfo((object)string.Format("[ShelfDebug] Spawned custom shelf for shopKey={0}, level={1}, narrative={2}, anchor={3}{4}, position={5}, yaw={6:F1}, scale={7}, bundle={8}, savedPlacement={9}, toggleKey={10}.", debugShelfCurrentShopKey, debugShelfCurrentLevelName, debugShelfCurrentNarrativeName, debugShelfAnchorName, FormatVector3(debugShelfAnchorPosition), FormatVector3(position), num, FormatVector3(val), debugShelfResolvedBundlePath, debugShelfHasSavedPlacement ? "yes" : "no", (object)(KeyCode)282));
	}

	private static void PrepareDebugShelfVisualOnly(GameObject instance)
	{
		if ((Object)(object)instance == (Object)null)
		{
			return;
		}
		int num = 0;
		ItemVolume[] componentsInChildren = instance.GetComponentsInChildren<ItemVolume>(true);
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			if (!((Object)(object)componentsInChildren[i] == (Object)null))
			{
				((Behaviour)componentsInChildren[i]).enabled = false;
				num++;
			}
		}
		int num2 = 0;
		Collider[] componentsInChildren2 = instance.GetComponentsInChildren<Collider>(true);
		foreach (Collider val in componentsInChildren2)
		{
			if (!((Object)(object)val == (Object)null) && !val.isTrigger)
			{
				val.isTrigger = true;
				num2++;
			}
		}
		Rigidbody[] componentsInChildren3 = instance.GetComponentsInChildren<Rigidbody>(true);
		foreach (Rigidbody val2 in componentsInChildren3)
		{
			if (!((Object)(object)val2 == (Object)null))
			{
				val2.isKinematic = true;
				val2.useGravity = false;
			}
		}
		((BaseUnityPlugin)Instance).Logger.LogInfo((object)$"[ShelfDebug] Prepared debug shelf as visual-only model. disabledItemVolumes={num}, triggerColliders={num2}, rigidbodies={componentsInChildren3.Length}.");
	}

	private static bool TryLoadDebugShelfPrefab(out string failureReason)
	{
		failureReason = null;
		if ((Object)(object)debugShelfPrefab != (Object)null)
		{
			return true;
		}
		string text = ResolveDebugShelfBundlePath();
		if (string.IsNullOrEmpty(text))
		{
			failureReason = "Could not find moreshopitems_assets.file. Searched repo local reference path, ShopPlus DLL folder, and installed plugin folders.";
			return false;
		}
		if ((Object)(object)debugShelfBundle == (Object)null)
		{
			debugShelfBundle = AssetBundle.LoadFromFile(text);
			if ((Object)(object)debugShelfBundle == (Object)null)
			{
				failureReason = "Failed to load asset bundle from " + text + ".";
				return false;
			}
		}
		debugShelfPrefab = debugShelfBundle.LoadAsset<GameObject>("custom_soda_shelf");
		if ((Object)(object)debugShelfPrefab == (Object)null)
		{
			failureReason = "Asset 'custom_soda_shelf' was not found in bundle " + text + ".";
			return false;
		}
		debugShelfResolvedBundlePath = text;
		return true;
	}

	private static string ResolveDebugShelfBundlePath()
	{
		if (!string.IsNullOrEmpty(debugShelfResolvedBundlePath) && File.Exists(debugShelfResolvedBundlePath))
		{
			return debugShelfResolvedBundlePath;
		}
		if (File.Exists(RepoLocalMoreShopItemsBundlePath))
		{
			debugShelfResolvedBundlePath = RepoLocalMoreShopItemsBundlePath;
			return debugShelfResolvedBundlePath;
		}
		string text = (((Object)(object)Instance != (Object)null) ? Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)Instance).Info.Location) ?? string.Empty, "moreshopitems_assets.file") : string.Empty);
		if (!string.IsNullOrEmpty(text) && File.Exists(text))
		{
			debugShelfResolvedBundlePath = text;
			return debugShelfResolvedBundlePath;
		}
		try
		{
			string[] files = Directory.GetFiles(Paths.PluginPath, "moreshopitems_assets.file", SearchOption.AllDirectories);
			foreach (string text2 in files)
			{
				if (text2.IndexOf("MoreShopItems", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					debugShelfResolvedBundlePath = text2;
					return debugShelfResolvedBundlePath;
				}
			}
			if (files.Length != 0)
			{
				debugShelfResolvedBundlePath = files[0];
				return debugShelfResolvedBundlePath;
			}
		}
		catch (Exception ex)
		{
			debugShelfLastError = "Failed to search plugin folders for debug shelf bundle: " + ex.Message;
		}
		return string.Empty;
	}

	private static void UpdateDebugShelfContext()
	{
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		debugShelfCurrentLevelName = (((Object)(object)RunManager.instance != (Object)null && (Object)(object)RunManager.instance.levelCurrent != (Object)null) ? ((Object)RunManager.instance.levelCurrent).name : string.Empty);
		debugShelfCurrentNarrativeName = (((Object)(object)RunManager.instance != (Object)null && (Object)(object)RunManager.instance.levelCurrent != (Object)null) ? RunManager.instance.levelCurrent.NarrativeName : string.Empty);
		debugShelfCurrentResourcePath = (SemiFunc.RunIsShop() ? "Shop" : string.Empty);
		Scene activeScene = SceneManager.GetActiveScene();
		debugShelfCurrentSceneName = ((Scene)(ref activeScene)).name;
	}

	private static string BuildCurrentDebugShelfShopKey()
	{
		UpdateDebugShelfContext();
		if (!string.IsNullOrWhiteSpace(debugShelfCurrentLevelName))
		{
			return debugShelfCurrentLevelName;
		}
		return "UnknownShopLevel";
	}

	private static bool TryGetDebugShelfAnchor(out Vector3 anchorPosition, out Quaternion anchorRotation, out string anchorName)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: 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_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: 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_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < DebugShelfAnchorCandidates.Length; i++)
		{
			string text = DebugShelfAnchorCandidates[i];
			GameObject val = GameObject.Find(text);
			if (!((Object)(object)val == (Object)null))
			{
				anchorPosition = val.transform.position;
				anchorRotation = ResolveAnchorRotation(text, val.transform.rotation);
				anchorName = text;
				return true;
			}
		}
		PlayerAvatar instance = PlayerAvatar.instance;
		if ((Object)(object)instance != (Object)null)
		{
			Vector3 forward = ((Component)instance).transform.forward;
			if (((Vector3)(ref forward)).sqrMagnitude < 0.01f)
			{
				forward = Vector3.forward;
			}
			anchorPosition = ((Component)instance).transform.position + ((Vector3)(ref forward)).normalized * 2f;
			anchorRotation = Quaternion.Euler(0f, NormalizeYaw(((Component)instance).transform.eulerAngles.y + 180f), 0f);
			anchorName = "PlayerSpawnFallback";
			return true;
		}
		if ((Object)(object)ShopManager.instance != (Object)null && (Object)(object)ShopManager.instance.extractionPoint != (Object)null)
		{
			anchorPosition = ShopManager.instance.extractionPoint.position + Vector3.forward * 2f;
			anchorRotation = Quaternion.identity;
			anchorName = "ExtractionFallback";
			return true;
		}
		anchorPosition = Vector3.zero;
		anchorRotation = Quaternion.identity;
		anchorName = "OriginFallback";
		return true;
	}

	private static Quaternion ResolveAnchorRotation(string anchorName, Quaternion baseRotation)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		switch (anchorName)
		{
		case "Shop Magazine Stand (1)":
		case "Shop Magazine Stand":
			return baseRotation * Quaternion.Euler(0f, 90f, 0f);
		case "Soda Machine (1)":
			return Quaternion.Euler(0f, 90f, 0f);
		case "cashiers shelf":
			return baseRotation * Quaternion.Euler(0f, 180f, 0f);
		default:
			return baseRotation;
		}
	}

	private static void EnsureSecondaryDebugShelfSpawned(Vector3 anchorPosition, Quaternion anchorRotation)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: 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_00d1: 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_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)debugShelfSecondaryInstance != (Object)null))
		{
			Vector3 position = anchorPosition + new Vector3(2.5f, 0f, 0f);
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(1.5f, 2f, 0.75f);
			float num = NormalizeYaw(((Quaternion)(ref anchorRotation)).eulerAngles.y);
			if (TryGetSavedDebugShelfPlacement("gouwujia_fbx", debugShelfCurrentShopKey, out var placement) && placement != null)
			{
				position = placement.position;
				val = ValidateDebugShelfScale(placement.scale);
				num = NormalizeYaw(placement.yaw);
			}
			debugShelfSecondaryInstance = GameObject.CreatePrimitive((PrimitiveType)3);
			((Object)debugShelfSecondaryInstance).name = "ShopPlus_DebugShelf_UserFbxPlaceholder";
			Renderer component = debugShelfSecondaryInstance.GetComponent<Renderer>();
			if ((Object)(object)component != (Object)null)
			{
				component.material.color = new Color(0.35f, 0.85f, 1f, 0.9f);
			}
			PrepareDebugShelfVisualOnly(debugShelfSecondaryInstance);
			ApplyDebugShelfTransformForInstance(debugShelfSecondaryInstance, position, num, val);
			debugShelfSecondaryStatus = "FBX 运行时无法直接加载,当前使用占位体。请后续把 gouwujia.fbx 转成 AssetBundle 或 PrefabBundle。";
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)string.Format("[ShelfDebug] Spawned secondary placeholder for {0}: position={1}, yaw={2:F1}, scale={3}.", "gouwujia.fbx", FormatVector3(position), num, FormatVector3(val)));
		}
	}

	private static void DestroyDebugShelfInstances(string reason)
	{
		if ((Object)(object)debugShelfInstance != (Object)null)
		{
			Object.Destroy((Object)(object)debugShelfInstance);
			debugShelfInstance = null;
		}
		if ((Object)(object)debugShelfSecondaryInstance != (Object)null)
		{
			Object.Destroy((Object)(object)debugShelfSecondaryInstance);
			debugShelfSecondaryInstance = null;
		}
		if (!string.IsNullOrEmpty(reason) && (Object)(object)Instance != (Object)null)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)("[ShelfDebug] Destroyed debug shelf instances: " + reason));
		}
	}

	private static GameObject GetSelectedDebugShelfInstance()
	{
		if (!(debugShelfSelectedModelId == "gouwujia_fbx"))
		{
			return debugShelfInstance;
		}
		return debugShelfSecondaryInstance;
	}

	private static string GetSelectedDebugShelfPrefabName()
	{
		if (!(debugShelfSelectedModelId == "gouwujia_fbx"))
		{
			return "custom_soda_shelf";
		}
		return "gouwujia.fbx";
	}

	private bool ShouldDrawDebugShelfPanel()
	{
		if (IsDebugShelfPanelRuntimeEnabled() && SemiFunc.RunIsShop())
		{
			return debugShelfPanelVisible;
		}
		return false;
	}

	private void DrawDebugShelfPanel()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected O, but got Unknown
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		EnsureDebugShelfGuiStyles();
		debugShelfWindowRect = GUI.Window(381126, debugShelfWindowRect, new WindowFunction(DrawDebugShelfWindowContents), "ShopPlus 货架调试");
	}

	private void DrawDebugShelfWindowContents(int windowId)
	{
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_022d: Unknown result type (might be due to invalid IL or missing references)
		//IL_023d: Unknown result type (might be due to invalid IL or missing references)
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0412: Unknown result type (might be due to invalid IL or missing references)
		//IL_041c: Unknown result type (might be due to invalid IL or missing references)
		//IL_042b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0516: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		GUILayout.Label("图名: " + GetDebugShelfDisplayName(), debugShelfHeaderStyle, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"按 {(object)(KeyCode)282} 可显示/隐藏面板", debugShelfInfoStyle, Array.Empty<GUILayoutOption>());
		GUILayout.Label("ShopKey: " + BuildCurrentDebugShelfShopKey(), debugShelfInfoStyle, Array.Empty<GUILayoutOption>());
		GUILayout.Label("Scene: " + debugShelfCurrentSceneName, debugShelfInfoStyle, Array.Empty<GUILayoutOption>());
		GUILayout.Label("当前模型: " + GetSelectedDebugShelfPrefabName(), debugShelfInfoStyle, Array.Empty<GUILayoutOption>());
		GUILayout.Label("Anchor: " + debugShelfAnchorName + " " + FormatVector3(debugShelfAnchorPosition), debugShelfInfoStyle, Array.Empty<GUILayoutOption>());
		GUILayout.Label("Bundle: " + (string.IsNullOrEmpty(debugShelfResolvedBundlePath) ? "未解析" : debugShelfResolvedBundlePath), debugShelfInfoStyle, Array.Empty<GUILayoutOption>());
		if (!string.IsNullOrEmpty(debugShelfSecondaryStatus))
		{
			GUILayout.Label("用户模型状态: " + debugShelfSecondaryStatus, debugShelfInfoStyle, Array.Empty<GUILayoutOption>());
		}
		if (!string.IsNullOrEmpty(debugShelfLastError))
		{
			GUILayout.Space(4f);
			GUILayout.Label("错误: " + debugShelfLastError, debugShelfInfoStyle, Array.Empty<GUILayoutOption>());
		}
		GUILayout.Space(6f);
		if ((Object)(object)debugShelfInstance == (Object)null)
		{
			GUILayout.Label("当前还没有生成调试货架。", debugShelfInfoStyle, Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("重新加载并生成", Array.Empty<GUILayoutOption>()))
			{
				EnsureDebugShelfSpawnedForCurrentShop();
			}
			GUILayout.EndVertical();
			GUI.DragWindow(new Rect(0f, 0f, 10000f, 22f));
			return;
		}
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		if (GUILayout.Button("选中货架A", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(120f) }))
		{
			debugShelfSelectedModelId = "custom_soda_shelf";
		}
		if (GUILayout.Button("选中货架B", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(120f) }))
		{
			debugShelfSelectedModelId = "gouwujia_fbx";
		}
		GUILayout.EndHorizontal();
		DrawDebugShelfVectorRow("X", Vector3.right);
		DrawDebugShelfVectorRow("Y", Vector3.up);
		DrawDebugShelfVectorRow("Z", Vector3.forward);
		DrawDebugShelfScaleRow();
		DrawDebugShelfYawRow();
		GameObject selectedDebugShelfInstance = GetSelectedDebugShelfInstance();
		GUILayout.Label("当前坐标: " + (((Object)(object)selectedDebugShelfInstance != (Object)null) ? FormatVector3(selectedDebugShelfInstance.transform.position) : "未生成"), debugShelfInfoStyle, Array.Empty<GUILayoutOption>());
		GUILayout.Label("当前缩放: " + (((Object)(object)selectedDebugShelfInstance != (Object)null) ? FormatVector3(selectedDebugShelfInstance.transform.localScale) : "未生成"), debugShelfInfoStyle, Array.Empty<GUILayoutOption>());
		GUILayout.Label("当前旋转Y: " + (((Object)(object)selectedDebugShelfInstance != (Object)null) ? NormalizeYaw(selectedDebugShelfInstance.transform.eulerAngles.y).ToString("F1") : "未生成"), debugShelfInfoStyle, Array.Empty<GUILayoutOption>());
		GUILayout.Space(6f);
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		if (GUILayout.Button($"位移步长 {DebugShelfMoveSteps[debugShelfMoveStepIndex]:F2}", Array.Empty<GUILayoutOption>()))
		{
			debugShelfMoveStepIndex = (debugShelfMoveStepIndex + 1) % DebugShelfMoveSteps.Length;
		}
		if (GUILayout.Button($"缩放步长 {DebugShelfScaleSteps[debugShelfScaleStepIndex]:F2}", Array.Empty<GUILayoutOption>()))
		{
			debugShelfScaleStepIndex = (debugShelfScaleStepIndex + 1) % DebugShelfScaleSteps.Length;
		}
		if (GUILayout.Button($"旋转步长 {DebugShelfYawSteps[debugShelfYawStepIndex]:F0}", Array.Empty<GUILayoutOption>()))
		{
			debugShelfYawStepIndex = (debugShelfYawStepIndex + 1) % DebugShelfYawSteps.Length;
		}
		GUILayout.EndHorizontal();
		GUILayout.Space(6f);
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		if (GUILayout.Button("重置到锚点", Array.Empty<GUILayoutOption>()))
		{
			ApplyDebugShelfTransform(debugShelfAnchorPosition, NormalizeYaw(((Quaternion)(ref debugShelfAnchorRotation)).eulerAngles.y), Vector3.one);
			LogCurrentDebugShelfTransform("ResetToAnchor");
		}
		if (GUILayout.Button("读取已保存", Array.Empty<GUILayoutOption>()))
		{
			LoadSavedDebugShelfPlacementIntoInstance();
		}
		GUILayout.EndHorizontal();
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		if (GUILayout.Button("保存本图坐标", Array.Empty<GUILayoutOption>()))
		{
			SaveCurrentDebugShelfPlacement();
		}
		if (GUILayout.Button("导出当前到日志", Array.Empty<GUILayoutOption>()))
		{
			ExportCurrentDebugShelfPlacementToLog();
		}
		GUILayout.EndHorizontal();
		GUILayout.Label("本地JSON: " + GetDebugShelfPlacementFilePath(), debugShelfInfoStyle, Array.Empty<GUILayoutOption>());
		GUILayout.Label("当前状态JSON: " + GetDebugShelfLiveStateFilePath(), debugShelfInfoStyle, Array.Empty<GUILayoutOption>());
		GUILayout.Label("已保存坐标: " + (debugShelfHasSavedPlacement ? "有" : "无"), debugShelfInfoStyle, Array.Empty<GUILayoutOption>());
		GUILayout.EndVertical();
		GUI.DragWindow(new Rect(0f, 0f, 10000f, 22f));
	}

	private void DrawDebugShelfVectorRow(string axisLabel, Vector3 axis)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: 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)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		GameObject selectedDebugShelfInstance = GetSelectedDebugShelfInstance();
		if (!((Object)(object)selectedDebugShelfInstance == (Object)null))
		{
			Vector3 position = selectedDebugShelfInstance.transform.position;
			float num = DebugShelfMoveSteps[debugShelfMoveStepIndex];
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label($"{axisLabel}: {GetAxisValue(position, axis):F2}", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(96f) });
			if (GUILayout.Button(axisLabel + "-", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(64f) }))
			{
				Transform transform = selectedDebugShelfInstance.transform;
				transform.position -= axis * num;
				LogCurrentDebugShelfTransform("Adjust " + axisLabel + "-");
			}
			if (GUILayout.Button(axisLabel + "+", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(64f) }))
			{
				Transform transform2 = selectedDebugShelfInstance.transform;
				transform2.position += axis * num;
				LogCurrentDebugShelfTransform("Adjust " + axisLabel + "+");
			}
			float num2 = num * 0.1f;
			if (GUILayout.Button(axisLabel + "--", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(52f) }))
			{
				Transform transform3 = selectedDebugShelfInstance.transform;
				transform3.position -= axis * num2;
				LogCurrentDebugShelfTransform("FineAdjust " + axisLabel + "-");
			}
			if (GUILayout.Button(axisLabel + "++", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(52f) }))
			{
				Transform transform4 = selectedDebugShelfInstance.transform;
				transform4.position += axis * num2;
				LogCurrentDebugShelfTransform("FineAdjust " + axisLabel + "+");
			}
			GUILayout.EndHorizontal();
		}
	}

	private void DrawDebugShelfScaleRow()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		GameObject selectedDebugShelfInstance = GetSelectedDebugShelfInstance();
		if (!((Object)(object)selectedDebugShelfInstance == (Object)null))
		{
			Vector3 localScale = selectedDebugShelfInstance.transform.localScale;
			float num = DebugShelfScaleSteps[debugShelfScaleStepIndex];
			float num2 = num * 0.1f;
			float x = localScale.x;
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Scale: {x:F2}", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(96f) });
			if (GUILayout.Button("缩小", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(64f) }))
			{
				SetDebugShelfUniformScale(x - num);
			}
			if (GUILayout.Button("放大", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(64f) }))
			{
				SetDebugShelfUniformScale(x + num);
			}
			if (GUILayout.Button("默认大小", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(92f) }))
			{
				SetDebugShelfUniformScale(1f);
			}
			if (GUILayout.Button("细缩", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(52f) }))
			{
				SetDebugShelfUniformScale(x - num2);
			}
			if (GUILayout.Button("细放", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(52f) }))
			{
				SetDebugShelfUniformScale(x + num2);
			}
			GUILayout.EndHorizontal();
		}
	}

	private void DrawDebugShelfYawRow()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		GameObject selectedDebugShelfInstance = GetSelectedDebugShelfInstance();
		if (!((Object)(object)selectedDebugShelfInstance == (Object)null))
		{
			float num = NormalizeYaw(selectedDebugShelfInstance.transform.eulerAngles.y);
			float num2 = DebugShelfYawSteps[debugShelfYawStepIndex];
			float num3 = num2 * 0.1f;
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Yaw: {num:F1}", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(96f) });
			if (GUILayout.Button("左转", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(64f) }))
			{
				SetDebugShelfYaw(num - num2);
			}
			if (GUILayout.Button("右转", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(64f) }))
			{
				SetDebugShelfYaw(num + num2);
			}
			if (GUILayout.Button("微左", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(52f) }))
			{
				SetDebugShelfYaw(num - num3);
			}
			if (GUILayout.Button("微右", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(52f) }))
			{
				SetDebugShelfYaw(num + num3);
			}
			GUILayout.EndHorizontal();
		}
	}

	private static void SetDebugShelfUniformScale(float newScale)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		GameObject selectedDebugShelfInstance = GetSelectedDebugShelfInstance();
		if (!((Object)(object)selectedDebugShelfInstance == (Object)null))
		{
			float num = Mathf.Clamp(newScale, 0.25f, 3.5f);
			selectedDebugShelfInstance.transform.localScale = new Vector3(num, num, num);
			LogCurrentDebugShelfTransform("Adjust Scale");
		}
	}

	private static void SetDebugShelfYaw(float yaw)
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		GameObject selectedDebugShelfInstance = GetSelectedDebugShelfInstance();
		if (!((Object)(object)selectedDebugShelfInstance == (Object)null))
		{
			selectedDebugShelfInstance.transform.rotation = Quaternion.Euler(0f, NormalizeYaw(yaw), 0f);
			LogCurrentDebugShelfTransform("Adjust Yaw");
		}
	}

	private static float NormalizeYaw(float yaw)
	{
		while (yaw < 0f)
		{
			yaw += 360f;
		}
		while (yaw >= 360f)
		{
			yaw -= 360f;
		}
		return yaw;
	}

	private static float GetAxisValue(Vector3 vector, Vector3 axis)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		if (axis == Vector3.right)
		{
			return vector.x;
		}
		if (axis == Vector3.up)
		{
			return vector.y;
		}
		return vector.z;
	}

	private static Vector3 ValidateDebugShelfScale(Vector3 scale)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		float num = scale.x;
		if (num <= 0f)
		{
			num = 1f;
		}
		num = Mathf.Clamp(num, 0.25f, 3.5f);
		return new Vector3(num, num, num);
	}

	private static void ApplyDebugShelfTransform(Vector3 position, float yaw, Vector3 scale)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		ApplyDebugShelfTransformForInstance(GetSelectedDebugShelfInstance(), position, yaw, scale);
	}

	private static void ApplyDebugShelfTransformForInstance(GameObject instance, Vector3 position, float yaw, Vector3 scale)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: 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)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)instance == (Object)null))
		{
			instance.transform.position = position;
			instance.transform.rotation = Quaternion.Euler(0f, NormalizeYaw(yaw), 0f);
			instance.transform.localScale = ValidateDebugShelfScale(scale);
		}
	}

	private static void LoadSavedDebugShelfPlacementIntoInstance()
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		GameObject selectedDebugShelfInstance = GetSelectedDebugShelfInstance();
		string text = debugShelfSelectedModelId;
		if (!((Object)(object)selectedDebugShelfInstance == (Object)null))
		{
			if (!TryGetSavedDebugShelfPlacement(text, BuildCurrentDebugShelfShopKey(), out var placement))
			{
				debugShelfHasSavedPlacement = false;
				((BaseUnityPlugin)Instance).Logger.LogInfo((object)("[ShelfDebug] No saved placement found for " + BuildCurrentDebugShelfShopKey() + " model=" + text + "."));
			}
			else
			{
				debugShelfHasSavedPlacement = true;
				ApplyDebugShelfTransformForInstance(selectedDebugShelfInstance, placement.position, placement.yaw, placement.scale);
				((BaseUnityPlugin)Instance).Logger.LogInfo((object)$"[ShelfDebug] Loaded saved placement for {placement.shopKey} model={text}: position={FormatVector3(placement.position)}, yaw={placement.yaw:F1}, scale={FormatVector3(placement.scale)}.");
				LogCurrentDebugShelfTransform("LoadSavedPlacement");
			}
		}
	}

	private static void SaveCurrentDebugShelfPlacement()
	{
		if (!((Object)(object)GetSelectedDebugShelfInstance() == (Object)null))
		{
			DebugShelfPlacementRecord record = BuildCurrentDebugShelfPlacementRecord("Saved");
			SaveDebugShelfPlacementRecord(record);
			debugShelfHasSavedPlacement = true;
			ExportPlacementSummary("Saved", record);
		}
	}

	private static void ExportCurrentDebugShelfPlacementToLog()
	{
		//IL_006c: 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)
		//IL_0081: 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)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)GetSelectedDebugShelfInstance() == (Object)null))
		{
			DebugShelfPlacementRecord record = new DebugShelfPlacementRecord
			{
				shopKey = BuildCurrentDebugShelfShopKey(),
				levelName = debugShelfCurrentLevelName,
				narrativeName = debugShelfCurrentNarrativeName,
				sceneName = debugShelfCurrentSceneName,
				resourcePath = debugShelfCurrentResourcePath,
				prefabName = "custom_soda_shelf",
				lastAction = "Export",
				anchorName = debugShelfAnchorName,
				anchorPosition = debugShelfAnchorPosition,
				position = debugShelfInstance.transform.position,
				scale = debugShelfInstance.transform.localScale,
				yaw = NormalizeYaw(debugShelfInstance.transform.eulerAngles.y),
				savedAtUtc = DateTime.UtcNow.ToString("O")
			};
			ExportPlacementSummary("Export", record);
		}
	}

	private static void ExportPlacementSummary(string action, DebugShelfPlacementRecord record)
	{
		//IL_006d: 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_009a: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)Instance == (Object)null) && record != null)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)$"[ShelfDebug{action}] shopKey={record.shopKey}, level={record.levelName}, narrative={record.narrativeName}, scene={record.sceneName}, resourcePath={record.resourcePath}, prefab={record.prefabName}, anchor={record.anchorName}{FormatVector3(record.anchorPosition)}, position={FormatVector3(record.position)}, yaw={record.yaw:F1}, scale={FormatVector3(record.scale)}, jsonFile={GetDebugShelfPlacementFilePath()}.");
		}
	}

	private static void LogCurrentDebugShelfTransform(string action)
	{
		if (!((Object)(object)GetSelectedDebugShelfInstance() == (Object)null) && !((Object)(object)Instance == (Object)null))
		{
			DebugShelfPlacementRecord record = BuildCurrentDebugShelfPlacementRecord(action);
			SaveCurrentDebugShelfLiveState(record);
			ExportPlacementSummary(action, record);
		}
	}

	private static string GetDebugShelfDisplayName()
	{
		if (!string.IsNullOrWhiteSpace(debugShelfCurrentNarrativeName))
		{
			return debugShelfCurrentNarrativeName;
		}
		if (!string.IsNullOrWhiteSpace(debugShelfCurrentLevelName))
		{
			return debugShelfCurrentLevelName;
		}
		return "未知商店图";
	}

	private static void CaptureDebugShelfCursorStateIfNeeded()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		if (!debugShelfCursorStateCaptured)
		{
			debugShelfPreviousCursorVisible = Cursor.visible;
			debugShelfPreviousCursorLockMode = Cursor.lockState;
			debugShelfCursorStateCaptured = true;
		}
	}

	private static void ForceDebugShelfCursorUnlocked()
	{
		CaptureDebugShelfCursorStateIfNeeded();
		Cursor.visible = true;
		Cursor.lockState = (CursorLockMode)0;
	}

	private static void RestoreDebugShelfCursorState()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		if (debugShelfCursorStateCaptured)
		{
			Cursor.visible = debugShelfPreviousCursorVisible;
			Cursor.lockState = debugShelfPreviousCursorLockMode;
			debugShelfCursorStateCaptured = false;
		}
	}

	private static void CenterDebugShelfWindow()
	{
		//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)
		float num = 460f;
		float num2 = 420f;
		float num3 = Mathf.Max(12f, ((float)Screen.width - num) * 0.5f);
		float num4 = Mathf.Max(12f, ((float)Screen.height - num2) * 0.5f);
		debugShelfWindowRect = new Rect(num3, num4, num, num2);
	}

	private static string GetDebugShelfPlacementFilePath()
	{
		return BuildDebugShelfPerLevelFilePath("debug-shelf-placement-", debugShelfSelectedModelId);
	}

	private static string GetDebugShelfLiveStateFilePath()
	{
		return BuildDebugShelfPerLevelFilePath("debug-shelf-current-", debugShelfSelectedModelId);
	}

	private static string BuildDebugShelfPerLevelFilePath(string filePrefix, string modelId)
	{
		string path = filePrefix + SanitizeDebugShelfFileKey(BuildCurrentDebugShelfShopKey()) + "__" + SanitizeDebugShelfFileKey(modelId) + ".json";
		if (Directory.Exists("D:\\donetProjects\\repo\\Zichen-Mods\\Zichen-ShopPlus"))
		{
			return Path.Combine("D:\\donetProjects\\repo\\Zichen-Mods\\Zichen-ShopPlus", path);
		}
		string text = (((Object)(object)Instance != (Object)null) ? Path.GetDirectoryName(((BaseUnityPlugin)Instance).Info.Location) : null);
		if (!string.IsNullOrWhiteSpace(text) && Directory.Exists(text))
		{
			return Path.Combine(text, path);
		}
		return Path.Combine(Paths.ConfigPath, path);
	}

	private static string SanitizeDebugShelfFileKey(string key)
	{
		if (string.IsNullOrWhiteSpace(key))
		{
			return "unknown-shop-level";
		}
		char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
		char[] array = key.ToCharArray();
		for (int i = 0; i < array.Length; i++)
		{
			char c = array[i];
			if (Array.IndexOf(invalidFileNameChars, c) >= 0)
			{
				array[i] = '_';
			}
			else if (char.IsWhiteSpace(c))
			{
				array[i] = '-';
			}
		}
		return new string(array);
	}

	private static void SaveCurrentDebugShelfLiveState(DebugShelfPlacementRecord record)
	{
		if (record == null)
		{
			return;
		}
		try
		{
			string contents = JsonUtility.ToJson((object)record, true);
			File.WriteAllText(GetDebugShelfLiveStateFilePath(), contents);
		}
		catch (Exception ex)
		{
			debugShelfLastError = "Failed to write current shelf debug JSON: " + ex.Message;
			if ((Object)(object)Instance != (Object)null)
			{
				((BaseUnityPlugin)Instance).Logger.LogWarning((object)("[ShelfDebug] " + debugShelfLastError));
			}
		}
	}

	private static DebugShelfPlacementRecord BuildCurrentDebugShelfPlacementRecord(string action)
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: 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)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		GameObject selectedDebugShelfInstance = GetSelectedDebugShelfInstance();
		return new DebugShelfPlacementRecord
		{
			shopKey = BuildCurrentDebugShelfShopKey(),
			levelName = debugShelfCurrentLevelName,
			narrativeName = debugShelfCurrentNarrativeName,
			sceneName = debugShelfCurrentSceneName,
			resourcePath = debugShelfCurrentResourcePath,
			prefabName = GetSelectedDebugShelfPrefabName(),
			lastAction = action,
			anchorName = debugShelfAnchorName,
			anchorPosition = debugShelfAnchorPosition,
			position = (((Object)(object)selectedDebugShelfInstance != (Object)null) ? selectedDebugShelfInstance.transform.position : Vector3.zero),
			scale = (((Object)(object)selectedDebugShelfInstance != (Object)null) ? selectedDebugShelfInstance.transform.localScale : Vector3.one),
			yaw = (((Object)(object)selectedDebugShelfInstance != (Object)null) ? NormalizeYaw(selectedDebugShelfInstance.transform.eulerAngles.y) : 0f),
			savedAtUtc = DateTime.UtcNow.ToString("O")
		};
	}

	private static void SaveDebugShelfPlacementRecord(DebugShelfPlacementRecord record)
	{
		if (record == null)
		{
			return;
		}
		try
		{
			string contents = JsonUtility.ToJson((object)record, true);
			File.WriteAllText(BuildDebugShelfPerLevelFilePath("debug-shelf-placement-", debugShelfSelectedModelId), contents);
		}
		catch (Exception ex)
		{
			debugShelfLastError = "Failed to write shelf debug placement JSON: " + ex.Message;
			if ((Object)(object)Instance != (Object)null)
			{
				((BaseUnityPlugin)Instance).Logger.LogWarning((object)("[ShelfDebug] " + debugShelfLastError));
			}
		}
	}

	private static bool TryGetSavedDebugShelfPlacement(string modelId, string shopKey, out DebugShelfPlacementRecord placement)
	{
		placement = null;
		string path = BuildDebugShelfPerLevelFilePath("debug-shelf-placement-", modelId);
		if (string.IsNullOrWhiteSpace(shopKey) || !File.Exists(path))
		{
			return false;
		}
		try
		{
			string text = File.ReadAllText(path);
			placement = JsonUtility.FromJson<DebugShelfPlacementRecord>(text);
			if (placement == null)
			{
				return false;
			}
			return string.Equals(placement.shopKey, shopKey, StringComparison.OrdinalIgnoreCase);
		}
		catch (Exception ex)
		{
			debugShelfLastError = "Failed to read shelf debug placement JSON: " + ex.Message;
			return false;
		}
	}

	private static void EnsureDebugShelfGuiStyles()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: 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_006f: Expected O, but got Unknown
		//IL_0079: 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)
		//IL_0099: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Expected O, but got Unknown
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		if (debugShelfHeaderStyle == null)
		{
			debugShelfHeaderStyle = new GUIStyle(GUI.skin.label)
			{
				fontSize = 14,
				fontStyle = (FontStyle)1,
				wordWrap = true
			};
			debugShelfHeaderStyle.normal.textColor = Color.white;
		}
		if (debugShelfInfoStyle == null)
		{
			debugShelfInfoStyle = new GUIStyle(GUI.skin.label)
			{
				fontSize = 12,
				wordWrap = true
			};
			debugShelfInfoStyle.normal.textColor = Color.white;
		}
		if (debugShelfBadgeStyle == null)
		{
			debugShelfBadgeStyle = new GUIStyle(GUI.skin.label)
			{
				alignment = (TextAnchor)4,
				fontSize = 13,
				fontStyle = (FontStyle)1
			};
			debugShelfBadgeStyle.normal.textColor = Color.black;
		}
	}

	private bool TryGetDebugShelfLabelRect(out Rect rect)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: 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)
		//IL_008a: 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_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		rect = default(Rect);
		if ((Object)(object)debugShelfInstance == (Object)null || !SemiFunc.RunIsShop())
		{
			return false;
		}
		Camera val = (((Object)(object)GameDirector.instance != (Object)null) ? GameDirector.instance.MainCamera : Camera.main);
		if ((Object)(object)val == (Object)null)
		{
			return false;
		}
		Renderer componentInChildren = debugShelfInstance.GetComponentInChildren<Renderer>();
		Vector3 val2;
		if (!((Object)(object)componentInChildren != (Object)null))
		{
			val2 = debugShelfInstance.transform.position + Vector3.up * 2f;
		}
		else
		{
			Bounds bounds = componentInChildren.bounds;
			Vector3 center = ((Bounds)(ref bounds)).center;
			Vector3 up = Vector3.up;
			bounds = componentInChildren.bounds;
			val2 = center + up * (((Bounds)(ref bounds)).extents.y + 0.25f);
		}
		Vector3 val3 = val2;
		Vector3 val4 = val.WorldToScreenPoint(val3);
		if (val4.z <= 0f)
		{
			return false;
		}
		rect = new Rect(val4.x - 86f, (float)Screen.height - val4.y - 22f, 172f, 24f);
		return true;
	}

	private void DrawDebugShelfWorldBadge()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		EnsureDebugShelfGuiStyles();
		if (TryGetDebugShelfLabelRect(out var rect))
		{
			Color color = GUI.color;
			GUI.color = new Color(1f, 0.9f, 0.2f, 0.92f);
			GUI.DrawTexture(rect, (Texture)(object)Texture2D.whiteTexture);
			GUI.color = color;
			GUI.Label(rect, $"调试货架 [{(object)(KeyCode)282}]", debugShelfBadgeStyle);
		}
	}

	private void ApplyHarmonyPatches()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		harmony = new Harmony("zichen.shopplus");
		PatchPostfix(typeof(ShopManager), "GetAllItemVolumesInScene", "ShopManagerGetAllVolumesPostfix");
		PatchPrefix(typeof(ShopManager), "GetAllItemsFromStatsManager", "ShopManagerGetAllItemsPrefix");
		PatchPostfix(typeof(ShopManager), "GetAllItemsFromStatsManager", "ShopManagerGetAllItemsPostfix");
		PatchPrefix(typeof(ShopManager), "ShopInitialize", "ShopManagerShopInitializePrefix");
		PatchPostfix(typeof(ShopManager), "ShopInitialize", "ShopManagerShopInitializePostfix");
		PatchPostfix(typeof(ItemAttributes), "ShowingInfo", "ItemAttributesShowingInfoPostfix");
		PatchPostfix(typeof(ExtractionPoint), "CancelExtraction", "ExtractionPointCancelExtractionPostfix");
		PatchPostfix(typeof(WorldSpaceUIValue), "Show", "WorldSpaceUIValueShowPhysPostfix", new Type[4]
		{
			typeof(PhysGrabObject),
			typeof(int),
			typeof(bool),
			typeof(Vector3)
		});
		((BaseUnityPlugin)this).Logger.LogInfo((object)"ShopPlus Harmony patches applied.");
	}

	private void PatchPrefix(Type originalType, string originalName, string patchName)
	{
		PatchMethod(originalType, originalName, patchName, prefix: true, null);
	}

	private void PatchPostfix(Type originalType, string originalName, string patchName)
	{
		PatchMethod(originalType, originalName, patchName, prefix: false, null);
	}

	private void PatchPostfix(Type originalType, string originalName, string patchName, Type[] argumentTypes)
	{
		PatchMethod(originalType, originalName, patchName, prefix: false, argumentTypes);
	}

	private void PatchMethod(Type originalType, string originalName, string patchName, bool prefix, Type[] argumentTypes)
	{
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Expected O, but got Unknown
		MethodInfo methodInfo = ((argumentTypes == null) ? AccessTools.Method(originalType, originalName, (Type[])null, (Type[])null) : AccessTools.Method(originalType, originalName, argumentTypes, (Type[])null));
		MethodInfo methodInfo2 = AccessTools.Method(typeof(ShopPlusPlugin), patchName, (Type[])null, (Type[])null);
		if (methodInfo == null || methodInfo2 == null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Failed to find Harmony patch target: " + originalType?.Name + "." + originalName + " -> " + patchName));
		}
		else
		{
			HarmonyMethod val = new HarmonyMethod(methodInfo2);
			if (prefix)
			{
				harmony.Patch((MethodBase)methodInfo, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			else
			{
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}
	}

	private static void ShopManagerGetAllItemsPostfix(ShopManager __instance)
	{
		if (!ShouldRunMasterShopLogic())
		{
			return;
		}
		RestoreSpoofedShopCurrency(__instance);
		ExpandShopSpawnTargetsToCurrentPools(__instance);
		int configuredItemSpawnMultiplier = GetConfiguredItemSpawnMultiplier();
		if (configuredItemSpawnMultiplier > 1)
		{
			MultiplyIntField(ShopManagerItemSpawnTargetAmountField, __instance, configuredItemSpawnMultiplier);
			MultiplyIntField(ShopManagerItemConsumablesAmountField, __instance, configuredItemSpawnMultiplier);
			MultiplyIntField(ShopManagerItemUpgradesAmountField, __instance, configuredItemSpawnMultiplier);
			MultiplyIntField(ShopManagerItemHealthPacksAmountField, __instance, configuredItemSpawnMultiplier);
			MultiplyItemList(ShopManagerPotentialItemsField, __instance, configuredItemSpawnMultiplier);
			MultiplyItemList(ShopManagerPotentialItemConsumablesField, __instance, configuredItemSpawnMultiplier);
			MultiplyItemList(ShopManagerPotentialItemUpgradesField, __instance, configuredItemSpawnMultiplier);
			MultiplyItemList(ShopManagerPotentialItemHealthPacksField, __instance, configuredItemSpawnMultiplier);
			ShopPlusPlugin instance = Instance;
			if (instance != null)
			{
				((BaseUnityPlugin)instance).Logger.LogInfo((object)$"[ItemMultiplier] Applied {configuredItemSpawnMultiplier}x item spawn multiplier.");
			}
		}
		int num = EnforceSingleSpecialShopItemAcrossShopPools(__instance);
		if (num > 0)
		{
			ShopPlusPlugin instance2 = Instance;
			if (instance2 != null)
			{
				((BaseUnityPlugin)instance2).Logger.LogInfo((object)$"[ItemLimiter] Replaced/removed {num} extra cart/vehicle candidate(s); ShopPlus keeps max 1 big cart, 1 pocket cart, and 1 of each drivable vehicle.");
			}
		}
	}

	private static void ShopManagerGetAllItemsPrefix()
	{
		if (IsStaticModEnabled() && SemiFunc.RunIsShop())
		{
			Instance?.ReloadRuntimeConfigForNextShop();
			SpoofShopCurrencyForPoolGeneration();
		}
	}

	private static void SpoofShopCurrencyForPoolGeneration()
	{
		if ((Object)(object)ShopManager.instance == (Object)null || SemiFunc.IsNotMasterClient())
		{
			originalShopCurrency = -1;
			return;
		}
		originalShopCurrency = ShopManager.instance.totalCurrency;
		ShopManager.instance.totalCurrency = 999999;
	}

	private static void RestoreSpoofedShopCurrency(ShopManager shopManager)
	{
		if (!((Object)(object)shopManager == (Object)null) && originalShopCurrency >= 0)
		{
			shopManager.totalCurrency = originalShopCurrency;
			originalShopCurrency = -1;
		}
	}

	private static void ExpandShopSpawnTargetsToCurrentPools(ShopManager shopManager)
	{
		if (!((Object)(object)shopManager == (Object)null))
		{
			if (ShopManagerPotentialItemConsumablesField?.GetValue(shopManager) is IList list)
			{
				shopManager.itemConsumablesAmount = list.Count;
			}
			if (ShopManagerPotentialItemUpgradesField?.GetValue(shopManager) is IList list2)
			{
				shopManager.itemUpgradesAmount = list2.Count;
			}
			if (ShopManagerPotentialItemHealthPacksField?.GetValue(shopManager) is IList list3)
			{
				shopManager.itemHealthPacksAmount = list3.Count;
			}
			if (ShopManagerPotentialItemsField?.GetValue(shopManager) is IList list4)
			{
				shopManager.itemSpawnTargetAmount = list4.Count;
			}
		}
	}

	private static void MultiplyIntField(FieldInfo field, ShopManager shopManager, int multiplier)
	{
		if (field == null || (Object)(object)shopManager == (Object)null)
		{
			return;
		}
		object value = field.GetValue(shopManager);
		if (value is int)
		{
			int num = (int)value;
			if (num > 0)
			{
				long num2 = (long)num * (long)multiplier;
				field.SetValue(shopManager, (int)((num2 > int.MaxValue) ? int.MaxValue : num2));
			}
		}
	}

	private static void MultiplyItemList(FieldInfo field, ShopManager shopManager, int multiplier)
	{
		if (field == null || (Object)(object)shopManager == (Object)null || !(field.GetValue(shopManager) is IList list) || list.Count == 0)
		{
			return;
		}
		int count = list.Count;
		for (int i = 1; i < multiplier; i++)
		{
			for (int j = 0; j < count; j++)
			{
				list.Add(list[j]);
			}
		}
	}

	private static int EnforceSingleSpecialShopItemAcrossShopPools(ShopManager shopManager)
	{
		HashSet<string> allowedItemKeys = new HashSet<string>();
		return 0 + LimitSpecialShopItemEntriesInList(ShopManagerPotentialItemsField, shopManager, allowedItemKeys) + LimitSpecialShopItemEntriesInList(ShopManagerPotentialItemConsumablesField, shopManager, allowedItemKeys) + LimitSpecialShopItemEntriesInList(ShopManagerPotentialItemUpgradesField, shopManager, allowedItemKeys) + LimitSpecialShopItemEntriesInList(ShopManagerPotentialItemHealthPacksField, shopManager, allowedItemKeys) + LimitSpecialShopItemEntriesInSecretLists(ShopManagerPotentialSecretItemsField, shopManager, allowedItemKeys);
	}

	private static int LimitSpecialShopItemEntriesInList(FieldInfo field, ShopManager shopManager, HashSet<string> allowedItemKeys)
	{
		if (field == null || (Object)(object)shopManager == (Object)null)
		{
			return 0;
		}
		if (!(field.GetValue(shopManager) is IList list) || list.Count == 0)
		{
			return 0;
		}
		return LimitSpecialShopItemEntriesInIList(list, allowedItemKeys);
	}

	private static int LimitSpecialShopItemEntriesInSecretLists(FieldInfo field, ShopManager shopManager, HashSet<string> allowedItemKeys)
	{
		if (field == null || (Object)(object)shopManager == (Object)null)
		{
			return 0;
		}
		if (!(field.GetValue(shopManager) is IDictionary dictionary) || dictionary.Count == 0)
		{
			return 0;
		}
		int num = 0;
		foreach (DictionaryEntry item in dictionary)
		{
			if (item.Value is IList items)
			{
				num += LimitSpecialShopItemEntriesInIList(items, allowedItemKeys);
			}
		}
		return num;
	}

	private static int LimitSpecialShopItemEntriesInIList(IList items, HashSet<string> allowedItemKeys)
	{
		if (items == null || items.Count == 0)
		{
			return 0;
		}
		List<Item> replacementCandidates = BuildLimitedItemReplacementCandidates(items);
		int num = 0;
		for (int num2 = items.Count - 1; num2 >= 0; num2--)
		{
			object? obj = items[num2];
			Item val = (Item)((obj is Item) ? obj : null);
			if (val != null)
			{
				string specialShopItemLimitKey = GetSpecialShopItemLimitKey(val);
				if (!string.IsNullOrEmpty(specialShopItemLimitKey) && !allowedItemKeys.Add(specialShopItemLimitKey))
				{
					Item randomLimitedItemReplacement = GetRandomLimitedItemReplacement(replacementCandidates);
					if ((Object)(object)randomLimitedItemReplacement != (Object)null)
					{
						items[num2] = randomLimitedItemReplacement;
					}
					else
					{
						items.RemoveAt(num2);
					}
					num++;
				}
			}
		}
		return num;
	}

	private static List<Item> BuildLimitedItemReplacementCandidates(IList items)
	{
		List<Item> list = limitedItemReplacementCandidatesBuffer;
		list.Clear();
		if (items == null)
		{
			return list;
		}
		for (int i = 0; i < items.Count; i++)
		{
			object? obj = items[i];
			Item val = (Item)((obj is Item) ? obj : null);
			if (val != null && string.IsNullOrEmpty(GetSpecialShopItemLimitKey(val)))
			{
				list.Add(val);
			}
		}
		return list;
	}

	private static Item GetRandomLimitedItemReplacement(List<Item> replacementCandidates)
	{
		if (replacementCandidates == null || replacementCandidates.Count == 0)
		{
			return null;
		}
		return replacementCandidates[Random.Range(0, replacementCandidates.Count)];
	}

	private static string GetSpecialShopItemLimitKey(Item item)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Invalid comparison between Unknown and I4
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Invalid comparison between Unknown and I4
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Invalid comparison between Unknown and I4
		if ((Object)(object)item == (Object)null)
		{
			return string.Empty;
		}
		if ((int)item.itemType == 2)
		{
			return "cart:big";
		}
		if ((int)item.itemType == 12)
		{
			return "cart:pocket";
		}
		if ((int)item.itemType != 14)
		{
			return string.Empty;
		}
		return "vehicle:" + GetItemStableKey(item);
	}

	private static string GetItemStableKey(Item item)
	{
		if ((Object)(object)item == (Object)null)
		{
			return string.Empty;
		}
		if (item.prefab != null && !string.IsNullOrEmpty(item.prefab.ResourcePath))
		{
			return item.prefab.ResourcePath;
		}
		if (!string.IsNullOrEmpty(((Object)item).name))
		{
			return ((Object)item).name;
		}
		if (!string.IsNullOrEmpty(item.itemName))
		{
			return item.itemName;
		}
		return string.Empty;
	}

	private static string GetItemLogName(Item item)
	{
		if ((Object)(object)item == (Object)null)
		{
			return "unknown";
		}
		if (!string.IsNullOrEmpty(item.itemName) && !string.IsNullOrEmpty(((Object)item).name))
		{
			return item.itemName + " (" + ((Object)item).name + ")";
		}
		if (!string.IsNullOrEmpty(item.itemName))
		{
			return item.itemName;
		}
		return ((Object)item).name;
	}

	private static void ShopManagerGetAllVolumesPostfix(ShopManager __instance)
	{
		if (ShouldRunMasterShopLogic() && itemVolumeCollectionLogFrame != Time.frameCount && ShopManagerItemVolumesField?.GetValue(__instance) is IList list)
		{
			itemVolumeCollectionLogFrame = Time.frameCount;
			LogGroundPack($"ShopManager collected {list.Count} item volume(s); ShopPlus generated {groundSpawnVolumeObjects.Count} ground-pack root object(s).");
		}
	}

	private static void ShopManagerShopInitializePrefix()
	{
		Instance?.ReloadRuntimeConfigForNextShop();
		CleanGroundSpawnVolumes();
		Instance?.ResetFreeItemSelectionForShopChange();
		ApplyShopPlusItemLimitOverrides();
		if (IsStaticModEnabled() && SemiFunc.RunIsShop())
		{
			ShopPlusPlugin instance = Instance;
			if (instance != null)
			{
				((BaseUnityPlugin)instance).Logger.LogInfo((object)$"[Config] Shop settings snapshot: itemMultiplier={GetConfiguredItemSpawnMultiplier()}, groundPackEnabled={IsGroundPackEnabled()}, groundPackCount={GetConfiguredGroundPackCount()}, freeItemEnabled={IsStaticRandomFreeItemEnabled()}.");
			}
			if (SemiFunc.IsNotMasterClient())
			{
				LogGroundPack("Shop logic skipped on non-master client; waiting for host-generated shop items.");
			}
			else if (!IsGroundPackEnabled())
			{
				LogGroundPack("Ground pack skipped: disabled by config.");
			}
			else
			{
				CreateGroundItemPacks();
			}
		}
	}

	private static void CreateGroundItemPacks()
	{
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: 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_015a: 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_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02df: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0319: Unknown result type (might be due to invalid IL or missing references)
		//IL_031e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0339: Unknown result type (might be due to invalid IL or missing references)
		//IL_0355: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0425: Unknown result type (might be due to invalid IL or missing references)
		/