Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -additionaldir command-line option #471

Merged
merged 12 commits into from
Oct 5, 2024
5 changes: 2 additions & 3 deletions Descent3/Game2DLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,16 +565,15 @@ bool InitGameModule(const char *name, module *mod) {
std::filesystem::path dll_name;
std::filesystem::path tmp_dll_name;
// Make the hog filename
lib_name = std::filesystem::path(Base_directory) / "netgames" / name;
lib_name = std::filesystem::path("netgames") / name;
lib_name.replace_extension(".d3m");
// Make the dll filename
dll_name = name;
dll_name.replace_extension(MODULE_EXT);

// Open the hog file
if (!cf_OpenLibrary(lib_name)) {
tmp_dll_name = std::filesystem::path(Base_directory) / "netgames" / name;
tmp_dll_name.replace_extension(".d3m");
tmp_dll_name = cf_LocatePath(lib_name).u8string().c_str();
Multi_game_dll_name.clear();
goto loaddll;
}
Expand Down
12 changes: 5 additions & 7 deletions Descent3/Mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ bool LoadMission(const char *mssn) {

if (IS_MN3_FILE(mssn)) {
strcpy(mission, mssn);
ddio_MakePath(pathname, D3MissionsDir, mission, NULL);
ddio_MakePath(pathname, "missions", mission, NULL);
} else {
strcpy(mission, mssn);
strcpy(pathname, mssn);
Expand Down Expand Up @@ -1645,9 +1645,7 @@ void DoMissionMovie(const char *movie) {
return;
#endif
if (movie && *movie) {
char mpath[_MAX_PATH];
ddio_MakePath(mpath, LocalD3Dir, "movies", movie, NULL);
PlayMovie(mpath);
PlayMovie(movie);
}
}

Expand Down Expand Up @@ -1835,11 +1833,11 @@ bool mn3_Open(const char *mn3file) {
char voice_hog[_MAX_PATH*2];
if ((stricmp(filename, "d3") == 0) || (stricmp(filename, "training") == 0)) {
// Open audio hog file
ddio_MakePath(voice_hog, D3MissionsDir, "d3voice1.hog", nullptr); // Audio for levels 1-4
ddio_MakePath(voice_hog, "missions", "d3voice1.hog", nullptr); // Audio for levels 1-4
Mission_voice_hog_handle = cf_OpenLibrary(voice_hog);
} else if (stricmp(filename, "d3_2") == 0) {
// Open audio hog file
ddio_MakePath(voice_hog, D3MissionsDir, "d3voice2.hog", nullptr); // Audio for levels 5-17
ddio_MakePath(voice_hog, "missions", "d3voice2.hog", nullptr); // Audio for levels 5-17
Mission_voice_hog_handle = cf_OpenLibrary(voice_hog);
}
strcat(filename, ".gam");
Expand All @@ -1855,7 +1853,7 @@ bool mn3_GetInfo(const char *mn3file, tMissionInfo *msn) {
char pathname[_MAX_PATH];
char filename[PSFILENAME_LEN + 1];

ddio_MakePath(pathname, D3MissionsDir, mn3file, nullptr);
ddio_MakePath(pathname, "missions", mn3file, nullptr);
handle = cf_OpenLibrary(pathname);
if (handle == 0) {
LOG_ERROR << "MISSION: MN3 failed to open.";
Expand Down
4 changes: 1 addition & 3 deletions Descent3/PilotPicsAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ bool PPic_InitDatabase(void) {

// attempt to open the hog database
// --------------------------------
char fullpath[_MAX_PATH];
ddio_MakePath(fullpath, LocalD3Dir, PILOTPIC_DATABASE_HOG, NULL);
PilotPic_database_hog_handle = cf_OpenLibrary(fullpath);
PilotPic_database_hog_handle = cf_OpenLibrary(PILOTPIC_DATABASE_HOG);

if (PilotPic_database_hog_handle == 0) {
// there was an error opening the hog database
Expand Down
2 changes: 1 addition & 1 deletion Descent3/ambient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ void WriteAmbientData() {
CFILE *ofile;

#ifndef NEWEDITOR
ddio_MakePath(filename, Base_directory, "data", "misc", AMBIENT_FILE_NAME, NULL);
ddio_MakePath(filename, cf_GetWritableBaseDirectory().u8string().c_str(), "data", "misc", AMBIENT_FILE_NAME, NULL);
#else
ddio_MakePath(filename, D3HogDir, "data", "misc", AMBIENT_FILE_NAME, NULL);
#endif
Expand Down
10 changes: 7 additions & 3 deletions Descent3/args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,26 @@ const char *SkipArgPrefix(const char *arg) {
return arg;
}

int FindArg(const char *which) {
int FindArg(const char *which, int start) {
if (which == nullptr)
return 0;

auto which_matches = [which = SkipArgPrefix(which)](char *arg) -> bool {
return strcasecmp(which, SkipArgPrefix(arg)) == 0;
};

for (int i = 1; i <= TotalArgs; i++) {
for (int i = start; i <= TotalArgs; i++) {
if (which_matches(GameArgs[i])) {
LOG_INFO.printf("FindArg: Found [%s] at argument index (%d).", which, i);
return i;
}
}

LOG_VERBOSE.printf("FindArg: Did not find [%s] on command line.", which);
if (start == 1) {
LOG_VERBOSE.printf("FindArg: Did not find [%s] on command line.", which);
} else {
LOG_VERBOSE.printf("FindArg: Did not find [%s] on command line at index %i or after index %i.", which, start, start);
}
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion Descent3/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void GatherArgs(const char *str);
void GatherArgs(char **argv);

// Returns index of argument sought, or 0 if not found
int FindArg(const char *which);
int FindArg(const char *which, int start = 1);
int FindArgChar(const char *which, char singleCharArg);

const char *GetArg(int index);
Expand Down
5 changes: 1 addition & 4 deletions Descent3/cinematics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ bool InitCinematics() {
return true;
}

char path[_MAX_PATH];
ddio_MakePath(path, Base_directory, "movies", NULL);

if (mve_Init(path, Sound_card_name) != MVELIB_NOERROR)
if (mve_Init() != MVELIB_NOERROR)
return false;

mve_SetCallback(CinematicCallback);
Expand Down
53 changes: 3 additions & 50 deletions Descent3/d3movie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ static bool mve_InitSound();
static void mve_CloseSound();
#endif

// sets the directory where movies are stored
int mve_Init(const char *dir, const char *sndcard) {
int mve_Init() {
#ifndef NO_MOVIES
return MVELIB_NOERROR;
#else
Expand All @@ -72,47 +71,11 @@ void mve_SetCallback(MovieFrameCallback_fp callBack) {
// used to tell movie library how to render movies.
void mve_SetRenderProperties(int16_t x, int16_t y, int16_t w, int16_t h, renderer_type type, bool hicolor) {}

#if defined(POSIX)
// locates the case-sensitive movie file name
std::filesystem::path mve_FindMovieFileRealName(const std::filesystem::path &movie) {
// split into directory and file...
std::filesystem::path t_file = movie.filename();
std::filesystem::path t_dir = movie.parent_path();
std::filesystem::path t_out;

// found a directory?
if (!t_dir.empty()) {
// map the bits (or fail)
t_out = cf_FindRealFileNameCaseInsensitive(t_file, t_dir);
if (t_out.empty())
return t_out;
// re-assemble
return (t_dir / t_out);
} else {
// just a file, map that
t_out = cf_FindRealFileNameCaseInsensitive(t_file);
if (t_out.empty())
return t_out;
// re-assemble
return t_out;
}
}
#endif

// plays a movie using the current screen.
int mve_PlayMovie(const std::filesystem::path &pMovieName, oeApplication *pApp) {
#ifndef NO_MOVIES
// first, find that movie..
std::filesystem::path real_name;
#if defined(POSIX)
real_name = mve_FindMovieFileRealName(pMovieName);
if (real_name.empty()) {
LOG_WARNING.printf("MOVIE: No such file %s", pMovieName.u8string().c_str());
return MVELIB_FILE_ERROR;
}
#else
real_name = pMovieName;
#endif
std::filesystem::path real_name = cf_LocatePath("movies" / pMovieName);
// open movie file.
FILE *hFile = fopen(real_name.u8string().c_str(), "rb");
if (hFile == nullptr) {
Expand Down Expand Up @@ -355,17 +318,7 @@ void CallbackShowFrameNoFlip(unsigned char *buf, unsigned int bufw, unsigned int
intptr_t mve_SequenceStart(const char *mvename, void *fhandle, oeApplication *app, bool looping) {
#ifndef NO_MOVIES
// first, find that movie..
std::filesystem::path real_name;
#if defined(POSIX)
real_name = mve_FindMovieFileRealName(mvename);
if (real_name.empty()) {
LOG_WARNING.printf("MOVIE: No such file %s", mvename);
fhandle = nullptr;
return 0;
}
#else
real_name = mvename;
#endif
std::filesystem::path real_name = cf_LocatePath(std::filesystem::path("movies") / mvename);
winterheart marked this conversation as resolved.
Show resolved Hide resolved
fhandle = fopen(real_name.u8string().c_str(), "rb");

if (fhandle == nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion Descent3/d3movie.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#define MVELIB_PLAYBACK_ERROR (-5)
#define MVELIB_PLAYBACK_ABORTED (-6)

int mve_Init(const char *dir, const char *sndcard);
int mve_Init();

// simply plays a movie.
int mve_PlayMovie(const std::filesystem::path &pMovieName, oeApplication *pApp);
Expand Down
4 changes: 2 additions & 2 deletions Descent3/demofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ void DemoToggleRecording() {
if (stricmp(szfile + (strlen(szfile) - 4), ".dem") != 0) {
strcat(szfile, ".dem");
}
Demo_fname = std::filesystem::path(Base_directory) / "demo" / szfile;
Demo_fname = cf_GetWritableBaseDirectory() / "demo" / szfile;
LOG_INFO.printf("Saving demo to file: %s", Demo_fname.u8string().c_str());
// Try to create the file
Demo_cfp = cfopen(Demo_fname, "wb");
Expand Down Expand Up @@ -1408,7 +1408,7 @@ bool LoadDemoDialog() {
// return false;
// #else

std::filesystem::path file = std::filesystem::path(Base_directory) / "demo";
std::filesystem::path file = cf_GetWritableBaseDirectory() / "demo";

if (DoPathFileDialog(false, file, TXT_VIEWDEMO, {"*.dem"}, PFDF_FILEMUSTEXIST)) {
Demo_fname = file;
Expand Down
2 changes: 1 addition & 1 deletion Descent3/descent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ void Descent3() {
};

for (auto const &intro : intros) {
PlayMovie(std::filesystem::path(Base_directory) / "movies" / intro);
PlayMovie(intro);
}
}

Expand Down
3 changes: 0 additions & 3 deletions Descent3/descent.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ extern bool Descent_overrided_intro;
// How long the a mission name can be
#define MSN_NAMELEN 32

// The "root" directory of the D3 file tree
extern char Base_directory[];

// Variable to preserve current path. TODO: redundant?
extern std::filesystem::path orig_pwd;

Expand Down
2 changes: 1 addition & 1 deletion Descent3/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ void DoScreenshot() {
count = 1;
while (!done) {
snprintf(str, sizeof(str), "Screenshot%.3d.png", count);
ddio_MakePath(filename, Base_directory, str, NULL);
ddio_MakePath(filename, cf_GetWritableBaseDirectory().u8string().c_str(), str, NULL);
infile = (CFILE *)cfopen(filename, "rb");
if (infile == NULL) {
done = 1;
Expand Down
8 changes: 4 additions & 4 deletions Descent3/gamesave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ void QuickSaveGame() {
i = Quicksave_game_slot;

snprintf(filename, sizeof(filename), "saveg00%d", i);
ddio_MakePath(pathname, Base_directory, "savegame", filename, NULL);
ddio_MakePath(pathname, cf_GetWritableBaseDirectory().u8string().c_str(), "savegame", filename, NULL);

fp = fopen(pathname, "rb");
if (fp) {
Expand Down Expand Up @@ -391,7 +391,7 @@ void SaveGameDialog() {
#endif

// setup paths.
ddio_MakePath(savegame_dir, Base_directory, "savegame", NULL);
ddio_MakePath(savegame_dir, cf_GetWritableBaseDirectory().u8string().c_str(), "savegame", NULL);
// ddio_MakePath(pathname, savegame_dir, "*.sav", NULL); -unused

// create savegame directory if it didn't exist before.
Expand Down Expand Up @@ -543,7 +543,7 @@ void __cdecl LoadGameDialogCB(newuiTiledWindow *wnd, void *data)

LOG_DEBUG.printf("savegame slot=%d", id - SAVE_HOTSPOT_ID);

ddio_MakePath(savegame_dir, Base_directory, "savegame", NULL);
ddio_MakePath(savegame_dir, cf_GetWritableBaseDirectory().u8string().c_str(), "savegame", NULL);
snprintf(filename, sizeof(filename), "saveg00%d", (id - SAVE_HOTSPOT_ID));
ddio_MakePath(pathname, savegame_dir, filename, NULL);

Expand Down Expand Up @@ -586,7 +586,7 @@ bool LoadGameDialog() {
}

// setup paths.
ddio_MakePath(savegame_dir, Base_directory, "savegame", NULL);
ddio_MakePath(savegame_dir, cf_GetWritableBaseDirectory().u8string().c_str(), "savegame", NULL);
ddio_MakePath(pathname, savegame_dir, "*.sav", NULL);

// create savegame directory if it didn't exist before.
Expand Down
59 changes: 15 additions & 44 deletions Descent3/gamesequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1295,31 +1295,28 @@ bool GameSequencer() {

// Make sure we have the correct hogfile
void CheckHogfile() {
char hogpath[_MAX_PATH * 2];
const char *new_mn3;
LOG_DEBUG << "Checking to see if we need to open another hog off of disk or CDROM";

if (Current_mission.filename && (stricmp(Current_mission.filename, "d3.mn3") == 0) &&
(Current_mission.cur_level > 4)) {
// close the mission hog file and open d3_2.mn3
mn3_Close();
ddio_MakePath(hogpath, D3MissionsDir, "d3_2.mn3", nullptr);
if (cfexist(hogpath)) {
mn3_Open(hogpath);
mem_free(Current_mission.filename);
Current_mission.filename = mem_strdup("d3_2.mn3");
} else {
SetFunctionMode(MENU_MODE);
}
new_mn3 = "d3_2.mn3";
} else if (Current_mission.filename && (stricmp(Current_mission.filename, "d3_2.mn3") == 0) &&
(Current_mission.cur_level <= 4)) {
// Part 2 of the mission is d3_2.mn3
// close the mission hog file and open d3.mn3
new_mn3 = "d3.mn3";
} else {
new_mn3 = NULL;
}

if (new_mn3) {
// close the mission hog file and open the new one
mn3_Close();
ddio_MakePath(hogpath, D3MissionsDir, "d3.mn3", nullptr);
if (cfexist(hogpath)) {
mn3_Open(hogpath);
auto relative_path = std::filesystem::path("missions") / new_mn3;
auto absolute_path = cf_LocatePath(relative_path);
if (std::filesystem::exists(absolute_path)) {
mn3_Open(relative_path.u8string().c_str());
mem_free(Current_mission.filename);
Current_mission.filename = mem_strdup("d3.mn3");
Current_mission.filename = mem_strdup(new_mn3);
} else {
SetFunctionMode(MENU_MODE);
}
Expand Down Expand Up @@ -1628,35 +1625,9 @@ void StartLevel() {

// Loads a level and starts everything up
bool LoadAndStartCurrentLevel() {
char hogpath[_MAX_PATH * 2];
// This is a bit redundant because we just did it in most cases, but we need to be sure that it always happens,
// and this code is here for weird systems, like save/load and demo, etc.
if (Current_mission.filename && (stricmp(Current_mission.filename, "d3.mn3") == 0) &&
(Current_mission.cur_level > 4)) {
// close the mission hog file and open d3_2.mn3
mn3_Close();
ddio_MakePath(hogpath, D3MissionsDir, "d3_2.mn3", nullptr);
if (cfexist(hogpath)) {
mn3_Open(hogpath);
mem_free(Current_mission.filename);
Current_mission.filename = mem_strdup("d3_2.mn3");
} else {
SetFunctionMode(MENU_MODE);
}
} else if (Current_mission.filename && (stricmp(Current_mission.filename, "d3_2.mn3") == 0) &&
(Current_mission.cur_level <= 4)) {
// Part 2 of the mission is d3_2.mn3
// close the mission hog file and open d3.mn3
mn3_Close();
ddio_MakePath(hogpath, D3MissionsDir, "d3.mn3", nullptr);
if (cfexist(hogpath)) {
mn3_Open(hogpath);
mem_free(Current_mission.filename);
Current_mission.filename = mem_strdup("d3.mn3");
} else {
SetFunctionMode(MENU_MODE);
}
}
CheckHogfile();

// load the level. if fails, then bail out
// ShowProgressScreen (TXT_LOADINGLEVEL);
Expand Down
2 changes: 1 addition & 1 deletion Descent3/gamespy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ int gspy_Init() {
}

// Read the config, resolve the name if needed and setup the server addresses
cfgpath = std::filesystem::path(Base_directory) / gspy_cfgfilename;
cfgpath = cf_LocatePath(gspy_cfgfilename);

gspy_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

Expand Down
Loading
Loading