예제 #1
0
static int tolua_bindings_atlantis_write_game00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
 tolua_Error tolua_err;
 if (
     !tolua_isstring(tolua_S,1,0,&tolua_err) ||
     !tolua_isnoobj(tolua_S,2,&tolua_err)
 )
  goto tolua_lerror;
 else
#endif
 {
  const char* filename = ((const char*)  tolua_tostring(tolua_S,1,0));
  {
   int tolua_ret = (int)  write_game(filename);
   tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
  }
 }
 return 1;
#ifndef TOLUA_RELEASE
 tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'write_game'.",&tolua_err);
 return 0;
#endif
}
예제 #2
0
파일: tbg.cpp 프로젝트: TeoTwawki/dltcep
int Ctbg::patch_baldur_gam(int fhandle)
{
  npc_header tbgnentry;
  int npccount;
  int ret;

  if(read(fhandle,&tbgnheader.unused,sizeof(tbgnheader)-4)!=sizeof(tbgnheader)-4)
  {
    return -2;
  }
  if(tbgnheader.npcoffset!=sizeof(tbgnheader))
  {
    return -2;
  }
  if(read_game("BALDUR"))
  {
    return -6; //current ie engine doesn't support npcs (only bg2/bg1)
  }
  for(npccount=0;npccount<tbgnheader.npccount;npccount++)
  {
    if(read(fhandle,&tbgnentry,sizeof(npc_header) )!=sizeof(npc_header) )
    {
      return -2;
    }
    ret=the_game.AddNpc(tbgnentry.npcname,tbgnentry.area, tbgnentry.x, tbgnentry.y);
    if(ret<0) return ret;
  }
  return write_game("BALDUR","");
}
예제 #3
0
static void test_group_readwrite_dead_faction(CuTest *tc) {
    gamedata data;
    storage store;
    faction *f, *f2;
    unit * u;
    group *g;
    ally *al;
    int fno;

    test_cleanup();
    f = test_create_faction(0);
    fno = f->no;
    CuAssertPtrEquals(tc, f, factions);
    CuAssertPtrEquals(tc, 0, f->next);
    f2 = test_create_faction(0);
    CuAssertPtrEquals(tc, f2, factions->next);
    u = test_create_unit(f2, test_create_region(0, 0, 0));
    CuAssertPtrNotNull(tc, u);
    g = join_group(u, "group");
    CuAssertPtrNotNull(tc, g);
    al = ally_add(&g->allies, f);
    CuAssertPtrNotNull(tc, al);

    CuAssertPtrEquals(tc, f, factions);
    destroyfaction(&factions);
    CuAssertTrue(tc, !f->_alive);
    CuAssertPtrEquals(tc, f2, factions);
    mstream_init(&data.strm);
    gamedata_init(&data, &store, RELEASE_VERSION);
    write_game(&data);
    free_gamedata();
    f = f2 = NULL;
    data.strm.api->rewind(data.strm.handle);
    read_game(&data);
    mstream_done(&data.strm);
    gamedata_done(&data);
    CuAssertPtrEquals(tc, 0, findfaction(fno));
    f2 = factions;
    CuAssertPtrNotNull(tc, f2);
    u = f2->units;
    CuAssertPtrNotNull(tc, u);
    g = get_group(u);
    CuAssertPtrNotNull(tc, g);
    CuAssertPtrEquals(tc, 0, g->allies);
    test_cleanup();
}
예제 #4
0
void savegame::write_game_to_disk(const std::string& filename)
{
	LOG_SAVE << "savegame::save_game" << std::endl;

	filename_ = filename;
	filename_ += compression::format_extension(compress_saves_);

	std::stringstream ss;
	{
		config_writer out(ss, compress_saves_);
		write_game(out);
		finish_save_game(out);
	}
	filesystem::scoped_ostream os(open_save_game(filename_));
	(*os) << ss.str();

	if (!os->good()) {
		throw game::save_game_failed(_("Could not write to file"));
	}
}
예제 #5
0
void savegame::write_game_to_disk(const std::string& filename)
{
	LOG_SAVE << "savegame::save_game";

	filename_ = filename;

	if (compress_saves_) {
		filename_ += ".gz";
	}

	std::stringstream ss;
	{
		config_writer out(ss, compress_saves_);
		write_game(out);
		finish_save_game(out);
	}
	scoped_ostream os(open_save_game(filename_));
	(*os) << ss.str();

	if (!os->good()) {
		throw game::save_game_failed(_("Could not write to file"));
	}
}
예제 #6
0
void savegame::write_game_to_disk(const std::string& filename)
{
	filename_ = filename;
	filename_ += ".sav";

	std::stringstream ss;
	{
		config_writer out(ss, false);
		write_game(out);
	}

	// start scenario data(write it to stream only first, others write stream to file direct)
	if (!gamestate_.start_scenario_ss.str().length()) {
		::write(gamestate_.start_scenario_ss, gamestate_.starting_pos);
	}
	if (!gamestate_.start_hero_data_) {
		gamestate_.start_hero_data_ = (uint8_t*)malloc(heros_start_.file_size());
		heros_start_.map_to_mem(gamestate_.start_hero_data_);
	}

	config cfg_summary;
	std::stringstream summary_ss;
	extract_summary_data_from_save(cfg_summary);
	::write(summary_ss, cfg_summary);

	// if enable compress, ss.str() is compressed format data.
	posix_file_t fp;
	uint32_t summary_size, scenario_size, side_size, start_scenario_size, start_hero_size, replay_size, hero_size, member_data_size, bytertd;
	int size;

	// replace_space2underbar(filename_);
	std::string fullfilename = get_saves_dir() + "/" + filename_;
#ifdef _WIN32
	// utf8 ---> utf16
	int wlen = MultiByteToWideChar(CP_UTF8, 0, fullfilename.c_str(), -1, NULL, 0);
	WCHAR *wc = new WCHAR[wlen];
	MultiByteToWideChar(CP_UTF8, 0, fullfilename.c_str(), -1, wc, wlen);
			
	fp = CreateFileW(wc, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
			CREATE_ALWAYS, 0, NULL);
	// posix_fopen(wc, GENERIC_WRITE, CREATE_ALWAYS, fp);
	delete [] wc;
#else
	posix_fopen(fullfilename.c_str(), GENERIC_WRITE, CREATE_ALWAYS, fp);
#endif
	
	if (fp == INVALID_FILE) {
		throw game::save_game_failed(_("Could not write to file"));
	}

	// length of summary data
	summary_size = summary_ss.str().length();
	// length of scenario data
	scenario_size = ss.str().length();
	// length of side data
	side_size = ((unit_segment2*)game_config::savegame_cache)->size_;
	// length of start scenario data
	start_scenario_size = gamestate_.start_scenario_ss.str().length();
	// length of start hero data
	start_hero_size = heros_start_.file_size();
	// length of replay data
	if (gamestate_.replay_data.pool_pos_vsize()) {
		replay_size = 16 + gamestate_.replay_data.pool_data_gzip_size() + gamestate_.replay_data.pool_pos_vsize() * sizeof(unsigned int);
	} else {
		replay_size = 0;
	}
	// length of runtime hero data
	hero_size = heros_.file_size();
	// length of runtime-member data
	member_data_size = runtime_groups::size();

	// [write] length of summary data
	posix_fwrite(fp, &summary_size, sizeof(summary_size), bytertd);
	// [write] length of scenario data
	posix_fwrite(fp, &scenario_size, sizeof(scenario_size), bytertd);
	// [write] length of side data
	posix_fwrite(fp, &side_size, sizeof(side_size), bytertd);
	// [write] length of start scenario data
	posix_fwrite(fp, &start_scenario_size, sizeof(start_scenario_size), bytertd);
	// [write] length of start hero data
	posix_fwrite(fp, &start_hero_size, sizeof(start_hero_size), bytertd);
	// [write] length of replay data
	posix_fwrite(fp, &replay_size, sizeof(replay_size), bytertd);
	// [write] length of runtime hero data
	posix_fwrite(fp, &hero_size, sizeof(hero_size), bytertd);
	// [write] length of member data
	posix_fwrite(fp, &member_data_size, sizeof(member_data_size), bytertd);

	// summary data
	posix_fwrite(fp, summary_ss.str().c_str(), summary_ss.str().length(), bytertd);
	// scenario data
	posix_fwrite(fp, ss.str().c_str(), ss.str().length(), bytertd);
	// side data
	if (side_size) {
		posix_fwrite(fp, game_config::savegame_cache, side_size, bytertd);
	}
	// start scenario data
	posix_fwrite(fp, gamestate_.start_scenario_ss.str().c_str(), gamestate_.start_scenario_ss.str().length(), bytertd);
	// start hero data
	posix_fwrite(fp, gamestate_.start_hero_data_, start_hero_size, bytertd);
	
	// replay data
	if (replay_size) {
		size = gamestate_.replay_data.pool_data_size();
		posix_fwrite(fp, &size, sizeof(size), bytertd);
		size = gamestate_.replay_data.pool_data_gzip_size();
		posix_fwrite(fp, &size, sizeof(size), bytertd);
		size = gamestate_.replay_data.pool_pos_size();
		posix_fwrite(fp, &size, sizeof(size), bytertd);
		size = gamestate_.replay_data.pool_pos_vsize();
		posix_fwrite(fp, &size, sizeof(size), bytertd);
		// pool data
		posix_fwrite(fp, gamestate_.replay_data.pool_data(), gamestate_.replay_data.pool_data_gzip_size(), bytertd);
		// pool pos
		posix_fwrite(fp, gamestate_.replay_data.pool_pos(), gamestate_.replay_data.pool_pos_vsize() * sizeof(unsigned int), bytertd);
	}

	// hero data
	heros_.map_to_file_fp(fp);
	// member data
	runtime_groups::to_fp(fp); 

	posix_fclose(fp);
}