using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CommonAPI;
using CommonAPI.Systems;
using DysonSphereMods.Shared;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Valoneu")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyDescription("BottleneckUI")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+31b1750490d034965cde15adfc56e59a7ba9b23f")]
[assembly: AssemblyProduct("DysonSphereMods")]
[assembly: AssemblyTitle("BottleneckUI")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 DysonSphereMods.Shared
{
public static class Log
{
private static ManualLogSource _logger;
public static void Init(ManualLogSource logger)
{
_logger = logger;
}
public static void Debug(object data)
{
ManualLogSource logger = _logger;
if (logger != null)
{
logger.LogDebug(data);
}
}
public static void Info(object data)
{
ManualLogSource logger = _logger;
if (logger != null)
{
logger.LogInfo(data);
}
}
public static void Warning(object data)
{
ManualLogSource logger = _logger;
if (logger != null)
{
logger.LogWarning(data);
}
}
public static void Error(object data)
{
ManualLogSource logger = _logger;
if (logger != null)
{
logger.LogError(data);
}
}
public static void Fatal(object data)
{
ManualLogSource logger = _logger;
if (logger != null)
{
logger.LogFatal(data);
}
}
public static void Message(object data)
{
ManualLogSource logger = _logger;
if (logger != null)
{
logger.LogMessage(data);
}
}
public static void LogOnce(string msg, ref bool flag, params object[] args)
{
if (flag)
{
return;
}
flag = true;
try
{
string[] array = ((args == null) ? Array.Empty<string>() : args.Select((object arg) => (arg != null) ? ((!(arg is int) && !(arg is string) && !arg.GetType().IsPrimitive) ? JsonUtility.ToJson(arg) : arg.ToString()) : "null").ToArray());
object[] args2 = array;
Info(string.Format(msg, args2));
}
catch (Exception arg2)
{
Warning($"LogOnce failed to format message: {msg}. Exception: {arg2}");
}
}
}
public static class MultiplierService
{
private static readonly Dictionary<string, float> _multipliers = new Dictionary<string, float>();
private static bool _isDirty;
public static event Action OnMultipliersChanged;
public static void SetMultiplier(string key, float value)
{
if (!_multipliers.TryGetValue(key, out var value2) || Math.Abs(value2 - value) > 0.0001f)
{
_multipliers[key] = value;
_isDirty = true;
}
}
public static float GetMultiplier(string key, float defaultValue = 1f)
{
if (!_multipliers.TryGetValue(key, out var value))
{
return defaultValue;
}
return value;
}
public static void CommitChanges()
{
if (_isDirty)
{
_isDirty = false;
MultiplierService.OnMultipliersChanged?.Invoke();
}
}
}
public static class TickManager
{
private static long _lastSlowTick = -1L;
private static long _lastLazyTick = -1L;
private static bool _patched = false;
public static event Action OnSlowTick;
public static event Action OnLazyTick;
public static void Patch(Harmony harmony)
{
if (!_patched)
{
_patched = true;
harmony.PatchAll(typeof(TickManager));
}
}
[HarmonyPatch(typeof(GameMain), "Begin")]
[HarmonyPostfix]
public static void Init()
{
_lastSlowTick = -1L;
_lastLazyTick = -1L;
}
[HarmonyPatch(typeof(GameLogic), "LogicFrame")]
[HarmonyPostfix]
public static void GameTick()
{
long gameTick = GameMain.gameTick;
if (gameTick / 60 > _lastSlowTick)
{
_lastSlowTick = gameTick / 60;
TickManager.OnSlowTick?.Invoke();
}
if (gameTick / 600 > _lastLazyTick)
{
_lastLazyTick = gameTick / 600;
TickManager.OnLazyTick?.Invoke();
}
}
}
public abstract class WindowBase
{
public Rect WindowRect;
protected Vector2 ScrollPos;
private bool _isResizing;
private Rect _resizeRect = new Rect(0f, 0f, 15f, 15f);
public Vector2 MinSize = new Vector2(300f, 200f);
public int WindowId { get; protected set; }
public string Title { get; set; }
public bool IsVisible { get; set; }
protected WindowBase(int windowId, string title, Rect defaultRect)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//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_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
WindowId = windowId;
Title = title;
WindowRect = defaultRect;
}
public virtual void OnGUI()
{
//IL_001d: 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_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
//IL_004b: 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_0055: Unknown result type (might be due to invalid IL or missing references)
if (IsVisible)
{
GUI.backgroundColor = new Color(0.08f, 0.12f, 0.22f, 0.95f);
WindowRect = GUILayout.Window(WindowId, WindowRect, new WindowFunction(DrawWindowInternal), Title, Array.Empty<GUILayoutOption>());
GUI.backgroundColor = Color.white;
((Rect)(ref WindowRect)).x = Mathf.Clamp(((Rect)(ref WindowRect)).x, 0f - ((Rect)(ref WindowRect)).width + 50f, (float)(Screen.width - 50));
((Rect)(ref WindowRect)).y = Mathf.Clamp(((Rect)(ref WindowRect)).y, -20f, (float)(Screen.height - 50));
}
}
private void DrawWindowInternal(int id)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Expected O, but got Unknown
//IL_00dd: Expected O, but got Unknown
//IL_00e6: 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_011b: Invalid comparison between Unknown and I4
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Invalid comparison between Unknown and I4
//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
//IL_014d: Unknown result type (might be due to invalid IL or missing references)
//IL_016a: Unknown result type (might be due to invalid IL or missing references)
DrawWindowHeader();
ScrollPos = GUILayout.BeginScrollView(ScrollPos, Array.Empty<GUILayoutOption>());
DrawWindowContent();
GUILayout.EndScrollView();
DrawWindowFooter();
((Rect)(ref _resizeRect)).x = ((Rect)(ref WindowRect)).width - 20f;
((Rect)(ref _resizeRect)).y = ((Rect)(ref WindowRect)).height - 20f;
((Rect)(ref _resizeRect)).width = 20f;
((Rect)(ref _resizeRect)).height = 20f;
GUI.Label(_resizeRect, "↘", new GUIStyle(GUI.skin.label)
{
alignment = (TextAnchor)4,
fontSize = 20,
normal = new GUIStyleState
{
textColor = new Color(0.6f, 0.6f, 0.6f, 0.8f)
}
});
Event current = Event.current;
bool flag = false;
if ((int)current.type == 0 && ((Rect)(ref _resizeRect)).Contains(current.mousePosition))
{
_isResizing = true;
flag = true;
current.Use();
}
else if ((int)current.type == 1)
{
_isResizing = false;
}
else if ((int)current.type == 3 && _isResizing)
{
ref Rect windowRect = ref WindowRect;
((Rect)(ref windowRect)).width = ((Rect)(ref windowRect)).width + current.delta.x;
ref Rect windowRect2 = ref WindowRect;
((Rect)(ref windowRect2)).height = ((Rect)(ref windowRect2)).height + current.delta.y;
((Rect)(ref WindowRect)).width = Mathf.Max(MinSize.x, ((Rect)(ref WindowRect)).width);
((Rect)(ref WindowRect)).height = Mathf.Max(MinSize.y, ((Rect)(ref WindowRect)).height);
current.Use();
}
if ((int)current.type == 0 && !flag)
{
GUIUtility.keyboardControl = 0;
}
GUI.DragWindow();
}
protected virtual void DrawWindowHeader()
{
}
protected abstract void DrawWindowContent();
protected virtual void DrawWindowFooter()
{
}
public virtual void Toggle()
{
IsVisible = !IsVisible;
}
}
}
namespace BottleneckUI
{
[BepInPlugin("com.Valoneu.BottleneckUI", "BottleneckUI", "1.0.0")]
[BepInProcess("DSPGAME.exe")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[CommonAPISubmoduleDependency(new string[] { "ProtoRegistry", "CustomKeyBindSystem" })]
public class BottleneckUIPlugin : BaseUnityPlugin
{
public static ConfigEntry<KeyboardShortcut> toggleKey;
public static ConfigEntry<float> WindowX;
public static ConfigEntry<float> WindowY;
public static ConfigEntry<float> WindowW;
public static ConfigEntry<float> WindowH;
public static BottleneckNaviLine navi = new BottleneckNaviLine();
private BottleneckScanner _scanner;
private BottleneckWindow _window;
private Harmony _harmony;
private void Awake()
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Expected O, but got Unknown
Log.Init(((BaseUnityPlugin)this).Logger);
toggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "ToggleKey", new KeyboardShortcut((KeyCode)260, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), "Key to toggle the Bottleneck UI");
WindowX = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "WindowX", 200f, "Window X Position");
WindowY = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "WindowY", 200f, "Window Y Position");
WindowW = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "WindowW", 500f, "Window Width");
WindowH = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "WindowH", 600f, "Window Height");
_scanner = new BottleneckScanner();
_window = new BottleneckWindow(_scanner);
_harmony = new Harmony("com.Valoneu.BottleneckUI");
TickManager.Patch(_harmony);
TickManager.OnSlowTick += OnSlowTick;
InitKeyBinds();
((BaseUnityPlugin)this).Logger.LogInfo((object)"BottleneckUI v1.0.0 loaded!");
}
private void OnDestroy()
{
TickManager.OnSlowTick -= OnSlowTick;
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerControlGizmo), "GameTick")]
public static void PlayerControlGizmo_GameTick_Postfix()
{
navi?.GameTick();
}
private void InitKeyBinds()
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected I4, but got Unknown
//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_0061: Unknown result type (might be due to invalid IL or missing references)
if (!CustomKeyBindSystem.HasKeyBind("ToggleBottleneckUI"))
{
BuiltinKey val = default(BuiltinKey);
val.id = 1215;
KeyboardShortcut value = toggleKey.Value;
val.key = new CombineKey((int)((KeyboardShortcut)(ref value)).MainKey, (byte)2, (ECombineKeyAction)0, false);
val.conflictGroup = 2052;
val.name = "ToggleBottleneckUI";
val.canOverride = true;
CustomKeyBindSystem.RegisterKeyBind<PressKeyBind>(val);
}
ProtoRegistry.RegisterString("KEYToggleBottleneckUI", "Toggle Bottleneck UI");
}
private void Update()
{
if (CustomKeyBindSystem.GetKeyBind("ToggleBottleneckUI").keyValue)
{
_window.Toggle();
if (_window.IsVisible)
{
_scanner.Scan();
}
}
_window?.Update();
}
private void OnSlowTick()
{
if (_window.IsVisible)
{
_scanner.Scan();
}
}
private void OnGUI()
{
_window.OnGUI();
}
}
public class BottleneckScanner
{
public List<BottleneckInfo> Bottlenecks { get; private set; } = new List<BottleneckInfo>();
public int TotalScanned { get; private set; }
public void Scan()
{
Bottlenecks.Clear();
TotalScanned = 0;
if (GameMain.data == null || GameMain.data.factories == null)
{
return;
}
PlanetFactory[] factories = GameMain.data.factories;
foreach (PlanetFactory val in factories)
{
if (val != null)
{
string displayName = val.planet.displayName;
_ = val.factorySystem;
ScanAssemblers(val, displayName);
ScanLabs(val, displayName);
ScanFractionators(val, displayName);
ScanMiners(val, displayName);
ScanEjectors(val, displayName);
ScanSilos(val, displayName);
}
}
}
private void ScanAssemblers(PlanetFactory factory, string planetName)
{
FactorySystem factorySystem = factory.factorySystem;
for (int i = 1; i < factorySystem.assemblerCursor; i++)
{
ref AssemblerComponent reference = ref factorySystem.assemblerPool[i];
if (reference.id != i || reference.entityId == 0)
{
continue;
}
TotalScanned++;
if (!reference.replicating)
{
string assemblerStatus = BottleneckHeuristics.GetAssemblerStatus(ref reference, factory);
if (assemblerStatus != null && assemblerStatus != "Working" && assemblerStatus != "Idle" && !assemblerStatus.Contains("Output Full"))
{
Bottlenecks.Add(new BottleneckInfo
{
planetName = planetName,
machineName = BottleneckHeuristics.GetMachineName(factory, reference.entityId),
factory = factory,
entityId = reference.entityId,
status = assemblerStatus,
protoId = factory.entityPool[reference.entityId].protoId
});
}
}
}
}
private void ScanLabs(PlanetFactory factory, string planetName)
{
FactorySystem factorySystem = factory.factorySystem;
for (int i = 1; i < factorySystem.labCursor; i++)
{
ref LabComponent reference = ref factorySystem.labPool[i];
if (reference.id != i || reference.entityId == 0 || (!reference.researchMode && reference.recipeId == 0))
{
continue;
}
TotalScanned++;
if (!reference.replicating)
{
string labStatus = BottleneckHeuristics.GetLabStatus(ref reference, factory);
if (labStatus != null && labStatus != "Working" && labStatus != "Idle" && !labStatus.Contains("Output Full"))
{
Bottlenecks.Add(new BottleneckInfo
{
planetName = planetName,
machineName = BottleneckHeuristics.GetMachineName(factory, reference.entityId),
factory = factory,
entityId = reference.entityId,
status = labStatus,
protoId = factory.entityPool[reference.entityId].protoId
});
}
}
}
}
private void ScanFractionators(PlanetFactory factory, string planetName)
{
FactorySystem factorySystem = factory.factorySystem;
for (int i = 1; i < factorySystem.fractionatorCursor; i++)
{
ref FractionatorComponent reference = ref factorySystem.fractionatorPool[i];
if (reference.id != i || reference.entityId == 0 || reference.fluidId == 0)
{
continue;
}
TotalScanned++;
if (!reference.isWorking)
{
string fracStatus = BottleneckHeuristics.GetFracStatus(ref reference, factory);
if (fracStatus != null && fracStatus != "Working" && fracStatus != "Idle" && !fracStatus.Contains("Output Full"))
{
Bottlenecks.Add(new BottleneckInfo
{
planetName = planetName,
machineName = BottleneckHeuristics.GetMachineName(factory, reference.entityId),
factory = factory,
entityId = reference.entityId,
status = fracStatus,
protoId = factory.entityPool[reference.entityId].protoId
});
}
}
}
}
private void ScanMiners(PlanetFactory factory, string planetName)
{
FactorySystem factorySystem = factory.factorySystem;
for (int i = 1; i < factorySystem.minerCursor; i++)
{
ref MinerComponent reference = ref factorySystem.minerPool[i];
if (reference.id == i && reference.entityId != 0)
{
TotalScanned++;
string minerStatus = BottleneckHeuristics.GetMinerStatus(ref reference, factory);
if (minerStatus != null && minerStatus != "Working" && minerStatus != "Idle" && !minerStatus.Contains("Output Full") && !minerStatus.Contains("No Node"))
{
Bottlenecks.Add(new BottleneckInfo
{
planetName = planetName,
machineName = BottleneckHeuristics.GetMachineName(factory, reference.entityId),
factory = factory,
entityId = reference.entityId,
status = minerStatus,
protoId = factory.entityPool[reference.entityId].protoId
});
}
}
}
}
private void ScanEjectors(PlanetFactory factory, string planetName)
{
FactorySystem factorySystem = factory.factorySystem;
for (int i = 1; i < factorySystem.ejectorCursor; i++)
{
ref EjectorComponent reference = ref factorySystem.ejectorPool[i];
if (reference.id == i && reference.entityId != 0)
{
TotalScanned++;
string ejectorStatus = BottleneckHeuristics.GetEjectorStatus(ref reference, factory);
if (ejectorStatus != null && ejectorStatus != "Working" && ejectorStatus != "Idle" && !ejectorStatus.Contains("Output Full") && ejectorStatus != "No Orbit Set" && !ejectorStatus.Contains("No Node"))
{
Bottlenecks.Add(new BottleneckInfo
{
planetName = planetName,
machineName = BottleneckHeuristics.GetMachineName(factory, reference.entityId),
factory = factory,
entityId = reference.entityId,
status = ejectorStatus,
protoId = factory.entityPool[reference.entityId].protoId
});
}
}
}
}
private void ScanSilos(PlanetFactory factory, string planetName)
{
FactorySystem factorySystem = factory.factorySystem;
for (int i = 1; i < factorySystem.siloCursor; i++)
{
ref SiloComponent reference = ref factorySystem.siloPool[i];
if (reference.id == i && reference.entityId != 0)
{
TotalScanned++;
string siloStatus = BottleneckHeuristics.GetSiloStatus(ref reference, factory);
if (siloStatus != null && siloStatus != "Working" && siloStatus != "Idle" && !siloStatus.Contains("Output Full") && !siloStatus.Contains("No Node"))
{
Bottlenecks.Add(new BottleneckInfo
{
planetName = planetName,
machineName = BottleneckHeuristics.GetMachineName(factory, reference.entityId),
factory = factory,
entityId = reference.entityId,
status = siloStatus,
protoId = factory.entityPool[reference.entityId].protoId
});
}
}
}
}
}
public struct BottleneckInfo
{
public string planetName;
public string machineName;
public PlanetFactory factory;
public int entityId;
public string status;
public int protoId;
}
public static class BottleneckHeuristics
{
public static string GetMachineName(PlanetFactory factory, int entityId)
{
if (entityId <= 0 || entityId >= factory.entityCursor)
{
return "Unknown";
}
int protoId = factory.entityPool[entityId].protoId;
ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(protoId);
if (val == null)
{
return "Unknown Machine";
}
return Localization.Translate(((Proto)val).Name);
}
public static string GetPowerStatus(int pcId, PlanetFactory factory)
{
//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_0030: 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)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
if (pcId <= 0)
{
return "No Power Connection";
}
if (pcId >= factory.powerSystem.consumerCursor)
{
return "Power Error";
}
PowerConsumerComponent val = factory.powerSystem.consumerPool[pcId];
if (val.requiredEnergy <= 0)
{
return null;
}
float num = 1f;
if (val.networkId > 0 && val.networkId < factory.powerSystem.networkServes.Length)
{
num = factory.powerSystem.networkServes[val.networkId];
}
if (num <= 0.001f)
{
return "No Power";
}
if (num < 0.98f)
{
return $"Low Power ({num:P0})";
}
return null;
}
public static string GetAssemblerStatus(ref AssemblerComponent assembler, PlanetFactory factory)
{
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Invalid comparison between Unknown and I4
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Invalid comparison between Unknown and I4
if (assembler.recipeId == 0)
{
return "No Recipe";
}
string powerStatus = GetPowerStatus(assembler.pcId, factory);
if (powerStatus != null)
{
return powerStatus;
}
RecipeProto val = ((ProtoSet<RecipeProto>)(object)LDB.recipes).Select(assembler.recipeId);
if (val != null)
{
for (int i = 0; i < val.Items.Length; i++)
{
int num = val.Items[i];
if (num > 0 && assembler.served[i] < val.ItemCounts[i])
{
return "Missing " + Localization.Translate(((Proto)((ProtoSet<ItemProto>)(object)LDB.items).Select(num)).Name);
}
}
for (int j = 0; j < val.Results.Length; j++)
{
int num2 = val.Results[j];
if (num2 > 0)
{
int num3 = 0;
ERecipeType recipeType = assembler.recipeType;
num3 = (((int)recipeType == 1) ? 100 : (((int)recipeType != 4) ? (val.ResultCounts[j] * 19) : (val.ResultCounts[j] * 9)));
if (assembler.produced[j] >= num3)
{
return "Output Full: " + Localization.Translate(((Proto)((ProtoSet<ItemProto>)(object)LDB.items).Select(num2)).Name);
}
}
}
}
return "Idle";
}
public static string GetLabStatus(ref LabComponent lab, PlanetFactory factory)
{
string powerStatus = GetPowerStatus(lab.pcId, factory);
if (powerStatus != null)
{
return powerStatus;
}
if (lab.researchMode)
{
for (int i = 0; i < 6; i++)
{
int num = LabComponent.matrixIds[i];
if (lab.matrixPoints[i] > 0 && lab.matrixServed[i] < lab.matrixPoints[i])
{
return "Missing " + Localization.Translate(((Proto)((ProtoSet<ItemProto>)(object)LDB.items).Select(num)).Name);
}
}
}
else
{
if (lab.recipeId == 0)
{
return "No Recipe";
}
RecipeProto val = ((ProtoSet<RecipeProto>)(object)LDB.recipes).Select(lab.recipeId);
if (val != null)
{
for (int j = 0; j < val.Items.Length; j++)
{
int num2 = val.Items[j];
if (num2 > 0 && lab.served[j] < val.ItemCounts[j])
{
return "Missing " + Localization.Translate(((Proto)((ProtoSet<ItemProto>)(object)LDB.items).Select(num2)).Name);
}
}
for (int k = 0; k < val.Results.Length; k++)
{
int num3 = val.Results[k];
if (num3 > 0)
{
int num4 = 10 * ((lab.speedOverride + 9999) / 10000);
if (lab.produced[k] >= num4)
{
return "Output Full: " + Localization.Translate(((Proto)((ProtoSet<ItemProto>)(object)LDB.items).Select(num3)).Name);
}
}
}
}
}
return "Idle";
}
public static string GetFracStatus(ref FractionatorComponent frac, PlanetFactory factory)
{
string powerStatus = GetPowerStatus(frac.pcId, factory);
if (powerStatus != null)
{
return powerStatus;
}
if (frac.fluidInputCount <= 0)
{
return "Missing Input";
}
if (frac.productOutputCount >= frac.productOutputMax)
{
return "Output Full (Product)";
}
if (frac.fluidOutputCount >= frac.fluidOutputMax)
{
return "Output Full (Fluid)";
}
return "Idle";
}
public static string GetMinerStatus(ref MinerComponent miner, PlanetFactory factory)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Invalid comparison between Unknown and I4
string powerStatus = GetPowerStatus(miner.pcId, factory);
if (powerStatus != null)
{
return powerStatus;
}
if ((int)miner.type != 1 && miner.veinCount == 0)
{
return "No Veins";
}
if (miner.productCount >= 50)
{
return "Output Full";
}
return "Working";
}
public static string GetEjectorStatus(ref EjectorComponent ejector, PlanetFactory factory)
{
string powerStatus = GetPowerStatus(ejector.pcId, factory);
if (powerStatus != null)
{
return powerStatus;
}
if (ejector.bulletCount <= 0)
{
return "Missing Solar Sails";
}
if (ejector.orbitId == 0)
{
return "No Orbit Set";
}
return "Working";
}
public static string GetSiloStatus(ref SiloComponent silo, PlanetFactory factory)
{
string powerStatus = GetPowerStatus(silo.pcId, factory);
if (powerStatus != null)
{
return powerStatus;
}
if (silo.bulletCount <= 0)
{
return "Missing Rockets";
}
if (!silo.hasNode)
{
return "No Node Available";
}
return "Working";
}
}
public class BottleneckWindow : WindowBase
{
private readonly BottleneckScanner _scanner;
private Dictionary<string, bool> _planetFolds = new Dictionary<string, bool>();
private Dictionary<string, Dictionary<int, bool>> _protoFolds = new Dictionary<string, Dictionary<int, bool>>();
public BottleneckWindow(BottleneckScanner scanner)
: base(1215, "Bottleneck UI (Galactic)", new Rect(BottleneckUIPlugin.WindowX.Value, BottleneckUIPlugin.WindowY.Value, BottleneckUIPlugin.WindowW.Value, BottleneckUIPlugin.WindowH.Value))
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
_scanner = scanner;
}
protected override void DrawWindowHeader()
{
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
if (GUILayout.Button("Manual Scan", Array.Empty<GUILayoutOption>()))
{
_scanner.Scan();
}
if (GUILayout.Button("Close", Array.Empty<GUILayoutOption>()))
{
base.IsVisible = false;
}
GUILayout.EndHorizontal();
GUILayout.Label($"Total Machines (All Planets): {_scanner.TotalScanned} | Bottlenecks: {_scanner.Bottlenecks.Count}", Array.Empty<GUILayoutOption>());
}
protected override void DrawWindowContent()
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Expected O, but got Unknown
//IL_0047: Expected O, but got Unknown
//IL_011e: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Expected O, but got Unknown
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_018a: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Expected O, but got Unknown
//IL_02af: Unknown result type (might be due to invalid IL or missing references)
//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
//IL_02c9: Expected O, but got Unknown
//IL_0355: Unknown result type (might be due to invalid IL or missing references)
//IL_035a: Unknown result type (might be due to invalid IL or missing references)
//IL_036b: Expected O, but got Unknown
//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
//IL_0437: Unknown result type (might be due to invalid IL or missing references)
//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
//IL_04cf: Unknown result type (might be due to invalid IL or missing references)
if (_scanner.Bottlenecks.Count == 0)
{
GUILayout.Label("All machines across all planets are working normally!", new GUIStyle(GUI.skin.label)
{
alignment = (TextAnchor)4,
margin = new RectOffset(0, 0, 20, 0)
}, Array.Empty<GUILayoutOption>());
return;
}
foreach (IGrouping<string, BottleneckInfo> item in from b in _scanner.Bottlenecks
group b by b.planetName)
{
if (!_planetFolds.ContainsKey(item.Key))
{
_planetFolds[item.Key] = false;
}
if (!_protoFolds.ContainsKey(item.Key))
{
_protoFolds[item.Key] = new Dictionary<int, bool>();
}
GUILayout.Space(5f);
GUILayout.BeginHorizontal(GUI.skin.box, Array.Empty<GUILayoutOption>());
if (GUILayout.Button(_planetFolds[item.Key] ? "▼" : "▶", new GUIStyle(GUI.skin.label)
{
fixedWidth = 20f
}, Array.Empty<GUILayoutOption>()))
{
_planetFolds[item.Key] = !_planetFolds[item.Key];
}
GUILayout.Label("<b><size=16>" + item.Key + "</size></b>", new GUIStyle(GUI.skin.label)
{
richText = true,
alignment = (TextAnchor)3
}, Array.Empty<GUILayoutOption>());
GUILayout.EndHorizontal();
if (!_planetFolds[item.Key])
{
continue;
}
foreach (IGrouping<int, BottleneckInfo> item2 in from b in item
group b by b.protoId)
{
BottleneckInfo bottleneckInfo = item2.First();
int protoId = bottleneckInfo.protoId;
if (!_protoFolds[item.Key].ContainsKey(protoId))
{
_protoFolds[item.Key][protoId] = false;
}
ItemProto obj = ((ProtoSet<ItemProto>)(object)LDB.items).Select(protoId);
object obj2;
if (obj == null)
{
obj2 = null;
}
else
{
Sprite iconSprite = obj.iconSprite;
obj2 = ((iconSprite != null) ? iconSprite.texture : null);
}
Texture2D val = (Texture2D)obj2;
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
GUILayout.Space(20f);
GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
if (GUILayout.Button(_protoFolds[item.Key][protoId] ? "▼" : "▶", new GUIStyle(GUI.skin.label)
{
fixedWidth = 20f
}, Array.Empty<GUILayoutOption>()))
{
_protoFolds[item.Key][protoId] = !_protoFolds[item.Key][protoId];
}
if ((Object)(object)val != (Object)null)
{
GUILayout.Label((Texture)(object)val, (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Width(20f),
GUILayout.Height(20f)
});
}
GUILayout.Label($"<b>{bottleneckInfo.machineName} ({item2.Count()})</b>", new GUIStyle(GUI.skin.label)
{
richText = true
}, Array.Empty<GUILayoutOption>());
GUILayout.EndHorizontal();
if (_protoFolds[item.Key][protoId])
{
foreach (BottleneckInfo item3 in item2)
{
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
GUILayout.Space(20f);
if (GUILayout.Button("►", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(25f) }))
{
FocusOnBuilding(item3.factory, item3.entityId);
}
Color contentColor = GUI.contentColor;
if (item3.status.Contains("No Power") || item3.status.Contains("Missing") || item3.status.Contains("No Veins"))
{
GUI.contentColor = new Color(1f, 0.4f, 0.4f);
}
else if (item3.status.Contains("Low Power") || item3.status.Contains("No Recipe") || item3.status.Contains("No Orbit") || item3.status.Contains("No Node"))
{
GUI.contentColor = new Color(1f, 0.8f, 0.4f);
}
else if (item3.status.Contains("Output Full"))
{
GUI.contentColor = new Color(0.4f, 1f, 1f);
}
GUILayout.Label(item3.status, Array.Empty<GUILayoutOption>());
GUI.contentColor = contentColor;
GUILayout.EndHorizontal();
}
}
GUILayout.EndVertical();
GUILayout.EndHorizontal();
}
}
}
private void FocusOnBuilding(PlanetFactory targetFactory, int entityId)
{
//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_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
if (entityId > 0 && targetFactory != null)
{
if (entityId >= targetFactory.entityCursor || targetFactory.entityPool[entityId].id != entityId)
{
Log.Warning($"Invalid entityId: {entityId} for factory on {targetFactory.planet.displayName}");
return;
}
BottleneckUIPlugin.navi.Disable(reset: true);
BottleneckUIPlugin.navi.planetId = targetFactory.planetId;
BottleneckUIPlugin.navi.entityId = entityId;
Vector3 val = VectorLF3.op_Implicit(VectorLF3.op_Implicit(targetFactory.entityPool[entityId].pos));
BottleneckUIPlugin.navi.endPoint = val + ((Vector3)(ref val)).normalized * 8f;
}
}
public override void OnGUI()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Invalid comparison between Unknown and I4
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Invalid comparison between Unknown and I4
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
if ((!((Object)(object)Camera.current != (Object)null) || (int)Camera.current.cameraType == 1) && !GameMain.isPaused && (int)UIGame.viewMode != 6 && base.IsVisible)
{
GUI.backgroundColor = new Color(0.12f, 0.15f, 0.2f, 0.95f);
base.OnGUI();
GUI.backgroundColor = Color.white;
if (Mathf.Abs(((Rect)(ref WindowRect)).x - BottleneckUIPlugin.WindowX.Value) > 0.1f || Mathf.Abs(((Rect)(ref WindowRect)).y - BottleneckUIPlugin.WindowY.Value) > 0.1f || Mathf.Abs(((Rect)(ref WindowRect)).width - BottleneckUIPlugin.WindowW.Value) > 0.1f || Mathf.Abs(((Rect)(ref WindowRect)).height - BottleneckUIPlugin.WindowH.Value) > 0.1f)
{
BottleneckUIPlugin.WindowX.Value = ((Rect)(ref WindowRect)).x;
BottleneckUIPlugin.WindowY.Value = ((Rect)(ref WindowRect)).y;
BottleneckUIPlugin.WindowW.Value = ((Rect)(ref WindowRect)).width;
BottleneckUIPlugin.WindowH.Value = ((Rect)(ref WindowRect)).height;
}
}
}
public void Update()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Invalid comparison between Unknown and I4
if (GameMain.isPaused || (int)UIGame.viewMode == 6)
{
BottleneckUIPlugin.navi.Disable();
return;
}
if (Input.GetKeyDown((KeyCode)27))
{
BottleneckUIPlugin.navi.Disable();
}
BottleneckUIPlugin.navi.Draw();
}
}
public class BottleneckNaviLine
{
public Vector3 endPoint;
public int planetId;
public int entityId;
public LineGizmo lineGizmo;
public void GameTick()
{
if (planetId > 0)
{
Draw();
}
}
public void Draw()
{
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: 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_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: 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_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
if (planetId <= 0)
{
return;
}
if (GameMain.localPlanet != null && GameMain.localPlanet.id == planetId)
{
if ((Object)(object)lineGizmo == (Object)null)
{
Enable();
}
else
{
((GizmoBase)lineGizmo).Open();
}
Vector3 position = GameMain.mainPlayer.position;
Vector3 val = position + ((Vector3)(ref position)).normalized * 4f;
if (Time.frameCount % 30 == 0)
{
Vector3 val2 = val - endPoint;
if (((Vector3)(ref val2)).sqrMagnitude < 2000f)
{
Disable(reset: true);
return;
}
}
if ((Object)(object)lineGizmo != (Object)null)
{
lineGizmo.startPoint = val;
lineGizmo.endPoint = endPoint;
}
}
else if ((Object)(object)lineGizmo != (Object)null)
{
Disable();
}
}
public void Enable()
{
//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_0072: 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)
if (!((Object)(object)lineGizmo != (Object)null))
{
lineGizmo = LineGizmo.Create(1, Vector3.zero, Vector3.zero);
lineGizmo.autoRefresh = true;
lineGizmo.multiplier = 5f;
lineGizmo.alphaMultiplier = 0.6f;
lineGizmo.width = 3f;
lineGizmo.color = Configs.builtin.gizmoColors[4];
lineGizmo.spherical = true;
((GizmoBase)lineGizmo).Open();
((Component)lineGizmo).gameObject.SetActive(true);
}
}
public void Disable(bool reset = false)
{
if ((Object)(object)lineGizmo != (Object)null)
{
((GizmoBase)lineGizmo).Close();
lineGizmo = null;
}
if (reset)
{
planetId = 0;
entityId = 0;
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.Valoneu.BottleneckUI";
public const string PLUGIN_NAME = "BottleneckUI";
public const string PLUGIN_VERSION = "1.0.0";
}
}