Skip to content

Commit c1f7079

Browse files
committed
- Allow writing any DDS type for direct DDS imports.
- Allow writing Type 2 files with headers larger than 256 bytes.
1 parent 0d4f5fd commit c1f7079

File tree

2 files changed

+36
-29
lines changed
  • xivModdingFramework

2 files changed

+36
-29
lines changed

xivModdingFramework/SqPack/FileTypes/Dat.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -696,16 +696,17 @@ public async Task<byte[]> CreateType2Data(byte[] dataToCreate)
696696
headerData.InsertRange(12, BitConverter.GetBytes(totalCompSize / 128));
697697
headerData.InsertRange(16, BitConverter.GetBytes(totalCompSize / 128));
698698

699-
var headerSize = 128;
700-
701-
if (headerData.Count > 128)
699+
var headerSize = headerData.Count;
700+
var rem = headerSize % 128;
701+
if(rem != 0)
702702
{
703-
headerData.RemoveRange(0, 4);
704-
headerData.InsertRange(0, BitConverter.GetBytes(256));
705-
headerSize = 256;
703+
headerSize += (128 - rem);
706704
}
707-
var headerPadding = headerSize - headerData.Count;
708705

706+
headerData.RemoveRange(0, 4);
707+
headerData.InsertRange(0, BitConverter.GetBytes(headerSize));
708+
709+
var headerPadding = rem == 0 ? 0 : 128 - rem;
709710
headerData.AddRange(new byte[headerPadding]);
710711

711712
newData.AddRange(headerData);

xivModdingFramework/Textures/FileTypes/Tex.cs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,6 @@ public XivTexFormat GetDDSTexFormat(BinaryReader ddsStream)
712712
/// <returns></returns>
713713
public async Task<byte[]> MakeTexData(string internalPath, string externalPath, XivTexFormat texFormat = XivTexFormat.INVALID )
714714
{
715-
716715
// Ensure file exists.
717716
if (!File.Exists(externalPath))
718717
{
@@ -748,7 +747,7 @@ public async Task<byte[]> MakeTexData(string internalPath, string externalPath,
748747
}
749748

750749
// Check if the texture being imported has been imported before
751-
CompressionFormat compressionFormat;
750+
CompressionFormat compressionFormat = CompressionFormat.BGRA;
752751

753752
switch (texFormat)
754753
{
@@ -762,33 +761,40 @@ public async Task<byte[]> MakeTexData(string internalPath, string externalPath,
762761
compressionFormat = CompressionFormat.BGRA;
763762
break;
764763
default:
765-
throw new Exception($"Format {texFormat} is not currently supported for BMP import\n\nPlease use the DDS import option instead.");
764+
if (!isDds)
765+
{
766+
throw new Exception($"Format {texFormat} is not currently supported for BMP import\n\nPlease use the DDS import option instead.");
767+
}
768+
break;
766769
}
767770

768-
using (var surface = Surface.LoadFromFile(externalPath))
771+
if (!isDds)
769772
{
770-
if (surface == null)
771-
throw new FormatException($"Unsupported texture format");
773+
using (var surface = Surface.LoadFromFile(externalPath))
774+
{
775+
if (surface == null)
776+
throw new FormatException($"Unsupported texture format");
772777

773-
surface.FlipVertically();
778+
surface.FlipVertically();
774779

775-
var maxMipCount = 1;
776-
if (root != null)
777-
{
778-
// For things that have real roots (things that have actual models/aren't UI textures), we always want mipMaps, even if the existing texture only has one.
779-
// (Ex. The Default Mat-Add textures)
780-
maxMipCount = -1;
781-
}
780+
var maxMipCount = 1;
781+
if (root != null)
782+
{
783+
// For things that have real roots (things that have actual models/aren't UI textures), we always want mipMaps, even if the existing texture only has one.
784+
// (Ex. The Default Mat-Add textures)
785+
maxMipCount = -1;
786+
}
782787

783-
using (var compressor = new Compressor())
784-
{
785-
// UI/Paintings only have a single mipmap and will crash if more are generated, for everything else generate max levels
786-
compressor.Input.SetMipmapGeneration(true, maxMipCount);
787-
compressor.Input.SetData(surface);
788-
compressor.Compression.Format = compressionFormat;
789-
compressor.Compression.SetBGRAPixelFormat();
788+
using (var compressor = new Compressor())
789+
{
790+
// UI/Paintings only have a single mipmap and will crash if more are generated, for everything else generate max levels
791+
compressor.Input.SetMipmapGeneration(true, maxMipCount);
792+
compressor.Input.SetData(surface);
793+
compressor.Compression.Format = compressionFormat;
794+
compressor.Compression.SetBGRAPixelFormat();
790795

791-
compressor.Process(out ddsContainer);
796+
compressor.Process(out ddsContainer);
797+
}
792798
}
793799
}
794800

0 commit comments

Comments
 (0)