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
[tutorial] One-Shot memory reading: BattleList example
Page 1 of 4 123 ... LastLast
Results 1 to 10 of 32

Thread: [tutorial] One-Shot memory reading: BattleList example

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

    [tutorial] One-Shot memory reading: BattleList example

    As a word of introduction I'd like to thank the person here at TPForums (I can't remember thy name unfortunately ) that made me realize this is possible with Delphi.

    The battlelist (and other static structures) can be read into your program in one memory read given that you prepare for it accordingly.

    This tutorial is to show how it's done (one of two ways I know).
    Our example prog will read battlelist in one memory read.

    The example is based on 7.7 client as I'm coding things for RealOTS currently.
    This can be easily adapted to any other client with a small bit of work though.


    Let's get started.


    First off we have to declare our structure that will hold the single battlelist entry.
    I did it this way:
    [code=delphi]type
    TBattleListEntry = record
    ID: cardinal;
    name: array[0..31] of byte;
    posX, posY, posZ: cardinal;
    offsetX, offsetY: cardinal;
    unknown1: array[0..4] of cardinal;
    isWalking, direction: cardinal;
    unknown2: array[0..2] of cardinal;
    outfit: array[0..4] of cardinal;
    //outfit[0] // Looktype
    //outfit[1] // Head
    //outfit[2] // Body
    //outfit[3] // Legs
    //outfit[4] // Feet
    lightRange, lightColor: cardinal;
    blackSquare: array[0..1] of cardinal;
    HP, Speed, Visible: cardinal;
    Skull, Shield, unknown3: cardinal;
    end;[/code]BEWARE! Types and order of variables in the structure is CRUCIAL! It must preserve the data format in the client memory!

    After that we also have to declare an array that will hold all of the battlelist entries:
    [code=delphi]type
    TBattleList = record
    list: array[0..149] of TBattleListEntry;
    end;[/code]
    Then we can declare some constant values, like memory addresses and offsets we use:
    [code=delphi]const
    stBL = $0056C8B0;[/code]

    Now we are ready for memory reading.

    First thing of'course is to open process for memory reading, which is quite a common thing to do and I'll skip it here.
    It's in the example in attachment though.


    Now... any time we need to get some actuall info from battle list we read it like this:
    [code=delphi]ReadProcessMemory(tProcess, ptr(stBL), @mBL, $5B68, nobr);[/code]Where:
    - stBL is the battle list start address (ID of first creature entry) we declared as a constant;
    - mBL is local variable for whole battle list declared like this:
    [code=delphi]mBL: TBattleList; // your structure to hold BattleList[/code]- $5B68 is the size of battle list (in HEX) - basicly it's one creature entry size * number of entries ($9C * 150 in this case);
    - nobr is an integer for Number Of Bytes Read.
    This line reads whole battlelist contents into our structure directly. (Thanks Stiju for pointing this out ^^)


    Voila!
    You now have a copy of the battlelist in your structure, with a very comfortable access to it.


    For instance:
    To get the HP bar of first creature in battle list you have to do this:
    [code=delphi]HP := mBL.list[0].HP;[/code]Where:
    - HP is an integer;
    - 0 - first entry in our battlelist structure.


    Example sources in the attachment.

    Have fun & Good luck ^^

    [attachment=993]



    [edit]
    PS.
    To get the creature name from byte array into a string you just do:
    Code:
    name := PChar(@mBL.list[i].name); // copy creature name into string var
    Where name is a variable of type string.

  2. #2
    Senior Member
    Join Date
    May 2009
    Posts
    107

    RE: [tutorial] One-Shot memory reading: BattleList example

    I didn't knew it was possible XD
    And how is the performance ?
    Cool

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

    RE: [tutorial] One-Shot memory reading: BattleList example

    I didn't do performance tests myself but I did see someone (DarkstaR I believe) posting some tests at some other topic (will try my best to find it).
    From the look of it it's amazingly fast

    Ima look for the topic now


    [edit]
    Found it:
    [VB.NET Tutorial] Caching the BattleList

  4. #4

    RE: [tutorial] One-Shot memory reading: BattleList example

    Just like with C/C++ you should probably be able to fill your array of battlelist entires directly in ReadProcessMemory instead of reading it to a buffer and then copying it.
    That way you can skip the CopyMemory and also get a little speed boost.

    Anyway, good job ufo.

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

    RE: [tutorial] One-Shot memory reading: BattleList example

    Am currently working on reading map from memory and I just tested your suggestion and it works ^^ Thanks!
    I'll update the tutorial later on - gotta finish the map reader
    Currently at finding self in mem map...


    [edit]
    Tutorial edited with what Stiju was kind enough to point out.
    Example sources updated as well.
    Thanks again Stiju ! ^^

  6. #6
    Senior Member
    Join Date
    Jan 2012
    Posts
    417

    RE: [tutorial] One-Shot memory reading: BattleList example

    Nice to see all this.

    Some time ago, I read topics about this subject due to DarkstaR and CristoferMartins.

    Nothing against these guys, but in my opinion you explained all things very clear.

    About performance, DarkstaR did an excellent explanation, very clear too and you can find in his thread.

    I need to know if a ppl with 0 rep which +rep someone increase the rep?

    I need to spread out + rep to some guys.

  7. #7

    RE: [tutorial] One-Shot memory reading: BattleList example

    Its works for everything, backpacks, battlelist, map...
    I posted something like this 3 years ago but the explanation of the method was poor. http://tpforums.org/forum/thread-3933.html
    If you are doing dll injection, you can use this with pointers giving you direct access to tibia's structures.

    Ps: Delphi is better than c++ to do bots

  8. #8

    RE: [tutorial] One-Shot memory reading: BattleList example

    Quote Originally Posted by CristoferMartins
    Ps: Delphi is better than c++ to do bots
    Next time, prefix your opinions with "in my opinion".

  9. #9

    RE: [tutorial] One-Shot memory reading: BattleList example

    Quote Originally Posted by zippoxer
    Quote Originally Posted by CristoferMartins
    Ps: Delphi is better than c++ to do bots
    Next time, prefix your opinions with "in my opinion".
    If it was not my opinion, from whom it was supposed to be?

  10. #10
    Senior Member
    Join Date
    Nov 2009
    Posts
    320

    RE: [tutorial] One-Shot memory reading: BattleList example

    The Delphi code is cleaner than c++ for me...
    But c++ have your advantages in many cases :/

Posting Permissions

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