Sign in to follow this  
Followers 0
lbrtdy

Memory Read

6 posts in this topic

#1 ·  Posted (edited)

Below is a script that is working that reads the current hp of a character in game (SRO):

#include <nomadmemory.au3>
Global $CURHPOS = 1116
Global $POINTER = 13885268

Global $PROC = ProcessList("SRO_Client.exe")
Global $DLLINFO1 = _MEMORYOPEN($PROC[1][1])

$HP = _FINDNEWADDRESS($POINTER, $CURHPOS)
$CURHPOS = _MEMORYREAD($HP, $DLLINFO1)

MsgBox(0,"",$CURHPOS)

Func _FINDNEWADDRESS(ByRef $POINTER, ByRef $OSET)
    $NEW_ADDRESS = _MEMORYREAD($POINTER, $DLLINFO1) + $OSET
    Return $NEW_ADDRESS
EndFunc

Which successfully returns the hp. But when I try to add this snippet of code into a GUI and make it shutdown computer, and iniwrite time of death when Hp = 0, as soon as I turn it on the iniwrite is done and shuts down computer regardless of Hp. And no major changes are done, so hopefully a trained eye can spot the problem, as you most likely don't wanna try the game out ^^ thank you for your time and effort.

; AutoIt Version: 3.3.0.0
; Author: Lbrtdy

; Script Function:
;   Auto Shut/StandBy down computer
;

;------------------------------------------------------------------------------
#include <NomadMemory.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

HotKeySet("{F8}","ShowGUI")

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Albert Zhen\My Documents\Autoit\GUI\Farming Tool.kxf
$Form1 = GUICreate("Farming Tool", 162, 116, 353, 301, -1, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$DeathCheckBox = GUICtrlCreateCheckbox("Death", 8, 8, 49, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$TimeCheckBox = GUICtrlCreateCheckbox("Time", 8, 32, 49, 17)
$Hour = GUICtrlCreateInput("Hour", 64, 32, 41, 21)
GUICtrlSetLimit(-1, 2)
GUICtrlSetState(-1, $GUI_DISABLE)
$Minute = GUICtrlCreateInput("Min", 120, 32, 33, 21)
GUICtrlSetLimit(-1, 2)
GUICtrlSetState(-1, $GUI_DISABLE)
$Colon = GUICtrlCreateLabel(":", 112, 32, 7, 17)
$ShutDown = GUICtrlCreateCheckbox("ShutDown", 8, 64, 73, 17)
$StandBy = GUICtrlCreateCheckbox("StandBy", 96, 64, 65, 17)
$Group1 = GUICtrlCreateGroup("", 0, 0, 161, 57)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Hide = GUICtrlCreateButton("Hide", 45, 88, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;---Constants---
$PROC = ProcessList("SRO_Client.exe")
Global $CURHPOS = 1116
Global $POINTER = 13885268

;---Declared vars---
Global $TimerCheckBoxState ;used to enable input fields when "Timer" option is ticked

;---Timer---
AdlibEnable("TimerCheckBox", 100)


While 1
    $DeathCheckBoxState = GUICtrlRead($DeathCheckBox) ;checks if checking character death is specified
    if $DeathCheckBoxState = $GUI_CHECKED Then ;if it is specified then...
        ;checks Hp of character
        
        $DLLINFO1 = _MEMORYOPEN($PROC[1][1])
        $HP = _FINDNEWADDRESS($POINTER, $CURHPOS)
        $CURHPOS = _MEMORYREAD($HP, $DLLINFO1)

        
        ;shuts down/standby computer if Hp = 0
        if $CURHPOS = 0 Then
            IniWrite("Info.ini","Death","Hour",@HOUR)
            IniWrite("Info.ini","Death","Minute",@MIN)
;~          $ShutDownState = GUICtrlRead($Shutdown)
;~          if $ShutDownState = $GUI_CHECKED Then ;if shutdown checkbox is checked then shutdown computer
;~              run("shutdown -s")
;~          EndIf
;~          $StandByState = GUICtrlRead($StandBy)
;~          if $StandByState = $GUI_CHECKED Then ;if standby checkbox is checked then standby computer
;~              Run("shutdown -l")
;~          EndIf
            ;_MEMORYCLOSE($PROC)
            Exit
        EndIf
        Sleep(1000) ;checks on the health of character every 1 second.
    EndIf
    
    $TimeCheckBoxState = GUICtrlRead($TimeCheckBox) ;checks if checking time is specified
    if $TimeCheckBoxState = $GUI_CHECKED Then ;if it is specified then...
        If $Hour = @HOUR and $Minute = @MIN Then
            IniWrite("Info.ini","Time","Hour",@HOUR)
            IniWrite("Info.ini","Time","Minute",@MIN)
            $ShutDownState = GUICtrlRead($Shutdown)
            if $ShutDownState = $GUI_CHECKED) Then ;if shutdown check box is checked then shutdown the computer
                run("shutdown -s")
            EndIf
            $StandByState = GUICtrlRead($StandBy)
            if $StandByState = $GUI_CHECKED Then ;if standby checkbox is checked then standby the computer
                Run("shutdown -l")
            EndIf
        EndIf
    EndIf
    
    ;<<<<<<<<<<<<<<<<<<<   GUI     >>>>>>>>>>>>>>>>>>>>>
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            
        Case $Hide
            GUICtrlSetState($Form1, @SW_HIDE)
    EndSwitch
WEnd


Func TimerCheckBox() ;enables input fields when checkbox is ticked
    $TimerCheckBoxState = GUICtrlRead($TimeCheckBox)
    if $TimerCheckBoxState = $GUI_CHECKED Then
        GUICtrlSetState($Hour, $GUI_ENABLE)
        GUICtrlSetState($Minute, $GUI_ENABLE)
    ElseIf $TimerCheckBoxState = $GUI_UNCHECKED Then
        GUICtrlSetState($Hour, $GUI_DISABLE)
        GUICtrlSetState($Minute, $GUI_DISABLE)
    EndIf
EndFunc

Func ShowGUI()
    GUICtrlSetState($Form1,@SW_SHOW)
EndFunc

Func _FINDNEWADDRESS(ByRef $POINTER, ByRef $OSET)
    $NEW_ADDRESS = _MEMORYREAD($POINTER, $DLLINFO1) + $OSET
    Return $NEW_ADDRESS
EndFunc
Edited by lbrtdy

Share this post


Link to post
Share on other sites



Actually.. Maybe the method that I'm using to get the hp is wrong. When I change the first piece of code I posted to this, with a loop.

#include <nomadmemory.au3>
Global $CURHPOS = 1116
Global $POINTER = 13885268

Global $PROC = ProcessList("SRO_Client.exe")
Global $DLLINFO1 = _MEMORYOPEN($PROC[1][1])

while 1
$HP = _FINDNEWADDRESS($POINTER, $CURHPOS)
$CURHPOS = _MEMORYREAD($HP, $DLLINFO1)

MsgBox(0,"",$CURHPOS)
wend
Func _FINDNEWADDRESS(ByRef $POINTER, ByRef $OSET)
    $NEW_ADDRESS = _MEMORYREAD($POINTER, $DLLINFO1) + $OSET
    Return $NEW_ADDRESS
EndFunc

The first value it returns is the correct hp, but the second and third etc etc seems to be random and it'll hit 0, which is why my script was prematurely firing off thinking my character is dead. But.. When I remove the loop and keep running over and over again it'll return the same first answer. So my question now is:

How should I make it so that it continuously checks the hp, But does the equivalent of restarting the script and getting the first value that is returned as Hp? Thank you.

Share this post


Link to post
Share on other sites

Don't assign the new address to the offset variable because in the next loop the amount of hp you have will be the offset of the pointer heh.

Share this post


Link to post
Share on other sites

What does the _FINDNEWADDRESS do? Normally, for SRO, you only need 2 calls of memoryRead to find the HP.

$struct = _MemoryRead($pointer, $dll) ;Read the address of the structure
$HP = _MemoryRead($struct+$offset, $dll)

Moreover, the HP address only change when you restart the client or teleport only. You don't need to call $HP = _FINDNEWADDRESS($POINTER, $CURHPOS) in every loop.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

What does the _FINDNEWADDRESS do? Normally, for SRO, you only need 2 calls of memoryRead to find the HP.

$struct = _MemoryRead($pointer, $dll) ;Read the address of the structure
$HP = _MemoryRead($struct+$offset, $dll)

...

That is in the case of [reg+off] case but usually the pointer is held in a specific memory address and the offset part has to be calculated correctly:

EAX=0000037A
EBX=00D7282C // ....
ECX=004310D8
EDX=0000037A
ESI=00D72E74
EDI=0000037A
EBP=0012F638
ESP=0012F61C
EIP=00459865

0045985b - call 00402b70
00459860 - mov edi,eax
00459862 - mov [ebx+18],edi // ....
00459865 - lea edx,[ebp-04]
00459868 - mov eax,edi

// After another scan the address pointing to ebx's value is 0x00D70000.
[D70000 + 18] != [D70000]+18 // Which is most probably the case here.

Edit: Meh, nevermind. I reread your post and see it's actually same but using two calls instead of just one :).

Edited by Authenticity

Share this post


Link to post
Share on other sites

Well unfortunately I wasn't able to try this out as the game updated and all the offsets doesn't work. So I'll have to wait until someone posts them again before continuing on with this project. Thanks for everyone who helped! :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0