Decompiled source of InstantDelivery v1.0.0

InstantDelivery.dll

Decompiled 5 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("InstantDelivery")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Instantly delivery items among interstellar stations")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+fc529d71af3d82bc67071f0c521702884897fe13")]
[assembly: AssemblyProduct("InstantDelivery")]
[assembly: AssemblyTitle("InstantDelivery")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace InstantDelivery
{
	[BepInPlugin("lxb007981.dsp.InstantDelivery", "InstantDelivery", "0.1.0")]
	public class InstantDelivery : BaseUnityPlugin
	{
		public static class Configs
		{
			public static bool configEnableVessels = true;
		}

		public const string __NAME__ = "InstantDelivery";

		public const string __GUID__ = "lxb007981.dsp.InstantDelivery";

		private ConfigEntry<bool> configMethod;

		private Harmony harmony;

		public void Awake()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			harmony = new Harmony("lxb007981.dsp.InstantDelivery");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin lxb007981.dsp.InstantDelivery is loaded!");
			Configs.configEnableVessels = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableVessels", true, "Whether to enable sending out vessels as in the original game. Note setting this option to false will freeze vessels that have taken off.").Value;
			harmony.PatchAll(typeof(InstantDelivery));
		}

		public void OnDestroy()
		{
			harmony.UnpatchSelf();
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(StationComponent), "InternalTickRemote")]
		public static void InternalTickRemote_Prefix(ref StationComponent __instance, PlanetFactory factory, int timeGene, float shipSailSpeed, float shipWarpSpeed, int shipCarries, StationComponent[] gStationPool, AstroData[] astroPoses, ref VectorLF3 relativePos, ref Quaternion relativeRot, bool starmap, int[] consumeRegister, ref bool __runOriginal)
		{
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_054f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0555: Invalid comparison between Unknown and I4
			//IL_0569: Unknown result type (might be due to invalid IL or missing references)
			//IL_056f: Invalid comparison between Unknown and I4
			//IL_060b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0610: Unknown result type (might be due to invalid IL or missing references)
			//IL_0612: Unknown result type (might be due to invalid IL or missing references)
			//IL_0622: Unknown result type (might be due to invalid IL or missing references)
			//IL_064b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0667: Unknown result type (might be due to invalid IL or missing references)
			//IL_077c: Unknown result type (might be due to invalid IL or missing references)
			//IL_078c: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_06bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0820: Unknown result type (might be due to invalid IL or missing references)
			//IL_0830: Unknown result type (might be due to invalid IL or missing references)
			//IL_07be: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_07fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0718: Unknown result type (might be due to invalid IL or missing references)
			//IL_0731: Unknown result type (might be due to invalid IL or missing references)
			//IL_08b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_087e: Unknown result type (might be due to invalid IL or missing references)
			//IL_095b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0987: Unknown result type (might be due to invalid IL or missing references)
			//IL_09e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a01: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a5a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a94: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aa5: Unknown result type (might be due to invalid IL or missing references)
			__runOriginal = Configs.configEnableVessels;
			__instance.warperFree = DSPGame.IsMenuDemo;
			if (__instance.warperCount < __instance.warperMaxCount)
			{
				StationStore[] storage = __instance.storage;
				lock (storage)
				{
					for (int i = 0; i < __instance.storage.Length; i++)
					{
						if (__instance.storage[i].itemId == 1210 && __instance.storage[i].count > 0)
						{
							StationComponent obj = __instance;
							obj.warperCount++;
							int num = __instance.storage[i].inc / __instance.storage[i].count;
							StationStore[] storage2 = __instance.storage;
							int num2 = i;
							storage2[num2].count = storage2[num2].count - 1;
							StationStore[] storage3 = __instance.storage;
							int num3 = i;
							storage3[num3].inc = storage3[num3].inc - num;
							break;
						}
					}
				}
			}
			int num4 = 0;
			int num5 = 0;
			int itemId = 0;
			int num6 = 0;
			int num7 = 0;
			int num8 = 0;
			int num9 = 0;
			float num10 = shipSailSpeed / 600f;
			float num11 = Mathf.Pow(num10, 0.4f);
			float num12 = num11;
			if (num12 > 1f)
			{
				num12 = Mathf.Log(num12) + 1f;
			}
			float num13 = num12;
			if (num13 > 1f)
			{
				num13 = Mathf.Log(num13) + 1f;
			}
			if (num10 > 500f)
			{
				num10 = 500f;
			}
			ref AstroData reference = ref astroPoses[__instance.planetId];
			float num14 = shipSailSpeed * 0.03f;
			float num15 = shipSailSpeed * 0.12f * num12;
			float num16 = shipSailSpeed * 0.4f * num10;
			float num17 = num11 * 0.006f + 1E-05f;
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(0f, 0f, 0f);
			VectorLF3 val2 = default(VectorLF3);
			((VectorLF3)(ref val2))..ctor(0f, 0f, 0f);
			double num18 = 0.0;
			Quaternion val3 = default(Quaternion);
			((Quaternion)(ref val3))..ctor(0f, 0f, 0f, 1f);
			int inc = default(int);
			for (int j = 0; j < __instance.workShipCount; j++)
			{
				ref ShipData reference2 = ref __instance.workShipDatas[j];
				val3.x = (val3.y = (val3.z = 0f));
				val3.w = 1f;
				ref AstroData reference3 = ref astroPoses[reference2.planetB];
				val2.x = reference.uPos.x - reference3.uPos.x;
				val2.y = reference.uPos.y - reference3.uPos.y;
				val2.z = reference.uPos.z - reference3.uPos.z;
				num18 = Math.Sqrt(val2.x * val2.x + val2.y * val2.y + val2.z * val2.z);
				reference2.t = 0f;
				StationComponent val4 = gStationPool[reference2.otherGId];
				StationStore[] storage4 = val4.storage;
				if (num18 > __instance.warpEnableDist && reference2.warperCnt == 0 && val4.warperCount > 0)
				{
					lock (consumeRegister)
					{
						reference2.warperCnt++;
						val4.warperCount--;
						consumeRegister[1210]++;
					}
				}
				if (reference2.itemCount > 0)
				{
					val4.AddItem(reference2.itemId, reference2.itemCount, reference2.inc);
					factory.NotifyShipDelivery(reference2.planetA, __instance, reference2.planetB, val4, reference2.itemId, reference2.itemCount);
					reference2.itemCount = 0;
					reference2.inc = 0;
					if (__instance.workShipOrders[j].otherStationGId > 0)
					{
						StationStore[] array = storage4;
						lock (array)
						{
							if (storage4[__instance.workShipOrders[j].otherIndex].itemId == __instance.workShipOrders[j].itemId)
							{
								StationStore[] array2 = storage4;
								int otherIndex = __instance.workShipOrders[j].otherIndex;
								array2[otherIndex].remoteOrder = array2[otherIndex].remoteOrder - __instance.workShipOrders[j].otherOrdered;
							}
						}
						((RemoteLogisticOrder)(ref __instance.workShipOrders[j])).ClearOther();
					}
					if (__instance.remotePairTotalCount > 0)
					{
						int num19;
						int num20;
						if ((int)__instance.routePriority == 2)
						{
							num19 = 1;
							num20 = 5;
						}
						else if ((int)__instance.routePriority == 3)
						{
							num19 = 1;
							num20 = 4;
						}
						else
						{
							num19 = 0;
							num20 = 0;
						}
						bool flag = true;
						for (int k = num19; k <= num20; k++)
						{
							int num21 = __instance.remotePairOffsets[k + 1] - __instance.remotePairOffsets[k];
							if (num21 <= 0)
							{
								continue;
							}
							int num22 = __instance.remotePairOffsets[k];
							__instance.remotePairProcesses[k] = __instance.remotePairProcesses[k] % num21;
							int num23 = __instance.remotePairProcesses[k];
							int num24 = __instance.remotePairProcesses[k];
							do
							{
								SupplyDemandPair val5 = __instance.remotePairs[num24 + num22];
								if (val5.demandId != __instance.gid || val5.supplyId != val4.gid)
								{
									goto IL_077b;
								}
								if (__instance.priorityLocks[val5.demandIndex].priorityIndex < k && __instance.priorityLocks[val5.demandIndex].lockTick > 0)
								{
									num24++;
									num24 %= num21;
									continue;
								}
								if (val4.priorityLocks[val5.supplyIndex].priorityIndex >= k || val4.priorityLocks[val5.supplyIndex].lockTick <= 0)
								{
									StationStore[] storage5 = __instance.storage;
									lock (storage5)
									{
										num4 = ((StationStore)(ref __instance.storage[val5.demandIndex])).remoteDemandCount;
										num5 = ((StationStore)(ref __instance.storage[val5.demandIndex])).totalDemandCount;
										itemId = __instance.storage[val5.demandIndex].itemId;
									}
									goto IL_077b;
								}
								num24++;
								num24 %= num21;
								continue;
								IL_077b:
								if (val5.demandId == __instance.gid && val5.supplyId == val4.gid)
								{
									StationStore[] storage5 = storage4;
									lock (storage5)
									{
										num6 = storage4[val5.supplyIndex].count;
										num7 = storage4[val5.supplyIndex].inc;
										num8 = ((StationStore)(ref storage4[val5.supplyIndex])).remoteSupplyCount;
										num9 = ((StationStore)(ref storage4[val5.supplyIndex])).totalSupplyCount;
									}
								}
								if (val5.demandId == __instance.gid && val5.supplyId == val4.gid)
								{
									if (num4 > 0 && num5 > 0)
									{
										if (num6 >= shipCarries && num8 >= shipCarries && num9 >= shipCarries)
										{
											int num25 = ((shipCarries < num6) ? shipCarries : num6);
											int num26 = num6;
											int num27 = num7;
											int num28 = __instance.split_inc(ref num26, ref num27, num25);
											reference2.itemId = (__instance.workShipOrders[j].itemId = itemId);
											reference2.itemCount = num25;
											reference2.inc = num28;
											StationStore[] storage5 = storage4;
											lock (storage5)
											{
												StationStore[] array3 = storage4;
												int supplyIndex = val5.supplyIndex;
												array3[supplyIndex].count = array3[supplyIndex].count - num25;
												StationStore[] array4 = storage4;
												int supplyIndex2 = val5.supplyIndex;
												array4[supplyIndex2].inc = array4[supplyIndex2].inc - num28;
											}
											__instance.workShipOrders[j].otherStationGId = val4.gid;
											__instance.workShipOrders[j].thisIndex = val5.demandIndex;
											__instance.workShipOrders[j].otherIndex = val5.supplyIndex;
											__instance.workShipOrders[j].thisOrdered = num25;
											__instance.workShipOrders[j].otherOrdered = 0;
											storage5 = __instance.storage;
											lock (storage5)
											{
												StationStore[] storage6 = __instance.storage;
												int demandIndex = val5.demandIndex;
												storage6[demandIndex].remoteOrder = storage6[demandIndex].remoteOrder + num25;
											}
											__instance.SetPriorityLock(val5.demandIndex, k);
											val4.SetPriorityLock(val5.supplyIndex, k);
											flag = false;
											break;
										}
										val4.SetPriorityLock(val5.supplyIndex, k);
									}
									else if (num6 <= shipCarries || num8 <= shipCarries || num9 <= shipCarries)
									{
										val4.SetPriorityLock(val5.supplyIndex, k);
									}
								}
								num24++;
								num24 %= num21;
							}
							while (num23 != num24);
							if (!flag)
							{
								break;
							}
						}
					}
				}
				else
				{
					int itemId2 = reference2.itemId;
					int num29 = shipCarries;
					val4.TakeItem(ref itemId2, ref num29, ref inc);
					reference2.itemCount = num29;
					reference2.inc = inc;
					StationStore[] array5;
					if (__instance.workShipOrders[j].otherStationGId > 0)
					{
						array5 = storage4;
						lock (array5)
						{
							if (storage4[__instance.workShipOrders[j].otherIndex].itemId == __instance.workShipOrders[j].itemId)
							{
								StationStore[] array6 = storage4;
								int otherIndex2 = __instance.workShipOrders[j].otherIndex;
								array6[otherIndex2].remoteOrder = array6[otherIndex2].remoteOrder - __instance.workShipOrders[j].otherOrdered;
							}
						}
						((RemoteLogisticOrder)(ref __instance.workShipOrders[j])).ClearOther();
					}
					array5 = __instance.storage;
					lock (array5)
					{
						if (__instance.storage[__instance.workShipOrders[j].thisIndex].itemId == __instance.workShipOrders[j].itemId && __instance.workShipOrders[j].thisOrdered != num29)
						{
							int num30 = num29 - __instance.workShipOrders[j].thisOrdered;
							StationStore[] storage7 = __instance.storage;
							int thisIndex = __instance.workShipOrders[j].thisIndex;
							storage7[thisIndex].remoteOrder = storage7[thisIndex].remoteOrder + num30;
							RemoteLogisticOrder[] workShipOrders = __instance.workShipOrders;
							int num31 = j;
							workShipOrders[num31].thisOrdered = workShipOrders[num31].thisOrdered + num30;
						}
					}
				}
				reference2.direction = -1;
			}
			for (int l = 0; l < __instance.priorityLocks.Length; l++)
			{
				if (__instance.priorityLocks[l].priorityIndex >= 0)
				{
					if (__instance.priorityLocks[l].lockTick > 0)
					{
						StationPriorityLock[] priorityLocks = __instance.priorityLocks;
						int num32 = l;
						priorityLocks[num32].lockTick = (byte)(priorityLocks[num32].lockTick - 1);
					}
					else
					{
						__instance.priorityLocks[l].lockTick = 0;
						__instance.priorityLocks[l].priorityIndex = 0;
					}
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "InstantDelivery";

		public const string PLUGIN_NAME = "InstantDelivery";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}