diff --git a/src/buttons.cpp b/src/buttons.cpp index ffc160052..eb3c534ec 100644 --- a/src/buttons.cpp +++ b/src/buttons.cpp @@ -313,7 +313,7 @@ void buttonOpen(button_t* my) button->focused = 1; // file list - if ( (dir = openDataDir("maps/")) != NULL ) + if ( (dir = opendir("maps/")) != NULL ) { while ( (ent = readdir(dir)) != NULL ) { @@ -340,7 +340,7 @@ void buttonOpen(button_t* my) d_names[c] = (char*) malloc(sizeof(char) * FILENAME_MAX); } c = 0; - if ( (dir = openDataDir("maps/")) != NULL ) + if ( (dir = opendir("maps/")) != NULL ) { while ( (ent = readdir(dir)) != NULL ) { @@ -484,7 +484,7 @@ void buttonSaveAs(button_t* my) button->focused = 1; // file list - if ( (dir = openDataDir("maps/")) != NULL ) + if ( (dir = opendir("maps/")) != NULL ) { while ( (ent = readdir(dir)) != NULL ) { @@ -511,7 +511,7 @@ void buttonSaveAs(button_t* my) d_names[c] = (char*) malloc(sizeof(char) * FILENAME_MAX); } c = 0; - if ( (dir = openDataDir("maps/")) != NULL ) + if ( (dir = opendir("maps/")) != NULL ) { while ( (ent = readdir(dir)) != NULL ) { @@ -965,4 +965,4 @@ void buttonCloseSubwindow(button_t* my) d_names = NULL; } strcpy(filename, oldfilename); -} +} \ No newline at end of file diff --git a/src/editor.cpp b/src/editor.cpp index 0834e9719..4103e98f8 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -703,7 +703,6 @@ void redo() void processCommandLine(int argc, char** argv) { int c = 0; - strcpy(datadir, "./"); if ( argc > 1 ) { for ( c = 1; c < argc; c++ ) @@ -715,14 +714,9 @@ void processCommandLine(int argc, char** argv) strcpy(maptoload, argv[c] + 5); loadingmap = true; } - else if (!strncmp(argv[c], "-datadir=", 9)) - { - strcpy(datadir, argv[c] + 9); - } } } } - printlog("Data path is %s", datadir); } /*------------------------------------------------------------------------------- diff --git a/src/files.cpp b/src/files.cpp index 5a94273f0..7cb583ddc 100644 --- a/src/files.cpp +++ b/src/files.cpp @@ -10,7 +10,6 @@ -------------------------------------------------------------------------------*/ #include -#include #include #include "main.hpp" #include "sound.hpp" @@ -43,50 +42,6 @@ void glLoadTexture(SDL_Surface* image, int texnum) SDL_UnlockSurface(image); } - -bool completePath(char *dest, const char * const filename) { - if (!(filename && filename[0])) { - return false; - } - - // Already absolute - if (filename[0] == '/') { - strncpy(dest, filename, 1024); - return true; - } - - snprintf(dest, 1024, "%s/%s", datadir, filename); - return true; -} - -FILE* openDataFile(const char * const filename, const char * const mode) { - char path[1024]; - completePath(path, filename); - FILE * result = fopen(path, mode); - if (!result) { - printlog("Could not open '%s': %s", path, strerror(errno)); - } - return result; -} - -DIR* openDataDir(const char * const name) { - char path[1024]; - completePath(path, name); - DIR * result = opendir(path); - if (!result) { - printlog("Could not open '%s': %s", path, strerror(errno)); - } - return result; -} - - -bool dataPathExists(const char * const path) { - char full_path[1024]; - completePath(full_path, path); - return access(full_path, F_OK) != -1; -} - - /*------------------------------------------------------------------------------- loadImage @@ -98,8 +53,6 @@ bool dataPathExists(const char * const path) { SDL_Surface* loadImage(char* filename) { - char full_path[1024]; - completePath(full_path, filename); SDL_Surface* originalSurface; if ( imgref >= MAXTEXTURES ) @@ -108,9 +61,9 @@ SDL_Surface* loadImage(char* filename) printlog("aborting...\n"); exit(1); } - if ( (originalSurface = IMG_Load(full_path)) == NULL ) + if ( (originalSurface = IMG_Load(filename)) == NULL ) { - printlog("error: failed to load image '%s'\n", full_path); + printlog("error: failed to load image '%s'\n", filename); exit(1); // critical error return NULL; } @@ -140,19 +93,28 @@ SDL_Surface* loadImage(char* filename) -------------------------------------------------------------------------------*/ -voxel_t* loadVoxel(char* filename) +voxel_t* loadVoxel(char* filename2) { - //char filename2[1024]; + char* filename; FILE* file; voxel_t* model; - if (filename != NULL) + if (filename2 != NULL) { - //bool has_ext = strstr(filename, ".vox") == NULL; - //snprintf(filename2, 1024, "%s%s", filename, has_ext ? "" : ".vox"); - - if ((file = openDataFile(filename, "rb")) == NULL) + if ( strstr(filename2, ".vox") == NULL ) + { + filename = (char*) malloc(sizeof(char) * 256); + strcpy(filename, filename2); + strcat(filename, ".vox"); + } + else { + filename = (char*) malloc(sizeof(char) * 256); + strcpy(filename, filename2); + } + if ((file = fopen(filename, "rb")) == NULL) + { + free(filename); return NULL; } model = (voxel_t*) malloc(sizeof(voxel_t)); @@ -174,6 +136,7 @@ voxel_t* loadVoxel(char* filename) model->palette[c][2] = model->palette[c][2] << 2; } fclose(file); + free(filename); return model; } @@ -200,163 +163,189 @@ int loadMap(char* filename2, map_t* destmap, list_t* entlist) Sint32 x, y; Entity* entity; Sint32 sprite; - char filename[256]; + char* filename; char oldmapname[64]; strcpy(oldmapname, map.name); - printlog("LoadMap %s", filename2); - - if (! (filename2 && filename2[0])) { - printlog("map filename empty or null"); - return -1; - } - - strcpy(filename, "maps/"); - strcat(filename, filename2); - - // add extension if missing - if ( strstr(filename, ".lmp") == NULL ) - { - strcat(filename, ".lmp"); - } - - // load the file! - if ((fp = openDataFile(filename, "rb")) == NULL) - { - printlog("warning: failed to open file '%s' for map loading!\n", filename); - if ( destmap == &map && game ) - { - printlog("error: main map failed to load, aborting.\n"); - mainloop = 0; - } - return -1; - } - - fread(valid_data, sizeof(char), strlen("BARONY"), fp); - if ( strncmp(valid_data, "BARONY", strlen("BARONY")) ) + if ( filename2 != NULL && strcmp(filename2, "") ) { - printlog("warning: file '%s' is an invalid map file.\n", filename); - fclose(fp); - if ( destmap == &map && game ) + c = 0; + while (1) { - printlog("error: main map failed to load, aborting.\n"); - mainloop = 0; + if (filename2[c] == 0) + { + break; + } + c++; } - return -1; - } - list_FreeAll(entlist); - if ( destmap == &map ) - { - // remove old lights - list_FreeAll(&light_l); - } - if ( destmap->tiles != NULL ) - { - free(destmap->tiles); - } - fread(destmap->name, sizeof(char), 32, fp); // map name - fread(destmap->author, sizeof(char), 32, fp); // map author - fread(&destmap->width, sizeof(Uint32), 1, fp); // map width - fread(&destmap->height, sizeof(Uint32), 1, fp); // map height - destmap->tiles = (Sint32*) malloc(sizeof(Sint32) * destmap->width * destmap->height * MAPLAYERS); - fread(destmap->tiles, sizeof(Sint32), destmap->width * destmap->height * MAPLAYERS, fp); - fread(&numentities, sizeof(Uint32), 1, fp); // number of entities on the map - for (c = 0; c < numentities; c++) - { - fread(&sprite, sizeof(Sint32), 1, fp); - entity = newEntity(sprite, 0, entlist); - fread(&x, sizeof(Sint32), 1, fp); - fread(&y, sizeof(Sint32), 1, fp); - entity->x = x; - entity->y = y; - } - fclose(fp); - - if ( destmap == &map ) - { - nummonsters = 0; - minotaurlevel = 0; + filename = (char*) malloc(sizeof(char) * 256); + strcpy(filename, "maps/"); + strcat(filename, filename2); -#if defined (HAVE_FMOD) || defined(HAVE_OPENAL) - if ( strcmp(oldmapname, map.name) ) + if ( strcmp(filename, "..") && strcmp(filename, ".") ) { - levelmusicplaying = false; - } -#endif + // add extension if missing + if ( strstr(filename, ".lmp") == NULL ) + { + strcat(filename, ".lmp"); + } - // create new lightmap - if (lightmap != NULL) - { - free(lightmap); - } - lightmap = (int*) malloc(sizeof(Sint32) * destmap->width * destmap->height); - if ( strncmp(map.name, "Hell", 4) ) - { - for (c = 0; c < destmap->width * destmap->height; c++ ) + // load the file! + if ((fp = fopen(filename, "rb")) == NULL) { - lightmap[c] = 0; + printlog("warning: failed to open file '%s' for map loading!\n", filename); + if ( destmap == &map && game ) + { + printlog("error: main map failed to load, aborting.\n"); + mainloop = 0; + } + free(filename); + return -1; } } else { - for (c = 0; c < destmap->width * destmap->height; c++ ) + printlog("warning: failed to open file '%s' for map loading!\n", filename); + if ( destmap == &map && game ) { - lightmap[c] = 32; + printlog("error: main map failed to load, aborting.\n"); + mainloop = 0; } + free(filename); + return -1; } - - // create a new vismap - if (vismap != NULL) + fread(valid_data, sizeof(char), strlen("BARONY"), fp); + if ( strncmp(valid_data, "BARONY", strlen("BARONY")) ) { - free(vismap); - } - vismap = (bool*) calloc(destmap->width * destmap->height, sizeof(bool)); - - // reset minimap - for ( x = 0; x < 64; x++ ) - for ( y = 0; y < 64; y++ ) + printlog("warning: file '%s' is an invalid map file.\n", filename); + fclose(fp); + if ( destmap == &map && game ) { - minimap[y][x] = 0; + printlog("error: main map failed to load, aborting.\n"); + mainloop = 0; } - - // reset camera - if ( game ) + free(filename); + return -1; + } + list_FreeAll(entlist); + if ( destmap == &map ) { - camera.x = -32; - camera.y = -32; - camera.z = 0; - camera.ang = 3 * PI / 2; - camera.vang = 0; + // remove old lights + list_FreeAll(&light_l); } - else + if ( destmap->tiles != NULL ) { - camera.x = 2; - camera.y = 2; - camera.z = 0; - camera.ang = 0; - camera.vang = 0; + free(destmap->tiles); } - - // shoparea - if ( shoparea ) + fread(destmap->name, sizeof(char), 32, fp); // map name + fread(destmap->author, sizeof(char), 32, fp); // map author + fread(&destmap->width, sizeof(Uint32), 1, fp); // map width + fread(&destmap->height, sizeof(Uint32), 1, fp); // map height + destmap->tiles = (Sint32*) malloc(sizeof(Sint32) * destmap->width * destmap->height * MAPLAYERS); + fread(destmap->tiles, sizeof(Sint32), destmap->width * destmap->height * MAPLAYERS, fp); + fread(&numentities, sizeof(Uint32), 1, fp); // number of entities on the map + for (c = 0; c < numentities; c++) { - free(shoparea); + fread(&sprite, sizeof(Sint32), 1, fp); + entity = newEntity(sprite, 0, entlist); + fread(&x, sizeof(Sint32), 1, fp); + fread(&y, sizeof(Sint32), 1, fp); + entity->x = x; + entity->y = y; } - shoparea = (bool*) malloc(sizeof(bool) * destmap->width * destmap->height); - for ( x = 0; x < destmap->width; x++ ) - for ( y = 0; y < destmap->height; y++ ) + free(filename); + fclose(fp); + + if ( destmap == &map ) + { + nummonsters = 0; + minotaurlevel = 0; + +#if defined (HAVE_FMOD) || defined(HAVE_OPENAL) + if ( strcmp(oldmapname, map.name) ) { - shoparea[y + x * destmap->height] = false; + levelmusicplaying = false; + } +#endif + + // create new lightmap + if (lightmap != NULL) + { + free(lightmap); + } + lightmap = (int*) malloc(sizeof(Sint32) * destmap->width * destmap->height); + if ( strncmp(map.name, "Hell", 4) ) + { + for (c = 0; c < destmap->width * destmap->height; c++ ) + { + lightmap[c] = 0; + } + } + else + { + for (c = 0; c < destmap->width * destmap->height; c++ ) + { + lightmap[c] = 32; + } } - } - for ( c = 0; c < 512; c++ ) + // create a new vismap + if (vismap != NULL) + { + free(vismap); + } + vismap = (bool*) calloc(destmap->width * destmap->height, sizeof(bool)); + + // reset minimap + for ( x = 0; x < 64; x++ ) + for ( y = 0; y < 64; y++ ) + { + minimap[y][x] = 0; + } + + // reset camera + if ( game ) + { + camera.x = -32; + camera.y = -32; + camera.z = 0; + camera.ang = 3 * PI / 2; + camera.vang = 0; + } + else + { + camera.x = 2; + camera.y = 2; + camera.z = 0; + camera.ang = 0; + camera.vang = 0; + } + + // shoparea + if ( shoparea ) + { + free(shoparea); + } + shoparea = (bool*) malloc(sizeof(bool) * destmap->width * destmap->height); + for ( x = 0; x < destmap->width; x++ ) + for ( y = 0; y < destmap->height; y++ ) + { + shoparea[y + x * destmap->height] = false; + } + } + + for ( c = 0; c < 512; c++ ) + { + keystatus[c] = 0; + } + + return numentities; + } + else { - keystatus[c] = 0; + return -1; } - - return numentities; } /*------------------------------------------------------------------------------- @@ -386,7 +375,7 @@ int saveMap(char* filename2) { strcat(filename, ".lmp"); } - if ((fp = openDataFile(filename, "wb")) == NULL) + if ((fp = fopen(filename, "wb")) == NULL) { printlog("warning: failed to open file '%s' for map saving!\n", filename); return 1; @@ -434,34 +423,18 @@ char* readFile(char* filename) { char* file_contents = NULL; long input_file_size; - FILE* input_file = openDataFile(filename, "rb"); - if (!input_file) { - printlog("Open failed: %s", strerror(errno)); - goto out_input_file; - } - - if (fseek(input_file, 0, SEEK_END) != 0) { - printlog("Seek failed"); - goto out_input_file; - } - - if ((input_file_size = ftell(input_file)) == -1) { - printlog("ftell failed"); - goto out_input_file; + FILE* input_file = fopen(filename, "rb"); + if ( input_file ) + { + fseek(input_file, 0, SEEK_END); + input_file_size = ftell(input_file); + rewind(input_file); + file_contents = static_cast(malloc((input_file_size + 1) * sizeof(char))); + fread(file_contents, sizeof(char), input_file_size, input_file); + file_contents[input_file_size] = 0; + fclose(input_file); } - if (input_file_size > (1<<30)) { - printlog("Unreasonable size: %ld", input_file_size); - goto out_input_file; - } - - rewind(input_file); - file_contents = static_cast(malloc((input_file_size + 1) * sizeof(char))); - fread(file_contents, sizeof(char), input_file_size, input_file); - file_contents[input_file_size] = 0; - -out_input_file: - fclose(input_file); return file_contents; } @@ -476,10 +449,9 @@ char* readFile(char* filename) list_t* directoryContents(char* directory) { list_t* list = NULL; // list of strings - char fullPath[1024]; - completePath(fullPath, directory); - DIR* dir = opendir(fullPath); + DIR* dir = NULL; struct dirent* entry = NULL; + dir = opendir(directory); if ( !dir ) { @@ -491,20 +463,19 @@ list_t* directoryContents(char* directory) list->first = NULL; list->last = NULL; - struct stat cur; - char curPath[1024]; while ((entry = readdir(dir)) != NULL) { - strcpy(curPath, fullPath); - strcat(curPath, entry->d_name); + strcpy(tempstr, directory); + strcat(tempstr, entry->d_name); - if (stat(curPath, &cur) != 0) + DIR* newdir = NULL; + if ( (newdir = opendir(tempstr)) == NULL ) { - continue; + newString(list, 0xFFFFFFFF, entry->d_name); } - if (cur.st_mode & S_IFMT == S_IFREG) + else { - newString(list, 0xFFFFFFFF, entry->d_name); + closedir(newdir); } } diff --git a/src/game.cpp b/src/game.cpp index e5dc43e2f..bd0fbea28 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -672,11 +672,11 @@ void gameLogic(void) numplayers = 0; if ( !secretlevel ) { - fp = openDataFile(LEVELSFILE, "r"); + fp = fopen(LEVELSFILE, "r"); } else { - fp = openDataFile(SECRETLEVELSFILE, "r"); + fp = fopen(SECRETLEVELSFILE, "r"); } for ( i = 0; i < currentlevel; i++ ) while ( fgetc(fp) != '\n' ) if ( feof(fp) ) @@ -2184,7 +2184,14 @@ int main(int argc, char** argv) //SDL_Surface *sky_bmp; light_t* light; - strcpy(datadir, "./"); + // load default language file (english) + if ( loadLanguage("en") ) + { + printlog("Fatal error: failed to load default language file!\n"); + fclose(logfile); + exit(1); + } + // read command line arguments if ( argc > 1 ) { @@ -2222,23 +2229,9 @@ int main(int argc, char** argv) { strcpy(classtoquickstart, argv[c] + 12); } - else if (!strncmp(argv[c], "-datadir=", 9)) - { - strcpy(datadir, argv[c] + 9); - } } } } - printlog("Data path is %s", datadir); - - - // load default language file (english) - if ( loadLanguage("en") ) - { - printlog("Fatal error: failed to load default language file!\n"); - fclose(logfile); - exit(1); - } // load config file if ( loadingconfig ) @@ -2563,11 +2556,11 @@ int main(int argc, char** argv) { if ( !secretlevel ) { - fp = openDataFile(LEVELSFILE, "r"); + fp = fopen(LEVELSFILE, "r"); } else { - fp = openDataFile(SECRETLEVELSFILE, "r"); + fp = fopen(SECRETLEVELSFILE, "r"); } fscanf(fp, "%s", tempstr); while ( fgetc(fp) != ' ' ) if ( feof(fp) ) diff --git a/src/init.cpp b/src/init.cpp index 816c65953..44a8b3932 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -309,7 +309,7 @@ int initApp(char* title, int fullscreen) // load sprites printlog("loading sprites...\n"); - fp = openDataFile("images/sprites.txt", "r"); + fp = fopen("images/sprites.txt", "r"); for ( numsprites = 0; !feof(fp); numsprites++ ) { while ( fgetc(fp) != '\n' ) if ( feof(fp) ) @@ -324,7 +324,7 @@ int initApp(char* title, int fullscreen) return 6; } sprites = (SDL_Surface**) malloc(sizeof(SDL_Surface*)*numsprites); - fp = openDataFile("images/sprites.txt", "r"); + fp = fopen("images/sprites.txt", "r"); for ( c = 0; !feof(fp); c++ ) { fscanf(fp, "%s", name); @@ -353,7 +353,7 @@ int initApp(char* title, int fullscreen) // load models printlog("loading models...\n"); - fp = openDataFile("models/models.txt", "r"); + fp = fopen("models/models.txt", "r"); for ( nummodels = 0; !feof(fp); nummodels++ ) { while ( fgetc(fp) != '\n' ) if ( feof(fp) ) @@ -368,7 +368,7 @@ int initApp(char* title, int fullscreen) return 11; } models = (voxel_t**) malloc(sizeof(voxel_t*)*nummodels); - fp = openDataFile("models/models.txt", "r"); + fp = fopen("models/models.txt", "r"); for ( c = 0; !feof(fp); c++ ) { fscanf(fp, "%s", name); @@ -401,7 +401,7 @@ int initApp(char* title, int fullscreen) // load tiles printlog("loading tiles...\n"); - fp = openDataFile("images/tiles.txt", "r"); + fp = fopen("images/tiles.txt", "r"); for ( numtiles = 0; !feof(fp); numtiles++ ) { while ( fgetc(fp) != '\n' ) if ( feof(fp) ) @@ -418,7 +418,7 @@ int initApp(char* title, int fullscreen) tiles = (SDL_Surface**) malloc(sizeof(SDL_Surface*)*numtiles); animatedtiles = (bool*) malloc(sizeof(bool) * numtiles); lavatiles = (bool*) malloc(sizeof(bool) * numtiles); - fp = openDataFile("images/tiles.txt", "r"); + fp = fopen("images/tiles.txt", "r"); for ( c = 0; !feof(fp); c++ ) { fscanf(fp, "%s", name); @@ -465,7 +465,7 @@ int initApp(char* title, int fullscreen) // load sound effects #ifdef HAVE_FMOD printlog("loading sounds...\n"); - fp = openDataFile("sound/sounds.txt", "r"); + fp = fopen("sound/sounds.txt", "r"); for ( numsounds = 0; !feof(fp); numsounds++ ) { while ( fgetc(fp) != '\n' ) if ( feof(fp) ) @@ -480,7 +480,7 @@ int initApp(char* title, int fullscreen) return 10; } sounds = (FMOD_SOUND**) malloc(sizeof(FMOD_SOUND*)*numsounds); - fp = openDataFile("sound/sounds.txt", "r"); + fp = fopen("sound/sounds.txt", "r"); for ( c = 0; !feof(fp); c++ ) { fscanf(fp, "%s", name); @@ -501,7 +501,7 @@ int initApp(char* title, int fullscreen) FMOD_System_Set3DSettings(fmod_system, 1.0, 2.0, 1.0); #elif defined HAVE_OPENAL printlog("loading sounds...\n"); - fp = openDataFile("sound/sounds.txt", "r"); + fp = fopen("sound/sounds.txt", "r"); for ( numsounds = 0; !feof(fp); numsounds++ ) { while ( fgetc(fp) != '\n' ) if ( feof(fp) ) @@ -516,7 +516,7 @@ int initApp(char* title, int fullscreen) return 10; } sounds = (OPENAL_BUFFER**) malloc(sizeof(OPENAL_BUFFER*)*numsounds); - fp = openDataFile("sound/sounds.txt", "r"); + fp = fopen("sound/sounds.txt", "r"); for ( c = 0; !feof(fp); c++ ) { fscanf(fp, "%s", name); @@ -560,7 +560,7 @@ int loadLanguage(char* lang) snprintf(filename, 127, "lang/%s.txt", lang); // check if language file is valid - if ( !dataPathExists(filename) ) + if ( access( filename, F_OK ) == -1 ) { // language file doesn't exist printlog("error: unable to locate language file: '%s'", filename); @@ -586,23 +586,21 @@ int loadLanguage(char* lang) // load fonts char fontName[64] = { 0 }; - char fontPath[1024]; snprintf(fontName, 63, "lang/%s.ttf", lang); - if ( !dataPathExists(fontName) ) + if ( access(fontName, F_OK) == -1 ) { strncpy(fontName, "lang/en.ttf", 63); } - if ( !dataPathExists(fontName) ) + if ( access(fontName, F_OK) == -1 ) { printlog("error: default game font 'lang/en.ttf' not found"); return 1; } - completePath(fontPath, fontName); if ( ttf8 ) { TTF_CloseFont(ttf8); } - if ((ttf8 = TTF_OpenFont(fontPath, TTF8_HEIGHT)) == NULL ) + if ((ttf8 = TTF_OpenFont(fontName, TTF8_HEIGHT)) == NULL ) { printlog("failed to load size 8 ttf: %s\n", TTF_GetError()); return 1; @@ -613,7 +611,7 @@ int loadLanguage(char* lang) { TTF_CloseFont(ttf12); } - if ((ttf12 = TTF_OpenFont(fontPath, TTF12_HEIGHT)) == NULL ) + if ((ttf12 = TTF_OpenFont(fontName, TTF12_HEIGHT)) == NULL ) { printlog("failed to load size 12 ttf: %s\n", TTF_GetError()); return 1; @@ -624,7 +622,7 @@ int loadLanguage(char* lang) { TTF_CloseFont(ttf16); } - if ((ttf16 = TTF_OpenFont(fontPath, TTF16_HEIGHT)) == NULL ) + if ((ttf16 = TTF_OpenFont(fontName, TTF16_HEIGHT)) == NULL ) { printlog("failed to load size 16 ttf: %s\n", TTF_GetError()); return 1; @@ -633,7 +631,7 @@ int loadLanguage(char* lang) TTF_SetFontHinting(ttf16, TTF_HINTING_MONO); // open language file - if ( (fp = openDataFile(filename, "r")) == NULL ) + if ( (fp = fopen(filename, "r")) == NULL ) { printlog("error: unable to load language file: '%s'", filename); return 1; diff --git a/src/init_game.cpp b/src/init_game.cpp index fe6e59d8c..438041a0d 100644 --- a/src/init_game.cpp +++ b/src/init_game.cpp @@ -101,7 +101,7 @@ int initGame() strcpy(filename, "models/creatures/"); strcat(filename, monstertypename[c]); strcat(filename, "/limbs.txt"); - if ( (fp = openDataFile(filename, "r")) == NULL ) + if ( (fp = fopen(filename, "r")) == NULL ) { continue; } @@ -149,7 +149,7 @@ int initGame() // load item types printlog( "loading items...\n"); - fp = openDataFile("items/items.txt", "r"); + fp = fopen("items/items.txt", "r"); for ( c = 0; !feof(fp); c++ ) { items[c].name_identified = language[1545 + c * 2]; @@ -291,8 +291,8 @@ int initGame() createBooks(); setupSpells(); - randomPlayerNamesMale = getLinesFromFile(datadir + PLAYERNAMES_MALE_FILE); - randomPlayerNamesFemale = getLinesFromFile(datadir + PLAYERNAMES_FEMALE_FILE); + randomPlayerNamesMale = getLinesFromFile(PLAYERNAMES_MALE_FILE); + randomPlayerNamesFemale = getLinesFromFile(PLAYERNAMES_FEMALE_FILE); // print a loading message drawClearBuffers(); diff --git a/src/main.cpp b/src/main.cpp index b7e8d9315..bc864719f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,7 +21,6 @@ int mainloop = 1; bool initialized = false; Uint32 ticks = 0; bool stop = false; -char datadir[1024]; // language stuff char languageCode[32] = { 0 }; diff --git a/src/main.hpp b/src/main.hpp index cb0d7aa45..67847c050 100644 --- a/src/main.hpp +++ b/src/main.hpp @@ -30,7 +30,6 @@ using std::string; //Instead of including an entire namespace, please explicitly #define STEAM_APPID 371970 #endif -#include #include #include #include @@ -651,8 +650,3 @@ extern GLuint fbo_ren; #endif void GO_SwapBuffers(SDL_Window* screen); unsigned int GO_GetPixelU32(int x, int y); -extern char datadir[1024]; -FILE *openDataFile(const char *const filename, const char * const mode); -DIR * openDataDir(const char *const); -bool dataPathExists(const char *const); -bool completePath(char *dest, const char * const path); diff --git a/src/maps.cpp b/src/maps.cpp index b55aabd01..327c35783 100644 --- a/src/maps.cpp +++ b/src/maps.cpp @@ -284,7 +284,7 @@ int generateDungeon(char* levelset, Uint32 seed) snprintf(sublevelnum, 3, "%02d", numlevels); strcat(sublevelname, sublevelnum); snprintf(fullname, strlen(levelset) + 13, "maps/%s.lmp", sublevelname); - if ( !dataPathExists(fullname) ) + if ( access( fullname, F_OK ) == -1 ) { break; // no more levels to load } @@ -330,7 +330,7 @@ int generateDungeon(char* levelset, Uint32 seed) // check if there is another sublevel to load snprintf(fullname, strlen(levelset) + 13, "maps/%s.lmp", sublevelname); - if ( !dataPathExists(fullname) ) + if ( access( fullname, F_OK ) == -1 ) { break; // no more levels to load } diff --git a/src/menu.cpp b/src/menu.cpp index b88172ac7..6c37e5350 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -3791,11 +3791,11 @@ void handleMainMenu(bool mode) { if ( !secretlevel ) { - fp = openDataFile(LEVELSFILE, "r"); + fp = fopen(LEVELSFILE, "r"); } else { - fp = openDataFile(SECRETLEVELSFILE, "r"); + fp = fopen(SECRETLEVELSFILE, "r"); } int i; for ( i = 0; i < currentlevel; i++ ) @@ -3952,11 +3952,11 @@ void handleMainMenu(bool mode) { if ( !secretlevel ) { - fp = openDataFile(LEVELSFILE, "r"); + fp = fopen(LEVELSFILE, "r"); } else { - fp = openDataFile(SECRETLEVELSFILE, "r"); + fp = fopen(SECRETLEVELSFILE, "r"); } int i; for ( i = 0; i < currentlevel; i++ ) diff --git a/src/net.cpp b/src/net.cpp index 1c3c6df63..0d6179466 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1767,11 +1767,11 @@ void clientHandlePacket() printlog("Received map seed: %d. Entity UID start: %d\n", mapseed, entity_uids); if ( !secretlevel ) { - fp = openDataFile(LEVELSFILE, "r"); + fp = fopen(LEVELSFILE, "r"); } else { - fp = openDataFile(SECRETLEVELSFILE, "r"); + fp = fopen(SECRETLEVELSFILE, "r"); } for ( i = 0; i < currentlevel; i++ ) while ( fgetc(fp) != '\n' ) if ( feof(fp) ) diff --git a/src/sound.cpp b/src/sound.cpp index 320c4aa27..d79bb5472 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -264,7 +264,7 @@ static long int openal_oggtell(void* datasource) { } static int openal_oggopen(OPENAL_SOUND *self, const char* oggfile) { - FILE *f = openDataFile(oggfile, "rb"); + FILE *f = fopen(oggfile, "rb"); int err; ov_callbacks oggcb = {openal_oggread, openal_oggseek, openal_oggclose, openal_oggtell}; @@ -700,7 +700,7 @@ int OPENAL_CreateSound(const char* name, bool b3D, OPENAL_BUFFER **buffer) { *buffer = (OPENAL_BUFFER*)malloc(sizeof(OPENAL_BUFFER)); strcpy((*buffer)->oggfile, name); // for debugging purpose (*buffer)->stream = false; - FILE *f = openDataFile(name, "rb"); + FILE *f = fopen(name, "rb"); if(!f) { printlog("Error loading sound %s\n", name); return 0;