bool Map_Parser::load(std::string filename) { binifstream map; map.open(filename.c_str(),std::ios::binary|std::ios::in); if(map.is_open()) { std::cout<<"Opened the file."<<std::endl; } else { std::cout<<"Failed to open the file."<<std::endl; return false; } map.seekg(0,std::ios::end); size_t filesize = map.tellg(); map.seekg(0,std::ios::beg); map>>block_count; std::cout<<block_count<<" blocks in the file (total size: "<<filesize<<")"<<std::endl; switch(block_count) { case 0: std::cout<<"Looks like the demo's texture mappings. I'll treat it appropriately."<<std::endl; file_id = uw_map::uw1demo_tex; return process_tex_mappings(0); case 240: std::cout<<"Looks like the demo's tilemap/object list. I'll treat it appropriately."<<std::endl; file_id = uw_map::uw1demo_tilemap; return process_tilemap(0); case 42624: std::cout<<"Looks like the demo's animation overlay info. I'll treat it appropriately."<<std::endl; file_id = uw_map::uw1demo_anim_overlay; return process_anim_overlay(0); case 135: std::cout<<"Looks like UW1. I'll treat it appropriately."<<std::endl; file_id = uw_map::uw1map; field_width=9; break; case 320: std::cout<<"Looks like UW2. I'll treat it appropriately."<<std::endl; std::cout<<"TODO: Implement UW2 decompression. Sorry."<<std::endl; file_id = uw_map::uw2map; field_width=80; return false; break; default: std::cout<<"No idea what this file is. I choose to bail in a cowardly fashion."<<std::endl; return false; } block_offsets.resize(block_count,std::pair<uint32_t,uint32_t>(0,0)); lev_dat.resize(field_width); std::vector<uw_map::level_section> sects; sects.resize(block_count, uw_map::ls_none); size_t last_index=0; size_t real_count = 0; for(int i=0;i<block_count;++i) { sects[i]=get_section_type(i); map>>block_offsets[i].first; if(block_offsets[i].first != 0) { if(real_count != 0) { block_offsets[i-1].second = block_offsets[i].first - block_offsets[last_index].first; std::cout<<" Size: "<<block_offsets[i-1].second<<std::endl; } last_index=i; std::cout<<"Block #"<<real_count<<" ("<<i<<") ("<<ls_strings[sects[i]]<<") Offset: "<<block_offsets[i].first; real_count++; } else { //std::cout<<"Empty block #"<<i<<std::endl; } } block_offsets[last_index].second = filesize - block_offsets[last_index].first; std::cout<<" Size: "<<block_offsets[last_index].second<<std::endl; lev_dat.resize(field_width); for(int i=0;i<block_count;++i) { if(block_offsets[i].first != 0) { switch(sects[i]) { case uw_map::level_section::tile_map: break; case uw_map::level_section::anim_overlay: break; case uw_map::level_section::tex_map: break; case uw_map::level_section::map_info: break; case uw_map::level_section::map_notes: break; case uw_map::level_section::ls_none: return false; } //Go through all valid blocks, and parse them into the appropriate structures } } return true; }
int ff_text_pre_parser ( char *origin, FF_BUFSIZE_PTR fmt_buffer, PP_OBJECT_PTR pp_object ) { BOOLEAN called_untl = FALSE; /* called update_name_table_list */ int error = 0; int new_error = 0; char *current_sect_start; char *text_line; sect_types_t current_sect_type; /* type of the previous section */ sect_types_t sect_type; BOOLEAN first_section = TRUE; assert(fmt_buffer); text_line = get_first_line(fmt_buffer->buffer); first_section = TRUE; current_sect_start = NULL; current_sect_type = ZEROTH_SECT; sect_type = !LAST_SECT; /* MAIN LOOP that parses each line of format buffer */ while (sect_type != LAST_SECT) { char save_char; sect_type = get_section_type(text_line, current_sect_type); switch (sect_type) { case ZEROTH_SECT: case IN_SECT: break; case FMT_SECT: case INPUT_EQV_SECT: case OUTPUT_EQV_SECT: case BEGIN_CONSTANT_SECT: case BEGIN_NAME_EQUIV_SECT: case LAST_SECT: /* case ADD_YOUR_SECTION_TYPE_HERE: */ if (first_section) { first_section = FALSE; } else { FF_BUFSIZE bufsize; /* Process current (previous) section */ bufsize.buffer = current_sect_start; bufsize.bytes_used = bufsize.total_bytes = (FF_BSS_t)((char HUGE *)text_line - (char HUGE *)current_sect_start); save_char = *text_line; *text_line = STR_END; switch (current_sect_type) { case FMT_SECT: if (pp_object->ppo_type == PPO_FORMAT_LIST) { error = update_format_list(origin, &bufsize, pp_object->u.hf_list); new_error = error; } break; case INPUT_EQV_SECT: case OUTPUT_EQV_SECT: case BEGIN_CONSTANT_SECT: case BEGIN_NAME_EQUIV_SECT: if (pp_object->ppo_type == PPO_NT_LIST && SAME_IO_CONTEXT(current_sect_type, pp_object) ) { called_untl = TRUE; error = update_name_table_list(origin, &bufsize, pp_object->u.nt_list.hnt_list); new_error = error; } break; /* case ADD_YOUR_SECTION_TYPE_HERE: */ default: assert(!ERR_SWITCH_DEFAULT); return(err_push(ERR_SWITCH_DEFAULT, "%s, %s:%d", ROUTINE_NAME, os_path_return_name(__FILE__), __LINE__)); } /* switch on current section type */ if (new_error) break; *text_line = save_char; } /* (else) if first section */ current_sect_type = sect_type; current_sect_start = text_line; break; default: assert(!ERR_SWITCH_DEFAULT); return(err_push(ERR_SWITCH_DEFAULT, "%s, %s:%d", ROUTINE_NAME, os_path_return_name(__FILE__), __LINE__)); } /* switch on section type */ if (new_error) break; if (sect_type != LAST_SECT) text_line = get_next_line(text_line); } /* while not the last section */ if (pp_object->ppo_type == PPO_NT_LIST && called_untl == FALSE && !error) return(ERR_NO_NAME_TABLE); return(error); }