From f60e8909ef5b8895ea554d8474027bcb1ca82388 Mon Sep 17 00:00:00 2001 From: Daniel Svensson Date: Sat, 8 Feb 2025 17:01:32 +0100 Subject: [PATCH 1/7] macOS compat fixes. --- src/shared.c | 2 ++ src/sys_linux.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/shared.c b/src/shared.c index 8d61354..e035db3 100644 --- a/src/shared.c +++ b/src/shared.c @@ -156,6 +156,7 @@ size_t strlcpy(char *dst, const char *src, size_t siz) } #endif // LINUX & WIN32 +#if !defined(__APPLE__) size_t strlcat(char *dst, const char *src, size_t siz) { register char *d = dst; @@ -185,6 +186,7 @@ size_t strlcat(char *dst, const char *src, size_t siz) return(dlen + (s - src)); /* count does not include NUL */ } +#endif // Implemented in later versions of Visual Studio (https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010) #if defined(_MSC_VER) && _MSC_VER < 1900 diff --git a/src/sys_linux.c b/src/sys_linux.c index d36a251..a60d07d 100644 --- a/src/sys_linux.c +++ b/src/sys_linux.c @@ -17,7 +17,7 @@ #include #include #include -#ifndef __FreeBSD__ +#if !defined(__FreeBSD__) && !defined(__APPLE__) #include #endif #include From 72cfb7a0a8a6db1938a0a9c33a64ab8716a3c0de Mon Sep 17 00:00:00 2001 From: Daniel Svensson Date: Sat, 8 Feb 2025 17:02:38 +0100 Subject: [PATCH 2/7] Refactor parsing of entity deltas. --- src/netmsg_parser.c | 122 ++++++++++++++++++++++++-------------------- 1 file changed, 66 insertions(+), 56 deletions(-) diff --git a/src/netmsg_parser.c b/src/netmsg_parser.c index 958659b..5d8af4a 100644 --- a/src/netmsg_parser.c +++ b/src/netmsg_parser.c @@ -510,70 +510,47 @@ static void SetStat(mvd_info_t *mvd, int stat, int value) cp->stats[stat] = value; } -static void NetMsg_Parser_ParsePacketEntities(mvd_info_t *mvd, qbool delta) +static void NetMsg_Parser_ParseEntityNum(unsigned int *entnum, unsigned int *bits) { - byte from; - int bits; + *entnum = *bits = 0; - if (delta) - { - from = MSG_ReadByte(); + *bits = MSG_ReadShort(); - if ((outgoing_sequence - incoming_sequence - 1) >= UPDATE_MASK) - { - return; - } - } + *entnum = *bits & 0x1FF; + *bits &= ~0x1FF; - while (true) + if (*bits & U_MOREBITS) { - bits = MSG_ReadShort(); - - if (msg_badread) - { - // Something didn't parse right... - Sys_PrintError("NetMsg_Parser_ParsePacketEntities: msg_badread in packetentities.\n"); - return; - } - - if (!bits) - { - break; - } - - bits &= ~0x1FF; // Strip the first 9 bits. - - // Read any more bits. - if (bits & U_MOREBITS) - { - bits |= MSG_ReadByte(); - } - - if (bits & U_MODEL) - MSG_ReadByte(); - if (bits & U_FRAME) - MSG_ReadByte(); - if (bits & U_COLORMAP) - MSG_ReadByte(); - if (bits & U_SKIN) - MSG_ReadByte(); - if (bits & U_EFFECTS) - MSG_ReadByte(); - if (bits & U_ORIGIN1) - MSG_ReadCoord(); - if (bits & U_ORIGIN2) - MSG_ReadCoord(); - if (bits & U_ORIGIN3) - MSG_ReadCoord(); - if (bits & U_ANGLE1) - MSG_ReadAngle(); - if (bits & U_ANGLE2) - MSG_ReadAngle(); - if (bits & U_ANGLE3) - MSG_ReadAngle(); + *bits |= MSG_ReadByte(); } } +static void NetMsg_Parser_ParseEntityDelta(unsigned int bits) +{ + if (bits & U_MODEL) + MSG_ReadByte(); + if (bits & U_FRAME) + MSG_ReadByte(); + if (bits & U_COLORMAP) + MSG_ReadByte(); + if (bits & U_SKIN) + MSG_ReadByte(); + if (bits & U_EFFECTS) + MSG_ReadByte(); + if (bits & U_ORIGIN1) + MSG_ReadCoord(); + if (bits & U_ORIGIN2) + MSG_ReadCoord(); + if (bits & U_ORIGIN3) + MSG_ReadCoord(); + if (bits & U_ANGLE1) + MSG_ReadAngle(); + if (bits & U_ANGLE2) + MSG_ReadAngle(); + if (bits & U_ANGLE3) + MSG_ReadAngle(); +} + // ======================================================================================== // NET MESSAGE FUNCTITONS // ======================================================================================== @@ -1313,6 +1290,39 @@ static void NetMsg_Parser_Parse_svc_soundlist(mvd_info_t *mvd) MSG_ReadByte(); // Ignore. } +static void NetMsg_Parser_ParsePacketEntities(mvd_info_t *mvd, qbool delta) +{ + if (delta) + { + MSG_ReadByte(); + if ((outgoing_sequence - incoming_sequence - 1) >= UPDATE_MASK) + { + return; + } + } + + while (true) + { + unsigned int entnum, bits; + + NetMsg_Parser_ParseEntityNum(&entnum, &bits); + + if (msg_badread) + { + // Something didn't parse right... + Sys_PrintError("NetMsg_Parser_ParsePacketEntities: msg_badread in packetentities.\n"); + return; + } + + if (!entnum) + { + break; + } + + NetMsg_Parser_ParseEntityDelta(bits); + } +} + static void NetMsg_Parser_Parse_svc_packetentities(mvd_info_t *mvd) { NetMsg_Parser_ParsePacketEntities(mvd, false); From 69108f8b76827aaf41350eab5e07e48f05c8cf5a Mon Sep 17 00:00:00 2001 From: Daniel Svensson Date: Sat, 8 Feb 2025 17:10:01 +0100 Subject: [PATCH 3/7] Parse more bits in entity deltas. --- src/netmsg_parser.c | 29 +++++++++++++++++++++++------ src/qw_protocol.h | 26 ++++++++++++++++++-------- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/netmsg_parser.c b/src/netmsg_parser.c index 5d8af4a..81aaa3f 100644 --- a/src/netmsg_parser.c +++ b/src/netmsg_parser.c @@ -510,9 +510,9 @@ static void SetStat(mvd_info_t *mvd, int stat, int value) cp->stats[stat] = value; } -static void NetMsg_Parser_ParseEntityNum(unsigned int *entnum, unsigned int *bits) +static void NetMsg_Parser_ParseEntityNum(unsigned int *entnum, unsigned int *bits, unsigned int *morebits) { - *entnum = *bits = 0; + *entnum = *bits = *morebits = 0; *bits = MSG_ReadShort(); @@ -522,10 +522,27 @@ static void NetMsg_Parser_ParseEntityNum(unsigned int *entnum, unsigned int *bit if (*bits & U_MOREBITS) { *bits |= MSG_ReadByte(); + if (*bits & U_FTE_EVENMORE) + { + *morebits = MSG_ReadByte(); + if (*morebits & U_FTE_YETMORE) + { + *morebits |= MSG_ReadByte() << 8; + } + + if (*morebits & U_FTE_ENTITYDBL) + { + *entnum += 512; + } + if (*morebits & U_FTE_ENTITYDBL2) + { + *entnum += 1024; + } + } } } -static void NetMsg_Parser_ParseEntityDelta(unsigned int bits) +static void NetMsg_Parser_ParseEntityDelta(unsigned int bits, unsigned int morebits) { if (bits & U_MODEL) MSG_ReadByte(); @@ -1303,9 +1320,9 @@ static void NetMsg_Parser_ParsePacketEntities(mvd_info_t *mvd, qbool delta) while (true) { - unsigned int entnum, bits; + unsigned int entnum, bits, morebits; - NetMsg_Parser_ParseEntityNum(&entnum, &bits); + NetMsg_Parser_ParseEntityNum(&entnum, &bits, &morebits); if (msg_badread) { @@ -1319,7 +1336,7 @@ static void NetMsg_Parser_ParsePacketEntities(mvd_info_t *mvd, qbool delta) break; } - NetMsg_Parser_ParseEntityDelta(bits); + NetMsg_Parser_ParseEntityDelta(bits, morebits); } } diff --git a/src/qw_protocol.h b/src/qw_protocol.h index 869798c..fd2a91a 100644 --- a/src/qw_protocol.h +++ b/src/qw_protocol.h @@ -221,14 +221,24 @@ extern char *print_strings[]; // Contains descriptions of the print levels. #define U_MOREBITS (1 << 15) // if MOREBITS is set, these additional flags are read in next -#define U_ANGLE1 (1 << 0) -#define U_ANGLE3 (1 << 1) -#define U_MODEL (1 << 2) -#define U_COLORMAP (1 << 3) -#define U_SKIN (1 << 4) -#define U_EFFECTS (1 << 5) -#define U_SOLID (1 << 6) // the entity should be solid for prediction - +#define U_ANGLE1 (1 << 0) +#define U_ANGLE3 (1 << 1) +#define U_MODEL (1 << 2) +#define U_COLORMAP (1 << 3) +#define U_SKIN (1 << 4) +#define U_EFFECTS (1 << 5) +#define U_SOLID (1 << 6) // the entity should be solid for prediction +#define U_FTE_EVENMORE (1 << 7) + +// if EVENMORE is set, these additional flags are read in next +#define U_FTE_TRANS (1 << 1) +#define U_FTE_MODELDBL (1 << 3) +#define U_FTE_ENTITYDBL (1 << 5) +#define U_FTE_ENTITYDBL2 (1 << 6) +#define U_FTE_YETMORE (1 << 7) + +// if YETMORE is set, these additional flags are read in next +#define U_FTE_COLOURMOD (1 << 10) //============================================== // a sound with no channel is a local only sound From b59dbac938b32db4404e5e99d6b43fdd9719ec92 Mon Sep 17 00:00:00 2001 From: Daniel Svensson Date: Sat, 8 Feb 2025 17:12:35 +0100 Subject: [PATCH 4/7] Add support for PEXT_TRANS. --- src/netmsg_parser.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/netmsg_parser.c b/src/netmsg_parser.c index 81aaa3f..0db6fbb 100644 --- a/src/netmsg_parser.c +++ b/src/netmsg_parser.c @@ -566,6 +566,9 @@ static void NetMsg_Parser_ParseEntityDelta(unsigned int bits, unsigned int moreb MSG_ReadAngle(); if (bits & U_ANGLE3) MSG_ReadAngle(); + + if (morebits & U_FTE_TRANS) + MSG_ReadByte(); } // ======================================================================================== From 91d55294ea4e7eb39cb59b1435ace90f5164fe4b Mon Sep 17 00:00:00 2001 From: Daniel Svensson Date: Sat, 8 Feb 2025 17:12:54 +0100 Subject: [PATCH 5/7] Add support for PEXT_COLOURMOD. --- src/netmsg_parser.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/netmsg_parser.c b/src/netmsg_parser.c index 0db6fbb..15b6b01 100644 --- a/src/netmsg_parser.c +++ b/src/netmsg_parser.c @@ -569,6 +569,13 @@ static void NetMsg_Parser_ParseEntityDelta(unsigned int bits, unsigned int moreb if (morebits & U_FTE_TRANS) MSG_ReadByte(); + + if (morebits & U_FTE_COLOURMOD) + { + MSG_ReadByte(); // r + MSG_ReadByte(); // g + MSG_ReadByte(); // b + } } // ======================================================================================== From 9fe092a4776f8a50aec71f767df99d11fb23aa17 Mon Sep 17 00:00:00 2001 From: Daniel Svensson Date: Sat, 8 Feb 2025 14:31:19 +0100 Subject: [PATCH 6/7] Add support for PEXT_SPAWNSTATIC2. --- src/netmsg_parser.c | 24 ++++++++++++++++++++++++ src/qw_protocol.c | 4 ++-- src/qw_protocol.h | 3 ++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/netmsg_parser.c b/src/netmsg_parser.c index 15b6b01..f80957d 100644 --- a/src/netmsg_parser.c +++ b/src/netmsg_parser.c @@ -962,6 +962,13 @@ static void NetMsg_Parser_Parse_svc_spawnstatic(void) } } +static void NetMsg_Parser_Parse_svc_fte_spawnstatic2(void) +{ + unsigned int entnum, bits, morebits; + NetMsg_Parser_ParseEntityNum(&entnum, &bits, &morebits); + NetMsg_Parser_ParseEntityDelta(bits, morebits); +} + static void NetMsg_Parser_Parse_svc_spawnbaseline(void) { int i; @@ -979,6 +986,13 @@ static void NetMsg_Parser_Parse_svc_spawnbaseline(void) } } +static void NetMsg_Parser_Parse_svc_fte_spawnbaseline2(void) +{ + unsigned int entnum, bits, morebits; + NetMsg_Parser_ParseEntityNum(&entnum, &bits, &morebits); + NetMsg_Parser_ParseEntityDelta(bits, morebits); +} + static void NetMsg_Parser_Parse_svc_temp_entity(void) { int i; @@ -1596,6 +1610,11 @@ qbool NetMsg_Parser_StartParse(mvd_info_t *mvd) NetMsg_Parser_Parse_svc_spawnbaseline(); break; } + case svc_fte_spawnbaseline2 : + { + NetMsg_Parser_Parse_svc_fte_spawnbaseline2(); + break; + } case svc_updatefrags : { NetMsg_Parser_Parse_svc_updatefrags(mvd); @@ -1711,6 +1730,11 @@ qbool NetMsg_Parser_StartParse(mvd_info_t *mvd) NetMsg_Parser_Parse_svc_spawnstatic(); break; } + case svc_fte_spawnstatic2 : + { + NetMsg_Parser_Parse_svc_fte_spawnstatic2(); + break; + } case svc_foundsecret : { NetMsg_Parser_Parse_svc_foundsecret(); diff --git a/src/qw_protocol.c b/src/qw_protocol.c index 2a218d2..e8dab33 100644 --- a/src/qw_protocol.c +++ b/src/qw_protocol.c @@ -33,7 +33,7 @@ char *svc_strings[] = "svc_damage", // [byte] impact [byte] blood [vec3] from "svc_spawnstatic", - "OBSOLETE svc_spawnbinary", + "svc_fte_spawnstatic2", "svc_spawnbaseline", "svc_temp_entity", // @@ -84,7 +84,7 @@ char *svc_strings[] = "NEW PROTOCOL", "NEW PROTOCOL", "NEW PROTOCOL", - "NEW PROTOCOL" + "svc_fte_spawnbaseline2" }; diff --git a/src/qw_protocol.h b/src/qw_protocol.h index fd2a91a..6c26602 100644 --- a/src/qw_protocol.h +++ b/src/qw_protocol.h @@ -89,7 +89,7 @@ extern char *print_strings[]; // Contains descriptions of the print levels. #define svc_damage 19 #define svc_spawnstatic 20 -// svc_spawnbinary 21 +#define svc_fte_spawnstatic2 21 #define svc_spawnbaseline 22 #define svc_temp_entity 23 // variable @@ -138,6 +138,7 @@ extern char *print_strings[]; // Contains descriptions of the print levels. #define svc_serverinfo 52 // serverinfo #define svc_updatepl 53 // [byte] [byte] #define svc_nails2 54 +#define svc_fte_spawnbaseline2 66 #define svc_qizmovoice 83 //============================================== From b42be202b3d84d71bc6b505ed7a746a154b0515c Mon Sep 17 00:00:00 2001 From: Daniel Svensson Date: Sat, 8 Feb 2025 15:12:58 +0100 Subject: [PATCH 7/7] Add support for PEXT_MODELDBL. --- src/netmsg_parser.c | 14 +++++++++++--- src/qw_protocol.c | 2 +- src/qw_protocol.h | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/netmsg_parser.c b/src/netmsg_parser.c index f80957d..098fbc3 100644 --- a/src/netmsg_parser.c +++ b/src/netmsg_parser.c @@ -546,6 +546,9 @@ static void NetMsg_Parser_ParseEntityDelta(unsigned int bits, unsigned int moreb { if (bits & U_MODEL) MSG_ReadByte(); + else if (morebits & U_FTE_MODELDBL) + MSG_ReadShort(); + if (bits & U_FRAME) MSG_ReadByte(); if (bits & U_COLORMAP) @@ -1288,10 +1291,10 @@ static void NetMsg_Parser_Parse_svc_chokecount(void) MSG_ReadByte(); } -static void NetMsg_Parser_Parse_svc_modellist(void) +static void NetMsg_Parser_Parse_svc_modellist(qbool extended) { char *str; - int model_count = MSG_ReadByte(); + int model_count = extended ? MSG_ReadShort() : MSG_ReadByte(); while (true) { @@ -1592,7 +1595,12 @@ qbool NetMsg_Parser_StartParse(mvd_info_t *mvd) } case svc_modellist : { - NetMsg_Parser_Parse_svc_modellist(); + NetMsg_Parser_Parse_svc_modellist(false); + break; + } + case svc_fte_modellistshort : + { + NetMsg_Parser_Parse_svc_modellist(true); break; } case svc_soundlist : diff --git a/src/qw_protocol.c b/src/qw_protocol.c index e8dab33..4f6870b 100644 --- a/src/qw_protocol.c +++ b/src/qw_protocol.c @@ -78,7 +78,7 @@ char *svc_strings[] = "NEW PROTOCOL", "NEW PROTOCOL", "NEW PROTOCOL", - "NEW PROTOCOL", + "svc_fte_modellistshort", "NEW PROTOCOL", "NEW PROTOCOL", "NEW PROTOCOL", diff --git a/src/qw_protocol.h b/src/qw_protocol.h index 6c26602..5f870a0 100644 --- a/src/qw_protocol.h +++ b/src/qw_protocol.h @@ -138,6 +138,7 @@ extern char *print_strings[]; // Contains descriptions of the print levels. #define svc_serverinfo 52 // serverinfo #define svc_updatepl 53 // [byte] [byte] #define svc_nails2 54 +#define svc_fte_modellistshort 60 #define svc_fte_spawnbaseline2 66 #define svc_qizmovoice 83