mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2025-02-16 22:08:26 +00:00
Add IContextMenuContainers to IArchives
This commit is contained in:
parent
de13d285b1
commit
ff9c598d99
4 changed files with 83 additions and 19 deletions
Binary file not shown.
|
@ -11,7 +11,7 @@ using Toolbox.Library.Forms;
|
|||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
public class SARC : IArchiveFile, IFileFormat
|
||||
public class SARC : IArchiveFile, IFileFormat, IContextMenuNode
|
||||
{
|
||||
public FileType FileType { get; set; } = FileType.Archive;
|
||||
|
||||
|
@ -83,6 +83,13 @@ namespace FirstPlugin
|
|||
return true;
|
||||
}
|
||||
|
||||
public ToolStripItem[] GetContextMenuItems()
|
||||
{
|
||||
List<ToolStripItem> Items = new List<ToolStripItem>();
|
||||
Items.Add(new ToolStripMenuItem("Rename Actor Files (Odyssey)", null, RenameActors, Keys.Control | Keys.R));
|
||||
return Items.ToArray();
|
||||
}
|
||||
|
||||
private void RenameActors(object sender, EventArgs args)
|
||||
{
|
||||
string ActorName = Path.GetFileNameWithoutExtension(FileName);
|
||||
|
|
|
@ -146,9 +146,19 @@ namespace FirstPlugin
|
|||
public uint Version { get; set; }
|
||||
|
||||
public FINF FontSection { get; set; }
|
||||
public FontKerningTable KerningTable { get; set; }
|
||||
|
||||
public List<BFFNT_Block> Blocks = new List<BFFNT_Block>();
|
||||
|
||||
public PlatformType Platform { get; set; } = PlatformType.Cafe;
|
||||
|
||||
public enum PlatformType
|
||||
{
|
||||
Cafe,
|
||||
NX,
|
||||
Ctr
|
||||
}
|
||||
|
||||
public void Read(FileReader reader)
|
||||
{
|
||||
reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
|
||||
|
@ -165,6 +175,17 @@ namespace FirstPlugin
|
|||
ushort BlockCount = reader.ReadUInt16();
|
||||
ushort Padding = reader.ReadUInt16();
|
||||
|
||||
if (reader.ByteOrder == Syroot.BinaryData.ByteOrder.LittleEndian)
|
||||
{
|
||||
if (Version > 0x3000000 || Version > 0x00000103)
|
||||
Platform = PlatformType.NX;
|
||||
else
|
||||
Platform = PlatformType.Ctr;
|
||||
}
|
||||
else
|
||||
Platform = PlatformType.Cafe;
|
||||
|
||||
|
||||
reader.Seek(HeaderSize, SeekOrigin.Begin);
|
||||
FontSection = new FINF();
|
||||
FontSection.Read(reader, this);
|
||||
|
@ -187,7 +208,9 @@ namespace FirstPlugin
|
|||
case "TGLP":
|
||||
case "FINF":
|
||||
break;
|
||||
case "KRNG": //What the HECK is this section
|
||||
case "KRNG":
|
||||
KerningTable = new FontKerningTable();
|
||||
KerningTable.Read(reader, this);
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Unknown block found! " + BlockSignature);
|
||||
|
@ -226,11 +249,34 @@ namespace FirstPlugin
|
|||
}
|
||||
}
|
||||
|
||||
public class KRNG
|
||||
//Kerning Table
|
||||
//https://github.com/dnasdw/3dsfont/blob/4ead538d225d5d05929dce9d736bec91a6158052/src/bffnt/ResourceFormat.h
|
||||
public class FontKerningTable
|
||||
{
|
||||
public void Read(FileReader reader)
|
||||
{
|
||||
public KerningFirstTable FirstTable { get; set; }
|
||||
|
||||
public void Read(FileReader reader, FFNT Header)
|
||||
{
|
||||
if (Header.Platform == FFNT.PlatformType.NX)
|
||||
{
|
||||
ushort FirstWordCount = reader.ReadUInt16();
|
||||
ushort padding = reader.ReadUInt16();
|
||||
|
||||
FirstTable = new KerningFirstTable();
|
||||
FirstTable.Read(reader, Header);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class KerningFirstTable
|
||||
{
|
||||
public void Read(FileReader reader, FFNT Header)
|
||||
{
|
||||
if (Header.Platform == FFNT.PlatformType.NX)
|
||||
{
|
||||
uint FirstWordCount = reader.ReadUInt16();
|
||||
uint Offset = reader.ReadUInt16();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -711,7 +757,7 @@ namespace FirstPlugin
|
|||
|
||||
reader.ReadSignature(4, "CMAP");
|
||||
SectionSize = reader.ReadUInt32();
|
||||
if (header.Version > 0x3000000 || header.Version > 0x00000103)
|
||||
if (header.Platform == FFNT.PlatformType.NX)
|
||||
{
|
||||
CodeBegin = reader.ReadUInt32();
|
||||
CodeEnd = reader.ReadUInt32();
|
||||
|
@ -752,16 +798,19 @@ namespace FirstPlugin
|
|||
break;
|
||||
case Mapping.Scan:
|
||||
var CharEntryCount = reader.ReadUInt16();
|
||||
|
||||
if (header.Platform == FFNT.PlatformType.NX)
|
||||
reader.ReadUInt16(); //Padding
|
||||
|
||||
for (int i = 0; i < CharEntryCount; i++)
|
||||
{
|
||||
if (header.Version > 0x3000000 || header.Version > 0x00000103)
|
||||
if (header.Platform == FFNT.PlatformType.NX)
|
||||
{
|
||||
//Seems to have a spacing of a ushort for each entry
|
||||
char charCode = reader.ReadChar();
|
||||
short padding = reader.ReadInt16();
|
||||
uint charCode = reader.ReadUInt16();
|
||||
short index = reader.ReadInt16();
|
||||
short padding2 = reader.ReadInt16();
|
||||
if (index != -1) header.FontSection.CodeMapDictionary[charCode] = index;
|
||||
short padding = reader.ReadInt16();
|
||||
if (index != -1) header.FontSection.CodeMapDictionary[(char)charCode] = index;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -191,15 +191,23 @@ namespace Toolbox.Library
|
|||
|
||||
public ToolStripItem[] GetContextMenuItems()
|
||||
{
|
||||
return new ToolStripItem[]
|
||||
{
|
||||
new STToolStripItem("Save", SaveAction) { Enabled = ((IFileFormat)ArchiveFile).CanSave},
|
||||
new STToolStripSeparator(),
|
||||
new STToolStripItem("Repack", RepackAction){ Enabled = ArchiveFile.CanReplaceFiles},
|
||||
new STToolStripItem("Extract All", ExtractAllAction),
|
||||
new STToolStripSeparator(),
|
||||
new STToolStripItem("Preview Archive", PreviewAction),
|
||||
var ToolStrips = new ToolStripItem[]
|
||||
{
|
||||
new STToolStripItem("Save", SaveAction) { Enabled = ((IFileFormat)ArchiveFile).CanSave},
|
||||
new STToolStripSeparator(),
|
||||
new STToolStripItem("Repack", RepackAction){ Enabled = ArchiveFile.CanReplaceFiles},
|
||||
new STToolStripItem("Extract All", ExtractAllAction),
|
||||
new STToolStripSeparator(),
|
||||
new STToolStripItem("Preview Archive", PreviewAction),
|
||||
};
|
||||
|
||||
var toolStripList = ToolStrips.ToList();
|
||||
if (ArchiveFile is IContextMenuNode)
|
||||
{
|
||||
toolStripList.AddRange(((IContextMenuNode)ArchiveFile).GetContextMenuItems());
|
||||
}
|
||||
|
||||
return toolStripList.ToArray();
|
||||
}
|
||||
|
||||
private void EnableContextMenu(ToolStripItemCollection Items, string Key, bool Enabled)
|
||||
|
|
Loading…
Add table
Reference in a new issue