Decompiled source of Custom Jump v1.0.3

CustomJump.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CustomJump.Configuration;
using CustomJump.Generators;
using CustomJump.Managers;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LethalModpack")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LethalModpack")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c9e559f3-1a56-4209-87b4-08547a8901da")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CustomJump
{
	[BepInPlugin("com.actus.lethalcompany.customjump", "Custom Jump Mod", "1.0.3")]
	public class CustomJumpBase : BaseUnityPlugin
	{
		private const string modGUID = "com.actus.lethalcompany.customjump";

		private const string modName = "Custom Jump Mod";

		private const string modVersion = "1.0.3";

		private static string baseFolderPath;

		private readonly Harmony harmony = new Harmony("com.actus.lethalcompany.customjump");

		internal static ManualLogSource logger;

		internal AssetBundle networkAssets;

		internal static CustomJumpBase Instance;

		internal static ConfigManager ConfigManager { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			logger = Logger.CreateLogSource("com.actus.lethalcompany.customjump");
			baseFolderPath = ((BaseUnityPlugin)Instance).Info.Location.TrimEnd("CustomJump.dll".ToCharArray());
			ConfigManager = new ConfigManager(((BaseUnityPlugin)this).Config);
			networkAssets = AssetBundle.LoadFromFile(Path.Combine(baseFolderPath, "networkasset"));
			harmony.PatchAll();
			NetcodePatcher();
		}

		private static void NetcodePatcher()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
}
namespace CustomJump.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB), "Update")]
	internal class CustomJumpPatch
	{
		private static int currentNumberOfJumps = CustomJumpBase.ConfigManager.CurrentConfiguration.MaxNumberOfAirJumps;

		private static float currentJumpCooldown = 0f;

		[HarmonyPostfix]
		public static void CustomJump(ref PlayerControllerB __instance, ref bool ___isJumping, ref bool ___isFallingFromJump, ref bool ___isFallingNoJump, ref bool ___isExhausted, ref float ___sprintMeter, ref float ___fallValueUncapped)
		{
			if (((NetworkBehaviour)__instance).IsOwner)
			{
				UpdateJumpCooldown();
				if (CanPerformJump(__instance, ___isExhausted, ___isFallingFromJump, ___isFallingNoJump, ___fallValueUncapped))
				{
					ExecuteJump(ref __instance, ref ___sprintMeter, ref ___isJumping);
				}
				if (__instance.thisController.isGrounded)
				{
					ResetJumpOnGround();
				}
			}
		}

		private static void ExecuteJump(ref PlayerControllerB __instance, ref float sprintMeter, ref bool isJumping)
		{
			currentNumberOfJumps--;
			((MonoBehaviour)__instance).StartCoroutine("PlayerJump");
			sprintMeter = Mathf.Clamp(sprintMeter - 0.08f, 0f, 1f);
			isJumping = true;
			currentJumpCooldown = CustomJumpBase.ConfigManager.CurrentConfiguration.CoolDown;
		}

		private static bool CanPerformJump(PlayerControllerB __instance, bool isExhausted, bool isFallingFromJump, bool isFallingNoJump, float fallValueUncapped)
		{
			bool wasPressedThisFrame = ((ButtonControl)Keyboard.current.spaceKey).wasPressedThisFrame;
			bool flag = isFallingFromJump || isFallingNoJump;
			bool flag2 = currentNumberOfJumps > 0 && !isExhausted;
			bool flag3 = flag2 && wasPressedThisFrame && flag;
			bool flag4 = CustomJumpBase.ConfigManager.CurrentConfiguration.AlwaysAllowJumpsWhenFalling || fallValueUncapped >= CustomJumpBase.ConfigManager.CurrentConfiguration.FallValue;
			return flag3 && flag4 && SecureRandomNumberGenerator.GetRandomNumber(1, 100) <= CustomJumpBase.ConfigManager.CurrentConfiguration.JumpPercentage && currentJumpCooldown <= 0f;
		}

		private static void UpdateJumpCooldown()
		{
			if (currentJumpCooldown > 0f)
			{
				currentJumpCooldown -= Time.deltaTime;
			}
		}

		private static void ResetJumpOnGround()
		{
			currentJumpCooldown = 0f;
			currentNumberOfJumps = CustomJumpBase.ConfigManager.CurrentConfiguration.MaxNumberOfAirJumps;
		}
	}
	[HarmonyPatch]
	public class NetworkObjectPatch
	{
		private static GameObject networkPrefab;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		public static void Init()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			if (!((Object)(object)networkPrefab != (Object)null))
			{
				networkPrefab = (GameObject)CustomJumpBase.Instance.networkAssets.LoadAsset("CustomJumpNetworkManager.prefab");
				networkPrefab.AddComponent<NetworkHandler>();
				NetworkManager.Singleton.AddNetworkPrefab(networkPrefab);
				CustomJumpBase.logger.LogInfo((object)"NetworkObjectManager set!");
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		private static void SpawnNetworkObject()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				GameObject val = Object.Instantiate<GameObject>(networkPrefab, Vector3.zero, Quaternion.identity);
				val.GetComponent<NetworkObject>().Spawn(false);
				CustomJumpBase.logger.LogInfo((object)"NetworkObject SPAWNED!");
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "Start")]
	internal class StartOfRoundPatch
	{
		[HarmonyPostfix]
		public static void SyncConfigs()
		{
			NetworkHandler.Instance.RequestServerConfig();
		}
	}
}
namespace CustomJump.Managers
{
	public class NetworkHandler : NetworkBehaviour
	{
		public static NetworkHandler Instance { get; private set; }

		[RuntimeInitializeOnLoadMethod]
		internal static void ConfigureRpcHandler()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			CustomJumpBase.logger.LogInfo((object)"[ConfigureRpcHandler] Starting RPC initialization process to ensure proper network communication.");
			NetworkManager.__rpc_func_table.Add(881135941u, new RpcReceiveHandler(__rpc_handler_881135941));
			NetworkManager.__rpc_func_table.Add(743244665u, new RpcReceiveHandler(__rpc_handler_743244665));
			CustomJumpBase.logger.LogInfo((object)"[ConfigureRpcHandler] RPC initialization completed successfully. Network communication is now set up.");
		}

		public override void OnNetworkSpawn()
		{
			CustomJumpBase.logger.LogInfo((object)"[OnNetworkSpawn] Initializing NetworkHandler instance. Preparing to set up network behavior and spawn logic.");
			if ((Object)(object)Instance != (Object)null && (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer))
			{
				((Component)Instance).gameObject.GetComponent<NetworkObject>().Despawn(true);
			}
			Instance = this;
			((NetworkBehaviour)this).OnNetworkSpawn();
			CustomJumpBase.logger.LogInfo((object)"[OnNetworkSpawn] Initializing NetworkHandler instance. Preparing to set up network behavior and spawn logic.");
		}

		[ServerRpc(RequireOwnership = false)]
		public void RequestServerConfig()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Invalid comparison between Unknown and I4
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Invalid comparison between Unknown and I4
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if ((Object)(object)networkManager != (Object)null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(743244665u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 743244665u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					ConfigPackage configPackage = CustomJumpBase.ConfigManager.ProvideOriginalConfiruation();
					SendConfigToClient(configPackage.MaxNumberOfAirJumps, configPackage.AlwaysAllowJumpsWhenFalling, configPackage.FallValue, configPackage.JumpPercentage, configPackage.CoolDown);
				}
			}
		}

		[ClientRpc]
		public void SendConfigToClient(int maxNumberOfAirJumps, bool alwaysAllowJumpsWhenFalling, float fallValue, int jumpPercentage, float coolDown, ClientRpcParams rpcParams = default(ClientRpcParams))
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Invalid comparison between Unknown and I4
			//IL_0052: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (!((Object)(object)networkManager == (Object)null) && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(881135941u, rpcParams, (RpcDelivery)0);
					FastBufferWriter val2 = val;
					((FastBufferWriter)(ref val2)).WriteValueSafe<int>(ref maxNumberOfAirJumps, default(ForPrimitives));
					val2 = val;
					((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref alwaysAllowJumpsWhenFalling, default(ForPrimitives));
					val2 = val;
					((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref fallValue, default(ForPrimitives));
					val2 = val;
					((FastBufferWriter)(ref val2)).WriteValueSafe<int>(ref jumpPercentage, default(ForPrimitives));
					val2 = val;
					((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref coolDown, default(ForPrimitives));
					((NetworkBehaviour)this).__endSendClientRpc(ref val, 881135941u, rpcParams, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					CustomJumpBase.logger.LogInfo((object)("[Client] Received config from server!\nmaxNumberOfAirJumps: " + maxNumberOfAirJumps + "\nalwaysAllowJumpsWhenFalling: " + alwaysAllowJumpsWhenFalling + "\nfallValue: " + fallValue + "\njumpPercentage " + jumpPercentage + "\nCoolDown: " + coolDown));
					CustomJumpBase.ConfigManager.ChangeCurrentConfiguration(maxNumberOfAirJumps, alwaysAllowJumpsWhenFalling, fallValue, jumpPercentage, coolDown);
				}
			}
		}

		private static void __rpc_handler_743244665(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if ((Object)(object)networkManager != (Object)null && networkManager.IsListening)
			{
				((NetworkBehaviour)(target as NetworkHandler)).__rpc_exec_stage = (__RpcExecStage)1;
				((NetworkHandler)(object)target).RequestServerConfig();
				((NetworkBehaviour)(target as NetworkHandler)).__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_881135941(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_00b7: 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)
			NetworkManager networkManager = target.NetworkManager;
			if ((Object)(object)networkManager != (Object)null && networkManager.IsListening)
			{
				FastBufferReader val = reader;
				int maxNumberOfAirJumps = default(int);
				((FastBufferReader)(ref val)).ReadValueSafe<int>(ref maxNumberOfAirJumps, default(ForPrimitives));
				val = reader;
				bool alwaysAllowJumpsWhenFalling = default(bool);
				((FastBufferReader)(ref val)).ReadValueSafe<bool>(ref alwaysAllowJumpsWhenFalling, default(ForPrimitives));
				val = reader;
				float fallValue = default(float);
				((FastBufferReader)(ref val)).ReadValueSafe<float>(ref fallValue, default(ForPrimitives));
				val = reader;
				int jumpPercentage = default(int);
				((FastBufferReader)(ref val)).ReadValueSafe<int>(ref jumpPercentage, default(ForPrimitives));
				val = reader;
				float coolDown = default(float);
				((FastBufferReader)(ref val)).ReadValueSafe<float>(ref coolDown, default(ForPrimitives));
				((NetworkBehaviour)(target as NetworkHandler)).__rpc_exec_stage = (__RpcExecStage)2;
				((NetworkHandler)(object)target).SendConfigToClient(maxNumberOfAirJumps, alwaysAllowJumpsWhenFalling, fallValue, jumpPercentage, coolDown);
				((NetworkBehaviour)(target as NetworkHandler)).__rpc_exec_stage = (__RpcExecStage)0;
			}
		}
	}
}
namespace CustomJump.Generators
{
	internal class SecureRandomNumberGenerator
	{
		public static int GetRandomNumber(int minInclusive, int maxInclusive)
		{
			using RNGCryptoServiceProvider rNGCryptoServiceProvider = new RNGCryptoServiceProvider();
			byte[] array = new byte[4];
			rNGCryptoServiceProvider.GetBytes(array);
			int num = BitConverter.ToInt32(array, 0) & 0x7FFFFFFF;
			return minInclusive + num % (maxInclusive - minInclusive + 1);
		}
	}
}
namespace CustomJump.Configuration
{
	public class ConfigManager
	{
		private ConfigFile bepInExConfig;

		private ConfigPackage originalConfiguration;

		public ConfigPackage CurrentConfiguration { get; private set; }

		public ConfigManager(ConfigFile bepInExConfig)
		{
			this.bepInExConfig = bepInExConfig;
			originalConfiguration = LoadConfig();
			CurrentConfiguration = ProvideOriginalConfiruation();
		}

		public void ChangeCurrentConfiguration(int maxNumberOfAirJumps, bool alwaysAllowJumpsWhenFalling, float fallValue, int jumpPercentage, float coolDown)
		{
			CurrentConfiguration = new ConfigPackage(maxNumberOfAirJumps, alwaysAllowJumpsWhenFalling, fallValue, jumpPercentage, coolDown);
		}

		public ConfigPackage ProvideOriginalConfiruation()
		{
			return new ConfigPackage(originalConfiguration.MaxNumberOfAirJumps, originalConfiguration.AlwaysAllowJumpsWhenFalling, originalConfiguration.FallValue, originalConfiguration.JumpPercentage, originalConfiguration.CoolDown);
		}

		private ConfigPackage LoadConfig()
		{
			int value = bepInExConfig.Bind<int>("General", "maxNumberOfAirJumps", 1, "Set the max number of air jumps (1 = double jump, 2 = triple jump, etc.)").Value;
			bool value2 = bepInExConfig.Bind<bool>("General", "alwaysAllowJumpsWhenFalling", false, "Allows jumping while falling.").Value;
			float value3 = bepInExConfig.Bind<float>("General", "fallValue", -15f, "Sets the fall value. This value is ignored when alwaysAllowJumpsWhenFalling is set to true!\nA higher number (e.g., -10) means you can fall less before being able to air jump.\nA lower number (e.g., -20) allows you to fall more before being able to air jump.\nNote: For reference, if your player model reaches a fall value below -35, you will take fall damage upon landing.").Value;
			int value4 = bepInExConfig.Bind<int>("General", "jumpPercentage", 100, "The percentage chance that an air jump is executed (0 = never, 100 = always).").Value;
			float value5 = bepInExConfig.Bind<float>("General", "coolDown", 2.5f, "Sets the cooldown of the next air jump.\nNote: To allow spamming jumps, set the cooldown to 0.").Value;
			return new ConfigPackage(value, value2, value3, value4, value5);
		}
	}
	public class ConfigPackage
	{
		public int MaxNumberOfAirJumps { get; private set; }

		public bool AlwaysAllowJumpsWhenFalling { get; private set; }

		public float FallValue { get; private set; }

		public int JumpPercentage { get; private set; }

		public float CoolDown { get; private set; }

		public ConfigPackage(int maxNumberOfAirJumps, bool alwaysAllowJumpsWhenFalling, float fallValue, int jumpPercentage, float coolDown)
		{
			MaxNumberOfAirJumps = maxNumberOfAirJumps;
			AlwaysAllowJumpsWhenFalling = alwaysAllowJumpsWhenFalling;
			FallValue = fallValue;
			JumpPercentage = jumpPercentage;
			CoolDown = coolDown;
		}
	}
}