예제 #1
0
        public static void OpenByml(Stream file, BYAML byaml, string FileName, bool?paths, Stream saveStream, bool AsDialog)
        {
            bool _paths = paths == null?SupportPaths() : paths.Value;

            var byml = ByamlFile.LoadN(file, _paths);

            OpenByml(byml, byaml, saveStream, AsDialog);
        }
예제 #2
0
        public static void OpenByml(BymlFileData data, BYAML byaml, Stream saveStream = null, bool AsDialog = false)
        {
            var form = new ByamlEditor(data.RootNode, data.SupportPaths, saveStream, data.Version, data.byteOrder, AsDialog, byaml);

            if (saveStream != null && saveStream.CanWrite)
            {
                saveStream.Position = 0;
                saveStream.SetLength(0);
            }
        }
예제 #3
0
        public void UpdateByaml(System.Collections.IEnumerable by, bool _pathSupport, ushort _ver, ByteOrder defaultOrder = ByteOrder.LittleEndian, bool IsSaveDialog = false, BYAML byaml = null)
        {
            FileFormat = byaml;

            treeView1.Nodes.Clear();

            stTabControl1.myBackColor = FormThemes.BaseTheme.FormBackColor;

            if (byaml.FileName == "course_muunt_debug.byaml" && useMuunt)
            {
                pathSupport = true;

                stPanel1.Controls.Remove(splitContainer1);

                TurboMunntEditor editor = new TurboMunntEditor();
                editor.Dock = DockStyle.Fill;
                editor.LoadCourseInfo(by, byaml.FilePath);
                stPanel1.Controls.Add(editor);
                return;
            }


            byteOrder   = defaultOrder;
            FileName    = byaml.FileName;
            byml        = by;
            pathSupport = _pathSupport;
            bymlVer     = _ver;

            if (byml == null)
            {
                return;
            }
            ParseBymlFirstNode();

            stPanel4.Controls.Clear();

            textEditor = new TextEditor();
            textEditor.ClearContextMenus(new string[] { "Search" });
            textEditor.AddContextMenu("Decompile", TextEditorToYaml);
            textEditor.AddContextMenu("Compile", TextEditorFromYaml);

            var formatMenu = new STToolStripItem("Change Formatting");

            formatMenu.DropDownItems.Add(xmlOldToolstrip);
            formatMenu.DropDownItems.Add(xmlToolstrip);
            formatMenu.DropDownItems.Add(yamlToolstrip);

            textEditor.AddContextMenu(formatMenu);

            stPanel4.Controls.Add(textEditor);
        }
예제 #4
0
            public void ConvertBEtoLE(object sender, EventArgs args)
            {
                var byamlF = new BYAML();

                byamlF.IFileInfo = new IFileInfo();

                OpenFileDialog ofd = new OpenFileDialog();

                ofd.Filter = Utils.GetAllFilters(byamlF);
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    byamlF.Load(new FileStream(ofd.FileName, FileMode.Open));
                    byamlF.BymlData.byteOrder = Syroot.BinaryData.ByteOrder.LittleEndian;

                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = Utils.GetAllFilters(byamlF);
                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        STFileSaver.SaveFileFormat(byamlF, sfd.FileName);
                    }
                }
            }
        static YamlNode SaveNode(string name, dynamic node)
        {
            if (node == null)
            {
                return(new YamlScalarNode("null"));
            }
            else if (IsReferenceNode(node))
            {
                if (NodePaths[node].Tag == null)
                {
                    NodePaths[node].Tag = $"!ref{refNodeId++}";
                }
                return(new YamlScalarNode($"!refTag={NodePaths[node].Tag}"));
            }
            else if ((node is IList <dynamic>))
            {
                var yamlNode = new YamlSequenceNode();
                //  NodePaths.Add(node, yamlNode);

                if (!HasEnumerables((IList <dynamic>)node) &&
                    ((IList <dynamic>)node).Count < 6)
                {
                    yamlNode.Style = SharpYaml.YamlStyle.Flow;
                }

                foreach (var item in (IList <dynamic>)node)
                {
                    yamlNode.Add(SaveNode(null, item));
                }

                return(yamlNode);
            }
            else if (node is IDictionary <string, dynamic> )
            {
                var yamlNode = new YamlMappingNode();
                //  NodePaths.Add(node, yamlNode);

                if (!HasEnumerables((IDictionary <string, dynamic>)node) &&
                    ((IDictionary <string, dynamic>)node).Count < 6)
                {
                    yamlNode.Style = SharpYaml.YamlStyle.Flow;
                }

                foreach (var item in (IDictionary <string, dynamic>)node)
                {
                    string   key     = item.Key;
                    YamlNode keyNode = new YamlScalarNode(key);
                    if (BYAML.IsHash(key))
                    {
                        uint hash = Convert.ToUInt32(key, 16);
                        if (BYAML.Hashes.ContainsKey(hash))
                        {
                            key = $"{BYAML.Hashes[hash]}";
                        }

                        keyNode     = new YamlScalarNode(key);
                        keyNode.Tag = "!h";
                    }
                    yamlNode.Add(keyNode, SaveNode(item.Key, item.Value));
                }
                return(yamlNode);
            }
            else if (node is ByamlPathPoint)
            {
                return(ConvertPathPoint((ByamlPathPoint)node));
            }
            else if (node is List <ByamlPathPoint> )
            {
                var yamlNode = new YamlSequenceNode();
                foreach (var pt in (List <ByamlPathPoint>)node)
                {
                    yamlNode.Add(ConvertPathPoint(pt));
                }
                return(yamlNode);
            }
            else
            {
                string tag = null;
                if (node is int)
                {
                    tag = "!l";
                }
                else if (node is uint)
                {
                    tag = "!u";
                }
                else if (node is Int64)
                {
                    tag = "!ul";
                }
                else if (node is double)
                {
                    tag = "!d";
                }
                else if (node is ByamlPathIndex)
                {
                    tag = "!p";
                }

                var yamlNode = new YamlScalarNode(ConvertValue(node));
                if (tag != null)
                {
                    yamlNode.Tag = tag;
                }
                return(yamlNode);
            }
        }
예제 #6
0
        public ByamlEditor(System.Collections.IEnumerable by, bool _pathSupport, ushort _ver, ByteOrder defaultOrder = ByteOrder.LittleEndian, bool IsSaveDialog = false, BYAML byaml = null)
        {
            InitializeComponent();
            Reload();

            UpdateByaml(by, _pathSupport, _ver, defaultOrder, IsSaveDialog, byaml);
        }
예제 #7
0
 public static void OpenByml(Stream file, BYAML byaml, string FileName = "")
 {
     OpenByml(file, byaml, FileName, SupportPaths());
 }
예제 #8
0
 public static void OpenByml(Stream file, BYAML byaml, string FileName, bool paths)
 {
     OpenByml(file, byaml, FileName, paths, null, false);
 }
예제 #9
0
 public static void OpenByml(string Filename, BYAML byaml)
 {
     OpenByml(new FileStream(Filename, FileMode.Open), byaml, Filename);
 }
예제 #10
0
        public ByamlEditor(System.Collections.IEnumerable by, bool _pathSupport, Stream saveTo, ushort _ver, ByteOrder defaultOrder = ByteOrder.LittleEndian, bool IsSaveDialog = false, BYAML byaml = null) : this(by, _pathSupport, _ver, defaultOrder, IsSaveDialog, byaml)
        {
            treeView1.BackColor = FormThemes.BaseTheme.FormBackColor;
            treeView1.ForeColor = FormThemes.BaseTheme.FormForeColor;

            if (!IsSaveDialog)
            {
                stPanel1.Dock = DockStyle.Fill;
            }

            saveStream = saveTo;
            saveToolStripMenuItem.Visible = saveTo != null && saveStream.CanWrite;
        }
예제 #11
0
        public ByamlEditor(System.Collections.IEnumerable by, bool _pathSupport, ushort _ver, ByteOrder defaultOrder = ByteOrder.LittleEndian, bool IsSaveDialog = false, BYAML byaml = null)
        {
            InitializeComponent();

            treeView1.BackColor = FormThemes.BaseTheme.FormBackColor;
            treeView1.ForeColor = FormThemes.BaseTheme.FormForeColor;

            if (!IsSaveDialog)
            {
                stButton1.Visible = false;
                stButton2.Visible = false;
                stPanel1.Dock     = DockStyle.Fill;
            }

            /*   if (byaml.FileName == "course_muunt.byaml")
             * {
             *     pathSupport = true;
             *
             *     stPanel1.Controls.Remove(treeView1);
             *
             *     TurboMunntEditor editor = new TurboMunntEditor();
             *     editor.Dock = DockStyle.Fill;
             *     editor.LoadCourseInfo(by, byaml.FilePath);
             *     stPanel1.Controls.Add(editor);
             *     return;
             * }*/


            byteOrder   = defaultOrder;
            FileName    = byaml.FileName;
            byml        = by;
            pathSupport = _pathSupport;
            bymlVer     = _ver;

            if (byml == null)
            {
                return;
            }
            ParseBymlFirstNode();
        }
예제 #12
0
        public ByamlEditor(System.Collections.IEnumerable by, bool _pathSupport, ushort _ver, ByteOrder defaultOrder = ByteOrder.LittleEndian, bool IsSaveDialog = false, BYAML byaml = null)
        {
            InitializeComponent();

            treeView1.BackColor = FormThemes.BaseTheme.FormBackColor;
            treeView1.ForeColor = FormThemes.BaseTheme.FormForeColor;

            stTabControl1.myBackColor = FormThemes.BaseTheme.FormBackColor;

            if (byaml.FileName == "course_muunt_debug.byaml" && useMuunt)
            {
                pathSupport = true;

                stPanel1.Controls.Remove(splitContainer1);

                TurboMunntEditor editor = new TurboMunntEditor();
                editor.Dock = DockStyle.Fill;
                editor.LoadCourseInfo(by, byaml.FilePath);
                stPanel1.Controls.Add(editor);
                return;
            }


            byteOrder   = defaultOrder;
            FileName    = byaml.FileName;
            byml        = by;
            pathSupport = _pathSupport;
            bymlVer     = _ver;

            if (byml == null)
            {
                return;
            }
            ParseBymlFirstNode();

            xmlEditor = new TextEditor();
            stPanel2.Controls.Add(xmlEditor);
            xmlEditor.Dock  = DockStyle.Fill;
            xmlEditor.IsXML = true;
        }
        static dynamic ConvertValue(string value, string tag)
        {
            if (tag == null)
            {
                tag = "";
            }

            if (value == "null")
            {
                return(null);
            }
            else if (value == "true")
            {
                return(true);
            }
            else if (value == "false")
            {
                return(false);
            }
            else if (tag == "!u")
            {
                return(UInt32.Parse(value, CultureInfo.InvariantCulture));
            }
            else if (tag == "!l")
            {
                return(Int32.Parse(value, CultureInfo.InvariantCulture));
            }
            else if (tag == "!d")
            {
                return(Double.Parse(value, CultureInfo.InvariantCulture));
            }
            else if (tag == "!ul")
            {
                return(UInt64.Parse(value, CultureInfo.InvariantCulture));
            }
            else if (tag == "!ll")
            {
                return(Int64.Parse(value, CultureInfo.InvariantCulture));
            }
            else if (tag == "!p")
            {
                return new ByamlPathIndex()
                       {
                           Index = Int32.Parse(value, CultureInfo.InvariantCulture)
                       }
            }
            ;
            else
            {
                float floatValue = 0;

                bool isFloat = float.TryParse(value, out floatValue);
                if (isFloat)
                {
                    return(floatValue);
                }
                else
                {
                    if (BYAML.IsHash(value))
                    {
                        uint hash = Convert.ToUInt32(value, 16);
                        if (BYAML.Hashes.ContainsKey(hash))
                        {
                            return($"!h {BYAML.Hashes[hash]}");
                        }
                    }
                    return(value);
                }
            }
        }