mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-05-24 20:35:01 +00:00
emulator: Fix log initialization order. (#2878)
Some checks are pending
Build and Release / linux-sdl-gcc (push) Blocked by required conditions
Build and Release / reuse (push) Waiting to run
Build and Release / clang-format (push) Waiting to run
Build and Release / get-info (push) Waiting to run
Build and Release / windows-sdl (push) Blocked by required conditions
Build and Release / windows-qt (push) Blocked by required conditions
Build and Release / macos-sdl (push) Blocked by required conditions
Build and Release / macos-qt (push) Blocked by required conditions
Build and Release / linux-sdl (push) Blocked by required conditions
Build and Release / linux-qt (push) Blocked by required conditions
Build and Release / linux-qt-gcc (push) Blocked by required conditions
Build and Release / pre-release (push) Blocked by required conditions
Some checks are pending
Build and Release / linux-sdl-gcc (push) Blocked by required conditions
Build and Release / reuse (push) Waiting to run
Build and Release / clang-format (push) Waiting to run
Build and Release / get-info (push) Waiting to run
Build and Release / windows-sdl (push) Blocked by required conditions
Build and Release / windows-qt (push) Blocked by required conditions
Build and Release / macos-sdl (push) Blocked by required conditions
Build and Release / macos-qt (push) Blocked by required conditions
Build and Release / linux-sdl (push) Blocked by required conditions
Build and Release / linux-qt (push) Blocked by required conditions
Build and Release / linux-qt-gcc (push) Blocked by required conditions
Build and Release / pre-release (push) Blocked by required conditions
This commit is contained in:
parent
d542d952f4
commit
17b6343f18
1 changed files with 95 additions and 89 deletions
184
src/emulator.cpp
184
src/emulator.cpp
|
@ -10,7 +10,6 @@
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#ifdef ENABLE_QT_GUI
|
#ifdef ENABLE_QT_GUI
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
#include "common/memory_patcher.h"
|
|
||||||
#endif
|
#endif
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#ifdef ENABLE_DISCORD_RPC
|
#ifdef ENABLE_DISCORD_RPC
|
||||||
|
@ -20,6 +19,7 @@
|
||||||
#include <WinSock2.h>
|
#include <WinSock2.h>
|
||||||
#endif
|
#endif
|
||||||
#include "common/elf_info.h"
|
#include "common/elf_info.h"
|
||||||
|
#include "common/memory_patcher.h"
|
||||||
#include "common/ntapi.h"
|
#include "common/ntapi.h"
|
||||||
#include "common/path_util.h"
|
#include "common/path_util.h"
|
||||||
#include "common/polyfill_thread.h"
|
#include "common/polyfill_thread.h"
|
||||||
|
@ -54,27 +54,6 @@ Emulator::Emulator() {
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
WSAStartup(versionWanted, &wsaData);
|
WSAStartup(versionWanted, &wsaData);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Create stdin/stdout/stderr
|
|
||||||
Common::Singleton<FileSys::HandleTable>::Instance()->CreateStdHandles();
|
|
||||||
|
|
||||||
// Defer until after logging is initialized.
|
|
||||||
memory = Core::Memory::Instance();
|
|
||||||
controller = Common::Singleton<Input::GameController>::Instance();
|
|
||||||
linker = Common::Singleton<Core::Linker>::Instance();
|
|
||||||
|
|
||||||
// Load renderdoc module.
|
|
||||||
VideoCore::LoadRenderDoc();
|
|
||||||
|
|
||||||
// Start the timer (Play Time)
|
|
||||||
#ifdef ENABLE_QT_GUI
|
|
||||||
start_time = std::chrono::steady_clock::now();
|
|
||||||
const auto user_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
|
|
||||||
QString filePath = QString::fromStdString((user_dir / "play_time.txt").string());
|
|
||||||
QFile file(filePath);
|
|
||||||
ASSERT_MSG(file.open(QIODevice::ReadWrite | QIODevice::Text),
|
|
||||||
"Error opening or creating play_time.txt");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Emulator::~Emulator() {
|
Emulator::~Emulator() {
|
||||||
|
@ -102,54 +81,89 @@ void Emulator::Run(const std::filesystem::path& file, const std::vector<std::str
|
||||||
// Certain games may use /hostapp as well such as CUSA001100
|
// Certain games may use /hostapp as well such as CUSA001100
|
||||||
mnt->Mount(game_folder, "/hostapp", true);
|
mnt->Mount(game_folder, "/hostapp", true);
|
||||||
|
|
||||||
auto& game_info = Common::ElfInfo::Instance();
|
const auto param_sfo_path = mnt->GetHostPath("/app0/sce_sys/param.sfo");
|
||||||
|
const auto param_sfo_exists = std::filesystem::exists(param_sfo_path);
|
||||||
|
|
||||||
// Loading param.sfo file if exists
|
// Load param.sfo details if it exists
|
||||||
std::string id;
|
std::string id;
|
||||||
std::string title;
|
std::string title;
|
||||||
std::string app_version;
|
std::string app_version;
|
||||||
u32 fw_version;
|
u32 fw_version;
|
||||||
Common::PSFAttributes psf_attributes{};
|
Common::PSFAttributes psf_attributes{};
|
||||||
|
if (param_sfo_exists) {
|
||||||
const auto param_sfo_path = mnt->GetHostPath("/app0/sce_sys/param.sfo");
|
|
||||||
if (!std::filesystem::exists(param_sfo_path) || !Config::getSeparateLogFilesEnabled()) {
|
|
||||||
Common::Log::Initialize();
|
|
||||||
Common::Log::Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (std::filesystem::exists(param_sfo_path)) {
|
|
||||||
auto* param_sfo = Common::Singleton<PSF>::Instance();
|
auto* param_sfo = Common::Singleton<PSF>::Instance();
|
||||||
const bool success = param_sfo->Open(param_sfo_path);
|
ASSERT_MSG(param_sfo->Open(param_sfo_path), "Failed to open param.sfo");
|
||||||
ASSERT_MSG(success, "Failed to open param.sfo");
|
|
||||||
const auto content_id = param_sfo->GetString("CONTENT_ID");
|
const auto content_id = param_sfo->GetString("CONTENT_ID");
|
||||||
ASSERT_MSG(content_id.has_value(), "Failed to get CONTENT_ID");
|
ASSERT_MSG(content_id.has_value(), "Failed to get CONTENT_ID");
|
||||||
|
|
||||||
id = std::string(*content_id, 7, 9);
|
id = std::string(*content_id, 7, 9);
|
||||||
|
title = param_sfo->GetString("TITLE").value_or("Unknown title");
|
||||||
if (Config::getSeparateLogFilesEnabled()) {
|
fw_version = param_sfo->GetInteger("SYSTEM_VER").value_or(0x4700000);
|
||||||
Common::Log::Initialize(id + ".log");
|
app_version = param_sfo->GetString("APP_VER").value_or("Unknown version");
|
||||||
Common::Log::Start();
|
if (const auto raw_attributes = param_sfo->GetInteger("ATTRIBUTE")) {
|
||||||
|
psf_attributes.raw = *raw_attributes;
|
||||||
}
|
}
|
||||||
LOG_INFO(Loader, "Starting shadps4 emulator v{} ", Common::g_version);
|
}
|
||||||
LOG_INFO(Loader, "Revision {}", Common::g_scm_rev);
|
|
||||||
LOG_INFO(Loader, "Branch {}", Common::g_scm_branch);
|
|
||||||
LOG_INFO(Loader, "Description {}", Common::g_scm_desc);
|
|
||||||
LOG_INFO(Loader, "Remote {}", Common::g_scm_remote_url);
|
|
||||||
|
|
||||||
LOG_INFO(Config, "General LogType: {}", Config::getLogType());
|
// Initialize logging as soon as possible
|
||||||
LOG_INFO(Config, "General isNeo: {}", Config::isNeoModeConsole());
|
if (!id.empty() && Config::getSeparateLogFilesEnabled()) {
|
||||||
LOG_INFO(Config, "GPU isNullGpu: {}", Config::nullGpu());
|
Common::Log::Initialize(id + ".log");
|
||||||
LOG_INFO(Config, "GPU shouldDumpShaders: {}", Config::dumpShaders());
|
} else {
|
||||||
LOG_INFO(Config, "GPU vblankDivider: {}", Config::vblankDiv());
|
Common::Log::Initialize();
|
||||||
LOG_INFO(Config, "Vulkan gpuId: {}", Config::getGpuId());
|
}
|
||||||
LOG_INFO(Config, "Vulkan vkValidation: {}", Config::vkValidationEnabled());
|
Common::Log::Start();
|
||||||
LOG_INFO(Config, "Vulkan vkValidationSync: {}", Config::vkValidationSyncEnabled());
|
|
||||||
LOG_INFO(Config, "Vulkan vkValidationGpu: {}", Config::vkValidationGpuEnabled());
|
|
||||||
LOG_INFO(Config, "Vulkan crashDiagnostics: {}", Config::getVkCrashDiagnosticEnabled());
|
|
||||||
LOG_INFO(Config, "Vulkan hostMarkers: {}", Config::getVkHostMarkersEnabled());
|
|
||||||
LOG_INFO(Config, "Vulkan guestMarkers: {}", Config::getVkGuestMarkersEnabled());
|
|
||||||
LOG_INFO(Config, "Vulkan rdocEnable: {}", Config::isRdocEnabled());
|
|
||||||
|
|
||||||
|
LOG_INFO(Loader, "Starting shadps4 emulator v{} ", Common::g_version);
|
||||||
|
LOG_INFO(Loader, "Revision {}", Common::g_scm_rev);
|
||||||
|
LOG_INFO(Loader, "Branch {}", Common::g_scm_branch);
|
||||||
|
LOG_INFO(Loader, "Description {}", Common::g_scm_desc);
|
||||||
|
LOG_INFO(Loader, "Remote {}", Common::g_scm_remote_url);
|
||||||
|
|
||||||
|
LOG_INFO(Config, "General LogType: {}", Config::getLogType());
|
||||||
|
LOG_INFO(Config, "General isNeo: {}", Config::isNeoModeConsole());
|
||||||
|
LOG_INFO(Config, "GPU isNullGpu: {}", Config::nullGpu());
|
||||||
|
LOG_INFO(Config, "GPU shouldDumpShaders: {}", Config::dumpShaders());
|
||||||
|
LOG_INFO(Config, "GPU vblankDivider: {}", Config::vblankDiv());
|
||||||
|
LOG_INFO(Config, "Vulkan gpuId: {}", Config::getGpuId());
|
||||||
|
LOG_INFO(Config, "Vulkan vkValidation: {}", Config::vkValidationEnabled());
|
||||||
|
LOG_INFO(Config, "Vulkan vkValidationSync: {}", Config::vkValidationSyncEnabled());
|
||||||
|
LOG_INFO(Config, "Vulkan vkValidationGpu: {}", Config::vkValidationGpuEnabled());
|
||||||
|
LOG_INFO(Config, "Vulkan crashDiagnostics: {}", Config::getVkCrashDiagnosticEnabled());
|
||||||
|
LOG_INFO(Config, "Vulkan hostMarkers: {}", Config::getVkHostMarkersEnabled());
|
||||||
|
LOG_INFO(Config, "Vulkan guestMarkers: {}", Config::getVkGuestMarkersEnabled());
|
||||||
|
LOG_INFO(Config, "Vulkan rdocEnable: {}", Config::isRdocEnabled());
|
||||||
|
|
||||||
|
if (param_sfo_exists) {
|
||||||
|
LOG_INFO(Loader, "Game id: {} Title: {}", id, title);
|
||||||
|
LOG_INFO(Loader, "Fw: {:#x} App Version: {}", fw_version, app_version);
|
||||||
|
}
|
||||||
|
if (!args.empty()) {
|
||||||
|
const auto argc = std::min<size_t>(args.size(), 32);
|
||||||
|
for (auto i = 0; i < argc; i++) {
|
||||||
|
LOG_INFO(Loader, "Game argument {}: {}", i, args[i]);
|
||||||
|
}
|
||||||
|
if (args.size() > 32) {
|
||||||
|
LOG_ERROR(Loader, "Too many game arguments, only passing the first 32");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create stdin/stdout/stderr
|
||||||
|
Common::Singleton<FileSys::HandleTable>::Instance()->CreateStdHandles();
|
||||||
|
|
||||||
|
// Initialize components
|
||||||
|
memory = Core::Memory::Instance();
|
||||||
|
controller = Common::Singleton<Input::GameController>::Instance();
|
||||||
|
linker = Common::Singleton<Core::Linker>::Instance();
|
||||||
|
|
||||||
|
// Load renderdoc module
|
||||||
|
VideoCore::LoadRenderDoc();
|
||||||
|
|
||||||
|
// Initialize patcher and trophies
|
||||||
|
if (!id.empty()) {
|
||||||
|
MemoryPatcher::g_game_serial = id;
|
||||||
Libraries::NpTrophy::game_serial = id;
|
Libraries::NpTrophy::game_serial = id;
|
||||||
|
|
||||||
const auto trophyDir =
|
const auto trophyDir =
|
||||||
Common::FS::GetUserPath(Common::FS::PathType::MetaDataDir) / id / "TrophyFiles";
|
Common::FS::GetUserPath(Common::FS::PathType::MetaDataDir) / id / "TrophyFiles";
|
||||||
if (!std::filesystem::exists(trophyDir)) {
|
if (!std::filesystem::exists(trophyDir)) {
|
||||||
|
@ -158,41 +172,9 @@ void Emulator::Run(const std::filesystem::path& file, const std::vector<std::str
|
||||||
LOG_ERROR(Loader, "Couldn't extract trophies");
|
LOG_ERROR(Loader, "Couldn't extract trophies");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_QT_GUI
|
|
||||||
MemoryPatcher::g_game_serial = id;
|
|
||||||
|
|
||||||
// Timer for 'Play Time'
|
|
||||||
QTimer* timer = new QTimer();
|
|
||||||
QObject::connect(timer, &QTimer::timeout, [this, id]() {
|
|
||||||
UpdatePlayTime(id);
|
|
||||||
start_time = std::chrono::steady_clock::now();
|
|
||||||
});
|
|
||||||
timer->start(60000); // 60000 ms = 1 minute
|
|
||||||
#endif
|
|
||||||
title = param_sfo->GetString("TITLE").value_or("Unknown title");
|
|
||||||
LOG_INFO(Loader, "Game id: {} Title: {}", id, title);
|
|
||||||
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);
|
|
||||||
if (const auto raw_attributes = param_sfo->GetInteger("ATTRIBUTE")) {
|
|
||||||
psf_attributes.raw = *raw_attributes;
|
|
||||||
}
|
|
||||||
if (!args.empty()) {
|
|
||||||
int argc = std::min<int>(args.size(), 32);
|
|
||||||
for (int i = 0; i < argc; i++) {
|
|
||||||
LOG_INFO(Loader, "Game argument {}: {}", i, args[i]);
|
|
||||||
}
|
|
||||||
if (args.size() > 32) {
|
|
||||||
LOG_ERROR(Loader, "Too many game arguments, only passing the first 32");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto pic1_path = mnt->GetHostPath("/app0/sce_sys/pic1.png");
|
|
||||||
if (std::filesystem::exists(pic1_path)) {
|
|
||||||
game_info.splash_path = pic1_path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto& game_info = Common::ElfInfo::Instance();
|
||||||
game_info.initialized = true;
|
game_info.initialized = true;
|
||||||
game_info.game_serial = id;
|
game_info.game_serial = id;
|
||||||
game_info.title = title;
|
game_info.title = title;
|
||||||
|
@ -201,6 +183,11 @@ void Emulator::Run(const std::filesystem::path& file, const std::vector<std::str
|
||||||
game_info.raw_firmware_ver = fw_version;
|
game_info.raw_firmware_ver = fw_version;
|
||||||
game_info.psf_attributes = psf_attributes;
|
game_info.psf_attributes = psf_attributes;
|
||||||
|
|
||||||
|
const auto pic1_path = mnt->GetHostPath("/app0/sce_sys/pic1.png");
|
||||||
|
if (std::filesystem::exists(pic1_path)) {
|
||||||
|
game_info.splash_path = pic1_path;
|
||||||
|
}
|
||||||
|
|
||||||
std::string game_title = fmt::format("{} - {} <{}>", id, title, app_version);
|
std::string game_title = fmt::format("{} - {} <{}>", id, title, app_version);
|
||||||
std::string window_title = "";
|
std::string window_title = "";
|
||||||
if (Common::g_is_release) {
|
if (Common::g_is_release) {
|
||||||
|
@ -284,6 +271,25 @@ void Emulator::Run(const std::filesystem::path& file, const std::vector<std::str
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Start the timer (Play Time)
|
||||||
|
#ifdef ENABLE_QT_GUI
|
||||||
|
if (!id.empty()) {
|
||||||
|
auto* timer = new QTimer();
|
||||||
|
QObject::connect(timer, &QTimer::timeout, [this, id]() {
|
||||||
|
UpdatePlayTime(id);
|
||||||
|
start_time = std::chrono::steady_clock::now();
|
||||||
|
});
|
||||||
|
timer->start(60000); // 60000 ms = 1 minute
|
||||||
|
|
||||||
|
start_time = std::chrono::steady_clock::now();
|
||||||
|
const auto user_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
|
||||||
|
QString filePath = QString::fromStdString((user_dir / "play_time.txt").string());
|
||||||
|
QFile file(filePath);
|
||||||
|
ASSERT_MSG(file.open(QIODevice::ReadWrite | QIODevice::Text),
|
||||||
|
"Error opening or creating play_time.txt");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
linker->Execute(args);
|
linker->Execute(args);
|
||||||
|
|
||||||
window->InitTimers();
|
window->InitTimers();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue