1
0
mirror of synced 2025-01-31 12:23:52 +01:00

Palette bti fixes and U8 fixes

This commit is contained in:
KillzXGaming 2019-08-05 20:46:20 -04:00
parent a8f8deacd4
commit 2fd6077172
4 changed files with 112 additions and 9 deletions

Binary file not shown.

View File

@ -107,7 +107,7 @@ namespace FirstPlugin.LuigisMansion.DarkMoon
public ToolStripItem[] GetContextMenuItems()
{
List<ToolStripItem> Items = new List<ToolStripItem>();
Items.Add(new ToolStripMenuItem("Export All", null, ExportModelAction, Keys.Control | Keys.E));
Items.Add(new ToolStripMenuItem("Export", null, ExportModelAction, Keys.Control | Keys.E));
return Items.ToArray();
}

View File

@ -31,7 +31,10 @@ namespace FirstPlugin
using (var reader = new Toolbox.Library.IO.FileReader(stream, true))
{
reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
return reader.ReadUInt32() == 0x55AA382D;
uint signature = reader.ReadUInt32();
reader.Position = 0;
return signature == 0x55AA382D;
}
}
@ -64,15 +67,88 @@ namespace FirstPlugin
using (var reader = new FileReader(stream))
{
reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
uint Signature = reader.ReadUInt32();
uint FirstNodeOffset = reader.ReadUInt32();
uint NodeSectionSize = reader.ReadUInt32();
uint FileDataOffset = reader.ReadUInt32();
byte[] Reserved = new byte[4];
Console.WriteLine("FirstNodeOffset " + FirstNodeOffset);
reader.SeekBegin(FirstNodeOffset);
var RootNode = new NodeEntry();
RootNode.Read(reader);
nodes.Add(RootNode);
DirectoryEntry dirRoot = new DirectoryEntry();
dirRoot.Name = "ROOT";
dirRoot.nodeEntry = RootNode;
//Root has total number of nodes
uint TotalNodeCount = RootNode.Setting2;
List<NodeEntry> entries = new List<NodeEntry>();
entries.Add(RootNode);
for (int i = 0; i < TotalNodeCount - 1; i++)
{
var node = new NodeEntry();
node.Read(reader);
entries.Add(node);
}
var directroyEntries = entries.Where(i => i.nodeType == NodeEntry.NodeType.Directory).ToArray();
DirectoryEntry[] dirs = new DirectoryEntry[directroyEntries.Length];
for (int i = 0; i < dirs.Length; i++)
dirs[i] = new DirectoryEntry();
DirectoryEntry currentDir = dirRoot;
nodes.Add(currentDir);
for (int i = 0; i < TotalNodeCount; i++)
{
var node = entries[i];
if (node.nodeType == NodeEntry.NodeType.Directory)
{
DirectoryEntry dir = new DirectoryEntry();
dir.nodeEntry = node;
dirs[node.Setting1].AddNode(dir);
currentDir = dir;
}
else
{
FileEntry entry = new FileEntry();
entry.nodeEntry = node;
currentDir.nodes.Add(entry);
}
}
long stringPoolPos = reader.Position;
for (int i = 0; i < dirRoot.nodes.Count; i++)
{
if (dirRoot.nodes[i] is FileEntry)
{
var file = dirRoot.nodes[i] as FileEntry;
reader.SeekBegin(stringPoolPos + file.nodeEntry.StringPoolOffset);
file.FileName = reader.ReadZeroTerminatedString();
}
else
{
var dir = dirRoot.nodes[i] as DirectoryEntry;
reader.SeekBegin(stringPoolPos + dir.nodeEntry.StringPoolOffset);
dir.Name = reader.ReadZeroTerminatedString();
}
}
for (int i = 0; i < dirRoot.nodes.Count; i++)
{
if (dirRoot.nodes[i] is FileEntry)
{
var file = dirRoot.nodes[i] as FileEntry;
reader.SeekBegin(file.nodeEntry.Setting1);
file.FileData = reader.ReadBytes((int)file.nodeEntry.Setting2);
}
}
}
}
@ -85,6 +161,26 @@ namespace FirstPlugin
}
public class FileEntry : ArchiveFileInfo
{
public NodeEntry nodeEntry;
}
public class DirectoryEntry : IDirectoryContainer
{
public NodeEntry nodeEntry;
public string Name { get; set; }
public IEnumerable<INode> Nodes { get { return nodes; } }
public List<INode> nodes = new List<INode>();
public void AddNode(INode node)
{
nodes.Add(node);
}
}
public class NodeEntry : INode
{
public NodeType nodeType
@ -94,11 +190,11 @@ namespace FirstPlugin
public enum NodeType
{
Directory,
File,
Directory,
}
private uint _stringPoolOffset
public uint StringPoolOffset
{
get { return flags & 0x00ffffff; }
}

View File

@ -80,14 +80,16 @@ namespace FirstPlugin
Height = reader.ReadUInt16();
reader.ReadByte(); // wrap s
reader.ReadByte(); // wrap t
PaletteFormat = (PALETTE_FORMAT)reader.ReadInt16();
reader.ReadInt16(); // num of palette entries
reader.ReadInt32(); // offset to palette data
var paletteFormat = (Decode_Gamecube.PaletteFormats)reader.ReadByte();
var paletteEntryCount = reader.ReadInt16(); // num of palette entries
uint paletteOffset = reader.ReadUInt32(); // offset to palette data
reader.ReadInt32(); // border colour
reader.ReadByte(); // min filter type
reader.ReadByte(); // mag filter type
reader.ReadInt16();
MipCount = reader.ReadByte();
reader.ReadByte();
reader.ReadInt16();
@ -96,10 +98,15 @@ namespace FirstPlugin
//Lets set our method of decoding
PlatformSwizzle = PlatformSwizzle.Platform_Gamecube;
reader.Seek(offsetToImageData, System.IO.SeekOrigin.Begin);
reader.SeekBegin(offsetToImageData);
int imageDataSize = RoundWidth((int)Width, (int)GetBlockWidth(Format)) *
RoundHeight((int)Height, (int)GetBlockHeight(Format)) * (int)GetBytesPerPixel(Format) >> 3;
reader.SeekBegin(paletteOffset);
byte[] PaletteData = reader.ReadBytes((int)paletteEntryCount * 2);
SetPaletteData(PaletteData, Decode_Gamecube.ToGenericPaletteFormat(paletteFormat)); ;
ImageData = reader.ReadBytes(imageDataSize);
}
}