3 Commits

Author SHA1 Message Date
Ethan Lee
abe3eb6077 2.3.6 2021-12-22 08:20:25 -05:00
Misa
cfa0d04bbb LoadImage: Check LodePNG return value and print errors
Dvoid from Discord just reported a crash when trying to load a
custom tiles2.png that was encoded weirdly.

The problem is that we don't check the return value from LodePNG, so
LodePNG gives us a null pointer, and then SDL_CreateRGBSurfaceFrom
doesn't check this null pointer, which then propagates until we crash in
SDL_ConvertSurfaceFormat (or rather, one of its sub-functions), and we
would probably crash somewhere else anyway if it continued.

After properly checking LodePNG's return value, along with printing the
error, it turns out that Dvoid's custom tiles2.png had an "invalid CRC".
I don't know what this means but it sounds worrying. `feh` can read the
file correctly but it also reports a "CRC error".
2021-12-21 23:59:44 -08:00
Misa
cc3dc8d329 Don't go back to main menu when deleting main game save data
Going back to the main menu allowed for glitchiness to occur if you
deleted your save data while in in-game options. This meant you could
then load back in to the game, and then quit to the menu, then open the
options and then jump back in-game, exploring the state of the game
after hardreset() had been called on it. Which is: pretty glitchy.

For example, this meant having your room coordinates be 0,0 (which is
different from 100,100, which is the actual 0,0, thanks for the
100-indexing Terry), which caused some of the room transitions to be
disabled because room transitions were disabled if the
game.door_up/down/left/right variables were -2 or less, and they were
computed based on room coordinates, which meant some of them went
negative if you were 0,0 and not 100,100. At least this was the case
until I removed those variables for, at best, doing nothing, and at
worst, being actively harmful.

Anyways, so deleting your save data now just takes you back to the
previous menu, much like deleting custom level data does. I don't know
why deleting save data put you back on the main menu in the first place.
It's not like the options menu needed to be reloaded or anything. I
checked and this was the behavior in 2.0 as well, so it was probably
added for a dumb reason.

I considered prohibiting data deletion if you were ingame_titlemode, but
as of the moment it seems to be okay (if albeit weird, e.g. returning to
menu while in Secret Lab doesn't place your cursor on the "play"
button), and I can always add such a prohibition later if it was really
causing problems. Can't think of anything bad off of the top of my head,
though.

Btw thanks to Elomavi for discovering that you could do this glitch.
2021-12-21 23:58:22 -08:00
3 changed files with 13 additions and 7 deletions

View File

@@ -22,6 +22,7 @@ extern "C"
const unsigned char* in, const unsigned char* in,
size_t insize size_t insize
); );
extern const char* lodepng_error_text(unsigned code);
} }
static SDL_Surface* LoadImage(const char *filename, bool noBlend = true, bool noAlpha = false) static SDL_Surface* LoadImage(const char *filename, bool noBlend = true, bool noAlpha = false)
@@ -33,6 +34,7 @@ static SDL_Surface* LoadImage(const char *filename, bool noBlend = true, bool no
unsigned char *data; unsigned char *data;
unsigned int width, height; unsigned int width, height;
unsigned int error;
unsigned char *fileIn; unsigned char *fileIn;
size_t length; size_t length;
@@ -44,14 +46,20 @@ static SDL_Surface* LoadImage(const char *filename, bool noBlend = true, bool no
} }
if (noAlpha) if (noAlpha)
{ {
lodepng_decode24(&data, &width, &height, fileIn, length); error = lodepng_decode24(&data, &width, &height, fileIn, length);
} }
else else
{ {
lodepng_decode32(&data, &width, &height, fileIn, length); error = lodepng_decode32(&data, &width, &height, fileIn, length);
} }
FILESYSTEM_freeMemory(&fileIn); FILESYSTEM_freeMemory(&fileIn);
if (error != 0)
{
fprintf(stderr, "Could not load %s: %s\n", filename, lodepng_error_text(error));
return NULL;
}
loadedImage = SDL_CreateRGBSurfaceFrom( loadedImage = SDL_CreateRGBSurfaceFrom(
data, data,
width, width,

View File

@@ -1491,8 +1491,6 @@ static void menuactionpress(void)
case 0: case 0:
//back //back
music.playef(11); music.playef(11);
game.returnmenu();
map.nexttowercolour();
break; break;
default: default:
//yep //yep
@@ -1503,10 +1501,10 @@ static void menuactionpress(void)
game.deletesettings(); game.deletesettings();
game.flashlight = 5; game.flashlight = 5;
game.screenshake = 15; game.screenshake = 15;
game.createmenu(Menu::mainmenu);
map.nexttowercolour();
break; break;
} }
game.returnmenu();
map.nexttowercolour();
break; break;
case Menu::clearcustomdatamenu: case Menu::clearcustomdatamenu:
switch (game.currentmenuoption) switch (game.currentmenuoption)

View File

@@ -159,7 +159,7 @@ static void menurender(void)
#ifdef INTERIM_COMMIT #ifdef INTERIM_COMMIT
graphics.Print( 310 - (SDL_arraysize(INTERIM_COMMIT) - 1) * 8, 220, INTERIM_COMMIT, tr/2, tg/2, tb/2); graphics.Print( 310 - (SDL_arraysize(INTERIM_COMMIT) - 1) * 8, 220, INTERIM_COMMIT, tr/2, tg/2, tb/2);
#endif #endif
graphics.Print( 310 - (6*8), 230, "v2.3.5", tr/2, tg/2, tb/2); graphics.Print( 310 - (6*8), 230, "v2.3.6", tr/2, tg/2, tb/2);
if(music.mmmmmm){ if(music.mmmmmm){
graphics.Print( 10, 230, "[MMMMMM Mod Installed]", tr/2, tg/2, tb/2); graphics.Print( 10, 230, "[MMMMMM Mod Installed]", tr/2, tg/2, tb/2);