Skip to content

Commit

Permalink
- pass sprite array to map hack parser as parameter.
Browse files Browse the repository at this point in the history
This will later allow it to work on temporaries.
  • Loading branch information
coelckers committed Dec 5, 2021
1 parent 963837d commit 4896d04
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion source/build/include/build.h
Expand Up @@ -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);
Expand Down
26 changes: 13 additions & 13 deletions source/core/maphack.cpp
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
Expand All @@ -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;
}
}
}
Expand Down Expand Up @@ -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;
}
}
}
Expand All @@ -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;
}
}
}
Expand All @@ -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;
}
}
}
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/core/maploader.cpp
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion source/games/blood/src/db.cpp
Expand Up @@ -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)
{
Expand Down

0 comments on commit 4896d04

Please sign in to comment.