Decompiled source of GigaStationsUpdated v2.3.8

GigaStations.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CommonAPI;
using CommonAPI.Systems;
using CommonAPI.Systems.ModLocalization;
using HarmonyLib;
using NebulaAPI;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("GigaStations")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GigaStations")]
[assembly: AssemblyTitle("GigaStations")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace GigaStations;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("org.kremnev8.plugin.GigaStationsUpdated", "GigaStationsUpdated", "2.3.7")]
[CommonAPISubmoduleDependency(new string[] { "ProtoRegistry", "UtilSystem", "LocalizationModule" })]
public class GigaStationsPlugin : BaseUnityPlugin
{
	public const string MODGUID = "org.kremnev8.plugin.GigaStationsUpdated";

	public const string MODNAME = "GigaStationsUpdated";

	public const string VERSION = "2.3.7";

	public const string LDB_TOOL_GUID = "me.xiaoye97.plugin.Dyson.LDBTool";

	public const string WARPERS_MOD_GUID = "ShadowAngel.DSP.DistributeSpaceWarper";

	public static ManualLogSource logger;

	public static ItemProto pls;

	public static ItemProto ils;

	public static ItemProto collector;

	public static ModelProto plsModel;

	public static ModelProto ilsModel;

	public static ModelProto collectorModel;

	public static ResourceData resource;

	public static int gridXCount { get; set; } = 1;


	public static int gridYCount { get; set; } = 5;


	public static Color stationColor { get; set; } = new Color(0.3726f, 0.8f, 1f, 1f);


	public static int ilsMaxStorage { get; set; } = 30000;


	public static int ilsMaxWarps { get; set; } = 150;


	public static int ilsMaxVessels { get; set; } = 30;


	public static int ilsMaxDrones { get; set; } = 150;


	public static long ilsMaxAcuGJ { get; set; } = 50L;


	public static int ilsMaxSlots { get; set; } = 12;


	public static int plsMaxStorage { get; set; } = 15000;


	public static int plsMaxDrones { get; set; } = 150;


	public static long plsMaxAcuMJ { get; set; } = 500L;


	public static int plsMaxSlots { get; set; } = 12;


	public static int colMaxStorage { get; set; } = 15000;


	public static int colSpeedMultiplier { get; set; } = 3;


	public static int vesselCapacityMultiplier { get; set; } = 3;


	public static int droneCapacityMultiplier { get; set; } = 3;


	private void Awake()
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Expected O, but got Unknown
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Expected O, but got Unknown
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Expected O, but got Unknown
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Expected O, but got Unknown
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Expected O, but got Unknown
		//IL_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_024a: Expected O, but got Unknown
		//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b2: Expected O, but got Unknown
		//IL_067c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0682: Expected O, but got Unknown
		logger = ((BaseUnityPlugin)this).Logger;
		string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		resource = new ResourceData("GigaStationsUpdated", "gigastations", directoryName);
		resource.LoadAssetBundle("gigastations");
		ProtoRegistry.AddResource(resource);
		gridXCount = ((BaseUnityPlugin)this).Config.Bind<int>("-|0|- General", "-| 1 Grid X Max. Count", 1, new ConfigDescription("Amount of slots visible horizontally.\nIf this value is bigger than 1, layout will form a grid", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 3), Array.Empty<object>())).Value;
		gridYCount = ((BaseUnityPlugin)this).Config.Bind<int>("-|0|- General", "-| 2 Grid Y Max. Count", 5, new ConfigDescription("Amount of slots visible vertically", (AcceptableValueBase)(object)new AcceptableValueRange<int>(3, 12), Array.Empty<object>())).Value;
		stationColor = ((BaseUnityPlugin)this).Config.Bind<Color>("-|0|- General", "-| 3 Station Color", new Color(0.3726f, 0.8f, 1f, 1f), "Color tint of giga stations").Value;
		ilsMaxSlots = ((BaseUnityPlugin)this).Config.Bind<int>("-|1|- ILS", "-| 1 Max. Item Slots", 12, new ConfigDescription("The maximum Item Slots the Station can have.\nVanilla: 5", (AcceptableValueBase)(object)new AcceptableValueRange<int>(5, 12), Array.Empty<object>())).Value;
		ilsMaxStorage = ((BaseUnityPlugin)this).Config.Bind<int>("-|1|- ILS", "-| 2 Max. Storage", 30000, "The maximum Storage capacity per Item-Slot.\nVanilla: 10000").Value;
		ilsMaxVessels = ((BaseUnityPlugin)this).Config.Bind<int>("-|1|- ILS", "-| 3 Max. Vessels", 30, new ConfigDescription("The maximum Logistic Vessels amount.\nVanilla: 10", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 30), Array.Empty<object>())).Value;
		ilsMaxDrones = ((BaseUnityPlugin)this).Config.Bind<int>("-|1|- ILS", "-| 4 Max. Drones", 150, new ConfigDescription("The maximum Logistic Drones amount.\nVanilla: 50", (AcceptableValueBase)(object)new AcceptableValueRange<int>(50, 150), Array.Empty<object>())).Value;
		ilsMaxAcuGJ = ((BaseUnityPlugin)this).Config.Bind<int>("-|1|- ILS", "-| 5 Max. Accu Capacity (GJ)", 50, "The Stations maximum Accumulator Capacity in GJ.\nVanilla: 12 GJ").Value;
		ilsMaxWarps = ((BaseUnityPlugin)this).Config.Bind<int>("-|1|- ILS", "-| 6 Max. Warps", 150, "The maximum Warp Cells amount.\nVanilla: 50").Value;
		plsMaxSlots = ((BaseUnityPlugin)this).Config.Bind<int>("-|2|- PLS", "-| 1 Max. Item Slots", 12, new ConfigDescription("The maximum Item Slots the Station can have.\nVanilla: 3", (AcceptableValueBase)(object)new AcceptableValueRange<int>(3, 12), Array.Empty<object>())).Value;
		plsMaxStorage = ((BaseUnityPlugin)this).Config.Bind<int>("-|2|- PLS", "-| 2 Max. Storage", 15000, "The maximum Storage capacity per Item-Slot.\nVanilla: 5000").Value;
		plsMaxDrones = ((BaseUnityPlugin)this).Config.Bind<int>("-|2|- PLS", "-| 3 Max. Drones", 150, new ConfigDescription("The maximum Logistic Drones amount.\nVanilla: 50", (AcceptableValueBase)(object)new AcceptableValueRange<int>(50, 150), Array.Empty<object>())).Value;
		plsMaxAcuMJ = ((BaseUnityPlugin)this).Config.Bind<int>("-|2|- PLS", "-| 4 Max. Accu Capacity (GJ)", 500, "The Stations maximum Accumulator Capacity in MJ.\nVanilla: 180 MJ").Value;
		colSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<int>("-|3|- Collector", "-| 1 Collect Speed Multiplier", 3, "Multiplier for the Orbital Collectors Collection-Speed.\nVanilla: 1").Value;
		colMaxStorage = ((BaseUnityPlugin)this).Config.Bind<int>("-|3|- Collector", "-| 2 Max. Storage", 15000, "The maximum Storage capacity per Item-Slot.\nVanilla: 5000").Value;
		vesselCapacityMultiplier = ((BaseUnityPlugin)this).Config.Bind<int>("-|4|- Vessel", "-| 1 Max. Capacity", 3, "Vessel Capacity Multiplier\n1 == 1000 Vessel Capacity at max Level").Value;
		droneCapacityMultiplier = ((BaseUnityPlugin)this).Config.Bind<int>("-|5|- Drone", "-| 1 Max. Capacity", 3, "Drone Capacity Multiplier\n1 == 100 Drone Capacity at max Level").Value;
		LocalizationModule.RegisterTranslation("PLS_Name", "Planetary Giga Station");
		LocalizationModule.RegisterTranslation("PLS_Desc", "Has more Slots, Capacity, etc. than a usual PLS.");
		LocalizationModule.RegisterTranslation("ILS_Name", "Interstellar Giga Station");
		LocalizationModule.RegisterTranslation("ILS_Desc", "Has more Slots, Capacity, etc. than a usual ILS.");
		LocalizationModule.RegisterTranslation("Collector_Name", "Orbital Giga Collector");
		LocalizationModule.RegisterTranslation("Collector_Desc", $"Has more Capacity and collects {colSpeedMultiplier}x faster than a usual Collector.");
		LocalizationModule.RegisterTranslation("ModificationWarn", "  - [GigaStationsUpdated] Replaced {0} buildings");
		LocalizationModule.RegisterTranslation("CantDowngradeWarn", "Downgrading logistic station is not possible!");
		pls = ProtoRegistry.RegisterItem(2110, "PLS_Name", "PLS_Desc", "assets/gigastations/texture2d/icon_pls", 2701);
		ils = ProtoRegistry.RegisterItem(2111, "ILS_Name", "ILS_Desc", "assets/gigastations/texture2d/icon_ils", 2702);
		collector = ProtoRegistry.RegisterItem(2112, "Collector_Name", "Collector_Desc", "assets/gigastations/texture2d/icon_collector", 2703);
		collector.BuildInGas = true;
		ProtoRegistry.RegisterRecipe(410, (ERecipeType)4, 2400, new int[5] { 2103, 1103, 1106, 1303, 1206 }, new int[5] { 1, 40, 40, 40, 20 }, new int[1] { ((Proto)pls).ID }, new int[1] { 1 }, "PGS_Desc", 1604);
		ProtoRegistry.RegisterRecipe(411, (ERecipeType)4, 3600, new int[3] { 2110, 1107, 1206 }, new int[3] { 1, 40, 20 }, new int[1] { ((Proto)ils).ID }, new int[1] { 1 }, "ILS_Desc", 1605);
		ProtoRegistry.RegisterRecipe(412, (ERecipeType)4, 3600, new int[4] { 2111, 1205, 1406, 2207 }, new int[4] { 1, 50, 20, 20 }, new int[1] { ((Proto)collector).ID }, new int[1] { 1 }, "Collector_Desc", 1606);
		plsModel = ProtoRegistry.RegisterModel(460, pls, "Entities/Prefabs/logistic-station", (Material[])null, new int[5] { 24, 38, 12, 10, 1 }, 606, 2, new int[2] { 2103, 0 });
		ilsModel = ProtoRegistry.RegisterModel(461, ils, "Entities/Prefabs/interstellar-logistic-station", (Material[])null, new int[5] { 24, 38, 12, 10, 1 }, 607, 2, new int[2] { 2104, 0 });
		collectorModel = ProtoRegistry.RegisterModel(462, collector, "Entities/Prefabs/orbital-collector", (Material[])null, new int[4] { 18, 11, 32, 1 }, 608, 2, new int[2] { 2105, 0 });
		ProtoRegistry.onLoadingFinished += AddGigaPLS;
		ProtoRegistry.onLoadingFinished += AddGigaILS;
		ProtoRegistry.onLoadingFinished += AddGigaCollector;
		Harmony val = new Harmony("org.kremnev8.plugin.GigaStationsUpdated");
		val.PatchAll(typeof(StationEditPatch));
		val.PatchAll(typeof(SaveFixPatch));
		val.PatchAll(typeof(StationUpgradePatch));
		val.PatchAll(typeof(UIStationWindowPatch));
		val.PatchAll(typeof(BlueprintBuilding_Patch));
		val.PatchAll(typeof(UIEntityBriefInfo_Patch));
		foreach (KeyValuePair<string, PluginInfo> pluginInfo in Chainloader.PluginInfos)
		{
			if (!(pluginInfo.Value.Metadata.GUID != "ShadowAngel.DSP.DistributeSpaceWarper"))
			{
				((ConfigEntry<bool>)(object)pluginInfo.Value.Instance.Config["General", "ShowWarperSlot"]).Value = true;
				logger.LogInfo((object)"Overriding Distribute Space Warpers config: ShowWarperSlot = true");
				break;
			}
		}
		UtilSystem.AddLoadMessageHandler((Func<string>)SaveFixPatch.GetFixMessage);
		logger.LogInfo((object)"GigaStations is initialized!");
	}

	private void AddGigaPLS()
	{
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		ColliderData[] buildColliders = plsModel.prefabDesc.buildColliders;
		logger.LogInfo((object)$"PLS build collider is null: {buildColliders == null}, length: {((buildColliders != null) ? buildColliders.Length : 0)}");
		plsModel.prefabDesc.workEnergyPerTick = 3333334L;
		plsModel.prefabDesc.stationMaxItemCount = plsMaxStorage;
		plsModel.prefabDesc.stationMaxItemKinds = plsMaxSlots;
		plsModel.prefabDesc.stationMaxDroneCount = plsMaxDrones;
		plsModel.prefabDesc.stationMaxEnergyAcc = Convert.ToInt64(plsMaxAcuMJ * 1000000);
		Material val = Object.Instantiate<Material>(plsModel.prefabDesc.lodMaterials[0][0]);
		val.color = stationColor;
		plsModel.prefabDesc.lodMaterials[0][0] = val;
	}

	private void AddGigaILS()
	{
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		ColliderData[] buildColliders = ilsModel.prefabDesc.buildColliders;
		logger.LogInfo((object)$"ILS build collider is null: {buildColliders == null}, length: {((buildColliders != null) ? buildColliders.Length : 0)}");
		ilsModel.prefabDesc.workEnergyPerTick = 3333334L;
		ilsModel.prefabDesc.stationMaxItemCount = ilsMaxStorage;
		ilsModel.prefabDesc.stationMaxItemKinds = ilsMaxSlots;
		ilsModel.prefabDesc.stationMaxDroneCount = ilsMaxDrones;
		ilsModel.prefabDesc.stationMaxShipCount = ilsMaxVessels;
		ilsModel.prefabDesc.stationMaxEnergyAcc = Convert.ToInt64(ilsMaxAcuGJ * 1000000000);
		Material val = Object.Instantiate<Material>(ilsModel.prefabDesc.lodMaterials[0][0]);
		val.color = stationColor;
		ilsModel.prefabDesc.lodMaterials[0][0] = val;
	}

	private void AddGigaCollector()
	{
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(2105);
		collectorModel.prefabDesc.stationMaxItemCount = colMaxStorage;
		collectorModel.prefabDesc.stationCollectSpeed = val.prefabDesc.stationCollectSpeed * colSpeedMultiplier;
		PrefabDesc prefabDesc = collectorModel.prefabDesc;
		prefabDesc.workEnergyPerTick /= ((val.prefabDesc.workEnergyPerTick / colSpeedMultiplier >= 0) ? colSpeedMultiplier : val.prefabDesc.workEnergyPerTick);
		Material val2 = Object.Instantiate<Material>(collectorModel.prefabDesc.lodMaterials[0][0]);
		val2.color = stationColor;
		collectorModel.prefabDesc.lodMaterials[0][0] = val2;
	}
}
[BepInPlugin("org.kremnev8.plugin.GigaStationsNebulaCompat", "Giga Stations Nebula Compatibility", "2.3.7")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class NebulaCompat : BaseUnityPlugin
{
	public const string MOD_GUID = "org.kremnev8.plugin.GigaStationsNebulaCompat";

	public const string MOD_NAME = "Giga Stations Nebula Compatibility";

	private void Awake()
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Expected O, but got Unknown
		if (NebulaModAPI.NebulaIsInstalled)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Patching NebulaWorld!");
			Harmony val = new Harmony("org.kremnev8.plugin.GigaStationsNebulaCompat");
			MethodInfo method = AccessTools.TypeByName("NebulaWorld.Logistics.StationUIManager").GetMethod("UpdateSettingsUI", AccessTools.all);
			if (method == null)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Error: Not found NebulaWorld.Logistics.StationUIManager. There might be issues!");
				return;
			}
			MethodInfo method2 = typeof(NebulaCompatPatches).GetMethod("Replace10With1Transpiler");
			val.Patch((MethodBase)method, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null);
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Success! Nebula Compat is ready!");
	}
}
public static class NebulaCompatPatches
{
	public static IEnumerable<CodeInstruction> Replace10With1Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0002: 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_0035: Expected O, but got Unknown
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Expected O, but got Unknown
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Expected O, but got Unknown
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Expected O, but got Unknown
		CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(StationComponent), "deliveryDrones"), (string)null)
		}).MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction instr) => instr.opcode == OpCodes.Ldc_R4 && Mathf.Approximately((float)instr.operand, 10f)), (string)null)
		}).SetOperandAndAdvance((object)1f);
		val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(StationComponent), "deliveryShips"), (string)null)
		}).MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction instr) => instr.opcode == OpCodes.Ldc_R4 && Mathf.Approximately((float)instr.operand, 10f)), (string)null)
		}).SetOperandAndAdvance((object)1f);
		return val.InstructionEnumeration();
	}
}
[HarmonyPatch]
public static class BlueprintBuilding_Patch
{
	[HarmonyPatch(typeof(BlueprintBuilding), "Import")]
	[HarmonyPostfix]
	public static void UpdateBlueprintData(BlueprintBuilding __instance)
	{
		if (__instance.itemId == ((Proto)GigaStationsPlugin.ils).ID || __instance.itemId == ((Proto)GigaStationsPlugin.pls).ID || __instance.itemId == ((Proto)GigaStationsPlugin.collector).ID)
		{
			ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)__instance.itemId);
			__instance.modelIndex = (short)val.prefabDesc.modelIndex;
		}
	}
}
[HarmonyPatch]
public static class SaveFixPatch
{
	public static int updateCounter;

	[HarmonyPatch(typeof(EntityData), "Import")]
	[HarmonyPostfix]
	public static void Postfix(ref EntityData __instance)
	{
		int protoId = __instance.protoId;
		int modelIndex = __instance.modelIndex;
		if (protoId == ((Proto)GigaStationsPlugin.pls).ID)
		{
			if (modelIndex != ((Proto)GigaStationsPlugin.plsModel).ID)
			{
				__instance.modelIndex = (short)((Proto)GigaStationsPlugin.plsModel).ID;
				updateCounter++;
			}
		}
		else if (protoId == ((Proto)GigaStationsPlugin.ils).ID)
		{
			if (modelIndex != ((Proto)GigaStationsPlugin.ilsModel).ID)
			{
				__instance.modelIndex = (short)((Proto)GigaStationsPlugin.ilsModel).ID;
				updateCounter++;
			}
		}
		else if (protoId == ((Proto)GigaStationsPlugin.collector).ID && modelIndex != ((Proto)GigaStationsPlugin.collectorModel).ID)
		{
			__instance.modelIndex = (short)((Proto)GigaStationsPlugin.collectorModel).ID;
			updateCounter++;
		}
	}

	internal static string GetFixMessage()
	{
		if (updateCounter <= 0)
		{
			return "";
		}
		return string.Format(Localization.Translate("ModificationWarn"), updateCounter);
	}
}
[HarmonyPatch]
public static class StationEditPatch
{
	public delegate void RefAction<in T1, T2>(T1 arg, ref T2 arg2);

	private static readonly Dictionary<OpCode, OpCode> storeToLoad = new Dictionary<OpCode, OpCode>
	{
		{
			OpCodes.Stloc_0,
			OpCodes.Ldloc_0
		},
		{
			OpCodes.Stloc_1,
			OpCodes.Ldloc_1
		},
		{
			OpCodes.Stloc_2,
			OpCodes.Ldloc_2
		},
		{
			OpCodes.Stloc_3,
			OpCodes.Ldloc_3
		},
		{
			OpCodes.Stloc,
			OpCodes.Ldloc
		},
		{
			OpCodes.Stloc_S,
			OpCodes.Ldloc_S
		}
	};

	[HarmonyPostfix]
	[HarmonyPatch(typeof(UIRoot), "OnGameMainObjectCreated")]
	public static void OnGameMainObjectCreatedPostfix(UIRoot __instance)
	{
		CalculateCarrierCapacity();
	}

	public static CodeMatcher MoveToLabel(this CodeMatcher matcher, Label label)
	{
		while (!matcher.Labels.Contains(label))
		{
			matcher.Advance(1);
		}
		return matcher;
	}

	public static OpCode ToLoad(this OpCode opCode)
	{
		if (storeToLoad.Keys.Contains(opCode))
		{
			return storeToLoad[opCode];
		}
		throw new ArgumentException("Can't convert instruction " + opCode.ToString() + " to a load instruction!");
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(GameHistoryData), "UnlockTechFunction")]
	public static IEnumerable<CodeInstruction> MultiplyTechValues(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Expected O, but got Unknown
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Expected O, but got Unknown
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Expected O, but got Unknown
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Expected O, but got Unknown
		CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((OpCode?)OpCodes.Switch, (object)null, (string)null)
		});
		Label[] array = (Label[])val.Operand;
		val.MoveToLabel(array[17]).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((OpCode?)OpCodes.Add, (object)null, (string)null)
		}).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate<Func<int>>((Func<int>)(() => GigaStationsPlugin.droneCapacityMultiplier)) })
			.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
			{
				new CodeInstruction(OpCodes.Mul, (object)null)
			});
		val.MoveToLabel(array[18]).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((OpCode?)OpCodes.Add, (object)null, (string)null)
		}).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate<Func<int>>((Func<int>)(() => GigaStationsPlugin.vesselCapacityMultiplier)) })
			.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
			{
				new CodeInstruction(OpCodes.Mul, (object)null)
			});
		return val.InstructionEnumeration();
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(TechProto), "UnlockFunctionText")]
	public static IEnumerable<CodeInstruction> MultiplyUnlockText(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0002: 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_0035: Expected O, but got Unknown
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Expected O, but got Unknown
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Expected O, but got Unknown
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Expected O, but got Unknown
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Expected O, but got Unknown
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Expected O, but got Unknown
		CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(TechProto), "UnlockFunctions"), (string)null)
		}).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction instr) => CodeInstructionExtensions.IsStloc(instr, (LocalBuilder)null)), (string)null)
		});
		OpCode opCode = val.Opcode.ToLoad();
		object operand = val.Operand;
		val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(TechProto), "UnlockValues"), (string)null)
		}).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((OpCode?)OpCodes.Stloc_S, (object)null, (string)null)
		});
		object operand2 = val.Operand;
		val.Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
		{
			new CodeInstruction(opCode, operand)
		}).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
		{
			new CodeInstruction(OpCodes.Ldloca_S, operand2)
		})
			.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate<RefAction<int, int>>((RefAction<int, int>)delegate(int type, ref int value)
			{
				switch (type)
				{
				case 18:
					value *= GigaStationsPlugin.droneCapacityMultiplier;
					break;
				case 19:
					value *= GigaStationsPlugin.vesselCapacityMultiplier;
					break;
				}
			}) });
		return val.InstructionEnumeration();
	}

	private static void CalculateCarrierCapacity()
	{
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		int logisticDroneCarries = 25 * GigaStationsPlugin.droneCapacityMultiplier;
		int logisticShipCarries = 200 * GigaStationsPlugin.vesselCapacityMultiplier;
		int num = 0;
		for (int i = 3501; i <= 3510; i++)
		{
			if (GameMain.history.TechUnlocked(i))
			{
				TechProto val = ((ProtoSet<TechProto>)(object)LDB.techs).Select(i);
				num = GameMain.history.techStates[i].curLevel;
				int levels2 = 1;
				if (val.Level != val.MaxLevel)
				{
					levels2 = num - val.Level + 1;
				}
				for (int j = 0; j < val.UnlockFunctions.Length; j++)
				{
					Accumulate(val.UnlockFunctions[j], val.UnlockValues[j], levels2);
				}
			}
		}
		GigaStationsPlugin.logger.LogInfo((object)$"\nUnlocked Logistic carrier capacity Level {num}\nSetting Carrier Capacity Multipliers from settings...");
		GigaStationsPlugin.logger.LogInfo((object)$"\nLevel {num}\nSetting Vessels Capacity: {logisticShipCarries}\nSetting Drones Capacity: {logisticDroneCarries}");
		GameMain.history.logisticDroneCarries = logisticDroneCarries;
		GameMain.history.logisticShipCarries = logisticShipCarries;
		void Accumulate(int type, double value, int levels)
		{
			int num2 = (int)Math.Round(value);
			switch (type)
			{
			case 18:
				logisticDroneCarries += num2 * GigaStationsPlugin.droneCapacityMultiplier * levels;
				break;
			case 19:
				logisticShipCarries += num2 * GigaStationsPlugin.vesselCapacityMultiplier * levels;
				break;
			}
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(PowerSystem), "NewConsumerComponent")]
	public static bool NewConsumerComponentPrefix(PowerSystem __instance, ref int entityId, ref long work, ref long idle)
	{
		int iD = ((Proto)((ProtoSet<ItemProto>)(object)LDB.items).Select((int)__instance.factory.entityPool[entityId].protoId)).ID;
		if (iD != ((Proto)GigaStationsPlugin.ils).ID && iD != ((Proto)GigaStationsPlugin.pls).ID)
		{
			return true;
		}
		work = 1000000L;
		return true;
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(StationComponent), "Init")]
	public static void StationComponentInitPostfix(StationComponent __instance, ref int _id, ref int _entityId, ref int _pcId, ref PrefabDesc _desc, ref EntityData[] _entityPool)
	{
		__instance.needs = new int[13];
		if (_entityPool[_entityId].protoId == ((Proto)GigaStationsPlugin.ils).ID || _entityPool[_entityId].protoId == ((Proto)GigaStationsPlugin.pls).ID || _entityPool[_entityId].protoId == ((Proto)GigaStationsPlugin.collector).ID)
		{
			if (!__instance.isStellar && !__instance.isCollector)
			{
				_desc.stationMaxEnergyAcc = Convert.ToInt64(GigaStationsPlugin.plsMaxAcuMJ * 1000000);
				__instance.energyMax = GigaStationsPlugin.plsMaxAcuMJ * 1000000;
				__instance.storage = (StationStore[])(object)new StationStore[GigaStationsPlugin.plsMaxSlots];
				__instance.energyPerTick = 1000000L;
			}
			else if (__instance.isStellar && !__instance.isCollector)
			{
				_desc.stationMaxEnergyAcc = Convert.ToInt64(GigaStationsPlugin.ilsMaxAcuGJ * 1000000000);
				__instance.energyMax = GigaStationsPlugin.ilsMaxAcuGJ * 1000000000;
				__instance.warperMaxCount = GigaStationsPlugin.ilsMaxWarps;
				__instance.storage = (StationStore[])(object)new StationStore[GigaStationsPlugin.ilsMaxSlots];
				__instance.energyPerTick = 1000000L;
			}
		}
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(StationComponent), "Import")]
	public static IEnumerable<CodeInstruction> StationImportTranspiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Expected O, but got Unknown
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Expected O, but got Unknown
		return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[4]
		{
			new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
			new CodeMatch((OpCode?)OpCodes.Ldc_I4_6, (object)null, (string)null),
			new CodeMatch((OpCode?)OpCodes.Newarr, (object)null, (string)null),
			new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Stfld && ((FieldInfo)i.operand).Name == "needs"), (string)null)
		}).Advance(1).Set(OpCodes.Ldc_I4, (object)13)
			.InstructionEnumeration();
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(StationComponent), "UpdateNeeds")]
	public static bool UpdateNeeds(StationComponent __instance)
	{
		int num = __instance.storage.Length;
		if (num > 12)
		{
			num = 12;
		}
		for (int i = 0; i <= num; i++)
		{
			if (i == num && !__instance.isCollector)
			{
				__instance.needs[num] = ((__instance.isStellar && __instance.warperCount < __instance.warperMaxCount) ? 1210 : 0);
			}
			else if (i < __instance.needs.Length)
			{
				__instance.needs[i] = ((i < num && __instance.storage[i].count < __instance.storage[i].max) ? __instance.storage[i].itemId : 0);
			}
		}
		return false;
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(StationComponent), "UpdateInputSlots")]
	public static IEnumerable<CodeInstruction> UpdateInputSlotsTranspiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Expected O, but got Unknown
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Expected O, but got Unknown
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Expected O, but got Unknown
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Expected O, but got Unknown
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Expected O, but got Unknown
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Expected O, but got Unknown
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Expected O, but got Unknown
		CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(true, (CodeMatch[])(object)new CodeMatch[6]
		{
			new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
			new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(StationComponent), "needs"), (string)null),
			new CodeMatch((OpCode?)OpCodes.Ldc_I4_5, (object)null, (string)null),
			new CodeMatch((OpCode?)OpCodes.Ldelem_I4, (object)null, (string)null),
			new CodeMatch((OpCode?)OpCodes.Add, (object)null, (string)null),
			new CodeMatch((OpCode?)OpCodes.Stloc_S, (object)null, (string)null)
		});
		val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
		{
			new CodeInstruction(OpCodes.Ldarg_0, (object)null)
		}).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate<Func<StationComponent, int>>((Func<StationComponent, int>)delegate(StationComponent component)
		{
			int num = 0;
			for (int i = 6; i < component.needs.Length; i++)
			{
				num += component.needs[i];
			}
			return num;
		}) }).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
		{
			new CodeInstruction(OpCodes.Add, (object)null)
		});
		return val.InstructionEnumeration();
	}

	[HarmonyPrefix]
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	public static bool TryPickItemAtRear(CargoPath __instance, int[] needs, out int needIdx, out byte stack, out byte inc, ref int __result)
	{
		needIdx = -1;
		stack = 1;
		inc = 0;
		int num = __instance.bufferLength - 5 - 1;
		if (__instance.buffer[num] == 250)
		{
			int num2 = __instance.buffer[num + 1] - 1 + (__instance.buffer[num + 2] - 1) * 100 + (__instance.buffer[num + 3] - 1) * 10000 + (__instance.buffer[num + 4] - 1) * 1000000;
			int item = __instance.cargoContainer.cargoPool[num2].item;
			stack = __instance.cargoContainer.cargoPool[num2].stack;
			inc = __instance.cargoContainer.cargoPool[num2].inc;
			for (int i = 0; i < needs.Length; i++)
			{
				if (item == needs[i])
				{
					Array.Clear(__instance.buffer, num - 4, 10);
					int num3 = num + 5 + 1;
					if (__instance.updateLen < num3)
					{
						__instance.updateLen = num3;
					}
					__instance.cargoContainer.RemoveCargo(num2);
					needIdx = i;
					__result = item;
					return false;
				}
			}
		}
		__result = 0;
		return false;
	}

	[HarmonyPrefix]
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	public static bool TakeItemPrefix(StationComponent __instance, ref int _itemId, ref int _count, ref int[] _needs, out int _inc)
	{
		_inc = 0;
		bool flag = false;
		if (_needs == null)
		{
			flag = true;
		}
		else
		{
			int[] array = _needs;
			foreach (int num in array)
			{
				if (num == _itemId)
				{
					flag = true;
				}
			}
		}
		if (_itemId > 0 && _count > 0 && flag)
		{
			StationStore[] storage = __instance.storage;
			lock (storage)
			{
				int num2 = __instance.storage.Length;
				for (int j = 0; j < num2; j++)
				{
					if (__instance.storage[j].itemId == _itemId && __instance.storage[j].count > 0)
					{
						_count = ((_count >= __instance.storage[j].count) ? __instance.storage[j].count : _count);
						_itemId = __instance.storage[j].itemId;
						_inc = (int)((double)__instance.storage[j].inc / (double)__instance.storage[j].count * (double)_count + 0.5);
						StationStore[] storage2 = __instance.storage;
						storage2[j].count -= _count;
						storage2[j].inc -= _inc;
						return false;
					}
				}
			}
		}
		_itemId = 0;
		_count = 0;
		_inc = 0;
		return false;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(StationComponent), "AddItem")]
	public static bool AddItemPrefix(StationComponent __instance, int itemId, int count, int inc, ref int __result)
	{
		__result = 0;
		if (itemId <= 0)
		{
			return false;
		}
		StationStore[] storage = __instance.storage;
		lock (storage)
		{
			for (int i = 0; i < __instance.storage.Length; i++)
			{
				if (__instance.storage[i].itemId == itemId)
				{
					StationStore[] storage2 = __instance.storage;
					storage2[i].count += count;
					storage2[i].inc += inc;
					__result = count;
					return false;
				}
			}
		}
		return false;
	}
}
[HarmonyPatch]
public static class StationUpgradePatch
{
	public static void UpdateArray<T>(ref T[] array, int newSize)
	{
		T[] array2 = array;
		array = new T[newSize];
		Array.Copy(array2, array, array2.Length);
	}

	[HarmonyPatch(typeof(PlanetFactory), "UpgradeEntityWithComponents")]
	[HarmonyPostfix]
	public static void Postfix(int entityId, ItemProto newProto, PlanetFactory __instance)
	{
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		if (entityId == 0 || __instance.entityPool[entityId].id == 0)
		{
			return;
		}
		int stationId = __instance.entityPool[entityId].stationId;
		if (stationId <= 0)
		{
			return;
		}
		StationComponent val = __instance.transport.stationPool[stationId];
		PrefabDesc prefabDesc = newProto.prefabDesc;
		int newSize = (val.isStellar ? GigaStationsPlugin.ilsMaxSlots : GigaStationsPlugin.plsMaxSlots);
		UpdateArray(ref val.storage, newSize);
		if (val.needs.Length != 13)
		{
			UpdateArray(ref val.needs, 13);
		}
		if (val.isCollector)
		{
			val.collectSpeed = prefabDesc.stationCollectSpeed;
			return;
		}
		val.energyPerTick = 1000000L;
		UpdateArray(ref val.workDroneDatas, prefabDesc.stationMaxDroneCount);
		UpdateArray(ref val.workDroneOrders, prefabDesc.stationMaxDroneCount);
		if (val.isStellar)
		{
			UpdateArray(ref val.workShipDatas, prefabDesc.stationMaxShipCount);
			UpdateArray(ref val.workShipOrders, prefabDesc.stationMaxShipCount);
			UpdateArray(ref val.shipRenderers, prefabDesc.stationMaxShipCount);
			UpdateArray(ref val.shipUIRenderers, prefabDesc.stationMaxShipCount);
			val.shipDiskPos = (Vector3[])(object)new Vector3[prefabDesc.stationMaxShipCount];
			val.shipDiskRot = (Quaternion[])(object)new Quaternion[prefabDesc.stationMaxShipCount];
			int num = val.workShipDatas.Length;
			for (int i = 0; i < num; i++)
			{
				val.shipDiskRot[i] = Quaternion.Euler(0f, 360f / (float)num * (float)i, 0f);
				val.shipDiskPos[i] = val.shipDiskRot[i] * new Vector3(0f, 0f, 11.5f);
			}
			for (int j = 0; j < num; j++)
			{
				val.shipDiskRot[j] = val.shipDockRot * val.shipDiskRot[j];
				val.shipDiskPos[j] = val.shipDockPos + val.shipDockRot * val.shipDiskPos[j];
			}
			val.energyMax = GigaStationsPlugin.ilsMaxAcuGJ * 1000000000;
			val.warperMaxCount = GigaStationsPlugin.ilsMaxWarps;
		}
		else
		{
			val.energyMax = GigaStationsPlugin.plsMaxAcuMJ * 1000000;
		}
	}

	[HarmonyPatch(typeof(PlayerAction_Build), "DoUpgradeObject")]
	[HarmonyPrefix]
	public static bool CheckIfCanUpgrade(PlayerAction_Build __instance, int objId, int grade, int upgrade, ref bool __result)
	{
		//IL_0057: 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)
		ItemProto itemProto = ((BuildTool)__instance.noneTool).GetItemProto(objId);
		if (((Proto)itemProto).ID != ((Proto)GigaStationsPlugin.ils).ID && ((Proto)itemProto).ID != ((Proto)GigaStationsPlugin.pls).ID && ((Proto)itemProto).ID != ((Proto)GigaStationsPlugin.collector).ID)
		{
			return true;
		}
		if (grade == 1 || upgrade < 0)
		{
			__result = false;
			VFAudio.Create("ui-error", (Transform)null, Vector3.zero, true, 5, -1, -1L);
			if (VFInput._buildConfirm.onDown || GameMain.gameTick % 10 == 0L)
			{
				UIRealtimeTip.Popup(Localization.Translate("CantDowngradeWarn"), false, 0);
			}
			return false;
		}
		return true;
	}
}
[HarmonyPatch]
public static class UIEntityBriefInfo_Patch
{
	[HarmonyPatch(typeof(UIEntityBriefInfo), "_OnCreate")]
	[HarmonyPrefix]
	public static void ResizeArray(UIEntityBriefInfo __instance)
	{
		int num = Math.Max(GigaStationsPlugin.ilsMaxSlots, GigaStationsPlugin.plsMaxSlots);
		if (num > __instance.icons.Length)
		{
			Array.Resize(ref __instance.icons, num);
		}
	}
}
[HarmonyPatch]
public static class UIStationWindowPatch
{
	public static RectTransform contentTrs;

	public static RectTransform scrollTrs;

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(UIStationWindow), "OnMinDeliverVesselValueChange")]
	[HarmonyPatch(typeof(UIStationWindow), "OnMinDeliverDroneValueChange")]
	public static IEnumerable<CodeInstruction> Replace10With1Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0002: 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_0036: Expected O, but got Unknown
		CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction instr) => instr.opcode == OpCodes.Ldc_R4 && Mathf.Approximately((float)instr.operand, 10f)), (string)null)
		}).SetOperandAndAdvance((object)1f);
		return val.InstructionEnumeration();
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(UIStationWindow), "OnStationIdChange")]
	public static IEnumerable<CodeInstruction> RemoveDivisionBy10(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0002: 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_0035: Expected O, but got Unknown
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Expected O, but got Unknown
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Expected O, but got Unknown
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Expected O, but got Unknown
		CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(StationComponent), "deliveryDrones"), (string)null)
		}).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction instr) => instr.opcode == OpCodes.Ldc_R4 && Mathf.Approximately((float)instr.operand, 0.1f)), (string)null)
		}).SetAndAdvance(OpCodes.Nop, (object)null)
			.Advance(2)
			.SetAndAdvance(OpCodes.Nop, (object)null);
		val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(StationComponent), "deliveryShips"), (string)null)
		}).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction instr) => instr.opcode == OpCodes.Ldc_R4 && Mathf.Approximately((float)instr.operand, 0.1f)), (string)null)
		}).SetAndAdvance(OpCodes.Nop, (object)null)
			.Advance(2)
			.SetAndAdvance(OpCodes.Nop, (object)null);
		return val.InstructionEnumeration();
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(UIStationWindow), "OnStationIdChange")]
	[HarmonyPriority(0)]
	public static void OnStationIdChangePre(UIStationWindow __instance, ref string __state)
	{
		if (__instance.stationId != 0 && __instance.factory != null && __instance.transport?.stationPool != null)
		{
			StationComponent val = __instance.transport.stationPool[__instance.stationId];
			ItemProto val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)__instance.factory.entityPool[val.entityId].protoId);
			if ((((Proto)val2).ID == ((Proto)GigaStationsPlugin.pls).ID || ((Proto)val2).ID == ((Proto)GigaStationsPlugin.ils).ID || ((Proto)val2).ID == ((Proto)GigaStationsPlugin.collector).ID) && ((ManualBehaviour)__instance).active)
			{
				string text = __instance.factory.ReadExtraInfoOnEntity(val.entityId);
				string text2 = ((!string.IsNullOrEmpty(text)) ? text : ((!val.isStellar) ? ("Planetary Giga Station #" + val.id) : ((!val.isCollector) ? ("Interstellar Giga Station #" + val.gid) : ("Orbital Giga Collector #" + val.gid))));
				__state = text2;
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(UIStationWindow), "OnStationIdChange")]
	public static void OnStationIdChangePost(UIStationWindow __instance, string __state)
	{
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: 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_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_031a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0297: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_035b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0383: Unknown result type (might be due to invalid IL or missing references)
		//IL_0393: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
		if (__instance.stationId == 0 || __instance.factory == null || __instance.transport?.stationPool == null)
		{
			return;
		}
		StationComponent val = __instance.transport.stationPool[__instance.stationId];
		ItemProto val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)__instance.factory.entityPool[val.entityId].protoId);
		int num = ((val.isCollector || val.isVeinCollector) ? val.collectionIds.Length : val.storage.Length);
		int num2 = (val.isStellar ? 376 : 316);
		if (val.isCollector)
		{
			num2 = 136;
		}
		else if (val.isVeinCollector)
		{
			num2 = 289;
		}
		((RectTransform)((Component)__instance.storageUIs[0]).transform).anchoredPosition = new Vector2(0f, 0f);
		int num3 = (val.isVeinCollector ? (-190) : (-90));
		scrollTrs.anchoredPosition = new Vector2(scrollTrs.anchoredPosition.x, (float)num3);
		__instance.panelDownTrans.anchoredPosition = new Vector2(__instance.panelDownTrans.anchoredPosition.x, __instance.panelDownTrans.anchoredPosition.y - 10f);
		if (((Proto)val2).ID != ((Proto)GigaStationsPlugin.pls).ID && ((Proto)val2).ID != ((Proto)GigaStationsPlugin.ils).ID && ((Proto)val2).ID != ((Proto)GigaStationsPlugin.collector).ID)
		{
			UIStationStorage[] storageUIs = __instance.storageUIs;
			foreach (UIStationStorage val3 in storageUIs)
			{
				val3.popupBoxRect.anchoredPosition = new Vector2(5f, 0f);
			}
			scrollTrs.sizeDelta = new Vector2(scrollTrs.sizeDelta.x, (float)(76 * num));
			contentTrs.sizeDelta = new Vector2(contentTrs.sizeDelta.x, (float)(76 * num));
			int num4 = num2 + 76 * num;
			__instance.windowTrans.sizeDelta = new Vector2(600f, (float)num4);
			return;
		}
		__instance.nameInput.text = __state;
		if (!((ManualBehaviour)__instance).active)
		{
			return;
		}
		int num5 = num;
		int num6 = 600;
		if (GigaStationsPlugin.gridXCount > 1)
		{
			int num7 = 526 * (GigaStationsPlugin.gridXCount - 1);
			num6 += num7;
			num5 = num / GigaStationsPlugin.gridXCount;
			UIStationStorage[] storageUIs2 = __instance.storageUIs;
			foreach (UIStationStorage val4 in storageUIs2)
			{
				val4.popupBoxRect.anchoredPosition = new Vector2(-200f, 0f);
			}
			bool logisticShipWarpDrive = GameMain.history.logisticShipWarpDrive;
			__instance.powerGroupRect.sizeDelta = new Vector2(((!val.isStellar) ? 440f : (logisticShipWarpDrive ? 320f : 380f)) + (float)num7, 40f);
		}
		else
		{
			UIStationStorage[] storageUIs3 = __instance.storageUIs;
			foreach (UIStationStorage val5 in storageUIs3)
			{
				val5.popupBoxRect.anchoredPosition = new Vector2(5f, 0f);
			}
		}
		int num8 = ((num5 > GigaStationsPlugin.gridYCount) ? GigaStationsPlugin.gridYCount : num5);
		int num9 = num2 + 76 * num8;
		__instance.windowTrans.sizeDelta = new Vector2((float)num6, (float)num9);
		int num10 = ((num5 < GigaStationsPlugin.gridYCount) ? num5 : GigaStationsPlugin.gridYCount);
		scrollTrs.sizeDelta = new Vector2(scrollTrs.sizeDelta.x, (float)(76 * num10));
		contentTrs.sizeDelta = new Vector2(contentTrs.sizeDelta.x, (float)(76 * num5));
		for (int l = 0; l < __instance.storageUIs.Length; l++)
		{
			if (l < num)
			{
				__instance.storageUIs[l].station = val;
				__instance.storageUIs[l].index = l;
				((ManualBehaviour)__instance.storageUIs[l])._Open();
			}
			else
			{
				__instance.storageUIs[l].station = null;
				__instance.storageUIs[l].index = 0;
				((ManualBehaviour)__instance.storageUIs[l])._Close();
			}
			__instance.storageUIs[l].ClosePopMenu();
		}
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(UIStationWindow), "RefreshTrans")]
	public static IEnumerable<CodeInstruction> RefreshTransChanger(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Expected O, but got Unknown
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Expected O, but got Unknown
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Expected O, but got Unknown
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Expected O, but got Unknown
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Expected O, but got Unknown
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Expected O, but got Unknown
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Expected O, but got Unknown
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Expected O, but got Unknown
		CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(true, (CodeMatch[])(object)new CodeMatch[5]
		{
			new CodeMatch((OpCode?)OpCodes.Ldarg_1, (object)null, (string)null),
			new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(StationComponent), "collectionIds"), (string)null),
			new CodeMatch((OpCode?)OpCodes.Ldlen, (object)null, (string)null),
			new CodeMatch((OpCode?)OpCodes.Conv_I4, (object)null, (string)null),
			new CodeMatch((OpCode?)OpCodes.Stloc_2, (object)null, (string)null)
		});
		val.Advance(1);
		val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[3]
		{
			new CodeInstruction(OpCodes.Ldloc_2, (object)null),
			new CodeInstruction(OpCodes.Ldarg_1, (object)null),
			new CodeInstruction(OpCodes.Ldarg_0, (object)null)
		});
		val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate<Func<int, StationComponent, UIStationWindow, int>>((Func<int, StationComponent, UIStationWindow, int>)delegate(int count, StationComponent station, UIStationWindow stationUI)
		{
			ItemProto val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)stationUI.factory.entityPool[station.entityId].protoId);
			if (((Proto)val2).ID != ((Proto)GigaStationsPlugin.pls).ID && ((Proto)val2).ID != ((Proto)GigaStationsPlugin.ils).ID && ((Proto)val2).ID != ((Proto)GigaStationsPlugin.collector).ID)
			{
				return count;
			}
			int num = count;
			if (GigaStationsPlugin.gridXCount > 1)
			{
				num = count / GigaStationsPlugin.gridXCount;
			}
			return (num > GigaStationsPlugin.gridYCount) ? GigaStationsPlugin.gridYCount : num;
		}) });
		val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
		{
			new CodeInstruction(OpCodes.Stloc_2, (object)null)
		});
		return val.InstructionEnumeration();
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(UIStationWindow), "RefreshTrans")]
	public static void OnRefreshTrans(UIStationWindow __instance, StationComponent station)
	{
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)__instance.factory.entityPool[station.entityId].protoId);
		if ((((Proto)val).ID == ((Proto)GigaStationsPlugin.pls).ID || ((Proto)val).ID == ((Proto)GigaStationsPlugin.ils).ID || ((Proto)val).ID == ((Proto)GigaStationsPlugin.collector).ID) && ((ManualBehaviour)__instance).active)
		{
			int num = ((station.isCollector || station.isVeinCollector) ? station.collectionIds.Length : station.storage.Length);
			int num2 = num;
			int num3 = 600;
			if (GigaStationsPlugin.gridXCount > 1)
			{
				int num4 = 526 * (GigaStationsPlugin.gridXCount - 1);
				num3 += num4;
				num2 = num / GigaStationsPlugin.gridXCount;
			}
			__instance.windowTrans.sizeDelta = new Vector2((float)num3, __instance.windowTrans.sizeDelta.y);
			int num5 = ((num2 < GigaStationsPlugin.gridYCount) ? num2 : GigaStationsPlugin.gridYCount);
			scrollTrs.sizeDelta = new Vector2(scrollTrs.sizeDelta.x, (float)(76 * num5));
			contentTrs.sizeDelta = new Vector2(contentTrs.sizeDelta.x, (float)(76 * num2));
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(UIStationWindow), "_OnUpdate")]
	public static void OnStationUpdate(UIStationWindow __instance)
	{
		//IL_002a: 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)
		if (__instance.stationId != 0 && __instance.factory != null)
		{
			StationComponent val = __instance.transport.stationPool[__instance.stationId];
			float num = __instance.powerGroupRect.sizeDelta.x - 140f;
			float num2 = (float)val.energy / (float)val.energyMax;
			float num3 = (((double)num2 > 0.7) ? (-30) : 30);
			((Graphic)__instance.energyText).rectTransform.anchoredPosition = new Vector2(Mathf.Round(num * num2 + num3), 0f);
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(UIStationWindow), "OnWarperIconClick")]
	public static bool OnWarperIconClickPrefix(UIStationWindow __instance, ref int obj)
	{
		if (__instance.stationId == 0 || __instance.factory == null)
		{
			((ManualBehaviour)__instance)._Close();
			return false;
		}
		StationComponent val = __instance.transport.stationPool[__instance.stationId];
		ItemProto val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)__instance.factory.entityPool[val.entityId].protoId);
		if (((Proto)val2).ID != ((Proto)GigaStationsPlugin.pls).ID && ((Proto)val2).ID != ((Proto)GigaStationsPlugin.ils).ID && ((Proto)val2).ID != ((Proto)GigaStationsPlugin.collector).ID)
		{
			return true;
		}
		if (__instance.stationId == 0 || __instance.factory == null)
		{
			return false;
		}
		if (val.id != __instance.stationId)
		{
			return false;
		}
		if (!val.isStellar)
		{
			return false;
		}
		if (__instance.player.inhandItemId > 0 && __instance.player.inhandItemCount == 0)
		{
			__instance.player.SetHandItems(0, 0, 0);
		}
		else if (__instance.player.inhandItemId > 0 && __instance.player.inhandItemCount > 0)
		{
			int num = 1210;
			ItemProto val3 = ((ProtoSet<ItemProto>)(object)LDB.items).Select(num);
			if (__instance.player.inhandItemId != num)
			{
				UIRealtimeTip.Popup(Localization.Translate("只能放入") + ((Proto)val3).name, true, 0);
				return false;
			}
			int ilsMaxWarps = GigaStationsPlugin.ilsMaxWarps;
			int warperCount = val.warperCount;
			int num2 = ilsMaxWarps - warperCount;
			if (num2 < 0)
			{
				num2 = 0;
			}
			int num3 = ((__instance.player.inhandItemCount >= num2) ? num2 : __instance.player.inhandItemCount);
			if (num3 <= 0)
			{
				UIRealtimeTip.Popup(Localization.Translate("栏位已满"), true, 0);
				return false;
			}
			val.warperCount += num3;
			__instance.player.AddHandItemCount_Unsafe(-num3);
			if (__instance.player.inhandItemCount <= 0)
			{
				__instance.player.SetHandItemId_Unsafe(0);
				__instance.player.SetHandItemCount_Unsafe(0);
			}
		}
		else if (__instance.player.inhandItemId == 0 && __instance.player.inhandItemCount == 0)
		{
			int warperCount2 = val.warperCount;
			int num4 = warperCount2;
			if (num4 <= 0)
			{
				return false;
			}
			if (VFInput.shift || VFInput.control)
			{
				int num5 = default(int);
				num4 = __instance.player.package.AddItemStacked(1210, num4, 0, ref num5);
				if (warperCount2 != num4)
				{
					UIRealtimeTip.Popup(Localization.Translate("无法添加物品"), true, 0);
				}
				UIItemup.Up(1210, num4);
			}
			else
			{
				__instance.player.SetHandItemId_Unsafe(1210);
				__instance.player.SetHandItemCount_Unsafe(num4);
			}
			val.warperCount -= num4;
			if (val.warperCount < 0)
			{
				Assert.CannotBeReached();
				val.warperCount = 0;
			}
		}
		return false;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(UIStationWindow), "_OnCreate")]
	public static bool _OnCreatePrefix(UIStationWindow __instance)
	{
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Expected O, but got Unknown
		//IL_0058: 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_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Expected O, but got Unknown
		__instance.minDeliverDroneSlider.maxValue = 100f;
		__instance.minDeliverVesselSlider.maxValue = 100f;
		GameObject val = GigaStationsPlugin.resource.bundle.LoadAsset<GameObject>("assets/gigastations/ui/station-scroll.prefab");
		GameObject val2 = Object.Instantiate<GameObject>(val, ((Component)__instance).transform, false);
		scrollTrs = (RectTransform)val2.transform;
		scrollTrs.anchorMin = Vector2.up;
		scrollTrs.anchorMax = Vector2.one;
		scrollTrs.pivot = new Vector2(0.5f, 1f);
		scrollTrs.offsetMin = new Vector2(40f, 400f);
		scrollTrs.offsetMax = new Vector2(-40f, -90f);
		GameObject gameObject = ((Component)val2.transform.Find("Viewport/pane")).gameObject;
		contentTrs = (RectTransform)gameObject.transform;
		__instance.storageUIs = (UIStationStorage[])(object)new UIStationStorage[12];
		for (int i = 0; i < __instance.storageUIs.Length; i++)
		{
			__instance.storageUIs[i] = Object.Instantiate<UIStationStorage>(__instance.storageUIPrefab, (Transform)(object)contentTrs);
			__instance.storageUIs[i].stationWindow = __instance;
			((ManualBehaviour)__instance.storageUIs[i])._Create();
		}
		((ManualBehaviour)__instance.veinCollectorPanel)._Create();
		for (int j = 0; j < __instance.groupBtns.Length; j++)
		{
			__instance.groupBtns[j].data = j;
		}
		((ManualBehaviour)__instance.uiRoutePanel)._Create();
		return false;
	}
}