using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Peak;
using Photon.Pun;
using Photon.Realtime;
using Portningsbolaget;
using Portningsbolaget.Platforms;
using Portningsbolaget.Utilities;
using Steamworks;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using Zorro.UI.Modal;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SaveSlots")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+05dd776dd37c023e3699c3e457b281be47adf3ed")]
[assembly: AssemblyProduct("SaveSlots")]
[assembly: AssemblyTitle("SaveSlots")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SaveSlots;
[BepInPlugin("t0y9n.peak.saveslots", "SaveSlots", "1.0.0")]
public sealed class Plugin : BaseUnityPlugin
{
internal const string Guid = "t0y9n.peak.saveslots";
internal static ManualLogSource Log;
private void Awake()
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
if (!((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Save each run in its own slot. Read once at start; restart the game after changing it.").Value)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"SaveSlots 1.0.0 loaded. Enabled = false; nothing is patched.");
return;
}
new Harmony("t0y9n.peak.saveslots").PatchAll(typeof(Plugin).Assembly);
((BaseUnityPlugin)this).Logger.LogInfo((object)"SaveSlots 1.0.0 loaded.");
}
}
internal sealed class SlotListUI : MonoBehaviour
{
private static SlotListUI current;
private Button boardTemplate;
private Canvas overlayCanvas;
private Canvas raisedModalCanvas;
private int modalCanvasSortingLayerId;
private int modalCanvasSortingOrder;
private bool modalCanvasOverrideSorting;
private RectTransform content;
private RectTransform root;
internal static void Open()
{
//IL_007f: 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_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: 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)
if ((Object)(object)current != (Object)null)
{
current.Refresh();
return;
}
MainMenuMainPage val = Object.FindFirstObjectByType<MainMenuMainPage>();
Button val2 = (((Object)(object)val == (Object)null) ? null : Traverse.Create((object)val).Field("m_continueButton").GetValue<Button>());
if ((Object)(object)val2 == (Object)null)
{
Plugin.Log.LogWarning((object)"SaveSlots: the game's Continue sign could not be found.");
return;
}
GameObject val3 = new GameObject("SaveSlotsListCanvas", new Type[2]
{
typeof(RectTransform),
typeof(Canvas)
});
Canvas component = val3.GetComponent<Canvas>();
component.renderMode = (RenderMode)0;
component.sortingOrder = 1000;
CanvasScaler obj = val3.AddComponent<CanvasScaler>();
obj.uiScaleMode = (ScaleMode)1;
obj.referenceResolution = new Vector2(1920f, 1080f);
obj.matchWidthOrHeight = 0.5f;
val3.AddComponent<GraphicRaycaster>();
current = val3.AddComponent<SlotListUI>();
current.overlayCanvas = component;
current.boardTemplate = val2;
current.Build();
current.Refresh();
}
private void Build()
{
//IL_0017: 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_0037: 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_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0153: 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_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
//IL_0202: Unknown result type (might be due to invalid IL or missing references)
//IL_0217: Unknown result type (might be due to invalid IL or missing references)
//IL_022c: 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_0257: Unknown result type (might be due to invalid IL or missing references)
//IL_0261: Expected O, but got Unknown
//IL_0287: Unknown result type (might be due to invalid IL or missing references)
//IL_029c: 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_02b2: Unknown result type (might be due to invalid IL or missing references)
//IL_02db: Unknown result type (might be due to invalid IL or missing references)
//IL_0303: Unknown result type (might be due to invalid IL or missing references)
//IL_030e: Unknown result type (might be due to invalid IL or missing references)
//IL_0319: Unknown result type (might be due to invalid IL or missing references)
//IL_0324: Unknown result type (might be due to invalid IL or missing references)
//IL_036f: Unknown result type (might be due to invalid IL or missing references)
//IL_0389: Unknown result type (might be due to invalid IL or missing references)
//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
//IL_03fb: Expected O, but got Unknown
ref RectTransform reference = ref root;
Transform transform = ((Component)this).transform;
reference = (RectTransform)(object)((transform is RectTransform) ? transform : null);
root.anchorMin = Vector2.zero;
root.anchorMax = Vector2.one;
root.offsetMin = Vector2.zero;
root.offsetMax = Vector2.zero;
((Graphic)((Component)this).gameObject.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.35f);
RectTransform val = CreateRect("SavedRunsPanel", (Transform)(object)root);
val.anchorMin = new Vector2(0.5f, 0.5f);
val.anchorMax = new Vector2(0.5f, 0.5f);
val.pivot = new Vector2(0.5f, 0.5f);
val.anchoredPosition = Vector2.zero;
val.sizeDelta = new Vector2(1320f, 870f);
((Transform)val).localRotation = Quaternion.identity;
((Transform)val).localScale = Vector3.one;
((Graphic)((Component)val).gameObject.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.6f);
TMP_Text componentInChildren = ((Component)boardTemplate).GetComponentInChildren<TMP_Text>(true);
TMP_Text obj = CreateText("SavedRunsTitle", (Transform)(object)val, componentInChildren);
RectTransform rectTransform = obj.rectTransform;
rectTransform.anchorMin = new Vector2(0.05f, 0.88f);
rectTransform.anchorMax = new Vector2(0.75f, 0.98f);
rectTransform.offsetMin = Vector2.zero;
rectTransform.offsetMax = Vector2.zero;
obj.text = "SAVED RUNS";
obj.fontSize = 48f;
obj.alignment = (TextAlignmentOptions)4097;
obj.enableAutoSizing = true;
obj.fontSizeMin = 32f;
obj.fontSizeMax = 48f;
obj.overflowMode = (TextOverflowModes)1;
Button obj2 = CloneBoardButton("Close", (Transform)(object)val);
Transform transform2 = ((Component)obj2).transform;
Transform obj3 = ((transform2 is RectTransform) ? transform2 : null);
((RectTransform)obj3).anchorMin = new Vector2(1f, 1f);
((RectTransform)obj3).anchorMax = new Vector2(1f, 1f);
((RectTransform)obj3).pivot = new Vector2(1f, 1f);
((RectTransform)obj3).anchoredPosition = new Vector2(-24f, -20f);
((RectTransform)obj3).sizeDelta = new Vector2(170f, 72f);
((UnityEvent)obj2.onClick).AddListener(new UnityAction(Close));
((Component)obj2).GetComponent<LayoutElement>().preferredWidth = 170f;
RectTransform val2 = CreateRect("Viewport", (Transform)(object)val);
val2.anchorMin = new Vector2(0.04f, 0.045f);
val2.anchorMax = new Vector2(0.96f, 0.86f);
val2.offsetMin = Vector2.zero;
val2.offsetMax = Vector2.zero;
((Graphic)((Component)val2).gameObject.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.12f);
((Component)val2).gameObject.AddComponent<Mask>().showMaskGraphic = false;
RectTransform val3 = CreateRect("Scroll", (Transform)(object)val2);
val3.anchorMin = Vector2.zero;
val3.anchorMax = Vector2.one;
val3.offsetMin = Vector2.zero;
val3.offsetMax = Vector2.zero;
ScrollRect obj4 = ((Component)val3).gameObject.AddComponent<ScrollRect>();
obj4.viewport = val2;
obj4.horizontal = false;
obj4.vertical = true;
content = CreateRect("Content", (Transform)(object)val3);
content.anchorMin = new Vector2(0f, 1f);
content.anchorMax = new Vector2(1f, 1f);
content.pivot = new Vector2(0.5f, 1f);
content.anchoredPosition = Vector2.zero;
content.sizeDelta = Vector2.zero;
VerticalLayoutGroup obj5 = ((Component)content).gameObject.AddComponent<VerticalLayoutGroup>();
((HorizontalOrVerticalLayoutGroup)obj5).spacing = 14f;
((LayoutGroup)obj5).padding = new RectOffset(12, 12, 12, 12);
((HorizontalOrVerticalLayoutGroup)obj5).childControlHeight = true;
((HorizontalOrVerticalLayoutGroup)obj5).childControlWidth = true;
((HorizontalOrVerticalLayoutGroup)obj5).childForceExpandHeight = false;
((HorizontalOrVerticalLayoutGroup)obj5).childForceExpandWidth = true;
((Component)content).gameObject.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
obj4.content = content;
}
private void Refresh(bool includeCurrentQuickSave = true)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
foreach (Transform item in (Transform)content)
{
Object.Destroy((Object)(object)((Component)item).gameObject);
}
List<SlotInfo> list = SlotStore.List(includeCurrentQuickSave);
if (list.Count == 0)
{
Button obj = CloneBoardButton("No saved runs were found.", (Transform)(object)content);
((Selectable)obj).interactable = false;
LayoutElement component = ((Component)obj).GetComponent<LayoutElement>();
component.minHeight = 110f;
component.preferredHeight = 110f;
return;
}
foreach (SlotInfo item2 in list)
{
CreateRow(item2);
}
}
private void CreateRow(SlotInfo slot)
{
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Expected O, but got Unknown
//IL_021f: Unknown result type (might be due to invalid IL or missing references)
//IL_0229: Expected O, but got Unknown
//IL_0272: Unknown result type (might be due to invalid IL or missing references)
//IL_027c: Expected O, but got Unknown
//IL_0207: Unknown result type (might be due to invalid IL or missing references)
RectTransform val = CreateRect("SavedRun", (Transform)(object)content);
LayoutElement obj = ((Component)val).gameObject.AddComponent<LayoutElement>();
obj.minHeight = 110f;
obj.preferredHeight = 110f;
HorizontalLayoutGroup obj2 = ((Component)val).gameObject.AddComponent<HorizontalLayoutGroup>();
((HorizontalOrVerticalLayoutGroup)obj2).spacing = 48f;
((LayoutGroup)obj2).padding = new RectOffset(0, 0, 0, 0);
((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true;
((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true;
((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false;
((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = false;
string text = FormatNames(slot);
if (!slot.usable)
{
text += " · OLD VERSION";
}
TimeSpan timeSpan = TimeSpan.FromSeconds(Math.Max(0f, slot.runTimer));
string text2 = ((int)timeSpan.TotalHours).ToString("00") + ":" + timeSpan.Minutes.ToString("00");
string details = slot.biome + " · Ascent " + slot.ascent + " · Day " + slot.day + " · " + text2 + " · " + slot.lobby + " · " + slot.savedAt.ToLocalTime().ToString("g");
Button val2 = CloneBoardButton(text, (Transform)(object)val);
LayoutElement component = ((Component)val2).GetComponent<LayoutElement>();
component.flexibleWidth = 1f;
component.minHeight = 110f;
component.preferredHeight = 110f;
AddDetailsText(val2, details);
((Selectable)val2).interactable = slot.usable;
if (!slot.usable)
{
SetBoardTextColor(val2, new Color(0.65f, 0.65f, 0.65f));
}
((UnityEvent)val2.onClick).AddListener((UnityAction)delegate
{
Continue(slot);
});
Button obj3 = CloneBoardButton("Delete", (Transform)(object)val);
LayoutElement component2 = ((Component)obj3).GetComponent<LayoutElement>();
component2.preferredWidth = 165f;
component2.minWidth = 165f;
component2.minHeight = 110f;
component2.preferredHeight = 110f;
((UnityEvent)obj3.onClick).AddListener((UnityAction)delegate
{
ConfirmDelete(slot);
});
}
private static string FormatNames(SlotInfo slot)
{
if (slot.names == null || slot.names.Length == 0)
{
return slot.count + ((slot.count == 1) ? " player" : " players");
}
string text = string.Join(", ", slot.names);
int num = Math.Max(0, slot.count - slot.names.Length);
if (num != 0)
{
return text + " +" + num;
}
return text;
}
private Button CloneBoardButton(string label, Transform parent)
{
//IL_002a: 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_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_0188: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_019d: Unknown result type (might be due to invalid IL or missing references)
Button val = Object.Instantiate<Button>(boardTemplate, parent, false);
((Object)((Component)val).gameObject).name = "SaveSlotsBoardButton";
Transform transform = ((Component)val).transform;
Transform obj = ((transform is RectTransform) ? transform : null);
obj.localRotation = Quaternion.identity;
obj.localScale = Vector3.one;
((RectTransform)obj).anchorMin = Vector2.zero;
((RectTransform)obj).anchorMax = Vector2.one;
((RectTransform)obj).pivot = new Vector2(0.5f, 0.5f);
((RectTransform)obj).offsetMin = Vector2.zero;
((RectTransform)obj).offsetMax = Vector2.zero;
((RectTransform)obj).sizeDelta = Vector2.zero;
((UnityEventBase)val.onClick).RemoveAllListeners();
((Selectable)val).interactable = true;
LocalizeText[] componentsInChildren = ((Component)val).GetComponentsInChildren<LocalizeText>(true);
foreach (LocalizeText obj2 in componentsInChildren)
{
((Behaviour)obj2).enabled = false;
Object.Destroy((Object)(object)obj2);
}
if ((Object)(object)((Component)val).GetComponent<LayoutElement>() == (Object)null)
{
((Component)val).gameObject.AddComponent<LayoutElement>();
}
TMP_Text[] componentsInChildren2 = ((Component)val).GetComponentsInChildren<TMP_Text>(true);
if (componentsInChildren2.Length == 0)
{
Plugin.Log.LogWarning((object)"SaveSlots: the game's Continue sign has no text component.");
return val;
}
componentsInChildren2[0].text = label;
bool num = label == "Delete";
bool flag = label == "Close";
bool flag2 = num || flag;
RectTransform rectTransform = componentsInChildren2[0].rectTransform;
rectTransform.anchorMin = new Vector2(flag2 ? 0.12f : 0.055f, flag2 ? 0.12f : 0.48f);
rectTransform.anchorMax = new Vector2(flag2 ? 0.88f : 0.945f, flag2 ? 0.88f : 0.94f);
rectTransform.pivot = new Vector2(0.5f, 0.5f);
rectTransform.offsetMin = Vector2.zero;
rectTransform.offsetMax = Vector2.zero;
if (flag2)
{
componentsInChildren2[0].alignment = (TextAlignmentOptions)514;
}
if (flag2)
{
HideSecondaryImages(val);
}
componentsInChildren2[0].enableAutoSizing = true;
componentsInChildren2[0].fontSizeMin = 22f;
componentsInChildren2[0].fontSizeMax = 38f;
componentsInChildren2[0].textWrappingMode = (TextWrappingModes)0;
componentsInChildren2[0].overflowMode = (TextOverflowModes)1;
for (int j = 1; j < componentsInChildren2.Length; j++)
{
componentsInChildren2[j].text = string.Empty;
}
return val;
}
private static void HideSecondaryImages(Button button)
{
Graphic targetGraphic = ((Selectable)button).targetGraphic;
if ((Object)(object)targetGraphic == (Object)null)
{
return;
}
Image[] componentsInChildren = ((Component)button).GetComponentsInChildren<Image>(true);
foreach (Image val in componentsInChildren)
{
if ((Object)(object)val != (Object)(object)targetGraphic)
{
((Behaviour)val).enabled = false;
}
}
}
private static TMP_Text CreateText(string name, Transform parent, TMP_Text template)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
GameObject obj = Object.Instantiate<GameObject>(((Component)template).gameObject, parent, false);
((Object)obj).name = name;
TMP_Text component = obj.GetComponent<TMP_Text>();
RectTransform rectTransform = component.rectTransform;
((Transform)rectTransform).localRotation = Quaternion.identity;
((Transform)rectTransform).localScale = Vector3.one;
return component;
}
private static void AddDetailsText(Button button, string details)
{
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
TMP_Text componentInChildren = ((Component)button).GetComponentInChildren<TMP_Text>(true);
if (!((Object)(object)componentInChildren == (Object)null))
{
GameObject obj = Object.Instantiate<GameObject>(((Component)componentInChildren).gameObject, componentInChildren.transform.parent, false);
((Object)obj).name = "SavedRunDetails";
TMP_Text component = obj.GetComponent<TMP_Text>();
component.text = details;
component.alignment = (TextAlignmentOptions)4097;
component.enableAutoSizing = true;
component.fontSizeMin = 14f;
component.fontSizeMax = 26f;
component.textWrappingMode = (TextWrappingModes)0;
component.overflowMode = (TextOverflowModes)1;
RectTransform rectTransform = component.rectTransform;
rectTransform.anchorMin = new Vector2(0.035f, 0.08f);
rectTransform.anchorMax = new Vector2(0.965f, 0.48f);
rectTransform.pivot = new Vector2(0.5f, 0.5f);
rectTransform.offsetMin = Vector2.zero;
rectTransform.offsetMax = Vector2.zero;
}
}
private static void SetBoardTextColor(Button button, Color color)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
TMP_Text[] componentsInChildren = ((Component)button).GetComponentsInChildren<TMP_Text>(true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
((Graphic)componentsInChildren[i]).color = color;
}
}
private void Continue(SlotInfo slot)
{
if (!SlotStore.CopySlotToQuickSave(slot.runId))
{
return;
}
Quicksave.TryLoadSave((Action<bool>)delegate(bool success)
{
if (!success)
{
Plugin.Log.LogWarning((object)("SaveSlots: the selected run could not be loaded: " + slot.runId));
}
else
{
Close();
MainMenuMainPage val = Object.FindFirstObjectByType<MainMenuMainPage>();
if ((Object)(object)val != (Object)null)
{
Traverse.Create((object)val).Method("ContinueFromQuicksaveClicked", Array.Empty<object>()).GetValue();
}
}
});
}
private void ConfirmDelete(SlotInfo slot)
{
//IL_001e: 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_0037: Expected O, but got Unknown
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Expected O, but got Unknown
//IL_0066: Expected O, but got Unknown
Modal.OpenModal((HeaderModalOption)new DefaultHeaderModalOption("Delete saved run?", "This saved run will be deleted."), (ModalContentOption)new ModalButtonsOption((Option[])(object)new Option[2]
{
new Option("Cancel", (Action)null),
new Option("Delete", (Action)delegate
{
Delete(slot);
})
}), (Action)RestoreModalCanvasOrder);
RaiseModalCanvas();
}
private void RaiseModalCanvas()
{
Modal val = Object.FindFirstObjectByType<Modal>();
Canvas val2 = (((Object)(object)val == (Object)null) ? null : ((Component)val).GetComponent<Canvas>());
if ((Object)(object)val2 == (Object)null && (Object)(object)val != (Object)null)
{
val2 = ((Component)val).GetComponentInChildren<Canvas>(true);
}
if ((Object)(object)val2 == (Object)null && (Object)(object)val != (Object)null)
{
val2 = ((Component)val).GetComponentInParent<Canvas>();
}
if ((Object)(object)val2 == (Object)null || (Object)(object)val2 == (Object)(object)overlayCanvas)
{
Plugin.Log.LogWarning((object)"SaveSlots: the delete modal canvas could not be raised above the saved runs list.");
return;
}
if ((Object)(object)raisedModalCanvas != (Object)null)
{
RestoreModalCanvasOrder();
}
raisedModalCanvas = val2;
modalCanvasSortingLayerId = val2.sortingLayerID;
modalCanvasSortingOrder = val2.sortingOrder;
modalCanvasOverrideSorting = val2.overrideSorting;
val2.overrideSorting = true;
val2.sortingLayerID = overlayCanvas.sortingLayerID;
val2.sortingOrder = overlayCanvas.sortingOrder + 1;
}
private void RestoreModalCanvasOrder()
{
if (!((Object)(object)raisedModalCanvas == (Object)null))
{
raisedModalCanvas.sortingLayerID = modalCanvasSortingLayerId;
raisedModalCanvas.sortingOrder = modalCanvasSortingOrder;
raisedModalCanvas.overrideSorting = modalCanvasOverrideSorting;
raisedModalCanvas = null;
}
}
private void Delete(SlotInfo slot)
{
try
{
SlotStore.Delete(slot.runId);
Refresh(includeCurrentQuickSave: false);
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("SaveSlots: the selected run could not be deleted. " + ex.Message));
}
}
private void Close()
{
current = null;
Object.Destroy((Object)(object)((Component)this).gameObject);
}
private static RectTransform CreateRect(string name, Transform parent)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
val.transform.SetParent(parent, false);
return val.GetComponent<RectTransform>();
}
}
[HarmonyPatch(typeof(Quicksave), "SaveNow")]
internal static class SaveNowPatch
{
private static void Postfix()
{
SlotStore.SaveCurrentQuickSave();
}
}
[HarmonyPatch(typeof(MainMenuMainPage), "SetUpContinueButton")]
internal static class ContinueButtonPatch
{
private static readonly UnityAction OpenSlotsAction = new UnityAction(OpenSlots);
private static bool Prefix(MainMenuMainPage __instance)
{
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
Button value = Traverse.Create((object)__instance).Field("m_continueButton").GetValue<Button>();
Button value2 = Traverse.Create((object)__instance).Field("m_playButton").GetValue<Button>();
Button value3 = Traverse.Create((object)__instance).Field("m_quitButton").GetValue<Button>();
bool flag = SlotStore.List().Count > 0;
((Component)value).gameObject.SetActive(flag);
((UnityEvent)value.onClick).RemoveListener(OpenSlotsAction);
if (flag)
{
((UnityEvent)value.onClick).AddListener(OpenSlotsAction);
}
Navigation navigation = ((Selectable)value2).navigation;
((Navigation)(ref navigation)).selectOnUp = (Selectable)(object)(flag ? value : value3);
((Selectable)value2).navigation = navigation;
navigation = ((Selectable)value3).navigation;
((Navigation)(ref navigation)).selectOnDown = (Selectable)(object)(flag ? value : value2);
((Selectable)value3).navigation = navigation;
return false;
}
private static void OpenSlots()
{
SlotListUI.Open();
}
}
internal static class SlotStore
{
internal static string Folder
{
get
{
string text = Path.Join((ReadOnlySpan<char>)Application.persistentDataPath, (ReadOnlySpan<char>)"SaveSlots");
Directory.CreateDirectory(text);
return text;
}
}
internal static string PathFor(string runId)
{
if (!Guid.TryParse(runId, out var result))
{
throw new ArgumentException("Run ID must be a GUID.", "runId");
}
return Path.Combine(Folder, result.ToString() + ".peak");
}
internal static string MetaPathFor(string runId)
{
if (!Guid.TryParse(runId, out var result))
{
throw new ArgumentException("Run ID must be a GUID.", "runId");
}
return Path.Combine(Folder, result.ToString() + ".json");
}
internal static bool CopySlotToQuickSave(string runId)
{
try
{
string destFileName = Path.Join((ReadOnlySpan<char>)Application.persistentDataPath, (ReadOnlySpan<char>)"quicksave.peak");
File.Copy(PathFor(runId), destFileName, overwrite: true);
return true;
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("SaveSlots: the selected run could not be copied to the game's quicksave. " + ex.Message));
return false;
}
}
internal static void SaveCurrentQuickSave()
{
CopyCurrentQuickSaveToSlot(overwrite: true, writeMeta: true);
}
private static void CopyCurrentQuickSaveToSlot(bool overwrite, bool writeMeta)
{
string text = Path.Join((ReadOnlySpan<char>)Application.persistentDataPath, (ReadOnlySpan<char>)"quicksave.peak");
if (!File.Exists(text))
{
return;
}
try
{
if (!Guid.TryParse(ReadSave(File.ReadAllText(text))?.run.runId, out var result) || result == Guid.Empty)
{
Plugin.Log.LogWarning((object)"SaveSlots: the game's quicksave has no valid run ID; it was left untouched.");
return;
}
string text2 = result.ToString();
string text3 = PathFor(text2);
if (!overwrite && File.Exists(text3))
{
return;
}
File.Copy(text, text3, overwrite);
if (writeMeta)
{
try
{
WriteMeta(text2);
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("SaveSlots: save metadata could not be written; the game save and slot copy succeeded. " + ex.Message));
}
}
Plugin.Log.LogInfo((object)("SaveSlots: copied the game's quicksave to slot " + text2 + "."));
}
catch (Exception ex2)
{
Plugin.Log.LogWarning((object)("SaveSlots: the quicksave copy could not be made; the game's auto-save was left untouched. " + ex2.Message));
}
}
internal static void WriteMeta(string runId)
{
string[] names;
int count;
if (PhotonNetwork.InRoom)
{
names = (from player in PhotonNetwork.PlayerList
select player.NickName into name
where !string.IsNullOrWhiteSpace(name)
select name).ToArray();
count = PhotonNetwork.PlayerList.Length;
}
else
{
string nickName = PhotonNetwork.NickName;
names = (string.IsNullOrWhiteSpace(nickName) ? Array.Empty<string>() : new string[1] { nickName });
count = 1;
}
SlotMeta slotMeta = new SlotMeta
{
runId = runId,
names = names,
count = count,
savedAtUtc = DateTime.UtcNow.ToString("o")
};
File.WriteAllText(MetaPathFor(runId), JsonUtility.ToJson((object)slotMeta));
}
internal static SlotMeta ReadMeta(string runId)
{
string path = MetaPathFor(runId);
if (!File.Exists(path))
{
return null;
}
try
{
return JsonUtility.FromJson<SlotMeta>(File.ReadAllText(path));
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("SaveSlots: metadata could not be read for " + runId + ". " + ex.Message));
return null;
}
}
internal static List<SlotInfo> List(bool includeCurrentQuickSave = true)
{
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Expected I4, but got Unknown
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_017a: Invalid comparison between Unknown and I4
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_0189: Invalid comparison between Unknown and I4
if (includeCurrentQuickSave)
{
CopyCurrentQuickSaveToSlot(overwrite: false, writeMeta: false);
}
List<SlotInfo> list = new List<SlotInfo>();
string[] files = Directory.GetFiles(Folder, "*.peak");
foreach (string path in files)
{
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
if (!Guid.TryParse(fileNameWithoutExtension, out var result) || result == Guid.Empty)
{
continue;
}
fileNameWithoutExtension = result.ToString();
SlotMeta slotMeta = ReadMeta(fileNameWithoutExtension);
SlotInfo slotInfo = new SlotInfo
{
runId = fileNameWithoutExtension,
names = (slotMeta?.names ?? Array.Empty<string>()),
count = (slotMeta?.count ?? 0),
savedAt = File.GetLastWriteTimeUtc(path)
};
if (slotMeta != null && DateTime.TryParse(slotMeta.savedAtUtc, null, DateTimeStyles.RoundtripKind, out var result2))
{
slotInfo.savedAt = result2.ToUniversalTime();
}
try
{
ParsedSave parsedSave = ReadSave(File.ReadAllText(path));
if (parsedSave != null)
{
Traverse val = Traverse.Create((object)parsedSave.run);
slotInfo.biome = BiomeName((int)val.Field("biomeReached").GetValue<Segment>());
slotInfo.ascent = val.Field("ascent").GetValue<int>();
slotInfo.day = val.Field("day").GetValue<int>();
slotInfo.runTimer = val.Field("runTimer").GetValue<float>();
slotInfo.lobby = (((int)((RunProgress)(ref parsedSave.run)).LobbyType == 1) ? "Offline" : (((int)((RunProgress)(ref parsedSave.run)).LobbyType == 2) ? "Online" : "Unknown"));
if (slotMeta == null)
{
slotInfo.count = parsedSave.playerCount;
slotInfo.names = ResolveNames(parsedSave.playerHashedIds);
}
}
slotInfo.usable = parsedSave != null && parsedSave.version == 4;
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("SaveSlots: a saved run could not be read: " + fileNameWithoutExtension + ". " + ex.Message));
slotInfo.usable = false;
}
list.Add(slotInfo);
}
return list.OrderByDescending((SlotInfo slot) => slot.savedAt).ToList();
}
internal static void Delete(string runId)
{
string path = PathFor(runId);
string path2 = MetaPathFor(runId);
if (File.Exists(path))
{
File.Delete(path);
}
if (File.Exists(path2))
{
File.Delete(path2);
}
}
private static ParsedSave ReadSave(string text)
{
//IL_00e8: 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)
Type type = AccessTools.Inner(typeof(Quicksave), "SaveData");
if (type == null)
{
throw new InvalidOperationException("The game's quicksave data type could not be found.");
}
object obj = JsonUtility.FromJson(text, type);
if (obj == null)
{
return null;
}
Traverse val = Traverse.Create(obj);
object value = val.Field("run").GetValue();
if (value == null)
{
return null;
}
ICollection value2 = val.Field("playerSaves").GetValue<ICollection>();
List<string> list = new List<string>();
if (value2 != null)
{
foreach (object item in value2)
{
string value3 = Traverse.Create(item).Property("HashedUserId", (object[])null).GetValue<string>();
if (!string.IsNullOrWhiteSpace(value3))
{
list.Add(value3);
}
}
}
return new ParsedSave
{
version = val.Field("version").GetValue<int>(),
run = (RunProgress)value,
playerCount = (value2?.Count ?? 0),
playerHashedIds = list.ToArray()
};
}
private static string[] ResolveNames(string[] playerHashedIds)
{
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: 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_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
if (playerHashedIds == null || playerHashedIds.Length == 0)
{
return Array.Empty<string>();
}
try
{
Dictionary<string, string> namesByHash = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
CSteamID val = default(CSteamID);
((CSteamID)(ref val))..ctor(PlatformManager.Platform.UserID);
string sha256Hash = Utilities.GetSha256Hash(val.m_SteamID.ToString());
namesByHash[sha256Hash] = SteamFriends.GetPersonaName();
EFriendFlags val2 = (EFriendFlags)4;
int friendCount = SteamFriends.GetFriendCount(val2);
for (int i = 0; i < friendCount; i++)
{
CSteamID friendByIndex = SteamFriends.GetFriendByIndex(i, val2);
string sha256Hash2 = Utilities.GetSha256Hash(friendByIndex.m_SteamID.ToString());
namesByHash[sha256Hash2] = SteamFriends.GetFriendPersonaName(friendByIndex);
}
string value;
return (from hashedId in playerHashedIds
select (!namesByHash.TryGetValue(hashedId, out value)) ? null : value into name
where !string.IsNullOrWhiteSpace(name)
select name).ToArray();
}
catch
{
return Array.Empty<string>();
}
}
private static string BiomeName(int biome)
{
return biome switch
{
0 => "Beach",
1 => "Tropics",
2 => "Alpine",
3 => "Caldera",
4 => "The Kiln",
5 => "Peak",
_ => "Unknown",
};
}
}
[Serializable]
internal sealed class SlotMeta
{
public string runId;
public string[] names;
public int count;
public string savedAtUtc;
}
internal sealed class ParsedSave
{
internal int version;
internal RunProgress run;
internal int playerCount;
internal string[] playerHashedIds;
}
internal sealed class SlotInfo
{
internal string runId;
internal bool usable;
internal string biome = "Unknown";
internal int ascent;
internal int day;
internal float runTimer;
internal string lobby = "Unknown";
internal string[] names;
internal int count;
internal DateTime savedAt;
}