Decompiled source of FactoryOverclock v2.0.2

com.Valoneu.FactoryOverclock.dll

Decompiled 5 days ago
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CommonAPI;
using CommonAPI.Systems;
using FactoryMultiplier.Util;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.Valoneu.FactoryOverclock")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("FactoryOverclock")]
[assembly: AssemblyFileVersion("2.0.2.0")]
[assembly: AssemblyInformationalVersion("2.0.2+26b568c5a523a49d861f16e19f1dee1d4c3fd119")]
[assembly: AssemblyProduct("com.Valoneu.FactoryOverclock")]
[assembly: AssemblyTitle("com.Valoneu.FactoryOverclock")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.2.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 FactoryMultiplier
{
	public static class AssemblerPatcher
	{
		private static ConcurrentDictionary<int, RecipeProto> _recipeProtosById = new ConcurrentDictionary<int, RecipeProto>();

		[HarmonyPrefix]
		[HarmonyPatch(typeof(FactorySystem), "GameTick", new Type[]
		{
			typeof(long),
			typeof(bool)
		})]
		private static void FactorySystem_GameTick_Prefix(FactorySystem __instance)
		{
			MultiplyAssemblers(__instance);
			MultiplyFractionators(__instance);
		}

		private static void MultiplyAssemblers(FactorySystem factorySystem)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 1; i < factorySystem.assemblerCursor; i++)
			{
				int entityId = factorySystem.assemblerPool[i].entityId;
				if (entityId > 0)
				{
					ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)factorySystem.factory.entityPool[entityId].protoId);
					int multiplierByRecipe = PluginConfig.GetMultiplierByRecipe(ItemUtil.GetRecipeByProtoId(((Proto)val).ID));
					factorySystem.assemblerPool[i].speed = multiplierByRecipe * val.prefabDesc.assemblerSpeed;
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(CargoTraffic), "NewBeltComponent")]
		public static void NewBelt_Prefix(ref int speed)
		{
			speed *= PluginConfig.beltMultiplier;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(CargoTraffic), "UpgradeBeltComponent")]
		public static void UpgradeBelt_Prefix(ref int speed)
		{
			speed *= PluginConfig.beltMultiplier;
		}

		private static void MultiplyFractionators(FactorySystem factorySystem)
		{
			for (int i = 1; i < factorySystem.fractionatorCursor; i++)
			{
				if (factorySystem.fractionatorPool[i].id == i)
				{
					factorySystem.fractionatorPool[i].produceProb = (float)PluginConfig.fractionatorMultiplier * 0.01f;
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(LabComponent), "InternalUpdateAssemble")]
		private static void MultiplyLab(ref LabComponent __instance)
		{
			if (__instance.recipeId <= 0)
			{
				return;
			}
			if (!_recipeProtosById.TryGetValue(__instance.recipeId, out var value))
			{
				RecipeProto val = ((ProtoSet<RecipeProto>)(object)LDB.recipes).Select(__instance.recipeId);
				if (((Proto)val).ID <= 0)
				{
					return;
				}
				RecipeProto val3 = (_recipeProtosById[__instance.recipeId] = val);
				value = val3;
			}
			__instance.timeSpend = value.TimeSpend * 10000 / PluginConfig.labMultiplier;
			__instance.extraTimeSpend = value.TimeSpend * 100000 / PluginConfig.labMultiplier;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(EjectorComponent), "InternalUpdate")]
		public static void EjectorComponent_InternalUpdate_Prefix(ref EjectorComponent __instance)
		{
			ItemProto ejectorProto = ItemUtil.ejectorProto;
			__instance.chargeSpend = ejectorProto.prefabDesc.ejectorChargeFrame * 10000 / PluginConfig.ejectorMultiplier;
			__instance.coldSpend = ejectorProto.prefabDesc.ejectorColdFrame * 10000 / PluginConfig.ejectorMultiplier;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SiloComponent), "InternalUpdate")]
		public static void SiloComponent_InternalUpdate_Prefix(ref SiloComponent __instance)
		{
			__instance.chargeSpend = ItemUtil.GetSiloProto().prefabDesc.siloChargeFrame * 10000 / PluginConfig.siloMultiplier;
			__instance.coldSpend = ItemUtil.GetSiloProto().prefabDesc.siloColdFrame * 10000 / PluginConfig.siloMultiplier;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(InserterComponent), "InternalUpdate")]
		public static void InserterComponent_InternalUpdate_Prefix(ref InserterComponent __instance, PlanetFactory factory)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.id != 0 && __instance.entityId != 0)
			{
				EntityData val = factory.entityPool[__instance.entityId];
				ItemProto val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)val.protoId);
				if (val2.prefabDesc != null)
				{
					__instance.speed = 10000 * PluginConfig.inserterMultiplier;
					__instance.delay = val2.prefabDesc.inserterDelay / PluginConfig.inserterMultiplier;
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(InserterComponent), "InternalUpdateNoAnim")]
		public static void InserterComponent_InternalUpdateNoAnim_Prefix(ref InserterComponent __instance, PlanetFactory factory)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.id != 0 && __instance.entityId != 0)
			{
				EntityData val = factory.entityPool[__instance.entityId];
				ItemProto val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)val.protoId);
				if (val2.prefabDesc != null)
				{
					__instance.speed = 10000 * PluginConfig.inserterMultiplier;
					__instance.delay = val2.prefabDesc.inserterDelay / PluginConfig.inserterMultiplier;
				}
			}
		}
	}
	public static class FactoryUI
	{
		public static void CreateUI()
		{
		}

		public static void DestroyUI()
		{
		}
	}
	[BepInPlugin("com.Valoneu.FactoryOverclock", "FactoryOverclock", "2.0.0")]
	[BepInProcess("DSPGAME.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[CommonAPISubmoduleDependency(new string[] { "ProtoRegistry", "CustomKeyBindSystem" })]
	public class MultiplierPlugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		public static int BattlefieldAnalysisBaseProtoId = 3009;

		private void Awake()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			PluginConfig.InitConfig(((BaseUnityPlugin)this).Config);
			InitKeyBinds();
			Log.logger = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("com.Valoneu.FactoryOverclock");
			_harmony.PatchAll(typeof(PowerConsumptionPatcher));
			_harmony.PatchAll(typeof(PowerGenerationPatcher));
			_harmony.PatchAll(typeof(MultiplierPlugin));
			_harmony.PatchAll(typeof(AssemblerPatcher));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin: com.Valoneu.FactoryOverclock 2.0.0 is loaded!");
		}

		private void Update()
		{
			bool flag = PluginConfig.keyTestMode.Value && VFInput.alt && Input.GetKeyDown("1");
			if (CustomKeyBindSystem.GetKeyBind("ToggleOverclock").keyValue || flag)
			{
				PluginConfig.multiplierEnabled.Value = !PluginConfig.multiplierEnabled.Value;
				if (!PluginConfig.multiplierEnabled.Value)
				{
					Log.logger.LogWarning((object)"reverting multipliers");
					UIRealtimeTip.Popup("Reverting factory to normal", true, 0);
				}
				else
				{
					Log.logger.LogWarning((object)"applying multipliers");
					UIRealtimeTip.Popup("Applying multipliers to factory", true, 0);
				}
				RefreshAllBeltsInGame();
			}
		}

		private void RefreshAllBeltsInGame()
		{
			if (GameMain.data?.factories == null)
			{
				return;
			}
			Log.Info("Refreshing all belts in game...");
			PlanetFactory[] factories = GameMain.data.factories;
			foreach (PlanetFactory val in factories)
			{
				if (val?.cargoTraffic != null)
				{
					RefreshBeltsForFactory(val);
				}
			}
		}

		private void RefreshBeltsForFactory(PlanetFactory factory)
		{
			CargoTraffic cargoTraffic = factory.cargoTraffic;
			for (int i = 1; i < cargoTraffic.pathCursor; i++)
			{
				CargoPath val = cargoTraffic.pathPool[i];
				if (val != null && val.id == i && val.belts.Count > 0)
				{
					int num = val.belts[0];
					ItemProto val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)factory.entityPool[cargoTraffic.beltPool[num].entityId].protoId);
					for (int j = 0; j < val.chunkCount; j++)
					{
						int beltSpeed = val2.prefabDesc.beltSpeed;
						val.chunks[j * 3 + 2] = beltSpeed * PluginConfig.beltMultiplier;
					}
				}
			}
		}

		private void InitKeyBinds()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			if (!CustomKeyBindSystem.HasKeyBind("ToggleOverclock"))
			{
				BuiltinKey val = default(BuiltinKey);
				val.id = 214;
				val.key = new CombineKey(304, (byte)4, (ECombineKeyAction)0, false);
				val.conflictGroup = 2052;
				val.name = "ToggleOverclock";
				val.canOverride = true;
				CustomKeyBindSystem.RegisterKeyBind<PressKeyBind>(val);
			}
			ProtoRegistry.RegisterString("KEYToggleOverClock", "Enable/disable factory OverClock");
		}

		internal void OnDestroy()
		{
			_harmony.UnpatchSelf();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameMain), "Begin")]
		private static void GameBegin_Postfix()
		{
			((MultiplierPlugin)(object)Object.FindObjectOfType(typeof(MultiplierPlugin)))?.RefreshAllBeltsInGame();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.Valoneu.FactoryOverclock";

		public const string PLUGIN_NAME = "FactoryOverclock";

		public const string PLUGIN_VERSION = "2.0.0";
	}
	public static class PowerConsumptionPatcher
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(PowerSystem), "GameTick", new Type[]
		{
			typeof(long),
			typeof(bool),
			typeof(bool),
			typeof(int)
		})]
		private static void PowerSystem_GameTick_Prefix(PowerSystem __instance)
		{
			try
			{
				MultiplyPowerConsumption(__instance);
			}
			catch (Exception ex)
			{
				Log.logger.LogWarning((object)("Multiply power failed. " + ex.Message + " " + ex.StackTrace));
			}
			try
			{
				MultiplyReceivers(__instance);
			}
			catch (Exception ex2)
			{
				Log.logger.LogWarning((object)("Multiply gamma exception " + ex2.Message + " " + ex2.StackTrace));
			}
		}

		private static void MultiplyPowerConsumption(PowerSystem powerSystem)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Invalid comparison between Unknown and I4
			//IL_009b: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: 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)
			for (int i = 1; i < powerSystem.consumerCursor; i++)
			{
				PowerConsumerComponent val = powerSystem.consumerPool[i];
				int entityId = val.entityId;
				if (entityId <= 0)
				{
					continue;
				}
				ItemProto val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)powerSystem.factory.entityPool[entityId].protoId);
				if ((int)val2.Type != 5 && val2 != null && !val2.prefabDesc.isStation && !val2.prefabDesc.isPowerExchanger && ((Proto)val2).ID != 3009)
				{
					int num = -1;
					if (val2.prefabDesc.isAssembler)
					{
						num = PluginConfig.GetMultiplierByRecipe(ItemUtil.GetRecipeByProtoId(((Proto)val2).ID));
					}
					else if (val2.prefabDesc.isLab)
					{
						EntityData val3 = powerSystem.factory.entityPool[val.entityId];
						num = (powerSystem.factory.factorySystem.labPool[val3.labId].researchMode ? 1 : PluginConfig.labMultiplier);
					}
					else
					{
						num = PluginConfig.GetMultiplierFromPrefabDesc(val2.prefabDesc);
					}
					long workEnergyPerTick = val2.prefabDesc.workEnergyPerTick;
					powerSystem.consumerPool[i].workEnergyPerTick = (int)(PluginConfig.drawMultiplier.Value * (double)num * (double)workEnergyPerTick);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StationComponent), "SetPCState")]
		public static void StationComponent_SetPCState_Postfix(ref StationComponent __instance, PowerConsumerComponent[] pcPool)
		{
			__instance.energyPerTick = pcPool[__instance.pcId].requiredEnergy * PluginConfig.genExchMultiplier;
			pcPool[__instance.pcId].requiredEnergy = __instance.energyPerTick;
		}

		public static void MultiplyReceivers(PowerSystem powerSystem)
		{
			for (int i = 1; i < powerSystem.genCursor; i++)
			{
				int entityId = powerSystem.genPool[i].entityId;
				int protoId = powerSystem.factory.entityPool[entityId].protoId;
				ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(protoId);
				if (powerSystem.genPool[i].id == i && powerSystem.genPool[i].gamma)
				{
					powerSystem.genPool[i].genEnergyPerTick = PluginConfig.gammaMultiplier.Value * val.prefabDesc.genEnergyPerTick;
				}
			}
		}
	}
	public static class PowerGenerationPatcher
	{
		private enum FuelConsumerType
		{
			None,
			Chemical,
			Nuclear,
			Antimatter,
			Storage
		}

		private static ConcurrentDictionary<int, ConcurrentDictionary<int, FuelConsumerType>> _planetIdToEntityIdToConsumerType = new ConcurrentDictionary<int, ConcurrentDictionary<int, FuelConsumerType>>();

		private static bool _loggedNoneConsumerOnce;

		private static FuelConsumerType GetFuelConsumerType(PowerGeneratorComponent powerGenerator)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			short fuelMask = powerGenerator.fuelMask;
			if ((fuelMask & 1) == 1)
			{
				return FuelConsumerType.Chemical;
			}
			if ((fuelMask & 2) == 2)
			{
				return FuelConsumerType.Nuclear;
			}
			if ((fuelMask & 4) == 4)
			{
				return FuelConsumerType.Antimatter;
			}
			if ((fuelMask & 8) == 8)
			{
				return FuelConsumerType.Storage;
			}
			return FuelConsumerType.None;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PowerSystem), "GameTick", new Type[]
		{
			typeof(long),
			typeof(bool),
			typeof(bool),
			typeof(int)
		})]
		private static void PowerSystem_GameTick_Prefix_GenPool(PowerSystem __instance)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 1; i < __instance.genCursor; i++)
			{
				ref PowerGeneratorComponent reference = ref __instance.genPool[i];
				EntityData val = __instance.factory.entityPool[reference.entityId];
				ItemProto val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)val.protoId);
				if (reference.photovoltaic)
				{
					reference.genEnergyPerTick = val2.prefabDesc.genEnergyPerTick * PluginConfig.genSolarMultiplier;
				}
				if (reference.wind)
				{
					reference.genEnergyPerTick = val2.prefabDesc.genEnergyPerTick * PluginConfig.genWindMultiplier;
				}
				if (reference.geothermal)
				{
					reference.genEnergyPerTick = val2.prefabDesc.genEnergyPerTick * PluginConfig.genGeoMultiplier;
				}
				if (IsFuelConsumer(reference) && reference.fuelId > 0)
				{
					if (!_planetIdToEntityIdToConsumerType.TryGetValue(__instance.factory.planetId, out var value))
					{
						value = (_planetIdToEntityIdToConsumerType[__instance.factory.planetId] = new ConcurrentDictionary<int, FuelConsumerType>());
					}
					if (!value.TryGetValue(reference.entityId, out var value2))
					{
						value2 = (value[reference.entityId] = GetFuelConsumerType(reference));
					}
					switch (value2)
					{
					case FuelConsumerType.None:
						Log.LogOnce("Invalid fuel consumer type for generator {0}", ref _loggedNoneConsumerOnce, reference);
						break;
					case FuelConsumerType.Chemical:
						reference.genEnergyPerTick = val2.prefabDesc.genEnergyPerTick * PluginConfig.genThermalMultiplier;
						reference.useFuelPerTick = val2.prefabDesc.useFuelPerTick * PluginConfig.genThermalMultiplier;
						break;
					case FuelConsumerType.Nuclear:
						reference.genEnergyPerTick = val2.prefabDesc.genEnergyPerTick * PluginConfig.genFusionMultiplier;
						reference.useFuelPerTick = val2.prefabDesc.useFuelPerTick * PluginConfig.genFusionMultiplier;
						break;
					case FuelConsumerType.Antimatter:
						reference.genEnergyPerTick = val2.prefabDesc.genEnergyPerTick * PluginConfig.genStarMultiplier;
						reference.useFuelPerTick = val2.prefabDesc.useFuelPerTick * PluginConfig.genStarMultiplier;
						break;
					case FuelConsumerType.Storage:
						reference.genEnergyPerTick = val2.prefabDesc.genEnergyPerTick * PluginConfig.genExchMultiplier;
						break;
					default:
						Log.Warn("how did this even happen? " + JsonUtility.ToJson((object)reference));
						break;
					}
				}
			}
		}

		private static bool IsFuelConsumer(PowerGeneratorComponent generatorComponent)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			int[] array = ItemProto.fuelNeeds[generatorComponent.fuelMask];
			if (array == null)
			{
				return false;
			}
			return array.Length != 0;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.Valoneu.FactoryOverclock";

		public const string PLUGIN_NAME = "com.Valoneu.FactoryOverclock";

		public const string PLUGIN_VERSION = "2.0.2";
	}
}
namespace FactoryMultiplier.Util
{
	public static class ItemUtil
	{
		private static readonly ConcurrentDictionary<int, ERecipeType> recipeByProtoId = new ConcurrentDictionary<int, ERecipeType>();

		private static ConcurrentDictionary<int, byte> rayPhotonReceiverProtos;

		private static ItemProto _ejectorProto;

		private static ItemProto _siloProto;

		public static ItemProto ejectorProto
		{
			get
			{
				if (_ejectorProto == null)
				{
					_ejectorProto = ((ProtoSet<ItemProto>)(object)LDB.items).dataArray.ToList().Find((ItemProto i) => i.prefabDesc.isEjector);
				}
				return _ejectorProto;
			}
		}

		public static ERecipeType GetRecipeByProtoId(int protoId)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (recipeByProtoId.ContainsKey(protoId))
			{
				return recipeByProtoId[protoId];
			}
			Log.logger.LogDebug((object)$"looking up recipe by protoid {protoId}");
			ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(protoId);
			recipeByProtoId[((Proto)val).ID] = val.prefabDesc.assemblerRecipeType;
			return recipeByProtoId[((Proto)val).ID];
		}

		public static bool IsPhotonRayReceiver(int protoId)
		{
			if (rayPhotonReceiverProtos == null)
			{
				rayPhotonReceiverProtos = new ConcurrentDictionary<int, byte>();
				((ProtoSet<ItemProto>)(object)LDB.items).dataArray.ToList().FindAll((ItemProto i) => i.prefabDesc.gammaRayReceiver).ForEach(delegate(ItemProto i)
				{
					rayPhotonReceiverProtos[((Proto)i).ID] = 0;
				});
			}
			return rayPhotonReceiverProtos.ContainsKey(protoId);
		}

		public static ItemProto GetSiloProto()
		{
			if (_siloProto == null)
			{
				_siloProto = ((ProtoSet<ItemProto>)(object)LDB.items).dataArray.ToList().Find((ItemProto i) => i.prefabDesc.isSilo);
			}
			return _siloProto;
		}
	}
	public static class Log
	{
		public static ManualLogSource logger;

		public static void Debug(string message)
		{
			logger.LogDebug((object)$"[{DateTime.Now:HH:mm:ss.fff}] {message}");
		}

		public static void Info(string message)
		{
			logger.LogInfo((object)$"[{DateTime.Now:HH:mm:ss.fff}] {message}");
		}

		public static void Warn(string message)
		{
			logger.LogWarning((object)$"[{DateTime.Now:HH:mm:ss.fff}] {message}");
		}

		public static void LogOnce(string msg, ref bool flag, params object[] args)
		{
			if (!flag)
			{
				flag = true;
				string[] array = ((args == null) ? Array.Empty<string>() : (from arg in args.ToList()
					select (!(arg is int)) ? JsonUtility.ToJson(arg) : arg.ToString()).ToArray());
				object[] args2 = array;
				Info(string.Format(msg, args2));
			}
		}
	}
	public static class PluginConfig
	{
		public static ConfigEntry<int> smeltMultiplier;

		public static ConfigEntry<int> chemicalMultiplier;

		public static ConfigEntry<int> refineMultiplier;

		public static ConfigEntry<int> assembleMultiplier;

		public static ConfigEntry<int> particleMultiplier;

		private static ConfigEntry<int> _labMultiplier;

		private static ConfigEntry<int> _fractionatorMultiplier;

		private static ConfigEntry<int> _ejectorMultiplier;

		private static ConfigEntry<int> _siloMultiplier;

		public static ConfigEntry<int> gammaMultiplier;

		private static ConfigEntry<int> _inserterMultiplier;

		private static ConfigEntry<int> _beltMultiplier;

		public static ConfigEntry<double> drawMultiplier;

		private static ConfigEntry<int> _genWindMultiplier;

		private static ConfigEntry<int> _genSolarMultiplier;

		private static ConfigEntry<int> _genGeoMultiplier;

		private static ConfigEntry<int> _genThermalMultiplier;

		private static ConfigEntry<int> _genFusionMultiplier;

		private static ConfigEntry<int> _genStarMultiplier;

		private static ConfigEntry<int> _genExchMultiplier;

		public static ConfigEntry<bool> keyTestMode;

		public static ConfigEntry<bool> multiplierEnabled;

		public static ConfigEntry<bool> enableAssemblerPopupLogMessage;

		public static int genWindMultiplier
		{
			get
			{
				if (!multiplierEnabled.Value)
				{
					return 1;
				}
				return _genWindMultiplier.Value;
			}
		}

		public static int genSolarMultiplier
		{
			get
			{
				if (!multiplierEnabled.Value)
				{
					return 1;
				}
				return _genSolarMultiplier.Value;
			}
		}

		public static int genGeoMultiplier
		{
			get
			{
				if (!multiplierEnabled.Value)
				{
					return 1;
				}
				return _genGeoMultiplier.Value;
			}
		}

		public static int genThermalMultiplier
		{
			get
			{
				if (!multiplierEnabled.Value)
				{
					return 1;
				}
				return _genThermalMultiplier.Value;
			}
		}

		public static int genFusionMultiplier
		{
			get
			{
				if (!multiplierEnabled.Value)
				{
					return 1;
				}
				return _genFusionMultiplier.Value;
			}
		}

		public static int genStarMultiplier
		{
			get
			{
				if (!multiplierEnabled.Value)
				{
					return 1;
				}
				return _genStarMultiplier.Value;
			}
		}

		public static int genExchMultiplier
		{
			get
			{
				if (!multiplierEnabled.Value)
				{
					return 1;
				}
				return _genExchMultiplier.Value;
			}
		}

		public static int siloMultiplier
		{
			get
			{
				if (!multiplierEnabled.Value)
				{
					return 1;
				}
				return _siloMultiplier.Value;
			}
		}

		public static int inserterMultiplier
		{
			get
			{
				if (!multiplierEnabled.Value)
				{
					return 1;
				}
				return _inserterMultiplier.Value;
			}
		}

		public static int beltMultiplier
		{
			get
			{
				if (!multiplierEnabled.Value)
				{
					return 1;
				}
				return _beltMultiplier.Value;
			}
		}

		public static int ejectorMultiplier
		{
			get
			{
				if (!multiplierEnabled.Value)
				{
					return 1;
				}
				return _ejectorMultiplier.Value;
			}
		}

		public static int fractionatorMultiplier
		{
			get
			{
				if (!multiplierEnabled.Value)
				{
					return 1;
				}
				return _fractionatorMultiplier.Value;
			}
		}

		public static int labMultiplier
		{
			get
			{
				if (!multiplierEnabled.Value)
				{
					return 1;
				}
				return _labMultiplier.Value;
			}
		}

		public static void InitConfig(ConfigFile confFile)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Expected O, but got Unknown
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Expected O, but got Unknown
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Expected O, but got Unknown
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Expected O, but got Unknown
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Expected O, but got Unknown
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Expected O, but got Unknown
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Expected O, but got Unknown
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Expected O, but got Unknown
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Expected O, but got Unknown
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Expected O, but got Unknown
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Expected O, but got Unknown
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Expected O, but got Unknown
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Expected O, but got Unknown
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Expected O, but got Unknown
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Expected O, but got Unknown
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a6: Expected O, but got Unknown
			smeltMultiplier = confFile.Bind<int>("1. Factory", "smeltMultiplier", 1, new ConfigDescription("Multiplies speed of smelters", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 20), Array.Empty<object>()));
			chemicalMultiplier = confFile.Bind<int>("1. Factory", "chemicalMultiplier", 1, new ConfigDescription("Multiplies speed of chemical plants", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 20), Array.Empty<object>()));
			refineMultiplier = confFile.Bind<int>("1. Factory", "refineMultiplier", 1, new ConfigDescription("Multiplies speed of refineries", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 20), Array.Empty<object>()));
			assembleMultiplier = confFile.Bind<int>("1. Factory", "assembleMultiplier", 1, new ConfigDescription("Multiplies speed of assemblers", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 20), Array.Empty<object>()));
			particleMultiplier = confFile.Bind<int>("1. Factory", "particleMultiplier", 1, new ConfigDescription("Multiplies speed of particle colliders", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 20), Array.Empty<object>()));
			_labMultiplier = confFile.Bind<int>("1. Factory", "labMultiplier", 1, new ConfigDescription("Multiplies speed of laboratories", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 20), Array.Empty<object>()));
			_fractionatorMultiplier = confFile.Bind<int>("1. Factory", "fractionateMultiplier", 1, new ConfigDescription("Multiplies % of fractionators", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 20), Array.Empty<object>()));
			_ejectorMultiplier = confFile.Bind<int>("1. Factory", "ejectorMultiplier", 1, new ConfigDescription("Multiplies speed of EM rail ejectors", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			_siloMultiplier = confFile.Bind<int>("1. Factory", "siloMultiplier", 1, new ConfigDescription("Multiplies speed of silos", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			gammaMultiplier = confFile.Bind<int>("1. Factory", "gammaMultiplier", 1, new ConfigDescription("Multiplies speed of ray recievers", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 1000), Array.Empty<object>()));
			_inserterMultiplier = confFile.Bind<int>("1. Factory", "sorterMultiplier", 1, new ConfigDescription("Multiplies speed of sorter", (AcceptableValueBase)(object)new AcceptableValueList<int>(new int[4] { 1, 2, 4, 8 }), Array.Empty<object>()));
			_beltMultiplier = confFile.Bind<int>("1. Factory", "beltMultiplier", 1, new ConfigDescription("Multiplies speed of belts (max 2x)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 2), Array.Empty<object>()));
			drawMultiplier = confFile.Bind<double>("1. Factory", "drawMultipler", 1.0, new ConfigDescription("Multiplies how much your factory will draw on top of your normal overclock", (AcceptableValueBase)(object)new AcceptableValueRange<double>(0.1, 10.0), Array.Empty<object>()));
			_genWindMultiplier = confFile.Bind<int>("2. Generator", "generatorWindMultiplier", 1, new ConfigDescription("Multiplies speed of wind turbines", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			_genSolarMultiplier = confFile.Bind<int>("2. Generator", "generatorSolarMultiplier", 1, new ConfigDescription("Multiplies speed of solar panels", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			_genGeoMultiplier = confFile.Bind<int>("2. Generator", "generatorGeothermalMultiplier", 1, new ConfigDescription("Multiplies speed of geothermal plants", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			_genThermalMultiplier = confFile.Bind<int>("2. Generator", "generatorThermalMultiplier", 1, new ConfigDescription("Multiplies speed of thermal plants", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			_genFusionMultiplier = confFile.Bind<int>("2. Generator", "generatorFusionMultiplier", 1, new ConfigDescription("Multiplies speed of fusion power plants", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			_genStarMultiplier = confFile.Bind<int>("2. Generator", "generatorArtificialStarMultiplier", 1, new ConfigDescription("Multiplies speed of artificial stars", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			_genExchMultiplier = confFile.Bind<int>("2. Generator", "generatorExchangerMultiplier", 1, new ConfigDescription("Multiplies speed of energy exchangers", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			keyTestMode = confFile.Bind<bool>("3. Advanced", "keyTestMode", false, "Uses alt+1 as keybind for scriptengine support");
			multiplierEnabled = confFile.Bind<bool>("3. Advanced", "multiplierEnabled", true, "Determine whether we are currently multiplying values");
			enableAssemblerPopupLogMessage = confFile.Bind<bool>("3. Advanced", "enableAssemblerPopupLogMessage", false, "Ignore - For debugging, log message when UI window is opened");
		}

		public static int GetMultiplierFromPrefabDesc(PrefabDesc desc, int defaultToUse = 1)
		{
			if (!multiplierEnabled.Value)
			{
				return 1;
			}
			if (desc.isSilo)
			{
				return siloMultiplier;
			}
			if (desc.isFractionator)
			{
				return fractionatorMultiplier;
			}
			if (desc.isEjector)
			{
				return ejectorMultiplier;
			}
			if (desc.isLab)
			{
				return labMultiplier;
			}
			return defaultToUse;
		}

		public static int GetMultiplierByRecipe(ERecipeType eRecipeType)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected I4, but got Unknown
			if (!multiplierEnabled.Value)
			{
				return 1;
			}
			return (eRecipeType - 1) switch
			{
				3 => assembleMultiplier.Value, 
				1 => chemicalMultiplier.Value, 
				5 => 1, 
				7 => fractionatorMultiplier, 
				4 => particleMultiplier.Value, 
				2 => refineMultiplier.Value, 
				14 => labMultiplier, 
				0 => smeltMultiplier.Value, 
				6 => gammaMultiplier.Value, 
				_ => 1, 
			};
		}
	}
}