Decompiled source of NoSaveDelete v2.0.0

NoSaveDelete.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("NoSaveDelete")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+385cf7dfa763e1b749e66b5949d5a13695dd80e9")]
[assembly: AssemblyProduct("NoSaveDelete")]
[assembly: AssemblyTitle("NoSaveDelete")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 NoSaveDelete
{
	[BepInPlugin("com.vaniiaaa.nosavedelete", "NoSaveDelete", "2.0")]
	public class NoSaveDeletePlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(RunManager), "ChangeLevel")]
		public class RunManagerChangeLevelPatch
		{
			private static void Prefix(bool _completedLevel, bool _levelFailed, RunManager __instance)
			{
				if (!((Object)(object)__instance.levelCurrent == (Object)(object)__instance.levelLobbyMenu) && _levelFailed && (Object)(object)__instance.levelCurrent != (Object)(object)__instance.levelArena)
				{
					blockSaves = true;
					needsReload = true;
					reloadTimer = 0f;
					logger.LogInfo((object)"Level failed. Saves blocked. Reload scheduled.");
				}
			}
		}

		[HarmonyPatch(typeof(DataDirector), "SaveDeleteCheck")]
		public class DataDirectorSaveDeleteCheckPatch
		{
			private static bool Prefix()
			{
				return !SemiFunc.RunIsArena() && !blockSaves;
			}
		}

		[HarmonyPatch(typeof(StatsManager), "SaveFileDelete")]
		public class StatsManagerSaveFileDeletePatch
		{
			private static bool Prefix(string saveFileName)
			{
				return !SemiFunc.RunIsArena() && !blockSaves;
			}
		}

		[HarmonyPatch(typeof(RunManager), "ResetProgress")]
		public class ResetProgressPatch
		{
			private static bool Prefix()
			{
				return !SemiFunc.RunIsArena();
			}
		}

		[HarmonyPatch(typeof(StatsManager), "SaveGame")]
		public class StatsManagerSaveGamePatch
		{
			private static bool Prefix(string fileName)
			{
				return !SemiFunc.RunIsArena() && !blockSaves;
			}
		}

		[HarmonyPatch(typeof(StatsManager), "SaveFileSave")]
		public class StatsManagerSaveFileSavePatch
		{
			private static bool Prefix()
			{
				return !SemiFunc.RunIsArena() && !blockSaves;
			}
		}

		private static ManualLogSource logger;

		private static bool blockSaves;

		private static bool needsReload;

		private static float reloadTimer;

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			logger = ((BaseUnityPlugin)this).Logger;
			Harmony val = new Harmony("com.vaniiaaa.nosavedelete");
			val.PatchAll();
			logger.LogInfo((object)"NoSaveDelete loaded");
		}

		private void Update()
		{
			if (!needsReload)
			{
				return;
			}
			bool flag = false;
			Type type = AccessTools.TypeByName("LevelGenerator");
			if (type != null)
			{
				object obj = AccessTools.Property(type, "Instance")?.GetValue(null);
				if (obj != null)
				{
					FieldInfo fieldInfo = AccessTools.Field(type, "Generated");
					if (fieldInfo != null)
					{
						flag = (bool)fieldInfo.GetValue(obj);
					}
				}
			}
			if (!flag)
			{
				return;
			}
			reloadTimer += Time.deltaTime;
			if (!(reloadTimer > 0.1f))
			{
				return;
			}
			blockSaves = false;
			if ((Object)(object)StatsManager.instance != (Object)null)
			{
				string value = Traverse.Create((object)StatsManager.instance).Field("saveFileCurrent").GetValue<string>();
				if (!string.IsNullOrEmpty(value))
				{
					logger.LogInfo((object)("Restoring save file: " + value));
					StatsManager.instance.LoadGame(value, (List<string>)null);
					needsReload = false;
					reloadTimer = 0f;
				}
			}
		}
	}
}