Decompiled source of CosmeticsTools v1.0.1

Zichen-CosmeticsTools-1.0.1.dll

Decompiled 2 weeks ago
using System;
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 UnityEngine;
using UnityEngine.InputSystem;

[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-CosmeticsTools-1.0.1")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+35e7aca28356bf4254c5e9081ea522924e9cf1b3")]
[assembly: AssemblyProduct("Zichen-CosmeticsTools-1.0.1")]
[assembly: AssemblyTitle("Zichen-CosmeticsTools-1.0.1")]
[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;
		}
	}
}
internal sealed class ConfigurationManagerAttributes
{
	public int? Order;

	public bool? ReadOnly;

	public bool? Browsable;
}
namespace Zichen_CosmeticsTools
{
	public enum DisplayLanguage
	{
		中文,
		English
	}
	[BepInPlugin("zichen.cosmeticstools", "CosmeticsTools", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		private sealed class CosmeticState
		{
			public List<int> Unlocks;

			public List<int> History;

			public List<int> Equipped;

			public List<List<int>> CosmeticPresets;

			public List<List<int>> ColorPresets;

			public int[] ColorsEquipped;
		}

		private sealed class CosmeticRow
		{
			public int Index;

			public int Rarity;

			public CosmeticType Type;

			public string SortName;

			public string DisplayName;

			public string SearchText;
		}

		private sealed class CategoryRow
		{
			public CosmeticCategoryAsset Asset;

			public List<CosmeticType> Types;

			public string Name;

			public int Total;

			public int Unlocked;
		}

		private sealed class SectionRow
		{
			public CosmeticType Type;

			public string Name;

			public List<CosmeticRow> Rows;

			public int Total;

			public int Unlocked;
		}

		private sealed class DisplayRow
		{
			public SectionRow Section;

			public CosmeticRow Row;

			public float Height;
		}

		private sealed class CompatibilityReport
		{
			private readonly List<string> affected = new List<string>();

			private readonly List<string> details = new List<string>();

			public bool CoreEditAvailable { get; set; } = true;


			public bool VisualRefreshAvailable { get; set; } = true;


			public bool TokensAvailable { get; set; } = true;


			public bool HasIssues => affected.Count > 0;

			public static CompatibilityReport CreateHealthy()
			{
				return new CompatibilityReport();
			}

			public static CompatibilityReport Build()
			{
				CompatibilityReport compatibilityReport = new CompatibilityReport();
				if ((1u & (RequireField(F_Unlocks, "MetaManager.cosmeticUnlocks", compatibilityReport, "装饰解锁编辑") ? 1u : 0u) & (RequireField(F_History, "MetaManager.cosmeticHistory", compatibilityReport, "装饰历史编辑") ? 1u : 0u) & (RequireField(F_Equipped, "MetaManager.cosmeticEquipped", compatibilityReport, "装饰已装备清理") ? 1u : 0u) & (RequireField(F_Presets, "MetaManager.cosmeticPresets", compatibilityReport, "装饰预设清理") ? 1u : 0u) & (RequireField(F_ColorPresets, "MetaManager.colorPresets", compatibilityReport, "颜色预设清理") ? 1u : 0u) & (RequireField(F_ColorsEquipped, "MetaManager.colorsEquipped", compatibilityReport, "颜色重置") ? 1u : 0u) & (RequireField(F_SaveReady, "MetaManager.saveReady", compatibilityReport, "装饰存档就绪检测") ? 1u : 0u) & (RequireMethod(M_MetaSave, "MetaManager.Save()", compatibilityReport, "存档写回") ? 1u : 0u)) == 0)
				{
					compatibilityReport.CoreEditAvailable = false;
				}
				if (!RequireField(F_Tokens, "MetaManager.cosmeticTokens", compatibilityReport, "装饰币编辑"))
				{
					compatibilityReport.TokensAvailable = false;
				}
				if ((1u & (RequireMethod(M_CosmeticPreviewSet, "MetaManager.CosmeticPreviewSet(bool)", compatibilityReport, "保存后视觉刷新") ? 1u : 0u) & (RequireMethod(M_CosmeticPlayerUpdateLocal, "MetaManager.CosmeticPlayerUpdateLocal(bool, bool)", compatibilityReport, "保存后视觉刷新") ? 1u : 0u)) == 0)
				{
					compatibilityReport.VisualRefreshAvailable = false;
				}
				return compatibilityReport;
			}

			public void AddPatchFailure(string feature, string patchTarget, string message)
			{
				if (!affected.Contains(feature))
				{
					affected.Add(feature);
				}
				details.Add("Patch failed: " + patchTarget + " for feature '" + feature + "': " + message);
			}

			public string BuildLogMessage()
			{
				if (!HasIssues)
				{
					return "Compatibility self-check passed.";
				}
				return string.Format("Compatibility self-check found {0} affected feature(s): {1}", affected.Count, string.Join(", ", affected));
			}

			public IEnumerable<string> GetDetailMessages()
			{
				return details;
			}

			private static bool RequireField(FieldInfo field, string apiName, CompatibilityReport r, string feature)
			{
				if (field != null)
				{
					return true;
				}
				if (!r.affected.Contains(feature))
				{
					r.affected.Add(feature);
				}
				r.details.Add("Missing field: " + apiName + " (feature '" + feature + "')");
				return false;
			}

			private static bool RequireMethod(MethodInfo method, string apiName, CompatibilityReport r, string feature)
			{
				if (method != null)
				{
					return true;
				}
				if (!r.affected.Contains(feature))
				{
					r.affected.Add(feature);
				}
				r.details.Add("Missing method: " + apiName + " (feature '" + feature + "')");
				return false;
			}
		}

		public const string PluginGuid = "zichen.cosmeticstools";

		public const string PluginName = "CosmeticsTools";

		public const string PluginVersion = "1.0.1";

		private const int OpenInputKeyValue = 330;

		private const float Pad = 16f;

		private const float RowH = 30f;

		private const float CatBtnH = 32f;

		private const float SectionH = 68f;

		private const int RarityCount = 4;

		private const int GuiWindowId = 33001;

		private static readonly InputKey OpenInputKey = (InputKey)330;

		private static readonly FieldInfo F_Unlocks = AccessTools.Field(typeof(MetaManager), "cosmeticUnlocks");

		private static readonly FieldInfo F_History = AccessTools.Field(typeof(MetaManager), "cosmeticHistory");

		private static readonly FieldInfo F_Equipped = AccessTools.Field(typeof(MetaManager), "cosmeticEquipped");

		private static readonly FieldInfo F_Presets = AccessTools.Field(typeof(MetaManager), "cosmeticPresets");

		private static readonly FieldInfo F_ColorPresets = AccessTools.Field(typeof(MetaManager), "colorPresets");

		private static readonly FieldInfo F_ColorsEquipped = AccessTools.Field(typeof(MetaManager), "colorsEquipped");

		private static readonly FieldInfo F_Tokens = AccessTools.Field(typeof(MetaManager), "cosmeticTokens");

		private static readonly FieldInfo F_SaveReady = AccessTools.Field(typeof(MetaManager), "saveReady");

		private static readonly MethodInfo M_MetaSave = AccessTools.Method(typeof(MetaManager), "Save", (Type[])null, (Type[])null);

		private static readonly MethodInfo M_CosmeticPreviewSet = AccessTools.Method(typeof(MetaManager), "CosmeticPreviewSet", new Type[1] { typeof(bool) }, (Type[])null);

		private static readonly MethodInfo M_CosmeticPlayerUpdateLocal = AccessTools.Method(typeof(MetaManager), "CosmeticPlayerUpdateLocal", new Type[2]
		{
			typeof(bool),
			typeof(bool)
		}, (Type[])null);

		private static readonly MethodInfo M_CursorMgrUpdate = AccessTools.Method(typeof(CursorManager), "Update", (Type[])null, (Type[])null);

		private static readonly FieldInfo F_CursorUnlockTimer = AccessTools.Field(typeof(CursorManager), "unlockTimer");

		private static readonly MethodInfo M_InputMgrInit = AccessTools.Method(typeof(InputManager), "InitializeInputs", (Type[])null, (Type[])null);

		private static readonly MethodInfo M_PlayerCtrlStart = AccessTools.Method(typeof(PlayerController), "Start", (Type[])null, (Type[])null);

		private static CompatibilityReport _compat = CompatibilityReport.CreateHealthy();

		private static readonly string[] RarityNames = new string[4] { "普通", "稀有", "珍贵", "超稀有" };

		private static readonly string[] RarityNamesEn = new string[4] { "Common", "Uncommon", "Rare", "UltraRare" };

		private static readonly Color[] RarityColors = (Color[])(object)new Color[4]
		{
			new Color(0.3f, 0.8f, 0.3f),
			new Color(0.3f, 0.5f, 1f),
			new Color(0.7f, 0.3f, 0.9f),
			new Color(1f, 0.8f, 0.2f)
		};

		private static readonly string[] AvailableKeybinds = new string[55]
		{
			"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
			"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
			"U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3",
			"4", "5", "6", "7", "8", "9", "F1", "F2", "F3", "F4",
			"F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "Space", "Enter",
			"Tab", "LeftShift", "RightShift", "LeftControl", "RightControl"
		};

		private static Plugin _instance;

		private Harmony _harmony;

		private static ConfigEntry<bool> _cfgModEnabled;

		private ConfigEntry<string> _openKey;

		private static ConfigEntry<DisplayLanguage> _cfgLanguage;

		private static string _lastAppliedOpenKey;

		private static InputManager _registeredInputManager;

		private static Dictionary<InputKey, InputAction> _registeredInputActions;

		private static bool _inputRegistered;

		private bool _windowOpen;

		private bool _windowCentered;

		private Rect _windowRect = new Rect(0f, 0f, 860f, 700f);

		private Vector2 _scroll;

		private string _searchText = string.Empty;

		private string _status = "按 F5 打开或关闭装饰工具箱。";

		private readonly string[] _tokenTexts = new string[4] { "0", "0", "0", "0" };

		private bool _useChinese = true;

		private bool _stylesInit;

		private GUIStyle _sWindow;

		private GUIStyle _sTitle;

		private GUIStyle _sLabel;

		private GUIStyle _sStatus;

		private GUIStyle _sBtnGreen;

		private GUIStyle _sBtnRed;

		private GUIStyle _sBtnNormal;

		private GUIStyle _sBtnCatSel;

		private GUIStyle _sBtnCat;

		private GUIStyle _sSection;

		private GUIStyle _sSectionLabel;

		private GUIStyle _sToggleOn;

		private GUIStyle _sToggleOff;

		private GUIStyle _sTextField;

		private Texture2D _texDark;

		private Texture2D _texMid;

		private Texture2D _texLight;

		private Texture2D _texGreen;

		private Texture2D _texRed;

		private Texture2D _texAccent;

		private Texture2D _texSection;

		private readonly List<CosmeticRow> _allRows = new List<CosmeticRow>();

		private readonly List<CategoryRow> _categories = new List<CategoryRow>();

		private readonly List<SectionRow> _sections = new List<SectionRow>();

		private readonly List<DisplayRow> _display = new List<DisplayRow>();

		private readonly HashSet<int> _unlocked = new HashSet<int>();

		private readonly List<CosmeticRow> _matchBuf = new List<CosmeticRow>();

		private MetaManager _cachedMeta;

		private int _cachedCount = -1;

		private bool _dirty = true;

		private string _appliedSearch = string.Empty;

		private CosmeticCategoryAsset _selectedCat;

		private float _contentH;

		private int _visibleRows;

		private int _visibleSections;

		private bool _loggedOnce;

		private static readonly Dictionary<string, string> CosmeticNameMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
		{
			{ "2000s Beanie", "2000年代毛线帽" },
			{ "Anime Robot Ears", "动漫机器人耳" },
			{ "Antennas", "天线" },
			{ "Aratal Uniform", "Aratal 制服" },
			{ "Arctic", "北极" },
			{ "Arctic Explorer", "北极探险者" },
			{ "Armor Leg", "护腿" },
			{ "Armpad", "护臂" },
			{ "Arrow", "箭" },
			{ "Banana", "香蕉" },
			{ "Banana Peel", "香蕉皮" },
			{ "Bandages", "绷带" },
			{ "Bandaid", "创可贴" },
			{ "Bandana Brawler", "斗士头巾" },
			{ "Bandana Coloorful", "彩色头巾" },
			{ "Bandana Tintable", "可染色头巾" },
			{ "Barrel", "木桶" },
			{ "Basic Shirt", "基础衬衫" },
			{ "Basic Side Tech", "基础侧科技" },
			{ "Bat ears", "蝙蝠耳" },
			{ "Beak", "鸟喙" },
			{ "Beanie", "毛线帽" },
			{ "Beard", "胡子" },
			{ "Beret", "贝雷帽" },
			{ "Big Boot", "大靴子" },
			{ "Big Round Glasses", "大圆框眼镜" },
			{ "Bikini", "比基尼" },
			{ "Bølle", "Bølle" },
			{ "Bow", "蝴蝶结" },
			{ "Branch Antlers", "树枝鹿角" },
			{ "Broken", "破损" },
			{ "Broken Cords", "破损绳索" },
			{ "Burger", "汉堡" },
			{ "Camo", "迷彩" },
			{ "Cap", "鸭舌帽" },
			{ "Checkers", "棋盘格" },
			{ "Cheese Semibot", "奶酪半机器人" },
			{ "Chunky grabber", "粗壮抓取器" },
			{ "Chunky Tech", "粗壮科技" },
			{ "Clerk Glasses", "店员眼镜" },
			{ "Clown nose", "小丑鼻" },
			{ "Complex grabber", "复杂抓取器" },
			{ "Cone", "圆锥" },
			{ "Constructor", "建造者" },
			{ "Cosmetic Category - Arms", "装饰分类-手臂" },
			{ "Cosmetic Category - Body", "装饰分类-身体" },
			{ "Cosmetic Category - Head", "装饰分类-头部" },
			{ "Cosmetic Category - Legs", "装饰分类-腿部" },
			{ "Cracks", "裂纹" },
			{ "Crest", "羽冠" },
			{ "Crown", "皇冠" },
			{ "Curly Bob", "卷发波波头" },
			{ "Curly Bun", "卷发丸子头" },
			{ "Damaged", "破损" },
			{ "Danger Tape", "警戒带" },
			{ "Domino Mask", "多米诺面具" },
			{ "Dreads", "脏辫" },
			{ "Ear Muffs", "耳罩" },
			{ "Elf ears", "精灵耳" },
			{ "Elite", "精英" },
			{ "Emo Boot", "摇滚靴" },
			{ "Expert Goggles", "专家护目镜" },
			{ "Eyebrow Piercing", "眉毛穿孔" },
			{ "Eyebrows", "眉毛" },
			{ "Eyebrows Bushy", "浓密眉毛" },
			{ "Eyebrows Huge", "巨大眉毛" },
			{ "Eyebrows Mono", "一字眉" },
			{ "Eyebrows Thick Angry", "粗眉怒" },
			{ "Eyebrows Thick Flat", "粗眉平" },
			{ "Eyebrows Thick Short", "粗眉短" },
			{ "Eyebrows Thick Surprised", "粗眉惊" },
			{ "Eyebrows Thick Worried", "粗眉忧" },
			{ "Eyebrows Thin Angry", "细眉怒" },
			{ "Eyebrows Thin Flat", "细眉平" },
			{ "Eyebrows Thin Short", "细眉短" },
			{ "Eyebrows Thin Surprised", "细眉惊" },
			{ "Eyebrows Thin Worried", "细眉忧" },
			{ "Eyelash", "睫毛" },
			{ "Eyelash Separate", "分离睫毛" },
			{ "Eyepatch", "眼罩" },
			{ "Face Jewel", "脸部宝石" },
			{ "Formal Shirt", "正装衬衫" },
			{ "Glasses 1", "眼镜 1" },
			{ "Golden Semibot", "金色半机器人" },
			{ "Graffiti", "涂鸦" },
			{ "Green house", "温室" },
			{ "Grime Dirt", "污渍" },
			{ "Hair", "头发" },
			{ "Hair Emo", "摇滚发型" },
			{ "Hair Horseshoe", "马蹄发型" },
			{ "Hair Medium 01", "中长发 01" },
			{ "Hair Mohawk", "莫西干" },
			{ "Hair Mohawk Spikes", "莫西干尖刺" },
			{ "Hair Mullet 01", "鲻鱼头 01" },
			{ "Hair Mullet 02", "鲻鱼头 02" },
			{ "Hair Old Lob", "老式波波头" },
			{ "Hair Pageboy", "童花头" },
			{ "Hair Pigtails 01", "双马尾 01" },
			{ "Hair Pigtails 02", "双马尾 02" },
			{ "Hair Pompadour", "飞机头" },
			{ "Hair Posh Lad", "时髦少年" },
			{ "Hair Short 01", "短发 01" },
			{ "Half Dome", "半球" },
			{ "Hardhat", "安全帽" },
			{ "Headphones", "耳机" },
			{ "Heavy", "重型" },
			{ "Heel", "高跟鞋" },
			{ "Hoodie", "连帽衫" },
			{ "Hoodie Sleeve", "连帽袖" },
			{ "Internals", "内脏" },
			{ "Jacket", "夹克" },
			{ "Jacket Sleeve", "夹克袖" },
			{ "Jeans", "牛仔裤" },
			{ "Kiwi", "猕猴桃" },
			{ "Kneepad", "护膝" },
			{ "Knit Sleeve", "针织袖" },
			{ "Leather Mask", "皮革面具" },
			{ "Lip Piercing", "唇钉" },
			{ "Lipstick", "口红" },
			{ "Logistics", "后勤" },
			{ "Long Sleeve", "长袖" },
			{ "Long Sleeve Ruffle Tip", "长袖荷叶边" },
			{ "Low Headphones", "低位耳机" },
			{ "Magic Gear", "魔法装备" },
			{ "Mailer Hat", "邮差帽" },
			{ "Mask", "面具" },
			{ "Mechanic", "机械师" },
			{ "Medic", "医护" },
			{ "Messenger", "信使" },
			{ "Monkey", "猴子" },
			{ "Monkey shirt", "猴子衬衫" },
			{ "Monocle", "单片眼镜" },
			{ "Moose Antlers", "驼鹿角" },
			{ "Moose Ears", "驼鹿耳" },
			{ "Moss", "苔藓" },
			{ "Moustache Huge", "大胡子" },
			{ "Moustache Petite Handlebar", "小翘胡" },
			{ "Moustache Thin", "细胡子" },
			{ "Moustache Toothbrush", "牙刷胡" },
			{ "Mushroom", "蘑菇" },
			{ "Mushroom Attire", "蘑菇装" },
			{ "Mushrooms", "蘑菇群" },
			{ "Neck Ruffle", "颈部褶饰" },
			{ "Network", "网络" },
			{ "Networker", "网络员" },
			{ "Night Vision", "夜视" },
			{ "Paint Splats", "颜料溅" },
			{ "Pant Leg Long", "长裤腿" },
			{ "Pant Leg Short", "短裤腿" },
			{ "Pant Leg Short Ruffle", "短裤褶腿" },
			{ "Paper Bag", "纸袋" },
			{ "Pencil", "铅笔" },
			{ "Petals", "花瓣" },
			{ "Pilot Glasses", "飞行员眼镜" },
			{ "Plant Top", "植物上装" },
			{ "Plasma", "等离子" },
			{ "Polka", "波点" },
			{ "Puff Sleeve", "泡泡袖" },
			{ "Puff Sleeve Long", "长泡泡袖" },
			{ "Puffy Skirt", "蓬蓬裙" },
			{ "Robo arm", "机械臂" },
			{ "Robo leg 2", "机械腿 2" },
			{ "Robo Part", "机器零件" },
			{ "Robot Stick", "机器人杆" },
			{ "Robot sticks", "机器人杆群" },
			{ "Royal Boot", "皇家靴" },
			{ "Royal Shirt", "皇家衬衫" },
			{ "Royal Sleeve", "皇家袖" },
			{ "Ruffle", "荷叶边" },
			{ "Ruffle Shirt", "荷叶边衬衫" },
			{ "Ruffle Sleeve", "荷叶袖" },
			{ "Ruffle Sleeve Long", "长荷叶袖" },
			{ "Rusty", "生锈" },
			{ "Scifi Lines", "科幻线条" },
			{ "Scout", "侦察兵" },
			{ "Screw Loose", "螺丝松" },
			{ "Shades", "墨镜" },
			{ "Short Afro", "短爆炸头" },
			{ "Short Sleeve", "短袖" },
			{ "Short Sleeve Striped", "条纹短袖" },
			{ "Skeleton", "骷髅" },
			{ "Skeleton Armor", "骷髅护甲" },
			{ "Skeleton grabber", "骷髅抓取器" },
			{ "Skeleton Teeth", "骷髅牙" },
			{ "Skinny", "纤细" },
			{ "Skirt", "裙子" },
			{ "Skull belt", "骷髅腰带" },
			{ "Sleepless", "失眠" },
			{ "Sneaker", "运动鞋" },
			{ "Snow Hat", "雪帽" },
			{ "Sock", "袜子" },
			{ "Soldier", "士兵" },
			{ "Soot Eyes", "煤灰眼" },
			{ "Sparkly Semibot", "闪亮半机器人" },
			{ "Spike band", "尖刺带" },
			{ "Sporty Pants", "运动裤" },
			{ "Spray paint", "喷漆" },
			{ "Sprout", "嫩芽" },
			{ "Square Glasses", "方框眼镜" },
			{ "Sticky Notes", "便签" },
			{ "Striped shirt", "条纹衬衫" },
			{ "Stripes", "条纹" },
			{ "Sun Hat", "遮阳帽" },
			{ "Suspenders", "背带" },
			{ "Taxman", "税务官" },
			{ "Testing", "测试" },
			{ "Thermal Goggles", "热成像护目镜" },
			{ "Tie", "领带" },
			{ "Tiny Shoe", "小鞋" },
			{ "Top Hat", "高礼帽" },
			{ "Torn fabric", "破布" },
			{ "Tr arm", "透明手臂" },
			{ "Tr body bot", "透明下半身" },
			{ "Tr leg", "透明腿" },
			{ "Tr Top", "透明上装" },
			{ "Transparent", "透明" },
			{ "Triangle ears", "三角耳" },
			{ "Tube Sock", "长筒袜" },
			{ "Tuxedo", "燕尾服" },
			{ "Ugly Glasses", "丑眼镜" },
			{ "Unicorm", "独角兽" },
			{ "Visibility vest", "反光背心" },
			{ "Visor", "面罩" },
			{ "War Paint", "战纹" },
			{ "Witch", "女巫" },
			{ "Wizard Bottom", "巫师下装" },
			{ "Wizard Hat", "巫师帽" },
			{ "Wizard Shirt", "巫师衬衫" },
			{ "Wizard Sleeve", "巫师袖" },
			{ "Wool Sweater", "羊毛衫" },
			{ "Wrangler", "牛仔" },
			{ "Yarn", "毛线" }
		};

		private static string GetRarityName(int idx)
		{
			if (idx < 0 || idx >= 4)
			{
				return "?";
			}
			if (!((Object)(object)_instance != (Object)null) || !_instance._useChinese)
			{
				return RarityNamesEn[idx];
			}
			return RarityNames[idx];
		}

		public static bool IsStaticModEnabled()
		{
			if (_cfgModEnabled != null)
			{
				return _cfgModEnabled.Value;
			}
			return false;
		}

		public static bool UseChinese()
		{
			if (_cfgLanguage != null)
			{
				return _cfgLanguage.Value == DisplayLanguage.中文;
			}
			return true;
		}

		private void Awake()
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			_instance = this;
			DetachFromManager();
			ResetConfigIfVersionChanged();
			BindConfig();
			_openKey.SettingChanged += delegate
			{
				RebindOpenKey();
			};
			_cfgLanguage.SettingChanged += delegate
			{
				_useChinese = _cfgLanguage.Value == DisplayLanguage.中文;
				_dirty = true;
			};
			_compat = CompatibilityReport.Build();
			LogCompatibility();
			_harmony = new Harmony("zichen.cosmeticstools.patch");
			ApplyPatches();
			RegisterInputAction();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"CosmeticsTools v1.0.1 loaded.");
		}

		private void LogCompatibility()
		{
			if (!_compat.HasIssues)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Compatibility self-check passed.");
				return;
			}
			((BaseUnityPlugin)this).Logger.LogWarning((object)_compat.BuildLogMessage());
			foreach (string detailMessage in _compat.GetDetailMessages())
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Detail: " + detailMessage));
			}
		}

		private void LogAllCosmeticNames()
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			if (_loggedOnce)
			{
				return;
			}
			MetaManager instance = MetaManager.instance;
			if (instance?.cosmeticAssets == null)
			{
				return;
			}
			_loggedOnce = true;
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"=== Cosmetic Assets List (Total: {instance.cosmeticAssets.Count}) ===");
			for (int i = 0; i < instance.cosmeticAssets.Count; i++)
			{
				CosmeticAsset val = instance.cosmeticAssets[i];
				if (!((Object)(object)val == (Object)null))
				{
					string text = (string.IsNullOrWhiteSpace(val.assetName) ? ((Object)val).name : val.assetName);
					((BaseUnityPlugin)this).Logger.LogInfo((object)$"  [{i}] type={val.type} rarity={val.rarity} name=\"{text}\"");
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"=== End of List ===");
			if (instance.CosmeticCategoryAssets != null)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)$"=== Categories (Total: {instance.CosmeticCategoryAssets.Count}) ===");
				foreach (CosmeticCategoryAsset cosmeticCategoryAsset in instance.CosmeticCategoryAssets)
				{
					if (!((Object)(object)cosmeticCategoryAsset == (Object)null))
					{
						string text2 = "";
						try
						{
							LocalizedAsset localizedName = cosmeticCategoryAsset.localizedName;
							text2 = ((localizedName != null) ? localizedName.GetLocalizedString() : null) ?? "";
						}
						catch
						{
						}
						((BaseUnityPlugin)this).Logger.LogInfo((object)("  Category: name=\"" + ((Object)cosmeticCategoryAsset).name + "\" categoryName=\"" + cosmeticCategoryAsset.categoryName + "\" localizedName=\"" + text2 + "\" types=[" + string.Join(",", cosmeticCategoryAsset.typeList) + "]"));
					}
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)"=== End of Categories ===");
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"=== UI Text Labels Audit ===");
			string[] array = new string[165]
			{
				"装饰工具箱", "已解锁装饰", "全部解锁", "全部移除", "装饰币", "总计", "普通", "稀有", "珍贵", "超稀有",
				"清空", "清空全部装饰币", "当前", "已解锁", "本类全解锁", "本类全移除", "当前大分类", "暂无", "搜索", "显示",
				"个装饰", "个分段", "全解锁", "全移除", "装饰工具箱已打开", "装饰工具箱已关闭", "已添加", "已移除", "已设置", "切换英文",
				"切换中文", "未知", "全部", "头部", "身体", "手部", "腿脚", "脸部", "帽子", "右臂",
				"左臂", "右腿", "左腿", "头顶模型", "头底模型", "上身模型", "下身模型", "右臂模型", "左臂模型", "右腿模型",
				"左腿模型", "抓取器", "右眼睑", "左眼睑", "上身覆盖", "耳朵", "眼镜", "右脚", "上身", "下身",
				"左脚", "下身覆盖", "头顶覆盖", "头底覆盖", "右臂覆盖", "左臂覆盖", "右腿覆盖", "左腿覆盖", "头底", "鼻子",
				"嘴巴", "发型", "皇冠", "光环", "天线", "蝴蝶结", "头带", "头巾", "毛线帽", "鸭舌帽",
				"高帽", "巫师帽", "派对帽", "海盗", "维京", "牛仔", "厨师帽", "护士帽", "花朵", "树叶",
				"蘑菇", "星星", "爱心", "骷髅", "幽灵", "南瓜", "圣诞", "兔子", "猫", "狗",
				"鸟", "鱼", "机器人", "外星人", "忍者", "骑士", "国王", "女王", "天使", "恶魔",
				"龙", "独角兽", "彩虹", "黄金", "白银", "钻石", "水晶", "火焰", "冰霜", "闪电",
				"暗影", "霓虹", "迷彩", "条纹", "波点", "格子", "生锈", "涂鸦", "污渍", "口红",
				"等离子", "科幻", "纹身", "伤疤", "雀斑", "腮红", "眼罩", "单片眼镜", "太阳镜", "护目镜",
				"绷带", "链条", "尖刺", "翅膀", "尾巴", "披风", "围巾", "领带", "领结", "背包",
				"盾牌", "剑", "斧头", "锤子", "扳手", "靴子", "鞋子", "袜子", "手套", "手镯",
				"戒指", "手表", "袖套", "臂饰", "腿饰"
			};
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"  Plugin contains {array.Length} Chinese label/translation entries (all switch with _useChinese)");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"=== End of Audit ===");
		}

		private void OnDestroy()
		{
			SetWindowOpen(open: false);
			try
			{
				Harmony harmony = _harmony;
				if (harmony != null)
				{
					harmony.UnpatchSelf();
				}
			}
			catch
			{
			}
			_harmony = null;
			if (_instance == this)
			{
				_instance = null;
			}
		}

		private void Update()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if (!IsStaticModEnabled())
			{
				SetWindowOpen(open: false);
				return;
			}
			EnsureInputReady();
			if ((Object)(object)InputManager.instance != (Object)null && SemiFunc.InputDown(OpenInputKey))
			{
				SetWindowOpen(!_windowOpen);
			}
			if (_windowOpen)
			{
				KeepCursorFree();
			}
		}

		private void LateUpdate()
		{
			if (_windowOpen && IsStaticModEnabled())
			{
				KeepCursorFree();
			}
		}

		private static void KeepCursorFree()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if ((int)Cursor.lockState != 0)
			{
				Cursor.lockState = (CursorLockMode)0;
			}
			if (!Cursor.visible)
			{
				Cursor.visible = true;
			}
			try
			{
				if (F_CursorUnlockTimer != null && (Object)(object)CursorManager.instance != (Object)null)
				{
					F_CursorUnlockTimer.SetValue(CursorManager.instance, 99999f);
				}
			}
			catch
			{
			}
		}

		private static void TakeCursor()
		{
			try
			{
				if ((Object)(object)CursorManager.instance != (Object)null)
				{
					CursorManager.instance.Unlock(99999f);
				}
			}
			catch
			{
			}
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
		}

		private static void ReleaseCursor()
		{
			try
			{
				if (F_CursorUnlockTimer != null && (Object)(object)CursorManager.instance != (Object)null)
				{
					F_CursorUnlockTimer.SetValue(CursorManager.instance, 0f);
				}
			}
			catch
			{
			}
			try
			{
				if (SemiFunc.IsMainMenu() || SemiFunc.RunIsLobbyMenu())
				{
					Cursor.lockState = (CursorLockMode)0;
					Cursor.visible = true;
					return;
				}
			}
			catch
			{
			}
			Cursor.lockState = (CursorLockMode)1;
			Cursor.visible = false;
		}

		private void SetWindowOpen(bool open)
		{
			if (_windowOpen != open)
			{
				_windowOpen = open;
				if (open)
				{
					_windowCentered = false;
					LogAllCosmeticNames();
					RefreshRows(MetaManager.instance, force: true);
					TakeCursor();
					_status = (_useChinese ? "装饰工具箱已打开。" : "CosmeticsTools opened.");
				}
				else
				{
					ReleaseCursor();
					_status = (_useChinese ? "装饰工具箱已关闭。" : "CosmeticsTools closed.");
				}
			}
		}

		private void InitStyles()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_008c: 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)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Expected O, but got Unknown
			//IL_016c: Expected O, but got Unknown
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: 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_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Expected O, but got Unknown
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Expected O, but got Unknown
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Expected O, but got Unknown
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Expected O, but got Unknown
			//IL_0338: Expected O, but got Unknown
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Expected O, but got Unknown
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0384: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cf: Expected O, but got Unknown
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0406: Unknown result type (might be due to invalid IL or missing references)
			//IL_041b: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Expected O, but got Unknown
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			//IL_043a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0442: Unknown result type (might be due to invalid IL or missing references)
			//IL_0453: Unknown result type (might be due to invalid IL or missing references)
			//IL_0459: Unknown result type (might be due to invalid IL or missing references)
			//IL_0463: Unknown result type (might be due to invalid IL or missing references)
			//IL_0474: Unknown result type (might be due to invalid IL or missing references)
			//IL_047a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0484: Unknown result type (might be due to invalid IL or missing references)
			//IL_0489: Unknown result type (might be due to invalid IL or missing references)
			//IL_0493: Expected O, but got Unknown
			//IL_0498: Expected O, but got Unknown
			if (!_stylesInit)
			{
				_stylesInit = true;
				_texDark = MakeTex(new Color(0.12f, 0.12f, 0.14f, 0.97f));
				_texMid = MakeTex(new Color(0.18f, 0.18f, 0.22f, 0.95f));
				_texLight = MakeTex(new Color(0.25f, 0.25f, 0.3f, 0.9f));
				_texGreen = MakeTex(new Color(0.2f, 0.55f, 0.2f));
				_texRed = MakeTex(new Color(0.6f, 0.2f, 0.2f));
				_texAccent = MakeTex(new Color(0.3f, 0.5f, 0.8f));
				_texSection = MakeTex(new Color(0.15f, 0.15f, 0.2f, 0.95f));
				GUIStyle val = new GUIStyle(GUI.skin.window);
				val.normal.background = _texDark;
				val.normal.textColor = Color.white;
				val.onNormal.background = _texDark;
				val.onNormal.textColor = Color.white;
				val.fontSize = 16;
				val.padding = new RectOffset(8, 8, 26, 8);
				_sWindow = val;
				GUIStyle val2 = new GUIStyle(GUI.skin.label)
				{
					fontSize = 15
				};
				val2.normal.textColor = new Color(0.9f, 0.85f, 0.6f);
				_sTitle = val2;
				GUIStyle val3 = new GUIStyle(GUI.skin.label)
				{
					fontSize = 14
				};
				val3.normal.textColor = new Color(0.88f, 0.88f, 0.88f);
				_sLabel = val3;
				GUIStyle val4 = new GUIStyle(GUI.skin.label)
				{
					fontSize = 13
				};
				val4.normal.textColor = new Color(0.7f, 0.9f, 0.7f);
				_sStatus = val4;
				_sBtnGreen = MakeBtn(_texGreen, new Color(0.25f, 0.65f, 0.25f));
				_sBtnRed = MakeBtn(_texRed, new Color(0.7f, 0.25f, 0.25f));
				_sBtnNormal = MakeBtn(_texLight, new Color(0.32f, 0.32f, 0.38f));
				_sBtnCat = MakeBtn(_texMid, new Color(0.22f, 0.22f, 0.28f));
				_sBtnCat.fontSize = 13;
				_sBtnCatSel = MakeBtn(_texAccent, new Color(0.35f, 0.55f, 0.85f));
				_sBtnCatSel.fontSize = 13;
				GUIStyle val5 = new GUIStyle(GUI.skin.box);
				val5.normal.background = _texSection;
				val5.normal.textColor = Color.white;
				val5.padding = new RectOffset(8, 8, 6, 6);
				_sSection = val5;
				GUIStyle val6 = new GUIStyle(GUI.skin.label)
				{
					fontSize = 14
				};
				val6.normal.textColor = new Color(0.95f, 0.8f, 0.4f);
				_sSectionLabel = val6;
				GUIStyle val7 = new GUIStyle(GUI.skin.toggle)
				{
					fontSize = 14
				};
				val7.normal.textColor = new Color(0.6f, 1f, 0.6f);
				val7.onNormal.textColor = new Color(0.6f, 1f, 0.6f);
				_sToggleOn = val7;
				GUIStyle val8 = new GUIStyle(GUI.skin.toggle)
				{
					fontSize = 14
				};
				val8.normal.textColor = new Color(0.7f, 0.7f, 0.7f);
				val8.onNormal.textColor = new Color(0.7f, 0.7f, 0.7f);
				_sToggleOff = val8;
				GUIStyle val9 = new GUIStyle(GUI.skin.textField)
				{
					fontSize = 14
				};
				val9.normal.background = _texMid;
				val9.normal.textColor = Color.white;
				val9.focused.background = _texLight;
				val9.focused.textColor = Color.white;
				val9.padding = new RectOffset(6, 6, 4, 4);
				_sTextField = val9;
			}
		}

		private static GUIStyle MakeBtn(Texture2D bg, Color hover)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_004c: 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_0062: 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_0072: 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_0083: Expected O, but got Unknown
			//IL_0084: Expected O, but got Unknown
			Texture2D background = MakeTex(hover);
			GUIStyle val = new GUIStyle(GUI.skin.button)
			{
				fontSize = 14
			};
			val.normal.background = bg;
			val.normal.textColor = Color.white;
			val.hover.background = background;
			val.hover.textColor = Color.white;
			val.active.background = background;
			val.active.textColor = Color.yellow;
			val.padding = new RectOffset(10, 10, 5, 5);
			return val;
		}

		private static Texture2D MakeTex(Color c)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_0013: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			val.SetPixels((Color[])(object)new Color[4] { c, c, c, c });
			val.Apply();
			((Object)val).hideFlags = (HideFlags)61;
			return val;
		}

		private void OnGUI()
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			if (IsStaticModEnabled() && _windowOpen)
			{
				InitStyles();
				if (!_windowCentered)
				{
					((Rect)(ref _windowRect)).x = ((float)Screen.width - ((Rect)(ref _windowRect)).width) * 0.5f;
					((Rect)(ref _windowRect)).y = ((float)Screen.height - ((Rect)(ref _windowRect)).height) * 0.5f;
					_windowCentered = true;
				}
				string text = (_useChinese ? "装饰工具箱" : "✦ CosmeticsTools");
				_windowRect = GUI.Window(33001, _windowRect, new WindowFunction(DrawWindow), text, _sWindow);
			}
		}

		private void DrawWindow(int id)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: 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_00f3: 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_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_0581: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0455: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0650: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0755: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Max(400f, ((Rect)(ref _windowRect)).width - 32f);
			float num2 = 28f;
			DrawCloseButton();
			MetaManager instance = MetaManager.instance;
			if (!CanEdit(instance, out var reason))
			{
				GUI.Label(R(16f, num2, num, 22f), reason, _sLabel);
				GUI.Label(R(16f, num2 + 26f, num, 22f), _status, _sStatus);
				GUI.DragWindow(R(0f, 0f, ((Rect)(ref _windowRect)).width - 32f, 26f));
				return;
			}
			if (!GetState(instance, out var s))
			{
				GUI.Label(R(16f, num2, num, 22f), "无法读取装饰保存数据,游戏接口可能已变化。", _sLabel);
				GUI.DragWindow(R(0f, 0f, ((Rect)(ref _windowRect)).width - 32f, 26f));
				return;
			}
			RefreshRows(instance);
			RefreshUnlocked(s);
			RefreshCategories(instance);
			string text = (_useChinese ? $"已解锁装饰:{_unlocked.Count} / {_allRows.Count}" : $"Unlocked: {_unlocked.Count} / {_allRows.Count}");
			GUI.Label(R(16f, num2, num - 140f, 22f), text, _sTitle);
			string text2 = (_useChinese ? "Switch to English" : "切换中文");
			if (GUI.Button(R(16f + num - 130f, num2 - 2f, 130f, 26f), text2, _sBtnNormal))
			{
				_useChinese = !_useChinese;
				_cfgLanguage.Value = ((!_useChinese) ? DisplayLanguage.English : DisplayLanguage.中文);
				RefreshRows(MetaManager.instance, force: true);
				RefreshCategories(MetaManager.instance);
				_dirty = true;
			}
			num2 += 28f;
			float num3 = (num - 12f) * 0.5f;
			if (GUI.Button(R(16f, num2, num3, 34f), _useChinese ? "★ 全部解锁" : "★ Unlock All", _sBtnGreen))
			{
				int num4 = UnlockAll(instance, s);
				AfterChange(instance, s);
				_status = (_useChinese ? $"已全部解锁,新增 {num4} 个。" : $"All unlocked, {num4} new.");
			}
			if (GUI.Button(R(16f + num3 + 12f, num2, num3, 34f), _useChinese ? "✕ 全部移除" : "✕ Remove All", _sBtnRed))
			{
				int num5 = ClearAll(instance, s);
				AfterChange(instance, s);
				_status = (_useChinese ? $"已移除全部装饰数据,{num5} 个。" : $"All removed, {num5} items.");
			}
			num2 += 42f;
			num2 = DrawTokens(instance, 16f, num2, num);
			GUI.Label(R(16f, num2, num, 20f), _status, _sStatus);
			num2 += 26f;
			DrawCategoryBar(R(16f, num2, num, 32f));
			num2 += 40f;
			CategoryRow selectedCategory = GetSelectedCategory();
			if (selectedCategory != null)
			{
				string text3 = (_useChinese ? $"当前:{selectedCategory.Name}    已解锁 {selectedCategory.Unlocked}/{selectedCategory.Total}" : $"Current: {selectedCategory.Name}    Unlocked {selectedCategory.Unlocked}/{selectedCategory.Total}");
				GUI.Label(R(16f, num2, num, 22f), text3, _sLabel);
				num2 += 26f;
				if (selectedCategory.Types.Count > 0)
				{
					float num6 = (num - 12f) * 0.5f;
					if (GUI.Button(R(16f, num2, num6, 28f), _useChinese ? "本类全解锁" : "Unlock Category", _sBtnGreen))
					{
						int num7 = UnlockByTypes(instance, s, selectedCategory.Types);
						AfterChange(instance, s);
						_status = (_useChinese ? $"已解锁 {selectedCategory.Name},新增 {num7} 个。" : $"Unlocked {selectedCategory.Name}, {num7} new.");
					}
					if (GUI.Button(R(16f + num6 + 12f, num2, num6, 28f), _useChinese ? "本类全移除" : "Remove Category", _sBtnRed))
					{
						int num8 = ClearByTypes(instance, s, selectedCategory.Types);
						AfterChange(instance, s);
						_status = (_useChinese ? $"已移除 {selectedCategory.Name},{num8} 个。" : $"Removed {selectedCategory.Name}, {num8} items.");
					}
					num2 += 36f;
				}
			}
			else
			{
				GUI.Label(R(16f, num2, num, 22f), _useChinese ? "当前大分类:暂无" : "Category: None", _sLabel);
				num2 += 26f;
			}
			GUI.Label(R(16f, num2 + 4f, 60f, 22f), _useChinese ? "搜索:" : "Search:", _sLabel);
			string text4 = GUI.TextField(R(80f, num2, num - 140f, 26f), _searchText ?? string.Empty, _sTextField);
			if (text4 != _searchText)
			{
				_searchText = text4;
				_dirty = true;
			}
			if (GUI.Button(R(16f + num - 68f, num2, 68f, 26f), _useChinese ? "清空" : "Clear", _sBtnNormal))
			{
				_searchText = string.Empty;
				_dirty = true;
			}
			num2 += 34f;
			RebuildDisplay();
			string text5 = (_useChinese ? $"显示 {_visibleRows} 个装饰,{_visibleSections} 个分段" : $"Showing {_visibleRows} cosmetics, {_visibleSections} sections");
			GUI.Label(R(16f, num2, num, 20f), text5, _sLabel);
			num2 += 24f;
			DrawList(instance, s, 16f, num2, num, Mathf.Max(100f, ((Rect)(ref _windowRect)).height - num2 - 16f));
			GUI.DragWindow(R(0f, 0f, ((Rect)(ref _windowRect)).width - 32f, 26f));
		}

		private void DrawCloseButton()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			string text = (_useChinese ? "关闭" : "Close");
			if (GUI.Button(R(((Rect)(ref _windowRect)).width - 28f, 3f, 24f, 22f), new GUIContent("✕", text), _sBtnRed))
			{
				SetWindowOpen(open: false);
			}
		}

		private void DrawCategoryBar(Rect rect)
		{
			//IL_000d: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			if (_categories.Count == 0)
			{
				GUI.Label(rect, "没有读取到原版装饰大分类。", _sLabel);
				return;
			}
			float num = 6f;
			float num2 = Mathf.Max(80f, (((Rect)(ref rect)).width - num * (float)(_categories.Count - 1)) / (float)_categories.Count);
			for (int i = 0; i < _categories.Count; i++)
			{
				CategoryRow categoryRow = _categories[i];
				bool flag = (Object)(object)categoryRow.Asset == (Object)(object)_selectedCat;
				if (GUI.Button(R(((Rect)(ref rect)).x + (float)i * (num2 + num), ((Rect)(ref rect)).y, num2, ((Rect)(ref rect)).height), $"{categoryRow.Name} {categoryRow.Unlocked}/{categoryRow.Total}", flag ? _sBtnCatSel : _sBtnCat))
				{
					_selectedCat = categoryRow.Asset;
					_dirty = true;
					_scroll = Vector2.zero;
				}
			}
		}

		private void DrawList(MetaManager meta, CosmeticState st, float x, float y, float w, float viewH)
		{
			//IL_001b: 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)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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)
			float num = Mathf.Max(240f, w - 18f);
			_scroll = GUI.BeginScrollView(R(x, y, w, viewH), _scroll, R(0f, 0f, num, Mathf.Max(viewH, _contentH)), false, true, GUIStyle.none, GUI.skin.verticalScrollbar);
			if (_display.Count == 0)
			{
				GUI.Label(R(4f, 4f, num - 8f, 22f), "没有匹配的装饰。", _sLabel);
				GUI.EndScrollView();
				return;
			}
			float num2 = 0f;
			float num3 = _scroll.y - 100f;
			float num4 = _scroll.y + viewH + 100f;
			for (int i = 0; i < _display.Count; i++)
			{
				DisplayRow displayRow = _display[i];
				if (num2 + displayRow.Height >= num3 && num2 <= num4)
				{
					if (displayRow.Section != null)
					{
						DrawSection(meta, st, displayRow.Section, num2, num);
					}
					else
					{
						DrawToggle(meta, st, displayRow.Row, num2, num);
					}
				}
				num2 += displayRow.Height;
				if (num2 > num4)
				{
					break;
				}
			}
			GUI.EndScrollView();
		}

		private void DrawSection(MetaManager meta, CosmeticState st, SectionRow s, float y, float w)
		{
			//IL_001a: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			GUI.Box(R(0f, y + 2f, w - 4f, 64f), GUIContent.none, _sSection);
			string text = (_useChinese ? $"◆ {s.Name}    已解锁 {s.Unlocked}/{s.Total}" : $"◆ {s.Name}    Unlocked {s.Unlocked}/{s.Total}");
			GUI.Label(R(10f, y + 8f, w - 20f, 22f), text, _sSectionLabel);
			float num = Mathf.Max(90f, (w - 36f) * 0.5f);
			if (GUI.Button(R(10f, y + 36f, num, 24f), _useChinese ? "全解锁" : "Unlock", _sBtnGreen))
			{
				int num2 = UnlockByType(meta, st, s.Type);
				AfterChange(meta, st);
				_status = (_useChinese ? $"已解锁 {s.Name},新增 {num2} 个。" : $"Unlocked {s.Name}, {num2} new.");
			}
			if (GUI.Button(R(18f + num, y + 36f, num, 24f), _useChinese ? "全移除" : "Remove", _sBtnRed))
			{
				int num3 = ClearByType(meta, st, s.Type);
				AfterChange(meta, st);
				_status = (_useChinese ? $"已移除 {s.Name},{num3} 个。" : $"Removed {s.Name}, {num3} items.");
			}
		}

		private void DrawToggle(MetaManager meta, CosmeticState st, CosmeticRow row, float y, float w)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			bool flag = _unlocked.Contains(row.Index);
			bool flag2 = GUI.Toggle(R(10f, y + 3f, w - 20f, 26f), flag, row.DisplayName, flag ? _sToggleOn : _sToggleOff);
			if (flag2 != flag)
			{
				SetUnlocked(meta, st, row.Index, flag2);
				AfterChange(meta, st);
				_status = (flag2 ? ("已解锁:" + row.DisplayName) : ("已关闭:" + row.DisplayName));
			}
		}

		private float DrawTokens(MetaManager meta, float x, float y, float w)
		{
			//IL_0031: 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_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0547: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_043c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
			if (!_compat.TokensAvailable || F_Tokens == null || !GetField<List<int>>(F_Tokens, meta, out var v))
			{
				GUI.Label(R(x, y, w, 22f), _useChinese ? "装饰币接口不可用。" : "Token interface unavailable.", _sLabel);
				return y + 26f;
			}
			GUI.Label(R(x, y, w, 22f), _useChinese ? $"装饰币(总计 {v.Count} 个)" : $"Tokens (Total: {v.Count})", _sTitle);
			y += 26f;
			int[] array = new int[4];
			for (int i = 0; i < v.Count; i++)
			{
				int num = v[i];
				if (num >= 0 && num < 4)
				{
					array[num]++;
				}
			}
			string nameOfFocusedControl = GUI.GetNameOfFocusedControl();
			for (int j = 0; j < 4; j++)
			{
				if (nameOfFocusedControl != "tk" + j)
				{
					_tokenTexts[j] = array[j].ToString();
				}
			}
			for (int k = 0; k < 4; k++)
			{
				string rarityName = GetRarityName(k);
				float num2 = x;
				Color color = GUI.color;
				GUI.color = RarityColors[k];
				GUI.Label(R(num2, y + 4f, 100f, 22f), "● " + rarityName, _sLabel);
				GUI.color = color;
				num2 += 100f;
				if (GUI.Button(R(num2, y, 32f, 26f), "−", _sBtnRed) && array[k] > 0)
				{
					RemoveToken(v, k);
					SaveTokens(meta);
					_status = (_useChinese ? ("已移除 1 个" + rarityName + "装饰币。") : ("-1 " + rarityName + " token."));
				}
				num2 += 37f;
				GUI.SetNextControlName("tk" + k);
				string text = GUI.TextField(R(num2, y, 60f, 26f), _tokenTexts[k], _sTextField);
				if (text != _tokenTexts[k])
				{
					_tokenTexts[k] = text;
					if (int.TryParse(text, out var result) && result >= 0 && result != array[k])
					{
						SetTokenCount(v, k, result);
						SaveTokens(meta);
						_status = (_useChinese ? $"已设置{rarityName}为 {result} 个。" : $"Set {rarityName} to {result}.");
					}
				}
				num2 += 65f;
				if (GUI.Button(R(num2, y, 32f, 26f), "+", _sBtnGreen))
				{
					v.Add(k);
					SaveTokens(meta);
					_status = (_useChinese ? ("+1 " + rarityName + "装饰币。") : ("+1 " + rarityName + " token."));
				}
				num2 += 37f;
				if (GUI.Button(R(num2, y, 42f, 26f), "+1", _sBtnGreen))
				{
					v.Add(k);
					SaveTokens(meta);
					_status = (_useChinese ? ("+1 " + rarityName + "装饰币。") : ("+1 " + rarityName + " token."));
				}
				num2 += 47f;
				if (GUI.Button(R(num2, y, 42f, 26f), "+10", _sBtnGreen))
				{
					for (int l = 0; l < 10; l++)
					{
						v.Add(k);
					}
					SaveTokens(meta);
					_status = (_useChinese ? ("+10 " + rarityName + "装饰币。") : ("+10 " + rarityName + " tokens."));
				}
				num2 += 47f;
				if (GUI.Button(R(num2, y, 48f, 26f), "+100", _sBtnGreen))
				{
					for (int m = 0; m < 100; m++)
					{
						v.Add(k);
					}
					SaveTokens(meta);
					_status = (_useChinese ? ("+100 " + rarityName + "装饰币。") : ("+100 " + rarityName + " tokens."));
				}
				num2 += 53f;
				if (GUI.Button(R(num2, y, 50f, 26f), _useChinese ? "清空" : "Clear", _sBtnRed) && array[k] > 0)
				{
					SetTokenCount(v, k, 0);
					SaveTokens(meta);
					_status = (_useChinese ? ("已清空" + rarityName + "装饰币。") : (rarityName + " cleared."));
				}
				y += 30f;
			}
			if (GUI.Button(R(x, y, 140f, 28f), _useChinese ? "清空全部装饰币" : "Clear All Tokens", _sBtnRed) && v.Count > 0)
			{
				v.Clear();
				SaveTokens(meta);
				_status = (_useChinese ? "已清空全部装饰币。" : "All tokens cleared.");
			}
			y += 32f;
			return y + 4f;
		}

		private void RefreshRows(MetaManager meta, bool force = false)
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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_00c5: Expected I4, but got Unknown
			int valueOrDefault = (meta?.cosmeticAssets?.Count).GetValueOrDefault(-1);
			if (!force && _cachedMeta == meta && _cachedCount == valueOrDefault)
			{
				return;
			}
			_allRows.Clear();
			_cachedMeta = meta;
			_cachedCount = valueOrDefault;
			if (meta?.cosmeticAssets == null)
			{
				return;
			}
			for (int i = 0; i < meta.cosmeticAssets.Count; i++)
			{
				CosmeticAsset val = meta.cosmeticAssets[i];
				if (!((Object)(object)val == (Object)null))
				{
					string text = FormatName(val, i);
					_allRows.Add(new CosmeticRow
					{
						Index = i,
						Type = val.type,
						Rarity = (int)val.rarity,
						SortName = (string.IsNullOrWhiteSpace(val.assetName) ? ((Object)val).name : val.assetName),
						DisplayName = text,
						SearchText = BuildSearch(val, text)
					});
				}
			}
			_dirty = true;
		}

		private void RefreshUnlocked(CosmeticState state)
		{
			_unlocked.Clear();
			if (state?.Unlocks == null)
			{
				return;
			}
			for (int i = 0; i < state.Unlocks.Count; i++)
			{
				int num = state.Unlocks[i];
				if (ValidIndex(_cachedMeta, num))
				{
					_unlocked.Add(num);
				}
			}
		}

		private void RefreshCategories(MetaManager meta)
		{
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			_categories.Clear();
			_sections.Clear();
			if (meta?.CosmeticCategoryAssets != null)
			{
				foreach (CosmeticCategoryAsset cosmeticCategoryAsset in meta.CosmeticCategoryAssets)
				{
					if (!((Object)(object)cosmeticCategoryAsset == (Object)null) && cosmeticCategoryAsset.typeList != null && cosmeticCategoryAsset.typeList.Count != 0)
					{
						CategoryRow categoryRow = new CategoryRow
						{
							Asset = cosmeticCategoryAsset,
							Name = TranslateCategory(cosmeticCategoryAsset),
							Types = new List<CosmeticType>(new HashSet<CosmeticType>(cosmeticCategoryAsset.typeList))
						};
						CountCat(categoryRow);
						if (categoryRow.Total > 0)
						{
							_categories.Add(categoryRow);
						}
					}
				}
			}
			if (_categories.Count == 0)
			{
				List<CosmeticType> list = new List<CosmeticType>();
				HashSet<CosmeticType> hashSet = new HashSet<CosmeticType>();
				foreach (CosmeticRow allRow in _allRows)
				{
					if (hashSet.Add(allRow.Type))
					{
						list.Add(allRow.Type);
					}
				}
				CategoryRow categoryRow2 = new CategoryRow
				{
					Name = (_useChinese ? "全部" : "All"),
					Types = list
				};
				CountCat(categoryRow2);
				if (categoryRow2.Total > 0)
				{
					_categories.Add(categoryRow2);
				}
			}
			if (_categories.Count == 0)
			{
				_selectedCat = null;
				_dirty = true;
				return;
			}
			bool flag = false;
			for (int i = 0; i < _categories.Count; i++)
			{
				if ((Object)(object)_categories[i].Asset == (Object)(object)_selectedCat)
				{
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				_selectedCat = _categories[0].Asset;
			}
			RebuildSections();
			_dirty = true;
		}

		private void CountCat(CategoryRow cr)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			cr.Total = 0;
			cr.Unlocked = 0;
			HashSet<CosmeticType> hashSet = new HashSet<CosmeticType>(cr.Types);
			for (int i = 0; i < _allRows.Count; i++)
			{
				if (hashSet.Contains(_allRows[i].Type))
				{
					cr.Total++;
					if (_unlocked.Contains(_allRows[i].Index))
					{
						cr.Unlocked++;
					}
				}
			}
		}

		private void RebuildSections()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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)
			//IL_004c: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			_sections.Clear();
			CategoryRow selectedCategory = GetSelectedCategory();
			if (selectedCategory == null)
			{
				return;
			}
			foreach (CosmeticType type in selectedCategory.Types)
			{
				List<CosmeticRow> list = new List<CosmeticRow>();
				for (int i = 0; i < _allRows.Count; i++)
				{
					if (_allRows[i].Type == type)
					{
						list.Add(_allRows[i]);
					}
				}
				if (list.Count == 0)
				{
					continue;
				}
				list.Sort(delegate(CosmeticRow a, CosmeticRow b)
				{
					bool flag = _unlocked.Contains(a.Index);
					bool flag2 = _unlocked.Contains(b.Index);
					if (flag != flag2)
					{
						if (!flag)
						{
							return 1;
						}
						return -1;
					}
					int num2 = b.Rarity.CompareTo(a.Rarity);
					return (num2 != 0) ? num2 : string.Compare(a.SortName, b.SortName, StringComparison.Ordinal);
				});
				int num = 0;
				for (int j = 0; j < list.Count; j++)
				{
					if (_unlocked.Contains(list[j].Index))
					{
						num++;
					}
				}
				_sections.Add(new SectionRow
				{
					Type = type,
					Name = TranslateType(type),
					Rows = list,
					Total = list.Count,
					Unlocked = num
				});
			}
		}

		private void RebuildDisplay()
		{
			string text = (_searchText ?? string.Empty).Trim();
			if (!_dirty && _appliedSearch == text)
			{
				return;
			}
			_display.Clear();
			_contentH = 0f;
			_visibleRows = 0;
			_visibleSections = 0;
			for (int i = 0; i < _sections.Count; i++)
			{
				SectionRow sectionRow = _sections[i];
				_matchBuf.Clear();
				for (int j = 0; j < sectionRow.Rows.Count; j++)
				{
					CosmeticRow cosmeticRow = sectionRow.Rows[j];
					if (text.Length == 0 || (cosmeticRow.SearchText != null && cosmeticRow.SearchText.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0))
					{
						_matchBuf.Add(cosmeticRow);
					}
				}
				if (_matchBuf.Count != 0)
				{
					_display.Add(new DisplayRow
					{
						Section = sectionRow,
						Height = 68f
					});
					_contentH += 68f;
					_visibleSections++;
					for (int k = 0; k < _matchBuf.Count; k++)
					{
						_display.Add(new DisplayRow
						{
							Row = _matchBuf[k],
							Height = 30f
						});
						_contentH += 30f;
						_visibleRows++;
					}
				}
			}
			_appliedSearch = text;
			_dirty = false;
			_scroll.y = Mathf.Min(_scroll.y, Mathf.Max(0f, _contentH));
		}

		private CategoryRow GetSelectedCategory()
		{
			for (int i = 0; i < _categories.Count; i++)
			{
				if ((Object)(object)_categories[i].Asset == (Object)(object)_selectedCat)
				{
					return _categories[i];
				}
			}
			if (_categories.Count <= 0)
			{
				return null;
			}
			return _categories[0];
		}

		private void AfterChange(MetaManager meta, CosmeticState st)
		{
			RefreshUnlocked(st);
			RefreshCategories(meta);
			SaveAndRefresh(meta);
		}

		private static int UnlockAll(MetaManager m, CosmeticState s)
		{
			int num = 0;
			for (int i = 0; i < m.cosmeticAssets.Count; i++)
			{
				if (!((Object)(object)m.cosmeticAssets[i] == (Object)null))
				{
					if (!s.Unlocks.Contains(i))
					{
						s.Unlocks.Add(i);
						num++;
					}
					if (!s.History.Contains(i))
					{
						s.History.Add(i);
					}
				}
			}
			return num;
		}

		private static int ClearAll(MetaManager m, CosmeticState s)
		{
			int num = 0;
			for (int i = 0; i < s.Unlocks.Count; i++)
			{
				if (ValidIndex(m, s.Unlocks[i]))
				{
					num++;
				}
			}
			s.Unlocks.Clear();
			s.History.Clear();
			s.Equipped.Clear();
			foreach (List<int> cosmeticPreset in s.CosmeticPresets)
			{
				cosmeticPreset?.Clear();
			}
			foreach (List<int> colorPreset in s.ColorPresets)
			{
				ResetList(colorPreset);
			}
			ResetArr(s.ColorsEquipped);
			return num;
		}

		private static int UnlockByType(MetaManager m, CosmeticState s, CosmeticType t)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			for (int i = 0; i < m.cosmeticAssets.Count; i++)
			{
				CosmeticAsset val = m.cosmeticAssets[i];
				if (!((Object)(object)val == (Object)null) && val.type == t)
				{
					if (!s.Unlocks.Contains(i))
					{
						s.Unlocks.Add(i);
						num++;
					}
					if (!s.History.Contains(i))
					{
						s.History.Add(i);
					}
				}
			}
			return num;
		}

		private static int UnlockByTypes(MetaManager m, CosmeticState s, List<CosmeticType> types)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			HashSet<CosmeticType> hashSet = new HashSet<CosmeticType>(types);
			for (int i = 0; i < m.cosmeticAssets.Count; i++)
			{
				CosmeticAsset val = m.cosmeticAssets[i];
				if (!((Object)(object)val == (Object)null) && hashSet.Contains(val.type))
				{
					if (!s.Unlocks.Contains(i))
					{
						s.Unlocks.Add(i);
						num++;
					}
					if (!s.History.Contains(i))
					{
						s.History.Add(i);
					}
				}
			}
			return num;
		}

		private static int ClearByType(MetaManager m, CosmeticState s, CosmeticType t)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			for (int i = 0; i < m.cosmeticAssets.Count; i++)
			{
				CosmeticAsset val = m.cosmeticAssets[i];
				if (!((Object)(object)val == (Object)null) && val.type == t)
				{
					if (s.Unlocks.Contains(i))
					{
						num++;
					}
					SetUnlocked(m, s, i, unlock: false);
				}
			}
			return num;
		}

		private static int ClearByTypes(MetaManager m, CosmeticState s, List<CosmeticType> types)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			HashSet<CosmeticType> hashSet = new HashSet<CosmeticType>(types);
			for (int i = 0; i < m.cosmeticAssets.Count; i++)
			{
				CosmeticAsset val = m.cosmeticAssets[i];
				if (!((Object)(object)val == (Object)null) && hashSet.Contains(val.type))
				{
					if (s.Unlocks.Contains(i))
					{
						num++;
					}
					SetUnlocked(m, s, i, unlock: false);
				}
			}
			return num;
		}

		private static void SetUnlocked(MetaManager m, CosmeticState s, int idx, bool unlock)
		{
			if (!ValidIndex(m, idx))
			{
				return;
			}
			if (unlock)
			{
				if (!s.Unlocks.Contains(idx))
				{
					s.Unlocks.Add(idx);
				}
				if (!s.History.Contains(idx))
				{
					s.History.Add(idx);
				}
				return;
			}
			RemoveAll(s.Unlocks, idx);
			RemoveAll(s.History, idx);
			RemoveAll(s.Equipped, idx);
			if (s.CosmeticPresets != null)
			{
				foreach (List<int> cosmeticPreset in s.CosmeticPresets)
				{
					RemoveAll(cosmeticPreset, idx);
				}
			}
			ResetColorFor(m.cosmeticAssets[idx], s.ColorsEquipped, s.ColorPresets);
		}

		private static void SaveAndRefresh(MetaManager meta)
		{
			try
			{
				if (M_MetaSave != null)
				{
					M_MetaSave.Invoke(meta, null);
				}
				if (!_compat.VisualRefreshAvailable)
				{
					return;
				}
				if (M_CosmeticPreviewSet != null)
				{
					M_CosmeticPreviewSet.Invoke(meta, new object[1] { false });
				}
				if (M_CosmeticPlayerUpdateLocal != null)
				{
					M_CosmeticPlayerUpdateLocal.Invoke(meta, new object[2] { true, true });
				}
				PlayerCosmetics[] array = Object.FindObjectsOfType<PlayerCosmetics>();
				foreach (PlayerCosmetics val in array)
				{
					if (Object.op_Implicit((Object)(object)val))
					{
						try
						{
							val.SetupCosmetics(false, true, (List<int>)null);
							val.SetupColors(false, (int[])null);
						}
						catch
						{
						}
					}
				}
			}
			catch (Exception ex)
			{
				Plugin instance = _instance;
				if (instance != null)
				{
					((BaseUnityPlugin)instance).Logger.LogWarning((object)("Save: " + ex.Message));
				}
			}
		}

		private static void SaveTokens(MetaManager meta)
		{
			try
			{
				meta.Save(true);
				if ((Object)(object)CosmeticTokenUI.instance != (Object)null)
				{
					CosmeticTokenUI.instance.Setup();
				}
			}
			catch (Exception ex)
			{
				Plugin instance = _instance;
				if (instance != null)
				{
					((BaseUnityPlugin)instance).Logger.LogWarning((object)("Token: " + ex.Message));
				}
			}
		}

		private static void RemoveToken(List<int> t, int r)
		{
			for (int num = t.Count - 1; num >= 0; num--)
			{
				if (t[num] == r)
				{
					t.RemoveAt(num);
					break;
				}
			}
		}

		private static void SetTokenCount(List<int> t, int r, int target)
		{
			int num = 0;
			for (int i = 0; i < t.Count; i++)
			{
				if (t[i] == r)
				{
					num++;
				}
			}
			if (target > num)
			{
				for (int j = 0; j < target - num; j++)
				{
					t.Add(r);
				}
			}
			else
			{
				if (target >= num)
				{
					return;
				}
				int num2 = num - target;
				int num3 = t.Count - 1;
				while (num3 >= 0 && num2 > 0)
				{
					if (t[num3] == r)
					{
						t.RemoveAt(num3);
						num2--;
					}
					num3--;
				}
			}
		}

		private void EnsureInputReady()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			InputManager instance = InputManager.instance;
			if (!((Object)(object)instance == (Object)null))
			{
				if (!_inputRegistered || _registeredInputManager != instance || _registeredInputActions == null || !_registeredInputActions.ContainsKey(OpenInputKey))
				{
					RegisterInputAction();
				}
				RebindOpenKey();
			}
		}

		private static void RegisterInputAction()
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			InputManager instance = InputManager.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			if (_inputRegistered && _registeredInputManager == instance && _registeredInputActions != null && _registeredInputActions.TryGetValue(OpenInputKey, out var value) && value != null)
			{
				if (!value.enabled)
				{
					value.Enable();
				}
				return;
			}
			try
			{
				Dictionary<InputKey, InputAction> value2 = Traverse.Create((object)instance).Field<Dictionary<InputKey, InputAction>>("inputActions").Value;
				if (value2 != null)
				{
					if (!value2.TryGetValue(OpenInputKey, out var value3) || value3 == null)
					{
						value3 = new InputAction("CosmeticsToolsOpen", (InputActionType)1, KeyToPath(_instance?._openKey?.Value ?? "F5"), (string)null, (string)null, (string)null);
						value2[OpenInputKey] = value3;
						value3.Enable();
						_lastAppliedOpenKey = null;
					}
					else if (!value3.enabled)
					{
						value3.Enable();
					}
					_registeredInputManager = instance;
					_registeredInputActions = value2;
					_inputRegistered = true;
				}
			}
			catch (Exception ex)
			{
				_inputRegistered = false;
				Plugin instance2 = _instance;
				if (instance2 != null)
				{
					((BaseUnityPlugin)instance2).Logger.LogWarning((object)("Input: " + ex.Message));
				}
			}
		}

		private static void RebindOpenKey()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			if (_instance?._openKey == null || (Object)(object)InputManager.instance == (Object)null)
			{
				return;
			}
			string value = _instance._openKey.Value;
			if (_lastAppliedOpenKey == value)
			{
				return;
			}
			RegisterInputAction();
			try
			{
				InputManager.instance.Rebind(OpenInputKey, KeyToPath(value));
				_lastAppliedOpenKey = value;
			}
			catch
			{
				_lastAppliedOpenKey = null;
			}
		}

		internal static string KeyToPath(string n)
		{
			if (string.IsNullOrWhiteSpace(n))
			{
				return "<keyboard>/f5";
			}
			if (n.Length == 1 && char.IsLetter(n[0]))
			{
				return "<keyboard>/" + char.ToLowerInvariant(n[0]);
			}
			if (n.Length == 1 && n[0] >= '0' && n[0] <= '9')
			{
				return "<keyboard>/" + n;
			}
			if (n.Length > 1 && n[0] == 'F' && int.TryParse(n.Substring(1), out var _))
			{
				return "<keyboard>/" + n.ToLowerInvariant();
			}
			return n switch
			{
				"Space" => "<keyboard>/space", 
				"Enter" => "<keyboard>/enter", 
				"Tab" => "<keyboard>/tab", 
				"LeftShift" => "<keyboard>/leftShift", 
				"RightShift" => "<keyboard>/rightShift", 
				"LeftControl" => "<keyboard>/leftCtrl", 
				"RightControl" => "<keyboard>/rightCtrl", 
				_ => "<keyboard>/f5", 
			};
		}

		private void ApplyPatches()
		{
			TryPatch("InputManager.InitializeInputs", M_InputMgrInit, null, "Post_Init", "F5 输入注册");
			TryPatch("PlayerController.Start", M_PlayerCtrlStart, null, "Post_Start", "F5 输入重绑定");
		}

		private void TryPatch(string name, MethodInfo target, string prefix = null, string postfix = null, string patchedFeature = null)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			if (target == null)
			{
				_compat.AddPatchFailure(patchedFeature ?? name, name, "目标方法未找到");
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Skip patch " + name + ": target method missing."));
				return;
			}
			try
			{
				HarmonyMethod val = new HarmonyMethod(AccessTools.Method(typeof(Plugin), prefix ?? postfix, (Type[])null, (Type[])null));
				if (prefix != null)
				{
					_harmony.Patch((MethodBase)target, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				else
				{
					_harmony.Patch((MethodBase)target, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
			catch (Exception ex)
			{
				_compat.AddPatchFailure(patchedFeature ?? name, name, ex.Message);
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Patch " + name + " failed: " + ex.Message));
			}
		}

		private static void Post_Init()
		{
			RegisterInputAction();
		}

		private static void Post_Start()
		{
			RegisterInputAction();
			RebindOpenKey();
		}

		private void BindConfig()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Expected O, but got Unknown
			((BaseUnityPlugin)this).Config.Bind<string>("模组信息", "模组名称", "装饰工具箱", new ConfigDescription("", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 1000,
					ReadOnly = true
				}
			}));
			((BaseUnityPlugin)this).Config.Bind<string>("模组信息", "模组版本号", "1.0.1", new ConfigDescription("", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 990,
					ReadOnly = true
				}
			}));
			_cfgLanguage = ((BaseUnityPlugin)this).Config.Bind<DisplayLanguage>("模组信息", "语言/Language", DisplayLanguage.中文, "公开文档和配置说明语言切换。仅该项保留中英并列格式。");
			_useChinese = _cfgLanguage.Value == DisplayLanguage.中文;
			_cfgModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("A.全局设置", "模组启用", true, "关闭后整个模组全部功能彻底失效");
			_openKey = ((BaseUnityPlugin)this).Config.Bind<string>("A.全局设置", "打开按键", "F5", new ConfigDescription("按下此键打开或关闭装饰工具箱。", (AcceptableValueBase)(object)new AcceptableValueList<string>(AvailableKeybinds), Array.Empty<object>()));
		}

		private void ResetConfigIfVersionChanged()
		{
			try
			{
				string configFilePath = ((BaseUnityPlugin)this).Config.ConfigFilePath;
				if (!File.Exists(configFilePath))
				{
					return;
				}
				Match match = Regex.Match(File.ReadAllText(configFilePath), "(?m)^模组版本号\\s*=\\s*(.+?)\\s*$");
				if (!match.Success || !(match.Groups[1].Value.Trim() == "1.0.1"))
				{
					((BaseUnityPlugin)this).Config.Clear();
					if (File.Exists(configFilePath))
					{
						File.Delete(configFilePath);
					}
					((BaseUnityPlugin)this).Config.Reload();
					((BaseUnityPlugin)this).Logger.LogWarning((object)"Config version changed, reset to defaults.");
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Config reset: " + ex.Message));
			}
		}

		private void DetachFromManager()
		{
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
		}

		private static bool CanEdit(MetaManager m, out string reason)
		{
			if (!_compat.CoreEditAvailable)
			{
				reason = (((Object)(object)_instance != (Object)null && _instance._useChinese) ? "兼容自检失败:游戏接口可能已变化,编辑功能已禁用。" : "Compatibility check failed: editing disabled.");
				return false;
			}
			if ((Object)(object)m == (Object)null)
			{
				reason = "MetaManager 尚未就绪。";
				return false;
			}
			if (!GetField<bool>(F_SaveReady, m, out var v) || !v)
			{
				reason = "装饰存档尚未就绪。";
				return false;
			}
			if (m.cosmeticAssets == null || m.cosmeticAssets.Count == 0)
			{
				reason = "没有读取到装饰资源。";
				return false;
			}
			reason = null;
			return true;
		}

		private static bool GetState(MetaManager m, out CosmeticState s)
		{
			s = null;
			if (!GetField<List<int>>(F_Unlocks, m, out var v) || !GetField<List<int>>(F_History, m, out var v2) || !GetField<List<int>>(F_Equipped, m, out var v3) || !GetField<List<List<int>>>(F_Presets, m, out var v4) || !GetField<List<List<int>>>(F_ColorPresets, m, out var v5) || !GetField<int[]>(F_ColorsEquipped, m, out var v6))
			{
				return false;
			}
			s = new CosmeticState
			{
				Unlocks = v,
				History = v2,
				Equipped = v3,
				CosmeticPresets = v4,
				ColorPresets = v5,
				ColorsEquipped = v6
			};
			return true;
		}

		private static bool GetField<T>(FieldInfo f, object o, out T v)
		{
			v = default(T);
			if (f == null || o == null)
			{
				return false;
			}
			try
			{
				object value = f.GetValue(o);
				if (value is T)
				{
					T val = (T)value;
					v = val;
					return true;
				}
			}
			catch
			{
			}
			return false;
		}

		private static bool ValidIndex(MetaManager m, int i)
		{
			if ((Object)(object)m != (Object)null && m.cosmeticAssets != null && i >= 0 && i < m.cosmeticAssets.Count)
			{
				return (Object)(object)m.cosmeticAssets[i] != (Object)null;
			}
			return false;
		}

		private static void RemoveAll(List<int> l, int v)
		{
			if (l == null)
			{
				return;
			}
			for (int num = l.Count - 1; num >= 0; num--)
			{
				if (l[num] == v)
				{
					l.RemoveAt(num);
				}
			}
		}

		private static void ResetList(List<int> l)
		{
			if (l != null)
			{
				for (int i = 0; i < l.Count; i++)
				{
					l[i] = 0;
				}
			}
		}

		private static void ResetArr(int[] a)
		{
			if (a != null)
			{
				for (int i = 0; i < a.Length; i++)
				{
					a[i] = 0;
				}
			}
		}

		private static void ResetColorFor(CosmeticAsset a, int[] eq, List<List<int>> pr)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected I4, but got Unknown
			if ((Object)(object)a == (Object)null)
			{
				return;
			}
			int num = (int)a.type;
			if (eq != null && num >= 0 && num < eq.Length)
			{
				eq[num] = 0;
			}
			if (pr == null)
			{
				return;
			}
			foreach (List<int> item in pr)
			{
				if (item != null && num >= 0 && num < item.Count)
				{
					item[num] = 0;
				}
			}
		}

		private static Rect R(float x, float y, float w, float h)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			return new Rect(x, y, w, h);
		}

		private static string FormatName(CosmeticAsset a, int i)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected I4, but got Unknown
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			string text = (string.IsNullOrWhiteSpace(a.assetName) ? ((Object)a).name : a.assetName);
			if (string.IsNullOrWhiteSpace(text))
			{
				text = "Unnamed";
			}
			Rarity rarity = a.rarity;
			string text2 = (int)rarity switch
			{
				0 => "普通", 
				1 => "稀有", 
				2 => "珍贵", 
				3 => "超稀有", 
				_ => ((object)(Rarity)(ref a.rarity)).ToString(), 
			};
			if ((Object)(object)_instance != (Object)null && _instance._useChinese)
			{
				string text3 = TranslateCosmeticName(text);
				return $"[{i}] {TranslateType(a.type)} | {text3}({text}) | {text2}";
			}
			return $"[{i}] {a.type} | {text} | {a.rarity}";
		}

		private static string TranslateCosmeticName(string name)
		{
			if (string.IsNullOrWhiteSpace(name))
			{
				return "未知";
			}
			string text = name.Trim();
			if (CosmeticNameMap.TryGetValue(text, out var value))
			{
				return value;
			}
			return text;
		}

		private static string BuildSearch(CosmeticAsset a, string dn)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)a == (Object)null))
			{
				return $"{dn}\n{a.assetName}\n{((Object)a).name}\n{TranslateType(a.type)}\n{a.type}\n{a.rarity}";
			}
			return dn ?? "";
		}

		private static string TranslateCategory(CosmeticCategoryAsset cat)
		{
			if ((Object)(object)cat == (Object)null)
			{
				return "未知";
			}
			if ((Object)(object)_instance != (Object)null && !_instance._useChinese)
			{
				string text = (string.IsNullOrWhiteSpace(cat.categoryName) ? ((Object)cat).name : cat.categoryName);
				if (!string.IsNullOrWhiteSpace(text))
				{
					return text.Trim();
				}
				return "Unknown";
			}
			string text2 = null;
			try
			{
				LocalizedAsset localizedName = cat.localizedName;
				text2 = ((localizedName != null) ? localizedName.GetLocalizedString() : null);
			}
			catch
			{
			}
			if (string.IsNullOrWhiteSpace(text2))
			{
				text2 = (string.IsNullOrWhiteSpace(cat.categoryName) ? ((Object)cat).name : cat.categoryName);
			}
			return MapCat(text2);
		}

		private static string MapCat(string raw)
		{
			if (string.IsNullOrWhiteSpace(raw))
			{
				return "未知";
			}
			string text = raw.Trim().ToLowerInvariant();
			if (text.Contains("head") || raw.Contains("头"))
			{
				return "头部";
			}
			if (text.Contains("body") || raw.Contains("身"))
			{
				return "身体";
			}
			if (text.Contains("arm") || text.Contains("hand") || text.Contains("grab") || raw.Contains("手"))
			{
				return "手部";
			}
			if (text.Contains("leg") || text.Contains("foot") || raw.Contains("腿") || raw.Contains("脚"))
			{
				return "腿脚";
			}
			if (text.Contains("face") || text.Contains("eye") || text.Contains("ear") || raw.Contains("脸"))
			{
				return "脸部";
			}
			return raw.Trim();
		}

		private static string TranslateType(CosmeticType t)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Expected I4, but got Unknown
			if ((Object)(object)_instance != (Object)null && !_instance._useChinese)
			{
				return ((object)(CosmeticType)(ref t)).ToString();
			}
			return (int)t switch
			{
				0 => "帽子", 
				1 => "右臂", 
				2 => "左臂", 
				3 => "右腿", 
				4 => "左腿", 
				5 => "头顶模型", 
				6 => "头底模型", 
				7 => "上身模型", 
				8 => "下身模型", 
				9 => "右臂模型", 
				10 => "左臂模型", 
				11 => "右腿模型", 
				12 => "左腿模型", 
				13 => "抓取器", 
				14 => "右眼睑", 
				15 => "左眼睑", 
				16 => "上身覆盖", 
				17 => "耳朵", 
				18 => "眼镜", 
				19 => "右脚", 
				20 => "上身", 
				21 => "下身", 
				22 => "左脚", 
				23 => "下身覆盖", 
				24 => "头顶覆盖", 
				25 => "头底覆盖", 
				26 => "右臂覆盖", 
				27 => "左臂覆盖", 
				28 => "右腿覆盖", 
				29 => "左腿覆盖", 
				30 => "头底", 
				31 => "鼻子", 
				32 => "嘴巴", 
				_ => ((object)(CosmeticType)(ref t)).ToString(), 
			};
		}
	}
}