Decompiled source of DodgeDirectionalFix v1.0.0

DodgeDirectionalFix.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("DodgeDirectionalFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DodgeDirectionalFix")]
[assembly: AssemblyTitle("DodgeDirectionalFix")]
[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 DodgeDirectionalFix
{
	[BepInPlugin("yourname.dodgedirectionalfix", "Dodge Directional Fix", "1.0.0")]
	public class DodgeDirectionalFixPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "yourname.dodgedirectionalfix";

		public const string PluginName = "Dodge Directional Fix";

		public const string PluginVersion = "1.0.0";

		internal static DodgeDirectionalFixPlugin Instance;

		internal static ManualLogSource Log;

		public static ConfigEntry<bool> EnableMod;

		public static ConfigEntry<KeyCode> DodgeKey;

		public static ConfigEntry<bool> RequireDirectionInput;

		public static ConfigEntry<bool> BlockOnNumberKeys;

		public static ConfigEntry<bool> DebugLog;

		private static readonly KeyCode[] NumberKeys;

		private void Awake()
		{
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			EnableMod = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "EnableMod", true, "Liga/desliga o mod por completo.");
			DodgeKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("1 - General", "DodgeKey", (KeyCode)308, "Tecla que dispara o dodge (junto com uma direcao).");
			RequireDirectionInput = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "RequireDirectionInput", true, "Se ligado, a tecla parado NAO faz nada - so dispara em movimento. Se desligado, parado faz dodge pra frente na direcao que o personagem encara.");
			BlockOnNumberKeys = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "BlockOnNumberKeys", true, "Se ligado, a tecla + qualquer numerica (linha superior ou numpad) nunca dispara dodge - deixa o combo livre pros quick slots mesmo se voce estiver correndo.");
			DebugLog = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Advanced", "DebugLog", false, "Loga cada tentativa de dodge e o motivo de ter sido bloqueada.");
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "yourname.dodgedirectionalfix");
			Log.LogInfo((object)"Dodge Directional Fix v1.0.0 carregado.");
		}

		internal static bool IsAnyNumberKeyHeld()
		{
			for (int i = 0; i < NumberKeys.Length; i++)
			{
				if (Input.GetKey(NumberKeys[i]))
				{
					return true;
				}
			}
			return false;
		}

		static DodgeDirectionalFixPlugin()
		{
			KeyCode[] array = new KeyCode[20];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			NumberKeys = (KeyCode[])(object)array;
		}
	}
	[HarmonyPatch]
	internal static class DodgePatches
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "Update")]
		private static void Player_Update_Prefix(Player __instance)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			if (!DodgeDirectionalFixPlugin.EnableMod.Value)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)__instance != (Object)(object)localPlayer || !Input.GetKeyDown(DodgeDirectionalFixPlugin.DodgeKey.Value) || IsBlocked(localPlayer))
			{
				return;
			}
			if (DodgeDirectionalFixPlugin.BlockOnNumberKeys.Value && DodgeDirectionalFixPlugin.IsAnyNumberKeyHeld())
			{
				DebugLog("Dodge cancelado: tecla numerica pressionada junto.");
				return;
			}
			Vector3 val = Traverse.Create((object)localPlayer).Field("m_moveDir").GetValue<Vector3>();
			val.y = 0f;
			if (((Vector3)(ref val)).magnitude < 0.1f)
			{
				if (DodgeDirectionalFixPlugin.RequireDirectionInput.Value)
				{
					DebugLog("Dodge cancelado: sem direcao de movimento.");
					return;
				}
				val = ((Component)localPlayer).transform.rotation * Vector3.forward;
				val.y = 0f;
			}
			((Vector3)(ref val)).Normalize();
			DebugLog($"Dodge disparado. Direcao: {val}");
			Traverse.Create((object)localPlayer).Method("Dodge", new object[1] { val }).GetValue();
		}

		private static bool IsBlocked(Player player)
		{
			if (((Character)player).IsDead() || ((Character)player).IsTeleporting() || ((Character)player).IsAttachedToShip() || ((Character)player).InPlaceMode() || ((Character)player).InCutscene())
			{
				return true;
			}
			if (Menu.IsVisible() || InventoryGui.IsVisible() || StoreGui.IsVisible() || TextInput.IsVisible())
			{
				return true;
			}
			if ((Object)(object)Chat.instance != (Object)null && (Object)(object)((Terminal)Chat.instance).m_chatWindow != (Object)null && ((Component)((Terminal)Chat.instance).m_chatWindow).gameObject.activeInHierarchy)
			{
				return true;
			}
			if ((Object)(object)Console.instance != (Object)null && (Object)(object)((Terminal)Console.instance).m_chatWindow != (Object)null && ((Component)((Terminal)Console.instance).m_chatWindow).gameObject.activeInHierarchy)
			{
				return true;
			}
			return false;
		}

		private static void DebugLog(string msg)
		{
			if (DodgeDirectionalFixPlugin.DebugLog.Value)
			{
				DodgeDirectionalFixPlugin.Log.LogInfo((object)msg);
			}
		}
	}
}