BRFNT: Add support for little endian.
This commit is contained in:
parent
1d77d99968
commit
9a0f6ebddd
@ -32,7 +32,8 @@ namespace FirstPlugin
|
|||||||
{
|
{
|
||||||
return reader.CheckSignature(4, "FFNT") ||
|
return reader.CheckSignature(4, "FFNT") ||
|
||||||
reader.CheckSignature(4, "CFNT") ||
|
reader.CheckSignature(4, "CFNT") ||
|
||||||
reader.CheckSignature(4, "RFNT");
|
reader.CheckSignature(4, "RFNT") ||
|
||||||
|
reader.CheckSignature(4, "TNFR");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,6 +211,8 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
public PlatformType Platform { get; set; } = PlatformType.Cafe;
|
public PlatformType Platform { get; set; } = PlatformType.Cafe;
|
||||||
|
|
||||||
|
public bool IsWiiLE => Signature == "TNFR";
|
||||||
|
|
||||||
public enum PlatformType
|
public enum PlatformType
|
||||||
{
|
{
|
||||||
Wii,
|
Wii,
|
||||||
@ -223,15 +226,18 @@ namespace FirstPlugin
|
|||||||
reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
|
reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
|
||||||
|
|
||||||
Signature = reader.ReadString(4, Encoding.ASCII);
|
Signature = reader.ReadString(4, Encoding.ASCII);
|
||||||
if (Signature != "FFNT" && Signature != "CFNT" && Signature != "RFNT")
|
if (Signature != "FFNT" && Signature != "CFNT" && Signature != "RFNT" && Signature != "TNFR")
|
||||||
throw new Exception($"Invalid signature {Signature}! Expected FFNT or CFNT or RFNT.");
|
throw new Exception($"Invalid signature {Signature}! Expected FFNT or CFNT or RFNT.");
|
||||||
|
|
||||||
BOM = reader.ReadUInt16();
|
BOM = reader.ReadUInt16();
|
||||||
reader.CheckByteOrderMark(BOM);
|
reader.CheckByteOrderMark(BOM);
|
||||||
|
|
||||||
|
if (Signature == "TNFR")
|
||||||
|
reader.ReverseMagic = true;
|
||||||
|
|
||||||
//Parse header first and check the version
|
//Parse header first and check the version
|
||||||
//Brfnt uses a slightly different header structure
|
//Brfnt uses a slightly different header structure
|
||||||
if (Signature == "RFNT") {
|
if (Signature == "RFNT" || Signature == "TNFR") {
|
||||||
Version = reader.ReadUInt16();
|
Version = reader.ReadUInt16();
|
||||||
uint FileSize = reader.ReadUInt32();
|
uint FileSize = reader.ReadUInt32();
|
||||||
HeaderSize = reader.ReadUInt16();
|
HeaderSize = reader.ReadUInt16();
|
||||||
@ -259,7 +265,7 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
if (Signature == "CFNT")
|
if (Signature == "CFNT")
|
||||||
Platform = PlatformType.Ctr;
|
Platform = PlatformType.Ctr;
|
||||||
if (Signature == "RFNT")
|
if (Signature == "RFNT" || Signature == "TNFR")
|
||||||
Platform = PlatformType.Wii;
|
Platform = PlatformType.Wii;
|
||||||
|
|
||||||
Console.WriteLine($"Platform {Platform}");
|
Console.WriteLine($"Platform {Platform}");
|
||||||
@ -274,7 +280,7 @@ namespace FirstPlugin
|
|||||||
{
|
{
|
||||||
long BlockStart = reader.Position;
|
long BlockStart = reader.Position;
|
||||||
|
|
||||||
string BlockSignature = reader.ReadString(4, Encoding.ASCII);
|
string BlockSignature = reader.ReadSignature(4);
|
||||||
uint BlockSize = reader.ReadUInt32();
|
uint BlockSize = reader.ReadUInt32();
|
||||||
|
|
||||||
switch (BlockSignature)
|
switch (BlockSignature)
|
||||||
@ -314,6 +320,9 @@ namespace FirstPlugin
|
|||||||
writer.Write(BOM);
|
writer.Write(BOM);
|
||||||
writer.CheckByteOrderMark(BOM);
|
writer.CheckByteOrderMark(BOM);
|
||||||
|
|
||||||
|
if (Signature == "TNFR")
|
||||||
|
writer.ReverseMagic = true;
|
||||||
|
|
||||||
long _ofsFileSize;
|
long _ofsFileSize;
|
||||||
long _ofsBlockNum;
|
long _ofsBlockNum;
|
||||||
if (Platform == PlatformType.Wii)
|
if (Platform == PlatformType.Wii)
|
||||||
|
@ -50,7 +50,7 @@ namespace FirstPlugin
|
|||||||
CharacterWidths = new List<CWDH>();
|
CharacterWidths = new List<CWDH>();
|
||||||
CodeMaps = new List<CMAP>();
|
CodeMaps = new List<CMAP>();
|
||||||
|
|
||||||
string Signature = reader.ReadString(4, Encoding.ASCII);
|
string Signature = reader.ReadSignature(4);
|
||||||
if (Signature != "FINF")
|
if (Signature != "FINF")
|
||||||
throw new Exception($"Invalid signature {Signature}! Expected FINF.");
|
throw new Exception($"Invalid signature {Signature}! Expected FINF.");
|
||||||
Size = reader.ReadUInt32();
|
Size = reader.ReadUInt32();
|
||||||
@ -94,7 +94,6 @@ namespace FirstPlugin
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
Type = reader.ReadEnum<FontType>(true);
|
Type = reader.ReadEnum<FontType>(true);
|
||||||
Height = reader.ReadByte();
|
Height = reader.ReadByte();
|
||||||
Width = reader.ReadByte();
|
Width = reader.ReadByte();
|
||||||
|
@ -44,9 +44,7 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
public void Read(FileReader reader, FFNT header)
|
public void Read(FileReader reader, FFNT header)
|
||||||
{
|
{
|
||||||
string Signature = reader.ReadString(4, Encoding.ASCII);
|
string Signature = reader.ReadSignature(4, "TGLP");
|
||||||
if (Signature != "TGLP")
|
|
||||||
throw new Exception($"Invalid signature {Signature}! Expected TGLP.");
|
|
||||||
SectionSize = reader.ReadUInt32();
|
SectionSize = reader.ReadUInt32();
|
||||||
CellWidth = reader.ReadByte();
|
CellWidth = reader.ReadByte();
|
||||||
CellHeight = reader.ReadByte();
|
CellHeight = reader.ReadByte();
|
||||||
|
@ -13,6 +13,8 @@ namespace Toolbox.Library.IO
|
|||||||
{
|
{
|
||||||
public class FileReader : BinaryDataReader
|
public class FileReader : BinaryDataReader
|
||||||
{
|
{
|
||||||
|
public bool ReverseMagic { get; set; } = false;
|
||||||
|
|
||||||
public FileReader(Stream stream, bool leaveOpen = false)
|
public FileReader(Stream stream, bool leaveOpen = false)
|
||||||
: base(stream, Encoding.ASCII, leaveOpen)
|
: base(stream, Encoding.ASCII, leaveOpen)
|
||||||
{
|
{
|
||||||
@ -193,9 +195,20 @@ namespace Toolbox.Library.IO
|
|||||||
ByteOrder = ByteOrder.LittleEndian;
|
ByteOrder = ByteOrder.LittleEndian;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string ReadSignature(int length)
|
||||||
|
{
|
||||||
|
string RealSignature = ReadString(length, Encoding.ASCII);
|
||||||
|
if (ReverseMagic)
|
||||||
|
return new string(RealSignature.Reverse().ToArray());
|
||||||
|
else
|
||||||
|
return RealSignature;
|
||||||
|
}
|
||||||
|
|
||||||
public string ReadSignature(int length, string ExpectedSignature, bool TrimEnd = false)
|
public string ReadSignature(int length, string ExpectedSignature, bool TrimEnd = false)
|
||||||
{
|
{
|
||||||
string RealSignature = ReadString(length, Encoding.ASCII);
|
string RealSignature = ReadString(length, Encoding.ASCII);
|
||||||
|
if (ReverseMagic)
|
||||||
|
RealSignature = new string(RealSignature.Reverse().ToArray());
|
||||||
|
|
||||||
if (TrimEnd) RealSignature = RealSignature.TrimEnd(' ');
|
if (TrimEnd) RealSignature = RealSignature.TrimEnd(' ');
|
||||||
|
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
using Syroot.BinaryData;
|
using Syroot.BinaryData;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Toolbox.Library.IO
|
namespace Toolbox.Library.IO
|
||||||
{
|
{
|
||||||
public class FileWriter : BinaryDataWriter
|
public class FileWriter : BinaryDataWriter
|
||||||
{
|
{
|
||||||
|
public bool ReverseMagic { get; set; } = false;
|
||||||
|
|
||||||
public void CheckByteOrderMark(uint ByteOrderMark)
|
public void CheckByteOrderMark(uint ByteOrderMark)
|
||||||
{
|
{
|
||||||
if (ByteOrderMark == 0xFEFF)
|
if (ByteOrderMark == 0xFEFF)
|
||||||
@ -85,7 +88,10 @@ namespace Toolbox.Library.IO
|
|||||||
|
|
||||||
public void WriteSignature(string value)
|
public void WriteSignature(string value)
|
||||||
{
|
{
|
||||||
Write(Encoding.ASCII.GetBytes(value));
|
if (ReverseMagic)
|
||||||
|
Write(Encoding.ASCII.GetBytes(new string(value.Reverse().ToArray())));
|
||||||
|
else
|
||||||
|
Write(Encoding.ASCII.GetBytes(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteString(string value, Encoding encoding = null)
|
public void WriteString(string value, Encoding encoding = null)
|
||||||
|
Loading…
Reference in New Issue
Block a user