Decompiled source of Perfect Shot v1.0.2
com.lembo.perfectshot.dll
Decompiled 2 months 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.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using Brimstone.BallDistanceJobs; using HarmonyLib; using Microsoft.CodeAnalysis; using Mirror; using Unity.Collections; using Unity.Jobs; using Unity.Mathematics; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("com.lembo.perfectshot")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.2.0")] [assembly: AssemblyInformationalVersion("1.0.2+10f64b592b41f4707c1e52627bce1fc60e218194")] [assembly: AssemblyProduct("com.lembo.perfectshot")] [assembly: AssemblyTitle("com.lembo.perfectshot")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.2.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Lembo.PerfectShot { internal static class AutoFire { private class ShotTelemetry { public int ShotId; public Vector3 BallStart; public Vector3 HolePos; public Vector3 Wind; public float Pitch; public float Power; public float YawOffsetDeg; public float MaxSpeed; public float DragCoef; public float WindFactor; public float CrossWindFactor; public float SolverPredictedLongMiss; public float SolverPredictedSideMiss; public float ReleaseTime; public Component Ball; public Vector3 LastPos; public Vector3 PrevPos; public Vector3 PrevVel; public float LastMoveTime; public float MaxDistFromStart; public bool FirstHitCaptured; public Vector3 FirstHitPos; public Vector3 FirstHitVel; public float FirstHitTime; public string FirstHitTerrain; public float ApexY; public Vector3 EarlyVel0; public Vector3 EarlyVel1; public float EarlyDt; public bool EarlySampled0; public bool EarlySampled1; public float RbDrag; public bool RbUseGravity; public Vector3 VLaunch; public bool VLaunchSampled; } private static MethodInfo? _releaseMethod; private static MethodInfo? _tryStartChargingMethod; private static FieldInfo? _isAimingField; private static PropertyInfo? _isChargingProp; private static PropertyInfo? _isAimingProp; private static ShotTelemetry? _activeShot; private static int _shotCounter; public static void Trigger() { PlayerGolfer localPlayerAsGolfer = GameManager.LocalPlayerAsGolfer; if ((Object)(object)localPlayerAsGolfer == (Object)null) { Plugin.Log.LogWarning((object)"BV: no local golfer."); return; } if (_releaseMethod == null) { Type typeFromHandle = typeof(PlayerGolfer); _releaseMethod = typeFromHandle.GetMethod("ReleaseSwingCharge", BindingFlags.Instance | BindingFlags.Public); _tryStartChargingMethod = typeFromHandle.GetMethod("TryStartChargingSwing", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); _isAimingField = typeFromHandle.GetField("<IsAimingSwing>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic); _isChargingProp = typeFromHandle.GetProperty("IsChargingSwing", BindingFlags.Instance | BindingFlags.Public); _isAimingProp = typeFromHandle.GetProperty("IsAimingSwing", BindingFlags.Instance | BindingFlags.Public); } SwingReleaseHook.ForceFullPower.Remove(((Object)localPlayerAsGolfer).GetInstanceID()); ((MonoBehaviour)localPlayerAsGolfer).StartCoroutine(FireSequence(localPlayerAsGolfer)); } public static void BeginShotTelemetry(Vector3 ballStart, Vector3 holePos, Vector3 wind, float pitch, float power, float yawOffsetDeg, float maxSpeed, float drag, float windFactor, float crossWindFactor, float predictedLongMiss, float predictedSideMiss, Component ball) { //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_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_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_008c: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0093: 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_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_00c2: 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_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: 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_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) _shotCounter++; _activeShot = new ShotTelemetry { ShotId = _shotCounter, BallStart = ballStart, HolePos = holePos, Wind = wind, Pitch = pitch, Power = power, YawOffsetDeg = yawOffsetDeg, MaxSpeed = maxSpeed, DragCoef = drag, WindFactor = windFactor, CrossWindFactor = crossWindFactor, SolverPredictedLongMiss = predictedLongMiss, SolverPredictedSideMiss = predictedSideMiss, ReleaseTime = Time.time, Ball = ball, LastPos = ballStart, PrevPos = ballStart, PrevVel = Vector3.zero, LastMoveTime = Time.time, MaxDistFromStart = 0f, FirstHitCaptured = false, ApexY = ballStart.y, FirstHitTerrain = "unknown" }; Vector2 val = new Vector2(holePos.x - ballStart.x, holePos.z - ballStart.z); float magnitude = ((Vector2)(ref val)).magnitude; float num = holePos.y - ballStart.y; Plugin.Log.LogInfo((object)($"BV-TEL|FIRE|id={_shotCounter}|dist={magnitude:F2}|dy={num:F2}|" + $"ballX={ballStart.x:F2}|ballY={ballStart.y:F2}|ballZ={ballStart.z:F2}|" + $"holeX={holePos.x:F2}|holeY={holePos.y:F2}|holeZ={holePos.z:F2}|" + $"windX={wind.x:F2}|windY={wind.y:F2}|windZ={wind.z:F2}|windMag={((Vector3)(ref wind)).magnitude:F2}|" + $"pitch={pitch:F2}|power={power:F3}|yawOff={yawOffsetDeg:F2}|" + $"maxSpd={maxSpeed:F2}|drag={drag:F6}|wFactor={windFactor:F4}|cFactor={crossWindFactor:F4}|" + $"solverPredLong={predictedLongMiss:F2}|solverPredSide={predictedSideMiss:F2}")); } public static void TickShotTelemetry() { //IL_02a8: Unknown result type (might be due to invalid IL or missing references) //IL_02a9: Unknown result type (might be due to invalid IL or missing references) //IL_02af: Unknown result type (might be due to invalid IL or missing references) //IL_02b0: Unknown result type (might be due to invalid IL or missing references) //IL_02cf: Unknown result type (might be due to invalid IL or missing references) //IL_02d0: 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_004f: 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_0056: 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_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: 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_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_030b: Unknown result type (might be due to invalid IL or missing references) //IL_030d: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_0323: Unknown result type (might be due to invalid IL or missing references) //IL_0335: Unknown result type (might be due to invalid IL or missing references) //IL_0347: Unknown result type (might be due to invalid IL or missing references) //IL_0381: Unknown result type (might be due to invalid IL or missing references) //IL_0383: Unknown result type (might be due to invalid IL or missing references) //IL_038a: Unknown result type (might be due to invalid IL or missing references) //IL_038f: Unknown result type (might be due to invalid IL or missing references) //IL_0393: Unknown result type (might be due to invalid IL or missing references) //IL_039a: Unknown result type (might be due to invalid IL or missing references) //IL_03a7: Unknown result type (might be due to invalid IL or missing references) //IL_03a8: Unknown result type (might be due to invalid IL or missing references) //IL_03b1: Unknown result type (might be due to invalid IL or missing references) //IL_03d0: Unknown result type (might be due to invalid IL or missing references) //IL_03d5: Unknown result type (might be due to invalid IL or missing references) //IL_03d6: Unknown result type (might be due to invalid IL or missing references) //IL_03df: Unknown result type (might be due to invalid IL or missing references) //IL_0420: Unknown result type (might be due to invalid IL or missing references) //IL_0422: 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_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_04a6: Unknown result type (might be due to invalid IL or missing references) //IL_04ab: Unknown result type (might be due to invalid IL or missing references) //IL_04ad: Unknown result type (might be due to invalid IL or missing references) //IL_04b2: Unknown result type (might be due to invalid IL or missing references) //IL_04b3: Unknown result type (might be due to invalid IL or missing references) //IL_04bc: Unknown result type (might be due to invalid IL or missing references) //IL_04e0: Unknown result type (might be due to invalid IL or missing references) //IL_04e5: Unknown result type (might be due to invalid IL or missing references) //IL_04f0: Unknown result type (might be due to invalid IL or missing references) //IL_04f6: Unknown result type (might be due to invalid IL or missing references) //IL_0518: Unknown result type (might be due to invalid IL or missing references) //IL_051d: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_058d: Unknown result type (might be due to invalid IL or missing references) //IL_0593: Unknown result type (might be due to invalid IL or missing references) //IL_0598: Unknown result type (might be due to invalid IL or missing references) //IL_05a3: Unknown result type (might be due to invalid IL or missing references) //IL_05a8: Unknown result type (might be due to invalid IL or missing references) //IL_05aa: Unknown result type (might be due to invalid IL or missing references) //IL_05bd: Unknown result type (might be due to invalid IL or missing references) //IL_05c3: Unknown result type (might be due to invalid IL or missing references) //IL_05c8: Unknown result type (might be due to invalid IL or missing references) //IL_05d2: Unknown result type (might be due to invalid IL or missing references) //IL_05d7: Unknown result type (might be due to invalid IL or missing references) //IL_05da: Unknown result type (might be due to invalid IL or missing references) //IL_05e0: Unknown result type (might be due to invalid IL or missing references) //IL_05e5: Unknown result type (might be due to invalid IL or missing references) //IL_05f1: Unknown result type (might be due to invalid IL or missing references) //IL_060c: Unknown result type (might be due to invalid IL or missing references) //IL_060e: Unknown result type (might be due to invalid IL or missing references) //IL_0613: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_0704: Unknown result type (might be due to invalid IL or missing references) //IL_070f: Unknown result type (might be due to invalid IL or missing references) //IL_071a: Unknown result type (might be due to invalid IL or missing references) if (_activeShot == null) { return; } ShotTelemetry activeShot = _activeShot; if ((Object)(object)activeShot.Ball == (Object)null) { _activeShot = null; return; } Rigidbody component = activeShot.Ball.GetComponent<Rigidbody>(); if ((Object)(object)component == (Object)null) { _activeShot = null; return; } Vector3 position = activeShot.Ball.transform.position; Vector3 linearVelocity = component.linearVelocity; float num = Vector3.Distance(position, activeShot.BallStart); if (num > activeShot.MaxDistFromStart) { activeShot.MaxDistFromStart = num; } if (position.y > activeShot.ApexY) { activeShot.ApexY = position.y; } if (!activeShot.VLaunchSampled && ((Vector3)(ref linearVelocity)).sqrMagnitude > 1f) { activeShot.VLaunch = linearVelocity; activeShot.VLaunchSampled = true; } try { float num2 = Time.time - activeShot.ReleaseTime; if (!activeShot.EarlySampled0 && num2 > 0.02f && ((Vector3)(ref linearVelocity)).sqrMagnitude > 1f) { activeShot.EarlyVel0 = linearVelocity; activeShot.EarlySampled0 = true; activeShot.EarlyDt = Time.time; try { activeShot.RbDrag = component.drag; } catch { activeShot.RbDrag = -1f; } try { activeShot.RbUseGravity = component.useGravity; } catch { activeShot.RbUseGravity = false; } } else if (activeShot.EarlySampled0 && !activeShot.EarlySampled1 && Time.time - activeShot.EarlyDt > 0.2f) { activeShot.EarlyVel1 = linearVelocity; activeShot.EarlyDt = Time.time - activeShot.EarlyDt; activeShot.EarlySampled1 = true; } } catch { } if (!activeShot.FirstHitCaptured && Time.time - activeShot.ReleaseTime > 0.25f) { bool num3 = activeShot.PrevVel.y < -1f && linearVelocity.y > activeShot.PrevVel.y + 1.5f; bool flag = Mathf.Abs(linearVelocity.y) < 2f && position.y < activeShot.ApexY - 2f; if (num3 || flag) { activeShot.FirstHitCaptured = true; activeShot.FirstHitPos = activeShot.PrevPos; activeShot.FirstHitVel = activeShot.PrevVel; activeShot.FirstHitTime = Time.time - activeShot.ReleaseTime; try { object obj4 = ((object)activeShot.Ball).GetType().GetProperty("GroundData", BindingFlags.Instance | BindingFlags.Public)?.GetValue(activeShot.Ball); if (obj4 != null) { FieldInfo field = obj4.GetType().GetField("terrainDominantGlobalLayer", BindingFlags.Instance | BindingFlags.Public); if (field != null) { activeShot.FirstHitTerrain = field.GetValue(obj4)?.ToString() ?? "unknown"; } } } catch { } } } activeShot.PrevPos = position; activeShot.PrevVel = linearVelocity; if (((Vector3)(ref linearVelocity)).sqrMagnitude > 0.05f) { activeShot.LastMoveTime = Time.time; activeShot.LastPos = position; } else { if (Time.time - activeShot.LastMoveTime < 0.3f || Time.time - activeShot.ReleaseTime < 1.5f) { return; } bool flag2 = activeShot.MaxDistFromStart > 10f && Vector3.Distance(position, activeShot.BallStart) < 5f; Vector2 val = new Vector2(position.x - activeShot.BallStart.x, position.z - activeShot.BallStart.z); Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(activeShot.HolePos.x - activeShot.BallStart.x, activeShot.HolePos.z - activeShot.BallStart.z); Vector2 val3 = val - val2; Vector2 normalized = ((Vector2)(ref val2)).normalized; Vector2 val4 = default(Vector2); ((Vector2)(ref val4))..ctor(normalized.y, 0f - normalized.x); float num4 = Vector2.Dot(val3, normalized); float num5 = Vector2.Dot(val3, val4); Vector2 val5 = new Vector2(activeShot.Wind.x, activeShot.Wind.z); float num6 = Vector2.Dot(val5, normalized); float num7 = Vector2.Dot(val5, val4); float num8 = activeShot.HolePos.y - activeShot.BallStart.y; float magnitude = ((Vector2)(ref val2)).magnitude; float num9 = num4 - activeShot.SolverPredictedLongMiss; float num10 = num5 - activeShot.SolverPredictedSideMiss; float num11 = Vector3.Distance(position, activeShot.HolePos); bool flag3 = SwingReleaseHook.LastSinkTime > activeShot.ReleaseTime - 0.1f; float num12 = 0f; float num13 = 0f; float num14 = 0f; float num15 = 0f; float num16 = 0f; float num17 = 0f; if (activeShot.FirstHitCaptured) { Vector2 val6 = new Vector2(activeShot.FirstHitPos.x - activeShot.BallStart.x, activeShot.FirstHitPos.z - activeShot.BallStart.z) - val2; num12 = Vector2.Dot(val6, normalized); num13 = Vector2.Dot(val6, val4); num14 = Vector3.Distance(new Vector3(activeShot.FirstHitPos.x, 0f, activeShot.FirstHitPos.z), new Vector3(position.x, 0f, position.z)); Vector2 val7 = new Vector2(activeShot.FirstHitVel.x, activeShot.FirstHitVel.z); num15 = ((Vector2)(ref val7)).magnitude; num16 = activeShot.FirstHitVel.y; num17 = Mathf.Atan2(0f - num16, Mathf.Max(0.01f, num15)) * 57.29578f; } float num18 = 0f; float num19 = 0f; float num20 = -1f; if (activeShot.EarlySampled0 && activeShot.EarlySampled1 && activeShot.EarlyDt > 0.01f) { Vector3 val8 = (activeShot.EarlyVel1 - activeShot.EarlyVel0) / activeShot.EarlyDt; num18 = val8.y; num19 = ((Vector3)(ref val8)).magnitude; Vector3 val9 = (activeShot.EarlyVel0 + activeShot.EarlyVel1) * 0.5f; Vector3 val10 = activeShot.EarlyVel1 - activeShot.EarlyVel0; Vector3 val11 = default(Vector3); ((Vector3)(ref val11))..ctor(0f, Physics.gravity.y * activeShot.EarlyDt, 0f); Vector3 val12 = val10 - val11; float magnitude2 = ((Vector3)(ref val9)).magnitude; if (magnitude2 >= 40f && ((Vector3)(ref val12)).magnitude >= 0.5f) { float num21 = ((Vector3)(ref val12)).magnitude / (magnitude2 * magnitude2 * magnitude2 * activeShot.EarlyDt); if (num21 > 5E-05f && num21 < 0.002f) { num20 = num21; if (SwingReleaseHook.CalibratedDrag < 0f) { SwingReleaseHook.CalibratedDrag = num21; } else { SwingReleaseHook.CalibratedDrag = 0.5f * SwingReleaseHook.CalibratedDrag + 0.5f * num21; } SwingReleaseHook.CalibratedShotCount++; } } } Plugin.Log.LogInfo((object)(string.Format("BV-TEL|LAND|id={0}|valid={1}|oob={2}|", activeShot.ShotId, flag2 ? "0" : "1", flag2 ? "1" : "0") + $"dist={magnitude:F2}|dy={num8:F2}|" + $"landX={position.x:F2}|landY={position.y:F2}|landZ={position.z:F2}|" + $"maxDistReached={activeShot.MaxDistFromStart:F2}|apexY={activeShot.ApexY:F2}|" + $"missLong={num4:F2}|missSide={num5:F2}|" + "fhCaptured=" + (activeShot.FirstHitCaptured ? "1" : "0") + "|" + $"fhX={activeShot.FirstHitPos.x:F2}|fhY={activeShot.FirstHitPos.y:F2}|fhZ={activeShot.FirstHitPos.z:F2}|" + $"fhMissLong={num12:F2}|fhMissSide={num13:F2}|" + $"fhVx={num15:F2}|fhVy={num16:F2}|fhAngle={num17:F1}|" + $"fhTime={activeShot.FirstHitTime:F2}|fhTerrain={activeShot.FirstHitTerrain}|" + $"rollDist={num14:F2}|" + $"windHead={num6:F2}|windCross={num7:F2}|windMag={((Vector3)(ref activeShot.Wind)).magnitude:F2}|" + $"pitch={activeShot.Pitch:F2}|power={activeShot.Power:F3}|yawOff={activeShot.YawOffsetDeg:F2}|" + $"solverPredLong={activeShot.SolverPredictedLongMiss:F2}|solverPredSide={activeShot.SolverPredictedSideMiss:F2}|" + $"longErr={num9:F2}|sideErr={num10:F2}|" + string.Format("measG={0:F3}|measA={1:F3}|rbDrag={2:F4}|rbUseG={3}|", num18, num19, activeShot.RbDrag, activeShot.RbUseGravity ? "1" : "0") + $"v0x={activeShot.EarlyVel0.x:F2}|v0y={activeShot.EarlyVel0.y:F2}|v0z={activeShot.EarlyVel0.z:F2}|" + $"v1x={activeShot.EarlyVel1.x:F2}|v1y={activeShot.EarlyVel1.y:F2}|v1z={activeShot.EarlyVel1.z:F2}|dtEarly={activeShot.EarlyDt:F3}|" + $"vLx={activeShot.VLaunch.x:F2}|vLy={activeShot.VLaunch.y:F2}|vLz={activeShot.VLaunch.z:F2}|vLmag={((Vector3)(ref activeShot.VLaunch)).magnitude:F2}|" + $"backDrag={num20:F6}|calDrag={SwingReleaseHook.CalibratedDrag:F6}|calCnt={SwingReleaseHook.CalibratedShotCount}|" + string.Format("restDist={0:F2}|sunk={1}", num11, flag3 ? "1" : "0"))); _activeShot = null; } } public static void TriggerFullPowerOnly() { PlayerGolfer localPlayerAsGolfer = GameManager.LocalPlayerAsGolfer; if ((Object)(object)localPlayerAsGolfer == (Object)null) { Plugin.Log.LogWarning((object)"BV: no local golfer."); return; } if (_releaseMethod == null) { Type typeFromHandle = typeof(PlayerGolfer); _releaseMethod = typeFromHandle.GetMethod("ReleaseSwingCharge", BindingFlags.Instance | BindingFlags.Public); _tryStartChargingMethod = typeFromHandle.GetMethod("TryStartChargingSwing", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); _isAimingField = typeFromHandle.GetField("<IsAimingSwing>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic); _isChargingProp = typeFromHandle.GetProperty("IsChargingSwing", BindingFlags.Instance | BindingFlags.Public); _isAimingProp = typeFromHandle.GetProperty("IsAimingSwing", BindingFlags.Instance | BindingFlags.Public); } SwingReleaseHook.ForceFullPower[((Object)localPlayerAsGolfer).GetInstanceID()] = true; ((MonoBehaviour)localPlayerAsGolfer).StartCoroutine(FullPowerSequence(localPlayerAsGolfer)); } private static IEnumerator FullPowerSequence(PlayerGolfer local) { if (!(bool)(_isAimingProp?.GetValue(local) ?? ((object)false))) { typeof(PlayerGolfer).GetField("<IsAimingSwing>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(local, true); yield return null; } if (!(bool)(_isChargingProp?.GetValue(local) ?? ((object)false))) { _tryStartChargingMethod?.Invoke(local, null); } FieldInfo chargeField = typeof(PlayerGolfer).GetField("<SwingNormalizedCharge>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic); float timeout = Time.time + 3f; while (Time.time < timeout && !(((chargeField != null) ? ((float)chargeField.GetValue(local)) : 0f) >= 0.99f)) { yield return null; } SwingReleaseHook.ForceFullPower.Remove(((Object)local).GetInstanceID()); _releaseMethod?.Invoke(local, null); Plugin.Log.LogInfo((object)"BV: full-power fired (natural charge)."); } private static IEnumerator FireSequence(PlayerGolfer local) { if (!(bool)(_isAimingProp?.GetValue(local) ?? ((object)false))) { _isAimingField?.SetValue(local, true); } int id = ((Object)local).GetInstanceID(); bool ready = false; for (int i = 0; i < 15; i++) { if (SwingReleaseHook.InRange.TryGetValue(id, out var value) && value && SwingReleaseHook.LatestCharge.TryGetValue(id, out var _) && SwingReleaseHook.LatestDirection.TryGetValue(id, out var _)) { ready = true; break; } yield return null; } if (!ready) { Plugin.Log.LogWarning((object)"BV: R aborted — hole out of range or solver did not converge."); yield break; } bool flag = (bool)(_isChargingProp?.GetValue(local) ?? ((object)false)); if (!flag) { float tryUntil = Time.time + 1.5f; while (Time.time < tryUntil && !flag) { _tryStartChargingMethod?.Invoke(local, null); yield return (object)new WaitForFixedUpdate(); flag = (bool)(_isChargingProp?.GetValue(local) ?? ((object)false)); } if (!flag) { Plugin.Log.LogWarning((object)"BV: R aborted — TryStartChargingSwing never succeeded (prior swing or ball drop in progress)."); yield break; } } yield return (object)new WaitForFixedUpdate(); try { GolfHole mainHole = GolfHoleManager.MainHole; object obj = typeof(PlayerGolfer).GetProperty("NetworkownBall", BindingFlags.Instance | BindingFlags.Public)?.GetValue(local); if ((Object)(object)mainHole != (Object)null) { Component val = (Component)((obj is Component) ? obj : null); if (val != null) { int instanceID = ((Object)local).GetInstanceID(); float lastSolverPitchDeg = SwingReleaseHook.LastSolverPitchDeg; float value4; float power = (SwingReleaseHook.LatestCharge.TryGetValue(instanceID, out value4) ? value4 : 0f); Vector3 wind = Vector3.zero; try { if (WindManager.CurrentWindSpeed > 0) { wind = WindManager.Wind; } } catch { } float yawOffsetDeg = 0f; Vector3 value5; Vector3 val2 = (SwingReleaseHook.LatestDirection.TryGetValue(instanceID, out value5) ? value5 : Vector3.zero); if (((Vector3)(ref val2)).sqrMagnitude > 0.01f) { Vector2 val3 = new Vector2(val2.x, val2.z); Vector2 normalized = ((Vector2)(ref val3)).normalized; val3 = new Vector2(((Component)mainHole).transform.position.x - val.transform.position.x, ((Component)mainHole).transform.position.z - val.transform.position.z); yawOffsetDeg = Vector2.SignedAngle(((Vector2)(ref val3)).normalized, normalized); } BeginShotTelemetry(val.transform.position, ((Component)mainHole).transform.position, wind, lastSolverPitchDeg, power, yawOffsetDeg, SwingReleaseHook.LastMaxSpeed, SwingReleaseHook.LastDrag, SwingReleaseHook.LastWindFactor, SwingReleaseHook.LastCrossWindFactor, SwingReleaseHook.LastSolverPredictedMiss.x, SwingReleaseHook.LastSolverPredictedMiss.y, val); } } } catch { } _releaseMethod?.Invoke(local, null); Plugin.Log.LogInfo((object)"BV: auto-fired."); } } internal static class NativePhysics { public struct Sample { public float NormalizedSpeed; public float Distance; public TerrainLayer Layer; public LevelHazardType LevelHazard; public OutOfBoundsHazard OutOfBoundsHazard; } private static bool _initialized; private static bool _available; private static bool _loggedTypes; private static NativeArray<float> _normSpeeds; private static NativeArray<SwingDistanceEstimation> _out; private static Func<object>? _getSpatiallyHashedTerrains; private static Func<object>? _getGlobalTerrainLayerIndices; private static Func<object>? _getAllTerrainLayerWeights; private static Func<object>? _getAllTerrainHeights; private static Func<object>? _getTerrainSize; private static Func<object>? _getSecondaryOOBHazards; private static Func<object>? _getLevelHazards; private static Func<object>? _getMainOOBHazard; public static bool IsAvailable => _available; public static void Init() { //IL_0015: 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_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) if (_initialized) { return; } _initialized = true; try { _normSpeeds = new NativeArray<float>(301, (Allocator)4, (NativeArrayOptions)1); _out = new NativeArray<SwingDistanceEstimation>(301, (Allocator)4, (NativeArrayOptions)1); for (int i = 0; i < 301; i++) { _normSpeeds[i] = (float)i * 0.0033333334f; } Type typeFromHandle = typeof(TerrainManager); Type typeFromHandle2 = typeof(BoundsManager); _getSpatiallyHashedTerrains = ReflectStatic(typeFromHandle, "SpatiallyHashedJobsTerrains"); _getGlobalTerrainLayerIndices = ReflectStatic(typeFromHandle, "GlobalTerrainLayerIndicesPerLevelTerrainLayer"); _getAllTerrainLayerWeights = ReflectStatic(typeFromHandle, "AllTerrainLayerWeights"); _getAllTerrainHeights = ReflectStatic(typeFromHandle, "AllTerrainHeights"); _getTerrainSize = ReflectStatic(typeFromHandle, "TerrainSize"); _getSecondaryOOBHazards = ReflectStatic(typeFromHandle2, "SecondaryOutOfBoundsHazardInstances"); _getLevelHazards = ReflectStatic(typeFromHandle2, "LevelHazardInstances"); _getMainOOBHazard = ReflectStatic(typeFromHandle2, "MainOutOfBoundsHazard"); _available = _getSpatiallyHashedTerrains != null && _getAllTerrainHeights != null && _getTerrainSize != null && _getLevelHazards != null; Plugin.Log.LogInfo((object)$"NativePhysics: available={_available} (containers resolved via reflection)"); } catch (Exception ex) { _available = false; Plugin.Log.LogWarning((object)("NativePhysics init failed: " + ex.Message)); } } public static void Shutdown() { if (_normSpeeds.IsCreated) { _normSpeeds.Dispose(); } if (_out.IsCreated) { _out.Dispose(); } _available = false; } private static Func<object>? ReflectStatic(Type t, string name) { PropertyInfo prop = t.GetProperty(name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (prop != null) { return () => prop.GetValue(null); } FieldInfo field = t.GetField(name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { return () => field.GetValue(null); } Plugin.Log.LogWarning((object)("NativePhysics: " + t.Name + "." + name + " not found; native path disabled.")); return null; } public static bool TryQuery(Vector3 launchPos, float yawRad, float pitchRad, float maxSpeed, float gravity, float drag, float dt, Sample[] outBuf) { //IL_0016: 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_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_027d: Unknown result type (might be due to invalid IL or missing references) //IL_0282: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_028e: Unknown result type (might be due to invalid IL or missing references) //IL_0296: Unknown result type (might be due to invalid IL or missing references) //IL_029b: Unknown result type (might be due to invalid IL or missing references) //IL_02a4: Unknown result type (might be due to invalid IL or missing references) //IL_02a9: Unknown result type (might be due to invalid IL or missing references) //IL_02b2: Unknown result type (might be due to invalid IL or missing references) //IL_02b7: Unknown result type (might be due to invalid IL or missing references) //IL_02c0: Unknown result type (might be due to invalid IL or missing references) //IL_02c5: Unknown result type (might be due to invalid IL or missing references) //IL_02ce: Unknown result type (might be due to invalid IL or missing references) //IL_02d3: Unknown result type (might be due to invalid IL or missing references) //IL_02dc: Unknown result type (might be due to invalid IL or missing references) //IL_02e1: Unknown result type (might be due to invalid IL or missing references) //IL_0314: Unknown result type (might be due to invalid IL or missing references) //IL_02f3: Unknown result type (might be due to invalid IL or missing references) //IL_02f8: Unknown result type (might be due to invalid IL or missing references) //IL_031d: Unknown result type (might be due to invalid IL or missing references) //IL_0324: Unknown result type (might be due to invalid IL or missing references) //IL_032a: Unknown result type (might be due to invalid IL or missing references) //IL_0330: Unknown result type (might be due to invalid IL or missing references) //IL_0335: Unknown result type (might be due to invalid IL or missing references) //IL_0383: Unknown result type (might be due to invalid IL or missing references) //IL_0384: Unknown result type (might be due to invalid IL or missing references) //IL_0389: Unknown result type (might be due to invalid IL or missing references) //IL_039a: Unknown result type (might be due to invalid IL or missing references) //IL_03a0: Unknown result type (might be due to invalid IL or missing references) //IL_03a2: Unknown result type (might be due to invalid IL or missing references) //IL_03a7: Unknown result type (might be due to invalid IL or missing references) //IL_031b: Unknown result type (might be due to invalid IL or missing references) //IL_03c2: Unknown result type (might be due to invalid IL or missing references) //IL_03c7: Unknown result type (might be due to invalid IL or missing references) //IL_03ea: Unknown result type (might be due to invalid IL or missing references) //IL_03f8: Unknown result type (might be due to invalid IL or missing references) //IL_03fa: Unknown result type (might be due to invalid IL or missing references) //IL_03ff: Unknown result type (might be due to invalid IL or missing references) //IL_0406: Unknown result type (might be due to invalid IL or missing references) //IL_0408: Unknown result type (might be due to invalid IL or missing references) //IL_040d: Unknown result type (might be due to invalid IL or missing references) //IL_0414: Unknown result type (might be due to invalid IL or missing references) //IL_0416: Unknown result type (might be due to invalid IL or missing references) //IL_041b: Unknown result type (might be due to invalid IL or missing references) if (!_available) { return false; } string text = "start"; try { float mainOutOfBoundsHazardHeight = 0f; OutOfBoundsHazard mainOutOfBoundsHazardType = (OutOfBoundsHazard)0; if (_getMainOOBHazard != null) { text = "mainOOB"; object obj = _getMainOOBHazard(); if (obj != null) { FieldInfo field = obj.GetType().GetField("Height", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); FieldInfo field2 = obj.GetType().GetField("Type", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { mainOutOfBoundsHazardHeight = (float)(field.GetValue(obj) ?? ((object)0f)); } if (field2 != null && field2.GetValue(obj) is OutOfBoundsHazard val) { mainOutOfBoundsHazardType = val; } } } text = "spatHash"; object obj2 = _getSpatiallyHashedTerrains(); text = "layerIdx"; object obj3 = _getGlobalTerrainLayerIndices(); text = "layerWts"; object obj4 = _getAllTerrainLayerWeights(); text = "terrHts"; object obj5 = _getAllTerrainHeights(); text = "secOob"; object obj6 = _getSecondaryOOBHazards(); text = "levelHaz"; object obj7 = _getLevelHazards(); text = "terrSize"; object obj8 = _getTerrainSize(); if (!_loggedTypes) { _loggedTypes = true; Plugin.Log.LogInfo((object)("NativePhysics types: spatHash=" + obj2?.GetType().FullName + ", layerIdx=" + obj3?.GetType().FullName + ", layerWts=" + obj4?.GetType().FullName + ", terrHts=" + obj5?.GetType().FullName + ", secOob=" + obj6?.GetType().FullName + ", levelHaz=" + obj7?.GetType().FullName + ", terrSize=" + obj8?.GetType().FullName)); } if (obj2 == null || obj3 == null || obj4 == null || obj5 == null || obj6 == null || obj7 == null || obj8 == null) { Plugin.Log.LogWarning((object)("NativePhysics.TryQuery: a container is null (stage=" + text + ")")); _available = false; return false; } text = "job-build"; CalculateFirstGroundHitDistancesJob val2 = default(CalculateFirstGroundHitDistancesJob); val2.normalizedInitialSpeeds = _normSpeeds; val2.estimatedDistances = _out; val2.spatiallyHashedTerrains = (NativeHashMap<int2, JobsTerrain>)obj2; val2.globalTerrainLayerIndicesPerLevelTerrainLayer = (NativeHashMap<int, int>)obj3; val2.allTerrainLayerWeights = (NativeArray<float>)obj4; val2.allTerrainHeights = (NativeArray<float>)obj5; val2.secondaryOutOfBoundsHazards = (NativeList<SecondaryOutOfBoundsHazardInstance>)obj6; val2.levelHazards = (NativeList<LevelHazardInstance>)obj7; val2.terrainSize = (float2)((obj8 is float2 val3) ? val3 : new float2(((Vector2)obj8).x, ((Vector2)obj8).y)); val2.initialWorldPosition2d = new float2(launchPos.x, launchPos.z); val2.yawRad = yawRad; val2.pitchRad = pitchRad; val2.baseInitialSpeed = 0f; val2.fullInitialSpeed = maxSpeed; val2.verticalGravity = gravity; val2.airDragCoefficient = drag; val2.deltaTime = dt; val2.mainOutOfBoundsHazardHeight = mainOutOfBoundsHazardHeight; val2.mainOutOfBoundsHazardType = mainOutOfBoundsHazardType; CalculateFirstGroundHitDistancesJob val4 = val2; text = "schedule"; JobHandle val5 = default(JobHandle); val5 = IJobParallelForExtensions.Schedule<CalculateFirstGroundHitDistancesJob>(val4, 301, 64, val5); ((JobHandle)(ref val5)).Complete(); text = "read"; for (int i = 0; i < 301; i++) { SwingDistanceEstimation val6 = _out[i]; outBuf[i] = new Sample { NormalizedSpeed = _normSpeeds[i], Distance = val6.distance, Layer = val6.layer, LevelHazard = val6.levelHazard, OutOfBoundsHazard = val6.outOfBoundsHazard }; } return true; } catch (Exception ex) { Plugin.Log.LogWarning((object)("NativePhysics.TryQuery failed at stage=" + text + ": " + ex.GetType().Name + ": " + ex.Message)); _available = false; return false; } } } internal static class NetworkBugfix { private static bool _installed; private static int _swallowCount; public static void Install(Harmony harmony) { //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Expected O, but got Unknown if (_installed) { return; } _installed = true; try { Type type = AccessTools.TypeByName("CheckpointManager"); if (type == null) { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { try { Type[] types = assembly.GetTypes(); foreach (Type type2 in types) { if (type2.Name == "CheckpointManager") { type = type2; break; } } } catch { } if (type != null) { break; } } } if (type == null) { Plugin.Log.LogWarning((object)"BV NetBugfix: CheckpointManager type not found; skipping patch."); return; } MethodInfo method = type.GetMethod("OnDeserialize", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (method == null) { Plugin.Log.LogWarning((object)("BV NetBugfix: " + type.FullName + ".OnDeserialize not found.")); return; } HarmonyMethod val = new HarmonyMethod(typeof(NetworkBugfix).GetMethod("OnDeserializeFinalizer", BindingFlags.Static | BindingFlags.NonPublic)); harmony.Patch((MethodBase)method, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null); Plugin.Log.LogInfo((object)("BV NetBugfix: patched " + type.FullName + ".OnDeserialize (NRE-swallow).")); } catch (Exception ex) { Plugin.Log.LogWarning((object)("BV NetBugfix: install failed: " + ex.Message)); } } private static Exception? OnDeserializeFinalizer(Exception __exception) { if (__exception == null) { return null; } if (__exception is NullReferenceException) { _swallowCount++; if (_swallowCount <= 5 || _swallowCount % 50 == 0) { Plugin.Log.LogWarning((object)$"BV NetBugfix: swallowed CheckpointManager.OnDeserialize NRE (#{_swallowCount})."); } return null; } return __exception; } } [BepInPlugin("com.lembo.perfectshot", "Perfect Shot", "1.0.2")] public class Plugin : BaseUnityPlugin { public const string Guid = "com.lembo.perfectshot"; internal static ManualLogSource Log; internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<KeyCode> ToggleKey; internal static ConfigEntry<KeyCode> AutoFireKey; internal static ConfigEntry<KeyCode> FullPowerKey; internal static ConfigEntry<bool> OverridePitch; internal static ConfigEntry<bool> MetalMario; internal static ConfigEntry<KeyCode> MetalMarioKey; internal static ConfigEntry<float> PowerTrim; private GUIStyle? _statusStyle; private void Awake() { //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Expected O, but got Unknown //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Expected O, but got Unknown //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Expected O, but got Unknown //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Expected O, but got Unknown //IL_0235: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Expected O, but got Unknown //IL_027f: Unknown result type (might be due to invalid IL or missing references) //IL_028d: Expected O, but got Unknown //IL_02c9: Unknown result type (might be due to invalid IL or missing references) //IL_02d7: Expected O, but got Unknown //IL_0330: Unknown result type (might be due to invalid IL or missing references) //IL_033e: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", false, "Master toggle for Perfect Shot."); ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ToggleKey", (KeyCode)106, "Key to toggle Perfect Shot on/off."); AutoFireKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "AutoFireKey", (KeyCode)114, "Press while aiming (right-click held) to fire a perfect auto-aim shot."); FullPowerKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "FullPowerKey", (KeyCode)113, "Press while aiming to fire a perfect 100% power shot in your current aim direction."); OverridePitch = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "OverridePitch", true, "Auto-pick the best pitch preset. Disable to keep the pitch you chose manually."); MetalMario = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "MetalMario", false, "Immune to knockouts and freezes from items/swings/carts. Own movement unchanged."); MetalMarioKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "MetalMarioKey", (KeyCode)109, "Key to toggle Metal Mario on/off."); PowerTrim = ((BaseUnityPlugin)this).Config.Bind<float>("General", "PowerTrim", 1f, "Global multiplier on computed R-shot power. Lower if shots go long."); Harmony val = new Harmony("com.lembo.perfectshot"); try { val.PatchAll(typeof(SwingHook)); Type typeFromHandle = typeof(PlayerGolfer); MethodInfo method = typeFromHandle.GetMethod("GetSwingDirection", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo method2 = typeFromHandle.GetMethod("UpdateSwingNormalizedPower", BindingFlags.Instance | BindingFlags.NonPublic); if (method != null) { val.Patch((MethodBase)method, new HarmonyMethod(typeof(SwingReleaseHook).GetMethod("GetSwingDirectionPrefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } if (method2 != null) { val.Patch((MethodBase)method2, (HarmonyMethod)null, new HarmonyMethod(typeof(SwingReleaseHook).GetMethod("UpdateSwingNormalizedPowerPostfix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } MethodInfo method3 = typeof(PlayerMovement).GetMethod("AlignWithCameraImmediately", BindingFlags.Instance | BindingFlags.Public); if (method3 != null) { val.Patch((MethodBase)method3, new HarmonyMethod(typeof(SwingReleaseHook).GetMethod("AlignWithCameraImmediatelyPrefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } MethodInfo method4 = typeof(PlayerMovement).GetMethod("TryKnockOut", BindingFlags.Instance | BindingFlags.Public); if (method4 != null) { val.Patch((MethodBase)method4, new HarmonyMethod(typeof(SwingReleaseHook).GetMethod("TryKnockOutPrefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } MethodInfo method5 = typeof(PlayerMovement).GetMethod("CanBeKnockedOutBy", BindingFlags.Instance | BindingFlags.NonPublic); if (method5 != null) { val.Patch((MethodBase)method5, new HarmonyMethod(typeof(SwingReleaseHook).GetMethod("CanBeKnockedOutByPrefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } MethodInfo method6 = typeof(Hittable).GetMethod("HitWithGolfSwing", BindingFlags.Instance | BindingFlags.Public); if (method6 != null) { val.Patch((MethodBase)method6, new HarmonyMethod(typeof(SwingReleaseHook).GetMethod("HitWithGolfSwingPrefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } try { Type type = AccessTools.TypeByName("GolfHoleTrigger"); if (type != null) { MethodInfo method7 = type.GetMethod("OnTriggerEnter", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (method7 != null) { MethodInfo method8 = typeof(SwingReleaseHook).GetMethod("OnSinkEventPrefix", BindingFlags.Static | BindingFlags.NonPublic); if (method8 != null) { val.Patch((MethodBase)method7, new HarmonyMethod(method8), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } Log.LogInfo((object)"BV: GolfHoleTrigger.OnTriggerEnter patched for sink detection."); } } } catch (Exception ex) { Log.LogWarning((object)("BV: GolfHoleTrigger patch failed: " + ex.Message)); } NetworkBugfix.Install(val); NativePhysics.Init(); Log.LogInfo((object)"Perfect Shot 1.0.2 loaded. J/R/Q/M."); } catch (Exception arg) { Log.LogError((object)$"Perfect Shot failed to patch: {arg}"); } } private static Key MapKey(KeyCode k) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Expected I4, but got Unknown //IL_00e4: 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_00f1: 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_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0164: 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_0077: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Expected I4, but got Unknown //IL_016a: 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_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: 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_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) return (Key)((k - 97) switch { 0 => 15, 1 => 16, 2 => 17, 3 => 18, 4 => 19, 5 => 20, 6 => 21, 7 => 22, 8 => 23, 9 => 24, 10 => 25, 11 => 26, 12 => 27, 13 => 28, 14 => 29, 15 => 30, 16 => 31, 17 => 32, 18 => 33, 19 => 34, 20 => 35, 21 => 36, 22 => 37, 23 => 38, 24 => 39, 25 => 40, _ => (k - 282) switch { 0 => 94, 1 => 95, 2 => 96, 3 => 97, 4 => 98, 5 => 99, 6 => 100, 7 => 101, _ => 24, }, }); } private void FixedUpdate() { if (Enabled.Value) { AutoFire.TickShotTelemetry(); } } private void OnGUI() { //IL_0013: 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_0020: 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_0033: Expected O, but got Unknown //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) if (_statusStyle == null) { _statusStyle = new GUIStyle(GUI.skin.label) { fontSize = 18, fontStyle = (FontStyle)1, alignment = (TextAnchor)0 }; } string text = (Enabled.Value ? "ON" : "OFF"); string text2 = (MetalMario.Value ? "METAL" : "metal off"); _statusStyle.normal.textColor = (Enabled.Value ? new Color(0.4f, 1f, 0.4f, 0.9f) : new Color(1f, 0.5f, 0.5f, 0.7f)); GUI.Label(new Rect(12f, 12f, 500f, 28f), $"Perfect Shot: {text} [{ToggleKey.Value}] {text2} [{MetalMarioKey.Value}]", _statusStyle); } private void OnDestroy() { NativePhysics.Shutdown(); } private void Update() { //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_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: 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) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) Keyboard current = Keyboard.current; if (current == null) { return; } if (((ButtonControl)current[MapKey(ToggleKey.Value)]).wasPressedThisFrame) { Enabled.Value = !Enabled.Value; Log.LogInfo((object)("Perfect Shot " + (Enabled.Value ? "ENABLED" : "disabled") + ".")); } if (((ButtonControl)current[MapKey(MetalMarioKey.Value)]).wasPressedThisFrame) { MetalMario.Value = !MetalMario.Value; Log.LogInfo((object)("BV Metal Mario " + (MetalMario.Value ? "ENABLED" : "disabled") + ".")); } if (Enabled.Value) { if (((ButtonControl)current[MapKey(AutoFireKey.Value)]).wasPressedThisFrame) { AutoFire.Trigger(); } if (((ButtonControl)current[MapKey(FullPowerKey.Value)]).wasPressedThisFrame) { AutoFire.TriggerFullPowerOnly(); } } } } internal static class SwingReleaseHook { internal static readonly Dictionary<int, float> LatestCharge = new Dictionary<int, float>(); internal static readonly Dictionary<int, Vector3> LatestDirection = new Dictionary<int, Vector3>(); internal static readonly Dictionary<int, bool> InRange = new Dictionary<int, bool>(); internal static float LastMaxSpeed; internal static float LastDrag; internal static float LastWindFactor; internal static float LastCrossWindFactor; internal static Vector2 LastSolverPredictedMiss; internal static float LastSolverPitchDeg = 45f; internal static float LastSinkTime = -1f; internal static int LastSinkNetId = 0; internal static float CalibratedDrag = -1f; internal static int CalibratedShotCount = 0; internal static readonly Dictionary<int, bool> ForceFullPower = new Dictionary<int, bool>(); internal static bool GetSwingDirectionPrefix(PlayerGolfer __instance, float pitch, ref Vector3 __result) { //IL_0053: 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) if (!Plugin.Enabled.Value) { return true; } if (!((NetworkBehaviour)__instance).isLocalPlayer) { return true; } int instanceID = ((Object)__instance).GetInstanceID(); if (ForceFullPower.TryGetValue(instanceID, out var value) && value) { return true; } if (InRange.TryGetValue(instanceID, out var value2) && value2 && LatestDirection.TryGetValue(instanceID, out var value3)) { __result = value3; return false; } return true; } internal static void UpdateSwingNormalizedPowerPostfix(PlayerGolfer __instance, bool forSwingRelease) { if (forSwingRelease && Plugin.Enabled.Value && ((NetworkBehaviour)__instance).isLocalPlayer) { int instanceID = ((Object)__instance).GetInstanceID(); bool value2; float value3; if (ForceFullPower.TryGetValue(instanceID, out var value) && value) { SwingHook.ForceCharge(__instance, 1f); } else if (InRange.TryGetValue(instanceID, out value2) && value2 && LatestCharge.TryGetValue(instanceID, out value3)) { SwingHook.ForceCharge(__instance, value3); } } } internal static bool AlignWithCameraImmediatelyPrefix(PlayerMovement __instance) { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.Enabled.Value) { return true; } PlayerGolfer localPlayerAsGolfer = GameManager.LocalPlayerAsGolfer; if ((Object)(object)localPlayerAsGolfer == (Object)null) { return true; } if ((Object)(object)__instance.PlayerInfo == (Object)null || (Object)(object)__instance.PlayerInfo.AsGolfer != (Object)(object)localPlayerAsGolfer) { return true; } int instanceID = ((Object)localPlayerAsGolfer).GetInstanceID(); if (!InRange.TryGetValue(instanceID, out var value) || !value) { return true; } if (!LatestDirection.TryGetValue(instanceID, out var value2)) { return true; } float num = Mathf.Atan2(value2.x, value2.z) * 57.29578f; Type typeFromHandle = typeof(PlayerMovement); typeFromHandle.GetProperty("Yaw", BindingFlags.Instance | BindingFlags.Public)?.SetValue(__instance, num); typeFromHandle.GetField("targetYaw", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(__instance, num); object? obj = typeFromHandle.GetField("rigidbody", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(__instance); Rigidbody val = (Rigidbody)((obj is Rigidbody) ? obj : null); Quaternion rotation = Quaternion.Euler(0f, num, 0f); if ((Object)(object)val != (Object)null) { val.rotation = rotation; } ((Component)__instance).transform.rotation = rotation; return false; } internal static bool TryKnockOutPrefix(PlayerMovement __instance, ref bool __result, ref bool isNewKnockout) { if (!Plugin.Enabled.Value || !Plugin.MetalMario.Value) { return true; } PlayerGolfer localPlayerAsGolfer = GameManager.LocalPlayerAsGolfer; if ((Object)(object)localPlayerAsGolfer == (Object)null) { return true; } if ((Object)(object)__instance.PlayerInfo == (Object)null || (Object)(object)__instance.PlayerInfo.AsGolfer != (Object)(object)localPlayerAsGolfer) { return true; } __result = false; isNewKnockout = false; return false; } internal static bool OnSinkEventPrefix(Component __instance, Collider other) { try { if ((Object)(object)other == (Object)null || (Object)(object)__instance == (Object)null) { return true; } _ = ((object)__instance).GetType().GetField("ballTrigger", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) != null; PlayerGolfer localPlayerAsGolfer = GameManager.LocalPlayerAsGolfer; if ((Object)(object)localPlayerAsGolfer == (Object)null) { return true; } object? obj = typeof(PlayerGolfer).GetProperty("NetworkownBall", BindingFlags.Instance | BindingFlags.Public)?.GetValue(localPlayerAsGolfer); Component val = (Component)((obj is Component) ? obj : null); if (val == null) { return true; } if (!((Object)(object)((Component)other).transform == (Object)(object)val.transform) && !((Component)other).transform.IsChildOf(val.transform) && !val.transform.IsChildOf(((Component)other).transform)) { return true; } LastSinkTime = Time.time; Plugin.Log.LogInfo((object)$"BV SINK (own ball): trigger={((Object)__instance).name} by={((Object)other).name} at t={LastSinkTime:F2}"); } catch (Exception ex) { Plugin.Log.LogWarning((object)("BV OnSinkEventPrefix error: " + ex.Message)); } return true; } internal static bool CanBeKnockedOutByPrefix(PlayerMovement __instance, ref bool __result) { if (!Plugin.Enabled.Value || !Plugin.MetalMario.Value) { return true; } PlayerGolfer localPlayerAsGolfer = GameManager.LocalPlayerAsGolfer; if ((Object)(object)localPlayerAsGolfer == (Object)null) { return true; } if ((Object)(object)__instance.PlayerInfo == (Object)null || (Object)(object)__instance.PlayerInfo.AsGolfer != (Object)(object)localPlayerAsGolfer) { return true; } __result = false; return false; } internal static void HitWithGolfSwingPrefix(bool isPutt, ref float power, ref float sideSpin, PlayerGolfer hitter) { if (Plugin.Enabled.Value && !((Object)(object)hitter == (Object)null) && ((NetworkBehaviour)hitter).isLocalPlayer) { int instanceID = ((Object)hitter).GetInstanceID(); if (ForceFullPower.TryGetValue(instanceID, out var value) && value) { ForceFullPower.Remove(instanceID); } } } } [HarmonyPatch(typeof(PlayerGolfer), "OnBUpdate")] internal static class SwingHook { private static FieldInfo? _chargeField; private static FieldInfo? _powerField; private static PropertyInfo? _ownBallProp; private static PropertyInfo? _isAimingProp; private static PropertyInfo? _isChargingProp; private static PropertyInfo? _isSwingingProp; private static PropertyInfo? _swingPitchProp; private static MethodInfo? _setPitchMethod; private static bool _initFailed; private static FieldInfo? _gameRequiredNormField; private static WindElevationSolver.Result _cachedResult; private static Vector3 _cachedBall; private static Vector3 _cachedHole; private static Vector3 _cachedWind; private static float _cachedPitch; private static bool _hasCache; private static int _diag; private static float _lastSolveTime; private static bool _loggedInputsOnce; private static bool _loggedReflection; private static bool TryInitReflection() { if (_initFailed) { return false; } if (_chargeField != null) { return true; } try { Type typeFromHandle = typeof(PlayerGolfer); _chargeField = typeFromHandle.GetField("<SwingNormalizedCharge>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic); _powerField = typeFromHandle.GetField("<SwingNormalizedPower>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic); _ownBallProp = typeFromHandle.GetProperty("NetworkownBall", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); _isAimingProp = typeFromHandle.GetProperty("IsAimingSwing", BindingFlags.Instance | BindingFlags.Public); _isChargingProp = typeFromHandle.GetProperty("IsChargingSwing", BindingFlags.Instance | BindingFlags.Public); _isSwingingProp = typeFromHandle.GetProperty("IsSwinging", BindingFlags.Instance | BindingFlags.Public); _swingPitchProp = typeFromHandle.GetProperty("SwingPitch", BindingFlags.Instance | BindingFlags.Public); _setPitchMethod = typeFromHandle.GetMethod("SetPitch", BindingFlags.Instance | BindingFlags.Public); if (_chargeField == null || _isAimingProp == null || _setPitchMethod == null) { _initFailed = true; return false; } return true; } catch { _initFailed = true; return false; } } [HarmonyPostfix] private static void Postfix(PlayerGolfer __instance) { //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: 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_00db: 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) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.Enabled.Value || !((NetworkBehaviour)__instance).isLocalPlayer || !TryInitReflection()) { return; } try { bool num = (bool)(_isAimingProp.GetValue(__instance) ?? ((object)false)); bool flag = (bool)(_isChargingProp?.GetValue(__instance) ?? ((object)false)); bool flag2 = (bool)(_isSwingingProp?.GetValue(__instance) ?? ((object)false)); if (!num && !flag && !flag2) { return; } GolfHole mainHole = GolfHoleManager.MainHole; if ((Object)(object)mainHole == (Object)null) { return; } object obj = _ownBallProp?.GetValue(__instance); Component val = (Component)((obj is Component) ? obj : null); if (val == null) { return; } Vector3 position = val.transform.position; Vector3 val2 = ((Component)mainHole).transform.position - position; Vector3 val3 = default(Vector3); ((Vector3)(ref val3))..ctor(val2.x, 0f, val2.z); if (((Vector3)(ref val3)).magnitude < 0.05f) { return; } float num2 = (float)(_swingPitchProp?.GetValue(__instance) ?? ((object)0f)); if (!(num2 <= 0f)) { WindElevationSolver.Result result = RunFullPhysicsSolve(__instance, obj, val, mainHole, num2); if (result.Solved) { Vector3 val4 = default(Vector3); ((Vector3)(ref val4))..ctor(result.Direction.x, 0f, result.Direction.z); if (((Vector3)(ref val4)).sqrMagnitude > 0.0001f) { ((Component)__instance).transform.rotation = Quaternion.LookRotation(((Vector3)(ref val4)).normalized, Vector3.up); } SwingReleaseHook.LatestDirection[((Object)__instance).GetInstanceID()] = result.Direction; float num3 = Mathf.Clamp(result.NormPower * Plugin.PowerTrim.Value, 0f, 2f); SetCharge(__instance, num3); if (++_diag % 120 == 0) { Plugin.Log.LogInfo((object)$"BV solved: pitch={result.PitchDeg:F0} yaw={result.YawDeg:F1} norm={result.NormPower:F2} -> {num3:F2}"); } return; } if (++_diag % 120 == 0) { Plugin.Log.LogInfo((object)"BV: unsolved, capping at 1.0"); } } SwingReleaseHook.InRange[((Object)__instance).GetInstanceID()] = false; CapChargeAtOne(__instance); } catch (Exception ex) { Plugin.Log.LogError((object)("BV postfix error: " + ex.Message)); } } private static void SetCharge(PlayerGolfer golfer, float norm) { _chargeField.SetValue(golfer, norm); SwingReleaseHook.LatestCharge[((Object)golfer).GetInstanceID()] = norm; SwingReleaseHook.InRange[((Object)golfer).GetInstanceID()] = true; } internal static void ForceCharge(PlayerGolfer golfer, float norm) { TryInitReflection(); _chargeField?.SetValue(golfer, norm); _powerField?.SetValue(golfer, norm); } private static void CapChargeAtOne(PlayerGolfer golfer) { try { if ((float)(_chargeField.GetValue(golfer) ?? ((object)0f)) > 1f) { _chargeField.SetValue(golfer, 1f); } } catch { } } private static WindElevationSolver.Result RunFullPhysicsSolve(PlayerGolfer golfer, object ownBallObj, Component ballComp, GolfHole hole, float currentPitch) { //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_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_02d6: Unknown result type (might be due to invalid IL or missing references) //IL_02d7: Unknown result type (might be due to invalid IL or missing references) //IL_02de: Unknown result type (might be due to invalid IL or missing references) //IL_02df: Unknown result type (might be due to invalid IL or missing references) //IL_02e6: Unknown result type (might be due to invalid IL or missing references) //IL_0309: Unknown result type (might be due to invalid IL or missing references) //IL_030a: Unknown result type (might be due to invalid IL or missing references) //IL_0346: Unknown result type (might be due to invalid IL or missing references) //IL_0347: Unknown result type (might be due to invalid IL or missing references) //IL_034c: Unknown result type (might be due to invalid IL or missing references) //IL_034d: Unknown result type (might be due to invalid IL or missing references) //IL_0352: Unknown result type (might be due to invalid IL or missing references) //IL_0353: 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_0038: 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_004a: 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_03a0: Unknown result type (might be due to invalid IL or missing references) //IL_03a5: 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_04d8: Unknown result type (might be due to invalid IL or missing references) //IL_04e3: Unknown result type (might be due to invalid IL or missing references) //IL_04e9: Unknown result type (might be due to invalid IL or missing references) //IL_04ee: Unknown result type (might be due to invalid IL or missing references) //IL_04f9: Unknown result type (might be due to invalid IL or missing references) //IL_04ff: Unknown result type (might be due to invalid IL or missing references) //IL_0513: Unknown result type (might be due to invalid IL or missing references) //IL_051f: Unknown result type (might be due to invalid IL or missing references) //IL_0453: Unknown result type (might be due to invalid IL or missing references) //IL_045f: Unknown result type (might be due to invalid IL or missing references) Vector3 position = ballComp.transform.position; Vector3 position2 = ((Component)hole).transform.position; Vector3 val = Vector3.zero; try { if (WindManager.CurrentWindSpeed > 0) { val = WindManager.Wind; } } catch { } bool num = _hasCache && Vector3.Distance(position, _cachedBall) < 0.5f && Vector3.Distance(position2, _cachedHole) < 0.5f && Vector3.Distance(val, _cachedWind) < 0.5f && Mathf.Abs(currentPitch - _cachedPitch) < 3f; bool flag = Time.time - _lastSolveTime < 1f; if (num) { return _cachedResult; } if (_hasCache && flag) { return _cachedResult; } _lastSolveTime = Time.time; float num2 = 0.0005f; try { num2 = ReadFloat(typeof(GameManager).GetProperty("GolfBallSettings", BindingFlags.Static | BindingFlags.Public)?.GetValue(null), "LinearAirDragFactor", 0.0005f); } catch { } float num3 = 60f; float num4 = 0.1f; float num5 = 0.1f; try { object obj4 = ReadObj(ownBallObj, "AsEntity"); object obj5 = ReadObj(obj4, "AsHittable"); num3 = ReadFloat(ReadObj(obj5, "SwingSettings"), "MaxPowerSwingHitSpeed", 60f); object obj6 = ReadObj(obj5, "settings"); object obj7 = ReadObj(obj6, "Wind"); num4 = ReadFloat(obj7, "WindFactor", 0.1f); num5 = ReadFloat(obj7, "CrossWindFactor", 0.1f); if (!_loggedReflection) { _loggedReflection = true; Plugin.Log.LogInfo((object)("BV REFLECT: ownBall=" + (ownBallObj?.GetType().FullName ?? "null") + " asEntity=" + (obj4?.GetType().FullName ?? "NULL") + " asHit=" + (obj5?.GetType().FullName ?? "NULL") + " settings=" + (obj6?.GetType().FullName ?? "NULL") + " windSet=" + (obj7?.GetType().FullName ?? "NULL") + " " + $"wFactor={num4:F4} cFactor={num5:F4} " + "(if values == 0.1000 exactly, reflection failed and WindMultiplier should be ~8)")); } } catch { } try { float value = MatchSetupRules.GetValue((Rule)5); num3 *= value; } catch { } _ = ((Vector3)(ref val)).magnitude; float windFactor = num4; float crossWindFactor = num5; float drag = num2; WindElevationSolver.Inputs inputs = default(WindElevationSolver.Inputs); inputs.BallPos = position; inputs.HolePos = position2; inputs.Gravity = Physics.gravity.y; inputs.Drag = drag; inputs.MaxSpeed = num3; inputs.Wind = val; inputs.WindFactor = windFactor; inputs.CrossWindFactor = crossWindFactor; inputs.DeltaTime = Time.fixedDeltaTime; inputs.CurrentPitchDeg = currentPitch; WindElevationSolver.Inputs inp = inputs; _cachedResult = WindElevationSolver.Solve(inp); _cachedBall = position; _cachedHole = position2; _cachedWind = val; _cachedPitch = currentPitch; _hasCache = true; SwingReleaseHook.LastMaxSpeed = num3; SwingReleaseHook.LastDrag = num2; SwingReleaseHook.LastWindFactor = num4; SwingReleaseHook.LastCrossWindFactor = num5; SwingReleaseHook.LastSolverPitchDeg = (_cachedResult.Solved ? _cachedResult.PitchDeg : currentPitch); SwingReleaseHook.LastSolverPredictedMiss = Vector2.zero; if (!_loggedInputsOnce) { Plugin.Log.LogInfo((object)$"BV PHYSICS: MaxSpeed={num3:F2} Drag={num2:F6} WindFactor={num4:F3} CrossFactor={num5:F3} Gravity={inp.Gravity:F2} dt={inp.DeltaTime:F4}"); _loggedInputsOnce = true; } if (_diag % 120 == 0) { float num6 = TryReadGameRequiredNorm(); if (num6 >= 0f && _cachedResult.Solved && ((Vector3)(ref val)).sqrMagnitude < 0.01f && Mathf.Abs(inp.HolePos.y - inp.BallPos.y) < 0.5f) { Plugin.Log.LogInfo((object)$"CALIB flat-no-wind: ours={_cachedResult.NormPower:F3} game={num6:F3} ratio={_cachedResult.NormPower / Mathf.Max(0.001f, num6):F3}"); } } Plugin.Log.LogInfo((object)$"BV inputs: pitch={currentPitch:F0} horizR={Vector3.Distance(new Vector3(position.x, 0f, position.z), new Vector3(position2.x, 0f, position2.z)):F1} dy={inp.HolePos.y - inp.BallPos.y:F1} -> sol.pitch={_cachedResult.PitchDeg:F0} yaw={_cachedResult.YawDeg:F1} norm={_cachedResult.NormPower:F2} solved={_cachedResult.Solved}"); return _cachedResult; static float ReadFloat(object? obj, string name, float fallback) { if (obj == null) { return fallback; } try { Type type2 = obj.GetType(); while (type2 != null) { PropertyInfo property2 = type2.GetProperty(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (property2 != null) { return (float)property2.GetValue(obj); } FieldInfo field2 = type2.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field2 != null) { return (float)field2.GetValue(obj); } FieldInfo field3 = type2.GetField("<" + name + ">k__BackingField", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic); if (field3 != null) { return (float)field3.GetValue(obj); } type2 = type2.BaseType; } } catch { } return fallback; } static object? ReadObj(object? obj, string name) { if (obj == null) { return null; } try { Type type = obj.GetType(); while (type != null) { PropertyInfo property = type.GetProperty(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (property != null) { return property.GetValue(obj); } FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { return field.GetValue(obj); } type = type.BaseType; } } catch { } return null; } } private static float TryReadGameRequiredNorm() { try { if (_gameRequiredNormField == null) { _gameRequiredNormField = typeof(PlayerGolfer).GetField("desiredDistanceRequiredNormalizedSpeed", BindingFlags.Static | BindingFlags.NonPublic); } if (_gameRequiredNormField == null) { return -1f; } object value = _gameRequiredNormField.GetValue(null); if (value == null) { return -1f; } PropertyInfo property = value.GetType().GetProperty("Value", BindingFlags.Instance | BindingFlags.Public); if (property == null) { return -1f; } return (float)property.GetValue(value); } catch { return -1f; } } } internal static class WindElevationSolver { public struct Inputs { public Vector3 BallPos; public Vector3 HolePos; public float Gravity; public float Drag; public float MaxSpeed; public Vector3 Wind; public float WindFactor; public float CrossWindFactor; public float DeltaTime; public float CurrentPitchDeg; } public struct Result { public bool Solved; public float YawDeg; public float PitchDeg; public float NormPower; public Vector3 Direction; } private struct PowerSearchResult { public bool found; public float norm; public float miss; public float descentAngleDeg; public float landVxz; public float landVy; public float airtimeSec; } [ThreadStatic] private static NativePhysics.Sample[]? _nativeBuf; public static Result Solve(Inputs inp) { //IL_0016: 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_0032: 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_005f: 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_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_0235: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) Result result = default(Result); result.Solved = false; Result result2 = result; Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(inp.HolePos.x - inp.BallPos.x, 0f, inp.HolePos.z - inp.BallPos.z); float magnitude = ((Vector3)(ref val)).magnitude; if (magnitude < 0.05f) { return result2; } Vector3 val2 = val / magnitude; float dy = inp.HolePos.y - inp.BallPos.y; Vector2 targetXZ = default(Vector2); ((Vector2)(ref targetXZ))..ctor(val.x, val.z); bool flag = ((Vector3)(ref inp.Wind)).sqrMagnitude > 0.01f; int[] obj = new int[5] { 28, 42, 55, 68, 82 }; float yawHalfRange = (flag ? 15f : 0f); float yawStep = (flag ? 5f : 1f); float bestScore = float.MaxValue; float bestMiss = float.MaxValue; float bestYaw = 0f; float bestNorm = 1f; float bestPitchDeg = 45f; Vector3 bestDir = val2; int[] array = obj; for (int i = 0; i < array.Length; i++) { EvaluateAndUpdate(array[i], yawHalfRange, yawStep, val2, dy, targetXZ, inp, 15f, 0.03f, 0f, ref bestScore, ref bestMiss, ref bestYaw, ref bestNorm, ref bestPitchDeg, ref bestDir); } if (bestScore < float.MaxValue) { float num = Mathf.Max(25f, bestPitchDeg - 7f); float num2 = Mathf.Min(80f, bestPitchDeg + 7f); for (float num3 = num; num3 <= num2 + 0.001f; num3 += 2f) { int tryPitch = Mathf.RoundToInt(num3); float yawHalfRange2 = (flag ? 1.5f : 0.3f); float yawStep2 = 0.2f; EvaluateAndUpdate(tryPitch, yawHalfRange2, yawStep2, val2, dy, targetXZ, inp, 15f, 0.03f, 0f, ref bestScore, ref bestMiss, ref bestYaw, ref bestNorm, ref bestPitchDeg, ref bestDir, bestYaw); } } result2.Solved = bestMiss < Mathf.Max(3f, magnitude * 0.1f) && bestNorm >= 0.01f && bestNorm <= 1f; result2.YawDeg = bestYaw; result2.PitchDeg = bestPitchDeg; result2.NormPower = bestNorm; result2.Direction = bestDir; return result2; } private static void EvaluateAndUpdate(int tryPitch, float yawHalfRange, float yawStep, Vector3 baseForward, float dy, Vector2 targetXZ, Inputs inp, float minAngleDeg, float kAngle, float kAirtime, ref float bestScore, ref float bestMiss, ref float bestYaw, ref float bestNorm, ref float bestPitchDeg, ref Vector3 bestDir, float yawCenter = 0f) { //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_0023: 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) //IL_002a: 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_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: 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) //IL_00e6: 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_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) float pitchRad = (float)tryPitch * (MathF.PI / 180f); float num = yawCenter - yawHalfRange; float num2 = yawCenter + yawHalfRange; for (float num3 = num; num3 <= num2 + 0.0001f; num3 += yawStep) { Vector3 val = Quaternion.AngleAxis(num3, Vector3.up) * baseForward; PowerSearchResult powerSearchResult = SearchPower(val, pitchRad, dy, targetXZ, inp); if (powerSearchResult.found && !(powerSearchResult.norm > 1f)) { float num4 = Mathf.Max(0f, minAngleDeg - powerSearchResult.descentAngleDeg); float num5 = kAngle * num4 * num4; float num6 = kAirtime * powerSearchResult.airtimeSec; float num7 = 0.15f * Mathf.Max(0f, (float)tryPitch - 30f); float num8 = powerSearchResult.miss + num5 + num6 + num7; if (num8 < bestScore) { bestScore = num8; bestMiss = powerSearchResult.miss; bestYaw = num3; bestNorm = powerSearchResult.norm; bestPitchDeg = tryPitch; Vector3 val2 = Vector3.Cross(Vector3.up, val); Vector3 normalized = ((Vector3)(ref val2)).normalized; bestDir = Quaternion.AngleAxis((float)(-tryPitch), normalized) * val; } } } } private static PowerSearchResult SearchPower(Vector3 aim, float pitchRad, float dyTarget, Vector2 targetXZ, Inputs inp) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: 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_0044: 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_0053: 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_005b: 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_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_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_0248: Unknown result type (might be due to invalid IL or missing references) //IL_025d: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_026d: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Unknown result type (might be due to invalid IL or missing references) PowerSearchResult powerSearchResult = default(PowerSearchResult); powerSearchResult.found = false; PowerSearchResult result = powerSearchResult; float magnitude = ((Vector2)(ref targetXZ)).magnitude; float num = 0f; float num2 = 1f; float num3 = float.MaxValue; float num4 = 1f; Vector3 val = Vector3.Cross(Vector3.up, aim); Vector3 normalized = ((Vector3)(ref val)).normalized; Vector3 launchDir = Quaternion.AngleAxis((0f - pitchRad) * 57.29578f, normalized) * aim; bool flag = NativePhysics.IsAvailable; if (flag) { if (_nativeBuf == null) { _nativeBuf = new NativePhysics.Sample[301]; } float yawRad = Mathf.Atan2(aim.x, aim.z); if (!NativePhysics.TryQuery(inp.BallPos, yawRad, pitchRad, inp.MaxSpeed, inp.Gravity, inp.Drag, inp.DeltaTime, _nativeBuf)) { flag = false; } } for (int i = 0; i < 24; i++) { float num5 = (num + num2) * 0.5f; Vector2 val2 = Simulate(aim, pitchRad, num5 * inp.MaxSpeed, dyTarget, inp); if (float.IsNaN(val2.x)) { num = num5; continue; } Vector2 val4; if (flag) { int num6 = Mathf.Clamp(Mathf.RoundToInt(num5 * 300f), 0, 300); float distance = _nativeBuf[num6].Distance; if (distance > 0.01f) { Inputs inp2 = inp; inp2.Wind = Vector3.zero; Vector2 val3 = Simulate(aim, pitchRad, num5 * inp.MaxSpeed, 0f, inp2); if (!float.IsNaN(val3.x)) { float magnitude2 = ((Vector2)(ref val3)).magnitude; val4 = new Vector2(aim.x, aim.z); Vector2 normalized2 = ((Vector2)(ref val4)).normalized; float num7 = Vector2.Dot(val2, normalized2); Vector2 val5 = val2 - normalized2 * num7; float num8 = num7 - magnitude2 + distance; val2 = normalized2 * num8 + val5; } } } val4 = val2 - targetXZ; float magnitude3 = ((Vector2)(ref val4)).magnitude; if (magnitude3 < num3) { num3 = magnitude3; num4 = num5; } if (((Vector2)(ref val2)).magnitude < magnitude) { num = num5; } else { num2 = num5; } } if (num3 < float.MaxValue) { result.found = true; result.norm = num4; result.miss = num3; var (val6, airtimeSec) = SimulateLandingVelocityAndTime(launchDir, num4 * inp.MaxSpeed, dyTarget, inp); Vector2 val7 = default(Vector2); ((Vector2)(ref val7))..ctor(val6.x, val6.z); float magnitude4 = ((Vector2)(ref val7)).magnitude; float descentAngleDeg = Mathf.Atan2(0f - val6.y, Mathf.Max(0.01f, magnitude4)) * 57.29578f; result.landVxz = magnitude4; result.landVy = val6.y; result.descentAngleDeg = descentAngleDeg; result.airtimeSec = airtimeSec; } return result; } private static (Vector3 vel, float airtime) SimulateLandingVelocityAndTime(Vector3 launchDir, float speed, float dyTarget, Inputs inp) { //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_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_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_0048: 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_0053: 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_0145: 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_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_006e: 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_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0079: 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_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0095: 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_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: 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) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_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) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: 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_00f5: 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_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) Vector3 val = launchDir * speed; Vector3 val2 = Vector3.zero; Vector3 wind = inp.Wind; bool flag = ((Vector3)(ref wind)).sqrMagnitude > 0.01f; float num = Mathf.Max(0.001f, inp.DeltaTime); float num2 = Mathf.Max(0f, inp.Drag); Vector3 val3 = val2; for (int i = 0; i < 800; i++) { val3 = val2; val.y += inp.Gravity * num; Vector3 val7; if (flag) { Vector3 val4 = Vector3.Project(wind, val); Vector3 val5 = wind - val4; Vector3 val6 = val4 * inp.WindFactor + val5 * inp.CrossWindFactor; val7 = val - val6; } else { val7 = val; } float num3 = Mathf.Min(1f, num2 * ((Vector3)(ref val7)).sqrMagnitude * num); val -= val7 * num3; val2 += val * num; if (val.y <= 0f && val3.y >= dyTarget && val2.y <= dyTarget) { return (val, (float)(i + 1) * num); } if (val2.y < dyTarget - 200f && val.y < 0f) { break; } } return (val, 800f * num); } private static Vector2 Simulate(Vector3 aim, float pitchRad, float speed, float dyTarget, Inputs in