Repository navigation
Expand file tree
/
Copy pathhxbinser.hexpat
More file actions
392 lines (338 loc) · 8.09 KB
/
Copy pathhxbinser.hexpat
File metadata and controls
392 lines (338 loc) · 8.09 KB
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#pragma author Ne_Eo
#pragma description Haxe Binary Serializer
#pragma magic [43 4e 45 53 41 56 45 76 31 3a] @ 0x00
#pragma endian little
import std.math;
import std.core;
import type.time;
import type.magic;
using SerializedFormat;
// TODO:
// - Show date as human readable
// - Show the format of refs as the actual value
enum Type : u8 {
Null = 0x00,
True = 0x01,
False = 0x02,
Zero = 0x03,
Int8 = 0x04,
Int16 = 0x05,
Int32 = 0x06,
Int64 = 0x07,
Float = 0x08,
Single = 0x09,
NaN = 0x0A,
PositiveInfinity = 0x0B,
NegativeInfinity = 0x0C,
PI = 0x0D,
String8 = 0x0E,
String16 = 0x0F,
String32 = 0x10,
Array = 0x11,
Object = 0x12,
ObjectRef8 = 0x13,
ObjectRef16 = 0x14,
ObjectRef32 = 0x15,
StringRef8 = 0x16,
StringRef16 = 0x17,
StringRef32 = 0x18,
Exception = 0x19,
ClassInstance = 0x1A,
EnumInstance = 0x1B,
List = 0x1C,
StringMap = 0x1D,
IntMap = 0x1E,
ObjectMap = 0x1F,
EnumMap = 0x20,
Date = 0x21,
Bytes = 0x22,
ClassType = 0x23,
EnumType = 0x24,
NegOne = 0x25,
NegInt8 = 0x26,
NegInt16 = 0x27,
EmptySpace8 = 0xFC,
EmptySpace16 = 0xFD,
EmptySpace32 = 0xFE,
End = 0xFF,
};
struct Int {
Type type;
if (type == Type::Int8) {
u8 int;
}
else if (type == Type::Int16) {
u16 int;
}
else if (type == Type::Int32) {
u32 int;
}
//else if (type == Type::Int64) {
// Int64 int;
//}
};
u8 indent = 0;
fn print_indent(u32 indent, auto dd) {
str indent_string = " " * indent;
std::print(indent_string + string(dd));
};
fn string(auto dd) {
return std::format("{}", dd);
};
struct String8 {
u8 length [[hidden]];
char value[length];
print_indent(indent, std::format("STRING {}", value));
} [[sealed, format("format_string")]];
struct String16 {
u16 length [[hidden]];
char value[length];
print_indent(indent, std::format("STRING16"));
} [[sealed, format("format_string")]];
struct String32 {
u32 length [[hidden]];
char value[length];
print_indent(indent, std::format("STRING32"));
} [[sealed, format("format_string")]];
struct String {
Type type;
if (type == Type::String8) {
String8 string;
}
else if (type == Type::String16) {
String16 string;
}
else if (type == Type::String32) {
String32 string;
}
};
using StringRef;
union StringUnion {
String _str;
StringRef _ref;
} [[ format("format_string_union") ]];
fn format_string(auto string) {
return string.value;
};
fn format_string2(auto string) {
return string._str.string.value;
};
fn format_string_union(auto string) {
if (string._str.type == Type::String8) {
return string._str.string;
}
else if (string._str.type == Type::String16) {
return string._str.string;
}
else if (string._str.type == Type::String32) {
return string._str.string;
}
else {
return format_ref(string._ref.reference);
}
};
struct Array {
SerializedFormat data[while($[$] != Type::End)] [[inline]];
$ += 1; // skip END
};
fn format_field(auto field) {
return std::format("{}: {}", field.key, field.value);
};
struct FieldListing {
StringUnion key [[sealed, format("format_string_union")]];
SerializedFormat value;
} [[format("format_field")]];
struct Object {
FieldListing data[while($[$] != Type::End)] [[inline]];
$ += 1; // skip END
};
fn format_ref(auto reference) {
return std::format("REF({})", reference.index);
};
struct ObjectRef8 {
u8 index;
} [[sealed, format("format_ref")]];
struct ObjectRef16 {
u16 index;
} [[sealed, format("format_ref")]];
struct ObjectRef32 {
u32 index;
} [[sealed, format("format_ref")]];
struct StringRef8 {
u8 index;
};
struct StringRef16 {
u16 index;
};
struct StringRef32 {
u32 index;
};
struct StringRef {
Type type;
if (type == Type::StringRef8) {
StringRef8 reference;
}
else if (type == Type::StringRef16) {
StringRef16 reference;
}
else if (type == Type::StringRef32) {
StringRef32 reference;
}
};
struct ClassInstance {
StringUnion name [[sealed, format("format_string2")]];
FieldListing data[while($[$] != Type::End)];
$ += 1; // skip END
};
struct EnumInstance {
StringUnion name [[sealed, format("format_string2")]];
StringUnion tag [[sealed, format("format_string2")]];
SerializedFormat data[while($[$] != Type::End)];
$ += 1; // skip END
};
struct List {
SerializedFormat data[while($[$] != Type::End)] [[inline]];
$ += 1; // skip END
};
struct StringMapEntry {
StringUnion key [[sealed, format("format_string2")]];
SerializedFormat value;
};
struct StringMap {
StringMapEntry data[while($[$] != Type::End)] [[inline]];
$ += 1; // skip END
};
struct IntMapEntry {
Int key;
SerializedFormat value;
};
struct IntMap {
IntMapEntry data[while($[$] != Type::End)] [[inline]];
$ += 1; // skip END
};
struct ObjectMapEntry {
SerializedFormat key;
SerializedFormat value;
};
struct ObjectMap {
ObjectMapEntry data[while($[$] != Type::End)] [[inline]];
$ += 1; // skip END
};
struct EnumMapEntry {
SerializedFormat key;
SerializedFormat value;
};
struct EnumMap {
EnumMapEntry data[while($[$] != Type::End)] [[inline]];
$ += 1; // skip END
};
fn double_to_time (double val){
return type::impl::format_time_t(val);
};
struct Bytes {
Int length [[hidden]];
u8 value[length];
} [[sealed]];
struct SerializedFormat {
Type type;
print_indent(indent, type);
indent += 1;
if (type == Type::Null) {
/*Null null;*/
} else if (type == Type::True) {
//true;
} else if (type == Type::False) {
//false;
} else if (type == Type::Zero) {
//0;
} else if (type == Type::Int8) {
u8 int;
} else if (type == Type::Int16) {
u16 int;
} else if (type == Type::Int32) {
u32 int;
} else if (type == Type::Int64) {
u64 int;
} else if (type == Type::Float) {
double value ;
} else if (type == Type::Single) {
float value;
} else if (type == Type::NaN) {
} else if (type == Type::PositiveInfinity) {
} else if (type == Type::NegativeInfinity) {
} else if (type == Type::PI) {
} else if (type == Type::String8) {
String8 string;
} else if (type == Type::String16) {
String16 string;
} else if (type == Type::String32) {
String32 string;
} else if (type == Type::Array) {
Array array;
} else if (type == Type::Object) {
Object object;
} else if (type == Type::ObjectRef8) {
ObjectRef8 _ref [[inline]];
} else if (type == Type::ObjectRef16) {
ObjectRef16 _ref [[inline]];
} else if (type == Type::ObjectRef32) {
ObjectRef32 _ref [[inline]];
} else if (type == Type::StringRef8) {
StringRef8 _ref [[inline]];
} else if (type == Type::StringRef16) {
StringRef16 _ref [[inline]];
} else if (type == Type::StringRef32) {
StringRef32 _ref [[inline]];
} else if (type == Type::Exception) {
SerializedFormat exception;
} else if (type == Type::ClassInstance) {
ClassInstance classInstance;
} else if (type == Type::EnumInstance) {
EnumInstance enumInstance;
} else if (type == Type::List) {
List list;
} else if (type == Type::StringMap) {
StringMap stringMap;
} else if (type == Type::IntMap) {
IntMap intMap;
} else if (type == Type::ObjectMap) {
ObjectMap objectMap;
} else if (type == Type::EnumMap) {
EnumMap enumMap;
} else if (type == Type::Date) {
double date; // todo: convert into readable date
} else if (type == Type::Bytes) {
Bytes bytes;
} else if (type == Type::ClassType) {
StringUnion classType;
} else if (type == Type::EnumType) {
StringUnion enumType;
} else if (type == Type::NegOne) {
//-1;
} else if (type == Type::NegInt8) {
u8 negInt;
} else if (type == Type::NegInt16) {
u16 negInt;
} else if (type == Type::EmptySpace8) {
u8 emptySpace;
} else if (type == Type::EmptySpace16) {
u16 emptySpace;
} else if (type == Type::EmptySpace32) {
u32 emptySpace;
}
indent -= 1;
};
struct v1magic {
type::Magic<"CNESAVE"> magic;
char version[2];
type::Magic<":"> colon [[hidden]];
};
struct File {
try {
v1magic magic;
SerializedFormat ddd [[inline]];
} catch {
SerializedFormat ddd [[inline]];
}
};
File file @0x00 [[inline]];