Code:
$ADDRESS_BASE = 0xD22C74
$ADDRESS_ACTION1 = 0x49FF80
$ADDRESS_ACTION2 = 0x4A6320
$ADDRESS_ACTION3 = 0x4A0590
$OFFSET_ACTIONBASE = 0x13EC
Func MoveXYZ($GAME_X, $GAME_Y, $GAME_Z, $MOVEVERT=0)
$DEST_X = $GAME_X*10-4000
$DEST_Y = $GAME_Y*10-5500
$DEST_Z = $GAME_Z*10
MoveTo($DEST_X, $DEST_Y, $DEST_Z, $MOVEVERT)
EndFunc
Func MoveTo($DEST_X, $DEST_Y, $DEST_Z, $FLYMODE=0)
;Declare local variables
;Open process for given processId
$processHandle = $GAME_PROCESS[1]
;Allocate memory for the OpCode and retrieve address for this
$functionAddress = DllCall('kernel32.dll', 'int', 'VirtualAllocEx', 'int', $processHandle, 'ptr', 0, 'int', 100, 'int', 0x1000, 'int', 0x40)
;Construct the OpCode for calling the 'MoveXYZ' function
$OPcode = "60" ;60 PUSHAD
$OPcode &= "B8" & _Hex($ADDRESS_BASE) ;B8 00000000 MOV EAX,#Baseadr
$OPcode &= "8B00" ;8B00 MOV EAX,DWORD PTR DS:[EAX]
$OPcode &= "8B401C" ;8B40 1C MOV EAX,DWORD PTR DS:[EAX+1C]
$OPcode &= "8B7028" ;8B70 28 MOV ESI,DWORD PTR DS:[EAX+28]
$OPcode &= "8B8E" & _Hex($OFFSET_ACTIONBASE);8B8E 11111111 MOV ECX,DWORD PTR DS:[ESI+ActArr]
$OPcode &= "6A01" ;6A 01 PUSH 1
$OPcode &= "BA" & _Hex($ADDRESS_ACTION1) ;BA 00000000 MOV EDX,Walk1
$OPcode &= "FFD2" ;FFD2 CALL EDX
$OPcode &= "8BF8" ;8BF8 MOV EDI,EAX
$OPcode &= "8D442418" ;8D4424 18 LEA EAX,DWORD PTR SS:[ESP+18]
$OPcode &= "50" ;50 PUSH EAX
$OPcode &= "BA" & _Hex($FLYMODE) ;BA 00000000 MOV EDX, fly mode
$OPcode &= "52" ;52 PUSH EDX
$OPcode &= "8BCF" ;8BCF MOV ECX,EDI
$OPcode &= "BA" & _Hex($ADDRESS_ACTION2) ;BA 00000000 MOV EDX,Walk2
$OPcode &= "FFD2" ;FFD2 CALL EDX
$OPcode &= "8B8E" & _Hex($OFFSET_ACTIONBASE);8B8E 22222222 MOV ECX,DWORD PTR DS:[ESI+ActArr]
$OPcode &= "B8" & _Hex($DEST_X, 8, 'float') ;B8 00000000 MOV EAX,x
$OPcode &= "8BD7" ;8BD7 MOV EDX,EDI
$OPcode &= "83C220" ;83C2 20 ADD EDX,20
$OPcode &= "8902" ;8902 MOV DWORD PTR DS:[EDX],EAX
$OPcode &= "B8" & _Hex($DEST_Z, 8, 'float') ;B8 00000000 MOV EAX,z
$OPcode &= "8BD7" ;8BD7 MOV EDX,EDI
$OPcode &= "83C224" ;83C2 24 ADD EDX,24
$OPcode &= "8902" ;8902 MOV DWORD PTR DS:[EDX],EAX
$OPcode &= "B8" & _Hex($DEST_Y, 8, 'float') ;B8 00000000 MOV EAX,y
$OPcode &= "8BD7" ;8BD7 MOV EDX,EDI
$OPcode &= "83C228" ;83C2 28 ADD EDX,28
$OPcode &= "8902" ;8902 MOV DWORD PTR DS:[EDX],EAX
$OPcode &= "6A00" ;6A 00 PUSH 0
$OPcode &= "6A01" ;6A 01 PUSH 1
$OPcode &= "57" ;57 PUSH EDI
$OPcode &= "6A01" ;6A 01 PUSH 1
$OPcode &= "BA" & _Hex($ADDRESS_ACTION3) ;BA 00000000 MOV EDX,Walk3
$OPcode &= "FFD2" ;FFD2 CALL EDX
$OPcode &= "61" ;61 POPAD
$OPcode &= "C3" ;C3 RETN
;Put the OpCode into a struct for later memory writing
$vBuffer = DllStructCreate('byte[' & StringLen($OPcode) / 2 & ']')
For $loop = 1 To DllStructGetSize($vBuffer)
DllStructSetData($vBuffer, 1, Dec(StringMid($OPcode, ($loop - 1) * 2 + 1, 2)), $loop)
Next
;Write the OpCode to previously allocated memory
DllCall('kernel32.dll', 'int', 'WriteProcessMemory', 'int', $processHandle, 'int', $functionAddress[0], 'int', DllStructGetPtr($vBuffer), 'int', DllStructGetSize($vBuffer), 'int', 0)
;Create a remote thread in order to run the OpCode
$hRemoteThread = DllCall('kernel32.dll', 'int', 'CreateRemoteThread', 'int', $processHandle, 'int', 0, 'int', 0, 'int', $functionAddress[0], 'ptr', 0, 'int', 0, 'int', 0)
;Wait for the remote thread to finish
Do
$result = DllCall('kernel32.dll', 'int', 'WaitForSingleObject', 'int', $hRemoteThread[0], 'int', 50)
Until $result[0] <> 258
;Close the handle to the previously created remote thread
DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $hRemoteThread[0])
;Free the previously allocated memory
DllCall('kernel32.dll', 'ptr', 'VirtualFreeEx', 'hwnd', $processHandle, 'int', $functionAddress[0], 'int', 0, 'int', 0x8000)
Return True
EndFunc
Func _Hex($Value, $size=8, $type="int")
Local $tmp1, $tmp2, $i
If($type = "int") Then
$tmp1 = StringRight("000000000" & Hex($Value), $size)
ElseIf($type = "float") Then
$tmp1 = StringRight("000000000" & _FloatToHex($Value), $size)
EndIf
For $i = 0 To StringLen($tmp1) / 2 - 1
$tmp2 = $tmp2 & StringMid($tmp1, StringLen($tmp1) - 1 - 2 * $i, 2)
Next
Return $tmp2
EndFunc