Load DKCTF MSBT chunks

This commit is contained in:
KillzXGaming 2019-08-16 18:07:03 -04:00
parent 9a943baee2
commit e3a92f9777
6 changed files with 207 additions and 0 deletions

Binary file not shown.

View file

@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using Toolbox.Library.IO;
namespace DKCTF
{
//Documentation from https://github.com/Kinnay/Nintendo-File-Formats/wiki/DKCTF-Types#cformdescriptor
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class CFormDescriptor
{
public Magic Magic = "RFRM";
public ulong DataSize;
public ulong Unknown;
public Magic FormType;
public uint VersionA;
public uint VersionB;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class CChunkDescriptor
{
public Magic ChunkType;
public ulong DataSize;
public uint Unknown;
public ulong DataOffset;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class CMayaSpline
{
public Magic ChunkType;
public ulong DataSize;
public uint Unknown;
public ulong DataOffset;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class CMayaSplineKnot
{
public float Time;
public float Value;
public ETangentType TangentType1;
public ETangentType TangentType2;
public float FieldC;
public float Field10;
public float Field14;
public float Field18;
}
public enum ETangentType
{
Linear,
Flat,
Smooth,
Step,
Clamped,
Fixed,
}
public enum EInfinityType
{
Constant,
Linear,
Cycle,
CycleRelative,
Oscillate,
}
}

View file

@ -0,0 +1,110 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using Toolbox.Library;
using Toolbox.Library.IO;
using System.Windows.Forms;
using FirstPlugin.Forms;
namespace DKCTF
{
public class MSBT : TreeNodeFile, IFileFormat
{
public FileType FileType { get; set; } = FileType.Layout;
public bool CanSave { get; set; }
public string[] Description { get; set; } = new string[] { "MSBT (DKCTF)" };
public string[] Extension { get; set; } = new string[] { "*.MSBT" };
public string FileName { get; set; }
public string FilePath { get; set; }
public IFileInfo IFileInfo { get; set; }
public bool Identify(System.IO.Stream stream)
{
if (stream.Length <= 24)
return false;
using (var reader = new Toolbox.Library.IO.FileReader(stream, true))
{
return reader.CheckSignature(4, "MSBT", 20);
}
}
public Type[] Types
{
get
{
List<Type> types = new List<Type>();
return types.ToArray();
}
}
public void Load(System.IO.Stream stream)
{
using (var reader = new Toolbox.Library.IO.FileReader(stream))
{
reader.SetByteOrder(true);
var header = reader.ReadStruct<MSBTHeader>();
//parse the data
int index = 0;
while (!reader.EndOfStream)
{
CChunkDescriptor chunk = reader.ReadStruct<CChunkDescriptor>();
long startPos = reader.Position;
reader.SeekBegin(startPos + (int)chunk.DataOffset);
byte[] chunkData = reader.ReadBytes((int)chunk.DataSize);
Nodes.Add(new MessageEntry(chunkData, index++));
}
}
}
public void Unload()
{
}
public class MessageEntry : TreeNodeCustom
{
FirstPlugin.MSBT msbt;
public MessageEntry(byte[] data, int index)
{
Text = $"Message Entry {index}";
var chunkFile = STFileLoader.OpenFileFormat(Text, data);
if (chunkFile != null && chunkFile is FirstPlugin.MSBT)
msbt = (FirstPlugin.MSBT)chunkFile;
}
public override void OnClick(TreeView treeview)
{
if (msbt != null)
{
MSBTEditor editor = (MSBTEditor)LibraryGUI.GetActiveContent(typeof(MSBTEditor));
if (editor == null)
{
editor = new MSBTEditor();
editor.Dock = DockStyle.Fill;
LibraryGUI.LoadEditor(editor);
}
editor.LoadMSBT(msbt);
}
}
}
public void Save(System.IO.Stream stream)
{
}
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class MSBTHeader
{
CFormDescriptor PackForm;
}
}

View file

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace DKCTF
{
public class PAK
{
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class PakHeader
{
CFormDescriptor PackForm;
}
}

View file

@ -208,6 +208,9 @@
<Compile Include="FileFormats\Archives\ARC.cs" />
<Compile Include="FileFormats\Archives\GFA.cs" />
<Compile Include="FileFormats\Archives\LM2\LM2_Material.cs" />
<Compile Include="FileFormats\DKCTF\Common.cs" />
<Compile Include="FileFormats\DKCTF\MSBT.cs" />
<Compile Include="FileFormats\DKCTF\PAK.cs" />
<Compile Include="FileFormats\HedgehogEngine\HeaderCommon.cs" />
<Compile Include="FileFormats\HedgehogEngine\HedgeModel.cs" />
<Compile Include="FileFormats\HedgehogEngine\PACx.cs" />

View file

@ -376,6 +376,7 @@ namespace FirstPlugin
Formats.Add(typeof(NCCH));
Formats.Add(typeof(NCSD));
Formats.Add(typeof(CTR.NCCH.RomFS));
Formats.Add(typeof(DKCTF.MSBT));
//Unfinished wip formats not ready for use
if (Runtime.DEVELOPER_DEBUG_MODE)