From ca68e2bb8996045a5109cb2748875d762f3fdc17 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 10 Jun 2017 00:53:51 +0100 Subject: [PATCH] Use all leading format codes for timestamp --- src/openrct2/interface/chat.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/openrct2/interface/chat.c b/src/openrct2/interface/chat.c index ff55b78e22..e49038cbd3 100644 --- a/src/openrct2/interface/chat.c +++ b/src/openrct2/interface/chat.c @@ -177,17 +177,20 @@ void chat_history_add(const char * src) size_t bufferSize = strlen(src) + 64; utf8 * buffer = (utf8 *)calloc(1, bufferSize); - // Prepend colour marker (based on text, default to white) + // Find the start of the text (after format codes) const char * ch = src; - uint32 colour = FORMAT_WHITE; + const char * nextCh; uint32 codepoint; - while ((codepoint = utf8_get_next(ch, &ch)) != 0) { - if (utf8_is_colour_code(codepoint)) { - colour = codepoint; + while ((codepoint = utf8_get_next(ch, &nextCh)) != 0) { + if (!utf8_is_format_code(codepoint)) { break; } + ch = nextCh; } - utf8_write_codepoint(buffer, colour); + const char * srcText = ch; + + // Copy format codes to buffer + memcpy(buffer, src, min(bufferSize, (size_t)(srcText - src))); // Prepend a timestamp time_t timer; @@ -195,7 +198,7 @@ void chat_history_add(const char * src) struct tm * tmInfo = localtime(&timer); strcatftime(buffer, bufferSize, "[%H:%M] ", tmInfo); - safe_strcat(buffer, src, bufferSize); + safe_strcat(buffer, srcText, bufferSize); // Add to history list sint32 index = _chatHistoryIndex % CHAT_HISTORY_SIZE;