RUMBLE does not support other mod managers. If you want to use a manager, you must use the RUMBLE Mod Manager, a manager specifically designed for this game.
Decompiled source of RumbleFlightTrainer v1.0.5
Mods/RumbleFlightTrainer.dll
Decompiled 12 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text.Json; using HarmonyLib; using Il2CppInterop.Runtime.Attributes; using Il2CppInterop.Runtime.Injection; using Il2CppInterop.Runtime.InteropTypes; using Il2CppInterop.Runtime.InteropTypes.Arrays; using Il2CppRUMBLE.Managers; using Il2CppRUMBLE.MoveSystem; using Il2CppRUMBLE.Physics; using Il2CppRUMBLE.Players; using Il2CppRUMBLE.Players.Subsystems; using Il2CppRUMBLE.Utilities; using Il2CppSystem; using Il2CppTMPro; using MelonLoader; using MelonLoader.Preferences; using Microsoft.CodeAnalysis; using RumbleFlightTrainer; using UnityEngine; using UnityEngine.Events; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.Rendering; using UnityEngine.SceneManagement; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: MelonInfo(typeof(TrainerMod), "RumbleFlightTrainer", "1.0.5", "GloriousCandle119", null)] [assembly: MelonGame("Buckethead Entertainment", "RUMBLE")] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("RumbleFlightTrainer")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.5.0")] [assembly: AssemblyInformationalVersion("1.0.5+b49eabd7943aa688f0de4f94769efa8eb9f1756e")] [assembly: AssemblyProduct("RumbleFlightTrainer")] [assembly: AssemblyTitle("RumbleFlightTrainer")] [assembly: AssemblyVersion("1.0.5.0")] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } } namespace RumbleFlightTrainer { internal sealed class FlightHudView : IDisposable { private enum DrawOrder { Wireframe, NetPush, StructurePush, LossFace, LossRim, LiveFace, LiveRim, Text } private sealed record Arrow(LineRenderer Shaft, LineRenderer Head, LineRenderer? Badge); private sealed record Marker(GameObject Root, LineRenderer Rim, LineRenderer? Dot, LineRenderer Face, LineRenderer Span); private sealed record BoxWidget(Transform Root, LineRenderer[] Edges) { public HudBoxPreview? Shape { get; set; } public Material? Color { get; set; } } private sealed record PlayerWidget(Transform Root, LineRenderer Front, LineRenderer Side) { public float HalfSpan { get; set; } public float Radius { get; set; } public Material? Color { get; set; } } private sealed record MeshWidget(Transform Root) { public List<LineRenderer> Lines { get; } = new List<LineRenderer>(); public HudMeshPreview? Shape { get; set; } public Material? Color { get; set; } } private const float FullArrowImpulse = 40f; private const float MinimumArrowImpulse = 0.4f; private const int LiveBranchLimit = 2; private const int LossDashes = 6; private const float InactiveWireframeBrightness = 0.5f; private static readonly Color[] StructureColors = (Color[])(object)new Color[7] { new Color(1f, 0.72f, 0.38f), new Color(0.48f, 0.77f, 1f), new Color(1f, 0.58f, 0.81f), new Color(0.87f, 0.95f, 0.5f), new Color(0.79f, 0.67f, 1f), new Color(1f, 0.61f, 0.55f), new Color(0.47f, 0.95f, 0.92f) }; private readonly GameObject root = new GameObject("Flight Trainer HUD"); private readonly List<Material> materials = new List<Material>(); private readonly Transform anchor; private readonly Material edging; private readonly Material hitbox; private readonly Material lastHitbox; private readonly Material[] structureMaterials; private readonly Material[] dimStructureMaterials; private readonly Dictionary<StructureKey, int> structureColors = new Dictionary<StructureKey, int>(); private readonly HashSet<StructureKey> displayedStructures = new HashSet<StructureKey>(); private readonly Arrow totalArrow; private readonly Arrow[] branches; private readonly List<Marker> liveMarkers = new List<Marker>(); private readonly List<Marker> lossMarkers = new List<Marker>(); private readonly TextMeshPro status; private Quaternion viewYaw = Quaternion.identity; private bool hasViewYaw; private const int CapsuleCapSteps = 16; private static readonly (int From, int To)[] BoxEdges = new(int, int)[12] { (0, 1), (2, 3), (4, 5), (6, 7), (0, 2), (1, 3), (4, 6), (5, 7), (0, 4), (1, 5), (2, 6), (3, 7) }; private readonly List<BoxWidget> boxes = new List<BoxWidget>(); private readonly List<MeshWidget> meshes = new List<MeshWidget>(); private readonly List<PlayerWidget> playerColliders = new List<PlayerWidget>(); private readonly HashSet<int> drawnPlayerColliders = new HashSet<int>(); private readonly Dictionary<int, HudPairGeometry> retainedPlayerColliders = new Dictionary<int, HudPairGeometry>(); private readonly HashSet<int> drawnStructureColliders = new HashSet<int>(); public FlightHudView() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_012a: 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_0175: 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_0292: Unknown result type (might be due to invalid IL or missing references) //IL_029c: Unknown result type (might be due to invalid IL or missing references) //IL_0342: Unknown result type (might be due to invalid IL or missing references) //IL_0349: Expected O, but got Unknown //IL_02cf: Unknown result type (might be due to invalid IL or missing references) //IL_02e5: Unknown result type (might be due to invalid IL or missing references) FlightHudView flightHudView = this; try { anchor = root.transform; root.SetActive(false); Shader shader = Shader.Find("Hidden/Internal-Colored"); if ((Object)(object)shader == (Object)null) { throw new InvalidOperationException("The HUD line overlay shader was not available."); } edging = ColorMaterial(shader, new Color(0.035f, 0.08f, 0.09f)); hitbox = ColorMaterial(shader, new Color(0.71f, 0.84f, 0.84f)); lastHitbox = ColorMaterial(shader, new Color(0.34f, 0.46f, 0.46f)); Material material = ColorMaterial(shader, new Color(0.62f, 1f, 0.81f)); structureMaterials = StructureColors.Select((Color color) => flightHudView.ColorMaterial(shader, color)).ToArray(); dimStructureMaterials = StructureColors.Select((Color color) => flightHudView.ColorMaterial(shader, Color.Lerp(Color.black, color, 0.5f))).ToArray(); totalArrow = CreateArrow(anchor, "Net push", material, 0.0045f, branch: false); Transform transform = Child(anchor, "Structure pushes").transform; branches = new Arrow[2]; for (int num = 0; num < branches.Length; num++) { branches[num] = CreateArrow(transform, $"Branch {num + 1}", structureMaterials[0], 0.002f, branch: true); } GameObject val = Child(anchor, "Contact status"); val.transform.localPosition = new Vector3(0f, -0.195f, -0.003f); val.transform.localScale = Vector3.one * 0.024f; status = val.AddComponent<TextMeshPro>(); RectTransform rectTransform = ((TMP_Text)status).rectTransform; if (rectTransform != null) { rectTransform.sizeDelta = new Vector2(32f, 8f); rectTransform.pivot = new Vector2(0.5f, 1f); } ((TMP_Text)status).fontSize = 8.8f; ((TMP_Text)status).alignment = (TextAlignmentOptions)258; ((TMP_Text)status).richText = false; ((TMP_Text)status).text = string.Empty; root.SetActive(true); Material val2 = new Material(((TMP_Text)status).fontSharedMaterial); materials.Add(val2); Shader val3 = Shader.Find("TextMeshPro/Distance Field Overlay"); if ((Object)(object)val3 != (Object)null) { val2.shader = val3; } else { val2.SetInt("unity_GUIZTestMode", 8); } val2.renderQueue = 4000; ((TMP_Text)status).fontSharedMaterial = val2; MeshRenderer component = val.GetComponent<MeshRenderer>(); ((Renderer)component).sortingOrder = 7; ((Renderer)component).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)component).receiveShadows = false; root.SetActive(false); } catch { Dispose(); throw; } } public void Hide() { root.SetActive(false); } public void Draw(Transform headset, FlightHudFrame frame, HudNearbyCollider? playerReference, Vector3 offset) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0009: 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_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_004b: 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_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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_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_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_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: 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_00d0: 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_00e1: 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_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_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) //IL_0104: 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_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0116: 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_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0273: 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_023b: Unknown result type (might be due to invalid IL or missing references) //IL_0243: 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_021e: Unknown result type (might be due to invalid IL or missing references) //IL_02e2: Unknown result type (might be due to invalid IL or missing references) //IL_02cc: Unknown result type (might be due to invalid IL or missing references) Vector3 forward = headset.forward; Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(forward.x, 0f, forward.z); if (((Vector3)(ref val)).sqrMagnitude > 0.0025f || !hasViewYaw) { if (((Vector3)(ref val)).sqrMagnitude <= 0.0025f) { Vector3 right = headset.right; val = Vector3.Cross(new Vector3(right.x, 0f, right.z), Vector3.up); } if (((Vector3)(ref val)).sqrMagnitude > 0.0025f) { viewYaw = Quaternion.LookRotation(val, Vector3.up); } hasViewYaw = true; } Vector3 val2 = headset.position + forward * (0.84f + offset.Z) + headset.up * (offset.Y - 0.23f) + headset.right * offset.X; anchor.SetPositionAndRotation(val2, viewYaw); Quaternion val3 = Quaternion.Inverse(viewYaw); Quaternion bodyToView = val3 * ToUnity(frame.BodyYaw); DrawPush(totalArrow, val3 * ToUnity(frame.PushWorld)); AssignStructureColors(frame.Structures); HudStructureFrame[] array = (from item in frame.Structures where item.Touching orderby item.HasImpulse descending, item.PushWorld.LengthSquared() descending, item.Key.PoolGeneration, item.Key.InstanceId select item).Take(2).ToArray(); for (int num = 0; num < branches.Length; num++) { if (num >= array.Length) { DrawPush(branches[num], Vector3.zero); continue; } HudStructureFrame hudStructureFrame = array[num]; DrawPush(branches[num], val3 * ToUnity(hudStructureFrame.PushWorld), StructureMaterial(hudStructureFrame.Key)); } bool missingLocation = DrawContactGeometry(frame, val3, bodyToView, playerReference); string outcome = frame.Outcome; string text = Status(frame, outcome, missingLocation); if (((TMP_Text)status).text != text) { ((TMP_Text)status).text = text; } ((Graphic)status).color = ((outcome != null) ? new Color(1f, 0.82f, 0.57f) : new Color(0.9f, 0.97f, 0.96f)); if (!root.activeSelf) { root.SetActive(true); } } private void AssignStructureColors(HudStructureFrame[] structures) { displayedStructures.Clear(); HudStructureFrame[] array = structures; foreach (HudStructureFrame hudStructureFrame in array) { displayedStructures.Add(hudStructureFrame.Key); } int i = StructureColors.Length; Span<int> span = stackalloc int[i]; span.Clear(); foreach (KeyValuePair<StructureKey, int> structureColor in structureColors) { structureColor.Deconstruct(out var key, out i); StructureKey structureKey = key; int index = i; if (displayedStructures.Contains(structureKey)) { span[index]++; } else { structureColors.Remove(structureKey); } } array = structures; foreach (HudStructureFrame hudStructureFrame2 in array) { if (structureColors.ContainsKey(hudStructureFrame2.Key)) { continue; } int num = (int)((uint)hudStructureFrame2.Key.PoolGeneration % StructureColors.Length); for (int j = 0; j < span.Length; j++) { if (span[num] == 0) { break; } if (span[j] < span[num]) { num = j; } } structureColors.Add(hudStructureFrame2.Key, num); span[num]++; } } private Material StructureMaterial(StructureKey key) { return structureMaterials[structureColors[key]]; } private static Arrow CreateArrow(Transform parent, string name, Material material, float width, bool branch) { //IL_0027: 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_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) Transform transform = Child(parent, name).transform; DrawOrder order = ((!branch) ? DrawOrder.NetPush : DrawOrder.StructurePush); return new Arrow(Line(transform, "Shaft", material, width, order, Vector3.zero, Vector3.up), Line(transform, "Head", material, width, order, Vector3.left, Vector3.up, Vector3.right), branch ? Line(transform, "Structure circle", material, width, order, Arc(0.007f, 24)) : null); } private static void DrawPush(Arrow arrow, Vector3 impulse, Material? color = null) { //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_006e: 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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0078: 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_0083: 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_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_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: 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_00c6: 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_00e1: 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_00f8: 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_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_011b: 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_011f: 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_0161: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) float magnitude = ((Vector3)(ref impulse)).magnitude; bool flag = float.IsFinite(magnitude) && magnitude >= 0.4f; ((Renderer)arrow.Shaft).enabled = flag; ((Renderer)arrow.Head).enabled = flag; LineRenderer badge = arrow.Badge; if (badge != null) { ((Renderer)badge).enabled = flag; } if (!flag) { return; } Vector3 val = impulse / magnitude; float num = 0.019f + 0.077f * Mathf.Clamp01(magnitude / 40f); Vector3 val2 = val * num; Vector3 val3 = Vector3.Cross(val, Vector3.forward); if (((Vector3)(ref val3)).sqrMagnitude < 0.03f) { val3 = Vector3.Cross(val, Vector3.up); } bool flag2 = color != null; val3 = ((Vector3)(ref val3)).normalized * (flag2 ? 0.006f : 0.0095f); Vector3 val4 = val2 - val * (flag2 ? 0.012f : 0.016f); arrow.Shaft.SetPosition(1, val2); arrow.Head.SetPosition(0, val4 + val3); arrow.Head.SetPosition(1, val2); arrow.Head.SetPosition(2, val4 - val3); if (color != null) { LineRenderer badge2 = arrow.Badge; if (badge2 != null) { ((Renderer)arrow.Shaft).sharedMaterial = color; ((Renderer)arrow.Head).sharedMaterial = color; ((Renderer)badge2).sharedMaterial = color; ((Component)badge2).transform.localPosition = val2 + Vector3.back * 0.003f; } } } private Marker GetMarker(List<Marker> pool, int index, bool lost) { //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_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_0111: 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_0141: 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_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) if (index < pool.Count) { return pool[index]; } GameObject val = Child(anchor, lost ? "Lost contact" : "Live contact"); float num = (lost ? 0.017f : 0.01f); int segments = (lost ? 72 : 24); Vector3[] points = Arc(num, segments); DrawOrder order = (lost ? DrawOrder.LossFace : DrawOrder.LiveFace); DrawOrder order2 = (lost ? DrawOrder.LossRim : DrawOrder.LiveRim); LineRenderer val2 = Line(val.transform, "Dark edge", edging, 0.005f, order, points); ((Component)val2).transform.localPosition = Vector3.forward * 0.001f; Material material = structureMaterials[0]; LineRenderer val3 = Line(val.transform, "Outline", material, 0.0024f, order2, points); LineRenderer val4 = Line(val.transform, "Contact face", material, 0.0018f, order, Arc(num + 0.006f, segments)); LineRenderer span = Line(val.transform, "Contact span", material, 0.0022f, order, Vector3.zero, Vector3.one); if (!lost) { LineRenderer dot = Line(val.transform, "Measured contact", material, 0.009f, order2, Vector3.left * 0.001f, Vector3.right * 0.001f); pool.Add(new Marker(val, val3, dot, val4, span)); } else { AnimationCurve widthCurve = DashWidth(); LineRenderer[] array = (LineRenderer[])(object)new LineRenderer[3] { val2, val3, val4 }; foreach (LineRenderer obj in array) { float startWidth = obj.startWidth; obj.widthCurve = widthCurve; obj.widthMultiplier = startWidth; } pool.Add(new Marker(val, val3, null, val4, span)); } return pool[index]; } private static void DrawMarker(Marker marker, HudContactPatch patch, Vector3 position, Quaternion directionToHud, Material color, bool measured) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0081: 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_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_0092: Unknown result type (might be due to invalid IL or missing references) marker.Root.transform.localPosition = position; ((Renderer)marker.Rim).sharedMaterial = color; ((Renderer)marker.Face).sharedMaterial = color; LineRenderer dot = marker.Dot; if (dot != null) { ((Renderer)dot).sharedMaterial = color; ((Renderer)dot).enabled = measured; } ((Renderer)marker.Face).enabled = patch.BodyNormal.HasValue; Vector3? bodyNormal = patch.BodyNormal; if (bodyNormal.HasValue) { Vector3 valueOrDefault = bodyNormal.GetValueOrDefault(); ((Component)marker.Face).transform.localRotation = Quaternion.FromToRotation(Vector3.forward, directionToHud * ToUnity(valueOrDefault)); } marker.Root.SetActive(true); } private static void HideUnused(List<Marker> pool, int used) { for (int i = used; i < pool.Count; i++) { pool[i].Root.SetActive(false); } } private static string Status(FlightHudFrame frame, string? outcome, bool missingLocation) { List<string> list = new List<string>(); if (!frame.ObserverAvailable) { list.Add("Contact data unavailable"); } if (frame.TouchingCount > 1) { string text = $"{frame.TouchingCount} touching · {frame.MeasuredCount} measured"; if (frame.TouchingCount > 2) { text += $" · +{frame.TouchingCount - 2} more"; } list.Add(text); } if (frame.PartialImpulse) { list.Add((frame.MeasuredCount == 0) ? "Impulse unavailable" : "Partial impulse"); } if (missingLocation) { list.Add("Contact location unavailable"); } if (outcome != null) { list.Add(outcome); } return string.Join("\n", list); } private Material ColorMaterial(Shader shader, Color color) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_0019: Unknown result type (might be due to invalid IL or missing references) Material val = new Material(shader); materials.Add(val); val.SetColor("_Color", color); val.SetInt("_Cull", 0); val.SetInt("_ZTest", 8); val.SetInt("_ZWrite", 0); val.renderQueue = 4000; return val; } private static LineRenderer Line(Transform parent, string name, Material material, float width, DrawOrder order, params Vector3[] points) { //IL_0059: Unknown result type (might be due to invalid IL or missing references) LineRenderer val = Child(parent, name).AddComponent<LineRenderer>(); val.useWorldSpace = false; ((Renderer)val).sharedMaterial = material; ((Renderer)val).sortingOrder = (int)order; ((Renderer)val).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)val).receiveShadows = false; val.startWidth = width; val.endWidth = width; val.numCapVertices = 5; val.positionCount = points.Length; for (int i = 0; i < points.Length; i++) { val.SetPosition(i, points[i]); } return val; } private static GameObject Child(Transform parent, string name) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Expected O, but got Unknown GameObject val = new GameObject(name); val.transform.SetParent(parent, false); return val; } private static Vector3[] Arc(float radius, int segments) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) Vector3[] array = (Vector3[])(object)new Vector3[segments + 1]; for (int i = 0; i <= segments; i++) { float num = (float)i * (2f * Mathf.PI / (float)segments); array[i] = new Vector3(radius * Mathf.Cos(num), radius * Mathf.Sin(num), 0f); } return array; } private static AnimationCurve DashWidth(int dashCount = 6) { //IL_0020: 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_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Expected O, but got Unknown //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_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0084: 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) Keyframe[] array = (Keyframe[])(object)new Keyframe[dashCount * 4 + 1]; for (int i = 0; i <= dashCount; i++) { array[i * 4] = new Keyframe((float)i / (float)dashCount, 1f); if (i != dashCount) { array[i * 4 + 1] = new Keyframe(((float)i + 0.55f) / (float)dashCount, 1f); array[i * 4 + 2] = new Keyframe(((float)i + 0.59f) / (float)dashCount, 0f); array[i * 4 + 3] = new Keyframe(((float)i + 0.96f) / (float)dashCount, 0f); } } return new AnimationCurve(array); } private static Vector3 ToUnity(Vector3 v) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) return new Vector3(v.X, v.Y, v.Z); } private static Quaternion ToUnity(Quaternion q) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) return new Quaternion(q.X, q.Y, q.Z, q.W); } public void Dispose() { if ((Object)(object)root != (Object)null) { root.SetActive(false); Object.Destroy((Object)(object)root); } foreach (Material material in materials) { if ((Object)(object)material != (Object)null) { Object.Destroy((Object)(object)material); } } materials.Clear(); } private bool DrawContactGeometry(FlightHudFrame frame, Quaternion worldToView, Quaternion bodyToView, HudNearbyCollider? playerReference) { //IL_040b: Unknown result type (might be due to invalid IL or missing references) //IL_040c: Unknown result type (might be due to invalid IL or missing references) //IL_0471: 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_023c: Unknown result type (might be due to invalid IL or missing references) //IL_025b: 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_02e4: Unknown result type (might be due to invalid IL or missing references) //IL_02ef: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: 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) int num = 0; int num2 = 0; int num3 = 0; int count = 0; int count2 = 0; bool flag = false; drawnPlayerColliders.Clear(); retainedPlayerColliders.Clear(); HudStructureFrame[] structures = frame.Structures; int i; for (i = 0; i < structures.Length; i++) { HudStructureFrame hudStructureFrame = structures[i]; int num4 = structureColors[hudStructureFrame.Key]; Material val = structureMaterials[num4]; Material color = (Material)(hudStructureFrame.Touching ? ((object)val) : ((object)dimStructureMaterials[num4])); drawnStructureColliders.Clear(); HudPairFrame[] activePairs = hudStructureFrame.ActivePairs; for (int j = 0; j < activePairs.Length; j++) { HudPairFrame hudPairFrame = activePairs[j]; HudPairGeometry geometry = hudPairFrame.Geometry; HudContactPlacement hudContactPlacement = ((geometry.Tick == frame.GeometryTick) ? geometry.Placement : null); HudPlayerCollider hudPlayerCollider = hudContactPlacement?.Player; if ((object)hudPlayerCollider != null && drawnPlayerColliders.Add(geometry.Pair.PlayerColliderId)) { DrawPlayerCollider(num3++, hudPlayerCollider, hudContactPlacement, worldToView, hitbox); } HudBoxPreview hudBoxPreview = hudContactPlacement?.Box; if ((object)hudBoxPreview != null && drawnStructureColliders.Add(geometry.Pair.OtherColliderId)) { DrawBox(num++, hudBoxPreview, hudContactPlacement, color, worldToView); } HudMeshPreview hudMeshPreview = hudContactPlacement?.Mesh; if ((object)hudMeshPreview != null && drawnStructureColliders.Add(geometry.Pair.OtherColliderId)) { DrawMesh(num2++, hudMeshPreview, hudContactPlacement, color, worldToView); } flag |= DrawContactMarkers(geometry, hudContactPlacement, worldToView, val, hudPairFrame.HasImpulse, lost: false, liveMarkers, ref count); } IReadOnlyList<HudNearbyCollider> nearbyGeometry = hudStructureFrame.NearbyGeometry; if (nearbyGeometry != null) { foreach (HudNearbyCollider item2 in nearbyGeometry) { if (drawnStructureColliders.Add(item2.ColliderId)) { HudContactPlacement placement = item2.Placement; HudBoxPreview box = placement.Box; if ((object)box != null) { DrawBox(num++, box, placement, color, worldToView); } HudMeshPreview mesh = placement.Mesh; if ((object)mesh != null) { DrawMesh(num2++, mesh, placement, color, worldToView); } } } } HudLossMark[] losses = hudStructureFrame.Losses; for (int j = 0; j < losses.Length; j++) { foreach (HudPairGeometry item3 in losses[j].Contacts.OrderByDescending((HudPairGeometry contact) => contact.Tick)) { HudContactPlacement placement2 = item3.Placement; if ((object)placement2 != null) { Quaternion worldToHud = LossRotation(placement2, bodyToView); int num5 = count2; DrawContactMarkers(item3, placement2, worldToHud, val, measured: false, lost: true, lossMarkers, ref count2); int playerColliderId = item3.Pair.PlayerColliderId; if (count2 > num5 && (!retainedPlayerColliders.TryGetValue(playerColliderId, out HudPairGeometry value) || item3.Tick > value.Tick)) { retainedPlayerColliders[playerColliderId] = item3; } } } } } foreach (KeyValuePair<int, HudPairGeometry> retainedPlayerCollider in retainedPlayerColliders) { retainedPlayerCollider.Deconstruct(out i, out var value2); int item = i; HudPairGeometry hudPairGeometry = value2; if (!drawnPlayerColliders.Add(item)) { continue; } HudContactPlacement placement3 = hudPairGeometry.Placement; if ((object)placement3 != null) { HudPlayerCollider player = placement3.Player; if ((object)player != null) { DrawPlayerCollider(num3++, player, placement3, LossRotation(placement3, bodyToView), lastHitbox); } } } if ((object)playerReference != null) { HudContactPlacement placement4 = playerReference.Placement; if ((object)placement4 != null) { HudPlayerCollider player2 = placement4.Player; if ((object)player2 != null && drawnPlayerColliders.Add(playerReference.ColliderId)) { DrawPlayerCollider(num3++, player2, placement4, worldToView, hitbox); } } } for (int num6 = num; num6 < boxes.Count; num6++) { ((Component)boxes[num6].Root).gameObject.SetActive(false); } for (int num7 = num2; num7 < meshes.Count; num7++) { ((Component)meshes[num7].Root).gameObject.SetActive(false); } for (int num8 = num3; num8 < playerColliders.Count; num8++) { ((Component)playerColliders[num8].Root).gameObject.SetActive(false); } HideUnused(liveMarkers, count); HideUnused(lossMarkers, count2); return flag; } private static Quaternion LossRotation(HudContactPlacement placement, Quaternion bodyToView) { //IL_0000: 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_0019: Unknown result type (might be due to invalid IL or missing references) return bodyToView * Quaternion.Inverse(ToUnity(placement.Origin.Yaw)); } private bool DrawContactMarkers(HudPairGeometry geometry, HudContactPlacement? placement, Quaternion worldToHud, Material color, bool measured, bool lost, List<Marker> pool, ref int count) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: 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_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_011d: 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_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0130: 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_0144: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) if ((object)placement?.Player == null) { return true; } Quaternion directionToHud = worldToHud * ToUnity(placement.Origin.Yaw); bool result = geometry.Patches.Length == 0; HudContactPatch[] patches = geometry.Patches; foreach (HudContactPatch hudContactPatch in patches) { Vector3? vector = placement.MarkerPoint(hudContactPatch); if (vector.HasValue) { Vector3 valueOrDefault = vector.GetValueOrDefault(); Vector3 val = worldToHud * ToUnity(placement.Offset(valueOrDefault)); Marker marker = GetMarker(pool, count++, lost); DrawMarker(marker, hudContactPatch, val, directionToHud, color, measured); ((Renderer)marker.Span).enabled = hudContactPatch.Points.Length > 1; if (((Renderer)marker.Span).enabled) { var (vector2, vector3) = PatchSpan(hudContactPatch.Points); ((Renderer)marker.Span).enabled = vector2 != vector3; ((Renderer)marker.Span).sharedMaterial = color; marker.Span.SetPosition(0, worldToHud * ToUnity(placement.Offset(vector2)) - val); marker.Span.SetPosition(1, worldToHud * ToUnity(placement.Offset(vector3)) - val); } } else { result = true; } } return result; } private void DrawBox(int index, HudBoxPreview box, HudContactPlacement placement, Material color, Quaternion rotation) { //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: 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_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) if (index == boxes.Count) { Transform transform = Child(anchor, "Structure box").transform; LineRenderer[] array = (LineRenderer[])(object)new LineRenderer[BoxEdges.Length]; for (int i = 0; i < array.Length; i++) { LineRenderer val = Line(transform, "Box edge", color, 0.0016f, DrawOrder.Wireframe); val.numCapVertices = 0; val.positionCount = 2; array[i] = val; } boxes.Add(new BoxWidget(transform, array)); } BoxWidget boxWidget = boxes[index]; boxWidget.Root.localPosition = rotation * ToUnity(placement.Offset(box.Center)); boxWidget.Root.localRotation = rotation; if (!(boxWidget.Shape?.Frame != box.Frame)) { Vector3? vector = boxWidget.Shape?.HalfSize; Vector3 halfSize = box.HalfSize; if (vector.HasValue && !(vector.GetValueOrDefault() != halfSize) && !((Object)(object)boxWidget.Color != (Object)(object)color)) { goto IL_020d; } } boxWidget.Shape = box; boxWidget.Color = color; for (int j = 0; j < BoxEdges.Length; j++) { (int From, int To) tuple = BoxEdges[j]; int item = tuple.From; int item2 = tuple.To; LineRenderer obj = boxWidget.Edges[j]; ((Renderer)obj).sharedMaterial = color; obj.SetPosition(0, ToUnity(box.Corners[item] - box.Center) * 0.085f); obj.SetPosition(1, ToUnity(box.Corners[item2] - box.Center) * 0.085f); } goto IL_020d; IL_020d: ((Component)boxWidget.Root).gameObject.SetActive(true); } private void DrawPlayerCollider(int index, HudPlayerCollider player, HudContactPlacement placement, Quaternion rotation, Material color) { //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: 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_00bf: 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_00c9: 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_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Unknown result type (might be due to invalid IL or missing references) if (index == playerColliders.Count) { Transform transform = Child(anchor, "Player collider").transform; LineRenderer val = Line(transform, "Collider profile", color, 0.0017f, DrawOrder.Wireframe); LineRenderer val2 = Line(transform, "Collider depth", color, 0.0011f, DrawOrder.Wireframe); int positionCount = (val2.positionCount = 35); val.positionCount = positionCount; playerColliders.Add(new PlayerWidget(transform, val, val2)); } PlayerWidget playerWidget = playerColliders[index]; playerWidget.Root.localPosition = rotation * ToUnity(placement.Offset(player.Center)); playerWidget.Root.localRotation = rotation * Quaternion.FromToRotation(Vector3.up, ToUnity(player.Axis)); if ((Object)(object)playerWidget.Color != (Object)(object)color) { playerWidget.Color = color; ((Renderer)playerWidget.Front).sharedMaterial = color; ((Renderer)playerWidget.Side).sharedMaterial = color; } if (playerWidget.HalfSpan != player.HalfSpan || playerWidget.Radius != player.Radius) { playerWidget.HalfSpan = player.HalfSpan; playerWidget.Radius = player.Radius; float num2 = player.HalfSpan * 0.085f; float num3 = player.Radius * 0.085f; for (int i = 0; i <= 16; i++) { float num4 = (float)i * (Mathf.PI / 16f); float num5 = num3 * Mathf.Cos(num4); float num6 = num2 + num3 * Mathf.Sin(num4); int num7 = i + 16 + 1; playerWidget.Front.SetPosition(i, new Vector3(num5, num6, 0f)); playerWidget.Front.SetPosition(num7, new Vector3(0f - num5, 0f - num6, 0f)); playerWidget.Side.SetPosition(i, new Vector3(0f, num6, num5)); playerWidget.Side.SetPosition(num7, new Vector3(0f, 0f - num6, 0f - num5)); } int num8 = playerWidget.Front.positionCount - 1; playerWidget.Front.SetPosition(num8, new Vector3(num3, num2, 0f)); playerWidget.Side.SetPosition(num8, new Vector3(0f, num2, num3)); } ((Component)playerWidget.Root).gameObject.SetActive(true); } private void DrawMesh(int index, HudMeshPreview mesh, HudContactPlacement placement, Material color, Quaternion rotation) { //IL_004e: 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_0076: 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_01f7: Unknown result type (might be due to invalid IL or missing references) //IL_0232: Unknown result type (might be due to invalid IL or missing references) if (index == meshes.Count) { meshes.Add(new MeshWidget(Child(anchor, "Structure mesh").transform)); } MeshWidget meshWidget = meshes[index]; meshWidget.Root.localPosition = rotation * ToUnity(placement.Offset(mesh.Center)); meshWidget.Root.localRotation = rotation; HudColliderFrame? hudColliderFrame = meshWidget.Shape?.Offsets; HudColliderFrame offsets = mesh.Offsets; if (!hudColliderFrame.HasValue || hudColliderFrame.GetValueOrDefault() != offsets || meshWidget.Shape?.Edges != mesh.Edges || meshWidget.Shape?.Sections != mesh.Sections || (Object)(object)meshWidget.Color != (Object)(object)color) { meshWidget.Shape = mesh; meshWidget.Color = color; MeshEdge[]? edges = mesh.Edges; int num = ((edges != null) ? edges.Length : mesh.Sections.Length); for (int i = 0; i < num; i++) { if (i == meshWidget.Lines.Count) { LineRenderer val = Line(meshWidget.Root, "Collider outline", color, 0.0016f, DrawOrder.Wireframe); val.numCapVertices = 0; meshWidget.Lines.Add(val); } LineRenderer val2 = meshWidget.Lines[i]; ((Renderer)val2).sharedMaterial = color; MeshEdge[] edges2 = mesh.Edges; if (edges2 != null) { val2.positionCount = 2; val2.SetPosition(0, Point(edges2[i].Start)); val2.SetPosition(1, Point(edges2[i].End)); } else { Vec3[] array = mesh.Sections[i]; val2.positionCount = array.Length; for (int j = 0; j < array.Length; j++) { val2.SetPosition(j, Point(array[j])); } } ((Renderer)val2).enabled = true; } for (int k = num; k < meshWidget.Lines.Count; k++) { ((Renderer)meshWidget.Lines[k]).enabled = false; } } ((Component)meshWidget.Root).gameObject.SetActive(true); Vector3 Point(Vec3 local) { //IL_0019: 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) return ToUnity(mesh.Offsets.Point(FlightContactPatches.Vector(local))) * 0.085f; } } private static (Vector3 Start, Vector3 End) PatchSpan(ContactGeometry[] points) { Vector3 vector = FlightContactPatches.Vector(points[0].PointWorld); (Vector3, Vector3) result = (vector, vector); float num = 0f; for (int i = 0; i < points.Length; i++) { for (int j = i + 1; j < points.Length; j++) { Vector3 vector2 = FlightContactPatches.Vector(points[i].PointWorld); Vector3 vector3 = FlightContactPatches.Vector(points[j].PointWorld); float num2 = Vector3.DistanceSquared(vector2, vector3); if (num2 > num) { result = (vector2, vector3); num = num2; } } } return result; } } internal static class FlightBakedWireframes { private sealed record Wireframe(int FormatVersion, string GameVersion, string MeshName, string CookingOptions, MeshLocalBounds Bounds, Vec3 Scale, MeshEdge[] Edges); public const int MaxEdges = 96; private static readonly JsonSerializerOptions Json = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; private static readonly Lazy<Dictionary<string, Wireframe>> Assets = new Lazy<Dictionary<string, Wireframe>>(Load); public static bool HasBakedOutline(string? meshName) { switch (meshName) { case "LargeRock": case "SmallRock": case "Ball": case "Structure_Ball": case "Structures_Ball": case "Strucutre_SmallRock": case "Structure_Boulder": return true; default: return false; } } public static MeshEdge[]? Match(ColliderShape shape, string gameVersion, Vec3 scale) { if ((object)shape != null && shape.Kind == "mesh" && (shape.Convex ?? false)) { string meshName = shape.MeshName; if (meshName != null) { MeshLocalBounds? meshBounds = shape.MeshBounds; if (meshBounds.HasValue) { MeshLocalBounds valueOrDefault = meshBounds.GetValueOrDefault(); if (Assets.Value.TryGetValue(meshName, out Wireframe value) && !(value.GameVersion != gameVersion) && !(value.CookingOptions != shape.CookingOptions) && Near(value.Bounds.Center, valueOrDefault.Center) && Near(value.Bounds.Size, valueOrDefault.Size) && Near(value.Scale, scale)) { return value.Edges; } } } } return null; } private static Dictionary<string, Wireframe> Load() { Dictionary<string, Wireframe> dictionary = new Dictionary<string, Wireframe>(StringComparer.Ordinal); Assembly executingAssembly = Assembly.GetExecutingAssembly(); string[] array = new string[3] { "Ball", "SmallRock", "LargeRock" }; foreach (string text in array) { using Stream stream = executingAssembly.GetManifestResourceStream("RumbleFlightTrainer.Wireframes." + text + ".json"); if (stream == null) { continue; } Wireframe wireframe = JsonSerializer.Deserialize<Wireframe>(stream, Json); if ((object)wireframe == null || wireframe.FormatVersion != 1) { continue; } MeshEdge[] edges = wireframe.Edges; if (edges != null) { int num = edges.Length; if (num >= 6 && num <= 96) { dictionary.Add(wireframe.MeshName, wireframe); } } } return dictionary; } private static bool Near(Vec3 left, Vec3 right) { if (MathF.Abs(left.X - right.X) <= 0.0001f && MathF.Abs(left.Y - right.Y) <= 0.0001f) { return MathF.Abs(left.Z - right.Z) <= 0.0001f; } return false; } } internal sealed record HudBoxPreview(long? GeometryTick, Vector3 Center, Vector3[] Corners, Vector3 HalfSize, HudColliderFrame Frame, Matrix4x4 WorldToBox) { public bool Contains(ContactGeometry point) { return SurfaceDistance(FlightContactPatches.Vector(point.PointWorld)) <= 0.02f + MathF.Abs(point.Separation); } public float SurfaceDistance(Vector3 worldPoint) { Vector3 vector = worldPoint - Center; Vector3 vector2 = Vector3.Transform(vector, WorldToBox); Vector3 vector3 = Vector3.Clamp(vector2, -HalfSize, HalfSize); if (vector3 != vector2) { return Vector3.Distance(vector, Frame.Point(vector3)); } Vector3 vector4 = HalfSize - Vector3.Abs(vector2); return MathF.Min(vector4.X * Frame.X.Length(), MathF.Min(vector4.Y * Frame.Y.Length(), vector4.Z * Frame.Z.Length())); } } internal static class FlightBoxPreview { public const float FaceToleranceMetres = 0.02f; public static HudBoxPreview? Build(long? geometryTick, ColliderShape shape, HudColliderFrame box) { if ((object)shape != null && shape.Kind == "box") { Vec3? center = shape.Center; if (center.HasValue) { Vec3 valueOrDefault = center.GetValueOrDefault(); Vec3? size = shape.Size; if (size.HasValue) { Vec3 valueOrDefault2 = size.GetValueOrDefault(); Vector3 vector = FlightContactPatches.Vector(valueOrDefault2) * 0.5f; if (!FlightContactPatches.IsFinite(vector) || vector.X <= 0f || vector.Y <= 0f || vector.Z <= 0f || !FlightContactPatches.IsFinite(FlightContactPatches.Vector(valueOrDefault))) { return null; } Vector3 vector2 = box.Point(FlightContactPatches.Vector(valueOrDefault)); HudColliderFrame hudColliderFrame = box with { Origin = Vector3.Zero }; if (!FlightContactPatches.IsFinite(vector2) || !TryInverse(hudColliderFrame, out var inverse)) { return null; } Vector3[] array = new Vector3[8]; for (int i = 0; i < array.Length; i++) { Vector3 local = new Vector3(((i & 1) == 0) ? (0f - vector.X) : vector.X, ((i & 2) == 0) ? (0f - vector.Y) : vector.Y, ((i & 4) == 0) ? (0f - vector.Z) : vector.Z); array[i] = vector2 + hudColliderFrame.Point(local); } return new HudBoxPreview(geometryTick, vector2, array, vector, hudColliderFrame, inverse); } } } return null; } private static bool TryInverse(HudColliderFrame box, out Matrix4x4 inverse) { inverse = default(Matrix4x4); HudColliderFrame hudColliderFrame = box; var (_, value, value2, value3) = (HudColliderFrame)(ref hudColliderFrame); if (!FlightContactPatches.IsFinite(value) || !FlightContactPatches.IsFinite(value2) || !FlightContactPatches.IsFinite(value3)) { return false; } Vector3 vector5 = Vector3.Normalize(value); Vector3 vector6 = Vector3.Normalize(value2); Vector3 vector7 = Vector3.Normalize(value3); if (MathF.Abs(Vector3.Dot(vector5, vector6)) <= 0.001f && MathF.Abs(Vector3.Dot(vector5, vector7)) <= 0.001f && MathF.Abs(Vector3.Dot(vector6, vector7)) <= 0.001f) { return Matrix4x4.Invert(new Matrix4x4(value.X, value.Y, value.Z, 0f, value2.X, value2.Y, value2.Z, 0f, value3.X, value3.Y, value3.Z, 0f, 0f, 0f, 0f, 1f), out inverse); } return false; } } internal sealed class FlightBreakTimeline { internal const double MatchSeconds = 0.3; private const double MaxSampleAgeSeconds = 0.1; private const int MaxObservations = 4096; private readonly short localActor; private readonly bool probesAvailable; private readonly Queue<TraceRecord> history = new Queue<TraceRecord>(); private int? segment; private double droppedThrough = double.NegativeInfinity; public FlightBreakTimeline(CaptureMetadata capture) { localActor = capture.LocalActorNumber; probesAvailable = capture.StructureCollisionProbeInstalled && capture.EnvironmentCollisionProbeInstalled; } public BreakAnalysis? Observe(TraceRecord record) { if (segment != record.Stamp.Segment) { segment = record.Stamp.Segment; history.Clear(); droppedThrough = double.NegativeInfinity; } double num = record.Stamp.TimeSeconds - 0.3; TraceRecord result; while (history.TryPeek(out result) && result.Stamp.TimeSeconds < num) { history.Dequeue(); } if (record is PhysicsSample) { goto IL_00dd; } if (record is ContactObservation { Structure: var structure }) { if (structure.HasValue) { goto IL_00dd; } } else if (record is StructureImpactObservation || record is StructureImpactGap) { goto IL_00dd; } bool flag = false; goto IL_00e5; IL_00e5: bool flag2 = flag; bool flag3; if (!flag2) { if (!(record is GameplayObservation gameplayObservation)) { goto IL_01d6; } switch (gameplayObservation.Event) { case "structure_collision": case "structure_destroyed": case "player_hit": case "player_hit_from_beneath": case "jump_on_structure": case "structure_kill_requested": case "structure_pool_return": break; default: goto IL_01d6; } flag3 = true; goto IL_01d9; } goto IL_01dd; IL_00dd: flag = true; goto IL_00e5; IL_01d6: flag3 = false; goto IL_01d9; IL_01dd: if (flag2) { BreakAnalysis result2 = ((record is GameplayObservation { Event: "structure_destroyed", Structure: { } structure2 } gameplayObservation2) ? Explain(gameplayObservation2, structure2, num) : null); if (history.Count == 4096) { droppedThrough = history.Dequeue().Stamp.TimeSeconds; } history.Enqueue(record); return result2; } return null; IL_01d9: flag2 = flag3; goto IL_01dd; } private BreakAnalysis Explain(GameplayObservation end, StructureKey key, double oldest) { IEnumerable<GameplayObservation> source = from row in history.OfType<GameplayObservation>() where row.Structure == key || row.OtherStructure == key select row; GameplayObservation gameplayObservation = source.LastOrDefault((GameplayObservation row) => row.Event == "structure_kill_requested"); List<BreakCandidate> list = (from row in source.Where(delegate(GameplayObservation row) { bool flag = row.Event == "structure_collision"; if (!flag) { bool flag2 = row.Actor == localActor; if (flag2) { bool flag3; switch (row.Event) { case "player_hit": case "player_hit_from_beneath": case "jump_on_structure": flag3 = true; break; default: flag3 = false; break; } flag2 = flag3; } flag = flag2; } return flag; }) select Candidate(row, key)).ToList(); long? num = end.CollisionSequence ?? gameplayObservation?.CollisionSequence; long? num2 = gameplayObservation?.LastPhysicsTick ?? end.LastPhysicsTick; foreach (StructureImpactObservation item in from row in history.OfType<StructureImpactObservation>() where (object)row.Environment != null && row.First.Structure == key select row) { if (item.Stamp.Sequence == num || (num2.HasValue && item.PhysicsTick == num2 && ((object)gameplayObservation == null || item.Stamp.Sequence < gameplayObservation.Stamp.Sequence) && IsWall(item))) { list.Add(EnvironmentCandidate(item)); } } bool timelineComplete = probesAvailable && oldest > droppedThrough && !history.OfType<StructureImpactGap>().Any((StructureImpactGap gap) => gap.Structure == key || gap.OtherStructure == key || (!gap.Structure.HasValue && !gap.OtherStructure.HasValue)); return new BreakAnalysis(gameplayObservation?.Stamp, list.ToArray(), timelineComplete, num); } private BreakCandidate Candidate(GameplayObservation combat, StructureKey key) { bool flag = combat.Event == "structure_collision"; bool flag2 = combat.Structure == key; StructureKey? structureKey = (flag2 ? combat.OtherStructure : combat.Structure); if (structureKey == key) { structureKey = null; } BreakImpact impact = null; float? num = null; bool possibleIronBoots = false; long? lastPhysicsTick = combat.LastPhysicsTick; if (lastPhysicsTick.HasValue) { long tick = lastPhysicsTick.GetValueOrDefault(); if (flag) { StructureImpactObservation structureImpactObservation = MatchRegistration(combat, key, structureKey, tick); if ((object)structureImpactObservation != null) { impact = StructureImpact(combat, key, tick, structureImpactObservation); AgedMotionSample? first = structureImpactObservation.Motion.First; if ((object)first == null || first.Sample.Frozen != true) { AgedMotionSample? second = structureImpactObservation.Motion.Second; if ((object)second == null || second.Sample.Frozen != true) { num = FiniteSpeed(structureImpactObservation.RelativeLinearVelocity); } } } if (!num.HasValue) { CombatMeasurement combat2 = combat.Combat; if ((object)combat2 != null) { CombatVelocity secondStructure = combat2.SecondStructure; if ((object)secondStructure != null) { num = FiniteSpeed(FlightContactPatches.Vector(combat2.FirstStructure.Positional) - FlightContactPatches.Vector(secondStructure.Positional)); } } } } else { ContactObservation contactObservation = MatchPlayerContact(key, tick); impact = (((object)contactObservation == null) ? null : PlayerImpact(contactObservation, tick)); if ((object)contactObservation == null || contactObservation.Impact?.Second?.Sample.Frozen != true) { num = FiniteSpeed(contactObservation?.RelativeLinearVelocity); } CombatMeasurement combat3 = combat.Combat; if ((object)combat3 != null) { Vec3? vec = combat3.PlayerPhysicsBody?.Positional; Vec3? vec2 = history.OfType<PhysicsSample>().LastOrDefault((PhysicsSample row) => row.Tick == tick)?.Physics.LinearVelocityWorld; Vec3? vec3 = vec ?? vec2; if (vec3.HasValue) { Vec3 valueOrDefault = vec3.GetValueOrDefault(); float? num2 = num; if (!num2.HasValue) { num = FiniteSpeed(FlightContactPatches.Vector(combat3.FirstStructure.Positional) - FlightContactPatches.Vector(valueOrDefault)); } } if (combat.Event == "jump_on_structure" && (object)contactObservation != null && contactObservation.PlayerHitbox == "foot" && vec.HasValue) { Vec3 descent = vec.GetValueOrDefault(); if (descent.Y < -0.25f) { possibleIronBoots = contactObservation.Points.Any((ContactGeometry point) => Vector3.Dot(FlightContactPatches.Vector(descent), FlightContactPatches.Vector(point.NormalTowardPlayer)) < 0f); } } } } } return new BreakCandidate(combat.Stamp, combat.LastPhysicsTick, combat.Event, combat.Actor, flag ? structureKey : ((StructureKey?)null), (!flag) ? null : (flag2 ? combat.Detail : combat.StructureName), combat.CombatTimestamp, combat.Combat, impact, num, null, possibleIronBoots); } private ContactObservation? MatchPlayerContact(StructureKey key, long tick) { IGrouping<ContactKey, ContactObservation>[] array = (from row in history.OfType<ContactObservation>().Where(delegate(ContactObservation row) { bool flag = row.Structure == key && row.PhysicsTick == tick; if (flag) { string phase = row.Phase; bool flag2 = ((phase == "enter" || phase == "stay") ? true : false); flag = flag2; } return flag; }) group row by row.Pair).Take(2).ToArray(); if (array.Length != 1) { return null; } return array[0].Last(); } private static BreakImpact? PlayerImpact(ContactObservation contact, long tick) { int? otherBodyId = contact.OtherBodyId; if (otherBodyId.HasValue) { int valueOrDefault = otherBodyId.GetValueOrDefault(); return MeasureImpact(contact.Stamp, tick, "collision_callback", valueOrDefault, contact.PlayerBodyId, otherIsStructure: false, normalKnown: true, contact.Impact?.Second, contact.Impact?.First, contact.ReportedPointCount, contact.Points.Select((ContactGeometry point) => new ImpactPoint(point.PointWorld, point.NormalTowardPlayer, point.Separation))); } return null; } private StructureImpactObservation? MatchRegistration(GameplayObservation combat, StructureKey key, StructureKey? counterpart, long tick) { if (!counterpart.HasValue || counterpart == key) { return null; } StructureImpactObservation[] array = history.OfType<StructureImpactObservation>().Where(delegate(StructureImpactObservation row) { if ((object)row.Environment == null && row.Stamp.Sequence < combat.Stamp.Sequence && row.PhysicsTick == tick) { StructureKey? structure = row.First.Structure; StructureKey structureKey = key; if (!structure.HasValue || !(structure.GetValueOrDefault() == structureKey) || !(row.Second.Structure == counterpart)) { if (row.Second.Structure == key) { StructureKey? structure2 = row.First.Structure; structure = counterpart; if (structure2.HasValue != structure.HasValue) { return false; } if (!structure2.HasValue) { return true; } return structure2.GetValueOrDefault() == structure.GetValueOrDefault(); } return false; } return true; } return false; }).Take(2) .ToArray(); if (array.Length != 1) { return null; } return array[0]; } private static BreakImpact? StructureImpact(GameplayObservation combat, StructureKey key, long tick, StructureImpactObservation registration) { bool flag = registration.First.Structure == key; ImpactParticipant obj = (flag ? registration.First : registration.Second); ImpactParticipant impactParticipant = (flag ? registration.Second : registration.First); int? bodyId = obj.BodyId; if (bodyId.HasValue) { int valueOrDefault = bodyId.GetValueOrDefault(); bodyId = impactParticipant.BodyId; if (bodyId.HasValue) { int valueOrDefault2 = bodyId.GetValueOrDefault(); return MeasureImpact(registration.Stamp, tick, registration.Motion.ObservationPhase, valueOrDefault, valueOrDefault2, otherIsStructure: true, registration.NormalConvention == "toward_first", flag ? registration.Motion.First : registration.Motion.Second, flag ? registration.Motion.Second : registration.Motion.First, registration.ReportedPointCount, registration.Points, flag, combat.Combat?.CollisionPoint); } } return null; } private static bool IsWall(StructureImpactObservation hit) { ImpactPoint[] points = hit.Points; if (points != null && points.Length > 0) { return hit.Points.All((ImpactPoint point) => MathF.Abs(point.NormalWorld.Y) < 0.5f && FlightContactPatches.Vector(point.NormalWorld).LengthSquared() > 1E-08f); } return false; } private static BreakCandidate EnvironmentCandidate(StructureImpactObservation hit) { string environment = (IsWall(hit) ? "map wall" : "map surface"); BreakImpact impact = null; long? physicsTick = hit.PhysicsTick; if (physicsTick.HasValue) { long valueOrDefault = physicsTick.GetValueOrDefault(); int? bodyId = hit.First.BodyId; if (bodyId.HasValue) { int valueOrDefault2 = bodyId.GetValueOrDefault(); TraceStamp stamp = hit.Stamp; string observationPhase = hit.Motion.ObservationPhase; int? bodyId2 = hit.Second.BodyId; bool normalKnown = hit.NormalConvention == "toward_first"; AgedMotionSample? first = hit.Motion.First; AgedMotionSample? second = hit.Motion.Second; int reportedPointCount = hit.ReportedPointCount; ImpactPoint[] points = hit.Points; bool staticCollider = hit.Environment.StaticCollider; impact = MeasureImpact(stamp, valueOrDefault, observationPhase, valueOrDefault2, bodyId2, otherIsStructure: false, normalKnown, first, second, reportedPointCount, points, negateNormal: true, null, staticCollider); } } AgedMotionSample? first2 = hit.Motion.First; float? linearImpactMetersPerSecond = (((object)first2 != null && first2.Sample.Frozen == true) ? ((float?)null) : FiniteSpeed(hit.RelativeLinearVelocity)); return new BreakCandidate(hit.Stamp, hit.PhysicsTick, "environment_collision", null, null, hit.Second.Name, null, null, impact, linearImpactMetersPerSecond, environment); } private static BreakImpact MeasureImpact(TraceStamp stamp, long tick, string phase, int breakingId, int? otherId, bool otherIsStructure, bool normalKnown, AgedMotionSample? breaking, AgedMotionSample? other, int pointCount, IEnumerable<ImpactPoint> points, bool negateNormal = false, Vec3? gamePoint = null, bool staticCounterpart = false) { AgedMotionSample breaking2 = breaking; bool staticCounterpart2 = staticCounterpart; AgedMotionSample other2 = other; bool normalKnown2 = normalKnown; bool negateNormal2 = negateNormal; List<ImpactSpeed> list = new List<ImpactSpeed>(); ImpactSpeed gameContactSpeed = null; if (UsableImpact(breaking2, breakingId, tick, stamp, structure: true)) { if (staticCounterpart2) { goto IL_009f; } if (otherId.HasValue) { int valueOrDefault = otherId.GetValueOrDefault(); if (UsableImpact(other2, valueOrDefault, tick, stamp, otherIsStructure) && breaking2.Sample.FixedGameTimeSeconds == other2.Sample.FixedGameTimeSeconds) { goto IL_009f; } } } goto IL_012d; IL_009f: float num = float.PositiveInfinity; foreach (ImpactPoint point2 in points) { ImpactSpeed impactSpeed = AtPoint(point2.PointWorld, point2.NormalWorld); if ((object)impactSpeed == null) { continue; } list.Add(impactSpeed); if (gamePoint.HasValue) { Vec3 valueOrDefault2 = gamePoint.GetValueOrDefault(); float num2 = Vector3.DistanceSquared(FlightContactPatches.Vector(valueOrDefault2), FlightContactPatches.Vector(point2.PointWorld)); if (num2 < num) { num = num2; gameContactSpeed = impactSpeed; } } } goto IL_012d; IL_012d: return new BreakImpact(stamp, tick, phase, breakingId, otherId, pointCount, breaking2?.AgeSeconds, other2?.AgeSeconds, list.ToArray(), gameContactSpeed); ImpactSpeed? AtPoint(Vec3 worldPoint, Vec3 worldNormal) { Vector3 point = FlightContactPatches.Vector(worldPoint); Vector3 vector = PointVelocity(breaking2.Sample.Body, point) - (staticCounterpart2 ? Vector3.Zero : PointVelocity(other2.Sample.Body, point)); float? num3 = FiniteSpeed(vector); if (!num3.HasValue) { return null; } float valueOrDefault3 = num3.GetValueOrDefault(); Vector3 vector2 = FlightContactPatches.Vector(worldNormal); float? closingMetersPerSecond = ((normalKnown2 && FlightContactPatches.IsFinite(vector2) && vector2.LengthSquared() > 1E-08f) ? new float?(Vector3.Dot(vector, Vector3.Normalize(negateNormal2 ? (-vector2) : vector2))) : ((float?)null)); return new ImpactSpeed(worldPoint, valueOrDefault3, closingMetersPerSecond); } } private static float? FiniteSpeed(Vec3? velocity) { if (velocity.HasValue) { Vec3 valueOrDefault = velocity.GetValueOrDefault(); return FiniteSpeed(FlightContactPatches.Vector(valueOrDefault)); } return null; } private static float? FiniteSpeed(Vector3 velocity) { float num = velocity.Length(); if (!float.IsFinite(num)) { return null; } return num; } private static Vector3 PointVelocity(BodyKinematics body, Vector3 point) { return FlightContactPatches.Vector(body.LinearVelocityWorld) + Vector3.Cross(FlightContactPatches.Vector(body.AngularVelocityWorld), point - FlightContactPatches.Vector(body.WorldCenterOfMass)); } private static bool UsableImpact(AgedMotionSample? motion, int id, long tick, TraceStamp stamp, bool structure) { if ((object)motion != null && motion.SameFixedStep) { double ageSeconds = motion.AgeSeconds; if (ageSeconds >= 0.0 && ageSeconds <= 0.1) { return Usable(motion.Sample, id, tick, stamp, structure); } } return false; } private static bool Usable(FixedMotionSample? sample, int id, long tick, TraceStamp stamp, bool structure) { if ((object)sample != null && sample.Body.BodyId == id && sample.Segment == stamp.Segment && sample.Tick == tick && sample.SimulationMode == "FixedUpdate" && (structure ? (sample.Frozen == false) : (sample.Frozen != true))) { double num = stamp.TimeSeconds - sample.SampleSeconds; if (num >= 0.0) { return num <= 0.1; } return false; } return false; } } public sealed class FlightContactObserver : MonoBehaviour { private StructureTelemetry? telemetry; private int receiverBodyId; public FlightContactObserver(IntPtr pointer) : base(pointer) { } [HideFromIl2Cpp] internal void Bind(StructureTelemetry? capture, int bodyId) { telemetry = capture; receiverBodyId = bodyId; } private void OnCollisionEnter(Collision collision) { telemetry?.ReportContact(receiverBodyId, collision, "enter"); } private void OnCollisionStay(Collision collision) { telemetry?.ReportContact(receiverBodyId, collision, "stay"); } private void OnCollisionExit(Collision collision) { telemetry?.ReportContact(receiverBodyId, collision, "exit"); } } internal readonly record struct HudBodyFrame(Vector3 Center, Quaternion Yaw); internal sealed record HudContactPatch(ContactGeometry[] Points, Vector3? BodyDirection, Vector3? BodyNormal, Vector3? WorldPoint); internal static class FlightContactPatches { private readonly record struct Point(ContactGeometry Geometry, Vector3 Position, Vector3 Normal); private const float SameFaceNormalDot = 0.9962f; private const float SameFacePlaneDistance = 0.015f; private const float MinimumOffsetSquared = 1E-06f; public static HudContactPatch[] Build(ContactGeometry[] geometry, HudBodyFrame? body) { if (geometry.Length == 0) { return Array.Empty<HudContactPatch>(); } Point[] array = geometry.Select((ContactGeometry contactGeometry) => new Point(contactGeometry, Vector(contactGeometry.PointWorld), UnitNormal(contactGeometry.NormalTowardPlayer))).ToArray(); Array.Sort(array, Compare); List<List<Point>> list = new List<List<Point>>(); Point[] array2 = array; foreach (Point point in array2) { List<Point> list2 = list.Find((List<Point> face) => face.TrueForAll((Point other) => SameFace(point, other))); if (list2 == null) { list.Add(list2 = new List<Point>()); } list2.Add(point); } return list.Select((List<Point> face) => Mark(face, body)).ToArray(); } private static HudContactPatch Mark(List<Point> face, HudBodyFrame? body) { Vector3? bodyDirection = null; Vector3? bodyNormal = null; Vector3? worldPoint = null; if (body.HasValue) { HudBodyFrame valueOrDefault = body.GetValueOrDefault(); if (IsFinite(face[0].Position)) { Quaternion rotation = Quaternion.Conjugate(valueOrDefault.Yaw); Vector3 vector = ClosestPoint(face, valueOrDefault.Center); Vector3 value = vector - valueOrDefault.Center; if (IsFinite(vector)) { worldPoint = vector; } if (IsFinite(value) && value.LengthSquared() >= 1E-06f) { bodyDirection = Vector3.Transform(value, rotation); } if (face[0].Normal != Vector3.Zero) { bodyNormal = Vector3.Transform(face[0].Normal, rotation); } } } return new HudContactPatch(face.Select((Point point) => point.Geometry).ToArray(), bodyDirection, bodyNormal, worldPoint); } private static Vector3 ClosestPoint(List<Point> face, Vector3 center) { Vector3 position = face[0].Position; if (face.Count == 1) { return position; } if (face.Count == 2) { return OnSegment(center, position, face[1].Position); } Vector3 normal = face[0].Normal; Vector3 vector = center - Vector3.Dot(center - position, normal) * normal; Span<Vector3> span = stackalloc Vector3[face.Count]; for (int i = 0; i < span.Length; i++) { Vector3 position2 = face[i].Position; span[i] = position2 - Vector3.Dot(position2 - position, normal) * normal; } Vector3 result = position; float num = Vector3.DistanceSquared(vector, position); for (int j = 0; j < span.Length; j++) { for (int k = j + 1; k < span.Length; k++) { if (j > 0 && InsideTriangle(vector, position, span[j], span[k], normal)) { return vector; } Vector3 vector2 = OnSegment(vector, span[j], span[k]); float num2 = Vector3.DistanceSquared(vector, vector2); if (num2 < num) { result = vector2; num = num2; } } } return result; } private static bool InsideTriangle(Vector3 point, Vector3 a, Vector3 b, Vector3 c, Vector3 normal) { float x = Vector3.Dot(Vector3.Cross(b - a, c - a), normal); if (MathF.Abs(x) <= 1E-08f) { return false; } float num = MathF.Sign(x); if (num * Vector3.Dot(Vector3.Cross(b - a, point - a), normal) >= 0f && num * Vector3.Dot(Vector3.Cross(c - b, point - b), normal) >= 0f) { return num * Vector3.Dot(Vector3.Cross(a - c, point - c), normal) >= 0f; } return false; } private static Vector3 OnSegment(Vector3 point, Vector3 a, Vector3 b) { Vector3 vector = b - a; float num = vector.LengthSquared(); if (!(num > 1E-10f)) { return a; } return a + Math.Clamp(Vector3.Dot(point - a, vector) / num, 0f, 1f) * vector; } private static bool SameFace(Point a, Point b) { Vector3 vector = a.Position - b.Position; if (Vector3.Dot(a.Normal, b.Normal) >= 0.9962f && MathF.Abs(Vector3.Dot(vector, a.Normal)) <= 0.015f) { return MathF.Abs(Vector3.Dot(vector, b.Normal)) <= 0.015f; } return false; } private static int Compare(Point a, Point b) { int num = CompareVector(a.Position, b.Position); if (num != 0) { return num; } return CompareVector(a.Normal, b.Normal); } private static int CompareVector(Vector3 a, Vector3 b) { int num = a.X.CompareTo(b.X); if (num != 0) { return num; } num = a.Y.CompareTo(b.Y); if (num != 0) { return num; } return a.Z.CompareTo(b.Z); } public static Quaternion? Yaw(Quat rotation) { Quaternion value = new Quaternion(rotation.X, rotation.Y, rotation.Z, rotation.W); float num = value.LengthSquared(); if (!float.IsFinite(num) || num < 1E-06f) { return null; } Vector3 vector = Vector3.Transform(Vector3.UnitZ, Quaternion.Normalize(value)); return Quaternion.CreateFromAxisAngle(Vector3.UnitY, MathF.Atan2(vector.X, vector.Z)); } private static Vector3 UnitNormal(Vec3 normal) { Vector3 vector = Vector(normal); float num = vector.LengthSquared(); if (!float.IsFinite(num) || !(num >= 1E-06f)) { return Vector3.Zero; } return vector / MathF.Sqrt(num); } public static bool IsFinite(Vector3 value) { if (float.IsFinite(value.X) && float.IsFinite(value.Y)) { return float.IsFinite(value.Z); } return false; } public static Vector3 Vector(Vec3 value) { return new Vector3(value.X, value.Y, value.Z); } } internal sealed class FlightGameHooks : IDisposable { private sealed record EnvironmentFrame(StructureTelemetry Owner, StructureTelemetry.EnvironmentCollision? Previous); private readonly Harmony harmony = new Harmony("GloriousCandle119.RumbleFlightRuntime"); private readonly Instance logger; private readonly List<MethodBase> methods = new List<MethodBase>(); private static StructureTelemetry? Active => FlightRuntime.ActiveTelemetry; public bool StructureCollisionProbeInstalled { get; } public bool EnvironmentCollisionProbeInstalled { get; } public FlightGameHooks(Instance logger) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown this.logger = logger; Patch(typeof(Structure), "OnFetchFromPool", "FetchPostfix", postfix: true); Patch(typeof(Structure), "OnReturnToPool", "ReturnPrefix"); Patch(typeof(Structure), "Kill", "KillPrefix"); Patch(typeof(HoldModifier), "Execute", "HoldPrefix"); Patch(typeof(FlickModifier), "Execute", "FlickPrefix"); StructureCollisionProbeInstalled = Patch(typeof(CombatManager), "RegisterStructureCollisionEvent", "StructureCollisionPrefix", postfix: false, new Type[3] { typeof(Structure), typeof(Structure), typeof(Collision) }); bool flag = Patch(typeof(Structure), "OnCollisionEnter", "EnvironmentEnterPrefix", postfix: false, null, "EnvironmentCollisionFinalizer"); bool flag2 = Patch(typeof(Structure), "OnCollisionStay", "EnvironmentStayPrefix", postfix: false, null, "EnvironmentCollisionFinalizer"); EnvironmentCollisionProbeInstalled = flag && flag2; } public void Dispose() { foreach (MethodBase method in methods) { try { harmony.Unpatch(method, (HarmonyPatchType)0, harmony.Id); } catch (Exception ex) { logger.Warning("Could not remove flight hook " + method.Name + ": " + ex.Message); } } } private bool Patch(Type gameType, string methodName, string hook, bool postfix = false, Type[]? parameterTypes = null, string? finalizer = null) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Expected O, but got Unknown //IL_0076: Unknown result type (might be due to invalid IL or missing references) try { MethodInfo methodInfo = AccessTools.DeclaredMethod(gameType, methodName, parameterTypes, (Type[])null) ?? throw new MissingMethodException(gameType.FullName, methodName); if (methods.Contains(methodInfo)) { return true; } HarmonyMethod val = new HarmonyMethod(typeof(FlightGameHooks), hook, (Type[])null); if (postfix) { harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } else { harmony.Patch((MethodBase)methodInfo, val, (HarmonyMethod)null, (HarmonyMethod)null, (finalizer == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(FlightGameHooks), finalizer, (Type[])null), (HarmonyMethod)null); } methods.Add(methodInfo); return true; } catch (Exception ex) { logger.Warning($"Flight hook {gameType.Name}.{methodName} failed: {ex.Message}"); return false; } } private static void EnvironmentEnterPrefix(Structure __instance, Collision __0, out EnvironmentFrame? __state) { BeginEnvironmentCollision(__instance, __0, "enter", out __state); } private static void EnvironmentStayPrefix(Structure __instance, Collision __0, out EnvironmentFrame? __state) { BeginEnvironmentCollision(__instance, __0, "stay", out __state); } private static void BeginEnvironmentCollision(Structure structure, Collision collision, string phase, out EnvironmentFrame? state) { state = null; StructureTelemetry capture = Active; if (capture != null) { state = new EnvironmentFrame(capture, capture.ActiveEnvironmentCollision); capture.ActiveEnvironmentCollision = null; capture.Guard("structure_environment_collision", delegate { capture.BeginEnvironmentCollision(structure, collision, phase); }); } } private static Exception? EnvironmentCollisionFinalizer(Exception? __exception, EnvironmentFrame? __state) { if ((object)__state != null) { __state.Owner.ActiveEnvironmentCollision = __state.Previous; } return __exception; } private static void StructureCollisionPrefix(Structure __0, Structure __1, Collision __2) { StructureTelemetry capture = Active; if (capture != null) { capture.Guard("structure_collision_probe", delegate { capture.OnStructureCollision(__0, __1, __2); }); } } private static void FetchPostfix(Structure __instance) { StructureTelemetry capture = Active; if (capture != null) { capture.Guard("pool_fetch", delegate { capture.OnFetch(__instance); }); } } private static void ReturnPrefix(Structure __instance) { StructureTelemetry capture = Active; if (capture != null) { capture.Guard("pool_return", delegate { capture.OnReturn(__instance); }); } } private static void KillPrefix(Structure __instance) { StructureTelemetry capture = Active; if (capture != null) { capture.Guard("structure_kill", delegate { capture.OnKill(__instance); }); } } private static void HoldPrefix(IProcessor __0, StackConfiguration __1) { StructureTelemetry capture = Active; if (capture != null) { capture.Guard("hold_execute", delegate { capture.OnModifier(__0, __1); }); } } private static void FlickPrefix(IProcessor __0, StackConfiguration __1) { StructureTelemetry capture = Active; if (capture != null) { capture.Guard("flick_execute", delegate { capture.OnModifier(__0, __1); }); } } } internal readonly record struct HudColliderFrame(Vector3 Origin, Vector3 X, Vector3 Y, Vector3 Z) { public static HudColliderFrame From(AffineFrame frame) { return new HudColliderFrame(FlightContactPatches.Vector(frame.Origin), FlightContactPatches.Vector(frame.XAxis), FlightContactPatches.Vector(frame.YAxis), FlightContactPatches.Vector(frame.ZAxis)); } public static HudColliderFrame? From(Pose pose) { Quaternion value = new Quaternion(pose.Rotation.X, pose.Rotation.Y, pose.Rotation.Z, pose.Rotation.W); Vector3 vector = FlightContactPatches.Vector(pose.Position); if (!FlightContactPatches.IsFinite(vector) || !float.IsFinite(value.LengthSquared()) || value.LengthSquared() < 1E-06f) { return null; } value = Quaternion.Normalize(value); return new HudColliderFrame(vector, Vector3.Transform(Vector3.UnitX, value), Vector3.Transform(Vector3.UnitY, value), Vector3.Transform(Vector3.UnitZ, value)); } private Vector3 Direction(Vector3 local) { return local.X * X + local.Y * Y + local.Z * Z; } public Vector3 Point(Vector3 local) { return Origin + Direction(local); } public HudColliderFrame Compose(AffineFrame child) { return new HudColliderFrame(Point(FlightContactPatches.Vector(child.Origin)), Direction(FlightContactPatches.Vector(child.XAxis)), Direction(FlightContactPatches.Vector(child.YAxis)), Direction(FlightContactPatches.Vector(child.ZAxis))); } } internal readonly record struct HudStructureCollider(ColliderShape Shape, HudColliderFrame Frame) { public bool AllowsBoundsPreview => !FlightBakedWireframes.HasBakedOutline(Shape.MeshName); public HudContactPlacement Place(HudBodyFrame origin, HudPlayerCollider? player, long? tick) { return new HudContactPlacement(origin, player, FlightBoxPreview.Build(tick, Shape, Frame), HudMeshPreview.Build(Shape, Frame)); } public static HudStructureCollider? Resolve(StructureKey structure, ContactKey pair, int segment, long? tick, ContactFrames frames, FixedMotionSample? motion, PhysicsSample? step) { ColliderFrameReference structureCollider = frames.StructureCollider; if ((object)structureCollider != null) { ColliderDescriptorObservation definition = structureCollider.Definition; if ((object)definition != null && definition.Stamp.Sequence == structureCollider.DescriptorSequence && definition.Stamp.Segment == segment) { ColliderDescriptor descriptor = definition.Descriptor; if ((object)descriptor != null) { StructureKey? structure2 = descriptor.Structure; if (structure2.HasValue && !(structure2.GetValueOrDefault() != structure) && descriptor.ColliderId == pair.OtherColliderId) { AffineFrame? structureRootWorld = frames.StructureRootWorld; HudColliderFrame? obj; if (structureRootWorld.HasValue) { AffineFrame valueOrDefault = structureRootWorld.GetValueOrDefault(); obj = HudColliderFrame.From(valueOrDefault); } else { obj = null; } HudColliderFrame? hudColliderFrame = obj; int? referenceBodyId = descriptor.ReferenceBodyId; if (referenceBodyId.HasValue) { int valueOrDefault2 = referenceBodyId.GetValueOrDefault(); if (descriptor.AttachedBodyId == valueOrDefault2) { structureRootWorld = structureCollider.RootToReferenceBodyOverride ?? descriptor.RootToReferenceBody; if (structureRootWorld.HasValue) { AffineFrame valueOrDefault3 = structureRootWorld.GetValueOrDefault(); HudColliderFrame? hudColliderFrame2 = FixedPose(structure, valueOrDefault2, segment, tick, motion, step); if (hudColliderFrame2.HasValue) { hudColliderFrame = hudColliderFrame2.GetValueOrDefault().Compose(valueOrDefault3); } } } } if (hudColliderFrame.HasValue) { HudColliderFrame valueOrDefault4 = hudColliderFrame.GetValueOrDefault(); return new HudStructureCollider(descriptor.Shape, valueOrDefault4.Compose(structureCollider.ColliderToRootOverride ?? descriptor.ColliderToRoot)); } return null; } } } } return null; } private static HudColliderFrame? FixedPose(StructureKey key, int bodyId, int segment, long? tick, FixedMotionSample? motion, PhysicsSample? step) { if ((((object)motion != null) ? (motion.Tick == tick) : (!tick.HasValue)) && (object)motion != null) { int segment2 = motion.Segment; BodyKinematics body = motion.Body; if (segment2 == segment && body.BodyId == bodyId) { return HudColliderFrame.From(body.WorldPose); } } if ((object)step != null && step.Tick == tick && step.Stamp.Segment == segment) { StructureFrame structureTelemetry = step.StructureTelemetry; if ((object)structureTelemetry != null) { StructureMotion[] structures = structureTelemetry.Structures; foreach (StructureMotion structureMotion in structures) { if (structureMotion.Key == key && structureMotion.RigidbodyId == bodyId) { return HudColliderFrame.From(structureMotion.WorldPose); } } } } return null; } } internal sealed record HudMeshPreview(Vector3 Center, HudColliderFrame Offsets, Vec3[][]? Sections, MeshEdge[]? Edges) { public static HudMeshPreview? Build(ColliderShape shape, HudColliderFrame frame) { if ((object)shape != null && shape.Kind == "mesh" && (shape.Convex ?? false)) { MeshLocalBounds? meshBounds = shape.MeshBounds; if (meshBounds.HasValue) { MeshLocalBounds valueOrDefault = meshBounds.GetValueOrDefault(); if (FlightContactPatches.IsFinite(frame.X) && FlightContactPatches.IsFinite(frame.Y) && FlightContactPatches.IsFinite(frame.Z)) { Vector3 vector = frame.Point(FlightContactPatches.Vector(valueOrDefault.Center)); if (!FlightContactPatches.IsFinite(vector)) { return null; } HudColliderFrame offsets = frame with { Origin = frame.Origin - vector }; MeshEdge[] meshEdges = shape.MeshEdges; if (meshEdges != null) { int num = meshEdges.Length; if (num >= 6 && num <= 96 && meshEdges.All((MeshEdge edge) => edge.Start != edge.End && FlightContactPatches.IsFinite(FlightContactPatches.Vector(edge.Start)) && FlightContactPatches.IsFinite(FlightContactPatches.Vector(edge.End)))) { return new HudMeshPreview(vector, offsets, null, meshEdges); } } Vec3[][] meshContours = shape.MeshContours; if (meshContours != null) { int num = meshContours.Length; if (num > 0 && num <= 4 && meshContours.All(delegate(Vec3[] path) { if (path != null) { int num2 = path.Length; if (num2 >= 4 && num2 <= 33 && path[0] == path[^1]) { return path.All((Vec3 point) => FlightContactPatches.IsFinite(FlightContactPatches.Vector(point))); } } return false; })) { return new HudMeshPreview(vector, offsets, meshContours, null); } } return null; } } } return null; } } internal sealed record HudPlayerCollider(Vector3 Center, Vector3 Axis, float HalfSpan, float Radius) { public float SurfaceDistance(Vector3 worldPoint) { return MathF.Abs(Vector3.Distance(worldPoint, AxisPoint(worldPoint)) - Radius); } public Vector3? PointOnSurface(Vector3 point) { Vector3 vector = AxisPoint(point); Vector3 vector2 = point - vector; float num = vector2.Length(); if (!(num > 1E-06f)) { return null; } return vector + vector2 * (Radius / num); } private Vector3 AxisPoint(Vector3 point) { return Center + Axis * Math.Clamp(Vector3.Dot(point - Center, Axis), 0f - HalfSpan, HalfSpan); } public static HudPlayerCollider? Build(ContactKey pair, int segment, int? receiverId, ContactFrames? frames, Pose? receivingPose) { if (receiverId.HasValue) { ColliderFrameReference colliderFrameReference = frames?.PlayerCollider; if ((object)colliderFrameReference != null) { ColliderDescriptorObservation definition = colliderFrameReference.Definition; if ((object)definition != null && definition.Stamp.Sequence == colliderFrameReference.DescriptorSequence && definition.Stamp.Segment == segment) { ColliderDescriptor descriptor = definition.Descriptor; if ((object)descriptor != null && !descriptor.Structure.HasValue && descriptor.ColliderId == pair.PlayerColliderId && descriptor.AttachedBodyId == receiverId && descriptor.ReferenceBodyId == receiverId) { AffineFrame? affineFrame = colliderFrameReference.RootToReferenceBodyOverride ?? descriptor.RootToReferenceBody; if (affineFrame.HasValue) { AffineFrame valueOrDefault = affineFrame.GetValueOrDefault(); if (receivingPose.HasValue) { Pose valueOrDefault2 = receivingPose.GetValueOrDefault(); HudColliderFrame? hudColliderFrame = HudColliderFrame.From(valueOrDefault2); if (hudColliderFrame.HasValue) { HudColliderFrame world = hudColliderFrame.GetValueOrDefault().Compose(valueOrDefault).Compose(colliderFrameReference.ColliderToRootOverride ?? descriptor.ColliderToRoot); return Build(descriptor.Shape, world); } } } } } } } return null; } public static HudPlayerCollider? Build(ColliderShape shape, HudColliderFrame world) { Vector3 vector; Vector3 value; Vector3 vector3; Vector3 vector4; (Vector3, float, float, float) tuple; float? radius; if ((object)shape != null) { Vec3? center = shape.Center; if (center.HasValue) { Vec3 valueOrDefault = center.GetValueOrDefault(); radius = shape.Radius; if (radius.HasValue && radius.GetValueOrDefault() > 0f) { vector = world.Point(FlightContactPatches.Vector(valueOrDefault)); value = new Vector3(world.X.Length(), world.Y.Length(), world.Z.Length()); if (!FlightContactPatches.IsFinite(vector) || !FlightContactPatches.IsFinite(value) || value.X <= 0f || value.Y <= 0f || value.Z <= 0f) { return null; } Vector3 vector2 = world.X / value.X; vector3 = world.Y / value.Y; vector4 = world.Z / value.Z; if (MathF.Abs(Vector3.Dot(vector2, vector3)) > 0.001f || MathF.Abs(Vector3.Dot(vector2, vector4)) > 0.001f || MathF.Abs(Vector3.Dot(vector3, vector4)) > 0.001f) { return null; } if ((object)shape == null) { goto IL_02a6; } string kind = shape.Kind; if (!(kind == "capsule")) { if (!(kind == "sphere") || !(MathF.Abs(value.X - value.Y) <= 0.001f)) { goto IL_02a6; } tuple = (vector3, value.Y, value.X, value.Z); } else { switch (shape.Direction) { case 0: break; case 1: goto IL_01ca; case 2: goto IL_01f2; default: goto IL_02a6; } radius = shape.Height; if (!radius.HasValue || !(radius.GetValueOrDefault() > 0f)) { goto IL_02a6; } tuple = (vector2, value.X, value.Y, value.Z); } goto IL_02b2; } } } return null; IL_02a6: tuple = default((Vector3, float, float, float)); goto IL_02b2; IL_01f2: radius = shape.Height; if (!radius.HasValue || !(radius.GetValueOrDefault() > 0f)) { goto IL_02a6; } tuple = (vector4, value.Z, value.X, value.Y); goto IL_02b2; IL_02b2: var (axis, num, num2, num3) = tuple; if (num == 0f || MathF.Abs(num2 - num3) > 0.001f) { return null; } float num4 = shape.Radius.Value * num2; float num5 = ((shape.Kind == "sphere") ? (2f * num4) : (shape.Height.Value * num)); if (!float.IsFinite(num5) || !float.IsFinite(num4)) { return null; } return new HudPlayerCollider(vector, axis, MathF.Max(0f, num5 * 0.5f - num4), num4); IL_01ca: radius = shape.Height; if (!radius.HasValue || !(radius.GetValueOrDefault() > 0f)) { goto IL_02a6; } tuple = (vector3, value.Y, value.Z, value.X); goto IL_02b2; } } internal sealed record HudContactPlacement(HudBodyFrame Origin, HudPlayerCollider? Player, HudBoxPreview? Box, HudMeshPreview? Mesh = null) { public const float Scale = 0.085f; public Vector3 Offset(Vector3 worldPoint) { return (worldPoint - Origin.Center) * 0.085f; } public Vector3? MarkerPoint(HudContactPatch patch) { HudPlayerCollider player = Player; if ((object)player != null) { Vector3? worldPoint = patch.WorldPoint; if (worldPoint.HasValue) { Vector3 valueOrDefault = worldPoint.GetValueOrDefault(); float num = 0f; ContactGeometry[] points = patch.Points; int num2 = 0; while (num2 < points.Length) { ContactGeometry contactGeometry = points[num2]; float num3 = 0.02f + MathF.Abs(contactGeometry.Separation); if (float.IsFinite(num3)) { HudBoxPreview? box = Box; if (((object)box == null || box.Contains(contactGeometry)) && player.SurfaceDistance(FlightContactPatches.Vector(contactGeometry.PointWorld)) <= num3) { num = MathF.Max(num3, num); num2++; continue; } } return null; } if (!(player.SurfaceDistance(valueOrDefault) <= num)) { return null; } return player.PointOnSurface(valueOrDefault); } } return null; } [CompilerGenerated] private HudContactPlacement(HudContactPlacement original) { Origin = original.Origin; Player = original.Player; Box = original.Box; Mesh = original.Mesh; } } internal enum HudLossKind { Separated, SeparatedIntact, Broken, SignalLost } internal sealed record HudLossMark(HudPairGeometry[] Contacts, HudLossKind Kind, double TimeSeconds, HudBreak? Break = null); internal sealed record HudBreak(StructureKey Key, string? Name, BreakAnalysis? Analysis, double TimeSeconds); internal sealed record HudPairGeometry(ContactKey Pair, long? Tick, HudContactPatch[] Patches, HudContactPlacement? Placement); internal sealed record HudNearbyCollider(int ColliderId, HudContactPlacement Placement); internal readonly record struct HudPairFrame(HudPairGeometry Geometry, Vector3 PushWorld, bool HasImpulse) { public HudContactPatch[] Patches => Geometry.Patches; } internal sealed record HudStructureFrame(StructureKey Key, HudPairFrame[] ActivePairs, Vector3 PushWorld, bool HasImpulse, bool PartialImpulse, HudLossMark[] Losses, IReadOnlyList<HudNearbyCollider>? NearbyGeometry = null) { public bool Touching => ActivePairs.Length != 0; } internal sealed record FlightHudFrame(Quaternion BodyYaw, Vector3 PushWorld, HudStructureFrame[] Structures, int TouchingCount, int MeasuredCount, bool PartialImpulse, bool ObserverAvailable, long? GeometryTick, HudBreak? RecentBreak = null) { public string? Outcome { get { HudLossMark hudLossMark = Structures.SelectMany((HudStructureFrame structure) => structure.Losses).Ma