Decompiled source of InfiniteSave v1.0.2

plugins/amione.InfiniteSave.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Reflection;
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;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("amione.InfiniteSave")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+9c8498e9ea3fdfaf032f12ce23cd641528b1f7ea")]
[assembly: AssemblyProduct("InfiniteSave")]
[assembly: AssemblyTitle("amione.InfiniteSave")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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;
		}
	}
}
internal static class PluginInfo
{
	public const string PluginGuid = "amione.InfiniteSave";

	public const string PluginName = "InfiniteSave";

	public const string PluginVersion = "1.0.2";
}
namespace InfiniteSave
{
	[BepInPlugin("amione.InfiniteSave", "InfiniteSave", "1.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource Log;

		public static ConfigEntry<bool> InfiniteDiscSaves;

		private void Awake()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			InfiniteDiscSaves = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "InfiniteDiscSaves", true, "When enabled, loading/reviving from a disc save never spends a use.");
			Harmony val = new Harmony("amione.InfiniteSave");
			val.PatchAll(typeof(SaveState));
			foreach (MethodBase patchedMethod in val.GetPatchedMethods())
			{
				Log.LogInfo((object)("Patched: " + patchedMethod.DeclaringType?.FullName + "." + patchedMethod.Name));
			}
			Log.LogInfo((object)"InfiniteSave v1.0.2 loaded - disc saves will no longer be consumed.");
		}
	}
	internal static class SaveState
	{
		[HarmonyPatch(typeof(SaveState), "LoadSave")]
		[HarmonyPrefix]
		private static void SaveStateLoadSavePatch(SaveState __instance)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Invalid comparison between Unknown and I4
			if (Plugin.InfiniteDiscSaves.Value && __instance != null && (int)__instance.type == 1)
			{
				__instance.amount++;
				CommandConsole.Log("<color=grey>[InfiniteSave] Disc save use restored - this save will not run out.</color>");
				Plugin.Log.LogInfo((object)$"Protected disc save '{__instance.id}' from being consumed (amount bumped to {__instance.amount} before load).");
			}
		}
	}
}