Skip to content

Instantly share code, notes, and snippets.

@khorevaa
Created January 17, 2017 18:41
Show Gist options
  • Save khorevaa/20db64cc42f91ff1b46d17093667ab8e to your computer and use it in GitHub Desktop.
Save khorevaa/20db64cc42f91ff1b46d17093667ab8e to your computer and use it in GitHub Desktop.
@eskhatov
Copy link

;UDF R3 CRMP

global hGTA := 0x0
global dwGTAPID := 0x0
global dwSAMP := 0x0
global pMemory := 0x0
global pParam1 := 0x0
global pParam2 := 0x0
global pParam3 := 0x0
global pParam4 := 0x0
global pParam5 := 0x0
global pInjectFunc := 0x0
global iRefreshHandles := 0
global pInjectFunc := 0x0
global nZone := 1
global nCity := 1
global bInitZaC := 0
global iRefreshScoreboard := 0
global oScoreboardData := ""
global iRefreshHandles := 0
global iUpdateTick := 2500
global bCheckSizeOnce := 1

global SAMP_INFO_OFFSET := 0x21A0F8
global SAMP_PPOOLS_OFFSET := 0x3CD
global SAMP_PPOOL_PLAYER_OFFSET := 0x18
global SAMP_SLOCALPLAYERID_OFFSET := 0x4
global SAMP_ISTRLEN_LOCALPLAYERNAME_OFFSET := 0x1A
global SAMP_SZLOCALPLAYERNAME_OFFSET := 0xA
global SAMP_PSZLOCALPLAYERNAME_OFFSET := 0xA
global SAMP_PREMOTEPLAYER_OFFSET := 0x2E
global SAMP_ISTRLENNAME___OFFSET := 0x1C
global SAMP_SZPLAYERNAME_OFFSET := 0xC
global SAMP_PSZPLAYERNAME_OFFSET := 0xC
global SAMP_ILOCALPLAYERPING_OFFSET := 0x26
global SAMP_ILOCALPLAYERSCORE_OFFSET := 0x2A
global SAMP_IPING_OFFSET := 0x28
global SAMP_ISCORE_OFFSET := 0x24
global SAMP_ISNPC_OFFSET := 0x4
global SAMP_SZIP_OFFSET := 0x20
global SAMP_SZHOSTNAME_OFFSET := 0x121

global SAMP_PLAYER_MAX := 1004
global SIZE_SAMP_CHATMSG := 0xFC

; SAMP Addresses
global ADDR_SAMP_INCHAT_PTR := 0x21A10C
global ADDR_SAMP_INCHAT_PTR_OFF := 0x55
global ADDR_SAMP_USERNAME := 0x219A6F
global ADDR_SAMP_CHATMSG_PTR := 0x21A0E4
global ADDR_SAMP_SHOWDLG_PTR := 0x21A0B8
global FUNC_SAMP_SENDCMD := 0x698C0
global FUNC_SAMP_SENDSAY := 0x5A00
global FUNC_SAMP_ADDTOCHATWND := 0x64520
global FUNC_SAMP_SHOWGAMETEXT := 0x9C2C0
global FUNC_SAMP_PLAYAUDIOSTR := 0x62DA0
global FUNC_SAMP_STOPAUDIOSTR := 0x629A0
global FUNC_SAMP_SHOWDIALOG := 0x6B9C0
global FUNC_UPDATESCOREBOARD := 0x8A10

; GTA Addresses
global ADDR_ZONECODE := 0xA49AD4
global ADDR_POSITION_X := 0xB6F2E4
global ADDR_POSITION_Y := 0xB6F2E8
global ADDR_POSITION_Z := 0xB6F2EC
global ADDR_CPED_PTR := 0xB6F5F0
global ADDR_CPED_HPOFF := 0x540
global ADDR_CPED_ARMOROFF := 0x548
global ADDR_VEHICLE_PTR := 0xBA18FC
global ADDR_VEHICLE_HPOFF := 0x4C0
global ADDR_CPED_MONEY := 0xB7CE50
global ADDR_CPED_INTID := 0xA4ACE8
global ADDR_VEHICLE_DOORSTATE := 0x4F8
global ADDR_VEHICLE_ENGINESTATE := 0x428
global ADDR_VEHICLE_LIGHTSTATE := 0x584
global ADDR_VEHICLE_MODEL := 0x22
global ADDR_VEHICLE_TYPE := 0x590
global ADDR_VEHICLE_DRIVER := 0x460

global ERROR_OK := 0
global ERROR_PROCESS_NOT_FOUND := 1
global ERROR_OPEN_PROCESS := 2
global ERROR_INVALID_HANDLE := 3
global ERROR_MODULE_NOT_FOUND := 4
global ERROR_ENUM_PROCESS_MODULES := 5
global ERROR_ZONE_NOT_FOUND := 6
global ERROR_CITY_NOT_FOUND := 7
global ERROR_READ_MEMORY := 8
global ERROR_WRITE_MEMORY := 9
global ERROR_ALLOC_MEMORY := 10
global ERROR_FREE_MEMORY := 11
global ERROR_WAIT_FOR_OBJECT := 12
global ERROR_CREATE_THREAD := 13

global DIALOG_STYLE_MSGBOX := 0
global DIALOG_STYLE_INPUT := 1
global DIALOG_STYLE_LIST := 2
global DIALOG_STYLE_PASSWORD := 3
global DIALOG_STYLE_TABLIST := 4
global DIALOG_STYLE_TABLIST_HEADERS := 5

global SAMP_DIALOG_PTR1_OFFSET := 0x1C
global SAMP_DIALOG_LINES_OFFSET := 0x44C
global SAMP_DIALOG_INDEX_OFFSET := 0x443
global SAMP_DIALOG_BUTTON_HOVERING_OFFSET := 0x465
global SAMP_DIALOG_BUTTON_CLICKED_OFFSET := 0x466
global SAMP_DIALOG_PTR2_OFFSET := 0x20
global SAMP_DIALOG_LINECOUNT_OFFSET := 0x150
global SAMP_DIALOG_OPEN_OFFSET := 0x28
global SAMP_DIALOG_STYLE_OFFSET := 0x2C
global SAMP_DIALOG_ID_OFFSET := 0x30
global SAMP_DIALOG_TEXT_PTR_OFFSET := 0x34
global SAMP_DIALOG_CAPTION_OFFSET := 0x40
global SAMP_PLAYER_MAX := 1004
global SAMP_KILLSTAT_OFFSET := 0x21A0EC
global multVehicleSpeed_tick := 0
global CheckpointCheck := 0xC7DEEA
global rmaddrs := [0xC7DEC8, 0xC7DECC, 0xC7DED0]

findChatLine(text, fLines=10) { ; fLines - сколько попыток поиска (снизу вверх), по-умолчанию 10.
line_index = -1
loop, % fLines
{
line_index += 1
line_text := GetChatLine(line_index)
if line_text contains %text%
{
finded = 1
break
}
}

if finded
	return line_text
else
	return 0

}

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

}
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

}
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

}
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

}
getDist(pos1,pos2) {
if(!pos1 || !pos2)
return 0
return Sqrt((pos1[1]-pos2[1])(pos1[1]-pos2[1])+(pos1[2]-pos2[2])(pos1[2]-pos2[2])+(pos1[3]-pos2[3])(pos1[3]-pos2[3]))
}
callWithParams(hProcess, dwFunc, aParams, bCleanupStack = true, thiscall = false) {
if (!hProcess) {
ErrorLevel := ERROR_INVALID_HANDLE
return false
}
validParams := 0
i := aParams.MaxIndex()
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((thiscall && i == 1 ? 0xB9 : 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
}
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

}
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

}
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)

}
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")

}
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")

}
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

}

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

}
closeProcess(hProcess) {
if (hProcess == 0) {
ErrorLevel := ERROR_INVALID_HANDLE
return 0
}

dwRet := DllCall("CloseHandle", "Uint", hProcess, "UInt")
ErrorLevel := ERROR_OK

}
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

}
getPID() {
local dwPID := 0
WinGet, dwPID, PID, GTA:SA:MP
return dwPID
}
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
}
refreshSAMP() {
if (dwSAMP)
return true

dwSAMP := getModuleBaseAddress("samp.dll", hGTA)
if (!dwSAMP) return false

return true

}
refreshGTA() {
newPID := getPID()
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

}
checkHandles() {
if (iRefreshHandles+500>A_TickCount)
return true

iRefreshHandles:=A_TickCoun
dwSAMP := getModuleBaseAddress("samp.dll", hGTA)
return (refreshGTA() && refreshSAMP() && refreshMemory())

}
writeMemory(hProcess, address, writevalue,length=4, datatype="int") {
if (!hProcess) {
ErrorLevel := ERROR_INVALID_HANDLE
return false
}

VarSetCapacity(finalvalue,length, 0)
NumPut(writevalue,finalvalue,0,datatype)
dwRet := DllCall("WriteProcessMemory", "Uint", hProcess, "Uint", address, "Uint", &finalvalue, "Uint", length, "Uint", 0)
if (dwRet == 0) {
	ErrorLevel := ERROR_WRITE_MEMORY
	return false
}
ErrorLevel := ERROR_OK
return true

}
writeByte(hProcess, dwAddress, wInt) {
if (!hProcess) {
ErrorLevel := ERROR_INVALID_HANDLE
return false
}
wInt := IntToHex(wInt)
dwRet := DllCall("WriteProcessMemory", "UInt", hProcess, "UInt", dwAddress, "UInt *", wInt, "UInt", 1, "UInt *", 0)
}
FloatToHex(value) {
format := A_FormatInteger
SetFormat, Integer, H
result := DllCall("MulDiv", Float, value, Int, 1, Int, 1, UInt)
SetFormat, Integer, %format%
return, result
}

IntToHex(int) {
CurrentFormat := A_FormatInteger
SetFormat, integer, hex
int += 0
SetFormat, integer, %CurrentFormat%
return int
}
writeFloat(hProcess, dwAddress, wFloat) {
if (!hProcess) {
ErrorLevel := ERROR_INVALID_HANDLE
return false
}
wFloat := FloatToHex(wFloat)
dwRet := DllCall("WriteProcessMemory", "UInt", hProcess, "UInt", dwAddress, "UInt ", wFloat, "UInt", 4, "UInt ", 0)
ErrorLevel := ERROR_OK
return true
}
HexToDec(str) {
local newStr := ""
static comp := {0:0, 1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, "a":10, "b":11, "c":12, "d":13, "e":14, "f":15}
str := RegExReplace(str.down(str), "^0x|[^a-f0-9]+", "")
Loop, % StrLen(str)
newStr .= SubStr(str, (StrLen(str)-A_Index)+1, 1)
newStr := StrSplit(newStr, "")
local ret := 0
for i,char in newStr
ret += comp[char]
(16
*(i-1))
return ret
}
HexToDecOne(Hex) {
if (InStr(Hex, "0x") != 1)
Hex := "0x" Hex
return, Hex + 0
}
HexToDecTwo(hex) {
VarSetCapacity(dec, 66, 0),
val := DllCall("msvcrt.dll_wcstoui64", "Str", hex, "UInt", 0, "UInt", 16, "CDECL Int64"), DllCall("msvcrt.dll_i64tow", "Int64", val, "Str", dec, "UInt", 10, "CDECL")
return dec
}
hex2rgb(CR) {
NumPut((InStr(CR, "#") ? "0x" SubStr(CR, 2) : "0x") SubStr(CR, -5), (V := "000000"))
return NumGet(V, 2, "UChar") "," NumGet(V, 1, "UChar") "," NumGet(V, 0, "UChar")
}
rgb2hex(R, G, B, H := 1) {
static U := A_IsUnicode ? "_wcstoui64" : "_strtoui64"
static V := A_IsUnicode ? "_i64tow" : "_i64toa"
rgb := ((R << 16) + (G << 8) + B)
H := ((H = 1) ? "#" : ((H = 2) ? "0x" : ""))
VarSetCapacity(S, 66, 0)
value := DllCall("msvcrt.dll" U, "Str", rgb , "UInt", 0, "UInt", 10, "CDECL Int64")
DllCall("msvcrt.dll" V, "Int64", value, "Str", S, "UInt", 16, "CDECL")
return H S
}
writeBytes(handle, address, bytes) {
length := strlen(bytes) / 2
VarSetCapacity(toInject, length, 0)
Loop %length% {
byte := "0x" substr(bytes, ((A_Index - 1) * 2) + 1, 2)
NumPut(byte, toInject, A_Index - 1, "uchar")
}
return writeRaw(handle, address, &toInject, length)
}
__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
}
__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
}
Utf8ToAnsi(ByRef Utf8String, CodePage = 1251) {
if ((NumGet(Utf8String) & 0xFFFFFF) = 0xBFBBEF)
BOM = 3
else
BOM = 0
UniSize := DllCall("MultiByteToWideChar", "UInt", 65001, "UInt", 0, "UInt", &Utf8String + BOM, "Int", -1, "Int", 0, "Int", 0)
VarSetCapacity(UniBuf, UniSize * 2)
DllCall("MultiByteToWideChar", "UInt", 65001, "UInt", 0, "UInt", &Utf8String + BOM, "Int", -1, "UInt", &UniBuf, "Int", UniSize)
AnsiSize := DllCall("WideCharToMultiByte", "UInt", CodePage, "UInt", 0, "UInt", &UniBuf, "Int", -1, "Int", 0, "Int", 0, "Int", 0, "Int", 0)
VarSetCapacity(AnsiString, AnsiSize)
DllCall("WideCharToMultiByte", "UInt", CodePage, "UInt", 0, "UInt", &UniBuf, "Int", -1, "Str", AnsiString, "Int", AnsiSize, "Int", 0, "Int", 0)
return AnsiString
}

setGravity(state="0.008") {
if (!checkHandles())
return -1

return writeFloat(hGTA, 0x863984, state)

}

setCoordinates(pos1, pos2, pos3) {
if (!checkHandles())
return -1

dwAddress := isPlayerInAnyVehicle()
if (dwAddress == 0)
	dwAddress := readDWORD(hGTA, 0xB6F5F0)
dwAddress := readDWORD(hGTA, dwAddress + 0x14)

writeFloat(hGTA, dwAddress + 0x30, pos1)
writeFloat(hGTA, dwAddress + 0x34, pos2)
writeFloat(hGTA, dwAddress + 0x38, pos3)

return true

}

getPlayerHealth() {
if (!checkHandles())
return -1

return readFloat(hGTA, readDWORD(hGTA, 0xB6F5F0) + 0x540)

}
getPlayerArmour() {
if (!checkHandles())
return -1

return readFloat(hGTA, readDWORD(hGTA, 0xB6F5F0) + 0x548)

}
getPlayerMoney() {
if (!checkHandles())
return -1

return readDWORD(hGTA, 0x0B7CE54)

}
getPlayerInteriorId() {
if (!checkHandles())
return -1

return readDWORD(hGTA, 0xA4ACE8)

}
getPlayerSkinId() {
if (!checkHandles())
return -1

return readMem(hGTA, readDWORD(hGTA, 0xB6F5F0) + 0x22, 2, "byte")

}
getPlayerWeaponId() {
if (!checkHandles())
return -1

return readDWORD(hGTA, 0xBAA410)

}

checkCRMP() {
IfWinNotActive, ahk_exe gta_sa.exe
return 0

return 1

}

; Функции чтения, связанные с текущим транспортом
isPlayerInAnyVehicle() {
if (!checkHandles())
return -1

return readDWORD(hGTA, 0xBA18FC)

}
getVehicleHealth() {
if (!checkHandles())
return -1

return readFloat(hGTA, readDWORD(hGTA, 0xBA18FC) + 0x4C0)

}
isPlayerDriver() {
if (!checkHandles())
return -1

return (readDWORD(hGTA, readDWORD(hGTA, 0xBA18FC) + 0x460) == readDWORD(hGTA, 0xB6F5F0))

}
getVehicleColor() {
if (!checkHandles())
return -1

dwAddress := isPlayerInAnyVehicle()
return [readMem(hGTA, dwAddress + 1076, 1, "byte"), readMem(hGTA, dwAddress + 1077, 1, "byte")]

}
getVehicleSpeed() {
if(!checkHandles())
return -1

dwAddress := isPlayerInAnyVehicle()

fSpeedX := readMem(hGTA, dwAddress + 0x44, 4, "float")
fSpeedY := readMem(hGTA, dwAddress + 0x48, 4, "float")
fSpeedZ := readMem(hGTA, dwAddress + 0x4C, 4, "float")

fVehicleSpeed := sqrt((fSpeedX * fSpeedX) + (fSpeedY * fSpeedY) + (fSpeedZ * fSpeedZ))
fVehicleSpeed := (fVehicleSpeed * 100) * 1.43

return Round(fVehicleSpeed)

}

; Функции, связанные с координатами
getCoordinates(ByRef x, ByRef y, ByRef z) {
if (!checkHandles())
return -1

dwAddress := isPlayerInAnyVehicle()
if (dwAddress == 0)
	dwAddress := readDWORD(hGTA, 0xB6F5F0)
dwAddress := readDWORD(hGTA, dwAddress + 0x14)

x := readFloat(hGTA, dwAddress + 0x30)
z := readFloat(hGTA, dwAddress + 0x34)
y := readFloat(hGTA, dwAddress + 0x38)

}
getPlayerCoordinates(ByRef x, ByRef y, ByRef z) {
if (!checkHandles())
return -1

dwAddress := readDWORD(hGTA, readDWORD(hGTA, 0xB6F5F0) + 0x14)

x := readFloat(hGTA, dwAddress + 0x30)
z := readFloat(hGTA, dwAddress + 0x34)
y := readFloat(hGTA, dwAddress + 0x38)

}
getCameraCoordinates() {
if (!checkHandles())
return -1

return readFloat(hGTA, 0xB6F9CC) "," readFloat(hGTA, 0xB6F9D0) "," readFloat(hGTA, 0xB6F9D4)

}

; Функции, связанные с модулем мультиплеера
addChatMessageEx(Color, Text) {
if (!checkHandles())
return -1

VarSetCapacity(data2, 4, 0)
NumPut(HexToDec(Color), data2, 0, "Int")

dwAddress := readDWORD(hGTA, dwSAMP + 0x26E8C8)
VarSetCapacity(data1, 4, 0)
NumPut(readDWORD(hGTA, dwAddress + 0x4), data1, 0, "Int") 
WriteRaw(hGTA, dwAddress + 0x4, &data2, 4)

callWithParams(hGTA, dwSAMP + 0x67970, [["p", readDWORD(hGTA, dwSAMP + 0x26E8C8)], ["s", "" Text]], true)
WriteRaw(hGTA, dwAddress + 0x4, &data1, 4)

}

sendChat(Text) {
if (!checkHandles())
return -1

dwFunc := 0
if (SubStr(Text, 1, 1) == "/") {
	dwFunc := dwSAMP + 0x69190
} else {
	dwFunc := dwSAMP + 0x5820
}

callWithParams(hGTA, dwFunc, [["s", "" Text]], false)

}

isInChat() {
if (!checkHandles())
return -1

return (readDWORD(hGTA, readDWORD(hGTA, dwSAMP + 0x26E8F4) + 0x61) > 0)

}

formatDialog(text, len=150) {
result := "", index := 0
loop, parse, text, % ""
{
index++
if A_LoopField = `n
index = 0

	result := result A_LoopField
	if (index = len) {
		result := result "`n"
		index = 0
	}
}
return result

}

showDialog(style, caption, text, button1, button2 := "", id := 1) {
style += 0
style := Floor(style)
id += 0
id := Floor(id)
caption := "" caption
text := "" text
button1 := "" button1
button2 := "" button2
text := formatdialog(text)

if (id < 0 || id > 32767 || style < 0 || style > 5 || StrLen(caption) > 64 || StrLen(text) > 4096 || StrLen(button1) > 10 || StrLen(button2) > 10)
	return false

if (!checkHandles())
	return -1

dwFunc := dwSAMP + 0x6F8C0
sleep 200
dwAddress := readDWORD(hGTA, dwSAMP + 0x26E898)
if (!dwAddress) {
	return -1
}

writeString(hGTA, pParam5, caption)
writeString(hGTA, pParam1, text)
writeString(hGTA, pParam5 + 512, button1)
writeString(hGTA, pParam5+StrLen(caption) + 1, button2)

dwLen := 5 + 7 * 5 + 5 + 1
VarSetCapacity(injectData, dwLen, 0)

NumPut(0xB9, injectData, 0, "UChar")
NumPut(dwAddress, injectData, 1, "UInt")
NumPut(0x68, injectData, 5, "UChar")
NumPut(1, injectData, 6, "UInt")
NumPut(0x68, injectData, 10, "UChar")
NumPut(pParam5 + StrLen(caption) + 1, injectData, 11, "UInt")
NumPut(0x68, injectData, 15, "UChar")
NumPut(pParam5 + 512, injectData, 16, "UInt")
NumPut(0x68, injectData, 20, "UChar")
NumPut(pParam1, injectData, 21, "UInt")
NumPut(0x68, injectData, 25, "UChar")
NumPut(pParam5, injectData, 26, "UInt")
NumPut(0x68, injectData, 30, "UChar")
NumPut(style, injectData, 31, "UInt")
NumPut(0x68, injectData, 35, "UChar")
NumPut(id, injectData, 36, "UInt")
NumPut(0xE8, injectData, 40, "UChar")
offset := dwFunc - (pInjectFunc + 45)
NumPut(offset, injectData, 41, "Int")
NumPut(0xC3, injectData, 45, "UChar")

writeRaw(hGTA, pInjectFunc, &injectData, dwLen)
hThread := createRemoteThread(hGTA, 0, 0, pInjectFunc, 0, 0, 0)

;waitForSingleObject(hThread, 0xFFFFFFFF)
closeProcess(hThread)

}

IsPlayerInRangeOfPoint(_posX, _posY, _posZ, _posRadius)
{
getPlayerCoordinates(posX, posY, posZ)
X := posX -_posX
Y := posY -_posY
Z := posZ -_posZ
if(((X < _posRadius) && (X > -_posRadius)) && ((Y < _posRadius) && (Y > -_posRadius)) && ((Z < _posRadius) && (Z > -_posRadius)))
return TRUE
return FALSE
}

setFireImmunity(state)
{
if(!checkHandles())
return
writeMemory(hGTA, 0xB7CEE6, (state ? 1 : 0), 1, "byte")
}

gmpatch()
{
if(!checkHandles())
return false
a := writeMemory(hGTA, 0x4B35A0, 0x560CEC83, 4, "int")
b := writeMemory(hGTA, 0x4B35A4, 0xF18B, 2, "byte")
return (a && b)
}

toggleNoDamageByWeapon(tog := -1)
{
if(!checkHandles())
return -1
byte := readMem(hGTA, 0x60A5BA, 1, "byte")
if((tog == -1 && byte == 216) || tog == true || tog == 1)
{
writeBytes(hGTA, 0x60A5BA, "909090")
return true
} else if((tog == -1 && byte == 144) || !tog)
{
writeBytes(hGTA, 0x60A5BA, "D95E18")
return false
}
addChatMessageEx(0xCC0000, "only for gta_sa.exe 1.0 us")
return -1
}

toggleInvulnerability(tog := -1)
{
if(!checkHandles())
return -1
byte := readMem(hGTA, 0x60A5BA, 1, "byte")
if((tog == -1 && byte == 217) || tog == true || tog == 1)
{
writeBytes(hGTA, 0x4B3314, "909090")
return true
} else if((tog == -1 && byte == 144) || !tog)
{
writeBytes(hGTA, 0x4B3314, "D86504")
return false
}
addChatMessageEx(0xCC0000, "only for gta_sa.exe 1.0 us")
return -1
}

getDialogCaption() {
if (!CheckHandles())
return -1

return readString(hGTA, dwSamp + 0x16e04aee, 512)

}

getDialogText() {
if (!CheckHandles())
return -1

return readString(hGTA, dwSamp + 0x2069a38, 512)

}

AntiPause() {
if(!checkHandles())
return false
writeBytes(hGTA, 0x747FB6, "01")
writeBytes(hGTA, 0x74805A, "01")
writeBytes(hGTA, 0x74542B, "90909090909090")
writeBytes(hGTA, 0x74542C, "90909090909090")
writeBytes(hGTA, 0x74542D, "909090909090")
return
}

GetChatLine(Line, timestamp=0, color=0){
FileRead, file, % path_chatlog
chatindex := 0
loop, Parse, file, n, r
{
if(A_LoopField)
chatindex := A_Index
}

loop, Parse, file, `n, `r
{
	if(A_Index = chatindex - line){
		output := A_LoopField
		break
	}
}

file := ""
if(!timestamp)
	output := RegExReplace(output, "U)^\[\d{2}:\d{2}:\d{2}\]")
if(!color)
	output := RegExReplace(output, "Ui)\{[a-f0-9]{6}\}")

return output

}

UnlockFps(status) {
if(!checkHandles())
return false
if (status = 1) {
dwSAMP := getModuleBaseAddress("samp.dll", hGTA)
writeMemory(hGTA, dwSAMP + 0x9D9D0, 1347550997, 4, "UInt")
}
if (status = 0) {
dwSAMP := getModuleBaseAddress("samp.dll", hGTA)
writeMemory(hGTA, dwSAMP + 0x9D9D0, 4294417384, 4, "UInt")
}
return
}

setInfiniteRun(state)
{
if(!checkHandles())
return
writeMemory(hGTA, 0xB7CEE4, (state ? 1 : 0), 1, "byte")
}

PauseGame(state="") ; 0 - leave, 1 - shows
{
if(!checkHandles())
return

if (state = "") {
	return readMem(hGTA, 0xB7CB49, 1, "byte")
}

return writeMemory(hGTA, 0xB7CB49, (state ? 1 : 0), 1, "byte")

}

PrintLow(text, time) {
;0x69F1E0 = PrintLowPriorityMessage(const char* text, int time_in_ms, int unknown1 = 1, int unknown2 = 1);
if(!checkHandles())
return -1
dwFunc := 0x69F1E0
callwithparams(hGta, dwFunc, [["s",text], ["i", time], ["i", 1], ["i", 1]], true)
}

setCarNitro() {
If(!checkHandles())
return -1
return writeMemory(hGTA, 0x969165, 0x1)
}

toggleMotionBlur(tog := -1)
{
if(!checkHandles())
return -1
byte := readMem(hGTA, 0x704E8A, 1, "byte")
if((tog == -1 && byte == 144) || tog == true || tog == 1)
{
writeBytes(hGTA, 0x704E8A, "E811E2FFFF")
return true
} else if((tog == -1 && byte == 232) || !tog)
{
writeBytes(hGTA, 0x704E8A, "9090909090")
return false
}
return -1
}

setTime(hour)
{
if(!checkHandles())
return
; disable gta setTime function
VarSetCapacity(nop, 6, 0)
Loop 6 {
NumPut(0x90, nop, A_INDEX-1, "UChar")
}
writeRaw(hGTA, 0x52D168, &nop, 6)

; set our own weather
VarSetCapacity(time, 1, 0)
NumPut(hour, time, 0, "Int")
writeRaw(hGTA, 0xB70153, &time, 1)

}

getWeatherID() {
if(!checkHandles())
return -1

dwGTA := getModuleBaseAddress("gta_sa.exe", hGTA)
WeatherID := readMem(hGTA, 0xC81320, 2, "byte")
if(ErrorLevel) {
    ErrorLevel := ERROR_READ_MEMORY
    return -1
}

ErrorLevel := ERROR_OK    
return WeatherID

}

setWeather(id)
{
if(!checkHandles())
return
VarSetCapacity(weather, 1, 0)
NumPut(id, weather, 0, "Int")
writeRaw(hGTA, 0xC81320, &weather, 1)
if(ErrorLevel)
return false

return true

}

setPlayerFreeze(status) {
if(!checkHandles())
return -1

dwCPed := readDWORD(hGTA, 0xB6F5F0)
if(ErrorLevel) {
    ErrorLevel := ERROR_READ_MEMORY
    return -1
}
dwAddr := dwCPed + 0x42 
writeString(hGTA, dwAddr, status)
if(ErrorLevel) {
	ErrorLevel := ERROR_WRITE_MEMORY
	return -1		
}     
ErrorLevel := ERROR_OK
return true

}

IsPlayerFreezed() {
if(!checkHandles())
return -1

dwGTA := getModuleBaseAddress("gta_sa.exe", hGTA)
IPF := readMem(hGTA, dwGTA + 0x690495, 2, "byte")    
if(ErrorLevel) {
    ErrorLevel := ERROR_READ_MEMORY
    return -1
}

ErrorLevel := ERROR_OK    
return IPF

}

IsInAfk() {
res := readMem(hGTA, 0xBA6748 + 0x5C)
WinGet, win, MinMax, ahk_exe gta_sa.exe
if ((res=0) and (win=-1)) or res=1
return 1

return 0

}

setPlayerHealth(amount) {
if(!checkHandles())
return -1

dwCPedPtr := readDWORD(hGTA, ADDR_CPED_PTR)
if(ErrorLevel) {
    ErrorLevel := ERROR_READ_MEMORY
    return -1
}

dwAddr := dwCPedPtr + ADDR_CPED_HPOFF
writeFloat(hGTA, dwAddr, amount)
if(ErrorLevel) {
    ErrorLevel := ERROR_READ_MEMORY
    return -1
}

ErrorLevel := ERROR_OK
return true

}

setPlayerArmor(amount) {
if(!checkHandles())
return -1

dwCPedPtr := readDWORD(hGTA, ADDR_CPED_PTR)
if(ErrorLevel) {
    ErrorLevel := ERROR_READ_MEMORY
    return -1
}

dwAddr := dwCPedPtr + ADDR_CPED_ARMOROFF
writeFloat(hGTA, dwAddr, amount)
if(ErrorLevel) {
    ErrorLevel := ERROR_READ_MEMORY
    return -1
}

ErrorLevel := ERROR_OK
return true

}

setVehicleHealth(amount) {
if(!checkHandles())
return -1

dwVehPtr := readDWORD(hGTA, ADDR_VEHICLE_PTR)
if(ErrorLevel) {
    ErrorLevel := ERROR_READ_MEMORY
    return -1
}

dwAddr := dwVehPtr + ADDR_VEHICLE_HPOFF
writeFloat(hGTA, dwAddr, amount)
if(ErrorLevel) {
    ErrorLevel := ERROR_READ_MEMORY
    return -1
}

ErrorLevel := ERROR_OK
return true

}

class sampCfg
{
fpslimit() {
loop, read, % path_cfg
{
RegExMatch(A_LoopReadLine, "fpslimit=(.*)", out)
if out1
return out1
}
}

multicore() {
	loop, read, % path_cfg
	{
		RegExMatch(A_LoopReadLine, "multicore=(.*)", out)
		if out1
			return out1
	}
}

audioproxyoff() {
	loop, read, % path_cfg
	{
		RegExMatch(A_LoopReadLine, "audioproxyoff=(.*)", out)
		if out1
			return out1
	}
}

pagesize() {
	loop, read, % path_cfg
	{
		RegExMatch(A_LoopReadLine, "pagesize=(.*)", out)
		if out1
			return out1
	}
}

fontsize() {
	loop, read, % path_cfg
	{
		RegExMatch(A_LoopReadLine, "fontsize=(.*)", out)
		if out1
			return out1
	}
}

timestamp() {
	loop, read, % path_cfg
	{
		RegExMatch(A_LoopReadLine, "timestamp=(.*)", out)
		if out1
			return out1
	}
}

disableheadmove() {
	loop, read, % path_cfg
	{
		RegExMatch(A_LoopReadLine, "disableheadmove=(.*)", out)
		if out1
			return out1
	}
}

}

class chat {
input(text, hide="") {
global
StringReplace, text, text, %w, {FFFFFF}, All StringReplace, text, text, %r, {FF6347}, All
StringReplace, text, text, %b, {4169E1}, All StringReplace, text, text, \n, n, All StringReplace, text, text, \r, r, All StringReplace, text, text, \t, `t, All

	if !hide
		showDialog(DIALOG_STYLE_INPUT, "{4169E1}" title, "{FFFFFF}" text, "Закрыть", button2 := "", id := "0")
	else
		showDialog(DIALOG_STYLE_PASSWORD, "{4169E1}" title, "{FFFFFF}" text, "Закрыть", button2 := "", id := "0")
	
	dialogInputText =
	dialogCaptured = 0
	
	SetTimer, _commandprocessor, off
	settimer, checkEnter, 1
	while dialogCaptured = 0
		continue
	
	settimer, checkEnter, off
	SetTimer, _commandprocessor, 1
	cancelDialog()
	
	if (trim(dialogInputText) = "") {
		return -1
	}
	
	return dialogInputText
}

show(text) {
	StringReplace, text, text, `%r, `{FF6347`}, All
	StringReplace, text, text, `%w, `{FFFFFF`}, All
	StringReplace, text, text, `%b, `{4169E1`}, All
	StringReplace, text, text, `%t, `{4169E1`}[GOS Helper]`{FFFFFF`}, All
	tmp_text := RegExReplace(text, "Ui)\{[a-f0-9]{6}\}")
	StringLen, len, tmp_text
	if len > 145
	{
		StringLeft, text, text, 145
		text = %text%...
	}
	return AddChatMessageEx(0xFFFFFFFF, text)
}

write(text) {
	if text = ERROR
		return
	
	ControlSend,, {F6}%text%{enter}, ahk_exe gta_sa.exe
}

send(text, forcibly=0) {
	if text = ERROR
		return
	
	chat_queue := chat_queue text "`n"
	tmp := text "`n"
	
	if forcibly = 1
	{
		if (chat_queue = tmp) {
			chat_queue()
			sleep 1100
		}
	}
	
	settimer, chat_queue, 1100
}

getQueueTime() {
	mstime := 0
	loop, parse, chat_queue, `n
		mstime+=1150
	
	return mstime
}

}

chat_queue() {
index = 0
loop, parse, chat_queue, n { index = 1 queue_text := A_LoopField StringReplace, chat_queue, chat_queue, % A_LoopField "n",,
break
}

if index = 0
	settimer, chat_queue, off
else
	SendChat(queue_text)

}

processDialog() {
global
ControlSend,, {space}, ahk_exe gta_sa.exe
sleep 100
dialogInputText := readString(hGTA, dwsamp + 0x141a78, 512)
cancelDialog()
return
}

cancelDialog() {
global
dialogCaptured = 1
ControlSend,, {enter}, ahk_exe gta_sa.exe
return
}

_commandprocessor() {
IfWinNotActive, ahk_exe gta_sa.exe
return

if (GetKeyState("Enter", "P")) {
	__CommandProcessor()
	return
}
return

}

checkEnter() {
IfWinNotActive, ahk_exe gta_sa.exe
return

if (GetKeyState("Enter", "P") or (GetKeyState("NumpadEnter", "P"))) {
	processDialog()
	return
}

if (GetKeyState("Escape", "P")) {
	cancelDialog()
	return
}
return

}

__CommandProcessor() {
while IsInChat()
continue

sleep 200
dwAddress := dwSamp + 0x141A78
chatInput := readString(hGTA, dwAddress, 512)

loop, parse, _cmds, `n
{
	cmdfield := "/" A_LoopField
	loop, parse, chatInput, % " "
	{
		if A_Index > 1
			continue
		
		if (str.up(cmdfield) = str.up(A_LoopField)) {
			sleep 500
			writeString(hGTA, dwAddress, "")
			goto, % "_cmd_" StrReplace(A_LoopField, "/")
		}
	}
}
return

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment