public BymlFileData GenerateByaml(bool isBigEndian)
        {
            var entries = GetCollisionEntries();
            var col     = RemoveDuplicateEntries(entries);

            List <dynamic> root = new List <dynamic>();

            foreach (var entry in col)
            {
                IDictionary <string, dynamic> colCodes = new Dictionary <string, dynamic>();

                colCodes.Add("CameraCode", CreateEntry(CameraCodes, entry.CameraCode));
                colCodes.Add("FloorCode", CreateEntry(FloorCodes, entry.FloorCode));
                colCodes.Add("MaterialCode", CreateEntry(MaterialCodes, entry.MaterialCode));
                colCodes.Add("WallCode", CreateEntry(WallCodes, entry.WallCode));
                root.Add(colCodes);
            }

            var byml = new BymlFileData();

            byml.byteOrder = isBigEndian ? Syroot.BinaryData.ByteOrder.BigEndian :
                             Syroot.BinaryData.ByteOrder.LittleEndian;
            byml.Version = (ushort)(isBigEndian ? 1 : 2);

            byml.SupportPaths = false;
            byml.RootNode     = root;

            return(byml);
        }
Exemplo n.º 2
0
        public BymlFileData GenerateByaml()
        {
            var entries = GetCollisionEntries();
            var col     = RemoveDuplicateEntries(entries);

            List <dynamic> root = new List <dynamic>();

            foreach (var entry in col)
            {
                IDictionary <string, dynamic> colCodes = new Dictionary <string, dynamic>();
                colCodes.Add("CameraCode", CameraCodes[entry.CameraCode]);
                colCodes.Add("FloorCode", FloorCodes[entry.FloorCode]);
                if (entry.MaterialPrefixCode != "NONE")
                {
                    colCodes.Add("MaterialCodePrefix", MaterialPrefixCodes[entry.MaterialPrefixCode]);
                }
                colCodes.Add("MaterialCode", MaterialCodes[entry.MaterialCode]);
                colCodes.Add("WallCode", WallCodes[entry.WallCode]);
                root.Add(colCodes);
            }

            var byml = new BymlFileData();

            byml.byteOrder    = Syroot.BinaryData.ByteOrder.LittleEndian;
            byml.Version      = 3;
            byml.SupportPaths = false;
            byml.RootNode     = root;

            return(byml);
        }
Exemplo n.º 3
0
        public void Load(Stream stream)
        {
            CanSave = true;

            IsDialog = IFileInfo != null && IFileInfo.InArchive;

            data = ByamlFile.LoadN(stream);
        }
Exemplo n.º 4
0
        private static void ParseYML(string FileName)
        {
            BymlFileData data = ByamlFile.LoadN(FileName, true);

            var serializer = new SharpYaml.Serialization.Serializer();
            var text       = serializer.Serialize(data);

            Console.WriteLine(text);
        }
Exemplo n.º 5
0
 public static BymlFileData SwitchEndianness(this BymlFileData data)
 {
     return(new BymlFileData
     {
         byteOrder = data.byteOrder.SwitchByteOrder(),
         RootNode = data.RootNode,
         SupportPaths = data.SupportPaths,
         Version = data.Version
     });
 }
Exemplo n.º 6
0
 public static Task <BymlFileData> SwitchEndiannessAsync(this BymlFileData data)
 {
     return(Task.Run(() => new BymlFileData
     {
         byteOrder = data.byteOrder.FlipByteOrder(),
         RootNode = data.RootNode,
         SupportPaths = data.SupportPaths,
         Version = data.Version
     }));
 }
Exemplo n.º 7
0
        public void Load(Stream stream)
        {
            CanSave = true;

            //Keep the stream open.
            //This is for the file to optionally be reloaded for different encoding types
            IsDialog = IFileInfo != null && IFileInfo.InArchive;

            BymlData = ByamlFile.LoadN(stream);
        }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
0
        public void Save()
        {
            //byte[] tmp = ToByaml();
            //File.WriteAllBytes("Test.byml", tmp);
            BymlFileData Output = new BymlFileData()
            {
                Version = 1, SupportPaths = false, byteOrder = ByteOrder
            };

            Dictionary <string, dynamic> FinalRoot = new Dictionary <string, dynamic>();
            List <dynamic> worlds = new List <dynamic>();

            for (int i = 0; i < Worlds.Count; i++)
            {
                worlds.Add(Worlds[i].ToByaml());
            }

            FinalRoot.Add("WorldList", worlds);
            Output.RootNode = FinalRoot;



            SarcData Data = new SarcData()
            {
                byteOrder = ByteOrder, Files = new Dictionary <string, byte[]>()
            };

            Data.Files.Add("StageList.byml", ByamlFile.SaveN(Output));
            Tuple <int, byte[]> x = SARC.PackN(Data);


            if (Filename.StartsWith(Program.GamePath) && !string.IsNullOrEmpty(Program.ProjectPath))
            {
                switch (MessageBox.Show(
                            Program.CurrentLanguage.GetTranslation("SaveStageListInProjectText") ?? "Would you like to save the StageList.szs to your ProjectPath instead of your BaseGame?",
                            Program.CurrentLanguage.GetTranslation("SaveStageListInProjectHeader") ?? "Save in ProjectPath",
                            MessageBoxButtons.YesNoCancel))
                {
                case DialogResult.Yes:
                    Directory.CreateDirectory(Path.Combine(Program.ProjectPath, "SystemData"));
                    Filename = Path.Combine(Program.ProjectPath, "SystemData", "StageList.szs");
                    break;

                case DialogResult.No:
                    break;

                case DialogResult.Cancel:
                    return;
                }
            }

            File.WriteAllBytes(Filename, YAZ0.Compress(x.Item2));
            //File.WriteAllBytes("Broken.byml", Data.Files["StageList.byml"]);
        }
Exemplo n.º 10
0
        public static BymlFileData FromYaml(string text)
        {
            NodePaths.Clear();
            ReferenceNodes.Clear();

            var data = new BymlFileData();
            var yaml = new YamlStream();

            yaml.Load(File.OpenText(text));
            var mapping = (YamlMappingNode)yaml.Documents[0].RootNode;

            foreach (var child in mapping.Children)
            {
                var key   = ((YamlScalarNode)child.Key).Value;
                var value = child.Value.ToString();

                if (key == "Version")
                {
                    data.Version = ushort.Parse(value);
                }
                if (key == "IsBigEndian")
                {
                    data.byteOrder = bool.Parse(value) ? ByteOrder.BigEndian : ByteOrder.LittleEndian;
                }
                if (key == "SupportPaths")
                {
                    data.SupportPaths = bool.Parse(value);
                }

                if (child.Value is YamlMappingNode)
                {
                    data.RootNode = ParseNode(child.Value);
                }
                if (child.Value is YamlSequenceNode)
                {
                    data.RootNode = ParseNode(child.Value);
                }
            }

            ReferenceNodes.Clear();
            NodePaths.Clear();

            return(data);
        }
Exemplo n.º 11
0
        private void Replace(object sender, EventArgs args)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Supported Formats|*.obj";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                var form = Runtime.MainForm;

                var thread = new Thread(() =>
                {
                    //Load runtime values to gui handler
                    MaterialWindowSettings.GamePreset      = Runtime.CollisionSettings.KCLGamePreset;
                    MaterialWindowSettings.Platform        = GetPlatform();
                    MaterialWindowSettings.UsePresetEditor = Runtime.CollisionSettings.KCLUsePresetEditor;

                    var result = CollisionLoader.CreateCollisionFromObject(form, ofd.FileName);
                    CollisionLoader.CloseConsole(form);

                    if (result.KclFie == null)
                    {
                        return;
                    }

                    SaveMaterialWindowSettings();

                    form.Invoke((MethodInvoker) delegate
                    {
                        KclFile = result.KclFie;
                        if (result.AttributeFile is MaterialAttributeBymlFile)
                        {
                            AttributeByml = ((MaterialAttributeBymlFile)result.AttributeFile).BymlFile;
                        }
                        ReloadData();
                        Renderer.UpdateVertexData();
                        SaveAttributeByml(true);
                    });
                });
                thread.Start();
            }
        }
Exemplo n.º 12
0
        private void Replace(object sender, EventArgs args)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Supported Formats|*.obj";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                var mod = EditorCore.Common.OBJ.Read(new MemoryStream(File.ReadAllBytes(ofd.FileName)), null);
                if (mod.Faces.Count > 65535)
                {
                    MessageBox.Show("this model has too many faces, only models with less than 65535 triangles can be converted");
                    return;
                }
                kcl           = MarioKart.MK7.KCL.FromOBJ(mod);
                AttributeByml = kcl.AttributeByml;
                data          = kcl.Write(Endianness);
                Read(data);
                Renderer.UpdateVertexData();
                SaveAttributeByml(true);
            }
        }
Exemplo n.º 13
0
        public void ReloadEncoding(Encoding encoding)
        {
            BymlFileData.Encoding = encoding;

            //Reopen and reload the byml data
            if (IFileInfo.ArchiveParent != null)
            {
                foreach (var file in IFileInfo.ArchiveParent.Files)
                {
                    var name = Path.GetFileName(file.FileName);
                    if (name == FileName)
                    {
                        BymlData = ByamlFile.LoadN(new MemoryStream(file.FileData));
                    }
                }
            }
            else if (File.Exists(FilePath))
            {
                var file = File.OpenRead(FilePath);
                BymlData = ByamlFile.LoadN(file);
                file.Close();
            }
        }
Exemplo n.º 14
0
 public static string ToYaml(this BymlFileData data)
 {
     return(YamlByamlConverter.ToYaml(data));
 }
Exemplo n.º 15
0
 public static void SaveFile(this BymlFileData data, string file)
 {
     File.WriteAllBytes(file, ByamlFile.SaveN(data));
 }
Exemplo n.º 16
0
 public static byte[] GetBytes(this BymlFileData data)
 {
     return(ByamlFile.SaveN(data));
 }
Exemplo n.º 17
0
 public void LoadByaml(BymlFileData byamlFile)
 {
 }