diff options
| author | 2022-08-30 19:28:37 -0500 | |
|---|---|---|
| committer | 2022-09-07 01:04:00 -0500 | |
| commit | caa138b33f6bbc18cde4d403017dad6bd4387e13 (patch) | |
| tree | 7de25f6a4f3f17e2beff0711e01119bedde15c2e /src/core/hle/service/nfp | |
| parent | core: nfp: Implement Convert and RecreateApplicationArea, accuracy fixes (diff) | |
| download | yuzu-caa138b33f6bbc18cde4d403017dad6bd4387e13.tar.gz yuzu-caa138b33f6bbc18cde4d403017dad6bd4387e13.tar.xz yuzu-caa138b33f6bbc18cde4d403017dad6bd4387e13.zip | |
core: nfp: Correct date and amiibo name
Diffstat (limited to 'src/core/hle/service/nfp')
| -rw-r--r-- | src/core/hle/service/nfp/amiibo_types.h | 12 | ||||
| -rw-r--r-- | src/core/hle/service/nfp/nfp.cpp | 29 | ||||
| -rw-r--r-- | src/core/hle/service/nfp/nfp.h | 10 |
3 files changed, 34 insertions, 17 deletions
diff --git a/src/core/hle/service/nfp/amiibo_types.h b/src/core/hle/service/nfp/amiibo_types.h index bd0424ffd..c9c0932d0 100644 --- a/src/core/hle/service/nfp/amiibo_types.h +++ b/src/core/hle/service/nfp/amiibo_types.h | |||
| @@ -8,6 +8,8 @@ | |||
| 8 | #include "core/hle/service/mii/types.h" | 8 | #include "core/hle/service/mii/types.h" |
| 9 | 9 | ||
| 10 | namespace Service::NFP { | 10 | namespace Service::NFP { |
| 11 | static constexpr std::size_t amiibo_name_length = 0xA; | ||
| 12 | |||
| 11 | enum class ServiceType : u32 { | 13 | enum class ServiceType : u32 { |
| 12 | User, | 14 | User, |
| 13 | Debug, | 15 | Debug, |
| @@ -76,16 +78,16 @@ using HashData = std::array<u8, 0x20>; | |||
| 76 | using ApplicationArea = std::array<u8, 0xD8>; | 78 | using ApplicationArea = std::array<u8, 0xD8>; |
| 77 | 79 | ||
| 78 | struct AmiiboDate { | 80 | struct AmiiboDate { |
| 79 | u16_be raw_date{}; | 81 | u16 raw_date{}; |
| 80 | 82 | ||
| 81 | u16 GetYear() const { | 83 | u16 GetYear() const { |
| 82 | return ((raw_date & 0xFE00) >> 9) + 2000; | 84 | return static_cast<u16>(((raw_date & 0xFE00) >> 9) + 2000); |
| 83 | } | 85 | } |
| 84 | u8 GetMonth() const { | 86 | u8 GetMonth() const { |
| 85 | return ((raw_date & 0x01E0) >> 5) - 1; | 87 | return static_cast<u8>(((raw_date & 0x01E0) >> 5) - 1); |
| 86 | } | 88 | } |
| 87 | u8 GetDay() const { | 89 | u8 GetDay() const { |
| 88 | return raw_date & 0x001F; | 90 | return static_cast<u8>(raw_date & 0x001F); |
| 89 | } | 91 | } |
| 90 | }; | 92 | }; |
| 91 | static_assert(sizeof(AmiiboDate) == 2, "AmiiboDate is an invalid size"); | 93 | static_assert(sizeof(AmiiboDate) == 2, "AmiiboDate is an invalid size"); |
| @@ -107,7 +109,7 @@ struct AmiiboSettings { | |||
| 107 | AmiiboDate init_date; | 109 | AmiiboDate init_date; |
| 108 | AmiiboDate write_date; | 110 | AmiiboDate write_date; |
| 109 | u32_be crc; | 111 | u32_be crc; |
| 110 | std::array<u16_be, 0xA> amiibo_name; // UTF-16 text | 112 | std::array<u16_be, amiibo_name_length> amiibo_name; // UTF-16 text |
| 111 | }; | 113 | }; |
| 112 | static_assert(sizeof(AmiiboSettings) == 0x20, "AmiiboSettings is an invalid size"); | 114 | static_assert(sizeof(AmiiboSettings) == 0x20, "AmiiboSettings is an invalid size"); |
| 113 | 115 | ||
diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp index 20fea87e6..fb89f6911 100644 --- a/src/core/hle/service/nfp/nfp.cpp +++ b/src/core/hle/service/nfp/nfp.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include "common/fs/file.h" | 7 | #include "common/fs/file.h" |
| 8 | #include "common/fs/path_util.h" | 8 | #include "common/fs/path_util.h" |
| 9 | #include "common/logging/log.h" | 9 | #include "common/logging/log.h" |
| 10 | #include "common/string_util.h" | ||
| 10 | #include "core/core.h" | 11 | #include "core/core.h" |
| 11 | #include "core/hid/emulated_controller.h" | 12 | #include "core/hid/emulated_controller.h" |
| 12 | #include "core/hid/hid_core.h" | 13 | #include "core/hid/hid_core.h" |
| @@ -917,20 +918,14 @@ Result Module::Interface::GetRegisterInfo(RegisterInfo& register_info) const { | |||
| 917 | if (is_data_decoded && tag_data.settings.settings.amiibo_initialized != 0) { | 918 | if (is_data_decoded && tag_data.settings.settings.amiibo_initialized != 0) { |
| 918 | const auto& settings = tag_data.settings; | 919 | const auto& settings = tag_data.settings; |
| 919 | 920 | ||
| 920 | // Amiibo name is u16 while the register info is u8. Figure out how to handle this properly | ||
| 921 | std::array<u8, 11> amiibo_name{}; | ||
| 922 | for (std::size_t i = 0; i < sizeof(amiibo_name) - 1; ++i) { | ||
| 923 | amiibo_name[i] = static_cast<u8>(settings.amiibo_name[i]); | ||
| 924 | } | ||
| 925 | |||
| 926 | // TODO: Validate this data | 921 | // TODO: Validate this data |
| 927 | register_info = { | 922 | register_info = { |
| 928 | .mii_char_info = manager.ConvertV3ToCharInfo(tag_data.owner_mii), | 923 | .mii_char_info = manager.ConvertV3ToCharInfo(tag_data.owner_mii), |
| 929 | .first_write_year = settings.init_date.GetYear(), | 924 | .first_write_year = settings.init_date.GetYear(), |
| 930 | .first_write_month = settings.init_date.GetMonth(), | 925 | .first_write_month = settings.init_date.GetMonth(), |
| 931 | .first_write_day = settings.init_date.GetDay(), | 926 | .first_write_day = settings.init_date.GetDay(), |
| 932 | .amiibo_name = amiibo_name, | 927 | .amiibo_name = GetAmiiboName(settings), |
| 933 | .unknown = {}, | 928 | .font_region = {}, |
| 934 | }; | 929 | }; |
| 935 | 930 | ||
| 936 | return ResultSuccess; | 931 | return ResultSuccess; |
| @@ -943,7 +938,7 @@ Result Module::Interface::GetRegisterInfo(RegisterInfo& register_info) const { | |||
| 943 | .first_write_month = 2, | 938 | .first_write_month = 2, |
| 944 | .first_write_day = 7, | 939 | .first_write_day = 7, |
| 945 | .amiibo_name = {'Y', 'u', 'z', 'u', 'A', 'm', 'i', 'i', 'b', 'o', 0}, | 940 | .amiibo_name = {'Y', 'u', 'z', 'u', 'A', 'm', 'i', 'i', 'b', 'o', 0}, |
| 946 | .unknown = {}, | 941 | .font_region = {}, |
| 947 | }; | 942 | }; |
| 948 | return ResultSuccess; | 943 | return ResultSuccess; |
| 949 | } | 944 | } |
| @@ -1077,6 +1072,22 @@ Core::HID::NpadIdType Module::Interface::GetNpadId() const { | |||
| 1077 | return npad_id; | 1072 | return npad_id; |
| 1078 | } | 1073 | } |
| 1079 | 1074 | ||
| 1075 | AmiiboName Module::Interface::GetAmiiboName(const AmiiboSettings& settings) const { | ||
| 1076 | std::array<char16_t, amiibo_name_length> settings_amiibo_name{}; | ||
| 1077 | AmiiboName amiibo_name{}; | ||
| 1078 | |||
| 1079 | // Convert from big endian to little endian | ||
| 1080 | for (std::size_t i = 0; i < amiibo_name_length; i++) { | ||
| 1081 | settings_amiibo_name[i] = static_cast<u16>(settings.amiibo_name[i]); | ||
| 1082 | } | ||
| 1083 | |||
| 1084 | // Convert from utf16 to utf8 | ||
| 1085 | const auto amiibo_name_utf8 = Common::UTF16ToUTF8(settings_amiibo_name.data()); | ||
| 1086 | memcpy(amiibo_name.data(), amiibo_name_utf8.data(), amiibo_name_utf8.size()); | ||
| 1087 | |||
| 1088 | return amiibo_name; | ||
| 1089 | } | ||
| 1090 | |||
| 1080 | void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { | 1091 | void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { |
| 1081 | auto module = std::make_shared<Module>(); | 1092 | auto module = std::make_shared<Module>(); |
| 1082 | std::make_shared<NFP_User>(module, system)->InstallAsService(service_manager); | 1093 | std::make_shared<NFP_User>(module, system)->InstallAsService(service_manager); |
diff --git a/src/core/hle/service/nfp/nfp.h b/src/core/hle/service/nfp/nfp.h index 6b979daba..0de0b48e7 100644 --- a/src/core/hle/service/nfp/nfp.h +++ b/src/core/hle/service/nfp/nfp.h | |||
| @@ -22,6 +22,8 @@ enum class NpadIdType : u32; | |||
| 22 | } // namespace Core::HID | 22 | } // namespace Core::HID |
| 23 | 23 | ||
| 24 | namespace Service::NFP { | 24 | namespace Service::NFP { |
| 25 | using AmiiboName = std::array<char, (amiibo_name_length * 4) + 1>; | ||
| 26 | |||
| 25 | struct TagInfo { | 27 | struct TagInfo { |
| 26 | TagUuid uuid; | 28 | TagUuid uuid; |
| 27 | u8 uuid_length; | 29 | u8 uuid_length; |
| @@ -59,9 +61,9 @@ struct RegisterInfo { | |||
| 59 | u16 first_write_year; | 61 | u16 first_write_year; |
| 60 | u8 first_write_month; | 62 | u8 first_write_month; |
| 61 | u8 first_write_day; | 63 | u8 first_write_day; |
| 62 | std::array<u8, 0xA + 1> amiibo_name; | 64 | AmiiboName amiibo_name; |
| 63 | u8 unknown; | 65 | u8 font_region; |
| 64 | INSERT_PADDING_BYTES(0x98); | 66 | INSERT_PADDING_BYTES(0x7A); |
| 65 | }; | 67 | }; |
| 66 | static_assert(sizeof(RegisterInfo) == 0x100, "RegisterInfo is an invalid size"); | 68 | static_assert(sizeof(RegisterInfo) == 0x100, "RegisterInfo is an invalid size"); |
| 67 | 69 | ||
| @@ -109,6 +111,8 @@ public: | |||
| 109 | std::shared_ptr<Module> module; | 111 | std::shared_ptr<Module> module; |
| 110 | 112 | ||
| 111 | private: | 113 | private: |
| 114 | AmiiboName GetAmiiboName(const AmiiboSettings& settings) const; | ||
| 115 | |||
| 112 | const Core::HID::NpadIdType npad_id; | 116 | const Core::HID::NpadIdType npad_id; |
| 113 | 117 | ||
| 114 | bool is_data_decoded{}; | 118 | bool is_data_decoded{}; |