Decompiled source of QuickPortal v1.0.0

QuickPortal.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace QuickPortal;

[BepInPlugin("com.burks.quickportal", "Quick Portal", "1.0.0")]
public class QuickPortalPlugin : BaseUnityPlugin
{
	public const string GUID = "com.burks.quickportal";

	public const string NAME = "Quick Portal";

	public const string VERSION = "1.0.0";

	public static ConfigEntry<float> MoveAfter;

	public static ConfigEntry<float> MinTotal;

	private void Awake()
	{
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Invalid comparison between Unknown and I4
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		MoveAfter = ((BaseUnityPlugin)this).Config.Bind<float>("Teleport", "MoveAfterSeconds", 1f, "Seconds of fade before you are moved (the game's own is 2). Below 1 the move can happen before the screen is fully black.");
		MinTotal = ((BaseUnityPlugin)this).Config.Bind<float>("Teleport", "MinimumSeconds", 2.5f, "Shortest total time of a long-distance teleport (the game's own is 8). It still waits until the destination is loaded.");
		if ((int)SystemInfo.graphicsDeviceType != 4)
		{
			new Harmony("com.burks.quickportal").PatchAll(Assembly.GetExecutingAssembly());
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Quick Portal 1.0.0 loaded.");
		}
	}
}
[HarmonyPatch(typeof(Player), "UpdateTeleport")]
public static class TeleportPatch
{
	private static readonly FieldRef<Player, bool> Teleporting = AccessTools.FieldRefAccess<Player, bool>("m_teleporting");

	private static readonly FieldRef<Player, bool> Distant = AccessTools.FieldRefAccess<Player, bool>("m_distantTeleport");

	private static readonly FieldRef<Player, float> Timer = AccessTools.FieldRefAccess<Player, float>("m_teleportTimer");

	private const float GameMove = 2f;

	private const float GameMin = 8f;

	[HarmonyPrefix]
	public static void Prefix(Player __instance, float dt)
	{
		try
		{
			if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && Teleporting.Invoke(__instance) && !(dt <= 0f))
			{
				float num = Mathf.Clamp(QuickPortalPlugin.MoveAfter.Value, 0.25f, 2f);
				float num2 = Mathf.Clamp(QuickPortalPlugin.MinTotal.Value, num + 0.25f, 8f);
				float num3 = Timer.Invoke(__instance);
				float num4 = 0f;
				if (num3 < 2f)
				{
					num4 = Mathf.Min(dt * (2f / num - 1f), Mathf.Max(0f, 2f - num3 - dt));
				}
				else if (num3 < 8f && Distant.Invoke(__instance))
				{
					num4 = Mathf.Min(dt * (6f / (num2 - num) - 1f), Mathf.Max(0f, 8f - num3 - dt));
				}
				if (num4 > 0f)
				{
					Timer.Invoke(__instance) = num3 + num4;
				}
			}
		}
		catch (Exception)
		{
		}
	}
}