From 889d5f51db5cfc966a7bdc42cc6289cf0854b0f6 Mon Sep 17 00:00:00 2001 From: Brad Harding Date: Fri, 15 Dec 2023 10:00:32 +1100 Subject: [PATCH] Minor tweaks --- releasenotes.md | 2 +- src/d_main.c | 14 +++++++------- src/md5.c | 48 +++++++++++++++++++++++------------------------- src/md5.h | 24 ++++++++---------------- 4 files changed, 39 insertions(+), 49 deletions(-) diff --git a/releasenotes.md b/releasenotes.md index 452561a5f7..57a56b6580 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -15,7 +15,7 @@ * “SIGIL” can no longer be selected in the episode menu if *SIGIL* isn’t loaded but *SIGIL II* is. * The Spider Mastermind’s health in *E6M8: Abyss Of Despair* is now correct. * [Thorr’s](https://music.apple.com/us/artist/thorr/1325613495) music is now louder. -* If known, the author of the current map is now displayed by the `mapstats` CCMD. +* If the current map is from a supported WAD, its author is now displayed by the `mapstats` CCMD. * A bug is fixed whereby the corpses of monsters could remain solid, blocking the player’s path, in some rare instances. * Minor improvements have been made to text autocompleted in the console by pressing the TAB key. * Minor improvements have been made to the parsing of `enterpic` in `MAPINFO` lumps. diff --git a/src/d_main.c b/src/d_main.c index 8712be7532..2cd25c03d4 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -818,19 +818,19 @@ bool D_IsSIGILWAD(char *filename) { const char *file = leafname(filename); - return (M_StringCompare(file, "SIGIL_v1_21.wad") - || M_StringCompare(file, "SIGIL_v1_2.wad") - || M_StringCompare(file, "SIGIL_v1_1.wad") - || M_StringCompare(file, "SIGIL_v1_0.wad") - || M_StringCompare(file, "SIGIL.wad")); + return ((M_StringStartsWith(file, "SIGIL_V") && M_StringEndsWith(file, ".WAD")) + || M_StringCompare(file, "SIGIL.WAD")); } bool D_IsSIGIL2WAD(char *filename) { const char *file = leafname(filename); - return (M_StringStartsWith(file, "SIGIL_II_MP3_V") - || M_StringStartsWith(file, "SIGIL_II_V")); + return ((M_StringStartsWith(file, "SIGIL_II_MP3_V") && M_StringEndsWith(file, ".WAD")) + || (M_StringStartsWith(file, "SIGIL_II_V") && M_StringEndsWith(file, ".WAD")) + || M_StringCompare(file, "SIGIL2.WAD") + || M_StringCompare(file, "SIGILII.WAD") + || M_StringCompare(file, "SIGIL_II.WAD")); } bool D_IsDOOM2IWAD(char *filename) diff --git a/src/md5.c b/src/md5.c index 762ef01ee4..29e18831ea 100644 --- a/src/md5.c +++ b/src/md5.c @@ -37,24 +37,22 @@ #include #include -#include "doomtype.h" #include "m_misc.h" #include "md5.h" #ifdef WORDS_BIGENDIAN -void byteSwap(UWORD32 *buf, unsigned words) +void byteswap(uint32_t *buf, unsigned int words) { - md5byte *p = (md5byte *)buf; + byte *p = (byte *)buf; do { - *buf++ = (UWORD32)((unsigned)p[3] << 8 | p[2]) << 16 | - ((unsigned)p[1] << 8 | p[0]); + *buf++ = (uint32_t)((unsigned int)p[3] << 8 | p[2]) << 16 | ((unsigned int)p[1] << 8 | p[0]); p += 4; } while (--words); } #else -#define byteSwap(buf, words) +#define byteswap(buf, words) #endif // Start MD5 accumulation. Set bit count to 0 and buffer to mysterious @@ -73,9 +71,9 @@ void MD5Init(MD5Context *ctx) // Update context to reflect the concatenation of another buffer full // of bytes. -void MD5Update(MD5Context *ctx, md5byte const *buf, unsigned len) +void MD5Update(MD5Context *ctx, byte const *buf, unsigned len) { - UWORD32 t = ctx->bytes[0]; + uint32_t t = ctx->bytes[0]; // Update byte count if ((ctx->bytes[0] = t + len) < t) @@ -85,13 +83,13 @@ void MD5Update(MD5Context *ctx, md5byte const *buf, unsigned len) if (t > len) { - memcpy((md5byte *)ctx->in + 64 - t, buf, len); + memcpy((byte *)ctx->in + 64 - t, buf, len); return; } // First chunk is an odd size - memcpy((md5byte *)ctx->in + 64 - t, buf, t); - byteSwap(ctx->in, 16); + memcpy((byte *)ctx->in + 64 - t, buf, t); + byteswap(ctx->in, 16); MD5Transform(ctx->buf, ctx->in); buf += t; len -= t; @@ -100,7 +98,7 @@ void MD5Update(MD5Context *ctx, md5byte const *buf, unsigned len) while (len >= 64) { memcpy(ctx->in, buf, 64); - byteSwap(ctx->in, 16); + byteswap(ctx->in, 16); MD5Transform(ctx->buf, ctx->in); buf += 64; len -= 64; @@ -113,10 +111,10 @@ void MD5Update(MD5Context *ctx, md5byte const *buf, unsigned len) // Final wrap-up - pad to 64-byte boundary with the bit pattern // 1 0* (64-bit count of bits processed, MSB-first) -void MD5Final(md5byte digest[16], MD5Context *ctx) +void MD5Final(byte digest[16], MD5Context *ctx) { int count = ctx->bytes[0] & 0x3f; // Number of bytes in ctx->in - md5byte *p = (md5byte *)ctx->in + count; + byte *p = (byte *)ctx->in + count; // Set the first char of padding to 0x80. There is always room. *p++ = 0x80; @@ -128,21 +126,21 @@ void MD5Final(md5byte digest[16], MD5Context *ctx) { // Padding forces an extra block memset(p, 0, count + 8); - byteSwap(ctx->in, 16); + byteswap(ctx->in, 16); MD5Transform(ctx->buf, ctx->in); - p = (md5byte *)ctx->in; + p = (byte *)ctx->in; count = 56; } memset(p, 0, count); - byteSwap(ctx->in, 14); + byteswap(ctx->in, 14); // Append length in bits and transform ctx->in[14] = ctx->bytes[0] << 3; ctx->in[15] = (ctx->bytes[1] << 3 | ctx->bytes[0] >> 29); MD5Transform(ctx->buf, ctx->in); - byteSwap(ctx->buf, 4); + byteswap(ctx->buf, 4); memcpy(digest, ctx->buf, 16); memset(ctx, 0, sizeof(*ctx)); // In case it's sensitive } @@ -157,17 +155,17 @@ void MD5Final(md5byte digest[16], MD5Context *ctx) #define F4(x, y, z) (y ^ (x | ~z)) // This is the central step in the MD5 algorithm. -#define MD5STEP(f,w,x,y,z,in,s) (w += f(x,y,z) + in, w = (w<>(32-s)) + x) +#define MD5STEP(f, w, x, y, z, in, s) (w += f(x, y, z) + in, w = (w << s | w >> (32 - s)) + x) // The core of the MD5 algorithm, this alters an existing MD5 hash to // reflect the addition of 16 longwords of new data. MD5Update blocks // the data and converts bytes into longwords for this routine. -void MD5Transform(UWORD32 buf[4], UWORD32 const in[16]) +void MD5Transform(uint32_t buf[4], uint32_t const in[16]) { - UWORD32 a = buf[0]; - UWORD32 b = buf[1]; - UWORD32 c = buf[2]; - UWORD32 d = buf[3]; + uint32_t a = buf[0]; + uint32_t b = buf[1]; + uint32_t c = buf[2]; + uint32_t d = buf[3]; MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); @@ -253,7 +251,7 @@ char *MD5(const char *filename) { MD5Context md5; byte buffer[8192]; - size_t len; + size_t len; MD5Init(&md5); diff --git a/src/md5.h b/src/md5.h index 9f8b1925fe..1db5549d1d 100644 --- a/src/md5.h +++ b/src/md5.h @@ -35,27 +35,19 @@ #pragma once -#ifdef _MSC_VER -#include +#include -#define UWORD32 DWORD -#else -#include - -#define UWORD32 uint32_t -#endif - -#define md5byte unsigned char +#include "doomtype.h" typedef struct { - UWORD32 buf[4]; - UWORD32 bytes[2]; - UWORD32 in[16]; + uint32_t buf[4]; + uint32_t bytes[2]; + uint32_t in[16]; } MD5Context; void MD5Init(MD5Context *context); -void MD5Update(MD5Context *context, md5byte const *buf, unsigned len); -void MD5Final(md5byte digest[16], MD5Context *context); -void MD5Transform(UWORD32 buf[4], UWORD32 const in[16]); +void MD5Update(MD5Context *context, byte const *buf, unsigned len); +void MD5Final(byte digest[16], MD5Context *context); +void MD5Transform(uint32_t buf[4], uint32_t const in[16]); char *MD5(const char *filename);