diff options
author | pg9182 <96569817+pg9182@users.noreply.github.com> | 2023-01-05 17:03:37 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-05 23:03:37 +0100 |
commit | 33eb3254ba1f020f58d80ca91f557515f56ac628 (patch) | |
tree | 46b6d1fb3dd28a9c938dcd059a7c2fab6c376115 /NorthstarDLL/scripts | |
parent | ca2530b82578ca4bd782dbedaced5f02b3141d69 (diff) | |
download | NorthstarLauncher-33eb3254ba1f020f58d80ca91f557515f56ac628.tar.gz NorthstarLauncher-33eb3254ba1f020f58d80ca91f557515f56ac628.zip |
Restrict chat message charset (#389)
Diffstat (limited to 'NorthstarDLL/scripts')
-rw-r--r-- | NorthstarDLL/scripts/client/clientchathooks.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/NorthstarDLL/scripts/client/clientchathooks.cpp b/NorthstarDLL/scripts/client/clientchathooks.cpp index 0fc68302..d4fa0c41 100644 --- a/NorthstarDLL/scripts/client/clientchathooks.cpp +++ b/NorthstarDLL/scripts/client/clientchathooks.cpp @@ -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) |