Deprecated: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence in /home/iano/public_html/tpforums-vb5/forum/includes/class_core.php on line 5842

PHP Warning: Use of undefined constant MYSQL_NUM - assumed 'MYSQL_NUM' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_BOTH - assumed 'MYSQL_BOTH' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 588

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 612

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6
7.6 Map parsing
Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: 7.6 Map parsing

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    28

    7.6 Map parsing

    I dont know why my program crashes. Here it is (the code):
    Code:
    #include "map.h"
    int mappointer=0x4AF478;
    struct objectData{
    	int objectId;
    	int data1;
    	int data2;
    };
    struct tileDef {
    	int stack;
    	objectData Data[13];
    };
    struct tileDef map[2016];
    void download_map(){
    	for(int i=0;i<2016;i++){
    		map[i].stack=Read(0x4AF478+i*168,4);
    		for(int e=0;e<=map[i].stack;e++){
    			map[i].Data[e].objectId=Read(0x4AF478+i*168+e*12+4,2);
    			map[i].Data[e].data1=Read(mappointer+i*168+12*e+8,2);
    			map[i].Data[e].data2=Read(mappointer+i*168+12*e+12,2);
    		}
    	}
    }
    void search_myself(){
    	int me=Read(0x4A1244,4);
    	for(int i=0;i<=2016;i++){
    		for(int e=0;e<=map[i].stack;e++){
    			if(map[i].Data[e].objectId==99){
    				if(map[i].Data[e].data1==me){
    				//Found. Gimme X, Y, Z.
    				MessageBox(NULL,"Found!","You Found Me!",MB_OK);
    				}
    			}
    		}
    	}
    
    }
    DWORD WINAPI map_thread(LPVOID args){
    	int id=0;
    	for(;;)
    	{
    		download_map();
    		search_myself();
    		Sleep(100);
    	}	
    	return 0;
    }
    Map.h:
    Code:
    #pragma once
    #include <Windows.h>
    #include <string>
    
    using namespace std;
    DWORD WINAPI map_thread(LPVOID args);
    typedef int (WINAPI *SENDPACKET)(DWORD, char*);
    extern SENDPACKET SendPacket;
    extern HINSTANCE hLib;
    extern HWND client;
    extern DWORD pid;
    extern HANDLE process;
    and function Read:
    Code:
    int Read(int address, int byte)
    {
    	int value;
    	if(ReadProcessMemory(process, (LPVOID)address, &value, byte, NULL))
    		return value;
    	return -1;
    }
    What is happening? It just crashes. I dont know why

  2. #2
    Senior Member
    Join Date
    Mar 2007
    Posts
    367

    RE: 7.6 Map parsing

    1st:
    Shouldn't you first read the mappointer and then apply offsets ?

    2nd:
    Code:
    struct tileDef map[2016];
    Should this be a struct really? Shouldn't this be an array simply?

    3rd:
    In the download_map:
    Code:
    for(int e=0;e<=map[i].stack;e++){
    Smells like "out of range": should either be
    Code:
    int e=0;e<map[i].stack
    or
    Code:
    int e=0;e<=map[i].stack-1;
    4th
    Make up your mind :P
    First you declare Data as array of 13 items,
    Code:
    objectData Data[13];
    and then you offset by 12 items (e*12)
    Code:
    map[i].Data[e].objectId=Read(0x4AF478+i*168+e*12+4,2);
    Besides you mix using memory address directly ("Read(0x4AF478...") with using it through a variable ("Read(mappointer...").


    HTH

  3. #3
    Junior Member
    Join Date
    Feb 2010
    Posts
    28

    RE: 7.6 Map parsing

    After doing all you said:
    Code:
    int mappointer=0x4AF478;
    struct objectData{
        int objectId;
        int data1;
        int data2;
    };
    struct tileDef {
        int stack;
        objectData Data[13];
    };
    tileDef map[2016];
    void download_map(){
        for(int i=0;i<2016;i++){
            map[i].stack=Read(mappointer+i*172,4);
            for(int e=0;e<map[i].stack;e++){
                map[i].Data[e].objectId=Read(mappointer+i*172+e*13+4,4);
                map[i].Data[e].data1=Read(mappointer+i*172+13*e+8,4);
                map[i].Data[e].data2=Read(mappointer+i*172+13*e+12,4);
            }
        }
    }
    void search_myself(){
        int me=Read(0x4A1244,4);
        for(int i=0;i<2016;i++){
            for(int e=0;e<map[i].stack;e++){
                if(map[i].Data[e].objectId==99){
                    MessageBox(NULL,"Found!","You Found Me!",MB_OK);
                }
            }
        }
    
    }
    DWORD WINAPI map_thread(LPVOID args){
        int id=0;
        for(;;)
        {
            download_map();
            search_myself();
            Sleep(100);
        }    
        return 0;
    }
    It doesnt crashes, but... Nobody said It works
    MessageBox hasn't appeared.
    Anyway, thanks a lot.

  4. #4
    Super Moderator
    Join Date
    May 2007
    Posts
    1,191

    RE: 7.6 Map parsing

    Your tile step is wrong. In 7.6, it's 168, not 172.

  5. #5

    RE: 7.6 Map parsing

    http://tibiaauto.net/articles/ta_art_mapread.html

    struct tileDef {
    int stack;
    objectData Data[13];
    int padding1;
    int padding2;
    };

    As blaster said, tile step is 168. You missed padding1 and padding2 in tileDef too, and map[i].Data[e].objectId == 99 doesn't mean you found yourself (it only means you found an creature), map[i].Data[e].data1 must be equal to your player id.

    You should read pointer value first, like this:
    map[i].stack=Read(Read(mappointer)+i*168,4);

    You can also read whole structure at once:
    ReadProcessMemory(process, (LPVOID)Read(mappointer), map, sizeof(tileDef)*2016, NULL)

  6. #6
    Junior Member
    Join Date
    Feb 2010
    Posts
    28

    RE: 7.6 Map parsing

    I did it!

    Code:
    int mappointer=0x4AF478;
    struct objectData{
        int objectId;
        int data1;
        int data2;
    };
    struct tileDef {
        int stack;
        objectData Data[12];
    	int padding1;
    	int padding2;
    };
    tileDef map[2016];
    void download_map(){
            ReadProcessMemory(process, (LPVOID)Read(mappointer,4), map, sizeof(tileDef)*2016, NULL);
    }
    void search_myself(){
        int me=Read(0x4A1244,4);
        for(int i=0;i<2016;i++){
            for(int e=0;e<map[i].stack;e++){
                if(map[i].Data[e].objectId==99 && map[i].Data[e].data1==me){
                    MessageBox(NULL,"You Found Me!","Found!",MB_OK);
                }
            }
        }
    
    }
    DWORD WINAPI map_thread(LPVOID args){
        int id=0;
            download_map();
            search_myself();
            Sleep(100);
        return 0;
    }
    It founds me



    But:
    Code:
    void download_map(){
            ReadProcessMemory(process, (LPVOID)Read(mappointer,4), map, sizeof(tileDef)*2016, NULL);
    }
    void search_for(int id){
    	download_map();
    	// By This I know "int id" is wright
        int me=Read(0x4A1244,4);
    	char buff[100];
    	itoa(id,buff,10);
    	char buf[100];
    	itoa(me,buf,10);
    	MessageBox(0,buff,buf,MB_OK);
    	//
        for(int i=0;i<2016;i++){
            for(int e=0;e<map[i].stack;e++){
                if(map[i].Data[e].objectId==99){
    				MessageBox(NULL,"Creature","Found!",MB_OK);
    				if(map[i].Data[e].data1==id){
                    MessageBox(NULL,"You Found Your Target!","Found!",MB_OK);
    				goingto_z = i/(14*18);
    				goingto_y= (i-goingto_z*14*18)/18;
    				goingto_x=(i-goingto_z*14*18-goingto_y*18);
    				go(goingto_x-1,goingto_y,goingto_z);
    				}
                }
            }
        }
    }
    Doesnt Works (No MessageBox appears). Why?

  7. #7

    RE: 7.6 Map parsing

    It's strange that first code actually found you, because in your tileDef struct you've got objectData Data[12] instead of objectData Data[13], so struct size isn't 168 bytes and it's reading whole map incorrectly. Second code looks good if you're looking for creature and it's id (which you pass as parameter) is correct.

  8. #8
    Junior Member
    Join Date
    Feb 2010
    Posts
    28

    RE: 7.6 Map parsing

    Well... I have It wright now, but It tells me that i=216 (then z=0).

  9. #9
    Senior Member
    Join Date
    Mar 2007
    Posts
    367

    RE: 7.6 Map parsing

    That's possible - happens when you're on the ground level on the surface (playerZ = 8).

    i=216 translates to x[0] y[12] z[0].


    I'm missing one thing in your code though...
    Where's stackPos ?
    It's there in 7.7 structure - dunno if it was in 7.6...

    This is how single map tile looks in memory in 7.7:
    [code=delphi]type // CAUTION!!! Order of the variables is CRUCIAL!!!
    TMemMapTile = record // TMemoryMap single tile
    cntItems: cardinal; // things count on map tile
    stack: array[0..9] of TStackThing; // stack of 10 visible things
    stackPos: array[0..9] of cardinal; // stack pos of the things
    unknown2: array[0..1] of cardinal; // unknown (filler?)
    end;[/code]

    I look through the stack but only through the things that exist - there are garbage leftovers of what you've seen that may lead to miscalculation of selfPos (happened to me today).

  10. #10
    Junior Member
    Join Date
    Feb 2010
    Posts
    28

    RE: 7.6 Map parsing

    Well: I took it from here: http://tibiaauto.net/articles/ta_art_mapread.html
    Code:
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •