From b00a321b5e671007af936572223db3da374cbbf5 Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Sun, 1 Dec 2024 04:12:04 -0800 Subject: [PATCH] playgo: Fix loading PlayGo file. (#1639) --- src/core/file_format/playgo_chunk.h | 1 - src/core/libraries/playgo/playgo.cpp | 55 ++++++++++++++++------------ src/emulator.cpp | 7 ---- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/core/file_format/playgo_chunk.h b/src/core/file_format/playgo_chunk.h index 2a234f5f..12d8f022 100644 --- a/src/core/file_format/playgo_chunk.h +++ b/src/core/file_format/playgo_chunk.h @@ -97,7 +97,6 @@ struct PlaygoChunk { class PlaygoFile { public: - bool initialized = false; OrbisPlayGoHandle handle = 0; OrbisPlayGoChunkId id = 0; OrbisPlayGoLocus locus = OrbisPlayGoLocus::NotDownloaded; diff --git a/src/core/libraries/playgo/playgo.cpp b/src/core/libraries/playgo/playgo.cpp index 6fcf875d..13d6f991 100644 --- a/src/core/libraries/playgo/playgo.cpp +++ b/src/core/libraries/playgo/playgo.cpp @@ -2,7 +2,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/logging/log.h" +#include "common/singleton.h" #include "core/file_format/playgo_chunk.h" +#include "core/file_sys/fs.h" #include "core/libraries/error_codes.h" #include "core/libraries/libs.h" #include "core/libraries/system/systemservice.h" @@ -29,10 +31,9 @@ s32 PS4_SYSV_ABI scePlayGoClose(OrbisPlayGoHandle handle) { if (handle != PlaygoHandle) { return ORBIS_PLAYGO_ERROR_BAD_HANDLE; } - if (!playgo->initialized) { + if (!playgo) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; } - playgo.reset(); return ORBIS_OK; } @@ -98,7 +99,7 @@ s32 PS4_SYSV_ABI scePlayGoGetInstallSpeed(OrbisPlayGoHandle handle, if (outSpeed == nullptr) { return ORBIS_PLAYGO_ERROR_BAD_POINTER; } - if (!playgo->initialized) { + if (!playgo) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; } @@ -126,7 +127,7 @@ s32 PS4_SYSV_ABI scePlayGoGetLanguageMask(OrbisPlayGoHandle handle, if (outLanguageMask == nullptr) { return ORBIS_PLAYGO_ERROR_BAD_POINTER; } - if (!playgo->initialized) { + if (!playgo) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; } @@ -148,7 +149,7 @@ s32 PS4_SYSV_ABI scePlayGoGetLocus(OrbisPlayGoHandle handle, const OrbisPlayGoCh if (numberOfEntries == 0) { return ORBIS_PLAYGO_ERROR_BAD_SIZE; } - if (!playgo->initialized) { + if (!playgo) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; } if (playgo->GetPlaygoHeader().file_size == 0) { @@ -180,7 +181,7 @@ s32 PS4_SYSV_ABI scePlayGoGetProgress(OrbisPlayGoHandle handle, const OrbisPlayG if (numberOfEntries == 0) { return ORBIS_PLAYGO_ERROR_BAD_SIZE; } - if (!playgo->initialized) { + if (!playgo) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; } if (playgo->GetPlaygoHeader().file_size == 0) { @@ -219,7 +220,7 @@ s32 PS4_SYSV_ABI scePlayGoGetToDoList(OrbisPlayGoHandle handle, OrbisPlayGoToDo* if (numberOfEntries == 0) { return ORBIS_PLAYGO_ERROR_BAD_SIZE; } - if (!playgo->initialized) { + if (!playgo) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; } *outEntries = 0; // nothing to do @@ -242,17 +243,24 @@ s32 PS4_SYSV_ABI scePlayGoInitialize(OrbisPlayGoInitParams* param) { if (param->bufSize < 0x200000) { return ORBIS_PLAYGO_ERROR_BAD_SIZE; } - - playgo = std::make_unique(); - if (!playgo->initialized) { - using namespace SystemService; - s32 system_lang = 0; - sceSystemServiceParamGetInt(OrbisSystemServiceParamId::Lang, &system_lang); - playgo->langMask = scePlayGoConvertLanguage(system_lang); - playgo->initialized = true; - } else { + if (playgo) { return ORBIS_PLAYGO_ERROR_ALREADY_INITIALIZED; } + + using namespace SystemService; + + playgo = std::make_unique(); + + auto* mnt = Common::Singleton::Instance(); + const auto file_path = mnt->GetHostPath("/app0/sce_sys/playgo-chunk.dat"); + if (!playgo->Open(file_path)) { + LOG_WARNING(Lib_PlayGo, "Could not open PlayGo file"); + } + + s32 system_lang = 0; + sceSystemServiceParamGetInt(OrbisSystemServiceParamId::Lang, &system_lang); + playgo->langMask = scePlayGoConvertLanguage(system_lang); + return ORBIS_OK; } @@ -265,7 +273,7 @@ s32 PS4_SYSV_ABI scePlayGoOpen(OrbisPlayGoHandle* outHandle, const void* param) if (param) { return ORBIS_PLAYGO_ERROR_INVALID_ARGUMENT; } - if (!playgo->initialized) { + if (!playgo) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; } if (playgo->GetPlaygoHeader().file_size == 0) { @@ -289,7 +297,7 @@ s32 PS4_SYSV_ABI scePlayGoPrefetch(OrbisPlayGoHandle handle, const OrbisPlayGoCh if (numberOfEntries == 0) { return ORBIS_PLAYGO_ERROR_BAD_SIZE; } - if (!playgo->initialized) { + if (!playgo) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; } @@ -310,7 +318,7 @@ s32 PS4_SYSV_ABI scePlayGoSetInstallSpeed(OrbisPlayGoHandle handle, OrbisPlayGoI if (handle != PlaygoHandle) { return ORBIS_PLAYGO_ERROR_BAD_HANDLE; } - if (!playgo->initialized) { + if (!playgo) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; } @@ -339,7 +347,7 @@ s32 PS4_SYSV_ABI scePlayGoSetLanguageMask(OrbisPlayGoHandle handle, if (handle != 1) { return ORBIS_PLAYGO_ERROR_BAD_HANDLE; } - if (!playgo->initialized) { + if (!playgo) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; } @@ -360,7 +368,7 @@ s32 PS4_SYSV_ABI scePlayGoSetToDoList(OrbisPlayGoHandle handle, const OrbisPlayG if (numberOfEntries == 0) { return ORBIS_PLAYGO_ERROR_BAD_SIZE; } - if (!playgo->initialized) { + if (!playgo) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; } return ORBIS_OK; @@ -369,11 +377,10 @@ s32 PS4_SYSV_ABI scePlayGoSetToDoList(OrbisPlayGoHandle handle, const OrbisPlayG s32 PS4_SYSV_ABI scePlayGoTerminate() { LOG_INFO(Lib_PlayGo, "called"); - if (playgo->initialized) { - playgo->initialized = false; - } else { + if (!playgo) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; } + playgo.reset(); return ORBIS_OK; } diff --git a/src/emulator.cpp b/src/emulator.cpp index 4ab535a2..1d2542d2 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -22,7 +22,6 @@ #include "common/scm_rev.h" #include "common/singleton.h" #include "common/version.h" -#include "core/file_format/playgo_chunk.h" #include "core/file_format/psf.h" #include "core/file_format/splash.h" #include "core/file_format/trp.h" @@ -157,12 +156,6 @@ void Emulator::Run(const std::filesystem::path& file) { fw_version = param_sfo->GetInteger("SYSTEM_VER").value_or(0x4700000); app_version = param_sfo->GetString("APP_VER").value_or("Unknown version"); LOG_INFO(Loader, "Fw: {:#x} App Version: {}", fw_version, app_version); - } else if (entry.path().filename() == "playgo-chunk.dat") { - auto* playgo = Common::Singleton::Instance(); - auto filepath = sce_sys_folder / "playgo-chunk.dat"; - if (!playgo->Open(filepath)) { - LOG_ERROR(Loader, "PlayGo: unable to open file"); - } } else if (entry.path().filename() == "pic1.png") { auto* splash = Common::Singleton::Instance(); if (splash->IsLoaded()) {