1 |
3 |
elsinir-9717 |
--[[ Vindar, 11/2010 |
2 |
|
elsinir-9717 |
A patch for the Turbine.PluginData bug for europeen clients. It's dirty but it seems to works :) |
3 |
|
elsinir-9717 |
]]-- |
4 |
|
elsinir-9717 |
|
5 |
|
elsinir-9717 |
|
6 |
|
elsinir-9717 |
-- return a copy of the object obj in a safe format |
7 |
|
elsinir-9717 |
function convSafe(obj) |
8 |
|
elsinir-9717 |
local lookup = {} |
9 |
|
elsinir-9717 |
local function _copy(obj) |
10 |
|
elsinir-9717 |
function _convSafe(obj) |
11 |
|
elsinir-9717 |
if type(obj)=="number" then return(tostring(obj)) end |
12 |
|
elsinir-9717 |
if type(obj)~="string" then return(obj) end |
13 |
|
elsinir-9717 |
local res = "" |
14 |
|
elsinir-9717 |
for i,v in ipairs({obj:byte(1,-1)}) do |
15 |
|
elsinir-9717 |
if (v < 32) or (v > 125) then res = res .. "#" .. tonumber(v) .. "#" |
16 |
|
elsinir-9717 |
else |
17 |
|
elsinir-9717 |
res = res .. string.char(v) |
18 |
|
elsinir-9717 |
if v == 35 then res = res .. "#" end |
19 |
|
elsinir-9717 |
end |
20 |
|
elsinir-9717 |
end |
21 |
|
elsinir-9717 |
if res:byte(1,1) == 35 then return("#" .. res) end |
22 |
|
elsinir-9717 |
if (tonumber(res)~= nil) then return("#" .. res) end |
23 |
|
elsinir-9717 |
return res |
24 |
|
elsinir-9717 |
end |
25 |
|
elsinir-9717 |
if type(obj) ~= "table" then return _convSafe(obj) elseif lookup[obj] then return lookup[obj] end |
26 |
|
elsinir-9717 |
local newt = {} |
27 |
|
elsinir-9717 |
lookup[obj] = newt |
28 |
|
elsinir-9717 |
for i, v in pairs(obj) do newt[_copy(i)] = _copy(v) end |
29 |
|
elsinir-9717 |
return setmetatable(newt, getmetatable(obj)) |
30 |
|
elsinir-9717 |
end |
31 |
|
elsinir-9717 |
return _copy(obj) |
32 |
|
elsinir-9717 |
end |
33 |
|
elsinir-9717 |
|
34 |
|
elsinir-9717 |
|
35 |
|
elsinir-9717 |
-- the inverse operation |
36 |
|
elsinir-9717 |
function convBack(obj) |
37 |
|
elsinir-9717 |
local lookup = {} |
38 |
|
elsinir-9717 |
local function _copy(obj) |
39 |
|
elsinir-9717 |
local function _convBack(obj) |
40 |
|
elsinir-9717 |
if type(obj) ~= "string" then return obj end |
41 |
|
elsinir-9717 |
if obj == "" then return "" end |
42 |
|
elsinir-9717 |
local num = tonumber(obj) |
43 |
|
elsinir-9717 |
if num ~= nil then return num end |
44 |
|
elsinir-9717 |
local res = "" |
45 |
|
elsinir-9717 |
if obj:byte(1,1) == 35 then obj = string.sub(obj,2,-1) end |
46 |
|
elsinir-9717 |
while string.len(obj)~=0 do |
47 |
|
elsinir-9717 |
if obj:byte(1,1) ~= 35 then res = res .. string.char(obj:byte(1,1)); obj = string.sub(obj,2,-1) |
48 |
|
elsinir-9717 |
elseif obj:byte(2,2) == 35 then res = res .. "#"; obj = string.sub(obj,3,-1) |
49 |
|
elsinir-9717 |
else |
50 |
|
elsinir-9717 |
obj = string.sub(obj,2,-1) |
51 |
|
elsinir-9717 |
local k = 1; |
52 |
|
elsinir-9717 |
while (obj:byte(k,k) ~= nil) and (obj:byte(k,k) ~= 35) do k = k + 1 end |
53 |
|
elsinir-9717 |
if obj:byte(k,k) == nil then error("convBack : parse error 1 !") end |
54 |
|
elsinir-9717 |
local v = tonumber(string.sub(obj,1,k-1)) |
55 |
|
elsinir-9717 |
if v == nil then error("convBack : parse error 2 !") end |
56 |
|
elsinir-9717 |
res = res .. string.char(v) |
57 |
|
elsinir-9717 |
obj = string.sub(obj,k+1,-1) |
58 |
|
elsinir-9717 |
end |
59 |
|
elsinir-9717 |
end |
60 |
|
elsinir-9717 |
return res; |
61 |
|
elsinir-9717 |
end |
62 |
|
elsinir-9717 |
if type(obj) ~= "table" then return _convBack(obj) elseif lookup[obj] then return lookup[obj] end |
63 |
|
elsinir-9717 |
local newt = {} |
64 |
|
elsinir-9717 |
lookup[obj] = newt |
65 |
|
elsinir-9717 |
for i, v in pairs(obj) do newt[_copy(i)] = _copy(v) end |
66 |
|
elsinir-9717 |
return setmetatable(newt, getmetatable(obj)) |
67 |
|
elsinir-9717 |
end |
68 |
|
elsinir-9717 |
return _copy(obj) |
69 |
|
elsinir-9717 |
end |
70 |
|
elsinir-9717 |
|
71 |
|
elsinir-9717 |
-- Replacement for Turbine.PluginData.Load |
72 |
|
elsinir-9717 |
function PatchDataLoad(a,b,c) |
73 |
|
elsinir-9717 |
return convBack(Turbine.PluginData.Load(a,b,c)) |
74 |
|
elsinir-9717 |
end |
75 |
|
elsinir-9717 |
|
76 |
|
elsinir-9717 |
-- Replacement for Turbine.PluginData.Save |
77 |
|
elsinir-9717 |
function PatchDataSave(a,b,c,d) |
78 |
|
elsinir-9717 |
return Turbine.PluginData.Save(a,b,convSafe(c),d) |
79 |
|
elsinir-9717 |
end |
80 |
|
elsinir-9717 |
|
81 |
|
elsinir-9717 |
-- end of file |