Decompiled source of QuickSave v0.1.0

QuickSave.dll

Decompiled 3 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("QuickSave")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Quick-save and quick-load hotkeys for Dyson Sphere Program")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+46fd5479be1cf6fa9f45f255de915e031c5c2e62")]
[assembly: AssemblyProduct("Quick Save")]
[assembly: AssemblyTitle("QuickSave")]
[assembly: AssemblyVersion("0.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[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 QuickSave
{
	[BepInPlugin("com.geostyx.dsp.quicksave", "Quick Save", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private const string SaveName = "quicksave";

		private const string CompressSaveGuid = "org.soardev.compresssave";

		private ConfigEntry<KeyboardShortcut> _quickSaveKey;

		private ConfigEntry<KeyboardShortcut> _quickLoadKey;

		private FieldInfo? _useCompressSave;

		private FieldInfo? _enableCompress;

		private MethodInfo? _useCommonSaveCompressionType;

		private void Awake()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			_quickSaveKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "QuickSaveKey", new KeyboardShortcut((KeyCode)286, Array.Empty<KeyCode>()), "Saves the game as \"quicksave\".");
			_quickLoadKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "QuickLoadKey", new KeyboardShortcut((KeyCode)290, Array.Empty<KeyCode>()), "Loads the \"quicksave\" save.");
			if (Chainloader.PluginInfos.TryGetValue("org.soardev.compresssave", out var value))
			{
				Type type = ((object)value.Instance).GetType().Assembly.GetType("CompressSave.PatchSave");
				_useCompressSave = type?.GetField("UseCompressSave");
				_enableCompress = type?.GetField("EnableCompress");
				_useCommonSaveCompressionType = type?.GetMethod("UseCommonSaveCompressionType");
				if (_useCompressSave == null || _enableCompress == null || _useCommonSaveCompressionType == null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"CompressSave.PatchSave members not found; quicksaves will not be compressed");
					_useCompressSave = null;
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Quick Save 0.1.0 loaded");
		}

		private void Update()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			if (VFInput.inputing || !GameMain.isRunning || (!GameMain.instance.isMenuDemo && (GameMain.inOtherScene || GameMain.mainPlayer.respawning)))
			{
				return;
			}
			KeyboardShortcut value = _quickSaveKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				QuickSave();
				return;
			}
			value = _quickLoadKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				QuickLoad();
			}
		}

		private void QuickSave()
		{
			if (!GameMain.instance.isMenuDemo && !GameMain.data.guideRunning)
			{
				bool flag = (GameMain.localStar == null || GameMain.localStar.loaded) && (GameMain.localPlanet == null || (GameMain.localPlanet.loaded && GameMain.localPlanet.factoryLoaded));
				bool flag2 = flag && SaveGame();
				if (flag2)
				{
					UIAutoSave.lastSaveTick = GameMain.gameTick;
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)(flag ? "Quicksave failed" : "Quicksave skipped while the local star or planet loads"));
				}
				UIRealtimeTip.Popup(Localization.Translate(flag2 ? "保存成功" : "保存失败"), !flag2, 0);
			}
		}

		private bool SaveGame()
		{
			if (_useCompressSave == null || !(bool)_enableCompress.GetValue(null))
			{
				return GameSave.SaveCurrentGame("quicksave");
			}
			_useCompressSave.SetValue(null, true);
			_useCommonSaveCompressionType.Invoke(null, null);
			try
			{
				return GameSave.SaveCurrentGame("quicksave");
			}
			finally
			{
				_useCompressSave.SetValue(null, false);
			}
		}

		private void QuickLoad()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			if (!GameSave.SaveExist("quicksave"))
			{
				UIRealtimeTip.Popup("No quicksave", true, 0);
				return;
			}
			GameDesc val = GameSave.LoadGameDesc("quicksave");
			if (val == null)
			{
				UIRealtimeTip.Popup(Localization.Translate("无效存档"), true, 0);
				return;
			}
			DSPGame.StartGame("quicksave");
			DSPGame.WillEnableSandboxTools = val.isSandboxMode;
			DSPGame.LoadWithGoalLevel = val.goalLevel;
			DSPGame.RecordPlayVersion();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.geostyx.dsp.quicksave";

		public const string PLUGIN_NAME = "Quick Save";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}