Commit 83a6adda authored by Richard Gobeille's avatar Richard Gobeille

Duke3d: address savegame crash issue

parent 014a7497
......@@ -4206,7 +4206,7 @@ PALONLY:
if (G_TileHasActor(pSprite->picnum))
{
if ((unsigned)scrofs_action + ACTION_PARAM_COUNT > (unsigned)g_scriptSize || apScript[scrofs_action + ACTION_PARAM_COUNT] != CON_ACTION)
if ((unsigned)scrofs_action + ACTION_PARAM_COUNT > (unsigned)g_scriptSize || apScript[scrofs_action + ACTION_PARAM_COUNT] != CON_END)
{
if (scrofs_action)
OSD_Printf("Sprite %d tile %d: invalid action at offset %d\n", i, pSprite->picnum, scrofs_action);
......
......@@ -2788,6 +2788,8 @@ DO_DEFSTATE:
else
{
g_scriptPtr--;
scriptWriteValue(CON_MOVE);
C_GetNextLabelName();
// Check to see it's already defined
......@@ -2825,7 +2827,7 @@ DO_DEFSTATE:
for (k=j; k>=0; k--)
scriptWriteValue(0);
scriptWriteValue(CON_MOVE);
scriptWriteValue(CON_END);
}
continue;
......@@ -2908,6 +2910,8 @@ DO_DEFSTATE:
else
{
g_scriptPtr--;
scriptWriteValue(CON_AI);
C_GetNextLabelName();
if (EDUKE32_PREDICT_FALSE(hash_find(&h_keywords,LAST_LABEL)>=0))
......@@ -2964,7 +2968,7 @@ DO_DEFSTATE:
for (k=j; k<3; k++)
scriptWriteValue(0);
scriptWriteValue(CON_AI);
scriptWriteValue(CON_END);
}
continue;
......@@ -2976,6 +2980,8 @@ DO_DEFSTATE:
else
{
g_scriptPtr--;
scriptWriteValue(CON_ACTION);
C_GetNextLabelName();
// Check to see it's already defined
......@@ -3015,7 +3021,7 @@ DO_DEFSTATE:
for (k=j; k>=0; k--)
scriptWriteValue(0);
scriptWriteValue(CON_ACTION);
scriptWriteValue(CON_END);
}
continue;
......
......@@ -2007,7 +2007,7 @@ static void sv_prelabelload(void)
savegame_labels = (char *)Xmalloc(savegame_labelcnt << 6);
}
static int sv_findlabelindex(int32_t val, int type)
static int sv_findlabelindex(int32_t const val, int const type)
{
for (int i=0;i<g_labelCnt;i++)
if (labelcode[i] == val && (labeltype[i] & type) != 0)
......@@ -2020,14 +2020,21 @@ static int sv_findlabelindex(int32_t val, int type)
return -1;
}
static inline int sv_checkoffset(int const scriptoffs, int const val, int const endoffs)
{
return ((unsigned)scriptoffs > 0 && (unsigned)scriptoffs + endoffs < (unsigned)g_scriptSize
&& apScript[scriptoffs - 1] == val
&& apScript[scriptoffs + endoffs] == CON_END);
}
// translate anything in actor[] that holds an offset into compiled CON into a label index
static void sv_preactorsave(void)
{
for (int i = 0; i < MAXSPRITES; i++)
{
actor_t &a = actor[i];
auto &a = actor[i];
if ((unsigned)AC_MOVE_ID(a.t_data) + 3 < (unsigned)g_scriptSize && apScript[AC_MOVE_ID(a.t_data) + 3] == CON_MOVE)
if (sv_checkoffset(AC_MOVE_ID(a.t_data), CON_MOVE, 3))
{
int const index = sv_findlabelindex(AC_MOVE_ID(a.t_data), LABEL_MOVE | LABEL_DEFINE);
Bassert(index != -1);
......@@ -2035,8 +2042,7 @@ static void sv_preactorsave(void)
a.flags |= SFLAG_RESERVED;
}
if ((unsigned)AC_ACTION_ID(a.t_data) + ACTION_PARAM_COUNT < (unsigned)g_scriptSize
&& apScript[AC_ACTION_ID(a.t_data) + ACTION_PARAM_COUNT] == CON_ACTION)
if (sv_checkoffset(AC_ACTION_ID(a.t_data), CON_ACTION, ACTION_PARAM_COUNT))
{
int const index = sv_findlabelindex(AC_ACTION_ID(a.t_data), LABEL_ACTION);
Bassert(index != -1);
......@@ -2044,7 +2050,7 @@ static void sv_preactorsave(void)
a.flags |= SFLAG_RESERVED2;
}
if ((unsigned)AC_AI_ID(a.t_data) + 3 < (unsigned)g_scriptSize && apScript[AC_AI_ID(a.t_data) + 3] == CON_AI)
if (sv_checkoffset(AC_AI_ID(a.t_data), CON_AI, 3))
{
int const index = sv_findlabelindex(AC_AI_ID(a.t_data), LABEL_AI);
Bassert(index != -1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment