Decompiled source of RegresoAlCadaver v1.0.0

BepInEx/plugins/RegresoAlCadaver/RegresoAlCadaver.dll

Decompiled 19 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
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("RegresoAlCadaver")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RegresoAlCadaver")]
[assembly: AssemblyTitle("RegresoAlCadaver")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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 RegresoAlCadaver
{
	[BepInPlugin("altairfernando.regresoalcadaver", "RegresoAlCadaver", "1.0.0")]
	public class RegresoAlCadaverPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "altairfernando.regresoalcadaver";

		public const string PluginName = "RegresoAlCadaver";

		public const string PluginVersion = "1.0.0";

		internal const int SegundosMinimos = 0;

		internal const int SegundosMaximos = 60;

		internal static RegresoAlCadaverPlugin Instancia;

		private ConfigEntry<bool> _activo;

		private ConfigEntry<KeyboardShortcut> _tecla;

		private ConfigEntry<int> _segundosInvulnerable;

		private ConfigEntry<bool> _avisarAlMorir;

		internal bool Activo
		{
			get
			{
				if (_activo != null)
				{
					return _activo.Value;
				}
				return false;
			}
		}

		internal bool AvisarAlMorir
		{
			get
			{
				if (_avisarAlMorir != null)
				{
					return _avisarAlMorir.Value;
				}
				return false;
			}
		}

		internal KeyboardShortcut Tecla
		{
			get
			{
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				if (_tecla == null)
				{
					return new KeyboardShortcut((KeyCode)290, Array.Empty<KeyCode>());
				}
				return _tecla.Value;
			}
		}

		internal int SegundosInvulnerable
		{
			get
			{
				if (_segundosInvulnerable == null)
				{
					return 10;
				}
				return _segundosInvulnerable.Value;
			}
		}

		private void Awake()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			Instancia = this;
			_activo = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - Regreso", "PermitirRegreso", true, "Te devuelve al sitio donde moriste, una sola vez por muerte.");
			_tecla = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("1 - Regreso", "Tecla", new KeyboardShortcut((KeyCode)290, Array.Empty<KeyCode>()), "Tecla del viaje. No responde mientras escribes en el chat ni con un menu abierto.");
			_segundosInvulnerable = ((BaseUnityPlugin)this).Config.Bind<int>("1 - Regreso", "SegundosInvulnerable", 10, new ConfigDescription("Cuanto aguantas sin recibir daño al llegar. Cuenta desde que aterrizas, no desde que pulsas: el viaje carga la zona y se comeria el regalo. Con 0 no hay proteccion.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 60), Array.Empty<object>()));
			_avisarAlMorir = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Aviso", "AvisarAlMorir", true, "Al reaparecer te recuerda en pantalla que tecla te lleva de vuelta.");
			new Harmony("altairfernando.regresoalcadaver").PatchAll(Assembly.GetExecutingAssembly());
			((BaseUnityPlugin)this).Logger.LogInfo((object)"RegresoAlCadaver 1.0.0 cargado.");
		}

		private void Update()
		{
			Regreso.Comprobar();
		}
	}
	internal static class Regreso
	{
		private const float RetrasoAviso = 2f;

		private static Vector3 _puntoGastado;

		private static bool _hayGastado;

		private static bool _esperandoLlegada;

		private static float _invulnerableHasta;

		private static bool _avisoPendiente;

		private static float _momentoAviso;

		internal static bool Invulnerable => Time.time < _invulnerableHasta;

		internal static void Murio()
		{
			_avisoPendiente = true;
			_momentoAviso = 0f;
		}

		internal static void Comprobar()
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			RegresoAlCadaverPlugin instancia = RegresoAlCadaverPlugin.Instancia;
			if ((Object)(object)instancia == (Object)null || !instancia.Activo)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				_esperandoLlegada = false;
				return;
			}
			if (_esperandoLlegada && !((Character)localPlayer).IsTeleporting())
			{
				_esperandoLlegada = false;
				Proteger(instancia.SegundosInvulnerable);
			}
			if (_avisoPendiente && !((Character)localPlayer).IsDead())
			{
				Avisar(instancia);
			}
			KeyboardShortcut tecla = instancia.Tecla;
			if (((KeyboardShortcut)(ref tecla)).IsDown() && !EscribiendoEnAlgo())
			{
				Intentar(localPlayer);
			}
		}

		private static void Proteger(int segundos)
		{
			if (segundos > 0)
			{
				_invulnerableHasta = Time.time + (float)segundos;
				Mensaje("Sin recibir daño " + segundos + " s: recoge tus cosas");
			}
		}

		private static void Avisar(RegresoAlCadaverPlugin plugin)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			if (_momentoAviso <= 0f)
			{
				_momentoAviso = Time.time + 2f;
			}
			else if (!(Time.time < _momentoAviso))
			{
				_avisoPendiente = false;
				if (plugin.AvisarAlMorir)
				{
					Mensaje("Pulsa " + ((object)plugin.Tecla/*cast due to .constrained prefix*/).ToString() + " para volver a tu cadáver");
				}
			}
		}

		private static void Intentar(Player jugador)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			if (((Character)jugador).IsDead() || ((Character)jugador).IsTeleporting())
			{
				return;
			}
			Game instance = Game.instance;
			PlayerProfile val = (((Object)(object)instance != (Object)null) ? instance.GetPlayerProfile() : null);
			if (val == null || !val.HaveDeathPoint())
			{
				Mensaje("No hay ningún cadáver al que volver");
				return;
			}
			Vector3 deathPoint = val.GetDeathPoint();
			if (_hayGastado && _puntoGastado == deathPoint)
			{
				Mensaje("Ya volviste a este cadáver");
				return;
			}
			if (!((Character)jugador).TeleportTo(deathPoint, ((Component)jugador).transform.rotation, true))
			{
				Mensaje("Ahora mismo no puedes viajar");
				return;
			}
			_puntoGastado = deathPoint;
			_hayGastado = true;
			_esperandoLlegada = true;
		}

		private static bool EscribiendoEnAlgo()
		{
			if (!Menu.IsVisible() && !TextInput.IsVisible())
			{
				if ((Object)(object)Chat.instance != (Object)null)
				{
					return Chat.instance.HasFocus();
				}
				return false;
			}
			return true;
		}

		private static void Mensaje(string texto)
		{
			MessageHud instance = MessageHud.instance;
			if ((Object)(object)instance != (Object)null && !string.IsNullOrEmpty(texto))
			{
				instance.ShowMessage((MessageType)2, texto, 0, (Sprite)null, false, false);
			}
		}
	}
	[HarmonyPatch(typeof(Player), "OnDeath")]
	internal static class ParcheAvisoAlMorir
	{
		private static void Postfix(Player __instance)
		{
			if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				Regreso.Murio();
			}
		}
	}
	[HarmonyPatch(typeof(Character), "Damage")]
	internal static class ParcheInvulnerableAlLlegar
	{
		private static bool Prefix(Character __instance)
		{
			if (Regreso.Invulnerable)
			{
				return (Object)(object)__instance != (Object)(object)Player.m_localPlayer;
			}
			return true;
		}
	}
}