-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMaterialArchive.bt
318 lines (278 loc) · 7.79 KB
/
MaterialArchive.bt
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
#ifndef _MATERIALARCHIVE
#define _MATERIALARCHIVE
struct SBufferTOCEntry {
uint align;
uint size;
};
struct CPermutation {
uint64 unk1;
uint64 unk2;
};
enum <char> EMaterialTechnique {
kMT_None = 'x', /* offset 0x10 = 9, offset 0x20 = 0, offset 0x28 = 1, type = 0 */
kMT_DepthOnly = 'z',/* offset 0x10 = 15, offset 0x20 = 0, offset 0x28 = 1, type 1 */
kMT_DeferredGBuffer = 'g',/* offset 0x10 = 15, offset 0x20 = 0, offset 0x28 = 1, type 2 */
kMT_DeferredInstance = 'i',/* offset 0x10 = 16, offset 0x20 = 0, offset 0x28 = 1, type 3 */
kMT_ForwardRender = 'f', /* offset 0x10 = 13, offset 0x20 = 0, offset 0x28 = 1, type 4 */
kMT_ParticleTechniqueSprite = 's', /* offset 0x10 = 23, offset 0x20 = 0, offset 0x28 = 1, type 5 */
kMT_ParticleTechniqueSwoosh = 'w', /* offset 0x10 = 23, offset 0x20 = 0, offset 0x28 = 1, type 6 */
kMT_ParticleTechniqueModel = 'm', /* offset 0x10 = 22, offset 0x20 = 0, offset 0x28 = 1, type 7 */
};
struct CShaderIdentifier {
EMaterialTechnique matTechnique;
CPermutation perm;
};
struct SShaderTOCEntry {
CShaderIdentifier identifier;
uint unk1;
uint unk2;
};
struct SMaterialTOCEntry {
GUID guid;
uint unk1;
uint nameLen;
char name[nameLen];
ushort unk2;
uint shaderEntryCount;
SShaderTOCEntry shaderEntries[shaderEntryCount];
SBufferTOCEntry bufferToc;
};
struct SShaderSource {
uchar state;
uint strLen;
if (strLen)
char str[strLen];
uint dataLen;
uchar data[dataLen];
};
struct CShaderDefines {
struct Name {
if (isDKCTF)
{
CString str1;
}
else
{
CStringFixed str1;
}
};
uint namesCount;
if (namesCount)
Name names[namesCount] <optimize = false>;
uint unk;
};
struct CShaderVariable {
ushort unk1;
};
struct SShaderImportDesc {
if (!isDKCTF)
{
CShaderIdentifier ident;
}
uint64 shaderID;
int vertexProgramIndex;
if (!isDKCTF)
{
int pixelProgramIndex;
}
else
{
int fragProgramIndex;
}
int geomProgramIndex;
if (!isDKCTF)
{
int computeProgramIndex;
}
uint unk;
CShaderDefines defines;
uint dataSize;
union {
struct {
uint variableCount;
CShaderVariable variables[1];
} meta;
char data[dataSize];
} data;
};
struct SExpression {
uint unk1;
uint unk2;
};
struct CBooleanExpressionEvaluator {
uint expressionCount;
SExpression expressions[expressionCount];
};
struct SSimpleFeatureInstanceInternalOptionRequirement {
uint unk;
CBooleanExpressionEvaluator evaluator;
};
struct SSimpleFeatureInstanceShaderBinding {
CStringFixed name;
CStringFixed binding;
};
struct SSimpleFeatureInstanceInternalOption {
uint unk;
CShaderDefines shaderDefines;
uint bindingCount;
if (bindingCount) {
SSimpleFeatureInstanceShaderBinding binding[bindingCount] <optimize = false>;
}
};
struct IFeatureInstance;
struct CFeatureSet {
uint count;
IFeatureInstance features[count] <optimize = false>;
CBooleanExpressionEvaluator evaluator;
};
struct CSimpleFeatureInstance {
FourCC unk1;
uint fccCount;
uint fccs[fccCount];
uint boolExpresionEvalCount;
CBooleanExpressionEvaluator evaluators[boolExpresionEvalCount] <optimize = false>;
uint internalOptionCount;
SSimpleFeatureInstanceInternalOption internalOption[internalOptionCount] <optimize = false>;
uint unk;
uint unkIntCount;
Assert(unkIntCount <= 32);
uint unkInts[unkIntCount];
uint optionRequirementCount;
if (optionRequirementCount)
SSimpleFeatureInstanceInternalOptionRequirement optionRequirements[optionRequirementCount] <optimize = false>;
};
struct SCompositeFeatureInstanceInternalOptionRequirement {
uint unk;
CBooleanExpressionEvaluator eval;
};
struct SCompositeFeatureInstanceInternalOption {
CStringFixed name;
CPermutation perm;
CShaderDefines defines;
};
struct SCompositeFeatureInstanceArgument {
CStringFixed name;
CBooleanExpressionEvaluator evaluator;
};
struct CCompositeFeatureInstance {
CFeatureSet subSet;
uint argumentCount1;
if (argumentCount1) {
SCompositeFeatureInstanceArgument arguments1[argumentCount1] <optimize = false>;
}
uint argumentCount2;
if (argumentCount2) {
SCompositeFeatureInstanceArgument arguments2[argumentCount2] <optimize = false>;
}
uint optionCount;
SCompositeFeatureInstanceInternalOption optionRequirements1[optionCount] <optimize = false>;
uint optionRequirementsCount;
SCompositeFeatureInstanceInternalOptionRequirement optionRequirements2[optionRequirementsCount] <optimize = false>;
};
struct IFeatureInstance;
struct CExplicitCompositeFeatureInstance;
struct CExplicitCompositeFeatureInstance {
CCompositeFeatureInstance base;
IFeatureInstance sub;
};
struct IFeatureInstance {
uint type;
CStringFixed name;
uint dataOrigin;
uint optionCount;
switch(type) {
case 0:
CSimpleFeatureInstance simple <optimize = false>;
break;
case 1:
CCompositeFeatureInstance composite <optimize = false>;
break;
case 2:
CExplicitCompositeFeatureInstance explicitComposite <optimize = false>;
break;
}
};
struct SDepthModeState {
};
struct SStencilModeState {
};
struct CGraphicsState {
uint flags;
};
struct SOverrideState {
CBooleanExpressionEvaluator evaluator;
CGraphicsState state;
};
struct SMaterialImportDesc {
if (!isDKCTF)
{
GUID guid;
uint shaderHash;
CStringFixed name;
}
else
{
FourCC name;
}
ushort unk2;
uint shaderImportCount;
SShaderImportDesc shaderImportDescs[shaderImportCount] <optimize = false>;
uint dataSize;
union {
struct {
uchar hasFeatureSet;
if (hasFeatureSet) {
CFeatureSet featureSet;
}
CGraphicsState state;
uint overrideStateCount;
if (overrideStateCount) {
SOverrideState overrideStates;
}
} meta;
char data[dataSize];
} data;
};
struct MaterialBackend {
ChunkDescriptor chunk;
local uint64 start <format=hex, hidden=true> = FTell();
uint flags;
if (flags != 0) {
uint tocSize;
uint bufferEntryCount;
SBufferTOCEntry bufferEntries[bufferEntryCount];
if (!isDKCTF)
{
uint materialEntryCount;
SMaterialTOCEntry materialEntries[materialEntryCount] <optimize = false>;
}
}
if (!isDKCTF)
{
uint shaderSourceCount;
SShaderSource shaderSources[shaderSourceCount] <optimize = false>;
}
uint materialImportDescCount;
SMaterialImportDesc materialImportDescs[materialImportDescCount] <optimize = false>;
if ((FTell() - start) != chunk.size) {
char data[chunk.size - (FTell() - start)];
}
};
struct MaterialArchive(uint64 size) {
local uint64 start <format=hex, hidden=true> = FTell();
while (FTell() < start + size) {
MaterialBackend backend;
}
};
struct SMaterialMetaData(uint64 fileStart) {
uint32 count;
uint32 version;
uint32 compressedSize;
uint32 decompressedSize;
uint32 fileOffset;
local uint64 pos <format=hex, hidden=true> = FTell();
FSeek(fileStart + fileOffset);
byte zlibData[compressedSize];
FSeek(pos);
};
#endif// _MATERIALARCHIVE