mii_database.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include "core/hle/result.h"
  5. #include "core/hle/service/mii/types/store_data.h"
  6. namespace Service::Mii {
  7. constexpr std::size_t MaxDatabaseLength{100};
  8. constexpr u32 MiiMagic{0xa523b78f};
  9. constexpr u32 DatabaseMagic{0x4244464e}; // NFDB
  10. class NintendoFigurineDatabase {
  11. public:
  12. /// Returns the total mii count.
  13. u8 GetDatabaseLength() const;
  14. /// Returns full if database is full.
  15. bool IsFull() const;
  16. /// Returns the mii of the specified index.
  17. StoreData Get(std::size_t index) const;
  18. /// Returns the total mii count. Ignoring special mii.
  19. u32 GetCount(const DatabaseSessionMetadata& metadata) const;
  20. /// Returns the index of a mii. If the mii isn't found returns false.
  21. bool GetIndexByCreatorId(u32& out_index, const Common::UUID& create_id) const;
  22. /// Moves the location of a specific mii.
  23. Result Move(u32 current_index, u32 new_index);
  24. /// Replaces mii with new data.
  25. void Replace(u32 index, const StoreData& store_data);
  26. /// Adds a new mii to the end of the database.
  27. void Add(const StoreData& store_data);
  28. /// Removes mii from database and shifts left the remainding data.
  29. void Delete(u32 index);
  30. /// Deletes all contents with a fresh database
  31. void CleanDatabase();
  32. /// Intentionally sets a bad checksum
  33. void CorruptCrc();
  34. /// Returns success if database is valid otherwise returns the corresponding error code.
  35. Result CheckIntegrity();
  36. private:
  37. /// Returns the checksum of the database
  38. u16 GenerateDatabaseCrc();
  39. u32 magic{}; // 'NFDB'
  40. std::array<StoreData, MaxDatabaseLength> miis{};
  41. u8 version{};
  42. u8 database_length{};
  43. u16 crc{};
  44. };
  45. static_assert(sizeof(NintendoFigurineDatabase) == 0x1A98,
  46. "NintendoFigurineDatabase has incorrect size.");
  47. }; // namespace Service::Mii