using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Logging; using HarmonyLib; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; using crecheng.DSPModSave; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = "")] [assembly: AssemblyVersion("0.0.0.0")] namespace LocalPriorityPairing; internal enum DispatchReason { Local, LocalPointToPoint, Remote, RemotePointToPoint, PlanetRoute, StarRoute, Group, RemoteFallback } internal struct DispatchRecord { internal long tick; internal int sourcePlanetId; internal int sourceStationId; internal int demandPlanetId; internal int demandStationId; internal int itemId; internal int itemCount; internal bool vessel; internal DispatchReason reason; } internal static class DispatchLog { private const int Capacity = 512; private static readonly DispatchRecord[] records = new DispatchRecord[512]; private static int next; private static int count; internal static void Clear() { next = 0; count = 0; } internal static void CaptureLocal(PlanetFactory factory, StationComponent dispatcher, StationComponent[] stationPool, int firstNewDrone) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003e: 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_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) if (factory == null || dispatcher == null || stationPool == null || firstNewDrone < 0) { return; } int num = dispatcher.workDroneCount; if (num > dispatcher.workDroneDatas.Length) { num = dispatcher.workDroneDatas.Length; } for (int i = firstNewDrone; i < num; i++) { DroneData val = dispatcher.workDroneDatas[i]; StationComponent val2 = StationAt(stationPool, val.endId); if (val2 != null && val.itemId > 0) { LocalLogisticOrder val3 = dispatcher.workDroneOrders[i]; bool num2 = val.itemCount > 0; StationComponent val4 = (num2 ? dispatcher : val2); StationComponent val5 = (num2 ? val2 : dispatcher); int itemCount = ((val.itemCount > 0) ? val.itemCount : Math.Max(Math.Abs(val3.thisOrdered), Math.Abs(val3.otherOrdered))); Add(new DispatchRecord { tick = GameMain.gameTick, sourcePlanetId = factory.planetId, sourceStationId = val4.id, demandPlanetId = factory.planetId, demandStationId = val5.id, itemId = val.itemId, itemCount = itemCount, vessel = false, reason = (LocalPairStore.Contains(factory.planetId, val4.id, val5.id) ? DispatchReason.LocalPointToPoint : DispatchReason.Local) }); } } } internal static void CaptureRemote(StationComponent dispatcher, StationComponent[] stationPool, int firstNewShip, int priorityIndex) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0067: 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_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0096: 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 (dispatcher == null || stationPool == null || firstNewShip < 0) { return; } int num = dispatcher.workShipCount; if (num > dispatcher.workShipDatas.Length) { num = dispatcher.workShipDatas.Length; } for (int i = firstNewShip; i < num; i++) { ShipData val = dispatcher.workShipDatas[i]; StationComponent val2 = StationAt(stationPool, val.otherGId); if (val2 != null && val.itemId > 0) { RemoteLogisticOrder val3 = dispatcher.workShipOrders[i]; bool num2 = val.itemCount > 0; StationComponent val4 = (num2 ? dispatcher : val2); StationComponent val5 = (num2 ? val2 : dispatcher); int itemCount = ((val.itemCount > 0) ? val.itemCount : Math.Max(Math.Abs(val3.thisOrdered), Math.Abs(val3.otherOrdered))); Add(new DispatchRecord { tick = GameMain.gameTick, sourcePlanetId = val4.planetId, sourceStationId = val4.id, demandPlanetId = val5.planetId, demandStationId = val5.id, itemId = val.itemId, itemCount = itemCount, vessel = true, reason = RemoteReason(priorityIndex) }); } } } internal static void AppendForStation(StringBuilder builder, int planetId, int stationId, int maximum) { int num = 0; for (int i = 0; i < count; i++) { if (num >= maximum) { break; } int num2 = next - 1 - i; if (num2 < 0) { num2 += 512; } DispatchRecord record = records[num2]; if (Involves(record, planetId, stationId)) { builder.Append(FormatTime(record.tick)).Append(" "); builder.Append(record.vessel ? "Vessel" : "Drone ").Append(" "); builder.Append(ReasonLabel(record.reason)).Append(" "); builder.Append(StationName(record.sourcePlanetId, record.sourceStationId)); builder.Append(" -> "); builder.Append(StationName(record.demandPlanetId, record.demandStationId)); builder.Append(" | "); ItemProto val = ((ProtoSet)(object)LDB.items).Select(record.itemId); builder.Append((val == null) ? record.itemId.ToString() : ((Proto)val).name); builder.Append(" x").Append(record.itemCount).AppendLine(); num++; } } if (num == 0) { builder.Append("No dispatches recorded for this station yet."); } } private static void Add(DispatchRecord record) { records[next] = record; next = (next + 1) % 512; if (count < 512) { count++; } } private static bool Involves(DispatchRecord record, int planetId, int stationId) { if (record.sourcePlanetId != planetId || record.sourceStationId != stationId) { if (record.demandPlanetId == planetId) { return record.demandStationId == stationId; } return false; } return true; } private static StationComponent StationAt(StationComponent[] pool, int id) { if (id <= 0 || id >= pool.Length) { return null; } StationComponent val = pool[id]; if (val == null || val.id <= 0) { return null; } return val; } private static DispatchReason RemoteReason(int priorityIndex) { return priorityIndex switch { 1 => DispatchReason.RemotePointToPoint, 2 => DispatchReason.PlanetRoute, 3 => DispatchReason.StarRoute, 4 => DispatchReason.Group, 5 => DispatchReason.RemoteFallback, _ => DispatchReason.Remote, }; } private static string ReasonLabel(DispatchReason reason) { return reason switch { DispatchReason.LocalPointToPoint => "Local P2P", DispatchReason.RemotePointToPoint => "Remote P2P", DispatchReason.PlanetRoute => "Planet route", DispatchReason.StarRoute => "Star route", DispatchReason.Group => "Group", DispatchReason.RemoteFallback => "Remote fallback", DispatchReason.Remote => "Remote", _ => "Local", }; } private static string StationName(int planetId, int stationId) { GameData data = GameMain.data; PlanetFactory val = ((data == null || data.galaxy == null) ? null : data.galaxy.PlanetById(planetId))?.factory; if (val != null && stationId > 0 && stationId < val.transport.stationCursor) { StationComponent val2 = val.transport.stationPool[stationId]; if (val2 != null && val2.id == stationId) { string text = val.ReadExtraInfoOnEntity(val2.entityId); if (!string.IsNullOrEmpty(text)) { return text; } return (val2.isStellar ? "ILS " : "PLS ") + planetId + "-" + stationId; } } return "Station " + planetId + "-" + stationId; } private static string FormatTime(long tick) { long num = tick / 60; long num2 = num / 3600; num %= 3600; long num3 = num / 60; num %= 60; return num2.ToString("00") + ":" + num3.ToString("00") + ":" + num.ToString("00"); } } internal sealed class DispatchLogPanel : MonoBehaviour { private UIStationWindow window; private GameObject panel; private RectTransform panelRect; private GameObject buttonObject; private RectTransform buttonRect; private RectTransform controlButtonRect; private Text buttonText; private Text content; private readonly StringBuilder builder = new StringBuilder(4096); private int lastRefreshFrame = -100; internal void Initialize(UIStationWindow owner) { //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) //IL_0069: 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_00eb: 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_0110: Expected O, but got Unknown //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Unknown result type (might be due to invalid IL or missing references) window = owner; Font font = owner.titleText.font; controlButtonRect = owner.controlPanelBtnRt; buttonObject = CreateBox("Dispatch Log Button", ((Transform)controlButtonRect).parent, new Color(0.08f, 0.18f, 0.25f, 0.96f)); buttonRect = (RectTransform)buttonObject.transform; PositionButton(); Button obj = buttonObject.AddComponent