using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using Brix.Assets;
using Brix.Game;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Smooth.Slinq;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyCompany("CastleStory_AutoQsave")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("CastleStory: Auto Quicksave Plugin")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0+bc26e6a01d230150304eb2bfe1a63ed66b0a4d84")]
[assembly: AssemblyProduct("CastleStory_AutoQsave")]
[assembly: AssemblyTitle("CastleStory_AutoQsave")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class IsReadOnlyAttribute : Attribute
{
}
[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 CastleStory_AutoQsave
{
internal class AutoQsave
{
private static AutoQsave _instance;
private AutoQsaveConfig config;
public static AutoQsave Instance => _instance ?? (_instance = new AutoQsave());
private AutoQsave()
{
}
public void Start(AutoQsaveConfig config)
{
this.config = config;
((MonoBehaviour)Plugin.Instance).StopAllCoroutines();
if (!(config.interval == TimeSpan.Zero))
{
Plugin instance = Plugin.Instance;
TimeSpan interval = config.interval;
((MonoBehaviour)instance).StartCoroutine(DoSave((float)interval.TotalSeconds));
}
}
private IEnumerator DoSave(float interval)
{
while (true)
{
yield return (object)new WaitForSecondsRealtime(interval);
try
{
Debug.Log((object)"Starting auto quick save.");
StatsTracker.SaveStats();
SaveType saveType = (SaveType)((config.type == AutoQsaveType.Auto) ? 3 : 4);
Asset_Map asset_Map = Slinqable.Slinq<Asset_Map>((IList<Asset_Map>)AssetDispensary.saves.SendSaveQuery(saveType, (AssetQueryParameters)15, (AssetPlayableContext)255)).FirstOrDefault();
if (asset_Map == null)
{
asset_Map = Asset_Map.CreateShellFrom(GameParam.Map, (MapType)2);
if (config.type == AutoQsaveType.Auto)
{
((Asset_Base<Asset_Map>)(object)asset_Map).codename = "autoquicksave";
((Asset_Base<Asset_Map>)(object)asset_Map).customName = "--Auto Quicksave--";
}
else
{
((Asset_Base<Asset_Map>)(object)asset_Map).codename = "quicksave";
((Asset_Base<Asset_Map>)(object)asset_Map).rawDisplayName = "--Quicksave--";
((Asset_Base<Asset_Map>)(object)asset_Map).customName = "--Quicksave--";
}
asset_Map.saveType = saveType;
((Asset_Base<Asset_Map>)(object)asset_Map).Disk_WriteAsNew((AssetAuthorType)0);
}
else
{
asset_Map.isDebug = GameParam.Map.isDebug;
((Asset_Base<Asset_Map>)(object)asset_Map).Disk_Overwrite();
}
}
catch (Exception ex)
{
Debug.LogException(ex);
break;
}
}
}
}
internal readonly struct AutoQsaveConfig
{
public readonly TimeSpan interval;
public readonly AutoQsaveType type;
public AutoQsaveConfig(TimeSpan interval, AutoQsaveType type)
{
this.interval = interval;
this.type = type;
}
internal static AutoQsaveConfig Parse(ConfigEntry<AutoQsaveType> configType, ConfigEntry<string> configInterval)
{
TimeSpan timeSpan;
try
{
Match match = Regex.Match(configInterval.Value, "^(\\d+)(.*)");
if (!match.Success || match.Groups.Count != 3)
{
throw new ArgumentException("Incorrect interval value. " + configInterval.Value);
}
double value = double.Parse(match.Groups[1].Value);
string value2 = match.Groups[2].Value;
string text = value2;
if (!(text == "s"))
{
if (text == "m")
{
timeSpan = TimeSpan.FromMinutes(value);
}
else
{
Debug.LogError((object)"Incorrect interval type.");
timeSpan = TimeSpan.Zero;
}
}
else
{
timeSpan = TimeSpan.FromSeconds(value);
}
}
catch (Exception ex)
{
Debug.LogException(ex);
timeSpan = TimeSpan.Zero;
}
return new AutoQsaveConfig(timeSpan, configType.Value);
}
}
internal enum AutoQsaveType
{
Auto,
Quick
}
[BepInPlugin("CastleStory_AutoQsave", "CastleStory_AutoQsave", "0.2.0")]
public class Plugin : BaseUnityPlugin
{
private static Plugin _instance;
public static Plugin Instance
{
get
{
if ((Object)(object)_instance == (Object)null)
{
throw new InvalidOperationException();
}
return _instance;
}
}
private void Awake()
{
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
_instance = this;
ConfigEntry<AutoQsaveType> configType = ((BaseUnityPlugin)this).Config.Bind<AutoQsaveType>("General", "Type", AutoQsaveType.Auto, "Saves are separated from quicksave when set to Auto. If set to Quick then both manual quicksave and autosave will overwrite each other");
ConfigEntry<string> configInterval = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Interval", "10m", "Sets interval between saves. s - seconds, m - minutes");
AutoQsave.Instance.Start(AutoQsaveConfig.Parse(configType, configInterval));
new Harmony("com.wasikuss.castlestory.autoqsave").PatchAll();
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "CastleStory_AutoQsave";
public const string PLUGIN_NAME = "CastleStory_AutoQsave";
public const string PLUGIN_VERSION = "0.2.0";
}
}