Decompiled source of MoreSaves v0.1.1

MoreSaves.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Events;
using UnityEngine.UI;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Mod
{
	[BepInPlugin("duviz.MoreSaves", "MoreSaves", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static Plugin instance;

		public static ConfigFile config;

		public void Awake()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			instance = this;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			config = ((BaseUnityPlugin)this).Config;
			new Harmony("duviz.MoreSaves").PatchAll();
		}

		public static T Ass<T>(string path)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return Addressables.LoadAssetAsync<T>((object)path).WaitForCompletion();
		}

		public static void LogInfo(object msg)
		{
			((BaseUnityPlugin)instance).Logger.LogInfo(msg);
		}

		public static void LogWarning(object msg)
		{
			((BaseUnityPlugin)instance).Logger.LogWarning(msg);
		}

		public static void LogError(object msg)
		{
			((BaseUnityPlugin)instance).Logger.LogError(msg);
		}
	}
	public class PluginInfo
	{
		public const string GUID = "duviz.MoreSaves";

		public const string Name = "MoreSaves";

		public const string Version = "1.0.0";
	}
}
namespace MoreSaves.Patches
{
	[HarmonyPatch(typeof(SaveSlotMenu), "OnEnable")]
	public static class SaveSlotMenuPatch
	{
		public static bool Prefix(SaveSlotMenu __instance)
		{
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: 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)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Expected O, but got Unknown
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Expected O, but got Unknown
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: 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_0307: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.slots == null)
			{
				List<SlotRowPanel> list = new List<SlotRowPanel>();
				SlotData[] slots = GameProgressSaver.GetSlots();
				for (int i = 0; i < 10; i++)
				{
					SlotRowPanel newRow = Object.Instantiate<SlotRowPanel>(__instance.templateRow, ((Component)__instance.templateRow).transform.parent);
					newRow.slotIndex = ((i < 5) ? i : (i + 100));
					((Component)newRow).gameObject.SetActive(true);
					RectTransform component = ((Component)newRow).GetComponent<RectTransform>();
					component.sizeDelta -= Vector2.up * 20f;
					__instance.UpdateSlotState(newRow, slots[newRow.slotIndex]);
					((UnityEvent)newRow.selectButton.onClick).AddListener((UnityAction)delegate
					{
						__instance.SelectSlot(newRow.slotIndex);
					});
					((UnityEvent)newRow.deleteButton.onClick).AddListener((UnityAction)delegate
					{
						__instance.ClearSlot(newRow.slotIndex);
					});
					list.Add(newRow);
					if (newRow.slotIndex >= 100 && newRow.slotIndex <= 200)
					{
						newRow.slotNumberLabel.text = $"SAVE {i + 1}";
					}
				}
				Navigation val;
				Navigation navigation;
				for (int j = 0; j < 10; j++)
				{
					Selectable selectButton = (Selectable)(object)list[j].selectButton;
					val = default(Navigation);
					((Navigation)(ref val)).mode = (Mode)4;
					((Navigation)(ref val)).selectOnUp = (Selectable)(object)((j > 0) ? list[j - 1].selectButton : null);
					((Navigation)(ref val)).selectOnDown = (Selectable)(object)((j + 1 < 10) ? list[j + 1].selectButton : __instance.closeButton);
					((Navigation)(ref val)).selectOnLeft = (Selectable)(object)list[j].deleteButton;
					((Navigation)(ref val)).selectOnRight = (Selectable)(object)list[j].deleteButton;
					navigation = val;
					selectButton.navigation = navigation;
					Selectable deleteButton = (Selectable)(object)list[j].deleteButton;
					val = default(Navigation);
					((Navigation)(ref val)).mode = (Mode)4;
					((Navigation)(ref val)).selectOnUp = (Selectable)(object)((j > 0) ? list[j - 1].deleteButton : null);
					((Navigation)(ref val)).selectOnDown = (Selectable)(object)((j + 1 < 10) ? list[j + 1].deleteButton : __instance.closeButton);
					((Navigation)(ref val)).selectOnLeft = (Selectable)(object)list[j].selectButton;
					((Navigation)(ref val)).selectOnRight = (Selectable)(object)list[j].selectButton;
					navigation = val;
					deleteButton.navigation = navigation;
				}
				Selectable closeButton = (Selectable)(object)__instance.closeButton;
				val = default(Navigation);
				((Navigation)(ref val)).mode = (Mode)4;
				((Navigation)(ref val)).selectOnUp = (Selectable)(object)list[4].selectButton;
				((Navigation)(ref val)).selectOnDown = (Selectable)(object)list[0].selectButton;
				navigation = val;
				closeButton.navigation = navigation;
				__instance.slots = list.ToArray();
				((Component)__instance.templateRow).gameObject.SetActive(false);
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(GameProgressSaver), "GetSlots")]
	public static class GameProgressSaverPatch
	{
		public static bool Prefix(ref SlotData[] __result)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			int currentSlot = GameProgressSaver.currentSlot;
			List<SlotData> list = new List<SlotData>();
			for (int i = 0; i < 200; i++)
			{
				GameProgressSaver.currentSlot = i;
				if (!Directory.Exists(GameProgressSaver.SavePath))
				{
					list.Add(new SlotData
					{
						exists = false
					});
					continue;
				}
				try
				{
					if (!(GameProgressSaver.ReadFile(GameProgressSaver.generalProgressPath) is GameProgressMoneyAndGear))
					{
						list.Add(new SlotData
						{
							exists = false
						});
					}
				}
				catch (Exception ex)
				{
					Debug.LogException(ex);
				}
				SlotData directorySlotData = GameProgressSaver.GetDirectorySlotData(GameProgressSaver.SavePath);
				list.Add(directorySlotData);
			}
			GameProgressSaver.currentSlot = currentSlot;
			__result = list.ToArray();
			return false;
		}
	}
	[HarmonyPatch(typeof(GameProgressSaver), "GetDirectorySlotData")]
	public static class GameProgressSaverPatch2
	{
		public static bool Prefix(ref SlotData __result, string path)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			Debug.Log((object)("Generating SlotData for " + path));
			int num = 0;
			int num2 = 0;
			for (int i = 0; i < 6; i++)
			{
				object obj = GameProgressSaver.ReadFile(Path.Combine(path, $"difficulty{i}progress.bepis"));
				GameProgressData val = (GameProgressData)((obj is GameProgressData) ? obj : null);
				if (val != null && (val.levelNum > num || (val.levelNum == num && val.difficulty > num2)))
				{
					num = val.levelNum;
					num2 = val.difficulty;
				}
			}
			__result = new SlotData
			{
				exists = true,
				highestDifficulty = num2,
				highestLvlNumber = num
			};
			return false;
		}
	}
	[HarmonyPatch(typeof(GameProgressSaver), "ReadFile")]
	public static class GameProgressSaverPatch3
	{
		public static bool Prefix(ref object __result, string path)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			if (!File.Exists(path))
			{
				__result = null;
				return false;
			}
			object obj;
			using (FileStream fileStream = new FileStream(path, FileMode.Open))
			{
				if (fileStream.Length == 0)
				{
					throw new Exception("Stream Length 0");
				}
				BinaryFormatter binaryFormatter = new BinaryFormatter();
				RestrictedSerializationBinder val = new RestrictedSerializationBinder();
				val.AllowedTypes.Add(typeof(RankData));
				val.AllowedTypes.Add(typeof(CyberRankData));
				val.AllowedTypes.Add(typeof(RankScoreData));
				val.AllowedTypes.Add(typeof(GameProgressData));
				val.AllowedTypes.Add(typeof(GameProgressMoneyAndGear));
				binaryFormatter.Binder = (SerializationBinder?)(object)val;
				obj = binaryFormatter.Deserialize(fileStream);
			}
			__result = obj;
			return obj == null;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}