Skip to content

Commit

Permalink
Merge pull request #455 from winterheart/remove-getmultcdpath
Browse files Browse the repository at this point in the history
Remove redundant GetMultiCDPath()
  • Loading branch information
Lgt2x authored Jun 24, 2024
2 parents ed79350 + c76612e commit c5d5037
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 121 deletions.
47 changes: 10 additions & 37 deletions Descent3/Mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -919,18 +919,7 @@ bool LoadMission(const char *mssn) {
ResetMission(); // Reset everything.
// open MN3 if filename passed was an mn3 file.

// Correct for mission split hack

if (stricmp(mssn, "d3_2.mn3") == 0) {
strcpy(mission, "d3_2.mn3");
strcpy(pathname, "d3_2.mn3");

} else if (stricmp(mssn, "d3.mn3") == 0) {
strcpy(mission, "d3.mn3");
strcpy(pathname, "d3.mn3");

}
else if (IS_MN3_FILE(mssn)) {
if (IS_MN3_FILE(mssn)) {
strcpy(mission, mssn);
ddio_MakePath(pathname, D3MissionsDir, mission, NULL);
} else {
Expand Down Expand Up @@ -1837,13 +1826,9 @@ bool mn3_Open(const char *mn3file) {
mn3file = tempMn3File;
}

const char *p = GetMultiCDPath((char *)mn3file);
// ddio_MakePath(pathname, D3MissionsDir, mn3file, NULL);
if (!p)
return false;
strcpy(pathname, p);
ddio_MakePath(pathname, D3MissionsDir, mn3file, NULL);
// open MN3 HOG.
mn3_handle = cf_OpenLibrary(pathname);
mn3_handle = cf_OpenLibrary(mn3file);
if (mn3_handle == 0) {
return false;
} else {
Expand All @@ -1852,42 +1837,30 @@ bool mn3_Open(const char *mn3file) {
// do table file stuff.
ddio_SplitPath(mn3file, NULL, filename, ext);

// char voice_hog[_MAX_PATH*2];
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", NULL);//Audio for levels 1-4
const char *v = GetMultiCDPath("d3voice1.hog");
if (!v)
return false;
Mission_voice_hog_handle = cf_OpenLibrary(v);
ddio_MakePath(voice_hog, D3MissionsDir, "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", NULL);//Audio for levels 5-17
const char *v = GetMultiCDPath("d3voice2.hog");
if (!v)
return false;
Mission_voice_hog_handle = cf_OpenLibrary(v);
ddio_MakePath(voice_hog, D3MissionsDir, "d3voice2.hog", nullptr); // Audio for levels 5-17
Mission_voice_hog_handle = cf_OpenLibrary(voice_hog);
}
strcat(filename, ".gam");
mng_SetAddonTable(filename);
Current_mission.mn3_handle = mn3_handle;
return true;
}

// returns mission information given the mn3 file.
bool mn3_GetInfo(const char *mn3file, tMissionInfo *msn) {
int handle;
bool retval;
char pathname[_MAX_PATH];
char filename[PSFILENAME_LEN + 1];

if (stricmp(mn3file, "d3.mn3") == 0) {
const char *p = GetMultiCDPath((char *)mn3file);
if (!p)
return false;
strcpy(pathname, p);
} else {
ddio_MakePath(pathname, D3MissionsDir, mn3file, NULL);
}
ddio_MakePath(pathname, D3MissionsDir, mn3file, nullptr);
handle = cf_OpenLibrary(pathname);
if (handle == 0) {
mprintf(0, "MISSION: MN3 failed to open.\n");
Expand Down
56 changes: 1 addition & 55 deletions Descent3/descent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,7 @@ void Descent3() {
for (auto const &intro : intros) {
ddio_MakePath(intropath, Base_directory, "movies", intro, nullptr);
if (cfexist(intropath)) {
const char *t = GetMultiCDPath(intro);
if (t)
PlayMovie(t);
PlayMovie(intropath);
}
}
}
Expand Down Expand Up @@ -715,55 +713,3 @@ void D3DebugResumeHandler() {
#endif

void RenderBlankScreen();

struct file_vols {
char file[_MAX_PATH];
char localpath[_MAX_PATH * 2];
int volume;
bool localized;
};

// This function figures out whether or not a file needs to be loaded off of
// CD or off of the local drive. If it needs to come from a CD, it figures out
// which CD and prompts the user to enter that CD. If they hit cancel, it
// returns NULL.
const char *GetMultiCDPath(const char *file) {
// Filename, directory it might be installed on the hard drive, CD number to look for it
const std::vector<file_vols> file_volumes = {
// file, localpath, volume, localized
{"d3.mn3", "missions", 1, false},
{"d3_2.mn3", "missions", 2, false},
{"level1.mve", "movies", 1, true},
{"level5.mve", "movies", 2, true},
{"end.mve", "movies", 2, true},
{"intro.mve", "movies", 1, true},
{"dolby1.mv8", "movies", 1, true},
{"d3voice1.hog", "missions", 1, true},
{"d3voice2.hog", "missions", 2, true},
};

static char fullpath[_MAX_PATH * 2];

if ((file == nullptr) || (*file == '\0'))
return nullptr;

auto it = std::find_if(
file_volumes.begin(), file_volumes.end(),
[&file](const file_vols& file_volume) {
return (stricmp(file_volume.file, file) == 0);
}
);

// This is a file we don't know about
if (it == file_volumes.end()) {
return file;
}

ddio_MakePath(fullpath, LocalD3Dir, it->localpath, file, nullptr);
// See if the file is in the local dir already.
if (cfexist(fullpath)) {
return fullpath;
}

return nullptr;
}
6 changes: 0 additions & 6 deletions Descent3/descent.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,6 @@ function_mode GetFunctionMode();
void CreateGameViewport(grViewport **vp);
void DestroyGameViewport(grViewport *vp);

// This function figures out whether or not a file needs to be loaded off of
// CD or off of the local drive. If it needs to come from a CD, it figures out
// which CD and prompts the user to enter that CD. If they hit cancel, it
// returns NULL.
const char *GetMultiCDPath(const char *file);

inline void CREATE_VIEWPORT(grViewport **vp) { CreateGameViewport(vp); }

inline void DESTROY_VIEWPORT(grViewport *vp) { DestroyGameViewport(vp); }
Expand Down
20 changes: 8 additions & 12 deletions Descent3/gamesequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1308,9 +1308,8 @@ void CheckHogfile() {
(Current_mission.cur_level > 4)) {
// close the mission hog file and open d3_2.mn3
mn3_Close();
const char *hogp = GetMultiCDPath("d3_2.mn3");
if (hogp) {
strcpy(hogpath, hogp);
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");
Expand All @@ -1322,9 +1321,8 @@ void CheckHogfile() {
// Part 2 of the mission is d3_2.mn3
// close the mission hog file and open d3.mn3
mn3_Close();
const char *hogp = GetMultiCDPath("d3.mn3");
if (hogp) {
strcpy(hogpath, hogp);
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");
Expand Down Expand Up @@ -1643,9 +1641,8 @@ bool LoadAndStartCurrentLevel() {
(Current_mission.cur_level > 4)) {
// close the mission hog file and open d3_2.mn3
mn3_Close();
const char *hogp = GetMultiCDPath("d3_2.mn3");
if (hogp) {
strcpy(hogpath, hogp);
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");
Expand All @@ -1657,9 +1654,8 @@ bool LoadAndStartCurrentLevel() {
// Part 2 of the mission is d3_2.mn3
// close the mission hog file and open d3.mn3
mn3_Close();
const char *hogp = GetMultiCDPath("d3.mn3");
if (hogp) {
strcpy(hogpath, hogp);
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");
Expand Down
10 changes: 4 additions & 6 deletions Descent3/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1155,12 +1155,10 @@ bool MenuNewGame() {

FirstGame = true;

char temppath[_MAX_PATH];
const char *moviepath;
moviepath = GetMultiCDPath("level1.mve");
if (moviepath) {
strcpy(temppath, moviepath);
PlayMovie(temppath);
char moviepath[_MAX_PATH];
ddio_MakePath(moviepath, LocalD3Dir, "movies", "level1.mve", nullptr);
if (cfexist(moviepath)) {
PlayMovie(moviepath);
}
Skip_next_movie = true;

Expand Down
6 changes: 1 addition & 5 deletions Descent3/mission_download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,11 +601,7 @@ int msn_CheckGetMission(network_address *net_addr, char *filename) {
#ifdef OEM
return 1;
#else
if ((stricmp(filename, "d3_2.mn3") == 0) || (stricmp(filename, "d3.mn3") == 0)) {
const char *p = GetMultiCDPath(filename);
return p ? 1 : 0;
}

// Don't download local missions
char pathname[_MAX_PATH];
ddio_MakePath(pathname, D3MissionsDir, filename, NULL);
if (cfexist(filename) || cfexist(pathname)) {
Expand Down

0 comments on commit c5d5037

Please sign in to comment.