Decompiled source of Keep Last Save v1.0.1

KeepLastSave.dll

Decompiled 3 weeks 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.1")]
public class KeepLastSaveModule : BaseUnityPlugin
{
	public const string GUID = "kleirof.etg.keeplastsave";

	public const string NAME = "Keep Last Save";

	public const string VERSION = "1.0.1";

	public const string TEXT_COLOR = "#FFCCCC";

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

	public void GMStart(GameManager g)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		Log("Keep Last Save v1.0.1 started successfully.", "#FFCCCC");
		Harmony val = new Harmony("kleirof.etg.keeplastsave");
		val.PatchAll();
	}

	public static void Log(string text, string color = "FFFFFF")
	{
		ETGModConsole.Log((object)("<color=" + color + ">" + text + "</color>"), false);
	}
}
public static class KeepLastSavePatches
{
	[HarmonyPatch(typeof(GameManager), "VerifyAndLoadMidgameSave")]
	public class VerifyAndLoadMidgameSavePatchClass
	{
		[HarmonyILManipulator]
		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)2, new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, "System.Collections.Generic.List`1<System.String>", "Contains")
			}))
			{
				val.EmitCall<VerifyAndLoadMidgameSavePatchClass>("VerifyAndLoadMidgameSavePatchCall");
			}
		}

		private static bool VerifyAndLoadMidgameSavePatchCall(bool orig)
		{
			return false;
		}
	}

	[HarmonyPatch(typeof(MainMenuFoyerController), "InitializeMainMenu")]
	public class InitializeMainMenuPatchClass
	{
		[HarmonyILManipulator]
		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")
			}))
			{
				val.Emit(OpCodes.Ldarg_0);
				val.EmitCall<InitializeMainMenuPatchClass>("InitializeMainMenuPatchCall");
			}
		}

		private static void InitializeMainMenuPatchCall(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 static void EmitCall<T>(this ILCursor iLCursor, string methodName, Type[] parameters = null, Type[] generics = null)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		MethodInfo methodInfo = AccessTools.Method(typeof(T), methodName, parameters, generics);
		iLCursor.Emit(OpCodes.Call, (MethodBase)methodInfo);
	}
}