Esempio n. 1
0
        // ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------

        private static void Main(string[] args)
        {
            Yaz0Compression.Decompress(@"D:\Pictures\zBFRES\BotW\Animal_Bass.sbfres",
                                       @"D:\Pictures\zBFRES\BotW\Animal_Bass.bfres");
            ResFile resFile = new ResFile(@"D:\Pictures\zBFRES\BotW\Animal_Bass.bfres");

            //ResFile resFile = new ResFile(@"D:\Archive\Wii U\_Roms\MK8\content\race_common\Coin\Coin.bfres");
            //resFile.Models[0].Shapes[0].Meshes[0].SetIndices(new uint[] { 1, 2, 3 }, GX2IndexFormat.UInt32);
            //resFile.Save(@"D:\Archive\Wii U\_Roms\MK8\content\race_common\Coin\Coin.bfres");

            //LoadResFiles(LogSurfaceFormats);

            Console.WriteLine("Done.");
            Console.ReadLine();
        }
    private ResFile GetResFileFromSBFRES(string sbfres)
    {
        //Determine the paths of each of the components for the extraction.
        string sbfresFolder = Path.Combine(Application.dataPath, "SBFRES");
        // Get model.
        string sbfresFile = Path.Combine(sbfresFolder, sbfres);

        //Make sure that the specified sbfresFile path exists.
        if (!File.Exists(sbfresFile) || Path.GetExtension(sbfresFile).Equals("sbfres"))
        {
            Debug.Log(sbfresFile + " was invalid!");
            return(null);
        }

        string bfresFile = Path.Combine(sbfresFolder, sbfres.Substring(0, sbfres.IndexOf(".", StringComparison.Ordinal)) + ".bfres");

        //Extract the SBFRES file to a loadable BFRES.
        if (!File.Exists(bfresFile))
        {
            Yaz0Compression.Decompress(sbfresFile, bfresFile);
            Debug.Log("Extracted " + sbfresFile + " to " + bfresFile);
        }
        else
        {
            Debug.Log(bfresFile + " already exists, not extracting.");
        }

        //Load the model into a ResFile instance.
        ResFile loadedFile;

        try
        {
            loadedFile = new ResFile(bfresFile);
        }
        catch (Exception e)
        {
            Debug.Log("Error while attempting to load " + bfresFile + " into a ResFile instance: " + e);
            return(null);
        }
        Debug.Log("Loaded " + loadedFile.Name + " (version " + loadedFile.Version + ") successfully!");

        return(loadedFile);
    }
Esempio n. 3
0
        private void openSZSToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult result = SZS.ShowDialog();

            if (result == DialogResult.OK)
            {
                if (SZS.FileName.EndsWith("szs"))
                {
                    Yaz0Compression.Decompress(SZS.FileName + "", "Files/Unpacked.sarc");
                    if (File.Exists("Files/Unpacked.sarc"))
                    {
                        Bytes = File.ReadAllBytes("Files/Unpacked.sarc");
                        var newArray = Bytes.Skip(4096).ToArray();
                        File.WriteAllBytes("Files/Unpacked.byml", newArray);
                        if (!File.Exists("Files/UNP"))
                        {
                            File.Copy("Files/Unpacked.byml", "Files/UNP");
                        }
                        else
                        {
                            File.Delete("Files/UNP");
                            File.Copy("Files/Unpacked.byml", "Files/UNP");
                        }
                        ofd.FileName = "Files/Unpacked.byml";
                        FileOpened   = true;
                        MessageBox.Show("Successfully Unpacked the byml file from the szs to Files folder in the exe folder", "Done!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    MessageBox.Show("Please select a valid szs file", "Not a szs file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Please Select A File", "File is not selected", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 4
0
        private void ButtonLoadByml_Click(object sender, EventArgs e)
        {
            string path = textBoxBrowseByml.Text;

            if (path == null || path.Length == 0)
            {
                MessageBox.Show("Please entery a valid byml path.");
                return;
            }
            if (!File.Exists(path))
            {
                return;
            }
            File.Copy(path, path + ".bak", true);

            using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.UTF8, true))
                {
                    UInt16 magicBytes = reader.ReadUInt16();
                    compressed = magicBytes == YAZ0_MAGIC_BYTES;
                }
            }
            if (compressed)
            {
                Yaz0Compression.Decompress(path, TEMP_FILE);
                if (textBoxBrowseByml.Text.Contains("sbyml"))
                {
                    textBoxBrowseByml.Text = textBoxBrowseByml.Text.Replace("sbyml", "byml");
                }
                path = TEMP_FILE;
            }
            Dictionary <string, dynamic> byamlData = ByamlFile.Load(path);

            treeViewByml.Nodes.Clear();
            treeViewByml.Nodes.Add(AddNode(byamlData, null));
        }
Esempio n. 5
0
        public static AnimationGroupNode Read(string filename, ResFile TargetWiiUBFRES, BFRES bfres)
        {
            string path = filename;

            FileData f = new FileData(filename);


            int Magic = f.readInt();

            if (Magic == 0x59617A30) //YAZO compressed
            {
                using (FileStream input = new FileStream(path, System.IO.FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    Yaz0Compression.Decompress(path, TEMP_FILE);

                    path = TEMP_FILE;
                }
            }

            f = new FileData(path);

            f.seek(0);

            f.Endian = Endianness.Little;

            Console.WriteLine("Reading Animations ...");

            f.seek(4);                     // magic check
            int SwitchCheck = f.readInt(); //Switch version only has padded magic

            f.skip(4);


            //    SwitchAnim2WiiU(path); //Hacky auto convert switch anims to wii u


            Syroot.NintenTools.NSW.Bfres.ResFile b = new Syroot.NintenTools.NSW.Bfres.ResFile(path);

            AnimationGroupNode ThisAnimation = new AnimationGroupNode()
            {
                Text = "Bone Visual Animations"
            };

            TreeNode dummy = new TreeNode()
            {
                Text = "Animation Set"
            };

            int i = 0;

            foreach (Syroot.NintenTools.NSW.Bfres.VisibilityAnim vis in b.BoneVisibilityAnims)
            {
                Animation a = new Animation(vis.Name);

                ThisAnimation.Nodes.Add(a);

                a.FrameCount = vis.FrameCount;
                i++;

                int boneindx = 0;
                if (vis.Names != null)
                {
                    foreach (string nm in vis.Names) //Loop through every bone. Not all have base and curve data
                    {
                        Animation.KeyNode bone = new Animation.KeyNode("");
                        a.Bones.Add(bone);
                        bone.Text = vis.Names[boneindx];



                        if (boneindx < vis.BaseDataList.Length)
                        {
                            bool bas = vis.BaseDataList[boneindx];

                            if (bas == true)
                            {
                                bone.XSCA.Keys.Add(new Animation.KeyFrame()
                                {
                                    Frame = 0, Value = 1
                                });
                                bone.YSCA.Keys.Add(new Animation.KeyFrame()
                                {
                                    Frame = 0, Value = 1
                                });
                                bone.ZSCA.Keys.Add(new Animation.KeyFrame()
                                {
                                    Frame = 0, Value = 1
                                });
                            }
                            else
                            {
                                bone.XSCA.Keys.Add(new Animation.KeyFrame()
                                {
                                    Frame = 0, Value = 0
                                });
                                bone.YSCA.Keys.Add(new Animation.KeyFrame()
                                {
                                    Frame = 0, Value = 0
                                });
                                bone.ZSCA.Keys.Add(new Animation.KeyFrame()
                                {
                                    Frame = 0, Value = 0
                                });
                            }
                        }


                        if (vis.Curves.Count != 0)
                        {
                            if (boneindx < vis.Curves.Count)
                            {
                                Syroot.NintenTools.NSW.Bfres.AnimCurve cr = vis.Curves[boneindx];

                                Console.WriteLine($"{vis.Name} {vis.Names[boneindx]}");

                                int frm = 0;
                                foreach (bool bn in cr.KeyStepBoolData)
                                {
                                    Animation.KeyFrame frame = new Animation.KeyFrame();
                                    frame.InterType = Animation.InterpolationType.STEP;
                                    frame.Frame     = cr.Frames[frm];



                                    Console.WriteLine(vis.Name + " " + vis.Names[boneindx] + " " + bn);

                                    switch (bn)
                                    {
                                    case true:
                                        frame.Value = 1; bone.XSCA.Keys.Add(frame);
                                        frame.Value = 1; bone.YSCA.Keys.Add(frame);
                                        frame.Value = 1; bone.ZSCA.Keys.Add(frame);
                                        break;

                                    case false:
                                        frame.Value = 0; bone.XSCA.Keys.Add(frame);
                                        frame.Value = 0; bone.YSCA.Keys.Add(frame);
                                        frame.Value = 0; bone.ZSCA.Keys.Add(frame);
                                        break;
                                    }
                                    frm++;
                                }
                            }
                        }

                        boneindx++;
                    }
                }
            }
            return(ThisAnimation);
        }