/** * 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; }
void generate_map_fade_ghost_table(const char *fname, unsigned char *palette, unsigned char *ghost_table) { if (LbFileLoadAt(fname, ghost_table) != PALETTE_COLORS*PALETTE_COLORS) { unsigned char *out; out = ghost_table; int i; for (i=0; i < PALETTE_COLORS; i++) { unsigned char *bpal; bpal = &palette[3*i]; int n; for (n=0; n < PALETTE_COLORS; n++) { unsigned char *spal; spal = &palette[3*n]; unsigned char r,g,b; r = bpal[0] + spal[0]; g = bpal[1] + spal[1]; b = bpal[2] + spal[2]; *out = LbPaletteFindColour(palette, r, g, b); out++; } } LbFileSaveAt(fname, ghost_table, PALETTE_COLORS*PALETTE_COLORS); } }
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; }
TbBool load_slab_tng_file(void) { char *fname; SYNCDBG(5,"Starting"); fname = prepare_file_fmtpath(FGrp_StdData,"slabs.tng"); wait_for_cd_to_be_available(); if ( LbFileExists(fname) ) LbFileLoadAt(fname, &game.slabobjs_num); else ERRORLOG("Could not load slab object set"); return true; }
TbBool init_whitepal_table(void) { char *fname; static const char textname[] = "white-blended color table"; fname = prepare_file_path(FGrp_StdData,"whitepal.col"); SYNCDBG(0,"Reading %s file \"%s\".",textname,fname); // Loading file data if (LbFileLoadAt(fname, &white_pal) != 256) { compute_shifted_palette_table(white_pal, engine_palette, engine_palette, 48, 48, 48); LbFileSaveAt(fname, &white_pal, 256); } return true; }
TbBool init_rgb2idx_table(void) { char *fname; static const char textname[] = "rgb-to-index color table"; fname = prepare_file_path(FGrp_StdData,"colours.col"); SYNCDBG(0,"Reading %s file \"%s\".",textname,fname); // Loading file data if (LbFileLoadAt(fname, &colours) != sizeof(TbRGBColorTable)) { compute_rgb2idx_table(colours,engine_palette); LbFileSaveAt(fname, &colours, sizeof(TbRGBColorTable)); } return true; }
TbBool init_alpha_table(void) { char *fname; static const char textname[] = "alpha color table"; fname = prepare_file_path(FGrp_StdData,"alpha.col"); SYNCDBG(0,"Reading %s file \"%s\".",textname,fname); // Loading file data if (LbFileLoadAt(fname, &alpha_sprite_table) != sizeof(struct TbAlphaTables)) { compute_alpha_tables(&alpha_sprite_table,engine_palette,engine_palette); LbFileSaveAt(fname, &alpha_sprite_table, sizeof(struct TbAlphaTables)); } return true; }
long load_texture_anim_file(void) { SYNCDBG(8,"Starting"); //return _DK_load_anim_file(); char *fname; static const char textname[] = "animated tmap"; fname = prepare_file_path(FGrp_StdData,"tmapanim.dat"); SYNCDBG(0,"Reading %s file \"%s\".",textname,fname); if (LbFileLoadAt(fname, game.texture_animation) != sizeof(game.texture_animation)) { return false; } return true; }
/** * 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; }
/** * Searches levels folder for LOF files and adds them to campaign levels list. */ TbBool find_and_load_lof_files(void) { struct TbFileFind fileinfo; unsigned char *buf; char *fname; short result; int rc; long i; SYNCDBG(16,"Starting"); buf = LbMemoryAlloc(MAX_LIF_SIZE); if (buf == NULL) { ERRORLOG("Can't allocate memory for .LOF files parsing."); return false; } result = false; fname = prepare_file_path(FGrp_VarLevels,"*.lof"); rc = LbFileFindFirst(fname, &fileinfo, 0x21u); while (rc != -1) { fname = prepare_file_path(FGrp_VarLevels,fileinfo.Filename); i = LbFileLength(fname); if ((i < 0) || (i >= MAX_LIF_SIZE)) { WARNMSG("File '%s' too long (Max size %d)", fileinfo.Filename, MAX_LIF_SIZE); } else if (LbFileLoadAt(fname, buf) != i) { WARNMSG("Unable to read .LOF file, '%s'", fileinfo.Filename); } else { buf[i] = '\0'; if (level_lof_file_parse(fileinfo.Filename, (char *)buf, i)) result = true; } rc = LbFileFindNext(&fileinfo); } LbFileFindEnd(&fileinfo); LbMemoryFree(buf); return result; }
/** * 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; }
TbBool init_fades_table(void) { char *fname; long i; static const char textname[] = "fade table"; fname = prepare_file_path(FGrp_StdData,"tables.dat"); SYNCDBG(0,"Reading %s file \"%s\".",textname,fname); if (LbFileLoadAt(fname, &pixmap) != sizeof(struct TbColorTables)) { compute_fade_tables(&pixmap,engine_palette,engine_palette); LbFileSaveAt(fname, &pixmap, sizeof(struct TbColorTables)); } lbDisplay.FadeTable = pixmap.fade_tables; TbPixel cblack = 144; // Update black color for (i=0; i < 8192; i++) { if (pixmap.fade_tables[i] == 0) { pixmap.fade_tables[i] = cblack; } } return true; }
TbBool load_texture_map_file(unsigned long tmapidx, unsigned char n) { char *fname; SYNCDBG(7,"Starting"); #ifdef SPRITE_FORMAT_V2 fname = prepare_file_fmtpath(FGrp_StdData,"tmapa%03d-%d.dat",tmapidx,32); #else fname = prepare_file_fmtpath(FGrp_StdData,"tmapa%03d.dat",tmapidx); #endif if (!wait_for_cd_to_be_available()) return false; if (!LbFileExists(fname)) { WARNMSG("Texture file \"%s\" doesn't exits.",fname); return false; } // The texture file has always over 500kb if (LbFileLoadAt(fname, block_mem) < 65536) { WARNMSG("Texture file \"%s\" can't be loaded or is too small.",fname); return false; } return true; }
/** * 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; }
TbBool parse_lenses_data_blocks(char *buf, long len, const char *config_textname, unsigned short flags) { long pos; int i,k,n; int cmd_num; char *fname; struct LensConfig *lenscfg; // Block name and parameter word store variables char block_buf[COMMAND_WORD_LEN]; char word_buf[COMMAND_WORD_LEN]; // Initialize the array int arr_size; if ((flags & CnfLd_AcceptPartial) == 0) { arr_size = sizeof(lenses_conf.lenses)/sizeof(lenses_conf.lenses[0]); for (i=0; i < arr_size; i++) { lenscfg = &lenses_conf.lenses[i]; LbMemorySet(lenscfg->code_name, 0, COMMAND_WORD_LEN); LbMemorySet(lenscfg->mist_file, 0, DISKPATH_SIZE); lenscfg->mist_lightness = 0; lenscfg->mist_ghost = 0; lenscfg->displace_kind = 0; lenscfg->displace_magnitude = 0; lenscfg->displace_period = 1; LbMemorySet(lenscfg->palette, 0, PALETTE_SIZE*sizeof(TbPixel)); lenscfg->flags = 0; if (i < lenses_conf.lenses_count) { lenses_desc[i].name = lenscfg->code_name; lenses_desc[i].num = i; } else { lenses_desc[i].name = NULL; lenses_desc[i].num = 0; } } } // Load the file arr_size = lenses_conf.lenses_count; for (i=0; i < arr_size; i++) { sprintf(block_buf,"lens%d",i); pos = 0; k = find_conf_block(buf,&pos,len,block_buf); if (k < 0) { if ((flags & CnfLd_AcceptPartial) == 0) { WARNMSG("Block [%s] not found in %s file.",block_buf,config_textname); return false; } continue; } lenscfg = &lenses_conf.lenses[i]; #define COMMAND_TEXT(cmd_num) get_conf_parameter_text(lenses_data_commands,cmd_num) while (pos<len) { // Finding command number in this line cmd_num = recognize_conf_command(buf,&pos,len,lenses_data_commands); // Now store the config item in correct place if (cmd_num == -3) break; // if next block starts if ((flags & CnfLd_ListOnly) != 0) { // In "List only" mode, accept only name command if (cmd_num > 1) { cmd_num = 0; } } n = 0; switch (cmd_num) { case 1: // NAME if (get_conf_parameter_single(buf,&pos,len,lenscfg->code_name,COMMAND_WORD_LEN) <= 0) { CONFWRNLOG("Couldn't read \"%s\" parameter in [%s] block of %s file.", COMMAND_TEXT(cmd_num),block_buf,config_textname); break; } n++; break; case 2: // MIST if (get_conf_parameter_single(buf,&pos,len,lenscfg->mist_file,DISKPATH_SIZE) > 0) { n++; } if (get_conf_parameter_single(buf,&pos,len,word_buf,sizeof(word_buf)) > 0) { k = atoi(word_buf); if ((k >= 0) && (k < 64)) { lenscfg->mist_lightness = k; n++; } } if (get_conf_parameter_single(buf,&pos,len,word_buf,sizeof(word_buf)) > 0) { k = atoi(word_buf); if ((k >= 0) && (k < 256)) { lenscfg->mist_ghost = k; n++; } } if (n < 3) { CONFWRNLOG("Incorrect value of \"%s\" parameter in [%s] block of %s file.", COMMAND_TEXT(cmd_num),block_buf,config_textname); } else { lenscfg->flags |= LCF_HasMist; } break; case 3: // DISPLACEMENT if (get_conf_parameter_single(buf,&pos,len,word_buf,sizeof(word_buf)) > 0) { k = atoi(word_buf); if ((k > 0) && (k < 256)) { lenscfg->displace_kind = k; n++; } } if (get_conf_parameter_single(buf,&pos,len,word_buf,sizeof(word_buf)) > 0) { k = atoi(word_buf); if ((k >= 0) && (k < 512)) { lenscfg->displace_magnitude = k; n++; } } if (get_conf_parameter_single(buf,&pos,len,word_buf,sizeof(word_buf)) > 0) { k = atoi(word_buf); if ((k > 0) && (k < 512)) { lenscfg->displace_period = k; n++; } } if (n < 3) { CONFWRNLOG("Incorrect value of \"%s\" parameter in [%s] block of %s file.", COMMAND_TEXT(cmd_num),block_buf,config_textname); } else { lenscfg->flags |= LCF_HasDisplace; } break; case 4: // PALETTE if (get_conf_parameter_single(buf,&pos,len,word_buf,sizeof(word_buf)) > 0) { fname = prepare_file_path(FGrp_StdData,word_buf); if ( LbFileLoadAt(fname, lenscfg->palette) == PALETTE_SIZE) { n++; } } if (n < 1) { CONFWRNLOG("Incorrect value of \"%s\" parameter in [%s] block of %s file.", COMMAND_TEXT(cmd_num),block_buf,config_textname); } else { lenscfg->flags |= LCF_HasPalette; } break; case 0: // comment break; case -1: // end of buffer break; default: CONFWRNLOG("Unrecognized command (%d) in [%s] block of %s file.", cmd_num,block_buf,config_textname); break; } skip_conf_to_next_line(buf,&pos,len); } #undef COMMAND_TEXT } return true; }
void fronttorture_load(void) { struct PlayerInfo *player; char *fname; unsigned char *ptr; long i,k; wait_for_cd_to_be_available(); frontend_load_data_from_cd(); memcpy(frontend_backup_palette, &frontend_palette, PALETTE_SIZE); // Texture blocks memory isn't used here, so reuse it instead of allocating ptr = block_mem; // Load RAW/PAL background fname = prepare_file_path(FGrp_LoData,"torture.raw"); torture_background = ptr; i = LbFileLoadAt(fname, ptr); ptr += i; fname = prepare_file_path(FGrp_LoData,"torture.pal"); torture_palette = ptr; i = LbFileLoadAt(fname, ptr); ptr += i; // Load DAT/TAB sprites for doors k = 0; { fname = prepare_file_fmtpath(FGrp_LoData,"door%02d.dat",k+1); i = LbFileLoadAt(fname, ptr); doors[k].data = ptr; ptr += i; doors[k].data_end = ptr; fname = prepare_file_fmtpath(FGrp_LoData,"door%02d.tab",k+1); i = LbFileLoadAt(fname, ptr); doors[k].sprites = (struct TbSprite *)ptr; ptr += i; doors[k].sprites_end =(struct TbSprite *) ptr; } ptr = &game.land_map_start; for (k=1; k < 8; k++) { fname = prepare_file_fmtpath(FGrp_LoData,"door%02d.dat",k+1); i = LbFileLoadAt(fname, ptr); doors[k].data = ptr; ptr += i; doors[k].data_end = ptr; fname = prepare_file_fmtpath(FGrp_LoData,"door%02d.tab",k+1); i = LbFileLoadAt(fname, ptr); doors[k].sprites = (struct TbSprite *)ptr; ptr += i; doors[k].sprites_end = (struct TbSprite *)ptr; } ptr = poly_pool; k = 8; { fname = prepare_file_fmtpath(FGrp_LoData,"door%02d.dat",k+1); i = LbFileLoadAt(fname, ptr); doors[k].data = ptr; ptr += i; doors[k].data_end = ptr; fname = prepare_file_fmtpath(FGrp_LoData,"door%02d.tab",k+1); i = LbFileLoadAt(fname, ptr); doors[k].sprites = (struct TbSprite *)ptr; ptr += i; doors[k].sprites_end = (struct TbSprite *)ptr; } if ( LbDataLoadAll(torture_load_files) ) ERRORLOG("Unable to load torture load files"); LbSpriteSetupAll(setup_torture_sprites); frontend_load_data_reset(); memcpy(&frontend_palette, torture_palette, PALETTE_SIZE); torture_state.action = 0; torture_door_selected = -1; torture_end_sprite = -1; torture_sprite_direction = 0; LbMemorySet(door_sound_state, 0, TORTURE_DOORS_COUNT*sizeof(struct DoorSoundState)); player = get_my_player(); if (player->victory_state == VicS_WonLevel) { LbMouseChangeSpriteAndHotspot(&fronttor_sprites[1], 0, 0); } else { LbMouseChangeSpriteAndHotspot(0, 0, 0); } torture_left_button = 0; }