BRLYT & BRLAN : Support little endian.

This commit is contained in:
KillzXGaming 2020-09-18 17:34:05 -04:00
parent 2f6605761a
commit 426e7440a6
2 changed files with 21 additions and 9 deletions

View file

@ -26,7 +26,8 @@ namespace LayoutBXLYT
{
using (var reader = new Toolbox.Library.IO.FileReader(stream, true))
{
return reader.CheckSignature(4, "RLAN");
return reader.CheckSignature(4, "RLAN") ||
reader.CheckSignature(4, "NALR");
}
}
@ -102,7 +103,7 @@ namespace LayoutBXLYT
public class Header : BxlanHeader
{
private const string Magic = "RLAN";
private string Magic = "RLAN";
private ushort ByteOrderMark;
private ushort HeaderSize;
@ -115,7 +116,10 @@ namespace LayoutBXLYT
AnimationInfo = new PAI1();
reader.SetByteOrder(true);
reader.ReadSignature(4, Magic);
Magic = reader.ReadSignature(4);
if (Magic == "NALR")
reader.ReverseMagic = true;
ByteOrderMark = reader.ReadUInt16();
reader.CheckByteOrderMark(ByteOrderMark);
Version = reader.ReadUInt16();
@ -131,7 +135,7 @@ namespace LayoutBXLYT
for (int i = 0; i < sectionCount; i++)
{
long pos = reader.Position;
string Signature = reader.ReadString(4, Encoding.ASCII);
string Signature = reader.ReadSignature(4);
uint SectionSize = reader.ReadUInt32();
SectionCommon section = new SectionCommon(Signature);
@ -382,7 +386,7 @@ namespace LayoutBXLYT
Unknown = reader.ReadUInt32(); //This doesn't seem to be included in the offsets to the entries (?)
long startPos = reader.Position;
Tag = reader.ReadString(4, Encoding.ASCII);
Tag = reader.ReadSignature(4);
var numEntries = reader.ReadByte();
reader.Seek(3);
var offsets = reader.ReadUInt32s((int)numEntries);

View file

@ -31,7 +31,8 @@ namespace LayoutBXLYT
{
using (var reader = new Toolbox.Library.IO.FileReader(stream, true))
{
return reader.CheckSignature(4, "RLYT");
return reader.CheckSignature(4, "RLYT") ||
reader.CheckSignature(4, "TYLR");
}
}
@ -100,10 +101,13 @@ namespace LayoutBXLYT
public Dictionary<string, STGenericTexture> GetTextures()
{
Dictionary<string, STGenericTexture> textures = new Dictionary<string, STGenericTexture>();
Console.WriteLine($"GetTextures {IFileInfo.ArchiveParent != null}");
if (IFileInfo.ArchiveParent != null)
{
foreach (var file in IFileInfo.ArchiveParent.Files)
{
Console.WriteLine($"GetTextures {file.FileName}");
try
{
if (Utils.GetExtension(file.FileName) == ".tpl")
@ -141,7 +145,7 @@ namespace LayoutBXLYT
//https://github.com/FuryBaguette/SwitchLayoutEditor/tree/master/SwitchThemesCommon
public class Header : BxlytHeader, IDisposable
{
private const string Magic = "RLYT";
private string Magic = "RLYT";
private ushort ByteOrderMark;
private ushort HeaderSize;
@ -329,7 +333,9 @@ namespace LayoutBXLYT
FileInfo = brlyt;
reader.SetByteOrder(true);
reader.ReadSignature(4, Magic);
Magic = reader.ReadSignature(4);
if (Magic == "TYLR")
reader.ReverseMagic = true;
ByteOrderMark = reader.ReadUInt16();
reader.CheckByteOrderMark(ByteOrderMark);
Version = reader.ReadUInt16();
@ -355,7 +361,7 @@ namespace LayoutBXLYT
{
long pos = reader.Position;
string Signature = reader.ReadString(4, Encoding.ASCII);
string Signature = reader.ReadSignature(4);
uint SectionSize = reader.ReadUInt32();
SectionCommon section = new SectionCommon(Signature);
@ -470,6 +476,8 @@ namespace LayoutBXLYT
{
writer.SetByteOrder(IsBigEndian);
writer.WriteSignature(Magic);
if (Magic == "TYLR")
writer.ReverseMagic = true;
writer.Write(ByteOrderMark);
writer.Write((ushort)Version);
writer.Write(uint.MaxValue); //Reserve space for file size later