Memory & Offsets

08/22/2010 16:46 majidemo#1
what i want to do?
i want to get the current value of MP / HP.

but my code doesnt give me the correct value, its always = 0

here is my own code

though the $Addr_CheckLogin, $Addr_CheckCharName is static so no problem with that.. but my problem is with the dynamic addresses that need offset and base address stuff.

Code:
#include <NomadMemory.au3>
#include <GUIConstants.au3>
#include <GUIListBox.au3>
#include <Misc.au3>
#include <Array.au3>
#include <asm.au3>
#include <basememory.au3>

;#RequireAdmin

;Declaring Variables
Global $MemPointer, $finalADDR, $baseADDR

;Check if Khan Online is running.
If ProcessExists("KhanClient.exe") = 0 Then
    MsgBox(0, "Error", "Khan Online is not running. Please start Khan first.")
    Exit
EndIf

;Get Khan Process and Open Memoryz
$ID=_MemoryOpen(ProcessExists("KhanClient.exe"))

;Function Calls
_ReadCurHP($ID)

;Addresses
$Addr_CheckLogin=0x0184B30C
$Addr_CheckCharName=0x00718DB4
$Addr_Exp=0x006F526E
;$Addr_CurHP=0x006F532C
$Addr_FullHP=0x006F5330
;$Addr_CurMP=0x
$Addr_FullMP=0x006F5356

;Check If Logged in to Khan
$Check_Login=_MemoryRead($Addr_CheckLogin,$ID)
If $Check_Login = ""  Then
    MsgBox(0x1010, "Error", "Please Login.")
    Exit
EndIf

;Check Selected Character Name
$Check_CharName=_MemoryRead($Addr_CheckCharName,$ID)
If $Check_CharName = ""  Then
    MsgBox(0x1010, "Error", "Please Select Character.")
    Exit
EndIf

;Display Character Selected
$Char_Chosen=_MemoryRead($Addr_CheckCharName, $ID, "Char[21]")
MsgBox(0, "Character Chosen",$Char_Chosen)

;Display Characters Current Exp
$Char_Exp=_MemoryRead($Addr_Exp, $ID, "Char[31]")
MsgBox(0, "Character EXP",$Char_Exp)

;Display Characters Current HP
$Char_CurHP=_MemoryRead($Addr_Exp, $ID, "Char[31]")
MsgBox(0, "Character HP",$baseADDR)

;functions for getting offsets
Func _ReadCurHP($ID)

	Global $CurHPOffset[6]
	$CurHPOffset[0] = 0
	$CurHPOffset[1] = Dec("017C")
	$CurHPOffset[2] = Dec("0108")
	$CurHPOffset[3] = Dec("0004")
	$CurHPOffset[4] = Dec("0004")
	$CurHPOffset[5] = Dec("0020")
	$StaticOffset = Dec("0030EA80")
	$openmem = _MemoryOpen($ID)
	$baseADDR = _MemoryGetBaseAddress($openmem, 1)
	$finalADDR = "0x" & Hex($baseADDR + $StaticOffset)
	$MemPointer = _MemoryPointerRead($finalADDR, $openmem, $CurHPOffset)
	_MemoryClose($openmem)

	Return $MemPointer
EndFunc
I saw this code somewhere, and I'm trying to edit it to work with the game I'm playing. I have the Base Address and My Offsets, but i have a problem.
i don't know how to complete the code.

please help?

Code:
#include <NomadMemory.au3>
$h=WinGetHandle("[CLASS:ZElementClient Window]","")
$pid = ProcessExists("elementclient.exe")
$pointer = Dec("00AF9094")
$offset = Dec("28")
$hp_current = Dec("270")
$hp_max = Dec("288")
$mp_current = Dec("274")
$mp_max = Dec("28C")

$openmem = _MemoryOpen($pid)
$base=_MemoryRead($pointer,$openmem)
$offsetADDR = "0x" & Hex($offset + $base)
$finalADDR=_memoryread($offsetADDR,$openmem)

$hp_current_ADDR = "0x" & Hex($hp_current + $finalADDR)
$hp_max_ADDR = "0x" & Hex($hp_max + $finalADDR)
$mp_current_ADDR = "0x" & Hex($mp_current + $finalADDR)
$mp_max_ADDR = "0x" & Hex($mp_max + $finalADDR)
this is the information about my address and offset,
i just used a generator to get this autoit function. i dont even understand much of this. but can someone help merge this code with the code above? thanks...

Code:
Func _ReadCurMP($pid)

	Global $CurMPOffset[6]
	$CurMPOffset[0] = 0
	$CurMPOffset[1] = Dec("017C")
	$CurMPOffset[2] = Dec("010C")
	$CurMPOffset[3] = Dec("0004")
	$CurMPOffset[4] = Dec("0004")
	$CurMPOffset[5] = Dec("0020")
	$StaticOffset = Dec("0030EA80")
	$openmem = _MemoryOpen($pid)
	$baseADDR = _MemoryGetBaseAddress($openmem, 1)
	$finalADDR = "0x" & Hex($baseADDR + $StaticOffset)
	$MemPointer = _MemoryPointerRead($finalADDR, $openmem, $CurMPOffset)
	_MemoryClose($openmem)

	Return $MemPointer
EndFunc
08/23/2010 02:37 Quadratball#2
PHP Code:
$MPread _MemoryPointerRead($finalADDR,$openmem,$CurMPOffset)
MsgBox(0"Info"$MPread[1]) 
Try this.
08/23/2010 07:21 majidemo#3
hi , thanks for the reply..
but i still cant make it work? could you please correct my code.
im looking for a char[10], because HP is stored in TEXT :) thanks

Code:
#include <NomadMemory.au3>
#include <GUIConstants.au3>
#include <GUIListBox.au3>
#include <Misc.au3>
#include <Array.au3>
#include <asm.au3>
#include <basememory.au3>

$ID = ProcessExists("KhanClient.exe")

	Global $CurHPOffset[6]
	$CurHPOffset[0] = 0
	$CurHPOffset[1] = Dec("017C")
	$CurHPOffset[2] = Dec("0108")
	$CurHPOffset[3] = Dec("0004")
	$CurHPOffset[4] = Dec("0004")
	$CurHPOffset[5] = Dec("0020")
	$StaticOffset = Dec("0030EA80")
	$openmem = _MemoryOpen($ID)
	$baseADDR = _MemoryGetBaseAddress($openmem, 1)
	$finalADDR = "0x" & Hex($baseADDR + $StaticOffset)
	$MemPointer = _MemoryPointerRead($finalADDR, $openmem, $CurHPOffset)
	_MemoryClose($openmem)

$MPread = _MemoryPointerRead($finalADDR,$openmem,$CurHPOffset)
MsgBox(0, "Info", $MPread)
08/24/2010 01:27 KDeluxe#4
PHP Code:
#include <NomadMemory.au3>

$ID ProcessExists("KhanClient.exe")
If 
$ID 0 Then
    
Global $CurHPOffset[6] = [00x17C0x1080x40x40x20]
    
$StaticOffset 0x30EA80

    $openmem 
_MemoryOpen($ID)
    
$baseADDR _MemoryGetBaseAddress($openmem1)
    
$finalADDR "0x" Hex($baseADDR $StaticOffset)

    
$HPread _MemoryPointerRead($finalADDR$openmem$CurHPOffset"char[10]")
    
_MemoryClose($openmem)
    
MsgBox(0"Info"$HPread[1])
EndIf 
08/24/2010 14:04 majidemo#5
Thank you :) now i have this code..
but i have a little question, how do i keep the value real time?
i mean, if the value changed in game, it will also change on my msgbox? or GUI?
and is there a cleaner code? i think my code is too long..hehe
Code:
#include <NomadMemory2.au3>
SetPrivilege("SeDebugPrivilege", 1)

;get process
$ID = ProcessExists("KhanClient.exe")

;check if khan is running
If ProcessExists("KhanClient.exe") = 0 Then
    MsgBox(0, "Error", "Khan Online is not running. Please start Khan first.")
    Exit
EndIf

;Offset Array
Global $CurHPOffset[7] = [0, 0x18570DC, 0x4338, 0x3C, 0x6C, 0x0, 0xC0]
Global $MaxHPOffset[7] = [0, 0x18570DC, 0x4338, 0x3C, 0x6C, 0x0, 0xC8]
Global $CurMPOffset[7] = [0, 0x18570DC, 0x4338, 0x3C, 0x6C, 0x4, 0xC0]
Global $MaxMPOffset[7] = [0, 0x18570DC, 0x4338, 0x3C, 0x6C, 0x4, 0xC8]
Global $CurEXPOffset[3] = [0, 0x7198BC, 0x128]
Global $MaxEXPOffset[3] = [0, 0x7197B4, 0x101C]

;Static Offsets
$HPMPStaticOffset = 0x18570DC
$CurEXPStaticOffset = 0x7198BC
$MaxEXPStaticOffset = 0x7197B4

;Process 1
$openmem = _MemoryOpen($ID)
$baseADDR = _MemoryGetBaseAddress($openmem, 1)

;get final read addresss
$HPMPfinalADDR = "0x" & Hex($baseADDR + $HPMPStaticOffset)
$CurEXPfinalADDR = "0x" & Hex($baseADDR + $CurEXPStaticOffset)
$MaxEXPfinalADDR = "0x" & Hex($baseADDR + $MaxEXPStaticOffset)

;Read
$CurHPread = _MemoryPointerRead($HPMPfinalADDR, $openmem, $CurHPOffset)
$MaxHPread = _MemoryPointerRead($HPMPfinalADDR, $openmem, $MaxHPOffset)
$CurMPread = _MemoryPointerRead($HPMPfinalADDR, $openmem, $CurMPOffset)
$MaxMPread = _MemoryPointerRead($HPMPfinalADDR, $openmem, $MaxMPOffset)
$CurEXPread = _MemoryPointerRead($CurEXPfinalADDR, $openmem, $CurEXPOffset)
$MaxEXPread = _MemoryPointerRead($MaxEXPfinalADDR, $openmem, $MaxEXPOffset)

;Close Memory
_MemoryClose($openmem)

;Get Percentage
$hp_perc = Int(($CurHPread[1]/$MaxHPread[1])*100)
$mp_perc = Int(($CurMPread[1]/$MaxMPread[1])*100)
$exp_perc = Int(($CurEXPread[1]/$MaxEXPread[1])*100)

;Test Display
MsgBox(0, "HP/MP/EXP", "HP: " & $CurHPread[1] & " / " & $MaxHPread[1] & " - " & $hp_perc & "%" & @CRLF & "MP: " & $CurMPread[1] & " / " & $MaxMPread[1] & " - " & $mp_perc & "%" & @CRLF & "EXP: " & $CurEXPread[1] & " / " & $MaxEXPread[1]& " - " & $exp_perc & "%")