Decompiled source of GordionVoidRescue v1.3.2

BepInEx/plugins/GordionVoidRescue/GordionRescue.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("GordionRescue")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GordionRescue")]
[assembly: AssemblyTitle("GordionRescue")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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;
		}
	}
}
[BepInPlugin("POTATOH.GordionVoidRescue", "Gordion Void Rescue", "1.3.2")]
public class GordionVoidRescue : BaseUnityPlugin
{
	[HarmonyPatch(typeof(PlayerControllerB), "KillPlayer")]
	private static class KillPlayerPatch
	{
		private static readonly Dictionary<ulong, float> Cooldowns = new Dictionary<ulong, float>();

		private static bool Prefix(PlayerControllerB __instance)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)NetworkManager.Singleton == (Object)null || !NetworkManager.Singleton.IsServer)
			{
				return true;
			}
			if ((Object)(object)__instance == (Object)null)
			{
				return true;
			}
			if (__instance.isPlayerDead)
			{
				return true;
			}
			if (!__instance.isPlayerControlled)
			{
				return true;
			}
			if (OnlyOnGordion.Value && !IsCompanyOrGordion())
			{
				return true;
			}
			float y = ((Component)__instance).transform.position.y;
			if (y >= YThreshold.Value)
			{
				return true;
			}
			ulong actualClientId = __instance.actualClientId;
			float time = Time.time;
			if (Cooldowns.TryGetValue(actualClientId, out var value) && time < value)
			{
				return true;
			}
			RescueToShip(__instance);
			Cooldowns[actualClientId] = time + CooldownSeconds.Value;
			if (DebugLog.Value && (Object)(object)Instance != (Object)null)
			{
				((BaseUnityPlugin)Instance).Logger.LogInfo((object)$"[KillRescue] prevented death for {__instance.playerUsername} at y={y:F1}");
			}
			return false;
		}
	}

	[HarmonyPatch(typeof(PlayerControllerB), "TeleportPlayer")]
	private static class TeleportWakePatch
	{
		private static void Postfix(PlayerControllerB __instance)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance == (Object)null) && ((NetworkBehaviour)__instance).IsOwner && !((Object)(object)__instance.thisController == (Object)null))
			{
				__instance.thisController.Move(Vector3.down * 0.2f);
			}
		}
	}

	internal static GordionVoidRescue Instance;

	private static ConfigEntry<float> YThreshold;

	private static ConfigEntry<bool> OnlyOnGordion;

	private static ConfigEntry<float> CooldownSeconds;

	private static ConfigEntry<bool> DebugLog;

	private static ConfigEntry<float> ShipX;

	private static ConfigEntry<float> ShipY;

	private static ConfigEntry<float> ShipZ;

	private void Awake()
	{
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		YThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("General", "YThreshold", -17f, "If a player is about to die while below this Y, rescue them instead.");
		OnlyOnGordion = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "OnlyOnGordion", true, "If true, only rescue on Company/Gordion.");
		CooldownSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("General", "CooldownSeconds", 2f, "Cooldown between rescues per player (seconds).");
		DebugLog = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DebugLog", false, "If true, logs rescues to LogOutput.log.");
		ShipX = ((BaseUnityPlugin)this).Config.Bind<float>("Ship", "ShipX", -8f, "Ship teleport X (Gordion).");
		ShipY = ((BaseUnityPlugin)this).Config.Bind<float>("Ship", "ShipY", 0f, "Ship teleport Y (Gordion).");
		ShipZ = ((BaseUnityPlugin)this).Config.Bind<float>("Ship", "ShipZ", -14f, "Ship teleport Z (Gordion).");
		new Harmony("POTATOH.GordionVoidRescue").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"GVR 1.3.2 loaded. YThreshold={YThreshold.Value}, OnlyOnGordion={OnlyOnGordion.Value}, ShipPos=({ShipX.Value},{ShipY.Value},{ShipZ.Value})");
	}

	private static bool IsCompanyOrGordion()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		Scene activeScene = SceneManager.GetActiveScene();
		if (((Scene)(ref activeScene)).name.ToLowerInvariant().Contains("company"))
		{
			return true;
		}
		SelectableLevel val = StartOfRound.Instance?.currentLevel;
		if ((Object)(object)val == (Object)null)
		{
			return true;
		}
		string text = (val.PlanetName ?? "").ToLowerInvariant();
		if (!text.Contains("gordion"))
		{
			return text.Contains("company");
		}
		return true;
	}

	private static Vector3 GetShipPos()
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		return new Vector3(ShipX.Value, ShipY.Value, ShipZ.Value);
	}

	private static void RescueToShip(PlayerControllerB p)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		Vector3 shipPos = GetShipPos();
		p.isInsideFactory = false;
		try
		{
			p.TeleportPlayer(shipPos, true, 0f, false, true);
		}
		catch
		{
		}
	}
}