I'll tell you what I gather from MSVC std library source code plus the help of a few guys here (Ty DarkStar and Stiju).
Tibia containers are stored in a red black tree (msvc std::map implementation) as mentioned by DarkStar here and Stiju here.
The container address, points to the address of a structure with the following format (Delphi syntax):
Code:
TTreeEntry = record
Proxy, Head: longword; //Head's node address
Count: longint; //Tree's node count
end;
The head points to a tree node, which is another structure with the following format:
Code:
TTreeNode = record
Left, Parent, Right: longword; //Address of Left, Parent and Right nodes.
Color: byte; //Red or black color
IsNil: boolean;
ContainerData: record //Key/Value pair
Key, Address: longword; //Key is the container index, Address is the container address.
end;
end;
The head is not the tree root, instead, head's parent is.
Now, with the root address (Head.Parent) in hands, you'll be able create a method to traverse the whole tree. All nodes uses the same structure as the head does. The leaf node points to the tree head. So, to check whether a leaf has been reached, you can either use the IsNil value, as well as compare the right and left with the head address.