コード例 #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);
                    }
                }
            }
コード例 #5
0
        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;
        }
コード例 #13
0
        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);
                }
            }
        }