|
1 | 1 | using Dalamud.Interface.ImGuiNotification;
|
| 2 | +using Lumina.Data.Files; |
2 | 3 | using OtterGui.Classes;
|
3 | 4 | using OtterGui.Services;
|
| 5 | +using Lumina.Extensions; |
| 6 | +using Penumbra.GameData.Files.Utility; |
| 7 | +using Penumbra.Import.Textures; |
4 | 8 | using SharpCompress.Common;
|
5 | 9 | using SharpCompress.Readers;
|
6 | 10 | using MdlFile = Penumbra.GameData.Files.MdlFile;
|
@@ -296,6 +300,26 @@ public void MigrateMtrlDuringExtraction(IReader reader, string directory, Extrac
|
296 | 300 | }
|
297 | 301 | }
|
298 | 302 |
|
| 303 | + public void FixMipMaps(IReader reader, string directory, ExtractionOptions options) |
| 304 | + { |
| 305 | + var path = Path.Combine(directory, reader.Entry.Key!); |
| 306 | + using var s = new MemoryStream(); |
| 307 | + using var e = reader.OpenEntryStream(); |
| 308 | + e.CopyTo(s); |
| 309 | + var length = s.Position; |
| 310 | + s.Seek(0, SeekOrigin.Begin); |
| 311 | + var br = new BinaryReader(s, Encoding.UTF8, true); |
| 312 | + var header = br.ReadStructure<TexFile.TexHeader>(); |
| 313 | + br.Dispose(); |
| 314 | + TexFileParser.FixMipOffsets(length, ref header, out var actualSize); |
| 315 | + |
| 316 | + s.Seek(0, SeekOrigin.Begin); |
| 317 | + Directory.CreateDirectory(Path.GetDirectoryName(path)!); |
| 318 | + using var f = File.Open(path, FileMode.Create, FileAccess.Write); |
| 319 | + f.Write(header); |
| 320 | + f.Write(s.GetBuffer().AsSpan(80, (int)actualSize - 80)); |
| 321 | + } |
| 322 | + |
299 | 323 | /// <summary> Update the data of a .mdl file during TTMP extraction. Returns either the existing array or a new one. </summary>
|
300 | 324 | public byte[] MigrateTtmpModel(string path, byte[] data)
|
301 | 325 | {
|
@@ -348,6 +372,25 @@ public byte[] MigrateTtmpMaterial(string path, byte[] data)
|
348 | 372 | }
|
349 | 373 | }
|
350 | 374 |
|
| 375 | + public byte[] FixTtmpMipMaps(string path, byte[] data) |
| 376 | + { |
| 377 | + using var m = new MemoryStream(data); |
| 378 | + var br = new BinaryReader(m, Encoding.UTF8, true); |
| 379 | + var header = br.ReadStructure<TexFile.TexHeader>(); |
| 380 | + br.Dispose(); |
| 381 | + TexFileParser.FixMipOffsets(data.Length, ref header, out var actualSize); |
| 382 | + if (actualSize == data.Length) |
| 383 | + return data; |
| 384 | + |
| 385 | + var ret = new byte[actualSize]; |
| 386 | + using var m2 = new MemoryStream(ret); |
| 387 | + using var bw = new BinaryWriter(m2); |
| 388 | + bw.Write(header); |
| 389 | + bw.Write(data.AsSpan(80, (int)actualSize - 80)); |
| 390 | + |
| 391 | + return ret; |
| 392 | + } |
| 393 | + |
351 | 394 |
|
352 | 395 | private static bool MigrateModel(string path, MdlFile mdl, bool createBackup)
|
353 | 396 | {
|
|
0 commit comments