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 GameNetcodeStuff;
using HarmonyLib;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("lcbhop")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Lethal Company Source Movement Mod")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: AssemblyInformationalVersion("1.2.1")]
[assembly: AssemblyProduct("lcbhop")]
[assembly: AssemblyTitle("lcbhop")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.1.0")]
[module: UnverifiableCode]
namespace lcbhop;
public class Config
{
private readonly ConfigFile config;
public bool autobhop { get; set; }
public bool speedometer { get; set; }
public bool enablebunnyhopping { get; set; }
public float gravity { get; set; }
public float friction { get; set; }
public float maxspeed { get; set; }
public float movespeed { get; set; }
public float accelerate { get; set; }
public float airaccelerate { get; set; }
public float stopspeed { get; set; }
public Config(ConfigFile cfg)
{
config = cfg;
}
public void Init()
{
autobhop = config.Bind<bool>("General", "Auto Bhop", true, "Disabling rebinds jump to scroll, needs ItemQuickSwitch mod!").Value;
speedometer = config.Bind<bool>("General", "Speedometer", false, "Enables speedometer HUD.").Value;
enablebunnyhopping = config.Bind<bool>("General", "Enable bunnyhopping", false, "Disables the speed cap.").Value;
gravity = config.Bind<float>("Move Vars", "Gravity", 800f, "Gravity.").Value;
friction = config.Bind<float>("Move Vars", "Friction", 4f, "Ground friction.").Value;
maxspeed = config.Bind<float>("Move Vars", "Max Speed", 320f, "Max speed per tick.").Value;
movespeed = config.Bind<float>("Move Vars", "Move Speed", 250f, "Ground speed (like cl_forwardspeed etc.).").Value;
accelerate = config.Bind<float>("Move Vars", "Accelerate", 5f, "Ground acceleration.").Value;
airaccelerate = config.Bind<float>("Move Vars", "Air Accelerate", 10f, "Air acceleration.").Value;
stopspeed = config.Bind<float>("Move Vars", "Stop Speed", 75f, "Ground deceleration.").Value;
}
}
internal struct Cmd
{
public float forwardMove;
public float rightMove;
public float upMove;
}
public class CPMPlayer : MonoBehaviour
{
public float gravity = Plugin.cfg.gravity;
public float friction = Plugin.cfg.friction;
public float maxspeed = Plugin.cfg.maxspeed;
public float movespeed = Plugin.cfg.movespeed;
public float accelerate = Plugin.cfg.accelerate;
public float airaccelerate = Plugin.cfg.airaccelerate;
public float stopspeed = Plugin.cfg.stopspeed;
public PlayerControllerB player;
private CharacterController _controller;
private Vector3 velocity = Vector3.zero;
public bool wishJump;
private Cmd _cmd;
private GameObject compass;
private TextMeshProUGUI speedo;
private void Start()
{
_controller = player.thisController;
}
private void Update()
{
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
//IL_018d: Unknown result type (might be due to invalid IL or missing references)
//IL_0192: Unknown result type (might be due to invalid IL or missing references)
//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
player.fallValue = 0f;
player.fallValueUncapped = 0f;
player.sprintMeter = 1f;
if (((!((NetworkBehaviour)player).IsOwner || !player.isPlayerControlled || (((NetworkBehaviour)player).IsServer && !player.isHostPlayerObject)) && !player.isTestingPlayer) || player.quickMenuManager.isMenuOpen || player.inSpecialInteractAnimation || player.isTypingChat)
{
return;
}
if (player.isClimbingLadder)
{
Plugin.patchMove = false;
return;
}
Jump();
if (!wishJump && _controller.isGrounded)
{
Friction();
}
if (_controller.isGrounded)
{
WalkMove();
}
else if (!_controller.isGrounded)
{
AirMove();
}
Plugin.patchMove = false;
_controller.Move(velocity / 32f * Time.deltaTime);
Plugin.patchMove = true;
wishJump = false;
if (Plugin.cfg.speedometer)
{
if (!Object.op_Implicit((Object)(object)compass))
{
compass = GameObject.Find("/Systems/UI/Canvas/IngamePlayerHUD/TopLeftCorner/Compass");
speedo = compass.GetComponentInChildren<TextMeshProUGUI>();
}
if (Object.op_Implicit((Object)(object)compass))
{
compass.SetActive(true);
Vector3 val = velocity;
val.y = 0f;
((TMP_Text)speedo).text = $"{(int)((Vector3)(ref val)).magnitude} u";
((TMP_Text)speedo).rectTransform.sizeDelta = ((TMP_Text)speedo).GetPreferredValues();
}
}
else if (Object.op_Implicit((Object)(object)compass))
{
compass.SetActive(false);
}
}
private void SetMovementDir()
{
//IL_0011: 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_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: 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)
ref Cmd cmd = ref _cmd;
MovementActions movement = player.playerActions.Movement;
cmd.forwardMove = ((MovementActions)(ref movement)).Move.ReadValue<Vector2>().y * movespeed;
ref Cmd cmd2 = ref _cmd;
movement = player.playerActions.Movement;
cmd2.rightMove = ((MovementActions)(ref movement)).Move.ReadValue<Vector2>().x * movespeed;
}
private void Jump()
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: 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)
MovementActions movement;
if (Plugin.cfg.autobhop)
{
movement = player.playerActions.Movement;
wishJump = ((MovementActions)(ref movement)).Jump.ReadValue<float>() > 0f;
}
else if (!wishJump)
{
movement = player.playerActions.Movement;
wishJump = ((MovementActions)(ref movement)).SwitchItem.ReadValue<float>() != 0f;
}
if (!Plugin.cfg.enablebunnyhopping)
{
PreventMegaBunnyJumping();
}
}
private void AirMove()
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: 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_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
SetMovementDir();
Vector3 val = default(Vector3);
((Vector3)(ref val))..ctor(_cmd.rightMove, 0f, _cmd.forwardMove);
val = ((Component)this).transform.TransformDirection(val);
Vector3 wishdir = val;
float magnitude = ((Vector3)(ref wishdir)).magnitude;
((Vector3)(ref wishdir)).Normalize();
if (magnitude > maxspeed)
{
val *= maxspeed / magnitude;
magnitude = maxspeed;
}
AirAccelerate(wishdir, magnitude, airaccelerate);
velocity.y -= gravity * Time.deltaTime;
}
private void WalkMove()
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: 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_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
SetMovementDir();
Vector3 val = default(Vector3);
((Vector3)(ref val))..ctor(_cmd.rightMove, 0f, _cmd.forwardMove);
val = ((Component)this).transform.TransformDirection(val);
Vector3 wishdir = val;
float magnitude = ((Vector3)(ref wishdir)).magnitude;
((Vector3)(ref wishdir)).Normalize();
if (magnitude > maxspeed)
{
val *= maxspeed / magnitude;
magnitude = maxspeed;
}
Accelerate(wishdir, magnitude, accelerate);
velocity.y = (0f - gravity) * Time.deltaTime;
if (wishJump)
{
velocity.y = 295f;
}
}
private void Friction()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = velocity;
val.y = 0f;
float magnitude = ((Vector3)(ref val)).magnitude;
if (!(magnitude < 0.1f))
{
float num = 0f;
if (_controller.isGrounded)
{
float num2 = ((magnitude < stopspeed) ? stopspeed : magnitude);
num += num2 * friction * Time.deltaTime;
}
float num3 = magnitude - num;
if (num3 < 0f)
{
num3 = 0f;
}
num3 /= magnitude;
velocity.x *= num3;
velocity.z *= num3;
}
}
private void Accelerate(Vector3 wishdir, float wishspeed, float accel)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: 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)
float num = Vector3.Dot(velocity, wishdir);
float num2 = wishspeed - num;
if (!(num2 <= 0f))
{
float num3 = accel * Time.deltaTime * wishspeed;
if (num3 > num2)
{
num3 = num2;
}
velocity.x += num3 * wishdir.x;
velocity.z += num3 * wishdir.z;
}
}
private void AirAccelerate(Vector3 wishdir, float wishspeed, float accel)
{
//IL_0011: 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_0048: 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)
float num = wishspeed;
if (num > 30f)
{
num = 30f;
}
float num2 = Vector3.Dot(velocity, wishdir);
float num3 = num - num2;
if (!(num3 <= 0f))
{
float num4 = accel * wishspeed * Time.deltaTime;
if (num4 > num3)
{
num4 = num3;
}
velocity.x += num4 * wishdir.x;
velocity.z += num4 * wishdir.z;
}
}
private void PreventMegaBunnyJumping()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = velocity;
float num = 1.7f * maxspeed;
if (!(num <= 0f))
{
val.y = 0f;
float magnitude = ((Vector3)(ref val)).magnitude;
if (!(magnitude <= num))
{
float num2 = num / magnitude * 0.65f;
velocity.x *= num2;
velocity.z *= num2;
}
}
}
}
[HarmonyPatch(typeof(CharacterController), "Move")]
internal class Move_Patch
{
[HarmonyPrefix]
internal static bool Prefix(ref Vector3 motion)
{
return !Plugin.patchMove;
}
}
[HarmonyPatch(typeof(PlayerControllerB), "Crouch_performed")]
internal class Crouch_performed_Patch
{
[HarmonyPrefix]
internal static bool Prefix(PlayerControllerB __instance, ref CallbackContext context)
{
if (!((CallbackContext)(ref context)).performed)
{
return false;
}
if (__instance.quickMenuManager.isMenuOpen)
{
return false;
}
if ((!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || (((NetworkBehaviour)__instance).IsServer && !__instance.isHostPlayerObject)) && !__instance.isTestingPlayer)
{
return false;
}
if (__instance.inSpecialInteractAnimation || __instance.isTypingChat)
{
return false;
}
__instance.Crouch(!__instance.isCrouching);
return false;
}
}
[HarmonyPatch(typeof(PlayerControllerB), "Jump_performed")]
internal class Jump_performed_Patch
{
[HarmonyPrefix]
internal static bool Prefix(ref CallbackContext context)
{
Plugin.player.wishJump = true;
return !Plugin.patchJump;
}
}
[HarmonyPatch(typeof(PlayerControllerB), "ScrollMouse_performed")]
internal class ScrollMouse_performed_Patch
{
[HarmonyPrefix]
internal static bool Prefix(ref CallbackContext context)
{
return Plugin.cfg.autobhop;
}
}
[HarmonyPatch(typeof(HUDManager), "SubmitChat_performed")]
internal class SubmitChat_performed_Patch
{
[HarmonyPrefix]
internal static bool Prefix(HUDManager __instance)
{
string text = __instance.chatTextField.text;
if (text.StartsWith("/autobhop"))
{
Plugin.cfg.autobhop = !Plugin.cfg.autobhop;
}
else
{
if (!text.StartsWith("/speedo"))
{
return true;
}
Plugin.cfg.speedometer = !Plugin.cfg.speedometer;
}
__instance.localPlayer.isTypingChat = false;
__instance.chatTextField.text = "";
EventSystem.current.SetSelectedGameObject((GameObject)null);
__instance.PingHUDElement(__instance.Chat, 2f, 1f, 0.2f);
((Behaviour)__instance.typingIndicator).enabled = false;
return false;
}
}
public class ComponentAdder : MonoBehaviour
{
private void Update()
{
PlayerControllerB[] array = Object.FindObjectsOfType<PlayerControllerB>();
foreach (PlayerControllerB val in array)
{
if ((Object)(object)val != (Object)null && (Object)(object)((Component)val).gameObject.GetComponentInChildren<CPMPlayer>() == (Object)null && ((NetworkBehaviour)val).IsOwner && val.isPlayerControlled)
{
Plugin.player = ((Component)val).gameObject.AddComponent<CPMPlayer>();
Plugin.player.player = val;
}
}
}
}
[BepInPlugin("lcbhop", "lcbhop", "1.2.1")]
public class Plugin : BaseUnityPlugin
{
public static ManualLogSource logger;
private readonly Harmony harmony = new Harmony("lcbhop");
public static bool patchMove = true;
public static bool patchJump = true;
public static CPMPlayer player;
public static Config cfg { get; set; }
private void Awake()
{
cfg = new Config(((BaseUnityPlugin)this).Config);
cfg.Init();
logger = ((BaseUnityPlugin)this).Logger;
harmony.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin lcbhop is loaded!");
}
private void OnDestroy()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
GameObject val = new GameObject("ComponentAdder");
Object.DontDestroyOnLoad((Object)val);
val.AddComponent<ComponentAdder>();
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "lcbhop";
public const string PLUGIN_NAME = "lcbhop";
public const string PLUGIN_VERSION = "1.2.1";
}