Skip to content

Commit 524e08f

Browse files
committed
Fix on both ends (create, import) of TT for uncompressed Tex sizes
1 parent d870525 commit 524e08f

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

xivModdingFramework/Mods/FileTypes/TTMP.cs

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// xivModdingFramework
1+
// xivModdingFramework
22
// Copyright © 2018 Rafael Gonzalez - All Rights Reserved
33
//
44
// This program is free software: you can redistribute it and/or modify
@@ -48,9 +48,9 @@ public class TTMP
4848
".cmp", ".imc", ".eqdp", ".eqp", ".gmp", ".est"
4949
};
5050

51-
private readonly string _currentWizardTTMPVersion = "1.2w";
52-
private readonly string _currentSimpleTTMPVersion = "1.2s";
53-
private const string _minimumAssembly = "1.2.0.0";
51+
private readonly string _currentWizardTTMPVersion = "1.3w";
52+
private readonly string _currentSimpleTTMPVersion = "1.3s";
53+
private const string _minimumAssembly = "1.3.0.0";
5454

5555
private string _tempMPD, _tempMPL, _source;
5656
private readonly DirectoryInfo _modPackDirectory;
@@ -423,7 +423,7 @@ public Task<List<OriginalModPackJson>> GetOriginalModPackJsonData(DirectoryInfo
423423
/// </summary>
424424
/// <param name="modPackDirectory">The mod pack directory</param>
425425
/// <returns>The version of the mod pack as a string</returns>
426-
public string GetVersion(DirectoryInfo modPackDirectory)
426+
public static string GetVersion(DirectoryInfo modPackDirectory)
427427
{
428428
ModPackJson modPackJson = null;
429429

@@ -529,6 +529,7 @@ await Task.Run(async () =>
529529

530530
var _modding = new Modding(XivCache.GameInfo.GameDirectory);
531531
var modList = _modding.GetModList();
532+
var needsTexFix = DoesTexNeedFixing(modPackDirectory);
532533

533534
// 0 - Extract the MPD file.
534535
using (var zf = ZipFile.Read(modPackDirectory.FullName))
@@ -572,6 +573,10 @@ await Task.Run(async () =>
572573
{
573574
binaryReader.BaseStream.Seek(modJson.ModOffset, SeekOrigin.Begin);
574575
var data = binaryReader.ReadBytes(modJson.ModSize);
576+
577+
if (modJson.FullPath.EndsWith(".tex") && needsTexFix)
578+
FixupTextoolsTex(data);
579+
575580
var df = IOUtil.GetDataFileFromPath(modJson.FullPath);
576581

577582
var size = data.Length;
@@ -953,6 +958,46 @@ await Task.Run(async () =>
953958
return (count, errorCount, importErrors, seconds);
954959
}
955960

961+
/// <summary>
962+
/// Parse the version out of this modpack to determine whether or not we need
963+
/// to add 80 to the uncompressed size of the Tex files contained within.
964+
/// </summary>
965+
/// <param name="mpd">The path to the modpack.</param>
966+
/// <returns>True if we must modify tex header uncompressed sizes, false otherwise.</returns>
967+
private static bool DoesTexNeedFixing(DirectoryInfo mpd) {
968+
969+
var ver = GetVersion(mpd);
970+
if (string.IsNullOrEmpty(ver))
971+
return true;
972+
973+
var newVer = ver;
974+
975+
var lastChar = ver.Substring(ver.Length - 1)[0];
976+
if (char.IsLetter(lastChar))
977+
newVer = ver.Substring(0, ver.Length - 1);
978+
979+
double.TryParse(newVer, out var verDouble);
980+
981+
return verDouble < 1.3;
982+
}
983+
984+
/// <summary>
985+
/// Fix xivModdingFramework TEX quirks.
986+
/// </summary>
987+
/// <param name="tex">The TEX data to be fixed up.</param>
988+
public static void FixupTextoolsTex(byte[] tex) {
989+
990+
// Read the uncompressed size from the file
991+
var size = BitConverter.ToInt32(tex, 8);
992+
var newSize = size + 80;
993+
994+
byte[] buffer = BitConverter.GetBytes(newSize);
995+
tex[8] = buffer[0];
996+
tex[9] = buffer[1];
997+
tex[10] = buffer[2];
998+
tex[11] = buffer[3];
999+
}
1000+
9561001
/// <summary>
9571002
/// Gets the data type from an item path
9581003
/// </summary>

xivModdingFramework/SqPack/FileTypes/Dat.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// xivModdingFramework
1+
// xivModdingFramework
22
// Copyright © 2018 Rafael Gonzalez - All Rights Reserved
33
//
44
// This program is free software: you can redistribute it and/or modify
@@ -1266,7 +1266,7 @@ public byte[] MakeType4DatHeader(XivTexFormat format, List<short> mipPartOffsets
12661266

12671267
headerData.AddRange(BitConverter.GetBytes(headerSize + headerPadding));
12681268
headerData.AddRange(BitConverter.GetBytes(4));
1269-
headerData.AddRange(BitConverter.GetBytes(uncompressedLength));
1269+
headerData.AddRange(BitConverter.GetBytes(uncompressedLength + 80));
12701270
headerData.AddRange(BitConverter.GetBytes(0));
12711271
headerData.AddRange(BitConverter.GetBytes(0));
12721272
headerData.AddRange(BitConverter.GetBytes(newMipCount));

xivModdingFramework/xivModdingFramework.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
<AssemblyVersion>1.2.0.0</AssemblyVersion>
5+
<AssemblyVersion>1.3.0.0</AssemblyVersion>
66
<Version>1.0.8</Version>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
88
<LangVersion>latest</LangVersion>

0 commit comments

Comments
 (0)