From a1b1db6f84e6460ec773b700b7fd7ccc74a4ff49 Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 5 Apr 2026 10:48:27 +0100 Subject: [PATCH] Fix parsing of SayText2 messages starting with color codes other than \x01 SayText2 messages can use a simplified format where the body is just client, raw, and a single null-terminated colored text string, without the usual kind/from/text fields. The parser detected this by peeking the first byte after client and raw and checking if it was \x01 (color code for default color), but the text can also start with other color codes such as \x07 (6-char hex color). When this happened, the parser would consume the entire message text as the kind string (falling back to ChatAll), leaving the text and from fields empty. --- src/demo/message/usermessage.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/demo/message/usermessage.rs b/src/demo/message/usermessage.rs index 181328e..f943463 100644 --- a/src/demo/message/usermessage.rs +++ b/src/demo/message/usermessage.rs @@ -297,15 +297,17 @@ impl BitRead<'_, LittleEndian> for SayText2Message { fn read(stream: &mut Stream) -> ReadResult { let client = EntityId::from(stream.read::()? as u32); let raw = stream.read()?; - let (kind, from, text): (ChatMessageKind, Option, MaybeUtf8String) = - if stream.read::()? == 1 { - stream.set_pos(stream.pos() - 8)?; - + let (kind, from, text): (ChatMessageKind, Option, MaybeUtf8String) = { + let next_byte = stream.read::()?; + stream.set_pos(stream.pos() - 8)?; + if next_byte > 0 && next_byte <= 8 { + // Starts with a color code (\x01-\x08) rather than a kind + // string like "TF_Chat_All", so this is the simplified format + // where the message body is just raw colored text without + // kind/from fields. let text: MaybeUtf8String = stream.read()?; (ChatMessageKind::ChatAll, None, text) } else { - stream.set_pos(stream.pos() - 8)?; - let kind = stream.read()?; let from = stream.read()?; let text = stream.read()?; @@ -315,7 +317,8 @@ impl BitRead<'_, LittleEndian> for SayText2Message { let _: u16 = stream.read()?; } (kind, Some(from), text) - }; + } + }; Ok(SayText2Message { client,