Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of EnhancedControls v1.1.2
EnhancedControls.dll
Decompiled a year agousing System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")] [assembly: AssemblyCompany("EnhancedControls")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.1.2")] [assembly: AssemblyInformationalVersion("1.1.2")] [assembly: AssemblyProduct("EnhancedControls")] [assembly: AssemblyTitle("EnhancedControls")] [assembly: AssemblyVersion("1.1.2.0")] 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; } } } namespace EnhancedControls { [BepInPlugin("Mhz.EnhancedControls", "EnhancedControls", "1.1.0")] public class EnhancedControlsPlugin : BaseUnityPlugin { [HarmonyPatch(typeof(PlayerController), "Update")] public class PlayerControllerUpdatePatch { private static bool _wasSprintingLastFrame; private static float _crouchDuration; private const float MinCrouchTime = 0.4f; private static bool _jumpedFromCrouch; private static bool _sprintKeyPressedDuringCrouch; private static bool _justFinishedSliding; private static bool _wasSlidingLastFrame; private static float _slideFinishStandUpDelay; private const float SlideFinishDelay = 0.1f; private static FieldInfo? _jumpImpulseField; private static FieldInfo? _toggleCrouchField; private static FieldInfo? _toggleSprintField; private static MethodInfo? _checkBlockedMethod; private static Type? _playerCollisionStandType; private static FieldInfo? _playerCollisionStandInstanceField; private static FieldInfo? _slidingField; private static bool _reflectionInitialized; private static void InitializeReflection(PlayerController playerController) { if (_reflectionInitialized) { return; } try { _jumpImpulseField = ((object)playerController).GetType().GetField("JumpImpulse", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); _toggleCrouchField = ((object)playerController).GetType().GetField("toggleCrouch", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); _toggleSprintField = ((object)playerController).GetType().GetField("toggleSprint", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); _slidingField = ((object)playerController).GetType().GetField("Sliding", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); _playerCollisionStandType = Type.GetType("PlayerCollisionStand, Assembly-CSharp"); if (_playerCollisionStandType != null) { _playerCollisionStandInstanceField = _playerCollisionStandType.GetField("instance", BindingFlags.Static | BindingFlags.Public); _checkBlockedMethod = _playerCollisionStandType.GetMethod("CheckBlocked", BindingFlags.Instance | BindingFlags.Public); } _reflectionInitialized = true; } catch (Exception ex) { ManualLogSource? logger = _logger; if (logger != null) { logger.LogError((object)("初始化反射缓存失败 | Failed to initialize reflection cache: " + ex.Message)); } } } private static bool CheckCanStandUp() { if (!_reflectionInitialized || _playerCollisionStandInstanceField == null || _checkBlockedMethod == null) { return true; } try { object value = _playerCollisionStandInstanceField.GetValue(null); if (value == null) { return true; } return !(bool)_checkBlockedMethod.Invoke(value, null); } catch (Exception ex) { ManualLogSource? logger = _logger; if (logger != null) { logger.LogError((object)("检查头顶障碍物失败 | Failed to check overhead obstacles: " + ex.Message)); } return true; } } private static bool IsSliding(PlayerController playerController) { if (!_reflectionInitialized || _slidingField == null) { return false; } try { return (bool)_slidingField.GetValue(playerController); } catch (Exception ex) { ManualLogSource? logger = _logger; if (logger != null) { logger.LogError((object)("获取Sliding状态失败 | Failed to get Sliding state: " + ex.Message)); } return false; } } private static bool IsJumping(PlayerController playerController) { if (!_reflectionInitialized || _jumpImpulseField == null) { return false; } try { return (bool)_jumpImpulseField.GetValue(playerController); } catch (Exception ex) { ManualLogSource? logger = _logger; if (logger != null) { logger.LogError((object)("获取JumpImpulse失败 | Failed to get JumpImpulse: " + ex.Message)); } return false; } } private static void SetToggleCrouch(PlayerController playerController, bool value) { if (!_reflectionInitialized || _toggleCrouchField == null) { return; } try { _toggleCrouchField.SetValue(playerController, value); } catch (Exception ex) { ManualLogSource? logger = _logger; if (logger != null) { logger.LogError((object)("设置toggleCrouch失败 | Failed to set toggleCrouch: " + ex.Message)); } } } private static void SetToggleSprint(PlayerController playerController, bool value) { if (!_reflectionInitialized || _toggleSprintField == null) { return; } try { _toggleSprintField.SetValue(playerController, value); } catch (Exception ex) { ManualLogSource? logger = _logger; if (logger != null) { logger.LogError((object)("设置toggleSprint失败 | Failed to set toggleSprint: " + ex.Message)); } } } private static bool GetToggleSprint(PlayerController playerController) { if (!_reflectionInitialized || _toggleSprintField == null) { return false; } try { return (bool)_toggleSprintField.GetValue(playerController); } catch (Exception ex) { ManualLogSource? logger = _logger; if (logger != null) { logger.LogError((object)("获取toggleSprint失败 | Failed to get toggleSprint: " + ex.Message)); } return false; } } [HarmonyPostfix] public static void Postfix(PlayerController __instance) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Invalid comparison between Unknown and I4 if (!_reflectionInitialized) { InitializeReflection(__instance); } if ((int)GameDirector.instance.currentState != 2) { return; } ConfigEntry<bool> val = Instance?._enableResetSprintOnStop; if (val != null && val.Value && InputManager.instance.InputToggleGet((InputKey)15)) { bool toggleSprint = GetToggleSprint(__instance); bool flag = ((Vector3)(ref __instance.InputDirection)).magnitude <= 0.1f; if (toggleSprint && flag) { SetToggleSprint(__instance, value: false); } } if (!InputManager.instance.InputToggleGet((InputKey)12)) { return; } bool flag2 = IsSliding(__instance); val = Instance?._enableAutoStandAfterSlide; if (val != null && val.Value) { if (_wasSlidingLastFrame && !flag2) { _justFinishedSliding = true; _slideFinishStandUpDelay = 0.1f; } if (_justFinishedSliding && _slideFinishStandUpDelay > 0f) { _slideFinishStandUpDelay -= Time.deltaTime; if (_slideFinishStandUpDelay <= 0f) { if (__instance.Crouching && CheckCanStandUp()) { __instance.Crouching = false; SetToggleCrouch(__instance, value: false); } _justFinishedSliding = false; } } _wasSlidingLastFrame = flag2; } bool flag3 = SemiFunc.InputHold((InputKey)15); bool flag4 = SemiFunc.InputDown((InputKey)12); bool flag5 = SemiFunc.InputDown((InputKey)1); bool grounded = __instance.CollisionController.Grounded; bool flag6 = IsJumping(__instance); val = Instance?._enableCrouchJump; if (val != null && val.Value) { if (__instance.Crouching && flag5) { _jumpedFromCrouch = true; } if (_jumpedFromCrouch && grounded && !flag6) { if (CheckCanStandUp()) { __instance.Crouching = false; SetToggleCrouch(__instance, value: false); } _jumpedFromCrouch = false; } if (flag4) { _jumpedFromCrouch = false; } } val = Instance?._enableCrouchSprint; if (val == null || !val.Value || InputManager.instance.InputToggleGet((InputKey)15)) { return; } if (__instance.sprinting && flag4) { _wasSprintingLastFrame = true; return; } if (_wasSprintingLastFrame && __instance.Crouching) { if (!flag3) { _wasSprintingLastFrame = false; } return; } _wasSprintingLastFrame = __instance.sprinting; if (__instance.Crouching) { _crouchDuration += Time.deltaTime; } else { _crouchDuration = 0f; _sprintKeyPressedDuringCrouch = false; } if (__instance.Crouching && flag3 && _crouchDuration < 0.4f) { _sprintKeyPressedDuringCrouch = true; } if (__instance.Crouching && _sprintKeyPressedDuringCrouch && _crouchDuration >= 0.4f && CheckCanStandUp()) { __instance.Crouching = false; SetToggleCrouch(__instance, value: false); __instance.sprinting = true; _crouchDuration = 0f; _sprintKeyPressedDuringCrouch = false; } if (__instance.Crouching && flag3 && _crouchDuration >= 0.4f && CheckCanStandUp()) { __instance.Crouching = false; SetToggleCrouch(__instance, value: false); __instance.sprinting = true; _crouchDuration = 0f; } } } [HarmonyPatch(typeof(PhysGrabber), "PhysGrabLogic")] public class PhysGrabberLogicPatch { private static FieldInfo? _overrideGrabField; private static FieldInfo? _overrideGrabTargetField; private static bool _reflectionInitialized; private static void InitializeReflection() { if (_reflectionInitialized) { return; } try { _overrideGrabField = typeof(PhysGrabber).GetField("overrideGrab", BindingFlags.Instance | BindingFlags.NonPublic); _overrideGrabTargetField = typeof(PhysGrabber).GetField("overrideGrabTarget", BindingFlags.Instance | BindingFlags.NonPublic); _reflectionInitialized = true; } catch (Exception ex) { ManualLogSource? logger = _logger; if (logger != null) { logger.LogError((object)("初始化PhysGrabber反射缓存失败 | Failed to initialize PhysGrabber reflection cache: " + ex.Message)); } } } [HarmonyPrefix] public static void Prefix(PhysGrabber __instance) { EnhancedControlsPlugin? instance = Instance; if (instance == null || !(instance._disableItemProtection?.Value).GetValueOrDefault()) { return; } if (!_reflectionInitialized) { InitializeReflection(); } try { if (!(_overrideGrabField != null) || !(_overrideGrabTargetField != null)) { return; } bool flag = (bool)_overrideGrabField.GetValue(__instance); object value = _overrideGrabTargetField.GetValue(__instance); if (flag && value != null) { FieldInfo field = typeof(PhysGrabber).GetField("toggleGrab", BindingFlags.Instance | BindingFlags.NonPublic); if (field != null) { field.SetValue(__instance, true); } } } catch (Exception ex) { ManualLogSource? logger = _logger; if (logger != null) { logger.LogError((object)("应用物品保护机制禁用功能失败 | Failed to apply item protection disable feature: " + ex.Message)); } } } } private static ManualLogSource? _logger; private Harmony? _harmony; private ConfigEntry<bool>? _enableCrouchSprint; private ConfigEntry<bool>? _enableCrouchJump; private ConfigEntry<bool>? _enableResetSprintOnStop; private ConfigEntry<bool>? _enableAutoStandAfterSlide; private ConfigEntry<bool>? _disableItemProtection; public static EnhancedControlsPlugin? Instance { get; private set; } private void Awake() { //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Expected O, but got Unknown Instance = this; _logger = ((BaseUnityPlugin)this).Logger; _enableCrouchSprint = ((BaseUnityPlugin)this).Config.Bind<bool>("蹲下奔跑 | Crouch Sprint", "启用蹲下自动站起奔跑 | Enable Crouch-to-Sprint", true, "按奔跑键时自动站起并奔跑 | Auto stand up when pressing sprint key"); _enableCrouchJump = ((BaseUnityPlugin)this).Config.Bind<bool>("蹲下跳跃 | Crouch Jump", "启用蹲下跳跃后站立 | Enable Stand After Crouch Jump", true, "蹲下状态跳跃后不再自动蹲下 | Don't auto crouch after jumping from crouch"); _enableResetSprintOnStop = ((BaseUnityPlugin)this).Config.Bind<bool>("切换跑步 | Toggle Sprint", "停止移动自动取消跑步 | Auto Cancel Sprint on Stop", true, "切换跑步模式下停止移动时自动恢复走路状态 | Auto return to walking when stopped in toggle sprint mode"); _enableAutoStandAfterSlide = ((BaseUnityPlugin)this).Config.Bind<bool>("滑铲后站立 | Stand After Slide", "启用滑铲后自动站立 | Enable Auto Stand After Slide", false, "滑铲结束后自动恢复站立姿势 | Auto return to standing position after sliding"); _disableItemProtection = ((BaseUnityPlugin)this).Config.Bind<bool>("禁用保护 | Disable Protection", "禁用物品保护机制 | Disable Item Protection", false, "拿出物品后只需点击一次左键即可丢弃物品(需等待拿出动画播放完毕)| Only need to click once to drop an item after equipping (must wait for equipping animation to complete)"); _harmony = new Harmony("Mhz.EnhancedControls"); _harmony.PatchAll(); _logger.LogInfo((object)"增强控制MOD已启用 | Enhanced Controls MOD Enabled"); } } }