From e05e6853faf8563702963f384fb1486cda77c841 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 17 Mar 2022 03:01:03 -0400 Subject: [PATCH 1/7] applets: Rename Mii to MiiEdit --- src/core/CMakeLists.txt | 8 +++--- .../applets/{mii.cpp => mii_edit.cpp} | 9 +++--- .../frontend/applets/{mii.h => mii_edit.h} | 6 ++-- .../{applet_mii.cpp => applet_mii_edit.cpp} | 23 +++++++-------- .../{applet_mii.h => applet_mii_edit.h} | 10 +++---- src/core/hle/service/am/applets/applets.cpp | 28 +++++++++---------- src/core/hle/service/am/applets/applets.h | 8 +++--- src/yuzu/main.cpp | 4 +-- 8 files changed, 49 insertions(+), 47 deletions(-) rename src/core/frontend/applets/{mii.cpp => mii_edit.cpp} (68%) rename src/core/frontend/applets/{mii.h => mii_edit.h} (87%) rename src/core/hle/service/am/applets/{applet_mii.cpp => applet_mii_edit.cpp} (81%) rename src/core/hle/service/am/applets/{applet_mii.h => applet_mii_edit.h} (89%) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 1d4e92edb..f7dd4294f 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -122,8 +122,8 @@ add_library(core STATIC frontend/applets/error.h frontend/applets/general_frontend.cpp frontend/applets/general_frontend.h - frontend/applets/mii.cpp - frontend/applets/mii.h + frontend/applets/mii_edit.cpp + frontend/applets/mii_edit.h frontend/applets/profile_select.cpp frontend/applets/profile_select.h frontend/applets/software_keyboard.cpp @@ -306,8 +306,8 @@ add_library(core STATIC hle/service/am/applets/applet_error.h hle/service/am/applets/applet_general_backend.cpp hle/service/am/applets/applet_general_backend.h - hle/service/am/applets/applet_mii.cpp - hle/service/am/applets/applet_mii.h + hle/service/am/applets/applet_mii_edit.cpp + hle/service/am/applets/applet_mii_edit.h hle/service/am/applets/applet_profile_select.cpp hle/service/am/applets/applet_profile_select.h hle/service/am/applets/applet_software_keyboard.cpp diff --git a/src/core/frontend/applets/mii.cpp b/src/core/frontend/applets/mii_edit.cpp similarity index 68% rename from src/core/frontend/applets/mii.cpp rename to src/core/frontend/applets/mii_edit.cpp index 1c05ff412..948d66f3d 100644 --- a/src/core/frontend/applets/mii.cpp +++ b/src/core/frontend/applets/mii_edit.cpp @@ -3,16 +3,17 @@ // Refer to the license.txt file included. #include "common/logging/log.h" -#include "core/frontend/applets/mii.h" +#include "core/frontend/applets/mii_edit.h" namespace Core::Frontend { -MiiApplet::~MiiApplet() = default; +MiiEditApplet::~MiiEditApplet() = default; -void DefaultMiiApplet::ShowMii( +void DefaultMiiEditApplet::ShowMii( const MiiParameters& parameters, const std::function callback) const { - LOG_INFO(Service_HID, "(STUBBED) called"); + LOG_WARNING(Service_AM, "(STUBBED) called"); + callback(parameters); } diff --git a/src/core/frontend/applets/mii.h b/src/core/frontend/applets/mii_edit.h similarity index 87% rename from src/core/frontend/applets/mii.h rename to src/core/frontend/applets/mii_edit.h index 11ba8a359..0d5bb69a2 100644 --- a/src/core/frontend/applets/mii.h +++ b/src/core/frontend/applets/mii_edit.h @@ -15,16 +15,16 @@ struct MiiParameters { Service::Mii::MiiInfo mii_data{}; }; -class MiiApplet { +class MiiEditApplet { public: - virtual ~MiiApplet(); + virtual ~MiiEditApplet(); virtual void ShowMii(const MiiParameters& parameters, const std::function callback) const = 0; }; -class DefaultMiiApplet final : public MiiApplet { +class DefaultMiiEditApplet final : public MiiEditApplet { public: void ShowMii(const MiiParameters& parameters, const std::function diff --git a/src/core/hle/service/am/applets/applet_mii.cpp b/src/core/hle/service/am/applets/applet_mii_edit.cpp similarity index 81% rename from src/core/hle/service/am/applets/applet_mii.cpp rename to src/core/hle/service/am/applets/applet_mii_edit.cpp index facede97e..ec57d98bd 100644 --- a/src/core/hle/service/am/applets/applet_mii.cpp +++ b/src/core/hle/service/am/applets/applet_mii_edit.cpp @@ -5,19 +5,20 @@ #include "common/assert.h" #include "common/logging/log.h" #include "core/core.h" -#include "core/frontend/applets/mii.h" +#include "core/frontend/applets/mii_edit.h" #include "core/hle/service/am/am.h" -#include "core/hle/service/am/applets/applet_mii.h" +#include "core/hle/service/am/applets/applet_mii_edit.h" +#include "core/reporter.h" namespace Service::AM::Applets { -Mii::Mii(Core::System& system_, LibraryAppletMode applet_mode_, - const Core::Frontend::MiiApplet& frontend_) +MiiEdit::MiiEdit(Core::System& system_, LibraryAppletMode applet_mode_, + const Core::Frontend::MiiEditApplet& frontend_) : Applet{system_, applet_mode_}, frontend{frontend_}, system{system_} {} -Mii::~Mii() = default; +MiiEdit::~MiiEdit() = default; -void Mii::Initialize() { +void MiiEdit::Initialize() { is_complete = false; const auto storage = broker.PopNormalDataToApplet(); @@ -29,19 +30,19 @@ void Mii::Initialize() { std::memcpy(&input_data, data.data(), sizeof(MiiAppletInput)); } -bool Mii::TransactionComplete() const { +bool MiiEdit::TransactionComplete() const { return is_complete; } -ResultCode Mii::GetStatus() const { +ResultCode MiiEdit::GetStatus() const { return ResultSuccess; } -void Mii::ExecuteInteractive() { +void MiiEdit::ExecuteInteractive() { UNREACHABLE_MSG("Unexpected interactive applet data!"); } -void Mii::Execute() { +void MiiEdit::Execute() { if (is_complete) { return; } @@ -83,7 +84,7 @@ void Mii::Execute() { } } -void Mii::DisplayCompleted(const Core::Frontend::MiiParameters& parameters) { +void MiiEdit::DisplayCompleted(const Core::Frontend::MiiParameters& parameters) { is_complete = true; std::vector reply(sizeof(AppletOutputForCharInfoEditing)); diff --git a/src/core/hle/service/am/applets/applet_mii.h b/src/core/hle/service/am/applets/applet_mii_edit.h similarity index 89% rename from src/core/hle/service/am/applets/applet_mii.h rename to src/core/hle/service/am/applets/applet_mii_edit.h index 42326bfc2..828f28da4 100644 --- a/src/core/hle/service/am/applets/applet_mii.h +++ b/src/core/hle/service/am/applets/applet_mii_edit.h @@ -63,11 +63,11 @@ struct AppletOutputForCharInfoEditing { static_assert(sizeof(AppletOutputForCharInfoEditing) == 0x80, "AppletOutputForCharInfoEditing has incorrect size."); -class Mii final : public Applet { +class MiiEdit final : public Applet { public: - explicit Mii(Core::System& system_, LibraryAppletMode applet_mode_, - const Core::Frontend::MiiApplet& frontend_); - ~Mii() override; + explicit MiiEdit(Core::System& system_, LibraryAppletMode applet_mode_, + const Core::Frontend::MiiEditApplet& frontend_); + ~MiiEdit() override; void Initialize() override; @@ -79,7 +79,7 @@ public: void DisplayCompleted(const Core::Frontend::MiiParameters& parameters); private: - const Core::Frontend::MiiApplet& frontend; + const Core::Frontend::MiiEditApplet& frontend; MiiAppletInput input_data{}; AppletOutputForCharInfoEditing output_data{}; diff --git a/src/core/hle/service/am/applets/applets.cpp b/src/core/hle/service/am/applets/applets.cpp index 79e62679d..1f4c9786a 100644 --- a/src/core/hle/service/am/applets/applets.cpp +++ b/src/core/hle/service/am/applets/applets.cpp @@ -9,7 +9,7 @@ #include "core/frontend/applets/controller.h" #include "core/frontend/applets/error.h" #include "core/frontend/applets/general_frontend.h" -#include "core/frontend/applets/mii.h" +#include "core/frontend/applets/mii_edit.h" #include "core/frontend/applets/profile_select.h" #include "core/frontend/applets/software_keyboard.h" #include "core/frontend/applets/web_browser.h" @@ -20,7 +20,7 @@ #include "core/hle/service/am/applets/applet_controller.h" #include "core/hle/service/am/applets/applet_error.h" #include "core/hle/service/am/applets/applet_general_backend.h" -#include "core/hle/service/am/applets/applet_mii.h" +#include "core/hle/service/am/applets/applet_mii_edit.h" #include "core/hle/service/am/applets/applet_profile_select.h" #include "core/hle/service/am/applets/applet_software_keyboard.h" #include "core/hle/service/am/applets/applet_web_browser.h" @@ -173,12 +173,12 @@ void Applet::Initialize() { AppletFrontendSet::AppletFrontendSet() = default; AppletFrontendSet::AppletFrontendSet(ControllerApplet controller_applet, ErrorApplet error_applet, + MiiEdit mii_edit_, ParentalControlsApplet parental_controls_applet, - MiiApplet mii_applet, PhotoViewer photo_viewer_, - ProfileSelect profile_select_, + PhotoViewer photo_viewer_, ProfileSelect profile_select_, SoftwareKeyboard software_keyboard_, WebBrowser web_browser_) : controller{std::move(controller_applet)}, error{std::move(error_applet)}, - parental_controls{std::move(parental_controls_applet)}, mii{std::move(mii_applet)}, + mii_edit{std::move(mii_edit_)}, parental_controls{std::move(parental_controls_applet)}, photo_viewer{std::move(photo_viewer_)}, profile_select{std::move(profile_select_)}, software_keyboard{std::move(software_keyboard_)}, web_browser{std::move(web_browser_)} {} @@ -205,12 +205,12 @@ void AppletManager::SetAppletFrontendSet(AppletFrontendSet set) { frontend.error = std::move(set.error); } - if (set.parental_controls != nullptr) { - frontend.parental_controls = std::move(set.parental_controls); + if (set.mii_edit != nullptr) { + frontend.mii_edit = std::move(set.mii_edit); } - if (set.mii != nullptr) { - frontend.mii = std::move(set.mii); + if (set.parental_controls != nullptr) { + frontend.parental_controls = std::move(set.parental_controls); } if (set.photo_viewer != nullptr) { @@ -245,15 +245,15 @@ void AppletManager::SetDefaultAppletsIfMissing() { frontend.error = std::make_unique(); } + if (frontend.mii_edit == nullptr) { + frontend.mii_edit = std::make_unique(); + } + if (frontend.parental_controls == nullptr) { frontend.parental_controls = std::make_unique(); } - if (frontend.mii == nullptr) { - frontend.mii = std::make_unique(); - } - if (frontend.photo_viewer == nullptr) { frontend.photo_viewer = std::make_unique(); } @@ -289,7 +289,7 @@ std::shared_ptr AppletManager::GetApplet(AppletId id, LibraryAppletMode case AppletId::SoftwareKeyboard: return std::make_shared(system, mode, *frontend.software_keyboard); case AppletId::MiiEdit: - return std::make_shared(system, mode, *frontend.mii); + return std::make_shared(system, mode, *frontend.mii_edit); case AppletId::Web: case AppletId::Shop: case AppletId::OfflineWeb: diff --git a/src/core/hle/service/am/applets/applets.h b/src/core/hle/service/am/applets/applets.h index 0c44aec79..50a7bdceb 100644 --- a/src/core/hle/service/am/applets/applets.h +++ b/src/core/hle/service/am/applets/applets.h @@ -20,8 +20,8 @@ namespace Core::Frontend { class ControllerApplet; class ECommerceApplet; class ErrorApplet; +class MiiEditApplet; class ParentalControlsApplet; -class MiiApplet; class PhotoViewerApplet; class ProfileSelectApplet; class SoftwareKeyboardApplet; @@ -179,8 +179,8 @@ protected: struct AppletFrontendSet { using ControllerApplet = std::unique_ptr; using ErrorApplet = std::unique_ptr; + using MiiEdit = std::unique_ptr; using ParentalControlsApplet = std::unique_ptr; - using MiiApplet = std::unique_ptr; using PhotoViewer = std::unique_ptr; using ProfileSelect = std::unique_ptr; using SoftwareKeyboard = std::unique_ptr; @@ -188,7 +188,7 @@ struct AppletFrontendSet { AppletFrontendSet(); AppletFrontendSet(ControllerApplet controller_applet, ErrorApplet error_applet, - ParentalControlsApplet parental_controls_applet, MiiApplet mii_applet, + MiiEdit mii_edit_, ParentalControlsApplet parental_controls_applet, PhotoViewer photo_viewer_, ProfileSelect profile_select_, SoftwareKeyboard software_keyboard_, WebBrowser web_browser_); ~AppletFrontendSet(); @@ -201,8 +201,8 @@ struct AppletFrontendSet { ControllerApplet controller; ErrorApplet error; + MiiEdit mii_edit; ParentalControlsApplet parental_controls; - MiiApplet mii; PhotoViewer photo_viewer; ProfileSelect profile_select; SoftwareKeyboard software_keyboard; diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index ecd2f9f24..f2182d901 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -24,7 +24,7 @@ #include "core/file_sys/vfs_real.h" #include "core/frontend/applets/controller.h" #include "core/frontend/applets/general_frontend.h" -#include "core/frontend/applets/mii.h" +#include "core/frontend/applets/mii_edit.h" #include "core/frontend/applets/software_keyboard.h" #include "core/hid/emulated_controller.h" #include "core/hid/hid_core.h" @@ -1280,8 +1280,8 @@ bool GMainWindow::LoadROM(const QString& filename, u64 program_id, std::size_t p system->SetAppletFrontendSet({ std::make_unique(*this), // Controller Selector std::make_unique(*this), // Error Display + nullptr, // Mii Editor nullptr, // Parental Controls - nullptr, // Mii editor nullptr, // Photo Viewer std::make_unique(*this), // Profile Selector std::make_unique(*this), // Software Keyboard From aa44ef7b64ad5b00a1e6da94d06fb6c3ecd82582 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 17 Mar 2022 03:48:31 -0400 Subject: [PATCH 2/7] service: Move mii enums and structs into its own file Moves these into types.h, since other files also make use of these types. --- src/core/frontend/applets/mii_edit.h | 2 +- src/core/hle/service/mii/mii_manager.cpp | 3 +- src/core/hle/service/mii/mii_manager.h | 303 +--------------------- src/core/hle/service/mii/raw_data.h | 2 +- src/core/hle/service/mii/types.h | 307 ++++++++++++++++++++++- src/core/hle/service/nfp/nfp.cpp | 1 + src/core/hle/service/nfp/nfp.h | 2 +- 7 files changed, 312 insertions(+), 308 deletions(-) diff --git a/src/core/frontend/applets/mii_edit.h b/src/core/frontend/applets/mii_edit.h index 0d5bb69a2..247ccd461 100644 --- a/src/core/frontend/applets/mii_edit.h +++ b/src/core/frontend/applets/mii_edit.h @@ -6,7 +6,7 @@ #include -#include "core/hle/service/mii/mii_manager.h" +#include "core/hle/service/mii/types.h" namespace Core::Frontend { diff --git a/src/core/hle/service/mii/mii_manager.cpp b/src/core/hle/service/mii/mii_manager.cpp index 0a57c3cde..188231615 100644 --- a/src/core/hle/service/mii/mii_manager.cpp +++ b/src/core/hle/service/mii/mii_manager.cpp @@ -1,4 +1,4 @@ -// Copyright 2020 yuzu emulator team +// Copyright 2020 yuzu Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. @@ -12,7 +12,6 @@ #include "core/hle/service/acc/profile_manager.h" #include "core/hle/service/mii/mii_manager.h" #include "core/hle/service/mii/raw_data.h" -#include "core/hle/service/mii/types.h" namespace Service::Mii { diff --git a/src/core/hle/service/mii/mii_manager.h b/src/core/hle/service/mii/mii_manager.h index 6999d15b1..5d134c425 100644 --- a/src/core/hle/service/mii/mii_manager.h +++ b/src/core/hle/service/mii/mii_manager.h @@ -1,315 +1,16 @@ -// Copyright 2020 yuzu emulator team +// Copyright 2020 yuzu Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. #pragma once -#include #include -#include "common/bit_field.h" -#include "common/common_funcs.h" -#include "common/uuid.h" + #include "core/hle/result.h" #include "core/hle/service/mii/types.h" namespace Service::Mii { -enum class Source : u32 { - Database = 0, - Default = 1, - Account = 2, - Friend = 3, -}; - -enum class SourceFlag : u32 { - None = 0, - Database = 1 << 0, - Default = 1 << 1, -}; -DECLARE_ENUM_FLAG_OPERATORS(SourceFlag); - -struct MiiInfo { - Common::UUID uuid; - std::array name; - u8 font_region; - u8 favorite_color; - u8 gender; - u8 height; - u8 build; - u8 type; - u8 region_move; - u8 faceline_type; - u8 faceline_color; - u8 faceline_wrinkle; - u8 faceline_make; - u8 hair_type; - u8 hair_color; - u8 hair_flip; - u8 eye_type; - u8 eye_color; - u8 eye_scale; - u8 eye_aspect; - u8 eye_rotate; - u8 eye_x; - u8 eye_y; - u8 eyebrow_type; - u8 eyebrow_color; - u8 eyebrow_scale; - u8 eyebrow_aspect; - u8 eyebrow_rotate; - u8 eyebrow_x; - u8 eyebrow_y; - u8 nose_type; - u8 nose_scale; - u8 nose_y; - u8 mouth_type; - u8 mouth_color; - u8 mouth_scale; - u8 mouth_aspect; - u8 mouth_y; - u8 beard_color; - u8 beard_type; - u8 mustache_type; - u8 mustache_scale; - u8 mustache_y; - u8 glasses_type; - u8 glasses_color; - u8 glasses_scale; - u8 glasses_y; - u8 mole_type; - u8 mole_scale; - u8 mole_x; - u8 mole_y; - u8 padding; - - std::u16string Name() const; -}; -static_assert(sizeof(MiiInfo) == 0x58, "MiiInfo has incorrect size."); -static_assert(std::has_unique_object_representations_v, - "All bits of MiiInfo must contribute to its value."); - -#pragma pack(push, 4) - -struct MiiInfoElement { - MiiInfoElement(const MiiInfo& info_, Source source_) : info{info_}, source{source_} {} - - MiiInfo info{}; - Source source{}; -}; -static_assert(sizeof(MiiInfoElement) == 0x5c, "MiiInfoElement has incorrect size."); - -struct MiiStoreBitFields { - union { - u32 word_0{}; - - BitField<0, 8, u32> hair_type; - BitField<8, 7, u32> height; - BitField<15, 1, u32> mole_type; - BitField<16, 7, u32> build; - BitField<23, 1, HairFlip> hair_flip; - BitField<24, 7, u32> hair_color; - BitField<31, 1, u32> type; - }; - - union { - u32 word_1{}; - - BitField<0, 7, u32> eye_color; - BitField<7, 1, Gender> gender; - BitField<8, 7, u32> eyebrow_color; - BitField<16, 7, u32> mouth_color; - BitField<24, 7, u32> beard_color; - }; - - union { - u32 word_2{}; - - BitField<0, 7, u32> glasses_color; - BitField<8, 6, u32> eye_type; - BitField<14, 2, u32> region_move; - BitField<16, 6, u32> mouth_type; - BitField<22, 2, FontRegion> font_region; - BitField<24, 5, u32> eye_y; - BitField<29, 3, u32> glasses_scale; - }; - - union { - u32 word_3{}; - - BitField<0, 5, u32> eyebrow_type; - BitField<5, 3, MustacheType> mustache_type; - BitField<8, 5, u32> nose_type; - BitField<13, 3, BeardType> beard_type; - BitField<16, 5, u32> nose_y; - BitField<21, 3, u32> mouth_aspect; - BitField<24, 5, u32> mouth_y; - BitField<29, 3, u32> eyebrow_aspect; - }; - - union { - u32 word_4{}; - - BitField<0, 5, u32> mustache_y; - BitField<5, 3, u32> eye_rotate; - BitField<8, 5, u32> glasses_y; - BitField<13, 3, u32> eye_aspect; - BitField<16, 5, u32> mole_x; - BitField<21, 3, u32> eye_scale; - BitField<24, 5, u32> mole_y; - }; - - union { - u32 word_5{}; - - BitField<0, 5, u32> glasses_type; - BitField<8, 4, u32> favorite_color; - BitField<12, 4, u32> faceline_type; - BitField<16, 4, u32> faceline_color; - BitField<20, 4, u32> faceline_wrinkle; - BitField<24, 4, u32> faceline_makeup; - BitField<28, 4, u32> eye_x; - }; - - union { - u32 word_6{}; - - BitField<0, 4, u32> eyebrow_scale; - BitField<4, 4, u32> eyebrow_rotate; - BitField<8, 4, u32> eyebrow_x; - BitField<12, 4, u32> eyebrow_y; - BitField<16, 4, u32> nose_scale; - BitField<20, 4, u32> mouth_scale; - BitField<24, 4, u32> mustache_scale; - BitField<28, 4, u32> mole_scale; - }; -}; -static_assert(sizeof(MiiStoreBitFields) == 0x1c, "MiiStoreBitFields has incorrect size."); -static_assert(std::is_trivially_copyable_v, - "MiiStoreBitFields is not trivially copyable."); - -struct MiiStoreData { - using Name = std::array; - - MiiStoreData(); - MiiStoreData(const Name& name, const MiiStoreBitFields& bit_fields, - const Common::UUID& user_id); - - // This corresponds to the above structure MiiStoreBitFields. I did it like this because the - // BitField<> type makes this (and any thing that contains it) not trivially copyable, which is - // not suitable for our uses. - struct { - std::array data{}; - static_assert(sizeof(MiiStoreBitFields) == sizeof(data), "data field has incorrect size."); - - Name name{}; - Common::UUID uuid{}; - } data; - - u16 data_crc{}; - u16 device_crc{}; -}; -static_assert(sizeof(MiiStoreData) == 0x44, "MiiStoreData has incorrect size."); - -struct MiiStoreDataElement { - MiiStoreData data{}; - Source source{}; -}; -static_assert(sizeof(MiiStoreDataElement) == 0x48, "MiiStoreDataElement has incorrect size."); - -struct MiiDatabase { - u32 magic{}; // 'NFDB' - std::array miis{}; - INSERT_PADDING_BYTES(1); - u8 count{}; - u16 crc{}; -}; -static_assert(sizeof(MiiDatabase) == 0x1A98, "MiiDatabase has incorrect size."); - -struct RandomMiiValues { - std::array values{}; -}; -static_assert(sizeof(RandomMiiValues) == 0xbc, "RandomMiiValues has incorrect size."); - -struct RandomMiiData4 { - Gender gender{}; - Age age{}; - Race race{}; - u32 values_count{}; - std::array values{}; -}; -static_assert(sizeof(RandomMiiData4) == 0xcc, "RandomMiiData4 has incorrect size."); - -struct RandomMiiData3 { - u32 arg_1; - u32 arg_2; - u32 values_count; - std::array values{}; -}; -static_assert(sizeof(RandomMiiData3) == 0xc8, "RandomMiiData3 has incorrect size."); - -struct RandomMiiData2 { - u32 arg_1; - u32 values_count; - std::array values{}; -}; -static_assert(sizeof(RandomMiiData2) == 0xc4, "RandomMiiData2 has incorrect size."); - -struct DefaultMii { - u32 face_type{}; - u32 face_color{}; - u32 face_wrinkle{}; - u32 face_makeup{}; - u32 hair_type{}; - u32 hair_color{}; - u32 hair_flip{}; - u32 eye_type{}; - u32 eye_color{}; - u32 eye_scale{}; - u32 eye_aspect{}; - u32 eye_rotate{}; - u32 eye_x{}; - u32 eye_y{}; - u32 eyebrow_type{}; - u32 eyebrow_color{}; - u32 eyebrow_scale{}; - u32 eyebrow_aspect{}; - u32 eyebrow_rotate{}; - u32 eyebrow_x{}; - u32 eyebrow_y{}; - u32 nose_type{}; - u32 nose_scale{}; - u32 nose_y{}; - u32 mouth_type{}; - u32 mouth_color{}; - u32 mouth_scale{}; - u32 mouth_aspect{}; - u32 mouth_y{}; - u32 mustache_type{}; - u32 beard_type{}; - u32 beard_color{}; - u32 mustache_scale{}; - u32 mustache_y{}; - u32 glasses_type{}; - u32 glasses_color{}; - u32 glasses_scale{}; - u32 glasses_y{}; - u32 mole_type{}; - u32 mole_scale{}; - u32 mole_x{}; - u32 mole_y{}; - u32 height{}; - u32 weight{}; - Gender gender{}; - u32 favorite_color{}; - u32 region{}; - FontRegion font_region{}; - u32 type{}; - INSERT_PADDING_WORDS(5); -}; -static_assert(sizeof(DefaultMii) == 0xd8, "MiiStoreData has incorrect size."); - -#pragma pack(pop) - // The Mii manager is responsible for loading and storing the Miis to the database in NAND along // with providing an easy interface for HLE emulation of the mii service. class MiiManager { diff --git a/src/core/hle/service/mii/raw_data.h b/src/core/hle/service/mii/raw_data.h index bd90c2162..2e39c0d4f 100644 --- a/src/core/hle/service/mii/raw_data.h +++ b/src/core/hle/service/mii/raw_data.h @@ -6,7 +6,7 @@ #include -#include "core/hle/service/mii/mii_manager.h" +#include "core/hle/service/mii/types.h" namespace Service::Mii::RawData { diff --git a/src/core/hle/service/mii/types.h b/src/core/hle/service/mii/types.h index d65a1055e..5580b8c6a 100644 --- a/src/core/hle/service/mii/types.h +++ b/src/core/hle/service/mii/types.h @@ -1,11 +1,16 @@ -// Copyright 2020 yuzu emulator team +// Copyright 2020 yuzu Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. #pragma once +#include +#include + +#include "common/bit_field.h" #include "common/common_funcs.h" #include "common/common_types.h" +#include "common/uuid.h" namespace Service::Mii { @@ -25,7 +30,11 @@ enum class BeardType : u32 { Beard5, }; -enum class BeardAndMustacheFlag : u32 { Beard = 1, Mustache, All = Beard | Mustache }; +enum class BeardAndMustacheFlag : u32 { + Beard = 1, + Mustache, + All = Beard | Mustache, +}; DECLARE_ENUM_FLAG_OPERATORS(BeardAndMustacheFlag); enum class FontRegion : u32 { @@ -64,4 +73,298 @@ enum class Race : u32 { All, }; +enum class Source : u32 { + Database = 0, + Default = 1, + Account = 2, + Friend = 3, +}; + +enum class SourceFlag : u32 { + None = 0, + Database = 1 << 0, + Default = 1 << 1, +}; +DECLARE_ENUM_FLAG_OPERATORS(SourceFlag); + +struct MiiInfo { + Common::UUID uuid; + std::array name; + u8 font_region; + u8 favorite_color; + u8 gender; + u8 height; + u8 build; + u8 type; + u8 region_move; + u8 faceline_type; + u8 faceline_color; + u8 faceline_wrinkle; + u8 faceline_make; + u8 hair_type; + u8 hair_color; + u8 hair_flip; + u8 eye_type; + u8 eye_color; + u8 eye_scale; + u8 eye_aspect; + u8 eye_rotate; + u8 eye_x; + u8 eye_y; + u8 eyebrow_type; + u8 eyebrow_color; + u8 eyebrow_scale; + u8 eyebrow_aspect; + u8 eyebrow_rotate; + u8 eyebrow_x; + u8 eyebrow_y; + u8 nose_type; + u8 nose_scale; + u8 nose_y; + u8 mouth_type; + u8 mouth_color; + u8 mouth_scale; + u8 mouth_aspect; + u8 mouth_y; + u8 beard_color; + u8 beard_type; + u8 mustache_type; + u8 mustache_scale; + u8 mustache_y; + u8 glasses_type; + u8 glasses_color; + u8 glasses_scale; + u8 glasses_y; + u8 mole_type; + u8 mole_scale; + u8 mole_x; + u8 mole_y; + u8 padding; +}; +static_assert(sizeof(MiiInfo) == 0x58, "MiiInfo has incorrect size."); +static_assert(std::has_unique_object_representations_v, + "All bits of MiiInfo must contribute to its value."); + +#pragma pack(push, 4) + +struct MiiInfoElement { + MiiInfoElement(const MiiInfo& info_, Source source_) : info{info_}, source{source_} {} + + MiiInfo info{}; + Source source{}; +}; +static_assert(sizeof(MiiInfoElement) == 0x5c, "MiiInfoElement has incorrect size."); + +struct MiiStoreBitFields { + union { + u32 word_0{}; + + BitField<0, 8, u32> hair_type; + BitField<8, 7, u32> height; + BitField<15, 1, u32> mole_type; + BitField<16, 7, u32> build; + BitField<23, 1, HairFlip> hair_flip; + BitField<24, 7, u32> hair_color; + BitField<31, 1, u32> type; + }; + + union { + u32 word_1{}; + + BitField<0, 7, u32> eye_color; + BitField<7, 1, Gender> gender; + BitField<8, 7, u32> eyebrow_color; + BitField<16, 7, u32> mouth_color; + BitField<24, 7, u32> beard_color; + }; + + union { + u32 word_2{}; + + BitField<0, 7, u32> glasses_color; + BitField<8, 6, u32> eye_type; + BitField<14, 2, u32> region_move; + BitField<16, 6, u32> mouth_type; + BitField<22, 2, FontRegion> font_region; + BitField<24, 5, u32> eye_y; + BitField<29, 3, u32> glasses_scale; + }; + + union { + u32 word_3{}; + + BitField<0, 5, u32> eyebrow_type; + BitField<5, 3, MustacheType> mustache_type; + BitField<8, 5, u32> nose_type; + BitField<13, 3, BeardType> beard_type; + BitField<16, 5, u32> nose_y; + BitField<21, 3, u32> mouth_aspect; + BitField<24, 5, u32> mouth_y; + BitField<29, 3, u32> eyebrow_aspect; + }; + + union { + u32 word_4{}; + + BitField<0, 5, u32> mustache_y; + BitField<5, 3, u32> eye_rotate; + BitField<8, 5, u32> glasses_y; + BitField<13, 3, u32> eye_aspect; + BitField<16, 5, u32> mole_x; + BitField<21, 3, u32> eye_scale; + BitField<24, 5, u32> mole_y; + }; + + union { + u32 word_5{}; + + BitField<0, 5, u32> glasses_type; + BitField<8, 4, u32> favorite_color; + BitField<12, 4, u32> faceline_type; + BitField<16, 4, u32> faceline_color; + BitField<20, 4, u32> faceline_wrinkle; + BitField<24, 4, u32> faceline_makeup; + BitField<28, 4, u32> eye_x; + }; + + union { + u32 word_6{}; + + BitField<0, 4, u32> eyebrow_scale; + BitField<4, 4, u32> eyebrow_rotate; + BitField<8, 4, u32> eyebrow_x; + BitField<12, 4, u32> eyebrow_y; + BitField<16, 4, u32> nose_scale; + BitField<20, 4, u32> mouth_scale; + BitField<24, 4, u32> mustache_scale; + BitField<28, 4, u32> mole_scale; + }; +}; +static_assert(sizeof(MiiStoreBitFields) == 0x1c, "MiiStoreBitFields has incorrect size."); +static_assert(std::is_trivially_copyable_v, + "MiiStoreBitFields is not trivially copyable."); + +struct MiiStoreData { + using Name = std::array; + + MiiStoreData(); + MiiStoreData(const Name& name, const MiiStoreBitFields& bit_fields, + const Common::UUID& user_id); + + // This corresponds to the above structure MiiStoreBitFields. I did it like this because the + // BitField<> type makes this (and any thing that contains it) not trivially copyable, which is + // not suitable for our uses. + struct { + std::array data{}; + static_assert(sizeof(MiiStoreBitFields) == sizeof(data), "data field has incorrect size."); + + Name name{}; + Common::UUID uuid{}; + } data; + + u16 data_crc{}; + u16 device_crc{}; +}; +static_assert(sizeof(MiiStoreData) == 0x44, "MiiStoreData has incorrect size."); + +struct MiiStoreDataElement { + MiiStoreData data{}; + Source source{}; +}; +static_assert(sizeof(MiiStoreDataElement) == 0x48, "MiiStoreDataElement has incorrect size."); + +struct MiiDatabase { + u32 magic{}; // 'NFDB' + std::array miis{}; + INSERT_PADDING_BYTES(1); + u8 count{}; + u16 crc{}; +}; +static_assert(sizeof(MiiDatabase) == 0x1A98, "MiiDatabase has incorrect size."); + +struct RandomMiiValues { + std::array values{}; +}; +static_assert(sizeof(RandomMiiValues) == 0xbc, "RandomMiiValues has incorrect size."); + +struct RandomMiiData4 { + Gender gender{}; + Age age{}; + Race race{}; + u32 values_count{}; + std::array values{}; +}; +static_assert(sizeof(RandomMiiData4) == 0xcc, "RandomMiiData4 has incorrect size."); + +struct RandomMiiData3 { + u32 arg_1; + u32 arg_2; + u32 values_count; + std::array values{}; +}; +static_assert(sizeof(RandomMiiData3) == 0xc8, "RandomMiiData3 has incorrect size."); + +struct RandomMiiData2 { + u32 arg_1; + u32 values_count; + std::array values{}; +}; +static_assert(sizeof(RandomMiiData2) == 0xc4, "RandomMiiData2 has incorrect size."); + +struct DefaultMii { + u32 face_type{}; + u32 face_color{}; + u32 face_wrinkle{}; + u32 face_makeup{}; + u32 hair_type{}; + u32 hair_color{}; + u32 hair_flip{}; + u32 eye_type{}; + u32 eye_color{}; + u32 eye_scale{}; + u32 eye_aspect{}; + u32 eye_rotate{}; + u32 eye_x{}; + u32 eye_y{}; + u32 eyebrow_type{}; + u32 eyebrow_color{}; + u32 eyebrow_scale{}; + u32 eyebrow_aspect{}; + u32 eyebrow_rotate{}; + u32 eyebrow_x{}; + u32 eyebrow_y{}; + u32 nose_type{}; + u32 nose_scale{}; + u32 nose_y{}; + u32 mouth_type{}; + u32 mouth_color{}; + u32 mouth_scale{}; + u32 mouth_aspect{}; + u32 mouth_y{}; + u32 mustache_type{}; + u32 beard_type{}; + u32 beard_color{}; + u32 mustache_scale{}; + u32 mustache_y{}; + u32 glasses_type{}; + u32 glasses_color{}; + u32 glasses_scale{}; + u32 glasses_y{}; + u32 mole_type{}; + u32 mole_scale{}; + u32 mole_x{}; + u32 mole_y{}; + u32 height{}; + u32 weight{}; + Gender gender{}; + u32 favorite_color{}; + u32 region{}; + FontRegion font_region{}; + u32 type{}; + INSERT_PADDING_WORDS(5); +}; +static_assert(sizeof(DefaultMii) == 0xd8, "MiiStoreData has incorrect size."); + +#pragma pack(pop) + } // namespace Service::Mii diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp index 513107715..dab99b675 100644 --- a/src/core/hle/service/nfp/nfp.cpp +++ b/src/core/hle/service/nfp/nfp.cpp @@ -12,6 +12,7 @@ #include "core/hid/hid_types.h" #include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" +#include "core/hle/service/mii/mii_manager.h" #include "core/hle/service/nfp/nfp.h" #include "core/hle/service/nfp/nfp_user.h" diff --git a/src/core/hle/service/nfp/nfp.h b/src/core/hle/service/nfp/nfp.h index 022f13b29..ab652f635 100644 --- a/src/core/hle/service/nfp/nfp.h +++ b/src/core/hle/service/nfp/nfp.h @@ -9,7 +9,7 @@ #include "common/common_funcs.h" #include "core/hle/service/kernel_helpers.h" -#include "core/hle/service/mii/mii_manager.h" +#include "core/hle/service/mii/types.h" #include "core/hle/service/service.h" namespace Kernel { From 7c44a4ede39a5e9cc3cb6484a874bede2559a731 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 17 Mar 2022 03:52:48 -0400 Subject: [PATCH 3/7] applets/mii: Move MiiEdit applet types into its own file --- src/core/CMakeLists.txt | 1 + .../service/am/applets/applet_mii_edit.cpp | 3 +- .../hle/service/am/applets/applet_mii_edit.h | 58 ++--------------- .../am/applets/applet_mii_edit_types.h | 62 +++++++++++++++++++ 4 files changed, 70 insertions(+), 54 deletions(-) create mode 100644 src/core/hle/service/am/applets/applet_mii_edit_types.h diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index f7dd4294f..a6f442316 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -308,6 +308,7 @@ add_library(core STATIC hle/service/am/applets/applet_general_backend.h hle/service/am/applets/applet_mii_edit.cpp hle/service/am/applets/applet_mii_edit.h + hle/service/am/applets/applet_mii_edit_types.h hle/service/am/applets/applet_profile_select.cpp hle/service/am/applets/applet_profile_select.h hle/service/am/applets/applet_software_keyboard.cpp diff --git a/src/core/hle/service/am/applets/applet_mii_edit.cpp b/src/core/hle/service/am/applets/applet_mii_edit.cpp index ec57d98bd..769c3c3eb 100644 --- a/src/core/hle/service/am/applets/applet_mii_edit.cpp +++ b/src/core/hle/service/am/applets/applet_mii_edit.cpp @@ -8,6 +8,7 @@ #include "core/frontend/applets/mii_edit.h" #include "core/hle/service/am/am.h" #include "core/hle/service/am/applets/applet_mii_edit.h" +#include "core/hle/service/mii/mii_manager.h" #include "core/reporter.h" namespace Service::AM::Applets { @@ -89,7 +90,7 @@ void MiiEdit::DisplayCompleted(const Core::Frontend::MiiParameters& parameters) std::vector reply(sizeof(AppletOutputForCharInfoEditing)); output_data = { - .result = ResultSuccess, + .result = 0, .mii_data = parameters.mii_data, }; diff --git a/src/core/hle/service/am/applets/applet_mii_edit.h b/src/core/hle/service/am/applets/applet_mii_edit.h index 828f28da4..2b4b27c8f 100644 --- a/src/core/hle/service/am/applets/applet_mii_edit.h +++ b/src/core/hle/service/am/applets/applet_mii_edit.h @@ -4,65 +4,16 @@ #pragma once -#include - #include "core/hle/result.h" +#include "core/hle/service/am/applets/applet_mii_edit_types.h" #include "core/hle/service/am/applets/applets.h" -#include "core/hle/service/mii/mii_manager.h" namespace Core { class System; -} +} // namespace Core namespace Service::AM::Applets { -// This is nn::mii::AppletMode -enum class MiiAppletMode : u32 { - ShowMiiEdit = 0, - AppendMii = 1, - AppendMiiImage = 2, - UpdateMiiImage = 3, - CreateMii = 4, - EditMii = 5, -}; - -struct MiiCharInfo { - Service::Mii::MiiInfo mii_data{}; - INSERT_PADDING_BYTES(0x28); -}; -static_assert(sizeof(MiiCharInfo) == 0x80, "MiiCharInfo has incorrect size."); - -// This is nn::mii::AppletInput -struct MiiAppletInput { - s32 version{}; - MiiAppletMode applet_mode{}; - u32 special_mii_key_code{}; - union { - std::array valid_uuid; - MiiCharInfo mii_char_info; - }; - Common::UUID used_uuid; - INSERT_PADDING_BYTES(0x64); -}; -static_assert(sizeof(MiiAppletInput) == 0x100, "MiiAppletInput has incorrect size."); - -// This is nn::mii::AppletOutput -struct MiiAppletOutput { - ResultCode result{ResultSuccess}; - s32 index{}; - INSERT_PADDING_BYTES(0x18); -}; -static_assert(sizeof(MiiAppletOutput) == 0x20, "MiiAppletOutput has incorrect size."); - -// This is nn::mii::AppletOutputForCharInfoEditing -struct AppletOutputForCharInfoEditing { - ResultCode result{ResultSuccess}; - Service::Mii::MiiInfo mii_data{}; - INSERT_PADDING_BYTES(0x24); -}; -static_assert(sizeof(AppletOutputForCharInfoEditing) == 0x80, - "AppletOutputForCharInfoEditing has incorrect size."); - class MiiEdit final : public Applet { public: explicit MiiEdit(Core::System& system_, LibraryAppletMode applet_mode_, @@ -80,11 +31,12 @@ public: private: const Core::Frontend::MiiEditApplet& frontend; + Core::System& system; + MiiAppletInput input_data{}; AppletOutputForCharInfoEditing output_data{}; - bool is_complete = false; - Core::System& system; + bool is_complete{false}; }; } // namespace Service::AM::Applets diff --git a/src/core/hle/service/am/applets/applet_mii_edit_types.h b/src/core/hle/service/am/applets/applet_mii_edit_types.h new file mode 100644 index 000000000..7b8b35254 --- /dev/null +++ b/src/core/hle/service/am/applets/applet_mii_edit_types.h @@ -0,0 +1,62 @@ +// Copyright 2022 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include + +#include "common/common_funcs.h" +#include "common/common_types.h" +#include "core/hle/service/mii/types.h" + +namespace Service::AM::Applets { + +// This is nn::mii::AppletMode +enum class MiiAppletMode : u32 { + ShowMiiEdit = 0, + AppendMii = 1, + AppendMiiImage = 2, + UpdateMiiImage = 3, + CreateMii = 4, + EditMii = 5, +}; + +struct MiiCharInfo { + Service::Mii::MiiInfo mii_data{}; + INSERT_PADDING_BYTES(0x28); +}; +static_assert(sizeof(MiiCharInfo) == 0x80, "MiiCharInfo has incorrect size."); + +// This is nn::mii::AppletInput +struct MiiAppletInput { + s32 version{}; + MiiAppletMode applet_mode{}; + u32 special_mii_key_code{}; + union { + std::array valid_uuid; + MiiCharInfo mii_char_info; + }; + Common::UUID used_uuid; + INSERT_PADDING_BYTES(0x64); +}; +static_assert(sizeof(MiiAppletInput) == 0x100, "MiiAppletInput has incorrect size."); + +// This is nn::mii::AppletOutput +struct MiiAppletOutput { + u32 result{}; + s32 index{}; + INSERT_PADDING_BYTES(0x18); +}; +static_assert(sizeof(MiiAppletOutput) == 0x20, "MiiAppletOutput has incorrect size."); + +// This is nn::mii::AppletOutputForCharInfoEditing +struct AppletOutputForCharInfoEditing { + u32 result{}; + Service::Mii::MiiInfo mii_data{}; + INSERT_PADDING_BYTES(0x24); +}; +static_assert(sizeof(AppletOutputForCharInfoEditing) == 0x80, + "AppletOutputForCharInfoEditing has incorrect size."); + +} // namespace Service::AM::Applets From 1d5f6b173d7a48cd6fb1b8d637b587e586e6acb6 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 17 Mar 2022 05:15:48 -0400 Subject: [PATCH 4/7] applets/mii: Cleanup MiiEdit applet types --- .../am/applets/applet_mii_edit_types.h | 67 ++++++++++++------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/src/core/hle/service/am/applets/applet_mii_edit_types.h b/src/core/hle/service/am/applets/applet_mii_edit_types.h index 7b8b35254..70dea0007 100644 --- a/src/core/hle/service/am/applets/applet_mii_edit_types.h +++ b/src/core/hle/service/am/applets/applet_mii_edit_types.h @@ -12,8 +12,13 @@ namespace Service::AM::Applets { +enum class MiiEditAppletVersion : s32 { + Version3 = 0x3, // 1.0.0 - 10.1.1 + Version4 = 0x4, // 10.2.0+ +}; + // This is nn::mii::AppletMode -enum class MiiAppletMode : u32 { +enum class MiiEditAppletMode : u32 { ShowMiiEdit = 0, AppendMii = 1, AppendMiiImage = 2, @@ -22,41 +27,57 @@ enum class MiiAppletMode : u32 { EditMii = 5, }; -struct MiiCharInfo { - Service::Mii::MiiInfo mii_data{}; - INSERT_PADDING_BYTES(0x28); +enum class MiiEditResult : u32 { + Success, + Cancel, }; -static_assert(sizeof(MiiCharInfo) == 0x80, "MiiCharInfo has incorrect size."); -// This is nn::mii::AppletInput -struct MiiAppletInput { - s32 version{}; - MiiAppletMode applet_mode{}; +struct MiiEditCharInfo { + Service::Mii::MiiInfo mii_info{}; +}; +static_assert(sizeof(MiiEditCharInfo) == 0x58, "MiiEditCharInfo has incorrect size."); + +struct MiiEditAppletInputCommon { + MiiEditAppletVersion version{}; + MiiEditAppletMode applet_mode{}; +}; +static_assert(sizeof(MiiEditAppletInputCommon) == 0x8, + "MiiEditAppletInputCommon has incorrect size."); + +struct MiiEditAppletInputV3 { u32 special_mii_key_code{}; - union { - std::array valid_uuid; - MiiCharInfo mii_char_info; - }; - Common::UUID used_uuid; + std::array valid_uuids{}; + Common::UUID used_uuid{}; INSERT_PADDING_BYTES(0x64); }; -static_assert(sizeof(MiiAppletInput) == 0x100, "MiiAppletInput has incorrect size."); +static_assert(sizeof(MiiEditAppletInputV3) == 0x100 - sizeof(MiiEditAppletInputCommon), + "MiiEditAppletInputV3 has incorrect size."); + +struct MiiEditAppletInputV4 { + u32 special_mii_key_code{}; + MiiEditCharInfo char_info{}; + INSERT_PADDING_BYTES(0x28); + Common::UUID used_uuid{}; + INSERT_PADDING_BYTES(0x64); +}; +static_assert(sizeof(MiiEditAppletInputV4) == 0x100 - sizeof(MiiEditAppletInputCommon), + "MiiEditAppletInputV4 has incorrect size."); // This is nn::mii::AppletOutput -struct MiiAppletOutput { - u32 result{}; +struct MiiEditAppletOutput { + MiiEditResult result{}; s32 index{}; INSERT_PADDING_BYTES(0x18); }; -static_assert(sizeof(MiiAppletOutput) == 0x20, "MiiAppletOutput has incorrect size."); +static_assert(sizeof(MiiEditAppletOutput) == 0x20, "MiiEditAppletOutput has incorrect size."); // This is nn::mii::AppletOutputForCharInfoEditing -struct AppletOutputForCharInfoEditing { - u32 result{}; - Service::Mii::MiiInfo mii_data{}; +struct MiiEditAppletOutputForCharInfoEditing { + MiiEditResult result{}; + MiiEditCharInfo char_info{}; INSERT_PADDING_BYTES(0x24); }; -static_assert(sizeof(AppletOutputForCharInfoEditing) == 0x80, - "AppletOutputForCharInfoEditing has incorrect size."); +static_assert(sizeof(MiiEditAppletOutputForCharInfoEditing) == 0x80, + "MiiEditAppletOutputForCharInfoEditing has incorrect size."); } // namespace Service::AM::Applets From c50401903f593dbc3fa83cef333e2e957fe18e85 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 17 Mar 2022 05:18:48 -0400 Subject: [PATCH 5/7] applets/mii: Cleanup MiiEdit applet implementation This also enables proper support for MiiEdit applets which are used in games with firmware versions prior to 10.2.0 by handling the 2 different versions of applet inputs and outputs. --- .../service/am/applets/applet_mii_edit.cpp | 124 ++++++++++++------ .../hle/service/am/applets/applet_mii_edit.h | 9 +- 2 files changed, 87 insertions(+), 46 deletions(-) diff --git a/src/core/hle/service/am/applets/applet_mii_edit.cpp b/src/core/hle/service/am/applets/applet_mii_edit.cpp index 769c3c3eb..a97a3295e 100644 --- a/src/core/hle/service/am/applets/applet_mii_edit.cpp +++ b/src/core/hle/service/am/applets/applet_mii_edit.cpp @@ -20,15 +20,44 @@ MiiEdit::MiiEdit(Core::System& system_, LibraryAppletMode applet_mode_, MiiEdit::~MiiEdit() = default; void MiiEdit::Initialize() { - is_complete = false; + // Note: MiiEdit is not initialized with common arguments. + // Instead, it is initialized by an AppletInput storage with size 0x100 bytes. + // Do NOT call Applet::Initialize() here. const auto storage = broker.PopNormalDataToApplet(); ASSERT(storage != nullptr); - const auto data = storage->GetData(); - ASSERT(data.size() == sizeof(MiiAppletInput)); + const auto applet_input_data = storage->GetData(); + ASSERT(applet_input_data.size() >= sizeof(MiiEditAppletInputCommon)); - std::memcpy(&input_data, data.data(), sizeof(MiiAppletInput)); + std::memcpy(&applet_input_common, applet_input_data.data(), sizeof(MiiEditAppletInputCommon)); + + LOG_INFO(Service_AM, + "Initializing MiiEdit Applet with MiiEditAppletVersion={} and MiiEditAppletMode={}", + applet_input_common.version, applet_input_common.applet_mode); + + switch (applet_input_common.version) { + case MiiEditAppletVersion::Version3: + ASSERT(applet_input_data.size() == + sizeof(MiiEditAppletInputCommon) + sizeof(MiiEditAppletInputV3)); + std::memcpy(&applet_input_v3, applet_input_data.data() + sizeof(MiiEditAppletInputCommon), + sizeof(MiiEditAppletInputV3)); + break; + case MiiEditAppletVersion::Version4: + ASSERT(applet_input_data.size() == + sizeof(MiiEditAppletInputCommon) + sizeof(MiiEditAppletInputV4)); + std::memcpy(&applet_input_v4, applet_input_data.data() + sizeof(MiiEditAppletInputCommon), + sizeof(MiiEditAppletInputV4)); + break; + default: + UNIMPLEMENTED_MSG("Unknown MiiEditAppletVersion={} with size={}", + applet_input_common.version, applet_input_data.size()); + ASSERT(applet_input_data.size() >= + sizeof(MiiEditAppletInputCommon) + sizeof(MiiEditAppletInputV4)); + std::memcpy(&applet_input_v4, applet_input_data.data() + sizeof(MiiEditAppletInputCommon), + sizeof(MiiEditAppletInputV4)); + break; + } } bool MiiEdit::TransactionComplete() const { @@ -40,7 +69,7 @@ ResultCode MiiEdit::GetStatus() const { } void MiiEdit::ExecuteInteractive() { - UNREACHABLE_MSG("Unexpected interactive applet data!"); + UNREACHABLE_MSG("Attempted to call interactive execution on non-interactive applet."); } void MiiEdit::Execute() { @@ -48,54 +77,63 @@ void MiiEdit::Execute() { return; } - const auto callback = [this](const Core::Frontend::MiiParameters& parameters) { - DisplayCompleted(parameters); - }; + // This is a default stub for each of the MiiEdit applet modes. + switch (applet_input_common.applet_mode) { + case MiiEditAppletMode::ShowMiiEdit: + case MiiEditAppletMode::AppendMii: + case MiiEditAppletMode::AppendMiiImage: + case MiiEditAppletMode::UpdateMiiImage: + MiiEditOutput(MiiEditResult::Success, 0); + break; + case MiiEditAppletMode::CreateMii: + case MiiEditAppletMode::EditMii: { + Service::Mii::MiiManager mii_manager; - switch (input_data.applet_mode) { - case MiiAppletMode::ShowMiiEdit: { - Service::Mii::MiiManager manager; - Core::Frontend::MiiParameters params{ - .is_editable = false, - .mii_data = input_data.mii_char_info.mii_data, + const MiiEditCharInfo char_info{ + .mii_info{applet_input_common.applet_mode == MiiEditAppletMode::EditMii + ? applet_input_v4.char_info.mii_info + : mii_manager.BuildDefault(0)}, }; - frontend.ShowMii(params, callback); - break; - } - case MiiAppletMode::EditMii: { - Service::Mii::MiiManager manager; - Core::Frontend::MiiParameters params{ - .is_editable = true, - .mii_data = input_data.mii_char_info.mii_data, - }; - frontend.ShowMii(params, callback); - break; - } - case MiiAppletMode::CreateMii: { - Service::Mii::MiiManager manager; - Core::Frontend::MiiParameters params{ - .is_editable = true, - .mii_data = manager.BuildDefault(0), - }; - frontend.ShowMii(params, callback); + + MiiEditOutputForCharInfoEditing(MiiEditResult::Success, char_info); break; } default: - UNIMPLEMENTED_MSG("Unimplemented LibAppletMiiEdit mode={:02X}!", input_data.applet_mode); + UNIMPLEMENTED_MSG("Unknown MiiEditAppletMode={}", applet_input_common.applet_mode); + + MiiEditOutput(MiiEditResult::Success, 0); + break; } } -void MiiEdit::DisplayCompleted(const Core::Frontend::MiiParameters& parameters) { - is_complete = true; - - std::vector reply(sizeof(AppletOutputForCharInfoEditing)); - output_data = { - .result = 0, - .mii_data = parameters.mii_data, +void MiiEdit::MiiEditOutput(MiiEditResult result, s32 index) { + const MiiEditAppletOutput applet_output{ + .result{result}, + .index{index}, }; - std::memcpy(reply.data(), &output_data, sizeof(AppletOutputForCharInfoEditing)); - broker.PushNormalDataFromApplet(std::make_shared(system, std::move(reply))); + std::vector out_data(sizeof(MiiEditAppletOutput)); + std::memcpy(out_data.data(), &applet_output, sizeof(MiiEditAppletOutput)); + + is_complete = true; + + broker.PushNormalDataFromApplet(std::make_shared(system, std::move(out_data))); + broker.SignalStateChanged(); +} + +void MiiEdit::MiiEditOutputForCharInfoEditing(MiiEditResult result, + const MiiEditCharInfo& char_info) { + const MiiEditAppletOutputForCharInfoEditing applet_output{ + .result{result}, + .char_info{char_info}, + }; + + std::vector out_data(sizeof(MiiEditAppletOutputForCharInfoEditing)); + std::memcpy(out_data.data(), &applet_output, sizeof(MiiEditAppletOutputForCharInfoEditing)); + + is_complete = true; + + broker.PushNormalDataFromApplet(std::make_shared(system, std::move(out_data))); broker.SignalStateChanged(); } diff --git a/src/core/hle/service/am/applets/applet_mii_edit.h b/src/core/hle/service/am/applets/applet_mii_edit.h index 2b4b27c8f..e9ca0e2af 100644 --- a/src/core/hle/service/am/applets/applet_mii_edit.h +++ b/src/core/hle/service/am/applets/applet_mii_edit.h @@ -27,14 +27,17 @@ public: void ExecuteInteractive() override; void Execute() override; - void DisplayCompleted(const Core::Frontend::MiiParameters& parameters); + void MiiEditOutput(MiiEditResult result, s32 index); + + void MiiEditOutputForCharInfoEditing(MiiEditResult result, const MiiEditCharInfo& char_info); private: const Core::Frontend::MiiEditApplet& frontend; Core::System& system; - MiiAppletInput input_data{}; - AppletOutputForCharInfoEditing output_data{}; + MiiEditAppletInputCommon applet_input_common{}; + MiiEditAppletInputV3 applet_input_v3{}; + MiiEditAppletInputV4 applet_input_v4{}; bool is_complete{false}; }; From bcca849d0c68d50690711fe17480cfcda624f2c2 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 17 Mar 2022 05:19:25 -0400 Subject: [PATCH 6/7] applets/mii: Remove frontend parameters These are unused for now as we do not support a frontend implementation. --- src/core/frontend/applets/mii_edit.cpp | 6 ++---- src/core/frontend/applets/mii_edit.h | 15 ++------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/core/frontend/applets/mii_edit.cpp b/src/core/frontend/applets/mii_edit.cpp index 948d66f3d..fadb5fb15 100644 --- a/src/core/frontend/applets/mii_edit.cpp +++ b/src/core/frontend/applets/mii_edit.cpp @@ -9,12 +9,10 @@ namespace Core::Frontend { MiiEditApplet::~MiiEditApplet() = default; -void DefaultMiiEditApplet::ShowMii( - const MiiParameters& parameters, - const std::function callback) const { +void DefaultMiiEditApplet::ShowMiiEdit(const std::function& callback) const { LOG_WARNING(Service_AM, "(STUBBED) called"); - callback(parameters); + callback(); } } // namespace Core::Frontend diff --git a/src/core/frontend/applets/mii_edit.h b/src/core/frontend/applets/mii_edit.h index 247ccd461..cca0e931d 100644 --- a/src/core/frontend/applets/mii_edit.h +++ b/src/core/frontend/applets/mii_edit.h @@ -6,29 +6,18 @@ #include -#include "core/hle/service/mii/types.h" - namespace Core::Frontend { -struct MiiParameters { - bool is_editable; - Service::Mii::MiiInfo mii_data{}; -}; - class MiiEditApplet { public: virtual ~MiiEditApplet(); - virtual void ShowMii(const MiiParameters& parameters, - const std::function - callback) const = 0; + virtual void ShowMiiEdit(const std::function& callback) const = 0; }; class DefaultMiiEditApplet final : public MiiEditApplet { public: - void ShowMii(const MiiParameters& parameters, - const std::function - callback) const override; + void ShowMiiEdit(const std::function& callback) const override; }; } // namespace Core::Frontend From 6e232b9efe47135263e957a7d852764832fd4695 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 17 Mar 2022 05:30:48 -0400 Subject: [PATCH 7/7] applets/mii: Remove unused include --- src/core/hle/service/am/applets/applet_mii_edit.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core/hle/service/am/applets/applet_mii_edit.cpp b/src/core/hle/service/am/applets/applet_mii_edit.cpp index a97a3295e..8fbde1be4 100644 --- a/src/core/hle/service/am/applets/applet_mii_edit.cpp +++ b/src/core/hle/service/am/applets/applet_mii_edit.cpp @@ -9,7 +9,6 @@ #include "core/hle/service/am/am.h" #include "core/hle/service/am/applets/applet_mii_edit.h" #include "core/hle/service/mii/mii_manager.h" -#include "core/reporter.h" namespace Service::AM::Applets {