Decompiled source of Dodge v1.0.0

Dodge.dll

Decompiled 13 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Tolga")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Dodge")]
[assembly: AssemblyTitle("Dodge")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 Dodge
{
	[BepInPlugin("Tolga.Dodge", "Dodge", "1.0")]
	public class Dodge : BaseUnityPlugin
	{
		internal float DodgeTapWindow = 0.25f;

		internal float DodgeCooldown = 0.9f;

		internal float DodgeEnergyCost = 15f;

		internal float DodgeStrengthMultiplier = 2.2f;

		internal float DodgeDuration = 0.3f;

		private float _lastSprintTapTime = -999f;

		private float _dodgeCooldownTimer;

		internal static Dodge Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
			TryHandleDodge();
		}

		private void TryHandleDodge()
		{
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)PlayerController.instance == (Object)null || !Object.op_Implicit((Object)(object)LevelGenerator.Instance) || !LevelGenerator.Instance.Generated || SemiFunc.MenuLevel())
			{
				return;
			}
			PlayerController instance = PlayerController.instance;
			if (_dodgeCooldownTimer > 0f)
			{
				_dodgeCooldownTimer -= Time.deltaTime;
			}
			Vector3 moveInput = default(Vector3);
			((Vector3)(ref moveInput))..ctor(SemiFunc.InputMovementX(), 0f, SemiFunc.InputMovementY());
			bool flag = ((Vector3)(ref moveInput)).sqrMagnitude > 0.01f;
			if (SemiFunc.InputDown((InputKey)15))
			{
				float time = Time.time;
				if (time - _lastSprintTapTime <= DodgeTapWindow && flag && _dodgeCooldownTimer <= 0f)
				{
					TryPerformDodge(instance, moveInput);
					_lastSprintTapTime = -999f;
				}
				else
				{
					_lastSprintTapTime = time;
				}
			}
		}

		private void TryPerformDodge(PlayerController player, Vector3 moveInput)
		{
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			if (player.InputDisableTimer > 0f)
			{
				Logger.LogDebug((object)"Dodge: Input disabled, cannot dodge.");
				return;
			}
			if (!Object.op_Implicit((Object)(object)player.playerAvatarScript) || player.playerAvatarScript.isTumbling)
			{
				Logger.LogDebug((object)"Dodge: Player tumbling or avatar missing, cannot dodge.");
				return;
			}
			if (player.EnergyCurrent < DodgeEnergyCost)
			{
				Logger.LogDebug((object)$"Dodge: Not enough energy ({player.EnergyCurrent:F1} < {DodgeEnergyCost:F1}).");
				return;
			}
			Vector3 val;
			if (((Vector3)(ref moveInput)).sqrMagnitude > 0.01f)
			{
				val = ((Component)player).transform.TransformDirection(((Vector3)(ref moveInput)).normalized);
			}
			else
			{
				Vector3 val2 = (Object.op_Implicit((Object)(object)player.cameraGameObject) ? player.cameraGameObject.transform.forward : ((Component)player).transform.forward);
				val2.y = 0f;
				if (((Vector3)(ref val2)).sqrMagnitude < 0.01f)
				{
					val2 = ((Component)player).transform.forward;
					val2.y = 0f;
				}
				val = ((Vector3)(ref val2)).normalized;
			}
			float num = player.SprintSpeed * DodgeStrengthMultiplier;
			player.MoveForce(val, num, DodgeDuration);
			PlayerTumble tumble = player.playerAvatarScript.tumble;
			if ((Object)(object)tumble != (Object)null)
			{
				tumble.TumbleRequest(true, false);
				float num2 = num;
				tumble.TumbleForce(val * num2);
			}
			else
			{
				Logger.LogDebug((object)"Dodge: Player has no tumble component; skipping roll visual.");
			}
			player.EnergyCurrent = Mathf.Max(0f, player.EnergyCurrent - DodgeEnergyCost);
			_dodgeCooldownTimer = DodgeCooldown;
			Logger.LogDebug((object)$"Dodge: Performed dodge. Dir={val}, Amount={num:F2}, Energy now={player.EnergyCurrent:F1}");
		}
	}
	[HarmonyPatch(typeof(PlayerController))]
	internal static class ExamplePlayerControllerPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("Start")]
		private static void Start_Prefix(PlayerController __instance)
		{
			Dodge.Logger.LogDebug((object)$"{__instance} Start Prefix");
		}

		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void Start_Postfix(PlayerController __instance)
		{
			Dodge.Logger.LogDebug((object)$"{__instance} Start Postfix");
		}
	}
}