mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-26 06:20:24 +00:00
Parse CTPK
This commit is contained in:
parent
9db860f0b8
commit
fb2648205b
11 changed files with 205 additions and 6 deletions
|
@ -1367,7 +1367,10 @@ namespace FirstPlugin
|
|||
|
||||
var ImageDataCached = new List<List<byte[]>>();
|
||||
if (Texture != null && Texture.TextureData != null)
|
||||
ImageDataCached = Texture.TextureData;
|
||||
{
|
||||
foreach (var sliceData in Texture.TextureData)
|
||||
ImageDataCached.Add(sliceData);
|
||||
}
|
||||
|
||||
switch (ext)
|
||||
{
|
||||
|
|
|
@ -7,10 +7,11 @@ using Toolbox;
|
|||
using System.Windows.Forms;
|
||||
using Toolbox.Library;
|
||||
using Toolbox.Library.IO;
|
||||
using Toolbox.Library.Forms;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
public class CTPK : IFileFormat
|
||||
public class CTPK : TreeNodeFile, IFileFormat, ITextureIconLoader
|
||||
{
|
||||
public FileType FileType { get; set; } = FileType.Layout;
|
||||
|
||||
|
@ -29,6 +30,19 @@ namespace FirstPlugin
|
|||
}
|
||||
}
|
||||
|
||||
public List<STGenericTexture> IconTextureList
|
||||
{
|
||||
get
|
||||
{
|
||||
List<STGenericTexture> textures = new List<STGenericTexture>();
|
||||
foreach (STGenericTexture node in Nodes)
|
||||
textures.Add(node);
|
||||
|
||||
return textures;
|
||||
}
|
||||
set { }
|
||||
}
|
||||
|
||||
public Type[] Types
|
||||
{
|
||||
get
|
||||
|
@ -38,8 +52,17 @@ namespace FirstPlugin
|
|||
}
|
||||
}
|
||||
|
||||
public Header header;
|
||||
|
||||
public void Load(System.IO.Stream stream)
|
||||
{
|
||||
Text = FileName;
|
||||
|
||||
header = new Header();
|
||||
header.Read(new FileReader(stream));
|
||||
|
||||
for (int i = 0; i < header.Textures.Count; i++)
|
||||
Nodes.Add(new CtpkTextureWrapper(header.Textures[i]));
|
||||
}
|
||||
public void Unload()
|
||||
{
|
||||
|
@ -50,15 +73,125 @@ namespace FirstPlugin
|
|||
{
|
||||
}
|
||||
|
||||
public class CtpkTextureWrapper : STGenericTexture
|
||||
{
|
||||
public TextureEntry CtpkTexture;
|
||||
|
||||
public CtpkTextureWrapper(TextureEntry tex) {
|
||||
ApplyCtpkTexture(tex);
|
||||
}
|
||||
|
||||
private void ApplyCtpkTexture(TextureEntry tex)
|
||||
{
|
||||
CtpkTexture = tex;
|
||||
Width = tex.Width;
|
||||
Height = tex.Height;
|
||||
MipCount = tex.MipCount;
|
||||
ArrayCount = tex.FaceCount;
|
||||
Text = tex.Name;
|
||||
Format = CTR_3DS.ConvertPICAToGenericFormat(tex.PicaFormat);
|
||||
|
||||
Parameters.FlipY = true;
|
||||
}
|
||||
|
||||
public override bool CanEdit { get; set; } = false;
|
||||
|
||||
public override TEX_FORMAT[] SupportedFormats
|
||||
{
|
||||
get
|
||||
{
|
||||
return new TEX_FORMAT[]
|
||||
{
|
||||
TEX_FORMAT.B5G6R5_UNORM,
|
||||
TEX_FORMAT.R8G8_UNORM,
|
||||
TEX_FORMAT.B5G5R5A1_UNORM,
|
||||
TEX_FORMAT.B4G4R4A4_UNORM,
|
||||
TEX_FORMAT.LA8,
|
||||
TEX_FORMAT.HIL08,
|
||||
TEX_FORMAT.L8,
|
||||
TEX_FORMAT.A8_UNORM,
|
||||
TEX_FORMAT.LA4,
|
||||
TEX_FORMAT.A4,
|
||||
TEX_FORMAT.ETC1_UNORM,
|
||||
TEX_FORMAT.ETC1_A4,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetImageData(System.Drawing.Bitmap bitmap, int ArrayLevel)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
{
|
||||
return CtpkTexture.ImageData;
|
||||
}
|
||||
|
||||
|
||||
public override void OnClick(TreeView treeView)
|
||||
{
|
||||
UpdateEditor();
|
||||
}
|
||||
|
||||
private void UpdateEditor()
|
||||
{
|
||||
ImageEditorBase editor = (ImageEditorBase)LibraryGUI.GetActiveContent(typeof(ImageEditorBase));
|
||||
if (editor == null)
|
||||
{
|
||||
editor = new ImageEditorBase();
|
||||
editor.Dock = DockStyle.Fill;
|
||||
LibraryGUI.LoadEditor(editor);
|
||||
}
|
||||
|
||||
editor.LoadProperties(GenericProperties);
|
||||
editor.LoadImage(this);
|
||||
}
|
||||
}
|
||||
|
||||
public class Header
|
||||
{
|
||||
public const string MAGIC = "CTPK";
|
||||
|
||||
public ushort Version { get; set; }
|
||||
|
||||
public List<TextureEntry> Textures { get; set; }
|
||||
|
||||
public List<ConversionInfo> ConversionInfos { get; set; }
|
||||
|
||||
public void Read(FileReader reader)
|
||||
{
|
||||
Textures = new List<TextureEntry>();
|
||||
ConversionInfos = new List<ConversionInfo>();
|
||||
|
||||
reader.ReadSignature(4, MAGIC);
|
||||
Version = reader.ReadUInt16();
|
||||
ushort numTextures = reader.ReadUInt16();
|
||||
uint textureDataOffset = reader.ReadUInt32();
|
||||
uint hashArrayOffset = reader.ReadUInt32();
|
||||
uint conversionInfoOffset = reader.ReadUInt32();
|
||||
|
||||
reader.Position = 0x20;
|
||||
for (int i = 0; i < numTextures; i++)
|
||||
{
|
||||
TextureEntry entry = new TextureEntry();
|
||||
entry.Read(reader);
|
||||
Textures.Add(entry);
|
||||
}
|
||||
|
||||
reader.SeekBegin(conversionInfoOffset);
|
||||
for (int i = 0; i < numTextures; i++)
|
||||
{
|
||||
ConversionInfo conversionInfo = new ConversionInfo();
|
||||
conversionInfo.Read(reader);
|
||||
ConversionInfos.Add(conversionInfo);
|
||||
}
|
||||
|
||||
for (int i = 0; i < numTextures; i++)
|
||||
{
|
||||
reader.SeekBegin(textureDataOffset + Textures[i].DataOffset);
|
||||
Textures[i].ImageData = reader.ReadBytes((int)Textures[i].ImageSize);
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(FileWriter writer)
|
||||
|
@ -66,5 +199,70 @@ namespace FirstPlugin
|
|||
writer.Write(MAGIC);
|
||||
}
|
||||
}
|
||||
|
||||
public class TextureEntry
|
||||
{
|
||||
public CTR_3DS.PICASurfaceFormat PicaFormat { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
public uint ImageSize { get; set; }
|
||||
public uint TextureFormat { get; set; }
|
||||
public ushort Width { get; set; }
|
||||
public ushort Height { get; set; }
|
||||
public byte MipCount { get; set; }
|
||||
public byte Type { get; set; }
|
||||
public ushort FaceCount { get; set; }
|
||||
public uint UnixTimeStamp { get; set; }
|
||||
|
||||
internal uint DataOffset { get; set; }
|
||||
internal uint BitmapSizeOffset { get; set; }
|
||||
|
||||
public byte[] ImageData { get; set; }
|
||||
|
||||
public void Read(FileReader reader)
|
||||
{
|
||||
Name = reader.LoadString(false, typeof(uint));
|
||||
ImageSize = reader.ReadUInt32();
|
||||
DataOffset = reader.ReadUInt32();
|
||||
TextureFormat = reader.ReadUInt32();
|
||||
Width = reader.ReadUInt16();
|
||||
Height = reader.ReadUInt16();
|
||||
MipCount = reader.ReadByte();
|
||||
Type = reader.ReadByte();
|
||||
FaceCount = reader.ReadUInt16();
|
||||
BitmapSizeOffset = reader.ReadUInt32();
|
||||
UnixTimeStamp = reader.ReadUInt32();
|
||||
|
||||
PicaFormat = (CTR_3DS.PICASurfaceFormat)TextureFormat;
|
||||
}
|
||||
|
||||
public void Write(FileWriter writer)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class ConversionInfo
|
||||
{
|
||||
public byte TextureFormat { get; set; }
|
||||
public byte Unknown { get; set; }
|
||||
public bool Compressed { get; set; }
|
||||
public byte Etc1Quality { get; set; }
|
||||
|
||||
public void Read(FileReader reader)
|
||||
{
|
||||
TextureFormat = reader.ReadByte();
|
||||
Unknown = reader.ReadByte();
|
||||
Compressed = reader.ReadBoolean();
|
||||
Etc1Quality = reader.ReadByte();
|
||||
}
|
||||
|
||||
public void Write(FileWriter writer)
|
||||
{
|
||||
writer.Write(TextureFormat);
|
||||
writer.Write(Unknown);
|
||||
writer.Write(Compressed);
|
||||
writer.Write(Etc1Quality);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@ namespace FirstPlugin.Forms
|
|||
if (ofd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (IsBntx)
|
||||
((TextureData)image).Replace(ofd.FileName, 0, 0, image.Format, ((TextureData)image).Texture.SurfaceDim);
|
||||
((TextureData)image).Replace(ofd.FileName, 0, (uint)ImageIndex, image.Format, ((TextureData)image).Texture.SurfaceDim);
|
||||
else
|
||||
image.Replace(ofd.FileName);
|
||||
}
|
||||
|
|
|
@ -364,6 +364,7 @@ namespace FirstPlugin
|
|||
Formats.Add(typeof(IGZ_TEX));
|
||||
Formats.Add(typeof(MOD));
|
||||
Formats.Add(typeof(U8));
|
||||
Formats.Add(typeof(CTPK));
|
||||
|
||||
//Unfinished wip formats not ready for use
|
||||
if (Runtime.DEVELOPER_DEBUG_MODE)
|
||||
|
|
|
@ -194,8 +194,6 @@ namespace Toolbox.Library.Forms
|
|||
|
||||
Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight);
|
||||
|
||||
Console.WriteLine("generating mips CTR");
|
||||
|
||||
List<byte[]> mipmaps = new List<byte[]>();
|
||||
mipmaps.Add(CTR_3DS.EncodeBlock(DecompressedData[SurfaceLevel],
|
||||
(int)TexWidth, (int)TexHeight, Format));
|
||||
|
|
|
@ -110,7 +110,6 @@ namespace Toolbox.Library
|
|||
if (Increment == 0) Increment = 1;
|
||||
|
||||
int IOffset = 0;
|
||||
|
||||
for (int TY = 0; TY < Height; TY += 8)
|
||||
{
|
||||
for (int TX = 0; TX < Width; TX += 8)
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue