bsputil: write ents in binary mode and print its crc in 4-digit hex (#317)

This commit is contained in:
Ozkan Sezer 2021-09-09 02:50:32 +03:00 committed by GitHub
parent 5fef157f53
commit 69cb6b981f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View File

@ -593,11 +593,12 @@ main(int argc, char **argv)
WriteBSPFile(source, &bspdata); WriteBSPFile(source, &bspdata);
} else if (!strcmp(argv[i], "--extract-entities")) { } else if (!strcmp(argv[i], "--extract-entities")) {
unsigned int crc = CRC_Block((unsigned char *)bsp->dentdata, bsp->entdatasize - 1);
StripExtension(source); StripExtension(source);
DefaultExtension(source, ".ent"); DefaultExtension(source, ".ent");
printf("-> writing %s... ", source); printf("-> writing %s [CRC: %04x]... ", source, crc);
f = fopen(source, "w"); f = fopen(source, "wb");
if (!f) if (!f)
Error("couldn't open %s for writing\n", source); Error("couldn't open %s for writing\n", source);

View File

@ -1115,6 +1115,15 @@ CRC_Value(unsigned short crcvalue)
return crcvalue ^ CRC_XOR_VALUE; return crcvalue ^ CRC_XOR_VALUE;
} }
unsigned short CRC_Block (const unsigned char *start, int count)
{
unsigned short crc;
CRC_Init (&crc);
while (count--)
crc = (crc << 8) ^ crctable[(crc >> 8) ^ *start++];
return crc;
}
/* ========================================================================= */ /* ========================================================================= */
/* /*

View File

@ -125,6 +125,7 @@ char *copystring(const char *s);
void CRC_Init(unsigned short *crcvalue); void CRC_Init(unsigned short *crcvalue);
void CRC_ProcessByte(unsigned short *crcvalue, uint8_t data); void CRC_ProcessByte(unsigned short *crcvalue, uint8_t data);
unsigned short CRC_Value(unsigned short crcvalue); unsigned short CRC_Value(unsigned short crcvalue);
unsigned short CRC_Block (const unsigned char *start, int count);
void CreatePath(char *path); void CreatePath(char *path);
void Q_CopyFile(const char *from, char *to); void Q_CopyFile(const char *from, char *to);