Skip to content

Commit

Permalink
Move CRC to common code, expose CRC_Block().
Browse files Browse the repository at this point in the history
(cherry picked from commit a5b8927)
  • Loading branch information
skullernet authored and res2k committed Jan 18, 2025
1 parent f3a7511 commit 1766086
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
25 changes: 25 additions & 0 deletions inc/common/crc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#pragma once

uint16_t CRC_Block(const byte *start, size_t count);

#if USE_CLIENT
byte COM_BlockSequenceCRCByte(const byte *base, size_t length, int sequence);
#endif
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ common_src = [
'src/common/cmd.c',
'src/common/cmodel.c',
'src/common/common.c',
'src/common/crc.c',
'src/common/cvar.c',
'src/common/error.c',
'src/common/field.c',
Expand Down Expand Up @@ -124,7 +125,6 @@ client_src = [
'src/client/cgame.c',
'src/client/cgame_classic.c',
'src/client/console.c',
'src/client/crc.c',
'src/client/demo.c',
'src/client/download.c',
'src/client/effects.c',
Expand Down
5 changes: 0 additions & 5 deletions src/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -1326,11 +1326,6 @@ void CL_GTV_Shutdown(void);
#define CL_GTV_Shutdown() (void)0
#endif

//
// crc.c
//
byte COM_BlockSequenceCRCByte(const byte *base, size_t length, int sequence);

//
// cgame.c
//
Expand Down
1 change: 1 addition & 0 deletions src/client/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// cl.input.c -- builds an intended movement command to send to the server

#include "client.h"
#include "common/crc.h"

static cvar_t *cl_nodelta;
static cvar_t *cl_maxpackets;
Expand Down
9 changes: 7 additions & 2 deletions src/client/crc.c → src/common/crc.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
/* crc.c */

#include "client.h"
#include "shared/shared.h"
#include "common/crc.h"

// this is a 16 bit, non-reflected CRC using the polynomial 0x1021
// and the initial and final xor values shown below... in other words, the
Expand Down Expand Up @@ -61,7 +62,7 @@ static const uint16_t crctable[256] = {
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
};

static uint16_t CRC_Block(const byte *start, size_t count)
uint16_t CRC_Block(const byte *start, size_t count)
{
uint16_t crc = CRC_INIT_VALUE;

Expand All @@ -71,6 +72,8 @@ static uint16_t CRC_Block(const byte *start, size_t count)
return crc;
}

#if USE_CLIENT

static const byte chktbl[1024] = {
0x84, 0x47, 0x51, 0xc1, 0x93, 0x22, 0x21, 0x24, 0x2f, 0x66, 0x60, 0x4d, 0xb0, 0x7c, 0xda,
0x88, 0x54, 0x15, 0x2b, 0xc6, 0x6c, 0x89, 0xc5, 0x9d, 0x48, 0xee, 0xe6, 0x8a, 0xb5, 0xf4,
Expand Down Expand Up @@ -178,3 +181,5 @@ byte COM_BlockSequenceCRCByte(const byte *base, size_t length, int sequence)

return crc;
}

#endif // USE_CLIENT

0 comments on commit 1766086

Please sign in to comment.