extract trophy info on game start + various fixes

This commit is contained in:
CrazyBloo 2024-09-09 11:44:47 -04:00
parent 794770f94e
commit 315afc52fa
4 changed files with 26 additions and 25 deletions

View file

@ -542,17 +542,12 @@ int PS4_SYSV_ABI sceNpTrophyUnlockTrophy(OrbisNpTrophyContext context, OrbisNpTr
if (platinumId == nullptr)
return ORBIS_NP_TROPHY_ERROR_INVALID_ARGUMENT;
#ifdef _WIN32
const auto trophyDir =
Common::FS::GetUserPath(Common::FS::PathType::MetaDataDir) / game_serial / "TrophyFiles";
#else
const auto trophyDir =
Common::FS::GetUserPath(Common::FS::PathType::MetaDataDir) / game_serial / "TrophyFiles";
#endif
pugi::xml_document doc;
pugi::xml_parse_result result =
doc.load_file((trophyDir.string() + "\\trophy00\\Xml\\TROP.XML").c_str());
doc.load_file((trophyDir.string() + "/trophy00/Xml/TROP.XML").c_str());
// only do this if platinum is not unlocked
*platinumId = ORBIS_NP_TROPHY_INVALID_TROPHY_ID;
@ -564,8 +559,10 @@ int PS4_SYSV_ABI sceNpTrophyUnlockTrophy(OrbisNpTrophyContext context, OrbisNpTr
for (pugi::xml_node_iterator it = trophyconf.children().begin();
it != trophyconf.children().end() && !foundTrophy; ++it) {
std::string currentTrophyId = reinterpret_cast<const char*>(it->attribute("id").value());
std::string currentTrophyName = reinterpret_cast<const char*>(it->child("name").text().as_string());
std::string currentTrophyId =
reinterpret_cast<const char*>(it->attribute("id").value());
std::string currentTrophyName =
reinterpret_cast<const char*>(it->child("name").text().as_string());
std::string currentTrophyDescription =
reinterpret_cast<const char*>(it->child("detail").text().as_string());
std::string currentTrophyType =
@ -590,7 +587,7 @@ int PS4_SYSV_ABI sceNpTrophyUnlockTrophy(OrbisNpTrophyContext context, OrbisNpTr
g_trophy_ui.AddTrophyToQueue(trophyId, currentTrophyName, TrophyType::BRONZE);
//doc.save_file((trophyDir.string() + "\\trophy00\\Xml\\TROP.XML").c_str());
//doc.save_file((trophyDir.string() + "/trophy00/Xml/TROP.XML").c_str());
}
foundTrophy = true;
}

View file

@ -1,8 +1,8 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <imgui.h>
#include <chrono>
#include <imgui.h>
#include "common/assert.h"
#include "imgui/imgui_std.h"
#include "trophy_ui.h"
@ -15,7 +15,6 @@ TrophyUI::TrophyUI() {
AddLayer(this);
}
TrophyUI::~TrophyUI() {
Finish();
}
@ -41,17 +40,9 @@ void TrophyUI::Draw() {
const ImVec2 window_size{
std::min(io.DisplaySize.x, 200.f),
std::min(io.DisplaySize.y, 125.f),
std::min(io.DisplaySize.y, 75.f),
};
CentralizeWindow();
SetNextWindowSize(window_size);
SetNextWindowFocus();
SetNextWindowCollapsed(false);
SetNextWindowPos(ImVec2(io.DisplaySize.x - 200, 50));
PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0));
KeepNavHighlight();
if (trophyQueue.size() != 0) {
if (!displayingTrophy) {
displayingTrophy = true;
@ -68,17 +59,21 @@ void TrophyUI::Draw() {
}
if (trophyQueue.size() != 0) {
SetNextWindowSize(window_size);
SetNextWindowCollapsed(false);
SetNextWindowPos(ImVec2(io.DisplaySize.x - 200, 50));
KeepNavHighlight();
TrophyInfo currentTrophyInfo = trophyQueue[0];
if (Begin("Trophy Window", nullptr,
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings)) {
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings
| ImGuiWindowFlags_NoInputs)) {
Text("Trophy earned!");
Text(currentTrophyInfo.trophyName.c_str());
TextWrapped(currentTrophyInfo.trophyName.c_str());
End();
}
}
}
PopStyleColor();
first_render = false;
}

View file

@ -3,9 +3,9 @@
#pragma once
#include <string>
#include <variant>
#include <vector>
#include <string>
#include "common/fixed_value.h"
#include "common/types.h"

View file

@ -19,6 +19,7 @@
#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"
#include "core/file_sys/fs.h"
#include "core/libraries/disc_map/disc_map.h"
#include "core/libraries/kernel/thread_management.h"
@ -101,6 +102,14 @@ void Emulator::Run(const std::filesystem::path& file) {
param_sfo->open(sce_sys_folder.string() + "/param.sfo", {});
id = std::string(param_sfo->GetString("CONTENT_ID"), 7, 9);
Libraries::NpTrophy::game_serial = id;
const auto trophyDir = Common::FS::GetUserPath(Common::FS::PathType::MetaDataDir) /
id / "TrophyFiles";
if (!std::filesystem::exists(trophyDir)) {
TRP trp;
if (!trp.Extract(file.parent_path())) {
LOG_ERROR(Loader, "Couldn't extract trophies");
}
}
#ifdef ENABLE_QT_GUI
MemoryPatcher::g_game_serial = id;
#endif