Code:
#include <String.au3>
#include <NomadMemory.au3>
HotKeySet("{END}", "_Quit")
#region -- Make sure we have admin right
;modified from http://www.ownedcore.com/forums/diablo-3/diablo-3-bots-programs/diablo-3-memory-editing/361270-autoit-diablo-3-click-move-interaction-actor-handling-version-2-a.html
;author: UnknOwned
#RequireAdmin
$Admin = IsAdmin()
if $Admin <> 1 Then
MsgBox(0x30,"ERROR","You need administrative rights")
Exit
EndIf
#endregion
#region -- Open memory for Gw2 and determine base address
;modified from http://www.ownedcore.com/forums/diablo-3/diablo-3-bots-programs/diablo-3-memory-editing/361270-autoit-diablo-3-click-move-interaction-actor-handling-version-2-a.html
;author: UnknOwned
Opt("WinTitleMatchMode", -1)
SetPrivilege("SeDebugPrivilege", 1)
$Gw2Exefile = "Gw2.exe"
$list = ProcessList()
for $i = 1 to $list[0][0]
if $list[$i][0] = $Gw2Exefile Then
Global $ProcessID = $list[$i][1]
ExitLoop
EndIf
next
Local $gw2 = _MemoryOpen($ProcessID)
If @Error Then
MsgBox(4096, "ERROR", "Failed to open memory for process;" & $ProcessID)
Exit
EndIf
#endregion
WinActivate("Guild Wars 2")
Global $player_offset
Global $player_physical_x, $player_physical_y, $player_physical_z
Global $player_visual_x, $player_visual_y, $player_visual_z
Global $player_speed
Global $player_gravity
Global $player_heading_A1, $player_heading_B1, $player_heading_A2, $player_heading_B2
_GetPlayerOffset()
_InitPointers()
While 1
Sleep(100)
WEnd
#region -- various user written functions
Func _isInGame()
Return _MemoryRead(0x015C5D78, $gw2, 'int') ;0 for no, 1 for yes
EndFunc
Func _GetPlayerOffset()
;must be called when player zones
$pattern = "8B108BC88B4210FFD0D95DF0E8" ;pattern to find call
$call = _MemoryPatternSearch($gw2, $pattern, 0x00400000, 0x00600000, 51200) ;read the base address of the call
$test = _MemoryRead($call-4, $gw2, 'int') ;read the offset for the call
$player_offset = _MemoryRead($call+$test+1, $gw2, 'int') + 0x20C +0x14 ;read the player offset (and add 0x20C)
Return
EndFunc
Func _InitPointers()
;must be called when player zones
$player_heading_A1 = _PointerRead($player_offset, 0x44, 0x1C, 0x5C) + 0x94 ;returns Addr
$player_heading_B1 = $player_heading_A1 + 4
$player_heading_A2 = _PointerRead($player_offset, 0x44, 0x1C, 0x5C) + 0xA4 ;returns Addr
$player_heading_B2 = $player_heading_A2 + 4
$player_visual_x = _PointerRead($player_offset, 0x44, 0x1C, 0x5C) + 0xB4 ;returns Addr
$player_visual_y = $player_visual_x + 4
$player_visual_z = $player_visual_y + 4
$player_gravity = _PointerRead($player_offset, 0x44, 0x1C, 0x5C) + 0x104 ;returns Addr
$player_speed = _PointerRead($player_offset, 0x44, 0x1C, 0x5C) + 0x114 ;returns Addr
$player_physical_x = _PointerRead($player_offset, 0x44, 0x1C, 0x88) + 0xD0 ;returns Addr
$player_physical_y = $player_physical_x + 4
$player_physical_z = $player_physical_y + 4
EndFunc
Func _PointerRead($StartAddress, $offset1, $offset2, $offset3)
Local $temp
$temp = $StartAddress
$temp = _MemoryRead($temp, $gw2, 'ptr') ;returns first address
$temp = _MemoryRead($temp+$offset1, $gw2, 'ptr') ;returns address
$temp = _MemoryRead($temp+$offset2, $gw2, 'ptr') ;returns address
$temp = _MemoryRead($temp+$offset3, $gw2, 'ptr') ;returns
Return $temp
EndFunc
Func _GetHeading()
Local $return[4]
$return[0] = _MemoryRead($player_heading_A1, $gw2, 'float')
$return[1] = _MemoryRead($player_heading_B1, $gw2, 'float')
$return[2] = _MemoryRead($player_heading_A2, $gw2, 'float')
$return[3] = _MemoryRead($player_heading_B2, $gw2, 'float')
Return $return
EndFunc
Func _GetPhysicalPos()
Local $return[3]
$return[0] = _MemoryRead($player_physical_x, $gw2, 'float')
$return[1] = _MemoryRead($player_physical_y, $gw2, 'float')
$return[2] = _MemoryRead($player_physical_z, $gw2, 'float')
Return $return
EndFunc
Func _GetVisualPos()
Local $return[3]
$return[0] = _MemoryRead($player_visual_x, $gw2, 'float')
$return[1] = _MemoryRead($player_visual_y, $gw2, 'float')
$return[2] = _MemoryRead($player_visual_z, $gw2, 'float')
Return $return
EndFunc
Func _GetSpeed()
Return _MemoryRead($player_speed, $gw2, 'float')
EndFunc
Func _GetGravity()
Return _MemoryRead($player_gravity, $gw2, 'float')
EndFunc
Func _Quit()
Exit
EndFunc
#endregion
Func _MemoryPatternSearch($ProcessHandle, $Pattern, $StartAddress = 0x00400000, $StopAddress = 0x00600000, $Step = 51200)
;found here: http://www.autoitscript.com/forum/topic/137320-c-memory-pattern-scanner/
;not sure of original author
If Not IsArray($ProcessHandle) Then
SetError(1)
Return -1
EndIf
$Pattern = StringRegExpReplace($Pattern, '[^0123456789ABCDEFabcdef.]', '')
If StringLen($Pattern) = 0 Then
SetError(2)
Return -2
EndIf
Local $BufferPattern, $FormatedPattern
For $i = 0 To ((StringLen($Pattern) / 2) - 1)
$BufferPattern = StringLeft($Pattern, 2)
$Pattern = StringRight($Pattern, StringLen($Pattern) - 2)
$FormatedPattern = $FormatedPattern & $BufferPattern
Next
$Pattern = $FormatedPattern
For $Address = $StartAddress To $StopAddress Step $Step - (StringLen($Pattern) / 2)
StringRegExp(_MemoryRead($Address, $ProcessHandle, 'byte[' & $Step & ']'), $Pattern, 1, 2)
If Not @error Then
;~ Return StringFormat('0x%.8X', $Address + ((@extended - StringLen($Pattern) - 2) / 2)) ;original function
Return Floor($Address + ((@extended - StringLen($Pattern) - 2) / 2))
EndIf
Next
Return -3
EndFunc