Decompiled source of TripleInfusion v1.1.0

plugins/TripleInfusion.dll

Decompiled 8 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("TripleInfusion")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+293502ee6fdc8d4f5e549e50101d34c524a3d1e1")]
[assembly: AssemblyProduct("TripleInfusion")]
[assembly: AssemblyTitle("TripleInfusion")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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 TripleInfusion
{
	[HarmonyPatch]
	internal static class HostSettings
	{
		private const string MessageName = "girthy_mods.TripleInfusion.Settings";

		private static HandleNamedMessageDelegate handler;

		private static Dictionary<string, string> synced;

		internal static bool Enabled
		{
			get
			{
				if (synced == null || !synced.TryGetValue("Enabled", out var value) || !bool.TryParse(value, out var result))
				{
					return Plugin.Enabled.Value;
				}
				return result;
			}
		}

		internal static int SpellLevel => Int("SpellLevel", Plugin.ThirdInfusionLevel.Value);

		internal static bool AllowRepeat
		{
			get
			{
				if (synced == null || !synced.TryGetValue("AllowRepeat", out var value) || !bool.TryParse(value, out var result))
				{
					return Plugin.AllowRepeatElements.Value;
				}
				return result;
			}
		}

		internal static int Choices => Int("Choices", Plugin.Choices.Value);

		private static int Int(string key, int local)
		{
			if (synced == null || !synced.TryGetValue(key, out var value) || !int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result))
			{
				return local;
			}
			return result;
		}

		[HarmonyPatch(typeof(RunManager), "OnNetworkSpawn")]
		[HarmonyPostfix]
		private static void Listen()
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			try
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if (!((Object)(object)singleton == (Object)null) && !singleton.IsServer && singleton.CustomMessagingManager != null)
				{
					if (handler == null)
					{
						handler = DelegateSupport.ConvertDelegate<HandleNamedMessageDelegate>((Delegate)new Action<ulong, FastBufferReader>(OnReceived));
					}
					singleton.CustomMessagingManager.RegisterNamedMessageHandler("girthy_mods.TripleInfusion.Settings", handler);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(24, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Host settings (listen): ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log.LogError(val);
			}
		}

		private static void OnReceived(ulong sender, FastBufferReader reader)
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				string text = default(string);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref text, false);
				Dictionary<string, string> dictionary = new Dictionary<string, string>();
				string[] array = text.Split(';');
				foreach (string text2 in array)
				{
					int num = text2.IndexOf('=');
					if (num > 0)
					{
						dictionary[text2.Substring(0, num)] = text2.Substring(num + 1);
					}
				}
				synced = dictionary;
				ManualLogSource log = Plugin.Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(42, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Using the host's third-infusion settings: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
				}
				log.LogInfo(val);
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = Plugin.Log;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(25, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Host settings (receive): ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
				}
				log2.LogError(val2);
			}
		}

		[HarmonyPatch(typeof(RunManager), "StartRunOnServerRpc")]
		[HarmonyPrefix]
		private static void StartRun_Prefix(RunManager __instance, out bool __state)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			__state = false;
			try
			{
				__state = (int)((NetworkBehaviour)__instance).__rpc_exec_stage == 1;
			}
			catch
			{
			}
		}

		[HarmonyPatch(typeof(RunManager), "StartRunOnServerRpc")]
		[HarmonyPostfix]
		private static void StartRun_Postfix(bool __state)
		{
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			if (!__state)
			{
				return;
			}
			bool value = default(bool);
			try
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if ((Object)(object)singleton == (Object)null || !singleton.IsServer || singleton.CustomMessagingManager == null)
				{
					return;
				}
				CultureInfo invariantCulture = CultureInfo.InvariantCulture;
				string[] array = new string[4];
				value = Plugin.Enabled.Value;
				array[0] = "Enabled=" + value;
				array[1] = "SpellLevel=" + Plugin.ThirdInfusionLevel.Value.ToString(invariantCulture);
				value = Plugin.AllowRepeatElements.Value;
				array[2] = "AllowRepeat=" + value;
				array[3] = "Choices=" + Plugin.Choices.Value.ToString(invariantCulture);
				string text = string.Join(";", array);
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(Encoding.UTF8.GetByteCount(text) * 2 + 64, (Allocator)2, -1);
				try
				{
					((FastBufferWriter)(ref val)).WriteValueSafe(text, false);
					singleton.CustomMessagingManager.SendNamedMessageToAll("girthy_mods.TripleInfusion.Settings", val, (NetworkDelivery)4);
				}
				finally
				{
					((FastBufferWriter)(ref val)).Dispose();
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(22, 1, ref value);
				if (value)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Host settings (send): ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
				}
				log.LogError(val2);
			}
		}

		[HarmonyPatch(typeof(RunManager), "OnDestroy")]
		[HarmonyPostfix]
		private static void Clear()
		{
			synced = null;
		}
	}
	[HarmonyPatch]
	internal static class InfusionPatches
	{
		private static readonly Dictionary<(ulong client, SpellType spell), ElementType> third = new Dictionary<(ulong, SpellType), ElementType>();

		private static readonly HashSet<SpellType> pending = new HashSet<SpellType>();

		private static List<StoreItem> allInfusionItems;

		private static PlayerStats localStats;

		private static readonly ElementType[] CoreElements;

		[ThreadStatic]
		private static bool combining;

		private static readonly Dictionary<ElementType, List<ElementType>> coreCache;

		[ThreadStatic]
		private static bool applyingThird;

		private static PlayerStats LocalStats
		{
			get
			{
				if ((Object)(object)localStats != (Object)null && !((Il2CppObjectBase)localStats).WasCollected)
				{
					return localStats;
				}
				localStats = null;
				try
				{
					NetworkManager singleton = NetworkManager.Singleton;
					bool flag = (Object)(object)singleton == (Object)null || !singleton.IsListening;
					foreach (PlayerStats item in Object.FindObjectsOfType<PlayerStats>())
					{
						if ((Object)(object)item != (Object)null && (((NetworkBehaviour)item).IsOwner || flag))
						{
							localStats = item;
							break;
						}
					}
				}
				catch
				{
				}
				return localStats;
			}
		}

		private static ulong LocalClientId
		{
			get
			{
				try
				{
					NetworkManager singleton = NetworkManager.Singleton;
					return (singleton != null) ? singleton.LocalClientId : 0;
				}
				catch
				{
					return 0uL;
				}
			}
		}

		private static int CoreCount(ElementType element)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			if ((int)element == 0)
			{
				return 0;
			}
			try
			{
				return ElementCombiner.GetCoreElements(element)?.Count ?? 0;
			}
			catch
			{
				return 0;
			}
		}

		private static List<ElementType> Cores(ElementType element)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			List<ElementType> list = new List<ElementType>();
			try
			{
				List<ElementType> coreElements = ElementCombiner.GetCoreElements(element);
				if (coreElements != null)
				{
					for (int i = 0; i < coreElements.Count; i++)
					{
						list.Add(coreElements[i]);
					}
				}
			}
			catch
			{
			}
			return list;
		}

		internal static bool TryGetThird(ulong client, SpellType spell, out ElementType element)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return third.TryGetValue((client, spell), out element);
		}

		[HarmonyPatch(typeof(InfusionStoreAvailabilityChecker), "InfusionStoreShouldBeOffered")]
		[HarmonyPostfix]
		private static void ShouldOffer_Postfix(SpellType spell, int spellLevel, ref bool __result)
		{
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			if (__result || !HostSettings.Enabled || spellLevel < HostSettings.SpellLevel)
			{
				return;
			}
			bool flag = default(bool);
			try
			{
				PlayerStats val = LocalStats;
				if (!((Object)(object)val == (Object)null) && CoreCount(val.GetElement(spell)) >= 2 && !third.ContainsKey((LocalClientId, spell)) && !pending.Contains(spell))
				{
					pending.Add(spell);
					__result = true;
					ManualLogSource log = Plugin.Log;
					BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(37, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Third infusion offered for ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<SpellType>(spell);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" (level ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(spellLevel);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(").");
					}
					log.LogInfo(val2);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = Plugin.Log;
				BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(7, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Offer: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Exception>(ex);
				}
				log2.LogError(val3);
			}
		}

		[HarmonyPatch(typeof(StoreItemDatabase), "GetSpellInfusionItems")]
		[HarmonyPostfix]
		private static void CacheInfusionItems(List<StoreItem> __result)
		{
			if (__result != null && __result.Count > 0)
			{
				allInfusionItems = __result;
			}
		}

		[HarmonyPatch(typeof(InfusionInventoryGenerator), "Generate")]
		[HarmonyPostfix]
		private static void Generate_Postfix(InfusionInventoryGenerator __instance, ref List<StoreItem> __result)
		{
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Expected O, but got Unknown
			//IL_01b0: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: 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_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			if (!HostSettings.Enabled)
			{
				return;
			}
			bool flag = default(bool);
			try
			{
				if (!Raw.TryGetNullable4<InfusionInventoryGenerator>(__instance, "spell", out int bits))
				{
					return;
				}
				SpellType val = (SpellType)bits;
				if (!pending.Contains(val))
				{
					return;
				}
				PlayerStats val2 = LocalStats;
				if ((Object)(object)val2 == (Object)null || allInfusionItems == null)
				{
					return;
				}
				List<ElementType> list = Cores(val2.GetElement(val));
				if (list.Count < 2)
				{
					return;
				}
				Dictionary<ElementType, bool> elementUnlockMap = __instance.elementUnlockMap;
				List<StoreItem> list2 = new List<StoreItem>();
				for (int i = 0; i < allInfusionItems.Count; i++)
				{
					StoreItem obj = allInfusionItems[i];
					SpellInfusionItem val3 = ((obj != null) ? ((Il2CppObjectBase)obj).TryCast<SpellInfusionItem>() : null);
					if (val3 != null && !((Object)(object)val3.Configuration == (Object)null) && val3.Configuration.SpellType == val)
					{
						ElementType e = val3.Element;
						if (Array.IndexOf(CoreElements, e) >= 0 && (HostSettings.AllowRepeat || !list.Contains(e)) && (elementUnlockMap == null || !elementUnlockMap.ContainsKey(e) || elementUnlockMap[e]) && !list2.Exists((StoreItem o) => ((Il2CppObjectBase)o).TryCast<SpellInfusionItem>().Element == e))
						{
							list2.Add(allInfusionItems[i]);
						}
					}
				}
				if (list2.Count == 0)
				{
					ManualLogSource log = Plugin.Log;
					BepInExWarningLogInterpolatedStringHandler val4 = new BepInExWarningLogInterpolatedStringHandler(70, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Third infusion for ");
						((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<SpellType>(val);
						((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(": no infusion items found, keeping the game's shop.");
					}
					log.LogWarning(val4);
					pending.Remove(val);
					return;
				}
				for (int num = list2.Count - 1; num > 0; num--)
				{
					int num2 = Random.Range(0, num + 1);
					List<StoreItem> list3 = list2;
					int index = num;
					int index2 = num2;
					StoreItem value = list2[num2];
					StoreItem value2 = list2[num];
					list3[index] = value;
					list2[index2] = value2;
				}
				List<StoreItem> val5 = new List<StoreItem>();
				for (int num3 = 0; num3 < Math.Min(HostSettings.Choices, list2.Count); num3++)
				{
					val5.Add(list2[num3]);
				}
				__result = val5;
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = Plugin.Log;
				BepInExErrorLogInterpolatedStringHandler val6 = new BepInExErrorLogInterpolatedStringHandler(6, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val6).AppendLiteral("Shop: ");
					((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<Exception>(ex);
				}
				log2.LogError(val6);
			}
		}

		[HarmonyPatch(typeof(PlayerStats), "AddInfusion")]
		[HarmonyPrefix]
		private static bool AddInfusion_Prefix(PlayerStats __instance, SpellType spell, ElementType newElement)
		{
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Expected O, but got Unknown
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			//IL_0046: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			if (!HostSettings.Enabled)
			{
				return true;
			}
			bool flag = default(bool);
			try
			{
				if (CoreCount(__instance.GetElement(spell)) < 2)
				{
					return true;
				}
				ulong ownerClientId = ((NetworkBehaviour)__instance).OwnerClientId;
				third[(ownerClientId, spell)] = newElement;
				if (((NetworkBehaviour)__instance).IsOwner)
				{
					pending.Remove(spell);
				}
				ManualLogSource log = Plugin.Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(38, 5, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Third infusion: player ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ulong>(ownerClientId);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<SpellType>(spell);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" + ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ElementType>(newElement);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (now ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ElementType>(__instance.GetElement(spell));
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" + ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ElementType>(newElement);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(").");
				}
				log.LogInfo(val);
				return false;
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = Plugin.Log;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(8, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Choose: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
				}
				log2.LogError(val2);
				return true;
			}
		}

		private static List<ElementType> CachedCores(ElementType e)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if (coreCache.TryGetValue(e, out var value))
			{
				return value;
			}
			value = (((int)e == 0) ? new List<ElementType>() : Cores(e));
			if (value.Count == 0 && (int)e != 0)
			{
				value.Add(e);
			}
			coreCache[e] = value;
			return value;
		}

		[HarmonyPatch(typeof(ElementCombiner), "GetElement")]
		[HarmonyPrefix]
		private static bool GetElement_Prefix(List<ElementType> elements, ref ElementType __result)
		{
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Expected I4, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Expected I4, but got Unknown
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected I4, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			if (combining || elements == null || elements.Count < 2)
			{
				return true;
			}
			combining = true;
			try
			{
				int num = 0;
				for (int i = 0; i < elements.Count; i++)
				{
					num += CachedCores(elements[i]).Count;
				}
				if (num < 3)
				{
					return true;
				}
				ElementType val = (ElementType)0;
				ElementType val2 = (ElementType)0;
				ElementType val3 = (ElementType)0;
				int num2 = 0;
				for (int j = 0; j < elements.Count; j++)
				{
					List<ElementType> list = CachedCores(elements[j]);
					if (list.Count >= 2 && (int)val == 0)
					{
						val = elements[j];
					}
					foreach (ElementType item in list)
					{
						switch (num2)
						{
						case 0:
							val2 = item;
							break;
						case 1:
							val3 = item;
							break;
						}
						num2++;
					}
				}
				if ((int)val != 0)
				{
					__result = (ElementType)(int)val;
					return false;
				}
				List<ElementType> val4 = new List<ElementType>();
				val4.Add(val2);
				val4.Add(val3);
				__result = (ElementType)(int)ElementCombiner.GetElement(val4);
				return false;
			}
			catch
			{
				__result = (ElementType)(int)elements[0];
				return false;
			}
			finally
			{
				combining = false;
			}
		}

		[HarmonyPatch(typeof(ElementEffectExecutor), "Execute")]
		[HarmonyPostfix]
		private static void Execute_Postfix(ElementEffectExecutor __instance, float damage, DamageInfo damageInfo, HealthContainer targetHealthContainer)
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			if (applyingThird || damageInfo == null || third.Count == 0)
			{
				return;
			}
			try
			{
				PlayerSpellDamageInfo val = ((Il2CppObjectBase)damageInfo).TryCast<PlayerSpellDamageInfo>();
				if (val == null || !third.TryGetValue((((PlayerDamageInfo)val).OwnerClientId, val.Spell), out var value) || (Object)(object)targetHealthContainer == (Object)null || ((Il2CppObjectBase)targetHealthContainer).WasCollected)
				{
					return;
				}
				ElementType element = damageInfo.Element;
				applyingThird = true;
				damageInfo.Element = value;
				try
				{
					__instance.Execute(damage, damageInfo, targetHealthContainer);
				}
				finally
				{
					damageInfo.Element = element;
					applyingThird = false;
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(5, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Hit: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
				}
				log.LogError(val2);
			}
		}

		[HarmonyPatch(typeof(RunManager), "OnDestroy")]
		[HarmonyPostfix]
		private static void Reset()
		{
			third.Clear();
			pending.Clear();
			localStats = null;
		}

		static InfusionPatches()
		{
			ElementType[] array = new ElementType[5];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			CoreElements = (ElementType[])(object)array;
			coreCache = new Dictionary<ElementType, List<ElementType>>();
		}
	}
	[BepInPlugin("girthy_mods.TripleInfusion", "TripleInfusion", "1.1.0")]
	public class Plugin : BasePlugin
	{
		public const string Guid = "girthy_mods.TripleInfusion";

		public const string Name = "TripleInfusion";

		public const string Version = "1.1.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<int> ThirdInfusionLevel;

		internal static ConfigEntry<bool> AllowRepeatElements;

		internal static ConfigEntry<int> Choices;

		public override void Load()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Expected O, but got Unknown
			Log = ((BasePlugin)this).Log;
			Enabled = ((BasePlugin)this).Config.Bind<bool>("Third Infusion", "Enabled", true, "Offer a third infusion for spells that already have two elements.");
			ThirdInfusionLevel = ((BasePlugin)this).Config.Bind<int>("Third Infusion", "SpellLevel", 21, new ConfigDescription("Spell level for the third infusion (vanilla gives the first at 7 and the second at 14). It's offered at the first level-up at or above this.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(2, 99), Array.Empty<object>()));
			AllowRepeatElements = ((BasePlugin)this).Config.Bind<bool>("Third Infusion", "AllowRepeatElements", true, "Allow a third element the spell already has (e.g. Fire + Lightning + Fire). Off = only elements the spell doesn't have yet.");
			Choices = ((BasePlugin)this).Config.Bind<int>("Third Infusion", "Choices", 2, new ConfigDescription("How many elements to choose from in the third infusion shop (vanilla infusion shops offer 2).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 5), Array.Empty<object>()));
			Harmony val = new Harmony("girthy_mods.TripleInfusion");
			val.PatchAll(typeof(InfusionPatches));
			val.PatchAll(typeof(HostSettings));
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(8, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("TripleInfusion");
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" ");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("1.1.0");
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" ready.");
			}
			log.LogInfo(val2);
		}
	}
	internal static class Raw
	{
		private static readonly Dictionary<string, int> fieldOffsets = new Dictionary<string, int>();

		private static int hasValueAt = -1;

		private static int valueAt = -1;

		private static int FieldOffset<TOwner>(string field) where TOwner : Il2CppObjectBase
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			string text = typeof(TOwner).FullName + "." + field;
			if (fieldOffsets.TryGetValue(text, out var value))
			{
				return value;
			}
			IntPtr il2CppField = IL2CPP.GetIl2CppField(Il2CppClassPointerStore<TOwner>.NativeClassPtr, field);
			value = ((il2CppField == IntPtr.Zero) ? (-1) : ((int)IL2CPP.il2cpp_field_get_offset(il2CppField)));
			fieldOffsets[text] = value;
			if (value < 0)
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(17, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Field ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" not found.");
				}
				log.LogError(val);
			}
			return value;
		}

		private static void NullableLayout()
		{
			if (hasValueAt >= 0)
			{
				return;
			}
			hasValueAt = 0;
			valueAt = 4;
			try
			{
				IntPtr nativeClassPtr = Il2CppClassPointerStore<Nullable<float>>.NativeClassPtr;
				IntPtr il2CppField = IL2CPP.GetIl2CppField(nativeClassPtr, "hasValue");
				IntPtr il2CppField2 = IL2CPP.GetIl2CppField(nativeClassPtr, "value");
				if (il2CppField != IntPtr.Zero && il2CppField2 != IntPtr.Zero)
				{
					int num = IntPtr.Size * 2;
					int num2 = (int)IL2CPP.il2cpp_field_get_offset(il2CppField) - num;
					int num3 = (int)IL2CPP.il2cpp_field_get_offset(il2CppField2) - num;
					if (num2 >= 0 && num3 >= 0 && num2 < 16 && num3 < 16)
					{
						hasValueAt = num2;
						valueAt = num3;
					}
				}
			}
			catch
			{
			}
		}

		internal unsafe static bool TryGetNullable4<TOwner>(TOwner obj, string field, out int bits) where TOwner : Il2CppObjectBase
		{
			bits = 0;
			int num = FieldOffset<TOwner>(field);
			if (num < 0 || obj == null)
			{
				return false;
			}
			NullableLayout();
			byte* ptr = (byte*)(void*)((Il2CppObjectBase)obj).Pointer + num;
			if (ptr[hasValueAt] == 0)
			{
				return false;
			}
			bits = *(int*)(ptr + valueAt);
			return true;
		}
	}
}