Decompiled source of UltraStrafe v1.2.0

UltraStrafe.dll

Decompiled 5 days ago
using System;
using System.Collections.Generic;
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.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("UltraStrafe")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+2824f43aaf0413ef507aaaf2f0e056c213bd52b8")]
[assembly: AssemblyProduct("UltraStrafe")]
[assembly: AssemblyTitle("UltraStrafe")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.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 class ConfigManager
	{
		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 static ConfigEntry<bool> sv_autobhop;

		internal static ConfigEntry<float> sv_jumppower;

		internal ConfigFile Config;

		public Dictionary<string, ConfigEntryBase> Cvars;

		public ConfigManager(ConfigFile config)
		{
			Config = config;
			Cvars = new Dictionary<string, ConfigEntryBase>
			{
				{
					"sv_accelerate",
					(ConfigEntryBase)(object)sv_accelerate
				},
				{
					"sv_maxspeed",
					(ConfigEntryBase)(object)sv_maxspeed
				},
				{
					"sv_maxfrictionlessframes",
					(ConfigEntryBase)(object)sv_maxfrictionlessframes
				},
				{
					"sv_acceltweak",
					(ConfigEntryBase)(object)sv_acceltweak
				},
				{
					"sv_switchspeed",
					(ConfigEntryBase)(object)sv_switchspeed
				},
				{
					"sv_autobhop",
					(ConfigEntryBase)(object)sv_autobhop
				},
				{
					"sv_jumppower",
					(ConfigEntryBase)(object)sv_jumppower
				}
			};
			base..ctor();
		}

		public void Reload()
		{
			sv_accelerate = Config.Bind<float>("Cvars", "sv_accelerate", 70f, "The (base) acceleration value for the strafe movement, affecting the turn radius.");
			sv_maxspeed = Config.Bind<float>("Cvars", "sv_maxspeed", 0f, "The maximum speed value for the strafe movement. Set to 0 for no maximum");
			sv_jumppower = Config.Bind<float>("Cvars", "sv_jumppower", 90f, "The jump power for jumping (note that this affects all jumps, not just bhops.");
			sv_maxfrictionlessframes = 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 = Config.Bind<bool>("Cvars", "sv_acceltweak", true, "Enable this to make sv_accelerate increase based on your speed");
			sv_switchspeed = 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.");
			sv_autobhop = Config.Bind<bool>("Cvars", "sv_autobhop", false, "Enable this to make the game automatically jump while holding jump, without any need to release the jump key");
		}
	}
	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 = ConfigManager.sv_autobhop.Value;
				__instance.Jump();
			}
		}
	}
	[HarmonyPatch(typeof(NewMovement))]
	public class MovementPatcher
	{
		[HarmonyPatch("Move")]
		[HarmonyPrefix]
		private static bool MovePrefix(NewMovement __instance)
		{
			QuakeMovement.NewMove(__instance);
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("Update")]
		private static void UpdatePrefix(NewMovement __instance)
		{
			JumpBuffer.JumpBufferCheck(__instance);
		}

		[HarmonyPrefix]
		[HarmonyPatch("Jump")]
		private static void JumpPrefix(NewMovement __instance)
		{
			__instance.jumpPower = ConfigManager.sv_jumppower.Value;
		}
	}
	[BepInPlugin("com.10-days-till-xmas.ultrastrafe", "UltraStrafe", "1.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		internal static ConfigManager ConfigManager;

		internal void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin UltraStrafe is loaded! :3");
			ConfigManager = new ConfigManager(((BaseUnityPlugin)this).Config);
			ConfigManager.Reload();
			DoPatching();
		}

		private static void DoPatching()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			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 static class QuakeMovement
	{
		private static float wishspeed;

		private static int frictionlessFrames = 0;

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

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

		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 = ConfigManager.sv_accelerate.Value;

		public static float sv_maxspeed = ConfigManager.sv_maxspeed.Value;

		public static int sv_maxfrictionlessframes = ConfigManager.sv_maxfrictionlessframes.Value;

		public static float sv_switchspeed = ConfigManager.sv_switchspeed.Value;

		public static bool sv_acceltweak = ConfigManager.sv_acceltweak.Value;

		private static void NewGroundMove(NewMovement __instance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: 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)
			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));
		}

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

		private static void QuakeAirMove(NewMovement __instance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = new Vector2(__instance.rb.velocity.x, __instance.rb.velocity.z);
			float magnitude = ((Vector2)(ref val)).magnitude;
			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 && sv_maxspeed != 0f)
			{
				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 * (sv_acceltweak ? NewAcceleration(magnitude) : sv_accelerate);
				if (num3 > num2)
				{
					num3 = num2;
				}
				Rigidbody rb = __instance.rb;
				rb.velocity += num3 * val2;
			}
		}

		private static void NewAirMove(NewMovement __instance)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: 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);
			if (((Vector2)(ref val)).magnitude > sv_switchspeed)
			{
				QuakeAirMove(__instance);
				return;
			}
			float num = (__instance.slowMode ? 1.25f : 2.75f);
			movementDirection2Ref.Invoke(__instance) = new Vector3(movementDirectionRef.Invoke(__instance).x * __instance.walkSpeed * Time.deltaTime * num, __instance.rb.velocity.y, movementDirectionRef.Invoke(__instance).z * __instance.walkSpeed * Time.deltaTime * num);
			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 static void NewMove(NewMovement __instance)
		{
			slideEndingRef.Invoke(__instance) = false;
			if (hurtInvincibilityRef.Invoke(__instance) <= 0f && !__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(__instance);
				}
				else
				{
					frictionlessFrames--;
				}
			}
			else
			{
				NewAirMove(__instance);
				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.2.0";
	}
}