- pass sprite array to map hack parser as parameter.

This will later allow it to work on temporaries.
This commit is contained in:
Christoph Oelckers 2021-12-03 19:54:29 +01:00
parent 5dfc79bdbe
commit 58cd933d74
4 changed files with 16 additions and 16 deletions

View file

@ -353,7 +353,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);

View file

@ -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;
@ -157,7 +157,7 @@ static int32_t LoadMapHack(const char *filename)
{
if (currentsprite != -1 && validateSprite())
{
sprite[currentsprite].sectnum = sc.Number;
sprites[currentsprite].sectnum = sc.Number;
}
}
}
@ -171,7 +171,7 @@ static int32_t LoadMapHack(const char *filename)
}
else if (currentsprite != -1 && validateSprite())
{
sprite[currentsprite].picnum = sc.Number;
sprites[currentsprite].picnum = sc.Number;
}
}
}
@ -222,7 +222,7 @@ static int32_t LoadMapHack(const char *filename)
}
else if (currentsprite != -1 && validateSprite())
{
sprite[currentsprite].cstat &= ~sc.Number;
sprites[currentsprite].cstat &= ~sc.Number;
}
}
}
@ -236,7 +236,7 @@ static int32_t LoadMapHack(const char *filename)
}
else if (currentsprite != -1 && validateSprite())
{
sprite[currentsprite].cstat |= sc.Number;
sprites[currentsprite].cstat |= sc.Number;
}
}
}
@ -250,7 +250,7 @@ static int32_t LoadMapHack(const char *filename)
}
else if (currentsprite != -1 && validateSprite())
{
sprite[currentsprite].lotag = sc.Number;
sprites[currentsprite].lotag = sc.Number;
}
}
}
@ -377,7 +377,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();
@ -387,16 +387,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);
}
}
}

View file

@ -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);

View file

@ -884,7 +884,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)
{