Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of AutoItemPickup Updated v2.4.2
AutoItemPickup.dll
Decompiled 15 hours agousing 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.Versioning; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using AutoItemPickup.Configuration; using AutoItemPickup.Enums; using AutoItemPickup.Hooks; using AutoItemPickup.ItemDistributors; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using EntityStates.Scrapper; using IL.EntityStates.Scrapper; using IL.RoR2; using Mono.Cecil; using Mono.Cecil.Cil; using MonoMod.Cil; using MonoMod.RuntimeDetour.HookGen; using On.RoR2; using RiskOfOptions; using RiskOfOptions.Options; using RoR2; using RoR2.Artifacts; using UnityEngine; using UnityEngine.Networking; [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("KubeRoot")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("2.4.2.0")] [assembly: AssemblyInformationalVersion("2.4.2+a003c3bf3ca92d3c06bdcbf37f984a7bf5285f7d")] [assembly: AssemblyProduct("AutoItemPickup")] [assembly: AssemblyTitle("AutoItemPickup")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("2.4.2.0")] namespace AutoItemPickup { [BepInPlugin("com.rfaael.autoitempickup.updated", "AutoItemPickup Updated", "2.4.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class AutoItemPickup : BaseUnityPlugin { private static readonly MethodInfo GenericPickupController_AttemptGrant = typeof(GenericPickupController).GetMethod("AttemptGrant", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static readonly FieldInfo GenericPickupController_consumed = typeof(GenericPickupController).GetField("consumed", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private bool distributorNeedsUpdate; private HookManager hookManager; internal static ManualLogSource Log { get; private set; } public ItemDistributor Distributor { get; private set; } public Config ModConfig { get; private set; } public void OnEnable() { Log = ((BaseUnityPlugin)this).Logger; if (GenericPickupController_AttemptGrant == null) { Log.LogError((object)"GenericPickupController.AttemptGrant not found; items cannot be granted to living players."); } if (GenericPickupController_consumed == null) { Log.LogWarning((object)"GenericPickupController.consumed not found; double grants to dead players are possible."); } ModConfig = new Config(this, ((BaseUnityPlugin)this).Logger); TryRegisterRiskOfOptions(); hookManager = new HookManager(this); hookManager.RegisterHooks(); TryRegister("PlayerCharacterMasterController.OnBodyDeath", delegate { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown PlayerCharacterMasterController.OnBodyDeath += new hook_OnBodyDeath(OnPlayerBodyDeath); }); TryRegister("PlayerCharacterMasterController.OnBodyStart", delegate { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown PlayerCharacterMasterController.OnBodyStart += new hook_OnBodyStart(OnPlayerBodyStart); }); TryRegister("PickupDropletController.CreatePickup (IL)", delegate { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown PickupDropletController.CreatePickup += new Manipulator(ModifyCreatePickup); }); TryRegister("PlayerCharacterMasterController.Awake", delegate { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown PlayerCharacterMasterController.Awake += new hook_Awake(OnPlayerAwake); }); PlayerCharacterMasterController.onPlayerAdded += UpdateTargetsWrapper; PlayerCharacterMasterController.onPlayerRemoved += UpdateTargetsWrapper; ModConfig.distributeToDeadPlayers.SettingChanged += OnDeadPlayersSettingChanged; ModConfig.distributionMode.SettingChanged += OnDistributionModeChanged; } public void OnDisable() { hookManager?.UnregisterHooks(); HookEndpointManager.RemoveAllOwnedBy(HookEndpointManager.GetOwner((Delegate)new Action(OnDisable))); PlayerCharacterMasterController.onPlayerAdded -= UpdateTargetsWrapper; PlayerCharacterMasterController.onPlayerRemoved -= UpdateTargetsWrapper; if (ModConfig != null) { ModConfig.distributeToDeadPlayers.SettingChanged -= OnDeadPlayersSettingChanged; ModConfig.distributionMode.SettingChanged -= OnDistributionModeChanged; } } private void TryRegisterRiskOfOptions() { if (!Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions")) { return; } try { RiskOfOptionsCompat.Register(ModConfig); } catch (Exception arg) { Log.LogWarning((object)$"Could not add the in-game Risk Of Options menu; the .cfg file still works.\n{arg}"); } } private void TryRegister(string name, Action register) { try { register(); } catch (Exception arg) { Log.LogError((object)("Failed to hook " + name + "; the mod keeps running without it. " + $"The game was probably updated.\n{arg}")); } } private void OnDeadPlayersSettingChanged(object sender, EventArgs e) { UpdateTargets(); } private void OnDistributionModeChanged(object sender, EventArgs e) { Distributor = ItemDistributor.GetItemDistributor(ModConfig.distributionMode.Value, this); } private void OnPlayerBodyDeath(orig_OnBodyDeath orig, PlayerCharacterMasterController self) { orig.Invoke(self); UpdateTargets(); } private void OnPlayerBodyStart(orig_OnBodyStart orig, PlayerCharacterMasterController self) { orig.Invoke(self); UpdateTargets(); } private void UpdateTargetsWrapper(PlayerCharacterMasterController player) { UpdateTargets(); } private void OnPlayerAwake(orig_Awake orig, PlayerCharacterMasterController self) { orig.Invoke(self); if (!NetworkServer.active) { return; } CharacterMaster master = self.master; if (Object.op_Implicit((Object)(object)master)) { master.onBodyStart += delegate { UpdateTargets(); }; } } private void ModifyCreatePickup(ILContext il) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_006a: 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 i) => ILPatternMatchingExt.MatchCall<GenericPickupController>(i, "CreatePickup") })) { Log.LogError((object)("Could not find the call to GenericPickupController.CreatePickup in " + ((MemberReference)il.Method).FullName + ". Printer/scrapper/Command target overrides will not reach the dropped item.")); return; } val.Emit(OpCodes.Dup); val.Emit(OpCodes.Ldarg_0); val.EmitDelegate<Action<GenericPickupController, PickupDropletController>>((Action<GenericPickupController, PickupDropletController>)delegate(GenericPickupController pickupController, PickupDropletController self) { if (Object.op_Implicit((Object)(object)pickupController) && Object.op_Implicit((Object)(object)self)) { OverrideDistributorBehaviour component = ((Component)self).GetComponent<OverrideDistributorBehaviour>(); if (Object.op_Implicit((Object)(object)component)) { ((Component)pickupController).gameObject.AddComponent<OverrideDistributorBehaviour>().Distributor = component.Distributor; } } }); } [Server] public static void GrantItem(GenericPickupController item, CharacterMaster master) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0088: 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_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Invalid comparison between Unknown and I4 //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: 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_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: 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_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)item) || !Object.op_Implicit((Object)(object)master)) { return; } if (master.hasBody) { if (!(GenericPickupController_AttemptGrant == null)) { GenericPickupController_AttemptGrant.Invoke(item, new object[1] { master.GetBody() }); } return; } object obj = GenericPickupController_consumed?.GetValue(item); if ((!(obj is bool) || !(bool)obj) && Object.op_Implicit((Object)(object)master.inventory)) { PickupDef pickupDef = PickupCatalog.GetPickupDef(item.pickupIndex); ItemIndex val = (ItemIndex)((pickupDef == null) ? (-1) : ((int)pickupDef.itemIndex)); if ((int)val != -1) { master.inventory.GiveItem(val, 1); PlayerCharacterMasterController playerCharacterMasterController = master.playerCharacterMasterController; NetworkUser subjectAsNetworkUser = (((Object)(object)playerCharacterMasterController != (Object)null) ? playerCharacterMasterController.networkUser : null); Chat.AddMessage(((ChatMessageBase)new PlayerPickupChatMessage { subjectAsNetworkUser = subjectAsNetworkUser, baseToken = "PLAYER_PICKUP", pickupToken = (pickupDef?.nameToken ?? PickupCatalog.invalidPickupToken), pickupColor = Color32.op_Implicit(pickupDef?.baseColor ?? Color.black), pickupQuantity = (uint)master.inventory.GetItemCount(val) }).ConstructChatString()); GenericPickupController_consumed?.SetValue(item, true); Object.Destroy((Object)(object)((Component)item).gameObject); } } } private void UpdateTargets() { distributorNeedsUpdate = true; } public void PreDistributeItemInternal(Cause cause) { if (Distributor == null) { Distributor = ItemDistributor.GetItemDistributor(ModConfig.distributionMode.Value, this); } if (distributorNeedsUpdate) { distributorNeedsUpdate = false; Distributor?.UpdateTargets(); } } public void DistributeItemInternal(GenericPickupController item, Cause cause) { if (!Object.op_Implicit((Object)(object)item)) { return; } try { GetDistributorInternal(((Component)item).gameObject, cause)?.DistributeItem(item); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)$"Caught AutoItemPickup distributor exception:\n{ex}\n{ex.StackTrace}"); } } public void DistributeItem(GenericPickupController item, Cause cause) { PreDistributeItemInternal(cause); DistributeItemInternal(item, cause); } public void DistributeItems(IEnumerable<GenericPickupController> items, Cause cause) { PreDistributeItemInternal(cause); foreach (GenericPickupController item in items) { DistributeItemInternal(item, cause); } } public ItemDistributor GetDistributorInternal(GameObject item, Cause cause) { if ((Object)(object)item != (Object)null) { OverrideDistributorBehaviour component = item.GetComponent<OverrideDistributorBehaviour>(); if ((Object)(object)component != (Object)null) { return component.Distributor; } } return Distributor; } public ItemDistributor GetDistributor(GameObject item, Cause cause) { PreDistributeItemInternal(cause); return GetDistributorInternal(item, cause); } } public abstract class ItemDistributor { public delegate bool TargetFilter(CharacterMaster target); private readonly AutoItemPickup plugin; protected ItemDistributor(AutoItemPickup plugin) { this.plugin = plugin; UpdateTargets(); } public abstract CharacterMaster GetTarget(Vector3 position, PickupIndex pickupIndex, TargetFilter extraFilter = null); public virtual void DistributeItem(ref CreatePickupInfo pickupInfo, TargetFilter extraFilter = null) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0026: 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_003f: 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) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) CharacterMaster target = GetTarget(pickupInfo.position, ((CreatePickupInfo)(ref pickupInfo)).pickupIndex, extraFilter); if (Object.op_Implicit((Object)(object)target)) { Vector3 val = (target.hasBody ? ((Component)target.GetBody()).transform.position : target.deathFootPosition); pickupInfo.position = val + Vector3.up * 2f; } } public virtual void DistributeItem(GenericPickupController item, TargetFilter extraFilter = null) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) CharacterMaster target = GetTarget(((Component)item).transform.position, item.pickupIndex, extraFilter); if (Object.op_Implicit((Object)(object)target)) { AutoItemPickup.GrantItem(item, target); } } public abstract void UpdateTargets(); public virtual bool IsValid() { return true; } protected bool IsValidTarget(CharacterMaster master) { return plugin.ModConfig.CheckTarget(master); } protected bool IsValidTarget(PlayerCharacterMasterController player) { if ((Object)(object)player != (Object)null) { return IsValidTarget(player.master); } return false; } protected List<PlayerCharacterMasterController> GetValidTargets() { return PlayerCharacterMasterController.instances.Where(IsValidTarget).ToList(); } public static ItemDistributor GetItemDistributor(Mode mode, AutoItemPickup plugin) { return mode switch { Mode.Closest => new ClosestDistributor(plugin), Mode.LeastItems => new LeastItemsDistributor(plugin), Mode.Random => new RandomDistributor(plugin), _ => new SequentialDistributor(plugin), }; } } public class OverrideDistributorBehaviour : MonoBehaviour { public ItemDistributor Distributor; } internal static class RiskOfOptionsCompat { public const string Guid = "com.rune580.riskofoptions"; private static ConfigFile proxyFile; private static Sprite modIcon; [MethodImpl(MethodImplOptions.NoInlining)] public static void Register(Config config) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Expected O, but got Unknown //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Expected O, but got Unknown //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Expected O, but got Unknown //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Expected O, but got Unknown //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Expected O, but got Unknown //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Expected O, but got Unknown //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Expected O, but got Unknown //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Expected O, but got Unknown //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Expected O, but got Unknown RegisterIcon(); ModSettingsManager.SetModDescription("Automatically distributes items among players using the host's settings. Optional CommandQueue auto-interaction uses each player's local queue and settings."); ModSettingsManager.AddOption((BaseOption)new ChoiceOption((ConfigEntryBase)(object)config.distributionMode)); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(config.distributeToDeadPlayers)); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(config.printerOverrideTarget)); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(config.scrapperOverrideTarget)); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(config.distributeOnDrop)); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(config.distributeOnTeleport)); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(config.teleportCommandOnDrop)); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(config.teleportCommandOnTeleport)); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(config.teleportCommandObeyTier)); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(config.autoOpenQueuedCommand)); ModSettingsManager.AddOption((BaseOption)new FloatFieldOption(config.queuedCommandRadius)); if (config.Ready) { RegisterFilters(config); return; } config.OnConfigReady += delegate { RegisterFilters(config); }; } private static void RegisterIcon() { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Expected O, but got Unknown //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) Texture2D val = null; try { if (!Object.op_Implicit((Object)(object)modIcon)) { using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("AutoItemPickup.icon.png"); if (stream == null) { throw new FileNotFoundException("Embedded mod icon was not found."); } using MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); val = new Texture2D(2, 2); if (!ImageConversion.LoadImage(val, memoryStream.ToArray())) { throw new InvalidDataException("Could not decode the mod icon."); } modIcon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)); } ModSettingsManager.SetModIcon(modIcon); } catch (Exception arg) { if (Object.op_Implicit((Object)(object)val) && !Object.op_Implicit((Object)(object)modIcon)) { Object.Destroy((Object)(object)val); } AutoItemPickup.Log.LogWarning((object)$"Could not load the Risk Of Options icon; settings remain available.\n{arg}"); } } private static void RegisterFilters(Config config) { //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_0021: Expected O, but got Unknown try { proxyFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "AutoItemPickup.riskofoptions.unused"), false) { SaveOnConfigSet = false }; AddFilter(config.OnDrop); AddFilter(config.OnTeleport); } catch (Exception arg) { AutoItemPickup.Log.LogWarning((object)$"Could not add the item filters to the Risk Of Options menu; they still work in the .cfg file.\n{arg}"); } } private static void AddFilter(ItemFilter filter) { AddTextOption(filter.TierWhitelistEntry, ItemTierSet.Deserialize); AddTextOption(filter.ItemWhitelistEntry, ItemSet.Deserialize); AddTextOption(filter.ItemBlacklistEntry, ItemSet.Deserialize); } private static void AddTextOption<T>(ConfigEntry<T> real, Func<string, T> parse) where T : class { //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Expected O, but got Unknown ConfigDefinition definition = ((ConfigEntryBase)real).Definition; ConfigEntry<string> proxy = proxyFile.Bind<string>(definition, real.Value?.ToString() ?? "", ((ConfigEntryBase)real).Description); bool syncing = false; proxy.SettingChanged += delegate { if (syncing) { return; } syncing = true; try { T val = parse(proxy.Value ?? ""); if (val.ToString() != (real.Value?.ToString() ?? "")) { real.Value = val; } } catch (Exception ex) { AutoItemPickup.Log.LogWarning((object)("Invalid value for " + definition.Section + "/" + definition.Key + ": " + ex.Message)); } finally { syncing = false; } }; real.SettingChanged += delegate { if (syncing) { return; } syncing = true; try { string text = real.Value?.ToString() ?? ""; if (proxy.Value != text) { proxy.Value = text; } } finally { syncing = false; } }; ModSettingsManager.AddOption((BaseOption)new StringInputFieldOption(proxy)); } } } namespace AutoItemPickup.ItemDistributors { internal class ClosestDistributor : ItemDistributor { private CharacterMaster[] targets; public ClosestDistributor(AutoItemPickup plugin) : base(plugin) { } public override void UpdateTargets() { targets = (from player in GetValidTargets() select player.master).ToArray(); } public override CharacterMaster GetTarget(Vector3 position, PickupIndex pickupIndex, TargetFilter extraFilter = null) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0050: 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_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005a: 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) CharacterMaster result = null; float num = float.MaxValue; CharacterMaster[] array = targets; foreach (CharacterMaster val in array) { if (Object.op_Implicit((Object)(object)val) && (extraFilter == null || extraFilter(val))) { Vector3 val2 = (val.hasBody ? val.GetBodyObject().transform.position : val.deathFootPosition); Vector3 val3 = position - val2; float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude; if (sqrMagnitude < num) { result = val; num = sqrMagnitude; } } } return result; } } internal class FixedTargetDistributor : ItemDistributor { private readonly CharacterMaster target; public FixedTargetDistributor(AutoItemPickup plugin, PlayerCharacterMasterController target) : this(plugin, target.master) { } public FixedTargetDistributor(AutoItemPickup plugin, CharacterMaster target) : base(plugin) { this.target = target; } public override bool IsValid() { return IsValidTarget(target); } public override void UpdateTargets() { } public override CharacterMaster GetTarget(Vector3 position, PickupIndex pickupIndex, TargetFilter extraFilter = null) { if (extraFilter != null && !extraFilter(target)) { return null; } return target; } } internal class LeastItemsDistributor : ItemDistributor { private CharacterMaster[] targets; public LeastItemsDistributor(AutoItemPickup plugin) : base(plugin) { } public override void UpdateTargets() { List<PlayerCharacterMasterController> validTargets = GetValidTargets(); targets = (CharacterMaster[])(object)new CharacterMaster[validTargets.Count]; for (int i = 0; i < validTargets.Count; i++) { PlayerCharacterMasterController val = validTargets[i]; targets[i] = val.master; } } public override CharacterMaster GetTarget(Vector3 position, PickupIndex pickupIndex, TargetFilter extraFilter = null) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) CharacterMaster result = null; int num = int.MaxValue; PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndex); ItemDef val = ((pickupDef != null) ? ItemCatalog.GetItemDef(pickupDef.itemIndex) : null); CharacterMaster[] array = targets; foreach (CharacterMaster val2 in array) { if (Object.op_Implicit((Object)(object)val2) && (extraFilter == null || extraFilter(val2))) { if ((Object)(object)val == (Object)null || !Object.op_Implicit((Object)(object)val2.inventory)) { return val2; } int totalItemCountOfTier = val2.inventory.GetTotalItemCountOfTier(val.tier); if (totalItemCountOfTier < num) { result = val2; num = totalItemCountOfTier; } } } return result; } } internal class RandomDistributor : ItemDistributor { private CharacterMaster[] targets; public RandomDistributor(AutoItemPickup plugin) : base(plugin) { } public override void UpdateTargets() { targets = (from pcmc in GetValidTargets() select pcmc.master).ToArray(); } public override CharacterMaster GetTarget(Vector3 position, PickupIndex pickupIndex, TargetFilter extraFilter = null) { IEnumerable<CharacterMaster> source = targets.Where((CharacterMaster target) => Object.op_Implicit((Object)(object)target)); if (extraFilter != null) { source = source.Where((CharacterMaster target) => extraFilter(target)); } CharacterMaster[] array = source.ToArray(); return array.ElementAtOrDefault(Random.Range(0, array.Length)); } } internal class SequentialDistributor : ItemDistributor { private int index; private CharacterMaster[] playerDistribution; public SequentialDistributor(AutoItemPickup plugin) : base(plugin) { } public override void UpdateTargets() { CharacterMaster val = null; if (playerDistribution != null && index >= 0 && index < playerDistribution.Length) { val = playerDistribution[index]; } List<PlayerCharacterMasterController> validTargets = GetValidTargets(); playerDistribution = (CharacterMaster[])(object)new CharacterMaster[validTargets.Count]; index = -1; for (int i = 0; i < validTargets.Count; i++) { PlayerCharacterMasterController val2 = validTargets[i]; playerDistribution[i] = val2.master; if (Object.op_Implicit((Object)(object)val) && (Object)(object)val2.master == (Object)(object)val) { index = i; } } if (index == -1) { index = ((playerDistribution.Length != 0) ? Random.Range(0, playerDistribution.Length) : 0); } } public override CharacterMaster GetTarget(Vector3 position, PickupIndex pickupIndex, TargetFilter extraFilter = null) { if (playerDistribution == null || playerDistribution.Length == 0) { return null; } if (index < 0 || index >= playerDistribution.Length) { index = 0; } CharacterMaster result = null; for (int i = 0; i < playerDistribution.Length; i++) { CharacterMaster val = playerDistribution[(index + i) % playerDistribution.Length]; if (Object.op_Implicit((Object)(object)val) && (extraFilter == null || extraFilter(val))) { result = val; index = (index + i + 1) % playerDistribution.Length; break; } } return result; } } } namespace AutoItemPickup.Enums { public enum Cause { Teleport, Drop } public enum Mode { Sequential, Random, Closest, LeastItems } } namespace AutoItemPickup.Configuration { public class Config { public readonly AutoItemPickup Plugin; private readonly ManualLogSource logger; public ConfigEntry<Mode> distributionMode; public ConfigEntry<bool> printerOverrideTarget; public ConfigEntry<bool> scrapperOverrideTarget; public ConfigEntry<bool> teleportCommandObeyTier; public ConfigEntry<bool> distributeToDeadPlayers; public ConfigEntry<bool> distributeOnDrop; public ConfigEntry<bool> distributeOnTeleport; public ItemFilter OnDrop; public ItemFilter OnTeleport; public ConfigEntry<bool> teleportCommandOnDrop; public ConfigEntry<bool> teleportCommandOnTeleport; public ConfigEntry<bool> autoOpenQueuedCommand; public ConfigEntry<float> queuedCommandRadius; public ConfigMigrator migrator; private bool OnDropReady => OnDrop?.Ready ?? false; private bool OnTeleportReady => OnTeleport?.Ready ?? false; public bool Ready { get { if (OnDropReady) { return OnTeleportReady; } return false; } } private ConfigFile config => ((BaseUnityPlugin)Plugin).Config; public event Action OnConfigReady; public Config(AutoItemPickup plugin, ManualLogSource _logger) { //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Expected O, but got Unknown Plugin = plugin; logger = _logger; migrator = new ConfigMigrator(config, this); OnTeleport = new ItemFilter("OnTeleportFilter", config); OnDrop = new ItemFilter("OnDropFilter", config); distributeToDeadPlayers = config.Bind<bool>("General", "DistributeToDeadPlayers", true, "Should items be distributed to dead players?"); printerOverrideTarget = config.Bind<bool>("General", "OverridePrinterTarget", true, "Should items from printers and cauldrons be distributed only to activator as long as they're a valid target?"); scrapperOverrideTarget = config.Bind<bool>("General", "OverrideScrapperTarget", true, "Should scrap from scrappers be distributed only to activator as long as they're a valid target?"); distributionMode = config.Bind<Mode>("General", "DistributionMode", Mode.Sequential, "Decide how to distribute items among the players\r\nSequential - Goes over all players, giving each of them one item\r\nRandom - Chooses which player receives the item randomly\r\nClosest - Gives the item to the nearest player\r\nLeastItems - Gives the item to the player with least total items of the item's tier"); distributeOnDrop = config.Bind<bool>("Items", "DistributeOnDrop", false, "Should items be distributed when they drop?"); distributeOnTeleport = config.Bind<bool>("Items", "DistributeOnTeleport", true, "Should items be distributed when the teleporter is activated?"); teleportCommandOnDrop = config.Bind<bool>("Command", "DistributeOnDrop", true, "Should Command essences be teleported to players?\r\nIf enabled, when an essence is spawned, it will teleport to a player using distribution mode rules. It will not be opened automatically.\r\nNote: Doesn't work well with LeastItems, due to LeastItems only accounting for the current number of items and not including any unopened command essences."); teleportCommandOnTeleport = config.Bind<bool>("Command", "DistributeOnTeleport", true, "Should Command essences be teleported to the teleporter when charged?\r\nIf enabled, when the teleporter is charged, all essences are teleported nearby the teleporter.\r\nAfterwards, any new essences that do not fit the requirements for OnDrop distribution will also be teleported nearby the teleporter."); teleportCommandObeyTier = config.Bind<bool>("Command", "UseTierWhitelist", true, "Should Command essence teleportation be restricted by item tiers?\r\nIf enabled, when deciding if a command essence should be teleported, its tier will be compared against the OnDrop/OnTeleport tier whitelist."); autoOpenQueuedCommand = config.Bind<bool>("Command", "AutoOpenQueuedCommand", true, "Automatically interact with nearby permanent Command essences when Nick's Command Queue Flavour has an available queued choice. Uses your local queue, including reservations and repeat mode. Empty/unavailable queues remain manual. Each player who wants this feature needs both mods installed. Independent of the item distribution and essence teleport filters."); queuedCommandRadius = config.Bind<float>("Command", "QueuedCommandRadius", 8f, new ConfigDescription("Maximum distance in meters for automatic Command interaction, also limited by the game's prompt cutoff distance.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 30f), Array.Empty<object>())); config.SettingChanged += ConfigOnSettingChanged; OnTeleport.OnReady += CheckReadyStatus; OnDrop.OnReady += CheckReadyStatus; OnConfigReady += DoMigrationIfReady; DoMigrationIfReady(); } private void CheckReadyStatus() { if (Ready) { this.OnConfigReady?.Invoke(); } } private void DoMigrationIfReady() { if (Ready && migrator.NeedsMigration) { migrator.DoMigration(); } } public bool CheckTarget(CharacterMaster master) { if ((Object)(object)master != (Object)null) { if (!master.hasBody) { return distributeToDeadPlayers.Value; } return true; } return false; } public bool ShouldDistribute(PickupIndex index, Cause cause) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Invalid comparison between Unknown and I4 //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) if (!((cause == Cause.Drop) ? distributeOnDrop : distributeOnTeleport).Value) { return false; } PickupDef pickupDef = PickupCatalog.GetPickupDef(index); if (pickupDef == null || (int)pickupDef.itemIndex == -1) { return false; } ItemDef itemDef = ItemCatalog.GetItemDef(pickupDef.itemIndex); if ((Object)(object)itemDef == (Object)null) { return false; } return ((cause == Cause.Drop) ? OnDrop : OnTeleport).CheckFilter(itemDef.itemIndex); } public bool ShouldDistributeCommand(ItemTier tier, Cause cause) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) if (!((cause == Cause.Drop) ? teleportCommandOnDrop : teleportCommandOnTeleport).Value) { return false; } if (!teleportCommandObeyTier.Value) { return true; } return ((cause == Cause.Drop) ? OnDrop : OnTeleport).CheckFilterTier(tier); } public bool ShouldDistributeCommand(PickupIndex index, Cause cause) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Invalid comparison between Unknown and I4 //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) if (!((cause == Cause.Drop) ? teleportCommandOnDrop : teleportCommandOnTeleport).Value) { return false; } PickupDef pickupDef = PickupCatalog.GetPickupDef(index); if (pickupDef == null || (int)pickupDef.itemIndex == -1) { return false; } if (!teleportCommandObeyTier.Value) { return true; } ItemDef itemDef = ItemCatalog.GetItemDef(pickupDef.itemIndex); if ((Object)(object)itemDef == (Object)null) { return false; } return ((cause == Cause.Drop) ? OnDrop : OnTeleport).CheckFilterTier(itemDef.tier); } private void ConfigOnSettingChanged(object sender, SettingChangedEventArgs e) { if (e.ChangedSetting.SettingType == typeof(ItemSet)) { ConfigEntry<ItemSet> val = (ConfigEntry<ItemSet>)(object)e.ChangedSetting; ItemSet value = val.Value; IList<string> parseErrors = value.ParseErrors; if (parseErrors != null && parseErrors.Count > 0) { string text = "Errors found when parsing " + ((ConfigEntryBase)val).Definition.Key + " for " + ((ConfigEntryBase)val).Definition.Section + ":\n\t" + string.Join("\n\t", value.ParseErrors); logger.LogWarning((object)text); } } } } public class ConfigMigrator { private static PropertyInfo Property_ConfigFiles_OrphanedEntries = typeof(ConfigFile).GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private ConfigFile config; private Dictionary<ConfigDefinition, string> OrphanedEntries; private Config ModConfig; private static Dictionary<ConfigDefinition, Action<Config, string>> migrations = new Dictionary<ConfigDefinition, Action<Config, string>> { { new ConfigDefinition("General", "TeleportCommandCubes"), delegate(Config config, string value) { ConfigEntry<bool> teleportCommandOnDrop = config.teleportCommandOnDrop; bool value2 = (config.teleportCommandOnTeleport.Value = value == "true"); teleportCommandOnDrop.Value = value2; } }, { new ConfigDefinition("General", "DebugItemDefinitions"), delegate { } }, { new ConfigDefinition("General", "DistributeOnDrop"), delegate(Config config, string value) { config.distributeOnDrop.Value = value == "true"; } }, { new ConfigDefinition("General", "DistributeOnTeleport"), delegate(Config config, string value) { config.distributeOnTeleport.Value = value == "true"; } }, { new ConfigDefinition("OnDrop", "ItemDistributionMode"), delegate(Config config, string value) { config.distributionMode.Value = (Mode)Enum.Parse(typeof(Mode), value); } }, { new ConfigDefinition("OnDrop", "DistributeWhiteItems"), delegate(Config config, string value) { MigrateItemTier(config.OnDrop.TierWhitelist, (ItemTier)0, value); } }, { new ConfigDefinition("OnDrop", "DistributeGreenItems"), delegate(Config config, string value) { MigrateItemTier(config.OnDrop.TierWhitelist, (ItemTier)1, value); } }, { new ConfigDefinition("OnDrop", "DistributeRedItems"), delegate(Config config, string value) { MigrateItemTier(config.OnDrop.TierWhitelist, (ItemTier)2, value); } }, { new ConfigDefinition("OnDrop", "DistributeLunarItems"), delegate(Config config, string value) { MigrateItemTier(config.OnDrop.TierWhitelist, (ItemTier)3, value); } }, { new ConfigDefinition("OnDrop", "DistributeBossItems"), delegate(Config config, string value) { MigrateItemTier(config.OnDrop.TierWhitelist, (ItemTier)4, value); } }, { new ConfigDefinition("OnDrop", "ItemBlacklist"), delegate(Config config, string value) { config.OnDrop.ItemBlacklistEntry.Value = ItemSet.Deserialize(value); } }, { new ConfigDefinition("OnTeleport", "ItemDistributionMode"), delegate { } }, { new ConfigDefinition("OnTeleport", "DistributeWhiteItems"), delegate(Config config, string value) { MigrateItemTier(config.OnTeleport.TierWhitelist, (ItemTier)0, value); } }, { new ConfigDefinition("OnTeleport", "DistributeGreenItems"), delegate(Config config, string value) { MigrateItemTier(config.OnTeleport.TierWhitelist, (ItemTier)1, value); } }, { new ConfigDefinition("OnTeleport", "DistributeRedItems"), delegate(Config config, string value) { MigrateItemTier(config.OnTeleport.TierWhitelist, (ItemTier)2, value); } }, { new ConfigDefinition("OnTeleport", "DistributeLunarItems"), delegate(Config config, string value) { MigrateItemTier(config.OnTeleport.TierWhitelist, (ItemTier)3, value); } }, { new ConfigDefinition("OnTeleport", "DistributeBossItems"), delegate(Config config, string value) { MigrateItemTier(config.OnTeleport.TierWhitelist, (ItemTier)4, value); } }, { new ConfigDefinition("OnTeleport", "ItemBlacklist"), delegate(Config config, string value) { config.OnTeleport.ItemBlacklistEntry.Value = ItemSet.Deserialize(value); } } }; public bool NeedsMigration => migrations.Keys.Any((ConfigDefinition def) => OrphanedEntries.ContainsKey(def)); public ConfigMigrator(ConfigFile config, Config modConfig) { this.config = config; ModConfig = modConfig; OrphanedEntries = (Dictionary<ConfigDefinition, string>)Property_ConfigFiles_OrphanedEntries.GetValue(config); } private static void MigrateItemTier(ItemTierSet set, ItemTier tier, string value) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) if (value == "true") { set.Add(tier); } else { set.Remove(tier); } } public void DoMigration() { List<ConfigDefinition> list = new List<ConfigDefinition>(); foreach (KeyValuePair<ConfigDefinition, Action<Config, string>> migration in migrations) { ConfigDefinition key = migration.Key; Action<Config, string> value = migration.Value; if (OrphanedEntries.TryGetValue(key, out var value2)) { value(ModConfig, value2); list.Add(key); } } foreach (ConfigDefinition item in list) { OrphanedEntries.Remove(item); } config.Save(); } } public class ItemFilter { private readonly ConfigFile config; public ConfigEntry<ItemSet> ItemBlacklistEntry; public ConfigEntry<ItemSet> ItemWhitelistEntry; public ConfigEntry<ItemTierSet> TierWhitelistEntry; public string Type; public bool Ready; public ItemTierSet TierWhitelist => TierWhitelistEntry.Value; public ItemSet ItemWhitelist => ItemWhitelistEntry.Value; public ItemSet ItemBlacklist => ItemBlacklistEntry.Value; public event Action OnReady; static ItemFilter() { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: 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_0040: Expected O, but got Unknown //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Expected O, but got Unknown TomlTypeConverter.AddConverter(typeof(ItemTierSet), new TypeConverter { ConvertToObject = (string str, Type type) => ItemTierSet.Deserialize(str), ConvertToString = (object obj, Type type) => obj.ToString() }); TomlTypeConverter.AddConverter(typeof(ItemSet), new TypeConverter { ConvertToObject = (string str, Type type) => ItemSet.Deserialize(str), ConvertToString = (object obj, Type type) => obj.ToString() }); } public ItemFilter(string type, ConfigFile config) { Type = type; this.config = config; if (ItemSet.Initialized) { CreateSets(); } else { ItemSet.OnInitialized += CreateSets; } } public bool CheckFilter(ItemIndex index) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) if (!Ready) { return false; } ItemDef itemDef = ItemCatalog.GetItemDef(index); if ((Object)(object)itemDef == (Object)null) { return false; } if (!ItemBlacklist.HasItem(index)) { if (!TierWhitelist.Contains(itemDef.tier)) { return ItemWhitelist.HasItem(index); } return true; } return false; } public bool CheckFilterTier(ItemTier tier) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) if (Ready) { return TierWhitelist.Contains(tier); } return false; } private void CreateSets() { //IL_0012: 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_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown //IL_0086: Expected O, but got Unknown //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Expected O, but got Unknown //IL_00bc: Expected O, but got Unknown //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Expected O, but got Unknown //IL_00f2: Expected O, but got Unknown TierWhitelistEntry = config.Bind<ItemTierSet>(new ConfigDefinition(Type, "TierWhitelist"), new ItemTierSet { (ItemTier)0, (ItemTier)1, (ItemTier)2 }, new ConfigDescription("Which item tiers should be distributed?\nValid values: " + string.Join(", ", ((IEnumerable<ItemTierDef>)(object)ItemTierCatalog.allItemTierDefs).Select((ItemTierDef def) => ((Object)def).name)), (AcceptableValueBase)null, Array.Empty<object>())); ItemWhitelistEntry = config.Bind<ItemSet>(new ConfigDefinition(Type, "ItemWhitelist"), new ItemSet(), new ConfigDescription("Which items should be distributed, regardless of tier?\nAccepts localized english item names and internal names, use backslash for escapes", (AcceptableValueBase)null, Array.Empty<object>())); ItemBlacklistEntry = config.Bind<ItemSet>(new ConfigDefinition(Type, "ItemBlacklist"), new ItemSet(), new ConfigDescription("Which items should NOT be distributed, regardless of tier?\nAccepts localized english item names and internal names, use backslash for escapes", (AcceptableValueBase)null, Array.Empty<object>())); Ready = true; this.OnReady?.Invoke(); } } public class ItemSet { public enum ItemNameSource { EN_Name, Def_Name } public struct ItemWrapper { public ItemIndex itemIndex; public string EN_Name; public string Def_Name; public ItemNameSource itemNameSource; public string GetName() { return itemNameSource switch { ItemNameSource.EN_Name => EN_Name, ItemNameSource.Def_Name => Def_Name, _ => EN_Name ?? Def_Name ?? ((object)Unsafe.As<ItemIndex, ItemIndex>(ref itemIndex)/*cast due to .constrained prefix*/).ToString(), }; } public override bool Equals(object obj) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) if (!(obj is ItemWrapper itemWrapper)) { return false; } if (itemIndex == itemWrapper.itemIndex) { return EN_Name == itemWrapper.EN_Name; } return false; } public override int GetHashCode() { return ((17 * 31 + ((object)Unsafe.As<ItemIndex, ItemIndex>(ref itemIndex)/*cast due to .constrained prefix*/).GetHashCode()) * 31 + EqualityComparer<string>.Default.GetHashCode(EN_Name)) * 31 + EqualityComparer<string>.Default.GetHashCode(Def_Name); } } public static readonly Dictionary<string, ItemWrapper> ItemsByEnglishName; public static readonly Dictionary<string, ItemWrapper> ItemsByDefName; public static readonly Dictionary<ItemIndex, ItemWrapper> ItemsByIndex; private static readonly Regex regexEscapes; private static readonly Regex regexEntries; private readonly HashSet<ItemWrapper> items = new HashSet<ItemWrapper>(); public IList<string> ParseErrors; public static bool Initialized { get; private set; } internal static event Action OnInitialized; static ItemSet() { ItemsByEnglishName = new Dictionary<string, ItemWrapper>(); ItemsByDefName = new Dictionary<string, ItemWrapper>(); ItemsByIndex = new Dictionary<ItemIndex, ItemWrapper>(); regexEscapes = new Regex("(?:([^\\\\]+)|(?:\\\\(.)))", RegexOptions.IgnoreCase | RegexOptions.Compiled); regexEntries = new Regex("([^,]*)(,|$)", RegexOptions.IgnoreCase | RegexOptions.Compiled); TryInitialize(); ((ResourceAvailability)(ref ItemCatalog.availability)).CallWhenAvailable((Action)delegate { TryInitialize(); }); RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, (Action)delegate { TryInitialize(); }); } public ItemSet() { if (!Initialized) { TryInitialize(); } } public static string Escape(string s) { return s.Replace(",", "\\,"); } public void AddParseError(string error) { if (ParseErrors == null) { ParseErrors = new List<string>(); } ParseErrors.Add(error); } public static IEnumerable<string> Parse(string s) { MatchCollection matchCollection = regexEscapes.Matches(s); List<string> list = new List<string>(); StringBuilder stringBuilder = new StringBuilder(); foreach (Match item in matchCollection) { if (item.Groups[2].Length > 0) { stringBuilder.Append(item.Groups[2].Value); continue; } foreach (Match item2 in regexEntries.Matches(item.Groups[1].Value)) { stringBuilder.Append(item2.Groups[1].Value); if (item2.Groups[2].Length > 0) { list.Add(stringBuilder.ToString()); stringBuilder.Clear(); } } } if (stringBuilder.Length > 0) { list.Add(stringBuilder.ToString()); } return list.Select((string entry) => entry.Trim()); } public static string Serialize(ItemSet self) { if (!TryInitialize()) { throw new InvalidOperationException("ItemSet cannot be initialized at this point"); } StringBuilder stringBuilder = new StringBuilder(); using (IEnumerator<string> enumerator = self.items.Select((ItemWrapper item) => Escape(item.GetName())).GetEnumerator()) { if (enumerator.MoveNext()) { stringBuilder.Append(enumerator.Current); while (enumerator.MoveNext()) { stringBuilder.Append(", "); stringBuilder.Append(enumerator.Current); } } } return stringBuilder.ToString(); } public static ItemSet Deserialize(string src) { //IL_006c: Unknown result type (might be due to invalid IL or missing references) if (!TryInitialize()) { throw new InvalidOperationException("ItemSet cannot be initialized at this point"); } ItemSet itemSet = new ItemSet(); foreach (string item in Parse(src)) { if (!ItemsByEnglishName.TryGetValue(item, out var value) && !ItemsByDefName.TryGetValue(item, out value)) { itemSet.AddParseError("Invalid item in blacklist: " + item + "; ignoring"); value = new ItemWrapper { itemIndex = (ItemIndex)(-1), EN_Name = item, itemNameSource = ItemNameSource.EN_Name }; } itemSet.items.Add(value); } return itemSet; } public override string ToString() { return Serialize(this); } public static bool TryInitialize() { //IL_0024: 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_0057: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) if (Initialized) { return true; } if (!((ResourceAvailability)(ref ItemCatalog.availability)).available || Language.english == null) { return false; } Language english = Language.english; foreach (ItemDef item in ((IEnumerable<ItemIndex>)(object)ItemCatalog.allItems).Select((Func<ItemIndex, ItemDef>)ItemCatalog.GetItemDef)) { ItemIndex itemIndex = item.itemIndex; string text = null; if (item.nameToken != null) { text = english.GetLocalizedStringByToken(item.nameToken); } ItemWrapper value = new ItemWrapper { itemIndex = itemIndex, EN_Name = text, Def_Name = ((Object)item).name, itemNameSource = ItemNameSource.EN_Name }; ItemsByIndex[itemIndex] = value; if (text != null) { ItemsByEnglishName[text] = value; } value.itemNameSource = ItemNameSource.Def_Name; ItemsByDefName[((Object)item).name] = value; } foreach (ItemWrapper item2 in ItemsByIndex.Values.Where((ItemWrapper wrapper) => wrapper.EN_Name != null)) { string key = item2.EN_Name.Trim(); if (!ItemsByEnglishName.ContainsKey(key)) { ItemsByEnglishName[key] = item2; } } Initialized = true; ItemSet.OnInitialized?.Invoke(); return true; } public void AddItem(ItemWrapper item) { items.Add(item); } public void RemoveItem(ItemWrapper item) { items.Remove(item); } public bool HasItem(ItemWrapper item) { return items.Contains(item); } public void AddItem(ItemWrapper? item) { AddItem(item.Value); } public void RemoveItem(ItemWrapper? item) { RemoveItem(item.Value); } public bool HasItem(ItemWrapper? item) { return HasItem(item.Value); } public void AddItem(string name) { AddItem(GetItemByName(name)); } public void RemoveItem(string name) { RemoveItem(GetItemByName(name)); } public bool HasItem(string name) { return HasItem(GetItemByName(name)); } public void AddItem(ItemIndex name) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) AddItem(GetItemByIndex(name)); } public void RemoveItem(ItemIndex name) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) RemoveItem(GetItemByIndex(name)); } public bool HasItem(ItemIndex name) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return HasItem(GetItemByIndex(name)); } public static ItemWrapper? GetItemByName(string name) { if (!ItemsByDefName.TryGetValue(name, out var value) && !ItemsByEnglishName.TryGetValue(name, out value) && !ItemsByEnglishName.TryGetValue(name.Trim(), out value)) { return null; } return value; } public static ItemWrapper? GetItemByIndex(ItemIndex index) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) if (!ItemsByIndex.TryGetValue(index, out var value)) { return null; } return value; } } public class ItemTierSet : SortedSet<ItemTier> { public static string Serialize(ItemTierSet self) { return string.Join(", ", self.Select((ItemTier x) => ((Object)ItemTierCatalog.GetItemTierDef(x)).name)); } public static ItemTierSet Deserialize(string src) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) ItemTierSet itemTierSet = new ItemTierSet(); foreach (string item in from s in src.Split(',') select s.Trim()) { if (Enum.TryParse<ItemTier>(item, out ItemTier result)) { itemTierSet.Add(result); continue; } ItemTierDef val = ItemTierCatalog.FindTierDef(item); int result2; if ((Object)(object)val != (Object)null) { itemTierSet.Add(val.tier); } else if (int.TryParse(item, out result2)) { itemTierSet.Add((ItemTier)result2); } } return itemTierSet; } public override string ToString() { return Serialize(this); } } } namespace AutoItemPickup.Hooks { public abstract class AbstractHookHandler { internal HookManager hookManager; protected AutoItemPickup Plugin => hookManager.Plugin; protected Config ModConfig => Plugin.ModConfig; public virtual string Name => GetType().Name; public void Init(HookManager _hookManager) { hookManager = _hookManager; } public abstract void RegisterHooks(); public abstract void UnregisterHooks(); protected void LogPatchFailed(ILContext il, string what) { AutoItemPickup.Log.LogError((object)("[" + Name + "] Could not find " + what + " in " + ((MemberReference)il.Method).FullName + ". The game was probably updated and this feature is disabled until the mod is updated.")); } } public class HookManager { public readonly Dictionary<Type, AbstractHookHandler> HookHandlers = new Dictionary<Type, AbstractHookHandler>(); public readonly AutoItemPickup Plugin; public HookManager(AutoItemPickup pluginInstance) { Plugin = pluginInstance; RegisterHandler<CreatePickupDropletHandler>(); RegisterHandler<PrinterTargetHandler>(); RegisterHandler<ScrapperTargetHandler>(); RegisterHandler<CommandTargetHandler>(); RegisterHandler<CommandHandler>(); RegisterHandler<CommandQueueHandler>(); RegisterHandler<ItemHandler>(); } public void RegisterHandler<T>() where T : AbstractHookHandler, new() { T val = new T(); val.Init(this); HookHandlers[typeof(T)] = val; } public T GetHandler<T>() where T : AbstractHookHandler { return (T)HookHandlers[typeof(T)]; } public void RegisterHooks() { foreach (AbstractHookHandler value in HookHandlers.Values) { try { value.RegisterHooks(); } catch (Exception arg) { AutoItemPickup.Log.LogError((object)("[" + value.Name + "] Failed to register hooks; this feature is disabled. " + $"The game was probably updated.\n{arg}")); try { value.UnregisterHooks(); } catch (Exception) { } } } } public void UnregisterHooks() { foreach (AbstractHookHandler value in HookHandlers.Values) { try { value.UnregisterHooks(); } catch (Exception arg) { AutoItemPickup.Log.LogWarning((object)$"[{value.Name}] Failed to unregister hooks:\n{arg}"); } } } } public class CommandHandler : AbstractHookHandler { private static readonly FieldInfo Field_createPickupInfo = typeof(PickupDropletController).GetField("createPickupInfo", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static bool CanRedirectCommandCube { get { if (Field_createPickupInfo != null) { return Field_createPickupInfo.FieldType == typeof(CreatePickupInfo); } return false; } } public override void RegisterHooks() { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown if (CanRedirectCommandCube) { PickupDropletController.CreateCommandCube += new hook_CreateCommandCube(On_PickupDropletController_CreateCommandCube); } else { AutoItemPickup.Log.LogWarning((object)"PickupDropletController.createPickupInfo no longer exists in this game version. Command essences will not be redirected on drop until the mod is updated."); } TeleporterInteraction.onTeleporterChargedGlobal += OnTeleporterCharged; } public override void UnregisterHooks() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown PickupDropletController.CreateCommandCube -= new hook_CreateCommandCube(On_PickupDropletController_CreateCommandCube); TeleporterInteraction.onTeleporterChargedGlobal -= OnTeleporterCharged; } private void On_PickupDropletController_CreateCommandCube(orig_CreateCommandCube orig, PickupDropletController self) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) try { CreatePickupInfo pickupInfo = (CreatePickupInfo)Field_createPickupInfo.GetValue(self); if (base.ModConfig.ShouldDistributeCommand(((CreatePickupInfo)(ref pickupInfo)).pickupIndex, Cause.Drop)) { base.Plugin.GetDistributor(((Component)self).gameObject, Cause.Drop)?.DistributeItem(ref pickupInfo, (CharacterMaster target) => Object.op_Implicit((Object)(object)target) && target.hasBody); Field_createPickupInfo.SetValue(self, pickupInfo); } else if (Object.op_Implicit((Object)(object)TeleporterInteraction.instance) && TeleporterInteraction.instance.isCharged && base.ModConfig.ShouldDistributeCommand(((CreatePickupInfo)(ref pickupInfo)).pickupIndex, Cause.Teleport)) { pickupInfo.position = GetTeleporterCommandTargetPosition(); Field_createPickupInfo.SetValue(self, pickupInfo); } } catch (Exception arg) { AutoItemPickup.Log.LogError((object)$"Error while distributing Command essence:\n{arg}"); } orig.Invoke(self); } private Vector3 GetTeleporterCommandTargetPosition() { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: 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_0048: 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_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) Vector3 position = ((Component)TeleporterInteraction.instance).transform.position; float num = Random.Range(0f, MathF.PI * 2f); float num2 = Random.Range(4, 15); return position + Mathf.Sin(num) * num2 * Vector3.forward + Mathf.Cos(num) * num2 * Vector3.right + Vector3.up * 10f; } private void TeleportToTeleporter(NetworkBehaviour obj) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) TeleportHelper.TeleportGameObject(((Component)obj).gameObject, GetTeleporterCommandTargetPosition()); } private void OnTeleporterCharged(TeleporterInteraction obj) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_007c: 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_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) if (!NetworkServer.active || !base.ModConfig.teleportCommandOnTeleport.Value || !Object.op_Implicit((Object)(object)TeleporterInteraction.instance)) { return; } try { List<PickupPickerController> instancesList = InstanceTracker.GetInstancesList<PickupPickerController>(); PickupPickerController[] array = (PickupPickerController[])(object)new PickupPickerController[instancesList.Count]; instancesList.CopyTo(array); Vector3 position = ((Component)TeleporterInteraction.instance).transform.position; PickupPickerController[] array2 = array; foreach (PickupPickerController val in array2) { if (!Object.op_Implicit((Object)(object)val)) { continue; } PickupIndexNetworker component = ((Component)val).GetComponent<PickupIndexNetworker>(); if (Object.op_Implicit((Object)(object)component)) { Vector3 val2 = ((Component)val).transform.position - position; if (((Vector3)(ref val2)).sqrMagnitude > 100f && base.ModConfig.ShouldDistributeCommand(component.pickupIndex, Cause.Teleport)) { TeleportToTeleporter((NetworkBehaviour)(object)val); } } } } catch (Exception arg) { AutoItemPickup.Log.LogError((object)$"Error while moving Command essences to the teleporter:\n{arg}"); } } } public class CommandQueueHandler : AbstractHookHandler { private Func<IEnumerable<(ItemTier, PickupIndex)>> peekAllUnreserved; private float nextScan; private BaseUnityPlugin queuePluginInstance; private PickupPickerController pendingInteraction; private float pendingUntil; private Func<PickupPickerController, ItemTier, PickupIndex, NetworkUIPromptController, LocalUser, CameraRigController, IEnumerator> submitQueuedChoice; private bool displayHookRegistered; private float nextErrorLog; public override void RegisterHooks() { if (!Chainloader.PluginInfos.TryGetValue("com.kuberoot.commandqueue", out var value)) { return; } MethodInfo methodInfo = ((object)value.Instance).GetType().Assembly.GetType("CommandQueue.QueueManager")?.GetMethod("PeekAllUnreserved", BindingFlags.Static | BindingFlags.Public, null, Type.EmptyTypes, null); if (methodInfo == null || methodInfo.ReturnType != typeof(IEnumerable<(ItemTier, PickupIndex)>)) { AutoItemPickup.Log.LogWarning((object)"CommandQueue does not expose PeekAllUnreserved; automatic Command interaction is disabled."); return; } MethodInfo method = ((object)value.Instance).GetType().GetMethod("SubmitQueuedChoiceNextFrame", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[6] { typeof(PickupPickerController), typeof(ItemTier), typeof(PickupIndex), typeof(NetworkUIPromptController), typeof(LocalUser), typeof(CameraRigController) }, null); if (method == null || method.ReturnType != typeof(IEnumerator)) { AutoItemPickup.Log.LogWarning((object)"CommandQueue does not expose the supported queued-choice coroutine; automatic Command interaction is disabled."); return; } submitQueuedChoice = (Func<PickupPickerController, ItemTier, PickupIndex, NetworkUIPromptController, LocalUser, CameraRigController, IEnumerator>)Delegate.CreateDelegate(typeof(Func<PickupPickerController, ItemTier, PickupIndex, NetworkUIPromptController, LocalUser, CameraRigController, IEnumerator>), method); peekAllUnreserved = (Func<IEnumerable<(ItemTier, PickupIndex)>>)Delegate.CreateDelegate(typeof(Func<IEnumerable<(ItemTier, PickupIndex)>>), methodInfo); queuePluginInstance = value.Instance; Run.onRunStartGlobal += OnRunStart; if (Object.op_Implicit((Object)(object)Run.instance)) { OnRunStart(Run.instance); } RoR2Application.onUpdate += Update; AutoItemPickup.Log.LogInfo((object)"CommandQueue integration ready: nearby queued Command essences can be opened automatically for the local player."); } public override void UnregisterHooks() { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown RoR2Application.onUpdate -= Update; Run.onRunStartGlobal -= OnRunStart; if (displayHookRegistered) { PickupPickerController.OnDisplayBegin -= new hook_OnDisplayBegin(OnDisplayBegin); } displayHookRegistered = false; peekAllUnreserved = null; submitQueuedChoice = null; queuePluginInstance = null; pendingInteraction = null; } private void OnRunStart(Run run) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown if (displayHookRegistered) { PickupPickerController.OnDisplayBegin -= new hook_OnDisplayBegin(OnDisplayBegin); } PickupPickerController.OnDisplayBegin += new hook_OnDisplayBegin(OnDisplayBegin); displayHookRegistered = true; pendingInteraction = null; nextScan = 0f; } private void OnDisplayBegin(orig_OnDisplayBegin orig, PickupPickerController self, NetworkUIPromptController prompt, LocalUser user, CameraRigController camera) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_007c: 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_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: 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_00d9: 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) if ((Object)(object)self == (Object)(object)pendingInteraction && base.ModConfig.autoOpenQueuedCommand.Value && Object.op_Implicit((Object)(object)queuePluginInstance) && ((Behaviour)queuePluginInstance).isActiveAndEnabled && user == LocalUserManager.GetFirstLocalUser()) { pendingInteraction = null; foreach (var item3 in peekAllUnreserved()) { ItemTier item = item3.Item1; PickupIndex item2 = item3.Item2; Option[] options = self.options; for (int i = 0; i < options.Length; i++) { Option val = options[i]; if (val.available && val.pickup.pickupIndex == item2 && !((UniquePickup)(ref val.pickup)).isTempItem && !val.pickup.isRental) { ((MonoBehaviour)self).StartCoroutine(submitQueuedChoice(self, item, item2, prompt, user, camera)); return; } } } } orig.Invoke(self, prompt, user, camera); } private void Update() { //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Unknown result type (might be due to invalid IL or missing references) //IL_0266: Invalid comparison between Unknown and I4 //IL_02a0: Unknown result type (might be due to invalid IL or missing references) //IL_02a5: Unknown result type (might be due to invalid IL or missing references) //IL_02a7: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Unknown result type (might be due to invalid IL or missing references) //IL_02db: Unknown result type (might be due to invalid IL or missing references) //IL_02e0: Unknown result type (might be due to invalid IL or missing references) //IL_02e2: Unknown result type (might be due to invalid IL or missing references) //IL_02ed: Unknown result type (might be due to invalid IL or missing references) //IL_02ef: Unknown result type (might be due to invalid IL or missing references) //IL_02f4: Unknown result type (might be due to invalid IL or missing references) //IL_030e: Unknown result type (might be due to invalid IL or missing references) //IL_0310: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)base.Plugin) || !((Behaviour)base.Plugin).isActiveAndEnabled || !base.ModConfig.autoOpenQueuedCommand.Value || !Object.op_Implicit((Object)(object)Run.instance) || Time.time < nextScan) { return; } nextScan = Time.time + 0.2f; try { if (!Object.op_Implicit((Object)(object)queuePluginInstance) || !((Behaviour)queuePluginInstance).isActiveAndEnabled || (Object.op_Implicit((Object)(object)pendingInteraction) && Time.time < pendingUntil)) { return; } LocalUser firstLocalUser = LocalUserManager.GetFirstLocalUser(); CharacterBody val = ((firstLocalUser != null) ? firstLocalUser.cachedBody : null); CharacterMaster val2 = ((firstLocalUser != null) ? firstLocalUser.cachedMaster : null); if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)val.healthComponent) || !val.healthComponent.alive) { return; } Interactor component = ((Component)val).GetComponent<Interactor>(); if (!Object.op_Implicit((Object)(object)component)) { return; } PickupPickerController[] array = InstanceTracker.GetInstancesList<PickupPickerController>().ToArray(); foreach (NetworkUIPromptController instances in InstanceTracker.GetInstancesList<NetworkUIPromptController>()) { if (Object.op_Implicit((Object)(object)instances) && (Object)(object)instances.currentParticipantMaster == (Object)(object)val2) { return; } } GameObject commandCubePrefab = CommandArtifactManager.commandCubePrefab; PickupPickerController val3 = (Object.op_Implicit((Object)(object)commandCubePrefab) ? commandCubePrefab.GetComponent<PickupPickerController>() : null); if (!Object.op_Implicit((Object)(object)val3) || !Object.op_Implicit((Object)(object)val3.panelPrefab)) { return; } HashSet<PickupIndex> hashSet = new HashSet<PickupIndex>(); foreach (var item2 in peekAllUnreserved()) { PickupIndex item = item2.Item2; if (item != PickupIndex.none) { hashSet.Add(item); } } if (hashSet.Count == 0) { return; } PickupPickerController val4 = null; float num = float.PositiveInfinity; Vector3 val5 = (Object.op_Implicit((Object)(object)val.inputBank) ? val.inputBank.aimOrigin : val.corePosition); PickupPickerController[] array2 = array; foreach (PickupPickerController val6 in array2) { if (!Object.op_Implicit((Object)(object)val6) || !((Behaviour)val6).isActiveAndEnabled || (Object)(object)val6.panelPrefab != (Object)(object)val3.panelPrefab || (int)val6.GetInteractability(component) != 2) { continue; } float num2 = Mathf.Min(base.ModConfig.queuedCommandRadius.Value, Mathf.Max(0f, val6.cutoffDistance - 0.5f)); Vector3 val7 = ((Component)val6).transform.position - val5; float sqrMagnitude = ((Vector3)(ref val7)).sqrMagnitude; if (sqrMagnitude > num2 * num2 || sqrMagnitude >= num) { continue; } bool flag = false; Option[] options = val6.options; for (int j = 0; j < options.Length; j++) { Option val8 = options[j]; if (val8.available && hashSet.Contains(val8.pickup.pickupIndex) && !((UniquePickup)(ref val8.pickup)).isTempItem && !val8.pickup.isRental) { flag = true; break; } } if (flag) { val4 = val6; num = sqrMagnitude; } } if (Object.op_Implicit((Object)(object)val4)) { pendingInteraction = val4; pendingUntil = Time.time + 1f; component.AttemptInteraction(((Component)val4).gameObject); } } catch (Exception arg) { nextScan = Time.time + 2f; if (Time.time >= nextErrorLog) { nextErrorLog = Time.time + 10f; AutoItemPickup.Log.LogError((object)$"Automatic CommandQueue interaction failed; retrying after a short delay.\n{arg}"); } } } } public class CommandTargetHandler : AbstractHookHandler { private static readonly FieldInfo Field_PickupPickerController_networkUIPromptController = typeof(PickupPickerController).GetField("networkUIPromptController", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); public override void RegisterHooks() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown if (Field_PickupPickerController_networkUIPromptController == null) { throw new MissingFieldException("PickupPickerController.networkUIPromptController no longer exists"); } PickupPickerController.CreatePickup_UniquePickup += new Manipulator(IL_PickupPickerController_CreatePickup); } public override void UnregisterHooks() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown PickupPickerController.CreatePickup_UniquePickup -= new Manipulator(IL_PickupPickerController_CreatePickup); } private void IL_PickupPickerController_CreatePickup(ILContext il) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_0046: 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) ILCursor val = new ILCursor(il); if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1] { (Instruction i) => ILPatternMatchingExt.MatchCallOrCallvirt<GenericPickupController>(i, "CreatePickup") })) { LogPatchFailed(il, "the call to GenericPickupController.CreatePickup"); return; } val.Emit(OpCodes.Dup); val.Emit(OpCodes.Ldarg_0); val.EmitDelegate<Action<GenericPickupController, PickupPickerController>>((Action<GenericPickupController, PickupPickerController>)delegate(GenericPickupController pickup, PickupPickerController self) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)pickup) && Object.op_Implicit((Object)(object)self)) { PickupDef pickupDef = PickupCatalog.GetPickupDef(pickup.pickupIndex); if (pickupDef != null && !((Object)(object)ItemCatalog.GetItemDef(pickupDef.itemIndex) == (Object)null)) { object? value = Field_PickupPickerController_networkUIPromptController.GetValue(self); NetworkUIPromptController val2 = (NetworkUIPromptController)((value is NetworkUIPromptController) ? value : null); CharacterMaster val3 = (Object.op_Implicit((Object)(object)val2) ? val2.currentParticipantMaster : null); if (Object.op_Implicit((Object)(object)val3)) { ((Component)pickup).gameObject.AddComponent<OverrideDistributorBehaviour>().Distributor = new FixedTargetDistributor(base.Plugin, val3); } } } }); } } public class CreatePickupDropletHandler : AbstractHookHandler { public ItemDistributor DistributorOverride; public override void RegisterHooks() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown PickupDropletController.CreatePickupDroplet_CreatePickupInfo_Vector3_Vector3 += new Manipulator(IL_PickupDropletController_CreatePickupDroplet); } public override void UnregisterHooks() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown PickupDropletController.CreatePickupDroplet_CreatePickupInfo_Vector3_Vector3 -= new Manipulator(IL_PickupDropletController_CreatePickupDroplet); } private void IL_PickupDropletController_CreatePickupDroplet(ILContext il) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_0046: 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 i) => ILPatternMatchingExt.MatchCall<Object>(i, "Instantiate") })) { LogPatchFailed(il, "the call to UnityEngine.Object.Instantiate"); return; } val.Emit(OpCodes.Dup); val.EmitDelegate<Action<GameObject>>((Action<GameObject>)delegate(GameObject obj) { if (DistributorOverride != null && Object.op_Implicit((Object)(object)obj)) { obj.AddComponent<OverrideDistributorBehaviour>().Distributor = DistributorOverride; } }); } } public class ItemHandler : AbstractHookHandler { public override void RegisterHooks() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown SceneExitController.Begin += new hook_Begin(On_SceneExitController_Begin); GenericPickupController.Start += new hook_Start(On_GenericPickupController_Start); } public override void UnregisterHooks() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown SceneExitController.Begin -= new hook_Begin(On_SceneExitController_Begin); GenericPickupController.Start -= new hook_Start(On_GenericPickupController_Start); } private void On_GenericPickupController_Start(orig_Start orig, GenericPickupController self) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) try { if (NetworkServer.active && base.ModConfig.distributeOnDrop.Value && Object.op_Implicit((Object)(object)self) && base.ModConfig.ShouldDistribute(self.pickupIndex, Cause.Drop)) { base.Plugin.DistributeItem(self, Cause.Drop); } } catch (Exception arg) { AutoItemPickup.Log.LogError((object)$"Error while distributing dropped item:\n{arg}"); } orig.Invoke(self); } private void On_SceneExitController_Begin(orig_Begin orig, SceneExitController self) { try { if (NetworkServer.active && base.ModConfig.distributeOnTeleport.Value) { List<GenericPickupController> instancesList = InstanceTracker.GetInstancesList<GenericPickupController>(); GenericPickupController[] array = (GenericPickupController[])(object)new GenericPickupController[instancesList.Count]; instancesList.CopyTo(array); base.Plugin.DistributeItems(array.Where((GenericPickupController pickup) => Object.op_Implicit((Object)(object)pickup) && base.ModConfig.ShouldDistribute(pickup.pickupIndex, Cause.Teleport)), Cause.Teleport); } } catch (Exception arg) { AutoItemPickup.Log.LogError((object)$"Error while distributing items on teleport:\n{arg}"); } orig.Invoke(self); } } public class PrinterTargetHandler : AbstractHookHandler { public override void RegisterHooks() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown ShopTerminalBehavior.DropPickup += new hook_DropPickup(On_ShopTerminalBehavior_DropPickup); } public override void UnregisterHooks() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown ShopTerminalBehavior.DropPickup -= new hook_DropPickup(On_ShopTerminalBehavior_DropPickup); } private void On_ShopTerminalBehavior_DropPickup(orig_DropPickup orig, ShopTerminalBehavior self) { //IL_0031: 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) //IL_0046: Invalid comparison between Unknown and I4 CreatePickupDropletHandler handler = hookManager.GetHandler<CreatePickupDropletHandler>(); try { if (base.ModConfig.printerOverrideTarget.Value) { PurchaseInteraction component = ((Component)self).GetComponent<PurchaseInteraction>(); CostTypeDef val = (Object.op_Implicit((Object)(object)component) ? CostTypeCatalog.GetCostTypeDef(component.costType) : null); if (val != null && (int)val.itemTier != 5) { Interactor lastActivator = component.lastActivator; CharacterBody val2 = (Object.op_Implicit((Object)(object)lastActivator) ? ((Component)lastActivator).GetComponent<CharacterBody>() : null); CharacterMaster val3 = (Object.op_Implicit((Object)(object)val2) ? val2.master : null); if (Object.op_Implicit((Object)(object)val3)) { handler.DistributorOverride = new FixedTargetDistributor(base.Plugin, val3); } } } orig.Invoke(self); } finally { handler.DistributorOverride = null; } } } public class ScrapperTargetHandler : AbstractHookHandler { internal static FieldInfo Field_ScrapperBaseState_scrapperController = typeof(ScrapperBaseState).GetField("scrapperController", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); internal static FieldInfo Field_ScrapperController_interactor = typeof(ScrapperController).GetField("interactor", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); public override void RegisterHooks() { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown if (Field_ScrapperBaseState_scrapperController == null || Field_ScrapperController_interactor == null) { throw new MissingFieldException("ScrapperBaseState.scrapperController or ScrapperController.interactor no longer exists"); } ScrappingToIdle.OnEnter += new Manipulator(IL_ScrappingToIdle_OnEnter); } public override void UnregisterHooks() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown ScrappingToIdle.OnEnter -= new Manipulator(IL_ScrappingToIdle_OnEnter); } private void IL_ScrappingToIdle_OnEnter(ILContext il) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_0046: 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_0063: Unknown result type (might be due to invalid IL or missing references) ILCursor val = new ILCursor(il); if (!val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1] { (Instruction i) => ILPatternMatchingExt.MatchCall<PickupDropletController>(i, "CreatePickupDroplet") })) { LogPatchFailed(il, "the call to PickupDropletController.CreatePickupDroplet"); return; } val.Emit(OpCodes.Ldarg_0); val.Emit(OpCodes.Ldfld, Field_ScrapperBaseState_scrapperController); val.Emit(OpCodes.Ldfld, Field_ScrapperController_interactor); val.EmitDelegate<Action<Interactor>>((Action<Interactor>)delegate(Interactor interactor) { if (base.ModConfig.scrapperOverrideTarget.Value && Object.op_Implicit((Object)(object)interactor)) { CharacterBody component = ((Component)interactor).GetComponent<CharacterBody>(); CharacterMaster val2 = (Object.op_Implicit((Object)(object)component) ? component.master : null); if (Object.op_Implicit((Object)(object)val2)) { hookManager.GetHandler<CreatePickupDropletHandler>().DistributorOverride = new FixedTargetDistributor(base.Plugin, val2); } } }); int index = val.Index; val.Index = index + 1; val.EmitDelegate<Action>((Action)delegate { hookManager.GetHandler<CreatePickupDropletHandler>().DistributorOverride = null; }); } } }