TbBool load_slabclm_file(struct Column *cols, long *ccount) { long total; unsigned char *buf; long fsize; long i,k; SYNCDBG(18,"Starting"); fsize = 4; buf = load_data_file_to_buffer(&fsize, FGrp_StdData, "slabs.clm"); if (buf == NULL) return false; i = 0; total = llong(&buf[i]); i += 4; // Validate total amount of columns if ((total < 0) || (total > (fsize-4)/sizeof(struct Column))) { total = (fsize-4)/sizeof(struct Column); WARNMSG("Bad amount of columns in Column Set file; corrected to %ld.",total); } if (total > *ccount) { WARNMSG("Only %d columns supported, Column Set file has %ld.",*ccount,total); total = *ccount; } for (k=0; k < total; k++) { LbMemoryCopy(&cols[k],&buf[i],sizeof(struct Column)); i += sizeof(struct Column); } *ccount = total; LbMemoryFree(buf); return true; }
TbBool load_column_file(LevelNumber lv_num) { unsigned long i; long k; unsigned short n; long total; unsigned char *buf; long fsize; if ((game.operation_flags & GOF_ColumnConvert) != 0) { convert_old_column_file(lv_num); game.operation_flags &= ~GOF_ColumnConvert; } fsize = 8; buf = load_single_map_file_to_buffer(lv_num,"clm",&fsize,LMFF_None); if (buf == NULL) return false; clear_columns(); i = 0; total = llong(&buf[i]); i += 4; // Validate total amount of columns if ((total < 0) || (total > (fsize-8)/sizeof(struct Column))) { total = (fsize-8)/sizeof(struct Column); WARNMSG("Bad amount of columns in CLM file; corrected to %ld.",total); } if (total > COLUMNS_COUNT) { WARNMSG("Only %d columns supported, CLM file has %ld.",COLUMNS_COUNT,total); total = COLUMNS_COUNT; } // Read and validate second amount game.field_14AB3F = llong(&buf[i]); if (game.field_14AB3F >= COLUMNS_COUNT) { game.field_14AB3F = COLUMNS_COUNT-1; } i += 4; // Fill the columns for (k=0; k < total; k++) { struct Column *colmn; colmn = &game.columns_data[k]; LbMemoryCopy(colmn, &buf[i], sizeof(struct Column)); //Update top cube in the column n = find_column_height(colmn); set_column_floor_filled_subtiles(colmn, n); i += sizeof(struct Column); } LbMemoryFree(buf); return true; }
void setup_default_settings(void) { // CPU status variable struct CPU_INFO cpu_info; const struct GameSettings default_settings = { 0, // field_0 4, // video_shadows 3, // view_distance 0, // video_rotate_mode 1, // video_textures 0, // video_cluedo_mode 127, // sound_volume 90, // redbook_volume 1, // field_8 0, // gamma_correction Lb_SCREEN_MODE_640_480, // Default Screen mode 0x004 640X480 { {KC_UP, KMod_NONE}, {KC_DOWN, KMod_NONE}, {KC_LEFT, KMod_NONE}, {KC_RIGHT, KMod_NONE}, {KC_LCONTROL, KMod_NONE}, {KC_LSHIFT, KMod_NONE}, {KC_DELETE, KMod_NONE}, {KC_PGDOWN, KMod_NONE}, {KC_HOME, KMod_NONE}, {KC_END, KMod_NONE}, {KC_T, KMod_NONE}, {KC_L, KMod_NONE}, {KC_L, KMod_SHIFT}, {KC_P, KMod_SHIFT}, {KC_T, KMod_ALT}, {KC_T, KMod_SHIFT}, {KC_H, KMod_NONE}, {KC_W, KMod_NONE}, {KC_S, KMod_NONE}, {KC_T, KMod_CONTROL}, {KC_G, KMod_NONE}, {KC_B, KMod_NONE}, {KC_H, KMod_SHIFT}, {KC_G, KMod_SHIFT}, {KC_B, KMod_SHIFT}, {KC_F, KMod_NONE}, {KC_A, KMod_NONE}, {KC_LSHIFT, KMod_NONE}, {KC_NUMPAD0, KMod_NONE}, {KC_BACK, KMod_NONE}, {KC_P, KMod_NONE}, {KC_M, KMod_NONE}, }, // kbkeys 1, // tooltips_on 1, // first_person_move_invert 6 // first_person_move_sensitivity }; LbMemoryCopy(&settings, &default_settings, sizeof(struct GameSettings)); settings.video_scrnmode = get_next_vidmode_for_switching(Lb_SCREEN_MODE_INVALID); cpu_detect(&cpu_info); // Removing this because we suppose these requirements are always met, and only reserved 640*400 // in default switch mode list. // if ((cpu_get_family(&cpu_info) > CPUID_FAMILY_PENTIUM) && (is_feature_on(Ft_HiResVideo))) // { // SYNCDBG(6,"Updating to hires video mode"); // settings.video_scrnmode = get_next_vidmode_for_switching(settings.video_scrnmode); // } }
TbBool load_slab_datclm_files(void) { struct Column *cols; long cols_tot; struct SlabSet *slbset; long slbset_tot; struct SlabSet *sset; long i; SYNCDBG(5,"Starting"); // Load Column Set cols_tot = COLUMNS_COUNT; cols = (struct Column *)LbMemoryAlloc(cols_tot*sizeof(struct Column)); if (cols == NULL) { WARNMSG("Can't allocate memory for %d column sets.",cols_tot); return false; } if (!load_slabclm_file(cols, &cols_tot)) { LbMemoryFree(cols); return false; } // Load Slab Set slbset_tot = SLABSET_COUNT; slbset = (struct SlabSet *)LbMemoryAlloc(slbset_tot*sizeof(struct SlabSet)); if (slbset == NULL) { WARNMSG("Can't allocate memory for %d slab sets.",slbset_tot); return false; } if (!load_slabdat_file(slbset, &slbset_tot)) { LbMemoryFree(cols); LbMemoryFree(slbset); return false; } // Update the structure for (i=0; i < slbset_tot; i++) { sset = &game.slabset[i]; LbMemoryCopy(sset, &slbset[i], sizeof(struct SlabSet)); } game.slabset_num = slbset_tot; update_columns_use(cols,cols_tot,slbset,slbset_tot); LbMemoryFree(slbset); create_columns_from_list(cols,cols_tot); update_slabset_column_indices(cols,cols_tot); LbMemoryFree(cols); return true; }
long load_static_light_file(unsigned long lv_num) { unsigned long i; long k; long total; unsigned char *buf; struct InitLight ilght; long fsize; fsize = 4; buf = load_single_map_file_to_buffer(lv_num,"lgt",&fsize,LMFF_Optional); if (buf == NULL) return false; light_initialise(); i = 0; total = llong(&buf[i]); i += 4; // Validate total amount of lights if ((total < 0) || (total > (fsize-4)/sizeof(struct InitLight))) { total = (fsize-4)/sizeof(struct InitLight); WARNMSG("Bad amount of static lights in LGT file; corrected to %ld.",total); } if (total >= LIGHTS_COUNT) { WARNMSG("Only %d static lights supported, LGT file has %ld.",LIGHTS_COUNT,total); total = LIGHTS_COUNT-1; } else if (total >= LIGHTS_COUNT/2) { WARNMSG("More than %d%% of light slots used by static lights.",100*total/LIGHTS_COUNT); } // Create the lights for (k=0; k < total; k++) { LbMemoryCopy(&ilght, &buf[i], sizeof(struct InitLight)); if (light_create_light(&ilght) == 0) { WARNLOG("Couldn't allocate static light %d",(int)k); } i += sizeof(struct InitLight); } LbMemoryFree(buf); return true; }
void net_load_config_file(void) { TbFileHandle handle; char *fname; // Try to load the config file fname = prepare_file_path(FGrp_Save,keeper_netconf_file); handle = LbFileOpen(fname, Lb_FILE_MODE_READ_ONLY); if (handle != -1) { if (LbFileRead(handle, &net_config_info, sizeof(net_config_info)) == sizeof(net_config_info)) { LbFileClose(handle); return; } LbFileClose(handle); } // If can't load, then use default config LbMemoryCopy(&net_config_info, &default_net_config_info, sizeof(net_config_info)); LbStringCopy(net_config_info.str_u2, get_string(GUIStr_MnuNoName), 20); }
/** * 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 load_action_point_file(LevelNumber lv_num) { struct InitActionPoint iapt; unsigned long i; long k; long total; unsigned char *buf; long fsize; SYNCDBG(5,"Starting"); fsize = 4; buf = load_single_map_file_to_buffer(lv_num,"apt",&fsize,LMFF_None); if (buf == NULL) return false; i = 0; total = llong(&buf[i]); i += 4; // Validate total amount of action points if ((total < 0) || (total > (fsize-4)/sizeof(struct InitActionPoint))) { total = (fsize-4)/sizeof(struct InitActionPoint); WARNMSG("Bad amount of action points in APT file; corrected to %ld.",total); } if (total > ACTN_POINTS_COUNT-1) { WARNMSG("Only %d action points supported, APT file has %ld.",ACTN_POINTS_COUNT-1,total); total = ACTN_POINTS_COUNT-1; } // Create action points for (k=0; k < total; k++) { LbMemoryCopy(&iapt, &buf[i], sizeof(struct InitActionPoint)); if (actnpoint_create_actnpoint(&iapt) == INVALID_ACTION_POINT) { ERRORLOG("Cannot allocate action point %d during APT load",k); } i += sizeof(struct InitActionPoint); } LbMemoryFree(buf); return true; }
TbBool load_thing_file(LevelNumber lv_num) { struct InitThing itng; unsigned long i; long k; long total; unsigned char *buf; long fsize; SYNCDBG(5,"Starting"); fsize = 2; buf = load_single_map_file_to_buffer(lv_num,"tng",&fsize,LMFF_None); if (buf == NULL) return false; i = 0; total = lword(&buf[i]); i += 2; // Validate total amount of things if ((total < 0) || (total > (fsize-2)/sizeof(struct InitThing))) { total = (fsize-2)/sizeof(struct InitThing); WARNMSG("Bad amount of things in TNG file; corrected to %d.",(int)total); } if (total > THINGS_COUNT-2) { WARNMSG("Only %d things supported, TNG file has %d.",(int)(THINGS_COUNT-2),(int)total); total = THINGS_COUNT-2; } // Create things for (k=0; k < total; k++) { LbMemoryCopy(&itng, &buf[i], sizeof(struct InitThing)); thing_create_thing(&itng); i += sizeof(struct InitThing); } LbMemoryFree(buf); return true; }