From 7c552ddb38eec6a5d2ad440a5a6ccf73810c4cd4 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Sat, 29 Oct 2022 10:23:58 +0300 Subject: [PATCH] added detection of PS4 PKG image (magic is 0x7F434E54) --- shadPS4/emulator/Loader.cpp | 24 ++++++++++++++++++++++++ shadPS4/emulator/Loader.h | 10 ++++++++++ shadPS4/gui/shadps4gui.cpp | 12 +++++++++++- shadPS4/shadPS4.vcxproj | 2 ++ shadPS4/shadPS4.vcxproj.filters | 6 ++++++ 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 shadPS4/emulator/Loader.cpp create mode 100644 shadPS4/emulator/Loader.h diff --git a/shadPS4/emulator/Loader.cpp b/shadPS4/emulator/Loader.cpp new file mode 100644 index 00000000..c01f4a4d --- /dev/null +++ b/shadPS4/emulator/Loader.cpp @@ -0,0 +1,24 @@ +#include "Loader.h" +#include "../core/FsFile.h" + +FileTypes detectFileType(const std::string& filepath) +{ + if (filepath.size() == 0)//no file loaded + { + return FILETYPE_UNKNOWN; + } + FsFile file; + file.Open(filepath, fsRead); + file.Seek(0, fsSeekSet); + U32 magic; + file.Read(&magic, sizeof(magic)); + file.Close(); + ReadBE(magic);//magic is BE make it LE + switch (magic) + { + case 0x7F434E54://PS4 PKG + return FILETYPE_PKG; + } + return FILETYPE_UNKNOWN; + +} diff --git a/shadPS4/emulator/Loader.h b/shadPS4/emulator/Loader.h new file mode 100644 index 00000000..d1fd765d --- /dev/null +++ b/shadPS4/emulator/Loader.h @@ -0,0 +1,10 @@ +#pragma once + +#include + +enum FileTypes +{ + FILETYPE_UNKNOWN, + FILETYPE_PKG +}; +FileTypes detectFileType(const std::string& filepath); diff --git a/shadPS4/gui/shadps4gui.cpp b/shadPS4/gui/shadps4gui.cpp index c7933610..6d6889b9 100644 --- a/shadPS4/gui/shadps4gui.cpp +++ b/shadPS4/gui/shadps4gui.cpp @@ -1,4 +1,6 @@ #include "shadps4gui.h" +#include "../emulator/Loader.h" +#include #include #include shadps4gui::shadps4gui(QWidget *parent) @@ -17,5 +19,13 @@ shadps4gui::~shadps4gui() void shadps4gui::installPKG() { - QMessageBox::critical(this, "PKG ERROR", "Not yet", QMessageBox::Ok, 0); + std::string file(QFileDialog::getOpenFileName(this, tr("Install PKG File"), QDir::currentPath(), tr("PKG File (*.PKG)")).toStdString()); + if (detectFileType(file) == FILETYPE_PKG) + { + + } + else + { + QMessageBox::critical(this, "PKG ERROR", "File doesn't appear to be a valid PKG file", QMessageBox::Ok, 0); + } } diff --git a/shadPS4/shadPS4.vcxproj b/shadPS4/shadPS4.vcxproj index 698a9717..0923605c 100644 --- a/shadPS4/shadPS4.vcxproj +++ b/shadPS4/shadPS4.vcxproj @@ -13,6 +13,7 @@ + @@ -29,6 +30,7 @@ + diff --git a/shadPS4/shadPS4.vcxproj.filters b/shadPS4/shadPS4.vcxproj.filters index bfe0d7f8..4eac2ac3 100644 --- a/shadPS4/shadPS4.vcxproj.filters +++ b/shadPS4/shadPS4.vcxproj.filters @@ -50,6 +50,9 @@ emulator\fileFormat + + emulator + @@ -74,5 +77,8 @@ emulator\fileFormat + + emulator + \ No newline at end of file