using System;
using System.Collections.Generic;
using System.Diagnostics;
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 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.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+6c948015323632b3a602764b996a91e84476f4a0")]
[assembly: AssemblyProduct("DysonSphereMods")]
[assembly: AssemblyTitle("SpaciousStations")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 SpaciousStations
{
[BepInPlugin("com.Valoneu.SpaciousStations", "SpaciousStations", "1.0.3")]
[BepInProcess("DSPGAME.exe")]
public class SpaciousStationsPlugin : BaseUnityPlugin
{
public const string MOD_GUID = "com.Valoneu.SpaciousStations";
public const string MOD_NAME = "SpaciousStations";
public const string MOD_VERSION = "1.0.3";
public static ConfigEntry<float> DroneMultiplier;
public static ConfigEntry<float> ShipMultiplier;
public static ConfigEntry<float> StorageMultiplier;
public static ConfigEntry<float> ChargeMultiplier;
public static ConfigEntry<float> EnergyMultiplier;
private void Awake()
{
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
DroneMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "DroneMultiplier", 2f, "Multiplies max number of drones in a station.");
ShipMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ShipMultiplier", 2f, "Multiplies max number of ships in a station.");
StorageMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "StorageMultiplier", 2f, "Multiplies maximum amount of items in a station.");
ChargeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ChargeMultiplier", 2f, "Multiplies station's charge power.");
EnergyMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "EnergyMultiplier", 2f, "Multiplies station's max energy storage.");
Log.Init(((BaseUnityPlugin)this).Logger);
new Harmony("com.Valoneu.SpaciousStations").PatchAll(typeof(StationPatch));
Log.Info((object)"SpaciousStations v1.0.3 loaded!");
}
}
public static class StationPatch
{
private struct ProtoValues
{
public int DroneCount;
public int ShipCount;
public int ItemCount;
public long EnergyMax;
public long EnergyPerTick;
}
private static Dictionary<int, ProtoValues> _originalValues = new Dictionary<int, ProtoValues>();
[HarmonyPostfix]
[HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")]
public static void VFPreload_InvokeOnLoadWorkEnded_Postfix()
{
ApplyToPrototypes();
}
public static void ApplyToPrototypes()
{
ItemProto[] dataArray;
if (_originalValues.Count == 0)
{
dataArray = ((ProtoSet<ItemProto>)(object)LDB.items).dataArray;
foreach (ItemProto val in dataArray)
{
if (val.prefabDesc != null && val.prefabDesc.isStation)
{
_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
};
}
}
}
dataArray = ((ProtoSet<ItemProto>)(object)LDB.items).dataArray;
foreach (ItemProto val2 in dataArray)
{
if (_originalValues.TryGetValue(((Proto)val2).ID, out var value))
{
val2.prefabDesc.stationMaxDroneCount = (int)((float)value.DroneCount * SpaciousStationsPlugin.DroneMultiplier.Value);
val2.prefabDesc.stationMaxShipCount = (int)((float)value.ShipCount * SpaciousStationsPlugin.ShipMultiplier.Value);
val2.prefabDesc.stationMaxItemCount = (int)((float)value.ItemCount * SpaciousStationsPlugin.StorageMultiplier.Value);
val2.prefabDesc.stationMaxEnergyAcc = (long)((float)value.EnergyMax * SpaciousStationsPlugin.EnergyMultiplier.Value);
if (!val2.prefabDesc.isCollectStation)
{
val2.prefabDesc.workEnergyPerTick = (long)((float)value.EnergyPerTick * SpaciousStationsPlugin.ChargeMultiplier.Value);
}
}
}
ModelProto[] dataArray2 = ((ProtoSet<ModelProto>)(object)LDB.models).dataArray;
foreach (ModelProto val3 in dataArray2)
{
if (val3.prefabDesc == null || !val3.prefabDesc.isStation)
{
continue;
}
ItemProto val4 = null;
dataArray = ((ProtoSet<ItemProto>)(object)LDB.items).dataArray;
foreach (ItemProto val5 in dataArray)
{
if (val5.ModelIndex == ((Proto)val3).ID)
{
val4 = val5;
break;
}
}
if (val4 != null && _originalValues.TryGetValue(((Proto)val4).ID, out var value2))
{
val3.prefabDesc.stationMaxDroneCount = (int)((float)value2.DroneCount * SpaciousStationsPlugin.DroneMultiplier.Value);
val3.prefabDesc.stationMaxShipCount = (int)((float)value2.ShipCount * SpaciousStationsPlugin.ShipMultiplier.Value);
val3.prefabDesc.stationMaxItemCount = (int)((float)value2.ItemCount * SpaciousStationsPlugin.StorageMultiplier.Value);
val3.prefabDesc.stationMaxEnergyAcc = (long)((float)value2.EnergyMax * SpaciousStationsPlugin.EnergyMultiplier.Value);
if (!val3.prefabDesc.isCollectStation)
{
val3.prefabDesc.workEnergyPerTick = (long)((float)value2.EnergyPerTick * SpaciousStationsPlugin.ChargeMultiplier.Value);
}
}
}
Log.Info((object)"Applied multipliers to station prototypes.");
}
[HarmonyPostfix]
[HarmonyPatch(typeof(GameMain), "Begin")]
public static void GameMain_Begin_Postfix()
{
ApplyToExistingStations();
}
[HarmonyPrefix]
[HarmonyPatch(typeof(StationComponent), "Init")]
public static void StationComponent_Init_Prefix(ref int _extraStorage)
{
_extraStorage = (int)((float)_extraStorage * SpaciousStationsPlugin.StorageMultiplier.Value);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIStationStorage), "GetAdditionStorage")]
public static void UIStationStorage_GetAdditionStorage_Postfix(ref int __result)
{
__result = (int)((float)__result * SpaciousStationsPlugin.StorageMultiplier.Value);
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(PlanetTransport), "SetStationStorage")]
public static IEnumerable<CodeInstruction> PlanetTransport_SetStationStorage_Transpiler(IEnumerable<CodeInstruction> instructions)
{
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Expected O, but got Unknown
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Expected O, but got Unknown
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Expected O, but got Unknown
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Expected O, but got Unknown
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Ldfld && list[i].operand != null && list[i].operand.ToString().Contains("ExtraStorage"))
{
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_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_StorageMultiplierValue()
{
return SpaciousStationsPlugin.StorageMultiplier.Value;
}
public static void ApplyToExistingStations()
{
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: 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_01c0: Unknown result type (might be due to invalid IL or missing references)
//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
//IL_020e: Unknown result type (might be due to invalid IL or missing references)
//IL_0215: Unknown result type (might be due to invalid IL or missing references)
//IL_0223: Unknown result type (might be due to invalid IL or missing references)
//IL_0228: Unknown result type (might be due to invalid IL or missing references)
//IL_022d: Unknown result type (might be due to invalid IL or missing references)
//IL_0232: Unknown result type (might be due to invalid IL or missing references)
if (GameMain.data == null)
{
return;
}
PlanetFactory[] factories = GameMain.data.factories;
foreach (PlanetFactory val in factories)
{
if (val == null || val.transport == null)
{
continue;
}
StationComponent[] stationPool = val.transport.stationPool;
foreach (StationComponent val2 in stationPool)
{
if (val2 == null || val2.id <= 0)
{
continue;
}
ItemProto val3 = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)val.entityPool[val2.entityId].protoId);
if (val3 == null)
{
continue;
}
PrefabDesc prefabDesc = val3.prefabDesc;
val2.PatchDroneArray(prefabDesc.stationMaxDroneCount);
if (val2.workShipDatas != null && val2.workShipDatas.Length != prefabDesc.stationMaxShipCount)
{
int num = val2.workShipDatas.Length;
int stationMaxShipCount = prefabDesc.stationMaxShipCount;
val2.workShipDatas = ResizeArray(val2.workShipDatas, stationMaxShipCount);
val2.workShipOrders = ResizeArray(val2.workShipOrders, stationMaxShipCount);
val2.shipRenderers = ResizeArray(val2.shipRenderers, stationMaxShipCount);
val2.shipUIRenderers = ResizeArray(val2.shipUIRenderers, stationMaxShipCount);
val2.shipDiskPos = ResizeArray(val2.shipDiskPos, stationMaxShipCount);
val2.shipDiskRot = ResizeArray(val2.shipDiskRot, stationMaxShipCount);
if (val2.isStellar && stationMaxShipCount > num)
{
for (int k = 0; k < stationMaxShipCount; k++)
{
val2.shipDiskRot[k] = Quaternion.Euler(0f, 360f / (float)stationMaxShipCount * (float)k, 0f);
val2.shipDiskPos[k] = val2.shipDiskRot[k] * new Vector3(0f, 0f, 11.5f);
}
for (int l = 0; l < stationMaxShipCount; l++)
{
val2.shipDiskRot[l] = val2.shipDockRot * val2.shipDiskRot[l];
val2.shipDiskPos[l] = val2.shipDockPos + val2.shipDockRot * val2.shipDiskPos[l];
}
}
}
val2.energyMax = prefabDesc.stationMaxEnergyAcc;
if (val2.pcId > 0 && val.powerSystem != null && val2.pcId < val.powerSystem.consumerCursor)
{
val.powerSystem.consumerPool[val2.pcId].workEnergyPerTick = prefabDesc.workEnergyPerTick;
}
int additionStorage = GetAdditionStorage(val2);
if (val2.storage == null)
{
continue;
}
for (int m = 0; m < val2.storage.Length; m++)
{
if (val2.storage[m].itemId > 0)
{
val2.storage[m].max = prefabDesc.stationMaxItemCount + additionStorage;
}
}
}
}
}
private static T[] ResizeArray<T>(T[] array, int newSize)
{
if (array == null)
{
return new T[newSize];
}
if (array.Length == newSize)
{
return array;
}
T[] array2 = new T[newSize];
Array.Copy(array, array2, Math.Min(array.Length, newSize));
return array2;
}
private static int GetAdditionStorage(StationComponent station)
{
if (station == null || GameMain.history == null)
{
return 0;
}
return (int)((float)(station.isCollector ? GameMain.history.localStationExtraStorage : (station.isVeinCollector ? GameMain.history.localStationExtraStorage : ((!station.isStellar) ? GameMain.history.localStationExtraStorage : GameMain.history.remoteStationExtraStorage))) * SpaciousStationsPlugin.StorageMultiplier.Value);
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.Valoneu.SpaciousStations";
public const string PLUGIN_NAME = "SpaciousStations";
public const string PLUGIN_VERSION = "1.0.3";
}
}