/** * Loads the language-specific strings data for the current campaign. */ TbBool setup_campaign_strings_data(struct GameCampaign *campgn) { char *strings_data_end; char *fname; short result; long filelen; SYNCDBG(18,"Starting"); fname = prepare_file_path(FGrp_Main,campgn->strings_fname); filelen = LbFileLengthRnc(fname); if (filelen <= 0) { ERRORLOG("Campaign Strings file does not exist or can't be opened"); return false; } campgn->strings_data = (char *)LbMemoryAlloc(filelen + 256); if (campgn->strings_data == NULL) { ERRORLOG("Can't allocate memory for Campaign Strings data"); return false; } strings_data_end = campgn->strings_data+filelen+255; long loaded_size; loaded_size = LbFileLoadAt(fname, campgn->strings_data); if (loaded_size < 16) { ERRORLOG("Campaign Strings file couldn't be loaded or is too small"); return false; } // Resetting all values to empty strings reset_strings(campgn->strings); // Analyzing strings data and filling correct values result = create_strings_list(campgn->strings, campgn->strings_data, strings_data_end); SYNCDBG(19,"Finished"); return result; }
TbBool load_trapdoor_config_file(const char *textname, const char *fname, unsigned short flags) { char *buf; long len; TbBool result; SYNCDBG(0,"%s %s file \"%s\".",((flags & CnfLd_ListOnly) == 0)?"Reading":"Parsing",textname,fname); len = LbFileLengthRnc(fname); if (len < MIN_CONFIG_FILE_SIZE) { if ((flags & CnfLd_IgnoreErrors) == 0) WARNMSG("The %s file \"%s\" doesn't exist or is too small.",textname,fname); return false; } if (len > MAX_CONFIG_FILE_SIZE) { if ((flags & CnfLd_IgnoreErrors) == 0) WARNMSG("The %s file \"%s\" is too large.",textname,fname); return false; } buf = (char *)LbMemoryAlloc(len+256); if (buf == NULL) return false; // Loading file data len = LbFileLoadAt(fname, buf); result = (len > 0); // Parse blocks of the config file if (result) { result = parse_trapdoor_common_blocks(buf, len, textname, flags); if ((flags & CnfLd_AcceptPartial) != 0) result = true; if (!result) WARNMSG("Parsing %s file \"%s\" common blocks failed.",textname,fname); } if (result) { result = parse_trapdoor_trap_blocks(buf, len, textname, flags); if ((flags & CnfLd_AcceptPartial) != 0) result = true; if (!result) WARNMSG("Parsing %s file \"%s\" trap blocks failed.",textname,fname); } if (result) { result = parse_trapdoor_door_blocks(buf, len, textname, flags); if ((flags & CnfLd_AcceptPartial) != 0) result = true; if (!result) WARNMSG("Parsing %s file \"%s\" door blocks failed.",textname,fname); } //Freeing and exiting LbMemoryFree(buf); SYNCDBG(19,"Done"); return result; }
/** * Loads map file with given level number and file extension. * @return Returns NULL if the file doesn't exist or is smaller than ldsize; * on success, returns a buffer which should be freed after use, * and sets ldsize into its size. */ unsigned char *load_single_map_file_to_buffer(LevelNumber lvnum,const char *fext,long *ldsize,unsigned short flags) { unsigned char *buf; char *fname; long fsize; short fgroup; fgroup = get_level_fgroup(lvnum); fname = prepare_file_fmtpath(fgroup,"map%05lu.%s",lvnum,fext); wait_for_cd_to_be_available(); fsize = LbFileLengthRnc(fname); if (fsize < *ldsize) { if ((flags & LMFF_Optional) == 0) WARNMSG("Map file \"map%05lu.%s\" doesn't exist or is too small.",lvnum,fext); else SYNCMSG("Optional file \"map%05lu.%s\" doesn't exist or is too small.",lvnum,fext); return NULL; } if (fsize > ANY_MAP_FILE_MAX_SIZE) { if ((flags & LMFF_Optional) == 0) WARNMSG("Map file \"map%05lu.%s\" exceeds max size of %d; loading failed.",lvnum,fext,ANY_MAP_FILE_MAX_SIZE); else SYNCMSG("Optional file \"map%05lu.%s\" exceeds max size of %d; not loading.",lvnum,fext,ANY_MAP_FILE_MAX_SIZE); return NULL; } buf = LbMemoryAlloc(fsize+16); if (buf == NULL) { if ((flags & LMFF_Optional) == 0) WARNMSG("Can't allocate %ld bytes to load \"map%05lu.%s\".",fsize,lvnum,fext); else SYNCMSG("Can't allocate %ld bytes to load \"map%05lu.%s\".",fsize,lvnum,fext); return NULL; } fsize = LbFileLoadAt(fname,buf); if (fsize < *ldsize) { if ((flags & LMFF_Optional) == 0) WARNMSG("Reading map file \"map%05lu.%s\" failed.",lvnum,fext); else SYNCMSG("Reading optional file \"map%05lu.%s\" failed.",lvnum,fext); LbMemoryFree(buf); return NULL; } *ldsize = fsize; SYNCDBG(7,"Map file \"map%05lu.%s\" loaded.",lvnum,fext); return buf; }
TbBool load_settings(void) { SYNCDBG(6,"Starting"); char *fname; long len; fname = prepare_file_path(FGrp_Save,"settings.dat"); len = LbFileLengthRnc(fname); if (len == sizeof(struct GameSettings)) { if (LbFileLoadAt(fname, &settings) == sizeof(struct GameSettings)) return true; } setup_default_settings(); LbFileSaveAt(fname, &settings, sizeof(struct GameSettings)); return false; }
/** * Loads the language-specific strings data for game interface. */ TbBool setup_gui_strings_data(void) { char *strings_data_end; char *fname; short result; long filelen; long loaded_size; SYNCDBG(8,"Starting"); fname = prepare_file_fmtpath(FGrp_FxData,"gtext_%s.dat",get_language_lwrstr(install_info.lang_id)); filelen = LbFileLengthRnc(fname); if (filelen <= 0) { ERRORLOG("GUI Strings file does not exist or can't be opened"); SYNCLOG("Strings file name is \"%s\"",fname); return false; } gui_strings_data = (char *)LbMemoryAlloc(filelen + 256); if (gui_strings_data == NULL) { ERRORLOG("Can't allocate memory for GUI Strings data"); SYNCLOG("Strings file name is \"%s\"",fname); return false; } strings_data_end = gui_strings_data+filelen+255; loaded_size = LbFileLoadAt(fname, gui_strings_data); if (loaded_size < 16) { ERRORLOG("GUI Strings file couldn't be loaded or is too small"); return false; } // Resetting all values to empty strings reset_strings(gui_strings); // Analyzing strings data and filling correct values result = create_strings_list(gui_strings, gui_strings_data, strings_data_end); // Updating strings inside the DLL LbMemoryCopy(_DK_strings, gui_strings, DK_STRINGS_MAX*sizeof(char *)); SYNCDBG(19,"Finished"); return result; }
/** * Loads binary config of cubes. * @deprecated Replaced by text config - remove pending. */ long load_cube_file(void) { char *buf; long len; TbBool result; char *fname; static const char textname[] = "binary cubes config"; fname = prepare_file_path(FGrp_StdData,"cube.dat"); SYNCDBG(0,"%s %s file \"%s\".","Reading",textname,fname); //return _DK_load_cube_file(); clear_cubes(); len = LbFileLengthRnc(fname); if (len < MIN_CONFIG_FILE_SIZE) { WARNMSG("The %s file \"%s\" doesn't exist or is too small.",textname,fname); return false; } if (len > MAX_CONFIG_FILE_SIZE) { WARNMSG("The %s file \"%s\" is too large.",textname,fname); return false; } buf = (char *)LbMemoryAlloc(len+256); if (buf == NULL) return false; // Loading file data len = LbFileLoadAt(fname, buf); result = (len > 0); // Parse the config file if (result) { long i,count; count = *(long *)&buf[0]; if (count > len/sizeof(struct CubeAttribs)) { count = len/sizeof(struct CubeAttribs); WARNMSG("The %s file \"%s\" seem truncated.",textname,fname); } if (count > CUBE_ITEMS_MAX-1) count = CUBE_ITEMS_MAX-1; if (count < 0) count = 0; struct CubeAttribs * cubuf; cubuf = (struct CubeAttribs *)&buf[4]; for (i=0; i < count; i++) { struct CubeAttribs * cubed; cubed = &game.cubes_data[i]; int n; for (n=0; n < CUBE_TEXTURES; n++) { cubed->texture_id[n] = cubuf->texture_id[n]; } for (n=0; n < CUBE_TEXTURES; n++) { cubed->field_C[n] = cubuf->field_C[n]; } cubuf++; } result = true; } //Freeing and exiting LbMemoryFree(buf); return result; }