Decompiled source of MoreSaves v1.0.2

plugins/Nebulaetrix.WK_More_Saves.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using WK_More_Saves.core;

[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: AssemblyCompany("WK_More_Saves")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+727e94a82ade1f2ea71d0c2a41837bb821131287")]
[assembly: AssemblyProduct("WK_More_Saves")]
[assembly: AssemblyTitle("WK_More_Saves")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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 WK_More_Saves
{
	[BepInPlugin("WK_More_Saves", "WK_More_Saves", "1.0.2")]
	public class MoreSaves : BaseUnityPlugin
	{
		private bool _patched;

		public static ConfigEntry<int> ConfigSaveNum;

		public static ConfigEntry<bool> ConfigUseProfileSettings;

		private static Harmony _harmony;

		public static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			if (_patched)
			{
				Log.LogWarning((object)"Already Patched");
			}
			Log = ((BaseUnityPlugin)this).Logger;
			ConfigSaveNum = ((BaseUnityPlugin)this).Config.Bind<int>("General", "SaveNum", 0, "The current save file index to launch the game with.");
			ConfigUseProfileSettings = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "UseProfileSettings", false, "If each save profile should use its own settings.");
			_harmony = new Harmony("WK_More_Saves");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			SceneManager.sceneLoaded += UI.OnSceneLoad;
			Log.LogInfo((object)"Plugin WK_More_Saves is loaded!");
			_patched = true;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "WK_More_Saves";

		public const string PLUGIN_NAME = "WK_More_Saves";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}
namespace WK_More_Saves.patches
{
	[HarmonyPatch(typeof(SettingsManager))]
	public class SettingsManagerPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_004c: 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_0070: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			int value = MoreSaves.ConfigSaveNum.Value;
			if (!MoreSaves.ConfigUseProfileSettings.Value && value == 0)
			{
				return instructions;
			}
			Directory.CreateDirectory(Path.Combine(Application.persistentDataPath, $"Save{value}"));
			return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[3]
			{
				new CodeMatch((OpCode?)OpCodes.Ldstr, (object)"settings.json", (string)null),
				new CodeMatch((OpCode?)OpCodes.Call, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Stfld, (object)null, (string)null)
			}).SetOperandAndAdvance((object)$"Save{value}\\settings.json").InstructionEnumeration();
		}

		[HarmonyPatch("WipeSettings")]
		[HarmonyPrefix]
		private static bool WipeSave(SettingsManager __instance)
		{
			int value = MoreSaves.ConfigSaveNum.Value;
			if (!MoreSaves.ConfigUseProfileSettings.Value || value == 0)
			{
				return true;
			}
			File.Delete(Path.Combine(Application.persistentDataPath, $"Save{value}\\settings.json"));
			if ((Object)(object)SettingsManager.instance != (Object)null)
			{
				return false;
			}
			SettingsManager.instance.LoadSettings();
			return false;
		}
	}
	[HarmonyPatch(typeof(StatManager))]
	public class StatManagerPatch
	{
		[HarmonyPatch("LoadStats")]
		[HarmonyPrefix]
		private static void LoadSave(StatManager __instance)
		{
			int value = MoreSaves.ConfigSaveNum.Value;
			if (value != 0)
			{
				Directory.CreateDirectory(Path.Combine(Application.persistentDataPath, $"Save{value}"));
				Traverse.Create((object)__instance).Field("filePath").SetValue((object)Path.Combine(Application.persistentDataPath, $"Save{value}\\save{value}.json"));
			}
		}
	}
}
namespace WK_More_Saves.core
{
	public abstract class UI
	{
		public static void OnSceneLoad(Scene scene, LoadSceneMode loadSceneMode)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
			if (!(((Scene)(ref scene)).name != "Main-Menu"))
			{
				GameObject gameObject = GameObject.Find("Play Game").gameObject;
				((LayoutGroup)gameObject.AddComponent<HorizontalLayoutGroup>()).padding = new RectOffset(10, 10, 0, 0);
				gameObject.AddComponent<ContentSizeFitter>().horizontalFit = (FitMode)2;
				RectTransform component = gameObject.GetComponent<RectTransform>();
				gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(component.sizeDelta.x + 100f, component.sizeDelta.y);
				GameObject gameObject2 = ((Component)gameObject.transform.Find("Text (TMP)")).gameObject;
				gameObject2.GetComponent<RectTransform>().pivot = new Vector2(0f, 0.5f);
				gameObject2.GetComponent<TMP_Text>().text = $"PLAY - Save {MoreSaves.ConfigSaveNum.Value}";
				gameObject2.AddComponent<ContentSizeFitter>().horizontalFit = (FitMode)2;
				gameObject2.AddComponent<LayoutElement>().preferredHeight = 45f;
				LayoutRebuilder.ForceRebuildLayoutImmediate(((Component)gameObject.transform.parent).GetComponent<RectTransform>());
			}
		}
	}
}