Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add several ImHex file format documentation files #13

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions patterns/animation.hexpat
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import std.mem;
// import stingray; // Not sure where to put custom library files yet =/
// stingray.hexpat
import std.io;

using ThinMurmurHash;
using MurmurHash;

fn formatThinHash(ThinMurmurHash hash) {
return std::format("{:08X}", hash.value);
};

fn formatHash(MurmurHash hash) {
return std::format("{:016X}", hash.value);
};

struct ThinMurmurHash {
u32 value;
} [[format("formatThinHash")]];

struct MurmurHash {
u64 value;
} [[format("formatHash")]];
// end stingray.hexpat

bitfield BoneData {
u8 ItemType : 2;
u16 BoneId : 10;
u32 TimeCode : 20;
u48 data : 32;
};

struct AnimationData {
u32 unk00;
u32 channels;
float duration;
u32 totalSize;
BoneData data[10];
} [[inline]];

s64 offset;
struct Animation {
$ = offset;
u32 size;
offset = offset - size;
$ = offset;
AnimationData animData;
offset = offset - 4;
};

offset = std::mem::size() - 4;
Animation animation[while(offset > 0)] @0x00;
47 changes: 47 additions & 0 deletions patterns/bones.hexpat
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import std.ptr;
// import stingray; // Not sure where to put custom library files yet =/
// stingray.hexpat
import std.io;

using ThinMurmurHash;
using MurmurHash;

fn formatThinHash(ThinMurmurHash hash) {
return std::format("{:08X}", hash.value);
};

fn formatHash(MurmurHash hash) {
return std::format("{:016X}", hash.value);
};

struct ThinMurmurHash {
u32 value;
} [[format("formatThinHash")]];

struct MurmurHash {
u64 value;
} [[format("formatHash")]];
// end stingray.hexpat

fn relative_to_parents_parent(u128 offset) {
return addressof(parent.parent.parent);
};

fn relative_to_parent(u128 offset) {
return addressof(parent.parent);
};

struct Name {
char data[];
};

struct Bones {
u32 boneCount;
u32 parentCount;
float floats[parentCount];
ThinMurmurHash nameHashes[boneCount];
u32 roots[parentCount];
Name names[boneCount];
};

Bones b @0x0;
91 changes: 91 additions & 0 deletions patterns/ik_skeleton.hexpat
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import std.mem;
// import stingray; // Not sure where to put custom library files yet =/
// stingray.hexpat
import std.io;

using ThinMurmurHash;
using MurmurHash;

fn formatThinHash(ThinMurmurHash hash) {
return std::format("{:08X}", hash.value);
};

fn formatHash(MurmurHash hash) {
return std::format("{:016X}", hash.value);
};

struct ThinMurmurHash {
u32 value;
} [[format("formatThinHash")]];

struct MurmurHash {
u64 value;
} [[format("formatHash")]];
// end stingray.hexpat

struct quaternion {
float x, y, z, w;
};

struct Name {
char data[];
if(std::mem::read_unsigned($, 1) == 0x00){
padding[1];
}
};

struct Header {
ThinMurmurHash unkHashes[4];
u32 size;
u8 unk00[16];
u32 shortCount0;
u32 shortCount1;
u32 firstSectionSize;
u8 unk01[24];
// Quite likely to be a bone to ik bone index map
u16 shorts00[shortCount0];
s16 shorts01[shortCount1];

std::mem::AlignTo<16> align0;
};

bitfield PacketHeader {
padding : 1;
bool leaf : 1;
padding : 6;
};

enum Type : char[4] {
ROOT = "TAG0",
VERSION = "SDKV",
DATA = "DATA",
TYPES = "TYPE",
TYPE_PTRS = "TPTR",
TYPE_STRS = "TST1",
TYPE_NAME_IDXS = "TNA1",
};

struct PacketData {
match (parent.type) {
u8 data[size - 8];
}
} [[inline]];

struct Packet {
be PacketHeader header;
be u24 size;
char type[4];
if(!header.leaf) {
Packet children[while($ < (addressof(this) + size))];
} else {
PacketData data;
}
};

struct IKSkeleton {
Header header;
Packet packets[while($ < header.size)];
};


IKSkeleton skeleton @0x0;
63 changes: 63 additions & 0 deletions patterns/material.hexpat
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import std.io;

using ThinMurmurHash;
using MurmurHash;

fn formatThinHash(ThinMurmurHash hash) {
return std::format("{:08X}", hash.value);
};

fn formatHash(MurmurHash hash) {
return std::format("{:016X}", hash.value);
};

struct ThinMurmurHash {
u32 value;
} [[format("formatThinHash")]];

struct MurmurHash {
u64 value;
} [[format("formatHash")]];

enum ImageUsage : u32 {
AlbedoIridescence = 0xff2c91cc,
Albedo = 0xac652e43,
Normal = 0xcaed6cd6,
BaseData = 0xc2eb8d6e,
MaterialLUT = 0x7e662968,
PatternLUT = 0x81d4c49d,
CompositeArray = 0xa17b45a8,
BloodSplatterTiler = 0x30e2d136,
WeatheringSpecial = 0xd2f99d38,
WeatheringDirt = 0x6834aa9b,
BugSplatterTiler = 0x37831285,
DecalSheet = 0x632a8b80,
CustomizationCamoTilerArray = 0x0f5ff78d,
PatternMasksArray = 0x05a27dd5,
CustomizationMaterialDetailTilerArray = 0xd3a0408e,
IdMasksArray = 0xb281e5f2,
};

union ImageType {
ThinMurmurHash hash;
ImageUsage usage;
};

struct Header {
u8 unk00[12];
u32 mainSize;
u32 gpuSize;
u8 unk01[4];
MurmurHash baseMaterial;
u8 unk02[32];
u32 numTextures;
u8 unk03[68];
};

struct Material {
Header header;
ImageType keys[header.numTextures];
MurmurHash values[header.numTextures];
};

Material mat @0x00;
106 changes: 106 additions & 0 deletions patterns/openexr.hexpat
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import std.mem;

bitfield OpenEXRFlags {
tile : 1;
longname : 1;
deep : 1;
multipart : 1;
padding : 19;
};

enum PixelType : u32 {
UINT = 0,
HALF = 1,
FLOAT = 2,
};

struct ChannelList {
char name[];
PixelType type;
u8 pLinear;
padding[3];
u32 xSampling;
u32 ySampling;
};

enum Compression : u8 {
NO_COMPRESSION = 0,
RLE_COMPRESSION = 1,
ZIPS_COMPRESSION = 2,
ZIP_COMPRESSION = 3,
PIZ_COMPRESSION = 4,
PXR24_COMPRESSION = 5,
B44_COMPRESSION = 6,
B44A_COMPRESSION = 7,
DWAA_COMPRESSION = 8,
DWAB_COMPRESSION = 9,
};

enum LineOrder : u8 {
INCREASING_Y = 0,
DECREASING_Y = 1,
RANDOM_Y = 2,
};

struct Box2i {
u32 xMin, yMin, xMax, yMax;
};

struct Box2f {
float xMin, yMin, xMax, yMax;
};

struct V2f {
float x, y;
};

struct Attribute {
char name[];
char type[];
u32 size;
if(type == "chlist\0") {
ChannelList chlists[while(std::mem::read_unsigned($, 1) != 0x00)];
padding[1];
} else if (type == "compression\0") {
Compression compression;
} else if (type == "float\0") {
float value;
} else if (type == "box2i\0") {
Box2i value;
} else if (type == "box2f\0") {
Box2f value;
} else if (type == "lineOrder\0") {
LineOrder lineOrder;
} else if (type == "v2f\0") {
V2f value;
} else {
u8 data[size];
}
};

struct Header {
Attribute attributes[while(std::mem::read_unsigned($, 1) != 0x00)];
padding[1];
};

// For larger files this will actually need to be calculated
struct OffsetTable {
u64 offset;
};

struct ScanlineBlock {
u32 scanline;
u32 size;
u8 data[size];
};

struct OpenEXR {
u32 magic;
u8 version;
OpenEXRFlags flags;
Header header;
OffsetTable offsets;
ScanlineBlock blocks[while(!std::mem::eof())];
};

OpenEXR exr @0x00;
Loading