well first you have to get a list of all mobs around you. to do that you gotta find the npclist function.
it looks like this:
Code:
;~ Npclist
;~ 005D49E0 /$ 56 PUSH ESI
;~ 005D49E1 |. 8B7424 08 MOV ESI,DWORD PTR SS:[ESP+8]
;~ 005D49E5 |. 8BC6 MOV EAX,ESI
;~ 005D49E7 |. 33D2 XOR EDX,EDX
;~ 005D49E9 |. F771 24 DIV DWORD PTR DS:[ECX+24]
;~ 005D49EC |. 8B41 18 MOV EAX,DWORD PTR DS:[ECX+18]
;~ 005D49EF |. 8B1490 MOV EDX,DWORD PTR DS:[EAX+EDX*4]
;~ 005D49F2 |. 85D2 TEST EDX,EDX
;~ 005D49F4 |. 74 0B JE SHORT elementc.005D4A01
;~ 005D49F6 |> 3972 08 /CMP DWORD PTR DS:[EDX+8],ESI
;~ 005D49F9 |. 74 0C |JE SHORT elementc.005D4A07
;~ 005D49FB |. 8B12 |MOV EDX,DWORD PTR DS:[EDX]
;~ 005D49FD |. 85D2 |TEST EDX,EDX
;~ 005D49FF |.^75 F5 \JNZ SHORT elementc.005D49F6
;~ 005D4A01 |> 33C0 XOR EAX,EAX
;~ 005D4A03 |. 5E POP ESI
;~ 005D4A04 |. C2 0800 RETN 8
;~ 005D4A07 |> 8B4424 0C MOV EAX,DWORD PTR SS:[ESP+C]
;~ 005D4A0B |. 85C0 TEST EAX,EAX
;~ 005D4A0D |. 74 11 JE SHORT elementc.005D4A20
;~ 005D4A0F |. 8B4A 04 MOV ECX,DWORD PTR DS:[EDX+4]
;~ 005D4A12 |. 3981 E8000000 CMP DWORD PTR DS:[ECX+E8],EAX
;~ 005D4A18 |. 74 06 JE SHORT elementc.005D4A20
;~ 005D4A1A |. 33C0 XOR EAX,EAX
;~ 005D4A1C |. 5E POP ESI
;~ 005D4A1D |. C2 0800 RETN 8
;~ 005D4A20 |> 8B42 04 MOV EAX,DWORD PTR DS:[EDX+4]
;~ 005D4A23 |. 5E POP ESI
;~ 005D4A24 \. C2 0800 RETN 8
now that we know how the client builds up the list of all npcs, we can do the same in our tool.
we could even let the script show us the offsets we need.
Code:
$path = "elementclient.exe"
$file = FileOpen($path, 16)
$data = FileRead($file, FileGetSize($path))
FileClose($file)
$npc_list = StringRegExp($data, '568B7424(.{2})8BC633D2F771(.{2})8B41(.{2})8B149085D274.{2}3972.{2}74.{2}8B1285D275.{2}33C05EC2.{4}8B4424.{2}85C074.{2}8B4A(.{2})', 1)
If IsArray($npc_list) Then ConsoleWrite('MobBase = ClientBase + 0x1C + 0x'&$npc_list[0]&' + 0x'&$npc_list[1]&' + 0x'&$npc_list[2]&' + x*4 + 0x'&$npc_list[3]&@CRLF)
will return us something like this (in PWI):
Quote:
|
MobBase = ClientBase + 0x1C + 0x08 + 0x24 + 0x18 + x*4 + 0x04
|
now that we've got the structure, we can build that code up in autoit.
Code:
$npc_base = memread(memread(memread(memread(memread(memread(memread($base) + 0x1C) + 0x8) + 0x24) + 0x18) + $x*0x4) + 0x4)
if we set a breakpoint on the variable line, we'll get the range we have to make $x loop through (should be 0-768 normaly). (loops should allways be done with "for ... next" in autoit)
well now that we've got a list of all npc_bases, we will have to figure out some offsets for that base. guess type, id, position, name, level and maybe some more would be helpfull for filtering/selecting the mobs.
my NpcListing function looks like this:
Code:
Func GetNpcList()
Local $array[1][8], $pointer, $npc_base, $counter
$pointer = memread(memread(memread(memread(memread($base) + 0x1C) + 0x8) + 0x24) + 0x18)
For $x=0 To 768
$npc_base = memread(memread($pointer + $x*0x4) + 0x4)
If $npc_base<>0 Then
ReDim $array[$counter+1][8]
$array[$counter][0] = memread($npc_base, 'byte') ;NPC Type (NPC/MOB/PET)
$array[$counter][1] = memread($npc_base + 0x11C) ;NPC ID
$array[$counter][2] = memread(memread($npc_base + 0x254), 'wchar[30]') ;NPC Name
$array[$counter][3] = memread($npc_base + 0x124) ;NPC Level
$array[$counter][4] = memread($npc_base + 0x248) ;Special Info
$array[$counter][5] = (memread($npc_base + 0x3C, 'float')+4000)/10 ;NPC x-position
$array[$counter][6] = (memread($npc_base + 0x44, 'float')+5500)/10 ;NPC y-position
$array[$counter][7] = memread($npc_base + 0x40, 'float')/10 ;NPC z-position
$counter += 1
EndIf
Next
Return $array
EndFunc
and it returns something like that:
[Only registered and activated users can see links. Click Here To Register...]
now that u've got a list of all available mobs and special infos, you could calculate the distance between player and mobs, and selected the closest one. (you can even filter them, by name or filter out mag resistant (for wizzards) mobs or whatever you like to do with those infos =))
if you need a basic list of special info types i've found so far, you could check my open source
[Only registered and activated users can see links. Click Here To Register...]
well the most important part is still missing. now i've got those mob ids, but how can i use them to select the mob?
to do that i've used the selection function from the client.
Code:
;~ select
;~ 0046061D A1 6C3E9F00 MOV EAX,DWORD PTR DS:[9F3E6C] ; |eax <- [base]
;~ 00460622 57 PUSH EDI ; |Arg1 = Mob-ID
;~ 00460623 |. 8B48 20 MOV ECX,DWORD PTR DS:[EAX+20] ; |ecx <- [[base]+0x20]
;~ 00460626 |. 81C1 EC000000 ADD ECX,0EC ; |ecx += 0xEC
;~ 0046062C |. E8 8F961800 CALL elementc.005E9CC0 ; \call select_call
thats the code in the PWI client. may be a little diferent in your client, but i've allready posted a tool above which gets the base and select_call adress.
to use it we will simply allocate some memory in the element client, for our tool, add the select function to it and run it. after that we'll delete the code from the client, to make some space for more functions we could use. (we could also leave the select function in the client, so we wouldn't have to rebuild it all the time, but it would be harder to handle multiclients that way)
so here's the function i'm using:
Code:
Func SelectMob($id)
Local $pRemoteThread, $vBuffer, $loop, $result, $OPcode
; --- save the position of the allocated memory ---
$pRemoteMem = DllCall($kernel32, 'int', 'VirtualAllocEx', 'int', $mid, 'ptr', 0, 'int', 0x46, 'int', 0x1000, 'int', 0x40)
; --- build up the asm code ---
; 0046061D A1 6C3E9F00 MOV EAX,DWORD PTR DS:[9F3E6C]
; 00460622 57 PUSH EDI <---- EDI Contains Mob-ID
; 00460623 8B48 20 MOV ECX,DWORD PTR DS:[EAX+20]
; 00460626 81C1 EC000000 ADD ECX,0EC
; 0046062C E8 8F961800 CALL elementc.005E9CC0
$OPcode &= '60' ; pushad
$OPcode &= 'A1'&_hex($base) ; mov eax, [base]
$OPcode &= '68'&_hex($id) ; push mob-id
$OPcode &= '8B4820' ; mov ecx, [eax+0x20]
$OPcode &= '81C1'&_hex(0xEC) ; add ecx, 0xEC
$OPcode &= 'E8'&_hex($select_call-$pRemoteMem[0]-5-StringLen($OPcode)/2) ; call select_call
$OPcode &= '61' ; popad
$OPcode &= 'C3' ; retn
; --- enter the asm code to to a dllstruct, which can be used with WriteProcessMemory ---
$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
; --- now letz write the code from our dllstruct ---
DllCall($kernel32, 'int', 'WriteProcessMemory', 'int', $mid, 'int', $pRemoteMem[0], 'int', DllStructGetPtr($vBuffer), 'int', DllStructGetSize($vBuffer), 'int', 0)
; --- now we run the asm code we've just written ---
$hRemoteThread = DllCall($kernel32, 'int', 'CreateRemoteThread', 'int', $mid, 'int', 0, 'int', 0, 'int', $pRemoteMem[0], 'ptr', 0, 'int', 0, 'int', 0)
; --- wait till the thread did his job ---
Do
$result = DllCall('kernel32.dll', 'int', 'WaitForSingleObject', 'int', $hRemoteThread[0], 'int', 50)
Until $result[0] <> 258
; --- close everything we've opened ---
DllCall($kernel32, 'int', 'CloseHandle', 'int', $hRemoteThread[0])
DllCall($kernel32, 'ptr', 'VirtualFreeEx', 'hwnd', $mid, 'int', $pRemoteMem[0], 'int', 0, 'int', 0x8000)
Return True
EndFunc
now that we're able to list, filter and select mobs, we need to kill the selected mobs.
to do that, we can use simple keypressing, or find the skill function in the client.
the skillfunction looks like this:
Code:
;~ Skill
;~ 00463B2A |. 50 PUSH EAX ; /Arg4 = Skill-ID
;~ 00463B2B |. 8B42 08 MOV EAX,DWORD PTR DS:[EDX+8] ; |[EDX+8] constains Skill-SN
;~ 00463B2E |. 6A 01 PUSH 1 ; |Arg3 = 00000001
;~ 00463B30 |. 51 PUSH ECX ; |Arg2 = 00000000
;~ 00463B31 |. 8B0D 6C3E9F00 MOV ECX,DWORD PTR DS:[9F3E6C] ; |elementc.009F44F0
;~ 00463B37 |. 50 PUSH EAX ; |Arg1 = Skill-SN
;~ 00463B38 |. 8B49 20 MOV ECX,DWORD PTR DS:[ECX+20] ; |ecx = [[base] + 0x20]
;~ 00463B3B |. 81C1 EC000000 ADD ECX,0EC ; |ecx += 20
;~ 00463B41 |. E8 EA621800 CALL elementc.005E9E30 ; \elementc.005E9E30
we can simply use it in the same way we've used the select function.
the Skill SNs are stored in the skillstr.txt
well since this is not a how-do-i-code-a-bot-which-ruins-the-game thread, i will not explain how to list all skills and get the needed skill ids.
same can be done for looting btw.