Decompiled source of GrillspettAzuAutoStoreCompat v1.0.0

patchers\AzuAutoStoreCompat.Patcher.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("AzuAutoStoreCompat.Patcher")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AzuAutoStoreCompat.Patcher")]
[assembly: AssemblyTitle("AzuAutoStoreCompat.Patcher")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 KRINJUN.AzuAutoStoreCompat.Patcher
{
	public static class Patcher
	{
		private static readonly ManualLogSource Logger = Logger.CreateLogSource("GrillspettAzuAutoStoreCompat.Patcher");

		public static IEnumerable<string> TargetDLLs { get; } = new string[1] { "assembly_valheim.dll" };

		public static void Initialize()
		{
			Logger.LogInfo((object)"GrillspettAzuAutoStoreCompat.Patcher initialized.");
		}

		public static void Patch(AssemblyDefinition assembly)
		{
			try
			{
				PatchZRoutedRpc(assembly);
				PatchInventory(assembly);
				PatchInventoryGrid(assembly);
				PatchItemData(assembly);
				PatchConsoleCommand(assembly);
				PatchCharacter(assembly);
				PatchEffectList(assembly);
			}
			catch (Exception arg)
			{
				Logger.LogError((object)$"Failed during preloader patch: {arg}");
			}
		}

		private static void PatchZRoutedRpc(AssemblyDefinition assembly)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			TypeDefinition type = assembly.MainModule.GetType("ZRoutedRpc");
			if (type == null)
			{
				return;
			}
			FieldDefinition val = ((IEnumerable<FieldDefinition>)type.Fields).FirstOrDefault((Func<FieldDefinition, bool>)((FieldDefinition x) => ((MemberReference)x).Name == "Everybody"));
			if (val != null && val.IsLiteral)
			{
				val.Attributes = (FieldAttributes)(val.Attributes & 0xFFBF);
				val.Attributes = (FieldAttributes)(val.Attributes & 0x7FFF);
				val.Attributes = (FieldAttributes)(val.Attributes | 0x16);
				val.Constant = null;
				val.HasDefault = false;
				MethodDefinition val2 = ((IEnumerable<MethodDefinition>)type.Methods).FirstOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == ".cctor"));
				if (val2 != null && val2.HasBody)
				{
					ILProcessor iLProcessor = val2.Body.GetILProcessor();
					Instruction val3 = val2.Body.Instructions[0];
					iLProcessor.InsertBefore(val3, iLProcessor.Create(OpCodes.Ldc_I8, 0L));
					iLProcessor.InsertBefore(val3, iLProcessor.Create(OpCodes.Stsfld, (FieldReference)(object)val));
				}
				Logger.LogInfo((object)"Successfully patched ZRoutedRpc.Everybody from const literal to public static long.");
			}
		}

		private static void PatchInventory(AssemblyDefinition assembly)
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Expected O, but got Unknown
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Expected O, but got Unknown
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Expected O, but got Unknown
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			TypeDefinition type = assembly.MainModule.GetType("Inventory");
			if (type == null)
			{
				return;
			}
			if (!((IEnumerable<MethodDefinition>)type.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == "AddItem" && ((MethodReference)m).Parameters.Count == 4))
			{
				MethodDefinition val = ((IEnumerable<MethodDefinition>)type.Methods).FirstOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == "AddItem" && ((MethodReference)m).Parameters.Count == 5));
				if (val != null)
				{
					MethodDefinition val2 = new MethodDefinition("AddItem", (MethodAttributes)134, assembly.MainModule.TypeSystem.Boolean);
					((MethodReference)val2).Parameters.Add(new ParameterDefinition("item", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[0]).ParameterType));
					((MethodReference)val2).Parameters.Add(new ParameterDefinition("amount", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[1]).ParameterType));
					((MethodReference)val2).Parameters.Add(new ParameterDefinition("x", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[2]).ParameterType));
					((MethodReference)val2).Parameters.Add(new ParameterDefinition("y", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[3]).ParameterType));
					ILProcessor iLProcessor = val2.Body.GetILProcessor();
					iLProcessor.Emit(OpCodes.Ldarg_0);
					iLProcessor.Emit(OpCodes.Ldarg_1);
					iLProcessor.Emit(OpCodes.Ldarg_2);
					iLProcessor.Emit(OpCodes.Ldarg_3);
					iLProcessor.Emit(OpCodes.Ldarg_S, ((MethodReference)val2).Parameters[3]);
					iLProcessor.Emit(OpCodes.Ldc_I4_M1);
					iLProcessor.Emit(OpCodes.Callvirt, (MethodReference)(object)val);
					iLProcessor.Emit(OpCodes.Ret);
					type.Methods.Add(val2);
					Logger.LogInfo((object)"Successfully injected Inventory.AddItem(ItemData, int, int, int) bridge.");
				}
			}
			if (!((IEnumerable<MethodDefinition>)type.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == "Changed" && ((MethodReference)m).Parameters.Count == 0))
			{
				MethodDefinition val3 = ((IEnumerable<MethodDefinition>)type.Methods).FirstOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == "Changed" && ((MethodReference)m).Parameters.Count == 2));
				if (val3 != null)
				{
					MethodDefinition val4 = new MethodDefinition("Changed", (MethodAttributes)134, assembly.MainModule.TypeSystem.Void);
					ILProcessor iLProcessor2 = val4.Body.GetILProcessor();
					iLProcessor2.Emit(OpCodes.Ldarg_0);
					iLProcessor2.Emit(OpCodes.Ldc_I4_1);
					iLProcessor2.Emit(OpCodes.Ldc_I4_1);
					iLProcessor2.Emit(OpCodes.Callvirt, (MethodReference)(object)val3);
					iLProcessor2.Emit(OpCodes.Ret);
					type.Methods.Add(val4);
					Logger.LogInfo((object)"Successfully injected Inventory.Changed() bridge.");
				}
			}
		}

		private static void PatchInventoryGrid(AssemblyDefinition assembly)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			TypeDefinition type = assembly.MainModule.GetType("InventoryGrid");
			if (type != null && ((IEnumerable<TypeDefinition>)type.NestedTypes).FirstOrDefault((Func<TypeDefinition, bool>)((TypeDefinition t) => ((MemberReference)t).Name == "Element")) == null)
			{
				TypeDefinition val = new TypeDefinition("", "Element", (TypeAttributes)2, assembly.MainModule.TypeSystem.Object);
				type.NestedTypes.Add(val);
				Logger.LogInfo((object)"Successfully injected dummy nested class InventoryGrid/Element.");
			}
		}

		private static void PatchItemData(AssemblyDefinition assembly)
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Expected O, but got Unknown
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Expected O, but got Unknown
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Expected O, but got Unknown
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			TypeDefinition type = assembly.MainModule.GetType("ItemDrop/ItemData");
			if (type != null && !((IEnumerable<MethodDefinition>)type.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == "GetTooltip" && ((MethodReference)m).Parameters.Count == 5))
			{
				MethodDefinition val = ((IEnumerable<MethodDefinition>)type.Methods).FirstOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == "GetTooltip" && ((MethodReference)m).Parameters.Count == 6));
				if (val != null)
				{
					MethodDefinition val2 = new MethodDefinition("GetTooltip", (MethodAttributes)150, assembly.MainModule.TypeSystem.String);
					((MethodReference)val2).Parameters.Add(new ParameterDefinition("item", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[0]).ParameterType));
					((MethodReference)val2).Parameters.Add(new ParameterDefinition("qualityLevel", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[1]).ParameterType));
					((MethodReference)val2).Parameters.Add(new ParameterDefinition("crafting", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[2]).ParameterType));
					((MethodReference)val2).Parameters.Add(new ParameterDefinition("worldLevel", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[3]).ParameterType));
					((MethodReference)val2).Parameters.Add(new ParameterDefinition("stackOverride", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[4]).ParameterType));
					ILProcessor iLProcessor = val2.Body.GetILProcessor();
					iLProcessor.Emit(OpCodes.Ldarg_0);
					iLProcessor.Emit(OpCodes.Ldarg_1);
					iLProcessor.Emit(OpCodes.Ldarg_2);
					iLProcessor.Emit(OpCodes.Ldarg_3);
					iLProcessor.Emit(OpCodes.Ldarg_S, ((MethodReference)val2).Parameters[4]);
					iLProcessor.Emit(OpCodes.Ldc_I4_0);
					iLProcessor.Emit(OpCodes.Call, (MethodReference)(object)val);
					iLProcessor.Emit(OpCodes.Ret);
					type.Methods.Add(val2);
					Logger.LogInfo((object)"Successfully injected ItemDrop.ItemData.GetTooltip 5-param bridge.");
				}
			}
		}

		private static void PatchConsoleCommand(AssemblyDefinition assembly)
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Expected O, but got Unknown
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Expected O, but got Unknown
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Expected O, but got Unknown
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			TypeDefinition type = assembly.MainModule.GetType("Terminal/ConsoleCommand");
			if (type == null || ((IEnumerable<MethodDefinition>)type.Methods).Any((MethodDefinition m) => m.IsConstructor && ((MethodReference)m).Parameters.Count == 12))
			{
				return;
			}
			MethodDefinition val = ((IEnumerable<MethodDefinition>)type.Methods).FirstOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => m.IsConstructor && ((MethodReference)m).Parameters.Count == 13 && ((MemberReference)((ParameterReference)((MethodReference)m).Parameters[2]).ParameterType).Name == "ConsoleEvent"));
			if (val != null)
			{
				MethodDefinition val2 = new MethodDefinition(".ctor", (MethodAttributes)6278, assembly.MainModule.TypeSystem.Void);
				for (int num = 0; num < 8; num++)
				{
					((MethodReference)val2).Parameters.Add(new ParameterDefinition(((ParameterReference)((MethodReference)val).Parameters[num]).Name, (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[num]).ParameterType));
				}
				((MethodReference)val2).Parameters.Add(new ParameterDefinition("optionsFetcher", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[9]).ParameterType));
				((MethodReference)val2).Parameters.Add(new ParameterDefinition("alwaysRefreshTabOptions", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[10]).ParameterType));
				((MethodReference)val2).Parameters.Add(new ParameterDefinition("remoteCommand", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[11]).ParameterType));
				((MethodReference)val2).Parameters.Add(new ParameterDefinition("onlyAdmin", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[12]).ParameterType));
				ILProcessor iLProcessor = val2.Body.GetILProcessor();
				iLProcessor.Emit(OpCodes.Ldarg_0);
				iLProcessor.Emit(OpCodes.Ldarg_1);
				iLProcessor.Emit(OpCodes.Ldarg_2);
				iLProcessor.Emit(OpCodes.Ldarg_3);
				iLProcessor.Emit(OpCodes.Ldarg_S, ((MethodReference)val2).Parameters[3]);
				iLProcessor.Emit(OpCodes.Ldarg_S, ((MethodReference)val2).Parameters[4]);
				iLProcessor.Emit(OpCodes.Ldarg_S, ((MethodReference)val2).Parameters[5]);
				iLProcessor.Emit(OpCodes.Ldarg_S, ((MethodReference)val2).Parameters[6]);
				iLProcessor.Emit(OpCodes.Ldarg_S, ((MethodReference)val2).Parameters[7]);
				iLProcessor.Emit(OpCodes.Ldc_I4_0);
				iLProcessor.Emit(OpCodes.Ldarg_S, ((MethodReference)val2).Parameters[8]);
				iLProcessor.Emit(OpCodes.Ldarg_S, ((MethodReference)val2).Parameters[9]);
				iLProcessor.Emit(OpCodes.Ldarg_S, ((MethodReference)val2).Parameters[10]);
				iLProcessor.Emit(OpCodes.Ldarg_S, ((MethodReference)val2).Parameters[11]);
				iLProcessor.Emit(OpCodes.Call, (MethodReference)(object)val);
				iLProcessor.Emit(OpCodes.Ret);
				type.Methods.Add(val2);
				Logger.LogInfo((object)"Successfully injected Terminal.ConsoleCommand 12-param constructor bridge.");
			}
		}

		private static void PatchCharacter(AssemblyDefinition assembly)
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			TypeDefinition type = assembly.MainModule.GetType("Character");
			if (type == null || ((IEnumerable<MethodDefinition>)type.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == "Message" && ((MethodReference)m).Parameters.Count == 4))
			{
				return;
			}
			MethodDefinition val = ((IEnumerable<MethodDefinition>)type.Methods).FirstOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == "Message" && ((MethodReference)m).Parameters.Count == 5));
			if (val != null)
			{
				MethodDefinition val2 = new MethodDefinition("Message", (MethodAttributes)134, assembly.MainModule.TypeSystem.Void);
				for (int num = 0; num < 4; num++)
				{
					((MethodReference)val2).Parameters.Add(new ParameterDefinition(((ParameterReference)((MethodReference)val).Parameters[num]).Name, (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[num]).ParameterType));
				}
				ILProcessor iLProcessor = val2.Body.GetILProcessor();
				iLProcessor.Emit(OpCodes.Ldarg_0);
				iLProcessor.Emit(OpCodes.Ldarg_1);
				iLProcessor.Emit(OpCodes.Ldarg_2);
				iLProcessor.Emit(OpCodes.Ldarg_3);
				iLProcessor.Emit(OpCodes.Ldarg_S, ((MethodReference)val2).Parameters[3]);
				iLProcessor.Emit(OpCodes.Ldc_I4_1);
				iLProcessor.Emit(OpCodes.Callvirt, (MethodReference)(object)val);
				iLProcessor.Emit(OpCodes.Ret);
				type.Methods.Add(val2);
				Logger.LogInfo((object)"Successfully injected Character.Message 4-param bridge.");
			}
		}

		private static void PatchEffectList(AssemblyDefinition assembly)
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			TypeDefinition type = assembly.MainModule.GetType("EffectList");
			if (type == null || ((IEnumerable<MethodDefinition>)type.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == "Create" && ((MethodReference)m).Parameters.Count == 5))
			{
				return;
			}
			MethodDefinition val = ((IEnumerable<MethodDefinition>)type.Methods).FirstOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == "Create" && ((MethodReference)m).Parameters.Count == 6));
			if (val != null)
			{
				MethodDefinition val2 = new MethodDefinition("Create", (MethodAttributes)134, ((MethodReference)val).ReturnType);
				for (int num = 0; num < 5; num++)
				{
					((MethodReference)val2).Parameters.Add(new ParameterDefinition(((ParameterReference)((MethodReference)val).Parameters[num]).Name, (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[num]).ParameterType));
				}
				TypeDefinition type2 = assembly.MainModule.GetType("ZDOID");
				FieldDefinition val3 = ((type2 != null) ? ((IEnumerable<FieldDefinition>)type2.Fields).FirstOrDefault((Func<FieldDefinition, bool>)((FieldDefinition f) => ((MemberReference)f).Name == "None")) : null);
				ILProcessor iLProcessor = val2.Body.GetILProcessor();
				iLProcessor.Emit(OpCodes.Ldarg_0);
				iLProcessor.Emit(OpCodes.Ldarg_1);
				iLProcessor.Emit(OpCodes.Ldarg_2);
				iLProcessor.Emit(OpCodes.Ldarg_3);
				iLProcessor.Emit(OpCodes.Ldarg_S, ((MethodReference)val2).Parameters[3]);
				iLProcessor.Emit(OpCodes.Ldarg_S, ((MethodReference)val2).Parameters[4]);
				if (val3 != null)
				{
					iLProcessor.Emit(OpCodes.Ldsfld, (FieldReference)(object)val3);
				}
				else
				{
					iLProcessor.Emit(OpCodes.Ldc_I4_0);
				}
				iLProcessor.Emit(OpCodes.Callvirt, (MethodReference)(object)val);
				iLProcessor.Emit(OpCodes.Ret);
				type.Methods.Add(val2);
				Logger.LogInfo((object)"Successfully injected EffectList.Create 5-param bridge.");
			}
		}
	}
}

plugins\AzuAutoStoreCompat.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[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("AzuAutoStoreCompat")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AzuAutoStoreCompat")]
[assembly: AssemblyTitle("AzuAutoStoreCompat")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 KRINJUN.AzuAutoStoreCompat
{
	internal static class FavoriteIndicator
	{
		private const string MarkerName = "AzuAutoStoreCompatFavoriteMarker";

		private static MethodInfo _getPlayerConfigMethod;

		private static MethodInfo _isItemNameFavoritedMethod;

		private static MethodInfo _isSlotFavoritedMethod;

		private static ConfigEntry<Color> _borderColorFavoritedItem;

		private static ConfigEntry<Color> _borderColorFavoritedSlot;

		private static ConfigEntry<Color> _borderColorFavoritedItemOnFavoritedSlot;

		private static Sprite _borderSprite;

		private static bool _ready;

		internal static void Setup(Harmony harmony, ManualLogSource log)
		{
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Expected O, but got Unknown
			try
			{
				Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "AzuAutoStore");
				if (assembly == null)
				{
					log.LogWarning((object)"[AzuAutoStoreCompat] Favorite indicator: AzuAutoStore assembly not found.");
					return;
				}
				Type type = assembly.GetType("AzuAutoStore.Patches.Favoriting.UserConfig");
				Type type2 = assembly.GetType("AzuAutoStore.AzuAutoStorePlugin");
				if (type == null || type2 == null)
				{
					log.LogWarning((object)"[AzuAutoStoreCompat] Favorite indicator: could not locate UserConfig/AzuAutoStorePlugin types.");
					return;
				}
				_getPlayerConfigMethod = AccessTools.Method(type, "GetPlayerConfig", new Type[1] { typeof(long) }, (Type[])null);
				_isItemNameFavoritedMethod = AccessTools.Method(type, "IsItemNameFavorited", new Type[1] { typeof(SharedData) }, (Type[])null);
				_isSlotFavoritedMethod = AccessTools.Method(type, "IsSlotFavorited", new Type[1] { typeof(Vector2i) }, (Type[])null);
				_borderColorFavoritedItem = AccessTools.Field(type2, "BorderColorFavoritedItem")?.GetValue(null) as ConfigEntry<Color>;
				_borderColorFavoritedSlot = AccessTools.Field(type2, "BorderColorFavoritedSlot")?.GetValue(null) as ConfigEntry<Color>;
				_borderColorFavoritedItemOnFavoritedSlot = AccessTools.Field(type2, "BorderColorFavoritedItemOnFavoritedSlot")?.GetValue(null) as ConfigEntry<Color>;
				object? obj = AccessTools.Method(type2, "loadSprite", (Type[])null, (Type[])null)?.Invoke(null, new object[1] { "border.png" });
				_borderSprite = (Sprite)((obj is Sprite) ? obj : null);
				_ready = _getPlayerConfigMethod != null && _isItemNameFavoritedMethod != null && _isSlotFavoritedMethod != null && _borderColorFavoritedItem != null && _borderColorFavoritedSlot != null && _borderColorFavoritedItemOnFavoritedSlot != null;
				if (!_ready)
				{
					log.LogWarning((object)"[AzuAutoStoreCompat] Favorite indicator: one or more AzuAutoStore members were not found; feature disabled.");
					return;
				}
				MethodInfo methodInfo = AccessTools.Method(typeof(InventoryGrid), "UpdateGui", (Type[])null, (Type[])null);
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(FavoriteIndicator), "UpdateGuiPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				log.LogInfo((object)"[AzuAutoStoreCompat] Favorite indicator enabled (persistent marker on favorited items/slots).");
			}
			catch (Exception arg)
			{
				_ready = false;
				log.LogError((object)$"[AzuAutoStoreCompat] Error setting up favorite indicator: {arg}");
			}
		}

		private static void UpdateGuiPostfix(InventoryGrid __instance, Player player, Inventory ___m_inventory, List<InventoryElement> ___m_elements)
		{
			//IL_00ac: 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_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			if (!_ready)
			{
				return;
			}
			try
			{
				if ((Object)(object)player == (Object)null || ___m_inventory == null || ___m_elements == null || ((Humanoid)player).GetInventory() != ___m_inventory)
				{
					return;
				}
				object obj = _getPlayerConfigMethod.Invoke(null, new object[1] { player.GetPlayerID() });
				if (obj == null)
				{
					return;
				}
				int width = ___m_inventory.GetWidth();
				int height = ___m_inventory.GetHeight();
				if (width <= 0)
				{
					return;
				}
				for (int i = 0; i < height; i++)
				{
					for (int j = 0; j < width; j++)
					{
						InventoryElement val = ElementAt(___m_elements, j, i, width);
						if (!((Object)(object)val == (Object)null) && !((Object)(object)val.m_queued == (Object)null))
						{
							bool flag = (bool)_isSlotFavoritedMethod.Invoke(obj, new object[1] { (object)new Vector2i(j, i) });
							Image orCreateMarker = GetOrCreateMarker(val.m_queued);
							((Behaviour)orCreateMarker).enabled = flag;
							if (flag)
							{
								((Graphic)orCreateMarker).color = _borderColorFavoritedSlot.Value;
							}
						}
					}
				}
				foreach (ItemData allItem in ___m_inventory.GetAllItems())
				{
					if (allItem != null && allItem.m_shared != null && (bool)_isItemNameFavoritedMethod.Invoke(obj, new object[1] { allItem.m_shared }))
					{
						InventoryElement val2 = ElementAt(___m_elements, allItem.m_gridPos.x, allItem.m_gridPos.y, width);
						if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.m_queued == (Object)null))
						{
							Image orCreateMarker2 = GetOrCreateMarker(val2.m_queued);
							((Graphic)orCreateMarker2).color = (((Behaviour)orCreateMarker2).enabled ? _borderColorFavoritedItemOnFavoritedSlot.Value : _borderColorFavoritedItem.Value);
							((Behaviour)orCreateMarker2).enabled = true;
						}
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = AzuAutoStoreCompatPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("[AzuAutoStoreCompat] Error rendering favorite indicator: " + ex.Message));
				}
			}
		}

		private static InventoryElement ElementAt(List<InventoryElement> elements, int x, int y, int width)
		{
			int num = y * width + x;
			if (num < 0 || num >= elements.Count)
			{
				return null;
			}
			return elements[num];
		}

		private static Image GetOrCreateMarker(Image baseImg)
		{
			Image val = FindMarker(baseImg);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			Image val2 = Object.Instantiate<Image>(baseImg, ((Component)baseImg).transform);
			for (int num = ((Component)val2).transform.childCount - 1; num >= 0; num--)
			{
				Object.Destroy((Object)(object)((Component)((Component)val2).transform.GetChild(num)).gameObject);
			}
			((Object)val2).name = "AzuAutoStoreCompatFavoriteMarker";
			((Component)val2).transform.SetParent(((Component)baseImg).transform, false);
			((Graphic)val2).raycastTarget = false;
			if ((Object)(object)_borderSprite != (Object)null)
			{
				val2.sprite = _borderSprite;
			}
			((Behaviour)val2).enabled = false;
			return val2;
		}

		private static Image FindMarker(Image baseImg)
		{
			Transform transform = ((Component)baseImg).transform;
			for (int i = 0; i < transform.childCount; i++)
			{
				Transform child = transform.GetChild(i);
				if (((Object)child).name == "AzuAutoStoreCompatFavoriteMarker")
				{
					return ((Component)child).GetComponent<Image>();
				}
			}
			return null;
		}
	}
	[BepInPlugin("000_Grillspett.AzuAutoStoreCompat", "GrillspettAzuAutoStoreCompat", "1.0.0")]
	public class AzuAutoStoreCompatPlugin : BaseUnityPlugin
	{
		public const string ModGUID = "000_Grillspett.AzuAutoStoreCompat";

		public const string ModName = "GrillspettAzuAutoStoreCompat";

		public const string ModVersion = "1.0.0";

		private const string AzuAutoStoreGUID = "Azumatt.AzuAutoStore";

		private const string ExtraSlotsGUID = "shudnal.ExtraSlots";

		internal static ManualLogSource Log;

		private static Harmony _harmony;

		private static MethodInfo _extraSlotsGetAllItemsMethod;

		private static FieldInfo _storeShortcutField;

		private static MethodInfo _tryStoreMethod;

		private static FieldInfo _playerLocalPlayerField;

		private static MethodInfo _inventoryGuiIsVisibleMethod;

		private static MethodInfo _characterIsDeadMethod;

		private static MethodInfo _characterInCutsceneMethod;

		private static MethodInfo _characterIsTeleportingMethod;

		private static PropertyInfo _chatInstanceProp;

		private static MethodInfo _chatHasFocusMethod;

		private static MethodInfo _consoleIsVisibleMethod;

		private static MethodInfo _textInputIsVisibleMethod;

		private static MethodInfo _storeGuiIsVisibleMethod;

		private static MethodInfo _menuIsVisibleMethod;

		private static PropertyInfo _textViewerInstanceProp;

		private static MethodInfo _textViewerIsVisibleMethod;

		private static MethodInfo _minimapIsOpenMethod;

		private static MethodInfo _gameCameraInFreeFlyMethod;

		private static MethodInfo _barberGuiVisibleMethod;

		private static PropertyInfo _hudInstanceProp;

		private static FieldInfo _hudBuildUiField;

		private static PropertyInfo _buildUiSearchFieldFocusedProp;

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Expected O, but got Unknown
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("000_Grillspett.AzuAutoStoreCompat");
			Log.LogInfo((object)"AzuAutoStoreCompat initializing...");
			try
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(Harmony), "PatchAll", new Type[1] { typeof(Assembly) }, (Type[])null);
				if (methodInfo != null)
				{
					MethodInfo methodInfo2 = AccessTools.Method(typeof(AzuAutoStoreCompatPlugin), "PatchAllPrefix", (Type[])null, (Type[])null);
					_harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					Log.LogInfo((object)"Successfully hooked Harmony.PatchAll(Assembly) with selective patcher prefix.");
				}
				else
				{
					Log.LogError((object)"Could not find Harmony.PatchAll(Assembly) method to hook!");
				}
				MethodInfo methodInfo3 = AccessTools.Method(typeof(AccessTools), "DeclaredMethod", new Type[4]
				{
					typeof(Type),
					typeof(string),
					typeof(Type[]),
					typeof(Type[])
				}, (Type[])null);
				if (methodInfo3 != null)
				{
					MethodInfo methodInfo4 = AccessTools.Method(typeof(AzuAutoStoreCompatPlugin), "DeclaredMethodPrefix", (Type[])null, (Type[])null);
					_harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(methodInfo4), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					Log.LogInfo((object)"Successfully hooked AccessTools.DeclaredMethod to disambiguate legacy bridge overloads.");
				}
				MethodInfo methodInfo5 = AccessTools.Method(typeof(AccessTools), "Method", new Type[4]
				{
					typeof(Type),
					typeof(string),
					typeof(Type[]),
					typeof(Type[])
				}, (Type[])null);
				if (methodInfo5 != null)
				{
					MethodInfo methodInfo6 = AccessTools.Method(typeof(AzuAutoStoreCompatPlugin), "MethodPrefix", (Type[])null, (Type[])null);
					_harmony.Patch((MethodBase)methodInfo5, new HarmonyMethod(methodInfo6), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					Log.LogInfo((object)"Successfully hooked AccessTools.Method to disambiguate legacy bridge overloads.");
				}
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Error initializing AzuAutoStoreCompat: {arg}");
			}
		}

		private void Start()
		{
			try
			{
				SetupExtraSlotsQuickSlotBridge();
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Error setting up ExtraSlots quick-slot bridge: {arg}");
			}
			try
			{
				SetupStoreShortcutInventoryOpenBridge();
			}
			catch (Exception arg2)
			{
				Log.LogError((object)$"Error setting up store-shortcut-while-inventory-open bridge: {arg2}");
			}
			try
			{
				FavoriteIndicator.Setup(_harmony, Log);
			}
			catch (Exception arg3)
			{
				Log.LogError((object)$"Error setting up favorite indicator: {arg3}");
			}
		}

		private void SetupStoreShortcutInventoryOpenBridge()
		{
			//IL_0516: Unknown result type (might be due to invalid IL or missing references)
			//IL_0524: Expected O, but got Unknown
			Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "AzuAutoStore");
			Assembly valheimAssembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "assembly_valheim");
			if (assembly == null || valheimAssembly == null)
			{
				Log.LogWarning((object)"[AzuAutoStoreCompat] Store-shortcut-while-inventory-open bridge: could not locate AzuAutoStore/assembly_valheim.");
				return;
			}
			Type type = assembly.GetType("AzuAutoStore.AzuAutoStorePlugin");
			Type type2 = assembly.GetType("AzuAutoStore.Util.Functions");
			if (type == null || type2 == null)
			{
				Log.LogWarning((object)"[AzuAutoStoreCompat] Store-shortcut-while-inventory-open bridge: could not locate AzuAutoStorePlugin/Functions types.");
				return;
			}
			_storeShortcutField = AccessTools.Field(type, "_storeShortcut");
			_tryStoreMethod = AccessTools.Method(type2, "TryStore", Type.EmptyTypes, (Type[])null);
			MethodInfo methodInfo = AccessTools.Method(type, "Update", (Type[])null, (Type[])null);
			Type type3 = Get("Chat");
			Type type4 = Get("Console");
			Type type5 = Get("TextInput");
			Type type6 = Get("StoreGui");
			Type type7 = Get("Menu");
			Type type8 = Get("TextViewer");
			Type type9 = Get("Minimap");
			Type type10 = Get("GameCamera");
			Type type11 = Get("PlayerCustomizaton");
			Type type12 = Get("Hud");
			Type type13 = Get("BuildUi");
			Type type14 = Get("Character");
			Type type15 = Get("InventoryGui");
			Type type16 = Get("Player");
			_chatInstanceProp = type3?.GetProperty("instance", BindingFlags.Static | BindingFlags.Public);
			_chatHasFocusMethod = type3?.GetMethod("HasFocus", BindingFlags.Instance | BindingFlags.Public);
			_consoleIsVisibleMethod = type4?.GetMethod("IsVisible", BindingFlags.Static | BindingFlags.Public);
			_textInputIsVisibleMethod = type5?.GetMethod("IsVisible", BindingFlags.Static | BindingFlags.Public);
			_storeGuiIsVisibleMethod = type6?.GetMethod("IsVisible", BindingFlags.Static | BindingFlags.Public);
			_menuIsVisibleMethod = type7?.GetMethod("IsVisible", BindingFlags.Static | BindingFlags.Public);
			_textViewerInstanceProp = type8?.GetProperty("instance", BindingFlags.Static | BindingFlags.Public);
			_textViewerIsVisibleMethod = type8?.GetMethod("IsVisible", BindingFlags.Instance | BindingFlags.Public);
			_minimapIsOpenMethod = type9?.GetMethod("IsOpen", BindingFlags.Static | BindingFlags.Public);
			_gameCameraInFreeFlyMethod = type10?.GetMethod("InFreeFly", BindingFlags.Static | BindingFlags.Public);
			_barberGuiVisibleMethod = type11?.GetMethod("IsBarberGuiVisible", BindingFlags.Static | BindingFlags.Public);
			_hudInstanceProp = type12?.GetProperty("instance", BindingFlags.Static | BindingFlags.Public);
			_hudBuildUiField = type12?.GetField("m_buildUi", BindingFlags.Instance | BindingFlags.Public);
			_buildUiSearchFieldFocusedProp = type13?.GetProperty("SearchFieldFocused", BindingFlags.Instance | BindingFlags.Public);
			_characterIsDeadMethod = type14?.GetMethod("IsDead", BindingFlags.Instance | BindingFlags.Public);
			_characterInCutsceneMethod = type14?.GetMethod("InCutscene", BindingFlags.Instance | BindingFlags.Public);
			_characterIsTeleportingMethod = type14?.GetMethod("IsTeleporting", BindingFlags.Instance | BindingFlags.Public);
			_inventoryGuiIsVisibleMethod = type15?.GetMethod("IsVisible", BindingFlags.Static | BindingFlags.Public);
			_playerLocalPlayerField = type16?.GetField("m_localPlayer", BindingFlags.Static | BindingFlags.Public);
			if (!(_storeShortcutField != null) || !(_tryStoreMethod != null) || !(methodInfo != null) || !(_chatInstanceProp != null) || !(_chatHasFocusMethod != null) || !(_consoleIsVisibleMethod != null) || !(_textInputIsVisibleMethod != null) || !(_storeGuiIsVisibleMethod != null) || !(_menuIsVisibleMethod != null) || !(_textViewerInstanceProp != null) || !(_textViewerIsVisibleMethod != null) || !(_minimapIsOpenMethod != null) || !(_gameCameraInFreeFlyMethod != null) || !(_barberGuiVisibleMethod != null) || !(_hudInstanceProp != null) || !(_hudBuildUiField != null) || !(_buildUiSearchFieldFocusedProp != null) || !(_characterIsDeadMethod != null) || !(_characterInCutsceneMethod != null) || !(_characterIsTeleportingMethod != null) || !(_inventoryGuiIsVisibleMethod != null) || !(_playerLocalPlayerField != null))
			{
				Log.LogWarning((object)"[AzuAutoStoreCompat] Store-shortcut-while-inventory-open bridge: one or more game API members were not found; feature disabled.");
				return;
			}
			_harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(AccessTools.Method(typeof(AzuAutoStoreCompatPlugin), "StoreShortcutUpdatePrefix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			Log.LogInfo((object)"[AzuAutoStoreCompat] Bridged AzuAutoStore's Store Shortcut to also fire while the inventory/a container is open.");
			Type Get(string name)
			{
				return valheimAssembly.GetType(name);
			}
		}

		public static void StoreShortcutUpdatePrefix()
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				object value = _playerLocalPlayerField.GetValue(null);
				if (value == null || !(bool)_inventoryGuiIsVisibleMethod.Invoke(null, null) || IsAnyNonInventoryUiBlocking())
				{
					return;
				}
				bool num = (bool)_characterIsDeadMethod.Invoke(value, null);
				bool flag = (bool)_characterInCutsceneMethod.Invoke(value, null);
				bool flag2 = (bool)_characterIsTeleportingMethod.Invoke(value, null);
				if (!(num || flag || flag2) && _storeShortcutField.GetValue(null) is ConfigEntry<KeyboardShortcut> val)
				{
					KeyboardShortcut value2 = val.Value;
					if (((KeyboardShortcut)(ref value2)).IsDown())
					{
						_tryStoreMethod.Invoke(null, null);
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Log;
				if (log != null)
				{
					log.LogWarning((object)("[AzuAutoStoreCompat] Error in store-shortcut-while-inventory-open bridge: " + ex.Message));
				}
			}
		}

		private static bool IsAnyNonInventoryUiBlocking()
		{
			object value = _chatInstanceProp.GetValue(null);
			if (value != null && (bool)_chatHasFocusMethod.Invoke(value, null))
			{
				return true;
			}
			if ((bool)_consoleIsVisibleMethod.Invoke(null, null))
			{
				return true;
			}
			if ((bool)_textInputIsVisibleMethod.Invoke(null, null))
			{
				return true;
			}
			if ((bool)_storeGuiIsVisibleMethod.Invoke(null, null))
			{
				return true;
			}
			if ((bool)_menuIsVisibleMethod.Invoke(null, null))
			{
				return true;
			}
			object value2 = _textViewerInstanceProp.GetValue(null);
			if (value2 != null && (bool)_textViewerIsVisibleMethod.Invoke(value2, null))
			{
				return true;
			}
			if ((bool)_minimapIsOpenMethod.Invoke(null, null))
			{
				return true;
			}
			if ((bool)_gameCameraInFreeFlyMethod.Invoke(null, null))
			{
				return true;
			}
			if ((bool)_barberGuiVisibleMethod.Invoke(null, null))
			{
				return true;
			}
			object value3 = _hudInstanceProp.GetValue(null);
			if (value3 != null)
			{
				object value4 = _hudBuildUiField.GetValue(value3);
				if (value4 != null && (bool)_buildUiSearchFieldFocusedProp.GetValue(value4))
				{
					return true;
				}
			}
			return false;
		}

		private void SetupExtraSlotsQuickSlotBridge()
		{
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Expected O, but got Unknown
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Expected O, but got Unknown
			bool flag = Chainloader.PluginInfos.ContainsKey("Azumatt.AzuAutoStore");
			bool flag2 = Chainloader.PluginInfos.ContainsKey("shudnal.ExtraSlots");
			if (!flag || !flag2)
			{
				Log.LogInfo((object)$"[AzuAutoStoreCompat] ExtraSlots bridge: skipped (AzuAutoStore loaded={flag}, ExtraSlots loaded={flag2}).");
				return;
			}
			Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "AzuAutoStore");
			Assembly assembly2 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "ExtraSlots");
			if (assembly == null || assembly2 == null)
			{
				Log.LogWarning((object)"[AzuAutoStoreCompat] ExtraSlots bridge: could not locate AzuAutoStore/ExtraSlots assemblies.");
				return;
			}
			Type type = assembly.GetType("AzuExtendedPlayerInventory.API");
			Type type2 = assembly2.GetType("ExtraSlots.API");
			if (type == null || type2 == null)
			{
				Log.LogWarning((object)"[AzuAutoStoreCompat] ExtraSlots bridge: could not locate AzuExtendedPlayerInventory.API / ExtraSlots.API types.");
				return;
			}
			MethodInfo methodInfo = AccessTools.Method(type, "IsLoaded", Type.EmptyTypes, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(type, "GetQuickSlotsItems", Type.EmptyTypes, (Type[])null);
			_extraSlotsGetAllItemsMethod = AccessTools.Method(type2, "GetAllExtraSlotsItems", Type.EmptyTypes, (Type[])null);
			if (methodInfo == null || methodInfo2 == null || _extraSlotsGetAllItemsMethod == null)
			{
				Log.LogWarning((object)"[AzuAutoStoreCompat] ExtraSlots bridge: could not locate IsLoaded/GetQuickSlotsItems/GetAllExtraSlotsItems methods.");
				return;
			}
			_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(AzuAutoStoreCompatPlugin), "IsLoadedPostfix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			_harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(AzuAutoStoreCompatPlugin), "GetQuickSlotsItemsPostfix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			Log.LogInfo((object)"[AzuAutoStoreCompat] Bridged ExtraSlots food/ammo/quick/misc slots into AzuAutoStore's quick-slot exclusion. AutoStore will no longer pull items out of those slots.");
		}

		public static void IsLoadedPostfix(ref bool __result)
		{
			__result = true;
		}

		public static void GetQuickSlotsItemsPostfix(ref object __result)
		{
			try
			{
				if (!(__result is IList list) || !(_extraSlotsGetAllItemsMethod != null) || !(_extraSlotsGetAllItemsMethod.Invoke(null, null) is IList list2))
				{
					return;
				}
				foreach (object item in list2)
				{
					list.Add(item);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Log;
				if (log != null)
				{
					log.LogWarning((object)("[AzuAutoStoreCompat] Error bridging ExtraSlots items into AzuAutoStore's quick-slot filter: " + ex.Message));
				}
			}
		}

		private static MethodInfo RedirectGetTooltipTo6Param(Type itemDataType)
		{
			return itemDataType.GetMethods(AccessTools.all).FirstOrDefault((MethodInfo x) => x.Name == "GetTooltip" && x.GetParameters().Length == 6);
		}

		public static bool DeclaredMethodPrefix(Type type, string name, Type[] parameters, Type[] generics, ref MethodInfo __result)
		{
			if (type != null && type.Name == "ItemData" && name == "GetTooltip" && parameters != null && parameters.Length == 5)
			{
				MethodInfo methodInfo = RedirectGetTooltipTo6Param(type);
				if (methodInfo != null)
				{
					__result = methodInfo;
					return false;
				}
			}
			if (parameters == null && type != null && !string.IsNullOrEmpty(name))
			{
				if (type.Name == "Inventory" && name == "Changed")
				{
					MethodInfo methodInfo2 = type.GetMethods(AccessTools.allDeclared).FirstOrDefault((MethodInfo x) => x.Name == "Changed" && x.GetParameters().Length == 2);
					if (methodInfo2 != null)
					{
						__result = methodInfo2;
						return false;
					}
				}
				if (type.Name == "Character" && name == "Message")
				{
					MethodInfo methodInfo3 = type.GetMethods(AccessTools.allDeclared).FirstOrDefault((MethodInfo x) => x.Name == "Message" && x.GetParameters().Length == 5);
					if (methodInfo3 != null)
					{
						__result = methodInfo3;
						return false;
					}
				}
				if (type.Name == "EffectList" && name == "Create")
				{
					MethodInfo methodInfo4 = type.GetMethods(AccessTools.allDeclared).FirstOrDefault((MethodInfo x) => x.Name == "Create" && x.GetParameters().Length == 6);
					if (methodInfo4 != null)
					{
						__result = methodInfo4;
						return false;
					}
				}
				if (type.Name == "InventoryGrid" && name == "OnRightClick")
				{
					MethodInfo methodInfo5 = type.GetMethods(AccessTools.allDeclared).FirstOrDefault((MethodInfo x) => x.Name == "OnRightDown");
					if (methodInfo5 != null)
					{
						__result = methodInfo5;
						return false;
					}
				}
				if (type.Name == "InventoryGrid" && name == "OnLeftClick")
				{
					MethodInfo methodInfo6 = type.GetMethods(AccessTools.allDeclared).FirstOrDefault((MethodInfo x) => x.Name == "OnLeftDown");
					if (methodInfo6 != null)
					{
						__result = methodInfo6;
						return false;
					}
				}
				try
				{
					type.GetMethod(name, AccessTools.allDeclared);
				}
				catch (AmbiguousMatchException)
				{
					MethodInfo methodInfo7 = (from m in type.GetMethods(AccessTools.allDeclared)
						where m.Name == name
						orderby m.GetParameters().Length descending
						select m).FirstOrDefault();
					if (methodInfo7 != null)
					{
						if (generics != null && generics.Length != 0 && methodInfo7.IsGenericMethodDefinition)
						{
							methodInfo7 = methodInfo7.MakeGenericMethod(generics);
						}
						__result = methodInfo7;
						ManualLogSource log = Log;
						if (log != null)
						{
							log.LogWarning((object)$"[AzuAutoStoreCompat] Disambiguated DeclaredMethod {type.Name}.{name} -> {methodInfo7}");
						}
						return false;
					}
				}
			}
			return true;
		}

		public static bool MethodPrefix(Type type, string name, Type[] parameters, Type[] generics, ref MethodInfo __result)
		{
			if (type != null && type.Name == "ItemData" && name == "GetTooltip" && parameters != null && parameters.Length == 5)
			{
				MethodInfo methodInfo = RedirectGetTooltipTo6Param(type);
				if (methodInfo != null)
				{
					__result = methodInfo;
					return false;
				}
			}
			if (parameters == null && type != null && !string.IsNullOrEmpty(name))
			{
				if (type.Name == "Inventory" && name == "Changed")
				{
					MethodInfo methodInfo2 = type.GetMethods(AccessTools.all).FirstOrDefault((MethodInfo x) => x.Name == "Changed" && x.GetParameters().Length == 2);
					if (methodInfo2 != null)
					{
						__result = methodInfo2;
						return false;
					}
				}
				if (type.Name == "Character" && name == "Message")
				{
					MethodInfo methodInfo3 = type.GetMethods(AccessTools.all).FirstOrDefault((MethodInfo x) => x.Name == "Message" && x.GetParameters().Length == 5);
					if (methodInfo3 != null)
					{
						__result = methodInfo3;
						return false;
					}
				}
				if (type.Name == "EffectList" && name == "Create")
				{
					MethodInfo methodInfo4 = type.GetMethods(AccessTools.all).FirstOrDefault((MethodInfo x) => x.Name == "Create" && x.GetParameters().Length == 6);
					if (methodInfo4 != null)
					{
						__result = methodInfo4;
						return false;
					}
				}
				if (type.Name == "InventoryGrid" && name == "OnRightClick")
				{
					MethodInfo methodInfo5 = type.GetMethods(AccessTools.all).FirstOrDefault((MethodInfo x) => x.Name == "OnRightDown");
					if (methodInfo5 != null)
					{
						__result = methodInfo5;
						return false;
					}
				}
				if (type.Name == "InventoryGrid" && name == "OnLeftClick")
				{
					MethodInfo methodInfo6 = type.GetMethods(AccessTools.all).FirstOrDefault((MethodInfo x) => x.Name == "OnLeftDown");
					if (methodInfo6 != null)
					{
						__result = methodInfo6;
						return false;
					}
				}
				try
				{
					type.GetMethod(name, AccessTools.all);
				}
				catch (AmbiguousMatchException)
				{
					MethodInfo methodInfo7 = (from m in type.GetMethods(AccessTools.all)
						where m.Name == name
						orderby m.GetParameters().Length descending
						select m).FirstOrDefault();
					if (methodInfo7 != null)
					{
						if (generics != null && generics.Length != 0 && methodInfo7.IsGenericMethodDefinition)
						{
							methodInfo7 = methodInfo7.MakeGenericMethod(generics);
						}
						__result = methodInfo7;
						ManualLogSource log = Log;
						if (log != null)
						{
							log.LogWarning((object)$"[AzuAutoStoreCompat] Disambiguated Method {type.Name}.{name} -> {methodInfo7}");
						}
						return false;
					}
				}
			}
			return true;
		}

		public static bool PatchAllPrefix(Harmony __instance, Assembly assembly)
		{
			if (assembly != null && assembly.GetName().Name == "AzuAutoStore")
			{
				SafePatchAll(__instance, assembly);
				return false;
			}
			return true;
		}

		public static void SafePatchAll(Harmony harmony, Assembly assembly)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			Log.LogInfo((object)("[AzuAutoStoreCompat] Intercepted PatchAll for " + assembly.GetName().Name + ". Performing safe selective patching..."));
			try
			{
				Type type = assembly.GetType("AzuAutoStore.AzuAutoStorePlugin");
				if (type != null)
				{
					MethodInfo methodInfo = AccessTools.Method(type, "Start", (Type[])null, (Type[])null);
					if (methodInfo != null)
					{
						MethodInfo methodInfo2 = AccessTools.Method(typeof(AzuAutoStoreCompatPlugin), "StartPrefix", (Type[])null, (Type[])null);
						harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						Log.LogInfo((object)"[AzuAutoStoreCompat] Hooked AzuAutoStorePlugin.Start() with safe prefix.");
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[AzuAutoStoreCompat] Could not hook AzuAutoStorePlugin.Start(): " + ex.Message));
			}
			Type[] array;
			try
			{
				array = assembly.GetTypes();
			}
			catch (ReflectionTypeLoadException ex2)
			{
				array = ex2.Types.Where((Type t) => t != null).ToArray();
			}
			int num = 0;
			int num2 = 0;
			Type[] array2 = array;
			foreach (Type type2 in array2)
			{
				if (type2.FullName == "AzuAutoStore.Patches.Favoriting.BorderRenderer" || type2.FullName == "AzuAutoStore.Patches.InventoryGridGetHoveredElementPatch")
				{
					Log.LogInfo((object)("[AzuAutoStoreCompat] Skipping known-broken patch type: " + type2.FullName));
					num2++;
					continue;
				}
				if (type2.Namespace != null && type2.Namespace.StartsWith("AzuAutoStore.APIs.MUC.MUCSrc.Patches"))
				{
					Log.LogInfo((object)("[AzuAutoStoreCompat] Skipping MUC patch type: " + type2.FullName));
					num2++;
					continue;
				}
				try
				{
					List<MethodInfo> list = harmony.CreateClassProcessor(type2).Patch();
					if (list != null && list.Count > 0)
					{
						Log.LogInfo((object)$"[AzuAutoStoreCompat] Successfully patched: {type2.FullName} ({list.Count} methods)");
						num++;
					}
				}
				catch (Exception ex3)
				{
					Log.LogWarning((object)("[AzuAutoStoreCompat] Skipped type " + type2.FullName + " (" + ex3.Message + ")"));
					num2++;
				}
			}
			Log.LogInfo((object)$"[AzuAutoStoreCompat] SafePatchAll finished. Successfully patched: {num}, Skipped: {num2}");
		}

		public static bool StartPrefix(object __instance)
		{
			try
			{
				FieldInfo fieldInfo = AccessTools.Field(__instance.GetType(), "BackpacksIsLoaded");
				if (fieldInfo != null)
				{
					bool flag = Chainloader.PluginInfos != null && Chainloader.PluginInfos.ContainsKey("org.bepinex.plugins.backpacks");
					fieldInfo.SetValue(null, flag);
				}
				Type type = AccessTools.TypeByName("AzuAutoStore.APIs.MUC.MUCCompat");
				if (type != null)
				{
					AccessTools.Method(type, "ForceEnableMUC", (Type[])null, (Type[])null)?.Invoke(null, new object[1] { true });
				}
				Log.LogInfo((object)"[AzuAutoStoreCompat] Executed safe Start() for AzuAutoStore (skipped broken Favoriting border initialization).");
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"[AzuAutoStoreCompat] Error in StartPrefix: {arg}");
			}
			return false;
		}
	}
}