Morse
12-11-2016, 20:36
Here's what I've learned so far: Tibia 11 uses two collections to keep track of open containers. One collection stores information about the containers and its items. The other one stores UI information (related to each container's window). To access these collections, traverse the following paths:
// Tibia 11.02.4171
// Container collection start
{qt5core_dll + 0x004555C8, 0x8, 0x1E4, 0x124, 0x20 };
// Container UI collection start
{qt5core_dll + 0x004555C8, 0x8, 0x114, 0x034 };
Both collections use one byte, the container ID, as keys. Due to alignment, however, keys end up taking 4 bytes in memory. The other 3 should be disregarded (or so I think). Each collection item has also a pointer to a structure, (A) or (D), containing useful data, exactly like in the battle list example (http://www.blackdtools.net/showthread.php?62991-Tibia-11-The-Battle-list/page2). For more information on how to navigate these collections, see Daniel's posts (http://www.blackdtools.net/showthread.php?62980-Code-to-read-Tibia-11-collections-(skills-server-info-etc)).
(A) Each item in the first collection has a pointer to a structure that looks like this:
0x08: pointer to the container item information structure (C). That is, if the container is a backpack, this should point to a structure that contains information about a backpack item.
0x14: pointer to a QString (http://www.blackdtools.net/showthread.php?62992-Tibia-11-Understanding-QStrings-in-memory) containing the container name.
0x18: number of slots in the container. Looks like 4 bytes long, but one byte should be enough.
0x20: number of occupied slots in the container. One byte should be enough.
0x28: pointer to a list (B). May be null if this container is empty. Each element in the list has a pointer to one item information structure (C).
(B) Item list:
0x00: pointer to the 1st item's information structure.
0x08: pointer to the 2nd item's information structure.
0x10: pointer to the 3rd item's information structure.
...
(C) Item information structure:
0x08: pointer to the item's ID. 2 bytes should be enough.
0x38: item count, exactly one byte. When the item isn't stackable, this byte should be disregarded.
(D) Each item in the second collection, the one about container windows, has a pointer to a structure that looks like:
0x04: a pointer to a pointer to... ultimately leads to a structure with data about the container window (E). (See examples below).
0x40: a 4 byte integer indicating the container slot your mouse is currently hovering. If you're not hovering one of this container's slots, this number is -1 (that is, 0xFFFFFFFF).
(E) Container window info structure:
0x08C: height of the window's interior. Doesn't include the window's borders measurements.
0x1F4: 1 byte long. 0 means the window is minimized, 1 means it isn't.
0x23C: duplicated minimized flag?
0x284: window's relative position index. (2/4 bytes long?) (Example: Suppose there are two containers open: a backpack and, below it, a bag. The bag's relative position index should be bigger than the backpack's. These number are not necessarily consecutive, and are exchanged when the windows positions are exchanged.)
It is important to note that some of these structures are immutable: The item structure (C), for instance. If you have a stack of coins inside your backpack, and you throw one of them into the sea, your old stack of coins gets invalidated and a new one is allocated. Meaning you must frequently retraverse some paths. Also, when a container is closed, the corresponding window collection item might not be deleted immediately.
Here are some examples of how to navigate this mess. Suppose now that you have just one open backpack. It's first item is a stack of coins and its second item is a rope. You can use the following paths:
// Tibia 11.02.4171
// Backpack item ID:
{qt5core_dll + 0x004555C8, 0x8, 0x1E4, 0x124, 0x20, 0x04, 0x14, 0x08, 0x8, 0x00 };
// Coins item ID:
{qt5core_dll + 0x004555C8, 0x8, 0x1E4, 0x124, 0x20, 0x04, 0x14, 0x28, 0x0, 0x08, 0x0 };
// Ammount of coins:
{qt5core_dll + 0x004555C8, 0x8, 0x1E4, 0x124, 0x20, 0x04, 0x14, 0x28, 0x0, 0x38 };
// Rope item ID:
{qt5core_dll + 0x004555C8, 0x8, 0x1E4, 0x124, 0x20, 0x04, 0x14, 0x28, 0x8, 0x08, 0x0 };
// Backpack hovered slot:
{qt5core_dll + 0x004555C8, 0x8, 0x114, 0x034, 0x00, 0x14, 0x40 };
// Backpack's interior height:
{qt5core_dll + 0x004555C8, 0x8, 0x114, 0x034, 0x00, 0x14, 0x04, 0x38, 0x40, 0x8C };
We're lacking a lot of information about the aforementioned structures. Contributions and corrections of any kind are welcome. Thank you.
// Tibia 11.02.4171
// Container collection start
{qt5core_dll + 0x004555C8, 0x8, 0x1E4, 0x124, 0x20 };
// Container UI collection start
{qt5core_dll + 0x004555C8, 0x8, 0x114, 0x034 };
Both collections use one byte, the container ID, as keys. Due to alignment, however, keys end up taking 4 bytes in memory. The other 3 should be disregarded (or so I think). Each collection item has also a pointer to a structure, (A) or (D), containing useful data, exactly like in the battle list example (http://www.blackdtools.net/showthread.php?62991-Tibia-11-The-Battle-list/page2). For more information on how to navigate these collections, see Daniel's posts (http://www.blackdtools.net/showthread.php?62980-Code-to-read-Tibia-11-collections-(skills-server-info-etc)).
(A) Each item in the first collection has a pointer to a structure that looks like this:
0x08: pointer to the container item information structure (C). That is, if the container is a backpack, this should point to a structure that contains information about a backpack item.
0x14: pointer to a QString (http://www.blackdtools.net/showthread.php?62992-Tibia-11-Understanding-QStrings-in-memory) containing the container name.
0x18: number of slots in the container. Looks like 4 bytes long, but one byte should be enough.
0x20: number of occupied slots in the container. One byte should be enough.
0x28: pointer to a list (B). May be null if this container is empty. Each element in the list has a pointer to one item information structure (C).
(B) Item list:
0x00: pointer to the 1st item's information structure.
0x08: pointer to the 2nd item's information structure.
0x10: pointer to the 3rd item's information structure.
...
(C) Item information structure:
0x08: pointer to the item's ID. 2 bytes should be enough.
0x38: item count, exactly one byte. When the item isn't stackable, this byte should be disregarded.
(D) Each item in the second collection, the one about container windows, has a pointer to a structure that looks like:
0x04: a pointer to a pointer to... ultimately leads to a structure with data about the container window (E). (See examples below).
0x40: a 4 byte integer indicating the container slot your mouse is currently hovering. If you're not hovering one of this container's slots, this number is -1 (that is, 0xFFFFFFFF).
(E) Container window info structure:
0x08C: height of the window's interior. Doesn't include the window's borders measurements.
0x1F4: 1 byte long. 0 means the window is minimized, 1 means it isn't.
0x23C: duplicated minimized flag?
0x284: window's relative position index. (2/4 bytes long?) (Example: Suppose there are two containers open: a backpack and, below it, a bag. The bag's relative position index should be bigger than the backpack's. These number are not necessarily consecutive, and are exchanged when the windows positions are exchanged.)
It is important to note that some of these structures are immutable: The item structure (C), for instance. If you have a stack of coins inside your backpack, and you throw one of them into the sea, your old stack of coins gets invalidated and a new one is allocated. Meaning you must frequently retraverse some paths. Also, when a container is closed, the corresponding window collection item might not be deleted immediately.
Here are some examples of how to navigate this mess. Suppose now that you have just one open backpack. It's first item is a stack of coins and its second item is a rope. You can use the following paths:
// Tibia 11.02.4171
// Backpack item ID:
{qt5core_dll + 0x004555C8, 0x8, 0x1E4, 0x124, 0x20, 0x04, 0x14, 0x08, 0x8, 0x00 };
// Coins item ID:
{qt5core_dll + 0x004555C8, 0x8, 0x1E4, 0x124, 0x20, 0x04, 0x14, 0x28, 0x0, 0x08, 0x0 };
// Ammount of coins:
{qt5core_dll + 0x004555C8, 0x8, 0x1E4, 0x124, 0x20, 0x04, 0x14, 0x28, 0x0, 0x38 };
// Rope item ID:
{qt5core_dll + 0x004555C8, 0x8, 0x1E4, 0x124, 0x20, 0x04, 0x14, 0x28, 0x8, 0x08, 0x0 };
// Backpack hovered slot:
{qt5core_dll + 0x004555C8, 0x8, 0x114, 0x034, 0x00, 0x14, 0x40 };
// Backpack's interior height:
{qt5core_dll + 0x004555C8, 0x8, 0x114, 0x034, 0x00, 0x14, 0x04, 0x38, 0x40, 0x8C };
We're lacking a lot of information about the aforementioned structures. Contributions and corrections of any kind are welcome. Thank you.