using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
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;
using Jotunn.Utils;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ConfigurableAutosave")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ConfigurableAutosave")]
[assembly: AssemblyCopyright("Copyright \ufffd 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("26.2.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("26.2.0.0")]
namespace ConfigurableAutosave;
[BepInPlugin("com.github.johndowson.ConfigurableAutosave", "ConfigurableAutosave", "26.2.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
internal class ConfigurableAutosave : BaseUnityPlugin
{
[HarmonyPatch(typeof(Game))]
public static class GamePatches
{
[HarmonyPatch("UpdateSaving")]
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> PatchAutosave(IEnumerable<CodeInstruction> instructions)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
if (autosavePeriod.Value == 0f)
{
list[0] = new CodeInstruction(OpCodes.Ret, (object)null);
}
return list.AsEnumerable();
}
[HarmonyPatch("Start")]
[HarmonyPrefix]
public static void ModifyAutosavePeriod()
{
float value = autosavePeriod.Value;
if (value != 0f)
{
Game.m_saveInterval = value;
}
}
[HarmonyPatch("SleepStop")]
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> SaveOnSleep(IEnumerable<CodeInstruction> instructions)
{
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Expected O, but got Unknown
if (saveOnSleep.Value)
{
return instructions;
}
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Ldarg_0 && list[i + 1].opcode == OpCodes.Ldfld && list[i + 2].opcode == OpCodes.Ldc_R4 && list[i + 2].operand == (object)60f)
{
list[i] = new CodeInstruction(OpCodes.Ret, (object)null);
}
}
return list.AsEnumerable();
}
}
public const string PluginGUID = "com.github.johndowson.ConfigurableAutosave";
public const string PluginName = "ConfigurableAutosave";
public const string PluginVersion = "26.2.0";
private static readonly Harmony harmony = new Harmony("com.github.johndowson.ConfigurableAutosave");
private static ConfigEntry<float> autosavePeriod;
public static ConfigEntry<bool> saveOnSleep;
private void Awake()
{
autosavePeriod = ((BaseUnityPlugin)this).Config.Bind<float>("Autosave", "Interval", 1200f, "Time between autosaves in seconds. If set ot zero, autosaving is disabled");
saveOnSleep = ((BaseUnityPlugin)this).Config.Bind<bool>("Autosave", "OnSleep", true, "Save after sleeping");
harmony.PatchAll();
Logger.LogInfo((object)"ConfigurableAutosave has landed");
}
}