Skip to content

Commit 93fc4a6

Browse files
authored
InstaLS: refactor globals (#2438)
* chore: refactor the use of globals in instaLS
1 parent 2c72090 commit 93fc4a6

File tree

1 file changed

+63
-22
lines changed

1 file changed

+63
-22
lines changed

addons/instaLS/instaLS.lua

+63-22
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@
2525
--SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626

2727
_addon.name = 'instaLS'
28-
_addon.version = 0.220213
28+
_addon.version = 0.250421
2929
_addon.author = 'Byrth'
3030

3131
linkshell_inventories_loaded = true
32-
chatmode = {}
33-
chatcolor = {}
34-
message = false
32+
queue = {}
3533
require 'strings'
3634
bit = require 'bit'
3735

@@ -50,44 +48,87 @@ windower.register_event('incoming chunk', function(id,org)
5048
end)
5149

5250
windower.register_event('outgoing chunk',function(id,org,mod,inj)
53-
if id == 0xB5 and not inj and #chatmode>0 and mod:byte(5) == 0 then -- and org:unpack('z',7) == message
54-
-- Not injected, message currently queued
55-
local outpack = mod:sub(1,4)..string.char(table.remove(chatmode,1))..mod:sub(6)
56-
return outpack
51+
if id == 0xB5 and not inj and mod:byte(5) == 0 and #queue > 0 then
52+
local pop_index, outpack = nil, nil
53+
for i, v in pairs(queue) do
54+
-- Not injected, message currently queued
55+
if string.find(org, v.message) then
56+
outpack = mod:sub(1,4)..string.char(v.chatmode)..mod:sub(6)
57+
if v.status == "seen" then
58+
pop_index = i
59+
else
60+
v.status = "sent"
61+
end
62+
break
63+
end
64+
end
65+
if pop_index then
66+
table.remove(queue, pop_index)
67+
end
68+
if outpack then
69+
return outpack
70+
end
5771
end
5872
end)
5973

6074
windower.register_event('incoming text',function(org, mod, col)
61-
if message and #chatcolor>0 and string.find(org,translate_escape(message)) then
75+
if #queue > 0 then
6276
local a,b = string.find(mod,windower.ffxi.get_player().name)
63-
mod = mod:sub(1,a-1)..'['..(chatcolor[1]==6 and '1' or '2')..']<'..mod:sub(a,b)..'>'..mod:sub(b+3)
64-
local retarr = {mod, table.remove(chatcolor,1)}
65-
message = nil
66-
return unpack(retarr)
77+
local pop_index, retarr = nil, nil
78+
for i,v in pairs(queue) do
79+
if string.find(org,translate_escape(v.message)) then
80+
mod = mod:sub(1,a-1)..'['..(v.chatcolor==6 and '1' or '2')..']<'..mod:sub(a,b)..'>'..mod:sub(b+3)
81+
retarr = {mod, v.chatcolor}
82+
if v.status == "sent" then
83+
pop_index = i
84+
else
85+
v.status = "seen"
86+
end
87+
break
88+
end
89+
end
90+
if pop_index then
91+
table.remove(queue, pop_index)
92+
end
93+
if retarr then
94+
return unpack(retarr)
95+
end
6796
end
6897
end)
6998

7099
windower.register_event('outgoing text',function(org,mod,bool)
71100
if bool or linkshell_inventories_loaded then return end
101+
local message
72102
if mod:sub(1,3) == '/l ' then
73-
chatmode[#chatmode+1] = 0x05
74-
chatcolor[#chatcolor+1] = 6
75103
message = mod:sub(4)
104+
queue[#queue+1] = {
105+
chatmode = 0x05,
106+
chatcolor = 6,
107+
message = message
108+
}
76109
elseif mod:sub(1,11) == '/linkshell ' then
77-
chatmode[#chatmode+1] = 0x05
78-
chatcolor[#chatcolor+1] = 6
79110
message = mod:sub(12)
111+
queue[#queue+1] = {
112+
chatmode = 0x05,
113+
chatcolor = 6,
114+
message = message,
115+
}
80116
elseif mod:sub(1,4) == '/l2 ' then
81-
chatmode[#chatmode+1] = 0x1B
82-
chatcolor[#chatcolor+1] = 213
83117
message = mod:sub(5)
118+
queue[#queue+1] = {
119+
chatmode = 0x1B,
120+
chatcolor = 213,
121+
message = message,
122+
}
84123
elseif mod:sub(1,12) == '/linkshell2 ' then
85-
chatmode[#chatmode+1] = 0x1B
86-
chatcolor[#chatcolor+1] = 213
87124
message = mod:sub(13)
125+
queue[#queue+1] = {
126+
chatmode = 0x1B,
127+
chatcolor = 213,
128+
message = message,
129+
}
88130
else
89131
return
90132
end
91-
92133
return '/s '..message
93134
end)

0 commit comments

Comments
 (0)