1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
untyped
global function AddCallback_OnReceivedSayTextMessage
// this is global due to squirrel bridge v3 making native not be able to find non-global funcs properly
// temp fix (surely it will get replaced), do not use this function please (although there isnt rly a downside to it?)
global function CHudChat_ProcessMessageStartThread
global struct ClClient_MessageStruct {
string message
entity player
string playerName
bool isTeam
bool isDead
bool isWhisper
bool shouldBlock
bool noServerTag
}
struct {
array< ClClient_MessageStruct functionref( ClClient_MessageStruct ) > OnReceivedSayTextMessageCallbacks
} NsCustomCallbacksClient
void function OnReceivedMessage(ClClient_MessageStruct localMessage) {
if ( IsWatchingReplay() && localMessage.player == null )
return
if (localMessage.player != null)
{
foreach (callbackFunc in NsCustomCallbacksClient.OnReceivedSayTextMessageCallbacks)
{
ClClient_MessageStruct returnStruct = callbackFunc(localMessage)
localMessage.message = returnStruct.message
localMessage.playerName = returnStruct.playerName
localMessage.isTeam = returnStruct.isTeam
localMessage.isDead = returnStruct.isDead
localMessage.isWhisper = returnStruct.isWhisper
localMessage.shouldBlock = localMessage.shouldBlock || returnStruct.shouldBlock
localMessage.noServerTag = returnStruct.noServerTag
}
}
if (localMessage.shouldBlock)
{
return
}
NSChatWriteRaw(1, "\n")
if (localMessage.player == null)
{
if (!localMessage.noServerTag || localMessage.isWhisper)
{
NSChatWrite(1, "\x1b[95m")
}
}
else
{
bool isFriendly = localMessage.player.GetTeam() == GetLocalClientPlayer().GetTeam()
if (isFriendly) NSChatWrite(1, "\x1b[111m")
else NSChatWrite(1, "\x1b[112m")
}
if (localMessage.isWhisper) NSChatWriteRaw(1, Localize("#HUD_CHAT_WHISPER_PREFIX"))
if (localMessage.isDead) NSChatWriteRaw(1, Localize("#HUD_CHAT_DEAD_PREFIX"))
if (localMessage.isTeam) NSChatWriteRaw(1, Localize("#HUD_CHAT_TEAM_PREFIX"))
if (localMessage.player == null)
{
if (!localMessage.noServerTag)
{
NSChatWriteRaw(1, Localize("#HUD_CHAT_SERVER_PREFIX") + " ")
}
}
else
{
NSChatWriteRaw(1, localMessage.playerName)
NSChatWriteRaw(1, ": ")
}
if (localMessage.player != null || !localMessage.noServerTag || localMessage.isWhisper) NSChatWrite(1, "\x1b[0m")
NSChatWrite(1, localMessage.message)
}
void function CHudChat_ProcessMessageStartThread(int playerIndex, string message, bool isTeam, bool isDead, int messageType)
{
thread CHudChat_OnReceivedSayTextMessageCallback(playerIndex, message, isTeam, isDead, messageType)
}
void function CHudChat_OnReceivedSayTextMessageCallback(int fromPlayerIndex, string message, bool isTeam, bool isDead, int messageType)
{
entity fromPlayer = null
string fromPlayerName = ""
if (fromPlayerIndex >= 0 && fromPlayerIndex <= 128)
{
fromPlayer = GetEntByIndex(fromPlayerIndex + 1)
if (fromPlayer == null) {
print("Ignored chat message from invalid player index " + fromPlayerIndex + ": " + message)
return
}
fromPlayerName = fromPlayer.GetPlayerNameWithClanTag()
}
// Null player + isTeam == true: Server with no tag.
if (messageType == 0 || messageType == 1)
{
ClClient_MessageStruct localMessage
localMessage.message = message
localMessage.player = fromPlayer
localMessage.playerName = fromPlayerName
localMessage.isTeam = fromPlayer != null && isTeam
localMessage.isDead = isDead
localMessage.isWhisper = false
localMessage.shouldBlock = false
localMessage.noServerTag = fromPlayer == null && isTeam
OnReceivedMessage(localMessage)
return
}
if (messageType == 2)
{
ClClient_MessageStruct localMessage
localMessage.message = message
localMessage.player = fromPlayer
localMessage.playerName = fromPlayerName
localMessage.isTeam = fromPlayer != null && isTeam
localMessage.isDead = isDead
localMessage.isWhisper = true
localMessage.shouldBlock = false
localMessage.noServerTag = fromPlayer == null && isTeam
OnReceivedMessage(localMessage)
return
}
}
void function AddCallback_OnReceivedSayTextMessage( ClClient_MessageStruct functionref (ClClient_MessageStruct) callbackFunc )
{
NsCustomCallbacksClient.OnReceivedSayTextMessageCallbacks.append(callbackFunc)
}
|