Decompiled source of QuickSave v1.0.0

QuickSave.dll

Decompiled 2 days ago
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using UnityEngine;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace SailwindQuickSave;

[BepInPlugin("com.roy.sailwind.quicksave", "QuickSave", "1.0.0")]
public class QuickSavePlugin : BaseUnityPlugin
{
	private ConfigEntry<KeyboardShortcut> hotkey;

	private ConfigEntry<bool> compressed;

	private ConfigEntry<bool> showMessage;

	private string message = "";

	private float messageTimer;

	private GUIStyle style;

	private void Awake()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		hotkey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "QuicksaveKey", new KeyboardShortcut((KeyCode)286, Array.Empty<KeyCode>()), "Hotkey that triggers a save. Any UnityEngine KeyCode works (F5, F9, K...). Modifiers supported, e.g. 'K + LeftControl'.");
		compressed = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "CompressedSave", true, "Save in compressed format (same as the game's autosave). Leave true unless you have a reason not to.");
		showMessage = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowOnScreenMessage", true, "Show a brief on-screen confirmation when quicksaving.");
		((BaseUnityPlugin)this).Logger.LogInfo((object)string.Concat("QuickSave loaded. Press ", hotkey.Value, " to save."));
	}

	private void Update()
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		if (messageTimer > 0f)
		{
			messageTimer -= Time.deltaTime;
		}
		KeyboardShortcut value = hotkey.Value;
		if (((KeyboardShortcut)(ref value)).IsDown())
		{
			TrySave();
		}
	}

	private void TrySave()
	{
		SaveLoadManager instance = SaveLoadManager.instance;
		if ((Object)(object)instance == (Object)null || !SaveLoadManager.readyToSave)
		{
			Show("Can't save right now (still loading)");
			return;
		}
		if (GameState.sleeping || GameState.recovering)
		{
			Show("Can't save while sleeping");
			return;
		}
		if (Object.op_Implicit((Object)(object)GameState.inBed))
		{
			Show("Can't save while in bed");
			return;
		}
		if (Object.op_Implicit((Object)(object)GameState.currentShipyard))
		{
			Show("Can't save at the shipyard");
			return;
		}
		instance.SaveGame(compressed.Value);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Quicksave triggered.");
		Show("Game saved");
	}

	private void Show(string msg)
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)msg);
		if (showMessage.Value)
		{
			message = msg;
			messageTimer = 2.5f;
		}
	}

	private void OnGUI()
	{
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected O, but got Unknown
		if (!(messageTimer <= 0f))
		{
			if (style == null)
			{
				style = new GUIStyle();
				style.fontSize = 22;
				style.fontStyle = (FontStyle)1;
				style.alignment = (TextAnchor)4;
			}
			float num = Mathf.Clamp01(messageTimer / 0.5f);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(0f, (float)Screen.height * 0.08f, (float)Screen.width, 30f);
			style.normal.textColor = new Color(0f, 0f, 0f, 0.75f * num);
			GUI.Label(new Rect(((Rect)(ref val)).x + 1f, ((Rect)(ref val)).y + 1f, ((Rect)(ref val)).width, ((Rect)(ref val)).height), message, style);
			style.normal.textColor = new Color(1f, 0.95f, 0.75f, num);
			GUI.Label(val, message, style);
		}
	}
}