using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; 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 = ".NET Standard 2.1")] [assembly: AssemblyCompany("FishAimAssist")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("FishAimAssist")] [assembly: AssemblyTitle("FishAimAssist")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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 FishAimAssist { [BepInPlugin("com.KingIDFK.fishaimassist", "ReymAssist", "1.0.0")] public class AimAssistPlugin : BaseUnityPlugin { public const float ConeAngleDegrees = 6f; public const float MaxDistance = 150f; public const float PullStrength = 0.68f; internal static Camera CachedCamera; private void Awake() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) new Harmony("com.KingIDFK.fishaimassist").PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Fish Aim Assist loaded. Press F9 near a creature to dump aim-assist debug info to this log."); } private void Update() { //IL_003d: 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) if (Input.GetKeyDown((KeyCode)290)) { if ((Object)(object)CachedCamera == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"F9 pressed but no local camera is cached yet (are you holding a weapon?)."); } else { TargetSearch.DebugDump(((Component)CachedCamera).transform.position, ((Component)CachedCamera).transform.forward, ((BaseUnityPlugin)this).Logger); } } } } internal readonly struct TargetHit { public readonly Transform Transform; public readonly Vector3 AimPoint; public TargetHit(Transform t, Vector3 p) { //IL_0009: 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) Transform = t; AimPoint = p; } } internal static class TargetSearch { private static int EnvironmentMask => LayerMask.op_Implicit(GameInfo.LevelLayer); public static bool TryFindBestTarget(Vector3 origin, Vector3 forward, out TargetHit result) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: 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_00ab: 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_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00de: 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_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) Creature[] array = Object.FindObjectsByType((FindObjectsInactive)0); int environmentMask = EnvironmentMask; Transform val = null; Vector3 p = default(Vector3); float num = 6f; float num2 = 150f; Creature[] array2 = array; foreach (Creature val2 in array2) { if ((Object)(object)val2 == (Object)null || val2.IsDead) { continue; } Collider[] componentsInChildren = ((Component)val2).GetComponentsInChildren(); if (componentsInChildren.Length == 0) { continue; } Bounds bounds = componentsInChildren[0].bounds; for (int j = 1; j < componentsInChildren.Length; j++) { ((Bounds)(ref bounds)).Encapsulate(componentsInChildren[j].bounds); } Vector3 val3 = ((Bounds)(ref bounds)).center - origin; float magnitude = ((Vector3)(ref val3)).magnitude; if (!(magnitude > num2) && !(magnitude <= 0f)) { float num3 = Vector3.Angle(forward, val3); if (!(num3 >= num) && TryGetPreferredBodyPoint(val2, origin, bounds, componentsInChildren, environmentMask, out var point)) { num = num3; val = ((Component)val2).transform; p = point; } } } if ((Object)(object)val != (Object)null) { result = new TargetHit(val, p); return true; } result = default(TargetHit); return false; } private static bool TryGetPreferredBodyPoint(Creature creature, Vector3 origin, Bounds bounds, Collider[] colliders, int environmentMask, out Vector3 point) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0074: 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_007b: 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_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: 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_009d: 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_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: 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_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012c: 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_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) Collider val = null; float num = float.NegativeInfinity; Bounds bounds2; foreach (Collider val2 in colliders) { Transform transform = ((Component)creature).transform; bounds2 = val2.bounds; float z = transform.InverseTransformPoint(((Bounds)(ref bounds2)).center).z; if (z > creature.HeadPos && z > num) { num = z; val = val2; } } if ((Object)(object)val != (Object)null) { bounds2 = val.bounds; if (IsVisible(origin, ((Bounds)(ref bounds2)).center, environmentMask)) { bounds2 = val.bounds; point = ((Bounds)(ref bounds2)).center; return true; } } if (IsVisible(origin, ((Bounds)(ref bounds)).center, environmentMask)) { point = ((Bounds)(ref bounds)).center; return true; } Collider val3 = null; Vector3 val4 = default(Vector3); float num2 = float.MaxValue; foreach (Collider val5 in colliders) { if (!((Object)(object)val5 == (Object)(object)val)) { bounds2 = val5.bounds; Vector3 center = ((Bounds)(ref bounds2)).center; Vector3 val6 = center - ((Bounds)(ref bounds)).center; float sqrMagnitude = ((Vector3)(ref val6)).sqrMagnitude; if (sqrMagnitude < num2 && IsVisible(origin, center, environmentMask)) { num2 = sqrMagnitude; val3 = val5; val4 = center; } } } if ((Object)(object)val3 != (Object)null) { point = val4; return true; } point = default(Vector3); return false; } private static bool IsVisible(Vector3 origin, Vector3 point, int environmentMask) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) Vector3 val = point - origin; float magnitude = ((Vector3)(ref val)).magnitude; if (magnitude <= 0f) { return true; } RaycastHit val2 = default(RaycastHit); return !Physics.Raycast(origin, val / magnitude, ref val2, Mathf.Max(magnitude - 0.05f, 0f), environmentMask, (QueryTriggerInteraction)1); } public static void DebugDump(Vector3 origin, Vector3 forward, ManualLogSource logger) { //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: 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_0083: 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_0118: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0096: 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_00bc: 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_00c1: 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) //IL_00da: Unknown result type (might be due to invalid IL or missing references) Creature[] array = Object.FindObjectsByType((FindObjectsInactive)0); int environmentMask = EnvironmentMask; logger.LogInfo((object)$"--- Fish Aim Assist debug dump: {array.Length} Creature(s) found in scene ---"); List<(float, string)> list = new List<(float, string)>(); Creature[] array2 = array; foreach (Creature val in array2) { if ((Object)(object)val == (Object)null) { continue; } Collider[] componentsInChildren = ((Component)val).GetComponentsInChildren(); Vector3 val2 = ((Component)val).transform.position; string arg = "n/a (sin colliders)"; if (componentsInChildren.Length != 0) { Bounds bounds = componentsInChildren[0].bounds; for (int j = 1; j < componentsInChildren.Length; j++) { ((Bounds)(ref bounds)).Encapsulate(componentsInChildren[j].bounds); } val2 = ((Bounds)(ref bounds)).center; arg = ((!TryGetPreferredBodyPoint(val, origin, bounds, componentsInChildren, environmentMask, out var point)) ? "totalmente tapada" : ((point == ((Bounds)(ref bounds)).center) ? "visible (pecho/centro)" : "visible (cabeza u otra parte)")); } Vector3 val3 = val2 - origin; float magnitude = ((Vector3)(ref val3)).magnitude; float num = ((magnitude > 0f) ? Vector3.Angle(forward, val3) : (-1f)); string item = $"'{((Object)val).name}' | dead={val.IsDead} " + $"| dist={magnitude:0.00} (max {150f:0.0}) " + $"| angle={num:0.0} (cone {6f:0.0}) | visibility={arg}"; list.Add(((num < 0f) ? 9999f : num, item)); } list.Sort(((float angle, string text) a, (float angle, string text) b) => a.angle.CompareTo(b.angle)); int num2 = 0; foreach (var item2 in list) { logger.LogInfo((object)item2.Item2); num2++; if (num2 >= 5) { break; } } if (list.Count == 0) { logger.LogInfo((object)"No Creature instances found in the scene at all."); } logger.LogInfo((object)"--- end debug dump ---"); } } [HarmonyPatch(typeof(Weapon), "Shoot")] public static class Weapon_Shoot_AimAssist { [ThreadStatic] private static Transform _firePoint; [ThreadStatic] private static Quaternion _savedLocalRot; [ThreadStatic] private static bool _restoreNeeded; private static void Prefix(Weapon __instance) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0053: 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_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007a: 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_0084: 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_008d: 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_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) _restoreNeeded = false; if (!WeaponCache.TryGetCamera(__instance, out var camTransform)) { return; } Transform firePoint = __instance.Attachments.FirePoint; if (!((Object)(object)firePoint == (Object)null)) { _firePoint = firePoint; _savedLocalRot = firePoint.localRotation; _restoreNeeded = true; Vector3 val = camTransform.forward; if (TargetSearch.TryFindBestTarget(camTransform.position, camTransform.forward, out var result)) { Vector3 val2 = result.AimPoint - firePoint.position; val = ((Vector3)(ref val2)).normalized; } Quaternion val3 = Quaternion.LookRotation(val, camTransform.up); float num = (((Object)(object)result.Transform != (Object)null) ? 0.68f : 1f); firePoint.rotation = Quaternion.Slerp(firePoint.rotation, val3, num); } } private static void Postfix() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) if (_restoreNeeded && (Object)(object)_firePoint != (Object)null) { _firePoint.localRotation = _savedLocalRot; } } } internal static class WeaponCache { private class Entry { public bool IsLocal; public Transform CamTransform; } private static readonly ConditionalWeakTable Cache = new ConditionalWeakTable(); private static readonly FieldInfo HolderField = AccessTools.Field(typeof(Tool), "_holder"); public static void Populate(Weapon instance) { Entry entry = new Entry { IsLocal = false, CamTransform = null }; object value = HolderField.GetValue(instance); if (value != null) { Type type = value.GetType(); object obj = AccessTools.Property(type, "Owner")?.GetValue(value); PropertyInfo propertyInfo = ((obj != null) ? AccessTools.Property(obj.GetType(), "IsLocalClient") : null); if (propertyInfo != null && (bool)propertyInfo.GetValue(obj)) { object? obj2 = AccessTools.Property(type, "CamObject")?.GetValue(value); Transform val = (Transform)((obj2 is Transform) ? obj2 : null); entry.IsLocal = (Object)(object)val != (Object)null; entry.CamTransform = val; } } Cache.Remove(instance); Cache.Add(instance, entry); } public static void Clear(Weapon instance) { Cache.Remove(instance); } public static bool TryGetCamera(Weapon instance, out Transform camTransform) { if (!Cache.TryGetValue(instance, out var value)) { Populate(instance); Cache.TryGetValue(instance, out value); } camTransform = value?.CamTransform; return value != null && value.IsLocal && (Object)(object)camTransform != (Object)null; } } [HarmonyPatch(typeof(Weapon), "OnPickUp")] public static class Weapon_OnPickUp_CachePopulate { private static void Postfix(Weapon __instance) { WeaponCache.Populate(__instance); } } [HarmonyPatch(typeof(Weapon), "OnDrop")] public static class Weapon_OnDrop_CacheClear { private static void Postfix(Weapon __instance) { WeaponCache.Clear(__instance); } } [HarmonyPatch(typeof(Weapon), "Update")] public static class Weapon_Camera_Update { private static void Postfix(Weapon __instance) { if (WeaponCache.TryGetCamera(__instance, out var camTransform)) { AimAssistPlugin.CachedCamera = ((Component)camTransform).GetComponent() ?? ((Component)camTransform).GetComponentInChildren(); } } } }