Decompiled source of NebulaCompatibilityAssist v0.4.22

NebulaCompatibilityAssist.dll

Decompiled 2 weeks ago
using System;
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 System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CommonAPI.Systems;
using DSP_Battle;
using FactoryLocator;
using FactoryLocator.UI;
using HarmonyLib;
using NebulaAPI;
using NebulaAPI.DataStructures;
using NebulaAPI.GameState;
using NebulaAPI.Interfaces;
using NebulaAPI.Networking;
using NebulaAPI.Packets;
using NebulaCompatibilityAssist.Hotfix;
using NebulaCompatibilityAssist.Packets;
using NebulaCompatibilityAssist.Patches;
using NebulaModel;
using NebulaModel.DataStructures;
using NebulaModel.DataStructures.Chat;
using NebulaModel.Logger;
using NebulaModel.Packets.Factory.Assembler;
using NebulaModel.Packets.Factory.PowerGenerator;
using NebulaModel.Packets.Factory.Storage;
using NebulaPatcher.Patches.Dynamic;
using NebulaWorld;
using NebulaWorld.Chat.Commands;
using NebulaWorld.Factory;
using NebulaWorld.MonoBehaviours.Local.Chat;
using PlanetFinderMod;
using ProjectGenesis.Patches.Logic.QuantumStorage;
using ProjectGenesis.Utils;
using SphereOpt;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using crecheng.DSPModSave;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyFileVersion("0.4.22")]
[assembly: AssemblyInformationalVersion("0.4.22")]
[assembly: AssemblyProduct("NebulaCompatibilityAssist")]
[assembly: AssemblyTitle("NebulaCompatibilityAssist")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.4.22.0")]
[module: UnverifiableCode]
namespace NebulaCompatibilityAssist
{
	[BepInPlugin("NebulaCompatibilityAssist", "NebulaCompatibilityAssist", "0.4.22")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin, IMultiplayerMod
	{
		public const string GUID = "NebulaCompatibilityAssist";

		public const string NAME = "NebulaCompatibilityAssist";

		public const string VERSION = "0.4.22";

		public static Plugin Instance { get; private set; }

		public Harmony Harmony { get; private set; }

		public string Version { get; set; }

		public void Awake()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			Instance = this;
			Log.LogSource = ((BaseUnityPlugin)this).Logger;
			Harmony = new Harmony("NebulaCompatibilityAssist");
			NC_Patch.OnAwake();
		}

		[Conditional("DEBUG")]
		public void OnDestroy()
		{
			NC_Patch.OnDestory();
			Harmony.UnpatchSelf();
			Harmony = null;
		}

		public bool CheckVersion(string hostVersion, string clientVersion)
		{
			return hostVersion.Equals(clientVersion);
		}
	}
	public static class Log
	{
		public static ManualLogSource LogSource;

		public static void Error(object obj)
		{
			LogSource.LogError(obj);
		}

		public static void Warn(object obj)
		{
			LogSource.LogWarning(obj);
		}

		public static void Info(object obj)
		{
			LogSource.LogInfo(obj);
		}

		public static void Debug(object obj)
		{
			LogSource.LogDebug(obj);
		}

		[Conditional("DEBUG")]
		public static void Dev(object obj)
		{
			LogSource.LogDebug(obj);
		}

		[Conditional("DEBUG")]
		public static void SlowLog(object obj)
		{
			if (GameMain.gameTick % 30 == 0L)
			{
				LogSource.LogDebug(obj);
			}
		}
	}
}
namespace NebulaCompatibilityAssist.Packets
{
	public class NC_AllModList
	{
		public string[] GUIDs { get; set; }

		public string[] Names { get; set; }

		public string[] Versions { get; set; }

		public bool SandboxToolsEnabled { get; set; }

		public NC_AllModList()
		{
		}

		public NC_AllModList(int _)
		{
			int count = Chainloader.PluginInfos.Count;
			GUIDs = new string[count];
			Names = new string[count];
			Versions = new string[count];
			int num = 0;
			foreach (KeyValuePair<string, PluginInfo> pluginInfo in Chainloader.PluginInfos)
			{
				GUIDs[num] = pluginInfo.Key;
				Names[num] = pluginInfo.Value.Metadata.Name;
				Versions[num] = pluginInfo.Value.Metadata.Version.ToString();
				num++;
			}
			SandboxToolsEnabled = GameMain.sandboxToolsEnabled;
		}
	}
	[RegisterPacketProcessor]
	internal class NC_AllModListProcessor : BasePacketProcessor<NC_AllModList>
	{
		public override void ProcessPacket(NC_AllModList packet, INebulaConnection conn)
		{
			if (base.IsClient)
			{
				ChatManager.ServerModList = packet;
				string report;
				int num = ChatManager.CheckModsVersion(out report);
				if (num > 0)
				{
					ChatManager.ShowMessageInChat($"Server mods diff = {num}. Type /info full to see details.");
				}
				GameMain.sandboxToolsEnabled = packet.SandboxToolsEnabled;
			}
		}
	}
	public class NC_BattleUpdate
	{
		public enum EType
		{
			None,
			AddRelic,
			RemoveRelic,
			ApplyAuthorizationPoint,
			ResetAuthorizationPoint
		}

		public string Username { get; set; }

		public EType Type { get; set; }

		public int Value1 { get; set; }

		public int Value2 { get; set; }

		public int[] Values1 { get; set; }

		public int[] Values2 { get; set; }

		public NC_BattleUpdate()
		{
		}

		public NC_BattleUpdate(EType type, int value1, int value2)
		{
			Username = Multiplayer.Session.LocalPlayer.Data.Username;
			Type = type;
			Value1 = value1;
			Value2 = value2;
			Values1 = (Values2 = new int[0]);
		}

		public NC_BattleUpdate(EType type, int[] values1, int[] values2)
		{
			Username = Multiplayer.Session.LocalPlayer.Data.Username;
			Type = type;
			Values1 = values1;
			Values2 = values2;
		}
	}
	[RegisterPacketProcessor]
	internal class NC_BattleUpdateProcessor : BasePacketProcessor<NC_BattleUpdate>
	{
		public override void ProcessPacket(NC_BattleUpdate packet, INebulaConnection conn)
		{
			DSP_Battle_Patch.OnReceive(packet);
		}
	}
	public class NC_GB_Packet
	{
		public enum EType
		{
			None,
			StroageBoxRequest,
			StroageBoxResponse
		}

		public EType Type { get; set; }

		public int PlanetId { get; set; }

		public int OrbitId { get; set; }

		public byte[] Data { get; set; }

		public NC_GB_Packet()
		{
		}

		public NC_GB_Packet(EType type, int planetId, int orbitId, byte[] data)
		{
			Type = type;
			PlanetId = planetId;
			OrbitId = orbitId;
			Data = data;
		}
	}
	[RegisterPacketProcessor]
	internal class NC_GB_PacketProcessor : BasePacketProcessor<NC_GB_Packet>
	{
		public override void ProcessPacket(NC_GB_Packet packet, INebulaConnection conn)
		{
			Log.Debug(packet.Type.ToString() + " p" + packet.PlanetId + " o" + packet.OrbitId);
			if (GameMain.galaxy.PlanetById(packet.PlanetId)?.factory == null)
			{
				return;
			}
			switch (packet.Type)
			{
			case NC_GB_Packet.EType.StroageBoxRequest:
			{
				IWriterProvider binaryWriter = NebulaModAPI.GetBinaryWriter();
				try
				{
					QuantumStoragePatches._components[packet.OrbitId - 1].Export(binaryWriter.BinaryWriter);
					packet.Data = binaryWriter.CloseAndGetBytes();
					packet.Type = NC_GB_Packet.EType.StroageBoxResponse;
					conn.SendPacket<NC_GB_Packet>(packet);
					break;
				}
				finally
				{
					((IDisposable)binaryWriter)?.Dispose();
				}
			}
			case NC_GB_Packet.EType.StroageBoxResponse:
			{
				IReaderProvider binaryReader = NebulaModAPI.GetBinaryReader(packet.Data);
				try
				{
					StorageComponent val = QuantumStoragePatches._components[packet.OrbitId - 1];
					val.Import(binaryReader.BinaryReader);
					UIStorageWindow storageWindow = UIRoot.instance.uiGame.storageWindow;
					if (((ManualBehaviour)storageWindow).active && storageWindow.factory != null && storageWindow.factoryStorage.storagePool[storageWindow.storageId] == val)
					{
						Log.Debug("Refresh Quantum depot window");
						storageWindow.eventLock = true;
						storageWindow.storageUI.OnStorageDataChanged();
						storageWindow.bansSlider.maxValue = val.size;
						storageWindow.bansSlider.value = val.size - val.bans;
						storageWindow.bansValueText.text = storageWindow.bansSlider.value.ToString();
						storageWindow.eventLock = false;
					}
					break;
				}
				finally
				{
					((IDisposable)binaryReader)?.Dispose();
				}
			}
			}
		}
	}
	public class NC_LocatorFilter
	{
		public int AstroId { get; set; }

		public int QueryType { get; set; }

		public int Mode { get; set; }

		public int[] Ids { get; set; }

		public int[] Counts { get; set; }

		public NC_LocatorFilter()
		{
		}

		public NC_LocatorFilter(int astroId, int queryType, int mode, Dictionary<int, int> filter)
		{
			AstroId = astroId;
			QueryType = queryType;
			Mode = mode;
			if (filter == null)
			{
				return;
			}
			Ids = new int[filter.Count];
			Counts = new int[filter.Count];
			int num = 0;
			foreach (KeyValuePair<int, int> item in filter)
			{
				Ids[num] = item.Key;
				Counts[num++] = item.Value;
			}
		}
	}
	[RegisterPacketProcessor]
	internal class NC_LocatorFilterProcessor : BasePacketProcessor<NC_LocatorFilter>
	{
		public override void ProcessPacket(NC_LocatorFilter packet, INebulaConnection conn)
		{
			FactoryLocator_Patch.OnReceive(packet, conn);
		}
	}
	public class NC_LocatorResult
	{
		public int AstroId { get; set; }

		public int QueryType { get; set; }

		public int Mode { get; set; }

		public int ProtoId { get; set; }

		public int[] PlanetIds { get; set; }

		public Float3[] LocalPos { get; set; }

		public int[] DetailIds { get; set; }

		public NC_LocatorResult()
		{
		}

		public NC_LocatorResult(int astroId, int queryType, int mode, int protoId)
		{
			AstroId = astroId;
			QueryType = queryType;
			Mode = mode;
			ProtoId = protoId;
			PlanetIds = Array.Empty<int>();
			LocalPos = Array.Empty<Float3>();
			DetailIds = Array.Empty<int>();
		}

		public NC_LocatorResult(int queryType, List<int> planetIds, List<Vector3> localPos, List<int> detailIds)
		{
			//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_004e: Unknown result type (might be due to invalid IL or missing references)
			QueryType = queryType;
			PlanetIds = planetIds.ToArray();
			DetailIds = detailIds.ToArray();
			LocalPos = (Float3[])(object)new Float3[localPos.Count];
			for (int i = 0; i < localPos.Count; i++)
			{
				LocalPos[i] = DataStructureExtensions.ToFloat3(localPos[i]);
			}
		}
	}
	[RegisterPacketProcessor]
	internal class NC_LocatorResultProcessor : BasePacketProcessor<NC_LocatorResult>
	{
		public override void ProcessPacket(NC_LocatorResult packet, INebulaConnection conn)
		{
			FactoryLocator_Patch.OnReceive(packet, conn);
		}
	}
	public class NC_ModSaveData
	{
		public static Action<string, byte[]> OnReceive;

		public string Guid { get; set; }

		public byte[] Bytes { get; set; }

		public NC_ModSaveData()
		{
		}

		public NC_ModSaveData(string guid, byte[] bytes)
		{
			Guid = guid;
			Bytes = bytes;
		}
	}
	[RegisterPacketProcessor]
	internal class NC_ModSaveDataProcessor : BasePacketProcessor<NC_ModSaveData>
	{
		public override void ProcessPacket(NC_ModSaveData packet, INebulaConnection conn)
		{
			if (base.IsHost)
			{
				NebulaModAPI.MultiplayerSession.Network.SendPacketExclude<NC_ModSaveData>(packet, conn);
			}
			Log.Debug("Receive ModSave Data Packet - " + packet.Guid);
			NC_ModSaveData.OnReceive?.Invoke(packet.Guid, packet.Bytes);
		}
	}
	public class NC_ModSaveRequest
	{
		public static Action<string, INebulaConnection> OnReceive;

		public string Guid { get; set; }

		public NC_ModSaveRequest()
		{
		}

		public NC_ModSaveRequest(string guid)
		{
			Guid = guid;
		}
	}
	[RegisterPacketProcessor]
	internal class NC_ModSaveRequestProcessor : BasePacketProcessor<NC_ModSaveRequest>
	{
		public override void ProcessPacket(NC_ModSaveRequest packet, INebulaConnection conn)
		{
			NC_ModSaveRequest.OnReceive?.Invoke(packet.Guid, conn);
		}
	}
	public class NC_PlanetInfoData
	{
		public int StarId { get; set; }

		public int PlanetId { get; set; }

		public long EnergyCapacity { get; set; }

		public long EnergyRequired { get; set; }

		public long EnergyExchanged { get; set; }

		public int NetworkCount { get; set; }

		public float[] ConsumerRatios { get; set; }

		public int[] ConsumerCounts { get; set; }

		public NC_PlanetInfoData()
		{
		}

		public NC_PlanetInfoData(in PlanetData planet)
		{
			PlanetId = planet.id;
			List<float> list = new List<float>();
			List<int> list2 = new List<int>();
			if (planet.factory?.powerSystem != null)
			{
				for (int i = 1; i < planet.factory.powerSystem.netCursor; i++)
				{
					PowerNetwork val = planet.factory.powerSystem.netPool[i];
					if (val != null && val.id == i)
					{
						NetworkCount++;
						EnergyCapacity += val.energyCapacity;
						EnergyRequired += val.energyRequired;
						EnergyExchanged += val.energyExchanged;
						list.Add((float)val.consumerRatio);
						list2.Add(val.consumers.Count);
					}
				}
			}
			ConsumerRatios = list.ToArray();
			ConsumerCounts = list2.ToArray();
		}

		public NC_PlanetInfoData(in StarData star)
		{
			StarId = star.id;
			List<float> list = new List<float>();
			List<int> list2 = new List<int>();
			for (int i = 0; i < star.planetCount; i++)
			{
				PlanetData val = star.planets[i];
				if (val.factory?.powerSystem == null)
				{
					continue;
				}
				for (int j = 1; j < val.factory.powerSystem.netCursor; j++)
				{
					PowerNetwork val2 = val.factory.powerSystem.netPool[j];
					if (val2 != null && val2.id == j)
					{
						NetworkCount++;
						EnergyCapacity += val2.energyCapacity;
						EnergyRequired += val2.energyRequired;
						EnergyExchanged += val2.energyExchanged;
						list.Add((float)val2.consumerRatio);
						list2.Add(val2.consumers.Count);
					}
				}
			}
			ConsumerRatios = list.ToArray();
			ConsumerCounts = list2.ToArray();
		}
	}
	[RegisterPacketProcessor]
	internal class NC_PlanetInfoDataProcessor : BasePacketProcessor<NC_PlanetInfoData>
	{
		public override void ProcessPacket(NC_PlanetInfoData packet, INebulaConnection conn)
		{
			if (!base.IsHost)
			{
				if (PlanetFinder_Patch.Enable)
				{
					PlanetFinder_Patch.OnReceive(packet);
				}
				if (FactoryLocator_Patch.Enable)
				{
					FactoryLocator_Patch.OnReceive(packet);
				}
			}
		}
	}
	public class NC_PlanetInfoRequest
	{
		public int AstroId { get; set; }

		public NC_PlanetInfoRequest()
		{
		}

		public NC_PlanetInfoRequest(int astroId)
		{
			AstroId = astroId;
		}
	}
	[RegisterPacketProcessor]
	internal class NC_PlanetInfoRequestProcessor : BasePacketProcessor<NC_PlanetInfoRequest>
	{
		public override void ProcessPacket(NC_PlanetInfoRequest packet, INebulaConnection conn)
		{
			if (base.IsClient)
			{
				return;
			}
			if (packet.AstroId == -1)
			{
				for (int i = 0; i < GameMain.data.factoryCount; i++)
				{
					PlanetData planet = GameMain.data.factories[i].planet;
					conn.SendPacket<NC_PlanetInfoData>(new NC_PlanetInfoData(in planet));
				}
			}
			else
			{
				if (packet.AstroId <= 0)
				{
					return;
				}
				if (packet.AstroId % 100 == 0)
				{
					StarData star = GameMain.data.galaxy.StarById(packet.AstroId / 100);
					Log.Debug(packet.AstroId / 100);
					Log.Debug(star);
					if (star != null)
					{
						conn.SendPacket<NC_PlanetInfoData>(new NC_PlanetInfoData(in star));
					}
				}
				else
				{
					PlanetData planet2 = GameMain.data.galaxy.PlanetById(packet.AstroId);
					if (planet2 != null)
					{
						conn.SendPacket<NC_PlanetInfoData>(new NC_PlanetInfoData(in planet2));
					}
				}
			}
		}
	}
	public class NC_StationConfig
	{
		public int PlanetId { get; set; }

		public int[] StationIds { get; set; }

		public long[] MaxChargePower { get; set; }

		public double[] MaxTripDrones { get; set; }

		public double[] MaxTripVessel { get; set; }

		public int[] MinDeliverDrone { get; set; }

		public int[] MinDeliverVessel { get; set; }

		public double[] WarpDistance { get; set; }

		public bool[] WarperNeeded { get; set; }

		public bool[] IncludeCollectors { get; set; }

		public int[] PilerCount { get; set; }

		public int[] MaxMiningSpeed { get; set; }

		public NC_StationConfig()
		{
		}

		public NC_StationConfig(in StationComponent station, in PlanetFactory factory)
		{
			StationComponent[] stations = (StationComponent[])(object)new StationComponent[1] { station };
			this..ctor(in stations, in factory);
		}

		public NC_StationConfig(in StationComponent[] stations, in PlanetFactory factory)
		{
			int num = ((stations.Length < factory.transport.stationCursor) ? stations.Length : factory.transport.stationCursor);
			PlanetId = factory.planetId;
			StationIds = new int[num];
			MaxChargePower = new long[num];
			MaxTripDrones = new double[num];
			MaxTripVessel = new double[num];
			MinDeliverDrone = new int[num];
			MinDeliverVessel = new int[num];
			WarpDistance = new double[num];
			WarperNeeded = new bool[num];
			IncludeCollectors = new bool[num];
			PilerCount = new int[num];
			MaxMiningSpeed = new int[num];
			for (int i = 0; i < num; i++)
			{
				if (stations[i] != null)
				{
					StationComponent val = stations[i];
					StationIds[i] = val.id;
					if (!val.isCollector && !val.isVeinCollector)
					{
						MaxChargePower[i] = factory.powerSystem.consumerPool[val.pcId].workEnergyPerTick;
					}
					MaxTripDrones[i] = val.tripRangeDrones;
					MaxTripVessel[i] = val.tripRangeShips;
					MinDeliverDrone[i] = val.deliveryDrones;
					MinDeliverVessel[i] = val.deliveryShips;
					WarpDistance[i] = val.warpEnableDist;
					WarperNeeded[i] = val.warperNecessary;
					IncludeCollectors[i] = val.includeOrbitCollector;
					PilerCount[i] = val.pilerCount;
					if (val.isVeinCollector)
					{
						MaxMiningSpeed[i] = factory.factorySystem.minerPool[val.minerId].speed;
					}
				}
			}
		}
	}
	[RegisterPacketProcessor]
	internal class NC_StationConfigProcessor : BasePacketProcessor<NC_StationConfig>
	{
		public override void ProcessPacket(NC_StationConfig packet, INebulaConnection conn)
		{
			PlanetFactory val = GameMain.galaxy.PlanetById(packet.PlanetId)?.factory;
			if (val == null)
			{
				return;
			}
			Log.Debug($"Update stations config on {packet.PlanetId}: {packet.StationIds.Length}");
			StationComponent[] stationPool = val.transport.stationPool;
			for (int i = 0; i < packet.StationIds.Length; i++)
			{
				if (packet.StationIds[i] == 0)
				{
					continue;
				}
				StationComponent val2 = stationPool[packet.StationIds[i]];
				if (val2 == null)
				{
					Log.Warn($"Station {i} doesn't exist!");
					continue;
				}
				if (!val2.isCollector && !val2.isVeinCollector)
				{
					val.powerSystem.consumerPool[val2.pcId].workEnergyPerTick = packet.MaxChargePower[i];
				}
				val2.tripRangeDrones = packet.MaxTripDrones[i];
				val2.tripRangeShips = packet.MaxTripVessel[i];
				val2.deliveryDrones = packet.MinDeliverDrone[i];
				val2.deliveryShips = packet.MinDeliverVessel[i];
				val2.warpEnableDist = packet.WarpDistance[i];
				val2.warperNecessary = packet.WarperNeeded[i];
				val2.includeOrbitCollector = packet.IncludeCollectors[i];
				val2.pilerCount = packet.PilerCount[i];
				if (val2.isVeinCollector)
				{
					val.factorySystem.minerPool[val2.minerId].speed = packet.MaxMiningSpeed[i];
				}
			}
			UIStationWindow stationWindow = UIRoot.instance.uiGame.stationWindow;
			if ((Object)(object)stationWindow != (Object)null && ((ManualBehaviour)stationWindow).active && stationWindow.factory == val)
			{
				stationWindow.OnStationIdChange();
			}
		}
	}
	public class NC_StationShipCount
	{
		public int PlanetId { get; set; }

		public int[] StationIds { get; set; }

		public int[] WarperCount { get; set; }

		public int[] DroneCount { get; set; }

		public int[] ShipCount { get; set; }

		public NC_StationShipCount()
		{
		}

		public NC_StationShipCount(StationComponent station, int planetId)
			: this((StationComponent[])(object)new StationComponent[1] { station }, planetId)
		{
		}

		public NC_StationShipCount(StationComponent[] stations, int planetId)
		{
			PlanetId = planetId;
			StationIds = new int[stations.Length];
			WarperCount = new int[stations.Length];
			DroneCount = new int[stations.Length];
			ShipCount = new int[stations.Length];
			for (int i = 0; i < stations.Length; i++)
			{
				if (stations[i] != null)
				{
					StationComponent val = stations[i];
					StationIds[i] = val.id;
					WarperCount[i] = val.warperCount;
					DroneCount[i] = val.idleDroneCount + val.workDroneCount;
					ShipCount[i] = val.idleShipCount + val.workShipCount;
				}
			}
		}
	}
	[RegisterPacketProcessor]
	internal class NC_StationItemCountProcessor : BasePacketProcessor<NC_StationShipCount>
	{
		public override void ProcessPacket(NC_StationShipCount packet, INebulaConnection conn)
		{
			PlanetFactory val = GameMain.galaxy.PlanetById(packet.PlanetId)?.factory;
			if (val == null)
			{
				return;
			}
			Log.Debug($"Update stations ship count on {packet.PlanetId}: {packet.StationIds.Length}");
			StationComponent[] stationPool = val.transport.stationPool;
			for (int i = 0; i < packet.StationIds.Length; i++)
			{
				if (packet.StationIds[i] != 0)
				{
					StationComponent val2 = stationPool[packet.StationIds[i]];
					if (val2 == null)
					{
						Log.Warn($"Station {i} doesn't exist!");
						continue;
					}
					val2.warperCount = packet.WarperCount[i];
					val2.idleDroneCount = packet.DroneCount[i] - val2.workDroneCount;
					val2.idleShipCount = packet.ShipCount[i] - val2.workShipCount;
				}
			}
			UIStationWindow stationWindow = UIRoot.instance.uiGame.stationWindow;
			if ((Object)(object)stationWindow != (Object)null && ((ManualBehaviour)stationWindow).active && stationWindow.factory == val)
			{
				stationWindow.OnStationIdChange();
			}
		}
	}
	public class NC_StationStorageData
	{
		public static Action OnReceive;

		public int[] StationGId { get; set; }

		public int[] StorageLength { get; set; }

		public bool[] IsCollector { get; set; }

		public int[] ItemId { get; set; }

		public int[] Max { get; set; }

		public int[] Count { get; set; }

		public int[] Inc { get; set; }

		public int[] RemoteOrder { get; set; }

		public byte[] Logic { get; set; }

		public NC_StationStorageData()
		{
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: 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)
			StationComponent[] stationPool = GameMain.data.galacticTransport.stationPool;
			List<int> list = new List<int>();
			List<int> list2 = new List<int>();
			List<bool> list3 = new List<bool>();
			int num = 0;
			int num2 = 0;
			StationComponent[] array = stationPool;
			foreach (StationComponent val in array)
			{
				if (val != null)
				{
					list.Add(val.gid);
					list2.Add(val.storage.Length);
					list3.Add(val.isCollector);
					num += val.storage.Length;
				}
			}
			StationGId = list.ToArray();
			StorageLength = list2.ToArray();
			IsCollector = list3.ToArray();
			ItemId = new int[num];
			Max = new int[num];
			Count = new int[num];
			Inc = new int[num];
			RemoteOrder = new int[num];
			Logic = new byte[num];
			for (int j = 0; j < list.Count; j++)
			{
				StationComponent val2 = stationPool[list[j]];
				for (int k = 0; k < list2[j]; k++)
				{
					StationStore val3 = val2.storage[k];
					ItemId[num2 + k] = val3.itemId;
					Max[num2 + k] = val3.max;
					Count[num2 + k] = val3.count;
					Inc[num2 + k] = val3.inc;
					RemoteOrder[num2 + k] = val3.remoteOrder;
					Logic[num2 + k] = (byte)val3.remoteLogic;
				}
				num2 += list2[j];
			}
		}
	}
	[RegisterPacketProcessor]
	internal class NC_StationStorageReponseProcessor : BasePacketProcessor<NC_StationStorageData>
	{
		public override void ProcessPacket(NC_StationStorageData packet, INebulaConnection conn)
		{
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			if (base.IsHost)
			{
				return;
			}
			int num = 0;
			StationComponent[] stationPool = GameMain.data.galacticTransport.stationPool;
			for (int i = 0; i < packet.StationGId.Length; i++)
			{
				StationComponent val = stationPool[packet.StationGId[i]];
				if (val == null)
				{
					Log.Warn($"Gid {packet.StationGId[i]} does not in client");
					continue;
				}
				if (val.storage == null || val.storage.Length < packet.StorageLength[i])
				{
					val.storage = (StationStore[])(object)new StationStore[packet.StorageLength[i]];
				}
				val.isCollector = packet.IsCollector[i];
				for (int j = 0; j < packet.StorageLength[i]; j++)
				{
					val.storage[j].itemId = packet.ItemId[num + j];
					val.storage[j].max = packet.Max[num + j];
					val.storage[j].count = packet.Count[num + j];
					val.storage[j].inc = packet.Inc[num + j];
					val.storage[j].remoteOrder = packet.RemoteOrder[num + j];
					val.storage[j].remoteLogic = (ELogisticStorage)packet.Logic[num + j];
				}
				num += packet.StorageLength[i];
			}
			StationComponent[] array = stationPool;
			foreach (StationComponent val2 in array)
			{
				if (val2 != null && val2.storage == null)
				{
					Log.Warn($"Gid {val2.gid} does not in server");
				}
			}
			NC_StationStorageData.OnReceive?.Invoke();
		}
	}
	public class NC_StationStorageRequest
	{
	}
	[RegisterPacketProcessor]
	internal class NC_StationStorageRequestProcessor : BasePacketProcessor<NC_StationStorageRequest>
	{
		public override void ProcessPacket(NC_StationStorageRequest packet, INebulaConnection conn)
		{
			if (base.IsHost)
			{
				conn.SendPacket<NC_StationStorageData>(new NC_StationStorageData());
			}
		}
	}
	public class NC_UXA_Packet
	{
		public enum EType
		{
			None,
			InitDysonSphere,
			DismantleAll,
			BuildOrbitalCollector
		}

		public EType Type { get; set; }

		public int PlanetId { get; set; }

		public int AuthorId { get; set; }

		public float Value1 { get; set; }

		public float Value2 { get; set; }

		public float Value3 { get; set; }

		public NC_UXA_Packet()
		{
		}

		public NC_UXA_Packet(EType type, int planetId, int authorId)
		{
			Type = type;
			PlanetId = planetId;
			AuthorId = authorId;
		}
	}
	[RegisterPacketProcessor]
	internal class NC_UXA_PacketProcessor : BasePacketProcessor<NC_UXA_Packet>
	{
		public override void ProcessPacket(NC_UXA_Packet packet, INebulaConnection conn)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: 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_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			Log.Debug(packet.Type);
			if (packet.Type == NC_UXA_Packet.EType.InitDysonSphere)
			{
				if (base.IsHost)
				{
					((INetworkProvider)Multiplayer.Session.Server).SendPacketExclude<NC_UXA_Packet>(packet, conn);
				}
				int num = (int)packet.Value1;
				int num2 = (int)packet.Value2;
				DysonSphere val = GameMain.data.dysonSpheres[num];
				if (val == null)
				{
					return;
				}
				if (num2 < 0)
				{
					DysonSphere val2 = new DysonSphere();
					GameMain.data.dysonSpheres[num] = val2;
					val2.Init(GameMain.data, GameMain.data.galaxy.stars[num]);
					val2.ResetNew();
				}
				else
				{
					if (((val != null) ? val.layersIdBased[num2] : null) == null)
					{
						return;
					}
					DysonRocket[] rocketPool = val.rocketPool;
					for (int num3 = val.rocketCursor - 1; num3 > 0; num3--)
					{
						if (rocketPool[num3].id == num3 && rocketPool[num3].nodeLayerId == num2)
						{
							val.RemoveDysonRocket(num3);
						}
					}
					val.RemoveLayer(num2);
				}
				return;
			}
			PlanetFactory val3 = GameMain.galaxy.PlanetById(packet.PlanetId)?.factory;
			if (val3 == null)
			{
				return;
			}
			using (Multiplayer.Session.Factories.IsIncomingRequest.On())
			{
				Multiplayer.Session.Factories.TargetPlanet = packet.PlanetId;
				Multiplayer.Session.Factories.PacketAuthor = packet.AuthorId;
				Multiplayer.Session.Factories.EventFactory = val3;
				if (!val3.planet.factoryLoaded)
				{
					IFactoryManager factories = Multiplayer.Session.Factories;
					FactoryManager val4 = (FactoryManager)(object)((factories is FactoryManager) ? factories : null);
					if (val4.RemovePlanetTimer(packet.PlanetId))
					{
						val4.UnloadPlanetData(packet.PlanetId);
					}
				}
				switch (packet.Type)
				{
				case NC_UXA_Packet.EType.DismantleAll:
				{
					EntityData[] entityPool = val3.entityPool;
					foreach (EntityData val9 in entityPool)
					{
						if (val9.id == 0)
						{
							continue;
						}
						int stationId = val9.stationId;
						if (stationId > 0)
						{
							StationComponent val10 = val3.transport.stationPool[stationId];
							if (val10.storage != null)
							{
								for (int j = 0; j < val10.storage.Length; j++)
								{
									val10.storage[j].count = 0;
								}
							}
						}
						val3.RemoveEntityWithComponents(val9.id, false);
					}
					break;
				}
				case NC_UXA_Packet.EType.BuildOrbitalCollector:
				{
					Vector3 val5 = default(Vector3);
					((Vector3)(ref val5))..ctor(packet.Value1, packet.Value2, packet.Value3);
					Quaternion val6 = Maths.SphericalRotation(val5, 0f);
					PrebuildData val7 = default(PrebuildData);
					val7.protoId = 2105;
					val7.modelIndex = 117;
					val7.pos = val5;
					val7.pos2 = val5;
					val7.rot = val6;
					val7.rot2 = val6;
					val7.pickOffset = 0;
					val7.insertOffset = 0;
					val7.recipeId = 0;
					val7.filterId = 0;
					val7.paramCount = 0;
					PrebuildData val8 = val7;
					val3.AddPrebuildDataWithComponents(val8);
					break;
				}
				}
				Multiplayer.Session.Factories.TargetPlanet = -2;
				Multiplayer.Session.Factories.PacketAuthor = -1;
				Multiplayer.Session.Factories.EventFactory = null;
			}
		}
	}
}
namespace NebulaCompatibilityAssist.Patches
{
	public static class NC_Patch
	{
		public static bool IsClient;

		public static Action OnLogin;

		public static string RequriedPlugins = "";

		public static string ErrorMessage = "";

		public static bool initialized = false;

		public static void OnAwake()
		{
			NebulaModAPI.RegisterPackets(Assembly.GetExecutingAssembly());
			Plugin.Instance.Harmony.PatchAll(typeof(NC_Patch));
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")]
		public static void Init()
		{
			if (!initialized)
			{
				Harmony harmony = Plugin.Instance.Harmony;
				ConfigFile config = ((BaseUnityPlugin)Plugin.Instance).Config;
				LSTM.Init(harmony);
				if (config.Bind<bool>("Sync Patch", "DSPStarMapMemo", true, "Enable patching DSPStarMapMemo").Value)
				{
					DSPStarMapMemo.Init(harmony);
				}
				PlanetFinder_Patch.Init(harmony);
				DSPFreeMechaCustom.Init(harmony);
				AutoStationConfig.Init(harmony);
				Auxilaryfunction.Init(harmony);
				UXAssist_Patch.Init(harmony);
				DSPOptimizations.Init(harmony);
				SphereOpt_Patch.Init(harmony);
				FactoryLocator_Patch.Init(harmony);
				SplitterOverBelt.Init(harmony);
				if (config.Bind<bool>("Sync Patch", "MoreMegaStructure", true, "Enable patching MoreMegaStructure").Value)
				{
					MoreMegaStructure.Init(harmony);
				}
				BlueprintTweaks.Init(harmony);
				DSPAutoSorter.Init(harmony);
				if (config.Bind<bool>("Sync Patch", "AssemblerVerticalConstruction", true, "Enable patching AssemblerVerticalConstruction").Value)
				{
					AssemblerVerticalConstruction.Init(harmony);
				}
				if (config.Bind<bool>("Sync Patch", "GenesisBook", true, "Enable patching GenesisBook").Value)
				{
					GenesisBook_Patch.Init(harmony);
				}
				if (config.Bind<bool>("Sync Patch", "DSP_Battle", true, "Enable patching TheyComeFromVoid").Value)
				{
					DSP_Battle_Patch.Init(harmony);
				}
				NebulaHotfix.Init(harmony);
				string text = (Localization.isZHCN ? "联机补丁提示" : "Nebula Compatibility Assist Report");
				string text2 = (Localization.isZHCN ? "修改以下mod时出错, 在联机模式中可能无法正常运行" : "Error occurred when patching the following mods:");
				string incompatMessage = (Localization.isZHCN ? "以下mod和联机mod不相容, 可能将导致错误或不同步\n" : "The following mods are not compatible with multiplayer mod:\n");
				string warnMessage = (Localization.isZHCN ? "以下mod的部分功能可能导致联机不同步\n" : "The following mods have some functions that don't sync in multiplayer game:\n");
				string text3 = "";
				if (ErrorMessage != "")
				{
					text2 += ErrorMessage;
					text3 = text3 + text2 + "\n";
				}
				if (TestIncompatMods(ref incompatMessage))
				{
					text3 += incompatMessage;
				}
				if (TestWarnMods(ref warnMessage))
				{
					text3 += warnMessage;
				}
				if (!string.IsNullOrEmpty(text3))
				{
					UIMessageBox.Show(text, text3, Localization.Translate("确定"), 3);
				}
				initialized = true;
				Plugin.Instance.Version = "0.4.22" + RequriedPlugins;
				Log.Debug("Version: " + Plugin.Instance.Version);
			}
		}

		public static void OnDestory()
		{
			ChatManager.OnDestory();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameMain), "Begin")]
		public static void OnGameBegin()
		{
			if (NebulaModAPI.IsMultiplayerActive && NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)
			{
				Log.Debug("OnLogin");
				IsClient = true;
				OnLogin?.Invoke();
			}
			else
			{
				IsClient = false;
			}
		}

		private static bool TestIncompatMods(ref string incompatMessage)
		{
			int num = 0;
			if (Chainloader.PluginInfos.ContainsKey("semarware.dysonsphereprogram.LongArm"))
			{
				incompatMessage += "LongArm\n";
				num++;
			}
			if (Chainloader.PluginInfos.ContainsKey("greyhak.dysonsphereprogram.droneclearing"))
			{
				incompatMessage += "DSP Drone Clearing\n";
				num++;
			}
			if (Chainloader.PluginInfos.ContainsKey("com.small.dsp.transferInfo"))
			{
				incompatMessage += "TransferInfo\n";
				num++;
			}
			if (Chainloader.PluginInfos.ContainsKey("greyhak.dysonsphereprogram.beltreversedirection"))
			{
				incompatMessage += "DSP Belt Reverse\n";
				num++;
			}
			return num > 0;
		}

		private static bool TestWarnMods(ref string warnMessage)
		{
			int num = 0;
			if (Chainloader.PluginInfos.ContainsKey("cn.blacksnipe.dsp.Multfuntion_mod"))
			{
				warnMessage += "Multfuntion mod\n";
				num++;
			}
			if (Chainloader.PluginInfos.ContainsKey("org.soardev.cheatenabler"))
			{
				warnMessage += "CheatEnabler\n";
				num++;
			}
			return num > 0;
		}
	}
	public static class AssemblerVerticalConstruction
	{
		private const string NAME = "AssemblerVerticalConstruction";

		private const string GUID = "lltcggie.DSP.plugin.AssemblerVerticalConstruction";

		private const string VERSION = "1.1.4";

		private static IModCanSave Save;

		public static void Init(Harmony harmony)
		{
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Expected O, but got Unknown
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Expected O, but got Unknown
			if (!Chainloader.PluginInfos.TryGetValue("lltcggie.DSP.plugin.AssemblerVerticalConstruction", out var value))
			{
				return;
			}
			Assembly assembly = ((object)value.Instance).GetType().Assembly;
			try
			{
				BaseUnityPlugin instance = value.Instance;
				Save = (IModCanSave)(object)((instance is IModCanSave) ? instance : null);
				NC_Patch.OnLogin = (Action)Delegate.Combine(NC_Patch.OnLogin, new Action(SendRequest));
				NC_ModSaveRequest.OnReceive = (Action<string, INebulaConnection>)Delegate.Combine(NC_ModSaveRequest.OnReceive, (Action<string, INebulaConnection>)delegate(string guid, INebulaConnection conn)
				{
					if (!(guid != "lltcggie.DSP.plugin.AssemblerVerticalConstruction"))
					{
						conn.SendPacket<NC_ModSaveData>(new NC_ModSaveData("lltcggie.DSP.plugin.AssemblerVerticalConstruction", Export()));
					}
				});
				NC_ModSaveData.OnReceive = (Action<string, byte[]>)Delegate.Combine(NC_ModSaveData.OnReceive, (Action<string, byte[]>)delegate(string guid, byte[] bytes)
				{
					if (!(guid != "lltcggie.DSP.plugin.AssemblerVerticalConstruction"))
					{
						Import(bytes);
					}
				});
				Type type = assembly.GetType("AssemblerVerticalConstruction.AssemblerPatches");
				harmony.Patch((MethodBase)AccessTools.Method(type, "SyncAssemblerFunctions", (Type[])null, (Type[])null), new HarmonyMethod(typeof(AssemblerVerticalConstruction).GetMethod("SyncAssemblerFunctions_Prefix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				type = assembly.GetType("AssemblerVerticalConstruction.AssemblerComponentEx");
				harmony.Patch((MethodBase)AccessTools.Method(type, "UpdateOutputToNextInner", (Type[])null, (Type[])null), new HarmonyMethod(typeof(AssemblerVerticalConstruction).GetMethod("UpdateOutputToNextInner_Prefix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.Info("AssemblerVerticalConstruction - OK");
			}
			catch (Exception obj)
			{
				Log.Warn("AssemblerVerticalConstruction - Fail! Last target version: 1.1.4");
				NC_Patch.ErrorMessage += "\nAssemblerVerticalConstruction (last target version: 1.1.4)";
				Log.Debug(obj);
			}
		}

		public static void SendRequest()
		{
			if (NebulaModAPI.IsMultiplayerActive && NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)
			{
				NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_ModSaveRequest>(new NC_ModSaveRequest("lltcggie.DSP.plugin.AssemblerVerticalConstruction"));
			}
		}

		public static void SendData()
		{
			if (NebulaModAPI.IsMultiplayerActive)
			{
				NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_ModSaveData>(new NC_ModSaveData("lltcggie.DSP.plugin.AssemblerVerticalConstruction", Export()));
			}
		}

		public static byte[] Export()
		{
			if (Save != null)
			{
				IWriterProvider binaryWriter = NebulaModAPI.GetBinaryWriter();
				try
				{
					Save.Export(binaryWriter.BinaryWriter);
					return binaryWriter.CloseAndGetBytes();
				}
				finally
				{
					((IDisposable)binaryWriter)?.Dispose();
				}
			}
			return new byte[0];
		}

		public static void Import(byte[] bytes)
		{
			if (Save != null)
			{
				IReaderProvider binaryReader = NebulaModAPI.GetBinaryReader(bytes);
				try
				{
					Save.Import(binaryReader.BinaryReader);
				}
				finally
				{
					((IDisposable)binaryReader)?.Dispose();
				}
			}
		}

		public static bool SyncAssemblerFunctions_Prefix(FactorySystem factorySystem, Player player, int assemblerId)
		{
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Expected O, but got Unknown
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Expected O, but got Unknown
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Expected O, but got Unknown
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Expected O, but got Unknown
			int entityId = factorySystem.assemblerPool[assemblerId].entityId;
			if (entityId == 0)
			{
				return false;
			}
			int num = entityId;
			bool flag = default(bool);
			int num2 = default(int);
			int num3 = default(int);
			do
			{
				factorySystem.factory.ReadObjectConn(num, 14, ref flag, ref num2, ref num3);
				num = num2;
				if (num <= 0)
				{
					continue;
				}
				int assemblerId2 = factorySystem.factory.entityPool[num].assemblerId;
				if (assemblerId2 <= 0 || factorySystem.assemblerPool[assemblerId2].id != assemblerId2)
				{
					continue;
				}
				if (factorySystem.assemblerPool[assemblerId].recipeId > 0)
				{
					if (factorySystem.assemblerPool[assemblerId2].recipeId != factorySystem.assemblerPool[assemblerId].recipeId)
					{
						factorySystem.TakeBackItems_Assembler(player, assemblerId2);
						int recipeId = factorySystem.assemblerPool[assemblerId].recipeId;
						((AssemblerComponent)(ref factorySystem.assemblerPool[assemblerId2])).SetRecipe(recipeId, factorySystem.factory.entitySignPool);
						Multiplayer.Session.Network.SendPacketToLocalStar<AssemblerRecipeEventPacket>(new AssemblerRecipeEventPacket(factorySystem.planet.id, assemblerId2, recipeId));
					}
				}
				else if (factorySystem.assemblerPool[assemblerId2].recipeId != 0)
				{
					factorySystem.TakeBackItems_Assembler(player, assemblerId2);
					((AssemblerComponent)(ref factorySystem.assemblerPool[assemblerId2])).SetRecipe(0, factorySystem.factory.entitySignPool);
					Multiplayer.Session.Network.SendPacketToLocalStar<AssemblerRecipeEventPacket>(new AssemblerRecipeEventPacket(factorySystem.planet.id, assemblerId2, 0));
				}
			}
			while (num != 0);
			num = entityId;
			int num4 = default(int);
			do
			{
				factorySystem.factory.ReadObjectConn(num, 15, ref flag, ref num4, ref num3);
				num = num4;
				if (num <= 0)
				{
					continue;
				}
				int assemblerId3 = factorySystem.factory.entityPool[num].assemblerId;
				if (assemblerId3 <= 0 || factorySystem.assemblerPool[assemblerId3].id != assemblerId3)
				{
					continue;
				}
				if (factorySystem.assemblerPool[assemblerId].recipeId > 0)
				{
					if (factorySystem.assemblerPool[assemblerId3].recipeId != factorySystem.assemblerPool[assemblerId].recipeId)
					{
						factorySystem.TakeBackItems_Assembler(factorySystem.factory.gameData.mainPlayer, assemblerId3);
						int recipeId2 = factorySystem.assemblerPool[assemblerId].recipeId;
						((AssemblerComponent)(ref factorySystem.assemblerPool[assemblerId3])).SetRecipe(recipeId2, factorySystem.factory.entitySignPool);
						Multiplayer.Session.Network.SendPacketToLocalStar<AssemblerRecipeEventPacket>(new AssemblerRecipeEventPacket(factorySystem.planet.id, assemblerId3, recipeId2));
					}
				}
				else if (factorySystem.assemblerPool[assemblerId3].recipeId != 0)
				{
					factorySystem.TakeBackItems_Assembler(factorySystem.factory.gameData.mainPlayer, assemblerId3);
					((AssemblerComponent)(ref factorySystem.assemblerPool[assemblerId3])).SetRecipe(0, factorySystem.factory.entitySignPool);
					Multiplayer.Session.Network.SendPacketToLocalStar<AssemblerRecipeEventPacket>(new AssemblerRecipeEventPacket(factorySystem.planet.id, assemblerId3, 0));
				}
			}
			while (num != 0);
			return false;
		}

		public static bool UpdateOutputToNextInner_Prefix(int assemblerId, int assemblerNextId, AssemblerComponent[] assemblerPool)
		{
			if (assemblerId >= assemblerPool.Length || assemblerPool[assemblerId].served == null)
			{
				return false;
			}
			if (assemblerNextId >= assemblerPool.Length || assemblerPool[assemblerNextId].timeSpend == 0)
			{
				return false;
			}
			return true;
		}
	}
	public static class AutoStationConfig
	{
		public const string NAME = "AutoStationConfig";

		public const string GUID = "pasukaru.dsp.AutoStationConfig";

		public const string VERSION = "1.4.0";

		public static void Init(Harmony harmony)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_0079: Expected O, but got Unknown
			if (!Chainloader.PluginInfos.TryGetValue("pasukaru.dsp.AutoStationConfig", out var value))
			{
				return;
			}
			Assembly assembly = ((object)value.Instance).GetType().Assembly;
			try
			{
				Type type = assembly.GetType("Pasukaru.DSP.AutoStationConfig.PlanetTransportPatch");
				harmony.Patch((MethodBase)AccessTools.Method(type, "NewStationComponent", (Type[])null, (Type[])null), new HarmonyMethod(typeof(AutoStationConfig).GetMethod("NewStationComponent_Prefix")), new HarmonyMethod(typeof(AutoStationConfig).GetMethod("NewStationComponent_Postfix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.Info("AutoStationConfig - OK");
			}
			catch (Exception obj)
			{
				Log.Warn("AutoStationConfig - Fail! Last target version: 1.4.0");
				NC_Patch.ErrorMessage += "\nAutoStationConfig (last target version: 1.4.0)";
				Log.Debug(obj);
			}
		}

		public static bool NewStationComponent_Prefix()
		{
			if (!NebulaModAPI.IsMultiplayerActive)
			{
				return true;
			}
			IFactoryManager factories = NebulaModAPI.MultiplayerSession.Factories;
			if (factories.PacketAuthor != NebulaModAPI.MultiplayerSession.LocalPlayer.Id)
			{
				if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsHost)
				{
					return factories.PacketAuthor == -1;
				}
				return false;
			}
			return true;
		}

		public static void NewStationComponent_Postfix(PlanetTransport __0, StationComponent __1, bool __runOriginal)
		{
			if (NebulaModAPI.IsMultiplayerActive && __runOriginal)
			{
				PlanetFactory factory = __0.factory;
				NebulaModAPI.MultiplayerSession.Network.SendPacketToLocalStar<NC_StationConfig>(new NC_StationConfig(in __1, in factory));
				NebulaModAPI.MultiplayerSession.Network.SendPacketToLocalStar<NC_StationShipCount>(new NC_StationShipCount(__1, factory.planetId));
			}
		}
	}
	public static class Auxilaryfunction
	{
		public const string NAME = "Auxilaryfunction";

		public const string GUID = "cn.blacksnipe.dsp.Auxilaryfunction";

		public const string VERSION = "2.5.3";

		private static ConfigEntry<bool> stationcopyItem_bool;

		private static ConfigEntry<bool> auto_supply_station;

		public static void Init(Harmony harmony)
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Expected O, but got Unknown
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Expected O, but got Unknown
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Expected O, but got Unknown
			//IL_0189: Expected O, but got Unknown
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Expected O, but got Unknown
			if (!Chainloader.PluginInfos.TryGetValue("cn.blacksnipe.dsp.Auxilaryfunction", out var value))
			{
				return;
			}
			Assembly assembly = ((object)value.Instance).GetType().Assembly;
			try
			{
				Type type = assembly.GetType("Auxilaryfunction.Auxilaryfunction");
				stationcopyItem_bool = (ConfigEntry<bool>)AccessTools.Field(type, "stationcopyItem_bool").GetValue(value.Instance);
				auto_supply_station = (ConfigEntry<bool>)AccessTools.Field(type, "auto_supply_station").GetValue(value.Instance);
				harmony.Patch((MethodBase)AccessTools.Method(type, "AddDroneShipToStation", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Auxilaryfunction).GetMethod("AddDroneShiptooldstation_Postfix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)AccessTools.Method(type, "ChangeAllStationConfig", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Auxilaryfunction).GetMethod("Changeallstationconfig_Postfix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)AccessTools.Method(type, "ChangeAllVeinCollectorSpeedConfig", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Auxilaryfunction).GetMethod("Changeallstationconfig_Postfix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)AccessTools.Method(type, "AddFuelToAllStar", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Auxilaryfunction).GetMethod("AddfueltoallStar_Postfix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				type = assembly.GetType("Auxilaryfunction.AuxilaryfunctionPatch");
				harmony.Patch((MethodBase)AccessTools.Method(type, "NewStationComponentPatch", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Auxilaryfunction).GetMethod("NewStationComponent_Prefix")), new HarmonyMethod(typeof(Auxilaryfunction).GetMethod("NewStationComponent_Postfix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)AccessTools.Method(type, "PasteToFactoryObjectPatch", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Auxilaryfunction).GetMethod("PasteToFactoryObject_Prefix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.Info("Auxilaryfunction - OK");
			}
			catch (Exception obj)
			{
				Log.Warn("Auxilaryfunction - Fail! Last target version: 2.5.3");
				NC_Patch.ErrorMessage += "\nAuxilaryfunction (last target version: 2.5.3)";
				Log.Debug(obj);
			}
		}

		public static void AddDroneShiptooldstation_Postfix()
		{
			if (NebulaModAPI.IsMultiplayerActive && GameMain.localPlanet?.factory != null)
			{
				NebulaModAPI.MultiplayerSession.Network.SendPacketToLocalStar<NC_StationShipCount>(new NC_StationShipCount(GameMain.localPlanet.factory.transport.stationPool, GameMain.localPlanet.id));
			}
		}

		public static void Changeallstationconfig_Postfix()
		{
			if (NebulaModAPI.IsMultiplayerActive && GameMain.localPlanet?.factory != null)
			{
				NebulaModAPI.MultiplayerSession.Network.SendPacketToLocalStar<NC_StationConfig>(new NC_StationConfig(in GameMain.localPlanet.factory.transport.stationPool, in GameMain.localPlanet.factory));
			}
		}

		public static void AddfueltoallStar_Postfix()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			if (!NebulaModAPI.IsMultiplayerActive || GameMain.localPlanet?.factory == null)
			{
				return;
			}
			PowerGeneratorComponent[] genPool = GameMain.localPlanet.factory.powerSystem.genPool;
			foreach (PowerGeneratorComponent val in genPool)
			{
				if (val.fuelMask == 4)
				{
					NebulaModAPI.MultiplayerSession.Network.SendPacketToLocalStar<PowerGeneratorFuelUpdatePacket>(new PowerGeneratorFuelUpdatePacket(val.id, (int)val.fuelId, val.fuelCount, val.fuelInc, GameMain.localPlanet.id));
				}
			}
		}

		public static bool NewStationComponent_Prefix()
		{
			if (!auto_supply_station.Value)
			{
				return false;
			}
			if (!NebulaModAPI.IsMultiplayerActive)
			{
				return true;
			}
			IFactoryManager factories = NebulaModAPI.MultiplayerSession.Factories;
			if (factories.PacketAuthor != NebulaModAPI.MultiplayerSession.LocalPlayer.Id)
			{
				if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsHost)
				{
					return factories.PacketAuthor == -1;
				}
				return false;
			}
			return true;
		}

		public static void NewStationComponent_Postfix(StationComponent __0, PlanetTransport __1, bool __runOriginal)
		{
			if (NebulaModAPI.IsMultiplayerActive && __runOriginal)
			{
				PlanetFactory factory = __1.factory;
				NebulaModAPI.MultiplayerSession.Network.SendPacketToLocalStar<NC_StationConfig>(new NC_StationConfig(in __0, in factory));
				NebulaModAPI.MultiplayerSession.Network.SendPacketToLocalStar<NC_StationShipCount>(new NC_StationShipCount(__0, factory.planetId));
			}
		}

		public static bool PasteToFactoryObject_Prefix()
		{
			if (!stationcopyItem_bool.Value)
			{
				return false;
			}
			if (!NebulaModAPI.IsMultiplayerActive)
			{
				return true;
			}
			return !NebulaModAPI.MultiplayerSession.Factories.IsIncomingRequest.Value;
		}
	}
	public static class BlueprintTweaks
	{
		public const string NAME = "BlueprintTweaks";

		public const string GUID = "org.kremnev8.plugin.BlueprintTweaks";

		public const string VERSION = "1.6.3";

		public static void Init(Harmony _)
		{
			if (!Chainloader.PluginInfos.TryGetValue("org.kremnev8.plugin.BlueprintTweaks", out var value))
			{
				return;
			}
			Assembly assembly = ((object)value.Instance).GetType().Assembly;
			try
			{
				((ConfigEntry<bool>)AccessTools.Field(assembly.GetType("BlueprintTweaks.BlueprintTweaksPlugin"), "useFastDismantle").GetValue(value.Instance)).Value = false;
				Log.Info("BlueprintTweaks - OK");
			}
			catch (Exception obj)
			{
				Log.Warn("BlueprintTweaks - Fail! Last target version: 1.6.3");
				NC_Patch.ErrorMessage += "\nBlueprintTweaks (last target version: 1.6.3)";
				Log.Debug(obj);
			}
		}
	}
	public static class DSPAutoSorter
	{
		public const string NAME = "DSPAutoSorter";

		public const string GUID = "Appun.DSP.plugin.AutoSorter";

		public const string VERSION = "1.2.11";

		public static void Init(Harmony harmony)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			if (!Chainloader.PluginInfos.TryGetValue("Appun.DSP.plugin.AutoSorter", out var value))
			{
				return;
			}
			Assembly assembly = ((object)value.Instance).GetType().Assembly;
			try
			{
				Type type = assembly.GetType("DSPAutoSorter.DSPAutoSorter");
				harmony.Patch((MethodBase)AccessTools.Method(type, "UIStorageWindow_OnOpen_Postfix", (Type[])null, (Type[])null), new HarmonyMethod(typeof(DSPAutoSorter).GetMethod("Block")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.Info("DSPAutoSorter - OK");
			}
			catch (Exception obj)
			{
				Log.Warn("DSPAutoSorter - Fail! Last target version: 1.2.11");
				NC_Patch.ErrorMessage += "\nDSPAutoSorter (last target version: 1.2.11)";
				Log.Debug(obj);
			}
		}

		public static bool Block()
		{
			if (!NebulaModAPI.IsMultiplayerActive)
			{
				return true;
			}
			return false;
		}
	}
	public static class DSPFreeMechaCustom
	{
		private const string NAME = "DSPFreeMechaCustom";

		private const string GUID = "Appun.DSP.plugin.FreeMechaCustom";

		private const string VERSION = "0.0.2";

		public static void Init(Harmony harmony)
		{
			if (!Chainloader.PluginInfos.TryGetValue("Appun.DSP.plugin.FreeMechaCustom", out var _))
			{
				return;
			}
			try
			{
				harmony.PatchAll(typeof(DSPFreeMechaCustom));
				Log.Info("DSPFreeMechaCustom - OK");
			}
			catch (Exception obj)
			{
				Log.Warn("DSPFreeMechaCustom - Fail! Last target version: 0.0.2");
				NC_Patch.ErrorMessage += "\nDSPFreeMechaCustom (last target version: 0.0.2)";
				Log.Debug(obj);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(UIMechaEditor), "ApplyMechaAppearance")]
		public static bool ApplyMechaAppearance_Prefix()
		{
			return false;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIMechaMatsGroup), "OnApplyClick")]
		public static void OnApplyClick_Postfix(UIMechaMatsGroup __instance)
		{
			__instance.mechaEditor.ApplyMechaAppearance();
		}
	}
	public static class DSPOptimizations
	{
		public const string NAME = "DSPOptimizations";

		public const string GUID = "com.Selsion.DSPOptimizations";

		public const string VERSION = "1.1.16";

		private static Action<GameData> InitFactoryInfo;

		public static void Init(Harmony harmony)
		{
			if (!Chainloader.PluginInfos.TryGetValue("com.Selsion.DSPOptimizations", out var value))
			{
				return;
			}
			Assembly assembly = ((object)value.Instance).GetType().Assembly;
			try
			{
				InitFactoryInfo = AccessTools.MethodDelegate<Action<GameData>>(AccessTools.Method(assembly.GetType("DSPOptimizations.StationStorageOpt"), "InitFactoryInfo", (Type[])null, (Type[])null), (object)null, true);
				harmony.PatchAll(typeof(DSPOptimizations));
				Log.Info("DSPOptimizations - OK");
			}
			catch (Exception obj)
			{
				Log.Warn("DSPOptimizations - Fail! Last target version: 1.1.16");
				NC_Patch.ErrorMessage += "\nDSPOptimizations (last target version: 1.1.16)";
				Log.Debug(obj);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameData), "LeaveStar")]
		public static void LeaveStar_Prefix()
		{
			if (GameMain.data.factoryCount == 0)
			{
				Log.Debug("Unload factories data for DSPOptimizations");
				InitFactoryInfo(GameMain.data);
			}
		}
	}
	public static class DSPStarMapMemo
	{
		private const string NAME = "DSPStarMapMemo";

		private const string GUID = "Appun.DSP.plugin.StarMapMemo";

		private const string VERSION = "0.0.5";

		private static IModCanSave Save;

		public static void Init(Harmony harmony)
		{
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Expected O, but got Unknown
			if (!Chainloader.PluginInfos.TryGetValue("Appun.DSP.plugin.StarMapMemo", out var value))
			{
				return;
			}
			Assembly assembly = ((object)value.Instance).GetType().Assembly;
			try
			{
				BaseUnityPlugin instance = value.Instance;
				Save = (IModCanSave)(object)((instance is IModCanSave) ? instance : null);
				NC_Patch.OnLogin = (Action)Delegate.Combine(NC_Patch.OnLogin, new Action(SendRequest));
				NC_ModSaveRequest.OnReceive = (Action<string, INebulaConnection>)Delegate.Combine(NC_ModSaveRequest.OnReceive, (Action<string, INebulaConnection>)delegate(string guid, INebulaConnection conn)
				{
					if (!(guid != "Appun.DSP.plugin.StarMapMemo"))
					{
						conn.SendPacket<NC_ModSaveData>(new NC_ModSaveData("Appun.DSP.plugin.StarMapMemo", Export()));
					}
				});
				NC_ModSaveData.OnReceive = (Action<string, byte[]>)Delegate.Combine(NC_ModSaveData.OnReceive, (Action<string, byte[]>)delegate(string guid, byte[] bytes)
				{
					if (!(guid != "Appun.DSP.plugin.StarMapMemo"))
					{
						Import(bytes);
					}
				});
				Type type = assembly.GetType("DSPStarMapMemo.MemoPool");
				harmony.Patch((MethodBase)AccessTools.Method(type, "AddOrUpdate", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(DSPStarMapMemo).GetMethod("SendData")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.Info("DSPStarMapMemo - OK");
			}
			catch (Exception obj)
			{
				Log.Warn("DSPStarMapMemo - Fail! Last target version: 0.0.5");
				NC_Patch.ErrorMessage += "\nDSPStarMapMemo (last target version: 0.0.5)";
				Log.Debug(obj);
			}
		}

		public static void SendRequest()
		{
			if (NebulaModAPI.IsMultiplayerActive && NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)
			{
				NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_ModSaveRequest>(new NC_ModSaveRequest("Appun.DSP.plugin.StarMapMemo"));
			}
		}

		public static void SendData()
		{
			if (NebulaModAPI.IsMultiplayerActive)
			{
				NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_ModSaveData>(new NC_ModSaveData("Appun.DSP.plugin.StarMapMemo", Export()));
			}
		}

		public static byte[] Export()
		{
			if (Save != null)
			{
				IWriterProvider binaryWriter = NebulaModAPI.GetBinaryWriter();
				try
				{
					Save.Export(binaryWriter.BinaryWriter);
					return binaryWriter.CloseAndGetBytes();
				}
				finally
				{
					((IDisposable)binaryWriter)?.Dispose();
				}
			}
			return new byte[0];
		}

		public static void Import(byte[] bytes)
		{
			if (Save != null)
			{
				IReaderProvider binaryReader = NebulaModAPI.GetBinaryReader(bytes);
				try
				{
					Save.Import(binaryReader.BinaryReader);
				}
				finally
				{
					((IDisposable)binaryReader)?.Dispose();
				}
			}
		}
	}
	public static class DSP_Battle_Patch
	{
		private static class Warper
		{
			private static bool IsIncoming { get; set; }

			public static void HandleRequest(NC_BattleUpdate packet)
			{
				string text = $"{packet.Username} {packet.Type} ";
				Log.Info(text + $"{packet.Value1} {packet.Value2}");
				IsIncoming = true;
				try
				{
					switch (packet.Type)
					{
					case NC_BattleUpdate.EType.AddRelic:
						Relic.AddRelic(packet.Value1, packet.Value2);
						UIRelic.RefreshSlotsWindowUI();
						text += Localization.Translate("遗物名称" + packet.Value1 + "-" + packet.Value2).Split(new char[1] { '\n' })[0];
						break;
					case NC_BattleUpdate.EType.RemoveRelic:
						Relic.RemoveRelic(packet.Value1, packet.Value2);
						UIRelic.RefreshSlotsWindowUI();
						text += Localization.Translate("遗物名称" + packet.Value1 + "-" + packet.Value2).Split(new char[1] { '\n' })[0];
						break;
					case NC_BattleUpdate.EType.ApplyAuthorizationPoint:
						UISkillPointsWindow.ClearTempLevelAdded();
						Array.Copy(packet.Values1, UISkillPointsWindow.tempLevelAddedL, Math.Min(packet.Values1.Length, UISkillPointsWindow.tempLevelAddedL.Length));
						Array.Copy(packet.Values2, UISkillPointsWindow.tempLevelAddedR, Math.Min(packet.Values2.Length, UISkillPointsWindow.tempLevelAddedR.Length));
						SkillPoints.ConfirmAll();
						break;
					case NC_BattleUpdate.EType.ResetAuthorizationPoint:
						SkillPoints.ResetAll();
						break;
					}
					ChatManager.ShowMessageInChat(text);
				}
				catch (Exception ex)
				{
					ChatManager.ShowWarningInChat("DSP_Battle_Patch error!\n" + ex);
				}
				IsIncoming = false;
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(Relic), "AddRelic")]
			private static void AddRelic_Postfix(int type, int num)
			{
				if (Multiplayer.IsActive && !IsIncoming)
				{
					Log.Info(Environment.StackTrace);
					Multiplayer.Session.Network.SendPacket<NC_BattleUpdate>(new NC_BattleUpdate(NC_BattleUpdate.EType.AddRelic, type, num));
				}
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(Relic), "RemoveRelic")]
			private static void RemoveRelic_Postfix(int removeType, int removeNum)
			{
				if (Multiplayer.IsActive && !IsIncoming)
				{
					Multiplayer.Session.Network.SendPacket<NC_BattleUpdate>(new NC_BattleUpdate(NC_BattleUpdate.EType.RemoveRelic, removeType, removeNum));
				}
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(SkillPoints), "ConfirmAll")]
			private static void SkillConfirmAll_Prefix()
			{
				if (Multiplayer.IsActive && !IsIncoming)
				{
					Multiplayer.Session.Network.SendPacket<NC_BattleUpdate>(new NC_BattleUpdate(NC_BattleUpdate.EType.ApplyAuthorizationPoint, UISkillPointsWindow.tempLevelAddedL, UISkillPointsWindow.tempLevelAddedR));
				}
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(SkillPoints), "ResetAll")]
			private static void ResetAll_Prefix()
			{
				if (Multiplayer.IsActive && !IsIncoming)
				{
					Multiplayer.Session.Network.SendPacket<NC_BattleUpdate>(new NC_BattleUpdate(NC_BattleUpdate.EType.ResetAuthorizationPoint, 0, 0));
				}
			}
		}

		private const string NAME = "DSP_Battle";

		private const string GUID = "com.ckcz123.DSP_Battle";

		private const string VERSION = "3.1.2";

		private static IModCanSave Save;

		public static void Init(Harmony harmony)
		{
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Expected O, but got Unknown
			if (!Chainloader.PluginInfos.TryGetValue("com.ckcz123.DSP_Battle", out var value))
			{
				return;
			}
			_ = ((object)value.Instance).GetType().Assembly;
			try
			{
				BaseUnityPlugin instance = value.Instance;
				Save = (IModCanSave)(object)((instance is IModCanSave) ? instance : null);
				NC_Patch.OnLogin = (Action)Delegate.Combine(NC_Patch.OnLogin, new Action(SendRequest));
				NC_ModSaveRequest.OnReceive = (Action<string, INebulaConnection>)Delegate.Combine(NC_ModSaveRequest.OnReceive, (Action<string, INebulaConnection>)delegate(string guid, INebulaConnection conn)
				{
					if (!(guid != "com.ckcz123.DSP_Battle"))
					{
						conn.SendPacket<NC_ModSaveData>(new NC_ModSaveData("com.ckcz123.DSP_Battle", Export()));
					}
				});
				NC_ModSaveData.OnReceive = (Action<string, byte[]>)Delegate.Combine(NC_ModSaveData.OnReceive, (Action<string, byte[]>)delegate(string guid, byte[] bytes)
				{
					if (!(guid != "com.ckcz123.DSP_Battle"))
					{
						Import(bytes);
					}
				});
				harmony.PatchAll(typeof(Warper));
				MethodInfo methodInfo = AccessTools.Method(AccessTools.TypeByName("CommonAPI.Patches.ResourcesPatch"), "Prefix", (Type[])null, (Type[])null);
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(DSP_Battle_Patch), "ResourcesPatch_Prefix_Transpiler", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null);
				Log.Info("DSP_Battle - OK");
			}
			catch (Exception obj)
			{
				Log.Warn("DSP_Battle - Fail! Last target version: 3.1.2");
				NC_Patch.ErrorMessage += "\nDSP_Battle (last target version: 3.1.2)";
				Log.Debug(obj);
			}
		}

		public static void SendRequest()
		{
			if (NebulaModAPI.IsMultiplayerActive && NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)
			{
				NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_ModSaveRequest>(new NC_ModSaveRequest("com.ckcz123.DSP_Battle"));
			}
		}

		public static byte[] Export()
		{
			if (Save != null)
			{
				IWriterProvider binaryWriter = NebulaModAPI.GetBinaryWriter();
				try
				{
					Save.Export(binaryWriter.BinaryWriter);
					return binaryWriter.CloseAndGetBytes();
				}
				finally
				{
					((IDisposable)binaryWriter)?.Dispose();
				}
			}
			return new byte[0];
		}

		public static void Import(byte[] bytes)
		{
			if (Save != null)
			{
				IReaderProvider binaryReader = NebulaModAPI.GetBinaryReader(bytes);
				try
				{
					Save.Import(binaryReader.BinaryReader);
				}
				finally
				{
					((IDisposable)binaryReader)?.Dispose();
				}
			}
		}

		public static void OnReceive(NC_BattleUpdate packet)
		{
			Warper.HandleRequest(packet);
		}

		public static IEnumerable<CodeInstruction> ResourcesPatch_Prefix_Transpiler(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
			try
			{
				return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Callvirt && ((MethodInfo)i.operand).Name == "LogDebug"), (string)null)
				}).Repeat((Action<CodeMatcher>)delegate(CodeMatcher matcher)
				{
					matcher.SetAndAdvance(OpCodes.Pop, (object)null);
				}, (Action<string>)null).InstructionEnumeration();
			}
			catch (Exception)
			{
				Log.Warn("CommonAPI.Patches.ResourcesPatch.Prefix Transpiler fail!");
				return instructions;
			}
		}
	}
	public class FactoryLocator_Patch
	{
		public class Warper
		{
			private static int astroId;

			private static int detailId;

			[HarmonyPostfix]
			[HarmonyPatch(typeof(UILocatorWindow), "SetViewingTarget")]
			private static void SetViewingTarget_Postfix()
			{
				if (!NebulaModAPI.IsMultiplayerActive || !NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)
				{
					return;
				}
				UILocatorWindow mainWindow = Plugin.mainWindow;
				PlanetData veiwPlanet = mainWindow.veiwPlanet;
				int num;
				if (veiwPlanet == null)
				{
					StarData veiwStar = mainWindow.veiwStar;
					num = ((veiwStar != null) ? (veiwStar.id * 100) : 0);
				}
				else
				{
					num = veiwPlanet.id;
				}
				int num2 = num;
				if (mainWindow.veiwPlanet != null && Plugin.mainLogic.factories.Count == 0)
				{
					NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_PlanetInfoRequest>(new NC_PlanetInfoRequest(num2));
					if (num2 != astroId)
					{
						mainWindow.nameText.text = "Loading...";
					}
				}
				else if (mainWindow.veiwStar != null)
				{
					NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_PlanetInfoRequest>(new NC_PlanetInfoRequest(num2));
					if (num2 != astroId)
					{
						mainWindow.nameText.text = "Loading...";
					}
				}
				astroId = num2;
			}

			public static void UpdateStatus(NC_PlanetInfoData packet)
			{
				UILocatorWindow mainWindow = Plugin.mainWindow;
				bool flag = false;
				if (packet.PlanetId > 0 && packet.PlanetId == mainWindow.veiwPlanet?.id)
				{
					mainWindow.nameText.text = mainWindow.veiwPlanet.displayName;
					flag = true;
				}
				else if (packet.StarId > 0 && packet.StarId == mainWindow.veiwStar?.id)
				{
					mainWindow.nameText.text = mainWindow.veiwStar.displayName + Localization.Translate("空格行星系");
					flag = true;
				}
				if (flag)
				{
					for (int i = 0; i < mainWindow.queryBtns.Length; i++)
					{
						((Behaviour)mainWindow.queryBtns[i].button).enabled = packet.NetworkCount > 0;
					}
				}
				mainWindow.SetStatusTipText(packet.ConsumerRatios, packet.ConsumerCounts);
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(UILocatorWindow), "OnQueryClick")]
			public static bool OnQueryClick(UILocatorWindow __instance, int queryType)
			{
				if (!NebulaModAPI.IsMultiplayerActive || !NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient || (Plugin.mainLogic.factories.Count > 0 && __instance.veiwStar == null))
				{
					return true;
				}
				if (__instance.autoclear_enable)
				{
					WarningSystemPatch.ClearAll();
				}
				UILocatorWindow.networkIds = null;
				__instance.SetSubcategory(queryType);
				NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_LocatorFilter>(new NC_LocatorFilter(astroId, queryType, UILocatorWindow.comboBox.itemIndex, null));
				return false;
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(UILocatorWindow), "OnComboBoxIndexChange")]
			public static bool OnComboBoxIndexChange()
			{
				if (!NebulaModAPI.IsMultiplayerActive || !NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient || (Plugin.mainLogic.factories.Count > 0 && Plugin.mainWindow.veiwStar == null))
				{
					return true;
				}
				bool active = ((ManualBehaviour)UIRoot.instance.uiGame.itemPicker).active;
				bool active2 = ((ManualBehaviour)UIRoot.instance.uiGame.recipePicker).active;
				switch (UILocatorWindow.queryingType)
				{
				case 0:
					UILocatorWindow.buildingIndex = UILocatorWindow.comboBox.itemIndex;
					if (active)
					{
						Plugin.mainLogic.OnBuildingPickReturn((ItemProto)null);
						UIItemPicker.Close();
						NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_LocatorFilter>(new NC_LocatorFilter(astroId, UILocatorWindow.queryingType, UILocatorWindow.comboBox.itemIndex, null));
					}
					break;
				case 1:
					UILocatorWindow.veinIndex = UILocatorWindow.comboBox.itemIndex;
					if (active)
					{
						Plugin.mainLogic.OnVeinPickReturn((ItemProto)null);
						UIItemPicker.Close();
						NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_LocatorFilter>(new NC_LocatorFilter(astroId, UILocatorWindow.queryingType, UILocatorWindow.comboBox.itemIndex, null));
					}
					break;
				case 2:
					UILocatorWindow.assemblerIndex = UILocatorWindow.comboBox.itemIndex;
					if (active2)
					{
						Plugin.mainLogic.OnAssemblerPickReturn((RecipeProto)null);
						UIRecipePicker.Close();
						NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_LocatorFilter>(new NC_LocatorFilter(astroId, UILocatorWindow.queryingType, UILocatorWindow.comboBox.itemIndex, null));
					}
					break;
				case 4:
					UILocatorWindow.storageIndex = UILocatorWindow.comboBox.itemIndex;
					if (active)
					{
						Plugin.mainLogic.OnStoragePickReturn((ItemProto)null);
						UIItemPicker.Close();
						NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_LocatorFilter>(new NC_LocatorFilter(astroId, UILocatorWindow.queryingType, UILocatorWindow.comboBox.itemIndex, null));
					}
					break;
				case 5:
					UILocatorWindow.stationIndex = UILocatorWindow.comboBox.itemIndex;
					if (active)
					{
						Plugin.mainLogic.OnStationPickReturn((ItemProto)null);
						UIItemPicker.Close();
						NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_LocatorFilter>(new NC_LocatorFilter(astroId, UILocatorWindow.queryingType, UILocatorWindow.comboBox.itemIndex, null));
					}
					break;
				}
				return false;
			}

			public static void HandleRequest(NC_LocatorFilter packet, INebulaConnection conn)
			{
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Expected O, but got Unknown
				StarData val = null;
				PlanetData val2 = null;
				if (packet.AstroId % 100 == 0)
				{
					val = GameMain.data.galaxy.StarById(packet.AstroId / 100);
				}
				else
				{
					val2 = GameMain.data.galaxy.PlanetById(packet.AstroId);
				}
				MainLogic val3 = new MainLogic();
				val3.SetFactories(val, val2);
				switch (packet.QueryType)
				{
				case 0:
					val3.RefreshBuilding(-1, packet.Mode);
					break;
				case 1:
					val3.RefreshVein(-1, packet.Mode);
					break;
				case 2:
					val3.RefreshAssemblers(-1, packet.Mode);
					break;
				case 3:
					val3.RefreshSignal(-1);
					break;
				case 4:
					if (packet.Mode == 0)
					{
						val3.RefreshStorage(-1);
					}
					else
					{
						val3.RefreshDispenser(-1, packet.Mode);
					}
					break;
				case 5:
					val3.RefreshStation(-1, packet.Mode);
					break;
				}
				conn.SendPacket<NC_LocatorFilter>(new NC_LocatorFilter(packet.AstroId, packet.QueryType, packet.Mode, val3.filterIds));
			}

			public static void ShowPickerWindow(NC_LocatorFilter packet)
			{
				//IL_007d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0082: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_011e: Unknown result type (might be due to invalid IL or missing references)
				//IL_015f: Unknown result type (might be due to invalid IL or missing references)
				//IL_018b: Unknown result type (might be due to invalid IL or missing references)
				//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
				if (astroId != packet.AstroId)
				{
					return;
				}
				Dictionary<int, int> filterIds = Plugin.mainLogic.filterIds;
				filterIds.Clear();
				for (int i = 0; i < packet.Ids.Length; i++)
				{
					filterIds[packet.Ids[i]] = packet.Counts[i];
				}
				Vector2 windowPos = Plugin.mainLogic.windowPos;
				switch (packet.QueryType)
				{
				case -1:
					UIMessageBox.Show("ACCESS DENY", "Server doesn't install FactoryLocator", Localization.Translate("确定"), 3);
					break;
				case 0:
					UIentryCount.OnOpen((ESignalType)1, filterIds, (Dictionary<int, Color>)null);
					UIItemPickerExtension.Popup(windowPos, (Action<ItemProto>)delegate(ItemProto itemProto)
					{
						if (itemProto != null)
						{
							NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_LocatorResult>(new NC_LocatorResult(astroId, packet.QueryType, packet.Mode, ((Proto)itemProto).ID));
							detailId = ((Proto)itemProto).ID;
						}
						UIentryCount.OnClose();
					}, (Func<ItemProto, bool>)((ItemProto itemProto) => filterIds.ContainsKey(((Proto)itemProto).ID)));
					UIRoot.instance.uiGame.itemPicker.OnTypeButtonClick(2);
					break;
				case 1:
					UIentryCount.OnOpen((ESignalType)1, filterIds, (Dictionary<int, Color>)null);
					UIItemPickerExtension.Popup(windowPos, (Action<ItemProto>)delegate(ItemProto itemProto)
					{
						if (itemProto != null)
						{
							NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_LocatorResult>(new NC_LocatorResult(astroId, packet.QueryType, packet.Mode, ((Proto)itemProto).ID));
							detailId = ((Proto)itemProto).ID;
						}
						UIentryCount.OnClose();
					}, (Func<ItemProto, bool>)((ItemProto itemProto) => filterIds.ContainsKey(((Proto)itemProto).ID)));
					UIRoot.instance.uiGame.itemPicker.OnTypeButtonClick(1);
					break;
				case 2:
					UIentryCount.OnOpen((ESignalType)2, filterIds, (Dictionary<int, Color>)null);
					UIRecipePickerExtension.Popup(windowPos, (Action<RecipeProto>)delegate(RecipeProto recipeProto)
					{
						if (recipeProto != null)
						{
							NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_LocatorResult>(new NC_LocatorResult(astroId, packet.QueryType, packet.Mode, ((Proto)recipeProto).ID));
							detailId = SignalProtoSet.SignalId((ESignalType)2, ((Proto)recipeProto).ID);
						}
						UIentryCount.OnClose();
					}, (Func<RecipeProto, bool>)((RecipeProto recipeProto) => filterIds.ContainsKey(((Proto)recipeProto).ID)));
					break;
				case 3:
					UIentryCount.OnOpen((ESignalType)0, filterIds, (Dictionary<int, Color>)null);
					UISignalPickerExtension.Popup(windowPos, (Action<int>)delegate(int signalId)
					{
						if (signalId > 0)
						{
							NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_LocatorResult>(new NC_LocatorResult(astroId, packet.QueryType, packet.Mode, signalId));
							detailId = signalId;
						}
						UIentryCount.OnClose();
					}, (Func<int, bool>)((int signalId) => filterIds.ContainsKey(signalId)));
					UIRoot.instance.uiGame.signalPicker.OnTypeButtonClick(1);
					break;
				case 4:
					UIentryCount.OnOpen((ESignalType)1, filterIds, (Dictionary<int, Color>)null);
					UIItemPickerExtension.Popup(windowPos, (Action<ItemProto>)delegate(ItemProto itemProto)
					{
						if (itemProto != null)
						{
							NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_LocatorResult>(new NC_LocatorResult(astroId, packet.QueryType, packet.Mode, ((Proto)itemProto).ID));
							detailId = ((Proto)itemProto).ID;
						}
						UIentryCount.OnClose();
					}, (Func<ItemProto, bool>)((ItemProto itemProto) => filterIds.ContainsKey(((Proto)itemProto).ID)));
					break;
				case 5:
					UIentryCount.OnOpen((ESignalType)1, filterIds, (Dictionary<int, Color>)null);
					UIItemPickerExtension.Popup(windowPos, (Action<ItemProto>)delegate(ItemProto itemProto)
					{
						if (itemProto != null)
						{
							NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_LocatorResult>(new NC_LocatorResult(astroId, packet.QueryType, packet.Mode, ((Proto)itemProto).ID));
							detailId = ((Proto)itemProto).ID;
						}
						UIentryCount.OnClose();
					}, (Func<ItemProto, bool>)((ItemProto itemProto) => filterIds.ContainsKey(((Proto)itemProto).ID)));
					break;
				}
			}

			public static void HandleRequest(NC_LocatorResult packet, INebulaConnection conn)
			{
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Expected O, but got Unknown
				StarData val = null;
				PlanetData val2 = null;
				if (packet.AstroId % 100 == 0)
				{
					val = GameMain.data.galaxy.StarById(packet.AstroId / 100);
				}
				else
				{
					val2 = GameMain.data.galaxy.PlanetById(packet.AstroId);
				}
				MainLogic val3 = new MainLogic();
				val3.SetFactories(val, val2);
				switch (packet.QueryType)
				{
				case 0:
					val3.RefreshBuilding(packet.ProtoId, packet.Mode);
					break;
				case 1:
					val3.RefreshVein(packet.ProtoId, packet.Mode);
					break;
				case 2:
					val3.RefreshAssemblers(packet.ProtoId, packet.Mode);
					break;
				case 3:
					val3.RefreshSignal(packet.ProtoId);
					break;
				case 4:
					if (packet.Mode == 0)
					{
						val3.RefreshStorage(packet.ProtoId);
					}
					else
					{
						val3.RefreshDispenser(packet.ProtoId, packet.Mode);
					}
					break;
				case 5:
					val3.RefreshStation(packet.ProtoId, packet.Mode);
					break;
				}
				conn.SendPacket<NC_LocatorResult>(new NC_LocatorResult(packet.QueryType, val3.planetIds, val3.localPos, val3.detailIds));
			}

			public static void ShowResult(NC_LocatorResult packet)
			{
				//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)
				MainLogic mainLogic = Plugin.mainLogic;
				mainLogic.planetIds.Clear();
				mainLogic.localPos.Clear();
				mainLogic.detailIds.Clear();
				for (int i = 0; i < packet.PlanetIds.Length; i++)
				{
					mainLogic.planetIds.Add(packet.PlanetIds[i]);
					mainLogic.localPos.Add(DataStructureExtensions.ToVector3(packet.LocalPos[i]));
				}
				for (int j = 0; j < packet.DetailIds.Length; j++)
				{
					mainLogic.detailIds.Add(packet.DetailIds[j]);
				}
				if (packet.QueryType != 3)
				{
					WarningSystemPatch.AddWarningData(mainLogic.SignalId, detailId, mainLogic.planetIds, mainLogic.localPos, (List<int>)null);
				}
				else
				{
					WarningSystemPatch.AddWarningData(mainLogic.SignalId, detailId, mainLogic.planetIds, mainLogic.localPos, mainLogic.detailIds);
				}
			}
		}

		public const string NAME = "FactoryLocator";

		public const string GUID = "starfi5h.plugin.FactoryLocator";

		public const string VERSION = "1.3.4";

		public static bool Enable { get; private set; }

		public static void Init(Harmony harmony)
		{
			if (!Chainloader.PluginInfos.TryGetValue("starfi5h.plugin.FactoryLocator", out var _))
			{
				return;
			}
			Enable = true;
			try
			{
				harmony.PatchAll(typeof(Warper));
				Log.Info("FactoryLocator - OK");
			}
			catch (Exception obj)
			{
				Log.Warn("FactoryLocator - Fail! Last target version: 1.3.4");
				NC_Patch.ErrorMessage += "\nFactoryLocator (last target version: 1.3.4)";
				Log.Debug(obj);
			}
		}

		public static void OnReceive(NC_PlanetInfoData packet)
		{
			Warper.UpdateStatus(packet);
		}

		public static void OnReceive(NC_LocatorFilter packet, INebulaConnection conn)
		{
			if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsHost)
			{
				if (Enable)
				{
					Warper.HandleRequest(packet, conn);
					return;
				}
				packet.QueryType = -1;
				conn.SendPacket<NC_LocatorFilter>(packet);
			}
			else if (Enable)
			{
				Warper.ShowPickerWindow(packet);
			}
		}

		public static void OnReceive(NC_LocatorResult packet, INebulaConnection conn)
		{
			if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsHost)
			{
				if (Enable)
				{
					Warper.HandleRequest(packet, conn);
				}
			}
			else if (Enable)
			{
				Warper.ShowResult(packet);
			}
		}
	}
	public static class GenesisBook_Patch
	{
		private static class Warper
		{
			[HarmonyPrefix]
			[HarmonyPatch(typeof(UIStorageWindow_Patch), "OnStorageIdChange_Prefix")]
			public static bool OnStorageIdChange_Prefix(ref bool __result)
			{
				__result = true;
				return false;
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(SyncNewQuantumStorageData), "Sync")]
			[HarmonyPatch(typeof(SyncRemoveQuantumStorageData), "Sync")]
			public static bool Block()
			{
				return false;
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(QuantumStoragePatches), "QuantumStorageOrbitChange")]
			public static bool QuantumStorageOrbitChange(int planetId, int storageId, int orbitId)
			{
				//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
				Log.Debug($"QuantumStorageOrbitChange p{planetId} s{storageId} o{orbitId}");
				if (!QuantumStoragePatches.QuantumStorageIds.TryGetValue(planetId, out var value))
				{
					return false;
				}
				int num = value.FindIndex((QuantumStorageData i) => i.StorageId == storageId);
				if (num < 0)
				{
					return false;
				}
				FactoryStorage val = GameMain.galaxy.PlanetById(planetId)?.factory?.factoryStorage;
				if (val == null)
				{
					return false;
				}
				val.storagePool[storageId] = QuantumStoragePatches._components[orbitId - 1];
				value[num] = new QuantumStorageData(storageId, orbitId);
				UIStorageWindow storageWindow = UIRoot.instance.uiGame.storageWindow;
				PlanetData localPlanet = GameMain.localPlanet;
				if (localPlanet != null && localPlanet.id == planetId && storageWindow.factory == GameMain.localPlanet.factory && storageWindow.storageId == storageId)
				{
					storageWindow.OnStorageIdChange();
				}
				return false;
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(UIStorageWindow), "OnStorageIdChange")]
			public static void OnStorageIdChange_Prefix(UIStorageWindow __instance)
			{
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
				if (!NebulaModAPI.IsMultiplayerActive || !NebulaModAPI.MultiplayerSession.IsClient || !((ManualBehaviour)__instance).active || __instance.factory == null || __instance.storageId == 0)
				{
					return;
				}
				int planetId = __instance.factory.planetId;
				int storageId = __instance.storageId;
				if (QuantumStoragePatches.QuantumStorageIds.TryGetValue(planetId, out var value))
				{
					int num = value.FindIndex((QuantumStorageData i) => i.StorageId == storageId);
					if (num >= 0)
					{
						Log.Debug($"StroageBoxRequest p{planetId} s{storageId} o{value[num].OrbitId}");
						NC_GB_Packet nC_GB_Packet = new NC_GB_Packet(NC_GB_Packet.EType.StroageBoxRequest, planetId, value[num].OrbitId, Array.Empty<byte>());
						NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_GB_Packet>(nC_GB_Packet);
					}
				}
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(QuantumStoragePatches), "OnOrbitPickerButtonClick")]
			private static void OnOrbitPickerButtonClick_Postfix(int orbitId)
			{
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Expected O, but got Unknown
				UIStorageWindow storageWindow = UIRoot.instance.uiGame.storageWindow;
				if (((ManualBehaviour)storageWindow).active && storageWindow.factory != null && NebulaModAPI.IsMultiplayerActive)
				{
					NebulaModAPI.MultiplayerSession.Network.SendPacketToLocalStar<SyncQuantumStorageOrbitChangeData>(new SyncQuantumStorageOrbitChangeData(storageWindow.factory.planetId, storageWindow.storageId, orbitId));
				}
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(QuantumStoragePatches), "ImportPlanetQuantumStorage")]
			private static void ImportPlanetQuantumStorage_Postfix()
			{
				//IL_006a: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_007e: Unknown result type (might be due to invalid IL or missing references)
				//IL_009d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c4: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
				Log.Debug("ImportPlanetQuantumStorage assign");
				if (GameMain.localPlanet?.factory == null)
				{
					return;
				}
				int num = GameMain.localPlanet?.id ?? 0;
				if (!QuantumStoragePatches.QuantumStorageIds.TryGetValue(num, out var value))
				{
					return;
				}
				HashSet<int> hashSet = new HashSet<int>();
				StorageComponent[] storagePool = GameMain.localPlanet.factory.factoryStorage.storagePool;
				foreach (QuantumStorageData item in value)
				{
					storagePool[item.StorageId] = QuantumStoragePatches._components[item.OrbitId - 1];
					if (NebulaModAPI.IsMultiplayerActive && NebulaModAPI.MultiplayerSession.IsClient && !hashSet.Contains(item.OrbitId))
					{
						hashSet.Add(item.OrbitId);
						Log.Debug($"StroageBoxRequest p{num} s{item.StorageId} o{item.OrbitId}");
						NC_GB_Packet nC_GB_Packet = new NC_GB_Packet(NC_GB_Packet.EType.StroageBoxRequest, num, item.OrbitId, Array.Empty<byte>());
						NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_GB_Packet>(nC_GB_Packet);
					}
				}
			}
		}

		[HarmonyPatch(typeof(StorageComponent))]
		internal class StorageComponent_Patch
		{
			[HarmonyPrefix]
			[HarmonyPatch(/*Could not decode attribute arguments.*/)]
			public static void AddItem_Prefix(StorageComponent __instance, int itemId, int count, int startIndex, int length, int inc)
			{
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Expected O, but got Unknown
				int quantumStorageId = GetQuantumStorageId(__instance);
				if (quantumStorageId != 0)
				{
					HandleUserInteraction<StorageSyncRealtimeChangePacket>(new StorageSyncRealtimeChangePacket(quantumStorageId, (StorageSyncRealtimeChangeEvent)2, itemId, count, startIndex, length, inc));
				}
			}

			[HarmonyPrefix]
			[HarmonyPatch("AddItemStacked")]
			public static void AddItemStacked_Prefix(StorageComponent __instance, int itemId, int count, int inc)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Expected O, but got Unknown
				int quantumStorageId = GetQuantumStorageId(__instance);
				if (quantumStorageId != 0)
				{
					HandleUserInteraction<StorageSyncRealtimeChangePacket>(new StorageSyncRealtimeChangePacket(quantumStorageId, (StorageSyncRealtimeChangeEvent)3, itemId, count, inc));
				}
			}

			[HarmonyPrefix]
			[HarmonyPatch("TakeItemFromGrid")]
			public static void TakeItemFromGrid_Prefix(StorageComponent __instance, int gridIndex, ref int itemId, ref int count)
			{
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Expected O, but got Unknown
				int quantumStorageId = GetQuantumStorageId(__instance);
				if (quantumStorageId != 0)
				{
					HandleUserInteraction<StorageSyncRealtimeChangePacket>(new StorageSyncRealtimeChangePacket(quantumStorageId, (StorageSyncRealtimeChangeEvent)6, gridIndex, itemId, count, 0));
				}
			}

			[HarmonyPostfix]
			[HarmonyPatch("SetBans")]
			public static void SetBans_Postfix(StorageComponent __instance, int _bans)
			{
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Expected O, but got Unknown
				int quantumStorageId = GetQuantumStorageId(__instance);
				if (quantumStorageId != 0)
				{
					HandleUserInteraction<StorageSyncSetBansPacket>(new StorageSyncSetBansPacket(quantumStorageId, GameMain.data.localPlanet.id, _bans));
				}
			}

			[HarmonyPostfix]
			[HarmonyPatch("Sort")]
			public static void Sort_Postfix(StorageComponent __instance)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Expected O, but got Unknown
				int quantumStorageId = GetQuantumStorageId(__instance);
				if (quantumStorageId != 0)
				{
					HandleUserInteraction<StorageSyncSortPacket>(new StorageSyncSortPacket(quantumStorageId, GameMain.data.localPlanet.id));
				}
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(StorageComponent), "SetFilter")]
			private static void SetFilter_Postfix(StorageComponent __instance, int gridIndex, int filterId)
			{
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Expected O, but got Unknown
				int quantumStorageId = GetQuantumStorageId(__instance);
				if (quantumStorageId != 0)
				{
					HandleUserInteraction<StorageSyncSetFilterPacket>(new StorageSyncSetFilterPacket(quantumStorageId, GameMain.data.localPlanet.id, gridIndex, filterId, __instance.type));
				}
			}

			private static int GetQuantumStorageId(StorageComponent __instance)
			{
				if (__instance.id != 0 || __instance.size != 80)
				{
					return 0;
				}
				if (Multiplayer.IsActive && !ToggleSwitch.op_Implicit(Multiplayer.Session.Storage.IsIncomingRequest) && Multiplayer.Session.Storage.IsHumanInput && GameMain.data.localPlanet != null)
				{
					StorageComponent[] storagePool = GameMain.localPlanet.factory.factoryStorage.storagePool;
					int storageCursor = GameMain.localPlanet.factory.factoryStorage.storageCursor;
					for (int i = 1; i < storageCursor; i++)
					{
						if (storagePool[i] == __instance)
						{
							return i;
						}
					}
				}
				return 0;
			}

			private static void HandleUserInteraction<T>(T packet) where T : class, new()
			{
				Log.Debug(packet);
				if (Multiplayer.Session.LocalPlayer.IsHost)
				{
					Multiplayer.Session.Network.SendPacketToStar<T>(packet, GameMain.localStar.id);
				}
				else
				{
					Multiplayer.Session.Network.SendPacket<T>(packet);
				}
			}
		}

		public const string NAME = "GenesisBook";

		public const string GUID = "org.LoShin.GenesisBook";

		public const string VERSION = "3.0.14";

		private const int QuantumStorageSize = 80;

		public static void Init(Harmony harmony)
		{
			if (!Chainloader.PluginInfos.TryGetValue("org.LoShin.GenesisBook", out var _))
			{
				return;
			}
			try
			{
				harmony.PatchAll(typeof(Warper));
				harmony.PatchAll(typeof(StorageComponent_Patch));
				Log.Info("GenesisBook - OK");
			}
			catch (Exception obj)
			{
				Log.Warn("GenesisBook - Fail! Last target version: 3.0.14");
				NC_Patch.ErrorMessage += "\nGenesisBook (last target version: 3.0.14)";
				Log.Debug(obj);
			}
		}
	}
	public static class LSTM
	{
		public const string NAME = "LSTM";

		public const string GUID = "com.hetima.dsp.LSTM";

		public const string VERSION = "0.8.7";

		public static void Init(Harmony harmony)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			if (!Chainloader.PluginInfos.ContainsKey("com.hetima.dsp.LSTM"))
			{
				return;
			}
			try
			{
				Type type = AccessTools.TypeByName("LSTMMod.UIBalanceWindow");
				harmony.Patch((MethodBase)AccessTools.Method(type, "_OnOpen", (Type[])null, (Type[])null), new HarmonyMethod(typeof(LSTM).GetMethod("SendRequest")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)type.GetMethod("SwitchToStarSystem"), new HarmonyMethod(typeof(LSTM).GetMethod("SendRequest")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)type.GetMethod("SwitchToGlobal"), new HarmonyMethod(typeof(LSTM).GetMethod("SendRequest")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.Info("LSTM - OK");
			}
			catch (Exception obj)
			{
				Log.Warn("LSTM - Fail! Last target version: 0.8.7");
				NC_Patch.ErrorMessage += "\nLSTM (last target version: 0.8.7)";
				Log.Debug(obj);
			}
		}

		public static void SendRequest()
		{
			if (NebulaModAPI.IsMultiplayerActive && NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)
			{
				NebulaModAPI.MultiplayerSession.Network.SendPacket<NC_StationStorageRequest>(new NC_StationStorageRequest());
			}
		}
	}
	public static class MoreMegaStructure
	{
		public class PointerDownUpHandler : ManualBehaviour, IPointerDownHandler, IEventSystemHandler, IPointerUpHandler
		{
			public int Id;

			public event Action<int> onPointerDown;

			public event Action<int> onPointerUp;

			public void OnPointerDown(PointerEventData pointerEventData)
			{
				this.onPointerDown?.Invoke(Id);
			}

			public void OnPointerUp(PointerEventData pointerEventData)
			{
				this.onPointerUp?.Invoke(Id);
			}
		}

		private const string NAME = "MoreMegaStructure";

		private const string GUID = "Gnimaerd.DSP.plugin.MoreMegaStructure";

		private const string VERSION = "1.5.3";

		private static IModCanSave Save;

		public static void Init(Harmony harmony)
		{
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Expected O, but got Unknown
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Expected O, but got Unknown
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Expected O, but got Unknown
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Expected O, but got Unknown
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Expected O, but got Unknown
			if (!Chainloader.PluginInfos.TryGetValue("Gnimaerd.DSP.plugin.MoreMegaStructure", out var value))
			{
				return;
			}
			Assembly assembly = ((object)value.Instance).GetType().Assembly;
			try
			{
				BaseUnityPlugin instance = value.Instance;
				Save = (IModCanSave)(object)((instance is IModCanSave) ? instance : null);
				NC_Patch.OnLogin = (Action)Delegate.Combine(NC_Patch.OnLogin, new Action(SendRequest));
				NC_ModSaveRequest.OnReceive = (Action<string, INebulaConnection>)Delegate.Combine(NC_ModSaveRequest.OnReceive, (Action<string, INebulaConnection>)delegate(string guid, INebulaConnection conn)
				{
					if (!(guid != "Gnimaerd.DSP.plugin.MoreMegaStructure"))
					{
						conn.SendPacket<NC_ModSaveData>(new NC_ModSaveData("Gnimaerd.DSP.plugin.MoreMegaStructure", Export()));
					}
				});
				NC_ModSaveData.OnReceive = (Action<string, byte[]>)Delegate.Combine(NC_ModSaveData.OnReceive, (Action<string, byte[]>)delegate(string guid, byte[] bytes)
				{
					if (!(guid != "Gnimaerd.DSP.plugin.MoreMegaStructure"))
					{
						Import(bytes);
					}
				});
				HarmonyMethod val = new HarmonyMethod(typeof(MoreMegaStructure).GetMethod("SendData"));
				Type type = assembly.GetType("MoreMegaStructure.MoreMegaStructure");
				harmony.Patch((MethodBase)AccessTools.Method(type, "SetMegaStructure", (Type[])null, (Type[])null), (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)AccessTools.Method(type, "BeforeGameTickPostPatch", (Type[])null, (Type[])null), new HarmonyMethod(typeof(MoreMegaStructure).GetMethod("SuppressOnClient")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				type = assembly.GetType("MoreMegaStructure.ReceiverPatchers");
				harmony.Patch((MethodBase)AccessTools.Method(type, "RequestDysonSpherePowerPrePatch", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(MoreMegaStructure).GetMethod("RequestDysonSpherePowerPrePatch_Transpiler")), (HarmonyMethod)null, (HarmonyMethod)null);
				type = assembly.GetType("MoreMegaStructure.StarAssembly");
				harmony.Patch((MethodBase)AccessTools.Method(type, "OnRecipePickerReturn", (Type[])null, (Type[])null), (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				foreach (Slider item in AccessTools.StaticFieldRefAccess<List<Slider>>(type, "sliders"))
				{
					GameObject gameObject = ((Component)item).gameObject;
					Object.Destroy((Object)(object)gameObject.GetComponent<PointerDownUpHandler>());
					gameObject.AddComponent<PointerDownUpHandler>().onPointerUp += delegate
					{
						SendData();
					};
				}
				harmony.Patch((MethodBase)AccessTools.Method(type, "UIFrameUpdate", (Type[])null, (Type[])null), new HarmonyMethod(typeof(MoreMegaStructure).GetMethod("SuppressUIupdate")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				type = assembly.GetType("MoreMegaStructure.StarCannon");
				harmony.Patch((MethodBase)AccessTools.Method(type, "StartAiming", (Type[])null, (Type[])null), (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				HarmonyMethod val2 = new HarmonyMethod(typeof(MoreMegaStructure).GetMethod("SuppressPrefixOnMultiplayer"));
				HarmonyMethod val3 = new HarmonyMethod(typeof(MoreMegaStructure).GetMethod("SuppressPostfixOnMultiplayer"));
				type = assembly.GetType("MoreMegaStructure.UIStatisticsPatcher");
				harmony.Patch((Met