mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-22 20:43:09 +00:00
Add bflyt file settings (endianness and version edits)
This commit is contained in:
parent
d5b9de852d
commit
fce999e1fb
10 changed files with 264 additions and 30 deletions
|
@ -109,7 +109,6 @@ namespace FirstPlugin
|
|||
public void Load(Stream stream)
|
||||
{
|
||||
stream = CheckCompression(stream);
|
||||
stream.ExportToFile(FilePath + ".dec");
|
||||
|
||||
using (var reader = new FileReader(stream))
|
||||
{
|
||||
|
|
|
@ -73,7 +73,7 @@ namespace LayoutBXLYT.Cafe
|
|||
|
||||
#region Text Converter Interface
|
||||
public TextFileType TextFileType => TextFileType.Xml;
|
||||
public bool CanConvertBack => false;
|
||||
public bool CanConvertBack => true;
|
||||
|
||||
public string ConvertToString()
|
||||
{
|
||||
|
@ -95,6 +95,8 @@ namespace LayoutBXLYT.Cafe
|
|||
|
||||
public void ConvertFromString(string text)
|
||||
{
|
||||
header = FLYT.FromXml(text);
|
||||
header.FileInfo = this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -228,19 +230,24 @@ namespace LayoutBXLYT.Cafe
|
|||
public class Header : BxlytHeader, IDisposable
|
||||
{
|
||||
private const string Magic = "FLYT";
|
||||
|
||||
private ushort ByteOrderMark;
|
||||
private ushort HeaderSize;
|
||||
|
||||
[Browsable(false)]
|
||||
public LYT1 LayoutInfo { get; set; }
|
||||
[Browsable(false)]
|
||||
public TXL1 TextureList { get; set; }
|
||||
[Browsable(false)]
|
||||
public MAT1 MaterialList { get; set; }
|
||||
[Browsable(false)]
|
||||
public FNL1 FontList { get; set; }
|
||||
[Browsable(false)]
|
||||
public CNT1 Container { get; set; }
|
||||
|
||||
//As of now this should be empty but just for future proofing
|
||||
private List<SectionCommon> UnknownSections = new List<SectionCommon>();
|
||||
|
||||
[Browsable(false)]
|
||||
public int TotalPaneCount()
|
||||
{
|
||||
int panes = GetPanes().Count;
|
||||
|
@ -248,16 +255,19 @@ namespace LayoutBXLYT.Cafe
|
|||
return panes + grpPanes;
|
||||
}
|
||||
|
||||
[Browsable(false)]
|
||||
public override List<string> Textures
|
||||
{
|
||||
get { return TextureList.Textures; }
|
||||
}
|
||||
|
||||
[Browsable(false)]
|
||||
public override Dictionary<string, STGenericTexture> GetTextures
|
||||
{
|
||||
get { return ((BFLYT)FileInfo).GetTextures(); }
|
||||
}
|
||||
|
||||
[Browsable(false)]
|
||||
public List<PAN1> GetPanes()
|
||||
{
|
||||
List<PAN1> panes = new List<PAN1>();
|
||||
|
@ -265,6 +275,7 @@ namespace LayoutBXLYT.Cafe
|
|||
return panes;
|
||||
}
|
||||
|
||||
[Browsable(false)]
|
||||
public List<GRP1> GetGroupPanes()
|
||||
{
|
||||
List<GRP1> panes = new List<GRP1>();
|
||||
|
@ -286,7 +297,7 @@ namespace LayoutBXLYT.Cafe
|
|||
GetGroupChildren(panes, (GRP1)pane);
|
||||
}
|
||||
|
||||
public void Read(FileReader reader, BFLYT bflyt)
|
||||
public Header()
|
||||
{
|
||||
LayoutInfo = new LYT1();
|
||||
TextureList = new TXL1();
|
||||
|
@ -295,6 +306,20 @@ namespace LayoutBXLYT.Cafe
|
|||
RootPane = new PAN1();
|
||||
RootGroup = new GRP1();
|
||||
|
||||
VersionMajor = 8;
|
||||
VersionMinor = 0;
|
||||
VersionMicro = 0;
|
||||
VersionMicro2 = 0;
|
||||
}
|
||||
|
||||
public void Read(FileReader reader, BFLYT bflyt)
|
||||
{
|
||||
LayoutInfo = new LYT1();
|
||||
TextureList = new TXL1();
|
||||
MaterialList = new MAT1();
|
||||
FontList = new FNL1();
|
||||
RootPane = new PAN1();
|
||||
RootGroup = new GRP1();
|
||||
FileInfo = bflyt;
|
||||
|
||||
reader.SetByteOrder(true);
|
||||
|
@ -303,6 +328,7 @@ namespace LayoutBXLYT.Cafe
|
|||
reader.CheckByteOrderMark(ByteOrderMark);
|
||||
HeaderSize = reader.ReadUInt16();
|
||||
Version = reader.ReadUInt32();
|
||||
SetVersionInfo();
|
||||
uint FileSize = reader.ReadUInt32();
|
||||
ushort sectionCount = reader.ReadUInt16();
|
||||
reader.ReadUInt16(); //Padding
|
||||
|
@ -1331,7 +1357,9 @@ namespace LayoutBXLYT.Cafe
|
|||
|
||||
private BFLYT.Header ParentLayout;
|
||||
|
||||
public PIC1() : base() {
|
||||
public PIC1(BFLYT.Header header) : base() {
|
||||
ParentLayout = header;
|
||||
|
||||
ColorTopLeft = STColor8.White;
|
||||
ColorTopRight = STColor8.White;
|
||||
ColorBottomLeft = STColor8.White;
|
||||
|
@ -1474,7 +1502,23 @@ namespace LayoutBXLYT.Cafe
|
|||
|
||||
public PAN1() : base()
|
||||
{
|
||||
Alpha = 255;
|
||||
PaneMagFlags = 0;
|
||||
Name = "";
|
||||
Translate = new Vector3F(0,0,0);
|
||||
Rotate = new Vector3F(0,0,0);
|
||||
Scale = new Vector2F(1,1);
|
||||
Width = 0;
|
||||
Height = 0;
|
||||
UserDataInfo = "";
|
||||
UserData = new UserData();
|
||||
|
||||
originX = OriginX.Center;
|
||||
originY = OriginY.Center;
|
||||
ParentOriginX = OriginX.Center;
|
||||
ParentOriginY = OriginY.Center;
|
||||
InfluenceAlpha = false;
|
||||
Visible = true;
|
||||
}
|
||||
|
||||
public PAN1(FileReader reader) : base()
|
||||
|
@ -1637,6 +1681,9 @@ namespace LayoutBXLYT.Cafe
|
|||
ParentLayout = header;
|
||||
|
||||
Name = reader.ReadString(0x1C).Replace("\0", string.Empty);
|
||||
Name = Name.Replace("\x01", string.Empty);
|
||||
Name = Name.Replace("\x04", string.Empty);
|
||||
|
||||
if (header.VersionMajor >= 8)
|
||||
{
|
||||
flags = reader.ReadUInt32();
|
||||
|
|
|
@ -235,55 +235,63 @@ namespace LayoutBXLYT
|
|||
|
||||
public class BxlytHeader : IDisposable
|
||||
{
|
||||
[Browsable(false)]
|
||||
public string FileName
|
||||
{
|
||||
get { return FileInfo.FileName; }
|
||||
}
|
||||
|
||||
[DisplayName("Use Big Endian"), CategoryAttribute("File Settings")]
|
||||
public bool IsBigEndian { get; set; }
|
||||
|
||||
[Browsable(false)]
|
||||
internal IFileFormat FileInfo;
|
||||
|
||||
[Browsable(false)]
|
||||
public BasePane RootPane { get; set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public BasePane RootGroup { get; set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public virtual Dictionary<string, STGenericTexture> GetTextures { get; }
|
||||
|
||||
[Browsable(false)]
|
||||
public virtual List<string> Textures { get; }
|
||||
|
||||
[Browsable(false)]
|
||||
internal uint Version;
|
||||
|
||||
[DisplayName("Version"), CategoryAttribute("File Settings")]
|
||||
public string VersionFull
|
||||
{
|
||||
get
|
||||
{
|
||||
var major = Version >> 24;
|
||||
var minor = Version >> 16 & 0xFF;
|
||||
var micro = Version >> 8 & 0xFF;
|
||||
var micro2 = Version & 0xFF;
|
||||
return $"{major} {minor} {micro} {micro2}";
|
||||
return $"{VersionMajor},{VersionMinor},{VersionMicro},{VersionMicro2}";
|
||||
}
|
||||
}
|
||||
|
||||
public uint VersionMajor
|
||||
|
||||
[RefreshProperties(RefreshProperties.All)]
|
||||
public uint VersionMajor { get; set; }
|
||||
[RefreshProperties(RefreshProperties.All)]
|
||||
public uint VersionMinor { get; set; }
|
||||
[RefreshProperties(RefreshProperties.All)]
|
||||
public uint VersionMicro { get; set; }
|
||||
[RefreshProperties(RefreshProperties.All)]
|
||||
public uint VersionMicro2 { get; set; }
|
||||
|
||||
internal void SetVersionInfo()
|
||||
{
|
||||
get { return Version >> 24; }
|
||||
VersionMajor = Version >> 24;
|
||||
VersionMinor = Version >> 16 & 0xFF;
|
||||
VersionMicro = Version >> 8 & 0xFF;
|
||||
VersionMicro2 = Version & 0xFF;
|
||||
}
|
||||
|
||||
public uint VersionMinor
|
||||
internal uint SaveVersion()
|
||||
{
|
||||
get { return Version >> 16 & 0xFF; }
|
||||
}
|
||||
|
||||
public uint VersionMicro
|
||||
{
|
||||
get { return Version >> 8 & 0xFF; }
|
||||
}
|
||||
|
||||
public uint VersionMicro2
|
||||
{
|
||||
get { return Version & 0xFF; }
|
||||
return VersionMajor << 24 | VersionMinor << 16 | VersionMicro << 8 | VersionMicro2;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
|
@ -147,11 +147,15 @@ namespace LayoutBXLYT
|
|||
{
|
||||
if (e is TreeViewEventArgs) {
|
||||
var node = ((TreeViewEventArgs)e).Node;
|
||||
var pane = (BasePane)node.Tag;
|
||||
|
||||
LayoutProperties.LoadProperties(pane, OnProperyChanged);
|
||||
|
||||
ActiveViewport.SelectedPanes.Add(pane);
|
||||
if (node.Tag is BasePane)
|
||||
{
|
||||
var pane = node.Tag as BasePane;
|
||||
LayoutProperties.LoadProperties(pane, OnProperyChanged);
|
||||
ActiveViewport.SelectedPanes.Add(pane);
|
||||
}
|
||||
else
|
||||
LayoutProperties.LoadProperties(node.Tag, OnProperyChanged);
|
||||
}
|
||||
}
|
||||
if (ActiveViewport != null)
|
||||
|
@ -428,6 +432,7 @@ namespace LayoutBXLYT
|
|||
if (TextConverter == null)
|
||||
TextConverter = new LayoutTextDocked();
|
||||
TextConverter.Text = "Text Converter";
|
||||
TextConverter.TextCompiled += OnTextCompiled;
|
||||
TextConverter.LoadLayout((BFLYT)ActiveLayout.FileInfo);
|
||||
if (ActiveViewport != null)
|
||||
TextConverter.Show(ActiveViewport.Pane, DockAlignment.Bottom, 0.4);
|
||||
|
@ -444,6 +449,16 @@ namespace LayoutBXLYT
|
|||
}
|
||||
}
|
||||
|
||||
private void OnTextCompiled(object sender, EventArgs e)
|
||||
{
|
||||
var layout = TextConverter.GetLayout();
|
||||
ActiveLayout = layout.header;
|
||||
ReloadEditors(layout.header);
|
||||
|
||||
if (ActiveViewport != null)
|
||||
ActiveViewport.ResetLayout(ActiveLayout);
|
||||
}
|
||||
|
||||
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ActiveLayout != null && ActiveLayout.FileInfo.CanSave)
|
||||
|
|
|
@ -47,6 +47,8 @@ namespace LayoutBXLYT
|
|||
treeView1.BeginUpdate();
|
||||
treeView1.Nodes.Clear();
|
||||
|
||||
treeView1.Nodes.Add(new TreeNode("File Settings") {Tag = bxlyt });
|
||||
|
||||
CreateQuickAccess(bxlyt);
|
||||
LoadPane(bxlyt.RootGroup);
|
||||
LoadPane(bxlyt.RootPane);
|
||||
|
|
|
@ -35,6 +35,11 @@ namespace LayoutBXLYT
|
|||
stPropertyGrid1.UpdateProperties();
|
||||
}
|
||||
|
||||
public void LoadProperties(object prop, Action propChanged)
|
||||
{
|
||||
LoadPropertyTab("Properties", prop, propChanged);
|
||||
}
|
||||
|
||||
public void LoadProperties(BasePane prop, Action propChanged)
|
||||
{
|
||||
LoadPropertyTab("Pane", prop, propChanged);
|
||||
|
|
|
@ -28,8 +28,16 @@
|
|||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// LayoutTextDocked
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(320, 292);
|
||||
this.Name = "LayoutTextDocked";
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -14,6 +14,8 @@ namespace LayoutBXLYT
|
|||
{
|
||||
public partial class LayoutTextDocked : LayoutDocked
|
||||
{
|
||||
public EventHandler TextCompiled;
|
||||
|
||||
TextEditor editor;
|
||||
public LayoutTextDocked()
|
||||
{
|
||||
|
@ -22,6 +24,13 @@ namespace LayoutBXLYT
|
|||
editor = new TextEditor();
|
||||
editor.Dock = DockStyle.Fill;
|
||||
Controls.Add(editor);
|
||||
|
||||
TextCompiled += CompileLayout;
|
||||
}
|
||||
|
||||
public BFLYT GetLayout()
|
||||
{
|
||||
return activeLayout;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
|
@ -29,9 +38,24 @@ namespace LayoutBXLYT
|
|||
editor.FillEditor("");
|
||||
}
|
||||
|
||||
private BFLYT activeLayout;
|
||||
public void LoadLayout(BFLYT bflyt)
|
||||
{
|
||||
activeLayout = bflyt;
|
||||
editor.AddContextMenu("Convert to BFLYT", TextCompiled);
|
||||
editor.FillEditor(bflyt.ConvertToString());
|
||||
}
|
||||
|
||||
private void CompileLayout(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
activeLayout.ConvertFromString(editor.GetText());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
STErrorDialog.Show("Failed to convert BFLYT! ", "Text Converter", ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
120
File_Format_Library/GUI/BFLYT/LayoutTextDocked.resx
Normal file
120
File_Format_Library/GUI/BFLYT/LayoutTextDocked.resx
Normal file
|
@ -0,0 +1,120 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
|
@ -34,6 +34,12 @@ namespace LayoutBXLYT
|
|||
|
||||
private Dictionary<string, STGenericTexture> Textures;
|
||||
|
||||
public void ResetLayout(BxlytHeader bxlyt)
|
||||
{
|
||||
LayoutFile = bxlyt;
|
||||
UpdateViewport();
|
||||
}
|
||||
|
||||
public LayoutViewer(BxlytHeader bxlyt, Dictionary<string, STGenericTexture> textures)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
|
Loading…
Reference in a new issue