From 8423a1ed6d400adc22c4ab46e35531cdc19afe71 Mon Sep 17 00:00:00 2001 From: rubin Date: Sat, 28 Jan 2023 21:15:56 +0300 Subject: [PATCH] initial commit --- README.md | 5 + changelog | 2 + mafia-tools.lua | 327 ++++++++++++++++++++++++++++++++++++++++++ pictures/download.png | Bin 0 -> 5548 bytes version | 1 + 5 files changed, 335 insertions(+) create mode 100644 README.md create mode 100644 changelog create mode 100644 mafia-tools.lua create mode 100644 pictures/download.png create mode 100644 version diff --git a/README.md b/README.md new file mode 100644 index 0000000..b2c3a4f --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +[![Cкачать](pictures/download.png)](mafia-tools.lua) +# [**Cкачать**](mafia-tools.lua) +Перенести файл mafia-tools.lua в папку moonloader + + diff --git a/changelog b/changelog new file mode 100644 index 0000000..0a6bd75 --- /dev/null +++ b/changelog @@ -0,0 +1,2 @@ +Версия от 28.01.2023 +Релиз скрипта \ No newline at end of file diff --git a/mafia-tools.lua b/mafia-tools.lua new file mode 100644 index 0000000..eed0583 --- /dev/null +++ b/mafia-tools.lua @@ -0,0 +1,327 @@ +script_name('mafia-tools') +script_author("Serhiy_Rubin") +script_version("28.01.2023") + +sampev = require 'samp.events' + +function main() + if not isSampLoaded() or not isSampfuncsLoaded() then return end + while not isSampAvailable() do wait(0) end + lua_thread.create(script_update.main) + repeat wait(0) until sampGetCurrentServerName() ~= "SA-MP" + repeat wait(0) until sampGetCurrentServerName():find("Samp%-Rp.Ru") or sampGetCurrentServerName():find("SRP") + server = sampGetCurrentServerName():gsub("|", "") + server = (server:find("02") and "Two" or + (server:find("Revo") and "Revolution" or + (server:find("Legacy") and "Legacy" or (server:find("Classic") and "Classic" or + (server:find("Zero Two") and "Two" or ""))))) + if server == "" then + thisScript():unload() + end + + + + wait(-1) +end + + + + + +-->> CONFIG +config = {} +config.data = {} +config.default = { + time_2min = 0 + +} +config.address = string.format("%s\\moonloader\\%s.json", getGameDirectory(), thisScript().name) +config.init = function() + if not doesFileExist(config.address) then + config.save(config.default) + end + config.read() + config.save(config.data) +end +config.save = function(data) + local file, error = io.open(config.address, "w") + if file == nil then + addChatMessage(error) + end + file:write(encodeJson(data)) + file:flush() + io.close(file) +end +config.read = function() + local readJson = function() + local file, error = io.open(config.address, "r") + if file then + config.data = decodeJson(file:read("*a")) + io.close(file) + if config.data == nil then + addChatMessage("Ошибка чтения конфига! Сбрасываю конфиг!") + config.save(config.default) + end + end + end + local result = pcall(readJson) + if not result then + addChatMessage("Ошибка чтения конфига! Сбрасываю конфиг!") + config.save(config.default) + end + if config.data == nil then + config.error = true + addChatMessage("Ошибка чтения конфига! Пробую ещё раз прочесть") + config.read() + else + if config.error then + addChatMessage("Конфиг был успешно загружен!") + config.error = false + end + end +end + +-->> UPDATE MODULE +function openURL(url, fpath) + local text = "" + local file_download = false + local download_final = false + + + if doesFileExist(fpath) then + os.remove(fpath) + end + + downloadUrlToFile(url, fpath, function(id, status, p1, p2) + if status == dlstatus.STATUS_ENDDOWNLOADDATA then + file_download = true + end + if status == dlstatus.STATUSEX_ENDDOWNLOAD then + download_final = true + end + end + ) + + repeat + wait(1000) + until download_final or file_download + + if file_download then + local f = io.open(fpath, "r") + if f then + text = f:read("*a") + io.close(f) + end + os.remove(fpath) + end + + if (text:find("Not found") and not text:find('"Not found"')) or text == "" then + text = "" + addChatMessage("Не удалось скачать обновление по ссылке:") + addChatMessage(url) + end + + return text +end + +function addChatMessage(text) + local tag = string.format("{667dff}[%s]{FFFFFF} ", thisScript().name) + sampAddChatMessage(tag..text, 0xFFFFFFFF) +end + +script_update = { + version_url = "http://git.deadpoo.net/rubin/mafia-tools/raw/branch/master/version", + script_url = "http://git.deadpoo.net/rubin/mafia-tools/raw/branch/master/mafia-tools.lua", + changelog_url = "http://git.deadpoo.net/rubin/mafia-tools/raw/branch/master/changelog", + address_ini = string.format("rubin-mods-updates\\%s.ini", thisScript().name), + main = function() + if not doesDirectoryExist("moonloader\\config\\rubin-mods-updates") then + createDirectory("moonloader\\config\\rubin-mods-updates") + end + local ini = inicfg.load({ + settings = { + check_update = true, + auto_update = true, + server_version = "" + } + }, script_update.address_ini) + ini.settings.version_url = script_update.version_url + ini.settings.script_url = script_update.script_url + ini.settings.changelog_url = script_update.changelog_url + ini.settings.version = thisScript().version + ini.settings.script_name = thisScript().name + local command = (thisScript().name:gsub(" ", "").."-update"):lower() + sampRegisterChatCommand(command, script_update.command) + if ini.settings.check_update or ini.settings.auto_update then + local fpath = os.tmpname() + local result, text = pcall(openURL, script_update.version_url, fpath) + if result then + ini.settings.server_version = text + if text ~= "" and text ~= thisScript().version then + addChatMessage( string.format("Вышла новая версия '%s'. Текущая: '%s'", text, thisScript().version) ) + if ini.settings.auto_update then + addChatMessage( string.format("Автообновление скрипта включено. Процесс запущен!") ) + script_update.command() + else + addChatMessage( string.format("Автообновление скрипта выключено. Обновить самому: /%s", command) ) + end + end + end + end + inicfg.save(ini, script_update.address_ini) + script_update.menu.init() + end, + command = function() + lua_thread.create(function() + local fpath = os.tmpname() + local result, text = pcall(openURL, script_update.version_url, fpath) + if result then + if text ~= "" and text ~= thisScript().version then + addChatMessage( string.format("Вышла новая версия '%s'. Текущая: '%s'", text, thisScript().version) ) + local fpath = os.tmpname() + local result, text = pcall(openURL, script_update.script_url, fpath) + if result and text ~= "" and text:find(thisScript().name:gsub("%-", "%%-")) then + local file, error = io.open(thisScript().path, "w") + if file ~= nil then + file:write(text) + file:flush() + io.close(file) + addChatMessage("Обновление завершено, скрипт перезагружен!") + wait(500) + thisScript():reload() + end + end + else + addChatMessage("У Вас установлена последняя версия!") + end + end + end) + end, + menu = { + dialog = {}, + ini = {}, + init = function() + if not sampIsChatCommandDefined("rubin-mods") then + sampAddChatMessage("{667dff}[RUBIN MODS]{FFFFFF} Управление обновлениями скриптов: /rubin-mods", 0xFFFFFFFF) + sampRegisterChatCommand("rubin-mods",script_update.menu.show) + while true do + wait(0) + local result, button, list, input = sampHasDialogRespond(2160) + if result and button == 1 then + if script_update.menu.ini[list+1] ~= nil and script_update.menu.dialog[list+1] ~= nil then + script_update.menu.dialog[list+1](script_update.menu.ini[list+1]) + end + end + local result, button, list, input = sampHasDialogRespond(2162) + if result then + if button == 1 then + if script_update.menu2.text[list+1] ~= nil and script_update.menu2.dialog[list+1] ~= nil then + script_update.menu2.dialog[list+1]() + end + else + script_update.menu.show() + end + end + local result, button, list, input = sampHasDialogRespond(2161) + if result then + script_update.menu2.show(script_update.menu2.data) + end + end + end + end, + show = function() + script_update.menu.dialog = {} + script_update.menu.ini = {} + local text = "" + if doesDirectoryExist("moonloader\\config\\rubin-mods-updates") then + local FileHandle, FileName = findFirstFile("moonloader\\config\\rubin-mods-updates\\*") + while FileName ~= nil do + if FileName ~= nil and FileName ~= ".." and FileName ~= "." and FileName:find("%.ini") then + local address = string.format("moonloader\\config\\rubin-mods-updates\\%s", FileName) + if doesFileExist(address) then + local ini = inicfg.load({}, address) + script_update.menu.ini[#script_update.menu.ini+1] = address + text = string.format("%s%s\n", text, string.format("%s\t%s%s", ini.settings.script_name, (ini.settings.version == ini.settings.server_version and "{59fc30}" or "{ff0000}"),ini.settings.version)) + script_update.menu.dialog[#script_update.menu.dialog+1] = function(data) + script_update.menu2.show(data) + end + end + end + FileName = findNextFile(FileHandle) + end + findClose(FileHandle) + else + text = "Не найдена директория:\t\n moonloader\\config\\rubin-mods-updates\t" + end + sampShowDialog(2160,"Обновление скриптов: Rubin Mods","Скрипт\tВерсия\n"..text,"Выбрать","Закрыть",5) + end + }, + menu2 = { + data = {}, + text = {}, + dialog = {}, + show = function(data) + script_update.menu2.data = data + script_update.menu2.text = {} + script_update.menu2.dialog = {} + if doesFileExist(data) then + local ini = inicfg.load({}, data) + script_update.menu2.text[#script_update.menu2.text+1] = string.format("Автообновление %s", (ini.settings.auto_update and "{59fc30}ON" or "{ff0000}OFF")) + script_update.menu2.dialog[#script_update.menu2.dialog+1] = function() + ini.settings.auto_update = not ini.settings.auto_update + inicfg.save(ini, data) + script_update.menu2.show(data) + end + if not ini.settings.auto_update then + script_update.menu2.text[#script_update.menu2.text+1] = string.format("Проверять обновления %s", (ini.settings.check_update and "{59fc30}ON" or "{ff0000}OFF")) + script_update.menu2.dialog[#script_update.menu2.dialog+1] = function() + ini.settings.check_update = not ini.settings.check_update + inicfg.save(ini, data) + script_update.menu2.show(data) + end + end + script_update.menu2.text[#script_update.menu2.text+1] = string.format("Последние изменения") + script_update.menu2.dialog[#script_update.menu2.dialog+1] = function() + script_update.changelog(ini.settings.changelog_url, ini.settings.script_name) + end + script_update.menu2.text[#script_update.menu2.text+1] = string.format("Удалить из списка") + script_update.menu2.dialog[#script_update.menu2.dialog+1] = function() + os.remove(data) + script_update.menu.show() + end + local text = "" + for i = 1, #script_update.menu2.text do + text = text..script_update.menu2.text[i].."\n" + end + sampShowDialog(2162,"Настройки обновления для "..ini.settings.script_name,text,"Выбрать","Назад",2) + end + end + }, + changelog = function(url, name) + local fpath = os.tmpname() + local result, text = pcall(openURL, url, fpath) + if result then + sampShowDialog(2161,"Changelog - "..name,text,"Выбрать","Назад",4) + end + end +} + +-->> SCRIPT UTF-8 +-->> utf8(table path, incoming variables encoding, outcoming variables encoding) +-->> table path example { "sampev", "onShowDialog" } +-->> encoding options nil | AnsiToUtf8 | Utf8ToAnsi +_utf8 = load([=[return function(utf8_func, in_encoding, out_encoding); if encoding == nil then; encoding = require("encoding"); encoding.default = "CP1251"; u8 = encoding.UTF8; end; if type(utf8_func) ~= "table" then; return false; end; if AnsiToUtf8 == nil or Utf8ToAnsi == nil then; AnsiToUtf8 = function(text); return u8(text); end; Utf8ToAnsi = function(text); return u8:decode(text); end; end; if _UTF8_FUNCTION_SAVE == nil then; _UTF8_FUNCTION_SAVE = {}; end; local change_var = "_G"; for s = 1, #utf8_func do; change_var = string.format('%s["%s"]', change_var, utf8_func[s]); end; if _UTF8_FUNCTION_SAVE[change_var] == nil then; _UTF8_FUNCTION = function(...); local pack = table.pack(...); readTable = function(t, enc); for k, v in next, t do; if type(v) == 'table' then; readTable(v, enc); else; if enc ~= nil and (enc == "AnsiToUtf8" or enc == "Utf8ToAnsi") then; if type(k) == "string" then; k = _G[enc](k); end; if type(v) == "string" then; t[k] = _G[enc](v); end; end; end; end; return t; end; return table.unpack(readTable({_UTF8_FUNCTION_SAVE[change_var](table.unpack(readTable(pack, in_encoding)))}, out_encoding)); end; local text = string.format("_UTF8_FUNCTION_SAVE['%s'] = %s; %s = _UTF8_FUNCTION;", change_var, change_var, change_var); load(text)(); _UTF8_FUNCTION = nil; end; return true; end]=]) +function utf8(...) + pcall(_utf8(), ...) +end + +utf8({ "sampShowDialog" }, "Utf8ToAnsi") +utf8({ "sampSendChat" }, "Utf8ToAnsi") +utf8({ "sampAddChatMessage" }, "Utf8ToAnsi") +utf8({ "print" }, "Utf8ToAnsi") +utf8({ "renderGetFontDrawTextLength" }, "Utf8ToAnsi") +utf8({ "renderFontDrawText" }, "Utf8ToAnsi") +utf8({ "sampHasDialogRespond" }, nil, "AnsiToUtf8") +utf8({ "sampev", "onShowDialog" }, "AnsiToUtf8", "Utf8ToAnsi") +utf8({ "sampev", "onServerMessage" }, "AnsiToUtf8", "Utf8ToAnsi") +utf8({ "sampev", "onCreate3DText" }, "AnsiToUtf8", "Utf8ToAnsi") \ No newline at end of file diff --git a/pictures/download.png b/pictures/download.png new file mode 100644 index 0000000000000000000000000000000000000000..7c13b4acd8de1fea9e555a790829dfc3e1150171 GIT binary patch literal 5548 zcmd5=XH*njlWssj$x0AVkSqd%k`ZOdpk&FCC4(@)0E1+ZAVG=4z>rarLyj`!oO6yt zMlwi_v-7@x_d9!b|81Sq)phUbuD-XbZq?Hjrmm_$N<>ct008M*McMZNfMbl6!|vi@ z`8Iy1BldRBNl_mH0OVi)xo~K@vO@rX+W4)kl$J-z?!2ue<>Uc~r$zwKkPqAr1AIu`U%-TgxzKF|`mIqQuhe&c# z;Y#Z3>#q#^chXaMuG|fl4wfE1e??1rmzm~2F^_IaejD6?rn$M4!Hwg#}}@ z5N&i_UEPEbQ(@5}oIS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tClA@#uD3wWEOK-aZ{FZ6-kfbHC-Gk_X3B8u`ey4hpSFcTHkMggS#$^piSOX5 zn71YLR|yNp7*rQsTEQZE4M-iJCtK0ZD>w3u;#S?U?bv<`LOzx)xaHx^&~bz~vko^5 zn>xN7*V!z!Fo;7FV6gEDb*gNws>-XOkJu=T?Y77?GsF5-LSo9m;J7N%CHV!-bTIkvDlms0^!<~%{YkT|I^9k6y z?DzRvNG(L@=H@0NBjf4msUh!V=SJ%N)=<2r-=*epaeTsKkTb{mnM!-;?ezsh;$EN= z1k&5zKiYFnONMn7s>;vrIBxl=5)I!p6=RVWS9zJ^U^1xD%66>5hmu1%@i9e-`Njaa z;kL1b^#`D-bP(XICyQgPlng)XLE+}^x4~53d->oN#BnYA)#+Eb+py{|t z(g$v;=Y$>nkGZEJB#YArK4eFGtB1`9g>-^W84XG{LL`3JauYqlqxZY%ppk?WM@|Eq z8Hb?MD%fu0htby7l|RFYF|6{Yl7c~5d064`8+z=l47ySf$M194Q1V?Yr|_iyPi?&a c(;S8zlrhvJ7@%N;ZNCC<R literal 0 HcmV?d00001 diff --git a/version b/version new file mode 100644 index 0000000..3ada7f6 --- /dev/null +++ b/version @@ -0,0 +1 @@ +28.01.2023 \ No newline at end of file