using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
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 Microsoft.CodeAnalysis;
using OoLunar.LethalCompanyPatched.Patches;
using TMPro;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LethalCompanyPatched")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A continuation of An0n_Patches.")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: AssemblyInformationalVersion("1.2.1")]
[assembly: AssemblyProduct("LethalCompanyPatched")]
[assembly: AssemblyTitle("LethalCompanyPatched")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.1.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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 OoLunar.LethalCompanyPatched
{
[BepInPlugin("LethalCompanyPatched", "LethalCompanyPatched", "1.2.1")]
public sealed class LethalCompanyPatchedPlugin : BaseUnityPlugin
{
private readonly Harmony _harmony = new Harmony("LethalCompanyPatched");
internal static ManualLogSource StaticLogger;
internal static ConfigEntry<float> InstantSprint;
internal static ConfigEntry<float> Slipperiness;
internal static ConfigEntry<float> JumpDelay;
internal static ConfigEntry<bool> ShowHudPercentages;
internal static ConfigEntry<bool> CrouchHold;
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogDebug((object)"LethalCompanyPatched started loading!");
StaticLogger = ((BaseUnityPlugin)this).Logger;
CrouchHold = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "crouchHold", true, "Enable/disable crouch hold. If disabled, crouch functions as a toggle with the additional behavior of going back into a crouch upon landing from a crouch jump.");
JumpDelay = ((BaseUnityPlugin)this).Config.Bind<float>("General", "jumpDelay", 0f, "Configure the time till jump, defaults to instant with 0.0. Vanilla is 0.15");
InstantSprint = ((BaseUnityPlugin)this).Config.Bind<float>("General", "instantSprint", 2.25f, "How fast to accelerate to sprint value of 2.25. 2.25 is the max, so it's instant acceleration. Vanilla is 1.0");
Slipperiness = ((BaseUnityPlugin)this).Config.Bind<float>("General", "slipperiness", 10f, "The amount of slipperiness when running and changing direction. 10-15f is a good value for little to no slippery feeling. Vanilla is 5.0");
ShowHudPercentages = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "showHealthStamina", true, "Show your health and sprint/stamina % on the HUD.");
Type[] types = typeof(LethalCompanyPatchedPlugin).Assembly.GetTypes();
foreach (Type type in types)
{
if (type.GetCustomAttribute<LethalPatchAttribute>() != null)
{
_harmony.PatchAll(type);
}
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"LethalCompanyPatched finished loading!");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "LethalCompanyPatched";
public const string PLUGIN_NAME = "LethalCompanyPatched";
public const string PLUGIN_VERSION = "1.2.1";
}
}
namespace OoLunar.LethalCompanyPatched.Patches
{
[HarmonyPatch]
[LethalPatch]
internal class HUDManagerPatch : MonoBehaviour
{
private static bool _instantiating = true;
private static TextMeshProUGUI? _hudPercentagesText;
[HarmonyPostfix]
[HarmonyPatch(typeof(StartOfRound), "SceneManager_OnLoadComplete1")]
public static void CreateHudPercentages()
{
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: 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)
if (_instantiating)
{
GameObject obj = GameObject.Find("Systems/UI/Canvas/IngamePlayerHUD/TopLeftCorner/WeightUI");
GameObject val = GameObject.Find("Systems/UI/Canvas/IngamePlayerHUD/TopLeftCorner");
GameObject obj2 = Object.Instantiate<GameObject>(obj, val.transform);
((Object)obj2).name = "HPSP";
GameObject gameObject = ((Component)obj2.transform.GetChild(0)).gameObject;
gameObject.GetComponent<RectTransform>().anchoredPosition = new Vector2(-45f, 10f);
_hudPercentagesText = gameObject.GetComponent<TextMeshProUGUI>();
((TMP_Text)_hudPercentagesText).faceColor = Color32.op_Implicit(new Color(255f, 0f, 0f, 255f));
((TMP_Text)_hudPercentagesText).fontSize = 12f;
((TMP_Text)_hudPercentagesText).margin = new Vector4(0f, -36f, 100f, 0f);
((TMP_Text)_hudPercentagesText).alignment = (TextAlignmentOptions)260;
((TMP_Text)_hudPercentagesText).text = "";
_instantiating = false;
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(GameNetworkManager), "Disconnect")]
public static void UnInstantiate()
{
_instantiating = true;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(HUDManager), "Update")]
public static void Update()
{
PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
if (!((Object)(object)localPlayerController == (Object)null) && !_instantiating && !((Object)(object)_hudPercentagesText == (Object)null))
{
float num = Mathf.RoundToInt((float)localPlayerController.health);
int num2 = Math.Max(Mathf.RoundToInt((localPlayerController.sprintMeter * 100f - 10f) / 90f * 100f), 0);
((TMP_Text)_hudPercentagesText).text = (LethalCompanyPatchedPlugin.ShowHudPercentages.Value ? $"{num}\n\n\n\n{num2}%" : "");
}
}
}
[AttributeUsage(AttributeTargets.Class)]
public sealed class LethalPatchAttribute : Attribute
{
}
[HarmonyPatch(typeof(PlayerControllerB))]
[LethalPatch]
internal class PlayerControllerPatch
{
private static readonly FieldInfo? _playerCarryWeight = AccessTools.Field(typeof(PlayerControllerB), "carryWeight");
private static readonly FieldInfo? _slipperinessConfigField = AccessTools.Field(typeof(LethalCompanyPatchedPlugin), "Slipperiness");
private static readonly FieldInfo? _jumpDelayConfigField = AccessTools.Field(typeof(LethalCompanyPatchedPlugin), "JumpDelay");
private static readonly FieldInfo? _instantSprintConfigField = AccessTools.Field(typeof(LethalCompanyPatchedPlugin), "InstantSprint");
private static readonly MethodInfo? _configEntryFloatValueMethod = AccessTools.Method(typeof(ConfigEntry<float>), "get_Value", (Type[])null, (Type[])null);
private static bool _tempCrouch;
private static readonly int _crouchingId = Animator.StringToHash("crouching");
private static readonly int _startCrouchingId = Animator.StringToHash("startCrouching");
private static bool ReplaceInstruction(List<CodeInstruction> instructions, List<CodeInstruction> newInstructions, Predicate<int> whereClause, int lookAhead = 0, int lookBehind = 0)
{
int num = instructions.Count - lookAhead;
for (int i = lookBehind; i < num; i++)
{
if (whereClause(i))
{
instructions.RemoveAt(i);
instructions.InsertRange(i, newInstructions);
return true;
}
}
return false;
}
[HarmonyTranspiler]
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
public static IEnumerable<CodeInstruction> RemoveJumpDelay(IEnumerable<CodeInstruction> instructions)
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Expected O, but got Unknown
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Expected O, but got Unknown
List<CodeInstruction> list = new List<CodeInstruction>();
foreach (CodeInstruction instruction in instructions)
{
list.Add(instruction);
}
List<CodeInstruction> currentInstructions = list;
List<CodeInstruction> newInstructions = new List<CodeInstruction>
{
new CodeInstruction(OpCodes.Ldsfld, (object)_jumpDelayConfigField),
new CodeInstruction(OpCodes.Callvirt, (object)_configEntryFloatValueMethod)
};
if (ReplaceInstruction(currentInstructions, newInstructions, (int instructionIndex) => currentInstructions[instructionIndex + 1].opcode == OpCodes.Newobj && ((ConstructorInfo)currentInstructions[instructionIndex + 1].operand).DeclaringType == typeof(WaitForSeconds), 1))
{
LethalCompanyPatchedPlugin.StaticLogger.LogDebug((object)"Patched Jump-Delay");
}
else
{
LethalCompanyPatchedPlugin.StaticLogger.LogError((object)"Failed to patch Jump-Delay, the player's jump will have it's default delay.");
}
return currentInstructions;
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(PlayerControllerB), "Update")]
public static IEnumerable<CodeInstruction> FixSlipperiness(IEnumerable<CodeInstruction> instructions)
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Expected O, but got Unknown
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Expected O, but got Unknown
List<CodeInstruction> list = new List<CodeInstruction>();
foreach (CodeInstruction instruction in instructions)
{
list.Add(instruction);
}
List<CodeInstruction> currentInstructions = list;
List<CodeInstruction> newInstructions = new List<CodeInstruction>
{
new CodeInstruction(OpCodes.Ldsfld, (object)_slipperinessConfigField),
new CodeInstruction(OpCodes.Callvirt, (object)_configEntryFloatValueMethod)
};
if (ReplaceInstruction(currentInstructions, newInstructions, (int instructionIndex) => currentInstructions[instructionIndex].opcode == OpCodes.Ldc_R4 && Mathf.Approximately((float)currentInstructions[instructionIndex].operand, 5f) && CodeInstructionExtensions.LoadsField(currentInstructions[instructionIndex + 2], _playerCarryWeight, false) && currentInstructions[instructionIndex + 3].opcode == OpCodes.Ldc_R4 && Mathf.Approximately((float)currentInstructions[instructionIndex + 3].operand, 1.5f), 3))
{
LethalCompanyPatchedPlugin.StaticLogger.LogDebug((object)"Patched Slipperiness");
}
else
{
LethalCompanyPatchedPlugin.StaticLogger.LogError((object)"Failed to patch Slipperiness, the player will have the default slipperiness.");
}
return currentInstructions;
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(PlayerControllerB), "Update")]
public static IEnumerable<CodeInstruction> InstantSprint(IEnumerable<CodeInstruction> instructions)
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Expected O, but got Unknown
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Expected O, but got Unknown
List<CodeInstruction> list = new List<CodeInstruction>();
foreach (CodeInstruction instruction in instructions)
{
list.Add(instruction);
}
List<CodeInstruction> currentInstructions = list;
List<CodeInstruction> newInstructions = new List<CodeInstruction>
{
new CodeInstruction(OpCodes.Ldsfld, (object)_instantSprintConfigField),
new CodeInstruction(OpCodes.Callvirt, (object)_configEntryFloatValueMethod)
};
if (ReplaceInstruction(currentInstructions, newInstructions, (int instructionIndex) => currentInstructions[instructionIndex - 3].opcode == OpCodes.Ldfld && ((object)currentInstructions[instructionIndex - 3]).ToString() == "ldfld float GameNetcodeStuff.PlayerControllerB::sprintMultiplier" && currentInstructions[instructionIndex - 2].opcode == OpCodes.Ldc_R4 && Mathf.Approximately((float)currentInstructions[instructionIndex - 2].operand, 2.25f) && currentInstructions[instructionIndex].opcode == OpCodes.Ldc_R4 && Mathf.Approximately((float)currentInstructions[instructionIndex].operand, 1f), 0, 3))
{
LethalCompanyPatchedPlugin.StaticLogger.LogDebug((object)"Patched Instant-Sprint");
}
else
{
LethalCompanyPatchedPlugin.StaticLogger.LogError((object)"Failed to patch Instant-Sprint, the player will have the default sprint speed.");
}
return currentInstructions;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerControllerB), "Update")]
public static void HoldCrouch(PlayerControllerB __instance)
{
PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
if (LethalCompanyPatchedPlugin.CrouchHold.Value && !((Object)(object)localPlayerController == (Object)null) && (!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || (((NetworkBehaviour)__instance).IsServer && !__instance.isHostPlayerObject)) && !__instance.isTestingPlayer && !__instance.inTerminalMenu && !__instance.isTypingChat && !__instance.isPlayerDead && !__instance.quickMenuManager.isMenuOpen && !IngamePlayerSettings.Instance.playerInput.actions.FindAction("Crouch", true).IsPressed() && localPlayerController.playerBodyAnimator.GetBool(_crouchingId) && CanJump(__instance))
{
localPlayerController.isCrouching = false;
localPlayerController.playerBodyAnimator.SetBool(_crouchingId, false);
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerControllerB), "Jump_performed")]
public static void PreJump(PlayerControllerB __instance)
{
if (__instance.isCrouching && CanJump(__instance))
{
__instance.isCrouching = false;
_tempCrouch = true;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerControllerB), "Jump_performed")]
public static void PostJump(PlayerControllerB __instance)
{
if (_tempCrouch)
{
__instance.isCrouching = true;
_tempCrouch = false;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerControllerB), "PlayerHitGroundEffects")]
public static void PostPlayerHitGroundEffects(PlayerControllerB __instance)
{
if (__instance.isCrouching)
{
__instance.playerBodyAnimator.SetTrigger(_startCrouchingId);
__instance.playerBodyAnimator.SetBool(_crouchingId, true);
}
}
private static bool CanJump(PlayerControllerB __instance)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
return !Physics.Raycast(((Component)__instance.gameplayCamera).transform.position, Vector3.up, ref __instance.hit, 0.72f, __instance.playersManager.collidersAndRoomMask, (QueryTriggerInteraction)1);
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}