onilink_

Untitled

Feb 25th, 2019
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.21 KB | None | 0 0
  1.  
  2. int PersistentPlayerData::deserialize(od::StreamData& s, const SaveParams& params, bool only_game_mode)
  3. {
  4.     uint32_t flags_temp;
  5.    
  6.     printf("PersistantPlayerData::deserialize(%d)\n", params.version);
  7.    
  8.     if(params.version > 8)
  9.     {
  10.         uint8_t diff, mode;
  11.         s >> diff
  12.           >> mode
  13.           >> hardmode
  14.           >> challenge_save_id;
  15.        
  16.         difficulty = static_cast<Difficulty>(diff);
  17.         game_mode  = static_cast<GameMode>(mode);
  18.        
  19.         if(params.version > 13 && !params.networked)
  20.             linked_world.deserialize(s);
  21.     }
  22.    
  23.     //if(only_game_mode && params.version <= 13)
  24.     //    return 0;
  25.    
  26.     if(params.version >= 32) {
  27.         player_uuid.deserialize(s);
  28.         decltype (play_time.seconds()) seconds;
  29.         s >> seconds;
  30.         play_time.setSeconds(seconds);
  31.     } else {
  32.         player_uuid.generate();
  33.     }
  34.    
  35.     if(params.version > 6) {
  36.         appearance.deserialize(s, params.version);
  37.     }
  38.    
  39.     s >> souls
  40.       >> monster_experience
  41.       >> fame;
  42.    
  43.     if(params.version >= 28) {
  44.         s >> dark_souls;
  45.     }
  46.    
  47.     if(!params.networked)
  48.     {
  49.         if(params.version > 9)
  50.         {
  51.             uint16_t count;
  52.             s >> count;
  53.            
  54.             std::cout << "Unlocked skills:" << count << std::endl;
  55.            
  56.             if(unlocked_skill_tree.size() < count)
  57.                 unlocked_skill_tree.resize(count);
  58.             for(auto& e: unlocked_skill_tree)
  59.             {
  60.                 uint8_t flags;
  61.                 s >> flags;
  62.                 e = std::bitset<8>(flags);
  63.             }
  64.            
  65.             for(int i=0; i<13; ++i)
  66.             {
  67.                 uint16_t frame;
  68.                 s >> frame;
  69.                 assigned_skills_ground[i] = skillFromIconIndex(frame);
  70.                 s >> frame;
  71.                 assigned_skills_air[i] = skillFromIconIndex(frame);
  72.             }
  73.         }
  74.         else
  75.         {
  76.             // Ancien format de skills
  77.             std::vector<uint8_t> unlocked_skill;
  78.             s >> unlocked_skill;
  79.         }
  80.        
  81.         s >> unlocked_transformation
  82.           >> quests_states
  83.           >> flags_temp;
  84.        
  85.         printf(">souls = %d\n", souls);
  86.        
  87.         flags = std::bitset<32>(flags_temp);
  88.         //printf("Flags: %u\n", flags_temp);
  89.     }
  90.    
  91.     eaten_food.deserialize(s, params);
  92.     initializeBaseStats();
  93.     eaten_food.updateBaseStats(base_life, base_stamina);
  94.    
  95.     if(!params.networked)
  96.     {
  97.        
  98.         if(params.version > 6)
  99.         {
  100.             for(int i=0; i<8; ++i)
  101.                 inventories.inventories[i].deserialize(s, params);
  102.            
  103.             /* for(auto& inv: super_inventory)
  104.             {
  105.                 inv.deserialize(s, params);
  106.             }
  107.            
  108.             // Check inventories sizes
  109.             for(auto& inv: super_inventory)
  110.             {
  111.                 std::cout << "Inv:" << inv.count() << "," << inv.maxCapacity() << std::endl;
  112.                 inv.resize(256);
  113.             }*/
  114.         }
  115.         else
  116.         {
  117.             throw std::runtime_error("Deprecated save version");
  118.            
  119.             /* inventory.deserialize(s, params);
  120.             std::swap(inventory, super_inventory[0]);
  121.             // Sort items
  122.             //for(auto& item: super_inventory[0].items())
  123.             for(unsigned i=0; i<super_inventory[0].items().size(); ++i)
  124.             {
  125.                 ItemSlot& item = super_inventory[0].get(i);
  126.                 int inv = getItemIventory(item);
  127.                 if(inv != 0)
  128.                 {
  129.                     ItemSlot slot = item;
  130.                     item = ItemSlot();
  131.                     super_inventory[inv].addItem(slot);
  132.                 }
  133.             }*/
  134.         }
  135.     }
  136.    
  137.     inventories.hotbar().deserialize(s, params);
  138.     inventories.equipment().deserialize(s, params);
  139.     hand_slot.deserialize(s, params);
  140.    
  141.     /**
  142.     inventories.hotbar().clear();
  143.     inventories.equipment().clear();
  144.     for(int i=0; i<8; ++i)
  145.         inventories.inventories[i].clear();
  146.     */
  147.    
  148.     ///std::cout << "select_bar:" << select_bar.count() << "," << select_bar.maxCapacity() << std::endl;    
  149.     ///std::cout << "equipment:" << equipment.count() << "," << equipment.maxCapacity() << std::endl;      
  150.    
  151.     if(!params.networked)
  152.     {
  153.         uint32_t count;
  154.         s >> count;
  155.        
  156.         std::cout << "Quests:" << count << std::endl;
  157.        
  158.         /// @todo temporary code
  159.         // Corrupted quests
  160.         if(count >= 100)
  161.             return 1;
  162.        
  163.         for(uint32_t i=0; i<count; ++i)
  164.         {
  165.             std::unique_ptr<Quest> quest = std::make_unique<Quest>();
  166.             quest->deserialize(s, params);
  167.             // double quests not allowed
  168.             bool find = false;
  169.             for(const auto& q: quests) {
  170.                 if(q->ind() == quest->ind()) {
  171.                     find = true;
  172.                     break;
  173.                 }
  174.             }
  175.             if(!find)
  176.                 quests.push_back(std::move(quest));
  177.         }
  178.        
  179.         //if(unlocked_skill.size() < 8)
  180.         //    unlocked_skill.resize(8, false);
  181.        
  182.         for(auto& quest: quests)
  183.             quest->initialize(*this);
  184.        
  185.         // dans le cas ou certaines quetes lancées ne serait pas crées (wtf mais ça peut arriver il faut croire)
  186.         // on les crées
  187.         for(size_t i=0; i<quests_states.size(); ++i)
  188.         {
  189.             if(quests_states[i] == 1) {
  190.                 // on verifie que la quete est bien lancée
  191.                 bool find = false;
  192.                 for(auto& quest: quests)
  193.                 {
  194.                     if(quest->ind() == i) {
  195.                         find = true;
  196.                         break;
  197.                     }
  198.                 }
  199.                 if(!find) {
  200.                     quests.push_back( std::make_unique<Quest>(Quest::getQuest(i)) );
  201.                 }
  202.             }
  203.         }
  204.         /// fix for corrupted quests
  205. //        for(unsigned i=10; i<quests_states.size(); ++i) {
  206. //            quests_states[i] = 0;
  207. //        }
  208. //        quests.clear();
  209.     }
  210.    
  211.     return 0;
  212. }
Advertisement
Add Comment
Please, Sign In to add comment