Decompiled source of RouteOptimizer v1.0.0
RouteOptimizer.dll
Decompiled a day ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; 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 = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("RouteOptimizer")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+ba3d5484bdb3e38c62ce6d8d38d9b0111b0ac083")] [assembly: AssemblyProduct("RouteOptimizer")] [assembly: AssemblyTitle("RouteOptimizer")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace RouteOptimizer { public static class Api { public static void ToggleWindow() { if (IlsCensus.Enabled) { IlsWindow.Toggle(); } } } internal static class DashboardAlarmsLink { private const string Guid = "buffylvr.dsp.dashboardalarms"; private static bool looked; private static Type api; private static Func<int> alarmCount; private static Func<float> bannerBottom; private static Func<Vector2, float, Vector2> drawRows; private static Func<byte[]> takeLegacy; public static bool Present { get { Find(); if (drawRows != null) { return alarmCount != null; } return false; } } public static int AlarmCount => Call(alarmCount, 0); public static float BannerBottomPixels => Call(bannerBottom, 0f); public static byte[] TakeLegacyIlsData() { return Call(takeLegacy, null); } public static Vector2 DrawAlarmRows(Vector2 scroll, float height) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0040: 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_0044: Unknown result type (might be due to invalid IL or missing references) if (!Present) { return scroll; } try { return drawRows(scroll, height); } catch (Exception ex) { ManualLogSource log = Plugin.Log; if (log != null) { log.LogWarning((object)("Dashboard Alarms link: " + ex.Message)); } drawRows = null; return scroll; } } private static T Call<T>(Func<T> f, T fallback) { Find(); if (f == null) { return fallback; } try { return f(); } catch (Exception ex) { ManualLogSource log = Plugin.Log; if (log != null) { log.LogWarning((object)("Dashboard Alarms link: " + ex.Message)); } return fallback; } } private static void Find() { if (looked) { return; } looked = true; try { if (!Chainloader.PluginInfos.TryGetValue("buffylvr.dsp.dashboardalarms", out var value) || (Object)(object)value.Instance == (Object)null) { return; } api = ((object)value.Instance).GetType().Assembly.GetType("DashboardAlarms.Api"); if (!(api == null)) { alarmCount = Getter<int>("AlarmCount"); bannerBottom = Getter<float>("BannerBottomPixels"); MethodInfo method = api.GetMethod("DrawAlarmRows", BindingFlags.Static | BindingFlags.Public, null, new Type[2] { typeof(Vector2), typeof(float) }, null); if (method != null) { drawRows = (Func<Vector2, float, Vector2>)Delegate.CreateDelegate(typeof(Func<Vector2, float, Vector2>), method); } MethodInfo method2 = api.GetMethod("TakeLegacyIlsData", BindingFlags.Static | BindingFlags.Public, null, Type.EmptyTypes, null); if (method2 != null) { takeLegacy = (Func<byte[]>)Delegate.CreateDelegate(typeof(Func<byte[]>), method2); } } } catch (Exception ex) { ManualLogSource log = Plugin.Log; if (log != null) { log.LogWarning((object)("Dashboard Alarms link: " + ex.Message)); } } } private static Func<T> Getter<T>(string property) { MethodInfo methodInfo = api.GetProperty(property, BindingFlags.Static | BindingFlags.Public)?.GetGetMethod(); if (!(methodInfo == null)) { return (Func<T>)Delegate.CreateDelegate(typeof(Func<T>), methodInfo); } return null; } } internal static class GameSkin { public static readonly Color Text = new Color(0.86f, 0.92f, 0.96f, 1f); public static readonly Color TextDim = new Color(0.62f, 0.7f, 0.76f, 1f); public static readonly Color Accent = new Color(0.38f, 0.84f, 1f, 1f); private static readonly Color Panel = new Color(0.06f, 0.11f, 0.16f, 0.94f); private static readonly Color TitleBand = new Color(0.11f, 0.19f, 0.26f, 0.97f); private static readonly Color Edge = new Color(0.38f, 0.84f, 1f, 0.35f); private static readonly Color ButtonFill = new Color(0.16f, 0.25f, 0.33f, 0.95f); private static readonly Color ButtonHover = new Color(0.22f, 0.35f, 0.45f, 0.98f); private static readonly Color ButtonPressed = new Color(0.12f, 0.42f, 0.56f, 1f); private static readonly Color SelectedFill = new Color(0.14f, 0.5f, 0.68f, 1f); private static readonly Color FieldFill = new Color(0.03f, 0.07f, 0.1f, 0.95f); private static readonly Color FieldEdge = new Color(0.3f, 0.4f, 0.48f, 1f); private static GUISkin skin; private static readonly List<Texture2D> textures = new List<Texture2D>(); private static GUIStyle bannerBox; private static GUIStyle bannerLine; private static GUIStyle bannerTitle; private static GUIStyle bannerSnoozed; private static GUISkin bannerBoxSkin; private static bool builtZh; public static GUIStyle SelectedButton { get; private set; } public static GUIStyle Check { get; private set; } public static GUIStyle DimLabel { get; private set; } public static GUIStyle Header { get; private set; } public static Texture2D CheckOn { get; private set; } public static Texture2D CheckOff { get; private set; } public static Texture2D BannerFill { get; private set; } public static Font GameFont { get; private set; } public static GUISkin Skin { get { if ((Object)(object)skin == (Object)null || builtZh != L.Zh) { Build(); } return skin; } } public static GUIStyle BannerLine { get { EnsureBannerStyles(); return bannerLine; } } public static GUIStyle BannerTitle { get { EnsureBannerStyles(); return bannerTitle; } } public static GUIStyle BannerSnoozed { get { EnsureBannerStyles(); return bannerSnoozed; } } private static void Build() { //IL_007b: 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_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Expected O, but got Unknown //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Expected O, but got Unknown //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_017c: 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_0188: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Expected O, but got Unknown //IL_019f: 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_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Expected O, but got Unknown //IL_01db: Expected O, but got Unknown //IL_01e5: 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_0205: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_0257: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_02c9: Unknown result type (might be due to invalid IL or missing references) //IL_02d9: Unknown result type (might be due to invalid IL or missing references) //IL_02e9: Unknown result type (might be due to invalid IL or missing references) //IL_02f9: Unknown result type (might be due to invalid IL or missing references) //IL_0309: Unknown result type (might be due to invalid IL or missing references) //IL_0319: Unknown result type (might be due to invalid IL or missing references) //IL_0329: Unknown result type (might be due to invalid IL or missing references) //IL_0338: Unknown result type (might be due to invalid IL or missing references) //IL_0342: Expected O, but got Unknown //IL_0349: Unknown result type (might be due to invalid IL or missing references) //IL_0353: Expected O, but got Unknown //IL_0363: 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_0374: Expected O, but got Unknown //IL_0374: Unknown result type (might be due to invalid IL or missing references) //IL_0379: Unknown result type (might be due to invalid IL or missing references) //IL_03b2: Unknown result type (might be due to invalid IL or missing references) //IL_03b7: Unknown result type (might be due to invalid IL or missing references) //IL_03e0: Unknown result type (might be due to invalid IL or missing references) //IL_03f4: Unknown result type (might be due to invalid IL or missing references) //IL_0409: Unknown result type (might be due to invalid IL or missing references) //IL_040e: Unknown result type (might be due to invalid IL or missing references) //IL_042d: Unknown result type (might be due to invalid IL or missing references) //IL_0455: Unknown result type (might be due to invalid IL or missing references) //IL_046a: Unknown result type (might be due to invalid IL or missing references) //IL_046f: Unknown result type (might be due to invalid IL or missing references) //IL_04a7: Unknown result type (might be due to invalid IL or missing references) //IL_04b7: 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_04d6: Unknown result type (might be due to invalid IL or missing references) //IL_04e0: Expected O, but got Unknown //IL_04e5: Unknown result type (might be due to invalid IL or missing references) //IL_04ef: Expected O, but got Unknown //IL_04f7: Unknown result type (might be due to invalid IL or missing references) //IL_0510: Unknown result type (might be due to invalid IL or missing references) //IL_052e: Unknown result type (might be due to invalid IL or missing references) //IL_0546: Unknown result type (might be due to invalid IL or missing references) //IL_0550: Expected O, but got Unknown //IL_05b4: Unknown result type (might be due to invalid IL or missing references) //IL_05b9: Unknown result type (might be due to invalid IL or missing references) //IL_05c0: Unknown result type (might be due to invalid IL or missing references) //IL_05c7: Unknown result type (might be due to invalid IL or missing references) //IL_05cc: Unknown result type (might be due to invalid IL or missing references) //IL_05d6: Expected O, but got Unknown //IL_05db: Expected O, but got Unknown //IL_05e5: Unknown result type (might be due to invalid IL or missing references) //IL_064b: Unknown result type (might be due to invalid IL or missing references) //IL_0655: Expected O, but got Unknown //IL_0664: Unknown result type (might be due to invalid IL or missing references) //IL_0669: Unknown result type (might be due to invalid IL or missing references) //IL_069a: Unknown result type (might be due to invalid IL or missing references) //IL_06a4: Expected O, but got Unknown skin = Object.Instantiate<GUISkin>(GUI.skin); ((Object)skin).hideFlags = (HideFlags)61; builtZh = L.Zh; GameFont = FindGameFont(); if (builtZh && !CanDrawChinese(GameFont)) { GameFont = ChineseOsFont() ?? GameFont; } if ((Object)(object)GameFont != (Object)null) { skin.font = GameFont; } skin.settings.cursorColor = Accent; skin.settings.selectionColor = new Color(Accent.r, Accent.g, Accent.b, 0.35f); GUIStyle window = skin.window; Texture2D tex = Make(16, 40, delegate(int x, int top, int w, int h) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) if (x == 0 || x == w - 1 || top == 0 || top == h - 1) { return Edge; } if (top < 26) { return TitleBand; } return (Color)((top == 26) ? new Color(Accent.r, Accent.g, Accent.b, 0.7f) : Panel); }); SetAll(window, tex, Accent); window.border = new RectOffset(2, 2, 28, 2); window.padding = new RectOffset(12, 12, 36, 12); window.contentOffset = new Vector2(0f, -30f); window.alignment = (TextAnchor)1; window.fontSize = 15; window.fontStyle = (FontStyle)1; skin.label.normal.textColor = Text; skin.label.fontSize = 14; DimLabel = new GUIStyle(skin.label) { wordWrap = true, fontSize = 13 }; DimLabel.normal.textColor = TextDim; Header = new GUIStyle(skin.label) { fontStyle = (FontStyle)1, fontSize = 14, margin = new RectOffset(4, 4, 6, 2) }; Header.normal.textColor = Accent; GUIStyle button = skin.button; button.normal.background = Boxed(ButtonFill, Edge); button.hover.background = Boxed(ButtonHover, new Color(Accent.r, Accent.g, Accent.b, 0.7f)); button.active.background = Boxed(ButtonPressed, Accent); button.focused.background = button.normal.background; button.onNormal.background = button.normal.background; button.onHover.background = button.hover.background; button.onActive.background = button.active.background; button.normal.textColor = Text; button.hover.textColor = Color.white; button.active.textColor = Color.white; button.focused.textColor = Text; button.onNormal.textColor = Text; button.onHover.textColor = Color.white; button.onActive.textColor = Color.white; button.border = new RectOffset(2, 2, 2, 2); button.padding = new RectOffset(10, 10, 5, 5); button.fontSize = 14; button.alignment = (TextAnchor)4; SelectedButton = new GUIStyle(button) { fontStyle = (FontStyle)1 }; Texture2D background = Boxed(SelectedFill, Accent); SelectedButton.normal.background = background; SelectedButton.hover.background = Boxed(new Color(0.18f, 0.58f, 0.78f, 1f), Accent); SelectedButton.active.background = background; SelectedButton.normal.textColor = Color.white; SelectedButton.hover.textColor = Color.white; GUIStyle textField = skin.textField; Texture2D background2 = Boxed(FieldFill, FieldEdge); textField.normal.background = background2; textField.hover.background = Boxed(FieldFill, new Color(Accent.r, Accent.g, Accent.b, 0.6f)); textField.focused.background = Boxed(FieldFill, Accent); textField.active.background = textField.focused.background; textField.onNormal.background = background2; textField.normal.textColor = Text; textField.hover.textColor = Text; textField.focused.textColor = Color.white; textField.border = new RectOffset(2, 2, 2, 2); textField.padding = new RectOffset(6, 6, 4, 4); textField.fontSize = 14; BannerFill = Boxed(Color.white, new Color(1f, 0.55f, 0.5f, 1f)); SetAll(skin.box, BannerFill, Text); skin.box.border = new RectOffset(2, 2, 2, 2); CheckOff = Make(16, 16, (int x, int top, int w, int h) => (!Edge1(x, top, w, h)) ? FieldFill : Accent); CheckOn = Make(16, 16, (int x, int top, int w, int h) => (!Edge1(x, top, w, h)) ? ((x < 4 || x > 11 || top < 4 || top > 11) ? FieldFill : Accent) : Accent); Check = new GUIStyle(skin.label) { imagePosition = (ImagePosition)0, alignment = (TextAnchor)3, padding = new RectOffset(0, 4, 3, 3) }; Check.hover.textColor = Color.white; skin.verticalScrollbar.normal.background = Make(4, 4, (int x, int top, int w, int h) => FieldFill); skin.verticalScrollbar.fixedWidth = 10f; skin.verticalScrollbar.border = new RectOffset(0, 0, 0, 0); skin.verticalScrollbarThumb.normal.background = Boxed(ButtonHover, Edge); skin.verticalScrollbarThumb.fixedWidth = 10f; skin.verticalScrollbarThumb.border = new RectOffset(2, 2, 2, 2); skin.verticalScrollbarUpButton.fixedHeight = 0f; skin.verticalScrollbarDownButton.fixedHeight = 0f; skin.scrollView.normal.background = null; } public static bool Toggle(bool value, string label, params GUILayoutOption[] options) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown if (!GUILayout.Button(new GUIContent(string.IsNullOrEmpty(label) ? "" : (" " + label), (Texture)(object)(value ? CheckOn : CheckOff)), Check, options)) { return value; } return !value; } private static void EnsureBannerStyles() { //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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Expected O, but got Unknown //IL_009a: 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_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Expected O, but got Unknown //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Expected O, but got Unknown //IL_00f6: Unknown result type (might be due to invalid IL or missing references) if (bannerBox == null || !((Object)(object)bannerBoxSkin == (Object)(object)skin)) { bannerBoxSkin = skin; GUISkin obj = skin ?? GUI.skin; bannerBox = new GUIStyle(obj.box) { fontSize = 15, fontStyle = (FontStyle)1, alignment = (TextAnchor)3, wordWrap = true }; bannerBox.normal.textColor = Color.white; bannerLine = new GUIStyle(obj.label) { wordWrap = true, fontSize = 14 }; bannerLine.normal.textColor = Color.white; bannerTitle = new GUIStyle(bannerLine) { fontSize = 15, fontStyle = (FontStyle)1 }; bannerSnoozed = new GUIStyle(bannerLine) { fontStyle = (FontStyle)2 }; bannerSnoozed.normal.textColor = new Color(1f, 1f, 1f, 0.6f); } } public static void DrawBannerPanel(Rect r, bool alarming) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0081: 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_008b: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) EnsureBannerStyles(); float num = (alarming ? Mathf.Abs(Mathf.Sin(Time.realtimeSinceStartup * 4f)) : 0f); Color backgroundColor = GUI.backgroundColor; Color color = GUI.color; GUI.backgroundColor = (Color)(alarming ? Color.Lerp(new Color(0.24f, 0.05f, 0.07f, 0.95f), new Color(0.48f, 0.07f, 0.08f, 0.97f), num) : new Color(0.16f, 0.09f, 0.11f, 0.93f)); GUI.Box(r, "", bannerBox); GUI.backgroundColor = backgroundColor; GUI.color = (Color)(alarming ? Color.Lerp(new Color(1f, 0.25f, 0.2f, 0.8f), new Color(1f, 0.45f, 0.35f, 1f), num) : new Color(0.75f, 0.35f, 0.35f, 0.7f)); GUI.DrawTexture(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, 4f, ((Rect)(ref r)).height), (Texture)(object)Texture2D.whiteTexture); GUI.color = color; } private static bool CanDrawChinese(Font f) { if ((Object)(object)f == (Object)null) { return false; } try { f.RequestCharactersInTexture("中文警报"); return f.HasCharacter('中') && f.HasCharacter('报'); } catch { return false; } } private static Font ChineseOsFont() { try { Font val = Font.CreateDynamicFontFromOSFont(new string[5] { "Microsoft YaHei UI", "Microsoft YaHei", "SimHei", "DengXian", "SimSun" }, 14); if ((Object)(object)val != (Object)null) { ManualLogSource log = Plugin.Log; if (log != null) { log.LogInfo((object)("Alarm windows use a Chinese system font: " + string.Join(", ", val.fontNames ?? new string[0]))); } } return val; } catch (Exception ex) { ManualLogSource log2 = Plugin.Log; if (log2 != null) { log2.LogWarning((object)("Could not load a Chinese system font: " + ex.Message)); } return null; } } private static Font FindGameFont() { try { if ((Object)(object)UIRoot.instance == (Object)null) { return null; } Dictionary<Font, int> dictionary = new Dictionary<Font, int>(); Text[] componentsInChildren = ((Component)UIRoot.instance).GetComponentsInChildren<Text>(true); foreach (Text val in componentsInChildren) { if (!((Object)(object)val.font == (Object)null) && !(((Object)val.font).name == "Arial")) { dictionary.TryGetValue(val.font, out var value); dictionary[val.font] = value + 1; } } Font val2 = null; int num = 0; foreach (KeyValuePair<Font, int> item in dictionary) { if (item.Value > num) { val2 = item.Key; num = item.Value; } } if ((Object)(object)val2 != (Object)null) { ManualLogSource log = Plugin.Log; if (log != null) { log.LogInfo((object)("Alarm windows use the game font '" + ((Object)val2).name + "'")); } } return val2; } catch (Exception ex) { ManualLogSource log2 = Plugin.Log; if (log2 != null) { log2.LogWarning((object)("Could not find the game's UI font: " + ex.Message)); } return null; } } private static bool Edge1(int x, int top, int w, int h) { if (x != 0 && x != w - 1 && top != 0) { return top == h - 1; } return true; } private static void SetAll(GUIStyle s, Texture2D tex, Color text) { //IL_0066: 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_007e: 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_00a2: 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_00ba: Unknown result type (might be due to invalid IL or missing references) s.normal.background = tex; s.hover.background = tex; s.active.background = tex; s.focused.background = tex; s.onNormal.background = tex; s.onHover.background = tex; s.onActive.background = tex; s.onFocused.background = tex; s.normal.textColor = text; s.hover.textColor = text; s.active.textColor = text; s.focused.textColor = text; s.onNormal.textColor = text; s.onHover.textColor = text; s.onActive.textColor = text; s.onFocused.textColor = text; } private static Texture2D Boxed(Color fill, Color edge) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) return Make(8, 8, (int x, int top, int w, int h) => (!Edge1(x, top, w, h)) ? fill : edge); } private static Texture2D Make(int w, int h, Func<int, int, int, int, Color> colorAt) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(w, h, (TextureFormat)4, false) { filterMode = (FilterMode)0, wrapMode = (TextureWrapMode)1, hideFlags = (HideFlags)61 }; Color[] array = (Color[])(object)new Color[w * h]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { array[(h - 1 - i) * w + j] = colorAt(j, i, w, h); } } val.SetPixels(array); val.Apply(); textures.Add(val); return val; } } public static class IlsActions { public sealed class LocalChange { public int PlanetId; public int StationId; public int Gid; public int Slot; public int ItemId; public ELogisticStorage PreviousLocal; } public const string RouteComment = "Added by Route Optimizer"; public const string LegacyRouteComment = "Added by Dashboard Alarms"; private static readonly Queue<Action> pending = new Queue<Action>(); public static readonly List<LocalChange> LocalChanges = new List<LocalChange>(); public static readonly List<(int a, int b, int item)> DisabledRoutes = new List<(int, int, int)>(); public static readonly HashSet<long> Dismissed = new HashSet<long>(); public static bool IsOurComment(string c) { if (!(c == "Added by Route Optimizer")) { return c == "Added by Dashboard Alarms"; } return true; } public static long DismissKey(int consumer, int item, int supplier) { return ((long)consumer << 40) | ((long)supplier << 16) | (uint)(item & 0xFFFF); } public static void ClearSaved() { LocalChanges.Clear(); DisabledRoutes.Clear(); Dismissed.Clear(); } public static void Queue(Action a) { pending.Enqueue(a); } public static int ReplaceRoutes(int consumer, int nearer, int item, IEnumerable<int> farther) { AddRoutes(consumer, new int[1] { nearer }, item); return DisableRoutes(farther.Select((int f) => (consumer: consumer, f: f, item: item))); } public static int DisableRoutes(IEnumerable<(int a, int b, int item)> routes) { GalacticTransport val = GameMain.data?.galacticTransport; if (val == null) { return 0; } int num = 0; foreach (var route in routes) { if (val.IsAstro2AstroRouteEnable(route.a, route.b, route.item)) { val.SetAstro2AstroRouteEnable(route.a, route.b, route.item, false); DisabledRoutes.Add(route); num++; ManualLogSource log = Plugin.Log; if (log != null) { log.LogInfo((object)("Disabled " + IlsCensus.ItemName(route.item) + " route " + IlsCensus.PlanetName(route.a) + " <-> " + IlsCensus.PlanetName(route.b))); } } } if (num > 0) { Tip(L.T(string.Format("Route Optimizer: {0} route{1} switched off (not deleted)", num, (num == 1) ? "" : "s"), $"Route Optimizer:已关闭 {num} 条航线(未删除)")); } return num; } public static int ReenableRoutes() { GalacticTransport val = GameMain.data?.galacticTransport; int num = 0; foreach (var disabledRoute in DisabledRoutes) { if (val != null && val.IsAstro2AstroRouteExist(disabledRoute.a, disabledRoute.b, disabledRoute.item) && !val.IsAstro2AstroRouteEnable(disabledRoute.a, disabledRoute.b, disabledRoute.item)) { val.SetAstro2AstroRouteEnable(disabledRoute.a, disabledRoute.b, disabledRoute.item, true); num++; } } DisabledRoutes.Clear(); if (num > 0) { Tip(L.T(string.Format("Route Optimizer: {0} route{1} switched back on", num, (num == 1) ? "" : "s"), $"Route Optimizer:已重新开启 {num} 条航线")); } return num; } public static void RunPending() { while (pending.Count > 0) { Action action = pending.Dequeue(); try { action(); } catch (Exception ex) { ManualLogSource log = Plugin.Log; if (log != null) { log.LogError((object)("ILS action failed: " + ex)); } Tip(L.T("Route Optimizer: the change failed, see the BepInEx log", "Route Optimizer:更改失败,请查看 BepInEx 日志")); } } } public static bool RouteExists(GalacticTransport gt, int planetA, int planetB, int item) { if (!gt.IsAstro2AstroRouteEnable(planetA, planetB, item)) { return gt.IsAstro2AstroRouteEnable(planetA / 100 * 100, planetB / 100 * 100, item); } return true; } public static int AddRoutes(int consumerPlanet, IEnumerable<int> supplierPlanets, int item) { GalacticTransport val = GameMain.data?.galacticTransport; if (val == null) { return 0; } int num = 0; foreach (int supplierPlanet in supplierPlanets) { if (supplierPlanet == consumerPlanet || val.IsAstro2AstroRouteExist(consumerPlanet, supplierPlanet, item)) { if (!val.IsAstro2AstroRouteEnable(consumerPlanet, supplierPlanet, item) && val.IsAstro2AstroRouteExist(consumerPlanet, supplierPlanet, item)) { val.SetAstro2AstroRouteEnable(consumerPlanet, supplierPlanet, item, true); num++; } continue; } val.AddAstro2AstroRoute(consumerPlanet, supplierPlanet, item); val.SetAstro2AstroRouteComment(consumerPlanet, supplierPlanet, item, "Added by Route Optimizer"); num++; ManualLogSource log = Plugin.Log; if (log != null) { log.LogInfo((object)("Added " + IlsCensus.ItemName(item) + " route " + IlsCensus.PlanetName(consumerPlanet) + " <-> " + IlsCensus.PlanetName(supplierPlanet))); } } if (num > 0) { Tip(L.T(string.Format("Route Optimizer: {0} {1} route{2} set up for {3}", num, IlsCensus.ItemName(item), (num == 1) ? "" : "s", IlsCensus.PlanetName(consumerPlanet)), $"Route Optimizer:已为 {IlsCensus.PlanetName(consumerPlanet)} 设置 {num} 条 {IlsCensus.ItemName(item)} 航线")); } return num; } public static List<(int a, int b, int item)> OurRoutes() { List<(int, int, int)> list = new List<(int, int, int)>(); GalacticTransport val = GameMain.data?.galacticTransport; if (val?.astro2astroRoutes == null) { return list; } foreach (KeyValuePair<long, LogisticShipRoute> astro2astroRoute in val.astro2astroRoutes) { if (astro2astroRoute.Value != null && IsOurComment(astro2astroRoute.Value.comment)) { long key = astro2astroRoute.Key; list.Add(((int)(key & 0x3FFFFF), (int)((key >> 22) & 0x3FFFFF), (int)(key >> 44))); } } return list; } public static int RemoveOurRoutes() { GalacticTransport val = GameMain.data?.galacticTransport; List<(int, int, int)> list = OurRoutes(); foreach (var item in list) { val.RemoveAstro2AstroRoute(item.Item1, item.Item2, item.Item3); } if (list.Count > 0) { Tip(L.T(string.Format("Route Optimizer: removed {0} route{1} it had added", list.Count, (list.Count == 1) ? "" : "s"), $"Route Optimizer:已移除其添加的 {list.Count} 条航线")); } return list.Count; } public static int SetLocalDemand(IEnumerable<StationSlot> slots) { //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Invalid comparison between Unknown and I4 //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) int num = 0; foreach (StationSlot slot in slots) { GalaxyData galaxy = GameMain.galaxy; PlanetTransport val = ((galaxy == null) ? null : galaxy.PlanetById(slot.PlanetId)?.factory?.transport); StationComponent val2 = ((val != null) ? val.GetStationComponent(slot.StationId) : null); if (val2 != null && val2.gid == slot.Gid && val2.storage != null && slot.Slot < val2.storage.Length) { StationStore val3 = val2.storage[slot.Slot]; if (val3.itemId == slot.ItemId && (int)val3.localLogic != 2) { LocalChanges.Add(new LocalChange { PlanetId = slot.PlanetId, StationId = slot.StationId, Gid = slot.Gid, Slot = slot.Slot, ItemId = slot.ItemId, PreviousLocal = val3.localLogic }); val.SetStationStorage(slot.StationId, slot.Slot, val3.itemId, val3.max, (ELogisticStorage)2, val3.remoteLogic, (Player)null); num++; } } } if (num > 0) { Tip(L.T($"Route Optimizer: {num} ILS set to receive locally", $"Route Optimizer:{num} 个站已设为本地接收")); } return num; } public static int UndoLocalDemand() { //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: 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_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Invalid comparison between Unknown and I4 //IL_00c8: 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_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) int num = 0; foreach (LocalChange localChange in LocalChanges) { GalaxyData galaxy = GameMain.galaxy; PlanetTransport val = ((galaxy == null) ? null : galaxy.PlanetById(localChange.PlanetId)?.factory?.transport); StationComponent val2 = ((val != null) ? val.GetStationComponent(localChange.StationId) : null); if (val2 != null && val2.gid == localChange.Gid && val2.storage != null && localChange.Slot < val2.storage.Length) { StationStore val3 = val2.storage[localChange.Slot]; if (val3.itemId == localChange.ItemId && (int)val3.localLogic == 2) { val.SetStationStorage(localChange.StationId, localChange.Slot, val3.itemId, val3.max, localChange.PreviousLocal, val3.remoteLogic, (Player)null); num++; } } } LocalChanges.Clear(); if (num > 0) { Tip(L.T($"Route Optimizer: {num} ILS set back to their previous local setting", $"Route Optimizer:{num} 个站已恢复为之前的本地设置")); } return num; } private static void Tip(string text) { try { UIRealtimeTip.Popup(text, false, 0); } catch { } } public static void Write(BinaryWriter w) { //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected I4, but got Unknown w.Write(2); w.Write(LocalChanges.Count); foreach (LocalChange localChange in LocalChanges) { w.Write(localChange.PlanetId); w.Write(localChange.StationId); w.Write(localChange.Gid); w.Write(localChange.Slot); w.Write(localChange.ItemId); w.Write((int)localChange.PreviousLocal); } w.Write(DisabledRoutes.Count); foreach (var disabledRoute in DisabledRoutes) { w.Write(disabledRoute.a); w.Write(disabledRoute.b); w.Write(disabledRoute.item); } w.Write(Dismissed.Count); foreach (long item in Dismissed) { w.Write(item); } } public static void Read(BinaryReader r) { //IL_007d: Unknown result type (might be due to invalid IL or missing references) LocalChanges.Clear(); DisabledRoutes.Clear(); Dismissed.Clear(); int num = r.ReadInt32(); int num2 = r.ReadInt32(); for (int i = 0; i < num2; i++) { LocalChanges.Add(new LocalChange { PlanetId = r.ReadInt32(), StationId = r.ReadInt32(), Gid = r.ReadInt32(), Slot = r.ReadInt32(), ItemId = r.ReadInt32(), PreviousLocal = (ELogisticStorage)r.ReadInt32() }); } if (num >= 2) { int num3 = r.ReadInt32(); for (int j = 0; j < num3; j++) { DisabledRoutes.Add((r.ReadInt32(), r.ReadInt32(), r.ReadInt32())); } int num4 = r.ReadInt32(); for (int k = 0; k < num4; k++) { Dismissed.Add(r.ReadInt64()); } } } } public static class IlsAlarm { public static bool Enabled = true; public static double ThresholdPct = 5.0; public static double PlanetThresholdPct = 25.0; public static int HoldWindows = 2; public static bool PlaySound = true; public static float SnoozeMinutes = 10f; public static readonly HashSet<int> IgnoredItems = new HashSet<int>(); public static readonly List<ItemShortage> Raised = new List<ItemShortage>(); public static readonly Dictionary<int, PlanetAdvice> WorstPlanet = new Dictionary<int, PlanetAdvice>(); private static int windowsOver; private static long snoozeUntilTick; public static AlarmState State { get; private set; } = AlarmState.Normal; public static bool IsShown { get { if (State != AlarmState.Alarming) { return State == AlarmState.Snoozed; } return true; } } public static float SnoozeSecondsLeft { get { if (State != AlarmState.Snoozed) { return 0f; } return (float)(snoozeUntilTick - GameMain.gameTick) / 60f; } } public static void ResetRuntime() { State = AlarmState.Normal; Raised.Clear(); WorstPlanet.Clear(); windowsOver = 0; snoozeUntilTick = 0L; } public static void ResetSettings() { Enabled = true; ThresholdPct = 5.0; PlanetThresholdPct = 25.0; HoldWindows = 2; PlaySound = true; SnoozeMinutes = 10f; IgnoredItems.Clear(); } public static List<ItemShortage> Over(IlsReport report) { return report.Shortages.Where((ItemShortage s) => !IgnoredItems.Contains(s.ItemId) && ((s.DryPct >= ThresholdPct && s.SlotsDry10 > 0) || report.Planets.Any((PlanetAdvice p) => p.ItemId == s.ItemId && p.DryPct >= PlanetThresholdPct))).ToList(); } public static void Evaluate(IlsReport report) { if (!Enabled) { ResetRuntime(); return; } List<ItemShortage> list = Over(report); Raised.Clear(); Raised.AddRange(list); WorstPlanet.Clear(); foreach (ItemShortage s in list) { PlanetAdvice planetAdvice = (from p in report.Planets where p.ItemId == s.ItemId orderby p.DryPct descending select p).FirstOrDefault(); if (planetAdvice != null) { WorstPlanet[s.ItemId] = planetAdvice; } } if (list.Count == 0) { windowsOver = 0; State = AlarmState.Normal; return; } windowsOver++; if (State == AlarmState.Snoozed) { if (GameMain.gameTick >= snoozeUntilTick) { State = AlarmState.Alarming; PlayAlarm(); } } else if (State == AlarmState.Normal && windowsOver >= HoldWindows) { State = AlarmState.Alarming; PlayAlarm(); } } public static void Snooze() { if (State == AlarmState.Alarming) { State = AlarmState.Snoozed; snoozeUntilTick = GameMain.gameTick + (long)(SnoozeMinutes * 60f * 60f); } } public static void Unsnooze() { if (State == AlarmState.Snoozed) { State = AlarmState.Alarming; } } private static void PlayAlarm() { if (PlaySound) { Sound.Play("warning-popup-1"); } } public static void Write(BinaryWriter w) { w.Write(2); w.Write(Enabled); w.Write(ThresholdPct); w.Write(HoldWindows); w.Write(PlaySound); w.Write(SnoozeMinutes); w.Write(IgnoredItems.Count); foreach (int ignoredItem in IgnoredItems) { w.Write(ignoredItem); } w.Write(PlanetThresholdPct); } public static void Read(BinaryReader r) { int num = r.ReadInt32(); Enabled = r.ReadBoolean(); ThresholdPct = r.ReadDouble(); HoldWindows = r.ReadInt32(); PlaySound = r.ReadBoolean(); SnoozeMinutes = r.ReadSingle(); IgnoredItems.Clear(); int num2 = r.ReadInt32(); for (int i = 0; i < num2; i++) { IgnoredItems.Add(r.ReadInt32()); } PlanetThresholdPct = ((num >= 2) ? r.ReadDouble() : 25.0); } } public static class IlsCensus { private sealed class SlotStat { public int ItemId; public int Gid; public int StationId; public int Slot; public int PlanetId; public int Samples; public int Dry; public readonly int[] Cause = new int[6]; public ERemoteRoutePriority Priority; public Dictionary<int, int> Sources; } private sealed class SupplierStat { public int PlanetId; public int ItemId; public int Stations; public long StationSamples; public long AllShipsOut; public long Charging; public double FillSum; public long ShipsSum; public long WorkSum; public long OwnTrips; public long FetchedTrips; public long DistTrips; public double DistLySum; } private sealed class SupplyAgg { public int Shippable; } private sealed class SupplyPlanet { public int PlanetId; public int Stations; public int Shippable; public long Count; public long Max; } public static bool Enabled = true; public static int WindowTicks = 3600; public const int SampleTicks = 60; private const double StarvedShare = 0.1; private const int MaxOptions = 5; private const double MinOptionFill = 0.5; private const double SaturatedBusy = 0.5; private const double SaturatedFill = 0.8; private static readonly Dictionary<long, SlotStat> slots = new Dictionary<long, SlotStat>(); private static readonly Dictionary<long, SupplierStat> suppliers = new Dictionary<long, SupplierStat>(); private static readonly HashSet<long> seenThisSample = new HashSet<long>(); private static readonly Dictionary<int, int> slotCap = new Dictionary<int, int>(); private static Dictionary<int, SupplyAgg> supply = new Dictionary<int, SupplyAgg>(); private static readonly Dictionary<int, long> lastProduced = new Dictionary<int, long>(); private static readonly Dictionary<int, long> lastConsumed = new Dictionary<int, long>(); private static long lastSampleTick = -1L; private static long windowStartTick = -1L; private static long lastReportTick = -1L; private static readonly Dictionary<long, (long prod, long cons, long outv)> lastPlanetTotals = new Dictionary<long, (long, long, long)>(); private const int MaxSuggestedIls = 20; public const double NearLimitPct = 75.0; private const long ChargingBelowJ = 1400000000L; private static int samples; private static bool failed; public static int RouteReviewHoldWindows = 15; private const double MinGainLy = 2.0; private const double MinGainShare = 0.25; private const double MinShipsInFlight = 0.5; private const double CandidateMaxBusy = 0.5; private const double CandidateMinFill = 0.5; private static readonly Dictionary<(int, int, int), int> routeHeld = new Dictionary<(int, int, int), int>(); private static readonly Dictionary<(int, int, int), int> staleHeld = new Dictionary<(int, int, int), int>(); public static bool UseCurrentVesselSpeed = true; public const double RefSailSpeed = 25500.0; public const double RefWarpSpeed = 5100000.0; private const double FixedS = 22.0; private const double RefScaledS = 4.5; private const double RefPerLyS = 1.1; public static IlsReport Latest { get; private set; } public static event Action<IlsReport> ReportReady; public static void Reset() { slots.Clear(); suppliers.Clear(); slotCap.Clear(); supply = new Dictionary<int, SupplyAgg>(); lastProduced.Clear(); lastConsumed.Clear(); lastPlanetTotals.Clear(); routeHeld.Clear(); staleHeld.Clear(); lastSampleTick = (windowStartTick = (lastReportTick = -1L)); samples = 0; failed = false; Latest = null; } public static void Tick() { if (!Enabled || failed) { return; } GameData data = GameMain.data; if (data?.galacticTransport?.stationPool == null || GameMain.galaxy == null || !GameMain.isRunning || GameMain.isPaused) { return; } long gameTick = GameMain.gameTick; if (gameTick < lastSampleTick) { Reset(); } if (lastSampleTick >= 0 && gameTick - lastSampleTick < 60) { return; } try { if (windowStartTick < 0) { windowStartTick = gameTick; ReadProductionTotals(lastProduced, lastConsumed); lastReportTick = gameTick; } lastSampleTick = gameTick; SampleNow(data); if (gameTick - windowStartTick >= WindowTicks) { IlsReport obj = (Latest = BuildReport(data, gameTick)); NewWindow(gameTick); IlsCensus.ReportReady?.Invoke(obj); } } catch (Exception ex) { failed = true; ManualLogSource log = Plugin.Log; if (log != null) { log.LogError((object)("ILS monitor stopped after an error: " + ex)); } } } private static void NewWindow(long tick) { slots.Clear(); suppliers.Clear(); slotCap.Clear(); samples = 0; windowStartTick = tick; } private static void SampleNow(GameData data) { //IL_0085: 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_008c: 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_0299: Unknown result type (might be due to invalid IL or missing references) //IL_029e: Unknown result type (might be due to invalid IL or missing references) //IL_02a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Invalid comparison between Unknown and I4 //IL_02ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_02ba: Unknown result type (might be due to invalid IL or missing references) //IL_02bc: Unknown result type (might be due to invalid IL or missing references) //IL_02c2: Invalid comparison between Unknown and I4 //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_02f8: Unknown result type (might be due to invalid IL or missing references) //IL_02e9: 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_0351: Unknown result type (might be due to invalid IL or missing references) //IL_0356: 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_0139: Unknown result type (might be due to invalid IL or missing references) //IL_0387: Unknown result type (might be due to invalid IL or missing references) //IL_039a: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_03b8: Unknown result type (might be due to invalid IL or missing references) //IL_03bf: Unknown result type (might be due to invalid IL or missing references) //IL_03cd: Unknown result type (might be due to invalid IL or missing references) GalacticTransport galacticTransport = data.galacticTransport; StationComponent[] stationPool = galacticTransport.stationPool; int logisticShipCarries = GameMain.history.logisticShipCarries; Dictionary<int, SupplyAgg> dictionary = new Dictionary<int, SupplyAgg>(); seenThisSample.Clear(); for (int i = 1; i < galacticTransport.stationCursor && i < stationPool.Length; i++) { StationComponent val = stationPool[i]; if (val == null || val.gid != i || val.isCollector || val.storage == null) { continue; } int minLoad = (logisticShipCarries - 1) * val.deliveryShips / 100; for (int j = 0; j < val.storage.Length; j++) { StationStore val2 = val.storage[j]; if (val2.itemId <= 0 || val2.max <= 0 || (int)val2.remoteLogic != 1) { continue; } if (!dictionary.TryGetValue(val2.itemId, out var value)) { value = new SupplyAgg(); dictionary[val2.itemId] = value; } if (Shippable(val2, minLoad)) { value.Shippable++; } if (val.isStellar) { long num = ((long)val.planetId << 20) | (uint)val2.itemId; if (!suppliers.TryGetValue(num, out var value2)) { value2 = new SupplierStat { PlanetId = val.planetId, ItemId = val2.itemId }; suppliers[num] = value2; } if (seenThisSample.Add(num)) { value2.Stations = 0; } value2.Stations++; value2.StationSamples++; value2.FillSum += (double)val2.count / (double)val2.max; value2.ShipsSum += val.idleShipCount + val.workShipCount; value2.WorkSum += val.workShipCount; if (val.idleShipCount == 0) { value2.AllShipsOut++; } else if (val.energy < 1400000000) { value2.Charging++; } } } } supply = dictionary; for (int k = 1; k < galacticTransport.stationCursor && k < stationPool.Length; k++) { StationComponent val3 = stationPool[k]; if (val3 == null || val3.gid != k || val3.isCollector || val3.storage == null) { continue; } for (int l = 0; l < val3.storage.Length; l++) { StationStore val4 = val3.storage[l]; if (val4.itemId > 0 && val4.max > 0 && (int)val4.remoteLogic == 2) { long key = ((long)k << 4) | (uint)l; if (!slots.TryGetValue(key, out var value3) || value3.ItemId != val4.itemId) { value3 = new SlotStat { ItemId = val4.itemId, Gid = k, StationId = val3.id, Slot = l, PlanetId = val3.planetId }; slots[key] = value3; } value3.Samples++; value3.Priority = val3.routePriority; if (val4.count < Math.Max(1, val4.max / 50)) { value3.Dry++; int num2 = Math.Max(0, val4.remoteOrder); SupplyAgg value4; DryCause dryCause = ((supply.TryGetValue(val4.itemId, out value4) && value4.Shippable != 0) ? ((val4.max - val4.count - num2 < logisticShipCarries) ? ((val4.max < MaxSlotFor(val3)) ? DryCause.RaiseMax : DryCause.TripTooLong) : ((num2 == 0) ? DryCause.NotDispatched : ((val3.idleShipCount != 0) ? DryCause.DeliverySlow : DryCause.MoreShips))) : DryCause.MakeMore); value3.Cause[(int)dryCause]++; } } } } for (int m = 1; m < galacticTransport.stationCursor && m < stationPool.Length; m++) { StationComponent val5 = stationPool[m]; if (val5 == null || val5.gid != m || !val5.isStellar || val5.workShipDatas == null) { continue; } int num3 = Math.Min(val5.workShipCount, val5.workShipDatas.Length); for (int n = 0; n < num3; n++) { int itemId = val5.workShipDatas[n].itemId; int otherGId = val5.workShipDatas[n].otherGId; if (itemId <= 0 || otherGId <= 0 || otherGId >= stationPool.Length || stationPool[otherGId] == null) { continue; } StationComponent val6 = val5; StationComponent val7 = stationPool[otherGId]; int num4 = DemandSlot(val5, itemId); if (num4 < 0) { val6 = stationPool[otherGId]; val7 = val5; num4 = DemandSlot(val6, itemId); } if (num4 < 0 || !slots.TryGetValue(((long)val6.gid << 4) | (uint)num4, out var value5)) { continue; } if (value5.Sources == null) { value5.Sources = new Dictionary<int, int>(); } value5.Sources.TryGetValue(val7.planetId, out var value6); value5.Sources[val7.planetId] = value6 + 1; if (suppliers.TryGetValue(((long)val7.planetId << 20) | (uint)itemId, out var value7)) { if (val7 == val5) { value7.OwnTrips++; } else { value7.FetchedTrips++; } double num5 = ((val7.planetId != val6.planetId) ? Ly(GameMain.galaxy, val7.planetId, val6.planetId) : double.NaN); if (!double.IsNaN(num5)) { value7.DistLySum += num5; value7.DistTrips++; } } } } samples++; } private static bool Shippable(StationStore st, int minLoad) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) int num = ((st.max <= minLoad) ? Math.Max(0, st.max - 1) : minLoad); if (st.count > num) { return st.count + Math.Min(0, st.remoteOrder) > num; } return false; } private static int DemandSlot(StationComponent sc, int itemId) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Invalid comparison between Unknown and I4 StationStore[] storage = sc.storage; if (storage == null) { return -1; } for (int i = 0; i < storage.Length; i++) { if (storage[i].itemId == itemId && (int)storage[i].remoteLogic == 2) { return i; } } return -1; } internal static int MaxSlotFor(StationComponent sc) { if (slotCap.TryGetValue(sc.gid, out var value)) { return value; } value = int.MaxValue; try { PlanetFactory val = GameMain.galaxy.PlanetById(sc.planetId)?.factory; if (val != null && sc.entityId > 0 && sc.entityId < val.entityPool.Length) { PrefabDesc val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)val.entityPool[sc.entityId].protoId)?.prefabDesc; if (val2 != null && val2.stationMaxItemCount > 0) { value = val2.stationMaxItemCount + (sc.isStellar ? GameMain.history.remoteStationExtraStorage : GameMain.history.localStationExtraStorage); } } } catch { } slotCap[sc.gid] = value; return value; } private static IlsReport BuildReport(GameData data, long tick) { //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: 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_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Invalid comparison between Unknown and I4 //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) IlsReport ilsReport = new IlsReport { Tick = tick, Samples = samples }; GalaxyData galaxy = GameMain.galaxy; GalacticTransport galacticTransport = data.galacticTransport; Dictionary<int, long> dictionary = new Dictionary<int, long>(); Dictionary<int, long> dictionary2 = new Dictionary<int, long>(); ReadProductionTotals(dictionary, dictionary2); double num = ((tick > lastReportTick) ? ((double)(tick - lastReportTick) / 3600.0) : 0.0); Dictionary<int, (long, long, int, int)> dictionary3 = new Dictionary<int, (long, long, int, int)>(); int logisticShipCarries = GameMain.history.logisticShipCarries; StationComponent[] stationPool = galacticTransport.stationPool; for (int i = 1; i < galacticTransport.stationCursor && i < stationPool.Length; i++) { StationComponent val = stationPool[i]; if (val == null || val.gid != i || val.isCollector || val.storage == null) { continue; } int minLoad = (logisticShipCarries - 1) * val.deliveryShips / 100; StationStore[] storage = val.storage; foreach (StationStore val2 in storage) { if (val2.itemId > 0 && val2.max > 0 && (int)val2.remoteLogic == 1) { dictionary3.TryGetValue(val2.itemId, out var value); dictionary3[val2.itemId] = (value.Item1 + val2.count, value.Item2 + val2.max, value.Item3 + 1, value.Item4 + (Shippable(val2, minLoad) ? 1 : 0)); } } } foreach (IGrouping<int, SlotStat> item in from s in slots.Values where s.Samples > 0 group s by s.ItemId) { long num2 = ((IEnumerable<SlotStat>)item).Sum((Func<SlotStat, long>)((SlotStat s) => s.Samples)); long num3 = ((IEnumerable<SlotStat>)item).Sum((Func<SlotStat, long>)((SlotStat s) => s.Dry)); double num4 = ((num2 == 0L) ? 0.0 : (100.0 * (double)num3 / (double)num2)); if (num4 < 1.0 && !item.Any((SlotStat s) => (double)s.Dry >= (double)s.Samples * 0.1)) { continue; } ItemShortage itemShortage = new ItemShortage { ItemId = item.Key, Name = ItemName(item.Key), DryPct = num4, DemandSlots = item.Count(), SlotsDry10 = item.Count((SlotStat s) => (double)s.Dry >= (double)s.Samples * 0.1) }; long[] array = new long[6]; foreach (SlotStat item2 in item) { for (int num5 = 0; num5 < 6; num5++) { array[num5] += item2.Cause[num5]; } } itemShortage.MainCause = (DryCause)Array.IndexOf(array, array.Max()); for (int num6 = 0; num6 < 6; num6++) { itemShortage.CausePct[num6] = ((num3 == 0L) ? 0.0 : (100.0 * (double)array[num6] / (double)num3)); } if (num > 0.0) { itemShortage.ProducedPerMin = Rate(dictionary, lastProduced, item.Key, num); itemShortage.ConsumedPerMin = Rate(dictionary2, lastConsumed, item.Key, num); } if (dictionary3.TryGetValue(item.Key, out var value2) && value2.Item2 > 0) { itemShortage.SupplyFillPct = 100.0 * (double)value2.Item1 / (double)value2.Item2; itemShortage.SupplyStations = value2.Item3; itemShortage.SupplyShippable = value2.Item4; } ilsReport.Shortages.Add(itemShortage); } ilsReport.Shortages.Sort((ItemShortage a, ItemShortage b) => b.DryPct.CompareTo(a.DryPct)); List<SlotStat> source = slots.Values.Where((SlotStat s) => s.Samples > 0 && (double)s.Dry >= (double)s.Samples * 0.1).ToList(); Dictionary<int, Dictionary<int, SupplyPlanet>> supplyPlanets = ReadSupplyPlanets(galacticTransport, new HashSet<int>(source.Select((SlotStat s) => s.ItemId))); foreach (IGrouping<(int, int), SlotStat> item3 in from s in source group s by (PlanetId: s.PlanetId, ItemId: s.ItemId)) { ilsReport.Planets.Add(BuildPlanetAdvice(item3.Key.Item1, item3.Key.Item2, item3.ToList(), galaxy, galacticTransport, supplyPlanets)); } ilsReport.Planets.Sort((PlanetAdvice a, PlanetAdvice b) => ((double)b.StarvedSlots * b.DryPct).CompareTo((double)a.StarvedSlots * a.DryPct)); foreach (IGrouping<int, SlotStat> item4 in from s in source group s by s.ItemId) { ilsReport.Suppliers[item4.Key] = BuildSupplierAdvice(item4.Key, item4.ToList()); } BuildSupplyRows(ilsReport, data, num); BuildRouteReview(ilsReport, galaxy, galacticTransport); lastProduced.Clear(); foreach (KeyValuePair<int, long> item5 in dictionary) { lastProduced[item5.Key] = item5.Value; } lastConsumed.Clear(); foreach (KeyValuePair<int, long> item6 in dictionary2) { lastConsumed[item6.Key] = item6.Value; } lastReportTick = tick; return ilsReport; } private static Dictionary<int, Dictionary<int, SupplyPlanet>> ReadSupplyPlanets(GalacticTransport gt, HashSet<int> items) { //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Invalid comparison between Unknown and I4 //IL_00b0: 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_00da: 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_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) Dictionary<int, Dictionary<int, SupplyPlanet>> dictionary = new Dictionary<int, Dictionary<int, SupplyPlanet>>(); StationComponent[] stationPool = gt.stationPool; int logisticShipCarries = GameMain.history.logisticShipCarries; for (int i = 1; i < gt.stationCursor && i < stationPool.Length; i++) { StationComponent val = stationPool[i]; if (val == null || val.gid != i || !val.isStellar || val.isCollector || val.storage == null) { continue; } int minLoad = (logisticShipCarries - 1) * val.deliveryShips / 100; StationStore[] storage = val.storage; foreach (StationStore val2 in storage) { if (val2.itemId > 0 && val2.max > 0 && (int)val2.remoteLogic == 1 && items.Contains(val2.itemId)) { if (!dictionary.TryGetValue(val2.itemId, out var value)) { value = new Dictionary<int, SupplyPlanet>(); dictionary[val2.itemId] = value; } if (!value.TryGetValue(val.planetId, out var value2)) { value2 = new SupplyPlanet { PlanetId = val.planetId }; value[val.planetId] = value2; } value2.Stations++; value2.Count += val2.count; value2.Max += val2.max; if (Shippable(val2, minLoad)) { value2.Shippable++; } } } } return dictionary; } private static PlanetAdvice BuildPlanetAdvice(int planetId, int item, List<SlotStat> group, GalaxyData galaxy, GalacticTransport gt, Dictionary<int, Dictionary<int, SupplyPlanet>> supplyPlanets) { PlanetAdvice planetAdvice = new PlanetAdvice { PlanetId = planetId, ItemId = item, StarvedSlots = group.Count, DryPct = 100.0 * group.Average((SlotStat s) => (double)s.Dry / (double)s.Samples), NotPrioritize = group.Count((SlotStat s) => (int)s.Priority == 1) }; long[] array = new long[6]; Dictionary<int, int> dictionary = new Dictionary<int, int>(); foreach (SlotStat item2 in group) { for (int num = 0; num < 6; num++) { array[num] += item2.Cause[num]; } if (item2.Sources == null) { continue; } foreach (KeyValuePair<int, int> source in item2.Sources) { dictionary.TryGetValue(source.Key, out var value); dictionary[source.Key] = value + source.Value; } } planetAdvice.MainCause = (DryCause)Array.IndexOf(array, array.Max()); int num2 = dictionary.Values.Sum(); if (num2 > 0) { planetAdvice.AvgLy = dictionary.Sum((KeyValuePair<int, int> kv) => (double)kv.Value * Ly(galaxy, planetId, kv.Key)) / (double)num2; foreach (KeyValuePair<int, int> item3 in dictionary.OrderByDescending((KeyValuePair<int, int> kv) => kv.Value).Take(5)) { planetAdvice.Sources.Add(new SourceShare { PlanetId = item3.Key, Ly = Ly(galaxy, planetId, item3.Key), SharePct = 100.0 * (double)item3.Value / (double)num2 }); } } if (supplyPlanets.TryGetValue(item, out var value2)) { List<SupplyOption> list = new List<SupplyOption>(); foreach (SupplyPlanet value3 in value2.Values) { if (value3.PlanetId != planetId && (value3.Shippable > 0 || (value3.Max > 0 && (double)value3.Count / (double)value3.Max >= 0.5))) { double num3 = Ly(galaxy, planetId, value3.PlanetId); list.Add(new SupplyOption { PlanetId = value3.PlanetId, Ly = num3, Stations = value3.Stations, FillPct = ((value3.Max == 0L) ? 0.0 : (100.0 * (double)value3.Count / (double)value3.Max)), RouteSet = IlsActions.RouteExists(gt, planetId, value3.PlanetId, item), Closer = (double.IsNaN(planetAdvice.AvgLy) || num3 < planetAdvice.AvgLy) }); } } planetAdvice.Options.AddRange(list.OrderBy((SupplyOption o) => o.Ly).Take(5)); } planetAdvice.Local = BuildLocalAdvice(planetId, item, group, galaxy); return planetAdvice; } private static LocalAdvice BuildLocalAdvice(int planetId, int item, List<SlotStat> group, GalaxyData galaxy) { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0075: 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_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Invalid comparison between Unknown and I4 //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Invalid comparison between Unknown and I4 PlanetTransport val = galaxy.PlanetById(planetId)?.factory?.transport; if (val?.stationPool == null) { return null; } LocalAdvice localAdvice = new LocalAdvice(); for (int i = 1; i < val.stationCursor && i < val.stationPool.Length; i++) { StationComponent val2 = val.stationPool[i]; if (val2 == null || val2.id != i || val2.storage == null) { continue; } StationStore[] storage = val2.storage; foreach (StationStore val3 in storage) { if (val3.itemId == item && (int)val3.localLogic == 1) { localAdvice.Suppliers++; if (val2.isVeinCollector) { localAdvice.Miners++; } localAdvice.Stock += val3.count; } } } if (localAdvice.Suppliers == 0) { return null; } foreach (SlotStat item2 in group) { StationComponent val4 = ((item2.StationId > 0 && item2.StationId < val.stationPool.Length) ? val.stationPool[item2.StationId] : null); if (val4?.storage == null || val4.gid != item2.Gid || item2.Slot >= val4.storage.Length || val4.storage[item2.Slot].itemId != item) { continue; } if ((int)val4.storage[item2.Slot].localLogic == 2) { localAdvice.AlreadyLocal++; continue; } localAdvice.NotLocalDemand.Add(new StationSlot { Gid = item2.Gid, PlanetId = planetId, StationId = item2.StationId, Slot = item2.Slot, ItemId = item }); if (val4.idleDroneCount + val4.workDroneCount == 0) { localAdvice.WithoutDrones++; } } return localAdvice; } private static SupplierAdvice BuildSupplierAdvice(int item, List<SlotStat> starved) { SupplierAdvice supplierAdvice = new SupplierAdvice { ItemId = item }; Dictionary<int, int> dictionary = new Dictionary<int, int>(); foreach (SlotStat item2 in starved) { if (item2.Sources == null) { continue; } foreach (KeyValuePair<int, int> source in item2.Sources) { dictionary.TryGetValue(source.Key, out var value); dictionary[source.Key] = value + source.Value; } } int num = dictionary.Values.Sum(); foreach (SupplierStat item3 in suppliers.Values.Where((SupplierStat x) => x.ItemId == item && x.StationSamples > 0)) { double num2 = (double)item3.AllShipsOut / (double)item3.StationSamples; double num3 = item3.FillSum / (double)item3.StationSamples; dictionary.TryGetValue(item3.PlanetId, out var value2); supplierAdvice.Planets.Add(new SupplierPlanet { PlanetId = item3.PlanetId, Stations = item3.Stations, FillPct = 100.0 * num3, AllShipsOutPct = 100.0 * num2, ShareOfStarvedPct = ((num == 0) ? 0.0 : (100.0 * (double)value2 / (double)num)), Saturated = (num2 >= 0.5 && num3 >= 0.8) }); } supplierAdvice.Planets.Sort((SupplierPlanet a, SupplierPlanet b) => b.AllShipsOutPct.CompareTo(a.AllShipsOutPct)); supplierAdvice.MostlyTripTooLong = starved.Count((SlotStat s) => Array.IndexOf(s.Cause, s.Cause.Max()) == 2) * 2 > starved.Count; return supplierAdvice; } private static void BuildSupplyRows(IlsReport report, GameData data, double minutes) { FactoryProductionStat[] array = data.statistics?.production?.factoryStatPool; AstroTrafficStat[] array2 = data.statistics?.traffic?.factoryTrafficPool; HashSet<long> seen = new HashSet<long>(); HashSet<int> hashSet = new HashSet<int>(report.Shortages.Select((ItemShortage x) => x.ItemId)); List<(SupplyRow, SupplierStat)> list = new List<(SupplyRow, SupplierStat)>(); foreach (SupplierStat value4 in suppliers.Values) { if (value4.StationSamples == 0L) { continue; } long num = ((long)value4.PlanetId << 20) | (uint)value4.ItemId; seen.Add(num); PlanetFactory val = GameMain.galaxy.PlanetById(value4.PlanetId)?.factory; long num2 = 0L; long num3 = 0L; long num4 = 0L; float num5 = float.NaN; if (val != null) { FactoryProductionStat val2 = ((array != null && val.index < array.Length) ? array[val.index] : null); int num6 = ((val2?.productIndices != null && value4.ItemId < val2.productIndices.Length) ? val2.productIndices[value4.ItemId] : 0); if (num6 > 0 && val2.productPool[num6]?.total != null) { num2 = val2.productPool[num6].total[6]; num3 = val2.productPool[num6].total[13]; num5 = val2.productPool[num6].refProductSpeed; } AstroTrafficStat val3 = ((array2 != null && val.index < array2.Length) ? array2[val.index] : null); int num7 = ((val3?.itemIndices != null && value4.ItemId < val3.itemIndices.Length) ? val3.itemIndices[value4.ItemId] : 0); if (num7 > 0 && val3.trafficPool[num7]?.total != null) { num4 = val3.trafficPool[num7].total[13]; } } SupplyRow supplyRow = new SupplyRow { PlanetId = value4.PlanetId, ItemId = value4.ItemId, SupplyIls = value4.Stations, FillPct = 100.0 * value4.FillSum / (double)value4.StationSamples, AllShipsOutPct = 100.0 * (double)value4.AllShipsOut / (double)value4.StationSamples, ChargingPct = 100.0 * (double)value4.Charging / (double)value4.StationSamples, CapacityPerMin = ((num5 > 0f) ? ((double)num5) : double.NaN) }; if (minutes > 0.0 && lastPlanetTotals.TryGetValue(num, out (long, long, long) value)) { supplyRow.ProducedPerMin = (double)(num2 - value.Item1) / minutes; supplyRow.UsedPerMin = (double)(num3 - value.Item2) / minutes; supplyRow.ShippedPerMin = (double)(num4 - value.Item3) / minutes; if (supplyRow.SupplyIls > 0) { supplyRow.PerIlsPerMin = supplyRow.ShippedPerMin / (double)supplyRow.SupplyIls; } } lastPlanetTotals[num] = (num2, num3, num4); list.Add((supplyRow, value4)); if (!report.Supply.TryGetValue(value4.ItemId, out var value2)) { value2 = new List<SupplyRow>(); report.Supply[value4.ItemId] = value2; } value2.Add(supplyRow); } Dictionary<int, double> dictionary = (from m in list where m.sup.DistTrips > 0 group m by m.sup.ItemId).ToDictionary((IGrouping<int, (SupplyRow row, SupplierStat sup)> g) => g.Key, (IGrouping<int, (SupplyRow row, SupplierStat sup)> g) => g.Sum(((SupplyRow row, SupplierStat sup) m) => m.sup.DistLySum) / (double)g.Sum(((SupplyRow row, SupplierStat sup) m) => m.sup.DistTrips)); int carries = GameMain.history?.logisticShipCarries ?? 0; foreach (var item3 in list) { SupplyRow item = item3.Item1; SupplierStat item2 = item3.Item2; item.AvgLy = ((item2.DistTrips > 0) ? (item2.DistLySum / (double)item2.DistTrips) : (dictionary.TryGetValue(item2.ItemId, out var value3) ? value3 : double.NaN)); EstimateCarry(item, item2, carries); Suggest(item, hashSet.Contains(item2.ItemId)); } foreach (IGrouping<int, (SupplyRow, SupplierStat)> item4 in from m in list group m by m.sup.ItemId) { ApplyItemNeed(item4.Select<(SupplyRow, SupplierStat), SupplyRow>(((SupplyRow row, SupplierStat sup) m) => m.row).ToList(), hashSet.Contains(item4.Key)); } foreach (long item5 in lastPlanetTotals.Keys.Where((long k) => !seen.Contains(k)).ToList()) { lastPlanetTotals.Remove(item5); } foreach (List<SupplyRow> value5 in report.Supply.Values) { value5.Sort((SupplyRow a, SupplyRow b) => (b.SuggestedExtraIls == a.SuggestedExtraIls) ? (double.IsNaN(b.ShippedPerMin) ? 0.0 : b.ShippedPerMin).CompareTo(double.IsNaN(a.ShippedPerMin) ? 0.0 : a.ShippedPerMin) : b.SuggestedExtraIls.CompareTo(a.SuggestedExtraIls)); } } private static void EstimateCarry(SupplyRow r, SupplierStat sup, int carries) { double num = ((!double.IsNaN(r.CapacityPerMin)) ? r.CapacityPerMin : r.ProducedPerMin); double num2 = (double.IsNaN(r.UsedPerMin) ? 0.0 : r.UsedPerMin); r.ExportPerMin = (double.IsNaN(num) ? double.NaN : Math.Max(0.0, num - num2)); if (samples > 0 && carries > 0 && !double.IsNaN(r.AvgLy) && r.SupplyIls > 0) { double num3 = Math.Max(0.0, (double)(sup.ShipsSum - sup.WorkSum + sup.OwnTrips) / (double)samples) * (double)carries * 60.0 / RoundTripSeconds(r.AvgLy); long num4 = sup.OwnTrips + sup.FetchedTrips; double num5 = ((num4 > 0 && !double.IsNaN(r.ShippedPerMin)) ? (Math.Max(0.0, r.ShippedPerMin) * (double)sup.FetchedTrips / (double)num4) : 0.0); r.CarryPerMin = num3 + num5; r.CarryPerIlsPerMin = num3 / (double)r.SupplyIls; } } public static void Suggest(SupplyRow r, bool itemShort) { string text = ((r.ChargingPct >= 25.0) ? L.T($" Idle vessels wait to charge {r.ChargingPct:0}% of the time: check the planet's power and these ILS' max charging power.", $" 空闲运输船 {r.ChargingPct:0}% 的时间在等待充电:请检查该星球的电力和这些站的最大充电功率。") : ""); if (double.IsNaN(r.ExportPerMin) || double.IsNaN(r.CarryPerMin)) { r.Limit = SupplyLimit.Unknown; r.Verdict = L.T("measuring (needs a game minute of shipping)", "测量中(需要一游戏分钟的运输数据)") + text; return; } double num = Math.Min(r.ExportPerMin, r.CarryPerMin); r.LoadShare = ((num > 0.0 && !double.IsNaN(r.ShippedPerMin)) ? (r.ShippedPerMin / num) : double.NaN); if (r.CarryPerMin >= r.ExportPerMin) { r.Limit = SupplyLimit.Throughput; r.Verdict = L.T("Throughput maximized. More ILS won't help.", "运力已足够运出全部产能。增加站点无济于事。") + text; return; } r.Limit = SupplyLimit.Ils; if (double.IsNaN(r.CarryPerIlsPerMin) || r.CarryPerIlsPerMin <= 0.0) { r.SuggestedExtraIls = 1; r.Verdict = L.T("It can make more than its ILS can carry: more ILS would help.", "产能超过站点运力:增加站点会有帮助。") + text; return; } double num2 = r.ExportPerMin - r.CarryPerMin; int num3 = Math.Max(1, Math.Min(20, (int)Math.Ceiling(num2 / r.CarryPerIlsPerMin))); string text2 = ((num3 == 20) ? L.T($" (capped at {20})", $"(上限 {20})") : ""); double num4 = (double.IsNaN(r.LoadShare) ? 0.0 : (100.0 * r.LoadShare)); if (num4 >= 75.0) { r.SuggestedExtraIls = num3; r.Verdict = L.T($"Near its ILS limit ({num4:0}% used). +{num3} ILS{text2} would let it ship all {Num(r.ExportPerMin)}/min.", $"接近站点运力上限(已用 {num4:0}%)。+{num3} 个站{text2} 即可运出全部 {Num(r.ExportPerMin)}/分钟。") + text; } else { r.Verdict = L.T($"OK now ({num4:0}% of what its ILS can carry). It can make more than its ILS can carry: if demand grows past that, about {num3} more ILS{text2} would let it ship all {Num(r.ExportPerMin)}/min.", $"目前正常(已用站点运力的 {num4:0}%)。产能超过站点运力:若需求增长超过运力,约再增加 {num3} 个站{text2} 即可运出全部 {Num(r.ExportPerMin)}/分钟。") + text; } } public static void ApplyItemNeed(List<SupplyRow> rows, bool itemShort) { if (itemShort || !rows.Any((SupplyRow r) => r.SuggestedExtraIls > 0)) { return; } List<SupplyRow> source = rows.Where((SupplyRow r) => !double.IsNaN(r.CarryPerMin) && !double.IsNaN(r.ShippedPerMin)).ToList(); double num = source.Sum((SupplyRow r) => r.CarryPerMin); double num2 = source.Sum((SupplyRow r) => r.ShippedPerMin); double num3 = ((num > 0.0) ? (100.0 * num2 / num) : 0.0); if (num3 >= 75.0) { return; } foreach (SupplyRow item in rows.Where((SupplyRow r) => r.SuggestedExtraIls > 0)) { double num4 = (double.IsNaN(item.LoadShare) ? 0.0 : (100.0 * item.LoadShare)); item.SuggestedExtraIls = 0; item.Verdict = L.T($"Near its ILS limit ({num4:0}% used), but nothing is short and all suppliers together ship only {num3:0}% of what their ILS can carry: more ILS here won't help now.", $"接近站点运力上限(已用 {num4:0}%),但没有短缺,且所有供应星球合计只用了站点运力的 {num3:0}%:目前在此增加站点无济于事。"); } } private static string Num(double v) { if (!double.IsNaN(v)) { if (!(v >= 1000000.0)) { if (!(v >= 10000.0)) { return v.ToString("N0", CultureInfo.InvariantCulture); } return (v / 1000.0).ToString("0.#", CultureInfo.InvariantCulture) + "k"; } return (v / 1000000.0).ToString("0.##", CultureInfo.InvariantCulture) + "M"; } return "-"; } public static void RequestCapacity(IEnumerable<int> planetIds) { ProductionExtraInfoCalculator val = GameMain.data?.statistics?.production?.extraInfoCalculator; if (val == null) { return; } foreach (int planetId in planetIds) { GalaxyData galaxy = GameMain.galaxy; PlanetFactory val2 = ((galaxy == null) ? null : galaxy.PlanetById(planetId)?.factory); if (val2 != null) { val.AddFactory(val2.index); } } } private static void ReadProductionTotals(Dictionary<int, long> produced, Dictionary<int, long> consumed) { FactoryProductionStat[] array = GameMain.data.statistics?.production?.factoryStatPool; if (array == null) { return; } int factoryCount = GameMain.data.factoryCount; for (int i = 0; i < factoryCount && i < array.Length; i++) { FactoryProductionStat val = array[i]; if (val?.productPool == null) { continue; } for (int j = 1; j < val.productCursor && j < val.productPool.Length; j++) { ProductStat val2 = val.productPool[j]; if (val2?.total != null && val2.total.Length >= 14) { produced.TryGetValue(val2.itemId, out var value); produced[val2.itemId] = value + val2.total[6]; consumed.TryGetValue(val2.itemId, out var value2); consumed[val2.itemId] = value2 + val2.total[13]; } } } } private static double Rate(Dictionary<int, long> now, Dictionary<int, long> before, int id, double minutes) { now.TryGetValue(id, out var value); if (!before.TryGetValue(id, out var value2)) { return double.NaN; } return (double)(value - value2) / minutes; } public static double Ly(GalaxyData galaxy, int a, int b) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) AstroData[] astrosData = galaxy.astrosData; if (a <= 0 || b <= 0 || a >= astrosData.Length || b >= astrosData.Length) { return double.NaN; } VectorLF3 val = astrosData[a].uPos - astrosData[b].uPos; return ((VectorLF3)(ref val)).magnitude / 2400000.0; } public static string PlanetName(int id) { GalaxyData galaxy = GameMain.galaxy; object obj; if (galaxy == null) { obj = null; } else { PlanetData obj2 = galaxy.PlanetById(id); obj = ((obj2 != null) ? obj2.displayName : null); } if (obj == null) { obj = "planet " + id; } return (string)obj; } public static string ItemName(int id) { try { ItemProto obj = ((ProtoSet<ItemProto>)(object)LDB.items).Select(id); return ((obj != null) ? ((Proto)obj).name : null) ?? ("item " + id); } catch { return "item " + id; } } public static double RoundTripSeconds(double ly) { double sailSpeed = 25500.0; double warpSpeed = 5100000.0; if (UseCurrentVesselSpeed) { try { GameHistoryData history = GameMain.history; if (history != null && history.logisticShipSailSpeedModified > 0f && history.logisticShipWarpSpeedModified > 0f) { sailSpeed = history.logisticShipSailSpeedModified; warpSpeed = history.logisticShipWarpSpeedModified; } } catch { } } return RoundTripSeconds(ly, sailSpeed, warpSpeed); } public static double RoundTripSeconds(double ly, double sailSpeed, double warpSpeed) { ly = Math.Max(0.0, ly); if (!(sailSpeed > 0.0) || !(warpSpeed > 0.0)) { sailSpeed = 25500.0; warpSpeed = 5100000.0; } return 22.0 + 114750.0 / sailSpeed + 1.1 * ly * 5100000.0 / warpSpeed; } private static bool SameStar(int planetA, int planetB) { return planetA / 100 == planetB / 100; } private static void BuildRouteReview(IlsReport report, GalaxyData galaxy, GalacticTransport gt) { if (samples <= 0) { return; } Dictionary<(int, int), Dictionary<int, int>> dictionary = new Dictionary<(int, int), Dictionary<int, int>>(); foreach (SlotStat value7 in slots.Values) { if (value7.Sources == null) { continue; } if (!dictionary.TryGetValue((value7.PlanetId, value7.ItemId), out var value)) { value = new Dictionary<int, int>(); dictionary[(value7.PlanetId, value7.ItemId)] = value; } foreach (KeyValuePair<int, int> source in value7.Sources) { value.TryGetValue(source.Key, out var value2); value[source.Key] = value2 + source.Value; } } HashSet<int> items = new HashSet<int>(dictionary.Keys.Select<(int, int), int>(((int planet, int item) k) => k.item)); Dictionary<int, Dictionary<int, SupplyPlanet>> dictionary2 = ReadSupplyPlanets(gt, items); Dictionary<(int, int), List<int>> dictionary3 = EnabledPlanetRoutes(gt); HashSet<(int, int, int)> seen = new HashSet<(int, int, int)>(); foreach (KeyValuePair<(int, int), Dictionary<int, int>> item2 in dictionary) { int consumer = item2.Key.Item1; int item = item2.Key.Item2; int num = item2.Value.Values.Sum(); double num2 = (double)num / (double)samples; if (num2 < 0.5 || !dictionary2.TryGetValue(item, out var value3)) { continue; } double num3 = item2.Value.Sum((KeyValuePair<int, int> s) => (double)s.Value * Ly(galaxy, consumer, s.Key)) / (double)num; double num4 = (double)item2.Value.Where((KeyValuePair<int, int> s) => !SameStar(consumer, s.Key)).Sum((KeyValuePair<int, int> s) => s.Value) / (double)num; SupplyPlanet supplyPlanet = null; double bestLy = double.MaxValue; foreach (SupplyPlanet value8 in value3.Values) { if (value8.PlanetId == consumer || IlsActions.Dismissed.Contains(IlsActions.DismissKey(consumer, item, value8.PlanetId))) { continue; } double num5 = Ly(galaxy, consumer, value8.PlanetId); if (!double.IsNaN(num5) && !(num5 >= bestLy)) { bool num6 = num5 <= num3 - 2.0 && num5 <= num3 * 0.75; bool flag = SameStar(consumer, value8.PlanetId) && num4 >= 0.5; if ((num6 || flag) && (value8.Shippable > 0 || (value8.Max > 0 && (double)value8.Count / (double)value8.Max >= 0.5)) && HasHeadroom(value8.PlanetId, item) && !IlsActions.RouteExists(gt, consumer, value8.PlanetId, item)) { supplyPlanet = value8; bestLy = num5; } } } if (supplyPlanet == null) { continue; } (int, int, int) tuple = (consumer, item, 0); seen.Add(tuple); routeHeld.TryGetValue(tuple, out var value4); value4++; routeHeld[tuple] = value4; double num7 = RoundTripSeconds(num3); double num8 = RoundTripSeconds(bestLy); double num9 = num2 / num7 * 3600.0; suppliers.TryGetValue(((long)supplyPlanet.PlanetId << 20) | (uint)item, out var value5); RouteSuggestion routeSuggestion = new RouteSuggestion { ConsumerPlanet = consumer, ItemId = item, CurrentLy = num3, Candidate = supplyPlanet.PlanetId, CandidateLy = bestLy, CandidateStations = supplyPlanet.Stations, CandidateFillPct = ((supplyPlanet.Max == 0L) ? 0.0 : (100.0 * (double)supplyPlanet.Count / (double)supplyPlanet.Max)), CandidateBusyPct = ((value5 == null || value5.StationSamples == 0L) ? 0.0 : (100.0 * (double)(value5.AllShipsOut + value5.Charging) / (double)value5.StationSamples)), CandidateSameStar = SameStar(consumer, supplyPlanet.PlanetId), CurrentMostlyOtherStars = (num4 >= 0.5), ShipsInFlight = num2, ShipsFreed = num2 * (1.0 - num8 / num7), WarpersPerHour = (SameStar(consumer, supplyPlanet.PlanetId) ? (num9 * num4) : 0.0), HeldWindows = value4, Ready = (value4 >= RouteReviewHoldWindows) }; foreach (KeyValuePair<int, int> item3 in item2.Value.OrderByDescending((KeyValuePair<int, int> s) => s.Value).Take(4)) { routeSuggestion.Sources.Add(new SourceShare { PlanetId = item3.Key, Ly = Ly(galaxy, consumer, item3.Key), SharePct = 100.0 * (double)item3.Value / (double)num }); } if (dictionary3.TryGetValue((consumer, item), out var value6)) { routeSuggestion.FartherRoutes.AddRange(value6.Where((int p) => Ly(galaxy, consumer, p) > bestLy + 0.01)); } report.RouteSuggestions.Add(routeSuggestion); } foreach (var item4 in routeHeld.Keys.Where(((int, int, int) k) => !seen.Contains(k)).ToList()) { routeHeld.Remove(item4); } report.RouteSuggestions.Sort((RouteSuggestion a, RouteSuggestion b) => b.ShipsFreed.CompareTo(a.ShipsFreed)); BuildStaleRoutes(report, gt); } private static bool HasHeadroom(int planet, int item) { if (!suppliers.TryGetValue(((long)planet << 20) | (uint)item, out var value) || value.StationSamples == 0L) { return false; } return (double)(value.AllShipsOut + value.Charging) / (double)value.StationSamples < 0.5; } private static Dictionary<(int, int), List<int>> EnabledPlanetRoutes(GalacticTransport gt) { Dictionary<(int, int), List<int>> dictionary = new Dictionary<(int, int), List<int>>(); if (gt.astro2astroRoutes == null) { return dictionary; } foreach (KeyValuePair<long, LogisticShipRoute> astro2astroRoute in gt.astro2astroRoutes) { if (astro2astroRoute.Value != null && astro2astroRoute.Value.enable) { int num = (int)(astro2astroRoute.Key & 0x3FFFFF); int num2 = (int)((astro2astroRoute.Key >> 22) & 0x3FFFFF); int item = (int)(astro2astroRoute.Key >> 44); if (num % 100 != 0 && num2 % 100 != 0) { Add(dictionary, (num, item), num2); Add(dictionary, (num2, item), num); } } } return dictionary; static void Add(Dictionary<(int, int), List<int>> d, (int, int) k, int v) { if (!d.TryGetValue(k, out var value)) { value = (d[k] = new List<int>()); } value.Add(v); } } private static void BuildStaleRoutes(IlsReport report, GalacticTransport gt) { //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Invalid comparison between Unknown and I4 //IL_00af: 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_00b7: Invalid comparison between Unknown and I4 //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) if (gt.astro2astroRoutes == null) { return; } HashSet<(int, int)> hashSet = new HashSet<(int, int)>(); HashSet<(int, int)> hashSet2 = new HashSet<(int, int)>(); StationComponent[] stationPool = gt.stationPool; for (int i = 1; i < gt.stationCursor && i < stationPool.Length; i++) { StationComponent val = stationPool[i]; if (val == null || val.gid != i || !val.isStellar || val.isCollector || val.storage == null) { continue; } StationStore[] storage = val.storage; foreach (StationStore val2 in storage) { if (val2.itemId > 0) { if ((int)val2.remoteLogic == 1) { hashSet.Add((val.planetId, val2.itemId)); } else if ((int)val2.remoteLogic == 2) { hashSet2.Add((val.planetId, val2.itemId)); } } } } HashSet<(int, int, int)> stillStale = new HashSet<(int, int, int)>(); foreach (KeyValuePair<long, LogisticShipRoute> astro2astroRoute in gt.astro2astroRoutes) { if (astro2astroRoute.Value == null || !astro2astroRoute.Value.enable) { continue; } int num = (int)(astro2astroRoute.Key & 0x3FFFFF); int num2 = (int)((astro2astroRoute.Key >> 22) & 0x3FFFFF); int item = (int)(astro2astroRoute.Key >> 44); if (num % 100 == 0 || num2 % 100 == 0 || item <= 0) { continue; } bool flag = hashSet.Contains((num, item)); bool flag2 = hashSet.Contains((num2, item)); bool flag3 = hashSet2.Contains((num, item)); bool flag4 = hashSet2.Contains((num2, item)); string text = null; if (!flag && !flag2) { text = L.T("neither planet supplies it any more", "两个星球都不再供应该物品"); } else if (!flag3 && !flag4) { text = L.T("neither planet asks for it any more", "两个星球都不再需求该物品"); } else { bool num3 = !flag || Empty(num); bool flag5 = !flag2 || Empty(num2); if (num3 && flag5) { text = L.T("its supply stayed empty all window (mined out?)", "其供应整个周期都是空的(已采空?)"); } } if (text != null) { (int, int, int) tuple = (num, num2, item); stillStale.Add(tuple); staleHeld.TryGetValue(tuple, out var value); value = (staleHeld[tuple] = value + 1); report.StaleRoutes.Add(new StaleRoute { AstroA = num, AstroB = num2, ItemId = item, Reason = text, Ours = IlsActions.IsOurComment(astro2astroRoute.Value.comment), HeldWindows = value, Ready = (value >= RouteReviewHoldWindows) }); } bool Empty(int p) { if (suppliers.TryGetValue(((long)p << 20) | (uint)item, out var value2) && value2.StationSamples > 0) { return value2.FillSum / (double)value2.StationSamples < 0.02; } return false; } } foreach (var item2 in staleHeld.Keys.Where(((int, int, int) k) => !stillStale.Contains(k)).ToList()) { staleHeld.Remove(item2); } } } public enum DryCause { MakeMore, RaiseMax, TripTooLong, NotDispatched, MoreShips, DeliverySlow } public static class DryCauses { public const int Count = 6; public static string Label(DryCause c) { return c switch { DryCause.MakeMore => L.T("make more", "需增产"), DryCause.RaiseMax => L.T("raise the slot limit", "需提高上限"), DryCause.TripTooLong => L.T("trips too long", "航程过长"), DryCause.NotDispatched => L.T("nothing dispatched", "未派船"), DryCause.MoreShips => L.T("no idle ships", "无空闲运输船"), _ => L.T("deliveries slow", "送货太慢"), }; } public static string Explain(DryCause c) { return c switch { DryCause.MakeMore => L.T("No supply station has stock to ship: produce more.", "没有供应站有可发货的库存:需要增加产量。"), DryCause.RaiseMax => L.T("The slot limit is full counting what is on the way, so the station can't order more. Raise the limit.", "计入在途货物后栏位上限已满,站点无法再订购。请提高上限。"), DryCause.TripTooLong => L.T("The slot is at its maximum with all of it on the way: more is used during a round trip than a full slot holds. Get it from closer: routes to nearer supply, or local supply on the planet.", "栏位已是最大上限且全部在途:一次往返期间的消耗超过满栏位的容量。请从更近处获取:设置到更近供应的航线,或使用本星球的本地供应。"), DryCause.NotDispatched => L.T("Nothing is on the way although suppliers have stock: check range, warpers, energy and route priority.", "供应方有库存但没有货物在途:请检查运输距离、翘曲器、能量和航线优先级。"), DryCause.MoreShips => L.T("Shipments are coming but the station has no idle ship to fetch more.", "有货物在途,但站点没有空闲运输船去取更多。"), _ => L.T("Shipments are coming and more could be ordered, but they arrive too slowly: supply stations may be busy or far away.", "有货物在途且还能订购更多,但到货太慢:供应站可能很忙或距离太远。"), }; } } public sealed class ItemShortage { public int ItemId; public string Name; public double DryPct; public int DemandSlots; public int SlotsDry10; public DryCause MainCause; public double[] CausePct = new double[6]; public double ProducedPerMin = double.NaN; public double ConsumedPerMin = double.NaN; public double SupplyFillPct = double.NaN; public int SupplyStations; public int SupplyShippable; } public sealed class SourceShare { public int PlanetId; public double Ly; public double SharePct; } public sealed class SupplyOption { public int PlanetId; public double Ly; public double FillPct; public int Stations; public bool RouteSet; public bool Closer; } public sealed class StationSlot { public int Gid; public int PlanetId; public int StationId; public int Slot; public int ItemId; } public sealed class LocalAdvice { public int Suppliers; public int Miners; public long Stock; public readonly List<StationSlot> NotLocalDemand = new List<StationSlot>(); public int WithoutDrones; public int AlreadyLocal; } public sealed class PlanetAdvice { public int PlanetId; public int ItemId; public int StarvedSlots; public double DryPct; public DryCause MainCause; public double AvgLy = double.NaN; public readonly List<SourceShare> Sources = new List<SourceShare>(); public readonly List<SupplyOption> Options = new List<SupplyOption>(); public int NotPrioritize; public LocalAdvice Local; } public sealed class SupplierPlanet { public int PlanetId; public int Stations; public double FillPct; public double AllShipsOutPct; public double ShareOfStarvedPct; public bool Saturated; } public sealed class SupplierAdvice { public int ItemId; public readonly List<SupplierPlanet> Planets = new List<SupplierPlanet>(); public bool MostlyTripTooLong; } public enum SupplyLimit { Unknown, Ils, Throughput } public sealed class SupplyRow { public int PlanetId; public int ItemId; public int SupplyIls; public double FillPct; public double AllShipsOutPct; public double ChargingPct; public double CapacityPerMin = double.NaN; public double ProducedPerMin = double.NaN; public double UsedPerMin = double.NaN; public double ShippedPerMin = double.NaN; public double PerIlsPerMin = double.NaN; public double ExportPerMin = double.NaN; public double CarryPerMin = double.NaN; public double CarryPerIlsPerMin = double.NaN; public double AvgLy = double.NaN; public SupplyLimit Limit; public double LoadShare = double.NaN; public int SuggestedExtraIls; public string Verdict = ""; } public sealed class RouteSuggestion { public int ConsumerPlanet; public int ItemId; public double CurrentLy; public readonly List<SourceShare> Sources = new List<SourceShare>(); public int Candidate; public double CandidateLy;