Decompiled source of FractionateAntimatter v1.0.4

FractionateAntimatter.dll

Decompiled a month ago
using System;
using System.Collections.Concurrent;
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 FractionateAntimatter
{
	public static class AntimatterFractionationPatch
	{
		private const int AntimatterId = 1122;

		private static RecipeProto antimatterFractionRecipe;

		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 (itemId == 1122)
			{
				refSpeed *= 2f;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(RecipeProto), "InitFractionatorNeeds")]
		public static void InitFractionatorNeedsPostfix()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			RecipeProto val = new RecipeProto();
			val.Type = (ERecipeType)8;
			((Proto)val).ID = 999;
			((Proto)val).Name = "Antimatter Fractionation";
			val.Items = new int[1] { 1122 };
			val.ItemCounts = new int[1] { 200 };
			val.Results = new int[1] { 1122 };
			val.ResultCounts = new int[1] { 2 };
			val.GridIndex = 0;
			val.TimeSpend = 60;
			val.Handcraft = false;
			val.Explicit = false;
			val.NonProductive = true;
			antimatterFractionRecipe = val;
			int num = RecipeProto.fractionatorRecipes.Length;
			RecipeProto[] array = (RecipeProto[])(object)new RecipeProto[num + 1];
			for (int i = 0; i < num; i++)
			{
				array[i] = RecipeProto.fractionatorRecipes[i];
			}
			array[num] = antimatterFractionRecipe;
			RecipeProto.fractionatorRecipes = array;
			int[] array2 = new int[num + 1];
			for (int j = 0; j < num; j++)
			{
				array2[j] = RecipeProto.fractionatorNeeds[j];
			}
			array2[num] = 1122;
			RecipeProto.fractionatorNeeds = array2;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(FractionatorComponent), "InternalUpdate")]
		public static void InternalUpdatePrefix(ref FractionatorComponent __instance)
		{
			if (__instance.fluidId == 1122)
			{
				previousProductTotal[__instance.id] = __instance.productOutputTotal;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(FractionatorComponent), "InternalUpdate")]
		public static void InternalUpdatePostfix(ref FractionatorComponent __instance, int[] productRegister)
		{
			if (__instance.fluidId != 1122 || !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.FractionateAntimatter", "FractionateAntimatter", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.leo.dsp.FractionateAntimatter";

		public const string PluginName = "FractionateAntimatter";

		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.FractionateAntimatter");
			_harmony.PatchAll(typeof(AntimatterFractionationPatch));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"FractionateAntimatter 1.0.0 loaded.");
		}

		public void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}