diff --git a/source/build/include/build.h b/source/build/include/build.h index a1c1f6a75c2..02f975d0de7 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -354,7 +354,7 @@ void allocateMapArrays(int numsprites); void ValidateSprite(spritetype& spr); void engineLoadBoard(const char *filename, int flags, vec3_t *dapos, int16_t *daang, int *dacursectnum); void loadMapBackup(const char* filename); -void G_LoadMapHack(const char* filename, const unsigned char*); +void G_LoadMapHack(const char* filename, const unsigned char*, spritetype*, int); void videoSetCorrectedAspect(); void videoSetViewableArea(int32_t x1, int32_t y1, int32_t x2, int32_t y2); diff --git a/source/core/maphack.cpp b/source/core/maphack.cpp index 91d7c07b768..f16617e2ad9 100644 --- a/source/core/maphack.cpp +++ b/source/core/maphack.cpp @@ -48,7 +48,7 @@ void AddUserMapHack(usermaphack_t& mhk) usermaphacks.Push(mhk); } -static int32_t LoadMapHack(const char *filename) +static int32_t LoadMapHack(const char *filename, spritetype* sprites, int numsprites) { int currentsprite = -1; int currentwall = -1; @@ -67,7 +67,7 @@ static int32_t LoadMapHack(const char *filename) FString token = sc.String; auto validateSprite = [&]() { - if (currentsprite < 0) + if (currentsprite < 0 || currentsprite >= numsprites) { sc.ScriptMessage("Using %s without a valid sprite", token.GetChars()); return false; @@ -77,7 +77,7 @@ static int32_t LoadMapHack(const char *filename) auto validateWall = [&]() { - if (currentwall < 0) + if (currentwall < 0 || currentwall >= numwalls) { sc.ScriptMessage("Using %s without a valid wall", token.GetChars()); return false; @@ -87,7 +87,7 @@ static int32_t LoadMapHack(const char *filename) auto validateSector = [&]() { - if (currentsector < 0) + if (currentsector < 0 || currentsector >= numsectors) { sc.ScriptMessage("Using %s without a valid sector", token.GetChars()); return false; @@ -154,7 +154,7 @@ static int32_t LoadMapHack(const char *filename) { if (currentsprite != -1 && validateSprite()) { - sprite[currentsprite].sectnum = sc.Number; + sprites[currentsprite].sectnum = sc.Number; } } } @@ -168,7 +168,7 @@ static int32_t LoadMapHack(const char *filename) } else if (currentsprite != -1 && validateSprite()) { - sprite[currentsprite].picnum = sc.Number; + sprites[currentsprite].picnum = sc.Number; } } } @@ -219,7 +219,7 @@ static int32_t LoadMapHack(const char *filename) } else if (currentsprite != -1 && validateSprite()) { - sprite[currentsprite].cstat &= ~sc.Number; + sprites[currentsprite].cstat &= ~sc.Number; } } } @@ -233,7 +233,7 @@ static int32_t LoadMapHack(const char *filename) } else if (currentsprite != -1 && validateSprite()) { - sprite[currentsprite].cstat |= sc.Number; + sprites[currentsprite].cstat |= sc.Number; } } } @@ -247,7 +247,7 @@ static int32_t LoadMapHack(const char *filename) } else if (currentsprite != -1 && validateSprite()) { - sprite[currentsprite].lotag = sc.Number; + sprites[currentsprite].lotag = sc.Number; } } } @@ -374,7 +374,7 @@ static int32_t LoadMapHack(const char *filename) return 0; } -void G_LoadMapHack(const char* filename, const unsigned char* md4) +void G_LoadMapHack(const char* filename, const unsigned char* md4, spritetype* sprites, int numsprites) { hw_ClearSplitSector(); blockingpairs.Reset(); @@ -384,16 +384,16 @@ void G_LoadMapHack(const char* filename, const unsigned char* md4) { internal.AppendFormat("%02x", md4[j]); } - LoadMapHack(internal + ".mhk"); + LoadMapHack(internal + ".mhk", sprites, numsprites); FString hack = StripExtension(filename) + ".mhk"; - if (LoadMapHack(hack)) + if (LoadMapHack(hack, sprites, numsprites)) { for (auto& mhk : usermaphacks) { if (!memcmp(md4, mhk.md4, 16)) { - LoadMapHack(mhk.mhkfile); + LoadMapHack(mhk.mhkfile, sprites, numsprites); } } } diff --git a/source/core/maploader.cpp b/source/core/maploader.cpp index 312d752b6ea..ab32c7e4e39 100644 --- a/source/core/maploader.cpp +++ b/source/core/maploader.cpp @@ -513,7 +513,7 @@ void engineLoadBoard(const char* filename, int flags, vec3_t* pos, int16_t* ang, auto buffer = fr.Read(); unsigned char md4[16]; md4once(buffer.Data(), buffer.Size(), md4); - G_LoadMapHack(filename, md4); + G_LoadMapHack(filename, md4, sprite, numsprites); setWallSectors(); hw_BuildSections(); sectorGeometry.SetSize(numsections); diff --git a/source/games/blood/src/db.cpp b/source/games/blood/src/db.cpp index bd2f3a0df5c..741023cd35d 100644 --- a/source/games/blood/src/db.cpp +++ b/source/games/blood/src/db.cpp @@ -885,7 +885,7 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect auto buffer = fr.Read(); uint8_t md4[16]; md4once(buffer.Data(), buffer.Size(), md4); - G_LoadMapHack(mapname, md4); + G_LoadMapHack(mapname, md4, sprite, mapHeader.numsprites); if (CalcCRC32(buffer.Data(), buffer.Size() - 4) != nCRC) {