diff options
author | pg9182 <96569817+pg9182@users.noreply.github.com> | 2023-01-05 17:03:37 -0500 |
---|---|---|
committer | GeckoEidechse <gecko.eidechse+git@pm.me> | 2023-01-05 23:05:51 +0100 |
commit | 7133fe80c6615297dfef3653981e766ff5d56038 (patch) | |
tree | 51c3dff97b8a585ca1db28d107fb108427d05530 /NorthstarDLL/server/serverchathooks.cpp | |
parent | 401b17300d167b961e5a86a5dbae3aa9e2bedbb4 (diff) | |
download | NorthstarLauncher-7133fe80c6615297dfef3653981e766ff5d56038.tar.gz NorthstarLauncher-7133fe80c6615297dfef3653981e766ff5d56038.zip |
Restrict chat message charset (#389)v1.11.3-rc1v1.11.3
Diffstat (limited to 'NorthstarDLL/server/serverchathooks.cpp')
-rw-r--r-- | NorthstarDLL/server/serverchathooks.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/NorthstarDLL/server/serverchathooks.cpp b/NorthstarDLL/server/serverchathooks.cpp index 57c2c31a..eb0034c0 100644 --- a/NorthstarDLL/server/serverchathooks.cpp +++ b/NorthstarDLL/server/serverchathooks.cpp @@ -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) |