Seregon/ShadPKG

A tool for deriving PKG packet encryption keys for ps4 written in c++

C++/47.3 KB/No license
core/file_format/splash.cpp
ShadPKG / core / file_format / splash.cpp
1// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3 
4#include <fstream>
5 
6#include "common/assert.h"
7#include "common/io_file.h"
8#include "common/stb.h"
9#include "splash.h"
10 
11bool Splash::Open(const std::filesystem::path& filepath) {
12 ASSERT_MSG(filepath.extension().string() == ".png", "Unexpected file format passed");
13 
14 Common::FS::IOFile file(filepath, Common::FS::FileAccessMode::Read);
15 if (!file.IsOpen()) {
16 return false;
17 }
18 
19 std::vector<u8> png_file{};
20 const auto png_size = file.GetSize();
21 png_file.resize(png_size);
22 file.Seek(0);
23 file.Read(png_file);
24 
25 auto* img_mem = stbi_load_from_memory(png_file.data(), png_file.size(),
26 reinterpret_cast<int*>(&img_info.width),
27 reinterpret_cast<int*>(&img_info.height),
28 reinterpret_cast<int*>(&img_info.num_channels), 4);
29 if (!img_mem) {
30 return false;
31 }
32 
33 const auto img_size = img_info.GetSizeBytes();
34 img_data.resize(img_size);
35 std::memcpy(img_data.data(), img_mem, img_size);
36 stbi_image_free(img_mem);
37 return true;
38}
39