From 09fb49446339a706bbaa207f6e3a139a9a3c1d71 Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Mon, 26 Feb 2024 04:36:10 +0100 Subject: [PATCH] early-access version 4172 --- README.md | 2 +- src/core/CMakeLists.txt | 24 +- src/core/core.cpp | 109 +- src/core/hle/service/am/am.cpp | 15 +- src/core/hle/service/am/am_results.h | 1 - src/core/hle/service/am/am_types.h | 7 + src/core/hle/service/am/applet.cpp | 66 +- src/core/hle/service/am/applet.h | 33 +- .../hle/service/am/applet_data_broker.cpp | 18 +- src/core/hle/service/am/applet_data_broker.h | 14 + src/core/hle/service/am/applet_manager.cpp | 128 +- src/core/hle/service/am/applet_manager.h | 37 +- src/core/hle/service/am/frontend/applets.cpp | 6 +- src/core/hle/service/am/hid_registration.cpp | 10 +- src/core/hle/service/am/hid_registration.h | 6 +- .../all_system_applet_proxies_service.cpp | 16 +- .../all_system_applet_proxies_service.h | 5 +- .../am/service/applet_common_functions.cpp | 9 +- .../am/service/applet_common_functions.h | 1 - .../am/service/application_accessor.cpp | 39 +- .../service/am/service/application_accessor.h | 5 +- .../am/service/application_creator.cpp | 49 +- .../service/am/service/application_creator.h | 5 +- .../am/service/application_functions.cpp | 3 +- .../service/am/service/application_proxy.cpp | 11 +- .../service/am/service/application_proxy.h | 4 +- .../am/service/application_proxy_service.cpp | 12 +- .../am/service/application_proxy_service.h | 5 +- .../am/service/common_state_getter.cpp | 9 +- .../am/service/home_menu_functions.cpp | 18 +- .../service/am/service/home_menu_functions.h | 5 +- .../am/service/library_applet_accessor.cpp | 16 +- .../am/service/library_applet_accessor.h | 2 +- .../am/service/library_applet_creator.cpp | 49 +- .../am/service/library_applet_creator.h | 5 +- .../am/service/library_applet_proxy.cpp | 14 +- .../service/am/service/library_applet_proxy.h | 4 +- .../service/library_applet_self_accessor.cpp | 3 +- .../service/am/service/self_controller.cpp | 37 +- .../am/service/system_applet_proxy.cpp | 16 +- .../service/am/service/system_applet_proxy.h | 4 +- .../service/am/service/window_controller.cpp | 19 +- .../service/am/service/window_controller.h | 5 +- .../hid/active_vibration_device_list.cpp | 53 + .../hid/active_vibration_device_list.h | 39 + src/core/hle/service/hid/applet_resource.cpp | 34 + src/core/hle/service/hid/applet_resource.h | 36 + src/core/hle/service/hid/hid.cpp | 4 + src/core/hle/service/hid/hid_server.cpp | 2617 +++++------------ src/core/hle/service/hid/hid_server.h | 352 ++- src/hid_core/hid_types.h | 34 +- src/hid_core/resource_manager.cpp | 26 - src/hid_core/resource_manager.h | 13 - src/hid_core/resources/palma/palma.cpp | 24 +- src/hid_core/resources/palma/palma.h | 34 +- src/video_core/engines/draw_manager.cpp | 11 +- .../renderer_opengl/gl_rasterizer.cpp | 29 +- .../renderer_vulkan/vk_rasterizer.cpp | 56 +- .../renderer_vulkan/vk_texture_cache.cpp | 7 +- .../renderer_vulkan/vk_texture_cache.h | 5 + src/yuzu/main.cpp | 7 + src/yuzu/main.h | 1 + 62 files changed, 1685 insertions(+), 2543 deletions(-) create mode 100755 src/core/hle/service/hid/active_vibration_device_list.cpp create mode 100755 src/core/hle/service/hid/active_vibration_device_list.h create mode 100755 src/core/hle/service/hid/applet_resource.cpp create mode 100755 src/core/hle/service/hid/applet_resource.h diff --git a/README.md b/README.md index 60c9cf79f..839b78491 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 4171. +This is the source code for early-access 4172. ## Legal Notice diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 74b38eae6..419c9e650 100755 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -401,16 +401,14 @@ add_library(core STATIC hle/service/am/am_types.h hle/service/am/applet.cpp hle/service/am/applet.h - hle/service/am/applet_manager.cpp hle/service/am/applet_data_broker.cpp hle/service/am/applet_data_broker.h + hle/service/am/applet_manager.cpp hle/service/am/applet_manager.h - hle/service/am/button_poller.cpp - hle/service/am/button_poller.h + hle/service/am/applet_message_queue.cpp + hle/service/am/applet_message_queue.h hle/service/am/display_layer_manager.cpp hle/service/am/display_layer_manager.h - hle/service/am/event_observer.cpp - hle/service/am/event_observer.h hle/service/am/frontend/applet_cabinet.cpp hle/service/am/frontend/applet_cabinet.h hle/service/am/frontend/applet_controller.cpp @@ -436,12 +434,8 @@ add_library(core STATIC hle/service/am/hid_registration.h hle/service/am/library_applet_storage.cpp hle/service/am/library_applet_storage.h - hle/service/am/lifecycle_manager.cpp - hle/service/am/lifecycle_manager.h - hle/service/am/process_creation.cpp - hle/service/am/process_creation.h - hle/service/am/process_holder.cpp - hle/service/am/process_holder.h + hle/service/am/process.cpp + hle/service/am/process.h hle/service/am/service/all_system_applet_proxies_service.cpp hle/service/am/service/all_system_applet_proxies_service.h hle/service/am/service/applet_common_functions.cpp @@ -492,8 +486,6 @@ add_library(core STATIC hle/service/am/service/system_applet_proxy.h hle/service/am/service/window_controller.cpp hle/service/am/service/window_controller.h - hle/service/am/window_system.cpp - hle/service/am/window_system.h hle/service/aoc/addon_content_manager.cpp hle/service/aoc/addon_content_manager.h hle/service/aoc/purchase_event_manager.cpp @@ -676,6 +668,10 @@ add_library(core STATIC hle/service/glue/time/worker.h hle/service/grc/grc.cpp hle/service/grc/grc.h + hle/service/hid/active_vibration_device_list.cpp + hle/service/hid/active_vibration_device_list.h + hle/service/hid/applet_resource.cpp + hle/service/hid/applet_resource.h hle/service/hid/hid.cpp hle/service/hid/hid.h hle/service/hid/hid_debug_server.cpp @@ -922,8 +918,6 @@ add_library(core STATIC hle/service/os/multi_wait_utils.h hle/service/os/mutex.cpp hle/service/os/mutex.h - hle/service/os/process.cpp - hle/service/os/process.h hle/service/pcie/pcie.cpp hle/service/pcie/pcie.h hle/service/pctl/parental_control_service_factory.cpp diff --git a/src/core/core.cpp b/src/core/core.cpp index a51d3447b..56f5dd67d 100755 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -19,6 +20,7 @@ #include "core/cpu_manager.h" #include "core/debugger/debugger.h" #include "core/device_memory.h" +#include "core/file_sys/bis_factory.h" #include "core/file_sys/fs_filesystem.h" #include "core/file_sys/patch_manager.h" #include "core/file_sys/registered_cache.h" @@ -36,7 +38,6 @@ #include "core/hle/service/acc/profile_manager.h" #include "core/hle/service/am/applet_manager.h" #include "core/hle/service/am/frontend/applets.h" -#include "core/hle/service/am/process_creation.h" #include "core/hle/service/apm/apm_controller.h" #include "core/hle/service/filesystem/filesystem.h" #include "core/hle/service/glue/glue_manager.h" @@ -71,6 +72,30 @@ MICROPROFILE_DEFINE(ARM_CPU3, "ARM", "CPU 3", MP_RGB(255, 64, 64)); namespace Core { +namespace { + +FileSys::StorageId GetStorageIdForFrontendSlot( + std::optional slot) { + if (!slot.has_value()) { + return FileSys::StorageId::None; + } + + switch (*slot) { + case FileSys::ContentProviderUnionSlot::UserNAND: + return FileSys::StorageId::NandUser; + case FileSys::ContentProviderUnionSlot::SysNAND: + return FileSys::StorageId::NandSystem; + case FileSys::ContentProviderUnionSlot::SDMC: + return FileSys::StorageId::SdCard; + case FileSys::ContentProviderUnionSlot::FrontendManual: + return FileSys::StorageId::Host; + default: + return FileSys::StorageId::None; + } +} + +} // Anonymous namespace + FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, const std::string& path) { // To account for split 00+01+etc files. @@ -272,6 +297,9 @@ struct System::Impl { } SystemResultStatus SetupForApplicationProcess(System& system, Frontend::EmuWindow& emu_window) { + /// Reset all glue registrations + arp_manager.ResetAll(); + telemetry_session = std::make_unique(); host1x_core = std::make_unique(system); @@ -307,24 +335,8 @@ struct System::Impl { SystemResultStatus Load(System& system, Frontend::EmuWindow& emu_window, const std::string& filepath, Service::AM::FrontendAppletParameters& params) { - InitializeKernel(system); - - const auto file = GetGameFileFromPath(virtual_filesystem, filepath); - - // Create the application process - Loader::ResultStatus load_result{}; - std::vector control; - auto process = - Service::AM::CreateApplicationProcess(control, app_loader, load_result, system, file, - params.program_id, params.program_index); - - if (load_result != Loader::ResultStatus::Success) { - LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", load_result); - ShutdownMainProcess(); - - return static_cast( - static_cast(SystemResultStatus::ErrorLoader) + static_cast(load_result)); - } + app_loader = Loader::GetLoader(system, GetGameFileFromPath(virtual_filesystem, filepath), + params.program_id, params.program_index); if (!app_loader) { LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath); @@ -332,7 +344,7 @@ struct System::Impl { } if (app_loader->ReadProgramId(params.program_id) != Loader::ResultStatus::Success) { - LOG_ERROR(Core, "Failed to find program id for ROM!"); + LOG_ERROR(Core, "Failed to find title id for ROM!"); } std::string name = "Unknown program"; @@ -340,10 +352,23 @@ struct System::Impl { LOG_ERROR(Core, "Failed to read title for ROM!"); } - LOG_INFO(Core, "Loading {} ({:016X}) ...", name, params.program_id); + LOG_INFO(Core, "Loading {} ({})", name, params.program_id); - // Make the process created be the application - kernel.MakeApplicationProcess(process->GetHandle()); + InitializeKernel(system); + + // Create the application process. + auto main_process = Kernel::KProcess::Create(system.Kernel()); + Kernel::KProcess::Register(system.Kernel(), main_process); + kernel.AppendNewProcess(main_process); + kernel.MakeApplicationProcess(main_process); + const auto [load_result, load_parameters] = app_loader->Load(*main_process, system); + if (load_result != Loader::ResultStatus::Success) { + LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", load_result); + ShutdownMainProcess(); + + return static_cast( + static_cast(SystemResultStatus::ErrorLoader) + static_cast(load_result)); + } // Set up the rest of the system. SystemResultStatus init_result{SetupForApplicationProcess(system, emu_window)}; @@ -354,6 +379,7 @@ struct System::Impl { return init_result; } + AddGlueRegistrationForProcess(*app_loader, *main_process); telemetry_session->AddInitialInfo(*app_loader, fs_controller, *content_provider); // Initialize cheat engine @@ -362,7 +388,13 @@ struct System::Impl { } // Register with applet manager. - applet_manager.CreateAndInsertByFrontendAppletParameters(std::move(process), params); + applet_manager.CreateAndInsertByFrontendAppletParameters(main_process->GetProcessId(), + params); + + // All threads are started, begin main process execution, now that we're in the clear. + main_process->Run(load_parameters->main_thread_priority, + load_parameters->main_thread_stack_size); + main_process->Close(); if (Settings::values.gamecard_inserted) { if (Settings::values.gamecard_current_game) { @@ -434,6 +466,7 @@ struct System::Impl { kernel.SuspendEmulation(true); kernel.CloseServices(); kernel.ShutdownCores(); + applet_manager.Reset(); services.reset(); service_manager.reset(); fs_controller.Reset(); @@ -459,9 +492,6 @@ struct System::Impl { // Workarounds Settings::values.renderer_amdvlk_depth_bias_workaround = false; - // Reset all glue registrations - arp_manager.ResetAll(); - LOG_DEBUG(Core, "Shutdown OK"); } @@ -479,6 +509,31 @@ struct System::Impl { return app_loader->ReadTitle(out); } + void AddGlueRegistrationForProcess(Loader::AppLoader& loader, Kernel::KProcess& process) { + std::vector nacp_data; + FileSys::NACP nacp; + if (loader.ReadControlData(nacp) == Loader::ResultStatus::Success) { + nacp_data = nacp.GetRawBytes(); + } else { + nacp_data.resize(sizeof(FileSys::RawNACP)); + } + + Service::Glue::ApplicationLaunchProperty launch{}; + launch.title_id = process.GetProgramId(); + + FileSys::PatchManager pm{launch.title_id, fs_controller, *content_provider}; + launch.version = pm.GetGameVersion().value_or(0); + + // TODO(DarkLordZach): When FSController/Game Card Support is added, if + // current_process_game_card use correct StorageId + launch.base_game_storage_id = GetStorageIdForFrontendSlot(content_provider->GetSlotForEntry( + launch.title_id, FileSys::ContentRecordType::Program)); + launch.update_storage_id = GetStorageIdForFrontendSlot(content_provider->GetSlotForEntry( + FileSys::GetUpdateTitleID(launch.title_id), FileSys::ContentRecordType::Program)); + + arp_manager.Register(launch.title_id, launch, std::move(nacp_data)); + } + void SetStatus(SystemResultStatus new_status, const char* details = nullptr) { status = new_status; if (details) { diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 9ec5bb48c..df2e7abd7 100755 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -2,26 +2,19 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "core/hle/service/am/am.h" -#include "core/hle/service/am/button_poller.h" -#include "core/hle/service/am/event_observer.h" #include "core/hle/service/am/service/all_system_applet_proxies_service.h" #include "core/hle/service/am/service/application_proxy_service.h" -#include "core/hle/service/am/window_system.h" #include "core/hle/service/server_manager.h" namespace Service::AM { void LoopProcess(Core::System& system) { - WindowSystem window_system(system); - ButtonPoller button_poller(system, window_system); - EventObserver event_observer(system, window_system); - auto server_manager = std::make_unique(system); - server_manager->RegisterNamedService( - "appletAE", std::make_shared(system, window_system)); - server_manager->RegisterNamedService( - "appletOE", std::make_shared(system, window_system)); + server_manager->RegisterNamedService("appletAE", + std::make_shared(system)); + server_manager->RegisterNamedService("appletOE", + std::make_shared(system)); ServerManager::RunServer(std::move(server_manager)); } diff --git a/src/core/hle/service/am/am_results.h b/src/core/hle/service/am/am_results.h index 44846aa2e..a2afc9eec 100755 --- a/src/core/hle/service/am/am_results.h +++ b/src/core/hle/service/am/am_results.h @@ -9,7 +9,6 @@ namespace Service::AM { constexpr Result ResultNoDataInChannel{ErrorModule::AM, 2}; constexpr Result ResultNoMessages{ErrorModule::AM, 3}; -constexpr Result ResultLibraryAppletTerminated{ErrorModule::AM, 22}; constexpr Result ResultInvalidOffset{ErrorModule::AM, 503}; constexpr Result ResultInvalidStorageType{ErrorModule::AM, 511}; constexpr Result ResultFatalSectionCountImbalance{ErrorModule::AM, 512}; diff --git a/src/core/hle/service/am/am_types.h b/src/core/hle/service/am/am_types.h index eb9ad0ac5..a14defb40 100755 --- a/src/core/hle/service/am/am_types.h +++ b/src/core/hle/service/am/am_types.h @@ -61,6 +61,12 @@ enum class ScreenshotPermission : u32 { Disable = 2, }; +struct FocusHandlingMode { + bool notify; + bool background; + bool suspend; +}; + enum class IdleTimeDetectionExtension : u32 { Disabled = 0, Extended = 1, @@ -233,6 +239,7 @@ struct ApplicationPlayStatistics { static_assert(sizeof(ApplicationPlayStatistics) == 0x18, "ApplicationPlayStatistics has incorrect size."); +using AppletResourceUserId = u64; using ProgramId = u64; struct Applet; diff --git a/src/core/hle/service/am/applet.cpp b/src/core/hle/service/am/applet.cpp index 6847f250c..5b9056c12 100755 --- a/src/core/hle/service/am/applet.cpp +++ b/src/core/hle/service/am/applet.cpp @@ -1,71 +1,27 @@ // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include "common/scope_exit.h" + #include "core/core.h" +#include "core/hle/service/am/am_results.h" #include "core/hle/service/am/applet.h" #include "core/hle/service/am/applet_manager.h" namespace Service::AM { -Applet::Applet(Core::System& system, std::unique_ptr process_, bool is_application) - : context(system, "Applet"), lifecycle_manager(system, context, is_application), - process(std::move(process_)), hid_registration(system, *process), - gpu_error_detected_event(context), friend_invitation_storage_channel_event(context), - notification_storage_channel_event(context), health_warning_disappeared_system_event(context), - acquired_sleep_lock_event(context), pop_from_general_channel_event(context), - library_applet_launchable_event(context), accumulated_suspended_tick_changed_event(context), - sleep_lock_event(context), state_changed_event(context) { +Applet::Applet(Core::System& system, std::unique_ptr process_) + : context(system, "Applet"), message_queue(system), process(std::move(process_)), + hid_registration(system, *process), gpu_error_detected_event(context), + friend_invitation_storage_channel_event(context), notification_storage_channel_event(context), + health_warning_disappeared_system_event(context), acquired_sleep_lock_event(context), + pop_from_general_channel_event(context), library_applet_launchable_event(context), + accumulated_suspended_tick_changed_event(context), sleep_lock_event(context) { - aruid.pid = process->GetProcessId(); + aruid = process->GetProcessId(); program_id = process->GetProgramId(); } Applet::~Applet() = default; -void Applet::UpdateSuspensionStateLocked(bool force_message) { - // Remove any forced resumption. - lifecycle_manager.RemoveForceResumeIfPossible(); - - // Check if we're runnable. - const bool curr_activity_runnable = lifecycle_manager.IsRunnable(); - const bool prev_activity_runnable = is_activity_runnable; - const bool was_changed = curr_activity_runnable != prev_activity_runnable; - - if (was_changed) { - if (curr_activity_runnable) { - process->Suspend(false); - } else { - process->Suspend(true); - lifecycle_manager.RequestResumeNotification(); - } - - is_activity_runnable = curr_activity_runnable; - } - - if (lifecycle_manager.GetForcedSuspend()) { - // TODO: why is this allowed? - return; - } - - // Signal if the focus state was changed or the process state was changed. - if (lifecycle_manager.UpdateRequestedFocusState() || was_changed || force_message) { - lifecycle_manager.SignalSystemEventIfNeeded(); - } -} - -void Applet::SetInteractibleLocked(bool interactible) { - if (is_interactible == interactible) { - return; - } - - is_interactible = interactible; - - hid_registration.EnableAppletToGetInput(interactible && !lifecycle_manager.GetExitRequested()); -} - -void Applet::OnProcessTerminatedLocked() { - is_completed = true; - state_changed_event.Signal(); -} - } // namespace Service::AM diff --git a/src/core/hle/service/am/applet.h b/src/core/hle/service/am/applet.h index 571904fab..ad602153e 100755 --- a/src/core/hle/service/am/applet.h +++ b/src/core/hle/service/am/applet.h @@ -3,28 +3,25 @@ #pragma once -#include #include #include "common/math_util.h" #include "core/hle/service/apm/apm_controller.h" #include "core/hle/service/caps/caps_types.h" -#include "core/hle/service/cmif_types.h" #include "core/hle/service/kernel_helpers.h" #include "core/hle/service/os/event.h" -#include "core/hle/service/os/process.h" #include "core/hle/service/service.h" #include "core/hle/service/am/am_types.h" +#include "core/hle/service/am/applet_message_queue.h" #include "core/hle/service/am/display_layer_manager.h" #include "core/hle/service/am/hid_registration.h" -#include "core/hle/service/am/lifecycle_manager.h" -#include "core/hle/service/am/process_holder.h" +#include "core/hle/service/am/process.h" namespace Service::AM { struct Applet { - explicit Applet(Core::System& system, std::unique_ptr process_, bool is_application); + explicit Applet(Core::System& system, std::unique_ptr process_); ~Applet(); // Lock @@ -33,13 +30,11 @@ struct Applet { // Event creation helper KernelHelpers::ServiceContext context; - // Lifecycle manager - LifecycleManager lifecycle_manager; + // Applet message queue + AppletMessageQueue message_queue; // Process std::unique_ptr process; - std::optional process_holder; - bool is_process_running{}; // Creation state AppletId applet_id{}; @@ -80,9 +75,11 @@ struct Applet { bool game_play_recording_supported{}; GamePlayRecordingState game_play_recording_state{GamePlayRecordingState::Disabled}; bool jit_service_launched{}; + bool is_running{}; bool application_crash_report_enabled{}; // Common state + FocusState focus_state{}; bool sleep_lock_enabled{}; bool vr_mode_enabled{}; bool lcd_backlight_off_enabled{}; @@ -96,12 +93,15 @@ struct Applet { // Caller applet std::weak_ptr caller_applet{}; std::shared_ptr caller_applet_broker{}; - std::list> child_applets{}; - bool is_completed{}; // Self state bool exit_locked{}; s32 fatal_section_count{}; + bool operation_mode_changed_notification_enabled{true}; + bool performance_mode_changed_notification_enabled{true}; + FocusHandlingMode focus_handling_mode{}; + bool restart_message_enabled{}; + bool out_of_focus_suspension_enabled{true}; Capture::AlbumImageOrientation album_image_orientation{}; bool handles_request_to_display{}; ScreenshotPermission screenshot_permission{}; @@ -110,9 +110,6 @@ struct Applet { u64 suspended_ticks{}; bool album_image_taken_notification_enabled{}; bool record_volume_muted{}; - bool is_activity_runnable{}; - bool is_interactible{true}; - bool window_visible{true}; // Events Event gpu_error_detected_event; @@ -124,15 +121,9 @@ struct Applet { Event library_applet_launchable_event; Event accumulated_suspended_tick_changed_event; Event sleep_lock_event; - Event state_changed_event; // Frontend state std::shared_ptr frontend{}; - - // Process state management - void UpdateSuspensionStateLocked(bool force_message); - void SetInteractibleLocked(bool interactible); - void OnProcessTerminatedLocked(); }; } // namespace Service::AM diff --git a/src/core/hle/service/am/applet_data_broker.cpp b/src/core/hle/service/am/applet_data_broker.cpp index fff78c5af..9057244a9 100755 --- a/src/core/hle/service/am/applet_data_broker.cpp +++ b/src/core/hle/service/am/applet_data_broker.cpp @@ -44,8 +44,24 @@ Kernel::KReadableEvent* AppletStorageChannel::GetEvent() { AppletDataBroker::AppletDataBroker(Core::System& system_) : system(system_), context(system_, "AppletDataBroker"), in_data(context), - interactive_in_data(context), out_data(context), interactive_out_data(context) {} + interactive_in_data(context), out_data(context), interactive_out_data(context), + state_changed_event(context), is_completed(false) {} AppletDataBroker::~AppletDataBroker() = default; +void AppletDataBroker::SignalCompletion() { + { + std::scoped_lock lk{lock}; + + if (is_completed) { + return; + } + + is_completed = true; + state_changed_event.Signal(); + } + + system.GetAppletManager().FocusStateChanged(); +} + } // namespace Service::AM diff --git a/src/core/hle/service/am/applet_data_broker.h b/src/core/hle/service/am/applet_data_broker.h index 2718f608a..5a1d43c11 100755 --- a/src/core/hle/service/am/applet_data_broker.h +++ b/src/core/hle/service/am/applet_data_broker.h @@ -53,6 +53,16 @@ public: return interactive_out_data; } + Event& GetStateChangedEvent() { + return state_changed_event; + } + + bool IsCompleted() const { + return is_completed; + } + + void SignalCompletion(); + private: Core::System& system; KernelHelpers::ServiceContext context; @@ -61,6 +71,10 @@ private: AppletStorageChannel interactive_in_data; AppletStorageChannel out_data; AppletStorageChannel interactive_out_data; + Event state_changed_event; + + std::mutex lock; + bool is_completed; }; } // namespace Service::AM diff --git a/src/core/hle/service/am/applet_manager.cpp b/src/core/hle/service/am/applet_manager.cpp index c6b7ec8bb..2e109181d 100755 --- a/src/core/hle/service/am/applet_manager.cpp +++ b/src/core/hle/service/am/applet_manager.cpp @@ -13,7 +13,6 @@ #include "core/hle/service/am/frontend/applet_mii_edit_types.h" #include "core/hle/service/am/frontend/applet_software_keyboard_types.h" #include "core/hle/service/am/service/storage.h" -#include "core/hle/service/am/window_system.h" #include "hid_core/hid_types.h" namespace Service::AM { @@ -226,46 +225,49 @@ void PushInShowSoftwareKeyboard(Core::System& system, AppletStorageChannel& chan } // namespace AppletManager::AppletManager(Core::System& system) : m_system(system) {} -AppletManager::~AppletManager() = default; +AppletManager::~AppletManager() { + this->Reset(); +} -void AppletManager::CreateAndInsertByFrontendAppletParameters( - std::unique_ptr process, const FrontendAppletParameters& params) { +void AppletManager::InsertApplet(std::shared_ptr applet) { + std::scoped_lock lk{m_lock}; + + m_applets.emplace(applet->aruid, std::move(applet)); +} + +void AppletManager::TerminateAndRemoveApplet(AppletResourceUserId aruid) { + std::shared_ptr applet; + bool should_stop = false; { std::scoped_lock lk{m_lock}; - m_pending_process = std::move(process); - m_pending_parameters = params; - } - m_cv.notify_all(); -} -void AppletManager::RequestExit() { - std::scoped_lock lk{m_lock}; - if (m_window_system) { - m_window_system->OnExitRequested(); + const auto it = m_applets.find(aruid); + if (it == m_applets.end()) { + return; + } + + applet = it->second; + m_applets.erase(it); + + should_stop = m_applets.empty(); + } + + // Terminate process. + applet->process->Terminate(); + + // If there were no applets left, stop emulation. + if (should_stop) { + m_system.Exit(); } } -void AppletManager::OperationModeChanged() { - std::scoped_lock lk{m_lock}; - if (m_window_system) { - m_window_system->OnOperationModeChanged(); - } -} - -void AppletManager::SetWindowSystem(WindowSystem* window_system) { - std::unique_lock lk{m_lock}; - - m_window_system = window_system; - if (!m_window_system) { - return; - } - - m_cv.wait(lk, [&] { return m_pending_process != nullptr; }); - - const auto& params = m_pending_parameters; - auto applet = std::make_shared(m_system, std::move(m_pending_process), - params.applet_id == AppletId::Application); +void AppletManager::CreateAndInsertByFrontendAppletParameters( + AppletResourceUserId aruid, const FrontendAppletParameters& params) { + // TODO: this should be run inside AM so that the events will have a parent process + // TODO: have am create the guest process + auto applet = std::make_shared(m_system, std::make_unique(m_system)); + applet->aruid = aruid; applet->program_id = params.program_id; applet->applet_id = params.applet_id; applet->type = params.applet_type; @@ -320,19 +322,59 @@ void AppletManager::SetWindowSystem(WindowSystem* window_system) { } // Applet was started by frontend, so it is foreground. - applet->lifecycle_manager.SetFocusState(FocusState::InFocus); + applet->message_queue.PushMessage(AppletMessage::ChangeIntoForeground); + applet->message_queue.PushMessage(AppletMessage::FocusStateChanged); + applet->focus_state = FocusState::InFocus; - if (applet->applet_id == AppletId::QLaunch) { - applet->lifecycle_manager.SetFocusHandlingMode(false); - applet->lifecycle_manager.SetOutOfFocusSuspendingEnabled(false); - m_window_system->TrackApplet(applet, false); - m_window_system->RequestHomeMenuToGetForeground(); - } else { - m_window_system->TrackApplet(applet, true); - m_window_system->RequestApplicationToGetForeground(); + this->InsertApplet(std::move(applet)); +} + +std::shared_ptr AppletManager::GetByAppletResourceUserId(AppletResourceUserId aruid) const { + std::scoped_lock lk{m_lock}; + + if (const auto it = m_applets.find(aruid); it != m_applets.end()) { + return it->second; } - applet->process->Run(); + return {}; +} + +void AppletManager::Reset() { + std::scoped_lock lk{m_lock}; + + m_applets.clear(); +} + +void AppletManager::RequestExit() { + std::scoped_lock lk{m_lock}; + + for (const auto& [aruid, applet] : m_applets) { + applet->message_queue.RequestExit(); + } +} + +void AppletManager::RequestResume() { + std::scoped_lock lk{m_lock}; + + for (const auto& [aruid, applet] : m_applets) { + applet->message_queue.RequestResume(); + } +} + +void AppletManager::OperationModeChanged() { + std::scoped_lock lk{m_lock}; + + for (const auto& [aruid, applet] : m_applets) { + applet->message_queue.OperationModeChanged(); + } +} + +void AppletManager::FocusStateChanged() { + std::scoped_lock lk{m_lock}; + + for (const auto& [aruid, applet] : m_applets) { + applet->message_queue.FocusStateChanged(); + } } } // namespace Service::AM diff --git a/src/core/hle/service/am/applet_manager.h b/src/core/hle/service/am/applet_manager.h index fbdc77140..4875de309 100755 --- a/src/core/hle/service/am/applet_manager.h +++ b/src/core/hle/service/am/applet_manager.h @@ -3,23 +3,17 @@ #pragma once -#include +#include #include -#include "core/hle/service/am/am_types.h" +#include "core/hle/service/am/applet.h" namespace Core { class System; } -namespace Service { -class Process; -} - namespace Service::AM { -class WindowSystem; - enum class LaunchType { FrontendInitiated, ApplicationInitiated, @@ -39,24 +33,27 @@ public: explicit AppletManager(Core::System& system); ~AppletManager(); - void CreateAndInsertByFrontendAppletParameters(std::unique_ptr process, - const FrontendAppletParameters& params); - void RequestExit(); - void OperationModeChanged(); + void InsertApplet(std::shared_ptr applet); + void TerminateAndRemoveApplet(AppletResourceUserId aruid); -public: - void SetWindowSystem(WindowSystem* window_system); + void CreateAndInsertByFrontendAppletParameters(AppletResourceUserId aruid, + const FrontendAppletParameters& params); + std::shared_ptr GetByAppletResourceUserId(AppletResourceUserId aruid) const; + + void Reset(); + + void RequestExit(); + void RequestResume(); + void OperationModeChanged(); + void FocusStateChanged(); private: Core::System& m_system; - std::mutex m_lock; - std::condition_variable m_cv; + mutable std::mutex m_lock{}; + std::map> m_applets{}; - WindowSystem* m_window_system{}; - - FrontendAppletParameters m_pending_parameters{}; - std::unique_ptr m_pending_process{}; + // AudioController state goes here }; } // namespace Service::AM diff --git a/src/core/hle/service/am/frontend/applets.cpp b/src/core/hle/service/am/frontend/applets.cpp index cdd431857..e662c6cd6 100755 --- a/src/core/hle/service/am/frontend/applets.cpp +++ b/src/core/hle/service/am/frontend/applets.cpp @@ -69,11 +69,7 @@ void FrontendApplet::PushInteractiveOutData(std::shared_ptr storage) { } void FrontendApplet::Exit() { - auto applet_ = applet.lock(); - - std::scoped_lock lk{applet_->lock}; - applet_->is_completed = true; - applet_->state_changed_event.Signal(); + applet.lock()->caller_applet_broker->SignalCompletion(); } FrontendAppletSet::FrontendAppletSet() = default; diff --git a/src/core/hle/service/am/hid_registration.cpp b/src/core/hle/service/am/hid_registration.cpp index ea4bd8f45..8ed49bac1 100755 --- a/src/core/hle/service/am/hid_registration.cpp +++ b/src/core/hle/service/am/hid_registration.cpp @@ -3,28 +3,24 @@ #include "core/core.h" #include "core/hle/service/am/hid_registration.h" +#include "core/hle/service/am/process.h" #include "core/hle/service/hid/hid_server.h" -#include "core/hle/service/os/process.h" #include "core/hle/service/sm/sm.h" #include "hid_core/resource_manager.h" namespace Service::AM { HidRegistration::HidRegistration(Core::System& system, Process& process) : m_process(process) { - m_hid_server = system.ServiceManager().GetService("hid", true); + m_hid_server = system.ServiceManager().GetService("hid"); if (m_process.IsInitialized()) { m_hid_server->GetResourceManager()->RegisterAppletResourceUserId(m_process.GetProcessId(), true); - m_hid_server->GetResourceManager()->SetAruidValidForVibration(m_process.GetProcessId(), - true); } } HidRegistration::~HidRegistration() { if (m_process.IsInitialized()) { - m_hid_server->GetResourceManager()->SetAruidValidForVibration(m_process.GetProcessId(), - false); m_hid_server->GetResourceManager()->UnregisterAppletResourceUserId( m_process.GetProcessId()); } @@ -32,8 +28,6 @@ HidRegistration::~HidRegistration() { void HidRegistration::EnableAppletToGetInput(bool enable) { if (m_process.IsInitialized()) { - m_hid_server->GetResourceManager()->SetAruidValidForVibration(m_process.GetProcessId(), - enable); m_hid_server->GetResourceManager()->EnableInput(m_process.GetProcessId(), enable); } } diff --git a/src/core/hle/service/am/hid_registration.h b/src/core/hle/service/am/hid_registration.h index 54f42af18..67cd84961 100755 --- a/src/core/hle/service/am/hid_registration.h +++ b/src/core/hle/service/am/hid_registration.h @@ -13,12 +13,10 @@ namespace Service::HID { class IHidServer; } -namespace Service { -class Process; -} - namespace Service::AM { +class Process; + class HidRegistration { public: explicit HidRegistration(Core::System& system, Process& process); diff --git a/src/core/hle/service/am/service/all_system_applet_proxies_service.cpp b/src/core/hle/service/am/service/all_system_applet_proxies_service.cpp index bc9c86c55..21747783a 100755 --- a/src/core/hle/service/am/service/all_system_applet_proxies_service.cpp +++ b/src/core/hle/service/am/service/all_system_applet_proxies_service.cpp @@ -6,14 +6,12 @@ #include "core/hle/service/am/service/all_system_applet_proxies_service.h" #include "core/hle/service/am/service/library_applet_proxy.h" #include "core/hle/service/am/service/system_applet_proxy.h" -#include "core/hle/service/am/window_system.h" #include "core/hle/service/cmif_serialization.h" namespace Service::AM { -IAllSystemAppletProxiesService::IAllSystemAppletProxiesService(Core::System& system_, - WindowSystem& window_system) - : ServiceFramework{system_, "appletAE"}, m_window_system{window_system} { +IAllSystemAppletProxiesService::IAllSystemAppletProxiesService(Core::System& system_) + : ServiceFramework{system_, "appletAE"} { // clang-format off static const FunctionInfo functions[] = { {100, D<&IAllSystemAppletProxiesService::OpenSystemAppletProxy>, "OpenSystemAppletProxy"}, @@ -38,8 +36,8 @@ Result IAllSystemAppletProxiesService::OpenSystemAppletProxy( LOG_DEBUG(Service_AM, "called"); if (const auto applet = this->GetAppletFromProcessId(pid); applet) { - *out_system_applet_proxy = std::make_shared( - system, applet, process_handle.Get(), m_window_system); + *out_system_applet_proxy = + std::make_shared(system, applet, process_handle.Get()); R_SUCCEED(); } else { UNIMPLEMENTED(); @@ -54,8 +52,8 @@ Result IAllSystemAppletProxiesService::OpenLibraryAppletProxy( LOG_DEBUG(Service_AM, "called"); if (const auto applet = this->GetAppletFromProcessId(pid); applet) { - *out_library_applet_proxy = std::make_shared( - system, applet, process_handle.Get(), m_window_system); + *out_library_applet_proxy = + std::make_shared(system, applet, process_handle.Get()); R_SUCCEED(); } else { UNIMPLEMENTED(); @@ -75,7 +73,7 @@ Result IAllSystemAppletProxiesService::OpenLibraryAppletProxyOld( std::shared_ptr IAllSystemAppletProxiesService::GetAppletFromProcessId( ProcessId process_id) { - return m_window_system.GetByAppletResourceUserId(process_id.pid); + return system.GetAppletManager().GetByAppletResourceUserId(process_id.pid); } } // namespace Service::AM diff --git a/src/core/hle/service/am/service/all_system_applet_proxies_service.h b/src/core/hle/service/am/service/all_system_applet_proxies_service.h index e3e79dc4f..0e2dcb86d 100755 --- a/src/core/hle/service/am/service/all_system_applet_proxies_service.h +++ b/src/core/hle/service/am/service/all_system_applet_proxies_service.h @@ -14,12 +14,11 @@ struct Applet; struct AppletAttribute; class ILibraryAppletProxy; class ISystemAppletProxy; -class WindowSystem; class IAllSystemAppletProxiesService final : public ServiceFramework { public: - explicit IAllSystemAppletProxiesService(Core::System& system_, WindowSystem& window_system); + explicit IAllSystemAppletProxiesService(Core::System& system_); ~IAllSystemAppletProxiesService() override; private: @@ -36,8 +35,6 @@ private: private: std::shared_ptr GetAppletFromProcessId(ProcessId pid); - - WindowSystem& m_window_system; }; } // namespace AM diff --git a/src/core/hle/service/am/service/applet_common_functions.cpp b/src/core/hle/service/am/service/applet_common_functions.cpp index a051000af..0f29ab285 100755 --- a/src/core/hle/service/am/service/applet_common_functions.cpp +++ b/src/core/hle/service/am/service/applet_common_functions.cpp @@ -19,7 +19,7 @@ IAppletCommonFunctions::IAppletCommonFunctions(Core::System& system_, {21, nullptr, "TryPopFromAppletBoundChannel"}, {40, nullptr, "GetDisplayLogicalResolution"}, {42, nullptr, "SetDisplayMagnification"}, - {50, D<&IAppletCommonFunctions::SetHomeButtonDoubleClickEnabled>, "SetHomeButtonDoubleClickEnabled"}, + {50, nullptr, "SetHomeButtonDoubleClickEnabled"}, {51, D<&IAppletCommonFunctions::GetHomeButtonDoubleClickEnabled>, "GetHomeButtonDoubleClickEnabled"}, {52, nullptr, "IsHomeButtonShortPressedBlocked"}, {60, nullptr, "IsVrModeCurtainRequired"}, @@ -40,13 +40,6 @@ IAppletCommonFunctions::IAppletCommonFunctions(Core::System& system_, IAppletCommonFunctions::~IAppletCommonFunctions() = default; -Result IAppletCommonFunctions::SetHomeButtonDoubleClickEnabled( - bool home_button_double_click_enabled) { - LOG_WARNING(Service_AM, "(STUBBED) called, home_button_double_click_enabled={}", - home_button_double_click_enabled); - R_SUCCEED(); -} - Result IAppletCommonFunctions::GetHomeButtonDoubleClickEnabled( Out out_home_button_double_click_enabled) { LOG_WARNING(Service_AM, "(STUBBED) called"); diff --git a/src/core/hle/service/am/service/applet_common_functions.h b/src/core/hle/service/am/service/applet_common_functions.h index 376f85acf..4424fc83d 100755 --- a/src/core/hle/service/am/service/applet_common_functions.h +++ b/src/core/hle/service/am/service/applet_common_functions.h @@ -16,7 +16,6 @@ public: ~IAppletCommonFunctions() override; private: - Result SetHomeButtonDoubleClickEnabled(bool home_button_double_click_enabled); Result GetHomeButtonDoubleClickEnabled(Out out_home_button_double_click_enabled); Result SetCpuBoostRequestPriority(s32 priority); Result GetCurrentApplicationId(Out out_application_id); diff --git a/src/core/hle/service/am/service/application_accessor.cpp b/src/core/hle/service/am/service/application_accessor.cpp index 986abc716..6e7d110e8 100755 --- a/src/core/hle/service/am/service/application_accessor.cpp +++ b/src/core/hle/service/am/service/application_accessor.cpp @@ -9,16 +9,12 @@ #include "core/hle/service/am/service/application_accessor.h" #include "core/hle/service/am/service/library_applet_accessor.h" #include "core/hle/service/am/service/storage.h" -#include "core/hle/service/am/window_system.h" #include "core/hle/service/cmif_serialization.h" -#include "core/hle/service/glue/glue_manager.h" namespace Service::AM { -IApplicationAccessor::IApplicationAccessor(Core::System& system_, std::shared_ptr applet, - WindowSystem& window_system) - : ServiceFramework{system_, "IApplicationAccessor"}, m_window_system(window_system), - m_applet(std::move(applet)) { +IApplicationAccessor::IApplicationAccessor(Core::System& system_, std::shared_ptr applet) + : ServiceFramework{system_, "IApplicationAccessor"}, m_applet(std::move(applet)) { // clang-format off static const FunctionInfo functions[] = { {0, D<&IApplicationAccessor::GetAppletStateChangedEvent>, "GetAppletStateChangedEvent"}, @@ -63,15 +59,7 @@ Result IApplicationAccessor::Start() { Result IApplicationAccessor::RequestExit() { LOG_INFO(Service_AM, "called"); - - std::scoped_lock lk{m_applet->lock}; - if (m_applet->exit_locked) { - m_applet->lifecycle_manager.RequestExit(); - m_applet->UpdateSuspensionStateLocked(true); - } else { - m_applet->process->Terminate(); - } - + m_applet->message_queue.RequestExit(); R_SUCCEED(); } @@ -83,14 +71,13 @@ Result IApplicationAccessor::Terminate() { Result IApplicationAccessor::GetResult() { LOG_INFO(Service_AM, "called"); - std::scoped_lock lk{m_applet->lock}; - R_RETURN(m_applet->terminate_result); + R_SUCCEED(); } Result IApplicationAccessor::GetAppletStateChangedEvent( OutCopyHandle out_event) { LOG_INFO(Service_AM, "called"); - *out_event = m_applet->state_changed_event.GetHandle(); + *out_event = m_applet->caller_applet_broker->GetStateChangedEvent().GetHandle(); R_SUCCEED(); } @@ -109,15 +96,8 @@ Result IApplicationAccessor::PushLaunchParameter(LaunchParameterKind kind, Result IApplicationAccessor::GetApplicationControlProperty( OutBuffer out_control_property) { - LOG_INFO(Service_AM, "called"); - - std::vector nacp; - R_TRY(system.GetARPManager().GetControlProperty(&nacp, m_applet->program_id)); - - std::memcpy(out_control_property.data(), nacp.data(), - std::min(out_control_property.size(), nacp.size())); - - R_SUCCEED(); + LOG_WARNING(Service_AM, "(STUBBED) called"); + R_THROW(ResultUnknown); } Result IApplicationAccessor::SetUsers(bool enable, @@ -134,9 +114,8 @@ Result IApplicationAccessor::GetCurrentLibraryApplet( } Result IApplicationAccessor::RequestForApplicationToGetForeground() { - LOG_INFO(Service_AM, "called"); - m_window_system.RequestApplicationToGetForeground(); - R_SUCCEED(); + LOG_WARNING(Service_AM, "(STUBBED) called"); + R_THROW(ResultUnknown); } Result IApplicationAccessor::CheckRightsEnvironmentAvailable(Out out_is_available) { diff --git a/src/core/hle/service/am/service/application_accessor.h b/src/core/hle/service/am/service/application_accessor.h index b9797bcc0..39a9b2153 100755 --- a/src/core/hle/service/am/service/application_accessor.h +++ b/src/core/hle/service/am/service/application_accessor.h @@ -13,12 +13,10 @@ namespace Service::AM { struct Applet; class ILibraryAppletAccessor; class IStorage; -class WindowSystem; class IApplicationAccessor final : public ServiceFramework { public: - explicit IApplicationAccessor(Core::System& system_, std::shared_ptr applet, - WindowSystem& window_system); + explicit IApplicationAccessor(Core::System& system_, std::shared_ptr applet); ~IApplicationAccessor() override; private: @@ -36,7 +34,6 @@ private: Result GetNsRightsEnvironmentHandle(Out out_handle); Result ReportApplicationExitTimeout(); - WindowSystem& m_window_system; const std::shared_ptr m_applet; }; diff --git a/src/core/hle/service/am/service/application_creator.cpp b/src/core/hle/service/am/service/application_creator.cpp index 8994f1914..568bb0122 100755 --- a/src/core/hle/service/am/service/application_creator.cpp +++ b/src/core/hle/service/am/service/application_creator.cpp @@ -1,57 +1,17 @@ // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "core/file_sys/nca_metadata.h" -#include "core/file_sys/registered_cache.h" #include "core/hle/service/am/am_types.h" #include "core/hle/service/am/applet.h" #include "core/hle/service/am/applet_manager.h" -#include "core/hle/service/am/process_creation.h" #include "core/hle/service/am/service/application_accessor.h" #include "core/hle/service/am/service/application_creator.h" -#include "core/hle/service/am/window_system.h" #include "core/hle/service/cmif_serialization.h" -#include "core/loader/loader.h" namespace Service::AM { -namespace { - -Result CreateGuestApplication(SharedPointer* out_application_accessor, - Core::System& system, WindowSystem& window_system, u64 program_id) { - FileSys::VirtualFile nca_raw{}; - - // Get the program NCA from storage. - auto& storage = system.GetContentProviderUnion(); - nca_raw = storage.GetEntryRaw(program_id, FileSys::ContentRecordType::Program); - - // Ensure we retrieved a program NCA. - R_UNLESS(nca_raw != nullptr, ResultUnknown); - - std::vector control; - std::unique_ptr loader; - Loader::ResultStatus result; - auto process = - CreateApplicationProcess(control, loader, result, system, nca_raw, program_id, 0); - R_UNLESS(process != nullptr, ResultUnknown); - - const auto applet = std::make_shared(system, std::move(process), true); - applet->program_id = program_id; - applet->applet_id = AppletId::Application; - applet->type = AppletType::Application; - applet->library_applet_mode = LibraryAppletMode::AllForeground; - - window_system.TrackApplet(applet, true); - - *out_application_accessor = - std::make_shared(system, applet, window_system); - R_SUCCEED(); -} - -} // namespace - -IApplicationCreator::IApplicationCreator(Core::System& system_, WindowSystem& window_system) - : ServiceFramework{system_, "IApplicationCreator"}, m_window_system{window_system} { +IApplicationCreator::IApplicationCreator(Core::System& system_) + : ServiceFramework{system_, "IApplicationCreator"} { // clang-format off static const FunctionInfo functions[] = { {0, D<&IApplicationCreator::CreateApplication>, "CreateApplication"}, @@ -68,9 +28,8 @@ IApplicationCreator::~IApplicationCreator() = default; Result IApplicationCreator::CreateApplication( Out> out_application_accessor, u64 application_id) { - LOG_INFO(Service_NS, "called, application_id={:016X}", application_id); - R_RETURN( - CreateGuestApplication(out_application_accessor, system, m_window_system, application_id)); + LOG_ERROR(Service_NS, "called, application_id={:x}", application_id); + R_THROW(ResultUnknown); } } // namespace Service::AM diff --git a/src/core/hle/service/am/service/application_creator.h b/src/core/hle/service/am/service/application_creator.h index 287745af8..9f939ebf6 100755 --- a/src/core/hle/service/am/service/application_creator.h +++ b/src/core/hle/service/am/service/application_creator.h @@ -10,17 +10,14 @@ namespace Service::AM { class IApplicationAccessor; struct Applet; -class WindowSystem; class IApplicationCreator final : public ServiceFramework { public: - explicit IApplicationCreator(Core::System& system_, WindowSystem& window_system); + explicit IApplicationCreator(Core::System& system_); ~IApplicationCreator() override; private: Result CreateApplication(Out>, u64 application_id); - - WindowSystem& m_window_system; }; } // namespace Service::AM diff --git a/src/core/hle/service/am/service/application_functions.cpp b/src/core/hle/service/am/service/application_functions.cpp index 3bab5ac5f..bfccb6b09 100755 --- a/src/core/hle/service/am/service/application_functions.cpp +++ b/src/core/hle/service/am/service/application_functions.cpp @@ -181,8 +181,7 @@ Result IApplicationFunctions::GetDesiredLanguage(Out out_language_code) { } Result IApplicationFunctions::SetTerminateResult(Result terminate_result) { - LOG_INFO(Service_AM, "(STUBBED) called, result={:#x} ({:04}-{:04})", - terminate_result.GetInnerValue(), + LOG_INFO(Service_AM, "(STUBBED) called, result={:#x} ({}-{})", terminate_result.GetInnerValue(), static_cast(terminate_result.GetModule()) + 2000, terminate_result.GetDescription()); diff --git a/src/core/hle/service/am/service/application_proxy.cpp b/src/core/hle/service/am/service/application_proxy.cpp index 6e1328fee..19d6a3b89 100755 --- a/src/core/hle/service/am/service/application_proxy.cpp +++ b/src/core/hle/service/am/service/application_proxy.cpp @@ -17,9 +17,9 @@ namespace Service::AM { IApplicationProxy::IApplicationProxy(Core::System& system_, std::shared_ptr applet, - Kernel::KProcess* process, WindowSystem& window_system) - : ServiceFramework{system_, "IApplicationProxy"}, - m_window_system{window_system}, m_process{process}, m_applet{std::move(applet)} { + Kernel::KProcess* process) + : ServiceFramework{system_, "IApplicationProxy"}, m_process{process}, m_applet{ + std::move(applet)} { // clang-format off static const FunctionInfo functions[] = { {0, D<&IApplicationProxy::GetCommonStateGetter>, "GetCommonStateGetter"}, @@ -70,7 +70,7 @@ Result IApplicationProxy::GetDebugFunctions( Result IApplicationProxy::GetWindowController( Out> out_window_controller) { LOG_DEBUG(Service_AM, "called"); - *out_window_controller = std::make_shared(system, m_applet, m_window_system); + *out_window_controller = std::make_shared(system, m_applet); R_SUCCEED(); } @@ -91,8 +91,7 @@ Result IApplicationProxy::GetCommonStateGetter( Result IApplicationProxy::GetLibraryAppletCreator( Out> out_library_applet_creator) { LOG_DEBUG(Service_AM, "called"); - *out_library_applet_creator = - std::make_shared(system, m_applet, m_window_system); + *out_library_applet_creator = std::make_shared(system, m_applet); R_SUCCEED(); } diff --git a/src/core/hle/service/am/service/application_proxy.h b/src/core/hle/service/am/service/application_proxy.h index 8c62459c4..6da350df7 100755 --- a/src/core/hle/service/am/service/application_proxy.h +++ b/src/core/hle/service/am/service/application_proxy.h @@ -18,12 +18,11 @@ class ILibraryAppletCreator; class IProcessWindingController; class ISelfController; class IWindowController; -class WindowSystem; class IApplicationProxy final : public ServiceFramework { public: explicit IApplicationProxy(Core::System& system_, std::shared_ptr applet, - Kernel::KProcess* process, WindowSystem& window_system); + Kernel::KProcess* process); ~IApplicationProxy(); private: @@ -41,7 +40,6 @@ private: Out> out_application_functions); private: - WindowSystem& m_window_system; Kernel::KProcess* const m_process; const std::shared_ptr m_applet; }; diff --git a/src/core/hle/service/am/service/application_proxy_service.cpp b/src/core/hle/service/am/service/application_proxy_service.cpp index b7d7b3c2d..fd66e77b9 100755 --- a/src/core/hle/service/am/service/application_proxy_service.cpp +++ b/src/core/hle/service/am/service/application_proxy_service.cpp @@ -6,14 +6,12 @@ #include "core/hle/service/am/applet_manager.h" #include "core/hle/service/am/service/application_proxy.h" #include "core/hle/service/am/service/application_proxy_service.h" -#include "core/hle/service/am/window_system.h" #include "core/hle/service/cmif_serialization.h" namespace Service::AM { -IApplicationProxyService::IApplicationProxyService(Core::System& system_, - WindowSystem& window_system) - : ServiceFramework{system_, "appletOE"}, m_window_system{window_system} { +IApplicationProxyService::IApplicationProxyService(Core::System& system_) + : ServiceFramework{system_, "appletOE"} { static const FunctionInfo functions[] = { {0, D<&IApplicationProxyService::OpenApplicationProxy>, "OpenApplicationProxy"}, }; @@ -28,8 +26,8 @@ Result IApplicationProxyService::OpenApplicationProxy( LOG_DEBUG(Service_AM, "called"); if (const auto applet = this->GetAppletFromProcessId(pid)) { - *out_application_proxy = std::make_shared( - system, applet, process_handle.Get(), m_window_system); + *out_application_proxy = + std::make_shared(system, applet, process_handle.Get()); R_SUCCEED(); } else { UNIMPLEMENTED(); @@ -38,7 +36,7 @@ Result IApplicationProxyService::OpenApplicationProxy( } std::shared_ptr IApplicationProxyService::GetAppletFromProcessId(ProcessId process_id) { - return m_window_system.GetByAppletResourceUserId(process_id.pid); + return system.GetAppletManager().GetByAppletResourceUserId(process_id.pid); } } // namespace Service::AM diff --git a/src/core/hle/service/am/service/application_proxy_service.h b/src/core/hle/service/am/service/application_proxy_service.h index e5f4ea345..8efafa31a 100755 --- a/src/core/hle/service/am/service/application_proxy_service.h +++ b/src/core/hle/service/am/service/application_proxy_service.h @@ -12,11 +12,10 @@ namespace AM { struct Applet; class IApplicationProxy; -class WindowSystem; class IApplicationProxyService final : public ServiceFramework { public: - explicit IApplicationProxyService(Core::System& system_, WindowSystem& window_system); + explicit IApplicationProxyService(Core::System& system_); ~IApplicationProxyService() override; private: @@ -25,8 +24,6 @@ private: private: std::shared_ptr GetAppletFromProcessId(ProcessId pid); - - WindowSystem& m_window_system; }; } // namespace AM diff --git a/src/core/hle/service/am/service/common_state_getter.cpp b/src/core/hle/service/am/service/common_state_getter.cpp index f523bcd9e..a32855ffa 100755 --- a/src/core/hle/service/am/service/common_state_getter.cpp +++ b/src/core/hle/service/am/service/common_state_getter.cpp @@ -80,14 +80,15 @@ ICommonStateGetter::~ICommonStateGetter() = default; Result ICommonStateGetter::GetEventHandle(OutCopyHandle out_event) { LOG_DEBUG(Service_AM, "called"); - *out_event = m_applet->lifecycle_manager.GetSystemEvent().GetHandle(); + *out_event = &m_applet->message_queue.GetMessageReceiveEvent(); R_SUCCEED(); } Result ICommonStateGetter::ReceiveMessage(Out out_applet_message) { LOG_DEBUG(Service_AM, "called"); - if (!m_applet->lifecycle_manager.PopMessage(out_applet_message)) { + *out_applet_message = m_applet->message_queue.PopMessage(); + if (*out_applet_message == AppletMessage::None) { LOG_ERROR(Service_AM, "Tried to pop message but none was available!"); R_THROW(AM::ResultNoMessages); } @@ -99,7 +100,7 @@ Result ICommonStateGetter::GetCurrentFocusState(Out out_focus_state) LOG_DEBUG(Service_AM, "called"); std::scoped_lock lk{m_applet->lock}; - *out_focus_state = m_applet->lifecycle_manager.GetAndClearFocusState(); + *out_focus_state = m_applet->focus_state; R_SUCCEED(); } @@ -136,7 +137,7 @@ Result ICommonStateGetter::GetWriterLockAccessorEx( Result ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent( OutCopyHandle out_event) { LOG_DEBUG(Service_AM, "called"); - *out_event = m_applet->lifecycle_manager.GetOperationModeChangedSystemEvent().GetHandle(); + *out_event = &m_applet->message_queue.GetOperationModeChangedEvent(); R_SUCCEED(); } diff --git a/src/core/hle/service/am/service/home_menu_functions.cpp b/src/core/hle/service/am/service/home_menu_functions.cpp index 25f78beb5..0c4d24b58 100755 --- a/src/core/hle/service/am/service/home_menu_functions.cpp +++ b/src/core/hle/service/am/service/home_menu_functions.cpp @@ -4,16 +4,13 @@ #include "core/hle/result.h" #include "core/hle/service/am/applet_manager.h" #include "core/hle/service/am/service/home_menu_functions.h" -#include "core/hle/service/am/window_system.h" #include "core/hle/service/cmif_serialization.h" namespace Service::AM { -IHomeMenuFunctions::IHomeMenuFunctions(Core::System& system_, std::shared_ptr applet, - WindowSystem& window_system) - : ServiceFramework{system_, "IHomeMenuFunctions"}, m_window_system{window_system}, - m_applet{std::move(applet)}, m_context{system, "IHomeMenuFunctions"}, - m_pop_from_general_channel_event{m_context} { +IHomeMenuFunctions::IHomeMenuFunctions(Core::System& system_, std::shared_ptr applet) + : ServiceFramework{system_, "IHomeMenuFunctions"}, m_applet{std::move(applet)}, + m_context{system, "IHomeMenuFunctions"}, m_pop_from_general_channel_event{m_context} { // clang-format off static const FunctionInfo functions[] = { {10, D<&IHomeMenuFunctions::RequestToGetForeground>, "RequestToGetForeground"}, @@ -40,20 +37,17 @@ IHomeMenuFunctions::IHomeMenuFunctions(Core::System& system_, std::shared_ptr { public: - explicit IHomeMenuFunctions(Core::System& system_, std::shared_ptr applet, - WindowSystem& window_system); + explicit IHomeMenuFunctions(Core::System& system_, std::shared_ptr applet); ~IHomeMenuFunctions() override; private: @@ -28,7 +26,6 @@ private: Result IsForceTerminateApplicationDisabledForDebug( Out out_is_force_terminate_application_disabled_for_debug); - WindowSystem& m_window_system; const std::shared_ptr m_applet; KernelHelpers::ServiceContext m_context; Event m_pop_from_general_channel_event; diff --git a/src/core/hle/service/am/service/library_applet_accessor.cpp b/src/core/hle/service/am/service/library_applet_accessor.cpp index cda8c3eb8..0c2426d4b 100755 --- a/src/core/hle/service/am/service/library_applet_accessor.cpp +++ b/src/core/hle/service/am/service/library_applet_accessor.cpp @@ -47,21 +47,20 @@ ILibraryAppletAccessor::~ILibraryAppletAccessor() = default; Result ILibraryAppletAccessor::GetAppletStateChangedEvent( OutCopyHandle out_event) { LOG_DEBUG(Service_AM, "called"); - *out_event = m_applet->state_changed_event.GetHandle(); + *out_event = m_broker->GetStateChangedEvent().GetHandle(); R_SUCCEED(); } Result ILibraryAppletAccessor::IsCompleted(Out out_is_completed) { LOG_DEBUG(Service_AM, "called"); - std::scoped_lock lk{m_applet->lock}; - *out_is_completed = m_applet->is_completed; + *out_is_completed = m_broker->IsCompleted(); R_SUCCEED(); } -Result ILibraryAppletAccessor::GetResult() { +Result ILibraryAppletAccessor::GetResult(Out out_result) { LOG_DEBUG(Service_AM, "called"); - std::scoped_lock lk{m_applet->lock}; - R_RETURN(m_applet->terminate_result); + *out_result = m_applet->terminate_result; + R_SUCCEED(); } Result ILibraryAppletAccessor::PresetLibraryAppletGpuTimeSliceZero() { @@ -78,10 +77,7 @@ Result ILibraryAppletAccessor::Start() { Result ILibraryAppletAccessor::RequestExit() { LOG_DEBUG(Service_AM, "called"); - { - std::scoped_lock lk{m_applet->lock}; - m_applet->lifecycle_manager.RequestExit(); - } + m_applet->message_queue.RequestExit(); FrontendRequestExit(); R_SUCCEED(); } diff --git a/src/core/hle/service/am/service/library_applet_accessor.h b/src/core/hle/service/am/service/library_applet_accessor.h index 36712821a..97d3b6c8a 100755 --- a/src/core/hle/service/am/service/library_applet_accessor.h +++ b/src/core/hle/service/am/service/library_applet_accessor.h @@ -21,7 +21,7 @@ public: private: Result GetAppletStateChangedEvent(OutCopyHandle out_event); Result IsCompleted(Out out_is_completed); - Result GetResult(); + Result GetResult(Out out_result); Result PresetLibraryAppletGpuTimeSliceZero(); Result Start(); Result RequestExit(); diff --git a/src/core/hle/service/am/service/library_applet_creator.cpp b/src/core/hle/service/am/service/library_applet_creator.cpp index 3ffb03bc9..c97358d81 100755 --- a/src/core/hle/service/am/service/library_applet_creator.cpp +++ b/src/core/hle/service/am/service/library_applet_creator.cpp @@ -7,11 +7,9 @@ #include "core/hle/service/am/applet_manager.h" #include "core/hle/service/am/frontend/applets.h" #include "core/hle/service/am/library_applet_storage.h" -#include "core/hle/service/am/process_creation.h" #include "core/hle/service/am/service/library_applet_accessor.h" #include "core/hle/service/am/service/library_applet_creator.h" #include "core/hle/service/am/service/storage.h" -#include "core/hle/service/am/window_system.h" #include "core/hle/service/cmif_serialization.h" #include "core/hle/service/sm/sm.h" @@ -95,7 +93,6 @@ AppletProgramId AppletIdToProgramId(AppletId applet_id) { } std::shared_ptr CreateGuestApplet(Core::System& system, - WindowSystem& window_system, std::shared_ptr caller_applet, AppletId applet_id, LibraryAppletMode mode) { @@ -113,38 +110,53 @@ std::shared_ptr CreateGuestApplet(Core::System& system, Firmware1700 = 17, }; - auto process = CreateProcess(system, program_id, Firmware1400, Firmware1700); - if (!process) { + auto process = std::make_unique(system); + if (!process->Initialize(program_id, Firmware1400, Firmware1700)) { // Couldn't initialize the guest process return {}; } - const auto applet = std::make_shared(system, std::move(process), false); + const auto applet = std::make_shared(system, std::move(process)); applet->program_id = program_id; applet->applet_id = applet_id; applet->type = AppletType::LibraryApplet; applet->library_applet_mode = mode; - applet->window_visible = mode != LibraryAppletMode::AllForegroundInitiallyHidden; + + // Set focus state + switch (mode) { + case LibraryAppletMode::AllForeground: + case LibraryAppletMode::NoUi: + case LibraryAppletMode::PartialForeground: + case LibraryAppletMode::PartialForegroundIndirectDisplay: + applet->hid_registration.EnableAppletToGetInput(true); + applet->focus_state = FocusState::InFocus; + applet->message_queue.PushMessage(AppletMessage::ChangeIntoForeground); + break; + case LibraryAppletMode::AllForegroundInitiallyHidden: + applet->hid_registration.EnableAppletToGetInput(false); + applet->focus_state = FocusState::NotInFocus; + applet->display_layer_manager.SetWindowVisibility(false); + applet->message_queue.PushMessage(AppletMessage::ChangeIntoBackground); + break; + } auto broker = std::make_shared(system); applet->caller_applet = caller_applet; applet->caller_applet_broker = broker; - caller_applet->child_applets.push_back(applet); - window_system.TrackApplet(applet, false); + system.GetAppletManager().InsertApplet(applet); return std::make_shared(system, broker, applet); } std::shared_ptr CreateFrontendApplet(Core::System& system, - WindowSystem& window_system, std::shared_ptr caller_applet, AppletId applet_id, LibraryAppletMode mode) { const auto program_id = static_cast(AppletIdToProgramId(applet_id)); auto process = std::make_unique(system); - auto applet = std::make_shared(system, std::move(process), false); + auto applet = std::make_shared(system, std::move(process)); applet->program_id = program_id; applet->applet_id = applet_id; applet->type = AppletType::LibraryApplet; @@ -154,19 +166,14 @@ std::shared_ptr CreateFrontendApplet(Core::System& syste applet->caller_applet = caller_applet; applet->caller_applet_broker = storage; applet->frontend = system.GetFrontendAppletHolder().GetApplet(applet, applet_id, mode); - caller_applet->child_applets.push_back(applet); - - window_system.TrackApplet(applet, false); return std::make_shared(system, storage, applet); } } // namespace -ILibraryAppletCreator::ILibraryAppletCreator(Core::System& system_, std::shared_ptr applet, - WindowSystem& window_system) - : ServiceFramework{system_, "ILibraryAppletCreator"}, - m_window_system{window_system}, m_applet{std::move(applet)} { +ILibraryAppletCreator::ILibraryAppletCreator(Core::System& system_, std::shared_ptr applet) + : ServiceFramework{system_, "ILibraryAppletCreator"}, m_applet{std::move(applet)} { static const FunctionInfo functions[] = { {0, D<&ILibraryAppletCreator::CreateLibraryApplet>, "CreateLibraryApplet"}, {1, nullptr, "TerminateAllLibraryApplets"}, @@ -188,12 +195,10 @@ Result ILibraryAppletCreator::CreateLibraryApplet( std::shared_ptr library_applet; if (ShouldCreateGuestApplet(applet_id)) { - library_applet = - CreateGuestApplet(system, m_window_system, m_applet, applet_id, library_applet_mode); + library_applet = CreateGuestApplet(system, m_applet, applet_id, library_applet_mode); } if (!library_applet) { - library_applet = - CreateFrontendApplet(system, m_window_system, m_applet, applet_id, library_applet_mode); + library_applet = CreateFrontendApplet(system, m_applet, applet_id, library_applet_mode); } if (!library_applet) { LOG_ERROR(Service_AM, "Applet doesn't exist! applet_id={}", applet_id); diff --git a/src/core/hle/service/am/service/library_applet_creator.h b/src/core/hle/service/am/service/library_applet_creator.h index a10a76982..fe6d40eb3 100755 --- a/src/core/hle/service/am/service/library_applet_creator.h +++ b/src/core/hle/service/am/service/library_applet_creator.h @@ -12,12 +12,10 @@ namespace Service::AM { struct Applet; class ILibraryAppletAccessor; class IStorage; -class WindowSystem; class ILibraryAppletCreator final : public ServiceFramework { public: - explicit ILibraryAppletCreator(Core::System& system_, std::shared_ptr applet, - WindowSystem& window_system); + explicit ILibraryAppletCreator(Core::System& system_, std::shared_ptr applet); ~ILibraryAppletCreator() override; private: @@ -31,7 +29,6 @@ private: Result CreateHandleStorage(Out> out_storage, s64 size, InCopyHandle transfer_memory_handle); - WindowSystem& m_window_system; const std::shared_ptr m_applet; }; diff --git a/src/core/hle/service/am/service/library_applet_proxy.cpp b/src/core/hle/service/am/service/library_applet_proxy.cpp index f9cfb82a9..58e709347 100755 --- a/src/core/hle/service/am/service/library_applet_proxy.cpp +++ b/src/core/hle/service/am/service/library_applet_proxy.cpp @@ -19,9 +19,9 @@ namespace Service::AM { ILibraryAppletProxy::ILibraryAppletProxy(Core::System& system_, std::shared_ptr applet, - Kernel::KProcess* process, WindowSystem& window_system) - : ServiceFramework{system_, "ILibraryAppletProxy"}, - m_window_system{window_system}, m_process{process}, m_applet{std::move(applet)} { + Kernel::KProcess* process) + : ServiceFramework{system_, "ILibraryAppletProxy"}, m_process{process}, m_applet{ + std::move(applet)} { // clang-format off static const FunctionInfo functions[] = { {0, D<&ILibraryAppletProxy::GetCommonStateGetter>, "GetCommonStateGetter"}, @@ -75,7 +75,7 @@ Result ILibraryAppletProxy::GetDebugFunctions( Result ILibraryAppletProxy::GetWindowController( Out> out_window_controller) { LOG_DEBUG(Service_AM, "called"); - *out_window_controller = std::make_shared(system, m_applet, m_window_system); + *out_window_controller = std::make_shared(system, m_applet); R_SUCCEED(); } @@ -96,8 +96,7 @@ Result ILibraryAppletProxy::GetCommonStateGetter( Result ILibraryAppletProxy::GetLibraryAppletCreator( Out> out_library_applet_creator) { LOG_DEBUG(Service_AM, "called"); - *out_library_applet_creator = - std::make_shared(system, m_applet, m_window_system); + *out_library_applet_creator = std::make_shared(system, m_applet); R_SUCCEED(); } @@ -119,8 +118,7 @@ Result ILibraryAppletProxy::GetAppletCommonFunctions( Result ILibraryAppletProxy::GetHomeMenuFunctions( Out> out_home_menu_functions) { LOG_DEBUG(Service_AM, "called"); - *out_home_menu_functions = - std::make_shared(system, m_applet, m_window_system); + *out_home_menu_functions = std::make_shared(system, m_applet); R_SUCCEED(); } diff --git a/src/core/hle/service/am/service/library_applet_proxy.h b/src/core/hle/service/am/service/library_applet_proxy.h index 792d58582..7d0714b85 100755 --- a/src/core/hle/service/am/service/library_applet_proxy.h +++ b/src/core/hle/service/am/service/library_applet_proxy.h @@ -21,12 +21,11 @@ class ILibraryAppletSelfAccessor; class IProcessWindingController; class ISelfController; class IWindowController; -class WindowSystem; class ILibraryAppletProxy final : public ServiceFramework { public: explicit ILibraryAppletProxy(Core::System& system_, std::shared_ptr applet, - Kernel::KProcess* process, WindowSystem& window_system); + Kernel::KProcess* process); ~ILibraryAppletProxy(); private: @@ -48,7 +47,6 @@ private: Result GetGlobalStateController( Out> out_global_state_controller); - WindowSystem& m_window_system; Kernel::KProcess* const m_process; const std::shared_ptr m_applet; }; diff --git a/src/core/hle/service/am/service/library_applet_self_accessor.cpp b/src/core/hle/service/am/service/library_applet_self_accessor.cpp index 3fe36b899..330eb26f0 100755 --- a/src/core/hle/service/am/service/library_applet_self_accessor.cpp +++ b/src/core/hle/service/am/service/library_applet_self_accessor.cpp @@ -176,7 +176,8 @@ Result ILibraryAppletSelfAccessor::GetMainAppletStorageId(Outprocess->Terminate(); + system.GetAppletManager().TerminateAndRemoveApplet(m_applet->aruid); + m_broker->SignalCompletion(); R_SUCCEED(); } diff --git a/src/core/hle/service/am/service/self_controller.cpp b/src/core/hle/service/am/service/self_controller.cpp index 1db02b88f..06314407c 100755 --- a/src/core/hle/service/am/service/self_controller.cpp +++ b/src/core/hle/service/am/service/self_controller.cpp @@ -86,7 +86,8 @@ ISelfController::~ISelfController() { Result ISelfController::Exit() { LOG_DEBUG(Service_AM, "called"); - m_applet->process->Terminate(); + // TODO + system.Exit(); R_SUCCEED(); } @@ -94,16 +95,7 @@ Result ISelfController::Exit() { Result ISelfController::LockExit() { LOG_DEBUG(Service_AM, "called"); - std::scoped_lock lk{m_applet->lock}; - - if (m_applet->lifecycle_manager.GetExitRequested()) { - // With exit already requested, ignore and terminate immediately. - m_applet->process->Terminate(); - } else { - // Otherwise, set exit lock state. - m_applet->exit_locked = true; - system.SetExitLocked(true); - } + system.SetExitLocked(true); R_SUCCEED(); } @@ -111,13 +103,10 @@ Result ISelfController::LockExit() { Result ISelfController::UnlockExit() { LOG_DEBUG(Service_AM, "called"); - std::scoped_lock lk{m_applet->lock}; - - m_applet->exit_locked = false; system.SetExitLocked(false); - if (m_applet->lifecycle_manager.GetExitRequested()) { - m_applet->process->Terminate(); + if (system.GetExitRequested()) { + system.Exit(); } R_SUCCEED(); @@ -166,7 +155,7 @@ Result ISelfController::SetOperationModeChangedNotification(bool enabled) { LOG_INFO(Service_AM, "called, enabled={}", enabled); std::scoped_lock lk{m_applet->lock}; - m_applet->lifecycle_manager.SetOperationModeChangedNotificationEnabled(enabled); + m_applet->operation_mode_changed_notification_enabled = enabled; R_SUCCEED(); } @@ -175,18 +164,17 @@ Result ISelfController::SetPerformanceModeChangedNotification(bool enabled) { LOG_INFO(Service_AM, "called, enabled={}", enabled); std::scoped_lock lk{m_applet->lock}; - m_applet->lifecycle_manager.SetPerformanceModeChangedNotificationEnabled(enabled); + m_applet->performance_mode_changed_notification_enabled = enabled; R_SUCCEED(); } Result ISelfController::SetFocusHandlingMode(bool notify, bool background, bool suspend) { - LOG_INFO(Service_AM, "called, notify={} background={} suspend={}", notify, background, suspend); + LOG_WARNING(Service_AM, "(STUBBED) called, notify={} background={} suspend={}", notify, + background, suspend); std::scoped_lock lk{m_applet->lock}; - m_applet->lifecycle_manager.SetFocusStateChangedNotificationEnabled(notify); - m_applet->lifecycle_manager.SetFocusHandlingMode(suspend); - m_applet->UpdateSuspensionStateLocked(true); + m_applet->focus_handling_mode = {notify, background, suspend}; R_SUCCEED(); } @@ -195,7 +183,7 @@ Result ISelfController::SetRestartMessageEnabled(bool enabled) { LOG_INFO(Service_AM, "called, enabled={}", enabled); std::scoped_lock lk{m_applet->lock}; - m_applet->lifecycle_manager.SetResumeNotificationEnabled(enabled); + m_applet->restart_message_enabled = enabled; R_SUCCEED(); } @@ -214,8 +202,7 @@ Result ISelfController::SetOutOfFocusSuspendingEnabled(bool enabled) { LOG_INFO(Service_AM, "called, enabled={}", enabled); std::scoped_lock lk{m_applet->lock}; - m_applet->lifecycle_manager.SetOutOfFocusSuspendingEnabled(enabled); - m_applet->UpdateSuspensionStateLocked(false); + m_applet->out_of_focus_suspension_enabled = enabled; R_SUCCEED(); } diff --git a/src/core/hle/service/am/service/system_applet_proxy.cpp b/src/core/hle/service/am/service/system_applet_proxy.cpp index c435288a2..d1871ef9b 100755 --- a/src/core/hle/service/am/service/system_applet_proxy.cpp +++ b/src/core/hle/service/am/service/system_applet_proxy.cpp @@ -19,9 +19,9 @@ namespace Service::AM { ISystemAppletProxy::ISystemAppletProxy(Core::System& system_, std::shared_ptr applet, - Kernel::KProcess* process, WindowSystem& window_system) - : ServiceFramework{system_, "ISystemAppletProxy"}, - m_window_system{window_system}, m_process{process}, m_applet{std::move(applet)} { + Kernel::KProcess* process) + : ServiceFramework{system_, "ISystemAppletProxy"}, m_process{process}, m_applet{ + std::move(applet)} { // clang-format off static const FunctionInfo functions[] = { {0, D<&ISystemAppletProxy::GetCommonStateGetter>, "GetCommonStateGetter"}, @@ -75,7 +75,7 @@ Result ISystemAppletProxy::GetDebugFunctions( Result ISystemAppletProxy::GetWindowController( Out> out_window_controller) { LOG_DEBUG(Service_AM, "called"); - *out_window_controller = std::make_shared(system, m_applet, m_window_system); + *out_window_controller = std::make_shared(system, m_applet); R_SUCCEED(); } @@ -96,15 +96,14 @@ Result ISystemAppletProxy::GetCommonStateGetter( Result ISystemAppletProxy::GetLibraryAppletCreator( Out> out_library_applet_creator) { LOG_DEBUG(Service_AM, "called"); - *out_library_applet_creator = - std::make_shared(system, m_applet, m_window_system); + *out_library_applet_creator = std::make_shared(system, m_applet); R_SUCCEED(); } Result ISystemAppletProxy::GetApplicationCreator( Out> out_application_creator) { LOG_DEBUG(Service_AM, "called"); - *out_application_creator = std::make_shared(system, m_window_system); + *out_application_creator = std::make_shared(system); R_SUCCEED(); } @@ -118,8 +117,7 @@ Result ISystemAppletProxy::GetAppletCommonFunctions( Result ISystemAppletProxy::GetHomeMenuFunctions( Out> out_home_menu_functions) { LOG_DEBUG(Service_AM, "called"); - *out_home_menu_functions = - std::make_shared(system, m_applet, m_window_system); + *out_home_menu_functions = std::make_shared(system, m_applet); R_SUCCEED(); } diff --git a/src/core/hle/service/am/service/system_applet_proxy.h b/src/core/hle/service/am/service/system_applet_proxy.h index 217d9dc8c..67cd50e03 100755 --- a/src/core/hle/service/am/service/system_applet_proxy.h +++ b/src/core/hle/service/am/service/system_applet_proxy.h @@ -21,12 +21,11 @@ class ILibraryAppletCreator; class IProcessWindingController; class ISelfController; class IWindowController; -class WindowSystem; class ISystemAppletProxy final : public ServiceFramework { public: explicit ISystemAppletProxy(Core::System& system, std::shared_ptr applet, - Kernel::KProcess* process, WindowSystem& window_system); + Kernel::KProcess* process); ~ISystemAppletProxy(); private: @@ -47,7 +46,6 @@ private: Result GetGlobalStateController( Out> out_global_state_controller); - WindowSystem& m_window_system; Kernel::KProcess* const m_process; const std::shared_ptr m_applet; }; diff --git a/src/core/hle/service/am/service/window_controller.cpp b/src/core/hle/service/am/service/window_controller.cpp index 54396affb..99a4f50a2 100755 --- a/src/core/hle/service/am/service/window_controller.cpp +++ b/src/core/hle/service/am/service/window_controller.cpp @@ -4,15 +4,12 @@ #include "core/hle/service/am/applet.h" #include "core/hle/service/am/applet_manager.h" #include "core/hle/service/am/service/window_controller.h" -#include "core/hle/service/am/window_system.h" #include "core/hle/service/cmif_serialization.h" namespace Service::AM { -IWindowController::IWindowController(Core::System& system_, std::shared_ptr applet, - WindowSystem& window_system) - : ServiceFramework{system_, "IWindowController"}, - m_window_system{window_system}, m_applet{std::move(applet)} { +IWindowController::IWindowController(Core::System& system_, std::shared_ptr applet) + : ServiceFramework{system_, "IWindowController"}, m_applet{std::move(applet)} { // clang-format off static const FunctionInfo functions[] = { {0, nullptr, "CreateWindow"}, @@ -66,9 +63,17 @@ Result IWindowController::RejectToChangeIntoBackground() { } Result IWindowController::SetAppletWindowVisibility(bool visible) { - LOG_INFO(Service_AM, "called"); + m_applet->display_layer_manager.SetWindowVisibility(visible); + m_applet->hid_registration.EnableAppletToGetInput(visible); - m_window_system.RequestAppletVisibilityState(*m_applet, visible); + if (visible) { + m_applet->message_queue.PushMessage(AppletMessage::ChangeIntoForeground); + m_applet->focus_state = FocusState::InFocus; + } else { + m_applet->focus_state = FocusState::NotInFocus; + } + + m_applet->message_queue.PushMessage(AppletMessage::FocusStateChanged); R_SUCCEED(); } diff --git a/src/core/hle/service/am/service/window_controller.h b/src/core/hle/service/am/service/window_controller.h index a784dd4a4..bfbad9bcc 100755 --- a/src/core/hle/service/am/service/window_controller.h +++ b/src/core/hle/service/am/service/window_controller.h @@ -9,12 +9,10 @@ namespace Service::AM { struct Applet; -class WindowSystem; class IWindowController final : public ServiceFramework { public: - explicit IWindowController(Core::System& system_, std::shared_ptr applet, - WindowSystem& window_system); + explicit IWindowController(Core::System& system_, std::shared_ptr applet); ~IWindowController() override; private: @@ -26,7 +24,6 @@ private: Result SetAppletWindowVisibility(bool visible); Result SetAppletGpuTimeSlice(s64 time_slice); - WindowSystem& m_window_system; const std::shared_ptr m_applet; }; diff --git a/src/core/hle/service/hid/active_vibration_device_list.cpp b/src/core/hle/service/hid/active_vibration_device_list.cpp new file mode 100755 index 000000000..c440f8382 --- /dev/null +++ b/src/core/hle/service/hid/active_vibration_device_list.cpp @@ -0,0 +1,53 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "common/logging/log.h" +#include "core/hle/service/cmif_serialization.h" +#include "core/hle/service/hid/active_vibration_device_list.h" +#include "hid_core/hid_result.h" +#include "hid_core/hid_util.h" +#include "hid_core/resource_manager.h" +#include "hid_core/resources/vibration/vibration_device.h" + +namespace Service::HID { + +IActiveVibrationDeviceList::IActiveVibrationDeviceList(Core::System& system_, + std::shared_ptr resource) + : ServiceFramework{system_, "IActiveVibrationDeviceList"}, resource_manager(resource) { + // clang-format off + static const FunctionInfo functions[] = { + {0, C<&IActiveVibrationDeviceList::ActivateVibrationDevice>, "ActivateVibrationDevice"}, + }; + // clang-format on + + RegisterHandlers(functions); +} + +IActiveVibrationDeviceList::~IActiveVibrationDeviceList() = default; + +Result IActiveVibrationDeviceList::ActivateVibrationDevice( + Core::HID::VibrationDeviceHandle vibration_device_handle) { + LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}", + vibration_device_handle.npad_type, vibration_device_handle.npad_id, + vibration_device_handle.device_index); + + std::scoped_lock lock{mutex}; + + R_TRY(IsVibrationHandleValid(vibration_device_handle)); + + for (std::size_t i = 0; i < list_size; i++) { + if (vibration_device_handle.device_index == vibration_device_list[i].device_index && + vibration_device_handle.npad_id == vibration_device_list[i].npad_id && + vibration_device_handle.npad_type == vibration_device_list[i].npad_type) { + R_SUCCEED(); + } + } + + R_UNLESS(list_size < MaxVibrationDevicesHandles, ResultVibrationDeviceIndexOutOfRange); + R_TRY(resource_manager->GetVibrationDevice(vibration_device_handle)->Activate()); + + vibration_device_list[list_size++] = vibration_device_handle; + R_SUCCEED(); +} + +} // namespace Service::HID diff --git a/src/core/hle/service/hid/active_vibration_device_list.h b/src/core/hle/service/hid/active_vibration_device_list.h new file mode 100755 index 000000000..beaa44d97 --- /dev/null +++ b/src/core/hle/service/hid/active_vibration_device_list.h @@ -0,0 +1,39 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include +#include +#include + +#include "core/hle/service/cmif_types.h" +#include "core/hle/service/service.h" +#include "hid_core/hid_types.h" + +namespace Core { +class System; +} + +namespace Service::HID { +class ResourceManager; + +class IActiveVibrationDeviceList final : public ServiceFramework { +public: + explicit IActiveVibrationDeviceList(Core::System& system_, + std::shared_ptr resource); + ~IActiveVibrationDeviceList() override; + +private: + static constexpr std::size_t MaxVibrationDevicesHandles{0x100}; + + Result ActivateVibrationDevice(Core::HID::VibrationDeviceHandle vibration_device_handle); + + mutable std::mutex mutex; + std::size_t list_size{}; + std::array + vibration_device_list{}; + std::shared_ptr resource_manager; +}; + +} // namespace Service::HID diff --git a/src/core/hle/service/hid/applet_resource.cpp b/src/core/hle/service/hid/applet_resource.cpp new file mode 100755 index 000000000..4814d7ad5 --- /dev/null +++ b/src/core/hle/service/hid/applet_resource.cpp @@ -0,0 +1,34 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "common/logging/log.h" +#include "core/hle/kernel/k_shared_memory.h" +#include "core/hle/service/cmif_serialization.h" +#include "core/hle/service/hid/applet_resource.h" +#include "hid_core/resource_manager.h" + +namespace Service::HID { + +IAppletResource::IAppletResource(Core::System& system_, std::shared_ptr resource, + u64 applet_resource_user_id) + : ServiceFramework{system_, "IAppletResource"}, aruid{applet_resource_user_id}, + resource_manager{resource} { + static const FunctionInfo functions[] = { + {0, C<&IAppletResource::GetSharedMemoryHandle>, "GetSharedMemoryHandle"}, + }; + RegisterHandlers(functions); +} + +IAppletResource::~IAppletResource() { + resource_manager->FreeAppletResourceId(aruid); +} + +Result IAppletResource::GetSharedMemoryHandle( + OutCopyHandle out_shared_memory_handle) { + const auto result = resource_manager->GetSharedMemoryHandle(out_shared_memory_handle, aruid); + + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, result=0x{:X}", aruid, result.raw); + R_RETURN(result); +} + +} // namespace Service::HID diff --git a/src/core/hle/service/hid/applet_resource.h b/src/core/hle/service/hid/applet_resource.h new file mode 100755 index 000000000..d1e7db9b1 --- /dev/null +++ b/src/core/hle/service/hid/applet_resource.h @@ -0,0 +1,36 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include + +#include "common/common_types.h" +#include "core/hle/service/cmif_types.h" +#include "core/hle/service/service.h" + +namespace Core { +class System; +} + +namespace Kernel { +class KSharedMemory; +} + +namespace Service::HID { +class ResourceManager; + +class IAppletResource final : public ServiceFramework { +public: + explicit IAppletResource(Core::System& system_, std::shared_ptr resource, + u64 applet_resource_user_id); + ~IAppletResource() override; + +private: + Result GetSharedMemoryHandle(OutCopyHandle out_shared_memory_handle); + + u64 aruid{}; + std::shared_ptr resource_manager; +}; + +} // namespace Service::HID diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index e6a5a0250..4a2e2c56c 100755 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -23,7 +23,11 @@ void LoopProcess(Core::System& system) { std::shared_ptr resource_manager = std::make_shared(system, firmware_settings); + // TODO: Remove this hack when am is emulated properly. resource_manager->Initialize(); + resource_manager->RegisterAppletResourceUserId(system.ApplicationProcess()->GetProcessId(), + true); + resource_manager->SetAruidValidForVibration(system.ApplicationProcess()->GetProcessId(), true); server_manager->RegisterNamedService( "hid", std::make_shared(system, resource_manager, firmware_settings)); diff --git a/src/core/hle/service/hid/hid_server.cpp b/src/core/hle/service/hid/hid_server.cpp index 3603d8ccf..926a3bfe9 100755 --- a/src/core/hle/service/hid/hid_server.cpp +++ b/src/core/hle/service/hid/hid_server.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include + #include "common/common_types.h" #include "common/logging/log.h" #include "common/settings.h" @@ -9,6 +10,8 @@ #include "core/hle/kernel/k_transfer_memory.h" #include "core/hle/kernel/kernel.h" #include "core/hle/service/cmif_serialization.h" +#include "core/hle/service/hid/active_vibration_device_list.h" +#include "core/hle/service/hid/applet_resource.h" #include "core/hle/service/hid/hid_server.h" #include "core/hle/service/ipc_helpers.h" #include "core/memory.h" @@ -36,168 +39,107 @@ namespace Service::HID { -class IActiveVibrationDeviceList final : public ServiceFramework { -public: - explicit IActiveVibrationDeviceList(Core::System& system_, - std::shared_ptr resource) - : ServiceFramework{system_, "IActiveVibrationDeviceList"}, resource_manager(resource) { - // clang-format off - static const FunctionInfo functions[] = { - {0, &IActiveVibrationDeviceList::ActivateVibrationDevice, "ActivateVibrationDevice"}, - }; - // clang-format on - - RegisterHandlers(functions); - } - -private: - void ActivateVibrationDevice(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto vibration_device_handle{rp.PopRaw()}; - - LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}", - vibration_device_handle.npad_type, vibration_device_handle.npad_id, - vibration_device_handle.device_index); - - const auto result = ActivateVibrationDeviceImpl(vibration_device_handle); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); - } - - Result ActivateVibrationDeviceImpl(const Core::HID::VibrationDeviceHandle& handle) { - std::scoped_lock lock{mutex}; - - const Result is_valid = IsVibrationHandleValid(handle); - if (is_valid.IsError()) { - return is_valid; - } - - for (std::size_t i = 0; i < list_size; i++) { - if (handle.device_index == vibration_device_list[i].device_index && - handle.npad_id == vibration_device_list[i].npad_id && - handle.npad_type == vibration_device_list[i].npad_type) { - return ResultSuccess; - } - } - if (list_size == vibration_device_list.size()) { - return ResultVibrationDeviceIndexOutOfRange; - } - const Result result = resource_manager->GetVibrationDevice(handle)->Activate(); - if (result.IsError()) { - return result; - } - vibration_device_list[list_size++] = handle; - return ResultSuccess; - } - - mutable std::mutex mutex; - std::size_t list_size{}; - std::array vibration_device_list{}; - std::shared_ptr resource_manager; -}; - IHidServer::IHidServer(Core::System& system_, std::shared_ptr resource, std::shared_ptr settings) : ServiceFramework{system_, "hid"}, resource_manager{resource}, firmware_settings{settings} { // clang-format off static const FunctionInfo functions[] = { - {0, &IHidServer::CreateAppletResource, "CreateAppletResource"}, - {1, &IHidServer::ActivateDebugPad, "ActivateDebugPad"}, - {11, &IHidServer::ActivateTouchScreen, "ActivateTouchScreen"}, - {21, &IHidServer::ActivateMouse, "ActivateMouse"}, + {0, C<&IHidServer::CreateAppletResource>, "CreateAppletResource"}, + {1, C<&IHidServer::ActivateDebugPad>, "ActivateDebugPad"}, + {11, C<&IHidServer::ActivateTouchScreen>, "ActivateTouchScreen"}, + {21, C<&IHidServer::ActivateMouse>, "ActivateMouse"}, {26, nullptr, "ActivateDebugMouse"}, - {31, &IHidServer::ActivateKeyboard, "ActivateKeyboard"}, - {32, &IHidServer::SendKeyboardLockKeyEvent, "SendKeyboardLockKeyEvent"}, - {40, &IHidServer::AcquireXpadIdEventHandle, "AcquireXpadIdEventHandle"}, - {41, &IHidServer::ReleaseXpadIdEventHandle, "ReleaseXpadIdEventHandle"}, - {51, &IHidServer::ActivateXpad, "ActivateXpad"}, - {55, &IHidServer::GetXpadIds, "GetXpadIds"}, - {56, &IHidServer::ActivateJoyXpad, "ActivateJoyXpad"}, - {58, &IHidServer::GetJoyXpadLifoHandle, "GetJoyXpadLifoHandle"}, - {59, &IHidServer::GetJoyXpadIds, "GetJoyXpadIds"}, - {60, &IHidServer::ActivateSixAxisSensor, "ActivateSixAxisSensor"}, - {61, &IHidServer::DeactivateSixAxisSensor, "DeactivateSixAxisSensor"}, - {62, &IHidServer::GetSixAxisSensorLifoHandle, "GetSixAxisSensorLifoHandle"}, - {63, &IHidServer::ActivateJoySixAxisSensor, "ActivateJoySixAxisSensor"}, - {64, &IHidServer::DeactivateJoySixAxisSensor, "DeactivateJoySixAxisSensor"}, - {65, &IHidServer::GetJoySixAxisSensorLifoHandle, "GetJoySixAxisSensorLifoHandle"}, - {66, &IHidServer::StartSixAxisSensor, "StartSixAxisSensor"}, - {67, &IHidServer::StopSixAxisSensor, "StopSixAxisSensor"}, - {68, &IHidServer::IsSixAxisSensorFusionEnabled, "IsSixAxisSensorFusionEnabled"}, - {69, &IHidServer::EnableSixAxisSensorFusion, "EnableSixAxisSensorFusion"}, - {70, &IHidServer::SetSixAxisSensorFusionParameters, "SetSixAxisSensorFusionParameters"}, - {71, &IHidServer::GetSixAxisSensorFusionParameters, "GetSixAxisSensorFusionParameters"}, - {72, &IHidServer::ResetSixAxisSensorFusionParameters, "ResetSixAxisSensorFusionParameters"}, + {31, C<&IHidServer::ActivateKeyboard>, "ActivateKeyboard"}, + {32, C<&IHidServer::SendKeyboardLockKeyEvent>, "SendKeyboardLockKeyEvent"}, + {40, C<&IHidServer::AcquireXpadIdEventHandle>, "AcquireXpadIdEventHandle"}, + {41, C<&IHidServer::ReleaseXpadIdEventHandle>, "ReleaseXpadIdEventHandle"}, + {51, C<&IHidServer::ActivateXpad>, "ActivateXpad"}, + {55, C<&IHidServer::GetXpadIds>, "GetXpadIds"}, + {56, C<&IHidServer::ActivateJoyXpad>, "ActivateJoyXpad"}, + {58, C<&IHidServer::GetJoyXpadLifoHandle>, "GetJoyXpadLifoHandle"}, + {59, C<&IHidServer::GetJoyXpadIds>, "GetJoyXpadIds"}, + {60, C<&IHidServer::ActivateSixAxisSensor>, "ActivateSixAxisSensor"}, + {61, C<&IHidServer::DeactivateSixAxisSensor>, "DeactivateSixAxisSensor"}, + {62, C<&IHidServer::GetSixAxisSensorLifoHandle>, "GetSixAxisSensorLifoHandle"}, + {63, C<&IHidServer::ActivateJoySixAxisSensor>, "ActivateJoySixAxisSensor"}, + {64, C<&IHidServer::DeactivateJoySixAxisSensor>, "DeactivateJoySixAxisSensor"}, + {65, C<&IHidServer::GetJoySixAxisSensorLifoHandle>, "GetJoySixAxisSensorLifoHandle"}, + {66, C<&IHidServer::StartSixAxisSensor>, "StartSixAxisSensor"}, + {67, C<&IHidServer::StopSixAxisSensor>, "StopSixAxisSensor"}, + {68, C<&IHidServer::IsSixAxisSensorFusionEnabled>, "IsSixAxisSensorFusionEnabled"}, + {69, C<&IHidServer::EnableSixAxisSensorFusion>, "EnableSixAxisSensorFusion"}, + {70, C<&IHidServer::SetSixAxisSensorFusionParameters>, "SetSixAxisSensorFusionParameters"}, + {71, C<&IHidServer::GetSixAxisSensorFusionParameters>, "GetSixAxisSensorFusionParameters"}, + {72, C<&IHidServer::ResetSixAxisSensorFusionParameters>, "ResetSixAxisSensorFusionParameters"}, {73, nullptr, "SetAccelerometerParameters"}, {74, nullptr, "GetAccelerometerParameters"}, {75, nullptr, "ResetAccelerometerParameters"}, {76, nullptr, "SetAccelerometerPlayMode"}, {77, nullptr, "GetAccelerometerPlayMode"}, {78, nullptr, "ResetAccelerometerPlayMode"}, - {79, &IHidServer::SetGyroscopeZeroDriftMode, "SetGyroscopeZeroDriftMode"}, - {80, &IHidServer::GetGyroscopeZeroDriftMode, "GetGyroscopeZeroDriftMode"}, - {81, &IHidServer::ResetGyroscopeZeroDriftMode, "ResetGyroscopeZeroDriftMode"}, - {82, &IHidServer::IsSixAxisSensorAtRest, "IsSixAxisSensorAtRest"}, - {83, &IHidServer::IsFirmwareUpdateAvailableForSixAxisSensor, "IsFirmwareUpdateAvailableForSixAxisSensor"}, - {84, &IHidServer::EnableSixAxisSensorUnalteredPassthrough, "EnableSixAxisSensorUnalteredPassthrough"}, - {85, &IHidServer::IsSixAxisSensorUnalteredPassthroughEnabled, "IsSixAxisSensorUnalteredPassthroughEnabled"}, + {79, C<&IHidServer::SetGyroscopeZeroDriftMode>, "SetGyroscopeZeroDriftMode"}, + {80, C<&IHidServer::GetGyroscopeZeroDriftMode>, "GetGyroscopeZeroDriftMode"}, + {81, C<&IHidServer::ResetGyroscopeZeroDriftMode>, "ResetGyroscopeZeroDriftMode"}, + {82, C<&IHidServer::IsSixAxisSensorAtRest>, "IsSixAxisSensorAtRest"}, + {83, C<&IHidServer::IsFirmwareUpdateAvailableForSixAxisSensor>, "IsFirmwareUpdateAvailableForSixAxisSensor"}, + {84, C<&IHidServer::EnableSixAxisSensorUnalteredPassthrough>, "EnableSixAxisSensorUnalteredPassthrough"}, + {85, C<&IHidServer::IsSixAxisSensorUnalteredPassthroughEnabled>, "IsSixAxisSensorUnalteredPassthroughEnabled"}, {86, nullptr, "StoreSixAxisSensorCalibrationParameter"}, - {87, &IHidServer::LoadSixAxisSensorCalibrationParameter, "LoadSixAxisSensorCalibrationParameter"}, - {88, &IHidServer::GetSixAxisSensorIcInformation, "GetSixAxisSensorIcInformation"}, - {89, &IHidServer::ResetIsSixAxisSensorDeviceNewlyAssigned, "ResetIsSixAxisSensorDeviceNewlyAssigned"}, - {91, &IHidServer::ActivateGesture, "ActivateGesture"}, - {100, &IHidServer::SetSupportedNpadStyleSet, "SetSupportedNpadStyleSet"}, - {101, &IHidServer::GetSupportedNpadStyleSet, "GetSupportedNpadStyleSet"}, - {102, &IHidServer::SetSupportedNpadIdType, "SetSupportedNpadIdType"}, - {103, &IHidServer::ActivateNpad, "ActivateNpad"}, - {104, &IHidServer::DeactivateNpad, "DeactivateNpad"}, - {106, &IHidServer::AcquireNpadStyleSetUpdateEventHandle, "AcquireNpadStyleSetUpdateEventHandle"}, - {107, &IHidServer::DisconnectNpad, "DisconnectNpad"}, + {87, C<&IHidServer::LoadSixAxisSensorCalibrationParameter>, "LoadSixAxisSensorCalibrationParameter"}, + {88, C<&IHidServer::GetSixAxisSensorIcInformation>, "GetSixAxisSensorIcInformation"}, + {89, C<&IHidServer::ResetIsSixAxisSensorDeviceNewlyAssigned>, "ResetIsSixAxisSensorDeviceNewlyAssigned"}, + {91, C<&IHidServer::ActivateGesture>, "ActivateGesture"}, + {100, C<&IHidServer::SetSupportedNpadStyleSet>, "SetSupportedNpadStyleSet"}, + {101, C<&IHidServer::GetSupportedNpadStyleSet>, "GetSupportedNpadStyleSet"}, + {102, C<&IHidServer::SetSupportedNpadIdType>, "SetSupportedNpadIdType"}, + {103, C<&IHidServer::ActivateNpad>, "ActivateNpad"}, + {104, C<&IHidServer::DeactivateNpad>, "DeactivateNpad"}, + {106, C<&IHidServer::AcquireNpadStyleSetUpdateEventHandle>, "AcquireNpadStyleSetUpdateEventHandle"}, + {107, C<&IHidServer::DisconnectNpad>, "DisconnectNpad"}, {108, C<&IHidServer::GetPlayerLedPattern>, "GetPlayerLedPattern"}, - {109, &IHidServer::ActivateNpadWithRevision, "ActivateNpadWithRevision"}, - {120, &IHidServer::SetNpadJoyHoldType, "SetNpadJoyHoldType"}, - {121, &IHidServer::GetNpadJoyHoldType, "GetNpadJoyHoldType"}, - {122, &IHidServer::SetNpadJoyAssignmentModeSingleByDefault, "SetNpadJoyAssignmentModeSingleByDefault"}, - {123, &IHidServer::SetNpadJoyAssignmentModeSingle, "SetNpadJoyAssignmentModeSingle"}, - {124, &IHidServer::SetNpadJoyAssignmentModeDual, "SetNpadJoyAssignmentModeDual"}, - {125, &IHidServer::MergeSingleJoyAsDualJoy, "MergeSingleJoyAsDualJoy"}, - {126, &IHidServer::StartLrAssignmentMode, "StartLrAssignmentMode"}, - {127, &IHidServer::StopLrAssignmentMode, "StopLrAssignmentMode"}, - {128, &IHidServer::SetNpadHandheldActivationMode, "SetNpadHandheldActivationMode"}, - {129, &IHidServer::GetNpadHandheldActivationMode, "GetNpadHandheldActivationMode"}, - {130, &IHidServer::SwapNpadAssignment, "SwapNpadAssignment"}, - {131, &IHidServer::IsUnintendedHomeButtonInputProtectionEnabled, "IsUnintendedHomeButtonInputProtectionEnabled"}, - {132, &IHidServer::EnableUnintendedHomeButtonInputProtection, "EnableUnintendedHomeButtonInputProtection"}, - {133, &IHidServer::SetNpadJoyAssignmentModeSingleWithDestination, "SetNpadJoyAssignmentModeSingleWithDestination"}, - {134, &IHidServer::SetNpadAnalogStickUseCenterClamp, "SetNpadAnalogStickUseCenterClamp"}, - {135, &IHidServer::SetNpadCaptureButtonAssignment, "SetNpadCaptureButtonAssignment"}, - {136, &IHidServer::ClearNpadCaptureButtonAssignment, "ClearNpadCaptureButtonAssignment"}, - {200, &IHidServer::GetVibrationDeviceInfo, "GetVibrationDeviceInfo"}, - {201, &IHidServer::SendVibrationValue, "SendVibrationValue"}, - {202, &IHidServer::GetActualVibrationValue, "GetActualVibrationValue"}, - {203, &IHidServer::CreateActiveVibrationDeviceList, "CreateActiveVibrationDeviceList"}, - {204, &IHidServer::PermitVibration, "PermitVibration"}, - {205, &IHidServer::IsVibrationPermitted, "IsVibrationPermitted"}, - {206, &IHidServer::SendVibrationValues, "SendVibrationValues"}, - {207, &IHidServer::SendVibrationGcErmCommand, "SendVibrationGcErmCommand"}, - {208, &IHidServer::GetActualVibrationGcErmCommand, "GetActualVibrationGcErmCommand"}, - {209, &IHidServer::BeginPermitVibrationSession, "BeginPermitVibrationSession"}, - {210, &IHidServer::EndPermitVibrationSession, "EndPermitVibrationSession"}, - {211, &IHidServer::IsVibrationDeviceMounted, "IsVibrationDeviceMounted"}, - {212, &IHidServer::SendVibrationValueInBool, "SendVibrationValueInBool"}, - {300, &IHidServer::ActivateConsoleSixAxisSensor, "ActivateConsoleSixAxisSensor"}, - {301, &IHidServer::StartConsoleSixAxisSensor, "StartConsoleSixAxisSensor"}, - {302, &IHidServer::StopConsoleSixAxisSensor, "StopConsoleSixAxisSensor"}, - {303, &IHidServer::ActivateSevenSixAxisSensor, "ActivateSevenSixAxisSensor"}, - {304, &IHidServer::StartSevenSixAxisSensor, "StartSevenSixAxisSensor"}, - {305, &IHidServer::StopSevenSixAxisSensor, "StopSevenSixAxisSensor"}, - {306, &IHidServer::InitializeSevenSixAxisSensor, "InitializeSevenSixAxisSensor"}, - {307, &IHidServer::FinalizeSevenSixAxisSensor, "FinalizeSevenSixAxisSensor"}, + {109, C<&IHidServer::ActivateNpadWithRevision>, "ActivateNpadWithRevision"}, + {120, C<&IHidServer::SetNpadJoyHoldType>, "SetNpadJoyHoldType"}, + {121, C<&IHidServer::GetNpadJoyHoldType>, "GetNpadJoyHoldType"}, + {122, C<&IHidServer::SetNpadJoyAssignmentModeSingleByDefault>, "SetNpadJoyAssignmentModeSingleByDefault"}, + {123, C<&IHidServer::SetNpadJoyAssignmentModeSingle>, "SetNpadJoyAssignmentModeSingle"}, + {124, C<&IHidServer::SetNpadJoyAssignmentModeDual>, "SetNpadJoyAssignmentModeDual"}, + {125, C<&IHidServer::MergeSingleJoyAsDualJoy>, "MergeSingleJoyAsDualJoy"}, + {126, C<&IHidServer::StartLrAssignmentMode>, "StartLrAssignmentMode"}, + {127, C<&IHidServer::StopLrAssignmentMode>, "StopLrAssignmentMode"}, + {128, C<&IHidServer::SetNpadHandheldActivationMode>, "SetNpadHandheldActivationMode"}, + {129, C<&IHidServer::GetNpadHandheldActivationMode>, "GetNpadHandheldActivationMode"}, + {130, C<&IHidServer::SwapNpadAssignment>, "SwapNpadAssignment"}, + {131, C<&IHidServer::IsUnintendedHomeButtonInputProtectionEnabled>, "IsUnintendedHomeButtonInputProtectionEnabled"}, + {132, C<&IHidServer::EnableUnintendedHomeButtonInputProtection>, "EnableUnintendedHomeButtonInputProtection"}, + {133, C<&IHidServer::SetNpadJoyAssignmentModeSingleWithDestination>, "SetNpadJoyAssignmentModeSingleWithDestination"}, + {134, C<&IHidServer::SetNpadAnalogStickUseCenterClamp>, "SetNpadAnalogStickUseCenterClamp"}, + {135, C<&IHidServer::SetNpadCaptureButtonAssignment>, "SetNpadCaptureButtonAssignment"}, + {136, C<&IHidServer::ClearNpadCaptureButtonAssignment>, "ClearNpadCaptureButtonAssignment"}, + {200, C<&IHidServer::GetVibrationDeviceInfo>, "GetVibrationDeviceInfo"}, + {201, C<&IHidServer::SendVibrationValue>, "SendVibrationValue"}, + {202, C<&IHidServer::GetActualVibrationValue>, "GetActualVibrationValue"}, + {203, C<&IHidServer::CreateActiveVibrationDeviceList>, "CreateActiveVibrationDeviceList"}, + {204, C<&IHidServer::PermitVibration>, "PermitVibration"}, + {205, C<&IHidServer::IsVibrationPermitted>, "IsVibrationPermitted"}, + {206, C<&IHidServer::SendVibrationValues>, "SendVibrationValues"}, + {207, C<&IHidServer::SendVibrationGcErmCommand>, "SendVibrationGcErmCommand"}, + {208, C<&IHidServer::GetActualVibrationGcErmCommand>, "GetActualVibrationGcErmCommand"}, + {209, C<&IHidServer::BeginPermitVibrationSession>, "BeginPermitVibrationSession"}, + {210, C<&IHidServer::EndPermitVibrationSession>, "EndPermitVibrationSession"}, + {211, C<&IHidServer::IsVibrationDeviceMounted>, "IsVibrationDeviceMounted"}, + {212, C<&IHidServer::SendVibrationValueInBool>, "SendVibrationValueInBool"}, + {300, C<&IHidServer::ActivateConsoleSixAxisSensor>, "ActivateConsoleSixAxisSensor"}, + {301, C<&IHidServer::StartConsoleSixAxisSensor>, "StartConsoleSixAxisSensor"}, + {302, C<&IHidServer::StopConsoleSixAxisSensor>, "StopConsoleSixAxisSensor"}, + {303, C<&IHidServer::ActivateSevenSixAxisSensor>, "ActivateSevenSixAxisSensor"}, + {304, C<&IHidServer::StartSevenSixAxisSensor>, "StartSevenSixAxisSensor"}, + {305, C<&IHidServer::StopSevenSixAxisSensor>, "StopSevenSixAxisSensor"}, + {306, C<&IHidServer::InitializeSevenSixAxisSensor>, "InitializeSevenSixAxisSensor"}, + {307, C<&IHidServer::FinalizeSevenSixAxisSensor>, "FinalizeSevenSixAxisSensor"}, {308, nullptr, "SetSevenSixAxisSensorFusionStrength"}, {309, nullptr, "GetSevenSixAxisSensorFusionStrength"}, - {310, &IHidServer::ResetSevenSixAxisSensorTimestamp, "ResetSevenSixAxisSensorTimestamp"}, - {400, &IHidServer::IsUsbFullKeyControllerEnabled, "IsUsbFullKeyControllerEnabled"}, + {310, C<&IHidServer::ResetSevenSixAxisSensorTimestamp>, "ResetSevenSixAxisSensorTimestamp"}, + {400, C<&IHidServer::IsUsbFullKeyControllerEnabled>, "IsUsbFullKeyControllerEnabled"}, {401, nullptr, "EnableUsbFullKeyController"}, {402, nullptr, "IsUsbFullKeyControllerConnected"}, {403, nullptr, "HasBattery"}, @@ -206,41 +148,41 @@ IHidServer::IHidServer(Core::System& system_, std::shared_ptr r {406, nullptr, "GetNpadLeftRightInterfaceType"}, {407, nullptr, "GetNpadOfHighestBatteryLevel"}, {408, nullptr, "GetNpadOfHighestBatteryLevelForJoyRight"}, - {500, &IHidServer::GetPalmaConnectionHandle, "GetPalmaConnectionHandle"}, - {501, &IHidServer::InitializePalma, "InitializePalma"}, - {502, &IHidServer::AcquirePalmaOperationCompleteEvent, "AcquirePalmaOperationCompleteEvent"}, - {503, &IHidServer::GetPalmaOperationInfo, "GetPalmaOperationInfo"}, - {504, &IHidServer::PlayPalmaActivity, "PlayPalmaActivity"}, - {505, &IHidServer::SetPalmaFrModeType, "SetPalmaFrModeType"}, - {506, &IHidServer::ReadPalmaStep, "ReadPalmaStep"}, - {507, &IHidServer::EnablePalmaStep, "EnablePalmaStep"}, - {508, &IHidServer::ResetPalmaStep, "ResetPalmaStep"}, - {509, &IHidServer::ReadPalmaApplicationSection, "ReadPalmaApplicationSection"}, - {510, &IHidServer::WritePalmaApplicationSection, "WritePalmaApplicationSection"}, - {511, &IHidServer::ReadPalmaUniqueCode, "ReadPalmaUniqueCode"}, - {512, &IHidServer::SetPalmaUniqueCodeInvalid, "SetPalmaUniqueCodeInvalid"}, - {513, &IHidServer::WritePalmaActivityEntry, "WritePalmaActivityEntry"}, - {514, &IHidServer::WritePalmaRgbLedPatternEntry, "WritePalmaRgbLedPatternEntry"}, - {515, &IHidServer::WritePalmaWaveEntry, "WritePalmaWaveEntry"}, - {516, &IHidServer::SetPalmaDataBaseIdentificationVersion, "SetPalmaDataBaseIdentificationVersion"}, - {517, &IHidServer::GetPalmaDataBaseIdentificationVersion, "GetPalmaDataBaseIdentificationVersion"}, - {518, &IHidServer::SuspendPalmaFeature, "SuspendPalmaFeature"}, - {519, &IHidServer::GetPalmaOperationResult, "GetPalmaOperationResult"}, - {520, &IHidServer::ReadPalmaPlayLog, "ReadPalmaPlayLog"}, - {521, &IHidServer::ResetPalmaPlayLog, "ResetPalmaPlayLog"}, - {522, &IHidServer::SetIsPalmaAllConnectable, "SetIsPalmaAllConnectable"}, - {523, &IHidServer::SetIsPalmaPairedConnectable, "SetIsPalmaPairedConnectable"}, - {524, &IHidServer::PairPalma, "PairPalma"}, - {525, &IHidServer::SetPalmaBoostMode, "SetPalmaBoostMode"}, - {526, &IHidServer::CancelWritePalmaWaveEntry, "CancelWritePalmaWaveEntry"}, - {527, &IHidServer::EnablePalmaBoostMode, "EnablePalmaBoostMode"}, - {528, &IHidServer::GetPalmaBluetoothAddress, "GetPalmaBluetoothAddress"}, - {529, &IHidServer::SetDisallowedPalmaConnection, "SetDisallowedPalmaConnection"}, - {1000, &IHidServer::SetNpadCommunicationMode, "SetNpadCommunicationMode"}, - {1001, &IHidServer::GetNpadCommunicationMode, "GetNpadCommunicationMode"}, - {1002, &IHidServer::SetTouchScreenConfiguration, "SetTouchScreenConfiguration"}, - {1003, &IHidServer::IsFirmwareUpdateNeededForNotification, "IsFirmwareUpdateNeededForNotification"}, - {1004, &IHidServer::SetTouchScreenResolution, "SetTouchScreenResolution"}, + {500, C<&IHidServer::GetPalmaConnectionHandle>, "GetPalmaConnectionHandle"}, + {501, C<&IHidServer::InitializePalma>, "InitializePalma"}, + {502, C<&IHidServer::AcquirePalmaOperationCompleteEvent>, "AcquirePalmaOperationCompleteEvent"}, + {503, C<&IHidServer::GetPalmaOperationInfo>, "GetPalmaOperationInfo"}, + {504, C<&IHidServer::PlayPalmaActivity>, "PlayPalmaActivity"}, + {505, C<&IHidServer::SetPalmaFrModeType>, "SetPalmaFrModeType"}, + {506, C<&IHidServer::ReadPalmaStep>, "ReadPalmaStep"}, + {507, C<&IHidServer::EnablePalmaStep>, "EnablePalmaStep"}, + {508, C<&IHidServer::ResetPalmaStep>, "ResetPalmaStep"}, + {509, C<&IHidServer::ReadPalmaApplicationSection>, "ReadPalmaApplicationSection"}, + {510, C<&IHidServer::WritePalmaApplicationSection>, "WritePalmaApplicationSection"}, + {511, C<&IHidServer::ReadPalmaUniqueCode>, "ReadPalmaUniqueCode"}, + {512, C<&IHidServer::SetPalmaUniqueCodeInvalid>, "SetPalmaUniqueCodeInvalid"}, + {513, C<&IHidServer::WritePalmaActivityEntry>, "WritePalmaActivityEntry"}, + {514, C<&IHidServer::WritePalmaRgbLedPatternEntry>, "WritePalmaRgbLedPatternEntry"}, + {515, C<&IHidServer::WritePalmaWaveEntry>, "WritePalmaWaveEntry"}, + {516, C<&IHidServer::SetPalmaDataBaseIdentificationVersion>, "SetPalmaDataBaseIdentificationVersion"}, + {517, C<&IHidServer::GetPalmaDataBaseIdentificationVersion>, "GetPalmaDataBaseIdentificationVersion"}, + {518, C<&IHidServer::SuspendPalmaFeature>, "SuspendPalmaFeature"}, + {519, C<&IHidServer::GetPalmaOperationResult>, "GetPalmaOperationResult"}, + {520, C<&IHidServer::ReadPalmaPlayLog>, "ReadPalmaPlayLog"}, + {521, C<&IHidServer::ResetPalmaPlayLog>, "ResetPalmaPlayLog"}, + {522, C<&IHidServer::SetIsPalmaAllConnectable>, "SetIsPalmaAllConnectable"}, + {523, C<&IHidServer::SetIsPalmaPairedConnectable>, "SetIsPalmaPairedConnectable"}, + {524, C<&IHidServer::PairPalma>, "PairPalma"}, + {525, C<&IHidServer::SetPalmaBoostMode>, "SetPalmaBoostMode"}, + {526, C<&IHidServer::CancelWritePalmaWaveEntry>, "CancelWritePalmaWaveEntry"}, + {527, C<&IHidServer::EnablePalmaBoostMode>, "EnablePalmaBoostMode"}, + {528, C<&IHidServer::GetPalmaBluetoothAddress>, "GetPalmaBluetoothAddress"}, + {529, C<&IHidServer::SetDisallowedPalmaConnection>, "SetDisallowedPalmaConnection"}, + {1000, C<&IHidServer::SetNpadCommunicationMode>, "SetNpadCommunicationMode"}, + {1001, C<&IHidServer::GetNpadCommunicationMode>, "GetNpadCommunicationMode"}, + {1002, C<&IHidServer::SetTouchScreenConfiguration>, "SetTouchScreenConfiguration"}, + {1003, C<&IHidServer::IsFirmwareUpdateNeededForNotification>, "IsFirmwareUpdateNeededForNotification"}, + {1004, C<&IHidServer::SetTouchScreenResolution>, "SetTouchScreenResolution"}, {2000, nullptr, "ActivateDigitizer"}, }; // clang-format on @@ -250,890 +192,455 @@ IHidServer::IHidServer(Core::System& system_, std::shared_ptr r IHidServer::~IHidServer() = default; -void IHidServer::CreateAppletResource(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; +Result IHidServer::CreateAppletResource(OutInterface out_applet_resource, + ClientAppletResourceUserId aruid) { + const auto result = GetResourceManager()->CreateAppletResource(aruid.pid); - Result result = GetResourceManager()->CreateAppletResource(applet_resource_user_id); + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, result=0x{:X}", aruid.pid, + result.raw); - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, result=0x{:X}", - applet_resource_user_id, result.raw); - - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(result); - rb.PushIpcInterface(system, resource_manager, applet_resource_user_id); + *out_applet_resource = std::make_shared(system, resource_manager, aruid.pid); + R_SUCCEED(); } -void IHidServer::ActivateDebugPad(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); - - Result result = ResultSuccess; - auto debug_pad = GetResourceManager()->GetDebugPad(); +Result IHidServer::ActivateDebugPad(ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid); if (!firmware_settings->IsDeviceManaged()) { - result = debug_pad->Activate(); + R_TRY(GetResourceManager()->GetDebugPad()->Activate()); } - if (result.IsSuccess()) { - result = debug_pad->Activate(applet_resource_user_id); - } - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetDebugPad()->Activate(aruid.pid)); } -void IHidServer::ActivateTouchScreen(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); - - Result result = ResultSuccess; - auto touch_screen = GetResourceManager()->GetTouchScreen(); +Result IHidServer::ActivateTouchScreen(ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid); if (!firmware_settings->IsDeviceManaged()) { - result = touch_screen->Activate(); + R_TRY(GetResourceManager()->GetTouchScreen()->Activate()); } - if (result.IsSuccess()) { - result = touch_screen->Activate(applet_resource_user_id); - } - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetTouchScreen()->Activate(aruid.pid)); } -void IHidServer::ActivateMouse(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); - - Result result = ResultSuccess; - auto mouse = GetResourceManager()->GetMouse(); +Result IHidServer::ActivateMouse(ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid); if (!firmware_settings->IsDeviceManaged()) { - result = mouse->Activate(); + R_TRY(GetResourceManager()->GetMouse()->Activate()); } - if (result.IsSuccess()) { - result = mouse->Activate(applet_resource_user_id); - } - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetMouse()->Activate(aruid.pid)); } -void IHidServer::ActivateKeyboard(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); - - Result result = ResultSuccess; - auto keyboard = GetResourceManager()->GetKeyboard(); +Result IHidServer::ActivateKeyboard(ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid); if (!firmware_settings->IsDeviceManaged()) { - result = keyboard->Activate(); + R_TRY(GetResourceManager()->GetKeyboard()->Activate()); } - if (result.IsSuccess()) { - result = keyboard->Activate(applet_resource_user_id); - } - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetKeyboard()->Activate(aruid.pid)); } -void IHidServer::SendKeyboardLockKeyEvent(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto flags{rp.Pop()}; - +Result IHidServer::SendKeyboardLockKeyEvent(u32 flags) { LOG_WARNING(Service_HID, "(STUBBED) called. flags={}", flags); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IHidServer::AcquireXpadIdEventHandle(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); +Result IHidServer::AcquireXpadIdEventHandle(OutCopyHandle out_event, + ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid); // This function has been stubbed since 10.0.0+ - - IPC::ResponseBuilder rb{ctx, 2, 1}; - rb.Push(ResultSuccess); - // Handle returned is null here + *out_event = nullptr; + R_SUCCEED(); } -void IHidServer::ReleaseXpadIdEventHandle(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); +Result IHidServer::ReleaseXpadIdEventHandle(ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid); // This function has been stubbed since 10.0.0+ - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IHidServer::ActivateXpad(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - u32 basic_xpad_id; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - - LOG_DEBUG(Service_HID, "called, basic_xpad_id={}, applet_resource_user_id={}", - parameters.basic_xpad_id, parameters.applet_resource_user_id); +Result IHidServer::ActivateXpad(u32 basic_xpad_id, ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_HID, "called, basic_xpad_id={}, applet_resource_user_id={}", basic_xpad_id, + aruid.pid); // This function has been stubbed since 10.0.0+ - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IHidServer::GetXpadIds(HLERequestContext& ctx) { +Result IHidServer::GetXpadIds(Out out_count, + OutArray out_basic_pad_ids) { LOG_DEBUG(Service_HID, "called"); // This function has been hardcoded since 10.0.0+ - const std::array basic_xpad_id{0, 1, 2, 3}; - ctx.WriteBuffer(basic_xpad_id); - - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); - rb.Push(basic_xpad_id.size()); + out_basic_pad_ids[0] = 0; + out_basic_pad_ids[1] = 1; + out_basic_pad_ids[2] = 2; + out_basic_pad_ids[3] = 3; + *out_count = 4; + R_SUCCEED(); } -void IHidServer::ActivateJoyXpad(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto joy_xpad_id{rp.Pop()}; - +Result IHidServer::ActivateJoyXpad(u32 joy_xpad_id) { LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id); // This function has been stubbed since 10.0.0+ - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IHidServer::GetJoyXpadLifoHandle(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto joy_xpad_id{rp.Pop()}; - +Result IHidServer::GetJoyXpadLifoHandle( + OutCopyHandle out_shared_memory_handle, u32 joy_xpad_id) { LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id); // This function has been stubbed since 10.0.0+ - - IPC::ResponseBuilder rb{ctx, 2, 1}; - rb.Push(ResultSuccess); - // Handle returned is null here + *out_shared_memory_handle = nullptr; + R_SUCCEED(); } -void IHidServer::GetJoyXpadIds(HLERequestContext& ctx) { +Result IHidServer::GetJoyXpadIds(Out out_basic_xpad_id_count) { LOG_DEBUG(Service_HID, "called"); // This function has been hardcoded since 10.0.0+ - const s64 basic_xpad_id_count{}; - - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); - rb.Push(basic_xpad_id_count); + *out_basic_xpad_id_count = 0; + R_SUCCEED(); } -void IHidServer::ActivateSixAxisSensor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto joy_xpad_id{rp.Pop()}; - +Result IHidServer::ActivateSixAxisSensor(u32 joy_xpad_id) { LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id); // This function has been stubbed since 10.0.0+ - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IHidServer::DeactivateSixAxisSensor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto joy_xpad_id{rp.Pop()}; - +Result IHidServer::DeactivateSixAxisSensor(u32 joy_xpad_id) { LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id); // This function has been stubbed since 10.0.0+ - - IPC::ResponseBuilder rb{ctx, 2, 1}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IHidServer::GetSixAxisSensorLifoHandle(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto joy_xpad_id{rp.Pop()}; - +Result IHidServer::GetSixAxisSensorLifoHandle( + OutCopyHandle out_shared_memory_handle, u32 joy_xpad_id) { LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id); // This function has been stubbed since 10.0.0+ - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + *out_shared_memory_handle = nullptr; + R_SUCCEED(); } -void IHidServer::ActivateJoySixAxisSensor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto joy_xpad_id{rp.Pop()}; - +Result IHidServer::ActivateJoySixAxisSensor(u32 joy_xpad_id) { LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id); // This function has been stubbed since 10.0.0+ - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IHidServer::DeactivateJoySixAxisSensor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto joy_xpad_id{rp.Pop()}; - +Result IHidServer::DeactivateJoySixAxisSensor(u32 joy_xpad_id) { LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id); // This function has been stubbed since 10.0.0+ - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IHidServer::GetJoySixAxisSensorLifoHandle(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto joy_xpad_id{rp.Pop()}; - +Result IHidServer::GetJoySixAxisSensorLifoHandle( + OutCopyHandle out_shared_memory_handle, u32 joy_xpad_id) { LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id); // This function has been stubbed since 10.0.0+ - - IPC::ResponseBuilder rb{ctx, 2, 1}; - rb.Push(ResultSuccess); - // Handle returned is null here + *out_shared_memory_handle = nullptr; + R_SUCCEED(); } -void IHidServer::StartSixAxisSensor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::SixAxisSensorHandle sixaxis_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - - auto six_axis = GetResourceManager()->GetSixAxis(); - const auto result = six_axis->SetSixAxisEnabled(parameters.sixaxis_handle, true); - +Result IHidServer::StartSixAxisSensor(Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid) { LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", - parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, - parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); + sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index, + aruid.pid); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetSixAxis()->SetSixAxisEnabled(sixaxis_handle, true)); } -void IHidServer::StopSixAxisSensor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::SixAxisSensorHandle sixaxis_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - - auto six_axis = GetResourceManager()->GetSixAxis(); - const auto result = six_axis->SetSixAxisEnabled(parameters.sixaxis_handle, false); - +Result IHidServer::StopSixAxisSensor(Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid) { LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", - parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, - parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); + sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index, + aruid.pid); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetSixAxis()->SetSixAxisEnabled(sixaxis_handle, false)); } -void IHidServer::IsSixAxisSensorFusionEnabled(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::SixAxisSensorHandle sixaxis_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - - bool is_enabled{}; - auto six_axis = GetResourceManager()->GetSixAxis(); - const auto result = - six_axis->IsSixAxisSensorFusionEnabled(parameters.sixaxis_handle, is_enabled); - +Result IHidServer::IsSixAxisSensorFusionEnabled(Out out_is_enabled, + Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid) { LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", - parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, - parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); + sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index, + aruid.pid); - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(result); - rb.Push(is_enabled); + R_RETURN(GetResourceManager()->GetSixAxis()->IsSixAxisSensorFusionEnabled(sixaxis_handle, + *out_is_enabled)); } -void IHidServer::EnableSixAxisSensorFusion(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - bool enable_sixaxis_sensor_fusion; - INSERT_PADDING_BYTES_NOINIT(3); - Core::HID::SixAxisSensorHandle sixaxis_handle; - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - - auto six_axis = GetResourceManager()->GetSixAxis(); - const auto result = six_axis->SetSixAxisFusionEnabled(parameters.sixaxis_handle, - parameters.enable_sixaxis_sensor_fusion); - +Result IHidServer::EnableSixAxisSensorFusion(bool is_enabled, + Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid) { LOG_DEBUG(Service_HID, - "called, enable_sixaxis_sensor_fusion={}, npad_type={}, npad_id={}, " + "called, is_enabled={}, npad_type={}, npad_id={}, " "device_index={}, applet_resource_user_id={}", - parameters.enable_sixaxis_sensor_fusion, parameters.sixaxis_handle.npad_type, - parameters.sixaxis_handle.npad_id, parameters.sixaxis_handle.device_index, - parameters.applet_resource_user_id); + is_enabled, sixaxis_handle.npad_type, sixaxis_handle.npad_id, + sixaxis_handle.device_index, aruid.pid); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN( + GetResourceManager()->GetSixAxis()->SetSixAxisFusionEnabled(sixaxis_handle, is_enabled)); } -void IHidServer::SetSixAxisSensorFusionParameters(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::SixAxisSensorHandle sixaxis_handle; - Core::HID::SixAxisSensorFusionParameters sixaxis_fusion; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - - auto six_axis = GetResourceManager()->GetSixAxis(); - const auto result = - six_axis->SetSixAxisFusionParameters(parameters.sixaxis_handle, parameters.sixaxis_fusion); - +Result IHidServer::SetSixAxisSensorFusionParameters( + Core::HID::SixAxisSensorHandle sixaxis_handle, + Core::HID::SixAxisSensorFusionParameters sixaxis_fusion, ClientAppletResourceUserId aruid) { LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, parameter1={}, " "parameter2={}, applet_resource_user_id={}", - parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, - parameters.sixaxis_handle.device_index, parameters.sixaxis_fusion.parameter1, - parameters.sixaxis_fusion.parameter2, parameters.applet_resource_user_id); + sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index, + sixaxis_fusion.parameter1, sixaxis_fusion.parameter2, aruid.pid); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetSixAxis()->SetSixAxisFusionParameters(sixaxis_handle, + sixaxis_fusion)); } -void IHidServer::GetSixAxisSensorFusionParameters(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::SixAxisSensorHandle sixaxis_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - - Core::HID::SixAxisSensorFusionParameters fusion_parameters{}; - auto six_axis = GetResourceManager()->GetSixAxis(); - const auto result = - six_axis->GetSixAxisFusionParameters(parameters.sixaxis_handle, fusion_parameters); - +Result IHidServer::GetSixAxisSensorFusionParameters( + Out out_fusion_parameters, + Core::HID::SixAxisSensorHandle sixaxis_handle, ClientAppletResourceUserId aruid) { LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", - parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, - parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); + sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index, + aruid.pid); - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(result); - rb.PushRaw(fusion_parameters); + R_RETURN(GetResourceManager()->GetSixAxis()->GetSixAxisFusionParameters( + sixaxis_handle, *out_fusion_parameters)); } -void IHidServer::ResetSixAxisSensorFusionParameters(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::SixAxisSensorHandle sixaxis_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; +Result IHidServer::ResetSixAxisSensorFusionParameters(Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_HID, + "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", + sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index, + aruid.pid); // Since these parameters are unknown just use what HW outputs const Core::HID::SixAxisSensorFusionParameters fusion_parameters{ .parameter1 = 0.03f, .parameter2 = 0.4f, }; - auto six_axis = GetResourceManager()->GetSixAxis(); - const auto result1 = - six_axis->SetSixAxisFusionParameters(parameters.sixaxis_handle, fusion_parameters); - const auto result2 = six_axis->SetSixAxisFusionEnabled(parameters.sixaxis_handle, true); - LOG_DEBUG(Service_HID, - "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", - parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, - parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - if (result1.IsError()) { - rb.Push(result1); - return; - } - rb.Push(result2); + R_TRY(GetResourceManager()->GetSixAxis()->SetSixAxisFusionParameters(sixaxis_handle, + fusion_parameters)); + R_RETURN(GetResourceManager()->GetSixAxis()->SetSixAxisFusionEnabled(sixaxis_handle, true)); } -void IHidServer::SetGyroscopeZeroDriftMode(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto sixaxis_handle{rp.PopRaw()}; - const auto drift_mode{rp.PopEnum()}; - const auto applet_resource_user_id{rp.Pop()}; - - auto six_axis = GetResourceManager()->GetSixAxis(); - const auto result = six_axis->SetGyroscopeZeroDriftMode(sixaxis_handle, drift_mode); - +Result IHidServer::SetGyroscopeZeroDriftMode(Core::HID::SixAxisSensorHandle sixaxis_handle, + Core::HID::GyroscopeZeroDriftMode drift_mode, + ClientAppletResourceUserId aruid) { LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, drift_mode={}, " "applet_resource_user_id={}", sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index, - drift_mode, applet_resource_user_id); + drift_mode, aruid.pid); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN( + GetResourceManager()->GetSixAxis()->SetGyroscopeZeroDriftMode(sixaxis_handle, drift_mode)); } -void IHidServer::GetGyroscopeZeroDriftMode(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::SixAxisSensorHandle sixaxis_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - - auto drift_mode{Core::HID::GyroscopeZeroDriftMode::Standard}; - auto six_axis = GetResourceManager()->GetSixAxis(); - const auto result = six_axis->GetGyroscopeZeroDriftMode(parameters.sixaxis_handle, drift_mode); - +Result IHidServer::GetGyroscopeZeroDriftMode(Out out_drift_mode, + Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid) { LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", - parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, - parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); + sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index, + aruid.pid); - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(result); - rb.PushEnum(drift_mode); + R_RETURN(GetResourceManager()->GetSixAxis()->GetGyroscopeZeroDriftMode(sixaxis_handle, + *out_drift_mode)); } -void IHidServer::ResetGyroscopeZeroDriftMode(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::SixAxisSensorHandle sixaxis_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; +Result IHidServer::ResetGyroscopeZeroDriftMode(Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_HID, + "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", + sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index, + aruid.pid); const auto drift_mode{Core::HID::GyroscopeZeroDriftMode::Standard}; - auto six_axis = GetResourceManager()->GetSixAxis(); - const auto result = six_axis->SetGyroscopeZeroDriftMode(parameters.sixaxis_handle, drift_mode); - - LOG_DEBUG(Service_HID, - "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", - parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, - parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN( + GetResourceManager()->GetSixAxis()->SetGyroscopeZeroDriftMode(sixaxis_handle, drift_mode)); } -void IHidServer::IsSixAxisSensorAtRest(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::SixAxisSensorHandle sixaxis_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - - bool is_at_rest{}; - auto six_axis = GetResourceManager()->GetSixAxis(); - six_axis->IsSixAxisSensorAtRest(parameters.sixaxis_handle, is_at_rest); - +Result IHidServer::IsSixAxisSensorAtRest(Out out_is_at_rest, + Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid) { LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", - parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, - parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); + sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index, + aruid.pid); - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.Push(is_at_rest); + R_RETURN( + GetResourceManager()->GetSixAxis()->IsSixAxisSensorAtRest(sixaxis_handle, *out_is_at_rest)); } -void IHidServer::IsFirmwareUpdateAvailableForSixAxisSensor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::SixAxisSensorHandle sixaxis_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - - bool is_firmware_available{}; - auto controller = GetResourceManager()->GetNpad(); - controller->IsFirmwareUpdateAvailableForSixAxisSensor( - parameters.applet_resource_user_id, parameters.sixaxis_handle, is_firmware_available); - +Result IHidServer::IsFirmwareUpdateAvailableForSixAxisSensor( + Out out_is_firmware_available, Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid) { LOG_WARNING( Service_HID, "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", - parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, - parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); + sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index, aruid.pid); - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.Push(is_firmware_available); + R_RETURN(GetResourceManager()->GetNpad()->IsFirmwareUpdateAvailableForSixAxisSensor( + aruid.pid, sixaxis_handle, *out_is_firmware_available)); } -void IHidServer::EnableSixAxisSensorUnalteredPassthrough(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - bool enabled; - Core::HID::SixAxisSensorHandle sixaxis_handle; - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - - auto six_axis = GetResourceManager()->GetSixAxis(); - const auto result = six_axis->EnableSixAxisSensorUnalteredPassthrough(parameters.sixaxis_handle, - parameters.enabled); - +Result IHidServer::EnableSixAxisSensorUnalteredPassthrough( + bool is_enabled, Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid) { LOG_DEBUG(Service_HID, "(STUBBED) called, enabled={}, npad_type={}, npad_id={}, device_index={}, " "applet_resource_user_id={}", - parameters.enabled, parameters.sixaxis_handle.npad_type, - parameters.sixaxis_handle.npad_id, parameters.sixaxis_handle.device_index, - parameters.applet_resource_user_id); + is_enabled, sixaxis_handle.npad_type, sixaxis_handle.npad_id, + sixaxis_handle.device_index, aruid.pid); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetSixAxis()->EnableSixAxisSensorUnalteredPassthrough( + sixaxis_handle, is_enabled)); } -void IHidServer::IsSixAxisSensorUnalteredPassthroughEnabled(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::SixAxisSensorHandle sixaxis_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - - bool is_unaltered_sisxaxis_enabled{}; - auto six_axis = GetResourceManager()->GetSixAxis(); - const auto result = six_axis->IsSixAxisSensorUnalteredPassthroughEnabled( - parameters.sixaxis_handle, is_unaltered_sisxaxis_enabled); - +Result IHidServer::IsSixAxisSensorUnalteredPassthroughEnabled( + Out out_is_enabled, Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid) { LOG_DEBUG( Service_HID, "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", - parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, - parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); + sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index, aruid.pid); - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(result); - rb.Push(is_unaltered_sisxaxis_enabled); + R_RETURN(GetResourceManager()->GetSixAxis()->IsSixAxisSensorUnalteredPassthroughEnabled( + sixaxis_handle, *out_is_enabled)); } -void IHidServer::LoadSixAxisSensorCalibrationParameter(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::SixAxisSensorHandle sixaxis_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - - Core::HID::SixAxisSensorCalibrationParameter calibration{}; - auto six_axis = GetResourceManager()->GetSixAxis(); - const auto result = - six_axis->LoadSixAxisSensorCalibrationParameter(parameters.sixaxis_handle, calibration); - +Result IHidServer::LoadSixAxisSensorCalibrationParameter( + OutLargeData + out_calibration, + Core::HID::SixAxisSensorHandle sixaxis_handle, ClientAppletResourceUserId aruid) { LOG_WARNING( Service_HID, "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", - parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, - parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); + sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index, aruid.pid); - if (result.IsSuccess()) { - ctx.WriteBuffer(calibration); - } - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetSixAxis()->LoadSixAxisSensorCalibrationParameter( + sixaxis_handle, *out_calibration)); } -void IHidServer::GetSixAxisSensorIcInformation(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::SixAxisSensorHandle sixaxis_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - - Core::HID::SixAxisSensorIcInformation ic_information{}; - auto six_axis = GetResourceManager()->GetSixAxis(); - const auto result = - six_axis->GetSixAxisSensorIcInformation(parameters.sixaxis_handle, ic_information); - +Result IHidServer::GetSixAxisSensorIcInformation( + OutLargeData out_ic_information, + Core::HID::SixAxisSensorHandle sixaxis_handle, ClientAppletResourceUserId aruid) { LOG_WARNING( Service_HID, "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", - parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, - parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); + sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index, aruid.pid); - if (result.IsSuccess()) { - ctx.WriteBuffer(ic_information); - } - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetSixAxis()->GetSixAxisSensorIcInformation( + sixaxis_handle, *out_ic_information)); } -void IHidServer::ResetIsSixAxisSensorDeviceNewlyAssigned(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::SixAxisSensorHandle sixaxis_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - - auto controller = GetResourceManager()->GetNpad(); - const auto result = controller->ResetIsSixAxisSensorDeviceNewlyAssigned( - parameters.applet_resource_user_id, parameters.sixaxis_handle); - +Result IHidServer::ResetIsSixAxisSensorDeviceNewlyAssigned( + Core::HID::SixAxisSensorHandle sixaxis_handle, ClientAppletResourceUserId aruid) { LOG_WARNING( Service_HID, "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", - parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, - parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); + sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index, aruid.pid); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetNpad()->ResetIsSixAxisSensorDeviceNewlyAssigned( + aruid.pid, sixaxis_handle)); } -void IHidServer::ActivateGesture(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - u32 basic_gesture_id; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IHidServer::ActivateGesture(u32 basic_gesture_id, ClientAppletResourceUserId aruid) { LOG_INFO(Service_HID, "called, basic_gesture_id={}, applet_resource_user_id={}", - parameters.basic_gesture_id, parameters.applet_resource_user_id); - - Result result = ResultSuccess; - auto gesture = GetResourceManager()->GetGesture(); + basic_gesture_id, aruid.pid); if (!firmware_settings->IsDeviceManaged()) { - result = gesture->Activate(); + R_TRY(GetResourceManager()->GetGesture()->Activate()); } - if (result.IsSuccess()) { - result = gesture->Activate(parameters.applet_resource_user_id, parameters.basic_gesture_id); - } - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetGesture()->Activate(aruid.pid, basic_gesture_id)); } -void IHidServer::SetSupportedNpadStyleSet(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::NpadStyleSet supported_style_set; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IHidServer::SetSupportedNpadStyleSet(Core::HID::NpadStyleSet supported_style_set, + ClientAppletResourceUserId aruid) { LOG_DEBUG(Service_HID, "called, supported_style_set={}, applet_resource_user_id={}", - parameters.supported_style_set, parameters.applet_resource_user_id); + supported_style_set, aruid.pid); - const auto npad = GetResourceManager()->GetNpad(); - const Result result = npad->SetSupportedNpadStyleSet(parameters.applet_resource_user_id, - parameters.supported_style_set); + R_TRY( + GetResourceManager()->GetNpad()->SetSupportedNpadStyleSet(aruid.pid, supported_style_set)); - if (result.IsSuccess()) { - Core::HID::NpadStyleTag style_tag{parameters.supported_style_set}; - const auto revision = npad->GetRevision(parameters.applet_resource_user_id); + Core::HID::NpadStyleTag style_tag{supported_style_set}; + const auto revision = GetResourceManager()->GetNpad()->GetRevision(aruid.pid); - if (style_tag.palma != 0 && revision < NpadRevision::Revision3) { - // GetResourceManager()->GetPalma()->EnableBoostMode(parameters.applet_resource_user_id, - // true); - } + if (style_tag.palma != 0 && revision < NpadRevision::Revision3) { + // GetResourceManager()->GetPalma()->EnableBoostMode(aruid.pid, true); } - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_SUCCEED() } -void IHidServer::GetSupportedNpadStyleSet(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; +Result IHidServer::GetSupportedNpadStyleSet(Out out_supported_style_set, + ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid); - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); - - Core::HID::NpadStyleSet supported_style_set{}; - const auto npad = GetResourceManager()->GetNpad(); - const auto result = - npad->GetSupportedNpadStyleSet(applet_resource_user_id, supported_style_set); - - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(result); - rb.PushEnum(supported_style_set); + R_RETURN(GetResourceManager()->GetNpad()->GetSupportedNpadStyleSet(aruid.pid, + *out_supported_style_set)); } -void IHidServer::SetSupportedNpadIdType(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - const auto buffer = ctx.ReadBuffer(); - const std::size_t elements = ctx.GetReadBufferNumElements(); +Result IHidServer::SetSupportedNpadIdType( + ClientAppletResourceUserId aruid, + InArray supported_npad_list) { + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid); - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); - - std::vector supported_npad_list(elements); - memcpy(supported_npad_list.data(), buffer.data(), buffer.size()); - - const auto npad = GetResourceManager()->GetNpad(); - const Result result = - npad->SetSupportedNpadIdType(applet_resource_user_id, supported_npad_list); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN( + GetResourceManager()->GetNpad()->SetSupportedNpadIdType(aruid.pid, supported_npad_list)); } -void IHidServer::ActivateNpad(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); +Result IHidServer::ActivateNpad(ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid); auto npad = GetResourceManager()->GetNpad(); - npad->SetRevision(applet_resource_user_id, NpadRevision::Revision0); - const Result result = npad->Activate(applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + GetResourceManager()->GetNpad()->SetRevision(aruid.pid, NpadRevision::Revision0); + R_RETURN(GetResourceManager()->GetNpad()->Activate(aruid.pid)); } -void IHidServer::DeactivateNpad(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); +Result IHidServer::DeactivateNpad(ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid); // This function does nothing since 10.0.0+ - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IHidServer::AcquireNpadStyleSetUpdateEventHandle(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::NpadIdType npad_id; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - u64 unknown; - }; - static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size."); +Result IHidServer::AcquireNpadStyleSetUpdateEventHandle( + OutCopyHandle out_event, Core::HID::NpadIdType npad_id, + ClientAppletResourceUserId aruid, u64 unknown) { + LOG_DEBUG(Service_HID, "called, npad_id={}, applet_resource_user_id={}, unknown={}", npad_id, + aruid.pid, unknown); - const auto parameters{rp.PopRaw()}; - - LOG_DEBUG(Service_HID, "called, npad_id={}, applet_resource_user_id={}, unknown={}", - parameters.npad_id, parameters.applet_resource_user_id, parameters.unknown); - - Kernel::KReadableEvent* style_set_update_event; - const auto result = GetResourceManager()->GetNpad()->AcquireNpadStyleSetUpdateEventHandle( - parameters.applet_resource_user_id, &style_set_update_event, parameters.npad_id); - - IPC::ResponseBuilder rb{ctx, 2, 1}; - rb.Push(result); - rb.PushCopyObjects(style_set_update_event); + R_RETURN(GetResourceManager()->GetNpad()->AcquireNpadStyleSetUpdateEventHandle( + aruid.pid, out_event, npad_id)); } -void IHidServer::DisconnectNpad(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::NpadIdType npad_id; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); +Result IHidServer::DisconnectNpad(Core::HID::NpadIdType npad_id, ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_HID, "called, npad_id={}, applet_resource_user_id={}", npad_id, aruid.pid); - const auto parameters{rp.PopRaw()}; - - auto controller = GetResourceManager()->GetNpad(); - controller->DisconnectNpad(parameters.applet_resource_user_id, parameters.npad_id); - - LOG_DEBUG(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id, - parameters.applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_RETURN(GetResourceManager()->GetNpad()->DisconnectNpad(aruid.pid, npad_id)); } Result IHidServer::GetPlayerLedPattern(Out out_led_pattern, @@ -1171,833 +678,445 @@ Result IHidServer::GetPlayerLedPattern(Out out_led_patter } } -void IHidServer::ActivateNpadWithRevision(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - NpadRevision revision; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); +Result IHidServer::ActivateNpadWithRevision(NpadRevision revision, + ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_HID, "called, revision={}, applet_resource_user_id={}", revision, aruid.pid); - const auto parameters{rp.PopRaw()}; - - LOG_DEBUG(Service_HID, "called, revision={}, applet_resource_user_id={}", parameters.revision, - parameters.applet_resource_user_id); - - auto npad = GetResourceManager()->GetNpad(); - - npad->SetRevision(parameters.applet_resource_user_id, parameters.revision); - const auto result = npad->Activate(parameters.applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + GetResourceManager()->GetNpad()->SetRevision(aruid.pid, revision); + R_RETURN(GetResourceManager()->GetNpad()->Activate(aruid.pid)); } -void IHidServer::SetNpadJoyHoldType(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - const auto hold_type{rp.PopEnum()}; - - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, hold_type={}", - applet_resource_user_id, hold_type); +Result IHidServer::SetNpadJoyHoldType(ClientAppletResourceUserId aruid, NpadJoyHoldType hold_type) { + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, hold_type={}", aruid.pid, + hold_type); if (hold_type != NpadJoyHoldType::Horizontal && hold_type != NpadJoyHoldType::Vertical) { // This should crash console ASSERT_MSG(false, "Invalid npad joy hold type"); } - const auto npad = GetResourceManager()->GetNpad(); - const auto result = npad->SetNpadJoyHoldType(applet_resource_user_id, hold_type); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetNpad()->SetNpadJoyHoldType(aruid.pid, hold_type)); } -void IHidServer::GetNpadJoyHoldType(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; +Result IHidServer::GetNpadJoyHoldType(Out out_hold_type, + ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid); - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); - - NpadJoyHoldType hold_type{}; - const auto npad = GetResourceManager()->GetNpad(); - const auto result = npad->GetNpadJoyHoldType(applet_resource_user_id, hold_type); - - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(result); - rb.PushEnum(hold_type); + R_RETURN(GetResourceManager()->GetNpad()->GetNpadJoyHoldType(aruid.pid, *out_hold_type)); } -void IHidServer::SetNpadJoyAssignmentModeSingleByDefault(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::NpadIdType npad_id; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; +Result IHidServer::SetNpadJoyAssignmentModeSingleByDefault(Core::HID::NpadIdType npad_id, + ClientAppletResourceUserId aruid) { + LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}", npad_id, aruid.pid); Core::HID::NpadIdType new_npad_id{}; - auto controller = GetResourceManager()->GetNpad(); - controller->SetNpadMode(parameters.applet_resource_user_id, new_npad_id, parameters.npad_id, - NpadJoyDeviceType::Left, NpadJoyAssignmentMode::Single); - - LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id, - parameters.applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + GetResourceManager()->GetNpad()->SetNpadMode( + aruid.pid, new_npad_id, npad_id, NpadJoyDeviceType::Left, NpadJoyAssignmentMode::Single); + R_SUCCEED(); } -void IHidServer::SetNpadJoyAssignmentModeSingle(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::NpadIdType npad_id; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - NpadJoyDeviceType npad_joy_device_type; - }; - static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - - Core::HID::NpadIdType new_npad_id{}; - auto controller = GetResourceManager()->GetNpad(); - controller->SetNpadMode(parameters.applet_resource_user_id, new_npad_id, parameters.npad_id, - parameters.npad_joy_device_type, NpadJoyAssignmentMode::Single); - +Result IHidServer::SetNpadJoyAssignmentModeSingle(Core::HID::NpadIdType npad_id, + ClientAppletResourceUserId aruid, + NpadJoyDeviceType npad_joy_device_type) { LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}, npad_joy_device_type={}", - parameters.npad_id, parameters.applet_resource_user_id, - parameters.npad_joy_device_type); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); -} - -void IHidServer::SetNpadJoyAssignmentModeDual(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::NpadIdType npad_id; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; + npad_id, aruid.pid, npad_joy_device_type); Core::HID::NpadIdType new_npad_id{}; - auto controller = GetResourceManager()->GetNpad(); - controller->SetNpadMode(parameters.applet_resource_user_id, new_npad_id, parameters.npad_id, {}, - NpadJoyAssignmentMode::Dual); - - LOG_DEBUG(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id, - parameters.applet_resource_user_id); // Spams a lot when controller applet is open - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + GetResourceManager()->GetNpad()->SetNpadMode( + aruid.pid, new_npad_id, npad_id, npad_joy_device_type, NpadJoyAssignmentMode::Single); + R_SUCCEED(); } -void IHidServer::MergeSingleJoyAsDualJoy(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto npad_id_1{rp.PopEnum()}; - const auto npad_id_2{rp.PopEnum()}; - const auto applet_resource_user_id{rp.Pop()}; +Result IHidServer::SetNpadJoyAssignmentModeDual(Core::HID::NpadIdType npad_id, + ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_HID, "called, npad_id={}, applet_resource_user_id={}", npad_id, aruid.pid); - auto controller = GetResourceManager()->GetNpad(); - const auto result = - controller->MergeSingleJoyAsDualJoy(applet_resource_user_id, npad_id_1, npad_id_2); + Core::HID::NpadIdType new_npad_id{}; + GetResourceManager()->GetNpad()->SetNpadMode(aruid.pid, new_npad_id, npad_id, {}, + NpadJoyAssignmentMode::Dual); + R_SUCCEED(); +} +Result IHidServer::MergeSingleJoyAsDualJoy(Core::HID::NpadIdType npad_id_1, + Core::HID::NpadIdType npad_id_2, + ClientAppletResourceUserId aruid) { LOG_DEBUG(Service_HID, "called, npad_id_1={}, npad_id_2={}, applet_resource_user_id={}", - npad_id_1, npad_id_2, applet_resource_user_id); + npad_id_1, npad_id_2, aruid.pid); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN( + GetResourceManager()->GetNpad()->MergeSingleJoyAsDualJoy(aruid.pid, npad_id_1, npad_id_2)); } -void IHidServer::StartLrAssignmentMode(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; +Result IHidServer::StartLrAssignmentMode(ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid); - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); - - GetResourceManager()->GetNpad()->StartLrAssignmentMode(applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + GetResourceManager()->GetNpad()->StartLrAssignmentMode(aruid.pid); + R_SUCCEED(); } -void IHidServer::StopLrAssignmentMode(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; +Result IHidServer::StopLrAssignmentMode(ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid); - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); - - GetResourceManager()->GetNpad()->StopLrAssignmentMode(applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + GetResourceManager()->GetNpad()->StopLrAssignmentMode(aruid.pid); + R_SUCCEED(); } -void IHidServer::SetNpadHandheldActivationMode(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - const auto activation_mode{rp.PopEnum()}; - - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, activation_mode={}", - applet_resource_user_id, activation_mode); +Result IHidServer::SetNpadHandheldActivationMode(ClientAppletResourceUserId aruid, + NpadHandheldActivationMode activation_mode) { + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, activation_mode={}", aruid.pid, + activation_mode); if (activation_mode >= NpadHandheldActivationMode::MaxActivationMode) { // Console should crash here ASSERT_MSG(false, "Activation mode should be always None, Single or Dual"); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); - return; + R_SUCCEED(); } - const auto npad = GetResourceManager()->GetNpad(); - const auto result = - npad->SetNpadHandheldActivationMode(applet_resource_user_id, activation_mode); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN( + GetResourceManager()->GetNpad()->SetNpadHandheldActivationMode(aruid.pid, activation_mode)); } -void IHidServer::GetNpadHandheldActivationMode(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; +Result IHidServer::GetNpadHandheldActivationMode( + Out out_activation_mode, ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid); - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); - - NpadHandheldActivationMode activation_mode{}; - const auto npad = GetResourceManager()->GetNpad(); - const auto result = - npad->GetNpadHandheldActivationMode(applet_resource_user_id, activation_mode); - - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(result); - rb.PushEnum(activation_mode); + R_RETURN(GetResourceManager()->GetNpad()->GetNpadHandheldActivationMode(aruid.pid, + *out_activation_mode)); } -void IHidServer::SwapNpadAssignment(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto npad_id_1{rp.PopEnum()}; - const auto npad_id_2{rp.PopEnum()}; - const auto applet_resource_user_id{rp.Pop()}; - +Result IHidServer::SwapNpadAssignment(Core::HID::NpadIdType npad_id_1, + Core::HID::NpadIdType npad_id_2, + ClientAppletResourceUserId aruid) { LOG_DEBUG(Service_HID, "called, npad_id_1={}, npad_id_2={}, applet_resource_user_id={}", - npad_id_1, npad_id_2, applet_resource_user_id); + npad_id_1, npad_id_2, aruid.pid); - const auto npad = GetResourceManager()->GetNpad(); - const auto result = npad->SwapNpadAssignment(applet_resource_user_id, npad_id_1, npad_id_2); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetNpad()->SwapNpadAssignment(aruid.pid, npad_id_1, npad_id_2)) } -void IHidServer::IsUnintendedHomeButtonInputProtectionEnabled(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::NpadIdType npad_id; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); +Result IHidServer::IsUnintendedHomeButtonInputProtectionEnabled(Out out_is_enabled, + Core::HID::NpadIdType npad_id, + ClientAppletResourceUserId aruid) { + LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}", npad_id, aruid.pid); - const auto parameters{rp.PopRaw()}; - - LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id, - parameters.applet_resource_user_id); - - if (!IsNpadIdValid(parameters.npad_id)) { - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultInvalidNpadId); - return; - } - - bool is_enabled{}; - const auto npad = GetResourceManager()->GetNpad(); - const auto result = npad->IsUnintendedHomeButtonInputProtectionEnabled( - is_enabled, parameters.applet_resource_user_id, parameters.npad_id); - - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(result); - rb.Push(is_enabled); + R_UNLESS(IsNpadIdValid(npad_id), ResultInvalidNpadId); + R_RETURN(GetResourceManager()->GetNpad()->IsUnintendedHomeButtonInputProtectionEnabled( + *out_is_enabled, aruid.pid, npad_id)); } -void IHidServer::EnableUnintendedHomeButtonInputProtection(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - bool is_enabled; - INSERT_PADDING_BYTES_NOINIT(3); - Core::HID::NpadIdType npad_id; - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IHidServer::EnableUnintendedHomeButtonInputProtection(bool is_enabled, + Core::HID::NpadIdType npad_id, + ClientAppletResourceUserId aruid) { LOG_DEBUG(Service_HID, "called, is_enabled={}, npad_id={}, applet_resource_user_id={}", - parameters.is_enabled, parameters.npad_id, parameters.applet_resource_user_id); + is_enabled, npad_id, aruid.pid); - if (!IsNpadIdValid(parameters.npad_id)) { - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultInvalidNpadId); - return; - } - - const auto npad = GetResourceManager()->GetNpad(); - const auto result = npad->EnableUnintendedHomeButtonInputProtection( - parameters.applet_resource_user_id, parameters.npad_id, parameters.is_enabled); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_UNLESS(IsNpadIdValid(npad_id), ResultInvalidNpadId); + R_RETURN(GetResourceManager()->GetNpad()->EnableUnintendedHomeButtonInputProtection( + aruid.pid, npad_id, is_enabled)); } -void IHidServer::SetNpadJoyAssignmentModeSingleWithDestination(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::NpadIdType npad_id; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - NpadJoyDeviceType npad_joy_device_type; - }; - static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - - Core::HID::NpadIdType new_npad_id{}; - auto controller = GetResourceManager()->GetNpad(); - const auto is_reassigned = - controller->SetNpadMode(parameters.applet_resource_user_id, new_npad_id, parameters.npad_id, - parameters.npad_joy_device_type, NpadJoyAssignmentMode::Single); - +Result IHidServer::SetNpadJoyAssignmentModeSingleWithDestination( + Out out_is_reassigned, Out out_new_npad_id, + Core::HID::NpadIdType npad_id, ClientAppletResourceUserId aruid, + NpadJoyDeviceType npad_joy_device_type) { LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}, npad_joy_device_type={}", - parameters.npad_id, parameters.applet_resource_user_id, - parameters.npad_joy_device_type); + npad_id, aruid.pid, npad_joy_device_type); - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); - rb.Push(is_reassigned); - rb.PushEnum(new_npad_id); + *out_is_reassigned = GetResourceManager()->GetNpad()->SetNpadMode( + aruid.pid, *out_new_npad_id, npad_id, npad_joy_device_type, NpadJoyAssignmentMode::Single); + + R_SUCCEED(); } -void IHidServer::SetNpadAnalogStickUseCenterClamp(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - bool use_center_clamp; - INSERT_PADDING_BYTES_NOINIT(7); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IHidServer::SetNpadAnalogStickUseCenterClamp(bool use_center_clamp, + ClientAppletResourceUserId aruid) { LOG_INFO(Service_HID, "called, use_center_clamp={}, applet_resource_user_id={}", - parameters.use_center_clamp, parameters.applet_resource_user_id); + use_center_clamp, aruid.pid); - GetResourceManager()->GetNpad()->SetNpadAnalogStickUseCenterClamp( - parameters.applet_resource_user_id, parameters.use_center_clamp); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + GetResourceManager()->GetNpad()->SetNpadAnalogStickUseCenterClamp(aruid.pid, use_center_clamp); + R_SUCCEED(); } -void IHidServer::SetNpadCaptureButtonAssignment(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::NpadStyleSet npad_styleset; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - Core::HID::NpadButton button; - }; - static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IHidServer::SetNpadCaptureButtonAssignment(Core::HID::NpadStyleSet npad_styleset, + ClientAppletResourceUserId aruid, + Core::HID::NpadButton button) { LOG_INFO(Service_HID, "called, npad_styleset={}, applet_resource_user_id={}, button={}", - parameters.npad_styleset, parameters.applet_resource_user_id, parameters.button); + npad_styleset, aruid.pid, button); - const auto result = GetResourceManager()->GetNpad()->SetNpadCaptureButtonAssignment( - parameters.applet_resource_user_id, parameters.npad_styleset, parameters.button); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetNpad()->SetNpadCaptureButtonAssignment( + aruid.pid, npad_styleset, button)); } -void IHidServer::ClearNpadCaptureButtonAssignment(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; +Result IHidServer::ClearNpadCaptureButtonAssignment(ClientAppletResourceUserId aruid) { + LOG_INFO(Service_HID, "called, applet_resource_user_id={}", aruid.pid); - LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); - - const auto result = - GetResourceManager()->GetNpad()->ClearNpadCaptureButtonAssignment(applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetNpad()->ClearNpadCaptureButtonAssignment(aruid.pid)); } -void IHidServer::GetVibrationDeviceInfo(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto vibration_device_handle{rp.PopRaw()}; +Result IHidServer::GetVibrationDeviceInfo( + Out out_vibration_device_info, + Core::HID::VibrationDeviceHandle vibration_device_handle) { + LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}", + vibration_device_handle.npad_type, vibration_device_handle.npad_id, + vibration_device_handle.device_index); - Core::HID::VibrationDeviceInfo vibration_device_info{}; - const auto result = GetResourceManager()->GetVibrationDeviceInfo(vibration_device_info, - vibration_device_handle); - - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(result); - rb.PushRaw(vibration_device_info); + R_RETURN(GetResourceManager()->GetVibrationDeviceInfo(*out_vibration_device_info, + vibration_device_handle)); } -void IHidServer::SendVibrationValue(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::VibrationDeviceHandle vibration_device_handle; - Core::HID::VibrationValue vibration_value; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x20, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IHidServer::SendVibrationValue(Core::HID::VibrationDeviceHandle vibration_device_handle, + Core::HID::VibrationValue vibration_value, + ClientAppletResourceUserId aruid) { LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", - parameters.vibration_device_handle.npad_type, - parameters.vibration_device_handle.npad_id, - parameters.vibration_device_handle.device_index, parameters.applet_resource_user_id); + vibration_device_handle.npad_type, vibration_device_handle.npad_id, + vibration_device_handle.device_index, aruid.pid); - GetResourceManager()->SendVibrationValue(parameters.applet_resource_user_id, - parameters.vibration_device_handle, - parameters.vibration_value); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + GetResourceManager()->SendVibrationValue(aruid.pid, vibration_device_handle, vibration_value); + R_SUCCEED() } -void IHidServer::GetActualVibrationValue(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::VibrationDeviceHandle vibration_device_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IHidServer::GetActualVibrationValue(Out out_vibration_value, + Core::HID::VibrationDeviceHandle vibration_device_handle, + ClientAppletResourceUserId aruid) { LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", - parameters.vibration_device_handle.npad_type, - parameters.vibration_device_handle.npad_id, - parameters.vibration_device_handle.device_index, parameters.applet_resource_user_id); + vibration_device_handle.npad_type, vibration_device_handle.npad_id, + vibration_device_handle.device_index, aruid.pid); bool has_active_aruid{}; - NpadVibrationDevice* device{nullptr}; - Core::HID::VibrationValue vibration_value{}; - Result result = GetResourceManager()->IsVibrationAruidActive(parameters.applet_resource_user_id, - has_active_aruid); + R_TRY(GetResourceManager()->IsVibrationAruidActive(aruid.pid, has_active_aruid)); - if (result.IsSuccess() && has_active_aruid) { - result = IsVibrationHandleValid(parameters.vibration_device_handle); - } - if (result.IsSuccess() && has_active_aruid) { - device = GetResourceManager()->GetNSVibrationDevice(parameters.vibration_device_handle); - } - if (device != nullptr) { - result = device->GetActualVibrationValue(vibration_value); - } - if (result.IsError()) { - vibration_value = Core::HID::DEFAULT_VIBRATION_VALUE; + if (!has_active_aruid) { + *out_vibration_value = Core::HID::DEFAULT_VIBRATION_VALUE; + R_SUCCEED(); } - IPC::ResponseBuilder rb{ctx, 6}; - rb.Push(ResultSuccess); - rb.PushRaw(vibration_value); + R_TRY(IsVibrationHandleValid(vibration_device_handle)); + NpadVibrationDevice* device = + GetResourceManager()->GetNSVibrationDevice(vibration_device_handle); + + if (device == nullptr || R_FAILED(device->GetActualVibrationValue(*out_vibration_value))) { + *out_vibration_value = Core::HID::DEFAULT_VIBRATION_VALUE; + } + + R_SUCCEED(); } -void IHidServer::CreateActiveVibrationDeviceList(HLERequestContext& ctx) { +Result IHidServer::CreateActiveVibrationDeviceList( + OutInterface out_interface) { LOG_DEBUG(Service_HID, "called"); - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - rb.PushIpcInterface(system, GetResourceManager()); + *out_interface = std::make_shared(system, GetResourceManager()); + R_SUCCEED(); } -void IHidServer::PermitVibration(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto can_vibrate{rp.Pop()}; - +Result IHidServer::PermitVibration(bool can_vibrate) { LOG_DEBUG(Service_HID, "called, can_vibrate={}", can_vibrate); - const auto result = - GetResourceManager()->GetNpad()->GetVibrationHandler()->SetVibrationMasterVolume( - can_vibrate ? 1.0f : 0.0f); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetNpad()->GetVibrationHandler()->SetVibrationMasterVolume( + can_vibrate ? 1.0f : 0.0f)); } -void IHidServer::IsVibrationPermitted(HLERequestContext& ctx) { +Result IHidServer::IsVibrationPermitted(Out out_is_permitted) { LOG_DEBUG(Service_HID, "called"); f32 master_volume{}; - const auto result = - GetResourceManager()->GetNpad()->GetVibrationHandler()->GetVibrationMasterVolume( - master_volume); + R_TRY(GetResourceManager()->GetNpad()->GetVibrationHandler()->GetVibrationMasterVolume( + master_volume)); - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(result); - rb.Push(master_volume > 0.0f); + *out_is_permitted = master_volume > 0.0f; + R_SUCCEED(); } -void IHidServer::SendVibrationValues(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; +Result IHidServer::SendVibrationValues( + ClientAppletResourceUserId aruid, + InArray vibration_handles, + InArray vibration_values) { + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid); - const auto handle_data = ctx.ReadBuffer(0); - const auto handle_count = ctx.GetReadBufferNumElements(0); - const auto vibration_data = ctx.ReadBuffer(1); - const auto vibration_count = ctx.GetReadBufferNumElements(1); + R_UNLESS(vibration_handles.size() == vibration_values.size(), ResultVibrationArraySizeMismatch); - auto vibration_device_handles = - std::span(reinterpret_cast(handle_data.data()), - handle_count); - auto vibration_values = std::span( - reinterpret_cast(vibration_data.data()), vibration_count); - - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); - - Result result = ResultSuccess; - if (handle_count != vibration_count) { - result = ResultVibrationArraySizeMismatch; + for (std::size_t i = 0; i < vibration_handles.size(); i++) { + R_TRY(GetResourceManager()->SendVibrationValue(aruid.pid, vibration_handles[i], + vibration_values[i])); } - for (std::size_t i = 0; i < handle_count; i++) { - if (result.IsSuccess()) { - result = GetResourceManager()->SendVibrationValue( - applet_resource_user_id, vibration_device_handles[i], vibration_values[i]); - } - } - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_SUCCEED(); } -void IHidServer::SendVibrationGcErmCommand(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::VibrationDeviceHandle vibration_device_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - Core::HID::VibrationGcErmCommand gc_erm_command; - }; - static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IHidServer::SendVibrationGcErmCommand( + Core::HID::VibrationDeviceHandle vibration_device_handle, ClientAppletResourceUserId aruid, + Core::HID::VibrationGcErmCommand gc_erm_command) { LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}, " "gc_erm_command={}", - parameters.vibration_device_handle.npad_type, - parameters.vibration_device_handle.npad_id, - parameters.vibration_device_handle.device_index, parameters.applet_resource_user_id, - parameters.gc_erm_command); + vibration_device_handle.npad_type, vibration_device_handle.npad_id, + vibration_device_handle.device_index, aruid.pid, gc_erm_command); bool has_active_aruid{}; - NpadGcVibrationDevice* gc_device{nullptr}; - Result result = GetResourceManager()->IsVibrationAruidActive(parameters.applet_resource_user_id, - has_active_aruid); + R_TRY(GetResourceManager()->IsVibrationAruidActive(aruid.pid, has_active_aruid)); - if (result.IsSuccess() && has_active_aruid) { - result = IsVibrationHandleValid(parameters.vibration_device_handle); - } - if (result.IsSuccess() && has_active_aruid) { - gc_device = GetResourceManager()->GetGcVibrationDevice(parameters.vibration_device_handle); + if (!has_active_aruid) { + R_SUCCEED(); } + + R_TRY(IsVibrationHandleValid(vibration_device_handle)); + NpadGcVibrationDevice* gc_device = + GetResourceManager()->GetGcVibrationDevice(vibration_device_handle); if (gc_device != nullptr) { - result = gc_device->SendVibrationGcErmCommand(parameters.gc_erm_command); + R_RETURN(gc_device->SendVibrationGcErmCommand(gc_erm_command)); } - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_SUCCEED(); } -void IHidServer::GetActualVibrationGcErmCommand(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::VibrationDeviceHandle vibration_device_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - - const auto parameters{rp.PopRaw()}; - +Result IHidServer::GetActualVibrationGcErmCommand( + Out out_gc_erm_command, + Core::HID::VibrationDeviceHandle vibration_device_handle, ClientAppletResourceUserId aruid) { LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", - parameters.vibration_device_handle.npad_type, - parameters.vibration_device_handle.npad_id, - parameters.vibration_device_handle.device_index, parameters.applet_resource_user_id); + vibration_device_handle.npad_type, vibration_device_handle.npad_id, + vibration_device_handle.device_index, aruid.pid); bool has_active_aruid{}; - NpadGcVibrationDevice* gc_device{nullptr}; - Core::HID::VibrationGcErmCommand gc_erm_command{}; - Result result = GetResourceManager()->IsVibrationAruidActive(parameters.applet_resource_user_id, - has_active_aruid); + R_TRY(GetResourceManager()->IsVibrationAruidActive(aruid.pid, has_active_aruid)); - if (result.IsSuccess() && has_active_aruid) { - result = IsVibrationHandleValid(parameters.vibration_device_handle); - } - if (result.IsSuccess() && has_active_aruid) { - gc_device = GetResourceManager()->GetGcVibrationDevice(parameters.vibration_device_handle); - } - if (gc_device != nullptr) { - result = gc_device->GetActualVibrationGcErmCommand(gc_erm_command); - } - if (result.IsError()) { - gc_erm_command = Core::HID::VibrationGcErmCommand::Stop; + if (!has_active_aruid) { + *out_gc_erm_command = Core::HID::VibrationGcErmCommand::Stop; } - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); - rb.PushEnum(gc_erm_command); + R_TRY(IsVibrationHandleValid(vibration_device_handle)); + NpadGcVibrationDevice* gc_device = + GetResourceManager()->GetGcVibrationDevice(vibration_device_handle); + + if (gc_device == nullptr || + R_FAILED(gc_device->GetActualVibrationGcErmCommand(*out_gc_erm_command))) { + *out_gc_erm_command = Core::HID::VibrationGcErmCommand::Stop; + } + + R_SUCCEED(); } -void IHidServer::BeginPermitVibrationSession(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; +Result IHidServer::BeginPermitVibrationSession(ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid); - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); - - const auto result = - GetResourceManager()->GetNpad()->GetVibrationHandler()->BeginPermitVibrationSession( - applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetNpad()->GetVibrationHandler()->BeginPermitVibrationSession( + aruid.pid)); } -void IHidServer::EndPermitVibrationSession(HLERequestContext& ctx) { +Result IHidServer::EndPermitVibrationSession(ClientAppletResourceUserId aruid) { LOG_DEBUG(Service_HID, "called"); - const auto result = - GetResourceManager()->GetNpad()->GetVibrationHandler()->EndPermitVibrationSession(); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetNpad()->GetVibrationHandler()->EndPermitVibrationSession()); } -void IHidServer::IsVibrationDeviceMounted(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::VibrationDeviceHandle vibration_device_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IHidServer::IsVibrationDeviceMounted( + Out out_is_mounted, Core::HID::VibrationDeviceHandle vibration_device_handle, + ClientAppletResourceUserId aruid) { LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", - parameters.vibration_device_handle.npad_type, - parameters.vibration_device_handle.npad_id, - parameters.vibration_device_handle.device_index, parameters.applet_resource_user_id); + vibration_device_handle.npad_type, vibration_device_handle.npad_id, + vibration_device_handle.device_index, aruid.pid); - bool is_mounted{}; - NpadVibrationBase* device{nullptr}; - Result result = IsVibrationHandleValid(parameters.vibration_device_handle); + R_TRY(IsVibrationHandleValid(vibration_device_handle)); - if (result.IsSuccess()) { - device = GetResourceManager()->GetVibrationDevice(parameters.vibration_device_handle); - } + NpadVibrationBase* device = GetResourceManager()->GetVibrationDevice(vibration_device_handle); if (device != nullptr) { - is_mounted = device->IsVibrationMounted(); + *out_is_mounted = device->IsVibrationMounted(); } - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(result); - rb.Push(is_mounted); + R_SUCCEED(); } -void IHidServer::SendVibrationValueInBool(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::VibrationDeviceHandle vibration_device_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - bool is_vibrating; - }; - static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IHidServer::SendVibrationValueInBool( + bool is_vibrating, Core::HID::VibrationDeviceHandle vibration_device_handle, + ClientAppletResourceUserId aruid) { LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}, " "is_vibrating={}", - parameters.vibration_device_handle.npad_type, - parameters.vibration_device_handle.npad_id, - parameters.vibration_device_handle.device_index, parameters.applet_resource_user_id, - parameters.is_vibrating); + vibration_device_handle.npad_type, vibration_device_handle.npad_id, + vibration_device_handle.device_index, aruid.pid, is_vibrating); bool has_active_aruid{}; - NpadN64VibrationDevice* n64_device{nullptr}; - Result result = GetResourceManager()->IsVibrationAruidActive(parameters.applet_resource_user_id, - has_active_aruid); + R_TRY(GetResourceManager()->IsVibrationAruidActive(aruid.pid, has_active_aruid)); - if (result.IsSuccess() && has_active_aruid) { - result = IsVibrationHandleValid(parameters.vibration_device_handle); - } - if (result.IsSuccess() && has_active_aruid) { - n64_device = - GetResourceManager()->GetN64VibrationDevice(parameters.vibration_device_handle); + if (!has_active_aruid) { + R_SUCCEED(); } + + R_TRY(IsVibrationHandleValid(vibration_device_handle)); + NpadN64VibrationDevice* n64_device = + GetResourceManager()->GetN64VibrationDevice(vibration_device_handle); + if (n64_device != nullptr) { - result = n64_device->SendValueInBool(parameters.is_vibrating); + R_TRY(n64_device->SendValueInBool(is_vibrating)); } - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_SUCCEED(); } -void IHidServer::ActivateConsoleSixAxisSensor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - - LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); - - Result result = ResultSuccess; - auto console_sixaxis = GetResourceManager()->GetConsoleSixAxis(); +Result IHidServer::ActivateConsoleSixAxisSensor(ClientAppletResourceUserId aruid) { + LOG_INFO(Service_HID, "called, applet_resource_user_id={}", aruid.pid); if (!firmware_settings->IsDeviceManaged()) { - result = console_sixaxis->Activate(); + R_TRY(GetResourceManager()->GetConsoleSixAxis()->Activate()); } - if (result.IsSuccess()) { - result = console_sixaxis->Activate(applet_resource_user_id); - } - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetConsoleSixAxis()->Activate(aruid.pid)); } -void IHidServer::StartConsoleSixAxisSensor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::ConsoleSixAxisSensorHandle console_sixaxis_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IHidServer::StartConsoleSixAxisSensor( + Core::HID::ConsoleSixAxisSensorHandle console_sixaxis_handle, + ClientAppletResourceUserId aruid) { LOG_WARNING(Service_HID, "(STUBBED) called, unknown_1={}, unknown_2={}, applet_resource_user_id={}", - parameters.console_sixaxis_handle.unknown_1, - parameters.console_sixaxis_handle.unknown_2, parameters.applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + console_sixaxis_handle.unknown_1, console_sixaxis_handle.unknown_2, aruid.pid); + R_SUCCEED(); } -void IHidServer::StopConsoleSixAxisSensor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::ConsoleSixAxisSensorHandle console_sixaxis_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IHidServer::StopConsoleSixAxisSensor( + Core::HID::ConsoleSixAxisSensorHandle console_sixaxis_handle, + ClientAppletResourceUserId aruid) { LOG_WARNING(Service_HID, "(STUBBED) called, unknown_1={}, unknown_2={}, applet_resource_user_id={}", - parameters.console_sixaxis_handle.unknown_1, - parameters.console_sixaxis_handle.unknown_2, parameters.applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + console_sixaxis_handle.unknown_1, console_sixaxis_handle.unknown_2, aruid.pid); + R_SUCCEED(); } -void IHidServer::ActivateSevenSixAxisSensor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - - LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); - - Result result = ResultSuccess; - auto seven_sixaxis = GetResourceManager()->GetSevenSixAxis(); +Result IHidServer::ActivateSevenSixAxisSensor(ClientAppletResourceUserId aruid) { + LOG_INFO(Service_HID, "called, applet_resource_user_id={}", aruid.pid); if (!firmware_settings->IsDeviceManaged()) { - result = seven_sixaxis->Activate(); + R_TRY(GetResourceManager()->GetSevenSixAxis()->Activate()); } - if (result.IsSuccess()) { - seven_sixaxis->Activate(applet_resource_user_id); - } - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + GetResourceManager()->GetSevenSixAxis()->Activate(aruid.pid); + R_SUCCEED(); } -void IHidServer::StartSevenSixAxisSensor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - - LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}", - applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); +Result IHidServer::StartSevenSixAxisSensor(ClientAppletResourceUserId aruid) { + LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}", aruid.pid); + R_SUCCEED(); } -void IHidServer::StopSevenSixAxisSensor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - - LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}", - applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); +Result IHidServer::StopSevenSixAxisSensor(ClientAppletResourceUserId aruid) { + LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}", aruid.pid); + R_SUCCEED(); } -void IHidServer::InitializeSevenSixAxisSensor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - const auto t_mem_1_size{rp.Pop()}; - const auto t_mem_2_size{rp.Pop()}; - const auto t_mem_1_handle{ctx.GetCopyHandle(0)}; - const auto t_mem_2_handle{ctx.GetCopyHandle(1)}; +Result IHidServer::InitializeSevenSixAxisSensor(ClientAppletResourceUserId aruid, u64 t_mem_1_size, + u64 t_mem_2_size, + InCopyHandle t_mem_1, + InCopyHandle t_mem_2) { + LOG_WARNING(Service_HID, + "called, t_mem_1_size=0x{:08X}, t_mem_2_size=0x{:08X}, " + "applet_resource_user_id={}", + t_mem_1_size, t_mem_2_size, aruid.pid); ASSERT_MSG(t_mem_1_size == 0x1000, "t_mem_1_size is not 0x1000 bytes"); ASSERT_MSG(t_mem_2_size == 0x7F000, "t_mem_2_size is not 0x7F000 bytes"); - auto t_mem_1 = ctx.GetObjectFromHandle(t_mem_1_handle); - - if (t_mem_1.IsNull()) { - LOG_ERROR(Service_HID, "t_mem_1 is a nullptr for handle=0x{:08X}", t_mem_1_handle); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultUnknown); - return; - } - - auto t_mem_2 = ctx.GetObjectFromHandle(t_mem_2_handle); - - if (t_mem_2.IsNull()) { - LOG_ERROR(Service_HID, "t_mem_2 is a nullptr for handle=0x{:08X}", t_mem_2_handle); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultUnknown); - return; - } - 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"); @@ -2007,519 +1126,309 @@ void IHidServer::InitializeSevenSixAxisSensor(HLERequestContext& ctx) { GetResourceManager()->GetSevenSixAxis()->SetTransferMemoryAddress(t_mem_1->GetSourceAddress()); - LOG_WARNING(Service_HID, - "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); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IHidServer::FinalizeSevenSixAxisSensor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; +Result IHidServer::FinalizeSevenSixAxisSensor(ClientAppletResourceUserId aruid) { + LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}", aruid.pid); - LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}", - applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IHidServer::ResetSevenSixAxisSensorTimestamp(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; +Result IHidServer::ResetSevenSixAxisSensorTimestamp(ClientAppletResourceUserId aruid) { + LOG_WARNING(Service_HID, "called, applet_resource_user_id={}", aruid.pid); GetResourceManager()->GetSevenSixAxis()->ResetTimestamp(); - - LOG_WARNING(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IHidServer::IsUsbFullKeyControllerEnabled(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - +Result IHidServer::IsUsbFullKeyControllerEnabled(Out out_is_enabled, + ClientAppletResourceUserId aruid) { LOG_WARNING(Service_HID, "(STUBBED) called"); - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.Push(false); + *out_is_enabled = false; + R_SUCCEED(); } -void IHidServer::GetPalmaConnectionHandle(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::HID::NpadIdType npad_id; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); +Result IHidServer::GetPalmaConnectionHandle(Out out_handle, + Core::HID::NpadIdType npad_id, + ClientAppletResourceUserId aruid) { + LOG_WARNING(Service_HID, "(STUBBED) called, npad_id={}, applet_resource_user_id={}", npad_id, + aruid.pid); - const auto parameters{rp.PopRaw()}; - - LOG_WARNING(Service_HID, "(STUBBED) called, npad_id={}, applet_resource_user_id={}", - parameters.npad_id, parameters.applet_resource_user_id); - - Palma::PalmaConnectionHandle handle; - auto controller = GetResourceManager()->GetPalma(); - const auto result = controller->GetPalmaConnectionHandle(parameters.npad_id, handle); - - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(result); - rb.PushRaw(handle); + R_RETURN(GetResourceManager()->GetPalma()->GetPalmaConnectionHandle(npad_id, *out_handle)); } -void IHidServer::InitializePalma(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; - +Result IHidServer::InitializePalma(Palma::PalmaConnectionHandle connection_handle) { LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); - auto controller = GetResourceManager()->GetPalma(); - const auto result = controller->InitializePalma(connection_handle); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetPalma()->InitializePalma(connection_handle)); } -void IHidServer::AcquirePalmaOperationCompleteEvent(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; - +Result IHidServer::AcquirePalmaOperationCompleteEvent( + OutCopyHandle out_event, + Palma::PalmaConnectionHandle connection_handle) { LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); - auto controller = GetResourceManager()->GetPalma(); - - IPC::ResponseBuilder rb{ctx, 2, 1}; - rb.Push(ResultSuccess); - rb.PushCopyObjects(controller->AcquirePalmaOperationCompleteEvent(connection_handle)); + *out_event = + &GetResourceManager()->GetPalma()->AcquirePalmaOperationCompleteEvent(connection_handle); + R_SUCCEED(); } -void IHidServer::GetPalmaOperationInfo(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; - +Result IHidServer::GetPalmaOperationInfo(Out out_operation_type, + Palma::PalmaConnectionHandle connection_handle, + OutBuffer out_data) { LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); - Palma::PalmaOperationType operation_type; - Palma::PalmaOperationData data; - auto controller = GetResourceManager()->GetPalma(); - const auto result = controller->GetPalmaOperationInfo(connection_handle, operation_type, data); - - if (result.IsError()) { - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); - } - - ctx.WriteBuffer(data); - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(result); - rb.Push(static_cast(operation_type)); + R_RETURN(GetResourceManager()->GetPalma()->GetPalmaOperationInfo( + connection_handle, *out_operation_type, out_data)); } -void IHidServer::PlayPalmaActivity(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; - const auto palma_activity{rp.Pop()}; - +Result IHidServer::PlayPalmaActivity(Palma::PalmaConnectionHandle connection_handle, + u64 palma_activity) { LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, palma_activity={}", connection_handle.npad_id, palma_activity); - auto controller = GetResourceManager()->GetPalma(); - const auto result = controller->PlayPalmaActivity(connection_handle, palma_activity); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN( + GetResourceManager()->GetPalma()->PlayPalmaActivity(connection_handle, palma_activity)); } -void IHidServer::SetPalmaFrModeType(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; - const auto fr_mode{rp.PopEnum()}; - +Result IHidServer::SetPalmaFrModeType(Palma::PalmaConnectionHandle connection_handle, + Palma::PalmaFrModeType fr_mode) { LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, fr_mode={}", connection_handle.npad_id, fr_mode); - auto controller = GetResourceManager()->GetPalma(); - const auto result = controller->SetPalmaFrModeType(connection_handle, fr_mode); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetPalma()->SetPalmaFrModeType(connection_handle, fr_mode)); } -void IHidServer::ReadPalmaStep(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; - +Result IHidServer::ReadPalmaStep(Palma::PalmaConnectionHandle connection_handle) { LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); - auto controller = GetResourceManager()->GetPalma(); - const auto result = controller->ReadPalmaStep(connection_handle); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetPalma()->ReadPalmaStep(connection_handle)); } -void IHidServer::EnablePalmaStep(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - bool is_enabled; - INSERT_PADDING_WORDS_NOINIT(1); - Palma::PalmaConnectionHandle connection_handle; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IHidServer::EnablePalmaStep(bool is_enabled, + Palma::PalmaConnectionHandle connection_handle) { LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, is_enabled={}", - parameters.connection_handle.npad_id, parameters.is_enabled); + connection_handle.npad_id, is_enabled); - auto controller = GetResourceManager()->GetPalma(); - const auto result = - controller->EnablePalmaStep(parameters.connection_handle, parameters.is_enabled); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetPalma()->EnablePalmaStep(connection_handle, is_enabled)); } -void IHidServer::ResetPalmaStep(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; - +Result IHidServer::ResetPalmaStep(Palma::PalmaConnectionHandle connection_handle) { LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); - auto controller = GetResourceManager()->GetPalma(); - const auto result = controller->ResetPalmaStep(connection_handle); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetPalma()->ResetPalmaStep(connection_handle)); } -void IHidServer::ReadPalmaApplicationSection(HLERequestContext& ctx) { - LOG_WARNING(Service_HID, "(STUBBED) called"); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); +Result IHidServer::ReadPalmaApplicationSection(Palma::PalmaConnectionHandle connection_handle, + u64 offset, u64 size) { + LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, offset={}, size={}", + connection_handle.npad_id, offset, size); + R_SUCCEED(); } -void IHidServer::WritePalmaApplicationSection(HLERequestContext& ctx) { - LOG_WARNING(Service_HID, "(STUBBED) called"); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); +Result IHidServer::WritePalmaApplicationSection( + Palma::PalmaConnectionHandle connection_handle, u64 offset, u64 size, + InLargeData data) { + LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, offset={}, size={}", + connection_handle.npad_id, offset, size); + R_SUCCEED(); } -void IHidServer::ReadPalmaUniqueCode(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; - +Result IHidServer::ReadPalmaUniqueCode(Palma::PalmaConnectionHandle connection_handle) { LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); GetResourceManager()->GetPalma()->ReadPalmaUniqueCode(connection_handle); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IHidServer::SetPalmaUniqueCodeInvalid(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; - +Result IHidServer::SetPalmaUniqueCodeInvalid(Palma::PalmaConnectionHandle connection_handle) { LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); GetResourceManager()->GetPalma()->SetPalmaUniqueCodeInvalid(connection_handle); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IHidServer::WritePalmaActivityEntry(HLERequestContext& ctx) { - LOG_CRITICAL(Service_HID, "(STUBBED) called"); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); +Result IHidServer::WritePalmaActivityEntry(Palma::PalmaConnectionHandle connection_handle, + Palma::PalmaActivityEntry activity_entry) { + LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); + R_SUCCEED(); } -void IHidServer::WritePalmaRgbLedPatternEntry(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; - const auto unknown{rp.Pop()}; - - [[maybe_unused]] const auto buffer = ctx.ReadBuffer(); - +Result IHidServer::WritePalmaRgbLedPatternEntry(Palma::PalmaConnectionHandle connection_handle, + u64 unknown, + InBuffer led_pattern) { LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, unknown={}", connection_handle.npad_id, unknown); GetResourceManager()->GetPalma()->WritePalmaRgbLedPatternEntry(connection_handle, unknown); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IHidServer::WritePalmaWaveEntry(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; - const auto wave_set{rp.PopEnum()}; - const auto unknown{rp.Pop()}; - const auto t_mem_size{rp.Pop()}; - const auto t_mem_handle{ctx.GetCopyHandle(0)}; - const auto size{rp.Pop()}; +Result IHidServer::WritePalmaWaveEntry(Palma::PalmaConnectionHandle connection_handle, + Palma::PalmaWaveSet wave_set, u64 unknown, u64 t_mem_size, + u64 size, InCopyHandle t_mem) { + ASSERT_MSG(t_mem->GetSize() == t_mem_size, "t_mem has incorrect size"); - ASSERT_MSG(t_mem_size == 0x3000, "t_mem_size is not 0x3000 bytes"); - - auto t_mem = ctx.GetObjectFromHandle(t_mem_handle); - - if (t_mem.IsNull()) { - LOG_ERROR(Service_HID, "t_mem is a nullptr for handle=0x{:08X}", t_mem_handle); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultUnknown); - return; - } - - ASSERT_MSG(t_mem->GetSize() == 0x3000, "t_mem has incorrect size"); - - LOG_WARNING(Service_HID, - "(STUBBED) called, connection_handle={}, wave_set={}, unknown={}, " - "t_mem_handle=0x{:08X}, t_mem_size={}, size={}", - connection_handle.npad_id, wave_set, unknown, t_mem_handle, t_mem_size, size); + LOG_WARNING( + Service_HID, + "(STUBBED) called, connection_handle={}, wave_set={}, unknown={}, t_mem_size={}, size={}", + connection_handle.npad_id, wave_set, unknown, t_mem_size, size); GetResourceManager()->GetPalma()->WritePalmaWaveEntry(connection_handle, wave_set, t_mem->GetSourceAddress(), t_mem_size); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IHidServer::SetPalmaDataBaseIdentificationVersion(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - s32 database_id_version; - INSERT_PADDING_WORDS_NOINIT(1); - Palma::PalmaConnectionHandle connection_handle; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IHidServer::SetPalmaDataBaseIdentificationVersion( + s32 database_id_version, Palma::PalmaConnectionHandle connection_handle) { LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, database_id_version={}", - parameters.connection_handle.npad_id, parameters.database_id_version); + connection_handle.npad_id, database_id_version); - GetResourceManager()->GetPalma()->SetPalmaDataBaseIdentificationVersion( - parameters.connection_handle, parameters.database_id_version); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + GetResourceManager()->GetPalma()->SetPalmaDataBaseIdentificationVersion(connection_handle, + database_id_version); + R_SUCCEED(); } -void IHidServer::GetPalmaDataBaseIdentificationVersion(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; - +Result IHidServer::GetPalmaDataBaseIdentificationVersion( + Palma::PalmaConnectionHandle connection_handle) { LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); - GetResourceManager()->GetPalma()->GetPalmaDataBaseIdentificationVersion(connection_handle); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_RETURN( + GetResourceManager()->GetPalma()->GetPalmaDataBaseIdentificationVersion(connection_handle)); } -void IHidServer::SuspendPalmaFeature(HLERequestContext& ctx) { - LOG_WARNING(Service_HID, "(STUBBED) called"); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); +Result IHidServer::SuspendPalmaFeature(Palma::PalmaFeature feature, + Palma::PalmaConnectionHandle connection_handle) { + LOG_WARNING(Service_HID, "(STUBBED) called, feature={}, connection_handle={}", feature, + connection_handle.npad_id); + R_SUCCEED(); } -void IHidServer::GetPalmaOperationResult(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; - +Result IHidServer::GetPalmaOperationResult(Palma::PalmaConnectionHandle connection_handle) { LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); - const auto result = - GetResourceManager()->GetPalma()->GetPalmaOperationResult(connection_handle); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetPalma()->GetPalmaOperationResult(connection_handle)); } -void IHidServer::ReadPalmaPlayLog(HLERequestContext& ctx) { - LOG_WARNING(Service_HID, "(STUBBED) called"); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); +Result IHidServer::ReadPalmaPlayLog(u16 unknown, Palma::PalmaConnectionHandle connection_handle) { + LOG_WARNING(Service_HID, "(STUBBED) called, unknown={}, connection_handle={}", unknown, + connection_handle.npad_id); + R_SUCCEED(); } -void IHidServer::ResetPalmaPlayLog(HLERequestContext& ctx) { - LOG_WARNING(Service_HID, "(STUBBED) called"); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); +Result IHidServer::ResetPalmaPlayLog(u16 unknown, Palma::PalmaConnectionHandle connection_handle) { + LOG_WARNING(Service_HID, "(STUBBED) called, unknown={}, connection_handle={}", unknown, + connection_handle.npad_id); + R_SUCCEED(); } -void IHidServer::SetIsPalmaAllConnectable(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - bool is_palma_all_connectable; - INSERT_PADDING_BYTES_NOINIT(7); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IHidServer::SetIsPalmaAllConnectable(bool is_palma_all_connectable, + ClientAppletResourceUserId aruid) { LOG_WARNING(Service_HID, - "(STUBBED) called, is_palma_all_connectable={},applet_resource_user_id={}", - parameters.is_palma_all_connectable, parameters.applet_resource_user_id); + "(STUBBED) called, is_palma_all_connectable={}, applet_resource_user_id={}", + is_palma_all_connectable, aruid.pid); - GetResourceManager()->GetPalma()->SetIsPalmaAllConnectable(parameters.is_palma_all_connectable); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + GetResourceManager()->GetPalma()->SetIsPalmaAllConnectable(is_palma_all_connectable); + R_SUCCEED(); } -void IHidServer::SetIsPalmaPairedConnectable(HLERequestContext& ctx) { - LOG_WARNING(Service_HID, "(STUBBED) called"); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); +Result IHidServer::SetIsPalmaPairedConnectable(bool is_palma_paired_connectable, + ClientAppletResourceUserId aruid) { + LOG_WARNING(Service_HID, + "(STUBBED) called, is_palma_paired_connectable={}, applet_resource_user_id={}", + is_palma_paired_connectable, aruid.pid); + R_SUCCEED(); } -void IHidServer::PairPalma(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; - +Result IHidServer::PairPalma(Palma::PalmaConnectionHandle connection_handle) { LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); GetResourceManager()->GetPalma()->PairPalma(connection_handle); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IHidServer::SetPalmaBoostMode(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto palma_boost_mode{rp.Pop()}; +Result IHidServer::SetPalmaBoostMode(bool is_enabled) { + LOG_WARNING(Service_HID, "(STUBBED) called, is_enabled={}", is_enabled); - LOG_WARNING(Service_HID, "(STUBBED) called, palma_boost_mode={}", palma_boost_mode); - - GetResourceManager()->GetPalma()->SetPalmaBoostMode(palma_boost_mode); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + GetResourceManager()->GetPalma()->SetPalmaBoostMode(is_enabled); + R_SUCCEED(); } -void IHidServer::CancelWritePalmaWaveEntry(HLERequestContext& ctx) { - LOG_WARNING(Service_HID, "(STUBBED) called"); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); +Result IHidServer::CancelWritePalmaWaveEntry(Palma::PalmaConnectionHandle connection_handle) { + LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); + R_SUCCEED(); } -void IHidServer::EnablePalmaBoostMode(HLERequestContext& ctx) { - LOG_WARNING(Service_HID, "(STUBBED) called"); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); +Result IHidServer::EnablePalmaBoostMode(bool is_enabled, ClientAppletResourceUserId aruid) { + LOG_WARNING(Service_HID, "(STUBBED) called, is_enabled={}, applet_resource_user_id={}", + is_enabled, aruid.pid); + R_SUCCEED(); } -void IHidServer::GetPalmaBluetoothAddress(HLERequestContext& ctx) { - LOG_WARNING(Service_HID, "(STUBBED) called"); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); +Result IHidServer::GetPalmaBluetoothAddress(Out out_bt_address, + Palma::PalmaConnectionHandle connection_handle) { + LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); + R_SUCCEED(); } -void IHidServer::SetDisallowedPalmaConnection(HLERequestContext& ctx) { - LOG_WARNING(Service_HID, "(STUBBED) called"); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); +Result IHidServer::SetDisallowedPalmaConnection( + ClientAppletResourceUserId aruid, + InArray disallowed_address) { + LOG_DEBUG(Service_HID, "(STUBBED) called, applet_resource_user_id={}", aruid.pid); + R_SUCCEED(); } -void IHidServer::SetNpadCommunicationMode(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - const auto communication_mode{rp.PopEnum()}; - - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, communication_mode={}", - applet_resource_user_id, communication_mode); +Result IHidServer::SetNpadCommunicationMode(ClientAppletResourceUserId aruid, + NpadCommunicationMode communication_mode) { + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, communication_mode={}", aruid.pid, + communication_mode); // This function has been stubbed since 2.0.0+ - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IHidServer::GetNpadCommunicationMode(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); +Result IHidServer::GetNpadCommunicationMode(Out out_communication_mode, + ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid); // This function has been stubbed since 2.0.0+ - - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); - rb.PushEnum(NpadCommunicationMode::Default); + *out_communication_mode = NpadCommunicationMode::Default; + R_SUCCEED(); } -void IHidServer::SetTouchScreenConfiguration(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - auto touchscreen_config{rp.PopRaw()}; - const auto applet_resource_user_id{rp.Pop()}; - +Result IHidServer::SetTouchScreenConfiguration( + Core::HID::TouchScreenConfigurationForNx touchscreen_config, ClientAppletResourceUserId aruid) { LOG_INFO(Service_HID, "called, touchscreen_config={}, applet_resource_user_id={}", - touchscreen_config.mode, applet_resource_user_id); + touchscreen_config.mode, aruid.pid); if (touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Heat2 && touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Finger) { touchscreen_config.mode = Core::HID::TouchScreenModeForNx::UseSystemSetting; } - const Result result = GetResourceManager()->GetTouchScreen()->SetTouchScreenConfiguration( - touchscreen_config, applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetTouchScreen()->SetTouchScreenConfiguration(touchscreen_config, + aruid.pid)); } -void IHidServer::IsFirmwareUpdateNeededForNotification(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - s32 unknown; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); +Result IHidServer::IsFirmwareUpdateNeededForNotification(Out out_is_firmware_update_needed, + s32 unknown, + ClientAppletResourceUserId aruid) { + LOG_WARNING(Service_HID, "(STUBBED) called, unknown={}, applet_resource_user_id={}", unknown, + aruid.pid); - const auto parameters{rp.PopRaw()}; - - LOG_WARNING(Service_HID, "(STUBBED) called, unknown={}, applet_resource_user_id={}", - parameters.unknown, parameters.applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.Push(false); + *out_is_firmware_update_needed = false; + R_SUCCEED(); } -void IHidServer::SetTouchScreenResolution(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto width{rp.Pop()}; - const auto height{rp.Pop()}; - const auto applet_resource_user_id{rp.Pop()}; - +Result IHidServer::SetTouchScreenResolution(u32 width, u32 height, + ClientAppletResourceUserId aruid) { LOG_INFO(Service_HID, "called, width={}, height={}, applet_resource_user_id={}", width, height, - applet_resource_user_id); + aruid.pid); - GetResourceManager()->GetTouchScreen()->SetTouchScreenResolution(width, height, - applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + GetResourceManager()->GetTouchScreen()->SetTouchScreenResolution(width, height, aruid.pid); + R_SUCCEED(); } std::shared_ptr IHidServer::GetResourceManager() { diff --git a/src/core/hle/service/hid/hid_server.h b/src/core/hle/service/hid/hid_server.h index faf775689..cfa31c2de 100755 --- a/src/core/hle/service/hid/hid_server.h +++ b/src/core/hle/service/hid/hid_server.h @@ -6,12 +6,20 @@ #include "core/hle/service/cmif_types.h" #include "core/hle/service/service.h" #include "hid_core/hid_types.h" +#include "hid_core/resources/npad/npad_types.h" +#include "hid_core/resources/palma/palma.h" namespace Core { class System; } +namespace Kernel { +class KReadableEvent; +} + namespace Service::HID { +class IActiveVibrationDeviceList; +class IAppletResource; class ResourceManager; class HidFirmwareSettings; @@ -24,128 +32,232 @@ public: std::shared_ptr GetResourceManager(); private: - void CreateAppletResource(HLERequestContext& ctx); - void ActivateDebugPad(HLERequestContext& ctx); - void ActivateTouchScreen(HLERequestContext& ctx); - void ActivateMouse(HLERequestContext& ctx); - void ActivateKeyboard(HLERequestContext& ctx); - void SendKeyboardLockKeyEvent(HLERequestContext& ctx); - void AcquireXpadIdEventHandle(HLERequestContext& ctx); - void ReleaseXpadIdEventHandle(HLERequestContext& ctx); - void ActivateXpad(HLERequestContext& ctx); - void GetXpadIds(HLERequestContext& ctx); - void ActivateJoyXpad(HLERequestContext& ctx); - void GetJoyXpadLifoHandle(HLERequestContext& ctx); - void GetJoyXpadIds(HLERequestContext& ctx); - void ActivateSixAxisSensor(HLERequestContext& ctx); - void DeactivateSixAxisSensor(HLERequestContext& ctx); - void GetSixAxisSensorLifoHandle(HLERequestContext& ctx); - void ActivateJoySixAxisSensor(HLERequestContext& ctx); - void DeactivateJoySixAxisSensor(HLERequestContext& ctx); - void GetJoySixAxisSensorLifoHandle(HLERequestContext& ctx); - void StartSixAxisSensor(HLERequestContext& ctx); - void StopSixAxisSensor(HLERequestContext& ctx); - void IsSixAxisSensorFusionEnabled(HLERequestContext& ctx); - void EnableSixAxisSensorFusion(HLERequestContext& ctx); - void SetSixAxisSensorFusionParameters(HLERequestContext& ctx); - void GetSixAxisSensorFusionParameters(HLERequestContext& ctx); - void ResetSixAxisSensorFusionParameters(HLERequestContext& ctx); - void SetGyroscopeZeroDriftMode(HLERequestContext& ctx); - void GetGyroscopeZeroDriftMode(HLERequestContext& ctx); - void ResetGyroscopeZeroDriftMode(HLERequestContext& ctx); - void IsSixAxisSensorAtRest(HLERequestContext& ctx); - void IsFirmwareUpdateAvailableForSixAxisSensor(HLERequestContext& ctx); - void EnableSixAxisSensorUnalteredPassthrough(HLERequestContext& ctx); - void IsSixAxisSensorUnalteredPassthroughEnabled(HLERequestContext& ctx); - void LoadSixAxisSensorCalibrationParameter(HLERequestContext& ctx); - void GetSixAxisSensorIcInformation(HLERequestContext& ctx); - void ResetIsSixAxisSensorDeviceNewlyAssigned(HLERequestContext& ctx); - void ActivateGesture(HLERequestContext& ctx); - void SetSupportedNpadStyleSet(HLERequestContext& ctx); - void GetSupportedNpadStyleSet(HLERequestContext& ctx); - void SetSupportedNpadIdType(HLERequestContext& ctx); - void ActivateNpad(HLERequestContext& ctx); - void DeactivateNpad(HLERequestContext& ctx); - void AcquireNpadStyleSetUpdateEventHandle(HLERequestContext& ctx); - void DisconnectNpad(HLERequestContext& ctx); + Result CreateAppletResource(OutInterface out_applet_resource, + ClientAppletResourceUserId aruid); + Result ActivateDebugPad(ClientAppletResourceUserId aruid); + Result ActivateTouchScreen(ClientAppletResourceUserId aruid); + Result ActivateMouse(ClientAppletResourceUserId aruid); + Result ActivateKeyboard(ClientAppletResourceUserId aruid); + Result SendKeyboardLockKeyEvent(u32 flags); + Result AcquireXpadIdEventHandle(OutCopyHandle out_event, + ClientAppletResourceUserId aruid); + Result ReleaseXpadIdEventHandle(ClientAppletResourceUserId aruid); + Result ActivateXpad(u32 basic_xpad_id, ClientAppletResourceUserId aruid); + Result GetXpadIds(Out out_count, OutArray out_basic_pad_ids); + Result ActivateJoyXpad(u32 joy_xpad_id); + Result GetJoyXpadLifoHandle(OutCopyHandle out_shared_memory_handle, + u32 joy_xpad_id); + Result GetJoyXpadIds(Out out_basic_xpad_id_count); + Result ActivateSixAxisSensor(u32 joy_xpad_id); + Result DeactivateSixAxisSensor(u32 joy_xpad_id); + Result GetSixAxisSensorLifoHandle(OutCopyHandle out_shared_memory_handle, + u32 joy_xpad_id); + Result ActivateJoySixAxisSensor(u32 joy_xpad_id); + Result DeactivateJoySixAxisSensor(u32 joy_xpad_id); + Result GetJoySixAxisSensorLifoHandle( + OutCopyHandle out_shared_memory_handle, u32 joy_xpad_id); + Result StartSixAxisSensor(Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid); + Result StopSixAxisSensor(Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid); + Result IsSixAxisSensorFusionEnabled(Out out_is_enabled, + Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid); + Result EnableSixAxisSensorFusion(bool is_enabled, Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid); + Result SetSixAxisSensorFusionParameters(Core::HID::SixAxisSensorHandle sixaxis_handle, + Core::HID::SixAxisSensorFusionParameters sixaxis_fusion, + ClientAppletResourceUserId aruid); + Result GetSixAxisSensorFusionParameters( + Out out_fusion_parameters, + Core::HID::SixAxisSensorHandle sixaxis_handle, ClientAppletResourceUserId aruid); + Result ResetSixAxisSensorFusionParameters(Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid); + Result SetGyroscopeZeroDriftMode(Core::HID::SixAxisSensorHandle sixaxis_handle, + Core::HID::GyroscopeZeroDriftMode drift_mode, + ClientAppletResourceUserId aruid); + Result GetGyroscopeZeroDriftMode(Out out_drift_mode, + Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid); + Result ResetGyroscopeZeroDriftMode(Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid); + Result IsSixAxisSensorAtRest(Out out_is_at_rest, + Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid); + Result IsFirmwareUpdateAvailableForSixAxisSensor(Out out_is_firmware_available, + Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid); + Result EnableSixAxisSensorUnalteredPassthrough(bool is_enabled, + Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid); + Result IsSixAxisSensorUnalteredPassthroughEnabled(Out out_is_enabled, + Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid); + Result LoadSixAxisSensorCalibrationParameter( + OutLargeData + out_calibration, + Core::HID::SixAxisSensorHandle sixaxis_handle, ClientAppletResourceUserId aruid); + Result GetSixAxisSensorIcInformation( + OutLargeData + out_ic_information, + Core::HID::SixAxisSensorHandle sixaxis_handle, ClientAppletResourceUserId aruid); + Result ResetIsSixAxisSensorDeviceNewlyAssigned(Core::HID::SixAxisSensorHandle sixaxis_handle, + ClientAppletResourceUserId aruid); + Result ActivateGesture(u32 basic_gesture_id, ClientAppletResourceUserId aruid); + Result SetSupportedNpadStyleSet(Core::HID::NpadStyleSet supported_style_set, + ClientAppletResourceUserId aruid); + Result GetSupportedNpadStyleSet(Out out_supported_style_set, + ClientAppletResourceUserId aruid); + Result SetSupportedNpadIdType( + ClientAppletResourceUserId aruid, + InArray supported_npad_list); + Result ActivateNpad(ClientAppletResourceUserId aruid); + Result DeactivateNpad(ClientAppletResourceUserId aruid); + Result AcquireNpadStyleSetUpdateEventHandle(OutCopyHandle out_event, + Core::HID::NpadIdType npad_id, + ClientAppletResourceUserId aruid, u64 unknown); + Result DisconnectNpad(Core::HID::NpadIdType npad_id, ClientAppletResourceUserId aruid); Result GetPlayerLedPattern(Out out_led_pattern, Core::HID::NpadIdType npad_id); - void ActivateNpadWithRevision(HLERequestContext& ctx); - void SetNpadJoyHoldType(HLERequestContext& ctx); - void GetNpadJoyHoldType(HLERequestContext& ctx); - void SetNpadJoyAssignmentModeSingleByDefault(HLERequestContext& ctx); - void SetNpadJoyAssignmentModeSingle(HLERequestContext& ctx); - void SetNpadJoyAssignmentModeDual(HLERequestContext& ctx); - void MergeSingleJoyAsDualJoy(HLERequestContext& ctx); - void StartLrAssignmentMode(HLERequestContext& ctx); - void StopLrAssignmentMode(HLERequestContext& ctx); - void SetNpadHandheldActivationMode(HLERequestContext& ctx); - void GetNpadHandheldActivationMode(HLERequestContext& ctx); - void SwapNpadAssignment(HLERequestContext& ctx); - void IsUnintendedHomeButtonInputProtectionEnabled(HLERequestContext& ctx); - void EnableUnintendedHomeButtonInputProtection(HLERequestContext& ctx); - void SetNpadJoyAssignmentModeSingleWithDestination(HLERequestContext& ctx); - void SetNpadAnalogStickUseCenterClamp(HLERequestContext& ctx); - void SetNpadCaptureButtonAssignment(HLERequestContext& ctx); - void ClearNpadCaptureButtonAssignment(HLERequestContext& ctx); - void GetVibrationDeviceInfo(HLERequestContext& ctx); - void SendVibrationValue(HLERequestContext& ctx); - void GetActualVibrationValue(HLERequestContext& ctx); - void CreateActiveVibrationDeviceList(HLERequestContext& ctx); - void PermitVibration(HLERequestContext& ctx); - void IsVibrationPermitted(HLERequestContext& ctx); - void SendVibrationValues(HLERequestContext& ctx); - void SendVibrationGcErmCommand(HLERequestContext& ctx); - void GetActualVibrationGcErmCommand(HLERequestContext& ctx); - void BeginPermitVibrationSession(HLERequestContext& ctx); - void EndPermitVibrationSession(HLERequestContext& ctx); - void IsVibrationDeviceMounted(HLERequestContext& ctx); - void SendVibrationValueInBool(HLERequestContext& ctx); - void ActivateConsoleSixAxisSensor(HLERequestContext& ctx); - void StartConsoleSixAxisSensor(HLERequestContext& ctx); - void StopConsoleSixAxisSensor(HLERequestContext& ctx); - void ActivateSevenSixAxisSensor(HLERequestContext& ctx); - void StartSevenSixAxisSensor(HLERequestContext& ctx); - void StopSevenSixAxisSensor(HLERequestContext& ctx); - void InitializeSevenSixAxisSensor(HLERequestContext& ctx); - void FinalizeSevenSixAxisSensor(HLERequestContext& ctx); - void ResetSevenSixAxisSensorTimestamp(HLERequestContext& ctx); - void IsUsbFullKeyControllerEnabled(HLERequestContext& ctx); - void GetPalmaConnectionHandle(HLERequestContext& ctx); - void InitializePalma(HLERequestContext& ctx); - void AcquirePalmaOperationCompleteEvent(HLERequestContext& ctx); - void GetPalmaOperationInfo(HLERequestContext& ctx); - void PlayPalmaActivity(HLERequestContext& ctx); - void SetPalmaFrModeType(HLERequestContext& ctx); - void ReadPalmaStep(HLERequestContext& ctx); - void EnablePalmaStep(HLERequestContext& ctx); - void ResetPalmaStep(HLERequestContext& ctx); - void ReadPalmaApplicationSection(HLERequestContext& ctx); - void WritePalmaApplicationSection(HLERequestContext& ctx); - void ReadPalmaUniqueCode(HLERequestContext& ctx); - void SetPalmaUniqueCodeInvalid(HLERequestContext& ctx); - void WritePalmaActivityEntry(HLERequestContext& ctx); - void WritePalmaRgbLedPatternEntry(HLERequestContext& ctx); - void WritePalmaWaveEntry(HLERequestContext& ctx); - void SetPalmaDataBaseIdentificationVersion(HLERequestContext& ctx); - void GetPalmaDataBaseIdentificationVersion(HLERequestContext& ctx); - void SuspendPalmaFeature(HLERequestContext& ctx); - void GetPalmaOperationResult(HLERequestContext& ctx); - void ReadPalmaPlayLog(HLERequestContext& ctx); - void ResetPalmaPlayLog(HLERequestContext& ctx); - void SetIsPalmaAllConnectable(HLERequestContext& ctx); - void SetIsPalmaPairedConnectable(HLERequestContext& ctx); - void PairPalma(HLERequestContext& ctx); - void SetPalmaBoostMode(HLERequestContext& ctx); - void CancelWritePalmaWaveEntry(HLERequestContext& ctx); - void EnablePalmaBoostMode(HLERequestContext& ctx); - void GetPalmaBluetoothAddress(HLERequestContext& ctx); - void SetDisallowedPalmaConnection(HLERequestContext& ctx); - void SetNpadCommunicationMode(HLERequestContext& ctx); - void GetNpadCommunicationMode(HLERequestContext& ctx); - void SetTouchScreenConfiguration(HLERequestContext& ctx); - void IsFirmwareUpdateNeededForNotification(HLERequestContext& ctx); - void SetTouchScreenResolution(HLERequestContext& ctx); + Result ActivateNpadWithRevision(NpadRevision revision, ClientAppletResourceUserId aruid); + Result SetNpadJoyHoldType(ClientAppletResourceUserId aruid, NpadJoyHoldType hold_type); + Result GetNpadJoyHoldType(Out out_hold_type, ClientAppletResourceUserId aruid); + Result SetNpadJoyAssignmentModeSingleByDefault(Core::HID::NpadIdType npad_id, + ClientAppletResourceUserId aruid); + Result SetNpadJoyAssignmentModeSingle(Core::HID::NpadIdType npad_id, + ClientAppletResourceUserId aruid, + NpadJoyDeviceType npad_joy_device_type); + Result SetNpadJoyAssignmentModeDual(Core::HID::NpadIdType npad_id, + ClientAppletResourceUserId aruid); + Result MergeSingleJoyAsDualJoy(Core::HID::NpadIdType npad_id_1, Core::HID::NpadIdType npad_id_2, + ClientAppletResourceUserId aruid); + Result StartLrAssignmentMode(ClientAppletResourceUserId aruid); + Result StopLrAssignmentMode(ClientAppletResourceUserId aruid); + Result SetNpadHandheldActivationMode(ClientAppletResourceUserId aruid, + NpadHandheldActivationMode activation_mode); + Result GetNpadHandheldActivationMode(Out out_activation_mode, + ClientAppletResourceUserId aruid); + Result SwapNpadAssignment(Core::HID::NpadIdType npad_id_1, Core::HID::NpadIdType npad_id_2, + ClientAppletResourceUserId aruid); + Result IsUnintendedHomeButtonInputProtectionEnabled(Out out_is_enabled, + Core::HID::NpadIdType npad_id, + ClientAppletResourceUserId aruid); + Result EnableUnintendedHomeButtonInputProtection(bool is_enabled, Core::HID::NpadIdType npad_id, + ClientAppletResourceUserId aruid); + Result SetNpadJoyAssignmentModeSingleWithDestination(Out out_is_reassigned, + Out out_new_npad_id, + Core::HID::NpadIdType npad_id, + ClientAppletResourceUserId aruid, + NpadJoyDeviceType npad_joy_device_type); + Result SetNpadAnalogStickUseCenterClamp(bool use_center_clamp, + ClientAppletResourceUserId aruid); + Result SetNpadCaptureButtonAssignment(Core::HID::NpadStyleSet npad_styleset, + ClientAppletResourceUserId aruid, + Core::HID::NpadButton button); + Result ClearNpadCaptureButtonAssignment(ClientAppletResourceUserId aruid); + Result GetVibrationDeviceInfo(Out out_vibration_device_info, + Core::HID::VibrationDeviceHandle vibration_device_handle); + Result SendVibrationValue(Core::HID::VibrationDeviceHandle vibration_device_handle, + Core::HID::VibrationValue vibration_value, + ClientAppletResourceUserId aruid); + Result GetActualVibrationValue(Out out_vibration_value, + Core::HID::VibrationDeviceHandle vibration_device_handle, + ClientAppletResourceUserId aruid); + Result CreateActiveVibrationDeviceList(OutInterface out_interface); + Result PermitVibration(bool can_vibrate); + Result IsVibrationPermitted(Out out_is_permitted); + Result SendVibrationValues( + ClientAppletResourceUserId aruid, + InArray vibration_handles, + InArray vibration_values); + Result SendVibrationGcErmCommand(Core::HID::VibrationDeviceHandle vibration_device_handle, + ClientAppletResourceUserId aruid, + Core::HID::VibrationGcErmCommand gc_erm_command); + Result GetActualVibrationGcErmCommand(Out out_gc_erm_command, + Core::HID::VibrationDeviceHandle vibration_device_handle, + ClientAppletResourceUserId aruid); + Result BeginPermitVibrationSession(ClientAppletResourceUserId aruid); + Result EndPermitVibrationSession(ClientAppletResourceUserId aruid); + Result IsVibrationDeviceMounted(Out out_is_mounted, + Core::HID::VibrationDeviceHandle vibration_device_handle, + ClientAppletResourceUserId aruid); + Result SendVibrationValueInBool(bool is_vibrating, + Core::HID::VibrationDeviceHandle vibration_device_handle, + ClientAppletResourceUserId aruid); + Result ActivateConsoleSixAxisSensor(ClientAppletResourceUserId aruid); + Result StartConsoleSixAxisSensor(Core::HID::ConsoleSixAxisSensorHandle console_sixaxis_handle, + ClientAppletResourceUserId aruid); + Result StopConsoleSixAxisSensor(Core::HID::ConsoleSixAxisSensorHandle console_sixaxis_handle, + ClientAppletResourceUserId aruid); + Result ActivateSevenSixAxisSensor(ClientAppletResourceUserId aruid); + Result StartSevenSixAxisSensor(ClientAppletResourceUserId aruid); + Result StopSevenSixAxisSensor(ClientAppletResourceUserId aruid); + Result InitializeSevenSixAxisSensor(ClientAppletResourceUserId aruid, u64 t_mem_1_size, + u64 t_mem_2_size, + InCopyHandle t_mem_1, + InCopyHandle t_mem_2); + Result FinalizeSevenSixAxisSensor(ClientAppletResourceUserId aruid); + Result ResetSevenSixAxisSensorTimestamp(ClientAppletResourceUserId aruid); + Result IsUsbFullKeyControllerEnabled(Out out_is_enabled, + ClientAppletResourceUserId aruid); + Result GetPalmaConnectionHandle(Out out_handle, + Core::HID::NpadIdType npad_id, + ClientAppletResourceUserId aruid); + Result InitializePalma(Palma::PalmaConnectionHandle connection_handle); + Result AcquirePalmaOperationCompleteEvent(OutCopyHandle out_event, + Palma::PalmaConnectionHandle connection_handle); + Result GetPalmaOperationInfo(Out out_operation_type, + Palma::PalmaConnectionHandle connection_handle, + OutBuffer out_data); + Result PlayPalmaActivity(Palma::PalmaConnectionHandle connection_handle, u64 palma_activity); + Result SetPalmaFrModeType(Palma::PalmaConnectionHandle connection_handle, + Palma::PalmaFrModeType fr_mode); + Result ReadPalmaStep(Palma::PalmaConnectionHandle connection_handle); + Result EnablePalmaStep(bool is_enabled, Palma::PalmaConnectionHandle connection_handle); + Result ResetPalmaStep(Palma::PalmaConnectionHandle connection_handle); + Result ReadPalmaApplicationSection(Palma::PalmaConnectionHandle connection_handle, u64 offset, + u64 size); + Result WritePalmaApplicationSection( + Palma::PalmaConnectionHandle connection_handle, u64 offset, u64 size, + InLargeData data); + Result ReadPalmaUniqueCode(Palma::PalmaConnectionHandle connection_handle); + Result SetPalmaUniqueCodeInvalid(Palma::PalmaConnectionHandle connection_handle); + Result WritePalmaActivityEntry(Palma::PalmaConnectionHandle connection_handle, + Palma::PalmaActivityEntry activity_entry); + Result WritePalmaRgbLedPatternEntry(Palma::PalmaConnectionHandle connection_handle, u64 unknown, + InBuffer led_pattern); + Result WritePalmaWaveEntry(Palma::PalmaConnectionHandle connection_handle, + Palma::PalmaWaveSet wave_set, u64 unknown, u64 t_mem_size, u64 size, + InCopyHandle t_mem); + Result SetPalmaDataBaseIdentificationVersion(s32 database_id_version, + Palma::PalmaConnectionHandle connection_handle); + Result GetPalmaDataBaseIdentificationVersion(Palma::PalmaConnectionHandle connection_handle); + Result SuspendPalmaFeature(Palma::PalmaFeature feature, + Palma::PalmaConnectionHandle connection_handle); + Result GetPalmaOperationResult(Palma::PalmaConnectionHandle connection_handle); + Result ReadPalmaPlayLog(u16 unknown, Palma::PalmaConnectionHandle connection_handle); + Result ResetPalmaPlayLog(u16 unknown, Palma::PalmaConnectionHandle connection_handle); + Result SetIsPalmaAllConnectable(bool is_palma_all_connectable, ClientAppletResourceUserId arui); + Result SetIsPalmaPairedConnectable(bool is_palma_paired_connectable, + ClientAppletResourceUserId aruid); + Result PairPalma(Palma::PalmaConnectionHandle connection_handle); + Result SetPalmaBoostMode(bool is_enabled); + Result CancelWritePalmaWaveEntry(Palma::PalmaConnectionHandle connection_handle); + Result EnablePalmaBoostMode(bool is_enabled, ClientAppletResourceUserId aruid); + Result GetPalmaBluetoothAddress(Out out_bt_address, + Palma::PalmaConnectionHandle connection_handle); + Result SetDisallowedPalmaConnection( + ClientAppletResourceUserId aruid, + InArray disallowed_address); + Result SetNpadCommunicationMode(ClientAppletResourceUserId aruid, + NpadCommunicationMode communication_mode); + Result GetNpadCommunicationMode(Out out_communication_mode, + ClientAppletResourceUserId aruid); + Result SetTouchScreenConfiguration(Core::HID::TouchScreenConfigurationForNx touchscreen_config, + ClientAppletResourceUserId aruid); + Result IsFirmwareUpdateNeededForNotification(Out out_is_firmware_update_needed, + s32 unknown, ClientAppletResourceUserId aruid); + Result SetTouchScreenResolution(u32 width, u32 height, ClientAppletResourceUserId aruid); std::shared_ptr resource_manager; std::shared_ptr firmware_settings; diff --git a/src/hid_core/hid_types.h b/src/hid_core/hid_types.h index 38888fdd1..40a90c2bc 100755 --- a/src/hid_core/hid_types.h +++ b/src/hid_core/hid_types.h @@ -565,36 +565,28 @@ static_assert(sizeof(SixAxisSensorProperties) == 1, "SixAxisSensorProperties is // This is nn::hid::SixAxisSensorCalibrationParameter struct SixAxisSensorCalibrationParameter { - std::array unknown_data{}; + std::array unknown_data; }; static_assert(sizeof(SixAxisSensorCalibrationParameter) == 0x744, "SixAxisSensorCalibrationParameter is an invalid size"); +static_assert(std::is_trivial_v, + "SixAxisSensorCalibrationParameter must be trivial."); // This is nn::hid::SixAxisSensorIcInformation struct SixAxisSensorIcInformation { - f32 angular_rate{2000.0f}; // dps - std::array unknown_gyro_data1{ - -10.0f, -10.0f, -10.0f, 10.0f, 10.0f, 10.0f, - }; // dps - std::array unknown_gyro_data2{ - 0.95f, -0.003f, -0.003f, -0.003f, 0.95f, -0.003f, -0.003f, -0.003f, 0.95f, - }; - std::array unknown_gyro_data3{ - 1.05f, 0.003f, 0.003f, 0.003f, 1.05f, 0.003f, 0.003f, 0.003f, 1.05f, - }; - f32 acceleration_range{8.0f}; // g force - std::array unknown_accel_data1{ - -0.0612f, -0.0612f, -0.0612f, 0.0612f, 0.0612f, 0.0612f, - }; // g force - std::array unknown_accel_data2{ - 0.95f, -0.003f, -0.003f, -0.003f, 0.95f, -0.003f, -0.003f, -0.003f, 0.95f, - }; - std::array unknown_accel_data3{ - 1.05f, 0.003f, 0.003f, 0.003f, 1.05f, 0.003f, 0.003f, 0.003f, 1.05f, - }; + f32 angular_rate; // dps + std::array unknown_gyro_data1; // dps + std::array unknown_gyro_data2; + std::array unknown_gyro_data3; + f32 acceleration_range; // g force + std::array unknown_accel_data1; // g force + std::array unknown_accel_data2; + std::array unknown_accel_data3; }; static_assert(sizeof(SixAxisSensorIcInformation) == 0xC8, "SixAxisSensorIcInformation is an invalid size"); +static_assert(std::is_trivial_v, + "SixAxisSensorIcInformation must be trivial."); // This is nn::hid::SixAxisSensorAttribute struct SixAxisSensorAttribute { diff --git a/src/hid_core/resource_manager.cpp b/src/hid_core/resource_manager.cpp index 01261ba97..62fec03b1 100755 --- a/src/hid_core/resource_manager.cpp +++ b/src/hid_core/resource_manager.cpp @@ -4,7 +4,6 @@ #include "common/logging/log.h" #include "core/core.h" #include "core/core_timing.h" -#include "core/hle/kernel/k_shared_memory.h" #include "core/hle/service/ipc_helpers.h" #include "core/hle/service/set/system_settings_server.h" #include "core/hle/service/sm/sm.h" @@ -501,29 +500,4 @@ void ResourceManager::UpdateMotion(std::chrono::nanoseconds ns_late) { console_six_axis->OnUpdate(core_timing); } -IAppletResource::IAppletResource(Core::System& system_, std::shared_ptr resource, - u64 applet_resource_user_id) - : ServiceFramework{system_, "IAppletResource"}, aruid{applet_resource_user_id}, - resource_manager{resource} { - static const FunctionInfo functions[] = { - {0, &IAppletResource::GetSharedMemoryHandle, "GetSharedMemoryHandle"}, - }; - RegisterHandlers(functions); -} - -IAppletResource::~IAppletResource() { - resource_manager->FreeAppletResourceId(aruid); -} - -void IAppletResource::GetSharedMemoryHandle(HLERequestContext& ctx) { - Kernel::KSharedMemory* handle; - const auto result = resource_manager->GetSharedMemoryHandle(&handle, aruid); - - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, result=0x{:X}", aruid, result.raw); - - IPC::ResponseBuilder rb{ctx, 2, 1}; - rb.Push(result); - rb.PushCopyObjects(handle); -} - } // namespace Service::HID diff --git a/src/hid_core/resource_manager.h b/src/hid_core/resource_manager.h index dc3ff01f8..5abd7e044 100755 --- a/src/hid_core/resource_manager.h +++ b/src/hid_core/resource_manager.h @@ -174,17 +174,4 @@ private: KernelHelpers::ServiceContext service_context; }; -class IAppletResource final : public ServiceFramework { -public: - explicit IAppletResource(Core::System& system_, std::shared_ptr resource, - u64 applet_resource_user_id); - ~IAppletResource() override; - -private: - void GetSharedMemoryHandle(HLERequestContext& ctx); - - u64 aruid{}; - std::shared_ptr resource_manager; -}; - } // namespace Service::HID diff --git a/src/hid_core/resources/palma/palma.cpp b/src/hid_core/resources/palma/palma.cpp index ea4a291fd..be3d3c0ed 100755 --- a/src/hid_core/resources/palma/palma.cpp +++ b/src/hid_core/resources/palma/palma.cpp @@ -56,12 +56,14 @@ Kernel::KReadableEvent& Palma::AcquirePalmaOperationCompleteEvent( Result Palma::GetPalmaOperationInfo(const PalmaConnectionHandle& handle, PalmaOperationType& operation_type, - PalmaOperationData& data) const { + std::span out_data) const { if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } - operation_type = operation.operation; - data = operation.data; + operation_type = static_cast(operation.operation); + std::memcpy(out_data.data(), operation.data.data(), + std::min(out_data.size(), operation.data.size())); + return ResultSuccess; } @@ -69,7 +71,7 @@ Result Palma::PlayPalmaActivity(const PalmaConnectionHandle& handle, u64 palma_a if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } - operation.operation = PalmaOperationType::PlayActivity; + operation.operation = PackedPalmaOperationType::PlayActivity; operation.result = PalmaResultSuccess; operation.data = {}; operation_complete_event->Signal(); @@ -88,7 +90,7 @@ Result Palma::ReadPalmaStep(const PalmaConnectionHandle& handle) { if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } - operation.operation = PalmaOperationType::ReadStep; + operation.operation = PackedPalmaOperationType::ReadStep; operation.result = PalmaResultSuccess; operation.data = {}; operation_complete_event->Signal(); @@ -117,7 +119,7 @@ Result Palma::ReadPalmaUniqueCode(const PalmaConnectionHandle& handle) { if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } - operation.operation = PalmaOperationType::ReadUniqueCode; + operation.operation = PackedPalmaOperationType::ReadUniqueCode; operation.result = PalmaResultSuccess; operation.data = {}; operation_complete_event->Signal(); @@ -128,7 +130,7 @@ Result Palma::SetPalmaUniqueCodeInvalid(const PalmaConnectionHandle& handle) { if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } - operation.operation = PalmaOperationType::SetUniqueCodeInvalid; + operation.operation = PackedPalmaOperationType::SetUniqueCodeInvalid; operation.result = PalmaResultSuccess; operation.data = {}; operation_complete_event->Signal(); @@ -141,7 +143,7 @@ Result Palma::WritePalmaRgbLedPatternEntry(const PalmaConnectionHandle& handle, if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } - operation.operation = PalmaOperationType::WriteRgbLedPatternEntry; + operation.operation = PackedPalmaOperationType::WriteRgbLedPatternEntry; operation.result = PalmaResultSuccess; operation.data = {}; operation_complete_event->Signal(); @@ -153,7 +155,7 @@ Result Palma::WritePalmaWaveEntry(const PalmaConnectionHandle& handle, PalmaWave if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } - operation.operation = PalmaOperationType::WriteWaveEntry; + operation.operation = PackedPalmaOperationType::WriteWaveEntry; operation.result = PalmaResultSuccess; operation.data = {}; operation_complete_event->Signal(); @@ -166,7 +168,7 @@ Result Palma::SetPalmaDataBaseIdentificationVersion(const PalmaConnectionHandle& return InvalidPalmaHandle; } database_id_version = database_id_version_; - operation.operation = PalmaOperationType::ReadDataBaseIdentificationVersion; + operation.operation = PackedPalmaOperationType::ReadDataBaseIdentificationVersion; operation.result = PalmaResultSuccess; operation.data[0] = {}; operation_complete_event->Signal(); @@ -177,7 +179,7 @@ Result Palma::GetPalmaDataBaseIdentificationVersion(const PalmaConnectionHandle& if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } - operation.operation = PalmaOperationType::ReadDataBaseIdentificationVersion; + operation.operation = PackedPalmaOperationType::ReadDataBaseIdentificationVersion; operation.result = PalmaResultSuccess; operation.data = {}; operation.data[0] = static_cast(database_id_version); diff --git a/src/hid_core/resources/palma/palma.h b/src/hid_core/resources/palma/palma.h index 60259c3d8..477cbf904 100755 --- a/src/hid_core/resources/palma/palma.h +++ b/src/hid_core/resources/palma/palma.h @@ -4,6 +4,8 @@ #pragma once #include +#include + #include "common/common_funcs.h" #include "common/typed_address.h" #include "hid_core/hid_result.h" @@ -27,9 +29,31 @@ namespace Service::HID { class Palma final : public ControllerBase { public: using PalmaOperationData = std::array; + using PalmaApplicationSection = std::array; + using Address = std::array; // This is nn::hid::PalmaOperationType - enum class PalmaOperationType { + enum class PalmaOperationType : u64 { + PlayActivity, + SetFrModeType, + ReadStep, + EnableStep, + ResetStep, + ReadApplicationSection, + WriteApplicationSection, + ReadUniqueCode, + SetUniqueCodeInvalid, + WriteActivityEntry, + WriteRgbLedPatternEntry, + WriteWaveEntry, + ReadDataBaseIdentificationVersion, + WriteDataBaseIdentificationVersion, + SuspendFeature, + ReadPlayLog, + ResetPlayLog, + }; + + enum class PackedPalmaOperationType : u32 { PlayActivity, SetFrModeType, ReadStep, @@ -75,7 +99,7 @@ public: // This is nn::hid::PalmaOperationInfo struct PalmaOperationInfo { - PalmaOperationType operation{}; + PackedPalmaOperationType operation{}; Result result{PalmaResultSuccess}; PalmaOperationData data{}; }; @@ -92,8 +116,7 @@ public: static_assert(sizeof(PalmaActivityEntry) == 0x20, "PalmaActivityEntry is an invalid size"); struct PalmaConnectionHandle { - Core::HID::NpadIdType npad_id; - INSERT_PADDING_BYTES(4); // Unknown + alignas(8) Core::HID::NpadIdType npad_id; }; static_assert(sizeof(PalmaConnectionHandle) == 0x8, "PalmaConnectionHandle has incorrect size."); @@ -115,8 +138,7 @@ public: Kernel::KReadableEvent& AcquirePalmaOperationCompleteEvent( const PalmaConnectionHandle& handle) const; Result GetPalmaOperationInfo(const PalmaConnectionHandle& handle, - PalmaOperationType& operation_type, - PalmaOperationData& data) const; + PalmaOperationType& operation_type, std::span out_data) const; Result PlayPalmaActivity(const PalmaConnectionHandle& handle, u64 palma_activity); Result SetPalmaFrModeType(const PalmaConnectionHandle& handle, PalmaFrModeType fr_mode_); Result ReadPalmaStep(const PalmaConnectionHandle& handle); diff --git a/src/video_core/engines/draw_manager.cpp b/src/video_core/engines/draw_manager.cpp index d77ff455b..971025cb5 100755 --- a/src/video_core/engines/draw_manager.cpp +++ b/src/video_core/engines/draw_manager.cpp @@ -216,14 +216,11 @@ void DrawManager::DrawTexture() { const bool lower_left{regs.window_origin.mode != Maxwell3D::Regs::WindowOrigin::Mode::UpperLeft}; if (lower_left) { - draw_texture_state.dst_y0 -= dst_height; + draw_texture_state.dst_y0 = + static_cast(regs.surface_clip.height) - draw_texture_state.dst_y0; } - draw_texture_state.dst_x1 = - draw_texture_state.dst_x0 + - static_cast(Settings::values.resolution_info.ScaleUp(static_cast(dst_width))); - draw_texture_state.dst_y1 = - draw_texture_state.dst_y0 + - static_cast(Settings::values.resolution_info.ScaleUp(static_cast(dst_height))); + draw_texture_state.dst_x1 = draw_texture_state.dst_x0 + dst_width; + draw_texture_state.dst_y1 = draw_texture_state.dst_y0 + dst_height; draw_texture_state.src_x0 = static_cast(regs.draw_texture.src_x0) / 4096.f; draw_texture_state.src_y0 = static_cast(regs.draw_texture.src_y0) / 4096.f; draw_texture_state.src_x1 = diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 9ac59266f..90aea6c7e 100755 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -370,27 +370,32 @@ void RasterizerOpenGL::DrawTexture() { const auto& sampler = texture_cache.GetGraphicsSampler(draw_texture_state.src_sampler); const auto& texture = texture_cache.GetImageView(draw_texture_state.src_texture); + const auto Scale = [&](auto dim) -> s32 { + return Settings::values.resolution_info.ScaleUp(static_cast(dim)); + }; + + Region2D dst_region = { + Offset2D{.x = Scale(draw_texture_state.dst_x0), .y = Scale(draw_texture_state.dst_y0)}, + Offset2D{.x = Scale(draw_texture_state.dst_x1), .y = Scale(draw_texture_state.dst_y1)}}; + Region2D src_region = { + Offset2D{.x = Scale(draw_texture_state.src_x0), .y = Scale(draw_texture_state.src_y0)}, + Offset2D{.x = Scale(draw_texture_state.src_x1), .y = Scale(draw_texture_state.src_y1)}}; + Extent3D src_size = {static_cast(Scale(texture.size.width)), + static_cast(Scale(texture.size.height)), texture.size.depth}; + if (device.HasDrawTexture()) { state_tracker.BindFramebuffer(texture_cache.GetFramebuffer()->Handle()); - glDrawTextureNV(texture.DefaultHandle(), sampler->Handle(), draw_texture_state.dst_x0, - draw_texture_state.dst_y0, draw_texture_state.dst_x1, - draw_texture_state.dst_y1, 0, + glDrawTextureNV(texture.DefaultHandle(), sampler->Handle(), + static_cast(dst_region.start.x), static_cast(dst_region.start.y), + static_cast(dst_region.end.x), static_cast(dst_region.end.y), 0, draw_texture_state.src_x0 / static_cast(texture.size.width), draw_texture_state.src_y0 / static_cast(texture.size.height), draw_texture_state.src_x1 / static_cast(texture.size.width), draw_texture_state.src_y1 / static_cast(texture.size.height)); } else { - Region2D dst_region = {Offset2D{.x = static_cast(draw_texture_state.dst_x0), - .y = static_cast(draw_texture_state.dst_y0)}, - Offset2D{.x = static_cast(draw_texture_state.dst_x1), - .y = static_cast(draw_texture_state.dst_y1)}}; - Region2D src_region = {Offset2D{.x = static_cast(draw_texture_state.src_x0), - .y = static_cast(draw_texture_state.src_y0)}, - Offset2D{.x = static_cast(draw_texture_state.src_x1), - .y = static_cast(draw_texture_state.src_y1)}}; blit_image.BlitColor(texture_cache.GetFramebuffer()->Handle(), texture.DefaultHandle(), - sampler->Handle(), dst_region, src_region, texture.size); + sampler->Handle(), dst_region, src_region, src_size); state_tracker.InvalidateState(); } diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index b11cf9acd..d9b43379c 100755 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp @@ -125,11 +125,23 @@ VkRect2D GetScissorState(const Maxwell& regs, size_t index, u32 up_scale = 1, u3 return value < 0 ? std::min(converted_value - acumm, -1) : std::max(converted_value + acumm, 1); }; + + const bool lower_left = regs.window_origin.mode != Maxwell::WindowOrigin::Mode::UpperLeft; + const s32 clip_height = regs.surface_clip.height; + + // Flip coordinates if lower left + s32 min_y = lower_left ? (clip_height - src.max_y) : src.min_y.Value(); + s32 max_y = lower_left ? (clip_height - src.min_y) : src.max_y.Value(); + + // Bound to render area + min_y = std::max(min_y, 0); + max_y = std::max(max_y, 0); + if (src.enable) { - scissor.offset.x = scale_up(static_cast(src.min_x)); - scissor.offset.y = scale_up(static_cast(src.min_y)); + scissor.offset.x = scale_up(src.min_x); + scissor.offset.y = scale_up(min_y); scissor.extent.width = scale_up(src.max_x - src.min_x); - scissor.extent.height = scale_up(src.max_y - src.min_y); + scissor.extent.height = scale_up(max_y - min_y); } else { scissor.offset.x = 0; scissor.offset.y = 0; @@ -308,17 +320,33 @@ void RasterizerVulkan::DrawTexture() { const auto& draw_texture_state = maxwell3d->draw_manager->GetDrawTextureState(); const auto& sampler = texture_cache.GetGraphicsSampler(draw_texture_state.src_sampler); const auto& texture = texture_cache.GetImageView(draw_texture_state.src_texture); - Region2D dst_region = {Offset2D{.x = static_cast(draw_texture_state.dst_x0), - .y = static_cast(draw_texture_state.dst_y0)}, - Offset2D{.x = static_cast(draw_texture_state.dst_x1), - .y = static_cast(draw_texture_state.dst_y1)}}; - Region2D src_region = {Offset2D{.x = static_cast(draw_texture_state.src_x0), - .y = static_cast(draw_texture_state.src_y0)}, - Offset2D{.x = static_cast(draw_texture_state.src_x1), - .y = static_cast(draw_texture_state.src_y1)}}; - blit_image.BlitColor(texture_cache.GetFramebuffer(), texture.RenderTarget(), - texture.ImageHandle(), sampler->Handle(), dst_region, src_region, - texture.size); + const auto* framebuffer = texture_cache.GetFramebuffer(); + + const bool src_rescaling = texture_cache.IsRescaling() && texture.IsRescaled(); + const bool dst_rescaling = texture_cache.IsRescaling() && framebuffer->IsRescaled(); + + const auto ScaleSrc = [&](auto dim_f) -> s32 { + auto dim = static_cast(dim_f); + return src_rescaling ? Settings::values.resolution_info.ScaleUp(dim) : dim; + }; + + const auto ScaleDst = [&](auto dim_f) -> s32 { + auto dim = static_cast(dim_f); + return dst_rescaling ? Settings::values.resolution_info.ScaleUp(dim) : dim; + }; + + Region2D dst_region = {Offset2D{.x = ScaleDst(draw_texture_state.dst_x0), + .y = ScaleDst(draw_texture_state.dst_y0)}, + Offset2D{.x = ScaleDst(draw_texture_state.dst_x1), + .y = ScaleDst(draw_texture_state.dst_y1)}}; + Region2D src_region = {Offset2D{.x = ScaleSrc(draw_texture_state.src_x0), + .y = ScaleSrc(draw_texture_state.src_y0)}, + Offset2D{.x = ScaleSrc(draw_texture_state.src_x1), + .y = ScaleSrc(draw_texture_state.src_y1)}}; + Extent3D src_size = {static_cast(ScaleSrc(texture.size.width)), + static_cast(ScaleSrc(texture.size.height)), texture.size.depth}; + blit_image.BlitColor(framebuffer, texture.RenderTarget(), texture.ImageHandle(), + sampler->Handle(), dst_region, src_region, src_size); } void RasterizerVulkan::Clear(u32 layer_count) { diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp index 7a1569278..ace4f4d23 100755 --- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp @@ -1962,21 +1962,22 @@ Framebuffer::Framebuffer(TextureCacheRuntime& runtime, std::span color_buffers{color_buffer}; - CreateFramebuffer(runtime, color_buffers, depth_buffer, is_rescaled); + CreateFramebuffer(runtime, color_buffers, depth_buffer, is_rescaled_); } Framebuffer::~Framebuffer() = default; void Framebuffer::CreateFramebuffer(TextureCacheRuntime& runtime, std::span color_buffers, - ImageView* depth_buffer, bool is_rescaled) { + ImageView* depth_buffer, bool is_rescaled_) { boost::container::small_vector attachments; RenderPassKey renderpass_key{}; s32 num_layers = 1; + is_rescaled = is_rescaled_; const auto& resolution = runtime.resolution; u32 width = std::numeric_limits::max(); diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.h b/src/video_core/renderer_vulkan/vk_texture_cache.h index 296d34f64..459dfd148 100755 --- a/src/video_core/renderer_vulkan/vk_texture_cache.h +++ b/src/video_core/renderer_vulkan/vk_texture_cache.h @@ -361,6 +361,10 @@ public: return has_stencil; } + [[nodiscard]] bool IsRescaled() const noexcept { + return is_rescaled; + } + private: vk::Framebuffer framebuffer; VkRenderPass renderpass{}; @@ -373,6 +377,7 @@ private: std::array rt_map{}; bool has_depth{}; bool has_stencil{}; + bool is_rescaled{}; }; struct TextureCacheParams { diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 70e089902..6c8540186 100755 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -1461,6 +1461,7 @@ void GMainWindow::OnAppFocusStateChanged(Qt::ApplicationState state) { OnPauseGame(); } else if (!emu_thread->IsRunning() && auto_paused && state == Qt::ApplicationActive) { auto_paused = false; + RequestGameResume(); OnStartGame(); } } @@ -1701,6 +1702,7 @@ void GMainWindow::OnPrepareForSleep(bool prepare_sleep) { } else { if (!emu_thread->IsRunning() && auto_paused) { auto_paused = false; + RequestGameResume(); OnStartGame(); } } @@ -3455,6 +3457,7 @@ void GMainWindow::OnPauseContinueGame() { if (emu_thread->IsRunning()) { OnPauseGame(); } else { + RequestGameResume(); OnStartGame(); } } @@ -5010,6 +5013,10 @@ void GMainWindow::RequestGameExit() { system->GetAppletManager().RequestExit(); } +void GMainWindow::RequestGameResume() { + system->GetAppletManager().RequestResume(); +} + void GMainWindow::filterBarSetChecked(bool state) { ui->action_Show_Filter_Bar->setChecked(state); emit(OnToggleFilterBar()); diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 1501c99bc..697c38e57 100755 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -310,6 +310,7 @@ private: bool ConfirmChangeGame(); bool ConfirmForceLockedExit(); void RequestGameExit(); + void RequestGameResume(); void changeEvent(QEvent* event) override; void closeEvent(QCloseEvent* event) override;