mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-12-27 04:41:23 +00:00
Merge branch 'flat-changing-hotfix' into 'next'
Flat changing hotfix This should fix how Lua scripts that change flats in levels, particularly to flats that don't already exist in the level, cause SRB2 to crash for anyone who joins a netgame afterwards. (I'm not sure if it's a consistent thing or not though) Probably needs a good test to verify the issue is completely fixed before being merged in. Maybe there are other minor things I didn't account for in this fix? I don't know! See merge request !141
This commit is contained in:
commit
5e12f3497a
4 changed files with 73 additions and 59 deletions
|
@ -348,22 +348,12 @@ static int sector_get(lua_State *L)
|
|||
case sector_ceilingheight:
|
||||
lua_pushfixed(L, sector->ceilingheight);
|
||||
return 1;
|
||||
case sector_floorpic: { // floorpic
|
||||
levelflat_t *levelflat;
|
||||
INT16 i;
|
||||
for (i = 0, levelflat = levelflats; i != sector->floorpic; i++, levelflat++)
|
||||
;
|
||||
lua_pushlstring(L, levelflat->name, 8);
|
||||
case sector_floorpic: // floorpic
|
||||
lua_pushlstring(L, levelflats[sector->floorpic].name, 8);
|
||||
return 1;
|
||||
}
|
||||
case sector_ceilingpic: { // ceilingpic
|
||||
levelflat_t *levelflat;
|
||||
INT16 i;
|
||||
for (i = 0, levelflat = levelflats; i != sector->ceilingpic; i++, levelflat++)
|
||||
;
|
||||
lua_pushlstring(L, levelflat->name, 8);
|
||||
case sector_ceilingpic: // ceilingpic
|
||||
lua_pushlstring(L, levelflats[sector->ceilingpic].name, 8);
|
||||
return 1;
|
||||
}
|
||||
case sector_lightlevel:
|
||||
lua_pushinteger(L, sector->lightlevel);
|
||||
return 1;
|
||||
|
@ -400,46 +390,6 @@ static int sector_get(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// help function for P_LoadSectors, find a flat in the active wad files,
|
||||
// allocate an id for it, and set the levelflat (to speedup search)
|
||||
//
|
||||
static INT32 P_AddLevelFlatRuntime(const char *flatname)
|
||||
{
|
||||
size_t i;
|
||||
levelflat_t *levelflat = levelflats;
|
||||
|
||||
//
|
||||
// first scan through the already found flats
|
||||
//
|
||||
for (i = 0; i < numlevelflats; i++, levelflat++)
|
||||
if (strnicmp(levelflat->name,flatname,8)==0)
|
||||
break;
|
||||
|
||||
// that flat was already found in the level, return the id
|
||||
if (i == numlevelflats)
|
||||
{
|
||||
// allocate new flat memory
|
||||
levelflats = Z_Realloc(levelflats, (numlevelflats + 1) * sizeof(*levelflats), PU_LEVEL, NULL);
|
||||
levelflat = levelflats+i;
|
||||
|
||||
// store the name
|
||||
strlcpy(levelflat->name, flatname, sizeof (levelflat->name));
|
||||
strupr(levelflat->name);
|
||||
|
||||
// store the flat lump number
|
||||
levelflat->lumpnum = R_GetFlatNumForName(flatname);
|
||||
|
||||
#ifndef ZDEBUG
|
||||
CONS_Debug(DBG_SETUP, "flat #%03d: %s\n", atoi(sizeu1(numlevelflats)), levelflat->name);
|
||||
#endif
|
||||
|
||||
numlevelflats++;
|
||||
}
|
||||
|
||||
// level flat id
|
||||
return (INT32)i;
|
||||
}
|
||||
|
||||
static int sector_set(lua_State *L)
|
||||
{
|
||||
sector_t *sector = *((sector_t **)luaL_checkudata(L, 1, META_SECTOR));
|
||||
|
|
|
@ -509,10 +509,9 @@ static void P_NetArchiveWorld(void)
|
|||
//
|
||||
// flats
|
||||
//
|
||||
// P_AddLevelFlat should not add but just return the number
|
||||
if (ss->floorpic != P_AddLevelFlat(ms->floorpic, levelflats))
|
||||
if (ss->floorpic != P_CheckLevelFlat(ms->floorpic))
|
||||
diff |= SD_FLOORPIC;
|
||||
if (ss->ceilingpic != P_AddLevelFlat(ms->ceilingpic, levelflats))
|
||||
if (ss->ceilingpic != P_CheckLevelFlat(ms->ceilingpic))
|
||||
diff |= SD_CEILPIC;
|
||||
|
||||
if (ss->lightlevel != SHORT(ms->lightlevel))
|
||||
|
@ -752,12 +751,12 @@ static void P_NetUnArchiveWorld(void)
|
|||
sectors[i].ceilingheight = READFIXED(get);
|
||||
if (diff & SD_FLOORPIC)
|
||||
{
|
||||
sectors[i].floorpic = P_AddLevelFlat((char *)get, levelflats);
|
||||
sectors[i].floorpic = P_AddLevelFlatRuntime((char *)get);
|
||||
get += 8;
|
||||
}
|
||||
if (diff & SD_CEILPIC)
|
||||
{
|
||||
sectors[i].ceilingpic = P_AddLevelFlat((char *)get, levelflats);
|
||||
sectors[i].ceilingpic = P_AddLevelFlatRuntime((char *)get);
|
||||
get += 8;
|
||||
}
|
||||
if (diff & SD_LIGHT)
|
||||
|
|
|
@ -574,6 +574,69 @@ INT32 P_AddLevelFlat(const char *flatname, levelflat_t *levelflat)
|
|||
return (INT32)i;
|
||||
}
|
||||
|
||||
// help function for Lua and $$$.sav reading
|
||||
// same as P_AddLevelFlat, except this is not setup so we must realloc levelflats to fit in the new flat
|
||||
// no longer a static func in lua_maplib.c because p_saveg.c also needs it
|
||||
//
|
||||
INT32 P_AddLevelFlatRuntime(const char *flatname)
|
||||
{
|
||||
size_t i;
|
||||
levelflat_t *levelflat = levelflats;
|
||||
|
||||
//
|
||||
// first scan through the already found flats
|
||||
//
|
||||
for (i = 0; i < numlevelflats; i++, levelflat++)
|
||||
if (strnicmp(levelflat->name,flatname,8)==0)
|
||||
break;
|
||||
|
||||
// that flat was already found in the level, return the id
|
||||
if (i == numlevelflats)
|
||||
{
|
||||
// allocate new flat memory
|
||||
levelflats = Z_Realloc(levelflats, (numlevelflats + 1) * sizeof(*levelflats), PU_LEVEL, NULL);
|
||||
levelflat = levelflats+i;
|
||||
|
||||
// store the name
|
||||
strlcpy(levelflat->name, flatname, sizeof (levelflat->name));
|
||||
strupr(levelflat->name);
|
||||
|
||||
// store the flat lump number
|
||||
levelflat->lumpnum = R_GetFlatNumForName(flatname);
|
||||
|
||||
#ifndef ZDEBUG
|
||||
CONS_Debug(DBG_SETUP, "flat #%03d: %s\n", atoi(sizeu1(numlevelflats)), levelflat->name);
|
||||
#endif
|
||||
|
||||
numlevelflats++;
|
||||
}
|
||||
|
||||
// level flat id
|
||||
return (INT32)i;
|
||||
}
|
||||
|
||||
// help function for $$$.sav checking
|
||||
// this simply returns the flat # for the name given
|
||||
//
|
||||
INT32 P_CheckLevelFlat(const char *flatname)
|
||||
{
|
||||
size_t i;
|
||||
levelflat_t *levelflat = levelflats;
|
||||
|
||||
//
|
||||
// scan through the already found flats
|
||||
//
|
||||
for (i = 0; i < numlevelflats; i++, levelflat++)
|
||||
if (strnicmp(levelflat->name,flatname,8)==0)
|
||||
break;
|
||||
|
||||
if (i == numlevelflats)
|
||||
return 0; // ??? flat was not found, this should not happen!
|
||||
|
||||
// level flat id
|
||||
return (INT32)i;
|
||||
}
|
||||
|
||||
static void P_LoadSectors(lumpnum_t lumpnum)
|
||||
{
|
||||
UINT8 *data;
|
||||
|
|
|
@ -47,6 +47,8 @@ typedef struct
|
|||
extern size_t numlevelflats;
|
||||
extern levelflat_t *levelflats;
|
||||
INT32 P_AddLevelFlat(const char *flatname, levelflat_t *levelflat);
|
||||
INT32 P_AddLevelFlatRuntime(const char *flatname);
|
||||
INT32 P_CheckLevelFlat(const char *flatname);
|
||||
|
||||
extern size_t nummapthings;
|
||||
extern mapthing_t *mapthings;
|
||||
|
|
Loading…
Reference in a new issue