using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
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(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("BanAnything")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("BepInEx mod that bans items (curses, potions, relics, wands, spells) from appearing in runs with Gallery UI integration and unlimited spell disables")]
[assembly: AssemblyFileVersion("1.0.35.0")]
[assembly: AssemblyInformationalVersion("1.0.35+74f1688ad803e31f0e318e037aa44c7963d8dcae")]
[assembly: AssemblyProduct("BanAnything")]
[assembly: AssemblyTitle("BanAnything")]
[assembly: AssemblyVersion("1.0.35.0")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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 BanAnythingMod
{
[Serializable]
public class BanAnythingConfig
{
public List<int> bannedCurseIDs = new List<int>();
public List<int> bannedPotionIDs = new List<int>();
public List<int> bannedRelicIDs = new List<int>();
public List<int> bannedWandIDs = new List<int>();
}
public static class ConfigManager
{
private const string ConfigFileName = "BanAnythingConfig.txt";
private static ManualLogSource? Log;
public static void Initialize(ManualLogSource logger)
{
Log = logger;
}
private static string GetConfigPath()
{
string text = Path.Combine(Paths.PluginPath, "BanAnything");
Directory.CreateDirectory(text);
return Path.Combine(text, "BanAnythingConfig.txt");
}
public static BanAnythingConfig LoadConfig()
{
string configPath = GetConfigPath();
BanAnythingConfig banAnythingConfig = new BanAnythingConfig();
if (File.Exists(configPath))
{
try
{
string[] array = File.ReadAllLines(configPath);
string text = "";
string[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
string text2 = array2[i].Trim();
if (string.IsNullOrWhiteSpace(text2))
{
continue;
}
int result;
if (text2.StartsWith("[") && text2.EndsWith("]"))
{
text = text2.Substring(1, text2.Length - 2).ToLower();
}
else if (!text2.StartsWith("#") && int.TryParse(text2, out result))
{
switch (text)
{
case "curses":
banAnythingConfig.bannedCurseIDs.Add(result);
break;
case "potions":
banAnythingConfig.bannedPotionIDs.Add(result);
break;
case "relics":
banAnythingConfig.bannedRelicIDs.Add(result);
break;
case "wands":
banAnythingConfig.bannedWandIDs.Add(result);
break;
}
}
}
ManualLogSource? log = Log;
if (log != null)
{
log.LogInfo((object)("[BanAnything] Config loaded from " + configPath));
}
}
catch (Exception ex)
{
ManualLogSource? log2 = Log;
if (log2 != null)
{
log2.LogError((object)("[BanAnything] Error loading config: " + ex.Message));
}
}
}
else
{
SaveConfig(banAnythingConfig);
}
return banAnythingConfig;
}
public static void SaveConfig(BanAnythingConfig config)
{
string configPath = GetConfigPath();
try
{
List<string> list = new List<string> { "# Ban Anything Configuration", "# List item IDs to ban them from appearing in runs", "# One ID per line", "", "[Curses]", "# Curse IDs to ban" };
list.AddRange(config.bannedCurseIDs.Select((int id) => id.ToString()));
list.Add("");
list.Add("[Potions]");
list.Add("# Potion IDs to ban");
list.AddRange(config.bannedPotionIDs.Select((int id) => id.ToString()));
list.Add("");
list.Add("[Relics]");
list.Add("# Relic IDs to ban");
list.AddRange(config.bannedRelicIDs.Select((int id) => id.ToString()));
list.Add("");
list.Add("[Wands]");
list.Add("# Wand IDs to ban");
list.AddRange(config.bannedWandIDs.Select((int id) => id.ToString()));
File.WriteAllLines(configPath, list);
}
catch (Exception ex)
{
ManualLogSource? log = Log;
if (log != null)
{
log.LogError((object)("[BanAnything] Error saving config: " + ex.Message));
}
}
}
}
[BepInPlugin("com.magicraft.bananything", "Ban Anything", "1.0.35")]
public class BanAnythingPlugin : BaseUnityPlugin
{
public static class Patches
{
[HarmonyPatch(typeof(BattleData), "InitialPools")]
[HarmonyPostfix]
private static void InitialPools_Postfix(BattleData __instance)
{
try
{
if (Config == null)
{
return;
}
if (typeof(BattleData).GetField("poolOfCurse", BindingFlags.Instance | BindingFlags.Public)?.GetValue(__instance) is Dictionary<int, int> dictionary)
{
List<int> list = new List<int>();
foreach (int bannedCurseID in Config.bannedCurseIDs)
{
if (dictionary.ContainsKey(bannedCurseID))
{
dictionary.Remove(bannedCurseID);
list.Add(bannedCurseID);
}
}
if (list.Count > 0)
{
ManualLogSource? log = Log;
if (log != null)
{
log.LogInfo((object)string.Format("[BanAnything] Removed {0} banned curses from pool: {1}", list.Count, string.Join(", ", list)));
}
}
}
if (typeof(BattleData).GetField("poolOfPotionID", BindingFlags.Instance | BindingFlags.Public)?.GetValue(__instance) is List<int> list2)
{
List<int> list3 = new List<int>();
foreach (int bannedPotionID in Config.bannedPotionIDs)
{
if (list2.Contains(bannedPotionID))
{
list2.Remove(bannedPotionID);
list3.Add(bannedPotionID);
}
}
if (list3.Count > 0)
{
ManualLogSource? log2 = Log;
if (log2 != null)
{
log2.LogInfo((object)string.Format("[BanAnything] Removed {0} banned potions from pool: {1}", list3.Count, string.Join(", ", list3)));
}
}
}
if (typeof(BattleData).GetField("poolOfRelic", BindingFlags.Instance | BindingFlags.Public)?.GetValue(__instance) is Dictionary<int, int> dictionary2)
{
List<int> list4 = new List<int>();
foreach (int bannedRelicID in Config.bannedRelicIDs)
{
if (dictionary2.ContainsKey(bannedRelicID))
{
dictionary2.Remove(bannedRelicID);
list4.Add(bannedRelicID);
}
}
if (list4.Count > 0)
{
ManualLogSource? log3 = Log;
if (log3 != null)
{
log3.LogInfo((object)string.Format("[BanAnything] Removed {0} banned relics from pool: {1}", list4.Count, string.Join(", ", list4)));
}
}
}
if (!(typeof(BattleData).GetField("poolOfWandID", BindingFlags.Instance | BindingFlags.Public)?.GetValue(__instance) is List<int> list5))
{
return;
}
List<int> list6 = new List<int>();
foreach (int bannedWandID in Config.bannedWandIDs)
{
if (list5.Contains(bannedWandID))
{
list5.Remove(bannedWandID);
list6.Add(bannedWandID);
}
}
if (list6.Count > 0)
{
ManualLogSource? log4 = Log;
if (log4 != null)
{
log4.LogInfo((object)string.Format("[BanAnything] Removed {0} banned wands from pool: {1}", list6.Count, string.Join(", ", list6)));
}
}
}
catch (Exception ex)
{
ManualLogSource? log5 = Log;
if (log5 != null)
{
log5.LogError((object)("[BanAnything] Error in InitialPools patch: " + ex.Message));
}
}
}
[HarmonyPatch(typeof(BattleData), "BackCurseToPool")]
[HarmonyPrefix]
public static bool BackCurseToPool_Prefix(BattleData __instance, int id, int level)
{
try
{
BanAnythingConfig? config = Config;
if (config != null && config.bannedCurseIDs?.Contains(id) == true)
{
ManualLogSource? log = Log;
if (log != null)
{
log.LogInfo((object)$"[BanAnything] Blocked banned curse ID {id} from being re-added to pool");
}
return false;
}
}
catch (Exception ex)
{
ManualLogSource? log2 = Log;
if (log2 != null)
{
log2.LogError((object)("[BanAnything] Error in BackCurseToPool patch: " + ex?.Message));
}
}
return true;
}
[HarmonyPatch(typeof(BattleData), "BackRelicToPool")]
[HarmonyPrefix]
public static bool BackRelicToPool_Prefix(BattleData __instance, int id, int level)
{
try
{
BanAnythingConfig? config = Config;
if (config != null && config.bannedRelicIDs?.Contains(id) == true)
{
ManualLogSource? log = Log;
if (log != null)
{
log.LogInfo((object)$"[BanAnything] Blocked banned relic ID {id} from being re-added to pool");
}
return false;
}
}
catch (Exception ex)
{
ManualLogSource? log2 = Log;
if (log2 != null)
{
log2.LogError((object)("[BanAnything] Error in BackRelicToPool patch: " + ex?.Message));
}
}
return true;
}
[HarmonyPatch(typeof(BattleData), "BackWandToPool")]
[HarmonyPrefix]
public static bool BackWandToPool_Prefix(BattleData __instance, int id)
{
try
{
BanAnythingConfig? config = Config;
if (config != null && config.bannedWandIDs?.Contains(id) == true)
{
ManualLogSource? log = Log;
if (log != null)
{
log.LogInfo((object)$"[BanAnything] Blocked banned wand ID {id} from being re-added to pool");
}
return false;
}
}
catch (Exception ex)
{
ManualLogSource? log2 = Log;
if (log2 != null)
{
log2.LogError((object)("[BanAnything] Error in BackWandToPool patch: " + ex?.Message));
}
}
return true;
}
[HarmonyPatch(typeof(UISpellDisable), "Init")]
[HarmonyPrefix]
public static void UISpellDisable_Init_Prefix(UISpellDisable __instance)
{
try
{
int num = DataMgr.selectedWorldData.ActivateGirl_ExtraFreeDisableCount();
int num2 = DataMgr.selectedWorldData.ActivateGirl_ExtraMaxDisableCount();
__instance.defaultFreeDisableCount = 999 - num;
__instance.defaultMaxDisableCount = 999 - num2;
ManualLogSource? log = Log;
if (log != null)
{
log.LogInfo((object)$"[BanAnything] Init_Prefix: Girl bonuses - free={num}, max={num2}. Set defaults: free={__instance.defaultFreeDisableCount}, max={__instance.defaultMaxDisableCount}");
}
}
catch (Exception ex)
{
ManualLogSource? log2 = Log;
if (log2 != null)
{
log2.LogError((object)("[BanAnything] Error in UISpellDisable_Init prefix: " + ex?.Message));
}
}
}
[HarmonyPatch(typeof(UISpellDisable), "Init")]
[HarmonyPostfix]
public static void UISpellDisable_Init_Postfix(UISpellDisable __instance)
{
try
{
if (__instance.finalFreeDisableCount != 999 || __instance.finalMaxDisableCount != 999)
{
ManualLogSource? log = Log;
if (log != null)
{
log.LogWarning((object)$"[BanAnything] Init_Postfix: Values diverged from 999! Correcting: free={__instance.finalFreeDisableCount}→999, max={__instance.finalMaxDisableCount}→999");
}
__instance.finalFreeDisableCount = 999;
__instance.finalMaxDisableCount = 999;
typeof(UISpellDisable).GetMethod("UpdateResidualCount", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(__instance, null);
}
else
{
ManualLogSource? log2 = Log;
if (log2 != null)
{
log2.LogInfo((object)$"[BanAnything] Init_Postfix: Final unlimited values verified: free=999, max=999, disableCounter={__instance.disableCounter}");
}
}
}
catch (Exception ex)
{
ManualLogSource? log3 = Log;
if (log3 != null)
{
log3.LogError((object)("[BanAnything] Error in UISpellDisable_Init postfix: " + ex?.Message));
}
}
}
[HarmonyPatch(typeof(UISpellDisable), "SlotClick")]
[HarmonyPrefix]
public static void UISpellDisable_SlotClick_Debug(UISpellDisable __instance, UISpellDisableSlot slot)
{
try
{
ManualLogSource? log = Log;
if (log != null)
{
log.LogInfo((object)$"[BanAnything] SlotClick START - Spell ID: {slot.Level1ID}, disableCounter={__instance.disableCounter}, finalFreeDisableCount={__instance.finalFreeDisableCount}, finalMaxDisableCount={__instance.finalMaxDisableCount}, AlreadyDisable={slot.AlreadyDisable}");
}
}
catch (Exception ex)
{
ManualLogSource? log2 = Log;
if (log2 != null)
{
log2.LogError((object)("[BanAnything] Error in SlotClick debug: " + ex?.Message));
}
}
}
[HarmonyPatch(typeof(UISpellDisable), "SlotClick")]
[HarmonyPostfix]
public static void UISpellDisable_SlotClick_Debug_After(UISpellDisable __instance, UISpellDisableSlot slot)
{
try
{
ManualLogSource? log = Log;
if (log != null)
{
log.LogInfo((object)$"[BanAnything] SlotClick END - Spell ID: {slot.Level1ID}, disableCounter={__instance.disableCounter}, finalFreeDisableCount={__instance.finalFreeDisableCount}, AlreadyDisable={slot.AlreadyDisable}, costTypes.Count={__instance.costTypes.Count}");
}
}
catch (Exception ex)
{
ManualLogSource? log2 = Log;
if (log2 != null)
{
log2.LogError((object)("[BanAnything] Error in SlotClick debug after: " + ex?.Message));
}
}
}
[HarmonyPatch(typeof(UIGallery), "UpdateCurseSlots")]
[HarmonyPostfix]
private static void UpdateCurseSlots_Postfix(UIGallery __instance)
{
UpdateItemSlots(__instance, (GalleryCategory)6, "curseSlots");
}
[HarmonyPatch(typeof(UIGallery), "UpdatePotionSlots")]
[HarmonyPostfix]
private static void UpdatePotionSlots_Postfix(UIGallery __instance)
{
UpdateItemSlots(__instance, (GalleryCategory)5, "potionSlots");
}
[HarmonyPatch(typeof(UIGallery), "UpdateRelicSlots")]
[HarmonyPostfix]
private static void UpdateRelicSlots_Postfix(UIGallery __instance)
{
UpdateItemSlots(__instance, (GalleryCategory)4, "RelicSlots");
}
[HarmonyPatch(typeof(UIGallery), "UpdateWandSlots")]
[HarmonyPostfix]
private static void UpdateWandSlots_Postfix(UIGallery __instance)
{
UpdateItemSlots(__instance, (GalleryCategory)3, "wandSlots");
}
private static void UpdateItemSlots(UIGallery __instance, GalleryCategory category, string fieldName)
{
//IL_027d: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Invalid comparison between Unknown and I4
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Invalid comparison between Unknown and I4
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Invalid comparison between Unknown and I4
//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
//IL_01cf: Invalid comparison between Unknown and I4
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_0163: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Unknown result type (might be due to invalid IL or missing references)
try
{
if (!(((object)__instance).GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(__instance) is List<UIGallerySlot> list))
{
return;
}
int num = 0;
if ((int)category == 6)
{
foreach (CurseConfig item in CurseConfig.list)
{
if (num >= list.Count)
{
break;
}
int id = item.id;
if (IsItemBanned(category, id))
{
list[num].SpellBaned.gameObject.SetActive(true);
}
else
{
list[num].SpellBaned.gameObject.SetActive(false);
}
num++;
}
return;
}
if ((int)category == 5)
{
foreach (PotionConfig item2 in PotionConfig.list)
{
if (num >= list.Count)
{
break;
}
int id2 = item2.id;
if (IsItemBanned(category, id2))
{
list[num].SpellBaned.gameObject.SetActive(true);
}
else
{
list[num].SpellBaned.gameObject.SetActive(false);
}
num++;
}
return;
}
if ((int)category == 4)
{
foreach (RelicConfig item3 in RelicConfig.list)
{
if (num >= list.Count)
{
break;
}
if ((int)item3.dropType != 0)
{
int id3 = item3.id;
if (IsItemBanned(category, id3))
{
list[num].SpellBaned.gameObject.SetActive(true);
}
else
{
list[num].SpellBaned.gameObject.SetActive(false);
}
num++;
}
}
return;
}
if ((int)category != 3)
{
return;
}
foreach (WandConfig item4 in WandConfig.list)
{
if (num >= list.Count)
{
break;
}
if (item4.dropStage >= 1 && item4.dropStage <= 20)
{
int id4 = item4.id;
if (IsItemBanned(category, id4))
{
list[num].SpellBaned.gameObject.SetActive(true);
}
else
{
list[num].SpellBaned.gameObject.SetActive(false);
}
num++;
}
}
}
catch (Exception ex)
{
ManualLogSource? log = Log;
if (log != null)
{
log.LogError((object)$"[BanAnything] Error updating {category} slots: {ex.Message}");
}
}
}
}
private static ManualLogSource? Log;
private static Harmony? _harmony;
private static BanAnythingConfig? Config;
private void Awake()
{
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
Log.LogInfo((object)"Ban Anything mod loaded!");
ConfigManager.Initialize(Log);
GalleryInputHandler.Initialize(Log);
Config = ConfigManager.LoadConfig();
Log.LogInfo((object)$"[BanAnything] Loaded {Config.bannedCurseIDs.Count} banned curses, {Config.bannedPotionIDs.Count} banned potions, {Config.bannedRelicIDs.Count} banned relics, {Config.bannedWandIDs.Count} banned wands");
_harmony = new Harmony("com.magicraft.bananything");
_harmony.PatchAll(typeof(Patches));
_harmony.PatchAll(typeof(GalleryInputHandler));
_harmony.PatchAll(typeof(UIGallerySlotEnterPatch));
UIGallerySlotEnterPatch.SetLogger(Log);
Log.LogInfo((object)"Ban Anything: Harmony patches applied");
}
private void OnDestroy()
{
Harmony? harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
ManualLogSource? log = Log;
if (log != null)
{
log.LogInfo((object)"Ban Anything: Harmony patches removed");
}
}
private static bool IsItemDiscovered(GalleryCategory category, int itemID)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected I4, but got Unknown
return (category - 2) switch
{
4 => DataMgr.selectedWorldData.galleryUnlockedCurses.Contains(itemID),
3 => DataMgr.selectedWorldData.galleryUnlockedPotions.Contains(itemID),
2 => DataMgr.selectedWorldData.galleryUnlockedRelics.Contains(itemID),
1 => DataMgr.selectedWorldData.galleryUnlockedWands.Contains(itemID),
0 => DataMgr.selectedWorldData.galleryUnlockedSpells.Contains(itemID),
_ => false,
};
}
private static bool CanBanItem(GalleryCategory category, int itemID)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Invalid comparison between Unknown and I4
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Invalid comparison between Unknown and I4
if ((int)category == 4 && RelicConfig.dic.ContainsKey(itemID))
{
return (int)RelicConfig.dic[itemID].dropType != 4;
}
return true;
}
public static void ToggleBan(GalleryCategory category, int itemID)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Invalid comparison between Unknown and I4
//IL_0004: 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_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: 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_0098: Unknown result type (might be due to invalid IL or missing references)
if ((int)category == 2)
{
bool flag = IsItemDiscovered(category, itemID);
if (IsSpellDisabled(itemID))
{
ToggleSpellBan(itemID);
}
else if (flag)
{
ToggleSpellBan(itemID);
}
}
else
{
if (Config == null)
{
return;
}
bool flag2 = IsItemDiscovered(category, itemID);
List<int> banList = GetBanList(category);
if (banList.Contains(itemID))
{
banList.Remove(itemID);
ManualLogSource? log = Log;
if (log != null)
{
log.LogInfo((object)$"[BanAnything] Unbanned {category} ID {itemID}");
}
}
else
{
if (!flag2 || !CanBanItem(category, itemID))
{
return;
}
banList.Add(itemID);
ManualLogSource? log2 = Log;
if (log2 != null)
{
log2.LogInfo((object)$"[BanAnything] Banned {category} ID {itemID}");
}
}
ConfigManager.SaveConfig(Config);
}
}
private static List<int> GetBanList(GalleryCategory category)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected I4, but got Unknown
return (category - 3) switch
{
3 => Config?.bannedCurseIDs ?? new List<int>(),
2 => Config?.bannedPotionIDs ?? new List<int>(),
1 => Config?.bannedRelicIDs ?? new List<int>(),
0 => Config?.bannedWandIDs ?? new List<int>(),
_ => new List<int>(),
};
}
public static bool IsItemBanned(GalleryCategory category, int itemID)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Invalid comparison between Unknown and I4
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
if ((int)category == 2)
{
return IsSpellDisabled(itemID);
}
return GetBanList(category).Contains(itemID);
}
private static void ToggleSpellBan(int spellBaseID)
{
if (!GameMgr.HaveGame || DataMgr.selectedWorldData == null)
{
ManualLogSource? log = Log;
if (log != null)
{
log.LogWarning((object)"[BanAnything] Cannot toggle spell ban: game not active or world data unavailable");
}
return;
}
List<int> spellDisableCurrentBattle = DataMgr.selectedWorldData.battleData8.spellDisableCurrentBattle;
if (spellDisableCurrentBattle.Contains(spellBaseID))
{
PlayerMgr.Inst.BaData.AddSpellAllLevelToPool(spellBaseID);
PlayerMgr.Inst.BaData.CheckSpellPoolHaveRarity();
spellDisableCurrentBattle.Remove(spellBaseID);
ManualLogSource? log2 = Log;
if (log2 != null)
{
log2.LogInfo((object)$"[BanAnything] Re-enabled spell ID {spellBaseID}");
}
}
else
{
PlayerMgr.Inst.BaData.RemoveSpellAllLevelFromPool(spellBaseID);
PlayerMgr.Inst.BaData.CheckSpellPoolHaveRarity();
spellDisableCurrentBattle.Add(spellBaseID);
ManualLogSource? log3 = Log;
if (log3 != null)
{
log3.LogInfo((object)$"[BanAnything] Disabled spell ID {spellBaseID}");
}
}
}
private static bool IsSpellDisabled(int spellBaseID)
{
if (!GameMgr.HaveGame || DataMgr.selectedWorldData == null)
{
return false;
}
return DataMgr.selectedWorldData.battleData8.spellDisableCurrentBattle.Contains(spellBaseID);
}
}
public static class GalleryInputHandler
{
private static ManualLogSource? Log;
public static void Initialize(ManualLogSource logger)
{
Log = logger;
}
public static void RegisterPatches(Harmony harmony)
{
}
[HarmonyPatch(typeof(UIGallery), "RegistarOnlyWhenOpen")]
[HarmonyPostfix]
private static void UIGallery_RegistarOnlyWhenOpen_Postfix(UIGallery __instance)
{
try
{
PropertyInfo propertyInfo = ((object)__instance).GetType().BaseType?.GetProperty("inputActions", BindingFlags.Instance | BindingFlags.NonPublic);
if (propertyInfo == null)
{
propertyInfo = typeof(GameUI).GetProperty("inputActions", BindingFlags.Instance | BindingFlags.NonPublic);
}
if (propertyInfo == null)
{
ManualLogSource? log = Log;
if (log != null)
{
log.LogError((object)"[BanAnything] Failed to register A button: inputActions property not found");
}
return;
}
object value = propertyInfo.GetValue(__instance);
if (value == null)
{
ManualLogSource? log2 = Log;
if (log2 != null)
{
log2.LogError((object)"[BanAnything] Failed to register A button: inputActions object is null");
}
return;
}
PropertyInfo property = value.GetType().GetProperty("Player");
if (property == null)
{
ManualLogSource? log3 = Log;
if (log3 != null)
{
log3.LogError((object)"[BanAnything] Failed to register A button: Player property not found");
}
return;
}
object value2 = property.GetValue(value);
if (value2 == null)
{
ManualLogSource? log4 = Log;
if (log4 != null)
{
log4.LogError((object)"[BanAnything] Failed to register A button: Player object is null");
}
return;
}
PropertyInfo property2 = value2.GetType().GetProperty("Interact");
if (property2 == null)
{
ManualLogSource? log5 = Log;
if (log5 != null)
{
log5.LogError((object)"[BanAnything] Failed to register A button: Interact property not found");
}
return;
}
object value3 = property2.GetValue(value2);
if (value3 == null)
{
ManualLogSource? log6 = Log;
if (log6 != null)
{
log6.LogError((object)"[BanAnything] Failed to register A button: Interact action is null");
}
return;
}
EventInfo @event = value3.GetType().GetEvent("performed");
if (@event == null)
{
ManualLogSource? log7 = Log;
if (log7 != null)
{
log7.LogError((object)"[BanAnything] Failed to register A button: performed event not found");
}
return;
}
MethodInfo method = typeof(GalleryInputHandler).GetMethod("OnGalleryAButtonPerformed", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[2]
{
typeof(UIGallery),
typeof(object)
}, null);
if (method == null)
{
ManualLogSource? log8 = Log;
if (log8 != null)
{
log8.LogError((object)"[BanAnything] Failed to register A button: handler method not found");
}
return;
}
Type eventHandlerType = @event.EventHandlerType;
if (eventHandlerType == null)
{
ManualLogSource? log9 = Log;
if (log9 != null)
{
log9.LogError((object)"[BanAnything] Failed to register A button: event handler type could not be determined");
}
return;
}
Delegate @delegate = Delegate.CreateDelegate(eventHandlerType, __instance, method);
MethodInfo addMethod = @event.GetAddMethod();
if (addMethod == null)
{
ManualLogSource? log10 = Log;
if (log10 != null)
{
log10.LogError((object)"[BanAnything] Failed to register A button: could not get add method for performed event");
}
}
else
{
addMethod.Invoke(value3, new object[1] { @delegate });
}
}
catch (Exception ex)
{
ManualLogSource? log11 = Log;
if (log11 != null)
{
log11.LogError((object)("[BanAnything] Error registering A button handler: " + ex.Message));
}
}
}
[HarmonyPatch(typeof(UIGallery), "UnRegistarOnlyWhenHide")]
[HarmonyPostfix]
private static void UIGallery_UnRegistarOnlyWhenHide_Postfix(UIGallery __instance)
{
}
private static void OnGalleryAButtonPerformed(UIGallery __instance, object callbackContext)
{
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Invalid comparison between Unknown and I4
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Invalid comparison between Unknown and I4
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Invalid comparison between Unknown and I4
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_017f: Invalid comparison between Unknown and I4
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Invalid comparison between Unknown and I4
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Invalid comparison between Unknown and I4
//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Invalid comparison between Unknown and I4
try
{
FieldInfo field = ((object)__instance).GetType().GetField("hoveredSlots", BindingFlags.Instance | BindingFlags.NonPublic);
if (!(field != null) || !(field.GetValue(__instance) is UIGallerySlot[] array) || array.Length == 0)
{
return;
}
FieldInfo field2 = ((object)__instance).GetType().GetField("toggles", BindingFlags.Instance | BindingFlags.Public);
if (!(field2 != null) || !(field2.GetValue(__instance) is Array array2))
{
return;
}
for (int i = 0; i < array2.Length && i < array.Length; i++)
{
object value = array2.GetValue(i);
if (value == null)
{
continue;
}
PropertyInfo property = value.GetType().GetProperty("isOn");
if (!(property != null) || !(bool)property.GetValue(value))
{
continue;
}
UIGallerySlot slot = array[i];
if (!((Object)(object)slot != (Object)null) || ((int)slot.Category != 6 && (int)slot.Category != 5 && (int)slot.Category != 4 && (int)slot.Category != 3 && (int)slot.Category != 2))
{
break;
}
bool flag = false;
if ((int)slot.Category == 3)
{
WandConfig val = ((IEnumerable<WandConfig>)WandConfig.list).FirstOrDefault((Func<WandConfig, bool>)((WandConfig w) => w.id == slot.Level1ID));
if (val == null || val.dropStage < 1 || val.dropStage > 20)
{
flag = true;
}
}
else if ((int)slot.Category == 4)
{
RelicConfig val2 = ((IEnumerable<RelicConfig>)RelicConfig.list).FirstOrDefault((Func<RelicConfig, bool>)((RelicConfig r) => r.id == slot.Level1ID));
if (val2 == null || (int)val2.dropType == 0)
{
flag = true;
}
}
if (!flag)
{
BanAnythingPlugin.ToggleBan(slot.Category, slot.Level1ID);
slot.SpellBaned.gameObject.SetActive(BanAnythingPlugin.IsItemBanned(slot.Category, slot.Level1ID));
}
break;
}
}
catch (Exception ex)
{
ManualLogSource? log = Log;
if (log != null)
{
log.LogError((object)("[BanAnything] Error in A button ban toggle: " + ex.Message));
}
}
}
[HarmonyPatch(typeof(UIGallerySlot), "OnPointerClick")]
[HarmonyPrefix]
private static void OnPointerClick_Prefix(UIGallerySlot __instance)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Invalid comparison between Unknown and I4
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Invalid comparison between Unknown and I4
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Invalid comparison between Unknown and I4
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Invalid comparison between Unknown and I4
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Invalid comparison between Unknown and I4
try
{
if ((int)__instance.Category == 6 || (int)__instance.Category == 5 || (int)__instance.Category == 4 || (int)__instance.Category == 3 || (int)__instance.Category == 2)
{
BanAnythingPlugin.ToggleBan(__instance.Category, __instance.Level1ID);
__instance.SpellBaned.gameObject.SetActive(BanAnythingPlugin.IsItemBanned(__instance.Category, __instance.Level1ID));
}
}
catch (Exception ex)
{
ManualLogSource? log = Log;
if (log != null)
{
log.LogError((object)("[BanAnything] Error in OnPointerClick patch: " + ex.Message));
}
}
}
[HarmonyPatch(typeof(UIGallerySlot), "Hover")]
[HarmonyPostfix]
private static void UIGallerySlot_Hover_Postfix(UIGallerySlot __instance)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
try
{
if ((Object)(object)__instance.SpellBaned != (Object)null)
{
GalleryCategory category = __instance.Category;
int level1ID = __instance.Level1ID;
if (BanAnythingPlugin.IsItemBanned(category, level1ID))
{
__instance.SpellBaned.gameObject.SetActive(true);
}
}
}
catch (Exception ex)
{
ManualLogSource? log = Log;
if (log != null)
{
log.LogError((object)("[BanAnything] Error in UIGallerySlot Hover patch: " + ex.Message));
}
}
}
}
[HarmonyPatch(typeof(UIGallery), "SlotEnter")]
public class UIGallerySlotEnterPatch
{
private static FieldInfo? uiGalleryField = typeof(UIGallerySlot).GetField("uiGallery", BindingFlags.Instance | BindingFlags.NonPublic);
private static ManualLogSource? Log;
public static void SetLogger(ManualLogSource logger)
{
Log = logger;
}
[HarmonyPostfix]
public static void Postfix(UIGallerySlot slot)
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: 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_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Expected I4, but got Unknown
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Invalid comparison between Unknown and I4
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Invalid comparison between Unknown and I4
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)slot == (Object)null || uiGalleryField == null)
{
return;
}
object? value = uiGalleryField.GetValue(slot);
UIGallery val = (UIGallery)((value is UIGallery) ? value : null);
if ((Object)(object)val == (Object)null)
{
return;
}
GalleryCategory category = slot.Category;
Text val2 = (Text)((category - 2) switch
{
0 => val.text_SpellInfo,
1 => val.text_info,
2 => val.text_RelicInfo,
3 => val.text_PotionInfo,
4 => val.text_CurseInfo,
_ => null,
});
if (!((Object)(object)val2 != (Object)null))
{
return;
}
if (slot.IsLocked)
{
if (!string.IsNullOrEmpty(val2.text))
{
ManualLogSource? log = Log;
if (log != null)
{
log.LogWarning((object)$"{slot.Category} info not empty for locked slot: {val2.text}");
}
}
else
{
val2.text = "Cannot ban undiscovered items.";
((Graphic)val2).color = GameConst.color_InfoGrey;
((Component)val2).gameObject.SetActive(true);
}
}
else if ((int)slot.Category == 4)
{
RelicConfig obj = RelicConfig.dic[slot.Level1ID];
if (obj != null && (int)obj.dropType == 4)
{
val2.text = "Cannot ban Unique relics.\n" + val2.text;
((Component)val2).gameObject.SetActive(true);
}
}
}
}
}