Decompiled source of RepoSaveOrganizer v1.0.0

BepInEx/plugins/RepoSaveOrganizer/Matsu.RepoSaveOrganizer.dll

Decompiled 4 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Matsu.RepoSaveOrganizer.Core;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("Matsu.RepoSaveOrganizer.Probe")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("Matsu.RepoSaveOrganizer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Matsu.RepoSaveOrganizer")]
[assembly: AssemblyTitle("Matsu.RepoSaveOrganizer")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 Matsu.RepoSaveOrganizer
{
	internal static class Es3SaveHelper
	{
		private sealed class CachedEntry
		{
			public long LastWriteTicks;

			public long Length;

			public SaveSummary Summary;
		}

		private static readonly Dictionary<string, CachedEntry> Cache = new Dictionary<string, CachedEntry>(StringComparer.OrdinalIgnoreCase);

		private static readonly FieldInfo? Es3FormatKeyField = AccessTools.Field(typeof(StatsManager), "totallyNormalString");

		private static readonly FieldInfo? DictOfDictsField = AccessTools.Field(typeof(StatsManager), "dictionaryOfDictionaries");

		private static readonly FieldInfo? DoNotSaveField = AccessTools.Field(typeof(StatsManager), "doNotSaveTheseDictionaries");

		public static string SavesRoot => Application.persistentDataPath + "/saves";

		internal static string GetVanillaEs3Key()
		{
			if ((Object)(object)StatsManager.instance != (Object)null && Es3FormatKeyField != null && Es3FormatKeyField.GetValue(StatsManager.instance) is string text && !string.IsNullOrEmpty(text))
			{
				return text;
			}
			return "";
		}

		public static void Invalidate(string? folderName = null)
		{
			if (string.IsNullOrWhiteSpace(folderName))
			{
				Cache.Clear();
			}
			else
			{
				Cache.Remove(folderName);
			}
		}

		public static SaveSummary ReadSummary(string folderName, IReadOnlyList<string>? backups = null)
		{
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Expected O, but got Unknown
			if (!SaveFolderOperations.TryResolveSaveSubdirectory(SavesRoot, folderName, out string resolvedDir))
			{
				return new SaveSummary
				{
					FolderName = (folderName ?? ""),
					TeamName = (folderName ?? ""),
					IsValid = false,
					BackupCount = (backups?.Count ?? 0)
				};
			}
			string text;
			bool flag = File.Exists(text = Path.Combine(resolvedDir, folderName + ".es3"));
			if (!flag && backups != null && backups.Count > 0 && SaveFolderOperations.IsSafeSaveFolderName(backups[0]))
			{
				string text2 = Path.Combine(resolvedDir, backups[0] + ".es3");
				if (File.Exists(text2))
				{
					text = text2;
				}
			}
			long num = (Directory.Exists(resolvedDir) ? Directory.GetCreationTimeUtc(resolvedDir).Ticks : 0);
			if (!File.Exists(text))
			{
				return new SaveSummary
				{
					FolderName = folderName,
					TeamName = folderName,
					CreationUtcTicks = num,
					LastWriteUtcTicks = num,
					IsValid = false,
					BackupCount = (backups?.Count ?? 0)
				};
			}
			FileInfo fileInfo = new FileInfo(text);
			long ticks = fileInfo.LastWriteTimeUtc.Ticks;
			long length = fileInfo.Length;
			if (Cache.TryGetValue(folderName, out CachedEntry value) && value.LastWriteTicks == ticks && value.Length == length)
			{
				value.Summary.BackupCount = backups?.Count ?? value.Summary.BackupCount;
				return value.Summary;
			}
			SaveSummary saveSummary = new SaveSummary
			{
				FolderName = folderName,
				TeamName = "R.E.P.O.",
				DateText = "",
				CreationUtcTicks = num,
				LastWriteUtcTicks = ticks,
				BackupCount = (backups?.Count ?? 0),
				IsValid = false
			};
			try
			{
				string vanillaEs3Key = GetVanillaEs3Key();
				ES3Settings val = new ES3Settings(text, (EncryptionType)1, vanillaEs3Key, (ES3Settings)null);
				if (ES3.KeyExists("dictionaryOfDictionaries", val))
				{
					Dictionary<string, Dictionary<string, int>> dictionary = ES3.Load<Dictionary<string, Dictionary<string, int>>>("dictionaryOfDictionaries", (string)null, new Dictionary<string, Dictionary<string, int>>(), val);
					if (dictionary != null && dictionary.TryGetValue("runStats", out var value2) && value2 != null)
					{
						int value3;
						bool num2 = value2.TryGetValue("level", out value3);
						int value4;
						bool flag2 = value2.TryGetValue("currency", out value4);
						int value5;
						bool flag3 = value2.TryGetValue("totalHaul", out value5);
						if (num2 && flag2 && flag3)
						{
							saveSummary.Level = value3;
							saveSummary.Currency = value4;
							saveSummary.TotalHaul = value5;
							saveSummary.IsValid = flag;
						}
					}
				}
				if (ES3.KeyExists("teamName", val))
				{
					saveSummary.TeamName = ES3.Load<string>("teamName", val) ?? "R.E.P.O.";
				}
				if (ES3.KeyExists("dateAndTime", val))
				{
					saveSummary.DateText = ES3.Load<string>("dateAndTime", val) ?? "";
				}
				if (ES3.KeyExists("timePlayed", val))
				{
					saveSummary.TimePlayed = ES3.Load<float>("timePlayed", val);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[SaveManager] Failed reading summary for '" + folderName + "': " + ex.Message));
			}
			Cache[folderName] = new CachedEntry
			{
				LastWriteTicks = ticks,
				Length = length,
				Summary = saveSummary
			};
			return saveSummary;
		}

		public static string? DuplicateSaveWithEs3Rename(string sourceFolderName)
		{
			string text = SaveFolderOperations.DuplicateSaveDirectory(SavesRoot, sourceFolderName, null, delegate(string newFolder, string newEs3Path)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Expected O, but got Unknown
				try
				{
					string vanillaEs3Key = GetVanillaEs3Key();
					ES3Settings val = new ES3Settings(newEs3Path, (EncryptionType)1, vanillaEs3Key, (ES3Settings)null);
					string text2 = (ES3.KeyExists("teamName", val) ? (ES3.Load<string>("teamName", val) ?? "R.E.P.O.") : "R.E.P.O.");
					string text3 = SaveManagerLocalization.CopySuffix();
					string text4 = (text2.EndsWith(text3, StringComparison.Ordinal) ? text2 : (text2 + text3));
					if (text4.Length > 60)
					{
						text4 = text4.Substring(0, 60);
					}
					ES3.Save<string>("teamName", text4, val);
					ES3.Save<bool>("teamNameChanged", true, val);
					ES3.Save<string>("dateAndTime", DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), val);
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("[SaveManager] Duplicate teamName update warning for '" + newFolder + "': " + ex.Message));
				}
			});
			if (text != null)
			{
				Invalidate(text);
			}
			return text;
		}

		public static bool RenameSaveTeam(string folderName, string newTeamName)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			if (!SaveFolderOperations.TryResolveSaveSubdirectory(SavesRoot, folderName, out string resolvedDir))
			{
				return false;
			}
			string text = Path.Combine(resolvedDir, folderName + ".es3");
			if (!File.Exists(text))
			{
				return false;
			}
			string text2 = (newTeamName ?? "").Trim();
			if (text2.Length == 0)
			{
				return false;
			}
			if (text2.Length > 60)
			{
				text2 = text2.Substring(0, 60);
			}
			try
			{
				DateTime lastWriteTimeUtc = File.GetLastWriteTimeUtc(text);
				ES3Settings val = new ES3Settings(text, (EncryptionType)1, GetVanillaEs3Key(), (ES3Settings)null);
				ES3.Save<string>("teamName", text2, val);
				ES3.Save<bool>("teamNameChanged", true, val);
				File.SetLastWriteTimeUtc(text, lastWriteTimeUtc);
				Invalidate(folderName);
				return true;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[SaveOrganizer] Failed renaming '" + folderName + "': " + ex.Message));
				return false;
			}
		}

		public static string? CreateBlankSaveSlot(string teamName)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_009e: Expected O, but got Unknown
			try
			{
				string savesRoot = SavesRoot;
				if (!Directory.Exists(savesRoot))
				{
					Directory.CreateDirectory(savesRoot);
				}
				string text = SaveFolderOperations.GenerateUniqueSaveFolderName(savesRoot);
				string text2 = Path.Combine(savesRoot, text);
				Directory.CreateDirectory(text2);
				string path = Path.Combine(text2, text + ".es3");
				string text3 = (string.IsNullOrWhiteSpace(teamName) ? "R.E.P.O." : teamName.Trim());
				if (text3.Length > 60)
				{
					text3 = text3.Substring(0, 60);
				}
				ES3Settings val = new ES3Settings(new Enum[1] { (Enum)(object)(Location)4 })
				{
					encryptionType = (EncryptionType)1,
					encryptionPassword = GetVanillaEs3Key(),
					path = path
				};
				ES3.Save<string>("teamName", text3, val);
				ES3.Save<bool>("teamNameChanged", true, val);
				ES3.Save<string>("dateAndTime", DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), val);
				ES3.Save<float>("timePlayed", 0f, val);
				ES3.Save<Dictionary<string, string>>("playerNames", new Dictionary<string, string>(), val);
				Dictionary<string, Dictionary<string, int>> dictionary = new Dictionary<string, Dictionary<string, int>>();
				if ((Object)(object)StatsManager.instance != (Object)null && DictOfDictsField?.GetValue(StatsManager.instance) is Dictionary<string, Dictionary<string, int>> dictionary2)
				{
					List<string> list = DoNotSaveField?.GetValue(StatsManager.instance) as List<string>;
					foreach (KeyValuePair<string, Dictionary<string, int>> item in dictionary2)
					{
						if (list == null || !list.Contains(item.Key))
						{
							dictionary[item.Key] = new Dictionary<string, int>();
						}
					}
				}
				dictionary["runStats"] = new Dictionary<string, int>
				{
					["level"] = 0,
					["currency"] = 0,
					["lives"] = 3,
					["chargingStationCharge"] = 1,
					["chargingStationChargeTotal"] = 100,
					["totalHaul"] = 0
				};
				ES3.Save<Dictionary<string, Dictionary<string, int>>>("dictionaryOfDictionaries", dictionary, val);
				ES3.Save<int>("saveVersion", 1, val);
				ES3.StoreCachedFile(val);
				Invalidate(text);
				return text;
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"[SaveManager] Failed creating blank save slot: {arg}");
				return null;
			}
		}

		public static List<string> GetBackups(string folderName)
		{
			if ((Object)(object)StatsManager.instance != (Object)null)
			{
				try
				{
					return StatsManager.instance.SaveFileGetBackups(folderName, SavesRoot) ?? new List<string>();
				}
				catch
				{
				}
			}
			return new List<string>();
		}
	}
	internal static class NativeUiFactory
	{
		public const string ScrollSkipSuffix = " [SCROLL SKIP SELF]";

		private static Sprite? whiteSprite;

		private static TMP_FontAsset? cachedDynamicJaFallback;

		private static readonly HashSet<int> PatchedFonts = new HashSet<int>();

		private static readonly MethodInfo? MenuEffectClickMethod = AccessTools.Method(typeof(MenuManager), "MenuEffectClick", (Type[])null, (Type[])null);

		public static Sprite GetWhiteSprite()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)whiteSprite != (Object)null)
			{
				return whiteSprite;
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false)
			{
				name = "RepoSaveOrganizer_WhitePixel",
				filterMode = (FilterMode)0,
				wrapMode = (TextureWrapMode)1,
				hideFlags = (HideFlags)61
			};
			Color32 val2 = default(Color32);
			((Color32)(ref val2))..ctor(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
			val.SetPixels32((Color32[])(object)new Color32[4] { val2, val2, val2, val2 });
			val.Apply(false, false);
			whiteSprite = Sprite.Create(val, new Rect(0f, 0f, 2f, 2f), new Vector2(0.5f, 0.5f), 100f);
			((Object)whiteSprite).hideFlags = (HideFlags)61;
			return whiteSprite;
		}

		public static void EnsureJapaneseFallback(TMP_FontAsset? font)
		{
			if ((Object)(object)font == (Object)null)
			{
				return;
			}
			int instanceID = ((Object)font).GetInstanceID();
			if (!PatchedFonts.Add(instanceID))
			{
				return;
			}
			try
			{
				if ((Object)(object)cachedDynamicJaFallback == (Object)null)
				{
					Font val = Font.CreateDynamicFontFromOSFont(new string[6] { "Yu Gothic UI Bold", "Yu Gothic UI", "Meiryo UI", "Meiryo", "MS Gothic", "Arial" }, 28);
					if ((Object)(object)val != (Object)null)
					{
						((Object)val).hideFlags = (HideFlags)61;
						cachedDynamicJaFallback = TMP_FontAsset.CreateFontAsset(val);
						if ((Object)(object)cachedDynamicJaFallback != (Object)null)
						{
							((Object)cachedDynamicJaFallback).name = "RepoSaveOrganizer_DynamicCJKFallback";
							((Object)cachedDynamicJaFallback).hideFlags = (HideFlags)61;
						}
					}
				}
				if ((Object)(object)cachedDynamicJaFallback != (Object)null)
				{
					if (font.fallbackFontAssetTable == null)
					{
						List<TMP_FontAsset> list = (font.fallbackFontAssetTable = new List<TMP_FontAsset>());
					}
					if (!font.fallbackFontAssetTable.Contains(cachedDynamicJaFallback))
					{
						font.fallbackFontAssetTable.Add(cachedDynamicJaFallback);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[SaveManager] Dynamic font fallback setup skipped: " + ex.Message));
			}
		}

		public static Color HexColor(string hex, float alpha = 1f)
		{
			//IL_0047: 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)
			Color result = default(Color);
			if (!string.IsNullOrWhiteSpace(hex) && ColorUtility.TryParseHtmlString(hex.StartsWith("#", StringComparison.Ordinal) ? hex : ("#" + hex), ref result))
			{
				result.a = alpha;
				return result;
			}
			return new Color(1f, 0.62f, 0.11f, alpha);
		}

		public static void PlayConfirmSound()
		{
			try
			{
				MenuManager instance = MenuManager.instance;
				if (instance != null)
				{
					instance.MenuEffectClick((MenuClickEffectType)1, (MenuPage)null, 1f, 1f, false, true);
				}
			}
			catch
			{
			}
		}

		public static void PlayTickSound()
		{
			try
			{
				if ((Object)(object)MenuManager.instance != (Object)null && MenuEffectClickMethod != null)
				{
					MenuManager.instance.MenuEffectClick((MenuClickEffectType)4, (MenuPage)null, 1.4f, 0.5f, false, true);
				}
			}
			catch
			{
			}
		}

		public static void PlayDenySound()
		{
			try
			{
				MenuManager instance = MenuManager.instance;
				if (instance != null)
				{
					instance.MenuEffectClick((MenuClickEffectType)2, (MenuPage)null, 1f, 1f, false, true);
				}
			}
			catch
			{
			}
		}

		public static RectTransform CreatePanel(Transform parent, string name, Vector2 anchoredPos, Vector2 size, Color bgColor, Color borderColor, bool skipScroll = false, bool bottomLeftAnchor = false)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(skipScroll ? (name + " [SCROLL SKIP SELF]") : name, new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Outline)
			});
			val.layer = ((Component)parent).gameObject.layer;
			RectTransform component = val.GetComponent<RectTransform>();
			((Transform)component).SetParent(parent, false);
			component.anchorMin = (Vector2)(bottomLeftAnchor ? Vector2.zero : new Vector2(0.5f, 0.5f));
			component.anchorMax = (Vector2)(bottomLeftAnchor ? Vector2.zero : new Vector2(0.5f, 0.5f));
			component.pivot = new Vector2(0.5f, 0.5f);
			component.anchoredPosition = anchoredPos;
			component.sizeDelta = size;
			Image component2 = val.GetComponent<Image>();
			component2.sprite = GetWhiteSprite();
			((Graphic)component2).color = bgColor;
			((Graphic)component2).raycastTarget = false;
			Outline component3 = val.GetComponent<Outline>();
			((Shadow)component3).effectColor = borderColor;
			((Shadow)component3).effectDistance = new Vector2(1f, -1f);
			return component;
		}

		public static TextMeshProUGUI CreateLabel(Transform parent, string name, TMP_FontAsset? font, string text, float fontSize, Color color, TextAlignmentOptions align = (TextAlignmentOptions)4098, bool skipScroll = false)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			EnsureJapaneseFallback(font);
			GameObject val = new GameObject(skipScroll ? (name + " [SCROLL SKIP SELF]") : name, new Type[2]
			{
				typeof(RectTransform),
				typeof(TextMeshProUGUI)
			})
			{
				layer = ((Component)parent).gameObject.layer
			};
			RectTransform component = val.GetComponent<RectTransform>();
			((Transform)component).SetParent(parent, false);
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = new Vector2(2f, 0f);
			component.offsetMax = new Vector2(-2f, 0f);
			TextMeshProUGUI component2 = val.GetComponent<TextMeshProUGUI>();
			if ((Object)(object)font != (Object)null)
			{
				((TMP_Text)component2).font = font;
			}
			((TMP_Text)component2).text = text;
			((TMP_Text)component2).fontSize = fontSize;
			((Graphic)component2).color = color;
			((TMP_Text)component2).alignment = align;
			((TMP_Text)component2).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)component2).overflowMode = (TextOverflowModes)1;
			((TMP_Text)component2).richText = true;
			((Graphic)component2).raycastTarget = false;
			return component2;
		}

		public static NativeMenuChip CreateChip(Transform parent, string name, TMP_FontAsset? font, string label, Vector2 anchoredPos, Vector2 size, float fontSize, Action onClick, bool skipScroll = false, bool showSelectionBox = false)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: 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_00f2: 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_010c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(skipScroll ? (name + " [SCROLL SKIP SELF]") : name, new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Outline)
			})
			{
				layer = ((Component)parent).gameObject.layer
			};
			RectTransform component = val.GetComponent<RectTransform>();
			((Transform)component).SetParent(parent, false);
			component.anchorMin = new Vector2(0.5f, 0.5f);
			component.anchorMax = new Vector2(0.5f, 0.5f);
			component.pivot = new Vector2(0.5f, 0.5f);
			component.anchoredPosition = anchoredPos;
			component.sizeDelta = size;
			Image component2 = val.GetComponent<Image>();
			component2.sprite = GetWhiteSprite();
			((Graphic)component2).raycastTarget = false;
			Outline component3 = val.GetComponent<Outline>();
			((Shadow)component3).effectDistance = new Vector2(1f, -1f);
			TextMeshProUGUI label2 = CreateLabel((Transform)(object)component, "Label", font, label, fontSize, Color.white, (TextAlignmentOptions)514, skipScroll);
			MenuSelectableElement selectable = val.AddComponent<MenuSelectableElement>();
			MenuElementHover val2 = val.AddComponent<MenuElementHover>();
			val2.hasHoverEffect = showSelectionBox;
			NativeMenuChip nativeMenuChip = val.AddComponent<NativeMenuChip>();
			nativeMenuChip.Init(component, component2, component3, label2, val2, selectable, onClick);
			return nativeMenuChip;
		}
	}
	internal static class SaveManagerClickGuard
	{
		public static int LastChipConsumeFrame = -1;

		public static int LastHoveredChipFrame = -1;

		public static string CurrentHoverHint = "";

		public static int CurrentHoverHintFrame = -1;

		public static void SetHint(string? hint)
		{
			if (!string.IsNullOrEmpty(hint))
			{
				CurrentHoverHint = hint;
				CurrentHoverHintFrame = Time.frameCount;
			}
		}

		public static string GetActiveHintOrDefault(string fallback)
		{
			if (Time.frameCount - CurrentHoverHintFrame > 2 || string.IsNullOrEmpty(CurrentHoverHint))
			{
				return fallback;
			}
			return CurrentHoverHint;
		}

		public static bool ShouldBlockParentRowClick()
		{
			int frameCount = Time.frameCount;
			if (LastChipConsumeFrame != frameCount)
			{
				return LastHoveredChipFrame == frameCount;
			}
			return true;
		}
	}
	internal sealed class NativeMenuChip : MonoBehaviour
	{
		public Color NormalBg = new Color(0.09f, 0.12f, 0.18f, 0.95f);

		public Color HoverBg = new Color(0.24f, 0.34f, 0.48f, 0.99f);

		public Color ActiveBg = new Color(0.88f, 0.5f, 0.08f, 0.98f);

		public Color NormalBorder = new Color(0.38f, 0.46f, 0.58f, 0.92f);

		public Color HoverBorder = new Color(1f, 0.84f, 0.28f, 1f);

		public Color NormalText = new Color(0.92f, 0.95f, 0.99f, 1f);

		public Color HoverText = Color.white;

		public Color DisabledText = new Color(0.62f, 0.66f, 0.72f, 0.85f);

		public bool IsActiveState;

		public bool IsDisabled;

		public bool BlockParentRow;

		public Func<string>? TooltipProvider;

		private Action? clickHandler;

		public Action? RightClickHandler;

		private float clickCooldown;

		private bool wasHovering;

		public RectTransform Rect { get; private set; }

		public Image Background { get; private set; }

		public Outline Border { get; private set; }

		public TextMeshProUGUI Label { get; private set; }

		public MenuElementHover Hover { get; private set; }

		public MenuSelectableElement Selectable { get; private set; }

		public void Init(RectTransform rt, Image bg, Outline border, TextMeshProUGUI label, MenuElementHover hover, MenuSelectableElement selectable, Action onClick)
		{
			Rect = rt;
			Background = bg;
			Border = border;
			Label = label;
			Hover = hover;
			Selectable = selectable;
			clickHandler = onClick;
			ApplyVisuals(hovering: false, instant: true);
		}

		public void SetText(string text)
		{
			if ((Object)(object)Label != (Object)null && ((TMP_Text)Label).text != text)
			{
				((TMP_Text)Label).text = text;
			}
		}

		public void SetTheme(Color normalBg, Color activeBg, Color borderColor, Color textColor)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			NormalBg = normalBg;
			ActiveBg = activeBg;
			NormalBorder = borderColor;
			NormalText = textColor;
			ApplyVisuals(NativeSavesAccess.IsHovering(Hover), instant: true);
		}

		private void Update()
		{
			if (clickCooldown > 0f)
			{
				clickCooldown -= Time.unscaledDeltaTime;
			}
			bool flag = !IsDisabled && NativeSavesAccess.IsHovering(Hover);
			if (flag && BlockParentRow)
			{
				SaveManagerClickGuard.LastHoveredChipFrame = Time.frameCount;
			}
			if ((Object)(object)Hover != (Object)null && NativeSavesAccess.IsHovering(Hover) && TooltipProvider != null)
			{
				SaveManagerClickGuard.SetHint(TooltipProvider());
			}
			if (flag && !wasHovering && !Hover.hasHoverEffect)
			{
				try
				{
					MenuManager instance = MenuManager.instance;
					if (instance != null)
					{
						instance.MenuEffectHover(SemiFunc.MenuGetPitchFromYPos(Rect), -1f);
					}
				}
				catch
				{
				}
			}
			wasHovering = flag;
			ApplyVisuals(flag, instant: false);
			if (!flag || (Object)(object)Hover == (Object)null || NativeSavesAccess.JustBecameCurrentTarget(Hover) || clickCooldown > 0f)
			{
				return;
			}
			if (SemiFunc.InputUIClick())
			{
				clickCooldown = 0.16f;
				if (BlockParentRow)
				{
					SaveManagerClickGuard.LastChipConsumeFrame = Time.frameCount;
				}
				clickHandler?.Invoke();
			}
			else if (RightClickHandler != null && Input.GetMouseButtonDown(1))
			{
				clickCooldown = 0.16f;
				if (BlockParentRow)
				{
					SaveManagerClickGuard.LastChipConsumeFrame = Time.frameCount;
				}
				RightClickHandler();
			}
		}

		private void ApplyVisuals(bool hovering, bool instant)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: 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_003f: 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)
			//IL_00a7: 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_009f: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: 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_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: 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_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Background == (Object)null) && !((Object)(object)Border == (Object)null) && !((Object)(object)Label == (Object)null))
			{
				Color val = (Color)(IsDisabled ? new Color(0.06f, 0.07f, 0.09f, 0.65f) : (hovering ? HoverBg : (IsActiveState ? ActiveBg : NormalBg)));
				Color val2 = (Color)(IsDisabled ? new Color(0.2f, 0.22f, 0.25f, 0.5f) : (hovering ? HoverBorder : (IsActiveState ? new Color(1f, 0.88f, 0.45f, 0.95f) : NormalBorder)));
				Color val3 = (IsDisabled ? DisabledText : ((hovering || IsActiveState) ? HoverText : NormalText));
				if (instant)
				{
					((Graphic)Background).color = val;
					((Shadow)Border).effectColor = val2;
					((Graphic)Label).color = val3;
				}
				else
				{
					float num = Mathf.Clamp01(Time.unscaledDeltaTime * 16f);
					((Graphic)Background).color = Color.Lerp(((Graphic)Background).color, val, num);
					((Shadow)Border).effectColor = Color.Lerp(((Shadow)Border).effectColor, val2, num);
					((Graphic)Label).color = Color.Lerp(((Graphic)Label).color, val3, num);
				}
			}
		}
	}
	internal static class NativeSavesAccess
	{
		private static readonly Func<MenuElementHover, bool>? HoverIsHovering = CreatePropGetter<MenuElementHover, bool>("isHovering");

		private static readonly Func<MenuElementHover, bool>? HoverJustBecameTarget = CreatePropGetter<MenuElementHover, bool>("JustBecameCurrentTarget");

		public static readonly FieldRef<MenuElementSaveFile, string> ElemSaveFileName = AccessTools.FieldRefAccess<MenuElementSaveFile, string>("saveFileName");

		public static readonly FieldRef<MenuElementSaveFile, List<string>> ElemSaveFileBackups = AccessTools.FieldRefAccess<MenuElementSaveFile, List<string>>("saveFileBackups");

		public static readonly FieldRef<MenuPageSaves, List<MenuElementSaveFile>> PageSaveFiles = AccessTools.FieldRefAccess<MenuPageSaves, List<MenuElementSaveFile>>("saveFiles");

		public static readonly FieldRef<MenuPageSaves, string> PageCurrentSaveFileName = AccessTools.FieldRefAccess<MenuPageSaves, string>("currentSaveFileName");

		public static readonly FieldRef<MenuPageSaves, float> PageSaveFileYOffset = AccessTools.FieldRefAccess<MenuPageSaves, float>("saveFileYOffset");

		public static readonly FieldRef<MenuScrollBox, float> ScrollAmount = AccessTools.FieldRefAccess<MenuScrollBox, float>("scrollAmount");

		private static readonly MethodInfo? RecalcScrollHeightMethod = AccessTools.Method(typeof(MenuScrollBox), "RecalculateScrollHeight", new Type[1] { typeof(bool) }, (Type[])null);

		public static readonly FieldRef<MenuManager, MenuPageIndex> CurrentMenuPageIndex = AccessTools.FieldRefAccess<MenuManager, MenuPageIndex>("currentMenuPageIndex");

		private static readonly Func<MenuPage, bool>? PageIsInteractableGetter = CreatePropOrFieldGetter<MenuPage, bool>("isInteractable");

		public static readonly FieldRef<StatsManager, string> StatsSaveFileCurrent = AccessTools.FieldRefAccess<StatsManager, string>("saveFileCurrent");

		public static bool IsHovering(MenuElementHover? hover)
		{
			if ((Object)(object)hover != (Object)null && HoverIsHovering != null)
			{
				return HoverIsHovering(hover);
			}
			return false;
		}

		public static bool JustBecameCurrentTarget(MenuElementHover? hover)
		{
			if ((Object)(object)hover != (Object)null && HoverJustBecameTarget != null)
			{
				return HoverJustBecameTarget(hover);
			}
			return false;
		}

		public static bool IsPageInteractable(MenuPage? page)
		{
			if (!((Object)(object)page == (Object)null) && PageIsInteractableGetter != null)
			{
				return PageIsInteractableGetter(page);
			}
			return true;
		}

		public static void RecalculateScrollHeight(MenuScrollBox? scrollBox, bool includeInactive = false)
		{
			if (!((Object)(object)scrollBox == (Object)null))
			{
				RecalcScrollHeightMethod?.Invoke(scrollBox, new object[1] { includeInactive });
			}
		}

		private static Func<T, TResult>? CreatePropGetter<T, TResult>(string propName)
		{
			MethodInfo methodInfo = AccessTools.PropertyGetter(typeof(T), propName);
			if (methodInfo == null)
			{
				return null;
			}
			return (Func<T, TResult>)Delegate.CreateDelegate(typeof(Func<T, TResult>), methodInfo);
		}

		private static Func<T, TResult>? CreatePropOrFieldGetter<T, TResult>(string memberName)
		{
			MethodInfo methodInfo = AccessTools.PropertyGetter(typeof(T), memberName);
			if (methodInfo != null)
			{
				return (Func<T, TResult>)Delegate.CreateDelegate(typeof(Func<T, TResult>), methodInfo);
			}
			FieldInfo field = AccessTools.Field(typeof(T), memberName);
			if (field != null)
			{
				return (T obj) => (TResult)field.GetValue(obj);
			}
			return null;
		}
	}
	[BepInPlugin("com.matsu.reposaveorganizer", "REPO Save Organizer", "1.0.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.matsu.reposaveorganizer";

		public const string PluginName = "REPO Save Organizer";

		public const string PluginVersion = "1.0.0";

		private static SaveManagerCatalog? sharedCatalog;

		private Harmony? harmony;

		internal static ManualLogSource Log { get; private set; }

		internal static ConfigEntry<int>? MaxSaveSlots { get; private set; }

		internal static ConfigEntry<int>? MaxBackupsPerSave { get; private set; }

		internal static ConfigEntry<bool>? ProtectPinnedFromBulkDelete { get; private set; }

		internal static ConfigEntry<LanguageOption>? LanguageMode { get; private set; }

		internal static SaveManagerCatalog GetSharedCatalog()
		{
			if (sharedCatalog == null)
			{
				sharedCatalog = new SaveManagerCatalog(Es3SaveHelper.SavesRoot);
			}
			return sharedCatalog;
		}

		private void Awake()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			MaxSaveSlots = ((BaseUnityPlugin)this).Config.Bind<int>("Saves", "MaxSaveSlots", 0, new ConfigDescription("Maximum number of save files allowed (0 = Unlimited, vanilla default is 10). / 最大セーブ枠数 (0 = 無制限、バニラ初期値は10)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10000), Array.Empty<object>()));
			MaxBackupsPerSave = ((BaseUnityPlugin)this).Config.Bind<int>("Saves", "MaxBackupsPerSave", 10, new ConfigDescription("Maximum .es3 backup files retained per save slot (vanilla default is 3). / 1セーブあたりの保持バックアップ数", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			ProtectPinnedFromBulkDelete = ((BaseUnityPlugin)this).Config.Bind<bool>("Safety", "ProtectPinnedFromBulkDelete", true, "Automatically skip ★ Pinned saves during Bulk Delete so favorite runs are never accidentally deleted. / ★ピン留め中のセーブを一括削除から自動保護する");
			LanguageMode = ((BaseUnityPlugin)this).Config.Bind<LanguageOption>("UI", "Language", LanguageOption.Auto, "UI display language (Auto detects R.E.P.O. game language). / 表示言語 (Autoでゲームの言語設定に追従)");
			harmony = new Harmony("com.matsu.reposaveorganizer");
			harmony.PatchAll(typeof(Plugin).Assembly);
			Log.LogInfo((object)("REPO Save Organizer 1.0.0 initialized (MaxSaveSlots=" + ((MaxSaveSlots.Value == 0) ? "Unlimited" : MaxSaveSlots.Value.ToString()) + ")."));
		}
	}
	internal sealed class SaveManagerController : MonoBehaviour
	{
		private static readonly MethodInfo? RecalcScrollMethod = AccessTools.Method(typeof(MenuScrollBox), "RecalculateScrollHeight", new Type[1] { typeof(bool) }, (Type[])null);

		private static readonly MethodInfo? UpdateNewGameNavMethod = AccessTools.Method(typeof(MenuPageSaves), "UpdateNewGameNavigation", (Type[])null, (Type[])null);

		private static readonly FieldInfo? MenuPageField = AccessTools.Field(typeof(MenuPageSaves), "menuPage");

		private readonly Dictionary<string, MenuElementSaveFile> allRowElements = new Dictionary<string, MenuElementSaveFile>(StringComparer.OrdinalIgnoreCase);

		private readonly List<SaveSummary> allSummaries = new List<SaveSummary>();

		private readonly List<SaveSummary> visibleSummaries = new List<SaveSummary>();

		private TMP_FontAsset? uiFont;

		private MenuButtonPopUp? popupHelper;

		private RectTransform? topBarRoot;

		private NativeMenuChip? tabAllChip;

		private NativeMenuChip? tabPinnedChip;

		private NativeMenuChip? tabUncatChip;

		private NativeMenuChip? catPrevChip;

		private NativeMenuChip? catNextChip;

		private readonly NativeMenuChip[] userCatChips = new NativeMenuChip[3];

		private readonly string?[] userCatIdsOnPage = new string[3];

		private NativeMenuChip? addCatChip;

		private NativeMenuChip? renameCatChip;

		private NativeMenuChip? colorCatChip;

		private NativeMenuChip? deleteCatChip;

		private TextMeshProUGUI? slotCounterLabel;

		private RectTransform? bottomBarRoot;

		private NativeMenuChip? sortChip;

		private NativeMenuChip? searchChip;

		private NativeMenuChip? selectAllChip;

		private NativeMenuChip? bulkDeleteChip;

		private NativeMenuChip? duplicateChip;

		private NativeMenuChip? newSlotChip;

		private NativeMenuChip? moveCatChip;

		private NativeMenuChip? renameSaveChip;

		private TextMeshProUGUI? emptyHintLabel;

		private TextMeshProUGUI? guideHintLabel;

		private RectTransform? sortModal;

		private TextMeshProUGUI? sortTitleLabel;

		private readonly NativeMenuChip[] sortModeChips = new NativeMenuChip[9];

		private NativeMenuChip? sortCloseChip;

		private RectTransform? pickerModal;

		private TextMeshProUGUI? pickerTitleLabel;

		private NativeMenuChip? pickerUncatChip;

		private NativeMenuChip? pickerCreateNewChip;

		private NativeMenuChip? pickerPrevChip;

		private NativeMenuChip? pickerNextChip;

		private NativeMenuChip? pickerCloseChip;

		private readonly NativeMenuChip[] pickerCatChips = new NativeMenuChip[6];

		private readonly string?[] pickerCatIds = new string[6];

		private List<string> pendingMoveTargets = new List<string>();

		private int pickerPage;

		private int categoryTabPage;

		private string searchQuery = "";

		private bool uiBuilt;

		private bool isRebuilding;

		private bool initialSavesSynced;

		public static SaveManagerController? ActiveInstance { get; private set; }

		public MenuPageSaves PageSaves { get; private set; }

		public SaveManagerCatalog Catalog { get; private set; }

		public SaveSelectionModel Selection { get; } = new SaveSelectionModel();

		public bool IsReady => initialSavesSynced;

		public void EnsureInitialSavesSynced()
		{
			if (!initialSavesSynced && !isRebuilding && !((Object)(object)PageSaves == (Object)null))
			{
				initialSavesSynced = true;
				OnSavesLoadedFromVanilla();
			}
		}

		public void Initialize(MenuPageSaves pageSaves)
		{
			ActiveInstance = this;
			PageSaves = pageSaves;
			Catalog = Plugin.GetSharedCatalog();
			ApplySaveSlotLimit();
			uiFont = (((Object)(object)pageSaves.saveFileHeader != (Object)null) ? ((TMP_Text)pageSaves.saveFileHeader).font : (((Object)(object)pageSaves.gameModeHeader != (Object)null) ? ((TMP_Text)pageSaves.gameModeHeader).font : null));
			NativeUiFactory.EnsureJapaneseFallback(uiFont);
			popupHelper = ((Component)this).gameObject.GetComponent<MenuButtonPopUp>() ?? ((Component)this).gameObject.AddComponent<MenuButtonPopUp>();
			EnsureUiBuilt();
		}

		private void OnDestroy()
		{
			if ((Object)(object)ActiveInstance == (Object)(object)this)
			{
				ActiveInstance = null;
			}
		}

		public void ApplySaveSlotLimit()
		{
			if (!((Object)(object)PageSaves == (Object)null))
			{
				int num = ((Plugin.MaxSaveSlots != null) ? Plugin.MaxSaveSlots.Value : 0);
				PageSaves.maxSaveFiles = ((num > 0) ? num : 0);
			}
		}

		public void OnSavesLoadedFromVanilla()
		{
			ApplySaveSlotLimit();
			EnsureUiBuilt();
			allRowElements.Clear();
			List<MenuElementSaveFile> list = NativeSavesAccess.PageSaveFiles.Invoke(PageSaves);
			if (list != null)
			{
				foreach (MenuElementSaveFile item in list)
				{
					if (!((Object)(object)item == (Object)null))
					{
						string text = NativeSavesAccess.ElemSaveFileName.Invoke(item);
						if (!string.IsNullOrWhiteSpace(text))
						{
							allRowElements[text] = item;
							AttachRowView(item);
						}
					}
				}
			}
			Selection.PruneMissing(new HashSet<string>(allRowElements.Keys, StringComparer.OrdinalIgnoreCase));
			RebuildFilterSortAndLayout(preserveScroll: false);
		}

		private SaveRowView AttachRowView(MenuElementSaveFile elem)
		{
			SaveRowView obj = ((Component)elem).GetComponent<SaveRowView>() ?? ((Component)elem).gameObject.AddComponent<SaveRowView>();
			obj.Attach(elem, this);
			return obj;
		}

		private MenuElementSaveFile? InstantiateSaveRowElement(string folderName, List<string> backups)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)PageSaves.saveFilePrefab == (Object)null || (Object)(object)PageSaves.Scroller == (Object)null)
			{
				return null;
			}
			GameObject val = Object.Instantiate<GameObject>(PageSaves.saveFilePrefab, (Transform)(object)PageSaves.Scroller);
			val.transform.localPosition = ((Transform)PageSaves.saveFilePosition).localPosition;
			val.transform.SetSiblingIndex(3);
			MenuElementSaveFile component = val.GetComponent<MenuElementSaveFile>();
			NativeSavesAccess.ElemSaveFileName.Invoke(component) = folderName;
			NativeSavesAccess.ElemSaveFileBackups.Invoke(component) = backups;
			PageSaves.UpdateSaveDetails(component, folderName);
			if (NativeSavesAccess.PageSaveFileYOffset.Invoke(PageSaves) <= 1f)
			{
				RectTransform component2 = val.GetComponent<RectTransform>();
				ref float reference = ref NativeSavesAccess.PageSaveFileYOffset.Invoke(PageSaves);
				float num;
				if (!((Object)(object)component2 != (Object)null))
				{
					num = 44f;
				}
				else
				{
					Rect rect = component2.rect;
					num = ((Rect)(ref rect)).height;
				}
				reference = num + 2f;
			}
			allRowElements[folderName] = component;
			AttachRowView(component);
			return component;
		}

		public void RebuildFilterSortAndLayout(bool preserveScroll = true)
		{
			if ((Object)(object)PageSaves == (Object)null || isRebuilding)
			{
				return;
			}
			isRebuilding = true;
			try
			{
				RebuildFilterSortAndLayoutCore(preserveScroll);
			}
			finally
			{
				isRebuilding = false;
			}
		}

		private void RebuildFilterSortAndLayoutCore(bool preserveScroll)
		{
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: 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_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			EnsureUiBuilt();
			allSummaries.Clear();
			foreach (KeyValuePair<string, MenuElementSaveFile> allRowElement in allRowElements)
			{
				if (!((Object)(object)allRowElement.Value == (Object)null))
				{
					allSummaries.Add(Es3SaveHelper.ReadSummary(allRowElement.Key, NativeSavesAccess.ElemSaveFileBackups.Invoke(allRowElement.Value)));
				}
			}
			visibleSummaries.Clear();
			visibleSummaries.AddRange(Catalog.FilterAndSort(allSummaries, searchQuery));
			HashSet<string> hashSet = new HashSet<string>(visibleSummaries.Select((SaveSummary s) => s.FolderName), StringComparer.OrdinalIgnoreCase);
			foreach (KeyValuePair<string, MenuElementSaveFile> allRowElement2 in allRowElements)
			{
				if (!((Object)(object)allRowElement2.Value == (Object)null))
				{
					bool flag = hashSet.Contains(allRowElement2.Key);
					if (((Component)allRowElement2.Value).gameObject.activeSelf != flag)
					{
						((Component)allRowElement2.Value).gameObject.SetActive(flag);
					}
				}
			}
			List<MenuElementSaveFile> list = NativeSavesAccess.PageSaveFiles.Invoke(PageSaves);
			list.Clear();
			Vector3 val = (((Object)(object)PageSaves.saveFilePosition != (Object)null) ? ((Transform)PageSaves.saveFilePosition).localPosition : Vector3.zero);
			float num = 0f;
			Vector3 val2 = default(Vector3);
			for (int num2 = 0; num2 < visibleSummaries.Count; num2++)
			{
				string folderName = visibleSummaries[num2].FolderName;
				if (!allRowElements.TryGetValue(folderName, out MenuElementSaveFile value) || (Object)(object)value == (Object)null)
				{
					continue;
				}
				RectTransform component = ((Component)value).GetComponent<RectTransform>();
				float num3;
				if ((Object)(object)component != (Object)null)
				{
					Rect rect = component.rect;
					if (((Rect)(ref rect)).height > 4f)
					{
						rect = component.rect;
						num3 = ((Rect)(ref rect)).height;
						goto IL_021a;
					}
				}
				num3 = 42f;
				goto IL_021a;
				IL_021a:
				float num4 = num3 + 2f;
				NativeSavesAccess.PageSaveFileYOffset.Invoke(PageSaves) = num4;
				((Vector3)(ref val2))..ctor(val.x, val.y + num, val.z);
				((Component)value).transform.localPosition = val2;
				MenuElementAnimations component2 = ((Component)value).GetComponent<MenuElementAnimations>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.UIAniNewInitialPosition(new Vector2(val2.x, val2.y));
				}
				num -= num4;
				list.Add(value);
				(((Component)value).GetComponent<SaveRowView>() ?? AttachRowView(value)).RefreshVisuals();
			}
			float num5 = (((Object)(object)PageSaves.menuScrollBox != (Object)null) ? NativeSavesAccess.ScrollAmount.Invoke(PageSaves.menuScrollBox) : 0f);
			if ((Object)(object)PageSaves.menuScrollBox != (Object)null)
			{
				NativeSavesAccess.RecalculateScrollHeight(PageSaves.menuScrollBox);
				if (preserveScroll && num5 > 0f)
				{
					NativeSavesAccess.ScrollAmount.Invoke(PageSaves.menuScrollBox) = num5;
				}
			}
			UpdateNewGameNavMethod?.Invoke(PageSaves, null);
			string text = NativeSavesAccess.PageCurrentSaveFileName.Invoke(PageSaves);
			if (!string.IsNullOrEmpty(text) && !hashSet.Contains(text))
			{
				NativeSavesAccess.PageCurrentSaveFileName.Invoke(PageSaves) = "";
				PageSaves.GoBackToDefaultInfo();
			}
			if ((Object)(object)emptyHintLabel != (Object)null)
			{
				((Component)emptyHintLabel).gameObject.SetActive(visibleSummaries.Count == 0);
				((TMP_Text)emptyHintLabel).text = SaveManagerLocalization.EmptyCategoryHint();
			}
			RefreshToolbarVisuals();
		}

		private void EnsureUiBuilt()
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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_00fe: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			if (!uiBuilt && !((Object)(object)PageSaves == (Object)null))
			{
				uiBuilt = true;
				Transform transform = ((Component)PageSaves).transform;
				if ((Object)(object)PageSaves.saveFileInfo != (Object)null)
				{
					((Transform)PageSaves.saveFileInfo).localScale = new Vector3(0.9f, 0.72f, 1f);
					((Transform)PageSaves.saveFileInfo).localPosition = new Vector3(522f, 169f, 0f);
				}
				BuildTopCategoryBar(transform, new Vector2(526f, 300f), 300f);
				BuildLiveGuideBar(transform, new Vector2(526f, 55f), 300f);
				BuildBottomActionBar(transform, new Vector2(526f, 24f), 300f);
				BuildEmptyListHint();
				BuildCategoryPickerModal(transform, new Vector2(526f, 168f));
				BuildSortPickerModal(transform, new Vector2(526f, 168f));
			}
		}

		private void BuildTopCategoryBar(Transform parent, Vector2 center, float width)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_00db: 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_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: 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_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: 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_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0471: Unknown result type (might be due to invalid IL or missing references)
			//IL_047d: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04de: Unknown result type (might be due to invalid IL or missing references)
			topBarRoot = NativeUiFactory.CreatePanel(parent, "SaveOrganizer_CategoryBar", center, new Vector2(width, 38f), new Color(0.03f, 0.05f, 0.08f, 0.94f), new Color(0.24f, 0.36f, 0.52f, 0.9f), skipScroll: false, bottomLeftAnchor: true);
			float num = 8.5f;
			float num2 = -8.5f;
			float num3 = (0f - width) * 0.5f + 4f;
			tabAllChip = NativeUiFactory.CreateChip((Transform)(object)topBarRoot, "TabAll", uiFont, "ALL", new Vector2(num3 + 27f, num), new Vector2(54f, 14.5f), 8.2f, delegate
			{
				SelectFilter(CategoryFilterKind.All, null);
			});
			tabPinnedChip = NativeUiFactory.CreateChip((Transform)(object)topBarRoot, "TabPinned", uiFont, "★", new Vector2(num3 + 73.5f, num), new Vector2(34f, 14.5f), 8.2f, delegate
			{
				SelectFilter(CategoryFilterKind.Pinned, null);
			});
			tabUncatChip = NativeUiFactory.CreateChip((Transform)(object)topBarRoot, "TabUncat", uiFont, "NONE", new Vector2(num3 + 118f, num), new Vector2(50f, 14.5f), 8.2f, delegate
			{
				SelectFilter(CategoryFilterKind.Uncategorized, null);
			});
			addCatChip = NativeUiFactory.CreateChip((Transform)(object)topBarRoot, "AddCat", uiFont, "+CAT", new Vector2(num3 + 169.5f, num), new Vector2(48f, 14.5f), 8f, PromptCreateCategory);
			addCatChip.TooltipProvider = SaveManagerLocalization.HintAddCat;
			renameCatChip = NativeUiFactory.CreateChip((Transform)(object)topBarRoot, "RenCat", uiFont, "REN", new Vector2(num3 + 214f, num), new Vector2(36f, 14.5f), 7.5f, PromptRenameActiveCategory);
			colorCatChip = NativeUiFactory.CreateChip((Transform)(object)topBarRoot, "ColCat", uiFont, "COL", new Vector2(num3 + 243.5f, num), new Vector2(18f, 14.5f), 7.5f, CycleActiveCategoryColor);
			deleteCatChip = NativeUiFactory.CreateChip((Transform)(object)topBarRoot, "DelCat", uiFont, "DEL", new Vector2(num3 + 273f, num), new Vector2(36f, 14.5f), 7.5f, PromptDeleteActiveCategory);
			RectTransform component = new GameObject("SlotBadge", new Type[1] { typeof(RectTransform) })
			{
				layer = ((Component)topBarRoot).gameObject.layer
			}.GetComponent<RectTransform>();
			((Transform)component).SetParent((Transform)(object)topBarRoot, false);
			component.anchorMin = new Vector2(0.5f, 0.5f);
			component.anchorMax = new Vector2(0.5f, 0.5f);
			component.anchoredPosition = new Vector2(width * 0.5f - 52f, num);
			component.sizeDelta = new Vector2(92f, 15f);
			slotCounterLabel = NativeUiFactory.CreateLabel((Transform)(object)component, "Text", uiFont, "", 8.6f, new Color(0.75f, 0.92f, 1f, 1f), (TextAlignmentOptions)4100);
			catPrevChip = NativeUiFactory.CreateChip((Transform)(object)topBarRoot, "CatPrev", uiFont, "◀", new Vector2(num3 + 9f, num2), new Vector2(16f, 14.5f), 7.5f, delegate
			{
				categoryTabPage = Mathf.Max(0, categoryTabPage - 1);
				NativeUiFactory.PlayTickSound();
				RefreshToolbarVisuals();
			});
			float num4 = (width - 46f - 6f) / 3f;
			for (int num5 = 0; num5 < 3; num5++)
			{
				int slotIndex = num5;
				float num6 = num3 + 20f + num4 * 0.5f + (float)num5 * (num4 + 3f);
				userCatChips[num5] = NativeUiFactory.CreateChip((Transform)(object)topBarRoot, $"UserCat_{num5}", uiFont, "", new Vector2(num6, num2), new Vector2(num4, 14.5f), 8f, delegate
				{
					string text = userCatIdsOnPage[slotIndex];
					if (!string.IsNullOrEmpty(text))
					{
						SelectFilter(CategoryFilterKind.Category, text);
					}
				});
			}
			catNextChip = NativeUiFactory.CreateChip((Transform)(object)topBarRoot, "CatNext", uiFont, "▶", new Vector2(width * 0.5f - 12f, num2), new Vector2(16f, 14.5f), 7.5f, delegate
			{
				categoryTabPage++;
				NativeUiFactory.PlayTickSound();
				RefreshToolbarVisuals();
			});
		}

		private void BuildBottomActionBar(Transform parent, Vector2 center, float width)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: Unknown result type (might be due to invalid IL or missing references)
			//IL_043e: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
			bottomBarRoot = NativeUiFactory.CreatePanel(parent, "SaveOrganizer_ActionBar", center, new Vector2(width, 38f), new Color(0.03f, 0.05f, 0.08f, 0.94f), new Color(0.24f, 0.36f, 0.52f, 0.9f), skipScroll: false, bottomLeftAnchor: true);
			float num = 8.5f;
			float num2 = -8.5f;
			float num3 = (0f - width) * 0.5f + 4f;
			float num4 = 3f;
			float num5 = 90f;
			float num6 = 58f;
			float num7 = 52f;
			float num8 = Mathf.Max(66f, width - 8f - num5 - num6 - num7 - num4 * 3f);
			float num9 = num3 + num5 * 0.5f;
			sortChip = NativeUiFactory.CreateChip((Transform)(object)bottomBarRoot, "BtnSort", uiFont, "SORT", new Vector2(num9, num), new Vector2(num5, 15f), 8.5f, OnOpenSortPickerClicked);
			sortChip.RightClickHandler = OnCycleSortClicked;
			sortChip.TooltipProvider = SaveManagerLocalization.HintSort;
			num9 += num5 * 0.5f + num4 + num6 * 0.5f;
			searchChip = NativeUiFactory.CreateChip((Transform)(object)bottomBarRoot, "BtnSearch", uiFont, "FIND", new Vector2(num9, num), new Vector2(num6, 15f), 8.5f, OnSearchClicked);
			searchChip.TooltipProvider = SaveManagerLocalization.HintSearch;
			num9 += num6 * 0.5f + num4 + num7 * 0.5f;
			selectAllChip = NativeUiFactory.CreateChip((Transform)(object)bottomBarRoot, "BtnSelAll", uiFont, "ALL", new Vector2(num9, num), new Vector2(num7, 15f), 8.5f, OnSelectAllClicked);
			selectAllChip.TooltipProvider = SaveManagerLocalization.HintSelectAll;
			num9 += num7 * 0.5f + num4 + num8 * 0.5f;
			bulkDeleteChip = NativeUiFactory.CreateChip((Transform)(object)bottomBarRoot, "BtnBulkDel", uiFont, "BULK DEL", new Vector2(num9, num), new Vector2(num8, 15f), 8.5f, OnBulkDeleteClicked);
			bulkDeleteChip.TooltipProvider = SaveManagerLocalization.HintBulkDelete;
			float num10 = 66f;
			float num11 = 74f;
			float num12 = 80f;
			float num13 = Mathf.Max(56f, width - 8f - num10 - num11 - num12 - num4 * 3f);
			float num14 = num3 + num10 * 0.5f;
			duplicateChip = NativeUiFactory.CreateChip((Transform)(object)bottomBarRoot, "BtnDuplicate", uiFont, "COPY", new Vector2(num14, num2), new Vector2(num10, 15f), 8.5f, OnDuplicateClicked);
			duplicateChip.TooltipProvider = SaveManagerLocalization.HintDuplicate;
			num14 += num10 * 0.5f + num4 + num11 * 0.5f;
			newSlotChip = NativeUiFactory.CreateChip((Transform)(object)bottomBarRoot, "BtnNewSlot", uiFont, "+NEW", new Vector2(num14, num2), new Vector2(num11, 15f), 8.5f, PromptCreateBlankSave);
			newSlotChip.TooltipProvider = SaveManagerLocalization.HintNewSlot;
			num14 += num11 * 0.5f + num4 + num12 * 0.5f;
			moveCatChip = NativeUiFactory.CreateChip((Transform)(object)bottomBarRoot, "BtnMoveCat", uiFont, "MOVE", new Vector2(num14, num2), new Vector2(num12, 15f), 8.5f, OnOpenCategoryPickerClicked);
			moveCatChip.TooltipProvider = SaveManagerLocalization.HintMoveCat;
			num14 += num12 * 0.5f + num4 + num13 * 0.5f;
			renameSaveChip = NativeUiFactory.CreateChip((Transform)(object)bottomBarRoot, "BtnRenameSave", uiFont, "RENAME", new Vector2(num14, num2), new Vector2(num13, 15f), 8.2f, OnRenameSaveClicked);
			renameSaveChip.TooltipProvider = SaveManagerLocalization.HintRenameSave;
		}

		private void BuildLiveGuideBar(Transform parent, Vector2 center, float width)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			RectTransform parent2 = NativeUiFactory.CreatePanel(parent, "SaveOrganizer_GuideBar", center, new Vector2(width, 14f), new Color(0.02f, 0.04f, 0.07f, 0.85f), new Color(0.18f, 0.28f, 0.4f, 0.65f), skipScroll: false, bottomLeftAnchor: true);
			guideHintLabel = NativeUiFactory.CreateLabel((Transform)(object)parent2, "GuideText", uiFont, "", 7.6f, new Color(0.76f, 0.9f, 1f, 0.96f), (TextAlignmentOptions)514);
		}

		private void BuildEmptyListHint()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_0078: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)PageSaves.Scroller == (Object)null))
			{
				GameObject val = new GameObject("EmptyCategoryHint [SCROLL SKIP SELF]", new Type[1] { typeof(RectTransform) })
				{
					layer = ((Component)PageSaves.Scroller).gameObject.layer
				};
				RectTransform component = val.GetComponent<RectTransform>();
				((Transform)component).SetParent((Transform)(object)PageSaves.Scroller, false);
				Vector3 val2 = (((Object)(object)PageSaves.saveFilePosition != (Object)null) ? ((Transform)PageSaves.saveFilePosition).localPosition : Vector3.zero);
				((Transform)component).localPosition = new Vector3(val2.x, val2.y - 16f, val2.z);
				component.sizeDelta = new Vector2(280f, 32f);
				emptyHintLabel = NativeUiFactory.CreateLabel((Transform)(object)component, "HintText", uiFont, "", 10.5f, new Color(0.65f, 0.72f, 0.82f, 0.85f), (TextAlignmentOptions)514, skipScroll: true);
				val.SetActive(false);
			}
		}

		private void Update()
		{
			if ((Object)(object)PageSaves == (Object)null || (Object)(object)MenuManager.instance == (Object)null || (int)NativeSavesAccess.CurrentMenuPageIndex.Invoke(MenuManager.instance) != 11 || !NativeSavesAccess.IsPageInteractable((MenuPage?)/*isinst with value type is only supported in some contexts*/))
			{
				return;
			}
			if ((Object)(object)guideHintLabel != (Object)null)
			{
				string activeHintOrDefault = SaveManagerClickGuard.GetActiveHintOrDefault(SaveManagerLocalization.DefaultHint(Selection.Count));
				if (((TMP_Text)guideHintLabel).text != activeHintOrDefault)
				{
					((TMP_Text)guideHintLabel).text = activeHintOrDefault;
				}
			}
			if ((Object)(object)pickerModal != (Object)null && ((Component)pickerModal).gameObject.activeSelf && SemiFunc.InputDown((InputKey)18))
			{
				CloseCategoryPicker();
				return;
			}
			if ((Object)(object)sortModal != (Object)null && ((Component)sortModal).gameObject.activeSelf && SemiFunc.InputDown((InputKey)18))
			{
				((Component)sortModal).gameObject.SetActive(false);
				return;
			}
			bool flag = Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305);
			if (flag && Input.GetKeyDown((KeyCode)97))
			{
				OnSelectAllClicked();
			}
			else if (flag && Input.GetKeyDown((KeyCode)100))
			{
				OnDuplicateClicked();
			}
			else if (flag && Input.GetKeyDown((KeyCode)102))
			{
				OnSearchClicked();
			}
			else if (flag && Input.GetKeyDown((KeyCode)110))
			{
				PromptCreateBlankSave();
			}
			else if (Input.GetKeyDown((KeyCode)283))
			{
				OnRenameSaveClicked();
			}
			else if (Input.GetKeyDown((KeyCode)127) && Selection.Count > 0)
			{
				OnBulkDeleteClicked();
			}
		}

		public void RefreshToolbarVisuals()
		{
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0684: Unknown result type (might be due to invalid IL or missing references)
			//IL_0689: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04da: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0506: Unknown result type (might be due to invalid IL or missing references)
			//IL_050b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0518: Unknown result type (might be due to invalid IL or missing references)
			//IL_0525: Unknown result type (might be due to invalid IL or missing references)
			//IL_0537: Unknown result type (might be due to invalid IL or missing references)
			//IL_053c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0543: Unknown result type (might be due to invalid IL or missing references)
			//IL_054a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0561: Unknown result type (might be due to invalid IL or missing references)
			//IL_0730: Unknown result type (might be due to invalid IL or missing references)
			//IL_0715: Unknown result type (might be due to invalid IL or missing references)
			//IL_057d: Unknown result type (might be due to invalid IL or missing references)
			//IL_056a: Unknown result type (might be due to invalid IL or missing references)
			//IL_056c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0576: Unknown result type (might be due to invalid IL or missing references)
			//IL_0749: Unknown result type (might be due to invalid IL or missing references)
			//IL_0835: Unknown result type (might be due to invalid IL or missing references)
			//IL_084e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0867: Unknown result type (might be due to invalid IL or missing references)
			//IL_0880: Unknown result type (might be due to invalid IL or missing references)
			//IL_0782: Unknown result type (might be due to invalid IL or missing references)
			//IL_0767: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_08db: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_090d: Unknown result type (might be due to invalid IL or missing references)
			//IL_07bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a0: Unknown result type (might be due to invalid IL or missing references)
			if (!uiBuilt)
			{
				return;
			}
			int count = allSummaries.Count;
			int count2 = Catalog.CountForFilter(allSummaries, CategoryFilterKind.Pinned);
			int count3 = Catalog.CountForFilter(allSummaries, CategoryFilterKind.Uncategorized);
			CategoryFilterKind activeFilterKind = Catalog.Data.ActiveFilterKind;
			string activeCategoryId = Catalog.Data.ActiveCategoryId;
			if ((Object)(object)tabAllChip != (Object)null)
			{
				tabAllChip.SetText(SaveManagerLocalization.TabAll(count));
				tabAllChip.IsActiveState = activeFilterKind == CategoryFilterKind.All;
			}
			if ((Object)(object)tabPinnedChip != (Object)null)
			{
				tabPinnedChip.SetText(SaveManagerLocalization.TabPinned(count2));
				tabPinnedChip.IsActiveState = activeFilterKind == CategoryFilterKind.Pinned;
				tabPinnedChip.ActiveBg = new Color(0.78f, 0.54f, 0.06f, 0.96f);
			}
			if ((Object)(object)tabUncatChip != (Object)null)
			{
				tabUncatChip.SetText(SaveManagerLocalization.TabUncategorized(count3));
				tabUncatChip.IsActiveState = activeFilterKind == CategoryFilterKind.Uncategorized;
			}
			if ((Object)(object)addCatChip != (Object)null)
			{
				addCatChip.SetText(SaveManagerLocalization.TabNewCategory());
				addCatChip.SetTheme(new Color(0.06f, 0.22f, 0.18f, 0.94f), new Color(0.1f, 0.55f, 0.42f, 0.96f), new Color(0.22f, 0.72f, 0.56f, 0.9f), new Color(0.68f, 1f, 0.88f, 1f));
			}
			bool flag = activeFilterKind == CategoryFilterKind.Category && Catalog.FindCategory(activeCategoryId) != null;
			if ((Object)(object)renameCatChip != (Object)null)
			{
				((Component)renameCatChip).gameObject.SetActive(flag);
				renameCatChip.SetText(SaveManagerLocalization.BtnRenameCategory());
			}
			if ((Object)(object)colorCatChip != (Object)null)
			{
				((Component)colorCatChip).gameObject.SetActive(flag);
				colorCatChip.SetText(SaveManagerLocalization.BtnColorCategory());
				SaveCategory saveCategory = Catalog.FindCategory(activeCategoryId);
				if (saveCategory != null)
				{
					Color val = NativeUiFactory.HexColor(saveCategory.ColorHex, 0.95f);
					colorCatChip.SetTheme(val * 0.55f, val, val, Color.white);
				}
			}
			if ((Object)(object)deleteCatChip != (Object)null)
			{
				((Component)deleteCatChip).gameObject.SetActive(flag);
				deleteCatChip.SetText(SaveManagerLocalization.BtnDeleteCategory());
				deleteCatChip.SetTheme(new Color(0.32f, 0.08f, 0.1f, 0.94f), new Color(0.75f, 0.15f, 0.18f, 0.96f), new Color(0.85f, 0.3f, 0.32f, 0.9f), new Color(1f, 0.75f, 0.75f, 1f));
			}
			if ((Object)(object)slotCounterLabel != (Object)null)
			{
				((Component)slotCounterLabel).gameObject.SetActive(!flag);
				int maxSaves = ((Plugin.MaxSaveSlots != null) ? Plugin.MaxSaveSlots.Value : 0);
				((TMP_Text)slotCounterLabel).text = SaveManagerLocalization.SlotCountBadge(count, maxSaves);
			}
			IReadOnlyList<SaveCategory> categories = Catalog.GetCategories();
			int num = Mathf.Max(1, Mathf.CeilToInt((float)categories.Count / 3f));
			categoryTabPage = Mathf.Clamp(categoryTabPage, 0, num - 1);
			if ((Object)(object)catPrevChip != (Object)null)
			{
				catPrevChip.IsDisabled = categoryTabPage <= 0;
				((Component)catPrevChip).gameObject.SetActive(categories.Count > 3);
			}
			if ((Object)(object)catNextChip != (Object)null)
			{
				catNextChip.IsDisabled = categoryTabPage >= num - 1;
				((Component)catNextChip).gameObject.SetActive(categories.Count > 3);
			}
			for (int i = 0; i < 3; i++)
			{
				int num2 = categoryTabPage * 3 + i;
				NativeMenuChip nativeMenuChip = userCatChips[i];
				if (!((Object)(object)nativeMenuChip == (Object)null))
				{
					if (num2 < categories.Count)
					{
						SaveCategory saveCategory2 = categories[num2];
						int num3 = Catalog.CountForFilter(allSummaries, CategoryFilterKind.Category, saveCategory2.Id);
						userCatIdsOnPage[i] = saveCategory2.Id;
						((Component)nativeMenuChip).gameObject.SetActive(true);
						nativeMenuChip.SetText($"{saveCategory2.Name} ({num3})");
						bool flag2 = (nativeMenuChip.IsActiveState = activeFilterKind == CategoryFilterKind.Category && string.Equals(activeCategoryId, saveCategory2.Id, StringComparison.OrdinalIgnoreCase));
						Color val2 = NativeUiFactory.HexColor(saveCategory2.ColorHex);
						nativeMenuChip.SetTheme(new Color(val2.r * 0.18f, val2.g * 0.18f, val2.b * 0.18f, 0.92f), new Color(val2.r * 0.72f, val2.g * 0.72f, val2.b * 0.72f, 0.98f), new Color(val2.r, val2.g, val2.b, flag2 ? 1f : 0.7f), flag2 ? Color.white : Color.Lerp(val2, Color.white, 0.55f));
					}
					else
					{
						userCatIdsOnPage[i] = null;
						((Component)nativeMenuChip).gameObject.SetActive(false);
					}
				}
			}
			int count4 = Selection.Count;
			List<string> list = visibleSummaries.Select((SaveSummary s) => s.FolderName).ToList();
			bool allChecked = Selection.AreAllVisibleChecked(list);
			if ((Object)(object)sortChip != (Object)null)
			{
				sortChip.SetText(SaveManagerLocalization.SortLabel(Catalog.Data.SortMode));
			}
			if ((Object)(object)searchChip != (Object)null)
			{
				bool isActiveState = !string.IsNullOrWhiteSpace(searchQuery);
				searchChip.SetText(SaveManagerLocalization.BtnSearch(searchQuery));
				searchChip.IsActiveState = isActiveState;
				searchChip.ActiveBg = new Color(0.16f, 0.52f, 0.78f, 0.96f);
			}
			if ((Object)(object)selectAllChip != (Object)null)
			{
				selectAllChip.SetText(SaveManagerLocalization.BtnSelectAll(allChecked));
				selectAllChip.IsDisabled = list.Count == 0;
			}
			if ((Object)(object)bulkDeleteChip != (Object)null)
			{
				bulkDeleteChip.SetText(SaveManagerLocalization.BtnBulkDelete(count4));
				bulkDeleteChip.IsDisabled = count4 == 0;
				bulkDeleteChip.SetTheme((count4 > 0) ? new Color(0.45f, 0.08f, 0.1f, 0.96f) : new Color(0.12f, 0.08f, 0.09f, 0.75f), new Color(0.82f, 0.14f, 0.16f, 0.98f), (count4 > 0) ? new Color(1f, 0.36f, 0.36f, 0.95f) : new Color(0.35f, 0.22f, 0.24f, 0.6f), (count4 > 0) ? new Color(1f, 0.86f, 0.86f, 1f) : new Color(0.5f, 0.45f, 0.45f, 0.7f));
			}
			bool flag3 = count4 > 0 || !string.IsNullOrWhiteSpace(NativeSavesAccess.PageCurrentSaveFileName.Invoke(PageSaves));
			if ((Object)(object)duplicateChip != (Object)null)
			{
				duplicateChip.SetText(SaveManagerLocalization.BtnDuplicate(count4));
				duplicateChip.IsDisabled = !flag3;
				duplicateChip.SetTheme(new Color(0.08f, 0.22f, 0.34f, 0.94f), new Color(0.14f, 0.48f, 0.74f, 0.98f), new Color(0.3f, 0.66f, 0.92f, 0.88f), new Color(0.82f, 0.94f, 1f, 1f));
			}
			if ((Object)(object)newSlotChip != (Object)null)
			{
				newSlotChip.SetText(SaveManagerLocalization.BtnCreateNewSave());
				newSlotChip.SetTheme(new Color(0.08f, 0.24f, 0.16f, 0.94f), new Color(0.15f, 0.56f, 0.36f, 0.98f), new Color(0.28f, 0.78f, 0.52f, 0.88f), new Color(0.82f, 1f, 0.9f, 1f));
			}
			if ((Object)(object)moveCatChip != (Object)null)
			{
				moveCatChip.SetText(SaveManagerLocalization.BtnMoveCategory(count4));
				moveCatChip.IsDisabled = !flag3;
			}
			if ((Object)(object)renameSaveChip != (Object)null)
			{
				renameSaveChip.SetText(SaveManagerLocalization.BtnRenameSave());
				renameSaveChip.IsDisabled = GetSingleTargetSaveForRename() == null;
			}
			if ((Object)(object)pickerModal != (Object)null && ((Component)pickerModal).gameObject.activeSelf)
			{
				RefreshPickerVisuals();
			}
		}

		public void ToggleRowChecked(string saveFolderName, bool shiftHeld)
		{
			List<string> visibleSaveNames = visibleSummaries.Select((SaveSummary s) => s.FolderName).ToList();
			Selection.Toggle(saveFolderName, shiftHeld, visibleSaveNames);
			RefreshAllRowVisuals();
			RefreshToolbarVisuals();
		}

		public void ToggleRowPinned(string saveFolderName)
		{
			Catalog.TogglePin(saveFolderName);
			RebuildFilterSortAndLayout();
		}

		public bool MoveRowManual(string saveFolderName, int delta)
		{
			if (!Catalog.MoveSaveInVisibleOrder(visibleSummaries, allSummaries, saveFolderName, delta))
			{
				return false;
			}
			RebuildFilterSortAndLayout();
			return true;
		}

		public void RefreshSingleRow(string saveFolderName)
		{
			Es3SaveHelper.Invalidate(saveFolderName);
			if (allRowElements.TryGetValue(saveFolderName, out MenuElementSaveFile value) && (Object)(object)value != (Object)null)
			{
				(((Component)value).GetComponent<SaveRowView>() ?? AttachRowView(value)).RefreshVisuals();
			}
			RebuildFilterSortAndLayout();
		}

		private void RefreshAllRowVisuals()
		{
			foreach (KeyValuePair<string, MenuElementSaveFile> allRowElement in allRowElements)
			{
				if (!((Object)(object)allRowElement.Value == (Object)null))
				{
					((Component)allRowElement.Value).GetComponent<SaveRowView>()?.RefreshVisuals();
				}
			}
		}

		private void SelectFilter(CategoryFilterKind kind, string? categoryId)
		{
			CloseCategoryPicker();
			Catalog.SetFilter(kind, categoryId);
			NativeUiFactory.PlayConfirmSound();
			RebuildFilterSortAndLayout(preserveScroll: false);
		}

		private void PromptCreateCategory()
		{
			CloseCategoryPicker();
			NativeUiFactory.PlayConfirmSound();
			OpenTextInputPopup(SaveManagerLocalization.PopupNewCategoryHeader(), SaveManagerLocalization.PopupNewCategoryBody(), "", 28, allowEmpty: false, delegate(string text)
			{
				if (!string.IsNullOrWhiteSpace(text))
				{
					SaveCategory saveCategory = Catalog.CreateCategory(text);
					Catalog.SetFilter(CategoryFilterKind.Category, saveCategory.Id);
					JumpToCategoryPage(saveCategory.Id);
					RebuildFilterSortAndLayout(preserveScroll: false);
				}
			});
		}

		private void PromptRenameActiveCategory()
		{
			SaveCategory cat = Catalog.FindCategory(Catalog.Data.ActiveCategoryId);
			if (cat == null)
			{
				return;
			}
			NativeUiFactory.PlayConfirmSound();
			OpenTextInputPopup(SaveManagerLocalization.PopupRenameCategoryHeader(), SaveManagerLocalization.PopupNewCategoryBody(), cat.Name, 28, allowEmpty: false, delegate(string text)
			{
				if (Catalog.RenameCategory(cat.Id, text))
				{
					RebuildFilterSortAndLayout();
				}
			});
		}

		private void CycleActiveCategoryColor()
		{
			SaveCategory saveCategory = Catalog.FindCategory(Catalog.Data.ActiveCategoryId);
			if (saveCategory != null)
			{
				Catalog.CycleCategoryColor(saveCategory.Id);
				NativeUiFactory.PlayTickSound();
				RefreshAllRowVisuals();
				RefreshToolbarVisuals();
			}
		}

		private void PromptDeleteActiveCategory()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			SaveCategory cat = Catalog.FindCategory(Catalog.Data.ActiveCategoryId);
			if (cat != null)
			{
				NativeUiFactory.PlayConfirmSound();
				OpenTwoOptionsConfirm(SaveManagerLocalization.PopupDeleteCategoryHeader(), new Color(1f, 0.4f, 0.35f), SaveManagerLocalization.PopupDeleteCategoryBody(cat.Name), SaveManagerLocalization.PopupYesDelete(), SaveManagerLocalization.PopupCancel(), (UnityAction)delegate
				{
					Catalog.DeleteCategory(cat.Id);
					NativeUiFactory.PlayConfirmSound();
					RebuildFilterSortAndLayout(preserveScroll: false);
				});
			}
		}

		private void JumpToCategoryPage(string categoryId)
		{
			IReadOnlyList<SaveCategory> categories = Catalog.GetCategories();
			for (int i = 0; i < categories.Count; i++)
			{
				if (string.Equals(categories[i].Id, categoryId, StringComparison.OrdinalIgnoreCase))
				{
					categoryTabPage = i / 3;
					break;
				}
			}
		}

		private void OnCycleSortClicked()
		{
			Catalog.CycleSortMode((visibleSummaries.Count > 0) ? visibleSummaries : allSummaries);
			NativeUiFactory.PlayConfirmSound();
			RebuildFilterSortAndLayout(preserveScroll: false);
		}

		private void OnSearchClicked()
		{
			if (!string.IsNullOrWhiteSpace(searchQuery))
			{
				searchQuery = "";
				NativeUiFactory.PlayTickSound();
				RebuildFilterSortAndLayout(preserveScroll: false);
				return;
			}
			NativeUiFactory.PlayConfirmSound();
			OpenTextInputPopup(SaveManagerLocalization.PopupSearchHeader(), SaveManagerLocalization.PopupSearchBody(), searchQuery, 36, allowEmpty: true, delegate(string text)
			{
				searchQuery = (text ?? "").Trim();
				RebuildFilterSortAndLayout(preserveScroll: false);
			});
		}

		private void OnSelectAllClicked()
		{
			List<string> list = visibleSummaries.Select((SaveSummary s) => s.FolderName).ToList();
			if (list.Count != 0)
			{
				if (Selection.AreAllVisibleChecked(list))
				{
					Selection.UncheckVisible(list);
				}
				else
				{
					Selection.SelectAllVisible(list);
				}
				NativeUiFactory.PlayTickSound();
				RefreshAllRowVisuals();
				RefreshToolbarVisuals();
			}
		}

		private void OnBulkDeleteClicked()
		{
			//IL_0184: 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_01b6: Expected O, but got Unknown
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			if (Selection.Count == 0)
			{
				NativeUiFactory.PlayDenySound();
				return;
			}
			bool flag = Plugin.ProtectPinnedFromBulkDelete == null || Plugin.ProtectPinnedFromBulkDelete.Value;
			List<string> list = Selection.CheckedSaves.Where((string s) => allRowElements.ContainsKey(s)).ToList();
			int skippedCount = (flag ? list.Count((string s) => Catalog.IsPinned(s)) : 0);
			List<string> toDelete = (flag ? list.Where((string s) => !Catalog.IsPinned(s)).ToList() : list);
			if (toDelete.Count == 0)
			{
				NativeUiFactory.PlayDenySound();
				MenuManager instance = MenuManager.instance;
				if (instance != null)
				{
					instance.PageCloseAllAddedOnTop();
				}
				MenuManager instance2 = MenuManager.instance;
				if (instance2 != null)
				{
					instance2.PagePopUp(SaveManagerLocalization.PopupAllPinnedProtectedHeader(), new Color(1f, 0.8f, 0.2f), SaveManagerLocalization.PopupAllPinnedProtectedBody(), "OK", true);
				}
			}
			else
			{
				List<string> list2 = (from f in toDelete.Take(4)
					select "• " + (Es3SaveHelper.ReadSummary(f).TeamName ?? f)).ToList();
				if (toDelete.Count > 4)
				{
					list2.Add($"... (+{toDelete.Count - 4})");
				}
				string previewNames = string.Join("\n", list2) + SaveManagerLocalization.SkippedPinnedNote(skippedCount);
				NativeUiFactory.PlayConfirmSound();
				OpenTwoOptionsConfirm(SaveManagerLocalization.PopupBulkDeleteHeader(), new Color(1f, 0.25f, 0.25f), SaveManagerLocalization.PopupBulkDeleteBody(toDelete.Count, previewNames), SaveManagerLocalization.PopupYesDelete(), SaveManagerLocalization.PopupCancel(), (UnityAction)delegate
				{
					ExecuteBulkDelete(toDelete);
				});
			}
		}

		public void ExecuteBulkDelete(IReadOnlyCollection<string> saveNamesToDelete)
		{
			List<MenuElementSaveFile> list = NativeSavesAccess.PageSaveFiles.Invoke(PageSaves);
			foreach (string item in saveNamesToDelete)
			{
				if (SaveFolderOperations.IsSafeSaveFolderName(item))
				{
					SemiFunc.SaveFileDelete(item);
					Es3SaveHelper.Invalidate(item);
					Selection.Remove(item);
					if (allRowElements.TryGetValue(item, out MenuElementSaveFile value) && (Object)(object)value != (Object)null)
					{
						list.Remove(value);
						Object.Destroy((Object)(object)((Component)value).gameObject);
					}
					allRowElements.Remove(item);
					if (string.Equals(NativeSavesAccess.PageCurrentSaveFileName.Invoke(PageSaves), item, StringComparison.OrdinalIgnoreCase))
					{
						NativeSavesAccess.PageCurrentSaveFileName.Invoke(PageSaves) = "";
						PageSaves.GoBackToDefaultInfo();
					}
				}
			}
			Catalog.RemoveSaveMetadata(saveNamesToDelete);
			NativeUiFactory.PlayConfirmSound();
			RebuildFilterSortAndLayout();
		}

		private List<string> GetTargetSavesForAction()
		{
			if (Selection.Count > 0)
			{
				return Selection.CheckedSaves.Where((string s) => allRowElements.ContainsKey(s)).ToList();
			}
			string text = NativeSavesAccess.PageCurrentSaveFileName.Invoke(PageSaves);
			if (!string.IsNullOrWhiteSpace(text) && allRowElements.ContainsKey(text))
			{
				return new List<string> { text };
			}
			return new List<string>();
		}

		private void OnDuplicateClicked()
		{
			List<string> targetSavesForAction = GetTargetSavesForAction();
			if (targetSavesForAction.Count == 0)
			{
				NativeUiFactory.PlayDenySound();
				return;
			}
			string text = null;
			foreach (string item in targetSavesForAction)
			{
				string text2 = Es3SaveHelper.DuplicateSaveWithEs3Rename(item);
				if (!string.IsNullOrEmpty(text2))
				{
					Catalog.CopySaveMetadata(item, text2);
					List<string> backups = Es3SaveHelper.GetBackups(text2);
					InstantiateSaveRowElement(text2, backups);
					text = text2;
				}
			}
			if (text != null)
			{
				NativeUiFactory.PlayConfirmSound();
				RebuildFilterSortAndLayout();
				if (allRowElements.TryGetValue(text, out MenuElementSaveFile value) && (Object)(object)value != (Object)null && ((Component)value).gameObject.activeSelf)
				{
					PageSaves.SaveFileSelected(text, NativeSavesAccess.ElemSaveFileBackups.Invoke(value));
				}
			}
		}

		private void PromptCreateBlankSave()
		{
			CloseCategoryPicker();
			NativeUiFactory.PlayConfirmSound();
			OpenTextInputPopup(SaveManagerLocalization.PopupNewSaveHeader(), SaveManagerLocalization.PopupNewSaveBody(), "R.E.P.O.", 60, allowEmpty: false, delegate(string teamName)
			{
				string text = Es3SaveHelper.CreateBlankSaveSlot(teamName);
				if (!string.IsNullOrEmpty(text))
				{
					if (Catalog.Data.ActiveFilterKind == CategoryFilterKind.Category && !string.IsNullOrEmpty(Catalog.Data.ActiveCategoryId))
					{
						Catalog.AssignCategory(new string[1] { text }, Catalog.Data.ActiveCategoryId);
					}
					MenuElementSaveFile val = InstantiateSaveRowElement(text, new List<string>());
					RebuildFilterSortAndLayout(preserveScroll: false);
					if ((Object)(object)val != (Object)null && ((Component)val).gameObject.activeSelf)
					{
						PageSaves.SaveFileSelected(text, NativeSavesAccess.ElemSaveFileBackups.Invoke(val));
					}
				}
			});
		}

		private string? GetSingleTargetSaveForRename()
		{
			if (Selection.Count == 1)
			{
				string text = Selection.CheckedSaves.First();
				if (!allRowElements.ContainsKey(text))
				{
					return null;
				}
				return text;
			}
			if (Selection.Count == 0)
			{
				string text2 = NativeSavesAccess.PageCurrentSaveFileName.Invoke(PageSaves);
				if (!string.IsNullOrWhiteSpace(text2) && allRowElements.ContainsKey(text2))
				{
					return text2;
				}
			}
			return null;
		}

		private void OnRenameSaveClicked()
		{
			CloseCategoryPicker();
			if ((Object)(object)sortModal != (Object)null)
			{
				((Component)sortModal).gameObject.SetActive(false);
			}
			string target = GetSingleTargetSaveForRename();
			if (string.IsNullOrEmpty(target))
			{
				NativeUiFactory.PlayDenySound();
				return;
			}
			string teamName = Es3SaveHelper.ReadSummary(target).TeamName;
			NativeUiFactory.PlayConfirmSound();
			OpenTextInputPopup(SaveManagerLocalization.PopupRenameSaveHeader(), SaveManagerLocalization.PopupRenameSaveBody(), teamName, 60, allowEmpty: false, delegate(string newText)
			{
				if (Es3SaveHelper.RenameSaveTeam(target, newText))
				{
					if (allRowElements.TryGetValue(target, out MenuElementSaveFile value) && (Object)(object)value != (Object)null)
					{
						PageSaves.UpdateSaveDetails(value, target);
						RebuildFilterSortAndLayout();
						if (string.Equals(NativeSavesAccess.PageCurrentSaveFileName.Invoke(PageSaves), target, StringComparison.OrdinalIgnoreCase) && ((Component)value).gameObject.activeSelf)
						{
							PageSaves.SaveFileSelected(target, NativeSavesAccess.ElemSaveFileBackups.Invoke(value));
						}
					}
					else
					{
						RebuildFilterSortAndLayout();
					}
				}
			});
		}

		public void NotifyVanillaDeletedSingle(string deletedFolder)
		{
			if (!string.IsNullOrWhiteSpace(deletedFolder))
			{
				Es3SaveHelper.Invalidate(deletedFolder);
				Selection.Remove(deletedFolder);
				allRowElements.Remove(deletedFolder);
				Catalog.RemoveSaveMetadata(new string[1] { deletedFolder });
				RebuildFilterSortAndLayout();
			}
		}

		private void BuildSortPickerModal(Transform parent, Vector2 center)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			sortModal = NativeUiFactory.CreatePanel(parent, "SaveOrganizer_SortPicker", center, new Vector2(288f, 174f), new Color(0.04f, 0.06f, 0.1f, 0.98f), new Color(0.28f, 0.78f, 0.98f, 0.98f), skipScroll: false, bottomLeftAnchor: true);
			((Transform)sortModal).SetAsLastSibling();
			RectTransform component = new GameObject("SortTitle", new Type[1] { typeof(RectTransform) })
			{
				layer = ((Component)sortModal).gameObject.layer
			}.GetComponent<RectTransform>();
			((Transform)component).SetParent((Transform)(object)sortModal, false);
			component.anchoredPosition = new Vector2(0f, 70f);
			component.sizeDelta = new Vector2(260f, 18f);
			sortTitleLabel = NativeUiFactory.CreateLabel((Transform)(object)component, "Label", uiFont, "", 9.5f, new Color(0.45f, 0.9f, 1f, 1f), (TextAlignmentOptions)514);
			SaveSortMode[] array = (SaveSortMode[])Enum.GetValues(typeof(SaveSortMode));
			for (int i = 0; i < array.Length && i < 9; i++)
			{
				SaveSortMode mode = array[i];
				int num = i % 2;
				int num2 = i / 2;
				float num3 = ((i == 8) ? 0f : ((num == 0) ? (-66f) : 66f));
				float num4 = ((i == 8) ? 256f : 124f);
				float num5 = 46f - (float)num2 * 21f;
				sortModeChips[i] = NativeUiFactory.CreateChip((Transform)(object)sortModal, $"SortOpt_{mode}", uiFont, "", new Vector2(num3, num5), new Vector2(num4, 17f), 8.2f, delegate
				{
					Catalog.SetSortMode(mode, (visibleSummaries.Count > 0) ? visibleSummaries : allSummaries);
					((Component)sortModal).gameObject.SetActive(false);
					NativeUiFactory.PlayConfirmSound();
					RebuildFilterSortAndLayout(preserveScroll: false);
				});
			}
			sortCloseChip = NativeUiFactory.CreateChip((Transform)(object)sortModal, "SortClose", uiFont, "CLOSE", new Vector2(0f, -66f), new Vector2(110f, 16f), 8.4f, delegate
			{
				((Component)sortModal).gameObject.SetActive(false);
				NativeUiFactory.PlayTickSound();
			});
			((Component)sortModal).gameObject.SetActive(false);
		}

		private void BuildCategoryPickerModal(Transform parent, Vector2 center)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: 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_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			pickerModal = NativeUiFactory.CreatePanel(parent, "SaveOrganizer_CategoryPicker", center, new Vector2(288f, 162f), new Color(0.04f, 0.06f, 0.1f, 0.98f), new Color(0.95f, 0.62f, 0.15f, 0.98f), skipScroll: false, bottomLeftAnchor: true);
			((Transform)pickerModal).SetAsLastSibling();
			RectTransform component = new GameObject("PickerTitle", new Type[1] { typeof(RectTransform) })
			{
				layer = ((Component)pickerModal).gameObject.layer
			}.GetComponent<RectTransform>();
			((Transform)component).SetParent((Transform)(object)pickerModal, false);
			component.anchoredPosition = new Vector2(0f, 64f);
			component.sizeDelta = new Vector2(260f, 18f);
			pickerTitleLabel = NativeUiFactory.CreateLabel((Transform)(object)component, "Label", uiFont, "", 9.5f, new Color(1f, 0.78f, 0.28f, 1f), (TextAlignmentOptions)514);
			pickerUncatChip = NativeUiFactory.CreateChip((Transform)(object)pickerModal, "PickUncat", uiFont, "", new Vector2(-65f, 44f), new Vector2(124f, 16f), 8.2f, delegate
			{
				ApplyCategoryPickerSelection(null);
			});
			pickerCreateNewChip = NativeUiFactory.CreateChip((Transform)(object)pickerModal, "PickCreate", uiFont, "", new Vector2(65f, 44f), new Vector2(124f, 16f), 8.2f, PromptCreateCategoryAndAssignPending);
			for (int num = 0; num < 6; num++)
			{
				int idx = num;
				int num2 = num % 2;
				int num3 = num / 2;
				float num4 = ((num2 == 0) ? (-65f) : 65f);
				float num5 = 20f - (float)num3 * 21f;
				pickerCatChips[num] = NativeUiFactory.CreateChip((Transform)(object)pickerModal, $"PickCat_{num}", uiFont, "", new Vector2(num4, num5), new Vector2(124f, 17f), 8.2f, delegate
				{
					string text = pickerCatIds[idx];
					if (!string.IsNullOrEmpty(text))
					{
						ApplyCategoryPickerSelection(text);
					}
				});
			}
			pickerPrevChip = NativeUiFactory.CreateChip((Transform)(object)pickerModal, "PickPrev", uiFont, "◀", new Vector2(-100f, -58f), new Vector2(36f, 16f), 8.2f, delegate
			{
				pickerPage = Mathf.Max(0, pickerPage - 1);
				NativeUiFactory.PlayTickSound();
				RefreshPickerVisuals();
			});
			pickerCloseChip = NativeUiFactory.CreateChip((Transform)(object)pickerModal, "PickClose", uiFont, "CLOSE", new Vector2(0f, -58f), new Vector2(110f, 16f), 8.4f, delegate
			{
				CloseCategoryPicker();
				NativeUiFactory.PlayTickSound();
			});
			pickerNextChip = NativeUiFactory.CreateChip((Transform)(object)pickerModal, "PickNext", uiFont, "▶", new Vector2(100f, -58f), new Vector2(36f, 16f), 8.2f, delegate
			{
				pickerPage++;
				NativeUiFactory.PlayTickSound();
				RefreshPickerVisuals();
			});
			((Component)pickerModal).gameObject.SetActive(false);
		}

		private void OnOpenSortPickerClicked()
		{
			CloseCategoryPicker();
			if (!((Object)(object)sortModal == (Object)null))
			{
				bool flag = !((Component)sortModal).gameObject.activeSelf;
				((Transform)sortModal).SetAsLastSibling();
				((Component)sortModal).gameObject.SetActive(flag);
				if (flag)
				{
					RefreshSortPickerVisuals();
				}
				NativeUiFactory.PlayConfirmSound();
			}
		}

		private void RefreshSortPickerVisuals()
		{
			if ((Object)(object)sortModal == (Object)null)
			{
				return;
			}
			if ((Object)(object)sortTitleLabel != (Object)null)
			{
				((TMP_Text)sortTitleLabel).text = SaveManagerLocalization.SortPickerTitle();
			}
			if ((Object)(object)sortCloseChip != (Object)null)
			{
				sortCloseChip.SetText(SaveManagerLocalization.PickerClose());
			}