Decompiled source of UltraStrafe v1.0.2

UltraStrafe.dll

Decompiled 8 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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using HarmonyLib.Tools;
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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("UltraStrafe")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+8fb1f1ecd45524b176db5665289e316bb29a34a3")]
[assembly: AssemblyProduct("UltraStrafe")]
[assembly: AssemblyTitle("UltraStrafe")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace UltraStrafe
{
	internal static class JumpBuffer
	{
		private static bool jumpBuffer = false;

		private static readonly FieldRef<NewMovement, WallCheck> wcRef = AccessTools.FieldRefAccess<NewMovement, WallCheck>("wc");

		private static readonly FieldRef<NewMovement, float> clingFadeRef = AccessTools.FieldRefAccess<NewMovement, float>("clingFade");

		private static readonly FieldRef<NewMovement, bool> jumpCooldownRef = AccessTools.FieldRefAccess<NewMovement, bool>("jumpCooldown");

		private static readonly FieldRef<NewMovement, bool> fallingRef = AccessTools.FieldRefAccess<NewMovement, bool>("falling");

		public static void JumpBufferCheck(NewMovement __instance)
		{
			if (MonoSingleton<InputManager>.Instance.InputSource.Jump.WasPerformedThisFrame)
			{
				jumpBuffer = true;
			}
			if (!GameStateManager.Instance.PlayerInputLocked && jumpBuffer && MonoSingleton<InputManager>.Instance.InputSource.Jump.IsPressed && !jumpCooldownRef.Invoke(__instance) && (!fallingRef.Invoke(__instance) || __instance.gc.canJump || wcRef.Invoke(__instance).CheckForEnemyCols()))
			{
				if (__instance.gc.canJump || wcRef.Invoke(__instance).CheckForEnemyCols())
				{
					__instance.currentWallJumps = 0;
					__instance.rocketJumps = 0;
					__instance.hammerJumps = 0;
					clingFadeRef.Invoke(__instance) = 0f;
					__instance.rocketRides = 0;
				}
				jumpBuffer = false;
				__instance.Jump();
			}
		}
	}
	[HarmonyPatch(typeof(NewMovement))]
	public class MovementPatcher
	{
		[HarmonyPatch(typeof(NewMovement), "Move")]
		[HarmonyPrefix]
		private static bool MovePrefix(NewMovement __instance)
		{
			QuakeMovement quakeMovement = new QuakeMovement(__instance);
			quakeMovement.NewMove();
			return false;
		}

		[HarmonyPatch(typeof(NewMovement), "Update")]
		[HarmonyPrefix]
		private static bool UpdatePrefix(NewMovement __instance)
		{
			JumpBuffer.JumpBufferCheck(__instance);
			return true;
		}
	}
	[BepInPlugin("com.10-days-till-xmas.ultrastrafe", "UltraStrafe", "1.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		internal static ConfigEntry<float> sv_accelerate;

		internal static ConfigEntry<float> sv_maxspeed;

		internal static ConfigEntry<byte> sv_maxfrictionlessframes;

		internal static ConfigEntry<bool> sv_acceltweak;

		internal static ConfigEntry<float> sv_switchspeed;

		internal void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin UltraStrafe is loaded! :3");
			sv_accelerate = ((BaseUnityPlugin)this).Config.Bind<float>("Cvars", "sv_accelerate", 70f, "The (base) acceleration value for the strafe movement, affecting the turn radius");
			sv_maxspeed = ((BaseUnityPlugin)this).Config.Bind<float>("Cvars", "sv_maxspeed", 320000f, "The maximum speed value for the strafe movement");
			sv_maxfrictionlessframes = ((BaseUnityPlugin)this).Config.Bind<byte>("Cvars", "sv_maxfrictionlessframes", (byte)2, "The maximum number of frames that friction is disabled for when landing. A value from 2-4 is recommended depending on your specs with lower framerates having a higher value.");
			sv_acceltweak = ((BaseUnityPlugin)this).Config.Bind<bool>("Cvars", "sv_acceltweak", true, "Enable this to make sv_accelerate increase based on your speed");
			sv_switchspeed = ((BaseUnityPlugin)this).Config.Bind<float>("Cvars", "sv_switchspeed", 16.5f, "The speed at which it switches from ultrakill physics (low speeds) to quake (high speeds). I don't recommend changing unless you know what you're doing.");
			DoPatching();
		}

		private void DoPatching()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			Harmony val = new Harmony("com.10-days-till-xmas.ultrastrafe");
			HarmonyFileLog.Enabled = true;
			val.PatchAll();
			Logger.LogInfo((object)"Patches applied!");
		}

		[HarmonyPostfix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private static void ScoresSubmission(ref bool __result)
		{
			__result = false;
		}
	}
	internal class QuakeMovement
	{
		private readonly NewMovement __instance;

		private float wishspeed;

		private static int frictionlessFrames = 0;

		private static readonly FieldRef<NewMovement, bool> slideEndingRef = AccessTools.FieldRefAccess<NewMovement, bool>("slideEnding");

		private static readonly FieldRef<NewMovement, bool> hurtingRef = AccessTools.FieldRefAccess<NewMovement, bool>("hurting");

		private static readonly FieldRef<NewMovement, Vector3> movementDirectionRef = AccessTools.FieldRefAccess<NewMovement, Vector3>("movementDirection");

		private static readonly FieldRef<NewMovement, Vector3> movementDirection2Ref = AccessTools.FieldRefAccess<NewMovement, Vector3>("movementDirection2");

		private static readonly FieldRef<NewMovement, Vector3> airDirectionRef = AccessTools.FieldRefAccess<NewMovement, Vector3>("airDirection");

		private static readonly FieldRef<NewMovement, float> frictionRef = AccessTools.FieldRefAccess<NewMovement, float>("friction");

		public static float sv_accelerate = Plugin.sv_accelerate.Value;

		public static float sv_maxspeed = Plugin.sv_maxspeed.Value;

		public static int sv_maxfrictionlessframes = Plugin.sv_maxfrictionlessframes.Value;

		public QuakeMovement(NewMovement __instance)
		{
			this.__instance = __instance;
			base..ctor();
		}

		private void NewGroundMove()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: 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_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			float num = __instance.rb.velocity.y;
			if (__instance.slopeCheck.onGround && movementDirectionRef.Invoke(__instance).x == 0f && movementDirectionRef.Invoke(__instance).z == 0f)
			{
				num = 0f;
				__instance.rb.useGravity = false;
			}
			else
			{
				__instance.rb.useGravity = true;
			}
			float num2 = (__instance.slowMode ? 1.25f : 2.75f);
			if (Object.op_Implicit((Object)(object)__instance.groundProperties))
			{
				num2 *= __instance.groundProperties.speedMultiplier;
			}
			float num3 = __instance.walkSpeed * Time.deltaTime * num2;
			movementDirection2Ref.Invoke(__instance) = new Vector3(movementDirectionRef.Invoke(__instance).x * num3, num, movementDirectionRef.Invoke(__instance).z * num3);
			Vector3 val = __instance.pushForce;
			if (Object.op_Implicit((Object)(object)__instance.groundProperties) && __instance.groundProperties.push)
			{
				Vector3 val2 = __instance.groundProperties.pushForce;
				if (__instance.groundProperties.pushDirectionRelative)
				{
					val2 = ((Component)__instance.groundProperties).transform.rotation * val2;
				}
				val += val2;
			}
			__instance.rb.velocity = Vector3.Lerp(__instance.rb.velocity, movementDirection2Ref.Invoke(__instance) + val, 0.25f * frictionRef.Invoke(__instance));
			__instance.anim.SetBool("Run", false);
		}

		private float NewAcceleration(float speed)
		{
			float num = Mathf.Clamp(Mathf.Log(speed - 8.5f, 2f) - 2f, 1f, 10f);
			return sv_accelerate * num;
		}

		private void NewAirMove()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			__instance.rb.useGravity = true;
			Vector2 val = new Vector2(__instance.rb.velocity.x, __instance.rb.velocity.z);
			float magnitude = ((Vector2)(ref val)).magnitude;
			if (magnitude > Plugin.sv_switchspeed.Value)
			{
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(movementDirectionRef.Invoke(__instance).x, 0f, movementDirectionRef.Invoke(__instance).z);
				wishspeed = ((Vector3)(ref val2)).magnitude;
				if (wishspeed > sv_maxspeed)
				{
					val2 *= sv_maxspeed / wishspeed;
					wishspeed = sv_maxspeed;
				}
				float num = Vector3.Dot(__instance.rb.velocity, val2);
				float num2 = wishspeed - num;
				if (!(num2 <= 0f))
				{
					float num3 = Time.deltaTime * wishspeed * (Plugin.sv_acceltweak.Value ? NewAcceleration(magnitude) : sv_accelerate);
					if (num3 > num2)
					{
						num3 = num2;
					}
					Rigidbody rb = __instance.rb;
					rb.velocity += num3 * val2;
				}
			}
			else
			{
				float num4 = (__instance.slowMode ? 1.25f : 2.75f);
				movementDirection2Ref.Invoke(__instance) = new Vector3(movementDirectionRef.Invoke(__instance).x * __instance.walkSpeed * Time.deltaTime * num4, __instance.rb.velocity.y, movementDirectionRef.Invoke(__instance).z * __instance.walkSpeed * Time.deltaTime * num4);
				airDirectionRef.Invoke(__instance).y = 0f;
				if (__instance.rb.velocity.x * movementDirection2Ref.Invoke(__instance).x < Mathf.Pow(movementDirection2Ref.Invoke(__instance).x, 2f))
				{
					airDirectionRef.Invoke(__instance).x = movementDirection2Ref.Invoke(__instance).x;
				}
				else
				{
					airDirectionRef.Invoke(__instance).x = 0f;
				}
				if (__instance.rb.velocity.z * movementDirection2Ref.Invoke(__instance).z < Mathf.Pow(movementDirection2Ref.Invoke(__instance).z, 2f))
				{
					airDirectionRef.Invoke(__instance).z = movementDirection2Ref.Invoke(__instance).z;
				}
				else
				{
					airDirectionRef.Invoke(__instance).z = 0f;
				}
				__instance.rb.AddForce(((Vector3)(ref airDirectionRef.Invoke(__instance))).normalized * __instance.airAcceleration);
			}
		}

		public void NewMove()
		{
			slideEndingRef.Invoke(__instance) = false;
			if (!hurtingRef.Invoke(__instance) && !__instance.levelOver)
			{
				((Component)__instance).gameObject.layer = 2;
				__instance.exploded = false;
			}
			if (__instance.gc.onGround && !__instance.jumping)
			{
				__instance.currentWallJumps = 0;
				__instance.rocketJumps = 0;
				__instance.hammerJumps = 0;
				__instance.rocketRides = 0;
			}
			if (__instance.gc.onGround && frictionRef.Invoke(__instance) > 0f && !__instance.jumping)
			{
				if (frictionlessFrames == 0)
				{
					NewGroundMove();
				}
				else
				{
					frictionlessFrames--;
				}
			}
			else
			{
				NewAirMove();
				frictionlessFrames = sv_maxfrictionlessframes;
			}
		}
	}
	public static class UltraStrafePluginInfo
	{
		public const string PLUGIN_GUID = "com.10-days-till-xmas.ultrastrafe";

		public const string PLUGIN_NAME = "UltraStrafe";

		public const string PLUGIN_VERSION = "1.0.2";
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "UltraStrafe";

		public const string PLUGIN_NAME = "UltraStrafe";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}