using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Threading.Tasks; using Switch_Toolbox; using System.Windows.Forms; using Switch_Toolbox.Library; using ByamlExt.Byaml; using ByamlExt; using WeifenLuo.WinFormsUI.Docking; namespace FirstPlugin { public class BYAML : TreeNodeFile, IFileFormat { public bool CanSave { get; set; } = false; public bool FileIsEdited { get; set; } = false; public bool FileIsCompressed { get; set; } = false; public string[] Description { get; set; } = new string[] { "BYAML" }; public string[] Extension { get; set; } = new string[] { "*.byaml", "*.byml", "*.bprm", "*.sbyml" }; public string Magic { get; set; } = "YB"; public CompressionType CompressionType { get; set; } = CompressionType.None; public byte[] Data { get; set; } public string FileName { get; set; } public bool IsActive { get; set; } = false; public bool UseEditMenu { get; set; } = false; public string FilePath { get; set; } public IFileInfo IFileInfo { get; set; } public Type[] Types { get { List types = new List(); return types.ToArray(); } } class EditableNode { public Type type { get => Node[Index].GetType(); } dynamic Node; dynamic Index; public dynamic Get() => Node[Index]; public void Set(dynamic value) => Node[Index] = value; public string GetTreeViewString() { if (Index is int) return Node[Index].ToString(); else return Index + " : " + Node[Index].ToString(); } public EditableNode(dynamic _node, dynamic _index) { Node = _node; Index = _index; } } MemoryStream mem; public void Load() { IsActive = false; CanSave = false; mem = new MemoryStream(Data); ByamlViewer.OpenByml(mem, FileName); // BymlFileData byamlFile = ByamlFile.LoadN(new System.IO.MemoryStream(Data), false, Syroot.BinaryData.ByteOrder.LittleEndian); // LoadDockedEditor(byamlFile); } public void Unload() { } public TreeNode LoadByamlNodes(dynamic root) { TreeNode node = new TreeNode(); if (root == null) return node; if (root is Dictionary) { parseDictNode(root, node.Nodes); } else if (root is List) { if (((List)root).Count == 0) { MessageBox.Show("This byml is empty"); } parseArrayNode(root, node.Nodes); } else if (root is List) { } return node; } void parseArrayNode(IList list, TreeNodeCollection addto) { int index = 0; foreach (dynamic k in list) { if (k is IDictionary) { TreeNode current = addto.Add(""); current.Tag = ((IDictionary)k); current.Nodes.Add("✯✯dummy✯✯"); } else if (k is IList) { TreeNode current = addto.Add(""); current.Tag = ((IList)k); current.Nodes.Add("✯✯dummy✯✯"); } else if (k is IList) { TreeNode current = addto.Add(""); current.Tag = ((IList)k); parsePathPointArray(k, current.Nodes); } else { var n = addto.Add(k == null ? "" : k.ToString()); if (k != null) n.Tag = new EditableNode(list, index); } index++; } } void parseDictNode(IDictionary node, TreeNodeCollection addto) { foreach (string k in node.Keys) { TreeNode current = addto.Add(k); if (node[k] is IDictionary) { current.Text += " : "; current.Tag = node[k]; current.Nodes.Add("✯✯dummy✯✯"); //a text that can't be in a byml } else if (node[k] is IList) { current.Text += " : "; current.Tag = ((IList)node[k]); current.Nodes.Add("✯✯dummy✯✯"); } else if (node[k] is IList) { current.Text += " : "; current.Tag = ((IList)node[k]); parsePathPointArray(node[k], current.Nodes); } else { current.Text = current.Text + " : " + (node[k] == null ? "" : node[k].ToString()); if (node[k] != null) current.Tag = new EditableNode(node, k); } } } void parsePathPointArray(IList list, TreeNodeCollection addto) { int index = 0; foreach (var k in list) { index++; var n = addto.Add(k == null ? "" : k.ToString()); if (k != null) n.Tag = new EditableNode(list, index); } } public byte[] Save() { if (mem != null) return mem.ToArray(); return null; } } }