shadPS4/src/core/file_format/psf.cpp
georgemoralis 02cbebbf78
file formats and qt (#88)
* added psf file format

* clang format fix

* crypto functions for pkg decryption

* pkg decryption

* initial add of qt gui , not yet usable

* renamed ini for qt gui settings into shadps4qt.ini

* file detection and loader support

* option to build QT qui

* clang format fix

* fixed reuse

* Update src/core/file_format/pkg.cpp

Co-authored-by: GPUCode <47210458+GPUCode@users.noreply.github.com>

* Update src/core/file_format/pkg.cpp

Co-authored-by: GPUCode <47210458+GPUCode@users.noreply.github.com>

* Update src/core/file_format/pkg.cpp

Co-authored-by: GPUCode <47210458+GPUCode@users.noreply.github.com>

* Update src/core/file_format/pkg.cpp

Co-authored-by: GPUCode <47210458+GPUCode@users.noreply.github.com>

* Update src/core/loader.h

Co-authored-by: GPUCode <47210458+GPUCode@users.noreply.github.com>

* Update src/core/loader.cpp

Co-authored-by: GPUCode <47210458+GPUCode@users.noreply.github.com>

* uppercase fix

* clang format fix

* small fixes

* let's try windows qt build ci

* some more fixes for ci

* Update src/core/file_format/pkg.cpp

Co-authored-by: GPUCode <47210458+GPUCode@users.noreply.github.com>

* Update src/core/file_format/pkg.cpp

Co-authored-by: GPUCode <47210458+GPUCode@users.noreply.github.com>

* Update src/core/file_format/pkg.cpp

Co-authored-by: GPUCode <47210458+GPUCode@users.noreply.github.com>

* Update src/core/file_format/pkg.cpp

Co-authored-by: GPUCode <47210458+GPUCode@users.noreply.github.com>

* Update .github/workflows/windows-qt.yml

Co-authored-by: GPUCode <47210458+GPUCode@users.noreply.github.com>

* Update src/core/loader.cpp

Co-authored-by: GPUCode <47210458+GPUCode@users.noreply.github.com>

* Update src/core/file_format/psf.cpp

Co-authored-by: GPUCode <47210458+GPUCode@users.noreply.github.com>

* loader namespace

* Update src/core/loader.cpp

Co-authored-by: GPUCode <47210458+GPUCode@users.noreply.github.com>

* constexpr magic

* linux qt ci by qurious

* fix for linux qt

* Make script executable

* ci fix?

---------

Co-authored-by: raziel1000 <ckraziel@gmail.com>
Co-authored-by: GPUCode <47210458+GPUCode@users.noreply.github.com>
Co-authored-by: GPUCode <geoster3d@gmail.com>
2024-03-01 00:00:35 +02:00

59 lines
1.7 KiB
C++

// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <cstring>
#include <fstream>
#include <iostream>
#include "common/io_file.h"
#include "psf.h"
PSF::PSF() = default;
PSF::~PSF() = default;
bool PSF::open(const std::string& filepath) {
Common::FS::IOFile file(filepath, Common::FS::FileAccessMode::Read);
if (!file.IsOpen()) {
return false;
}
const u64 psfSize = file.GetSize();
psf.resize(psfSize);
file.Seek(0);
file.Read(psf);
// Parse file contents
PSFHeader header;
std::memcpy(&header, psf.data(), sizeof(header));
for (u32 i = 0; i < header.index_table_entries; i++) {
PSFEntry entry;
std::memcpy(&entry, &psf[sizeof(PSFHeader) + i * sizeof(PSFEntry)], sizeof(entry));
const std::string key = (char*)&psf[header.key_table_offset + entry.key_offset];
if (entry.param_fmt == PSFEntry::Fmt::TextRaw ||
entry.param_fmt == PSFEntry::Fmt::TextNormal) {
map_strings[key] = (char*)&psf[header.data_table_offset + entry.data_offset];
}
if (entry.param_fmt == PSFEntry::Fmt::Integer) {
u32 value;
std::memcpy(&value, &psf[header.data_table_offset + entry.data_offset], sizeof(value));
map_integers[key] = value;
}
}
return true;
}
std::string PSF::GetString(const std::string& key) {
if (map_strings.find(key) != map_strings.end()) {
return map_strings.at(key);
}
return "";
}
u32 PSF::GetInteger(const std::string& key) {
if (map_integers.find(key) != map_integers.end()) {
return map_integers.at(key); // TODO std::invalid_argument exception if it fails?
}
return 0;
}