-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathExtractDebugShaders.cs
More file actions
331 lines (272 loc) · 15.6 KB
/
Copy pathExtractDebugShaders.cs
File metadata and controls
331 lines (272 loc) · 15.6 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using DataTool.Flag;
using DataTool.Helper;
using DataTool.SaveLogic;
using TankLib;
using TankLib.STU.Types;
using static DataTool.Program;
using static DataTool.Helper.STUHelper;
using TankLib.Helpers;
namespace DataTool.ToolLogic.Extract.Debug;
[Tool("extract-debug-shaders", Description = "Extract shaders for a material (debug)", CustomFlags = typeof(ExtractFlags), IsSensitive = true)]
public class ExtractDebugShaders : ITool {
public void Parse(ICLIFlags toolFlags) {
GetShaders(toolFlags);
}
public void GetShaders(ICLIFlags toolFlags) {
const string container = "ShaderCode";
//const ulong materialGUID = 0xE00000000005860; // 000000005860.008: Sombra - League - NYXL - Main
//const string matName = "Sombra - League - NYXL - Main";
//const ulong materialGUID = 0xE00000000006086;
//const string matName = "Orisa - Nature - Leaves";
//const ulong materialGUID = 0xE00000000002381;
//const string matName = "Maps - Tall bush";
//const ulong materialGUID = 0xE000000000008B2;
//const string matName = "Widow - Odette - Arm tassels";
// orisa owl
//const ulong materialGUID = 0xE00000000005809; // 000000005809.008: Orisa - League - NYXL - Team Decals
//const string matName = "Orisa - League - NYXL - Team Decals";
//const ulong materialGUID = 0xE00000000005840;
//const string matName = "Orisa - League - NYXL - Main";
//const ulong materialGUID = 0xE000000000051CC;
//const string matName = "Orisa - League - NYXL - 51CC";
string basePath;
if (toolFlags is ExtractFlags flags) {
basePath = flags.OutputPath;
} else {
throw new Exception("no output path");
}
string path = Path.Combine(basePath, container);
IO.WriteFile(0x0C008000CAE5C31B, path); // failing tex. 0 payloads. but data
IO.WriteFile(0x0D00000000000F5B, path); // tracer model (idk which)
IO.WriteFile(0x0D0000000000302E, path); // tracer model 2 (idk which)
IO.WriteFile(0x0D00000000000413, path); // tracer model 3 (idk which)
IO.WriteFile(0x0D000000000002B1, path); // tracer model 4 (main)
IO.WriteFile(0x0D000000000006A0, path); // pharah main
IO.WriteFile(0x0D0000000000DCA7, path); // sojurn main
IO.WriteFile(0x0D0000000000DCA8, path); // sojurn 1p
IO.WriteFile(0xD0000000000D748, path); // tracer new
IO.WriteFile(0xD0000020000D748, path); // tracer new lod
IO.WriteFile(0x0E8800000000000F, path); // lod streaming model.... omnic waiter? donk
FindLogic.Combo.ComboInfo comboInfo = new FindLogic.Combo.ComboInfo();
FindLogic.Combo.Find(comboInfo, 0x0C00000000035A3D); // toronto broken mips
FindLogic.Combo.Find(comboInfo, 0x0C0000000001B1D0); // more broken mips
FindLogic.Combo.Find(comboInfo, 0x0C0000000002C94F); // kanezaka cube
var context = new Combo.SaveContext(comboInfo);
Combo.SaveLooseTextures(flags, path, context);
//return;
//TestModelLook(0x98000000000682F); // Chateau - Lake
//SaveMaterial(path, 0xE00000000004F46, "Chateau - Tower - Body");
//SaveMaterial(path, 0xE00000000004F45, "Chateau - Tower - Borders");
//SaveMaterial(path, 0xE00000000004D4B, "Chateau - Tower - Windows");
//SaveMaterial(path, 0xE00000000004F44, "Chateau - Tower - Tip");
//SaveMaterial(path, 0xE000000000003A5, "Rein - Shield - Main");
//SaveMaterial(path, 0xE00000000005840, "Orisa - League - NYXL - Main");
//SaveMaterial(path, 0xE00000000005809, "Orisa - League - NYXL - Team Decals");
//SaveMaterial(path, 0xE00000000005C70, "Moira - Blackwatch - Decals");
//SaveMaterial(path, 0xE0000000000562D, "Moira - Blackwatch - Face");
//SaveCompute(path);
// string allPath = Path.Combine(path, "All");
// foreach (ulong inst in TrackedFiles[0x86]) {
// SaveShaderInstance(allPath, inst, teResourceGUID.AsString(inst));
// }
// return;
SaveMaterial(path, 0xE00000000002381, "Chateau - Tall bush");
SaveMaterial(path, 0xE00000000004D29, "Chateau - Lake");
//SaveMaterial(path, 0xE00000000004F0B, "Chateau - Background - Road");
//SaveMaterial(path, 0xE00000000004EFF, "Chateau - Background - House");
SaveMaterial(path, 0xE00000000004F46, "Chateau - Tower - Body");
SaveMaterial(path, 0xE000000000040C0, "Orisa - Classic - Main");
SaveMaterial(path, 0xE00000000000171, "Reaper - Classic - Main");
SaveMaterial(path, 0xE00000000005BBB, "Brigitte - Classic - Hair");
//SavePostFX(path);
//SaveScreenQuad(path);
//Save088(path);
}
public void TestModelLook(ulong guid) {
STUModelLook modelLook = GetInstance<STUModelLook>(guid);
}
public void Save088(string basePath) {
var path = Path.Combine(basePath, "088");
//{
// var path2 = Path.Combine(basePath, "xxShader}");
// using (Stream stream = IO.OpenFile((teResourceGUID) 0xE100000000000xx)) {
// teShaderGroup shaderGroup = new teShaderGroup(stream);
// SaveShaderGroup(shaderGroup, path2);
// }
//}
foreach (ulong guid in TrackedFiles[0x88]) {
using (Stream stream = IO.OpenFile(guid)) {
teShaderGroup shaderGroup = new teShaderGroup(stream);
string groupPath = Path.Combine(path, teResourceGUID.AsString(guid));
SaveShaderGroup(shaderGroup, groupPath);
}
}
}
public void SaveScreenQuad(string basePath) {
var path = Path.Combine(basePath, "ScreenQuad");
using (Stream stream = IO.OpenFile((teResourceGUID) 0xE1000000000000C)) {
teShaderGroup shaderGroup = new teShaderGroup(stream);
SavePostShader(path, shaderGroup, 0xF1B0EC09, "s_pVShader");
SavePostShader(path, shaderGroup, 0x2183B37B, "s_pGeometryVShader");
SavePostShader(path, shaderGroup, 0xF203D3B5, "s_pDepthVShader");
SavePostShader(path, shaderGroup, 0xBD9B9307, "s_pLayerVShader"); // VERTEX, UNKNOWN_C????
}
}
public void SavePostFX(string basePath) {
var path = Path.Combine(basePath, "PostFX");
using (Stream stream = IO.OpenFile((teResourceGUID) 0xE10000000000044)) {
teShaderGroup shaderGroup = new teShaderGroup(stream);
SavePostShader(path, shaderGroup, 0xF0A5D76B, "CopyPointSampledState");
SavePostShader(path, shaderGroup, 0x64DADF24, "OutlineFinalizeState");
SavePostShader(path, shaderGroup, 0xA2883CA8, "OutlineFinalizeApplyState");
SavePostShader(path, shaderGroup, 0x24F981CF, "RefractedOutlineFinalizeState[0]");
//SavePostShader(path, shaderGroup, 0x64DADF24, "RefractedOutlineFinalizeState[1]"); // same as m_outlineFinalizeState
SavePostShader(path, shaderGroup, 0x6E8A86F6, "RefractedOutlineFinalizeApplyState[0]");
//SavePostShader(path, shaderGroup, 0xA2883CA8, "RefractedOutlineFinalizeState[1]"); // same as m_outlineFinalizeApplyState
SavePostShader(path, shaderGroup, 0x2314B25F, "SolidColorState");
SavePostShader(path, shaderGroup, 0x23DEF50E, "HistogramState");
SavePostShader(path, shaderGroup, 0xF4F31C1E, "BrightPassStateLo");
SavePostShader(path, shaderGroup, 0x2418E502, "BrightPassStateHi");
SavePostShader(path, shaderGroup, 0x660AA4D1, "DownsampleState");
SavePostShader(path, shaderGroup, 0x7918E37C, "DownsampleStateCheckForNaN");
SavePostShader(path, shaderGroup, 0xE30F741A, "DownsampleLuminanceState");
SavePostShader(path, shaderGroup, 0xED42C442, "HorizontalBlurState");
SavePostShader(path, shaderGroup, 0x5D84E4EE, "VerticalBlurState");
SavePostShader(path, shaderGroup, 0x7BD41894, "OverlayAddState");
SavePostShader(path, shaderGroup, 0x26817C6F, "InvertZState");
SavePostShader(path, shaderGroup, 0x3C8225F1, "DOFTileIntermediateState");
SavePostShader(path, shaderGroup, 0x48ED2C1F, "DOFTileState");
SavePostShader(path, shaderGroup, 0xEC9BC9DB, "DOFTileFilterState");
SavePostShader(path, shaderGroup, 0x51305AFC, "DOFPresortState");
SavePostShader(path, shaderGroup, 0xF191CE9E, "DOFCircularFilterState");
SavePostShader(path, shaderGroup, 0xEA0B974D, "DOFMedianFilterState");
SavePostShader(path, shaderGroup, 0x36DF160E, "DOFUpsampleState");
SavePostShader(path, shaderGroup, 0xB3FE8DDE, "DOFUpsampleIntoGbufferState");
SavePostShader(path, shaderGroup, 0x79C90032, "TonemapState");
SavePostShader(path, shaderGroup, 0x895D656C, "GammaCorrectionState");
SavePostShader(path, shaderGroup, 0x9615383C, "ColorGradingState");
SavePostShader(path, shaderGroup, 0x14B25063, "ColorizationState");
SavePostShader(path, shaderGroup, 0x924CFDEA, "CombinedMainState");
SavePostShader(path, shaderGroup, 0xEB0B080A, "CombinedAllEnabledMainState");
SavePostShader(path, shaderGroup, 0x7540E081, "RadialBlurState");
SavePostShader(path, shaderGroup, 0x3460D76B, "FXAAState");
SavePostShader(path, shaderGroup, 0x739B7624, "HorizontalOutlineBlurState");
SavePostShader(path, shaderGroup, 0xC35D5688, "VerticalOutlineBlurState");
SavePostShader(path, shaderGroup, 0x2314B25F, "OutlineBlackState");
//SavePostShader(path, shaderGroup, 0x2314B25F, "OutlineClearToBlackState"); // same as m_outlineBlackState
SavePostShader(path, shaderGroup, 0xA5DBBF87, "PostUnkVertex1");
SavePostShader(path, shaderGroup, 0xC335DDAE, "PostUnkVertex2");
}
}
public void SavePostShader(string path, teShaderGroup shaderGroup, uint hash, string name) {
teResourceGUID state = shaderGroup.GetShaderByHash(hash);
if (state == 0) {
Console.Out.WriteLine($"Couldn't find {hash} / {name}");
return;
}
SaveShaderInstance(path, state, name);
}
public void SaveCompute(string path) {
Dictionary<ulong, int> bufferOccr = new Dictionary<ulong, int>();
foreach (ulong guid in TrackedFiles[0x86]) {
teShaderInstance instance = new teShaderInstance(IO.OpenFile(guid));
//teShaderCode shaderCode = new teShaderCode(IO.OpenFile(instance.Header.ShaderCode));
if (instance.BufferHeaders == null) continue;
foreach (teShaderInstance.BufferHeader bufferHeader in instance.BufferHeaders) {
if (!bufferOccr.ContainsKey(bufferHeader.Hash)) {
bufferOccr[bufferHeader.Hash] = 0;
}
bufferOccr[bufferHeader.Hash]++;
}
//if (shaderCode.Header.ShaderType == Enums.teSHADER_TYPE.COMPUTE) {
// SaveShaderInstance(path, guid, instance, shaderCode);
//}
}
int i = 0;
foreach (KeyValuePair<ulong, int> buffer in bufferOccr.OrderByDescending(x => x.Value)) {
Console.Out.WriteLine($"{buffer.Key:X16}: {buffer.Value}");
i++;
//if (i == 10) {
// break;
//}
}
}
public static void SaveMaterial(string basePath, ulong materialGUID, string name) {
string path = Path.Combine(basePath, name, IO.GetFileName(materialGUID));
string rawPath = Path.Combine(path, "raw");
string imgPath = Path.Combine(path, "img");
// IO.CreateDirectorySafe(path);
IO.CreateDirectorySafe(rawPath);
var matStream = IO.OpenFile(materialGUID);
if (matStream == null) return;
teMaterial material = new teMaterial(matStream);
IO.WriteFile(materialGUID, rawPath);
IO.WriteFile(material.Header.ShaderSource, rawPath);
IO.WriteFile(material.Header.ShaderGroup, rawPath);
IO.WriteFile(material.Header.GUIDx03A, rawPath);
IO.WriteFile(material.Header.MaterialData, rawPath);
using (Stream stream = IO.OpenFile(material.Header.MaterialData)) {
if (stream != null) {
teMaterialData materialData = new teMaterialData(stream);
if (materialData.Textures != null) {
FindLogic.Combo.ComboInfo comboInfo = new FindLogic.Combo.ComboInfo();
foreach (var texture in materialData.Textures) {
FindLogic.Combo.Find(comboInfo, texture.TextureGUID);
comboInfo.SetTextureName(texture.TextureGUID, texture.NameHash.ToString("X8")+".tif");
IO.WriteFile(texture.TextureGUID, rawPath);
IO.WriteFile(teTexture.GetPayloadGUID2(texture.TextureGUID, 1), rawPath);
IO.WriteFile(teTexture.GetPayloadGUID2(texture.TextureGUID, 2), rawPath);
IO.WriteFile(teTexture.GetPayloadGUID2(texture.TextureGUID, 3), rawPath);
IO.WriteFile(teTexture.GetPayloadGUID2(texture.TextureGUID, 4), rawPath);
}
var context = new Combo.SaveContext(comboInfo);
Combo.SaveLooseTextures(null, imgPath, context);
}
}
}
teShaderGroup shaderGroup = new teShaderGroup(IO.OpenFile(material.Header.ShaderGroup));
SaveShaderGroup(shaderGroup, path);
}
public static void SaveShaderGroup(teShaderGroup shaderGroup, string path) {
int i = 0;
foreach (ulong shaderGroupInstance in shaderGroup.Instances) {
string name = null;
Logger.Error("SaveShaderGroup", $"teShaderGroup no longer associates a hash with teShaderInstance, see documentation on GetShaderByHash.");
//if (shaderGroup.Hashes != null && shaderGroup.Hashes[i] != 0) {
// name = shaderGroup.Hashes[i].ToString("X8");
//}
SaveShaderInstance(path, shaderGroupInstance, name);
i++;
}
}
public static void SaveShaderInstance(string path, ulong guid, string name) {
/*string rawPath = Path.Combine(path, "raw");
IO.WriteFile(guid, rawPath);
return;*/
teShaderInstance instance = new teShaderInstance(IO.OpenFile(guid));
teShaderCode shaderCode = new teShaderCode(IO.OpenFile(instance.Header.ShaderCode));
if (name == null) {
name = teResourceGUID.AsString(guid);
}
string instanceDirectory = Path.Combine(path, shaderCode.Header.ShaderType.ToString(), name);
IO.WriteFile(guid, instanceDirectory);
IO.WriteFile(instance.Header.ShaderCode, instanceDirectory);
using (Stream file = File.OpenWrite(Path.Combine(instanceDirectory, IO.GetFileName(instance.Header.ShaderCode) + ".bin"))) {
file.SetLength(0);
file.Write(shaderCode.ByteCode, 0, shaderCode.ByteCode.Length);
}
using (StreamWriter writer =
new StreamWriter(Path.Combine(instanceDirectory, IO.GetFileName(instance.Header.ShaderCode)) + ".meta")) {
writer.WriteLine($"{shaderCode.Header.ShaderType}");
writer.WriteLine("{texture \"hash\"} : {shader input index}");
if (instance.ShaderResources == null) return;
foreach (teShaderInstance.ShaderResourceDefinition textureInputDefinition in instance.ShaderResources) {
writer.WriteLine($"{textureInputDefinition.NameHash:X8} : {textureInputDefinition.Register}");
}
}
}
}