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 Transporter v1.0.1
Transporter.dll
Decompiled 9 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Net; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using System.Threading; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Microsoft.CodeAnalysis; using MyMods.Web; using Newtonsoft.Json; using UnityEngine; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Transporter")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.1.0")] [assembly: AssemblyInformationalVersion("1.0.1+901b84ab23f2f10926b13865f9b40bb283490874")] [assembly: AssemblyProduct("Transporter")] [assembly: AssemblyTitle("Transporter")] [assembly: AssemblyVersion("1.0.1.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace MyMods.Web { public static class WebNav { public sealed class Link { public readonly string Id; public readonly string Label; public readonly int Port; public string Url => "http://127.0.0.1:" + Port + "/"; public Link(string id, string label, int port) { Id = id; Label = label; Port = port; } } public static readonly Link[] Links = new Link[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 Transporter { public class TransporterSettingsData { public float WagonScale { get; set; } = 7.5f; public float DriverScale { get; set; } = 0.44f; public float DriverOffsetX { get; set; } public float DriverOffsetY { get; set; } = -0.16f; public float DriverOffsetZ { get; set; } = 0.01f; public float DriverRotX { get; set; } public float DriverRotY { get; set; } public float DriverRotZ { get; set; } public float WaistRotX { get; set; } = -32f; public float WaistRotY { get; set; } = -22f; public float WaistRotZ { get; set; } = 72f; public float SpineRotX { get; set; } public float SpineRotY { get; set; } public float SpineRotZ { get; set; } = -81f; public float ThighRotX { get; set; } = -37f; public float ThighRotY { get; set; } = 37f; public float ThighRotZ { get; set; } = 3f; public float CalfRotX { get; set; } = 18f; public float CalfRotY { get; set; } public float CalfRotZ { get; set; } = 16f; public float ArmLeftRotX { get; set; } = -11f; public float ArmLeftRotY { get; set; } public float ArmLeftRotZ { get; set; } = -48f; public float ArmRightRotX { get; set; } = -4f; public float ArmRightRotY { get; set; } public float ArmRightRotZ { get; set; } = -87f; public float ElbowBend { get; set; } = -69f; public float FollowSpeed { get; set; } = 7f; public float SprintSpeed { get; set; } = 11f; public float TurnSpeed { get; set; } = 120f; public float StopDistance { get; set; } = 4.5f; public bool EnableFuelSystem { get; set; } = true; public float MaxFuel { get; set; } = 50f; public float SecondsPerFuelUnit { get; set; } = 12f; public float CoalFuelValue { get; set; } = 10f; public float WoodFuelValue { get; set; } = 3f; public float SurtlingCoreFuelValue { get; set; } = 50f; public float MaxVehicleHealth { get; set; } = 2500f; public bool EnableDriverVoiceLines { get; set; } = true; public float SpeechInterval { get; set; } = 75f; public bool ShowFuelHud { get; set; } = true; public float HudPositionX { get; set; } = 25f; public float HudPositionY { get; set; } = 160f; public string LightMode { get; set; } = "Auto"; } public static class TransporterConfig { private static string s_configPath; public static TransporterSettingsData Data { get; private set; } = new TransporterSettingsData(); public static void Initialize() { string text = Path.Combine(Paths.PluginPath ?? "", "Transporter"); if (!Directory.Exists(text)) { text = Path.Combine(Paths.PluginPath ?? "", "DFG-Transporter"); } if (!Directory.Exists(text)) { text = Path.GetDirectoryName(typeof(TransporterConfig).Assembly.Location) ?? ""; } s_configPath = Path.Combine(text, "transporter_config.json"); Load(); } public static void Load() { try { if (File.Exists(s_configPath)) { TransporterSettingsData transporterSettingsData = JsonConvert.DeserializeObject<TransporterSettingsData>(File.ReadAllText(s_configPath)); if (transporterSettingsData != null) { Data = transporterSettingsData; TransporterPlugin.Log.LogInfo((object)("TransporterConfig: loaded settings from " + s_configPath)); return; } } } catch (Exception ex) { TransporterPlugin.Log.LogWarning((object)("TransporterConfig: error loading config: " + ex.Message)); } Data = new TransporterSettingsData(); Save(); } public static void Save() { try { string directoryName = Path.GetDirectoryName(s_configPath); if (!string.IsNullOrEmpty(directoryName) && !Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } string contents = JsonConvert.SerializeObject((object)Data, (Formatting)1); File.WriteAllText(s_configPath, contents); TransporterPlugin.Log.LogInfo((object)("TransporterConfig: saved settings to " + s_configPath)); } catch (Exception ex) { TransporterPlugin.Log.LogWarning((object)("TransporterConfig: error saving config: " + ex.Message)); } } public static string NormalizeLightMode(string mode) { if (string.IsNullOrEmpty(mode)) { return "Auto"; } if (string.Equals(mode, "Off", StringComparison.OrdinalIgnoreCase)) { return "Off"; } if (string.Equals(mode, "Always", StringComparison.OrdinalIgnoreCase) || string.Equals(mode, "AlwaysOn", StringComparison.OrdinalIgnoreCase) || string.Equals(mode, "On", StringComparison.OrdinalIgnoreCase)) { return "Always"; } return "Auto"; } public static bool LampsPowered(bool fueled) { string text = NormalizeLightMode((Data != null) ? Data.LightMode : "Auto"); if (text == "Off") { return false; } if (text == "Always") { return true; } return fueled; } public static void ApplyLightMode(string mode) { string text = NormalizeLightMode(mode); if (Data != null) { Data.LightMode = text; } if (TransporterPlugin.LightMode != null && TransporterPlugin.LightMode.Value != text) { TransporterPlugin.LightMode.Value = text; } } public static string CycleLightMode() { string text = NormalizeLightMode((Data != null) ? Data.LightMode : "Auto"); string obj = ((text == "Auto") ? "Off" : ((text == "Off") ? "Always" : "Auto")); ApplyLightMode(obj); return obj; } } public static class TransporterGlb { [Serializable] private class GLTFRoot { public GLTFScene[] scenes; public GLTFNode[] nodes; public GLTFSkin[] skins; public GLTFMesh[] meshes; public GLTFMaterial[] materials; public GLTFAccessor[] accessors; public GLTFBufferView[] bufferViews; public GLTFTexture[] textures; public GLTFImage[] images; } [Serializable] private class GLTFSkin { public int inverseBindMatrices = -1; public int[] joints; } [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; public int JOINTS_0 = -1; public int WEIGHTS_0 = -1; } [Serializable] private class GLTFNode { public string name; public int mesh = -1; public int skin = -1; public float[] translation; public float[] rotation; public float[] scale; public int[] children; } [Serializable] private class GLTFMaterial { public string name; public GLTFPBR pbrMetallicRoughness; } [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 Dictionary<string, GameObject> s_cachedPrefabs = new Dictionary<string, GameObject>(); public static GameObject LoadGlb(string path, Material sourceMaterialTemplate = null) { if (string.IsNullOrEmpty(path) || !File.Exists(path)) { TransporterPlugin.Log.LogError((object)("TransporterGlb: Model file not found: " + path)); return null; } if (s_cachedPrefabs.TryGetValue(path, out var value) && (Object)(object)value != (Object)null) { GameObject obj = Object.Instantiate<GameObject>(value); obj.SetActive(true); return obj; } try { byte[] array = File.ReadAllBytes(path); if (array.Length < 20 || BitConverter.ToUInt32(array, 0) != 1179937895) { TransporterPlugin.Log.LogError((object)("TransporterGlb: File is not a valid GLB: " + path)); return null; } int num = 12; string text = null; byte[] array2 = null; while (num < array.Length && num + 8 <= array.Length) { uint num2 = BitConverter.ToUInt32(array, num); uint num3 = BitConverter.ToUInt32(array, num + 4); num += 8; switch (num3) { case 1313821514u: text = Encoding.UTF8.GetString(array, num, (int)num2); break; case 5130562u: array2 = new byte[num2]; Buffer.BlockCopy(array, num, array2, 0, (int)num2); break; } num += (int)num2; num = (num + 3) & -4; } if (string.IsNullOrEmpty(text) || array2 == null) { TransporterPlugin.Log.LogError((object)("TransporterGlb: Failed to extract JSON or BIN chunk from " + path)); return null; } Shader shader = (((Object)(object)sourceMaterialTemplate != (Object)null) ? sourceMaterialTemplate.shader : FindValidShader()); GameObject val = ParseGLTF(text, array2, shader, Path.GetFileNameWithoutExtension(path)); if ((Object)(object)val != (Object)null) { val.SetActive(false); Object.DontDestroyOnLoad((Object)(object)val); s_cachedPrefabs[path] = val; GameObject obj2 = Object.Instantiate<GameObject>(val); obj2.SetActive(true); return obj2; } } catch (Exception ex) { TransporterPlugin.Log.LogError((object)("TransporterGlb: Exception loading GLB " + path + ": " + ex)); } return null; } public static Shader FindValidShader() { Shader val = Shader.Find("Custom/Creature") ?? Shader.Find("Custom/Piece") ?? Shader.Find("Custom/StaticObject") ?? Shader.Find("Standard"); if ((Object)(object)val != (Object)null) { return val; } try { Shader[] array = Resources.FindObjectsOfTypeAll<Shader>(); foreach (Shader val2 in array) { if (((Object)val2).name == "Custom/Creature" || ((Object)val2).name == "Custom/Piece" || ((Object)val2).name == "Custom/StaticObject" || ((Object)val2).name == "Standard") { return val2; } } } catch { } return Shader.Find("Diffuse") ?? Shader.Find("Unlit/Texture"); } private static GameObject ParseGLTF(string json, byte[] binData, Shader shader, string rootName) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Expected O, but got Unknown //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Expected O, but got Unknown //IL_06eb: Unknown result type (might be due to invalid IL or missing references) //IL_06f1: Expected O, but got Unknown //IL_0536: Unknown result type (might be due to invalid IL or missing references) //IL_053b: Unknown result type (might be due to invalid IL or missing references) //IL_074c: Unknown result type (might be due to invalid IL or missing references) //IL_05ef: Unknown result type (might be due to invalid IL or missing references) //IL_05f1: Unknown result type (might be due to invalid IL or missing references) //IL_0796: Unknown result type (might be due to invalid IL or missing references) //IL_0554: Unknown result type (might be due to invalid IL or missing references) //IL_0559: Unknown result type (might be due to invalid IL or missing references) //IL_055e: Unknown result type (might be due to invalid IL or missing references) //IL_0563: Unknown result type (might be due to invalid IL or missing references) //IL_07d7: Unknown result type (might be due to invalid IL or missing references) //IL_056a: 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) //IL_0575: Unknown result type (might be due to invalid IL or missing references) //IL_057a: Unknown result type (might be due to invalid IL or missing references) //IL_057c: Unknown result type (might be due to invalid IL or missing references) //IL_0582: Unknown result type (might be due to invalid IL or missing references) //IL_0587: Unknown result type (might be due to invalid IL or missing references) //IL_058c: Unknown result type (might be due to invalid IL or missing references) //IL_059f: Unknown result type (might be due to invalid IL or missing references) //IL_05a1: Unknown result type (might be due to invalid IL or missing references) //IL_05a3: Unknown result type (might be due to invalid IL or missing references) //IL_05ad: Unknown result type (might be due to invalid IL or missing references) //IL_05b2: Unknown result type (might be due to invalid IL or missing references) //IL_05c9: Unknown result type (might be due to invalid IL or missing references) //IL_05ce: Unknown result type (might be due to invalid IL or missing references) //IL_05d0: Unknown result type (might be due to invalid IL or missing references) //IL_0a30: Unknown result type (might be due to invalid IL or missing references) //IL_0a3e: Unknown result type (might be due to invalid IL or missing references) //IL_0a43: Unknown result type (might be due to invalid IL or missing references) //IL_0374: 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) GameObject val = new GameObject(rootName); try { GLTFRoot gLTFRoot = JsonConvert.DeserializeObject<GLTFRoot>(json); if (gLTFRoot == null) { TransporterPlugin.Log.LogError((object)"TransporterGlb: Failed to parse GLTF JSON"); return null; } 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]; GLTFSkin[] array5 = gLTFRoot.skins ?? new GLTFSkin[0]; GLTFTexture[] array6 = 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 value)) { return value; } 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[] array21 = new byte[gLTFBufferView.byteLength]; Buffer.BlockCopy(binData, gLTFBufferView.byteOffset, array21, 0, gLTFBufferView.byteLength); Texture2D val11 = new Texture2D(2, 2, (TextureFormat)4, false); if (!ImageConversion.LoadImage(val11, array21)) { Object.Destroy((Object)(object)val11); return (Texture2D)null; } ((Object)val11).name = gLTFImage.name ?? $"img_{imageIndex}"; ((Texture)val11).wrapMode = (TextureWrapMode)0; ((Texture)val11).filterMode = (FilterMode)1; texCache[imageIndex] = val11; return val11; }; Mesh[] array7 = (Mesh[])(object)new Mesh[array2.Length]; Material[][] array8 = new Material[array2.Length][]; Vector3[] array9 = (Vector3[])(object)new Vector3[array2.Length]; for (int num = 0; num < array2.Length; num++) { GLTFMesh gLTFMesh = array2[num]; Mesh val2 = new Mesh(); ((Object)val2).name = gLTFMesh.name ?? $"Mesh_{num}"; if (gLTFMesh.primitives != null && gLTFMesh.primitives.Length != 0) { List<Vector3> list = new List<Vector3>(); List<Vector3> list2 = new List<Vector3>(); List<Vector2> list3 = new List<Vector2>(); List<Vector4> list4 = new List<Vector4>(); List<Vector4> list5 = new List<Vector4>(); List<int[]> list6 = new List<int[]>(); List<Material> list7 = new List<Material>(); bool flag = false; for (int num2 = 0; num2 < gLTFMesh.primitives.Length; num2++) { GLTFPrimitive gLTFPrimitive = gLTFMesh.primitives[num2]; int count = list.Count; GLTFAttributes attributes = gLTFPrimitive.attributes; Vector3[] array10 = ((attributes != null && attributes.POSITION >= 0 && gLTFPrimitive.attributes.POSITION < array.Length) ? ReadVec3Accessor(array[gLTFPrimitive.attributes.POSITION], bufferViews, binData) : null); GLTFAttributes attributes2 = gLTFPrimitive.attributes; Vector3[] array11 = ((attributes2 != null && attributes2.NORMAL >= 0 && gLTFPrimitive.attributes.NORMAL < array.Length) ? ReadVec3Accessor(array[gLTFPrimitive.attributes.NORMAL], bufferViews, binData) : null); GLTFAttributes attributes3 = gLTFPrimitive.attributes; Vector2[] array12 = ((attributes3 != null && attributes3.TEXCOORD_0 >= 0 && gLTFPrimitive.attributes.TEXCOORD_0 < array.Length) ? ReadVec2Accessor(array[gLTFPrimitive.attributes.TEXCOORD_0], bufferViews, binData) : null); GLTFAttributes attributes4 = gLTFPrimitive.attributes; Vector4[] array13 = ((attributes4 != null && attributes4.JOINTS_0 >= 0 && gLTFPrimitive.attributes.JOINTS_0 < array.Length) ? ReadVec4Accessor(array[gLTFPrimitive.attributes.JOINTS_0], bufferViews, binData) : null); GLTFAttributes attributes5 = gLTFPrimitive.attributes; Vector4[] array14 = ((attributes5 != null && attributes5.WEIGHTS_0 >= 0 && gLTFPrimitive.attributes.WEIGHTS_0 < array.Length) ? ReadVec4Accessor(array[gLTFPrimitive.attributes.WEIGHTS_0], bufferViews, binData) : null); if (array13 != null && array14 != null) { flag = true; } if (array10 != null) { list.AddRange(array10); if (array11 != null && array11.Length == array10.Length) { list2.AddRange(array11); } else { for (int num3 = 0; num3 < array10.Length; num3++) { list2.Add(Vector3.up); } } if (array12 != null && array12.Length == array10.Length) { list3.AddRange(array12); } else { for (int num4 = 0; num4 < array10.Length; num4++) { list3.Add(Vector2.zero); } } if (array13 != null && array13.Length == array10.Length) { list4.AddRange(array13); } if (array14 != null && array14.Length == array10.Length) { list5.AddRange(array14); } } if (gLTFPrimitive.indices >= 0 && gLTFPrimitive.indices < array.Length) { int[] array15 = ReadIndicesAccessor(array[gLTFPrimitive.indices], bufferViews, binData); if (array15 != null) { int[] array16 = new int[array15.Length]; for (int num5 = 0; num5 < array15.Length; num5++) { array16[num5] = array15[num5] + count; } list6.Add(array16); } } if (gLTFPrimitive.material >= 0 && gLTFPrimitive.material < array3.Length) { GLTFMaterial gLTFMaterial = array3[gLTFPrimitive.material]; Texture2D baseTexture = null; int num6 = gLTFMaterial.pbrMetallicRoughness?.baseColorTexture?.index ?? (-1); if (num6 >= 0 && num6 < array6.Length) { baseTexture = func(array6[num6].source); } list7.Add(CreateMaterial(gLTFMaterial, shader, baseTexture)); } else { list7.Add(CreateFallbackMaterial(shader)); } } if (list.Count > 65535) { val2.indexFormat = (IndexFormat)1; } Vector3 val3 = Vector3.zero; if (!flag && list.Count > 0) { Vector3 val4 = list[0]; Vector3 val5 = list[0]; for (int num7 = 1; num7 < list.Count; num7++) { val4 = Vector3.Min(val4, list[num7]); val5 = Vector3.Max(val5, list[num7]); } val3 = (val4 + val5) * 0.5f; for (int num8 = 0; num8 < list.Count; num8++) { List<Vector3> list8 = list; int index = num8; list8[index] -= val3; } } array9[num] = val3; val2.SetVertices(list); val2.SetNormals(list2); val2.SetUVs(0, list3); if (flag && list4.Count == list.Count && list5.Count == list.Count) { val2.boneWeights = ConvertToBoneWeights(list4.ToArray(), list5.ToArray()); } val2.subMeshCount = list6.Count; for (int num9 = 0; num9 < list6.Count; num9++) { val2.SetTriangles(list6[num9], num9); } array8[num] = list7.ToArray(); } val2.RecalculateNormals(); val2.RecalculateBounds(); array7[num] = val2; } GameObject[] array17 = (GameObject[])(object)new GameObject[array4.Length]; for (int num10 = 0; num10 < array4.Length; num10++) { array17[num10] = new GameObject(array4[num10].name ?? $"Node_{num10}"); } for (int num11 = 0; num11 < array4.Length; num11++) { GLTFNode gLTFNode = array4[num11]; GameObject val6 = array17[num11]; if (gLTFNode.translation != null && gLTFNode.translation.Length == 3) { val6.transform.localPosition = new Vector3(gLTFNode.translation[0], gLTFNode.translation[1], gLTFNode.translation[2]); } if (gLTFNode.rotation != null && gLTFNode.rotation.Length == 4) { val6.transform.localRotation = new Quaternion(gLTFNode.rotation[0], gLTFNode.rotation[1], gLTFNode.rotation[2], gLTFNode.rotation[3]); } if (gLTFNode.scale != null && gLTFNode.scale.Length == 3) { val6.transform.localScale = new Vector3(gLTFNode.scale[0], gLTFNode.scale[1], gLTFNode.scale[2]); } } for (int num12 = 0; num12 < array4.Length; num12++) { GLTFNode gLTFNode2 = array4[num12]; GameObject val7 = array17[num12]; if (gLTFNode2.children == null) { continue; } int[] children = gLTFNode2.children; foreach (int num13 in children) { if (num13 >= 0 && num13 < array17.Length) { array17[num13].transform.SetParent(val7.transform, false); } } } for (int num14 = 0; num14 < array4.Length; num14++) { GLTFNode gLTFNode3 = array4[num14]; GameObject val8 = array17[num14]; if (gLTFNode3.mesh < 0 || gLTFNode3.mesh >= array7.Length) { continue; } Mesh val9 = array7[gLTFNode3.mesh]; Material[] sharedMaterials = (Material[])(((object)array8[gLTFNode3.mesh]) ?? ((object)new Material[1] { CreateFallbackMaterial(shader) })); if (gLTFNode3.skin >= 0 && gLTFNode3.skin < array5.Length && array5[gLTFNode3.skin].joints != null && array5[gLTFNode3.skin].joints.Length != 0 && val9.boneWeights != null && val9.boneWeights.Length != 0) { GLTFSkin gLTFSkin = array5[gLTFNode3.skin]; Transform[] array18 = (Transform[])(object)new Transform[gLTFSkin.joints.Length]; for (int num15 = 0; num15 < gLTFSkin.joints.Length; num15++) { int num16 = gLTFSkin.joints[num15]; if (num16 >= 0 && num16 < array17.Length) { array18[num15] = array17[num16].transform; } } if (gLTFSkin.inverseBindMatrices >= 0 && gLTFSkin.inverseBindMatrices < array.Length) { Matrix4x4[] array19 = ReadMat4Accessor(array[gLTFSkin.inverseBindMatrices], bufferViews, binData); if (array19 != null && array19.Length == gLTFSkin.joints.Length) { val9.bindposes = array19; } } SkinnedMeshRenderer val10 = val8.AddComponent<SkinnedMeshRenderer>(); val10.sharedMesh = val9; val10.bones = array18; if (array18.Length != 0 && (Object)(object)array18[0] != (Object)null) { val10.rootBone = array18[0]; } ((Renderer)val10).sharedMaterials = sharedMaterials; val10.updateWhenOffscreen = true; val10.quality = (SkinQuality)4; } else { if (gLTFNode3.translation == null || gLTFNode3.translation.Length < 3) { Transform transform = val8.transform; transform.localPosition += array9[gLTFNode3.mesh]; } val8.AddComponent<MeshFilter>().sharedMesh = val9; ((Renderer)val8.AddComponent<MeshRenderer>()).sharedMaterials = sharedMaterials; } } bool flag2 = false; GLTFScene[] array20 = gLTFRoot.scenes ?? new GLTFScene[0]; foreach (GLTFScene gLTFScene in array20) { if (gLTFScene.nodes == null) { continue; } int[] children = gLTFScene.nodes; foreach (int num18 in children) { if (num18 >= 0 && num18 < array17.Length) { array17[num18].transform.SetParent(val.transform, false); flag2 = true; } } } if (!flag2) { for (int num19 = 0; num19 < array17.Length; num19++) { if ((Object)(object)array17[num19].transform.parent == (Object)null) { array17[num19].transform.SetParent(val.transform, false); } } } return val; } catch (Exception arg) { TransporterPlugin.Log.LogError((object)$"TransporterGlb: Error parsing GLTF: {arg}"); return null; } } private static Vector3[] ReadVec3Accessor(GLTFAccessor accessor, GLTFBufferView[] bufferViews, byte[] binData) { //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) if (accessor == null || accessor.bufferView < 0 || accessor.bufferView >= bufferViews.Length) { 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), BitConverter.ToSingle(binData, num3 + 8)); } } return array; } private static Vector2[] ReadVec2Accessor(GLTFAccessor accessor, GLTFBufferView[] bufferViews, byte[] binData) { //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) if (accessor == null || accessor.bufferView < 0 || accessor.bufferView >= bufferViews.Length) { 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) { float num4 = BitConverter.ToSingle(binData, num3); float num5 = BitConverter.ToSingle(binData, num3 + 4); array[i] = new Vector2(num4, 1f - num5); } } return array; } private static Vector4[] ReadVec4Accessor(GLTFAccessor accessor, GLTFBufferView[] bufferViews, byte[] binData) { //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) if (accessor == null || accessor.bufferView < 0 || accessor.bufferView >= bufferViews.Length) { return null; } GLTFBufferView gLTFBufferView = bufferViews[accessor.bufferView]; int num = gLTFBufferView.byteOffset + accessor.byteOffset; int count = accessor.count; Vector4[] array = (Vector4[])(object)new Vector4[count]; if (accessor.componentType == 5126) { int num2 = ((gLTFBufferView.byteStride > 0) ? gLTFBufferView.byteStride : 16); for (int i = 0; i < count; i++) { int num3 = num + i * num2; if (num3 + 16 <= binData.Length) { array[i] = new Vector4(BitConverter.ToSingle(binData, num3), BitConverter.ToSingle(binData, num3 + 4), BitConverter.ToSingle(binData, num3 + 8), BitConverter.ToSingle(binData, num3 + 12)); } } } else if (accessor.componentType == 5121) { int num4 = ((gLTFBufferView.byteStride > 0) ? gLTFBufferView.byteStride : 4); for (int j = 0; j < count; j++) { int num5 = num + j * num4; if (num5 + 4 <= binData.Length) { array[j] = new Vector4((float)(int)binData[num5], (float)(int)binData[num5 + 1], (float)(int)binData[num5 + 2], (float)(int)binData[num5 + 3]); } } } else if (accessor.componentType == 5123) { int num6 = ((gLTFBufferView.byteStride > 0) ? gLTFBufferView.byteStride : 8); for (int k = 0; k < count; k++) { int num7 = num + k * num6; if (num7 + 8 <= binData.Length) { array[k] = new Vector4((float)(int)BitConverter.ToUInt16(binData, num7), (float)(int)BitConverter.ToUInt16(binData, num7 + 2), (float)(int)BitConverter.ToUInt16(binData, num7 + 4), (float)(int)BitConverter.ToUInt16(binData, num7 + 6)); } } } return array; } private static Matrix4x4[] ReadMat4Accessor(GLTFAccessor accessor, GLTFBufferView[] bufferViews, byte[] binData) { //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) if (accessor == null || accessor.bufferView < 0 || accessor.bufferView >= bufferViews.Length) { return null; } GLTFBufferView gLTFBufferView = bufferViews[accessor.bufferView]; int num = gLTFBufferView.byteOffset + accessor.byteOffset; int count = accessor.count; int num2 = ((gLTFBufferView.byteStride > 0) ? gLTFBufferView.byteStride : 64); Matrix4x4[] array = (Matrix4x4[])(object)new Matrix4x4[count]; for (int i = 0; i < count; i++) { int num3 = num + i * num2; if (num3 + 64 > binData.Length) { continue; } Matrix4x4 identity = Matrix4x4.identity; for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { ((Matrix4x4)(ref identity))[k, j] = BitConverter.ToSingle(binData, num3 + (j * 4 + k) * 4); } } array[i] = identity; } return array; } private static BoneWeight[] ConvertToBoneWeights(Vector4[] joints, Vector4[] weights) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_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_003a: 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_0068: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: 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_00cf: Unknown result type (might be due to invalid IL or missing references) if (joints == null || weights == null) { return null; } int num = Mathf.Min(joints.Length, weights.Length); BoneWeight[] array = (BoneWeight[])(object)new BoneWeight[num]; for (int i = 0; i < num; i++) { Vector4 val = joints[i]; Vector4 val2 = weights[i]; ((BoneWeight)(ref array[i])).boneIndex0 = Mathf.RoundToInt(val.x); ((BoneWeight)(ref array[i])).boneIndex1 = Mathf.RoundToInt(val.y); ((BoneWeight)(ref array[i])).boneIndex2 = Mathf.RoundToInt(val.z); ((BoneWeight)(ref array[i])).boneIndex3 = Mathf.RoundToInt(val.w); ((BoneWeight)(ref array[i])).weight0 = val2.x; ((BoneWeight)(ref array[i])).weight1 = val2.y; ((BoneWeight)(ref array[i])).weight2 = val2.z; ((BoneWeight)(ref array[i])).weight3 = val2.w; } return array; } private static int[] ReadIndicesAccessor(GLTFAccessor accessor, GLTFBufferView[] bufferViews, byte[] binData) { if (accessor == null || accessor.bufferView < 0 || accessor.bufferView >= bufferViews.Length) { 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 == 5123) { int num2 = ((gLTFBufferView.byteStride > 0) ? gLTFBufferView.byteStride : 2); for (int i = 0; i < count; i++) { int num3 = num + i * num2; if (num3 + 2 <= binData.Length) { array[i] = BitConverter.ToUInt16(binData, num3); } } } else if (accessor.componentType == 5125) { int num4 = ((gLTFBufferView.byteStride > 0) ? gLTFBufferView.byteStride : 4); for (int j = 0; j < count; j++) { int num5 = num + j * num4; if (num5 + 4 <= binData.Length) { array[j] = BitConverter.ToInt32(binData, num5); } } } else if (accessor.componentType == 5121) { for (int k = 0; k < count; k++) { int num6 = num + k; if (num6 < binData.Length) { array[k] = binData[num6]; } } } return array; } private static Material CreateMaterial(GLTFMaterial mat, Shader shader, Texture2D baseTexture) { //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) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_0106: 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_010d: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) Material val = CreateBaseMaterial(shader); ((Object)val).name = mat.name ?? "GLTFMaterial"; if ((Object)(object)baseTexture != (Object)null) { val.mainTexture = (Texture)(object)baseTexture; if (val.HasProperty("_MainTex")) { val.SetTexture("_MainTex", (Texture)(object)baseTexture); } if (val.HasProperty("_BaseMap")) { val.SetTexture("_BaseMap", (Texture)(object)baseTexture); } if (val.HasProperty("_Albedo")) { val.SetTexture("_Albedo", (Texture)(object)baseTexture); } } Color val2 = Color.white; if (mat.pbrMetallicRoughness != null) { GLTFPBR pbrMetallicRoughness = mat.pbrMetallicRoughness; if (pbrMetallicRoughness.baseColorFactor != null && pbrMetallicRoughness.baseColorFactor.Length == 4) { Color white = default(Color); ((Color)(ref white))..ctor(pbrMetallicRoughness.baseColorFactor[0], pbrMetallicRoughness.baseColorFactor[1], pbrMetallicRoughness.baseColorFactor[2], pbrMetallicRoughness.baseColorFactor[3]); if (white.a <= 0.01f || ((Object)(object)baseTexture != (Object)null && white.r <= 0.08f && white.g <= 0.08f && white.b <= 0.08f)) { white = Color.white; } val2 = white; } if (pbrMetallicRoughness.metallicFactor.HasValue && val.HasProperty("_Metallic")) { val.SetFloat("_Metallic", Mathf.Clamp01(pbrMetallicRoughness.metallicFactor.Value)); } if (pbrMetallicRoughness.roughnessFactor.HasValue) { float num = Mathf.Clamp01(1f - pbrMetallicRoughness.roughnessFactor.Value); if (val.HasProperty("_Glossiness")) { val.SetFloat("_Glossiness", num); } if (val.HasProperty("_Smoothness")) { val.SetFloat("_Smoothness", num); } } } val.color = val2; if (val.HasProperty("_Color")) { val.SetColor("_Color", val2); } if (val.HasProperty("_BaseColor")) { val.SetColor("_BaseColor", val2); } if (val.HasProperty("_Cull")) { val.SetInt("_Cull", 0); } val.renderQueue = 2000; return val; } private static Material CreateFallbackMaterial(Shader shader) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) Material obj = CreateBaseMaterial(shader); ((Object)obj).name = "Transporter_FallbackMat"; obj.color = Color.white; return obj; } private static Material CreateBaseMaterial(Shader shader) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown if ((Object)(object)shader == (Object)null) { shader = FindValidShader(); } return new Material(shader); } } public static class TransporterPiece { public const string PrefabName = "DFG_Transporter"; private const string BaseSourcePrefab = "piece_chest_wood"; private const string FallbackSourcePrefab = "piece_cart"; private const string DisplayName = "The Transporter"; private const string Description = "An automated steam wagon. It follows you, hauls cargo, and burns coal or wood from its boiler. E opens the hold, Shift+E opens the boiler."; private static bool s_prefabRegistered; private static bool s_pieceManagerAdded; private static bool s_pieceTableRegistered; private static bool s_pieceRegistered; private static bool s_registrationWarningLogged; private static float s_registrationTimer; private static readonly Dictionary<string, ItemDrop> s_cachedRequirementItems = new Dictionary<string, ItemDrop>(); private static MethodInfo s_addKnownPieceMethod; private static MethodInfo s_updateAvailablePiecesListMethod; public static void Initialize() { PrefabManager.OnVanillaPrefabsAvailable += OnVanillaPrefabsAvailable; } public static void Shutdown() { PrefabManager.OnVanillaPrefabsAvailable -= OnVanillaPrefabsAvailable; s_cachedRequirementItems.Clear(); s_prefabRegistered = false; s_pieceManagerAdded = false; s_pieceTableRegistered = false; s_pieceRegistered = false; s_registrationWarningLogged = false; s_registrationTimer = 0f; } public static void Update() { if (TransporterPlugin.Enabled.Value) { TryRegisterContent(); EnsureLocalPlayerKnownPiece(); } } private static void OnVanillaPrefabsAvailable() { s_registrationTimer = 0f; TryRegisterPrefab(); } private static void TryRegisterPrefab() { //IL_0305: Unknown result type (might be due to invalid IL or missing references) //IL_0316: Unknown result type (might be due to invalid IL or missing references) //IL_0342: Unknown result type (might be due to invalid IL or missing references) //IL_0349: Unknown result type (might be due to invalid IL or missing references) //IL_038f: Unknown result type (might be due to invalid IL or missing references) //IL_03ad: Unknown result type (might be due to invalid IL or missing references) if (!TransporterPlugin.Enabled.Value || s_prefabRegistered) { return; } try { GameObject prefab = PrefabManager.Instance.GetPrefab("piece_chest_wood"); if ((Object)(object)prefab == (Object)null && (Object)(object)ZNetScene.instance != (Object)null) { prefab = ZNetScene.instance.GetPrefab("piece_chest_wood"); } if ((Object)(object)prefab == (Object)null) { prefab = PrefabManager.Instance.GetPrefab("piece_cart"); } if ((Object)(object)prefab == (Object)null && (Object)(object)ZNetScene.instance != (Object)null) { prefab = ZNetScene.instance.GetPrefab("piece_cart"); } if ((Object)(object)prefab == (Object)null) { if (!s_registrationWarningLogged) { TransporterPlugin.Log.LogWarning((object)"TransporterPiece: could not find base piece prefab to clone."); s_registrationWarningLogged = true; } return; } bool activeSelf = prefab.activeSelf; if (activeSelf) { prefab.SetActive(false); } GameObject val = PrefabManager.Instance.CreateClonedPrefab("DFG_Transporter", prefab); if (activeSelf) { prefab.SetActive(true); } if ((Object)(object)val == (Object)null) { TransporterPlugin.Log.LogError((object)("TransporterPiece: failed to clone " + ((Object)prefab).name)); return; } val.SetActive(true); Piece component = val.GetComponent<Piece>(); if ((Object)(object)component != (Object)null) { component.m_name = "The Transporter"; component.m_description = "An automated steam wagon. It follows you, hauls cargo, and burns coal or wood from its boiler. E opens the hold, Shift+E opens the boiler."; component.m_canBeRemoved = true; component.m_groundPiece = false; component.m_clipGround = false; component.m_groundOnly = false; component.m_waterPiece = false; component.m_noInWater = false; component.m_craftingStation = null; } Container val2 = val.GetComponent<Container>(); if ((Object)(object)val2 == (Object)null) { val2 = val.AddComponent<Container>(); } if ((Object)(object)val2 != (Object)null) { val2.m_name = "The Transporter Cargo"; val2.m_width = Mathf.Clamp(TransporterPlugin.StorageWidth.Value, 4, 10); val2.m_height = Mathf.Clamp(TransporterPlugin.StorageHeight.Value, 2, 8); val2.m_autoDestroyEmpty = false; val2.m_checkGuardStone = true; val2.m_open = null; val2.m_closed = null; } WearNTear val3 = val.GetComponent<WearNTear>(); if ((Object)(object)val3 == (Object)null) { val3 = val.AddComponent<WearNTear>(); } if ((Object)(object)val3 != (Object)null) { val3.m_noSupportWear = true; val3.m_noRoofWear = true; val3.m_staticPosition = false; val3.m_supports = false; val3.m_health = 2500f; val3.m_new = null; val3.m_worn = null; val3.m_broken = null; val3.m_wet = null; val3.m_snow = null; val3.m_snowWorn = null; val3.m_snowBroken = null; } Rigidbody val4 = val.GetComponent<Rigidbody>(); if ((Object)(object)val4 == (Object)null) { val4 = val.AddComponent<Rigidbody>(); } val4.mass = 400f; val4.interpolation = (RigidbodyInterpolation)1; val4.isKinematic = true; val4.useGravity = false; Renderer componentInChildren = prefab.GetComponentInChildren<Renderer>(true); if ((Object)(object)componentInChildren != (Object)null) { _ = componentInChildren.sharedMaterial; } HideVanillaVisuals(val); string wagonGlbPath = TransporterPlugin.GetWagonGlbPath(); GameObject val5 = TransporterGlb.LoadGlb(wagonGlbPath); if ((Object)(object)val5 != (Object)null) { ((Object)val5).name = "Transporter_WagonModel"; val5.transform.SetParent(val.transform, false); val5.transform.localPosition = Vector3.zero; val5.transform.localRotation = Quaternion.identity; float num = Mathf.Clamp(TransporterPlugin.WagonScale.Value, 0.5f, 5f); val5.transform.localScale = Vector3.one * num; val5.SetActive(true); BoxCollider val6 = val.GetComponent<BoxCollider>(); if ((Object)(object)val6 == (Object)null) { val6 = val.AddComponent<BoxCollider>(); } val6.size = new Vector3(0.5f * num, 0.65f * num, 1.05f * num); val6.center = new Vector3(0f, 0.42f * num, 0f); int layer = val.layer; Transform[] componentsInChildren = val5.GetComponentsInChildren<Transform>(true); for (int i = 0; i < componentsInChildren.Length; i++) { ((Component)componentsInChildren[i]).gameObject.layer = layer; } } else { TransporterPlugin.Log.LogError((object)("TransporterPiece: Wagon GLB model could not be loaded from " + wagonGlbPath)); } if ((Object)(object)val.GetComponent<TransporterVehicle>() == (Object)null) { val.AddComponent<TransporterVehicle>(); } PrefabManager.Instance.AddPrefab(val); s_prefabRegistered = true; s_registrationWarningLogged = false; TransporterPlugin.Log.LogInfo((object)"TransporterPiece: registered prefab DFG_Transporter"); } catch (Exception ex) { TransporterPlugin.Log.LogError((object)("TransporterPiece: Error registering piece prefab: " + ex)); } } private static void TryRegisterContent() { //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: 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_00e4: Expected O, but got Unknown //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Expected O, but got Unknown //IL_0120: 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_0139: Expected I4, but got Unknown if (!TransporterPlugin.Enabled.Value || s_pieceRegistered) { return; } s_registrationTimer -= Time.deltaTime; if (s_registrationTimer > 0f) { return; } s_registrationTimer = 1f; TryRegisterPrefab(); ZNetScene instance = ZNetScene.instance; if (!s_prefabRegistered || (Object)(object)instance == (Object)null || instance.m_prefabs == null || instance.m_prefabs.Count == 0 || (Object)(object)ObjectDB.instance == (Object)null) { return; } GameObject prefab = PrefabManager.Instance.GetPrefab("DFG_Transporter"); if ((Object)(object)prefab == (Object)null) { return; } try { PieceCategory val = PieceManager.Instance.AddPieceCategory("DFG"); if (!s_pieceManagerAdded) { PieceConfig val2 = new PieceConfig { Name = "The Transporter", Description = "An automated steam wagon. It follows you, hauls cargo, and burns coal or wood from its boiler. E opens the hold, Shift+E opens the boiler.", PieceTable = "Hammer", Category = "DFG", Enabled = true }; PieceManager.Instance.AddPiece(new CustomPiece(prefab, false, val2)); s_pieceManagerAdded = true; } if (!s_pieceTableRegistered) { PieceManager.Instance.RegisterPieceInPieceTable(prefab, "Hammer", "DFG"); s_pieceTableRegistered = true; } FinalizePiece(prefab, val); s_pieceRegistered = true; TransporterPlugin.Log.LogInfo((object)("The Transporter: added to live Hammer PieceTable in category 'DFG' (id=" + (int)val + ").")); RefreshPieceCategories(); EnsureLocalPlayerKnownPiece(); } catch (Exception ex) { TransporterPlugin.Log.LogError((object)("The Transporter: piece registration failed: " + ex)); } } private static void FinalizePiece(GameObject prefab, PieceCategory categoryId) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) Piece component = prefab.GetComponent<Piece>(); if (!((Object)(object)component == (Object)null)) { component.m_name = "The Transporter"; component.m_description = "An automated steam wagon. It follows you, hauls cargo, and burns coal or wood from its boiler. E opens the hold, Shift+E opens the boiler."; component.m_category = categoryId; component.m_craftingStation = null; component.m_groundPiece = false; component.m_clipGround = false; component.m_groundOnly = false; component.m_waterPiece = false; component.m_noInWater = false; component.m_canBeRemoved = true; component.m_resources = BuildRequirements(); WearNTear component2 = prefab.GetComponent<WearNTear>(); if ((Object)(object)component2 != (Object)null) { component2.m_noSupportWear = true; component2.m_noRoofWear = true; component2.m_staticPosition = false; component2.m_supports = false; component2.m_health = 2500f; component2.m_new = null; component2.m_worn = null; component2.m_broken = null; component2.m_wet = null; component2.m_snow = null; component2.m_snowWorn = null; component2.m_snowBroken = null; } Sprite val = LoadIcon(); if ((Object)(object)val != (Object)null) { component.m_icon = val; } } } private static Requirement[] BuildRequirements() { List<Requirement> list = new List<Requirement>(); AddRequirement(list, "FineWood", TransporterPlugin.BuildFineWoodCost.Value); AddRequirement(list, "BronzeNails", TransporterPlugin.BuildBronzeNailsCost.Value); AddRequirement(list, "DeerHide", TransporterPlugin.BuildDeerHideCost.Value); AddRequirement(list, "SurtlingCore", TransporterPlugin.BuildSurtlingCoreCost.Value); return list.ToArray(); } private static void AddRequirement(List<Requirement> requirements, string itemName, int amount) { //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_0052: 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_0065: Expected O, but got Unknown if (amount > 0) { ItemDrop val = ResolveRequirementItem(itemName); if ((Object)(object)val == (Object)null || val.m_itemData == null || val.m_itemData.m_shared == null) { TransporterPlugin.Log.LogWarning((object)("Transporter: build requirement " + itemName + " could not be resolved.")); return; } requirements.Add(new Requirement { m_resItem = val, m_amount = amount, m_recover = true }); } } private static ItemDrop ResolveRequirementItem(string prefabName) { if (s_cachedRequirementItems.TryGetValue(prefabName, out var value) && (Object)(object)value != (Object)null && value.m_itemData != null && value.m_itemData.m_shared != null) { return value; } if ((Object)(object)ObjectDB.instance != (Object)null) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(prefabName); ItemDrop val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null); if ((Object)(object)val != (Object)null && val.m_itemData != null && val.m_itemData.m_shared != null) { s_cachedRequirementItems[prefabName] = val; return val; } } Piece[] array = Resources.FindObjectsOfTypeAll<Piece>(); foreach (Piece val2 in array) { if ((Object)(object)val2 == (Object)null || val2.m_resources == null) { continue; } for (int j = 0; j < val2.m_resources.Length; j++) { Requirement val3 = val2.m_resources[j]; if (val3 != null && !((Object)(object)val3.m_resItem == (Object)null) && !(((Object)val3.m_resItem).name != prefabName) && val3.m_resItem.m_itemData != null && val3.m_resItem.m_itemData.m_shared != null) { s_cachedRequirementItems[prefabName] = val3.m_resItem; return val3.m_resItem; } } } return null; } private static void EnsureLocalPlayerKnownPiece() { if (!s_pieceRegistered || (Object)(object)Player.m_localPlayer == (Object)null || Player.m_localPlayer.IsRecipeKnown("The Transporter")) { return; } GameObject prefab = PrefabManager.Instance.GetPrefab("DFG_Transporter"); Piece val = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<Piece>() : null); if (!((Object)(object)val != (Object)null)) { return; } if (s_addKnownPieceMethod == null) { s_addKnownPieceMethod = typeof(Player).GetMethod("AddKnownPiece", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); } if (s_updateAvailablePiecesListMethod == null) { s_updateAvailablePiecesListMethod = typeof(Player).GetMethod("UpdateAvailablePiecesList", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); } try { s_addKnownPieceMethod?.Invoke(Player.m_localPlayer, new object[1] { val }); s_updateAvailablePiecesListMethod?.Invoke(Player.m_localPlayer, null); RefreshPieceCategories(); TransporterPlugin.Log.LogInfo((object)"The Transporter: unlocked in Hammer menu for local player."); } catch (Exception ex) { TransporterPlugin.Log.LogWarning((object)("The Transporter: error adding known piece to player: " + ex.Message)); } } private static void RefreshPieceCategories() { try { MethodInfo method = typeof(PieceManager).GetMethod("RefreshCategories", BindingFlags.Instance | BindingFlags.NonPublic); if (method != null) { method.Invoke(PieceManager.Instance, null); } } catch (Exception ex) { TransporterPlugin.Log.LogWarning((object)("Transporter: could not refresh categories: " + ex.Message)); } } private static void HideVanillaVisuals(GameObject pieceObj) { MeshFilter[] componentsInChildren = pieceObj.GetComponentsInChildren<MeshFilter>(true); for (int i = 0; i < componentsInChildren.Length; i++) { if (((Object)((Component)componentsInChildren[i]).gameObject).name != "Transporter_WagonModel") { Transform parent = ((Component)componentsInChildren[i]).transform.parent; if (((parent != null) ? ((Object)parent).name : null) != "Transporter_WagonModel") { componentsInChildren[i].sharedMesh = null; } } } Renderer[] componentsInChildren2 = pieceObj.GetComponentsInChildren<Renderer>(true); for (int j = 0; j < componentsInChildren2.Length; j++) { if (((Object)((Component)componentsInChildren2[j]).gameObject).name != "Transporter_WagonModel") { Transform parent2 = ((Component)componentsInChildren2[j]).transform.parent; if (((parent2 != null) ? ((Object)parent2).name : null) != "Transporter_WagonModel") { componentsInChildren2[j].enabled = false; } } } Collider[] componentsInChildren3 = pieceObj.GetComponentsInChildren<Collider>(true); for (int k = 0; k < componentsInChildren3.Length; k++) { if ((Object)(object)((Component)componentsInChildren3[k]).gameObject != (Object)(object)pieceObj) { componentsInChildren3[k].enabled = false; } } } private static Sprite LoadIcon() { //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Expected O, but got Unknown //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) try { string path = Path.GetDirectoryName(typeof(TransporterPiece).Assembly.Location) ?? ""; string[] array = new string[3] { Path.Combine(path, "transporter_icon.png"), Path.Combine(path, "icon.png"), Path.Combine(Paths.PluginPath ?? "", "Transporter", "transporter_icon.png") }; foreach (string path2 in array) { if (File.Exists(path2)) { byte[] array2 = File.ReadAllBytes(path2); Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); if (ImageConversion.LoadImage(val, array2)) { return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)); } } } } catch (Exception ex) { TransporterPlugin.Log.LogWarning((object)("TransporterPiece: Could not load custom icon: " + ex.Message)); } return null; } } [BepInPlugin("com.dfg.transporter", "Transporter", "1.0.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class TransporterPlugin : BaseUnityPlugin { public const string PluginGUID = "com.dfg.transporter"; public const string PluginName = "Transporter"; public const string PluginVersion = "1.0.1"; internal static ManualLogSource Log; private Harmony m_harmony; private TransporterWebGui m_webGui; public static ConfigEntry<bool> Enabled; public static ConfigEntry<float> FollowSpeed; public static ConfigEntry<float> SprintSpeed; public static ConfigEntry<float> TurnSpeed; public static ConfigEntry<float> StopDistance; public static ConfigEntry<KeyCode> CommandHotkey; public static ConfigEntry<int> StorageWidth; public static ConfigEntry<int> StorageHeight; public static ConfigEntry<bool> AllowTeleportCatchup; public static ConfigEntry<float> TeleportDistance; public static ConfigEntry<float> WagonScale; public static ConfigEntry<float> DriverScale; public static ConfigEntry<bool> EnableExhaustVFX; public static ConfigEntry<string> LightMode; public static ConfigEntry<int> BuildFineWoodCost; public static ConfigEntry<int> BuildBronzeNailsCost; public static ConfigEntry<int> BuildDeerHideCost; public static ConfigEntry<int> BuildSurtlingCoreCost; private void Awake() { //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Expected O, but got Unknown //IL_02e6: Unknown result type (might be due to invalid IL or missing references) //IL_02f0: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "Enabled", true, "Master switch for The Transporter mod."); CommandHotkey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("1 - General", "CommandHotkey", (KeyCode)118, "Global hotkey to order your nearest Transporter to Follow / Stay."); FollowSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Movement", "FollowSpeed", 7f, "Normal driving follow speed when player is walking."); SprintSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Movement", "SprintSpeed", 11f, "Accelerated driving follow speed when player is sprinting."); TurnSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Movement", "TurnSpeed", 120f, "Vehicle steering turn rate in degrees per second."); StopDistance = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Movement", "StopDistance", 4.5f, "Target stopping distance from player in meters."); AllowTeleportCatchup = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Movement", "AllowTeleportCatchup", true, "Whether the transporter will catch up / teleport if you go through a portal or move too far away."); TeleportDistance = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Movement", "TeleportDistance", 80f, "Distance in meters before catch-up teleport triggers."); StorageWidth = ((BaseUnityPlugin)this).Config.Bind<int>("3 - Storage", "StorageWidth", 8, "Cargo inventory grid columns (4 to 10)."); StorageHeight = ((BaseUnityPlugin)this).Config.Bind<int>("3 - Storage", "StorageHeight", 4, "Cargo inventory grid rows (2 to 8). 8x4 = 32 slots."); WagonScale = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Visuals", "WagonScale", 5.6f, "Scale of the wagon 3D model."); DriverScale = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Visuals", "DriverScale", 0.18f, "Scale of the driver companion model."); EnableExhaustVFX = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Visuals", "EnableExhaustVFX", true, "Emit active fire embers and rising smoke clouds from the smelter-powered exhaust chimney stack (tripo_part_27)."); LightMode = ((BaseUnityPlugin)this).Config.Bind<string>("4 - Visuals", "LightMode", "Auto", new ConfigDescription("Wagon lamps. Auto is on while the boiler has fuel. Off disables them. Always keeps them lit.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "Auto", "Off", "Always" }), Array.Empty<object>())); LightMode.SettingChanged += delegate { if (TransporterConfig.Data != null) { TransporterConfig.Data.LightMode = TransporterConfig.NormalizeLightMode(LightMode.Value); } }; BuildFineWoodCost = ((BaseUnityPlugin)this).Config.Bind<int>("5 - Crafting", "BuildFineWoodCost", 20, "Fine Wood required to build."); BuildBronzeNailsCost = ((BaseUnityPlugin)this).Config.Bind<int>("5 - Crafting", "BuildBronzeNailsCost", 10, "Bronze Nails required to build."); BuildDeerHideCost = ((BaseUnityPlugin)this).Config.Bind<int>("5 - Crafting", "BuildDeerHideCost", 4, "Deer Hide required to build."); BuildSurtlingCoreCost = ((BaseUnityPlugin)this).Config.Bind<int>("5 - Crafting", "BuildSurtlingCoreCost", 1, "Surtling Core required to build."); if (!Enabled.Value) { Log.LogInfo((object)"Transporter is disabled via configuration."); return; } m_harmony = new Harmony("com.dfg.transporter"); m_harmony.PatchAll(); TransporterConfig.Initialize(); TransporterConfig.Data.LightMode = TransporterConfig.NormalizeLightMode(LightMode.Value); try { m_webGui = new TransporterWebGui(); m_webGui.Start(); } catch (Exception ex) { Log.LogWarning((object)("Failed to start Web GUI: " + ex.Message)); } TransporterPiece.Initialize(); Log.LogInfo((object)"Transporter v1.0.1 loaded successfully."); } private void Update() { TransporterPiece.Update(); if (Enabled != null && Enabled.Value) { TryCycleLamps(); } } private static void TryCycleLamps() { if (!((Object)(object)Player.m_localPlayer == (Object)null) && (!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.IsChatDialogWindowVisible()) && !Console.IsVisible() && !InventoryGui.IsVisible() && (Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307)) && Input.GetKeyDown((KeyCode)108)) { string text = TransporterConfig.CycleLightMode(); string text2 = ((text == "Off") ? "Lamps: Off" : ((text == "Always") ? "Lamps: Always on" : "Lamps: Auto (on while the boiler has fuel)")); ((Character)Player.m_localPlayer).Message((MessageType)2, text2, 0, (Sprite)null, false); } } private void OnDestroy() { try { m_webGui?.Stop(); } catch { } TransporterPiece.Shutdown(); Harmony harmony = m_harmony; if (harmony != null) { harmony.UnpatchSelf(); } } public static string GetWagonGlbPath() { string path = Path.GetDirectoryName(typeof(TransporterPlugin).Assembly.Location) ?? ""; string[] array = new string[5] { Path.Combine(path, "wagon.glb"), Path.Combine(Paths.PluginPath ?? "", "Transporter", "wagon.glb"), Path.Combine(Paths.PluginPath ?? "", "DFG-Transporter", "wagon.glb"), Path.Combine(Paths.PluginPath ?? "", "wagon.glb"), "C:\\Users\\dhugh\\Documents\\MyMods\\Transporter\\wagon.glb" }; string[] array2 = array; foreach (string text in array2) { if (File.Exists(text)) { return text; } } return array[0]; } public static string GetDriverGlbPath() { string path = Path.GetDirectoryName(typeof(TransporterPlugin).Assembly.Location) ?? ""; string[] array = new string[5] { Path.Combine(path, "the_driver.glb"), Path.Combine(Paths.PluginPath ?? "", "Transporter", "the_driver.glb"), Path.Combine(Paths.PluginPath ?? "", "DFG-Transporter", "the_driver.glb"), Path.Combine(Paths.PluginPath ?? "", "the_driver.glb"), "C:\\Users\\dhugh\\Documents\\MyMods\\Transporter\\the_driver.glb" }; string[] array2 = array; foreach (string text in array2) { if (File.Exists(text)) { return text; } } return array[0]; } } public class TransporterVehicle : MonoBehaviour, Hoverable, Interactable { public static readonly List<TransporterVehicle> AllVehicles = new List<TransporterVehicle>(); private ZNetView m_nview; private Rigidbody m_body; private Container m_container; private Piece m_piece; private WearNTear m_wearNTear; private Transform m_wagonModelTransform; private Transform m_chair; private Transform m_exhaustStack; private GameObject m_driverInstance; private GameObject m_exhaustEffectObj; private ParticleSystem[] m_exhaustParticles; private float[] m_baseEmissionRates; private readonly List<Transform> m_allWheels = new List<Transform>(); private readonly List<Transform> m_steerWheels = new List<Transform>(); private readonly Dictionary<Transform, Quaternion> m_wheelBaseRotations = new Dictionary<Transform, Quaternion>(); private Vector3 m_lastPosition; private float m_currentSteerAngle; private float m_wheelRadius = 0.45f; private float m_accumulatedWheelSpin; private float m_currentSpeed; private readonly Dictionary<Transform, Quaternion> m_boneBaseRotations = new Dictionary<Transform, Quaternion>(); private Transform m_driverHead; private Transform m_pelvis; private Transform m_spine1; private Transform m_spine2; private Transform m_thighL; private Transform m_thighR; private Transform m_calfL; private Transform m_calfR; private Transform m_upperarmL; private Transform m_upperarmR; private Transform m_lowerarmL; private Transform m_lowerarmR; private float m_headLookYaw; private float m_headLookPitch; private float m_targetHeadYaw; private float m_targetHeadPitch; private float m_headIdleTimer; private Player m_targetPlayer; private float m_searchTargetTimer; private Vector3 m_smoothedAim; private bool m_hasAim; private float m_smoothedPitch; private float m_smoothedRoll; private float m_smoothedGroundY; private bool m_hasGround; private Vector3 m_lastPlayerPlanar; private bool m_hasPlayerPlanar; private float m_playerPlanarSpeed; private float m_yaw; private bool m_hasYaw; private WaterVolume m_waterProbe; private readonly RaycastHit[] m_groundHits = (RaycastHit[])(object)new RaycastHit[24]; private const string FuelBinKey = "Transporter_FuelBin"; private Container m_fuelContainer; private bool m_suppressFuelSave; private int m_fuelBinHash = int.MinValue; private float m_fuelFeedTimer; private static FieldInfo s_currentContainerField; private GameObject m_lampsRoot; private Light m_tailLight; private readonly List<Light> m_headLights = new List<Light>(); private readonly List<Renderer> m_lampOrbs = new List<Renderer>(); private static Material s_lampMaterial; private float m_lowFuelWarningTimer; private float m_speechTimer = 25f; private static readonly string[] s_transporterQuotes = new string[30] { "Rule number one: The deal is the deal. Rule number two: No names. Rule number three: Never open the cart.", "You put the ore in the back, you pay the coins upfront, and you shut your mouth until we hit the gate.", "Seatbelts weren't invented yet. Hold onto the timber and pray to whatever god you fancy.", "Look at me. Does it look like I take detours through the Plains for fun?", "I don't care if it's fine wood, black metal, or fresh entrails. If it fits on the bed, it ships.", "Rule four: Don't ask what's rattling in the crates. You won't like the answer.", "Greydwarfs throwing rocks at my chassis? Amateur hour.", "I drive. That’s what I do. You want someone to hold your hand and chop birch, hire a dwarf.", "One scratch on this finish and your corpse pays for the resin polish.", "Troll in the road. Hold your lunch.", "I asked for precise coordinates, mate. Not 'past the big spooky tree on the left.'", "If Odin himself steps in front of this axle, he'd better have the fare ready.", "You broke rule one. You changed the drop point. That's gonna cost you another stack of silver.", "Suspension is custom ironwood. Rides rough, hits harder.", "Don't look at the package. Looking makes people curious. Curious gets people buried in the Black Forest.", "Two minutes ahead of schedule. That’s why you pay me the big coin.", "Lox in the middle lane. Time to test the bumper.", "I deliver on time, every time. Surviving the pickup was your responsibility.", "Put your helmet on, sunshine. We’re taking the shortcut down the mountain.", "Never change the deal. Ever.", "Engine’s running hot, terrain’s rough, and my patience is paper-thin. Let's move.", "You hear that rattle? That's fifty ingots of pure profit shaking in the boot.", "I don’t make friends on the road. I make deliveries.", "Fog in the Mistlands? Good. Harder for them to see what hit 'em.", "Rule five: If you're late to the wagon, you walk back to the longhouse.", "Keep your bow drawn and your eyes forward. I don't brake for Neck herds.", "They said carts couldn't climb mountains. Clearly, they hadn't met me.", "Fuel in the boiler, grease on the axles, and not a single copper coin wasted.", "Any luggage over five hundred kilos pays the heavy-haul surcharge.", "Smooth road never made a legendary wheelman." }; private static volatile bool s_pendingLiveSettings = false; public static TransporterVehicle NearestInstance { get { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Player.m_localPlayer == (Object)null || AllVehicles.Count == 0) { if (AllVehicles.Count <= 0) { return null; } return AllVehicles[0]; } Vector3 position = ((Component)Player.m_localPlayer).transform.position; TransporterVehicle result = null; float num = float.MaxValue; for (int i = 0; i < AllVehicles.Count; i++) { TransporterVehicle transporterVehicle = AllVehicles[i]; if (!((Object)(object)transporterVehicle == (Object)null)) { float num2 = Vector3.Distance(((Component)transporterVehicle).transform.position, position); if (num2 < num) { num = num2; result = transporterVehicle; } } } return result; } } public Rigidbody Body => m_body; public Container CargoContainer => m_container; public float CurrentSpeed => m_currentSpeed; public float Health { get { if (!((Object)(object)m_wearNTear != (Object)null)) { return TransporterConfig.Data.MaxVehicleHealth; } return m_wearNTear.GetHealthPercentage() * m_wearNTear.m_health; } } public float CurrentFuel { get { if ((Object)(object)m_nview == (Object)null || !m_nview.IsValid()) { return TransporterConfig.Data.MaxFuel; } return m_nview.GetZDO().GetFloat("Transporter_Fuel", 25f); } set { if ((Object)(object)m_nview != (Object)null && m_nview.IsValid()) { m_nview.GetZDO().Set("Transporter_Fuel", Mathf.Clamp(value, 0f, TransporterConfig.Data.MaxFuel)); } } } private void Awake() { //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) m_nview = ((Component)this).GetComponent<ZNetView>(); m_body = ((Component)this).GetComponent<Rigidbody>(); m_container = ((Component)this).GetComponent<Container>(); m_piece = ((Component)this).GetComponent<Piece>(); m_wearNTear = ((Component)this).GetComponent<WearNTear>(); if ((Object)(object)m_wearNTear != (Object)null) { m_wearNTear.m_health = TransporterConfig.Data.MaxVehicleHealth; } if ((Object)(object)m_body != (Object)null) { if (!m_body.isKinematic) { m_body.linearVelocity = Vector3.zero; m_body.angularVelocity = Vector3.zero; } m_body.isKinematic = true; m_body.useGravity = false; m_body.interpolation = (RigidbodyInterpolation)1; m_body.mass = 800f; } m_lastPosition = ((Component)this).transform.position; if (!AllVehicles.Contains(this)) { AllVehicles.Add(this); } InitializeVisuals(); } private void Start() { InitializeVisuals(); ApplyCurrentSettings(); } private void OnDestroy() { AllVehicles.Remove(this); } private bool IsPlacementGhost() { if (!((Object)(object)m_nview == (Object)null)) { return !m_nview.IsValid(); } return true; } public void InitializeVisuals() { Transform val = ((Component)this).transform.Find("Transporter_WagonModel"); if ((Object)(object)val != (Object)null) { m_wagonModelTransform = val; } if (m_allWheels.Count == 0 || (Object)(object)m_exhaustStack == (Object)null || (Object)(object)m_chair == (Object)null) { DiscoverParts(((Component)this).transform); } SetupDriver(); if (!IsPlacementGhost()) { SetupExhaustEffects(); SetupLamps(); EnsureFuelHold(); } ApplyCurrentSettings(); PositionLamps(); } private void DiscoverParts(Transform root) { //IL_00c5: Unknown result type (might be due to invalid IL or missing references) m_allWheels.Clear(); m_steerWheels.Clear(); m_wheelBaseRotations.Clear(); Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { string text = ((Object)val).name.ToLowerInvariant(); if (text == "chair") { m_chair = val; } else if (text == "tripo_part_27" || text.Contains("part_27") || text.Contains("exhaust")) { m_exhaustStack = val; } else if ((text.StartsWith("wheel") || text.Contains("wheel")) && !m_allWheels.Contains(val)) { m_allWheels.Add(val); m_wheelBaseRotations[val] = val.localRotation; if (text == "wheel1" || text == "wheel5") { m_steerWheels.Add(val); } } } TransporterPlugin.Log.LogInfo((object)$"Transporter: Discovered {m_allWheels.Count} wheels, chair: {(Object)(object)m_chair != (Object)null}, exhaust: {(Object)(object)m_exhaustStack != (Object)null}"); } private void SetupDriver() { if (!((Object)(object)m_driverInstance != (Object)null)) { Transform val = (((Object)(object)m_chair != (Object)null) ? m_chair : ((Component)this).transform); GameObject val2 = TransporterGlb.LoadGlb(TransporterPlugin.GetDriverGlbPath()); if (!((Object)(object)val2 == (Object)null)) { m_driverInstance = val2; ((Object)m_driverInstance).name = "Transporter_Driver"; m_driverInstance.transform.SetParent(val, false); CacheDriverBones(); m_driverInstance.SetActive(true); } } } private void CacheDriverBones() { //IL_003a: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)m_driverInstance == (Object)null) { return; } m_boneBaseRotations.Clear(); Transform[] componentsInChildren = m_driverInstance.GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { m_boneBaseRotations[val] = val.localRotation; switch (((Object)val).name.ToLowerInvariant()) { case "head": m_driverHead = val; break; case "pelvis": m_pelvis = val; break; case "spine_01": case "spine1": m_spine1 = val; break; case "spine_02": case "spine2": m_spine2 = val; break; case "thigh_l": m_thighL = val; break; case "thigh_r": m_thighR = val; break; case "calf_l": m_calfL = val; break; case "calf_r": m_calfR = val; break; case "upperarm_l": m_upperarmL = val; break; case "upperarm_r": m_upperarmR = val; break; case "lowerarm_l": m_lowerarmL = val; break; case "lowerarm_r": m_lowerarmR = val; break; } } } public void ApplyCurrentSettings() { //IL_0030: 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_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: 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_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_0229: 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_0244: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_02c3: Unknown result type (might be due to invalid IL or missing references) //IL_02d9: 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_0311: Unknown result type (might be due to invalid IL or missing references) //IL_0325: Unknown result type (might be due to invalid IL or missing references) //IL_032a: Unknown result type (might be due to invalid IL or missing references) //IL_035d: Unknown result type (might be due to invalid IL or missing references) //IL_0371: Unknown result type (might be due to invalid IL or missing references) //IL_0376: Unknown result type (might be due to invalid IL or missing references) //IL_03a9: Unknown result type (might be due to invalid IL or missing references) //IL_03bb: Unknown result type (might be due to invalid IL or missing references) //IL_03c0: Unknown result type (might be due to invalid IL or missing references) //IL_03f3: Unknown result type (might be due to invalid IL or missing references) //IL_0406: Unknown result type (might be due to invalid IL or missing references) //IL_040b: Unknown result type (might be due to invalid IL or missing references) TransporterSettingsData data = TransporterConfig.Data; if ((Object)(object)m_wagonModelTransform != (Object)null) { float num = Mathf.Clamp(data.WagonScale, 1f, 15f); m_wagonModelTransform.localScale = Vector3.one * num; BoxCollider component = ((Component)this).GetComponent<BoxCollider>(); if ((Object)(object)component != (Object)null) { component.size = new Vector3(0.55f * num, 0.7f * num, 1.1f * num); component.center = new Vector3(0f, 0.35f * num, 0f); } } if ((Object)(object)m_driverInstance != (Object)null) { float num2 = Mathf.Clamp(data.DriverScale, 0.02f, 1f); m_driverInstance.transform.localScale = Vector3.one * num2; m_driverInstance.transform.localPosition = new Vector3(data.DriverOffsetX, data.DriverOffsetY, data.DriverOffsetZ); m_driverInstance.transform.localRotation = Quaternion.Euler(data.DriverRotX, data.DriverRotY, data.DriverRotZ); if ((Object)(object)m_pelvis != (Object)null && m_boneBaseRotations.TryGetValue(m_pelvis, out var value)) { m_pelvis.localRotation = value * Quaternion.Euler(data.WaistRotX, data.WaistRotY, data.WaistRotZ); } if ((Object)(object)m_spine1 != (Object)null && m_boneBaseRotations.TryGetValue(m_spine1, out var value2)) { m_spine1.localRotation = value2 * Quaternion.Euler(data.SpineRotX, data.SpineRotY, data.SpineRotZ); } if ((Object)(object)m_thighL != (Object)null && m_boneBaseRotations.TryGetValue(m_thighL, out var value3)) { m_thighL.localRotation = value3 * Quaternion.Euler(data.ThighRotX, data.ThighRotY, data.ThighRotZ); } if ((Object)(object)m_thighR != (Object)null && m_boneBaseRotations.TryGetValue(m_thighR, out var value4)) { m_thighR.localRotation = value4 * Quaternion.Euler(data.ThighRotX, 0f - data.ThighRotY, 0f - data.ThighRotZ); } if ((Object)(object)m_calfL != (Object)null && m_boneBaseRotations.TryGetValue(m_calfL, out var value5)) { m_calfL.localRotation = value5 * Quaternion.Euler(data.CalfRotX, data.CalfRotY, data.CalfRotZ); } if ((Object)(object)m_calfR != (Object)null && m_boneBaseRotations.TryGetValue(m_calfR, out var value6)) { m_calfR.localRotation = value6 * Quaternion.Euler(data.CalfRotX, 0f - data.CalfRotY, 0f - data.CalfRotZ); } if ((Object)(object)m_upperarmL != (Object)null && m_boneBaseRotations.TryGetValue(m_upperarmL, out var value7)) { m_upperarmL.localRotation = value7 * Quaternion.Euler(data.ArmLeftRotX, data.ArmLeftRotY, data.ArmLeftRotZ); } if ((Object)(object)m_upperarmR != (Object)null && m_boneBaseRotations.TryGetValue(m_upperarmR, out var value8)) { m_upperarmR.localRotation = value8 * Quaternion.Euler(data.ArmRightRotX, data.ArmRightRotY, data.ArmRightRotZ); } if ((Object)(object)m_lowerarmL != (Object)null && m_boneBaseRotations.TryGetValue(m_lowerarmL, out var value9)) { m_lowerarmL.localRotation = value9 * Quaternion.Euler(0f, data.ElbowBend, 0f); } if ((Object)(object)m_lowerarmR != (Object)null && m_boneBaseRotations.TryGetValue(m_lowerarmR, out var value10)) { m_lowerarmR.localRotation = value10 * Quaternion.Euler(0f, 0f - data.ElbowBend, 0f); } } if ((Object)(object)m_wearNTear != (Object)null) { m_wearNTear.m_health = Mathf.Clamp(data.MaxVehicleHealth, 500f, 100000f); } PositionLamps(); } public void Repair() { if ((Object)(object)m_wearNTear != (Object)null) { m_wearNTear.Repair(); m_wearNTear.m_health = TransporterConfig.Data.MaxVehicleHealth; if ((Object)(object)m_nview != (Object)null && m_nview.IsValid()) { m_nview.GetZDO().Set("health", TransporterConfig.Data.MaxVehicleHealth); } } } public static void ApplyLiveSettings() { s_pendingLiveSettings = true; } private static void ProcessPendingLiveSettings() { if (!s_pendingLiveSettings) { return; } s_pendingLiveSettings = false; for (int i = 0; i < AllVehicles.Count; i++) { if ((Object)(object)AllVehicles[i] != (Object)null) { try { AllVehicles[i].ApplyCurrentSettings(); } catch (Exception ex) { TransporterPlugin.Log.LogWarning((object)("Error applying live settings to vehicle: " + ex.Message)); } } } } private void SetupExhaustEffects() { //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_01fe: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_0360: Unknown result type (might be due to invalid IL or missing references) //IL_0365: Unknown result type (might be due to invalid IL or missing references) //IL_0371: Unknown result type (might be due to invalid IL or missing references) //IL_0376: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)m_exhaustEffectObj != (Object)null || !TransporterPlugin.EnableExhaustVFX.Value) { return; } Transform val = (((Object)(object)m_exhaustStack != (Object)null) ? m_exhaustStack : (((Object)(object)m_chair != (Object)null) ? m_chair.parent : ((Component)this).transform)); PrefabManager instance = PrefabManager.Instance; GameObject val2 = ((instance != null) ? instance.GetPrefab("smelter") : null); if ((Object)(object)val2 == (Object)null && (Object)(object)ZNetScene.instance != (Object)null) { val2 = ZNetScene.instance.GetPrefab("smelter"); } if ((Object)(object)val2 == (Object)null && PrefabManager.Instance != null) { val2 = PrefabManager.Instance.GetPrefab("blastfurnace"); } if ((Object)(object)val2 == (Object)null && (Object)(object)ZNetScene.instance != (Object)null) { val2 = ZNetScene.instance.GetPrefab("blastfurnace"); } if ((Object)(object)val2 == (Object)null && (Object)(object)ZNetScene.instance != (Object)null) { val2 = ZNetScene.instance.GetPrefab("charcoal_kiln"); } if ((Object)(object)val2 == (Object)null && (Object)(object)ZNetScene.instance != (Object)null) { val2 = ZNetScene.instance.GetPrefab("fire_pit"); } if ((Object)(object)val2 == (Object)null) { return; } Transform val3 = null; Smelter component = val2.GetComponent<Smelter>(); if ((Object)(object)component != (Object)null && (Object)(object)component.m_enabledObject != (Object)null) { val3 = component.m_enabledObject.transform; } if ((Object)(object)val3 == (Object)null) { ParticleSystem componentInChildren = val2.GetComponentInChildren<ParticleSystem>(true); if ((Object)(object)componentInChildren != (Object)null) { val3 = ((Component)componentInChildren).transform; } } if (!((Object)(object)val3 != (Object)null)) { return; } m_exhaustEffectObj = Object.Instantiate<GameObject>(((Component)val3).gameObject, val, false); ((Object)m_exhaustEffectObj).name = "Transporter_SmelterExhaustVFX"; m_exhaustEffectObj.transform.localPosition = new Vector3(0f, 0.1f, 0f); m_exhaustEffectObj.transform.localRotation = Quaternion.Euler(-90f, 0f, 0f); m_exhaustEffectObj.transform.localScale = Vector3.one * 0.35f; MeshRenderer[] componentsInChildren = m_exhaustEffectObj.GetComponentsInChildren<MeshRenderer>(true); for (int i = 0; i < componentsInChildren.Length; i++) { ((Renderer)componentsInChildren[i]).enabled = false; } MeshFilter[] componentsInChildren2 = m_exhaustEffectObj.GetComponentsInChildren<MeshFilter>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { componentsInChildren2[i].sharedMesh = null; } Collider[] componentsInChildren3 = m_exhaustEffectObj.GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren3.Length; i++) { Object.Destroy((Object)(object)componentsInChildren3[i]); } AudioSource[] componentsInChildren4 = m_exhaustEffectObj.GetComponentsInChildren<AudioSource>(true); for (int i = 0; i < componentsInChildren4.Length; i++) { ((Behaviour)componentsInChildren4[i]).enabled = false; } Light[] componentsInChildren5 = m_exhaustEffectObj.GetComponentsInChildren<Light>(true); for (int i = 0; i < componentsInChildren5.Length; i++) { componentsInChildren5[i].range = 3f; } MonoBehaviour[] componentsInChildren6 = m_exhaustEffectObj.GetComponentsInChildren<MonoBehaviour>(true); for (int i = 0; i < componentsInChildren6.Length; i++) { Object.Destroy((Object)(object)componentsInChildren6[i]); } m_exhaustParticles = m_exhaustEffectObj.GetComponentsInChildren<ParticleSystem>(true); if (m_exhaustParticles != null && m_exhaustParticles.Length != 0) { m_baseEmissionRates = new float[m_exhaustParticles.Length]; for (int j = 0; j < m_exhaustParticles.Length; j++) { EmissionModule emission = m_exhaustParticles[j].emission; float[] baseEmissionRates = m_baseEmissionRates; int num = j; MinMaxCurve rateOverTime = ((EmissionModule)(ref emission)).rateOverTime; baseEmissionRates[num] = Mathf.Max(((MinMaxCurve)(ref rateOverTime)).constant, 3f); m_exhaustParticles[j].Play(); } } m_exhaustEffectObj.SetActive(true); TransporterPlugin.Log.LogInfo((object)"Transporter: Attached Smelter fire & smoke exhaust VFX to chimney stack!"); } private void UpdateExhaustVFX() { //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) if (m_exhaustParticles == null || m_exhaustParticles.Length == 0) { return; } float currentSpeed = m_currentSpeed; bool flag = !TransporterConfig.Data.EnableFuelSystem || CurrentFuel > 0.05f; bool flag2 = currentSpeed > 0.4f && flag; float num = (flag2 ? Mathf.Clamp01(currentSpeed / 8f) : 0f); for (int i = 0; i < m_exhaustParticles.Length; i++) { ParticleSystem val = m_exhaustParticles[i]; if (!((Object)(object)val == (Object)null)) { EmissionModule emission = val.emission; float num2 = ((m_baseEmissionRates != null && i < m_baseEmissionRates.Length) ? m_baseEmissionRates[i] : 4f); if (!flag) { ((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(0f); continue; } float num3 = (flag2 ? Mathf.Lerp(num2, num2 * 2.8f, num) : (num2 * 0.4f)); ((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(num3); MainModule main = val.main; ((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(flag2 ? Mathf.Lerp(1.5f, 4.2f, num) : 1f); } } } private void Update() { //IL_0044: Unknown result type (might be due to invalid IL or missing references) ProcessPendingLiveSettings(); if (IsPlacementGhost()) { return; } if ((Object)(object)Player.m_localPlayer != (Object)null) { Chat instance = Chat.instance; if (instance != null && !instance.IsChatDialogWindowVisible() && !Console.IsVisible() && !InventoryGui.IsVisible() && Input.GetKeyDown(TransporterPlugin.CommandHotkey.Value)) { TryToggleNearestTransporter(); } } if (TransporterConfig.Data.EnableDriverVoiceLines && TransporterConfig.Data.SpeechInterval > 5f) { m_speechTimer -= Time.deltaTime; if (m_speechTimer <= 0f) { m_speechTimer = TransporterConfig.Data.SpeechInterval + Random.Range(-10f, 15f); DriverSay(); } } UpdateDriverHead(); UpdateExhaustVFX(); EnsureFuelHold(); UpdateLamps(); UpdateBoilerFeed(); } private void TryToggleNearestTransporter() { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)Player.m_localPlayer == (Object)null) && !IsPlacementGhost() && Vector3.Distance(((Component)this).transform.position, ((Component)Player.m_localPlayer).transform.position) <= 30f) { ToggleFollow(Player.m_localPlayer); } } private void FixedUpdate() { if ((Object)(object)m_nview == (Object)null || !m_nview.IsValid()) { return; } bool num = IsFollowing(); bool flag = !TransporterConfig.Data.EnableFuelSystem || CurrentFuel > 0.01f; if (num && flag) { if (!m_nview.IsOwner()) { m_nview.ClaimOwnership(); } if (m_nview.IsOwner()) { if ((Object)(object)m_targetPlayer == (Object)null) { FindFollowTarget(); } UpdateFollowPhysics(); } } else { m_currentSpeed = Mathf.MoveTowards(m_currentSpeed, 0f, Time.fixedDeltaTime * 10f); m_hasAim = false; m_hasPlayerPlanar = false; } UpdateWheels(); } private void UpdateFollowPhysics() { //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0076: 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_007c: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_0241: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_024a: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_024f: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: 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_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0129: 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_00eb: 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_02d4: Unknown result type (might be due to invalid IL or missing references) //IL_02d9: Unknown result type (might be due to invalid IL or missing references) //IL_02db: 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_02e6: Unknown result type (might be due to invalid IL or missing references) //IL_02eb: Unknown result type (might be due to invalid IL or missing references) //IL_02f0: Unknown result type (might be due to invalid IL or missing references) //IL_02f3: Unknown result type (might be due to invalid IL or missing references) //IL_02f7: Unknown result type (might be due to invalid IL or missing references) //IL_02fa: Unknown result type (might be due to invalid IL or missing references) //IL_02ff: Unknown result type (might be due to invalid IL or missing references) //I