I have tried with sending packages to make my character to fly up or down, but have failed.
The result so far is that the camera moves in steps of the flight speed every time interval (ie. not smooth) and ends up where it should be but the character stays where it was from the start.
Code:
Dim $oposx = 0x3c, $oposy = 0x44, $oposz = 0x40
Dim $oposx2 = 0x7c, $oposy2 = 0x84, $oposz2 = 0x80
Dim $oposx3 = 0x7e8, $oposy3 = 0x7f0, $oposz3 = 0x7ec
Dim $oposx4 = 0x828, $oposy4 = 0x830, $oposz4 = 0x82c
Fly(20) ;fly 20 units up
Func Fly($zfly)
local $packedaddress, $packetSize, $speed, $dX, $dY, $dZ, $destZ, $curX, $curY, $curZ
GetCharInfo($pid)
$speed = $charinfo[$IFlyspeed]
$curX = $charinfo[$IX]
$curY = $charinfo[$IY]
$curZ = $charinfo[$IZ]
$pchar = _MemoryRead(_MemoryRead($base, $pid) + 0x34, $pid)
$c = _MemoryRead($pchar + 0x928, $pid, 'word')
$destZ = $curZ + $zfly
$timeinterval = 1000
$timeneeded = DistanceFromMe($curX, $curY, $curZ + $zfly) / $speed
$dZ = (($destZ - $curZ) / $timeneeded) * $timeinterval / 1000
If $speed > 0 Then
While $timeneeded > ($timeinterval / 1000)
$curZ += $dZ
$packetAddress = DllCall($pid[0], 'int', 'VirtualAllocEx', 'int', $pid[1], 'ptr', 0, 'int', 0x21, 'int', 0x1000, 'int', 0x40)
_MemoryWrite($packetAddress[0], $pid, 0, 'word')
_MemoryWrite($packetAddress[0] + 2, $pid, $curX, 'float')
_MemoryWrite($packetAddress[0] + 6, $pid, $curY, 'float')
_MemoryWrite($packetAddress[0] + 10, $pid, $curZ, 'float')
_MemoryWrite($packetAddress[0] + 14, $pid, $curX, 'float')
_MemoryWrite($packetAddress[0] + 18, $pid, $curY, 'float')
_MemoryWrite($packetAddress[0] + 22, $pid, $curZ, 'float')
_MemoryWrite($packetAddress[0] + 26, $pid, $timeinterval, 'word')
_MemoryWrite($packetAddress[0] + 28, $pid, Round($speed * 256 + 0.5), 'word')
_MemoryWrite($packetAddress[0] + 30, $pid, 0x61, 'byte')
_MemoryWrite($packetAddress[0] + 31, $pid, $c, 'word')
sendPacket2($packetAddress, 0x21, $pid)
DllCall($pid[0], 'ptr', 'VirtualFreeEx', 'hwnd', $pid[1], 'int', $packetAddress[0], 'int', 0, 'int', 0x8000)
_MemoryWrite($pchar + $oposx, $pid, $curX, 'float')
_MemoryWrite($pchar + $oposy, $pid, $curY, 'float')
_MemoryWrite($pchar + $oposz, $pid, $curZ, 'float')
_MemoryWrite($pchar + $oposx2, $pid, $curX, 'float')
_MemoryWrite($pchar + $oposy2, $pid, $curY, 'float')
_MemoryWrite($pchar + $oposz2, $pid, $curZ, 'float')
_MemoryWrite($pchar + $oposx3, $pid, $curX, 'float')
_MemoryWrite($pchar + $oposy3, $pid, $curY, 'float')
_MemoryWrite($pchar + $oposz3, $pid, $curZ, 'float')
_MemoryWrite($pchar + $oposx4, $pid, $curX, 'float')
_MemoryWrite($pchar + $oposy4, $pid, $curY, 'float')
_MemoryWrite($pchar + $oposz4, $pid, $curZ, 'float')
$c += 1
_MemoryWrite($pchar + 0x928, $pid, $c, 'word') ;Update counter
$timeneeded -= $timeinterval / 1000
Sleep($timeinterval)
WEnd
EndIf
If ($timeneeded > 0) Then
$curZ += $dZ * $timeneeded
$packetAddress = DllCall($pid[0], 'int', 'VirtualAllocEx', 'int', $pid[1], 'ptr', 0, 'int', 0x16, 'int', 0x1000, 'int', 0x40)
_MemoryWrite($packetAddress[0], $pid, 7, 'word')
_MemoryWrite($packetAddress[0] + 2, $pid, $curX, 'float')
_MemoryWrite($packetAddress[0] + 6, $pid, $curY, 'float')
_MemoryWrite($packetAddress[0] + 10, $pid, $curZ, 'float')
_MemoryWrite($packetAddress[0] + 14, $pid, Round($speed * 256 + 0.5), 'word')
_MemoryWrite($packetAddress[0] + 16, $pid, 0, 'byte')
_MemoryWrite($packetAddress[0] + 17, $pid, 0x61, 'byte')
_MemoryWrite($packetAddress[0] + 18, $pid, $c, 'word')
_MemoryWrite($packetAddress[0] + 20, $pid, $timeneeded * 1000, 'word')
sendPacket2($packetAddress, 0x21, $pid)
DllCall($pid[0], 'ptr', 'VirtualFreeEx', 'hwnd', $pid[1], 'int', $packetAddress[0], 'int', 0, 'int', 0x8000)
_MemoryWrite($pchar + $oposx, $pid, $curX, 'float')
_MemoryWrite($pchar + $oposy, $pid, $curY, 'float')
_MemoryWrite($pchar + $oposz, $pid, $curZ, 'float')
_MemoryWrite($pchar + $oposx2, $pid, $curX, 'float')
_MemoryWrite($pchar + $oposy2, $pid, $curY, 'float')
_MemoryWrite($pchar + $oposz2, $pid, $curZ, 'float')
_MemoryWrite($pchar + $oposx3, $pid, $curX, 'float')
_MemoryWrite($pchar + $oposy3, $pid, $curY, 'float')
_MemoryWrite($pchar + $oposz3, $pid, $curZ, 'float')
_MemoryWrite($pchar + $oposx4, $pid, $curX, 'float')
_MemoryWrite($pchar + $oposy4, $pid, $curY, 'float')
_MemoryWrite($pchar + $oposz4, $pid, $curZ, 'float')
$c += 1
_MemoryWrite($pchar + 0x928, $pid, $c, 'word') ;Update counter
EndIf
EndFunc
Code:
Func sendPacket2($packetAddress, $packetSize, $pid)
Local $pRemoteThread, $vBuffer, $loop, $result, $OPcode, $processHandle, $functionAddress
$processHandle = $pid[1]
;//Allocate memory for the OpCode and retrieve address for this
$functionAddress = DllCall($pid[0], 'int', 'VirtualAllocEx', 'int', $processHandle, 'ptr', 0, 'int', 0x46, 'int', 0x1000, 'int', 0x40)
;//Construct the OpCode for calling the 'SendPacket' function
$OPcode &= '60' ;//PUSHAD
$OPcode &= 'B8'&_hex($sendPacketFunction) ;//MOV EAX, sendPacketAddress
$OPcode &= '8B0D'&_hex($realBaseAddress) ;//MOV ECX, DWORD PTR [revBaseAddress]
$OPcode &= '8B4920' ;//MOV ECX, DWORD PTR [ECX+20]
$OPcode &= 'BF'&_hex($packetAddress[0]) ;//MOV EDI, packetAddress //src pointer
$OPcode &= '6A'&_hex($packetSize,2) ;//PUSH packetSize //size
$OPcode &= '57' ;//PUSH EDI
$OPcode &= 'FFD0' ;//CALL EAX
$OPcode &= '61' ;//POPAD
$OPcode &= 'C3' ;//RET
;//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($pid[0], '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($pid[0], '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($pid[0], 'int', 'WaitForSingleObject', 'int', $hRemoteThread[0], 'int', 50)
Until $result[0] <> 258
;//Close the handle to the previously created remote thread
DllCall($pid[0], 'int', 'CloseHandle', 'int', $hRemoteThread[0])
;//Free the previously allocated memory
DllCall($pid[0], 'ptr', 'VirtualFreeEx', 'hwnd', $processHandle, 'int', $functionAddress[0], 'int', 0, 'int', 0x8000)
Return True
EndFunc
To target an npc with its id is something I've gotten to work with help of the send packets guide: