|
|
|
@ -2808,9 +2808,9 @@ function loadEvents() |
|
|
|
|
end |
|
|
|
|
end, Cid) |
|
|
|
|
end |
|
|
|
|
utf8({ "sampev", "onShowDialog" }, "AnsiToUtf8") |
|
|
|
|
utf8({ "sampev", "onShowDialog" }, "AnsiToUtf8", "Utf8ToAnsi") |
|
|
|
|
utf8({ "sampev", "onServerMessage" }, "AnsiToUtf8", "Utf8ToAnsi") |
|
|
|
|
utf8({ "sampev", "onCreate3DText" }, "AnsiToUtf8") |
|
|
|
|
utf8({ "sampev", "onCreate3DText" }, "AnsiToUtf8", "Utf8ToAnsi") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
function isTruck3dTextDefined(id) |
|
|
|
@ -4421,66 +4421,11 @@ script_update = { |
|
|
|
|
-->> 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(...); for i = 1, pack.n do; 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 = {_UTF8_FUNCTION_SAVE[change_var](table.unpack(pack))}; for i = 1, #unpacked do; 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("_UTF8_FUNCTION_SAVE['%s'] = %s; %s = _UTF8_FUNCTION;", change_var, change_var, change_var); load(text)(); _UTF8_FUNCTION = nil; end; return true; end]=]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utf8 = 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 |
|
|
|
|
_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 |
|
|
|
|
function utf8(...) |
|
|
|
|
pcall(_utf8(), ...) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
utf8({ "sampShowDialog" }, "Utf8ToAnsi") |
|
|
|
|
utf8({ "sampSendChat" }, "Utf8ToAnsi") |
|
|
|
|