AutoHotKey获取魔兽基址,魔兽版本
采用的是进程快照的方式获取,
GetGameDllBaseAndPath(ByRef BasePath);返回魔兽基址,BasePath返回dll的路径
{
WinGet,pid,PID,ahk_class Warcraft III ;得到魔兽进程pid
GameBase := GetDLLBase(BasePath,"game.dll",pid) ;获取game.dll基址
if(GameBase=0)
{
GameBase := 0x6f000000
}
return %GameBase%
}
GetDllBase(ByRef BasePath,DllName, pid = 0)
{
TH32CS_SNAPMODULE := 0x00000008
INVALID_HANDLE_VALUE = -1
VarSetCapacity(me32, 548, 0)
NumPut(548, me32)
snapMod := DllCall("CreateToolhelp32Snapshot", "Uint", TH32CS_SNAPMODULE, "Uint", pid)
If (snapMod = INVALID_HANDLE_VALUE) {
Return 0
}
If (DllCall("Module32First", "Uint", snapMod, "Uint", &me32)){
while(DllCall("Module32Next", "Uint", snapMod, "Uint", &me32)) {
text := StrGet(&me32 + 32, "cp0") ;再加256可能为dll路径
;=StringLower, text, text
if(text =DllName)
{
BasePath :=StrGet(&me32 + 32 +256, "cp0")
DllCall("CloseHandle", "Uint", snapMod)
Return NumGet(&me32 + 20)
}
}
}
DllCall("CloseHandle", "Uint", snapMod)
Return 0
}
{
WinGet,pid,PID,ahk_class Warcraft III ;得到魔兽进程pid
GameBase := GetDLLBase(BasePath,"game.dll",pid) ;获取game.dll基址
if(GameBase=0)
{
GameBase := 0x6f000000
}
return %GameBase%
}
GetDllBase(ByRef BasePath,DllName, pid = 0)
{
TH32CS_SNAPMODULE := 0x00000008
INVALID_HANDLE_VALUE = -1
VarSetCapacity(me32, 548, 0)
NumPut(548, me32)
snapMod := DllCall("CreateToolhelp32Snapshot", "Uint", TH32CS_SNAPMODULE, "Uint", pid)
If (snapMod = INVALID_HANDLE_VALUE) {
Return 0
}
If (DllCall("Module32First", "Uint", snapMod, "Uint", &me32)){
while(DllCall("Module32Next", "Uint", snapMod, "Uint", &me32)) {
text := StrGet(&me32 + 32, "cp0") ;再加256可能为dll路径
;=StringLower, text, text
if(text =DllName)
{
BasePath :=StrGet(&me32 + 32 +256, "cp0")
DllCall("CloseHandle", "Uint", snapMod)
Return NumGet(&me32 + 20)
}
}
}
DllCall("CloseHandle", "Uint", snapMod)
Return 0
}
用上面的BasePath获取魔兽的版本
Version := GetWar3Version(BasePath)
GetWar3Version(BasePath)
{
FileGetVersion, veeersion, %BasePath% ;1.24.0.5841
StringTrimRight,veeersion,veeersion,5 ;1.24.0
StringReplace,veeersion,veeersion,.,,All ;1240
return veeersion
}
GetWar3Version(BasePath)
{
FileGetVersion, veeersion, %BasePath% ;1.24.0.5841
StringTrimRight,veeersion,veeersion,5 ;1.24.0
StringReplace,veeersion,veeersion,.,,All ;1240
return veeersion
}
关键是获取dll路径和 FileGetVersion