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 BuildOnShip v1.1.0
BuildOnShip.dll
Decompiled 11 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("BuildOnShip")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+b4456c59c797a22c85bf258466228a3533aa42a5")] [assembly: AssemblyProduct("BuildOnShip")] [assembly: AssemblyTitle("BuildOnShip")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ShipBuildingMod { [BepInPlugin("com.custom.shipbuildmod", "ShipBuildMod", "2.7.1")] public class ShipBuildPlugin : BaseUnityPlugin { public const string ModGUID = "com.custom.shipbuildmod"; public const string ModName = "ShipBuildMod"; public const string ModVersion = "2.7.1"; public const string KeyShipUUID = "ShipBuild_ShipUUID"; public const string KeyShipParent = "ShipBuild_ParentUUID"; public const string KeyLocalPos = "ShipBuild_LocalPos"; public const string KeyLocalRot = "ShipBuild_LocalRot"; public const string KeySpawnShipUUID = "ShipBuild_SpawnShipUUID"; public const string KeySpawnBedLocalPos = "ShipBuild_SpawnBedLocalPos"; private Harmony m_harmony; private void Awake() { m_harmony = Harmony.CreateAndPatchAll(typeof(ShipBuildPlugin).Assembly, "com.custom.shipbuildmod"); ((BaseUnityPlugin)this).Logger.LogInfo((object)"ShipBuildMod v2.7.1 loaded successfully."); } private void OnDestroy() { Harmony harmony = m_harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } public static class WearNTearHelper { private static readonly FieldRef<WearNTear, float> SupportRef = AccessTools.FieldRefAccess<WearNTear, float>("m_support"); private static readonly Func<WearNTear, float> GetMaxSupportFunc = AccessTools.MethodDelegate<Func<WearNTear, float>>(AccessTools.Method(typeof(WearNTear), "GetMaxSupport", (Type[])null, (Type[])null), (object)null, true); public static float GetMaxSupport(WearNTear wnt) { //IL_003a: 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_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Expected I4, but got Unknown if ((Object)(object)wnt == (Object)null) { return 100f; } if (GetMaxSupportFunc != null) { try { return GetMaxSupportFunc(wnt); } catch { } } MaterialType materialType = wnt.m_materialType; MaterialType val = materialType; return (int)val switch { 0 => 100f, 1 => 1000f, 2 => 1500f, 3 => 140f, 4 => 1500f, 5 => 2000f, 6 => 5000f, _ => 100f, }; } public static void SetMaxSupport(WearNTear wnt) { if ((Object)(object)wnt == (Object)null) { return; } float maxSupport = GetMaxSupport(wnt); if (SupportRef != null) { try { SupportRef.Invoke(wnt) = maxSupport; } catch { } } ZNetView component = ((Component)wnt).GetComponent<ZNetView>(); if ((Object)(object)component != (Object)null && component.IsValid() && component.GetZDO() != null) { component.GetZDO().Set(ZDOVars.s_support, maxSupport); } } } public static class MaterialFixer { private static readonly int TriplanarLocalPos = Shader.PropertyToID("_TriplanarLocalPos"); private static readonly int RippleDistance = Shader.PropertyToID("_RippleDistance"); private static readonly int ValueNoise = Shader.PropertyToID("_ValueNoise"); private static readonly Dictionary<Material, Material> s_fixedMaterialCache = new Dictionary<Material, Material>(); public static void FixPieceMaterials(ZNetView netView) { if ((Object)(object)netView == (Object)null) { return; } Renderer[] componentsInChildren = ((Component)netView).GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if (!(val is MeshRenderer) && !(val is SkinnedMeshRenderer)) { continue; } Material[] sharedMaterials = val.sharedMaterials; if (sharedMaterials == null || sharedMaterials.Length == 0) { continue; } bool flag = false; for (int j = 0; j < sharedMaterials.Length; j++) { Material val2 = FixMaterial(sharedMaterials[j]); if ((Object)(object)val2 != (Object)(object)sharedMaterials[j]) { sharedMaterials[j] = val2; flag = true; } } if (flag) { val.sharedMaterials = sharedMaterials; } } } private static Material FixMaterial(Material original) { //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Expected O, but got Unknown if ((Object)(object)original == (Object)null) { return null; } if (!original.HasProperty(RippleDistance) && !original.HasProperty(ValueNoise) && !original.HasProperty(TriplanarLocalPos)) { return original; } if (s_fixedMaterialCache.TryGetValue(original, out var value)) { return value; } Material val = new Material(original); if (val.HasProperty(ValueNoise)) { val.SetFloat(ValueNoise, 0f); } if (val.HasProperty(RippleDistance)) { val.SetFloat(RippleDistance, 0f); } if (val.HasProperty(TriplanarLocalPos)) { val.SetFloat(TriplanarLocalPos, 1f); } s_fixedMaterialCache[original] = val; return val; } } public static class ShipRegistry { public static readonly Dictionary<string, Ship> ShipsByUUID = new Dictionary<string, Ship>(); public static string GetOrCreateShipUUID(ZDO shipZDO) { if (shipZDO == null) { return string.Empty; } string text = shipZDO.GetString("ShipBuild_ShipUUID", ""); if (string.IsNullOrEmpty(text)) { text = Guid.NewGuid().ToString(); shipZDO.Set("ShipBuild_ShipUUID", text); } return text; } public static void RegisterShip(string uuid, Ship ship) { if (!string.IsNullOrEmpty(uuid) && !((Object)(object)ship == (Object)null)) { ShipsByUUID[uuid] = ship; } } public static void UnregisterShip(string uuid) { if (!string.IsNullOrEmpty(uuid)) { ShipsByUUID.Remove(uuid); } } } public class ShipPiecesContainer : MonoBehaviour { public Ship ShipComponent; public string ShipUUID = ""; private readonly List<ZNetView> m_attachedPieces = new List<ZNetView>(); public readonly List<Transform> DeckSnapPoints = new List<Transform>(); public float DeckY = 0.35f; private float m_syncTimer = 0f; private Vector3 m_lastSyncedPos = Vector3.zero; private Quaternion m_lastSyncedRot = Quaternion.identity; public bool HasMovedRecently { get; private set; } = true; private void Awake() { //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_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) ShipComponent = ((Component)this).GetComponent<Ship>(); m_lastSyncedPos = ((Component)this).transform.position; m_lastSyncedRot = ((Component)this).transform.rotation; ZNetView component = ((Component)this).GetComponent<ZNetView>(); if (Object.op_Implicit((Object)(object)component) && component.GetZDO() != null) { ShipUUID = ShipRegistry.GetOrCreateShipUUID(component.GetZDO()); ShipRegistry.RegisterShip(ShipUUID, ShipComponent); } CreateDeckSnapPoints(); } private void OnDestroy() { ShipRegistry.UnregisterShip(ShipUUID); } public void CreateDeckSnapPoints() { //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Expected O, but got Unknown //IL_00e6: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Expected O, but got Unknown //IL_01b7: Unknown result type (might be due to invalid IL or missing references) Transform val = ((Component)this).transform.Find("_DeckSnapGrid"); if ((Object)(object)val != (Object)null) { DeckSnapPoints.Clear(); { foreach (Transform item in val) { Transform val2 = item; if (((Component)val2).CompareTag("snappoint")) { DeckSnapPoints.Add(val2); } } return; } } GameObject val3 = new GameObject("_DeckSnapGrid"); val3.transform.SetParent(((Component)this).transform, false); BoxCollider val4 = (Object.op_Implicit((Object)(object)ShipComponent) ? ShipComponent.m_floatCollider : null); Vector3 val5 = (Vector3)(Object.op_Implicit((Object)(object)val4) ? val4.size : new Vector3(3f, 1f, 8f)); float num = Mathf.Max(0.5f, val5.x * 0.5f - 0.5f); float num2 = Mathf.Max(1f, val5.z * 0.5f - 1f); DeckY = (Object.op_Implicit((Object)(object)val4) ? (val4.center.y + val4.size.y * 0.25f) : 0.35f); DeckSnapPoints.Clear(); for (float num3 = 0f - num2; num3 <= num2; num3 += 1f) { for (float num4 = 0f - num; num4 <= num; num4 += 1f) { GameObject val6 = new GameObject("snappoint"); val6.tag = "snappoint"; val6.transform.SetParent(val3.transform, false); val6.transform.localPosition = new Vector3(num4, DeckY, num3); DeckSnapPoints.Add(val6.transform); } } } public void RegisterPiece(ZNetView pieceView, Vector3 localPos, Quaternion localRot) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Expected O, but got Unknown //IL_013e: 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_017f: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: 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) if ((Object)(object)pieceView == (Object)null) { return; } if (!m_attachedPieces.Contains(pieceView)) { m_attachedPieces.Add(pieceView); } ((Component)pieceView).transform.SetParent(((Component)this).transform); ((Component)pieceView).transform.localPosition = localPos; ((Component)pieceView).transform.localRotation = localRot; ((Component)pieceView).transform.localScale = Vector3.one; Physics.SyncTransforms(); WearNTear component = ((Component)pieceView).GetComponent<WearNTear>(); if ((Object)(object)component != (Object)null) { component.m_noSupportWear = false; component.m_staticPosition = false; WearNTearHelper.SetMaxSupport(component); } if ((Object)(object)((Component)pieceView).GetComponent<TeleportWorld>() != (Object)null) { MeshCollider[] componentsInChildren = ((Component)pieceView).GetComponentsInChildren<MeshCollider>(true); foreach (MeshCollider val in componentsInChildren) { ((Collider)val).enabled = false; } if ((Object)(object)((Component)pieceView).transform.Find("_PortalFrameColliders") == (Object)null) { GameObject val2 = new GameObject("_PortalFrameColliders"); val2.transform.SetParent(((Component)pieceView).transform, false); BoxCollider val3 = val2.AddComponent<BoxCollider>(); val3.center = new Vector3(-0.75f, 1.2f, 0f); val3.size = new Vector3(0.45f, 2.4f, 0.5f); BoxCollider val4 = val2.AddComponent<BoxCollider>(); val4.center = new Vector3(0.75f, 1.2f, 0f); val4.size = new Vector3(0.45f, 2.4f, 0.5f); BoxCollider val5 = val2.AddComponent<BoxCollider>(); val5.center = new Vector3(0f, 2.5f, 0f); val5.size = new Vector3(1.9f, 0.5f, 0.5f); } } MaterialFixer.FixPieceMaterials(pieceView); Renderer[] componentsInChildren2 = ((Component)pieceView).GetComponentsInChildren<Renderer>(true); foreach (Renderer val6 in componentsInChildren2) { val6.probeAnchor = ((Component)ShipComponent).transform; val6.lightProbeUsage = (LightProbeUsage)1; } IgnoreCollisionsWithShipHull(((Component)pieceView).gameObject); Rigidbody[] componentsInChildren3 = ((Component)pieceView).GetComponentsInChildren<Rigidbody>(); foreach (Rigidbody val7 in componentsInChildren3) { if ((Object)(object)val7 != (Object)(object)((Component)ShipComponent).GetComponent<Rigidbody>()) { val7.isKinematic = true; } } } public void UnregisterPiece(ZNetView pieceView) { m_attachedPieces.Remove(pieceView); } private void FixedUpdate() { //IL_002a: 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_0041: 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_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0139: 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_018e: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) //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) //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) if (PieceAttachmentQueue.HasPending(ShipUUID)) { PieceAttachmentQueue.CheckPending(ShipUUID, ShipComponent); } float num = Vector3.Distance(((Component)this).transform.position, m_lastSyncedPos); float num2 = Quaternion.Angle(((Component)this).transform.rotation, m_lastSyncedRot); HasMovedRecently = num > 0.05f || num2 > 0.5f; if (!string.IsNullOrEmpty(ShipNavigationManager.CurrentSpawnShipUUID) && ShipNavigationManager.CurrentSpawnShipUUID == ShipUUID && (Object)(object)Game.instance != (Object)null && Game.instance.GetPlayerProfile() != null) { Vector3 customSpawnPoint = ((Component)this).transform.TransformPoint(ShipNavigationManager.CurrentSpawnBedLocalPos); Game.instance.GetPlayerProfile().SetCustomSpawnPoint(customSpawnPoint); } m_syncTimer += Time.fixedDeltaTime; if (!(m_syncTimer >= 1f)) { return; } m_syncTimer = 0f; Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null) { float num3 = Vector3.Distance(((Component)this).transform.position, ((Component)localPlayer).transform.position); if (num3 > 100f && !ShipComponent.HasPlayerOnboard()) { return; } } if (HasMovedRecently) { m_lastSyncedPos = ((Component)this).transform.position; m_lastSyncedRot = ((Component)this).transform.rotation; SyncZDOPositions(); } } private void SyncZDOPositions() { //IL_0054: 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) for (int num = m_attachedPieces.Count - 1; num >= 0; num--) { ZNetView val = m_attachedPieces[num]; if ((Object)(object)val == (Object)null || val.GetZDO() == null) { m_attachedPieces.RemoveAt(num); } else { val.GetZDO().SetPosition(((Component)val).transform.position); val.GetZDO().SetRotation(((Component)val).transform.rotation); } } } private void IgnoreCollisionsWithShipHull(GameObject pieceRoot) { Collider[] components = ((Component)ShipComponent).GetComponents<Collider>(); BoxCollider floatCollider = ShipComponent.m_floatCollider; Collider[] componentsInChildren = pieceRoot.GetComponentsInChildren<Collider>(true); Collider[] array = componentsInChildren; foreach (Collider val in array) { if (!Object.op_Implicit((Object)(object)val)) { continue; } Collider[] array2 = components; foreach (Collider val2 in array2) { if (Object.op_Implicit((Object)(object)val2) && (Object)(object)val2 != (Object)(object)val) { Physics.IgnoreCollision(val2, val, true); } } if (Object.op_Implicit((Object)(object)floatCollider) && (Object)(object)floatCollider != (Object)(object)val) { Physics.IgnoreCollision((Collider)(object)floatCollider, val, true); } } } } public static class BuildContext { public static Ship TargetShip; } public static class ShipNavigationManager { public static readonly Dictionary<Player, ZDOID> TeleportTargets = new Dictionary<Player, ZDOID>(); public static string CurrentSpawnShipUUID = ""; public static Vector3 CurrentSpawnBedLocalPos = Vector3.zero; private static readonly FieldRef<Player, Vector3> TeleportTargetPosRef = AccessTools.FieldRefAccess<Player, Vector3>("m_teleportTargetPos"); public static string FormatVector3(Vector3 v) { //IL_000b: 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_0021: Unknown result type (might be due to invalid IL or missing references) return string.Format(CultureInfo.InvariantCulture, "{0}:{1}:{2}", v.x, v.y, v.z); } public static Vector3 ParseVector3(string s) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) if (string.IsNullOrEmpty(s)) { return Vector3.zero; } string[] array = s.Split(':'); if (array.Length == 3 && float.TryParse(array[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var result) && float.TryParse(array[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) && float.TryParse(array[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result3)) { return new Vector3(result, result2, result3); } return Vector3.zero; } public static void SetShipSpawnBed(string shipUUID, Vector3 bedLocalPos) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) CurrentSpawnShipUUID = shipUUID; CurrentSpawnBedLocalPos = bedLocalPos; if ((Object)(object)Player.m_localPlayer != (Object)null) { Player.m_localPlayer.m_customData["ShipBuild_SpawnShipUUID"] = shipUUID; Player.m_localPlayer.m_customData["ShipBuild_SpawnBedLocalPos"] = FormatVector3(bedLocalPos); } } public static void ClearShipSpawnBed() { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) CurrentSpawnShipUUID = ""; CurrentSpawnBedLocalPos = Vector3.zero; if ((Object)(object)Player.m_localPlayer != (Object)null) { Player.m_localPlayer.m_customData.Remove("ShipBuild_SpawnShipUUID"); Player.m_localPlayer.m_customData.Remove("ShipBuild_SpawnBedLocalPos"); } } public static bool TryGetShipSpawnPoint(out Vector3 spawnPoint) { //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_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_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_0069: 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_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) spawnPoint = Vector3.zero; if (string.IsNullOrEmpty(CurrentSpawnShipUUID)) { return false; } if (ShipRegistry.ShipsByUUID.TryGetValue(CurrentSpawnShipUUID, out var value) && (Object)(object)value != (Object)null) { spawnPoint = ((Component)value).transform.TransformPoint(CurrentSpawnBedLocalPos) + Vector3.up * 0.4f; return true; } Ship[] array = Object.FindObjectsByType<Ship>((FindObjectsSortMode)0); foreach (Ship val in array) { ShipPiecesContainer component = ((Component)val).GetComponent<ShipPiecesContainer>(); if ((Object)(object)component != (Object)null && component.ShipUUID == CurrentSpawnShipUUID) { ShipRegistry.RegisterShip(component.ShipUUID, val); spawnPoint = ((Component)val).transform.TransformPoint(CurrentSpawnBedLocalPos) + Vector3.up * 0.4f; return true; } } return false; } public static Vector3 GetDynamicTeleportPosition(GameObject go) { //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_001a: 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_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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) TeleportWorld component = go.GetComponent<TeleportWorld>(); if ((Object)(object)component != (Object)null) { return ((Component)component).transform.position + ((Component)component).transform.forward * component.m_exitDistance + Vector3.up * 0.2f; } return go.transform.position; } public static Vector3 ResolveTeleportTargetPos(Player player) { //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_0059: 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_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) if (TeleportTargets.TryGetValue(player, out var value)) { GameObject val = (Object.op_Implicit((Object)(object)ZNetScene.instance) ? ZNetScene.instance.FindInstance(value) : null); if ((Object)(object)val != (Object)null) { return GetDynamicTeleportPosition(val); } } return TeleportTargetPosRef.Invoke(player); } } [HarmonyPatch] public static class ShipSpawnAndPortal_Patches { [HarmonyPatch(typeof(ZoneSystem), "FindFloor")] [HarmonyPrefix] private static bool ZoneSystem_FindFloor_Prefix(Vector3 p, ref float height, ref bool __result) { //IL_002d: 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_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) int mask = LayerMask.GetMask(new string[4] { "piece", "vehicle", "Default", "static_solid" }); RaycastHit val = default(RaycastHit); if (Physics.Raycast(p + Vector3.up * 3f, Vector3.down, ref val, 20f, mask) && (Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Ship>() != (Object)null) { height = ((RaycastHit)(ref val)).point.y; __result = true; return false; } return true; } [HarmonyPatch(typeof(Bed), "IsCurrent")] [HarmonyPrefix] private static bool Bed_IsCurrent_Prefix(Bed __instance, ref bool __result) { ZNetView component = ((Component)__instance).GetComponent<ZNetView>(); if ((Object)(object)component == (Object)null || component.GetZDO() == null) { return true; } long num = component.GetZDO().GetLong(ZDOVars.s_owner, 0L); long num2 = (((Object)(object)Game.instance != (Object)null && Game.instance.GetPlayerProfile() != null) ? Game.instance.GetPlayerProfile().GetPlayerID() : 0); if (num != num2) { return true; } Ship componentInParent = ((Component)__instance).GetComponentInParent<Ship>(); if ((Object)(object)componentInParent != (Object)null) { ShipPiecesContainer component2 = ((Component)componentInParent).GetComponent<ShipPiecesContainer>(); if ((Object)(object)component2 != (Object)null && !string.IsNullOrEmpty(component2.ShipUUID) && component2.ShipUUID == ShipNavigationManager.CurrentSpawnShipUUID) { __result = true; return false; } } return true; } [HarmonyPatch(typeof(Bed), "Interact")] [HarmonyPostfix] private static void Bed_Interact_Postfix(Bed __instance, Humanoid human, bool repeat, bool alt) { //IL_013d: 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_0147: 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_0163: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)human != (Object)(object)Player.m_localPlayer) { return; } ZNetView component = ((Component)__instance).GetComponent<ZNetView>(); if ((Object)(object)component == (Object)null || component.GetZDO() == null) { return; } long num = (((Object)(object)Game.instance != (Object)null && Game.instance.GetPlayerProfile() != null) ? Game.instance.GetPlayerProfile().GetPlayerID() : 0); long num2 = component.GetZDO().GetLong(ZDOVars.s_owner, 0L); if (num2 != 0L && num2 != num) { return; } Ship componentInParent = ((Component)__instance).GetComponentInParent<Ship>(); if ((Object)(object)componentInParent != (Object)null) { ShipPiecesContainer shipPiecesContainer = ((Component)componentInParent).GetComponent<ShipPiecesContainer>() ?? ((Component)componentInParent).gameObject.AddComponent<ShipPiecesContainer>(); if (string.IsNullOrEmpty(shipPiecesContainer.ShipUUID)) { ZNetView component2 = ((Component)componentInParent).GetComponent<ZNetView>(); if (Object.op_Implicit((Object)(object)component2) && component2.GetZDO() != null) { shipPiecesContainer.ShipUUID = ShipRegistry.GetOrCreateShipUUID(component2.GetZDO()); ShipRegistry.RegisterShip(shipPiecesContainer.ShipUUID, componentInParent); } } if (!string.IsNullOrEmpty(shipPiecesContainer.ShipUUID)) { Vector3 bedLocalPos = ((Component)componentInParent).transform.InverseTransformPoint(__instance.GetSpawnPoint()); ShipNavigationManager.SetShipSpawnBed(shipPiecesContainer.ShipUUID, bedLocalPos); Game.instance.GetPlayerProfile().SetCustomSpawnPoint(__instance.GetSpawnPoint()); } } else { ShipNavigationManager.ClearShipSpawnBed(); } } [HarmonyPatch(typeof(Player), "Load")] [HarmonyPostfix] private static void Player_Load_Postfix(Player __instance) { //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 (__instance.m_customData.TryGetValue("ShipBuild_SpawnShipUUID", out var value) && __instance.m_customData.TryGetValue("ShipBuild_SpawnBedLocalPos", out var value2)) { ShipNavigationManager.CurrentSpawnShipUUID = value; ShipNavigationManager.CurrentSpawnBedLocalPos = ShipNavigationManager.ParseVector3(value2); } } [HarmonyPatch(typeof(Player), "SetLocalPlayer")] [HarmonyPostfix] private static void Player_SetLocalPlayer_Postfix(Player __instance) { //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 (__instance.m_customData.TryGetValue("ShipBuild_SpawnShipUUID", out var value) && __instance.m_customData.TryGetValue("ShipBuild_SpawnBedLocalPos", out var value2)) { ShipNavigationManager.CurrentSpawnShipUUID = value; ShipNavigationManager.CurrentSpawnBedLocalPos = ShipNavigationManager.ParseVector3(value2); } } [HarmonyPatch(typeof(Player), "Save")] [HarmonyPrefix] private static void Player_Save_Prefix(Player __instance) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) if (!string.IsNullOrEmpty(ShipNavigationManager.CurrentSpawnShipUUID)) { __instance.m_customData["ShipBuild_SpawnShipUUID"] = ShipNavigationManager.CurrentSpawnShipUUID; __instance.m_customData["ShipBuild_SpawnBedLocalPos"] = ShipNavigationManager.FormatVector3(ShipNavigationManager.CurrentSpawnBedLocalPos); } else { __instance.m_customData.Remove("ShipBuild_SpawnShipUUID"); __instance.m_customData.Remove("ShipBuild_SpawnBedLocalPos"); } } [HarmonyPatch(typeof(Game), "FindSpawnPoint")] [HarmonyPrefix] private static bool Game_FindSpawnPoint_Prefix(Game __instance, out Vector3 point, out bool usedLogoutPoint, float dt, ref bool __result) { //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_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) point = Vector3.zero; usedLogoutPoint = false; PlayerProfile playerProfile = __instance.GetPlayerProfile(); if (playerProfile != null && playerProfile.HaveLogoutPoint()) { return true; } if (ShipNavigationManager.TryGetShipSpawnPoint(out var spawnPoint)) { point = spawnPoint; usedLogoutPoint = false; __result = true; if (playerProfile != null) { playerProfile.SetCustomSpawnPoint(spawnPoint); } return false; } return true; } [HarmonyPatch(typeof(TeleportWorld), "Teleport")] [HarmonyTranspiler] public static IEnumerable<CodeInstruction> TeleportWorld_Teleport_Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown MethodInfo methodInfo = AccessTools.Method(typeof(Character), "TeleportTo", (Type[])null, (Type[])null); MethodInfo methodInfo2 = AccessTools.Method(typeof(ShipSpawnAndPortal_Patches), "Player_TeleportToWrapper", (Type[])null, (Type[])null); List<CodeInstruction> list = new List<CodeInstruction>(instructions); for (int i = 0; i < list.Count; i++) { if (CodeInstructionExtensions.Calls(list[i], methodInfo)) { list[i] = new CodeInstruction(OpCodes.Call, (object)methodInfo2); list.Insert(i, new CodeInstruction(OpCodes.Ldarg_0, (object)null)); break; } } return list; } public static bool Player_TeleportToWrapper(Player player, Vector3 pos, Quaternion rot, bool distantTeleport, TeleportWorld portalInstance) { //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_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_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0063: 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_00b5: 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_00ba: 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_00c7: 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_00dc: 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_00e0: 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_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0138: 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_0151: Unknown result type (might be due to invalid IL or missing references) ZNetView component = ((Component)portalInstance).GetComponent<ZNetView>(); if ((Object)(object)component == (Object)null || component.GetZDO() == null) { return ((Character)player).TeleportTo(pos, rot, distantTeleport); } ZDOID connectionZDOID = component.GetZDO().GetConnectionZDOID((ConnectionType)1); if (connectionZDOID != ZDOID.None) { ZDO val = ((ZDOMan.instance != null) ? ZDOMan.instance.GetZDO(connectionZDOID) : null); if (val != null) { GameObject val2 = (Object.op_Implicit((Object)(object)ZNetScene.instance) ? ZNetScene.instance.FindInstance(val.m_uid) : null); Vector3 val3 = (Object.op_Implicit((Object)(object)val2) ? val2.transform.position : val.GetPosition()); Quaternion val4 = (Object.op_Implicit((Object)(object)val2) ? val2.transform.rotation : val.GetRotation()); Vector3 val5 = val3 + val4 * Vector3.forward * portalInstance.m_exitDistance + Vector3.up * 0.2f; if ((Object)(object)((Component)player).transform.parent != (Object)null) { ((Component)player).transform.SetParent((Transform)null); } if (((Character)player).TeleportTo(val5, val4, true)) { ShipNavigationManager.TeleportTargets[player] = val.m_uid; return true; } } } return ((Character)player).TeleportTo(pos, rot, distantTeleport); } [HarmonyPatch(typeof(Player), "UpdateTeleport")] [HarmonyTranspiler] public static IEnumerable<CodeInstruction> Player_UpdateTeleport_Transpiler(IEnumerable<CodeInstruction> instructions) { FieldInfo targetPosField = AccessTools.Field(typeof(Player), "m_teleportTargetPos"); MethodInfo customPosGetter = AccessTools.Method(typeof(ShipNavigationManager), "ResolveTeleportTargetPos", (Type[])null, (Type[])null); foreach (CodeInstruction inst in instructions) { if (CodeInstructionExtensions.LoadsField(inst, targetPosField, false)) { yield return new CodeInstruction(OpCodes.Call, (object)customPosGetter); } else { yield return inst; } } } [HarmonyPatch(typeof(Player), "UpdateTeleport")] [HarmonyPostfix] private static void Player_UpdateTeleport_Postfix(Player __instance) { if (!((Character)__instance).IsTeleporting()) { ShipNavigationManager.TeleportTargets.Remove(__instance); } } } [HarmonyPatch(typeof(WearNTear))] public static class WearNTear_Patches { public static bool IsPieceOnShip(WearNTear wnt) { if ((Object)(object)wnt == (Object)null) { return false; } if ((Object)(object)((Component)wnt).GetComponent<Ship>() != (Object)null) { return false; } if ((Object)(object)((Component)wnt).GetComponentInParent<Ship>() != (Object)null) { return true; } if ((Object)(object)((Component)wnt).transform.parent != (Object)null && (Object)(object)((Component)((Component)wnt).transform.parent).GetComponent<ShipPiecesContainer>() != (Object)null) { return true; } ZNetView component = ((Component)wnt).GetComponent<ZNetView>(); if ((Object)(object)component != (Object)null && component.IsValid() && component.GetZDO() != null) { string value = component.GetZDO().GetString("ShipBuild_ParentUUID", ""); if (!string.IsNullOrEmpty(value)) { return true; } } return false; } [HarmonyPatch("UpdateSupport")] [HarmonyPrefix] private static bool UpdateSupport_Prefix(WearNTear __instance) { if (IsPieceOnShip(__instance)) { WearNTearHelper.SetMaxSupport(__instance); return false; } return true; } [HarmonyPatch("UpdateWear")] [HarmonyPrefix] private static void UpdateWear_Prefix(WearNTear __instance) { if (IsPieceOnShip(__instance)) { __instance.m_noSupportWear = false; __instance.m_staticPosition = false; } } } [HarmonyPatch] public static class StationAndCover_Patches { private static readonly FieldRef<CraftingStation, bool> HaveFireRef = AccessTools.FieldRefAccess<CraftingStation, bool>("m_haveFire"); [HarmonyPatch(typeof(Cover), "GetCoverForPoint")] [HarmonyPostfix] private static void Cover_GetCoverForPoint_Postfix(Vector3 startPos, ref float coverPercentage, ref bool underRoof) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) Collider[] array = Physics.OverlapSphere(startPos, 2.5f); Collider[] array2 = array; foreach (Collider val in array2) { if ((Object)(object)((Component)val).GetComponentInParent<Ship>() != (Object)null) { coverPercentage = Mathf.Clamp01(coverPercentage + 0.35f); break; } } } [HarmonyPatch(typeof(CraftingStation), "CheckUsable")] [HarmonyPrefix] private static bool CraftingStation_CheckUsable_Prefix(CraftingStation __instance, Player player, bool showMessage, ref bool __result) { //IL_00a1: 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_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) ZNetView component = ((Component)__instance).GetComponent<ZNetView>(); bool flag = (Object)(object)((Component)__instance).GetComponentInParent<Ship>() != (Object)null; if (!flag && (Object)(object)component != (Object)null && component.IsValid() && component.GetZDO() != null) { string value = component.GetZDO().GetString("ShipBuild_ParentUUID", ""); flag = !string.IsNullOrEmpty(value); } if (flag) { if (__instance.m_craftRequireRoof && !player.NoCostCheat()) { Vector3 val = (Object.op_Implicit((Object)(object)__instance.m_roofCheckPoint) ? __instance.m_roofCheckPoint.position : ((Component)__instance).transform.position); float num = default(float); bool flag2 = default(bool); Cover.GetCoverForPoint(val, ref num, ref flag2, 0.5f); GameObject val2 = default(GameObject); if (!flag2 && !WearNTear.RoofCheck(val, ref val2)) { if (showMessage) { ((Character)player).Message((MessageType)2, "$msg_stationneedroof", 0, (Sprite)null); } __result = false; return false; } } if (__instance.m_craftRequireFire && !player.NoCostCheat() && !HaveFireRef.Invoke(__instance)) { if (showMessage) { ((Character)player).Message((MessageType)2, "$msg_needfire", 0, (Sprite)null); } __result = false; return false; } __result = true; return false; } return true; } } [HarmonyPatch] public static class Player_Patches { [HarmonyPatch(typeof(Piece), "GetSnapPoints", new Type[] { typeof(Vector3), typeof(float), typeof(List<Transform>), typeof(List<Piece>) })] [HarmonyPostfix] private static void Piece_GetSnapPoints_Postfix(Vector3 point, float radius, List<Transform> points, List<Piece> pieces) { Ship targetShip = BuildContext.TargetShip; if (!((Object)(object)targetShip != (Object)null)) { return; } ShipPiecesContainer component = ((Component)targetShip).GetComponent<ShipPiecesContainer>(); if ((Object)(object)component != (Object)null && component.DeckSnapPoints.Count > 0) { points.AddRange(component.DeckSnapPoints); Piece component2 = ((Component)targetShip).GetComponent<Piece>(); if ((Object)(object)component2 != (Object)null && !pieces.Contains(component2)) { pieces.Add(component2); } } } [HarmonyPatch(typeof(Player), "TestGhostClipping")] [HarmonyPrefix] private static bool TestGhostClipping_Prefix(Player __instance, GameObject ghost, float maxPenetration, ref bool __result) { if ((Object)(object)BuildContext.TargetShip != (Object)null) { __result = false; return false; } return true; } public static Quaternion GetGhostRotation(float x, float y, float z) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0030: 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_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) Quaternion val = Quaternion.Euler(x, y, z); Ship targetShip = BuildContext.TargetShip; if ((Object)(object)targetShip != (Object)null) { return ((Component)targetShip).transform.rotation * val; } return val; } [HarmonyPatch(typeof(Player), "UpdatePlacementGhost")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> UpdatePlacementGhost_Transpiler(IEnumerable<CodeInstruction> instructions) { MethodInfo eulerMethod = AccessTools.Method(typeof(Quaternion), "Euler", new Type[3] { typeof(float), typeof(float), typeof(float) }, (Type[])null); MethodInfo customMethod = AccessTools.Method(typeof(Player_Patches), "GetGhostRotation", (Type[])null, (Type[])null); foreach (CodeInstruction instruction in instructions) { if (CodeInstructionExtensions.Calls(instruction, eulerMethod)) { yield return new CodeInstruction(OpCodes.Call, (object)customMethod); } else { yield return instruction; } } } [HarmonyPatch(typeof(Player), "PieceRayTest")] [HarmonyPrefix] private static bool PieceRayTest_Prefix(Player __instance, ref bool __result, out Vector3 point, out Vector3 normal, out Piece piece, out Heightmap heightmap, out Collider waterSurface, bool water) { //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_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Expected O, but got Unknown //IL_0133: 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_021a: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_0271: Unknown result type (might be due to invalid IL or missing references) //IL_0276: Unknown result type (might be due to invalid IL or missing references) //IL_0260: 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) point = Vector3.zero; normal = Vector3.zero; piece = null; heightmap = null; waterSurface = null; BuildContext.TargetShip = null; int num = (water ? ((int)AccessTools.Field(typeof(Player), "m_placeWaterRayMask").GetValue(__instance)) : ((int)AccessTools.Field(typeof(Player), "m_placeRayMask").GetValue(__instance))); num &= ~LayerMask.GetMask(new string[1] { "Water" }); RaycastHit val = default(RaycastHit); if (Physics.Raycast(((Component)GameCamera.instance).transform.position, ((Component)GameCamera.instance).transform.forward, ref val, 50f, num)) { float num2 = __instance.m_maxPlaceDistance; object? value = AccessTools.Field(typeof(Player), "m_placementGhost").GetValue(__instance); GameObject val2 = (GameObject)((value is GameObject) ? value : null); if (Object.op_Implicit((Object)(object)val2)) { Piece component = val2.GetComponent<Piece>(); if (Object.op_Implicit((Object)(object)component)) { num2 += (float)component.m_extraPlacementDistance; } } Transform val3 = (Transform)AccessTools.Field(typeof(Player), "m_eye").GetValue(__instance); if (Vector3.Distance(val3.position, ((RaycastHit)(ref val)).point) < num2) { Ship value2 = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Ship>(); if ((Object)(object)value2 == (Object)null) { Piece componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Piece>(); if ((Object)(object)componentInParent != (Object)null && (Object)(object)((Component)componentInParent).GetComponent<ZNetView>() != (Object)null) { ZDO zDO = ((Component)componentInParent).GetComponent<ZNetView>().GetZDO(); if (zDO != null) { string text = zDO.GetString("ShipBuild_ParentUUID", ""); if (!string.IsNullOrEmpty(text)) { ShipRegistry.ShipsByUUID.TryGetValue(text, out value2); } } } } if ((Object)(object)((RaycastHit)(ref val)).collider.attachedRigidbody == (Object)null || (Object)(object)value2 != (Object)null) { point = ((RaycastHit)(ref val)).point; piece = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Piece>(); heightmap = ((Component)((RaycastHit)(ref val)).collider).GetComponent<Heightmap>(); if ((Object)(object)value2 != (Object)null) { BuildContext.TargetShip = value2; normal = ((Component)value2).transform.up; } else { normal = ((RaycastHit)(ref val)).normal; } __result = true; return false; } } } __result = false; return false; } [HarmonyPatch(typeof(Player), "UpdatePlacementGhost")] [HarmonyPostfix] private static void UpdatePlacementGhost_Postfix(Player __instance) { //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //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_00dc: 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_00fd: 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_011f: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_017e: 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_01bd: Unknown result type (might be due to invalid IL or missing references) Ship targetShip = BuildContext.TargetShip; if ((Object)(object)targetShip == (Object)null) { return; } object? value = AccessTools.Field(typeof(Player), "m_placementGhost").GetValue(__instance); GameObject val = (GameObject)((value is GameObject) ? value : null); if ((Object)(object)val == (Object)null || !val.activeInHierarchy) { return; } ShipPiecesContainer component = ((Component)targetShip).GetComponent<ShipPiecesContainer>(); if (!((Object)(object)component == (Object)null)) { int num = (int)AccessTools.Field(typeof(Player), "m_placeRotation").GetValue(__instance); float num2 = (float)AccessTools.Field(typeof(Player), "m_placeRotationDegrees").GetValue(__instance); Quaternion val2 = Quaternion.Euler(0f, num2 * (float)num, 0f); val.transform.rotation = ((Component)targetShip).transform.rotation * val2; Vector3 val3 = ((Component)targetShip).transform.InverseTransformPoint(val.transform.position); BoxCollider floatCollider = targetShip.m_floatCollider; Vector3 val4 = (Vector3)(Object.op_Implicit((Object)(object)floatCollider) ? floatCollider.size : new Vector3(3.5f, 1.5f, 8.5f)); if (Mathf.Abs(val3.x) < val4.x * 0.75f && Mathf.Abs(val3.z) < val4.z * 0.75f && (val3.y < component.DeckY || Mathf.Abs(val3.y - component.DeckY) < 0.35f)) { val3.y = component.DeckY; val.transform.position = ((Component)targetShip).transform.TransformPoint(val3); } Physics.SyncTransforms(); } } [HarmonyPatch(typeof(Player), "FindHoverObject")] [HarmonyPostfix] private static void FindHoverObject_Postfix(Player __instance, ref GameObject hover, ref Character hoverCreature) { if (!((Object)(object)hover != (Object)null) || !((Object)(object)hover.GetComponent<Ship>() != (Object)null)) { return; } RaycastHit[] array = (RaycastHit[])AccessTools.Field(typeof(Player), "m_raycastHoverHits").GetValue(__instance); for (int i = 0; i < array.Length; i++) { Collider collider = ((RaycastHit)(ref array[i])).collider; if ((Object)(object)collider == (Object)null) { break; } Hoverable componentInParent = ((Component)collider).GetComponentInParent<Hoverable>(); if (componentInParent != null && !(componentInParent is Ship)) { hover = ((Component)((componentInParent is MonoBehaviour) ? componentInParent : null)).gameObject; break; } Interactable componentInParent2 = ((Component)collider).GetComponentInParent<Interactable>(); if (componentInParent2 != null && !(componentInParent2 is Ship)) { hover = ((Component)((componentInParent2 is MonoBehaviour) ? componentInParent2 : null)).gameObject; break; } } } [HarmonyPatch(typeof(Player), "PlacePiece")] [HarmonyPostfix] private static void PlacePiece_Postfix(Player __instance, Piece piece, Vector3 pos, Quaternion rot) { //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_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01f5: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_028f: Unknown result type (might be due to invalid IL or missing references) //IL_02a5: Unknown result type (might be due to invalid IL or missing references) //IL_02b3: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) Ship targetShip = BuildContext.TargetShip; if ((Object)(object)targetShip == (Object)null) { return; } if (Vector3.Distance(pos, ((Component)targetShip).transform.position) > 25f) { BuildContext.TargetShip = null; return; } ShipPiecesContainer shipPiecesContainer = ((Component)targetShip).GetComponent<ShipPiecesContainer>() ?? ((Component)targetShip).gameObject.AddComponent<ShipPiecesContainer>(); Piece val = null; List<IPlaced> list = AccessTools.StaticFieldRefAccess<List<IPlaced>>(typeof(Player), "m_placed"); if (list != null && list.Count > 0) { foreach (IPlaced item in list) { Piece val2 = (Piece)(object)((item is Piece) ? item : null); if (val2 != null && !Player.IsPlacementGhost(((Component)val2).gameObject)) { val = val2; break; } } } if ((Object)(object)val == (Object)null) { Collider[] array = Physics.OverlapSphere(pos, 2f); float num = 999f; Collider[] array2 = array; foreach (Collider val3 in array2) { Piece componentInParent = ((Component)val3).GetComponentInParent<Piece>(); if ((Object)(object)componentInParent != (Object)null && !Player.IsPlacementGhost(((Component)componentInParent).gameObject) && ((Object)((Component)componentInParent).gameObject).name.StartsWith(((Object)((Component)piece).gameObject).name)) { float num2 = Vector3.Distance(((Component)componentInParent).transform.position, pos); if (num2 < num) { num = num2; val = componentInParent; } } } } if ((Object)(object)val != (Object)null) { ZNetView component = ((Component)val).GetComponent<ZNetView>(); if (Object.op_Implicit((Object)(object)component) && component.IsValid()) { Vector3 val4 = ((Component)targetShip).transform.InverseTransformPoint(((Component)val).transform.position); Quaternion localRot = Quaternion.Inverse(((Component)targetShip).transform.rotation) * ((Component)val).transform.rotation; if (((Object)val).name.ToLower().Contains("floor")) { val4.y += 0.015f; } string text = shipPiecesContainer.ShipUUID; if (string.IsNullOrEmpty(text)) { text = (shipPiecesContainer.ShipUUID = ShipRegistry.GetOrCreateShipUUID(((Component)targetShip).GetComponent<ZNetView>().GetZDO())); } component.GetZDO().Set("ShipBuild_ParentUUID", text); component.GetZDO().Set("ShipBuild_LocalPos", val4); component.GetZDO().Set("ShipBuild_LocalRot", ((Quaternion)(ref localRot)).eulerAngles); shipPiecesContainer.RegisterPiece(component, val4, localRot); } } BuildContext.TargetShip = null; } } public static class PieceAttachmentQueue { private static readonly Dictionary<string, List<ZNetView>> m_queue = new Dictionary<string, List<ZNetView>>(); public static void Enqueue(string shipUUID, ZNetView piece) { if (!string.IsNullOrEmpty(shipUUID) && !((Object)(object)piece == (Object)null)) { if (!m_queue.ContainsKey(shipUUID)) { m_queue[shipUUID] = new List<ZNetView>(); } m_queue[shipUUID].Add(piece); } } public static bool HasPending(string shipUUID) { if (string.IsNullOrEmpty(shipUUID)) { return false; } return m_queue.ContainsKey(shipUUID); } public static void CheckPending(string shipUUID, Ship ship) { if (string.IsNullOrEmpty(shipUUID) || !Object.op_Implicit((Object)(object)ship) || !m_queue.TryGetValue(shipUUID, out var value)) { return; } for (int num = value.Count - 1; num >= 0; num--) { ZNetView val = value[num]; if (Object.op_Implicit((Object)(object)val)) { AttachToShip(ship, val); } } m_queue.Remove(shipUUID); } public static void AttachToShip(Ship ship, ZNetView pieceView) { //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_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: 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_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)ship) && Object.op_Implicit((Object)(object)pieceView)) { ShipPiecesContainer shipPiecesContainer = ((Component)ship).GetComponent<ShipPiecesContainer>() ?? ((Component)ship).gameObject.AddComponent<ShipPiecesContainer>(); Vector3 vec = pieceView.GetZDO().GetVec3("ShipBuild_LocalPos", Vector3.zero); Vector3 vec2 = pieceView.GetZDO().GetVec3("ShipBuild_LocalRot", Vector3.zero); shipPiecesContainer.RegisterPiece(pieceView, vec, Quaternion.Euler(vec2)); } } } [HarmonyPatch(typeof(ZNetView), "Awake")] public static class ZNetView_Awake_Patch { [HarmonyPostfix] private static void ZNetView_Awake_Postfix(ZNetView __instance) { if (__instance.GetZDO() == null) { return; } string text = __instance.GetZDO().GetString("ShipBuild_ParentUUID", ""); if (!string.IsNullOrEmpty(text)) { WearNTear component = ((Component)__instance).GetComponent<WearNTear>(); if ((Object)(object)component != (Object)null) { component.m_noSupportWear = false; component.m_staticPosition = false; WearNTearHelper.SetMaxSupport(component); } if (ShipRegistry.ShipsByUUID.TryGetValue(text, out var value) && (Object)(object)value != (Object)null) { PieceAttachmentQueue.AttachToShip(value, __instance); } else { PieceAttachmentQueue.Enqueue(text, __instance); } } } } [HarmonyPatch(typeof(Ship), "Awake")] public static class Ship_Awake_Patch { [HarmonyPostfix] private static void Ship_Awake_Postfix(Ship __instance) { ShipPiecesContainer shipPiecesContainer = ((Component)__instance).GetComponent<ShipPiecesContainer>() ?? ((Component)__instance).gameObject.AddComponent<ShipPiecesContainer>(); ZNetView component = ((Component)__instance).GetComponent<ZNetView>(); if (Object.op_Implicit((Object)(object)component) && component.GetZDO() != null) { shipPiecesContainer.ShipUUID = ShipRegistry.GetOrCreateShipUUID(component.GetZDO()); ShipRegistry.RegisterShip(shipPiecesContainer.ShipUUID, __instance); PieceAttachmentQueue.CheckPending(shipPiecesContainer.ShipUUID, __instance); } } } }