SlonPvpru

[ARZ] KladmanElite v0.2.2v

Aug 26th, 2020
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 61.72 KB | None | 0 0
  1. -- https://www.blast.hk/threads/61060/
  2.  
  3. script_author('Fomikus')
  4. script_version('0.2.2v')
  5.  
  6.  
  7.  
  8. --Require
  9. local dlstatus = require('moonloader').download_status
  10. local inicfg = require 'inicfg'
  11. local imgui     = require 'imgui'
  12. local samp = require("lib.samp.events")
  13. local encoding = require 'encoding'
  14. local vector = require 'vector3d'
  15. local memory = require 'memory'
  16. local ffi = require 'ffi'
  17. local effil = require 'effil'
  18. encoding.default = 'CP1251'
  19. local utf8 = encoding.UTF8
  20.  
  21. local qwords = ffi.typeof("uint64_t[?]")
  22. local dwords = ffi.typeof("uint32_t *")
  23. local cpuid_EAX_EDX = ffi.cast("__cdecl uint64_t (*)(uint32_t)", "\x53\x0F\xA2\x5B\xC3")
  24. local cpuid_EBX_ECX = ffi.cast("__cdecl uint64_t (*)(uint32_t)", "\x53\x0F\xA2\x91\x92\x93\x5B\xC3")
  25.  
  26. local function cpuid(n)
  27.    local arr = ffi.cast(dwords, qwords(2, cpuid_EAX_EDX(n), cpuid_EBX_ECX(n)))
  28.    return ffi.string(arr, 4), ffi.string(arr + 2, 4), ffi.string(arr + 3, 4), ffi.string(arr + 1, 4)
  29. end
  30.  
  31. local s1 = ""
  32. for n = 0x80000002, 0x80000004 do
  33.    local eax, ebx, ecx, edx = cpuid(n)
  34.    s1 = s1..eax..ebx..ecx..edx
  35. end
  36. s1 = s1:gsub("^%s+", ""):gsub("%z+$", "")
  37.  
  38. local eax, ebx, ecx, edx = cpuid(0)
  39. local s2 = ebx..edx..ecx
  40. s2 = s2:gsub("^%s+", ""):gsub("%z+$", "")
  41.  
  42. local ffi = require("ffi")
  43. ffi.cdef[[
  44.     int __stdcall GetVolumeInformationA(
  45.     const char* lpRootPathName,
  46.     char* lpVolumeNameBuffer,
  47.     uint32_t nVolumeNameSize,
  48.     uint32_t* lpVolumeSerialNumber,
  49.     uint32_t* lpMaximumComponentLength,
  50.     uint32_t* lpFileSystemFlags,
  51.     char* lpFileSystemNameBuffer,
  52.     uint32_t nFileSystemNameSize
  53.     );
  54. ]]
  55.  
  56. local function getSerialNumber()
  57.     local serial = ffi.new("unsigned long[1]", 0)
  58.     ffi.C.GetVolumeInformationA('C:\\', nil, 0, serial, nil, nil, nil, 0)
  59.     return serial[0]
  60. end
  61.  
  62. --Params
  63. local questions = {}
  64. local data1 = {}
  65. local WaitingAnswer = false
  66. local tag = '[{4C75A3}KladMan{ffb700}Elite{FFFFFF}] '
  67. local CurAnswer = ''
  68. local CurQuest = ''
  69. local Answered = false
  70. local searching = false
  71. local randoming = false
  72. local state = false
  73. local server = -1
  74. local join = 0
  75. local x, y, z = 0, 0, 0
  76. local tp, sync = false, false
  77. local text
  78. local server
  79. local charPosX
  80. local charPosY
  81. local charPosZ
  82. local ddist
  83. local packetCount = 0
  84. local startDist = 0
  85. local progress = 0
  86. local coords = {}
  87. local Addition = ''
  88. local text = ''
  89. local file = ''
  90. local searching = false
  91. local eating = false
  92. local enabled = false
  93. local sendvk = false
  94. local global_q = ''
  95.  
  96.  
  97. --Config
  98. local config = inicfg.load({
  99.     setting = {
  100.         rgb = true,
  101.         rgb_speed = 1,
  102.         key1 = 74,
  103.         key2 = 75,
  104.         mode = 1,
  105.         vk_id = 0,
  106.         vk_token = 'token',
  107.         auto_tp = true,
  108.         na_dno = true,
  109.         custom_dno = false,
  110.         dno_x = 0,
  111.         dno_y = 0,
  112.         dno_z = 0,
  113.         vk_alerts = true,
  114.         prize_alert = false,
  115.         klad_alert = false,
  116.         cant_answer = false,
  117.         auto_blip = true,
  118.         auto_answer = true,
  119.         kladman_cmd = 'shk',
  120.         kladman_cheatcode = 'IOP',
  121.         auto_yn = true,
  122.         auto_eat = true,
  123.         save_prize = true,
  124.         random_txt = false,
  125.         fogdist_dl = 101,
  126.         nick_alert = true,
  127.         tp_speed = 7.5,
  128.         spec_delay = 300,
  129.         tp_delay = 1,
  130.         double_spec = false
  131.     }
  132. }, "Fomikus/KladMan.ini")
  133.  
  134.  
  135. --imgui
  136. local auto_answer        = imgui.ImBool(config.setting.auto_answer)
  137. local cant_answer        = imgui.ImBool(config.setting.cant_answer)
  138. local double_spec        = imgui.ImBool(config.setting.double_spec)
  139. local prize_alert        = imgui.ImBool(config.setting.prize_alert)
  140. local nick_alert         = imgui.ImBool(config.setting.nick_alert)
  141. local random_txt         = imgui.ImBool(config.setting.random_txt)
  142. local save_prize         = imgui.ImBool(config.setting.save_prize)
  143. local klad_alert         = imgui.ImBool(config.setting.klad_alert)
  144. local custom_dno         = imgui.ImBool(config.setting.custom_dno)
  145. local auto_blip          = imgui.ImBool(config.setting.auto_blip)
  146. local vk_alerts          = imgui.ImBool(config.setting.vk_alerts)
  147. local fogdist_dl         = imgui.ImInt(config.setting.fogdist_dl)
  148. local tp_speed           = imgui.ImFloat(config.setting.tp_speed)
  149. local rgb_speed          = imgui.ImInt(config.setting.rgb_speed)
  150. local auto_eat           = imgui.ImBool(config.setting.auto_eat)
  151. local auto_tp            = imgui.ImBool(config.setting.auto_tp)
  152. local auto_yn            = imgui.ImBool(config.setting.auto_yn)
  153. local na_dno             = imgui.ImBool(config.setting.na_dno)
  154. local dno_x              = imgui.ImInt(config.setting.dno_x)
  155. local dno_y              = imgui.ImInt(config.setting.dno_y)
  156. local tp_delay           = imgui.ImInt(config.setting.tp_delay)
  157. local spec_delay         = imgui.ImInt(config.setting.spec_delay)
  158. local dno_z              = imgui.ImInt(config.setting.dno_z)
  159. local mode               = imgui.ImInt(config.setting.mode)
  160. local key1               = imgui.ImInt(config.setting.key1)
  161. local key2               = imgui.ImInt(config.setting.key2)
  162. local rgb                = imgui.ImBool(config.setting.rgb)
  163. local vk_id = imgui.ImInt(config.setting.vk_id)
  164. local kladman_cheatcode  = imgui.ImBuffer(256)
  165. local kladman_cmd        = imgui.ImBuffer(256)
  166. local vk_token           = imgui.ImBuffer(256)
  167. local main_window_state  = imgui.ImBool(false)
  168. local key = ''
  169. local url = 'https://api.vk.com/method/messages.getHistory?&user_id='..vk_id.v..'&access_token='..vk_token.v..'&v=5.80&count=1'
  170.  
  171. vk_token.v = tostring(config.setting.vk_token)
  172. kladman_cmd.v = tostring(config.setting.kladman_cmd)
  173. kladman_cheatcode.v = tostring(config.setting.kladman_cheatcode)
  174. local sms = '555'
  175. local vkladki = {
  176.     true,
  177.     false,
  178.     false,
  179.     false,
  180.     false,
  181.     false
  182. }
  183.  
  184.  
  185. function main()
  186.     if not isSampfuncsLoaded() or not isSampLoaded() then return end
  187.     while not isSampAvailable() do wait(0) end
  188.     ch_cr_directories()
  189.     style()
  190.     text = md5sumhexa(s1..' 1')..' '..md5sumhexa(getSerialNumber()..' 1')..' '..md5sumhexa(s2..' 1')
  191.     sampAddChatMessage(tag..'Ваш ключ: '..text, -1)
  192.     setClipboardText(text)
  193.     local file = LicFile('r')
  194.     if file then
  195.     for line in file:lines() do
  196.          key = line
  197.     end
  198.     file:close()
  199.     else
  200.     sampAddChatMessage(tag..'Файл лицензии не найден', -1)
  201.     key = 'net'
  202.     end
  203.     if key ~= tostring(md5sumhexa(md5sumhexa(s1..' 1')..' Ochko'..md5sumhexa(getSerialNumber()..' 1')..md5sumhexa(s2..' 1'))) then
  204.     thisScript():unload()
  205.     sampAddChatMessage(tag..'Привязка не обнаружена', -1)
  206.     end
  207.     if doesFileExist(getGameDirectory() .. '\\moonloader\\Fomikus\\resource\\logo1.jpg') and doesFileExist(getGameDirectory() .. '\\moonloader\\Fomikus\\resource\\logo2.jpg')  then
  208.         sampAddChatMessage(tag..'Успешно загружен', -1)
  209.         img2 = imgui.CreateTextureFromFile(getGameDirectory() .. "\\moonloader\\Fomikus\\resource\\logo1.jpg")
  210.         img1 = imgui.CreateTextureFromFile(getGameDirectory() .. "\\moonloader\\Fomikus\\resource\\logo2.jpg")
  211.     else
  212.         sampAddChatMessage(tag..'Зависимости не обнаружены', -1)
  213.         lua_thread.create(function()
  214.             url1 = 'https://sun7-6.userapi.com/c857028/v857028212/1df92b/e-qlTzYmrPM.jpg'
  215.             url2 = 'https://irecommend.ru/sites/default/files/product-images/956866/fNua3KXXi6yZZKg4kGnL0w.jpg'
  216.             downloadUrlToFile(url1, getGameDirectory() .. "\\moonloader\\Fomikus\\resource\\logo1.jpg", download_handler)
  217.             downloadUrlToFile(url2, getGameDirectory() .. "\\moonloader\\Fomikus\\resource\\logo2.jpg", download_handler)
  218.         end)
  219.     end
  220.     if not doesFileExist(getGameDirectory()..'\\moonloader\\Fomikus\\Coords.txt') then
  221.         sampAddChatMessage(tag..'Нет координат братик', -1)
  222.     end
  223. sampRegisterChatCommand(kladman_cmd.v, function()
  224.     searching = not searching
  225.     enabled = not enabled
  226.     sampAddChatMessage(searching and tag..'Игорь Карпенко пошел шкурить' or tag..'Игорь Карпенко пошел домой', -1)
  227.     if na_dno.v and searching then
  228.         if tp then return false end
  229.         if not custom_dno.v then
  230.             placeWaypoint(-49, -1864, -62.4)
  231.         else
  232.             placeWaypoint(dno_x.v, dno_y.v, dno_z.v)
  233.         end
  234.         blip, blipX, blipY, blipZ = getTargetBlipCoordinatesFixed()
  235.         if blip then
  236.             sync = true
  237.             charPosX, charPosY, charPosZ = getCharCoordinates(playerPed)
  238.             startDist = getDistanceBetweenCoords3d(blipX, blipY, charPosZ, charPosX, charPosY, charPosZ)
  239.             tp = true
  240.             tpTime = os.clock()
  241.             packetCount = 0
  242.         end
  243.     end
  244. end)
  245. sampRegisterChatCommand('mtp', function()
  246.     if not isCharOnFoot(playerPed)
  247.     then return
  248.         sampAddChatMessage('{FF0000}Ошибка{FFFFFF}. Вы должны быть не в машине', -1)
  249.     end
  250.     lua_thread.create(function()
  251.         if tp then return end
  252.         blip, blipX, blipY, blipZ = getTargetBlipCoordinatesFixed()
  253.         if blip then
  254.             sync = true
  255.             charPosX, charPosY, charPosZ = getCharCoordinates(playerPed)
  256.             startDist = getDistanceBetweenCoords3d(blipX, blipY, charPosZ, charPosX, charPosY, charPosZ)
  257.             tp = true
  258.             tpTime = os.clock()
  259.             packetCount = 0
  260.         end
  261.     end)
  262. end)
  263. sampRegisterChatCommand('mtpc', function()
  264.     if not isCharOnFoot(playerPed)
  265.     then return
  266.         sampAddChatMessage('{FF0000}Ошибка{FFFFFF}. Вы должны быть не в машине', -1)
  267.     end
  268.     lua_thread.create(function()
  269.         if tp then return end
  270.         blip, blipX, blipY, blipZ = SearchMarker()
  271.         if blip then
  272.             sync = true
  273.             charPosX, charPosY, charPosZ = getCharCoordinates(playerPed)
  274.             startDist = getDistanceBetweenCoords3d(blipX, blipY, charPosZ, charPosX, charPosY, charPosZ)
  275.             tp = true
  276.             tpTime = os.clock()
  277.             packetCount = 0
  278.         end
  279.     end)
  280. end)
  281. lua_thread.create(function()
  282. while true do wait(0)
  283.                 text, _, _, _ = sampGetChatString(99)
  284.                 if text:find("closed the connection.") then
  285.                     sampAddChatMessage(tag..' Вы были кикнуты', -1)
  286.                     alert_text = ' Был кикнут сервером'
  287.                     sendVK(alert_text)
  288.                 end
  289. end
  290. end)
  291.  
  292. lua_thread.create(function()
  293.     while true do wait(0)
  294.         local data2 = {}
  295.         local data2 = read_klads()
  296.         coords = {}
  297.         if data2 == nil then return false end
  298.         for i, value in pairs(data2) do
  299.             table.insert(coords, value)
  300.         end
  301.         questions = read_answers()
  302.         wait(10000)
  303.     end
  304. end)
  305. lua_thread.create(function()
  306.     while true do wait(0)
  307.         if searching then
  308.             if mode.v == 1 then
  309.                 if random_txt.v then
  310.                     zhopa = random(1, #coords)
  311.                     textik = coords[zhopa]
  312.                     if textik ~= nil then
  313.                         printStringNow('~w~'..zhopa, 600)
  314.                         var1, var2, var3, var4 = textik:match('{(.*)}:{(.*)}:{(.*)}:{(.*)}')
  315.                         var1 = math.floor(var1)
  316.                         var2 = math.floor(var2)
  317.                         var3 = math.floor(var3)
  318.                         spec(var1, var2, var3)
  319.                         if double_spec.v then
  320.                             wait(50)
  321.                             spec(var1, var2, var3)
  322.                         end
  323.                         wait(spec_delay.v)
  324.                     end
  325.                 else
  326.                     for ad = 1, #coords do
  327.                         textik = coords[ad]
  328.                         if textik ~= nil and searching then
  329.                             printStringNow('~w~'..ad, 600)
  330.                             var1, var2, var3, var4 = textik:match('{(.*)}:{(.*)}:{(.*)}:{(.*)}')
  331.                             var1 = math.floor(var1)
  332.                             var2 = math.floor(var2)
  333.                             var3 = math.floor(var3)
  334.                             spec(var1, var2, var3)
  335.                             if double_spec.v then
  336.                                 wait(50)
  337.                                 spec(var1, var2, var3)
  338.                             end
  339.                             wait(spec_delay.v)
  340.                         end
  341.                     end
  342.                 end
  343.             else
  344.                 a = random(-120, 120)
  345.                 b = random(-120, 120)
  346.                 a = a * 25
  347.                 b = b * 25
  348.                 printStringNow(a..' '..b, 400)
  349.                 spec(a, b, 20)
  350.                 wait(350)
  351.             end
  352.         end
  353.     end
  354. end)
  355. lua_thread.create(function()
  356.     while true do wait(0)
  357.         if tp then
  358.             ncharPosX, ncharPosY, ncharPosZ = getCharCoordinates(playerPed)
  359.             CurrentDist = getDistanceBetweenCoords3d(blipX, blipY, charPosZ, charPosX, charPosY, charPosZ)
  360.             if CurrentDist > tp_speed.v then
  361.                 progress = (1 - (CurrentDist / startDist)) * 100
  362.                 printStringNow(string.format('Progress ~p~%.2f~b~', progress)..'%', 100)
  363.                 packetCount = packetCount + 1
  364.                 vectorX = blipX - charPosX
  365.                 vectorY = blipY - charPosY
  366.                 vectorZ = blipZ - charPosZ
  367.                 local vec = vector(vectorX, vectorY, vectorZ)
  368.                 vec:normalize()
  369.                 charPosX = charPosX + vec.x * tp_speed.v
  370.                 charPosY = charPosY + vec.y * tp_speed.v
  371.                 charPosZ = charPosZ + vec.z * tp_speed.v
  372.                 sendOnfootSync(charPosX, charPosY, charPosZ)
  373.                 sendOnfootSync(charPosX, charPosY, charPosZ + 55)
  374.                 wait(25)
  375.                 wait(tp_delay.v)
  376.                 return true
  377.             end
  378.             printStringNow('Progress ~p~100~b~%', 1000)
  379.             sendOnfootSync(charPosX, charPosY, charPosZ)
  380.             sendOnfootSync(charPosX, charPosY, charPosZ + 55)
  381.             setCharCoordinates(playerPed, blipX, blipY, blipZ)
  382.             wait(2000)
  383.             setCharCoordinates(playerPed, blipX, blipY, blipZ+0.1)
  384.             tp = false
  385.             timee = os.clock() - tpTime - 1
  386.             printStringNow(string.format('~w~Time ~g~%.2f ~w~sec (Packets ~r~%d~w~)', timee, packetCount), 5000)
  387.             sync = false
  388.         end
  389.     end
  390. end)
  391. lua_thread.create(getAsync)
  392. while true do wait(0)
  393.     if rgb.v then
  394.         style()
  395.     end
  396.     set_fog_dist(fogdist_dl.v)
  397.     if testCheat(kladman_cheatcode.v) then
  398.         searching = not searching
  399.         enabled = not enabled
  400.         sampAddChatMessage(searching and tag..'Игорь Карпенко пошел шкурить' or tag..'Игорь Карпенко пошел домой', -1)
  401.         if na_dno.v and searching then
  402.             if tp then return false end
  403.             if not custom_dno.v then
  404.                 placeWaypoint(-49, -1864, -62.4)
  405.             else
  406.                 placeWaypoint(dno_x.v, dno_y.v, dno_z.v)
  407.             end
  408.             blip, blipX, blipY, blipZ = getTargetBlipCoordinatesFixed()
  409.             if blip then
  410.                 sync = true
  411.                 charPosX, charPosY, charPosZ = getCharCoordinates(playerPed)
  412.                 startDist = getDistanceBetweenCoords3d(blipX, blipY, charPosZ, charPosX, charPosY, charPosZ)
  413.                 tp = true
  414.                 tpTime = os.clock()
  415.                 packetCount = 0
  416.             end
  417.         end
  418.     end
  419.     if ((isKeyDown(key1.v) and isKeyJustPressed(key2.v)) or (isKeyDown(key2.v) and isKeyJustPressed(key1.v))) and not sampIsDialogActive() and not sampIsChatInputActive() then
  420.         main_window_state.v  = not main_window_state.v
  421.         wait(100)
  422.     end
  423.     imgui.Process = main_window_state.v
  424. end
  425. end
  426.  
  427. function getAsync() -- ваша функция, содержащая асинхроны
  428.  while true do wait(0)
  429.  if sendvk == false then
  430.   asyncHttpRequest('GET', url, nil,
  431.      function(response)
  432.         new_sms(response.text)
  433.      end,
  434.      function(err)
  435.       print('{6600FF}Нет связи | '..err)
  436.       wait(700)
  437.   end)
  438.   wait(2000)
  439.  end
  440.  end
  441. end
  442.  
  443. function obrabotka(n)
  444.         res,data = pcall(decodeJson,n)
  445.         local data = decodeJson(n)
  446.         if res == true  then
  447.             if data then
  448.                 if utf8:decode(data.response.items[1]['text']) then
  449.                     deist(utf8:decode(data.response.items[1]['text']))
  450.                 end
  451.             end
  452.         end
  453. end
  454.  
  455. function new_sms(n)
  456. if sms == '555' then
  457. sms = n
  458. end
  459.     if n == sms then
  460.     else   
  461.         sms = n
  462.         obrabotka(n)
  463.     end
  464. end
  465.  
  466. function deist(d)
  467.     print('Получено новое сообщение: '..d)
  468.     window_id = 1
  469.     _, window_id = sampGetPlayerIdByCharHandle(playerPed)
  470.     msg_to = d:match('(.*)%s+|')
  471.     if window_id == tonumber(msg_to) then
  472.         print('Сообщение сюда')
  473.         d = d:match(msg_to..'%s+|%s+(.*)')
  474.         if d:find('Ответь') or d:find('ответь') then
  475.             VK_ans = '555'
  476.             VK_ans = d:match('тветь%s+(.*)')
  477.             cur_did =  sampGetCurrentDialogId()
  478.             if not sampIsDialogActive() then
  479.                 sendVK('%0A Нет активного диалога')
  480.             else
  481.                 sampSendDialogResponse(cur_did, 1, 0, VK_ans)
  482.                 file = AnswerFile('a')
  483.                 file:write("{q = '"..CurQuest.."', a = '"..VK_ans.."'} \n")
  484.                 file:close()
  485.                 sampAddChatMessage(tag..' Добавлен вопрос/ответ '..CurQuest..' / '..VK_ans, -1)
  486.                 WaitingAnswer = false
  487.                 sampCloseCurrentDialogWithButton(0)
  488.                 sendVK('Ответили: '..VK_ans..' На диалог: '..cur_did)
  489.             end
  490.         end
  491.     end
  492. end
  493.  
  494.  
  495. function imgui.OnDrawFrame()
  496.     if main_window_state.v and not sampIsDialogActive() then
  497.         imgui.SetNextWindowSize(imgui.ImVec2(611, 325), main_window_state, imgui.Cond.FirstUseEver)
  498.         if not window_pos then
  499.             ScreenX, ScreenY = getScreenResolution()
  500.             imgui.SetNextWindowPos(imgui.ImVec2(ScreenX / 2 , ScreenY / 2), imgui.Cond.FirsUseEver, imgui.ImVec2(0.5, 0.5))
  501.             window_pos = true
  502.         end
  503.         imgui.Begin(utf8'MainWindow', main_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoScrollbar + imgui.WindowFlags.NoTitleBar)
  504.         imgui.BeginChild("##MenuButtons", imgui.ImVec2(150, 315), true, imgui.WindowFlags.NoScrollbar)
  505.         if imgui.Button(utf8"Кладмэн", imgui.ImVec2(140, 35)) then
  506.             sbros()
  507.             vkladki[1] = true
  508.         end
  509.         if imgui.Button(utf8"Уведомления", imgui.ImVec2(140, 35)) then
  510.             sbros()
  511.             vkladki[3] = true
  512.         end
  513.         if imgui.Button(utf8"Настройки", imgui.ImVec2(140, 35)) then
  514.             sbros()
  515.             vkladki[4] = true
  516.         end
  517.         if imgui.Button(utf8"Информация", imgui.ImVec2(140, 35)) then
  518.             sbros()
  519.             vkladki[5] = true
  520.         end
  521.         if imgui.Button(utf8"Вернуть деньги", imgui.ImVec2(140, 35)) then
  522.             sbros()
  523.             vkladki[6] = true
  524.         end
  525.         if imgui.Button(utf8"Save ini", imgui.ImVec2(140, 35)) then
  526.         save_ini()
  527.         end
  528.         if imgui.Button(utf8"Reload", imgui.ImVec2(140, 35)) then
  529.         thisScript():reload()
  530.         end
  531.         imgui.Image(img1, imgui.ImVec2(140, 55))
  532.         imgui.EndChild()
  533.         imgui.SameLine()
  534.         imgui.BeginChild("##VkladOchki", imgui.ImVec2(450, 315), true, imgui.WindowFlags.NoScrollbar)
  535.         if vkladki[1] == true then -- Настройки бота
  536.             imgui.BeginGroup()
  537.             imgui.SetCursorPosX((imgui.GetWindowWidth() - 200) / 2)
  538.             imgui.RadioButton(utf8"Coords(txt)", mode, 1)
  539.             imgui.SameLine()
  540.             ShowHelpMarker(utf8'Проход по координатам из текстовика \n(moonloader/Fomikus/Coords.txt)')
  541.             imgui.SameLine()
  542.             imgui.RadioButton(utf8"Random", mode, 2)
  543.             imgui.SameLine()
  544.             ShowHelpMarker(utf8'Чекает случайные координаты (По всей карте). Шанс очень мал. \nОднако если найдет - запишет в общий текстовик')
  545.             imgui.Separator()
  546.             imgui.Checkbox(utf8"Автоматический телепорт", auto_tp)
  547.             imgui.Checkbox(utf8"Автоматический ответ", auto_answer)
  548.             imgui.Checkbox(utf8"Автоматическое откапывание", auto_yn)
  549.             imgui.Checkbox(utf8"Автоматическая еда", auto_eat)
  550.             imgui.Checkbox(utf8"Телепорт на дно", na_dno)
  551.             imgui.Checkbox(utf8"Проверять клад дважды", double_spec)
  552.             if mode.v == 1 then imgui.Checkbox(utf8"Случайный порядок", random_txt) end
  553.             imgui.EndGroup()
  554.         end
  555.         if vkladki[3] == true then -- Настройки бота
  556.             imgui.BeginGroup()
  557.             imgui.Checkbox(utf8"Уведомлять о кладе", klad_alert)
  558.             imgui.Checkbox(utf8"Уведомлять о дропе", prize_alert)
  559.             imgui.Checkbox(utf8"Писать ник в уведомлении", nick_alert)
  560.             imgui.Checkbox(utf8"Уведомлять если не смог ответить", cant_answer)
  561.             imgui.Checkbox(utf8'Уведомления VK', vk_alerts)
  562.             if vk_alerts.v then
  563.                 imgui.InputText(utf8"VK Token", vk_token, imgui.InputTextFlags.Password)
  564.                 imgui.InputInt(utf8"VK ID", vk_id, 0, 0)
  565.             end
  566.             if imgui.Button(utf8"Тестовое оповещение", imgui.ImVec2(140, 35)) then
  567.                 sendVK('Я тестовое оповещение '..os.date())
  568.             end
  569.             imgui.EndGroup()
  570.         end
  571.         if vkladki[4] == true then -- Настройки бота
  572.             imgui.BeginGroup()
  573.             imgui.Checkbox(utf8"ЛГБТ Меню", rgb)
  574.             imgui.Checkbox(utf8"Свои координаты дна", custom_dno)
  575.             if custom_dno.v then
  576.             imgui.SameLine()
  577.               if imgui.Button(utf8"Текущие координаты", imgui.ImVec2(140, 25)) then
  578.                dno_x.v, dno_y.v, dno_z.v = getCharCoordinates(playerPed)
  579.             end
  580.             end
  581.             imgui.Checkbox(utf8"Сохранять призы", save_prize)
  582.             imgui.InputText(utf8"Кладмэн команда", kladman_cmd)
  583.             imgui.InputText(utf8"Кладмэн чит-код", kladman_cheatcode)
  584.             imgui.SliderInt(utf8"Fog dist", fogdist_dl, 0, 500)
  585.             imgui.SliderInt(utf8"TP Delay", tp_delay, 0, 100)
  586.             imgui.SliderInt(utf8"Spec delay", spec_delay, 300, 1000)
  587.             imgui.SliderFloat(utf8"TP Speed", tp_speed, 0, 25)
  588.             if custom_dno.v then
  589.             imgui.InputInt(utf8"X", dno_x, 0, 0)
  590.             imgui.InputInt(utf8"Y", dno_y, 0, 0)
  591.             imgui.InputInt(utf8"Z", dno_z, 0, 0)
  592.             end
  593.             imgui.EndGroup()
  594.         end
  595.         if vkladki[5] == true then -- Настройки бота
  596.             imgui.BeginGroup()
  597.             imgui.SetCursorPosY(imgui.GetWindowHeight() / 2.25)
  598.             imgui.SetCursorPosX((imgui.GetWindowWidth() - imgui.CalcTextSize(utf8"Telegram: @Fomikus").x) / 2)
  599.             imgui.Text(utf8'Telegram: @Fomikus')
  600.             imgui.SetCursorPosX((imgui.GetWindowWidth() - imgui.CalcTextSize(utf8"Версия скрипта: "..thisScript().version).x) / 2)
  601.             imgui.Text(utf8'Версия скрипта: '..thisScript().version)
  602.             imgui.EndGroup()
  603.         end
  604.         if vkladki[6] then
  605.             imgui.Image(img2, imgui.ImVec2(450, 300))
  606.         end
  607.         imgui.EndChild()
  608.         imgui.End()
  609.     end
  610. end
  611.  
  612. function samp.onSendPlayerSync(data)
  613.     if tp then return false end
  614. end
  615.  
  616. function samp.onSetPlayerPos(p)
  617.     if sync then
  618.         timer = os.clock()
  619.         return false
  620.     end
  621. end
  622.  
  623. function samp.onShowDialog(id, style, title, btn1, btn2, text)
  624.     if enabled then
  625.         if id == 13101 and auto_answer.v then
  626.             Answered = false
  627.             WaitingAnswer = false
  628.             if CurQuest:find('?') then
  629.                 CurQuest = text:match('Вопрос:%s+(.*)?')
  630.             else
  631.                 CurQuest = text:match('Вопрос:%s+(.*)%s+Введите')
  632.             end
  633.             if CurQuest then
  634.                 sampAddChatMessage(tag..' Вопрос: '..CurQuest, -1)
  635.                 CurQuest = CurQuest:gsub('%%', '')
  636.                 for i = 1, #questions do
  637.                     textik = questions[i]
  638.                     if textik and textik ~= nil then
  639.                         question, answer = textik:match("{q = '(.*)', a = '(.*)'}")
  640.                         if question ~= nil then
  641.                             question = question:gsub('%%', '')
  642.                             if text:find(question) then
  643.                                 sampAddChatMessage(answer, -1)
  644.                                 sampSendDialogResponse(id, 1, 0, answer)
  645.                                 Answered = true
  646.                                 WaitingAnswer = false
  647.                                 sampCloseCurrentDialogWithButton(0)
  648.                                 return false
  649.                             end
  650.                         end
  651.                     end
  652.                 end
  653.             end
  654.             if not Answered then
  655.                 sampAddChatMessage(tag..' Ответ не найден, введите ответ и он будет сохранен', -1)
  656.                 WaitingAnswer = true
  657.                 if cant_answer.v and vk_alerts.v then
  658.                     server = sampGetCurrentServerName()
  659.                     _, my_id = sampGetPlayerIdByCharHandle(playerPed)
  660.                     if CurQuest:find('?') then
  661.                         CurQuest = text:match('Вопрос:%s+(.*)?')
  662.                     else
  663.                         CurQuest = text:match('Вопрос:%s+(.*)%s+Введите')
  664.                     end
  665.                     CurQuest = CurQuest:gsub('%%', '')
  666.                     alert_text = ' Вопрос: '..CurQuest..' %0A Чтобы ответить введите - '..my_id..' | Ответь [ответ]'
  667.                     if vk_alerts.v then
  668.                         sendVK(alert_text)
  669.                     end
  670.                 end
  671.             end
  672.         end
  673.         if id == 13100 then
  674.             sampSendDialogResponse(id, 1, 0, '')
  675.             return false
  676.         end
  677.     end
  678. end
  679.  
  680.  
  681. function samp.onServerMessage(_, msg)
  682.     if enabled then
  683.         if msg:find('больницу или подождать врачей') and vk_alerts.v then
  684.             alert_text = ' Бот умер и прекратил свою работу'
  685.             sendVK(alert_text)
  686.             enabled = false
  687.             searching = false
  688.         end
  689.         if msg:find('добавлен предмет') and save_prize.v and not msg:find('сундук рулетки') then
  690.             server = sampGetCurrentServerName()
  691.             prize = msg:match('(.*) Чтобы')
  692.             if save_prize.v then
  693.                 file = io.open('moonloader/Fomikus/!all.txt', 'a')
  694.                 file:write(prize..' ('..server..') '..os.date()..' \n')
  695.                 file:close()
  696.                 file = io.open('moonloader/Fomikus/'..os.date("%d.%m")..'p.txt', 'a')
  697.                 file:write(prize..' ('..server..') '..os.date()..' \n')
  698.                 file:close()
  699.             end
  700.             if prize_alert.v and vk_alerts.v then
  701.                 alert_text = msg:match('(.*) Чтобы')
  702.                 if vk_alerts.v then
  703.                     sendVK(alert_text)
  704.                 end
  705.             end
  706.             if na_dno.v then
  707.                 lua_thread.create(function()
  708.                     wait(1000)
  709.                     searching = true
  710.                     if not custom_dno.v then
  711.                         placeWaypoint(-49, -1864, -62.4)
  712.                     else
  713.                         placeWaypoint(dno_x.v, dno_y.v, dno_z.v)
  714.                     end
  715.                     if tp then return false end
  716.                     blip, blipX, blipY, blipZ = getTargetBlipCoordinatesFixed()
  717.                     if blip then
  718.                         sync = true
  719.                         charPosX, charPosY, charPosZ = getCharCoordinates(playerPed)
  720.                         startDist = getDistanceBetweenCoords3d(blipX, blipY, charPosZ, charPosX, charPosY, charPosZ)
  721.                         tp = true
  722.                         tpTime = os.clock()
  723.                         packetCount = 0
  724.                     end
  725.                 end)
  726.             end
  727.         end
  728.         if msg:find('Вы немного перекусили') and eating then
  729.             searching = true
  730.             if na_dno.v then
  731.                 if not custom_dno.v then
  732.                     placeWaypoint(-49, -1864, -62.4)
  733.                 else
  734.                     placeWaypoint(dno_x.v, dno_y.v, dno_z.v)
  735.                 end
  736.                 if tp then return false end
  737.                 blip, blipX, blipY, blipZ = getTargetBlipCoordinatesFixed()
  738.                 if blip then
  739.                     sync = true
  740.                     charPosX, charPosY, charPosZ = getCharCoordinates(playerPed)
  741.                     startDist = getDistanceBetweenCoords3d(blipX, blipY, charPosZ, charPosX, charPosY, charPosZ)
  742.                     tp = true
  743.                     tpTime = os.clock()
  744.                     packetCount = 0
  745.                 end
  746.             end
  747.         end
  748.         if msg:find('У Вас должна быть лопата в руках') then
  749.             _, my_id =  sampGetPlayerIdByCharHandle(PLAYER_PED)
  750.             my_nick = sampGetPlayerNickname(my_id)
  751.             alert_text = '['..my_id..'] Требует лопату'
  752.             if vk_alerts.v then
  753.                 sendVK(alert_text)
  754.             end
  755.         end
  756.     end
  757. end
  758.  
  759.  
  760. function samp.onDisplayGameText(style, timer, text)
  761.     if enabled then
  762.         if auto_yn.v then
  763.             if not tp and not searching then
  764.                 if text:find('Press: ~g~Y') then
  765.                     local data = samp_create_sync_data('player')
  766.                     data.weapon = data.weapon + 64
  767.                     data.send()
  768.                 end
  769.                 if text:find('Press: ~r~N') then
  770.                     local data = samp_create_sync_data('player')
  771.                     data.weapon = data.weapon + 128
  772.                     data.send()
  773.                 end
  774.                 if text:find('ALT') then
  775.                     local data = samp_create_sync_data('player')
  776.                     data.keysData = data.keysData + 1024
  777.                     data.send()
  778.                 end
  779.                 if text:find('~g~successfully') then
  780.                     lua_thread.create(function()
  781.                     wait(500)
  782.                         local data = samp_create_sync_data('player')
  783.                         data.keysData = data.keysData + 1024
  784.                         data.send()
  785.                     end)
  786.                 end
  787.                  if text:find('fail') or text:find('FAIL') or text:find('Fail') then
  788.                     lua_thread.create(function()
  789.                         wait(500)
  790.                         local data = samp_create_sync_data('player')
  791.                         data.keysData = data.keysData + 1024
  792.                         data.send()
  793.                     end)
  794.                 end
  795.             end
  796.         end
  797.         if text:find('hungry') and auto_eat.v then
  798.             eda()
  799.         end
  800.     end
  801. end
  802.  
  803. function samp.onSendDialogResponse(id, btn, listId, input)
  804.     if enabled then
  805.         if id == 13101 and auto_answer.v then
  806.             if WaitingAnswer then
  807.                 question = CurQuest
  808.                 if question ~= nil then
  809.                     answer = input
  810.                     file = AnswerFile('a')
  811.                     file:write("{q = '"..question.."', a = '"..answer.."'} \n")
  812.                     file:close()
  813.                     sampAddChatMessage(tag..' Добавлен вопрос/ответ '..question..' / '..answer, -1)
  814.                     WaitingAnswer = false
  815.                 end
  816.             end
  817.         end
  818.     end
  819. end
  820.  
  821.  
  822. function samp.onCreateObject(objectId, data)
  823. if enabled then
  824.     if data.modelId == 2680 and auto_tp.v then
  825.     if not tp then
  826.         charPosX, charPosY, charPosZ = getCharCoordinates(playerPed)
  827.         dist2 = getDistanceBetweenCoords3d(data.position.x, data.position.y, charPosZ, charPosX, charPosY, charPosZ)
  828.         lua_thread.create(function()
  829.             searching = false
  830.             wait(90000)
  831.             if not searching and not tp then
  832.                 if na_dno.v then
  833.                         if not custom_dno.v then
  834.                             placeWaypoint(-49, -1864, -62.4)
  835.                         else
  836.                             placeWaypoint(dno_x.v, dno_y.v, dno_z.v)
  837.                         end
  838.                         if not tp then
  839.                         blip, blipX, blipY, blipZ = getTargetBlipCoordinatesFixed()
  840.                         if blip then
  841.                             sync = true
  842.                             charPosX, charPosY, charPosZ = getCharCoordinates(playerPed)
  843.                             startDist = getDistanceBetweenCoords3d(blipX, blipY, charPosZ, charPosX, charPosY, charPosZ)
  844.                             tp = true
  845.                             tpTime = os.clock()
  846.                             packetCount = 0
  847.                         end
  848.                         end
  849.                 end
  850.                 searching = true
  851.                 alert_text = ' Что-то случилось, продолжаю работу'
  852.                 sendVK(alert_text)
  853.             end
  854.         end)
  855.         if dist2 > 10 then
  856.             sampAddChatMessage(tag..'Появился клад: '..data.position.x..' '..data.position.y..' '..data.position.z, -1)
  857.             placeWaypoint(data.position.x, data.position.y, data.position.z)
  858.             blip, blipX, blipY, blipZ = true, data.position.x, data.position.y, data.position.z
  859.             if blip and not tp then
  860.                 sync = true
  861.                 charPosX, charPosY, charPosZ = getCharCoordinates(playerPed)
  862.                 startDist = getDistanceBetweenCoords3d(blipX, blipY, charPosZ, charPosX, charPosY, charPosZ)
  863.                 tp = true
  864.                 tpTime = os.clock()
  865.                 packetCount = 0
  866.             end
  867.             else
  868.             setCharCoordinates(playerPed, data.position.x, data.position.y, data.position.z)
  869.         end
  870.     end
  871.     end
  872.     if data.modelId == 2680 and vk_alerts.v and klad_alert.v then
  873.         server = sampGetCurrentServerName()
  874.         charPosX, charPosY, charPosZ = getCharCoordinates(playerPed)
  875.         startDist = getDistanceBetweenCoords3d(data.position.x, data.position.y, charPosZ, charPosX, charPosY, charPosZ)
  876.         if startDist > 25 then
  877.             var1 = data.position.x
  878.             var2 = data.position.y
  879.             var3 = data.position.z
  880.             alert_text = prize
  881.                 alert_text = tostring('%0A X1YZ:'..var1..', '..var2..', '..var3..'%0A Dist: '..startDist)
  882.             if vk_alerts.v then
  883.                 sendVK(alert_text)
  884.             end
  885.         end
  886.     end
  887.     if data.modelId == 2680 then
  888.     _G['pov'..objectId] = false
  889.         data5 = {}
  890.         data5 = read_new_klads()
  891.         for i = 1, #data5 do
  892.             text = data5[i]
  893.             if text ~= nil then
  894.                 var1, var2, var3, var4 = text:match('{(.*)}:{(.*)}:{(.*)}:{(.*)}')
  895.                 if var1 ~= nil and var2 ~= nil and var3 ~= nil then
  896.                     var1, var2, var3 = math.floor(tonumber(var1)), math.floor(tonumber(var2)), math.floor(tonumber(var3))
  897.                     var11 = math.floor(data.position.x)
  898.                     var21 = math.floor(data.position.y)
  899.                     var31 = math.floor(data.position.z)
  900.                     if (var1 == var11 or var1 - 1 == var11 or var1 + 1 == var11) and (var2 == var21 or var2 - 1 == var21 or var2 + 1 == var21) and (var3 == var31 or var3 - 1 == var31 or var3 + 1 == var31) then
  901.                         _G['pov'..objectId] = true
  902.                     end
  903.                 end
  904.             end
  905.         end
  906.         if not _G['pov'..objectId] then
  907.             sampAddChatMessage('Добавлен клад', -1)
  908.             file = KladFile('a')
  909.             file:write('{'..data.position.x..'}:{'..data.position.y..'}:{'..data.position.z..'}:{klad1} \n')
  910.             file:close()
  911.         end
  912.     end
  913. end
  914. end
  915.  
  916. function eda()
  917.     if enabled then
  918.         searching = false
  919.         placeWaypoint(157.1, -1812.5, 3.7)
  920.         if tp then return false end
  921.         blip, blipX, blipY, blipZ = getTargetBlipCoordinatesFixed()
  922.         if blip then
  923.             sync = true
  924.             charPosX, charPosY, charPosZ = getCharCoordinates(playerPed)
  925.             startDist = getDistanceBetweenCoords3d(blipX, blipY, charPosZ, charPosX, charPosY, charPosZ)
  926.             tp = true
  927.             tpTime = os.clock()
  928.             packetCount = 0
  929.         end
  930.         eating = true
  931.         lua_thread.create(function()
  932.             searching = false
  933.             wait(60000)
  934.             if not searching and not tp then
  935.                 if na_dno.v then
  936.                         if not custom_dno.v then
  937.                             placeWaypoint(-49, -1864, -62.4)
  938.                         else
  939.                             placeWaypoint(dno_x.v, dno_y.v, dno_z.v)
  940.                         end
  941.                         if not tp then
  942.                         blip, blipX, blipY, blipZ = getTargetBlipCoordinatesFixed()
  943.                         if blip then
  944.                             sync = true
  945.                             charPosX, charPosY, charPosZ = getCharCoordinates(playerPed)
  946.                             startDist = getDistanceBetweenCoords3d(blipX, blipY, charPosZ, charPosX, charPosY, charPosZ)
  947.                             tp = true
  948.                             tpTime = os.clock()
  949.                             packetCount = 0
  950.                         end
  951.                         end
  952.                 end
  953.                 searching = true
  954.                 alert_text = ' Что-то случилось, продолжаю работу'
  955.                 sendVK(alert_text)
  956.             end
  957.         end)
  958.     end
  959. end
  960.  
  961.  
  962. function samp.onShowTextDraw(id, id1)
  963. if enabled then
  964.     if id1.text:find('icon1') and auto_eat.v and eating then
  965.         sampSendClickTextdraw(id)
  966.     end
  967.     end
  968. end
  969.  
  970. function random(min, max)
  971.     kf = math.random(min, max)
  972.     math.randomseed(os.time() * kf - os.clock())
  973.     rand = math.random(min, max)
  974.     return tonumber(rand)
  975. end
  976.  
  977. function sendVK(text)
  978.     server = sampGetCurrentServerName()
  979.     alert_text = text
  980.     if nick_alert.v then
  981.         _, my_id =  sampGetPlayerIdByCharHandle(PLAYER_PED)
  982.         my_nick = sampGetPlayerNickname(my_id)
  983.         alert_text = server..' | '..my_nick..' | '..alert_text
  984.         else
  985.         alert_text = server..' | '..alert_text
  986.     end
  987.     text = utf8(alert_text)
  988.     urld = ('https://api.vk.com/method/messages.send?message='..text..'&user_id='..vk_id.v..'&access_token='..vk_token.v..'&v=5.50')
  989.     downloadUrlToFile(urld,nil,nil)
  990. end
  991.  
  992. function AnswerFile(mode)
  993.     return io.open('moonloader/Fomikus/AutoAnswer.txt', mode)
  994. end
  995.  
  996. function LicFile(mode)
  997.     return io.open('moonloader/Fomikus/license.txt', mode)
  998. end
  999.  
  1000. function KladFile(mode)
  1001.     return io.open('moonloader/Fomikus/NewKlads.txt', mode)
  1002. end
  1003.  
  1004. function CoordsFile(mode)
  1005.     return io.open('moonloader/Fomikus/Coords.txt', mode)
  1006. end
  1007.  
  1008. function ch_cr_directories()
  1009.     if not doesDirectoryExist('moonloader/Fomikus') or not doesDirectoryExist('moonloadre/Fomikus/resource') then
  1010.         createDirectory('moonloader/Fomikus')
  1011.         createDirectory('moonloader/Fomikus/resource')
  1012.     end
  1013. end
  1014.  
  1015. function read_answers()
  1016.     local file = AnswerFile('r')
  1017.     if file then
  1018.         local data = {}
  1019.         for line in file:lines() do
  1020.             table.insert(data, line)
  1021.         end
  1022.         file:close()
  1023.         return data
  1024.     else
  1025.         return nil
  1026.     end
  1027. end
  1028.  
  1029. function read_new_klads()
  1030.     local file = new_klads_file('r')
  1031.     if file then
  1032.         local data = {}
  1033.         for line in file:lines() do
  1034.             table.insert(data, line)
  1035.         end
  1036.         file:close()
  1037.         return data
  1038.     else
  1039.         return nil
  1040.     end
  1041. end
  1042.  
  1043. function new_klads_file(mode)
  1044.     return io.open('moonloader/Fomikus/NewKlads.txt', mode)
  1045. end
  1046.  
  1047. function read_klads()
  1048.     local file = CoordsFile('r')
  1049.     if file then
  1050.         local data = {}
  1051.         for line in file:lines() do
  1052.             table.insert(data, line)
  1053.         end
  1054.         file:close()
  1055.         return data
  1056.     else
  1057.         return nil
  1058.     end
  1059. end
  1060.  
  1061.  
  1062. function download_handler(id, status, p1, p2)
  1063.     if stop_downloading then
  1064.         stop_downloading = false
  1065.         download_id = nil
  1066.         print('Загрузка отменена.')
  1067.         return false -- прервать загрузку
  1068.     end
  1069.     if status == dlstatus.STATUS_DOWNLOADINGDATA then
  1070.         print(string.format('Загружено %d из %d.', p1, p2))
  1071.     elseif status == dlstatus.STATUS_ENDDOWNLOADDATA then
  1072.         print('Загрузка завершена.')
  1073.         if doesFileExist(getGameDirectory() .. '\\moonloader\\Fomikus\\resource\\logo1.jpg') and doesFileExist(getGameDirectory() .. '\\moonloader\\Fomikus\\resource\\logo2.jpg')  then
  1074.             thisScript():reload()
  1075.         end
  1076.     end
  1077. end
  1078.  
  1079. function ShowHelpMarker(desc)
  1080.     imgui.TextDisabled(utf8'(?)')
  1081.     if imgui.IsItemHovered() then
  1082.         imgui.BeginTooltip()
  1083.         imgui.PushTextWrapPos(450.0)
  1084.         imgui.TextUnformatted(desc)
  1085.         imgui.PopTextWrapPos()
  1086.         imgui.EndTooltip()
  1087.     end
  1088. end
  1089.  
  1090.  
  1091. function save_ini()
  1092. local config = {
  1093.             setting = {
  1094.                 rgb = rgb.v,
  1095.                 rgb_speed = rgb_speed.v,
  1096.                 key1 = key1.v,
  1097.                 key2 = key2.v,
  1098.                 mode = mode.v,
  1099.                 vk_id = vk_id.v,
  1100.                 vk_token = vk_token.v,
  1101.                 auto_tp = auto_tp.v,
  1102.                 na_dno = na_dno.v,
  1103.                 dno_x = dno_x.v,
  1104.                 dno_y = dno_y.v,
  1105.                 dno_z = dno_z.v,
  1106.                 vk_alerts = vk_alerts.v,
  1107.                 prize_alert = prize_alert.v,
  1108.                 klad_alert = klad_alert.v,
  1109.                 cant_answer = cant_answer.v,
  1110.                 auto_blip = auto_blip.v,
  1111.                 auto_answer = auto_answer.v,
  1112.                 kladman_cmd = kladman_cmd.v,
  1113.                 kladman_cheatcode = kladman_cheatcode.v,
  1114.                 auto_yn = auto_yn.v,
  1115.                 auto_eat = auto_eat.v,
  1116.                 save_prize = save_prize.v,
  1117.                 custom_dno = custom_dno.v,
  1118.                 random_txt = random_txt.v,
  1119.                 fogdist_dl = fogdist_dl.v,
  1120.                 nick_alert = nick_alert.v,
  1121.                 tp_speed = tp_speed.v,
  1122.                 spec_delay = spec_delay.v,
  1123.                 tp_delay = tp_delay.v,
  1124.                 double_spec = double_spec.v
  1125.             }
  1126.         }
  1127.         inicfg.save(config, "Fomikus/KladMan.ini")
  1128. end
  1129.  
  1130.  
  1131. function sbros()
  1132.     for i = 0,6 do
  1133.         vkladki[i] = false
  1134.     end
  1135. end
  1136.  
  1137. function spec(x, y, z)
  1138.     local data = samp_create_sync_data('spectator')
  1139.     data.position = {x, y, z}
  1140.     data.send()
  1141. end
  1142.  
  1143. function sendOnfootSync(x, y, z)
  1144.     local data = samp_create_sync_data('player')
  1145.     data.position = {x, y, z}
  1146.     data.moveSpeed = {0.899999, 0.899999, -0.899999}
  1147.     data.send()
  1148. end
  1149.  
  1150. function getTargetBlipCoordinatesFixed()
  1151.     local bool, x, y, z = getTargetBlipCoordinates(); if not bool then return false end
  1152.     requestCollision(x, y); loadScene(x, y, z)
  1153.     local bool, x, y, z = getTargetBlipCoordinates()
  1154.     return bool, x, y, z
  1155. end
  1156.  
  1157. function asyncHttpRequest(method, url, args, resolve, reject)
  1158.    local request_thread = effil.thread(function (method, url, args)
  1159.       local requests = require 'requests'
  1160.       local result, response = pcall(requests.request, method, url, args)
  1161.       if result then
  1162.          response.json, response.xml = nil, nil
  1163.          return true, response
  1164.       else
  1165.          return false, response
  1166.       end
  1167.    end)(method, url, args)
  1168.    if not resolve then resolve = function() end end
  1169.    if not reject then reject = function() end end
  1170.    lua_thread.create(function()
  1171.       local runner = request_thread
  1172.       while true do
  1173.          local status, err = runner:status()
  1174.          if not err then
  1175.             if status == 'completed' then
  1176.                local result, response = runner:get()
  1177.                if result then
  1178.                   resolve(response)
  1179.                else
  1180.                   reject(response)
  1181.                end
  1182.                return
  1183.             elseif status == 'canceled' then
  1184.                return reject(status)
  1185.             end
  1186.          else
  1187.             return reject(err)
  1188.          end
  1189.          wait(0)
  1190.       end
  1191.    end)
  1192. end
  1193.  
  1194. function SearchMarker(posX, posY, posZ)
  1195.     local ret_posX = 0.0
  1196.     local ret_posY = 0.0
  1197.     local ret_posZ = 0.0
  1198.     local isFind = false
  1199.     for id = 0, 31 do
  1200.         local MarkerStruct = 0
  1201.         MarkerStruct = 0xC7F168 + id * 56
  1202.         local MarkerPosX = representIntAsFloat(readMemory(MarkerStruct + 0, 4, false))
  1203.         local MarkerPosY = representIntAsFloat(readMemory(MarkerStruct + 4, 4, false))
  1204.         local MarkerPosZ = representIntAsFloat(readMemory(MarkerStruct + 8, 4, false))
  1205.         if MarkerPosX ~= 0.0 or MarkerPosY ~= 0.0 or MarkerPosZ ~= 0.0 then
  1206.             ret_posX = MarkerPosX
  1207.             ret_posY = MarkerPosY
  1208.             ret_posZ = MarkerPosZ
  1209.             isFind = true
  1210.         end
  1211.     end
  1212.     return isFind, ret_posX, ret_posY, ret_posZ
  1213. end
  1214.  
  1215. function samp_create_sync_data(sync_type, copy_from_player)
  1216.     local ffi = require 'ffi'
  1217.     local sampfuncs = require 'sampfuncs'
  1218.     -- from SAMP.Lua
  1219.     local raknet = require 'samp.raknet'
  1220.     require 'samp.synchronization'
  1221.  
  1222.     copy_from_player = copy_from_player or true
  1223.     local sync_traits = {
  1224.         player = {'PlayerSyncData', raknet.PACKET.PLAYER_SYNC, sampStorePlayerOnfootData},
  1225.         vehicle = {'VehicleSyncData', raknet.PACKET.VEHICLE_SYNC, sampStorePlayerIncarData},
  1226.         passenger = {'PassengerSyncData', raknet.PACKET.PASSENGER_SYNC, sampStorePlayerPassengerData},
  1227.         aim = {'AimSyncData', raknet.PACKET.AIM_SYNC, sampStorePlayerAimData},
  1228.         trailer = {'TrailerSyncData', raknet.PACKET.TRAILER_SYNC, sampStorePlayerTrailerData},
  1229.         unoccupied = {'UnoccupiedSyncData', raknet.PACKET.UNOCCUPIED_SYNC, nil},
  1230.         bullet = {'BulletSyncData', raknet.PACKET.BULLET_SYNC, nil},
  1231.         spectator = {'SpectatorSyncData', raknet.PACKET.SPECTATOR_SYNC, nil}
  1232.     }
  1233.     local sync_info = sync_traits[sync_type]
  1234.     local data_type = 'struct ' .. sync_info[1]
  1235.     local data = ffi.new(data_type, {})
  1236.     local raw_data_ptr = tonumber(ffi.cast('uintptr_t', ffi.new(data_type .. '*', data)))
  1237.     -- copy player's sync data to the allocated memory
  1238.     if copy_from_player then
  1239.         local copy_func = sync_info[3]
  1240.         if copy_func then
  1241.             local _, player_id
  1242.             if copy_from_player == true then
  1243.                 _, player_id = sampGetPlayerIdByCharHandle(PLAYER_PED)
  1244.             else
  1245.                 player_id = tonumber(copy_from_player)
  1246.             end
  1247.             copy_func(player_id, raw_data_ptr)
  1248.         end
  1249.     end
  1250.     -- function to send packet
  1251.     local func_send = function()
  1252.         local bs = raknetNewBitStream()
  1253.         raknetBitStreamWriteInt8(bs, sync_info[2])
  1254.         raknetBitStreamWriteBuffer(bs, raw_data_ptr, ffi.sizeof(data))
  1255.         raknetSendBitStreamEx(bs, sampfuncs.HIGH_PRIORITY, sampfuncs.UNRELIABLE_SEQUENCED, 1)
  1256.         raknetDeleteBitStream(bs)
  1257.     end
  1258.     -- metatable to access sync data and 'send' function
  1259.     local mt = {
  1260.         __index = function(t, index)
  1261.             return data[index]
  1262.         end,
  1263.         __newindex = function(t, index, value)
  1264.             data[index] = value
  1265.         end
  1266.     }
  1267.     return setmetatable({send = func_send}, mt)
  1268. end
  1269.  
  1270. function join_argb(a, r, g, b)
  1271.     local argb = b  -- b
  1272.     argb = bit.bor(argb, bit.lshift(g, 8))  -- g
  1273.     argb = bit.bor(argb, bit.lshift(r, 16)) -- r
  1274.     argb = bit.bor(argb, bit.lshift(a, 24)) -- a
  1275.     return argb
  1276. end
  1277.  
  1278. function rainbow(speed, alpha, offset)
  1279.     local clock = os.clock() + offset
  1280.     local r = math.floor(math.sin(clock * speed) * 127 + 128)
  1281.     local g = math.floor(math.sin(clock * speed + 2) * 127 + 128)
  1282.     local b = math.floor(math.sin(clock * speed + 4) * 127 + 128)
  1283.     return r,g,b,alpha
  1284. end
  1285.  
  1286. local cast = ffi.cast
  1287. local draw_dist = cast('float *', 0x00B7C4F0)
  1288. cast('unsigned char *', 0x005609FF)[0] = 0xEB
  1289. cast('unsigned char *', 0x00561344)[0] = 0xEB
  1290.  
  1291. function set_fog_dist(m)
  1292.     if m > 3600.0 or m < 0 then return false end
  1293.     draw_dist[0] = m
  1294.     return true
  1295. end
  1296.  
  1297. function cmdproc_set_fog_dist(param)
  1298.     param = tonumber(param)
  1299.     if param ~= nil then
  1300.         if not set_fog_dist(param) then
  1301.             sampAddChatMessage('[FogDist] {FFFFFF}Incorrect value', 0xFF5000)
  1302.         end
  1303.     end
  1304. end
  1305.  
  1306. function style()
  1307.     local r,g,b,a = rainbow(rgb_speed.v, 255, 0)
  1308.     local argb = join_argb(a, r, g, b)
  1309.     local a = a / 255
  1310.     local r = r / 255
  1311.     local g = g / 255
  1312.     local b = b / 255
  1313.     imgui.SwitchContext()
  1314.     local style = imgui.GetStyle()
  1315.     local colors = style.Colors
  1316.     local clr = imgui.Col
  1317.     local ImVec4 = imgui.ImVec4
  1318.     local ImVec2 = imgui.ImVec2
  1319.  
  1320.     style.WindowPadding = ImVec2(5, 5)
  1321.     style.WindowRounding = 0
  1322.     style.FramePadding = ImVec2(5, 5)
  1323.     style.FrameRounding = 0.0
  1324.     style.ItemSpacing = ImVec2(1, 1)
  1325.     style.ItemInnerSpacing = ImVec2(8, 6)
  1326.     style.IndentSpacing = 15.0
  1327.     style.ScrollbarSize = 15.0
  1328.     style.ScrollbarRounding = 9.0
  1329.     style.GrabMinSize = 5.0
  1330.     style.GrabRounding = 3.0
  1331.  
  1332.     colors[clr.Text] = ImVec4(0.80, 0.80, 0.83, 1.00)
  1333.     colors[clr.TextDisabled] = ImVec4(0.24, 0.23, 0.29, 1.00)
  1334.     colors[clr.WindowBg] = ImVec4(0.06, 0.05, 0.07, 1.00)
  1335.     colors[clr.ChildWindowBg] = ImVec4(0.07, 0.07, 0.09, 1.00)
  1336.     colors[clr.PopupBg] = ImVec4(0.07, 0.07, 0.09, 1.00)
  1337.     colors[clr.Border] = ImVec4(0.80, 0.80, 0.83, 0.88)
  1338.     colors[clr.BorderShadow] = ImVec4(0.92, 0.91, 0.88, 0.00)
  1339.     colors[clr.FrameBg] = ImVec4(0.10, 0.09, 0.12, 1.00)
  1340.     colors[clr.FrameBgHovered] = ImVec4(0.24, 0.23, 0.29, 1.00)
  1341.     colors[clr.FrameBgActive] = ImVec4(0.56, 0.56, 0.58, 1.00)
  1342.     colors[clr.TitleBg] = ImVec4(0.76, 0.31, 0.00, 1.00)
  1343.     colors[clr.TitleBgCollapsed] = ImVec4(1.00, 0.98, 0.95, 0.75)
  1344.     colors[clr.TitleBgActive] = ImVec4(r, g, b, 1.00)
  1345.     colors[clr.MenuBarBg] = ImVec4(0.10, 0.09, 0.12, 1.00)
  1346.     colors[clr.ScrollbarBg] = ImVec4(0.10, 0.09, 0.12, 1.00)
  1347.     colors[clr.ScrollbarGrab] = ImVec4(0.80, 0.80, 0.83, 0.31)
  1348.     colors[clr.ScrollbarGrabHovered] = ImVec4(0.56, 0.56, 0.58, 1.00)
  1349.     colors[clr.ScrollbarGrabActive] = ImVec4(0.06, 0.05, 0.07, 1.00)
  1350.     colors[clr.ComboBg] = ImVec4(0.19, 0.18, 0.21, 1.00)
  1351.     colors[clr.CheckMark] = ImVec4(r, g, b, 1.00)
  1352.     colors[clr.SliderGrab] = ImVec4(r, g, b, 0.53)
  1353.     colors[clr.SliderGrabActive] = ImVec4(r, g, b, 1.00)
  1354.     colors[clr.Button] = ImVec4(0.10, 0.09, 0.12, 1.00)
  1355.     colors[clr.ButtonHovered] = ImVec4(0.24, 0.23, 0.29, 1.00)
  1356.     colors[clr.ButtonActive] = ImVec4(0.56, 0.56, 0.58, 1.00)
  1357.     colors[clr.Header] = ImVec4(0.10, 0.09, 0.12, 1.00)
  1358.     colors[clr.HeaderHovered] = ImVec4(0.56, 0.56, 0.58, 1.00)
  1359.     colors[clr.HeaderActive] = ImVec4(0.06, 0.05, 0.07, 1.00)
  1360.     colors[clr.ResizeGrip] = ImVec4(0.00, 0.00, 0.00, 0.00)
  1361.     colors[clr.ResizeGripHovered] = ImVec4(0.56, 0.56, 0.58, 1.00)
  1362.     colors[clr.ResizeGripActive] = ImVec4(0.06, 0.05, 0.07, 1.00)
  1363.     colors[clr.CloseButton] = ImVec4(0.40, 0.39, 0.38, 0.16)
  1364.     colors[clr.CloseButtonHovered] = ImVec4(0.40, 0.39, 0.38, 0.39)
  1365.     colors[clr.CloseButtonActive] = ImVec4(0.40, 0.39, 0.38, 1.00)
  1366.     colors[clr.PlotLines] = ImVec4(0.40, 0.39, 0.38, 0.63)
  1367.     colors[clr.PlotLinesHovered] = ImVec4(0.25, 1.00, 0.00, 1.00)
  1368.     colors[clr.PlotHistogram] = ImVec4(0.40, 0.39, 0.38, 0.63)
  1369.     colors[clr.PlotHistogramHovered] = ImVec4(0.25, 1.00, 0.00, 1.00)
  1370.     colors[clr.TextSelectedBg] = ImVec4(0.25, 1.00, 0.00, 0.43)
  1371.     colors[clr.ModalWindowDarkening] = ImVec4(1.00, 0.98, 0.95, 0.73)
  1372. end
  1373.  
  1374.     local md5 = {
  1375.       _VERSION     = "md5.lua 1.1.0",
  1376.       _DESCRIPTION = "MD5 computation in Lua (5.1-3, LuaJIT)",
  1377.       _URL         = "https://github.com/kikito/md5.lua",
  1378.       _LICENSE     = [[
  1379.       MIT LICENSE
  1380.  
  1381.       Copyright (c) 2013 Enrique Garcia Cota + Adam Baldwin + hanzao + Equi 4 Software
  1382.  
  1383.       Permission is hereby granted, free of charge, to any person obtaining a
  1384.       copy of this software and associated documentation files (the
  1385.       "Software"), to deal in the Software without restriction, including
  1386.       without limitation the rights to use, copy, modify, merge, publish,
  1387.       distribute, sublicense, and/or sell copies of the Software, and to
  1388.       permit persons to whom the Software is furnished to do so, subject to
  1389.       the following conditions:
  1390.  
  1391.       The above copyright notice and this permission notice shall be included
  1392.       in all copies or substantial portions of the Software.
  1393.  
  1394.       THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1395.       OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1396.       MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  1397.       IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  1398.       CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  1399.       TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  1400.       SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  1401.       ]]
  1402.     }
  1403.  
  1404.     -- bit lib implementions
  1405.  
  1406.     local char, byte, format, rep, sub =
  1407.     string.char, string.byte, string.format, string.rep, string.sub
  1408.     local bit_or, bit_and, bit_not, bit_xor, bit_rshift, bit_lshift
  1409.  
  1410.     local ok, bit = pcall(require, 'bit')
  1411.     if ok then
  1412.       bit_or, bit_and, bit_not, bit_xor, bit_rshift, bit_lshift = bit.bor, bit.band, bit.bnot, bit.bxor, bit.rshift, bit.lshift
  1413.     else
  1414.       ok, bit = pcall(require, 'bit32')
  1415.  
  1416.       if ok then
  1417.  
  1418.         bit_not = bit.bnot
  1419.  
  1420.         local tobit = function(n)
  1421.         return n <= 0x7fffffff and n or -(bit_not(n) + 1)
  1422.       end
  1423.  
  1424.       local normalize = function(f)
  1425.       return function(a,b) return tobit(f(tobit(a), tobit(b))) end
  1426.     end
  1427.  
  1428.     bit_or, bit_and, bit_xor = normalize(bit.bor), normalize(bit.band), normalize(bit.bxor)
  1429.     bit_rshift, bit_lshift = normalize(bit.rshift), normalize(bit.lshift)
  1430.  
  1431.   else
  1432.  
  1433.     local function tbl2number(tbl)
  1434.       local result = 0
  1435.       local power = 1
  1436.       for i = 1, #tbl do
  1437.         result = result + tbl[i] * power
  1438.         power = power * 2
  1439.       end
  1440.       return result
  1441.     end
  1442.  
  1443.     local function expand(t1, t2)
  1444.       local big, small = t1, t2
  1445.       if(#big < #small) then
  1446.         big, small = small, big
  1447.       end
  1448.       -- expand small
  1449.       for i = #small + 1, #big do
  1450.         small[i] = 0
  1451.       end
  1452.     end
  1453.  
  1454.     local to_bits -- needs to be declared before bit_not
  1455.  
  1456.     bit_not = function(n)
  1457.     local tbl = to_bits(n)
  1458.     local size = math.max(#tbl, 32)
  1459.     for i = 1, size do
  1460.       if(tbl[i] == 1) then
  1461.         tbl[i] = 0
  1462.       else
  1463.         tbl[i] = 1
  1464.       end
  1465.     end
  1466.     return tbl2number(tbl)
  1467.   end
  1468.  
  1469.   -- defined as local above
  1470.   to_bits = function (n)
  1471.   if(n < 0) then
  1472.     -- negative
  1473.     return to_bits(bit_not(math.abs(n)) + 1)
  1474.   end
  1475.   -- to bits table
  1476.   local tbl = {}
  1477.   local cnt = 1
  1478.   local last
  1479.   while n > 0 do
  1480.     last      = n % 2
  1481.     tbl[cnt]  = last
  1482.     n         = (n-last)/2
  1483.     cnt       = cnt + 1
  1484.   end
  1485.  
  1486.   return tbl
  1487. end
  1488.  
  1489. bit_or = function(m, n)
  1490. local tbl_m = to_bits(m)
  1491. local tbl_n = to_bits(n)
  1492. expand(tbl_m, tbl_n)
  1493.  
  1494. local tbl = {}
  1495. for i = 1, #tbl_m do
  1496.   if(tbl_m[i]== 0 and tbl_n[i] == 0) then
  1497.     tbl[i] = 0
  1498.   else
  1499.     tbl[i] = 1
  1500.   end
  1501. end
  1502.  
  1503. return tbl2number(tbl)
  1504. end
  1505.  
  1506. bit_and = function(m, n)
  1507. local tbl_m = to_bits(m)
  1508. local tbl_n = to_bits(n)
  1509. expand(tbl_m, tbl_n)
  1510.  
  1511. local tbl = {}
  1512. for i = 1, #tbl_m do
  1513. if(tbl_m[i]== 0 or tbl_n[i] == 0) then
  1514.   tbl[i] = 0
  1515. else
  1516.   tbl[i] = 1
  1517. end
  1518. end
  1519.  
  1520. return tbl2number(tbl)
  1521. end
  1522.  
  1523. bit_xor = function(m, n)
  1524. local tbl_m = to_bits(m)
  1525. local tbl_n = to_bits(n)
  1526. expand(tbl_m, tbl_n)
  1527.  
  1528. local tbl = {}
  1529. for i = 1, #tbl_m do
  1530. if(tbl_m[i] ~= tbl_n[i]) then
  1531. tbl[i] = 1
  1532. else
  1533. tbl[i] = 0
  1534. end
  1535. end
  1536.  
  1537. return tbl2number(tbl)
  1538. end
  1539.  
  1540. bit_rshift = function(n, bits)
  1541. local high_bit = 0
  1542. if(n < 0) then
  1543. -- negative
  1544. n = bit_not(math.abs(n)) + 1
  1545. high_bit = 0x80000000
  1546. end
  1547.  
  1548. local floor = math.floor
  1549.  
  1550. for i=1, bits do
  1551. n = n/2
  1552. n = bit_or(floor(n), high_bit)
  1553. end
  1554. return floor(n)
  1555. end
  1556.  
  1557. bit_lshift = function(n, bits)
  1558. if(n < 0) then
  1559. -- negative
  1560. n = bit_not(math.abs(n)) + 1
  1561. end
  1562.  
  1563. for i=1, bits do
  1564. n = n*2
  1565. end
  1566. return bit_and(n, 0xFFFFFFFF)
  1567. end
  1568. end
  1569. end
  1570.  
  1571. -- convert little-endian 32-bit int to a 4-char string
  1572. local function lei2str(i)
  1573. local f=function (s) return char( bit_and( bit_rshift(i, s), 255)) end
  1574. return f(0)..f(8)..f(16)..f(24)
  1575. end
  1576.  
  1577. -- convert raw string to big-endian int
  1578. local function str2bei(s)
  1579. local v=0
  1580. for i=1, #s do
  1581. v = v * 256 + byte(s, i)
  1582. end
  1583. return v
  1584. end
  1585.  
  1586. -- convert raw string to little-endian int
  1587. local function str2lei(s)
  1588. local v=0
  1589. for i = #s,1,-1 do
  1590. v = v*256 + byte(s, i)
  1591. end
  1592. return v
  1593. end
  1594.  
  1595. -- cut up a string in little-endian ints of given size
  1596. local function cut_le_str(s,...)
  1597. local o, r = 1, {}
  1598. local args = {...}
  1599. for i=1, #args do
  1600. table.insert(r, str2lei(sub(s, o, o + args[i] - 1)))
  1601. o = o + args[i]
  1602. end
  1603. return r
  1604. end
  1605.  
  1606. local swap = function (w) return str2bei(lei2str(w)) end
  1607.  
  1608. -- An MD5 mplementation in Lua, requires bitlib (hacked to use LuaBit from above, ugh)
  1609. -- 10/02/2001 [email protected]
  1610.  
  1611. local CONSTS = {
  1612. 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
  1613. 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
  1614. 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
  1615. 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
  1616. 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
  1617. 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
  1618. 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
  1619. 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
  1620. 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
  1621. 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
  1622. 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
  1623. 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
  1624. 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
  1625. 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
  1626. 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
  1627. 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
  1628. 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476
  1629. }
  1630.  
  1631. local f=function (x,y,z) return bit_or(bit_and(x,y),bit_and(-x-1,z)) end
  1632. local g=function (x,y,z) return bit_or(bit_and(x,z),bit_and(y,-z-1)) end
  1633. local h=function (x,y,z) return bit_xor(x,bit_xor(y,z)) end
  1634. local i=function (x,y,z) return bit_xor(y,bit_or(x,-z-1)) end
  1635. local z=function (ff,a,b,c,d,x,s,ac)
  1636. a=bit_and(a+ff(b,c,d)+x+ac,0xFFFFFFFF)
  1637. -- be *very* careful that left shift does not cause rounding!
  1638. return bit_or(bit_lshift(bit_and(a,bit_rshift(0xFFFFFFFF,s)),s),bit_rshift(a,32-s))+b
  1639. end
  1640.  
  1641. local function transform(A,B,C,D,X)
  1642. local a,b,c,d=A,B,C,D
  1643. local t=CONSTS
  1644.  
  1645. a=z(f,a,b,c,d,X[ 0], 7,t[ 1])
  1646. d=z(f,d,a,b,c,X[ 1],12,t[ 2])
  1647. c=z(f,c,d,a,b,X[ 2],17,t[ 3])
  1648. b=z(f,b,c,d,a,X[ 3],22,t[ 4])
  1649. a=z(f,a,b,c,d,X[ 4], 7,t[ 5])
  1650. d=z(f,d,a,b,c,X[ 5],12,t[ 6])
  1651. c=z(f,c,d,a,b,X[ 6],17,t[ 7])
  1652. b=z(f,b,c,d,a,X[ 7],22,t[ 8])
  1653. a=z(f,a,b,c,d,X[ 8], 7,t[ 9])
  1654. d=z(f,d,a,b,c,X[ 9],12,t[10])
  1655. c=z(f,c,d,a,b,X[10],17,t[11])
  1656. b=z(f,b,c,d,a,X[11],22,t[12])
  1657. a=z(f,a,b,c,d,X[12], 7,t[13])
  1658. d=z(f,d,a,b,c,X[13],12,t[14])
  1659. c=z(f,c,d,a,b,X[14],17,t[15])
  1660. b=z(f,b,c,d,a,X[15],22,t[16])
  1661.  
  1662. a=z(g,a,b,c,d,X[ 1], 5,t[17])
  1663. d=z(g,d,a,b,c,X[ 6], 9,t[18])
  1664. c=z(g,c,d,a,b,X[11],14,t[19])
  1665. b=z(g,b,c,d,a,X[ 0],20,t[20])
  1666. a=z(g,a,b,c,d,X[ 5], 5,t[21])
  1667. d=z(g,d,a,b,c,X[10], 9,t[22])
  1668. c=z(g,c,d,a,b,X[15],14,t[23])
  1669. b=z(g,b,c,d,a,X[ 4],20,t[24])
  1670. a=z(g,a,b,c,d,X[ 9], 5,t[25])
  1671. d=z(g,d,a,b,c,X[14], 9,t[26])
  1672. c=z(g,c,d,a,b,X[ 3],14,t[27])
  1673. b=z(g,b,c,d,a,X[ 8],20,t[28])
  1674. a=z(g,a,b,c,d,X[13], 5,t[29])
  1675. d=z(g,d,a,b,c,X[ 2], 9,t[30])
  1676. c=z(g,c,d,a,b,X[ 7],14,t[31])
  1677. b=z(g,b,c,d,a,X[12],20,t[32])
  1678.  
  1679. a=z(h,a,b,c,d,X[ 5], 4,t[33])
  1680. d=z(h,d,a,b,c,X[ 8],11,t[34])
  1681. c=z(h,c,d,a,b,X[11],16,t[35])
  1682. b=z(h,b,c,d,a,X[14],23,t[36])
  1683. a=z(h,a,b,c,d,X[ 1], 4,t[37])
  1684. d=z(h,d,a,b,c,X[ 4],11,t[38])
  1685. c=z(h,c,d,a,b,X[ 7],16,t[39])
  1686. b=z(h,b,c,d,a,X[10],23,t[40])
  1687. a=z(h,a,b,c,d,X[13], 4,t[41])
  1688. d=z(h,d,a,b,c,X[ 0],11,t[42])
  1689. c=z(h,c,d,a,b,X[ 3],16,t[43])
  1690. b=z(h,b,c,d,a,X[ 6],23,t[44])
  1691. a=z(h,a,b,c,d,X[ 9], 4,t[45])
  1692. d=z(h,d,a,b,c,X[12],11,t[46])
  1693. c=z(h,c,d,a,b,X[15],16,t[47])
  1694. b=z(h,b,c,d,a,X[ 2],23,t[48])
  1695.  
  1696. a=z(i,a,b,c,d,X[ 0], 6,t[49])
  1697. d=z(i,d,a,b,c,X[ 7],10,t[50])
  1698. c=z(i,c,d,a,b,X[14],15,t[51])
  1699. b=z(i,b,c,d,a,X[ 5],21,t[52])
  1700. a=z(i,a,b,c,d,X[12], 6,t[53])
  1701. d=z(i,d,a,b,c,X[ 3],10,t[54])
  1702. c=z(i,c,d,a,b,X[10],15,t[55])
  1703. b=z(i,b,c,d,a,X[ 1],21,t[56])
  1704. a=z(i,a,b,c,d,X[ 8], 6,t[57])
  1705. d=z(i,d,a,b,c,X[15],10,t[58])
  1706. c=z(i,c,d,a,b,X[ 6],15,t[59])
  1707. b=z(i,b,c,d,a,X[13],21,t[60])
  1708. a=z(i,a,b,c,d,X[ 4], 6,t[61])
  1709. d=z(i,d,a,b,c,X[11],10,t[62])
  1710. c=z(i,c,d,a,b,X[ 2],15,t[63])
  1711. b=z(i,b,c,d,a,X[ 9],21,t[64])
  1712.  
  1713. return bit_and(A+a,0xFFFFFFFF),bit_and(B+b,0xFFFFFFFF),
  1714. bit_and(C+c,0xFFFFFFFF),bit_and(D+d,0xFFFFFFFF)
  1715. end
  1716.  
  1717. ----------------------------------------------------------------
  1718.  
  1719. local function md5_update(self, s)
  1720. self.pos = self.pos + #s
  1721. s = self.buf .. s
  1722. for ii = 1, #s - 63, 64 do
  1723. local X = cut_le_str(sub(s,ii,ii+63),4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4)
  1724. assert(#X == 16)
  1725. X[0] = table.remove(X,1) -- zero based!
  1726. self.a,self.b,self.c,self.d = transform(self.a,self.b,self.c,self.d,X)
  1727. end
  1728. self.buf = sub(s, math.floor(#s/64)*64 + 1, #s)
  1729. return self
  1730. end
  1731.  
  1732. local function md5_finish(self)
  1733. local msgLen = self.pos
  1734. local padLen = 56 - msgLen % 64
  1735.  
  1736. if msgLen % 64 > 56 then padLen = padLen + 64 end
  1737.  
  1738. if padLen == 0 then padLen = 64 end
  1739.  
  1740. local s = char(128) .. rep(char(0),padLen-1) .. lei2str(bit_and(8*msgLen, 0xFFFFFFFF)) .. lei2str(math.floor(msgLen/0x20000000))
  1741. md5_update(self, s)
  1742.  
  1743. assert(self.pos % 64 == 0)
  1744. return lei2str(self.a) .. lei2str(self.b) .. lei2str(self.c) .. lei2str(self.d)
  1745. end
  1746.  
  1747. ----------------------------------------------------------------
  1748.  
  1749. function md5.new()
  1750. return { a = CONSTS[65], b = CONSTS[66], c = CONSTS[67], d = CONSTS[68],
  1751. pos = 0,
  1752. buf = '',
  1753. update = md5_update,
  1754. finish = md5_finish }
  1755. end
  1756.  
  1757. function md5.tohex(s)
  1758. return format("%08x%08x%08x%08x", str2bei(sub(s, 1, 4)), str2bei(sub(s, 5, 8)), str2bei(sub(s, 9, 12)), str2bei(sub(s, 13, 16)))
  1759. end
  1760.  
  1761. function md5.sum(s)
  1762. return md5.new():update(s):finish()
  1763. end
  1764.  
  1765. function md5sumhexa(s)
  1766. return md5.tohex(md5.sum(s))
  1767. end
Add Comment
Please, Sign In to add comment