Reading Tibia map from memory.
|
Purpose of this article is to describe in deep, low-level details how to read contents of the Tibia map in memory.
After reading the article you will know and understand all the algorithms that are needed to implement the map reading feature
in your own bot.
Part 1. Locating the map in memory. The map is stored in memory in a dynamic way - this means that its location might vary every time you start your Tibia client (although in practice it varies from one windows type to the other only). In such case to know the exact location you have to look into the value of some pointer in the memory - in Tibia 7.6 its address is 0x4AF478. After rereferencing this pointer, you obtain a pointer to the map structure itself.The map is stored as an array of 2016 tiles. Each tile consumes 168 bytes, which gives space for 168/4=42 integers. Those 42 integers are:
struct objectData { int objectId; int data1; int data2; } struct tileDef { int stackedObjectCount; struct objectData[13]; int padding1; int padding2; }; struct tileDef map[2016]; // with tileDef address 0x4AF478 Part 2. Decrypting the 'extra data' tile parts The 'extra data' of tile depends on the object type. I know about two usages of it:
Part 3. Locating yourself on the map Having the current knowledge, locating yourself on the map in the memory is pretty simple: it is just a tile with creature id 99 (0x63) and data1 (Tibia ID) equal to your own Tibia ID. Position (between 0 and 2015) of the 'yourself tile' is esential for further computations.Part 4. Map structure in memory As I mentioned in the very beginning of this article, a map in memory contains description of exactly 2016 tiles. It appears that this array of tiles is not flat, but is rather a tri-dimension array of size 8*14*18 (see that 8*14*18 equals to 2016)! In the memory it is written likestruct tileDef map[8][14][18]; So having any 'tile position' it is possible to compute an exact location of the tile in the tri-dimension array using the following equations:z = cellNr/(14*18); y=(cellNr-z*14*18)/18; x=(cellNr-z*14*18-y*18); Now assuming that we know 'yourself tile' position (see part 3) we can compute an exact location of 'yourself tile' in the memory array. For example if 'yourself tile' is 1066, then we can compute that this equals to position [4][3][7]. Unfortunetally doing a few experiments with a running Tibia client lead to two surprising conclusions:
Part 5. Solving the map puzzle Further experiments with walking east/west closed us to the final solution of the map puzzle:
Part 6. Map reading in Tibia Auto The map reading/writting technique is used in Tibia Auto to solve a few problems:
Back to the homesite |