Decompiled source of EnhancedMovement v1.1.0

BepInEx/plugins/EnhancedMovement.dll

Decompiled 10 months ago
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
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 Microsoft.CodeAnalysis;
using Pigeon.Movement;
using Unity.Netcode;
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("EnhancedMovement")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.0.0.0")]
[assembly: AssemblyInformationalVersion("0.0.0-alpha.0+873ff3fae4fe7f4415f75c3331915ef3d1a2134f")]
[assembly: AssemblyProduct("EnhancedMovement")]
[assembly: AssemblyTitle("EnhancedMovement")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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;
		}
	}
}
[BepInPlugin("sparroh.enhancedmovement", "EnhancedMovement", "1.1.0")]
public class FreeFireMod : BaseUnityPlugin
{
	public const string PluginGUID = "sparroh.enhancedmovement";

	public const string PluginName = "EnhancedMovement";

	public const string PluginVersion = "1.1.0";

	internal static ManualLogSource Logger;

	private Harmony harmony;

	public static ConfigEntry<bool> enableCanFireWhileSprinting;

	public static ConfigEntry<bool> enableCanFireWhileSliding;

	public static ConfigEntry<bool> enableCanAimWhileSliding;

	public static ConfigEntry<bool> enableCanAimWhileReloading;

	public static ConfigEntry<bool> enableCanAimWhileSprinting;

	public static ConfigEntry<bool> enableWallrunning;

	public static ConfigEntry<bool> enableStrafing;

	public static ConfigEntry<bool> enableWingsuitStrafing;

	private void Awake()
	{
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Expected O, but got Unknown
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Expected O, but got Unknown
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_021b: Expected O, but got Unknown
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0232: Expected O, but got Unknown
		//IL_0284: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Expected O, but got Unknown
		//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d2: Expected O, but got Unknown
		Logger = ((BaseUnityPlugin)this).Logger;
		enableCanFireWhileSprinting = ((BaseUnityPlugin)this).Config.Bind<bool>("Movement Modifications", "CanFireWhileSprinting", true, "Allows firing weapons while sprinting.");
		enableCanFireWhileSliding = ((BaseUnityPlugin)this).Config.Bind<bool>("Movement Modifications", "CanFireWhileSliding", true, "Allows firing weapons while sliding.");
		enableCanAimWhileSliding = ((BaseUnityPlugin)this).Config.Bind<bool>("Movement Modifications", "CanAimWhileSliding", true, "Allows aiming weapons while sliding.");
		enableCanAimWhileReloading = ((BaseUnityPlugin)this).Config.Bind<bool>("Movement Modifications", "CanAimWhileReloading", true, "Allows aiming weapons while reloading.");
		enableCanAimWhileSprinting = ((BaseUnityPlugin)this).Config.Bind<bool>("Movement Modifications", "CanAimWhileSprinting", true, "Allows aiming weapons while sprinting.");
		enableWallrunning = ((BaseUnityPlugin)this).Config.Bind<bool>("Movement Modifications", "Wallrunning", true, "Enables wallrunning ability.");
		enableStrafing = ((BaseUnityPlugin)this).Config.Bind<bool>("Movement Modifications", "Strafing", true, "Enables improved strafing speed.");
		enableWingsuitStrafing = ((BaseUnityPlugin)this).Config.Bind<bool>("Movement Modifications", "WingsuitStrafing", true, "Enables strafing while flying with wingsuit.");
		ConfigFile configFile = ((ConfigEntryBase)enableCanFireWhileSprinting).ConfigFile;
		FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, "sparroh.enhancedmovement.cfg");
		fileSystemWatcher.Changed += delegate
		{
			Logger.LogInfo((object)"Config file changed, reloading");
			configFile.Reload();
		};
		fileSystemWatcher.EnableRaisingEvents = true;
		Harmony val = new Harmony("sparroh.enhancedmovement");
		MethodInfo methodInfo = AccessTools.Method(typeof(Gun), "Setup", new Type[3]
		{
			typeof(Player),
			typeof(PlayerAnimation),
			typeof(IGear)
		}, (Type[])null);
		if (methodInfo == null)
		{
			Logger.LogError((object)"Could not find Gun.Setup method!");
			return;
		}
		HarmonyMethod val2 = new HarmonyMethod(typeof(Patches), "ModifyWeaponPrefix", (Type[])null);
		val.Patch((MethodBase)methodInfo, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo methodInfo2 = AccessTools.Method(typeof(Gun), "OnStartAim", (Type[])null, (Type[])null);
		if (methodInfo2 == null)
		{
			Logger.LogError((object)"Could not find Gun.OnStartAim method!");
			return;
		}
		HarmonyMethod val3 = new HarmonyMethod(typeof(Patches), "OnStartAimPrefix", (Type[])null);
		HarmonyMethod val4 = new HarmonyMethod(typeof(Patches), "OnStartAimPostfix", (Type[])null);
		val.Patch((MethodBase)methodInfo2, val3, val4, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo methodInfo3 = AccessTools.Method(typeof(Gun), "CanAim", (Type[])null, (Type[])null);
		if (methodInfo3 == null)
		{
			Logger.LogError((object)"Could not find Gun.CanAim method!");
			return;
		}
		HarmonyMethod val5 = new HarmonyMethod(typeof(Patches), "CanAimPrefix", (Type[])null);
		val.Patch((MethodBase)methodInfo3, val5, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo methodInfo4 = AccessTools.PropertyGetter(typeof(Player), "EnableWallrun");
		if (!(methodInfo4 == null))
		{
			HarmonyMethod val6 = new HarmonyMethod(typeof(Patches), "EnableWallrunGetPrefix", (Type[])null);
			val.Patch((MethodBase)methodInfo4, val6, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.PatchAll(typeof(StrafingSpeedPatch));
			val.PatchAll(typeof(WingsuitStrafingPatch));
			Logger.LogInfo((object)"EnhancedMovement loaded successfully.");
		}
	}
}
public class ModGunData : MonoBehaviour
{
	public bool CanAimWhileSprinting { get; set; }

	public bool WasSprinting { get; set; }
}
internal static class Patches
{
	private static readonly FieldInfo lockSprintingField = AccessTools.Field(typeof(Gun), "lockSprinting");

	public static void ModifyWeaponPrefix(Gun __instance, IGear prefab)
	{
		ModGunData modGunData = ((Component)__instance).gameObject.AddComponent<ModGunData>();
		ModifyGunBaseStats(prefab, modGunData);
	}

	private static void ModifyGunBaseStats(IGear prefab, ModGunData modGunData)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		if (prefab != null)
		{
			Gun val = (Gun)(object)((prefab is Gun) ? prefab : null);
			if (val != null)
			{
				ref GunData gunData = ref val.GunData;
				gunData.fireConstraints.canFireWhileSprinting = (ActionFireMode)FreeFireMod.enableCanFireWhileSprinting.Value;
				gunData.fireConstraints.canFireWhileSliding = (ActionFireMode)FreeFireMod.enableCanFireWhileSliding.Value;
				gunData.fireConstraints.canAimWhileSliding = (ActionFireMode)FreeFireMod.enableCanAimWhileSliding.Value;
				gunData.fireConstraints.canAimWhileReloading = FreeFireMod.enableCanAimWhileReloading.Value;
				modGunData.CanAimWhileSprinting = FreeFireMod.enableCanAimWhileSprinting.Value;
				bool flag = !FreeFireMod.enableCanAimWhileSprinting.Value;
				lockSprintingField.SetValue(val, flag);
			}
		}
	}

	public static bool OnStartAimPrefix(Gun __instance)
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Expected O, but got Unknown
		ModGunData component = ((Component)__instance).gameObject.GetComponent<ModGunData>();
		if ((Object)(object)component != (Object)null && component.CanAimWhileSprinting)
		{
			Player val = (Player)AccessTools.Field(typeof(Gun), "player").GetValue(__instance);
			if ((Object)(object)val != (Object)null)
			{
				PropertyInfo propertyInfo = AccessTools.Property(typeof(Player), "IsSprinting");
				if (propertyInfo != null)
				{
					component.WasSprinting = (bool)propertyInfo.GetValue(val);
				}
			}
		}
		return true;
	}

	public static void OnStartAimPostfix(Gun __instance)
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Expected O, but got Unknown
		ModGunData component = ((Component)__instance).gameObject.GetComponent<ModGunData>();
		if (!((Object)(object)component != (Object)null) || !component.CanAimWhileSprinting || !component.WasSprinting)
		{
			return;
		}
		Player val = (Player)AccessTools.Field(typeof(Gun), "player").GetValue(__instance);
		if ((Object)(object)val != (Object)null)
		{
			MethodInfo methodInfo = AccessTools.Method(typeof(Player), "ResumeSprint", (Type[])null, (Type[])null);
			if (methodInfo != null)
			{
				methodInfo.Invoke(val, null);
			}
		}
		component.WasSprinting = false;
	}

	public static bool CanAimPrefix(Gun __instance, ref bool __result)
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Expected O, but got Unknown
		ModGunData component = ((Component)__instance).gameObject.GetComponent<ModGunData>();
		if ((Object)(object)component != (Object)null && component.CanAimWhileSprinting)
		{
			Player val = (Player)AccessTools.Field(typeof(Gun), "player").GetValue(__instance);
			if ((Object)(object)val != (Object)null)
			{
				PropertyInfo propertyInfo = AccessTools.Property(typeof(Player), "IsSprinting");
				if (propertyInfo != null && (bool)propertyInfo.GetValue(val))
				{
					FieldInfo fieldInfo = AccessTools.Field(typeof(Gun), "isAimInputHeld");
					if (fieldInfo != null && (bool)fieldInfo.GetValue(__instance))
					{
						__result = true;
						return false;
					}
				}
			}
		}
		return true;
	}

	public static bool EnableWallrunGetPrefix(Player __instance, ref bool __result)
	{
		if (!((NetworkBehaviour)__instance).IsLocalPlayer)
		{
			return true;
		}
		if (!FreeFireMod.enableWallrunning.Value)
		{
			return true;
		}
		__result = true;
		return false;
	}
}
[HarmonyPatch]
public static class WingsuitStrafingPatch
{
	[HarmonyPatch(typeof(Wingsuit), "OnJumpPressed")]
	[HarmonyPostfix]
	public static void OnJumpPressedPostfix(Wingsuit __instance)
	{
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: 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_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: 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_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		if (!FreeFireMod.enableWingsuitStrafing.Value)
		{
			return;
		}
		FieldInfo field = ((object)__instance).GetType().GetField("wingsuitData", BindingFlags.Instance | BindingFlags.NonPublic);
		if (field == null)
		{
			return;
		}
		object value = field.GetValue(__instance);
		if (value == null)
		{
			return;
		}
		FieldInfo field2 = value.GetType().GetField("lockFlyDirection", BindingFlags.Instance | BindingFlags.Public);
		if (field2 == null || !(bool)field2.GetValue(value))
		{
			return;
		}
		FieldInfo field3 = ((object)__instance).GetType().GetField("player", BindingFlags.Instance | BindingFlags.NonPublic);
		if (field3 == null)
		{
			return;
		}
		object value2 = field3.GetValue(__instance);
		if (value2 == null)
		{
			return;
		}
		Vector2 val = PlayerInput.MoveInput();
		if (((Vector2)(ref val)).magnitude < 0.1f)
		{
			return;
		}
		FieldInfo field4 = ((object)__instance).GetType().GetField("isFlying", BindingFlags.Instance | BindingFlags.NonPublic);
		if (!(field4 != null) || !(bool)field4.GetValue(__instance))
		{
			return;
		}
		Vector3 val2 = new Vector3(val.x, val.y, 0f);
		Vector3 normalized = ((Vector3)(ref val2)).normalized;
		FieldInfo field5 = value.GetType().GetField("flySpeed", BindingFlags.Instance | BindingFlags.Public);
		if (field5 == null)
		{
			return;
		}
		float num = (float)field5.GetValue(value);
		float num2 = Mathf.Abs(normalized.x) * num * 0.5f;
		if (num2 > 0f)
		{
			Vector3 val3 = ((Component)__instance).transform.right * (float)((normalized.x > 0f) ? 1 : (-1)) * num2;
			MethodInfo method = value2.GetType().GetMethod("AddForce", new Type[1] { typeof(Vector3) });
			if (method != null)
			{
				method.Invoke(value2, new object[1] { val3 });
			}
		}
	}

	[HarmonyPatch(typeof(Wingsuit), "FixedUpdate")]
	[HarmonyPostfix]
	public static void FixedUpdatePostfix(Wingsuit __instance)
	{
		//IL_0038: 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_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0238: Unknown result type (might be due to invalid IL or missing references)
		if (!FreeFireMod.enableWingsuitStrafing.Value)
		{
			return;
		}
		FieldInfo field = ((object)__instance).GetType().GetField("isFlying", BindingFlags.Instance | BindingFlags.NonPublic);
		if (field == null || !(bool)field.GetValue(__instance))
		{
			return;
		}
		Vector2 val = PlayerInput.MoveInput();
		if (((Vector2)(ref val)).magnitude < 0.01f)
		{
			return;
		}
		Vector3 val2 = default(Vector3);
		((Vector3)(ref val2))..ctor(val.x, val.y, 0f);
		float magnitude = ((Vector3)(ref val2)).magnitude;
		if (magnitude > 0f)
		{
			val2 /= magnitude;
		}
		FieldInfo field2 = ((object)__instance).GetType().GetField("wingsuitData", BindingFlags.Instance | BindingFlags.NonPublic);
		if (field2 == null)
		{
			return;
		}
		object value = field2.GetValue(__instance);
		if (value == null)
		{
			return;
		}
		FieldInfo field3 = value.GetType().GetField("flySpeed", BindingFlags.Instance | BindingFlags.Public);
		FieldInfo field4 = value.GetType().GetField("flySpeedCurve", BindingFlags.Instance | BindingFlags.Public);
		FieldInfo field5 = value.GetType().GetField("flySpeedCurveDuration", BindingFlags.Instance | BindingFlags.Public);
		if (field3 == null || field4 == null)
		{
			return;
		}
		float num = (float)field3.GetValue(value);
		object? value2 = field4.GetValue(value);
		AnimationCurve val3 = (AnimationCurve)((value2 is AnimationCurve) ? value2 : null);
		float num2 = ((field5 != null) ? ((float)field5.GetValue(value)) : 1f);
		FieldInfo field6 = ((object)__instance).GetType().GetField("flyStartTime", BindingFlags.Instance | BindingFlags.NonPublic);
		if (field6 == null)
		{
			return;
		}
		float num3 = (float)field6.GetValue(__instance);
		float num4 = Mathf.Min((Time.time - num3) / num2, 1f);
		float num5 = val3.Evaluate(num4);
		FieldInfo field7 = ((object)__instance).GetType().GetField("player", BindingFlags.Instance | BindingFlags.NonPublic);
		if (field7 == null)
		{
			return;
		}
		object value3 = field7.GetValue(__instance);
		if (value3 == null)
		{
			return;
		}
		float x = val2.x;
		if (Mathf.Abs(x) > 0.1f)
		{
			float num6 = num * num5 * 2f;
			Vector3 val4 = ((Component)__instance).transform.right * x * num6;
			MethodInfo method = value3.GetType().GetMethod("AddForce", new Type[1] { typeof(Vector3) });
			if (method != null)
			{
				method.Invoke(value3, new object[1] { val4 });
			}
		}
	}
}
[HarmonyPatch]
public static class StrafingSpeedPatch
{
	[HarmonyTargetMethod]
	public static MethodBase TargetMethod()
	{
		Type type = Type.GetType("Pigeon.Movement.Player, Assembly-CSharp");
		if (type == null)
		{
			return null;
		}
		MethodInfo method = type.GetMethod("Awake", BindingFlags.Instance | BindingFlags.NonPublic);
		if (method != null)
		{
			return method;
		}
		MethodInfo method2 = type.GetMethod("Start", BindingFlags.Instance | BindingFlags.NonPublic);
		if (method2 != null)
		{
			return method2;
		}
		return null;
	}

	[HarmonyPostfix]
	public static void Postfix(object __instance)
	{
		if (FreeFireMod.enableStrafing.Value)
		{
			Type type = __instance.GetType();
			FieldInfo field = type.GetField("strafeSpeedMultiplier", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field2 = type.GetField("strafeSpeedMultiplierWhileMoving", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field != null)
			{
				field.SetValue(__instance, 1f);
			}
			if (field2 != null)
			{
				field2.SetValue(__instance, 1f);
			}
		}
	}
}
[CompilerGenerated]
[ExcludeFromCodeCoverage]
internal static class GitVersionInformation
{
	public const string AssemblySemFileVer = "0.0.1.0";

	public const string AssemblySemVer = "0.0.1.0";

	public const string BranchName = "master";

	public const string BuildMetaData = "";

	public const string CommitDate = "2025-10-17";

	public const string CommitsSinceVersionSource = "1";

	public const string EscapedBranchName = "master";

	public const string FullBuildMetaData = "Branch.master.Sha.873ff3fae4fe7f4415f75c3331915ef3d1a2134f";

	public const string FullSemVer = "0.0.1-1";

	public const string InformationalVersion = "0.0.1-1+Branch.master.Sha.873ff3fae4fe7f4415f75c3331915ef3d1a2134f";

	public const string Major = "0";

	public const string MajorMinorPatch = "0.0.1";

	public const string Minor = "0";

	public const string Patch = "1";

	public const string PreReleaseLabel = "";

	public const string PreReleaseLabelWithDash = "";

	public const string PreReleaseNumber = "1";

	public const string PreReleaseTag = "1";

	public const string PreReleaseTagWithDash = "-1";

	public const string SemVer = "0.0.1-1";

	public const string Sha = "873ff3fae4fe7f4415f75c3331915ef3d1a2134f";

	public const string ShortSha = "873ff3f";

	public const string UncommittedChanges = "12";

	public const string VersionSourceSha = "";

	public const string WeightedPreReleaseNumber = "55001";
}
namespace EnhancedMovement
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "EnhancedMovement";

		public const string PLUGIN_NAME = "EnhancedMovement";

		public const string PLUGIN_VERSION = "0.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}