Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Descent3/Game2DLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ bool InitGameModule(const char *name, module *mod) {

// Open the hog file
if (!cf_OpenLibrary(lib_name)) {
tmp_dll_name = cf_LocatePath(lib_name).u8string().c_str();
tmp_dll_name = cf_LocatePath(lib_name);
Multi_game_dll_name.clear();
goto loaddll;
}
Expand Down
10 changes: 3 additions & 7 deletions Descent3/Inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,7 @@ bool Inventory::AddCounterMeasure(int id, int aux_type, int aux_id, int flags, c
newnode->iflags |= INVF_SELECTABLE | INVF_USEABLE | INVF_MISSIONITEM | INVF_TIMEOUTONSPEW;

if (Weapons[id].icon_handle >= 0) {
newnode->icon_name =
mem_rmalloc<char>(strlen(GameBitmaps[GameTextures[Weapons[id].icon_handle].bm_handle].name) + 1);
strcpy(newnode->icon_name, GameBitmaps[GameTextures[Weapons[id].icon_handle].bm_handle].name);
newnode->icon_name = mem_strdup(GameBitmaps[GameTextures[Weapons[id].icon_handle].bm_handle].name);
} else {
newnode->icon_name = nullptr;
}
Expand Down Expand Up @@ -647,8 +645,7 @@ bool Inventory::AddObjectItem(int otype, int oid, int oauxt, int oauxi, int flag
newnode->oid = oauxi;

if (Object_info[oid].description) {
newnode->description = mem_rmalloc<char>(strlen(Object_info[oid].description) + 1);
strcpy(newnode->description, Object_info[oid].description);
newnode->description = mem_strdup(Object_info[oid].description);
} else {
newnode->description = mem_rmalloc<char>();
newnode->description[0] = 0;
Expand All @@ -672,8 +669,7 @@ bool Inventory::AddObjectItem(int otype, int oid, int oauxt, int oauxi, int flag
if (flags & INVAF_LEVELLAST)
newnode->iflags |= INVAF_LEVELLAST;

newnode->icon_name = mem_rmalloc<char>(strlen(Object_info[oid].icon_name) + 1);
strcpy(newnode->icon_name, Object_info[oid].icon_name);
newnode->icon_name = mem_strdup(Object_info[oid].icon_name);

if (description) {
newnode->name = mem_strdup(description);
Expand Down
8 changes: 3 additions & 5 deletions Descent3/LoadLevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1684,8 +1684,7 @@ int ReadObject(CFILE *ifile, object *objp, int handle, int fileversion) {

// Set the name
if (tempname[0]) {
objp->name = mem_rmalloc<char>(strlen(tempname) + 1);
strcpy(objp->name, tempname);
objp->name = mem_strdup(tempname);
}

// Update checksum
Expand Down Expand Up @@ -2444,8 +2443,7 @@ int ReadRoom(CFILE *ifile, room *rp, int version) {
char tempname[ROOM_NAME_LEN + 1];
cf_ReadString(tempname, sizeof(tempname), ifile);
if (strlen(tempname)) {
rp->name = mem_rmalloc<char>(strlen(tempname) + 1);
strcpy(rp->name, tempname);
rp->name = mem_strdup(tempname);
}
}

Expand Down Expand Up @@ -3620,7 +3618,7 @@ bool LoadLevelInfo(const std::filesystem::path &filename, level_info &info) {
bool found = false;

if (!ifile) {
LOG_ERROR.printf("Failed to open mission file %s", filename.u8string().c_str());
LOG_ERROR.printf("Failed to open mission file %s", PATH_TO_CSTR(filename));
return false;
}

Expand Down
18 changes: 9 additions & 9 deletions Descent3/Mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,12 +701,12 @@ bool mn3_GetInfo(const std::filesystem::path &mn3file, tMissionInfo *msn);

static inline bool IS_MN3_FILE(const std::filesystem::path &fname) {
std::filesystem::path ext = fname.extension();
return (stricmp((const char*)ext.u8string().c_str(), ".mn3") == 0);
return stricmp(PATH_TO_CSTR(ext), ".mn3") == 0;
}

static inline std::filesystem::path MN3_TO_MSN_NAME(const std::filesystem::path &mn3name) {
std::filesystem::path fname = std::filesystem::path(mn3name).stem();
if (stricmp((const char*)fname.u8string().c_str(), "d3_2") == 0) {
if (stricmp(PATH_TO_CSTR(fname), "d3_2") == 0) {
fname = "d3";
}
fname.replace_extension(".msn");
Expand Down Expand Up @@ -1166,9 +1166,9 @@ bool LoadMission(const char *mssn) {
// set up current mission (movies are already set above)
msn->cur_level = 1;
msn->num_levels = numlevels;
msn->filename = mem_strdup((const char*)mission.u8string().c_str());
msn->filename = mem_strdup(PATH_TO_CSTR(mission));
msn->game_state_flags = 0;
strcpy(Net_msn_URLs.msnname, (const char*)mission.u8string().c_str());
strcpy(Net_msn_URLs.msnname, PATH_TO_CSTR(mission));
res = true; // everything is ok.

// if error, print it out, else end.
Expand Down Expand Up @@ -1238,7 +1238,7 @@ void LoadLevelText(const std::filesystem::path &level_filename) {
pathname.replace_extension(".str");

char **goal_strings;
if (CreateStringTable((const char*)pathname.u8string().c_str(), &goal_strings, &n_strings)) {
if (CreateStringTable(PATH_TO_CSTR(pathname), &goal_strings, &n_strings)) {
int n_goals = Level_goals.GetNumGoals();
ASSERT(n_strings == (n_goals * 3));
for (int i = 0; i < n_goals; i++) {
Expand Down Expand Up @@ -1692,7 +1692,7 @@ bool GetMissionInfo(const std::filesystem::path &msnfile, tMissionInfo *msn) {
}
CFILE *fp = cfopen(msnfile, "rt");
if (!fp) {
LOG_WARNING.printf("Failed to open mission file %s in GetMissionInfo.", msnfile.u8string().c_str());
LOG_WARNING.printf("Failed to open mission file %s in GetMissionInfo.", PATH_TO_CSTR(msnfile));
return false;
}
msn->multi = true;
Expand Down Expand Up @@ -1791,17 +1791,17 @@ bool mn3_Open(const std::filesystem::path &mn3file) {
std::filesystem::path filename = mn3file.stem();

std::filesystem::path voice_hog;
if ((stricmp((const char*)filename.u8string().c_str(), "d3") == 0) || (stricmp((const char*)filename.u8string().c_str(), "training") == 0)) {
if (stricmp(PATH_TO_CSTR(filename), "d3") == 0 || stricmp(PATH_TO_CSTR(filename), "training") == 0) {
// Open audio hog file
voice_hog = std::filesystem::path("missions") / "d3voice1.hog"; // Audio for levels 1-4
Mission_voice_hog_handle = cf_OpenLibrary(voice_hog);
} else if (stricmp((const char*)filename.u8string().c_str(), "d3_2") == 0) {
} else if (stricmp(PATH_TO_CSTR(filename), "d3_2") == 0) {
// Open audio hog file
voice_hog = std::filesystem::path("missions") / "d3voice2.hog"; // Audio for levels 5-17
Mission_voice_hog_handle = cf_OpenLibrary(voice_hog);
}
filename.replace_extension(".gam");
mng_SetAddonTable((const char*)filename.u8string().c_str());
mng_SetAddonTable(PATH_TO_CSTR(filename));
Current_mission.mn3_handle = mn3_handle;
return true;
}
Expand Down
54 changes: 27 additions & 27 deletions Descent3/OsirisLoadandBind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ int Osiris_FindLoadedModule(const std::filesystem::path &module_name) {
for (int i = 0; i < MAX_LOADED_MODULES; i++) {
if (OSIRIS_loaded_modules[i].flags & OSIMF_INUSE) {
if (OSIRIS_loaded_modules[i].module_name &&
(stricmp(OSIRIS_loaded_modules[i].module_name, (const char*)real_name.u8string().c_str()) == 0)) {
stricmp(OSIRIS_loaded_modules[i].module_name, PATH_TO_CSTR(real_name)) == 0) {
// we found a match
return i;
}
Expand Down Expand Up @@ -890,7 +890,7 @@ int get_full_path_to_module(const std::filesystem::path &module_name, std::files
adjusted_fname = module_name.filename();

// make sure filename/ext is all lowercase, requirement for Linux, doesn't hurt Windows
std::string p = (const char*)adjusted_fname.u8string().c_str();
std::string p = PATH_TO_CSTR(adjusted_fname);
std::transform(p.begin(), p.end(), p.begin(), [](unsigned char c) { return std::tolower(c); });
adjusted_fname = p;

Expand Down Expand Up @@ -958,7 +958,7 @@ int Osiris_LoadLevelModule(const std::filesystem::path &module_name) {
// the module is already loaded
OSIRIS_loaded_modules[loaded_id].reference_count++;
LOG_DEBUG_IF(Show_osiris_debug)
.printf("OSIRIS: Level Module (%s) reference count increased to %d", module_name.u8string().c_str(),
.printf("OSIRIS: Level Module (%s) reference count increased to %d", PATH_TO_CSTR(module_name),
OSIRIS_loaded_modules[loaded_id].reference_count);
return loaded_id;
}
Expand All @@ -973,7 +973,7 @@ int Osiris_LoadLevelModule(const std::filesystem::path &module_name) {

if (loaded_id >= MAX_LOADED_MODULES) {
// no slots available
LOG_FATAL.printf("OSIRIS: Osiris_LoadLevelModule(%s): No available slots\n", module_name.u8string().c_str());
LOG_FATAL.printf("OSIRIS: Osiris_LoadLevelModule(%s): No available slots\n", PATH_TO_CSTR(module_name));
Int3();
return -4;
}
Expand All @@ -985,16 +985,16 @@ int Osiris_LoadLevelModule(const std::filesystem::path &module_name) {
switch (ret_val) {
case -2:
// the module does not exist
LOG_ERROR.printf("OSIRIS: Osiris_LoadLevelModule(%s): Module doesn't exist", module_name.u8string().c_str());
LOG_ERROR.printf("OSIRIS: Osiris_LoadLevelModule(%s): Module doesn't exist", PATH_TO_CSTR(module_name));
return -1;
break;
case -1:
// the module is in data\scripts
break;
default:
// the module was an extracted file
LOG_DEBUG.printf("OSIRIS: Found module (%s) in a temp file (%s)", basename.u8string().c_str(),
fullpath.u8string().c_str());
LOG_DEBUG.printf("OSIRIS: Found module (%s) in a temp file (%s)", PATH_TO_CSTR(basename),
PATH_TO_CSTR(fullpath));
OSIRIS_loaded_modules[loaded_id].flags |= OSIMF_INTEMPDIR;
OSIRIS_loaded_modules[loaded_id].extracted_id = ret_val;
break;
Expand All @@ -1003,7 +1003,7 @@ int Osiris_LoadLevelModule(const std::filesystem::path &module_name) {
// the module exists, now attempt to load it
if (!mod_LoadModule(&OSIRIS_loaded_modules[loaded_id].mod, fullpath)) {
// there was an error trying to load the module
LOG_FATAL.printf("OSIRIS: Osiris_LoadLevelModule(%s): Unable to load module", module_name.u8string().c_str());
LOG_FATAL.printf("OSIRIS: Osiris_LoadLevelModule(%s): Unable to load module", PATH_TO_CSTR(module_name));
Int3();
return -3;
}
Expand Down Expand Up @@ -1034,7 +1034,7 @@ int Osiris_LoadLevelModule(const std::filesystem::path &module_name) {
osm->SaveRestoreState = (SaveRestoreState_fp)mod_GetSymbol(mod, "SaveRestoreState", 8);

osm->flags |= OSIMF_INUSE | OSIMF_LEVEL;
osm->module_name = mem_strdup((const char*)basename.u8string().c_str());
osm->module_name = mem_strdup(PATH_TO_CSTR(basename));
osm->reference_count = 1;

#ifdef OSIRISDEBUG
Expand All @@ -1047,7 +1047,7 @@ int Osiris_LoadLevelModule(const std::filesystem::path &module_name) {
!osm->GetCOScriptList || !osm->CreateInstance || !osm->DestroyInstance || !osm->SaveRestoreState ||
!osm->CallInstanceEvent) {
// there was an error importing a function
LOG_ERROR.printf("OSIRIS: Osiris_LoadLevelModule(%s) couldn't import function.", (const char*)module_name.u8string().c_str());
LOG_ERROR.printf("OSIRIS: Osiris_LoadLevelModule(%s) couldn't import function.", PATH_TO_CSTR(module_name));
Int3();
osm->flags = 0;
if (osm->module_name)
Expand All @@ -1059,15 +1059,15 @@ int Osiris_LoadLevelModule(const std::filesystem::path &module_name) {

// check to see if there is a corresponding string table to load
char stringtablename[_MAX_PATH];
strcpy(stringtablename, (const char*)basename.u8string().c_str());
strcpy(stringtablename, PATH_TO_CSTR(basename));
strcat(stringtablename, ".str");

if (cfexist(stringtablename)) {
// there is a string table, load it up
bool ret = CreateStringTable(stringtablename, &osm->string_table, &osm->strings_loaded);
if (!ret) {
LOG_ERROR.printf("OSIRIS: Unable to load string table (%s) for (%s)", stringtablename,
basename.u8string().c_str());
PATH_TO_CSTR(basename));
Int3();
osm->string_table = NULL;
osm->strings_loaded = 0;
Expand All @@ -1086,7 +1086,7 @@ int Osiris_LoadLevelModule(const std::filesystem::path &module_name) {
// when we get to this point we nearly have a loaded module, we just need to initialize it
if (!osm->InitializeDLL(&Osiris_module_init)) {
// there was an error initializing the module
LOG_ERROR.printf("OSIRIS: Osiris_LoadLevelModule(%s) error initializing module.", basename.u8string().c_str());
LOG_ERROR.printf("OSIRIS: Osiris_LoadLevelModule(%s) error initializing module.", PATH_TO_CSTR(basename));
if (osm->string_table) {
DestroyStringTable(osm->string_table, osm->strings_loaded);
}
Expand Down Expand Up @@ -1129,7 +1129,7 @@ int Osiris_LoadLevelModule(const std::filesystem::path &module_name) {
tOSIRISCurrentLevel.instance =
OSIRIS_loaded_modules[loaded_id].CreateInstance(0); // level scripts always have id of 0 in a level dll

LOG_INFO.printf("OSIRIS: Level Module (%s) loaded successfully (%d custom handles)", basename.u8string().c_str(),
LOG_INFO.printf("OSIRIS: Level Module (%s) loaded successfully (%d custom handles)", PATH_TO_CSTR(basename),
tOSIRISCurrentLevel.num_customs);
Osiris_level_script_loaded = true;
return loaded_id;
Expand All @@ -1153,7 +1153,7 @@ int Osiris_LoadGameModule(const std::filesystem::path &module_name) {
// the module is already loaded
OSIRIS_loaded_modules[loaded_id].reference_count++;
if (Show_osiris_debug) {
LOG_DEBUG.printf("OSIRIS: Game Module (%s) reference count increased to %d", module_name.u8string().c_str(),
LOG_DEBUG.printf("OSIRIS: Game Module (%s) reference count increased to %d", PATH_TO_CSTR(module_name),
OSIRIS_loaded_modules[loaded_id].reference_count);
}
return loaded_id;
Expand All @@ -1169,7 +1169,7 @@ int Osiris_LoadGameModule(const std::filesystem::path &module_name) {

if (loaded_id >= MAX_LOADED_MODULES) {
// no slots available
LOG_FATAL.printf("OSIRIS: Osiris_LoadGameModule(%s): No available slots", module_name.u8string().c_str());
LOG_FATAL.printf("OSIRIS: Osiris_LoadGameModule(%s): No available slots", PATH_TO_CSTR(module_name));
Int3();
return -4;
}
Expand All @@ -1181,15 +1181,15 @@ int Osiris_LoadGameModule(const std::filesystem::path &module_name) {
switch (ret_val) {
case -2:
// the module does not exist
LOG_WARNING.printf("OSIRIS: Osiris_LoadLevelModule(%s): Module doesn't exist", module_name.u8string().c_str());
LOG_WARNING.printf("OSIRIS: Osiris_LoadLevelModule(%s): Module doesn't exist", PATH_TO_CSTR(module_name));
return -1;
break;
case -1:
// the module is in data\scripts
break;
default:
// the module was an extracted file
LOG_INFO.printf("OSIRIS: Found module (%s) in a temp file", basename.u8string().c_str());
LOG_INFO.printf("OSIRIS: Found module (%s) in a temp file", PATH_TO_CSTR(basename));
OSIRIS_loaded_modules[loaded_id].flags |= OSIMF_INTEMPDIR;
OSIRIS_loaded_modules[loaded_id].extracted_id = ret_val;
break;
Expand All @@ -1198,7 +1198,7 @@ int Osiris_LoadGameModule(const std::filesystem::path &module_name) {
// the module exists, now attempt to load it
if (!mod_LoadModule(&OSIRIS_loaded_modules[loaded_id].mod, fullpath)) {
// there was an error trying to load the module
LOG_FATAL.printf("OSIRIS: Osiris_LoadGameModule(%s): Unable to load module", module_name.u8string().c_str());
LOG_FATAL.printf("OSIRIS: Osiris_LoadGameModule(%s): Unable to load module", PATH_TO_CSTR(module_name));
Int3();
return -3;
}
Expand Down Expand Up @@ -1227,7 +1227,7 @@ int Osiris_LoadGameModule(const std::filesystem::path &module_name) {
osm->SaveRestoreState = (SaveRestoreState_fp)mod_GetSymbol(mod, "SaveRestoreState", 8);

osm->flags |= OSIMF_INUSE;
osm->module_name = mem_strdup((const char*)basename.u8string().c_str());
osm->module_name = mem_strdup(PATH_TO_CSTR(basename));
osm->reference_count = 1;

#ifdef OSIRISDEBUG
Expand All @@ -1239,7 +1239,7 @@ int Osiris_LoadGameModule(const std::filesystem::path &module_name) {
if (!osm->InitializeDLL || !osm->ShutdownDLL || !osm->GetGOScriptID || !osm->CreateInstance ||
!osm->DestroyInstance || !osm->SaveRestoreState || !osm->CallInstanceEvent) {
// there was an error importing a function
LOG_WARNING.printf("OSIRIS: Osiris_LoadGameModule(%s) couldn't import function.", basename.u8string().c_str());
LOG_WARNING.printf("OSIRIS: Osiris_LoadGameModule(%s) couldn't import function.", PATH_TO_CSTR(basename));
Int3();
osm->flags = 0;
if (osm->module_name)
Expand All @@ -1251,15 +1251,15 @@ int Osiris_LoadGameModule(const std::filesystem::path &module_name) {

// check to see if there is a corresponding string table to load
char stringtablename[_MAX_PATH];
strcpy(stringtablename, (const char*)basename.u8string().c_str());
strcpy(stringtablename, PATH_TO_CSTR(basename));
strcat(stringtablename, ".str");

if (cfexist(stringtablename)) {
// there is a string table, load it up
bool ret = CreateStringTable(stringtablename, &osm->string_table, &osm->strings_loaded);
if (!ret) {
LOG_FATAL.printf("OSIRIS: Unable to load string table (%s) for (%s)", stringtablename,
(const char*)basename.u8string().c_str());
PATH_TO_CSTR(basename));
Int3();
osm->string_table = nullptr;
osm->strings_loaded = 0;
Expand All @@ -1277,7 +1277,7 @@ int Osiris_LoadGameModule(const std::filesystem::path &module_name) {
// when we get to this point we nearly have a loaded module, we just need to initialize it
if (!osm->InitializeDLL(&Osiris_module_init)) {
// there was an error initializing the module
LOG_ERROR.printf("OSIRIS: Osiris_LoadGameModule(%s) error initializing module.", (const char*)basename.u8string().c_str());
LOG_ERROR.printf("OSIRIS: Osiris_LoadGameModule(%s) error initializing module.", PATH_TO_CSTR(basename));
if (osm->string_table) {
DestroyStringTable(osm->string_table, osm->strings_loaded);
}
Expand All @@ -1298,7 +1298,7 @@ int Osiris_LoadGameModule(const std::filesystem::path &module_name) {
}

// we have a successful module load
LOG_INFO.printf("OSIRIS: Game Module (%s) loaded successfully", basename.u8string().c_str());
LOG_INFO.printf("OSIRIS: Game Module (%s) loaded successfully", PATH_TO_CSTR(basename));
return loaded_id;
}

Expand Down Expand Up @@ -3120,7 +3120,7 @@ int Osiris_ExtractScriptsFromHog(int library_handle, bool is_mission_hog) {
if (temp_filename.empty()) {
Int3();
} else {
std::string temp_realname = (const char*)std::filesystem::path(filename).stem().u8string().c_str();
std::string temp_realname = PATH_TO_CSTR(std::filesystem::path(filename).stem());
// Lowercase for optimized search
std::transform(temp_realname.begin(), temp_realname.end(), temp_realname.begin(),
[](unsigned char c) { return std::tolower(c); });
Expand All @@ -3135,7 +3135,7 @@ int Osiris_ExtractScriptsFromHog(int library_handle, bool is_mission_hog) {
t.temp_filename = temp_filename.filename();
OSIRIS_Extracted_scripts.insert_or_assign(temp_realname, t);

LOG_DEBUG.printf("Extracted %s as %s", temp_realname.c_str(), temp_filename.u8string().c_str());
LOG_DEBUG.printf("Extracted %s as %s", temp_realname.c_str(), PATH_TO_CSTR(temp_filename));
} else {
LOG_DEBUG.printf("Skipped %s (already extracted)", temp_realname.c_str());
}
Expand Down
3 changes: 1 addition & 2 deletions Descent3/TelComEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1253,10 +1253,9 @@ bool CreateMovie(tceffect *tce, const char *filename) {
tce->movieinfo.filename = NULL;
tce->w = tce->h = 100;

tce->movieinfo.filename = mem_rmalloc<char>(strlen(filename) + 1);
tce->movieinfo.filename = mem_strdup(filename);
if (!tce->movieinfo.filename)
return false;
strcpy(tce->movieinfo.filename, filename);
tce->movieinfo.handle = StartMovie(filename);
if (!tce->movieinfo.handle)
return false;
Expand Down
2 changes: 1 addition & 1 deletion Descent3/ambient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ void WriteAmbientData() {
CFILE *ofile;

#ifndef NEWEDITOR
ddio_MakePath(filename, (const char*)cf_GetWritableBaseDirectory().u8string().c_str(), "data", "misc", AMBIENT_FILE_NAME, NULL);
ddio_MakePath(filename, PATH_TO_CSTR(cf_GetWritableBaseDirectory()), "data", "misc", AMBIENT_FILE_NAME, NULL);
#else
ddio_MakePath(filename, D3HogDir, "data", "misc", AMBIENT_FILE_NAME, NULL);
#endif
Expand Down
Loading
Loading