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 TargetLockOn v0.9.0
TargetLockOn.dll
Decompiled 3 days ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = "")] [assembly: AssemblyVersion("0.0.0.0")] namespace VKTR.TargetLockOn; internal static class Aim { private const int LeadIterations = 3; private const float MaxLeadSeconds = 3f; internal static Vector3 Toward(in Shot s, ItemData weapon, Attack atk, out bool reachable) { //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_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0055: 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_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_007e: 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_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0092: 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) Character target = Lock.Target; Vector3 val = AimTarget(); Vector3 val2 = (Plugin.LeadMovingTargets.Value ? Lock.TargetVelocity : Vector3.zero); if (!target.IsFlying()) { val2.y = 0f; } float cap = ((weapon != null && Ballistics.IsBomb(weapon, atk)) ? Plugin.BombLockRange.Value : 0f); Vector3 aim = Vector3.forward; float time = 0f; reachable = false; for (int i = 0; i < 3; i++) { Vector3 target2 = Cap(s.Origin, val + val2 * Mathf.Min(time, 3f), cap); reachable = Ballistics.Solve(in s, target2, out aim, out time); if (((Vector3)(ref val2)).sqrMagnitude < 0.01f) { break; } } return aim; } private static Vector3 AimTarget() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: 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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0032: 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_003d: 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) Vector3 aimPoint = Lock.AimPoint; GameCamera instance = GameCamera.instance; if (Plugin.AimAt.Value == AimAtMode.Target || (Object)(object)instance == (Object)null) { return aimPoint; } Transform transform = ((Component)instance).transform; return transform.position + transform.forward * Vector3.Distance(transform.position, aimPoint); } private static Vector3 Cap(Vector3 origin, Vector3 point, float cap) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: 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_0023: 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_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: 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) if (cap <= 0f) { return point; } Vector3 val = point - origin; Vector2 val2 = new Vector2(val.x, val.z); float magnitude = ((Vector2)(ref val2)).magnitude; if (!(magnitude > cap)) { return point; } return origin + val * (cap / magnitude); } } [HarmonyPatch(typeof(Attack), "GetProjectileSpawnPoint")] internal static class Attack_GetProjectileSpawnPoint_Patch { private static void Postfix(Attack __instance, ref Vector3 spawnPoint, ref Vector3 aimDir) { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) try { if (!Plugin.BallisticAim.Value || (Object)(object)Lock.Target == (Object)null) { return; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || (Object)(object)R.AttackCharacter.Invoke(__instance) != (Object)(object)localPlayer) { return; } float num = R.AttackDraw.Invoke(__instance); if (Ballistics.Build(__instance, R.AttackAmmo.Invoke(__instance), num, spawnPoint, out var shot)) { aimDir = Aim.Toward(in shot, R.AttackWeapon.Invoke(__instance), __instance, out var reachable); if (Plugin.DebugLog.Value) { ManualLogSource log = Plugin.Log; string text = $"Shot at {Lock.Target.m_name}: speed {shot.Speed:0.0}, gravity {shot.Gravity:0.00}, "; string text2 = $"drag {shot.Drag:0.0000}, launch {shot.LaunchAngle:0.0}, draw {num:0.00}, "; string text3 = $"elevation {Mathf.Asin(Mathf.Clamp(aimDir.y, -1f, 1f)) * 57.29578f:0.0}, "; Vector3 targetVelocity = Lock.TargetVelocity; log.LogInfo((object)(text + text2 + text3 + string.Format("lead {0:0.0} m/s{1}", ((Vector3)(ref targetVelocity)).magnitude, reachable ? "" : ", OUT OF RANGE"))); } } } catch (Exception e) { Diag.Once("BallisticAim", e); } } } public static class Api { public static bool CameraBusy { get { if (!((Object)(object)Lock.Target != (Object)null)) { return Framing.FreeAim; } return true; } } } internal struct Shot { public Vector3 Origin; public float Speed; public float Gravity; public float Drag; public float LaunchAngle; public float Ttl; public float Radius; } internal static class Ballistics { private const int MaxSteps = 750; private const float PointSpacing = 1.5f; private const float MaxPreviewDistance = 150f; private static readonly Dictionary<GameObject, Projectile> _projectiles = new Dictionary<GameObject, Projectile>(); private static readonly Dictionary<GameObject, float> _radii = new Dictionary<GameObject, float>(); private static readonly RaycastHit[] _hits = (RaycastHit[])(object)new RaycastHit[16]; private static int _solidMask; private static Humanoid _jointOwner; private static string _jointName; private static Transform _joint; private static int SolidMask { get { if (_solidMask == 0) { return _solidMask = LayerMask.GetMask(new string[12] { "Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "terrain", "character", "character_net", "character_ghost", "hitbox", "character_noenv", "vehicle" }); } return _solidMask; } } internal static Attack RangedAttack(ItemData item) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Invalid comparison between Unknown and I4 //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Invalid comparison between Unknown and I4 //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Invalid comparison between Unknown and I4 if (item == null) { return null; } SharedData shared = item.m_shared; if ((int)shared.m_skillType == 104) { return null; } if (shared.m_attack != null && (int)shared.m_attack.m_attackType == 2) { return shared.m_attack; } if (shared.m_secondaryAttack != null && (int)shared.m_secondaryAttack.m_attackType == 2) { return shared.m_secondaryAttack; } return null; } internal static bool IsBomb(ItemData item, Attack atk) { if (atk.m_consumeItem) { return item.m_shared.m_maxStackSize > 1; } return false; } internal static ItemData FindAmmo(Humanoid h, ItemData weapon) { string ammoType = weapon.m_shared.m_ammoType; if (string.IsNullOrEmpty(ammoType)) { return null; } Inventory inventory = h.GetInventory(); ItemData val = h.GetAmmoItem(); if (val != null && (!inventory.ContainsItem(val) || val.m_shared.m_ammoType != ammoType)) { val = null; } return val ?? inventory.GetAmmoItem(ammoType, (string)null); } internal static bool Build(Attack atk, ItemData ammo, float draw, Vector3 origin, out Shot shot) { //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) shot = default(Shot); GameObject attackProjectile = atk.m_attackProjectile; float num = atk.m_projectileVel; float num2 = atk.m_projectileVelMin; AnimationCurve drawVelocityCurve = atk.m_drawVelocityCurve; if (ammo != null && (Object)(object)ammo.m_shared.m_attack.m_attackProjectile != (Object)null) { Attack attack = ammo.m_shared.m_attack; attackProjectile = attack.m_attackProjectile; num += attack.m_projectileVel; num2 += attack.m_projectileVelMin; drawVelocityCurve = attack.m_drawVelocityCurve; } if ((Object)(object)attackProjectile == (Object)null) { return false; } if (!_projectiles.TryGetValue(attackProjectile, out var value)) { value = attackProjectile.GetComponent<Projectile>(); _projectiles[attackProjectile] = value; } if ((Object)(object)value == (Object)null) { return false; } float num3 = (atk.m_bowDraw ? Mathf.Lerp(num2, num, (drawVelocityCurve != null) ? drawVelocityCurve.Evaluate(draw) : draw) : ((!atk.m_randomVelocity) ? num : ((num2 + num) * 0.5f))); shot.Origin = origin; shot.Speed = num3; shot.Gravity = value.m_gravity; shot.Drag = value.m_drag; shot.LaunchAngle = atk.m_launchAngle; shot.Ttl = value.m_ttl; shot.Radius = ImpactRadius(attackProjectile, value); return num3 > 0.1f; } private static float ImpactRadius(GameObject prefab, Projectile proj) { if (_radii.TryGetValue(prefab, out var value)) { return value; } value = Mathf.Max(proj.m_aoe, AoeRadius(proj.m_spawnOnHit)); if (proj.m_randomSpawnOnHit != null) { foreach (GameObject item in proj.m_randomSpawnOnHit) { value = Mathf.Max(value, AoeRadius(item)); } } _radii[prefab] = value; Diag.Debug($"Impact radius of {((Object)prefab).name}: {value:0.00} m (projectile aoe {proj.m_aoe:0.00}, " + "spawn on hit " + (((Object)(object)proj.m_spawnOnHit != (Object)null) ? ((Object)proj.m_spawnOnHit).name : "none") + ")"); return value; } private static float AoeRadius(GameObject go) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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_0056: 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) if ((Object)(object)go == (Object)null) { return 0f; } float num = 0f; Aoe[] componentsInChildren = go.GetComponentsInChildren<Aoe>(true); foreach (Aoe val in componentsInChildren) { if ((Object)(object)val.m_useCollider != (Object)null) { Vector3 val2 = Vector3.Scale(val.m_useCollider.size, ((Component)val.m_useCollider).transform.lossyScale); num = Mathf.Max(num, Mathf.Max(val2.x, val2.z) * 0.5f); } else { num = Mathf.Max(num, val.m_radius); } } return num; } internal static Vector3 JointLocal(Humanoid h, Attack atk) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: 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_0029: Unknown result type (might be due to invalid IL or missing references) Transform transform = ((Component)h).transform; return Quaternion.Inverse(transform.rotation) * (Origin(h, atk).position - transform.position); } internal static Vector3 SpawnPoint(Humanoid h, Attack atk, Quaternion body, Vector3 jointLocal) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //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_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0033: 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_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_004d: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) return ((Component)h).transform.position + body * jointLocal + body * Vector3.up * atk.m_attackHeight + body * Vector3.forward * atk.m_attackRange + body * Vector3.right * atk.m_attackOffset; } private static Transform Origin(Humanoid h, Attack atk) { string attackOriginJoint = atk.m_attackOriginJoint; if (string.IsNullOrEmpty(attackOriginJoint)) { return ((Component)h).transform; } if ((Object)(object)_jointOwner != (Object)(object)h || _jointName != attackOriginJoint) { _jointOwner = h; _jointName = attackOriginJoint; GameObject visual = ((Character)h).GetVisual(); _joint = (((Object)(object)visual != (Object)null) ? Utils.FindChild(visual.transform, attackOriginJoint, (IterativeSearchType)0) : null); } if (!((Object)(object)_joint != (Object)null)) { return ((Component)h).transform; } return _joint; } internal static Vector3 VanillaAim(Humanoid h, Attack atk, Vector3 spawn, Quaternion body) { //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_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0033: 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) //IL_0015: 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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) Vector3 val = h.GetAimDir(spawn); if (atk.m_useCharacterFacing) { Vector3 forward = Vector3.forward; if (atk.m_useCharacterFacingYAim) { forward.y = val.y; } val = body * forward; } return val; } internal static Vector3 Launch(Vector3 aim, float launchAngle) { //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) //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_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001c: 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) if (launchAngle == 0f) { return aim; } return Quaternion.AngleAxis(launchAngle, Vector3.Cross(Vector3.up, aim)) * aim; } private static int Steps(in Shot s, float dt) { return Mathf.Min((s.Ttl > 0f) ? Mathf.CeilToInt(s.Ttl / dt) : 750, 750); } internal static bool Solve(in Shot s, Vector3 target, out Vector3 aim, out float time) { //IL_0000: 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_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: 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_007c: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: 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_0048: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) Vector3 val = target - s.Origin; Vector2 val2 = new Vector2(val.x, val.z); float magnitude = ((Vector2)(ref val2)).magnitude; if (magnitude < 0.25f) { aim = ((((Vector3)(ref val)).sqrMagnitude > 1E-06f) ? ((Vector3)(ref val)).normalized : Vector3.forward); time = 0f; return true; } float fixedDeltaTime = Time.fixedDeltaTime; float elev; bool result = Solver2D.Solve(s.Speed, s.Gravity, s.Drag, fixedDeltaTime, Steps(in s, fixedDeltaTime), magnitude, val.y, out elev, out time); float num = Mathf.Clamp(elev + s.LaunchAngle, -89f, 89f); float num2 = Mathf.Atan2(val.x, val.z) * 57.29578f; aim = Quaternion.Euler(0f - num, num2, 0f) * Vector3.forward; return result; } internal static int Trace(in Shot s, Vector3 launchDir, Vector3[] pts, Transform shooter, out bool hit, out RaycastHit hitInfo) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: 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_0049: 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_0057: 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_0065: 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_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_008c: 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_0097: 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_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: 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_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: 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_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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_00f7: 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_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) hit = false; hitInfo = default(RaycastHit); float fixedDeltaTime = Time.fixedDeltaTime; int num = Steps(in s, fixedDeltaTime); Vector3 val = s.Origin; Vector3 val2 = ((Vector3)(ref launchDir)).normalized * s.Speed; Vector3 val3 = val; float num2 = 0f; int num3 = 0; pts[num3++] = val; for (int i = 1; i <= num; i++) { val2 += Vector3.down * (s.Gravity * fixedDeltaTime); val2 -= val2 * Mathf.Min(1f, ((Vector3)(ref val2)).magnitude * s.Drag * fixedDeltaTime); val += val2 * fixedDeltaTime; Vector3 val4 = val - val3; float magnitude = ((Vector3)(ref val4)).magnitude; if (!(magnitude < 1.5f) || i >= num) { if (Cast(val3, val, shooter, out hitInfo)) { pts[num3++] = ((RaycastHit)(ref hitInfo)).point; hit = true; return num3; } pts[num3++] = val; val3 = val; num2 += magnitude; if (num3 >= pts.Length || num2 >= 150f) { break; } } } return num3; } private static bool Cast(Vector3 a, Vector3 b, Transform shooter, out RaycastHit hit) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: 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_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0021: 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_0024: 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_0054: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) hit = default(RaycastHit); Vector3 val = b - a; float magnitude = ((Vector3)(ref val)).magnitude; if (magnitude < 0.0001f) { return false; } int num = Physics.RaycastNonAlloc(a, val / magnitude, _hits, magnitude, SolidMask); float num2 = float.MaxValue; bool result = false; for (int i = 0; i < num; i++) { RaycastHit val2 = _hits[i]; if (!(((RaycastHit)(ref val2)).distance >= num2) && !((Object)(object)((RaycastHit)(ref val2)).collider == (Object)null) && (!((Object)(object)shooter != (Object)null) || !((Object)(object)((Component)((RaycastHit)(ref val2)).collider).transform.root == (Object)(object)shooter))) { num2 = ((RaycastHit)(ref val2)).distance; hit = val2; result = true; } } return result; } } internal static class FaceCamera { private const float MaxSeconds = 1.5f; private const float DoneAngle = 3f; private static float _until; internal static void Request() { _until = Time.time + 1.5f; } internal static bool Active(Player p) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: 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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: 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) if (_until <= 0f) { return false; } Vector3 v = ((Character)p).GetLookYaw() * Vector3.forward; if (!(Time.time > _until)) { Vector3 moveDir = ((Character)p).GetMoveDir(); if (!(((Vector3)(ref moveDir)).sqrMagnitude > 0.01f) && !(Vector3.Angle(Flat(((Component)p).transform.forward), Flat(v)) < 3f)) { return true; } } _until = 0f; return false; } private static Vector3 Flat(Vector3 v) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) return new Vector3(v.x, 0f, v.z); } } internal static class Facing { private const float MinDistance = 0.3f; private static Quaternion _saved; private static Quaternion _written; private static bool _swapped; private static bool TargetYaw(Character c, out Quaternion yaw) { //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_0030: 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_0040: 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_0063: Unknown result type (might be due to invalid IL or missing references) //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) yaw = Quaternion.identity; if ((Object)(object)c == (Object)null || (Object)(object)c != (Object)(object)Player.m_localPlayer || (Object)(object)Lock.Target == (Object)null) { return false; } Vector3 val = Lock.AimPoint - ((Component)c).transform.position; val.y = 0f; if (((Vector3)(ref val)).sqrMagnitude < 0.09f) { return false; } yaw = Quaternion.LookRotation(val); return true; } internal static Quaternion BodyYaw(Character c) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (!TargetYaw(c, out var yaw)) { return c.GetLookYaw(); } return yaw; } internal static void Push(Character c) { //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_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) _swapped = false; if (TargetYaw(c, out var yaw)) { ref Quaternion reference = ref R.LookYaw.Invoke(c); _saved = reference; reference = (_written = yaw); _swapped = true; } } internal static void Pop(Character c) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) if (_swapped) { _swapped = false; ref Quaternion reference = ref R.LookYaw.Invoke(c); if (reference == _written) { reference = _saved; } } } } [HarmonyPatch(typeof(Character), "UpdateRotation")] internal static class Character_UpdateRotation_Patch { private static void Prefix(Character __instance) { try { Facing.Push(__instance); } catch (Exception e) { Diag.Once("FacingTarget", e); } } private static void Finalizer(Character __instance) { try { Facing.Pop(__instance); } catch (Exception e) { Diag.Once("FacingTargetRestore", e); } } } [HarmonyPatch(typeof(Attack), "Start")] internal static class Attack_Start_Patch { private static void Prefix(Humanoid character) { try { Facing.Push((Character)(object)character); } catch (Exception e) { Diag.Once("AttackFacingTarget", e); } } private static void Finalizer(Humanoid character) { try { Facing.Pop((Character)(object)character); } catch (Exception e) { Diag.Once("AttackFacingTargetRestore", e); } } } [HarmonyPatch(typeof(Player), "AlwaysRotateCamera")] internal static class Player_AlwaysRotateCamera_Patch { private static void Postfix(Player __instance, ref bool __result) { try { if (!__result && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer)) { if (FaceCamera.Active(__instance)) { __result = true; } else if (Plugin.StrafeWhileLocked.Value && !((Object)(object)Lock.Target == (Object)null) && !((Character)__instance).IsRunning() && !((Character)__instance).IsSwimming()) { __result = true; } } } catch (Exception e) { Diag.Once("Strafe", e); } } } [HarmonyPatch(/*Could not decode attribute arguments.*/)] internal static class Player_AttackTowardsPlayerLookDir_Patch { private static void Postfix(Player __instance, ref bool __result) { if (!__result && Plugin.AttackTowardsTarget.Value && (Object)(object)Lock.Target != (Object)null && (Object)(object)__instance == (Object)(object)Player.m_localPlayer) { __result = true; } } } [HarmonyPatch(typeof(Attack), "GetMeleeAttackDir")] internal static class Attack_GetMeleeAttackDir_Patch { private static void Postfix(Attack __instance, ref Transform originJoint, ref Vector3 attackDir) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0061: 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_0086: Unknown result type (might be due to invalid IL or missing references) //IL_009c: 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) try { if (Plugin.AttackTowardsTarget.Value && !((Object)(object)originJoint == (Object)null) && !((Object)(object)Lock.Target == (Object)null) && !((Object)(object)R.AttackCharacter.Invoke(__instance) != (Object)(object)Player.m_localPlayer)) { Vector3 val = Lock.AimPoint - originJoint.position; Vector3 val2 = default(Vector3); ((Vector3)(ref val2))..ctor(val.x, 0f, val.z); if (!(((Vector3)(ref val2)).sqrMagnitude < 0.0001f)) { attackDir = Vector3.RotateTowards(((Vector3)(ref val2)).normalized, ((Vector3)(ref val)).normalized, (float)Math.PI / 180f * __instance.m_maxYAngle, 10f); } } } catch (Exception e) { Diag.Once("MeleeTowardsTarget", e); } } } internal static class CrosshairLock { private const float GroupRadius = 200f; private static Hud _hud; private static readonly List<RectTransform> _moved = new List<RectTransform>(); private static readonly List<Vector2> _home = new List<Vector2>(); private static bool _away; internal static void Follow(Camera cam, Vector3 target) { //IL_0017: 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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: 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_003b: 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) //IL_0058: 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) //IL_0065: 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_0099: 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_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) Hud instance = Hud.instance; if ((Object)(object)instance == (Object)null) { return; } Vector3 val = Utils.WorldToScreenPointScaled(cam, ((Component)cam).transform.position + ((Component)cam).transform.forward * 10f); if ((Object)(object)_hud != (Object)(object)instance) { Capture(instance, val); } Vector3 val2 = default(Vector3); ((Vector3)(ref val2))..ctor(target.x - val.x, target.y - val.y, 0f); for (int i = 0; i < _moved.Count; i++) { RectTransform val3 = _moved[i]; if (!((Object)(object)val3 == (Object)null)) { val3.anchoredPosition = _home[i]; ((Transform)val3).position = ((Transform)val3).position + val2; } } _away = true; } internal static void Restore() { //IL_0036: Unknown result type (might be due to invalid IL or missing references) if (!_away) { return; } _away = false; for (int i = 0; i < _moved.Count; i++) { if ((Object)(object)_moved[i] != (Object)null) { _moved[i].anchoredPosition = _home[i]; } } } private static void Capture(Hud hud, Vector3 center) { //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) _hud = hud; _moved.Clear(); _home.Clear(); _away = false; List<RectTransform> list = new List<RectTransform>(); Add(list, ((Object)(object)hud.m_crosshair != (Object)null) ? ((Component)hud.m_crosshair).transform : null); Add(list, ((Object)(object)hud.m_crosshairBow != (Object)null) ? ((Component)hud.m_crosshairBow).transform : null); Add(list, ((Object)(object)hud.m_hidden != (Object)null) ? hud.m_hidden.transform : null); Add(list, ((Object)(object)hud.m_targeted != (Object)null) ? hud.m_targeted.transform : null); Add(list, ((Object)(object)hud.m_targetedAlert != (Object)null) ? hud.m_targetedAlert.transform : null); Add(list, ((Object)(object)hud.m_stealthBar != (Object)null) ? ((Component)hud.m_stealthBar).transform : null); float num = 200f * (float)Screen.height / 1080f; Vector2 val = default(Vector2); foreach (RectTransform item in list) { ((Vector2)(ref val))..ctor(((Transform)item).position.x - center.x, ((Transform)item).position.y - center.y); if (((Vector2)(ref val)).magnitude > num) { continue; } bool flag = false; foreach (RectTransform item2 in list) { if ((Object)(object)item2 != (Object)(object)item && ((Transform)item).IsChildOf((Transform)(object)item2) && Vector2.Distance(Vector2.op_Implicit(((Transform)item2).position), Vector2.op_Implicit(center)) <= num) { flag = true; } } if (!flag) { _moved.Add(item); _home.Add(item.anchoredPosition); } } Diag.Debug(string.Format("Crosshair lock moves {0} HUD elements: {1}", _moved.Count, string.Join(", ", _moved.ConvertAll((RectTransform r) => ((Object)r).name)))); } private static void Add(List<RectTransform> list, Transform t) { RectTransform val = (RectTransform)(object)((t is RectTransform) ? t : null); if (val != null && !list.Contains(val)) { list.Add(val); } } } internal static class EnemyHuds { private static readonly List<KeyValuePair<object, float>> _held = new List<KeyValuePair<object, float>>(); internal static void ApplyHoverSeconds(EnemyHud hud) { if ((Object)(object)hud != (Object)null) { hud.m_hoverShowDuration = Plugin.HoverHudSeconds.Value; } } internal static void BeforeUpdate(EnemyHud hud) { _held.Clear(); IDictionary dictionary = R.Huds.GetValue(hud) as IDictionary; Player localPlayer = Player.m_localPlayer; if (dictionary == null || dictionary.Count == 0 || (Object)(object)localPlayer == (Object)null) { return; } bool value = Plugin.HideHudBehindObstacles.Value; Character target = Lock.Target; Character hoverCreature = localPlayer.GetHoverCreature(); float hoverShowDuration = hud.m_hoverShowDuration; List<Character> allCharacters = Character.GetAllCharacters(); for (int i = 0; i < allCharacters.Count; i++) { Character val = allCharacters[i]; if ((Object)(object)val == (Object)null || (Object)(object)val == (Object)(object)localPlayer) { continue; } object obj = dictionary[val]; if (obj == null || val.IsBoss() || val.IsPlayer() || R.IsMount.Invoke(obj)) { continue; } ref float reference = ref R.HoverTimer.Invoke(obj); if ((Object)(object)val == (Object)(object)target || (Object)(object)val == (Object)(object)hoverCreature || reference < hoverShowDuration) { if (value && !Sight.Visible(val)) { _held.Add(new KeyValuePair<object, float>(obj, reference)); reference = float.PositiveInfinity; } else if ((Object)(object)val == (Object)(object)target) { reference = 0f; } } } } internal static void AfterUpdate(float dt) { for (int i = 0; i < _held.Count; i++) { R.HoverTimer.Invoke(_held[i].Key) = _held[i].Value + dt; } _held.Clear(); } } [HarmonyPatch(typeof(EnemyHud), "Awake")] internal static class EnemyHud_Awake_Patch { private static void Postfix(EnemyHud __instance) { try { EnemyHuds.ApplyHoverSeconds(__instance); } catch (Exception e) { Diag.Once("HoverHudSeconds", e); } } } [HarmonyPatch(typeof(EnemyHud), "TestShow")] internal static class EnemyHud_TestShow_Patch { private static void Postfix(Character c, ref bool __result) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004d: 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) //IL_0057: Unknown result type (might be due to invalid IL or missing references) try { if (__result || (Object)(object)c == (Object)null || (Object)(object)c != (Object)(object)Lock.Target) { return; } Player localPlayer = Player.m_localPlayer; float num = Plugin.LockRange.Value * 1.15f; if ((Object)(object)localPlayer != (Object)null) { Vector3 val = ((Component)c).transform.position - ((Component)localPlayer).transform.position; if (((Vector3)(ref val)).sqrMagnitude <= num * num) { __result = true; } } } catch (Exception e) { Diag.Once("LockedTargetHud", e); } } } [HarmonyPatch(typeof(EnemyHud), "UpdateHuds")] internal static class EnemyHud_UpdateHuds_Patch { private static void Prefix(EnemyHud __instance) { try { EnemyHuds.BeforeUpdate(__instance); } catch (Exception e) { Diag.Once("EnemyHudVisibility", e); } } private static void Postfix(float dt) { try { EnemyHuds.AfterUpdate(dt); } catch (Exception e) { Diag.Once("EnemyHudVisibility", e); } } } internal static class Framing { private enum Kind { Melee, Bow, Crossbow, Bomb } private const float NearSideRatio = 0.35f; private const float MinSide = 0.005f; internal const float FirstPersonDistance = 0.01f; private const float BlendToSmoothTime = 2.5f; private const float CrossbowZoom = 0.75f; private const float BombZoom = 0.7f; private const float BombShoulder = 0.7f; private const float BowIdleZoom = 0.5f; private const float BowLingerSeconds = 0.75f; private const float MeleeSideSpeed = 1f; private const float EaseOutRate = 3f; private static float _dist = 1f; private static float _distVel; private static float _side; private static float _sideVel; private static bool _easeOut; private static float _saved; private static float _written; private static bool _pushed; private static float _bowUntil; private static int _meleeSign = 1; private static Character _signTarget; private static ItemData _reported; private static bool _reportedLock; internal static float Side { get; private set; } internal static bool FreeAim { get; private set; } internal static void Tick(GameCamera cam, float dt) { //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; Character target = Lock.Target; float num = 1f; float num2 = 0f; float baseX = 0f; FreeAim = false; if ((Object)(object)target == (Object)null) { _signTarget = null; } if ((Object)(object)localPlayer != (Object)null && R.CamDistance.Invoke(cam) > 0.01f) { baseX = BaseX(cam, localPlayer); ItemData currentWeapon = ((Humanoid)localPlayer).GetCurrentWeapon(); Kind kind = KindOf(currentWeapon); float num3 = 0f; float near = 0f; if ((Object)(object)target != (Object)null) { Vector3 val = Flat(Lock.AimPoint - ((Component)localPlayer).transform.position); near = 0.35f * ((Vector3)(ref val)).magnitude; _easeOut = kind == Kind.Melee; if (kind == Kind.Melee) { num = Plugin.MeleeDistance.Value; num3 = Plugin.MeleeShoulder.Value * (float)MeleeSign(cam, localPlayer, target); } else { num = RangedZoom(kind, kind != Kind.Bow || ((Character)localPlayer).IsDrawingBow()); if (Plugin.BallisticAim.Value) { num3 = RangedShoulder(kind); } } } else if (FreeAimOn(localPlayer, kind)) { FreeAim = true; _easeOut = false; num = ((kind == Kind.Bomb) ? Plugin.BombFreeAimDistance.Value : RangedZoom(kind, drawing: true)); num3 = RangedShoulder(kind); } if (num3 != 0f) { num2 = SideFor(cam, baseX, num, num3, near); } Report(cam, currentWeapon, kind, (Object)(object)target != (Object)null, num, num2); } float value = Plugin.CameraBlendSeconds.Value; if (_easeOut) { float num4 = 1f - Mathf.Exp(-3f / Mathf.Max(value, 0.01f) * dt); float num5 = Mathf.Lerp(_dist, num, num4); float num6 = Mathf.Lerp(_side, num2, num4); if (dt > 0f) { _distVel = (num5 - _dist) / dt; _sideVel = (num6 - _side) / dt; } _dist = num5; _side = num6; } else { float num7 = value / 2.5f; _dist = Mathf.SmoothDamp(_dist, num, ref _distVel, num7, float.PositiveInfinity, dt); _side = Mathf.SmoothDamp(_side, num2, ref _sideVel, num7, float.PositiveInfinity, dt); } Side = 0f; if (!((Object)(object)localPlayer == (Object)null) && !(Mathf.Abs(_side) < 0.005f)) { float num8 = Fit(cam, localPlayer, baseX, _side); if (Mathf.Abs(num8 - _side) > 0.0001f) { _side = num8; _sideVel = 0f; } Side = _side; } } private static Kind KindOf(ItemData w) { //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) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Invalid comparison between Unknown and I4 //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Invalid comparison between Unknown and I4 if (w == null) { return Kind.Melee; } SkillType skillType = w.m_shared.m_skillType; if ((int)skillType == 8) { return Kind.Bow; } if ((int)skillType == 14) { return Kind.Crossbow; } Attack val = Ballistics.RangedAttack(w); if (val == null || !Ballistics.IsBomb(w, val)) { return Kind.Melee; } return Kind.Bomb; } private static bool FreeAimOn(Player p, Kind kind) { if (kind == Kind.Melee || !Plugin.RangedFreeAim.Value || !Plugin.TrajectoryLine.Value || !Lock.Allowed(p)) { return false; } if (kind != Kind.Bow) { return true; } if (((Character)p).IsDrawingBow()) { _bowUntil = Time.time + 0.75f; } return Time.time < _bowUntil; } private static float RangedZoom(Kind kind, bool drawing) { return 1f - (1f - Plugin.RangedDistance.Value) * kind switch { Kind.Bomb => 0.7f, Kind.Crossbow => 0.75f, _ => drawing ? 1f : 0.5f, }; } private static float RangedShoulder(Kind kind) { return Plugin.RangedShoulder.Value * ((kind == Kind.Bomb) ? 0.7f : 1f); } private static int MeleeSign(GameCamera cam, Player p, Character t) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0012: 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_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_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: 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_003c: 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) Vector3 right = ((Component)cam).transform.right; Vector3 val = ((Component)t).transform.position - ((Component)p).transform.position; if ((Object)(object)t != (Object)(object)_signTarget) { _signTarget = t; _meleeSign = ((Vector3.Dot(right, val) >= 0f) ? 1 : (-1)); return _meleeSign; } Vector3 val2 = Flat(val); if (((Vector3)(ref val2)).magnitude - t.GetRadius() < Plugin.MeleeSafeZone.Value) { return _meleeSign; } float num = Vector3.Dot(((Character)p).GetVelocity(), right); if (Mathf.Abs(num) > 1f) { _meleeSign = ((!(num > 0f)) ? 1 : (-1)); } return _meleeSign; } private static float BaseX(GameCamera cam, Player p) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) return (((Character)p).UseMeleeCamera() ? cam.m_3rdCombatOffset : cam.m_3rdOffset).x; } private static float SideFor(GameCamera cam, float baseX, float distFactor, float frac, float near) { float num = R.CamDistance.Invoke(cam) * distFactor; if (num <= 0.01f || Screen.height <= 0) { return 0f; } float num2 = Mathf.Tan(cam.m_fov * 0.5f * ((float)Math.PI / 180f)) * (float)Screen.width / (float)Screen.height; float num3 = frac * num * num2; if (near > 0f) { float num4 = Mathf.Max(near, Mathf.Abs(baseX)); num3 = Mathf.Clamp(num3, 0f - num4, num4); } return num3 - baseX; } private static float Fit(GameCamera cam, Player p, float baseX, float side) { //IL_0024: 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_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) float num = baseX + side; float num2 = Mathf.Abs(num); if (num2 < 0.005f) { return side; } float num3 = Mathf.Sign(num); Transform eye = ((Character)p).m_eye; RaycastHit val = default(RaycastHit); if (!Physics.SphereCast(eye.position, cam.m_raycastWidth, eye.right * num3, ref val, num2, LayerMask.op_Implicit(cam.m_blockCameraMask))) { return side; } return num3 * ((RaycastHit)(ref val)).distance - baseX; } private static Vector3 Flat(Vector3 v) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) return new Vector3(v.x, 0f, v.z); } internal static void PushDistance(GameCamera cam) { if (!(Mathf.Abs(_dist - 1f) < 0.0001f)) { ref float reference = ref R.CamDistance.Invoke(cam); if (!(reference <= 0.01f)) { _saved = reference; reference *= _dist; _written = reference; _pushed = true; } } } internal static void PopDistance(GameCamera cam) { if (_pushed) { _pushed = false; ref float reference = ref R.CamDistance.Invoke(cam); if (reference == _written) { reference = _saved; } } } private static void Report(GameCamera cam, ItemData w, Kind kind, bool locked, float dist, float side) { //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) if (Plugin.DebugLog.Value) { if (!locked && !FreeAim) { _reported = null; } else if (w != _reported || locked != _reportedLock) { _reported = w; _reportedLock = locked; Plugin.Log.LogInfo((object)(string.Format("Camera framing: {0} ({1}, ", (w != null) ? w.m_shared.m_name : "none", kind) + string.Format("{0}, centerCamera {1}): ", locked ? "locked" : "free aim", w?.m_shared.m_centerCamera ?? false) + $"zoom {R.CamDistance.Invoke(cam):0.00} m x{dist:0.00}, side {side:0.00} m. Vanilla: offset {cam.m_3rdOffset}, " + $"combat offset {cam.m_3rdCombatOffset}, fov {cam.m_fov:0}, zoom {cam.m_minDistance:0.0}-{cam.m_maxDistance:0.0} m, " + $"ray width {cam.m_raycastWidth:0.00}")); } } } } [HarmonyPatch(typeof(GameCamera), "UpdateCamera")] internal static class GameCamera_UpdateCamera_Patch { private static void Prefix(GameCamera __instance, float dt) { try { Framing.Tick(__instance, dt); } catch (Exception e) { Diag.Once("CameraFraming", e); } } } [HarmonyPatch(typeof(GameCamera), "GetCameraPosition")] internal static class GameCamera_GetCameraPosition_Patch { [HarmonyPriority(600)] private static void Prefix(GameCamera __instance) { try { Framing.PushDistance(__instance); } catch (Exception e) { Diag.Once("CameraDistance", e); } } private static void Finalizer(GameCamera __instance) { try { Framing.PopDistance(__instance); } catch (Exception e) { Diag.Once("CameraDistanceRestore", e); } } } [HarmonyPatch(typeof(GameCamera), "GetCameraOffset")] internal static class GameCamera_GetCameraOffset_Patch { [HarmonyPriority(200)] private static void Postfix(GameCamera __instance, Player player, ref Vector3 __result) { //IL_003a: 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_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) try { float side = Framing.Side; if (side != 0f && !((Object)(object)player != (Object)(object)Player.m_localPlayer) && !(R.CamDistance.Invoke(__instance) <= 0.01f) && !((Character)player).InBed()) { __result += ((Character)player).m_eye.right * side; } } catch (Exception e) { Diag.Once("CameraSide", e); } } } internal static class CrosshairHide { private static Image _dot; private static Image _bow; internal static void Apply(Hud hud) { bool hide = Plugin.HideCrosshairInFreeAim.Value && Framing.FreeAim && Trajectory.Showing; Set(ref _dot, hud.m_crosshair, hide); Set(ref _bow, hud.m_crosshairBow, hide); } private static void Set(ref Image hidden, Image img, bool hide) { if (hide && (Object)(object)img != (Object)null && (Object)(object)hidden == (Object)null && ((Behaviour)img).enabled) { ((Behaviour)img).enabled = false; hidden = img; } else if (!hide && (Object)(object)hidden != (Object)null) { ((Behaviour)hidden).enabled = true; hidden = null; } } } [HarmonyPatch(typeof(Hud), "UpdateCrosshair")] internal static class Hud_UpdateCrosshair_Patch { private static void Postfix(Hud __instance) { try { CrosshairHide.Apply(__instance); } catch (Exception e) { Diag.Once("CrosshairHide", e); } } } internal static class Lock { private struct Entry { public Character C; public int Node; public float Angle; } private const float BreakRangeFactor = 1.15f; private const float MaxTrackedSpeed = 30f; private const float VelocitySmoothing = 0.15f; private const float StickFlick = 0.7f; private const float StickRearm = 0.3f; private const float MouseFlickDecay = 0.12f; private const float MouseFlickCooldown = 0.35f; private static Character _target; private static int _node; private static bool _locked; private static float _lastSeen; private static Vector3 _lastPos; private static readonly List<Entry> _entries = new List<Entry>(); private static readonly Comparison<Entry> ByAngle = delegate(Entry a, Entry b) { int num = a.Angle.CompareTo(b.Angle); return (num == 0) ? a.Node.CompareTo(b.Node) : num; }; private static bool _stickArmed; private static float _flick; private static float _flickCooldown; private static string _ignoreRaw; private static readonly HashSet<string> _ignore = new HashSet<string>(StringComparer.OrdinalIgnoreCase); internal static Character Target { get { if (!_locked || !((Object)(object)_target != (Object)null)) { return null; } return _target; } } internal static Vector3 AimPoint => Nodes.Position(_target, _node); internal static Vector3 TargetVelocity { get; private set; } internal static void Tick(Player p) { if ((Object)(object)p == (Object)null) { Clear(null); return; } RefreshIgnore(); if (_locked && ((Object)(object)_target == (Object)null || !Keep(p))) { Drop(p); } if (!Allowed(p)) { Clear("player busy"); ResetInput(); return; } if (!R.TakeInput(p) || Hud.InRadial()) { ResetInput(); return; } if (LockPressed(p)) { if (_locked) { Clear("button"); } else { Acquire(p); } } else if (_locked) { int num = CycleInput(); if (num != 0) { Cycle(p, num); } } if (_locked) { TrackVelocity(); } } internal static bool Allowed(Player p) { if (!((Character)p).IsDead() && !((Character)p).IsAttached() && !((Character)p).IsRiding() && p.GetDoodadController() == null && !((Character)p).InPlaceMode() && !p.IsSleeping() && !((Character)p).IsTeleporting()) { return !((Character)p).InCutscene(); } return false; } internal static bool Targetable(Character c, Player p) { if ((Object)(object)c == (Object)null || (Object)(object)c == (Object)(object)p || c.IsDead() || c.IsPlayer() || c.IsTamed() || c.m_hideHud) { return false; } if (_ignore.Count != 0) { return !_ignore.Contains(Utils.GetPrefabName(((Component)c).gameObject)); } return true; } private static bool Keep(Player p) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0033: 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_003d: Unknown result type (might be due to invalid IL or missing references) Character target = _target; if (!Targetable(target, p)) { return false; } float num = Plugin.LockRange.Value * 1.15f; Vector3 val = ((Component)target).transform.position - ((Component)p).transform.position; if (((Vector3)(ref val)).sqrMagnitude > num * num) { return false; } if (Sight.Visible(target)) { _lastSeen = Time.time; } else if (Time.time - _lastSeen > Plugin.LostSightSeconds.Value) { return false; } return true; } private static void Drop(Player p) { int num; object reason; if (!((Object)(object)_target == (Object)null)) { num = (_target.IsDead() ? 1 : 0); if (num == 0) { reason = "out of range or sight"; goto IL_0029; } } else { num = 1; } reason = "target gone"; goto IL_0029; IL_0029: Clear((string)reason); if (num != 0 && Plugin.RelockOnKill.Value && Allowed(p)) { int bestNode; Character val = Best(p, Plugin.SwitchAngle.Value, out bestNode); if ((Object)(object)val != (Object)null) { Set(val, bestNode); } } } private static void Set(Character c, int node) { //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_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0071: 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_0111: Unknown result type (might be due to invalid IL or missing references) _target = c; _node = node; _locked = true; _lastSeen = Time.time; _lastPos = c.GetCenterPoint(); TargetVelocity = Vector3.zero; if (Plugin.DebugLog.Value) { Player localPlayer = Player.m_localPlayer; float light; float fog; float num = Sight.Range(c, Plugin.LockRange.Value, out light, out fog); float num2 = (((Object)(object)localPlayer != (Object)null) ? Vector3.Distance(((Component)localPlayer).transform.position, ((Component)c).transform.position) : 0f); Plugin.Log.LogInfo((object)("Locked " + c.m_name + " (" + Utils.GetPrefabName(((Component)c).gameObject) + ") " + $"point {node + 1}/{Nodes.For(c).Length} {Nodes.Label(c, node)} at {num2:0.0} m: " + $"light {light:0.00}, fog {RenderSettings.fogMode} {RenderSettings.fogDensity:0.0000} " + $"(sees {Sight.FogDistance():0} m, x{fog:0.00}), lock range {num:0.0} m")); } } private static void Clear(string reason) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) if (_locked && reason != null) { Diag.Debug("Lock released: " + reason); } _target = null; _locked = false; TargetVelocity = Vector3.zero; } private static void Acquire(Player p) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) Character val = null; int bestNode = 0; Character hoverCreature = p.GetHoverCreature(); GameCamera instance = GameCamera.instance; if ((Object)(object)hoverCreature != (Object)null && (Object)(object)instance != (Object)null && Targetable(hoverCreature, p) && InLockRange(p, hoverCreature, Distance(p, hoverCreature))) { val = hoverCreature; bestNode = Nearest(hoverCreature, ((Component)instance).transform.position, ((Component)instance).transform.forward); } if ((Object)(object)val == (Object)null) { val = Best(p, Plugin.LockAngle.Value, out bestNode); } if ((Object)(object)val != (Object)null) { Set(val, bestNode); } else if (Plugin.FaceCameraWithoutTarget.Value) { FaceCamera.Request(); } } private static int Nearest(Character c, Vector3 cp, Vector3 cf) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //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_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: 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) int result = 0; float num = float.MinValue; int num2 = Nodes.For(c).Length; for (int i = 0; i < num2; i++) { Vector3 val = Nodes.Position(c, i) - cp; float num3 = Vector3.Dot(cf, ((Vector3)(ref val)).normalized); if (num3 > num) { num = num3; result = i; } } return result; } private static float Distance(Player p, Character c) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) return Vector3.Distance(((Component)p).transform.position, ((Component)c).transform.position); } private static bool InLockRange(Player p, Character c, float dist) { if (dist > Plugin.LockRange.Value) { return false; } float light; float fog; return dist <= Sight.Range(c, Plugin.LockRange.Value, out light, out fog); } private static Character Best(Player p, float angle, out int bestNode) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0026: 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_009c: 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_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: 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_00e9: Unknown result type (might be due to invalid IL or missing references) bestNode = 0; GameCamera instance = GameCamera.instance; if ((Object)(object)instance == (Object)null) { return null; } Vector3 position = ((Component)instance).transform.position; Vector3 forward = ((Component)instance).transform.forward; float num = Mathf.Cos(angle * ((float)Math.PI / 180f)); float value = Plugin.LockRange.Value; Character result = null; float num2 = float.MinValue; List<Character> allCharacters = Character.GetAllCharacters(); for (int i = 0; i < allCharacters.Count; i++) { Character val = allCharacters[i]; if (!Targetable(val, p)) { continue; } float num3 = Distance(p, val); if (num3 > value) { continue; } int num4 = Nodes.For(val).Length; int num5 = 0; for (int j = 0; j < num4; j++) { Vector3 val2 = Nodes.Position(val, j) - position; float num6 = Vector3.Dot(forward, ((Vector3)(ref val2)).normalized); if (num6 < num) { continue; } float num7 = num6 - 0.15f * num3 / value; if (!(num7 <= num2)) { if (num5 == 0) { num5 = ((InLockRange(p, val, num3) && Sight.Check(val, position)) ? 1 : (-1)); } if (num5 < 0) { break; } result = val; bestNode = j; num2 = num7; } } } return result; } private static void Cycle(Player p, int dir) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: 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_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: 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_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: 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) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: 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) //IL_00c7: 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) GameCamera instance = GameCamera.instance; if ((Object)(object)instance == (Object)null) { return; } Vector3 position = ((Component)instance).transform.position; Vector3 forward = ((Component)instance).transform.forward; Vector3 val = Flat(forward); float num = Mathf.Cos(Plugin.SwitchAngle.Value * ((float)Math.PI / 180f)); float value = Plugin.LockRange.Value; _entries.Clear(); List<Character> allCharacters = Character.GetAllCharacters(); for (int i = 0; i < allCharacters.Count; i++) { Character val2 = allCharacters[i]; Vector3 v = (((Object)(object)val2 != (Object)null) ? (val2.GetCenterPoint() - position) : Vector3.zero); if ((Object)(object)val2 != (Object)(object)_target) { if (!Targetable(val2, p)) { continue; } float num2 = Distance(p, val2); if (num2 > value || Vector3.Dot(forward, ((Vector3)(ref v)).normalized) < num || !InLockRange(p, val2, num2) || !Sight.Check(val2, position)) { continue; } } float angle = Vector3.SignedAngle(val, Flat(v), Vector3.up); int num3 = Nodes.For(val2).Length; for (int j = 0; j < num3; j++) { _entries.Add(new Entry { C = val2, Node = j, Angle = angle }); } } _entries.Sort(ByAngle); for (int k = 0; k < _entries.Count; k++) { if (!((Object)(object)_entries[k].C != (Object)(object)_target) && _entries[k].Node == _node) { int num4 = k + dir; if (num4 >= 0 && num4 < _entries.Count) { Set(_entries[num4].C, _entries[num4].Node); } break; } } _entries.Clear(); } private static Vector3 Flat(Vector3 v) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) return new Vector3(v.x, 0f, v.z); } private static void TrackVelocity() { //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_005c: 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) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: 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_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: 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) Vector3 centerPoint = _target.GetCenterPoint(); float deltaTime = Time.deltaTime; if (deltaTime > 0.0001f) { Vector3 val = (centerPoint - _lastPos) / deltaTime; if (((Vector3)(ref val)).sqrMagnitude < 900f) { TargetVelocity = Vector3.Lerp(TargetVelocity, val, 1f - Mathf.Exp((0f - deltaTime) / 0.15f)); } } _lastPos = centerPoint; } private static bool LockPressed(Player p) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) bool result = Pad.LockPressed(p); KeyboardShortcut value = Plugin.LockKey.Value; if ((int)((KeyboardShortcut)(ref value)).MainKey != 0 && ((KeyboardShortcut)(ref value)).IsDown()) { result = true; } return result; } private static int CycleInput() { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0070: 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) int result = 0; float joyRightStickX = ZInput.GetJoyRightStickX(); if (Mathf.Abs(joyRightStickX) < 0.3f) { _stickArmed = true; } else if (_stickArmed && Mathf.Abs(joyRightStickX) > 0.7f) { _stickArmed = false; result = ((joyRightStickX > 0f) ? 1 : (-1)); } KeyboardShortcut value = Plugin.PrevTargetKey.Value; KeyboardShortcut value2 = Plugin.NextTargetKey.Value; if ((int)((KeyboardShortcut)(ref value)).MainKey != 0 && ((KeyboardShortcut)(ref value)).IsDown()) { result = -1; } if ((int)((KeyboardShortcut)(ref value2)).MainKey != 0 && ((KeyboardShortcut)(ref value2)).IsDown()) { result = 1; } float value3 = Plugin.MouseFlickPixels.Value; if (value3 > 0f && ZInput.IsMouseActive()) { float unscaledTime = Time.unscaledTime; _flick = _flick * Mathf.Exp((0f - Time.unscaledDeltaTime) / 0.12f) + ZInput.GetMouseDelta().x; if (unscaledTime >= _flickCooldown && Mathf.Abs(_flick) >= value3) { result = ((_flick > 0f) ? 1 : (-1)); _flick = 0f; _flickCooldown = unscaledTime + 0.35f; } } return result; } private static void ResetInput() { _stickArmed = false; _flick = 0f; } private static void RefreshIgnore() { string value = Plugin.IgnoreTargets.Value; if ((object)value == _ignoreRaw) { return; } _ignoreRaw = value; _ignore.Clear(); string[] array = (value ?? "").Split(','); foreach (string text in array) { if (text.Trim().Length > 0) { _ignore.Add(text.Trim()); } } } } internal static class Marker { private const int RingTexture = 64; private const float RingOuter = 31f; private const float RingInner = 24f; private static RectTransform _rt; private static Image _img; private static Sprite _ring; private static bool _failed; private static float _size = -1f; private static Color _color; internal static void Tick(EnemyHud hud) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: 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_004d: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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_0092: Unknown result type (might be due to invalid IL or missing references) MarkerStyle value = Plugin.LockMarkerStyle.Value; Character target = Lock.Target; Camera mainCamera = Utils.GetMainCamera(); Vector3 val = Vector3.zero; bool flag = value != MarkerStyle.Off && (Object)(object)target != (Object)null && (Object)(object)mainCamera != (Object)null && Sight.Visible(target); if (flag) { val = Utils.WorldToScreenPointScaled(mainCamera, Lock.AimPoint); flag = val.z > 0f; } if (flag && value == MarkerStyle.Crosshair) { CrosshairLock.Follow(mainCamera, val); } else { CrosshairLock.Restore(); } if (!flag || value != MarkerStyle.Ring || !Ensure(hud)) { Hide(); return; } Style(); ((Transform)_rt).position = val; if (!((Component)_rt).gameObject.activeSelf) { ((Component)_rt).gameObject.SetActive(true); } } private static void Hide() { if ((Object)(object)_rt != (Object)null && ((Component)_rt).gameObject.activeSelf) { ((Component)_rt).gameObject.SetActive(false); } } private static void Style() { //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_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0042: 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_004d: Unknown result type (might be due to invalid IL or missing references) float value = Plugin.LockMarkerSize.Value; if (value != _size) { _size = value; _rt.sizeDelta = new Vector2(value, value); } Color value2 = Plugin.LockMarkerColor.Value; if (value2 != _color) { _color = value2; ((Graphic)_img).color = value2; } } private static bool Ensure(EnemyHud hud) { //IL_0055: 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_006a: Expected O, but got Unknown //IL_00bd: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_rt != (Object)null) { return true; } if (_failed || (Object)(object)hud == (Object)null || (Object)(object)hud.m_hudRoot == (Object)null) { return false; } try { GameObject val = new GameObject("TargetLockOn_Marker", new Type[2] { typeof(RectTransform), typeof(Image) }); _rt = (RectTransform)val.transform; ((Transform)_rt).SetParent(hud.m_hudRoot.transform, false); ((Transform)_rt).SetAsLastSibling(); _img = val.GetComponent<Image>(); ((Graphic)_img).raycastTarget = false; _img.sprite = Ring(); _size = -1f; _color = default(Color); return true; } catch (Exception e) { _failed = true; Diag.Once("LockMarker", e); return false; } } private static Sprite Ring() { //IL_0019: 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_0029: 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_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown //IL_0108: 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) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_ring != (Object)null) { return _ring; } Texture2D val = new Texture2D(64, 64, (TextureFormat)4, true) { name = "TargetLockOn_Ring", wrapMode = (TextureWrapMode)1, filterMode = (FilterMode)2, hideFlags = (HideFlags)32 }; Color32[] array = (Color32[])(object)new Color32[4096]; float num = 31.5f; for (int i = 0; i < 64; i++) { for (int j = 0; j < 64; j++) { float num2 = Mathf.Sqrt(((float)j - num) * ((float)j - num) + ((float)i - num) * ((float)i - num)); float num3 = Mathf.Clamp01(31f - num2 + 0.5f) * Mathf.Clamp01(num2 - 24f + 0.5f); array[i * 64 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(num3 * 255f)); } } val.SetPixels32(array); val.Apply(true, true); _ring = Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 100f); ((Object)_ring).name = "TargetLockOn_Ring"; ((Object)_ring).hideFlags = (HideFlags)32; return _ring; } } [HarmonyPatch(typeof(EnemyHud), "LateUpdate")] internal static class EnemyHud_LateUpdate_Patch { private static void Postfix(EnemyHud __instance) { try { Marker.Tick(__instance); } catch (Exception e) { Diag.Once("LockMarker", e); } } } internal struct Node { public Transform Bone; public Collider Collider; public string Label; } internal static class Nodes { internal const string WeakSpotsToken = "WeakSpots"; private const float SweepEvery = 30f; private static readonly Node[] Center = new Node[1] { new Node { Label = "Center" } }; private static readonly Dictionary<Character, Node[]> _cache = new Dictionary<Character, Node[]>(); private static readonly Dictionary<string, string[]> _table = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase); private static readonly HashSet<string> _warned = new HashSet<string>(); private static readonly List<Node> _build = new List<Node>(); private static readonly List<Character> _dead = new List<Character>(); private static string _tableRaw; private static bool _enabled; private static float _nextSweep; internal static Node[] For(Character c) { Refresh(); if (_cache.TryGetValue(c, out var value)) { return value; } value = (_enabled ? Build(c) : Center); _cache[c] = value; if (Time.time >= _nextSweep) { Sweep(); } return value; } internal static Vector3 Position(Character c, int index) { //IL_0086: 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_0051: 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) //IL_0062: 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) Node[] array = For(c); if (index >= 0 && index < array.Length) { Node node = array[index]; if ((Object)(object)node.Collider != (Object)null) { if (!node.Collider.enabled || !((Component)node.Collider).gameObject.activeInHierarchy) { return ((Component)node.Collider).transform.position; } Bounds bounds = node.Collider.bounds; return ((Bounds)(ref bounds)).center; } if ((Object)(object)node.Bone != (Object)null) { return node.Bone.position; } } return c.GetCenterPoint(); } internal static string Label(Character c, int index) { Node[] array = For(c); if (index < 0 || index >= array.Length) { return "Center"; } return array[index].Label; } private static Node[] Build(Character c) { //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Invalid comparison between Unknown and I4 //IL_014b: Unknown result type (might be due to invalid IL or missing references) string prefabName = Utils.GetPrefabName(((Component)c).gameObject); if (!_table.TryGetValue(prefabName, out var value)) { return Center; } _build.Clear(); Animator val = R.CharAnimator.Invoke(c); bool flag = (Object)(object)val != (Object)null && val.isHuman; GameObject visual = c.GetVisual(); string[] array = value; foreach (string text in array) { if (string.Equals(text, "WeakSpots", StringComparison.OrdinalIgnoreCase)) { int count = _build.Count; if (c.m_weakSpots != null) { WeakSpot[] weakSpots = c.m_weakSpots; foreach (WeakSpot val2 in weakSpots) { if (!((Object)(object)val2 == (Object)null)) { Collider collider = (((Object)(object)val2.m_collider != (Object)null) ? val2.m_collider : ((Component)val2).GetComponent<Collider>()); _build.Add(new Node { Collider = collider, Bone = ((Component)val2).transform, Label = ((Object)val2).name }); } } } if (_build.Count == count) { Warn(prefabName, text); } } else { Transform val3 = null; if (flag && Enum.TryParse<HumanBodyBones>(text, ignoreCase: true, out HumanBodyBones result) && (int)result != 55) { val3 = val.GetBoneTransform(result); } if ((Object)(object)val3 == (Object)null && (Object)(object)visual != (Object)null) { val3 = Utils.FindChild(visual.transform, text, (IterativeSearchType)1); } if ((Object)(object)val3 != (Object)null) { _build.Add(new Node { Bone = val3, Label = text }); } else { Warn(prefabName, text); } } } if (_build.Count <= 0) { return Center; } return _build.ToArray(); } private static void Warn(string prefab, string token) { if (_warned.Add(prefab + "/" + token)) { Plugin.Log.LogWarning((object)("TargetNodes: '" + token + "' not found on " + prefab + ", that lock point is skipped.")); } } private static void Refresh() { string value = Plugin.TargetNodes.Value; bool value2 = Plugin.MultiNodeTargets.Value; if ((object)value == _tableRaw && value2 == _enabled) { return; } _tableRaw = value; _enabled = value2; _table.Clear(); _cache.Clear(); string[] array = (value ?? "").Split(';'); foreach (string text in array) { int num = text.IndexOf('='); if (num <= 0) { continue; } List<string> list = new List<string>(); string[] array2 = text.Substring(num + 1).Split(','); foreach (string text2 in array2) { if (text2.Trim().Length > 0) { list.Add(text2.Trim()); } } if (list.Count > 0) { _table[text.Substring(0, num).Trim()] = list.ToArray(); } } } private static void Sweep() { _nextSweep = Time.time + 30f; foreach (KeyValuePair<Character, Node[]> item in _cache) { if ((Object)(object)item.Key == (Object)null) { _dead.Add(item.Key); } } foreach (Character item2 in _dead) { _cache.Remove(item2); } _dead.Clear(); } } internal static class Pad { [HarmonyPatch(typeof(PlayerController), "FixedUpdate")] private static class PlayerController_FixedUpdate_Patch { private static void Prefix() { try { if (LockOnCrouchButton && ZInput.GetButtonDown("JoyCrouch")) { ZInput.ResetButtonStatus("JoyCrouch"); } } catch (Exception e) { Diag.Once("Pad crouch", e); } } } [HarmonyPatch(typeof(Player), "Update")] private static class Player_Update_Patch { private static void Prefix(Player __instance) { try { if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer && ZInput.GetButtonUp("JoyHide")) { ZInput.ResetButtonStatus("JoyHide"); } } catch (Exception e) { Diag.Once("Pad holster", e); } } } private const float TapSeconds = 0.33f; private static bool _tapClean; private static bool Classic => (int)ZInput.InputLayout == 0; private static string CrouchButton { get { if (!Classic) { return "JoyRStick"; } return "JoyLStick"; } } private static string HideButton { get { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Invalid comparison between Unknown and I4 if (Classic) { return "JoyRStick"; } if ((int)ZInput.InputLayout != 2) { return "JoyLTrigger"; } return "JoyLBumper"; } } internal static bool LockOnCrouchButton => Plugin.LockOnRightStick.Value != Classic; internal static void Tick(Player p) { string hideButton = HideButton; if (ZInput.GetButtonDown(hideButton)) { _tapClean = true; } if (ZInput.GetButton(hideButton) && (ZInput.GetButton("JoyAltKeys") || (hideButton == "JoyRStick" && ZInput.GetButton("JoyLStick")))) { _tapClean = false; } if (!((Object)(object)p == (Object)null) && LockOnCrouchButton && !((Character)p).IsDead() && R.TakeInput(p) && TapReleased(p)) { R.SetCrouch(p, !R.CrouchToggled.Invoke(p)); } } internal static bool LockPressed(Player p) { if (!LockOnCrouchButton) { return TapReleased(p); } string crouchButton = CrouchButton; if (ZInput.GetButtonDown(crouchButton)) { return !ZInput.GetButton((crouchButton == "JoyRStick") ? "JoyLStick" : "JoyRStick"); } return false; } private static bool TapReleased(Player p) { string hideButton = HideButton; if (!ZInput.GetButtonUp(hideButton)) { return false; } bool tapClean = _tapClean; _tapClean = false; if (tapClean && ZInput.GetButtonLastPressedTimer(hideButton) < 0.33f && !Hud.InRadial() && !((Character)p).InPlaceMode()) { return !ZInput.GetButton("JoyAltKeys"); } return false; } } public enum PitchLockMode { Off, RangedAndSpears, AllWeapons } public enum AimAtMode { Camera, Target } public enum MarkerStyle { Crosshair, Ring, Off } [BepInPlugin("vktr.targetlockon", "TargetLockOn", "0.9.0")] public class Plugin : BaseUnityPlugin { public const string GUID = "vktr.targetlockon"; public const string NAME = "TargetLockOn"; public const string VERSION = "0.9.0"; internal static ManualLogSource Log; internal static ConfigEntry<bool> LockOnRightStick; internal static ConfigEntry<KeyboardShortcut> LockKey; internal static ConfigEntry<KeyboardShortcut> PrevTargetKey; internal static ConfigEntry<KeyboardShortcut> NextTargetKey; internal static ConfigEntry<float> MouseFlickPixels; internal static ConfigEntry<bool> FaceCameraWithoutTarget; internal static ConfigEntry<float> LockRange; internal static ConfigEntry<float> LockAngle; internal static ConfigEntry<float> SwitchAngle; internal static ConfigEntry<float> LostSightSeconds; internal static ConfigEntry<float> DarkRangeFactor; internal static ConfigEntry<float> MistRange; internal static ConfigEntry<float> LargeEnvironmentWeight; internal static ConfigEntry<bool> RelockOnKill; internal static ConfigEntry<bool> WeatherHidesTargets; internal static ConfigEntry<bool> MultiNodeTargets; internal static ConfigEntry<string> IgnoreTargets; internal static ConfigEntry<string> TargetNodes; internal static ConfigEntry<string> LargeCreatures; internal static ConfigEntry<PitchLockMode> PitchLock; internal static ConfigEntry<float> CameraSpeed; internal static ConfigEntry<float> MeleeDistance; internal static ConfigEntry<float> MeleeShoulder; internal static ConfigEntry<float> MeleeSafeZone; internal static ConfigEntry<float> RangedDistance; internal static ConfigEntry<float> RangedShoulder; internal static ConfigEntry<float> BombFreeAimDistance; internal static ConfigEntry<float> CameraBlendSeconds; internal static ConfigEntry<bool> RangedFreeAim; internal static ConfigEntry<bool> StrafeWhileLocked; internal static ConfigEntry<bool> AttackTowardsTarget; internal static ConfigEntry<bool> BallisticAim; internal static ConfigEntry<bool> LeadMovingTargets; internal static ConfigEntry<AimAtMode> AimAt; internal static ConfigEntry<float> BombLockRange; internal static ConfigEntry<bool> TrajectoryLine; internal static ConfigEntry<bool> ImpactMarker; internal static ConfigEntry<Color> TrajectoryColor; internal static ConfigEntry<float> TrajectoryWidth; internal static ConfigEntry<bool> HideHudBehindObstacles; internal static ConfigEntry<bool> HideCrosshairInFreeAim; internal static ConfigEntry<MarkerStyle> LockMarkerStyle; internal static ConfigEntry<float> HoverHudSeconds; internal static ConfigEntry<float> LockMarkerSize; internal static ConfigEntry<Color> LockMarkerColor; internal static ConfigEntry<bool> DebugLog; internal static ConfigEntry<bool> DumpCreatureRigs; private const string DefaultTargetNodes = "Troll=WeakSpots,Chest;Troll_sleeping=WeakSpots,Chest;TrollFrost=Nose,Spine1,LeftLeg,RightLeg;gd_king=Head,Chest,LeftLowerLeg,RightLowerLeg;Aspect_Elder=Head,Chest,LeftLowerLeg,RightLowerLeg;Dragon=Head,Chest,LeftHandMiddle3,RightHandMiddle3;Aspect_Moder=Head,Chest,LeftHandMiddle3,RightHandMiddle3;Fader=head,chest,front_shin.L,front_shin.R;Aspect_Fader=head,chest,front_shin.L,front_shin.R;Abomination=spine1,l.hand,r.hand,l.lowerleg,r.lowerleg;Gjall=Forehead,WeakSpots;Seeker=head,thorax3;SeekerBrute=head,WeakSpots"; private const string DefaultLargeCreatures = "Gjall,FallenValkyrie,Troll,Troll_sleeping,TrollFrost,Abomination,Aspect_Bonemass,Aspect_Eikthyr,Aspect_Elder,Aspect_Fader,Aspect_Moder,Aspect_SeekerQueen,Aspect_Yagluth"; private void Awake() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; BindConfig(); new Harmony("vktr.targetlockon").PatchAll(); Log.LogInfo((object)"TargetLockOn 0.9.0 loaded."); } private void Update() { try { Pad.Tick(Player.m_localPlayer); } catch (Exception e) { Diag.Once("Pad.Tick", e); } try { Lock.Tick(Player.m_localPlayer); } catch (Exception e2) { Diag.Once("Lock.Tick", e2); } } private void LateUpdate() { try { Trajectory.Tick(Player.m_localPlayer); } catch (Exception e) { Diag.Once("Trajectory.Tick", e); } } private void BindConfig() { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: 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_0062: Invalid comparison between Unknown and I4 //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Expected O, but got Unknown //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Expected O, but got Unknown //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Expected O, but got Unknown //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_0213: Expected O, but got Unknown //IL_026a: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Expected O, but got Unknown //IL_02a7: Unknown result type (might be due to invalid IL or missing references) //IL_02b1: Expected O, but got Unknown //IL_02e4: Unknown result type (might be due to invalid IL or missing references) //IL_02ee: Expected O, but got Unknown //IL_0321: Unknown result type (might be due to invalid IL or missing references) //IL_032b: Expected O, but got Unknown //IL_0406: Unknown result type (might be due to invalid IL or missing references) //IL_0410: Expected O, but got Unknown //IL_0443: Unknown result type (might be due to invalid IL or missing references) //IL_044d: Expected O, but got Unknown //IL_0480: Unknown result type (might be due to invalid IL or missing references) //IL_048a: Expected O, but got Unknown //IL_04bd: Unknown result type (might be due to invalid IL or missing references) //IL_04c7: Expected O, but got Unknown //IL_04fa: Unknown result type (might be due to invalid IL or missing references) //IL_0504: Expected O, but got Unknown //IL_0537: Unknown result type (might be due to invalid IL or missing references) //IL_0541: Expected O, but got Unknown //IL_0574: Unknown result type (might be due to invalid IL or missing references) //IL_057e: Expected O, but got Unknown //IL_05d1: Unknown result type (might be due to invalid IL or missing references) //IL_05db: Expected O, but got Unknown //IL_06ae: Unknown result type (might be due to invalid IL or missing references) //IL_06b8: Expected O, but got Unknown //IL_0721: Unknown result type (might be due to invalid IL or missing references) //IL_0763: Unknown result type (might be due to invalid IL or missing references) //IL_076d: Expected O, but got Unknown //IL_07e0: Unknown result type (might be due to invalid IL or missing references) //IL_07ea: Expected O, but got Unknown //IL_0866: Unknown result type (might be due to invalid IL or missing references) //IL_0870: Expected O, but got Unknown //IL_0899: 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) LockOnRightStick = ((BaseUnityPlugin)this).Config.Bind<bool>("Input", "LockOnRightStick", true, "Puts the gamepad lock-on on the right stick click, and moves crouch to a tap of the holster button: LT on Alt1, LB on Alt2. On Classic the right stick click is the holster button, so lock-on is a tap of it and crouch stays on the left stick. Off swaps the two. A tap is a press shorter than a third of a second; holding the button still opens the radial menu. The game's gamepad holster tap is always taken. L3 + R3 together never locks: it is the forsaken power."); LockKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Input", "LockKey", new KeyboardShortcut((KeyCode)48, Array.Empty<KeyCode>()), "Keyboard or mouse key that locks onto a target or releases the lock."); KeyboardShortcut value = LockKey.Value; if ((int)((KeyboardShortcut)(ref value)).MainKey == 325 && !((KeyboardShortcut)(ref value)).Modifiers.GetEnumerator().MoveNext()) { LockKey.Value = new KeyboardShortcut((KeyCode)48, Array.Empty<KeyCode>()); Log.LogInfo((object)"LockKey moved from Mouse2 (the game's secondary attack) to 0."); } PrevTargetKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Input", "PrevTargetKey", KeyboardShortcut.Empty, "Key that moves the lock to the next target on the left. On gamepad, flick the right stick left."); NextTargetKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Input", "NextTargetKey", KeyboardShortcut.Empty, "Key that moves the lock to the next target on the right. On gamepad, flick the right stick right."); MouseFlickPixels = ((BaseUnityPlugin)this).Config.Bind<float>("Input", "MouseFlickPixels", 60f, new ConfigDescription("While locked, a quick mouse move of this many pixels left or right moves the lock to the next target on that side. 0 turns it off.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 500f), Array.Empty<object>())); FaceCameraWithoutTarget = ((BaseUnityPlugin)this).Config.Bind<bool>("Input", "FaceCameraWithoutTarget", true, "Pressing the lock button with no target in view turns your character toward where the camera looks, at the game's normal turning speed."); LockRange = ((BaseUnityPlugin)this).Config.Bind<float>("Lock", "LockRange", 50f, new ConfigDescription("Maximum distance in meters for locking a target in full light and clear weather. Once locked, the lock breaks a little beyond this distance.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 100f), Array.Empty<object>())); DarkRangeFactor = ((BaseUnityPlugin)this).Config.Bind<float>("Lock", "DarkRangeFactor", 0.4f, new ConfigDescription("A creature in full darkness can be locked only within this fraction of LockRange. Light on it (daylight, moonlight, fires, torches) brings the range back up. Once locked, LockRange applies. 1 turns it off.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>())); WeatherHidesTargets = ((BaseUnityPlugin)this).Config.Bind<bool>("Lock", "WeatherHidesTargets", true, "Fog and Mistlands mist hide creatures. A hidden creature cannot be locked, and a locked one that stays hidden for LostSightSeconds is lost. Fog hides by how far it lets you see;