Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #3 from REDxEYE/development
Browse files Browse the repository at this point in the history
Texture Load & Export
  • Loading branch information
ShadelessFox authored Aug 9, 2020
2 parents 7233dfa + 8eef782 commit 05fab12
Show file tree
Hide file tree
Showing 30 changed files with 422 additions and 188 deletions.
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@
[submodule "libs/imgui"]
path = libs/imgui
url = https://github.com/ocornut/imgui
[submodule "libs/detex"]
path = libs/detex
url = https://github.com/hglm/detex
[submodule "libs/libpng"]
path = libs/libpng
url = https://github.com/glennrp/libpng
[submodule "libs/zlib"]
path = libs/zlib
url = https://github.com/madler/zlib
11 changes: 7 additions & 4 deletions ArchiveTest.cmake
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
add_executable(ArchiveTest
src/archive_test.cpp
src/decima/archive/archive.cpp
src/decima/file_types/prefetch.cpp
src/decima/archive/archive_file.cpp
src/decima/archive/archive_array.cpp
src/utils.cpp
src/decima/file_types/prefetch.cpp
src/decima/file_types/prefetch.cpp
src/decima/file_types/core.cpp
src/decima/archive/archive_file.cpp)
src/decima/file_types/core_draw.cpp
src/utils.cpp
# src/decima/file_types/core_draw.cpp
)

target_include_directories(ArchiveTest PUBLIC include ${HASHLIB_INC} ${OOZLIB_INC})


target_link_libraries(ArchiveTest PUBLIC
HashLib oozLib
HashLib oozLib imgui
-static-libgcc -static-libstdc++ -static
-Wl,-Bstatic -lstdc++ -lpthread
-Wl,-Bdynamic
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ endif (DEBUG_MODE)
add_subdirectory(libs/hash)
add_subdirectory(libs/ooz)
add_subdirectory(libs/glfw)
add_subdirectory(libs/zlib)
add_subdirectory(libs/libpng)
add_subdirectory(cmake_subprojects/glad)
add_subdirectory(cmake_subprojects/stb)
add_subdirectory(cmake_subprojects/imgui)
add_subdirectory(cmake_subprojects/detex)

include(QuickHash.cmake)
include(ArchiveTest.cmake)
Expand Down
2 changes: 1 addition & 1 deletion ProjectDS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ target_include_directories(ProjectDS PUBLIC
)

target_link_libraries(ProjectDS PUBLIC
HashLib oozLib glfw glad imgui
HashLib oozLib glfw glad imgui detex
-static-libgcc -static-libstdc++ -static
-Wl,-Bstatic -lstdc++ -lpthread
-Wl,-Bdynamic
Expand Down
2 changes: 2 additions & 0 deletions cmake_subprojects/detex/alloca.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include <malloc.h>
#include <string.h>
4 changes: 4 additions & 0 deletions include/ash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ namespace ash {
pos = std::min(pos + amount, cap);
}

[[nodiscard]] bool eof() const noexcept {
return cur == end;
}

[[nodiscard]] std::size_t tell() const noexcept {
return std::distance(beg, cur);
}
Expand Down
4 changes: 2 additions & 2 deletions include/decima/archive/archive_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ namespace Decima {

class CompressedFile {
public:

CompressedFile(FileEntry* file_entry_, mio::mmap_source* filebuffer_,Archive* archive_);
CompressedFile(FileEntry* file_entry_, mio::mmap_source* filebuffer_, Archive* archive_, bool encrypted_);

CompressedFile() = default;

std::pair<std::vector<ChunkEntry>::iterator, std::vector<ChunkEntry>::iterator> chunk_range;
FileEntry* file_entry = nullptr;
mio::mmap_source* filebuffer = nullptr;
Archive* archive = nullptr;
bool encrypted = true;

std::vector<uint8_t> storage;

Expand Down
28 changes: 12 additions & 16 deletions include/decima/archive/archive_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,27 @@
#include "archive_file.h"

struct SelectionInfo {
std::uint64_t preview_file{0};
std::uint64_t selected_file{0};
SelectionInfo() = default;
std::uint64_t preview_file { 0 };
std::uint64_t preview_file_size { 0 };
std::uint64_t preview_file_offset { 0 };
std::uint64_t selected_file { 0 };
std::unordered_set<std::uint64_t> selected_files;
Decima::CompressedFile file;
};

struct FileInfo {
uint64_t hash{0};
Decima::CoreHeader header{0};
uint64_t hash { 0 };
Decima::CoreHeader header { 0 };
};

struct FileTypeHandler {
std::string name;
std::function<void(Decima::CompressedFile&, bool update)> render = nullptr;
};

template<class T>
template <class T>
using FileTreeToggleable = std::pair<T, bool>;

class FileTree {
public:
std::map<std::string, FileTreeToggleable<std::unique_ptr<FileTree>>> folders;
std::map<std::string, FileTreeToggleable<FileInfo>> files;
// std::unordered_map<std::uint64_t, FileTypeHandler> file_type_handlers;


FileTree* add_folder(const std::string& name);

Expand All @@ -52,19 +48,19 @@ class FileTree {

void reset_filter(bool state);

template<typename Visitor>
template <typename Visitor>
void visit(const Visitor& visitor, std::size_t depth = 0) const {
for (const auto&[name, data] : folders) {
for (const auto& [name, data] : folders) {
visitor(name, depth);
data.first->visit(visitor, depth + 1);
}

for (const auto&[name, _] : files) {
for (const auto& [name, _] : files) {
visitor(name, depth);
}
}

void draw(SelectionInfo& selection, Decima::ArchiveArray& archive_array);
void draw(SelectionInfo& selection, Decima::ArchiveArray& archive_array, bool draw_header = true);
};

#endif //PROJECTDS_ARCHIVE_TREE_H
5 changes: 5 additions & 0 deletions include/decima/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ namespace Decima {
static constexpr uint64_t Translation = 0x31be502435317445;
static constexpr uint64_t Model = 0x16bb69a9e5aa0d9e;
};
class ZeroDawn_FileMagics : public FileMagics {
public:
static constexpr uint64_t Texture = 0xf2e1afb7052b3866;

};

enum class Version : uint32_t {
default_version = 0x20304050,
Expand Down
4 changes: 3 additions & 1 deletion include/decima/file_types/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "ash.hpp"
#include "shared.hpp"

class ProjectDS;

namespace Decima {
struct GUID {
std::uint64_t data[2];
Expand All @@ -36,7 +38,7 @@ namespace Decima {

virtual void parse(Source& stream);

virtual void draw(ArchiveArray& archive_array);
virtual void draw(ProjectDS& ctx);
};

std::string read_string(CoreFile::Source& stream, const std::string& default_value = "<empty>");
Expand Down
44 changes: 27 additions & 17 deletions include/decima/file_types/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#define PROJECTDS_TEXTURE_H

#include "decima/file_types/core.h"

namespace Decima {
enum class TexturePixelFormat : uint8_t {
R8G8B8A8 = 0xC,
RGBA8 = 0xC,
A8 = 0x1F,
BC1 = 0x42,
BC2 = 0x43,
Expand All @@ -18,26 +19,35 @@ namespace Decima {
BC7 = 0x4B,
};

std::ostream& operator<<(std::ostream& os, Decima::TexturePixelFormat fmt);

class Texture : public CoreFile {
public:
uint16_t unk1{};
uint16_t width{};
uint16_t height{};
uint16_t layers{};
uint8_t mip_count{};
TexturePixelFormat pixel_format{};
uint16_t unk2{};
uint32_t unk3{};
uint64_t file_guid[2]{};
uint32_t buffer_size{};
uint32_t total_size{};
uint32_t unks[4]{};

std::string stream_name="NO_EXTERNAL_STREAM";
~Texture();

std::uint16_t unk1 {};
std::uint16_t width {};
std::uint16_t height {};
std::uint16_t layers {};
std::uint8_t mip_count {};
TexturePixelFormat pixel_format {};
std::uint16_t unk2 {};
std::uint32_t unk3 {};
GUID file_guid {};
std::uint32_t buffer_size {};
std::uint32_t total_size {};
std::uint32_t stream_size {};
std::uint32_t unks[3] {};

std::vector<std::uint8_t> stream_buffer;
std::vector<std::uint8_t> image_buffer;
unsigned int image_texture;

std::string stream_name = "NO_EXTERNAL_STREAM";

void parse(Source& stream) override;
void draw(ArchiveArray& archive_array) override;
void draw(ProjectDS& ctx) override;
void draw_texture(ProjectDS& ctx, float preview_width, float preview_height, float zoom_region, float zoom_scale);
};

}
#endif //PROJECTDS_TEXTURE_H
3 changes: 1 addition & 2 deletions include/decima/file_types/translation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ namespace Decima {
std::uint8_t flags[std::size(languages)];

void parse(Source& stream) override;

void draw(ArchiveArray& archive_array) override;
void draw(ProjectDS& ctx) override;
};

}
Expand Down
4 changes: 2 additions & 2 deletions include/projectds_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ class ProjectDS : public App {
ProjectDS(const std::pair<uint32_t, uint32_t>& windowSize, const std::string& title,
bool imgui_multi_viewport = false);

private:
public:
bool m_multi_viewport;

Decima::ArchiveArray archive_array;
std::vector<const char*> file_names;
FileTree root_tree;
SelectionInfo selection_info;
std::vector<std::shared_ptr<Decima::CoreFile>> parsed_files;
std::vector<std::unique_ptr<Decima::CoreFile>> parsed_files;
int32_t file_id = 0;
ImGuiTextFilter filter;
MemoryEditor file_viewer;
Expand Down
1 change: 1 addition & 0 deletions libs/detex
Submodule detex added at cab115
1 change: 1 addition & 0 deletions libs/libpng
Submodule libpng added at dbe3e0
3 changes: 1 addition & 2 deletions libs/ooz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ set(OOZLIB_INC
)


set(GCC_COVERAGE_COMPILE_FLAGS -Wpsabi)



SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O0")
add_library(oozLib Kraken.cpp)

#if (DEBUG_MODE)
Expand Down
1 change: 1 addition & 0 deletions libs/zlib
Submodule zlib added at cacf7f
2 changes: 1 addition & 1 deletion src/archive_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "decima/archive/archive.h"

int main() {
Decima::ArchiveArray archive_array(R"(F:\SteamLibrary\steamapps\common\Death Stranding\data)");
Decima::ArchiveArray archive_array(R"(F:\SteamLibrary\steamapps\common\Horizon Zero Dawn\Packed_DX12)");

archive_array.read_prefetch_file();

Expand Down
7 changes: 2 additions & 5 deletions src/decima/archive/archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
#include <MurmurHash3.h>
#include <md5.h>

template <class T>
using slice = std::pair<std::decay_t<T>, std::decay_t<T>>;

Decima::Archive::Archive(const std::string& workdir, const std::string& filename)
: filepath(workdir + "\\" + filename) { }

Expand Down Expand Up @@ -135,10 +132,10 @@ Decima::CompressedFile Decima::Archive::query_file(uint64_t file_hash) {
// log("Archive", "Queried " + uint64_to_hex(file_hash) + " file");
auto file_id = get_file_index(file_hash);
if (file_id == -1) {
return Decima::CompressedFile(nullptr, nullptr, nullptr);
return Decima::CompressedFile(nullptr, nullptr, nullptr, true);
}
auto& file_entry = content_table.at(file_id);
Decima::CompressedFile file(&file_entry, &filebuffer, this);
Decima::CompressedFile file(&file_entry, &filebuffer, this, is_encrypted());

file.chunk_range = get_mio_boundaries(file_id);

Expand Down
9 changes: 5 additions & 4 deletions src/decima/archive/archive_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "utils.h"
#include "decima/archive/archive_array.h"
#include "decima/archive/archive.h"

Decima::ArchiveArray::ArchiveArray(const std::string& _workdir) {
open(_workdir);
Expand All @@ -24,8 +23,10 @@ void Decima::ArchiveArray::read_prefetch_file() {

for (auto& string : prefetch.strings) {
uint64_t hash = hash_string(sanitize_name(string.string), seed);
hash_to_name[hash] = string.string;
hash_to_name.insert({ hash, string.string });
}

hash_to_name.insert({ 0x2fff5af65cd64c0a, "prefetch/fullgame.prefetch" });
}

void Decima::ArchiveArray::open(const std::string& _workdir) {
Expand Down Expand Up @@ -57,7 +58,7 @@ Decima::ArchiveArray::get_file_entry(uint64_t file_hash) {
uint64_t archive_id = hash_to_archive.at(file_hash);
auto& archive = archives[archive_id];
uint64_t file_id = archive.get_file_index(file_hash);
return std::optional<std::reference_wrapper<FileEntry>> {archive.content_table[file_id] };
return std::optional<std::reference_wrapper<FileEntry>> { archive.content_table[file_id] };
}
return std::nullopt;
}
Expand All @@ -68,7 +69,7 @@ Decima::CompressedFile Decima::ArchiveArray::query_file(uint64_t file_hash) {
auto& archive = archives[archive_id->second];
return std::move(archive.query_file(file_hash));
}
return Decima::CompressedFile(nullptr, nullptr,nullptr);
return Decima::CompressedFile(nullptr, nullptr, nullptr, true);
}

Decima::CompressedFile Decima::ArchiveArray::query_file(const std::string& file_name) {
Expand Down
Loading

0 comments on commit 05fab12

Please sign in to comment.