Ejemplo n.º 1
0
        public bool TryGetPlayerItem(int player, string itemName, out InvLoot item)
        {
            CheckPlayerIndex(player);
            UpdateInventory(player);

            return(_playerItems[player].TryGetValue(itemName, out item));
        }
Ejemplo n.º 2
0
        public void UpdateInventory(int player)
        {
            CheckPlayerIndex(player);

            // 100ms cooldown between inventory updates
            if (!_playerItemTimes.TryGetValue(player, out DateTime time) || DateTime.Now > time)
            {
                _playerItemTimes[player] = DateTime.Now.AddMilliseconds(100);
            }
            else
            {
                return;
            }

            // Get player items list, clear
            if (!_playerItems.TryGetValue(player, out Dictionary <string, InvLoot> items))
            {
                items = new Dictionary <string, InvLoot>();
                _playerItems[player] = items;
            }

            items.Clear();

            // PlayerMgr.player[player].playerInv.inventory
            IntPtr inventory = (IntPtr)_players.Read <uint>(Program, 0x8 + sizeof(uint) * player, 0x24, 0x8);

            int len = Program.Read <int>(inventory, 0x4);

            for (int i = 0; i < len; i++)
            {
                // inventory[i]
                IntPtr itemPtr = (IntPtr)Program.Read <uint>(inventory, 0x8 + sizeof(uint) * i);

                if (itemPtr == IntPtr.Zero)
                {
                    continue;
                }

                // Follow ptr to struct
                InvLoot item = new InvLoot(Program, itemPtr);

                if (item.name != null)
                {
                    items[item.name] = item;
                }
            }
        }