;定义内存基址
$Address = 0x00FF0F90
;定义内存偏移地址
$Off_Hp = 0x310
;~ 01F228B0
MsgBox(0,"",Hex($Address+$Off_Hp))
;获取游戏句柄
$CurProcID=WinGetProcess("步骤")
;获取内存读写句柄
$Handle = _MemoryOpen($CurProcID)
;错误处理
If $Handle=0 then
MsgBox(4096,"错误提示","打开游戏内存错误。")
Exit
EndIf
$HP1 = _MemoryRead("0x" & Hex($Address), $Handle, "int")
;读取内存数据
$HP = _MemoryRead("0x" & Hex($HP1+$Off_Hp), $Handle, "int")
;~ $HP = _MemRead($Handle, $Address+$Off_Hp, "Byte")
MsgBox(0,"",$HP)
;关闭内存句柄
_MemoryClose($CurProcID)
;=================================================================================================
Func _MemoryOpen($iv_Pid, $iv_DesiredAccess = 0x1F0FFF, $if_InheritHandle = 1)
If Not ProcessExists($iv_Pid) Then
SetError(1)
Return 0
EndIf
Local $ah_Handle[2] = [DllOpen('kernel32.dll')]
If @Error Then
SetError(2)
Return 0
EndIf
Local $av_OpenProcess = DllCall($ah_Handle[0], 'int', 'OpenProcess', 'int', $iv_DesiredAccess, 'int', $if_InheritHandle, 'int', $iv_Pid)
If @Error Then
DllClose($ah_Handle[0])
SetError(3)
Return 0
EndIf
$ah_Handle[1] = $av_OpenProcess[0]
Return $ah_Handle
EndFunc
;=================================================================================================
Func _MemoryRead($iv_Address, $ah_Handle, $sv_Type = 'dword')
If Not IsArray($ah_Handle) Then
SetError(1)
Return 0
EndIf
Local $v_Buffer = DllStructCreate($sv_Type)
If @Error Then
SetError(@Error + 1)
Return 0
EndIf
DllCall($ah_Handle[0], 'int', 'ReadProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')
If Not @Error Then
Local $v_Value = DllStructGetData($v_Buffer, 1)
Return $v_Value
Else
SetError(6)
Return 0
EndIf
EndFunc
;=================================================================================================
Func _MemoryClose($ah_Handle)
If Not IsArray($ah_Handle) Then
SetError(1)
Return 0
EndIf
DllCall($ah_Handle[0], 'int', 'CloseHandle', 'int', $ah_Handle[1])
If Not @Error Then
DllClose($ah_Handle[0])
Return 1
Else
DllClose($ah_Handle[0])
SetError(2)
Return 0
EndIf
EndFunc
;=================================================================================================