Decompiled source of SaveManager v0.4.6

BepInEx/plugins/SaveManager/SaveManager.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyFileVersion("0.4.6.0")]
[assembly: AssemblyInformationalVersion("0.4.6")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("0.4.6.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SaveManager
{
	internal static class Lang
	{
		private static bool? _zh;

		private static readonly Dictionary<string, string> En = new Dictionary<string, string>
		{
			["存档"] = "Save",
			["打开存档页面(SM · Save Manager)"] = "Open the save slots page (SM)",
			["打开存档页面"] = "Open the save slots page",
			["找不到界面,无法打开存档窗口"] = "UI not found, cannot open the save window",
			["操作"] = "Actions",
			["+ 新建存档"] = "+ New save",
			["读取最近一档"] = "Load latest",
			["打开文件夹"] = "Open folder",
			["已选存档"] = "Selected slot",
			["读取此档"] = "Load this slot",
			["回滚上一档"] = "Restore previous",
			["删除此档"] = "Delete this slot",
			["存档设置"] = "Save options",
			["设置"] = "Settings",
			["存档选项与设置 ▸"] = "Save options & settings ▸",
			["← 返回存档列表"] = "← Back to slots",
			["游戏内读档"] = "In-game load",
			["自动存档"] = "Auto save",
			["标记作弊(成就关闭)"] = "Mark cheated (no achievements)",
			["沙盒不标作弊"] = "No cheat mark in sandbox",
			["联机允许存读档"] = "Allow in multiplayer",
			["覆盖前保留上一档"] = "Keep previous backup",
			["绕过教程门禁"] = "Bypass tutorial gate",
			["行为"] = "Behaviour",
			["存档标记"] = "Save marking",
			["其它"] = "Other",
			["开"] = "ON",
			["关"] = "OFF",
			["新名字"] = "New name",
			["单人"] = "SP",
			["联机"] = "MP",
			["沙盒"] = "sandbox",
			["作弊"] = "cheated",
			["(还没有存档:进游戏按 F5,或点左边「新建存档」)"] = "(No saves yet: press F5 in game, or use \"+ New save\")",
			["档"] = "slots",
			["(无上限,按时间倒序)"] = "  (unlimited, newest first)",
			["已选:"] = "Selected: ",
			["共 "] = ""
		};

		public static string Mode
		{
			get
			{
				try
				{
					string text = ((Plugin.CfgLang != null) ? (Plugin.CfgLang.Value ?? "auto") : "auto");
					text = text.Trim().ToLowerInvariant();
					return (text == "zh" || text == "en") ? text : "auto";
				}
				catch
				{
					return "auto";
				}
			}
		}

		public static bool Zh
		{
			get
			{
				//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_00a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ab: Invalid comparison between Unknown and I4
				//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b0: Invalid comparison between Unknown and I4
				//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b5: Invalid comparison between Unknown and I4
				string mode = Mode;
				if (mode == "zh")
				{
					return true;
				}
				if (mode == "en")
				{
					return false;
				}
				if (_zh.HasValue)
				{
					return _zh.Value;
				}
				bool flag = false;
				try
				{
					string text = Locale.currentLangName ?? "";
					flag = text.IndexOf('中') >= 0 || text.IndexOf("zh", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Chinese", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Mandarin", StringComparison.OrdinalIgnoreCase) >= 0;
					if (!flag && !string.IsNullOrEmpty(text))
					{
						flag = false;
					}
					if (string.IsNullOrEmpty(text))
					{
						SystemLanguage systemLanguage = Application.systemLanguage;
						flag = (int)systemLanguage == 6 || (int)systemLanguage == 40 || (int)systemLanguage == 41;
					}
				}
				catch
				{
					flag = false;
				}
				_zh = flag;
				return flag;
			}
		}

		public static void Invalidate()
		{
			_zh = null;
		}

		public static string T(string zh)
		{
			if (zh == null)
			{
				return null;
			}
			if (Zh)
			{
				return zh;
			}
			if (!En.TryGetValue(zh, out var value))
			{
				return zh;
			}
			return value;
		}

		public static string T(string zh, string en)
		{
			if (!Zh)
			{
				return en;
			}
			return zh;
		}
	}
	internal static class Hotkeys
	{
		public static void PollInGame()
		{
			//IL_000c: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.CfgKeyPanel != null && Input.GetKeyDown(Plugin.CfgKeyPanel.Value))
			{
				SavePage.Open();
			}
			if (Plugin.CfgKeySave != null && Input.GetKeyDown(Plugin.CfgKeySave.Value))
			{
				Plugin.DoSave(null, out var _);
			}
			if (Plugin.CfgKeyLoad != null && Input.GetKeyDown(Plugin.CfgKeyLoad.Value))
			{
				if (Plugin.CfgInGameLoad != null && Plugin.CfgInGameLoad.Value)
				{
					Plugin.DoQuickLoad(out var message2);
					Ui.Notify(message2);
				}
				else
				{
					SavePage.Open();
					Ui.Notify("游戏内读档没开:在「存档」分页里选档,或打开 ExperimentalInGameLoad");
				}
			}
		}

		public static void PollMenu()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.CfgKeyPanel != null && Input.GetKeyDown(Plugin.CfgKeyPanel.Value))
			{
				SavePage.Open();
			}
		}
	}
	[HarmonyPatch(typeof(PlayerCamera), "HandleInput")]
	internal static class Patch_PlayerCamera_HandleInput
	{
		private static void Prefix()
		{
			try
			{
				Hotkeys.PollInGame();
			}
			catch (Exception ex)
			{
				Log.Error("热键处理异常:" + ex);
			}
		}
	}
	[HarmonyPatch(typeof(PreRunScript), "Update")]
	internal static class Patch_PreRunScript_Update
	{
		private static void Prefix()
		{
			try
			{
				Hotkeys.PollMenu();
			}
			catch (Exception ex)
			{
				Log.Error("主菜单热键异常:" + ex);
			}
		}
	}
	[HarmonyPatch(typeof(ConsoleScript), "RegisterAllCommands")]
	internal static class Patch_ConsoleCommands
	{
		private static void Postfix(ConsoleScript __instance)
		{
			try
			{
				ConsoleCommands.Register(__instance);
			}
			catch (Exception ex)
			{
				Log.Error("注册控制台命令失败:" + ex);
			}
		}
	}
	internal static class ConsoleCommands
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Func<object, bool> <>9__2_0;

			public static Action <>9__2_1;

			public static Func<SlotMeta, string> <>9__2_10;

			public static Action <>9__2_2;

			public static Action <>9__2_3;

			public static Action <>9__2_4;

			public static Action <>9__2_5;

			public static Action <>9__2_6;

			public static Action <>9__2_7;

			public static Action <>9__2_8;

			public static Action <>9__2_9;

			internal bool <Register>b__2_0(object c)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				return ((Command)c).name == "cssave";
			}

			internal void <Register>b__2_1(string[] a)
			{
				Ui.Notify(Plugin.DoSave((a.Length > 1) ? string.Join(" ", a.Skip(1)) : null, out var message) ? message : ("失败:" + message));
			}

			internal void <Register>b__2_2(string[] a)
			{
				Ui.Notify((SlotStore.List().Count == 0) ? "还没有任何存档槽" : string.Join("\n", from s in SlotStore.List()
					select string.Format("{0}  D{1}  {2}  {3}{4}{5}", s.name, s.biome, s.DurationText(), (s.mode == "mp") ? "联机" : "单人", s.sandbox ? " 沙盒" : "", s.cheated ? " 作弊" : "")));
			}

			internal string <Register>b__2_10(SlotMeta s)
			{
				return string.Format("{0}  D{1}  {2}  {3}{4}{5}", s.name, s.biome, s.DurationText(), (s.mode == "mp") ? "联机" : "单人", s.sandbox ? " 沙盒" : "", s.cheated ? " 作弊" : "");
			}

			internal void <Register>b__2_3(string[] a)
			{
				if (a.Length < 2)
				{
					throw new Exception("用法:csload <槽名>");
				}
				Ui.Notify(Plugin.DoLoad(a[1], out var message) ? message : ("失败:" + message));
			}

			internal void <Register>b__2_4(string[] a)
			{
				if (!Directory.Exists(Paths.SlotRoot))
				{
					Directory.CreateDirectory(Paths.SlotRoot);
				}
				PreRunScript.OpenInFileBrowser(Paths.SlotRoot);
				Ui.Notify("已打开:" + Paths.SlotRoot);
			}

			internal void <Register>b__2_5(string[] a)
			{
				if (a.Length < 2)
				{
					throw new Exception("用法:csdel <槽名>");
				}
				Ui.Notify(SlotStore.Delete(a[1], out var error) ? ("已删除:" + a[1]) : ("失败:" + error));
			}

			internal void <Register>b__2_6(string[] a)
			{
				if (a.Length < 3)
				{
					throw new Exception("用法:csrename <旧名> <新名>");
				}
				Ui.Notify(SlotStore.Rename(a[1], a[2], out var error) ? "已改名" : ("失败:" + error));
			}

			internal void <Register>b__2_7(string[] a)
			{
				if (a.Length < 2)
				{
					throw new Exception("用法:csrollback <槽名>");
				}
				Ui.Notify(SlotStore.RestoreBackup(a[1], out var error) ? ("已回滚:" + a[1]) : ("失败:" + error));
			}

			internal void <Register>b__2_8(string[] a)
			{
				if (a.Length < 2)
				{
					throw new Exception("用法:csexport <槽名>");
				}
				Ui.Notify(SlotStore.ExportToGameSave(a[1], out var error) ? ("已铺成 save.sv:" + a[1]) : ("失败:" + error));
			}

			internal void <Register>b__2_9(string[] a)
			{
				SavePage.Open();
			}
		}

		private static readonly FieldInfo CommandsField = typeof(ConsoleScript).GetField("Commands", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static IList _list;

		public static void Register(ConsoleScript instance)
		{
			//IL_009d: 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_00a8: Expected O, but got Unknown
			//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_00f2: Expected O, but got Unknown
			//IL_0116: 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_0121: Expected O, but got Unknown
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Expected O, but got Unknown
			//IL_018f: 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_019a: Expected O, but got Unknown
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Expected O, but got Unknown
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Expected O, but got Unknown
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Expected O, but got Unknown
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Expected O, but got Unknown
			if (CommandsField == null)
			{
				Log.Warn("找不到 ConsoleScript.Commands 字段");
				return;
			}
			_list = CommandsField.GetValue(CommandsField.IsStatic ? null : instance) as IList;
			if (_list == null)
			{
				Log.Warn("ConsoleScript.Commands 不是 IList");
			}
			else
			{
				if (_list.Cast<object>().Any((object c) => ((Command)c).name == "cssave"))
				{
					return;
				}
				object obj = <>c.<>9__2_1;
				if (obj == null)
				{
					Action val = delegate(string[] a)
					{
						Ui.Notify(Plugin.DoSave((a.Length > 1) ? string.Join(" ", a.Skip(1)) : null, out var message) ? message : ("失败:" + message));
					};
					<>c.<>9__2_1 = val;
					obj = (object)val;
				}
				Add("cssave", "[存档] 把当前局面存成一个新槽(不传名字=自动命名)", (Action)obj, ("name", "可选,存档名(可含中文)"));
				object obj2 = <>c.<>9__2_2;
				if (obj2 == null)
				{
					Action val2 = delegate
					{
						Ui.Notify((SlotStore.List().Count == 0) ? "还没有任何存档槽" : string.Join("\n", from s in SlotStore.List()
							select string.Format("{0}  D{1}  {2}  {3}{4}{5}", s.name, s.biome, s.DurationText(), (s.mode == "mp") ? "联机" : "单人", s.sandbox ? " 沙盒" : "", s.cheated ? " 作弊" : "")));
					};
					<>c.<>9__2_2 = val2;
					obj2 = (object)val2;
				}
				Add("cslots", "[存档] 列出所有存档槽", (Action)obj2, null);
				object obj3 = <>c.<>9__2_3;
				if (obj3 == null)
				{
					Action val3 = delegate(string[] a)
					{
						if (a.Length < 2)
						{
							throw new Exception("用法:csload <槽名>");
						}
						Ui.Notify(Plugin.DoLoad(a[1], out var message) ? message : ("失败:" + message));
					};
					<>c.<>9__2_3 = val3;
					obj3 = (object)val3;
				}
				Add("csload", "[存档] 读取指定槽(回主菜单流程)", (Action)obj3, ("name", "槽名(cslots 里看到的那个)"));
				object obj4 = <>c.<>9__2_4;
				if (obj4 == null)
				{
					Action val4 = delegate
					{
						if (!Directory.Exists(Paths.SlotRoot))
						{
							Directory.CreateDirectory(Paths.SlotRoot);
						}
						PreRunScript.OpenInFileBrowser(Paths.SlotRoot);
						Ui.Notify("已打开:" + Paths.SlotRoot);
					};
					<>c.<>9__2_4 = val4;
					obj4 = (object)val4;
				}
				Add("csdir", "[存档] 打开存档目录", (Action)obj4, null);
				object obj5 = <>c.<>9__2_5;
				if (obj5 == null)
				{
					Action val5 = delegate(string[] a)
					{
						if (a.Length < 2)
						{
							throw new Exception("用法:csdel <槽名>");
						}
						Ui.Notify(SlotStore.Delete(a[1], out var error) ? ("已删除:" + a[1]) : ("失败:" + error));
					};
					<>c.<>9__2_5 = val5;
					obj5 = (object)val5;
				}
				Add("csdel", "[存档] 删除一个槽", (Action)obj5, ("name", "槽名"));
				object obj6 = <>c.<>9__2_6;
				if (obj6 == null)
				{
					Action val6 = delegate(string[] a)
					{
						if (a.Length < 3)
						{
							throw new Exception("用法:csrename <旧名> <新名>");
						}
						Ui.Notify(SlotStore.Rename(a[1], a[2], out var error) ? "已改名" : ("失败:" + error));
					};
					<>c.<>9__2_6 = val6;
					obj6 = (object)val6;
				}
				Add("csrename", "[存档] 给槽改名", (Action)obj6, ("old", "旧名"), ("new", "新名"));
				object obj7 = <>c.<>9__2_7;
				if (obj7 == null)
				{
					Action val7 = delegate(string[] a)
					{
						if (a.Length < 2)
						{
							throw new Exception("用法:csrollback <槽名>");
						}
						Ui.Notify(SlotStore.RestoreBackup(a[1], out var error) ? ("已回滚:" + a[1]) : ("失败:" + error));
					};
					<>c.<>9__2_7 = val7;
					obj7 = (object)val7;
				}
				Add("csrollback", "[存档] 回滚到该槽的上一档备份", (Action)obj7, ("name", "槽名"));
				object obj8 = <>c.<>9__2_8;
				if (obj8 == null)
				{
					Action val8 = delegate(string[] a)
					{
						if (a.Length < 2)
						{
							throw new Exception("用法:csexport <槽名>");
						}
						Ui.Notify(SlotStore.ExportToGameSave(a[1], out var error) ? ("已铺成 save.sv:" + a[1]) : ("失败:" + error));
					};
					<>c.<>9__2_8 = val8;
					obj8 = (object)val8;
				}
				Add("csexport", "[存档] 把槽铺成游戏当前存档(游戏外换档同效)", (Action)obj8, ("name", "槽名"));
				object obj9 = <>c.<>9__2_9;
				if (obj9 == null)
				{
					Action val9 = delegate
					{
						SavePage.Open();
					};
					<>c.<>9__2_9 = val9;
					obj9 = (object)val9;
				}
				Add("csslots", "[存档] 打开设置里的「存档」分页", (Action)obj9, null);
				Log.Info("控制台命令已注册(cssave / cslots / csload / csdir / csdel / csrename / csrollback / csexport / csslots)");
			}
		}

		private static void Add(string name, string desc, Action action, params (string, string)[] argDesc)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			try
			{
				_list.Add((object?)new Command(name, desc, action, (Dictionary<int, List<string>>)null, argDesc));
			}
			catch (Exception ex)
			{
				Log.Warn("加命令失败 " + name + ":" + ex.Message);
			}
		}
	}
	internal static class Paths
	{
		public static string DataPath => Application.persistentDataPath;

		public static string VanillaSave => Path.Combine(DataPath, "save.sv");

		public static string MpSaveDir => Path.Combine(DataPath, "mp_save");

		public static string SlotRoot
		{
			get
			{
				string text = ((Plugin.CfgRootDir != null) ? Plugin.CfgRootDir.Value : string.Empty);
				if (!string.IsNullOrWhiteSpace(text))
				{
					try
					{
						return Path.GetFullPath(text.Trim());
					}
					catch
					{
					}
				}
				return Path.Combine(DataPath, "SaveSlots");
			}
		}

		public static bool MpPresent => Directory.Exists(MpSaveDir);

		public static void EnsureRoot()
		{
			Directory.CreateDirectory(SlotRoot);
		}

		public static string SlotDir(string slotName)
		{
			return Path.Combine(SlotRoot, slotName);
		}

		public static string SlotSave(string slotName)
		{
			return Path.Combine(SlotDir(slotName), "save.sv");
		}

		public static string SlotMp(string slotName)
		{
			return Path.Combine(SlotDir(slotName), "mp");
		}

		public static string SlotMeta(string slotName)
		{
			return Path.Combine(SlotDir(slotName), "meta.json");
		}

		public static string SlotBackup(string slotName)
		{
			return Path.Combine(SlotDir(slotName), "backup");
		}

		public static string SafeName(string raw)
		{
			if (string.IsNullOrWhiteSpace(raw))
			{
				return null;
			}
			StringBuilder stringBuilder = new StringBuilder(raw.Length);
			string text = raw.Trim();
			foreach (char c in text)
			{
				if (Array.IndexOf(Path.GetInvalidFileNameChars(), c) >= 0 || c == '\\' || c == '/')
				{
					stringBuilder.Append('_');
				}
				else
				{
					stringBuilder.Append(c);
				}
			}
			string text2 = stringBuilder.ToString().Trim('.', ' ');
			if (text2.Length > 80)
			{
				text2 = text2.Substring(0, 80);
			}
			if (text2.Length != 0)
			{
				return text2;
			}
			return null;
		}
	}
	internal static class PauseButton
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__3_0;

			internal void <Install>b__3_0()
			{
				try
				{
					PlayerCamera.PlayUISound("miniClick", 1f);
				}
				catch
				{
				}
				SaveWindow.Open();
			}
		}

		private static GameObject _go;

		private static Sprite _glyph;

		private static readonly FieldInfo ButtonPosField = typeof(PauseHandler).GetField("buttonPos", BindingFlags.Instance | BindingFlags.NonPublic);

		public static void Install(PauseHandler handler)
		{
			//IL_01c8: 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_020c: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Expected O, but got Unknown
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Expected O, but got Unknown
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)_go != (Object)null || (Object)(object)handler == (Object)null || handler.buttons == null || handler.buttons.Count == 0)
				{
					return;
				}
				int num = handler.buttons.Count - 1;
				RectTransform val = handler.buttons[num];
				if ((Object)(object)val == (Object)null || (Object)(object)((Transform)val).parent == (Object)null)
				{
					return;
				}
				GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, ((Transform)val).parent);
				((Object)val2).name = "SM.SaveButton";
				val2.SetActive(true);
				RectTransform component = val2.GetComponent<RectTransform>();
				((Transform)component).localScale = Vector3.one;
				Sprite sprite = Glyph();
				List<Image> list = ImagesOf(val2);
				int num2 = FindIconIndex(handler, num, list.Count);
				if (num2 >= 0 && num2 < list.Count && (Object)(object)list[num2] != (Object)null)
				{
					Image obj = list[num2];
					obj.sprite = sprite;
					((Graphic)obj).color = Color.white;
					obj.type = (Type)0;
					obj.preserveAspect = true;
				}
				Button component2 = val2.GetComponent<Button>();
				if ((Object)(object)component2 == (Object)null)
				{
					Object.Destroy((Object)(object)val2);
					return;
				}
				component2.onClick = new ButtonClickedEvent();
				ButtonClickedEvent onClick = component2.onClick;
				object obj2 = <>c.<>9__3_0;
				if (obj2 == null)
				{
					UnityAction val3 = delegate
					{
						try
						{
							PlayerCamera.PlayUISound("miniClick", 1f);
						}
						catch
						{
						}
						SaveWindow.Open();
					};
					<>c.<>9__3_0 = val3;
					obj2 = (object)val3;
				}
				((UnityEvent)onClick).AddListener((UnityAction)obj2);
				try
				{
					UITooltip val4 = val2.GetComponent<UITooltip>();
					if ((Object)(object)val4 == (Object)null)
					{
						val4 = val2.AddComponent<UITooltip>();
					}
					val4.skipLocale = true;
					val4.tipName = Lang.T("存档");
					val4.tipDesc = Lang.T("打开存档页面(SM · Save Manager)", "Open the save slots page (SM)");
				}
				catch (Exception ex)
				{
					Log.Warn("tooltip 设置失败:" + ex.Message);
				}
				((Transform)component).localPosition = Vector2.op_Implicit(ComputePos(handler, val, component));
				handler.buttons.Add(component);
				((ButtonPosField != null) ? (ButtonPosField.GetValue(handler) as List<Vector2>) : null)?.Add(Vector2.op_Implicit(((Transform)component).localPosition));
				_go = val2;
				Log.Info("ESC 暂停菜单:已加入圆形存档按钮(克隆自原版按钮)");
			}
			catch (Exception ex2)
			{
				Log.Error("加暂停菜单按钮失败:" + ex2);
			}
		}

		private static int FindIconIndex(PauseHandler handler, int templateIdx, int selfCount)
		{
			try
			{
				if (handler.buttons.Count < 2)
				{
					return (selfCount > 1) ? (selfCount - 1) : 0;
				}
				RectTransform val = null;
				for (int i = 0; i < handler.buttons.Count; i++)
				{
					if (i != templateIdx && !((Object)(object)handler.buttons[i] == (Object)null))
					{
						val = handler.buttons[i];
						break;
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					return (selfCount > 1) ? (selfCount - 1) : 0;
				}
				List<Image> list = ImagesOf(((Component)handler.buttons[templateIdx]).gameObject);
				List<Image> list2 = ImagesOf(((Component)val).gameObject);
				int num = Mathf.Min(list.Count, list2.Count);
				for (int j = 0; j < num; j++)
				{
					if (!((Object)(object)list[j] == (Object)null) && !((Object)(object)list2[j] == (Object)null) && (Object)(object)list[j].sprite != (Object)(object)list2[j].sprite)
					{
						return j;
					}
				}
				return (selfCount > 0) ? (selfCount - 1) : 0;
			}
			catch (Exception ex)
			{
				Log.Warn("定位图标层失败:" + ex.Message);
				return 0;
			}
		}

		private static List<Image> ImagesOf(GameObject root)
		{
			List<Image> list = new List<Image>();
			if ((Object)(object)root == (Object)null)
			{
				return list;
			}
			Image component = root.GetComponent<Image>();
			if ((Object)(object)component != (Object)null)
			{
				list.Add(component);
			}
			Image[] componentsInChildren = root.GetComponentsInChildren<Image>(true);
			foreach (Image val in componentsInChildren)
			{
				if ((Object)(object)((Component)val).gameObject != (Object)(object)root)
				{
					list.Add(val);
				}
			}
			return list;
		}

		private static Vector2 ComputePos(PauseHandler handler, RectTransform template, RectTransform self)
		{
			//IL_0008: 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_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_00a6: 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_00b0: 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_00c1: 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_009f: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: 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_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			List<RectTransform> buttons = handler.buttons;
			float num = ((self.sizeDelta.x > 1f) ? self.sizeDelta.x : 64f);
			if (buttons.Count == 0)
			{
				return Vector2.op_Implicit(((Transform)template).localPosition);
			}
			RectTransform val = null;
			for (int i = 0; i < buttons.Count; i++)
			{
				RectTransform val2 = buttons[i];
				if (!((Object)(object)val2 == (Object)null) && ((Object)(object)val == (Object)null || ((Transform)val2).localPosition.x > ((Transform)val).localPosition.x))
				{
					val = val2;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				return Vector2.op_Implicit(((Transform)template).localPosition);
			}
			Vector2 val3 = Vector2.op_Implicit(((Transform)val).localPosition);
			Vector2 val4 = default(Vector2);
			((Vector2)(ref val4))..ctor(val3.x + num * 0.95f, val3.y + num * 0.97f);
			Transform parent = ((Transform)self).parent;
			RectTransform val5 = (RectTransform)(object)((parent is RectTransform) ? parent : null);
			if ((Object)(object)val5 != (Object)null)
			{
				Rect rect = val5.rect;
				if (((Rect)(ref rect)).width > 1f)
				{
					rect = val5.rect;
					float num2 = ((Rect)(ref rect)).width * 0.5f;
					rect = val5.rect;
					float num3 = ((Rect)(ref rect)).height * 0.5f;
					if (val4.x + num * 0.5f > num2)
					{
						val4.x = num2 - num * 0.7f;
					}
					if (val4.y + num * 0.5f > num3)
					{
						val4.y = num3 - num * 0.7f;
					}
				}
			}
			return val4;
		}

		private static Sprite Glyph()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_006c: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_glyph != (Object)null)
			{
				return _glyph;
			}
			Texture2D val = new Texture2D(128, 128, (TextureFormat)4, false);
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Texture)val).filterMode = (FilterMode)1;
			Color32[] array = (Color32[])(object)new Color32[16384];
			Color32 val2 = default(Color32);
			((Color32)(ref val2))..ctor((byte)0, (byte)0, (byte)0, (byte)0);
			Color32 val3 = default(Color32);
			((Color32)(ref val3))..ctor(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = val2;
			}
			float num = 63.5f;
			float num2 = 63.5f;
			for (int j = 0; j < 128; j++)
			{
				for (int k = 0; k < 128; k++)
				{
					float num3 = (float)k - num;
					float num4 = (float)j - num2;
					float num5 = Mathf.Sqrt(num3 * num3 + num4 * num4);
					if (num5 <= 61f && num5 >= 56.5f)
					{
						array[j * 128 + k] = val3;
					}
				}
			}
			Fill(array, 128, 46, 36, 82, 92, val3);
			Fill(array, 128, 52, 44, 76, 66, val2);
			Fill(array, 128, 64, 78, 82, 92, val2);
			Fill(array, 128, 68, 82, 76, 90, val3);
			val.SetPixels32(array);
			val.Apply();
			_glyph = Sprite.Create(val, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f), 100f);
			((Object)_glyph).name = "SM.FloppyGlyph";
			return _glyph;
		}

		private static void Fill(Color32[] px, int size, int x0, int y0, int x1, int y1, Color32 c)
		{
			//IL_001a: 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)
			for (int i = Mathf.Max(0, y0); i <= Mathf.Min(size - 1, y1); i++)
			{
				for (int j = Mathf.Max(0, x0); j <= Mathf.Min(size - 1, x1); j++)
				{
					px[i * size + j] = c;
				}
			}
		}
	}
	[HarmonyPatch(typeof(PauseHandler), "Start")]
	internal static class Patch_PauseHandler_Start
	{
		private static void Postfix(PauseHandler __instance)
		{
			try
			{
				PauseButton.Install(__instance);
			}
			catch (Exception ex)
			{
				Log.Error("暂停按钮注入失败:" + ex);
			}
		}
	}
	[BepInPlugin("suzuay.savemanager", "SM (Save Manager)", "0.4.6")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "suzuay.savemanager";

		public const string VersionStr = "0.4.6";

		internal static Plugin Instance;

		internal static ConfigEntry<KeyCode> CfgKeySave;

		internal static ConfigEntry<KeyCode> CfgKeyPanel;

		internal static ConfigEntry<KeyCode> CfgKeyLoad;

		internal static ConfigEntry<bool> CfgCheatMark;

		internal static ConfigEntry<bool> CfgSandboxNoCheat;

		internal static ConfigEntry<bool> CfgInGameLoad;

		internal static ConfigEntry<bool> CfgAllowMp;

		internal static ConfigEntry<bool> CfgKeepBackup;

		internal static ConfigEntry<bool> CfgBypassGate;

		internal static ConfigEntry<bool> CfgAutoSave;

		internal static ConfigEntry<int> CfgAutoSaveMinutes;

		internal static ConfigEntry<string> CfgRootDir;

		internal static ConfigEntry<string> CfgLang;

		private float _autoTimer;

		internal static bool MpAllowed
		{
			get
			{
				if (CfgAllowMp != null)
				{
					return CfgAllowMp.Value;
				}
				return true;
			}
		}

		private void Awake()
		{
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log.Init(((BaseUnityPlugin)this).Logger);
			CfgKeySave = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("键位 Keybinds", "QuickSave", (KeyCode)286, "游戏内随时存一个新槽");
			CfgKeyLoad = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("键位 Keybinds", "QuickLoad", (KeyCode)290, "读最近一次存档(需启用 ExperimentalInGameLoad)");
			CfgKeyPanel = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("键位 Keybinds", "Panel", (KeyCode)289, "打开设置菜单里的「存档」分页");
			CfgCheatMark = ((BaseUnityPlugin)this).Config.Bind<bool>("存档 Slot", "MarkCheatedSave", false, "存档时把本局标记为 cheated(原版语义:成就关闭到重启)。默认关。");
			CfgSandboxNoCheat = ((BaseUnityPlugin)this).Config.Bind<bool>("存档 Slot", "SandboxNoCheatMark", true, "沙盒模式里不标记作弊(沙盒本身就允许随便用控制台)。");
			CfgAllowMp = ((BaseUnityPlugin)this).Config.Bind<bool>("存档 Slot", "AllowInMultiplayer", true, "联机时也允许存/读档(会连同 mp_save 一起收进槽里)。");
			CfgKeepBackup = ((BaseUnityPlugin)this).Config.Bind<bool>("存档 Slot", "KeepLastBackup", true, "覆盖同名槽前,把上一份挪进 backup/。");
			CfgLang = ((BaseUnityPlugin)this).Config.Bind<string>("界面 UI", "Language", "auto", "界面语言:auto=跟随游戏 / zh=中文 / en=English");
			CfgRootDir = ((BaseUnityPlugin)this).Config.Bind<string>("存档 Slot", "SlotRootOverride", "", "留空 = 游戏存档目录下的 SaveSlots\\。");
			CfgBypassGate = ((BaseUnityPlugin)this).Config.Bind<bool>("兼容 Compatibility", "BypassTutorialGate", true, "没做完基础教程(didbasiccourse)时也允许读档:跳过原版「先做教程」的拦截,直接铺档读。沙盒/教程玩家需要。");
			CfgInGameLoad = ((BaseUnityPlugin)this).Config.Bind<bool>("兼容 Compatibility", "ExperimentalInGameLoad", true, "允许游戏内直接读档:存档页点「读取此档」/ F9 会自动回主菜单→铺档→继续。默认开。");
			CfgAutoSave = ((BaseUnityPlugin)this).Config.Bind<bool>("自动存档 AutoSave", "Enabled", false, "定时自动存一个新槽(默认关)");
			CfgAutoSaveMinutes = ((BaseUnityPlugin)this).Config.Bind<int>("自动存档 AutoSave", "Minutes", 5, "自动存档间隔(分钟)");
			try
			{
				new Harmony("suzuay.savemanager").PatchAll();
				Log.Info("Harmony 补丁已打上");
			}
			catch (Exception ex)
			{
				Log.Error("Harmony 补丁失败:" + ex);
			}
			Log.Info("存档根目录:" + Paths.SlotRoot);
			Log.Info("联机存档目录存在:" + Paths.MpPresent);
		}

		private void Update()
		{
			if (CfgAutoSave == null || !CfgAutoSave.Value)
			{
				return;
			}
			if (!SlotStore.InWorld)
			{
				_autoTimer = 0f;
				return;
			}
			_autoTimer += Time.unscaledDeltaTime;
			float num = (float)Mathf.Max(1, CfgAutoSaveMinutes.Value) * 60f;
			if (!(_autoTimer < num))
			{
				_autoTimer = 0f;
				if (!SlotStore.Capture(null, out var slotName, out var error))
				{
					Log.Warn("自动存档失败:" + error);
				}
				else
				{
					Ui.Notify("已自动存档:" + slotName);
				}
			}
		}

		public static void SaveConfig()
		{
			try
			{
				if ((Object)(object)Instance != (Object)null && ((BaseUnityPlugin)Instance).Config != null)
				{
					((BaseUnityPlugin)Instance).Config.Save();
				}
			}
			catch (Exception ex)
			{
				Log.Warn("保存配置失败:" + ex.Message);
			}
		}

		public static bool DoSave(string name, out string message)
		{
			if (!SlotStore.Capture(name, out var slotName, out var error))
			{
				message = error;
				return false;
			}
			message = "已存档:" + slotName;
			Ui.Notify(message);
			return true;
		}

		public static bool DoLoad(string slotName, out string message)
		{
			if (string.IsNullOrEmpty(slotName))
			{
				message = "没有选中存档槽";
				return false;
			}
			if (!Directory.Exists(Paths.SlotDir(slotName)))
			{
				message = "槽不存在:" + slotName;
				return false;
			}
			bool flag = SlotStore.ReadMeta(slotName)?.sandbox ?? false;
			if (flag != Sandbox.IsActive)
			{
				message = (flag ? "这是沙盒存档,只能在沙盒场地里读" : "这是实机存档,沙盒场地里读不了");
				return false;
			}
			if (SlotStore.InWorld && (CfgInGameLoad == null || !CfgInGameLoad.Value))
			{
				message = "游戏内读档没开(ExperimentalInGameLoad=false):先在暂停菜单里选档";
				return false;
			}
			message = "正在读档:" + slotName;
			((MonoBehaviour)Instance).StartCoroutine(LoadRoutine(slotName));
			return true;
		}

		public static bool DoQuickLoad(out string message)
		{
			bool sandbox = Sandbox.IsActive;
			List<SlotMeta> list = (from s in SlotStore.List()
				where s.sandbox == sandbox
				select s).ToList();
			if (list.Count == 0)
			{
				message = "当前模式还没有任何存档槽";
				return false;
			}
			return DoLoad(list[0].name, out message);
		}

		public static void OpenSavePage()
		{
			SavePage.Open();
		}

		private static IEnumerator LoadRoutine(string slotName)
		{
			if (SlotStore.InWorld)
			{
				try
				{
					if ((Object)(object)PauseHandler.main != (Object)null && PauseHandler.paused)
					{
						PauseHandler.TogglePause();
					}
				}
				catch (Exception ex)
				{
					Log.Warn("解除暂停失败:" + ex.Message);
				}
				PreRunScript oldPre = PreRunScript.instance;
				try
				{
					PlayerCamera.main.ToMainMenu();
				}
				catch (Exception ex2)
				{
					Log.Error("回主菜单失败:" + ex2.Message);
				}
				float waited = 0f;
				while (waited < 12f)
				{
					PreRunScript instance = PreRunScript.instance;
					if ((Object)(object)instance != (Object)null && (Object)(object)instance != (Object)(object)oldPre)
					{
						break;
					}
					waited += Time.unscaledDeltaTime;
					yield return null;
				}
				Log.Info("等主菜单结束,等待 " + waited.ToString("0.0") + "s");
				yield return null;
				yield return null;
			}
			if (!SlotStore.PrepareLoad(slotName, out var error))
			{
				Log.Error(error);
				Ui.Notify("读档失败:" + error);
				yield break;
			}
			SaveSystem.loadedRun = true;
			PreRunScript instance2 = PreRunScript.instance;
			if ((Object)(object)instance2 == (Object)null)
			{
				Log.Error("找不到 PreRunScript.instance");
				Ui.Notify("读档失败:找不到主菜单脚本");
				yield break;
			}
			if (PlayerPrefs.GetInt("didbasiccourse") == 0)
			{
				if (CfgBypassGate == null || !CfgBypassGate.Value)
				{
					Ui.Notify("原版要求先做完基础教程才能读档(BypassTutorialGate 可关掉这条限制)");
					yield break;
				}
				Ui.Notify("没做完基础教程 → 走直连读档");
				RawLoad(instance2);
				yield break;
			}
			try
			{
				instance2.LoadRun();
			}
			catch (Exception ex3)
			{
				Log.Error("LoadRun 抛异常:" + ex3);
			}
			Log.Info("已触发读档:" + slotName);
		}

		private static void RawLoad(PreRunScript pre)
		{
			Type typeFromHandle = typeof(PreRunScript);
			try
			{
				FieldInfo field = typeFromHandle.GetField("savedCharacter", BindingFlags.Instance | BindingFlags.NonPublic);
				FieldInfo field2 = typeFromHandle.GetField("characterSelected", BindingFlags.Static | BindingFlags.Public);
				if (field != null && field2 != null)
				{
					field2.SetValue(null, field.GetValue(pre));
				}
				FieldInfo field3 = typeFromHandle.GetField("startedLoading", BindingFlags.Instance | BindingFlags.NonPublic);
				if (field3 != null)
				{
					field3.SetValue(pre, true);
				}
				if ((Object)(object)pre.tutorialWarning != (Object)null)
				{
					pre.tutorialWarning.SetActive(false);
				}
				if ((Object)(object)pre.runSettingsScreen != (Object)null)
				{
					pre.runSettingsScreen.SetActive(false);
				}
			}
			catch (Exception ex)
			{
				Log.Warn("直连读档准备失败:" + ex.Message);
			}
			((MonoBehaviour)Instance).StartCoroutine(SceneLoadRoutine());
		}

		private static IEnumerator SceneLoadRoutine()
		{
			try
			{
				if ((Object)(object)GlobalDark.main != (Object)null)
				{
					GlobalDark.main.Darken();
				}
			}
			catch
			{
			}
			float t = 0f;
			while (t < 6f)
			{
				bool flag = false;
				try
				{
					flag = (Object)(object)GlobalDark.main != (Object)null && GlobalDark.main.IsDarkening();
				}
				catch
				{
				}
				if (!flag)
				{
					break;
				}
				t += Time.unscaledDeltaTime;
				yield return null;
			}
			SceneManager.LoadScene("SampleScene");
		}
	}
	internal static class Log
	{
		private static ManualLogSource _src;

		public static void Init(ManualLogSource src)
		{
			_src = src;
		}

		public static void Info(string m)
		{
			if (_src != null)
			{
				_src.LogInfo((object)m);
			}
			else
			{
				Debug.Log((object)("[SM] " + m));
			}
		}

		public static void Warn(string m)
		{
			if (_src != null)
			{
				_src.LogWarning((object)m);
			}
			else
			{
				Debug.LogWarning((object)("[SM] " + m));
			}
		}

		public static void Error(string m)
		{
			if (_src != null)
			{
				_src.LogError((object)m);
			}
			else
			{
				Debug.LogError((object)("[SM] " + m));
			}
		}
	}
	internal static class Sandbox
	{
		public static bool IsActive
		{
			get
			{
				try
				{
					Type typeFromHandle = typeof(TutorialHandler);
					FieldInfo field = typeFromHandle.GetField("main", BindingFlags.Static | BindingFlags.Public);
					Object val = (Object)((field != null) ? /*isinst with value type is only supported in some contexts*/: null);
					if (val == (Object)null)
					{
						return false;
					}
					FieldInfo field2 = typeFromHandle.GetField("activeCourse", BindingFlags.Instance | BindingFlags.Public);
					if (field2 == null)
					{
						return false;
					}
					object? value = field2.GetValue(val);
					TutorialCourse val2 = (TutorialCourse)((value is TutorialCourse) ? value : null);
					if ((Object)(object)val2 == (Object)null)
					{
						return false;
					}
					string text = val2.LocaleName();
					return !string.IsNullOrEmpty(text) && text.IndexOf("sandbox", StringComparison.OrdinalIgnoreCase) >= 0;
				}
				catch (Exception ex)
				{
					Log.Warn("沙盒检测失败:" + ex.Message);
					return false;
				}
			}
		}
	}
	internal static class Ui
	{
		public static void Notify(string msg)
		{
			Log.Info(msg);
			try
			{
				Type typeFromHandle = typeof(ConsoleScript);
				object obj = typeFromHandle.GetField("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(null);
				if (obj != null)
				{
					typeFromHandle.GetMethod("LogToConsole", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(string) }, null)?.Invoke(obj, new object[1] { msg });
				}
			}
			catch
			{
			}
		}

		public static void Alert(string msg, bool important = false)
		{
			Log.Info(msg);
			try
			{
				if ((Object)(object)PlayerCamera.main != (Object)null)
				{
					PlayerCamera.main.DoAlert(msg, important);
				}
			}
			catch
			{
			}
		}
	}
	internal static class SavePage
	{
		private enum Screen
		{
			Main,
			Options
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__21_0;

			public static Action <>9__32_0;

			public static Action <>9__32_1;

			public static Action <>9__32_2;

			public static Action <>9__32_3;

			public static Action <>9__32_4;

			public static Action <>9__32_5;

			public static Action <>9__32_6;

			public static Action <>9__33_0;

			public static Action <>9__33_1;

			public static Action <>9__33_2;

			public static Action <>9__33_3;

			public static Action<int> <>9__33_5;

			public static Action <>9__33_4;

			public static Func<SlotMeta, bool> <>9__41_1;

			public static Func<SlotMeta, bool> <>9__41_2;

			public static UnityAction<string> <>9__41_3;

			internal void <InstallTab>b__21_0()
			{
				if ((Object)(object)SettingsMenu.instance != (Object)null)
				{
					SettingsMenu.instance.SelectTab(5);
				}
			}

			internal void <BuildLeft>b__32_0()
			{
				Ui.Notify(Plugin.DoSave(null, out var message) ? message : ("存档失败:" + message));
				Rebuild();
			}

			internal void <BuildLeft>b__32_1()
			{
				Ui.Notify(Plugin.DoQuickLoad(out var message) ? message : ("读档失败:" + message));
			}

			internal void <BuildLeft>b__32_2()
			{
				try
				{
					if (!Directory.Exists(Paths.SlotRoot))
					{
						Directory.CreateDirectory(Paths.SlotRoot);
					}
					PreRunScript.OpenInFileBrowser(Paths.SlotRoot);
				}
				catch (Exception ex)
				{
					Ui.Notify("打开目录失败:" + ex.Message);
				}
			}

			internal void <BuildLeft>b__32_3()
			{
				Ui.Notify(Plugin.DoLoad(_selected, out var message) ? message : ("读档失败:" + message));
			}

			internal void <BuildLeft>b__32_4()
			{
				Ui.Notify(SlotStore.RestoreBackup(_selected, out var error) ? ("已回滚:" + _selected) : ("回滚失败:" + error));
				Rebuild();
			}

			internal void <BuildLeft>b__32_5()
			{
				Ui.Notify(SlotStore.Delete(_selected, out var error) ? ("已删除:" + _selected) : ("删除失败:" + error));
				_selected = null;
				Rebuild();
			}

			internal void <BuildLeft>b__32_6()
			{
				_screen = Screen.Options;
				Rebuild();
			}

			internal void <BuildOptions>b__33_0()
			{
				_screen = Screen.Main;
				Rebuild();
			}

			internal void <BuildOptions>b__33_1()
			{
				BoolRow(Lang.T("游戏内读档"), Plugin.CfgInGameLoad);
				BoolRow(Lang.T("自动存档"), Plugin.CfgAutoSave);
				IntRow(Lang.T("自动存档间隔"), Plugin.CfgAutoSaveMinutes, 1, 120);
			}

			internal void <BuildOptions>b__33_2()
			{
				BoolRow(Lang.T("标记作弊(成就关闭)"), Plugin.CfgCheatMark);
				BoolRow(Lang.T("沙盒不标作弊"), Plugin.CfgSandboxNoCheat);
			}

			internal void <BuildOptions>b__33_3()
			{
				BoolRow(Lang.T("联机允许存读档"), Plugin.CfgAllowMp);
				BoolRow(Lang.T("覆盖前保留上一档"), Plugin.CfgKeepBackup);
				BoolRow(Lang.T("绕过教程门禁"), Plugin.CfgBypassGate);
			}

			internal void <BuildOptions>b__33_4()
			{
				DropdownRow("Language / 语言", new string[3]
				{
					Lang.T("跟随游戏", "Follow game"),
					"中文",
					"English"
				}, (Lang.Mode == "zh") ? 1 : ((Lang.Mode == "en") ? 2 : 0), delegate(int idx)
				{
					Plugin.CfgLang.Value = idx switch
					{
						2 => "en", 
						1 => "zh", 
						_ => "auto", 
					};
					Plugin.SaveConfig();
					Lang.Invalidate();
					Rebuild();
				});
			}

			internal void <BuildOptions>b__33_5(int idx)
			{
				Plugin.CfgLang.Value = idx switch
				{
					2 => "en", 
					1 => "zh", 
					_ => "auto", 
				};
				Plugin.SaveConfig();
				Lang.Invalidate();
				Rebuild();
			}

			internal bool <BuildRight>b__41_1(SlotMeta s)
			{
				return s.name != _selected;
			}

			internal bool <BuildRight>b__41_2(SlotMeta s)
			{
				return s.name == _selected;
			}

			internal void <BuildRight>b__41_3(string v)
			{
				try
				{
					if (!SlotStore.Rename(_selected, v, out var error))
					{
						Ui.Notify("改名失败:" + error);
						return;
					}
					Ui.Notify("已改名:" + v);
					_selected = Paths.SafeName(v);
					Rebuild();
				}
				catch (Exception ex)
				{
					Log.Error("改名异常:" + ex);
				}
			}
		}

		public const int TabIndex = 5;

		private const string RowPrefab = "Special/GameSettingLanguage";

		private const string InputPrefab = "Special/GameSettingInt";

		private const float LeftWidth = 196f;

		private const float Gap = 8f;

		private const float TabGap = 4f;

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

		private static RectTransform _content;

		private static RectTransform _leftContent;

		private static RectTransform _rightContent;

		private static ScrollRect _leftScroll;

		private static ScrollRect _rightScroll;

		private static SettingsMenu _menu;

		private static Button _tabButton;

		private static string _selected;

		private static float _pageHeight = 430f;

		private static float _keepLeft = 1f;

		private static float _keepRight = 1f;

		private static Screen _screen = Screen.Main;

		private static int _lastCat = -1;

		private static TMP_FontAsset _font;

		private static float _optY;

		private static readonly HashSet<string> Folded = new HashSet<string>();

		private static float _colWidth = 196f;

		public static void InstallTab(SettingsMenu menu)
		{
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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_00ea: 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)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Expected O, but got Unknown
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Expected O, but got Unknown
			_menu = menu;
			if ((Object)(object)menu == (Object)null || menu.buttons == null || menu.buttons.Count == 0 || ((Object)(object)_tabButton != (Object)null && (Object)(object)((Component)_tabButton).gameObject != (Object)null))
			{
				return;
			}
			Button val = menu.buttons[menu.buttons.Count - 1];
			if ((Object)(object)val == (Object)null || (Object)(object)((Component)val).transform.parent == (Object)null)
			{
				return;
			}
			GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, ((Component)val).transform.parent);
			((Object)val2).name = "SaveManagerTab";
			val2.SetActive(true);
			RectTransform component = ((Component)val).GetComponent<RectTransform>();
			RectTransform component2 = val2.GetComponent<RectTransform>();
			if ((Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null)
			{
				component2.anchorMin = component.anchorMin;
				component2.anchorMax = component.anchorMax;
				component2.pivot = component.pivot;
				component2.sizeDelta = component.sizeDelta;
				component2.anchoredPosition = component.anchoredPosition;
			}
			TextMeshProUGUI[] componentsInChildren = val2.GetComponentsInChildren<TextMeshProUGUI>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				((Behaviour)componentsInChildren[i]).enabled = false;
			}
			Image[] componentsInChildren2 = val2.GetComponentsInChildren<Image>(true);
			foreach (Image val3 in componentsInChildren2)
			{
				if ((Object)(object)((Component)val3).gameObject != (Object)(object)val2)
				{
					((Behaviour)val3).enabled = false;
				}
			}
			AddLabel(val2);
			Button component3 = val2.GetComponent<Button>();
			if ((Object)(object)component3 == (Object)null)
			{
				Object.Destroy((Object)(object)val2);
				return;
			}
			component3.onClick = new ButtonClickedEvent();
			ButtonClickedEvent onClick = component3.onClick;
			object obj = <>c.<>9__21_0;
			if (obj == null)
			{
				UnityAction val4 = delegate
				{
					if ((Object)(object)SettingsMenu.instance != (Object)null)
					{
						SettingsMenu.instance.SelectTab(5);
					}
				};
				<>c.<>9__21_0 = val4;
				obj = (object)val4;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj);
			menu.buttons.Add(component3);
			_tabButton = component3;
			RelayoutTabRow();
			Log.Info("设置页已注册「存档」分页(buttons index " + (menu.buttons.Count - 1) + ")");
		}

		private static void RelayoutTabRow()
		{
			//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_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)_menu == (Object)null || _menu.buttons == null)
				{
					return;
				}
				int count = _menu.buttons.Count;
				int num = count - 1;
				if (num < 1)
				{
					return;
				}
				RectTransform val = FindLayoutGroup(((Object)(object)_tabButton != (Object)null) ? ((Component)_tabButton).transform : null);
				HorizontalLayoutGroup val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<HorizontalLayoutGroup>() : null);
				GridLayoutGroup val3 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<GridLayoutGroup>() : null);
				float num2 = 0f;
				Rect rect;
				for (int i = 0; i < num; i++)
				{
					RectTransform val4 = (((Object)(object)_menu.buttons[i] != (Object)null) ? ((Component)_menu.buttons[i]).GetComponent<RectTransform>() : null);
					if (!((Object)(object)val4 == (Object)null))
					{
						rect = val4.rect;
						float num3;
						if (!(((Rect)(ref rect)).width > 1f))
						{
							num3 = Mathf.Abs(val4.sizeDelta.x);
						}
						else
						{
							rect = val4.rect;
							num3 = ((Rect)(ref rect)).width;
						}
						float num4 = num3;
						if (num4 > num2)
						{
							num2 = num4;
						}
					}
				}
				float num5 = 4f;
				float num6 = 0f;
				if ((Object)(object)val2 != (Object)null)
				{
					num5 = ((HorizontalOrVerticalLayoutGroup)val2).spacing;
					rect = val.rect;
					num6 = ((Rect)(ref rect)).width - (float)((LayoutGroup)val2).padding.left - (float)((LayoutGroup)val2).padding.right;
				}
				else if ((Object)(object)val3 != (Object)null)
				{
					num5 = val3.spacing.x;
					rect = val.rect;
					num6 = ((Rect)(ref rect)).width - (float)((LayoutGroup)val3).padding.left - (float)((LayoutGroup)val3).padding.right;
				}
				float num7;
				if (num6 > 1f)
				{
					num7 = Mathf.Floor((num6 - (float)num * num5) / (float)(num + 1)) - 1f;
				}
				else
				{
					if (!(num2 > 1f))
					{
						return;
					}
					num7 = Mathf.Floor(((float)num * num2 - 4f) / (float)(num + 1)) - 1f;
				}
				num7 = Mathf.Max(24f, num7);
				for (int j = 0; j < count; j++)
				{
					RectTransform val5 = (((Object)(object)_menu.buttons[j] != (Object)null) ? ((Component)_menu.buttons[j]).GetComponent<RectTransform>() : null);
					if ((Object)(object)val5 == (Object)null)
					{
						continue;
					}
					val5.sizeDelta = new Vector2(num7, val5.sizeDelta.y);
					LayoutElement component = ((Component)val5).GetComponent<LayoutElement>();
					if ((Object)(object)component != (Object)null)
					{
						component.preferredWidth = num7;
						if (component.minWidth > num7)
						{
							component.minWidth = num7;
						}
					}
				}
				if ((Object)(object)val != (Object)null)
				{
					LayoutRebuilder.MarkLayoutForRebuild(val);
					Canvas.ForceUpdateCanvases();
					return;
				}
				float num8 = float.MaxValue;
				for (int k = 0; k < num; k++)
				{
					RectTransform component2 = ((Component)_menu.buttons[k]).GetComponent<RectTransform>();
					if ((Object)(object)component2 != (Object)null)
					{
						num8 = Mathf.Min(num8, component2.anchoredPosition.x);
					}
				}
				if (num8 > 1000000f)
				{
					return;
				}
				for (int l = 0; l < count; l++)
				{
					RectTransform component3 = ((Component)_menu.buttons[l]).GetComponent<RectTransform>();
					if (!((Object)(object)component3 == (Object)null))
					{
						component3.anchoredPosition = new Vector2(num8 + (float)l * (num7 + 4f), component3.anchoredPosition.y);
					}
				}
			}
			catch (Exception ex)
			{
				Log.Warn("分页排版修正失败:" + ex.Message);
			}
		}

		private static void AddLabel(GameObject go)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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_0056: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				GameObject val = new GameObject("Label", new Type[1] { typeof(RectTransform) });
				val.transform.SetParent(go.transform, false);
				RectTransform component = val.GetComponent<RectTransform>();
				component.anchorMin = Vector2.zero;
				component.anchorMax = Vector2.one;
				component.offsetMin = new Vector2(2f, 2f);
				component.offsetMax = new Vector2(-2f, -2f);
				TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
				TMP_FontAsset val3 = BorrowFont();
				if ((Object)(object)val3 != (Object)null)
				{
					((TMP_Text)val2).font = val3;
				}
				((TMP_Text)val2).text = "存档";
				((TMP_Text)val2).fontSize = 15f;
				((TMP_Text)val2).alignment = (TextAlignmentOptions)514;
				((Graphic)val2).color = new Color(0.92f, 0.92f, 0.88f, 1f);
				((Graphic)val2).raycastTarget = false;
			}
			catch (Exception ex)
			{
				Log.Warn("分页文字创建失败:" + ex.Message);
			}
		}

		private static TMP_FontAsset BorrowFont()
		{
			if ((Object)(object)_font != (Object)null)
			{
				return _font;
			}
			try
			{
				if ((Object)(object)_menu != (Object)null)
				{
					TextMeshProUGUI[] componentsInChildren = ((Component)_menu).GetComponentsInChildren<TextMeshProUGUI>(true);
					foreach (TextMeshProUGUI val in componentsInChildren)
					{
						if ((Object)(object)((TMP_Text)val).font != (Object)null)
						{
							_font = ((TMP_Text)val).font;
							return _font;
						}
					}
				}
				TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
				if (array != null && array.Length != 0)
				{
					_font = array[0];
				}
			}
			catch
			{
			}
			return _font;
		}

		private static RectTransform FindLayoutGroup(Transform from)
		{
			Transform val = from;
			for (int i = 0; i < 6; i++)
			{
				if (!((Object)(object)val != (Object)null))
				{
					break;
				}
				LayoutGroup component = ((Component)val).GetComponent<LayoutGroup>();
				if ((Object)(object)component != (Object)null)
				{
					Transform transform = ((Component)component).transform;
					return (RectTransform)(object)((transform is RectTransform) ? transform : null);
				}
				val = val.parent;
			}
			return null;
		}

		public static void OnTabSelected(SettingsMenu menu, SettingCategory category)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Invalid comparison between I4 and Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected I4, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected I4, but got Unknown
			_menu = menu;
			ClearRows();
			if ((int)category != 5)
			{
				_lastCat = (int)category;
				return;
			}
			if (_lastCat != (int)category)
			{
				_screen = Screen.Main;
				_lastCat = (int)category;
			}
			try
			{
				BuildPage();
			}
			catch (Exception ex)
			{
				Log.Error("渲染存档页失败:" + ex);
			}
		}

		private static void ClearRows()
		{
			if ((Object)(object)_leftScroll != (Object)null)
			{
				_keepLeft = _leftScroll.verticalNormalizedPosition;
			}
			if ((Object)(object)_rightScroll != (Object)null)
			{
				_keepRight = _rightScroll.verticalNormalizedPosition;
			}
			for (int num = _rows.Count - 1; num >= 0; num--)
			{
				if ((Object)(object)_rows[num] != (Object)null)
				{
					Object.Destroy((Object)(object)_rows[num]);
				}
			}
			_rows.Clear();
			_leftScroll = null;
			_rightScroll = null;
			_leftContent = null;
			_rightContent = null;
		}

		private static void BuildPage()
		{
			//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_0079: 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_0095: 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_0129: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_menu == (Object)null) && !((Object)(object)_menu.content == (Object)null))
			{
				_content = _menu.content;
				float num = PageWidth();
				_pageHeight = PageHeight();
				RectTransform val = NewRect("SaveManager.Page", (Transform)(object)_content);
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor(0.5f, 1f);
				val.anchorMax = val2;
				val.anchorMin = val2;
				val.pivot = new Vector2(0.5f, 1f);
				val.sizeDelta = new Vector2(num, _pageHeight);
				val.anchoredPosition = Vector2.zero;
				_rows.Add(((Component)val).gameObject);
				if (_screen == Screen.Options)
				{
					BuildOptions(val, num);
				}
				else
				{
					BuildLeft(NewColumn("Left", val, 0f, 196f, out _leftScroll, out _leftContent));
					BuildRight(NewColumn("Right", val, 204f, num - 196f - 8f, out _rightScroll, out _rightContent));
				}
				_content.sizeDelta = new Vector2(_content.sizeDelta.x, _pageHeight);
				if ((Object)(object)Plugin.Instance != (Object)null)
				{
					((MonoBehaviour)Plugin.Instance).StartCoroutine(RestoreScroll());
				}
			}
		}

		private static RectTransform NewColumn(string name, RectTransform parent, float x, float width, out ScrollRect scroll, out RectTransform content)
		{
			//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_0032: 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)
			//IL_0054: 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_00ba: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = NewRect(name, (Transform)(object)parent);
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0f, 1f);
			val.anchorMax = val2;
			val.anchorMin = val2;
			val.pivot = new Vector2(0f, 1f);
			val.sizeDelta = new Vector2(width, _pageHeight);
			val.anchoredPosition = new Vector2(x, 0f);
			_colWidth = width;
			((Component)val).gameObject.AddComponent<RectMask2D>();
			((Graphic)((Component)val).gameObject.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.001f);
			content = NewRect(name + ".Content", (Transform)(object)val);
			content.anchorMin = new Vector2(0f, 1f);
			content.anchorMax = new Vector2(1f, 1f);
			content.pivot = new Vector2(0.5f, 1f);
			content.anchoredPosition = Vector2.zero;
			content.sizeDelta = new Vector2(0f, 0f);
			scroll = ((Component)val).gameObject.AddComponent<ScrollRect>();
			scroll.viewport = val;
			scroll.content = content;
			scroll.horizontal = false;
			scroll.vertical = true;
			scroll.movementType = (MovementType)2;
			scroll.scrollSensitivity = 40f;
			return val;
		}

		private static IEnumerator RestoreScroll()
		{
			yield return null;
			if ((Object)(object)_leftScroll != (Object)null)
			{
				_leftScroll.verticalNormalizedPosition = Mathf.Clamp01(_keepLeft);
			}
			if ((Object)(object)_rightScroll != (Object)null)
			{
				_rightScroll.verticalNormalizedPosition = Mathf.Clamp01(_keepRight);
			}
		}

		private static void BuildLeft(RectTransform column)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: 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_0271: Unknown result type (might be due to invalid IL or missing references)
			float y = 0f;
			bool isActive = Sandbox.IsActive;
			Section(Lang.T("操作"), ref y);
			LRow(Lang.T("+ 新建存档"), ref y, delegate
			{
				Ui.Notify(Plugin.DoSave(null, out var message) ? message : ("存档失败:" + message));
				Rebuild();
			}, isActive ? new Color?(new Color(0.98f, 0.86f, 0.52f, 1f)) : ((Color?)null));
			LRow(Lang.T("读取最近一档"), ref y, delegate
			{
				Ui.Notify(Plugin.DoQuickLoad(out var message) ? message : ("读档失败:" + message));
			});
			LRow(Lang.T("打开文件夹"), ref y, delegate
			{
				try
				{
					if (!Directory.Exists(Paths.SlotRoot))
					{
						Directory.CreateDirectory(Paths.SlotRoot);
					}
					PreRunScript.OpenInFileBrowser(Paths.SlotRoot);
				}
				catch (Exception ex)
				{
					Ui.Notify("打开目录失败:" + ex.Message);
				}
			});
			if (_selected != null)
			{
				Section(Lang.T("已选存档"), ref y);
				LRow(Lang.T("读取此档"), ref y, delegate
				{
					Ui.Notify(Plugin.DoLoad(_selected, out var message) ? message : ("读档失败:" + message));
				});
				LRow(Lang.T("回滚上一档"), ref y, delegate
				{
					Ui.Notify(SlotStore.RestoreBackup(_selected, out var error) ? ("已回滚:" + _selected) : ("回滚失败:" + error));
					Rebuild();
				});
				LRow(Lang.T("删除此档"), ref y, delegate
				{
					Ui.Notify(SlotStore.Delete(_selected, out var error) ? ("已删除:" + _selected) : ("删除失败:" + error));
					_selected = null;
					Rebuild();
				});
			}
			float y2 = Mathf.Max(y + 8f, _pageHeight - 46f);
			GameObject val = NewRow("Special/GameSettingLanguage", _leftContent, _colWidth, ref y2);
			if ((Object)(object)val != (Object)null)
			{
				Bind(val, Lang.T("设置", "Settings"), (Action)delegate
				{
					_screen = Screen.Options;
					Rebuild();
				}, (Color?)new Color(0.86f, 0.9f, 0.98f, 1f), dragGuard: true);
				RectTransform component = val.GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					component.anchoredPosition = new Vector2(component.anchoredPosition.x, 0f - (_pageHeight - 27f));
				}
			}
			_leftContent.sizeDelta = new Vector2(_leftContent.sizeDelta.x, Mathf.Max(y2 + 8f, _pageHeight));
		}

		private static void BuildOptions(RectTransform root, float width)
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: 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)
			NewColumn("Options", root, 0f, width, out _leftScroll, out _leftContent);
			_optY = 0f;
			GameObject val = NewRow("Special/GameSettingLanguage", _leftContent, _colWidth, ref _optY);
			if ((Object)(object)val != (Object)null)
			{
				Bind(val, Lang.T("← 返回存档列表"), (Action)delegate
				{
					_screen = Screen.Main;
					Rebuild();
				}, (Color?)new Color(0.98f, 0.86f, 0.52f, 1f), dragGuard: true);
			}
			Fold("behaviour", Lang.T("行为"), delegate
			{
				BoolRow(Lang.T("游戏内读档"), Plugin.CfgInGameLoad);
				BoolRow(Lang.T("自动存档"), Plugin.CfgAutoSave);
				IntRow(Lang.T("自动存档间隔"), Plugin.CfgAutoSaveMinutes, 1, 120);
			});
			Fold("marking", Lang.T("存档标记"), delegate
			{
				BoolRow(Lang.T("标记作弊(成就关闭)"), Plugin.CfgCheatMark);
				BoolRow(Lang.T("沙盒不标作弊"), Plugin.CfgSandboxNoCheat);
			});
			Fold("other", Lang.T("其它"), delegate
			{
				BoolRow(Lang.T("联机允许存读档"), Plugin.CfgAllowMp);
				BoolRow(Lang.T("覆盖前保留上一档"), Plugin.CfgKeepBackup);
				BoolRow(Lang.T("绕过教程门禁"), Plugin.CfgBypassGate);
			});
			Fold("lang", Lang.T("界面", "Interface"), delegate
			{
				DropdownRow("Language / 语言", new string[3]
				{
					Lang.T("跟随游戏", "Follow game"),
					"中文",
					"English"
				}, (Lang.Mode == "zh") ? 1 : ((Lang.Mode == "en") ? 2 : 0), delegate(int idx)
				{
					Plugin.CfgLang.Value = idx switch
					{
						2 => "en", 
						1 => "zh", 
						_ => "auto", 
					};
					Plugin.SaveConfig();
					Lang.Invalidate();
					Rebuild();
				});
			});
			_leftContent.sizeDelta = new Vector2(_leftContent.sizeDelta.x, _optY + 8f);
		}

		private static void Fold(string key, string title, Action build)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			bool flag = Folded.Contains(key);
			GameObject val = NewRow("Special/GameSettingLanguage", _leftContent, _colWidth, ref _optY);
			if ((Object)(object)val != (Object)null)
			{
				Bind(val, (flag ? "▸ " : "▾ ") + title, (Action)delegate
				{
					if (Folded.Contains(key))
					{
						Folded.Remove(key);
					}
					else
					{
						Folded.Add(key);
					}
					Rebuild();
				}, (Color?)new Color(0.98f, 0.86f, 0.52f, 1f), dragGuard: true);
			}
			if (!flag)
			{
				build();
			}
		}

		private static void BoolRow(string label, ConfigEntry<bool> entry)
		{
			GameObject val = NewRow("Special/GameSettingBool", _leftContent, _colWidth, ref _optY);
			if ((Object)(object)val == (Object)null || entry == null)
			{
				return;
			}
			TextMeshProUGUI component = ((Component)val.transform.GetChild(0)).GetComponent<TextMeshProUGUI>();
			if ((Object)(object)component != (Object)null)
			{
				((TMP_Text)component).text = label;
			}
			Toggle component2 = ((Component)val.transform.GetChild(1)).GetComponent<Toggle>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.SetIsOnWithoutNotify(entry.Value);
				((UnityEvent<bool>)(object)component2.onValueChanged).AddListener((UnityAction<bool>)delegate(bool v)
				{
					entry.Value = v;
					Plugin.SaveConfig();
				});
			}
		}

		private static void IntRow(string label, ConfigEntry<int> entry, int min, int max)
		{
			GameObject val = NewRow("Special/GameSettingInt", _leftContent, _colWidth, ref _optY);
			if ((Object)(object)val == (Object)null || entry == null)
			{
				return;
			}
			TextMeshProUGUI component = ((Component)val.transform.GetChild(0)).GetComponent<TextMeshProUGUI>();
			if ((Object)(object)component != (Object)null)
			{
				((TMP_Text)component).text = label + Lang.T("(分钟)", " (min)");
			}
			TMP_InputField f = ((Component)val.transform.GetChild(1)).GetComponent<TMP_InputField>();
			if (!((Object)(object)f != (Object)null))
			{
				return;
			}
			f.SetTextWithoutNotify(entry.Value.ToString());
			((UnityEvent<string>)(object)f.onEndEdit).AddListener((UnityAction<string>)delegate(string v)
			{
				if (!int.TryParse(v, out var result))
				{
					result = entry.Value;
				}
				result = Mathf.Clamp(result, min, max);
				f.SetTextWithoutNotify(result.ToString());
				entry.Value = result;
				Plugin.SaveConfig();
			});
		}

		private static void DropdownRow(string label, string[] options, int current, Action<int> pick)
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			GameObject val = NewRow("Special/GameSettingDropdown", _leftContent, _colWidth, ref _optY);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			TextMeshProUGUI component = ((Component)val.transform.GetChild(0)).GetComponent<TextMeshProUGUI>();
			if ((Object)(object)component != (Object)null)
			{
				((TMP_Text)component).text = label;
			}
			TMP_Dropdown component2 = ((Component)val.transform.GetChild(1)).GetComponent<TMP_Dropdown>();
			if ((Object)(object)component2 == (Object)null)
			{
				return;
			}
			component2.ClearOptions();
			List<OptionData> list = new List<OptionData>();
			foreach (string text in options)
			{
				list.Add(new OptionData(text));
			}
			component2.AddOptions(list);
			component2.SetValueWithoutNotify(Mathf.Clamp(current, 0, options.Length - 1));
			((UnityEventBase)component2.onValueChanged).RemoveAllListeners();
			((UnityEvent<int>)(object)component2.onValueChanged).AddListener((UnityAction<int>)delegate(int obj)
			{
				try
				{
					pick(obj);
				}
				catch (Exception ex)
				{
					Log.Error("下拉框异常:" + ex);
				}
			});
		}

		private static string LangModeLabel()
		{
			string mode = Lang.Mode;
			if (mode == "zh")
			{
				return "中文";
			}
			if (mode == "en")
			{
				return "English";
			}
			return Lang.T("跟随游戏", "Follow game");
		}

		private static void BuildRight(RectTransform column)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			List<SlotMeta> source = SlotStore.List();
			bool sandboxNow = Sandbox.IsActive;
			source = source.Where((SlotMeta s) => s.sandbox == sandboxNow).ToList();
			if (_selected != null && source.All((SlotMeta s) => s.name != _selected))
			{
				_selected = null;
			}
			float x = column.sizeDelta.x;
			float y = 0f;
			if (_selected != null)
			{
				SlotMeta slotMeta = source.FirstOrDefault((SlotMeta s) => s.name == _selected);
				RRow(Lang.T("已选:") + _selected, ref y, x, (Action)null, (Color?)new Color(0.98f, 0.86f, 0.52f, 1f));
				GameObject val = NewRow("Special/GameSettingInt", _rightContent, x, ref y);
				if ((Object)(object)val != (Object)null)
				{
					try
					{
						TextMeshProUGUI component = ((Component)val.transform.GetChild(0)).GetComponent<TextMeshProUGUI>();
						if ((Object)(object)component != (Object)null)
						{
							((TMP_Text)component).text = Lang.T("新名字");
						}
						TMP_InputField component2 = ((Component)val.transform.GetChild(1)).GetComponent<TMP_InputField>();
						if ((Object)(object)component2 != (Object)null)
						{
							component2.SetTextWithoutNotify((slotMeta != null) ? slotMeta.name : _selected);
							((UnityEvent<string>)(object)component2.onEndEdit).AddListener((UnityAction<string>)delegate(string v)
							{
								try
								{
									if (!SlotStore.Rename(_selected, v, out var error))
									{
										Ui.Notify("改名失败:" + error);
									}
									else
									{
										Ui.Notify("已改名:" + v);
										_selected = Paths.SafeName(v);
										Rebuild();
									}
								}
								catch (Exception ex2)
								{
									Log.Error("改名异常:" + ex2);
								}
							});
						}
					}
					catch (Exception ex)
					{
						Log.Warn("改名输入行失败:" + ex.Message);
					}
				}
			}
			RRow(Lang.T("共 ", "") + source.Count + Lang.T(" 档(无上限,按时间倒序)", " slots (unlimited, newest first)"), ref y, x, (Action)null, (Color?)new Color(0.72f, 0.72f, 0.68f, 1f));
			if (source.Count == 0)
			{
				RRow(Lang.T("(还没有存档:进游戏按 F5,或点左边「新建存档」)"), ref y, x, (Action)null, (Color?)new Color(0.72f, 0.72f, 0.68f, 1f));
			}
			else
			{
				foreach (SlotMeta item in source)
				{
					SlotMeta mm = item;
					string text = ((item.name == _selected) ? "▶ " : "\u2003");
					string text2 = ((item.mode == "mp") ? Lang.T("联机", "MP") : Lang.T("单人", "SP"));
					if (item.sandbox)
					{
						text2 += Lang.T("·沙盒", "·sbx");
					}
					if (item.cheated)
					{
						text2 += Lang.T("·作弊", "·cheat");
					}
					RRow(string.Format(Lang.T("{0}{1}\u2003D{2} · {3} · {4}件 · {5}", "{0}{1}\u2003D{2} · {3} · {4} items · {5}"), text, item.name, item.biome, item.DurationText(), item.itemCount, text2), ref y, x, delegate
					{
						_selected = mm.name;
						Rebuild();
					});
				}
			}
			_rightContent.sizeDelta = new Vector2(0f, Mathf.Max(y, _pageHeight));
		}

		private static void Rebuild()
		{
			OnTabSelected(_menu, (SettingCategory)5);
		}

		public static void RenderStandalone(SettingsMenu menu)
		{
			if ((Object)(object)menu == (Object)null || (Object)(object)menu.content == (Object)null)
			{
				return;
			}
			_menu = menu;
			_content = menu.content;
			_screen = Screen.Main;
			ClearRows();
			ClearVanillaRows(menu);
			try
			{
				BuildPage();
			}
			catch (Exception ex)
			{
				Log.Error("渲染存档窗口失败:" + ex);
			}
		}

		private static void ClearVanillaRows(SettingsMenu menu)
		{
			try
			{
				FieldInfo field = typeof(SettingsMenu).GetField("spawnedSettings", BindingFlags.Instance | BindingFlags.NonPublic);
				if (field != null && field.GetValue(menu) is List<GameObject> list)
				{
					foreach (GameObject item in list)
					{
						if ((Object)(object)item != (Object)null)
						{
							Object.Destroy((Object)(object)item);
						}
					}
					list.Clear();
				}
				if ((Object)(object)_content == (Object)null)
				{
					return;
				}
				for (int num = ((Transform)_content).childCount - 1; num >= 0; num--)
				{
					GameObject gameObject = ((Component)((Transform)_content).GetChild(num)).gameObject;
					if (!_rows.Contains(gameObject))
					{
						Object.Destroy((Object)(object)gameObject);
					}
				}
				Log.Info("存档窗口:已清空原版设置行");
			}
			catch (Exception ex)
			{
				Log.Warn("清空原版设置行失败:" + ex.Message);
			}
		}

		private static GameObject NewRow(string prefab, RectTransform parent, float width, ref float y)
		{
			//IL_004c: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			GameObject val;
			try
			{
				val = Utils.Create(prefab, (Transform)(object)parent);
			}
			catch (Exception ex)
			{
				Log.Warn("生成行失败 [" + prefab + "]:" + ex.Message);
				return null;
			}
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			RectTransform component = val.GetComponent<RectTransform>();
			if ((Object)(object)component != (Object)null)
			{
				float num = ((component.sizeDelta.y > 1f) ? component.sizeDelta.y : 44f);
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor(0.5f, 1f);
				component.anchorMax = val2;
				component.anchorMin = val2;
				component.pivot = new Vector2(0.5f, 0.5f);
				component.sizeDelta = new Vector2(width, num);
				component.anchoredPosition = new Vector2(0f, 0f - (y + num * 0.5f));
				y += num + 2f;
			}
			_rows.Add(val);
			return val;
		}

		private static void Section(string title, ref float y)
		{
			//IL_0057: 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_007c: Expected O, but got Unknown
			GameObject val = NewRow("Special/GameSettingLanguage", _leftContent, _colWidth, ref y);
			if (!((Object)(object)val == (Object)null))
			{
				TextMeshProUGUI component = ((Component)val.transform.GetChild(0)).GetComponent<TextMeshProUGUI>();
				if ((Object)(object)component != (Object)null)
				{
					((TMP_Text)component).text = title;
					((Graphic)component).color = new Color(0.98f, 0.86f, 0.52f, 1f);
				}
				Button component2 = val.GetComponent<Button>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.onClick = new ButtonClickedEvent();
				}
			}
		}

		private static void LRow(string label, ref float y, Action onClick, Color? color = null)
		{
			GameObject val = NewRow("Special/GameSettingLanguage", _leftContent, _colWidth, ref y);
			if (!((Object)(object)val == (Object)null))
			{
				Bind(val, label, onClick, color);
			}
		}

		private static void ToggleRow(string label, ref float y, ConfigEntry<bool> entry, string tip = null)
		{
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			bool on = entry != null && entry.Value;
			LRow(label + (on ? Lang.T(":开", " : ON") : Lang.T(":关", " : OFF")), ref y, delegate
			{
				if (entry != null)
				{
					entry.Value = !on;
				}
				Plugin.SaveConfig();
				Rebuild();
			}, on ? new Color?(new Color(0.72f, 0.92f, 0.72f, 1f)) : ((Color?)null));
		}

		private static void RRow(string label, ref float y, float width, Action onClick, Color? color = null)
		{
			GameObject val = NewRow("Special/GameSettingLanguage", _rightContent, width, ref y);
			if (!((Object)(object)val == (Object)null))
			{
				Bind(val, label, onClick, color);
			}
		}

		private static void Bind(GameObject go, string label, Action onClick, Color? color, bool dragGuard = true)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI component = ((Component)go.transform.GetChild(0)).GetComponent<TextMeshProUGUI>();
			if ((Object)(object)component != (Object)null)
			{
				((TMP_Text)component).text = label;
				if (color.HasValue)
				{
					((Graphic)component).color = color.Value;
				}
			}
			Button component2 = go.GetComponent<Button>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.onClick = new ButtonClickedEvent();
			}
			if (onClick == null)
			{
				return;
			}
			RowClick rowClick = go.GetComponent<RowClick>();
			if ((Object)(object)rowClick == (Object)null)
			{
				rowClick = go.AddComponent<RowClick>();
			}
			rowClick.dragGuard = dragGuard;
			rowClick.Tap = delegate
			{
				try
				{
					onClick();
				}
				catch (Exception ex)
				{
					Log.Error("行点击异常:" + ex);
				}
			};
		}

		private static RectTransform NewRect(string name, Transform parent)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = new GameObject(name, new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
			((Transform)component).SetParent(parent, false);
			return component;
		}

		private static float PageWidth()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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)
			Rect rect = _content.rect;
			float num = ((Rect)(ref rect)).width;
			if (num <= 1f)
			{
				num = _content.sizeDelta.x;
			}
			if (num <= 1f)
			{
				Transform parent = ((Transform)_content).parent;
				RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
				if (val != null)
				{
					rect = val.rect;
					num = ((Rect)(ref rect)).width;
				}
			}
			if (num <= 1f)
			{
				num = 760f;
			}
			return num;
		}

		private static float PageHeight()
		{
			//IL_003c: 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_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			Transform parent = ((Transform)_content).parent;
			RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
			Rect rect;
			if (val != null)
			{
				rect = val.rect;
				if (((Rect)(ref rect)).height > 1f)
				{
					rect = val.rect;
					return ((Rect)(ref rect)).height;
				}
			}
			rect = _content.rect;
			float num = ((Rect)(ref rect)).height;
			if (num <= 1f)
			{
				num = _content.sizeDelta.y;
			}
			if (num <= 1f)
			{
				num = 430f;
			}
			return num;
		}

		public static void CommitLayout()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_content != (Object)null)
			{
				_content.sizeDelta = new Vector2(_content.sizeDelta.x, _pageHeight);
			}
		}

		public static bool Open()
		{
			if ((Object)(object)Plugin.Instance == (Object)null)
			{
				return false;
			}
			((MonoBehaviour)Plugin.Instance).StartCoroutine(OpenRoutine());
			return true;
		}

		private static IEnumerator OpenRoutine()
		{
			if ((Object)(object)PauseHandler.main != (Object)null)
			{
				if (!PauseHandler.paused)
				{
					PauseHandler.TogglePause();
				}
				yield return null;
				yield return null;
				if ((Object)(object)PauseHandler.main != (Object)null)
				{
					PauseHandler.main.Settings();
				}
			}
			else
			{
				Transform val = null;
				try
				{
					if ((Object)(object)PreRunScript.instance != (Object)null && (Object)(object)PreRunScript.instance.mainCanvas != (Object)null)
					{
						val = ((Component)PreRunScript.instance.mainCanvas).transform;
					}
					else if ((Object)(object)PlayerCamera.main != (Object)null && (Object)(object)PlayerCamera.main.mainCanvas != (Object)null)
					{
						val = ((Component)PlayerCamera.main.mainCanvas).transform;
					}
				}
				catch
				{
				}
				if ((Object)(object)val == (Object)null)
				{
					Ui.Notify("找不到 UI,无法打开存档页");
					yield break;
				}
				SettingsMenu.OpenMenu(val);
			}
			yield return null;
			yield return null;
			if ((Object)(object)SettingsMenu.instance != (Object)null)
			{
				try
				{
					SettingsMenu.instance.SelectTab(5);
				}
				catch (Exception ex)
				{
					Log.Error("跳转存档页失败:" + ex);
				}
			}
		}
	}
	internal class RowClick : MonoBehaviour, IPointerDownHandler, IEventSystemHandler, IPointerClickHandler
	{
		public Action Tap;

		public bool dragGuard = true;

		private Vector2 _down;

		public void OnPointerDown(PointerEventData e)
		{
			//IL_0002: 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)
			_down = e.position;
		}

		public void OnPointerClick(PointerEventData e)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			if (dragGuard)
			{
				Vector2 val = e.position - _down;
				if (((Vector2)(ref val)).sqrMagnitude > 144f)
				{
					return;
				}
			}
			try
			{
				Tap?.Invoke();
			}
			catch (Exception ex)
			{
				Log.Error("行点击异常:" + ex);
			}
		}
	}
	[HarmonyPatch(typeof(SettingsMenu), "Start")]
	internal static class Patch_SettingsMenu_Start
	{
		private static void Postfix(SettingsMenu __instance)
		{
			try
			{
				SavePage.InstallTab(__instance);
			}
			catch (Exception ex)
			{
				Log.Error("装存档分页失败:" + ex);
			}
		}
	}
	[HarmonyPatch(typeof(SettingsMenu), "SelectTab", new Type[] { typeof(SettingCategory) })]
	internal static class Patch_SettingsMenu_SelectTab
	{
		private static void Postfix(SettingsMenu __instance, SettingCategory category)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				SavePage.OnTabSelected(__instance, category);
			}
			catch (Exception ex)
			{
				Log.Error("渲染存档分页失败:" + ex);
			}
		}
	}
	internal static class SaveWindow
	{
		private static int _styledId;

		public static bool Open()
		{
			try
			{
				if ((Object)(object)Plugin.Instance == (Object)null)
				{
					return false;
				}
				SettingsMenu instance = SettingsMenu.instance;
				if ((Object)(object)instance == (Object)null)
				{
					Transform val = null;
					if ((Object)(object)PauseHandler.main != (Object)null)
					{
						val = ((Component)PauseHandler.main).transform;
					}
					else if ((Object)(object)PreRunScript.instance != (Object)null && (Object)(object)PreRunScript.instance.mainCanvas != (Object)null)
					{
						val = ((Component)PreRunScript.instance.mainCanvas).transform;
					}
					if ((Object)(object)val == (Object)null)
					{
						Ui.Notify(Lang.T("找不到界面,无法打开存档窗口"));
						return false;
					}
					SettingsMenu.OpenMenu(val);
					instance = SettingsMenu.instance;
				}
				if ((Object)(object)instance == (Object)null)
				{
					return false;
				}
				((MonoBehaviour)Plugin.Instance).StartCoroutine(OpenRoutine(instance));
				return true;
			}
			catch (Exception ex)
			{
				Log.Error("打开存档窗口失败:" + ex);
				return false;
			}
		}

		private static IEnumerator OpenRoutine(SettingsMenu menu)
		{
			yield return null;
			yield return null;
			Style(menu);
			SavePage.RenderStandalone(menu);
			yield return null;
			if ((Object)(object)menu == (Object)null || !((Component)menu).gameObject.activeInHierarchy)
			{
				Log.Error("存档窗口渲染后不可见(可能被别的逻辑关掉了)");
			}
		}

		private static void Style(SettingsMenu menu)
		{
			if ((Object)(object)menu == (Object)null || ((Object)menu).GetInstanceID() == _styledId)
			{
				return;
			}
			try
			{
				int num = 0;
				if (menu.buttons != null)
				{
					foreach (Button button in menu.buttons)
					{
						if (!((Object)(object)button == (Object)null))
						{
							((Component)button).gameObject.SetActive(false);
							num++;
						}
					}
				}
				int num2 = 0;
				Button[] componentsInChildren = ((Component)menu).GetComponentsInChildren<Button>(true);
				foreach (Button val in componentsInChildren)
				{
					if (!((Object)(object)val == (Object)null) && PersistentMethod(val) == "ResetToDefault")
					{
						((Component)val).gameObject.SetActive(false);
						num2++;
					}
				}
				_styledId = ((Object)menu).GetInstanceID();
				Log.Info("存档窗口:隐藏分页按钮 " + num + " 个、重置按钮 " + num2 + " 个");
			}
			catch (Exception ex)
			{
				Log.Warn("改造存档窗口失败:" + ex.Message);
			}
		}

		private static string PersistentMethod(Button b)
		{
			try
			{
				ButtonClickedEvent onClick = b.onClick;
				if (onClick == null)
				{
					return null;
				}
				int persistentEventCount = ((UnityEventBase)onClick).GetPersistentEventCount();
				for (int i = 0; i < persistentEventCount; i++)
				{
					string persistentMethodName = ((UnityEventBase)onClick).GetPersistentMethodName(i);
					if (!string.IsNullOrEmpty(persistentMethodName))
					{
						return persistentMethodName;
					}
				}
			}
			catch
			{
			}
			return null;
		}
	}
	[Serializable]
	internal class SlotMeta
	{
		public int format = 1;

		public string name = "";

		public string createdAt = "";

		public string mode = "sp";

		public bool sandbox;

		public int biome = 1;

		public float runTime;

		public string character = "";

		public int itemCount;

		public bool cheated;

		public bool hasBackup;

		public long bytes;

		public List<string> players = new List<string>();

		public string note = "";

		public string TimeText()
		{
			try
			{
				if (DateTime.TryParse(createdAt, out var result))
				{
					return result.ToString("MM-dd HH:mm");
				}
			}
			catch
			{
			}
			return createdAt;
		}

		public string DurationText()
		{
			int num = (int)Math.Floor(runTime);
			int num2 = num / 3600;
			int num3 = num % 3600 / 60;
			if (num2 > 0)
			{
				return num2 + "h" + num3 + "m";
			}
			return num3 + "m" + num % 60 + "s";
		}
	}
	internal static class SlotStore
	{
		public static bool InWorld
		{
			get
			{
				if ((Object)(object)PlayerCamera.main != (Object)null)
				{
					return (Object)(object)PlayerCamera.main.body != (Object)null;
				}
				return false;
			}
		}

		public static bool Capture(string requestedName, out string slotName, out string error)
		{
			slotName = null;
			error = null;
			if (!InWorld)
			{
				error = "当前不在游戏世界内,无法存档";
				return false;
			}
			if (!Plugin.MpAllowed && Paths.MpPresent)
			{
				error = "联机存档被配置禁用(AllowInMultiplayer=false)";
				return false;
			}
			bool isActive = Sandbox.IsActive;
			try
			{
				bool num = Plugin.CfgCheatMark != null && Plugin.CfgCheatMark.Value;
				bool flag = isActive && (Plugin.CfgSandboxNoCheat == null || Plugin.CfgSandboxNoCheat.Value);
				if (num && !flag && !SteamManager.disableAchievements)
				{
					SteamManager.disableAchievements = true;
				}
				SaveSystem.SaveGame();
			}
			catch (Exception ex)
			{
				error = "调用游戏 SaveGame 失败:" + ex.Message;
				Log.Error(error + "\n" + ex.StackTrace);
				return false;
			}
			bool mpPresent = Paths.MpPresent;
			string text = (File.Exists(Paths.VanillaSave) ? Paths.VanillaSave : (mpPresent ? Path.Combine(Paths.MpSaveDir, "save.sv") : null));
			if (text == null || !File.Exists(text))
			{
				error = "游戏没有产出 save.sv(可能处于不允许存档的层)";
				return false;
			}
			SlotMeta slotMeta = Probe(text);
			slotMeta.mode = (mpPresent ? "mp" : "sp");
			slotMeta.sandbox = isActive;
			slotMeta.createdAt = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture);
			if (mpPresent)
			{
				slotMeta.players = ListMpPlayers();
			}
			string text2 = Paths.SafeName(requestedName);
			if (text2 == null)
			{
				text2 = UniqueAutoName(slotMeta);
			}
			try
			{
				Paths.EnsureRoot();
				Directory.CreateDirectory(Paths.SlotDir(text2));
				if (Plugin.CfgKeepBackup != null && Plugin.CfgKeepBackup.Value && (File.Exists(Paths.SlotSave(text2)) || Directory.Exists(Paths.SlotMp(text2))))
				{
					RotateBackup(text2);
					slotMeta.hasBackup = true;
				}
				try
				{
					File.Copy(Paths.VanillaSave, Paths.SlotSave(text2), overwrite: true);
				}
				catch (FileNotFoundException)
				{
				}
				if (Directory.Exists(Paths.SlotMp(text2)))
				{
					Directory.Delete(Paths.SlotMp(text2), recursive: true);
				}
				if (mpPresent)
				{
					CopyDir(Paths.MpSaveDir, Paths.SlotMp(text2));
				}
				slotMeta.name = text2;
				slotMeta.bytes = new FileInfo(text).Length;
				WriteMeta(text2, slotMeta);
				slotName = text2;
				Log.Info($"已存档 -> {text2}({slotMeta.mode},{FormatBytes(slotMeta.bytes)})");
				return true;
			}
			catch (Exception ex3)
			{
				error = "写入存档槽失败:" + ex3.Message;
				Log.Error(error + "\n" + ex3.StackTrace);
				return false;
			}
		}

		public static bool PrepareLoad(string slotName, out string error)
		{
			error = null;
			if (!Directory.Exists(Paths.SlotDir(slotName)))
			{
				error = "槽不存在:" + slotName;
				return false;
			}
			try
			{
				string text = Paths.SlotSave(slotName);
				string text2 = Paths.SlotMp(slotName);
				if (Directory.Exists(text2))
				{
					if (Directory.Exists(Paths.MpSaveDir))
					{
						string destDirName = Paths.MpSaveDir + ".old_" + DateTime.Now.ToString("HHmmss");
						try
						{
							Directory.Move(Paths.MpSaveDir, destDirName);
						}
						catch
						{
							Directory.Delete(Paths.MpSaveDir, recursive: true);
						}
					}
					CopyDir(text2, Paths.MpSaveDir);
				}
				if (File.Exists(text))
				{
					File.Copy(text, Paths.VanillaSave, overwrite: true);
				}
				else if (!Directory.Exists(text2))
				{
					error = "槽里没有 save.sv:" + slotName;
					return false;
				}
				Log.Info("已铺档 -> " + slotName);
				return true;
			}
			catch (Exception ex)
			{
				error = "铺档失败:" + ex.Message;
				Log.Error(error + "\n" + ex.StackTrace);
				return false;
			}
		}

		public static bool ExportToGameSave(string slotName, out string error)
		{
			return PrepareLoad(slotName, out error);
		}

		public static List<SlotMeta> List()
		{
			List<SlotMeta> list = new List<SlotMeta>();
			try
			{
				if (!Directory.Exists(Paths.SlotRoot))
				{
					return list;
				}
				string[] directories = Directory.GetDirectories(Paths.SlotRoot);
				foreach (string text in directories)
				{
					string fileName = Path.GetFileName(text);
					SlotMeta slotMeta = ReadMeta(fileName);
					if (slotMeta == null)
					{
						if (!File.Exists(Path.Combine(text, "save.sv")) && !Directory.Exists(Path.Combine(text, "mp")))
						{
							continue;
						}
						slotMeta = new SlotMeta
						{
							name = fileName
						};
					}
					slotMeta.name = fileName;
					if (string.IsNullOrEmpty(slotMeta.createdAt))
					{
						try
						{
							slotMeta.createdAt = File.GetLastWriteTime(text).ToString("yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture);
						}
						catch
						{
						}
					}
					slotMeta.hasBackup = Directory.Exists(Paths.SlotBackup(fileName));
					list.Add(slotMeta);
				}
			}
			catch (Exception ex)
			{
				Log.Error("列存档失败:" + ex.Message);
			}
			return list.OrderByDescending<SlotMeta, string>((SlotMeta m) => m.createdAt, StringComparer.Ordinal).ToList();
		}

		public static bool Delete(string slotName, out string error)
		{
			error = null;
			try
			{
				if (!Directory.Exists(Paths.SlotDir(slotName)))
				{
					error = "槽不存在";
					return false;
				}
				Directory.Delete(Paths.SlotDir(slotName), recursive: true);
				Log.Info("已删除槽:" + slotName);
				return true;
			}
			catch (Exception ex)
			{
				error = "删除失败:" + ex.Message;
				return false;
			}
		}

		public static bool Rename(string oldName, string newNameRaw, out string error)
		{
			error = null;
			string text = Paths.SafeName(newNameRaw);
			if (text == null)
			{
				error = "名字不合法";
				return false;
			}
			try
			{
				if (!Directory.Exists(Paths.SlotDir(oldName)))
				{
					error = "槽不存在";
					return false;
				}
				if (Directory.Exists(Paths.SlotDir(text)))
				{
					error = "目标名字已存在";
					return false;
				}
				Directory.Move(Paths.SlotDir(oldName), Paths.SlotDir(text));
				SlotMeta slotMeta = ReadMeta(text) ?? new SlotMeta();
				slotMeta.name = text;
				WriteMeta(text, slotMeta);
				Log.Info("已改名:" + oldName + " -> " + text);
				return true;
			}
			catch (Exception ex)
			{
				error = "改名失败:" + ex.Message;
				return false;
			}
		}

		public static b