using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Xml.Linq;
using BepInEx;
using BepInEx.Logging;
using HG;
using IL.RoR2;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2;
using R2API.AutoVersionGen;
using R2API.ContentManagement;
using R2API.Utils;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("R2API.Items")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4+5b0ce6f434ee8e85003c799f176939f4c445d71d")]
[assembly: AssemblyProduct("R2API.Items")]
[assembly: AssemblyTitle("R2API.Items")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.4.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.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 System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
internal sealed class MemberNotNullAttribute : Attribute
{
public string[] Members { get; }
public MemberNotNullAttribute(string member)
{
Members = new string[1] { member };
}
public MemberNotNullAttribute(params string[] members)
{
Members = members;
}
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
internal sealed class MemberNotNullWhenAttribute : Attribute
{
public bool ReturnValue { get; }
public string[] Members { get; }
public MemberNotNullWhenAttribute(bool returnValue, string member)
{
ReturnValue = returnValue;
Members = new string[1] { member };
}
public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
{
ReturnValue = returnValue;
Members = members;
}
}
}
namespace R2API
{
public class CustomEquipment
{
public EquipmentDef? EquipmentDef;
public ItemDisplayRuleDict? ItemDisplayRules;
public CustomEquipment(EquipmentDef? equipmentDef, ItemDisplayRule[]? itemDisplayRules)
{
EquipmentDef = equipmentDef;
ItemDisplayRules = new ItemDisplayRuleDict(itemDisplayRules);
}
public CustomEquipment(EquipmentDef? equipmentDef, ItemDisplayRuleDict? itemDisplayRules)
{
EquipmentDef = equipmentDef;
ItemDisplayRules = itemDisplayRules;
}
public CustomEquipment(string name, string nameToken, string descriptionToken, string loreToken, string pickupToken, Sprite pickupIconSprite, GameObject pickupModelPrefab, float cooldown, bool canDrop, bool enigmaCompatible, bool isBoss, bool isLunar, BuffDef passiveBuffDef, UnlockableDef unlockableDef, ColorIndex colorIndex = 5, bool appearsInMultiPlayer = true, bool appearsInSinglePlayer = true, ItemDisplayRule[]? itemDisplayRules = null)
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
EquipmentDef = ScriptableObject.CreateInstance<EquipmentDef>();
EquipmentDef.appearsInMultiPlayer = appearsInMultiPlayer;
EquipmentDef.appearsInSinglePlayer = appearsInSinglePlayer;
EquipmentDef.canDrop = canDrop;
EquipmentDef.colorIndex = colorIndex;
EquipmentDef.cooldown = cooldown;
EquipmentDef.descriptionToken = descriptionToken;
EquipmentDef.enigmaCompatible = enigmaCompatible;
EquipmentDef.isBoss = isBoss;
EquipmentDef.isLunar = isLunar;
EquipmentDef.loreToken = loreToken;
((Object)EquipmentDef).name = name;
EquipmentDef.nameToken = nameToken;
EquipmentDef.passiveBuffDef = passiveBuffDef;
EquipmentDef.pickupIconSprite = pickupIconSprite;
EquipmentDef.pickupModelPrefab = pickupModelPrefab;
EquipmentDef.pickupToken = pickupToken;
EquipmentDef.unlockableDef = unlockableDef;
ItemDisplayRules = new ItemDisplayRuleDict(itemDisplayRules);
}
public CustomEquipment(string name, string nameToken, string descriptionToken, string loreToken, string pickupToken, Sprite pickupIconSprite, GameObject pickupModelPrefab, float cooldown, bool canDrop, bool enigmaCompatible, bool isBoss, bool isLunar, BuffDef passiveBuffDef, UnlockableDef unlockableDef, ColorIndex colorIndex = 5, bool appearsInMultiPlayer = true, bool appearsInSinglePlayer = true, ItemDisplayRuleDict? itemDisplayRules = null)
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
EquipmentDef = ScriptableObject.CreateInstance<EquipmentDef>();
EquipmentDef.appearsInMultiPlayer = appearsInMultiPlayer;
EquipmentDef.appearsInSinglePlayer = appearsInSinglePlayer;
EquipmentDef.canDrop = canDrop;
EquipmentDef.colorIndex = colorIndex;
EquipmentDef.cooldown = cooldown;
EquipmentDef.descriptionToken = descriptionToken;
EquipmentDef.enigmaCompatible = enigmaCompatible;
EquipmentDef.isBoss = isBoss;
EquipmentDef.isLunar = isLunar;
EquipmentDef.loreToken = loreToken;
((Object)EquipmentDef).name = name;
EquipmentDef.nameToken = nameToken;
EquipmentDef.passiveBuffDef = passiveBuffDef;
EquipmentDef.pickupIconSprite = pickupIconSprite;
EquipmentDef.pickupModelPrefab = pickupModelPrefab;
EquipmentDef.pickupToken = pickupToken;
EquipmentDef.unlockableDef = unlockableDef;
ItemDisplayRules = itemDisplayRules;
}
}
public class CustomItem
{
public ItemDef? ItemDef;
public ItemDisplayRuleDict? ItemDisplayRules;
public CustomItem(ItemDef? itemDef, ItemDisplayRule[]? itemDisplayRules)
{
ItemDef = itemDef;
ItemDisplayRules = new ItemDisplayRuleDict(itemDisplayRules);
}
public CustomItem(ItemDef? itemDef, ItemDisplayRuleDict? itemDisplayRules)
{
ItemDef = itemDef;
ItemDisplayRules = itemDisplayRules;
}
public CustomItem(string name, string nameToken, string descriptionToken, string loreToken, string pickupToken, Sprite pickupIconSprite, GameObject pickupModelPrefab, ItemTag[] tags, ItemTier tier, bool hidden, bool canRemove, UnlockableDef unlockableDef, ItemDisplayRule[]? itemDisplayRules)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
SetupItem(name, nameToken, descriptionToken, loreToken, pickupToken, pickupIconSprite, pickupModelPrefab, tier, tags, canRemove, hidden, unlockableDef, new ItemDisplayRuleDict(itemDisplayRules));
}
public CustomItem(string name, string nameToken, string descriptionToken, string loreToken, string pickupToken, Sprite pickupIconSprite, GameObject pickupModelPrefab, ItemTag[] tags, ItemTier tier, bool hidden, bool canRemove, UnlockableDef unlockableDef, ItemDisplayRule[]? itemDisplayRules, ItemTierDef itemTierDef = null)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
SetupItem(name, nameToken, descriptionToken, loreToken, pickupToken, pickupIconSprite, pickupModelPrefab, tier, tags, canRemove, hidden, unlockableDef, new ItemDisplayRuleDict(itemDisplayRules), itemTierDef);
}
public CustomItem(string name, string nameToken, string descriptionToken, string loreToken, string pickupToken, Sprite pickupIconSprite, GameObject pickupModelPrefab, ItemTier tier, ItemTag[] tags, bool canRemove, bool hidden, UnlockableDef unlockableDef = null, ItemDisplayRuleDict? itemDisplayRules = null)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
SetupItem(name, nameToken, descriptionToken, loreToken, pickupToken, pickupIconSprite, pickupModelPrefab, tier, tags, canRemove, hidden, unlockableDef, itemDisplayRules);
}
public CustomItem(string name, string nameToken, string descriptionToken, string loreToken, string pickupToken, Sprite pickupIconSprite, GameObject pickupModelPrefab, ItemTier tier, ItemTag[] tags, bool canRemove, bool hidden, UnlockableDef unlockableDef = null, ItemDisplayRuleDict? itemDisplayRules = null, ItemTierDef itemTierDef = null)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
SetupItem(name, nameToken, descriptionToken, loreToken, pickupToken, pickupIconSprite, pickupModelPrefab, tier, tags, canRemove, hidden, unlockableDef, itemDisplayRules, itemTierDef);
}
private void SetupItem(string name, string nameToken, string descriptionToken, string loreToken, string pickupToken, Sprite pickupIconSprite, GameObject pickupModelPrefab, ItemTier tier, ItemTag[] tags, bool canRemove, bool hidden, UnlockableDef unlockableDef = null, ItemDisplayRuleDict? itemDisplayRules = null, ItemTierDef itemTierDef = null)
{
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Invalid comparison between Unknown and I4
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
ItemDef = ScriptableObject.CreateInstance<ItemDef>();
ItemDef.canRemove = canRemove;
ItemDef.descriptionToken = descriptionToken;
ItemDef.hidden = hidden;
ItemDef.loreToken = loreToken;
((Object)ItemDef).name = name;
ItemDef.nameToken = nameToken;
ItemDef.pickupIconSprite = pickupIconSprite;
ItemDef.pickupModelPrefab = pickupModelPrefab;
ItemDef.pickupToken = pickupToken;
ItemDef.tags = tags;
ItemDef.unlockableDef = unlockableDef;
ItemDisplayRules = itemDisplayRules;
if ((int)tier != 10)
{
ItemDef._itemTierDef = LoadTierFromAddress(tier);
}
else if (!Object.op_Implicit((Object)(object)itemTierDef))
{
ItemDef._itemTierDef = null;
ItemsPlugin.Logger.LogWarning((object)("Trying to create an itemDef (" + name + "), but the \"tier\" argument is set to AssignedAtRuntimeAnd the argument \"itemTierDef\" is null! Resorting to setting tier to NoTier"));
}
else
{
ItemDef._itemTierDef = itemTierDef;
}
}
private ItemTierDef LoadTierFromAddress(ItemTier itemTierToLoad)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Expected I4, but got Unknown
return (ItemTierDef)((int)itemTierToLoad switch
{
0 => LoadTier("RoR2/Base/Common/Tier1Def.asset"),
1 => LoadTier("RoR2/Base/Common/Tier2Def.asset"),
2 => LoadTier("RoR2/Base/Common/Tier3Def.asset"),
3 => LoadTier("RoR2/Base/Common/LunarTierDef.asset"),
4 => LoadTier("RoR2/Base/Common/BossTierDef.asset"),
6 => LoadTier("RoR2/DLC1/Common/VoidTier1Def.asset"),
7 => LoadTier("RoR2/DLC1/Common/VoidTier2Def.asset"),
8 => LoadTier("RoR2/DLC1/Common/VoidTier3Def.asset"),
9 => LoadTier("RoR2/DLC1/Common/VoidBossDef.asset"),
5 => null,
10 => null,
_ => null,
});
}
private ItemTierDef LoadTier(string address)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
return Addressables.LoadAssetAsync<ItemTierDef>((object)address).WaitForCompletion();
}
}
[AutoVersion]
public static class ItemAPI
{
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__MaterialFixForItemDisplayOnCharacter;
public static hook_Init <1>__AddingItemDisplayRulesToCharacterModels;
public static Manipulator <2>__AddCustomTagsToItemCatalog;
}
public const string PluginGUID = "com.bepis.r2api.items";
public const string PluginName = "R2API.Items";
public static ObservableCollection<CustomItem?>? ItemDefinitions = new ObservableCollection<CustomItem>();
public static ObservableCollection<CustomEquipment?> EquipmentDefinitions = new ObservableCollection<CustomEquipment>();
private static ICollection<string> noDefaultIDRSCharacterList = new List<string>();
private static List<string> customItemTags = new List<string>();
public static int CustomItemCount;
public static int CustomEquipmentCount;
private static bool _hooksEnabled = false;
public const string PluginVersion = "1.0.4";
[Obsolete("All submodules are automatically loaded and this property is now unused")]
public static bool Loaded => true;
internal static void SetHooks()
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Expected O, but got Unknown
//IL_0058: 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_0063: Expected O, but got Unknown
if (!_hooksEnabled)
{
object obj = <>O.<0>__MaterialFixForItemDisplayOnCharacter;
if (obj == null)
{
Manipulator val = MaterialFixForItemDisplayOnCharacter;
<>O.<0>__MaterialFixForItemDisplayOnCharacter = val;
obj = (object)val;
}
CharacterModel.UpdateMaterials += (Manipulator)obj;
object obj2 = <>O.<1>__AddingItemDisplayRulesToCharacterModels;
if (obj2 == null)
{
hook_Init val2 = AddingItemDisplayRulesToCharacterModels;
<>O.<1>__AddingItemDisplayRulesToCharacterModels = val2;
obj2 = (object)val2;
}
ItemDisplayRuleSet.Init += (hook_Init)obj2;
object obj3 = <>O.<2>__AddCustomTagsToItemCatalog;
if (obj3 == null)
{
Manipulator val3 = AddCustomTagsToItemCatalog;
<>O.<2>__AddCustomTagsToItemCatalog = val3;
obj3 = (object)val3;
}
ItemCatalog.SetItemDefs += (Manipulator)obj3;
_hooksEnabled = true;
}
}
internal static void UnsetHooks()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
//IL_0030: 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_003b: Expected O, but got Unknown
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Expected O, but got Unknown
object obj = <>O.<0>__MaterialFixForItemDisplayOnCharacter;
if (obj == null)
{
Manipulator val = MaterialFixForItemDisplayOnCharacter;
<>O.<0>__MaterialFixForItemDisplayOnCharacter = val;
obj = (object)val;
}
CharacterModel.UpdateMaterials -= (Manipulator)obj;
object obj2 = <>O.<1>__AddingItemDisplayRulesToCharacterModels;
if (obj2 == null)
{
hook_Init val2 = AddingItemDisplayRulesToCharacterModels;
<>O.<1>__AddingItemDisplayRulesToCharacterModels = val2;
obj2 = (object)val2;
}
ItemDisplayRuleSet.Init -= (hook_Init)obj2;
object obj3 = <>O.<2>__AddCustomTagsToItemCatalog;
if (obj3 == null)
{
Manipulator val3 = AddCustomTagsToItemCatalog;
<>O.<2>__AddCustomTagsToItemCatalog = val3;
obj3 = (object)val3;
}
ItemCatalog.SetItemDefs -= (Manipulator)obj3;
_hooksEnabled = false;
}
[MethodImpl(MethodImplOptions.NoInlining)]
public static bool Add(CustomItem? item)
{
SetHooks();
return AddItemInternal(item, Assembly.GetCallingAssembly());
}
internal static bool AddItemInternal(CustomItem item, Assembly addingAssembly)
{
if (!CatalogBlockers.GetAvailability<ItemDef>())
{
ItemsPlugin.Logger.LogError((object)("Too late ! Tried to add item: " + item.ItemDef.nameToken + " after the ItemCatalog has Initialized!"));
}
if (!Object.op_Implicit((Object)(object)item.ItemDef))
{
ItemsPlugin.Logger.LogError((object)"ItemDef is null ! Can't add the custom item.");
}
if (string.IsNullOrEmpty(((Object)item.ItemDef).name))
{
ItemsPlugin.Logger.LogError((object)"ItemDef.name is null or empty ! Can't add the custom item.");
}
if (!Object.op_Implicit((Object)(object)item.ItemDef.pickupModelPrefab))
{
ItemsPlugin.Logger.LogWarning((object)("No ItemDef.pickupModelPrefab (" + ((Object)item.ItemDef).name + "), the game will show nothing when the item is on the ground."));
}
if (item.ItemDisplayRules != null && item.ItemDisplayRules.Dictionary.Values.Any((ItemDisplayRule[] rules) => rules.Any((ItemDisplayRule rule) => (int)rule.ruleType == 0)) && item.ItemDisplayRules.HasInvalidDisplays(out StringBuilder logger))
{
ItemsPlugin.Logger.LogWarning((object)(string.Format("Some of the ItemDisplayRules in the dictionary for CustomItem ({0}) have an invalid {1}. ", item.ItemDef, "followerPrefab") + "(There are ItemDisplayRuleType.ParentedPrefab rules),Logging invalid rules... (For full details, check the Log file)"));
ItemsPlugin.Logger.LogDebug((object)logger.ToString());
}
bool flag = false;
try
{
new XElement(((Object)item.ItemDef).name);
flag = true;
}
catch
{
ItemsPlugin.Logger.LogError((object)("Custom item '" + ((Object)item.ItemDef).name + "' is not XMLsafe. Item not added."));
}
if (flag)
{
R2APIContentManager.HandleContentAddition(addingAssembly, (Object)(object)item.ItemDef);
ItemDefinitions.Add(item);
return true;
}
if (item.ItemDef.tags == null)
{
ItemsPlugin.Logger.LogInfo((object)("Adding empty tags array to custom item '" + ((Object)item.ItemDef).name + "'"));
item.ItemDef.tags = Array.Empty<ItemTag>();
}
return false;
}
[MethodImpl(MethodImplOptions.NoInlining)]
public static bool Add(CustomEquipment? item)
{
SetHooks();
return AddEquippmentInternal(item, Assembly.GetCallingAssembly());
}
private static bool AddEquippmentInternal(CustomEquipment equip, Assembly addingAssembly)
{
if (!CatalogBlockers.GetAvailability<EquipmentDef>())
{
ItemsPlugin.Logger.LogError((object)("Too late ! Tried to add equipment item: " + equip.EquipmentDef.nameToken + " after the EquipmentCatalog has initialized!"));
}
if ((Object)(object)equip.EquipmentDef == (Object)null)
{
ItemsPlugin.Logger.LogError((object)"EquipmentDef is null ! Can't add the custom Equipment.");
}
if (string.IsNullOrEmpty(((Object)equip.EquipmentDef).name))
{
ItemsPlugin.Logger.LogError((object)"EquipmentDef.name is null or empty ! Can't add the custom Equipment.");
}
if (!Object.op_Implicit((Object)(object)equip.EquipmentDef.pickupModelPrefab))
{
ItemsPlugin.Logger.LogWarning((object)("No EquipmentDef.pickupModelPrefab (" + ((Object)equip.EquipmentDef).name + "), the game will show nothing when the equipment is on the ground."));
}
if (equip.ItemDisplayRules != null && equip.ItemDisplayRules.Dictionary.Values.Any((ItemDisplayRule[] rules) => rules.Any((ItemDisplayRule rule) => (int)rule.ruleType == 0)) && equip.ItemDisplayRules.HasInvalidDisplays(out StringBuilder logger))
{
ItemsPlugin.Logger.LogWarning((object)(string.Format("Some of the ItemDisplayRules in the dictionary for CustomEquipment ({0}) have an invalid {1}. ", equip.EquipmentDef, "followerPrefab") + "(There are ItemDisplayRuleType.ParentedPrefab rules),Logging invalid rules... (For full details, check the Log file)"));
ItemsPlugin.Logger.LogDebug((object)logger.ToString());
}
bool flag = false;
try
{
new XElement(((Object)equip.EquipmentDef).name);
flag = true;
}
catch
{
ItemsPlugin.Logger.LogError((object)("Custom equipment '" + ((Object)equip.EquipmentDef).name + "' is not XMLsafe. Equipment not added."));
}
if (flag)
{
R2APIContentManager.HandleContentAddition(addingAssembly, (Object)(object)equip.EquipmentDef);
EquipmentDefinitions.Add(equip);
return true;
}
return false;
}
public static ItemTag AddItemTag(string name)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected I4, but got Unknown
SetHooks();
if (!CatalogBlockers.GetAvailability<ItemDef>())
{
ItemsPlugin.Logger.LogError((object)("Too late ! Tried to add itemTag: " + name + " after the ItemCatalog has Initialized!"));
return (ItemTag)(-1);
}
int num = (int)FindItemTagByName(name);
if (num == -1)
{
customItemTags.Add(name);
num = customItemTags.Count + 23;
}
return (ItemTag)num;
}
public static ItemTag FindItemTagByName(string name)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Invalid comparison between Unknown and I4
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
SetHooks();
ItemTag result = (ItemTag)customItemTags.IndexOf(name);
if ((int)result == -1)
{
if (Enum.TryParse<ItemTag>(name, out result))
{
return result;
}
return (ItemTag)(-1);
}
return (ItemTag)(result + 1 + 23);
}
public static void ApplyTagToItem(string tagName, ItemDef item)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
SetHooks();
ApplyTagToItem(FindItemTagByName(tagName), item);
}
public static void ApplyTagToItem(ItemTag tag, ItemDef item)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
SetHooks();
ArrayUtils.ArrayAppend<ItemTag>(ref item.tags, ref tag);
if (!CatalogBlockers.GetAvailability<ItemDef>())
{
ref ItemIndex[] reference = ref ItemCatalog.itemIndicesByTag[tag];
ItemIndex itemIndex = item.itemIndex;
ArrayUtils.ArrayAppend<ItemIndex>(ref reference, ref itemIndex);
}
}
public static void DoNotAutoIDRSFor(string bodyPrefabOrCharacterModelName)
{
SetHooks();
noDefaultIDRSCharacterList.Add(bodyPrefabOrCharacterModelName);
}
public static void DoNotAutoIDRSFor(GameObject bodyPrefab)
{
SetHooks();
if (Object.op_Implicit((Object)(object)bodyPrefab.GetComponentInChildren<CharacterModel>()))
{
DoNotAutoIDRSFor(((Object)bodyPrefab).name);
}
}
private static void MaterialFixForItemDisplayOnCharacter(ILContext il)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Expected O, but got Unknown
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(il);
int forCounterLoc = 0;
int itemDisplayLoc = 0;
try
{
val.GotoNext(new Func<Instruction, bool>[3]
{
(Instruction i) => ILPatternMatchingExt.MatchLdarg(i, 0),
(Instruction i) => ILPatternMatchingExt.MatchLdfld(i, "RoR2.CharacterModel", "parentedPrefabDisplays"),
(Instruction i) => ILPatternMatchingExt.MatchLdloc(i, ref forCounterLoc)
});
val.GotoNext(new Func<Instruction, bool>[2]
{
(Instruction i) => ILPatternMatchingExt.MatchCallOrCallvirt(i, "RoR2.CharacterModel/ParentedPrefabDisplay", "get_itemDisplay"),
(Instruction i) => ILPatternMatchingExt.MatchStloc(i, ref itemDisplayLoc)
});
val.Index += 2;
val.Emit(OpCodes.Ldloc, itemDisplayLoc);
val.Emit(OpCodes.Call, (MethodBase)Reflection.GetMethodCached(typeof(Object), "op_Implicit"));
val.Emit(OpCodes.Brfalse, (object)val.MarkLabel());
int index = val.Index - 1;
val.GotoNext(new Func<Instruction, bool>[1]
{
(Instruction i) => ILPatternMatchingExt.MatchLdloc(i, forCounterLoc)
});
ILLabel operand = val.MarkLabel();
val.Index = index;
val.Next.Operand = operand;
}
catch (Exception arg)
{
ItemsPlugin.Logger.LogError((object)string.Format("Exception in {0} : Item mods without the {1} component may not work correctly.\n{2}", "MaterialFixForItemDisplayOnCharacter", "ItemDisplay", arg));
}
}
private static void AddingItemDisplayRulesToCharacterModels(orig_Init orig)
{
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_0180: Unknown result type (might be due to invalid IL or missing references)
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
orig.Invoke();
foreach (GameObject allBodyPrefab in BodyCatalog.allBodyPrefabs)
{
CharacterModel componentInChildren = allBodyPrefab.GetComponentInChildren<CharacterModel>();
if (!Object.op_Implicit((Object)(object)componentInChildren))
{
continue;
}
if (!Object.op_Implicit((Object)(object)componentInChildren.itemDisplayRuleSet))
{
componentInChildren.itemDisplayRuleSet = ScriptableObject.CreateInstance<ItemDisplayRuleSet>();
}
string name = ((Object)componentInChildren).name;
string name2 = ((Object)allBodyPrefab).name;
bool flag = true;
if (noDefaultIDRSCharacterList.Contains(name) || noDefaultIDRSCharacterList.Contains(name2))
{
flag = false;
}
foreach (CustomItem itemDefinition in ItemDefinitions)
{
ItemDisplayRuleDict itemDisplayRules = itemDefinition.ItemDisplayRules;
if (itemDisplayRules != null && (itemDisplayRules.TryGetRules(name, out ItemDisplayRule[] itemDisplayRules2) || itemDisplayRules.TryGetRules(name2, out itemDisplayRules2) || (flag && componentInChildren.itemDisplayRuleSet.GetItemDisplayRuleGroup(itemDefinition.ItemDef.itemIndex).rules == null)))
{
componentInChildren.itemDisplayRuleSet.SetDisplayRuleGroup((Object)(object)itemDefinition.ItemDef, new DisplayRuleGroup
{
rules = itemDisplayRules2
});
}
}
foreach (CustomEquipment equipmentDefinition in EquipmentDefinitions)
{
ItemDisplayRuleDict itemDisplayRules3 = equipmentDefinition.ItemDisplayRules;
if (itemDisplayRules3 != null && (itemDisplayRules3.TryGetRules(name, out ItemDisplayRule[] itemDisplayRules4) || itemDisplayRules3.TryGetRules(name2, out itemDisplayRules4) || (flag && componentInChildren.itemDisplayRuleSet.GetEquipmentDisplayRuleGroup(equipmentDefinition.EquipmentDef.equipmentIndex).rules == null)))
{
componentInChildren.itemDisplayRuleSet.SetDisplayRuleGroup((Object)(object)equipmentDefinition.EquipmentDef, new DisplayRuleGroup
{
rules = itemDisplayRules4
});
}
}
componentInChildren.itemDisplayRuleSet.GenerateRuntimeValues();
}
}
private static void AddCustomTagsToItemCatalog(ILContext il)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(il);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 23)
}))
{
val.EmitDelegate<Func<int>>((Func<int>)(() => customItemTags.Count + 1));
val.Emit(OpCodes.Add);
}
}
}
public class ItemDisplayRuleDict
{
public ItemDisplayRule[]? this[string? bodyPrefabName]
{
get
{
if (string.IsNullOrEmpty(bodyPrefabName) || !Dictionary.ContainsKey(bodyPrefabName))
{
return DefaultRules;
}
return Dictionary[bodyPrefabName];
}
set
{
if (string.IsNullOrEmpty(bodyPrefabName))
{
ItemsPlugin.Logger.LogWarning((object)"DefaultRules overwritten with Indexer! Please set them with the constructor instead!");
DefaultRules = value;
}
else if (Dictionary.ContainsKey(bodyPrefabName))
{
Dictionary[bodyPrefabName] = value;
}
else
{
Dictionary.Add(bodyPrefabName, value);
}
}
}
public ItemDisplayRule[]? DefaultRules { get; private set; }
internal Dictionary<string, ItemDisplayRule[]?> Dictionary { get; private set; }
public void Add(string? bodyPrefabName, params ItemDisplayRule[]? itemDisplayRules)
{
this[bodyPrefabName] = itemDisplayRules;
}
public bool TryGetRules(string? bodyPrefabName, out ItemDisplayRule[] itemDisplayRules)
{
itemDisplayRules = this[bodyPrefabName];
if (bodyPrefabName != null)
{
return Dictionary.ContainsKey(bodyPrefabName);
}
return false;
}
internal bool HasInvalidDisplays(out StringBuilder logger)
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: 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_007e: 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)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
bool result = false;
logger = new StringBuilder();
foreach (KeyValuePair<string, ItemDisplayRule[]> item in Dictionary)
{
item.Deconstruct(out var key, out var value);
string arg = key;
ItemDisplayRule[] array = value;
for (int i = 0; i < array.Length; i++)
{
ItemDisplayRule val = array[i];
if ((int)val.ruleType != 0)
{
continue;
}
if (!Object.op_Implicit((Object)(object)val.followerPrefab))
{
logger.AppendLine($"invalid follower prefab for entry {arg}. The follower prefab of entry N°{i} is null. (The ItemDisplayRule.ruleType is ItemDisplayRuleType.ParentedPrefab)");
result = true;
continue;
}
ItemDisplay component = val.followerPrefab.GetComponent<ItemDisplay>();
if (!Object.op_Implicit((Object)(object)component))
{
logger.AppendLine($"Invalid follower prefab for entry {arg}. The follower prefab ({val.followerPrefab}) does not have an ItemDisplay component. (The ItemDisplayRule.ruleType is ItemDisplayRuleType.ParentedPrefab) " + "The ItemDisplay model should have one and have at least a rendererInfo in it for having correct visibility levels.");
result = true;
}
else if (component.rendererInfos == null || component.rendererInfos.Length == 0)
{
logger.AppendLine($"Invalid follower prefab for entry {arg}. The follower prefab ({val.followerPrefab}) has an ItemDisplay component, but no RendererInfos assigned. (The ItemDisplayRule.ruleType is ItemDisplayRuleType.ParentedPrefab)" + "The ItemDisplay model should have one and have at least a rendererInfo in it for having correct visibility levels.");
result = true;
}
}
}
return result;
}
public ItemDisplayRuleDict(params ItemDisplayRule[]? defaultRules)
{
DefaultRules = defaultRules;
Dictionary = new Dictionary<string, ItemDisplayRule[]>();
}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.bepis.r2api.items", "R2API.Items", "1.0.4")]
public sealed class ItemsPlugin : BaseUnityPlugin
{
internal static ManualLogSource Logger { get; set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
}
private void OnDestroy()
{
ItemAPI.UnsetHooks();
}
}
}
namespace R2API.AutoVersionGen
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
internal class AutoVersionAttribute : Attribute
{
}
}