#include <NomadMemory.au3>
#include <Array.au3>
Global $kernel32 = DllOpen('kernel32.dll')
Global $ADDRESS_BASE=0xE5B2A4
Global $realBaseAddress=0xE5B2A4
Global $sendPacketFunction=0x81F130
Global $PlayerOffSet=0x34
Global $PlayerIdOffset=0x4B8
Global $PARTYINV_ADDRESS=0xE67C80
Global $NpcListOffset=0x20
Global $NpcCounterOffset=0x18
Global $sortedNpcListOffset=0x5C
Global $NpcUIDOffset=0x114
Global $NpcX=0x3C
Global $NpcY=0x44
Global $NpcZ=0x40
Global $NpcNameOffset=0x25C
Global $NpcHPOffset=0x128
Global $NpcHPmaxOffset=0x17C
Global $NpcIDOffset=0x118
Global $SORTEDLISTOffset=0x14
global $NpcStatusOffset=0x210
HotKeySet("{Home}", "Go1")
While 1
sleep(100)
WEnd
Func Go1()
$GAME_TITLE = "1"
$pid = WinGetProcess($GAME_TITLE)
$Filter = 4187 ;

- Teleport Master Shan
$array = NPCArrayFilter($Filter, $pid)
$NPCFilteredUID = $array[0][0]
startNpcDialogue($NPCFilteredUID, $pid)
EndFunc
Func startNpcDialogue($NPCFilteredUID, $pid)
local $packet, $packetSize
$packet = '2300'
$packet &= _hex($NPCFilteredUID)
$packetSize = 6
sendPacket($packet, $packetSize, $pid)
EndFunc
Func NPCArrayFilter($Filter, $pid)
$GAME_PROCESS = _MemoryOpen($pid)
$POINTER_BASE = _MemoryRead(_MemoryRead($ADDRESS_BASE, $GAME_PROCESS) + 0x1C, $GAME_PROCESS)
$SORTEDLIST = _MemoryRead($POINTER_BASE + $SORTEDLISTOffset, $GAME_PROCESS)
$NPCBASE = _MemoryRead($SORTEDLIST + $NpcListOffset, $GAME_PROCESS)
$NPCCOUNT = _MemoryRead($NPCBASE + $NpcCounterOffset, $GAME_PROCESS)
$NPCLIST = _MemoryRead($NPCBASE + $sortedNpcListOffset, $GAME_PROCESS)
If $NPCCOUNT = 0 Then Return
Dim $array[$NPCCOUNT][9]
For $i = 0 To $NPCCOUNT - 1
$NPC = _MemoryRead($NPCLIST + $i * 4, $GAME_PROCESS)
If ($NPC <> 0 And _MemoryRead($NPC + $NpcUIDOffset, $GAME_PROCESS)) Then
$array[$i][0] = _MemoryRead($NPC + $NpcUIDOffset, $GAME_PROCESS) ; unique ID
$array[$i][1] = _MemoryRead($NPC + $NpcIDOffset, $GAME_PROCESS) ; ID0
$array[$i][2] = _MemoryRead(_MemoryRead($NPC + $NpcNameOffset, $GAME_PROCESS), $GAME_PROCESS, 'wchar[100]')
$array[$i][4] = _MemoryRead($NPC + $NpcX, $GAME_PROCESS, 'float') ;X Coord in Map
$array[$i][5] = _MemoryRead($NPC + $NpcY, $GAME_PROCESS, 'float') ;y Coord in Map
$array[$i][6] = _MemoryRead($NPC + $NpcZ, $GAME_PROCESS, 'float') ;Z Coord or Vertical Altitude
$array[$i][7] = _MemoryRead($NPC + $NpcHPOffset, $GAME_PROCESS) ; HP
$array[$i][8] = _MemoryRead($NPC + $NpcHPmaxOffset, $GAME_PROCESS) ; Max HP
EndIf
Next
For $i = ($NPCCOUNT - 1) To 0 Step -1
If StringInStr($array[$i][2], $Filter) = 0 Then
_ArrayDelete($array, $i)
EndIf
Next
Return $array
EndFunc ;==>NPCArrayFilter
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 ;==>_Hex
Func _RevHex($VALUE, $SIZE = 8, $TYPE = "int")
Local $TEMP1, $TEMP2
If ($TYPE = "int") Then
$TEMP1 = StringRight("000000000" & Hex($VALUE), $SIZE)
ElseIf ($TYPE = "float") Then
$TEMP1 = StringRight("000000000" & _FloatToHex($VALUE), $SIZE)
EndIf
For $i = 0 To StringLen($TEMP1) / 2 - 1
$TEMP2 &= StringMid($TEMP1, StringLen($TEMP1) - 1 - 2 * $i, 2)
Next
Return $TEMP2
EndFunc ;==>_RevHex
Func _FloatToHex($floatval)
$sF = DllStructCreate("float")
$sB = DllStructCreate("ptr", DllStructGetPtr($sF))
If $floatval = "" Then Exit
DllStructSetData($sF, 1, $floatval)
$return = DllStructGetData($sB, 1)
Return $return
EndFunc ;==>_FloatToHex
Func sendPacket($packet, $packetSize, $pid)
;//Declare local variables
Local $pRemoteThread, $vBuffer, $loop, $result, $OPcode, $processHandle, $packetAddress
;//Open process for given processId
$processHandle = memopen($pid)
;//Allocate memory for the OpCode and retrieve address for this
$functionAddress = DllCall($kernel32, 'int', 'VirtualAllocEx', 'int', $processHandle, 'ptr', 0, 'int', 0x46, 'int', 0x1000, 'int', 0x40)
;//Allocate memory for the packet to be sent and retrieve the address for this
$packetAddress = DllCall($kernel32, 'int', 'VirtualAllocEx', 'int', $processHandle, 'ptr', 0, 'int', $packetSize, '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($kernel32, 'int', 'WriteProcessMemory', 'int', $processHandle, 'int', $functionAddress[0], 'int', DllStructGetPtr($vBuffer), 'int', DllStructGetSize($vBuffer), 'int', 0)
;//Put the packet into a struct for later memory writing
$vBuffer = DllStructCreate('byte[' & StringLen($packet) / 2 & ']')
For $loop = 1 To DllStructGetSize($vBuffer)
DllStructSetData($vBuffer, 1, Dec(StringMid($packet, ($loop - 1) * 2 + 1, 2)), $loop)
Next
;//Write the packet to previously allocated memory
DllCall($kernel32, 'int', 'WriteProcessMemory', 'int', $processHandle, 'int', $packetAddress[0], 'int', DllStructGetPtr($vBuffer), 'int', DllStructGetSize($vBuffer), 'int', 0)
;//Create a remote thread in order to run the OpCode
$hRemoteThread = DllCall($kernel32, '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, 'int', 'CloseHandle', 'int', $hRemoteThread[0])
;//Free the previously allocated memory
DllCall($kernel32, 'ptr', 'VirtualFreeEx', 'hwnd', $processHandle, 'int', $functionAddress[0], 'int', 0, 'int', 0x8000)
DllCall($kernel32, 'ptr', 'VirtualFreeEx', 'hwnd', $processHandle, 'int', $packetAddress[0], 'int', 0, 'int', 0x8000)
;//Close the Process
memclose($processHandle)
Return True
EndFunc
Func memopen($pid)
Local $mid = DllCall($kernel32, 'int', 'OpenProcess', 'int', 0x1F0FFF, 'int', 1, 'int', $pid)
Return $mid[0]
EndFunc
Func memclose($mid)
DllCall($kernel32, 'int', 'CloseHandle', 'int', $mid)
EndFunc