Decompiled source of SaveFrequency v1.1.1

plugins/SaveFrequency.dll

Decompiled a week ago
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("SaveFrequency")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SaveFrequency")]
[assembly: AssemblyCopyright("Copyright \ufffd  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.0")]
namespace SaveFrequency;

public static class Configs
{
	public static ConfigEntry<bool> AlwaysSavePlayerPosition;

	public static ConfigEntry<int> SaveFrequency;

	public static ConfigEntry<int> BackupFrequency;

	public static ConfigEntry<int> OldestBackupLifeTime;

	public static void SetupConfigs(ConfigFile config)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Expected O, but got Unknown
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Expected O, but got Unknown
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Expected O, but got Unknown
		AlwaysSavePlayerPosition = config.Bind<bool>("General", GenerateConfigKey("AlwaysSavePlayerPosition"), true, new ConfigDescription("If true, the player's position will always be saved when the game is saved.", (AcceptableValueBase)null, new object[1] { SetOrder(3) }));
		SaveFrequency = config.Bind<int>("General", GenerateConfigKey("SaveFrequency", "in seconds"), 900, new ConfigDescription("How often (in seconds) the game should be saved. Default game value = 1800 = 30 minutes.", (AcceptableValueBase)null, new object[1] { SetOrder(2) }));
		BackupFrequency = config.Bind<int>("General", GenerateConfigKey("BackupFrequency", "in seconds"), 1800, new ConfigDescription("How often (in seconds) the game save should be backed up. Default game value = 7200 = 2 hours.", (AcceptableValueBase)null, new object[1] { SetOrder(1) }));
		OldestBackupLifeTime = config.Bind<int>("General", GenerateConfigKey("OldestBackupLifeTime", "in seconds"), 43200, new ConfigDescription("How long (in seconds) the oldest backup should be kept before it can be overwritten. Default game value = 43200 = 12 hours.", (AcceptableValueBase)null, new object[1] { SetOrder(0) }));
		config.SettingChanged += Config_SettingChanged;
	}

	public static string GenerateConfigKey(string key)
	{
		return GenerateConfigKey(key, null);
	}

	public static string GenerateConfigKey(string key, string unit)
	{
		key = string.Concat(key.Select((char x) => (!char.IsUpper(x)) ? x.ToString() : (" " + x))).TrimStart(new char[1] { ' ' });
		if (!string.IsNullOrEmpty(unit))
		{
			key += $" ({unit})";
		}
		return key;
	}

	public static ConfigurationManagerAttributes SetOrder(int order, bool isAdminOnly = true)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		return new ConfigurationManagerAttributes
		{
			Order = order,
			IsAdminOnly = isAdminOnly
		};
	}

	private static void Config_SettingChanged(object sender, SettingChangedEventArgs e)
	{
		Plugin.UpdateSaveSettings();
	}
}
[BepInPlugin("SaveFrequency", "SaveFrequency", "1.1.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(ZNetScene), "Awake")]
	public static class ZNetScene_Awake_Patch
	{
		public static void Postfix()
		{
			UpdateSaveSettings();
		}
	}

	[HarmonyPatch(typeof(Game), "SavePlayerProfile")]
	public static class Game_SavePlayerProfile_Patch
	{
		public static void Prefix(ref bool setLogoutPoint)
		{
			if (Configs.AlwaysSavePlayerPosition.Value)
			{
				setLogoutPoint = true;
			}
		}
	}

	public const string PluginGUID = "SaveFrequency";

	public const string PluginName = "SaveFrequency";

	public const string PluginVersion = "1.1.1";

	private static Harmony harmony;

	private void Awake()
	{
		Configs.SetupConfigs(((BaseUnityPlugin)this).Config);
		harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "SaveFrequency");
	}

	private void OnDestroy()
	{
		Harmony obj = harmony;
		if (obj != null)
		{
			obj.UnpatchSelf();
		}
	}

	public static void UpdateSaveSettings()
	{
		if ((Object)(object)ZNetScene.instance != (Object)null)
		{
			Game.m_saveInterval = Configs.SaveFrequency.Value;
			ZNet.m_backupShort = Configs.BackupFrequency.Value;
			ZNet.m_backupLong = Configs.OldestBackupLifeTime.Value;
			if (Terminal.m_testList.ContainsKey("autowait"))
			{
				Terminal.m_testList["autowait"] = "0";
			}
			else
			{
				Terminal.m_testList.Add("autowait", "0");
			}
		}
	}
}