Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int PersistentPlayerData::deserialize(od::StreamData& s, const SaveParams& params, bool only_game_mode)
- {
- uint32_t flags_temp;
- printf("PersistantPlayerData::deserialize(%d)\n", params.version);
- if(params.version > 8)
- {
- uint8_t diff, mode;
- s >> diff
- >> mode
- >> hardmode
- >> challenge_save_id;
- difficulty = static_cast<Difficulty>(diff);
- game_mode = static_cast<GameMode>(mode);
- if(params.version > 13 && !params.networked)
- linked_world.deserialize(s);
- }
- //if(only_game_mode && params.version <= 13)
- // return 0;
- if(params.version >= 32) {
- player_uuid.deserialize(s);
- decltype (play_time.seconds()) seconds;
- s >> seconds;
- play_time.setSeconds(seconds);
- } else {
- player_uuid.generate();
- }
- if(params.version > 6) {
- appearance.deserialize(s, params.version);
- }
- s >> souls
- >> monster_experience
- >> fame;
- if(params.version >= 28) {
- s >> dark_souls;
- }
- if(!params.networked)
- {
- if(params.version > 9)
- {
- uint16_t count;
- s >> count;
- std::cout << "Unlocked skills:" << count << std::endl;
- if(unlocked_skill_tree.size() < count)
- unlocked_skill_tree.resize(count);
- for(auto& e: unlocked_skill_tree)
- {
- uint8_t flags;
- s >> flags;
- e = std::bitset<8>(flags);
- }
- for(int i=0; i<13; ++i)
- {
- uint16_t frame;
- s >> frame;
- assigned_skills_ground[i] = skillFromIconIndex(frame);
- s >> frame;
- assigned_skills_air[i] = skillFromIconIndex(frame);
- }
- }
- else
- {
- // Ancien format de skills
- std::vector<uint8_t> unlocked_skill;
- s >> unlocked_skill;
- }
- s >> unlocked_transformation
- >> quests_states
- >> flags_temp;
- printf(">souls = %d\n", souls);
- flags = std::bitset<32>(flags_temp);
- //printf("Flags: %u\n", flags_temp);
- }
- eaten_food.deserialize(s, params);
- initializeBaseStats();
- eaten_food.updateBaseStats(base_life, base_stamina);
- if(!params.networked)
- {
- if(params.version > 6)
- {
- for(int i=0; i<8; ++i)
- inventories.inventories[i].deserialize(s, params);
- /* for(auto& inv: super_inventory)
- {
- inv.deserialize(s, params);
- }
- // Check inventories sizes
- for(auto& inv: super_inventory)
- {
- std::cout << "Inv:" << inv.count() << "," << inv.maxCapacity() << std::endl;
- inv.resize(256);
- }*/
- }
- else
- {
- throw std::runtime_error("Deprecated save version");
- /* inventory.deserialize(s, params);
- std::swap(inventory, super_inventory[0]);
- // Sort items
- //for(auto& item: super_inventory[0].items())
- for(unsigned i=0; i<super_inventory[0].items().size(); ++i)
- {
- ItemSlot& item = super_inventory[0].get(i);
- int inv = getItemIventory(item);
- if(inv != 0)
- {
- ItemSlot slot = item;
- item = ItemSlot();
- super_inventory[inv].addItem(slot);
- }
- }*/
- }
- }
- inventories.hotbar().deserialize(s, params);
- inventories.equipment().deserialize(s, params);
- hand_slot.deserialize(s, params);
- /**
- inventories.hotbar().clear();
- inventories.equipment().clear();
- for(int i=0; i<8; ++i)
- inventories.inventories[i].clear();
- */
- ///std::cout << "select_bar:" << select_bar.count() << "," << select_bar.maxCapacity() << std::endl;
- ///std::cout << "equipment:" << equipment.count() << "," << equipment.maxCapacity() << std::endl;
- if(!params.networked)
- {
- uint32_t count;
- s >> count;
- std::cout << "Quests:" << count << std::endl;
- /// @todo temporary code
- // Corrupted quests
- if(count >= 100)
- return 1;
- for(uint32_t i=0; i<count; ++i)
- {
- std::unique_ptr<Quest> quest = std::make_unique<Quest>();
- quest->deserialize(s, params);
- // double quests not allowed
- bool find = false;
- for(const auto& q: quests) {
- if(q->ind() == quest->ind()) {
- find = true;
- break;
- }
- }
- if(!find)
- quests.push_back(std::move(quest));
- }
- //if(unlocked_skill.size() < 8)
- // unlocked_skill.resize(8, false);
- for(auto& quest: quests)
- quest->initialize(*this);
- // dans le cas ou certaines quetes lancées ne serait pas crées (wtf mais ça peut arriver il faut croire)
- // on les crées
- for(size_t i=0; i<quests_states.size(); ++i)
- {
- if(quests_states[i] == 1) {
- // on verifie que la quete est bien lancée
- bool find = false;
- for(auto& quest: quests)
- {
- if(quest->ind() == i) {
- find = true;
- break;
- }
- }
- if(!find) {
- quests.push_back( std::make_unique<Quest>(Quest::getQuest(i)) );
- }
- }
- }
- /// fix for corrupted quests
- // for(unsigned i=10; i<quests_states.size(); ++i) {
- // quests_states[i] = 0;
- // }
- // quests.clear();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment