using System;
using System.Collections.Concurrent;
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.Configuration;
using BepInEx.Logging;
using CommonAPI;
using CommonAPI.Systems;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using xiaoye97;
[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("MegaProduction")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Adds Mega versions of production buildings")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MegaProduction")]
[assembly: AssemblyTitle("MegaProduction")]
[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 MegaProduction
{
public struct MegaSlotData
{
public IODir dir;
public int beltId;
public int storageIdx;
public int counter;
}
public struct MegaSprayPool
{
public int incItemId;
public int incAbility;
public int incCount;
public int extraIncCount;
public const int incCapacity = 816;
public bool refConsumptionCalculated;
public float refProlifConsumption;
public int TotalCount => incCount + extraIncCount;
public bool CanAdd => TotalCount < 816;
public bool HasProliferator
{
get
{
if (incItemId != 0)
{
return TotalCount > 0;
}
return false;
}
}
}
public struct ProliferatorSlotData
{
public int itemId;
public int served;
public const int MaxCapacity = 10;
public bool CanAdd => served < 10;
public bool HasItems
{
get
{
if (itemId != 0)
{
return served > 0;
}
return false;
}
}
}
public struct MatrixSlotData
{
public int[] served;
public const int MaxCapacity = 10;
public int TotalCount => served[0] + served[1] + served[2] + served[3] + served[4] + served[5];
public MatrixSlotData(int dummy)
{
served = new int[6];
}
public bool CanAdd(int typeIdx)
{
return served[typeIdx] < 10;
}
}
public static class MegaBuildingPatches
{
public const int ProliferatorMk1 = 1141;
public const int ProliferatorMk2 = 1142;
public const int ProliferatorMk3 = 1143;
private static readonly ConcurrentDictionary<(int, int), MegaSlotData[]> SlotDataStore = new ConcurrentDictionary<(int, int), MegaSlotData[]>();
private static readonly ConcurrentDictionary<(int, int), MegaSprayPool> SprayPoolStore = new ConcurrentDictionary<(int, int), MegaSprayPool>();
private static readonly ConcurrentDictionary<(int, int), ProliferatorSlotData> ProliferatorSlotStore = new ConcurrentDictionary<(int, int), ProliferatorSlotData>();
private static readonly ConcurrentDictionary<(int, int), MatrixSlotData> MatrixSlotStore = new ConcurrentDictionary<(int, int), MatrixSlotData>();
private static readonly ConcurrentDictionary<(int, int), int> ProliferatorConsumptionStore = new ConcurrentDictionary<(int, int), int>();
public static int MegaAssemblerSpeed => 10000 * Plugin.MegaBuildingSpeedMultiplier - 1000;
public static MegaSlotData[] GetSlots(int planetId, int entityId)
{
return SlotDataStore.GetOrAdd((planetId, entityId), ((int, int) _) => new MegaSlotData[12]);
}
public static bool IsMegaAssembler(FactorySystem factorySystem, int assemblerId)
{
if (assemblerId <= 0)
{
return false;
}
ref AssemblerComponent reference = ref factorySystem.assemblerPool[assemblerId];
if (reference.id == assemblerId)
{
return reference.speed >= MegaAssemblerSpeed;
}
return false;
}
public static bool IsMegaLab(FactorySystem factorySystem, int labId)
{
if (labId <= 0)
{
return false;
}
ref LabComponent reference = ref factorySystem.labPool[labId];
if (reference.id == labId)
{
return reference.speed >= MegaAssemblerSpeed;
}
return false;
}
public static bool IsMegaFractionator(FactorySystem factorySystem, int fractionatorId)
{
if (fractionatorId <= 0)
{
return false;
}
ref FractionatorComponent reference = ref factorySystem.fractionatorPool[fractionatorId];
if (reference.id == fractionatorId)
{
return reference.fluidInputMax <= 400;
}
return false;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(FactorySystem), "NewAssemblerComponent")]
public static void FactorySystem_NewAssemblerComponent_Postfix(ref FactorySystem __instance, int __result, int entityId, int speed)
{
_ = MegaAssemblerSpeed;
}
public static void RemoveSlots(int planetId, int entityId)
{
SlotDataStore.TryRemove((planetId, entityId), out var _);
SprayPoolStore.TryRemove((planetId, entityId), out var _);
ProliferatorSlotStore.TryRemove((planetId, entityId), out var _);
MatrixSlotStore.TryRemove((planetId, entityId), out var _);
}
public static MegaSprayPool GetSprayPool(int planetId, int entityId)
{
return SprayPoolStore.GetOrAdd((planetId, entityId), ((int, int) _) => default(MegaSprayPool));
}
public static void SetSprayPool(int planetId, int entityId, MegaSprayPool pool)
{
SprayPoolStore[(planetId, entityId)] = pool;
}
public static ProliferatorSlotData GetProliferatorSlot(int planetId, int entityId)
{
return ProliferatorSlotStore.GetOrAdd((planetId, entityId), ((int, int) _) => default(ProliferatorSlotData));
}
public static void SetProliferatorSlot(int planetId, int entityId, ProliferatorSlotData slot)
{
ProliferatorSlotStore[(planetId, entityId)] = slot;
}
public static MatrixSlotData GetMatrixSlot(int planetId, int entityId)
{
return MatrixSlotStore.GetOrAdd((planetId, entityId), ((int, int) _) => new MatrixSlotData(0));
}
public static void SetMatrixSlot(int planetId, int entityId, MatrixSlotData slot)
{
MatrixSlotStore[(planetId, entityId)] = slot;
}
public static IEnumerable<KeyValuePair<(int planetId, int entityId), MegaSprayPool>> GetAllSprayPools()
{
return SprayPoolStore.ToArray();
}
public static void UpdateSprayPool(int planetId, int entityId, MegaSprayPool pool)
{
SprayPoolStore[(planetId, entityId)] = pool;
}
public static void ResetRefConsumptionFlags()
{
(int, int)[] array = SprayPoolStore.Keys.ToArray();
foreach ((int, int) key in array)
{
MegaSprayPool value = SprayPoolStore[key];
value.refConsumptionCalculated = false;
SprayPoolStore[key] = value;
}
}
public static void TrackProliferatorConsumption(int planetId, int entityId, int chargesConsumed, int factoryIndex)
{
if (chargesConsumed <= 0)
{
return;
}
MegaSprayPool sprayPool = GetSprayPool(planetId, entityId);
if (!sprayPool.HasProliferator || sprayPool.incItemId <= 0)
{
return;
}
ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(sprayPool.incItemId);
if (val == null)
{
return;
}
int hpMax = val.HpMax;
if (hpMax <= 0)
{
return;
}
int num = ProliferatorConsumptionStore.AddOrUpdate((planetId, entityId), chargesConsumed, ((int, int) _, int old) => old + chargesConsumed) / hpMax;
if (num <= 0 || factoryIndex < 0 || GameMain.statistics?.production?.factoryStatPool == null)
{
return;
}
FactoryProductionStat val2 = GameMain.statistics.production.factoryStatPool[factoryIndex];
if (val2?.consumeRegister == null)
{
return;
}
int usedCharges = num * hpMax;
ProliferatorConsumptionStore.AddOrUpdate((planetId, entityId), 0, ((int, int) _, int old) => old - usedCharges);
lock (val2.consumeRegister)
{
val2.consumeRegister[sprayPool.incItemId] += num;
}
}
public static int GetProliferatorIncLevel(int itemId)
{
return itemId switch
{
1141 => 1,
1142 => 2,
1143 => 4,
_ => 0,
};
}
public static bool IsProliferator(int itemId)
{
if (itemId != 1141 && itemId != 1142)
{
return itemId == 1143;
}
return true;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlanetFactory), "ApplyInsertTarget")]
public static void PlanetFactory_ApplyInsertTarget_Postfix(ref PlanetFactory __instance, int entityId, int insertTarget, int slotId)
{
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
if (entityId == 0)
{
return;
}
int assemblerId = __instance.entityPool[entityId].assemblerId;
int labId = __instance.entityPool[entityId].labId;
int fractionatorId = __instance.entityPool[entityId].fractionatorId;
bool num = IsMegaAssembler(__instance.factorySystem, assemblerId);
bool flag = IsMegaLab(__instance.factorySystem, labId);
bool flag2 = IsMegaFractionator(__instance.factorySystem, fractionatorId);
if (num || flag || flag2)
{
int beltId = __instance.entityPool[insertTarget].beltId;
if (beltId > 0)
{
MegaSlotData[] slots = GetSlots(__instance.planetId, entityId);
slots[slotId].dir = (IODir)1;
slots[slotId].beltId = beltId;
slots[slotId].counter = 0;
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlanetFactory), "ApplyPickTarget")]
public static void PlanetFactory_ApplyPickTarget_Postfix(ref PlanetFactory __instance, int entityId, int pickTarget, int slotId)
{
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
if (entityId == 0)
{
return;
}
int assemblerId = __instance.entityPool[entityId].assemblerId;
int labId = __instance.entityPool[entityId].labId;
int fractionatorId = __instance.entityPool[entityId].fractionatorId;
bool num = IsMegaAssembler(__instance.factorySystem, assemblerId);
bool flag = IsMegaLab(__instance.factorySystem, labId);
bool flag2 = IsMegaFractionator(__instance.factorySystem, fractionatorId);
if (num || flag || flag2)
{
int beltId = __instance.entityPool[pickTarget].beltId;
if (beltId > 0)
{
MegaSlotData[] slots = GetSlots(__instance.planetId, entityId);
slots[slotId].dir = (IODir)2;
slots[slotId].beltId = beltId;
slots[slotId].storageIdx = 0;
slots[slotId].counter = 0;
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlanetFactory), "ApplyEntityDisconnection")]
public static void PlanetFactory_ApplyEntityDisconnection_Postfix(ref PlanetFactory __instance, int otherEntityId, int removingEntityId, int otherSlotId)
{
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
if (otherEntityId != 0)
{
int assemblerId = __instance.entityPool[otherEntityId].assemblerId;
int labId = __instance.entityPool[otherEntityId].labId;
int fractionatorId = __instance.entityPool[otherEntityId].fractionatorId;
bool num = IsMegaAssembler(__instance.factorySystem, assemblerId);
bool flag = IsMegaLab(__instance.factorySystem, labId);
bool flag2 = IsMegaFractionator(__instance.factorySystem, fractionatorId);
if ((num || flag || flag2) && __instance.entityPool[removingEntityId].beltId > 0)
{
MegaSlotData[] slots = GetSlots(__instance.planetId, otherEntityId);
slots[otherSlotId].dir = (IODir)0;
slots[otherSlotId].beltId = 0;
slots[otherSlotId].counter = 0;
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(FactorySystem), "SetFractionatorBelt")]
public static void FactorySystem_SetFractionatorBelt_Postfix(ref FactorySystem __instance, int fracId, int beltId, int slot, bool isOutput)
{
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
if (fracId <= 0 || beltId <= 0 || slot < 0 || slot > 2)
{
return;
}
ref FractionatorComponent reference = ref __instance.fractionatorPool[fracId];
if (reference.id == fracId && reference.fluidInputMax <= 400)
{
int entityId = reference.entityId;
if (entityId > 0)
{
MegaSlotData[] slots = GetSlots(__instance.factory.planetId, entityId);
slots[slot].beltId = beltId;
slots[slot].dir = (IODir)(isOutput ? 1 : 2);
slots[slot].counter = 0;
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(PlanetFactory), "RemoveEntityWithComponents")]
[HarmonyPriority(700)]
public static void PlanetFactory_RemoveEntityWithComponents_Prefix(ref PlanetFactory __instance, int id)
{
if (id != 0)
{
ref EntityData reference = ref __instance.entityPool[id];
if (reference.id != 0 && (reference.assemblerId != 0 || reference.labId != 0 || reference.fractionatorId != 0))
{
RemoveSlots(__instance.planetId, id);
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(AssemblerComponent), "InternalUpdate")]
public static void AssemblerComponent_InternalUpdate_Postfix(ref AssemblerComponent __instance, float power)
{
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Invalid comparison between Unknown and I4
//IL_0415: Unknown result type (might be due to invalid IL or missing references)
//IL_041b: Invalid comparison between Unknown and I4
if (__instance.speed < MegaAssemblerSpeed)
{
return;
}
PlanetFactory val = GameMain.localPlanet?.factory;
if (val == null)
{
return;
}
CargoTraffic cargoTraffic = val.cargoTraffic;
if (cargoTraffic == null)
{
return;
}
int entityId = __instance.entityId;
MegaSlotData[] slots = GetSlots(val.planetId, entityId);
SignData[] entitySignPool = val.entitySignPool;
if (__instance.recipeId == 0)
{
return;
}
MegaSprayPool sprayPool = GetSprayPool(val.planetId, entityId);
ProliferatorSlotData proliferatorSlot = GetProliferatorSlot(val.planetId, entityId);
int planetId = val.planetId;
int num = default(int);
byte b = default(byte);
byte b2 = default(byte);
int num9 = default(int);
byte b3 = default(byte);
byte b4 = default(byte);
for (int i = 0; i < slots.Length; i++)
{
ref MegaSlotData reference = ref slots[i];
if ((int)reference.dir != 2 || reference.beltId <= 0)
{
continue;
}
ref BeltComponent reference2 = ref cargoTraffic.beltPool[reference.beltId];
if (reference2.id <= 0)
{
continue;
}
CargoPath cargoPath = cargoTraffic.GetCargoPath(reference2.segPathId);
if (cargoPath == null)
{
continue;
}
if (proliferatorSlot.CanAdd)
{
int[] array = new int[6] { 1143, 1142, 1141, 0, 0, 0 };
int num2 = cargoPath.TryPickItemAtRear(array, ref num, ref b, ref b2);
if (num2 > 0 && IsProliferator(num2))
{
int num3 = b;
if (num3 > 0)
{
if (proliferatorSlot.itemId == 0)
{
proliferatorSlot.itemId = num2;
}
if (proliferatorSlot.itemId == num2)
{
proliferatorSlot.served += num3;
}
SetProliferatorSlot(planetId, entityId, proliferatorSlot);
entitySignPool[reference2.entityId].iconType = 1u;
entitySignPool[reference2.entityId].iconId0 = (uint)num2;
continue;
}
}
}
if (proliferatorSlot.HasItems && sprayPool.CanAdd)
{
ItemProto obj = ((ProtoSet<ItemProto>)(object)LDB.items).Select(proliferatorSlot.itemId);
int num4 = obj?.HpMax ?? 75;
int incAbility = obj?.Ability ?? 1;
int proliferatorIncLevel = GetProliferatorIncLevel(proliferatorSlot.itemId);
int num5 = (int)((double)num4 * ((double)Cargo.incTable[proliferatorIncLevel] * 0.001) + 0.1);
int num6 = num4 + num5;
int num7 = 816 - sprayPool.TotalCount;
int num8 = Math.Min(proliferatorSlot.served, num7 / num6);
if (num8 > 0)
{
if (sprayPool.incItemId == 0)
{
sprayPool.incItemId = proliferatorSlot.itemId;
sprayPool.incAbility = incAbility;
}
if (sprayPool.incItemId == proliferatorSlot.itemId)
{
sprayPool.incCount += num4 * num8;
sprayPool.extraIncCount += num5 * num8;
}
SetSprayPool(planetId, entityId, sprayPool);
proliferatorSlot.served -= num8;
if (proliferatorSlot.served == 0)
{
proliferatorSlot.itemId = 0;
}
SetProliferatorSlot(planetId, entityId, proliferatorSlot);
}
}
int num10 = cargoPath.TryPickItemAtRear(__instance.needs, ref num9, ref b3, ref b4);
if (num9 < 0 || num10 <= 0 || __instance.needs[num9] != num10)
{
continue;
}
__instance.served[num9] += b3;
int num11 = 0;
if (sprayPool.HasProliferator && sprayPool.TotalCount >= b3 && b4 < sprayPool.incAbility)
{
int num12 = b3;
int incCount = sprayPool.incCount;
if (sprayPool.extraIncCount >= num12)
{
sprayPool.extraIncCount -= num12;
}
else
{
num12 -= sprayPool.extraIncCount;
sprayPool.extraIncCount = 0;
sprayPool.incCount -= num12;
}
num11 = sprayPool.incAbility;
SetSprayPool(planetId, entityId, sprayPool);
int num13 = incCount - sprayPool.incCount;
if (num13 > 0)
{
TrackProliferatorConsumption(planetId, entityId, num13, val.index);
}
}
if (num11 > 0)
{
__instance.incServed[num9] += b3 * num11;
}
else
{
__instance.incServed[num9] += b4;
}
entitySignPool[reference2.entityId].iconType = 1u;
entitySignPool[reference2.entityId].iconId0 = (uint)num10;
}
for (int j = 0; j < slots.Length; j++)
{
ref MegaSlotData reference3 = ref slots[j];
if ((int)reference3.dir != 1 || reference3.beltId <= 0)
{
continue;
}
int[] array2 = __instance.recipeExecuteData?.products;
if (array2 == null)
{
continue;
}
int num14 = reference3.storageIdx - 1;
if (num14 >= 0 && num14 < array2.Length)
{
if (__instance.produced[num14] > 0)
{
byte b5 = (byte)Math.Min(__instance.produced[num14], 4);
if (cargoTraffic.TryInsertItemAtHead(reference3.beltId, array2[num14], b5, (byte)0))
{
__instance.produced[num14] -= b5;
}
}
continue;
}
for (int k = 0; k < array2.Length; k++)
{
if (__instance.produced[k] > 0)
{
byte b6 = (byte)Math.Min(__instance.produced[k], 4);
if (cargoTraffic.TryInsertItemAtHead(reference3.beltId, array2[k], b6, (byte)0))
{
__instance.produced[k] -= b6;
break;
}
}
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(LabComponent), "InternalUpdateAssemble")]
public static void LabComponent_InternalUpdateAssemble_Postfix(ref LabComponent __instance, float power)
{
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Invalid comparison between Unknown and I4
//IL_0415: Unknown result type (might be due to invalid IL or missing references)
//IL_041b: Invalid comparison between Unknown and I4
if (__instance.speed < MegaAssemblerSpeed)
{
return;
}
PlanetFactory val = GameMain.localPlanet?.factory;
if (val == null)
{
return;
}
CargoTraffic cargoTraffic = val.cargoTraffic;
if (cargoTraffic == null)
{
return;
}
int entityId = __instance.entityId;
MegaSlotData[] slots = GetSlots(val.planetId, entityId);
SignData[] entitySignPool = val.entitySignPool;
if (__instance.recipeId == 0)
{
return;
}
MegaSprayPool sprayPool = GetSprayPool(val.planetId, entityId);
ProliferatorSlotData proliferatorSlot = GetProliferatorSlot(val.planetId, entityId);
int planetId = val.planetId;
int num = default(int);
byte b = default(byte);
byte b2 = default(byte);
int num9 = default(int);
byte b3 = default(byte);
byte b4 = default(byte);
for (int i = 0; i < slots.Length; i++)
{
ref MegaSlotData reference = ref slots[i];
if ((int)reference.dir != 2 || reference.beltId <= 0)
{
continue;
}
ref BeltComponent reference2 = ref cargoTraffic.beltPool[reference.beltId];
if (reference2.id <= 0)
{
continue;
}
CargoPath cargoPath = cargoTraffic.GetCargoPath(reference2.segPathId);
if (cargoPath == null)
{
continue;
}
if (proliferatorSlot.CanAdd)
{
int[] array = new int[6] { 1143, 1142, 1141, 0, 0, 0 };
int num2 = cargoPath.TryPickItemAtRear(array, ref num, ref b, ref b2);
if (num2 > 0 && IsProliferator(num2))
{
int num3 = b;
if (num3 > 0)
{
if (proliferatorSlot.itemId == 0)
{
proliferatorSlot.itemId = num2;
}
if (proliferatorSlot.itemId == num2)
{
proliferatorSlot.served += num3;
}
SetProliferatorSlot(planetId, entityId, proliferatorSlot);
entitySignPool[reference2.entityId].iconType = 1u;
entitySignPool[reference2.entityId].iconId0 = (uint)num2;
continue;
}
}
}
if (proliferatorSlot.HasItems && sprayPool.CanAdd)
{
ItemProto obj = ((ProtoSet<ItemProto>)(object)LDB.items).Select(proliferatorSlot.itemId);
int num4 = obj?.HpMax ?? 75;
int incAbility = obj?.Ability ?? 1;
int proliferatorIncLevel = GetProliferatorIncLevel(proliferatorSlot.itemId);
int num5 = (int)((double)num4 * ((double)Cargo.incTable[proliferatorIncLevel] * 0.001) + 0.1);
int num6 = num4 + num5;
int num7 = 816 - sprayPool.TotalCount;
int num8 = Math.Min(proliferatorSlot.served, num7 / num6);
if (num8 > 0)
{
if (sprayPool.incItemId == 0)
{
sprayPool.incItemId = proliferatorSlot.itemId;
sprayPool.incAbility = incAbility;
}
if (sprayPool.incItemId == proliferatorSlot.itemId)
{
sprayPool.incCount += num4 * num8;
sprayPool.extraIncCount += num5 * num8;
}
SetSprayPool(planetId, entityId, sprayPool);
proliferatorSlot.served -= num8;
if (proliferatorSlot.served == 0)
{
proliferatorSlot.itemId = 0;
}
SetProliferatorSlot(planetId, entityId, proliferatorSlot);
}
}
int num10 = cargoPath.TryPickItemAtRear(__instance.needs, ref num9, ref b3, ref b4);
if (num9 < 0 || num10 <= 0 || __instance.needs[num9] != num10)
{
continue;
}
__instance.served[num9] += b3;
int num11 = 0;
if (sprayPool.HasProliferator && sprayPool.TotalCount >= b3 && b4 < sprayPool.incAbility)
{
int num12 = b3;
int incCount = sprayPool.incCount;
if (sprayPool.extraIncCount >= num12)
{
sprayPool.extraIncCount -= num12;
}
else
{
num12 -= sprayPool.extraIncCount;
sprayPool.extraIncCount = 0;
sprayPool.incCount -= num12;
}
num11 = sprayPool.incAbility;
SetSprayPool(planetId, entityId, sprayPool);
int num13 = incCount - sprayPool.incCount;
if (num13 > 0)
{
TrackProliferatorConsumption(planetId, entityId, num13, val.index);
}
}
if (num11 > 0)
{
__instance.incServed[num9] += b3 * num11;
}
else
{
__instance.incServed[num9] += b4;
}
entitySignPool[reference2.entityId].iconType = 1u;
entitySignPool[reference2.entityId].iconId0 = (uint)num10;
}
for (int j = 0; j < slots.Length; j++)
{
ref MegaSlotData reference3 = ref slots[j];
if ((int)reference3.dir != 1 || reference3.beltId <= 0)
{
continue;
}
int[] array2 = __instance.recipeExecuteData?.products;
if (array2 == null)
{
continue;
}
int num14 = reference3.storageIdx - 1;
if (num14 >= 0 && num14 < array2.Length)
{
if (__instance.produced[num14] > 0)
{
byte b5 = (byte)Math.Min(__instance.produced[num14], 4);
if (cargoTraffic.TryInsertItemAtHead(reference3.beltId, array2[num14], b5, (byte)0))
{
__instance.produced[num14] -= b5;
}
}
continue;
}
for (int k = 0; k < array2.Length; k++)
{
if (__instance.produced[k] > 0)
{
byte b6 = (byte)Math.Min(__instance.produced[k], 4);
if (cargoTraffic.TryInsertItemAtHead(reference3.beltId, array2[k], b6, (byte)0))
{
__instance.produced[k] -= b6;
break;
}
}
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(LabComponent), "InternalUpdateResearch")]
public static void LabComponent_InternalUpdateResearch_Prefix(ref LabComponent __instance, ref float research_speed)
{
if (__instance.speed >= MegaAssemblerSpeed && __instance.researchMode)
{
research_speed *= Plugin.MegaLabResearchHashMultiplier;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(LabComponent), "InternalUpdateResearch")]
public static void LabComponent_InternalUpdateResearch_Postfix(ref LabComponent __instance, float power)
{
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Invalid comparison between Unknown and I4
if (__instance.speed < MegaAssemblerSpeed || !__instance.researchMode)
{
return;
}
PlanetFactory val = GameMain.localPlanet?.factory;
if (val == null)
{
return;
}
CargoTraffic cargoTraffic = val.cargoTraffic;
if (cargoTraffic == null)
{
return;
}
int entityId = __instance.entityId;
MegaSlotData[] slots = GetSlots(val.planetId, entityId);
SignData[] entitySignPool = val.entitySignPool;
MegaSprayPool sprayPool = GetSprayPool(val.planetId, entityId);
ProliferatorSlotData proliferatorSlot = GetProliferatorSlot(val.planetId, entityId);
GetMatrixSlot(val.planetId, entityId);
int planetId = val.planetId;
if (__instance.matrixIncServed == null && __instance.matrixServed != null)
{
__instance.matrixIncServed = new int[__instance.matrixServed.Length];
}
int[] array = new int[6] { 6001, 6002, 6003, 6004, 6005, 6006 };
int num = default(int);
byte b = default(byte);
byte b2 = default(byte);
int num9 = default(int);
byte b3 = default(byte);
byte b4 = default(byte);
for (int i = 0; i < slots.Length; i++)
{
ref MegaSlotData reference = ref slots[i];
if ((int)reference.dir != 2 || reference.beltId <= 0)
{
continue;
}
ref BeltComponent reference2 = ref cargoTraffic.beltPool[reference.beltId];
if (reference2.id <= 0)
{
continue;
}
CargoPath cargoPath = cargoTraffic.GetCargoPath(reference2.segPathId);
if (cargoPath == null)
{
continue;
}
if (proliferatorSlot.CanAdd)
{
int[] array2 = new int[6] { 1143, 1142, 1141, 0, 0, 0 };
int num2 = cargoPath.TryPickItemAtRear(array2, ref num, ref b, ref b2);
if (num2 > 0 && IsProliferator(num2))
{
int num3 = b;
if (num3 > 0)
{
if (proliferatorSlot.itemId == 0)
{
proliferatorSlot.itemId = num2;
}
if (proliferatorSlot.itemId == num2)
{
proliferatorSlot.served += num3;
}
SetProliferatorSlot(planetId, entityId, proliferatorSlot);
entitySignPool[reference2.entityId].iconType = 1u;
entitySignPool[reference2.entityId].iconId0 = (uint)num2;
continue;
}
}
}
if (proliferatorSlot.HasItems && sprayPool.CanAdd)
{
ItemProto obj = ((ProtoSet<ItemProto>)(object)LDB.items).Select(proliferatorSlot.itemId);
int num4 = obj?.HpMax ?? 75;
int incAbility = obj?.Ability ?? 1;
int proliferatorIncLevel = GetProliferatorIncLevel(proliferatorSlot.itemId);
int num5 = (int)((double)num4 * ((double)Cargo.incTable[proliferatorIncLevel] * 0.001) + 0.1);
int num6 = num4 + num5;
int num7 = 816 - sprayPool.TotalCount;
int num8 = Math.Min(proliferatorSlot.served, num7 / num6);
if (num8 > 0)
{
if (sprayPool.incItemId == 0)
{
sprayPool.incItemId = proliferatorSlot.itemId;
sprayPool.incAbility = incAbility;
}
if (sprayPool.incItemId == proliferatorSlot.itemId)
{
sprayPool.incCount += num4 * num8;
sprayPool.extraIncCount += num5 * num8;
}
SetSprayPool(planetId, entityId, sprayPool);
proliferatorSlot.served -= num8;
if (proliferatorSlot.served == 0)
{
proliferatorSlot.itemId = 0;
}
SetProliferatorSlot(planetId, entityId, proliferatorSlot);
}
}
int[] array3 = new int[6];
bool flag = false;
for (int j = 0; j < 6; j++)
{
if (LabComponent.matrixPoints[j] > 0 && __instance.matrixServed[j] < 140400)
{
array3[j] = array[j];
flag = true;
}
}
if (!flag)
{
continue;
}
int num10 = cargoPath.TryPickItemAtRear(array3, ref num9, ref b3, ref b4);
if (num9 < 0 || num10 <= 0 || array3[num9] != num10)
{
continue;
}
int num11 = 0;
if (sprayPool.HasProliferator && sprayPool.TotalCount >= b3)
{
int num12 = b3;
int incCount = sprayPool.incCount;
if (sprayPool.extraIncCount >= num12)
{
sprayPool.extraIncCount -= num12;
}
else
{
num12 -= sprayPool.extraIncCount;
sprayPool.extraIncCount = 0;
sprayPool.incCount -= num12;
}
num11 = sprayPool.incAbility;
SetSprayPool(planetId, entityId, sprayPool);
int num13 = incCount - sprayPool.incCount;
if (num13 > 0)
{
TrackProliferatorConsumption(planetId, entityId, num13, val.index);
}
}
__instance.matrixServed[num9] += b3 * 3600;
if (num11 > 0 && __instance.matrixIncServed != null)
{
__instance.matrixIncServed[num9] += b3 * 3600 * num11;
}
entitySignPool[reference2.entityId].iconType = 1u;
entitySignPool[reference2.entityId].iconId0 = (uint)num10;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(FractionatorComponent), "SetRecipe")]
public static void FractionatorComponent_SetRecipe_Postfix(ref FractionatorComponent __instance)
{
if (__instance.fluidInputMax <= 400)
{
float num = (float)Plugin.MegaBuildingSpeedMultiplier / 4f * 0.01f;
__instance.produceProb = Math.Min(1f, (float)Math.Round(num, 4));
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(FractionatorComponent), "InternalUpdate")]
public static void FractionatorComponent_InternalUpdate_Prefix(ref FractionatorComponent __instance, out (int belt0, int belt1, int belt2, bool isMega) __state)
{
bool flag = __instance.fluidInputMax <= 400;
__state = (__instance.belt0, __instance.belt1, __instance.belt2, flag);
if (flag)
{
__instance.belt0 = 0;
__instance.belt1 = 0;
__instance.belt2 = 0;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(FractionatorComponent), "InternalUpdate")]
public static void FractionatorComponent_InternalUpdate_Postfix(ref FractionatorComponent __instance, float power, PlanetFactory factory, SignData[] signPool, (int belt0, int belt1, int belt2, bool isMega) __state)
{
//IL_0106: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Invalid comparison between Unknown and I4
//IL_063c: Unknown result type (might be due to invalid IL or missing references)
//IL_0642: Invalid comparison between Unknown and I4
if (__state.isMega)
{
(__instance.belt0, __instance.belt1, __instance.belt2, _) = __state;
}
if (!__state.isMega)
{
return;
}
float num = ((__instance.fluidInputCount > 0 && __instance.fluidInputCargoCount > 0f) ? ((float)__instance.fluidInputCount / __instance.fluidInputCargoCount) : 4f);
float num2 = Math.Min(__instance.fluidInputCargoCount, 30f);
int num3 = (int)(166.66666666666666 * (double)num2 * (double)num * 5.0);
__instance.progress += num3;
if (power < 0.1f)
{
return;
}
CargoTraffic cargoTraffic = factory.cargoTraffic;
if (cargoTraffic == null)
{
return;
}
int entityId = __instance.entityId;
MegaSlotData[] slots = GetSlots(factory.planetId, entityId);
MegaSprayPool sprayPool = GetSprayPool(factory.planetId, entityId);
ProliferatorSlotData proliferatorSlot = GetProliferatorSlot(factory.planetId, entityId);
int planetId = factory.planetId;
int num4 = 0;
int num5 = default(int);
byte b = default(byte);
byte b2 = default(byte);
byte b3 = default(byte);
byte b4 = default(byte);
byte b5 = default(byte);
byte b6 = default(byte);
for (int i = 0; i < slots.Length; i++)
{
ref MegaSlotData reference = ref slots[i];
if ((int)reference.dir != 2 || reference.beltId <= 0)
{
continue;
}
ref BeltComponent reference2 = ref cargoTraffic.beltPool[reference.beltId];
if (reference2.id <= 0)
{
continue;
}
CargoPath cargoPath = cargoTraffic.GetCargoPath(reference2.segPathId);
if (cargoPath == null)
{
continue;
}
if (num4 < 10 && proliferatorSlot.CanAdd)
{
int[] array = new int[6] { 1143, 1142, 1141, 0, 0, 0 };
int num6 = cargoPath.TryPickItemAtRear(array, ref num5, ref b, ref b2);
if (num6 > 0 && IsProliferator(num6))
{
int val = b;
val = Math.Min(val, 10 - num4);
if (val > 0)
{
if (proliferatorSlot.itemId == 0)
{
proliferatorSlot.itemId = num6;
}
if (proliferatorSlot.itemId == num6)
{
proliferatorSlot.served += val;
}
SetProliferatorSlot(planetId, entityId, proliferatorSlot);
num4 += val;
signPool[reference2.entityId].iconType = 1u;
signPool[reference2.entityId].iconId0 = (uint)num6;
continue;
}
}
}
if (proliferatorSlot.HasItems && sprayPool.CanAdd)
{
ItemProto obj = ((ProtoSet<ItemProto>)(object)LDB.items).Select(proliferatorSlot.itemId);
int num7 = obj?.HpMax ?? 75;
int incAbility = obj?.Ability ?? 1;
int proliferatorIncLevel = GetProliferatorIncLevel(proliferatorSlot.itemId);
int num8 = (int)((double)num7 * ((double)Cargo.incTable[proliferatorIncLevel] * 0.001) + 0.1);
int num9 = num7 + num8;
int num10 = 816 - sprayPool.TotalCount;
int num11 = Math.Min(proliferatorSlot.served, num10 / num9);
if (num11 > 0)
{
if (sprayPool.incItemId == 0)
{
sprayPool.incItemId = proliferatorSlot.itemId;
sprayPool.incAbility = incAbility;
}
if (sprayPool.incItemId == proliferatorSlot.itemId)
{
sprayPool.incCount += num7 * num11;
sprayPool.extraIncCount += num8 * num11;
}
SetSprayPool(planetId, entityId, sprayPool);
proliferatorSlot.served -= num11;
if (proliferatorSlot.served == 0)
{
proliferatorSlot.itemId = 0;
}
SetProliferatorSlot(planetId, entityId, proliferatorSlot);
}
}
if (__instance.fluidInputCargoCount >= (float)__instance.fluidInputMax)
{
continue;
}
int fluidId = __instance.fluidId;
if (fluidId > 0)
{
int[] array2 = new int[6] { fluidId, 0, 0, 0, 0, 0 };
int num12 = cargoPath.TryPickItemAtRear(array2, ref num5, ref b3, ref b4);
if (num12 <= 0 || num12 != fluidId)
{
continue;
}
__instance.fluidInputCount += b3;
__instance.fluidInputInc += b4;
__instance.fluidInputCargoCount += 1f;
int num13 = 0;
if (sprayPool.HasProliferator && sprayPool.TotalCount >= b3 && b4 < sprayPool.incAbility)
{
int num14 = b3;
int incCount = sprayPool.incCount;
if (sprayPool.extraIncCount >= num14)
{
sprayPool.extraIncCount -= num14;
}
else
{
num14 -= sprayPool.extraIncCount;
sprayPool.extraIncCount = 0;
sprayPool.incCount -= num14;
}
num13 = sprayPool.incAbility;
SetSprayPool(planetId, entityId, sprayPool);
int num15 = incCount - sprayPool.incCount;
if (num15 > 0)
{
TrackProliferatorConsumption(planetId, entityId, num15, factory.index);
}
}
if (num13 > 0)
{
__instance.fluidInputInc += b3 * num13;
}
else
{
__instance.fluidInputInc += b4;
}
signPool[reference2.entityId].iconType = 1u;
signPool[reference2.entityId].iconId0 = (uint)num12;
continue;
}
int[] array3;
if (RecipeProto.fractionatorNeeds.Length >= 6)
{
array3 = RecipeProto.fractionatorNeeds;
}
else
{
array3 = new int[6];
Array.Copy(RecipeProto.fractionatorNeeds, array3, RecipeProto.fractionatorNeeds.Length);
}
int num16 = cargoPath.TryPickItemAtRear(array3, ref num5, ref b5, ref b6);
if (num16 <= 0)
{
continue;
}
((FractionatorComponent)(ref __instance)).SetRecipe(num16, signPool);
__instance.fluidInputCount += b5;
__instance.fluidInputInc += b6;
__instance.fluidInputCargoCount += 1f;
int num17 = 0;
if (sprayPool.HasProliferator && sprayPool.TotalCount >= b5 && b6 < sprayPool.incAbility)
{
int num18 = b5;
int incCount2 = sprayPool.incCount;
if (sprayPool.extraIncCount >= num18)
{
sprayPool.extraIncCount -= num18;
}
else
{
num18 -= sprayPool.extraIncCount;
sprayPool.extraIncCount = 0;
sprayPool.incCount -= num18;
}
num17 = sprayPool.incAbility;
SetSprayPool(planetId, entityId, sprayPool);
int num19 = incCount2 - sprayPool.incCount;
if (num19 > 0)
{
TrackProliferatorConsumption(planetId, entityId, num19, factory.index);
}
}
if (num17 > 0)
{
__instance.fluidInputInc += b5 * num17;
}
else
{
__instance.fluidInputInc += b6;
}
signPool[reference2.entityId].iconType = 1u;
signPool[reference2.entityId].iconId0 = (uint)num16;
}
for (int j = 0; j < slots.Length; j++)
{
ref MegaSlotData reference3 = ref slots[j];
if ((int)reference3.dir != 1 || reference3.beltId <= 0)
{
continue;
}
int storageIdx = reference3.storageIdx;
if (storageIdx == 1 && __instance.productId > 0 && __instance.productOutputCount > 0)
{
byte b7 = (byte)Math.Min(__instance.productOutputCount, 4);
int productId = __instance.productId;
int num20 = ((__instance.productOutputCount > 0) ? ((FractionatorComponent)(ref __instance)).incLevel : 0);
if (cargoTraffic.TryInsertItemAtHead(reference3.beltId, productId, b7, (byte)num20))
{
__instance.productOutputCount -= b7;
}
}
else if (storageIdx == 2 && __instance.fluidId > 0 && __instance.fluidOutputCount > 0)
{
byte b8 = (byte)Math.Min(__instance.fluidOutputCount, 4);
int fluidId2 = __instance.fluidId;
int num21 = ((__instance.fluidOutputCount > 0) ? (__instance.fluidOutputInc / __instance.fluidOutputCount) : 0);
if (cargoTraffic.TryInsertItemAtHead(reference3.beltId, fluidId2, b8, (byte)num21))
{
__instance.fluidOutputCount -= b8;
__instance.fluidOutputInc -= num21 * b8;
}
}
else
{
if (storageIdx != 0)
{
continue;
}
if (__instance.productId > 0 && __instance.productOutputCount > 0)
{
byte b9 = (byte)Math.Min(__instance.productOutputCount, 4);
int productId2 = __instance.productId;
int num22 = ((__instance.productOutputCount > 0) ? ((FractionatorComponent)(ref __instance)).incLevel : 0);
if (cargoTraffic.TryInsertItemAtHead(reference3.beltId, productId2, b9, (byte)num22))
{
__instance.productOutputCount -= b9;
continue;
}
}
if (__instance.fluidId > 0 && __instance.fluidOutputCount > 0)
{
byte b10 = (byte)Math.Min(__instance.fluidOutputCount, 4);
int fluidId3 = __instance.fluidId;
int num23 = ((__instance.fluidOutputCount > 0) ? (__instance.fluidOutputInc / __instance.fluidOutputCount) : 0);
if (cargoTraffic.TryInsertItemAtHead(reference3.beltId, fluidId3, b10, (byte)num23))
{
__instance.fluidOutputCount -= b10;
__instance.fluidOutputInc -= num23 * b10;
}
}
}
}
}
}
public static class UISlotPickerPatches
{
private static int _currentMegaEntityId = 0;
private static int _currentMegaSlotId = -1;
private static List<int> _megaFilterItems = new List<int>();
public static int[] GetMegaProducts(PlanetFactory factory, int entityId)
{
if (factory == null || entityId <= 0)
{
return null;
}
ref EntityData reference = ref factory.entityPool[entityId];
if (reference.assemblerId > 0)
{
ref AssemblerComponent reference2 = ref factory.factorySystem.assemblerPool[reference.assemblerId];
if (reference2.speed >= MegaBuildingPatches.MegaAssemblerSpeed && reference2.recipeId > 0)
{
return reference2.recipeExecuteData?.products;
}
}
if (reference.labId > 0)
{
ref LabComponent reference3 = ref factory.factorySystem.labPool[reference.labId];
if (reference3.speed >= MegaBuildingPatches.MegaAssemblerSpeed && reference3.recipeId > 0)
{
return reference3.recipeExecuteData?.products;
}
}
if (reference.fractionatorId > 0)
{
ref FractionatorComponent reference4 = ref factory.factorySystem.fractionatorPool[reference.fractionatorId];
if (reference4.fluidInputMax <= 400 && reference4.productId > 0 && reference4.fluidId > 0)
{
return new int[2] { reference4.productId, reference4.fluidId };
}
}
return null;
}
public static bool IsMegaBuilding(PlanetFactory factory, int entityId)
{
if (factory == null || entityId <= 0)
{
return false;
}
ref EntityData reference = ref factory.entityPool[entityId];
if (reference.assemblerId > 0)
{
return MegaBuildingPatches.IsMegaAssembler(factory.factorySystem, reference.assemblerId);
}
if (reference.labId > 0)
{
return MegaBuildingPatches.IsMegaLab(factory.factorySystem, reference.labId);
}
if (reference.fractionatorId > 0)
{
return MegaBuildingPatches.IsMegaFractionator(factory.factorySystem, reference.fractionatorId);
}
return false;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UISlotPicker), "Determine")]
public static void UISlotPicker_Determine_Postfix(UISlotPicker __instance)
{
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Invalid comparison between Unknown and I4
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_0188: Unknown result type (might be due to invalid IL or missing references)
//IL_019c: 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_01a6: Unknown result type (might be due to invalid IL or missing references)
//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: 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_01ce: Unknown result type (might be due to invalid IL or missing references)
//IL_01d0: 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_01d7: Unknown result type (might be due to invalid IL or missing references)
//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0202: Unknown result type (might be due to invalid IL or missing references)
//IL_0207: Unknown result type (might be due to invalid IL or missing references)
//IL_021a: Unknown result type (might be due to invalid IL or missing references)
//IL_021f: Unknown result type (might be due to invalid IL or missing references)
//IL_0224: Unknown result type (might be due to invalid IL or missing references)
//IL_0228: Unknown result type (might be due to invalid IL or missing references)
//IL_022f: Unknown result type (might be due to invalid IL or missing references)
//IL_0245: Unknown result type (might be due to invalid IL or missing references)
//IL_024a: Unknown result type (might be due to invalid IL or missing references)
//IL_024c: Unknown result type (might be due to invalid IL or missing references)
//IL_025c: Unknown result type (might be due to invalid IL or missing references)
//IL_0261: Unknown result type (might be due to invalid IL or missing references)
//IL_0273: Unknown result type (might be due to invalid IL or missing references)
//IL_0355: Unknown result type (might be due to invalid IL or missing references)
//IL_0357: Unknown result type (might be due to invalid IL or missing references)
//IL_0367: Unknown result type (might be due to invalid IL or missing references)
//IL_037b: Unknown result type (might be due to invalid IL or missing references)
//IL_0380: Unknown result type (might be due to invalid IL or missing references)
//IL_0385: Unknown result type (might be due to invalid IL or missing references)
//IL_038a: Unknown result type (might be due to invalid IL or missing references)
//IL_038f: Unknown result type (might be due to invalid IL or missing references)
if (((ManualBehaviour)__instance).active)
{
return;
}
GameData data = GameMain.data;
if (data == null)
{
return;
}
PlanetData localPlanet = data.localPlanet;
if (localPlanet == null || localPlanet.factory == null)
{
return;
}
Player mainPlayer = data.mainPlayer;
PlayerController controller = mainPlayer.controller;
if (!VFInput.readyToBuild || mainPlayer.inhandItemId != 0 || ((int)controller.cmd.type == 5 && controller.cmd.mode != 0) || VFInput.shift)
{
return;
}
PlanetFactory factory = localPlanet.factory;
RaycastLogic raycastLogic = localPlanet.physics.raycastLogic;
if (raycastLogic.castAllCount <= 0)
{
return;
}
RaycastData val = raycastLogic.castAll[0];
if (val.rch.dist >= 60f || ((int)val.objType != 0 && (int)val.objType != 0))
{
return;
}
int objId = val.objId;
if (!IsMegaBuilding(factory, objId))
{
return;
}
ModelProto val2 = ((ProtoSet<ModelProto>)(object)LDB.models).Select((int)factory.entityPool[objId].modelIndex);
if (val2 == null)
{
return;
}
PrefabDesc prefabDesc = val2.prefabDesc;
if (prefabDesc.portPoses == null || prefabDesc.portPoses.Length == 0)
{
return;
}
Vector3 pos = factory.entityPool[objId].pos;
Quaternion rot = factory.entityPool[objId].rot;
Camera main = GameCamera.main;
int num = -1;
float num2 = 80f;
bool flag = default(bool);
int num3 = default(int);
int num4 = default(int);
RCHCPU val6 = default(RCHCPU);
for (int i = 0; i < prefabDesc.portPoses.Length; i++)
{
factory.ReadObjectConn(objId, i, ref flag, ref num3, ref num4);
if (!flag || num3 <= 0)
{
continue;
}
Vector3 val3 = pos + rot * (prefabDesc.portPoses[i].position + new Vector3(0f, 2.4f, 0f));
Vector3 val4 = rot * ((Pose)(ref prefabDesc.portPoses[i])).forward;
if (!(Vector3.Dot(val4, val.rch.normal) <= 0.5f) && !(Vector3.Angle(val4, Maths.HorzVector(((Component)main).transform.position - pos, ((Vector3)(ref pos)).normalized)) >= 40f))
{
Ray val5 = main.ScreenPointToRay(Input.mousePosition);
if (Phys.RayCastOBB(((Ray)(ref val5)).origin, ((Ray)(ref val5)).direction, num2, new Vector3(0.625f, 2.5f, 0.2f), val3, rot * prefabDesc.portPoses[i].rotation, ref val6))
{
num = i;
num2 = val6.dist;
}
}
}
if (num < 0)
{
return;
}
_currentMegaEntityId = objId;
_currentMegaSlotId = num;
int[] megaProducts = GetMegaProducts(factory, objId);
_megaFilterItems.Clear();
_megaFilterItems.Add(0);
if (megaProducts != null)
{
int[] array = megaProducts;
foreach (int num5 in array)
{
if (num5 > 0)
{
_megaFilterItems.Add(num5);
}
}
}
MegaSlotData[] slots = MegaBuildingPatches.GetSlots(factory.planetId, objId);
int num6 = 0;
if (num >= 0 && num < slots.Length)
{
num6 = slots[num].storageIdx;
}
__instance.outputEntityId = objId;
__instance.outputSlotId = num;
__instance.selectedIndex = ((num6 < _megaFilterItems.Count) ? num6 : 0);
__instance.position = pos + rot * (prefabDesc.portPoses[num].position + new Vector3(0f, 3f, 0f));
((ManualBehaviour)__instance)._Open();
}
[HarmonyPrefix]
[HarmonyPatch(typeof(UISlotPicker), "SetFilterToEntity")]
public static bool UISlotPicker_SetFilterToEntity_Prefix(UISlotPicker __instance)
{
if (__instance.outputEntityId <= 0 || __instance.outputSlotId < 0)
{
return true;
}
PlanetFactory val = GameMain.localPlanet?.factory;
if (val == null)
{
return true;
}
if (!IsMegaBuilding(val, __instance.outputEntityId))
{
return true;
}
MegaSlotData[] slots = MegaBuildingPatches.GetSlots(val.planetId, __instance.outputEntityId);
if (__instance.outputSlotId < slots.Length)
{
slots[__instance.outputSlotId].storageIdx = __instance.selectedIndex;
}
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(UISlotPicker), "SetOutputEntity")]
public static bool UISlotPicker_SetOutputEntity_Prefix(UISlotPicker __instance, int entityId, int slot)
{
if (entityId <= 0 || slot < 0)
{
return true;
}
PlanetFactory val = GameMain.localPlanet?.factory;
if (val == null)
{
return true;
}
if (!IsMegaBuilding(val, entityId))
{
return true;
}
return false;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(ItemProto), "GetPropValue")]
public static void ItemProto_GetPropValue_Postfix(ItemProto __instance, int index, StringBuilder sb, int incLevel, ref string __result)
{
if (index == 33)
{
PrefabDesc prefabDesc = __instance.prefabDesc;
if (prefabDesc != null && prefabDesc.labResearchSpeed >= 10f)
{
__result = (__instance.prefabDesc.labResearchSpeed * 60f * (float)GameMain.history.techSpeed).ToString("0.0###") + " Hash/s";
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(ProductionExtraInfoCalculator), "CalculateImmediately")]
public static void ProductionExtraInfoCalculator_CalculateImmediately_Postfix(ProductionExtraInfoCalculator __instance)
{
try
{
foreach (KeyValuePair<(int, int), MegaSprayPool> allSprayPool in MegaBuildingPatches.GetAllSprayPools())
{
(int, int) key = allSprayPool.Key;
MegaSprayPool value = allSprayPool.Value;
if (!value.HasProliferator || value.refConsumptionCalculated)
{
continue;
}
int item = key.Item1;
int item2 = key.Item2;
PlanetFactory val = GameMain.galaxy.astrosFactory[item];
if (val == null)
{
continue;
}
FactoryProductionStat val2 = GameMain.statistics.production.factoryStatPool[val.index];
if (val2 == null)
{
continue;
}
ItemProto val3 = ((ProtoSet<ItemProto>)(object)LDB.items).Select(value.incItemId);
if (val3 == null)
{
continue;
}
int hpMax = val3.HpMax;
if (hpMax <= 0)
{
continue;
}
int proliferatorIncLevel = MegaBuildingPatches.GetProliferatorIncLevel(value.incItemId);
int num = (int)((double)hpMax * ((double)Cargo.incTable[proliferatorIncLevel] * 0.001) + 0.1);
int num2 = hpMax + num;
int assemblerId = val.entityPool[item2].assemblerId;
if (assemblerId <= 0 || assemblerId >= val.factorySystem.assemblerCursor)
{
continue;
}
ref AssemblerComponent reference = ref val.factorySystem.assemblerPool[assemblerId];
int num3 = 10000 * Plugin.MegaBuildingSpeedMultiplier - 10000;
if (reference.speed < num3 || reference.recipeId <= 0)
{
continue;
}
RecipeProto val4 = ((ProtoSet<RecipeProto>)(object)LDB.recipes).Select(reference.recipeId);
if (val4 != null)
{
int num4 = 0;
for (int i = 0; i < val4.Items.Length; i++)
{
num4 += val4.ItemCounts[i];
}
float num5 = (float)reference.speed * 60f / 10000f;
float num6 = (float)num4 * num5 / (float)num2;
val2.AddRefConsumeSpeed(value.incItemId, num6);
value.refConsumptionCalculated = true;
value.refProlifConsumption = num6;
MegaBuildingPatches.UpdateSprayPool(item, item2, value);
}
}
MegaBuildingPatches.ResetRefConsumptionFlags();
}
catch (Exception arg)
{
ManualLogSource log = Plugin.Log;
if (log != null)
{
log.LogError((object)$"Error in CalculateImmediately Postfix: {arg}");
}
}
}
}
[HarmonyPatch(typeof(AssemblerComponent), "InternalUpdate")]
public static class AssemblerComponent_MegaInternalUpdate_Prefix
{
public static bool Prefix(ref AssemblerComponent __instance, float power, int[] productRegister, int[] consumeRegister, ref uint __result)
{
int num = 10000 * Plugin.MegaBuildingSpeedMultiplier - 10000;
if (__instance.speed < num)
{
return true;
}
__result = MegaInternalUpdate.AssemblerUpdate(ref __instance, power, productRegister, consumeRegister);
return false;
}
}
[HarmonyPatch(typeof(LabComponent), "InternalUpdateAssemble")]
public static class LabComponent_MegaInternalUpdate_Prefix
{
public static bool Prefix(ref LabComponent __instance, float power, int[] productRegister, int[] consumeRegister, ref uint __result)
{
int num = 10000 * Plugin.MegaBuildingSpeedMultiplier - 10000;
if (__instance.speed < num)
{
return true;
}
__result = MegaInternalUpdate.LabUpdateAssemble(ref __instance, power, productRegister, consumeRegister);
return false;
}
}
public static class MegaInternalUpdate
{
public static uint AssemblerUpdate(ref AssemblerComponent instance, float power, int[] productRegister, int[] consumeRegister)
{
if (power < 0.1f)
{
return 0u;
}
if (instance.recipeId <= 0 || instance.recipeExecuteData == null)
{
return 0u;
}
int timeSpend = instance.recipeExecuteData.timeSpend;
int extraTimeSpend = instance.recipeExecuteData.extraTimeSpend;
if (instance.extraTime >= extraTimeSpend)
{
int[] products = instance.recipeExecuteData.products;
int[] productCounts = instance.recipeExecuteData.productCounts;
int num = products.Length;
if (num == 1)
{
instance.produced[0] += productCounts[0];
lock (productRegister)
{
productRegister[products[0]] += productCounts[0];
}
}
else
{
for (int i = 0; i < num; i++)
{
instance.produced[i] += productCounts[i];
lock (productRegister)
{
productRegister[products[i]] += productCounts[i];
}
}
}
instance.extraCycleCount++;
instance.extraTime -= extraTimeSpend;
}
int num2 = 0;
int[] requireCounts = instance.recipeExecuteData.requireCounts;
int num3 = ((requireCounts != null) ? requireCounts.Length : 0);
while (instance.time >= timeSpend && num2 < 500)
{
bool flag = true;
for (int j = 0; j < num3; j++)
{
int num4 = requireCounts[j] * (num2 + 1);
if (instance.served[j] < num4 || instance.served[j] == 0)
{
flag = false;
break;
}
}
if (!flag)
{
break;
}
int[] products2 = instance.recipeExecuteData.products;
int[] productCounts2 = instance.recipeExecuteData.productCounts;
instance.replicating = false;
if (products2.Length == 1)
{
instance.produced[0] += productCounts2[0];
lock (productRegister)
{
productRegister[products2[0]] += productCounts2[0];
}
}
else
{
int num5 = products2.Length;
for (int k = 0; k < num5; k++)
{
instance.produced[k] += productCounts2[k];
lock (productRegister)
{
productRegister[products2[k]] += productCounts2[k];
}
}
}
instance.extraSpeed = 0;
instance.speedOverride = instance.speed;
instance.extraPowerRatio = 0;
num2++;
instance.time -= timeSpend;
}
instance.cycleCount += num2;
if (!instance.replicating)
{
int[] requires = instance.recipeExecuteData.requires;
int num6 = requireCounts.Length;
for (int l = 0; l < num6; l++)
{
if (instance.incServed[l] <= 0)
{
instance.incServed[l] = 0;
}
int num7 = requireCounts[l] * num2;
if (instance.served[l] < num7 || instance.served[l] == 0)
{
instance.time = 0;
return 0u;
}
}
int num8 = ((num6 > 0) ? 10 : 0);
for (int m = 0; m < num6; m++)
{
int num9 = requireCounts[m] * num2;
int num10 = SplitIncLevel(ref instance.served[m], ref instance.incServed[m], num9);
num8 = ((num8 < num10) ? num8 : num10);
if (!instance.incUsed)
{
instance.incUsed = num10 > 0;
}
if (instance.served[m] == 0)
{
instance.incServed[m] = 0;
}
lock (consumeRegister)
{
consumeRegister[requires[m]] += num9;
}
}
if (num8 < 0)
{
num8 = 0;
}
if (instance.recipeExecuteData.productive && !instance.forceAccMode)
{
instance.extraSpeed = (int)((double)instance.speed * Cargo.incTableMilli[num8] * 10.0 + 0.1);
instance.speedOverride = instance.speed;
instance.extraPowerRatio = Cargo.powerTable[num8];
}
else
{
instance.extraSpeed = 0;
instance.speedOverride = (int)((double)instance.speed * (1.0 + Cargo.accTableMilli[num8]) + 0.1);
instance.extraPowerRatio = Cargo.powerTable[num8];
}
instance.replicating = true;
}
if (instance.replicating && instance.time < timeSpend && instance.extraTime < extraTimeSpend)
{
instance.time += (int)(power * (float)instance.speedOverride);
instance.extraTime += (int)(power * (float)instance.extraSpeed);
}
if (!instance.replicating)
{
return 0u;
}
return 1u;
}
public static uint LabUpdateAssemble(ref LabComponent instance, float power, int[] productRegister, int[] consumeRegister)
{
if (power < 0.1f)
{
return 0u;
}
if (instance.recipeId <= 0 || instance.recipeExecuteData == null)
{
return 0u;
}
int[] products = instance.recipeExecuteData.products;
int extraTimeSpend = instance.recipeExecuteData.extraTimeSpend;
int timeSpend = instance.recipeExecuteData.timeSpend;
if (instance.extraTime >= extraTimeSpend)
{
int[] productCounts = instance.recipeExecuteData.productCounts;
int num = products.Length;
if (num == 1)
{
instance.produced[0] += productCounts[0];
lock (productRegister)
{
productRegister[products[0]] += productCounts[0];
}
}
else
{
for (int i = 0; i < num; i++)
{
instance.produced[i] += productCounts[i];
lock (productRegister)
{
productRegister[products[i]] += productCounts[i];
}
}
}
instance.extraTime -= extraTimeSpend;
instance.extraCycleCount++;
}
int num2 = 0;
int[] requireCounts = instance.recipeExecuteData.requireCounts;
int num3 = ((requireCounts != null) ? requireCounts.Length : 0);
while (instance.time >= timeSpend && num2 < 500)
{
bool flag = true;
for (int j = 0; j < num3; j++)
{
int num4 = requireCounts[j] * (num2 + 1);
if (instance.served[j] < num4 || instance.served[j] == 0)
{
flag = false;
break;
}
}
if (!flag)
{
break;
}
int[] productCounts2 = instance.recipeExecuteData.productCounts;
int num5 = products.Length;
instance.replicating = false;
if (num5 == 1)
{
instance.produced[0] += productCounts2[0];
lock (productRegister)
{
productRegister[products[0]] += productCounts2[0];
}
}
else
{
for (int k = 0; k < num5; k++)
{
instance.produced[k] += productCounts2[k];
lock (productRegister)
{
productRegister[products[k]] += productCounts2[k];
}
}
}
instance.extraSpeed = 0;
instance.speedOverride = instance.speed;
instance.extraPowerRatio = 0;
num2++;
instance.time -= timeSpend;
}
instance.cycleCount += num2;
if (!instance.replicating)
{
int[] requires = instance.recipeExecuteData.requires;
int num6 = requireCounts.Length;
for (int l = 0; l < num6; l++)
{
if (instance.incServed[l] <= 0)
{
instance.incServed[l] = 0;
}
int num7 = requireCounts[l] * num2;
if (instance.served[l] < num7 || instance.served[l] == 0)
{
instance.time = 0;
return 0u;
}
}
int num8 = ((num6 > 0) ? 10 : 0);
for (int m = 0; m < num6; m++)
{
int num9 = requireCounts[m] * num2;
int num10 = SplitIncLevel(ref instance.served[m], ref instance.incServed[m], num9);
num8 = ((num8 < num10) ? num8 : num10);
if (!instance.incUsed)
{
instance.incUsed = num10 > 0;
}
if (instance.served[m] == 0)
{
instance.incServed[m] = 0;
}
lock (consumeRegister)
{
consumeRegister[requires[m]] += num9;
}
}
if (num8 < 0)
{
num8 = 0;
}
if (instance.recipeExecuteData.productive && !instance.forceAccMode)
{
instance.extraSpeed = (int)((double)instance.speed * Cargo.incTableMilli[num8] * 10.0 + 0.1);
instance.speedOverride = instance.speed;
instance.extraPowerRatio = Cargo.powerTable[num8];
}
else
{
instance.extraSpeed = 0;
instance.speedOverride = (int)((double)instance.speed * (1.0 + Cargo.accTableMilli[num8]) + 0.1);
instance.extraPowerRatio = Cargo.powerTable[num8];
}
instance.replicating = true;
}
if (instance.replicating && instance.time < timeSpend && instance.extraTime < extraTimeSpend)
{
instance.time += (int)(power * (float)instance.speedOverride);
instance.extraTime += (int)(power * (float)instance.extraSpeed);
}
if (!instance.replicating)
{
return 0u;
}
return (uint)(products[0] - LabComponent.matrixIds[0] + 1);
}
private static int SplitIncLevel(ref int n, ref int m, int p)
{
int num = m / n;
int num2 = m - num * n;
n -= p;
num2 -= n;
m -= ((num2 > 0) ? (num * p + num2) : (num * p));
return num;
}
}
public static class ModelArrayExpandPatches
{
private const int ExpandedArraySize = 1024;
[HarmonyPatch(typeof(SpaceSector), "InitPrefabDescArray")]
[HarmonyPatch(typeof(PlanetFactory), "InitPrefabDescArray")]
[HarmonyPatch(typeof(ModelProtoSet), "OnAfterDeserialize")]
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> ModelProtoSet_OnAfterDeserialize_Transpiler(IEnumerable<CodeInstruction> instructions)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Expected O, but got Unknown
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Expected O, but got Unknown
CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
{
new CodeMatch((OpCode?)OpCodes.Newarr, (object)null, (string)null)
});
val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
{
new CodeInstruction(OpCodes.Pop, (object)null),
new CodeInstruction(OpCodes.Ldc_I4, (object)1024)
});
return val.InstructionEnumeration();
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> SkillSystem_Constructor_Transpiler(IEnumerable<CodeInstruction> instructions)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Expected O, but got Unknown
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Expected O, but got Unknown
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Expected O, but got Unknown
CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
{
new CodeMatch((OpCode?)OpCodes.Newarr, (object)null, (string)null)
});
do
{
val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
{
new CodeInstruction(OpCodes.Pop, (object)null),
new CodeInstruction(OpCodes.Ldc_I4, (object)1024)
});
val.Advance(1).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
{
new CodeMatch((OpCode?)OpCodes.Newarr, (object)null, (string)null)
});
}
while (val.IsValid);
return val.InstructionEnumeration();
}
[HarmonyPatch(typeof(ModelProto), "InitMaxModelIndex")]
[HarmonyPostfix]
public static void InitMaxModelIndex_Postfix()
{
ModelProto.maxModelIndex = ((ProtoSet<ModelProto>)(object)LDB.models).dataArray.Max((ModelProto model) => ((Proto)(model?)).ID).GetValueOrDefault();
}
}
[BepInPlugin("com.leo.dsp.MegaProduction", "MegaProduction", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[CommonAPISubmoduleDependency(new string[] { "ProtoRegistry", "TabSystem" })]
public class Plugin : BaseUnityPlugin
{
public static class RecipeUnlockPatches
{
[HarmonyPostfix]
[HarmonyPatch(typeof(GameHistoryData), "Import")]
public static void GameHistoryData_Import_Postfix(GameHistoryData __instance)
{
UnlockMegaRecipes(__instance);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(GameHistoryData), "SetForNewGame")]
public static void GameHistoryData_SetForNewGame_Postfix(GameHistoryData __instance)
{
UnlockMegaRecipes(__instance);
}
private static void UnlockMegaRecipes(GameHistoryData history)
{
int[] array = new int[7] { 650, 651, 652, 653, 654, 655, 656 };
foreach (int num in array)
{
if (!history.RecipeUnlocked(num))
{
history.UnlockRecipe(num);
}
}
}
}
public const string PluginGuid = "com.leo.dsp.MegaProduction";
public const string PluginName = "MegaProduction";
public const string PluginVersion = "1.0.0";
public static ManualLogSource Log;
private Harmony _harmony;
public static ConfigEntry<int> MaxProliferatorBufferConfig;
public static ConfigEntry<int> MegaBuildingSpeedMultiplierConfig;
public static ConfigEntry<int> MegaLabSpeedMultiplierConfig;
public static ConfigEntry<float> MegaLabResearchHashMultiplierConfig;
public static int MegaBuildingSpeedMultiplier = 30;
public static int MegaLabSpeedMultiplier = 80;
public static float MegaLabResearchHashMultiplier = 40f;
public static int MegaProductionTabId;
public const int MegaSmelterID = 9501;
public const int MegaAssemblerID = 9502;
public const int MegaChemicalPlantID = 9503;
public const int MegaLabID = 9504;
public const int MegaParticleColliderID = 9505;
public const int MegaOilRefineryID = 9506;
public const int MegaFractionatorID = 9507;
public const int MegaSmelterRecipeID = 650;
public const int MegaAssemblerRecipeID = 651;
public const int MegaChemicalPlantRecipeID = 652;
public const int MegaLabRecipeID = 653;
public const int MegaParticleColliderRecipeID = 654;
public const int MegaOilRefineryRecipeID = 655;
public const int MegaFractionatorRecipeID = 656;
public const int ArcSmelterID = 2302;
public const int AssemblerMk1ID = 2303;
public const int ChemicalPlantID = 2309;
public const int MatrixLabID = 2901;
public const int QuantumChipID = 1305;
public const int UnipolarMagnetID = 1016;
public const int TitaniumAlloyID = 1107;
public const int ParticleColliderID = 2310;
public const int OilRefineryID = 2308;
public const int FractionatorID = 2317;
public const int StrangeMatterID = 1208;
public const int GravitonLensID = 1204;
public const int PLSModelIndex = 49;
public const int MegaSmelterModelID = 460;
public const int MegaAssemblerModelID = 461;
public const int MegaChemicalPlantModelID = 462;
public const int MegaLabModelID = 463;
public const int MegaParticleColliderModelID = 464;
public const int MegaOilRefineryModelID = 465;
public const int MegaFractionatorModelID = 466;
private static ItemProto _megaSmelter;
private static ItemProto _megaAssembler;
private static ItemProto _megaChemicalPlant;
private static ItemProto _megaLab;
private static ItemProto _megaParticleCollider;
private static ItemProto _megaOilRefinery;
private static ItemProto _megaFractionator;
private static readonly FieldInfo _colliderPathField = typeof(ModelProto).GetField("_colliderPath", BindingFlags.Instance | BindingFlags.NonPublic);
public void Awake()
{
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Expected O, but got Unknown
//IL_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Expected O, but got Unknown
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
//IL_019e: Expected O, but got Unknown
//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
MegaBuildingSpeedMultiplierConfig = ((BaseUnityPlugin)this).Config.Bind<int>("General", "SpeedMultiplier", 80, "Speed multiplier for mega buildings compared to normal buildings (1-10000). Default is 80.");
MegaBuildingSpeedMultiplier = Mathf.Clamp(MegaBuildingSpeedMultiplierConfig.Value, 1, 10000);
MegaLabSpeedMultiplierConfig = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MegaLabSpeedMultiplier", 400, "Speed multiplier for Mega Lab crafting mode (1-10000). Default is 400.");
MegaLabSpeedMultiplier = Mathf.Clamp(MegaLabSpeedMultiplierConfig.Value, 1, 10000);
MegaLabResearchHashMultiplierConfig = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MegaLabResearchHashMultiplier", 200f, "Research hash rate multiplier for Mega Lab research mode. Default is 200.");
MegaLabResearchHashMultiplier = Mathf.Clamp(MegaLabResearchHashMultiplierConfig.Value, 1f, 10000f);
_harmony = new Harmony("com.leo.dsp.MegaProduction");
_harmony.PatchAll(typeof(ModelArrayExpandPatches));
_harmony.PatchAll(typeof(MegaBuildingPatches));
_harmony.PatchAll(typeof(UISlotPickerPatches));
MethodInfo methodInfo = AccessTools.Method(typeof(AssemblerComponent), "InternalUpdate", (Type[])null, (Type[])null);
MethodInfo methodInfo2 = AccessTools.Method(typeof(AssemblerComponent_MegaInternalUpdate_Prefix), "Prefix", (Type[])null, (Type[])null);
_harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
MethodInfo methodInfo3 = AccessTools.Method(typeof(LabComponent), "InternalUpdateAssemble", (Type[])null, (Type[])null);
MethodInfo methodInfo4 = AccessTools.Method(typeof(LabComponent_MegaInternalUpdate_Prefix), "Prefix", (Type[])null, (Type[])null);
_harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(methodInfo4), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
MegaProductionTabId = TabSystem.RegisterTab("com.leo.dsp.MegaProduction:MegaProductionTab", new TabData("MegaProduction", "Icons/Tech/1414"));
using (ProtoRegistry.StartModLoad("com.leo.dsp.MegaProduction"))
{
RegisterItems();
RegisterRecipes();
}
LDBTool.PreAddDataAction = (Action)Delegate.Combine(LDBTool.PreAddDataAction, new Action(OnPreAddData));
LDBTool.PostAddDataAction = (Action)Delegate.Combine(LDBTool.PostAddDataAction, new Action(OnPostAddData));
_harmony.PatchAll(typeof(RecipeUnlockPatches));
((BaseUnityPlugin)this).Logger.LogInfo((object)"MegaProduction 1.0.0 loaded.");
}
private void RegisterItems()
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: 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_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: 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_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: 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)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_0167: Unknown result type (might be due to invalid IL or missing references)
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
//IL_0191: 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_01bb: Unknown result type (might be due to invalid IL or missing references)
int num = MegaProductionTabId * 1000;
string text = "Icons/ItemRecipe/logistic-station";
Color val = Color.HSVToRGB(0f, 0.7f, 0.9f);
Color val2 = Color.HSVToRGB(0.33f, 0.7f, 0.9f);
Color val3 = Color.HSVToRGB(0.55f, 0.7f, 0.9f);
Color val4 = Color.HSVToRGB(0.75f, 0.7f, 0.9f);
Color val5 = Color.HSVToRGB(0.85f, 0.7f, 0.9f);
Color val6 = Color.HSVToRGB(0.45f, 0.7f, 0.9f);
Color val7 = Color.HSVToRGB(0.65f, 0.7f, 0.9f);
_megaSmelter = ProtoRegistry.RegisterItem(9501, "Mega Smelter", "A massive smelting facility with 10x the production capacity.", text, num + 101, 50, (EItemType)6, ProtoRegistry.GetDefaultIconDesc(val, val));
_megaAssembler = ProtoRegistry.RegisterItem(9502, "Mega Assembler", "A massive assembly facility with 10x the production capacity.", text, num + 102, 50, (EItemType)6, ProtoRegistry.GetDefaultIconDesc(val2, val2));
_megaChemicalPlant = ProtoRegistry.RegisterItem(9503, "Mega Chemical Plant", "A massive chemical processing facility with 10x the production capacity.", text, num + 103, 50, (EItemType)6, ProtoRegistry.GetDefaultIconDesc(val3, val3));
_megaLab = ProtoRegistry.RegisterItem(9504, "Mega Lab", "A massive research facility with 10x the production capacity.", text, num + 104, 50, (EItemType)6, ProtoRegistry.GetDefaultIconDesc(val4, val4));
_megaParticleCollider = ProtoRegistry.RegisterItem(9505, "Mega Particle Collider", "A massive particle collider with 10x the production capacity.", text, num + 105, 50, (EItemType)6, ProtoRegistry.GetDefaultIconDesc(val5, val5));
_megaOilRefinery = ProtoRegistry.RegisterItem(9506, "Mega Oil Refinery", "A massive oil refinery with 10x the production capacity.", text, num + 106, 50, (EItemType)6, ProtoRegistry.GetDefaultIconDesc(val6, val6));
_megaFractionator = ProtoRegistry.RegisterItem(9507, "Mega Fractionator", "A massive fractionator with 10x the production capacity.", text, num + 107, 50, (EItemType)6, ProtoRegistry.GetDefaultIconDesc(val7, val7));
}
private static void OnPreAddData()
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
CopyModelProto(49, 460, Color.HSVToRGB(0f, 0.7f, 0.9f));
CopyModelProto(49, 461, Color.HSVToRGB(0.33f, 0.7f, 0.9f));
CopyModelProto(49, 462, Color.HSVToRGB(0.55f, 0.7f, 0.9f));
CopyModelProto(49, 463, Color.HSVToRGB(0.75f, 0.7f, 0.9f));
CopyModelProto(49, 464, Color.HSVToRGB(0.85f, 0.7f, 0.9f));
CopyModelProto(49, 465, Color.HSVToRGB(0.45f, 0.7f, 0.9f));
CopyModelProto(49, 466, Color.HSVToRGB(0.65f, 0.7f, 0.9f));
}
private static void OnPostAddData()
{
((ProtoSet<ModelProto>)(object)LDB.models).OnAfterDeserialize();
ModifyModelPrefabDesc(460, (ERecipeType)1);
ModifyModelPrefabDesc(461, (ERecipeType)4);
ModifyModelPrefabDesc(462, (ERecipeType)2);
ModifyModelPrefabDesc(463, (ERecipeType)0, isLab: true);
ModifyModelPrefabDesc(464, (ERecipeType)5);
ModifyModelPrefabDesc(465, (ERecipeType)3);
((ProtoSet<ModelProto>)(object)LDB.models).Select(465);
ModifyModelPrefabDesc(466, (ERecipeType)8, isLab: false, isFractionator: true);
ModelProto.InitMaxModelIndex();
ModelProto.InitModelIndices();
ModelProto.InitModelOrders();
SetupMegaBuilding(_megaSmelter, 460);
SetupMegaBuilding(_megaAssembler, 461);
SetupMegaBuilding(_megaChemicalPlant, 462);
SetupMegaBuilding(_megaLab, 463);
SetupMegaBuilding(_megaParticleCollider, 464);
SetupMegaBuilding(_megaOilRefinery, 465);
SetupMegaBuilding(_megaFractionator, 466);
ItemProto megaSmelter = _megaSmelter;
if (megaSmelter != null)
{
megaSmelter.Preload(_megaSmelter.index);
}
ItemProto megaAssembler = _megaAssembler;
if (megaAssembler != null)
{
megaAssembler.Preload(_megaAssembler.index);
}
ItemProto megaChemicalPlant = _megaChemicalPlant;
if (megaChemicalPlant != null)
{
megaChemicalPlant.Preload(_megaChemicalPlant.index);
}
ItemProto megaLab = _megaLab;
if (megaLab != null)
{
megaLab.Preload(_megaLab.index);
}
ItemProto megaParticleCollider = _megaParticleCollider;
if (megaParticleCollider != null)
{
megaParticleCollider.Preload(_megaParticleCollider.index);
}
ItemProto megaOilRefinery = _megaOilRefinery;
if (megaOilRefinery != null)
{
megaOilRefinery.Preload(_megaOilRefinery.index);
}
ItemProto megaFractionator = _megaFractionator;
if (megaFractionator != null)
{
megaFractionator.Preload(_megaFractionator.index);
}
}
private static void SetupMegaBuilding(ItemProto newItem, int modelId)
{
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
if (newItem != null)
{
ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(2103);
newItem.ModelIndex = modelId;
newItem.ModelCount = 1;
newItem.IconPath = val?.IconPath ?? "Icons/ItemRecipe/logistic-station";
newItem.BuildMode = 1;
newItem.IsEntity = true;
newItem.CanBuild = true;
newItem.Type = (EItemType)6;
newItem.DescFields = new int[4] { 22, 11, 12, 1 };
newItem.Upgrades = new int[0];
}
}
private static void ModifyModelPrefabDesc(int modelId, ERecipeType recipeType, bool isLab = false, bool isFractionator = false)
{
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
ModelProto val = ((ProtoSet<ModelProto>)(object)LDB.models).Select(modelId);
if (val?.prefabDesc != null)
{
PrefabDesc prefabDesc = val.prefabDesc;
prefabDesc.isStation = false;
prefabDesc.isStellarStation = false;
prefabDesc.isCollectStation = false;
prefabDesc.stationMaxItemCount = 0;
prefabDesc.stationMaxItemKinds = 0;
prefabDesc.stationMaxDroneCount = 0;
prefabDesc.stationMaxShipCount = 0;
prefabDesc.stationMaxEnergyAcc = 0L;
prefabDesc.isAssembler = false;
prefabDesc.isLab = false;
prefabDesc.isFractionator = false;
int assemblerSpeed = 10000 * MegaBuildingSpeedMultiplier;
if (isLab)
{
prefabDesc.isLab = true;
prefabDesc.isAssembler = false;
prefabDesc.isPowerConsumer = true;
int labAssembleSpeed = 10000 * MegaLabSpeedMultiplier;
prefabDesc.labAssembleSpeed = labAssembleSpeed;
prefabDesc.labResearchSpeed = MegaLabSpeedMultiplier;
prefabDesc.workEnergyPerTick = 8333333L;
prefabDesc.idleEnergyPerTick = 333333L;
}
else if (isFractionator)
{
prefabDesc.isFractionator = true;
prefabDesc.isAssembler = false;
prefabDesc.isLab = false;
prefabDesc.assemblerRecipeType = recipeType;
prefabDesc.fracFluidInputMax = 360;
prefabDesc.fracProductOutputMax = 360;
prefabDesc.fracFluidOutputMax = 360;
prefabDesc.workEnergyPerTick = 8333333L;
prefabDesc.idleEnergyPerTick = 333333L;
}
else
{
prefabDesc.isAssembler = true;
prefabDesc.isLab = false;
prefabDesc.assemblerRecipeType = recipeType;
prefabDesc.assemblerSpeed = assemblerSpeed;
prefabDesc.workEnergyPerTick = 8333333L;
prefabDesc.idleEnergyPerTick = 333333L;
}
}
}
private static void CopyModelProto(int oriId, int newId, Color color)
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: 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_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: 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_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: 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_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Expected O, but got Unknown
//IL_0196: Unknown result type (might be due to invalid IL or missing references)
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
//IL_0236: Unknown result type (might be due to invalid IL or missing references)
//IL_023b: Unknown result type (might be due to invalid IL or missing references)
//IL_026e: Unknown result type (might be due to invalid IL or missing references)
//IL_0273: Unknown result type (might be due to invalid IL or missing references)
//IL_027c: Unknown result type (might be due to invalid IL or missing references)
//IL_0281: 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_01e3: Expected O, but got Unknown
//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
ModelProto val = ((ProtoSet<ModelProto>)(object)LDB.models).Select(oriId);
if (val == null)
{
ManualLogSource log = Log;
if (log != null)
{
log.LogError((object)$"Could not find original model {oriId}");
}
return;
}
string text = _colliderPathField?.GetValue(val) as string;
ModelProto val2 = new ModelProto
{
ObjectType = val.ObjectType,
RuinType = val.RuinType,
RendererType = val.RendererType,
HpMax = val.HpMax,
HpUpgrade = val.HpUpgrade,
HpRecover = val.HpRecover,
RuinId = val.RuinId,
RuinCount = val.RuinCount,
RuinLifeTime = val.RuinLifeTime,
PrefabPath = val.PrefabPath
};
((Proto)val2).Name = newId.ToString();
((Proto)val2).ID = newId;
_colliderPathField?.SetValue(val2, text);
PrefabDesc prefabDesc = val.prefabDesc;
GameObject val3 = (Object.op_Implicit((Object)(object)prefabDesc.prefab) ? prefabDesc.prefab : Resources.Load<GameObject>(val.PrefabPath));
GameObject val4 = (Object.op_Implicit((Object)(object)prefabDesc.colliderPrefab) ? prefabDesc.colliderPrefab : Resources.Load<GameObject>(text));
if ((Object)(object)val3 != (Object)null)
{
PowerDesc componentInChildren = val3.GetComponentInChildren<PowerDesc>(true);
if ((Object)(object)componentInChildren != (Object)null)
{
componentInChildren.workEnergyPerTick = 8333333L;
componentInChildren.idleEnergyPerTick = 333333L;
}
}
ref PrefabDesc prefabDesc2 = ref val2.prefabDesc;
prefabDesc2 = (PrefabDesc)(((Object)(object)val3 == (Object)null) ? ((object)PrefabDesc.none) : ((object)((!((Object)(object)val4 == (Object)null)) ? new PrefabDesc(newId, val3, val4) : new PrefabDesc(newId, val3))));
Material[][] lodMaterials = prefabDesc2.lodMaterials;
foreach (Material[] array in lodMaterials)
{
if (array == null)
{
continue;
}
for (int j = 0; j < array.Length; j++)
{
ref Material reference = ref array[j];
if (!((Object)(object)reference == (Object)null))
{
reference = new Material(reference);
reference.SetColor("_Color", color);
}
}
}
prefabDesc2.modelIndex = newId;
prefabDesc2.hasBuildCollider = prefabDesc.hasBuildCollider;
prefabDesc2.colliders = prefabDesc.colliders;
prefabDesc2.buildCollider = prefabDesc.buildCollider;
prefabDesc2.buildColliders = prefabDesc.buildColliders;
prefabDesc2.colliderPrefab = prefabDesc.colliderPrefab;
prefabDesc2.dragBuild = prefabDesc.dragBuild;
prefabDesc2.dragBuildDist = prefabDesc.dragBuildDist;
prefabDesc2.blueprintBoxSize = prefabDesc.blueprintBoxSize;
prefabDesc2.roughHeight = prefabDesc.roughHeight;
prefabDesc2.roughWidth = prefabDesc.roughWidth;
prefabDesc2.roughRadius = prefabDesc.roughRadius;
prefabDesc2.barHeight = prefabDesc.barHeight;
prefabDesc2.barWidth = prefabDesc.barWidth;
prefabDesc2.workEnergyPerTick = prefabDesc.workEnergyPerTick;
prefabDesc2.idleEnergyPerTick = prefabDesc.idleEnergyPerTick;
((Proto)val2).sid = "";
((Proto)val2).SID = "";
LDBTool.PreAddProto((Proto)(object)val2);
}
private void RegisterRecipes()
{
int num = MegaProductionTabId * 1000;
ProtoRegistry.RegisterRecipe(650, (ERecipeType)4, 600, new int[4] { 2302, 1305, 1016, 1107 }, new int[4] { 10, 20, 20, 10 }, new int[1] { 9501 }, new int[1] { 1 }, "Recipe for Mega Smelter", 0, num + 101);
ProtoRegistry.RegisterRecipe(651, (ERecipeType)4, 600, new int[4] { 2303, 1305, 1016, 1107 }, new int[4] { 10, 20, 20, 10 }, new int[1] { 9502 }, new int[1] { 1 }, "Recipe for Mega Assembler", 0, num + 102);
ProtoRegistry.RegisterRecipe(652, (ERecipeType)4, 600, new int[4] { 2309, 1305, 1016, 1107 }, new int[4] { 10, 20, 20, 10 }, new int[1] { 9503 }, new int[1] { 1 }, "Recipe for Mega Chemical Plant", 0, num + 103);
ProtoRegistry.RegisterRecipe(653, (ERecipeType)4, 600, new int[4] { 2901, 1305, 1016, 1107 }, new int[4] { 10, 20, 20, 10 }, new int[1] { 9504 }, new int[1] { 1 }, "Recipe for Mega Lab", 0, num + 104);
ProtoRegistry.RegisterRecipe(654, (ERecipeType)4, 600, new int[4] { 2310, 1305, 1208, 1204 }, new int[4] { 10, 20, 20, 10 }, new int[1] { 9505 }, new int[1] { 1 }, "Recipe for Mega Particle Collider", 0, num + 105);
ProtoRegistry.RegisterRecipe(655, (ERecipeType)4, 600, new int[4] { 2308, 1305, 1016, 1107 }, new int[4] { 10, 20, 20, 10 }, new int[1] { 9506 }, new int[1] { 1 }, "Recipe for Mega Oil Refinery", 0, num + 106);
ProtoRegistry.RegisterRecipe(656, (ERecipeType)4, 600, new int[4] { 2317, 1305, 1016, 1107 }, new int[4] { 10, 20, 20, 10 }, new int[1] { 9507 }, new int[1] { 1 }, "Recipe for Mega Fractionator", 0, num + 107);
}
public void OnDestroy()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
}
}