mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-05-20 18:34:58 +00:00
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>
This commit is contained in:
parent
99d013f612
commit
02cbebbf78
53 changed files with 5781 additions and 42 deletions
242
src/common/endian.h
Normal file
242
src/common/endian.h
Normal file
|
@ -0,0 +1,242 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
/**
|
||||
* (c) 2014-2016 Alexandro Sanchez Bach. All rights reserved.
|
||||
* Released under GPL v2 license. Read LICENSE for more details.
|
||||
* Some modifications for using with shadps4 by georgemoralis
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <bit>
|
||||
#include <concepts>
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Common {
|
||||
|
||||
/**
|
||||
* Native endianness
|
||||
*/
|
||||
template <typename T>
|
||||
using NativeEndian = T;
|
||||
|
||||
template <std::integral T>
|
||||
class SwappedEndian {
|
||||
public:
|
||||
const T& Raw() const {
|
||||
return data;
|
||||
}
|
||||
|
||||
T Swap() const {
|
||||
return std::byteswap(data);
|
||||
}
|
||||
|
||||
void FromRaw(const T& value) {
|
||||
data = value;
|
||||
}
|
||||
|
||||
void FromSwap(const T& value) {
|
||||
data = std::byteswap(value);
|
||||
}
|
||||
|
||||
operator const T() const {
|
||||
return Swap();
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
explicit operator const SwappedEndian<T1>() const {
|
||||
SwappedEndian<T1> res;
|
||||
if (sizeof(T1) < sizeof(T)) {
|
||||
res.FromRaw(Raw() >> ((sizeof(T) - sizeof(T1)) * 8));
|
||||
} else if (sizeof(T1) > sizeof(T)) {
|
||||
res.FromSwap(Swap());
|
||||
} else {
|
||||
res.FromRaw(Raw());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
SwappedEndian<T>& operator=(const T& right) {
|
||||
FromSwap(right);
|
||||
return *this;
|
||||
}
|
||||
SwappedEndian<T>& operator=(const SwappedEndian<T>& right) = default;
|
||||
|
||||
template <typename T1>
|
||||
SwappedEndian<T>& operator+=(T1 right) {
|
||||
return *this = T(*this) + right;
|
||||
}
|
||||
template <typename T1>
|
||||
SwappedEndian<T>& operator-=(T1 right) {
|
||||
return *this = T(*this) - right;
|
||||
}
|
||||
template <typename T1>
|
||||
SwappedEndian<T>& operator*=(T1 right) {
|
||||
return *this = T(*this) * right;
|
||||
}
|
||||
template <typename T1>
|
||||
SwappedEndian<T>& operator/=(T1 right) {
|
||||
return *this = T(*this) / right;
|
||||
}
|
||||
template <typename T1>
|
||||
SwappedEndian<T>& operator%=(T1 right) {
|
||||
return *this = T(*this) % right;
|
||||
}
|
||||
template <typename T1>
|
||||
SwappedEndian<T>& operator&=(T1 right) {
|
||||
return *this = T(*this) & right;
|
||||
}
|
||||
template <typename T1>
|
||||
SwappedEndian<T>& operator|=(T1 right) {
|
||||
return *this = T(*this) | right;
|
||||
}
|
||||
template <typename T1>
|
||||
SwappedEndian<T>& operator^=(T1 right) {
|
||||
return *this = T(*this) ^ right;
|
||||
}
|
||||
template <typename T1>
|
||||
SwappedEndian<T>& operator<<=(T1 right) {
|
||||
return *this = T(*this) << right;
|
||||
}
|
||||
template <typename T1>
|
||||
SwappedEndian<T>& operator>>=(T1 right) {
|
||||
return *this = T(*this) >> right;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
SwappedEndian<T>& operator+=(const SwappedEndian<T1>& right) {
|
||||
return *this = Swap() + right.Swap();
|
||||
}
|
||||
template <typename T1>
|
||||
SwappedEndian<T>& operator-=(const SwappedEndian<T1>& right) {
|
||||
return *this = Swap() - right.Swap();
|
||||
}
|
||||
template <typename T1>
|
||||
SwappedEndian<T>& operator*=(const SwappedEndian<T1>& right) {
|
||||
return *this = Swap() * right.Swap();
|
||||
}
|
||||
template <typename T1>
|
||||
SwappedEndian<T>& operator/=(const SwappedEndian<T1>& right) {
|
||||
return *this = Swap() / right.Swap();
|
||||
}
|
||||
template <typename T1>
|
||||
SwappedEndian<T>& operator%=(const SwappedEndian<T1>& right) {
|
||||
return *this = Swap() % right.Swap();
|
||||
}
|
||||
template <typename T1>
|
||||
SwappedEndian<T>& operator&=(const SwappedEndian<T1>& right) {
|
||||
return *this = Raw() & right.Raw();
|
||||
}
|
||||
template <typename T1>
|
||||
SwappedEndian<T>& operator|=(const SwappedEndian<T1>& right) {
|
||||
return *this = Raw() | right.Raw();
|
||||
}
|
||||
template <typename T1>
|
||||
SwappedEndian<T>& operator^=(const SwappedEndian<T1>& right) {
|
||||
return *this = Raw() ^ right.Raw();
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
SwappedEndian<T> operator&(const SwappedEndian<T1>& right) const {
|
||||
return SwappedEndian<T>{Raw() & right.Raw()};
|
||||
}
|
||||
template <typename T1>
|
||||
SwappedEndian<T> operator|(const SwappedEndian<T1>& right) const {
|
||||
return SwappedEndian<T>{Raw() | right.Raw()};
|
||||
}
|
||||
template <typename T1>
|
||||
SwappedEndian<T> operator^(const SwappedEndian<T1>& right) const {
|
||||
return SwappedEndian<T>{Raw() ^ right.Raw()};
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
bool operator==(T1 right) const {
|
||||
return (T1)Swap() == right;
|
||||
}
|
||||
template <typename T1>
|
||||
bool operator!=(T1 right) const {
|
||||
return !(*this == right);
|
||||
}
|
||||
template <typename T1>
|
||||
bool operator>(T1 right) const {
|
||||
return (T1)Swap() > right;
|
||||
}
|
||||
template <typename T1>
|
||||
bool operator<(T1 right) const {
|
||||
return (T1)Swap() < right;
|
||||
}
|
||||
template <typename T1>
|
||||
bool operator>=(T1 right) const {
|
||||
return (T1)Swap() >= right;
|
||||
}
|
||||
template <typename T1>
|
||||
bool operator<=(T1 right) const {
|
||||
return (T1)Swap() <= right;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
bool operator==(const SwappedEndian<T1>& right) const {
|
||||
return Raw() == right.Raw();
|
||||
}
|
||||
template <typename T1>
|
||||
bool operator!=(const SwappedEndian<T1>& right) const {
|
||||
return !(*this == right);
|
||||
}
|
||||
template <typename T1>
|
||||
bool operator>(const SwappedEndian<T1>& right) const {
|
||||
return (T1)Swap() > right.Swap();
|
||||
}
|
||||
template <typename T1>
|
||||
bool operator<(const SwappedEndian<T1>& right) const {
|
||||
return (T1)Swap() < right.Swap();
|
||||
}
|
||||
template <typename T1>
|
||||
bool operator>=(const SwappedEndian<T1>& right) const {
|
||||
return (T1)Swap() >= right.Swap();
|
||||
}
|
||||
template <typename T1>
|
||||
bool operator<=(const SwappedEndian<T1>& right) const {
|
||||
return (T1)Swap() <= right.Swap();
|
||||
}
|
||||
|
||||
SwappedEndian<T> operator++(int) {
|
||||
SwappedEndian<T> res = *this;
|
||||
*this += 1;
|
||||
return res;
|
||||
}
|
||||
SwappedEndian<T> operator--(int) {
|
||||
SwappedEndian<T> res = *this;
|
||||
*this -= 1;
|
||||
return res;
|
||||
}
|
||||
SwappedEndian<T>& operator++() {
|
||||
*this += 1;
|
||||
return *this;
|
||||
}
|
||||
SwappedEndian<T>& operator--() {
|
||||
*this -= 1;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
T data;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
using LittleEndian = std::conditional_t<std::endian::native == std::endian::little, NativeEndian<T>,
|
||||
SwappedEndian<T>>;
|
||||
|
||||
template <typename T>
|
||||
using BigEndian =
|
||||
std::conditional_t<std::endian::native == std::endian::big, NativeEndian<T>, SwappedEndian<T>>;
|
||||
|
||||
} // namespace Common
|
||||
|
||||
using u16_be = Common::BigEndian<u16>;
|
||||
using u32_be = Common::BigEndian<u32>;
|
||||
using u64_be = Common::BigEndian<u64>;
|
||||
|
||||
using u16_le = Common::LittleEndian<u16>;
|
||||
using u32_le = Common::LittleEndian<u32>;
|
||||
using u64_le = Common::LittleEndian<u64>;
|
|
@ -178,6 +178,11 @@ public:
|
|||
return std::fread(&object, sizeof(T), 1, file) == 1;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t WriteRaw(void* data, size_t size) const {
|
||||
return std::fwrite(data, sizeof(T), size, file);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool WriteObject(const T& object) const {
|
||||
static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable.");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue