-
-
Notifications
You must be signed in to change notification settings - Fork 181
/
pck.hexpat
187 lines (163 loc) · 4.16 KB
/
pck.hexpat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#pragma author nullptr
#pragma description Minecraft LCE .pck files
import std.io;
import std.array;
import std.core;
import std.sys;
import std.string;
import std.mem;
import type.size;
bool littleEndian in;
if (littleEndian)
std::core::set_endian(std::mem::Endian::Little);
else
std::core::set_endian(std::mem::Endian::Big);
namespace format
{
// TODO: find a way to access look up table differently
fn look_up_str(s32 index)
{
return pck.lut.table[index].value;
};
fn property(ref auto p)
{
return std::format("{}: {}", format::look_up_str(p.key), p.value);
};
fn assets(ref auto assets)
{
return std::format("Assets: {}", assets.count);
};
fn properties(ref auto p)
{
return std::format("count: {}", p.propertyCount);
};
fn string(ref auto string)
{
return std::string::to_string(string.value);
};
fn asset_entry(ref auto e)
{
return std::string::to_string(e.type);
};
}
namespace transform
{
fn assets(ref auto asstes)
{
std::unimplemented();
};
}
struct string
{
std::string::SizedString16<s32> value;
padding[4];
} [[sealed, format("format::string"), transform("format::string")]];
struct LookUpTableValue
{
s32 index;
string value;
} [[sealed, name(value), value(index)]];
struct LookUpTable
{
s32 count;
LookUpTableValue table[count];
} [[sealed]];
fn lutContains(ref LookUpTable lut, str value)
{
for (s32 i = 0, i < lut.count, i = i + 1)
{
if (std::string::contains(lut.table[i].value, value))
return true;
}
return false;
};
enum AssetType : s32
{
SkinFile = 0, // *.png
CapeFile = 1, // *.png
TextureFile = 2, // *.png
//! Unused !
UIDataFile = 3,
//! "0" file
InfoFile = 4,
//! (x16|x32|x64)Info.pck
TexturePackInfoFile = 5,
//! languages.loc/localisation.loc
LocalisationFile = 6,
//! GameRules.grf
GameRulesFile = 7,
//! audio.pck
AudioFile = 8,
//! colours.col
ColourTableFile = 9,
//! GameRules.grh
GameRulesHeader = 10,
//! Skins.pck
SkinDataFile = 11,
//! models.bin
ModelsFile = 12,
//! behaviours.bin
BehavioursFile = 13,
//! entityMaterials.bin
MaterialFile = 14,
};
struct Property
{
s32 key [[format("format::look_up_str")]];
string value;
} [[format("format::property")]];
struct AssetProperties
{
s32 propertyCount[[hidden]];
Property properties[propertyCount] [[inline]];
} [[inline, format("format::properties")]];
struct AssetEntry
{
type::Size32 size;
AssetType type;
string path;
} [[sealed, name(path), format("format::asset_entry")]];
struct AssetVisualizer<auto size, auto visualizer_name>
{
u8 data[size] [[hidden]];
} [[sealed, hex::visualize(visualizer_name, data)]];
using AssetTexture<auto size> = AssetVisualizer<size, "image">;
using Pck;
struct Asset
{
u64 index = std::core::array_index();
AssetProperties properties;
s32 size = parent.assetEntries[index].size;
AssetType type = parent.assetEntries[index].type;
match (parent.assetEntries[index].type)
{
(AssetType::SkinFile | AssetType::CapeFile | AssetType::TextureFile): AssetTexture<size> data;
(AssetType::TexturePackInfoFile | AssetType::SkinDataFile): Pck data;
(_): u8 data[size]; // hex::visualize("hex_viewer", data); causes crash ._.
}
} [[name(std::string::to_string(parent.assetEntries[index].path)), format("format::asset_entry")]];
struct Assets
{
s32 count [[hidden]];
AssetEntry assetEntries[count] [[hidden]];
Asset assetData[count] [[inline]];
} [[format("format::assets"), transform_entities("transform::assets")]];
struct Pck
{
s32 version;
if (version >> 24 & 0xff != 0)
{
if (!littleEndian)
std::warning("pck is likely to be little endian. Enable 'littleEndian' in the 'settings' tab");
else
std::warning("pck is likely to be big endian. Disable 'littleEndian' in the 'settings' tab");
break;
}
LookUpTable lut [[hidden]];
if (lutContains(lut, "XMLVERSION"))
{
s32 xmlVersion;
}
Assets assets;
};
Pck pck @ 0x00;