using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("Assisted Aiming")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Assisted Aiming")] [assembly: AssemblyCopyright("Copyright © 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("1833254b-a792-4c39-8f4e-1b46cde60ec4")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace Cnxc.AssistedAim; [BepInPlugin("cnxc.assistedaim", "Assisted Aim", "0.1.0")] public class AssistedAimPlugin : BaseUnityPlugin { internal static ManualLogSource Log; internal static ConfigEntry EnableAim; internal static ConfigEntry ToggleKey; internal static ConfigEntry AimCone; internal static ConfigEntry DebugLog; private Harmony _harmony; private void Awake() { //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Expected O, but got Unknown //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; EnableAim = ((BaseUnityPlugin)this).Config.Bind("General", "EnableAim", false, "启用自瞄(默认关闭)"); ToggleKey = ((BaseUnityPlugin)this).Config.Bind("General", "ToggleKey", (KeyCode)112, "开关按键"); AimCone = ((BaseUnityPlugin)this).Config.Bind("General", "AimCone", 180, new ConfigDescription("锁定角度(度,整数)", (AcceptableValueBase)(object)new AcceptableValueRange(1, 360), Array.Empty())); DebugLog = ((BaseUnityPlugin)this).Config.Bind("General", "DebugLog", false, "启用调试日志(每5秒输出状态)"); _harmony = new Harmony("cnxc.assistedaim"); _harmony.PatchAll(); Log.LogInfo((object)"Assisted Aim 已加载(固定锁定距离 ≤ 10m)"); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchAll("cnxc.assistedaim"); } } } [HarmonyPatch(typeof(InputManager))] public static class InputBlocker { private static bool _shouldBlock; public static void SetBlock(bool value) { _shouldBlock = value; } [HarmonyPrefix] [HarmonyPatch("GetMouseX")] public static bool OverrideMouseX(ref float __result) { if (!_shouldBlock) { return true; } __result = 0f; return false; } [HarmonyPrefix] [HarmonyPatch("GetMouseY")] public static bool OverrideMouseY(ref float __result) { if (!_shouldBlock) { return true; } __result = 0f; return false; } } [HarmonyPatch(typeof(PlayerAvatar))] public static class AimingPatch { private const float MAX_LOCK_DISTANCE = 10f; private static bool _active = true; private static Enemy _trackedEnemy = null; private static float _nextStatusLog = 0f; private const float StatusLogInterval = 5f; private static float _nextLockLog = 0f; private const float LockLogInterval = 1f; private static FieldInfo _localFlagField; private static FieldInfo _deadFlagField; private static FieldInfo _enemyRefField; [HarmonyPostfix] [HarmonyPatch("Update")] public static void OnPlayerUpdate(PlayerAvatar __instance) { //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_03f1: Unknown result type (might be due to invalid IL or missing references) //IL_03e3: Unknown result type (might be due to invalid IL or missing references) //IL_03f6: Unknown result type (might be due to invalid IL or missing references) //IL_0416: Unknown result type (might be due to invalid IL or missing references) //IL_0405: Unknown result type (might be due to invalid IL or missing references) //IL_041b: Unknown result type (might be due to invalid IL or missing references) //IL_041d: Unknown result type (might be due to invalid IL or missing references) //IL_041f: Unknown result type (might be due to invalid IL or missing references) if (!AssistedAimPlugin.EnableAim.Value) { return; } if (_localFlagField == null) { _localFlagField = typeof(PlayerAvatar).GetField("isLocal", BindingFlags.Instance | BindingFlags.NonPublic); _deadFlagField = typeof(PlayerAvatar).GetField("deadSet", BindingFlags.Instance | BindingFlags.NonPublic); Type typeFromHandle = typeof(EnemyParent); FieldInfo[] fields = typeFromHandle.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); FieldInfo[] array = fields; foreach (FieldInfo fieldInfo in array) { if (fieldInfo.FieldType == typeof(Enemy) || fieldInfo.FieldType.IsSubclassOf(typeof(Enemy))) { _enemyRefField = fieldInfo; break; } } } if (_localFlagField == null || _deadFlagField == null) { return; } bool flag = (bool)_localFlagField.GetValue(__instance); bool flag2 = (bool)_deadFlagField.GetValue(__instance); bool flag3 = SemiFunc.RunIsLevel() || SemiFunc.RunIsShop() || SemiFunc.RunIsLobby(); if (Input.GetKeyDown(AssistedAimPlugin.ToggleKey.Value)) { _active = !_active; AssistedAimPlugin.Log.LogInfo((object)("自瞄" + (_active ? "启用" : "禁用"))); if (!_active) { _trackedEnemy = null; InputBlocker.SetBlock(value: false); } } if (AssistedAimPlugin.DebugLog.Value) { float time = Time.time; if (time >= _nextStatusLog) { _nextStatusLog = time + 5f; LogStatus(__instance); } } if (!_active || !flag || flag2 || !flag3) { _trackedEnemy = null; InputBlocker.SetBlock(value: false); return; } EnemyDirector instance = EnemyDirector.instance; if ((Object)(object)instance == (Object)null) { return; } List enemiesSpawned = instance.enemiesSpawned; if (enemiesSpawned == null || enemiesSpawned.Count == 0) { _trackedEnemy = null; InputBlocker.SetBlock(value: false); return; } List list = new List(); foreach (EnemyParent item in enemiesSpawned) { if (!((Object)(object)item == (Object)null)) { Enemy val = null; if (_enemyRefField != null) { object? value = _enemyRefField.GetValue(item); val = (Enemy)((value is Enemy) ? value : null); } if ((Object)(object)val == (Object)null) { val = ((Component)item).GetComponentInChildren(); } if ((Object)(object)val != (Object)null && !IsDead(val)) { list.Add(val); } } } if (list.Count == 0) { _trackedEnemy = null; InputBlocker.SetBlock(value: false); return; } Enemy val2 = FindBestTarget(list); if ((Object)(object)val2 != (Object)null) { if ((Object)(object)_trackedEnemy == (Object)null || ((Object)_trackedEnemy).name != ((Object)val2).name) { _trackedEnemy = val2; if (AssistedAimPlugin.DebugLog.Value) { float time2 = Time.time; if (time2 >= _nextLockLog) { _nextLockLog = time2 + 1f; Vector3 val3 = (((Object)(object)val2.CenterTransform != (Object)null) ? val2.CenterTransform.position : ((Component)val2).transform.position); Vector3 val4 = (((Object)(object)PlayerController.instance != (Object)null) ? ((Component)PlayerController.instance).transform.position : Vector3.zero); float num = Vector3.Distance(val4, val3); AssistedAimPlugin.Log.LogInfo((object)$"锁定目标: {((Object)val2).name},距离 {num:F1}m"); } } } InputBlocker.SetBlock(value: true); ApplyLock(__instance, val2); return; } if ((Object)(object)_trackedEnemy != (Object)null) { _trackedEnemy = null; if (AssistedAimPlugin.DebugLog.Value) { AssistedAimPlugin.Log.LogInfo((object)"目标脱离锁定范围(>10m),释放鼠标"); } } InputBlocker.SetBlock(value: false); } private static void LogStatus(PlayerAvatar __instance) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0083: 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_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_01af: 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_0093: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: 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_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_01fe: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_0215: 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_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) Camera main = Camera.main; string arg = (((Object)(object)main != (Object)null) ? ((Component)main).transform.eulerAngles.y.ToString("F1") : "N/A"); List allAliveEnemies = GetAllAliveEnemies(); Enemy val = null; float num = float.MaxValue; float num2 = 0f; if (allAliveEnemies != null && allAliveEnemies.Count > 0) { Vector3 val2 = (((Object)(object)PlayerController.instance != (Object)null) ? ((Component)PlayerController.instance).transform.position : Vector3.zero); Vector3 val3 = (((Object)(object)main != (Object)null) ? ((Component)main).transform.position : Vector3.zero); Vector3 val4 = (((Object)(object)main != (Object)null) ? ((Component)main).transform.forward : Vector3.forward); foreach (Enemy item in allAliveEnemies) { Vector3 val5 = (((Object)(object)item.CenterTransform != (Object)null) ? item.CenterTransform.position : ((Component)item).transform.position); float num3 = Vector3.Distance(val2, val5); if (num3 < num) { num = num3; val = item; if ((Object)(object)main != (Object)null) { Vector3 val6 = val5 - val3; num2 = Vector3.Angle(val4, val6); } } } } string arg2; if (!((Object)(object)_trackedEnemy != (Object)null)) { arg2 = ((!((Object)(object)val != (Object)null)) ? "无锁定,无活敌" : $"无锁定,最近敌人 {((Object)val).name},距离 {num:F1}m,角度 {num2:F1}°(锁定距离上限 {10f}m)"); } else { Vector3 val7 = (((Object)(object)_trackedEnemy.CenterTransform != (Object)null) ? _trackedEnemy.CenterTransform.position : ((Component)_trackedEnemy).transform.position); Vector3 val8 = (((Object)(object)PlayerController.instance != (Object)null) ? ((Component)PlayerController.instance).transform.position : Vector3.zero); float num4 = Vector3.Distance(val8, val7); float num5 = 0f; if ((Object)(object)main != (Object)null) { Vector3 val9 = val7 - ((Component)main).transform.position; num5 = Vector3.Angle(((Component)main).transform.forward, val9); } arg2 = $"锁定 {((Object)_trackedEnemy).name},距离 {num4:F1}m,角度 {num5:F1}°"; } int valueOrDefault = (EnemyDirector.instance?.enemiesSpawned?.Count).GetValueOrDefault(); AssistedAimPlugin.Log.LogInfo((object)$"自瞄状态 | 摄像机Y角:{arg}° | 活敌数:{valueOrDefault} | {arg2}"); } private static List GetAllAliveEnemies() { List list = new List(); EnemyDirector instance = EnemyDirector.instance; if ((Object)(object)instance == (Object)null) { return list; } List enemiesSpawned = instance.enemiesSpawned; if (enemiesSpawned == null) { return list; } foreach (EnemyParent item in enemiesSpawned) { if (!((Object)(object)item == (Object)null)) { Enemy val = null; if (_enemyRefField != null) { object? value = _enemyRefField.GetValue(item); val = (Enemy)((value is Enemy) ? value : null); } if ((Object)(object)val == (Object)null) { val = ((Component)item).GetComponentInChildren(); } if ((Object)(object)val != (Object)null && !IsDead(val)) { list.Add(val); } } } return list; } private static Enemy FindBestTarget(List enemies) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0043: 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_0065: 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) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: 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_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: 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_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) float num = AssistedAimPlugin.AimCone.Value; Enemy result = null; float num2 = float.MaxValue; Camera main = Camera.main; if ((Object)(object)main == (Object)null) { return null; } Vector3 position = ((Component)main).transform.position; Vector3 forward = ((Component)main).transform.forward; Vector3 val = (((Object)(object)PlayerController.instance != (Object)null) ? ((Component)PlayerController.instance).transform.position : position); foreach (Enemy enemy in enemies) { if ((Object)(object)enemy == (Object)null) { continue; } Vector3 val2 = (((Object)(object)enemy.CenterTransform != (Object)null) ? enemy.CenterTransform.position : ((Component)enemy).transform.position); if (((Vector3)(ref val2)).sqrMagnitude < 0.01f) { continue; } float num3 = Vector3.Distance(val, val2); if (num3 > 10f) { continue; } Vector3 val3 = val2 - position; if (!(((Vector3)(ref val3)).sqrMagnitude < 0.001f)) { float num4 = Vector3.Angle(forward, val3); if (!(num4 > num) && num3 < num2) { num2 = num3; result = enemy; } } } return result; } private static void ApplyLock(PlayerAvatar player, Enemy target) { //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: 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_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: 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_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)player == (Object)null || (Object)(object)target == (Object)null) { _trackedEnemy = null; InputBlocker.SetBlock(value: false); return; } Transform val = target.CenterTransform ?? ((Component)target).transform; if ((Object)(object)val == (Object)null) { _trackedEnemy = null; InputBlocker.SetBlock(value: false); return; } PlayerController instance = PlayerController.instance; if ((Object)(object)instance == (Object)null || (Object)(object)instance.cameraGameObject == (Object)null) { _trackedEnemy = null; InputBlocker.SetBlock(value: false); return; } Camera main = Camera.main; if (!((Object)(object)main == (Object)null)) { Vector3 val2 = val.position - ((Component)main).transform.position; if (!(((Vector3)(ref val2)).sqrMagnitude < 0.001f)) { Quaternion localRotation = Quaternion.LookRotation(val2, Vector3.up); instance.cameraGameObject.transform.localRotation = localRotation; } } } private static bool IsDead(Enemy e) { if ((Object)(object)e == (Object)null) { return true; } EnemyHealth component = ((Component)e).GetComponent(); if ((Object)(object)component != (Object)null) { FieldInfo field = typeof(EnemyHealth).GetField("dead", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { return (bool)field.GetValue(component); } } return false; } }