using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using Alexandria.ItemAPI;
using BepInEx;
using BepInEx.Configuration;
using Gunfiguration;
using HarmonyLib;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using Newtonsoft.Json;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ItemBlacklist")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ItemBlacklist")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("17665fc7-b7f3-448d-b85b-22506f488236")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace ItemBlacklist;
public class BanSpriteController : MonoBehaviour
{
private tk2dClippedSprite banSprite;
private AmmonomiconPokedexEntry pokedexEntry;
private static int banSpriteId = -1;
private void Awake()
{
CreateBanSprite();
}
private void LateUpdate()
{
if ((Object)(object)banSprite != (Object)null && (Object)(object)pokedexEntry != (Object)null)
{
UpdateBanSpritePosition(banSprite, pokedexEntry);
pokedexEntry.UpdateClipping(banSprite);
}
}
private void CreateBanSprite()
{
AmmonomiconController instance = AmmonomiconController.Instance;
if (!((Object)(object)((instance != null) ? instance.CurrentLeftPageRenderer : null) == (Object)null) && banSpriteId != -1)
{
banSprite = AmmonomiconController.Instance.CurrentLeftPageRenderer.AddSpriteToPage<tk2dClippedSprite>(AmmonomiconController.Instance.EncounterIconCollection, banSpriteId);
if ((Object)(object)banSprite != (Object)null)
{
((tk2dBaseSprite)banSprite).SetSprite(AmmonomiconController.Instance.EncounterIconCollection, banSpriteId);
((BraveBehaviour)banSprite).transform.parent = ((Component)this).transform;
}
pokedexEntry = ((Component)this).GetComponent<AmmonomiconPokedexEntry>();
}
}
private void UpdateBanSpritePosition(tk2dClippedSprite banSprite, AmmonomiconPokedexEntry entry)
{
//IL_0035: 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: 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_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: 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_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)banSprite == (Object)null) && !((Object)(object)entry == (Object)null) && !((Object)(object)entry.m_childSprite == (Object)null) && !((Object)(object)entry.m_bgSprite == (Object)null))
{
Vector3 val = Vector2Extensions.ToVector3ZisY(((tk2dBaseSprite)entry.m_childSprite).WorldCenter, 0f);
Bounds bounds = ((tk2dBaseSprite)banSprite).GetBounds();
Vector3 size = ((Bounds)(ref bounds)).size;
Vector3 val2 = val - new Vector3(size.x / 2f, size.y / 2f, 0f);
((BraveBehaviour)banSprite).transform.position = Vector3Extensions.WithZ(val2, ((BraveBehaviour)entry.m_childSprite).transform.position.z - 0.1f);
}
}
private void OnDestroy()
{
if ((Object)(object)banSprite != (Object)null && (Object)(object)((Component)banSprite).gameObject != (Object)null)
{
Object.Destroy((Object)(object)((Component)banSprite).gameObject);
}
}
internal static void UpdateBanSprites(AmmonomiconPageRenderer pageRenderer)
{
List<AmmonomiconPokedexEntry> list = ((pageRenderer != null) ? pageRenderer.GetPokedexEntries() : null);
if (list == null)
{
return;
}
foreach (AmmonomiconPokedexEntry item in list)
{
if ((Object)(object)item == (Object)null || (Object)(object)((Component)item).gameObject == (Object)null)
{
continue;
}
EncounterDatabaseEntry linkedEncounterTrackable = item.linkedEncounterTrackable;
if (linkedEncounterTrackable == null)
{
continue;
}
string myGuid = ((AssetBundleDatabaseEntry)linkedEncounterTrackable).myGuid;
HashSet<string> hashSet = ItemBlacklistModule.instance?.blacklist;
if (!string.IsNullOrEmpty(myGuid) && hashSet != null)
{
bool flag = hashSet.Contains(myGuid);
bool flag2 = HasBanSprite(item);
if (flag && !flag2)
{
AddBanSprite(item);
}
else if (!flag && flag2)
{
RemoveBanSprite(item);
}
}
}
}
private static bool HasBanSprite(AmmonomiconPokedexEntry entry)
{
if ((Object)(object)entry != (Object)null && (Object)(object)((Component)entry).gameObject != (Object)null)
{
return (Object)(object)((Component)entry).gameObject.GetComponent<BanSpriteController>() != (Object)null;
}
return false;
}
private static void AddBanSprite(AmmonomiconPokedexEntry entry)
{
if (!((Object)(object)entry == (Object)null) && !((Object)(object)((Component)entry).gameObject == (Object)null))
{
((Component)entry).gameObject.AddComponent<BanSpriteController>();
}
}
private static void RemoveBanSprite(AmmonomiconPokedexEntry entry)
{
if (!((Object)(object)entry == (Object)null) && !((Object)(object)((Component)entry).gameObject == (Object)null))
{
BanSpriteController component = ((Component)entry).gameObject.GetComponent<BanSpriteController>();
if ((Object)(object)component != (Object)null)
{
Object.Destroy((Object)(object)component);
}
}
}
internal static void AddBanSpriteToCollection()
{
try
{
if (banSpriteId == -1)
{
banSpriteId = SpriteBuilder.AddSpriteToCollection("ItemBlacklist.ban_sprite", AmmonomiconController.ForceInstance.EncounterIconCollection, (Assembly)null);
}
}
catch (Exception ex)
{
Debug.LogError((object)("添加禁止图标失败:" + ex.Message + " Failed to add ban sprite: " + ex.Message));
}
}
}
public static class ItemBlacklistPatches
{
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
public class HandleTurnToNextPagePatch
{
[HarmonyPostfix]
public static void HandleTurnToNextPagePostfix(ref bool __result)
{
if (!__result && (Object)(object)cachedTargetTrackable != (Object)null)
{
AmmonomiconController instance = AmmonomiconController.Instance;
object obj;
if (instance == null)
{
obj = null;
}
else
{
AmmonomiconPageRenderer currentLeftPageRenderer = instance.CurrentLeftPageRenderer;
obj = ((currentLeftPageRenderer != null) ? currentLeftPageRenderer.GetPokedexEntry(cachedTargetTrackable) : null);
}
AmmonomiconPokedexEntry val = (AmmonomiconPokedexEntry)obj;
if ((Object)(object)val != (Object)null)
{
val.ForceFocus();
((MonoBehaviour)AmmonomiconController.Instance).StartCoroutine(FlashPokedexEntry(val));
cachedTargetTrackable = null;
}
}
}
private static void SetEntryColor(HashSet<string> blacklist, string guid, ref Color32 color)
{
if (!blacklist.Contains(guid))
{
color.g = byte.MaxValue;
color.b = byte.MaxValue;
}
else
{
color.g = 153;
color.b = 153;
}
}
private static IEnumerator FlashPokedexEntry(AmmonomiconPokedexEntry pokedexEntry)
{
if ((Object)(object)pokedexEntry == (Object)null)
{
yield break;
}
object obj;
if (pokedexEntry == null)
{
obj = null;
}
else
{
Transform transform = ((Component)pokedexEntry).transform;
if (transform == null)
{
obj = null;
}
else
{
Transform obj2 = transform.Find("Sliced Sprite");
obj = ((obj2 != null) ? ((Component)obj2).GetComponent<dfSlicedSprite>() : null);
}
}
dfSlicedSprite dfSlicedSprite = (dfSlicedSprite)obj;
if ((Object)(object)dfSlicedSprite == (Object)null)
{
yield break;
}
EncounterDatabaseEntry linkedEncounterTrackable = pokedexEntry.linkedEncounterTrackable;
HashSet<string> blacklist = ItemBlacklistModule.instance?.blacklist;
if (linkedEncounterTrackable == null || blacklist == null)
{
yield break;
}
string guid = ((AssetBundleDatabaseEntry)linkedEncounterTrackable).myGuid;
if (!string.IsNullOrEmpty(guid))
{
Color32 normalColor = ((dfControl)dfSlicedSprite).Color;
Color32 flashColor = new Color32((byte)254, (byte)224, (byte)0, byte.MaxValue);
int flashCount = 5;
float flashDuration = 0.15f;
for (int i = 0; i < flashCount; i++)
{
((dfControl)dfSlicedSprite).Color = flashColor;
yield return (object)new WaitForSecondsRealtime(flashDuration);
SetEntryColor(blacklist, guid, ref normalColor);
((dfControl)dfSlicedSprite).Color = normalColor;
yield return (object)new WaitForSecondsRealtime(flashDuration);
}
SetEntryColor(blacklist, guid, ref normalColor);
((dfControl)dfSlicedSprite).Color = normalColor;
}
}
}
[HarmonyPatch(typeof(AmmonomiconPokedexEntry), "Awake")]
public class AmmonomiconPokedexEntryAwakePatch
{
[HarmonyPostfix]
public static void AmmonomiconPokedexEntryAwakePostfix(AmmonomiconPokedexEntry __instance)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Expected O, but got Unknown
if ((Object)(object)__instance?.m_button != (Object)null)
{
((dfControl)__instance.m_button).Click += new MouseEventHandler(OnEntryClick);
}
}
private static void OnEntryClick(dfControl control, dfMouseEventArgs keyEvent)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Invalid comparison between Unknown and I4
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
if ((int)keyEvent.Buttons != 2)
{
return;
}
AmmonomiconPokedexEntry val = ((control != null) ? ((Component)control).GetComponent<AmmonomiconPokedexEntry>() : null);
if ((Object)(object)val == (Object)null || (int)val.encounterState != 0)
{
return;
}
EncounterDatabaseEntry linkedEncounterTrackable = val.linkedEncounterTrackable;
if (linkedEncounterTrackable == null || linkedEncounterTrackable.pickupObjectId == -1)
{
return;
}
string myGuid = ((AssetBundleDatabaseEntry)linkedEncounterTrackable).myGuid;
Dictionary<string, WeakBag<AmmonomiconPokedexEntry>> dictionary = ItemBlacklistModule.instance?.ammonomiconDictionary;
if (string.IsNullOrEmpty(myGuid) || dictionary == null)
{
return;
}
if (!val.IsEquipmentPage)
{
HashSet<string> hashSet = ItemBlacklistModule.instance?.blacklist;
object obj;
if (val == null)
{
obj = null;
}
else
{
Transform transform = ((Component)val).transform;
if (transform == null)
{
obj = null;
}
else
{
Transform obj2 = transform.Find("Sliced Sprite");
obj = ((obj2 != null) ? ((Component)obj2).GetComponent<dfSlicedSprite>() : null);
}
}
dfSlicedSprite val2 = (dfSlicedSprite)obj;
if ((Object)(object)val2 == (Object)null || hashSet == null)
{
return;
}
if (hashSet.Contains(myGuid))
{
hashSet.Remove(myGuid);
Color32 color = ((dfControl)val2).Color;
color.g = byte.MaxValue;
color.b = byte.MaxValue;
((dfControl)val2).Color = color;
ItemBlacklistModule.instance.RollbackWeight(myGuid);
if ((Object)(object)val.m_button != (Object)null && ((dfControl)val.m_button).HasFocus && GameManager.HasInstance)
{
AkSoundEngine.PostEvent("Play_UI_menu_select_01", ((Component)GameManager.Instance).gameObject);
}
}
else if (dictionary.ContainsKey(myGuid))
{
hashSet.Add(myGuid);
Color32 color2 = ((dfControl)val2).Color;
color2.g = 153;
color2.b = 153;
((dfControl)val2).Color = color2;
ItemBlacklistModule.instance.SetWeightToZero(myGuid);
if ((Object)(object)val.m_button != (Object)null && ((dfControl)val.m_button).HasFocus && GameManager.HasInstance)
{
AkSoundEngine.PostEvent("Play_UI_menu_select_01", ((Component)GameManager.Instance).gameObject);
}
}
return;
}
AmmonomiconController val3 = (AmmonomiconController.HasInstance ? AmmonomiconController.Instance : null);
if ((Object)(object)val3 == (Object)null || !dictionary.ContainsKey(myGuid))
{
return;
}
PickupObject byId = PickupObjectDatabase.GetById(linkedEncounterTrackable.pickupObjectId);
if ((Object)(object)byId == (Object)null)
{
return;
}
object obj3;
if (byId == null)
{
obj3 = null;
}
else
{
GameObject gameObject = ((Component)byId).gameObject;
obj3 = ((gameObject != null) ? gameObject.GetComponent<EncounterTrackable>() : null);
}
EncounterTrackable val4 = (EncounterTrackable)obj3;
if ((Object)(object)val4 == (Object)null)
{
return;
}
cachedTargetTrackable = val4;
AmmonomiconBookmarkController[] array = val3.m_AmmonomiconInstance?.bookmarks;
if (array == null)
{
return;
}
int num = ((byId is Gun) ? 1 : 2);
if (num < array.Length)
{
array[num].IsCurrentPage = true;
if ((Object)(object)val.m_button != (Object)null && ((dfControl)val.m_button).HasFocus && GameManager.HasInstance)
{
AkSoundEngine.PostEvent("Play_UI_menu_select_01", ((Component)GameManager.Instance).gameObject);
}
}
}
}
[HarmonyPatch(typeof(LootData), "GetItemForPlayer")]
public class LootDataGetItemForPlayerPatchClass
{
[HarmonyPrefix]
public static void LootDataGetItemForPlayerPrefix()
{
ItemBlacklistModule.instance?.SetAllWeightsToZero();
}
[HarmonyILManipulator]
public static void LootDataGetItemForPlayerPatch(ILContext ctx)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
ILCursor crs = new ILCursor(ctx);
if (TheNthTime(() => crs.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchCall<Object>(x, "op_Inequality")
}), 3))
{
crs.Emit(OpCodes.Ldloc_S, (byte)11);
crs.EmitCall<LootDataGetItemForPlayerPatchClass>("LootDataGetItemForPlayerPatchCall");
}
}
private static bool LootDataGetItemForPlayerPatchCall(bool orig, PickupObject pickupObject)
{
if ((Object)(object)pickupObject == (Object)null)
{
return orig;
}
if (ItemBlacklistModule.IsInBlacklist(pickupObject))
{
return false;
}
return orig;
}
}
[HarmonyPatch(typeof(RewardManager), "GetItemForPlayer")]
public class RewardManagerGetItemForPlayerPatchClass
{
[HarmonyPrefix]
public static void RewardManagerGetItemForPlayerPrefix()
{
ItemBlacklistModule.instance?.SetAllWeightsToZero();
}
[HarmonyILManipulator]
public static void RewardManagerGetItemForPlayerPatch(ILContext ctx)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
ILCursor crs = new ILCursor(ctx);
if (TheNthTime(() => crs.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchCall<Object>(x, "op_Inequality")
}), 2))
{
crs.Emit(OpCodes.Ldloc_S, (byte)7);
crs.EmitCall<RewardManagerGetItemForPlayerPatchClass>("RewardManagerGetItemForPlayerPatchCall");
}
}
private static bool RewardManagerGetItemForPlayerPatchCall(bool orig, PickupObject pickupObject)
{
if ((Object)(object)pickupObject == (Object)null)
{
return orig;
}
if (ItemBlacklistModule.IsInBlacklist(pickupObject))
{
return false;
}
return orig;
}
}
[HarmonyPatch(typeof(GunberMuncherController), "GetItemForPlayer")]
public class GunberMuncherControllerGetItemForPlayerPatchClass
{
[HarmonyPrefix]
public static void GunberMuncherControllerGetItemForPlayerPrefix()
{
ItemBlacklistModule.instance?.SetAllWeightsToZero();
}
[HarmonyILManipulator]
public static void GunberMuncherControllerGetItemForPlayerPatch(ILContext ctx)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
ILCursor crs = new ILCursor(ctx);
if (TheNthTime(() => crs.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchCall<Object>(x, "op_Inequality")
}), 5))
{
crs.Emit(OpCodes.Ldloc_S, (byte)9);
crs.EmitCall<GunberMuncherControllerGetItemForPlayerPatchClass>("GunberMuncherControllerGetItemForPlayerPatchCall");
}
}
private static bool GunberMuncherControllerGetItemForPlayerPatchCall(bool orig, PickupObject pickupObject)
{
if ((Object)(object)pickupObject == (Object)null)
{
return orig;
}
if (ItemBlacklistModule.IsInBlacklist(pickupObject))
{
return false;
}
return orig;
}
}
[HarmonyPatch(typeof(AmmonomiconController), "CloseAmmonomicon")]
public class CloseAmmonomiconPatch
{
[HarmonyPostfix]
public static void CloseAmmonomiconPostfix()
{
cachedTargetTrackable = null;
ItemBlacklistModule.instance?.SetAllWeightsToZero();
ItemBlacklistModule.instance?.SaveBlacklist();
}
}
[HarmonyPatch(typeof(LootEngine), "SpewLoot", new Type[]
{
typeof(GameObject),
typeof(Vector3)
})]
public class SpewLootPatchClass
{
[HarmonyILManipulator]
public static void SpewLootPatch(ILContext ctx)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchLdfld<PickupObject>(x, "PickupObjectId")
}))
{
val.EmitCall<SpewLootPatchClass>("SpewLootPatchCall");
}
}
private static int SpewLootPatchCall(int orig)
{
if (orig != GlobalItemIds.UnfinishedGun)
{
return orig;
}
ItemBlacklistModule instance = ItemBlacklistModule.instance;
if ((Object)(object)instance == (Object)null)
{
return orig;
}
if (instance.blacklist.Contains("90ff5de1e6af41d1baa820c6c0fc7647"))
{
return 1;
}
return orig;
}
}
[HarmonyPatch(typeof(LootEngine), "SpawnItem")]
public class SpawnItemPatchClass
{
[HarmonyILManipulator]
public static void SpawnItemPatch(ILContext ctx)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchLdfld<PickupObject>(x, "PickupObjectId")
}))
{
val.EmitCall<SpawnItemPatchClass>("SpawnItemPatchCall");
}
}
private static int SpawnItemPatchCall(int orig)
{
if (orig != GlobalItemIds.UnfinishedGun)
{
return orig;
}
ItemBlacklistModule instance = ItemBlacklistModule.instance;
if ((Object)(object)instance == (Object)null)
{
return orig;
}
if (instance.blacklist.Contains("90ff5de1e6af41d1baa820c6c0fc7647"))
{
return 1;
}
return orig;
}
}
[HarmonyPatch(typeof(LootData), "GetItemsForPlayer")]
public class GetItemsForPlayerPatchClass
{
[HarmonyILManipulator]
public static void GetItemsForPlayerPatch(ILContext ctx)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchLdfld<PickupObject>(x, "PickupObjectId")
}))
{
val.EmitCall<GetItemsForPlayerPatchClass>("GetItemsForPlayerPatchCall");
}
}
private static int GetItemsForPlayerPatchCall(int orig)
{
if (orig != GlobalItemIds.UnfinishedGun)
{
return orig;
}
ItemBlacklistModule instance = ItemBlacklistModule.instance;
if ((Object)(object)instance == (Object)null)
{
return orig;
}
if (instance.blacklist.Contains("90ff5de1e6af41d1baa820c6c0fc7647"))
{
return 1;
}
return orig;
}
}
[HarmonyPatch(typeof(AmmonomiconController), "LoadPageUIAtPath")]
public class LoadPageUIAtPathPatch
{
[HarmonyPostfix]
public static void LoadPageUIAtPathPostfix(AmmonomiconController __instance, PageType pageType)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Invalid comparison between Unknown and I4
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected I4, but got Unknown
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Expected I4, but got Unknown
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
if ((int)pageType <= 12)
{
return;
}
HashSet<int> hashSet = ItemBlacklistModule.instance?.extraPages;
HashSet<string> hashSet2 = ItemBlacklistModule.instance?.mainGuidSets;
if (hashSet == null || hashSet2 == null || hashSet.Contains((int)pageType))
{
return;
}
hashSet.Add((int)pageType);
foreach (AmmonomiconPokedexEntry item in __instance.m_extantPageMap?[pageType]?.m_pokedexEntries)
{
string text = ((AssetBundleDatabaseEntry)(item?.linkedEncounterTrackable?)).myGuid;
if (!string.IsNullOrEmpty(text) && hashSet2.Contains(text))
{
ItemBlacklistModule.instance?.AddToAmmonomiconPokedexEntryGroup(text, item);
ItemBlacklistModule.instance?.UpdateSavedEntry(text, item);
}
}
}
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
public class ConstructRectanglePageLayoutPatch
{
[HarmonyPostfix]
public static void ConstructRectanglePageLayoutPostfix(ref bool __result, object __instance)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Invalid comparison between Unknown and I4
if (!__result)
{
AmmonomiconPageRenderer fieldInEnumerator = GetFieldInEnumerator<AmmonomiconPageRenderer>(__instance, "this");
if (!((Object)(object)fieldInEnumerator == (Object)null) && (int)fieldInEnumerator.pageType == 1)
{
BanSpriteController.UpdateBanSprites(fieldInEnumerator);
}
}
}
}
[HarmonyPatch(typeof(PickupObjectDatabase), "GetRandomGun")]
public class GetRandomGunPatchClass
{
[HarmonyILManipulator]
public static void GetRandomGunPatch(ILContext ctx)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchIsinst<Gun>(x)
}))
{
val.EmitCall<GetRandomGunPatchClass>("GetRandomGunPatchCall");
}
}
private static Gun GetRandomGunPatchCall(Gun orig)
{
if ((Object)(object)orig == (Object)null)
{
return null;
}
if (ItemBlacklistModule.IsInBlacklist((PickupObject)(object)orig))
{
return null;
}
return orig;
}
}
[HarmonyPatch(typeof(PickupObjectDatabase), "GetRandomStartingGun")]
public class GetRandomStartingGunPatchClass
{
[HarmonyILManipulator]
public static void GetRandomStartingGunPatch(ILContext ctx)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchIsinst<Gun>(x)
}))
{
val.EmitCall<GetRandomStartingGunPatchClass>("GetRandomStartingGunPatchCall");
}
}
private static Gun GetRandomStartingGunPatchCall(Gun orig)
{
if ((Object)(object)orig == (Object)null)
{
return null;
}
if (ItemBlacklistModule.IsInBlacklist((PickupObject)(object)orig))
{
return null;
}
return orig;
}
}
[HarmonyPatch(typeof(PickupObjectDatabase), "GetRandomGunOfQualities")]
public class GetRandomGunOfQualitiesPatchClass
{
[HarmonyILManipulator]
public static void GetRandomGunOfQualitiesPatch(ILContext ctx)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchIsinst<Gun>(x)
}))
{
val.EmitCall<GetRandomGunOfQualitiesPatchClass>("GetRandomGunOfQualitiesPatchCall");
}
}
private static Gun GetRandomGunOfQualitiesPatchCall(Gun orig)
{
if ((Object)(object)orig == (Object)null)
{
return null;
}
if (ItemBlacklistModule.IsInBlacklist((PickupObject)(object)orig))
{
return null;
}
return orig;
}
}
[HarmonyPatch(typeof(PickupObjectDatabase), "GetRandomPassiveOfQualities")]
public class GetRandomPassiveOfQualitiesPatchClass
{
[HarmonyILManipulator]
public static void GetRandomPassiveOfQualitiesPatch(ILContext ctx)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchIsinst<PassiveItem>(x)
}))
{
val.EmitCall<GetRandomPassiveOfQualitiesPatchClass>("GetRandomPassiveOfQualitiesPatchCall");
}
}
private static PassiveItem GetRandomPassiveOfQualitiesPatchCall(PassiveItem orig)
{
if ((Object)(object)orig == (Object)null)
{
return null;
}
if (ItemBlacklistModule.IsInBlacklist((PickupObject)(object)orig))
{
return null;
}
return orig;
}
}
[HarmonyPatch]
public class GetRandomActiveOfQualitiesPatch
{
[HarmonyTargetMethod]
public static MethodBase TargetMethod()
{
return typeof(QoLConfig).GetNestedType("RandomizeParadoxEquipmentBetterPatch", BindingFlags.Public | BindingFlags.NonPublic)?.GetMethod("GetRandomActiveOfQualities", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2]
{
typeof(Random),
typeof(ItemQuality[])
}, null);
}
[HarmonyILManipulator]
public static void GetRandomPassiveOfQualitiesPatch(ILContext ctx)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchIsinst<PlayerItem>(x)
}))
{
val.EmitCall<GetRandomActiveOfQualitiesPatch>("GetRandomActiveOfQualitiesPatchCall");
}
}
private static PlayerItem GetRandomActiveOfQualitiesPatchCall(PlayerItem orig)
{
if ((Object)(object)orig == (Object)null)
{
return null;
}
if (ItemBlacklistModule.IsInBlacklist((PickupObject)(object)orig))
{
return null;
}
return orig;
}
}
[HarmonyPatch(typeof(LootEngine), "SpawnItem")]
public class LootEnginePatch
{
[HarmonyPrefix]
public static void SpawnItemPrefix(ref GameObject item)
{
ReplaceIfBlacklisted(ref item);
}
private static void ReplaceIfBlacklisted(ref GameObject item)
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Expected I4, but got Unknown
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Expected I4, but got Unknown
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Expected I4, but got Unknown
if ((Object)(object)ItemBlacklistModule.instance == (Object)null || !ItemBlacklistModule.instance.rollIfBlacklisted)
{
return;
}
PickupObject component = item.GetComponent<PickupObject>();
if ((Object)(object)component == (Object)null || !ItemBlacklistModule.IsInBlacklist(component))
{
return;
}
PickupObject val = null;
ItemQuality quality = component.quality;
int pickupObjectId = component.PickupObjectId;
Random random = new Random(Environment.TickCount ^ pickupObjectId ^ Random.Range(0, 65536));
for (int i = 0; i < 15; i++)
{
if (component is PassiveItem)
{
val = (PickupObject)(object)PickupObjectDatabase.GetRandomPassiveOfQualities(random, new List<int> { pickupObjectId }, (ItemQuality[])(object)new ItemQuality[1] { (ItemQuality)(int)quality });
}
else if (component is Gun)
{
val = (PickupObject)(object)PickupObjectDatabase.GetRandomGunOfQualities(random, new List<int> { pickupObjectId }, (ItemQuality[])(object)new ItemQuality[1] { (ItemQuality)(int)quality });
}
else if (component is PlayerItem)
{
val = (PickupObject)(object)GetRandomActiveOfQualities(random, new List<int> { pickupObjectId }, (ItemQuality)(int)quality);
}
if ((Object)(object)val == (Object)null || !ItemBlacklistModule.IsInBlacklist(val))
{
break;
}
pickupObjectId = val.PickupObjectId;
val = null;
}
if ((Object)(object)val != (Object)null)
{
item = ((Component)val).gameObject;
}
}
public static PlayerItem GetRandomActiveOfQualities(Random usedRandom, List<int> excludedIDs, params ItemQuality[] qualities)
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Invalid comparison between Unknown and I4
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Invalid comparison between Unknown and I4
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
List<PlayerItem> list = new List<PlayerItem>();
int num = 0;
int num2 = 0;
for (int i = 0; i < ((ObjectDatabase<PickupObject>)(object)PickupObjectDatabase.Instance).Objects.Count; i++)
{
PickupObject val = ((ObjectDatabase<PickupObject>)(object)PickupObjectDatabase.Instance).Objects[i];
if ((Object)(object)val == (Object)null || !(val is PlayerItem))
{
continue;
}
num++;
if (ItemBlacklistModule.IsInBlacklist(val))
{
num2++;
}
else if ((int)val.quality != -100 && (int)val.quality != -50 && !(val is ContentTeaserItem) && Array.IndexOf(qualities, val.quality) != -1 && (excludedIDs == null || !excludedIDs.Contains(val.PickupObjectId)))
{
EncounterTrackable component = ((Component)val).GetComponent<EncounterTrackable>();
if (Object.op_Implicit((Object)(object)component) && component.PrerequisitesMet())
{
list.Add((PlayerItem)(object)((val is PlayerItem) ? val : null));
}
}
}
if (list.Count == 0)
{
return null;
}
int index = usedRandom.Next(list.Count);
return list[index];
}
}
[HarmonyPatch]
public class GetItemOfTypeAndQualityPatchClass
{
private static MethodBase TargetMethod()
{
return typeof(LootEngine).GetMethod("GetItemOfTypeAndQuality").MakeGenericMethod(typeof(PickupObject));
}
[HarmonyILManipulator]
public static void GetItemOfTypeAndQualityPatch(ILContext ctx)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: 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)
ILCursor crs = new ILCursor(ctx);
if (crs.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchCallvirt<PickupObject>(x, "PrerequisitesMet")
}))
{
crs.Emit(OpCodes.Ldloc_2);
crs.Emit(OpCodes.Ldloc_1);
crs.EmitCall<GetItemOfTypeAndQualityPatchClass>("GetItemOfTypeAndQualityPatchCall_1");
}
crs.Index = 0;
if (TheNthTime(() => crs.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchCallvirt<PickupObject>(x, "PrerequisitesMet")
}), 2))
{
crs.Emit(OpCodes.Ldloc_S, (byte)6);
crs.EmitCall<GetItemOfTypeAndQualityPatchClass>("GetItemOfTypeAndQualityPatchCall_2");
}
}
private static bool GetItemOfTypeAndQualityPatchCall_1(bool orig, int i, List<WeightedGameObject> compiledRawItems)
{
object obj;
if (compiledRawItems == null)
{
obj = null;
}
else
{
WeightedGameObject obj2 = compiledRawItems[i];
if (obj2 == null)
{
obj = null;
}
else
{
GameObject gameObject = obj2.gameObject;
obj = ((gameObject != null) ? gameObject.GetComponent<PickupObject>() : null);
}
}
PickupObject val = (PickupObject)obj;
if ((Object)(object)val == (Object)null)
{
return orig;
}
if (ItemBlacklistModule.IsInBlacklist(val))
{
return false;
}
return orig;
}
private static bool GetItemOfTypeAndQualityPatchCall_2(bool orig, int j)
{
PickupObject val = ((ObjectDatabase<PickupObject>)(object)PickupObjectDatabase.Instance)?.Objects[j];
if ((Object)(object)val == (Object)null)
{
return orig;
}
if (ItemBlacklistModule.IsInBlacklist(val))
{
return false;
}
return orig;
}
}
private static EncounterTrackable cachedTargetTrackable;
public static void EmitCall<T>(this ILCursor iLCursor, string methodName, Type[] parameters = null, Type[] generics = null)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
MethodInfo methodInfo = AccessTools.Method(typeof(T), methodName, parameters, generics);
iLCursor.Emit(OpCodes.Call, (MethodBase)methodInfo);
}
public static T GetFieldInEnumerator<T>(object instance, string fieldNamePattern)
{
return (T)instance.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((FieldInfo f) => f.Name.Contains("$" + fieldNamePattern) || f.Name.Contains("<" + fieldNamePattern + ">") || f.Name == fieldNamePattern)
.GetValue(instance);
}
public static bool TheNthTime(this Func<bool> predict, int n = 1)
{
for (int i = 0; i < n; i++)
{
if (!predict())
{
return false;
}
}
return true;
}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("kleirof.etg.itemblacklist", "Item Blacklist", "1.0.9")]
public class ItemBlacklistModule : BaseUnityPlugin
{
public const string GUID = "kleirof.etg.itemblacklist";
public const string NAME = "Item Blacklist";
public const string VERSION = "1.0.9";
public const string TEXT_COLOR = "#AD8CFE";
internal Dictionary<string, WeakBag<AmmonomiconPokedexEntry>> ammonomiconDictionary = new Dictionary<string, WeakBag<AmmonomiconPokedexEntry>>();
internal static ItemBlacklistModule instance;
internal HashSet<string> blacklist = new HashSet<string>();
internal const string FINISHED_GUN_GUID = "90ff5de1e6af41d1baa820c6c0fc7647";
internal Dictionary<string, WeakBag<WeightedGameObject>> weightGroups = new Dictionary<string, WeakBag<WeightedGameObject>>();
internal WeakStrongDictionary<WeightedGameObject, float> oldWeights = new WeakStrongDictionary<WeightedGameObject, float>();
internal HashSet<string> mainGuidSets = new HashSet<string>();
internal HashSet<int> extraPages = new HashSet<int>();
private ConfigEntry<string> savePath;
private string finalSavePath;
private Gunfig gunfig;
private const string RollIfBlacklistedOnStr = "Roll If Blacklisted";
internal bool rollIfBlacklisted = true;
public void Start()
{
instance = this;
savePath = ((BaseUnityPlugin)this).Config.Bind<string>("ItemBlacklist", "SavePath", "[@BepInExConfigPath@]/blacklist_save.bl", "存档路径。支持以下变量:[@GameSavePath@] - 游戏存档目录;[@BepInExConfigPath@] - BepInEx配置目录;[@ModFolderPath@] - Mod所在目录。示例:[@BepInExConfigPath@]/blacklist_save.bl Save path. The following variables are supported: [@GameSavePath@] - game save directory; [@BepInExConfigPath@] - BepInEx configuration directory; [@ModFolderPath@] - directory containing mods. Example: [@BepInExConfigPath@]/blacklist_save.bl");
ETGModMainBehaviour.WaitForGameManagerStart((Action<GameManager>)GMStart);
}
public void GMStart(GameManager g)
{
//IL_0014: 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_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Invalid comparison between Unknown and I4
Log("Item Blacklist v1.0.9 started successfully.", "#AD8CFE");
new Harmony("kleirof.etg.itemblacklist").PatchAll();
finalSavePath = ResolveSavePath(savePath.Value);
gunfig = Gunfig.Get(GunfigHelpers.WithColor("Item Blacklist", Color.white));
gunfig.AddToggle("Roll If Blacklisted", true, ((int)GameManager.Options.CurrentLanguage == 11) ? "重随机黑名单物品" : "Roll If Blacklisted", (Action<string, string>)delegate(string optionKey, string optionValue)
{
UpdateRollBlacklisted(optionValue);
}, (Update)1);
UpdateRollBlacklisted();
((MonoBehaviour)g).StartCoroutine(DelayInitialize());
}
private string ResolveSavePath(string pathWithVariables)
{
if ((Object)(object)instance == (Object)null)
{
return GetDefaultPath();
}
if (string.IsNullOrEmpty(pathWithVariables))
{
return GetDefaultPath();
}
try
{
string fullPath = Path.GetFullPath(pathWithVariables.Replace("[@GameSavePath@]", SaveManager.SavePath ?? ".").Replace("[@BepInExConfigPath@]", Paths.ConfigPath ?? ".").Replace("[@ModFolderPath@]", ETGMod.FolderPath((BaseUnityPlugin)(object)instance) ?? "."));
return ValidateResolvedPath(fullPath) ? fullPath : GetDefaultPath();
}
catch
{
return GetDefaultPath();
}
}
private static bool ValidateResolvedPath(string path)
{
try
{
string fullPath = Path.GetFullPath(path);
string directoryName = Path.GetDirectoryName(fullPath);
string fileName = Path.GetFileName(fullPath);
return !string.IsNullOrEmpty(directoryName) && !string.IsNullOrEmpty(fileName) && !fileName.Any((char c) => Path.GetInvalidFileNameChars().Contains(c));
}
catch
{
return false;
}
}
private static string GetDefaultPath()
{
return Path.Combine(Paths.ConfigPath ?? ".", "blacklist_save.bl");
}
public static void Log(string text, string color = "FFFFFF")
{
ETGModConsole.Log((object)("<color=" + color + ">" + text + "</color>"), false);
}
internal void AddToWeightedGameObjectGroup(string groupId, WeightedGameObject weighted)
{
if (!weightGroups.TryGetValue(groupId, out var value))
{
value = new WeakBag<WeightedGameObject>();
weightGroups[groupId] = value;
}
value.Add(weighted);
mainGuidSets.Add(groupId);
}
internal void AddToAmmonomiconPokedexEntryGroup(string groupId, AmmonomiconPokedexEntry pokedexEntry)
{
if (!ammonomiconDictionary.TryGetValue(groupId, out var value))
{
value = new WeakBag<AmmonomiconPokedexEntry>();
ammonomiconDictionary[groupId] = value;
}
value.Add(pokedexEntry);
}
private IEnumerator DelayInitialize()
{
yield return null;
yield return null;
yield return null;
GameManager obj2 = GameManager.Instance;
List<WeightedGameObject> gunWeights = ((obj2 == null) ? null : obj2.RewardManager?.GunsLootTable?.defaultItemDrops?.elements);
GameManager obj3 = GameManager.Instance;
List<WeightedGameObject> itemWeights = ((obj3 == null) ? null : obj3.RewardManager?.ItemsLootTable?.defaultItemDrops?.elements);
yield return null;
yield return null;
AmmonomiconController.EnsureExistence();
yield return null;
yield return null;
BanSpriteController.AddBanSpriteToCollection();
while (AmmonomiconController.Instance?.m_extantPageMap == null)
{
yield return null;
}
while (!AmmonomiconController.Instance.m_extantPageMap.ContainsKey((PageType)3) || !AmmonomiconController.Instance.m_extantPageMap.ContainsKey((PageType)5))
{
yield return null;
}
List<AmmonomiconPokedexEntry> list = AmmonomiconController.Instance.m_extantPageMap[(PageType)3]?.m_pokedexEntries;
List<AmmonomiconPokedexEntry> list2 = AmmonomiconController.Instance.m_extantPageMap[(PageType)5]?.m_pokedexEntries;
if (gunWeights == null || itemWeights == null || list == null || list2 == null)
{
yield break;
}
GenericLootTable[] array = (from obj in Resources.FindObjectsOfTypeAll<GenericLootTable>()
where (Object)(object)obj != (Object)null && ((Object)obj).GetInstanceID() != 0
select obj).ToArray();
for (int i = 0; i < array.Length; i++)
{
List<WeightedGameObject> list3 = array[i]?.defaultItemDrops?.elements;
if (list3 == null)
{
continue;
}
foreach (WeightedGameObject item in list3)
{
object obj4;
if (item == null)
{
obj4 = null;
}
else
{
GameObject gameObject = item.gameObject;
obj4 = ((gameObject != null) ? gameObject.GetComponent<PickupObject>() : null);
}
PickupObject val = (PickupObject)obj4;
if ((Object)(object)val != (Object)null)
{
EncounterTrackable encounterTrackable = ((BraveBehaviour)val).encounterTrackable;
object obj5 = ((encounterTrackable != null) ? encounterTrackable.TrueEncounterGuid : null);
if (obj5 == null)
{
EncounterTrackable component = ((Component)val).GetComponent<EncounterTrackable>();
obj5 = ((component != null) ? component.TrueEncounterGuid : null);
}
string text = (string)obj5;
if (!string.IsNullOrEmpty(text))
{
oldWeights[item] = item.weight;
AddToWeightedGameObjectGroup(text, item);
}
}
}
}
foreach (AmmonomiconPokedexEntry item2 in list)
{
string text2 = ((AssetBundleDatabaseEntry)(item2?.linkedEncounterTrackable?)).myGuid;
if (!string.IsNullOrEmpty(text2) && mainGuidSets.Contains(text2))
{
AddToAmmonomiconPokedexEntryGroup(text2, item2);
}
}
foreach (AmmonomiconPokedexEntry item3 in list2)
{
string text3 = ((AssetBundleDatabaseEntry)(item3?.linkedEncounterTrackable?)).myGuid;
if (!string.IsNullOrEmpty(text3) && mainGuidSets.Contains(text3))
{
AddToAmmonomiconPokedexEntryGroup(text3, item3);
}
}
LoadBlacklist();
SetAllWeightsToZero();
}
internal void RollbackWeight(string guid)
{
if (string.IsNullOrEmpty(guid) || !weightGroups.TryGetValue(guid, out var value))
{
return;
}
foreach (WeightedGameObject item in value)
{
if (!oldWeights.TryGetValue(item, out var value2))
{
break;
}
item.weight = value2;
}
}
internal void SetAllWeightsToZero()
{
foreach (string item in blacklist)
{
SetWeightToZero(item);
}
}
internal void SetWeightToZero(string guid)
{
if (string.IsNullOrEmpty(guid) || !weightGroups.TryGetValue(guid, out var value))
{
return;
}
foreach (WeightedGameObject item in value)
{
if (item != null && !(item.weight <= Mathf.Epsilon))
{
oldWeights[item] = item.weight;
item.weight = 0f;
}
}
}
internal void UpdateSavedEntry(string guid, AmmonomiconPokedexEntry ammonomiconEntry)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//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_009c: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)ammonomiconEntry == (Object)null || (int)ammonomiconEntry.encounterState != 0 || ammonomiconEntry.IsEquipmentPage)
{
return;
}
EncounterDatabaseEntry linkedEncounterTrackable = ammonomiconEntry.linkedEncounterTrackable;
if (linkedEncounterTrackable == null || linkedEncounterTrackable.pickupObjectId == -1)
{
return;
}
object obj;
if (ammonomiconEntry == null)
{
obj = null;
}
else
{
Transform transform = ((Component)ammonomiconEntry).transform;
if (transform == null)
{
obj = null;
}
else
{
Transform obj2 = transform.Find("Sliced Sprite");
obj = ((obj2 != null) ? ((Component)obj2).GetComponent<dfSlicedSprite>() : null);
}
}
dfSlicedSprite val = (dfSlicedSprite)obj;
if (!((Object)(object)val == (Object)null) && blacklist != null && blacklist.Contains(guid))
{
Color32 color = ((dfControl)val).Color;
color.g = 153;
color.b = 153;
((dfControl)val).Color = color;
}
}
public void SaveBlacklist()
{
try
{
string text = finalSavePath;
if (string.IsNullOrEmpty(text))
{
return;
}
HashSet<string> obj = (File.Exists(text) ? new HashSet<string>(JsonConvert.DeserializeObject<List<string>>(File.ReadAllText(text)) ?? new List<string>()) : new HashSet<string>());
HashSet<string> hashSet = new HashSet<string>();
foreach (string item in obj)
{
if (!string.IsNullOrEmpty(item) && !mainGuidSets.Contains(item))
{
hashSet.Add(item);
}
}
foreach (string item2 in blacklist)
{
if (!string.IsNullOrEmpty(item2) && mainGuidSets.Contains(item2))
{
hashSet.Add(item2);
}
}
Directory.CreateDirectory(Path.GetDirectoryName(text));
File.WriteAllText(text, JsonConvert.SerializeObject((object)hashSet.ToList(), (Formatting)1));
Debug.Log((object)$"Blacklist共保存 {hashSet.Count} 项,保存路径 {text}\nBlacklist saved {hashSet.Count} items, save path {text}");
}
catch (Exception ex)
{
Debug.LogError((object)("Blacklist保存失败: " + ex.Message + " Blacklist save failed: " + ex.Message));
}
}
public void LoadBlacklist()
{
try
{
string text = finalSavePath;
if (string.IsNullOrEmpty(text))
{
return;
}
if (!File.Exists(text))
{
Debug.Log((object)"黑名单文件不存在。 Blacklist file does not exist.");
blacklist.Clear();
return;
}
List<string> list = JsonConvert.DeserializeObject<List<string>>(File.ReadAllText(text)) ?? new List<string>();
blacklist.Clear();
foreach (string item in list)
{
if (!string.IsNullOrEmpty(item) && mainGuidSets.Contains(item))
{
blacklist.Add(item);
}
}
foreach (string item2 in blacklist)
{
if (!ammonomiconDictionary.TryGetValue(item2, out var value))
{
continue;
}
foreach (AmmonomiconPokedexEntry item3 in value)
{
UpdateSavedEntry(item2, item3);
}
}
Debug.Log((object)($"Blacklist加载,文件中有 {list.Count} 项,加载了 {blacklist.Count} 项有效条目,加载路径 {text}\n" + $"Blacklist loaded, {list.Count} items in file, {blacklist.Count} valid items loaded, load path {text}"));
}
catch (Exception ex)
{
Debug.LogError((object)("Blacklist加载失败: " + ex.Message + " Blacklist load failed: " + ex.Message));
blacklist.Clear();
}
}
internal static bool IsInBlacklist(PickupObject pickupObject)
{
if ((Object)(object)pickupObject == (Object)null)
{
return false;
}
EncounterTrackable encounterTrackable = ((BraveBehaviour)pickupObject).encounterTrackable;
object obj = ((encounterTrackable != null) ? encounterTrackable.TrueEncounterGuid : null);
if (obj == null)
{
EncounterTrackable component = ((Component)pickupObject).GetComponent<EncounterTrackable>();
obj = ((component != null) ? component.TrueEncounterGuid : null);
}
string text = (string)obj;
if (string.IsNullOrEmpty(text))
{
return false;
}
return (instance?.blacklist)?.Contains(text) ?? false;
}
private void UpdateRollBlacklisted(string value = null)
{
if (value == null)
{
value = gunfig.Value("Roll If Blacklisted");
}
rollIfBlacklisted = value == "1";
}
private void OnApplicationQuit()
{
SaveBlacklist();
}
}
public sealed class WeakBag<T> : IEnumerable<T>, IEnumerable where T : class
{
public struct Enumerator : IEnumerator<T>, IDisposable, IEnumerator
{
private readonly WeakBag<T> _bag;
private int _index;
private T _current;
public T Current => _current;
object IEnumerator.Current => _current;
internal Enumerator(WeakBag<T> bag)
{
_bag = bag;
_index = -1;
_current = null;
}
public bool MoveNext()
{
while (++_index < _bag._count)
{
if (_bag._items[_index] != null && _bag.IsAlive(_bag._items[_index]))
{
_current = (T)_bag._items[_index].Target;
return true;
}
}
return false;
}
public void Dispose()
{
}
public void Reset()
{
_index = -1;
}
}
private WeakReference[] _items;
private int _count;
private readonly bool _isUnityObject;
public int Capacity => _items.Length;
public int Count
{
get
{
int num = 0;
for (int i = 0; i < _count; i++)
{
if (_items[i] != null && IsAlive(_items[i]))
{
num++;
}
}
return num;
}
}
public WeakBag(int initialCapacity = 4)
{
if (initialCapacity < 1)
{
initialCapacity = 1;
}
_items = new WeakReference[initialCapacity];
_isUnityObject = typeof(Object).IsAssignableFrom(typeof(T));
}
public bool Add(T item)
{
if (item == null)
{
throw new ArgumentNullException("item");
}
EnsureCapacity(_count + 1);
for (int i = 0; i < _count; i++)
{
if (_items[i] != null)
{
object target = _items[i].Target;
if (target != null && IsAlive(_items[i]) && target == item)
{
return false;
}
}
}
int num = FindFreeSlot();
_items[num] = new WeakReference(item);
if (num >= _count)
{
_count = num + 1;
}
return true;
}
public int AddRange(IEnumerable<T> items)
{
int num = 0;
foreach (T item in items)
{
if (Add(item))
{
num++;
}
}
return num;
}
public int CleanDeadItems()
{
int num = 0;
int num2 = 0;
for (int i = 0; i < _count; i++)
{
if (_items[i] == null || !IsAlive(_items[i]))
{
_items[i] = null;
num++;
continue;
}
if (num2 != i)
{
_items[num2] = _items[i];
_items[i] = null;
}
num2++;
}
_count = num2;
return num;
}
public bool NeedsCleanup()
{
for (int i = 0; i < _count; i++)
{
if (_items[i] != null && !IsAlive(_items[i]))
{
return true;
}
}
return false;
}
public T[] ToArray()
{
CleanDeadItems();
T[] array = new T[_count];
for (int i = 0; i < _count; i++)
{
array[i] = (T)_items[i].Target;
}
return array;
}
public List<T> ToList()
{
CleanDeadItems();
List<T> list = new List<T>(_count);
for (int i = 0; i < _count; i++)
{
list.Add((T)_items[i].Target);
}
return list;
}
public bool Contains(T item)
{
if (item == null)
{
return false;
}
for (int i = 0; i < _count; i++)
{
if (_items[i] != null)
{
object target = _items[i].Target;
if (target != null && IsAlive(_items[i]) && target == item)
{
return true;
}
}
}
return false;
}
public bool Remove(T item)
{
if (item == null)
{
return false;
}
for (int i = 0; i < _count; i++)
{
if (_items[i] != null)
{
object target = _items[i].Target;
if (target != null && IsAlive(_items[i]) && target == item)
{
_items[i] = null;
return true;
}
}
}
return false;
}
public void Clear()
{
Array.Clear(_items, 0, _count);
_count = 0;
}
public Enumerator GetEnumerator()
{
return new Enumerator(this);
}
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
return GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
private void EnsureCapacity(int min)
{
if (_items.Length < min)
{
int newSize = Math.Max(_items.Length * 2, min);
Array.Resize(ref _items, newSize);
}
}
private int FindFreeSlot()
{
for (int i = 0; i < _count; i++)
{
if (_items[i] == null)
{
return i;
}
}
return _count;
}
private bool IsAlive(WeakReference wr)
{
object target = wr.Target;
if (target == null)
{
return false;
}
if (_isUnityObject)
{
return (Object)((target is Object) ? target : null) != (Object)null;
}
return true;
}
public int GetTotalSlots()
{
return _count;
}
public int GetAliveCount()
{
return Count;
}
public int GetDeadCount()
{
int num = 0;
for (int i = 0; i < _count; i++)
{
if (_items[i] != null && !IsAlive(_items[i]))
{
num++;
}
}
return num;
}
public int GetFreeSlotCount()
{
int num = 0;
for (int i = 0; i < _count; i++)
{
if (_items[i] == null)
{
num++;
}
}
return num;
}
public float GetLoadFactor()
{
return (float)GetAliveCount() / (float)_items.Length;
}
}
public sealed class WeakStrongDictionary<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable where TKey : class
{
private struct Entry
{
public int Hash;
public int Next;
public WeakReference Key;
public TValue Value;
}
public struct Enumerator : IEnumerator<KeyValuePair<TKey, TValue>>, IDisposable, IEnumerator
{
private readonly Entry[] _entries;
private readonly int _end;
private int _index;
private KeyValuePair<TKey, TValue> _current;
public KeyValuePair<TKey, TValue> Current => _current;
object IEnumerator.Current => _current;
internal Enumerator(WeakStrongDictionary<TKey, TValue> dict)
{
_entries = dict._entries;
_end = dict._count;
_index = -1;
_current = default(KeyValuePair<TKey, TValue>);
}
public bool MoveNext()
{
while (++_index < _end)
{
Entry entry = _entries[_index];
WeakReference key = entry.Key;
if (key == null)
{
continue;
}
object target = key.Target;
if (target != null)
{
Object val = (Object)((target is Object) ? target : null);
if (val == null || !(val == (Object)null))
{
_current = new KeyValuePair<TKey, TValue>((TKey)target, entry.Value);
return true;
}
}
}
return false;
}
public void Dispose()
{
}
public void Reset()
{
_index = -1;
}
}
private const float LoadFactor = 0.9f;
private const int MinCapacity = 16;
private int[] _buckets;
private Entry[] _entries;
private int _count;
private int _freeList;
private int _liveCount;
private readonly IEqualityComparer<TKey> _comparer;
private readonly bool _isUnityObject;
private static readonly int[] Primes = new int[61]
{
3, 7, 11, 17, 23, 29, 37, 47, 59, 71,
89, 107, 131, 163, 197, 239, 293, 353, 431, 521,
631, 761, 919, 1103, 1327, 1597, 1931, 2333, 2801, 3371,
4049, 4861, 5839, 7013, 8419, 10103, 12143, 14591, 17519, 21023,
25229, 30293, 36353, 43627, 52361, 62851, 75431, 90523, 108631, 130363,
156437, 187751, 225307, 270371, 324449, 389357, 467237, 560689, 672827, 807403,
968897
};
public int Count => _liveCount;
public int Capacity => _entries.Length;
public TValue this[TKey key]
{
get
{
if (TryGetValue(key, out var value))
{
return value;
}
throw new KeyNotFoundException();
}
set
{
AddOrUpdate(key, value);
}
}
public IEnumerable<TKey> Keys
{
get
{
for (int i = 0; i < _count; i++)
{
if (TryGetAliveKey(_entries[i], out var key))
{
yield return key;
}
}
}
}
public IEnumerable<TValue> Values
{
get
{
for (int i = 0; i < _count; i++)
{
if (TryGetAliveKey(_entries[i], out var _))
{
yield return _entries[i].Value;
}
}
}
}
public WeakStrongDictionary(int capacity = 16, IEqualityComparer<TKey> comparer = null)
{
capacity = Math.Max(capacity, 16);
capacity = GetPrime(capacity);
_buckets = new int[capacity];
_entries = new Entry[capacity];
_freeList = -1;
_comparer = comparer ?? EqualityComparer<TKey>.Default;
_isUnityObject = typeof(Object).IsAssignableFrom(typeof(TKey));
}
public bool ContainsKey(TKey key)
{
TValue value;
return TryGetValue(key, out value);
}
public bool TryGetValue(TKey key, out TValue value)
{
value = default(TValue);
if (key == null)
{
return false;
}
int hash = GetHash(key);
int num = hash % _buckets.Length;
int num2 = _buckets[num] - 1;
int num3 = -1;
while (num2 >= 0)
{
Entry e = _entries[num2];
if (!TryGetAliveKey(e, out var key2))
{
RemoveEntry(num, num2, num3);
num2 = ((num3 < 0) ? (_buckets[num] - 1) : _entries[num3].Next);
continue;
}
if (e.Hash == hash && _comparer.Equals(key2, key))
{
value = e.Value;
return true;
}
num3 = num2;
num2 = e.Next;
}
return false;
}
public void AddOrUpdate(TKey key, TValue value)
{
if (key == null)
{
throw new ArgumentNullException("key");
}
int hash = GetHash(key);
if (FindEntry(hash, key, out var bucket, out var index, out var _))
{
_entries[index].Value = value;
return;
}
if (_count == _entries.Length || (float)_liveCount >= (float)_entries.Length * 0.9f)
{
Resize(_entries.Length * 2);
bucket = hash % _buckets.Length;
}
int num = AllocateEntry();
_entries[num].Hash = hash;
_entries[num].Key = new WeakReference(key);
_entries[num].Value = value;
_entries[num].Next = _buckets[bucket] - 1;
_buckets[bucket] = num + 1;
_liveCount++;
}
public bool TryRemove(TKey key, out TValue value)
{
value = default(TValue);
if (key == null)
{
return false;
}
int hash = GetHash(key);
int num = hash % _buckets.Length;
int num2 = _buckets[num] - 1;
int num3 = -1;
while (num2 >= 0)
{
Entry e = _entries[num2];
if (!TryGetAliveKey(e, out var key2))
{
RemoveEntry(num, num2, num3);
num2 = ((num3 < 0) ? (_buckets[num] - 1) : _entries[num3].Next);
continue;
}
if (e.Hash == hash && _comparer.Equals(key2, key))
{
value = e.Value;
RemoveEntry(num, num2, num3);
return true;
}
num3 = num2;
num2 = e.Next;
}
return false;
}
public int CleanDeadKeys()
{
int num = 0;
for (int i = 0; i < _buckets.Length; i++)
{
int num2 = -1;
int num3 = _buckets[i] - 1;
while (num3 >= 0)
{
Entry e = _entries[num3];
if (TryGetAliveKey(e, out var _))
{
num2 = num3;
num3 = e.Next;
}
else
{
RemoveEntry(i, num3, num2);
num++;
num3 = ((num2 < 0) ? (_buckets[i] - 1) : _entries[num2].Next);
}
}
}
return num;
}
public void EnsureCapacity(int capacity)
{
if (capacity > _liveCount)
{
int num = (int)((float)capacity / 0.9f);
if (num > _entries.Length)
{
Resize(num);
}
}
}
public void TrimExcess()
{
if (_liveCount == 0)
{
Clear();
return;
}
int prime = GetPrime((int)((float)_liveCount / 0.9f));
prime = Math.Max(prime, 16);
if (prime < _entries.Length)
{
Resize(prime);
}
}
public void Clear()
{
Array.Clear(_buckets, 0, _buckets.Length);
Array.Clear(_entries, 0, _entries.Length);
_count = 0;
_liveCount = 0;
_freeList = -1;
}
private void Resize(int newSize)
{
newSize = GetPrime(Math.Max(newSize, _liveCount * 2));
int[] array = new int[newSize];
Entry[] array2 = new Entry[newSize];
int num = 0;
int num2 = 0;
for (int i = 0; i < _count; i++)
{
Entry entry = _entries[i];
if (TryGetAliveKey(entry, out var _))
{
int num3 = entry.Hash % newSize;
entry.Next = array[num3] - 1;
array[num3] = num + 1;
array2[num++] = entry;
num2++;
}
}
_buckets = array;
_entries = array2;
_count = num;
_liveCount = num2;
_freeList = -1;
}
private int AllocateEntry()
{
if (_freeList >= 0)
{
int freeList = _freeList;
_freeList = _entries[freeList].Next;
return freeList;
}
return _count++;
}
private void RemoveEntry(int bucket, int index, int prev)
{
if (prev < 0)
{
_buckets[bucket] = _entries[index].Next + 1;
}
else
{
_entries[prev].Next = _entries[index].Next;
}
_entries[index].Key = null;
_entries[index].Value = default(TValue);
_entries[index].Next = _freeList;
_freeList = index;
_liveCount--;
}
private bool TryGetAliveKey(Entry e, out TKey key)
{
key = null;
WeakReference key2 = e.Key;
if (key2 == null)
{
return false;
}
object target = key2.Target;
if (target == null)
{
return false;
}
if (_isUnityObject && IsUnityObjectDestroyed((Object)((target is Object) ? target : null)))
{
return false;
}
key = (TKey)target;
return true;
}
private static bool IsUnityObjectDestroyed(Object obj)
{
return obj == (Object)null;
}
private bool FindEntry(int hash, TKey key, out int bucket, out int index, out int prev)
{
bucket = hash % _buckets.Length;
index = _buckets[bucket] - 1;
prev = -1;
while (index >= 0)
{
Entry e = _entries[index];
if (!TryGetAliveKey(e, out var key2))
{
RemoveEntry(bucket, index, prev);
index = ((prev < 0) ? (_buckets[bucket] - 1) : _entries[prev].Next);
continue;
}
if (e.Hash == hash && _comparer.Equals(key2, key))
{
return true;
}
prev = index;
index = e.Next;
}
return false;
}
private int GetHash(TKey key)
{
return _comparer.GetHashCode(key) & 0x7FFFFFFF;
}
public Enumerator GetEnumerator()
{
return new Enumerator(this);
}
IEnumerator<KeyValuePair<TKey, TValue>> IEnumerable<KeyValuePair<TKey, TValue>>.GetEnumerator()
{
return GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public int GetTotalEntryCount()
{
return _count;
}
public int GetDeadKeyCount()
{
return _count - _liveCount - GetFreeSlotCount();
}
public int GetFreeSlotCount()
{
int num = 0;
for (int num2 = _freeList; num2 >= 0; num2 = _entries[num2].Next)
{
num++;
}
return num;
}
public float GetLoadFactor()
{
return (float)_liveCount / (float)_entries.Length;
}
private static int GetPrime(int min)
{
int[] primes = Primes;
foreach (int num in primes)
{
if (num >= min)
{
return num;
}
}
for (int j = min | 1; j < int.MaxValue; j += 2)
{
if (IsPrime(j))
{
return j;
}
}
return min;
}
private static bool IsPrime(int v)
{
if ((v & 1) == 0)
{
return v == 2;
}
int num = (int)Math.Sqrt(v);
for (int i = 3; i <= num; i += 2)
{
if (v % i == 0)
{
return false;
}
}
return true;
}
}