Decompiled source of 0p41 PrayerBeadsRework v1.0.0

PrayerBeadsRework.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using IL.RoR2;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2;
using R2API;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PrayerBeadsRework")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PrayerBeadsRework")]
[assembly: AssemblyTitle("PrayerBeadsRework")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ExamplePlugin
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("0p41.PrayerBeadsRework", "PrayerBeadsRework", "1.0.0")]
	public class MainPlugin : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Func<Instruction, bool> <>9__17_5;

			public static Func<Instruction, bool> <>9__17_6;

			public static Func<Instruction, bool> <>9__17_7;

			public static Func<Instruction, bool> <>9__17_9;

			public static Func<Instruction, bool> <>9__17_10;

			public static Func<Instruction, bool> <>9__17_11;

			public static Func<bool> <>9__17_3;

			public static Func<Instruction, bool> <>9__17_12;

			public static Func<Instruction, bool> <>9__17_13;

			public static Func<Instruction, bool> <>9__17_14;

			public static Func<Instruction, bool> <>9__17_15;

			public static Func<Instruction, bool> <>9__17_16;

			public static Func<Instruction, bool> <>9__17_17;

			public static Func<Instruction, bool> <>9__17_18;

			public static Func<Instruction, bool> <>9__17_19;

			public static Func<bool, bool> <>9__17_4;

			public static Manipulator <>9__17_0;

			public static Func<Instruction, bool> <>9__17_21;

			public static Func<Instruction, bool> <>9__17_22;

			public static Func<Instruction, bool> <>9__17_23;

			public static Func<Instruction, bool> <>9__17_24;

			public static Func<Instruction, bool> <>9__17_25;

			public static Func<Instruction, bool> <>9__17_26;

			public static Func<int, int> <>9__17_20;

			public static Manipulator <>9__17_1;

			public static Func<Instruction, bool> <>9__17_28;

			public static Func<Instruction, bool> <>9__17_29;

			public static Func<Instruction, bool> <>9__17_30;

			public static Func<Instruction, bool> <>9__17_31;

			public static Func<Instruction, bool> <>9__17_32;

			public static Func<int, int> <>9__17_27;

			public static Manipulator <>9__17_2;

			internal void <ILHooks>b__17_0(ILContext il)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Expected O, but got Unknown
				//IL_0142: Unknown result type (might be due to invalid IL or missing references)
				<>c__DisplayClass17_0 CS$<>8__locals0 = new <>c__DisplayClass17_0
				{
					label = null
				};
				ILCursor val = new ILCursor(il);
				int num3 = default(int);
				int num2 = default(int);
				ILLabel val4 = default(ILLabel);
				if (val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[7]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num3),
					(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
					(Instruction x) => ILPatternMatchingExt.MatchLdfld<CharacterBody>(x, "extraStatsOnLevelUpCount_CachedLastApplied"),
					(Instruction x) => ILPatternMatchingExt.MatchBle(x, ref CS$<>8__locals0.label),
					(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num2),
					(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 0),
					(Instruction x) => ILPatternMatchingExt.MatchBle(x, ref val4)
				}))
				{
					if (CS$<>8__locals0.label.Target != null)
					{
						val.EmitDelegate<Func<bool>>((Func<bool>)(() => true));
						val.Emit(OpCodes.Brtrue, (object)CS$<>8__locals0.label);
						int num = default(int);
						ILLabel val3 = default(ILLabel);
						ILLabel val2 = default(ILLabel);
						if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[8]
						{
							(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num),
							(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
							(Instruction x) => ILPatternMatchingExt.MatchLdfld<CharacterBody>(x, "extraStatsOnLevelUpCount_CachedLastApplied"),
							(Instruction x) => ILPatternMatchingExt.MatchBge(x, ref val3),
							(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
							(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<CharacterBody>(x, "get_inventory"),
							(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Object>(x, "op_Implicit"),
							(Instruction x) => ILPatternMatchingExt.MatchBrfalse(x, ref val2)
						}))
						{
							val.Index -= 1;
							val.EmitDelegate<Func<bool, bool>>((Func<bool, bool>)((bool value) => false));
						}
						else
						{
							Log.Error("PrayerBeads | CharacterBody.RecalculateStats Second Hook Failed - No Match Found.");
						}
						Log.Info("PrayerBeads | CharacterBody.RecalculateStats Hooked Successfuly.");
					}
					else
					{
						Log.Error("PrayerBeads | CharacterBody.RecalculateStats First Hook Failed - Label.Target is Null.");
					}
				}
				else
				{
					Log.Error("PrayerBeads | CharacterBody.RecalculateStats Hook Failed - No Match Found.");
				}
			}

			internal bool <ILHooks>b__17_5(Instruction x)
			{
				int num = default(int);
				return ILPatternMatchingExt.MatchLdloc(x, ref num);
			}

			internal bool <ILHooks>b__17_6(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdarg(x, 0);
			}

			internal bool <ILHooks>b__17_7(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdfld<CharacterBody>(x, "extraStatsOnLevelUpCount_CachedLastApplied");
			}

			internal bool <ILHooks>b__17_9(Instruction x)
			{
				int num = default(int);
				return ILPatternMatchingExt.MatchLdloc(x, ref num);
			}

			internal bool <ILHooks>b__17_10(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdcI4(x, 0);
			}

			internal bool <ILHooks>b__17_11(Instruction x)
			{
				ILLabel val = default(ILLabel);
				return ILPatternMatchingExt.MatchBle(x, ref val);
			}

			internal bool <ILHooks>b__17_3()
			{
				return true;
			}

			internal bool <ILHooks>b__17_12(Instruction x)
			{
				int num = default(int);
				return ILPatternMatchingExt.MatchLdloc(x, ref num);
			}

			internal bool <ILHooks>b__17_13(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdarg(x, 0);
			}

			internal bool <ILHooks>b__17_14(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdfld<CharacterBody>(x, "extraStatsOnLevelUpCount_CachedLastApplied");
			}

			internal bool <ILHooks>b__17_15(Instruction x)
			{
				ILLabel val = default(ILLabel);
				return ILPatternMatchingExt.MatchBge(x, ref val);
			}

			internal bool <ILHooks>b__17_16(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdarg(x, 0);
			}

			internal bool <ILHooks>b__17_17(Instruction x)
			{
				return ILPatternMatchingExt.MatchCallOrCallvirt<CharacterBody>(x, "get_inventory");
			}

			internal bool <ILHooks>b__17_18(Instruction x)
			{
				return ILPatternMatchingExt.MatchCallOrCallvirt<Object>(x, "op_Implicit");
			}

			internal bool <ILHooks>b__17_19(Instruction x)
			{
				ILLabel val = default(ILLabel);
				return ILPatternMatchingExt.MatchBrfalse(x, ref val);
			}

			internal bool <ILHooks>b__17_4(bool value)
			{
				return false;
			}

			internal void <ILHooks>b__17_1(ILContext il)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				ILCursor val = new ILCursor(il);
				ILLabel val2 = default(ILLabel);
				if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[6]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
					(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<CharacterMaster>(x, "get_inventory"),
					(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Items), "ExtraStatsOnLevelUp"),
					(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Inventory>(x, "GetItemCount"),
					(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 0),
					(Instruction x) => ILPatternMatchingExt.MatchBle(x, ref val2)
				}))
				{
					val.Index -= 2;
					val.EmitDelegate<Func<int, int>>((Func<int, int>)((int value) => 0));
					Log.Info("PrayerBeads | CharacterMaster.OnBodyStart Hooked Successfuly.");
				}
				else
				{
					Log.Error("PrayerBeads | CharacterMaster.OnBodyStart - Hook Failed - No Match Found.");
				}
			}

			internal bool <ILHooks>b__17_21(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdarg(x, 0);
			}

			internal bool <ILHooks>b__17_22(Instruction x)
			{
				return ILPatternMatchingExt.MatchCallOrCallvirt<CharacterMaster>(x, "get_inventory");
			}

			internal bool <ILHooks>b__17_23(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdsfld(x, typeof(Items), "ExtraStatsOnLevelUp");
			}

			internal bool <ILHooks>b__17_24(Instruction x)
			{
				return ILPatternMatchingExt.MatchCallOrCallvirt<Inventory>(x, "GetItemCount");
			}

			internal bool <ILHooks>b__17_25(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdcI4(x, 0);
			}

			internal bool <ILHooks>b__17_26(Instruction x)
			{
				ILLabel val = default(ILLabel);
				return ILPatternMatchingExt.MatchBle(x, ref val);
			}

			internal int <ILHooks>b__17_20(int value)
			{
				return 0;
			}

			internal void <ILHooks>b__17_2(ILContext il)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				ILCursor val = new ILCursor(il);
				int num = default(int);
				if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[5]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
					(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<CharacterMaster>(x, "get_inventory"),
					(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Items), "ExtraStatsOnLevelUp"),
					(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Inventory>(x, "GetItemCount"),
					(Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref num)
				}))
				{
					val.Index -= 1;
					val.EmitDelegate<Func<int, int>>((Func<int, int>)((int value) => 0));
					Log.Info("PrayerBeads | CharacterMaster.TrackBeadExperience Hooked Successfuly.");
				}
				else
				{
					Log.Error("PrayerBeads | CharacterMaster.TrackBeadExperience - Hook Failed - No Match Found.");
				}
			}

			internal bool <ILHooks>b__17_28(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdarg(x, 0);
			}

			internal bool <ILHooks>b__17_29(Instruction x)
			{
				return ILPatternMatchingExt.MatchCallOrCallvirt<CharacterMaster>(x, "get_inventory");
			}

			internal bool <ILHooks>b__17_30(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdsfld(x, typeof(Items), "ExtraStatsOnLevelUp");
			}

			internal bool <ILHooks>b__17_31(Instruction x)
			{
				return ILPatternMatchingExt.MatchCallOrCallvirt<Inventory>(x, "GetItemCount");
			}

			internal bool <ILHooks>b__17_32(Instruction x)
			{
				int num = default(int);
				return ILPatternMatchingExt.MatchStloc(x, ref num);
			}

			internal int <ILHooks>b__17_27(int value)
			{
				return 0;
			}
		}

		[CompilerGenerated]
		private sealed class <>c__DisplayClass17_0
		{
			public ILLabel label;

			internal bool <ILHooks>b__8(Instruction x)
			{
				return ILPatternMatchingExt.MatchBle(x, ref label);
			}
		}

		public const string PluginGUID = "0p41.PrayerBeadsRework";

		public const string PluginAuthor = "0p41";

		public const string PluginName = "PrayerBeadsRework";

		public const string PluginVersion = "1.0.0";

		private float chanceExtraItem = 10f;

		private float greenWeight = 0.4f;

		private float redWeight = 0.15f;

		private float bossWeight = 0.05f;

		private float void1Weight = 0.1f;

		private float void2Weight = 0.25f;

		private float void3Weight = 0.05f;

		private float greenChance;

		private float redChance;

		private float bossChance;

		private float voidChance;

		public void Awake()
		{
			//IL_0012: 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)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			ItemDef val = Addressables.LoadAssetAsync<ItemDef>((object)"RoR2/DLC2/Items/ExtraStatsOnLevelUp/ExtraStatsOnLevelUp.asset").WaitForCompletion();
			ItemTag[] array = new ItemTag[6];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			val.tags = (ItemTag[])(object)array;
			ModConfig.Init(((BaseUnityPlugin)this).Config);
			LoadConfig();
			ILHooks();
			string text = "Transform into a copy of one of your items at the start of the stage.";
			string text2 = $"At the start of the stage this item transform into a copy of <style=cIsUtility>{1}</style> <style=cStack>(+{1} per stack)</style> of your items (<style=cIsHealing>{greenChance * 100f}%</style>/<style=cIsHealth>{redChance * 100f}%</style>/<style=cIsDamage>{bossChance * 100f}%</style>/<style=cIsVoid>{voidChance * 100f}%</style>) with a <style=cIsUtility>{chanceExtraItem}%</style> chance to transform into <style=cIsUtility>2</style> copies.\n<style=cStack>(Increase chance of high rarity with item stack.)</style>";
			LanguageAPI.Add("ITEM_EXTRASTATSONLEVELUP_PICKUP", text);
			LanguageAPI.Add("ITEM_EXTRASTATSONLEVELUP_DESC", text2);
			CharacterMaster.OnServerStageBegin += new hook_OnServerStageBegin(CharacterMaster_OnServerStageBegin);
		}

		private void CharacterMaster_OnServerStageBegin(orig_OnServerStageBegin orig, CharacterMaster self, Stage stage)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			orig.Invoke(self, stage);
			if (Object.op_Implicit((Object)(object)self) && NetworkServer.active)
			{
				TryPrayerBeads(self, new Xoroshiro128Plus((ulong)Random.Range(int.MinValue, int.MaxValue)));
			}
		}

		private void ILHooks()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_005f: 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_006a: Expected O, but got Unknown
			object obj = <>c.<>9__17_0;
			if (obj == null)
			{
				Manipulator val = delegate(ILContext il)
				{
					//IL_000f: Unknown result type (might be due to invalid IL or missing references)
					//IL_0015: Expected O, but got Unknown
					//IL_0142: Unknown result type (might be due to invalid IL or missing references)
					ILLabel label = null;
					ILCursor val7 = new ILCursor(il);
					int num4 = default(int);
					int num3 = default(int);
					ILLabel val10 = default(ILLabel);
					if (val7.TryGotoNext((MoveType)0, new Func<Instruction, bool>[7]
					{
						(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num4),
						(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
						(Instruction x) => ILPatternMatchingExt.MatchLdfld<CharacterBody>(x, "extraStatsOnLevelUpCount_CachedLastApplied"),
						(Instruction x) => ILPatternMatchingExt.MatchBle(x, ref label),
						(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num3),
						(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 0),
						(Instruction x) => ILPatternMatchingExt.MatchBle(x, ref val10)
					}))
					{
						if (label.Target != null)
						{
							val7.EmitDelegate<Func<bool>>((Func<bool>)(() => true));
							val7.Emit(OpCodes.Brtrue, (object)label);
							int num2 = default(int);
							ILLabel val9 = default(ILLabel);
							ILLabel val8 = default(ILLabel);
							if (val7.TryGotoNext((MoveType)2, new Func<Instruction, bool>[8]
							{
								(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num2),
								(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
								(Instruction x) => ILPatternMatchingExt.MatchLdfld<CharacterBody>(x, "extraStatsOnLevelUpCount_CachedLastApplied"),
								(Instruction x) => ILPatternMatchingExt.MatchBge(x, ref val9),
								(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
								(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<CharacterBody>(x, "get_inventory"),
								(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Object>(x, "op_Implicit"),
								(Instruction x) => ILPatternMatchingExt.MatchBrfalse(x, ref val8)
							}))
							{
								val7.Index -= 1;
								val7.EmitDelegate<Func<bool, bool>>((Func<bool, bool>)((bool value) => false));
							}
							else
							{
								Log.Error("PrayerBeads | CharacterBody.RecalculateStats Second Hook Failed - No Match Found.");
							}
							Log.Info("PrayerBeads | CharacterBody.RecalculateStats Hooked Successfuly.");
						}
						else
						{
							Log.Error("PrayerBeads | CharacterBody.RecalculateStats First Hook Failed - Label.Target is Null.");
						}
					}
					else
					{
						Log.Error("PrayerBeads | CharacterBody.RecalculateStats Hook Failed - No Match Found.");
					}
				};
				<>c.<>9__17_0 = val;
				obj = (object)val;
			}
			CharacterBody.RecalculateStats += (Manipulator)obj;
			object obj2 = <>c.<>9__17_1;
			if (obj2 == null)
			{
				Manipulator val2 = delegate(ILContext il)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_0008: Expected O, but got Unknown
					ILCursor val5 = new ILCursor(il);
					ILLabel val6 = default(ILLabel);
					if (val5.TryGotoNext((MoveType)2, new Func<Instruction, bool>[6]
					{
						(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
						(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<CharacterMaster>(x, "get_inventory"),
						(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Items), "ExtraStatsOnLevelUp"),
						(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Inventory>(x, "GetItemCount"),
						(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 0),
						(Instruction x) => ILPatternMatchingExt.MatchBle(x, ref val6)
					}))
					{
						val5.Index -= 2;
						val5.EmitDelegate<Func<int, int>>((Func<int, int>)((int value) => 0));
						Log.Info("PrayerBeads | CharacterMaster.OnBodyStart Hooked Successfuly.");
					}
					else
					{
						Log.Error("PrayerBeads | CharacterMaster.OnBodyStart - Hook Failed - No Match Found.");
					}
				};
				<>c.<>9__17_1 = val2;
				obj2 = (object)val2;
			}
			CharacterMaster.OnBodyStart += (Manipulator)obj2;
			object obj3 = <>c.<>9__17_2;
			if (obj3 == null)
			{
				Manipulator val3 = delegate(ILContext il)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_0008: Expected O, but got Unknown
					ILCursor val4 = new ILCursor(il);
					int num = default(int);
					if (val4.TryGotoNext((MoveType)2, new Func<Instruction, bool>[5]
					{
						(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
						(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<CharacterMaster>(x, "get_inventory"),
						(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Items), "ExtraStatsOnLevelUp"),
						(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Inventory>(x, "GetItemCount"),
						(Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref num)
					}))
					{
						val4.Index -= 1;
						val4.EmitDelegate<Func<int, int>>((Func<int, int>)((int value) => 0));
						Log.Info("PrayerBeads | CharacterMaster.TrackBeadExperience Hooked Successfuly.");
					}
					else
					{
						Log.Error("PrayerBeads | CharacterMaster.TrackBeadExperience - Hook Failed - No Match Found.");
					}
				};
				<>c.<>9__17_2 = val3;
				obj3 = (object)val3;
			}
			CharacterMaster.TrackBeadExperience += (Manipulator)obj3;
		}

		private void LoadConfig()
		{
			chanceExtraItem = ModConfig.prayerBeadsChance.Value;
			greenWeight = ModConfig.prayerBeadsTier2.Value;
			redWeight = ModConfig.prayerBeadsTier3.Value;
			bossWeight = ModConfig.prayerBeadsBoss.Value;
			void1Weight = ModConfig.prayerBeadsVoid1.Value;
			void2Weight = ModConfig.prayerBeadsVoid2.Value;
			void3Weight = ModConfig.prayerBeadsVoid3.Value;
			float num = greenWeight + redWeight + bossWeight + void1Weight + void2Weight + void3Weight;
			greenChance = greenWeight / num;
			redChance = redWeight / num;
			bossChance = bossWeight / num;
			voidChance = (void1Weight + void2Weight + void3Weight) / num;
		}

		public void TryPrayerBeads(CharacterMaster master, Xoroshiro128Plus rng)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: 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_00e7: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Expected I4, but got Unknown
			//IL_0115: 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_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: 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_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Invalid comparison between Unknown and I4
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Expected I4, but got Unknown
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: Expected I4, but got Unknown
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0465: Unknown result type (might be due to invalid IL or missing references)
			//IL_046c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_054d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0554: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0632: Unknown result type (might be due to invalid IL or missing references)
			//IL_0639: Unknown result type (might be due to invalid IL or missing references)
			int itemCount = master.inventory.GetItemCount(Items.ExtraStatsOnLevelUp);
			if (itemCount <= 0)
			{
				return;
			}
			List<ItemIndex> list = new List<ItemIndex>(master.inventory.itemAcquisitionOrder);
			List<ItemIndex> list2 = new List<ItemIndex>();
			List<ItemIndex> list3 = new List<ItemIndex>();
			List<ItemIndex> list4 = new List<ItemIndex>();
			List<ItemIndex> list5 = new List<ItemIndex>();
			List<ItemIndex> list6 = new List<ItemIndex>();
			List<ItemIndex> list7 = new List<ItemIndex>();
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			int num5 = 0;
			int num6 = 0;
			foreach (ItemIndex item in list)
			{
				ItemDef itemDef = ItemCatalog.GetItemDef(item);
				if (!((Object)(object)itemDef == (Object)(object)Items.ExtraStatsOnLevelUp) && !((Object)(object)itemDef == (Object)(object)Items.RegeneratingScrap) && !itemDef.ContainsTag((ItemTag)10) && !itemDef.ContainsTag((ItemTag)9) && (int)itemDef.tier != 5)
				{
					ItemTier tier = itemDef.tier;
					ItemTier val = tier;
					switch (val - 1)
					{
					case 0:
						list2.Add(item);
						num = 1;
						break;
					case 1:
						list3.Add(item);
						num2 = 1;
						break;
					case 3:
						list4.Add(item);
						num3 = 1;
						break;
					case 5:
						list5.Add(item);
						num4 = 1;
						break;
					case 6:
						list6.Add(item);
						num5 = 1;
						break;
					case 7:
						list7.Add(item);
						num6 = 1;
						break;
					}
				}
			}
			if (num == 0 && num2 == 0 && num3 == 0 && num4 == 0 && num5 == 0 && num6 == 0)
			{
				return;
			}
			WeightedSelection<ItemTier> val2 = new WeightedSelection<ItemTier>(4);
			val2.AddChoice((ItemTier)1, greenWeight * Mathf.Pow((float)itemCount, 1.1f) * (float)num);
			val2.AddChoice((ItemTier)2, redWeight * Mathf.Pow((float)itemCount, 1.25f) * (float)num2);
			val2.AddChoice((ItemTier)4, bossWeight * Mathf.Pow((float)itemCount, 1.5f) * (float)num3);
			val2.AddChoice((ItemTier)6, void1Weight * Mathf.Pow((float)itemCount, 1.25f) * (float)num4);
			val2.AddChoice((ItemTier)7, void2Weight * Mathf.Pow((float)itemCount, 1.4f) * (float)num5);
			val2.AddChoice((ItemTier)8, void3Weight * Mathf.Pow((float)itemCount, 1.05f) * (float)num6);
			Dictionary<ItemDef, int> dictionary = new Dictionary<ItemDef, int>();
			for (int i = 0; i < itemCount; i++)
			{
				ItemTier val3 = val2.Evaluate(rng.nextNormalizedFloat);
				ItemTier val4 = val3;
				ItemTier val5 = val4;
				switch (val5 - 1)
				{
				case 0:
					GiveRemoveItemProcess(list2, rng, master, dictionary);
					break;
				case 1:
					GiveRemoveItemProcess(list3, rng, master, dictionary);
					break;
				case 3:
					GiveRemoveItemProcess(list4, rng, master, dictionary);
					break;
				case 5:
					GiveRemoveItemProcess(list5, rng, master, dictionary);
					break;
				case 6:
					GiveRemoveItemProcess(list6, rng, master, dictionary);
					break;
				case 7:
					GiveRemoveItemProcess(list7, rng, master, dictionary);
					break;
				}
			}
			foreach (ItemDef key in dictionary.Keys)
			{
				ItemTier tier2 = key.tier;
				ItemTier val6 = tier2;
				switch (val6 - 1)
				{
				case 0:
					if (ModConfig.choices.Value == ModConfig.PopUp.Chat)
					{
						Chat.AddMessage($"<style=cSub>Transformed x{dictionary[key]} Prayer Beads into <style=cIsHealing>{Language.GetString(key.nameToken)}</style></style>");
					}
					else if (ModConfig.choices.Value == ModConfig.PopUp.Default)
					{
						CharacterMasterNotificationQueue.SendTransformNotification(master, Items.ExtraStatsOnLevelUp.itemIndex, key.itemIndex, (TransformationType)0);
					}
					break;
				case 1:
					if (ModConfig.choices.Value == ModConfig.PopUp.Chat)
					{
						Chat.AddMessage($"<style=cSub>Transformed x{dictionary[key]} Prayer Beads into <style=cIsHealth>{Language.GetString(key.nameToken)}</style></style>");
					}
					else if (ModConfig.choices.Value == ModConfig.PopUp.Default)
					{
						CharacterMasterNotificationQueue.SendTransformNotification(master, Items.ExtraStatsOnLevelUp.itemIndex, key.itemIndex, (TransformationType)0);
					}
					break;
				case 3:
					if (ModConfig.choices.Value == ModConfig.PopUp.Chat)
					{
						Chat.AddMessage($"<style=cSub>Transformed x{dictionary[key]} Prayer Beads into <style=cIsDamage>{Language.GetString(key.nameToken)}</style></style>");
					}
					else if (ModConfig.choices.Value == ModConfig.PopUp.Default)
					{
						CharacterMasterNotificationQueue.SendTransformNotification(master, Items.ExtraStatsOnLevelUp.itemIndex, key.itemIndex, (TransformationType)0);
					}
					break;
				case 5:
					if (ModConfig.choices.Value == ModConfig.PopUp.Chat)
					{
						Chat.AddMessage($"<style=cSub>Transformed x{dictionary[key]} Prayer Beads into <style=cIsVoid>{Language.GetString(key.nameToken)}</style></style>");
					}
					else if (ModConfig.choices.Value == ModConfig.PopUp.Default)
					{
						CharacterMasterNotificationQueue.SendTransformNotification(master, Items.ExtraStatsOnLevelUp.itemIndex, key.itemIndex, (TransformationType)0);
					}
					break;
				case 6:
					if (ModConfig.choices.Value == ModConfig.PopUp.Chat)
					{
						Chat.AddMessage($"<style=cSub>Transformed x{dictionary[key]} Prayer Beads into <style=cIsVoid>{Language.GetString(key.nameToken)}</style></style>");
					}
					else if (ModConfig.choices.Value == ModConfig.PopUp.Default)
					{
						CharacterMasterNotificationQueue.SendTransformNotification(master, Items.ExtraStatsOnLevelUp.itemIndex, key.itemIndex, (TransformationType)0);
					}
					break;
				case 7:
					if (ModConfig.choices.Value == ModConfig.PopUp.Chat)
					{
						Chat.AddMessage($"<style=cSub>Transformed x{dictionary[key]} Prayer Beads into <style=cIsVoid>{Language.GetString(key.nameToken)}</style></style>");
					}
					else if (ModConfig.choices.Value == ModConfig.PopUp.Default)
					{
						CharacterMasterNotificationQueue.SendTransformNotification(master, Items.ExtraStatsOnLevelUp.itemIndex, key.itemIndex, (TransformationType)0);
					}
					break;
				}
			}
		}

		private void GiveRemoveItemProcess(List<ItemIndex> list, Xoroshiro128Plus rng, CharacterMaster master, Dictionary<ItemDef, int> keyValuePairs)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			Util.ShuffleList<ItemIndex>(list, rng);
			ItemDef itemDef = ItemCatalog.GetItemDef(list[0]);
			master.inventory.RemoveItem(Items.ExtraStatsOnLevelUp, 1);
			master.inventory.GiveItem(itemDef, 1);
			num++;
			if (Util.CheckRoll(chanceExtraItem, 0f, master))
			{
				master.inventory.GiveItem(itemDef, 1);
				num++;
			}
			if (keyValuePairs.ContainsKey(itemDef))
			{
				keyValuePairs[itemDef] += num;
			}
			else
			{
				keyValuePairs.Add(itemDef, num);
			}
		}
	}
	public static class ModConfig
	{
		public enum PopUp
		{
			Default,
			Chat
		}

		public static ConfigEntry<PopUp> choices;

		public static ConfigEntry<float> prayerBeadsChance;

		private const float defaultPrayerChance = 10f;

		public static ConfigEntry<int> prayerBeadsTier2;

		private const int defaultPrayerTier2 = 40;

		public static ConfigEntry<int> prayerBeadsTier3;

		private const int defaultPrayerTier3 = 15;

		public static ConfigEntry<int> prayerBeadsBoss;

		private const int defaultPrayerBoss = 5;

		public static ConfigEntry<int> prayerBeadsVoid1;

		private const int defaultPrayerVoid1 = 10;

		public static ConfigEntry<int> prayerBeadsVoid2;

		private const int defaultPrayerVoid2 = 25;

		public static ConfigEntry<int> prayerBeadsVoid3;

		private const int defaultPrayerVoid3 = 5;

		public static void Init(ConfigFile config)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_005f: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Expected O, but got Unknown
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: 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_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Expected O, but got Unknown
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Expected O, but got Unknown
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Expected O, but got Unknown
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Expected O, but got Unknown
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Expected O, but got Unknown
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Expected O, but got Unknown
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Expected O, but got Unknown
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Expected O, but got Unknown
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Expected O, but got Unknown
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Expected O, but got Unknown
			choices = config.Bind<PopUp>("Prayer Beads Changes", "Notification Type", PopUp.Default, "Changes how Prayer Beads shows what item it transformed into.\n\nDefault: Show at the bottom of the screen, only shows up once per item.\n\nChat: Will show in chat how many Prayer Beads transformed into which items, messages are not shown to allies (hopefully), you may or may not be able to scroll up, that just how chat works.");
			ModSettingsManager.AddOption((BaseOption)new ChoiceOption((ConfigEntryBase)(object)choices));
			prayerBeadsChance = config.Bind<float>("Prayer Beads Changes", "Prayer Beads Extra Item Chance", 10f, $"Base drop chance for it to transform into 2 copies of the same item, in %.\nDefault value: {10f}.");
			ModSettingsManager.AddOption((BaseOption)new StepSliderOption(prayerBeadsChance, new StepSliderConfig
			{
				min = 0f,
				max = 100f,
				increment = 0.25f,
				restartRequired = true
			}));
			prayerBeadsTier2 = config.Bind<int>("Prayer Beads Changes", "Prayer Beads Tier 2(Green) Weight", 40, $"Weight for transforming into a Tier 2 item.\nThis value is relative to the other drop weights, to calculate drop chance use X/(TierA + TierB + TierC ...) where X is this tier and the parentesis is the sum of the tiers of items that you currently have.\nDefault value: {40}.");
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(prayerBeadsTier2, new IntSliderConfig
			{
				min = 0,
				max = 100,
				restartRequired = true
			}));
			prayerBeadsTier3 = config.Bind<int>("Prayer Beads Changes", "Prayer Beads Tier 3(Red) Weight", 15, $"Weight for transforming into a Tier 3 item.\nThis value is relative to the other drop weights, to calculate drop chance use X/(TierA + TierB + TierC ...) where X is this tier and the parentesis is the sum of the tiers of items that you currently have.\nDefault value: {15}.");
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(prayerBeadsTier3, new IntSliderConfig
			{
				min = 0,
				max = 100,
				restartRequired = true
			}));
			prayerBeadsBoss = config.Bind<int>("Prayer Beads Changes", "Prayer Beads Boss Item Weight", 5, $"Weight for transforming into a Boss item.\nThis value is relative to the other drop weights, to calculate drop chance use X/(TierA + TierB + TierC ...) where X is this tier and the parentesis is the sum of the tiers of items that you currently have.\nDefault value: {5}.");
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(prayerBeadsBoss, new IntSliderConfig
			{
				min = 0,
				max = 100,
				restartRequired = true
			}));
			prayerBeadsVoid1 = config.Bind<int>("Prayer Beads Changes", "Prayer Beads Void Tier 1 Weight", 10, $"Weight for transforming into a Void item of Tier 1 (Whites).\nThis value is relative to the other drop weights, to calculate drop chance use X/(TierA + TierB + TierC ...) where X is this tier and the parentesis is the sum of the tiers of items that you currently have.\nDefault value: {10}.");
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(prayerBeadsVoid1, new IntSliderConfig
			{
				min = 0,
				max = 100,
				restartRequired = true
			}));
			prayerBeadsVoid2 = config.Bind<int>("Prayer Beads Changes", "Prayer Beads Void Tier 2 Weight", 25, $"Weight for transforming into a Void item of Tier 2 (Greens).\nThis value is relative to the other drop weights, to calculate drop chance use X/(TierA + TierB + TierC ...) where X is this tier and the parentesis is the sum of the tiers of items that you currently have.\nDefault value: {25}.");
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(prayerBeadsVoid2, new IntSliderConfig
			{
				min = 0,
				max = 100,
				restartRequired = true
			}));
			prayerBeadsVoid3 = config.Bind<int>("Prayer Beads Changes", "Prayer Beads Void Tier 3 Weight", 5, $"Weight for transforming into a Void item of Tier 3 (Reds).\nThis value is relative to the other drop weights, to calculate drop chance use X/(TierA + TierB + TierC ...) where X is this tier and the parentesis is the sum of the tiers of items that you currently have.\nDefault value: {5}.");
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(prayerBeadsVoid3, new IntSliderConfig
			{
				min = 0,
				max = 100,
				restartRequired = true
			}));
		}
	}
}