Some mods may be broken due to the recent Alloyed Collective update.
Decompiled source of DropItem Addition v1.0.0
DropItemAddition.dll
Decompiled 2 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using HarmonyLib; using RoR2; using UnityEngine; [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("DropItemAddition")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("DropItemAddition")] [assembly: AssemblyTitle("DropItemAddition")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] namespace ShrineClamper.Utils { public static class ListHandlers { public static List<ItemDef> ItemDefList { get; } } } namespace DropItemAddition { [BepInPlugin("thebugreport.dropItemAddition", "DropItemAddition", "1.0.0")] public class Plugin : BaseUnityPlugin { internal static ManualLogSource Log; private Harmony _harmony; private void Awake() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; _harmony = new Harmony("thebugreport.dropItemAddition"); try { MethodInfo methodInfo = AccessTools.Method("Dropitem.Give:Give_Item", new Type[2] { typeof(NetworkUser), typeof(string[]) }, (Type[])null); if (methodInfo == null) { Log.LogError((object)"Failed to find Dropitem.Give.Give_Item(NetworkUser, string[]). Is Dropitem loaded?"); return; } _harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(GiveItemPatch), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); Log.LogInfo((object)"Patched Dropitem.Give.Give_Item successfully."); } catch (Exception arg) { Log.LogError((object)$"Error patching Dropitem.Give.Give_Item: {arg}"); } } private void OnDestroy() { try { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } catch (Exception arg) { ManualLogSource log = Log; if (log != null) { log.LogError((object)$"Error unpatching: {arg}"); } } } } public static class GiveItemPatch { public static bool Prefix(NetworkUser sender, string[] args, ref string __result) { ManualLogSource log = Plugin.Log; if (log != null) { log.LogInfo((object)string.Format("[GivePatch] Intercepted Give_Item from '{0}' with {1} arg(s).", sender?.userName ?? "null", (args != null) ? args.Length : 0)); } __result = DropReplacement.GiveItem(sender, args); return false; } } internal static class DropReplacement { public static string GiveItem(NetworkUser sender, string[] args) { //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Invalid comparison between Unknown and I4 //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Invalid comparison between Unknown and I4 //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_02a6: Unknown result type (might be due to invalid IL or missing references) //IL_02ad: Unknown result type (might be due to invalid IL or missing references) //IL_02b2: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Invalid comparison between Unknown and I4 //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_02dd: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Invalid comparison between Unknown and I4 //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Invalid comparison between Unknown and I4 //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0303: Unknown result type (might be due to invalid IL or missing references) //IL_030a: Unknown result type (might be due to invalid IL or missing references) //IL_030f: Unknown result type (might be due to invalid IL or missing references) //IL_0225: Unknown result type (might be due to invalid IL or missing references) //IL_032b: Unknown result type (might be due to invalid IL or missing references) //IL_0335: Unknown result type (might be due to invalid IL or missing references) //IL_0349: Unknown result type (might be due to invalid IL or missing references) //IL_034e: Unknown result type (might be due to invalid IL or missing references) //IL_036c: Unknown result type (might be due to invalid IL or missing references) //IL_0371: Unknown result type (might be due to invalid IL or missing references) //IL_0372: Unknown result type (might be due to invalid IL or missing references) //IL_0379: Unknown result type (might be due to invalid IL or missing references) //IL_0384: Unknown result type (might be due to invalid IL or missing references) //IL_0385: Unknown result type (might be due to invalid IL or missing references) //IL_0388: Unknown result type (might be due to invalid IL or missing references) //IL_038e: Expected I4, but got Unknown //IL_0390: Expected O, but got Unknown //IL_024a: Unknown result type (might be due to invalid IL or missing references) if (!DI.Users_CheckUserPerms(sender, out var text)) { return text; } Inventory inventory = sender.master.inventory; PlayerCharacterMasterController val = DI.StringParsers_GetNetUserFromString(args[1]); if (!Object.op_Implicit((Object)(object)val)) { return "<color=#FF8282>Could not find specified </color>player<color=#FF8282> '<color=#ff4646>" + args[1] + "</color>'</color>"; } Inventory inventory2 = val.master.inventory; if (!Object.op_Implicit((Object)(object)inventory) || !Object.op_Implicit((Object)(object)inventory2)) { return "<color=#ff4646>ERROR: null inventory</color>"; } if ((Object)(object)inventory == (Object)(object)inventory2) { return "<color=#FF8282>Target can not be the sender</color>"; } string name; if (Object.op_Implicit((Object)(object)val.networkUser)) { name = val.networkUser.userName; } else { if (!DI.Config_DropFromDisconnected()) { return "<color=#FF8282>Giving to disconnected players is disabled</color>"; } DI.Users_TryGetCachedName(val, out name); } name = "<color=#AAE6F0>" + name + "</color>"; string text2 = "<color=#AAE6F0>" + sender.masterController.GetDisplayName() + "</color>"; if (Object.op_Implicit((Object)(object)val.networkUser) && DI.Users_IsLocked(val.networkUser)) { return "<color=#FF8282>" + name + " has their inventory locked, failed to give item</color>"; } EquipmentIndex val2 = (EquipmentIndex)(-1); ItemIndex val3 = (ItemIndex)(-1); if (args[0].ToLower() == "e" || args[0].ToLower() == "equip" || args[0].ToLower() == "equipment") { val2 = inventory.GetEquipmentIndex(); if ((int)val2 == -1) { return "<color=#FF8282>Sender does not have an </color><color=#ff7d00>equipment</color>"; } } else { val3 = DI.StringParsers_FindItemInInventroy(args[0], inventory); } if ((int)val3 == -1) { if ((int)val2 == -1) { val2 = inventory.GetEquipmentIndex(); if ((int)val2 == -1 || !DI.StringParsers_ReformatString(Language.GetString(EquipmentCatalog.GetEquipmentDef(val2).nameToken)).Contains(DI.StringParsers_ReformatString(args[0]))) { return "<color=#FF8282>Could not find item '<color=#ff4646>" + args[0] + "</color>' in " + text2 + "<color=#AAE6F0>'s</color> inventory</color>"; } } if ((int)inventory2.GetEquipmentIndex() != -1) { return "<color=#FF8282>Target already has an equipment</color>"; } PickupIndex val4 = PickupCatalog.FindPickupIndex(val2); string text3 = Util.GenerateColoredString(Language.GetString(EquipmentCatalog.GetEquipmentDef(val2).nameToken), Color32.op_Implicit(PickupCatalog.GetPickupDef(val4).baseColor)); if (val2 != inventory.GetEquipmentIndex()) { return "<color=#FF8282>Sender does not have </color><color=#ff4646>" + text3 + "</color>"; } if (DI.Drop_IsBlacklisted(EquipmentCatalog.GetEquipmentDef(val2), !DI.Config_ApplyAllowToGive())) { return text3 + "<color=#FF8282> is not dropable</color>"; } inventory2.SetEquipmentIndex(val2); inventory.SetEquipmentIndex((EquipmentIndex)(-1)); return "<color=#96EBAA>" + text2 + " gave " + text3 + " to </color>" + name; } ItemDef itemDef = ItemCatalog.GetItemDef(val3); PickupIndex val5 = PickupCatalog.FindPickupIndex(val3); string text4 = Util.GenerateColoredString(Language.GetString(itemDef.nameToken), Color32.op_Implicit(PickupCatalog.GetPickupDef(val5).baseColor)); if (DI.Drop_IsBlacklisted(itemDef, !DI.Config_ApplyAllowToGive(), isItem: true)) { return text4 + "<color=#FF8282> is not dropable</color>"; } int num = inventory.GetItemCount(val3); if (num == 0) { return "<color=#FF8282>Sender does not have </color>" + text4; } if (num > 1) { text4 += Util.GenerateColoredString("s", Color32.op_Implicit(PickupCatalog.GetPickupDef(val5).baseColor)); } if (num > 30) { num = 30; } inventory2.GiveItem(val3, num); inventory.RemoveItem(val3, num); Vector3 corePosition = sender.master.GetBody().corePosition; GameObject gameObject = ((Component)val.master.GetBody()).gameObject; GameObject obj = LegacyResourcesAPI.Load<GameObject>("Prefabs/Effects/OrbEffects/ItemTransferOrbEffect"); EffectData val6 = new EffectData { origin = corePosition, genericFloat = 1f, genericUInt = (uint)(val3 + 1) }; val6.SetNetworkedObjectReference(gameObject); EffectManager.SpawnEffect(obj, val6, true); return string.Format("{0}{1} gave {2} {3} to </color>{4}", "<color=#96EBAA>", text2, num, text4, name); } } internal static class DI { private static Type _tUsers; private static Type _tConfig; private static Type _tStringParsers; private static Type _tDrop; private static MethodInfo _miCheckUserPerms; private static FieldInfo _fiCachedPlayerNames; private static FieldInfo _fiLockedUserIds; private static FieldInfo _fiApplyAllowToGive; private static FieldInfo _fiDropFromDisconnected; private static PropertyInfo _piConfigValue; private static MethodInfo _miGetNetUserFromString; private static MethodInfo _miFindItemInInventroy; private static MethodInfo _miReformatString; private static MethodInfo _miIsBlacklistedItem; private static MethodInfo _miIsBlacklistedEquip; private static Type TUsers => _tUsers ?? (_tUsers = AccessTools.TypeByName("Dropitem.Users")); private static Type TConfig => _tConfig ?? (_tConfig = AccessTools.TypeByName("Dropitem.Config")); private static Type TStringParsers => _tStringParsers ?? (_tStringParsers = AccessTools.TypeByName("Dropitem.StringParsers")); private static Type TDrop => _tDrop ?? (_tDrop = AccessTools.TypeByName("Dropitem.Drop")); public static bool Users_CheckUserPerms(NetworkUser sender, out string text) { text = null; if ((object)_miCheckUserPerms == null) { _miCheckUserPerms = AccessTools.Method(TUsers, "CheckUserPerms", new Type[2] { typeof(NetworkUser), typeof(string).MakeByRefType() }, (Type[])null); } if (_miCheckUserPerms == null) { return true; } object[] array = new object[2] { sender, null }; bool result = (bool)_miCheckUserPerms.Invoke(null, array); text = (string)array[1]; return result; } public static bool Users_TryGetCachedName(PlayerCharacterMasterController pcmc, out string name) { name = null; if ((object)_fiCachedPlayerNames == null) { _fiCachedPlayerNames = AccessTools.Field(TUsers, "cachedPlayerNames"); } object obj = _fiCachedPlayerNames?.GetValue(null); if (obj == null || (Object)(object)pcmc == (Object)null) { return false; } MethodInfo method = obj.GetType().GetMethod("TryGetValue"); object[] array = new object[2] { pcmc, null }; bool flag = (bool)method.Invoke(obj, array); name = (flag ? ((string)array[1]) : null); return flag; } public static bool Users_IsLocked(NetworkUser target) { //IL_0058: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)target == (Object)null) { return false; } if ((object)_fiLockedUserIds == null) { _fiLockedUserIds = AccessTools.Field(TUsers, "lockedUserIds"); } object obj = _fiLockedUserIds?.GetValue(null); if (obj == null) { return false; } return (bool)obj.GetType().GetMethod("Contains").Invoke(obj, new object[1] { target.id }); } private static bool GetConfigBool(ref FieldInfo field, string fieldName) { if ((object)field == null) { field = AccessTools.Field(TConfig, fieldName); } object obj = field?.GetValue(null); if (obj == null) { return false; } if ((object)_piConfigValue == null) { _piConfigValue = obj.GetType().GetProperty("Value"); } return (bool)(_piConfigValue?.GetValue(obj) ?? ((object)false)); } public static bool Config_ApplyAllowToGive() { return GetConfigBool(ref _fiApplyAllowToGive, "applyAllowToGive"); } public static bool Config_DropFromDisconnected() { return GetConfigBool(ref _fiDropFromDisconnected, "dropFromDisconnected"); } public static PlayerCharacterMasterController StringParsers_GetNetUserFromString(string s) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Expected O, but got Unknown if ((object)_miGetNetUserFromString == null) { _miGetNetUserFromString = AccessTools.Method(TStringParsers, "GetNetUserFromString", new Type[1] { typeof(string) }, (Type[])null); } return (PlayerCharacterMasterController)(_miGetNetUserFromString?.Invoke(null, new object[1] { s })); } public static ItemIndex StringParsers_FindItemInInventroy(string s, Inventory inv) { //IL_0064: Unknown result type (might be due to invalid IL or missing references) if ((object)_miFindItemInInventroy == null) { _miFindItemInInventroy = AccessTools.Method(TStringParsers, "FindItemInInventroy", new Type[2] { typeof(string), typeof(Inventory) }, (Type[])null); } if (!(_miFindItemInInventroy != null)) { return (ItemIndex)(-1); } return (ItemIndex)_miFindItemInInventroy.Invoke(null, new object[2] { s, inv }); } public static string StringParsers_ReformatString(string s) { if ((object)_miReformatString == null) { _miReformatString = AccessTools.Method(TStringParsers, "ReformatString", new Type[1] { typeof(string) }, (Type[])null); } return (string)_miReformatString?.Invoke(null, new object[1] { s }); } public static bool Drop_IsBlacklisted(ItemDef itemDef, bool invertAllow, bool isItem, bool defaultArg = false) { if ((object)_miIsBlacklistedItem == null) { _miIsBlacklistedItem = AccessTools.Method(TDrop, "IsBlacklisted", new Type[4] { typeof(ItemDef), typeof(bool), typeof(bool), typeof(bool) }, (Type[])null); } if (_miIsBlacklistedItem == null) { return false; } return (bool)_miIsBlacklistedItem.Invoke(null, new object[4] { itemDef, invertAllow, true, defaultArg }); } public static bool Drop_IsBlacklisted(EquipmentDef equipDef, bool invertAllow, bool defaultArg = false) { if ((object)_miIsBlacklistedEquip == null) { _miIsBlacklistedEquip = AccessTools.Method(TDrop, "IsBlacklisted", new Type[3] { typeof(EquipmentDef), typeof(bool), typeof(bool) }, (Type[])null); } if (_miIsBlacklistedEquip == null) { return false; } return (bool)_miIsBlacklistedEquip.Invoke(null, new object[3] { equipDef, invertAllow, false }); } } }