Decompiled source of SaveFrequency v1.0.0

SaveFrequency.dll

Decompiled a year 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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SaveFrequency")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SaveFrequency")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
namespace SaveFrequency;

public static class Configs
{
	public static ConfigEntry<int> SaveFrequency;

	public static ConfigEntry<int> BackupFrequency;

	public static ConfigEntry<int> OldestBackupLifeTime;

	public static void SetupConfigs(ConfigFile config)
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Expected O, but got Unknown
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Expected O, but got Unknown
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Expected O, but got Unknown
		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(0) }));
		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 for (therefore not overwritten). Default game value = 43200 = 12 hours.", (AcceptableValueBase)null, new object[1] { SetOrder(2) }));
		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) : x.ToString())).TrimStart(new char[1] { ' ' });
		if (!string.IsNullOrEmpty(unit))
		{
			key += $" ({unit})";
		}
		return key;
	}

	public static ConfigurationManagerAttributes SetOrder(int order, bool isAdminOnly = true)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: 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.0.0")]
[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();
		}
	}

	public const string PluginGUID = "SaveFrequency";

	public const string PluginName = "SaveFrequency";

	public const string PluginVersion = "1.0.0";

	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");
			}
		}
	}
}