Decompiled source of Keep Last Save v1.0.0

KeepLastSave.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Mono.Cecil.Cil;
using MonoMod.Cil;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("KeepLastSave")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("KeepLastSave")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("17665fc7-b7f3-448d-b85b-22506f488236")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace KeepLastSave;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("kleirof.etg.keeplastsave", "Keep Last Save", "1.0.0")]
public class KeepLastSaveModule : BaseUnityPlugin
{
	public class KeepLastSavePatches
	{
		[HarmonyILManipulator]
		[HarmonyPatch(typeof(GameManager), "VerifyAndLoadMidgameSave")]
		public static void VerifyAndLoadMidgameSavePatch(ILContext ctx)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			ILCursor val = new ILCursor(ctx);
			if (val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdstr(x, "Failed to load mid game save (2)")
			}))
			{
				int index = val.Index;
				val.Index = index - 1;
				val.EmitDelegate<Func<bool, bool>>((Func<bool, bool>)((bool orig) => false));
			}
		}

		[HarmonyILManipulator]
		[HarmonyPatch(typeof(MainMenuFoyerController), "InitializeMainMenu")]
		public static void InitializeMainMenuPatch(ILContext ctx)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(ctx);
			if (!val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCall<GameManager>(x, "HasValidMidgameSave")
			}))
			{
				return;
			}
			val.Emit(OpCodes.Ldarg_0);
			val.EmitDelegate<Action<MainMenuFoyerController>>((Action<MainMenuFoyerController>)delegate(MainMenuFoyerController self)
			{
				if (GameManager.HasValidMidgameSave())
				{
					((dfControl)self.ContinueGameButton).IsEnabled = true;
					((dfControl)self.ContinueGameButton).IsVisible = true;
				}
				else
				{
					((dfControl)self.ContinueGameButton).IsEnabled = false;
					((dfControl)self.ContinueGameButton).IsVisible = false;
				}
			});
		}
	}

	public const string GUID = "kleirof.etg.keeplastsave";

	public const string NAME = "Keep Last Save";

	public const string VERSION = "1.0.0";

	public const string TEXT_COLOR = "#FFCCCC";

	public void Start()
	{
		ETGModMainBehaviour.WaitForGameManagerStart((Action<GameManager>)GMStart);
	}

	public void GMStart(GameManager g)
	{
		Log("Keep Last Save v1.0.0 started successfully.", "#FFCCCC");
		Harmony.CreateAndPatchAll(typeof(KeepLastSavePatches), (string)null);
	}

	public static void Log(string text, string color = "FFFFFF")
	{
		ETGModConsole.Log((object)("<color=" + color + ">" + text + "</color>"), false);
	}
}