// static RefCountedPtr<Galaxy> GalaxyGenerator::CreateFromJson(const Json &jsonObj) { try { std::string genName = jsonObj["name"]; GalaxyGenerator::Version genVersion = jsonObj["version"]; RefCountedPtr<Galaxy> galaxy = GalaxyGenerator::Create(genName, genVersion); if (!galaxy) { Output("can't load savefile, unsupported galaxy generator %s, version %d\n", genName.c_str(), genVersion); throw SavedGameWrongVersionException(); } return galaxy; } catch (Json::type_error &) { throw SavedGameCorruptException(); } }
Game::Game(Serializer::Reader &rd) : m_timeAccel(TIMEACCEL_PAUSED), m_requestedTimeAccel(TIMEACCEL_PAUSED), m_forceTimeAccel(false) { // signature check for (Uint32 i = 0; i < strlen(s_saveStart)+1; i++) if (rd.Byte() != s_saveStart[i]) throw SavedGameCorruptException(); // version check rd.SetStreamVersion(rd.Int32()); Output("savefile version: %d\n", rd.StreamVersion()); if (rd.StreamVersion() != s_saveVersion) { Output("can't load savefile, expected version: %d\n", s_saveVersion); throw SavedGameWrongVersionException(); } // XXX This must be done after loading sectors once we can change them in game Pi::FlushCaches(); Serializer::Reader section; // game state section = rd.RdSection("Game"); m_time = section.Double(); m_state = State(section.Int32()); m_wantHyperspace = section.Bool(); m_hyperspaceProgress = section.Double(); m_hyperspaceDuration = section.Double(); m_hyperspaceEndTime = section.Double(); // space, all the bodies and things section = rd.RdSection("Space"); m_space.reset(new Space(this, section, m_time)); m_player.reset(static_cast<Player*>(m_space->GetBodyByIndex(section.Int32()))); // space transition state section = rd.RdSection("HyperspaceClouds"); // hyperspace clouds being brought over from the previous system Uint32 nclouds = section.Int32(); for (Uint32 i = 0; i < nclouds; i++) m_hyperspaceClouds.push_back(static_cast<HyperspaceCloud*>(Body::Unserialize(section, 0))); // system political stuff section = rd.RdSection("Polit"); Polit::Unserialize(section); // views LoadViews(rd); // lua section = rd.RdSection("LuaModules"); Pi::luaSerializer->Unserialize(section); // signature check for (Uint32 i = 0; i < strlen(s_saveEnd)+1; i++) if (rd.Byte() != s_saveEnd[i]) throw SavedGameCorruptException(); }
Game::Game(Serializer::Reader &rd) : m_timeAccel(TIMEACCEL_PAUSED), m_requestedTimeAccel(TIMEACCEL_PAUSED), m_forceTimeAccel(false) { // signature check for (Uint32 i = 0; i < strlen(s_saveStart)+1; i++) if (rd.Byte() != s_saveStart[i]) throw SavedGameCorruptException(); // version check rd.SetStreamVersion(rd.Int32()); Output("savefile version: %d\n", rd.StreamVersion()); if (rd.StreamVersion() != s_saveVersion) { Output("can't load savefile, expected version: %d\n", s_saveVersion); throw SavedGameWrongVersionException(); } // XXX This must be done after loading sectors once we can change them in game Pi::FlushCaches(); Serializer::Reader section; // Preparing the Lua stuff LuaRef::InitLoad(); Pi::luaSerializer->InitTableRefs(); // galaxy generator section = rd.RdSection("GalaxyGen"); std::string genName = section.String(); GalaxyGenerator::Version genVersion = section.Int32(); if (genName != Pi::GetGalaxy()->GetGeneratorName() || genVersion != Pi::GetGalaxy()->GetGeneratorVersion()) { if (!Pi::CreateGalaxy(genName, genVersion)) { Output("can't load savefile, unsupported galaxy generator %s, version %d\n", genName.c_str(), genVersion); throw SavedGameWrongVersionException(); } } // game state section = rd.RdSection("Game"); m_time = section.Double(); m_state = State(section.Int32()); m_wantHyperspace = section.Bool(); m_hyperspaceProgress = section.Double(); m_hyperspaceDuration = section.Double(); m_hyperspaceEndTime = section.Double(); // space, all the bodies and things section = rd.RdSection("Space"); m_space.reset(new Space(this, section, m_time)); m_player.reset(static_cast<Player*>(m_space->GetBodyByIndex(section.Int32()))); assert(!m_player->IsDead()); // Pioneer does not support necromancy // space transition state section = rd.RdSection("HyperspaceClouds"); // hyperspace clouds being brought over from the previous system Uint32 nclouds = section.Int32(); for (Uint32 i = 0; i < nclouds; i++) m_hyperspaceClouds.push_back(static_cast<HyperspaceCloud*>(Body::Unserialize(section, 0))); // system political stuff section = rd.RdSection("Polit"); Polit::Unserialize(section); // views LoadViews(rd); // lua section = rd.RdSection("LuaModules"); Pi::luaSerializer->Unserialize(section); Pi::luaSerializer->UninitTableRefs(); LuaRef::UninitLoad(); // signature check for (Uint32 i = 0; i < strlen(s_saveEnd)+1; i++) if (rd.Byte() != s_saveEnd[i]) throw SavedGameCorruptException(); EmitPauseState(IsPaused()); }
Game::Game(const Json::Value &jsonObj) : m_timeAccel(TIMEACCEL_PAUSED), m_requestedTimeAccel(TIMEACCEL_PAUSED), m_forceTimeAccel(false) { // signature check if (!jsonObj.isMember("signature")) throw SavedGameCorruptException(); Json::Value signature = jsonObj["signature"]; if (signature.isString() && signature.asString().compare(s_saveStart) == 0) {} else throw SavedGameCorruptException(); // version check if (!jsonObj.isMember("version")) throw SavedGameCorruptException(); Json::Value version = jsonObj["version"]; if (!version.isInt()) throw SavedGameCorruptException(); Output("savefile version: %d\n", version.asInt()); if (version.asInt() == s_saveVersion) {} else { Output("can't load savefile, expected version: %d\n", s_saveVersion); throw SavedGameWrongVersionException(); } // Preparing the Lua stuff Pi::luaSerializer->InitTableRefs(); // galaxy generator m_galaxy = Galaxy::LoadFromJson(jsonObj); // game state if (!jsonObj.isMember("time")) throw SavedGameCorruptException(); if (!jsonObj.isMember("state")) throw SavedGameCorruptException(); m_time = StrToDouble(jsonObj["time"].asString()); m_state = State(jsonObj["state"].asInt()); if (!jsonObj.isMember("want_hyperspace")) throw SavedGameCorruptException(); if (!jsonObj.isMember("hyperspace_progress")) throw SavedGameCorruptException(); if (!jsonObj.isMember("hyperspace_duration")) throw SavedGameCorruptException(); if (!jsonObj.isMember("hyperspace_end_time")) throw SavedGameCorruptException(); m_wantHyperspace = jsonObj["want_hyperspace"].asBool(); m_hyperspaceProgress = StrToDouble(jsonObj["hyperspace_progress"].asString()); m_hyperspaceDuration = StrToDouble(jsonObj["hyperspace_duration"].asString()); m_hyperspaceEndTime = StrToDouble(jsonObj["hyperspace_end_time"].asString()); // space, all the bodies and things if (!jsonObj.isMember("player")) throw SavedGameCorruptException(); m_space.reset(new Space(this, m_galaxy, jsonObj, m_time)); m_player.reset(static_cast<Player*>(m_space->GetBodyByIndex(jsonObj["player"].asUInt()))); assert(!m_player->IsDead()); // Pioneer does not support necromancy // hyperspace clouds being brought over from the previous system if (!jsonObj.isMember("hyperspace_clouds")) throw SavedGameCorruptException(); Json::Value hyperspaceCloudArray = jsonObj["hyperspace_clouds"]; if (!hyperspaceCloudArray.isArray()) throw SavedGameCorruptException(); for (Uint32 i = 0; i < hyperspaceCloudArray.size(); i++) m_hyperspaceClouds.push_back(static_cast<HyperspaceCloud*>(Body::FromJson(hyperspaceCloudArray[i], 0))); // views LoadViewsFromJson(jsonObj); // lua Pi::luaSerializer->FromJson(jsonObj); Pi::luaSerializer->UninitTableRefs(); // signature check (don't really need this anymore) if (!jsonObj.isMember("trailing_signature")) throw SavedGameCorruptException(); Json::Value trailingSignature = jsonObj["trailing_signature"]; if (trailingSignature.isString() && trailingSignature.asString().compare(s_saveEnd) == 0) {} else throw SavedGameCorruptException(); EmitPauseState(IsPaused()); }