Decompiled source of SecretSpells v1.0.0

BepInEx/plugins/SecretSpells/SecretSpells.dll

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

[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("SecretSpells")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SecretSpells")]
[assembly: AssemblyTitle("SecretSpells")]
[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 SecretSpells
{
	[BepInPlugin("com.fizzy.secretspells", "SecretSpells", "1.0.0")]
	public class SecretSpells : BaseUnityPlugin
	{
		public static ConfigEntry<float> chanceForSecretSpells;

		private void Awake()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			((ConfigEntry<bool>)AccessTools.Field(typeof(Chainloader), "ConfigHideBepInExGOs").GetValue(null)).Value = true;
			chanceForSecretSpells = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Chance for a secret spell in %", 8f, new ConfigDescription("Chance for a secret spell to appear among spell room rewards in percent", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"SecretSpells has been loaded");
		}
	}
	[HarmonyPatch]
	public static class PatchMethods
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(UIReroll), "GetCost")]
		private static bool PrefixGetCost(UIReroll __instance, ref int __result)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Invalid comparison between Unknown and I4
			MethodInfo methodInfo = AccessTools.PropertyGetter(typeof(UIReroll), "SelectedUIRS");
			UIReroll_Spell val = (UIReroll_Spell)methodInfo.Invoke(__instance, null);
			SpellConfig val2 = SpellConfig.dic[val.SpellID];
			if ((int)val2.dropType == 0)
			{
				__result = 3;
				return false;
			}
			return true;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(BattleData), "GetSpellFromPool")]
		private static void PostfixGetSpell(BattleData __instance, ref int __result, int level, ItemDropType dropType, int exceptID)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			int[] source = new int[18]
			{
				90000, 90191, 90201, 90211, 90212, 90213, 90221, 90222, 90231, 90241,
				90242, 90261, 90281, 90291, 90301, 90301, 90311, 90321
			};
			if (source.Contains(__result))
			{
				__result = __instance.GetSpellFromPool(level, dropType, exceptID);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(OutputMgr), "GetLevelReward")]
		private static bool PrefixLevelReward(LevelRewardType type, ref List<ItemInfo> __result)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Invalid comparison between Unknown and I4
			//IL_004b: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Invalid comparison between Unknown and I4
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Invalid comparison between Unknown and I4
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Invalid comparison between Unknown and I4
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Invalid comparison between Unknown and I4
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Invalid comparison between Unknown and I4
			//IL_0277: 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_02af: Unknown result type (might be due to invalid IL or missing references)
			List<ItemInfo> list = new List<ItemInfo>();
			if ((int)type == 1)
			{
				if (DataMgr.selectedWorldData.enterBattleTime == 1 && BattleMgr.Inst.CurrentStage == 1 && BattleMgr.Inst.CurrentLevel == 2)
				{
					list.Add(new ItemInfo((ItemType)1, 30131));
					list.Add(new ItemInfo((ItemType)1, 30071));
					__result = list;
					return false;
				}
				int spellOptionCount = OutputMgr.GetSpellOptionCount();
				float num = 0.01f;
				if (DataMgr.selectedWorldData.enterBattleTime <= 1)
				{
					num = 0f;
				}
				if ((int)DataMgr.selectedWorldData.selectedDifficulty == 3)
				{
					num *= 1.5f;
				}
				else if ((int)DataMgr.selectedWorldData.selectedDifficulty == 4)
				{
					num *= 1.5f;
				}
				else if ((int)DataMgr.selectedWorldData.selectedDifficulty == 5)
				{
					num *= 2f;
				}
				float num2 = 0.12f;
				num2 *= (float)DataMgr.selectedWorldData.GetTalentSpellRoomValue() / 100f;
				for (int i = 0; i < spellOptionCount; i++)
				{
					float num3 = Random.value;
					int spellFromPool;
					if (num3 < SecretSpells.chanceForSecretSpells.Value / 100f)
					{
						spellFromPool = PlayerMgr.Inst.BaData.GetSpellFromPool(1, (ItemDropType)0, 0);
						list.Add(new ItemInfo((ItemType)1, spellFromPool));
						continue;
					}
					if (DataMgr.selectedWorldData.ActivateGirlHave4Pick2())
					{
						num3 /= 0.5f;
					}
					else if (DataMgr.selectedWorldData.ActivateGirlHave3Pick2())
					{
						num3 /= 0.666667f;
					}
					spellFromPool = ((num3 < num) ? PlayerMgr.Inst.BaData.GetSpellFromPool(1, (ItemDropType)3, 0) : ((!(num3 <= num + num2)) ? PlayerMgr.Inst.BaData.GetSpellFromPool(1, (ItemDropType)1, 0) : PlayerMgr.Inst.BaData.GetSpellFromPool(1, (ItemDropType)2, 0)));
					list.Add(new ItemInfo((ItemType)1, spellFromPool));
				}
				if (ScriptableObjMgr.Inst.testCtrller.Battle100PercentEpicItem && list.Count > 0)
				{
					if ((int)type == 1)
					{
						list[Random.Range(0, list.Count)] = new ItemInfo((ItemType)1, PlayerMgr.Inst.BaData.GetSpellFromPool(1, (ItemDropType)3, 0));
					}
					else if ((int)type == 2)
					{
						list[Random.Range(0, list.Count)] = new ItemInfo((ItemType)2, PlayerMgr.Inst.BaData.GetRelicFromPool((ItemDropType)3, (int[])null));
					}
				}
				__result = list;
				return false;
			}
			return true;
		}

		[HarmonyTranspiler]
		[HarmonyPatch(typeof(BattleData), "InitialPools")]
		public static IEnumerable<CodeInstruction> TranspilerPools(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			bool flag = false;
			for (int i = 0; i < list.Count - 4; i++)
			{
				if (list[i].opcode == OpCodes.Ldsfld && list[i + 1].opcode == OpCodes.Ldloc_S && list[i + 2].opcode == OpCodes.Callvirt && list[i + 3].opcode == OpCodes.Ldfld && list[i + 3].operand.ToString().Contains("dropType") && list[i + 4].opcode == OpCodes.Brfalse)
				{
					for (int j = i; j <= i + 4; j++)
					{
						list[j].opcode = OpCodes.Nop;
						list[j].operand = null;
					}
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				Debug.LogWarning((object)"Failed to find the target pattern in InitialPools method");
			}
			return list;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SecretSpells";

		public const string PLUGIN_NAME = "SecretSpells";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}