Restrict chat message charset (#389)
This commit is contained in:
parent
ca2530b825
commit
33eb3254ba
|
@ -8,6 +8,25 @@
|
|||
|
||||
AUTOHOOK_INIT()
|
||||
|
||||
static char* skip_valid_ansi_csi_sgr(char* str)
|
||||
{
|
||||
if (*str++ != '\x1B')
|
||||
return NULL;
|
||||
if (*str++ != '[') // CSI
|
||||
return NULL;
|
||||
for (char* c = str; *c; c++)
|
||||
{
|
||||
if (*c >= '0' && *c <= '9')
|
||||
continue;
|
||||
if (*c == ';')
|
||||
continue;
|
||||
if (*c == 'm') // SGR
|
||||
break;
|
||||
return NULL;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
AUTOHOOK(CHudChat__AddGameLine, client.dll + 0x22E580,
|
||||
void, __fastcall, (void* self, const char* message, int inboxId, bool isTeam, bool isDead))
|
||||
|
@ -30,6 +49,14 @@ void, __fastcall, (void* self, const char* message, int inboxId, bool isTeam, bo
|
|||
payload = message + 1;
|
||||
}
|
||||
|
||||
for (char* c = const_cast<char*>(message); *c; c++)
|
||||
{
|
||||
if (*c == '\x1B' && (c = skip_valid_ansi_csi_sgr(c)))
|
||||
c--;
|
||||
else if (*c <= 9 || (*c >= 12 && *c <= 31))
|
||||
*c = ' ';
|
||||
}
|
||||
|
||||
SQRESULT result = g_pSquirrel<ScriptContext::CLIENT>->Call(
|
||||
"CHudChat_ProcessMessageStartThread", static_cast<int>(senderId) - 1, payload, isTeam, isDead, type);
|
||||
if (result == SQRESULT_ERROR)
|
||||
|
|
|
@ -34,12 +34,39 @@ void(__fastcall* MessageWriteByte)(int iValue);
|
|||
void(__fastcall* MessageWriteString)(const char* sz);
|
||||
void(__fastcall* MessageWriteBool)(bool bValue);
|
||||
|
||||
static char* skip_valid_ansi_csi_sgr(char* str)
|
||||
{
|
||||
if (*str++ != '\x1B')
|
||||
return NULL;
|
||||
if (*str++ != '[') // CSI
|
||||
return NULL;
|
||||
for (char* c = str; *c; c++)
|
||||
{
|
||||
if (*c >= '0' && *c <= '9')
|
||||
continue;
|
||||
if (*c == ';')
|
||||
continue;
|
||||
if (*c == 'm') // SGR
|
||||
break;
|
||||
return NULL;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
bool bShouldCallSayTextHook = false;
|
||||
// clang-format off
|
||||
AUTOHOOK(_CServerGameDLL__OnReceivedSayTextMessage, server.dll + 0x1595C0,
|
||||
void, __fastcall, (CServerGameDLL* self, unsigned int senderPlayerId, const char* text, bool isTeam))
|
||||
// clang-format on
|
||||
{
|
||||
for (char* c = const_cast<char*>(text); *c; c++)
|
||||
{
|
||||
if (*c == '\x1B' && (c = skip_valid_ansi_csi_sgr(c)))
|
||||
c--;
|
||||
else if (*c <= 9 || (*c >= 12 && *c <= 31))
|
||||
*c = ' ';
|
||||
}
|
||||
|
||||
// MiniHook doesn't allow calling the base function outside of anywhere but the hook function.
|
||||
// To allow bypassing the hook, isSkippingHook can be set.
|
||||
if (bShouldCallSayTextHook)
|
||||
|
|
Loading…
Reference in New Issue