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 TradeWind v0.3.6
TradeWind.dll
Decompiled a day ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.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; using MyMods.Web; using Newtonsoft.Json; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.SceneManagement; [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("TradeWind")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.3.6.0")] [assembly: AssemblyInformationalVersion("0.3.6+c13f19c3b078d3d6a56a0c7fbbe49d5fd3c23638")] [assembly: AssemblyProduct("TradeWind")] [assembly: AssemblyTitle("TradeWind")] [assembly: AssemblyVersion("0.3.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 { public static class HallClient { private struct Pending { public string Id; public string Title; public int Order; public Action<Rect> Draw; } private static readonly List<Pending> s_pending = new List<Pending>(); private static Type s_type; private static bool s_miss; private static MethodInfo s_register; private static MethodInfo s_open; private static MethodInfo s_close; private static MethodInfo s_hosting; private static MethodInfo s_yield; private static MethodInfo s_hold; private static PropertyInfo s_ready; private static PropertyInfo s_openProp; private static Type HallType { get { if (s_type != null || s_miss) { return s_type; } s_type = Type.GetType("DFGHub.HallBoard, DFGHub"); s_miss = s_type == null; return s_type; } } public static bool Ready { get { if (s_ready == null && HallType != null) { s_ready = HallType.GetProperty("Ready", BindingFlags.Static | BindingFlags.Public); } if (s_ready == null) { return false; } object value = s_ready.GetValue(null, null); bool flag = default(bool); int num; if (value is bool) { flag = (bool)value; num = 1; } else { num = 0; } return (byte)((uint)num & (flag ? 1u : 0u)) != 0; } } public static bool IsOpen { get { if (s_openProp == null && HallType != null) { s_openProp = HallType.GetProperty("IsOpen", BindingFlags.Static | BindingFlags.Public); } if (s_openProp == null) { return false; } object value = s_openProp.GetValue(null, null); bool flag = default(bool); int num; if (value is bool) { flag = (bool)value; num = 1; } else { num = 0; } return (byte)((uint)num & (flag ? 1u : 0u)) != 0; } } public static void Bind(string id, string title, int order, Action<Rect> draw) { if (string.IsNullOrEmpty(id) || draw == null) { return; } for (int num = s_pending.Count - 1; num >= 0; num--) { if (string.Equals(s_pending[num].Id, id, StringComparison.OrdinalIgnoreCase)) { s_pending.RemoveAt(num); } } s_pending.Add(new Pending { Id = id, Title = title, Order = order, Draw = draw }); Flush(); } public static void Flush() { if (s_pending.Count != 0 && Ready) { for (int i = 0; i < s_pending.Count; i++) { Pending pending = s_pending[i]; TryRegister(pending.Id, pending.Title, pending.Order, pending.Draw); } s_pending.Clear(); } } public static bool TryOpen(string tabId) { if (!Ready) { return false; } if (s_open == null) { s_open = HallType.GetMethod("Open", BindingFlags.Static | BindingFlags.Public); } if (s_open == null) { return false; } try { object obj = s_open.Invoke(null, new object[1] { tabId }); bool flag = default(bool); int num; if (obj is bool) { flag = (bool)obj; num = 1; } else { num = 0; } return (byte)((uint)num & (flag ? 1u : 0u)) != 0; } catch (Exception) { return false; } } public static void Close() { if (HallType == null) { return; } if (s_close == null) { s_close = HallType.GetMethod("Close", BindingFlags.Static | BindingFlags.Public); } try { s_close?.Invoke(null, null); } catch (Exception) { } } public static bool IsHosting(string id) { if (HallType == null || string.IsNullOrEmpty(id)) { return false; } if (s_hosting == null) { s_hosting = HallType.GetMethod("IsHosting", BindingFlags.Static | BindingFlags.Public); } if (s_hosting == null) { return false; } try { object obj = s_hosting.Invoke(null, new object[1] { id }); bool flag = default(bool); int num; if (obj is bool) { flag = (bool)obj; num = 1; } else { num = 0; } return (byte)((uint)num & (flag ? 1u : 0u)) != 0; } catch (Exception) { return false; } } public static void SetYield(bool yieldScreen) { if (HallType == null) { return; } if (s_yield == null) { s_yield = HallType.GetMethod("SetYield", BindingFlags.Static | BindingFlags.Public); } try { s_yield?.Invoke(null, new object[1] { yieldScreen }); } catch (Exception) { } } public static void HoldEscape() { if (HallType == null) { return; } if (s_hold == null) { s_hold = HallType.GetMethod("HoldEscape", BindingFlags.Static | BindingFlags.Public); } try { s_hold?.Invoke(null, null); } catch (Exception) { } } private static void TryRegister(string id, string title, int order, Action<Rect> draw) { if (s_register == null) { s_register = HallType.GetMethod("Register", BindingFlags.Static | BindingFlags.Public); } s_register?.Invoke(null, new object[4] { id, title, order, draw }); } } } 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[14] { 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), new Link("transporter", "Transporter", 8791) }; 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 TradeWind { internal sealed class MainThreadQueue : MonoBehaviour { private readonly object m_lock = new object(); private readonly Queue<Action> m_actions = new Queue<Action>(); public void Post(Action action) { lock (m_lock) { m_actions.Enqueue(action); } } private void Update() { Action[] array = null; lock (m_lock) { if (m_actions.Count > 0) { array = m_actions.ToArray(); m_actions.Clear(); } } if (array == null) { return; } for (int i = 0; i < array.Length; i++) { try { array[i](); } catch (Exception ex) { TradeWindPlugin.Debug("main-thread task error: " + ex.Message); } } } } internal static class TradeWindAppearance { public const string ModelFileName = "tradedock.glb"; public const string ShipModelFileName = "thetradeship.glb"; public const float ModelLength = 12f; public const float ShipLength = 8f; public const float DeckWidth = 8f; public const float DeckLength = 6f; public const float PilingLength = 8f; internal static GameObject DockTemplate; internal static GameObject ShipTemplate; internal static Sprite DockIcon; internal static Sprite ShipIcon; private static GameObject m_holder; public static void ApplyDock(GameObject prefab) { //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: 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_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) //IL_023c: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_02c5: Unknown result type (might be due to invalid IL or missing references) //IL_02e7: 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("TradeWindDeck"); val4.transform.SetParent(prefab.transform, false); val4.transform.localScale = new Vector3(8f / num2, 1f, 6f / 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; } BoxCollider obj = prefab.AddComponent<BoxCollider>(); obj.size = new Vector3(8f, num, 6f); obj.center = new Vector3(0f, (0f - num) * 0.5f, 0f); if ((Object)(object)val2 != (Object)null) { float num4 = 3.4f; float num5 = 2.4f; float num6 = Mathf.Max(1f, 8f); 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 = "TradeWindPiling" + j; Object.DestroyImmediate((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.3f, num6 * 0.5f, 0.3f); ((Renderer)obj2.GetComponent<MeshRenderer>()).sharedMaterial = val2; } } BuildSign(prefab, val2); BuildSkiff(prefab, val2); } private static void BuildSign(GameObject prefab, Material material) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown //IL_0032: 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_009f: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("TradeWindDockSign"); val.transform.SetParent(prefab.transform, false); val.transform.localPosition = new Vector3(0f, 0.05f, -2.4f); GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)2); ((Object)val2).name = "SignPost"; Object.DestroyImmediate((Object)(object)val2.GetComponent<Collider>()); val2.transform.SetParent(val.transform, false); val2.transform.localPosition = new Vector3(0f, 1.1f, 0f); val2.transform.localScale = new Vector3(0.08f, 1.1f, 0.08f); if ((Object)(object)material != (Object)null) { ((Renderer)val2.GetComponent<MeshRenderer>()).sharedMaterial = material; } GameObject obj = GameObject.CreatePrimitive((PrimitiveType)3); ((Object)obj).name = "SignBoard"; Object.DestroyImmediate((Object)(object)obj.GetComponent<Collider>()); obj.transform.SetParent(val.transform, false); obj.transform.localPosition = new Vector3(0f, 2.4f, 0f); obj.transform.localScale = new Vector3(0.6f, 0.35f, 0.06f); BoxCollider obj2 = val.AddComponent<BoxCollider>(); ((Collider)obj2).isTrigger = false; obj2.center = new Vector3(0f, 1.3f, 0f); obj2.size = new Vector3(0.8f, 3f, 0.4f); val.AddComponent<TradeWindDockInteract>(); } private static void BuildSkiff(GameObject prefab, Material material) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_001c: 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_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Expected O, but got Unknown //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Expected O, but got Unknown //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Expected O, but got Unknown //IL_00da: 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_0109: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("TradeWindSkiff"); val.transform.SetParent(prefab.transform, false); val.transform.localPosition = new Vector3(0f, 0.05f, 3.35f); AddPart(val, (PrimitiveType)3, "Hull", new Vector3(0f, 0.12f, 0.15f), new Vector3(2.3f, 0.26f, 0.9f), material); AddPart(val, (PrimitiveType)3, "Bow", new Vector3(0f, 0.2f, 0.62f), new Vector3(1.15f, 0.14f, 0.32f), material); AddPart(val, (PrimitiveType)2, "Mast", new Vector3(0.15f, 0.7f, 0f), new Vector3(0.06f, 0.5f, 0.06f), material); BoxCollider obj = val.AddComponent<BoxCollider>(); obj.center = new Vector3(0f, 0.45f, 0.25f); obj.size = new Vector3(2.6f, 1.4f, 1.6f); val.AddComponent<TradeWindDockInteract>(); } private static void AddPart(GameObject parent, PrimitiveType type, string name, Vector3 localPos, Vector3 scale, Material material) { //IL_0000: 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_003d: Unknown result type (might be due to invalid IL or missing references) GameObject val = GameObject.CreatePrimitive(type); ((Object)val).name = name; Object.DestroyImmediate((Object)(object)val.GetComponent<Collider>()); val.transform.SetParent(parent.transform, false); val.transform.localPosition = localPos; val.transform.localScale = scale; if ((Object)(object)material != (Object)null) { MeshRenderer component = val.GetComponent<MeshRenderer>(); if ((Object)(object)component != (Object)null) { ((Renderer)component).sharedMaterial = material; } } } public static void AddNameSign(GameObject prefab, Vector3 localPosition) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown //IL_0023: 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_007b: 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_00ac: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("TradeWindNameSign"); val.transform.SetParent(prefab.transform, false); val.transform.localPosition = localPosition; GameObject obj = GameObject.CreatePrimitive((PrimitiveType)3); ((Object)obj).name = "NameBoard"; Object.DestroyImmediate((Object)(object)obj.GetComponent<Collider>()); obj.transform.SetParent(val.transform, false); obj.transform.localPosition = Vector3.zero; obj.transform.localScale = new Vector3(0.55f, 0.3f, 0.08f); BoxCollider obj2 = val.AddComponent<BoxCollider>(); ((Collider)obj2).isTrigger = false; obj2.center = Vector3.zero; obj2.size = new Vector3(0.7f, 0.45f, 0.2f); val.AddComponent<TradeWindNameInteract>(); } public static string FindModelPath(string fileName) { string directoryName = Path.GetDirectoryName(typeof(TradeWindPlugin).Assembly.Location); string pluginPath = Paths.PluginPath; string[] array = new string[4] { string.IsNullOrEmpty(directoryName) ? null : Path.Combine(directoryName, fileName), string.IsNullOrEmpty(pluginPath) ? null : Path.Combine(pluginPath, "DFG-TradeWind", fileName), string.IsNullOrEmpty(pluginPath) ? null : Path.Combine(pluginPath, "TradeWind", fileName), Path.Combine("C:\\Users\\dhugh\\Documents\\MyMods\\TradeWind", fileName) }; for (int i = 0; i < array.Length; i++) { if (!string.IsNullOrEmpty(array[i]) && File.Exists(array[i])) { return array[i]; } } return null; } public static bool ApplyModel(GameObject prefab, GameObject model) { //IL_00bd: 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_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_011a: 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_0161: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_017d: 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_0181: 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_0188: 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_0197: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: 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_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_0201: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_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_025c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)prefab == (Object)null || (Object)(object)model == (Object)null) { return false; } 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; } } Renderer[] componentsInChildren2 = prefab.GetComponentsInChildren<Renderer>(true); for (int j = 0; j < componentsInChildren2.Length; j++) { 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]); } } ((Object)model).name = "TradeWindModel"; model.transform.SetParent(prefab.transform, false); model.transform.localPosition = Vector3.zero; model.transform.localRotation = Quaternion.identity; model.transform.localScale = Vector3.one; if (!TryLocalBounds(model.transform, prefab.transform, out var min, out var max)) { Logger.LogWarning((object)"Trade Wind: dock model has no mesh bounds."); return false; } Vector3 val = max - min; float num = Mathf.Max(val.x, val.z); float num2 = 1f; if (num > 0.05f && (num < 4f || num > 24f)) { num2 = 12f / num; } model.transform.localScale = Vector3.one * num2; Vector3 val2 = min * num2; Vector3 val3 = max * num2; Vector3 val4 = val3 - val2; model.transform.localPosition = new Vector3((0f - (val2.x + val3.x)) * 0.5f, 0f - val2.y, (0f - (val2.z + val3.z)) * 0.5f); SetLayerRecursive(model, prefab.layer); GameObject val5 = new GameObject("TradeWindUse") { layer = InteractLayer() }; val5.transform.SetParent(prefab.transform, false); BoxCollider obj = val5.AddComponent<BoxCollider>(); obj.center = new Vector3(0f, val4.y * 0.5f, 0f); obj.size = new Vector3(Mathf.Max(0.6f, val4.x), Mathf.Max(0.6f, val4.y), Mathf.Max(0.6f, val4.z)); val5.AddComponent<TradeWindDockInteract>(); if ((Object)(object)prefab.GetComponent<TradeWindHideSource>() == (Object)null) { prefab.AddComponent<TradeWindHideSource>(); } int num3 = 0; MeshFilter[] componentsInChildren4 = model.GetComponentsInChildren<MeshFilter>(true); for (int l = 0; l < componentsInChildren4.Length; l++) { if ((Object)(object)componentsInChildren4[l] != (Object)null && (Object)(object)componentsInChildren4[l].sharedMesh != (Object)null) { num3 += componentsInChildren4[l].sharedMesh.vertexCount; } } Logger.LogInfo((object)("Trade Wind: dock model raw " + val.x.ToString("0.00") + " x " + val.y.ToString("0.00") + " x " + val.z.ToString("0.00") + " m, scale " + num2.ToString("0.00") + ", placed " + val4.x.ToString("0.00") + " x " + val4.y.ToString("0.00") + " x " + val4.z.ToString("0.00") + " m, " + num3 + " vertices.")); StashTemplate(model, ship: false); EnsureAttacher(prefab, ship: false); return true; } public static bool ApplyShipModel(GameObject prefab, GameObject model) { //IL_008e: 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_00ae: 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_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0127: 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_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_014c: 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_0162: Unknown result type (might be due to invalid IL or missing references) //IL_016a: 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_0180: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)prefab == (Object)null || (Object)(object)model == (Object)null) { return false; } LODGroup[] componentsInChildren = prefab.GetComponentsInChildren<LODGroup>(true); for (int i = 0; i < componentsInChildren.Length; i++) { if ((Object)(object)componentsInChildren[i] != (Object)null) { componentsInChildren[i].enabled = false; } } Renderer[] componentsInChildren2 = prefab.GetComponentsInChildren<Renderer>(true); for (int j = 0; j < componentsInChildren2.Length; j++) { componentsInChildren2[j].enabled = false; } ((Object)model).name = "TradeWindShipModel"; model.transform.SetParent(prefab.transform, false); model.transform.localPosition = Vector3.zero; model.transform.localRotation = Quaternion.identity; model.transform.localScale = Vector3.one; if (!TryLocalBounds(model.transform, prefab.transform, out var min, out var max)) { Logger.LogWarning((object)"Trade Wind: ship model has no mesh bounds."); return false; } Vector3 val = max - min; float num = Mathf.Max(val.x, val.z); float num2 = 1f; if (num > 0.05f) { num2 = 8f / num; } model.transform.localScale = Vector3.one * num2; Vector3 val2 = min * num2; Vector3 val3 = max * num2; Vector3 val4 = val3 - val2; model.transform.localPosition = new Vector3((0f - (val2.x + val3.x)) * 0.5f, 0f - val2.y, (0f - (val2.z + val3.z)) * 0.5f); SetLayerRecursive(model, prefab.layer); if ((Object)(object)prefab.GetComponent<TradeWindHideSource>() == (Object)null) { prefab.AddComponent<TradeWindHideSource>(); } int num3 = 0; MeshFilter[] componentsInChildren3 = model.GetComponentsInChildren<MeshFilter>(true); for (int k = 0; k < componentsInChildren3.Length; k++) { if ((Object)(object)componentsInChildren3[k] != (Object)null && (Object)(object)componentsInChildren3[k].sharedMesh != (Object)null) { num3 += componentsInChildren3[k].sharedMesh.vertexCount; } } Logger.LogInfo((object)("Trade Wind: ship model raw " + val.x.ToString("0.00") + " x " + val.y.ToString("0.00") + " x " + val.z.ToString("0.00") + " m, scale " + num2.ToString("0.00") + ", hull " + val4.x.ToString("0.00") + " x " + val4.y.ToString("0.00") + " x " + val4.z.ToString("0.00") + " m, " + num3 + " vertices.")); StashTemplate(model, ship: true); EnsureAttacher(prefab, ship: true); return true; } private static void StashTemplate(GameObject model, bool ship) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown if ((Object)(object)m_holder == (Object)null) { m_holder = new GameObject("TradeWindModelHolder"); m_holder.SetActive(false); Object.DontDestroyOnLoad((Object)(object)m_holder); } model.SetActive(false); model.transform.SetParent(m_holder.transform, false); if (ship) { ShipTemplate = model; } else { DockTemplate = model; } } private static void EnsureAttacher(GameObject prefab, bool ship) { TradeWindModelAttacher tradeWindModelAttacher = prefab.GetComponent<TradeWindModelAttacher>(); if ((Object)(object)tradeWindModelAttacher == (Object)null) { tradeWindModelAttacher = prefab.AddComponent<TradeWindModelAttacher>(); } tradeWindModelAttacher.Ship = ship; } public static Sprite PieceIcon(bool dock) { //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) if (dock) { if ((Object)(object)DockIcon == (Object)null) { DockIcon = SolidIcon(new Color(0.62f, 0.45f, 0.22f, 1f)); } return DockIcon; } if ((Object)(object)ShipIcon == (Object)null) { ShipIcon = SolidIcon(new Color(0.35f, 0.48f, 0.62f, 1f)); } return ShipIcon; } private static Sprite SolidIcon(Color color) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(16, 16, (TextureFormat)4, false); Color[] array = (Color[])(object)new Color[256]; for (int i = 0; i < array.Length; i++) { array[i] = color; } val.SetPixels(array); val.Apply(); return Sprite.Create(val, new Rect(0f, 0f, 16f, 16f), new Vector2(0.5f, 0.5f), 16f); } private static bool TryLocalBounds(Transform model, Transform space, out Vector3 min, out Vector3 max) { //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_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_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_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_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0098: 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_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) min = new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity); max = new Vector3(float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity); bool result = false; MeshFilter[] componentsInChildren = ((Component)model).GetComponentsInChildren<MeshFilter>(true); foreach (MeshFilter val in componentsInChildren) { if ((Object)(object)val == (Object)null || (Object)(object)val.sharedMesh == (Object)null) { continue; } Bounds bounds = val.sharedMesh.bounds; Vector3 size = ((Bounds)(ref bounds)).size; if (((Vector3)(ref size)).sqrMagnitude < 1E-06f) { continue; } Vector3 center = ((Bounds)(ref bounds)).center; Vector3 extents = ((Bounds)(ref bounds)).extents; for (int j = -1; j <= 1; j += 2) { for (int k = -1; k <= 1; k += 2) { for (int l = -1; l <= 1; l += 2) { Vector3 val2 = ((Component)val).transform.TransformPoint(center + new Vector3(extents.x * (float)j, extents.y * (float)k, extents.z * (float)l)); Vector3 val3 = space.InverseTransformPoint(val2); min = Vector3.Min(min, val3); max = Vector3.Max(max, val3); result = true; } } } } return result; } private static int InteractLayer() { //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) int num = 0; bool flag = false; if ((Object)(object)ZNetScene.instance != (Object)null) { GameObject prefab = ZNetScene.instance.GetPrefab("Player"); Player val = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<Player>() : null); if ((Object)(object)val != (Object)null) { FieldInfo field = typeof(Player).GetField("m_interactMask", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null && field.GetValue(val) is LayerMask val2) { num = ((LayerMask)(ref val2)).value; flag = true; } } } string[] array = new string[5] { "piece", "item", "Default", "piece_nonsolid", "static_solid" }; for (int i = 0; i < array.Length; i++) { int num2 = LayerMask.NameToLayer(array[i]); if (num2 >= 0 && (!flag || (num & (1 << num2)) != 0)) { return num2; } } return 0; } private static void SetLayerRecursive(GameObject root, int layer) { if (!((Object)(object)root == (Object)null)) { Transform[] componentsInChildren = root.GetComponentsInChildren<Transform>(true); for (int i = 0; i < componentsInChildren.Length; i++) { ((Component)componentsInChildren[i]).gameObject.layer = layer; } } } } public class TradeWindHideSource : MonoBehaviour { private bool m_hidden; private void OnEnable() { Hide(); } private void LateUpdate() { if (!m_hidden) { Hide(); m_hidden = true; } } private void Hide() { Transform val = ((Component)this).transform.Find("TradeWindModel"); if ((Object)(object)val == (Object)null) { val = ((Component)this).transform.Find("TradeWindShipModel"); } Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true); foreach (Renderer val2 in componentsInChildren) { if (!((Object)(object)val2 == (Object)null)) { if ((Object)(object)val != (Object)null && ((Object)(object)((Component)val2).transform == (Object)(object)val || ((Component)val2).transform.IsChildOf(val))) { val2.enabled = true; } else { val2.enabled = false; } } } } } public class TradeWindModelAttacher : MonoBehaviour { public bool Ship; private bool m_done; private void Update() { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) if (m_done) { return; } Scene scene = ((Component)this).gameObject.scene; if (!((Scene)(ref scene)).IsValid() || !ShouldShow()) { return; } GameObject val = (Ship ? TradeWindAppearance.ShipTemplate : TradeWindAppearance.DockTemplate); if ((Object)(object)val == (Object)null) { return; } string text = (Ship ? "TradeWindShipModel" : "TradeWindModel"); if ((Object)(object)((Component)this).transform.Find(text) != (Object)null) { m_done = true; return; } GameObject obj = Object.Instantiate<GameObject>(val); ((Object)obj).name = text; obj.transform.SetParent(((Component)this).transform, false); obj.SetActive(true); int layer = ((Component)this).gameObject.layer; Transform[] componentsInChildren = obj.GetComponentsInChildren<Transform>(true); for (int i = 0; i < componentsInChildren.Length; i++) { ((Component)componentsInChildren[i]).gameObject.layer = layer; } m_done = true; Logger.LogInfo((object)("Trade Wind: showing " + text + (Player.IsPlacementGhost(((Component)this).gameObject) ? " on the placement ghost." : "."))); } private bool ShouldShow() { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return false; } if (Player.IsPlacementGhost(((Component)this).gameObject)) { return true; } ZNetView component = ((Component)this).GetComponent<ZNetView>(); if ((Object)(object)component == (Object)null || component.GetZDO() == null) { return false; } return Vector3.Distance(((Component)this).transform.position, ((Component)localPlayer).transform.position) < 220f; } } public class TradeWindCargoItem { public string Prefab; public int Stack; public TradeWindCargoItem() { } public TradeWindCargoItem(string prefab, int stack) { Prefab = prefab; Stack = stack; } } public class TradeWindHarborData { public string Name; public float X; public float Y; public float Z; public string DockZdo; } public enum TradeWindPhase { Idle, Departing, Outbound, ArrivingDest, UnloadingDest, LoadingDest, Returning, ArrivingOrigin, UnloadingOrigin, Waiting } public class TradeWindRouteData { public string Id; public string Name; public TradeWindHarborData Origin; public TradeWindHarborData Destination; public string ShipName; public float ShipX; public float ShipY; public float ShipZ; public string ShipZdo; public TradeWindPhase Phase; public float RemainingSeconds; public float TotalSeconds; public float PathMeters; public int CoinCost; public bool OneWay; public List<TradeWindCargoItem> Cargo = new List<TradeWindCargoItem>(); } public class TradeWindFile { public int Version = 1; public List<TradeWindRouteData> Routes = new List<TradeWindRouteData>(); } public static class TradeWindZdo { [JsonIgnore] public static ZDOID None => ZDOID.None; public static string ToString(ZDOID id) { return ((ZDOID)(ref id)).UserID + ":" + ((ZDOID)(ref id)).ID; } public static ZDOID FromString(string text) { //IL_0008: 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_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) if (string.IsNullOrEmpty(text)) { return ZDOID.None; } string[] array = text.Split(':'); if (array.Length != 2) { return ZDOID.None; } if (!long.TryParse(array[0], out var result) || !uint.TryParse(array[1], out var result2)) { return ZDOID.None; } return new ZDOID(result, result2); } } public class TradeWindOffer { public string DockZdo; public string Name; public bool Connected; public bool Loaded; public float Meters; public float Seconds; public int Coins; } public class TradeWindDepot : MonoBehaviour { public static readonly List<TradeWindDepot> All = new List<TradeWindDepot>(); private ZNetView m_nview; private Container m_container; private bool m_registered; public ZDOID Uid { get { //IL_001b: 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) if ((Object)(object)m_nview == (Object)null || !m_nview.IsValid()) { return ZDOID.None; } return m_nview.GetZDO().m_uid; } } public Container Container => m_container; private void Awake() { m_nview = ((Component)this).GetComponent<ZNetView>(); m_container = ((Component)this).GetComponent<Container>(); } private void OnEnable() { //IL_0021: 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) if (!m_registered) { All.Add(this); m_registered = true; } TradeWindRegistry.RegisterDepot(this); TradeWindRegistry.RegisterContainer(Uid, "", "depot", ((Component)this).transform.position); } private void OnDisable() { if (m_registered) { All.Remove(this); m_registered = false; } } } public class TradeWindDock : MonoBehaviour { public const string KeyName = "TradeWind_name"; public const string KeyLoad = "TradeWind_load"; public const string KeyUnload = "TradeWind_unload"; public const string KeyTier = "TradeWind_tier"; public const string KeyIncoming = "TradeWind_in"; public static readonly List<TradeWindDock> All = new List<TradeWindDock>(); private ZNetView m_nview; private Container m_container; private bool m_registered; private bool m_sized; public ZDOID Uid { get { //IL_001b: 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) if ((Object)(object)m_nview == (Object)null || !m_nview.IsValid()) { return ZDOID.None; } return m_nview.GetZDO().m_uid; } } public Container Container => m_container; public ZNetView View => m_nview; public int Tier { get { int num = GetInt("TradeWind_tier", 1); if (num < 1) { num = 1; } if (num > 3) { num = 3; } return num; } set { Claim(); SetInt("TradeWind_tier", Mathf.Clamp(value, 1, 3)); m_sized = false; } } public string TierName => Tier switch { 2 => "Harbor", 3 => "Port", _ => "Wharf", }; public int SlotCount => 8 * HeightFor(Tier); public List<TradeWindCargoItem> Incoming => ReadIncoming(); public string Nickname { get { return GetString("TradeWind_name", ""); } set { Claim(); SetString("TradeWind_name", value); TradeWindRegistry.RegisterDock(this); } } public ZDOID LoadContainer { get { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return GetZDOID("TradeWind_load"); } set { //IL_000c: Unknown result type (might be due to invalid IL or missing references) Claim(); SetZDOID("TradeWind_load", value); } } public ZDOID UnloadContainer { get { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return GetZDOID("TradeWind_unload"); } set { //IL_000c: Unknown result type (might be due to invalid IL or missing references) Claim(); SetZDOID("TradeWind_unload", value); } } public Vector3 BerthPosition => ((Component)this).transform.TransformPoint(0f, 0f, TradeWindPlugin.DockBerthOffset.Value); public Quaternion BerthRotation => ((Component)this).transform.rotation; private void Awake() { m_nview = ((Component)this).GetComponent<ZNetView>(); m_container = ((Component)this).GetComponent<Container>(); } private void OnEnable() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) if (!m_registered) { All.Add(this); m_registered = true; } TradeWindRegistry.RegisterDock(this); TradeWindRegistry.RegisterContainer(Uid, Nickname, "dock", ((Component)this).transform.position); ApplySize(); } private void Update() { if (!m_sized) { ApplySize(); } } private void OnDisable() { if (m_registered) { All.Remove(this); m_registered = false; } } public static int HeightFor(int tier) { if (tier >= 3) { return 10; } if (tier >= 2) { return 8; } return 6; } public static int UpgradeCost(int tier) { if (tier <= 1) { return 40; } if (tier == 2) { return 90; } return 0; } public Vector3 HoldPoint() { //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_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0059: 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) Vector3 berthPosition = BerthPosition; Vector3 forward = ((Component)this).transform.forward; forward.y = 0f; if (((Vector3)(ref forward)).sqrMagnitude < 0.01f) { forward = Vector3.forward; } ((Vector3)(ref forward)).Normalize(); Vector3 result = berthPosition + forward * 8f; result.y = berthPosition.y; return result; } public void ApplySize() { //IL_0066: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)m_container == (Object)null) { m_container = ((Component)this).GetComponent<Container>(); } Inventory val = (((Object)(object)m_container != (Object)null) ? m_container.GetInventory() : null); if (val != null) { int num = HeightFor(Tier); m_container.m_width = 8; m_container.m_height = num; m_container.m_privacy = (PrivacySetting)2; if (val.GetHeight() < num) { val.SetHeight(num); } m_sized = true; } } public bool TryStoreIncoming(string prefab, int amount) { if (string.IsNullOrEmpty(prefab) || amount <= 0) { return true; } List<TradeWindCargoItem> list = ReadIncoming(); for (int i = 0; i < list.Count; i++) { if (list[i] != null && list[i].Prefab == prefab) { list[i].Stack += amount; WriteIncoming(list); return true; } } if (list.Count >= SlotCount) { return false; } list.Add(new TradeWindCargoItem(prefab, amount)); WriteIncoming(list); return true; } public string TakeIncoming(int index) { List<TradeWindCargoItem> list = ReadIncoming(); if (index < 0 || index >= list.Count || list[index] == null) { return "Nothing in that slot."; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || ((Humanoid)localPlayer).GetInventory() == null) { return "No inventory."; } TradeWindCargoItem tradeWindCargoItem = list[index]; GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(tradeWindCargoItem.Prefab) : null); if ((Object)(object)val == (Object)null) { return "That good is missing."; } if (!((Humanoid)localPlayer).GetInventory().AddItem(val, tradeWindCargoItem.Stack)) { return "Your inventory is full."; } list.RemoveAt(index); WriteIncoming(list); return "Took " + tradeWindCargoItem.Stack + " " + tradeWindCargoItem.Prefab + "."; } public void Claim() { if ((Object)(object)m_nview != (Object)null && m_nview.IsValid() && !m_nview.IsOwner()) { m_nview.ClaimOwnership(); } } private List<TradeWindCargoItem> ReadIncoming() { string text = GetString("TradeWind_in", ""); if (string.IsNullOrEmpty(text)) { return new List<TradeWindCargoItem>(); } try { return JsonConvert.DeserializeObject<List<TradeWindCargoItem>>(text) ?? new List<TradeWindCargoItem>(); } catch (Exception) { return new List<TradeWindCargoItem>(); } } private void WriteIncoming(List<TradeWindCargoItem> items) { Claim(); SetString("TradeWind_in", JsonConvert.SerializeObject((object)(items ?? new List<TradeWindCargoItem>()))); } private int GetInt(string key, int def) { if ((Object)(object)m_nview == (Object)null || !m_nview.IsValid()) { return def; } return m_nview.GetZDO().GetInt(key, def); } private void SetInt(string key, int value) { if ((Object)(object)m_nview != (Object)null && m_nview.IsValid()) { m_nview.GetZDO().Set(key, value); } } private string GetString(string key, string def) { if ((Object)(object)m_nview == (Object)null || !m_nview.IsValid()) { return def; } return m_nview.GetZDO().GetString(key, def); } private void SetString(string key, string value) { if ((Object)(object)m_nview != (Object)null && m_nview.IsValid()) { m_nview.GetZDO().Set(key, value); } } private ZDOID GetZDOID(string key) { //IL_001b: 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) if ((Object)(object)m_nview == (Object)null || !m_nview.IsValid()) { return ZDOID.None; } return m_nview.GetZDO().GetZDOID(key); } private void SetZDOID(string key, ZDOID value) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)m_nview != (Object)null && m_nview.IsValid()) { m_nview.GetZDO().Set(key, value); } } } public class TradeWindDockInteract : MonoBehaviour, Interactable, Hoverable { public bool Interact(Humanoid character, bool hold, bool alt) { TradeWindDock tradeWindDock = (((Object)(object)((Component)this).transform.root != (Object)null) ? ((Component)((Component)this).transform.root).GetComponent<TradeWindDock>() : null); if ((Object)(object)tradeWindDock == (Object)null) { return false; } if (TradeWindGui.ChestModifier(alt)) { TradeWindGui.OpenStorage(tradeWindDock); return true; } TradeWindGui.OpenFor(tradeWindDock); return true; } public bool UseItem(Humanoid user, ItemData item) { return false; } public string GetHoverText() { return "[E] Trade routes\n[Shift+E] Outgoing storage"; } public string GetHoverName() { TradeWindDock tradeWindDock = (((Object)(object)((Component)this).transform.root != (Object)null) ? ((Component)((Component)this).transform.root).GetComponent<TradeWindDock>() : null); if ((Object)(object)tradeWindDock != (Object)null && !string.IsNullOrEmpty(tradeWindDock.Nickname)) { return tradeWindDock.Nickname; } return "Trade dock"; } public float GetHoverOffset() { return 0f; } } public static class TradeWindGlb { private struct PendingMaterial { public Material Material; public Texture Albedo; } [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; } private static readonly List<PendingMaterial> s_pending = new List<PendingMaterial>(); private static float s_nextRepair; public static GameObject Load(string glbPath, Material sourceMaterial) { if (string.IsNullOrEmpty(glbPath) || !File.Exists(glbPath)) { Logger.LogWarning((object)("Trade Wind: model file not found: " + glbPath)); return null; } Logger.LogInfo((object)("Trade Wind: loading model: " + glbPath)); byte[] data; try { data = File.ReadAllBytes(glbPath); } catch (Exception ex) { Logger.LogError((object)("Trade Wind: could not read model file: " + ex.Message)); return null; } return ParseGLB(data, sourceMaterial, glbPath); } private static GameObject ParseGLB(byte[] data, Material sourceMaterial, string path) { if (data == null || data.Length < 20) { return null; } if (BitConverter.ToUInt32(data, 0) != 1179937895) { Logger.LogWarning((object)("Trade Wind: '" + path + "' is not a GLB file (bad magic).")); return null; } Logger.LogInfo((object)("Trade Wind: 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)"Trade Wind: no JSON chunk found in GLB."); return null; } return ParseGLTF(text, array, sourceMaterial); } private static GameObject ParseGLTF(string json, byte[] binData, Material sourceMaterial) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown //IL_06a9: Unknown result type (might be due to invalid IL or missing references) //IL_06af: 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_0994: Unknown result type (might be due to invalid IL or missing references) //IL_070b: Unknown result type (might be due to invalid IL or missing references) //IL_0757: 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_09b0: Unknown result type (might be due to invalid IL or missing references) //IL_09b5: Unknown result type (might be due to invalid IL or missing references) //IL_09b9: Unknown result type (might be due to invalid IL or missing references) //IL_09be: Unknown result type (might be due to invalid IL or missing references) //IL_0798: Unknown result type (might be due to invalid IL or missing references) //IL_0a4a: Unknown result type (might be due to invalid IL or missing references) //IL_0a4f: Unknown result type (might be due to invalid IL or missing references) //IL_0a6f: Unknown result type (might be due to invalid IL or missing references) //IL_0a74: Unknown result type (might be due to invalid IL or missing references) //IL_0a94: Unknown result type (might be due to invalid IL or missing references) //IL_0a99: Unknown result type (might be due to invalid IL or missing references) //IL_09ea: Unknown result type (might be due to invalid IL or missing references) //IL_09d7: Unknown result type (might be due to invalid IL or missing references) //IL_09dc: Unknown result type (might be due to invalid IL or missing references) //IL_056b: Unknown result type (might be due to invalid IL or missing references) //IL_0570: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("TradeWindModel"); try { GLTFRoot gLTFRoot = JsonConvert.DeserializeObject<GLTFRoot>(json); if (gLTFRoot == null) { Logger.LogWarning((object)"Trade Wind: failed to parse GLTF JSON."); return null; } Logger.LogInfo((object)("Trade Wind: 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[] array9 = new byte[gLTFBufferView.byteLength]; Buffer.BlockCopy(binData, gLTFBufferView.byteOffset, array9, 0, gLTFBufferView.byteLength); Texture2D val9 = new Texture2D(2, 2, (TextureFormat)4, false); if (!ImageConversion.LoadImage(val9, array9)) { 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; Vector3[] vertices = null; Vector3[] normals = null; Vector2[] uvs = null; int[] indices = null; if (gLTFPrimitive.attributes != null && gLTFPrimitive.attributes.POSITION >= 0 && gLTFPrimitive.attributes.POSITION < array.Length) { vertices = ReadVec3Accessor(array[gLTFPrimitive.attributes.POSITION], bufferViews, binData); } if (gLTFPrimitive.attributes != null && gLTFPrimitive.attributes.NORMAL >= 0 && gLTFPrimitive.attributes.NORMAL < array.Length) { normals = ReadVec3Accessor(array[gLTFPrimitive.attributes.NORMAL], bufferViews, binData); } if (gLTFPrimitive.attributes != null && gLTFPrimitive.attributes.TEXCOORD_0 >= 0 && gLTFPrimitive.attributes.TEXCOORD_0 < array.Length) { uvs = ReadVec2Accessor(array[gLTFPrimitive.attributes.TEXCOORD_0], bufferViews, binData); } if (gLTFPrimitive.indices >= 0 && gLTFPrimitive.indices < array.Length) { indices = ReadIndicesAccessor(array[gLTFPrimitive.indices], bufferViews, binData); if (indices != null) { for (int num4 = 0; num4 + 2 < indices.Length; num4 += 3) { int num5 = indices[num4]; indices[num4] = indices[num4 + 1]; indices[num4 + 1] = num5; } } } if (vertices != null && vertices.Length > 60000) { int num6 = vertices.Length; int num7 = ((indices != null) ? (indices.Length / 3) : 0); Simplify(ref vertices, ref normals, ref uvs, ref indices); Logger.LogInfo((object)("Trade Wind: simplified mesh " + num6 + " vertices / " + num7 + " triangles -> " + vertices.Length + " vertices / " + ((indices != null) ? (indices.Length / 3) : 0) + " triangles.")); } if (vertices != null) { val6.vertices = vertices; } if (uvs != null && uvs.Length == val6.vertexCount) { val6.uv = uvs; } if (indices != null && indices.Length >= 3) { val6.triangles = indices; } if (normals != null && normals.Length == val6.vertexCount) { val6.normals = normals; } else if (val6.vertexCount > 0) { val6.RecalculateNormals(); } int vertexCount = val6.vertexCount; if (vertexCount > 0) { Color[] array6 = (Color[])(object)new Color[vertexCount]; for (int num8 = 0; num8 < vertexCount; num8++) { array6[num8] = Color.white; } val6.colors = array6; } val6.RecalculateBounds(); val4.mesh = val6; if (gLTFPrimitive.material >= 0 && gLTFPrimitive.material < array3.Length) { GLTFMaterial gLTFMaterial = array3[gLTFPrimitive.material]; Texture2D baseTexture = null; int num9 = ((gLTFMaterial.pbrMetallicRoughness != null && gLTFMaterial.pbrMetallicRoughness.baseColorTexture != null) ? gLTFMaterial.pbrMetallicRoughness.baseColorTexture.index : (-1)); if (num9 >= 0 && num9 < array5.Length) { baseTexture = func(array5[num9].source); } ((Renderer)val5).sharedMaterials = CreateMaterial(gLTFMaterial, sourceMaterial, baseTexture); } else { ((Renderer)val5).sharedMaterial = CreateFallbackMaterial(sourceMaterial); } } dictionary[num2] = val2; } if (array4.Length != 0) { GameObject[] array7 = (GameObject[])(object)new GameObject[array4.Length]; for (int num10 = 0; num10 < array4.Length; num10++) { array7[num10] = new GameObject((!string.IsNullOrEmpty(array4[num10].name)) ? array4[num10].name : ("Node_" + num10)); } for (int num11 = 0; num11 < array4.Length; num11++) { GLTFNode gLTFNode2 = array4[num11]; GameObject val7 = array7[num11]; 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 num12 = 0; num12 < gLTFNode2.children.Length; num12++) { int num13 = gLTFNode2.children[num12]; if (num13 >= 0 && num13 < array7.Length) { array7[num13].transform.SetParent(val7.transform, false); } } } bool flag = false; if (gLTFRoot.scenes != null) { for (int num14 = 0; num14 < gLTFRoot.scenes.Length; num14++) { if (flag) { break; } GLTFScene gLTFScene = gLTFRoot.scenes[num14]; if (gLTFScene == null || gLTFScene.nodes == null) { continue; } for (int num15 = 0; num15 < gLTFScene.nodes.Length; num15++) { int num16 = gLTFScene.nodes[num15]; if (num16 >= 0 && num16 < array7.Length) { array7[num16].transform.SetParent(val.transform, false); flag = true; } } } } if (!flag) { for (int num17 = 0; num17 < array7.Length; num17++) { if ((Object)(object)array7[num17].transform.parent == (Object)null) { array7[num17].transform.SetParent(val.transform, false); } } } } else { foreach (GameObject value4 in dictionary.Values) { value4.transform.SetParent(val.transform, false); } } int num18 = 0; MeshRenderer[] componentsInChildren = val.GetComponentsInChildren<MeshRenderer>(true); for (int num19 = 0; num19 < componentsInChildren.Length; num19++) { num18 += ((((Renderer)componentsInChildren[num19]).sharedMaterials != null) ? ((Renderer)componentsInChildren[num19]).sharedMaterials.Length : 0); } Bounds val8 = default(Bounds); bool flag2 = true; Renderer[] componentsInChildren2 = val.GetComponentsInChildren<Renderer>(true); Vector3 size; for (int num20 = 0; num20 < componentsInChildren2.Length; num20++) { Bounds bounds = componentsInChildren2[num20].bounds; size = ((Bounds)(ref bounds)).size; if (!(((Vector3)(ref size)).sqrMagnitude < 0.0001f)) { if (flag2) { val8 = componentsInChildren2[num20].bounds; flag2 = false; } else { ((Bounds)(ref val8)).Encapsulate(componentsInChildren2[num20].bounds); } } } string[] obj = new string[6] { "Trade Wind: model ready - ", componentsInChildren.Length.ToString(), " renderers, ", num18.ToString(), " primitives, bounds ", null }; object obj2; if (!flag2) { string[] array8 = new string[5]; size = ((Bounds)(ref val8)).size; array8[0] = size.x.ToString("0.##"); array8[1] = " x "; size = ((Bounds)(ref val8)).size; array8[2] = size.y.ToString("0.##"); array8[3] = " x "; size = ((Bounds)(ref val8)).size; array8[4] = size.z.ToString("0.##"); obj2 = string.Concat(array8); } else { obj2 = "none"; } obj[5] = (string)obj2; Logger.LogInfo((object)string.Concat(obj)); return val; } catch (Exception ex) { Logger.LogError((object)("Trade Wind: 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 void Simplify(ref Vector3[] vertices, ref Vector3[] normals, ref Vector2[] uvs, ref int[] indices) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0021: 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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0067: 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_0074: 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_0116: 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_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_019d: 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_02bf: Unknown result type (might be due to invalid IL or missing references) //IL_02c4: 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_02d1: Unknown result type (might be due to invalid IL or missing references) //IL_02d3: Unknown result type (might be due to invalid IL or missing references) //IL_02d5: Unknown result type (might be due to invalid IL or missing references) //IL_02da: Unknown result type (might be due to invalid IL or missing references) //IL_02dc: Unknown result type (might be due to invalid IL or missing references) //IL_02de: Unknown result type (might be due to invalid IL or missing references) //IL_02e3: Unknown result type (might be due to invalid IL or missing references) //IL_02e8: Unknown result type (might be due to invalid IL or missing references) //IL_0338: Unknown result type (might be due to invalid IL or missing references) //IL_0341: Unknown result type (might be due to invalid IL or missing references) //IL_0346: Unknown result type (might be due to invalid IL or missing references) //IL_034f: Unknown result type (might be due to invalid IL or missing references) //IL_0354: 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_030c: Unknown result type (might be due to invalid IL or missing references) //IL_0311: Unknown result type (might be due to invalid IL or missing references) //IL_031a: Unknown result type (might be due to invalid IL or missing references) //IL_0323: Unknown result type (might be due to invalid IL or missing references) //IL_0328: Unknown result type (might be due to invalid IL or missing references) //IL_032d: Unknown result type (might be due to invalid IL or missing references) //IL_0359: Unknown result type (might be due to invalid IL or missing references) //IL_0369: Unknown result type (might be due to invalid IL or missing references) //IL_035e: Unknown result type (might be due to invalid IL or missing references) //IL_036e: Unknown result type (might be due to invalid IL or missing references) //IL_037e: Unknown result type (might be due to invalid IL or missing references) //IL_0373: Unknown result type (might be due to invalid IL or missing references) //IL_0383: Unknown result type (might be due to invalid IL or missing references) //IL_0393: Unknown result type (might be due to invalid IL or missing references) //IL_0388: Unknown result type (might be due to invalid IL or missing references) //IL_0398: Unknown result type (might be due to invalid IL or missing references) //IL_039a: Unknown result type (might be due to invalid IL or missing references) //IL_039c: Unknown result type (might be due to invalid IL or missing references) //IL_03c5: Unknown result type (might be due to invalid IL or missing references) //IL_03ca: Unknown result type (might be due to invalid IL or missing references) //IL_03ce: Unknown result type (might be due to invalid IL or missing references) //IL_03d7: Unknown result type (might be due to invalid IL or missing references) //IL_03e0: Unknown result type (might be due to invalid IL or missing references) //IL_03e9: Unknown result type (might be due to invalid IL or missing references) //IL_03f2: Unknown result type (might be due to invalid IL or missing references) //IL_03fb: Unknown result type (might be due to invalid IL or missing references) //IL_03aa: Unknown result type (might be due to invalid IL or missing references) //IL_03ac: Unknown result type (might be due to invalid IL or missing references) //IL_03ae: Unknown result type (might be due to invalid IL or missing references) //IL_03b0: Unknown result type (might be due to invalid IL or missing references) //IL_03b2: Unknown result type (might be due to invalid IL or missing references) //IL_03b4: Unknown result type (might be due to invalid IL or missing references) //IL_03b6: Unknown result type (might be due to invalid IL or missing references) //IL_03b8: Unknown result type (might be due to invalid IL or missing references) //IL_03ba: Unknown result type (might be due to invalid IL or missing references) //IL_03bc: Unknown result type (might be due to invalid IL or missing references) //IL_03c1: Unknown result type (might be due to invalid IL or missing references) //IL_0408: Unknown result type (might be due to invalid IL or missing references) //IL_0411: Unknown result type (might be due to invalid IL or missing references) //IL_041a: Unknown result type (might be due to invalid IL or missing references) if (vertices == null || vertices.Length == 0 || indices == null || indices.Length < 3) { return; } Vector3 val = vertices[0]; Vector3 val2 = vertices[0]; for (int i = 1; i < vertices.Length; i++) { val = Vector3.Min(val, vertices[i]); val2 = Vector3.Max(val2, vertices[i]); } float num = Mathf.Max(val2.x - val.x, Mathf.Max(val2.y - val.y, val2.z - val.z)); if (num < 0.0001f) { return; } bool flag = uvs != null && uvs.Length == vertices.Length; bool flag2 = normals != null && normals.Length == vertices.Length; float num2 = 48f; Vector3[] array = null; Vector3[] array2 = null; Vector2[] array3 = null; int[] array4 = null; for (int j = 0; j < 5; j++) { float num3 = num / num2; if (num3 < 1E-05f) { break; } Dictionary<long, int> dictionary = new Dictionary<long, int>(4096); List<Vector3> list = new List<Vector3>(4096); int[] array5 = new int[vertices.Length]; for (int k = 0; k < vertices.Length; k++) { Vector3 val3 = vertices[k]; int num4 = Mathf.Max(0, (int)((val3.x - val.x) / num3)); int num5 = Mathf.Max(0, (int)((val3.y - val.y) / num3)); int num6 = Mathf.Max(0, (int)((val3.z - val.z) / num3)); long key = ((long)num4 << 42) | ((long)num5 << 21) | (uint)num6; if (!dictionary.TryGetValue(key, out var value)) { value = list.Count; dictionary.Add(key, value); list.Add(val3); } array5[k] = value; } HashSet<long> hashSet = new HashSet<long>(); List<Vector3> list2 = new List<Vector3>(16384); List<Vector3> list3 = new List<Vector3>(16384); List<Vector2> list4 = (flag ? new List<Vector2>(16384) : null); for (int l = 0; l + 2 < indices.Length; l += 3) { int num7 = indices[l]; int num8 = indices[l + 1]; int num9 = indices[l + 2]; if ((uint)num7 >= (uint)array5.Length || (uint)num8 >= (uint)array5.Length || (uint)num9 >= (uint)array5.Length) { continue; } int num10 = array5[num7]; int num11 = array5[num8]; int num12 = array5[num9]; if (num10 == num11 || num11 == num12 || num12 == num10) { continue; } int num13 = Mathf.Min(num10, Mathf.Min(num11, num12)); int num14 = Mathf.Max(num10, Mathf.Max(num11, num12)); int num15 = num10 + num11 + num12 - num13 - num14; if (!hashSet.Add(((long)num13 << 42) | ((long)num15 << 21) | (uint)num14)) { continue; } Vector3 val4 = list[num10]; Vector3 val5 = list[num11]; Vector3 val6 = list[num12]; Vector3 val7 = Vector3.Cross(val5 - val4, val6 - val4); if (!(((Vector3)(ref val7)).sqrMagnitude < 1E-14f)) { Vector3 val8 = (flag2 ? (normals[num7] + normals[num8] + normals[num9]) : Vector3.Cross(vertices[num8] - vertices[num7], vertices[num9] - vertices[num7])); Vector2 item = (flag ? uvs[num7] : Vector2.zero); Vector2 val9 = (flag ? uvs[num8] : Vector2.zero); Vector2 val10 = (flag ? uvs[num9] : Vector2.zero); if (Vector3.Dot(val7, val8) < 0f) { Vector3 val11 = val5; val5 = val6; val6 = val11; Vector2 val12 = val9; val9 = val10; val10 = val12; val7 = -val7; } Vector3 normalized = ((Vector3)(ref val7)).normalized; list2.Add(val4); list2.Add(val5); list2.Add(val6); list3.Add(normalized); list3.Add(normalized); list3.Add(normalized); if (list4 != null) { list4.Add(item); list4.Add(val9); list4.Add(val10); } } } array = list2.ToArray(); array2 = list3.ToArray(); array3 = list4?.ToArray(); if (array.Length <= 60000 && array.Length >= 3) { break; } num2 *= 0.65f; } if (array != null && array.Length >= 3) { array4 = new int[array.Length]; for (int m = 0; m < array4.Length; m++) { array4[m] = m; } vertices = array; normals = array2; uvs = array3; indices = array4; } } internal static void RepairMaterials() { if (s_pending.Count == 0 || Time.time < s_nextRepair) { return; } s_nextRepair = Time.time + 1f; Material val = FindLiveCreatureMaterial(); if ((Object)(object)val == (Object)null) { return; } for (int num = s_pending.Count - 1; num >= 0; num--) { Material material = s_pending[num].Material; if ((Object)(object)material == (Object)null) { s_pending.RemoveAt(num); } else if (ApplyCreatureAlbedo(material, val, s_pending[num].Albedo)) { s_pending.RemoveAt(num); } } } private static Material[] CreateMaterial(GLTFMaterial mat, Material sourceMaterial, Texture2D baseTexture) { //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Expected O, but got Unknown //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected O, but got Unknown string name = ((!string.IsNullOrEmpty(mat.name)) ? mat.name : "DockMaterial"); Material val = (IsCreatureMaterial(sourceMaterial) ? sourceMaterial : FindLiveCreatureMaterial()); Material val2; if ((Object)(object)val != (Object)null && (Object)(object)val.shader != (Object)null) { val2 = new Material(val.shader); ((Object)val2).name = name; if (!ApplyCreatureAlbedo(val2, val, (Texture)(object)baseTexture)) { s_pending.Add(new PendingMaterial { Material = val2, Albedo = (Texture)(object)baseTexture }); } } else { val2 = new Material(Shader.Find("Hidden/InternalErrorShader") ?? Shader.Find("Sprites/Default")); ((Object)val2).name = name; if ((Object)(object)baseTexture != (Object)null) { val2.mainTexture = (Texture)(object)baseTexture; } s_pending.Add(new PendingMaterial { Material = val2, Albedo = (Texture)(object)baseTexture }); Logger.LogInfo((object)("Trade Wind: material is waiting for a creature shader, albedo " + (((Object)(object)baseTexture != (Object)null) ? (((Texture)baseTexture).width + "x" + ((Texture)baseTexture).height) : "missing") + ".")); } return (Material[])(object)new Material[1] { val2 }; } private static bool ApplyCreatureAlbedo(Material material, Material live, Texture albedo) { //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)material == (Object)null || (Object)(object)live == (Object)null || (Object)(object)live.shader == (Object)null || !IsCreatureMaterial(live)) { return false; } string name = ((Object)live.shader).name; material.shader = live.shader; material.shaderKeywords = Array.Empty<string>(); CopyFloat(live, material, "_Hue"); CopyFloat(live, material, "_Saturation"); CopyFloat(live, material, "_Value"); material.color = Color.white; if (material.HasProperty("_Color")) { material.SetColor("_Color", Color.white); } if (material.HasProperty("_Cull")) { material.SetFloat("_Cull", 0f); } material.renderQueue = 2000; if ((Object)(object)albedo != (Object)null) { material.mainTexture = albedo; if (material.HasProperty("_MainTex")) { material.SetTexture("_MainTex", albedo); } material.mainTextureScale = Vector2.one; material.mainTextureOffset = Vector2.zero; } string text = (((Object)(object)material.shader != (Object)null) ? ((Object)material.shader).name : "none"); bool result = text.IndexOf("InternalError", StringComparison.Ordinal) < 0 && !text.StartsWith("Hidden/", StringComparison.Ordinal); Logger.LogInfo((object)("Trade Wind: shader '" + name + "' -> '" + text + "', albedo " + (((Object)(object)albedo != (Object)null) ? (albedo.width + "x" + albedo.height) : "missing") + ".")); return result; } private static void CopyFloat(Material from, Material to, string property) { if ((Object)(object)from != (Object)null && (Object)(object)to != (Object)null && from.HasProperty(property) && to.HasProperty(property)) { to.SetFloat(property, from.GetFloat(property)); } } private static bool IsCreatureMaterial(Material material) { if ((Object)(object)material == (Object)null || (Object)(object)material.shader == (Object)null) { return false; } string name = ((Object)material.shader).name; if (name.IndexOf("Creature", StringComparison.Ordinal) >= 0 && name.IndexOf("InternalError", StringComparison.Ordinal) < 0) { return !name.StartsWith("Hidden/", StringComparison.Ordinal); } return false; } private static Material FindLiveCreatureMaterial() { if ((Object)(object)ZNetScene.instance == (Object)null) { return null; } string[] array = new string[5] { "Greydwarf", "Boar", "Deer", "Skeleton", "Wolf" }; for (int i = 0; i < array.Length; i++) { GameObject prefab = ZNetScene.instance.GetPrefab(array[i]); if ((Object)(object)prefab == (Object)null) { continue; } Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true); for (int j = 0; j < componentsInChildren.Length; j++) { if ((Object)(object)componentsInChildren[j] == (Object)null) { continue; } Material[] sharedMaterials = componentsInChildren[j].sharedMaterials; if (sharedMaterials == null) { continue; } for (int k = 0; k < sharedMaterials.Length; k++) { if (IsCreatureMaterial(sharedMaterials[k])) { return sharedMaterials[k]; } } } } return null; } private static Material CreateFallbackMaterial(Material sourceMaterial) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Expected O, but got Unknown //IL_004f: Unknown result type (might be due to invalid IL or missing references) Shader val = Shader.Find("Hidden/InternalErrorShader") ?? Shader.Find("Sprites/Default"); Material val2 = (IsCreatureMaterial(sourceMaterial) ? sourceMaterial : FindLiveCreatureMaterial()); Material val3 = (((Object)(object)val2 != (Object)null && (Object)(object)val2.shader != (Object)null) ? new Material(val2.shader) : new Material(val)); ((Object)val3).name = "DockMaterial"; if ((Object)(object)val2 == (Object)null || !ApplyCreatureAlbedo(val3, val2, null)) { s_pending.Add(new PendingMaterial { Material = val3, Albedo = null }); } return val3; } } public static class TradeWindGui { public static bool Visible; public static bool Typing; internal static bool OpeningContainer; private static TradeWindDock m_dock; private static string m_editName = ""; private static string m_status; private static float m_statusTimer; private static Vector2 m_scroll; private static Vector2 m_listScroll; private static Vector2 m_inScroll; private static float m_offerAt = -100f; private static List<TradeWindOffer> m_offers; private static int m_stacks; private static int m_shipsReady; private static string m_renameZdo; private static string m_renameKind; private static string m_renameName; private static Rect m_panel; private static bool m_dragging; private static Vector2 m_dragOffset; private static Texture2D m_white; private static readonly Color ColBackdrop = new Color(0f, 0f, 0f, 0.4f); private static readonly Color ColWindowBg = new Color(0.08f, 0.1f, 0.14f, 0.98f); private static readonly Color ColWindowBorder = new Color(0.74f, 0.58f, 0.28f, 1f); private static readonly Color ColWindowBorderInner = new Color(0.18f, 0.23f, 0.32f, 0.85f); private static readonly Color ColCardBg = new Color(0.09f, 0.11f, 0.16f, 0.96f); private static readonly Color ColCardBorder = new Color(0.22f, 0.28f, 0.38f, 0.85f); private static readonly Color ColCardHeaderBg = new Color(0.12f, 0.16f, 0.22f, 1f); private static readonly Color ColGold = new Color(1f, 0.84f, 0.38f, 1f); private static readonly Color ColWhite = new Color(0.92f, 0.95f, 0.98f, 1f); private static readonly Color ColMuted = new Color(0.6f, 0.66f, 0.75f, 1f); private static readonly Color ColCyan = new Color(0.4f, 0.8f, 1f, 1f); private static readonly Color ColGreen = new Color(0.38f, 0.88f, 0.48f, 1f); private static readonly Color ColRed = new Color(0.95f, 0.38f, 0.38f, 1f); private static readonly Dictionary<string, GUIStyle> m_styles = new Dictionary<string, GUIStyle>(); private static GUIStyle m_field; public static void Toggle() { if (Visible && (Object)(object)m_dock == (Object)null && string.IsNullOrEmpty(m_renameZdo)) { Close(); } else { OpenBoard(); } } public static void OpenBoard() { m_dock = null; m_renameZdo = null; m_status = null; if (HallClient.TryOpen("tradewind")) { Visible = false; } else { Visible = true; } } internal static bool ChestModifier(bool alt) { if (alt || ZInput.GetButton("AltPlace")) { return true; } if (!Input.GetKey((KeyCode)304)) { return Input.GetKey((KeyCode)303); } return true; } public static void OpenStorage(TradeWindDock dock) { if (!((Object)(object)dock == (Object)null) && !((Object)(object)dock.Container == (Object)null)) { m_dock = dock; OpenContainer(dock.Container); } } public static void OpenFor(TradeWindDock dock) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)dock == (Object)null))