Skip to content

Commit

Permalink
Minor sanity checks and fixes
Browse files Browse the repository at this point in the history
Added nicer unsupported GXT version message; disabled non-working (i.e. garbage-producing) v2 and v1 support, also reworked version detection/usage during conversion; fixed palette reading when GXT file size isn't exactly as expected, i.e. when manually extracted from other containers; increased version number
  • Loading branch information
xdanieldzd committed Mar 29, 2016
1 parent d4152cb commit 6b53af8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
21 changes: 13 additions & 8 deletions GXTConvert/FileFormat/GxtBinary.cs
Expand Up @@ -37,16 +37,21 @@ public GxtBinary(Stream stream)

Header = new SceGxtHeader(stream);

Func<Stream, SceGxtTextureInfo> textureInfoGeneratorFunc;
switch (Header.Version)
{
case 0x10000003: textureInfoGeneratorFunc = new Func<Stream, SceGxtTextureInfo>((s) => { return new SceGxtTextureInfoV301(s); }); break;
//case 0x10000002: textureInfoGeneratorFunc = new Func<Stream, SceGxtTextureInfo>((s) => { return new SceGxtTextureInfoV201(s); }); break;
//case 0x10000001: textureInfoGeneratorFunc = new Func<Stream, SceGxtTextureInfo>((s) => { return new SceGxtTextureInfoV101(s); }); break;
default: throw new VersionNotImplementedException(Header.Version);
// TODO: re-add v2 and v1 once they're understood
}

TextureInfos = new SceGxtTextureInfo[Header.NumTextures];
for (int i = 0; i < TextureInfos.Length; i++)
{
switch (Header.Version)
{
case 0x10000003: TextureInfos[i] = new SceGxtTextureInfoV301(stream); break;
case 0x10000002: TextureInfos[i] = new SceGxtTextureInfoV201(stream); break;
case 0x10000001: TextureInfos[i] = new SceGxtTextureInfoV101(stream); break;
default: throw new VersionNotImplementedException(Header.Version);
}
if (textureInfoGeneratorFunc != null)
TextureInfos[i] = textureInfoGeneratorFunc(stream);
}

// TODO: any other way to detect these?
Expand Down Expand Up @@ -78,7 +83,7 @@ public GxtBinary(Stream stream)

private void ReadAllBasePalettes(BinaryReader reader)
{
long paletteOffset = reader.BaseStream.Length - (((Header.NumP8Palettes * 256) * 4) + ((Header.NumP4Palettes * 16) * 4));
long paletteOffset = (Header.TextureDataOffset + Header.TextureDataSize) - (((Header.NumP8Palettes * 256) * 4) + ((Header.NumP4Palettes * 16) * 4));
reader.BaseStream.Seek(paletteOffset, SeekOrigin.Begin);

P4Palettes = new uint[Header.NumP4Palettes][];
Expand Down
4 changes: 4 additions & 0 deletions GXTConvert/Program.cs
Expand Up @@ -220,6 +220,10 @@ private static void ProcessInputFile(FileInfo inputFile, DirectoryInfo inputDir,
}
}
#if !DEBUG
catch (VersionNotImplementedException vniEx)
{
IndentWriteLine("GXT version {0:D2} (0x{1:X8}) not implemented.", (vniEx.Version & 0xFFFF), vniEx.Version);
}
catch (FormatNotImplementedException fniEx)
{
IndentWriteLine("Format '{0}' not implemented.", fniEx.Format);
Expand Down
4 changes: 2 additions & 2 deletions GXTConvert/Properties/AssemblyInfo.cs
Expand Up @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.5.0.0")]
[assembly: AssemblyFileVersion("0.5.0.0")]
[assembly: AssemblyVersion("0.6.0.0")]
[assembly: AssemblyFileVersion("0.6.0.0")]

0 comments on commit 6b53af8

Please sign in to comment.