From e4a1c2aca2b3a7bfe4260b0db32b681d152edb85 Mon Sep 17 00:00:00 2001 From: rubin Date: Tue, 24 Jan 2023 13:19:25 +0300 Subject: [PATCH] changed utf8 on single process --- TruckHUD.lua | 112 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 65 insertions(+), 47 deletions(-) diff --git a/TruckHUD.lua b/TruckHUD.lua index 6a823bf..55103d7 100644 --- a/TruckHUD.lua +++ b/TruckHUD.lua @@ -2784,12 +2784,9 @@ function loadEvents() end end, Cid) end - wait(100) - utf8({ - { "sampev", "onShowDialog" }, - { "sampev", "onServerMessage" }, - { "sampev", "onCreate3DText" } - }, "AnsiToUtf8", "AnsiToUtf8") + utf8({ "sampev", "onShowDialog" }, "AnsiToUtf8", "AnsiToUtf8") + utf8({ "sampev", "onServerMessage" }, "AnsiToUtf8", "AnsiToUtf8") + utf8({ "sampev", "onCreate3DText" }, "AnsiToUtf8", "AnsiToUtf8") end function isTruck3dTextDefined(id) @@ -4455,64 +4452,85 @@ _utf8 = load([=[return { -- end utf8 = function(utf8_func, in_encoding, out_encoding); -if _G["encoding"] == nil then; - _G["encoding"] = require("encoding"); - _G["encoding"]["default"] = "CP1251"; - _G["u8"] = _G["encoding"]["UTF8"]; -end; -if _G["AnsiToUtf8"] == nil or _G["Utf8ToAnsi"] == nil then; - _G["AnsiToUtf8"] = function(text); - return _G["u8"](text); + if _G["encoding"] == nil then; + _G["encoding"] = require("encoding"); + _G["encoding"]["default"] = "CP1251"; + _G["u8"] = _G["encoding"]["UTF8"]; end; - _G["Utf8ToAnsi"] = function(text); - return _G["u8"]:decode(text); + if type(utf8_func) ~= "table" then; + return false; + end; + if _G["AnsiToUtf8"] == nil or _G["Utf8ToAnsi"] == nil then; + _G["AnsiToUtf8"] = function(text); + return _G["u8"](text); + end; + _G["Utf8ToAnsi"] = function(text); + return _G["u8"]:decode(text); + end; + end; + if _G["_UTF8_FUNCTION_SAVE"] == nil then; + _G["_UTF8_FUNCTION_SAVE"] = {}; end; -end; -if _G["_UTF8_FUNCTION_SAVE"] == nil then; - _G["_UTF8_FUNCTION_SAVE"] = {}; -end; -for i = 1, #utf8_func do; local change_var = "_G"; - for s = 1, #utf8_func[i] do; - change_var = string.format('%s["%s"]', change_var, utf8_func[i][s]); + for s = 1, #utf8_func do; + change_var = string.format('%s["%s"]', change_var, utf8_func[s]); end; if _G["_UTF8_FUNCTION_SAVE"][change_var] == nil then - _G["new_function"] = function(...); + _G["_UTF8_FUNCTION"] = function(...); local pack = table.pack(...); for i = 1, pack.n do; - if type(pack[i]) == "string" then; + if type(pack[i]) == "string" and in_encoding ~= nil and (in_encoding == "AnsiToUtf8" or in_encoding == "Utf8ToAnsi") then; pack[i] = _G[in_encoding](pack[i]); end; end; local unpacked = {_G["_UTF8_FUNCTION_SAVE"][change_var](table.unpack(pack))}; for i = 1, #unpacked do; - if type(unpacked[i]) == "string" then; + if type(unpacked[i]) == "string" and out_encoding ~= nil and (out_encoding == "AnsiToUtf8" or out_encoding == "Utf8ToAnsi") then; unpacked[i] = _G[out_encoding](unpacked[i]); end; end; return table.unpack(unpacked); end; - local text = string.format("_G['_UTF8_FUNCTION_SAVE']['%s'] = %s; %s = _G['new_function'];", change_var, change_var, change_var); - sampfuncsLog(text); + local text = string.format("_G['_UTF8_FUNCTION_SAVE']['%s'] = %s; %s = _G['_UTF8_FUNCTION'];", change_var, change_var, change_var); load(text)(); - _G["new_function"] = nil; - end -end; + _G["_UTF8_FUNCTION"] = nil; + end; + return true; end -utf8({ - { "sampShowDialog" }, - { "sampSendChat" }, - { "sampAddChatMessage" }, - { "print" }, - { "renderGetFontDrawTextLength" }, - { "renderFontDrawText" }, - { "sampSetCurrentDialogEditboxText" }, - { "sampCreate3dTextEx" }, - { "sampSet3dTextString" }, - { "sampCreate3dText" } -}, "Utf8ToAnsi", "AnsiToUtf8") -utf8({ - { "sampGetDialogCaption" }, - { "sampHasDialogRespond" } -}, "AnsiToUtf8", "AnsiToUtf8") \ No newline at end of file +-->> utf8(table path, incoming variables encoding, outcoming variables encoding) +-->> table path example { "sampev", "onShowDialog" } +-->> encoding options nil | AnsiToUtf8 | Utf8ToAnsi + +utf8({ "sampShowDialog" }, "Utf8ToAnsi") +utf8({ "sampSendChat" }, "Utf8ToAnsi") +utf8({ "sampAddChatMessage" }, "Utf8ToAnsi") +utf8({ "print" }, "Utf8ToAnsi") +utf8({ "renderGetFontDrawTextLength" }, "Utf8ToAnsi") +utf8({ "renderFontDrawText" }, "Utf8ToAnsi") +utf8({ "sampSetCurrentDialogEditboxText" }, "Utf8ToAnsi") +utf8({ "sampCreate3dTextEx" }, "Utf8ToAnsi") +utf8({ "sampCreate3dText" }, "Utf8ToAnsi") +utf8({ "sampGetDialogCaption" }, nil, "AnsiToUtf8") +utf8({ "sampHasDialogRespond" }, nil, "AnsiToUtf8") + + + +-- { } + +-- utf8({ +-- { "sampShowDialog" }, +-- { "sampSendChat" }, +-- { "sampAddChatMessage" }, +-- { "print" }, +-- { "renderGetFontDrawTextLength" }, +-- { "renderFontDrawText" }, +-- { "sampSetCurrentDialogEditboxText" }, +-- { "sampCreate3dTextEx" }, +-- { "sampSet3dTextString" }, +-- { "sampCreate3dText" } +-- }, "Utf8ToAnsi", "AnsiToUtf8") +-- utf8({ +-- { "sampGetDialogCaption" }, +-- { "sampHasDialogRespond" } +-- }, "AnsiToUtf8", "AnsiToUtf8") \ No newline at end of file