-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[kaineconv] tool to convert xap files
- Loading branch information
Showing
32 changed files
with
331 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
project(kaine) | ||
|
||
target_sources(kaine PRIVATE kaine.cpp) | ||
target_sources(kaine PRIVATE kaine.cpp arc.cpp bxon.cpp pack.cpp) | ||
|
||
add_subdirectory("bxon_types") | ||
|
||
add_subdirectory("arc") | ||
add_subdirectory("bxon") | ||
add_subdirectory("pack") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
project(kaine_bxon_types) | ||
|
||
target_sources(kaine PRIVATE tp_archive_file_param.cpp tp_gx_tex_head.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// | ||
// Created by Lilith on 2021-04-25. | ||
// | ||
|
||
#include <kaine/bxon_types/tp_gx_tex_head.hpp> | ||
|
||
#include <cassert> | ||
|
||
#include <standard_dragon/dds_support.hpp> | ||
#include <standard_dragon/exception/invalid_data.hpp> | ||
|
||
kaine::bxon_types::tp_gx_tex_head::tp_gx_tex_head(std::shared_ptr<dragon::Array<uint8_t>> &buffer) { | ||
auto data_start = reinterpret_cast<uintptr_t>(&width); | ||
#ifndef NDEBUG | ||
auto data_end = reinterpret_cast<uintptr_t>(&rel_offset_mip_surface) + sizeof(uint32_t); | ||
assert(data_end - data_start == EXPECTED_DATA_SIZE); | ||
#endif | ||
|
||
if (buffer->size() < EXPECTED_DATA_SIZE) { throw dragon::exception::invalid_data("Buffer passed to tp_gx_tex_head is not a valid tp_gx_tex_head buffer."); } | ||
|
||
buffer->copy(data_start, 0, EXPECTED_DATA_SIZE); | ||
|
||
uint8_t *ptr = buffer->data(); | ||
uint32_t offset; | ||
|
||
if (rel_offset_mip_surface > 0) { | ||
offset = rel_offset_mip_surface + MIP_SURFACE_OFFSET; | ||
mip_surfaces = dragon::Array<TexHeadMip>(reinterpret_cast<TexHeadMip *>(ptr + offset), mip_surface_count, true); | ||
} | ||
} | ||
|
||
std::shared_ptr<dragon::Array<uint8_t>> kaine::bxon_types::tp_gx_tex_head::generate_dds(std::shared_ptr<dragon::Array<uint8_t>> &resource, uintptr_t *offset) const { | ||
auto dds = standard_dragon::support::DDS{}; | ||
dds.dx9.linear_size = total_image_size; | ||
dds.dx9.width = width; | ||
dds.dx9.height = height; | ||
dds.dx9.mip_count = mip_surface_count; | ||
dds.dx10.array_size = surfaces; | ||
switch (format) { | ||
default: | ||
case XonSurfaceFormat::UNKNOWN: | ||
std::cerr << "warn: unrecognized XonSurfaceFormat 0x" << HEXLOG32 << static_cast<uint32_t>(format) << " defaulting to BC3_UNORM" << std::endl; | ||
dds.dx10.format = standard_dragon::support::DXGIFormat::BC3_UNORM; | ||
break; | ||
case XonSurfaceFormat::R8G8B8A8_UNORM: | ||
dds.dx10.format = standard_dragon::support::DXGIFormat::R8G8B8A8_UNORM; | ||
break; | ||
case XonSurfaceFormat::R8G8B8A8_UNORM_SRGB: | ||
dds.dx10.format = standard_dragon::support::DXGIFormat::R8G8B8A8_UNORM_SRGB; | ||
break; | ||
case XonSurfaceFormat::BC1_UNORM: | ||
dds.dx10.format = standard_dragon::support::DXGIFormat::BC1_UNORM; | ||
break; | ||
case XonSurfaceFormat::BC1_UNORM_SRGB: | ||
dds.dx10.format = standard_dragon::support::DXGIFormat::BC1_UNORM_SRGB; | ||
break; | ||
case XonSurfaceFormat::BC2_UNORM: | ||
dds.dx10.format = standard_dragon::support::DXGIFormat::BC2_UNORM; | ||
break; | ||
case XonSurfaceFormat::BC2_UNORM_SRGB: | ||
dds.dx10.format = standard_dragon::support::DXGIFormat::BC2_UNORM_SRGB; | ||
break; | ||
case XonSurfaceFormat::BC3_UNORM: | ||
dds.dx10.format = standard_dragon::support::DXGIFormat::BC3_UNORM; | ||
break; | ||
case XonSurfaceFormat::BC3_UNORM_SRGB: | ||
dds.dx10.format = standard_dragon::support::DXGIFormat::BC3_UNORM_SRGB; | ||
break; | ||
case XonSurfaceFormat::BC4_UNORM: | ||
dds.dx10.format = standard_dragon::support::DXGIFormat::BC4_UNORM; | ||
break; | ||
case XonSurfaceFormat::BC5_UNORM: | ||
dds.dx10.format = standard_dragon::support::DXGIFormat::BC5_UNORM; | ||
break; | ||
case XonSurfaceFormat::R32G32B32A32_FLOAT: | ||
dds.dx10.format = standard_dragon::support::DXGIFormat::R32G32B32A32_FLOAT; | ||
break; | ||
} | ||
|
||
auto buffer = std::make_shared<dragon::Array<uint8_t>>(total_image_size + sizeof(standard_dragon::support::DDS), nullptr); | ||
std::copy_n(reinterpret_cast<uint8_t *>(&dds), sizeof(standard_dragon::support::DDS), buffer->data()); | ||
auto ptr = reinterpret_cast<uintptr_t>(buffer->data() + sizeof(standard_dragon::support::DDS)); | ||
resource->lpcopy(&ptr, offset, total_image_size); | ||
return buffer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// | ||
// Created by Lilith on 2021-04-25. | ||
// | ||
|
||
#pragma once | ||
|
||
#include <kaine/bxon_types/abstract_bxon.hpp> | ||
|
||
#include <kaine/bxon_types/tp_archive_file_param.hpp> | ||
#include <kaine/bxon_types/tp_gx_tex_head.hpp> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
// Created by Lilith on 2021-04-25. | ||
// | ||
|
||
#pragma once | ||
|
||
#include <kaine/bxon_types/abstract_bxon.hpp> | ||
#include <kaine/kaine_export.h> | ||
|
||
#include <standard_dragon/Array.hpp> | ||
#include <standard_dragon/dragon.hpp> | ||
|
||
#include <cstdint> | ||
|
||
namespace kaine::bxon_types { | ||
class KAINE_EXPORT tp_gx_tex_head : public abstract_bxon { | ||
private: | ||
static constexpr uintptr_t EXPECTED_DATA_SIZE = 0x24; | ||
static constexpr uintptr_t MIP_SURFACE_OFFSET = 0x20; | ||
|
||
public: | ||
explicit tp_gx_tex_head(std::shared_ptr<dragon::Array<uint8_t>> &buffer); | ||
~tp_gx_tex_head() override = default; | ||
|
||
#pragma pack(push, 4) | ||
typedef struct TEX_HEAD_MIP_SURFACE { | ||
uint32_t offset; | ||
uint32_t unknown_1; | ||
uint32_t unknown_2; | ||
uint32_t unknown_3; | ||
uint32_t size; | ||
uint32_t unknown_5; | ||
uint32_t width; | ||
uint32_t height; | ||
uint32_t unknown_8; | ||
uint32_t unknown_9; | ||
} TexHeadMip; | ||
DRAGON_ASSERT(sizeof(TEX_HEAD_MIP_SURFACE) == 0x28, "ArchiveArcParam has an invalid size"); | ||
|
||
enum class XonSurfaceFormat : uint32_t { | ||
UNKNOWN = 0, | ||
R8G8B8A8_UNORM = 0x00010800, | ||
R8G8B8A8_UNORM_SRGB = 0x00010B00, | ||
BC1_UNORM = 0x00010F00, | ||
BC1_UNORM_SRGB = 0x00011000, | ||
BC2_UNORM = 0x00011100, | ||
BC2_UNORM_SRGB = 0x00011200, | ||
BC3_UNORM = 0x00011300, | ||
BC3_UNORM_SRGB = 0x00011400, | ||
BC4_UNORM = 0x00011500, | ||
BC5_UNORM = 0x00011600, | ||
R32G32B32A32_FLOAT = 0x00030000, | ||
}; | ||
|
||
struct { | ||
uint32_t width = 0; | ||
uint32_t height = 0; | ||
uint32_t surfaces = 0; | ||
uint32_t unknown_1 = 0; | ||
uint32_t total_image_size = 0; | ||
uint32_t unknown_2 = 0; | ||
XonSurfaceFormat format = XonSurfaceFormat::UNKNOWN; | ||
uint32_t mip_surface_count = 0; | ||
uint32_t rel_offset_mip_surface = 0; | ||
}; | ||
#pragma pack(pop) | ||
|
||
dragon::Array<TexHeadMip> mip_surfaces; | ||
|
||
std::shared_ptr<dragon::Array<uint8_t>> generate_dds(std::shared_ptr<dragon::Array<uint8_t>> &resource, uintptr_t *offset) const; | ||
|
||
static constexpr const char *bxon_name = "tpGxTexHead"; | ||
}; | ||
}// namespace kaine::bxon_types |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.