Skip to content

Commit

Permalink
Merge pull request #998 from qw-ctf/demo-proto-fixes
Browse files Browse the repository at this point in the history
PROTOCOL,DEMO: Strictness and correctness.
  • Loading branch information
dsvensson authored Jan 15, 2025
2 parents 725c563 + 02cf1df commit 658a765
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 29 deletions.
30 changes: 22 additions & 8 deletions src/cl_ents.c
Original file line number Diff line number Diff line change
Expand Up @@ -1525,14 +1525,6 @@ void CL_ParsePlayerinfo (void)
if (flags & PF_TRANS_Z && cls.fteprotocolextensions & FTE_PEXT_TRANS)
state->alpha = MSG_ReadByte();
#endif
#ifdef FTE_PEXT_COLOURMOD
if (flags & PF_COLOURMOD && cls.fteprotocolextensions & FTE_PEXT_COLOURMOD)
{
state->colourmod[0] = MSG_ReadByte();
state->colourmod[1] = MSG_ReadByte();
state->colourmod[2] = MSG_ReadByte();
}
#endif

if (cl.z_ext & Z_EXT_PM_TYPE)
{
Expand Down Expand Up @@ -1598,7 +1590,29 @@ void CL_ParsePlayerinfo (void)
// Write out here - generally packets are copied, but flags for userdelta were changed
// in protocol 27 - we always write out in new format
MSG_WriteByte(&cls.demomessage, num);
#if defined(FTE_PEXT_TRANS)
if (cls.fteprotocolextensions & FTE_PEXT_TRANS)
{
if (flags & 0xff0000)
{
flags |= PF_EXTRA_PFS;
}
MSG_WriteShort (&cls.demomessage, flags & 0xffff);
if (flags & PF_EXTRA_PFS)
{
MSG_WriteByte(&cls.demomessage, (flags & 0xff0000) >> 16);
}
}
else
{
// Without PEXT_TRANS there's no PF_EXTRA_PFS, move
// PF_ONGROUND and PF_SOLID to their expected offsets.
MSG_WriteShort (&cls.demomessage, flags & 0x3fff | (flags & 0xc00000) >> 8);
}
#else
MSG_WriteShort(&cls.demomessage, flags);
#endif

if (cls.mvdprotocolextensions1 & MVD_PEXT1_FLOATCOORDS) {
MSG_WriteLongCoord(&cls.demomessage, state->origin[0]);
MSG_WriteLongCoord(&cls.demomessage, state->origin[1]);
Expand Down
30 changes: 30 additions & 0 deletions src/com_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,22 @@ void MSG_WriteDeltaEntity (entity_state_t *from, entity_state_t *to, sizebuf_t *
}
}

#ifdef U_FTE_TRANS
if (to->trans != from->trans && (fte_extensions & FTE_PEXT_TRANS)) {
evenmorebits |= U_FTE_TRANS;
required_extensions |= FTE_PEXT_TRANS;
}
#endif

#ifdef U_FTE_COLOURMOD
if ((to->colourmod[0] != from->colourmod[0] ||
to->colourmod[1] != from->colourmod[1] ||
to->colourmod[2] != from->colourmod[2]) && (fte_extensions & FTE_PEXT_COLOURMOD)) {
evenmorebits |= U_FTE_COLOURMOD;
required_extensions |= FTE_PEXT_COLOURMOD;
}
#endif

if (evenmorebits&0xff00)
evenmorebits |= U_FTE_YETMORE;
if (evenmorebits&0x00ff)
Expand Down Expand Up @@ -430,6 +446,20 @@ void MSG_WriteDeltaEntity (entity_state_t *from, entity_state_t *to, sizebuf_t *
}
if (bits & U_ANGLE3)
MSG_WriteAngle(msg, to->angles[2]);

#ifdef U_FTE_TRANS
if (evenmorebits & U_FTE_TRANS)
MSG_WriteByte (msg, to->trans);
#endif

#ifdef U_FTE_COLOURMOD
if (evenmorebits & U_FTE_COLOURMOD)
{
MSG_WriteByte (msg, to->colourmod[0]);
MSG_WriteByte (msg, to->colourmod[1]);
MSG_WriteByte (msg, to->colourmod[2]);
}
#endif
}

/********************************** READING **********************************/
Expand Down
30 changes: 9 additions & 21 deletions src/sv_ents.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,19 @@ void SV_WriteDelta(client_t* client, entity_state_t *from, entity_state_t *to, s
}

#ifdef U_FTE_TRANS
if (to->trans != from->trans && (fte_extensions & FTE_PEXT_TRANS))
evenmorebits |= U_FTE_TRANS;
if (to->trans != from->trans && (fte_extensions & FTE_PEXT_TRANS)) {
evenmorebits |= U_FTE_TRANS;
required_extensions |= FTE_PEXT_TRANS;
}
#endif

#ifdef U_FTE_COLOURMOD
if ((to->colourmod[0] != from->colourmod[0] ||
to->colourmod[1] != from->colourmod[1] ||
to->colourmod[2] != from->colourmod[2]) && (fte_extensions & FTE_PEXT_COLOURMOD))
to->colourmod[2] != from->colourmod[2]) && (fte_extensions & FTE_PEXT_COLOURMOD)) {
evenmorebits |= U_FTE_COLOURMOD;
required_extensions |= FTE_PEXT_COLOURMOD;
}
#endif

if (evenmorebits&0xff00)
Expand Down Expand Up @@ -644,14 +648,6 @@ static void SV_WritePlayersToClient (client_t *client, client_frame_t *frame, by
pflags |= PF_TRANS_Z;
}
#endif
#ifdef FTE_PEXT_COLOURMOD
if (client->fteprotocolextensions & FTE_PEXT_COLOURMOD &&
(ent->xv.colourmod[0] > 0.0f && ent->xv.colourmod[1] > 0.0f && ent->xv.colourmod[2] > 0.0f) &&
!(ent->xv.colourmod[0] == 1.0f && ent->xv.colourmod[1] == 1.0f && ent->xv.colourmod[2] == 1.0f))
{
pflags |= PF_COLOURMOD;
}
#endif

// Z_EXT_PM_TYPE protocol extension
// encode pm_type and jump_held into pm_code
Expand Down Expand Up @@ -704,8 +700,8 @@ static void SV_WritePlayersToClient (client_t *client, client_frame_t *frame, by
MSG_WriteByte (msg, svc_playerinfo);
MSG_WriteByte (msg, j);

#if defined(FTE_PEXT_TRANS) && defined(FTE_PEXT_COLOURMOD)
if (client->fteprotocolextensions & (FTE_PEXT_TRANS | FTE_PEXT_COLOURMOD))
#if defined(FTE_PEXT_TRANS)
if (client->fteprotocolextensions & FTE_PEXT_TRANS)
{
if (pflags & 0xff0000)
{
Expand Down Expand Up @@ -799,14 +795,6 @@ static void SV_WritePlayersToClient (client_t *client, client_frame_t *frame, by
{
MSG_WriteByte (msg, bound(1, (byte)(ent->xv.alpha * 254.0f), 254));
}
#endif
#ifdef FTE_PEXT_COLOURMOD
if (pflags & PF_COLOURMOD)
{
MSG_WriteByte(msg, bound(0, ent->xv.colourmod[0] * (256.0f / 8.0f), 255));
MSG_WriteByte(msg, bound(0, ent->xv.colourmod[1] * (256.0f / 8.0f), 255));
MSG_WriteByte(msg, bound(0, ent->xv.colourmod[2] * (256.0f / 8.0f), 255));
}
#endif
}
}
Expand Down

0 comments on commit 658a765

Please sign in to comment.