GE Debugger: Include game ID inside dump file.

Just so we're not relying on filename parsing.  It's useful information.
This commit is contained in:
Unknown W. Brackets 2020-09-06 14:38:56 -07:00
parent 901239c05e
commit 815580533c
4 changed files with 47 additions and 11 deletions

View File

@ -68,6 +68,7 @@
#include "GPU/GPUState.h"
#include "GPU/GPUInterface.h"
#include "GPU/Debugger/RecordFormat.h"
enum CPUThreadState {
CPU_THREAD_NOT_RUNNING,
@ -185,7 +186,23 @@ bool CPU_HasPendingAction() {
void CPU_Shutdown();
bool DiscIDFromGEDumpPath(const std::string &path, std::string *id) {
bool DiscIDFromGEDumpPath(const std::string &path, FileLoader *fileLoader, std::string *id) {
using namespace GPURecord;
// For newer files, it's stored in the dump.
Header header;
if (fileLoader->ReadAt(0, sizeof(header), &header) == sizeof(header)) {
const bool magicMatch = memcmp(header.magic, HEADER_MAGIC, sizeof(header.magic)) == 0;
if (magicMatch && header.version <= VERSION && header.version >= 4) {
size_t gameIDLength = strnlen(header.gameID, sizeof(header.gameID));
if (gameIDLength != 0) {
*id = std::string(header.gameID, gameIDLength);
return true;
}
}
}
// Fall back to using the filename.
std::string filename = File::GetFilename(path);
// Could be more discerning, but hey..
if (filename.size() > 10 && filename[0] == 'U' && filename[9] == '_') {
@ -254,7 +271,7 @@ bool CPU_Init() {
// Try to grab the disc ID from the filename, since unfortunately, we don't store
// it in the GE dump. This should probably be fixed, but as long as you don't rename the dumps,
// this will do the trick.
if (!DiscIDFromGEDumpPath(filename, &discID)) {
if (!DiscIDFromGEDumpPath(filename, loadedFile, &discID)) {
// Failed? Let the param SFO autogen a fake disc ID.
discID = g_paramSFO.GetDiscID();
}

View File

@ -26,6 +26,7 @@
#include "Common/Log.h"
#include "Core/Core.h"
#include "Core/CoreTiming.h"
#include "Core/ELF/ParamSFO.h"
#include "Core/FileSystems/MetaFileSystem.h"
#include "Core/HLE/sceDisplay.h"
#include "Core/HLE/sceKernelMemory.h"
@ -671,16 +672,23 @@ bool RunMountedReplay(const std::string &filename) {
if (lastExecFilename != filename) {
PROFILE_THIS_SCOPE("ReplayLoad");
u32 fp = pspFileSystem.OpenFile(filename, FILEACCESS_READ);
u8 header[8]{};
int version = 0;
pspFileSystem.ReadFile(fp, header, sizeof(header));
pspFileSystem.ReadFile(fp, (u8 *)&version, sizeof(version));
Header header;
pspFileSystem.ReadFile(fp, (u8 *)&header, sizeof(header));
if (memcmp(header, HEADER, sizeof(header)) != 0 || version > VERSION || version < MIN_VERSION) {
if (memcmp(header.magic, HEADER_MAGIC, sizeof(header.magic)) != 0 || header.version > VERSION || header.version < MIN_VERSION) {
ERROR_LOG(SYSTEM, "Invalid GE dump or unsupported version");
pspFileSystem.CloseFile(fp);
return false;
}
if (header.version <= 3) {
pspFileSystem.SeekFile(fp, 12, FILEMOVE_BEGIN);
memset(header.gameID, 0, sizeof(header.gameID));
}
size_t gameIDLength = strnlen(header.gameID, sizeof(header.gameID));
if (gameIDLength != 0) {
g_paramSFO.SetValue("DISC_ID", std::string(header.gameID, gameIDLength), (int)sizeof(header.gameID));
}
u32 sz = 0;
pspFileSystem.ReadFile(fp, (u8 *)&sz, sizeof(sz));

View File

@ -115,8 +115,11 @@ static std::string WriteRecording() {
NOTICE_LOG(G3D, "Recording filename: %s", filename.c_str());
FILE *fp = File::OpenCFile(filename, "wb");
fwrite(HEADER, 8, 1, fp);
fwrite(&VERSION, sizeof(VERSION), 1, fp);
Header header{};
strncpy(header.magic, HEADER_MAGIC, sizeof(header.magic));
header.version = VERSION;
strncpy(header.gameID, g_paramSFO.GetDiscID().c_str(), sizeof(header.gameID));
fwrite(&header, sizeof(header), 1, fp);
u32 sz = (u32)commands.size();
fwrite(&sz, sizeof(sz), 1, fp);

View File

@ -21,11 +21,19 @@
namespace GPURecord {
static const char *HEADER = "PPSSPPGE";
struct Header {
char magic[8];
uint32_t version;
char gameID[9];
uint8_t pad[3];
};
static const char *HEADER_MAGIC = "PPSSPPGE";
// Version 1: Uncompressed
// Version 2: Uses snappy
// Version 3: Adds FRAMEBUF0-FRAMEBUF9
static const int VERSION = 3;
// Version 4: Expanded header with game ID
static const int VERSION = 4;
static const int MIN_VERSION = 2;
enum class CommandType : u8 {