using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
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("Multiplies station drone/ship counts, storage capacity and charge power.")]
[assembly: AssemblyFileVersion("1.2.3.0")]
[assembly: AssemblyInformationalVersion("1.2.3+7143abdcb9450a067e8e251466013a9342b96225")]
[assembly: AssemblyProduct("DysonSphereMods")]
[assembly: AssemblyTitle("SpaciousStations")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.3.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 SpaciousStations
{
[BepInPlugin("com.Valoneu.SpaciousStations", "SpaciousStations", "1.2.3")]
[BepInProcess("DSPGAME.exe")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class SpaciousStationsPlugin : BaseUnityPlugin
{
public const string MOD_GUID = "com.Valoneu.SpaciousStations";
public const string MOD_NAME = "SpaciousStations";
public const string MOD_VERSION = "1.2.3";
public static ConfigEntry<float> PLS_DroneMultiplier;
public static ConfigEntry<float> PLS_ShipMultiplier;
public static ConfigEntry<float> PLS_StorageMultiplier;
public static ConfigEntry<float> PLS_ChargeMultiplier;
public static ConfigEntry<float> PLS_EnergyMultiplier;
public static ConfigEntry<float> ILS_DroneMultiplier;
public static ConfigEntry<float> ILS_ShipMultiplier;
public static ConfigEntry<float> ILS_StorageMultiplier;
public static ConfigEntry<float> ILS_ChargeMultiplier;
public static ConfigEntry<float> ILS_EnergyMultiplier;
public static ConfigEntry<int> ILS_ShipReleasePerTick;
public static ConfigEntry<float> EXC_DroneMultiplier;
public static ConfigEntry<float> EXC_ShipMultiplier;
public static ConfigEntry<float> EXC_StorageMultiplier;
public static ConfigEntry<float> EXC_ChargeMultiplier;
public static ConfigEntry<float> EXC_EnergyMultiplier;
public static ConfigEntry<float> EXC_InternalsMultiplier;
public static ConfigEntry<int> DroneTaskInterval;
public static ConfigEntry<int> ShipTaskInterval;
public static ConfigEntry<float> InternalLastStorageMultiplier;
public static ConfigEntry<float> InternalLastChargeMultiplier;
public static ConfigEntry<float> InternalLastPLSStorageMultiplier;
public static ConfigEntry<float> InternalLastPLSChargeMultiplier;
public static ConfigEntry<float> InternalLastEXCStorageMultiplier;
public static ConfigEntry<float> InternalLastEXCChargeMultiplier;
public static ConfigEntry<float> DroneCarryMultiplier;
public static ConfigEntry<float> ShipCarryMultiplier;
public static ConfigEntry<float> CourierCarryMultiplier;
private void Awake()
{
//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
//IL_02ed: Expected O, but got Unknown
//IL_0333: Unknown result type (might be due to invalid IL or missing references)
//IL_033d: Expected O, but got Unknown
//IL_0383: Unknown result type (might be due to invalid IL or missing references)
//IL_038d: Expected O, but got Unknown
//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
//IL_03dd: Expected O, but got Unknown
//IL_0423: Unknown result type (might be due to invalid IL or missing references)
//IL_042d: Expected O, but got Unknown
//IL_0473: Unknown result type (might be due to invalid IL or missing references)
//IL_047d: Expected O, but got Unknown
//IL_0504: Unknown result type (might be due to invalid IL or missing references)
PLS_DroneMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Planetary Logistics Station", "DroneMultiplier", 2f, "Multiplies max number of drones in a PLS.");
PLS_ShipMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Planetary Logistics Station", "ShipMultiplier", 2f, "Multiplies max number of ships in a PLS.");
PLS_StorageMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Planetary Logistics Station", "StorageMultiplier", 2f, "Multiplies maximum amount of items in a PLS.");
PLS_ChargeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Planetary Logistics Station", "ChargeMultiplier", 2f, "Multiplies station's charge power for PLS.");
PLS_EnergyMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Planetary Logistics Station", "EnergyMultiplier", 2f, "Multiplies station's max energy storage for PLS.");
ILS_DroneMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Interstellar Logistics Station", "DroneMultiplier", 2f, "Multiplies max number of drones in an ILS.");
ILS_ShipMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Interstellar Logistics Station", "ShipMultiplier", 2f, "Multiplies max number of ships in an ILS.");
ILS_StorageMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Interstellar Logistics Station", "StorageMultiplier", 2f, "Multiplies maximum amount of items in an ILS.");
ILS_ChargeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Interstellar Logistics Station", "ChargeMultiplier", 2f, "Multiplies station's charge power for ILS.");
ILS_EnergyMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Interstellar Logistics Station", "EnergyMultiplier", 2f, "Multiplies station's max energy storage for ILS.");
ILS_ShipReleasePerTick = ((BaseUnityPlugin)this).Config.Bind<int>("Interstellar Logistics Station", "ShipReleasePerTick", 1, "Maximum number of ships that can be dispatched from a single ILS in a single tick (when it's their turn to dispatch). Vanilla is 1.");
EXC_DroneMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Megastructures Exchange Station", "DroneMultiplier", 2f, "Multiplies max number of drones in an Exchange Station.");
EXC_ShipMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Megastructures Exchange Station", "ShipMultiplier", 2f, "Multiplies max number of ships in an Exchange Station.");
EXC_StorageMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Megastructures Exchange Station", "StorageMultiplier", 2f, "Multiplies maximum amount of items in an Exchange Station.");
EXC_ChargeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Megastructures Exchange Station", "ChargeMultiplier", 2f, "Multiplies station's charge power for Exchange Station.");
EXC_EnergyMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Megastructures Exchange Station", "EnergyMultiplier", 2f, "Multiplies station's max energy storage for Exchange Station.");
EXC_InternalsMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Megastructures Exchange Station", "InternalsMultiplier", 10f, "Multiplies the internal storage capacity of the Interstellar Assembly (Assembly Nexus). Vanilla is 99,999.");
DroneTaskInterval = ((BaseUnityPlugin)this).Config.Bind<int>("General", "DroneTaskInterval", 20, "The interval between drone dispatches. Lower is faster. Vanilla default is 20 (3 dispatches per second). Setting this to 1 will dispatch drones every tick (60 per second).");
ShipTaskInterval = ((BaseUnityPlugin)this).Config.Bind<int>("General", "ShipTaskInterval", 10, "The interval between vessel dispatches for high priority items. Lower is faster. Vanilla default is 10 (6 dispatches per second). Setting this to 1 will dispatch vessels every tick (60 per second). Note: other priority items use 3x and 6x this interval.");
InternalLastStorageMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Internal", "LastStorageMultiplier", 1f, new ConfigDescription("DO NOT CHANGE. Used internally to track migration between sessions.", (AcceptableValueBase)null, new object[1]
{
new ConfigurationManagerAttributes
{
IsAdvanced = true,
Browsable = false
}
}));
InternalLastChargeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Internal", "LastChargeMultiplier", 1f, new ConfigDescription("DO NOT CHANGE. Used internally to track migration between sessions.", (AcceptableValueBase)null, new object[1]
{
new ConfigurationManagerAttributes
{
IsAdvanced = true,
Browsable = false
}
}));
InternalLastPLSStorageMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Internal", "LastPLSStorageMultiplier", 1f, new ConfigDescription("DO NOT CHANGE. Used internally to track migration between sessions.", (AcceptableValueBase)null, new object[1]
{
new ConfigurationManagerAttributes
{
IsAdvanced = true,
Browsable = false
}
}));
InternalLastPLSChargeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Internal", "LastPLSChargeMultiplier", 1f, new ConfigDescription("DO NOT CHANGE. Used internally to track migration between sessions.", (AcceptableValueBase)null, new object[1]
{
new ConfigurationManagerAttributes
{
IsAdvanced = true,
Browsable = false
}
}));
InternalLastEXCStorageMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Internal", "LastEXCStorageMultiplier", 1f, new ConfigDescription("DO NOT CHANGE. Used internally to track migration between sessions.", (AcceptableValueBase)null, new object[1]
{
new ConfigurationManagerAttributes
{
IsAdvanced = true,
Browsable = false
}
}));
InternalLastEXCChargeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Internal", "LastEXCChargeMultiplier", 1f, new ConfigDescription("DO NOT CHANGE. Used internally to track migration between sessions.", (AcceptableValueBase)null, new object[1]
{
new ConfigurationManagerAttributes
{
IsAdvanced = true,
Browsable = false
}
}));
DroneCarryMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "DroneCarryMultiplier", 1f, "Multiplies the carrying capacity of logistics drones.");
ShipCarryMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ShipCarryMultiplier", 1f, "Multiplies the carrying capacity of logistics vessels.");
CourierCarryMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "CourierCarryMultiplier", 1f, "Multiplies the carrying capacity of logistics couriers.");
Log.Init(((BaseUnityPlugin)this).Logger);
SyncConfigToService();
new Harmony("com.Valoneu.SpaciousStations").PatchAll(typeof(StationPatch));
Log.Info("SpaciousStations v1.2.3 loaded!");
}
private void SyncConfigToService()
{
MultiplierService.SetMultiplier("Station_PLS_Drone", PLS_DroneMultiplier.Value);
MultiplierService.SetMultiplier("Station_PLS_Ship", PLS_ShipMultiplier.Value);
MultiplierService.SetMultiplier("Station_PLS_Storage", PLS_StorageMultiplier.Value);
MultiplierService.SetMultiplier("Station_PLS_Charge", PLS_ChargeMultiplier.Value);
MultiplierService.SetMultiplier("Station_PLS_Energy", PLS_EnergyMultiplier.Value);
MultiplierService.SetMultiplier("Station_ILS_Drone", ILS_DroneMultiplier.Value);
MultiplierService.SetMultiplier("Station_ILS_Ship", ILS_ShipMultiplier.Value);
MultiplierService.SetMultiplier("Station_ILS_Storage", ILS_StorageMultiplier.Value);
MultiplierService.SetMultiplier("Station_ILS_Charge", ILS_ChargeMultiplier.Value);
MultiplierService.SetMultiplier("Station_ILS_Energy", ILS_EnergyMultiplier.Value);
MultiplierService.SetMultiplier("Station_EXC_Drone", EXC_DroneMultiplier.Value);
MultiplierService.SetMultiplier("Station_EXC_Ship", EXC_ShipMultiplier.Value);
MultiplierService.SetMultiplier("Station_EXC_Storage", EXC_StorageMultiplier.Value);
MultiplierService.SetMultiplier("Station_EXC_Charge", EXC_ChargeMultiplier.Value);
MultiplierService.SetMultiplier("Station_EXC_Energy", EXC_EnergyMultiplier.Value);
MultiplierService.SetMultiplier("Carry_Drone", DroneCarryMultiplier.Value);
MultiplierService.SetMultiplier("Carry_Ship", ShipCarryMultiplier.Value);
MultiplierService.SetMultiplier("Carry_Courier", CourierCarryMultiplier.Value);
MultiplierService.CommitChanges();
}
public static float GetStorageMultiplier(bool isStellar)
{
if (!isStellar)
{
return PLS_StorageMultiplier.Value;
}
return ILS_StorageMultiplier.Value;
}
public static int GetMultipliedDroneCarry(int vanillaValue)
{
return (int)((float)vanillaValue * DroneCarryMultiplier.Value);
}
public static int GetMultipliedShipCarry(int vanillaValue)
{
return (int)((float)vanillaValue * ShipCarryMultiplier.Value);
}
public static int GetMultipliedCourierCarry(int vanillaValue)
{
return (int)((float)vanillaValue * CourierCarryMultiplier.Value);
}
}
public class ConfigurationManagerAttributes
{
public bool? Browsable;
public bool? IsAdvanced;
}
public static class StationPatch
{
private struct ProtoValues
{
public int DroneCount;
public int ShipCount;
public int ItemCount;
public long EnergyMax;
public long EnergyPerTick;
}
private class ExtraShipState
{
public bool[] IdleShips;
public bool[] WorkingShips;
public ExtraShipState(int capacity)
{
IdleShips = new bool[capacity];
WorkingShips = new bool[capacity];
}
}
private struct LocalPairDistanceComparer : IComparer<SupplyDemandPair>
{
private readonly int _myId;
private readonly Vector3 _myDock;
private readonly StationComponent[] _pool;
public LocalPairDistanceComparer(int myId, Vector3 myDock, StationComponent[] pool)
{
//IL_0008: 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)
_myId = myId;
_myDock = myDock;
_pool = pool;
}
public int Compare(SupplyDemandPair a, SupplyDemandPair b)
{
//IL_0001: 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)
float distSq = GetDistSq(a);
float distSq2 = GetDistSq(b);
return distSq.CompareTo(distSq2);
}
private float GetDistSq(SupplyDemandPair pair)
{
//IL_0000: 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_000e: 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_0049: 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_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
int num = ((pair.supplyId == _myId) ? pair.demandId : pair.supplyId);
if (num <= 0 || num >= _pool.Length || _pool[num] == null)
{
return float.MaxValue;
}
Vector3 droneDock = _pool[num].droneDock;
float num2 = _myDock.x - droneDock.x;
float num3 = _myDock.y - droneDock.y;
float num4 = _myDock.z - droneDock.z;
return num2 * num2 + num3 * num3 + num4 * num4;
}
}
private static Dictionary<int, ProtoValues> _originalValues = new Dictionary<int, ProtoValues>();
private static int _shipsReleasedThisTick = 0;
private static Dictionary<int, int> _lastRequestedMax = new Dictionary<int, int>();
private static ConditionalWeakTable<StationComponent, ExtraShipState> _extraShipStates = new ConditionalWeakTable<StationComponent, ExtraShipState>();
[HarmonyPostfix]
[HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")]
public static void VFPreload_InvokeOnLoadWorkEnded_Postfix()
{
Log.Info("Performing final pass on prototypes for SpaciousStations...");
if ((Object)(object)LDB.items != (Object)null)
{
ItemProto[] dataArray = ((ProtoSet<ItemProto>)(object)LDB.items).dataArray;
foreach (ItemProto val in dataArray)
{
if (val != null && val.prefabDesc != null && val.prefabDesc.isStation)
{
ApplyToItem(val);
}
}
}
if (!((Object)(object)LDB.models != (Object)null))
{
return;
}
ModelProto[] dataArray2 = ((ProtoSet<ModelProto>)(object)LDB.models).dataArray;
foreach (ModelProto val2 in dataArray2)
{
if (val2 != null && val2.prefabDesc != null && val2.prefabDesc.isStation)
{
ApplyToModel(val2);
}
}
}
private static void ApplyToItem(ItemProto item)
{
if (item != null && item.prefabDesc != null && item.prefabDesc.isStation)
{
if (!_originalValues.ContainsKey(((Proto)item).ID))
{
_originalValues[((Proto)item).ID] = new ProtoValues
{
DroneCount = item.prefabDesc.stationMaxDroneCount,
ShipCount = item.prefabDesc.stationMaxShipCount,
ItemCount = item.prefabDesc.stationMaxItemCount,
EnergyMax = item.prefabDesc.stationMaxEnergyAcc,
EnergyPerTick = item.prefabDesc.workEnergyPerTick
};
}
ApplyToDesc(item.prefabDesc, _originalValues[((Proto)item).ID], item);
}
}
private static void ApplyToModel(ModelProto model)
{
if (model == null || model.prefabDesc == null || !model.prefabDesc.isStation)
{
return;
}
ItemProto val = null;
if ((Object)(object)LDB.items != (Object)null)
{
ItemProto[] dataArray = ((ProtoSet<ItemProto>)(object)LDB.items).dataArray;
foreach (ItemProto val2 in dataArray)
{
if (val2 != null && val2.ModelIndex == ((Proto)model).ID)
{
val = val2;
break;
}
}
}
if (val != null)
{
if (!_originalValues.ContainsKey(((Proto)val).ID))
{
_originalValues[((Proto)val).ID] = new ProtoValues
{
DroneCount = val.prefabDesc.stationMaxDroneCount,
ShipCount = val.prefabDesc.stationMaxShipCount,
ItemCount = val.prefabDesc.stationMaxItemCount,
EnergyMax = val.prefabDesc.stationMaxEnergyAcc,
EnergyPerTick = val.prefabDesc.workEnergyPerTick
};
}
ApplyToDesc(model.prefabDesc, _originalValues[((Proto)val).ID], val);
}
}
private static void ApplyToDesc(PrefabDesc desc, ProtoValues original, ItemProto item = null)
{
if (desc == null)
{
return;
}
int num;
float multiplier;
float multiplier2;
float multiplier3;
float multiplier4;
float multiplier5;
if (item != null)
{
if (((Proto)item).ID < 9400 && (((Proto)item).name == null || (((Proto)item).name.IndexOf("Exchange Logistic Station", StringComparison.OrdinalIgnoreCase) < 0 && ((Proto)item).name.IndexOf("Matter", StringComparison.OrdinalIgnoreCase) < 0 && ((Proto)item).name.IndexOf("星际组装厂", StringComparison.OrdinalIgnoreCase) < 0)) && !(((Proto)item).Name == "星际组装厂") && !(((Proto)item).Name == "物资交换器") && !(((Proto)item).Name == "Interstellar Assembly") && ((Proto)item).Name.IndexOf("Exchange", StringComparison.OrdinalIgnoreCase) < 0)
{
num = ((((Proto)item).Name.IndexOf("组装", StringComparison.OrdinalIgnoreCase) >= 0) ? 1 : 0);
if (num == 0)
{
goto IL_0121;
}
}
else
{
num = 1;
}
multiplier = MultiplierService.GetMultiplier("Station_EXC_Drone");
multiplier2 = MultiplierService.GetMultiplier("Station_EXC_Ship");
multiplier3 = MultiplierService.GetMultiplier("Station_EXC_Storage");
multiplier4 = MultiplierService.GetMultiplier("Station_EXC_Energy");
multiplier5 = MultiplierService.GetMultiplier("Station_EXC_Charge");
goto IL_01cd;
}
num = 0;
goto IL_0121;
IL_01cd:
desc.stationMaxDroneCount = (int)((float)original.DroneCount * multiplier);
if (num != 0)
{
desc.stationMaxShipCount = (int)((float)original.ShipCount * multiplier2);
}
else if (desc.isStellarStation)
{
desc.stationMaxShipCount = Math.Min(50, (int)((float)original.ShipCount * multiplier2));
}
else
{
desc.stationMaxShipCount = original.ShipCount;
}
desc.stationMaxItemCount = (int)((float)original.ItemCount * multiplier3);
desc.stationMaxEnergyAcc = (long)((float)original.EnergyMax * multiplier4);
if (!desc.isCollectStation)
{
desc.workEnergyPerTick = (long)((float)original.EnergyPerTick * multiplier5);
}
return;
IL_0121:
if (desc.isStellarStation)
{
multiplier = MultiplierService.GetMultiplier("Station_ILS_Drone");
multiplier2 = MultiplierService.GetMultiplier("Station_ILS_Ship");
multiplier3 = MultiplierService.GetMultiplier("Station_ILS_Storage");
multiplier4 = MultiplierService.GetMultiplier("Station_ILS_Energy");
multiplier5 = MultiplierService.GetMultiplier("Station_ILS_Charge");
}
else
{
multiplier = MultiplierService.GetMultiplier("Station_PLS_Drone");
multiplier2 = MultiplierService.GetMultiplier("Station_PLS_Ship");
multiplier3 = MultiplierService.GetMultiplier("Station_PLS_Storage");
multiplier4 = MultiplierService.GetMultiplier("Station_PLS_Energy");
multiplier5 = MultiplierService.GetMultiplier("Station_PLS_Charge");
}
goto IL_01cd;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(StationComponent), "InternalTickLocal")]
public static void StationComponent_InternalTickLocal_Prefix(StationComponent __instance)
{
__instance.droneTaskInterval = SpaciousStationsPlugin.DroneTaskInterval.Value;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(StationComponent), "DetermineFramingDispatchTime")]
public static bool StationComponent_DetermineFramingDispatchTime_Prefix(long time, int priorityIndex, ref bool __result)
{
int value = SpaciousStationsPlugin.ShipTaskInterval.Value;
switch (priorityIndex)
{
case 1:
__result = time % value == 0;
break;
case 2:
case 3:
__result = time % (value * 3) == 0;
break;
default:
__result = time % (value * 6) == 0;
break;
}
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(StationComponent), "DetermineDispatch")]
public static void StationComponent_DetermineDispatch_Safety_Prefix(StationComponent __instance)
{
_shipsReleasedThisTick = 0;
int num = __instance.idleShipCount + __instance.workShipCount;
if (num > __instance.workShipDatas.Length)
{
__instance.PatchShipArray(num + 10);
}
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(StationComponent), "DetermineDispatch")]
public static IEnumerable<CodeInstruction> DetermineDispatch_Transpiler(IEnumerable<CodeInstruction> instructions)
{
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Expected O, but got Unknown
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
MethodInfo methodInfo = AccessTools.Method(typeof(StationComponent), "DispatchSupplyShip", (Type[])null, (Type[])null);
MethodInfo methodInfo2 = AccessTools.Method(typeof(StationComponent), "DispatchDemandShip", (Type[])null, (Type[])null);
for (int i = 0; i < list.Count; i++)
{
if (!(list[i].opcode == OpCodes.Call) || (!(list[i].operand as MethodInfo == methodInfo) && !(list[i].operand as MethodInfo == methodInfo2)))
{
continue;
}
for (int j = i + 1; j < i + 20 && j < list.Count; j++)
{
if (list[j].opcode == OpCodes.Br)
{
object operand = list[j].operand;
list[j].opcode = OpCodes.Call;
list[j].operand = AccessTools.Method(typeof(StationPatch), "ShouldBreakShipDispatch", (Type[])null, (Type[])null);
list.Insert(j + 1, new CodeInstruction(OpCodes.Brtrue, operand));
i = j + 1;
break;
}
}
}
return list;
}
public static bool ShouldBreakShipDispatch()
{
_shipsReleasedThisTick++;
return _shipsReleasedThisTick >= SpaciousStationsPlugin.ILS_ShipReleasePerTick.Value;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StationComponent), "Import")]
public static void StationComponent_Import_Postfix(StationComponent __instance)
{
if (__instance == null || __instance.id <= 0 || __instance.entityId <= 0 || GameMain.data == null)
{
return;
}
PlanetFactory val = null;
if (GameMain.data.factories != null)
{
PlanetFactory[] factories = GameMain.data.factories;
foreach (PlanetFactory val2 in factories)
{
if (val2 != null && val2.planetId == __instance.planetId)
{
val = val2;
break;
}
}
}
if (val == null)
{
return;
}
int protoId = val.entityPool[__instance.entityId].protoId;
ItemProto val3 = ((ProtoSet<ItemProto>)(object)LDB.items).Select(protoId);
if (val3 == null || !_originalValues.TryGetValue(((Proto)val3).ID, out var _))
{
return;
}
PrefabDesc prefabDesc = val3.prefabDesc;
if (prefabDesc != null)
{
__instance.PatchDroneArray(prefabDesc.stationMaxDroneCount);
if (val3.IsExchangeStation() || (prefabDesc.isStellarStation && prefabDesc.stationMaxShipCount > 10))
{
__instance.PatchShipArray(prefabDesc.stationMaxShipCount);
}
__instance.energyMax = prefabDesc.stationMaxEnergyAcc;
__instance.droneTaskInterval = SpaciousStationsPlugin.DroneTaskInterval.Value;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(GameMain), "Begin")]
public static void GameMain_Begin_Postfix()
{
if ((Object)(object)LDB.items != (Object)null)
{
ItemProto[] dataArray = ((ProtoSet<ItemProto>)(object)LDB.items).dataArray;
for (int i = 0; i < dataArray.Length; i++)
{
ApplyToItem(dataArray[i]);
}
}
if (GameMain.data?.factories != null)
{
PlanetFactory[] factories = GameMain.data.factories;
foreach (PlanetFactory val in factories)
{
if (val?.transport?.stationPool == null)
{
continue;
}
StationComponent[] stationPool = val.transport.stationPool;
foreach (StationComponent val2 in stationPool)
{
if (val2 == null || val2.id <= 0 || val2.entityId <= 0)
{
continue;
}
int protoId = val.entityPool[val2.entityId].protoId;
ItemProto val3 = ((ProtoSet<ItemProto>)(object)LDB.items).Select(protoId);
if (val3?.prefabDesc == null || !_originalValues.TryGetValue(((Proto)val3).ID, out var value))
{
continue;
}
PrefabDesc prefabDesc = val3.prefabDesc;
val2.PatchDroneArray(prefabDesc.stationMaxDroneCount);
if (val3.IsExchangeStation() || (prefabDesc.isStellarStation && prefabDesc.stationMaxShipCount > 10))
{
val2.PatchShipArray(prefabDesc.stationMaxShipCount);
}
val2.energyMax = prefabDesc.stationMaxEnergyAcc;
val2.droneTaskInterval = SpaciousStationsPlugin.DroneTaskInterval.Value;
int num;
float num2;
if (val2.storage != null)
{
if (val3 != null)
{
if (((Proto)val3).ID < 9400 && (((Proto)val3).name == null || (((Proto)val3).name.IndexOf("Exchange Logistic Station", StringComparison.OrdinalIgnoreCase) < 0 && ((Proto)val3).name.IndexOf("Matter", StringComparison.OrdinalIgnoreCase) < 0 && ((Proto)val3).name.IndexOf("星际组装厂", StringComparison.OrdinalIgnoreCase) < 0)) && !(((Proto)val3).Name == "星际组装厂") && !(((Proto)val3).Name == "物资交换器") && !(((Proto)val3).Name == "Interstellar Assembly") && ((Proto)val3).Name.IndexOf("Exchange", StringComparison.OrdinalIgnoreCase) < 0)
{
num = ((((Proto)val3).Name.IndexOf("组装", StringComparison.OrdinalIgnoreCase) >= 0) ? 1 : 0);
if (num == 0)
{
goto IL_0245;
}
}
else
{
num = 1;
}
num2 = MultiplierService.GetMultiplier("Station_EXC_Storage");
goto IL_027f;
}
num = 0;
goto IL_0245;
}
goto IL_03ad;
IL_04f4:
float num3;
float num4 = num3;
int num5;
float num6 = ((num5 != 0) ? SpaciousStationsPlugin.InternalLastEXCChargeMultiplier.Value : (prefabDesc.isStellarStation ? SpaciousStationsPlugin.InternalLastChargeMultiplier.Value : SpaciousStationsPlugin.InternalLastPLSChargeMultiplier.Value));
bool num7 = Math.Abs(num6 - num4) > 0.001f;
long workEnergyPerTick = val.powerSystem.consumerPool[val2.pcId].workEnergyPerTick;
long energyPerTick = val2.energyPerTick;
long num8 = prefabDesc.workEnergyPerTick * 5;
if (num7 && num6 > 0.001f)
{
float num9 = num4 / num6;
val.powerSystem.consumerPool[val2.pcId].workEnergyPerTick = Math.Max(1L, (long)((float)workEnergyPerTick * num9));
val2.energyPerTick = Math.Max(1L, (long)((float)energyPerTick * num9));
}
if (val.powerSystem.consumerPool[val2.pcId].workEnergyPerTick > num8)
{
val.powerSystem.consumerPool[val2.pcId].workEnergyPerTick = num8;
}
if (val2.energyPerTick > num8)
{
val2.energyPerTick = num8;
}
continue;
IL_04ba:
num3 = (prefabDesc.isStellarStation ? MultiplierService.GetMultiplier("Station_ILS_Charge") : MultiplierService.GetMultiplier("Station_PLS_Charge"));
goto IL_04f4;
IL_03ad:
if (prefabDesc.isCollectStation || val2.pcId <= 0 || val.powerSystem == null || val2.pcId >= val.powerSystem.consumerCursor)
{
continue;
}
if (val3 != null)
{
if (((Proto)val3).ID < 9400 && (((Proto)val3).name == null || (((Proto)val3).name.IndexOf("Exchange Logistic Station", StringComparison.OrdinalIgnoreCase) < 0 && ((Proto)val3).name.IndexOf("Matter", StringComparison.OrdinalIgnoreCase) < 0 && ((Proto)val3).name.IndexOf("星际组装厂", StringComparison.OrdinalIgnoreCase) < 0)) && !(((Proto)val3).Name == "星际组装厂") && !(((Proto)val3).Name == "物资交换器") && !(((Proto)val3).Name == "Interstellar Assembly") && ((Proto)val3).Name.IndexOf("Exchange", StringComparison.OrdinalIgnoreCase) < 0)
{
num5 = ((((Proto)val3).Name.IndexOf("组装", StringComparison.OrdinalIgnoreCase) >= 0) ? 1 : 0);
if (num5 == 0)
{
goto IL_04ba;
}
}
else
{
num5 = 1;
}
num3 = MultiplierService.GetMultiplier("Station_EXC_Charge");
goto IL_04f4;
}
num5 = 0;
goto IL_04ba;
IL_0245:
num2 = (prefabDesc.isStellarStation ? MultiplierService.GetMultiplier("Station_ILS_Storage") : MultiplierService.GetMultiplier("Station_PLS_Storage"));
goto IL_027f;
IL_027f:
float num10 = num2;
float num11 = ((num != 0) ? SpaciousStationsPlugin.InternalLastEXCStorageMultiplier.Value : (prefabDesc.isStellarStation ? SpaciousStationsPlugin.InternalLastStorageMultiplier.Value : SpaciousStationsPlugin.InternalLastPLSStorageMultiplier.Value));
int vanillaAdditionStorage = GetVanillaAdditionStorage(val2);
int num12 = value.ItemCount + vanillaAdditionStorage;
int num13 = prefabDesc.stationMaxItemCount + (int)((float)vanillaAdditionStorage * num10);
bool flag = Math.Abs(num11 - num10) > 0.001f;
for (int k = 0; k < val2.storage.Length; k++)
{
if (val2.storage[k].itemId <= 0)
{
continue;
}
if (flag)
{
int num14 = (int)((float)num12 * num11);
if (num14 > 0)
{
val2.storage[k].max = Math.Max(1, (int)((float)val2.storage[k].max / (float)num14 * (float)num13));
}
else
{
val2.storage[k].max = num13;
}
}
else if (val2.storage[k].max > num13)
{
val2.storage[k].max = num13;
}
}
goto IL_03ad;
}
}
}
SpaciousStationsPlugin.InternalLastStorageMultiplier.Value = MultiplierService.GetMultiplier("Station_ILS_Storage");
SpaciousStationsPlugin.InternalLastChargeMultiplier.Value = MultiplierService.GetMultiplier("Station_ILS_Charge");
SpaciousStationsPlugin.InternalLastPLSStorageMultiplier.Value = MultiplierService.GetMultiplier("Station_PLS_Storage");
SpaciousStationsPlugin.InternalLastPLSChargeMultiplier.Value = MultiplierService.GetMultiplier("Station_PLS_Charge");
SpaciousStationsPlugin.InternalLastEXCStorageMultiplier.Value = MultiplierService.GetMultiplier("Station_EXC_Storage");
SpaciousStationsPlugin.InternalLastEXCChargeMultiplier.Value = MultiplierService.GetMultiplier("Station_EXC_Charge");
Log.Info("GameMain.Begin: All station limits synced.");
}
[HarmonyPostfix]
[HarmonyPatch(typeof(GameHistoryData), "UnlockTechFunction")]
public static void GameHistoryData_UnlockTechFunction_Postfix()
{
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIStationWindow), "_OnOpen")]
[HarmonyPatch(typeof(UIStationWindow), "OnStationIdChange")]
public static void UIStationWindow_UIUpdate_Postfix(UIStationWindow __instance)
{
if (__instance.stationId <= 0 || __instance.transport == null || !((Object)(object)__instance.maxChargePowerSlider != (Object)null))
{
return;
}
StationComponent val = __instance.transport.stationPool[__instance.stationId];
if (val != null && val.entityId > 0 && __instance.factory != null)
{
ItemProto val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)__instance.factory.entityPool[val.entityId].protoId);
if (val2 != null && val2.prefabDesc != null)
{
long num = val2.prefabDesc.workEnergyPerTick * 5;
__instance.maxChargePowerSlider.maxValue = num / 50000;
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIControlPanelStationInspector), "_OnOpen")]
[HarmonyPatch(typeof(UIControlPanelStationInspector), "OnStationIdChange")]
public static void UIControlPanelStationInspector_UIUpdate_Postfix(UIControlPanelStationInspector __instance)
{
if (__instance.station != null && (Object)(object)__instance.maxChargePowerSlider != (Object)null)
{
ItemProto val = null;
if (__instance.station.entityId > 0 && __instance.factory != null)
{
val = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)__instance.factory.entityPool[__instance.station.entityId].protoId);
}
if (val != null && val.prefabDesc != null)
{
long num = val.prefabDesc.workEnergyPerTick * 5;
__instance.maxChargePowerSlider.maxValue = num / 50000;
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIStationStorage), "GetAdditionStorage")]
public static void UIStationStorage_GetAdditionStorage_Postfix(UIStationStorage __instance, ref int __result)
{
if (__instance.station != null && (Object)(object)__instance.stationWindow != (Object)null && __instance.stationWindow.factory != null)
{
ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)__instance.stationWindow.factory.entityPool[__instance.station.entityId].protoId);
float num = ((val != null && (((Proto)val).ID >= 9400 || (((Proto)val).name != null && (((Proto)val).name.IndexOf("Exchange Logistic Station", StringComparison.OrdinalIgnoreCase) >= 0 || ((Proto)val).name.IndexOf("Matter", StringComparison.OrdinalIgnoreCase) >= 0 || ((Proto)val).name.IndexOf("星际组装厂", StringComparison.OrdinalIgnoreCase) >= 0)) || ((Proto)val).Name == "星际组装厂" || ((Proto)val).Name == "物资交换器" || ((Proto)val).Name == "Interstellar Assembly" || ((Proto)val).Name.IndexOf("Exchange", StringComparison.OrdinalIgnoreCase) >= 0 || ((Proto)val).Name.IndexOf("组装", StringComparison.OrdinalIgnoreCase) >= 0)) ? MultiplierService.GetMultiplier("Station_EXC_Storage") : (__instance.station.isStellar ? MultiplierService.GetMultiplier("Station_ILS_Storage") : MultiplierService.GetMultiplier("Station_PLS_Storage")));
__result = (int)((float)__result * num);
}
else if (__instance.station != null)
{
float num2 = (__instance.station.isStellar ? MultiplierService.GetMultiplier("Station_ILS_Storage") : MultiplierService.GetMultiplier("Station_PLS_Storage"));
__result = (int)((float)__result * num2);
}
else
{
__result = (int)((float)__result * MultiplierService.GetMultiplier("Station_ILS_Storage"));
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIControlPanelStationStorage), "GetAdditionStorage")]
public static void UIControlPanelStationStorage_GetAdditionStorage_Postfix(UIControlPanelStationStorage __instance, ref int __result)
{
if ((Object)(object)__instance.masterInspector != (Object)null && __instance.masterInspector.station != null && __instance.masterInspector.factory != null)
{
ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)__instance.masterInspector.factory.entityPool[__instance.masterInspector.station.entityId].protoId);
float num = ((val != null && (((Proto)val).ID >= 9400 || (((Proto)val).name != null && (((Proto)val).name.IndexOf("Exchange Logistic Station", StringComparison.OrdinalIgnoreCase) >= 0 || ((Proto)val).name.IndexOf("Matter", StringComparison.OrdinalIgnoreCase) >= 0 || ((Proto)val).name.IndexOf("星际组装厂", StringComparison.OrdinalIgnoreCase) >= 0)) || ((Proto)val).Name == "星际组装厂" || ((Proto)val).Name == "物资交换器" || ((Proto)val).Name == "Interstellar Assembly" || ((Proto)val).Name.IndexOf("Exchange", StringComparison.OrdinalIgnoreCase) >= 0 || ((Proto)val).Name.IndexOf("组装", StringComparison.OrdinalIgnoreCase) >= 0)) ? MultiplierService.GetMultiplier("Station_EXC_Storage") : (__instance.masterInspector.station.isStellar ? MultiplierService.GetMultiplier("Station_ILS_Storage") : MultiplierService.GetMultiplier("Station_PLS_Storage")));
__result = (int)((float)__result * num);
}
else if ((Object)(object)__instance.masterInspector != (Object)null && __instance.masterInspector.station != null)
{
float num2 = (__instance.masterInspector.station.isStellar ? MultiplierService.GetMultiplier("Station_ILS_Storage") : MultiplierService.GetMultiplier("Station_PLS_Storage"));
__result = (int)((float)__result * num2);
}
else
{
__result = (int)((float)__result * MultiplierService.GetMultiplier("Station_ILS_Storage"));
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIStationStorage), "RefreshValues")]
public static void UIStationStorage_RefreshValues_Postfix(UIStationStorage __instance)
{
if (__instance.station == null || !((Object)(object)__instance.stationWindow != (Object)null) || __instance.stationWindow.factory == null || !((Object)(object)__instance.maxSlider != (Object)null))
{
return;
}
ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)__instance.stationWindow.factory.entityPool[__instance.station.entityId].protoId);
if (val != null && val.prefabDesc != null)
{
float num = ((((Proto)val).ID >= 9400 || (((Proto)val).name != null && (((Proto)val).name.IndexOf("Exchange Logistic Station", StringComparison.OrdinalIgnoreCase) >= 0 || ((Proto)val).name.IndexOf("Matter", StringComparison.OrdinalIgnoreCase) >= 0 || ((Proto)val).name.IndexOf("星际组装厂", StringComparison.OrdinalIgnoreCase) >= 0)) || ((Proto)val).Name == "星际组装厂" || ((Proto)val).Name == "物资交换器" || ((Proto)val).Name == "Interstellar Assembly" || ((Proto)val).Name.IndexOf("Exchange", StringComparison.OrdinalIgnoreCase) >= 0 || ((Proto)val).Name.IndexOf("组装", StringComparison.OrdinalIgnoreCase) >= 0) ? MultiplierService.GetMultiplier("Station_EXC_Storage") : (__instance.station.isStellar ? MultiplierService.GetMultiplier("Station_ILS_Storage") : MultiplierService.GetMultiplier("Station_PLS_Storage")));
int num2 = (__instance.station.isCollector ? GameMain.history.localStationExtraStorage : (__instance.station.isVeinCollector ? GameMain.history.localStationExtraStorage : (__instance.station.isStellar ? GameMain.history.remoteStationExtraStorage : GameMain.history.localStationExtraStorage)));
if (_originalValues.TryGetValue(((Proto)val).ID, out var value))
{
int num3 = (int)((float)value.ItemCount * num) + (int)((float)num2 * num);
__instance.maxSlider.maxValue = (float)num3 / 100f;
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIControlPanelStationStorage), "RefreshValues")]
public static void UIControlPanelStationStorage_RefreshValues_Postfix(UIControlPanelStationStorage __instance)
{
if (__instance.station == null || !((Object)(object)__instance.masterInspector != (Object)null) || __instance.masterInspector.factory == null || !((Object)(object)__instance.maxSlider != (Object)null))
{
return;
}
ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)__instance.masterInspector.factory.entityPool[__instance.station.entityId].protoId);
if (val != null && val.prefabDesc != null)
{
float num = ((((Proto)val).ID >= 9400 || (((Proto)val).name != null && (((Proto)val).name.IndexOf("Exchange Logistic Station", StringComparison.OrdinalIgnoreCase) >= 0 || ((Proto)val).name.IndexOf("Matter", StringComparison.OrdinalIgnoreCase) >= 0 || ((Proto)val).name.IndexOf("星际组装厂", StringComparison.OrdinalIgnoreCase) >= 0)) || ((Proto)val).Name == "星际组装厂" || ((Proto)val).Name == "物资交换器" || ((Proto)val).Name == "Interstellar Assembly" || ((Proto)val).Name.IndexOf("Exchange", StringComparison.OrdinalIgnoreCase) >= 0 || ((Proto)val).Name.IndexOf("组装", StringComparison.OrdinalIgnoreCase) >= 0) ? MultiplierService.GetMultiplier("Station_EXC_Storage") : (__instance.station.isStellar ? MultiplierService.GetMultiplier("Station_ILS_Storage") : MultiplierService.GetMultiplier("Station_PLS_Storage")));
int num2 = (__instance.station.isCollector ? GameMain.history.localStationExtraStorage : (__instance.station.isVeinCollector ? GameMain.history.localStationExtraStorage : (__instance.station.isStellar ? GameMain.history.remoteStationExtraStorage : GameMain.history.localStationExtraStorage)));
if (_originalValues.TryGetValue(((Proto)val).ID, out var value))
{
int num3 = (int)((float)value.ItemCount * num) + (int)((float)num2 * num);
__instance.maxSlider.maxValue = (float)num3 / 100f;
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(PlanetTransport), "SetStationStorage")]
public static void PlanetTransport_SetStationStorage_Prefix(PlanetTransport __instance, int stationId, ref int itemCountMax)
{
if (stationId <= 0 || stationId >= __instance.stationCursor)
{
return;
}
StationComponent val = __instance.stationPool[stationId];
if (val == null || val.entityId <= 0 || __instance.factory == null)
{
return;
}
ItemProto val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)__instance.factory.entityPool[val.entityId].protoId);
if (val2 != null && val2.prefabDesc != null)
{
float num = ((((Proto)val2).ID >= 9400 || (((Proto)val2).name != null && (((Proto)val2).name.IndexOf("Exchange Logistic Station", StringComparison.OrdinalIgnoreCase) >= 0 || ((Proto)val2).name.IndexOf("Matter", StringComparison.OrdinalIgnoreCase) >= 0 || ((Proto)val2).name.IndexOf("星际组装厂", StringComparison.OrdinalIgnoreCase) >= 0)) || ((Proto)val2).Name == "星际组装厂" || ((Proto)val2).Name == "物资交换器" || ((Proto)val2).Name == "Interstellar Assembly" || ((Proto)val2).Name.IndexOf("Exchange", StringComparison.OrdinalIgnoreCase) >= 0 || ((Proto)val2).Name.IndexOf("组装", StringComparison.OrdinalIgnoreCase) >= 0) ? MultiplierService.GetMultiplier("Station_EXC_Storage") : (val.isStellar ? MultiplierService.GetMultiplier("Station_ILS_Storage") : MultiplierService.GetMultiplier("Station_PLS_Storage")));
int num2 = (val.isCollector ? GameMain.history.localStationExtraStorage : (val.isVeinCollector ? GameMain.history.localStationExtraStorage : (val.isStellar ? GameMain.history.remoteStationExtraStorage : GameMain.history.localStationExtraStorage)));
if (_originalValues.TryGetValue(((Proto)val2).ID, out var value))
{
int num3 = (int)((float)value.ItemCount * num) + (int)((float)num2 * num);
_lastRequestedMax[stationId] = Mathf.Min(itemCountMax, num3);
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlanetTransport), "SetStationStorage")]
public static void PlanetTransport_SetStationStorage_Postfix(PlanetTransport __instance, int stationId, int storageIdx, int itemId, int itemCountMax)
{
if (_lastRequestedMax.TryGetValue(stationId, out var value))
{
if (storageIdx >= 0 && storageIdx < __instance.stationPool[stationId].storage.Length && __instance.stationPool[stationId].storage[storageIdx].itemId == itemId)
{
__instance.stationPool[stationId].storage[storageIdx].max = value;
}
_lastRequestedMax.Remove(stationId);
}
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(PlanetTransport), "NewStationComponent")]
[HarmonyPatch(typeof(PlanetTransport), "SetStationStorage")]
[HarmonyPatch(typeof(PlanetFactory), "EntityFastFillIn")]
public static IEnumerable<CodeInstruction> ExtraStorage_Transpiler(IEnumerable<CodeInstruction> instructions)
{
return ExtraStorage_Transpiler_Worker(instructions);
}
private static IEnumerable<CodeInstruction> ExtraStorage_Transpiler_Worker(IEnumerable<CodeInstruction> instructions)
{
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Expected O, but got Unknown
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Expected O, but got Unknown
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Expected O, but got Unknown
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Expected O, but got Unknown
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Expected O, but got Unknown
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Expected O, but got Unknown
//IL_0169: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Expected O, but got Unknown
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Expected O, but got Unknown
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
FieldInfo fieldInfo = AccessTools.Field(typeof(GameHistoryData), "localStationExtraStorage");
FieldInfo fieldInfo2 = AccessTools.Field(typeof(GameHistoryData), "remoteStationExtraStorage");
if (fieldInfo == null || fieldInfo2 == null)
{
return list;
}
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Ldfld && list[i].operand as FieldInfo == fieldInfo)
{
list.Insert(i + 1, new CodeInstruction(OpCodes.Conv_R4, (object)null));
list.Insert(i + 2, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(StationPatch), "get_PLS_StorageMultiplierValue", (Type[])null, (Type[])null)));
list.Insert(i + 3, new CodeInstruction(OpCodes.Mul, (object)null));
list.Insert(i + 4, new CodeInstruction(OpCodes.Conv_I4, (object)null));
i += 4;
}
else if (list[i].opcode == OpCodes.Ldfld && list[i].operand as FieldInfo == fieldInfo2)
{
list.Insert(i + 1, new CodeInstruction(OpCodes.Conv_R4, (object)null));
list.Insert(i + 2, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(StationPatch), "get_ILS_StorageMultiplierValue", (Type[])null, (Type[])null)));
list.Insert(i + 3, new CodeInstruction(OpCodes.Mul, (object)null));
list.Insert(i + 4, new CodeInstruction(OpCodes.Conv_I4, (object)null));
i += 4;
}
}
return list;
}
public static float get_PLS_StorageMultiplierValue()
{
return MultiplierService.GetMultiplier("Station_PLS_Storage");
}
public static float get_ILS_StorageMultiplierValue()
{
return MultiplierService.GetMultiplier("Station_ILS_Storage");
}
private static int GetVanillaAdditionStorage(StationComponent station)
{
if (station == null || GameMain.history == null)
{
return 0;
}
if (station.isCollector)
{
return GameMain.history.localStationExtraStorage;
}
if (station.isVeinCollector)
{
return GameMain.history.localStationExtraStorage;
}
if (station.isStellar)
{
return GameMain.history.remoteStationExtraStorage;
}
return GameMain.history.localStationExtraStorage;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StationComponent), "RematchLocalPairs")]
public static void RematchLocalPairs_Postfix(StationComponent __instance, StationComponent[] stationPool)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: 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)
if (__instance.localPairs != null && __instance.localPairCount > 1)
{
Vector3 droneDock = __instance.droneDock;
Array.Sort(__instance.localPairs, 0, __instance.localPairCount, new LocalPairDistanceComparer(__instance.id, droneDock, stationPool));
}
}
public static bool IsExchangeStation(this ItemProto item)
{
if (item == null)
{
return false;
}
if (((Proto)item).ID < 9400 && (((Proto)item).name == null || (((Proto)item).name.IndexOf("Exchange Logistic Station", StringComparison.OrdinalIgnoreCase) < 0 && ((Proto)item).name.IndexOf("Matter", StringComparison.OrdinalIgnoreCase) < 0 && ((Proto)item).name.IndexOf("星际组装厂", StringComparison.OrdinalIgnoreCase) < 0)) && !(((Proto)item).Name == "星际组装厂") && !(((Proto)item).Name == "物资交换器") && !(((Proto)item).Name == "Interstellar Assembly") && ((Proto)item).Name.IndexOf("Exchange", StringComparison.OrdinalIgnoreCase) < 0)
{
return ((Proto)item).Name.IndexOf("组装", StringComparison.OrdinalIgnoreCase) >= 0;
}
return true;
}
private static ExtraShipState GetExtraShipState(StationComponent station)
{
if (station == null)
{
return null;
}
if (!_extraShipStates.TryGetValue(station, out var value))
{
value = new ExtraShipState(station.workShipDatas.Length);
_extraShipStates.Add(station, value);
for (int i = 0; i < Math.Min(64, value.IdleShips.Length); i++)
{
value.IdleShips[i] = (station.idleShipIndices & (ulong)(1L << i)) != 0;
value.WorkingShips[i] = (station.workShipIndices & (ulong)(1L << i)) != 0;
}
}
if (value.IdleShips.Length < station.workShipDatas.Length)
{
int num = station.workShipDatas.Length;
bool[] array = new bool[num];
bool[] array2 = new bool[num];
Array.Copy(value.IdleShips, array, value.IdleShips.Length);
Array.Copy(value.WorkingShips, array2, value.WorkingShips.Length);
for (int j = value.IdleShips.Length; j < num; j++)
{
array[j] = true;
}
value.IdleShips = array;
value.WorkingShips = array2;
}
return value;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(StationComponent), "IdleShipGetToWork")]
public static bool StationComponent_IdleShipGetToWork_Prefix(StationComponent __instance, int index)
{
ExtraShipState extraShipState = GetExtraShipState(__instance);
if (extraShipState != null && index >= 0 && index < extraShipState.IdleShips.Length)
{
extraShipState.IdleShips[index] = false;
extraShipState.WorkingShips[index] = true;
}
if (index < 64)
{
__instance.idleShipIndices &= (ulong)(~(1L << index));
__instance.workShipIndices |= (ulong)(1L << index);
}
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(StationComponent), "WorkShipBackToIdle")]
public static bool StationComponent_WorkShipBackToIdle_Prefix(StationComponent __instance, int index)
{
ExtraShipState extraShipState = GetExtraShipState(__instance);
if (extraShipState != null && index >= 0 && index < extraShipState.IdleShips.Length)
{
extraShipState.IdleShips[index] = true;
extraShipState.WorkingShips[index] = false;
}
if (index < 64)
{
__instance.idleShipIndices |= (ulong)(1L << index);
__instance.workShipIndices &= (ulong)(~(1L << index));
}
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(StationComponent), "AddIdleShip")]
public static bool StationComponent_AddIdleShip_Prefix(StationComponent __instance, int index)
{
ExtraShipState extraShipState = GetExtraShipState(__instance);
if (extraShipState != null && index >= 0 && index < extraShipState.IdleShips.Length)
{
extraShipState.IdleShips[index] = true;
extraShipState.WorkingShips[index] = false;
}
if (index < 64)
{
__instance.idleShipIndices |= (ulong)(1L << index);
}
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(StationComponent), "RemoveIdleShip")]
public static bool StationComponent_RemoveIdleShip_Prefix(StationComponent __instance, int index)
{
ExtraShipState extraShipState = GetExtraShipState(__instance);
if (extraShipState != null && index >= 0 && index < extraShipState.IdleShips.Length)
{
extraShipState.IdleShips[index] = false;
extraShipState.WorkingShips[index] = false;
}
if (index < 64)
{
__instance.idleShipIndices &= (ulong)(~(1L << index));
}
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(StationComponent), "HasWorkShipIndex")]
public static bool StationComponent_HasWorkShipIndex_Prefix(StationComponent __instance, int index, ref bool __result)
{
ExtraShipState extraShipState = GetExtraShipState(__instance);
if (extraShipState != null && index >= 0 && index < extraShipState.WorkingShips.Length)
{
__result = extraShipState.WorkingShips[index];
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(StationComponent), "HasIdleShipIndex")]
public static bool StationComponent_HasIdleShipIndex_Prefix(StationComponent __instance, int index, ref bool __result)
{
ExtraShipState extraShipState = GetExtraShipState(__instance);
if (extraShipState != null && index >= 0 && index < extraShipState.IdleShips.Length)
{
__result = extraShipState.IdleShips[index];
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(StationComponent), "HasShipIndex")]
public static bool StationComponent_HasShipIndex_Prefix(StationComponent __instance, int index, ref bool __result)
{
ExtraShipState extraShipState = GetExtraShipState(__instance);
if (extraShipState != null && index >= 0 && index < extraShipState.IdleShips.Length)
{
__result = extraShipState.IdleShips[index] || extraShipState.WorkingShips[index];
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(StationComponent), "ShipRenderersOnTick")]
public static bool StationComponent_ShipRenderersOnTick_Prefix(StationComponent __instance, AstroData[] astroPoses, ref VectorLF3 rPos, ref Quaternion rRot)
{
//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
//IL_01bb: 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)
ExtraShipState extraShipState = GetExtraShipState(__instance);
if (extraShipState == null)
{
return true;
}
int num = 0;
int renderShipCount = 0;
int num2 = __instance.workShipDatas.Length;
for (int i = 0; i < num2; i++)
{
if (extraShipState.IdleShips[i])
{
num++;
}
}
int num3 = __instance.idleShipCount - num;
if (num3 > 0)
{
for (int j = 0; j < num2; j++)
{
if (!extraShipState.IdleShips[j] && !extraShipState.WorkingShips[j])
{
StationComponent_AddIdleShip_Prefix(__instance, j);
num3--;
if (num3 == 0)
{
break;
}
}
}
}
else if (num3 < 0)
{
for (int num4 = num2 - 1; num4 >= 0; num4--)
{
if (extraShipState.IdleShips[num4])
{
StationComponent_RemoveIdleShip_Prefix(__instance, num4);
num3++;
if (num3 == 0)
{
break;
}
}
}
}
ref VectorLF3 uPos = ref astroPoses[__instance.planetId].uPos;
ref Quaternion uRot = ref astroPoses[__instance.planetId].uRot;
VectorLF3 val = default(VectorLF3);
((VectorLF3)(ref val))..ctor(0f, 0f, 0f);
Vector3 val2 = default(Vector3);
((Vector3)(ref val2))..ctor(0f, 0f, 0f);
Quaternion val3 = default(Quaternion);
((Quaternion)(ref val3))..ctor(0f, 0f, 0f, 1f);
for (int k = 0; k < num2 && k < __instance.shipRenderers.Length; k++)
{
ref ShipRenderingData reference = ref __instance.shipRenderers[k];
ref ShipUIRenderingData reference2 = ref __instance.shipUIRenderers[k];
if (extraShipState.IdleShips[k])
{
reference.gid = __instance.gid;
StationComponent.lpos2upos_ref(ref uPos, ref uRot, ref __instance.shipDiskPos[k], ref val);
Maths.QMultiply_ref(ref uRot, ref __instance.shipDiskRot[k], ref val3);
((ShipRenderingData)(ref reference)).SetPose(ref val, ref val3, ref rPos, ref rRot, ref val2, 0);
renderShipCount = k + 1;
reference.anim = Vector4.zero;
reference2.gid = 0;
}
else if (extraShipState.WorkingShips[k])
{
reference.gid = __instance.gid;
renderShipCount = k + 1;
reference2.gid = __instance.gid;
}
else
{
reference.gid = 0;
reference.anim = Vector4.zero;
reference2.gid = 0;
}
}
__instance.renderShipCount = renderShipCount;
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(StationComponent), "QueryIdleShip")]
public static bool StationComponent_QueryIdleShip_Prefix(StationComponent __instance, int qIdx, ref int __result)
{
ExtraShipState extraShipState = GetExtraShipState(__instance);
if (extraShipState == null)
{
return true;
}
int num = __instance.workShipDatas.Length;
for (int i = 0; i < num; i++)
{
int num2 = (qIdx + i) % num;
if (num2 < extraShipState.IdleShips.Length && extraShipState.IdleShips[num2])
{
__result = num2;
return false;
}
}
__result = -1;
return false;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StationComponent), "Import")]
public static void StationComponent_Import_ShipFix_Postfix(StationComponent __instance)
{
if (__instance == null)
{
return;
}
ExtraShipState extraShipState = GetExtraShipState(__instance);
if (extraShipState == null)
{
return;
}
for (int i = 0; i < extraShipState.IdleShips.Length; i++)
{
extraShipState.IdleShips[i] = true;
}
for (int j = 0; j < __instance.workShipCount; j++)
{
int shipIndex = __instance.workShipDatas[j].shipIndex;
if (shipIndex >= 0 && shipIndex < extraShipState.IdleShips.Length)
{
extraShipState.IdleShips[shipIndex] = false;
}
}
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(PlanetTransport), "GameTick")]
[HarmonyPatch(typeof(PlanetTransport), "RefreshStationTraffic")]
[HarmonyPatch(typeof(UITechTree), "RefreshDataValueText")]
[HarmonyPatch(typeof(ItemProto), "GetPropValue")]
[HarmonyPatch(typeof(UIPlayerDeliveryPanel), "_OnUpdate")]
[HarmonyPatch(typeof(DispenserComponent), "InternalTick")]
public static IEnumerable<CodeInstruction> CapacityTranspiler(IEnumerable<CodeInstruction> instructions)
{
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Expected O, but got Unknown
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Expected O, but got Unknown
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Expected O, but got Unknown
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
FieldInfo fieldInfo = AccessTools.Field(typeof(GameHistoryData), "logisticDroneCarries");
FieldInfo fieldInfo2 = AccessTools.Field(typeof(GameHistoryData), "logisticShipCarries");
FieldInfo fieldInfo3 = AccessTools.Field(typeof(GameHistoryData), "logisticCourierCarries");
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Ldfld)
{
if (list[i].operand as FieldInfo == fieldInfo)
{
list.Insert(i + 1, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(SpaciousStationsPlugin), "GetMultipliedDroneCarry", (Type[])null, (Type[])null)));
i++;
}
else if (list[i].operand as FieldInfo == fieldInfo2)
{
list.Insert(i + 1, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(SpaciousStationsPlugin), "GetMultipliedShipCarry", (Type[])null, (Type[])null)));
i++;
}
else if (list[i].operand as FieldInfo == fieldInfo3)
{
list.Insert(i + 1, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(SpaciousStationsPlugin), "GetMultipliedCourierCarry", (Type[])null, (Type[])null)));
i++;
}
}
}
return list;
}
}
public static class StationExtensions
{
public static void PatchDroneArray(this StationComponent station, int newCount)
{
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
if (station != null && station.workDroneDatas != null && station.workDroneDatas.Length < newCount)
{
int num = station.workDroneDatas.Length;
Array.Resize(ref station.workDroneDatas, newCount);
Array.Resize(ref station.workDroneOrders, newCount);
Array.Resize(ref station.droneDispatchStatus, newCount);
for (int i = num; i < newCount; i++)
{
station.workDroneDatas[i] = default(DroneData);
station.workDroneOrders[i] = default(LocalLogisticOrder);
station.droneDispatchStatus[i] = 1;
}
}
}
public static bool IsExchangeStation(this StationComponent station)
{
if (station == null || station.planetId <= 0)
{
return false;
}
GalaxyData galaxy = GameMain.galaxy;
PlanetFactory val = ((galaxy == null) ? null : galaxy.PlanetById(station.planetId)?.factory);
if (val == null || station.entityId <= 0 || station.entityId >= val.entityPool.Length)
{
return false;
}
int protoId = val.entityPool[station.entityId].protoId;
return ((ProtoSet<ItemProto>)(object)LDB.items).Select(protoId).IsExchangeStation();
}
public static void PatchShipArray(this StationComponent station, int newCount)
{
//IL_007e: 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_00a2: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
if (station == null || station.workShipDatas == null || station.workShipDatas.Length >= newCount)
{
return;
}
int num = station.workShipDatas.Length;
Array.Resize(ref station.workShipDatas, newCount);
Array.Resize(ref station.workShipOrders, newCount);
Array.Resize(ref station.shipRenderers, newCount);
Array.Resize(ref station.shipUIRenderers, newCount);
Array.Resize(ref station.shipDiskPos, newCount);
Array.Resize(ref station.shipDiskRot, newCount);
for (int i = num; i < newCount; i++)
{
station.workShipDatas[i] = default(ShipData);
station.workShipOrders[i] = default(RemoteLogisticOrder);
station.shipRenderers[i] = default(ShipRenderingData);
station.shipUIRenderers[i] = default(ShipUIRenderingData);
if (num > 0)
{
station.shipDiskPos[i] = station.shipDiskPos[i % num];
station.shipDiskRot[i] = station.shipDiskRot[i % num];
}
else
{
station.shipDiskPos[i] = Vector3.zero;
station.shipDiskRot[i] = Quaternion.identity;
}
}
}
}
[HarmonyPatch]
public static class MMS_StarAssembly_Patch
{
[CompilerGenerated]
private sealed class <Transpiler>d__2 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IEnumerator, IDisposable
{
private int <>1__state;
private CodeInstruction <>2__current;
private int <>l__initialThreadId;
private IEnumerable<CodeInstruction> instructions;
public IEnumerable<CodeInstruction> <>3__instructions;
private int <newMax>5__2;
private int <newSoft>5__3;
private IEnumerator<CodeInstruction> <>7__wrap3;
CodeInstruction IEnumerator<CodeInstruction>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <Transpiler>d__2(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if (num == -3 || num == 1)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<>7__wrap3 = null;
<>1__state = -2;
}
private bool MoveNext()
{
try
{
switch (<>1__state)
{
default:
return false;
case 0:
{
<>1__state = -1;
float value = SpaciousStationsPlugin.EXC_InternalsMultiplier.Value;
<newMax>5__2 = (int)(99999f * value);
<newSoft>5__3 = (int)(10000f * value);
<>7__wrap3 = instructions.GetEnumerator();
<>1__state = -3;
break;
}
case 1:
<>1__state = -3;
break;
}
if (<>7__wrap3.MoveNext())
{
CodeInstruction current = <>7__wrap3.Current;
if (current.opcode == OpCodes.Ldc_I4 && (int)current.operand == 99999)
{
current.operand = <newMax>5__2;
}
else if (current.opcode == OpCodes.Ldc_I4 && (int)current.operand == 10000)
{
current.operand = <newSoft>5__3;
}
<>2__current = current;
<>1__state = 1;
return true;
}
<>m__Finally1();
<>7__wrap3 = null;
return false;
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
private void <>m__Finally1()
{
<>1__state = -1;
if (<>7__wrap3 != null)
{
<>7__wrap3.Dispose();
}
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
[DebuggerHidden]
IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
{
<Transpiler>d__2 <Transpiler>d__;
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
<Transpiler>d__ = this;
}
else
{
<Transpiler>d__ = new <Transpiler>d__2(0);
}
<Transpiler>d__.instructions = <>3__instructions;
return <Transpiler>d__;
}
[DebuggerHidden]
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
}
}
[HarmonyPrepare]
public static bool Prepare()
{
return AccessTools.TypeByName("MoreMegaStructure.StarAssembly") != null;
}
[HarmonyTargetMethod]
public static MethodBase TargetMethod()
{
return AccessTools.Method("MoreMegaStructure.StarAssembly:InternalUpdate", (Type[])null, (Type[])null);
}
[IteratorStateMachine(typeof(<Transpiler>d__2))]
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <Transpiler>d__2(-2)
{
<>3__instructions = instructions
};
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.Valoneu.SpaciousStations";
public const string PLUGIN_NAME = "SpaciousStations";
public const string PLUGIN_VERSION = "1.2.3";
}
}