Decompiled source of AutoSaveConfig v0.0.5

plugins/AutoConfig/AutoSaveConfig.dll

Decompiled 10 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("AutoSaveConfig")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AutoSaveConfig")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("64443039-edc2-4adb-8193-a459b7477663")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.1.0")]
namespace AutoSaveConfig;

[BepInPlugin("autosaveconfig.nhickling.co.uk", "AutoSaveConfig", "0.0.0.5")]
public class AutoSaveConfig : BaseUnityPlugin
{
	public const string pluginGuid = "autosaveconfig.nhickling.co.uk";

	public const string pluginName = "AutoSaveConfig";

	public const string pluginVersion = "0.0.0.5";

	public const string Config_TimeoutSection = "Config";

	public const string Config_TimeoutKey = "Timeout";

	public static ConfigEntry<int> AutoSaveTimeout;

	private static ManualLogSource modLogger;

	public void Awake()
	{
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Expected O, but got Unknown
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Expected O, but got Unknown
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		modLogger = ((BaseUnityPlugin)this).Logger;
		modLogger.LogInfo((object)"AutoSaveConfig: Started 0.0.0.5");
		AutoSaveTimeout = ((BaseUnityPlugin)this).Config.Bind<int>("Config", "Timeout", 300, new ConfigDescription("Timeout in seconds between autosaves", (AcceptableValueBase)new AcceptableValueRange<int>(30, 600), Array.Empty<object>()));
		Harmony val = new Harmony("autosaveconfig.nhickling.co.uk");
		modLogger.LogInfo((object)"AutoSaveConfig: Fetching patch references");
		modLogger.LogInfo((object)"AutoSaveConfig: Starting Patch");
		val.PatchAll(typeof(AutoSavePatch));
	}
}
internal class AutoSavePatch
{
	[HarmonyPatch(typeof(SaveState), "NeedsToAutoSave")]
	[HarmonyPrefix]
	public static bool Prefix(ref bool __result)
	{
		try
		{
			if (SettingsMenu.autoSaveEnabled && NetworkConnector.IsHost)
			{
				__result = SaveState.currentPlayTime - SaveState.instance.metadata.playTime > AutoSaveConfig.AutoSaveTimeout.Value;
			}
			else
			{
				__result = false;
			}
			return false;
		}
		catch (Exception)
		{
		}
		return true;
	}
}