using System;
using System.Collections.Generic;
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 System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Eirshy.DSP.ReBuffer.AnyBeat;
using Eirshy.DSP.ReBuffer.NoRythhmn;
using Eirshy.DSP.Rythmn;
using HarmonyLib;
using Microsoft.CodeAnalysis;
[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("ReBuffer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ReBuffer")]
[assembly: AssemblyTitle("ReBuffer")]
[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 Eirshy.DSP.ReBuffer
{
internal static class Config
{
private const string HDR = "ReBuffer";
private const string HDR_BUGGY = "ReBuffer.Triage";
private const string HDR_IN = "ReBuffer.RecipeInputs";
private const string HDR_OUT = "ReBuffer.RecipeOutputs";
private const string HDR_RES = "ReBuffer.Research";
private const string HDR_RAYR = "ReBuffer.RayReciever";
private const string HDR_RYTHMN = "ReBuffer.Rythmn.Addons";
private const string REQ_ASM = "Requires Assemblers to be patched.";
private const string REQ_LAB = "Requires Labs to be patched.";
private const string REQ_RAYR = "Requires Power Generators to be patched (weirdly enough).";
private const string REQ_RYTHMN = "Experimental Settings (currently disabled)";
internal static int[] lookup_inp;
internal static int[] lookup_oup;
internal static int JelloAppetite { get; private set; }
internal static bool CollapseLabTowers { get; private set; }
internal static int RayrCataIn { get; private set; }
internal static int RayrProdOut { get; private set; }
internal static bool RayrPiling { get; private set; }
internal static bool RayrCataPass { get; private set; }
public static void Load(ConfigFile cf)
{
_LoadComponentEnabled(cf);
_LoadByRecipe(cf);
_LoadAdvancedLabSettings(cf);
}
private static void _LoadComponentEnabled(ConfigFile cf)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Expected O, but got Unknown
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Expected O, but got Unknown
ReBuffer.Enabled |= (EEnabledComponents)(cf.Bind<bool>("ReBuffer.Triage", "PatchAssemblerComponent", true, new ConfigDescription("This setting is to enable you to triage new-update and compatibility issues with this mod.\nIf true, we'll patch AssemblerComponents (includes Smelters, Refineries, ChemPlants, and more).\nOverwrites: UpdateNeeds, InternalUpdate", (AcceptableValueBase)null, Array.Empty<object>())).Value ? 1 : 0);
ReBuffer.Enabled |= (EEnabledComponents)(cf.Bind<bool>("ReBuffer.Triage", "PatchLabComponent", true, new ConfigDescription("This setting is to enable you to triage new-update and compatibility issues with this mod.\nIf true, we'll patch LabComponents (both Jello and Research modes).\nOverwrites: UpdateOutputToNext, UpdateNeedsAssemble, InternalUpdateAssemble, UpdateNeedsResearch, InternalUpdateResearch", (AcceptableValueBase)null, Array.Empty<object>())).Value ? 2 : 0);
ReBuffer.Enabled |= (EEnabledComponents)(cf.Bind<bool>("ReBuffer.Triage", "PatchPowerGenerators", true, new ConfigDescription("This setting is to enable you to triage new-update and compatibility issues with this mod.\nIf true, we'll patch PowerGenerators (includes all gennies and rayrs).\nOverwrites: GameTick_Gamma\nCurrently Incompatible with JinxOAO's MoreMegastructures (rip)", (AcceptableValueBase)null, Array.Empty<object>())).Value ? 8 : 0);
}
private static void _LoadByRecipe(ConfigFile cf)
{
//IL_00e0: 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)
//IL_00e9: Invalid comparison between Unknown and I4
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Expected I4, but got Unknown
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_014d: Expected O, but got Unknown
//IL_0158: Unknown result type (might be due to invalid IL or missing references)
//IL_0164: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Expected I4, but got Unknown
//IL_019d: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Expected O, but got Unknown
ERecipeType[] source = (ERecipeType[])Enum.GetValues(typeof(ERecipeType));
List<ERecipeType> list = source.Where((ERecipeType type) => (int)type != 0 && (int)type != 8 && (int)type != 7).ToList();
lookup_inp = new int[source.Select((ERecipeType rt) => (int)rt).Max() + 1];
lookup_oup = new int[lookup_inp.Length];
for (int i = 0; i < lookup_inp.Length; i++)
{
if (!Enum.IsDefined(typeof(ERecipeType), i))
{
lookup_inp[i] = -1;
lookup_oup[i] = -1;
}
else
{
lookup_inp[i] = 4;
lookup_oup[i] = 5;
}
}
foreach (ERecipeType item in list)
{
string text = (((int)item == 15) ? "Requires Labs to be patched." : "Requires Assemblers to be patched.");
lookup_inp[item] = cf.Bind<int>("ReBuffer.RecipeInputs", $"In{item}", 4, new ConfigDescription(text + $"\nThe multiplier for the input buffers for {item} ({(int)item}) recipes.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 500), Array.Empty<object>())).Value;
lookup_oup[item] = cf.Bind<int>("ReBuffer.RecipeOutputs", $"Out{item}", 5, new ConfigDescription(text + $"\nThe multiplier for the output buffers for {item} ({(int)item}) recipes.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 500), Array.Empty<object>())).Value;
}
}
private static void _LoadAdvancedLabSettings(ConfigFile cf)
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Expected O, but got Unknown
JelloAppetite = cf.Bind<int>("ReBuffer.Research", "JelloAppetite", 10, new ConfigDescription("Requires Labs to be patched.\nThe multiplier for the input buffers for hash-producing (research-mode) labs.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(2, 500), Array.Empty<object>())).Value;
CollapseLabTowers = cf.Bind<bool>("ReBuffer.Rythmn.Addons", "CollapseLabTowers", false, new ConfigDescription("Experimental Settings (currently disabled) Requires Labs to be patched.\nIf true, we'll collapse all of your Lab Towers into just the bottom floor, allowing all other labs to basically act as a flashy, overly tall hat.\nThis doesn't entirely remove them from the entity count, but it does make their tick operations notably cheaper.", (AcceptableValueBase)null, Array.Empty<object>())).Value;
}
private static void _LoadRayRecieverSettings(ConfigFile cf)
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Expected O, but got Unknown
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Expected O, but got Unknown
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Expected O, but got Unknown
RayrCataIn = cf.Bind<int>("ReBuffer.RayReciever", "Catalyst", 20, new ConfigDescription("Requires Power Generators to be patched (weirdly enough).\nThe number of catalysts (ie, Grav Lenses) a rayr should hoard in itself. Note that catalysts last for 1 minute (assuming 60 ticks per second).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 500), Array.Empty<object>())).Value;
RayrProdOut = cf.Bind<int>("ReBuffer.RayReciever", "Product", 20, new ConfigDescription("Requires Power Generators to be patched (weirdly enough).\nThe number of products (ie, Crit Photons) a rayr should keep ahold of.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 500), Array.Empty<object>())).Value;
RayrPiling = cf.Bind<bool>("ReBuffer.RayReciever", "ProductPiling", false, new ConfigDescription("Requires Power Generators to be patched (weirdly enough).\nIf set, we'll automatically pile products if we can, up to the max of 4.", (AcceptableValueBase)null, Array.Empty<object>())).Value;
RayrCataPass = cf.Bind<bool>("ReBuffer.RayReciever", "CataPassthrough", false, new ConfigDescription("Requires Power Generators to be patched (weirdly enough).\nIf set, AND a ray reciever has AT LEAST 2 + the piled (if piled) quantity, AND there's no product whatsoever, we'll pass extra catalysts through.\nThis feature is only ever usable if you like to use lenses on rayr power generators.", (AcceptableValueBase)null, Array.Empty<object>())).Value;
}
internal static int GetInp(ERecipeType @for)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
return lookup_inp[@for];
}
internal static int GetOup(ERecipeType @for)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
return lookup_oup[@for];
}
}
[Flags]
public enum EEnabledComponents
{
_NONE = 0,
_ALL = -1,
AssemblerComponent = 1,
LabComponent = 2,
LabDancers = 0,
PowerGenerators = 8
}
[BepInPlugin("eirshy.dsp.ReBuffer", "ReBuffer", "0.2.5")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class ReBuffer : BaseUnityPlugin
{
public const string MODID = "ReBuffer";
public const string ROOT = "eirshy.dsp.";
public const string GUID = "eirshy.dsp.ReBuffer";
public const string VERSION = "0.2.5";
public const string NAME = "ReBuffer";
private const string RYTHMN_GUID = "eirshy.dsp.Rythmn";
private static readonly Lazy<Harmony> _harmony = new Lazy<Harmony>((Func<Harmony>)(() => new Harmony("eirshy.dsp.ReBuffer")));
internal static Harmony Harmony => _harmony.Value;
internal static ManualLogSource Logs { get; private set; }
public static EEnabledComponents Enabled { get; internal set; } = EEnabledComponents._NONE;
public static int ComponentsEnabled => (int)Enabled;
private void Awake()
{
Logs = ((BaseUnityPlugin)this).Logger;
((BaseUnityPlugin)this).Logger.LogMessage((object)"ReBuffer Active");
Config.Load(((BaseUnityPlugin)this).Config);
HookAnyBeat();
if (Chainloader.PluginInfos.ContainsKey("eirshy.dsp.Rythmn"))
{
HookWithRythmn();
}
else
{
HookNoRythmn();
}
}
public static bool IsEnabled(EEnabledComponents component)
{
return (Enabled & component) == component;
}
public static bool IsComponentEnabled(int component)
{
return (ComponentsEnabled & component) == component;
}
private void HookAnyBeat()
{
if (IsEnabled(EEnabledComponents.AssemblerComponent))
{
AssemblerComponentPatcher.ApplyMe();
}
}
private void HookNoRythmn()
{
if (IsEnabled(EEnabledComponents.LabComponent))
{
LabComponentPatcher.ApplyMe();
}
}
private void HookWithRythmn()
{
Logs.LogMessage((object)"Taking advantage of having Rythmn!");
if (IsEnabled(EEnabledComponents.LabComponent))
{
LabComponentPatcher.ApplyMe();
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "ReBuffer";
public const string PLUGIN_NAME = "ReBuffer";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace Eirshy.DSP.ReBuffer.WithRythmn
{
internal static class LabComponentDancer
{
private const int LOCKED = -1;
private const int JELLO_CALORIES = 3600;
private const int JELLO_FLAVORS = 6;
private static int InpMult;
private static int OupMult;
private static int JelloPlateSize;
private const int DIMMA_TYPE = 0;
private const int DIMMA_TYPE_UNKNOWN = 0;
private const int DIMMA_TYPE_HAT = 1;
private const int DIMMA_TYPE_DOUG = 2;
private const int DIMMA_LAST = 1;
private const int DIMMA_WORNBY = 2;
private const int DIMMA_SPEED = 3;
private const int DIMMA_LOCK = 4;
public static void ApplyMe()
{
InpMult = Config.GetInp((ERecipeType)15);
OupMult = Config.GetOup((ERecipeType)15);
JelloPlateSize = 3600 * Config.JelloAppetite;
RythmnKit.AddLoad_PostVisitor((Action<GameData>)MoveToTheDimmsdaleSector);
RythmnKit.AddSaveClean_Visitor((Action<EntityRef>)SaveClean);
RythmnKit.AddSaveRestore_Visitor((Action<EntityRef>)SaveRestore);
ReBuffer.Harmony.PatchAll(typeof(LabComponentDancer));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int MIN2(int i, int j)
{
if (i >= j)
{
return j;
}
return i;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static long MIN2(long i, long j)
{
if (i >= j)
{
return j;
}
return i;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static long MIN3(long i, long j, long k)
{
if (i >= j)
{
if (j >= k)
{
return k;
}
return j;
}
if (i >= k)
{
return k;
}
return i;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool HAS_NO_TASK(in LabComponent lab)
{
if (!lab.researchMode)
{
return lab.recipeId == 0;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static ref int[] DimmaDome(ref LabComponent lab)
{
if (lab.researchMode)
{
return ref lab.requireCounts;
}
return ref lab.matrixServed;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static ref int[] DimmaDome(ref LabComponent lab, bool isRes)
{
if (isRes)
{
return ref lab.requireCounts;
}
return ref lab.matrixServed;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int[] DimmaForceDome(ref LabComponent lab, bool isRes)
{
ref int[] reference = ref DimmaDome(ref lab, isRes);
if (reference == null)
{
reference = new int[5];
}
return reference;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool DimmaIsDoug(ref LabComponent lab)
{
int[] array = DimmaDome(ref lab, lab.researchMode);
if (array != null)
{
return array[0] == 2;
}
return true;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool DimmaIsHat(ref LabComponent lab)
{
int[] array = DimmaDome(ref lab, lab.researchMode);
if (array != null)
{
return array[0] == 1;
}
return true;
}
private static bool DimmaIsDoug(int[] dome)
{
return dome[0] == 2;
}
private static bool DimmaIsHat(int[] dome)
{
return dome[0] == 1;
}
private static bool DimmaIsUnknown(int[] dome)
{
return dome[0] == 0;
}
private static ref int DimmaRefType(int[] dome)
{
return ref dome[0];
}
private static int DimmaSetType(int[] dome, int type)
{
return dome[0] = type;
}
private static uint DimmaGetLast(int[] dome)
{
return (uint)dome[1];
}
private static void DimmaSyncLast(int[] dome, int[] doug)
{
dome[1] = doug[1];
}
private static void DimmaSetLast(int[] dome, uint last)
{
dome[1] = (int)last;
}
private static ref int DimmaRefWornBy(int[] dome)
{
return ref dome[2];
}
private static void DimmaSetWornBy(int[] dome, in LabComponent by)
{
dome[2] = by.id;
}
private static ref int DimmaRefSpeedPrc(int[] dome)
{
return ref dome[3];
}
private static void DimmaClearSpeedPrc(int[] dome)
{
dome[3] = 0;
}
private static ref int DimmaRefLock(int[] dome)
{
return ref dome[4];
}
private static void DimmaUnlock(int[] dome)
{
dome[4] = 0;
}
private static int DimmaGetRelSpeed(in LabComponent hat, in LabComponent wearer, bool isRes)
{
if (wearer.speed != 0 && hat.speed != 0)
{
return (int)Math.Ceiling((float)hat.speed * 100f / (float)wearer.speed);
}
return 100;
}
private static void MoveToTheDimmsdaleSector(GameData gdat)
{
RythmnKit.LogProvider.LogStanza(typeof(LabComponentDancer), "Collapsing Labs");
gdat.factories.AsParallel().ForAll(delegate(PlanetFactory factory)
{
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
if (factory != null)
{
List<EntityRef> list = (from er in EntityRef.GetEntityRefs(factory)
where ((EntityRef)(ref er)).HasActive_LabComponent
select er).ToList();
if (list.Count >= 2)
{
foreach (EntityRef item in list)
{
EntityRef current = item;
ref LabComponent live_LabComponent = ref ((EntityRef)(ref current)).GetLive_LabComponent();
if (!HAS_NO_TASK(in live_LabComponent))
{
bool researchMode = live_LabComponent.researchMode;
int[] dome = DimmaForceDome(ref live_LabComponent, researchMode);
if (!DimmaIsHat(dome))
{
DimmaSetType(dome, 2);
int nextLabId = live_LabComponent.nextLabId;
while (nextLabId > 0)
{
ref LabComponent live_LabComponent2 = ref EntityRef.GetLive_LabComponent(((EntityRef)(ref current)).Factory, nextLabId);
int[] dome2 = DimmaForceDome(ref live_LabComponent2, researchMode);
if (!DimmaIsHat(dome2))
{
DimmaSetType(dome2, 1);
for (int i = 0; i < live_LabComponent2.needs.Length; i++)
{
live_LabComponent2.needs[i] = 0;
}
if (researchMode)
{
for (int j = 0; j < 6; j++)
{
live_LabComponent.matrixServed[j] += live_LabComponent2.matrixServed[j];
live_LabComponent.matrixIncServed[j] += live_LabComponent2.matrixIncServed[j];
live_LabComponent.matrixPoints[j] += live_LabComponent2.matrixPoints[j];
live_LabComponent2.matrixServed[j] = 0;
live_LabComponent2.matrixIncServed[j] = 0;
live_LabComponent2.matrixPoints[j] = 0;
}
live_LabComponent.hashBytes += live_LabComponent2.hashBytes;
live_LabComponent2.hashBytes = 0;
live_LabComponent.extraHashBytes += live_LabComponent2.extraHashBytes;
live_LabComponent2.extraHashBytes = 0;
}
else if (!HAS_NO_TASK(in live_LabComponent2))
{
for (int k = 0; k < live_LabComponent2.served.Length; k++)
{
live_LabComponent.served[k] += live_LabComponent2.served[k];
live_LabComponent.incServed[k] += live_LabComponent2.incServed[k];
live_LabComponent2.served[k] = 0;
live_LabComponent2.incServed[k] = 0;
}
live_LabComponent.produced[0] += live_LabComponent2.produced[0];
live_LabComponent2.produced[0] = 0;
live_LabComponent.time += live_LabComponent2.time;
live_LabComponent2.time = 0;
live_LabComponent.extraTime += live_LabComponent2.extraTime;
live_LabComponent2.extraTime = 0;
}
}
DimmaSetWornBy(dome2, in live_LabComponent);
nextLabId = live_LabComponent2.nextLabId;
}
}
}
}
foreach (EntityRef item2 in list)
{
EntityRef current2 = item2;
ref LabComponent live_LabComponent3 = ref ((EntityRef)(ref current2)).GetLive_LabComponent();
int[] array = DimmaDome(ref live_LabComponent3);
if (array != null && DimmaIsHat(array))
{
live_LabComponent3.replicating = EntityRef.GetLive_LabComponent(((EntityRef)(ref current2)).Factory, DimmaRefWornBy(array)).replicating;
}
}
}
}
});
}
[HarmonyPrefix]
[HarmonyPatch(typeof(LabComponent), "UpdateOutputToNext")]
private static void UpdateOutputToNext(LabComponent[] labPool, ref LabComponent __instance, ref bool __runOriginal)
{
if (!__runOriginal)
{
return;
}
__runOriginal = false;
bool researchMode = __instance.researchMode;
if (HAS_NO_TASK(in __instance))
{
return;
}
int[] array = DimmaDome(ref __instance, researchMode);
if (array == null)
{
return;
}
switch (DimmaRefType(array))
{
case 0:
break;
case 1:
if (__instance.nextLabId != 0 && Interlocked.Exchange(ref DimmaRefLock(array), -1) != -1)
{
ref LabComponent reference2 = ref labPool[DimmaRefWornBy(array)];
int[] array2 = DimmaDome(ref reference2, researchMode);
bool flag3 = false;
while (!DimmaIsDoug(array2))
{
reference2 = ref labPool[DimmaRefWornBy(array2)];
array2 = DimmaDome(ref reference2, researchMode);
flag3 = true;
}
if (flag3)
{
DimmaSetWornBy(array, in reference2);
}
DimmaSyncLast(array, array2);
__instance.replicating = reference2.replicating;
__instance.extraPowerRatio = reference2.extraPowerRatio;
int num2 = DimmaRefSpeedPrc(array);
Interlocked.Add(ref DimmaRefSpeedPrc(array2), DimmaGetRelSpeed(in __instance, in reference2, researchMode) + num2);
DimmaClearSpeedPrc(array);
}
break;
case 2:
{
ref int location = ref DimmaRefSpeedPrc(array);
int nextLabId = __instance.nextLabId;
while (nextLabId > 0)
{
ref LabComponent reference = ref labPool[nextLabId];
int[] dome = DimmaForceDome(ref reference, researchMode);
bool flag = DimmaIsHat(dome);
bool flag2 = reference.nextLabId == 0 && flag;
if (!flag || flag2)
{
Interlocked.Exchange(ref DimmaRefLock(dome), -1);
DimmaSetType(dome, 1);
DimmaSyncLast(dome, array);
DimmaSetWornBy(dome, in __instance);
int num = DimmaRefSpeedPrc(dome);
reference.replicating = __instance.replicating;
reference.extraPowerRatio = __instance.extraPowerRatio;
Interlocked.Add(ref location, DimmaGetRelSpeed(in reference, in __instance, researchMode) + num);
DimmaClearSpeedPrc(dome);
}
nextLabId = reference.nextLabId;
}
break;
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(LabComponent), "UpdateNeedsAssemble")]
private static void UpdateNeedsAssemble(ref LabComponent __instance, ref bool __runOriginal)
{
if (!__runOriginal)
{
return;
}
__runOriginal = false;
if (DimmaIsDoug(ref __instance))
{
switch (__instance.served.Length)
{
default:
return;
case 6:
UpdateNeedsAssemble_inline(ref __instance, 5);
goto case 5;
case 5:
UpdateNeedsAssemble_inline(ref __instance, 4);
goto case 4;
case 4:
UpdateNeedsAssemble_inline(ref __instance, 3);
goto case 3;
case 3:
UpdateNeedsAssemble_inline(ref __instance, 2);
goto case 2;
case 2:
UpdateNeedsAssemble_inline(ref __instance, 1);
break;
case 1:
break;
}
UpdateNeedsAssemble_inline(ref __instance, 0);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void UpdateNeedsAssemble_inline(ref LabComponent __instance, int i)
{
__instance.needs[i] = ((__instance.served[i] < __instance.requireCounts[i] * InpMult) ? __instance.requires[i] : 0);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(LabComponent), "InternalUpdateAssemble", new Type[]
{
typeof(float),
typeof(int[]),
typeof(int[])
})]
private static void InternalUpdateAssemble(float power, int[] productRegister, int[] consumeRegister, ref LabComponent __instance, ref bool __runOriginal, ref uint __result)
{
if (!__runOriginal)
{
return;
}
__runOriginal = false;
int[] dome = DimmaForceDome(ref __instance, isRes: false);
switch (DimmaRefType(dome))
{
case 1:
DimmaUnlock(dome);
__result = DimmaGetLast(dome);
return;
case 0:
DimmaSetType(dome, 2);
break;
}
if (power < 0.1f)
{
DimmaSetLast(dome, __result = 0u);
return;
}
float num = 1f + (float)DimmaRefSpeedPrc(dome) / 100f;
DimmaClearSpeedPrc(dome);
if (__instance.time >= __instance.timeSpend)
{
int num2 = __instance.products.Length;
__instance.replicating = false;
switch (num2)
{
case 6:
if (!InternalUpdate_inlineIsOutFull(ref __instance, 5))
{
goto case 5;
}
goto case -1;
case 5:
if (!InternalUpdate_inlineIsOutFull(ref __instance, 4))
{
goto case 4;
}
goto case -1;
case 4:
if (!InternalUpdate_inlineIsOutFull(ref __instance, 3))
{
goto case 3;
}
goto case -1;
case 3:
if (!InternalUpdate_inlineIsOutFull(ref __instance, 2))
{
goto case 2;
}
goto case -1;
case 2:
if (!InternalUpdate_inlineIsOutFull(ref __instance, 1))
{
goto case 1;
}
goto case -1;
case 1:
if (!InternalUpdate_inlineIsOutFull(ref __instance, 0))
{
break;
}
goto case -1;
case -1:
DimmaSetLast(dome, __result = 0u);
return;
}
switch (num2)
{
case 6:
InternalUpdate_inlineAddProd(ref __instance, 5, productRegister);
goto case 5;
case 5:
InternalUpdate_inlineAddProd(ref __instance, 4, productRegister);
goto case 4;
case 4:
InternalUpdate_inlineAddProd(ref __instance, 3, productRegister);
goto case 3;
case 3:
InternalUpdate_inlineAddProd(ref __instance, 2, productRegister);
goto case 2;
case 2:
InternalUpdate_inlineAddProd(ref __instance, 1, productRegister);
goto case 1;
case 1:
InternalUpdate_inlineAddProd(ref __instance, 0, productRegister);
break;
}
__instance.extraSpeed = 0;
__instance.speedOverride = __instance.speed;
__instance.extraPowerRatio = 0;
__instance.time -= __instance.timeSpend;
}
if (__instance.extraTime >= __instance.extraTimeSpend)
{
switch (__instance.products.Length)
{
case 6:
InternalUpdate_inlineAddProd(ref __instance, 5, productRegister);
goto case 5;
case 5:
InternalUpdate_inlineAddProd(ref __instance, 4, productRegister);
goto case 4;
case 4:
InternalUpdate_inlineAddProd(ref __instance, 3, productRegister);
goto case 3;
case 3:
InternalUpdate_inlineAddProd(ref __instance, 2, productRegister);
goto case 2;
case 2:
InternalUpdate_inlineAddProd(ref __instance, 1, productRegister);
goto case 1;
case 1:
InternalUpdate_inlineAddProd(ref __instance, 0, productRegister);
break;
}
__instance.extraTime -= __instance.extraTimeSpend;
}
if (!__instance.replicating)
{
int num3 = __instance.requireCounts.Length;
switch (num3)
{
case 6:
if (!InternalUpdate_inlineIsLacking(ref __instance, 5))
{
goto case 5;
}
goto case -1;
case 5:
if (!InternalUpdate_inlineIsLacking(ref __instance, 4))
{
goto case 4;
}
goto case -1;
case 4:
if (!InternalUpdate_inlineIsLacking(ref __instance, 3))
{
goto case 3;
}
goto case -1;
case 3:
if (!InternalUpdate_inlineIsLacking(ref __instance, 2))
{
goto case 2;
}
goto case -1;
case 2:
if (!InternalUpdate_inlineIsLacking(ref __instance, 1))
{
goto case 1;
}
goto case -1;
case 1:
if (!InternalUpdate_inlineIsLacking(ref __instance, 0))
{
break;
}
goto case -1;
case -1:
__instance.time = 0;
DimmaSetLast(dome, __result = 0u);
return;
}
int proli = ((num3 > 0) ? 10 : 0);
switch (num3)
{
case 6:
InternalUpdate_inlineConsume(ref __instance, 5, ref proli, consumeRegister);
goto case 5;
case 5:
InternalUpdate_inlineConsume(ref __instance, 4, ref proli, consumeRegister);
goto case 4;
case 4:
InternalUpdate_inlineConsume(ref __instance, 3, ref proli, consumeRegister);
goto case 3;
case 3:
InternalUpdate_inlineConsume(ref __instance, 2, ref proli, consumeRegister);
goto case 2;
case 2:
InternalUpdate_inlineConsume(ref __instance, 1, ref proli, consumeRegister);
goto case 1;
case 1:
InternalUpdate_inlineConsume(ref __instance, 0, ref proli, consumeRegister);
break;
}
if (proli < 0)
{
proli = 0;
}
if (__instance.productive && !__instance.forceAccMode)
{
__instance.extraSpeed = (int)((double)__instance.speed * Cargo.incTableMilli[proli] * 10.0 + 0.1);
__instance.speedOverride = __instance.speed;
__instance.extraPowerRatio = Cargo.powerTable[proli];
}
else
{
__instance.extraSpeed = 0;
__instance.speedOverride = (int)((double)__instance.speed * (1.0 + Cargo.accTableMilli[proli]) + 0.1);
__instance.extraPowerRatio = Cargo.powerTable[proli];
}
__instance.replicating = true;
}
if (__instance.replicating && __instance.time < __instance.timeSpend && __instance.extraTime < __instance.extraTimeSpend)
{
__instance.time += (int)(power * (float)__instance.speedOverride * num);
__instance.extraTime += (int)(power * (float)__instance.extraSpeed * num);
}
DimmaSetLast(dome, __result = (__instance.replicating ? ((uint)(__instance.products[0] - LabComponent.matrixIds[0] + 1)) : 0u));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void InternalUpdate_inlineAddProd(ref LabComponent __instance, int i, int[] productRegister)
{
__instance.produced[i] += __instance.productCounts[i];
Interlocked.Add(ref productRegister[__instance.products[i]], __instance.productCounts[i]);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool InternalUpdate_inlineIsOutFull(ref LabComponent __instance, int i)
{
return __instance.produced[i] > __instance.productCounts[i] * OupMult;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool InternalUpdate_inlineIsLacking(ref LabComponent __instance, int i)
{
if (__instance.served[i] >= __instance.requireCounts[i])
{
return __instance.served[i] == 0;
}
return true;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void InternalUpdate_inlineConsume(ref LabComponent __instance, int i, ref int proli, int[] consumeRegister)
{
if (__instance.incServed[i] < 0 || __instance.served[i] <= 0)
{
__instance.incServed[i] = 0;
}
int num = __instance.incServed[i] / __instance.served[i];
__instance.served[i] -= __instance.requireCounts[i];
__instance.incServed[i] -= num * __instance.requireCounts[i];
if (num < proli)
{
proli = num;
}
Interlocked.Add(ref consumeRegister[__instance.requires[i]], __instance.requireCounts[i]);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(LabComponent), "UpdateNeedsResearch")]
private static void UpdateNeedsResearch(ref LabComponent __instance, ref bool __runOriginal)
{
if (__runOriginal)
{
__runOriginal = false;
if (DimmaIsDoug(ref __instance))
{
__instance.needs[0] = ((__instance.matrixServed[0] < JelloPlateSize) ? 6001 : 0);
__instance.needs[1] = ((__instance.matrixServed[1] < JelloPlateSize) ? 6002 : 0);
__instance.needs[2] = ((__instance.matrixServed[2] < JelloPlateSize) ? 6003 : 0);
__instance.needs[3] = ((__instance.matrixServed[3] < JelloPlateSize) ? 6004 : 0);
__instance.needs[4] = ((__instance.matrixServed[4] < JelloPlateSize) ? 6005 : 0);
__instance.needs[5] = ((__instance.matrixServed[5] < JelloPlateSize) ? 6006 : 0);
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(LabComponent), "InternalUpdateResearch")]
private static void InternalUpdateResearch(float power, float speed, int[] consumeRegister, ref TechState ts, ref int techHashedThisFrame, ref long uMatrixPoint, ref long hashRegister, ref LabComponent __instance, ref bool __runOriginal, ref uint __result)
{
if (!__runOriginal)
{
return;
}
__runOriginal = false;
int[] dome = DimmaForceDome(ref __instance, isRes: true);
switch (DimmaRefType(dome))
{
case 1:
DimmaUnlock(dome);
__result = DimmaGetLast(dome);
return;
case 0:
DimmaSetType(dome, 2);
break;
}
if (power < 0.1f)
{
DimmaSetLast(dome, __result = 0u);
return;
}
float num = 1f + (float)DimmaRefSpeedPrc(dome) / 100f;
DimmaClearSpeedPrc(dome);
float num2 = speed * num;
int hashPotential = (int)(num2 + 2f);
if (InternalUpdateResearch_inlineCheckPoints(ref __instance, 0, ref hashPotential) || InternalUpdateResearch_inlineCheckPoints(ref __instance, 1, ref hashPotential) || InternalUpdateResearch_inlineCheckPoints(ref __instance, 2, ref hashPotential) || InternalUpdateResearch_inlineCheckPoints(ref __instance, 3, ref hashPotential) || InternalUpdateResearch_inlineCheckPoints(ref __instance, 4, ref hashPotential) || InternalUpdateResearch_inlineCheckPoints(ref __instance, 5, ref hashPotential))
{
__instance.replicating = false;
DimmaSetLast(dome, __result = 0u);
return;
}
__instance.replicating = true;
float num3 = ((num2 < (float)hashPotential) ? num2 : ((float)hashPotential));
long num4 = ts.hashNeeded - ts.hashUploaded;
int num5 = __instance.hashBytes + (int)(power * 10000f * num3 + 0.5f);
long num6 = MIN3((long)num5 / 10000L, num4, hashPotential);
__instance.hashBytes = num5 - (int)num6 * 10000;
if (num6 > 0)
{
int num7 = (int)num6;
int proli = 10;
switch (__instance.matrixServed.Length)
{
case 6:
InternalUpdateResearch_inlineConsume(ref __instance, 5, num7, ref proli, consumeRegister);
goto case 5;
case 5:
InternalUpdateResearch_inlineConsume(ref __instance, 4, num7, ref proli, consumeRegister);
goto case 4;
case 4:
InternalUpdateResearch_inlineConsume(ref __instance, 3, num7, ref proli, consumeRegister);
goto case 3;
case 3:
InternalUpdateResearch_inlineConsume(ref __instance, 2, num7, ref proli, consumeRegister);
goto case 2;
case 2:
InternalUpdateResearch_inlineConsume(ref __instance, 1, num7, ref proli, consumeRegister);
goto case 1;
case 1:
InternalUpdateResearch_inlineConsume(ref __instance, 0, num7, ref proli, consumeRegister);
break;
case 0:
proli = 0;
break;
}
__instance.extraSpeed = (int)(10000.0 * Cargo.incTableMilli[proli] * 10.0 + 0.1);
__instance.extraPowerRatio = Cargo.powerTable[proli];
int num8 = __instance.extraHashBytes + (int)(power * (float)__instance.extraSpeed * num3 + 0.5f);
long num9 = MIN2((long)num8 / 100000L, num4 - num6);
int num10 = (int)num9;
__instance.extraHashBytes = num8 - (int)num9 * 100000;
ts.hashUploaded += num6 + num9;
hashRegister += num6 + num9;
uMatrixPoint += ts.uPointPerHash * num6;
techHashedThisFrame += num7 + num10;
if (ts.hashUploaded >= ts.hashNeeded)
{
TechProto val = ((ProtoSet<TechProto>)(object)LDB.techs).Select(__instance.techId);
if (ts.curLevel >= ts.maxLevel)
{
ts.curLevel = ts.maxLevel;
ts.hashUploaded = ts.hashNeeded;
ts.unlocked = true;
}
else
{
ts.curLevel++;
ts.hashUploaded = 0L;
ts.hashNeeded = val.GetHashNeeded(ts.curLevel);
}
}
}
else
{
__instance.extraSpeed = 0;
__instance.extraPowerRatio = 0;
}
DimmaSetLast(dome, __result = 1u);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool InternalUpdateResearch_inlineCheckPoints(ref LabComponent __instance, int i, ref int hashPotential)
{
if (__instance.matrixPoints[i] > 0)
{
int num = __instance.matrixServed[i] / __instance.matrixPoints[i];
if (num == 0)
{
return true;
}
if (num < hashPotential)
{
hashPotential = num;
}
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void InternalUpdateResearch_inlineConsume(ref LabComponent __instance, int i, int iHashUp, ref int proli, int[] consumeRegister)
{
if (__instance.matrixPoints[i] > 0)
{
int num = __instance.matrixPoints[i] * iHashUp;
int num2 = __instance.matrixIncServed[i] / __instance.matrixServed[i];
__instance.matrixIncServed[i] -= num2 * num;
if (num2 < proli)
{
proli = num2;
}
int num3 = __instance.matrixServed[i] / 3600;
__instance.matrixServed[i] -= num;
int num4 = __instance.matrixServed[i] / 3600;
Interlocked.Add(ref consumeRegister[LabComponent.matrixIds[i]], num3 - num4);
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(FactorySystem), "TakeBackItems_Lab")]
private static void TakeBackItems_Lab(Player player, int labId, FactorySystem __instance)
{
if (labId != 0)
{
ref LabComponent reference = ref __instance.labPool[labId];
if (!DimmaIsDoug(ref reference))
{
reference.replicating = false;
}
}
}
private static void SaveClean(EntityRef eref)
{
if (((EntityRef)(ref eref)).Has_LabComponent)
{
ref LabComponent live_LabComponent = ref ((EntityRef)(ref eref)).GetLive_LabComponent();
if (!DimmaIsDoug(ref live_LabComponent))
{
live_LabComponent.replicating = false;
}
}
}
private static void SaveRestore(EntityRef eref)
{
if (((EntityRef)(ref eref)).Has_LabComponent)
{
ref LabComponent live_LabComponent = ref ((EntityRef)(ref eref)).GetLive_LabComponent();
int[] array = DimmaDome(ref live_LabComponent);
if (array != null && DimmaIsHat(array) && EntityRef.GetLive_LabComponent(((EntityRef)(ref eref)).Factory, DimmaRefWornBy(array)).replicating)
{
live_LabComponent.replicating = true;
}
}
}
}
}
namespace Eirshy.DSP.ReBuffer.NoRythhmn
{
internal static class LabComponentPatcher
{
private const int LOCKED = -1;
private const int JELLO_CALORIES = 3600;
private const int JELLO_FLAVORS = 6;
private static int InpMult;
private static int OupMult;
private static int JelloPlateSize;
public static void ApplyMe()
{
InpMult = Config.GetInp((ERecipeType)15);
OupMult = Config.GetOup((ERecipeType)15);
JelloPlateSize = 3600 * Config.JelloAppetite;
ReBuffer.Harmony.PatchAll(typeof(LabComponentPatcher));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int MIN2(int i, int j)
{
if (i >= j)
{
return j;
}
return i;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static long MIN2(long i, long j)
{
if (i >= j)
{
return j;
}
return i;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static long MIN3(long i, long j, long k)
{
if (i >= j)
{
if (j >= k)
{
return k;
}
return j;
}
if (i >= k)
{
return k;
}
return i;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(LabComponent), "UpdateOutputToNext")]
private static void UpdateOutputToNext(LabComponent[] labPool, ref LabComponent __instance, ref bool __runOriginal)
{
if (!__runOriginal)
{
return;
}
__runOriginal = false;
if (labPool[__instance.nextLabId].id == 0 || labPool[__instance.nextLabId].id != __instance.nextLabId)
{
Assert.CannotBeReached();
__instance.nextLabId = 0;
return;
}
ref LabComponent reference = ref labPool[__instance.nextLabId];
if (__instance.researchMode)
{
if (UpdateOutputToNext_inlineWillUp(ref __instance, ref reference, 0))
{
UpdateOutputToNext_inlineJelloUp(ref __instance, ref reference, 0);
}
if (UpdateOutputToNext_inlineWillUp(ref __instance, ref reference, 1))
{
UpdateOutputToNext_inlineJelloUp(ref __instance, ref reference, 1);
}
if (UpdateOutputToNext_inlineWillUp(ref __instance, ref reference, 2))
{
UpdateOutputToNext_inlineJelloUp(ref __instance, ref reference, 2);
}
if (UpdateOutputToNext_inlineWillUp(ref __instance, ref reference, 3))
{
UpdateOutputToNext_inlineJelloUp(ref __instance, ref reference, 3);
}
if (UpdateOutputToNext_inlineWillUp(ref __instance, ref reference, 4))
{
UpdateOutputToNext_inlineJelloUp(ref __instance, ref reference, 4);
}
if (UpdateOutputToNext_inlineWillUp(ref __instance, ref reference, 5))
{
UpdateOutputToNext_inlineJelloUp(ref __instance, ref reference, 5);
}
}
else
{
if (__instance.recipeId == 0)
{
return;
}
switch (__instance.served.Length)
{
case 6:
if (UpdateOutputToNext_inlineWillUp(ref __instance, ref reference, 5))
{
UpdateOutputToNext_inlineServeUp(ref __instance, ref reference, 5);
}
goto case 5;
case 5:
if (UpdateOutputToNext_inlineWillUp(ref __instance, ref reference, 4))
{
UpdateOutputToNext_inlineServeUp(ref __instance, ref reference, 4);
}
goto case 4;
case 4:
if (UpdateOutputToNext_inlineWillUp(ref __instance, ref reference, 3))
{
UpdateOutputToNext_inlineServeUp(ref __instance, ref reference, 3);
}
goto case 3;
case 3:
if (UpdateOutputToNext_inlineWillUp(ref __instance, ref reference, 2))
{
UpdateOutputToNext_inlineServeUp(ref __instance, ref reference, 2);
}
goto case 2;
case 2:
if (UpdateOutputToNext_inlineWillUp(ref __instance, ref reference, 1))
{
UpdateOutputToNext_inlineServeUp(ref __instance, ref reference, 1);
}
goto case 1;
case 1:
if (UpdateOutputToNext_inlineWillUp(ref __instance, ref reference, 0))
{
UpdateOutputToNext_inlineServeUp(ref __instance, ref reference, 0);
}
break;
}
if (__instance.produced[0] < __instance.productCounts[0] && reference.produced[0] > 0)
{
int value = Interlocked.Exchange(ref reference.produced[0], 0);
Interlocked.Add(ref __instance.produced[0], value);
}
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool UpdateOutputToNext_inlineWillUp(ref LabComponent __instance, ref LabComponent next, int i)
{
if (__instance.needs[i] == 0)
{
return next.needs[i] > 0;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void UpdateOutputToNext_inlineServeUp(ref LabComponent __instance, ref LabComponent next, int i)
{
int num = next.requireCounts[i];
if (num > 0)
{
int num2 = __instance.matrixServed[i];
int num3 = ((num2 > 0) ? (__instance.matrixIncServed[i] / num2) : 0) * num;
Interlocked.Add(ref __instance.served[i], -num);
Interlocked.Add(ref __instance.incServed[i], -num3);
Interlocked.Add(ref next.served[i], num);
Interlocked.Add(ref next.incServed[i], num3);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void UpdateOutputToNext_inlineJelloUp(ref LabComponent __instance, ref LabComponent next, int i)
{
int num = 3600;
if (num > 0)
{
int num2 = __instance.served[i];
int num3 = ((num2 > 0) ? (__instance.incServed[i] / num2) : 0) * num;
Interlocked.Add(ref __instance.matrixServed[i], -num);
Interlocked.Add(ref __instance.matrixIncServed[i], -num3);
Interlocked.Add(ref next.matrixServed[i], num);
Interlocked.Add(ref next.matrixIncServed[i], num3);
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(LabComponent), "UpdateNeedsAssemble")]
private static void UpdateNeedsAssemble(ref LabComponent __instance, ref bool __runOriginal)
{
if (__runOriginal)
{
__runOriginal = false;
if (__instance.matrixServed == null)
{
__instance.matrixServed = new int[6];
__instance.matrixIncServed = new int[6];
}
switch (__instance.served.Length)
{
case 6:
UpdateNeedsAssemble_inline(ref __instance, 5);
goto case 5;
case 5:
UpdateNeedsAssemble_inline(ref __instance, 4);
goto case 4;
case 4:
UpdateNeedsAssemble_inline(ref __instance, 3);
goto case 3;
case 3:
UpdateNeedsAssemble_inline(ref __instance, 2);
goto case 2;
case 2:
UpdateNeedsAssemble_inline(ref __instance, 1);
goto case 1;
case 1:
UpdateNeedsAssemble_inline(ref __instance, 0);
break;
}
Array.Copy(__instance.served, __instance.matrixServed, __instance.served.Length);
Array.Copy(__instance.incServed, __instance.matrixIncServed, __instance.incServed.Length);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void UpdateNeedsAssemble_inline(ref LabComponent __instance, int i)
{
__instance.needs[i] = ((__instance.served[i] < __instance.requireCounts[i] * InpMult) ? __instance.requires[i] : 0);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(LabComponent), "InternalUpdateAssemble", new Type[]
{
typeof(float),
typeof(int[]),
typeof(int[])
})]
private static void InternalUpdateAssemble(float power, int[] productRegister, int[] consumeRegister, ref LabComponent __instance, ref bool __runOriginal, ref uint __result)
{
if (!__runOriginal)
{
return;
}
__runOriginal = false;
if (power < 0.1f)
{
__result = 0u;
return;
}
if (__instance.time >= __instance.timeSpend)
{
int num = __instance.products.Length;
__instance.replicating = false;
switch (num)
{
case 6:
if (!InternalUpdate_inlineIsOutFull(ref __instance, 5))
{
goto case 5;
}
goto case -1;
case 5:
if (!InternalUpdate_inlineIsOutFull(ref __instance, 4))
{
goto case 4;
}
goto case -1;
case 4:
if (!InternalUpdate_inlineIsOutFull(ref __instance, 3))
{
goto case 3;
}
goto case -1;
case 3:
if (!InternalUpdate_inlineIsOutFull(ref __instance, 2))
{
goto case 2;
}
goto case -1;
case 2:
if (!InternalUpdate_inlineIsOutFull(ref __instance, 1))
{
goto case 1;
}
goto case -1;
case 1:
if (!InternalUpdate_inlineIsOutFull(ref __instance, 0))
{
break;
}
goto case -1;
case -1:
__result = 0u;
return;
}
switch (num)
{
case 6:
InternalUpdate_inlineAddProd(ref __instance, 5, productRegister);
goto case 5;
case 5:
InternalUpdate_inlineAddProd(ref __instance, 4, productRegister);
goto case 4;
case 4:
InternalUpdate_inlineAddProd(ref __instance, 3, productRegister);
goto case 3;
case 3:
InternalUpdate_inlineAddProd(ref __instance, 2, productRegister);
goto case 2;
case 2:
InternalUpdate_inlineAddProd(ref __instance, 1, productRegister);
goto case 1;
case 1:
InternalUpdate_inlineAddProd(ref __instance, 0, productRegister);
break;
}
__instance.extraSpeed = 0;
__instance.speedOverride = __instance.speed;
__instance.extraPowerRatio = 0;
__instance.time -= __instance.timeSpend;
}
if (__instance.extraTime >= __instance.extraTimeSpend)
{
switch (__instance.products.Length)
{
case 6:
InternalUpdate_inlineAddProd(ref __instance, 5, productRegister);
goto case 5;
case 5:
InternalUpdate_inlineAddProd(ref __instance, 4, productRegister);
goto case 4;
case 4:
InternalUpdate_inlineAddProd(ref __instance, 3, productRegister);
goto case 3;
case 3:
InternalUpdate_inlineAddProd(ref __instance, 2, productRegister);
goto case 2;
case 2:
InternalUpdate_inlineAddProd(ref __instance, 1, productRegister);
goto case 1;
case 1:
InternalUpdate_inlineAddProd(ref __instance, 0, productRegister);
break;
}
__instance.extraTime -= __instance.extraTimeSpend;
}
if (!__instance.replicating)
{
int num2 = __instance.requireCounts.Length;
switch (num2)
{
case 6:
if (!InternalUpdate_inlineIsLacking(ref __instance, 5))
{
goto case 5;
}
goto case -1;
case 5:
if (!InternalUpdate_inlineIsLacking(ref __instance, 4))
{
goto case 4;
}
goto case -1;
case 4:
if (!InternalUpdate_inlineIsLacking(ref __instance, 3))
{
goto case 3;
}
goto case -1;
case 3:
if (!InternalUpdate_inlineIsLacking(ref __instance, 2))
{
goto case 2;
}
goto case -1;
case 2:
if (!InternalUpdate_inlineIsLacking(ref __instance, 1))
{
goto case 1;
}
goto case -1;
case 1:
if (!InternalUpdate_inlineIsLacking(ref __instance, 0))
{
break;
}
goto case -1;
case -1:
__instance.time = 0;
__result = 0u;
return;
}
int proli = ((num2 > 0) ? 10 : 0);
switch (num2)
{
case 6:
InternalUpdate_inlineConsume(ref __instance, 5, ref proli, consumeRegister);
goto case 5;
case 5:
InternalUpdate_inlineConsume(ref __instance, 4, ref proli, consumeRegister);
goto case 4;
case 4:
InternalUpdate_inlineConsume(ref __instance, 3, ref proli, consumeRegister);
goto case 3;
case 3:
InternalUpdate_inlineConsume(ref __instance, 2, ref proli, consumeRegister);
goto case 2;
case 2:
InternalUpdate_inlineConsume(ref __instance, 1, ref proli, consumeRegister);
goto case 1;
case 1:
InternalUpdate_inlineConsume(ref __instance, 0, ref proli, consumeRegister);
break;
}
if (proli < 0)
{
proli = 0;
}
if (__instance.productive && !__instance.forceAccMode)
{
__instance.extraSpeed = (int)((double)__instance.speed * Cargo.incTableMilli[proli] * 10.0 + 0.1);
__instance.speedOverride = __instance.speed;
__instance.extraPowerRatio = Cargo.powerTable[proli];
}
else
{
__instance.extraSpeed = 0;
__instance.speedOverride = (int)((double)__instance.speed * (1.0 + Cargo.accTableMilli[proli]) + 0.1);
__instance.extraPowerRatio = Cargo.powerTable[proli];
}
__instance.replicating = true;
}
if (__instance.replicating && __instance.time < __instance.timeSpend && __instance.extraTime < __instance.extraTimeSpend)
{
__instance.time += (int)(power * (float)__instance.speedOverride);
__instance.extraTime += (int)(power * (float)__instance.extraSpeed);
}
__result = (__instance.replicating ? ((uint)(__instance.products[0] - LabComponent.matrixIds[0] + 1)) : 0u);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void InternalUpdate_inlineAddProd(ref LabComponent __instance, int i, int[] productRegister)
{
Interlocked.Add(ref __instance.produced[i], __instance.productCounts[i]);
Interlocked.Add(ref productRegister[__instance.products[i]], __instance.productCounts[i]);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool InternalUpdate_inlineIsOutFull(ref LabComponent __instance, int i)
{
return __instance.produced[i] > __instance.productCounts[i] * OupMult;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool InternalUpdate_inlineIsLacking(ref LabComponent __instance, int i)
{
if (__instance.matrixServed[i] >= __instance.requireCounts[i])
{
return __instance.matrixServed[i] == 0;
}
return true;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void InternalUpdate_inlineConsume(ref LabComponent __instance, int i, ref int proli, int[] consumeRegister)
{
int num = ((__instance.matrixServed[i] > 0) ? (__instance.matrixIncServed[i] / __instance.matrixServed[i]) : 0);
Interlocked.Add(ref __instance.served[i], -__instance.requireCounts[i]);
Interlocked.Add(ref __instance.incServed[i], -(num * __instance.requireCounts[i]));
if (num < proli)
{
proli = num;
}
Interlocked.Add(ref consumeRegister[__instance.requires[i]], __instance.requireCounts[i]);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(LabComponent), "UpdateNeedsResearch")]
private static void UpdateNeedsResearch(ref LabComponent __instance, ref bool __runOriginal)
{
if (__runOriginal)
{
__runOriginal = false;
if (__instance.served == null || __instance.served.Length < 6)
{
__instance.served = new int[6];
__instance.incServed = new int[6];
}
__instance.needs[0] = ((__instance.matrixServed[0] < JelloPlateSize) ? 6001 : 0);
__instance.needs[1] = ((__instance.matrixServed[1] < JelloPlateSize) ? 6002 : 0);
__instance.needs[2] = ((__instance.matrixServed[2] < JelloPlateSize) ? 6003 : 0);
__instance.needs[3] = ((__instance.matrixServed[3] < JelloPlateSize) ? 6004 : 0);
__instance.needs[4] = ((__instance.matrixServed[4] < JelloPlateSize) ? 6005 : 0);
__instance.needs[5] = ((__instance.matrixServed[5] < JelloPlateSize) ? 6006 : 0);
Array.Copy(__instance.matrixServed, __instance.served, __instance.matrixServed.Length);
Array.Copy(__instance.matrixIncServed, __instance.incServed, __instance.matrixIncServed.Length);
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(LabComponent), "InternalUpdateResearch")]
private static void InternalUpdateResearch(float power, float research_speed, int[] consumeRegister, ref TechState ts, ref int techHashedThisFrame, ref long uMatrixPoint, ref long hashRegister, ref LabComponent __instance, ref bool __runOriginal, ref uint __result)
{
if (!__runOriginal)
{
return;
}
__runOriginal = false;
if (power < 0.1f)
{
__result = 0u;
return;
}
int hashPotential = (int)(research_speed + 2f);
if (InternalUpdateResearch_inlineCheckPoints(ref __instance, 0, ref hashPotential) || InternalUpdateResearch_inlineCheckPoints(ref __instance, 1, ref hashPotential) || InternalUpdateResearch_inlineCheckPoints(ref __instance, 2, ref hashPotential) || InternalUpdateResearch_inlineCheckPoints(ref __instance, 3, ref hashPotential) || InternalUpdateResearch_inlineCheckPoints(ref __instance, 4, ref hashPotential) || InternalUpdateResearch_inlineCheckPoints(ref __instance, 5, ref hashPotential))
{
__instance.replicating = false;
__result = 0u;
return;
}
__instance.replicating = true;
float num = ((research_speed < (float)hashPotential) ? research_speed : ((float)hashPotential));
long num2 = ts.hashNeeded - ts.hashUploaded;
int num3 = __instance.hashBytes + (int)(power * 10000f * num + 0.5f);
long num4 = MIN3((long)num3 / 10000L, num2, hashPotential);
__instance.hashBytes = num3 - (int)num4 * 10000;
if (num4 > 0)
{
int num5 = (int)num4;
int proli = 10;
switch (__instance.matrixServed.Length)
{
case 6:
InternalUpdateResearch_inlineConsume(ref __instance, 5, num5, ref proli, consumeRegister);
goto case 5;
case 5:
InternalUpdateResearch_inlineConsume(ref __instance, 4, num5, ref proli, consumeRegister);
goto case 4;
case 4:
InternalUpdateResearch_inlineConsume(ref __instance, 3, num5, ref proli, consumeRegister);
goto case 3;
case 3:
InternalUpdateResearch_inlineConsume(ref __instance, 2, num5, ref proli, consumeRegister);
goto case 2;
case 2:
InternalUpdateResearch_inlineConsume(ref __instance, 1, num5, ref proli, consumeRegister);
goto case 1;
case 1:
InternalUpdateResearch_inlineConsume(ref __instance, 0, num5, ref proli, consumeRegister);
break;
case 0:
proli = 0;
break;
}
__instance.extraSpeed = (int)(10000.0 * Cargo.incTableMilli[proli] * 10.0 + 0.1);
__instance.extraPowerRatio = Cargo.powerTable[proli];
int num6 = __instance.extraHashBytes + (int)(power * (float)__instance.extraSpeed * num + 0.5f);
long num7 = MIN2((long)num6 / 100000L, num2 - num4);
int num8 = (int)num7;
__instance.extraHashBytes = num6 - (int)num7 * 100000;
ts.hashUploaded += num4 + num7;
hashRegister += num4 + num7;
uMatrixPoint += ts.uPointPerHash * num4;
techHashedThisFrame += num5 + num8;
if (ts.hashUploaded >= ts.hashNeeded)
{
TechProto val = ((ProtoSet<TechProto>)(object)LDB.techs).Select(__instance.techId);
if (ts.curLevel >= ts.maxLevel)
{
ts.curLevel = ts.maxLevel;
ts.hashUploaded = ts.hashNeeded;
ts.unlocked = true;
}
else
{
ts.curLevel++;
ts.hashUploaded = 0L;
ts.hashNeeded = val.GetHashNeeded(ts.curLevel);
}
}
}
else
{
__instance.extraSpeed = 0;
__instance.extraPowerRatio = 0;
}
__result = 1u;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool InternalUpdateResearch_inlineCheckPoints(ref LabComponent __instance, int i, ref int hashPotential)
{
int num = __instance.matrixPoints[i];
if (num > 0)
{
int num2 = __instance.served[i] / num;
if (num2 == 0)
{
return true;
}
if (num2 < hashPotential)
{
hashPotential = num2;
}
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void InternalUpdateResearch_inlineConsume(ref LabComponent __instance, int i, int iHashUp, ref int proli, int[] consumeRegister)
{
int num = __instance.served[i];
int num2 = __instance.matrixPoints[i];
if (num2 > 0)
{
int num3 = num2 * iHashUp;
int num4 = ((num != 0) ? (__instance.incServed[i] / num) : 0);
Interlocked.Add(ref __instance.matrixIncServed[i], -(num4 * num3));
if (num4 < proli)
{
proli = num4;
}
int num5 = num / 3600;
int num6 = Interlocked.Add(ref __instance.matrixServed[i], -num3) / 3600;
Interlocked.Add(ref consumeRegister[LabComponent.matrixIds[i]], num5 - num6);
}
}
}
}
namespace Eirshy.DSP.ReBuffer.AnyBeat
{
internal static class AssemblerComponentPatcher
{
public static void ApplyMe()
{
ReBuffer.Harmony.PatchAll(typeof(AssemblerComponentPatcher));
}
[HarmonyPrefix]
[HarmonyPatch(typeof(AssemblerComponent), "UpdateNeeds")]
private static void UpdateNeeds(ref AssemblerComponent __instance, ref bool __runOriginal)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
if (__runOriginal)
{
__runOriginal = false;
int inp = Config.GetInp(__instance.recipeType);
switch (__instance.requires.Length)
{
default:
return;
case 6:
UpdateNeeds_inline(ref __instance, 5, inp);
goto case 5;
case 5:
UpdateNeeds_inline(ref __instance, 4, inp);
goto case 4;
case 4:
UpdateNeeds_inline(ref __instance, 3, inp);
goto case 3;
case 3:
UpdateNeeds_inline(ref __instance, 2, inp);
goto case 2;
case 2:
UpdateNeeds_inline(ref __instance, 1, inp);
break;
case 1:
break;
}
UpdateNeeds_inline(ref __instance, 0, inp);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void UpdateNeeds_inline(ref AssemblerComponent __instance, int i, int buffm)
{
__instance.needs[i] = ((__instance.served[i] < __instance.requireCounts[i] * buffm) ? __instance.requires[i] : 0);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(AssemblerComponent), "InternalUpdate")]
private static void InternalUpdate(float power, int[] productRegister, int[] consumeRegister, ref AssemblerComponent __instance, ref bool __runOriginal, ref uint __result)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
if (!__runOriginal)
{
return;
}
__runOriginal = false;
if (power < 0.1f)
{
__result = 0u;
return;
}
int oup = Config.GetOup(__instance.recipeType);
if (__instance.time >= __instance.timeSpend)
{
int num = __instance.products.Length;
__instance.replicating = false;
switch (num)
{
case 6:
if (!InternalUpdate_inlineIsOutFull(ref __instance, 5, oup))
{
goto case 5;
}
goto case -1;
case 5:
if (!InternalUpdate_inlineIsOutFull(ref __instance, 4, oup))
{
goto case 4;
}
goto case -1;
case 4:
if (!InternalUpdate_inlineIsOutFull(ref __instance, 3, oup))
{
goto case 3;
}
goto case -1;
case 3:
if (!InternalUpdate_inlineIsOutFull(ref __instance, 2, oup))
{
goto case 2;
}
goto case -1;
case 2:
if (!InternalUpdate_inlineIsOutFull(ref __instance, 1, oup))
{
goto case 1;
}
goto case -1;
case 1:
if (!InternalUpdate_inlineIsOutFull(ref __instance, 0, oup))
{
break;
}
goto case -1;
case -1:
__result = 0u;
return;
}
switch (num)
{
case 6:
InternalUpdate_inlineAddProd(ref __instance, 5, productRegister);
goto case 5;
case 5:
InternalUpdate_inlineAddProd(ref __instance, 4, productRegister);
goto case 4;
case 4:
InternalUpdate_inlineAddProd(ref __instance, 3, productRegister);
goto case 3;
case 3:
InternalUpdate_inlineAddProd(ref __instance, 2, productRegister);
goto case 2;
case 2:
InternalUpdate_inlineAddProd(ref __instance, 1, productRegister);
goto case 1;
case 1:
InternalUpdate_inlineAddProd(ref __instance, 0, productRegister);
break;
}
__instance.extraSpeed = 0;
__instance.speedOverride = __instance.speed;
__instance.extraPowerRatio = 0;
__instance.time -= __instance.timeSpend;
}
if (__instance.extraTime >= __instance.extraTimeSpend)
{
switch (__instance.products.Length)
{
case 6:
InternalUpdate_inlineAddProd(ref __instance, 5, productRegister);
goto case 5;
case 5:
InternalUpdate_inlineAddProd(ref __instance, 4, productRegister);
goto case 4;
case 4:
InternalUpdate_inlineAddProd(ref __instance, 3, productRegister);
goto case 3;
case 3:
InternalUpdate_inlineAddProd(ref __instance, 2, productRegister);
goto case 2;
case 2:
InternalUpdate_inlineAddProd(ref __instance, 1, productRegister);
goto case 1;
case 1:
InternalUpdate_inlineAddProd(ref __instance, 0, productRegister);
break;
}
__instance.extraTime -= __instance.extraTimeSpend;
}
if (!__instance.replicating)
{
int num2 = __instance.requireCounts.Length;
switch (num2)
{
case 6:
if (!InternalUpdate_inlineIsLacking(ref __instance, 5))
{
goto case 5;
}
goto case -1;
case 5:
if (!InternalUpdate_inlineIsLacking(ref __instance, 4))
{
goto case 4;
}
goto case -1;
case 4:
if (!InternalUpdate_inlineIsLacking(ref __instance, 3))
{
goto case 3;
}
goto case -1;
case 3:
if (!InternalUpdate_inlineIsLacking(ref __instance, 2))
{
goto case 2;
}
goto case -1;
case 2:
if (!InternalUpdate_inlineIsLacking(ref __instance, 1))
{
goto case 1;
}
goto case -1;
case 1:
if (!InternalUpdate_inlineIsLacking(ref __instance, 0))
{
break;
}
goto case -1;
case -1:
__instance.time = 0;
__result = 0u;
return;
}
int proli = ((num2 > 0) ? 10 : 0);
switch (num2)
{
case 6:
InternalUpdate_inlineConsume(ref __instance, 5, ref proli, consumeRegister);
goto case 5;
case 5:
InternalUpdate_inlineConsume(ref __instance, 4, ref proli, consumeRegister);
goto case 4;
case 4:
InternalUpdate_inlineConsume(ref __instance, 3, ref proli, consumeRegister);
goto case 3;
case 3:
InternalUpdate_inlineConsume(ref __instance, 2, ref proli, consumeRegister);
goto case 2;
case 2:
InternalUpdate_inlineConsume(ref __instance, 1, ref proli, consumeRegister);
goto case 1;
case 1:
InternalUpdate_inlineConsume(ref __instance, 0, ref proli, consumeRegister);
break;
}
if (__instance.productive && !__instance.forceAccMode)
{
__instance.extraSpeed = (int)((double)__instance.speed * Cargo.incTableMilli[proli] * 10.0 + 0.1);
__instance.speedOverride = __instance.speed;
__instance.extraPowerRatio = Cargo.powerTable[proli];
}
else
{
__instance.extraSpeed = 0;
__instance.speedOverride = (int)((double)__instance.speed * (1.0 + Cargo.accTableMilli[proli]) + 0.1);
__instance.extraPowerRatio = Cargo.powerTable[proli];
}
__instance.replicating = true;
}
if (__instance.replicating && __instance.time < __instance.timeSpend && __instance.extraTime < __instance.extraTimeSpend)
{
__instance.time += (int)(power * (float)__instance.speedOverride);
__instance.extraTime += (int)(power * (float)__instance.extraSpeed);
}
__result = (__instance.replicating ? 1u : 0u);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void InternalUpdate_inlineAddProd(ref AssemblerComponent __instance, int i, int[] productRegister)
{
__instance.produced[i] += __instance.productCounts[i];
Interlocked.Add(ref productRegister[__instance.products[i]], __instance.productCounts[i]);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool InternalUpdate_inlineIsOutFull(ref AssemblerComponent __instance, int i, int buffm_oup)
{
return __instance.produced[i] > __instance.productCounts[i] * buffm_oup;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool InternalUpdate_inlineIsLacking(ref AssemblerComponent __instance, int i)
{
if (__instance.served[i] >= __instance.requireCounts[i])
{
return __instance.served[i] == 0;
}
return true;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void InternalUpdate_inlineConsume(ref AssemblerComponent __instance, int i, ref int proli, int[] consumeRegister)
{
int num = __instance.incServed[i] / __instance.served[i];
__instance.served[i] -= __instance.requireCounts[i];
__instance.incServed[i] -= num * __instance.requireCounts[i];
if (num < proli)
{
proli = num;
}
Interlocked.Add(ref consumeRegister[__instance.requires[i]], __instance.requireCounts[i]);
}
}
internal class PowerGeneratorComponentPatcher
{
private const int CATA_VALUE = 3600;
private const byte PILE_QTY = 4;
private static int CataMax;
private static float ProdMax;
private static int CataPassAt;
private static byte QtyOut;
public static void ApplyMe()
{
CataMax = 3600 * Config.RayrCataIn;
ProdMax = Config.RayrProdOut;
QtyOut = (byte)((!Config.RayrPiling) ? 1 : 4);
int num = 3600 * (2 + QtyOut);
CataPassAt = ((Config.RayrCataPass && CataMax >= num) ? num : int.MaxValue);
ReBuffer.Harmony.PatchAll(typeof(PowerGeneratorComponentPatcher));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static float MIN2(float i, float j)
{
if (!(i < j))
{
return j;
}
return i;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static float MAX2(float i, float j)
{
if (!(i < j))
{
return i;
}
return j;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(PowerGeneratorComponent), "GameTick_Gamma")]
private static void GameTick_Gamma(bool useIon, bool useCata, bool keyFrame, PlanetFactory factory, int[] productRegister, int[] consumeRegister, ref PowerGeneratorComponent __instance, ref bool __runOriginal)
{
__runOriginal = false;
ref SignData reference = ref factory.entitySignPool[__instance.entityId];
if (useCata && __instance.catalystPoint > 0)
{
int num = __instance.catalystPoint % 3600;
int num2 = __instance.catalystIncPoint / __instance.catalystPoint;
__instance.catalystPoint--;
__instance.catalystIncPoint -= num2;
if (num == 0)
{
Interlocked.Decrement(ref consumeRegister[__instance.catalystId]);
}
}
if (__instance.productId > 0 && __instance.productCount <= ProdMax)
{
float num3 = (float)((double)__instance.capacityCurrentTick / (double)__instance.productHeat);
int num4 = (int)__instance.productCount;
__instance.productCount += num3;
int num5 = (int)__instance.productCount - num4;
if (num5 > 0)
{
Interlocked.Add(ref productRegister[__instance.productId], num5);
}
reference.iconId0 = (uint)__instance.productId;
reference.iconType = 1u;
}
if (__instance.productId == 0)
{
reference.iconId0 = 0u;
reference.iconType = 0u;
}
if (__instance.warmupSpeed > 0f && __instance.warmup != 1f)
{
__instance.warmup = MIN2(__instance.warmup + __instance.warmupSpeed, 1f);
}
else if (__instance.warmupSpeed < 0f && __instance.warmup != 0f)
{
__instance.warmup = MAX2(__instance.warmup + __instance.warmupSpeed, 0f);
}
if (!keyFrame)
{
return;
}
bool flag = useIon && __instance.catalystPoint < CataMax;
bool flag2 = __instance.productId > 0;
bool flag3 = __instance.catalystPoint >= CataPassAt && !flag2 && __instance.productCount == 0f;
bool flag4 = flag2 && __instance.productCount >= 1f;
if (!(flag || flag3 || flag4))
{
return;
}
bool flag5 = default(bool);
int num6 = default(int);
int num7 = default(int);
factory.ReadObjectConn(__instance.entityId, 0, ref flag5, ref num6, ref num7);
bool flag6 = default(bool);
int num8 = default(int);
factory.ReadObjectConn(__instance.entityId, 1, ref flag6, ref num8, ref num7);
if (flag)
{
byte b = default(byte);
byte b2 = default(byte);
if (!flag5 && factory.PickFrom(num6, 0, __instance.catalystId, (int[])null, ref b, ref b2) == __instance.catalystId)
{
__instance.catalystPoint += 3600 * b;
__instance.catalystIncPoint += 3600 * b2;
}
if (!flag6 && factory.PickFrom(num8, 0, __instance.catalystId, (int[])null, ref b, ref b2) == __instance.catalystId)
{
__instance.catalystPoint += 3600 * b;
__instance.catalystIncPoint += 3600 * b2;
}
}
if ((!flag3 && !flag4) || (!flag5 && !flag6))
{
return;
}
bool flag7 = __instance.fuelHeat == 0;
__instance.fuelHeat = (flag7 ? 1 : 0);
int num9 = ((flag5 && (!flag6 || flag7)) ? num6 : ((flag6 && (!flag5 || !flag7)) ? num8 : 0));
byte b3 = default(byte);
if (flag4)
{
int num10 = factory.InsertInto(num9, 0, __instance.productId, QtyOut, (byte)0, ref b3);
if (num10 > 0)
{
__instance.productCount -= num10;
}
}
else if (flag3)
{
int num11 = __instance.catalystIncPoint / __instance.catalystPoint;
int num12 = QtyOut * num11;
int num13 = factory.InsertInto(num9, 0, __instance.catalystId, QtyOut, (byte)num12, ref b3);
if (num13 > 0)
{
__instance.catalystId -= 3600 * num13;
__instance.catalystIncPoint -= 3600 * num11 * num13;
}
}
}
}
}