From 96d280b4f5a4491beffd57c386deeb0e39e8a64f Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Mon, 11 Dec 2023 02:14:53 +0100 Subject: [PATCH] early-access version 4015 --- README.md | 2 +- src/android/app/src/main/jni/native.cpp | 7 +- src/android/app/src/main/jni/native.h | 1 - src/core/core.cpp | 14 ++- src/core/core.h | 7 ++ .../hid/controllers/applet_resource.cpp | 89 +++++++++++++++++++ .../service/hid/controllers/applet_resource.h | 6 ++ src/core/hle/service/hid/errors.h | 3 + src/core/hle/service/hid/hid_server.cpp | 10 +-- src/core/hle/service/hid/resource_manager.cpp | 45 ++++++++-- src/core/hle/service/hid/resource_manager.h | 9 +- .../nvnflinger/buffer_queue_consumer.cpp | 2 +- .../hle/service/nvnflinger/nvnflinger.cpp | 42 ++++----- src/core/hle/service/nvnflinger/nvnflinger.h | 11 +-- src/core/hle/service/sm/sm.cpp | 25 ++++-- src/core/hle/service/sm/sm.h | 7 +- .../hle/service/vi/display/vi_display.cpp | 25 +++++- src/core/hle/service/vi/display/vi_display.h | 13 +-- src/core/hle/service/vi/layer/vi_layer.cpp | 4 +- src/core/hle/service/vi/layer/vi_layer.h | 13 +++ src/core/hle/service/vi/vi.cpp | 3 + src/yuzu/applets/qt_profile_select.cpp | 14 +-- src/yuzu/applets/qt_profile_select.h | 15 ++-- .../configure_profile_manager.cpp | 36 ++++---- .../configuration/configure_profile_manager.h | 5 +- src/yuzu/main.cpp | 19 ++-- src/yuzu/multiplayer/lobby.cpp | 11 +-- src/yuzu/multiplayer/lobby.h | 5 -- src/yuzu/play_time_manager.cpp | 21 +++-- src/yuzu/play_time_manager.h | 12 ++- 30 files changed, 341 insertions(+), 135 deletions(-) diff --git a/README.md b/README.md index f637c3dbf..93ceee4ca 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 4014. +This is the source code for early-access 4015. ## Legal Notice diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp index 3d795b57f..e5d3158c8 100755 --- a/src/android/app/src/main/jni/native.cpp +++ b/src/android/app/src/main/jni/native.cpp @@ -291,9 +291,6 @@ Core::SystemResultStatus EmulationSession::InitializeEmulation(const std::string // Initialize filesystem. ConfigureFilesystemProvider(filepath); - // Initialize account manager - m_profile_manager = std::make_unique(); - // Load the ROM. m_load_result = m_system.Load(EmulationSession::GetInstance().Window(), filepath); if (m_load_result != Core::SystemResultStatus::Success) { @@ -736,8 +733,8 @@ void Java_org_yuzu_yuzu_1emu_NativeLibrary_initializeEmptyUserDirectory(JNIEnv* auto vfs_nand_dir = EmulationSession::GetInstance().System().GetFilesystem()->OpenDirectory( Common::FS::PathToUTF8String(nand_dir), FileSys::Mode::Read); - Service::Account::ProfileManager manager; - const auto user_id = manager.GetUser(static_cast(0)); + const auto user_id = EmulationSession::GetInstance().System().GetProfileManager().GetUser( + static_cast(0)); ASSERT(user_id); const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath( diff --git a/src/android/app/src/main/jni/native.h b/src/android/app/src/main/jni/native.h index 78ef96802..f1457bd1f 100755 --- a/src/android/app/src/main/jni/native.h +++ b/src/android/app/src/main/jni/native.h @@ -73,7 +73,6 @@ private: std::atomic m_is_running = false; std::atomic m_is_paused = false; SoftwareKeyboard::AndroidKeyboard* m_software_keyboard{}; - std::unique_ptr m_profile_manager; std::unique_ptr m_manual_provider; // GPU driver parameters diff --git a/src/core/core.cpp b/src/core/core.cpp index d62607443..296c6e671 100755 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -36,6 +36,7 @@ #include "core/hle/kernel/k_scheduler.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/physical_core.h" +#include "core/hle/service/acc/profile_manager.h" #include "core/hle/service/am/applets/applets.h" #include "core/hle/service/apm/apm_controller.h" #include "core/hle/service/filesystem/filesystem.h" @@ -130,8 +131,8 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, struct System::Impl { explicit Impl(System& system) : kernel{system}, fs_controller{system}, memory{system}, hid_core{}, room_network{}, - cpu_manager{system}, reporter{system}, applet_manager{system}, time_manager{system}, - gpu_dirty_memory_write_manager{} { + cpu_manager{system}, reporter{system}, applet_manager{system}, profile_manager{}, + time_manager{system}, gpu_dirty_memory_write_manager{} { memory.SetGPUDirtyManagers(gpu_dirty_memory_write_manager); } @@ -532,6 +533,7 @@ struct System::Impl { /// Service State Service::Glue::ARPManager arp_manager; + Service::Account::ProfileManager profile_manager; Service::Time::TimeManager time_manager; /// Service manager @@ -921,6 +923,14 @@ const Service::APM::Controller& System::GetAPMController() const { return impl->apm_controller; } +Service::Account::ProfileManager& System::GetProfileManager() { + return impl->profile_manager; +} + +const Service::Account::ProfileManager& System::GetProfileManager() const { + return impl->profile_manager; +} + Service::Time::TimeManager& System::GetTimeManager() { return impl->time_manager; } diff --git a/src/core/core.h b/src/core/core.h index 3e2373d6a..5fba2d739 100755 --- a/src/core/core.h +++ b/src/core/core.h @@ -45,6 +45,10 @@ class Memory; namespace Service { +namespace Account { +class ProfileManager; +} // namespace Account + namespace AM::Applets { struct AppletFrontendSet; class AppletManager; @@ -383,6 +387,9 @@ public: [[nodiscard]] Service::APM::Controller& GetAPMController(); [[nodiscard]] const Service::APM::Controller& GetAPMController() const; + [[nodiscard]] Service::Account::ProfileManager& GetProfileManager(); + [[nodiscard]] const Service::Account::ProfileManager& GetProfileManager() const; + [[nodiscard]] Service::Time::TimeManager& GetTimeManager(); [[nodiscard]] const Service::Time::TimeManager& GetTimeManager() const; diff --git a/src/core/hle/service/hid/controllers/applet_resource.cpp b/src/core/hle/service/hid/controllers/applet_resource.cpp index ee60d8b44..435b86233 100755 --- a/src/core/hle/service/hid/controllers/applet_resource.cpp +++ b/src/core/hle/service/hid/controllers/applet_resource.cpp @@ -112,6 +112,19 @@ void AppletResource::UnregisterAppletResourceUserId(u64 aruid) { } } +void AppletResource::FreeAppletResourceId(u64 aruid) { + u64 index = GetIndexFromAruid(aruid); + if (index >= AruidIndexMax) { + return; + } + + auto& aruid_data = data[index]; + if (aruid_data.flag.is_assigned) { + aruid_data.shared_memory_handle = nullptr; + aruid_data.flag.is_assigned.Assign(false); + } +} + u64 AppletResource::GetActiveAruid() { return active_aruid; } @@ -196,4 +209,80 @@ void AppletResource::EnablePalmaBoostMode(u64 aruid, bool is_enabled) { data[index].flag.enable_palma_boost_mode.Assign(is_enabled); } +Result AppletResource::RegisterCoreAppletResource() { + if (ref_counter == std::numeric_limits::max() - 1) { + return ResultAppletResourceOverflow; + } + if (ref_counter == 0) { + const u64 index = GetIndexFromAruid(0); + if (index < AruidIndexMax) { + return ResultAruidAlreadyRegistered; + } + + std::size_t data_index = AruidIndexMax; + for (std::size_t i = 0; i < AruidIndexMax; i++) { + if (!data[i].flag.is_initialized) { + data_index = i; + break; + } + } + + if (data_index == AruidIndexMax) { + return ResultAruidNoAvailableEntries; + } + + AruidData& aruid_data = data[data_index]; + + aruid_data.aruid = 0; + aruid_data.flag.is_initialized.Assign(true); + aruid_data.flag.enable_pad_input.Assign(true); + aruid_data.flag.enable_six_axis_sensor.Assign(true); + aruid_data.flag.bit_18.Assign(true); + aruid_data.flag.enable_touchscreen.Assign(true); + + data_index = AruidIndexMax; + for (std::size_t i = 0; i < AruidIndexMax; i++) { + if (registration_list.flag[i] == RegistrationStatus::Initialized) { + if (registration_list.aruid[i] != 0) { + continue; + } + data_index = i; + break; + } + if (registration_list.flag[i] == RegistrationStatus::None) { + data_index = i; + break; + } + } + + Result result = ResultSuccess; + + if (data_index == AruidIndexMax) { + result = CreateAppletResource(0); + } else { + registration_list.flag[data_index] = RegistrationStatus::Initialized; + registration_list.aruid[data_index] = 0; + } + + if (result.IsError()) { + UnregisterAppletResourceUserId(0); + return result; + } + } + ref_counter++; + return ResultSuccess; +} + +Result AppletResource::UnregisterCoreAppletResource() { + if (ref_counter == 0) { + return ResultAppletResourceNotInitialized; + } + + if (--ref_counter == 0) { + UnregisterAppletResourceUserId(0); + } + + return ResultSuccess; +} + } // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/applet_resource.h b/src/core/hle/service/hid/controllers/applet_resource.h index 3dcec2898..62137db13 100755 --- a/src/core/hle/service/hid/controllers/applet_resource.h +++ b/src/core/hle/service/hid/controllers/applet_resource.h @@ -28,6 +28,8 @@ public: Result RegisterAppletResourceUserId(u64 aruid, bool enable_input); void UnregisterAppletResourceUserId(u64 aruid); + void FreeAppletResourceId(u64 aruid); + u64 GetActiveAruid(); Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid); @@ -42,6 +44,9 @@ public: void SetIsPalmaConnectable(u64 aruid, bool is_connectable); void EnablePalmaBoostMode(u64 aruid, bool is_enabled); + Result RegisterCoreAppletResource(); + Result UnregisterCoreAppletResource(); + private: static constexpr std::size_t AruidIndexMax = 0x20; @@ -81,6 +86,7 @@ private: u64 active_aruid{}; AruidRegisterList registration_list{}; std::array data{}; + s32 ref_counter{}; Core::System& system; }; diff --git a/src/core/hle/service/hid/errors.h b/src/core/hle/service/hid/errors.h index a4a23f200..3ede41061 100755 --- a/src/core/hle/service/hid/errors.h +++ b/src/core/hle/service/hid/errors.h @@ -20,6 +20,9 @@ constexpr Result InvalidNpadId{ErrorModule::HID, 709}; constexpr Result NpadNotConnected{ErrorModule::HID, 710}; constexpr Result InvalidArraySize{ErrorModule::HID, 715}; +constexpr Result ResultAppletResourceOverflow{ErrorModule::HID, 1041}; +constexpr Result ResultAppletResourceNotInitialized{ErrorModule::HID, 1042}; +constexpr Result ResultSharedMemoryNotInitialized{ErrorModule::HID, 1043}; constexpr Result ResultAruidNoAvailableEntries{ErrorModule::HID, 1044}; constexpr Result ResultAruidAlreadyRegistered{ErrorModule::HID, 1046}; constexpr Result ResultAruidNotRegistered{ErrorModule::HID, 1047}; diff --git a/src/core/hle/service/hid/hid_server.cpp b/src/core/hle/service/hid/hid_server.cpp index e0f4051aa..b06ea467e 100755 --- a/src/core/hle/service/hid/hid_server.cpp +++ b/src/core/hle/service/hid/hid_server.cpp @@ -222,16 +222,14 @@ void IHidServer::CreateAppletResource(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 = GetResourceManager()->CreateAppletResource(applet_resource_user_id); - if (result.IsSuccess()) { - result = GetResourceManager()->GetNpad()->Activate(applet_resource_user_id); - } + + 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); + rb.PushIpcInterface(system, resource_manager, applet_resource_user_id); } void IHidServer::ActivateDebugPad(HLERequestContext& ctx) { diff --git a/src/core/hle/service/hid/resource_manager.cpp b/src/core/hle/service/hid/resource_manager.cpp index 60d4ef71f..89cdc19cc 100755 --- a/src/core/hle/service/hid/resource_manager.cpp +++ b/src/core/hle/service/hid/resource_manager.cpp @@ -146,10 +146,36 @@ std::shared_ptr ResourceManager::GetUniquePad() const { } Result ResourceManager::CreateAppletResource(u64 aruid) { + if (aruid == 0) { + const auto result = RegisterCoreAppletResource(); + if (result.IsError()) { + return result; + } + return GetNpad()->Activate(); + } + + const auto result = CreateAppletResourceImpl(aruid); + if (result.IsError()) { + return result; + } + return GetNpad()->Activate(aruid); +} + +Result ResourceManager::CreateAppletResourceImpl(u64 aruid) { std::scoped_lock lock{shared_mutex}; return applet_resource->CreateAppletResource(aruid); } +Result ResourceManager::RegisterCoreAppletResource() { + std::scoped_lock lock{shared_mutex}; + return applet_resource->RegisterCoreAppletResource(); +} + +Result ResourceManager::UnregisterCoreAppletResource() { + std::scoped_lock lock{shared_mutex}; + return applet_resource->UnregisterCoreAppletResource(); +} + Result ResourceManager::RegisterAppletResourceUserId(u64 aruid, bool bool_value) { std::scoped_lock lock{shared_mutex}; return applet_resource->RegisterAppletResourceUserId(aruid, bool_value); @@ -165,6 +191,11 @@ Result ResourceManager::GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle return applet_resource->GetSharedMemoryHandle(out_handle, aruid); } +void ResourceManager::FreeAppletResourceId(u64 aruid) { + std::scoped_lock lock{shared_mutex}; + applet_resource->FreeAppletResourceId(aruid); +} + void ResourceManager::EnableInput(u64 aruid, bool is_enabled) { std::scoped_lock lock{shared_mutex}; applet_resource->EnableInput(aruid, is_enabled); @@ -219,8 +250,10 @@ void ResourceManager::UpdateMotion(std::uintptr_t user_data, std::chrono::nanose console_six_axis->OnUpdate(core_timing); } -IAppletResource::IAppletResource(Core::System& system_, std::shared_ptr resource) - : ServiceFramework{system_, "IAppletResource"}, resource_manager{resource} { +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"}, }; @@ -274,14 +307,14 @@ IAppletResource::~IAppletResource() { system.CoreTiming().UnscheduleEvent(default_update_event, 0); system.CoreTiming().UnscheduleEvent(mouse_keyboard_update_event, 0); system.CoreTiming().UnscheduleEvent(motion_update_event, 0); + resource_manager->FreeAppletResourceId(aruid); } void IAppletResource::GetSharedMemoryHandle(HLERequestContext& ctx) { - LOG_DEBUG(Service_HID, "called"); - Kernel::KSharedMemory* handle; - const u64 applet_resource_user_id = resource_manager->GetAppletResource()->GetActiveAruid(); - const auto result = resource_manager->GetSharedMemoryHandle(&handle, applet_resource_user_id); + 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); diff --git a/src/core/hle/service/hid/resource_manager.h b/src/core/hle/service/hid/resource_manager.h index a78e2b729..15c1beb1a 100755 --- a/src/core/hle/service/hid/resource_manager.h +++ b/src/core/hle/service/hid/resource_manager.h @@ -66,10 +66,13 @@ public: Result CreateAppletResource(u64 aruid); + Result RegisterCoreAppletResource(); + Result UnregisterCoreAppletResource(); Result RegisterAppletResourceUserId(u64 aruid, bool bool_value); void UnregisterAppletResourceUserId(u64 aruid); Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid); + void FreeAppletResourceId(u64 aruid); void EnableInput(u64 aruid, bool is_enabled); void EnableSixAxisSensor(u64 aruid, bool is_enabled); @@ -82,6 +85,8 @@ public: void UpdateMotion(std::uintptr_t user_data, std::chrono::nanoseconds ns_late); private: + Result CreateAppletResourceImpl(u64 aruid); + bool is_initialized{false}; mutable std::mutex shared_mutex; @@ -121,7 +126,8 @@ private: class IAppletResource final : public ServiceFramework { public: - explicit IAppletResource(Core::System& system_, std::shared_ptr resource); + explicit IAppletResource(Core::System& system_, std::shared_ptr resource, + u64 applet_resource_user_id); ~IAppletResource() override; private: @@ -132,6 +138,7 @@ private: std::shared_ptr mouse_keyboard_update_event; std::shared_ptr motion_update_event; + u64 aruid; std::shared_ptr resource_manager; }; diff --git a/src/core/hle/service/nvnflinger/buffer_queue_consumer.cpp b/src/core/hle/service/nvnflinger/buffer_queue_consumer.cpp index 503768786..e38fc62bd 100755 --- a/src/core/hle/service/nvnflinger/buffer_queue_consumer.cpp +++ b/src/core/hle/service/nvnflinger/buffer_queue_consumer.cpp @@ -90,7 +90,7 @@ Status BufferQueueConsumer::AcquireBuffer(BufferItem* out_buffer, LOG_DEBUG(Service_Nvnflinger, "acquiring slot={}", slot); - if (core->StillTracking(*out_buffer)) { + if (core->StillTracking(*front)) { slots[slot].acquire_called = true; slots[slot].buffer_state = BufferState::Acquired; slots[slot].fence = Fence::NoFence(); diff --git a/src/core/hle/service/nvnflinger/nvnflinger.cpp b/src/core/hle/service/nvnflinger/nvnflinger.cpp index 0745434c5..6352b09a9 100755 --- a/src/core/hle/service/nvnflinger/nvnflinger.cpp +++ b/src/core/hle/service/nvnflinger/nvnflinger.cpp @@ -176,17 +176,37 @@ void Nvnflinger::CreateLayerAtId(VI::Display& display, u64 layer_id) { display.CreateLayer(layer_id, buffer_id, nvdrv->container); } +void Nvnflinger::OpenLayer(u64 layer_id) { + const auto lock_guard = Lock(); + + for (auto& display : displays) { + if (auto* layer = display.FindLayer(layer_id); layer) { + layer->Open(); + } + } +} + void Nvnflinger::CloseLayer(u64 layer_id) { const auto lock_guard = Lock(); for (auto& display : displays) { - display.CloseLayer(layer_id); + if (auto* layer = display.FindLayer(layer_id); layer) { + layer->Close(); + } + } +} + +void Nvnflinger::DestroyLayer(u64 layer_id) { + const auto lock_guard = Lock(); + + for (auto& display : displays) { + display.DestroyLayer(layer_id); } } std::optional Nvnflinger::FindBufferQueueId(u64 display_id, u64 layer_id) { const auto lock_guard = Lock(); - const auto* const layer = FindOrCreateLayer(display_id, layer_id); + const auto* const layer = FindLayer(display_id, layer_id); if (layer == nullptr) { return std::nullopt; @@ -240,24 +260,6 @@ VI::Layer* Nvnflinger::FindLayer(u64 display_id, u64 layer_id) { return display->FindLayer(layer_id); } -VI::Layer* Nvnflinger::FindOrCreateLayer(u64 display_id, u64 layer_id) { - auto* const display = FindDisplay(display_id); - - if (display == nullptr) { - return nullptr; - } - - auto* layer = display->FindLayer(layer_id); - - if (layer == nullptr) { - LOG_DEBUG(Service_Nvnflinger, "Layer at id {} not found. Trying to create it.", layer_id); - CreateLayerAtId(*display, layer_id); - return display->FindLayer(layer_id); - } - - return layer; -} - void Nvnflinger::Compose() { for (auto& display : displays) { // Trigger vsync for this display at the end of drawing diff --git a/src/core/hle/service/nvnflinger/nvnflinger.h b/src/core/hle/service/nvnflinger/nvnflinger.h index f5d73acdb..871285764 100755 --- a/src/core/hle/service/nvnflinger/nvnflinger.h +++ b/src/core/hle/service/nvnflinger/nvnflinger.h @@ -73,9 +73,15 @@ public: /// If an invalid display ID is specified, then an empty optional is returned. [[nodiscard]] std::optional CreateLayer(u64 display_id); + /// Opens a layer on all displays for the given layer ID. + void OpenLayer(u64 layer_id); + /// Closes a layer on all displays for the given layer ID. void CloseLayer(u64 layer_id); + /// Destroys the given layer ID. + void DestroyLayer(u64 layer_id); + /// Finds the buffer queue ID of the specified layer in the specified display. /// /// If an invalid display ID or layer ID is provided, then an empty optional is returned. @@ -117,11 +123,6 @@ private: /// Finds the layer identified by the specified ID in the desired display. [[nodiscard]] VI::Layer* FindLayer(u64 display_id, u64 layer_id); - /// Finds the layer identified by the specified ID in the desired display, - /// or creates the layer if it is not found. - /// To be used when the system expects the specified ID to already exist. - [[nodiscard]] VI::Layer* FindOrCreateLayer(u64 display_id, u64 layer_id); - /// Creates a layer with the specified layer ID in the desired display. void CreateLayerAtId(VI::Display& display, u64 layer_id); diff --git a/src/core/hle/service/sm/sm.cpp b/src/core/hle/service/sm/sm.cpp index 261639b32..6f39dba78 100755 --- a/src/core/hle/service/sm/sm.cpp +++ b/src/core/hle/service/sm/sm.cpp @@ -121,7 +121,7 @@ void SM::Initialize(HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void SM::GetService(HLERequestContext& ctx) { +void SM::GetServiceCmif(HLERequestContext& ctx) { Kernel::KClientSession* client_session{}; auto result = GetServiceImpl(&client_session, ctx); if (ctx.GetIsDeferred()) { @@ -196,13 +196,28 @@ Result SM::GetServiceImpl(Kernel::KClientSession** out_client_session, HLEReques return ResultSuccess; } -void SM::RegisterService(HLERequestContext& ctx) { +void SM::RegisterServiceCmif(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; std::string name(PopServiceName(rp)); const auto is_light = static_cast(rp.PopRaw()); const auto max_session_count = rp.PopRaw(); + this->RegisterServiceImpl(ctx, name, max_session_count, is_light); +} + +void SM::RegisterServiceTipc(HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + std::string name(PopServiceName(rp)); + + const auto max_session_count = rp.PopRaw(); + const auto is_light = static_cast(rp.PopRaw()); + + this->RegisterServiceImpl(ctx, name, max_session_count, is_light); +} + +void SM::RegisterServiceImpl(HLERequestContext& ctx, std::string name, u32 max_session_count, + bool is_light) { LOG_DEBUG(Service_SM, "called with name={}, max_session_count={}, is_light={}", name, max_session_count, is_light); @@ -238,15 +253,15 @@ SM::SM(ServiceManager& service_manager_, Core::System& system_) service_manager{service_manager_}, kernel{system_.Kernel()} { RegisterHandlers({ {0, &SM::Initialize, "Initialize"}, - {1, &SM::GetService, "GetService"}, - {2, &SM::RegisterService, "RegisterService"}, + {1, &SM::GetServiceCmif, "GetService"}, + {2, &SM::RegisterServiceCmif, "RegisterService"}, {3, &SM::UnregisterService, "UnregisterService"}, {4, nullptr, "DetachClient"}, }); RegisterHandlersTipc({ {0, &SM::Initialize, "Initialize"}, {1, &SM::GetServiceTipc, "GetService"}, - {2, &SM::RegisterService, "RegisterService"}, + {2, &SM::RegisterServiceTipc, "RegisterService"}, {3, &SM::UnregisterService, "UnregisterService"}, {4, nullptr, "DetachClient"}, }); diff --git a/src/core/hle/service/sm/sm.h b/src/core/hle/service/sm/sm.h index 7375bcfc0..e74fe3c94 100755 --- a/src/core/hle/service/sm/sm.h +++ b/src/core/hle/service/sm/sm.h @@ -37,12 +37,15 @@ public: private: void Initialize(HLERequestContext& ctx); - void GetService(HLERequestContext& ctx); + void GetServiceCmif(HLERequestContext& ctx); void GetServiceTipc(HLERequestContext& ctx); - void RegisterService(HLERequestContext& ctx); + void RegisterServiceCmif(HLERequestContext& ctx); + void RegisterServiceTipc(HLERequestContext& ctx); void UnregisterService(HLERequestContext& ctx); Result GetServiceImpl(Kernel::KClientSession** out_client_session, HLERequestContext& ctx); + void RegisterServiceImpl(HLERequestContext& ctx, std::string name, u32 max_session_count, + bool is_light); ServiceManager& service_manager; Kernel::KernelCore& kernel; diff --git a/src/core/hle/service/vi/display/vi_display.cpp b/src/core/hle/service/vi/display/vi_display.cpp index 54f738d2b..144ef2cc8 100755 --- a/src/core/hle/service/vi/display/vi_display.cpp +++ b/src/core/hle/service/vi/display/vi_display.cpp @@ -51,11 +51,24 @@ Display::~Display() { } Layer& Display::GetLayer(std::size_t index) { - return *layers.at(index); + size_t i = 0; + for (auto& layer : layers) { + if (!layer->IsOpen()) { + continue; + } + + if (i == index) { + return *layer; + } + + i++; + } + + UNREACHABLE(); } -const Layer& Display::GetLayer(std::size_t index) const { - return *layers.at(index); +size_t Display::GetNumLayers() const { + return std::ranges::count_if(layers, [](auto& l) { return l->IsOpen(); }); } Result Display::GetVSyncEvent(Kernel::KReadableEvent** out_vsync_event) { @@ -92,7 +105,11 @@ void Display::CreateLayer(u64 layer_id, u32 binder_id, hos_binder_driver_server.RegisterProducer(std::move(producer)); } -void Display::CloseLayer(u64 layer_id) { +void Display::DestroyLayer(u64 layer_id) { + if (auto* layer = this->FindLayer(layer_id); layer != nullptr) { + layer->GetConsumer().Abandon(); + } + std::erase_if(layers, [layer_id](const auto& layer) { return layer->GetLayerId() == layer_id; }); } diff --git a/src/core/hle/service/vi/display/vi_display.h b/src/core/hle/service/vi/display/vi_display.h index a9c5e655f..121ccba50 100755 --- a/src/core/hle/service/vi/display/vi_display.h +++ b/src/core/hle/service/vi/display/vi_display.h @@ -72,12 +72,7 @@ public: /// Gets a layer for this display based off an index. Layer& GetLayer(std::size_t index); - /// Gets a layer for this display based off an index. - const Layer& GetLayer(std::size_t index) const; - - std::size_t GetNumLayers() const { - return layers.size(); - } + std::size_t GetNumLayers() const; /** * Gets the internal vsync event. @@ -100,11 +95,11 @@ public: /// void CreateLayer(u64 layer_id, u32 binder_id, Service::Nvidia::NvCore::Container& core); - /// Closes and removes a layer from this display with the given ID. + /// Removes a layer from this display with the given ID. /// - /// @param layer_id The ID assigned to the layer to close. + /// @param layer_id The ID assigned to the layer to destroy. /// - void CloseLayer(u64 layer_id); + void DestroyLayer(u64 layer_id); /// Resets the display for a new connection. void Reset() { diff --git a/src/core/hle/service/vi/layer/vi_layer.cpp b/src/core/hle/service/vi/layer/vi_layer.cpp index d75aeb392..2947e74ed 100755 --- a/src/core/hle/service/vi/layer/vi_layer.cpp +++ b/src/core/hle/service/vi/layer/vi_layer.cpp @@ -8,8 +8,8 @@ namespace Service::VI { Layer::Layer(u64 layer_id_, u32 binder_id_, android::BufferQueueCore& core_, android::BufferQueueProducer& binder_, std::shared_ptr&& consumer_) - : layer_id{layer_id_}, binder_id{binder_id_}, core{core_}, binder{binder_}, consumer{std::move( - consumer_)} {} + : layer_id{layer_id_}, binder_id{binder_id_}, core{core_}, binder{binder_}, + consumer{std::move(consumer_)}, open{false} {} Layer::~Layer() = default; diff --git a/src/core/hle/service/vi/layer/vi_layer.h b/src/core/hle/service/vi/layer/vi_layer.h index 755c0b333..c4582cdc1 100755 --- a/src/core/hle/service/vi/layer/vi_layer.h +++ b/src/core/hle/service/vi/layer/vi_layer.h @@ -71,12 +71,25 @@ public: return core; } + bool IsOpen() const { + return open; + } + + void Close() { + open = false; + } + + void Open() { + open = true; + } + private: const u64 layer_id; const u32 binder_id; android::BufferQueueCore& core; android::BufferQueueProducer& binder; std::shared_ptr consumer; + bool open; }; } // namespace Service::VI diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index 231fd4e0d..7c58c184e 100755 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp @@ -719,6 +719,8 @@ private: return; } + nv_flinger.OpenLayer(layer_id); + android::OutputParcel parcel; parcel.WriteInterface(NativeWindow{*buffer_queue_id}); @@ -783,6 +785,7 @@ private: const u64 layer_id = rp.Pop(); LOG_WARNING(Service_VI, "(STUBBED) called. layer_id=0x{:016X}", layer_id); + nv_flinger.DestroyLayer(layer_id); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); diff --git a/src/yuzu/applets/qt_profile_select.cpp b/src/yuzu/applets/qt_profile_select.cpp index 68496866d..75ddb4924 100755 --- a/src/yuzu/applets/qt_profile_select.cpp +++ b/src/yuzu/applets/qt_profile_select.cpp @@ -14,6 +14,8 @@ #include "common/fs/path_util.h" #include "common/string_util.h" #include "core/constants.h" +#include "core/core.h" +#include "core/hle/service/acc/profile_manager.h" #include "yuzu/applets/qt_profile_select.h" #include "yuzu/main.h" #include "yuzu/util/controller_navigation.h" @@ -47,9 +49,9 @@ QPixmap GetIcon(Common::UUID uuid) { } // Anonymous namespace QtProfileSelectionDialog::QtProfileSelectionDialog( - Core::HID::HIDCore& hid_core, QWidget* parent, + Core::System& system, QWidget* parent, const Core::Frontend::ProfileSelectParameters& parameters) - : QDialog(parent), profile_manager(std::make_unique()) { + : QDialog(parent), profile_manager{system.GetProfileManager()} { outer_layout = new QVBoxLayout; instruction_label = new QLabel(); @@ -68,7 +70,7 @@ QtProfileSelectionDialog::QtProfileSelectionDialog( tree_view = new QTreeView; item_model = new QStandardItemModel(tree_view); tree_view->setModel(item_model); - controller_navigation = new ControllerNavigation(hid_core, this); + controller_navigation = new ControllerNavigation(system.HIDCore(), this); tree_view->setAlternatingRowColors(true); tree_view->setSelectionMode(QHeaderView::SingleSelection); @@ -106,10 +108,10 @@ QtProfileSelectionDialog::QtProfileSelectionDialog( SelectUser(tree_view->currentIndex()); }); - const auto& profiles = profile_manager->GetAllUsers(); + const auto& profiles = profile_manager.GetAllUsers(); for (const auto& user : profiles) { Service::Account::ProfileBase profile{}; - if (!profile_manager->GetProfileBase(user, profile)) + if (!profile_manager.GetProfileBase(user, profile)) continue; const auto username = Common::StringFromFixedZeroTerminatedBuffer( @@ -134,7 +136,7 @@ QtProfileSelectionDialog::~QtProfileSelectionDialog() { int QtProfileSelectionDialog::exec() { // Skip profile selection when there's only one. - if (profile_manager->GetUserCount() == 1) { + if (profile_manager.GetUserCount() == 1) { user_index = 0; return QDialog::Accepted; } diff --git a/src/yuzu/applets/qt_profile_select.h b/src/yuzu/applets/qt_profile_select.h index c3222e408..05af58758 100755 --- a/src/yuzu/applets/qt_profile_select.h +++ b/src/yuzu/applets/qt_profile_select.h @@ -7,7 +7,6 @@ #include #include #include "core/frontend/applets/profile_select.h" -#include "core/hle/service/acc/profile_manager.h" class ControllerNavigation; class GMainWindow; @@ -20,15 +19,19 @@ class QStandardItemModel; class QTreeView; class QVBoxLayout; -namespace Core::HID { -class HIDCore; -} // namespace Core::HID +namespace Core { +class System; +} + +namespace Service::Account { +class ProfileManager; +} class QtProfileSelectionDialog final : public QDialog { Q_OBJECT public: - explicit QtProfileSelectionDialog(Core::HID::HIDCore& hid_core, QWidget* parent, + explicit QtProfileSelectionDialog(Core::System& system, QWidget* parent, const Core::Frontend::ProfileSelectParameters& parameters); ~QtProfileSelectionDialog() override; @@ -58,7 +61,7 @@ private: QScrollArea* scroll_area; QDialogButtonBox* buttons; - std::unique_ptr profile_manager; + Service::Account::ProfileManager& profile_manager; ControllerNavigation* controller_navigation = nullptr; }; diff --git a/src/yuzu/configuration/configure_profile_manager.cpp b/src/yuzu/configuration/configure_profile_manager.cpp index 2acf17093..fff30525c 100755 --- a/src/yuzu/configuration/configure_profile_manager.cpp +++ b/src/yuzu/configuration/configure_profile_manager.cpp @@ -76,9 +76,9 @@ QString GetProfileUsernameFromUser(QWidget* parent, const QString& description_t } } // Anonymous namespace -ConfigureProfileManager::ConfigureProfileManager(const Core::System& system_, QWidget* parent) +ConfigureProfileManager::ConfigureProfileManager(Core::System& system_, QWidget* parent) : QWidget(parent), ui{std::make_unique()}, - profile_manager(std::make_unique()), system{system_} { + profile_manager{system_.GetProfileManager()}, system{system_} { ui->setupUi(this); tree_view = new QTreeView; @@ -149,10 +149,10 @@ void ConfigureProfileManager::SetConfiguration() { } void ConfigureProfileManager::PopulateUserList() { - const auto& profiles = profile_manager->GetAllUsers(); + const auto& profiles = profile_manager.GetAllUsers(); for (const auto& user : profiles) { Service::Account::ProfileBase profile{}; - if (!profile_manager->GetProfileBase(user, profile)) + if (!profile_manager.GetProfileBase(user, profile)) continue; const auto username = Common::StringFromFixedZeroTerminatedBuffer( @@ -167,11 +167,11 @@ void ConfigureProfileManager::PopulateUserList() { } void ConfigureProfileManager::UpdateCurrentUser() { - ui->pm_add->setEnabled(profile_manager->GetUserCount() < Service::Account::MAX_USERS); + ui->pm_add->setEnabled(profile_manager.GetUserCount() < Service::Account::MAX_USERS); - const auto& current_user = profile_manager->GetUser(Settings::values.current_user.GetValue()); + const auto& current_user = profile_manager.GetUser(Settings::values.current_user.GetValue()); ASSERT(current_user); - const auto username = GetAccountUsername(*profile_manager, *current_user); + const auto username = GetAccountUsername(profile_manager, *current_user); scene->clear(); scene->addPixmap( @@ -187,11 +187,11 @@ void ConfigureProfileManager::ApplyConfiguration() { void ConfigureProfileManager::SelectUser(const QModelIndex& index) { Settings::values.current_user = - std::clamp(index.row(), 0, static_cast(profile_manager->GetUserCount() - 1)); + std::clamp(index.row(), 0, static_cast(profile_manager.GetUserCount() - 1)); UpdateCurrentUser(); - ui->pm_remove->setEnabled(profile_manager->GetUserCount() >= 2); + ui->pm_remove->setEnabled(profile_manager.GetUserCount() >= 2); ui->pm_rename->setEnabled(true); ui->pm_set_image->setEnabled(true); } @@ -204,18 +204,18 @@ void ConfigureProfileManager::AddUser() { } const auto uuid = Common::UUID::MakeRandom(); - profile_manager->CreateNewUser(uuid, username.toStdString()); + profile_manager.CreateNewUser(uuid, username.toStdString()); item_model->appendRow(new QStandardItem{GetIcon(uuid), FormatUserEntryText(username, uuid)}); } void ConfigureProfileManager::RenameUser() { const auto user = tree_view->currentIndex().row(); - const auto uuid = profile_manager->GetUser(user); + const auto uuid = profile_manager.GetUser(user); ASSERT(uuid); Service::Account::ProfileBase profile{}; - if (!profile_manager->GetProfileBase(*uuid, profile)) + if (!profile_manager.GetProfileBase(*uuid, profile)) return; const auto new_username = GetProfileUsernameFromUser(this, tr("Enter a new username:")); @@ -227,7 +227,7 @@ void ConfigureProfileManager::RenameUser() { std::fill(profile.username.begin(), profile.username.end(), '\0'); std::copy(username_std.begin(), username_std.end(), profile.username.begin()); - profile_manager->SetProfileBase(*uuid, profile); + profile_manager.SetProfileBase(*uuid, profile); item_model->setItem( user, 0, @@ -238,9 +238,9 @@ void ConfigureProfileManager::RenameUser() { void ConfigureProfileManager::ConfirmDeleteUser() { const auto index = tree_view->currentIndex().row(); - const auto uuid = profile_manager->GetUser(index); + const auto uuid = profile_manager.GetUser(index); ASSERT(uuid); - const auto username = GetAccountUsername(*profile_manager, *uuid); + const auto username = GetAccountUsername(profile_manager, *uuid); confirm_dialog->SetInfo(username, *uuid, [this, uuid]() { DeleteUser(*uuid); }); confirm_dialog->show(); @@ -252,7 +252,7 @@ void ConfigureProfileManager::DeleteUser(const Common::UUID& uuid) { } UpdateCurrentUser(); - if (!profile_manager->RemoveUser(uuid)) { + if (!profile_manager.RemoveUser(uuid)) { return; } @@ -265,7 +265,7 @@ void ConfigureProfileManager::DeleteUser(const Common::UUID& uuid) { void ConfigureProfileManager::SetUserImage() { const auto index = tree_view->currentIndex().row(); - const auto uuid = profile_manager->GetUser(index); + const auto uuid = profile_manager.GetUser(index); ASSERT(uuid); const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(), @@ -317,7 +317,7 @@ void ConfigureProfileManager::SetUserImage() { } } - const auto username = GetAccountUsername(*profile_manager, *uuid); + const auto username = GetAccountUsername(profile_manager, *uuid); item_model->setItem(index, 0, new QStandardItem{GetIcon(*uuid), FormatUserEntryText(username, *uuid)}); UpdateCurrentUser(); diff --git a/src/yuzu/configuration/configure_profile_manager.h b/src/yuzu/configuration/configure_profile_manager.h index db4ccaa4d..4b118338e 100755 --- a/src/yuzu/configuration/configure_profile_manager.h +++ b/src/yuzu/configuration/configure_profile_manager.h @@ -52,7 +52,7 @@ class ConfigureProfileManager : public QWidget { Q_OBJECT public: - explicit ConfigureProfileManager(const Core::System& system_, QWidget* parent = nullptr); + explicit ConfigureProfileManager(Core::System& system_, QWidget* parent = nullptr); ~ConfigureProfileManager() override; void ApplyConfiguration(); @@ -85,7 +85,6 @@ private: std::unique_ptr ui; bool enabled = false; - std::unique_ptr profile_manager; - + Service::Account::ProfileManager& profile_manager; const Core::System& system; }; diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 03533d707..cb3491885 100755 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -346,7 +346,7 @@ GMainWindow::GMainWindow(std::unique_ptr config_, bool has_broken_vulk SetDiscordEnabled(UISettings::values.enable_discord_presence.GetValue()); discord_rpc->Update(); - play_time_manager = std::make_unique(); + play_time_manager = std::make_unique(system->GetProfileManager()); system->GetRoomNetwork().Init(); @@ -526,8 +526,7 @@ GMainWindow::GMainWindow(std::unique_ptr config_, bool has_broken_vulk continue; } - const Service::Account::ProfileManager manager; - if (!manager.UserExistsIndex(selected_user)) { + if (!system->GetProfileManager().UserExistsIndex(selected_user)) { LOG_ERROR(Frontend, "Selected user doesn't exist"); continue; } @@ -691,7 +690,7 @@ void GMainWindow::ControllerSelectorRequestExit() { void GMainWindow::ProfileSelectorSelectProfile( const Core::Frontend::ProfileSelectParameters& parameters) { - profile_select_applet = new QtProfileSelectionDialog(system->HIDCore(), this, parameters); + profile_select_applet = new QtProfileSelectionDialog(*system, this, parameters); SCOPE_EXIT({ profile_select_applet->deleteLater(); profile_select_applet = nullptr; @@ -706,8 +705,8 @@ void GMainWindow::ProfileSelectorSelectProfile( return; } - const Service::Account::ProfileManager manager; - const auto uuid = manager.GetUser(static_cast(profile_select_applet->GetIndex())); + const auto uuid = system->GetProfileManager().GetUser( + static_cast(profile_select_applet->GetIndex())); if (!uuid.has_value()) { emit ProfileSelectorFinishedSelection(std::nullopt); return; @@ -1856,7 +1855,7 @@ bool GMainWindow::LoadROM(const QString& filename, u64 program_id, std::size_t p bool GMainWindow::SelectAndSetCurrentUser( const Core::Frontend::ProfileSelectParameters& parameters) { - QtProfileSelectionDialog dialog(system->HIDCore(), this, parameters); + QtProfileSelectionDialog dialog(*system, this, parameters); dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); dialog.setWindowModality(Qt::WindowModal); @@ -2271,7 +2270,7 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target .display_options = {}, .purpose = Service::AM::Applets::UserSelectionPurpose::General, }; - QtProfileSelectionDialog dialog(system->HIDCore(), this, parameters); + QtProfileSelectionDialog dialog(*system, this, parameters); dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); dialog.setWindowModality(Qt::WindowModal); @@ -2288,8 +2287,8 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target return; } - Service::Account::ProfileManager manager; - const auto user_id = manager.GetUser(static_cast(index)); + const auto user_id = + system->GetProfileManager().GetUser(static_cast(index)); ASSERT(user_id); const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath( diff --git a/src/yuzu/multiplayer/lobby.cpp b/src/yuzu/multiplayer/lobby.cpp index 040cde438..65865ec3d 100755 --- a/src/yuzu/multiplayer/lobby.cpp +++ b/src/yuzu/multiplayer/lobby.cpp @@ -27,9 +27,9 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list, std::shared_ptr session, Core::System& system_) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint), - ui(std::make_unique()), announce_multiplayer_session(session), - profile_manager(std::make_unique()), system{system_}, - room_network{system.GetRoomNetwork()} { + ui(std::make_unique()), + announce_multiplayer_session(session), system{system_}, room_network{ + system.GetRoomNetwork()} { ui->setupUi(this); // setup the watcher for background connections @@ -299,14 +299,15 @@ void Lobby::OnRefreshLobby() { } std::string Lobby::GetProfileUsername() { - const auto& current_user = profile_manager->GetUser(Settings::values.current_user.GetValue()); + const auto& current_user = + system.GetProfileManager().GetUser(Settings::values.current_user.GetValue()); Service::Account::ProfileBase profile{}; if (!current_user.has_value()) { return ""; } - if (!profile_manager->GetProfileBase(*current_user, profile)) { + if (!system.GetProfileManager().GetProfileBase(*current_user, profile)) { return ""; } diff --git a/src/yuzu/multiplayer/lobby.h b/src/yuzu/multiplayer/lobby.h index ae9e2b66b..5d984b94c 100755 --- a/src/yuzu/multiplayer/lobby.h +++ b/src/yuzu/multiplayer/lobby.h @@ -24,10 +24,6 @@ namespace Core { class System; } -namespace Service::Account { -class ProfileManager; -} - /** * Listing of all public games pulled from services. The lobby should be simple enough for users to * find the game they want to play, and join it. @@ -103,7 +99,6 @@ private: QFutureWatcher room_list_watcher; std::weak_ptr announce_multiplayer_session; - std::unique_ptr profile_manager; QFutureWatcher* watcher; Validation validation; Core::System& system; diff --git a/src/yuzu/play_time_manager.cpp b/src/yuzu/play_time_manager.cpp index 155c36b7d..94c99274d 100755 --- a/src/yuzu/play_time_manager.cpp +++ b/src/yuzu/play_time_manager.cpp @@ -20,8 +20,8 @@ struct PlayTimeElement { PlayTime play_time; }; -std::optional GetCurrentUserPlayTimePath() { - const Service::Account::ProfileManager manager; +std::optional GetCurrentUserPlayTimePath( + const Service::Account::ProfileManager& manager) { const auto uuid = manager.GetUser(static_cast(Settings::values.current_user)); if (!uuid.has_value()) { return std::nullopt; @@ -30,8 +30,9 @@ std::optional GetCurrentUserPlayTimePath() { uuid->RawString().append(".bin"); } -[[nodiscard]] bool ReadPlayTimeFile(PlayTimeDatabase& out_play_time_db) { - const auto filename = GetCurrentUserPlayTimePath(); +[[nodiscard]] bool ReadPlayTimeFile(PlayTimeDatabase& out_play_time_db, + const Service::Account::ProfileManager& manager) { + const auto filename = GetCurrentUserPlayTimePath(manager); if (!filename.has_value()) { LOG_ERROR(Frontend, "Failed to get current user path"); @@ -66,8 +67,9 @@ std::optional GetCurrentUserPlayTimePath() { return true; } -[[nodiscard]] bool WritePlayTimeFile(const PlayTimeDatabase& play_time_db) { - const auto filename = GetCurrentUserPlayTimePath(); +[[nodiscard]] bool WritePlayTimeFile(const PlayTimeDatabase& play_time_db, + const Service::Account::ProfileManager& manager) { + const auto filename = GetCurrentUserPlayTimePath(manager); if (!filename.has_value()) { LOG_ERROR(Frontend, "Failed to get current user path"); @@ -96,8 +98,9 @@ std::optional GetCurrentUserPlayTimePath() { } // namespace -PlayTimeManager::PlayTimeManager() { - if (!ReadPlayTimeFile(database)) { +PlayTimeManager::PlayTimeManager(Service::Account::ProfileManager& profile_manager) + : manager{profile_manager} { + if (!ReadPlayTimeFile(database, manager)) { LOG_ERROR(Frontend, "Failed to read play time database! Resetting to default."); } } @@ -142,7 +145,7 @@ void PlayTimeManager::AutoTimestamp(std::stop_token stop_token) { } void PlayTimeManager::Save() { - if (!WritePlayTimeFile(database)) { + if (!WritePlayTimeFile(database, manager)) { LOG_ERROR(Frontend, "Failed to update play time database!"); } } diff --git a/src/yuzu/play_time_manager.h b/src/yuzu/play_time_manager.h index 5f96f3447..1714b9131 100755 --- a/src/yuzu/play_time_manager.h +++ b/src/yuzu/play_time_manager.h @@ -11,6 +11,10 @@ #include "common/common_types.h" #include "common/polyfill_thread.h" +namespace Service::Account { +class ProfileManager; +} + namespace PlayTime { using ProgramId = u64; @@ -19,7 +23,7 @@ using PlayTimeDatabase = std::map; class PlayTimeManager { public: - explicit PlayTimeManager(); + explicit PlayTimeManager(Service::Account::ProfileManager& profile_manager); ~PlayTimeManager(); YUZU_NON_COPYABLE(PlayTimeManager); @@ -32,11 +36,13 @@ public: void Stop(); private: + void AutoTimestamp(std::stop_token stop_token); + void Save(); + PlayTimeDatabase database; u64 running_program_id; std::jthread play_time_thread; - void AutoTimestamp(std::stop_token stop_token); - void Save(); + Service::Account::ProfileManager& manager; }; QString ReadablePlayTime(qulonglong time_seconds);