From 711e9e917d182120e8f06c5547c406acce46c0fb Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Sun, 30 Oct 2022 17:28:49 +0200 Subject: [PATCH] some intial work on PKG reading --- shadPS4/core/FsFile.h | 8 ++++++++ shadPS4/emulator/fileFormat/PKG.cpp | 31 +++++++++++++++++++++++++++++ shadPS4/emulator/fileFormat/PKG.h | 29 +++++++++++++++++++++++++++ shadPS4/gui/shadps4gui.cpp | 8 +++++++- shadPS4/shadPS4.vcxproj | 2 ++ shadPS4/shadPS4.vcxproj.filters | 6 ++++++ 6 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 shadPS4/emulator/fileFormat/PKG.cpp create mode 100644 shadPS4/emulator/fileFormat/PKG.h diff --git a/shadPS4/core/FsFile.h b/shadPS4/core/FsFile.h index 705fad6f..79984cf8 100644 --- a/shadPS4/core/FsFile.h +++ b/shadPS4/core/FsFile.h @@ -34,6 +34,14 @@ public: U64 Tell() const; ~FsFile(); + template< typename T > bool ReadBE(T& dst) + { + if (!Read(&dst, sizeof(T))) { + return false; + } + ::ReadBE(dst); + return true; + } const char* getOpenMode(fsOpenMode mode) { diff --git a/shadPS4/emulator/fileFormat/PKG.cpp b/shadPS4/emulator/fileFormat/PKG.cpp new file mode 100644 index 00000000..571bee4a --- /dev/null +++ b/shadPS4/emulator/fileFormat/PKG.cpp @@ -0,0 +1,31 @@ +#include "PKG.h" +#include "../../core/FsFile.h" + +PKG::PKG() +{ +} + + +PKG::~PKG() +{ +} + +bool PKG::open(const std::string& filepath) { + FsFile file; + if (!file.Open(filepath, fsRead)) + { + return false; + } + pkgSize = file.getFileSize(); + PKGHeader pkgheader; + file.ReadBE(pkgheader); + //we have already checked magic should be ok + + //find title id it is part of pkg_content_id starting at offset 0x40 + file.Seek(0x47, fsSeekSet);//skip first 7 characters of content_id + file.Read(&pkgTitleID, sizeof(pkgTitleID)); + + file.Close(); + + return true; +} \ No newline at end of file diff --git a/shadPS4/emulator/fileFormat/PKG.h b/shadPS4/emulator/fileFormat/PKG.h new file mode 100644 index 00000000..d1a512c6 --- /dev/null +++ b/shadPS4/emulator/fileFormat/PKG.h @@ -0,0 +1,29 @@ +#pragma once +#include +#include "../../Types.h" + +struct PKGHeader { + /*BE*/U32 magic; // Magic +}; + +class PKG +{ +private: + U08* pkg; + U64 pkgSize = 0; + S08 pkgTitleID[9]; + +public: + PKG(); + ~PKG(); + bool open(const std::string& filepath); + U64 getPkgSize() + { + return pkgSize; + } + std::string getTitleID() + { + return std::string(pkgTitleID); + } +}; + diff --git a/shadPS4/gui/shadps4gui.cpp b/shadPS4/gui/shadps4gui.cpp index 6d6889b9..ebfe1e81 100644 --- a/shadPS4/gui/shadps4gui.cpp +++ b/shadPS4/gui/shadps4gui.cpp @@ -1,8 +1,12 @@ #include "shadps4gui.h" #include "../emulator/Loader.h" +#include "../emulator/fileFormat/PKG.h" +#include "../core/FsFile.h" #include #include #include +#include + shadps4gui::shadps4gui(QWidget *parent) : QMainWindow(parent) { @@ -22,7 +26,9 @@ void shadps4gui::installPKG() std::string file(QFileDialog::getOpenFileName(this, tr("Install PKG File"), QDir::currentPath(), tr("PKG File (*.PKG)")).toStdString()); if (detectFileType(file) == FILETYPE_PKG) { - + PKG pkg; + pkg.open(file); + } else { diff --git a/shadPS4/shadPS4.vcxproj b/shadPS4/shadPS4.vcxproj index 0923605c..78e86485 100644 --- a/shadPS4/shadPS4.vcxproj +++ b/shadPS4/shadPS4.vcxproj @@ -12,6 +12,7 @@ + @@ -29,6 +30,7 @@ + diff --git a/shadPS4/shadPS4.vcxproj.filters b/shadPS4/shadPS4.vcxproj.filters index 4eac2ac3..9ca77d91 100644 --- a/shadPS4/shadPS4.vcxproj.filters +++ b/shadPS4/shadPS4.vcxproj.filters @@ -53,6 +53,9 @@ emulator + + emulator\fileFormat + @@ -80,5 +83,8 @@ emulator + + emulator\fileFormat + \ No newline at end of file