some intial work on PKG reading

This commit is contained in:
georgemoralis 2022-10-30 17:28:49 +02:00
parent 7c552ddb38
commit 711e9e917d
6 changed files with 83 additions and 1 deletions

View File

@ -34,6 +34,14 @@ public:
U64 Tell() const; U64 Tell() const;
~FsFile(); ~FsFile();
template< typename T > bool ReadBE(T& dst)
{
if (!Read(&dst, sizeof(T))) {
return false;
}
::ReadBE(dst);
return true;
}
const char* getOpenMode(fsOpenMode mode) const char* getOpenMode(fsOpenMode mode)
{ {

View File

@ -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;
}

View File

@ -0,0 +1,29 @@
#pragma once
#include <string>
#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);
}
};

View File

@ -1,8 +1,12 @@
#include "shadps4gui.h" #include "shadps4gui.h"
#include "../emulator/Loader.h" #include "../emulator/Loader.h"
#include "../emulator/fileFormat/PKG.h"
#include "../core/FsFile.h"
#include <QFileDialog> #include <QFileDialog>
#include <QDir> #include <QDir>
#include <QMessageBox> #include <QMessageBox>
#include <QProgressDialog>
shadps4gui::shadps4gui(QWidget *parent) shadps4gui::shadps4gui(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
{ {
@ -22,6 +26,8 @@ void shadps4gui::installPKG()
std::string file(QFileDialog::getOpenFileName(this, tr("Install PKG File"), QDir::currentPath(), tr("PKG File (*.PKG)")).toStdString()); std::string file(QFileDialog::getOpenFileName(this, tr("Install PKG File"), QDir::currentPath(), tr("PKG File (*.PKG)")).toStdString());
if (detectFileType(file) == FILETYPE_PKG) if (detectFileType(file) == FILETYPE_PKG)
{ {
PKG pkg;
pkg.open(file);
} }
else else

View File

@ -12,6 +12,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="core\FsFile.cpp" /> <ClCompile Include="core\FsFile.cpp" />
<ClCompile Include="emulator\fileFormat\PKG.cpp" />
<ClCompile Include="emulator\fileFormat\PSF.cpp" /> <ClCompile Include="emulator\fileFormat\PSF.cpp" />
<ClCompile Include="emulator\Loader.cpp" /> <ClCompile Include="emulator\Loader.cpp" />
<ClCompile Include="gui\GameListViewer.cpp" /> <ClCompile Include="gui\GameListViewer.cpp" />
@ -29,6 +30,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="core\FsFile.h" /> <ClInclude Include="core\FsFile.h" />
<ClInclude Include="emulator\fileFormat\PKG.h" />
<ClInclude Include="emulator\fileFormat\PSF.h" /> <ClInclude Include="emulator\fileFormat\PSF.h" />
<ClInclude Include="emulator\Loader.h" /> <ClInclude Include="emulator\Loader.h" />
<ClInclude Include="Types.h" /> <ClInclude Include="Types.h" />

View File

@ -53,6 +53,9 @@
<ClCompile Include="emulator\Loader.cpp"> <ClCompile Include="emulator\Loader.cpp">
<Filter>emulator</Filter> <Filter>emulator</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="emulator\fileFormat\PKG.cpp">
<Filter>emulator\fileFormat</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<QtUic Include="gui\shadps4gui.ui"> <QtUic Include="gui\shadps4gui.ui">
@ -80,5 +83,8 @@
<ClInclude Include="emulator\Loader.h"> <ClInclude Include="emulator\Loader.h">
<Filter>emulator</Filter> <Filter>emulator</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="emulator\fileFormat\PKG.h">
<Filter>emulator\fileFormat</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>