Fix game force exiting if you attempt to add a chat message with over 511 characters (Thanks sethbatman05)

This commit is contained in:
UnknownShadow200 2022-07-11 07:25:12 +10:00
parent cf4104bd96
commit d90fb2f092
3 changed files with 13 additions and 6 deletions

View File

@ -159,7 +159,7 @@ static void OpenChatLog(struct DateTime* now) {
}
static void AppendChatLog(const cc_string* text) {
cc_string str; char strBuffer[STRING_SIZE * 2];
cc_string str; char strBuffer[DRAWER2D_MAX_TEXT_LENGTH];
struct DateTime now;
cc_result res;
@ -209,6 +209,7 @@ void Chat_AddRaw(const char* raw) {
void Chat_Add(const cc_string* text) { Chat_AddOf(text, MSG_TYPE_NORMAL); }
void Chat_AddOf(const cc_string* text, int msgType) {
cc_string str;
if (msgType == MSG_TYPE_NORMAL) {
/* Check for chat overflow (see issue #837) */
/* This happens because Offset/Length are packed into a single 32 bit value, */
@ -219,9 +220,13 @@ void Chat_AddOf(const cc_string* text, int msgType) {
Chat_AddRaw("&cChat log cleared as it hit 8.3 million character limit");
}
/* StringsBuffer_Add will abort game if try to add string > 511 characters */
str = *text;
str.length = min(str.length, DRAWER2D_MAX_TEXT_LENGTH);
Chat_GetLogTime(Chat_Log.count) = Game.Time;
StringsBuffer_Add(&Chat_Log, text);
AppendChatLog(text);
AppendChatLog(&str);
StringsBuffer_Add(&Chat_Log, &str);
} else if (msgType >= MSG_TYPE_STATUS_1 && msgType <= MSG_TYPE_STATUS_3) {
/* Status[0] is for texture pack downloading message */
/* Status[1] is for reduced performance mode message */

View File

@ -449,9 +449,9 @@ static void DrawBitmappedTextCore(struct Bitmap* bmp, struct DrawTextArgs* args,
BitmapCol* srcRow, src;
BitmapCol* dstRow;
cc_uint8 coords[256];
BitmapCol colors[256];
cc_uint16 dstWidths[256];
cc_uint8 coords[DRAWER2D_MAX_TEXT_LENGTH];
BitmapCol colors[DRAWER2D_MAX_TEXT_LENGTH];
cc_uint16 dstWidths[DRAWER2D_MAX_TEXT_LENGTH];
color = Drawer2D.Colors['f'];
if (shadow) color = GetShadowColor(color);

View File

@ -15,6 +15,8 @@ struct IGameComponent;
struct StringsBuffer;
extern struct IGameComponent Drawer2D_Component;
#define DRAWER2D_MAX_TEXT_LENGTH 256
CC_VAR extern struct _Drawer2DData {
/* Whether text should be drawn and measured using the currently set font bitmap */
/* If false, then text is instead draw using platform/system fonts */