예제 #1
0
        static void ConvertPlatform(string fileName)
        {
            ResFile resFile = new ResFile(fileName);

            resFile.Save($"{fileName}.new.bfres");

            resFile.ChangePlatform(true, 4096, 0, 5, 0, 3);
            resFile.Save($"{fileName}.newNX.bfres");
        }
        static void SaveCompressedResFile(ResFile resFile, string path)
        {
            var mem = new MemoryStream();

            resFile.Save(mem);
            File.WriteAllBytes(path, YAZ0.Compress(mem.ToArray()));
        }
예제 #3
0
        public static void BatchCreateTextures(string filePath)
        {
            Console.WriteLine("filePath " + filePath);

            ResFile resFile = new ResFile();

            Bitmap image = new Bitmap(filePath);
            var    data  = BitmapExtension.ImageToByte(image);

            BitmapExtension.ConvertBgraToRgba(data);

            string name = Path.GetFileNameWithoutExtension(filePath);

            resFile.Name = $"{name}.sbitemico";
            var tex = AddTexture(name, data, image.Width, image.Height, 1, GX2SurfaceFormat.TCS_R8_G8_B8_A8_SRGB);

            resFile.Textures.Add(tex.Name, tex);
            resFile.Alignment     = 2048;
            resFile.VersionMajor  = 4;
            resFile.VersionMajor2 = 5;
            resFile.VersionMinor  = 0;
            resFile.VersionMinor2 = 3;

            if (!Directory.Exists("output"))
            {
                Directory.CreateDirectory("output");
            }

            var mem = new MemoryStream();

            resFile.Save(mem);
            var comp = EveryFileExplorer.YAZ0.Compress(mem.ToArray());

            File.WriteAllBytes($"output/{name}.sbitemico", comp);
        }
예제 #4
0
        private static void Chr0Convert(string[] args)
        {
            string openbfres = "";

            if (args.Length > 0)
            {
                openbfres = args[0];
            }
            else
            {
                openbfres = "dv_Kaigan_Original.bfres";
            }

            Console.WriteLine($"Loading bfres {openbfres}");
            ResFile resFile = new ResFile(openbfres);

            resFile.Textures[0].Export("dummy.bftex", resFile);

            Chr02Fska(CHR0Node.FromFile("walk.chr0"));

            Console.WriteLine($"Saving bfres");
            resFile.Save($"{openbfres}NEW.bfres");
            Console.WriteLine($"File Saved!");
            Console.Read();
        }
예제 #5
0
        public static byte[] CreateNewBFRES(string Name)
        {
            MemoryStream mem = new MemoryStream();

            ResFile resFile = new ResFile();

            resFile.Name = Name;

            resFile.Save(mem);
            var data = mem.ToArray();

            mem.Close();
            mem.Dispose();
            return(data);
        }
예제 #6
0
        public void GenerateBinary(FileSettings settings, string[] args)
        {
            ResFile resFile = new ResFile();
            string  output  = "";
            string  input   = "";

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == "-i" || args[i] == "--input")
                {
                    input = args[i + 1];
                }
                if (args[i] == "-o" || args[i] == "--output")
                {
                    output = args[i + 1];
                }
            }

            if (input == string.Empty)
            {
                Console.WriteLine("Must have an input (-i) file path");
                return;
            }
            if (output == string.Empty)
            {
                Console.WriteLine("Must have an output (-o) file path");
                return;
            }

            STGenericScene scene = new STGenericScene();

            string ext = Path.GetExtension(input);

            switch (ext)
            {
            case ".dae":
                scene = Collada.ColladaReader.Read(input);
                break;

            case ".fbx":
                break;
            }

            ConvertScene(resFile, scene);
            resFile.Save(output);
        }
예제 #7
0
        static void Main(string[] args)
        {
            ResFile animFile = new ResFile("JugemObj.bfres");

            animFile.Save("JugemObjRB.bfres");
            return;

            ResFile resFile = new ResFile(args[0]);

            string folder = Path.GetFileNameWithoutExtension(args[0]);

            foreach (var model in resFile.Models.Values)
            {
                if (!Directory.Exists($"{folder}/Models/{model.Name}"))
                {
                    Directory.CreateDirectory($"{folder}/Models/{model.Name}");
                }

                foreach (var mat in model.Materials.Values)
                {
                    File.WriteAllText($"{folder}/Models/{model.Name}/{mat.Name}.json", MaterialConvert.ToJson(mat));
                }
            }

/*
 *          string targetFileWiiU = "test.bfres";
 *
 *
 *          ResFile resFile = new ResFile(targetFileWiiU);
 *          resFile.Models[0].Export("ModelU.bfmdl", resFile);
 *          resFile.Save($"{targetFileWiiU}.new.bfres");
 *
 *          //Platform switch, alignment, version
 *          resFile.ChangePlatform(true, 4096, 0, 5, 0, 3);
 *          resFile.Save("newNX.bfres");
 *
 *          //Section export/import test
 *          //Swap a switch model with a wii u one
 *          resFile.Models[0].Export("ModelNX.bfmdl", resFile);
 *          resFile.Models[0].Import("ModelU.bfmdl", resFile);
 *
 *          //Platform wii u, alignment, version
 *          resFile.ChangePlatform(false, 8192, 3, 4, 0, 4);
 *          resFile.Save("newU.bfres");*/
        }
예제 #8
0
        static void Main(string[] args)
        {
            Console.WriteLine($"\n> BFRES Injector v2.0a\n" +
                              "> Made by SMB123W64GB\n" +
                              "> Using Syroot.NintenTools.Bfres API\n" +
                              "> *.bfres *.obj/*.smd\n");

            ResFile TargetBFRES = new ResFile(args[0]);
            MeshObj test        = new MeshObj();

            test.ReadObj(args[1]);
            test.InjectMesh(TargetBFRES.Models[0], TargetBFRES.ByteOrder);
            TargetBFRES.Models[0].Materials[0].RenderState.PolygonControl.CullBack           = false;
            TargetBFRES.Models[0].Materials[0].RenderState.PolygonControl.CullFront          = false;
            TargetBFRES.Models[0].Materials[0].RenderState.PolygonControl.PolygonModeEnabled = true;
            TargetBFRES.Name = "A_Cool_Mesh";
            Console.WriteLine("Writing {0}", args[0] + ".new.bfres");
            TargetBFRES.Save(args[0] + ".new.bfres");
        }
예제 #9
0
        static void Main(string[] args)
        {
            startTime   = DateTime.Now;
            targetBFRES = new ResFile("Player_Animation.bfres");
            targetBFRES.SkeletalAnims[0].Export("AFile.yaml", targetBFRES);

            TimeSpan timeElapsed = DateTime.Now - startTime;

            Console.WriteLine($" Loaded BFRES in { timeElapsed.TotalSeconds.ToString("0.000")}");

            startTime = DateTime.Now;
            targetBFRES.Save("NewTest.bfres");
            timeElapsed = DateTime.Now - startTime;
            Console.WriteLine($" Saved BFRES in { timeElapsed.TotalSeconds.ToString("0.000")}");

            //     ParseYML("course_muunt.byaml");

            Console.Read();
        }
예제 #10
0
        public Stream Save()
        {
            //Reload the model data
            Model.Shapes.Clear();
            Model.VertexBuffers.Clear();
            Model.Materials.Clear();
            Model.Skeleton.Bones.Clear();
            //Create a dummy root bone automatically
            Model.Skeleton.Bones.Add("dummy_area", new Bone()
            {
                Name        = "dummy_area",
                ParentIndex = -1,
                Position    = new Syroot.Maths.Vector3F(),
                Scale       = new Syroot.Maths.Vector3F(1, 1, 1),
                Rotation    = new Syroot.Maths.Vector4F(0, 0, 0, 1),
            });
            //Fill the resource with the object data.
            foreach (var obj in Objects)
            {
                Model.Shapes.Add(obj.MeshData.Name, obj.MeshData);
                Model.VertexBuffers.Add(obj.VertexData);
                if (!Model.Materials.ContainsKey(obj.MaterialData.Name))
                {
                    Model.Materials.Add(obj.MaterialData.Name, obj.MaterialData);
                }
                if (!Model.Skeleton.Bones.ContainsKey(obj.TransformData.Name))
                {
                    Model.Skeleton.Bones.Add(obj.TransformData.Name, obj.TransformData);
                }
            }

            var mem = new MemoryStream();

            ResFile.Save(mem);
            return(mem);
        }
예제 #11
0
 public void Save(Stream stream)
 {
     SaveWrappers();
     ResFile.Save(stream);
 }
예제 #12
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Supported Games :");
                Console.WriteLine("    Breath Of The Wild (Wii U => Switch)");
                Console.WriteLine("Arguments :");
                Console.WriteLine("     BfresPlatformConverter.exe file.bfres");
                return;
            }

            if (!Directory.Exists("SwitchConverted"))
            {
                Directory.CreateDirectory("SwitchConverted");
            }
            if (!Directory.Exists("WiiUConverted"))
            {
                Directory.CreateDirectory("WiiUConverted");
            }

            string externalShader = "Turbo_UBER.bfsha";

            foreach (var arg in args)
            {
                string name = Path.GetFileNameWithoutExtension(arg);
                string ext  = Path.GetExtension(arg);

                if (arg.Contains(".Tex2"))
                {
                    continue;
                }

                bool compressed = IsCompressed(arg);

                ResFile resFile = LoadBFRES(arg, compressed);
                if (arg.Contains(".Tex1") && resFile.Textures.Values.Max(x => x.MipCount > 1))
                {
                    //Load tex2 mip maps
                    string tex2File = arg.Replace("Tex1", "Tex2");
                    if (!File.Exists(tex2File))
                    {
                        Console.WriteLine("Cannot find Tex2 file for mipmap data! Skipping...");
                        continue;
                    }

                    var resFileTex2 = LoadBFRES(tex2File, compressed);
                    foreach (var tex in resFileTex2.Textures.Values)
                    {
                        ((Texture)resFile.Textures[tex.Name]).MipSwizzle = ((Texture)tex).Swizzle;
                        ((Texture)resFile.Textures[tex.Name]).MipData    = ((Texture)tex).MipData;
                    }
                    name         = name.Replace("Tex1", "Tex");
                    resFile.Name = name;
                }

                int alignment = 256;
                if (arg.Contains(".tex"))
                {
                    alignment = 4096;
                }

                //Change the platform.
                if (!resFile.IsPlatformSwitch)
                {
                    resFile.ChangePlatform(true, 4096, 0, 5, 0, 3, ConverterHandle.BOTW);
                    resFile.Alignment = 0x0C;

                    if (File.Exists(externalShader))
                    {
                        resFile.ExternalFiles.Add("Turbo_UBER.bfsha", new ExternalFile()
                        {
                            Data = File.ReadAllBytes(externalShader)
                        });
                    }

                    if (compressed)
                    {
                        SaveCompressedResFile(resFile, $"SwitchConverted/{name}{ext}");
                    }
                    else
                    {
                        resFile.Save($"SwitchConverted/{name}{ext}");
                    }
                }
                else
                {
                    resFile.ChangePlatform(false, alignment, 4, 5, 0, 3, ConverterHandle.BOTW);

                    if (compressed)
                    {
                        SaveCompressedResFile(resFile, $"SwitchConverted/{name}{ext}");
                    }
                    else
                    {
                        resFile.Save($"WiiUConverted/{name}{ext}");
                    }
                }
            }
        }
예제 #13
0
        static void Main(string[] args)
        {
            ResFile resFile = new ResFile();

            resFile.Save("NewFile.bfres");
        }
예제 #14
0
 private void button5_Click(object sender, EventArgs e)
 {
     if (MaterialList.Count != 0)
     {
         OpenFileDialog ofd = new OpenFileDialog();
         ofd.Filter = "Bfres File | *.bfres";
         ofd.Title  = "Select the bfres you imported the model into";
         if (ofd.ShowDialog() == DialogResult.OK)
         {
             ResFile resFile = new ResFile(ofd.FileName);
             ByteArrayToFile("Material.bfres", Resources.Material);
             ResFile matres     = new ResFile("Material.bfres");
             int     loopNumber = 0;
             int     loop       = 0;
             foreach (Model model in resFile.Models.Values)
             {
                 foreach (string str in MaterialList.Values)
                 {
                     resFile.Models[loop].Materials[loopNumber].Flags           = matres.Models[0].Materials[1].Flags;
                     resFile.Models[loop].Materials[loopNumber].RenderInfos     = matres.Models[0].Materials[1].RenderInfos;
                     resFile.Models[loop].Materials[loopNumber].RenderState     = matres.Models[0].Materials[1].RenderState;
                     resFile.Models[loop].Materials[loopNumber].Samplers        = matres.Models[0].Materials[1].Samplers;
                     resFile.Models[loop].Materials[loopNumber].ShaderAssign    = matres.Models[0].Materials[1].ShaderAssign;
                     resFile.Models[loop].Materials[loopNumber].ShaderParamData = matres.Models[0].Materials[1].ShaderParamData;
                     resFile.Models[loop].Materials[loopNumber].ShaderParams    = matres.Models[0].Materials[1].ShaderParams;
                     resFile.Models[loop].Materials[loopNumber].UserData        = matres.Models[0].Materials[1].UserData;
                     resFile.Models[loop].Materials[loopNumber].VolatileFlags   = matres.Models[0].Materials[1].VolatileFlags;
                     resFile.Models[loop].Materials[loopNumber].TextureRefs     = DeepClone(matres.Models[0].Materials[1].TextureRefs);
                     if (comboBox1.SelectedIndex == 0)
                     {
                         Syroot.NintenTools.Bfres.GX2.PolygonControl polygon = resFile.Models[loop].Materials[loopNumber].RenderState.PolygonControl;
                         polygon.CullBack  = false;
                         polygon.CullFront = false;
                         resFile.Models[loop].Materials[loopNumber].RenderState.PolygonControl = polygon;
                     }
                     if (comboBox1.SelectedIndex == 1)
                     {
                         Syroot.NintenTools.Bfres.GX2.PolygonControl polygon = resFile.Models[loop].Materials[loopNumber].RenderState.PolygonControl;
                         polygon.CullBack  = true;
                         polygon.CullFront = false;
                         resFile.Models[loop].Materials[loopNumber].RenderState.PolygonControl = polygon;
                     }
                     if (comboBox1.SelectedIndex == 2)
                     {
                         Syroot.NintenTools.Bfres.GX2.PolygonControl polygon = resFile.Models[loop].Materials[loopNumber].RenderState.PolygonControl;
                         polygon.CullBack  = false;
                         polygon.CullFront = true;
                         resFile.Models[loop].Materials[loopNumber].RenderState.PolygonControl = polygon;
                     }
                     string str2 = "_alb";
                     Diffuse.TryGetValue(MaterialList[resFile.Models[loop].Materials[loopNumber].Name], out str2);
                     if (str2 == null)
                     {
                         str2 = "_alb";
                     }
                     resFile.Models[loop].Materials[loopNumber].TextureRefs[0].Name = str2;
                     string str3 = "_nrm";
                     Normal.TryGetValue(MaterialList[resFile.Models[loop].Materials[loopNumber].Name], out str3);
                     if (str3 == null)
                     {
                         if (str2 != "_alb")
                         {
                             if (str2.Contains("_alb"))
                             {
                                 str3 = str2.Replace("_alb", "_nrm");
                             }
                             else
                             {
                                 str3 = str2 + "_nrm";
                             }
                         }
                     }
                     resFile.Models[loop].Materials[loopNumber].TextureRefs[1].Name = str3;
                     string str4 = "_spc";
                     Specular.TryGetValue(MaterialList[resFile.Models[loop].Materials[loopNumber].Name], out str4);
                     if (str4 == null)
                     {
                         if (str2 != "_alb")
                         {
                             if (str2.Contains("_alb"))
                             {
                                 str4 = str2.Replace("_alb", "_spc");
                             }
                             else
                             {
                                 str4 = str2 + "_spc";
                             }
                         }
                     }
                     resFile.Models[loop].Materials[loopNumber].TextureRefs[2].Name = str4;
                     loopNumber++;
                 }
                 loop++;
             }
             SaveFileDialog sfd = new SaveFileDialog();
             sfd.Filter = "Bfres File | *.bfres";
             sfd.Title  = "Where do you want to export the bfres?";
             if (sfd.ShowDialog() == DialogResult.OK)
             {
                 resFile.Save(sfd.FileName);
                 MessageBox.Show("Saved to " + sfd.FileName + "!");
                 File.Delete("Material.Bfres");
             }
         }
     }
 }