From ad8654ed064b94333eec3f1d24f0e339a90d734b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 7 Mar 2021 09:39:16 +0100 Subject: [PATCH] - fixed maphack loader. The duplicate 'currentSprite' variable prevented it from doing anything. Also cleaned up the interface a bit to avoid using a global variable for parameter passing. Fixes #279 --- source/build/include/build.h | 4 +--- source/core/maphack.cpp | 6 ++---- source/core/maploader.cpp | 6 +++++- source/games/blood/src/db.cpp | 5 +++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/source/build/include/build.h b/source/build/include/build.h index 595404cd6..0e8c43597 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -173,8 +173,6 @@ struct usermaphack_t uint8_t md4[16]{}; }; -extern usermaphack_t g_loadedMapHack; - EXTERN spriteext_t *spriteext; EXTERN spritesmooth_t *spritesmooth; @@ -425,7 +423,7 @@ void initspritelists(void); void engineLoadBoard(const char *filename, int flags, vec3_t *dapos, int16_t *daang, int16_t *dacursectnum); void loadMapBackup(const char* filename); -void G_LoadMapHack(const char* filename); +void G_LoadMapHack(const char* filename, const unsigned char*); int32_t qloadkvx(int32_t voxindex, const char *filename); void vox_undefine(int32_t const); diff --git a/source/core/maphack.cpp b/source/core/maphack.cpp index a9d126f54..3a62a0821 100644 --- a/source/core/maphack.cpp +++ b/source/core/maphack.cpp @@ -36,7 +36,6 @@ #include "sc_man.h" #include "printf.h" -usermaphack_t g_loadedMapHack; // used only for the MD4 part static TArray usermaphacks; void AddUserMapHack(usermaphack_t& mhk) @@ -59,7 +58,6 @@ static int32_t LoadMapHack(const char *filename) while (sc.GetString()) { FString token = sc.String; - int currentsprite = -1; auto validateSprite = [&]() { if (currentsprite < 0) @@ -201,7 +199,7 @@ static int32_t LoadMapHack(const char *filename) return 0; } -void G_LoadMapHack(const char* filename) +void G_LoadMapHack(const char* filename, const unsigned char* md4) { FString hack = StripExtension(filename) + ".mhk"; @@ -209,7 +207,7 @@ void G_LoadMapHack(const char* filename) { for (auto& mhk : usermaphacks) { - if (!memcmp(g_loadedMapHack.md4, mhk.md4, 16)) + if (!memcmp(md4, mhk.md4, 16)) { LoadMapHack(mhk.mhkfile); } diff --git a/source/core/maploader.cpp b/source/core/maploader.cpp index 4d455ca21..fb34935d1 100644 --- a/source/core/maploader.cpp +++ b/source/core/maploader.cpp @@ -439,7 +439,11 @@ void engineLoadBoard(const char* filename, int flags, vec3_t* pos, int16_t* ang, //Must be last. updatesector(pos->x, pos->y, cursectnum); guniqhudid = 0; - G_LoadMapHack(filename); + fr.Seek(0, FileReader::SeekSet); + auto buffer = fr.Read(); + unsigned char md4[16]; + md4once(buffer.Data(), buffer.Size(), md4); + G_LoadMapHack(filename, md4); memcpy(wallbackup, wall, sizeof(wallbackup)); memcpy(sectorbackup, sector, sizeof(sectorbackup)); diff --git a/source/games/blood/src/db.cpp b/source/games/blood/src/db.cpp index e1be1916d..07d372ab7 100644 --- a/source/games/blood/src/db.cpp +++ b/source/games/blood/src/db.cpp @@ -979,8 +979,9 @@ void dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, shor fr.Seek(0, FileReader::SeekSet); auto buffer = fr.Read(); - md4once(buffer.Data(), buffer.Size(), g_loadedMapHack.md4); - G_LoadMapHack(mapname); + unsigned char md4[16]; + md4once(buffer.Data(), buffer.Size(), md4); + G_LoadMapHack(mapname, md4); if (CalcCRC32(buffer.Data(), buffer.Size() -4) != nCRC) {