From 3155f4e96d10904f4a207e465f20fb4b25043f5c Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 2 Jan 2024 18:26:53 -0500 Subject: am: retrieve main applet creation info from frontend --- src/core/core.cpp | 49 ++++++++++++++++++++++++++++++------------------- src/core/core.h | 9 +++++++-- 2 files changed, 37 insertions(+), 21 deletions(-) (limited to 'src/core') diff --git a/src/core/core.cpp b/src/core/core.cpp index 2bf377b24..8c04685a5 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -36,6 +36,7 @@ #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/applet_manager.h" #include "core/hle/service/am/frontend/applets.h" #include "core/hle/service/apm/apm_controller.h" #include "core/hle/service/filesystem/filesystem.h" @@ -136,7 +137,7 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, struct System::Impl { explicit Impl(System& system) : kernel{system}, fs_controller{system}, hid_core{}, room_network{}, cpu_manager{system}, - reporter{system}, frontend_applets{system}, profile_manager{} {} + reporter{system}, applet_manager{system}, frontend_applets{system}, profile_manager{} {} void Initialize(System& system) { device_memory = std::make_unique(); @@ -330,16 +331,27 @@ struct System::Impl { } SystemResultStatus Load(System& system, Frontend::EmuWindow& emu_window, - const std::string& filepath, u64 program_id, - std::size_t program_index) { + const std::string& filepath, + Service::AM::FrontendAppletParameters& params) { app_loader = Loader::GetLoader(system, GetGameFileFromPath(virtual_filesystem, filepath), - program_id, program_index); + params.program_id, params.program_index); if (!app_loader) { LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath); return SystemResultStatus::ErrorGetLoader; } + if (app_loader->ReadProgramId(params.program_id) != Loader::ResultStatus::Success) { + LOG_ERROR(Core, "Failed to find title id for ROM!"); + } + + std::string name = "Unknown program"; + if (app_loader->ReadTitle(name) != Loader::ResultStatus::Success) { + LOG_ERROR(Core, "Failed to read title for ROM!"); + } + + LOG_INFO(Core, "Loading {} ({})", name, params.program_id); + InitializeKernel(system); // Create the application process. @@ -373,6 +385,10 @@ struct System::Impl { cheat_engine->Initialize(); } + // Register with applet manager. + 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); @@ -386,21 +402,13 @@ struct System::Impl { } } - if (app_loader->ReadProgramId(program_id) != Loader::ResultStatus::Success) { - LOG_ERROR(Core, "Failed to find title id for ROM (Error {})", load_result); - } - perf_stats = std::make_unique(program_id); + perf_stats = std::make_unique(params.program_id); // Reset counters and set time origin to current frame GetAndResetPerfStats(); perf_stats->BeginSystemFrame(); - std::string name = "Unknown Game"; - if (app_loader->ReadTitle(name) != Loader::ResultStatus::Success) { - LOG_ERROR(Core, "Failed to read title for ROM (Error {})", load_result); - } - std::string title_version; - const FileSys::PatchManager pm(program_id, system.GetFileSystemController(), + const FileSys::PatchManager pm(params.program_id, system.GetFileSystemController(), system.GetContentProvider()); const auto metadata = pm.GetControlMetadata(); if (metadata.first != nullptr) { @@ -409,14 +417,15 @@ struct System::Impl { if (auto room_member = room_network.GetRoomMember().lock()) { Network::GameInfo game_info; game_info.name = name; - game_info.id = program_id; + game_info.id = params.program_id; game_info.version = title_version; room_member->SendGameInfo(game_info); } // Workarounds: // Activate this in Super Smash Brothers Ultimate, it only affects AMD cards using AMDVLK - Settings::values.renderer_amdvlk_depth_bias_workaround = program_id == 0x1006A800016E000ULL; + Settings::values.renderer_amdvlk_depth_bias_workaround = + params.program_id == 0x1006A800016E000ULL; status = SystemResultStatus::Success; return status; @@ -455,6 +464,7 @@ struct System::Impl { } kernel.CloseServices(); kernel.ShutdownCores(); + applet_manager.Reset(); services.reset(); service_manager.reset(); fs_controller.Reset(); @@ -566,7 +576,8 @@ struct System::Impl { std::unique_ptr renderdoc_api; - /// Frontend applets + /// Applets + Service::AM::AppletManager applet_manager; Service::AM::Frontend::FrontendAppletHolder frontend_applets; /// APM (Performance) services @@ -680,8 +691,8 @@ void System::InitializeDebugger() { } SystemResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::string& filepath, - u64 program_id, std::size_t program_index) { - return impl->Load(*this, emu_window, filepath, program_id, program_index); + Service::AM::FrontendAppletParameters& params) { + return impl->Load(*this, emu_window, filepath, params); } bool System::IsPoweredOn() const { diff --git a/src/core/core.h b/src/core/core.h index 800e69501..97e2d4b50 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -50,6 +50,11 @@ namespace Account { class ProfileManager; } // namespace Account +namespace AM { +struct FrontendAppletParameters; +class AppletManager; +} // namespace AM + namespace AM::Frontend { struct FrontendAppletSet; class FrontendAppletHolder; @@ -203,8 +208,8 @@ public: * @returns SystemResultStatus code, indicating if the operation succeeded. */ [[nodiscard]] SystemResultStatus Load(Frontend::EmuWindow& emu_window, - const std::string& filepath, u64 program_id = 0, - std::size_t program_index = 0); + const std::string& filepath, + Service::AM::FrontendAppletParameters& params); /** * Indicates if the emulated system is powered on (all subsystems initialized and able to run an -- cgit v1.2.3