core: nfp: Implement Convert and RecreateApplicationArea, accuracy fixes
This commit is contained in:
parent
848f69eb19
commit
19a4e12e6e
10 changed files with 355 additions and 256 deletions
|
@ -16,76 +16,6 @@
|
|||
|
||||
namespace Service::NFP::AmiiboCrypto {
|
||||
|
||||
Service::Mii::MiiInfo AmiiboRegisterInfoToMii(const AmiiboRegisterInfo& mii_info) {
|
||||
|
||||
Service::Mii::MiiManager manager;
|
||||
auto mii = manager.BuildDefault(0);
|
||||
|
||||
// TODO: We are ignoring a bunch of data from the amiibo mii
|
||||
|
||||
mii.gender = static_cast<u8>(mii_info.mii_information.gender);
|
||||
mii.favorite_color = static_cast<u8>(mii_info.mii_information.favorite_color);
|
||||
memcpy(mii.name.data(), mii_info.mii_name.data(), 10);
|
||||
mii.height = mii_info.height;
|
||||
mii.build = mii_info.build;
|
||||
|
||||
mii.faceline_type = mii_info.appearance_bits1.face_shape;
|
||||
mii.faceline_color = mii_info.appearance_bits1.skin_color;
|
||||
mii.faceline_wrinkle = mii_info.appearance_bits2.wrinkles;
|
||||
mii.faceline_make = mii_info.appearance_bits2.makeup;
|
||||
|
||||
mii.hair_type = mii_info.hair_style;
|
||||
mii.hair_color = mii_info.appearance_bits3.hair_color;
|
||||
mii.hair_flip = mii_info.appearance_bits3.flip_hair;
|
||||
|
||||
mii.eye_type = static_cast<u8>(mii_info.appearance_bits4.eye_type);
|
||||
mii.eye_color = static_cast<u8>(mii_info.appearance_bits4.eye_color);
|
||||
mii.eye_scale = static_cast<u8>(mii_info.appearance_bits4.eye_scale);
|
||||
mii.eye_aspect = static_cast<u8>(mii_info.appearance_bits4.eye_vertical_stretch);
|
||||
mii.eye_rotate = static_cast<u8>(mii_info.appearance_bits4.eye_rotation);
|
||||
mii.eye_x = static_cast<u8>(mii_info.appearance_bits4.eye_spacing);
|
||||
mii.eye_y = static_cast<u8>(mii_info.appearance_bits4.eye_y_position);
|
||||
|
||||
mii.eyebrow_type = static_cast<u8>(mii_info.appearance_bits5.eyebrow_style);
|
||||
mii.eyebrow_color = static_cast<u8>(mii_info.appearance_bits5.eyebrow_color);
|
||||
mii.eyebrow_scale = static_cast<u8>(mii_info.appearance_bits5.eyebrow_scale);
|
||||
mii.eyebrow_aspect = static_cast<u8>(mii_info.appearance_bits5.eyebrow_yscale);
|
||||
mii.eyebrow_rotate = static_cast<u8>(mii_info.appearance_bits5.eyebrow_rotation);
|
||||
mii.eyebrow_x = static_cast<u8>(mii_info.appearance_bits5.eyebrow_spacing);
|
||||
mii.eyebrow_y = static_cast<u8>(mii_info.appearance_bits5.eyebrow_y_position);
|
||||
|
||||
mii.nose_type = static_cast<u8>(mii_info.appearance_bits6.nose_type);
|
||||
mii.nose_scale = static_cast<u8>(mii_info.appearance_bits6.nose_scale);
|
||||
mii.nose_y = static_cast<u8>(mii_info.appearance_bits6.nose_y_position);
|
||||
|
||||
mii.mouth_type = static_cast<u8>(mii_info.appearance_bits7.mouth_type);
|
||||
mii.mouth_color = static_cast<u8>(mii_info.appearance_bits7.mouth_color);
|
||||
mii.mouth_scale = static_cast<u8>(mii_info.appearance_bits7.mouth_scale);
|
||||
mii.mouth_aspect = static_cast<u8>(mii_info.appearance_bits7.mouth_horizontal_stretch);
|
||||
mii.mouth_y = static_cast<u8>(mii_info.appearance_bits8.mouth_y_position);
|
||||
|
||||
mii.mustache_type = static_cast<u8>(mii_info.appearance_bits8.mustache_type);
|
||||
mii.mustache_scale = static_cast<u8>(mii_info.appearance_bits9.mustache_scale);
|
||||
mii.mustache_y = static_cast<u8>(mii_info.appearance_bits9.mustache_y_position);
|
||||
|
||||
mii.beard_type = static_cast<u8>(mii_info.appearance_bits9.bear_type);
|
||||
mii.beard_color = static_cast<u8>(mii_info.appearance_bits9.facial_hair_color);
|
||||
|
||||
mii.glasses_type = static_cast<u8>(mii_info.appearance_bits10.glasses_type);
|
||||
mii.glasses_color = static_cast<u8>(mii_info.appearance_bits10.glasses_color);
|
||||
mii.glasses_scale = static_cast<u8>(mii_info.appearance_bits10.glasses_scale);
|
||||
mii.glasses_y = static_cast<u8>(mii_info.appearance_bits10.glasses_y_position);
|
||||
|
||||
mii.mole_type = static_cast<u8>(mii_info.appearance_bits11.mole_enabled);
|
||||
mii.mole_scale = static_cast<u8>(mii_info.appearance_bits11.mole_scale);
|
||||
mii.mole_x = static_cast<u8>(mii_info.appearance_bits11.mole_x_position);
|
||||
mii.mole_y = static_cast<u8>(mii_info.appearance_bits11.mole_y_position);
|
||||
|
||||
// TODO: Validate mii data
|
||||
|
||||
return mii;
|
||||
}
|
||||
|
||||
bool IsAmiiboValid(const EncryptedNTAG215File& ntag_file) {
|
||||
const auto& amiibo_data = ntag_file.user_memory;
|
||||
LOG_DEBUG(Service_NFP, "uuid_lock=0x{0:x}", ntag_file.static_lock);
|
||||
|
@ -126,9 +56,8 @@ bool IsAmiiboValid(const EncryptedNTAG215File& ntag_file) {
|
|||
if (amiibo_data.model_info.constant_value != 0x02) {
|
||||
return false;
|
||||
}
|
||||
if ((ntag_file.dynamic_lock & 0xFFFFFF) != 0x0F0001) {
|
||||
return false;
|
||||
}
|
||||
// dynamic_lock value apparently is not constant
|
||||
// ntag_file.dynamic_lock == 0x0F0001
|
||||
if (ntag_file.CFG0 != 0x04000000U) {
|
||||
return false;
|
||||
}
|
||||
|
@ -348,16 +277,16 @@ bool LoadKeys(InternalKey& locked_secret, InternalKey& unfixed_info) {
|
|||
Common::FS::FileType::BinaryFile};
|
||||
|
||||
if (!keys_file.IsOpen()) {
|
||||
LOG_ERROR(Core, "No keys detected");
|
||||
LOG_ERROR(Service_NFP, "No keys detected");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keys_file.Read(unfixed_info) != 1) {
|
||||
LOG_ERROR(Core, "Failed to read unfixed_info");
|
||||
LOG_ERROR(Service_NFP, "Failed to read unfixed_info");
|
||||
return false;
|
||||
}
|
||||
if (keys_file.Read(locked_secret) != 1) {
|
||||
LOG_ERROR(Core, "Failed to read locked-secret");
|
||||
LOG_ERROR(Service_NFP, "Failed to read locked-secret");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -55,9 +55,6 @@ struct DerivedKeys {
|
|||
};
|
||||
static_assert(sizeof(DerivedKeys) == 0x30, "DerivedKeys is an invalid size");
|
||||
|
||||
/// Converts mii data from nintendo 3ds format to nintendo switch format
|
||||
Service::Mii::MiiInfo AmiiboRegisterInfoToMii(const AmiiboRegisterInfo& register_info);
|
||||
|
||||
/// Validates that the amiibo file is not corrupted
|
||||
bool IsAmiiboValid(const EncryptedNTAG215File& ntag_file);
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include <array>
|
||||
|
||||
#include "core/hle/service/mii/types.h"
|
||||
|
||||
namespace Service::NFP {
|
||||
enum class ServiceType : u32 {
|
||||
User,
|
||||
|
@ -74,13 +76,17 @@ using HashData = std::array<u8, 0x20>;
|
|||
using ApplicationArea = std::array<u8, 0xD8>;
|
||||
|
||||
struct AmiiboDate {
|
||||
union {
|
||||
u16_be raw{};
|
||||
u16_be raw_date{};
|
||||
|
||||
BitField<0, 5, u16> day;
|
||||
BitField<5, 4, u16> month;
|
||||
BitField<9, 7, u16> year;
|
||||
};
|
||||
u16 GetYear() const {
|
||||
return ((raw_date & 0xFE00) >> 9) + 2000;
|
||||
}
|
||||
u8 GetMonth() const {
|
||||
return ((raw_date & 0x01E0) >> 5) - 1;
|
||||
}
|
||||
u8 GetDay() const {
|
||||
return raw_date & 0x001F;
|
||||
}
|
||||
};
|
||||
static_assert(sizeof(AmiiboDate) == 2, "AmiiboDate is an invalid size");
|
||||
|
||||
|
@ -123,135 +129,20 @@ struct NTAG215Password {
|
|||
};
|
||||
static_assert(sizeof(NTAG215Password) == 0x8, "NTAG215Password is an invalid size");
|
||||
|
||||
// Based on citra HLE::Applets::MiiData and PretendoNetwork.
|
||||
// https://github.com/citra-emu/citra/blob/master/src/core/hle/applets/mii_selector.h#L48
|
||||
// https://github.com/PretendoNetwork/mii-js/blob/master/mii.js#L299
|
||||
#pragma pack(1)
|
||||
struct AmiiboRegisterInfo {
|
||||
u32_be mii_id;
|
||||
u64_be system_id;
|
||||
u32_be specialness_and_creation_date;
|
||||
std::array<u8, 0x6> creator_mac;
|
||||
u16_be padding;
|
||||
union {
|
||||
u16 raw;
|
||||
|
||||
BitField<0, 1, u16> gender;
|
||||
BitField<1, 4, u16> birth_month;
|
||||
BitField<5, 5, u16> birth_day;
|
||||
BitField<10, 4, u16> favorite_color;
|
||||
BitField<14, 1, u16> favorite;
|
||||
} mii_information;
|
||||
std::array<char16_t, 0xA> mii_name;
|
||||
u8 height;
|
||||
u8 build;
|
||||
union {
|
||||
u8 raw;
|
||||
|
||||
BitField<0, 1, u8> disable_sharing;
|
||||
BitField<1, 4, u8> face_shape;
|
||||
BitField<5, 3, u8> skin_color;
|
||||
} appearance_bits1;
|
||||
union {
|
||||
u8 raw;
|
||||
|
||||
BitField<0, 4, u8> wrinkles;
|
||||
BitField<4, 4, u8> makeup;
|
||||
} appearance_bits2;
|
||||
u8 hair_style;
|
||||
union {
|
||||
u8 raw;
|
||||
|
||||
BitField<0, 3, u8> hair_color;
|
||||
BitField<3, 1, u8> flip_hair;
|
||||
} appearance_bits3;
|
||||
union {
|
||||
u32 raw;
|
||||
|
||||
BitField<0, 6, u32> eye_type;
|
||||
BitField<6, 3, u32> eye_color;
|
||||
BitField<9, 4, u32> eye_scale;
|
||||
BitField<13, 3, u32> eye_vertical_stretch;
|
||||
BitField<16, 5, u32> eye_rotation;
|
||||
BitField<21, 4, u32> eye_spacing;
|
||||
BitField<25, 5, u32> eye_y_position;
|
||||
} appearance_bits4;
|
||||
union {
|
||||
u32 raw;
|
||||
|
||||
BitField<0, 5, u32> eyebrow_style;
|
||||
BitField<5, 3, u32> eyebrow_color;
|
||||
BitField<8, 4, u32> eyebrow_scale;
|
||||
BitField<12, 3, u32> eyebrow_yscale;
|
||||
BitField<16, 4, u32> eyebrow_rotation;
|
||||
BitField<21, 4, u32> eyebrow_spacing;
|
||||
BitField<25, 5, u32> eyebrow_y_position;
|
||||
} appearance_bits5;
|
||||
union {
|
||||
u16 raw;
|
||||
|
||||
BitField<0, 5, u16> nose_type;
|
||||
BitField<5, 4, u16> nose_scale;
|
||||
BitField<9, 5, u16> nose_y_position;
|
||||
} appearance_bits6;
|
||||
union {
|
||||
u16 raw;
|
||||
|
||||
BitField<0, 6, u16> mouth_type;
|
||||
BitField<6, 3, u16> mouth_color;
|
||||
BitField<9, 4, u16> mouth_scale;
|
||||
BitField<13, 3, u16> mouth_horizontal_stretch;
|
||||
} appearance_bits7;
|
||||
union {
|
||||
u8 raw;
|
||||
|
||||
BitField<0, 5, u8> mouth_y_position;
|
||||
BitField<5, 3, u8> mustache_type;
|
||||
} appearance_bits8;
|
||||
u8 allow_copying;
|
||||
union {
|
||||
u16 raw;
|
||||
|
||||
BitField<0, 3, u16> bear_type;
|
||||
BitField<3, 3, u16> facial_hair_color;
|
||||
BitField<6, 4, u16> mustache_scale;
|
||||
BitField<10, 5, u16> mustache_y_position;
|
||||
} appearance_bits9;
|
||||
union {
|
||||
u16 raw;
|
||||
|
||||
BitField<0, 4, u16> glasses_type;
|
||||
BitField<4, 3, u16> glasses_color;
|
||||
BitField<7, 4, u16> glasses_scale;
|
||||
BitField<11, 5, u16> glasses_y_position;
|
||||
} appearance_bits10;
|
||||
union {
|
||||
u16 raw;
|
||||
|
||||
BitField<0, 1, u16> mole_enabled;
|
||||
BitField<1, 4, u16> mole_scale;
|
||||
BitField<5, 5, u16> mole_x_position;
|
||||
BitField<10, 5, u16> mole_y_position;
|
||||
} appearance_bits11;
|
||||
|
||||
std::array<u16_le, 0xA> author_name;
|
||||
INSERT_PADDING_BYTES(0x4);
|
||||
};
|
||||
static_assert(sizeof(AmiiboRegisterInfo) == 0x60, "AmiiboRegisterInfo is an invalid size");
|
||||
|
||||
struct EncryptedAmiiboFile {
|
||||
u8 constant_value; // Must be A5
|
||||
u16 write_counter; // Number of times the amiibo has been written?
|
||||
INSERT_PADDING_BYTES(0x1); // Unknown 1
|
||||
AmiiboSettings settings; // Encrypted amiibo settings
|
||||
HashData locked_hash; // Hash
|
||||
AmiiboModelInfo model_info; // Encrypted amiibo model info
|
||||
HashData keygen_salt; // Salt
|
||||
HashData unfixed_hash; // Hash
|
||||
AmiiboRegisterInfo owner_mii; // Encrypted Mii data
|
||||
u64_be title_id; // Encrypted Game id
|
||||
u16_be applicaton_write_counter; // Encrypted Counter
|
||||
u32_be application_area_id; // Encrypted Game id
|
||||
u8 constant_value; // Must be A5
|
||||
u16 write_counter; // Number of times the amiibo has been written?
|
||||
INSERT_PADDING_BYTES(0x1); // Unknown 1
|
||||
AmiiboSettings settings; // Encrypted amiibo settings
|
||||
HashData locked_hash; // Hash
|
||||
AmiiboModelInfo model_info; // Encrypted amiibo model info
|
||||
HashData keygen_salt; // Salt
|
||||
HashData unfixed_hash; // Hash
|
||||
Service::Mii::Ver3StoreData owner_mii; // Encrypted Mii data
|
||||
u64_be title_id; // Encrypted Game id
|
||||
u16_be applicaton_write_counter; // Encrypted Counter
|
||||
u32_be application_area_id; // Encrypted Game id
|
||||
std::array<u8, 0x2> unknown;
|
||||
HashData hash; // Probably a SHA256-HMAC hash?
|
||||
ApplicationArea application_area; // Encrypted Game data
|
||||
|
@ -267,7 +158,7 @@ struct NTAG215File {
|
|||
u16 write_counter; // Number of times the amiibo has been written?
|
||||
INSERT_PADDING_BYTES(0x1); // Unknown 1
|
||||
AmiiboSettings settings;
|
||||
AmiiboRegisterInfo owner_mii; // Encrypted Mii data
|
||||
Service::Mii::Ver3StoreData owner_mii; // Encrypted Mii data
|
||||
u64_be title_id;
|
||||
u16_be applicaton_write_counter; // Encrypted Counter
|
||||
u32_be application_area_id;
|
||||
|
|
|
@ -24,6 +24,7 @@ constexpr Result DeviceNotFound(ErrorModule::NFP, 64);
|
|||
constexpr Result WrongDeviceState(ErrorModule::NFP, 73);
|
||||
constexpr Result NfcDisabled(ErrorModule::NFP, 80);
|
||||
constexpr Result WriteAmiiboFailed(ErrorModule::NFP, 88);
|
||||
constexpr Result TagRemoved(ErrorModule::NFP, 97);
|
||||
constexpr Result ApplicationAreaIsNotInitialized(ErrorModule::NFP, 128);
|
||||
constexpr Result WrongApplicationAreaId(ErrorModule::NFP, 152);
|
||||
constexpr Result ApplicationAreaExist(ErrorModule::NFP, 168);
|
||||
|
@ -57,7 +58,7 @@ IUser::IUser(Module::Interface& nfp_interface_, Core::System& system_)
|
|||
{21, &IUser::GetNpadId, "GetNpadId"},
|
||||
{22, &IUser::GetApplicationAreaSize, "GetApplicationAreaSize"},
|
||||
{23, &IUser::AttachAvailabilityChangeEvent, "AttachAvailabilityChangeEvent"},
|
||||
{24, nullptr, "RecreateApplicationArea"},
|
||||
{24, &IUser::RecreateApplicationArea, "RecreateApplicationArea"},
|
||||
};
|
||||
RegisterHandlers(functions);
|
||||
|
||||
|
@ -597,6 +598,34 @@ void IUser::AttachAvailabilityChangeEvent(Kernel::HLERequestContext& ctx) {
|
|||
rb.PushCopyObjects(availability_change_event->GetReadableEvent());
|
||||
}
|
||||
|
||||
void IUser::RecreateApplicationArea(Kernel::HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto device_handle{rp.Pop<u64>()};
|
||||
const auto access_id{rp.Pop<u32>()};
|
||||
const auto data{ctx.ReadBuffer()};
|
||||
LOG_WARNING(Service_NFP, "(STUBBED) called, device_handle={}, data_size={}, access_id={}",
|
||||
device_handle, access_id, data.size());
|
||||
|
||||
if (state == State::NonInitialized) {
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ErrCodes::NfcDisabled);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(german77): Loop through all interfaces
|
||||
if (device_handle == nfp_interface.GetHandle()) {
|
||||
const auto result = nfp_interface.RecreateApplicationArea(access_id, data);
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(result);
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_ERROR(Service_NFP, "Handle not found, device_handle={}", device_handle);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ErrCodes::DeviceNotFound);
|
||||
}
|
||||
|
||||
Module::Interface::Interface(std::shared_ptr<Module> module_, Core::System& system_,
|
||||
const char* name)
|
||||
: ServiceFramework{system_, name}, module{std::move(module_)},
|
||||
|
@ -621,14 +650,14 @@ bool Module::Interface::LoadAmiiboFile(const std::string& filename) {
|
|||
Common::FS::FileType::BinaryFile};
|
||||
|
||||
if (!amiibo_file.IsOpen()) {
|
||||
LOG_ERROR(Core, "Amiibo is already on use");
|
||||
LOG_ERROR(Service_NFP, "Amiibo is already on use");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Workaround for files with missing password data
|
||||
std::array<u8, sizeof(EncryptedNTAG215File)> buffer{};
|
||||
if (amiibo_file.Read(buffer) < tag_size_without_password) {
|
||||
LOG_ERROR(Core, "Failed to read amiibo file");
|
||||
LOG_ERROR(Service_NFP, "Failed to read amiibo file");
|
||||
return false;
|
||||
}
|
||||
memcpy(&encrypted_tag_data, buffer.data(), sizeof(EncryptedNTAG215File));
|
||||
|
@ -759,12 +788,12 @@ Result Module::Interface::Flush() {
|
|||
bool is_character_equal = tmp_encrypted_tag_data.user_memory.model_info.character_id ==
|
||||
tag_data.model_info.character_id;
|
||||
if (!is_uuid_equal || !is_character_equal) {
|
||||
LOG_ERROR(Core, "Not the same amiibo");
|
||||
LOG_ERROR(Service_NFP, "Not the same amiibo");
|
||||
return ErrCodes::WriteAmiiboFailed;
|
||||
}
|
||||
|
||||
if (!AmiiboCrypto::EncodeAmiibo(tag_data, encrypted_tag_data)) {
|
||||
LOG_ERROR(Core, "Failed to encode data");
|
||||
LOG_ERROR(Service_NFP, "Failed to encode data");
|
||||
return ErrCodes::WriteAmiiboFailed;
|
||||
}
|
||||
|
||||
|
@ -830,13 +859,13 @@ Result Module::Interface::GetCommonInfo(CommonInfo& common_info) const {
|
|||
return ErrCodes::WrongDeviceState;
|
||||
}
|
||||
|
||||
if (is_data_decoded) {
|
||||
if (is_data_decoded && tag_data.settings.settings.amiibo_initialized != 0) {
|
||||
const auto& settings = tag_data.settings;
|
||||
// TODO: Validate this data
|
||||
common_info = {
|
||||
.last_write_year = static_cast<u16>(settings.write_date.year.Value()),
|
||||
.last_write_month = static_cast<u8>(settings.write_date.month.Value()),
|
||||
.last_write_day = static_cast<u8>(settings.write_date.day.Value()),
|
||||
.last_write_year = settings.write_date.GetYear(),
|
||||
.last_write_month = settings.write_date.GetMonth(),
|
||||
.last_write_day = settings.write_date.GetDay(),
|
||||
.write_counter = settings.crc_counter,
|
||||
.version = 1,
|
||||
.application_area_size = sizeof(ApplicationArea),
|
||||
|
@ -877,10 +906,15 @@ Result Module::Interface::GetModelInfo(ModelInfo& model_info) const {
|
|||
Result Module::Interface::GetRegisterInfo(RegisterInfo& register_info) const {
|
||||
if (device_state != DeviceState::TagMounted) {
|
||||
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
||||
if (device_state == DeviceState::TagRemoved) {
|
||||
return ErrCodes::TagRemoved;
|
||||
}
|
||||
return ErrCodes::WrongDeviceState;
|
||||
}
|
||||
|
||||
if (is_data_decoded) {
|
||||
Service::Mii::MiiManager manager;
|
||||
|
||||
if (is_data_decoded && tag_data.settings.settings.amiibo_initialized != 0) {
|
||||
const auto& settings = tag_data.settings;
|
||||
|
||||
// Amiibo name is u16 while the register info is u8. Figure out how to handle this properly
|
||||
|
@ -891,10 +925,10 @@ Result Module::Interface::GetRegisterInfo(RegisterInfo& register_info) const {
|
|||
|
||||
// TODO: Validate this data
|
||||
register_info = {
|
||||
.mii_char_info = AmiiboCrypto::AmiiboRegisterInfoToMii(tag_data.owner_mii),
|
||||
.first_write_year = static_cast<u16>(settings.init_date.year.Value()),
|
||||
.first_write_month = static_cast<u8>(settings.init_date.month.Value()),
|
||||
.first_write_day = static_cast<u8>(settings.init_date.day.Value()),
|
||||
.mii_char_info = manager.ConvertV3ToCharInfo(tag_data.owner_mii),
|
||||
.first_write_year = settings.init_date.GetYear(),
|
||||
.first_write_month = settings.init_date.GetMonth(),
|
||||
.first_write_day = settings.init_date.GetDay(),
|
||||
.amiibo_name = amiibo_name,
|
||||
.unknown = {},
|
||||
};
|
||||
|
@ -903,7 +937,6 @@ Result Module::Interface::GetRegisterInfo(RegisterInfo& register_info) const {
|
|||
}
|
||||
|
||||
// Generate a generic answer
|
||||
Service::Mii::MiiManager manager;
|
||||
register_info = {
|
||||
.mii_char_info = manager.BuildDefault(0),
|
||||
.first_write_year = 2022,
|
||||
|
@ -918,6 +951,9 @@ Result Module::Interface::GetRegisterInfo(RegisterInfo& register_info) const {
|
|||
Result Module::Interface::OpenApplicationArea(u32 access_id) {
|
||||
if (device_state != DeviceState::TagMounted) {
|
||||
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
||||
if (device_state == DeviceState::TagRemoved) {
|
||||
return ErrCodes::TagRemoved;
|
||||
}
|
||||
return ErrCodes::WrongDeviceState;
|
||||
}
|
||||
|
||||
|
@ -944,6 +980,9 @@ Result Module::Interface::OpenApplicationArea(u32 access_id) {
|
|||
Result Module::Interface::GetApplicationArea(ApplicationArea& data) const {
|
||||
if (device_state != DeviceState::TagMounted) {
|
||||
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
||||
if (device_state == DeviceState::TagRemoved) {
|
||||
return ErrCodes::TagRemoved;
|
||||
}
|
||||
return ErrCodes::WrongDeviceState;
|
||||
}
|
||||
|
||||
|
@ -960,6 +999,9 @@ Result Module::Interface::GetApplicationArea(ApplicationArea& data) const {
|
|||
Result Module::Interface::SetApplicationArea(const std::vector<u8>& data) {
|
||||
if (device_state != DeviceState::TagMounted) {
|
||||
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
||||
if (device_state == DeviceState::TagRemoved) {
|
||||
return ErrCodes::TagRemoved;
|
||||
}
|
||||
return ErrCodes::WrongDeviceState;
|
||||
}
|
||||
|
||||
|
@ -980,6 +1022,9 @@ Result Module::Interface::SetApplicationArea(const std::vector<u8>& data) {
|
|||
Result Module::Interface::CreateApplicationArea(u32 access_id, const std::vector<u8>& data) {
|
||||
if (device_state != DeviceState::TagMounted) {
|
||||
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
||||
if (device_state == DeviceState::TagRemoved) {
|
||||
return ErrCodes::TagRemoved;
|
||||
}
|
||||
return ErrCodes::WrongDeviceState;
|
||||
}
|
||||
|
||||
|
@ -999,6 +1044,26 @@ Result Module::Interface::CreateApplicationArea(u32 access_id, const std::vector
|
|||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result Module::Interface::RecreateApplicationArea(u32 access_id, const std::vector<u8>& data) {
|
||||
if (device_state != DeviceState::TagMounted) {
|
||||
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
||||
if (device_state == DeviceState::TagRemoved) {
|
||||
return ErrCodes::TagRemoved;
|
||||
}
|
||||
return ErrCodes::WrongDeviceState;
|
||||
}
|
||||
|
||||
if (data.size() != sizeof(ApplicationArea)) {
|
||||
LOG_ERROR(Service_NFP, "Wrong data size {}", data.size());
|
||||
return ResultUnknown;
|
||||
}
|
||||
|
||||
std::memcpy(&tag_data.application_area, data.data(), sizeof(ApplicationArea));
|
||||
tag_data.application_area_id = access_id;
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
u64 Module::Interface::GetHandle() const {
|
||||
// Generate a handle based of the npad id
|
||||
return static_cast<u64>(npad_id);
|
||||
|
|
|
@ -55,7 +55,7 @@ struct ModelInfo {
|
|||
static_assert(sizeof(ModelInfo) == 0x40, "ModelInfo is an invalid size");
|
||||
|
||||
struct RegisterInfo {
|
||||
Service::Mii::MiiInfo mii_char_info;
|
||||
Service::Mii::CharInfo mii_char_info;
|
||||
u16 first_write_year;
|
||||
u8 first_write_month;
|
||||
u8 first_write_day;
|
||||
|
@ -96,6 +96,7 @@ public:
|
|||
Result GetApplicationArea(ApplicationArea& data) const;
|
||||
Result SetApplicationArea(const std::vector<u8>& data);
|
||||
Result CreateApplicationArea(u32 access_id, const std::vector<u8>& data);
|
||||
Result RecreateApplicationArea(u32 access_id, const std::vector<u8>& data);
|
||||
|
||||
u64 GetHandle() const;
|
||||
DeviceState GetCurrentState() const;
|
||||
|
@ -152,6 +153,7 @@ private:
|
|||
void GetNpadId(Kernel::HLERequestContext& ctx);
|
||||
void GetApplicationAreaSize(Kernel::HLERequestContext& ctx);
|
||||
void AttachAvailabilityChangeEvent(Kernel::HLERequestContext& ctx);
|
||||
void RecreateApplicationArea(Kernel::HLERequestContext& ctx);
|
||||
|
||||
KernelHelpers::ServiceContext service_context;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue