Skip to content

Commit

Permalink
Workaround for the crash when unpacking TPP ftex files
Browse files Browse the repository at this point in the history
  • Loading branch information
Atvaark committed Sep 3, 2015
1 parent 7fe7878 commit e20b621
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion FtexTool/FtexDdsConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private static List<FtexsFileChunk> GetFtexsChunks(FtexFileMipMapInfo mipMapInfo
int chunkSize = Math.Min(mipMapData.Length - mipMapDataOffset, maxChunkSize);
byte[] chunkData = new byte[chunkSize];
Array.Copy(mipMapData, mipMapDataOffset, chunkData, 0, chunkSize);
chunk.SetData(chunkData, false);
chunk.SetData(chunkData, false, chunkSize);
ftexsFileChunks.Add(chunk);
mipMapDataOffset += chunkSize;
}
Expand Down
17 changes: 14 additions & 3 deletions FtexTool/Ftexs/FtexsFileChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public void Read(Stream inputStream, bool absoluteOffset)

byte[] data = reader.ReadBytes(compressedChunkSize);
bool dataCompressed = compressedChunkSize != decompressedChunkSize;
SetData(data, dataCompressed);
SetData(data, dataCompressed, decompressedChunkSize);

reader.BaseStream.Position = indexEndPosition;
}

Expand All @@ -76,12 +77,22 @@ public void WriteData(Stream outputStream, bool writeCompressedData)
}
}

public void SetData(byte[] chunkData, bool compressed)
public void SetData(byte[] chunkData, bool compressed, long decompressedSize)
{
if (compressed)
{
CompressedChunkData = chunkData;
ChunkData = ZipUtility.Inflate(chunkData);
try
{
ChunkData = ZipUtility.Inflate(chunkData);
}
catch (Exception)
{
// BUG: Smaller TPP mipmaps fail to load at them moment.
// This catch block allows unpacking of the textures, but should
// be removed once the unpacking issue has been resolved.
ChunkData = new byte[decompressedSize];
}
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions FtexTool/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("d87a6cb1-0454-4123-8fc6-23f50523de89")]
[assembly: AssemblyVersion("0.2.5.0")]
[assembly: AssemblyFileVersion("0.2.5.0")]
[assembly: AssemblyVersion("0.3.0.0")]
[assembly: AssemblyFileVersion("0.3.0.0")]

0 comments on commit e20b621

Please sign in to comment.