Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Valheim Airships v0.2.37
BepInEx/plugins/Valheim_Airships/ValheimAirships.dll
Decompiled 3 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security.Cryptography; using System.Text; using Airships.Core; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using SoftReferenceableAssets.SceneManagement; using TMPro; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("ValheimAirships")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.2.37.0")] [assembly: AssemblyInformationalVersion("0.2.37")] [assembly: AssemblyProduct("ValheimAirships")] [assembly: AssemblyTitle("ValheimAirships")] [assembly: AssemblyVersion("0.2.37.0")] namespace ValheimAirships; internal static class AirshipAnimalCageLayout { internal const int Count = 2; internal static readonly Vector3[] Centers = (Vector3[])(object)new Vector3[2] { new Vector3(0f, -1.2f, 3.5f), new Vector3(-2.7f, 0.14f, -2.3f) }; internal static readonly Vector3[] Sizes = (Vector3[])(object)new Vector3[2] { new Vector3(5.8f, 4.9f, 8f), new Vector3(2f, 2f, 3.6f) }; internal static readonly Vector3 HelmConsoleStanding = new Vector3(-0.65f, 0.08f, -3.95f); internal static Vector3 Handle(int slot) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) return Centers[slot] + new Vector3(Sizes[slot].x * 0.5f + 0.07f, (slot == 0) ? 2.25f : 1.05f, 0f); } internal static Bounds Interior(int slot) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Sizes[slot] - new Vector3(0.2f, 0.18f, 0.2f); return new Bounds(Centers[slot] + Vector3.up * (Sizes[slot].y * 0.5f), val); } internal static Vector3 HelmConsole(int slot) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) return new Vector3(-1.4f, 1.52f - (float)slot * 0.42f, -4.64f); } } internal sealed class AirshipAnimalCages : MonoBehaviour { private readonly Transform[] cages = (Transform[])(object)new Transform[2]; private readonly Transform[] gates = (Transform[])(object)new Transform[2]; private readonly BoxCollider[] gateBoxes = (BoxCollider[])(object)new BoxCollider[2]; private readonly Collider[][] solids = new Collider[2][]; private readonly Collider[] controls = (Collider[])(object)new Collider[4]; private AirshipAnimalTransport transport; private AirshipAnimalWellGeometry well; internal int VisibleCount { get { int num = 0; for (int i = 0; i < cages.Length; i++) { if (IsVisible(i)) { num++; } } return num; } } internal static string HelmHint { get { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) if (Plugin.AnimalTransportKey != null) { return "\n[<color=yellow>" + ((object)Plugin.AnimalTransportKey.Value/*cast due to .constrained prefix*/).ToString() + "</color>] Большая клетка · Alt — малая"; } return ""; } } internal bool IsVisible(int slot) { if (slot >= 0 && slot < cages.Length && Object.op_Implicit((Object)(object)cages[slot])) { return ((Component)cages[slot]).gameObject.activeSelf; } return false; } internal Transform Cage(int slot) { return cages[slot]; } internal static AirshipAnimalCages Create(Transform model, Transform root, PrototypeVisualResources owner, Material[] palette, AirshipAnimalTransport transport, AirshipAnimalWellGeometry well) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00be: 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_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_015a: 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_0176: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: 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_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_0220: 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_0241: Unknown result type (might be due to invalid IL or missing references) //IL_025f: Unknown result type (might be due to invalid IL or missing references) //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_0272: Unknown result type (might be due to invalid IL or missing references) //IL_0284: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_028e: Unknown result type (might be due to invalid IL or missing references) //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_02ab: Unknown result type (might be due to invalid IL or missing references) //IL_02bc: Unknown result type (might be due to invalid IL or missing references) //IL_02e3: Unknown result type (might be due to invalid IL or missing references) //IL_02f4: Unknown result type (might be due to invalid IL or missing references) //IL_0380: Unknown result type (might be due to invalid IL or missing references) //IL_0319: Unknown result type (might be due to invalid IL or missing references) //IL_0328: Unknown result type (might be due to invalid IL or missing references) //IL_0332: Unknown result type (might be due to invalid IL or missing references) //IL_0344: Unknown result type (might be due to invalid IL or missing references) //IL_03a1: Unknown result type (might be due to invalid IL or missing references) //IL_03b2: Unknown result type (might be due to invalid IL or missing references) //IL_0552: Unknown result type (might be due to invalid IL or missing references) //IL_057f: Unknown result type (might be due to invalid IL or missing references) //IL_04bb: Unknown result type (might be due to invalid IL or missing references) //IL_04c0: Unknown result type (might be due to invalid IL or missing references) //IL_04cc: Unknown result type (might be due to invalid IL or missing references) //IL_04d3: Unknown result type (might be due to invalid IL or missing references) //IL_04fc: Unknown result type (might be due to invalid IL or missing references) //IL_0506: Unknown result type (might be due to invalid IL or missing references) //IL_0512: Unknown result type (might be due to invalid IL or missing references) //IL_0519: Unknown result type (might be due to invalid IL or missing references) //IL_03de: Unknown result type (might be due to invalid IL or missing references) //IL_03e3: Unknown result type (might be due to invalid IL or missing references) //IL_03fa: Unknown result type (might be due to invalid IL or missing references) //IL_041d: Unknown result type (might be due to invalid IL or missing references) //IL_042e: Unknown result type (might be due to invalid IL or missing references) //IL_045a: Unknown result type (might be due to invalid IL or missing references) //IL_0469: Unknown result type (might be due to invalid IL or missing references) //IL_0476: Unknown result type (might be due to invalid IL or missing references) AirshipAnimalCages airshipAnimalCages = ((Component)model).gameObject.AddComponent<AirshipAnimalCages>(); airshipAnimalCages.transport = transport; airshipAnimalCages.well = well; Transform val = null; try { val = AirshipNativeDecor.Copy(model, owner, "iron_wall_2x2", "MA_CageIronTemplate", Vector3.zero, Quaternion.identity); if (!Object.op_Implicit((Object)(object)val)) { throw new InvalidOperationException("Native iron_wall_2x2 cage grid unavailable"); } ((Component)val).gameObject.SetActive(false); Bounds ironBounds = LocalMeshBounds(val); for (int i = 0; i < 2; i++) { Vector3 val2 = AirshipAnimalCageLayout.Sizes[i]; Transform transform = new GameObject("MA_AnimalCage" + i).transform; transform.SetParent(model, false); transform.localPosition = AirshipAnimalCageLayout.Centers[i]; airshipAnimalCages.cages[i] = transform; PanelWall(transform, val, ironBounds, "Port", new Vector3((0f - val2.x) * 0.5f, val2.y * 0.5f, 0f), Quaternion.Euler(0f, 90f, 0f), val2.z, val2.y); PanelWall(transform, val, ironBounds, "Starboard", new Vector3(val2.x * 0.5f, val2.y * 0.5f, 0f), Quaternion.Euler(0f, 90f, 0f), val2.z, val2.y); PanelWall(transform, val, ironBounds, "Bow", new Vector3(0f, val2.y * 0.5f, val2.z * 0.5f), Quaternion.identity, val2.x, val2.y); PanelWall(transform, val, ironBounds, "Roof", new Vector3(0f, val2.y, 0f), Quaternion.Euler(90f, 0f, 0f), val2.x, val2.z); Transform transform2 = new GameObject("MA_AnimalCageGate" + i).transform; transform2.SetParent(transform, false); transform2.localPosition = new Vector3((0f - val2.x) * 0.5f, 0f, (0f - val2.z) * 0.5f); airshipAnimalCages.gates[i] = transform2; airshipAnimalCages.gateBoxes[i] = PanelWall(transform2, val, ironBounds, "Gate", new Vector3(val2.x * 0.5f, val2.y * 0.5f, 0f), Quaternion.identity, val2.x, val2.y); float[] array = new float[2] { (0f - val2.x) * 0.5f, val2.x * 0.5f }; foreach (float num in array) { float[] array2 = new float[2] { (0f - val2.z) * 0.5f, val2.z * 0.5f }; foreach (float num2 in array2) { Block(transform, "OakCorner", new Vector3(num, val2.y * 0.5f, num2), new Vector3(0.13f, val2.y + 0.12f, 0.13f), palette[4]); } } array = new float[2] { 0.04f, val2.y }; foreach (float num3 in array) { float[] array2 = new float[2] { (0f - val2.z) * 0.5f, val2.z * 0.5f }; foreach (float num4 in array2) { Block(transform, "OakCrossRail", new Vector3(0f, num3, num4), new Vector3(val2.x + 0.15f, 0.13f, 0.13f), palette[4]); } array2 = new float[2] { (0f - val2.x) * 0.5f, val2.x * 0.5f }; foreach (float num5 in array2) { Block(transform, "OakSideRail", new Vector3(num5, num3, 0f), new Vector3(0.13f, 0.13f, val2.z + 0.15f), palette[4]); } } if (i != 0) { Block(transform, "RaisedTimberFloor", new Vector3(0f, 0.025f, 0f), new Vector3(val2.x, 0.05f, val2.z), palette[4]); BoxCollider obj = ((Component)transform).gameObject.AddComponent<BoxCollider>(); obj.center = new Vector3(0f, 0.025f, 0f); obj.size = new Vector3(val2.x, 0.05f, val2.z); } airshipAnimalCages.solids[i] = ((Component)transform).GetComponentsInChildren<Collider>(true); airshipAnimalCages.controls[i * 2] = CreateControl(model, transport, i, "MA_AnimalCageHandle" + i, AirshipAnimalCageLayout.Handle(i), palette); airshipAnimalCages.controls[i * 2 + 1] = CreateControl(model, transport, i, "MA_AnimalHelmConsole" + i, AirshipAnimalCageLayout.HelmConsole(i), palette); ((Component)transform).gameObject.SetActive(false); } airshipAnimalCages.Apply(); return airshipAnimalCages; } finally { if (Object.op_Implicit((Object)(object)val)) { Object.Destroy((Object)(object)((Component)val).gameObject); } } } private static BoxCollider PanelWall(Transform parent, Transform ironTemplate, Bounds ironBounds, string role, Vector3 center, Quaternion rotation, float width, float height, bool solid = true) { //IL_000b: 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_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_006c: 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_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0122: 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) Transform transform = new GameObject("MA_Cage_" + role).transform; transform.SetParent(parent, false); transform.localPosition = center; transform.localRotation = rotation; int num = Mathf.CeilToInt(width / 2f); int num2 = Mathf.CeilToInt(height / 2f); float num3 = width / (float)num; float num4 = height / (float)num2; for (int i = 0; i < num; i++) { for (int j = 0; j < num2; j++) { Transform transform2 = new GameObject("IronGrid").transform; transform2.SetParent(transform, false); transform2.localPosition = new Vector3((0f - width) * 0.5f + ((float)i + 0.5f) * num3, (0f - height) * 0.5f + ((float)j + 0.5f) * num4, 0f); Transform transform3 = Object.Instantiate<GameObject>(((Component)ironTemplate).gameObject, transform2, false).transform; ((Object)transform3).name = "NativeIronWall"; transform3.localPosition = -((Bounds)(ref ironBounds)).center; transform3.localRotation = Quaternion.identity; transform3.localScale = Vector3.one; ((Component)transform3).gameObject.SetActive(true); transform2.localScale = new Vector3(num3 / ((Bounds)(ref ironBounds)).size.x, num4 / ((Bounds)(ref ironBounds)).size.y, 1f); } } if (!solid) { return null; } ((Component)transform).gameObject.layer = LayerMask.NameToLayer("piece"); BoxCollider obj = ((Component)transform).gameObject.AddComponent<BoxCollider>(); obj.size = new Vector3(width, height, 0.1f); ((Collider)obj).enabled = false; return obj; } internal static Bounds LocalMeshBounds(Transform root) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_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_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) //IL_00ab: 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_009b: Unknown result type (might be due to invalid IL or missing references) Bounds result = default(Bounds); bool flag = true; MeshFilter[] componentsInChildren = ((Component)root).GetComponentsInChildren<MeshFilter>(true); foreach (MeshFilter val in componentsInChildren) { if (!Object.op_Implicit((Object)(object)val.sharedMesh)) { continue; } Bounds bounds = val.sharedMesh.bounds; Matrix4x4 val2 = root.worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix; for (int j = -1; j <= 1; j += 2) { for (int k = -1; k <= 1; k += 2) { for (int l = -1; l <= 1; l += 2) { Vector3 val3 = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)j, (float)k, (float)l))); if (flag) { ((Bounds)(ref result))..ctor(val3, Vector3.zero); flag = false; } else { ((Bounds)(ref result)).Encapsulate(val3); } } } } } if (flag || ((Bounds)(ref result)).size.x < 0.01f || ((Bounds)(ref result)).size.y < 0.01f) { throw new InvalidOperationException("Native cage grid has no mesh"); } return result; } private static void Block(Transform parent, string name, Vector3 position, Vector3 size, Material material) { //IL_0020: 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) GameObject obj = GameObject.CreatePrimitive((PrimitiveType)3); ((Object)obj).name = name; obj.transform.SetParent(parent, false); obj.transform.localPosition = position; obj.transform.localScale = size; Collider component = obj.GetComponent<Collider>(); component.enabled = false; Object.Destroy((Object)(object)component); ((Renderer)obj.GetComponent<MeshRenderer>()).sharedMaterial = material; } private static Collider CreateControl(Transform model, AirshipAnimalTransport transport, int slot, string name, Vector3 position, Material[] palette) { //IL_0001: 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_004c: 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_0077: 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_00c2: Unknown result type (might be due to invalid IL or missing references) Transform transform = new GameObject(name).transform; transform.SetParent(model, false); transform.localPosition = position; ((Component)transform).gameObject.layer = LayerMask.NameToLayer("piece_nonsolid"); BoxCollider val = ((Component)transform).gameObject.AddComponent<BoxCollider>(); val.size = new Vector3(0.32f, 0.28f, 0.16f); ((Collider)val).enabled = false; Block(transform, "WoodPlate", Vector3.zero, new Vector3(0.32f, 0.28f, 0.08f), palette[4]); Block(transform, (slot == 0) ? "LargeIronLatch" : "SmallIronLatch", new Vector3(0f, 0f, 0.065f), new Vector3((slot == 0) ? 0.2f : 0.12f, 0.075f, 0.05f), palette[8]); AirshipAnimalCageHandle airshipAnimalCageHandle = ((Component)transform).gameObject.AddComponent<AirshipAnimalCageHandle>(); airshipAnimalCageHandle.Transport = transport; airshipAnimalCageHandle.Slot = slot; return (Collider)(object)val; } private void Update() { Apply(); Player localPlayer = Player.m_localPlayer; if (Object.op_Implicit((Object)(object)localPlayer) && Object.op_Implicit((Object)(object)transport) && transport.Live && !InventoryGui.IsVisible() && !AirshipBunker.BlocksInput && !TextInput.IsVisible() && !Menu.IsVisible() && !Console.IsVisible() && (!Object.op_Implicit((Object)(object)Chat.instance) || !Chat.instance.HasFocus()) && ShortcutDown() && AtHelm(localPlayer)) { int slot = ((Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307)) ? 1 : 0); transport.Request(localPlayer, slot); } } private bool AtHelm(Player player) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) Ship component = ((Component)transport.ShipRoot).GetComponent<Ship>(); if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component.m_shipControlls) || !AirshipHelmArea.OnPhysicalDeck(component, player)) { return false; } Vector3 position = component.m_shipControlls.m_attachPoint.position; if (Vector3.Distance(((Component)player).transform.position, position) > 2.5f) { return false; } if ((object)player.GetDoodadController() == component.m_shipControlls) { return true; } GameObject val = GameAccess.Read<GameObject>(player, "m_hovering"); if (Object.op_Implicit((Object)(object)val)) { if (!Object.op_Implicit((Object)(object)val.GetComponentInParent<AirshipHelmHatch>())) { return Object.op_Implicit((Object)(object)val.GetComponentInParent<ShipControlls>()); } return true; } return false; } private void Apply() { //IL_003f: 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_027c: Unknown result type (might be due to invalid IL or missing references) //IL_0281: 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_0136: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) bool flag = Object.op_Implicit((Object)(object)transport) && transport.Live; ZDOID val; for (int i = 0; i < cages.Length; i++) { if (!Object.op_Implicit((Object)(object)cages[i])) { continue; } int num; if (flag) { val = transport.Occupant(i); num = ((!((ZDOID)(ref val)).IsNone()) ? 1 : 0); } else { num = 0; } bool flag2 = (byte)num != 0; bool flag3 = flag2 || (Plugin.HideEmptyCages != null && !Plugin.HideEmptyCages.Value); if (((Component)cages[i]).gameObject.activeSelf != flag3) { ((Component)cages[i]).gameObject.SetActive(flag3); } bool flag4 = flag && flag3; Collider[] array = solids[i]; foreach (Collider val2 in array) { if (Object.op_Implicit((Object)(object)val2) && (Object)(object)val2 != (Object)(object)gateBoxes[i] && val2.enabled != flag4) { val2.enabled = flag4; } } float num2 = ((!flag2) ? (-90) : 0); float num3 = Mathf.MoveTowardsAngle(gates[i].localEulerAngles.y, num2, 180f * Time.deltaTime); gates[i].localRotation = Quaternion.Euler(0f, num3, 0f); bool flag5 = flag && flag3 && Mathf.Abs(Mathf.DeltaAngle(num3, num2)) < 0.05f; if (flag5 && !((Collider)gateBoxes[i]).enabled) { foreach (Player allPlayer in Player.GetAllPlayers()) { CapsuleCollider val3 = (Object.op_Implicit((Object)(object)allPlayer) ? ((Component)allPlayer).GetComponent<CapsuleCollider>() : null); if (Object.op_Implicit((Object)(object)val3)) { Bounds val4 = PhysicalBounds(gateBoxes[i]); if (((Bounds)(ref val4)).Intersects(CaravanMovingParts.CapsuleBounds(val3))) { flag5 = false; break; } } } } if (((Collider)gateBoxes[i]).enabled != flag5) { ((Collider)gateBoxes[i]).enabled = flag5; } for (int k = i * 2; k < i * 2 + 2; k++) { if (Object.op_Implicit((Object)(object)controls[k]) && controls[k].enabled != flag) { controls[k].enabled = flag; } } } if (Object.op_Implicit((Object)(object)well)) { AirshipAnimalWellGeometry airshipAnimalWellGeometry = well; int open; if (flag) { val = transport.Occupant(0); open = ((!((ZDOID)(ref val)).IsNone()) ? 1 : 0); } else { open = 0; } airshipAnimalWellGeometry.SetOpen((byte)open != 0); } } private static Bounds PhysicalBounds(BoxCollider box) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) Matrix4x4 localToWorldMatrix = ((Component)box).transform.localToWorldMatrix; Bounds result = default(Bounds); ((Bounds)(ref result))..ctor(((Matrix4x4)(ref localToWorldMatrix)).MultiplyPoint3x4(box.center), Vector3.zero); for (int i = -1; i <= 1; i += 2) { for (int j = -1; j <= 1; j += 2) { for (int k = -1; k <= 1; k += 2) { ((Bounds)(ref result)).Encapsulate(((Matrix4x4)(ref localToWorldMatrix)).MultiplyPoint3x4(box.center + Vector3.Scale(box.size * 0.5f, new Vector3((float)i, (float)j, (float)k)))); } } } return result; } private static bool ShortcutDown() { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0016: 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_003d: Unknown result type (might be due to invalid IL or missing references) if (Plugin.AnimalTransportKey == null) { return false; } KeyboardShortcut value = Plugin.AnimalTransportKey.Value; if ((int)((KeyboardShortcut)(ref value)).MainKey == 0 || !Input.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey)) { return false; } foreach (KeyCode modifier in ((KeyboardShortcut)(ref value)).Modifiers) { if (!Input.GetKey(modifier)) { return false; } } return true; } } internal sealed class AirshipAnimalCageHandle : MonoBehaviour, Hoverable, Interactable { internal AirshipAnimalTransport Transport; internal int Slot; public string GetHoverName() { if (Slot != 0) { return "Малая клетка"; } return "Большая клетка"; } public string GetHoverText() { if (!Object.op_Implicit((Object)(object)Transport)) { return GetHoverName(); } return Transport.Hover(Slot); } public float GetHoverOffset() { return 0f; } public bool Interact(Humanoid user, bool hold, bool alt) { if (!hold && Object.op_Implicit((Object)(object)Transport)) { return Transport.Request((Player)(object)((user is Player) ? user : null), Slot); } return false; } public bool UseItem(Humanoid user, ItemData item) { return false; } } internal sealed class AirshipAnimalPassenger : MonoBehaviour { private Character animal; private ZNetView view; private Rigidbody body; private BaseAI ai; private ZSyncTransform sync; private bool registered; private bool prepared; private bool originalAi; private bool originalGravity; private bool originalKinematic; private bool originalDisableSleeping; private bool originalSyncGravity; private bool originalParentSync; private RigidbodyInterpolation originalInterpolation; private readonly Dictionary<Collider, bool> colliders = new Dictionary<Collider, bool>(); private ZDOMan subscribed; private Vector3 lastShipVelocity; private ZDOID destroyedShip = ZDOID.None; private bool lastOwner; private ZDO Data => view.GetZDO(); internal bool Bound { get { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)view) && view.IsValid()) { ZDOID zDOID = Data.GetZDOID("ma_animal_ship"); return !((ZDOID)(ref zDOID)).IsNone(); } return false; } } internal ZDOID BoundShip { get { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) if (!Bound) { return ZDOID.None; } return Data.GetZDOID("ma_animal_ship"); } } internal int BoundSlot { get { if (!Bound) { return -1; } return Data.GetInt("ma_animal_slot", -1); } } internal static AirshipAnimalPassenger Ensure(Character character) { if (!Object.op_Implicit((Object)(object)character) || character.IsPlayer() || !Object.op_Implicit((Object)(object)((Component)character).GetComponent<Tameable>())) { return null; } AirshipAnimalPassenger airshipAnimalPassenger = ((Component)character).GetComponent<AirshipAnimalPassenger>(); if (!Object.op_Implicit((Object)(object)airshipAnimalPassenger)) { airshipAnimalPassenger = ((Component)character).gameObject.AddComponent<AirshipAnimalPassenger>(); } airshipAnimalPassenger.Initialize(); return airshipAnimalPassenger; } private void Awake() { Initialize(); } private bool Initialize() { if (!Object.op_Implicit((Object)(object)animal)) { animal = ((Component)this).GetComponent<Character>(); view = ((Component)this).GetComponent<ZNetView>(); body = ((Component)this).GetComponent<Rigidbody>(); ai = ((Component)this).GetComponent<BaseAI>(); sync = ((Component)this).GetComponent<ZSyncTransform>(); if (Object.op_Implicit((Object)(object)animal)) { Character obj = animal; obj.m_onDeath = (Action)Delegate.Combine(obj.m_onDeath, new Action(OnDeath)); } } if (!Object.op_Implicit((Object)(object)animal) || !Object.op_Implicit((Object)(object)view) || !view.IsValid() || !Object.op_Implicit((Object)(object)body)) { return false; } if (!registered) { view.Register<ZDOID, int, int>("MA_AnimalCagePassenger", (Action<long, ZDOID, int, int>)OnRequest); registered = true; } if (subscribed != ZDOMan.instance) { if (subscribed != null) { ZDOMan obj2 = subscribed; obj2.m_onZDODestroyed = (Action<ZDO>)Delegate.Remove(obj2.m_onZDODestroyed, new Action<ZDO>(OnZdoDestroyed)); } subscribed = ZDOMan.instance; if (subscribed != null) { ZDOMan obj3 = subscribed; obj3.m_onZDODestroyed = (Action<ZDO>)Delegate.Combine(obj3.m_onZDODestroyed, new Action<ZDO>(OnZdoDestroyed)); } } return true; } private void Update() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_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_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_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) if (!Initialize()) { return; } if (Bound && BoundShip == destroyedShip) { if (view.IsOwner()) { ReleaseOwner(move: false, Vector3.zero, Quaternion.identity); } else if (prepared) { RestoreRuntime(move: false, Vector3.zero, Quaternion.identity); } } else if (Bound && !animal.IsDead()) { Prepare(); } else if (prepared) { RestoreRuntime(move: false, Vector3.zero, Quaternion.identity); } } private void FixedUpdate() { ApplyPose(rendered: false); } private void LateUpdate() { ApplyPose(rendered: true); } private void OnRequest(long sender, ZDOID shipId, int slot, int operation) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: 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_006a: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0108: 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_0112: 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_0131: 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_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) if (!Initialize() || !view.IsOwner()) { return; } AirshipAnimalTransport airshipAnimalTransport = AirshipAnimalTransport.Find(shipId); if (!Object.op_Implicit((Object)(object)airshipAnimalTransport) || !airshipAnimalTransport.MatchingReservation(sender, Data.m_uid, slot, operation)) { return; } int num = airshipAnimalTransport.PendingAction(slot); if (num == 1 && BoundShip == shipId && BoundSlot == slot) { airshipAnimalTransport.Acknowledge(slot, operation, Data.m_uid, success: true, ""); return; } if (num == 2 && !Bound) { airshipAnimalTransport.Acknowledge(slot, operation, Data.m_uid, success: true, ""); return; } if (!airshipAnimalTransport.AuthorizePassenger(sender, animal, slot, operation, out var action, out var localPosition, out var reason)) { airshipAnimalTransport.Acknowledge(slot, operation, Data.m_uid, success: false, reason); return; } if (action == 1) { Vector3 val = airshipAnimalTransport.ShipRoot.InverseTransformPoint(airshipAnimalTransport.Model.TransformPoint(localPosition)); Quaternion val2 = Quaternion.Inverse(airshipAnimalTransport.ShipRoot.rotation) * airshipAnimalTransport.Model.rotation; Data.Set("ma_animal_local_position", val); Data.Set("ma_animal_local_rotation", val2); Data.Set("ma_animal_slot", slot); Data.Set("ma_animal_operation", operation); Data.Set("ma_animal_ship", shipId); Prepare(); ApplyPose(rendered: false); if (Object.op_Implicit((Object)(object)sync)) { sync.SyncNow(); } } else { if (!airshipAnimalTransport.TryReleasePoint(animal, slot, out var position, out var rotation, out reason)) { airshipAnimalTransport.Acknowledge(slot, operation, Data.m_uid, success: false, reason); return; } ReleaseOwner(move: true, position, rotation); if (Object.op_Implicit((Object)(object)sync)) { sync.SyncNow(); } } airshipAnimalTransport.Acknowledge(slot, operation, Data.m_uid, success: true, (action == 1) ? "Животное размещено в клетке" : "Животное выпущено на землю"); } private void Prepare() { //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) if (!prepared && Bound && Object.op_Implicit((Object)(object)body)) { originalGravity = body.useGravity; originalKinematic = body.isKinematic; originalInterpolation = body.interpolation; originalDisableSleeping = animal.m_disableWhileSleeping; originalAi = Object.op_Implicit((Object)(object)ai) && ((Behaviour)ai).enabled; if (Object.op_Implicit((Object)(object)sync)) { originalSyncGravity = GameAccess.Read<bool>(sync, "m_useGravity"); originalParentSync = sync.m_characterParentSync; GameAccess.Write(sync, "m_useGravity", false); sync.m_characterParentSync = true; } colliders.Clear(); Collider[] componentsInChildren = ((Component)animal).GetComponentsInChildren<Collider>(true); foreach (Collider val in componentsInChildren) { colliders[val] = val.enabled; val.enabled = false; } if (Object.op_Implicit((Object)(object)ai)) { ai.StopMoving(); ((Behaviour)ai).enabled = false; } animal.SetMoveDir(Vector3.zero); animal.m_disableWhileSleeping = false; if (!body.isKinematic) { body.linearVelocity = Vector3.zero; body.angularVelocity = Vector3.zero; } body.useGravity = false; body.isKinematic = true; body.interpolation = (RigidbodyInterpolation)0; lastOwner = view.IsOwner(); prepared = true; ResetGround(); IdleAnimation(); } } private void ApplyPose(bool rendered) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: 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_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: 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_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_00be: 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_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) if (!Initialize() || !Bound || BoundShip == destroyedShip) { return; } if (animal.IsDead()) { if (view.IsOwner()) { ReleaseOwner(move: false, Vector3.zero, Quaternion.identity); } return; } Prepare(); ZDOID boundShip = BoundShip; GameObject val = (Object.op_Implicit((Object)(object)ZNetScene.instance) ? ZNetScene.instance.FindInstance(boundShip) : null); ZDO val2 = ((ZDOMan.instance != null) ? ZDOMan.instance.GetZDO(boundShip) : null); if (!Object.op_Implicit((Object)(object)val) && val2 == null) { if (Object.op_Implicit((Object)(object)ZNet.instance) && ZNet.instance.IsServer() && Time.timeSinceLevelLoad > 15f) { destroyedShip = boundShip; if (view.IsOwner()) { ReleaseOwner(move: false, Vector3.zero, Quaternion.identity); } } return; } Vector3 vec = Data.GetVec3("ma_animal_local_position", Vector3.zero); Quaternion quaternion = Data.GetQuaternion("ma_animal_local_rotation", Quaternion.identity); Vector3 val3; Quaternion val4; if (Object.op_Implicit((Object)(object)val)) { val3 = val.transform.TransformPoint(vec); val4 = val.transform.rotation * quaternion; Rigidbody component = val.GetComponent<Rigidbody>(); if (Object.op_Implicit((Object)(object)component)) { lastShipVelocity = component.GetPointVelocity(val3); } } else { val3 = val2.GetPosition() + val2.GetRotation() * vec; val4 = val2.GetRotation() * quaternion; } body.isKinematic = true; body.useGravity = false; if (rendered) { ((Component)animal).transform.SetPositionAndRotation(val3, val4); } else { body.position = val3; body.rotation = val4; ((Component)animal).transform.SetPositionAndRotation(val3, val4); } if (view.IsOwner() != lastOwner) { lastOwner = view.IsOwner(); if (lastOwner) { IdleAnimation(); } } } internal bool SuppressMotion() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) if (!Initialize() || !Bound || BoundShip == destroyedShip || animal.IsDead()) { return false; } Prepare(); ApplyPose(rendered: false); animal.SetMoveDir(Vector3.zero); IdleAnimation(); return true; } private void IdleAnimation() { if (Object.op_Implicit((Object)(object)view) && view.IsValid() && view.IsOwner()) { ZSyncAnimation component = ((Component)animal).GetComponent<ZSyncAnimation>(); if (Object.op_Implicit((Object)(object)component)) { component.SetFloat("forward_speed", 0f); component.SetFloat("sideway_speed", 0f); component.SetFloat("turn_speed", 0f); component.SetBool("onGround", true); component.SetBool("inWater", false); } } } private void ReleaseOwner(bool move, Vector3 position, Quaternion rotation) { //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_0044: 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_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0075: 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_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_0108: 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_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)view) || !view.IsValid() || !view.IsOwner()) { return; } ZDOID zDOID = Data.GetZDOID("ma_animal_ship"); Data.Set("ma_animal_ship", ZDOID.None); Data.Set("ma_animal_slot", -1); ZDOID connectionZDOID = Data.GetConnectionZDOID((ConnectionType)2); bool flag = !((ZDOID)(ref zDOID)).IsNone() && connectionZDOID == zDOID; if (flag) { Data.UpdateConnection((ConnectionType)2, ZDOID.None); Data.Set(ZDOVars.s_attachJointHash, ""); } if (Object.op_Implicit((Object)(object)sync)) { if (!((ZDOID)(ref zDOID)).IsNone() && GameAccess.Read<ZDOID>(sync, "m_tempParent") == zDOID) { GameAccess.Write(sync, "m_tempParent", ZDOID.None); } if (!((ZDOID)(ref zDOID)).IsNone() && GameAccess.Read<ZDOID>(sync, "m_tempParentCached") == zDOID) { GameAccess.Write(sync, "m_tempParentCached", ZDOID.None); } if (flag || ((ZDOID)(ref connectionZDOID)).IsNone()) { GameAccess.Write(sync, "m_haveTempRelPos", false); } } RestoreRuntime(move, position, rotation); } private void RestoreRuntime(bool move, Vector3 position, Quaternion rotation) { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0040: 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_009d: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) if (!prepared) { return; } if (Object.op_Implicit((Object)(object)body)) { if (move) { body.position = position; body.rotation = rotation; ((Component)animal).transform.SetPositionAndRotation(position, rotation); } body.isKinematic = originalKinematic; body.useGravity = originalGravity; body.interpolation = originalInterpolation; if (!body.isKinematic) { body.linearVelocity = lastShipVelocity; body.angularVelocity = Vector3.zero; } } foreach (KeyValuePair<Collider, bool> collider in colliders) { if (Object.op_Implicit((Object)(object)collider.Key)) { collider.Key.enabled = collider.Value; } } colliders.Clear(); if (Object.op_Implicit((Object)(object)ai)) { ((Behaviour)ai).enabled = originalAi; } if (move && Object.op_Implicit((Object)(object)ai) && Object.op_Implicit((Object)(object)view) && view.IsValid() && view.IsOwner()) { BaseAI obj = ai; MonsterAI val = (MonsterAI)(object)((obj is MonsterAI) ? obj : null); if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.GetFollowTarget())) { ai.SetPatrolPoint(); } } if (Object.op_Implicit((Object)(object)animal)) { animal.m_disableWhileSleeping = originalDisableSleeping; animal.SetMoveDir(Vector3.zero); ResetGround(); } if (Object.op_Implicit((Object)(object)sync)) { GameAccess.Write(sync, "m_useGravity", originalSyncGravity); sync.m_characterParentSync = originalParentSync; } prepared = false; Physics.SyncTransforms(); } private void ResetGround() { //IL_0071: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)animal)) { GameAccess.Write(animal, "m_lastAttachBody", null); GameAccess.Write(animal, "m_lastGroundBody", null); GameAccess.Write(animal, "m_lastGroundCollider", null); GameAccess.Write(animal, "m_lastGroundTouch", 999f); GameAccess.Write(animal, "m_maxAirAltitude", ((Component)animal).transform.position.y); GameAccess.Write(animal, "m_fallTimer", 0f); AccessTools.Method(typeof(Character), "ResetGroundContact", (Type[])null, (Type[])null).Invoke(animal, null); } } internal bool RelativePosition(out ZDOID parent, out string joint, out Vector3 position, out Quaternion rotation, out Vector3 velocity) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_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_0072: Unknown result type (might be due to invalid IL or missing references) parent = BoundShip; joint = ""; position = Vector3.zero; rotation = Quaternion.identity; velocity = Vector3.zero; if (((ZDOID)(ref parent)).IsNone()) { return false; } position = Data.GetVec3("ma_animal_local_position", Vector3.zero); rotation = Data.GetQuaternion("ma_animal_local_rotation", Quaternion.identity); return true; } private void OnDeath() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) if (Bound && view.IsOwner()) { ReleaseOwner(move: false, Vector3.zero, Quaternion.identity); } } private void OnZdoDestroyed(ZDO destroyed) { //IL_0009: 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_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_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_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) if (Bound && destroyed.m_uid == BoundShip) { destroyedShip = BoundShip; if (view.IsOwner()) { ReleaseOwner(move: false, Vector3.zero, Quaternion.identity); } else { RestoreRuntime(move: false, Vector3.zero, Quaternion.identity); } } } private void OnDestroy() { //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) if (subscribed != null) { ZDOMan obj = subscribed; obj.m_onZDODestroyed = (Action<ZDO>)Delegate.Remove(obj.m_onZDODestroyed, new Action<ZDO>(OnZdoDestroyed)); } if (Object.op_Implicit((Object)(object)animal)) { Character obj2 = animal; obj2.m_onDeath = (Action)Delegate.Remove(obj2.m_onDeath, new Action(OnDeath)); } RestoreRuntime(move: false, Vector3.zero, Quaternion.identity); } } [HarmonyPatch(typeof(Character), "Awake")] internal static class AirshipAnimalPassengerAwakePatch { private static void Postfix(Character __instance) { AirshipAnimalPassenger.Ensure(__instance); } } [HarmonyPatch(typeof(Character), "UpdateMotion")] internal static class AirshipAnimalPassengerMotionPatch { private static bool Prefix(Character __instance) { AirshipAnimalPassenger component = ((Component)__instance).GetComponent<AirshipAnimalPassenger>(); if (Object.op_Implicit((Object)(object)component)) { return !component.SuppressMotion(); } return true; } } [HarmonyPatch(typeof(Character), "GetRelativePosition")] internal static class AirshipAnimalPassengerRelativePatch { private static bool Prefix(Character __instance, ref ZDOID parent, ref string attachJoint, ref Vector3 relativePos, ref Quaternion relativeRot, ref Vector3 relativeVel, ref bool __result) { AirshipAnimalPassenger component = ((Component)__instance).GetComponent<AirshipAnimalPassenger>(); if (!Object.op_Implicit((Object)(object)component) || !component.RelativePosition(out parent, out attachJoint, out relativePos, out relativeRot, out relativeVel)) { return true; } __result = true; return false; } } [HarmonyPatch(typeof(Growup), "GrowUpdate")] internal static class AirshipAnimalPassengerGrowupPatch { private static bool Prefix(Growup __instance) { AirshipAnimalPassenger component = ((Component)__instance).GetComponent<AirshipAnimalPassenger>(); if (Object.op_Implicit((Object)(object)component)) { return !component.Bound; } return true; } } [HarmonyPatch(typeof(Procreation), "Procreate")] internal static class AirshipAnimalPassengerProcreationPatch { private static bool Prefix(Procreation __instance) { AirshipAnimalPassenger component = ((Component)__instance).GetComponent<AirshipAnimalPassenger>(); if (Object.op_Implicit((Object)(object)component)) { return !component.Bound; } return true; } } internal sealed class AirshipAnimalTransport : MonoBehaviour { internal const string AnimalShipKey = "ma_animal_ship"; internal const string AnimalSlotKey = "ma_animal_slot"; internal const string AnimalPositionKey = "ma_animal_local_position"; internal const string AnimalRotationKey = "ma_animal_local_rotation"; internal const string AnimalOperationKey = "ma_animal_operation"; internal const string AnimalRpc = "MA_AnimalCagePassenger"; private const string RequestRpc = "MA_AnimalCageRequest"; private const string NoticeRpc = "MA_AnimalCageNotice"; private const string AckRpc = "MA_AnimalCageAck"; private Transform model; private Transform shipRoot; private ZNetView view; private Rigidbody body; private bool registered; private float reconcileAt; private float lastRequestAt; private readonly float[] retryAt = new float[2]; private readonly HashSet<ZDOID> countedPayloadIds = new HashSet<ZDOID>(); private static readonly string[] OccupantKeys = Keys("ma_animal_occupant_"); private static readonly string[] PendingKeys = Keys("ma_animal_pending_"); private static readonly string[] OperationKeys = Keys("ma_animal_request_"); private static readonly string[] MassKeys = Keys("ma_animal_mass_"); private static readonly string[] OperatorKeys = Keys("ma_animal_operator_"); private static readonly string[] PlayerKeys = Keys("ma_animal_player_"); private ZDOMan subscribed; private ZDO Data => view.GetZDO(); internal Transform Model => model; internal Transform ShipRoot => shipRoot; internal ZNetView View => view; internal bool Live { get { if (Object.op_Implicit((Object)(object)view)) { return view.IsValid(); } return false; } } internal bool HasAnimals { get { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < 2; i++) { ZDOID val = Occupant(i); if (!((ZDOID)(ref val)).IsNone()) { return true; } } return false; } } internal bool Stopped { get { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)body)) { Vector3 val = body.linearVelocity; if (((Vector3)(ref val)).magnitude < 0.5f) { val = body.angularVelocity; return ((Vector3)(ref val)).magnitude < 0.12f; } return false; } return true; } } private static string[] Keys(string prefix) { string[] array = new string[2]; for (int i = 0; i < array.Length; i++) { array[i] = prefix + i; } return array; } private static string Key(string[] keys, string prefix, int slot) { if (slot < 0 || slot >= keys.Length) { return prefix + slot; } return keys[slot]; } internal static string OccupantKey(int slot) { return Key(OccupantKeys, "ma_animal_occupant_", slot); } internal static string PendingKey(int slot) { return Key(PendingKeys, "ma_animal_pending_", slot); } internal static string OperationKey(int slot) { return Key(OperationKeys, "ma_animal_request_", slot); } internal static string MassKey(int slot) { return Key(MassKeys, "ma_animal_mass_", slot); } private static string OperatorKey(int slot) { return Key(OperatorKeys, "ma_animal_operator_", slot); } private static string PlayerKey(int slot) { return Key(PlayerKeys, "ma_animal_player_", slot); } internal static AirshipAnimalTransport Create(Transform model, Transform shipRoot) { AirshipAnimalTransport airshipAnimalTransport = ((Component)model).GetComponent<AirshipAnimalTransport>(); if (!Object.op_Implicit((Object)(object)airshipAnimalTransport)) { airshipAnimalTransport = ((Component)model).gameObject.AddComponent<AirshipAnimalTransport>(); } airshipAnimalTransport.model = model; airshipAnimalTransport.shipRoot = shipRoot; airshipAnimalTransport.view = ((Component)shipRoot).GetComponent<ZNetView>(); airshipAnimalTransport.body = ((Component)shipRoot).GetComponent<Rigidbody>(); airshipAnimalTransport.Initialize(); return airshipAnimalTransport; } internal static AirshipAnimalTransport Find(ZDOID id) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) GameObject val = (Object.op_Implicit((Object)(object)ZNetScene.instance) ? ZNetScene.instance.FindInstance(id) : null); if (!Object.op_Implicit((Object)(object)val)) { return null; } return val.GetComponentInChildren<AirshipAnimalTransport>(true); } private bool Initialize() { if (!Live) { return false; } if (!registered) { view.Register<int, long>("MA_AnimalCageRequest", (Action<long, int, long>)OnRequest); view.Register<int, int, ZDOID, bool, string>("MA_AnimalCageAck", (Method<int, int, ZDOID, bool, string>)OnAck); view.Register<string>("MA_AnimalCageNotice", (Action<long, string>)OnNotice); registered = true; } if (subscribed != ZDOMan.instance) { if (subscribed != null) { ZDOMan obj = subscribed; obj.m_onZDODestroyed = (Action<ZDO>)Delegate.Remove(obj.m_onZDODestroyed, new Action<ZDO>(OnZdoDestroyed)); } subscribed = ZDOMan.instance; if (subscribed != null) { ZDOMan obj2 = subscribed; obj2.m_onZDODestroyed = (Action<ZDO>)Delegate.Combine(obj2.m_onZDODestroyed, new Action<ZDO>(OnZdoDestroyed)); } } return true; } private void Update() { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) if (!Initialize() || !view.IsOwner() || Time.time < reconcileAt) { return; } reconcileAt = Time.time + 0.25f; for (int i = 0; i < 2; i++) { ZDOID val = Occupant(i); if (((ZDOID)(ref val)).IsNone()) { continue; } Character val2 = LoadedAnimal(i); ZDO zDO = ZDOMan.instance.GetZDO(val); if (Object.op_Implicit((Object)(object)val2) && val2.IsDead()) { ClearSlot(i); continue; } if (zDO == null) { if (Object.op_Implicit((Object)(object)ZNet.instance) && ZNet.instance.IsServer() && Time.timeSinceLevelLoad > 15f) { ClearSlot(i); } continue; } bool flag = zDO.GetZDOID("ma_animal_ship") == Data.m_uid && zDO.GetInt("ma_animal_slot", -1) == i; if (flag && Object.op_Implicit((Object)(object)val2)) { Data.Set(MassKey(i), (float)MassOf(val2)); } int num = Data.GetInt(PendingKey(i), 0); if (num == 1 && flag) { Complete(i, success: true, "Животное размещено в клетке"); } else if (num == 2 && !flag) { Complete(i, success: true, "Животное выпущено на землю"); } else if (num == 0 && !flag) { ClearSlot(i); } else if (num != 0 && Time.time >= retryAt[i]) { SendPassengerRequest(i); } } } internal ZDOID Occupant(int slot) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) if (!Live || !ValidSlot(slot)) { return ZDOID.None; } return Data.GetZDOID(OccupantKey(slot)); } internal Character LoadedAnimal(int slot) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) ZDOID val = Occupant(slot); GameObject val2 = ((!((ZDOID)(ref val)).IsNone() && Object.op_Implicit((Object)(object)ZNetScene.instance)) ? ZNetScene.instance.FindInstance(val) : null); if (!Object.op_Implicit((Object)(object)val2)) { return null; } return val2.GetComponent<Character>(); } internal bool Busy(int slot) { if (Live && ValidSlot(slot)) { return Data.GetInt(PendingKey(slot), 0) != 0; } return false; } internal string Hover(int slot) { //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_008f: 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) if (!ValidSlot(slot)) { return "Клетка"; } string text = ((slot == 0) ? "Большая клетка" : ("Клетка " + (slot + 1))); if (Busy(slot)) { return text + "\nОжидание владельца животного"; } Character val = LoadedAnimal(slot); Localization instance = Localization.instance; ZDOID val2; object obj; if (!Object.op_Implicit((Object)(object)val)) { val2 = Occupant(slot); obj = ((!((ZDOID)(ref val2)).IsNone()) ? " · занята" : " · свободна"); } else { obj = " · " + val.GetHoverName(); } val2 = Occupant(slot); return instance.Localize(text + (string?)obj + "\n[<color=yellow><b>$KEY_Use</b></color>] " + (((ZDOID)(ref val2)).IsNone() ? "Поместить животное" : "Выпустить на землю")); } internal bool Request(Player player, int slot) { if (!Object.op_Implicit((Object)(object)player) || (Object)(object)player != (Object)(object)Player.m_localPlayer || !Initialize() || !ValidSlot(slot) || !NearControl(player, slot)) { return false; } view.InvokeRPC("MA_AnimalCageRequest", new object[2] { slot, player.GetPlayerID() }); return true; } private static bool ValidSlot(int slot) { if (slot >= 0) { return slot < 2; } return false; } private bool NearControl(Player player, int slot) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_005e: 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_006e: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)player) || ((Character)player).IsDead() || ((Character)player).IsTeleporting()) { return false; } if (Vector3.Distance(((Component)player).transform.position, model.TransformPoint(AirshipAnimalCageLayout.Handle(slot))) < 4f) { return true; } Ship component = ((Component)shipRoot).GetComponent<Ship>(); if (Object.op_Implicit((Object)(object)component) && Vector3.Distance(((Component)player).transform.position, model.TransformPoint(CaravanLayout.HelmStanding)) < 2.5f) { return AirshipHelmArea.OnPhysicalDeck(component, player); } return false; } private void OnRequest(long sender, int slot, long playerId) { //IL_007c: 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_00fd: Unknown result type (might be due to invalid IL or missing references) if (!Initialize() || !view.IsOwner() || !ValidSlot(slot)) { return; } Player player = GameAccess.PlayerForSender(sender, playerId); if (!NearControl(player, slot) || Time.time - lastRequestAt < 0.2f) { return; } lastRequestAt = Time.time; if (Busy(slot)) { Notice(sender, "Дождитесь завершения работы клетки"); return; } if (!Stopped) { Notice(sender, "Для работы с клеткой остановите корабль"); return; } ZDOID val = Occupant(slot); string reason; if (((ZDOID)(ref val)).IsNone()) { if (PlayerInside(slot)) { Notice(sender, "Освободите клетку перед посадкой животного"); return; } Character val2 = ChooseAnimal(player, slot, out reason); if (!Object.op_Implicit((Object)(object)val2)) { Notice(sender, reason); return; } if (OtherAnimalInside(slot, val2)) { Notice(sender, "Уберите другое животное из клетки"); return; } Data.Set(MassKey(slot), (float)MassOf(val2)); Data.Set(OccupantKey(slot), val2.GetZDOID()); Data.Set(PendingKey(slot), 1); } else { Character val2 = LoadedAnimal(slot); if (!Object.op_Implicit((Object)(object)val2)) { Notice(sender, "Дождитесь загрузки животного"); return; } if (!TryReleasePoint(val2, slot, out var _, out var _, out reason)) { Notice(sender, reason); return; } Data.Set(PendingKey(slot), 2); } int num = Data.GetInt(OperationKey(slot), 0) + 1; if (num <= 0) { num = 1; } Data.Set(OperationKey(slot), num); Data.Set(OperatorKey(slot), sender); Data.Set(PlayerKey(slot), playerId); SendPassengerRequest(slot); } private Character ChooseAnimal(Player player, int slot, out string reason) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0092: 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) Character val = null; float num = float.MaxValue; string text = null; bool flag = false; foreach (Character allCharacter in Character.GetAllCharacters()) { if (!Object.op_Implicit((Object)(object)allCharacter) || allCharacter.IsPlayer() || Vector3.Distance(((Component)allCharacter).transform.position, ((Component)player).transform.position) > 12f || !Eligible(allCharacter, out var reason2)) { continue; } flag = true; if (!TryFit(allCharacter, slot, out var _, out reason2)) { text = reason2; continue; } MonsterAI component = ((Component)allCharacter).GetComponent<MonsterAI>(); float num2 = Vector3.SqrMagnitude(((Component)allCharacter).transform.position - ((Component)player).transform.position) - (float)((Object.op_Implicit((Object)(object)component) && (Object)(object)component.GetFollowTarget() == (Object)(object)((Component)player).gameObject) ? 1000 : 0); if (num2 < num) { num = num2; val = allCharacter; } } reason = (Object.op_Implicit((Object)(object)val) ? null : ((flag && text != null) ? text : "Подведите приручённое животное ближе (до 12 м)")); return val; } internal static bool Eligible(Character animal, out string reason) { //IL_00ba: 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) reason = "Нужно живое приручённое животное"; if (!Object.op_Implicit((Object)(object)animal) || animal.IsPlayer() || animal.IsBoss() || animal.IsDead() || animal.GetHealth() <= 0f) { return false; } Tameable component = ((Component)animal).GetComponent<Tameable>(); ZNetView component2 = ((Component)animal).GetComponent<ZNetView>(); if (!Object.op_Implicit((Object)(object)component) || !component.IsTamed() || !Object.op_Implicit((Object)(object)component2) || !component2.IsValid()) { return false; } if (!component2.GetZDO().Persistent) { reason = "Это животное не сохраняется в мире; перевозка недоступна"; return false; } if (animal.HaveRider() || animal.IsRiding() || animal.IsAttached() || Object.op_Implicit((Object)(object)((Component)animal).transform.parent)) { reason = "Сначала освободите животное от всадника или крепления"; return false; } ZDOID zDOID = component2.GetZDO().GetZDOID("ma_animal_ship"); if (!((ZDOID)(ref zDOID)).IsNone()) { reason = "Это животное уже находится в клетке"; return false; } reason = null; return true; } internal bool PlayerInside(int slot) { //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_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_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_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_008a: 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_009b: Unknown result type (might be due to invalid IL or missing references) Bounds val = AirshipAnimalCageLayout.Interior(slot); ((Bounds)(ref val)).Expand(0.4f); foreach (Player allPlayer in Player.GetAllPlayers()) { if (Object.op_Implicit((Object)(object)allPlayer) && !((Character)allPlayer).IsDead()) { CapsuleCollider component = ((Component)allPlayer).GetComponent<CapsuleCollider>(); Bounds source = (Bounds)(Object.op_Implicit((Object)(object)component) ? CaravanMovingParts.CapsuleBounds(component) : new Bounds(((Component)allPlayer).transform.position + Vector3.up * 0.9f, new Vector3(1f, 1.8f, 1f))); if (((Bounds)(ref val)).Intersects(TransformBounds(model.worldToLocalMatrix, source))) { return true; } } } return false; } private bool OtherAnimalInside(int slot, Character loading) { //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_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) Bounds val = AirshipAnimalCageLayout.Interior(slot); foreach (Character allCharacter in Character.GetAllCharacters()) { if (Object.op_Implicit((Object)(object)allCharacter) && !((Object)(object)allCharacter == (Object)(object)loading) && !allCharacter.IsPlayer() && !allCharacter.IsDead()) { CapsuleCollider component = ((Component)allCharacter).GetComponent<CapsuleCollider>(); if (Object.op_Implicit((Object)(object)component) && ((Bounds)(ref val)).Intersects(TransformBounds(model.worldToLocalMatrix, CaravanMovingParts.CapsuleBounds(component)))) { return true; } } } return false; } internal bool TryFit(Character animal, int slot, out Vector3 localPosition, out string reason) { //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_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003c: 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_0050: 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_0070: 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_0090: 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_0102: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0142: 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_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) localPosition = Vector3.zero; reason = "Животное не помещается в эту клетку"; if (!ValidSlot(slot) || !AnimalBounds(animal, out var physical, out var visible)) { reason = "Не удалось проверить размеры животного"; return false; } Bounds pen = AirshipAnimalCageLayout.Interior(slot); Bounds all = physical; ((Bounds)(ref all)).Encapsulate(visible); if (((Bounds)(ref all)).size.x > ((Bounds)(ref pen)).size.x - 0.05f || ((Bounds)(ref all)).size.y > ((Bounds)(ref pen)).size.y - 0.05f || ((Bounds)(ref all)).size.z > ((Bounds)(ref pen)).size.z - 0.05f) { return false; } if (!BakedFoot(animal, out var minimum, out var vertexCount)) { minimum = ((Bounds)(ref physical)).min.y; Plugin.Log.LogWarning((object)("Animal cage foot probe unavailable for " + ((Object)animal).name + "; using the native capsule foot.")); } float num = AirshipAnimalCageLayout.Centers[slot].y + ((slot == 0) ? 0.015f : 0.065f); localPosition = new Vector3(((Bounds)(ref pen)).center.x - ((Bounds)(ref all)).center.x, num - minimum, ((Bounds)(ref pen)).center.z - ((Bounds)(ref all)).center.z); if (!Finite(localPosition)) { return false; } if (((Bounds)(ref all)).max.y + localPosition.y > ((Bounds)(ref pen)).max.y - 0.025f) { LogRoofFitFailure(animal, slot, physical, visible, pen, all, minimum, vertexCount, localPosition); return false; } reason = null; return true; } private static void LogRoofFitFailure(Character animal, int slot, Bounds physical, Bounds visible, Bounds pen, Bounds all, float foot, int footVertices, Vector3 position) { //IL_006a: 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_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: 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_0103: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_02fe: Unknown result type (might be due to invalid IL or missing references) //IL_0303: Unknown result type (might be due to invalid IL or missing references) //IL_0320: Unknown result type (might be due to invalid IL or missing references) //IL_0325: Unknown result type (might be due to invalid IL or missing references) //IL_03a1: Unknown result type (might be due to invalid IL or missing references) //IL_03a6: Unknown result type (might be due to invalid IL or missing references) //IL_03b1: Unknown result type (might be due to invalid IL or missing references) //IL_03b9: Expected O, but got Unknown //IL_03bf: Unknown result type (might be due to invalid IL or missing references) //IL_03c4: Unknown result type (might be due to invalid IL or missing references) //IL_03c9: Unknown result type (might be due to invalid IL or missing references) //IL_03d4: Unknown result type (might be due to invalid IL or missing references) //IL_03d9: Unknown result type (might be due to invalid IL or missing references) //IL_03de: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Unknown result type (might be due to invalid IL or missing references) //IL_04f2: Unknown result type (might be due to invalid IL or missing references) //IL_0559: Unknown result type (might be due to invalid IL or missing references) //IL_0572: Unknown result type (might be due to invalid IL or missing references) //IL_0577: Unknown result type (might be due to invalid IL or missing references) //IL_057b: Unknown result type (might be due to invalid IL or missing references) //IL_0594: Unknown result type (might be due to invalid IL or missing references) //IL_0599: Unknown result type (might be due to invalid IL or missing references) //IL_059d: Unknown result type (might be due to invalid IL or missing references) //IL_05b6: Unknown result type (might be due to invalid IL or missing references) //IL_05bb: Unknown result type (might be due to invalid IL or missing references) //IL_05bf: Unknown result type (might be due to invalid IL or missing references) //IL_05d8: Unknown result type (might be due to invalid IL or missing references) //IL_05dd: Unknown result type (might be due to invalid IL or missing references) //IL_05e1: Unknown result type (might be due to invalid IL or missing references) //IL_0649: Unknown result type (might be due to invalid IL or missing references) //IL_0652: Unknown result type (might be due to invalid IL or missing references) //IL_065e: Unknown result type (might be due to invalid IL or missing references) //IL_0663: Unknown result type (might be due to invalid IL or missing references) //IL_0668: Unknown result type (might be due to invalid IL or missing references) //IL_066d: Unknown result type (might be due to invalid IL or missing references) //IL_0672: Unknown result type (might be due to invalid IL or missing references) //IL_0679: Unknown result type (might be due to invalid IL or missing references) //IL_067e: Unknown result type (might be due to invalid IL or missing references) //IL_068f: Unknown result type (might be due to invalid IL or missing references) //IL_0694: Unknown result type (might be due to invalid IL or missing references) //IL_0699: Unknown result type (might be due to invalid IL or missing references) //IL_06b0: Unknown result type (might be due to invalid IL or missing references) //IL_06b5: Unknown result type (might be due to invalid IL or missing references) //IL_06b9: Unknown result type (might be due to invalid IL or missing references) //IL_06c4: Unknown result type (might be due to invalid IL or missing references) //IL_06c6: Unknown result type (might be due to invalid IL or missing references) //IL_06de: Unknown result type (might be due to invalid IL or missing references) //IL_06e7: Unknown result type (might be due to invalid IL or missing references) //IL_06ec: Unknown result type (might be due to invalid IL or missing references) //IL_06f8: Unknown result type (might be due to invalid IL or missing references) //IL_06fd: Unknown result type (might be due to invalid IL or missing references) //IL_0702: Unknown result type (might be due to invalid IL or missing references) //IL_0739: Unknown result type (might be due to invalid IL or missing references) //IL_0750: Unknown result type (might be due to invalid IL or missing references) //IL_0767: Unknown result type (might be due to invalid IL or missing references) //IL_0780: Unknown result type (might be due to invalid IL or missing references) //IL_0799: Unknown result type (might be due to invalid IL or missing references) //IL_07b2: Unknown result type (might be due to invalid IL or missing references) if (Array.IndexOf(Environment.GetCommandLineArgs(), "-airships-smoke-test") < 0) { return; } Plugin.Log.LogInfo((object)("LOCAL QA ANIMAL FIT ROOF slot=" + slot + "; animal=" + ((Object)animal).name + "; frame=" + Time.frameCount + "; rootScale=" + FitVector(((Component)animal).transform.localScale) + "; lossyScale=" + FitVector(((Component)animal).transform.lossyScale) + "; physicalMin=" + FitVector(((Bounds)(ref physical)).min) + "; physicalMax=" + FitVector(((Bounds)(ref physical)).max) + "; visibleMin=" + FitVector(((Bounds)(ref visible)).min) + "; visibleMax=" + FitVector(((Bounds)(ref visible)).max) + "; allMin=" + FitVector(((Bounds)(ref all)).min) + "; allMax=" + FitVector(((Bounds)(ref all)).max) + "; penMin=" + FitVector(((Bounds)(ref pen)).min) + "; penMax=" + FitVector(((Bounds)(ref pen)).max) + "; bakedFoot=" + FitNumber(foot) + "; bakedFootVertices=" + footVertices + "; localPosition=" + FitVector(position) + "; finalTop=" + FitNumber(((Bounds)(ref all)).max.y + position.y) + "; roofLimit=" + FitNumber(((Bounds)(ref pen)).max.y - 0.025f))); Animator[] componentsInChildren = ((Component)animal).GetComponentsInChildren<Animator>(true); foreach (Animator val in componentsInChildren) { string text = "uninitialized"; if (val.isInitialized && val.layerCount > 0) { AnimatorStateInfo currentAnimatorStateInfo = val.GetCurrentAnimatorStateInfo(0); text = "hash:" + ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).fullPathHash + ",time:" + FitNumber(((AnimatorStateInfo)(ref currentAnimatorStateInfo)).normalizedTime) + ",transition:" + val.IsInTransition(0); } Plugin.Log.LogInfo((object)("LOCAL QA ANIMAL FIT ANIMATOR path=" + FitPath(((Component)val).transform, ((Component)animal).transform) + "; enabled=" + ((Behaviour)val).enabled + "; active=" + ((Component)val).gameObject.activeInHierarchy + "; initialized=" + val.isInitialized + "; culling=" + ((object)val.cullingMode/*cast due to .constrained prefix*/).ToString() + "; updateMode=" + ((object)val.updateMode/*cast due to .constrained prefix*/).ToString() + "; speed=" + FitNumber(val.speed) + "; controller=" + (Object.op_Implicit((Object)(object)val.runtimeAnimatorController) ? ((Object)val.runtimeAnimatorController).name : "none") + "; state=" + text)); } Mesh val2 = null; try { val2 = new Mesh { name = "MA_AnimalFitRoofDiagnostic", indexFormat = (IndexFormat)1 }; Matrix4x4 val3 = Matrix4x4.Scale(Abs(((Component)animal).transform.lossyScale)) * ((Component)animal).transform.worldToLocalMatrix; SkinnedMeshRenderer[] componentsInChildren2 = ((Component)animal).GetComponentsInChildren<SkinnedMeshRenderer>(true); Bounds val7 = default(Bounds); Bounds val8 = default(Bounds); foreach (SkinnedMeshRenderer val4 in componentsInChildren2) { bool flag = ((Renderer)val4).enabled && ((Component)val4).gameObject.activeInHierarchy && Object.op_Implicit((Object)(object)val4.sharedMesh) && !EffectRenderer(((Component)val4).transform, ((Component)animal).transform); string[] obj = new string[26] { "LOCAL QA ANIMAL FIT SKIN path=", FitPath(((Component)val4).transform, ((Component)animal).transform), "; eligible=", flag.ToString(), "; enabled=", ((Renderer)val4).enabled.ToString(), "; active=", ((Component)val4).gameObject.activeInHierarchy.ToString(), "; offscreen=", val4.updateWhenOffscreen.ToString(), "; visible=", ((Renderer)val4).isVisible.ToString(), "; rendererScale=", FitVector(((Component)val4).transform.lossyScale), "; rootBone=", Object.op_Implicit((Object)(object)val4.rootBone) ? FitPath(val4.rootBone, ((Component)animal).transform) : "none", "; boneScale=", Object.op_Implicit((Object)(object)val4.rootBone) ? FitVector(val4.rootBone.lossyScale) : "none", "; localBoundsMin=", null, null, null, null, null, null, null }; Bounds val5 = ((Renderer)val4).localBounds; obj[19] = FitVector(((Bounds)(ref val5)).min); obj[20] = "; localBoundsMax="; val5 = ((Renderer)val4).localBounds; obj[21] = FitVector(((Bounds)(ref val5)).max); obj[22] = "; worldBoundsMin="; val5 = ((Renderer)val4).bounds; obj[23] = FitVector(((Bounds)(ref val5)).min); obj[24] = "; worldBoundsMax="; val5 = ((Renderer)val4).bounds; obj[25] = FitVector(((Bounds)(ref val5)).max); string text2 = string.Concat(obj); if (!flag) { Plugin.Log.LogInfo((object)(text2 + "; baked=False")); continue; } val2.Clear(); val4.BakeMesh(val2, false); Vector3[] vertices = val2.vertices; if (vertices.Length == 0) { Plugin.Log.LogInfo((object)(text2 + "; baked=True; vertices=0")); continue; } Matrix4x4 val6 = val3 * Matrix4x4.TRS(((Component)val4).transform.position, ((Component)val4).transform.rotation, Vector3.one); ((Bounds)(ref val7))..ctor(vertices[0], Vector3.zero); ((Bounds)(ref val8))..ctor(((Matrix4x4)(ref val6)).MultiplyPoint3x4(vertices[0]), Vector3.zero); Vector3[] array = vertices; foreach (Vector3 val9 in array) { ((Bounds)(ref val7)).Encapsulate(val9); ((Bounds)(ref val8)).Encapsulate(((Matrix4x4)(ref val6)).MultiplyPoint3x4(val9)); } Bounds val10 = TransformBounds(val3 * ((Component)val4).transform.localToWorldMatrix, val4.sharedMesh.bounds); Plugin.Log.LogInfo((object)(text2 + "; baked=True; useScale=False; vertices=" + vertices.Length + "; rawMin=" + FitVector(((Bounds)(ref val7)).min) + "; rawMax=" + FitVector(((Bounds)(ref val7)).max) + "; actualMin=" + FitVector(((Bounds)(ref val8)).min) + "; actualMax=" + FitVector(((Bounds)(ref val8)).max) + "; sharedMeshRootMin=" + FitVector(((Bounds)(ref val10)).min) + "; sharedMeshRootMax=" + FitVector(((Bounds)(ref val10)).max))); } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Animal roof fit diagnostic failed: " + ex.GetType().Name + ": " + ex.Message)); } finally { if (Object.op_Implicit((Object)(object)val2)) { Object.Destroy((Object)(object)val2); } } } private static string FitNumber(float value) { return value.ToString("F6", CultureInfo.InvariantCulture); } private static string FitVector(Vector3 value) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) return "(" + FitNumber(value.x) + "," + FitNumber(value.y) + "," + FitNumber(value.z) + ")"; } private static string FitPath(Transform node, Transform root) { string text = ((Object)node).name; while (Object.op_Implicit((Object)(object)node.parent) && (Object)(object)node != (Object)(object)root) { node = node.parent; text = ((Object)node).name + "/" + text; } return text; } internal static bool BakedFoot(Character animal, out float minimum, out int vertexCount) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Expected O, but got Unknown //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0109: 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) minimum = float.PositiveInfinity; vertexCount = 0; if (!Object.op_Implicit((Object)(object)animal)) { return false; } Mesh val = null; try { val = new Mesh { name = "MA_AnimalFootProbe", indexFormat = (IndexFormat)1 }; Matrix4x4 val2 = Matrix4x4.Scale(Abs(((Component)animal).transform.lossyScale)) * ((Component)animal).transform.worldToLocalMatrix; SkinnedMeshRenderer[] componentsInChildren = ((Component)animal).GetComponentsInChildren<SkinnedMeshRenderer>(true); foreach (SkinnedMeshRenderer val3 in componentsInChildren) { if (!((Renderer)val3).enabled || !((Component)val3).gameObject.activeInHierarchy || !Object.op_Implicit((Object)(object)val3.sharedMesh) || EffectRenderer(((Component)val3).transform, ((Component)animal).transform)) { continue; } val.Clear(); val3.BakeMesh(val, false); Matrix4x4 val4 = val2 * Matrix4x4.TRS(((Component)val3).transform.position, ((Component)val3).transform.rotation, Vector3.one); Vector3[] vertices = val.vertices; foreach (Vector3 val5 in vertices) { Vector3 val6 = ((Matrix4x4)(ref val4)).MultiplyPoint3x4(val5); if (!Finite(val6)) { return false; } minimum = Mathf.Min(minimum, val6.y); vertexCount++; } } return vertexCount > 0 && !float.IsInfinity(minimum) && !float.IsNaN(minimum); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Native animal skin foot probe failed: " + ex.GetType().Name + ": " + ex.Message)); return false; } finally { if (Object.op_Implicit((Object)(object)val)) { Object.Destroy((Object)(object)val); } } } internal static bool AnimalBounds(Character animal, out Bounds physical, out Bounds visible) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_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_0016: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_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_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unk
BepInEx/plugins/Valheim_Airships/Airships.Core.dll
Decompiled 3 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Airships.Core")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.2.17.0")] [assembly: AssemblyInformationalVersion("0.2.17")] [assembly: AssemblyProduct("Airships.Core")] [assembly: AssemblyTitle("Airships.Core")] [assembly: AssemblyVersion("0.2.17.0")] namespace Airships.Core; public struct TiltTarget { public double Pitch; public double Roll; public TiltTarget(double pitch, double roll) { Pitch = pitch; Roll = roll; } } public struct MotionVector { public double X; public double Y; public double Z; public MotionVector(double x, double y, double z) { X = x; Y = y; Z = z; } } public static class AirshipMotion { public static TiltTarget Target(double yawRate, double signedSpeed, double maximumSpeed, double maximumTurn, double forwardAcceleration, double windRight, double windForward, double windStrength, double phase, double load, bool large, bool resting, bool moored) { if (!Rules.Finite(yawRate) || !Rules.Finite(signedSpeed) || !Rules.Finite(maximumSpeed) || !Rules.Finite(maximumTurn) || !Rules.Finite(forwardAcceleration) || !Rules.Finite(windRight) || !Rules.Finite(windForward) || !Rules.Finite(windStrength) || !Rules.Finite(phase) || !Rules.Finite(load) || maximumSpeed <= 0.0 || maximumTurn <= 0.0) { throw new ArgumentOutOfRangeException("Invalid airship attitude input"); } if (resting) { return new TiltTarget(0.0, 0.0); } load = Rules.Clamp(load, 0.0, 1.0); windStrength = Rules.Clamp(windStrength, 0.0, 1.0); double num = (large ? 0.75 : 1.0) / (1.0 + 0.25 * load); double num2 = windStrength * (moored ? 0.3 : 1.0); double num3 = (0.0 - Rules.Clamp(yawRate / maximumTurn, -1.0, 1.0)) * Rules.Clamp(signedSpeed / maximumSpeed, -1.0, 1.0) * 8.0; num3 += num2 * (Rules.Clamp(windRight, -1.0, 1.0) * 1.4 + Math.Sin(phase * 0.73) * 1.2); return new TiltTarget(Rules.Clamp(((0.0 - Rules.Clamp(forwardAcceleration, -2.0, 2.0)) * 1.6 + num2 * (Rules.Clamp(windForward, -1.0, 1.0) * 0.65 + Math.Sin(phase * 0.49 + 0.7) * 0.65)) * num, -5.0, 5.0), Rules.Clamp(num3 * num, -8.0, 8.0)); } public static double Spring(double errorDegrees, double rateDegrees, double load, bool large) { if (!Rules.Finite(errorDegrees) || !Rules.Finite(rateDegrees) || !Rules.Finite(load)) { throw new ArgumentOutOfRangeException("Invalid angular spring input"); } double num = (large ? 0.85 : 1.05) / Math.Sqrt(1.0 + 0.5 * Rules.Clamp(load, 0.0, 1.0)); return Rules.Clamp(errorDegrees * num * num - rateDegrees * num * 1.55, -65.0, 65.0); } public static MotionVector AgainstContact(MotionVector acceleration, MotionVector normal) { double num = normal.X * normal.X + normal.Y * normal.Y + normal.Z * normal.Z; if (num < 1E-12) { return acceleration; } double num2 = (acceleration.X * normal.X + acceleration.Y * normal.Y + acceleration.Z * normal.Z) / num; if (num2 >= 0.0) { return acceleration; } return new MotionVector(acceleration.X - normal.X * num2, acceleration.Y - normal.Y * num2, acceleration.Z - normal.Z * num2); } public static double CollisionRecovery(double seconds) { return 0.25 + 0.75 * Rules.Clamp(seconds / 0.9, 0.0, 1.0); } } public static class AnchorRules { public const double SkitaletsMaxCable = 20.0; public const double CaravanMaxCable = 40.0; public const double WinchSpeed = 2.0; public static double MaximumCable(bool large) { if (!large) { return 20.0; } return 40.0; } public static double RestoreLength(double saved, double maximumLength) { ValidateMaximum(maximumLength); if (!Rules.Finite(saved)) { return 0.0; } return Math.Max(0.0, Math.Min(saved, maximumLength)); } public static double RadialSpeed(double requested, double distance, double length, double step, double maximumLength) { ValidateMaximum(maximumLength); if (!Rules.Finite(requested) || !Rules.Finite(distance) || !Rules.Finite(length) || !Rules.Finite(step) || distance < 0.0 || length < 0.0 || length > maximumLength || step <= 0.0) { throw new ArgumentException("Invalid cable state"); } return Math.Min(requested, Math.Max(-1.0, (length - distance) / step)); } private static void ValidateMaximum(double maximumLength) { if (!Rules.Finite(maximumLength) || maximumLength <= 0.0) { throw new ArgumentException("Invalid winch capacity"); } } } public enum FuelKind { None, Wood, Coal } public sealed class FlightSpec { public readonly double PayloadLimit; public readonly double Speed; public readonly double Ascent; public readonly double Ceiling; public readonly double EnergyPerMinute; public readonly int FuelCapacity; public readonly double AccelerationSeconds; public readonly double BrakingSeconds; public readonly double TurnRate; public readonly double DescentSpeed; public readonly double WindDrift; public readonly double HullHealth; public readonly double EnvelopeHealth; public readonly double EngineHealth; public readonly int Engines; public static FlightSpec Skitalets => new FlightSpec(2400.0, 7.0, 1.2, 150.0, 8.0, 80); public static FlightSpec Caravan => new FlightSpec(4000.0, 9.0, 1.8, 300.0, 12.0, 120, 6.0, 5.0, 16.0, 2.5, 0.6, 2800.0, 1400.0, 750.0, 2); public FlightSpec(double payloadLimit, double speed, double ascent, double ceiling, double energyPerMinute, int fuelCapacity, double accelerationSeconds = 8.0, double brakingSeconds = 6.0, double turnRate = 12.0, double descentSpeed = 2.0, double windDrift = 1.0, double hullHealth = 1800.0, double envelopeHealth = 900.0, double engineHealth = 500.0, int engines = 1) { if (!Rules.Finite(payloadLimit) || !Rules.Finite(speed) || !Rules.Finite(ascent) || !Rules.Finite(ceiling) || !Rules.Finite(energyPerMinute) || payloadLimit <= 0.0 || speed <= 0.0 || ascent <= 0.0 || ceiling <= 0.0 || energyPerMinute <= 0.0 || fuelCapacity <= 0 || !Rules.Finite(accelerationSeconds) || accelerationSeconds <= 0.0 || !Rules.Finite(brakingSeconds) || brakingSeconds <= 0.0 || !Rules.Finite(turnRate) || turnRate <= 0.0 || !Rules.Finite(descentSpeed) || descentSpeed <= 0.0 || !Rules.Finite(windDrift) || windDrift < 0.0 || !Rules.Finite(hullHealth) || hullHealth <= 0.0 || !Rules.Finite(envelopeHealth) || envelopeHealth <= 0.0 || !Rules.Finite(engineHealth) || engineHealth <= 0.0 || engines < 1 || engines > 2) { throw new ArgumentOutOfRangeException("Invalid flight specification"); } PayloadLimit = payloadLimit; Speed = speed; Ascent = ascent; Ceiling = ceiling; EnergyPerMinute = energyPerMinute; FuelCapacity = fuelCapacity; AccelerationSeconds = accelerationSeconds; BrakingSeconds = brakingSeconds; TurnRate = turnRate; DescentSpeed = descentSpeed; WindDrift = windDrift; HullHealth = hullHealth; EnvelopeHealth = envelopeHealth; EngineHealth = engineHealth; Engines = engines; } } public struct Envelope { public double LoadRatio; public double ForwardSpeed; public double AscentSpeed; public double Ceiling; public double EnergyRate; public bool Overloaded; } public static class Rules { public static bool Finite(double x) { if (!double.IsNaN(x)) { return !double.IsInfinity(x); } return false; } public static double Clamp(double x, double lo, double hi) { return Math.Max(lo, Math.Min(hi, x)); } public static double FuelEnergy(FuelKind kind) { return (kind == FuelKind.Coal) ? 3 : ((kind == FuelKind.Wood) ? 1 : 0); } public static double FuelQuality(FuelKind kind) { return kind switch { FuelKind.Wood => 0.8, FuelKind.Coal => 1.0, _ => 0.0, }; } public static double EnginePower(int engines, double first, double second) { first = Clamp(first, 0.0, 1.0); second = Clamp(second, 0.0, 1.0); if (engines == 1) { return first; } return Clamp(0.55 * (first + second), 0.0, 1.0); } public static double LiftFactor(double envelopeFraction) { return Clamp((envelopeFraction - 0.1) / 0.9, 0.0, 1.0); } public static double EmergencyDescent(double envelopeFraction) { if (!(envelopeFraction <= 0.1)) { return 0.6; } return 1.2; } public static int BunkerSpace(int capacity, int wood, int coal, bool burningItem) { return Math.Max(0, capacity - wood - coal - (burningItem ? 1 : 0)); } public static double FuelMinutes(double storedEnergy, double energyPerMinute) { if (!(energyPerMinute > 0.0)) { return 0.0; } return Math.Max(0.0, storedEnergy) / energyPerMinute; } public static Envelope Evaluate(FlightSpec spec, double payload, FuelKind kind, double throttle, double climb) { if (spec == null) { throw new ArgumentNullException("spec"); } if (!Finite(payload) || !Finite(throttle) || !Finite(climb) || payload < 0.0) { throw new ArgumentOutOfRangeException("Invalid flight input"); } if (kind != FuelKind.None && kind != FuelKind.Wood && kind != FuelKind.Coal) { throw new ArgumentOutOfRangeException("kind"); } double num = payload / spec.PayloadLimit; double num2 = Clamp(num, 0.0, 1.0); double num3 = Clamp(Math.Abs(throttle), 0.0, 1.0); double num4 = Clamp(climb, 0.0, 1.0); double num5 = FuelQuality(kind); return new Envelope { LoadRatio = num, Overloaded = (num > 1.0), ForwardSpeed = spec.Speed * num5 * (1.0 - 0.25 * num2), AscentSpeed = ((num > 1.0) ? 0.0 : (spec.Ascent * num5 * (1.0 - 0.5 * num2))), Ceiling = spec.Ceiling * (1.0 - 0.2 * num2), EnergyRate = spec.EnergyPerMinute * (0.4 + 0.6 * num3 * num3) * (1.0 + 0.5 * num2) * (1.0 + 0.25 * num4) }; } } public sealed class EnergyTank { public FuelKind Kind { get; private set; } public double Energy { get; private set; } public double OriginalWeight { get; private set; } public double ResidualWeight { get { if (!(Energy <= 0.0)) { return OriginalWeight * Energy / Rules.FuelEnergy(Kind); } return 0.0; } } public EnergyTank() { Restore(FuelKind.None, 0.0, 0.0); } public void Restore(FuelKind kind, double energy, double weight) { if (!Rules.Finite(energy) || !Rules.Finite(weight) || energy < 0.0 || weight < 0.0 || energy > Rules.FuelEnergy(kind) + 1E-06) { throw new ArgumentOutOfRangeException("Invalid saved fuel state"); } if (kind != FuelKind.None && kind != FuelKind.Wood && kind != FuelKind.Coal) { throw new ArgumentOutOfRangeException("kind"); } if (kind == FuelKind.None && energy > 0.0) { throw new ArgumentOutOfRangeException("energy"); } Kind = ((energy > 0.0) ? kind : FuelKind.None); Energy = energy; OriginalWeight = ((energy > 0.0) ? weight : 0.0); } public void LoadItem(FuelKind kind, double weight) { if (Energy > 0.0) { throw new InvalidOperationException("Previous fuel remains"); } if (Rules.FuelEnergy(kind) == 0.0) { throw new ArgumentOutOfRangeException("kind"); } Restore(kind, Rules.FuelEnergy(kind), weight); } public double Consume(double requested) { if (!Rules.Finite(requested) || requested < 0.0) { throw new ArgumentOutOfRangeException("requested"); } double num = Math.Min(requested, Energy); Energy = Math.Max(0.0, Energy - num); if (Energy <= 0.0) { Kind = FuelKind.None; OriginalWeight = 0.0; } return num; } } public static class FuelChestRules { public static bool Accepts(string name) { if (!(name == "$item_coal")) { return name == "$item_wood"; } return true; } public static bool CanDeposit(string name, int amount, int stored, int capacity, bool burning) { if (Accepts(name) && amount > 0 && stored >= 0 && capacity > 0) { return (long)stored + (long)amount + (burning ? 1 : 0) <= capacity; } return false; } } public sealed class ModelData { public readonly ModelPart[] Parts; public readonly bool DirectUV; private ModelData(ModelPart[] parts, bool directUV) { Parts = parts; DirectUV = directUV; } public static ModelData Read(Stream stream) { if (stream == null) { throw new ArgumentNullException("stream"); } try { using BinaryReader binaryReader = new BinaryReader(stream, Encoding.ASCII, leaveOpen: true); string text = Encoding.ASCII.GetString(binaryReader.ReadBytes(4)); bool flag = text == "VAM2"; if (text != "VAM1" && !flag) { throw new InvalidDataException("Unknown model format"); } int num = Count(binaryReader, 1, 64, "parts"); ModelPart[] array = new ModelPart[num]; HashSet<string> hashSet = new HashSet<string>(StringComparer.Ordinal); for (int i = 0; i < num; i++) { string text2 = Text(binaryReader); string text3 = Text(binaryReader); if (text2.Length == 0 || hashSet.Contains(text2) || (text3.Length > 0 && !hashSet.Contains(text3))) { throw new InvalidDataException("Invalid model hierarchy"); } float x = Number(binaryReader); float y = Number(binaryReader); float z = Number(binaryReader); int material = Count(binaryReader, 0, 2, "material"); int num2 = Count(binaryReader, 3, 250000, "vertices"); int num3 = Count(binaryReader, 3, 1500000, "indices"); if (num3 % 3 != 0) { throw new InvalidDataException("Incomplete triangles"); } ModelVertex[] array2 = new ModelVertex[num2]; int[] array3 = new int[num3]; int num4 = 0; while (num4 < num2) { float x2 = Number(binaryReader); float y2 = Number(binaryReader); float z2 = Number(binaryReader); float num5 = Number(binaryReader); float num6 = Number(binaryReader); float num7 = Number(binaryReader); float num8 = Number(binaryReader); float num9 = Number(binaryReader); int slot = (flag ? Count(binaryReader, 0, 15, "material slot") : 0); float num10 = num5 * num5 + num6 * num6 + num7 * num7; bool num11; if (!(num10 < 0.95f) && !(num10 > 1.05f)) { if (!flag) { if (!(num8 < 0f) && !(num8 > 1f) && !(num9 < 0f)) { num11 = num9 > 1f; goto IL_01ff; } } else if (!(Math.Abs(num8) > 100f)) { num11 = Math.Abs(num9) > 100f; goto IL_01ff; } } goto IL_0201; IL_01ff: if (!num11) { array2[num4] = new ModelVertex(x2, y2, z2, num5, num6, num7, num8, num9, slot); num4++; continue; } goto IL_0201; IL_0201: throw new InvalidDataException("Invalid model normals or UVs"); } for (int j = 0; j < num3; j++) { array3[j] = Count(binaryReader, 0, num2 - 1, "vertex index"); } array[i] = new ModelPart(text2, text3, x, y, z, material, array2, array3); hashSet.Add(text2); } if (binaryReader.BaseStream.ReadByte() != -1) { throw new InvalidDataException("Unexpected trailing model data"); } return new ModelData(array, flag); } catch (EndOfStreamException innerException) { throw new InvalidDataException("Truncated model", innerException); } } private static int Count(BinaryReader reader, int min, int max, string name) { int num = reader.ReadInt32(); if (num < min || num > max) { throw new InvalidDataException("Invalid " + name); } return num; } private static string Text(BinaryReader reader) { int num = Count(reader, 0, 64, "name length"); byte[] array = reader.ReadBytes(num); if (array.Length != num) { throw new EndOfStreamException(); } byte[] array2 = array; foreach (byte b in array2) { if ((b < 48 || b > 57) && (b < 65 || b > 90) && (b < 97 || b > 122) && b != 95) { throw new InvalidDataException("Invalid model name"); } } return Encoding.ASCII.GetString(array); } private static float Number(BinaryReader reader) { float num = reader.ReadSingle(); if (!Rules.Finite(num) || Math.Abs(num) > 1000f) { throw new InvalidDataException("Invalid model number"); } return num; } } public sealed class ModelPart { public readonly string Name; public readonly string Parent; public readonly float X; public readonly float Y; public readonly float Z; public readonly int Material; public readonly ModelVertex[] Vertices; public readonly int[] Indices; internal ModelPart(string name, string parent, float x, float y, float z, int material, ModelVertex[] vertices, int[] indices) { Name = name; Parent = parent; X = x; Y = y; Z = z; Material = material; Vertices = vertices; Indices = indices; } } public struct ModelVertex { public readonly float X; public readonly float Y; public readonly float Z; public readonly float NX; public readonly float NY; public readonly float NZ; public readonly float U; public readonly float V; public readonly int Slot; internal ModelVertex(float x, float y, float z, float nx, float ny, float nz, float u, float v, int slot) { X = x; Y = y; Z = z; NX = nx; NY = ny; NZ = nz; U = u; V = v; Slot = slot; } } public sealed class ShipSteering { public double Rudder { get; private set; } public double YawRate { get; private set; } public void Restore(double rudder, double yawRate, double maximum) { Rudder = (Rules.Finite(rudder) ? Rules.Clamp(rudder, -1.0, 1.0) : 0.0); YawRate = (Rules.Finite(yawRate) ? Rules.Clamp(yawRate, 0.0 - maximum, maximum) : 0.0); } private static double Towards(double from, double to, double amount) { return from + (double)Math.Sign(to - from) * Math.Min(Math.Abs(to - from), amount); } public double Step(double command, double signedSpeed, double maximumSpeed, double maximumTurn, double load, double dt, bool blocked) { if (!Rules.Finite(command) || !Rules.Finite(signedSpeed) || !Rules.Finite(maximumSpeed) || !Rules.Finite(maximumTurn) || !Rules.Finite(load) || !Rules.Finite(dt) || maximumSpeed <= 0.0 || maximumTurn <= 0.0 || dt <= 0.0) { throw new ArgumentOutOfRangeException("Invalid steering state"); } if (blocked) { double rudder = (YawRate = 0.0); Rudder = rudder; return 0.0; } load = Rules.Clamp(load, 0.0, 1.0); Rudder = Rules.Clamp(Rudder + Rules.Clamp(command, -1.0, 1.0) * (0.5 + 0.5 * Math.Abs(Rudder)) * dt / (1.5 + 0.5 * load), -1.0, 1.0); double num2 = Rules.Clamp(signedSpeed / maximumSpeed, -1.0, 1.0); double to = Rudder * num2 * maximumTurn / (1.0 + 0.35 * load); YawRate = Towards(YawRate, to, maximumTurn * dt / (2.0 + 0.8 * load)); return YawRate; } }