Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hle: service: mii: Rewrite service to properly support creation of random and default miis. #4292

Merged
merged 1 commit into from Jul 17, 2020

Conversation

@bunnei
Copy link
Contributor

@bunnei bunnei commented Jul 11, 2020

This change rewrites our Mii services implementation. We've pretty much removed the old implementation, which included code to handle the Mii database (which was incomplete/incorrect, and based on assumptions from ~2 years ago). With the rewrite, we focus just on the basics that games need, which are:

  • Proper default Mii data
  • The ability to correctly generate random Mii data

This fixes Mario Kart 8 Deluxe, as well as the Mii Fighter mode in Super Smash Bros. Ultimate (screenshots below). These changes require a dump of the Mii system archive, which is used for the actual Mii models.

Credit to Ryujinx team for the Mii lookup tables used for generating random data, as well as the table of default Mii's that matches hardware (credit and copyright info is also cited in the source).

image
image
image
image

@@ -0,0 +1,482 @@
// Copyright 2018 yuzu emulator team

This comment has been minimized.

@ogniK5377

ogniK5377 Jul 11, 2020
Contributor

Change to 2020

}

u16 GenerateCrc16(const void* data, std::size_t size) {
int crc{};

This comment has been minimized.

@ogniK5377

ogniK5377 Jul 11, 2020
Contributor

Suggested change
int crc{};
s32 crc{};

bool MiiManager::CheckAndResetUpdateCounter(SourceFlag source_flag, u64& current_update_counter) {
if ((source_flag & SourceFlag::Database) == SourceFlag::None) {
return {};

This comment has been minimized.

@ogniK5377

ogniK5377 Jul 11, 2020
Contributor

Suggested change
return {};
return false;

bool MiiManager::IsFullDatabase() const {
// TODO(bunnei): We don't implement the Mii database, so it cannot be full
return {};

This comment has been minimized.

@ogniK5377

ogniK5377 Jul 11, 2020
Contributor

Suggested change
return {};
return false;

bool CheckAndResetUpdateCounter(SourceFlag source_flag, u64& current_update_counter);
bool IsFullDatabase() const;
u32 GetCount(SourceFlag source_flag);

This comment has been minimized.

@ogniK5377

ogniK5377 Jul 11, 2020
Contributor

Suggested change
u32 GetCount(SourceFlag source_flag);
u32 GetCount(SourceFlag source_flag) const;
return {};
}

u32 MiiManager::GetCount(SourceFlag source_flag) {

This comment has been minimized.

@ogniK5377

ogniK5377 Jul 11, 2020
Contributor

Suggested change
u32 MiiManager::GetCount(SourceFlag source_flag) {
u32 MiiManager::GetCount(SourceFlag source_flag) const {
return count;
}

ResultVal<MiiInfo> MiiManager::UpdateLatest(const MiiInfo& /*info*/, SourceFlag source_flag) {

This comment has been minimized.

@ogniK5377

ogniK5377 Jul 11, 2020
Contributor

Suggested change
ResultVal<MiiInfo> MiiManager::UpdateLatest(const MiiInfo& /*info*/, SourceFlag source_flag) {
ResultVal<MiiInfo> MiiManager::UpdateLatest([[maybe_unused]] const MiiInfo& /*info*/, SourceFlag source_flag) {
return MakeResult<std::vector<MiiInfoElement>>(result);
}

ResultCode MiiManager::GetIndex(const MiiInfo& /*info*/, u32& index) {

This comment has been minimized.

@ogniK5377

ogniK5377 Jul 11, 2020
Contributor

Suggested change
ResultCode MiiManager::GetIndex(const MiiInfo& /*info*/, u32& index) {
ResultCode MiiManager::GetIndex([[maybe_unused]] const MiiInfo& /*info*/, u32& index) {
@@ -0,0 +1,331 @@
// Copyright 2018 yuzu emulator team

This comment has been minimized.

@ogniK5377

ogniK5377 Jul 11, 2020
Contributor

Suggested change
// Copyright 2018 yuzu emulator team
// Copyright 2020 yuzu emulator team
u32 read_size{};
ctx.WriteBuffer(SerializeArray(&MiiManager::GetInfo, offsets[1], size, read_size));
offsets[1] += read_size;
if (result->size()) {

This comment has been minimized.

@ogniK5377

ogniK5377 Jul 11, 2020
Contributor

Suggested change
if (result->size()) {
if (result->size() > 0) {
}

MiiInfo ConvertStoreDataToInfo(const MiiStoreData& data) {
MiiStoreBitFields bf{};

This comment has been minimized.

@lioncash

lioncash Jul 11, 2020
Contributor

Suggested change
MiiStoreBitFields bf{};
MiiStoreBitFields bf;

Particularly given it's being memcpy'd into completely immediately on the next line.

std::vector<MiiInfoElement> result;

if ((source_flag & SourceFlag::Default) == SourceFlag::None) {
return MakeResult<std::vector<MiiInfoElement>>(result);

This comment has been minimized.

@lioncash

lioncash Jul 11, 2020
Contributor

Suggested change
return MakeResult<std::vector<MiiInfoElement>>(result);
return MakeResult(std::move(result));
result.emplace_back(BuildDefault(index), Source::Default);
}

return MakeResult<std::vector<MiiInfoElement>>(result);

This comment has been minimized.

@lioncash

lioncash Jul 11, 2020
Contributor

Suggested change
return MakeResult<std::vector<MiiInfoElement>>(result);
return MakeResult(std::move(result));

namespace Service::Mii::RawData {

static constexpr std::array<u8, 1728> DefaultMii{

This comment has been minimized.

@lioncash

lioncash Jul 11, 2020
Contributor

These should be defined in a cpp file and be made extern const in the header, so that these don't copied entirely into every translation unit that may reference these identifiers.

@Thog
Copy link
Contributor

@Thog Thog commented Jul 11, 2020

Nice work on getting Mii support added.
When we were working on reversing Mii's for Ryujinx, we guessed a significant amount of the enums (names & properties) and structures, which seem to have been referenced here directly from Ryujinx code as well.

It would be appreciated if the appropriate license statements could be added to the top of those files as well.

Otherwise the code looks fine 👍

…ndom and default miis.
@bunnei
Copy link
Contributor Author

@bunnei bunnei commented Jul 12, 2020

@Thog thanks for taking a look. Yes, sorry, several of the enum definitions were from Ryujinx. However, these were largely unused, and considering we have not independently verified them, I have just gone ahead and removed these.

@bunnei bunnei force-pushed the bunnei:mii-rewrite branch from 677b88f to e706501 Jul 12, 2020
@bunnei bunnei merged commit 3bbf446 into yuzu-emu:master Jul 17, 2020
6 checks passed
6 checks passed
license/cla Contributor License Agreement is signed.
Details
yuzu verify Build #20200712.1 succeeded
Details
yuzu verify (build standard linux) build standard linux succeeded
Details
yuzu verify (build standard windows) build standard windows succeeded
Details
yuzu verify (build testing windows) build testing windows succeeded
Details
yuzu verify (format clang) format clang succeeded
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.