From 28668972ff909e8699817f8e58437460ff7f9d52 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 27 Feb 2024 00:37:26 +0200 Subject: [PATCH] client: add custom protocol with short model index --- src/client/cl_main.c | 2 +- src/client/cl_parse.c | 65 ++++++++++++++++++++++++++++---------- src/common/header/common.h | 6 ++-- src/common/movemsg.c | 56 ++++++++++++++++++++++++-------- src/server/header/server.h | 1 + src/server/sv_entities.c | 13 +++++--- src/server/sv_user.c | 3 +- 7 files changed, 106 insertions(+), 40 deletions(-) diff --git a/src/client/cl_main.c b/src/client/cl_main.c index e50b2796..e27f9e11 100644 --- a/src/client/cl_main.c +++ b/src/client/cl_main.c @@ -247,7 +247,7 @@ CL_Record_f(void) MSG_WriteByte(&buf, svc_spawnbaseline); MSG_WriteDeltaEntity(&nullstate, &cl_entities[i].baseline, - &buf, true, true); + &buf, true, true, PROTOCOL_VERSION); } MSG_WriteByte(&buf, svc_stufftext); diff --git a/src/client/cl_parse.c b/src/client/cl_parse.c index 8e95d9cf..95ec1ee0 100644 --- a/src/client/cl_parse.c +++ b/src/client/cl_parse.c @@ -143,24 +143,51 @@ CL_ParseDelta(entity_state_t *from, entity_state_t *to, int number, int bits) VectorCopy(from->origin, to->old_origin); to->number = number; - if (bits & U_MODEL) + if ((cls.serverProtocol == PROTOCOL_RELEASE_VERSION) || + (cls.serverProtocol == PROTOCOL_DEMO_VERSION) || + (cls.serverProtocol == PROTOCOL_RR97_VERSION)) { - to->modelindex = MSG_ReadByte(&net_message); - } + if (bits & U_MODEL) + { + to->modelindex = MSG_ReadByte(&net_message); + } - if (bits & U_MODEL2) - { - to->modelindex2 = MSG_ReadByte(&net_message); - } + if (bits & U_MODEL2) + { + to->modelindex2 = MSG_ReadByte(&net_message); + } - if (bits & U_MODEL3) - { - to->modelindex3 = MSG_ReadByte(&net_message); - } + if (bits & U_MODEL3) + { + to->modelindex3 = MSG_ReadByte(&net_message); + } - if (bits & U_MODEL4) + if (bits & U_MODEL4) + { + to->modelindex4 = MSG_ReadByte(&net_message); + } + } + else { - to->modelindex4 = MSG_ReadByte(&net_message); + if (bits & U_MODEL) + { + to->modelindex = MSG_ReadShort(&net_message); + } + + if (bits & U_MODEL2) + { + to->modelindex2 = MSG_ReadShort(&net_message); + } + + if (bits & U_MODEL3) + { + to->modelindex3 = MSG_ReadShort(&net_message); + } + + if (bits & U_MODEL4) + { + to->modelindex4 = MSG_ReadShort(&net_message); + } } if (bits & U_FRAME8) @@ -689,7 +716,7 @@ CL_ParseFrame(void) cl.frame.servertime = cl.frame.serverframe * 100; /* BIG HACK to let old demos continue to work */ - if (cls.serverProtocol != 26) + if (cls.serverProtocol != PROTOCOL_RELEASE_VERSION) { cl.surpressCount = MSG_ReadByte(&net_message); } @@ -843,9 +870,10 @@ CL_ParseServerData(void) if (Com_ServerState() && ( (i == PROTOCOL_RELEASE_VERSION) || (i == PROTOCOL_DEMO_VERSION) || - (i == PROTOCOL_VERSION) || + (i == PROTOCOL_RR97_VERSION) || (i == PROTOCOL_RR22_VERSION) || - (i == PROTOCOL_RR23_VERSION))) + (i == PROTOCOL_RR23_VERSION) || + (i == PROTOCOL_VERSION))) { Com_Printf("Network protocol: "); switch (i) @@ -856,7 +884,7 @@ CL_ParseServerData(void) case PROTOCOL_DEMO_VERSION: Com_Printf("Quake 2 Release Demo\n"); break; - case PROTOCOL_VERSION: + case PROTOCOL_RR97_VERSION: Com_Printf("Quake 2\n"); break; case PROTOCOL_RR22_VERSION: @@ -865,6 +893,9 @@ CL_ParseServerData(void) case PROTOCOL_RR23_VERSION: Com_Printf("ReRelease Quake 2\n"); break; + case PROTOCOL_VERSION: + Com_Printf("ReRelease Quake 2 Custom version\n"); + break; default: Com_Printf("Unknown protocol version\n"); break; diff --git a/src/common/header/common.h b/src/common/header/common.h index 6bfa7799..a364dbf8 100644 --- a/src/common/header/common.h +++ b/src/common/header/common.h @@ -120,7 +120,7 @@ void MSG_WriteDeltaUsercmd(sizebuf_t *sb, struct usercmd_s *from, struct usercmd_s *cmd); void MSG_WriteDeltaEntity(struct entity_state_s *from, struct entity_state_s *to, sizebuf_t *msg, - qboolean force, qboolean newentity); + qboolean force, qboolean newentity, int protocol); void MSG_WriteDir(sizebuf_t *sb, vec3_t vector); void MSG_BeginReading(sizebuf_t *sb); @@ -180,11 +180,13 @@ void Info_Print(char *s); /* Quake 2 Demo */ #define PROTOCOL_DEMO_VERSION 31 /* Quake 2 Network Release */ -#define PROTOCOL_VERSION 34 +#define PROTOCOL_RR97_VERSION 34 /* ReRelease demo files */ #define PROTOCOL_RR22_VERSION 2022 /* ReRelease network protocol */ #define PROTOCOL_RR23_VERSION 2023 +/* Quake 2 Customized Network Release */ +#define PROTOCOL_VERSION 2024 /* ========================================= */ diff --git a/src/common/movemsg.c b/src/common/movemsg.c index e7b55f03..f339b4de 100644 --- a/src/common/movemsg.c +++ b/src/common/movemsg.c @@ -433,7 +433,8 @@ MSG_WriteDeltaEntity(entity_state_t *from, entity_state_t *to, sizebuf_t *msg, qboolean force, - qboolean newentity) + qboolean newentity, + int protocol) { int bits; @@ -644,24 +645,51 @@ MSG_WriteDeltaEntity(entity_state_t *from, MSG_WriteByte(msg, to->number); } - if (bits & U_MODEL) + if ((protocol == PROTOCOL_RELEASE_VERSION) || + (protocol == PROTOCOL_DEMO_VERSION) || + (protocol == PROTOCOL_RR97_VERSION)) { - MSG_WriteByte(msg, to->modelindex); - } + if (bits & U_MODEL) + { + MSG_WriteByte(msg, to->modelindex); + } - if (bits & U_MODEL2) - { - MSG_WriteByte(msg, to->modelindex2); - } + if (bits & U_MODEL2) + { + MSG_WriteByte(msg, to->modelindex2); + } - if (bits & U_MODEL3) - { - MSG_WriteByte(msg, to->modelindex3); - } + if (bits & U_MODEL3) + { + MSG_WriteByte(msg, to->modelindex3); + } - if (bits & U_MODEL4) + if (bits & U_MODEL4) + { + MSG_WriteByte(msg, to->modelindex4); + } + } + else { - MSG_WriteByte(msg, to->modelindex4); + if (bits & U_MODEL) + { + MSG_WriteShort(msg, to->modelindex); + } + + if (bits & U_MODEL2) + { + MSG_WriteShort(msg, to->modelindex2); + } + + if (bits & U_MODEL3) + { + MSG_WriteShort(msg, to->modelindex3); + } + + if (bits & U_MODEL4) + { + MSG_WriteShort(msg, to->modelindex4); + } } if (bits & U_FRAME8) diff --git a/src/server/header/server.h b/src/server/header/server.h index f2e75a67..87b241c5 100644 --- a/src/server/header/server.h +++ b/src/server/header/server.h @@ -144,6 +144,7 @@ typedef struct client_s int challenge; /* challenge of this user, randomly generated */ netchan_t netchan; + int protocol; } client_t; typedef struct diff --git a/src/server/sv_entities.c b/src/server/sv_entities.c index 0360f01a..7fc2af75 100644 --- a/src/server/sv_entities.c +++ b/src/server/sv_entities.c @@ -37,7 +37,8 @@ static YQ2_ALIGNAS_TYPE(int32_t) byte fatpvs[65536 / 8]; * Writes a delta update of an entity_state_t list to the message. */ static void -SV_EmitPacketEntities(client_frame_t *from, client_frame_t *to, sizebuf_t *msg) +SV_EmitPacketEntities(client_frame_t *from, client_frame_t *to, sizebuf_t *msg, + int protocol) { entity_state_t *oldent, *newent; int oldindex, newindex; @@ -98,7 +99,7 @@ SV_EmitPacketEntities(client_frame_t *from, client_frame_t *to, sizebuf_t *msg) note that players are always 'newentities', this updates their oldorigin always and prevents warping */ MSG_WriteDeltaEntity(oldent, newent, msg, - false, newent->number <= maxclients->value); + false, newent->number <= maxclients->value, protocol); oldindex++; newindex++; continue; @@ -107,7 +108,8 @@ SV_EmitPacketEntities(client_frame_t *from, client_frame_t *to, sizebuf_t *msg) if (newnum < oldnum) { /* this is a new entity, send it from the baseline */ - MSG_WriteDeltaEntity(&sv.baselines[newnum], newent, msg, true, true); + MSG_WriteDeltaEntity(&sv.baselines[newnum], newent, msg, + true, true, protocol); newindex++; continue; } @@ -432,7 +434,7 @@ SV_WriteFrameToClient(client_t *client, sizebuf_t *msg) SV_WritePlayerstateToClient(oldframe, frame, msg); /* delta encode the entities */ - SV_EmitPacketEntities(oldframe, frame, msg); + SV_EmitPacketEntities(oldframe, frame, msg, client->protocol); } /* @@ -705,7 +707,8 @@ SV_RecordDemoMessage(void) (ent->s.modelindex || ent->s.effects || ent->s.sound || ent->s.event) && !(ent->svflags & SVF_NOCLIENT)) { - MSG_WriteDeltaEntity(&nostate, &ent->s, &buf, false, true); + MSG_WriteDeltaEntity(&nostate, &ent->s, &buf, + false, true, PROTOCOL_VERSION); } e++; diff --git a/src/server/sv_user.c b/src/server/sv_user.c index 0977b174..71b57aba 100644 --- a/src/server/sv_user.c +++ b/src/server/sv_user.c @@ -75,6 +75,7 @@ SV_New_f(void) gamedir = (char *)Cvar_VariableString("gamedir"); /* send the serverdata */ + sv_client->protocol = PROTOCOL_VERSION; MSG_WriteByte(&sv_client->netchan.message, svc_serverdata); MSG_WriteLong(&sv_client->netchan.message, PROTOCOL_VERSION); MSG_WriteLong(&sv_client->netchan.message, svs.spawncount); @@ -201,7 +202,7 @@ SV_Baselines_f(void) MSG_WriteByte(&sv_client->netchan.message, svc_spawnbaseline); MSG_WriteDeltaEntity(&nullstate, base, &sv_client->netchan.message, - true, true); + true, true, sv_client->protocol); } start++;