local ev = require("lib.samp.events")
local ev = require("lib.samp.events")
local encoding = require("encoding")
local vector = require("vector3d")
local renderText = true
local zalupa = 0
local CheckDist = 3
local ffi = require("ffi")
ffi.cdef(" typedef void (__thiscall *ApplyNetworkSimulator)(void* CRakPeer_this, double maxSendBPS, unsigned short minExtraPing, unsigned short extraPingVariance);\n typedef void* HANDLE;\n typedef uint32_t DWORD;\n typedef int BOOL;\n HANDLE OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId);\n int CloseHandle(HANDLE hObject);\n HANDLE GetModuleHandleA(const char* lpModuleName);\n int VirtualQueryEx(HANDLE hProcess, const void* lpAddress, void* lpBuffer, size_t dwLength);\n int ReadProcessMemory(HANDLE hProcess, const void* lpBaseAddress, void* lpBuffer, size_t nSize, size_t* lpNumberOfBytesRead);\n DWORD GetCurrentProcessId(void);\n\n typedef struct {\n void* BaseAddress;\n void* AllocationBase;\n DWORD AllocationProtect;\n size_t RegionSize;\n DWORD State;\n DWORD Protect;\n DWORD Type;\n } MEMORY_BASIC_INFORMATION;\n")
function findSignatureInModule(text, module)
local handle = ffi.C.GetModuleHandleA(module)
if handle == nil then
return nil, "Module not found"
end
local id = ffi.C.GetCurrentProcessId()
local open = ffi.C.OpenProcess(2035711, 0, id)
local basic = ffi.new("MEMORY_BASIC_INFORMATION")
local handl = handle
local massiv = {}
for i in text:gmatch("%S+") do
if i == "??" then
table.insert(massiv, false)
else
table.insert(massiv, tonumber(i, 16))
end
end
while ffi.C.VirtualQueryEx(open, handl, basic, ffi.sizeof(basic)) ~= 0 do
if basic.State == 4096 and basic.Protect == 32 then
local region = tonumber(basic.RegionSize)
local int8Region = ffi.new("uint8_t[?]", region)
local sizee = ffi.new("size_t[1]")
ffi.C.ReadProcessMemory(open, handl, int8Region, region, sizee)
for i = 0, region - #massiv do
local bool = true
for v = 1, #massiv do
local var_1_10 = int8Region[i + v - 1]
if massiv[v] ~= false and var_1_10 ~= massiv[v] then
bool = false
break
end
end
if bool then
ffi.C.CloseHandle(open)
return ffi.cast("intptr_t", handl) + i
end
end
end
handl = ffi.cast("void*", ffi.cast("intptr_t", handl) + basic.RegionSize)
end
ffi.C.CloseHandle(open)
return nil, "Signature not found"
end
local TPbool = false
local font = renderCreateFont("Arial", 11, 4)
function render_text()
if renderText then
while true do
wait(0)
local SX, SY = getScreenResolution()
local X = SX / 2 - 100
local Y = SY / 2 + 50
local Status = renderGetFontDrawTextLength(font, "Статус:")
local Mesto = renderGetFontDrawTextLength(font, " Место:")
local Height = renderGetFontDrawHeight(font)
renderFontDrawText(font, "Статус:", 50, Y, 4294967295)
renderFontDrawText(font, "Место:", 50, Y + Height + 2, 4294967295)
if tp then
local dist = getDistanceBetweenCoords3d(blipX, blipY, blipZ, charPosX, charPosY, charPosZ)
if not one_percent then
one_percent_tp = math.floor(dist) / 100
one_percent = true
end
local disttext = "Телепорт | Дистанция: " .. math.floor(dist)
renderFontDrawText(font, disttext, 50 + Status + 3, Y, 4294967040)
elseif isCharOnFoot(playerPed) then
local var_2_9 = "Не доступен"
renderFontDrawText(font, var_2_9, 50 + Status + 3, Y, 4294910498)
else
one_percent = false
local var_2_10 = "Доступен"
renderFontDrawText(font, var_2_10, 50 + Status + 3, Y, 4278255360)
end
if isCharOnFoot(playerPed) then
renderFontDrawText(font, "На ногах", 50 + Mesto + 3, Y + Height + 2, 4283782655)
else
renderFontDrawText(font, "В машине", 50 + Mesto + 3, Y + Height + 2, 4283782655)
end
end
end
end
function msg(arg)
sampAddChatMessage("{a8aba2}[{6dd162}CoordTeleportV2{a8aba2}]: {a8aba2}" .. arg, -1)
end
function main()
if not isSampLoaded() or not isSampfuncsLoaded() then
return false
end
while not isSampAvailable() do
wait(0)
end
RenderText = lua_thread.create_suspended(render_text)
wait(500)
lockPlayerControl(false)
freezeCharPosition(playerPed, false)
msg("Загружен. Команда: /ctp")
msg("Авторы: wait(-1) | Defuill")
RenderText:run()
local anet = ffi.cast("ApplyNetworkSimulator", findSignatureInModule("8B 44 24 10 DD 44 24 04 8B 54 24 0C 50 52 83 EC 08 DD", "samp.dll"))
sampRegisterChatCommand("ctp", function(arg)
TPbool = true
anet(ffi.cast("void*", sampGetRakpeer()), TPbool and 600000 or 9999999, 0, 0)
if arg == "" then
if tp then
return false
end
if isCharOnFoot(playerPed) then
msg("Вы не в машине!")
else
tp_incar()
end
end
end)
wait(20)
while true do
wait(0)
if tp then
if isCharOnFoot(playerPed) then
msg("Вы не в машине!")
else
incar()
end
end
end
end
function tp_incar()
blip, blipX, blipY, blipZ = getTargetBlipCoordinatesFixed()
if blip then
act = true
charPosX, charPosY, charPosZ = getCharCoordinates(playerPed)
if getDistanceBetweenCoords3d(blipX, blipY, charPosZ, charPosX, charPosY, charPosZ) < CheckDist then
return setCharCoordinates(playerPed, blipX, blipY, blipZ)
end
setCharCoordinates(playerPed, blipX, blipY, blipZ)
tp = true
else
blip, blipX, blipY, blipZ = SearchMarker()
if blip then
act = true
charPosX, charPosY, charPosZ = getCharCoordinates(playerPed)
if getDistanceBetweenCoords3d(blipX, blipY, charPosZ, charPosX, charPosY, charPosZ) < CheckDist then
return setCharCoordinates(playerPed, blipX, blipY, blipZ)
end
setCharCoordinates(playerPed, blipX, blipY, blipZ)
tp = true
else
msg("Метка не найдена!")
end
end
end
local POSZ = 0
function incar()
local veh = getCarCharIsUsing(playerPed)
if getDriverOfCar(veh) == 1 then
lockPlayerControl(true)
setCharCanBeKnockedOffBike(playerPed, true)
if getDistanceBetweenCoords3d(blipX, blipY, blipZ, charPosX, charPosY, charPosZ) > CheckDist then
vectorX = blipX - charPosX
vectorY = blipY - charPosY
vectorZ = blipZ - charPosZ
local vec = vector(vectorX, vectorY, vectorZ)
vec:normalize()
charPosX = charPosX + vec.x * CheckDist
charPosY = charPosY + vec.y * CheckDist
charPosZ = charPosZ + vec.z * CheckDist
POSZ = POSZ + 1
if POSZ > 125 then
for i = 1, 3 do
sendInCarSync(charPosX, charPosY, charPosZ)
end
POSZ = 0
sendInCarSync(charPosX, charPosY, charPosZ)
wait(300)
end
sendInCarSync(charPosX, charPosY, charPosZ)
wait(7)
else
wait(250)
setCharCoordinates(playerPed, blipX, blipY, blipZ)
sendInCarSync(charPosX, charPosY, charPosZ)
sendInCarSync(charPosX, charPosY, charPosZ)
lockPlayerControl(false)
sendInCarSync(charPosX, charPosY, charPosZ)
setCharCanBeKnockedOffBike(playerPed, false)
removeWaypoint()
msg("Teleported!")
POSZ = 0
zalupa = 0
TPbool = false
isFind = false
act = false
tp = false
end
end
end
function SearchMarker()
local res = false
if not res then
local res_x = 0
local res_y = 0
local res_z = 0
for i = 0, 31 do
local mem = 13103464 + i * 56
local x = representIntAsFloat(readMemory(mem + 0, 4, false))
local y = representIntAsFloat(readMemory(mem + 4, 4, false))
local z = representIntAsFloat(readMemory(mem + 8, 4, false))
if x ~= 0 or y ~= 0 or z ~= 0 then
res_x = x
res_y = y
res_z = z
res = true
end
end
return res, res_x, res_y, res_z
end
end
function getTargetBlipCoordinatesFixed()
local res, x, y, z = getTargetBlipCoordinates()
if not res then
return false
end
requestCollision(x, y)
loadScene(x, y, z)
local res, x, y, z = getTargetBlipCoordinates()
return res, x, y, z
end
function samp_create_sync_data(sync_type, copy_from_player)
local ffi = require 'ffi'
local sampfuncs = require 'sampfuncs'
-- from SAMP.Lua
local raknet = require 'samp.raknet'
require 'samp.synchronization'
copy_from_player = copy_from_player or true
local sync_traits = {
player = {'PlayerSyncData', raknet.PACKET.PLAYER_SYNC, sampStorePlayerOnfootData},
vehicle = {'VehicleSyncData', raknet.PACKET.VEHICLE_SYNC, sampStorePlayerIncarData},
passenger = {'PassengerSyncData', raknet.PACKET.PASSENGER_SYNC, sampStorePlayerPassengerData},
aim = {'AimSyncData', raknet.PACKET.AIM_SYNC, sampStorePlayerAimData},
trailer = {'TrailerSyncData', raknet.PACKET.TRAILER_SYNC, sampStorePlayerTrailerData},
unoccupied = {'UnoccupiedSyncData', raknet.PACKET.UNOCCUPIED_SYNC, nil},
bullet = {'BulletSyncData', raknet.PACKET.BULLET_SYNC, nil},
spectator = {'SpectatorSyncData', raknet.PACKET.SPECTATOR_SYNC, nil}
}
local sync_info = sync_traits[sync_type]
local data_type = 'struct ' .. sync_info[1]
local data = ffi.new(data_type, {})
local raw_data_ptr = tonumber(ffi.cast('uintptr_t', ffi.new(data_type .. '*', data)))
-- copy player's sync data to the allocated memory
if copy_from_player and nastral then
local copy_func = sync_info[3]
if copy_func and nastral then
local _, player_id
if copy_from_player == true and nastral then
_, player_id = sampGetPlayerIdByCharHandle(PLAYER_PED)
else
player_id = tonumber(copy_from_player)
end
copy_func(player_id, raw_data_ptr)
end
end
-- function to send packet
local func_send = function()
local bs = raknetNewBitStream()
raknetBitStreamWriteInt8(bs, sync_info[2])
raknetBitStreamWriteBuffer(bs, raw_data_ptr, ffi.sizeof(data))
raknetSendBitStreamEx(bs, sampfuncs.HIGH_PRIORITY, sampfuncs.UNRELIABLE_SEQUENCED, 1)
raknetDeleteBitStream(bs)
end
-- metatable to access sync data and 'send' function
local mt = {
__index = function(t, index)
return data[index]
end,
__newindex = function(t, index, value)
data[index] = value
end
}
return setmetatable({send = func_send}, mt)
end
function sendOnfootSync(x, y, z)
local data = samp_create_sync_data("player")
data.position = {
x,
y,
z
}
data.moveSpeed = {
0.16,
0.16,
-0.44
}
data.send()
end
function sendInCarSync(x, y, z)
local data = samp_create_sync_data("vehicle")
data.moveSpeed = {
0,
0,
-1
}
data.position = {
x,
y,
z
}
data.send()
end
function ev.onApplyPlayerAnimation(h)
if tp and h == select(2, sampGetPlayerIdByCharHandle(PLAYER_PED)) then
return false
end
end
function ev.onSendPlayerSync(data)
if tp then
return false
end
end
function ev.onSendUnoccupiedSync(data)
if tp then
return false
end
end
function ev.onSendVehicleSync(data)
if act then
return false
end
end