Results 1 to 1 of 1
  1. #1
    pepsiplaya's Avatar
    Join Date
    Apr 2013
    Gender
    male
    Posts
    0
    Reputation
    10
    Thanks
    0
    My Mood
    Amazed

    Autoit Using Memory To Create a Bot

    I've recently coded a bot for a 2d game. This script will read the games memory and get the players position, after this it ill simply do actions such as this send a key press for a duration then stop. it'll then read the characters position, if it doesn't fit where it should be the bot will stop and tell me where the error is. But this still doesn't work too well because if an enemy gets in my way or if some fps/ping issues happen it could easily get my character off my one position, causing the entire script to stop. Here's the code for my script:


    Code:

    Code:
    #include <NomadMemory2.au3>
    #include <Array.au3>
    
    HotKeySet("{esc}", "myExit")
    
    $x = WinActivate("~snip~")
    
    Global $walk = 200()
    Global $fish = 10000()
    Global $stall = 50()
    Global $food = 0x00FFF7()
    Global $t2 = 0x00423B()
    Global $mainwindow = "~snip~"
    Global $pid = WinGetProcess($mainwindow)
    Global $iHD = 0
    Global $address = "0x06021F04" ;Change this every time you reload the game
    
    Global $MemArray = _Memoryopen($pid)
    Global $out = _MemoryRead($address, $MemArray)
    ;MsgBox(0,"test",$out)
    _Memoryclose($pid)
    
    If WinExists("~snip~") = 0 Then
        MsgBox(0, "", "Application is not running. Please run it before starting this app.")
        Exit
    EndIf
    
    while(1)
       WalkBack() ;Calls the start of walking back to the fishing spot
       For $fishCount = 1 To 9 ;Calls all the functions for the fishing run, does this 9 times.
          Fish()
          fMove1()
          fMove2()
          fMove3()
          fMove4()
          fMove5()
          fMove6()
          fMove7()
       Next
       For $lastFish = 1 To 1 ;Does the last run, skips the buff/wait time for the fish to respawn
          Fish()
          fMove1()
          fMove2()
          fMove3()
          fMove4()
          fMove5()
          fMove6()
       Next
       Bank()
    WEnd
    
    Func WalkBack()
       If $out = 4113 Then
          Send("{s down}")
          Sleep(550)
          Send("{s up}")
          Sleep($stall)
          Call(wMove1)
    Else
             Send("{s down}")
          Sleep(550)
          Send("{s up}")
          Sleep($stall)
          Call(wMove1)
          EndIf
    EndFunc
    
    Func wMove1()
       $out = _MemoryRead($address, $MemArray)
       If $out = 70417 Then
          Send("{d down}")
          Sleep(3000)
          Send("{d up}")
          Sleep($stall)
          Call(wMove2)
       Else
          MsgBox(0, "Error", "wMove1")
          Exit
       EndIf
    EndFunc
    
    Func wMove2()
       $out = _MemoryRead($address, $MemArray)
       If $out = 201501 Then
          Send("{s down}")
          Sleep(4200)
          Send("{s up}")
          Sleep($stall)
          Call(wMove3)
       Else
          MsgBox(0, "Error", "wMove2")
          Exit
       EndIf
    EndFunc
    
    Func wMove3()
       $out = _MemoryRead($address, $MemArray)
       If $out = 74781 Then
          Send("{a down}")
          Sleep(3900)
          Send("{a up}")
          Sleep($stall)
          Call(wMove4)
       Else
          MsgBox(0, "Error", "wMove3")
          Exit
       EndIf
    EndFunc
    
    Func wMove4()
       $out = _MemoryRead($address, $MemArray)
       If $out = 140301 Then
          Send("{s down}")
          Sleep($walk)
          Send("{s up}")
          Sleep($stall)
       Else
          MsgBox(0, "Error", "wMove4")
          Exit
       EndIf
    EndFunc
    
    Func Fish() ;First function for fishing
       $out = _MemoryRead($address, $MemArray)
       If $out = 74765 Then
          Send("{f down}")
          Sleep($fish)
          Send("{f up}")
          Sleep($stall)
       Else
          MsgBox(0, "Error", "Fish")
          Exit
       EndIf
    EndFunc
    
    Func fMove1()
       $out = _MemoryRead($address, $MemArray)
       If $out = 74765 Then
          Send("{a down}")
          Sleep($walk)
          Send("{a up}")
          Sleep($stall)
          Send("{s down}")
          Sleep($walk)
          Send("{s up}")
          Sleep($stall)
       Else
          MsgBox(0, "Error", "fMove1")
          Exit
       EndIf
    EndFunc
    
    Func fMove2()
       $out = _MemoryRead($address, $MemArray)
       If $out = 74764 Then
          Send("{f down}")
          Sleep($fish)
          Send("{f up}")
          Sleep($stall)
       Else
          MsgBox(0, "Error", "fMove2")
          Exit
       EndIf
    EndFunc
    
    Func fMove3()
       $out = _MemoryRead($address, $MemArray)
       If $out = 74764 Then
          Send("{a down}")
          Sleep(700)
          Send("{a up}")
          Sleep($stall)
       Else
          MsgBox(0, "Error", "fMove3")
          Exit
       EndIf
    EndFunc
    
    Func fMove4()
       $out = _MemoryRead($address, $MemArray)
       If $out = 140297 Then
          Send("{s down}")
          Sleep($walk)
          Send("{s up}")
          Sleep($stall)
       Else
          MsgBox(0, "Error", "fMove4")
          Exit
       EndIf
    EndFunc
    
    Func fMove5()
       $out = _MemoryRead($address, $MemArray)
       If $out = 74761 Then
          Send("{f down}")
          Sleep($fish)
          Send("{f up}")
          Sleep($stall)
       Else
          MsgBox(0, "Error", "fMove5")
          Exit
       EndIf
    EndFunc
    
    Func fMove6()
       $out = _MemoryRead($address, $MemArray)
       If $out = 74761 Then
          Send("{d down}")
          Sleep(860)
          Send("{d up}")
          Sleep($stall)
       Else
          MsgBox(0, "Error", "fMove6")
          Exit
       EndIf
    EndFunc
    
    Func fMove7()
       $out = _MemoryRead($address, $MemArray)
       If $out = 205837 Then
          Send("{s down}")
          Sleep($walk)
          Send("{s up}")
          Sleep(2000)
          CastBuffs()
       Else
          MsgBox(0, "Error", "fMove7")
          Exit
       EndIf
    EndFunc
    
    Func Bank()
          Send("{d down}")
          Sleep(4600)
          Send("{d up}")
          Sleep($stall)
          Call(bMove1)
    EndFunc
    
    Func bMove1()
       $out = _MemoryRead($address, $MemArray)
       If $out = 205855 Then
          Send("{w down}")
          Sleep(3700)
          Send("{w up}")
          Sleep($stall)
          Call(bMove2)
       Else
          MsgBox(0, "Error", "bMove1")
          Exit
       EndIf
    EndFunc
    
    Func bMove2()
       $out = _MemoryRead($address, $MemArray)
       If $out = 5151 Then
          Send("{a down}")
          Sleep(3800)
          Send("{a up}")
          Sleep($stall)
          Call(bMove3)
       Else
          MsgBox(0, "Error", "bMove2")
          Exit
       EndIf
    EndFunc
    
    Func bMove3()
       $out = _MemoryRead($address, $MemArray)
       If $out = 136209 Then
          Send("{w down}")
          Sleep(850)
          Send("{w up}")
          Sleep($stall)
          EndIf
          $checkIfInvIsOpen = PixelSearch(1345, 625, 1350, 630, 0xCFAD94, 0)
          If Not(@error) Then
             Call(BankFish)
          Else
             MouseClick("left", 1089, 825, 1, 10)
             Call(BankFish)
       EndIf
    EndFunc
    
    Func BankFish()
       $checkInvForFood = PixelSearch(1105, 626, 1351, 797, $food, 0)
          If Not(@error) Then
             MouseClick("left", $checkInvForFood[0], $checkInvForFood[1], 1, 15)
             Send("{9}")
             Sleep($stall)
             Send("{9}")
             Sleep($stall)
             Send("{9}")
             Sleep($stall)
             Send("{enter}")
             Call(T2)
          Else
             Call(T2)
       EndIf
    EndFunc
    
    Func T2()
       $checkForT2Crate = PixelSearch(1105, 626, 1351, 797, $t2, 0)
          If Not(@error) Then
             MouseClick("left", $checkForT2Crate[0], $checkForT2Crate[1], 1, 15)
             Send("{9}")
             Sleep($stall)
             Send("{9}")
             Sleep($stall)
             Send("{9}")
             Sleep($stall)
             Send("{enter}")
          Else
       EndIf
    EndFunc
    
    Func CastBuffs()
       Send("{-}")
       Sleep(400)
       Send("{0}")
       Sleep(400)
       Send("{9}")
       Sleep(400)
       Send("{8}")
    EndFunc
    
    Func Tele()
       $CheckForTele = PixelSearch(1142, 696, 1172, 725, 0xFFBC44, 0)
          If Not(@error) Then
             MouseClick("left", $CheckForTele[0], $CheckForTele[1], 2, 15)
             Sleep(13500)
             MouseClick("left", 1090, 827, 2, 15)
             CastBuffs()
             Call(Bank)
          Else
          MouseClick("left", 1128, 827, 1, 15)
          Call(Tele)
       EndIf
    EndFunc
    
    Func myExit()
       msgbox(0,"Exiting", "Bot is quitting")
       Exit
    EndFunc
    I'm still new to coding so excuse my EXTREMELY sloppy way of doing this, that's why im here. Trying to figure out a proper way to move the character to the position even if it gets off track or something gets in the way. How the characters position works is a little weird. It reads from left to right just like a book. and it also has 4 values per tile, depending if your character is facing north, west, south or east. Anyway if there's anything else you need or any tips please comment below.

    I'll be 100% honest i'm very new to coding. I found the player location by scanning for an unknown value then moving one space to the right and searching for an increased value by one, then going left and finding a decrease then rinse and repeat till i found the location. Used that to then check if my player is in the right location as i stated above.

    Been watching some videos, i managed to attack a monster and scan their hp and then go into the memory and find all the values. I then did a pointscan towards the address of "~snip~.exe"+00135790" which is a goblin. then going into the pointscan i did i can then see all the information on that goblin, including health, it's position etc. But what can i do with this and how can i implement something like that into my code? I'm sure i can do the same with other things. But any information would help!

    Also, how could i do either mouseclick or controlclick event on a memory address? for example my player location address is: 0x06026CC0. How can i click on my player location, hopefully it'll target myself so then i can make a dank bot
    Last edited by pepsiplaya; 06-07-2018 at 11:46 PM.

Similar Threads

  1. [Solved] How to Create Own BOT for grimoire? (using script)
    By baguherma in forum Adventure Quest Worlds (AQW) Help
    Replies: 3
    Last Post: 06-06-2018, 08:08 PM
  2. Any Way to Spawn Bosses/Use HFS To Create Items?
    By Raisinets in forum Vindictus Discussions
    Replies: 1
    Last Post: 05-05-2011, 02:11 PM
  3. What Programs Do You Use to Make a AFK Bot?
    By doingtimeforlife in forum Combat Arms Discussions
    Replies: 4
    Last Post: 09-24-2009, 04:11 PM
  4. [HELP] How Do I Inject Im using viper101 GP and lvl Bot!
    By qdewased in forum Combat Arms Hacks & Cheats
    Replies: 5
    Last Post: 08-10-2008, 02:32 PM
  5. useful maple sites (tips, market, bot etc)
    By happyisles88 in forum MapleStory Hacks, Cheats & Trainers
    Replies: 1
    Last Post: 04-17-2008, 10:16 PM