1
0
mirror of synced 2024-09-24 11:38:22 +02:00

Fix multiple ptcl issues with rebuilding. Add some GCN formats

This commit is contained in:
KillzXGaming 2019-07-10 20:38:35 -04:00
parent 39998157a4
commit e5b0b71eaa
12 changed files with 292 additions and 10 deletions

Binary file not shown.

View File

@ -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<SectionBase> ChildSections = new List<SectionBase>();
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<BinarySavedEntry> BinariesSaved = new List<BinarySavedEntry>();
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)

View File

@ -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<Type> types = new List<Type>();
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<FileEntry> files = new List<FileEntry>();
public IEnumerable<ArchiveFileInfo> 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<FileEntry> 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<FSTEntry> Entires = new List<FSTEntry>();
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<FSTEntry> 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;
}
}
}
}

View File

@ -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)

View File

@ -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)

View File

@ -245,6 +245,7 @@
<Compile Include="FileFormats\Font\BFFNT.cs" />
<Compile Include="FileFormats\Audio\Archives\BFGRP.cs" />
<Compile Include="FileFormats\Gamecube\TPL.cs" />
<Compile Include="FileFormats\Rom\GCDisk.cs" />
<Compile Include="libWiiSharp\TPL.cs" />
<Compile Include="FileFormats\GFBMDL\GFBMDL.cs" />
<Compile Include="FileFormats\GFBMDL\GFBMDL_Wrappers.cs" />

View File

@ -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)