Decompiled source of PlanetwideMiner v1.0.0

PlanetwideMiner.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("PlanetwideMiner")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Make mining on a planet work in a planetwide way.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d48ef20f0433c0d261f22ef91219f499aded1b36")]
[assembly: AssemblyProduct("PlanetwideMiner")]
[assembly: AssemblyTitle("PlanetwideMiner")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 PlanetwideMiner
{
	[BepInPlugin("un1eagle.planetwideminer", "全球矿机", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource? Log;

		internal static Plugin? Instance;

		private void Awake()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Harmony val = new Harmony("un1eagle.planetwideminer");
			val.PatchAll(typeof(MinerInternalUpdatePatch));
			val.PatchAll(typeof(PlanetFactoryBuildPatch));
			val.PatchAll(typeof(UIMinerWindowUpdatePatch));
			val.PatchAll(typeof(ProductionExtraInfoCalculatorFactoryPatch));
			val.PatchAll(typeof(FactoryProductionStatAddRefProductSpeedPatch));
			val.PatchAll(typeof(FactoryProductionStatResetRefProductSpeedPatch));
			val.PatchAll(typeof(UIProductEntryOnProductionExtraInfoEndCalculatePatch));
			val.PatchAll(typeof(UIReferenceSpeedTipAddEntryDataWithFactoryPatch));
			Log.LogInfo((object)"[全球矿机] 加载完成 (GUID: un1eagle.planetwideminer, Version: 1.0.0)");
		}

		internal static void ExpandVeinMinerToPlanet(ref MinerComponent miner, PlanetFactory factory, VeinData[] veinPool)
		{
			if (miner.veinCount <= 0 || miner.veins == null || veinPool.Length == 0)
			{
				return;
			}
			int num = miner.veins[0];
			if (num <= 0 || num >= veinPool.Length || veinPool[num].id != num)
			{
				return;
			}
			int productId = veinPool[num].productId;
			if (productId <= 0)
			{
				return;
			}
			List<int> list = new List<int>(128);
			for (int i = 1; i < veinPool.Length; i++)
			{
				if (veinPool[i].id == i && veinPool[i].productId == productId)
				{
					list.Add(i);
				}
			}
			if (list.Count == 0)
			{
				return;
			}
			((MinerComponent)(ref miner)).InitVeinArray(list.Count);
			for (int j = 0; j < list.Count; j++)
			{
				miner.veins[j] = list[j];
			}
			((MinerComponent)(ref miner)).ArrangeVeinArray();
			miner.currentVeinIndex = 0;
			((MinerComponent)(ref miner)).GetMinimumVeinAmount(factory, veinPool);
			if (!GameMain.data.gameDesc.isInfiniteResource)
			{
				((MinerComponent)(ref miner)).GetTotalVeinAmount(veinPool);
			}
			foreach (int item in list)
			{
				factory.RefreshVeinMiningDisplay(item, miner.entityId, 0);
			}
			ManualLogSource? log = Log;
			if (log != null)
			{
				log.LogInfo((object)$"[PlanetwideMiner] Vein 矿机 {miner.id} 在建造时扩展为全球矿机,同种矿脉数={list.Count}。");
			}
		}

		internal static void ExpandOilMinerVeins(ref MinerComponent miner, PlanetFactory factory, VeinData[] veinPool)
		{
			if (miner.veinCount <= 0 || miner.veins == null || veinPool.Length == 0)
			{
				return;
			}
			int num = miner.veins[0];
			if (num <= 0 || num >= veinPool.Length || veinPool[num].id != num)
			{
				return;
			}
			int productId = veinPool[num].productId;
			if (productId <= 0)
			{
				return;
			}
			List<int> list = new List<int>(32);
			for (int i = 1; i < veinPool.Length; i++)
			{
				if (veinPool[i].id == i && veinPool[i].productId == productId)
				{
					list.Add(i);
				}
			}
			if (list.Count != 0)
			{
				((MinerComponent)(ref miner)).InitVeinArray(list.Count);
				for (int j = 0; j < list.Count; j++)
				{
					miner.veins[j] = list[j];
				}
				((MinerComponent)(ref miner)).ArrangeVeinArray();
				miner.currentVeinIndex = 0;
			}
		}
	}
	[HarmonyPatch(typeof(PlanetFactory), "OnBuildEntity")]
	internal static class PlanetFactoryBuildPatch
	{
		[HarmonyPostfix]
		private static void Postfix(PlanetFactory __instance, int newEntityId, int oldPrebuildId)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Invalid comparison between Unknown and I4
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Invalid comparison between Unknown and I4
			try
			{
				if (__instance == null || __instance.factorySystem == null || __instance.veinPool == null || newEntityId <= 0 || newEntityId >= __instance.entityPool.Length)
				{
					return;
				}
				ref EntityData reference = ref __instance.entityPool[newEntityId];
				if (reference.id == newEntityId && reference.minerId > 0)
				{
					ref MinerComponent reference2 = ref __instance.factorySystem.minerPool[reference.minerId];
					if ((int)reference2.type == 2)
					{
						Plugin.ExpandVeinMinerToPlanet(ref reference2, __instance, __instance.veinPool);
					}
					else if ((int)reference2.type == 3)
					{
						Plugin.ExpandOilMinerVeins(ref reference2, __instance, __instance.veinPool);
					}
				}
			}
			catch (Exception arg)
			{
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)$"[PlanetwideMiner] PlanetFactoryBuildPatch 异常: {arg}");
				}
			}
		}
	}
	[HarmonyPatch(typeof(MinerComponent), "InternalUpdate")]
	internal static class MinerInternalUpdatePatch
	{
		[HarmonyPrefix]
		private static bool Prefix(ref MinerComponent __instance, PlanetFactory factory, VeinData[] veinPool, float power, float miningRate, float miningSpeed, int[] productRegister, ref uint __result)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			//IL_0296: 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_02b8: Expected I4, but got Unknown
			if (factory == null || veinPool == null)
			{
				return true;
			}
			if ((int)__instance.type != 3)
			{
				return true;
			}
			if (power < 0.1f || __instance.veinCount <= 0)
			{
				__result = 0u;
				return false;
			}
			int num = ((__instance.veins != null && __instance.veins.Length != 0) ? __instance.veins[0] : 0);
			if (num <= 0 || num >= veinPool.Length || veinPool[num].id != num)
			{
				__result = 0u;
				return false;
			}
			uint num2 = 0u;
			double num3 = 0.0;
			lock (veinPool)
			{
				int productId = veinPool[num].productId;
				long num4 = 0L;
				for (int i = 1; i < veinPool.Length; i++)
				{
					if (veinPool[i].id == i && veinPool[i].productId == productId)
					{
						num4 += veinPool[i].amount;
					}
				}
				if (num4 <= 0)
				{
					__result = 0u;
					return false;
				}
				float num5 = (float)num4 * VeinData.oilSpeedMultiplier;
				num3 = 36000000.0 / (double)__instance.period * (double)miningSpeed * (double)(float)num4 * (double)VeinData.oilSpeedMultiplier;
				if (__instance.time < __instance.period)
				{
					__instance.time += (int)(power * __instance.speedDamper * (float)__instance.speed * miningSpeed * num5 + 0.5f);
					num2 = 1u;
				}
				if (__instance.time >= __instance.period && __instance.productCount < 50)
				{
					__instance.productId = productId;
					int num6 = __instance.time / __instance.period;
					if (miningRate > 0f && veinPool[num].amount > 2500)
					{
						__instance.costFrac += (double)miningRate * (double)num6;
						int num7 = (int)__instance.costFrac;
						__instance.costFrac -= num7;
						int num8 = veinPool[num].amount - 2500;
						if (num7 > 0)
						{
							if (num7 > num8)
							{
								num7 = num8;
							}
							if (num7 > 0)
							{
								int num9 = num;
								veinPool[num9].amount -= num7;
								VeinGroup[] veinGroups = factory.veinGroups;
								short groupIndex = veinPool[num].groupIndex;
								veinGroups[groupIndex].amount -= num7;
								factory.veinAnimPool[num].time = ((veinPool[num].amount >= 25000) ? 0f : (1f - (float)veinPool[num].amount * VeinData.oilSpeedMultiplier));
								if (veinPool[num].amount <= 2500)
								{
									factory.NotifyVeinExhausted((int)veinPool[num].type, (int)veinPool[num].groupIndex, veinPool[num].pos);
								}
							}
						}
					}
					__instance.productCount += num6;
					lock (productRegister)
					{
						productRegister[__instance.productId] += num6;
					}
					__instance.time -= __instance.period * num6;
				}
			}
			if (__instance.productCount > 0 && __instance.insertTarget > 0 && __instance.productId > 0)
			{
				int num10 = (int)(((num3 > 0.0) ? num3 : (36000000.0 / (double)__instance.period * (double)miningSpeed)) - 0.01) / 1800 + 1;
				if (num10 < 1)
				{
					num10 = 1;
				}
				if (num10 > 25)
				{
					num10 = 25;
				}
				int num11 = ((__instance.productCount < num10) ? __instance.productCount : num10);
				byte b = default(byte);
				int num12 = factory.InsertInto(__instance.insertTarget, 0, __instance.productId, (byte)num11, (byte)0, ref b);
				__instance.productCount -= num12;
			}
			__result = num2;
			return false;
		}
	}
	[HarmonyPatch(typeof(UIMinerWindow), "_OnUpdate")]
	internal static class UIMinerWindowUpdatePatch
	{
		[HarmonyPostfix]
		private static void Postfix(UIMinerWindow __instance)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Invalid comparison between Unknown and I4
			//IL_0066: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Invalid comparison between Unknown and I4
			try
			{
				if ((Object)(object)__instance == (Object)null || __instance.factory == null || __instance.factorySystem == null)
				{
					return;
				}
				int minerId = __instance.minerId;
				if (minerId <= 0)
				{
					return;
				}
				MinerComponent val = __instance.factorySystem.minerPool[minerId];
				if (val.id != minerId || (int)val.type != 3)
				{
					return;
				}
				VeinData[] veinPool = __instance.factory.veinPool;
				if (veinPool == null || val.veinCount <= 0 || val.veins == null)
				{
					return;
				}
				int num = val.veins[0];
				if (num <= 0 || num >= veinPool.Length || veinPool[num].id != num)
				{
					return;
				}
				int productId = veinPool[num].productId;
				if (productId <= 0)
				{
					return;
				}
				long num2 = 0L;
				for (int i = 1; i < veinPool.Length; i++)
				{
					if (veinPool[i].id == i && veinPool[i].productId == productId)
					{
						num2 += veinPool[i].amount;
					}
				}
				if (num2 > 0)
				{
					float num3 = (float)num2 * VeinData.oilSpeedMultiplier;
					__instance.veinAmountText.text = num3.ToString("0.0000") + "/s";
					int networkId = __instance.powerSystem.consumerPool[val.pcId].networkId;
					PowerNetwork val2 = __instance.powerSystem.netPool[networkId];
					float num4 = ((val2 != null && networkId > 0) ? ((float)val2.consumerRatio) : 0f);
					float num5 = (float)((double)val.period / 600000.0);
					float num6 = ((num5 > 0f) ? (60f / num5) : 0f);
					float num7 = (float)(0.0001 * (double)val.speed * (double)val.speedDamper * (double)num4 * (double)GameMain.history.miningSpeedScale) * (float)((double)num2 * (double)VeinData.oilSpeedMultiplier);
					if ((int)val.workstate <= 0 || num4 < 0.1f)
					{
						num7 = 0f;
					}
					__instance.speedText.text = (num6 * num7).ToString("0.0") + Localization.Translate("每分钟");
				}
			}
			catch (Exception arg)
			{
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)$"[PlanetwideMiner] UIMinerWindowUpdatePatch 异常: {arg}");
				}
			}
		}
	}
	internal static class OilRefSpeedPatchState
	{
		internal static HashSet<int>? OilProductIdsThisFactory;

		internal static bool InTipContext;
	}
	[HarmonyPatch(typeof(ProductionExtraInfoCalculator), "CalculateFactory")]
	internal static class ProductionExtraInfoCalculatorFactoryPatch
	{
		[CompilerGenerated]
		private sealed class <Transpiler>d__1 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private CodeInstruction <>2__current;

			private int <>l__initialThreadId;

			private IEnumerable<CodeInstruction> instructions;

			public IEnumerable<CodeInstruction> <>3__instructions;

			private FieldInfo <field>5__2;

			private bool <afterOilMultiplier>5__3;

			private IEnumerator<CodeInstruction> <>7__wrap3;

			private CodeInstruction <ins>5__5;

			CodeInstruction IEnumerator<CodeInstruction>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <Transpiler>d__1(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				switch (<>1__state)
				{
				case -3:
				case 1:
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
					break;
				case -4:
				case 2:
				case 3:
				case 4:
				case 5:
					try
					{
					}
					finally
					{
						<>m__Finally2();
					}
					break;
				}
				<field>5__2 = null;
				<>7__wrap3 = null;
				<ins>5__5 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d2: Expected O, but got Unknown
				//IL_0240: Unknown result type (might be due to invalid IL or missing references)
				//IL_024a: Expected O, but got Unknown
				//IL_0223: Unknown result type (might be due to invalid IL or missing references)
				//IL_0198: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a2: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<field>5__2 = AccessTools.Field(typeof(VeinData), "oilSpeedMultiplier");
						if (<field>5__2 == null)
						{
							<>7__wrap3 = instructions.GetEnumerator();
							<>1__state = -3;
							goto IL_009f;
						}
						<afterOilMultiplier>5__3 = false;
						<>7__wrap3 = instructions.GetEnumerator();
						<>1__state = -4;
						break;
					case 1:
						<>1__state = -3;
						goto IL_009f;
					case 2:
						<>1__state = -4;
						<>2__current = new CodeInstruction(OpCodes.Ldc_R4, (object)0f);
						<>1__state = 3;
						return true;
					case 3:
						<>1__state = -4;
						<>2__current = ((<ins>5__5.opcode == OpCodes.Stloc || <ins>5__5.opcode == OpCodes.Stloc_S) ? new CodeInstruction(<ins>5__5.opcode, <ins>5__5.operand) : new CodeInstruction(<ins>5__5.opcode, (object)null));
						<>1__state = 4;
						return true;
					case 4:
						<>1__state = -4;
						<afterOilMultiplier>5__3 = false;
						break;
					case 5:
						{
							<>1__state = -4;
							<ins>5__5 = null;
							break;
						}
						IL_009f:
						if (<>7__wrap3.MoveNext())
						{
							CodeInstruction current = <>7__wrap3.Current;
							<>2__current = current;
							<>1__state = 1;
							return true;
						}
						<>m__Finally1();
						<>7__wrap3 = null;
						return false;
					}
					if (<>7__wrap3.MoveNext())
					{
						<ins>5__5 = <>7__wrap3.Current;
						if (<afterOilMultiplier>5__3 && (<ins>5__5.opcode == OpCodes.Stloc || <ins>5__5.opcode == OpCodes.Stloc_S || <ins>5__5.opcode == OpCodes.Stloc_0 || <ins>5__5.opcode == OpCodes.Stloc_1 || <ins>5__5.opcode == OpCodes.Stloc_2 || <ins>5__5.opcode == OpCodes.Stloc_3))
						{
							<>2__current = new CodeInstruction(OpCodes.Pop, (object)null);
							<>1__state = 2;
							return true;
						}
						if (<ins>5__5.opcode == OpCodes.Ldsfld && <ins>5__5.operand is FieldInfo fieldInfo && fieldInfo == <field>5__2)
						{
							<afterOilMultiplier>5__3 = true;
						}
						<>2__current = <ins>5__5;
						<>1__state = 5;
						return true;
					}
					<>m__Finally2();
					<>7__wrap3 = null;
					return false;
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<>7__wrap3 != null)
				{
					<>7__wrap3.Dispose();
				}
			}

			private void <>m__Finally2()
			{
				<>1__state = -1;
				if (<>7__wrap3 != null)
				{
					<>7__wrap3.Dispose();
				}
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}

			[DebuggerHidden]
			IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
			{
				<Transpiler>d__1 <Transpiler>d__;
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					<Transpiler>d__ = this;
				}
				else
				{
					<Transpiler>d__ = new <Transpiler>d__1(0);
				}
				<Transpiler>d__.instructions = <>3__instructions;
				return <Transpiler>d__;
			}

			[DebuggerHidden]
			IEnumerator IEnumerable.GetEnumerator()
			{
				return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
			}
		}

		[HarmonyPrefix]
		private static void Prefix(PlanetFactory factory)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Invalid comparison between Unknown and I4
			OilRefSpeedPatchState.OilProductIdsThisFactory = null;
			if (factory?.factorySystem?.minerPool == null || factory.veinPool == null)
			{
				return;
			}
			MinerComponent[] minerPool = factory.factorySystem.minerPool;
			VeinData[] veinPool = factory.veinPool;
			int minerCursor = factory.factorySystem.minerCursor;
			HashSet<int> hashSet = new HashSet<int>();
			for (int i = 1; i < minerCursor; i++)
			{
				if (minerPool[i].id != i || (int)minerPool[i].type != 3 || minerPool[i].veins == null || minerPool[i].veinCount <= 0)
				{
					continue;
				}
				int num = minerPool[i].veins[0];
				if (num > 0 && num < veinPool.Length && veinPool[num].id == num)
				{
					int productId = veinPool[num].productId;
					if (productId > 0)
					{
						hashSet.Add(productId);
					}
				}
			}
			if (hashSet.Count > 0)
			{
				OilRefSpeedPatchState.OilProductIdsThisFactory = hashSet;
			}
		}

		[IteratorStateMachine(typeof(<Transpiler>d__1))]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <Transpiler>d__1(-2)
			{
				<>3__instructions = instructions
			};
		}

		[HarmonyPostfix]
		private static void Postfix(ProductionExtraInfoCalculator __instance, GameData gameData, PlanetFactory factory)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Invalid comparison between Unknown and I4
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Invalid comparison between Unknown and I4
			try
			{
				if (gameData?.statistics?.production == null || factory == null || factory.factorySystem == null)
				{
					return;
				}
				FactorySystem factorySystem = factory.factorySystem;
				MinerComponent[] minerPool = factorySystem.minerPool;
				int minerCursor = factorySystem.minerCursor;
				VeinData[] veinPool = factory.veinPool;
				if (veinPool == null || veinPool.Length == 0)
				{
					return;
				}
				HashSet<int> hashSet = new HashSet<int>();
				for (int i = 1; i < minerCursor; i++)
				{
					if (minerPool[i].id != i || (int)minerPool[i].type != 3 || minerPool[i].veins == null || minerPool[i].veinCount <= 0)
					{
						continue;
					}
					int num = minerPool[i].veins[0];
					if (num > 0 && num < veinPool.Length && veinPool[num].id == num)
					{
						int productId = veinPool[num].productId;
						if (productId > 0)
						{
							hashSet.Add(productId);
						}
					}
				}
				if (hashSet.Count == 0)
				{
					OilRefSpeedPatchState.OilProductIdsThisFactory = null;
					return;
				}
				double num2 = gameData.history.miningSpeedScale;
				FactoryProductionStat val = gameData.statistics.production.factoryStatPool[factory.index];
				if (val?.productPool == null || val.productIndices == null)
				{
					return;
				}
				foreach (int item in hashSet)
				{
					long num3 = 0L;
					for (int j = 1; j < veinPool.Length; j++)
					{
						if (veinPool[j].id == j && veinPool[j].productId == item)
						{
							num3 += veinPool[j].amount;
						}
					}
					if (num3 <= 0)
					{
						continue;
					}
					int num4 = 0;
					int num5 = 0;
					int num6 = 0;
					for (int k = 1; k < minerCursor; k++)
					{
						if (minerPool[k].id != k || (int)minerPool[k].type != 3 || minerPool[k].veins == null || minerPool[k].veinCount <= 0)
						{
							continue;
						}
						int num7 = minerPool[k].veins[0];
						if (num7 > 0 && num7 < veinPool.Length && veinPool[num7].productId == item)
						{
							num6++;
							if (num4 <= 0)
							{
								num4 = minerPool[k].period;
								num5 = minerPool[k].speed;
							}
						}
					}
					if (num4 <= 0 || num6 <= 0)
					{
						continue;
					}
					double num8 = 3600.0 / (double)num4 * num2 * (double)num5 * (double)num3 * (double)VeinData.oilSpeedMultiplier * (double)num6;
					int num9 = val.productIndices[item];
					if (num9 > 0 && num9 < val.productPool.Length)
					{
						ProductStat val2 = val.productPool[num9];
						if (val2 != null)
						{
							val2.refProductSpeed = (float)num8;
						}
					}
				}
				OilRefSpeedPatchState.OilProductIdsThisFactory = null;
			}
			catch (Exception arg)
			{
				OilRefSpeedPatchState.OilProductIdsThisFactory = null;
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)$"[PlanetwideMiner] ProductionExtraInfoCalculatorFactoryPatch 异常: {arg}");
				}
			}
		}
	}
	[HarmonyPatch(typeof(FactoryProductionStat), "AddRefProductSpeed")]
	internal static class FactoryProductionStatAddRefProductSpeedPatch
	{
		[HarmonyPrefix]
		private static void Prefix(int itemId, ref float refSpeed)
		{
			HashSet<int> oilProductIdsThisFactory = OilRefSpeedPatchState.OilProductIdsThisFactory;
			if (oilProductIdsThisFactory != null && oilProductIdsThisFactory.Contains(itemId))
			{
				refSpeed = 0f;
			}
		}
	}
	[HarmonyPatch(typeof(FactoryProductionStat), "ResetRefProductSpeed")]
	internal static class FactoryProductionStatResetRefProductSpeedPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(int itemId)
		{
			if (!OilRefSpeedPatchState.InTipContext)
			{
				return true;
			}
			HashSet<int> oilProductIdsThisFactory = OilRefSpeedPatchState.OilProductIdsThisFactory;
			if (oilProductIdsThisFactory == null || !oilProductIdsThisFactory.Contains(itemId))
			{
				return true;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(UIProductEntry), "OnProductionExtraInfoEndCalculate")]
	internal static class UIProductEntryOnProductionExtraInfoEndCalculatePatch
	{
		[HarmonyPostfix]
		private static void Postfix(UIProductEntry __instance)
		{
			try
			{
				__instance.UpdateExtraProductTexts();
			}
			catch (Exception arg)
			{
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)$"[PlanetwideMiner] UIProductEntryOnProductionExtraInfoEndCalculatePatch: {arg}");
				}
			}
		}
	}
	[HarmonyPatch(typeof(UIReferenceSpeedTip), "AddEntryDataWithFactory")]
	internal static class UIReferenceSpeedTipAddEntryDataWithFactoryPatch
	{
		private static readonly FieldInfo? TipItemIdField = AccessTools.Field(typeof(UIReferenceSpeedTip), "itemId");

		private static readonly FieldInfo? TipItemCycleField = AccessTools.Field(typeof(UIReferenceSpeedTip), "itemCycle");

		private static readonly FieldInfo? TipLoadedEntryDatasField = AccessTools.Field(typeof(UIReferenceSpeedTip), "loadedEntryDatas");

		[HarmonyPrefix]
		private static void Prefix(PlanetFactory factory)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Invalid comparison between Unknown and I4
			OilRefSpeedPatchState.OilProductIdsThisFactory = null;
			OilRefSpeedPatchState.InTipContext = false;
			if (factory?.factorySystem?.minerPool == null || factory.veinPool == null)
			{
				return;
			}
			MinerComponent[] minerPool = factory.factorySystem.minerPool;
			VeinData[] veinPool = factory.veinPool;
			int minerCursor = factory.factorySystem.minerCursor;
			HashSet<int> hashSet = new HashSet<int>();
			for (int i = 1; i < minerCursor; i++)
			{
				if (minerPool[i].id != i || (int)minerPool[i].type != 3 || minerPool[i].veins == null || minerPool[i].veinCount <= 0)
				{
					continue;
				}
				int num = minerPool[i].veins[0];
				if (num > 0 && num < veinPool.Length && veinPool[num].id == num)
				{
					int productId = veinPool[num].productId;
					if (productId > 0)
					{
						hashSet.Add(productId);
					}
				}
			}
			if (hashSet.Count > 0)
			{
				OilRefSpeedPatchState.OilProductIdsThisFactory = hashSet;
				OilRefSpeedPatchState.InTipContext = true;
			}
		}

		[HarmonyPostfix]
		private static void Postfix(UIReferenceSpeedTip __instance, PlanetFactory factory)
		{
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Invalid comparison between Unknown and I4
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Invalid comparison between Unknown and I4
			try
			{
				object obj = TipItemCycleField?.GetValue(__instance);
				if (obj == null || (int)obj != 1)
				{
					return;
				}
				object obj2 = TipItemIdField?.GetValue(__instance);
				if (obj2 == null)
				{
					return;
				}
				int num = (int)obj2;
				if (GameMain.data?.statistics?.production?.factoryStatPool == null || factory.veinPool == null || factory.factorySystem?.minerPool == null)
				{
					return;
				}
				VeinData[] veinPool = factory.veinPool;
				MinerComponent[] minerPool = factory.factorySystem.minerPool;
				int minerCursor = factory.factorySystem.minerCursor;
				EntityData[] entityPool = factory.entityPool;
				HashSet<int> hashSet = new HashSet<int>();
				int? num2 = null;
				for (int i = 1; i < minerCursor; i++)
				{
					if (minerPool[i].id != i || (int)minerPool[i].type != 3 || minerPool[i].veins == null || minerPool[i].veinCount <= 0)
					{
						continue;
					}
					int num3 = minerPool[i].veins[0];
					if (num3 <= 0 || num3 >= veinPool.Length || veinPool[num3].id != num3)
					{
						continue;
					}
					int productId = veinPool[num3].productId;
					if (productId <= 0)
					{
						continue;
					}
					hashSet.Add(productId);
					if (entityPool != null && minerPool[i].entityId > 0 && minerPool[i].entityId < entityPool.Length)
					{
						int valueOrDefault = num2.GetValueOrDefault();
						if (!num2.HasValue)
						{
							valueOrDefault = entityPool[minerPool[i].entityId].protoId;
							num2 = valueOrDefault;
						}
					}
				}
				if (hashSet.Count == 0 || !hashSet.Contains(num))
				{
					OilRefSpeedPatchState.OilProductIdsThisFactory = null;
					OilRefSpeedPatchState.InTipContext = false;
					return;
				}
				FactoryProductionStat val = GameMain.data.statistics.production.factoryStatPool[factory.index];
				if (val?.productPool == null || val.productIndices == null)
				{
					OilRefSpeedPatchState.OilProductIdsThisFactory = null;
					OilRefSpeedPatchState.InTipContext = false;
					return;
				}
				int num4 = val.productIndices[num];
				if (num4 <= 0 || num4 >= val.productPool.Length || val.productPool[num4] == null)
				{
					OilRefSpeedPatchState.OilProductIdsThisFactory = null;
					OilRefSpeedPatchState.InTipContext = false;
					return;
				}
				float refProductSpeed = val.productPool[num4].refProductSpeed;
				double num5 = GameMain.data.history.miningSpeedScale;
				double num6 = 0.0;
				for (int j = 1; j < minerCursor; j++)
				{
					if (minerPool[j].id == j && (int)minerPool[j].type == 3 && minerPool[j].veins != null && minerPool[j].veinCount > 0)
					{
						int num7 = minerPool[j].veins[0];
						if (num7 > 0 && num7 < veinPool.Length && veinPool[num7].productId == num)
						{
							num6 += 3600.0 / (double)minerPool[j].period * num5 * (double)minerPool[j].speed * (double)veinPool[num7].amount * (double)VeinData.oilSpeedMultiplier;
						}
					}
				}
				float num8 = refProductSpeed - (float)num6;
				if (!num2.HasValue || !(TipLoadedEntryDatasField?.GetValue(__instance) is Array array) || array.Length <= num2.Value)
				{
					return;
				}
				Type elementType = array.GetType().GetElementType();
				if (!(elementType != null))
				{
					return;
				}
				FieldInfo fieldInfo = AccessTools.Field(elementType, "normalSpeed");
				if (fieldInfo != null)
				{
					object value = array.GetValue(num2.Value);
					if (value != null)
					{
						float num9 = (float)(fieldInfo.GetValue(value) ?? ((object)0f));
						fieldInfo.SetValue(value, num9 + num8);
						array.SetValue(value, num2.Value);
					}
				}
			}
			finally
			{
				OilRefSpeedPatchState.OilProductIdsThisFactory = null;
				OilRefSpeedPatchState.InTipContext = false;
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "un1eagle.planetwideminer";

		public const string PLUGIN_NAME = "全球矿机";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}