Skip to content

Commit 25f09cb

Browse files
committed
Included Vindar's patch to fix a bug on europeen clients
1 parent 45ac1c8 commit 25f09cb

4 files changed

Lines changed: 108 additions & 4 deletions

File tree

ChatNotif.plugin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Information>
44
<Name>ChatNotif</Name>
55
<Author>Esy</Author>
6-
<Version>1.2.1</Version>
6+
<Version>1.2.2</Version>
77
<Description>
88
A simple plugin to display chat messages. Visit https://github.com/LilianHiault/ChatNotif#readme for more information.
99
</Description>

ChatNotif.plugincompendium

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PluginConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
33
<Id>1208</Id>
44
<Name>ChatNotif</Name>
5-
<Version>1.2.1</Version>
5+
<Version>1.2.2</Version>
66
<Author>Esy</Author>
77
<InfoUrl>https://www.lotrointerface.com/downloads/info1208</InfoUrl>
88
<DownloadUrl>https://www.lotrointerface.com/downloads/download1208</DownloadUrl>

ChatNotif/Settings.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import "Esy.ChatNotif.VindarPatch";
2+
13
-- Settings
24

35
-- Default settings
@@ -36,7 +38,8 @@ SettingsDataScope = Turbine.DataScope.Character;
3638

3739
-- Load settings from the file
3840
function LoadSettings()
39-
local loadedSettings = Turbine.PluginData.Load(SettingsDataScope, SettingsFileName);
41+
-- local loadedSettings = Turbine.PluginData.Load(SettingsDataScope, SettingsFileName);
42+
local loadedSettings = PatchDataLoad(SettingsDataScope, SettingsFileName);
4043

4144
if (type(loadedSettings) == 'table') then
4245
SETTINGS = loadedSettings;
@@ -58,7 +61,8 @@ end
5861

5962
-- Save settings for the character in the file
6063
function SaveSettings()
61-
Turbine.PluginData.Save(SettingsDataScope, SettingsFileName, SETTINGS);
64+
-- Turbine.PluginData.Save(SettingsDataScope, SettingsFileName, SETTINGS);
65+
PatchDataSave(SettingsDataScope, SettingsFileName, SETTINGS);
6266
if SETTINGS.DEBUG then Turbine.Shell.WriteLine("> Settings Saved") end
6367
end
6468

ChatNotif/VindarPatch.lua

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
--[[ Vindar, 11/2010
2+
A patch for the Turbine.PluginData bug for europeen clients. It's dirty but it seems to works :)
3+
]]--
4+
5+
6+
-- return a copy of the object obj in a safe format
7+
local function _convSafe(obj)
8+
if type(obj)=="number" then return(tostring(obj)) end
9+
if type(obj)~="string" then return(obj) end
10+
local res = ""
11+
for i,v in ipairs({obj:byte(1,-1)}) do
12+
if (v < 32) or (v > 125) then res = res .. "#" .. tonumber(v) .. "#"
13+
else
14+
res = res .. string.char(v)
15+
if v == 35 then res = res .. "#" end
16+
end
17+
end
18+
if res:byte(1,1) == 35 then return("#" .. res) end
19+
if (tonumber(res)~= nil) then return("#" .. res) end
20+
return res
21+
end
22+
local function _copySafe(obj)
23+
if type(obj) ~= "table" then return _convSafe(obj) elseif lookupSafe[obj] then return lookupSafe[obj] end
24+
local newt = {}
25+
lookupSafe[obj] = newt
26+
for i, v in pairs(obj) do newt[_copySafe(i)] = _copySafe(v) end
27+
return setmetatable(newt, getmetatable(obj))
28+
end
29+
function convSafe(obj)
30+
lookupSafe = {}
31+
local retVal=_copySafe(obj)
32+
lookupSafe=nil;
33+
return retVal;
34+
end
35+
36+
37+
-- the inverse operation
38+
local function _convBack(obj)
39+
if type(obj) ~= "string" then return obj end
40+
if obj == "" then return "" end
41+
local num = tonumber(obj)
42+
if num ~= nil then return num end
43+
local res = ""
44+
if obj:byte(1,1) == 35 then obj = string.sub(obj,2,-1) end
45+
while string.len(obj)~=0 do
46+
if obj:byte(1,1) ~= 35 then res = res .. string.char(obj:byte(1,1)); obj = string.sub(obj,2,-1)
47+
elseif obj:byte(2,2) == 35 then res = res .. "#"; obj = string.sub(obj,3,-1)
48+
else
49+
obj = string.sub(obj,2,-1)
50+
local k = 1;
51+
while (obj:byte(k,k) ~= nil) and (obj:byte(k,k) ~= 35) do k = k + 1 end
52+
if obj:byte(k,k) == nil then error("convBack : parse error 1 !") end
53+
local v = tonumber(string.sub(obj,1,k-1))
54+
if v == nil then error("convBack : parse error 2 !") end
55+
res = res .. string.char(v)
56+
obj = string.sub(obj,k+1,-1)
57+
end
58+
end
59+
return res;
60+
end
61+
local function _copyBack(obj)
62+
if type(obj) ~= "table" then return _convBack(obj) elseif lookupBack[obj] then return lookupBack[obj] end
63+
local newt = {}
64+
lookupBack[obj] = newt
65+
for i, v in pairs(obj) do newt[_copyBack(i)] = _copyBack(v) end
66+
return setmetatable(newt, getmetatable(obj))
67+
end
68+
function convBack(obj)
69+
lookupBack = {}
70+
local retVal=_copyBack(obj)
71+
lookupBack=nil;
72+
return retVal
73+
end
74+
75+
-- Replacement for Turbine.PluginData.Load
76+
function PatchDataLoad(a,b,c)
77+
local success,results;
78+
success,results=pcall(Turbine.PluginData.Load,a,b,c);
79+
if success then
80+
success,results=pcall(convBack,results);
81+
if success then
82+
return results;
83+
else
84+
Turbine.Shell.WriteLine("Error:"..tostring(results))
85+
Turbine.Shell.WriteLine("While processing convBack(Turbine.PluginData.Load("..tostring(a)..", "..tostring(b)..", "..tostring(c).."))")
86+
return nil;
87+
end
88+
else
89+
Turbine.Shell.WriteLine("Error:"..tostring(results))
90+
Turbine.Shell.WriteLine("While processing Turbine.PluginData.Load("..tostring(a)..", "..tostring(b)..", "..tostring(c)..")")
91+
return nil;
92+
end
93+
end
94+
95+
-- Replacement for Turbine.PluginData.Save
96+
function PatchDataSave(a,b,c,d)
97+
return Turbine.PluginData.Save(a,b,convSafe(c),d)
98+
end
99+
100+
-- end of file

0 commit comments

Comments
 (0)