using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
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: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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 FractionateMatrix
{
public static class MatrixFractionationPatch
{
private const int ElectromagneticMatrix = 6001;
private const int EnergyMatrix = 6002;
private const int StructureMatrix = 6003;
private const int InformationMatrix = 6004;
private const int GravityMatrix = 6005;
private const int UniverseMatrix = 6006;
private static readonly int[] MatrixIds = new int[6] { 6001, 6002, 6003, 6004, 6005, 6006 };
private static HashSet<int> DoubleOutputItems = new HashSet<int>(MatrixIds);
private static ConcurrentDictionary<int, int> previousProductTotal = new ConcurrentDictionary<int, int>();
[HarmonyPrefix]
[HarmonyPatch(typeof(FactoryProductionStat), "AddRefProductSpeed")]
public static void AddRefProductSpeedPrefix(int itemId, ref float refSpeed)
{
if (DoubleOutputItems.Contains(itemId))
{
refSpeed *= 2f;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(RecipeProto), "InitFractionatorNeeds")]
public static void InitFractionatorNeedsPostfix()
{
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Expected O, but got Unknown
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
int num = RecipeProto.fractionatorRecipes.Length;
int num2 = RecipeProto.fractionatorNeeds.Length;
int num3 = MatrixIds.Length;
RecipeProto[] array = (RecipeProto[])(object)new RecipeProto[num + num3];
int[] array2 = new int[num2 + num3];
for (int i = 0; i < num; i++)
{
array[i] = RecipeProto.fractionatorRecipes[i];
}
for (int j = 0; j < num2; j++)
{
array2[j] = RecipeProto.fractionatorNeeds[j];
}
for (int k = 0; k < num3; k++)
{
int num4 = MatrixIds[k];
RecipeProto val = new RecipeProto();
val.Type = (ERecipeType)8;
((Proto)val).ID = 990 + k;
((Proto)val).Name = $"Matrix Fractionation {k + 1}";
val.Items = new int[1] { num4 };
val.ItemCounts = new int[1] { 200 };
val.Results = new int[1] { num4 };
val.ResultCounts = new int[1] { 2 };
val.GridIndex = 0;
val.TimeSpend = 60;
val.Handcraft = false;
val.Explicit = false;
val.NonProductive = true;
RecipeProto val2 = val;
array[num + k] = val2;
array2[num2 + k] = num4;
}
RecipeProto.fractionatorRecipes = array;
RecipeProto.fractionatorNeeds = array2;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(FractionatorComponent), "InternalUpdate")]
public static void InternalUpdatePrefix(ref FractionatorComponent __instance)
{
if (DoubleOutputItems.Contains(__instance.fluidId))
{
previousProductTotal[__instance.id] = __instance.productOutputTotal;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(FractionatorComponent), "InternalUpdate")]
public static void InternalUpdatePostfix(ref FractionatorComponent __instance, int[] productRegister)
{
if (!DoubleOutputItems.Contains(__instance.fluidId) || !previousProductTotal.TryGetValue(__instance.id, out var value))
{
return;
}
int num = __instance.productOutputTotal - value;
if (num <= 0)
{
return;
}
__instance.productOutputCount += num;
__instance.productOutputTotal += num;
lock (productRegister)
{
productRegister[__instance.productId] += num;
}
}
}
[BepInPlugin("com.leo.dsp.FractionateMatrix", "FractionateMatrix", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public const string PluginGuid = "com.leo.dsp.FractionateMatrix";
public const string PluginName = "FractionateMatrix";
public const string PluginVersion = "1.0.0";
private Harmony _harmony;
public void Awake()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
_harmony = new Harmony("com.leo.dsp.FractionateMatrix");
_harmony.PatchAll(typeof(MatrixFractionationPatch));
((BaseUnityPlugin)this).Logger.LogInfo((object)"FractionateMatrix 1.0.0 loaded.");
}
public void OnDestroy()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
}
}