Skip to content

Commit e565027

Browse files
committed
Updated VeniceEXT code to support the new architecture changes.
1 parent 2737250 commit e565027

3 files changed

Lines changed: 49 additions & 26 deletions

File tree

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1-
function OnLoaded()
1+
local AdvancedChatHooks = require 'hooks'
2+
local AdvancedChatMessages = require 'messages'
3+
4+
class 'AdvancedChat'
5+
6+
function AdvancedChat:__init()
7+
-- Subscribe to events.
8+
self.m_ExtensionLoadedEvent = Events:Subscribe('ExtensionLoaded', self, self.OnLoaded)
9+
self.m_ChatMessageEvent = Events:Subscribe('AC:SendChatMessage', self, self.OnSendChatMessage)
10+
11+
-- Initialize the other components.
12+
self.m_Hooks = AdvancedChatHooks()
13+
self.m_Messages = AdvancedChatMessages()
14+
end
15+
16+
function AdvancedChat:OnLoaded()
217
-- Initialize our custom WebUI package.
318
WebUI:Init()
419

520
-- Show our custom WebUI package.
621
WebUI:Show()
7-
8-
return true
922
end
1023

11-
function OnSendChatMessage(p_Contents)
24+
function AdvancedChat:OnSendChatMessage(p_Contents)
1225
-- Get the target of the message and the message itself.
1326
local s_Target = p_Contents:match("^([a-z]+):.*$")
1427
local s_Message = p_Contents:match("^[a-z]+:(.*)$")
@@ -19,35 +32,34 @@ function OnSendChatMessage(p_Contents)
1932

2033
-- Ignore if the message is empty.
2134
if s_Message:len() == 0 then
22-
return true
35+
return
2336
end
2437

2538
-- Get the local player.
2639
local s_LocalPlayer = PlayerManager:GetLocalPlayer()
2740

2841
-- We can't send a message if we don't have an active player.
2942
if s_LocalPlayer == nil then
30-
return true
43+
return
3144
end
3245

3346
-- Dispatch message based on the specified target.
3447
if s_Target == 'all' then
3548
ChatManager:SendMessage(s_Message)
36-
return true
49+
return
3750
end
3851

3952
if s_Target == 'team' then
4053
ChatManager:SendMessage(s_Message, s_LocalPlayer.teamID)
41-
return true
54+
return
4255
end
4356

4457
if s_Target == 'sqd' then
4558
ChatManager:SendMessage(s_Message, s_LocalPlayer.teamID, s_LocalPlayer.squadID)
46-
return true
59+
return
4760
end
4861

49-
return true
62+
return
5063
end
5164

52-
Events:Subscribe('ExtensionLoaded', OnLoaded)
53-
Events:Subscribe('AC:SendChatMessage', OnSendChatMessage)
65+
g_AdvancedChat = AdvancedChat()

ext/Client/hooks.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ end
1515
function AdvancedChatHooks:OnCreateChatMessage(p_Hook, p_Message, p_Channel, p_Player, p_RecipientMask, p_SenderIsDead)
1616
-- A new chat message is being created; filter it in order to
1717
-- prevent the game from rendering it.
18-
18+
1919
return UITextMessageType.Last
2020
end
2121

@@ -67,4 +67,4 @@ function AdvancedChatHooks:OnDisableMouse()
6767
WebUI:DisableMouse()
6868
end
6969

70-
local hooks = AdvancedChatHooks()
70+
return AdvancedChatHooks

ext/Client/messages.lua

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
1-
function OnEngineMessage(p_Message)
1+
class 'AdvancedChatMessages'
2+
3+
function AdvancedChatMessages:__init()
4+
-- Subscribe to events.
5+
self.m_EngineMessageEvent = Events:Subscribe('Engine:Message', self, self.OnEngineMessage)
6+
end
7+
8+
function AdvancedChatMessages:OnEngineMessage(p_Message)
9+
if p_Message == nil then
10+
return
11+
end
12+
213
-- We only care about UIHudChatMessages.
314
if p_Message.category ~= MessageCategory.UI or p_Message.type ~= MessageType.UIHudChatMessage then
4-
return true
15+
return
516
end
617

718
-- Get the message, process it and pass it to our custom
819
-- WebUI package for rendering.
920
local s_Message = UIHudChatMessage(p_Message)
10-
21+
1122
if s_Message.channel == ChatChannelType.Admin then
1223
-- This is a workaround because many RCON tools prepend
1324
-- "Admin: " to admin messages.
1425
local s_String = s_Message.string:gsub("^Admin: ", '')
1526

1627
WebUI:ExecuteJS(string.format('AdvancedChat.trigger("message:all", "Admin", %s);', WebUI:QuoteString(s_String)))
17-
return true
28+
return
1829
end
1930

2031
-- Get the player sending the message, and our local player.
@@ -23,41 +34,41 @@ function OnEngineMessage(p_Message)
2334

2435
-- Players not found; cancel.
2536
if s_OtherPlayer == nil or s_LocalPlayer == nil then
26-
return true
37+
return
2738
end
2839

2940
-- Player is a spectator.
3041
if s_OtherPlayer.teamID == 0 then
3142
WebUI:ExecuteJS(string.format('AdvancedChat.trigger("message:spectator", %s, %s);', WebUI:QuoteString(s_OtherPlayer.name), WebUI:QuoteString(s_Message.string)))
32-
return true
43+
return
3344
end
3445

3546
-- Player is on a different team; display enemy message.
3647
if (s_LocalPlayer.teamID == 0 and s_OtherPlayer.teamID == 2) or (s_LocalPlayer.teamID ~= 0 and s_OtherPlayer.teamID ~= s_LocalPlayer.teamID) then
3748
WebUI:ExecuteJS(string.format('AdvancedChat.trigger("message:enemy", %s, %s);', WebUI:QuoteString(s_OtherPlayer.name), WebUI:QuoteString(s_Message.string)))
38-
return true
49+
return
3950
end
4051

4152
-- Player is in the same team.
4253
-- Display global message.
4354
if s_Message.channel == ChatChannelType.SayAll and s_LocalPlayer.teamID ~= 0 then
4455
WebUI:ExecuteJS(string.format('AdvancedChat.trigger("message:all", %s, %s);', WebUI:QuoteString(s_OtherPlayer.name), WebUI:QuoteString(s_Message.string)))
45-
return true
56+
return
4657
end
4758

4859
-- Display team message.
4960
if s_Message.channel == ChatChannelType.Team or s_LocalPlayer.teamID == 0 then
5061
WebUI:ExecuteJS(string.format('AdvancedChat.trigger("message:team", %s, %s);', WebUI:QuoteString(s_OtherPlayer.name), WebUI:QuoteString(s_Message.string)))
51-
return true
62+
return
5263
end
5364

5465
-- Display squad message.
5566
if s_Message.channel == ChatChannelType.Squad or s_Message.channel == ChatChannelType.SquadLeader then
5667
WebUI:ExecuteJS(string.format('AdvancedChat.trigger("message:squad", %s, %s);', WebUI:QuoteString(s_OtherPlayer.name), WebUI:QuoteString(s_Message.string)))
57-
return true
68+
return
5869
end
5970

60-
return true
71+
return
6172
end
6273

63-
Events:Subscribe('Engine:Message', OnEngineMessage)
74+
return AdvancedChatMessages

0 commit comments

Comments
 (0)