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 Ship Maintenance v1.0.1
BepInEx/plugins/ShipMaintenance/ShipMaintenance.dll
Decompiled an hour agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using LethalLib.Modules; using Microsoft.CodeAnalysis; using TMPro; using Unity.Collections; using Unity.Netcode; using Unity.Netcode.Samples; using UnityEngine; using UnityEngine.Events; using UnityEngine.InputSystem; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("ShipMaintenance")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.1.0")] [assembly: AssemblyInformationalVersion("1.0.1+6aafbc9c2358173c25b9bcc827f39391af5a5f8c")] [assembly: AssemblyProduct("ShipMaintenance")] [assembly: AssemblyTitle("ShipMaintenance")] [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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [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 ShipMaintenance { [HarmonyPatch(typeof(StormyWeather), "LightningStrike")] internal static class LightningContextPatch { [ThreadStatic] internal static int Depth; [HarmonyPrefix] internal static void Prefix() { Depth++; } [HarmonyFinalizer] internal static Exception? Finalizer(Exception? __exception) { Depth = Math.Max(0, Depth - 1); return __exception; } } [HarmonyPatch(typeof(Landmine), "SpawnExplosion")] internal static class MaintenanceExplosionPatch { private static double lastTime = -100.0; private static Vector3 lastPosition; [HarmonyPostfix] internal static void Postfix(Vector3 explosionPosition, float killRange, float damageRange) { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: 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_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) StartOfRound instance = StartOfRound.Instance; if (!MaintenanceRuntime.IsHost || !Plugin.HazardDamage.Value || (Object)(object)instance == (Object)null || instance.inShipPhase || !instance.shipHasLanded || (Object)(object)instance.shipBounds == (Object)null) { return; } float num = Mathf.Clamp(Mathf.Max(killRange, damageRange), 0f, 25f); float num2 = Vector3.Distance(instance.shipBounds.ClosestPoint(explosionPosition), explosionPosition); if (num2 > num) { return; } double clock = MaintenanceRuntime.Clock; if (clock >= lastTime && clock - lastTime < 0.12 && Vector3.SqrMagnitude(explosionPosition - lastPosition) < 0.25f) { return; } lastTime = clock; lastPosition = explosionPosition; int amount = MaintenanceRules.HazardLoss((LightningContextPatch.Depth > 0) ? Plugin.LightningDamage.Value : Plugin.ExplosionDamage.Value, num2, num); int num3 = -1; float num4 = float.MaxValue; for (int i = 0; i < 5; i++) { ServicePanel servicePanel = MaintenanceRuntime.Panels[i]; if (!((Object)(object)servicePanel == (Object)null)) { float num5 = Vector3.SqrMagnitude(((Component)servicePanel).transform.position - explosionPosition); if (num5 < num4) { num4 = num5; num3 = i; } } } if (MaintenanceRuntime.State.Damage(num3, amount)) { MaintenanceRuntime.Jobs[num3].Reset(); MaintenanceRuntime.Broadcast(); Plugin.Log.LogInfo((object)(((LightningContextPatch.Depth > 0) ? "Lightning" : "Explosion") + " damaged " + ServicePanel.Names[num3] + " by " + amount + " condition.")); } } } internal static class ItemCatalog { internal static Item Oil; internal static Item Fuse; internal static Item Spent; internal static void Register() { Oil = Create("Maintenance oil", 77100, spent: false, fuse: false); Fuse = Create("Maintenance fuse", 77101, spent: false, fuse: true); Spent = Create("Spent apparatus", 77102, spent: true, fuse: false); TerminalNode val = ScriptableObject.CreateInstance<TerminalNode>(); val.displayText = "Refills the separate oil fill port on the rear ship wall. Hold this can and hold E at the oil port while landed. Engine repair panels need no consumables. Consumed only when service finishes.\n\n"; TerminalNode val2 = ScriptableObject.CreateInstance<TerminalNode>(); val2.displayText = "Replacement fuse for the roof electrical panel. Hold this fuse and hold E at the rooftop service panel. Consumed only when service finishes.\n\n"; Items.RegisterShopItem(Oil, (TerminalNode)null, (TerminalNode)null, val, Plugin.OilCost.Value); Items.RegisterShopItem(Fuse, (TerminalNode)null, (TerminalNode)null, val2, Plugin.FuseCost.Value); Items.RegisterItem(Spent); } private static Item Create(string name, int id, bool spent, bool fuse) { //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_0255: Unknown result type (might be due to invalid IL or missing references) //IL_025f: Expected O, but got Unknown //IL_02ab: Unknown result type (might be due to invalid IL or missing references) //IL_02d1: Unknown result type (might be due to invalid IL or missing references) //IL_02f7: Unknown result type (might be due to invalid IL or missing references) //IL_030e: Unknown result type (might be due to invalid IL or missing references) //IL_0314: Unknown result type (might be due to invalid IL or missing references) //IL_031e: Unknown result type (might be due to invalid IL or missing references) //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_027f: Unknown result type (might be due to invalid IL or missing references) //IL_0445: Unknown result type (might be due to invalid IL or missing references) //IL_0459: Unknown result type (might be due to invalid IL or missing references) //IL_0481: Unknown result type (might be due to invalid IL or missing references) //IL_0495: Unknown result type (might be due to invalid IL or missing references) //IL_04a8: Unknown result type (might be due to invalid IL or missing references) //IL_04ad: Unknown result type (might be due to invalid IL or missing references) //IL_04bf: Unknown result type (might be due to invalid IL or missing references) //IL_04c7: Unknown result type (might be due to invalid IL or missing references) //IL_04ce: Unknown result type (might be due to invalid IL or missing references) //IL_0368: Unknown result type (might be due to invalid IL or missing references) //IL_037c: Unknown result type (might be due to invalid IL or missing references) //IL_03af: Unknown result type (might be due to invalid IL or missing references) //IL_03c3: Unknown result type (might be due to invalid IL or missing references) //IL_03fc: Unknown result type (might be due to invalid IL or missing references) //IL_0410: Unknown result type (might be due to invalid IL or missing references) //IL_051a: Unknown result type (might be due to invalid IL or missing references) //IL_0521: Expected O, but got Unknown //IL_05bb: Unknown result type (might be due to invalid IL or missing references) //IL_05ca: Unknown result type (might be due to invalid IL or missing references) //IL_0557: Unknown result type (might be due to invalid IL or missing references) //IL_0577: Unknown result type (might be due to invalid IL or missing references) //IL_0572: Unknown result type (might be due to invalid IL or missing references) //IL_056b: Unknown result type (might be due to invalid IL or missing references) //IL_0564: Unknown result type (might be due to invalid IL or missing references) Item val = ScriptableObject.CreateInstance<Item>(); ((Object)val).name = name.Replace(" ", ""); val.itemName = name; val.itemId = id; val.requiresBattery = false; val.isScrap = spent; val.canBeGrabbedBeforeGameStart = true; val.disallowUtilitySlot = true; val.weight = (spent ? 1.15f : 1.02f); val.toolTips = Array.Empty<string>(); val.grabAnim = ""; val.grabAnimationTime = 0.3f; val.useAnim = (val.pocketAnim = (val.throwAnim = "")); val.grabSFX = (val.dropSFX = (val.pocketSFX = (val.throwSFX = Visuals.HandlingClip()))); val.restingRotation = Vector3.zero; val.positionOffset = new Vector3(0.05f, 0.02f, 0.04f); val.rotationOffset = new Vector3(0f, 0f, 0f); val.verticalOffset = (spent ? 0.22f : 0.15f); val.minValue = 0; val.maxValue = 1000000; val.highestSalePercentage = 100; val.meshVariants = Array.Empty<Mesh>(); val.materialVariants = Array.Empty<Material>(); val.clinkAudios = Array.Empty<AudioClip>(); val.creditsWorth = ((!spent) ? (fuse ? Plugin.FuseCost.Value : Plugin.OilCost.Value) : 0); GameObject val2 = NetworkPrefabs.CreateNetworkPrefab("ShipMaintenance_" + ((Object)val).name); val2.AddComponent<RuntimeItem>(); val2.layer = 6; val2.tag = "PhysicsProp"; val2.AddComponent<ClientNetworkTransform>(); Rigidbody val3 = val2.AddComponent<Rigidbody>(); val3.isKinematic = true; val3.useGravity = false; val2.AddComponent<NetworkRigidbodyModifiable>().kinematicOnOwner = true; BoxCollider val4 = val2.AddComponent<BoxCollider>(); val4.size = (spent ? new Vector3(0.52f, 0.5f, 0.3f) : new Vector3(0.23f, 0.3f, 0.17f)); AudioSource obj = val2.AddComponent<AudioSource>(); obj.playOnAwake = false; obj.spatialBlend = 1f; PhysicsProp obj2 = val2.AddComponent<PhysicsProp>(); ((GrabbableObject)obj2).itemProperties = val; ((GrabbableObject)obj2).grabbable = true; ((GrabbableObject)obj2).grabbableToEnemies = true; ((GrabbableObject)obj2).propBody = val3; ((GrabbableObject)obj2).isInFactory = false; ((GrabbableObject)obj2).insertedBattery = new Battery(false, 1f); Material material = Visuals.Paint(name + " paint", spent ? new Color(0.28f, 0.3f, 0.25f) : (fuse ? new Color(0.65f, 0.12f, 0.08f) : new Color(0.83f, 0.59f, 0.12f))); Material material2 = Visuals.Paint(name + " dark", new Color(0.04f, 0.045f, 0.04f)); Material material3 = Visuals.Paint(name + " metal", new Color(0.58f, 0.57f, 0.49f)); GameObject val5 = Visuals.Part(val2.transform, "Body", Vector3.zero, val4.size * 0.9f, material, (PrimitiveType)3); ((GrabbableObject)obj2).mainObjectRenderer = val5.GetComponent<MeshRenderer>(); if (spent) { for (int i = 0; i < 5; i++) { Visuals.Part(val2.transform, "Spent coil", new Vector3(0f, -0.18f + (float)i * 0.08f, -0.18f), new Vector3(0.45f, 0.022f, 0.03f), material3, (PrimitiveType)3); } Visuals.Part(val2.transform, "Dead core", new Vector3(0f, 0.06f, -0.19f), new Vector3(0.08f, 0.28f, 0.06f), material2, (PrimitiveType)3); } else if (fuse) { for (int j = -1; j <= 1; j += 2) { Visuals.Part(val2.transform, "Fuse contact", new Vector3(0f, (float)j * 0.14f, 0f), new Vector3(0.21f, 0.06f, 0.15f), material3, (PrimitiveType)3); } } else { Visuals.Part(val2.transform, "Spout", new Vector3(0.06f, 0.2f, 0f), new Vector3(0.05f, 0.17f, 0.05f), material3, (PrimitiveType)3); Visuals.Part(val2.transform, "Oil stripe", new Vector3(0f, 0f, -0.082f), new Vector3(0.17f, 0.045f, 0.015f), material2, (PrimitiveType)3); } GameObject val6 = new GameObject("ScanNode"); val6.transform.SetParent(val2.transform, false); val6.layer = 22; val6.AddComponent<BoxCollider>().size = val4.size; ScanNodeProperties obj3 = val6.AddComponent<ScanNodeProperties>(); obj3.headerText = name; obj3.subText = (spent ? "Depleted - sell for scrap" : "Maintenance supply"); obj3.nodeType = (spent ? 2 : 0); obj3.minRange = 0; obj3.maxRange = 13; Texture2D val7 = new Texture2D(32, 32, (TextureFormat)4, false); Color[] array = (Color[])(object)new Color[1024]; for (int k = 0; k < 32; k++) { for (int l = 0; l < 32; l++) { array[k * 32 + l] = ((l >= 8 && l < 24 && k >= 4 && k < 27) ? (fuse ? Color.red : (spent ? Color.gray : Color.yellow)) : Color.clear); } } val7.SetPixels(array); val7.Apply(); val.itemIcon = Sprite.Create(val7, new Rect(0f, 0f, 32f, 32f), new Vector2(0.5f, 0.5f), 32f); val.spawnPrefab = val2; return val; } internal static void ApplyPrices(int oil, int fuse) { Oil.creditsWorth = oil; Fuse.creditsWorth = fuse; foreach (ShopItem shopItem in Items.shopItems) { if ((Object)(object)shopItem.item == (Object)(object)Oil || (Object)(object)shopItem.item == (Object)(object)Fuse) { shopItem.price = shopItem.item.creditsWorth; } } } } internal static class MaintenanceRules { internal const ulong Nobody = ulong.MaxValue; internal const int Systems = 5; internal const int OilPort = 4; internal const int Booster = 5; internal const int Stations = 6; internal const int SaveValues = 10; internal const int SnapshotBytes = 337; internal const float Reach = 3.5f; internal const int NoiseId = 18474; internal static int Clamp(int value, int min, int max) { return Math.Max(min, Math.Min(max, value)); } internal static int Quote(int basePrice, int condition, int maintenancePercent, bool boost, int boostPercent) { if (basePrice <= 0) { return 0; } decimal num = 1m - (decimal)(Clamp(condition, 0, 100) * Clamp(maintenancePercent, 0, 75)) / 10000m; if (boost) { num *= 1m - (decimal)Clamp(boostPercent, 0, 95) / 100m; } return Math.Min(basePrice, Math.Max(1, (int)Math.Ceiling((decimal)basePrice * num))); } internal static int SpentValue(int original, int percent) { return (int)((long)Clamp(original, 0, 1000000) * (long)Clamp(percent, 0, 90) / 100); } internal static int HazardLoss(int baseDamage, float distance, float radius) { if (float.IsNaN(distance) || float.IsNaN(radius) || distance < 0f || radius < 0f || distance > radius) { return 0; } return (int)Math.Ceiling((double)Clamp(baseDamage, 0, 100) * (1.0 - (double)distance / ((double)radius + 1.0))); } } internal sealed class MaintenanceState { internal readonly int[] Condition = new int[5] { 100, 100, 100, 100, 100 }; internal int BoostValue = -1; internal int PendingSpentValue = -1; internal bool VisitActive; internal int Days; internal bool BoostReady => BoostValue >= 0; internal int Average { get { int num = 0; int[] condition = Condition; foreach (int num2 in condition) { num += num2; } return num / Condition.Length; } } internal bool FinishVisit(int decay) { if (!VisitActive) { return false; } VisitActive = false; Days = MaintenanceRules.Clamp(Days + 1, 0, 1000000); for (int i = 0; i < Condition.Length; i++) { Condition[i] = Math.Max(0, Condition[i] - MaintenanceRules.Clamp(decay, 0, 100)); } return true; } internal bool LoadApparatus(int value) { if (BoostReady || PendingSpentValue >= 0) { return false; } BoostValue = MaintenanceRules.Clamp(value, 0, 1000000); return true; } internal bool Damage(int system, int amount) { if (system < 0 || system >= Condition.Length || amount <= 0) { return false; } int num = Math.Max(0, Condition[system] - MaintenanceRules.Clamp(amount, 0, 100)); bool result = num != Condition[system]; Condition[system] = num; return result; } internal bool Repair(int system) { if (system < 0 || system >= Condition.Length || Condition[system] >= 100) { return false; } Condition[system] = 100; return true; } internal bool SpendBoost(int originalRoutePrice, int salvagePercent) { if (originalRoutePrice <= 0 || !BoostReady) { return false; } PendingSpentValue = MaintenanceRules.SpentValue(BoostValue, salvagePercent); BoostValue = -1; return true; } internal int[] Save() { return new int[10] { 1, Condition[0], Condition[1], Condition[2], Condition[3], Condition[4], BoostValue, PendingSpentValue, VisitActive ? 1 : 0, Days }; } internal static MaintenanceState Load(int[]? data) { MaintenanceState maintenanceState = new MaintenanceState(); if (data == null || data.Length != 10 || data[0] != 1) { return maintenanceState; } for (int i = 0; i < 5; i++) { maintenanceState.Condition[i] = MaintenanceRules.Clamp(data[i + 1], 0, 100); } maintenanceState.BoostValue = MaintenanceRules.Clamp(data[6], -1, 1000000); maintenanceState.PendingSpentValue = MaintenanceRules.Clamp(data[7], -1, 1000000); if (maintenanceState.PendingSpentValue >= 0) { maintenanceState.BoostValue = -1; } maintenanceState.VisitActive = data[8] == 1; maintenanceState.Days = MaintenanceRules.Clamp(data[9], 0, 1000000); return maintenanceState; } } internal sealed class ServiceJob { internal ulong Worker = ulong.MaxValue; internal ulong Item = ulong.MaxValue; internal double Started; internal double ReadyAt; internal double Expires; internal bool Active => Worker != ulong.MaxValue; internal bool Begin(ulong worker, ulong item, double now, float seconds) { if (Active || worker == ulong.MaxValue) { return false; } Worker = worker; Item = item; Started = now; ReadyAt = now + (double)Math.Max(1f, seconds); Expires = now + 1.2; return true; } internal bool Heartbeat(ulong worker, ulong item, double now) { if (!Active || Worker != worker || Item != item || now > Expires) { return false; } Expires = now + 1.2; return true; } internal bool Complete(double now, bool valid) { if (Active && valid && now <= Expires) { return now >= ReadyAt; } return false; } internal bool Cancel(ulong worker) { if (Worker != worker) { return false; } Reset(); return true; } internal void Reset() { Worker = (Item = ulong.MaxValue); Started = (ReadyAt = (Expires = 0.0)); } } internal enum Notice : byte { Finished, NeedOil, NeedFuse, NeedApparatus, LandFirst, Full, Busy, TooFar, Charged, Invalid, PriceChanged } public sealed class MaintenanceRuntime : MonoBehaviour { [CompilerGenerated] private static class <>O { public static HandleNamedMessageDelegate <0>__OnRequest; public static HandleNamedMessageDelegate <1>__OnState; public static HandleNamedMessageDelegate <2>__OnConsume; public static HandleNamedMessageDelegate <3>__OnNotice; public static HandleNamedMessageDelegate <4>__OnSpent; } private const string RequestName = "sockpoop.shipmaintenance.request.v1"; private const string StateName = "sockpoop.shipmaintenance.state.v1"; private const string ConsumeName = "sockpoop.shipmaintenance.consume.v1"; private const string NoticeName = "sockpoop.shipmaintenance.notice.v1"; private const string SpentName = "sockpoop.shipmaintenance.spent.v1"; internal const string SaveKey = "sockpoop.shipmaintenance.v1"; internal static MaintenanceState State = new MaintenanceState(); internal static readonly ServiceJob[] Jobs = new ServiceJob[6] { new ServiceJob(), new ServiceJob(), new ServiceJob(), new ServiceJob(), new ServiceJob(), new ServiceJob() }; internal static readonly ServicePanel?[] Panels = new ServicePanel[6]; internal static readonly Vector3[] Positions = (Vector3[])(object)new Vector3[6]; internal static bool Ready; internal static int Discount = 25; internal static int Decay = 18; internal static int OilPrice = 5; internal static int FusePrice = 8; internal static int BoostDiscount = 80; internal static int Salvage = 25; internal static float Seconds = 8f; internal static float NoiseRange = 26f; internal static bool AllowOrbit; private static NetworkManager? network; private static Terminal? terminal; private static int held = -1; private static ulong heldItem; private static bool confirmed; private static float nextHeartbeat; private float nextSnapshot; private float nextNoise; private StartOfRound? currentRound; private static readonly Dictionary<ulong, (int value, Vector3 position, float expires)> pendingShells = new Dictionary<ulong, (int, Vector3, float)>(); internal static double Clock { get { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)network != (Object)null) || !network.IsListening) { return 0.0; } NetworkTime serverTime = network.ServerTime; return ((NetworkTime)(ref serverTime)).Time; } } internal static bool IsHost { get { if ((Object)(object)network != (Object)null && network.IsServer) { return Ready; } return false; } } internal static Terminal? Terminal { get { if (!((Object)(object)terminal != (Object)null)) { return terminal = Object.FindObjectOfType<Terminal>(); } return terminal; } } private void Update() { //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Expected O, but got Unknown //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Expected O, but got Unknown //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Expected O, but got Unknown //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Expected O, but got Unknown //IL_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0468: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; StartOfRound instance = StartOfRound.Instance; if ((Object)(object)singleton == (Object)null || !singleton.IsListening || singleton.CustomMessagingManager == null || (Object)(object)instance == (Object)null || (Object)(object)instance.elevatorTransform == (Object)null) { if ((Object)(object)network != (Object)null) { Disconnect(); } return; } if ((Object)(object)network != (Object)(object)singleton || (Object)(object)currentRound != (Object)(object)instance) { Disconnect(); network = singleton; currentRound = instance; CustomMessagingManager customMessagingManager = network.CustomMessagingManager; object obj = <>O.<0>__OnRequest; if (obj == null) { HandleNamedMessageDelegate val = OnRequest; <>O.<0>__OnRequest = val; obj = (object)val; } customMessagingManager.RegisterNamedMessageHandler("sockpoop.shipmaintenance.request.v1", (HandleNamedMessageDelegate)obj); CustomMessagingManager customMessagingManager2 = network.CustomMessagingManager; object obj2 = <>O.<1>__OnState; if (obj2 == null) { HandleNamedMessageDelegate val2 = OnState; <>O.<1>__OnState = val2; obj2 = (object)val2; } customMessagingManager2.RegisterNamedMessageHandler("sockpoop.shipmaintenance.state.v1", (HandleNamedMessageDelegate)obj2); CustomMessagingManager customMessagingManager3 = network.CustomMessagingManager; object obj3 = <>O.<2>__OnConsume; if (obj3 == null) { HandleNamedMessageDelegate val3 = OnConsume; <>O.<2>__OnConsume = val3; obj3 = (object)val3; } customMessagingManager3.RegisterNamedMessageHandler("sockpoop.shipmaintenance.consume.v1", (HandleNamedMessageDelegate)obj3); CustomMessagingManager customMessagingManager4 = network.CustomMessagingManager; object obj4 = <>O.<3>__OnNotice; if (obj4 == null) { HandleNamedMessageDelegate val4 = OnNotice; <>O.<3>__OnNotice = val4; obj4 = (object)val4; } customMessagingManager4.RegisterNamedMessageHandler("sockpoop.shipmaintenance.notice.v1", (HandleNamedMessageDelegate)obj4); CustomMessagingManager customMessagingManager5 = network.CustomMessagingManager; object obj5 = <>O.<4>__OnSpent; if (obj5 == null) { HandleNamedMessageDelegate val5 = OnSpent; <>O.<4>__OnSpent = val5; obj5 = (object)val5; } customMessagingManager5.RegisterNamedMessageHandler("sockpoop.shipmaintenance.spent.v1", (HandleNamedMessageDelegate)obj5); for (int i = 0; i < 6; i++) { Positions[i] = Plugin.Positions[i].Value; } if (network.IsServer) { LoadHost(); } nextSnapshot = 0f; } if ((Object)(object)Terminal == (Object)null) { return; } for (int j = 0; j < 6; j++) { if ((Object)(object)Panels[j] == (Object)null) { Panels[j] = ServicePanel.Create(j, instance.elevatorTransform, Positions[j]); } ((Component)Panels[j]).transform.localPosition = Positions[j]; } if (!Ready && Time.realtimeSinceStartup >= nextSnapshot) { Request(0, 0, 0uL); nextSnapshot = Time.realtimeSinceStartup + 1f; } ApplySpentDeliveries(); Notice reason; if (held >= 0) { PlayerControllerB val6 = GameNetworkManager.Instance?.localPlayerController; if (!((Object)(object)InputSystem.actions != (Object)null) || !InputSystem.actions.FindAction("Interact", false).IsPressed() || (Object)(object)val6 == (Object)null || val6.inTerminalMenu || val6.isTypingChat || !CanWork(val6, held, heldItem, out reason)) { StopLocal(); } else if (Time.realtimeSinceStartup >= nextHeartbeat) { Request(2, (byte)held, heldItem); nextHeartbeat = Time.realtimeSinceStartup + 0.25f; } } if (!IsHost) { return; } if (instance.shipHasLanded && !instance.inShipPhase && (Object)(object)instance.currentLevel != (Object)null && instance.currentLevel.planetHasTime) { State.VisitActive = true; } if (instance.inShipPhase && !instance.shipIsLeaving && !instance.shipHasLanded && State.FinishVisit(Decay)) { Broadcast(); } for (int k = 0; k < 6; k++) { ServiceJob serviceJob = Jobs[k]; if (serviceJob.Active) { PlayerControllerB val7 = Player(serviceJob.Worker); bool flag = (Object)(object)val7 != (Object)null && CanWork(val7, k, serviceJob.Item, out reason); if (!flag || Clock > serviceJob.Expires) { serviceJob.Reset(); Broadcast(); } else if (serviceJob.Complete(Clock, flag)) { Complete(k, val7); } } } if (Time.realtimeSinceStartup >= nextNoise) { nextNoise = Time.realtimeSinceStartup + 0.65f; if (!instance.inShipPhase && (Object)(object)RoundManager.Instance != (Object)null) { for (int l = 0; l < 6; l++) { if (Jobs[l].Active && (Object)(object)Panels[l] != (Object)null) { RoundManager.Instance.PlayAudibleNoise(((Component)Panels[l]).transform.position, NoiseRange, 0.85f, 0, l == 5 && instance.hangarDoorsClosed, 18474); } } } } if (State.PendingSpentValue >= 0 && instance.inShipPhase && !instance.travellingToNewLevel && !instance.beganLoadingNewLevel) { ReturnSpent(); } } private static void LoadHost() { Discount = Plugin.MaxDiscount.Value; Decay = Plugin.Wear.Value; OilPrice = Plugin.OilCost.Value; FusePrice = Plugin.FuseCost.Value; BoostDiscount = Plugin.BoostDiscount.Value; Salvage = Plugin.SpentPercent.Value; Seconds = Plugin.ServiceSeconds.Value; AllowOrbit = Plugin.WorkInOrbit.Value; NoiseRange = Plugin.NoiseRange.Value; try { State = MaintenanceState.Load(ES3.Load<int[]>("sockpoop.shipmaintenance.v1", GameNetworkManager.Instance.currentSaveFileName, Array.Empty<int>())); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Maintenance save could not be read; using new-ship condition: " + ex.Message)); State = new MaintenanceState(); } ItemCatalog.ApplyPrices(OilPrice, FusePrice); Ready = true; } internal static void SaveHost() { if (!IsHost || (Object)(object)GameNetworkManager.Instance == (Object)null || (Object)(object)StartOfRound.Instance == (Object)null || StartOfRound.Instance.isChallengeFile) { return; } try { ES3.Save<int[]>("sockpoop.shipmaintenance.v1", State.Save(), GameNetworkManager.Instance.currentSaveFileName); } catch (Exception ex) { Plugin.Log.LogError((object)("Could not save ship maintenance: " + ex)); } } internal static void ResetHost() { if (IsHost) { State = new MaintenanceState(); ServiceJob[] jobs = Jobs; for (int i = 0; i < jobs.Length; i++) { jobs[i].Reset(); } Broadcast(); SaveHost(); } } private void Disconnect() { if ((Object)(object)network != (Object)null && network.CustomMessagingManager != null) { string[] array = new string[5] { "sockpoop.shipmaintenance.request.v1", "sockpoop.shipmaintenance.state.v1", "sockpoop.shipmaintenance.consume.v1", "sockpoop.shipmaintenance.notice.v1", "sockpoop.shipmaintenance.spent.v1" }; foreach (string text in array) { network.CustomMessagingManager.UnregisterNamedMessageHandler(text); } } network = null; currentRound = null; terminal = null; Ready = false; held = -1; confirmed = false; State = new MaintenanceState(); ServiceJob[] jobs = Jobs; for (int i = 0; i < jobs.Length; i++) { jobs[i].Reset(); } pendingShells.Clear(); for (int j = 0; j < 6; j++) { if ((Object)(object)Panels[j] != (Object)null) { Object.Destroy((Object)(object)((Component)Panels[j]).gameObject); Panels[j] = null; } } } private void OnDestroy() { Disconnect(); } internal static PlayerControllerB? Player(ulong id) { if ((Object)(object)StartOfRound.Instance == (Object)null) { return null; } PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts; foreach (PlayerControllerB val in allPlayerScripts) { if ((Object)(object)val != (Object)null && val.actualClientId == id && val.isPlayerControlled) { return val; } } return null; } private static ulong HeldId(PlayerControllerB player, int station) { if (station > 2) { if (!((Object)(object)player.currentlyHeldObjectServer != (Object)null)) { return ulong.MaxValue; } return ((NetworkBehaviour)player.currentlyHeldObjectServer).NetworkObjectId; } return ulong.MaxValue; } private static bool CanWork(PlayerControllerB player, int station, ulong itemId, out Notice reason) { //IL_007f: 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) reason = Notice.Invalid; StartOfRound instance = StartOfRound.Instance; if (!Ready || station < 0 || station >= 6 || (Object)(object)player == (Object)null || player.isPlayerDead || !player.isPlayerControlled || player.inSpecialInteractAnimation || (Object)(object)instance == (Object)null || instance.shipIsLeaving || instance.travellingToNewLevel || instance.beganLoadingNewLevel || instance.firingPlayersCutsceneRunning || (Object)(object)Panels[station] == (Object)null) { return false; } if (Vector3.Distance(((Component)player.gameplayCamera).transform.position, ((Component)Panels[station]).transform.position) > 3.5f) { reason = Notice.TooFar; return false; } if (station < 5 && !instance.shipHasLanded && !AllowOrbit) { reason = Notice.LandFirst; return false; } if (station < 5 && State.Condition[station] >= 100) { reason = Notice.Full; return false; } if (station == 5 && (State.BoostReady || State.PendingSpentValue >= 0)) { reason = Notice.Charged; return false; } if (station <= 2) { return true; } GrabbableObject currentlyHeldObjectServer = player.currentlyHeldObjectServer; reason = station switch { 3 => Notice.NeedFuse, 4 => Notice.NeedOil, _ => Notice.NeedApparatus, }; if ((Object)(object)currentlyHeldObjectServer == (Object)null || !((NetworkBehaviour)currentlyHeldObjectServer).IsSpawned || ((NetworkBehaviour)currentlyHeldObjectServer).NetworkObjectId != itemId || (Object)(object)currentlyHeldObjectServer.playerHeldBy != (Object)(object)player || !currentlyHeldObjectServer.isHeld || player.currentItemSlot < 0 || player.currentItemSlot >= player.ItemSlots.Length || (Object)(object)player.ItemSlots[player.currentItemSlot] != (Object)(object)currentlyHeldObjectServer) { return false; } switch (station) { case 4: return (Object)(object)currentlyHeldObjectServer.itemProperties == (Object)(object)ItemCatalog.Oil; case 3: return (Object)(object)currentlyHeldObjectServer.itemProperties == (Object)(object)ItemCatalog.Fuse; default: { LungProp val = (LungProp)(object)((currentlyHeldObjectServer is LungProp) ? currentlyHeldObjectServer : null); if (val != null && !val.isLungDocked && !val.isLungDockedInElevator && val.isLungPowered) { return currentlyHeldObjectServer.itemProperties.isScrap; } return false; } } } internal static void BeginLocal(int station) { PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController; if (!((Object)(object)val == (Object)null) && !((Object)(object)network == (Object)null)) { ulong num = HeldId(val, station); if (!CanWork(val, station, num, out var reason)) { Show(reason); return; } StopLocal(); held = station; heldItem = num; confirmed = false; nextHeartbeat = Time.realtimeSinceStartup + 0.2f; Request(1, (byte)station, num); } } private static void StopLocal() { if (held >= 0) { Request(3, (byte)held, heldItem); } held = -1; confirmed = false; } private unsafe static void Request(byte action, byte station, ulong item) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)network == (Object)null || !network.IsListening) { return; } if (network.IsServer) { Handle(network.LocalClientId, action, station, item); return; } FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(16, (Allocator)2, -1); try { ((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref action, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref station, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref item, default(ForPrimitives)); network.CustomMessagingManager.SendNamedMessage("sockpoop.shipmaintenance.request.v1", 0uL, val, (NetworkDelivery)3); } finally { ((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose(); } } private static void OnRequest(ulong sender, FastBufferReader reader) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) if (IsHost && ((FastBufferReader)(ref reader)).TryBeginRead(10)) { byte action = default(byte); ((FastBufferReader)(ref reader)).ReadValueSafe<byte>(ref action, default(ForPrimitives)); byte station = default(byte); ((FastBufferReader)(ref reader)).ReadValueSafe<byte>(ref station, default(ForPrimitives)); ulong item = default(ulong); ((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref item, default(ForPrimitives)); Handle(sender, action, station, item); } } private static void Handle(ulong sender, byte action, byte station, ulong item) { if (!IsHost || !network.ConnectedClients.ContainsKey(sender)) { return; } if (action == 0) { Broadcast(sender); } else { if (station >= 6 || action > 3) { return; } if (action == 3) { if (Jobs[station].Cancel(sender)) { Broadcast(); } return; } PlayerControllerB val = Player(sender); Notice reason = Notice.Invalid; if ((Object)(object)val == (Object)null || !CanWork(val, station, item, out reason)) { if (Jobs[station].Cancel(sender)) { Broadcast(); } if (action == 1) { Tell(sender, reason); } return; } if (action == 2) { Jobs[station].Heartbeat(sender, item, Clock); return; } ServiceJob[] jobs = Jobs; foreach (ServiceJob serviceJob in jobs) { if (serviceJob.Active && serviceJob.Worker == sender) { Tell(sender, Notice.Busy); return; } } if (!Jobs[station].Begin(sender, item, Clock, (station == 5) ? 2f : Seconds)) { Tell(sender, Notice.Busy); } else { Broadcast(); } } } private static void Complete(int station, PlayerControllerB worker) { ulong worker2 = Jobs[station].Worker; Jobs[station].Reset(); if (station == 5) { State.LoadApparatus(worker.currentlyHeldObjectServer.scrapValue); } else { State.Repair(station); } if (station > 2) { Consume(worker); } Tell(worker2, Notice.Finished); Broadcast(); } private unsafe static void Consume(PlayerControllerB player) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) int currentItemSlot = player.currentItemSlot; if (!((NetworkBehaviour)player).IsOwner) { FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(16, (Allocator)2, -1); try { ((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref currentItemSlot, default(ForPrimitives)); ulong networkObjectId = ((NetworkBehaviour)player.currentlyHeldObjectServer).NetworkObjectId; ((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref networkObjectId, default(ForPrimitives)); network.CustomMessagingManager.SendNamedMessage("sockpoop.shipmaintenance.consume.v1", player.actualClientId, val, (NetworkDelivery)3); } finally { ((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose(); } } player.DestroyItemInSlotClientRpc(currentItemSlot); if (((NetworkBehaviour)player).IsOwner) { player.DestroyItemInSlot(currentItemSlot); } } private static void OnConsume(ulong sender, FastBufferReader reader) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) if (sender != 0L || !((FastBufferReader)(ref reader)).TryBeginRead(12)) { return; } int num = default(int); ((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives)); ulong num2 = default(ulong); ((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref num2, default(ForPrimitives)); PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController; if (!((Object)(object)val == (Object)null) && num >= 0 && num < val.ItemSlots.Length) { GrabbableObject val2 = val.ItemSlots[num]; if ((Object)(object)val2 != (Object)null && ((NetworkBehaviour)val2).NetworkObjectId == num2) { val.DestroyItemInSlot(num); } } } private unsafe static void ReturnSpent() { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_0107: 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_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) StartOfRound instance = StartOfRound.Instance; GameObject val = Object.Instantiate<GameObject>(ItemCatalog.Spent.spawnPrefab, instance.elevatorTransform.TransformPoint(Positions[5] + new Vector3(0f, -0.75f, 1f)), Quaternion.identity, instance.elevatorTransform); GrabbableObject component = val.GetComponent<GrabbableObject>(); component.isInShipRoom = true; component.isInElevator = true; component.isInFactory = false; component.SetScrapValue(State.PendingSpentValue); val.GetComponent<NetworkObject>().Spawn(false); int pendingSpentValue = State.PendingSpentValue; State.PendingSpentValue = -1; FastBufferWriter val2 = default(FastBufferWriter); ((FastBufferWriter)(ref val2))..ctor(32, (Allocator)2, -1); try { ulong networkObjectId = ((NetworkBehaviour)component).NetworkObjectId; ((FastBufferWriter)(ref val2)).WriteValueSafe<ulong>(ref networkObjectId, default(ForPrimitives)); ((FastBufferWriter)(ref val2)).WriteValueSafe<int>(ref pendingSpentValue, default(ForPrimitives)); Vector3 localPosition = val.transform.localPosition; ((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref localPosition.x, default(ForPrimitives)); ((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref localPosition.y, default(ForPrimitives)); ((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref localPosition.z, default(ForPrimitives)); network.CustomMessagingManager.SendNamedMessageToAll("sockpoop.shipmaintenance.spent.v1", val2, (NetworkDelivery)3); } finally { ((IDisposable)(*(FastBufferWriter*)(&val2))/*cast due to .constrained prefix*/).Dispose(); } Broadcast(); } private static void OnSpent(ulong sender, FastBufferReader reader) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_007a: 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_009d: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)network == (Object)null) && !network.IsServer && sender == 0L && ((FastBufferReader)(ref reader)).TryBeginRead(24)) { ulong key = default(ulong); ((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref key, default(ForPrimitives)); int value = default(int); ((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref value, default(ForPrimitives)); float num = default(float); ((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref num, default(ForPrimitives)); float num2 = default(float); ((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref num2, default(ForPrimitives)); float num3 = default(float); ((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref num3, default(ForPrimitives)); pendingShells[key] = (MaintenanceRules.Clamp(value, 0, 1000000), new Vector3(num, num2, num3), Time.realtimeSinceStartup + 10f); } } private static void ApplySpentDeliveries() { //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)network == (Object)null || pendingShells.Count == 0) { return; } foreach (ulong item in new List<ulong>(pendingShells.Keys)) { (int, Vector3, float) tuple = pendingShells[item]; if (network.SpawnManager.SpawnedObjects.TryGetValue(item, out var value) && (Object)(object)value != (Object)null) { GrabbableObject component = ((Component)value).GetComponent<GrabbableObject>(); if ((Object)(object)component != (Object)null && (Object)(object)component.itemProperties == (Object)(object)ItemCatalog.Spent) { component.SetScrapValue(tuple.Item1); component.isInShipRoom = true; component.isInElevator = true; component.isInFactory = false; ((Component)component).transform.SetParent(StartOfRound.Instance.elevatorTransform, false); ((Component)component).transform.localPosition = tuple.Item2; component.startFallingPosition = tuple.Item2; component.FallToGround(false, false, default(Vector3)); } pendingShells.Remove(item); } else if (Time.realtimeSinceStartup > tuple.Item3) { Plugin.Log.LogWarning((object)("Timed out waiting for spent apparatus network object " + item)); pendingShells.Remove(item); } } } internal static int RoutePrice(int original) { return MaintenanceRules.Quote(original, State.Average, Discount, State.BoostReady, BoostDiscount); } internal static void RouteAccepted(int original) { if (IsHost && State.SpendBoost(original, Salvage)) { Broadcast(); } } internal unsafe static void Broadcast(ulong? target = null) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: 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_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_0105: 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_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) if (!IsHost) { return; } FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(512, (Allocator)2, -1); try { int[] array = State.Save(); for (int i = 0; i < array.Length; i++) { int num = array[i]; ((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives)); } array = new int[6] { Discount, Decay, OilPrice, FusePrice, BoostDiscount, Salvage }; for (int i = 0; i < array.Length; i++) { int num2 = array[i]; ((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num2, default(ForPrimitives)); } ((FastBufferWriter)(ref val)).WriteValueSafe<float>(ref Seconds, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref AllowOrbit, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<float>(ref NoiseRange, default(ForPrimitives)); Vector3[] positions = Positions; for (int i = 0; i < positions.Length; i++) { Vector3 val2 = positions[i]; ((FastBufferWriter)(ref val)).WriteValueSafe<float>(ref val2.x, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<float>(ref val2.y, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<float>(ref val2.z, default(ForPrimitives)); } ServiceJob[] jobs = Jobs; foreach (ServiceJob serviceJob in jobs) { ((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref serviceJob.Worker, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref serviceJob.Item, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<double>(ref serviceJob.Started, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<double>(ref serviceJob.ReadyAt, default(ForPrimitives)); } if (target.HasValue) { network.CustomMessagingManager.SendNamedMessage("sockpoop.shipmaintenance.state.v1", target.Value, val, (NetworkDelivery)3); } else { network.CustomMessagingManager.SendNamedMessageToAll("sockpoop.shipmaintenance.state.v1", val, (NetworkDelivery)3); } } finally { ((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose(); } UpdateHeldState(); } private static void OnState(ulong sender, FastBufferReader reader) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009c: 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_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: 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_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)network == (Object)null) && !network.IsServer && sender == 0L && ((FastBufferReader)(ref reader)).TryBeginRead(337)) { int[] array = new int[10]; for (int i = 0; i < array.Length; i++) { ((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref array[i], default(ForPrimitives)); } State = MaintenanceState.Load(array); ((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref Discount, default(ForPrimitives)); ((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref Decay, default(ForPrimitives)); ((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref OilPrice, default(ForPrimitives)); ((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref FusePrice, default(ForPrimitives)); ((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref BoostDiscount, default(ForPrimitives)); ((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref Salvage, default(ForPrimitives)); ((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref Seconds, default(ForPrimitives)); ((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref AllowOrbit, default(ForPrimitives)); ((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref NoiseRange, default(ForPrimitives)); float num = default(float); float num2 = default(float); float num3 = default(float); for (int j = 0; j < 6; j++) { ((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref num, default(ForPrimitives)); ((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref num2, default(ForPrimitives)); ((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref num3, default(ForPrimitives)); Positions[j] = new Vector3(num, num2, num3); } ServiceJob[] jobs = Jobs; foreach (ServiceJob serviceJob in jobs) { ((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref serviceJob.Worker, default(ForPrimitives)); ((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref serviceJob.Item, default(ForPrimitives)); ((FastBufferReader)(ref reader)).ReadValueSafe<double>(ref serviceJob.Started, default(ForPrimitives)); ((FastBufferReader)(ref reader)).ReadValueSafe<double>(ref serviceJob.ReadyAt, default(ForPrimitives)); } Ready = true; ItemCatalog.ApplyPrices(OilPrice, FusePrice); UpdateHeldState(); } } private static void UpdateHeldState() { if (held >= 0 && !((Object)(object)network == (Object)null)) { if (Jobs[held].Worker == network.LocalClientId) { confirmed = true; } else if (confirmed) { held = -1; confirmed = false; } } } internal static void Show(Notice notice) { string[] array = new string[11] { "Service complete.", "Hold a Maintenance oil can at the separate rear oil fill port.", "Hold a Maintenance fuse to service the roof panel.", "Hold a fresh, undocked apparatus. Spent units cannot be used.", "Land the ship before performing exterior maintenance.", "This system is already fully maintained.", "Someone is already servicing this panel, or you have another service in progress.", "Move closer to the service panel.", "The apparatus boost is already charged or being discharged.", "Service unavailable. Hold the required item and try again when the ship is stationary.", "The route price changed. Select the moon again to confirm the new fare." }; if ((int)notice < array.Length && (Object)(object)HUDManager.Instance != (Object)null) { HUDManager.Instance.DisplayTip("Ship Maintenance", array[(uint)notice], false, false, "LC_Tip1"); } } private unsafe static void Tell(ulong target, Notice notice) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)network == (Object)null) { return; } if (target == network.LocalClientId) { Show(notice); if (notice != Notice.Finished) { held = -1; confirmed = false; } return; } FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(1, (Allocator)2, -1); try { byte b = (byte)notice; ((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref b, default(ForPrimitives)); network.CustomMessagingManager.SendNamedMessage("sockpoop.shipmaintenance.notice.v1", target, val, (NetworkDelivery)3); } finally { ((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose(); } } private static void OnNotice(ulong sender, FastBufferReader reader) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) if (sender != 0L || !((FastBufferReader)(ref reader)).TryBeginRead(1)) { return; } byte b = default(byte); ((FastBufferReader)(ref reader)).ReadValueSafe<byte>(ref b, default(ForPrimitives)); if (b <= 10) { Show((Notice)b); if (b != 0) { held = -1; confirmed = false; } } } } [BepInPlugin("sockpoop.shipmaintenance", "Ship Maintenance", "1.0.1")] [BepInDependency("evaisa.lethallib", "1.2.0")] public sealed class Plugin : BaseUnityPlugin { public const string Guid = "sockpoop.shipmaintenance"; public const string Name = "Ship Maintenance"; public const string Version = "1.0.1"; internal static ManualLogSource Log = null; internal static ConfigEntry<int> MaxDiscount = null; internal static ConfigEntry<int> Wear = null; internal static ConfigEntry<int> OilCost = null; internal static ConfigEntry<int> FuseCost = null; internal static ConfigEntry<int> BoostDiscount = null; internal static ConfigEntry<int> SpentPercent = null; internal static ConfigEntry<float> ServiceSeconds = null; internal static ConfigEntry<float> NoiseRange = null; internal static ConfigEntry<float> SoundVolume = null; internal static ConfigEntry<bool> WorkInOrbit = null; internal static ConfigEntry<bool> HazardDamage = null; internal static ConfigEntry<int> LightningDamage = null; internal static ConfigEntry<int> ExplosionDamage = null; internal static readonly ConfigEntry<Vector3>[] Positions = new ConfigEntry<Vector3>[6]; private Harmony? harmony; private void Awake() { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Expected O, but got Unknown //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Expected O, but got Unknown //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Expected O, but got Unknown //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Expected O, but got Unknown //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Expected O, but got Unknown //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Expected O, but got Unknown //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Expected O, but got Unknown //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_0213: Expected O, but got Unknown //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_0266: Expected O, but got Unknown //IL_028f: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Expected O, but got Unknown //IL_02b5: Unknown result type (might be due to invalid IL or missing references) //IL_02ba: Unknown result type (might be due to invalid IL or missing references) //IL_02d0: Unknown result type (might be due to invalid IL or missing references) //IL_02d5: Unknown result type (might be due to invalid IL or missing references) //IL_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_0306: Unknown result type (might be due to invalid IL or missing references) //IL_030b: Unknown result type (might be due to invalid IL or missing references) //IL_0321: Unknown result type (might be due to invalid IL or missing references) //IL_0326: Unknown result type (might be due to invalid IL or missing references) //IL_033c: Unknown result type (might be due to invalid IL or missing references) //IL_0341: Unknown result type (might be due to invalid IL or missing references) //IL_0398: 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_03c5: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; MaxDiscount = ((BaseUnityPlugin)this).Config.Bind<int>("Economy", "MaximumMaintenanceDiscount", 25, new ConfigDescription("Host: percent off paid moon travel at 100% condition. Neglect never raises the original fare.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 75), Array.Empty<object>())); Wear = ((BaseUnityPlugin)this).Config.Bind<int>("Maintenance", "WearPerDay", 18, new ConfigDescription("Host: condition lost from each system after a completed timed moon visit. No wear in menus or orbit.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())); OilCost = ((BaseUnityPlugin)this).Config.Bind<int>("Supplies", "OilCanCost", 5, new ConfigDescription("Host: terminal price of one maintenance oil can. One can refills the separate rear oil port. Engine panels require no consumable.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>())); FuseCost = ((BaseUnityPlugin)this).Config.Bind<int>("Supplies", "FuseCost", 8, new ConfigDescription("Host: terminal price of one maintenance fuse. One fuse services the roof electrical panel.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>())); BoostDiscount = ((BaseUnityPlugin)this).Config.Bind<int>("Apparatus", "NextPaidTripDiscount", 80, new ConfigDescription("Host: additional percent off the next successful paid route after the maintenance discount. Free trips do not consume the apparatus.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 95), Array.Empty<object>())); SpentPercent = ((BaseUnityPlugin)this).Config.Bind<int>("Apparatus", "SpentSaleValuePercent", 25, new ConfigDescription("Host: spent apparatus value as a percentage of the inserted apparatus's actual scrap value. Spent units cannot be reused.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 90), Array.Empty<object>())); ServiceSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Maintenance", "ServiceSeconds", 8f, new ConfigDescription("Host: uninterrupted time holding E at a service panel. Loading the apparatus takes two seconds.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 30f), Array.Empty<object>())); WorkInOrbit = ((BaseUnityPlugin)this).Config.Bind<bool>("Maintenance", "AllowServiceInOrbit", false, "Host: allow regular service work in orbit. The apparatus socket always works in orbit. Exterior maintenance is normally performed while landed."); NoiseRange = ((BaseUnityPlugin)this).Config.Bind<float>("Maintenance", "WorkNoiseRange", 26f, new ConfigDescription("Host: noise radius during service. Eyeless Dogs can hear it. Local volume does not reduce enemy hearing.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 60f), Array.Empty<object>())); SoundVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "ServiceVolume", 0.7f, new ConfigDescription("Local maintenance sound volume. Does not change enemy hearing.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); HazardDamage = ((BaseUnityPlugin)this).Config.Bind<bool>("Damage", "EnableHazardDamage", true, "Host: lightning and nearby explosions damage the nearest serviceable component. Does not add a surcharge or damage the vanilla door controls."); LightningDamage = ((BaseUnityPlugin)this).Config.Bind<int>("Damage", "LightningConditionLoss", 35, new ConfigDescription("Host: condition lost by the component nearest a lightning impact on or near the ship.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())); ExplosionDamage = ((BaseUnityPlugin)this).Config.Bind<int>("Damage", "ExplosionConditionLoss", 25, new ConfigDescription("Host: condition lost near an explosion. Includes vanilla mines, Old Bird missiles, and other impacts using the game's explosion system. Damage falls with distance from the ship.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())); Vector3[] array = (Vector3[])(object)new Vector3[6] { new Vector3(7.4f, 1f, -10.65f), new Vector3(7.4f, 1f, -2.69f), new Vector3(-7.61f, 1.3f, -9.05f), new Vector3(0f, 5.98f, -6.6f), new Vector3(11.36f, 1.1f, -6.6f), new Vector3(-4.5f, 1.25f, -9.63f) }; string[] array2 = new string[6] { "LeftEngine", "RightEngine", "DoorMechanism", "RoofElectrical", "OilFillPort", "ApparatusSocket" }; for (int i = 0; i < 6; i++) { Positions[i] = ((BaseUnityPlugin)this).Config.Bind<Vector3>("Panel positions", array2[i], array[i], "Host: local position relative to the ship. Restart the lobby after changing. Useful for ship layout mods."); } ItemCatalog.Register(); harmony = new Harmony("sockpoop.shipmaintenance"); harmony.PatchAll(typeof(Plugin).Assembly); ((Component)this).gameObject.AddComponent<MaintenanceRuntime>(); Log.LogInfo((object)"Ship Maintenance 1.0.1 loaded. All players need this mod."); } private void OnDestroy() { Harmony? obj = harmony; if (obj != null) { obj.UnpatchSelf(); } } } internal sealed class RuntimeItem : MonoBehaviour { private void Awake() { ((Object)((Component)this).gameObject).hideFlags = (HideFlags)0; } } internal sealed class RouteQuote { internal TerminalNode Node; internal int Original; internal int Credits; internal int Level; internal bool Restored; } [HarmonyPatch(typeof(Terminal), "LoadNewNodeIfAffordable")] internal static class RouteQuotePatch { internal static readonly Stack<RouteQuote> Active = new Stack<RouteQuote>(); [HarmonyPrefix] [HarmonyPriority(0)] internal static void Prefix(Terminal __instance, TerminalNode node, out RouteQuote? __state) { __state = null; if (MaintenanceRuntime.Ready && !((Object)(object)node == (Object)null) && node.buyRerouteToMoon >= 0 && !((Object)(object)StartOfRound.Instance == (Object)null) && !StartOfRound.Instance.isChallengeFile) { __state = new RouteQuote { Node = node, Original = node.itemCost, Credits = __instance.groupCredits, Level = node.buyRerouteToMoon }; Active.Push(__state); node.itemCost = MaintenanceRuntime.RoutePrice(__state.Original); } } private static void Restore(RouteQuote? scope) { if (scope != null && !scope.Restored) { scope.Node.itemCost = scope.Original; scope.Restored = true; if (Active.Count > 0 && Active.Peek() == scope) { Active.Pop(); } } } [HarmonyPostfix] internal static void Postfix(RouteQuote? __state) { Restore(__state); } [HarmonyFinalizer] internal static Exception? Finalizer(Exception? __exception, RouteQuote? __state) { Restore(__state); return __exception; } } [HarmonyPatch(typeof(StartOfRound), "ChangeLevelServerRpc")] internal static class RoutePaymentPatch { private static readonly FieldInfo stage = AccessTools.Field(typeof(NetworkBehaviour), "__rpc_exec_stage"); [HarmonyPrefix] internal static bool Prefix(StartOfRound __instance, int levelID, int newGroupCreditsAmount, out int __state) { __state = -1; if (!MaintenanceRuntime.IsHost || stage.GetValue(__instance)?.ToString() != "Execute") { return true; } Terminal terminal = MaintenanceRuntime.Terminal; if ((Object)(object)terminal == (Object)null) { return true; } RouteQuote routeQuote = ((RouteQuotePatch.Active.Count > 0) ? RouteQuotePatch.Active.Peek() : null); int num; int num2; if (routeQuote != null) { num = ((routeQuote.Level == levelID) ? 1 : 0); if (num != 0) { num2 = routeQuote.Credits; goto IL_007b; } } else { num = 0; } num2 = terminal.groupCredits; goto IL_007b; IL_00e7: int num4; int num3 = num4; int num5; int num6; if (num5 == 0 || num6 < num3 || newGroupCreditsAmount != num6 - num3) { terminal.groupCredits = num6; __instance.CancelChangeLevelClientRpc(num6); MaintenanceRuntime.Broadcast(); return false; } int num7; __state = num7; return true; IL_007b: num6 = num2; num7 = ((num != 0) ? routeQuote.Original : BasePrice(levelID)); if (levelID >= 0 && levelID < __instance.levels.Length && levelID != __instance.currentLevelID && !__instance.travellingToNewLevel && __instance.inShipPhase && !__instance.beganLoadingNewLevel && !__instance.isChallengeFile && !RoundManager.Instance.dungeonIsGenerating) { num5 = ((num7 >= 0) ? 1 : 0); if (num5 != 0) { num4 = MaintenanceRuntime.RoutePrice(num7); goto IL_00e7; } } else { num5 = 0; } num4 = 0; goto IL_00e7; } [HarmonyPostfix] internal static void Postfix(StartOfRound __instance, int __state) { if (__state >= 0 && __instance.travellingToNewLevel) { MaintenanceRuntime.RouteAccepted(__state); } } private static int BasePrice(int level) { int num = -1; TerminalNode[] array = Resources.FindObjectsOfTypeAll<TerminalNode>(); foreach (TerminalNode val in array) { if (val.buyRerouteToMoon == level) { num = Math.Max(num, val.itemCost); } } return num; } } [HarmonyPatch(typeof(Terminal), "ParsePlayerSentence")] internal static class MaintenanceCommandPatch { [HarmonyPrefix] internal static bool Prefix(Terminal __instance, ref TerminalNode __result) { string text = __instance.screenText.text; int num = Math.Min(Math.Max(0, __instance.textAdded), text.Length); string text2 = text.Substring(text.Length - num).Trim().ToLowerInvariant(); if (text2 != "maintenance" && text2 != "maint") { return true; } TerminalNode val = ScriptableObject.CreateInstance<TerminalNode>(); val.clearPreviousText = true; if (!MaintenanceRuntime.Ready) { val.displayText = "Synchronizing ship maintenance. Try again in a moment.\n\n"; } else { MaintenanceState state = MaintenanceRuntime.State; string text3 = "SHIP MAINTENANCE\n\n"; for (int i = 0; i < 5; i++) { text3 = text3 + ServicePanel.Names[i] + ": " + state.Condition[i] + "%\n"; } text3 = text3 + "\nTravel discount: " + ((decimal)(state.Average * MaintenanceRuntime.Discount) / 100m).ToString("0.##") + "%\n"; text3 += (state.BoostReady ? "Apparatus: CHARGED for the next paid trip\n" : "Apparatus: empty\n"); text3 = text3 + "\nHold E at a service panel while landed.\nEngine repair panels and door: no consumable.\nSeparate rear oil fill: one Maintenance oil ($" + MaintenanceRuntime.OilPrice + ").\nRoof electrical: one Maintenance fuse ($" + MaintenanceRuntime.FusePrice + ").\n\nSupplies arrive in the normal item dropship.\nLoad a fresh apparatus into the interior socket for " + MaintenanceRuntime.BoostDiscount + "% off one paid trip after maintenance savings. Its spent shell returns at reduced scrap value.\n\nWork makes noise. Lightning and nearby blasts damage components. Neglect never adds a travel surcharge.\n\n"; val.displayText = text3; } __result = val; return false; } } [HarmonyPatch(typeof(GameNetworkManager), "SaveItemsInShip")] internal static class MaintenanceSavePatch { [HarmonyPostfix] internal static void Postfix() { MaintenanceRuntime.SaveHost(); } } [HarmonyPatch(typeof(GameNetworkManager), "ResetSavedGameValues")] internal static class MaintenanceResetPatch { [HarmonyPostfix] internal static void Postfix() { MaintenanceRuntime.ResetHost(); } } [HarmonyPatch(typeof(StartOfRound), "ResetShipFurniture")] internal static class MaintenanceChallengeResetPatch { [HarmonyPostfix] internal static void Postfix(StartOfRound __instance) { if (__instance.isChallengeFile) { MaintenanceRuntime.ResetHost(); } } } internal static class Visuals { internal static Material Paint(string name, Color color) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) Material val = new Material(Shader.Find("HDRP/Lit") ?? Shader.Find("Standard") ?? Shader.Find("Unlit/Color")) { name = name }; if (val.HasProperty("_BaseColor")) { val.SetColor("_BaseColor", color); } if (val.HasProperty("_Color")) { val.SetColor("_Color", color); } if (val.HasProperty("_Smoothness")) { val.SetFloat("_Smoothness", 0.25f); } return val; } internal static GameObject Part(Transform parent, string name, Vector3 position, Vector3 scale, Material material, PrimitiveType shape = (PrimitiveType)3) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) GameObject obj = GameObject.CreatePrimitive(shape); ((Object)obj).name = name; obj.transform.SetParent(parent, false); obj.transform.localPosition = position; obj.transform.localScale = scale; obj.GetComponent<Renderer>().sharedMaterial = material; Collider component = obj.GetComponent<Collider>(); component.enabled = false; Object.Destroy((Object)(object)component); return obj; } internal static TextMeshPro Label(Transform parent, string text, Vector3 position, Vector2 size, float fontSize) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_007f: 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) GameObject val = new GameObject("Service label"); val.transform.SetParent(parent, false); val.transform.localPosition = position; TextMeshPro val2 = val.AddComponent<TextMeshPro>(); ((TMP_Text)val2).text = text; if ((Object)(object)HUDManager.Instance != (Object)null) { ((TMP_Text)val2).font = ((TMP_Text)HUDManager.Instance.controlTipLines[0]).font; } ((TMP_Text)val2).fontSize = fontSize; ((TMP_Text)val2).enableAutoSizing = true; ((TMP_Text)val2).fontSizeMin = fontSize * 0.5f; ((TMP_Text)val2).fontSizeMax = fontSize; ((TMP_Text)val2).rectTransform.sizeDelta = size; ((TMP_Text)val2).alignment = (TextAlignmentOptions)514; ((TMP_Text)val2).enableWordWrapping = true; ((Graphic)val2).color = new Color(0.92f, 0.92f, 0.78f); return val2; } internal static AudioClip WorkClip(int kind) { float[] array = new float[48000]; uint num = (uint)(731 + kind); float num2 = 0f; for (int i = 0; i < array.Length; i++) { num = num * 1664525 + 1013904223; float num3 = (float)(num >> 8) / 8388608f - 1f; num2 += 0.15f * (num3 - num2); double num4 = (double)i / 24000.0; float num5 = (float)(Math.Exp((0.0 - num4 % ((kind == 2) ? 0.25 : 0.4)) * 55.0) * Math.Sin(num4 * 2.0 * Math.PI * (double)((kind == 3) ? 620 : 210))); float num6 = Math.Min(1f, (float)Math.Min(i, array.Length - 1 - i) / 150f); array[i] = (num2 * ((kind == 3) ? 0.8f : 0.5f) + num5 * 0.35f) * num6; } AudioClip obj = AudioClip.Create("Maintenance mechanical service " + kind, array.Length, 1, 24000, false); obj.SetData(array, 0); return obj; } internal static AudioClip HandlingClip() { float[] array = new float[2400]; for (int i = 0; i < array.Length; i++) { double num = (double)i / 24000.0; array[i] = (float)(0.12 * Math.Sin(Math.PI * 360.0 * num) * Math.Exp((0.0 - num) * 65.0) * Math.Min(1.0, (double)i / 30.0)); } AudioClip obj = AudioClip.Create("Maintenance supply handling", array.Length, 1, 24000, false); obj.SetData(array, 0); return obj; } } internal sealed class ServicePanel : MonoBehaviour { internal int Index; internal InteractTrigger Trigger; private TextMeshPro label; private AudioSource audioSource; internal static readonly string[] Names = new string[6] { "LEFT ENGINE", "RIGHT ENGINE", "DOOR MECHANISM", "ROOF ELECTRICAL", "OIL FILL PORT", "APPARATUS BOOST" }; internal static ServicePanel Create(int index, Transform ship, Vector3 position) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown //IL_003c: 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_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_0235: Unknown result type (might be due to invalid IL or missing references) //IL_0268: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_02a1: Unknown result type (might be due to invalid IL or missing references) //IL_02c1: Unknown result type (might be due to invalid IL or missing references) //IL_0344: Unknown result type (might be due to invalid IL or missing references) //IL_0349: Unknown result type (might be due to invalid IL or missing references) //IL_035b: Unknown result type (might be due to invalid IL or missing references) //IL_0363: Unknown result type (might be due to invalid IL or missing references) //IL_036e: Unknown result type (might be due to invalid IL or missing references) //IL_0384: Unknown result type (might be due to invalid IL or missing references) //IL_039d: Unknown result type (might be due to invalid IL or missing references) //IL_03d8: Unknown result type (might be due to invalid IL or missing references) //IL_03e2: Expected O, but got Unknown //IL_03e4: Unknown result type (might be due to invalid IL or missing references) //IL_03ee: Expected O, but got Unknown //IL_03f0: Unknown result type (might be due to invalid IL or missing references) //IL_03fa: Expected O, but got Unknown //IL_03fc: Unknown result type (might be due to invalid IL or missing references) //IL_0406: Expected O, but got Unknown //IL_0408: Unknown result type (might be due to invalid IL or missing references) //IL_0412: Expected O, but got Unknown //IL_0414: Unknown result type (might be due to invalid IL or missing references) //IL_041e: Expected O, but got Unknown //IL_04a5: Unknown result type (might be due to invalid IL or missing references) //IL_04b4: Unknown result type (might be due to invalid IL or missing references) //IL_02fd: 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) GameObject val = new GameObject("Ship Maintenance " + Names[index]); val.transform.SetParent(ship, false); val.transform.localPosition = position; val.transform.localEulerAngles = (Vector3)((index == 1 || index == 5) ? new Vector3(0f, 180f, 0f) : ((index == 2) ? new Vector3(0f, 90f, 0f) : ((index == 3) ? new Vector3(90f, 0f, 0f) : ((index == 4) ? new Vector3(0f, -90f, 0f) : Vector3.zero)))); Material material = Visuals.Paint("Service dark steel", new Color(0.16f, 0.2f, 0.18f)); Material material2 = Visuals.Paint("Service yellow", new Color(0.8f, 0.57f, 0.12f)); Material material3 = Visuals.Paint("Service black", new Color(0.025f, 0.03f, 0.025f)); Visuals.Part(val.transform, "Housing", Vector3.zero, new Vector3(0.78f, 0.65f, 0.12f), material, (PrimitiveType)3); Visuals.Part(val.transform, "Warning stripe", new Vector3(0f, 0.25f, -0.068f), new Vector3(0.7f, 0.07f, 0.018f), material2, (PrimitiveType)3); for (int i = -1; i <= 1; i += 2) { for (int j = -1; j <= 1; j += 2) { Visuals.Part(val.transform, "Panel bolt", new Vector3((float)i * 0.34f, (float)j * 0.25f, -0.075f), Vector3.one * 0.045f, material3, (PrimitiveType)0); } } GameObject val2 = Visuals.Part(val.transform, (index == 4) ? "Oil filler cap" : ((index == 5) ? "Apparatus connector" : "Repair panel latch"), new Vector3(0f, -0.13f, -0.11f), (index == 5) ? new Vector3(0.3f, 0.2f, 0.13f) : new Vector3(0.17f, 0.17f, 0.07f), material2, (PrimitiveType)((index == 4) ? 2 : 3)); if (index == 4) { val2.transform.localEulerAngles = new Vector3(90f, 0f, 0f); val2.transform.localScale = new Vector3(0.19f, 0.035f, 0.19f); } if (index < 2) { for (int k = 0; k < 3; k++) { Visuals.Part(val.transform, "Engine panel vent", new Vector3(-0.2f + (float)k * 0.2f, -0.22f, -0.069f), new Vector3(0.12f, 0.025f, 0.015f), material3, (PrimitiveType)3); } } val2.layer = 9; val2.tag = "InteractTrigger"; GameObject val3 = new GameObject("Service interaction"); val3.transform.SetParent(val.transform, false); val3.layer = 9; val3.tag = "InteractTrigger"; BoxCollider obj = val3.AddComponent<BoxCollider>(); obj.size = new Vector3(0.78f, 0.65f, 0.2f); obj.center = new Vector3(0f, 0f, -0.04f); InteractTrigger val4 = val3.AddComponent<InteractTrigger>(); val4.disableTriggerMesh = false; val4.interactCooldown = false; val4.holdInteraction = false; val4.oneHandedItemAllowed = true; val4.twoHandedItemAllowed = true; val4.onInteract = new InteractEvent(); val4.onInteractEarly = new InteractEvent(); val4.onInteractEarlyOtherClients = new InteractEvent(); val4.onStopInteract = new InteractEvent(); val4.onCancelAnimation = new InteractEvent(); val4.holdingInteractEvent = new InteractEventFloat(); InteractTrigger[] array = Object.FindObjectsOfType<InteractTrigger>(); foreach (InteractTrigger val5 in array) { if ((Object)(object)val5 != (Object)(object)val4 && (Object)(object)val5.hoverIcon != (Object)null) { val4.hoverIcon = val5.hoverIcon; break; } } ServicePanel servicePanel = val.AddComponent<ServicePanel>(); servicePanel.Index = index; servicePanel.Trigger = val4; servicePanel.label = Visuals.Label(val.transform, Names[index], new Vector3(0f, 0.06f, -0.075f), new Vector2(0.61f, 0.25f), 0.8f); servicePanel.audioSource = val.AddComponent<AudioSource>(); servicePanel.audioSource.playOnAwake = false; servicePanel.audioSource.loop = true; servicePanel.audioSource.spatialBlend = 1f; servicePanel.audioSource.minDistance = 2f; servicePanel.audioSource.maxDistance = 30f; servicePanel.audioSource.dopplerLevel = 0f; servicePanel.audioSource.clip = Visuals.WorkClip(index); ((UnityEvent<PlayerControllerB>)(object)val4.onInteract).AddListener((UnityAction<PlayerControllerB>)delegate(PlayerControllerB player) { if ((Object)(object)player == (Object)(object)GameNetworkManager.Instance?.localPlayerController) { MaintenanceRuntime.BeginLocal(index); } }); return servicePanel; } private void Update() { ServiceJob serviceJob = MaintenanceRuntime.Jobs[Index]; bool active = serviceJob.Active; string text = ((Index != 5) ? (MaintenanceRuntime.State.Condition[Index] + "%") : (MaintenanceRuntime.State.BoostReady ? "CHARGED" : ((MaintenanceRuntime.State.PendingSpentValue >= 0) ? "DISCHARGING" : "INSERT APPARATUS"))); if (active) { text = Math.Min(100, (int)(100.0 * (MaintenanceRuntime.Clock - serviceJob.Started) / Math.Max(1.0, serviceJob.ReadyAt - serviceJob.Started))) + "% SERVICING"; } ((TMP_Text)label).text = Names[Index] + "\n" + text; string text2 = ((Index == 4) ? "refill with oil can" : ((Index == 3) ? "replace fuse" : ((Index == 5) ? "load fresh apparatus" : "repair panel"))); Trigger.hoverTip = (active ? "Servicing - keep holding [E]" : ("Hold [E] - " + text2)); Trigger.interactable = MaintenanceRuntime.Ready && ((Index != 5) ? (MaintenanceRuntime.State.Condition[Index] < 100) : (!MaintenanceRuntime.State.BoostReady && MaintenanceRuntime.State.PendingSpentValue < 0)); Trigger.disabledHoverTip = ((!MaintenanceRuntime.Ready) ? "Synchronizing maintenance" : ((Index == 5) ? "Charged or discharging" : "Fully maintained")); audioSource.volume = Plugin.SoundVolume.Value; if (active && !audioSource.isPlaying) { audioSource.Play(); } else if (!active && audioSource.isPlaying) { audioSource.Stop(); } } } }