-
-
Notifications
You must be signed in to change notification settings - Fork 181
/
hinf_luas.hexpat
441 lines (397 loc) · 8.94 KB
/
hinf_luas.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
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
#pragma author Surasia
#pragma description Halo Infinite HavokScript 5.1 "luas"
import std.io;
import std.mem;
import std.core;
import std.string;
struct String32 {
s32 length;
if (length != 0) {
char s[length - 1];
u8 endbyte;
}
};
struct String64 {
s64 length;
if (length != 0) {
char s[length - 1];
u8 endbyte;
}
};
enum lua_endian : u8 {
little_endian = 1,
big_endian = 0,
};
enum lua_numbertype : u8 {
_float = 0,
_int32 = 1,
};
struct lua_enum {
s32 value;
String32 string;
};
struct LuaEnum {
s32 count;
lua_enum entries[count];
};
enum HksOpCode : s8 {
GETFIELD,
TEST,
CALL_I,
CALL_C,
EQ,
EQ_BK,
GETGLOBAL,
MOVE,
SELF,
RETURN,
GETTABLE_S,
GETTABLE_N,
GETTABLE,
LOADBOOL,
TFORLOOP,
SETFIELD,
SETTABLE_S,
SETTABLE_S_BK,
SETTABLE_N,
SETTABLE_N_BK,
SETTABLE,
SETTABLE_BK,
TAILCALL_I,
TAILCALL_C,
TAILCALL_M,
LOADK,
LOADNIL,
SETGLOBAL,
JMP,
CALL_M,
CALL,
INTRINSIC_INDEX,
INTRINSIC_NEWINDEX,
INTRINSIC_SELF,
INTRINSIC_LITERAL,
INTRINSIC_NEWINDEX_LITERAL,
INTRINSIC_SELF_LITERAL,
TAILCALL,
GETUPVAL,
SETUPVAL,
ADD,
ADD_BK,
SUB,
SUB_BK,
MUL,
MUL_BK,
DIV,
DIV_BK,
MOD,
MOD_BK,
POW,
POW_BK,
NEWTABLE,
UNM,
NOT,
LEN,
LT,
LT_BK,
LE,
LE_BK,
CONCAT,
TESTSET,
FORPREP,
FORLOOP,
SETLIST,
CLOSE,
CLOSURE,
VARARG,
TAILCALL_I_R1,
CALL_I_R1,
SETUPVAL_R1,
TEST_R1,
NOT_R1,
GETFIELD_R1,
SETFIELD_R1,
NEWSTRUCT,
DATA,
SETSLOTN,
SETSLOTI,
SETSLOT,
SETSLOTS,
SETSLOTMT,
CHECKTYPE,
CHECKTYPES,
GETSLOT,
GETSLOTMT,
SELFSLOT,
SELFSLOTMT,
GETFIELD_MM,
CHECKTYPE_D,
GETSLOT_D,
GETGLOBAL_MEM,
};
enum HksType : u8
{
TNIL,
TBOOLEAN,
TLIGHTUSERDATA,
TNUMBER,
TSTRING,
TTABLE,
TFUNCTION,
TUSERDATA,
TTHREAD,
TIFUNCTION,
TCFUNCTION,
TUI64,
TSTRUCT
};
bitfield REG_CONST_UNUSED {
argB : 17 & 0x1ffff;
argA : 8 & 0xff;
};
bitfield REG_NUM_NUM {
argC : 9 & 0x1ff;
argB : 8 & 0xff;
argA : 8 & 0xff;
};
bitfield REG_NUM_UNUSED {
argB : 8 & 0xff;
argA : 8 & 0xff;
argC : 9 & 0x1ff;
};
bitfield UNUSED_OFFSET_UNUSED {
argA : 8 & 0xff;
argB : 9 & 0x1ff;
argC : 8 & 0xff;
};
bitfield LuaBitfield {
HksOpCode OpCode : 7;
//Arguments : 25; // read on how to process them at https://raw.githubusercontent.com/soupstream/havok-script-tools/main/HavokScriptToolsCommon/HksOpCodes.cs
match(OpCode) {
(HksOpCode::LOADK) : REG_CONST_UNUSED arguments;
(HksOpCode::SETGLOBAL) : REG_CONST_UNUSED arguments;
(HksOpCode::NEWTABLE) : REG_NUM_NUM arguments;
(HksOpCode::CLOSURE) : REG_CONST_UNUSED arguments;
(HksOpCode::RETURN) : REG_NUM_UNUSED arguments;
(HksOpCode::NEWSTRUCT) : REG_NUM_NUM arguments;
(HksOpCode::DATA) : UNUSED_OFFSET_UNUSED arguments;
(_): arguments : 25;
}
};
struct LuaInstruction {
LuaBitfield OpCode;
};
struct LuaConstant {
HksType type;
if (type == HksType::TNIL) {
}
else if (type == HksType::TSTRING) {
String64 string;
}
else if (type == HksType::TNUMBER) {
float number;
}
else if (type == HksType::TBOOLEAN) {
bool boolean;
}
else if (type == HksType::TLIGHTUSERDATA) {
s64 userdata;
}
else {
s64 data;
}
};
struct HksLocal {
String64 string;
u32 start;
u32 end;
};
struct LuaFunction {
s32 upvaluecount;
s32 paramcount;
s8 isVarArg;
s32 slotCount;
s32 unk;
s32 instruction_count;
if ($ % 4 != 0) {
$ += (4 - ($ % 4));
}
LuaInstruction instructions[instruction_count];
s32 constantCount;
LuaConstant constants[constantCount];
s32 HasDebugInfo;
if (HasDebugInfo != 0) {
u32 LineCount;
u32 LocalsCount;
u32 UpValueCount;
u32 LineBegin;
u32 LineEnd;
String64 path;
String64 functionName;
s32 Lines[LineCount];
HksLocal Locals[LocalsCount];
String64 UpValues[UpValueCount];
}
s32 function_count;
LuaFunction children[function_count];
};
struct LuaStructHeader {
String64 name;
s32 structID;
s32 pad;
s24 unk1;
HksType type;
s32 unk2;
};
struct LuaStructMember {
s32 pad;
LuaStructHeader header;
s32 index;
};
struct LuaStruct {
try {
u32 unk;
LuaStructHeader ExtendedStructHeader;
s64 ExtendedStructMemberCount;
LuaStructMember ExtendedStructMembers[ExtendedStructMemberCount];
u32 unk2;
} catch {
std::print("WARNING: this file does not support structs.");
}
try {
LuaStructHeader StructHeader;
s64 StructMemberCount;
LuaStructMember StructMembers[StructMemberCount];
} catch {
std::print("WARNING: this file does not support multiple structs.");
}
};
struct LuaHeader {
char luaheader[4];
u8 version;
u8 format;
lua_endian Endianness;
if (Endianness == lua_endian::big_endian) {
std::core::set_endian(std::mem::Endian::Big);
} else {
std::core::set_endian(std::mem::Endian::Little);
}
u8 intSize;
u8 size_tSize;
u8 instruction_size;
u8 number_size;
lua_numbertype numberType;
u8 flags;
u8 unknown;
LuaEnum enums;
LuaFunction LuaFunctions;
LuaStruct LuaStructures;
};
struct Header {
u32 magic;
u32 version;
u64 RootStructAltGUID;
u64 AssetChecksum;
u32 DependencyCount;
s32 DataBlockCount;
s32 TagStructCount;
s32 DataReferenceCount;
s32 TagReferenceCount;
u32 StringTableSize;
u32 ZoneSetDataSize;
u32 Unk_0x34;
u32 HeaderSize;
u32 DataSize;
u32 ResourceDataSize;
u32 ActualResoureDataSize;
u8 HeaderAlignment;
u8 TagDataAlignment;
u8 ResourceDataAlignment;
u8 ActualResourceDataAlignment;
s32 IsResource;
};
struct _s_tagblock {
char tagblock[16];
s32 count;
};
struct _s_resource {
char resource[12];
s32 count;
};
struct _s_data {
char data[24];
};
struct Data_Block {
u32 Size;
u16 Padding;
u16 Section;
u64 Offset;
};
struct Tag_Def_Structure {
s64 GUID_1;
s64 GUID_2;
u16 Type;
u16 Unk_0x12;
s32 TargetIndex;
s32 FieldBlock;
u32 FieldOffset;
};
struct Tag_Dependency {
char GroupTag[4] [[format("std::string::reverse")]];
u32 NameOffset;
u64 AssetID;
u32 GlobalID;
u32 Unk_0x14;
};
struct Data_Reference {
s32 ParentStructIndex;
s32 Unk_0x04;
s32 TargetIndex;
s32 FieldBlock;
u32 FieldOffset;
};
struct _s_tagref {
s64 GlobalHandle;
s32 ref_id_int;
s32 ref_id_sub;
s32 ref_id_center_int;
char TagGroupRev[4] [[format("std::string::reverse")]];
s32 local_handle;
};
struct Tag_Fixup_Reference {
s32 FieldBlock;
u32 FieldOffset;
u32 NameOffset;
s32 DependencyIndex;
_s_tagref tagreference @ header.HeaderSize + datablocks[FieldBlock].Offset + FieldOffset;
};
struct InternalStruct {
s64 vtablespace;
u32 global_tag_id;
char local_tag_handle[4];
};
struct LuaReferencedTagContainer {
_s_tagref tagReference;
};
struct LuaScriptTagDefinition {
u32 luaFileName;
_s_data luaFileData;
char luaFileNameString[256];
_s_tagblock referencedTags_count;
LuaHeader lua_header;
try {
char pad[14];
LuaReferencedTagContainer referencedTags[referencedTags_count.count];
} catch {
std::print("This file does not support referenced Tags.");
}
};
// TAG LAYOUT
Header header @ 0x00;
Tag_Dependency Dependencies[header.DependencyCount] @ 0x50;
Data_Block datablocks[header.DataBlockCount] @ header.DependencyCount * 0x18 + 0x50;
Tag_Def_Structure tagdefstructure[header.TagStructCount] @ header.DependencyCount * 0x18 + 0x50 + header.DataBlockCount * 0x10;
Data_Reference Data_References[header.DataReferenceCount] @ header.DependencyCount * 0x18 + 0x50 + header.DataBlockCount * 0x10 + header.TagStructCount * 0x20;
Tag_Fixup_Reference tagfixupreference[header.TagReferenceCount] @ header.DependencyCount * 0x18 + 0x50 + header.DataBlockCount * 0x10 + header.TagStructCount * 0x20 + header.DataReferenceCount * 0x14;
char ZoneSet[header.ZoneSetDataSize] @ header.HeaderSize - header.ZoneSetDataSize;
InternalStruct internalstruct @ header.HeaderSize;
LuaScriptTagDefinition lua_script @ header.HeaderSize + 16;