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 SafeHarbor v1.0.29
SafeHarbor.dll
Decompiled a month ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Net; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using System.Threading; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Microsoft.CodeAnalysis; using MyMods.Web; using Newtonsoft.Json; using UnityEngine; using UnityEngine.Rendering; [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("SafeHarbor")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.6.0")] [assembly: AssemblyInformationalVersion("1.0.6+901b84ab23f2f10926b13865f9b40bb283490874")] [assembly: AssemblyProduct("SafeHarbor")] [assembly: AssemblyTitle("SafeHarbor")] [assembly: AssemblyVersion("1.0.6.0")] [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 MyMods.Web { public static class WebNav { public sealed class Link { public readonly string Id; public readonly string Label; public readonly int Port; public string Url => "http://127.0.0.1:" + Port + "/"; public Link(string id, string label, int port) { Id = id; Label = label; Port = port; } } public static readonly Link[] Links = new Link[13] { new Link("monsters", "Monsters", 8777), new Link("searoute", "SeaRoute", 8778), new Link("longboat", "Harpoon Longboat", 8779), new Link("tradewind", "TradeWind", 8780), new Link("safeharbor", "Safe Harbor", 8781), new Link("hub", "DFG Hub", 8782), new Link("vault", "Viking Vault", 8783), new Link("qolvault", "QoL Vault Buttons", 8784), new Link("qolinventory", "QoL Inventory Buttons", 8785), new Link("cacophony", "Cacophony", 8787), new Link("ominous", "Ominous", 8788), new Link("pebble", "Pebble", 8789), new Link("trolls", "Trolls", 8790) }; public const string Style = "nav.top{position:sticky;top:0;z-index:20;font-family:Segoe UI,Arial,sans-serif;background:#0d1219;border-bottom:1px solid #2b3b4c;padding:6px 14px;display:flex;align-items:center;gap:6px;flex-wrap:wrap}\nnav.top .brand{color:#7f8fa0;font-size:11px;text-transform:uppercase;letter-spacing:.6px;margin-right:8px}\nnav.top a{color:#9fc3dd;text-decoration:none;font-size:13px;padding:4px 9px;border-radius:5px}\nnav.top a:hover{background:#1a2530}\nnav.top a.here{background:#3a2b4c;border:1px solid #55406b;color:#efe0ff}\n"; public static string Html(string currentId) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("<nav class='top'><span class='brand'>MyMods</span>"); Link[] links = Links; foreach (Link link in links) { stringBuilder.Append("<a class='"); if (link.Id == currentId) { stringBuilder.Append("here"); } stringBuilder.Append("' href='").Append(link.Url).Append("'>") .Append(link.Label) .Append("</a>"); } stringBuilder.Append("</nav>"); return stringBuilder.ToString(); } public static Link Find(string id) { Link[] links = Links; foreach (Link link in links) { if (link.Id == id) { return link; } } return null; } } } namespace SafeHarbor { public class BerthLamp : MonoBehaviour { public int Berth; public int Slot; public Vector3 BaseLocalPosition; public bool Locked; public static readonly Color OpenColor = new Color(0.25f, 1f, 0.35f); public static readonly Color ClosedColor = new Color(1f, 0.18f, 0.12f); private Light m_light; private Renderer[] m_tintRenderers; private void Awake() { m_light = ((Component)this).GetComponentInChildren<Light>(true); Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true); List<Renderer> list = new List<Renderer>(); foreach (Renderer val in componentsInChildren) { if (!((Object)(object)val == (Object)null)) { string text = ((Object)((Component)val).gameObject).name.ToLowerInvariant(); Material sharedMaterial = val.sharedMaterial; if (((Object)(object)sharedMaterial != (Object)null && sharedMaterial.HasProperty("_EmissionColor")) || text.Contains("lantern") || text.Contains("glass") || text.Contains("flame") || text.Contains("light") || text.Contains("lamp") || text.Contains("bulb")) { list.Add(val); } } } if (list.Count == 0) { list.AddRange(componentsInChildren); } m_tintRenderers = list.ToArray(); } public void SetOpen(bool open) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_000f: 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_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) Color val = (open ? OpenColor : ClosedColor); if ((Object)(object)m_light != (Object)null) { ((Behaviour)m_light).enabled = true; m_light.color = val; } if (m_tintRenderers == null) { return; } for (int i = 0; i < m_tintRenderers.Length; i++) { Renderer val2 = m_tintRenderers[i]; if ((Object)(object)val2 == (Object)null) { continue; } Material material = val2.material; if (!((Object)(object)material == (Object)null)) { if (material.HasProperty("_Color")) { material.color = val; } if (material.HasProperty("_EmissionColor")) { material.EnableKeyword("_EMISSION"); material.SetColor("_EmissionColor", val * 1.5f); } } } } } public class BlueprintPiece { public string Name; public Vector3 Position; public Quaternion Rotation = Quaternion.identity; public Vector3 Scale = Vector3.one; } public class DockBlueprint { public string Name = "safeDock"; public string Creator = ""; public string Description = ""; public string Category = "InfinityHammer"; public Vector3 Coordinates; public Vector3 EulerRotation; public readonly List<Vector3> SnapPoints = new List<Vector3>(); public readonly List<BlueprintPiece> Pieces = new List<BlueprintPiece>(); public static DockBlueprint Load(string path) { //IL_0244: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Unknown result type (might be due to invalid IL or missing references) //IL_02a4: Unknown result type (might be due to invalid IL or missing references) //IL_02d2: Unknown result type (might be due to invalid IL or missing references) //IL_02d7: Unknown result type (might be due to invalid IL or missing references) //IL_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_0207: Unknown result type (might be due to invalid IL or missing references) //IL_020c: 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) if (string.IsNullOrEmpty(path) || !File.Exists(path)) { return null; } string[] array; try { array = File.ReadAllLines(path); } catch { return null; } DockBlueprint dockBlueprint = new DockBlueprint(); CultureInfo invariantCulture = CultureInfo.InvariantCulture; bool flag = false; bool flag2 = false; for (int i = 0; i < array.Length; i++) { string text = array[i]; if (text == null) { continue; } text = text.Trim(); if (text.Length == 0) { continue; } if (text[0] == '#') { flag = false; flag2 = false; string text2 = text.Substring(1); int num = text2.IndexOf(':'); string text3 = ((num >= 0) ? text2.Substring(0, num) : text2); string text4 = ((num >= 0) ? text2.Substring(num + 1) : ""); switch (text3) { case "Name": dockBlueprint.Name = text4; break; case "Creator": dockBlueprint.Creator = text4; break; case "Description": dockBlueprint.Description = text4; break; case "Category": dockBlueprint.Category = text4; break; case "Coordinates": dockBlueprint.Coordinates = ParseVec(text4, invariantCulture); break; case "Rotation": dockBlueprint.EulerRotation = ParseVec(text4, invariantCulture); break; case "SnapPoints": flag = true; break; case "Pieces": flag2 = true; break; } } else if (flag) { dockBlueprint.SnapPoints.Add(ParseVec(text, invariantCulture)); } else if (flag2) { string[] array2 = text.Split(';'); if (array2.Length >= 13) { BlueprintPiece item = new BlueprintPiece { Name = array2[0], Position = new Vector3(ParseF(array2[2], invariantCulture), ParseF(array2[3], invariantCulture), ParseF(array2[4], invariantCulture)), Rotation = new Quaternion(ParseF(array2[5], invariantCulture), ParseF(array2[6], invariantCulture), ParseF(array2[7], invariantCulture), ParseF(array2[8], invariantCulture)), Scale = new Vector3(ParseF(array2[10], invariantCulture), ParseF(array2[11], invariantCulture), ParseF(array2[12], invariantCulture)) }; dockBlueprint.Pieces.Add(item); } } } if (dockBlueprint.Pieces.Count <= 0) { return null; } return dockBlueprint; } private static Vector3 ParseVec(string text, CultureInfo ci) { //IL_0008: 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_001e: Unknown result type (might be due to invalid IL or missing references) if (string.IsNullOrEmpty(text)) { return Vector3.zero; } string[] array = text.Split(','); if (array.Length < 3) { return Vector3.zero; } return new Vector3(ParseF(array[0], ci), ParseF(array[1], ci), ParseF(array[2], ci)); } private static float ParseF(string text, CultureInfo ci) { if (!float.TryParse(text, NumberStyles.Float, ci, out var result)) { return 0f; } return result; } } public static class DockGlb { [Serializable] private class GLTFRoot { public GLTFMesh[] meshes; public GLTFNode[] nodes; public GLTFMaterial[] materials; public GLTFAccessor[] accessors; public GLTFBufferView[] bufferViews; public GLTFImage[] images; public GLTFTexture[] textures; public GLTFScene[] scenes; } [Serializable] private class GLTFMesh { public string name; public GLTFPrimitive[] primitives; } [Serializable] private class GLTFPrimitive { public GLTFAttributes attributes; public int indices = -1; public int material = -1; } [Serializable] private class GLTFAttributes { public int POSITION = -1; public int NORMAL = -1; public int TEXCOORD_0 = -1; } [Serializable] private class GLTFNode { public string name; public int mesh = -1; public float[] translation; public float[] rotation; public float[] scale; public int[] children; } [Serializable] private class GLTFMaterial { public string name; public GLTFPBR pbrMetallicRoughness; public GLTFTextureInfo normalTexture; } [Serializable] private class GLTFPBR { public float[] baseColorFactor; public float? metallicFactor; public float? roughnessFactor; public GLTFTextureInfo baseColorTexture; } [Serializable] private class GLTFTextureInfo { public int index = -1; } [Serializable] private class GLTFImage { public string mimeType; public int bufferView = -1; public string name; public string uri; } [Serializable] private class GLTFTexture { public int source = -1; } [Serializable] private class GLTFAccessor { public int bufferView; public int byteOffset; public int componentType; public int count; public string type; } [Serializable] private class GLTFBufferView { public int buffer; public int byteOffset; public int byteLength; public int byteStride; } [Serializable] private class GLTFScene { public int[] nodes; } public static GameObject Load(string glbPath, Shader shader) { if (string.IsNullOrEmpty(glbPath) || !File.Exists(glbPath)) { Logger.LogWarning((object)("Safe Harbor: model file not found: " + glbPath)); return null; } Logger.LogInfo((object)("Safe Harbor: loading model: " + glbPath)); byte[] data; try { data = File.ReadAllBytes(glbPath); } catch (Exception ex) { Logger.LogError((object)("Safe Harbor: could not read model file: " + ex.Message)); return null; } return ParseGLB(data, shader, glbPath); } private static GameObject ParseGLB(byte[] data, Shader shader, string path) { if (data == null || data.Length < 20) { return null; } if (BitConverter.ToUInt32(data, 0) != 1179937895) { Logger.LogWarning((object)("Safe Harbor: '" + path + "' is not a GLB file (bad magic).")); return null; } Logger.LogInfo((object)("Safe Harbor: GLB version " + BitConverter.ToUInt32(data, 4) + ", total length " + data.Length)); int num = 12; string text = null; byte[] array = null; while (num + 8 <= data.Length) { uint num2 = BitConverter.ToUInt32(data, num); uint num3 = BitConverter.ToUInt32(data, num + 4); num += 8; if ((int)num2 > data.Length - num) { break; } switch (num3) { case 1313821514u: text = Encoding.UTF8.GetString(data, num, (int)num2); break; case 5130562u: array = new byte[num2]; Buffer.BlockCopy(data, num, array, 0, (int)num2); break; } num += (int)num2; num = (num + 3) & -4; } if (string.IsNullOrEmpty(text)) { Logger.LogWarning((object)"Safe Harbor: no JSON chunk found in GLB."); return null; } return ParseGLTF(text, array, shader); } private static GameObject ParseGLTF(string json, byte[] binData, Shader shader) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown //IL_05a9: Unknown result type (might be due to invalid IL or missing references) //IL_05af: Expected O, but got Unknown //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_023a: Expected O, but got Unknown //IL_0894: Unknown result type (might be due to invalid IL or missing references) //IL_060b: Unknown result type (might be due to invalid IL or missing references) //IL_0657: Unknown result type (might be due to invalid IL or missing references) //IL_027b: Unknown result type (might be due to invalid IL or missing references) //IL_0280: Unknown result type (might be due to invalid IL or missing references) //IL_0293: Unknown result type (might be due to invalid IL or missing references) //IL_02a2: Unknown result type (might be due to invalid IL or missing references) //IL_02a9: Expected O, but got Unknown //IL_08b0: Unknown result type (might be due to invalid IL or missing references) //IL_08b5: Unknown result type (might be due to invalid IL or missing references) //IL_08b9: Unknown result type (might be due to invalid IL or missing references) //IL_08be: Unknown result type (might be due to invalid IL or missing references) //IL_0698: Unknown result type (might be due to invalid IL or missing references) //IL_094a: Unknown result type (might be due to invalid IL or missing references) //IL_094f: Unknown result type (might be due to invalid IL or missing references) //IL_096f: Unknown result type (might be due to invalid IL or missing references) //IL_0974: Unknown result type (might be due to invalid IL or missing references) //IL_0994: Unknown result type (might be due to invalid IL or missing references) //IL_0999: Unknown result type (might be due to invalid IL or missing references) //IL_08ea: Unknown result type (might be due to invalid IL or missing references) //IL_08d7: Unknown result type (might be due to invalid IL or missing references) //IL_08dc: Unknown result type (might be due to invalid IL or missing references) //IL_046b: Unknown result type (might be due to invalid IL or missing references) //IL_0470: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("SafeHarborModel"); try { GLTFRoot gLTFRoot = JsonConvert.DeserializeObject<GLTFRoot>(json); if (gLTFRoot == null) { Logger.LogWarning((object)"Safe Harbor: failed to parse GLTF JSON."); return null; } Logger.LogInfo((object)("Safe Harbor: GLTF " + ((gLTFRoot.meshes != null) ? gLTFRoot.meshes.Length : 0) + " meshes, " + ((gLTFRoot.nodes != null) ? gLTFRoot.nodes.Length : 0) + " nodes, " + ((gLTFRoot.materials != null) ? gLTFRoot.materials.Length : 0) + " materials.")); GLTFBufferView[] bufferViews = gLTFRoot.bufferViews ?? new GLTFBufferView[0]; GLTFAccessor[] array = gLTFRoot.accessors ?? new GLTFAccessor[0]; GLTFMesh[] array2 = gLTFRoot.meshes ?? new GLTFMesh[0]; GLTFMaterial[] array3 = gLTFRoot.materials ?? new GLTFMaterial[0]; GLTFNode[] array4 = gLTFRoot.nodes ?? new GLTFNode[0]; GLTFTexture[] array5 = gLTFRoot.textures ?? new GLTFTexture[0]; GLTFImage[] images = gLTFRoot.images ?? new GLTFImage[0]; Dictionary<int, Texture2D> texCache = new Dictionary<int, Texture2D>(); Func<int, Texture2D> func = delegate(int imageIndex) { //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Expected O, but got Unknown if (imageIndex < 0 || imageIndex >= images.Length) { return (Texture2D)null; } if (texCache.TryGetValue(imageIndex, out var value3)) { return value3; } GLTFImage gLTFImage = images[imageIndex]; if (gLTFImage.bufferView < 0 || gLTFImage.bufferView >= bufferViews.Length) { return (Texture2D)null; } GLTFBufferView gLTFBufferView = bufferViews[gLTFImage.bufferView]; if (gLTFBufferView.byteOffset + gLTFBufferView.byteLength > binData.Length) { return (Texture2D)null; } byte[] array10 = new byte[gLTFBufferView.byteLength]; Buffer.BlockCopy(binData, gLTFBufferView.byteOffset, array10, 0, gLTFBufferView.byteLength); Texture2D val9 = new Texture2D(2, 2, (TextureFormat)4, false); if (!ImageConversion.LoadImage(val9, array10)) { Object.Destroy((Object)(object)val9); return (Texture2D)null; } ((Object)val9).name = ((!string.IsNullOrEmpty(gLTFImage.name)) ? gLTFImage.name : ("img_" + imageIndex)); texCache[imageIndex] = val9; return val9; }; Dictionary<int, GameObject> dictionary = new Dictionary<int, GameObject>(); Dictionary<int, string> dictionary2 = new Dictionary<int, string>(); if (array4 != null) { foreach (GLTFNode gLTFNode in array4) { if (gLTFNode != null && gLTFNode.mesh >= 0 && !dictionary2.ContainsKey(gLTFNode.mesh)) { dictionary2[gLTFNode.mesh] = gLTFNode.name; } } } for (int num2 = 0; num2 < array2.Length; num2++) { GLTFMesh gLTFMesh = array2[num2]; if (gLTFMesh == null || gLTFMesh.primitives == null || gLTFMesh.primitives.Length == 0) { continue; } string value; string text = ((dictionary2.TryGetValue(num2, out value) && !string.IsNullOrEmpty(value)) ? value : ((!string.IsNullOrEmpty(gLTFMesh.name)) ? gLTFMesh.name : ("Mesh_" + num2))); GameObject val2 = new GameObject(text); val2.transform.SetParent(val.transform, false); for (int num3 = 0; num3 < gLTFMesh.primitives.Length; num3++) { GLTFPrimitive gLTFPrimitive = gLTFMesh.primitives[num3]; if (gLTFPrimitive == null) { continue; } GameObject val3 = new GameObject(text + "_p" + num3); val3.transform.SetParent(val2.transform, false); MeshFilter val4 = val3.AddComponent<MeshFilter>(); MeshRenderer val5 = val3.AddComponent<MeshRenderer>(); Mesh val6 = new Mesh(); val6.indexFormat = (IndexFormat)1; ((Object)val6).name = (gLTFMesh.name ?? ("Mesh_" + num2)) + "_" + num3; if (gLTFPrimitive.attributes != null && gLTFPrimitive.attributes.POSITION >= 0 && gLTFPrimitive.attributes.POSITION < array.Length) { val6.vertices = ReadVec3Accessor(array[gLTFPrimitive.attributes.POSITION], bufferViews, binData); } if (gLTFPrimitive.attributes != null && gLTFPrimitive.attributes.NORMAL >= 0 && gLTFPrimitive.attributes.NORMAL < array.Length) { val6.normals = ReadVec3Accessor(array[gLTFPrimitive.attributes.NORMAL], bufferViews, binData); } else { val6.RecalculateNormals(); } if (gLTFPrimitive.attributes != null && gLTFPrimitive.attributes.TEXCOORD_0 >= 0 && gLTFPrimitive.attributes.TEXCOORD_0 < array.Length) { val6.uv = ReadVec2Accessor(array[gLTFPrimitive.attributes.TEXCOORD_0], bufferViews, binData); } if (gLTFPrimitive.indices >= 0 && gLTFPrimitive.indices < array.Length) { int[] array6 = ReadIndicesAccessor(array[gLTFPrimitive.indices], bufferViews, binData); if (array6 != null) { for (int num4 = 0; num4 + 2 < array6.Length; num4 += 3) { int num5 = array6[num4]; array6[num4] = array6[num4 + 1]; array6[num4 + 1] = num5; } val6.triangles = array6; } } int vertexCount = val6.vertexCount; if (vertexCount > 0) { Color[] array7 = (Color[])(object)new Color[vertexCount]; for (int num6 = 0; num6 < vertexCount; num6++) { array7[num6] = Color.white; } val6.colors = array7; } val6.RecalculateBounds(); val4.mesh = val6; if (gLTFPrimitive.material >= 0 && gLTFPrimitive.material < array3.Length) { GLTFMaterial gLTFMaterial = array3[gLTFPrimitive.material]; Texture2D baseTexture = null; int num7 = ((gLTFMaterial.pbrMetallicRoughness != null && gLTFMaterial.pbrMetallicRoughness.baseColorTexture != null) ? gLTFMaterial.pbrMetallicRoughness.baseColorTexture.index : (-1)); if (num7 >= 0 && num7 < array5.Length) { baseTexture = func(array5[num7].source); } ((Renderer)val5).sharedMaterials = CreateMaterial(gLTFMaterial, shader, baseTexture); } else { ((Renderer)val5).sharedMaterial = CreateFallbackMaterial(shader); } } dictionary[num2] = val2; } if (array4.Length != 0) { GameObject[] array8 = (GameObject[])(object)new GameObject[array4.Length]; for (int num8 = 0; num8 < array4.Length; num8++) { array8[num8] = new GameObject((!string.IsNullOrEmpty(array4[num8].name)) ? array4[num8].name : ("Node_" + num8)); } for (int num9 = 0; num9 < array4.Length; num9++) { GLTFNode gLTFNode2 = array4[num9]; GameObject val7 = array8[num9]; if (gLTFNode2.translation != null && gLTFNode2.translation.Length == 3) { val7.transform.localPosition = new Vector3(gLTFNode2.translation[0], gLTFNode2.translation[1], 0f - gLTFNode2.translation[2]); } if (gLTFNode2.rotation != null && gLTFNode2.rotation.Length == 4) { val7.transform.localRotation = new Quaternion(gLTFNode2.rotation[0], gLTFNode2.rotation[1], 0f - gLTFNode2.rotation[2], 0f - gLTFNode2.rotation[3]); } if (gLTFNode2.scale != null && gLTFNode2.scale.Length == 3) { val7.transform.localScale = new Vector3(gLTFNode2.scale[0], gLTFNode2.scale[1], gLTFNode2.scale[2]); } if (gLTFNode2.mesh >= 0 && gLTFNode2.mesh < array2.Length && dictionary.TryGetValue(gLTFNode2.mesh, out var value2)) { value2.transform.SetParent(val7.transform, false); } if (gLTFNode2.children == null) { continue; } for (int num10 = 0; num10 < gLTFNode2.children.Length; num10++) { int num11 = gLTFNode2.children[num10]; if (num11 >= 0 && num11 < array8.Length) { array8[num11].transform.SetParent(val7.transform, false); } } } bool flag = false; if (gLTFRoot.scenes != null) { for (int num12 = 0; num12 < gLTFRoot.scenes.Length; num12++) { if (flag) { break; } GLTFScene gLTFScene = gLTFRoot.scenes[num12]; if (gLTFScene == null || gLTFScene.nodes == null) { continue; } for (int num13 = 0; num13 < gLTFScene.nodes.Length; num13++) { int num14 = gLTFScene.nodes[num13]; if (num14 >= 0 && num14 < array8.Length) { array8[num14].transform.SetParent(val.transform, false); flag = true; } } } } if (!flag) { for (int num15 = 0; num15 < array8.Length; num15++) { if ((Object)(object)array8[num15].transform.parent == (Object)null) { array8[num15].transform.SetParent(val.transform, false); } } } } else { foreach (GameObject value4 in dictionary.Values) { value4.transform.SetParent(val.transform, false); } } int num16 = 0; MeshRenderer[] componentsInChildren = val.GetComponentsInChildren<MeshRenderer>(true); for (int num17 = 0; num17 < componentsInChildren.Length; num17++) { num16 += ((((Renderer)componentsInChildren[num17]).sharedMaterials != null) ? ((Renderer)componentsInChildren[num17]).sharedMaterials.Length : 0); } Bounds val8 = default(Bounds); bool flag2 = true; Renderer[] componentsInChildren2 = val.GetComponentsInChildren<Renderer>(true); Vector3 size; for (int num18 = 0; num18 < componentsInChildren2.Length; num18++) { Bounds bounds = componentsInChildren2[num18].bounds; size = ((Bounds)(ref bounds)).size; if (!(((Vector3)(ref size)).sqrMagnitude < 0.0001f)) { if (flag2) { val8 = componentsInChildren2[num18].bounds; flag2 = false; } else { ((Bounds)(ref val8)).Encapsulate(componentsInChildren2[num18].bounds); } } } string[] obj = new string[6] { "Safe Harbor: model ready - ", componentsInChildren.Length.ToString(), " renderers, ", num16.ToString(), " primitives, bounds ", null }; object obj2; if (!flag2) { string[] array9 = new string[5]; size = ((Bounds)(ref val8)).size; array9[0] = size.x.ToString("0.##"); array9[1] = " x "; size = ((Bounds)(ref val8)).size; array9[2] = size.y.ToString("0.##"); array9[3] = " x "; size = ((Bounds)(ref val8)).size; array9[4] = size.z.ToString("0.##"); obj2 = string.Concat(array9); } else { obj2 = "none"; } obj[5] = (string)obj2; Logger.LogInfo((object)string.Concat(obj)); return val; } catch (Exception ex) { Logger.LogError((object)("Safe Harbor: error parsing GLTF: " + ex)); return null; } } private static Vector3[] ReadVec3Accessor(GLTFAccessor accessor, GLTFBufferView[] bufferViews, byte[] binData) { //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) if (accessor == null || accessor.bufferView < 0 || accessor.bufferView >= bufferViews.Length || accessor.count <= 0) { return null; } GLTFBufferView gLTFBufferView = bufferViews[accessor.bufferView]; int num = gLTFBufferView.byteOffset + accessor.byteOffset; int count = accessor.count; int num2 = ((gLTFBufferView.byteStride > 0) ? gLTFBufferView.byteStride : 12); Vector3[] array = (Vector3[])(object)new Vector3[count]; for (int i = 0; i < count; i++) { int num3 = num + i * num2; if (num3 + 12 <= binData.Length) { array[i] = new Vector3(BitConverter.ToSingle(binData, num3), BitConverter.ToSingle(binData, num3 + 4), 0f - BitConverter.ToSingle(binData, num3 + 8)); } } return array; } private static Vector2[] ReadVec2Accessor(GLTFAccessor accessor, GLTFBufferView[] bufferViews, byte[] binData) { //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) if (accessor == null || accessor.bufferView < 0 || accessor.bufferView >= bufferViews.Length || accessor.count <= 0) { return null; } GLTFBufferView gLTFBufferView = bufferViews[accessor.bufferView]; int num = gLTFBufferView.byteOffset + accessor.byteOffset; int count = accessor.count; int num2 = ((gLTFBufferView.byteStride > 0) ? gLTFBufferView.byteStride : 8); Vector2[] array = (Vector2[])(object)new Vector2[count]; for (int i = 0; i < count; i++) { int num3 = num + i * num2; if (num3 + 8 <= binData.Length) { array[i] = new Vector2(BitConverter.ToSingle(binData, num3), 1f - BitConverter.ToSingle(binData, num3 + 4)); } } return array; } private static int[] ReadIndicesAccessor(GLTFAccessor accessor, GLTFBufferView[] bufferViews, byte[] binData) { if (accessor == null || accessor.bufferView < 0 || accessor.bufferView >= bufferViews.Length || accessor.count <= 0) { return null; } GLTFBufferView gLTFBufferView = bufferViews[accessor.bufferView]; int num = gLTFBufferView.byteOffset + accessor.byteOffset; int count = accessor.count; int[] array = new int[count]; if (accessor.componentType == 5125) { int num2 = ((gLTFBufferView.byteStride > 0) ? gLTFBufferView.byteStride : 4); for (int i = 0; i < count; i++) { int num3 = num + i * num2; if (num3 + 4 <= binData.Length) { array[i] = BitConverter.ToInt32(binData, num3); } } } else if (accessor.componentType == 5123) { int num4 = ((gLTFBufferView.byteStride > 0) ? gLTFBufferView.byteStride : 2); for (int j = 0; j < count; j++) { int num5 = num + j * num4; if (num5 + 2 <= binData.Length) { array[j] = BitConverter.ToUInt16(binData, num5); } } } else if (accessor.componentType == 5121) { int num6 = ((gLTFBufferView.byteStride <= 0) ? 1 : gLTFBufferView.byteStride); for (int k = 0; k < count; k++) { int num7 = num + k * num6; if (num7 < binData.Length) { array[k] = binData[num7]; } } } return array; } private static Material[] CreateMaterial(GLTFMaterial mat, Shader shader, Texture2D baseTexture) { //IL_0038: 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) Material val = CreateBaseMaterial(shader); ((Object)val).name = ((!string.IsNullOrEmpty(mat.name)) ? mat.name : "DockMaterial"); if ((Object)(object)baseTexture != (Object)null) { val.mainTexture = (Texture)(object)baseTexture; } val.color = Color.white; if (val.HasProperty("_Metallic")) { val.SetFloat("_Metallic", 0f); } if (val.HasProperty("_Glossiness")) { val.SetFloat("_Glossiness", 0.15f); } if (val.HasProperty("_Cutoff")) { val.SetFloat("_Cutoff", 0f); } if (val.HasProperty("_Cull")) { val.SetFloat("_Cull", 0f); } val.DisableKeyword("_ALPHATEST_ON"); if (mat.pbrMetallicRoughness != null) { GLTFPBR pbrMetallicRoughness = mat.pbrMetallicRoughness; if (pbrMetallicRoughness.baseColorFactor != null && pbrMetallicRoughness.baseColorFactor.Length == 4) { val.color = new Color(pbrMetallicRoughness.baseColorFactor[0], pbrMetallicRoughness.baseColorFactor[1], pbrMetallicRoughness.baseColorFactor[2], pbrMetallicRoughness.baseColorFactor[3]); } if (pbrMetallicRoughness.metallicFactor.HasValue) { val.SetFloat("_Metallic", pbrMetallicRoughness.metallicFactor.Value); } if (pbrMetallicRoughness.roughnessFactor.HasValue) { val.SetFloat("_Glossiness", 1f - pbrMetallicRoughness.roughnessFactor.Value); } } return (Material[])(object)new Material[1] { val }; } private static Material CreateFallbackMaterial(Shader shader) { return CreateBaseMaterial(shader); } private static Material CreateBaseMaterial(Shader shader) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown if ((Object)(object)shader == (Object)null) { Logger.LogWarning((object)"Safe Harbor: no usable shader; material will render magenta."); shader = Shader.Find("Hidden/InternalErrorShader"); } return new Material(shader); } } public class DockMechanism : MonoBehaviour, Interactable, Hoverable { public const string LeverName = "tripo_part_139"; public const string GearName = "tripo_part_13"; private const float PullDegrees = -45f; private Transform m_lever; private Transform m_gear; private Quaternion m_leverRest; private Quaternion m_gearRest; private float m_shown; private float m_goal; private bool m_ready; private bool m_bound; private bool m_poseSynced; public static void Install(Transform model) { //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008b: 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_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_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) if ((Object)(object)model == (Object)null) { return; } Transform val = FindPart(model, "tripo_part_139"); Transform val2 = FindPart(model, "tripo_part_13"); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { Logger.LogWarning((object)("Safe Harbor: lever/gear parts not found (lever=" + ((Object)(object)val != (Object)null) + " gear=" + ((Object)(object)val2 != (Object)null) + ").")); return; } Vector3 pivotInParent = PartCenter(val2); ShiftPivot(val2, pivotInParent); ShiftPivot(val, pivotInParent); DockMechanism dockMechanism = ((Component)val).GetComponent<DockMechanism>(); if ((Object)(object)dockMechanism == (Object)null) { dockMechanism = ((Component)val).gameObject.AddComponent<DockMechanism>(); } dockMechanism.m_lever = val; dockMechanism.m_gear = val2; dockMechanism.m_leverRest = val.localRotation; dockMechanism.m_gearRest = val2.localRotation; dockMechanism.m_ready = true; AddSwitchHotspot(val); if ((Object)(object)((Component)model).GetComponent<DockUse>() == (Object)null) { ((Component)model).gameObject.AddComponent<DockUse>(); } Logger.LogInfo((object)"Safe Harbor: lever tripo_part_139 drives gear tripo_part_13."); } private static void AddSwitchHotspot(Transform lever) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown //IL_003d: 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_005d: 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_0084: 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 (!((Object)(object)lever.Find("DryDockSwitch") != (Object)null)) { GameObject val = new GameObject("DryDockSwitch"); val.layer = SafeHarborAppearance.InteractLayer(); val.transform.SetParent(lever, false); val.transform.localPosition = Vector3.zero; val.transform.localRotation = Quaternion.identity; float num = Mathf.Max(0.001f, Mathf.Abs(lever.lossyScale.x)); val.transform.localScale = Vector3.one * (0.9f / num); val.AddComponent<BoxCollider>().size = Vector3.one; if ((Object)(object)val.GetComponent<DockUse>() == (Object)null) { val.AddComponent<DockUse>(); } } } private void OnEnable() { //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_008a: 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_008f: Unknown result type (might be due to invalid IL or missing references) if (!m_bound) { m_lever = ((Component)this).transform; Transform val = ((Component)this).transform; while ((Object)(object)val != (Object)null && ((Object)val).name != "SafeHarborModel") { val = val.parent; } m_gear = (((Object)(object)val != (Object)null) ? FindPart(val, "tripo_part_13") : null); m_leverRest = m_lever.localRotation; m_gearRest = (((Object)(object)m_gear != (Object)null) ? m_gear.localRotation : Quaternion.identity); m_ready = (Object)(object)m_gear != (Object)null; m_bound = m_ready; } } public void SetPulled(bool pulled) { m_goal = (pulled ? 1f : 0f); } public void Toggle() { SetPulled(m_goal < 0.5f); } private void Update() { //IL_00c8: 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_00d5: 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_00ec: Unknown result type (might be due to invalid IL or missing references) if (!m_ready || (Object)(object)m_lever == (Object)null || (Object)(object)m_gear == (Object)null) { return; } if (!m_poseSynced) { ShipDock componentInParent = ((Component)this).GetComponentInParent<ShipDock>(); ZNetView val = (((Object)(object)componentInParent != (Object)null) ? ((Component)componentInParent).GetComponent<ZNetView>() : null); if ((Object)(object)val != (Object)null && val.IsValid()) { m_poseSynced = true; if (!componentInParent.TryFindFreeBerth(out var _)) { m_goal = 1f; m_shown = 1f; } } } m_shown = Mathf.MoveTowards(m_shown, m_goal, Time.deltaTime / 0.45f); float num = -45f * Mathf.SmoothStep(0f, 1f, m_shown); Quaternion val2 = Quaternion.Euler(0f, 0f, num); m_lever.localRotation = m_leverRest; m_gear.localRotation = m_gearRest * val2; } public bool Interact(Humanoid user, bool hold, bool alt) { if (hold || !m_ready) { return false; } ShipDock componentInParent = ((Component)this).GetComponentInParent<ShipDock>(); if ((Object)(object)componentInParent == (Object)null) { return false; } SafeHarborPlugin.OpenDockMenu(componentInParent); return true; } public bool UseItem(Humanoid user, ItemData item) { return false; } public string GetHoverText() { ((Component)this).GetComponentInParent<ShipDock>(); return HoverLabel() + "Dock controls"; } public string GetHoverName() { return "Lever"; } public float GetHoverOffset() { return 8f; } internal static string HoverLabel() { string text = "E"; if (ZInput.instance != null) { text = ZInput.instance.GetBoundKeyString("Use", false); } return "[<color=yellow><b>" + text + "</b></color>] "; } private static Transform FindPart(Transform model, string name) { Transform[] componentsInChildren = ((Component)model).GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { if (!(((Object)val).name != name) && (!((Object)(object)val.parent != (Object)null) || !(((Object)val.parent).name == name))) { return val; } } return null; } private static Vector3 PartCenter(Transform part) { //IL_000a: 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_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0111: 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_0109: 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_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_0065: 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_0071: 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_007f: 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_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009e: 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_00b2: 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_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: 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_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: 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_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_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_00dd: 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) MeshFilter[] componentsInChildren = ((Component)part).GetComponentsInChildren<MeshFilter>(true); bool flag = false; Vector3 val = Vector3.zero; Vector3 val2 = Vector3.zero; Vector3 val5 = default(Vector3); foreach (MeshFilter val3 in componentsInChildren) { if (!((Object)(object)val3 == (Object)null) && !((Object)(object)val3.sharedMesh == (Object)null)) { Bounds bounds = val3.sharedMesh.bounds; Vector3 val4 = part.InverseTransformPoint(((Component)val3).transform.TransformPoint(((Bounds)(ref bounds)).center)); Vector3 extents = ((Bounds)(ref bounds)).extents; Vector3 lossyScale = ((Component)val3).transform.lossyScale; ((Vector3)(ref val5))..ctor(Mathf.Abs(extents.x * lossyScale.x), Mathf.Abs(extents.y * lossyScale.y), Mathf.Abs(extents.z * lossyScale.z)); Vector3 val6 = val4 - val5; Vector3 val7 = val4 + val5; if (!flag) { val = val6; val2 = val7; flag = true; } else { val = Vector3.Min(val, val6); val2 = Vector3.Max(val2, val7); } } } if (!flag) { return Vector3.zero; } return (val + val2) * 0.5f; } private static void ShiftPivot(Transform part, Vector3 pivotInParent) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_001f: 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_003e: Unknown result type (might be due to invalid IL or missing references) Vector3 val = pivotInParent - part.localPosition; for (int i = 0; i < part.childCount; i++) { Transform child = part.GetChild(i); child.localPosition -= val; } part.localPosition += val; } } public class DockUse : MonoBehaviour, Interactable, Hoverable { public bool Interact(Humanoid user, bool hold, bool alt) { DockMechanism componentInChildren = ((Component)this).GetComponentInChildren<DockMechanism>(true); if ((Object)(object)componentInChildren != (Object)null) { return componentInChildren.Interact(user, hold, alt); } ShipDock componentInParent = ((Component)this).GetComponentInParent<ShipDock>(); if ((Object)(object)componentInParent == (Object)null) { return false; } SafeHarborPlugin.OpenDockMenu(componentInParent); return true; } public bool UseItem(Humanoid user, ItemData item) { return false; } public string GetHoverText() { ((Component)this).GetComponentInParent<ShipDock>(); return DockMechanism.HoverLabel() + "Dock controls"; } public string GetHoverName() { return "Dry dock"; } public float GetHoverOffset() { return 8f; } } [Serializable] public class PieceTune { public string Name = ""; public float X; public float Y; public float Z; public float Yaw; public float Scale = 1f; } [Serializable] public class DockTuning { public float GlobalX; public float GlobalY; public float GlobalZ; public float GlobalYaw; public float GlobalScale = 1f; public float BerthX; public float BerthY; public float BerthZ; public float BerthYaw; public float ShipLevel; public bool HasShipPose; public float ShipX; public float ShipY; public float ShipZ; public float ShipRotX; public float ShipRotY; public float ShipRotZ; public float ShipRotW = 1f; public float LampX; public float LampY = 0.5f; public float LampZ = -6f; public float Lamp2X; public float Lamp2Y = 0.5f; public float Lamp2Z = 6f; public float LampScale = 1f; public float LightNudgeX; public float LightNudgeY; public float LightNudgeZ; public float Light2NudgeX; public float Light2NudgeY; public float Light2NudgeZ; public float Light3NudgeX; public float Light3NudgeY; public float Light3NudgeZ; public string DeckMaterial = ""; public List<PieceTune> Pieces = new List<PieceTune>(); } internal static class SafeHarborAppearance { private struct LegCell { public float MinY; public double SumX; public double SumZ; public int Count; } private static readonly string[] FixtureLightParts = new string[3] { "tripo_part_83", "tripo_part_93", "tripo_part_67" }; public static void Apply(GameObject prefab, float deckWidth, float deckLength, bool addPilings, float pilingLength, int berths, float berthSpacing, GameObject lampPrefab, float lampScale, Vector3 lampOffset, bool statusLights) { //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: 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_011b: 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_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_016c: 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_0227: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Unknown result type (might be due to invalid IL or missing references) //IL_029e: Unknown result type (might be due to invalid IL or missing references) //IL_02a3: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Unknown result type (might be due to invalid IL or missing references) //IL_02b9: Unknown result type (might be due to invalid IL or missing references) //IL_02ca: Unknown result type (might be due to invalid IL or missing references) //IL_02cf: Unknown result type (might be due to invalid IL or missing references) //IL_02df: Unknown result type (might be due to invalid IL or missing references) //IL_02e4: Unknown result type (might be due to invalid IL or missing references) //IL_0358: Unknown result type (might be due to invalid IL or missing references) //IL_037a: Unknown result type (might be due to invalid IL or missing references) //IL_03e6: Unknown result type (might be due to invalid IL or missing references) //IL_03ed: Unknown result type (might be due to invalid IL or missing references) Mesh val = null; Material val2 = null; MeshFilter[] componentsInChildren = prefab.GetComponentsInChildren<MeshFilter>(true); foreach (MeshFilter val3 in componentsInChildren) { if (!((Object)(object)val3.sharedMesh == (Object)null)) { MeshRenderer component = ((Component)val3).GetComponent<MeshRenderer>(); if (!((Object)(object)component == (Object)null) && !((Object)(object)((Renderer)component).sharedMaterial == (Object)null)) { val = val3.sharedMesh; val2 = ((Renderer)component).sharedMaterial; break; } } } MeshRenderer[] componentsInChildren2 = prefab.GetComponentsInChildren<MeshRenderer>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { ((Renderer)componentsInChildren2[i]).enabled = false; } Collider[] componentsInChildren3 = prefab.GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren3.Length; i++) { componentsInChildren3[i].enabled = false; } float num = 0.3f; if ((Object)(object)val != (Object)null) { Bounds bounds = val.bounds; num = Mathf.Max(0.1f, ((Bounds)(ref bounds)).size.y); float num2 = Mathf.Max(0.01f, ((Bounds)(ref bounds)).size.x); float num3 = Mathf.Max(0.01f, ((Bounds)(ref bounds)).size.z); GameObject val4 = new GameObject("SafeHarborDeck"); val4.transform.SetParent(prefab.transform, false); val4.transform.localScale = new Vector3(deckWidth / num2, 1f, deckLength / num3); val4.transform.localPosition = new Vector3(0f, 0f - ((Bounds)(ref bounds)).max.y, 0f); val4.AddComponent<MeshFilter>().sharedMesh = val; ((Renderer)val4.AddComponent<MeshRenderer>()).sharedMaterial = val2; } else { Logger.LogWarning((object)"Safe Harbor: base dock piece had no usable mesh; falling back to a plain platform."); GameObject val5 = GameObject.CreatePrimitive((PrimitiveType)3); ((Object)val5).name = "SafeHarborDeck"; Object.Destroy((Object)(object)val5.GetComponent<Collider>()); val5.transform.SetParent(prefab.transform, false); val5.transform.localScale = new Vector3(deckWidth, 0.4f, deckLength); val5.transform.localPosition = new Vector3(0f, -0.2f, 0f); if ((Object)(object)val2 != (Object)null) { ((Renderer)val5.GetComponent<MeshRenderer>()).sharedMaterial = val2; } } BoxCollider obj = prefab.AddComponent<BoxCollider>(); obj.size = new Vector3(deckWidth, num, deckLength); obj.center = new Vector3(0f, (0f - num) * 0.5f, 0f); if (addPilings && (Object)(object)val2 != (Object)null) { float num4 = deckWidth * 0.5f - 0.6f; float num5 = deckLength * 0.5f - 0.6f; float num6 = Mathf.Max(1f, pilingLength); Vector3[] array = (Vector3[])(object)new Vector3[4] { new Vector3(0f - num4, 0f, 0f - num5), new Vector3(num4, 0f, 0f - num5), new Vector3(0f - num4, 0f, num5), new Vector3(num4, 0f, num5) }; for (int j = 0; j < array.Length; j++) { GameObject obj2 = GameObject.CreatePrimitive((PrimitiveType)2); ((Object)obj2).name = "SafeHarborPiling" + j; Object.Destroy((Object)(object)obj2.GetComponent<Collider>()); obj2.transform.SetParent(prefab.transform, false); obj2.transform.localPosition = new Vector3(array[j].x, (0f - num6) * 0.5f, array[j].z); obj2.transform.localScale = new Vector3(0.5f, num6 * 0.5f, 0.5f); ((Renderer)obj2.GetComponent<MeshRenderer>()).sharedMaterial = val2; } } if (statusLights && berths > 0) { float num7 = (0f - deckLength) * 0.5f + 1f; for (int k = 0; k < berths; k++) { float num8 = ((float)k - (float)(berths - 1) * 0.5f) * berthSpacing; CreateLamp(prefab.transform, lampPrefab, val2, k, new Vector3(num8, 0f, num7), lampScale, lampOffset); } } } public static void ApplyModel(GameObject prefab, GameObject model, DockTuning tuning, GameObject lampPrefab, bool statusLights, out Vector3 berthLocal, out float deckLength) { //IL_0186: 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_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_026a: Unknown result type (might be due to invalid IL or missing references) //IL_026f: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Unknown result type (might be due to invalid IL or missing references) MeshFilter[] componentsInChildren = prefab.GetComponentsInChildren<MeshFilter>(true); for (int i = 0; i < componentsInChildren.Length; i++) { if ((Object)(object)componentsInChildren[i] != (Object)null) { componentsInChildren[i].sharedMesh = null; } } MeshRenderer[] componentsInChildren2 = prefab.GetComponentsInChildren<MeshRenderer>(true); for (int j = 0; j < componentsInChildren2.Length; j++) { ((Renderer)componentsInChildren2[j]).enabled = false; } Collider[] componentsInChildren3 = prefab.GetComponentsInChildren<Collider>(true); for (int k = 0; k < componentsInChildren3.Length; k++) { if ((Object)(object)componentsInChildren3[k] != (Object)null) { Object.DestroyImmediate((Object)(object)componentsInChildren3[k]); } } if (tuning == null) { tuning = new DockTuning(); } ((Object)model).name = "SafeHarborModel"; model.transform.SetParent(prefab.transform, false); SetLayerRecursive(model, InteractLayer()); Material val = null; MeshRenderer componentInChildren = model.GetComponentInChildren<MeshRenderer>(true); if ((Object)(object)componentInChildren != (Object)null) { val = ((Renderer)componentInChildren).sharedMaterial; } MeshFilter[] componentsInChildren4 = model.GetComponentsInChildren<MeshFilter>(true); foreach (MeshFilter val2 in componentsInChildren4) { if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.sharedMesh == (Object)null) && val2.sharedMesh.vertexCount >= 3) { MeshCollider component = ((Component)val2).GetComponent<MeshCollider>(); if ((Object)(object)component != (Object)null) { Object.DestroyImmediate((Object)(object)component); } if ((Object)(object)((Component)val2).gameObject.GetComponent<DockUse>() == (Object)null) { ((Component)val2).gameObject.AddComponent<DockUse>(); } } } if (statusLights && AttachFixtureLamps(model.transform, lampPrefab, val) == 0) { CreateLamp(model.transform, lampPrefab, val, 0, new Vector3(tuning.LampX, tuning.LampY, tuning.LampZ), 1f, Vector3.zero); CreateLamp(model.transform, lampPrefab, val, 0, new Vector3(tuning.Lamp2X, tuning.Lamp2Y, tuning.Lamp2Z), 1f, Vector3.zero); } ApplyModelTransform(prefab.transform, tuning); DockMechanism.Install(model.transform); if (SafeHarborPlugin.AddPilings == null || SafeHarborPlugin.AddPilings.Value) { float length = ((SafeHarborPlugin.PilingLength != null) ? SafeHarborPlugin.PilingLength.Value : 20f); BuildLegs(model.transform, val, length); } deckLength = (TryGetModelBounds(prefab.transform, out var bounds) ? Mathf.Max(((Bounds)(ref bounds)).size.x, ((Bounds)(ref bounds)).size.z) : 18f); berthLocal = ModelPoint(tuning, new Vector3(tuning.BerthX, tuning.BerthY, tuning.BerthZ)); } public static void EnsureDockColliders(GameObject root) { if ((Object)(object)root == (Object)null) { return; } MeshFilter[] componentsInChildren = root.GetComponentsInChildren<MeshFilter>(true); foreach (MeshFilter val in componentsInChildren) { if (!((Object)(object)val == (Object)null) && !((Object)(object)val.sharedMesh == (Object)null) && val.sharedMesh.vertexCount >= 3 && !((Object)(object)((Component)val).GetComponentInParent<DockLegs>() != (Object)null) && !((Object)(object)((Component)val).GetComponent<MeshCollider>() != (Object)null)) { MeshCollider obj = ((Component)val).gameObject.AddComponent<MeshCollider>(); obj.sharedMesh = val.sharedMesh; obj.convex = false; } } } public static void ApplyModelTransform(Transform dockRoot, DockTuning tuning) { //IL_0051: 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_0077: 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_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_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_010d: 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_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_0179: 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_0187: 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_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0149: 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) if ((Object)(object)dockRoot == (Object)null || tuning == null) { return; } Transform val = dockRoot.Find("SafeHarborModel"); if ((Object)(object)val == (Object)null) { return; } float num = ((tuning.GlobalScale <= 0f) ? 1f : tuning.GlobalScale); val.localPosition = new Vector3(tuning.GlobalX, tuning.GlobalY, tuning.GlobalZ); val.localRotation = Quaternion.Euler(0f, tuning.GlobalYaw, 0f); val.localScale = Vector3.one * num; float num2 = Mathf.Clamp(tuning.LampScale, 0.1f, 3f) / num; BerthLamp[] componentsInChildren = ((Component)val).GetComponentsInChildren<BerthLamp>(true); Vector3[] array = (Vector3[])(object)new Vector3[2] { new Vector3(tuning.LampX, tuning.LampY, tuning.LampZ), new Vector3(tuning.Lamp2X, tuning.Lamp2Y, tuning.Lamp2Z) }; for (int i = 0; i < componentsInChildren.Length; i++) { BerthLamp berthLamp = componentsInChildren[i]; if (!((Object)(object)berthLamp == (Object)null)) { ((Component)berthLamp).transform.localScale = Vector3.one * num2; if (berthLamp.Locked) { float num3 = Mathf.Max(0.001f, num); ((Component)berthLamp).transform.localPosition = berthLamp.BaseLocalPosition + LightNudge(tuning, berthLamp.Slot) / num3; } else { Vector3 localPosition = (berthLamp.BaseLocalPosition = array[Mathf.Min(i, array.Length - 1)]); ((Component)berthLamp).transform.localPosition = localPosition; ((Component)berthLamp).transform.localRotation = Quaternion.identity; } } } Transform val2 = val.Find("SafeHarborLegs"); if ((Object)(object)val2 != (Object)null) { DockLegs component = ((Component)val2).GetComponent<DockLegs>(); if ((Object)(object)component != (Object)null) { component.Fit(val); } } } private static void BuildLegs(Transform model, Material material, float length) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_0212: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Expected O, but got Unknown //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: 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_0119: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0140: 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_012b: Unknown result type (might be due to invalid IL or missing references) length = Mathf.Max(1f, length); float num = Mathf.Max(0.001f, Mathf.Abs(model.localScale.x)); float num2 = 4.75f / num; Matrix4x4 worldToLocalMatrix = model.worldToLocalMatrix; Dictionary<long, LegCell> dictionary = new Dictionary<long, LegCell>(); MeshFilter[] componentsInChildren = ((Component)model).GetComponentsInChildren<MeshFilter>(true); foreach (MeshFilter val in componentsInChildren) { if ((Object)(object)val == (Object)null || (Object)(object)val.sharedMesh == (Object)null || val.sharedMesh.vertexCount < 24 || (Object)(object)((Component)val).GetComponentInParent<BerthLamp>() != (Object)null) { continue; } Matrix4x4 val2 = worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix; Vector3[] vertices = val.sharedMesh.vertices; for (int j = 0; j < vertices.Length; j++) { Vector3 val3 = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(vertices[j]); int num3 = Mathf.FloorToInt(val3.x / num2); int num4 = Mathf.FloorToInt(val3.z / num2); long key = ((long)num3 << 32) | (uint)num4; if (!dictionary.TryGetValue(key, out var value)) { value.MinY = val3.y; } else if (val3.y < value.MinY) { value.MinY = val3.y; } value.SumX += val3.x; value.SumZ += val3.z; value.Count++; dictionary[key] = value; } } List<Vector3> list = new List<Vector3>(); foreach (LegCell value2 in dictionary.Values) { if (value2.Count >= 12) { list.Add(new Vector3((float)(value2.SumX / (double)value2.Count), value2.MinY, (float)(value2.SumZ / (double)value2.Count))); } } GameObject val4 = new GameObject("SafeHarborLegs"); val4.transform.SetParent(model, false); val4.transform.localPosition = Vector3.zero; val4.transform.localRotation = Quaternion.identity; val4.transform.localScale = Vector3.one; for (int k = 0; k < list.Count; k++) { GameObject obj = GameObject.CreatePrimitive((PrimitiveType)2); ((Object)obj).name = "SafeHarborPiling" + k; Object.DestroyImmediate((Object)(object)obj.GetComponent<Collider>()); obj.transform.SetParent(val4.transform, false); MeshRenderer component = obj.GetComponent<MeshRenderer>(); if ((Object)(object)material != (Object)null && (Object)(object)component != (Object)null) { ((Renderer)component).sharedMaterial = material; } } DockLegs dockLegs = val4.AddComponent<DockLegs>(); dockLegs.Anchors = list.ToArray(); dockLegs.Length = length; dockLegs.Fit(model); Logger.LogInfo((object)("Safe Harbor: added " + list.Count + " pilings, " + length.ToString("0") + "m long.")); } public static Vector3 ModelPoint(DockTuning tuning, Vector3 meters) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_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_0003: Unknown result type (might be due to invalid IL or missing references) if (tuning == null) { return meters; } Quaternion val = Quaternion.Euler(0f, tuning.GlobalYaw, 0f); return new Vector3(tuning.GlobalX, tuning.GlobalY, tuning.GlobalZ) + val * meters; } public static void ApplyBlueprint(GameObject prefab, DockBlueprint blueprint, Vector3 center, DockTuning tuning, GameObject lampPrefab, bool statusLights, out Vector3 berthLocal, out float deckLength) { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0171: 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_012b: 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_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: 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_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Unknown result type (might be due to invalid IL or missing references) MeshRenderer[] componentsInChildren = prefab.GetComponentsInChildren<MeshRenderer>(true); for (int i = 0; i < componentsInChildren.Length; i++) { ((Renderer)componentsInChildren[i]).enabled = false; } Collider[] componentsInChildren2 = prefab.GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { componentsInChildren2[i].enabled = false; } Quaternion val = Quaternion.Euler(0f, tuning.GlobalYaw, 0f); Vector3 val2 = default(Vector3); ((Vector3)(ref val2))..ctor(tuning.GlobalX, tuning.GlobalY, tuning.GlobalZ); float num = ((tuning.GlobalScale <= 0f) ? 1f : tuning.GlobalScale); Material val3 = null; for (int j = 0; j < blueprint.Pieces.Count; j++) { BlueprintPiece blueprintPiece = blueprint.Pieces[j]; GameObject val4 = SafeHarborPlugin.FindVanillaPrefab(blueprintPiece.Name); if ((Object)(object)val4 == (Object)null) { continue; } GameObject val5 = Object.Instantiate<GameObject>(val4, prefab.transform, false); ((Object)val5).name = "SH_BP_" + j; StripForDecoration(val5, keepColliders: true); if ((Object)(object)val3 == (Object)null) { MeshRenderer componentInChildren = val5.GetComponentInChildren<MeshRenderer>(true); if ((Object)(object)componentInChildren != (Object)null) { val3 = ((Renderer)componentInChildren).sharedMaterial; } } ApplyPieceTransform(val5.transform, blueprintPiece, j, tuning, center, val, val2, num); } deckLength = (TryGetBlueprintBounds(prefab.transform, out var bounds) ? Mathf.Max(((Bounds)(ref bounds)).size.x, ((Bounds)(ref bounds)).size.z) : 18f); berthLocal = val2 + val * (num * new Vector3(tuning.BerthX, tuning.BerthY, tuning.BerthZ)); if (statusLights) { Vector3 lampOffset = val * (num * new Vector3(tuning.LampX, tuning.LampY, tuning.LampZ)); CreateLamp(prefab.transform, lampPrefab, val3, 0, berthLocal, tuning.LampScale, lampOffset); } } public static void ApplyPieceTransform(Transform child, BlueprintPiece piece, int index, DockTuning tuning, Vector3 center, Quaternion globalRot, Vector3 globalOffset, float globalScale) { //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_0033: 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_0094: 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) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: 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_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00db: 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_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) float num = piece.Position.x - center.x; float num2 = piece.Position.y - center.y; float num3 = piece.Position.z - center.z; float num4 = 0f; float num5 = 1f; if (tuning != null && tuning.Pieces != null && index < tuning.Pieces.Count) { PieceTune pieceTune = tuning.Pieces[index]; num = pieceTune.X; num2 = pieceTune.Y; num3 = pieceTune.Z; num4 = pieceTune.Yaw; num5 = pieceTune.Scale; } child.localPosition = globalOffset + globalRot * (globalScale * new Vector3(num, num2, num3)); Vector3 eulerAngles = ((Quaternion)(ref piece.Rotation)).eulerAngles; child.localRotation = globalRot * Quaternion.Euler(eulerAngles.x, eulerAngles.y + num4, eulerAngles.z); child.localScale = Vector3.Scale(piece.Scale, Vector3.one * (globalScale * num5)); } private static int AttachFixtureLamps(Transform model, GameObject lampPrefab, Material fallbackMaterial) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) int num = 0; for (int i = 0; i < FixtureLightParts.Length; i++) { Transform val = FindModelNode(model, FixtureLightParts[i]); if (!((Object)(object)val == (Object)null) && TryGetLanternCenter(model, val, out var modelLocal)) { CreateLamp(model, lampPrefab, fallbackMaterial, 0, modelLocal, 1f, Vector3.zero, lockToSpot: true, i); num++; } } return num; } private static Transform FindModelNode(Transform root, string name) { if ((Object)(object)root == (Object)null || string.IsNullOrEmpty(name)) { return null; } Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { if (!((Object)(object)val == (Object)null) && !(((Object)val).name != name) && (!((Object)(object)val.parent != (Object)null) || !(((Object)val.parent).name == name))) { return val; } } return null; } private static bool TryGetLanternCenter(Transform model, Transform part, out Vector3 modelLocal) { //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_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_0097: 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_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: 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_00d4: 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_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_019d: 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_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01cd: 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_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_0234: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) modelLocal = Vector3.zero; MeshFilter componentInChildren = ((Component)part).GetComponentInChildren<MeshFilter>(true); if ((Object)(object)componentInChildren == (Object)null || (Object)(object)componentInChildren.sharedMesh == (Object)null) { return false; } Vector3[] vertices = componentInChildren.sharedMesh.vertices; if (vertices == null || vertices.Length == 0) { return false; } Transform transform = ((Component)componentInChildren).transform; float num = float.MaxValue; float num2 = float.MaxValue; float num3 = float.MaxValue; float num4 = float.MinValue; float num5 = float.MinValue; float num6 = float.MinValue; Vector3[] array = (Vector3[])(object)new Vector3[vertices.Length]; for (int i = 0; i < vertices.Length; i++) { Vector3 val = (array[i] = model.InverseTransformPoint(transform.TransformPoint(vertices[i]))); num = Mathf.Min(num, val.x); num2 = Mathf.Min(num2, val.y); num3 = Mathf.Min(num3, val.z); num4 = Mathf.Max(num4, val.x); num5 = Mathf.Max(num5, val.y); num6 = Mathf.Max(num6, val.z); } float num7 = Mathf.Max(num4 - num, Mathf.Max(num5 - num2, num6 - num3)); float num8 = num2 + (num5 - num2) * 0.55f; bool flag = num7 >= 0.15f; int num9 = 0; float num10 = float.MaxValue; float num11 = float.MaxValue; float num12 = float.MaxValue; float num13 = float.MinValue; float num14 = float.MinValue; float num15 = float.MinValue; foreach (Vector3 val2 in array) { if (!flag || !(val2.y < num8)) { num9++; num10 = Mathf.Min(num10, val2.x); num11 = Mathf.Min(num11, val2.y); num12 = Mathf.Min(num12, val2.z); num13 = Mathf.Max(num13, val2.x); num14 = Mathf.Max(num14, val2.y); num15 = Mathf.Max(num15, val2.z); } } if (num9 == 0) { return false; } modelLocal = new Vector3((num10 + num13) * 0.5f, (num11 + num14) * 0.5f, (num12 + num15) * 0.5f); return true; } private static Vector3 LightNudge(DockTuning tuning, int slot) { //IL_0003: 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_0053: 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 (tuning == null) { return Vector3.zero; } return (Vector3)(slot switch { 1 => new Vector3(tuning.Light2NudgeX, tuning.Light2NudgeY, tuning.Light2NudgeZ), 2 => new Vector3(tuning.Light3NudgeX, tuning.Light3NudgeY, tuning.Light3NudgeZ), _ => new Vector3(tuning.LightNudgeX, tuning.LightNudgeY, tuning.LightNudgeZ), }); } private static void CreateLamp(Transform parent, GameObject lampPrefab, Material fallbackMaterial, int berth, Vector3 baseLocalPosition, float lampScale, Vector3 lampOffset, bool lockToSpot = false, int slot = 0) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown //IL_0158: 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_015c: Unknown result type (might be due to invalid IL or missing references) //IL_016c: 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) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: 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_0127: 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_013b: 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_0103: 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) float num = Mathf.Clamp(lampScale, 0.1f, 3f); GameObject val = new GameObject("SafeHarborLamp" + berth); val.SetActive(false); GameObject val2; if ((Object)(object)lampPrefab != (Object)null) { val2 = Object.Instantiate<GameObject>(lampPrefab, val.transform, false); ((Object)val2).name = "Lantern"; StripForDecoration(val2, keepColliders: false); SetActiveRecursive(val2); HideLampPosts(val2); CropPoles(val2); } else { val2 = CreateFallbackLamp(fallbackMaterial); val2.transform.SetParent(val.transform, false); } Light val3 = val.GetComponentInChildren<Light>(true); if ((Object)(object)val3 == (Object)null) { val3 = val.AddComponent<Light>(); val3.type = (LightType)2; } ((Behaviour)val3).enabled = true; val3.range = Mathf.Clamp(val3.range, 6f, 10f); val3.intensity = Mathf.Clamp(val3.intensity, 0.8f, 1.4f); if (TryGetLocalBounds(val.transform, out var bounds)) { if (lockToSpot) { Transform transform = val2.transform; transform.localPosition -= ((Bounds)(ref bounds)).center; } else { Transform transform2 = val2.transform; transform2.localPosition -= new Vector3(0f, ((Bounds)(ref bounds)).min.y, 0f); } } val.transform.SetParent(parent, false); val.transform.localPosition = baseLocalPosition + lampOffset; val.transform.localRotation = Quaternion.identity; val.transform.localScale = Vector3.one * num; BerthLamp berthLamp = val.AddComponent<BerthLamp>(); berthLamp.Berth = berth; berthLamp.Slot = slot; berthLamp.BaseLocalPosition = baseLocalPosition; berthLamp.Locked = lockToSpot; val.SetActive(true); } private static void SetActiveRecursive(GameObject root) { if ((Object)(object)root == (Object)null) { return; } Transform[] componentsInChildren = root.GetComponentsInChildren<Transform>(true); for (int i = 0; i < componentsInChildren.Length; i++) { if ((Object)(object)componentsInChildren[i] != (Object)null) { ((Component)componentsInChildren[i]).gameObject.SetActive(true); } } } private static void CropPoles(GameObject lamp) { if ((Object)(object)lamp == (Object)null) { return; } MeshFilter[] componentsInChildren = lamp.GetComponentsInChildren<MeshFilter>(true); foreach (MeshFilter val in componentsInChildren) { if (!((Object)(object)val == (Object)null) && !((Object)(object)val.sharedMesh == (Object)null)) { Mesh val2 = CropVerticalPole(val.sharedMesh); if ((Object)(object)val2 != (Object)null) { val.sharedMesh = val2; } } } } private static Mesh CropVerticalPole(Mesh source) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_002c: 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_003f: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0085: 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_00a3: 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_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: 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_024b: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Expected O, but got Unknown if ((Object)(object)source == (Object)null || !source.isReadable || source.vertexCount < 12) { return null; } Bounds bounds = source.bounds; Vector3 size = ((Bounds)(ref bounds)).size; if (size.y < 0.75f || size.y < size.x * 1.7f || size.y < size.z * 1.7f) { return null; } Vector3[] vertices = source.vertices; float[] array = new float[16]; float y = ((Bounds)(ref bounds)).min.y; float num = Mathf.Max(0.001f, size.y); Vector3 center = ((Bounds)(ref bounds)).center; foreach (Vector3 val in vertices) { int num2 = Mathf.Clamp((int)((val.y - y) / num * 16f), 0, 15); float num3 = val.x - center.x; float num4 = val.z - center.z; float num5 = Mathf.Sqrt(num3 * num3 + num4 * num4); if (num5 > array[num2]) { array[num2] = num5; } } float num6 = 0f; for (int j = 0; j < 16; j++) { if (array[j] > num6) { num6 = array[j]; } } if (num6 < 0.02f) { return null; } int num7 = 15; bool flag = false; for (int num8 = 15; num8 >= 0; num8--) { if (array[num8] >= num6 * 0.5f) { num7 = num8; flag = true; } else if (flag) { break; } } if (!flag || num7 <= 1) { return null; } float num9 = y + (float)num7 / 16f * num - num * 0.05f; int[] triangles = source.triangles; List<int> list = new List<int>(triangles.Length); for (int k = 0; k + 2 < triangles.Length; k += 3) { int num10 = triangles[k]; int num11 = triangles[k + 1]; int num12 = triangles[k + 2]; if (vertices[num10].y >= num9 && vertices[num11].y >= num9 && vertices[num12].y >= num9) { list.Add(num10); list.Add(num11); list.Add(num12); } } if (list.Count < 12 || (float)list.Count > (float)triangles.Length * 0.85f) { return null; } Mesh val2 = new Mesh(); ((Object)val2).name = ((Object)source).name + "_lantern"; val2.vertices = vertices; val2.triangles = list.ToArray(); if (source.normals != null && source.normals.Length == vertices.Length) { val2.normals = source.normals; } if (source.uv != null && source.uv.Length == vertices.Length) { val2.uv = source.uv; } if (source.colors != null && source.colors.Length == vertices.Length) { val2.colors = source.colors; } val2.RecalculateBounds(); if (val2.normals == null || val2.normals.Length == 0) { val2.RecalculateNormals(); } return val2; } private static void HideLampPosts(GameObject lamp) { if ((Object)(object)lamp == (Object)null) { return; } Transform[] componentsInChildren = lamp.GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { if (!((Object)(object)val == (Object)null) && !((Object)(object)val == (Object)(object)lamp.transform)) { string text = ((Object)val).name.ToLowerInvariant(); if (text.Contains("pole") || text.Contains("post") || text.Contains("stake") || text.Contains("stand")) { ((Component)val).gameObject.SetActive(false); } } } } private static GameObject CreateFallbackLamp(Material material) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown //IL_004f: 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_0069: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("FallbackLantern"); GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)0); ((Object)val2).name = "LampBulb"; Object.Destroy((Object)(object)val2.GetComponent<Collider>()); val2.transform.SetParent(val.transform, false); val2.transform.localPosition = new Vector3(0f, 0.35f, 0f); val2.transform.localScale = Vector3.one * 0.45f; if ((Object)(object)material != (Object)null) { ((Renderer)val2.GetComponent<MeshRenderer>()).sharedMaterial = material; } return val; } private static void StripForDecoration(GameObject root, bool keepColliders) { Component[] componentsInChildren = root.GetComponentsInChildren<Component>(true); foreach (Component val in componentsInChildren) { if (!((Object)(object)val == (Object)null) && !(val is Transform) && !(val is MeshFilter) && !(val is MeshRenderer) && !(val is SkinnedMeshRenderer) && !(val is Light) && !(val is LODGroup) && (!keepColliders || !(val is Collider))) { ZNetView val2 = (ZNetView)(object)((val is ZNetView) ? val : null); if (val2 != null) { SafeHarborPlugin.ReleaseAccidentalView(val2); Object.DestroyImmediate((Object)(object)val2); } else if (!(val is ParticleSystem) && !(val is ParticleSystemRenderer) && !(val is ReflectionProbe)) { Object.DestroyImmediate((Object)(object)val); } } } } private static bool TryGetLocalBounds(Transform root, out Bounds bounds) { //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_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_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_004a: 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_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_007f: 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_0075: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: 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_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) bounds = new Bounds(Vector3.zero, Vector3.zero); Matrix4x4 worldToLocalMatrix = root.worldToLocalMatrix; bool flag = false; MeshFilter[] componentsInChildren = ((Component)root).GetComponentsInChildren<MeshFilter>(true); foreach (MeshFilter val in componentsInChildren) { if (!((Object)(object)val == (Object)null) && !((Object)(object)val.sharedMesh == (Object)null)) { Bounds val2 = TransformBounds(worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix, val.sharedMesh.bounds); if (!flag) { bounds = val2; flag = true; } else { ((Bounds)(ref bounds)).Encapsulate(val2); } } } SkinnedMeshRenderer[] componentsInChildren2 = ((Component)root).GetComponentsInChildren<SkinnedMeshRenderer>(true); foreach (SkinnedMeshRenderer val3 in componentsInChildren2) { if (!((Object)(object)val3 == (Object)null)) { Bounds val4 = TransformBounds(worldToLocalMatrix * ((Component)val3).transform.localToWorldMatrix, ((Renderer)val3).localBounds); if (!flag) { bounds = val4; flag = true; } else { ((Bounds)(ref bounds)).Encapsulate(val4); } } } return flag; } private static bool TryGetBlueprintBounds(Transform root, out Bounds bounds) { //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_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_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_0057: 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_0070: 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_007a: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0080: 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) bounds = new Bounds(Vector3.zero, Vector3.zero); Matrix4x4 worldToLocalMatrix = root.worldToLocalMatrix; bool flag = false; MeshFilter[] componentsInChildren = ((Component)root).GetComponentsInChildren<MeshFilter>(true); foreach (MeshFilter val in componentsInChildren) { if (!((Object)(object)val == (Object)null) && !((Object)(object)val.sharedMesh == (Object)null) && UnderBlueprint(((Component)val).transform, root)) { Bounds val2 = TransformBounds(worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix, val.sharedMesh.bounds); if (!flag) { bounds = val2; flag = true; } else { ((Bounds)(ref bounds)).Encapsulate(val2); } } } return flag; } private static bool TryGetModelBounds(Transform root, out Bounds bounds) { //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_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_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_0070: 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_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_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 = new Bounds(Vector3.zero, Vector3.zero); Matrix4x4 worldToLocalMatrix = root.worldToLocalMatrix; bool flag = false; Transform val = root.Find("SafeHarborModel"); if ((Object)(object)val == (Object)null) { return false; } MeshFilter[] componentsInChildren = ((Component)val).GetComponentsInChildren<MeshFilter>(true); foreach (MeshFilter val2 in componentsInChildren) { if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.sharedMesh == (Object)null) && !((Object)(object)((Component)val2).GetComponentInParent<BerthLamp>() != (Object)null)) { Bounds val3 = TransformBounds(worldToLocalMatrix * ((Component)val2).transform.localToWorldMatrix, val2.sharedMesh.bounds); if (!flag) { bounds = val3; flag = true; } else { ((Bounds)(ref bounds)).Encapsulate(val3); } } } return flag; } interna