Decompiled source of SavePoint v1.0.2

BepInEx/plugins/SavePoint.dll

Decompiled 2 days ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Photon.Pun;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("SavePoint")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SavePoint")]
[assembly: AssemblyTitle("SavePoint")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.peak.savepoint", "SavePoint", "1.0.0")]
public class SavePoint : BaseUnityPlugin
{
	private ConfigEntry<KeyCode> saveKey;

	private ConfigEntry<KeyCode> teleportKey;

	private ConfigEntry<KeyCode> returnKey;

	private Vector3 savedPosition;

	private string savedSceneName;

	private bool hasSavedPosition = false;

	private Vector3 lastKnownPosition;

	private string lastKnownSceneName;

	private bool hasLastKnownPosition = false;

	private float teleportCooldownSeconds = 1f;

	private float lastTeleportTime = -999f;

	private float lastReturnTime = -999f;

	private void Awake()
	{
		saveKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "SaveLocationKey", (KeyCode)286, "Key to save current location");
		teleportKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "TeleportKey", (KeyCode)287, "Key to teleport to saved location");
		returnKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ReturnKey", (KeyCode)288, "Key to return to position before last teleport");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"SavePoint loaded. F5 = Save, F6 = Teleport, F7 = Return.");
	}

	private void Update()
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_030d: Unknown result type (might be due to invalid IL or missing references)
		Character localCharacter = Character.localCharacter;
		if ((Object)(object)localCharacter == (Object)null || (Object)(object)((MonoBehaviourPun)localCharacter).photonView == (Object)null)
		{
			return;
		}
		Scene scene = ((Component)localCharacter).gameObject.scene;
		string name = ((Scene)(ref scene)).name;
		if (Input.GetKeyDown(saveKey.Value))
		{
			savedPosition = localCharacter.Head;
			savedSceneName = name;
			hasSavedPosition = true;
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Saved position: {savedPosition} in scene: {savedSceneName}");
		}
		if (Input.GetKeyDown(teleportKey.Value))
		{
			if (Time.time - lastTeleportTime < teleportCooldownSeconds)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Teleport blocked: Cooldown active.");
				return;
			}
			if (!hasSavedPosition)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Teleport failed: No saved position found.");
				return;
			}
			if (name != savedSceneName)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Teleport blocked: scene mismatch (saved: " + savedSceneName + ", current: " + name + ")"));
				return;
			}
			lastKnownPosition = localCharacter.Head;
			lastKnownSceneName = name;
			hasLastKnownPosition = true;
			lastTeleportTime = Time.time;
			Vector3 val = savedPosition + new Vector3(0f, 0.1f, 0f);
			((MonoBehaviourPun)localCharacter).photonView.RPC("WarpPlayerRPC", (RpcTarget)0, new object[2] { val, true });
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Teleported to saved position: {val}");
		}
		if (Input.GetKeyDown(returnKey.Value))
		{
			if (Time.time - lastReturnTime < teleportCooldownSeconds)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Return blocked: Cooldown active.");
			}
			else if (!hasLastKnownPosition)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Return failed: No previous location recorded.");
			}
			else if (name != lastKnownSceneName)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Return blocked: scene mismatch (last known: " + lastKnownSceneName + ", current: " + name + ")"));
			}
			else
			{
				lastReturnTime = Time.time;
				Vector3 val2 = lastKnownPosition + new Vector3(0f, 0.1f, 0f);
				((MonoBehaviourPun)localCharacter).photonView.RPC("WarpPlayerRPC", (RpcTarget)0, new object[2] { val2, true });
				((BaseUnityPlugin)this).Logger.LogInfo((object)$"Returned to last known position: {val2}");
			}
		}
	}
}