From 0a86348aabe1198f6f63ae523141880658c37b90 Mon Sep 17 00:00:00 2001 From: zicodxx <> Date: Sun, 15 Aug 2010 06:57:51 +0000 Subject: [PATCH] Added support to automatically load/mount ZIP files at startup, giving option to dynamically override or replace game content; Updated docs --- CHANGELOG.txt | 4 ++ INSTALL.txt | 35 +++++++------- include/physfsx.h | 2 + main/inferno.c | 4 +- misc/physfsx.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 143 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 1ad58aff9..17dd49d5a 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,9 @@ D1X-Rebirth Changelog +20100815 +-------- +INSTALL.txt, include/physfsx.h, main/inferno.c, misc/physfsx.c: Added support to automatically load/mount ZIP files at startup, giving option to dynamically override or replace game content; Updated docs + 20100814 -------- main/game.c: Tidy up for EVENT_IDLE case in game_handler, hopefully fixing obscure 'optimise threads' bug diff --git a/INSTALL.txt b/INSTALL.txt index 3b32095c6..b36ddbb12 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -88,27 +88,28 @@ Optional files: D1X-Rebirth is expandable. You can add additional content to the game. - HiRes Briefing Images and Fonts: - -------------------------------- - Available at http://www.dxx-rebirth.com/download/dxx/res/d1xrdata.zip - To add those, copy the ZIP file to the D1X-Rebirth directory or - on *NIX systems - - into Sharepath or ~/.d1x-rebirth. - The Mac data files are already hires. - - Custom/AddOn missions: - ---------------------- + Missions: + --------- Those can be found on several websites. Add them to the game by copying them to subdirectory ‘missions/’. They can also go in subdirectories of 'missions/', unlike with the original version. - Language Packs: - --------------- - German translation: http://www.dxx-rebirth.com/download/dxx/res/D1XBDE01.zip - Copy the txb-files to the Sharepath (non-Mac OS *NIX)/program directory (otherwise). + Custom Music (MP3, OGG, AIF, etc.): + ----------------------------------- + Custom Music can be played via the CUSTOM MUSIC options by specifying it in the Sound Options menu. + Please note that all custom music has to be in 44Khz format. Supported formats depend on the capabilities of SDL_mixer. - Custom Music (like MP3 or OGG): - ------------------------------- - Custom Music can be played via the Jukebox by specifying the path to your music in the Sound Options menu. - Please note that all custom music has to be in 44Khz format. + AddOn Packs: + ------------ + Custom AddOn packs will expand the game in many differnt ways. These are usually provided as ZIP or 7Z and can easily + be installed by putting them to where your game content resides (OS-dependent - see above). + NO EXTRACTION OR ADDITIONAL CONFIGURATION NEEDED. + A list of currently available packs: + - Hires background images and fonts: + http://www.dxx-rebirth.com/download/dxx/res/d1xr-hires.zip + - German briefings: + http://www.dxx-rebirth.com/download/dxx/res/d1xr-briefings-ger.zip + - Soundtrack in OGG format (if your MIDI output just does not kick ass): + http://www.dxx-rebirth.com/download/dxx/res/d1xr-music-ogg.zip Launching the program diff --git a/include/physfsx.h b/include/physfsx.h index 469973589..29397407e 100644 --- a/include/physfsx.h +++ b/include/physfsx.h @@ -166,5 +166,7 @@ extern PHYSFS_sint64 PHYSFSX_getFreeDiskSpace(); extern PHYSFS_file *PHYSFSX_openReadBuffered(char *filename); extern PHYSFS_file *PHYSFSX_openWriteBuffered(char *filename); extern PHYSFS_file *PHYSFSX_openDataFile(char *filename); +extern void PHYSFSX_addArchiveContent(); +extern void PHYSFSX_removeArchiveContent(); #endif /* PHYSFSX_H */ diff --git a/main/inferno.c b/main/inferno.c index 52260c543..2ccb0e39e 100644 --- a/main/inferno.c +++ b/main/inferno.c @@ -361,8 +361,7 @@ int main(int argc, char *argv[]) PHYSFS_freeList(list); } - if (cfile_init("d1xrdata.zip", 0)) - con_printf(CON_NORMAL, "Added d1xrdata.zip for additional content\n"); + PHYSFSX_addArchiveContent(); arch_init(); @@ -460,6 +459,7 @@ int main(int argc, char *argv[]) args_exit(); newmenu_free_background(); free_mission(); + PHYSFSX_removeArchiveContent(); return(0); //presumably successful exit } diff --git a/misc/physfsx.c b/misc/physfsx.c index a94dc1ffb..e37ba4a52 100644 --- a/misc/physfsx.c +++ b/misc/physfsx.c @@ -15,6 +15,8 @@ #endif #include "physfsx.h" +#include "object.h" +#include "newdemo.h" // Initialise PhysicsFS, set up basic search paths and add arguments from .ini file. // The .ini file can be in either the user directory or the same directory as the program. @@ -343,3 +345,118 @@ PHYSFS_file *PHYSFSX_openDataFile(char *filename) return fp; } +/* + * Add archives to the game. + * 1) archives from Sharepath/Data to extend/replace builtin game content + * 2) archived demos + */ +void PHYSFSX_addArchiveContent() +{ + char **list = NULL; + char *archive_exts[] = { ".zip", ".7z", NULL }, *file[2]; + int i = 0; + + // find files in Searchpath ... + list = PHYSFSX_findFiles("", archive_exts); + // if found, add them... + for (i = 0; list[i] != NULL; i++) + { + MALLOC(file[0], char, PATH_MAX); + MALLOC(file[1], char, PATH_MAX); + snprintf(file[0], sizeof(char)*PATH_MAX, "%s", list[i]); + PHYSFSX_getRealPath(file[0],file[1]); + PHYSFS_addToSearchPath(file[1], 0); + d_free(file[0]); + d_free(file[1]); + } + PHYSFS_freeList(list); + list = NULL; + + // find files in DATA_DIR ... + list = PHYSFSX_findFiles("Data/", archive_exts); + // if found, add them... + for (i = 0; list[i] != NULL; i++) + { + MALLOC(file[0], char, PATH_MAX); + MALLOC(file[1], char, PATH_MAX); + snprintf(file[0], sizeof(char)*PATH_MAX, "%s%s", "Data/", list[i]); + PHYSFSX_getRealPath(file[0],file[1]); + PHYSFS_addToSearchPath(file[1], 0); + d_free(file[0]); + d_free(file[1]); + } + PHYSFS_freeList(list); + list = NULL; + + // find files in DEMO_DIR ... + list = PHYSFSX_findFiles(DEMO_DIR, archive_exts); + // if found, add them... + for (i = 0; list[i] != NULL; i++) + { + MALLOC(file[0], char, PATH_MAX); + MALLOC(file[1], char, PATH_MAX); + snprintf(file[0], sizeof(char)*PATH_MAX, "%s%s", DEMO_DIR, list[i]); + PHYSFSX_getRealPath(file[0],file[1]); + PHYSFS_mount(file[1], DEMO_DIR, 0); + d_free(file[0]); + d_free(file[1]); + } + PHYSFS_freeList(list); + list = NULL; +} + +// Removes content added above when quitting game +void PHYSFSX_removeArchiveContent() +{ + char **list = NULL; + char *archive_exts[] = { ".zip", ".7z", NULL }, *file[2]; + int i = 0; + + // find files in Searchpath ... + list = PHYSFSX_findFiles("", archive_exts); + // if found, remove them... + for (i = 0; list[i] != NULL; i++) + { + MALLOC(file[0], char, PATH_MAX); + MALLOC(file[1], char, PATH_MAX); + snprintf(file[0], sizeof(char)*PATH_MAX, "%s", list[i]); + PHYSFSX_getRealPath(file[0],file[1]); + PHYSFS_removeFromSearchPath(file[1]); + d_free(file[0]); + d_free(file[1]); + } + PHYSFS_freeList(list); + list = NULL; + + // find files in DATA_DIR ... + list = PHYSFSX_findFiles("Data/", archive_exts); + // if found, remove them... + for (i = 0; list[i] != NULL; i++) + { + MALLOC(file[0], char, PATH_MAX); + MALLOC(file[1], char, PATH_MAX); + snprintf(file[0], sizeof(char)*PATH_MAX, "%s%s", "Data/", list[i]); + PHYSFSX_getRealPath(file[0],file[1]); + PHYSFS_removeFromSearchPath(file[1]); + d_free(file[0]); + d_free(file[1]); + } + PHYSFS_freeList(list); + list = NULL; + + // find files in DEMO_DIR ... + list = PHYSFSX_findFiles(DEMO_DIR, archive_exts); + // if found, remove them... + for (i = 0; list[i] != NULL; i++) + { + MALLOC(file[0], char, PATH_MAX); + MALLOC(file[1], char, PATH_MAX); + snprintf(file[0], sizeof(char)*PATH_MAX, "%s%s", DEMO_DIR, list[i]); + PHYSFSX_getRealPath(file[0],file[1]); + PHYSFS_removeFromSearchPath(file[1]); + d_free(file[0]); + d_free(file[1]); + } + PHYSFS_freeList(list); + list = NULL; +}