2015-12-04 22:05:23 +01:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <string>
|
2019-02-09 17:00:57 +01:00
|
|
|
#include <boost/crc.hpp>
|
2015-12-04 22:05:23 +01:00
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/logging/log.h"
|
|
|
|
#include "common/string_util.h"
|
2018-10-13 23:08:37 +02:00
|
|
|
#include "core/core.h"
|
2019-02-09 17:00:57 +01:00
|
|
|
#include "core/frontend/applets/mii_selector.h"
|
2016-09-21 08:52:38 +02:00
|
|
|
#include "core/hle/applets/mii_selector.h"
|
2015-12-04 22:05:23 +01:00
|
|
|
#include "core/hle/kernel/kernel.h"
|
|
|
|
#include "core/hle/kernel/shared_memory.h"
|
|
|
|
#include "core/hle/result.h"
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-02-19 02:34:18 +01:00
|
|
|
namespace HLE::Applets {
|
2015-12-04 22:05:23 +01:00
|
|
|
|
|
|
|
ResultCode MiiSelector::ReceiveParameter(const Service::APT::MessageParameter& parameter) {
|
2018-01-25 14:39:54 +01:00
|
|
|
if (parameter.signal != Service::APT::SignalType::Request) {
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_ERROR(Service_APT, "unsupported signal {}", static_cast<u32>(parameter.signal));
|
2015-12-04 22:05:23 +01:00
|
|
|
UNIMPLEMENTED();
|
|
|
|
// TODO(Subv): Find the right error code
|
|
|
|
return ResultCode(-1);
|
|
|
|
}
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
// The LibAppJustStarted message contains a buffer with the size of the framebuffer shared
|
|
|
|
// memory.
|
2016-05-05 19:36:07 +02:00
|
|
|
// Create the SharedMemory that will hold the framebuffer data
|
|
|
|
Service::APT::CaptureBufferInfo capture_info;
|
2016-04-16 12:18:49 +02:00
|
|
|
ASSERT(sizeof(capture_info) == parameter.buffer.size());
|
2016-05-05 19:36:07 +02:00
|
|
|
|
2016-04-16 12:18:49 +02:00
|
|
|
memcpy(&capture_info, parameter.buffer.data(), sizeof(capture_info));
|
2016-05-09 00:10:53 +02:00
|
|
|
|
2016-05-05 19:36:07 +02:00
|
|
|
using Kernel::MemoryPermission;
|
2016-05-09 00:10:53 +02:00
|
|
|
// Create a SharedMemory that directly points to this heap block.
|
2018-10-13 23:08:37 +02:00
|
|
|
framebuffer_memory = Core::System::GetInstance().Kernel().CreateSharedMemoryForApplet(
|
2018-11-06 21:00:47 +01:00
|
|
|
0, capture_info.size, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite,
|
2017-08-19 18:37:21 +02:00
|
|
|
"MiiSelector Memory");
|
2016-05-05 19:36:07 +02:00
|
|
|
|
|
|
|
// Send the response message with the newly created SharedMemory
|
2015-12-04 22:05:23 +01:00
|
|
|
Service::APT::MessageParameter result;
|
2018-01-25 14:39:54 +01:00
|
|
|
result.signal = Service::APT::SignalType::Response;
|
2016-04-16 12:18:49 +02:00
|
|
|
result.buffer.clear();
|
2018-01-25 14:39:54 +01:00
|
|
|
result.destination_id = Service::APT::AppletId::Application;
|
|
|
|
result.sender_id = id;
|
2015-12-04 22:05:23 +01:00
|
|
|
result.object = framebuffer_memory;
|
|
|
|
|
2018-01-25 14:39:54 +01:00
|
|
|
SendParameter(result);
|
2015-12-04 22:05:23 +01:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode MiiSelector::StartImpl(const Service::APT::AppletStartupParameter& parameter) {
|
2019-02-09 17:00:57 +01:00
|
|
|
ASSERT_MSG(parameter.buffer.size() == sizeof(config),
|
|
|
|
"The size of the parameter (MiiConfig) is wrong");
|
|
|
|
|
|
|
|
memcpy(&config, parameter.buffer.data(), parameter.buffer.size());
|
|
|
|
|
|
|
|
using namespace Frontend;
|
|
|
|
frontend_applet = GetRegisteredMiiSelector();
|
|
|
|
if (frontend_applet) {
|
|
|
|
MiiSelectorConfig frontend_config = ToFrontendConfig(config);
|
|
|
|
frontend_applet->Setup(&frontend_config);
|
|
|
|
}
|
|
|
|
|
2016-12-07 23:11:39 +01:00
|
|
|
is_running = true;
|
2019-02-09 17:00:57 +01:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2015-12-04 22:05:23 +01:00
|
|
|
|
2019-02-09 17:00:57 +01:00
|
|
|
void MiiSelector::Update() {
|
|
|
|
using namespace Frontend;
|
|
|
|
const MiiSelectorData* data = frontend_applet->ReceiveData();
|
|
|
|
result.return_code = data->return_code;
|
|
|
|
result.selected_mii_data = data->mii;
|
|
|
|
// Calculate the checksum of the selected Mii, see https://www.3dbrew.org/wiki/Mii#Checksum
|
|
|
|
result.mii_data_checksum = boost::crc<16, 0x1021, 0, 0, false, false>(
|
|
|
|
&result.selected_mii_data, sizeof(HLE::Applets::MiiData) + sizeof(result.unknown1));
|
|
|
|
result.selected_guest_mii_index = 0xFFFFFFFF;
|
2015-12-04 22:05:23 +01:00
|
|
|
|
2019-02-09 17:00:57 +01:00
|
|
|
// TODO(Subv): We're finalizing the applet immediately after it's started,
|
|
|
|
// but we should defer this call until after all the input has been collected.
|
|
|
|
Finalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MiiSelector::Finalize() {
|
|
|
|
// Let the application know that we're closing
|
|
|
|
Service::APT::MessageParameter message;
|
|
|
|
message.buffer.resize(sizeof(MiiResult));
|
|
|
|
std::memcpy(message.buffer.data(), &result, message.buffer.size());
|
|
|
|
message.signal = Service::APT::SignalType::WakeupByExit;
|
|
|
|
message.destination_id = Service::APT::AppletId::Application;
|
|
|
|
message.sender_id = id;
|
|
|
|
SendParameter(message);
|
|
|
|
|
|
|
|
is_running = false;
|
|
|
|
}
|
2016-04-16 12:18:49 +02:00
|
|
|
|
2019-02-09 17:00:57 +01:00
|
|
|
MiiResult MiiSelector::GetStandardMiiResult() {
|
2018-11-24 14:35:06 +01:00
|
|
|
// This data was obtained by writing the returned buffer in AppletManager::GlanceParameter of
|
|
|
|
// the LLEd Mii picker of version system version 11.8.0 to a file and then matching the values
|
|
|
|
// to the members of the MiiResult struct
|
|
|
|
MiiData mii_data;
|
|
|
|
mii_data.mii_id = 0x03001030;
|
|
|
|
mii_data.system_id = 0xD285B6B300C8850A;
|
|
|
|
mii_data.specialness_and_creation_date = 0x98391EE4;
|
|
|
|
mii_data.creator_mac = {0x40, 0xF4, 0x07, 0xB7, 0x37, 0x10};
|
|
|
|
mii_data.padding = 0x0;
|
|
|
|
mii_data.mii_information = 0xA600;
|
|
|
|
mii_data.mii_name = {'C', 'i', 't', 'r', 'a', 0x0, 0x0, 0x0, 0x0, 0x0};
|
|
|
|
mii_data.width_height = 0x4040;
|
2018-11-27 14:57:51 +01:00
|
|
|
mii_data.appearance_bits1.raw = 0x0;
|
|
|
|
mii_data.appearance_bits2.raw = 0x0;
|
2018-11-24 14:35:06 +01:00
|
|
|
mii_data.hair_style = 0x21;
|
2018-11-27 14:57:51 +01:00
|
|
|
mii_data.appearance_bits3.hair_color.Assign(0x1);
|
|
|
|
mii_data.appearance_bits3.flip_hair.Assign(0x0);
|
2018-11-24 14:35:06 +01:00
|
|
|
mii_data.unknown1 = 0x02684418;
|
2018-11-27 14:57:51 +01:00
|
|
|
mii_data.appearance_bits4.eyebrow_style.Assign(0x6);
|
|
|
|
mii_data.appearance_bits4.eyebrow_color.Assign(0x1);
|
|
|
|
mii_data.appearance_bits5.eyebrow_scale.Assign(0x4);
|
|
|
|
mii_data.appearance_bits5.eyebrow_yscale.Assign(0x3);
|
2018-11-24 14:35:06 +01:00
|
|
|
mii_data.appearance_bits6 = 0x4614;
|
|
|
|
mii_data.unknown2 = 0x81121768;
|
|
|
|
mii_data.allow_copying = 0x0D;
|
|
|
|
mii_data.unknown3 = {0x0, 0x0, 0x29, 0x0, 0x52, 0x48, 0x50};
|
|
|
|
mii_data.author_name = {'f', 'l', 'T', 'o', 'b', 'i', 0x0, 0x0, 0x0, 0x0};
|
|
|
|
|
2016-04-16 12:18:49 +02:00
|
|
|
MiiResult result;
|
2018-11-24 14:35:06 +01:00
|
|
|
result.return_code = 0x0;
|
|
|
|
result.is_guest_mii_selected = 0x0;
|
|
|
|
result.selected_guest_mii_index = 0xFFFFFFFF;
|
|
|
|
result.selected_mii_data = mii_data;
|
|
|
|
result.unknown1 = 0x0;
|
|
|
|
result.mii_data_checksum = 0x056C;
|
|
|
|
result.guest_mii_name.fill(0x0);
|
2016-04-24 11:39:06 +02:00
|
|
|
|
2019-02-09 17:00:57 +01:00
|
|
|
return result;
|
2015-12-04 22:05:23 +01:00
|
|
|
}
|
|
|
|
|
2019-02-09 17:00:57 +01:00
|
|
|
Frontend::MiiSelectorConfig MiiSelector::ToFrontendConfig(const MiiConfig& config) const {
|
|
|
|
Frontend::MiiSelectorConfig frontend_config;
|
|
|
|
frontend_config.enable_cancel_button = config.enable_cancel_button == 1;
|
|
|
|
frontend_config.title = reinterpret_cast<const char16_t*>(config.title.data());
|
|
|
|
frontend_config.initially_selected_mii_index = config.initially_selected_mii_index;
|
|
|
|
return frontend_config;
|
|
|
|
}
|
2019-02-19 02:34:18 +01:00
|
|
|
} // namespace HLE::Applets
|