diff options
Diffstat (limited to 'src')
31 files changed, 479 insertions, 189 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 04cf3f5b9..c28abc24c 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -393,6 +393,8 @@ add_library(core STATIC hle/service/hid/xcd.cpp hle/service/hid/xcd.h hle/service/hid/errors.h + hle/service/hid/controllers/console_sixaxis.cpp + hle/service/hid/controllers/console_sixaxis.h hle/service/hid/controllers/controller_base.cpp hle/service/hid/controllers/controller_base.h hle/service/hid/controllers/debug_pad.cpp diff --git a/src/core/frontend/input.h b/src/core/frontend/input.h index 88ebc6497..0c5d2b3b0 100644 --- a/src/core/frontend/input.h +++ b/src/core/frontend/input.h @@ -11,6 +11,7 @@ #include <utility> #include "common/logging/log.h" #include "common/param_package.h" +#include "common/quaternion.h" #include "common/vector_math.h" namespace Input { @@ -143,9 +144,10 @@ using VibrationDevice = InputDevice<u8>; /** * A motion status is an object that returns a tuple of accelerometer state vector, - * gyroscope state vector, rotation state vector and orientation state matrix. + * gyroscope state vector, rotation state vector, orientation state matrix and quaterion state + * vector. * - * For both vectors: + * For both 3D vectors: * x+ is the same direction as RIGHT on D-pad. * y+ is normal to the touch screen, pointing outward. * z+ is the same direction as UP on D-pad. @@ -164,9 +166,13 @@ using VibrationDevice = InputDevice<u8>; * x vector * y vector * z vector + * + * For quaternion state vector + * xyz vector + * w float */ using MotionStatus = std::tuple<Common::Vec3<float>, Common::Vec3<float>, Common::Vec3<float>, - std::array<Common::Vec3f, 3>>; + std::array<Common::Vec3f, 3>, Common::Quaternion<f32>>; /** * A motion device is an input device that returns a motion status object diff --git a/src/core/hle/kernel/transfer_memory.cpp b/src/core/hle/kernel/transfer_memory.cpp index cad063e4d..1dd65468d 100644 --- a/src/core/hle/kernel/transfer_memory.cpp +++ b/src/core/hle/kernel/transfer_memory.cpp @@ -36,6 +36,10 @@ std::shared_ptr<TransferMemory> TransferMemory::Create(KernelCore& kernel, return transfer_memory; } +u8* TransferMemory::GetPointer() { + return memory.GetPointer(base_address); +} + const u8* TransferMemory::GetPointer() const { return memory.GetPointer(base_address); } diff --git a/src/core/hle/kernel/transfer_memory.h b/src/core/hle/kernel/transfer_memory.h index 521951424..59328c0fe 100644 --- a/src/core/hle/kernel/transfer_memory.h +++ b/src/core/hle/kernel/transfer_memory.h @@ -57,6 +57,9 @@ public: } /// Gets a pointer to the backing block of this instance. + u8* GetPointer(); + + /// Gets a pointer to the backing block of this instance. const u8* GetPointer() const; /// Gets the size of the memory backing this instance in bytes. diff --git a/src/core/hle/service/hid/controllers/console_sixaxis.cpp b/src/core/hle/service/hid/controllers/console_sixaxis.cpp new file mode 100644 index 000000000..913768fab --- /dev/null +++ b/src/core/hle/service/hid/controllers/console_sixaxis.cpp @@ -0,0 +1,90 @@ +// Copyright 2021 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "common/settings.h" +#include "core/core_timing.h" +#include "core/hle/service/hid/controllers/console_sixaxis.h" + +namespace Service::HID { +constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3C200; + +Controller_ConsoleSixAxis::Controller_ConsoleSixAxis(Core::System& system) + : ControllerBase(system) {} +Controller_ConsoleSixAxis::~Controller_ConsoleSixAxis() = default; + +void Controller_ConsoleSixAxis::OnInit() {} + +void Controller_ConsoleSixAxis::OnRelease() {} + +void Controller_ConsoleSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, + std::size_t size) { + seven_six_axis.header.timestamp = core_timing.GetCPUTicks(); + seven_six_axis.header.total_entry_count = 17; + + if (!IsControllerActivated() || !is_transfer_memory_set) { + seven_six_axis.header.entry_count = 0; + seven_six_axis.header.last_entry_index = 0; + return; + } + seven_six_axis.header.entry_count = 16; + + const auto& last_entry = + seven_six_axis.sevensixaxis_states[seven_six_axis.header.last_entry_index]; + seven_six_axis.header.last_entry_index = (seven_six_axis.header.last_entry_index + 1) % 17; + auto& cur_entry = seven_six_axis.sevensixaxis_states[seven_six_axis.header.last_entry_index]; + + cur_entry.sampling_number = last_entry.sampling_number + 1; + cur_entry.sampling_number2 = cur_entry.sampling_number; + + // Try to read sixaxis sensor states + MotionDevice motion_device{}; + const auto& device = motions[0]; + if (device) { + std::tie(motion_device.accel, motion_device.gyro, motion_device.rotation, + motion_device.orientation, motion_device.quaternion) = device->GetStatus(); + console_six_axis.is_seven_six_axis_sensor_at_rest = motion_device.gyro.Length2() < 0.0001f; + } + + cur_entry.accel = motion_device.accel; + // Zero gyro values as they just mess up with the camera + // Note: Probably a correct sensivity setting must be set + cur_entry.gyro = {}; + cur_entry.quaternion = { + { + motion_device.quaternion.xyz.y, + motion_device.quaternion.xyz.x, + -motion_device.quaternion.w, + }, + -motion_device.quaternion.xyz.z, + }; + + console_six_axis.sampling_number++; + // TODO(German77): Find the purpose of those values + console_six_axis.verticalization_error = 0.0f; + console_six_axis.gyro_bias = {0.0f, 0.0f, 0.0f}; + + // Update console six axis shared memory + std::memcpy(data + SHARED_MEMORY_OFFSET, &console_six_axis, sizeof(console_six_axis)); + // Update seven six axis transfer memory + std::memcpy(transfer_memory, &seven_six_axis, sizeof(seven_six_axis)); +} + +void Controller_ConsoleSixAxis::OnLoadInputDevices() { + const auto player = Settings::values.players.GetValue()[0]; + std::transform(player.motions.begin() + Settings::NativeMotion::MOTION_HID_BEGIN, + player.motions.begin() + Settings::NativeMotion::MOTION_HID_END, motions.begin(), + Input::CreateDevice<Input::MotionDevice>); +} + +void Controller_ConsoleSixAxis::SetTransferMemoryPointer(u8* t_mem) { + is_transfer_memory_set = true; + transfer_memory = t_mem; +} + +void Controller_ConsoleSixAxis::ResetTimestamp() { + auto& cur_entry = seven_six_axis.sevensixaxis_states[seven_six_axis.header.last_entry_index]; + cur_entry.sampling_number = 0; + cur_entry.sampling_number2 = 0; +} +} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/console_sixaxis.h b/src/core/hle/service/hid/controllers/console_sixaxis.h new file mode 100644 index 000000000..1fae98e94 --- /dev/null +++ b/src/core/hle/service/hid/controllers/console_sixaxis.h @@ -0,0 +1,80 @@ +// Copyright 2021 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <array> +#include "common/bit_field.h" +#include "common/common_types.h" +#include "common/quaternion.h" +#include "core/frontend/input.h" +#include "core/hle/service/hid/controllers/controller_base.h" + +namespace Service::HID { +class Controller_ConsoleSixAxis final : public ControllerBase { +public: + explicit Controller_ConsoleSixAxis(Core::System& system); + ~Controller_ConsoleSixAxis() override; + + // Called when the controller is initialized + void OnInit() override; + + // When the controller is released + void OnRelease() override; + + // When the controller is requesting an update for the shared memory + void OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, size_t size) override; + + // Called when input devices should be loaded + void OnLoadInputDevices() override; + + // Called on InitializeSevenSixAxisSensor + void SetTransferMemoryPointer(u8* t_mem); + + // Called on ResetSevenSixAxisSensorTimestamp + void ResetTimestamp(); + +private: + struct SevenSixAxisState { + INSERT_PADDING_WORDS(4); // unused + s64_le sampling_number{}; + s64_le sampling_number2{}; + u64 unknown{}; + Common::Vec3f accel{}; + Common::Vec3f gyro{}; + Common::Quaternion<f32> quaternion{}; + }; + static_assert(sizeof(SevenSixAxisState) == 0x50, "SevenSixAxisState is an invalid size"); + + struct SevenSixAxisMemory { + CommonHeader header{}; + std::array<SevenSixAxisState, 0x21> sevensixaxis_states{}; + }; + static_assert(sizeof(SevenSixAxisMemory) == 0xA70, "SevenSixAxisMemory is an invalid size"); + + struct ConsoleSharedMemory { + u64_le sampling_number{}; + bool is_seven_six_axis_sensor_at_rest{}; + f32 verticalization_error{}; + Common::Vec3f gyro_bias{}; + }; + static_assert(sizeof(ConsoleSharedMemory) == 0x20, "ConsoleSharedMemory is an invalid size"); + + struct MotionDevice { + Common::Vec3f accel; + Common::Vec3f gyro; + Common::Vec3f rotation; + std::array<Common::Vec3f, 3> orientation; + Common::Quaternion<f32> quaternion; + }; + + using MotionArray = + std::array<std::unique_ptr<Input::MotionDevice>, Settings::NativeMotion::NUM_MOTIONS_HID>; + MotionArray motions; + u8* transfer_memory = nullptr; + bool is_transfer_memory_set = false; + ConsoleSharedMemory console_six_axis{}; + SevenSixAxisMemory seven_six_axis{}; +}; +} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index 113a41254..249c300f6 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp @@ -654,8 +654,8 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing const auto& device = motions[i][e]; if (device) { std::tie(motion_devices[e].accel, motion_devices[e].gyro, - motion_devices[e].rotation, motion_devices[e].orientation) = - device->GetStatus(); + motion_devices[e].rotation, motion_devices[e].orientation, + motion_devices[e].quaternion) = device->GetStatus(); sixaxis_at_rest = sixaxis_at_rest && motion_devices[e].gyro.Length2() < 0.0001f; } } diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index c3b07bd41..085f42c48 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h @@ -8,6 +8,7 @@ #include <atomic> #include "common/bit_field.h" #include "common/common_types.h" +#include "common/quaternion.h" #include "common/settings.h" #include "core/frontend/input.h" #include "core/hle/kernel/object.h" @@ -467,6 +468,7 @@ private: Common::Vec3f gyro; Common::Vec3f rotation; std::array<Common::Vec3f, 3> orientation; + Common::Quaternion<f32> quaternion; }; struct NfcXcdHandle { diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 2aa1942cb..9c4bf6d16 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -26,6 +26,7 @@ #include "core/hle/service/hid/xcd.h" #include "core/hle/service/service.h" +#include "core/hle/service/hid/controllers/console_sixaxis.h" #include "core/hle/service/hid/controllers/controller_base.h" #include "core/hle/service/hid/controllers/debug_pad.h" #include "core/hle/service/hid/controllers/gesture.h" @@ -67,7 +68,7 @@ IAppletResource::IAppletResource(Core::System& system_) MakeController<Controller_Stubbed>(HidController::UniquePad); MakeController<Controller_NPad>(HidController::NPad); MakeController<Controller_Gesture>(HidController::Gesture); - MakeController<Controller_Stubbed>(HidController::ConsoleSixAxisSensor); + MakeController<Controller_ConsoleSixAxis>(HidController::ConsoleSixAxisSensor); // Homebrew doesn't try to activate some controllers, so we activate them by default GetController<Controller_NPad>(HidController::NPad).ActivateController(); @@ -78,8 +79,6 @@ IAppletResource::IAppletResource(Core::System& system_) GetController<Controller_Stubbed>(HidController::CaptureButton).SetCommonHeaderOffset(0x5000); GetController<Controller_Stubbed>(HidController::InputDetector).SetCommonHeaderOffset(0x5200); GetController<Controller_Stubbed>(HidController::UniquePad).SetCommonHeaderOffset(0x5A00); - GetController<Controller_Stubbed>(HidController::ConsoleSixAxisSensor) - .SetCommonHeaderOffset(0x3C200); // Register update callbacks pad_update_event = Core::Timing::CreateEvent( @@ -1404,8 +1403,9 @@ void Hid::ActivateConsoleSixAxisSensor(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; - LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}", - applet_resource_user_id); + applet_resource->ActivateController(HidController::ConsoleSixAxisSensor); + + LOG_WARNING(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); @@ -1455,8 +1455,9 @@ void Hid::ActivateSevenSixAxisSensor(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; - LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}", - applet_resource_user_id); + applet_resource->ActivateController(HidController::ConsoleSixAxisSensor); + + LOG_WARNING(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); @@ -1518,8 +1519,15 @@ void Hid::InitializeSevenSixAxisSensor(Kernel::HLERequestContext& ctx) { ASSERT_MSG(t_mem_1->GetSize() == 0x1000, "t_mem_1 has incorrect size"); ASSERT_MSG(t_mem_2->GetSize() == 0x7F000, "t_mem_2 has incorrect size"); + // Activate console six axis controller + applet_resource->GetController<Controller_ConsoleSixAxis>(HidController::ConsoleSixAxisSensor) + .ActivateController(); + + applet_resource->GetController<Controller_ConsoleSixAxis>(HidController::ConsoleSixAxisSensor) + .SetTransferMemoryPointer(t_mem_1->GetPointer()); + LOG_WARNING(Service_HID, - "(STUBBED) called, t_mem_1_handle=0x{:08X}, t_mem_2_handle=0x{:08X}, " + "called, t_mem_1_handle=0x{:08X}, t_mem_2_handle=0x{:08X}, " "applet_resource_user_id={}", t_mem_1_handle, t_mem_2_handle, applet_resource_user_id); @@ -1542,8 +1550,10 @@ void Hid::ResetSevenSixAxisSensorTimestamp(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; - LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}", - applet_resource_user_id); + applet_resource->GetController<Controller_ConsoleSixAxis>(HidController::ConsoleSixAxisSensor) + .ResetTimestamp(); + + LOG_WARNING(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 4a10211f6..ed776fc49 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp @@ -24,10 +24,10 @@ namespace Loader { AppLoader_DeconstructedRomDirectory::AppLoader_DeconstructedRomDirectory(FileSys::VirtualFile file_, bool override_update) : AppLoader(std::move(file_)), override_update(override_update) { - const auto dir = file->GetContainingDirectory(); + const auto file_dir = file->GetContainingDirectory(); // Title ID - const auto npdm = dir->GetFile("main.npdm"); + const auto npdm = file_dir->GetFile("main.npdm"); if (npdm != nullptr) { const auto res = metadata.Load(npdm); if (res == ResultStatus::Success) @@ -37,7 +37,7 @@ AppLoader_DeconstructedRomDirectory::AppLoader_DeconstructedRomDirectory(FileSys // Icon FileSys::VirtualFile icon_file = nullptr; for (const auto& language : FileSys::LANGUAGE_NAMES) { - icon_file = dir->GetFile("icon_" + std::string(language) + ".dat"); + icon_file = file_dir->GetFile("icon_" + std::string(language) + ".dat"); if (icon_file != nullptr) { icon_data = icon_file->ReadAllBytes(); break; @@ -46,7 +46,7 @@ AppLoader_DeconstructedRomDirectory::AppLoader_DeconstructedRomDirectory(FileSys if (icon_data.empty()) { // Any png, jpeg, or bmp file - const auto& files = dir->GetFiles(); + const auto& files = file_dir->GetFiles(); const auto icon_iter = std::find_if(files.begin(), files.end(), [](const FileSys::VirtualFile& file) { return file->GetExtension() == "png" || file->GetExtension() == "jpg" || @@ -57,9 +57,9 @@ AppLoader_DeconstructedRomDirectory::AppLoader_DeconstructedRomDirectory(FileSys } // Metadata - FileSys::VirtualFile nacp_file = dir->GetFile("control.nacp"); + FileSys::VirtualFile nacp_file = file_dir->GetFile("control.nacp"); if (nacp_file == nullptr) { - const auto& files = dir->GetFiles(); + const auto& files = file_dir->GetFiles(); const auto nacp_iter = std::find_if(files.begin(), files.end(), [](const FileSys::VirtualFile& file) { return file->GetExtension() == "nacp"; @@ -200,17 +200,21 @@ AppLoader_DeconstructedRomDirectory::LoadResult AppLoader_DeconstructedRomDirect LoadParameters{metadata.GetMainThreadPriority(), metadata.GetMainThreadStackSize()}}; } -ResultStatus AppLoader_DeconstructedRomDirectory::ReadRomFS(FileSys::VirtualFile& dir) { - if (romfs == nullptr) +ResultStatus AppLoader_DeconstructedRomDirectory::ReadRomFS(FileSys::VirtualFile& out_dir) { + if (romfs == nullptr) { return ResultStatus::ErrorNoRomFS; - dir = romfs; + } + + out_dir = romfs; return ResultStatus::Success; } -ResultStatus AppLoader_DeconstructedRomDirectory::ReadIcon(std::vector<u8>& buffer) { - if (icon_data.empty()) +ResultStatus AppLoader_DeconstructedRomDirectory::ReadIcon(std::vector<u8>& out_buffer) { + if (icon_data.empty()) { return ResultStatus::ErrorNoIcon; - buffer = icon_data; + } + + out_buffer = icon_data; return ResultStatus::Success; } @@ -219,10 +223,12 @@ ResultStatus AppLoader_DeconstructedRomDirectory::ReadProgramId(u64& out_program return ResultStatus::Success; } -ResultStatus AppLoader_DeconstructedRomDirectory::ReadTitle(std::string& title) { - if (name.empty()) +ResultStatus AppLoader_DeconstructedRomDirectory::ReadTitle(std::string& out_title) { + if (name.empty()) { return ResultStatus::ErrorNoControl; - title = name; + } + + out_title = name; return ResultStatus::Success; } @@ -230,12 +236,12 @@ bool AppLoader_DeconstructedRomDirectory::IsRomFSUpdatable() const { return false; } -ResultStatus AppLoader_DeconstructedRomDirectory::ReadNSOModules(Modules& modules) { +ResultStatus AppLoader_DeconstructedRomDirectory::ReadNSOModules(Modules& out_modules) { if (!is_loaded) { return ResultStatus::ErrorNotInitialized; } - modules = this->modules; + out_modules = this->modules; return ResultStatus::Success; } diff --git a/src/core/loader/deconstructed_rom_directory.h b/src/core/loader/deconstructed_rom_directory.h index 3c968580f..c2b46e1bf 100644 --- a/src/core/loader/deconstructed_rom_directory.h +++ b/src/core/loader/deconstructed_rom_directory.h @@ -43,13 +43,13 @@ public: LoadResult Load(Kernel::Process& process, Core::System& system) override; - ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; - ResultStatus ReadIcon(std::vector<u8>& buffer) override; + ResultStatus ReadRomFS(FileSys::VirtualFile& out_dir) override; + ResultStatus ReadIcon(std::vector<u8>& out_buffer) override; ResultStatus ReadProgramId(u64& out_program_id) override; ResultStatus ReadTitle(std::string& title) override; bool IsRomFSUpdatable() const override; - ResultStatus ReadNSOModules(Modules& modules) override; + ResultStatus ReadNSOModules(Modules& out_modules) override; private: FileSys::ProgramMetadata metadata; diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index f4a339390..627c18c7e 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp @@ -364,21 +364,24 @@ SectionID ElfReader::GetSectionByName(const char* name, int firstSection) const namespace Loader { -AppLoader_ELF::AppLoader_ELF(FileSys::VirtualFile file) : AppLoader(std::move(file)) {} +AppLoader_ELF::AppLoader_ELF(FileSys::VirtualFile file_) : AppLoader(std::move(file_)) {} -FileType AppLoader_ELF::IdentifyType(const FileSys::VirtualFile& file) { +FileType AppLoader_ELF::IdentifyType(const FileSys::VirtualFile& elf_file) { static constexpr u16 ELF_MACHINE_ARM{0x28}; u32 magic = 0; - if (4 != file->ReadObject(&magic)) + if (4 != elf_file->ReadObject(&magic)) { return FileType::Error; + } u16 machine = 0; - if (2 != file->ReadObject(&machine, 18)) + if (2 != elf_file->ReadObject(&machine, 18)) { return FileType::Error; + } - if (Common::MakeMagic('\x7f', 'E', 'L', 'F') == magic && ELF_MACHINE_ARM == machine) + if (Common::MakeMagic('\x7f', 'E', 'L', 'F') == magic && ELF_MACHINE_ARM == machine) { return FileType::ELF; + } return FileType::Error; } diff --git a/src/core/loader/elf.h b/src/core/loader/elf.h index 2067932c7..2b86c0b49 100644 --- a/src/core/loader/elf.h +++ b/src/core/loader/elf.h @@ -20,11 +20,13 @@ public: explicit AppLoader_ELF(FileSys::VirtualFile file); /** - * Returns the type of the file - * @param file open file - * @return FileType found, or FileType::Error if this loader doesn't know it + * Identifies whether or not the given file is an ELF file. + * + * @param elf_file The file to identify. + * + * @return FileType::ELF, or FileType::Error if the file is not an ELF file. */ - static FileType IdentifyType(const FileSys::VirtualFile& file); + static FileType IdentifyType(const FileSys::VirtualFile& elf_file); FileType GetFileType() const override { return IdentifyType(file); diff --git a/src/core/loader/kip.cpp b/src/core/loader/kip.cpp index 55e6de794..9b447da2a 100644 --- a/src/core/loader/kip.cpp +++ b/src/core/loader/kip.cpp @@ -24,9 +24,9 @@ AppLoader_KIP::AppLoader_KIP(FileSys::VirtualFile file_) AppLoader_KIP::~AppLoader_KIP() = default; -FileType AppLoader_KIP::IdentifyType(const FileSys::VirtualFile& file) { +FileType AppLoader_KIP::IdentifyType(const FileSys::VirtualFile& in_file) { u32_le magic{}; - if (file->GetSize() < sizeof(u32) || file->ReadObject(&magic) != sizeof(u32)) { + if (in_file->GetSize() < sizeof(u32) || in_file->ReadObject(&magic) != sizeof(u32)) { return FileType::Error; } @@ -56,10 +56,10 @@ AppLoader::LoadResult AppLoader_KIP::Load(Kernel::Process& process, return {kip->GetStatus(), {}}; } - const auto get_kip_address_space_type = [](const auto& kip) { - return kip.Is64Bit() - ? (kip.Is39BitAddressSpace() ? FileSys::ProgramAddressSpaceType::Is39Bit - : FileSys::ProgramAddressSpaceType::Is36Bit) + const auto get_kip_address_space_type = [](const auto& kip_type) { + return kip_type.Is64Bit() + ? (kip_type.Is39BitAddressSpace() ? FileSys::ProgramAddressSpaceType::Is39Bit + : FileSys::ProgramAddressSpaceType::Is36Bit) : FileSys::ProgramAddressSpaceType::Is32Bit; }; diff --git a/src/core/loader/kip.h b/src/core/loader/kip.h index 14a85e295..2fe636f01 100644 --- a/src/core/loader/kip.h +++ b/src/core/loader/kip.h @@ -22,11 +22,13 @@ public: ~AppLoader_KIP() override; /** - * Returns the type of the file - * @param file open file - * @return FileType found, or FileType::Error if this loader doesn't know it + * Identifies whether or not the given file is a KIP. + * + * @param in_file The file to identify. + * + * @return FileType::KIP if found, or FileType::Error if unknown. */ - static FileType IdentifyType(const FileSys::VirtualFile& file); + static FileType IdentifyType(const FileSys::VirtualFile& in_file); FileType GetFileType() const override; diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index b2e5b13de..bf6db1ab1 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -152,21 +152,26 @@ public: /** * Returns the type of this file + * * @return FileType corresponding to the loaded file */ virtual FileType GetFileType() const = 0; /** * Load the application and return the created Process instance + * * @param process The newly created process. * @param system The system that this process is being loaded under. + * * @return The status result of the operation. */ virtual LoadResult Load(Kernel::Process& process, Core::System& system) = 0; /** * Get the code (typically .code section) of the application - * @param buffer Reference to buffer to store data + * + * @param[out] buffer Reference to buffer to store data + * * @return ResultStatus result of function */ virtual ResultStatus ReadCode(std::vector<u8>& buffer) { @@ -175,7 +180,9 @@ public: /** * Get the icon (typically icon section) of the application - * @param buffer Reference to buffer to store data + * + * @param[out] buffer Reference to buffer to store data + * * @return ResultStatus result of function */ virtual ResultStatus ReadIcon(std::vector<u8>& buffer) { @@ -186,7 +193,9 @@ public: * Get the banner (typically banner section) of the application * In the context of NX, this is the animation that displays in the bottom right of the screen * when a game boots. Stored in GIF format. - * @param buffer Reference to buffer to store data + * + * @param[out] buffer Reference to buffer to store data + * * @return ResultStatus result of function */ virtual ResultStatus ReadBanner(std::vector<u8>& buffer) { @@ -197,7 +206,9 @@ public: * Get the logo (typically logo section) of the application * In the context of NX, this is the static image that displays in the top left of the screen * when a game boots. Stored in JPEG format. - * @param buffer Reference to buffer to store data + * + * @param[out] buffer Reference to buffer to store data + * * @return ResultStatus result of function */ virtual ResultStatus ReadLogo(std::vector<u8>& buffer) { @@ -206,7 +217,9 @@ public: /** * Get the program id of the application - * @param out_program_id Reference to store program id into + * + * @param[out] out_program_id Reference to store program id into + * * @return ResultStatus result of function */ virtual ResultStatus ReadProgramId(u64& out_program_id) { @@ -216,19 +229,23 @@ public: /** * Get the RomFS of the application * Since the RomFS can be huge, we return a file reference instead of copying to a buffer - * @param file The directory containing the RomFS + * + * @param[out] out_file The directory containing the RomFS + * * @return ResultStatus result of function */ - virtual ResultStatus ReadRomFS(FileSys::VirtualFile& file) { + virtual ResultStatus ReadRomFS(FileSys::VirtualFile& out_file) { return ResultStatus::ErrorNotImplemented; } /** * Get the raw update of the application, should it come packed with one - * @param file The raw update NCA file (Program-type + * + * @param[out] out_file The raw update NCA file (Program-type) + * * @return ResultStatus result of function */ - virtual ResultStatus ReadUpdateRaw(FileSys::VirtualFile& file) { + virtual ResultStatus ReadUpdateRaw(FileSys::VirtualFile& out_file) { return ResultStatus::ErrorNotImplemented; } @@ -236,7 +253,8 @@ public: * Get whether or not updates can be applied to the RomFS. * By default, this is true, however for formats where it cannot be guaranteed that the RomFS is * the base game it should be set to false. - * @return bool whether or not updatable. + * + * @return bool indicating whether or not the RomFS is updatable. */ virtual bool IsRomFSUpdatable() const { return true; @@ -244,8 +262,9 @@ public: /** * Gets the difference between the start of the IVFC header and the start of level 6 (RomFS) - * data. Needed for bktr patching. - * @return IVFC offset for romfs. + * data. Needed for BKTR patching. + * + * @return IVFC offset for RomFS. */ virtual u64 ReadRomFSIVFCOffset() const { return 0; @@ -253,7 +272,9 @@ public: /** * Get the title of the application - * @param title Reference to store the application title into + * + * @param[out] title Reference to store the application title into + * * @return ResultStatus result of function */ virtual ResultStatus ReadTitle(std::string& title) { @@ -262,7 +283,9 @@ public: /** * Get the control data (CNMT) of the application - * @param control Reference to store the application control data into + * + * @param[out] control Reference to store the application control data into + * * @return ResultStatus result of function */ virtual ResultStatus ReadControlData(FileSys::NACP& control) { @@ -271,10 +294,12 @@ public: /** * Get the RomFS of the manual of the application - * @param file The raw manual RomFS of the game + * + * @param[out] out_file The raw manual RomFS of the game + * * @return ResultStatus result of function */ - virtual ResultStatus ReadManualRomFS(FileSys::VirtualFile& file) { + virtual ResultStatus ReadManualRomFS(FileSys::VirtualFile& out_file) { return ResultStatus::ErrorNotImplemented; } diff --git a/src/core/loader/nax.cpp b/src/core/loader/nax.cpp index 49028177b..f53c3a72c 100644 --- a/src/core/loader/nax.cpp +++ b/src/core/loader/nax.cpp @@ -26,14 +26,14 @@ FileType IdentifyTypeImpl(const FileSys::NAX& nax) { } } // Anonymous namespace -AppLoader_NAX::AppLoader_NAX(FileSys::VirtualFile file) - : AppLoader(file), nax(std::make_unique<FileSys::NAX>(file)), +AppLoader_NAX::AppLoader_NAX(FileSys::VirtualFile file_) + : AppLoader(file_), nax(std::make_unique<FileSys::NAX>(file_)), nca_loader(std::make_unique<AppLoader_NCA>(nax->GetDecrypted())) {} AppLoader_NAX::~AppLoader_NAX() = default; -FileType AppLoader_NAX::IdentifyType(const FileSys::VirtualFile& file) { - const FileSys::NAX nax(file); +FileType AppLoader_NAX::IdentifyType(const FileSys::VirtualFile& nax_file) { + const FileSys::NAX nax(nax_file); return IdentifyTypeImpl(nax); } @@ -41,8 +41,7 @@ FileType AppLoader_NAX::GetFileType() const { return IdentifyTypeImpl(*nax); } -AppLoader_NAX::LoadResult AppLoader_NAX::Load(Kernel::Process& process, - [[maybe_unused]] Core::System& system) { +AppLoader_NAX::LoadResult AppLoader_NAX::Load(Kernel::Process& process, Core::System& system) { if (is_loaded) { return {ResultStatus::ErrorAlreadyLoaded, {}}; } diff --git a/src/core/loader/nax.h b/src/core/loader/nax.h index a5b5e2ae1..68427c1cf 100644 --- a/src/core/loader/nax.h +++ b/src/core/loader/nax.h @@ -23,15 +23,17 @@ class AppLoader_NCA; /// Loads a NAX file class AppLoader_NAX final : public AppLoader { public: - explicit AppLoader_NAX(FileSys::VirtualFile file); + explicit AppLoader_NAX(FileSys::VirtualFile file_); ~AppLoader_NAX() override; /** - * Returns the type of the file - * @param file open file - * @return FileType found, or FileType::Error if this loader doesn't know it + * Identifies whether or not the given file is a NAX file. + * + * @param nax_file The file to identify. + * + * @return FileType::NAX, or FileType::Error if the file is not a NAX file. */ - static FileType IdentifyType(const FileSys::VirtualFile& file); + static FileType IdentifyType(const FileSys::VirtualFile& nax_file); FileType GetFileType() const override; diff --git a/src/core/loader/nca.cpp b/src/core/loader/nca.cpp index fa694de37..47e7a77a9 100644 --- a/src/core/loader/nca.cpp +++ b/src/core/loader/nca.cpp @@ -21,12 +21,13 @@ AppLoader_NCA::AppLoader_NCA(FileSys::VirtualFile file_) AppLoader_NCA::~AppLoader_NCA() = default; -FileType AppLoader_NCA::IdentifyType(const FileSys::VirtualFile& file) { - FileSys::NCA nca(file); +FileType AppLoader_NCA::IdentifyType(const FileSys::VirtualFile& nca_file) { + const FileSys::NCA nca(nca_file); if (nca.GetStatus() == ResultStatus::Success && - nca.GetType() == FileSys::NCAContentType::Program) + nca.GetType() == FileSys::NCAContentType::Program) { return FileType::NCA; + } return FileType::Error; } @@ -67,43 +68,59 @@ AppLoader_NCA::LoadResult AppLoader_NCA::Load(Kernel::Process& process, Core::Sy } ResultStatus AppLoader_NCA::ReadRomFS(FileSys::VirtualFile& dir) { - if (nca == nullptr) + if (nca == nullptr) { return ResultStatus::ErrorNotInitialized; - if (nca->GetRomFS() == nullptr || nca->GetRomFS()->GetSize() == 0) + } + + if (nca->GetRomFS() == nullptr || nca->GetRomFS()->GetSize() == 0) { return ResultStatus::ErrorNoRomFS; + } + dir = nca->GetRomFS(); return ResultStatus::Success; } u64 AppLoader_NCA::ReadRomFSIVFCOffset() const { - if (nca == nullptr) + if (nca == nullptr) { return 0; + } + return nca->GetBaseIVFCOffset(); } ResultStatus AppLoader_NCA::ReadProgramId(u64& out_program_id) { - if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) + if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) { return ResultStatus::ErrorNotInitialized; + } + out_program_id = nca->GetTitleId(); return ResultStatus::Success; } ResultStatus AppLoader_NCA::ReadBanner(std::vector<u8>& buffer) { - if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) + if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) { return ResultStatus::ErrorNotInitialized; + } + const auto logo = nca->GetLogoPartition(); - if (logo == nullptr) + if (logo == nullptr) { return ResultStatus::ErrorNoIcon; + } + buffer = logo->GetFile("StartupMovie.gif")->ReadAllBytes(); return ResultStatus::Success; } ResultStatus AppLoader_NCA::ReadLogo(std::vector<u8>& buffer) { - if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) + if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) { return ResultStatus::ErrorNotInitialized; + } + const auto logo = nca->GetLogoPartition(); - if (logo == nullptr) + if (logo == nullptr) { return ResultStatus::ErrorNoIcon; + } + buffer = logo->GetFile("NintendoLogo.png")->ReadAllBytes(); return ResultStatus::Success; } diff --git a/src/core/loader/nca.h b/src/core/loader/nca.h index 918792800..c9792f390 100644 --- a/src/core/loader/nca.h +++ b/src/core/loader/nca.h @@ -23,15 +23,17 @@ class AppLoader_DeconstructedRomDirectory; /// Loads an NCA file class AppLoader_NCA final : public AppLoader { public: - explicit AppLoader_NCA(FileSys::VirtualFile file); + explicit AppLoader_NCA(FileSys::VirtualFile file_); ~AppLoader_NCA() override; /** - * Returns the type of the file - * @param file open file - * @return FileType found, or FileType::Error if this loader doesn't know it + * Identifies whether or not the given file is an NCA file. + * + * @param nca_file The file to identify. + * + * @return FileType::NCA, or FileType::Error if the file is not an NCA file. */ - static FileType IdentifyType(const FileSys::VirtualFile& file); + static FileType IdentifyType(const FileSys::VirtualFile& nca_file); FileType GetFileType() const override { return IdentifyType(file); diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index 0115ed0c4..0597cfa60 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp @@ -72,7 +72,7 @@ struct AssetHeader { }; static_assert(sizeof(AssetHeader) == 0x38, "AssetHeader has incorrect size."); -AppLoader_NRO::AppLoader_NRO(FileSys::VirtualFile file) : AppLoader(file) { +AppLoader_NRO::AppLoader_NRO(FileSys::VirtualFile file_) : AppLoader(std::move(file_)) { NroHeader nro_header{}; if (file->ReadObject(&nro_header) != sizeof(NroHeader)) { return; @@ -114,10 +114,10 @@ AppLoader_NRO::AppLoader_NRO(FileSys::VirtualFile file) : AppLoader(file) { AppLoader_NRO::~AppLoader_NRO() = default; -FileType AppLoader_NRO::IdentifyType(const FileSys::VirtualFile& file) { +FileType AppLoader_NRO::IdentifyType(const FileSys::VirtualFile& nro_file) { // Read NSO header NroHeader nro_header{}; - if (sizeof(NroHeader) != file->ReadObject(&nro_header)) { + if (sizeof(NroHeader) != nro_file->ReadObject(&nro_header)) { return FileType::Error; } if (nro_header.magic == Common::MakeMagic('N', 'R', 'O', '0')) { @@ -130,8 +130,7 @@ static constexpr u32 PageAlignSize(u32 size) { return static_cast<u32>((size + Core::Memory::PAGE_MASK) & ~Core::Memory::PAGE_MASK); } -static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data, - const std::string& name) { +static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data) { if (data.size() < sizeof(NroHeader)) { return {}; } @@ -200,8 +199,8 @@ static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data, return true; } -bool AppLoader_NRO::LoadNro(Kernel::Process& process, const FileSys::VfsFile& file) { - return LoadNroImpl(process, file.ReadAllBytes(), file.GetName()); +bool AppLoader_NRO::LoadNro(Kernel::Process& process, const FileSys::VfsFile& nro_file) { + return LoadNroImpl(process, nro_file.ReadAllBytes()); } AppLoader_NRO::LoadResult AppLoader_NRO::Load(Kernel::Process& process, Core::System& system) { diff --git a/src/core/loader/nro.h b/src/core/loader/nro.h index a82b66221..20bbaeb0e 100644 --- a/src/core/loader/nro.h +++ b/src/core/loader/nro.h @@ -27,15 +27,17 @@ namespace Loader { /// Loads an NRO file class AppLoader_NRO final : public AppLoader { public: - explicit AppLoader_NRO(FileSys::VirtualFile file); + explicit AppLoader_NRO(FileSys::VirtualFile file_); ~AppLoader_NRO() override; /** - * Returns the type of the file - * @param file open file - * @return FileType found, or FileType::Error if this loader doesn't know it + * Identifies whether or not the given file is an NRO file. + * + * @param nro_file The file to identify. + * + * @return FileType::NRO, or FileType::Error if the file is not an NRO file. */ - static FileType IdentifyType(const FileSys::VirtualFile& file); + static FileType IdentifyType(const FileSys::VirtualFile& nro_file); FileType GetFileType() const override { return IdentifyType(file); @@ -51,7 +53,7 @@ public: bool IsRomFSUpdatable() const override; private: - bool LoadNro(Kernel::Process& process, const FileSys::VfsFile& file); + bool LoadNro(Kernel::Process& process, const FileSys::VfsFile& nro_file); std::vector<u8> icon_data; std::unique_ptr<FileSys::NACP> nacp; diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index 0c83dd666..f671afe02 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp @@ -56,11 +56,11 @@ bool NSOHeader::IsSegmentCompressed(size_t segment_num) const { return ((flags >> segment_num) & 1) != 0; } -AppLoader_NSO::AppLoader_NSO(FileSys::VirtualFile file) : AppLoader(std::move(file)) {} +AppLoader_NSO::AppLoader_NSO(FileSys::VirtualFile file_) : AppLoader(std::move(file_)) {} -FileType AppLoader_NSO::IdentifyType(const FileSys::VirtualFile& file) { +FileType AppLoader_NSO::IdentifyType(const FileSys::VirtualFile& in_file) { u32 magic = 0; - if (file->ReadObject(&magic) != sizeof(magic)) { + if (in_file->ReadObject(&magic) != sizeof(magic)) { return FileType::Error; } @@ -72,15 +72,15 @@ FileType AppLoader_NSO::IdentifyType(const FileSys::VirtualFile& file) { } std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process, Core::System& system, - const FileSys::VfsFile& file, VAddr load_base, + const FileSys::VfsFile& nso_file, VAddr load_base, bool should_pass_arguments, bool load_into_process, std::optional<FileSys::PatchManager> pm) { - if (file.GetSize() < sizeof(NSOHeader)) { + if (nso_file.GetSize() < sizeof(NSOHeader)) { return std::nullopt; } NSOHeader nso_header{}; - if (sizeof(NSOHeader) != file.ReadObject(&nso_header)) { + if (sizeof(NSOHeader) != nso_file.ReadObject(&nso_header)) { return std::nullopt; } @@ -92,8 +92,8 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process, Core::S Kernel::CodeSet codeset; Kernel::PhysicalMemory program_image; for (std::size_t i = 0; i < nso_header.segments.size(); ++i) { - std::vector<u8> data = - file.ReadBytes(nso_header.segments_compressed_size[i], nso_header.segments[i].offset); + std::vector<u8> data = nso_file.ReadBytes(nso_header.segments_compressed_size[i], + nso_header.segments[i].offset); if (nso_header.IsSegmentCompressed(i)) { data = DecompressSegment(data, nso_header.segments[i]); } @@ -136,7 +136,7 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process, Core::S pi_header.insert(pi_header.begin() + sizeof(NSOHeader), program_image.data(), program_image.data() + program_image.size()); - pi_header = pm->PatchNSO(pi_header, file.GetName()); + pi_header = pm->PatchNSO(pi_header, nso_file.GetName()); std::copy(pi_header.begin() + sizeof(NSOHeader), pi_header.end(), program_image.data()); } @@ -183,8 +183,8 @@ AppLoader_NSO::LoadResult AppLoader_NSO::Load(Kernel::Process& process, Core::Sy Core::Memory::DEFAULT_STACK_SIZE}}; } -ResultStatus AppLoader_NSO::ReadNSOModules(Modules& modules) { - modules = this->modules; +ResultStatus AppLoader_NSO::ReadNSOModules(Modules& out_modules) { + out_modules = this->modules; return ResultStatus::Success; } diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h index 3af461b5f..195149b55 100644 --- a/src/core/loader/nso.h +++ b/src/core/loader/nso.h @@ -71,27 +71,29 @@ static_assert(sizeof(NSOArgumentHeader) == 0x20, "NSOArgumentHeader has incorrec /// Loads an NSO file class AppLoader_NSO final : public AppLoader { public: - explicit AppLoader_NSO(FileSys::VirtualFile file); + explicit AppLoader_NSO(FileSys::VirtualFile file_); /** - * Returns the type of the file - * @param file open file - * @return FileType found, or FileType::Error if this loader doesn't know it + * Identifies whether or not the given file is a form of NSO file. + * + * @param in_file The file to be identified. + * + * @return FileType::NSO if found, or FileType::Error if some other type of file. */ - static FileType IdentifyType(const FileSys::VirtualFile& file); + static FileType IdentifyType(const FileSys::VirtualFile& in_file); FileType GetFileType() const override { return IdentifyType(file); } static std::optional<VAddr> LoadModule(Kernel::Process& process, Core::System& system, - const FileSys::VfsFile& file, VAddr load_base, + const FileSys::VfsFile& nso_file, VAddr load_base, bool should_pass_arguments, bool load_into_process, std::optional<FileSys::PatchManager> pm = {}); LoadResult Load(Kernel::Process& process, Core::System& system) override; - ResultStatus ReadNSOModules(Modules& modules) override; + ResultStatus ReadNSOModules(Modules& out_modules) override; private: Modules modules; diff --git a/src/core/loader/nsp.cpp b/src/core/loader/nsp.cpp index 928f64c8c..d7e590f1c 100644 --- a/src/core/loader/nsp.cpp +++ b/src/core/loader/nsp.cpp @@ -21,11 +21,11 @@ namespace Loader { -AppLoader_NSP::AppLoader_NSP(FileSys::VirtualFile file, +AppLoader_NSP::AppLoader_NSP(FileSys::VirtualFile file_, const Service::FileSystem::FileSystemController& fsc, const FileSys::ContentProvider& content_provider, std::size_t program_index) - : AppLoader(file), nsp(std::make_unique<FileSys::NSP>(file, program_index)), + : AppLoader(file_), nsp(std::make_unique<FileSys::NSP>(file_, program_index)), title_id(nsp->GetProgramTitleID()) { if (nsp->GetStatus() != ResultStatus::Success) { @@ -57,8 +57,8 @@ AppLoader_NSP::AppLoader_NSP(FileSys::VirtualFile file, AppLoader_NSP::~AppLoader_NSP() = default; -FileType AppLoader_NSP::IdentifyType(const FileSys::VirtualFile& file) { - FileSys::NSP nsp(file); +FileType AppLoader_NSP::IdentifyType(const FileSys::VirtualFile& nsp_file) { + const FileSys::NSP nsp(nsp_file); if (nsp.GetStatus() == ResultStatus::Success) { // Extracted Type case @@ -121,67 +121,80 @@ AppLoader_NSP::LoadResult AppLoader_NSP::Load(Kernel::Process& process, Core::Sy return result; } -ResultStatus AppLoader_NSP::ReadRomFS(FileSys::VirtualFile& file) { - return secondary_loader->ReadRomFS(file); +ResultStatus AppLoader_NSP::ReadRomFS(FileSys::VirtualFile& out_file) { + return secondary_loader->ReadRomFS(out_file); } u64 AppLoader_NSP::ReadRomFSIVFCOffset() const { return secondary_loader->ReadRomFSIVFCOffset(); } -ResultStatus AppLoader_NSP::ReadUpdateRaw(FileSys::VirtualFile& file) { - if (nsp->IsExtractedType()) +ResultStatus AppLoader_NSP::ReadUpdateRaw(FileSys::VirtualFile& out_file) { + if (nsp->IsExtractedType()) { return ResultStatus::ErrorNoPackedUpdate; + } const auto read = nsp->GetNCAFile(FileSys::GetUpdateTitleID(title_id), FileSys::ContentRecordType::Program); - if (read == nullptr) + if (read == nullptr) { return ResultStatus::ErrorNoPackedUpdate; - const auto nca_test = std::make_shared<FileSys::NCA>(read); + } - if (nca_test->GetStatus() != ResultStatus::ErrorMissingBKTRBaseRomFS) + const auto nca_test = std::make_shared<FileSys::NCA>(read); + if (nca_test->GetStatus() != ResultStatus::ErrorMissingBKTRBaseRomFS) { return nca_test->GetStatus(); + } - file = read; + out_file = read; return ResultStatus::Success; } ResultStatus AppLoader_NSP::ReadProgramId(u64& out_program_id) { - if (title_id == 0) + if (title_id == 0) { return ResultStatus::ErrorNotInitialized; + } + out_program_id = title_id; return ResultStatus::Success; } ResultStatus AppLoader_NSP::ReadIcon(std::vector<u8>& buffer) { - if (icon_file == nullptr) + if (icon_file == nullptr) { return ResultStatus::ErrorNoControl; + } + buffer = icon_file->ReadAllBytes(); return ResultStatus::Success; } ResultStatus AppLoader_NSP::ReadTitle(std::string& title) { - if (nacp_file == nullptr) + if (nacp_file == nullptr) { return ResultStatus::ErrorNoControl; + } + title = nacp_file->GetApplicationName(); return ResultStatus::Success; } ResultStatus AppLoader_NSP::ReadControlData(FileSys::NACP& nacp) { - if (nacp_file == nullptr) + if (nacp_file == nullptr) { return ResultStatus::ErrorNoControl; + } + nacp = *nacp_file; return ResultStatus::Success; } -ResultStatus AppLoader_NSP::ReadManualRomFS(FileSys::VirtualFile& file) { +ResultStatus AppLoader_NSP::ReadManualRomFS(FileSys::VirtualFile& out_file) { const auto nca = nsp->GetNCA(nsp->GetProgramTitleID(), FileSys::ContentRecordType::HtmlDocument); - if (nsp->GetStatus() != ResultStatus::Success || nca == nullptr) + if (nsp->GetStatus() != ResultStatus::Success || nca == nullptr) { return ResultStatus::ErrorNoRomFS; - file = nca->GetRomFS(); - return file == nullptr ? ResultStatus::ErrorNoRomFS : ResultStatus::Success; + } + + out_file = nca->GetRomFS(); + return out_file == nullptr ? ResultStatus::ErrorNoRomFS : ResultStatus::Success; } ResultStatus AppLoader_NSP::ReadBanner(std::vector<u8>& buffer) { diff --git a/src/core/loader/nsp.h b/src/core/loader/nsp.h index d48d87f2c..1660f1b94 100644 --- a/src/core/loader/nsp.h +++ b/src/core/loader/nsp.h @@ -26,18 +26,20 @@ class AppLoader_NCA; /// Loads an XCI file class AppLoader_NSP final : public AppLoader { public: - explicit AppLoader_NSP(FileSys::VirtualFile file, + explicit AppLoader_NSP(FileSys::VirtualFile file_, const Service::FileSystem::FileSystemController& fsc, const FileSys::ContentProvider& content_provider, std::size_t program_index); ~AppLoader_NSP() override; /** - * Returns the type of the file - * @param file open file - * @return FileType found, or FileType::Error if this loader doesn't know it + * Identifies whether or not the given file is an NSP file. + * + * @param nsp_file The file to identify. + * + * @return FileType::NSP, or FileType::Error if the file is not an NSP. */ - static FileType IdentifyType(const FileSys::VirtualFile& file); + static FileType IdentifyType(const FileSys::VirtualFile& nsp_file); FileType GetFileType() const override { return IdentifyType(file); @@ -45,14 +47,14 @@ public: LoadResult Load(Kernel::Process& process, Core::System& system) override; - ResultStatus ReadRomFS(FileSys::VirtualFile& file) override; + ResultStatus ReadRomFS(FileSys::VirtualFile& out_file) override; u64 ReadRomFSIVFCOffset() const override; - ResultStatus ReadUpdateRaw(FileSys::VirtualFile& file) override; + ResultStatus ReadUpdateRaw(FileSys::VirtualFile& out_file) override; ResultStatus ReadProgramId(u64& out_program_id) override; ResultStatus ReadIcon(std::vector<u8>& buffer) override; ResultStatus ReadTitle(std::string& title) override; ResultStatus ReadControlData(FileSys::NACP& nacp) override; - ResultStatus ReadManualRomFS(FileSys::VirtualFile& file) override; + ResultStatus ReadManualRomFS(FileSys::VirtualFile& out_file) override; ResultStatus ReadBanner(std::vector<u8>& buffer) override; ResultStatus ReadLogo(std::vector<u8>& buffer) override; diff --git a/src/core/loader/xci.cpp b/src/core/loader/xci.cpp index aaa250cea..0125ddf33 100644 --- a/src/core/loader/xci.cpp +++ b/src/core/loader/xci.cpp @@ -20,11 +20,11 @@ namespace Loader { -AppLoader_XCI::AppLoader_XCI(FileSys::VirtualFile file, +AppLoader_XCI::AppLoader_XCI(FileSys::VirtualFile file_, const Service::FileSystem::FileSystemController& fsc, const FileSys::ContentProvider& content_provider, std::size_t program_index) - : AppLoader(file), xci(std::make_unique<FileSys::XCI>(file, program_index)), + : AppLoader(file_), xci(std::make_unique<FileSys::XCI>(file_, program_index)), nca_loader(std::make_unique<AppLoader_NCA>(xci->GetProgramNCAFile())) { if (xci->GetStatus() != ResultStatus::Success) { return; @@ -43,8 +43,8 @@ AppLoader_XCI::AppLoader_XCI(FileSys::VirtualFile file, AppLoader_XCI::~AppLoader_XCI() = default; -FileType AppLoader_XCI::IdentifyType(const FileSys::VirtualFile& file) { - FileSys::XCI xci(file); +FileType AppLoader_XCI::IdentifyType(const FileSys::VirtualFile& xci_file) { + const FileSys::XCI xci(xci_file); if (xci.GetStatus() == ResultStatus::Success && xci.GetNCAByType(FileSys::NCAContentType::Program) != nullptr && @@ -87,31 +87,33 @@ AppLoader_XCI::LoadResult AppLoader_XCI::Load(Kernel::Process& process, Core::Sy return result; } -ResultStatus AppLoader_XCI::ReadRomFS(FileSys::VirtualFile& file) { - return nca_loader->ReadRomFS(file); +ResultStatus AppLoader_XCI::ReadRomFS(FileSys::VirtualFile& out_file) { + return nca_loader->ReadRomFS(out_file); } u64 AppLoader_XCI::ReadRomFSIVFCOffset() const { return nca_loader->ReadRomFSIVFCOffset(); } -ResultStatus AppLoader_XCI::ReadUpdateRaw(FileSys::VirtualFile& file) { +ResultStatus AppLoader_XCI::ReadUpdateRaw(FileSys::VirtualFile& out_file) { u64 program_id{}; nca_loader->ReadProgramId(program_id); - if (program_id == 0) + if (program_id == 0) { return ResultStatus::ErrorXCIMissingProgramNCA; + } const auto read = xci->GetSecurePartitionNSP()->GetNCAFile( FileSys::GetUpdateTitleID(program_id), FileSys::ContentRecordType::Program); - - if (read == nullptr) + if (read == nullptr) { return ResultStatus::ErrorNoPackedUpdate; - const auto nca_test = std::make_shared<FileSys::NCA>(read); + } - if (nca_test->GetStatus() != ResultStatus::ErrorMissingBKTRBaseRomFS) + const auto nca_test = std::make_shared<FileSys::NCA>(read); + if (nca_test->GetStatus() != ResultStatus::ErrorMissingBKTRBaseRomFS) { return nca_test->GetStatus(); + } - file = read; + out_file = read; return ResultStatus::Success; } @@ -120,33 +122,41 @@ ResultStatus AppLoader_XCI::ReadProgramId(u64& out_program_id) { } ResultStatus AppLoader_XCI::ReadIcon(std::vector<u8>& buffer) { - if (icon_file == nullptr) + if (icon_file == nullptr) { return ResultStatus::ErrorNoControl; + } + buffer = icon_file->ReadAllBytes(); return ResultStatus::Success; } ResultStatus AppLoader_XCI::ReadTitle(std::string& title) { - if (nacp_file == nullptr) + if (nacp_file == nullptr) { return ResultStatus::ErrorNoControl; + } + title = nacp_file->GetApplicationName(); return ResultStatus::Success; } ResultStatus AppLoader_XCI::ReadControlData(FileSys::NACP& control) { - if (nacp_file == nullptr) + if (nacp_file == nullptr) { return ResultStatus::ErrorNoControl; + } + control = *nacp_file; return ResultStatus::Success; } -ResultStatus AppLoader_XCI::ReadManualRomFS(FileSys::VirtualFile& file) { +ResultStatus AppLoader_XCI::ReadManualRomFS(FileSys::VirtualFile& out_file) { const auto nca = xci->GetSecurePartitionNSP()->GetNCA(xci->GetProgramTitleID(), FileSys::ContentRecordType::HtmlDocument); - if (xci->GetStatus() != ResultStatus::Success || nca == nullptr) + if (xci->GetStatus() != ResultStatus::Success || nca == nullptr) { return ResultStatus::ErrorXCIMissingPartition; - file = nca->GetRomFS(); - return file == nullptr ? ResultStatus::ErrorNoRomFS : ResultStatus::Success; + } + + out_file = nca->GetRomFS(); + return out_file == nullptr ? ResultStatus::ErrorNoRomFS : ResultStatus::Success; } ResultStatus AppLoader_XCI::ReadBanner(std::vector<u8>& buffer) { diff --git a/src/core/loader/xci.h b/src/core/loader/xci.h index 9f0ceb5ef..7ea8179af 100644 --- a/src/core/loader/xci.h +++ b/src/core/loader/xci.h @@ -26,18 +26,20 @@ class AppLoader_NCA; /// Loads an XCI file class AppLoader_XCI final : public AppLoader { public: - explicit AppLoader_XCI(FileSys::VirtualFile file, + explicit AppLoader_XCI(FileSys::VirtualFile file_, const Service::FileSystem::FileSystemController& fsc, const FileSys::ContentProvider& content_provider, std::size_t program_index); ~AppLoader_XCI() override; /** - * Returns the type of the file - * @param file open file - * @return FileType found, or FileType::Error if this loader doesn't know it + * Identifies whether or not the given file is an XCI file. + * + * @param xci_file The file to identify. + * + * @return FileType::XCI, or FileType::Error if the file is not an XCI file. */ - static FileType IdentifyType(const FileSys::VirtualFile& file); + static FileType IdentifyType(const FileSys::VirtualFile& xci_file); FileType GetFileType() const override { return IdentifyType(file); @@ -45,14 +47,14 @@ public: LoadResult Load(Kernel::Process& process, Core::System& system) override; - ResultStatus ReadRomFS(FileSys::VirtualFile& file) override; + ResultStatus ReadRomFS(FileSys::VirtualFile& out_file) override; u64 ReadRomFSIVFCOffset() const override; - ResultStatus ReadUpdateRaw(FileSys::VirtualFile& file) override; + ResultStatus ReadUpdateRaw(FileSys::VirtualFile& out_file) override; ResultStatus ReadProgramId(u64& out_program_id) override; ResultStatus ReadIcon(std::vector<u8>& buffer) override; ResultStatus ReadTitle(std::string& title) override; ResultStatus ReadControlData(FileSys::NACP& control) override; - ResultStatus ReadManualRomFS(FileSys::VirtualFile& file) override; + ResultStatus ReadManualRomFS(FileSys::VirtualFile& out_file) override; ResultStatus ReadBanner(std::vector<u8>& buffer) override; ResultStatus ReadLogo(std::vector<u8>& buffer) override; diff --git a/src/input_common/motion_input.cpp b/src/input_common/motion_input.cpp index 6a65f175e..1c9d561c0 100644 --- a/src/input_common/motion_input.cpp +++ b/src/input_common/motion_input.cpp @@ -195,7 +195,8 @@ Input::MotionStatus MotionInput::GetMotion() const { const Common::Vec3f accelerometer = GetAcceleration(); const Common::Vec3f rotation = GetRotations(); const std::array<Common::Vec3f, 3> orientation = GetOrientation(); - return {accelerometer, gyroscope, rotation, orientation}; + const Common::Quaternion<f32> quaternion = GetQuaternion(); + return {accelerometer, gyroscope, rotation, orientation, quaternion}; } Input::MotionStatus MotionInput::GetRandomMotion(int accel_magnitude, int gyro_magnitude) const { @@ -218,7 +219,12 @@ Input::MotionStatus MotionInput::GetRandomMotion(int accel_magnitude, int gyro_m Common::Vec3f{0.0f, 1.0f, 0.0f}, Common::Vec3f{0.0f, 0.0f, 1.0f}, }; - return {accelerometer * accel_magnitude, gyroscope * gyro_magnitude, rotation, orientation}; + constexpr Common::Quaternion<f32> quaternion{ + {0.0f, 0.0f, 0.0f}, + 1.0f, + }; + return {accelerometer * accel_magnitude, gyroscope * gyro_magnitude, rotation, orientation, + quaternion}; } void MotionInput::ResetOrientation() { diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index d1b8c4fc9..e80a3df77 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -863,8 +863,7 @@ void Config::ReadSystemValues() { Settings::values.rng_seed.SetGlobal(rng_seed_global); if (global || !rng_seed_global) { if (rng_seed_enabled) { - Settings::values.rng_seed.SetValue( - ReadSetting(QStringLiteral("rng_seed"), 0).toULongLong()); + Settings::values.rng_seed.SetValue(ReadSetting(QStringLiteral("rng_seed"), 0).toUInt()); } else { Settings::values.rng_seed.SetValue(std::nullopt); } diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 5f6cdc0c6..39bdf186d 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -349,7 +349,7 @@ GMainWindow::GMainWindow() continue; } - Settings::values.current_user = selected_user; + Settings::values.current_user = static_cast<s32>(selected_user); continue; } |