diff --git a/.vs/Switch_Toolbox/v15/.suo b/.vs/Switch_Toolbox/v15/.suo index 1f61e12b..5b2619c5 100644 Binary files a/.vs/Switch_Toolbox/v15/.suo and b/.vs/Switch_Toolbox/v15/.suo differ diff --git a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide index 509be690..ad8ed8fe 100644 Binary files a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide and b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide differ diff --git a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-shm b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-shm index 4649e6a1..64ff5bb0 100644 Binary files a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-shm and b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-shm differ diff --git a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal index 207e5f9d..a5a6c498 100644 Binary files a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal and b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal differ diff --git a/Switch_FileFormatsMain/FileFormats/Effects/PCTL.cs b/Switch_FileFormatsMain/FileFormats/Effects/PCTL.cs index 9bcd4d8d..f0a41d53 100644 --- a/Switch_FileFormatsMain/FileFormats/Effects/PCTL.cs +++ b/Switch_FileFormatsMain/FileFormats/Effects/PCTL.cs @@ -395,7 +395,27 @@ namespace FirstPlugin public uint SubSectionCount; public object BinaryData; - public byte[] BinaryDataBytes; + + private byte[] binaryDataBytes; + public byte[] BinaryDataBytes + { + get + { + /* if (BinaryData == null) + return binaryDataBytes; + else if (BinaryData is BFRES) + return (((BFRES)BinaryData).Save()); + else if (BinaryData is BNTX) + return (((BNTX)BinaryData).Save()); + else*/ + + return binaryDataBytes; + } + set + { + binaryDataBytes = value; + } + } public List ChildSections = new List(); public byte[] data; @@ -620,12 +640,15 @@ namespace FirstPlugin SaveHeader(writer, header, BinaryDataBytes, 4096); break; case "G3PR": - SaveHeader(writer, header, ((BFRES)BinaryData).Save(), 4096); - // SaveHeader(writer, header, BinaryDataBytes, 4096); + // SaveHeader(writer, header, ((BFRES)BinaryData).Save(), 4096); + SaveHeader(writer, header, BinaryDataBytes, 4096); break; case "GRTF": SaveHeader(writer, header, ((BNTX)BinaryData).Save(), 4096); - // SaveHeader(writer, header, BinaryDataBytes, 4096); + // SaveHeader(writer, header, BinaryDataBytes, 4096); + break; + case "PRIM": + SaveHeader(writer, header, BinaryDataBytes); break; case "EMTR": //Write all the data first @@ -669,8 +692,11 @@ namespace FirstPlugin public List BinariesSaved = new List(); - private void SaveHeader(FileWriter writer,Header header, byte[] BinaryFile, int BinaryAlignment) + private void SaveHeader(FileWriter writer,Header header, byte[] BinaryFile, int BinaryAlignment = 0) { + if (Signature != "PRIM") + writer.Align(16); + if (BinaryFile != null && BinaryFile.Length > 0) SectionSize = (uint)BinaryFile.Length; @@ -714,7 +740,8 @@ namespace FirstPlugin { if (BinaryFile != null && BinaryFile.Length > 0) { - writer.Align(BinaryAlignment); //Align the file + if (BinaryAlignment != 0) + writer.Align(BinaryAlignment); //Align the file Console.WriteLine($"{Signature} DATA BLOCK " + writer.Position + " " + BinaryFile.Length); writer.WriteUint32Offset(_ofsBinaryPos, BasePosition); //Save binary offset @@ -729,7 +756,9 @@ namespace FirstPlugin writer.WriteUint32Offset(binary._ofsData, binary.Position); //Save binary offset writer.Write(binary.Data); //Save binary data } + BinariesSaved.Clear(); + } if (NextSectionOffset != NullOffset) diff --git a/Switch_FileFormatsMain/FileFormats/Rom/GCDisk.cs b/Switch_FileFormatsMain/FileFormats/Rom/GCDisk.cs new file mode 100644 index 00000000..b4a7202b --- /dev/null +++ b/Switch_FileFormatsMain/FileFormats/Rom/GCDisk.cs @@ -0,0 +1,242 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Switch_Toolbox.Library; +using LibHac.IO; +using Switch_Toolbox.Library.IO; +using LibHac; + +namespace FirstPlugin +{ + public class GCDisk : IArchiveFile, IFileFormat + { + public FileType FileType { get; set; } = FileType.Rom; + + public bool CanSave { get; set; } + public string[] Description { get; set; } = new string[] { "Gamecube ISO" }; + public string[] Extension { get; set; } = new string[] { "*.iso" }; + public string FileName { get; set; } + public string FilePath { get; set; } + public IFileInfo IFileInfo { get; set; } + + public Type[] Types + { + get + { + List types = new List(); + return types.ToArray(); + } + } + + public bool CanAddFiles { get; set; } + public bool CanRenameFiles { get; set; } + public bool CanReplaceFiles { get; set; } + public bool CanDeleteFiles { get; set; } + + public List files = new List(); + public IEnumerable Files => files; + + public bool Identify(System.IO.Stream stream) + { + using (var reader = new FileReader(stream, true)) + { + return reader.CheckSignature(1033843650, 28); + } + } + + public DiskHeader Header; + + public void Load(System.IO.Stream stream) + { + using (var reader = new FileReader(stream)) + { + Header = new DiskHeader(); + Header.Read(reader, this); + } + } + + public class DiskHeader + { + public char[] GameCode { get; set; } + + public byte DiskID { get; set; } + public byte Version { get; set; } + public bool AudioStreaming { get; set; } + public byte StreamBufferSize { get; set; } + + public char[] GameName { get; set; } + + public FileSystemTable FileTable; + + public void Read(FileReader reader, GCDisk disk) + { + reader.SetByteOrder(true); + + GameCode = reader.ReadChars(6); + DiskID = reader.ReadByte(); + Version = reader.ReadByte(); + AudioStreaming = reader.ReadBoolean(); + StreamBufferSize = reader.ReadByte(); + byte[] Padding = reader.ReadBytes(0x12); + uint DvdMagic = reader.ReadUInt32(); + GameName = reader.ReadChars(0x3e0); + uint DebugMonitorOffset = reader.ReadUInt32(); + uint DebugLoadAddress = reader.ReadUInt32(); + byte[] Padding2 = reader.ReadBytes(0x18); + uint DolOffset = reader.ReadUInt32(); + uint FstOffset = reader.ReadUInt32(); + uint FstSize = reader.ReadUInt32(); + uint FstMaxSize = reader.ReadUInt32(); + uint userPos = reader.ReadUInt32(); + uint userLength = reader.ReadUInt32(); + uint unknown = reader.ReadUInt32(); + uint padding = reader.ReadUInt32(); + + reader.SeekBegin(FstOffset); + FileTable = new FileSystemTable(); + FileTable.Read(reader, disk.files, disk.FilePath); + } + } + + public class FileSystemTable + { + public void Read(FileReader reader, List Files, string FileName) + { + long pos = reader.Position; + + FSTEntry root = new FSTEntry(FileName); + root.NameOffset = reader.ReadUInt32(); + root.Offset = reader.ReadUInt32(); + root.Size = reader.ReadUInt32(); + + List Entires = new List(); + + uint stringTableOffset = (uint)pos; + for (int i = 0; i < root.Size; i++) + { + uint offset = (uint)(pos + (i * 0xC)); + reader.BaseStream.Position = offset; + + FSTEntry entry = new FSTEntry(FileName); + entry.NameOffset = reader.ReadUInt32(); + entry.Offset = reader.ReadUInt32(); + entry.Size = reader.ReadUInt32(); + Entires.Add(entry); + + stringTableOffset += 0x0C; + } + + SetFileNames(reader, Entires, 1, Entires.Count, "", stringTableOffset); + + for (int i = 0; i < Entires.Count - 1; i++) + { + + if (!Entires[i].IsDirectory) + { + var fileEntry = new FileEntry(Entires[i]); + fileEntry.FileName = Entires[i].FullPath; + Files.Add(fileEntry); + } + } + } + + //Based on https://github.com/lioncash/GameFormatReader/blob/master/GameFormatReader/GCWii/Discs/GC/FST.cs#L72 + private int SetFileNames(FileReader reader, List fileEntries, int firstIndex, int lastIndex, string directory, uint stringTableOffset) + { + int currentIndex = firstIndex; + while (currentIndex < lastIndex) + { + FSTEntry entry = fileEntries[currentIndex]; + uint tableOffset = stringTableOffset + (entry.NameOffset & 0xFFFFFF); + reader.BaseStream.Position = tableOffset; + + string filename = reader.ReadZeroTerminatedString(); + entry.FullPath = directory + filename; + + if (entry.IsDirectory) + { + entry.FullPath += "/"; + currentIndex = SetFileNames(reader, fileEntries, currentIndex + 1, (int)entry.Size, entry.FullPath, stringTableOffset); + } + else + { + ++currentIndex; + } + } + + return currentIndex; + } + } + + + + public void Unload() + { + + } + public byte[] Save() + { + return null; + } + + public bool AddFile(ArchiveFileInfo archiveFileInfo) + { + return false; + } + + public bool DeleteFile(ArchiveFileInfo archiveFileInfo) + { + return false; + } + + public class FileEntry : ArchiveFileInfo + { + FSTEntry FstEntry; + + public FileEntry(FSTEntry entry) + { + FstEntry = entry; + } + + public override byte[] FileData + { + get + { + GC.Collect(); //Memory fills up so fill any previous file data + + using (var reader = new FileReader(FstEntry.SourceFile)) + { + return reader.getSection((int)FstEntry.Offset, (int)FstEntry.Size); + } + } + set + { + + } + } + } + + public class FSTEntry + { + public bool IsDirectory + { + get { return (NameOffset & 0xFF000000) != 0; } + } + + public string SourceFile { get; set; } + + public uint NameOffset { get; set; } + public uint Offset { get; set; } + public uint Size { get; set; } + + public string FullPath { get; set; } + + public FSTEntry(string sourceFile) + { + SourceFile = sourceFile; + } + } + } +} diff --git a/Switch_FileFormatsMain/GUI/BFRES/TexturePattern/BfresTexturePatternEditor.cs b/Switch_FileFormatsMain/GUI/BFRES/TexturePattern/BfresTexturePatternEditor.cs index fd9d38a5..fa48904a 100644 --- a/Switch_FileFormatsMain/GUI/BFRES/TexturePattern/BfresTexturePatternEditor.cs +++ b/Switch_FileFormatsMain/GUI/BFRES/TexturePattern/BfresTexturePatternEditor.cs @@ -558,11 +558,16 @@ namespace FirstPlugin.Forms { if (listViewCustom1.SelectedItems.Count > 0 && KeyFrames.Count > 0) { - int SelectedFrame = KeyFrames[listViewCustom1.SelectedIndices[0]]; + int Index = listViewCustom1.SelectedIndices[0]; + int SelectedFrame = KeyFrames[Index]; + var ListItem = listViewCustom1.SelectedItems[Index]; + + } } + private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { if (ActiveMaterialAnim == null || !IsLoaded) diff --git a/Switch_FileFormatsMain/Main.cs b/Switch_FileFormatsMain/Main.cs index 0975b0a0..e67ece80 100644 --- a/Switch_FileFormatsMain/Main.cs +++ b/Switch_FileFormatsMain/Main.cs @@ -336,8 +336,9 @@ namespace FirstPlugin Formats.Add(typeof(ME01)); Formats.Add(typeof(LM2_DICT)); Formats.Add(typeof(GMX)); - // Formats.Add(typeof(TPL)); - //Formats.Add(typeof(GFA)); + // Formats.Add(typeof(GCDisk)); + // Formats.Add(typeof(TPL)); + // Formats.Add(typeof(GFA)); //Unfinished wip formats not ready for use if (Runtime.DEVELOPER_DEBUG_MODE) diff --git a/Switch_FileFormatsMain/Switch_FileFormatsMain.csproj b/Switch_FileFormatsMain/Switch_FileFormatsMain.csproj index 49527f4a..6eb72859 100644 --- a/Switch_FileFormatsMain/Switch_FileFormatsMain.csproj +++ b/Switch_FileFormatsMain/Switch_FileFormatsMain.csproj @@ -245,6 +245,7 @@ + diff --git a/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache b/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache index ac730309..e5ceb8d4 100644 Binary files a/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache and b/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache differ diff --git a/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache b/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache index 7eb33ab5..bd838ca3 100644 Binary files a/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache and b/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache differ diff --git a/Switch_Toolbox_Library/Interfaces/IArchiveFile.cs b/Switch_Toolbox_Library/Interfaces/IArchiveFile.cs index 07d91ce0..0e38ffa8 100644 --- a/Switch_Toolbox_Library/Interfaces/IArchiveFile.cs +++ b/Switch_Toolbox_Library/Interfaces/IArchiveFile.cs @@ -245,7 +245,11 @@ namespace Switch_Toolbox.Library private void RepackAction(object sender, EventArgs args) { - + FolderSelectDialog dlg = new FolderSelectDialog(); + if (dlg.ShowDialog() == DialogResult.OK) + { + string FolderPath = dlg.SelectedPath; + } } private void PreviewAction(object sender, EventArgs args)