Decompiled source of NadoRapido v1.0.0

NadoRapido.dll

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

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace NadoFundo;

[BepInPlugin("yuri.NadoRapido", "Nado Rapido", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public static ConfigEntry<bool> Ligado;

	public static ConfigEntry<bool> Mergulho;

	public static ConfigEntry<float> VelocidadeMin;

	public static ConfigEntry<float> VelocidadeMax;

	public static ConfigEntry<float> GastoMin;

	public static ConfigEntry<float> GastoMax;

	public static ConfigEntry<float> Regen;

	public static ConfigEntry<float> Exp;

	public static ConfigEntry<float> Dano;

	public static ConfigEntry<float> Nevoa;

	public static ConfigEntry<float> Brilho;

	public static float FatorNado(Player jogador)
	{
		float num = ((Character)jogador).GetSkillLevel((SkillType)103);
		if (num < 0f)
		{
			num = 0f;
		}
		if (num > 100f)
		{
			num = 100f;
		}
		return num / 100f;
	}

	private void Awake()
	{
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		Ligado = ((BaseUnityPlugin)this).Config.Bind<bool>("Geral", "Ligado", true, "Liga o mod so neste jogo. Nao precisa do servidor.");
		Mergulho = ((BaseUnityPlugin)this).Config.Bind<bool>("Mergulho", "Ligado", true, "Segura Ctrl e W dentro da agua e olha com o mouse para descer ou subir.");
		VelocidadeMin = ((BaseUnityPlugin)this).Config.Bind<float>("Nado", "VelocidadeMin", 2f, "Velocidade com a habilidade Nado em zero.");
		VelocidadeMax = ((BaseUnityPlugin)this).Config.Bind<float>("Nado", "VelocidadeMax", 7f, "Velocidade com a habilidade Nado em 100. Sobe junto com o nivel.");
		GastoMin = ((BaseUnityPlugin)this).Config.Bind<float>("Folego", "GastoNoInicio", 14f, "Quanto gasta de stamina nadando com pouca habilidade.");
		GastoMax = ((BaseUnityPlugin)this).Config.Bind<float>("Folego", "GastoNoMaximo", 4f, "Quanto gasta de stamina nadando com a habilidade no maximo.");
		Regen = ((BaseUnityPlugin)this).Config.Bind<float>("Folego", "RegenParado", 8f, "Stamina por segundo parado na agua, no nivel maximo de Nado.");
		Exp = ((BaseUnityPlugin)this).Config.Bind<float>("Nado", "Exp", 1f, "Multiplica a experiencia da habilidade Nado. 1 e o normal do jogo.");
		Dano = ((BaseUnityPlugin)this).Config.Bind<float>("Mergulho", "DanoSemFolego", 10f, "Dano por segundo debaixo da agua sem stamina.");
		Nevoa = ((BaseUnityPlugin)this).Config.Bind<float>("Agua", "Nevoa", 0.08f, "Nevoa debaixo da agua. 0 desliga.");
		Brilho = ((BaseUnityPlugin)this).Config.Bind<float>("Agua", "Brilho", 0.45f, "Clareza da agua. 0 fica escuro, 1 fica claro.");
		new Harmony("yuri.NadoRapido").PatchAll();
	}
}
[HarmonyPatch(typeof(Player), "RaiseSkill")]
public static class ExpPatch
{
	private static void Prefix(Player __instance, SkillType skill, ref float value)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Invalid comparison between Unknown and I4
		if (Plugin.Ligado.Value && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && (int)skill == 103)
		{
			value *= Plugin.Exp.Value;
		}
	}
}
[HarmonyPatch(typeof(Character), "UpdateSwimming")]
public static class VelocidadePatch
{
	private static void Prefix(Character __instance)
	{
		Player val = (Player)(object)((__instance is Player) ? __instance : null);
		if (!((Object)(object)val == (Object)null) && !((Object)(object)val != (Object)(object)Player.m_localPlayer) && Plugin.Ligado.Value)
		{
			float num = Plugin.FatorNado(val);
			((Character)val).m_swimSpeed = Mathf.Lerp(Plugin.VelocidadeMin.Value, Plugin.VelocidadeMax.Value, num);
			val.m_swimStaminaDrainMinSkill = Plugin.GastoMin.Value;
			val.m_swimStaminaDrainMaxSkill = Plugin.GastoMax.Value;
		}
	}
}
[HarmonyPatch(typeof(Player), "LateUpdate")]
public static class MergulhoPatch
{
	private static float profundidade;

	private static bool nevoaAtiva;

	private static bool fogLigado;

	private static int modo;

	private static float densidade;

	private static Color cor;

	private static void Postfix(Player __instance)
	{
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
		{
			return;
		}
		if (!Plugin.Ligado.Value || !((Character)__instance).IsSwimming())
		{
			profundidade = 0f;
			RestaurarNevoa();
			return;
		}
		float num = Plugin.FatorNado(__instance);
		float num2 = Mathf.Lerp(Plugin.GastoMin.Value, Plugin.GastoMax.Value, num);
		bool flag = Tecla((KeyCode)306) || Tecla((KeyCode)305);
		bool flag2 = Tecla((KeyCode)119) || Tecla((KeyCode)273);
		bool flag3 = Tecla((KeyCode)32);
		if (Plugin.Mergulho.Value && flag && flag2)
		{
			profundidade -= ((Character)__instance).GetLookDir().y * ((Character)__instance).m_swimSpeed * Time.deltaTime;
		}
		if (flag3)
		{
			profundidade = Mathf.MoveTowards(profundidade, 0f, ((Character)__instance).m_swimSpeed * 3f * Time.deltaTime);
		}
		if (profundidade < 0f)
		{
			profundidade = 0f;
		}
		if (profundidade > 40f)
		{
			profundidade = 40f;
		}
		if (profundidade > 0.05f)
		{
			Vector3 position = ((Component)__instance).transform.position;
			position.y -= profundidade;
			((Component)__instance).transform.position = position;
		}
		if (profundidade > 0.6f)
		{
			((Character)__instance).UseStamina(num2 * Time.deltaTime);
			if (__instance.GetStamina() <= 0.5f && Plugin.Dano.Value > 0f)
			{
				float num3 = ((Character)__instance).GetHealth() - Plugin.Dano.Value * Time.deltaTime;
				if (num3 < 0f)
				{
					num3 = 0f;
				}
				((Character)__instance).SetHealth(num3);
			}
			AplicarNevoa();
		}
		else
		{
			RestaurarNevoa();
			Vector3 velocity = ((Character)__instance).GetVelocity();
			if (((Vector3)(ref velocity)).magnitude < 0.35f && Plugin.Regen.Value > 0f)
			{
				((Character)__instance).AddStamina(Plugin.Regen.Value * num * Time.deltaTime);
			}
		}
	}

	private static bool Tecla(KeyCode tecla)
	{
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		Type type = Type.GetType("UnityEngine.Input, UnityEngine.InputLegacyModule");
		if (type == null)
		{
			return false;
		}
		MethodInfo method = type.GetMethod("GetKey", new Type[1] { typeof(KeyCode) });
		if (method == null)
		{
			return false;
		}
		return (bool)method.Invoke(null, new object[1] { tecla });
	}

	private static void AplicarNevoa()
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		if (!(Plugin.Nevoa.Value <= 0f))
		{
			if (!nevoaAtiva)
			{
				fogLigado = LerBool("fog");
				modo = LerInt("fogMode");
				densidade = LerFloat("fogDensity");
				cor = LerCor("fogColor");
				nevoaAtiva = true;
			}
			float num = Plugin.Brilho.Value;
			if (num < 0.05f)
			{
				num = 0.05f;
			}
			Escrever("fog", true);
			Escrever("fogMode", 2);
			Escrever("fogDensity", Plugin.Nevoa.Value);
			Escrever("fogColor", (object)new Color(0.04f * num, 0.16f * num, 0.28f * num, 1f));
		}
	}

	private static void RestaurarNevoa()
	{
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		if (nevoaAtiva)
		{
			Escrever("fog", fogLigado);
			Escrever("fogMode", modo);
			Escrever("fogDensity", densidade);
			Escrever("fogColor", cor);
			nevoaAtiva = false;
		}
	}

	private static Type TipoCena()
	{
		return Type.GetType("UnityEngine.RenderSettings, UnityEngine.CoreModule");
	}

	private static void Escrever(string nome, object valor)
	{
		Type type = TipoCena();
		if (type == null)
		{
			return;
		}
		PropertyInfo property = type.GetProperty(nome);
		if (!(property == null))
		{
			if (nome == "fogMode")
			{
				valor = Enum.ToObject(property.PropertyType, valor);
			}
			property.SetValue(null, valor, null);
		}
	}

	private static bool LerBool(string nome)
	{
		object obj = Ler(nome);
		if (obj is bool)
		{
			return (bool)obj;
		}
		return false;
	}

	private static int LerInt(string nome)
	{
		object obj = Ler(nome);
		if (obj == null)
		{
			return 2;
		}
		return Convert.ToInt32(obj);
	}

	private static float LerFloat(string nome)
	{
		object obj = Ler(nome);
		if (obj == null)
		{
			return 0f;
		}
		return Convert.ToSingle(obj);
	}

	private static Color LerCor(string nome)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		object obj = Ler(nome);
		if (obj is Color)
		{
			return (Color)obj;
		}
		return Color.gray;
	}

	private static object Ler(string nome)
	{
		Type type = TipoCena();
		if (type == null)
		{
			return null;
		}
		PropertyInfo property = type.GetProperty(nome);
		if (property == null)
		{
			return null;
		}
		return property.GetValue(null, null);
	}
}