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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
[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: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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]
[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
{
[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(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_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Invalid comparison between Unknown and I4
//IL_0337: Unknown result type (might be due to invalid IL or missing references)
//IL_034f: Unknown result type (might be due to invalid IL or missing references)
//IL_035a: 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, false);
}
}
}
}
__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 = 0;
int num12 = factory.InsertInto(__instance.insertTarget, 0, __instance.productId, (byte)num11, (byte)0, ref b);
__instance.productCount -= num12;
}
__result = num2;
return false;
}
}
internal static class OilRefSpeedPatchState
{
internal static HashSet<int>? OilProductIdsThisFactory;
internal static bool InTipContext;
}
[HarmonyPatch(typeof(PlanetFactory), "OnBuildEntity")]
internal static class PlanetFactoryBuildPatch
{
[HarmonyPostfix]
private static void Postfix(PlanetFactory __instance, int newEntityId, int oldPrebuildId)
{
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Invalid comparison between Unknown and I4
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: 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}");
}
}
}
}
[BepInPlugin("un1eagle.planetwideminer", "全球矿机", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource? Log;
internal static Plugin? Instance;
private void Awake()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
Instance = this;
Harmony val = new Harmony("un1eagle.planetwideminer");
val.PatchAll(typeof(Plugin).Assembly);
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;
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "un1eagle.planetwideminer";
public const string PLUGIN_NAME = "全球矿机";
public const string PLUGIN_VERSION = "1.0.0";
}
[HarmonyPatch(typeof(ProductionExtraInfoCalculator), "CalculateFactory")]
internal static class ProductionExtraInfoCalculatorFactoryPatch
{
[CompilerGenerated]
private sealed class _003CTranspiler_003Ed__1 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator
{
private int _003C_003E1__state;
private CodeInstruction _003C_003E2__current;
private int _003C_003El__initialThreadId;
private IEnumerable<CodeInstruction> instructions;
public IEnumerable<CodeInstruction> _003C_003E3__instructions;
private FieldInfo _003Cfield_003E5__2;
private bool _003CafterOilMultiplier_003E5__3;
private IEnumerator<CodeInstruction> _003C_003E7__wrap3;
private CodeInstruction _003Cins_003E5__5;
CodeInstruction IEnumerator<CodeInstruction>.Current
{
[DebuggerHidden]
get
{
return _003C_003E2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return _003C_003E2__current;
}
}
[DebuggerHidden]
public _003CTranspiler_003Ed__1(int _003C_003E1__state)
{
this._003C_003E1__state = _003C_003E1__state;
_003C_003El__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
switch (_003C_003E1__state)
{
case -3:
case 1:
try
{
}
finally
{
_003C_003Em__Finally1();
}
break;
case -4:
case 2:
case 3:
case 4:
case 5:
try
{
}
finally
{
_003C_003Em__Finally2();
}
break;
}
_003Cfield_003E5__2 = null;
_003C_003E7__wrap3 = null;
_003Cins_003E5__5 = null;
_003C_003E1__state = -2;
}
private bool MoveNext()
{
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Expected O, but got Unknown
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Expected O, but got Unknown
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_0297: Unknown result type (might be due to invalid IL or missing references)
//IL_02a1: Expected O, but got Unknown
try
{
switch (_003C_003E1__state)
{
default:
return false;
case 0:
_003C_003E1__state = -1;
_003Cfield_003E5__2 = AccessTools.Field(typeof(VeinData), "oilSpeedMultiplier");
if (_003Cfield_003E5__2 == null)
{
_003C_003E7__wrap3 = instructions.GetEnumerator();
_003C_003E1__state = -3;
goto IL_017f;
}
_003CafterOilMultiplier_003E5__3 = false;
_003C_003E7__wrap3 = instructions.GetEnumerator();
_003C_003E1__state = -4;
break;
case 1:
_003C_003E1__state = -3;
goto IL_017f;
case 2:
_003C_003E1__state = -4;
_003C_003E2__current = new CodeInstruction(OpCodes.Ldc_R4, (object)0f);
_003C_003E1__state = 3;
return true;
case 3:
_003C_003E1__state = -4;
_003C_003E2__current = ((_003Cins_003E5__5.opcode == OpCodes.Stloc || _003Cins_003E5__5.opcode == OpCodes.Stloc_S) ? new CodeInstruction(_003Cins_003E5__5.opcode, _003Cins_003E5__5.operand) : new CodeInstruction(_003Cins_003E5__5.opcode, (object)null));
_003C_003E1__state = 4;
return true;
case 4:
_003C_003E1__state = -4;
_003CafterOilMultiplier_003E5__3 = false;
break;
case 5:
{
_003C_003E1__state = -4;
_003Cins_003E5__5 = null;
break;
}
IL_017f:
if (_003C_003E7__wrap3.MoveNext())
{
CodeInstruction current = _003C_003E7__wrap3.Current;
_003C_003E2__current = current;
_003C_003E1__state = 1;
return true;
}
_003C_003Em__Finally1();
_003C_003E7__wrap3 = null;
return false;
}
if (_003C_003E7__wrap3.MoveNext())
{
_003Cins_003E5__5 = _003C_003E7__wrap3.Current;
if (_003CafterOilMultiplier_003E5__3 && (_003Cins_003E5__5.opcode == OpCodes.Stloc || _003Cins_003E5__5.opcode == OpCodes.Stloc_S || _003Cins_003E5__5.opcode == OpCodes.Stloc_0 || _003Cins_003E5__5.opcode == OpCodes.Stloc_1 || _003Cins_003E5__5.opcode == OpCodes.Stloc_2 || _003Cins_003E5__5.opcode == OpCodes.Stloc_3))
{
_003C_003E2__current = new CodeInstruction(OpCodes.Pop, (object)null);
_003C_003E1__state = 2;
return true;
}
if (_003Cins_003E5__5.opcode == OpCodes.Ldsfld && _003Cins_003E5__5.operand is FieldInfo fieldInfo && fieldInfo == _003Cfield_003E5__2)
{
_003CafterOilMultiplier_003E5__3 = true;
}
_003C_003E2__current = _003Cins_003E5__5;
_003C_003E1__state = 5;
return true;
}
_003C_003Em__Finally2();
_003C_003E7__wrap3 = null;
return false;
}
catch
{
((IDisposable)this).Dispose();
throw;
}
}
bool IEnumerator.MoveNext()
{
return MoveNext();
}
private void _003C_003Em__Finally1()
{
_003C_003E1__state = -1;
if (_003C_003E7__wrap3 != null)
{
_003C_003E7__wrap3.Dispose();
}
}
private void _003C_003Em__Finally2()
{
_003C_003E1__state = -1;
if (_003C_003E7__wrap3 != null)
{
_003C_003E7__wrap3.Dispose();
}
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
[DebuggerHidden]
IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
{
_003CTranspiler_003Ed__1 _003CTranspiler_003Ed__;
if (_003C_003E1__state == -2 && _003C_003El__initialThreadId == Environment.CurrentManagedThreadId)
{
_003C_003E1__state = 0;
_003CTranspiler_003Ed__ = this;
}
else
{
_003CTranspiler_003Ed__ = new _003CTranspiler_003Ed__1(0);
}
_003CTranspiler_003Ed__.instructions = _003C_003E3__instructions;
return _003CTranspiler_003Ed__;
}
[DebuggerHidden]
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
}
}
[HarmonyPrefix]
private static void Prefix(PlanetFactory factory)
{
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: 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;
}
}
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
try
{
int num = default(int);
FieldInfo fieldInfo = default(FieldInfo);
IEnumerator<CodeInstruction> enumerator = default(IEnumerator<CodeInstruction>);
bool flag = default(bool);
switch (num)
{
default:
yield break;
case 0:
fieldInfo = AccessTools.Field(typeof(VeinData), "oilSpeedMultiplier");
if (fieldInfo == null)
{
enumerator = instructions.GetEnumerator();
goto case 1;
}
flag = false;
enumerator = instructions.GetEnumerator();
break;
case 2:
new CodeInstruction(OpCodes.Ldc_R4, (object)0f);
/*Error near IL_0330: Unexpected return in MoveNext()*/;
case 3:
{
CodeInstruction val = default(CodeInstruction);
if (val.opcode == OpCodes.Stloc || val.opcode == OpCodes.Stloc_S)
{
new CodeInstruction(val.opcode, val.operand);
}
else
new CodeInstruction(val.opcode, (object)null);
/*Error near IL_0330: Unexpected return in MoveNext()*/;
}
case 4:
flag = false;
break;
case 1:
if (enumerator.MoveNext())
{
_ = enumerator.Current;
/*Error near IL_0330: Unexpected return in MoveNext()*/;
}
((_003CTranspiler_003Ed__1)/*Error near IL_01b5: stateMachine*/)._003C_003Em__Finally1();
yield break;
case 5:
break;
}
if (enumerator.MoveNext())
{
CodeInstruction val = enumerator.Current;
if (!flag || (!(val.opcode == OpCodes.Stloc) && !(val.opcode == OpCodes.Stloc_S) && !(val.opcode == OpCodes.Stloc_0) && !(val.opcode == OpCodes.Stloc_1) && !(val.opcode == OpCodes.Stloc_2) && !(val.opcode == OpCodes.Stloc_3)))
{
if (val.opcode == OpCodes.Ldsfld && val.operand is FieldInfo fieldInfo2 && fieldInfo2 == fieldInfo)
{
}
/*Error near IL_0330: Unexpected return in MoveNext()*/;
}
new CodeInstruction(OpCodes.Pop, (object)null);
/*Error near IL_0330: Unexpected return in MoveNext()*/;
}
((_003CTranspiler_003Ed__1)/*Error near IL_0312: stateMachine*/)._003C_003Em__Finally2();
}
catch
{
((IDisposable)/*Error near IL_0326: stateMachine*/).Dispose();
throw;
}
}
[HarmonyPostfix]
private static void Postfix(ProductionExtraInfoCalculator __instance, GameData gameData, PlanetFactory factory)
{
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Invalid comparison between Unknown and I4
//IL_0260: Unknown result type (might be due to invalid IL or missing references)
//IL_0266: 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(UIMinerWindow), "_OnUpdate")]
internal static class UIMinerWindowUpdatePatch
{
[HarmonyPostfix]
private static void Postfix(UIMinerWindow __instance)
{
//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)
//IL_0051: 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_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Invalid comparison between Unknown and I4
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: 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_0214: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_0243: Unknown result type (might be due to invalid IL or missing references)
//IL_0244: Unknown result type (might be due to invalid IL or missing references)
//IL_024a: Invalid comparison between Unknown and I4
try
{
if (__instance == 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}");
}
}
}
}
[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_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: 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_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Invalid comparison between Unknown and I4
//IL_0358: Unknown result type (might be due to invalid IL or missing references)
//IL_035e: 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;
}
}
}
}