Decompiled source of MelanieNoToolsFix v0.1.0

MelanieNoToolsFix.dll

Decompiled 19 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;

[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("MelanieNoToolsFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("MelanieNoToolsFix")]
[assembly: AssemblyTitle("MelanieNoToolsFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 MelanieNoToolsFix
{
	internal static class NoToolsRecipePatch
	{
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, MethodBase original)
		{
			List<CodeInstruction> list = instructions.ToList();
			List<int> list2 = new List<int>();
			MethodInfo method = typeof(string).GetMethod("Split", new Type[2]
			{
				typeof(char),
				typeof(StringSplitOptions)
			});
			if (method == null)
			{
				return list;
			}
			for (int i = 0; i + 4 < list.Count; i++)
			{
				if (LoadsInteger(list[i], 2) && list[i + 1].opcode == OpCodes.Ldelem_Ref && LoadsInteger(list[i + 2], 124) && LoadsInteger(list[i + 3], 0) && list[i + 4].opcode == OpCodes.Callvirt && method.Equals(list[i + 4].operand))
				{
					list2.Add(i + 3);
				}
			}
			string text = original.DeclaringType.FullName + "." + original.Name;
			if (list2.Count != 1)
			{
				Plugin.logger.LogError((object)(text + ": Erwartet wurde genau eine Werkzeug-Split-Stelle, gefunden: " + list2.Count + ". Keine Änderung vorgenommen."));
				return list;
			}
			int index = list2[0];
			list[index].opcode = OpCodes.Ldc_I4_1;
			list[index].operand = null;
			Plugin.logger.LogInfo((object)(text + ": Werkzeugfeld auf RemoveEmptyEntries umgestellt."));
			return list;
		}

		private static bool LoadsInteger(CodeInstruction instruction, int expected)
		{
			if (instruction.opcode == OpCodes.Ldc_I4_0)
			{
				return expected == 0;
			}
			if (instruction.opcode == OpCodes.Ldc_I4_1)
			{
				return expected == 1;
			}
			if (instruction.opcode == OpCodes.Ldc_I4_2)
			{
				return expected == 2;
			}
			if (instruction.opcode == OpCodes.Ldc_I4 || instruction.opcode == OpCodes.Ldc_I4_S)
			{
				return Convert.ToInt32(instruction.operand) == expected;
			}
			return false;
		}
	}
	[BepInPlugin("dev.chaosholz.melanienotoolsfix", "MelanieNoToolsFix", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "dev.chaosholz.melanienotoolsfix";

		private const string modName = "MelanieNoToolsFix";

		private const string modVersion = "0.1.0";

		private static readonly Harmony _harmony = new Harmony("dev.chaosholz.melanienotoolsfix");

		internal static readonly ManualLogSource logger = Logger.CreateLogSource("MelanieNoToolsFix");

		private void Awake()
		{
			logger.LogInfo((object)"Plugin MelanieNoToolsFix is loaded!");
			InstallPatch("MelMelCraft.HarmonyPatches");
			InstallPatch("MelanieMeliciousCooked.HarmonyPatches");
		}

		private void InstallPatch(string typeName)
		{
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			try
			{
				Type type = AccessTools.TypeByName(typeName);
				if (type == null)
				{
					logger.LogError((object)("Typ nicht gefunden: " + typeName));
					return;
				}
				MethodInfo[] array = (from method in type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
					where method.Name == "AddRecipe"
					select method).ToArray();
				if (array.Length != 1)
				{
					logger.LogError((object)(typeName + ": Erwartet wurde genau eine AddRecipe-Methode, gefunden: " + array.Length));
					return;
				}
				MethodInfo methodInfo = AccessTools.Method(typeof(NoToolsRecipePatch), "Transpiler", (Type[])null, (Type[])null);
				_harmony.Patch((MethodBase)array[0], (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(methodInfo), (HarmonyMethod)null, (HarmonyMethod)null);
				logger.LogInfo((object)("Patch-Verarbeitung abgeschlossen: " + typeName));
			}
			catch (Exception ex)
			{
				logger.LogError((object)("Patch fehlgeschlagen für " + typeName + "\n" + ex));
			}
		}
	}
}