/* --------- local code */
static struct wad_data *get_physics_wad_data(
	bool *bungie_physics)
{
	struct wad_data *wad= NULL;
	
//	dprintf("Open is: %d %d %.*s", physics_file.vRefNum, physics_file.parID, physics_file.name[0], physics_file.name+1);

	OpenedFile PhysicsFile;
	if(open_wad_file_for_reading(PhysicsFileSpec,PhysicsFile))
	{
		struct wad_header header;

		if(read_wad_header(PhysicsFile, &header))
		{
			if(header.data_version==BUNGIE_PHYSICS_DATA_VERSION || header.data_version==PHYSICS_DATA_VERSION)
			{
				wad= read_indexed_wad_from_file(PhysicsFile, &header, 0, true);
				if(header.data_version==BUNGIE_PHYSICS_DATA_VERSION)
				{
					*bungie_physics= true;
				} else {
					*bungie_physics= false;
				}
			}
		}

		close_wad_file(PhysicsFile);
	} 
	
	/* Reset any errors that might have occurred.. */
	set_game_error(systemError, errNone);

	return wad;
}
Exemplo n.º 2
0
SDL_Surface *WadImageCache::image_from_desc(WadImageDescriptor& desc)
{
	SDL_Surface *surface = NULL;
	OpenedFile wad_file;
	if (open_wad_file_for_reading(desc.file, wad_file))
	{
		struct wad_header header;
		if (read_wad_header(wad_file, &header))
		{
			struct wad_data *wad;
			wad = read_indexed_wad_from_file(wad_file, &header, desc.index, true);
			if (wad)
			{
				void *data;
				size_t length;
				data = extract_type_from_wad(wad, desc.tag, &length);
				if (data && length)
				{
					SDL_RWops *rwops = SDL_RWFromConstMem(data, length);
#ifdef HAVE_SDL_IMAGE
					surface = IMG_Load_RW(rwops, 1);
#else
					surface = SDL_LoadBMP_RW(rwops, 1);
#endif
				}
				free_wad(wad);
			}
		}
		close_wad_file(wad_file);
	}
	clear_game_error();
	return surface;
}
Exemplo n.º 3
0
static void load_preferences(
  void)
{
  /* If it was already allocated, we are reloading, so free the old one.. */
  if(prefInfo->wad) {
    free_wad(prefInfo->wad);
    prefInfo->wad= NULL;
  }

  OpenedFile PrefsFile;
  if (open_wad_file_for_reading(prefInfo->PrefsFile,PrefsFile)) {
    struct wad_header header;

    /* Read the header from the wad file */
    if(read_wad_header(PrefsFile, &header)) {
      /* Read the indexed wad from the file */
      prefInfo->wad= read_indexed_wad_from_file(PrefsFile, &header, 0, false);
      // LP change: more graceful degradation
      if (!prefInfo->wad) {
        set_game_error(gameError, errUnknownWadVersion);
      }
    }

    /* Close the file.. */
    close_wad_file(PrefsFile);
  }
}
Exemplo n.º 4
0
bool QuickSaveLoader::ParseQuickSave(FileSpecifier& file_name)
{
	struct wad_header header;
	struct wad_data *wad;

	OpenedFile file;
    if (file_name.Open(file))
    {
        if (read_wad_header(file, &header))
		{
			wad = read_indexed_wad_from_file(file, &header, SAVE_GAME_METADATA_INDEX, true);
			if (wad)
			{
				size_t data_length;
				char *raw_metadata = (char *)extract_type_from_wad(wad, SAVE_META_TAG, &data_length);
				std::string metadata = std::string(raw_metadata, data_length);
				
				boost::property_tree::ptree pt;
				std::istringstream strm(metadata);
				try {
					boost::property_tree::ini_parser::read_ini(strm, pt);
				} catch (...) {
					return false;
				}
				
				QuickSave Data = QuickSave();
				Data.save_file = file_name;
				Data.name = pt.get("name", Data.name);
				Data.level_name = pt.get("level_name", Data.level_name);
				Data.ticks = pt.get("ticks", Data.ticks);
				Data.formatted_ticks = pt.get("ticks_formatted", Data.formatted_ticks);
				Data.save_time = pt.get("time", Data.save_time);
				Data.formatted_time = pt.get("time_formatted", Data.formatted_time);
				Data.players = pt.get("players", Data.players);
				QuickSaves::instance()->add(Data);
				
				free_wad(wad);
			}
		}
		
        return true;
    }
    return false;
}
Exemplo n.º 5
0
void create_updated_save(QuickSave& save)
{
	// read data from existing save file
	struct wad_header header;
	struct wad_data *game_wad, *orig_meta_wad, *new_meta_wad;
	int32 game_wad_length;
	std::string imagedata;
	
	OpenedFile currentFile;
	if (save.save_file.Open(currentFile))
	{
		if (read_wad_header(currentFile, &header))
		{
			game_wad = read_indexed_wad_from_file(currentFile, &header, 0, false);
			if (game_wad) game_wad_length = calculate_wad_length(&header, game_wad);

			orig_meta_wad = read_indexed_wad_from_file(currentFile, &header, SAVE_GAME_METADATA_INDEX, true);
			
			if (orig_meta_wad)
			{
				size_t data_length;
				char *raw_imagedata = (char *)extract_type_from_wad(orig_meta_wad, SAVE_IMG_TAG, &data_length);
				imagedata = std::string(raw_imagedata, data_length);
			}
		}
		close_wad_file(currentFile);
	}
	
	// create updated save file
	short err = 0;
	int32 offset, meta_wad_length;
	struct directory_entry entries[2];
	
	FileSpecifier TempFile;
	TempFile.SetTempName(save.save_file);
	
	if (create_wadfile(TempFile, _typecode_savegame))
	{
		OpenedFile SaveFile;
		if(open_wad_file_for_writing(TempFile, SaveFile))
		{
			if (write_wad_header(SaveFile, &header))
			{
				offset = SIZEOF_wad_header;
				
				set_indexed_directory_offset_and_length(&header, entries, 0, offset, game_wad_length, 0);
				
				if (write_wad(SaveFile, &header, game_wad, offset))
				{
					offset += game_wad_length;
					header.directory_offset= offset;
					
					new_meta_wad = build_meta_game_wad(build_save_metadata(save), imagedata, &header, &meta_wad_length);
					if (new_meta_wad)
					{
						set_indexed_directory_offset_and_length(&header, entries, 1, offset, meta_wad_length, SAVE_GAME_METADATA_INDEX);
						
						if (write_wad(SaveFile, &header, new_meta_wad, offset))
						{
							offset += meta_wad_length;
							header.directory_offset= offset;
							
							if (write_wad_header(SaveFile, &header) && write_directorys(SaveFile, &header, entries))
							{
							}
						}
						free_wad(new_meta_wad);
					}
				}
				free_wad(game_wad);
				free_wad(orig_meta_wad);
			}

			err = SaveFile.GetError();
			close_wad_file(SaveFile);
		}
		
		if (!err)
		{
			if (!TempFile.Rename(save.save_file))
			{
				err = 1;
			}
		}
	}
	
	if (err || error_pending())
	{
		if (!err) err = get_game_error(NULL);
		alert_user(infoError, strERRORS, fileError, err);
		clear_game_error();
	}
}