; # - GetPlayerHealth() Ermittelt die HP des Spielers #
; # - GetPlayerArmor() Ermittelt den Rüstungswert des Spielers #
HP := GetPlayerHealth() / 80000 ; Hier wird dein HP also 8000000 Geteiltdruch 80000 gerechnet.
HP2 := Round(HP, 0)
SendChat(HP2)
GetPlayerHealth() {
if(!checkHandles())
return -1
dwCPedPtr := readDWORD(hGTA, ADDR_CPED_PTR)
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return -1
}
dwAddr := dwCPedPtr + ADDR_CPED_HPOFF
fHealth := readFloat(hGTA, dwAddr)
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return -1
}
ErrorLevel := ERROR_OK
return Round(fHealth)
}
GetPlayerArmor() {
if(!checkHandles())
return -1
dwCPedPtr := readDWORD(hGTA, ADDR_CPED_PTR)
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return -1
}
dwAddr := dwCPedPtr + ADDR_CPED_ARMOROFF
fHealth := readFloat(hGTA, dwAddr)
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return -1
}
ErrorLevel := ERROR_OK
return Round(fHealth)
}
; ##### Sonstiges #####
checkHandles() {
if (iRefreshHandles + 500 > A_TickCount)
return true
if (!refreshGTA() || !refreshSAMP() || !refreshMemory())
return false
iRefreshHandles := A_TickCount
return true
}
; internal stuff
refreshGTA() {
newPID := getPID("GTA:SA:MP")
if(!newPID) { ; GTA not found
if(hGTA) { ; open handle
virtualFreeEx(hGTA, pMemory, 0, 0x8000)
closeProcess(hGTA)
hGTA := 0x0
}
dwGTAPID := 0
hGTA := 0x0
dwSAMP := 0x0
pMemory := 0x0
return false
}
if(!hGTA || (dwGTAPID != newPID)) { ; changed PID, closed handle
hGTA := openProcess(newPID)
if(ErrorLevel) { ; openProcess fail
dwGTAPID := 0
hGTA := 0x0
dwSAMP := 0x0
pMemory := 0x0
return false
}
dwGTAPID := newPID
dwSAMP := 0x0
pMemory := 0x0
return true
}
return true
}
; internal stuff
refreshSAMP() {
if(dwSAMP)
return true
dwSAMP := getModuleBaseAddress("samp.dll", hGTA)
if(!dwSAMP)
return false
versionByte := readMem(hGTA, dwSAMP + 0x1036, 1, "UChar")
sampVersion := versionByte == 0xD8 ? 1 : (versionByte == 0xA8 ? 2 : (versionByte == 0x78 ? 3 : 0))
if (!sampVersion)
return false
return true
}
; internal stuff
refreshMemory() {
if(!pMemory) {
pMemory := virtualAllocEx(hGTA, 6144, 0x1000 | 0x2000, 0x40)
if(ErrorLevel) {
pMemory := 0x0
return false
}
pParam1 := pMemory
pParam2 := pMemory + 1024
pParam3 := pMemory + 2048
pParam4 := pMemory + 3072
pParam5 := pMemory + 4096
pInjectFunc := pMemory + 5120
}
return true
}
; internal stuff
getPID(szWindow) {
local dwPID := 0
WinGet, dwPID, PID, %szWindow%
return dwPID
}
; internal stuff
openProcess(dwPID, dwRights = 0x1F0FFF) {
hProcess := DllCall("OpenProcess"
, "UInt", dwRights
, "int", 0
, "UInt", dwPID
, "Uint")
if(hProcess == 0) {
ErrorLevel := ERROR_OPEN_PROCESS
return 0
}
ErrorLevel := ERROR_OK
return hProcess
}
; internal stuff
closeProcess(hProcess) {
if(hProcess == 0) {
ErrorLevel := ERROR_INVALID_HANDLE
return 0
}
dwRet := DllCall( "CloseHandle"
, "Uint", hProcess
, "UInt")
ErrorLevel := ERROR_OK
}
; internal stuff
getModuleBaseAddress(sModule, hProcess) {
if(!sModule) {
ErrorLevel := ERROR_MODULE_NOT_FOUND
return 0
}
if(!hProcess) {
ErrorLevel := ERROR_INVALID_HANDLE
return 0
}
dwSize = 1024*4 ; 1024 * sizeof(HMODULE = 4)
VarSetCapacity(hMods, dwSize)
VarSetCapacity(cbNeeded, 4) ; DWORD = 4
dwRet := DllCall( "Psapi.dll\EnumProcessModules"
, "UInt", hProcess
, "UInt", &hMods
, "UInt", dwSize
, "UInt*", cbNeeded
, "UInt")
if(dwRet == 0) {
ErrorLevel := ERROR_ENUM_PROCESS_MODULES
return 0
}
dwMods := cbNeeded / 4 ; cbNeeded / sizeof(HMDOULE = 4)
i := 0
VarSetCapacity(hModule, 4) ; HMODULE = 4
VarSetCapacity(sCurModule, 260) ; MAX_PATH = 260
while(i < dwMods) {
hModule := NumGet(hMods, i*4)
DllCall("Psapi.dll\GetModuleFileNameEx"
, "UInt", hProcess
, "UInt", hModule
, "Str", sCurModule
, "UInt", 260)
SplitPath, sCurModule, sFilename
if(sModule == sFilename) {
ErrorLevel := ERROR_OK
return hModule
}
i := i + 1
}
ErrorLevel := ERROR_MODULE_NOT_FOUND
return 0
}
; internal stuff
readString(hProcess, dwAddress, dwLen) {
if(!hProcess) {
ErrorLevel := ERROR_INVALID_HANDLE
return 0
}
VarSetCapacity(sRead, dwLen)
dwRet := DllCall( "ReadProcessMemory"
, "UInt", hProcess
, "UInt", dwAddress
, "Str", sRead
, "UInt", dwLen
, "UInt*", 0
, "UInt")
if(dwRet == 0) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
ErrorLevel := ERROR_OK
if A_IsUnicode
return __ansiToUnicode(sRead)
return sRead
}
; internal stuff
readFloat(hProcess, dwAddress) {
if(!hProcess) {
ErrorLevel := ERROR_INVALID_HANDLE
return 0
}
VarSetCapacity(dwRead, 4) ; float = 4
dwRet := DllCall( "ReadProcessMemory"
, "UInt", hProcess
, "UInt", dwAddress
, "Str", dwRead
, "UInt", 4
, "UInt*", 0
, "UInt")
if(dwRet == 0) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
ErrorLevel := ERROR_OK
return NumGet(dwRead, 0, "Float")
}
; internal stuff
readDWORD(hProcess, dwAddress) {
if(!hProcess) {
ErrorLevel := ERROR_INVALID_HANDLE
return 0
}
VarSetCapacity(dwRead, 4) ; DWORD = 4
dwRet := DllCall( "ReadProcessMemory"
, "UInt", hProcess
, "UInt", dwAddress
, "Str", dwRead
, "UInt", 4
, "UInt*", 0)
if(dwRet == 0) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
ErrorLevel := ERROR_OK
return NumGet(dwRead, 0, "UInt")
}
; internal stuff
readMem(hProcess, dwAddress, dwLen=4, type="UInt") {
if(!hProcess) {
ErrorLevel := ERROR_INVALID_HANDLE
return 0
}
VarSetCapacity(dwRead, dwLen)
dwRet := DllCall( "ReadProcessMemory"
, "UInt", hProcess
, "UInt", dwAddress
, "Str", dwRead
, "UInt", dwLen
, "UInt*", 0)
if(dwRet == 0) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
ErrorLevel := ERROR_OK
return NumGet(dwRead, 0, type)
}
; internal stuff
writeString(hProcess, dwAddress, wString) {
if(!hProcess) {
ErrorLevel := ERROR_INVALID_HANDLE
return false
}
sString := wString
if A_IsUnicode
sString := __unicodeToAnsi(wString)
dwRet := DllCall( "WriteProcessMemory"
, "UInt", hProcess
, "UInt", dwAddress
, "Str", sString
, "UInt", StrLen(wString) + 1
, "UInt", 0
, "UInt")
if(dwRet == 0) {
ErrorLEvel := ERROR_WRITE_MEMORY
return false
}
ErrorLevel := ERROR_OK
return true
}
; internal stuff
writeRaw(hProcess, dwAddress, pBuffer, dwLen) {
if(!hProcess) {
ErrorLevel := ERROR_INVALID_HANDLE
return false
}
dwRet := DllCall( "WriteProcessMemory"
, "UInt", hProcess
, "UInt", dwAddress
, "UInt", pBuffer
, "UInt", dwLen
, "UInt", 0
, "UInt")
if(dwRet == 0) {
ErrorLEvel := ERROR_WRITE_MEMORY
return false
}
ErrorLevel := ERROR_OK
return true
}
; internal stuff
Memory_ReadByte(process_handle, address) {
VarSetCapacity(value, 1, 0)
DllCall("ReadProcessMemory", "UInt", process_handle, "UInt", address, "Str", value, "UInt", 1, "UInt *", 0)
return, NumGet(value, 0, "Byte")
}
; internal stuff
callWithParams(hProcess, dwFunc, aParams, bCleanupStack = true) {
if(!hProcess) {
ErrorLevel := ERROR_INVALID_HANDLE
return false
}
validParams := 0
i := aParams.MaxIndex()
; i * PUSH + CALL + RETN
dwLen := i * 5 + 5 + 1
if(bCleanupStack)
dwLen += 3
VarSetCapacity(injectData, i * 5 + 5 + 3 + 1, 0)
i_ := 1
while(i > 0) {
if(aParams[i][1] != "") {
dwMemAddress := 0x0
if(aParams[i][1] == "p") {
dwMemAddress := aParams[i][2]
} else if(aParams[i][1] == "s") {
if(i_>3)
return false
dwMemAddress := pParam%i_%
writeString(hProcess, dwMemAddress, aParams[i][2])
if(ErrorLevel)
return false
i_ += 1
} else if(aParams[i][1] == "i") {
dwMemAddress := aParams[i][2]
} else {
return false
}
NumPut(0x68, injectData, validParams * 5, "UChar")
NumPut(dwMemAddress, injectData, validParams * 5 + 1, "UInt")
validParams += 1
}
i -= 1
}
offset := dwFunc - ( pInjectFunc + validParams * 5 + 5 )
NumPut(0xE8, injectData, validParams * 5, "UChar")
NumPut(offset, injectData, validParams * 5 + 1, "Int")
if(bCleanupStack) {
NumPut(0xC483, injectData, validParams * 5 + 5, "UShort")
NumPut(validParams*4, injectData, validParams * 5 + 7, "UChar")
NumPut(0xC3, injectData, validParams * 5 + 8, "UChar")
} else {
NumPut(0xC3, injectData, validParams * 5 + 5, "UChar")
}
writeRaw(hGTA, pInjectFunc, &injectData, dwLen)
if(ErrorLevel)
return false
hThread := createRemoteThread(hGTA, 0, 0, pInjectFunc, 0, 0, 0)
if(ErrorLevel)
return false
waitForSingleObject(hThread, 0xFFFFFFFF)
closeProcess(hThread)
return true
}
; internal stuff
virtualAllocEx(hProcess, dwSize, flAllocationType, flProtect) {
if(!hProcess) {
ErrorLevel := ERROR_INVALID_HANDLE
return 0
}
dwRet := DllCall( "VirtualAllocEx"
, "UInt", hProcess
, "UInt", 0
, "UInt", dwSize
, "UInt", flAllocationType
, "UInt", flProtect
, "UInt")
if(dwRet == 0) {
ErrorLEvel := ERROR_ALLOC_MEMORY
return 0
}
ErrorLevel := ERROR_OK
return dwRet
}
; internal stuff
virtualFreeEx(hProcess, lpAddress, dwSize, dwFreeType) {
if(!hProcess) {
ErrorLevel := ERROR_INVALID_HANDLE
return 0
}
dwRet := DllCall( "VirtualFreeEx"
, "UInt", hProcess
, "UInt", lpAddress
, "UInt", dwSize
, "UInt", dwFreeType
, "UInt")
if(dwRet == 0) {
ErrorLEvel := ERROR_FREE_MEMORY
return 0
}
ErrorLevel := ERROR_OK
return dwRet
}
; internal stuff
createRemoteThread(hProcess, lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId) {
if(!hProcess) {
ErrorLevel := ERROR_INVALID_HANDLE
return 0
}
dwRet := DllCall( "CreateRemoteThread"
, "UInt", hProcess
, "UInt", lpThreadAttributes
, "UInt", dwStackSize
, "UInt", lpStartAddress
, "UInt", lpParameter
, "UInt", dwCreationFlags
, "UInt", lpThreadId
, "UInt")
if(dwRet == 0) {
ErrorLEvel := ERROR_ALLOC_MEMORY
return 0
}
ErrorLevel := ERROR_OK
return dwRet
}
; internal stuff
waitForSingleObject(hThread, dwMilliseconds) {
if(!hThread) {
ErrorLevel := ERROR_INVALID_HANDLE
return 0
}
dwRet := DllCall( "WaitForSingleObject"
, "UInt", hThread
, "UInt", dwMilliseconds
, "UInt")
if(dwRet == 0xFFFFFFFF) {
ErrorLEvel := ERROR_WAIT_FOR_OBJECT
return 0
}
ErrorLevel := ERROR_OK
return dwRet
}
; internal stuff
__ansiToUnicode(sString, nLen = 0) {
If !nLen
{
nLen := DllCall("MultiByteToWideChar"
, "Uint", 0
, "Uint", 0
, "Uint", &sString
, "int", -1
, "Uint", 0
, "int", 0)
}
VarSetCapacity(wString, nLen * 2)
DllCall("MultiByteToWideChar"
, "Uint", 0
, "Uint", 0
, "Uint", &sString
, "int", -1
, "Uint", &wString
, "int", nLen)
return wString
}
; internal stuff
__unicodeToAnsi(wString, nLen = 0) {
pString := wString + 1 > 65536 ? wString : &wString
If !nLen
{
nLen := DllCall("WideCharToMultiByte"
, "Uint", 0
, "Uint", 0
, "Uint", pString
, "int", -1
, "Uint", 0
, "int", 0
, "Uint", 0
, "Uint", 0)
}
VarSetCapacity(sString, nLen)
DllCall("WideCharToMultiByte"
, "Uint", 0
, "Uint", 0
, "Uint", pString
, "int", -1
, "str", sString
, "int", nLen
, "Uint", 0
, "Uint", 0)
return sString
}
Alles anzeigen