Advertisement
Guest User

containers.cpp

a guest
Apr 26th, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.28 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "addresses.h"
  3. #include "containers.h"
  4.  
  5. using namespace tibia::objects;
  6.  
  7.  
  8.  
  9. Containers::Containers(void) {
  10. }
  11.  
  12. Containers::~Containers(void) {
  13. }
  14.  
  15.  
  16. Backpacks Containers:: getBackpacks() {
  17.     Backpacks backpacks;
  18.  
  19.     tibia::structures::ContainersEntry* containersInfo = getContainerEntry( getContainerPtr() );
  20.     if (containersInfo->count > 0) {
  21.         tibia::structures::ContainerNode* node = getContainerNode(containersInfo->address);
  22.         node = getContainerNode(node->parent);
  23.  
  24.         getNextContainer(node, containersInfo->address, &backpacks);
  25.     }
  26.  
  27.     return backpacks;
  28. }
  29.  
  30.  
  31. void Containers::getNextContainer(tibia::structures::ContainerNode* containernode, UINT32 address, Backpacks* backpacks) {
  32.     if (containernode->left != address) {
  33.         tibia::structures::ContainerNode* leftNode = getContainerNode(containernode->left);
  34.         getNextContainer(leftNode, address, backpacks);
  35.     }
  36.  
  37.     ptrContainer container (new Container(getContainer(containernode->address)));
  38.     backpacks->push_back(container);
  39.  
  40.     if (containernode->right != address) {
  41.         tibia::structures::ContainerNode* rightNode =getContainerNode(containernode->right);
  42.         getNextContainer(rightNode, address, backpacks);
  43.     }
  44. }
  45.  
  46.  
  47. UINT32 Containers::getContainerPtr() {
  48.     return *(UINT32 *)(tibia::addresses::container::start + tibia::addresses::baseAddress);
  49. }
  50.  
  51.  
  52. tibia::structures::Container* Containers::getContainer(UINT32 address) {
  53.     return (tibia::structures::Container*)(UINT32*)address;
  54. }
  55.  
  56. tibia::structures::ContainersEntry* Containers::getContainerEntry(UINT32 address) {
  57.     return (tibia::structures::ContainersEntry*)(UINT32*)address;
  58. }
  59.  
  60. tibia::structures::ContainerNode* Containers::getContainerNode(UINT32 address) {
  61.     return (tibia::structures::ContainerNode*)(UINT32*)address;
  62. }
  63.  
  64.  
  65. void Containers::debug() {
  66.     Backpacks backpacks = getBackpacks();
  67.     printf("\t ::CHECKING CONTAINERS: \n");
  68.     printf("\t Found opened containers: %d \n", backpacks.size());
  69.  
  70.     BOOST_FOREACH(ptrContainer container, backpacks) {
  71.         printf("\t\t name: %16s \t items: (%d / %d) \n", container->getName(), container->getItemsCount(), container->getSlotsCount());
  72.  
  73.         auto items = container->getItems();
  74.         BOOST_FOREACH(auto item, items)
  75.             printf("\t\t\t itemid: %d item count: %d \n", item->getId(), item->getCount());
  76.  
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement