Skip to content

Commit

Permalink
DOOM: The iwad selector is now ZIP-aware
Browse files Browse the repository at this point in the history
NOTE: This does not add zip support to DOOM (yet), just that it can differentiate compressed PWAD/IWAD.
  • Loading branch information
ducalex committed Jul 26, 2024
1 parent 86289ff commit 2c0e10b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion components/retro-go/rg_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ bool rg_storage_unzip_file(const char *zip_path, const char *filter, void **data
} while (status == TINFL_STATUS_NEEDS_MORE_INPUT);

// With user-provided buffer we might not reach TINFL_STATUS_DONE, but it doesn't mean we've failed
if (output_buffer_pos != output_buffer_size || status < TINFL_STATUS_DONE) // (status != TINFL_STATUS_DONE)
if (status < TINFL_STATUS_DONE) // (status != TINFL_STATUS_DONE)
{
RG_LOGE("Decompression failed! ret: %d", (int)status);
goto _fail;
Expand Down
25 changes: 12 additions & 13 deletions prboom-go/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,14 @@ static void event_handler(int event, void *arg)

bool is_iwad(const char *path)
{
FILE *fp = fopen(path, "rb");
bool valid = fp && fgetc(fp) == 'I' && fgetc(fp) == 'W';
fclose(fp);
return valid;
char header[16] = {0};
void *data = &header;
size_t data_len = 16;
if (rg_extension_match(path, "zip"))
rg_storage_unzip_file(path, NULL, &data, &data_len, RG_FILE_USER_BUFFER);
else
rg_storage_read_file(path, &data, &data_len, RG_FILE_USER_BUFFER);
return header[0] == 'I' && header[1] == 'W';
}

void app_main()
Expand Down Expand Up @@ -545,16 +549,11 @@ void app_main()

const char *iwad = NULL;
const char *pwad = NULL;
FILE *fp;

if ((fp = fopen(app->romPath, "rb")))
{
if (fgetc(fp) == 'P')
pwad = app->romPath;
else
iwad = app->romPath;
fclose(fp);
}
if (is_iwad(app->romPath))
iwad = app->romPath;
else
pwad = app->romPath;

if (!iwad)
{
Expand Down

0 comments on commit 2c0e10b

Please sign in to comment.