libcmo21/Unvirt/StructFormatter.cpp

644 lines
25 KiB
C++
Raw Normal View History

2023-02-14 16:28:37 +08:00
#include "StructFormatter.hpp"
#include <YYCCommonplace.hpp>
2023-02-14 16:28:37 +08:00
#include "AccessibleValue.hpp"
#include "TerminalHelper.hpp"
namespace Console = YYCC::ConsoleHelper;
2023-03-04 00:13:03 +08:00
namespace Unvirt::StructFormatter {
2023-08-27 22:14:02 +08:00
#pragma region Assist Functions
static std::u8string PrintCKSTRING(LibCmo::CKSTRING name) {
std::u8string ret;
2023-08-29 10:42:13 +08:00
if (name == nullptr) {
ret = YYCC_COLOR_LIGHT_MAGENTA(u8"<anonymous>");
2023-08-27 22:14:02 +08:00
} else {
if (name[0] == u8'\0') {
ret = YYCC_COLOR_LIGHT_MAGENTA(u8"<blank>");
2023-08-29 10:42:13 +08:00
} else {
ret = name;
2023-08-29 10:42:13 +08:00
}
2023-08-27 22:14:02 +08:00
}
return ret;
2023-08-27 22:14:02 +08:00
}
static std::u8string PrintPointer(const void* ptr) {
std::u8string ret;
2023-08-27 22:14:02 +08:00
if (ptr == nullptr) {
ret = YYCC_COLOR_LIGHT_CYAN(u8"<null>");
2023-08-27 22:14:02 +08:00
} else {
YYCC::StringHelper::Printf(ret, u8"<0x%" PRI_XPTR_LEFT_PADDING PRIxPTR ">", reinterpret_cast<uintptr_t>(ptr));
2023-08-27 22:14:02 +08:00
}
return ret;
2023-08-27 22:14:02 +08:00
}
static std::u8string PrintCKGUID(const LibCmo::CK2::CKGUID& guid) {
return YYCC::StringHelper::Printf(u8"<0x%08" PRIxCKDWORD ", 0x%08" PRIxCKDWORD ">", guid.d1, guid.d2);
2023-08-27 22:14:02 +08:00
}
static std::u8string PrintBool(bool v) {
return (v ? u8"true" : u8"false");
2023-09-22 16:40:10 +08:00
}
static std::u8string PrintColorfulBool(bool v) {
return (v ? YYCC_COLOR_LIGHT_GREEN(u8"Yes") : YYCC_COLOR_LIGHT_RED(u8"No"));
}
static std::u8string PrintColor(LibCmo::CKDWORD argb) {
2023-09-22 16:40:10 +08:00
LibCmo::CKDWORD a = (argb & 0xFF000000) >> 24,
r = (argb & 0x00FF0000) >> 16,
g = (argb & 0x0000FF00) >> 8,
b = (argb & 0x000000FF);
LibCmo::CKFLOAT fa = static_cast<LibCmo::CKFLOAT>(a) / 255.0f;
return YYCC::StringHelper::Printf(
u8"A:%" PRIuCKDWORD " (%.4" PRIfCKFLOAT ") "
"RGB(%" PRIuCKDWORD ", %" PRIuCKDWORD ", %" PRIuCKDWORD ") "
"RGB#%02" PRIxCKDWORD "%02" PRIxCKDWORD "%02" PRIxCKDWORD " "
"RGBA#%02" PRIxCKDWORD "%02" PRIxCKDWORD "%02" PRIxCKDWORD "%02" PRIxCKDWORD,
a, fa,
r, g, b,
r, g, b,
2023-09-22 16:40:10 +08:00
r, g, b, a
);
}
static std::u8string PrintColor(const LibCmo::VxMath::VxColor& col) {
return PrintColor(col.ToARGB());
2023-09-22 22:31:51 +08:00
}
2023-08-29 10:42:13 +08:00
2023-08-27 22:14:02 +08:00
template<class _Ty>
static void GeneralPrintList(
const std::vector<_Ty>& data, size_t page, size_t pageitems,
2023-08-29 10:42:13 +08:00
std::function<void()> printHdrFct, std::function<void(size_t, const _Ty&)> printEntryFct) {
2023-08-27 22:14:02 +08:00
// check page overflow
if (page * pageitems >= data.size()) {
Console::WriteLine(YYCC_COLOR_LIGHT_RED(u8"Page out of range."));
return;
}
// calc page data
2023-08-27 22:14:02 +08:00
size_t fulllen = data.size(),
startpos = page * pageitems,
fullpage = (fulllen + (pageitems - 1)) / pageitems; // to solve `fulllen / pageitems` empty page issue. like CKStateChunk::GetCeilDwordSize function (+3 /4 to get DWORD size).
2023-08-27 22:14:02 +08:00
// print header
printHdrFct();
// print body
for (size_t counter = startpos; counter < fulllen && (counter - startpos) < pageitems; ++counter) {
printEntryFct(counter, data[counter]);
}
Console::FormatLine(u8"Page %" PRIuSIZET " of %" PRIuSIZET, page + 1, fullpage);
2023-08-27 22:14:02 +08:00
}
#pragma endregion
2023-03-04 00:13:03 +08:00
2023-09-19 10:53:48 +08:00
#pragma region Object Printer
2023-09-22 16:40:10 +08:00
2023-09-19 10:53:48 +08:00
static void PrintCKObjectDetail(LibCmo::CK2::ObjImpls::CKObject* obj) {
Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"CKObject"));
// print name
Console::FormatLine(u8"Name: %s", PrintCKSTRING(obj->GetName()).c_str());
// print id
Console::FormatLine(u8"CK ID: %" PRIuCKID, obj->GetID());
// print class id
Console::FormatLine(u8"Class ID: %" PRIiCLASSID " (%s)", obj->GetClassID(), AccessibleValue::GetClassIdHierarchy(obj->GetClassID()).c_str());
2023-09-22 22:31:51 +08:00
// print flags
Console::WriteLine(u8"Flags:");
Console::WriteLine(AccessibleValue::GetFlagEnumName(obj->GetObjectFlags(), AccessibleValue::EnumDesc::CK_OBJECT_FLAGS, u8"\n", u8"\t").c_str());
2023-09-19 10:53:48 +08:00
}
2023-09-22 16:40:10 +08:00
2023-09-19 10:53:48 +08:00
static void PrintCKSceneObjectDetail(LibCmo::CK2::ObjImpls::CKSceneObject* obj) {
PrintCKObjectDetail(obj);
Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"CKSceneObject"));
Console::WriteLine(YYCC_COLOR_LIGHT_RED(u8"No Data"));
2023-09-19 10:53:48 +08:00
}
static void PrintCKBeObjectDetail(LibCmo::CK2::ObjImpls::CKBeObject* obj) {
PrintCKSceneObjectDetail(obj);
Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"CKBeObject"));
Console::WriteLine(YYCC_COLOR_LIGHT_RED(u8"No Data"));
2023-09-19 10:53:48 +08:00
}
static void PrintCKGroupDetail(LibCmo::CK2::ObjImpls::CKGroup* obj) {
PrintCKBeObjectDetail(obj);
Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"CKGroup"));
2023-09-22 16:40:10 +08:00
LibCmo::CKDWORD count = obj->GetObjectCount();
Console::FormatLine(u8"Group Object Count: %" PRIuCKDWORD, count);
Console::WriteLine(u8"CKID\tType\tObject\tName");
for (LibCmo::CKDWORD i = 0; i < count; ++i) {
LibCmo::CK2::ObjImpls::CKBeObject* beobj = obj->GetObject(i);
2023-09-22 16:40:10 +08:00
Console::FormatLine(u8"%" PRIuCKID "\t%s\t%s\t%s",
beobj->GetID(),
AccessibleValue::GetClassIdName(beobj->GetClassID()).c_str(),
PrintPointer(beobj).c_str(),
2024-08-24 21:27:23 +08:00
(beobj != nullptr ? PrintCKSTRING(beobj->GetName()).c_str() : u8"")
);
}
}
2023-09-22 16:40:10 +08:00
static void PrintCKRenderObjectDetail(LibCmo::CK2::ObjImpls::CKRenderObject* obj) {
PrintCKBeObjectDetail(obj);
Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"CKRenderObject"));
Console::WriteLine(YYCC_COLOR_LIGHT_RED(u8"No Data"));
}
2023-09-22 16:40:10 +08:00
static void PrintCK3dEntityDetail(LibCmo::CK2::ObjImpls::CK3dEntity* obj) {
PrintCKRenderObjectDetail(obj);
Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"CK3dEntity"));
2023-09-22 16:40:10 +08:00
Console::WriteLine(u8"== World Matrix ==");
2023-09-22 16:40:10 +08:00
auto mat = obj->GetWorldMatrix();
for (LibCmo::CKDWORD i = 0; i < 4; ++i) {
Console::FormatLine(u8"%+" PRIeCKFLOAT "\t%+" PRIeCKFLOAT "\t%+" PRIeCKFLOAT "\t%+" PRIeCKFLOAT,
2023-09-22 16:40:10 +08:00
mat[i].x, mat[i].y, mat[i].z, mat[i].w
);
}
Console::WriteLine(u8"== Flags ==");
Console::WriteLine(u8"3dEntity Flags:");
Console::WriteLine(AccessibleValue::GetFlagEnumName(obj->GetEntityFlags(), AccessibleValue::EnumDesc::CK_3DENTITY_FLAGS, u8"\n", u8"\t").c_str());
Console::WriteLine(u8"Moveable Flags:");
Console::WriteLine(AccessibleValue::GetFlagEnumName(obj->GetMoveableFlags(), AccessibleValue::EnumDesc::VX_MOVEABLE_FLAGS, u8"\n", u8"\t").c_str());
2023-09-22 16:40:10 +08:00
Console::WriteLine(u8"== Meshs ==");
Console::WriteLine(u8"Index\tAddress\tName");
2023-09-22 16:40:10 +08:00
// print current mesh
{
auto curmesh = obj->GetCurrentMesh();
2024-08-24 21:27:23 +08:00
Console::Format(u8"->\t%s\t%s",
PrintPointer(curmesh).c_str(),
(curmesh != nullptr ? PrintCKSTRING(curmesh->GetName()).c_str() : u8"")
);
}
// print other meshes
2023-09-22 16:40:10 +08:00
for (LibCmo::CKDWORD i = 0; i < obj->GetPotentialMeshCount(); ++i) {
auto thismesh = obj->GetPotentialMesh(i);
Console::FormatLine(u8"#%" PRIuCKDWORD "\t%s\t%s",
i,
PrintPointer(thismesh).c_str(),
2024-08-24 21:27:23 +08:00
(thismesh != nullptr ? PrintCKSTRING(thismesh->GetName()).c_str() : u8"")
);
2023-09-22 16:40:10 +08:00
}
}
2023-09-22 16:40:10 +08:00
static void PrintCK3dObjectDetail(LibCmo::CK2::ObjImpls::CK3dObject* obj) {
PrintCK3dEntityDetail(obj);
Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"CK3dObject"));
Console::WriteLine(YYCC_COLOR_LIGHT_RED(u8"No Data"));
}
2023-09-22 16:40:10 +08:00
static void PrintCKTextureDetail(LibCmo::CK2::ObjImpls::CKTexture* obj) {
PrintCKBeObjectDetail(obj);
Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"CKTexture"));
2023-09-22 22:31:51 +08:00
// texture
Console::WriteLine(u8"== Texture ==");
2023-09-22 22:31:51 +08:00
LibCmo::CK2::CKBitmapData& bd = obj->GetUnderlyingData();
LibCmo::CKDWORD slot_count = bd.GetSlotCount();
Console::FormatLine(u8"Slot Count: %" PRIuCKDWORD, slot_count);
Console::FormatLine(u8"Current Slot: %" PRIuCKDWORD, bd.GetCurrentSlot());
2023-09-22 22:31:51 +08:00
Console::WriteLine(u8"Index\tWidth\tHeight\tImage Addr\tImage Size\tFilename");
2023-09-22 22:31:51 +08:00
for (LibCmo::CKDWORD i = 0; i < slot_count; ++i) {
auto desc = bd.GetImageDesc(i);
Console::FormatLine(u8"#%" PRIuCKDWORD "\t%" PRIuCKDWORD "\t%" PRIuCKDWORD "\t0x%" PRIxCKDWORD " bytes\t",
i,
desc->GetWidth(),
desc->GetHeight(),
PrintPointer(desc->GetImage()).c_str(),
desc->GetImageSize(),
PrintCKSTRING(bd.GetSlotFileName(i)).c_str()
);
2023-09-22 22:31:51 +08:00
}
// other data
Console::WriteLine(u8"== Misc ==");
Console::FormatLine(u8"Video Format: %s", AccessibleValue::GetEnumName(obj->GetVideoFormat(), AccessibleValue::EnumDesc::VX_PIXELFORMAT).c_str());
Console::FormatLine(u8"Save Option: %s", AccessibleValue::GetEnumName(bd.GetSaveOptions(), AccessibleValue::EnumDesc::CK_TEXTURE_SAVEOPTIONS).c_str());
Console::FormatLine(u8"Pick Threshold: %" PRIuCKDWORD, bd.GetPickThreshold());
Console::FormatLine(u8"Transparent Color: %s", PrintColor(bd.GetTransparentColor()).c_str());
Console::WriteLine(u8"Bitmap Flags:");
Console::WriteLine(AccessibleValue::GetFlagEnumName(bd.GetBitmapFlags(), AccessibleValue::EnumDesc::CK_BITMAPDATA_FLAGS, u8"\n", u8"\t").c_str());
}
2023-09-22 16:40:10 +08:00
static void PrintCKMaterialDetail(LibCmo::CK2::ObjImpls::CKMaterial* obj) {
PrintCKBeObjectDetail(obj);
Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"CKMaterial"));
2023-09-22 16:40:10 +08:00
// color
Console::WriteLine(u8"== Color ==");
2023-09-22 16:40:10 +08:00
2024-08-24 21:27:23 +08:00
Console::FormatLine(u8"Diffuse: %s", PrintColor(obj->GetDiffuse()).c_str());
Console::FormatLine(u8"Ambient: %s", PrintColor(obj->GetAmbient()).c_str());
Console::FormatLine(u8"Specular: %s", PrintColor(obj->GetSpecular()).c_str());
Console::FormatLine(u8"Emissive: %s", PrintColor(obj->GetEmissive()).c_str());
2023-09-22 16:40:10 +08:00
Console::FormatLine(u8"Specular Power: %.2" PRIfCKFLOAT, obj->GetSpecularPower());
2023-09-22 16:40:10 +08:00
// basic data
Console::WriteLine(u8"== Basic ==");
2024-08-24 21:27:23 +08:00
Console::FormatLine(u8"Both Sided: %s", PrintBool(obj->GetTwoSidedEnabled()).c_str());
Console::FormatLine(u8"Fill Mode: %s", AccessibleValue::GetEnumName(obj->GetFillMode(), AccessibleValue::EnumDesc::VXFILL_MODE).c_str());
Console::FormatLine(u8"Shade Mode: %s", AccessibleValue::GetEnumName(obj->GetShadeMode(), AccessibleValue::EnumDesc::VXSHADE_MODE).c_str());
2023-09-22 16:40:10 +08:00
// textures
Console::WriteLine(u8"== Texture ==");
Console::WriteLine(u8"Textures:");
Console::WriteLine(u8"Index\tAddress\tName");
2023-09-22 16:40:10 +08:00
for (LibCmo::CKDWORD i = 0; i < 4; ++i) {
auto tex = obj->GetTexture(i);
2024-08-24 21:27:23 +08:00
Console::FormatLine(u8"#%" PRIuCKDWORD "\t%s\t%s",
i,
PrintPointer(tex).c_str(),
(tex != nullptr ? PrintCKSTRING(tex->GetName()).c_str() : u8"")
);
2023-09-22 16:40:10 +08:00
}
Console::FormatLine(u8"Texture Blend: %s", AccessibleValue::GetEnumName(obj->GetTextureBlendMode(), AccessibleValue::EnumDesc::VXTEXTURE_BLENDMODE).c_str());
Console::FormatLine(u8"Filter Min: %s", AccessibleValue::GetEnumName(obj->GetTextureMinMode(), AccessibleValue::EnumDesc::VXTEXTURE_FILTERMODE).c_str());
Console::FormatLine(u8"Filter Mag: %s", AccessibleValue::GetEnumName(obj->GetTextureMagMode(), AccessibleValue::EnumDesc::VXTEXTURE_FILTERMODE).c_str());
Console::FormatLine(u8"Address Mode: %s", AccessibleValue::GetEnumName(obj->GetTextureAddressMode(), AccessibleValue::EnumDesc::VXTEXTURE_ADDRESSMODE).c_str());
2024-08-24 21:27:23 +08:00
Console::FormatLine(u8"Perspective Correct: %s", PrintBool(obj->GetPerspectiveCorrectionEnabled()).c_str());
2023-09-22 16:40:10 +08:00
// alpha test
Console::WriteLine(u8"== Alpha Test ==");
2024-08-24 21:27:23 +08:00
Console::FormatLine(u8"Enabled: %s", PrintBool(obj->GetAlphaTestEnabled()).c_str());
Console::FormatLine(u8"Alpha Function: %s", AccessibleValue::GetEnumName(obj->GetAlphaFunc(), AccessibleValue::EnumDesc::VXCMPFUNC).c_str());
Console::FormatLine(u8"Alpha Ref Value: %" PRIuCKBYTE, obj->GetAlphaRef());
2023-09-22 16:40:10 +08:00
// alpha blend
Console::WriteLine(u8"== Alpha Blend ==");
2024-08-24 21:27:23 +08:00
Console::FormatLine(u8"Enabled: %s", PrintBool(obj->GetAlphaBlendEnabled()).c_str());
Console::FormatLine(u8"Source Blend: %s", AccessibleValue::GetEnumName(obj->GetSourceBlend(), AccessibleValue::EnumDesc::VXBLEND_MODE).c_str());
Console::FormatLine(u8"Destination Blend: %s", AccessibleValue::GetEnumName(obj->GetDestBlend(), AccessibleValue::EnumDesc::VXBLEND_MODE).c_str());
2023-09-22 16:40:10 +08:00
// z buffer
Console::WriteLine(u8"== Z-Buffer Write ==");
2024-08-24 21:27:23 +08:00
Console::FormatLine(u8"Enabled: %s", PrintBool(obj->GetZWriteEnabled()).c_str());
Console::FormatLine(u8"Z Compare Function: %s", AccessibleValue::GetEnumName(obj->GetZFunc(), AccessibleValue::EnumDesc::VXCMPFUNC).c_str());
2023-09-22 16:40:10 +08:00
// effect
Console::WriteLine(u8"== Effect ==");
Console::FormatLine(u8"Effect: %s", AccessibleValue::GetEnumName(obj->GetEffect(), AccessibleValue::EnumDesc::VX_EFFECT).c_str());
2023-09-22 16:40:10 +08:00
}
2023-09-22 16:40:10 +08:00
2023-09-19 10:53:48 +08:00
static void PrintCKMeshDetail(LibCmo::CK2::ObjImpls::CKMesh* obj) {
PrintCKBeObjectDetail(obj);
Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"CKMesh"));
Console::WriteLine(u8"== Flags ==");
Console::WriteLine(u8"Mesh Flags:");
2024-08-24 21:27:23 +08:00
Console::WriteLine(AccessibleValue::GetFlagEnumName(obj->GetMeshFlags(), AccessibleValue::EnumDesc::VXMESH_FLAGS, u8"\n", u8"\t").c_str());
Console::FormatLine(u8"Lit Mode: %s", AccessibleValue::GetEnumName(obj->GetLitMode(), AccessibleValue::EnumDesc::VXMESH_LITMODE).c_str());
Console::FormatLine(u8"Wrap Mode: %s", AccessibleValue::GetEnumName(obj->GetWrapMode(), AccessibleValue::EnumDesc::VXTEXTURE_WRAPMODE).c_str());
2023-09-22 16:40:10 +08:00
// vertex data
Console::WriteLine(u8"== Vertex ==");
Console::FormatLine(u8"Vertex Count: %" PRIuCKDWORD, obj->GetVertexCount());
Console::WriteLine(u8"Address\tSize\tType");
2023-09-19 10:53:48 +08:00
2024-08-24 21:27:23 +08:00
Console::FormatLine(u8"%s\t0x%" PRIxCKDWORD " bytes\tPositions",
PrintPointer(obj->GetVertexPositions()).c_str(),
obj->GetVertexCount() * CKSizeof(LibCmo::VxMath::VxVector3)
);
Console::FormatLine(u8"%s\t0x%" PRIxCKDWORD " bytes\tNormals",
PrintPointer(obj->GetVertexNormals()).c_str(),
obj->GetVertexCount() * CKSizeof(LibCmo::VxMath::VxVector3)
);
Console::FormatLine(u8"%s\t0x%" PRIxCKDWORD " bytes\tUVs",
PrintPointer(obj->GetVertexUVs()).c_str(),
obj->GetVertexCount() * CKSizeof(LibCmo::VxMath::VxVector2)
);
Console::FormatLine(u8"%s\t0x%" PRIxCKDWORD " bytes\tColors",
PrintPointer(obj->GetVertexColors()).c_str(),
obj->GetVertexCount() * CKSizeof(LibCmo::CKDWORD)
);
Console::FormatLine(u8"%s\t0x%" PRIxCKDWORD " bytes\tSpecularColors",
PrintPointer(obj->GetVertexSpecularColors()).c_str(),
obj->GetVertexCount() * CKSizeof(LibCmo::CKDWORD)
);
2023-09-22 16:40:10 +08:00
// face data
Console::WriteLine(u8"== Face ==");
Console::FormatLine(u8"Face Count: %" PRIuCKDWORD, obj->GetFaceCount());
Console::WriteLine(u8"Address\tSize\tType");
2023-09-22 16:40:10 +08:00
2024-08-24 21:27:23 +08:00
Console::FormatLine(u8"%s\t0x%" PRIxCKDWORD " bytes\tIndices",
PrintPointer(obj->GetFaceIndices()).c_str(),
obj->GetFaceCount() * 3 * CKSizeof(LibCmo::CKWORD)
);
Console::FormatLine(u8"%s\t0x%" PRIxCKDWORD " bytes\tMaterialSlotIndexs",
PrintPointer(obj->GetFaceMaterialSlotIndexs()).c_str(),
obj->GetFaceCount() * CKSizeof(LibCmo::CKWORD)
);
2023-09-19 10:53:48 +08:00
// mtl slot data
Console::WriteLine(u8"== Material Slot ==");
LibCmo::CKDWORD slotcount = obj->GetMaterialSlotCount();
LibCmo::CK2::ObjImpls::CKMaterial** pMtlSlots = obj->GetMaterialSlots();
Console::FormatLine(u8"Material Slot Count: %" PRIuCKDWORD, slotcount);
Console::WriteLine(u8"Index\tAddress\tName");
for (LibCmo::CKDWORD i = 0; i < slotcount; ++i) {
LibCmo::CK2::ObjImpls::CKMaterial* mtl = pMtlSlots[i];
2024-08-24 21:27:23 +08:00
Console::FormatLine(u8"#%" PRIuCKDWORD "\t%s\t%s",
i,
PrintPointer(mtl).c_str(),
(mtl != nullptr ? PrintCKSTRING(mtl->GetName()).c_str() : u8"")
);
}
2023-09-19 10:53:48 +08:00
}
#pragma endregion
2023-03-04 00:13:03 +08:00
void PrintCKFileInfo(const LibCmo::CK2::CKFileInfo& fileinfo) {
Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"CKFileInfo"));
Console::FormatLine(u8"FileVersion: %" PRIuCKDWORD, fileinfo.FileVersion);
LibCmo::CKDWORD ck_series[3] {
2023-03-04 00:13:03 +08:00
(fileinfo.CKVersion >> 24) & 0xFF,
(fileinfo.CKVersion >> 16) & 0xFF,
(fileinfo.CKVersion >> 0) & 0xFFFF
};
Console::FormatLine(u8"CKVersion: %02" PRIxCKDWORD "/%02" PRIxCKDWORD "/%04" PRIxCKDWORD,
ck_series[0], ck_series[1], ck_series[2]
2023-03-04 00:13:03 +08:00
);
2023-09-17 10:38:46 +08:00
LibCmo::CKDWORD product_series[4] {
2023-03-04 00:13:03 +08:00
(fileinfo.ProductBuild >> 24) & 0xFF,
(fileinfo.ProductBuild >> 16) & 0xFF,
(fileinfo.ProductBuild >> 8) & 0xFF,
(fileinfo.ProductBuild >> 0) & 0xFF,
};
Console::FormatLine(u8"Product (Version / Build): %" PRIuCKDWORD " / %" PRIuCKDWORD ".%" PRIuCKDWORD ".%" PRIuCKDWORD ".%" PRIuCKDWORD,
2023-03-04 00:13:03 +08:00
fileinfo.ProductVersion, product_series[0], product_series[1], product_series[2], product_series[3]
);
Console::FormatLine(u8"Save Flags: %s",
AccessibleValue::GetFlagEnumName(fileinfo.FileWriteMode, AccessibleValue::EnumDesc::CK_FILE_WRITEMODE, u8", ").c_str()
);
2023-03-04 00:13:03 +08:00
Console::FormatLine(u8"File Size: %s", AccessibleValue::GetReadableFileSize(fileinfo.FileSize).c_str());
2023-03-04 00:13:03 +08:00
Console::FormatLine(u8"Crc: 0x%" PRIxCKDWORD, fileinfo.Crc);
Console::WriteLine(u8"");
2023-03-04 00:13:03 +08:00
Console::FormatLine(u8"Hdr1 (Pack / UnPack): %s / %s",
AccessibleValue::GetReadableFileSize(fileinfo.Hdr1PackSize).c_str(),
AccessibleValue::GetReadableFileSize(fileinfo.Hdr1UnPackSize).c_str()
);
2023-03-04 00:13:03 +08:00
Console::FormatLine(u8"Data (Pack / UnPack): %s / %s",
AccessibleValue::GetReadableFileSize(fileinfo.DataPackSize).c_str(),
AccessibleValue::GetReadableFileSize(fileinfo.DataUnPackSize).c_str()
);
Console::WriteLine(u8"");
2023-03-04 00:13:03 +08:00
Console::FormatLine(u8"Manager Count: %" PRIuCKDWORD, fileinfo.ManagerCount);
Console::FormatLine(u8"Object Count: %" PRIuCKDWORD, fileinfo.ObjectCount);
Console::FormatLine(u8"Max ID Saved: %" PRIuCKID, fileinfo.MaxIDSaved);
2023-03-04 00:13:03 +08:00
}
2023-02-14 16:28:37 +08:00
#pragma region Object List Printer
static void PrintObjectListHeader(bool full_detail) {
if (full_detail) {
Console::WriteLine(u8"SaveFlags\tOptions\tCK ID\tFile CK ID\tFile Index\tPack Size\tIndex\tType\tCKObject\tCKStateChunk\tName");
} else {
Console::WriteLine(u8"Index\tType\tObject\tChunk\tName");
}
}
static void PrintObjectListEntry(const LibCmo::CK2::CKFileObject& obj, const LibCmo::CK2::CKFileInfo& fileinfo, size_t entry_index, bool full_detail) {
if (full_detail) {
2024-08-24 21:27:23 +08:00
Console::Format(u8"0x%08" PRIxCKDWORD "\t", obj.SaveFlags);
Console::Format(u8"%s\t", AccessibleValue::GetEnumName(obj.Options, AccessibleValue::EnumDesc::CK_FO_OPTIONS).c_str());
2024-08-24 21:27:23 +08:00
Console::Format(u8"%" PRIuCKID "\t%" PRIuCKID "\t",
obj.CreatedObjectId,
obj.ObjectId
);
2024-08-24 21:27:23 +08:00
Console::Format(u8"0x%08" PRIxCKDWORD " (Rel: 0x%08" PRIxCKDWORD ")\t",
obj.FileIndex,
obj.FileIndex - CKSizeof(LibCmo::CK2::CKRawFileInfo) - fileinfo.Hdr1UnPackSize
);
2024-08-24 21:27:23 +08:00
Console::Format(u8"0x%08" PRIxCKDWORD "\t", obj.PackSize);
}
// following items are shared by full details and simple layout
2024-08-24 21:27:23 +08:00
Console::FormatLine(u8"#%" PRIuSIZET "\t%s\t%s\t%s\t%s",
entry_index,
AccessibleValue::GetClassIdName(obj.ObjectCid).c_str(),
PrintColorfulBool(obj.ObjPtr != nullptr).c_str(),
PrintColorfulBool(obj.Data != nullptr).c_str(),
2024-08-24 21:27:23 +08:00
PrintCKSTRING(LibCmo::XContainer::NSXString::ToCKSTRING(obj.Name)).c_str()
);
}
2023-08-29 10:42:13 +08:00
void PrintObjectList(
const LibCmo::XContainer::XArray<LibCmo::CK2::CKFileObject>& ls,
const LibCmo::CK2::CKFileInfo& fileinfo,
size_t page, size_t pageitems,
bool full_detail) {
2023-03-04 00:13:03 +08:00
Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"CKFileObject"));
2023-08-27 22:14:02 +08:00
GeneralPrintList<LibCmo::CK2::CKFileObject>(ls, page, pageitems,
[full_detail]() -> void {
PrintObjectListHeader(full_detail);
},
[&fileinfo, full_detail](size_t index, const LibCmo::CK2::CKFileObject& obj) -> void {
PrintObjectListEntry(obj, fileinfo, index, full_detail);
}
);
}
void PrintSearchedObjectList(
const LibCmo::XContainer::XArray<size_t>& idxls,
const LibCmo::XContainer::XArray<LibCmo::CK2::CKFileObject>& ls,
const LibCmo::CK2::CKFileInfo& fileinfo,
size_t page, size_t pageitems,
bool full_detail) {
Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"CKFileObject Searching Result"));
GeneralPrintList<size_t>(idxls, page, pageitems,
[full_detail]() -> void {
PrintObjectListHeader(full_detail);
2023-08-27 22:14:02 +08:00
},
[&ls, &fileinfo, full_detail](size_t, const size_t& index_to_obj) -> void {
// resolve index to real item.
// and pass the entry index, not the page index.
PrintObjectListEntry(ls[index_to_obj], fileinfo, index_to_obj, full_detail);
2023-08-27 22:14:02 +08:00
}
2023-08-29 10:42:13 +08:00
);
2023-03-04 00:13:03 +08:00
}
#pragma endregion
#pragma region Manager List Printer
2023-03-04 00:13:03 +08:00
static void PrintManagerListHeader(bool full_detail) {
// manager list now do not affected by list style because it is enough short
Console::WriteLine(u8"Index\tCKGUID\tCKStateChunk");
}
static void PrintManagerListEntry(const LibCmo::CK2::CKFileManagerData& mgr, size_t entry_index, bool full_detail) {
// not affected by list style.
Console::FormatLine(u8"#%" PRIuSIZET "\t%s\t%s",
entry_index,
PrintCKGUID(mgr.Manager).c_str(),
PrintPointer(mgr.Data).c_str()
);
}
2023-08-29 10:42:13 +08:00
void PrintManagerList(
const LibCmo::XContainer::XArray<LibCmo::CK2::CKFileManagerData>& ls,
size_t page, size_t pageitems,
bool full_detail) {
2023-02-14 16:28:37 +08:00
Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"CKFileManager"));
2023-08-27 22:14:02 +08:00
GeneralPrintList<LibCmo::CK2::CKFileManagerData>(ls, page, pageitems,
[full_detail]() -> void {
2023-08-27 22:14:02 +08:00
// print header
PrintManagerListHeader(full_detail);
2023-08-27 22:14:02 +08:00
},
[full_detail](size_t index, const LibCmo::CK2::CKFileManagerData& mgr) -> void {
2023-08-27 22:14:02 +08:00
// print body
PrintManagerListEntry(mgr, index, full_detail);
}
);
}
void PrintSearchedManagerList(
const LibCmo::XContainer::XArray<size_t>& idxls,
const LibCmo::XContainer::XArray<LibCmo::CK2::CKFileManagerData>& ls,
size_t page, size_t pageitems,
bool full_detail) {
Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"CKFileManager Searching Result"));
GeneralPrintList<size_t>(idxls, page, pageitems,
[full_detail]() -> void {
PrintManagerListHeader(full_detail);
},
[&ls, full_detail](size_t, const size_t& index_to_mgr) -> void {
// resolve index to real one
PrintManagerListEntry(ls[index_to_mgr], index_to_mgr, full_detail);
2023-08-27 22:14:02 +08:00
}
2023-08-29 10:42:13 +08:00
);
2023-02-14 16:28:37 +08:00
}
#pragma endregion
2023-03-04 00:13:03 +08:00
2023-08-27 22:14:02 +08:00
void PrintCKObject(const LibCmo::CK2::ObjImpls::CKObject* obj) {
2023-09-01 12:19:06 +08:00
if (obj == nullptr) {
Console::WriteLine(YYCC_COLOR_LIGHT_RED(u8"Null Object"));
2023-09-01 12:19:06 +08:00
return;
}
2023-09-19 10:53:48 +08:00
LibCmo::CK2::ObjImpls::CKObject* mobj = const_cast<LibCmo::CK2::ObjImpls::CKObject*>(obj);
switch (mobj->GetClassID()) {
case LibCmo::CK2::CK_CLASSID::CKCID_OBJECT:
PrintCKObjectDetail(static_cast<LibCmo::CK2::ObjImpls::CKObject*>(mobj));
break;
case LibCmo::CK2::CK_CLASSID::CKCID_SCENEOBJECT:
PrintCKSceneObjectDetail(static_cast<LibCmo::CK2::ObjImpls::CKSceneObject*>(mobj));
break;
case LibCmo::CK2::CK_CLASSID::CKCID_BEOBJECT:
PrintCKBeObjectDetail(static_cast<LibCmo::CK2::ObjImpls::CKBeObject*>(mobj));
break;
case LibCmo::CK2::CK_CLASSID::CKCID_GROUP:
PrintCKGroupDetail(static_cast<LibCmo::CK2::ObjImpls::CKGroup*>(mobj));
break;
case LibCmo::CK2::CK_CLASSID::CKCID_RENDEROBJECT:
PrintCKRenderObjectDetail(static_cast<LibCmo::CK2::ObjImpls::CKRenderObject*>(mobj));
break;
case LibCmo::CK2::CK_CLASSID::CKCID_3DENTITY:
PrintCK3dEntityDetail(static_cast<LibCmo::CK2::ObjImpls::CK3dEntity*>(mobj));
break;
case LibCmo::CK2::CK_CLASSID::CKCID_3DOBJECT:
PrintCK3dObjectDetail(static_cast<LibCmo::CK2::ObjImpls::CK3dObject*>(mobj));
break;
case LibCmo::CK2::CK_CLASSID::CKCID_TEXTURE:
PrintCKTextureDetail(static_cast<LibCmo::CK2::ObjImpls::CKTexture*>(mobj));
break;
case LibCmo::CK2::CK_CLASSID::CKCID_MATERIAL:
PrintCKMaterialDetail(static_cast<LibCmo::CK2::ObjImpls::CKMaterial*>(mobj));
break;
2023-09-19 10:53:48 +08:00
case LibCmo::CK2::CK_CLASSID::CKCID_MESH:
PrintCKMeshDetail(static_cast<LibCmo::CK2::ObjImpls::CKMesh*>(mobj));
break;
default:
Console::WriteLine(YYCC_COLOR_LIGHT_RED(u8"Not Implemented."));
2023-09-19 10:53:48 +08:00
break;
}
2023-08-27 16:45:07 +08:00
}
2023-08-27 22:14:02 +08:00
void PrintCKBaseManager(const LibCmo::CK2::MgrImpls::CKBaseManager* mgr) {
Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"CKBaseManager"));
2023-09-01 12:19:06 +08:00
if (mgr == nullptr) {
Console::WriteLine(YYCC_COLOR_LIGHT_RED(u8"Null Manager"));
2023-09-01 12:19:06 +08:00
return;
}
Console::WriteLine(YYCC_COLOR_LIGHT_RED(u8"Not Implemented."));
2023-08-27 16:45:07 +08:00
}
2023-08-27 22:14:02 +08:00
void PrintCKStateChunk(const LibCmo::CK2::CKStateChunk* chunk) {
Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"CKStateChunk"));
2023-09-01 12:19:06 +08:00
if (chunk == nullptr) {
Console::WriteLine(YYCC_COLOR_LIGHT_RED(u8"Null Chunk"));
2023-09-01 12:19:06 +08:00
return;
}
2023-08-29 10:42:13 +08:00
// hack const state chunk
2023-08-27 22:14:02 +08:00
LibCmo::CK2::CKStateChunk* operchunk = const_cast<LibCmo::CK2::CKStateChunk*>(chunk);
2023-08-29 10:42:13 +08:00
// write profile
const auto profile = operchunk->GetStateChunkProfile();
Console::FormatLine(u8"Type: %s", AccessibleValue::GetClassIdName(profile.m_ClassId).c_str());
2023-08-29 10:42:13 +08:00
Console::FormatLine(u8"Version (Data / Chunk): %" PRIuCKDWORD " (%s) / %" PRIuCKDWORD " (%s)",
2023-09-17 10:38:46 +08:00
static_cast<LibCmo::CKDWORD>(profile.m_DataVersion), AccessibleValue::GetEnumName(profile.m_DataVersion, AccessibleValue::EnumDesc::CK_STATECHUNK_DATAVERSION).c_str(),
static_cast<LibCmo::CKDWORD>(profile.m_ChunkVersion), AccessibleValue::GetEnumName(profile.m_ChunkVersion, AccessibleValue::EnumDesc::CK_STATECHUNK_CHUNKVERSION).c_str()
);
Console::FormatLine(u8"List (Object / Chunk / Manager): %" PRIuCKDWORD " / %" PRIuCKDWORD " / %" PRIuCKDWORD,
2023-09-17 10:38:46 +08:00
static_cast<LibCmo::CKDWORD>(profile.m_ObjectListSize),
static_cast<LibCmo::CKDWORD>(profile.m_ChunkListSize),
static_cast<LibCmo::CKDWORD>(profile.m_ManagerListSize)
);
2023-08-29 10:42:13 +08:00
Console::FormatLine(u8"Data: %s (0x%" PRIxCKDWORD " DWORD)",
PrintPointer(profile.m_pData).c_str(),
profile.m_DataDwSize
);
2023-08-29 10:42:13 +08:00
Console::FormatLine(u8"Bind CKFile: %s", PrintPointer(profile.m_BindFile).c_str());
Console::FormatLine(u8"Bind CKContext: %s", PrintPointer(profile.m_BindContext).c_str());
2023-08-29 10:42:13 +08:00
// write identifiers
2023-08-27 22:14:02 +08:00
operchunk->StartRead();
2023-09-18 16:37:05 +08:00
const auto collection = operchunk->GetIdentifiersProfile();
2023-08-27 22:14:02 +08:00
operchunk->StopRead();
Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"Identifiers"));
Console::WriteLine(u8"Identifier\tData Pointer\tData Size");
2023-08-29 10:42:13 +08:00
for (const auto& ident : collection) {
2024-08-24 21:27:23 +08:00
Console::FormatLine(u8"0x%08" PRIxCKDWORD "\t%s\t%" PRIuCKDWORD " (%" PRIuCKDWORD " DWORD + %" PRIuCKDWORD ")",
ident.m_Identifier,
PrintPointer(ident.m_DataPtr).c_str(),
ident.m_AreaSize,
ident.m_AreaSize / CKSizeof(LibCmo::CKDWORD),
ident.m_AreaSize % CKSizeof(LibCmo::CKDWORD)
);
2023-08-27 22:14:02 +08:00
}
2023-08-27 16:45:07 +08:00
}
2023-02-14 16:28:37 +08:00
}