Esempio n. 1
0
        public static void WriteExternalFiles(ResFile resFile, TreeNode EditorRoot)
        {
            resFile.ExternalFiles.Clear();
            if (EditorRoot.Nodes.ContainsKey("EXT"))
            {
                foreach (TreeNode node in EditorRoot.Nodes["EXT"].Nodes)
                {
                    ExternalFile ext = new ExternalFile();
                    if (node is BNTX)
                    {
                        ext.Data = ((BNTX)node).Save();
                    }
                    else
                    {
                        ext.Data = ((ExternalFileData)node).Data;
                    }

                    resFile.ExternalFiles.Add(node.Text, ext);
                }
            }
        }
Esempio n. 2
0
 private static void DumpVertexCountInfo(ResFile resFile)
 {
     foreach (Model model in resFile.Models.Values)
     {
         int totalElementCount = 0;
         foreach (VertexBuffer vertexBuffer in model.VertexBuffers)
         {
             Buffer firstBuffer  = vertexBuffer.Buffers[0];
             int    elementCount = firstBuffer.Data[0].Length / firstBuffer.Stride;
             Console.WriteLine(String.Format("\tVertexBuffer {0} {1} {2}",
                                             vertexBuffer.VertexCount,
                                             vertexBuffer.VertexCount == elementCount ? "==" : "!=",
                                             elementCount));
             totalElementCount += elementCount;
         }
         Console.WriteLine(String.Format("\tModel {0} {1} {2}",
                                         model.TotalVertexCount,
                                         model.TotalVertexCount == totalElementCount ? "==" : "!=",
                                         totalElementCount));
     }
 }
Esempio n. 3
0
        private void ReadImportedFileHeader()
        {
            this.ByteOrder = ByteOrder.BigEndian;

            Seek(8, SeekOrigin.Begin); //SUB MAGIC
            ResFile.Version = ReadUInt32();
            ResFile.SetVersionInfo(ResFile.Version);

            string sectionMagic = ReadString(8, Encoding.ASCII);
            uint   offset       = ReadUInt32();
            uint   platformFlag = ReadUInt32();

            ReadUInt32();
            this.ByteOrder = ByteOrder.BigEndian;

            if (platformFlag != 0)
            {
                Seek(0x30, SeekOrigin.Begin);
                this.ByteOrder = ByteOrder.LittleEndian;
            }
        }
        public static void Read(BFRESRender renderer, ResFile resFile, TreeNode ResFileNode)
        {
            int CurMdl = 0;

            foreach (Model mdl in resFile.Models)
            {
                FMDL model = new FMDL();
                model.Text     = mdl.Name;
                model.Skeleton = new FSKL(mdl.Skeleton);
                model.Nodes.Add(model.Skeleton.node);
                model.Skeleton.reset();
                model.Skeleton.update();
                model.Skeleton.node.BFRESRender = renderer;
                model.Model = mdl;
                foreach (Material mat in mdl.Materials)
                {
                    FMAT FMAT = new FMAT();
                    FMAT.Text = mat.Name;
                    FMAT.ReadMaterial(mat);
                    model.Nodes[1].Nodes.Add(FMAT);
                    model.materials.Add(FMAT.Text, FMAT);
                }
                foreach (Shape shp in mdl.Shapes)
                {
                    VertexBuffer vertexBuffer = mdl.VertexBuffers[shp.VertexBufferIndex];
                    Material     material     = mdl.Materials[shp.MaterialIndex];
                    FSHP         mesh         = new FSHP();
                    mesh.ModelIndex = CurMdl;
                    ReadShapesVertices(mesh, shp, vertexBuffer, model);
                    mesh.MaterialIndex = shp.MaterialIndex;

                    model.Nodes[0].Nodes.Add(mesh);
                    model.shapes.Add(mesh);
                }
                ResFileNode.Nodes[0].Nodes.Add(model);
                renderer.models.Add(model);

                CurMdl++;
            }
        }
Esempio n. 5
0
        static Texture GetTexture(string path, ResFile file)
        {
            var basename = Path.GetFileName(path);

            if (file.ExternalFiles.Count() > 1)
            {
                Console.WriteLine($"[SKIP] {basename} - contains multiple external files");
                return(null);
            }
            try
            {
                using (var bntxStream = file.ExternalFiles.First().GetStream())
                {
                    var bntxFile = new BntxFile(bntxStream);
                    if (bntxFile.Textures.Count != 1)
                    {
                        Console.WriteLine($"[SKIP] {basename} - contains {bntxFile.Textures.Count} textures");
                        return(null);
                    }
                    var texture = bntxFile.Textures.First();
                    if (IsTextureDecodable(texture))
                    {
                        return(texture);
                    }

                    if (TextureFormatInfo.FormatTable.ContainsKey(texture.Format))
                    {
                        Console.WriteLine($"[SKIP] {basename} - unhandled texture format {texture.Format}");
                        return(null);
                    }

                    Console.WriteLine($"[SKIP] {basename} - unknown texture format {texture.Format}");
                    return(null);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
Esempio n. 6
0
        public bool getFile(string dir, out ResFile result)
        {
            result = null;
            if (!dir.StartsWith("/"))
            {
                return(false);
            }

            string[] dirs = dir.Split('/');

            ResDirectory resDir = baseDir;

            for (int level = 1; level < dirs.Length - 1; ++level)
            {
                if (!baseDir.getChildDir(out resDir, dirs[level]))
                {
                    return(false);
                }
            }

            return(resDir.getChildFile(out result, dirs[dirs.Length - 1]));
        }
Esempio n. 7
0
            public void Read(ResFile b, AnimationGroupNode ThisAnimation, ModelContainer modelContainer)
            {
                Console.WriteLine("Reading Shape Animations ...");

                TreeNode ShapeAnimation = new TreeNode()
                {
                    Text = "Shape Animations"
                };

                ThisAnimation.Nodes.Add(ShapeAnimation);

                int i = 0;

                foreach (ShapeAnim fsha in b.ShapeAnims)
                {
                    modelContainer.BFRES_MTA = new BFRES.MTA();

                    PerShapeAnim perAnim = new PerShapeAnim(modelContainer.BFRES_MTA, fsha);

                    ShapeAnimation.Nodes.Add(modelContainer.BFRES_MTA);
                }
            }
Esempio n. 8
0
        static internal void ImportSection(Stream stream, IResData resData, ResFile resFile)
        {
            bool platformSwitch = false;

            using (var reader = new BinaryDataReader(stream, true)) {
                reader.Seek(24, SeekOrigin.Begin);
                platformSwitch = reader.ReadUInt32() != 0;
            }

            if (platformSwitch)
            {
                using (var reader = new Switch.Core.ResFileSwitchLoader(resData, resFile, stream)) {
                    reader.ImportSection();
                }
            }
            else
            {
                using (var reader = new WiiU.Core.ResFileWiiULoader(resData, resFile, stream)) {
                    reader.ImportSection();
                }
            }
        }
            public CachedModel(ResFile bfres, string textureArc)
            {
                if (LoadTextures && textureArc != null && File.Exists(Program.TryGetPathViaProject("ObjectData", textureArc + ".szs")))
                {
                    SarcData objArc = SARC.UnpackRamN(YAZ0.Decompress(Program.TryGetPathViaProject("ObjectData", textureArc + ".szs")));

                    if (!texArcCache.ContainsKey(textureArc))
                    {
                        Dictionary <string, int> arc = new Dictionary <string, int>();
                        texArcCache.Add(textureArc, arc);
                        foreach (KeyValuePair <string, TextureShared> textureEntry in new ResFile(new MemoryStream(objArc.Files[textureArc + ".bfres"])).Textures)
                        {
                            arc.Add(textureEntry.Key, UploadTexture(textureEntry.Value));
                        }
                    }
                }

                Model mdl = bfres.Models[0];

                vaos = new VertexArrayObject[mdl.Shapes.Count];
                indexBufferLengths = new int[mdl.Shapes.Count];
                textures           = new int[mdl.Shapes.Count];
                wrapModes          = new (int, int)[mdl.Shapes.Count];
Esempio n. 10
0
        private static void ComputeIndices(ResFile resFile)
        {
            foreach (Model model in resFile.Models.Values)
            {
                foreach (Shape shape in model.Shapes.Values)
                {
                    foreach (Mesh mesh in shape.Meshes)
                    {
                        uint[] indices = mesh.GetIndices().ToArray();
                        mesh.SetIndices(indices);

                        uint[] newIndices = mesh.GetIndices().ToArray();
                        for (int i = 0; i < indices.Length; i++)
                        {
                            if (indices[i] != newIndices[i])
                            {
                                Console.WriteLine($"Failure {mesh.IndexFormat}");
                            }
                        }
                    }
                }
            }
        }
Esempio n. 11
0
        public void Replace(string FileName, ResFile resFile)
        {
            string ext = Utils.GetExtension(FileName);

            if (ext == ".bftxp")
            {
                bool IsSwitch = BfresUtilies.IsSubSectionSwitch(FileName);
                if (IsSwitch)
                {
                    var fmaa = new Syroot.NintenTools.NSW.Bfres.MaterialAnim();
                    fmaa.Import(FileName);
                    TexPatternAnim = BfresPlatformConverter.FTXPConvertSwitchToWiiU(fmaa);
                }
                else
                {
                    TexPatternAnim.Import(FileName, resFile);
                }

                TexPatternAnim.Name = Text;
                LoadAnim(TexPatternAnim);
            }
            else if (ext == ".yaml")
            {
                var fmaa = new Syroot.NintenTools.NSW.Bfres.MaterialAnim();
                fmaa                = YamlFmaa.FromYaml(FileName);
                TexPatternAnim      = BfresPlatformConverter.FTXPConvertSwitchToWiiU(fmaa);
                TexPatternAnim.Name = Text;
                LoadAnim(TexPatternAnim);
            }
            else if (ext == ".gif")
            {
                BFRESGroupNode ftexFolder         = PluginRuntime.ftexContainers[0];
                GifToTexturePatternAnimation anim = new GifToTexturePatternAnimation(FileName, ftexFolder, this);
                TexPatternAnim.Name = Text;
                LoadAnim(TexPatternAnim);
            }
        }
Esempio n. 12
0
 private static void TestVertexAttribFormat(ResFile resFile)
 {
     foreach (Model model in resFile.Models.Values)
     {
         int vertexBufferIndex = 0;
         foreach (VertexBuffer vertexBuffer in model.VertexBuffers)
         {
             Console.WriteLine($"\tVertexBuffer {vertexBufferIndex}");
             VertexBufferHelper helper = new VertexBufferHelper(vertexBuffer, resFile.ByteOrder);
             foreach (VertexBufferHelperAttrib attrib in helper.Attributes)
             {
                 IList <Vector4F> elements;
                 using (MemoryStream stream = new MemoryStream())
                 {
                     using (BinaryDataWriter writer = new BinaryDataWriter(stream, true))
                     {
                         writer.Write(attrib.Data, attrib.Format);
                     }
                     stream.Position = 0;
                     using (BinaryDataReader reader = new BinaryDataReader(stream, true))
                     {
                         elements = reader.ReadGX2Attribs(attrib.Data.Length, attrib.Format);
                     }
                 }
                 for (int i = 0; i < elements.Count; i++)
                 {
                     if (elements[i] != attrib.Data[i])
                     {
                         Console.WriteLine($"\t\tError {attrib.Name} {attrib.Format}");
                         break;
                     }
                 }
             }
             vertexBufferIndex++;
         }
     }
 }
Esempio n. 13
0
        public void Replace(string FileName, ResFile resFileNX, ResU.ResFile resFileU)
        {
            string ext = Utils.GetExtension(FileName);

            if (ext == ".bfska")
            {
                if (GetResFileU() != null)
                {
                    SkeletalAnimU.Import(FileName, GetResFileU());
                    SkeletalAnimU.Name = Text;
                    LoadAnim(SkeletalAnimU);
                }
                else
                {
                    SkeletalAnim.Import(FileName);
                    SkeletalAnim.Name = Text;
                    LoadAnim(SkeletalAnim);
                }
            }
            else if (ext == ".seanim")
            {
                FromSeanim(FileName);
            }
        }
Esempio n. 14
0
        public void Replace(string FileName, ResFile resFile)
        {
            ShaderParamAnim = new ShaderParamAnim();

            string ext = Utils.GetExtension(FileName);

            if (ext == ".bfshu")
            {
                ShaderParamAnim.Import(FileName, resFile, ShaderParamAnimType.ShaderParameter);
                LoadAnim(ShaderParamAnim, AnimationType.ShaderParam);
            }
            if (ext == ".bfcsh")
            {
                ShaderParamAnim.Import(FileName, resFile, ShaderParamAnimType.Color);
                LoadAnim(ShaderParamAnim, AnimationType.Color);
            }
            if (ext == ".bftxp")
            {
                ShaderParamAnim.Import(FileName, resFile, ShaderParamAnimType.TextureSRT);
                LoadAnim(ShaderParamAnim, AnimationType.TexturePattern);
            }

            ShaderParamAnim.Name = Text;
        }
Esempio n. 15
0
 public static void Save(ResFileWiiUSaver saver, ResFile resFile)
 {
     saver.WriteSignature("FRES");
     saver.Write(resFile.Version);
     saver.Write(resFile.ByteOrder, true);
     saver.Write((ushort)0x0010); // SizHeader
     saver.SaveFieldFileSize();
     saver.Write(resFile.Alignment);
     saver.SaveString(resFile.Name);
     saver.SaveFieldStringPool();
     saver.SaveDict(resFile.Models);
     saver.SaveDict(resFile.Textures);
     resFile.SkeletonAnimationOffset = saver.SaveOffsetPos();
     saver.SaveDict(resFile.ShaderParamAnims);
     saver.SaveDict(resFile.ColorAnims);
     saver.SaveDict(resFile.TexSrtAnims);
     saver.SaveDict(resFile.TexPatternAnims);
     saver.SaveDict(resFile.BoneVisibilityAnims);
     saver.SaveDict(resFile.MatVisibilityAnims);
     saver.SaveDict(resFile.ShapeAnims);
     saver.SaveDict(resFile.SceneAnims);
     saver.SaveDict(resFile.ExternalFiles);
     saver.Write((ushort)resFile.Models.Count);
     saver.Write((ushort)resFile.Textures.Count);
     saver.Write((ushort)resFile.SkeletalAnims.Count);
     saver.Write((ushort)resFile.ShaderParamAnims.Count);
     saver.Write((ushort)resFile.ColorAnims.Count);
     saver.Write((ushort)resFile.TexSrtAnims.Count);
     saver.Write((ushort)resFile.TexPatternAnims.Count);
     saver.Write((ushort)resFile.BoneVisibilityAnims.Count);
     saver.Write((ushort)resFile.MatVisibilityAnims.Count);
     saver.Write((ushort)resFile.ShapeAnims.Count);
     saver.Write((ushort)resFile.SceneAnims.Count);
     saver.Write((ushort)resFile.ExternalFiles.Count);
     saver.Write(0); // UserPointer
 }
Esempio n. 16
0
            public void Read(ResFile b, AnimationGroupNode ThisAnimation, ModelContainer modelContainer)
            {
                TreeNode TexAnimation = new TreeNode()
                {
                    Text = "Textue Pattern Animations"
                };

                ThisAnimation.Nodes.Add(TexAnimation);

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

                foreach (TexPatternAnim tex in b.TexPatternAnims.Values)
                {
                    modelContainer.BFRES_MTA = new MTA();

                    BFRES_FVTX FVTX = new BFRES_FVTX(modelContainer.BFRES_MTA, tex, b);


                    TexAnimation.Nodes.Add(modelContainer.BFRES_MTA);
                }
            }
Esempio n. 17
0
 public SifManager(ResFile asset, MaterialManager materialManager)
 {
     _asset           = asset;
     _materialManager = materialManager;
 }
Esempio n. 18
0
            public BFRES_FVTX(BFRES.MTA mta, TexPatternAnim tex, ResFile b)
            {
                mta.Text = tex.Name;

                mta.FrameCount = (uint)tex.FrameCount;


                if (tex.TextureRefs != null || tex.TextureRefNames != null)
                {
                    if (b.Version >= 0x03040000)
                    {
                        foreach (var tx in tex.TextureRefs)
                        {
                            mta.Pat0.Add(tx.Key);
                        }
                    }
                    else
                    {
                        foreach (var tx in tex.TextureRefNames)
                        {
                            mta.Pat0.Add(tx.Name);
                            //Console.WriteLine(tx.Name);
                        }
                    }
                }

                foreach (TexPatternMatAnim matanim in tex.TexPatternMatAnims)
                {
                    BFRES.MatAnimEntry mat = new BFRES.MatAnimEntry();

                    mat.Text = matanim.Name;
                    //Console.WriteLine($"MatAnim = {mat.Text}");
                    //Console.WriteLine($"Curve Count = {matanim.Curves.Count}");

                    if (matanim.Curves.Count == 0)
                    {
                        int CurTex = 0;
                        foreach (PatternAnimInfo inf in matanim.PatternAnimInfos)
                        {
                            if (tex.TextureRefs != null || tex.TextureRefNames != null)
                            {
                                BFRES.MatAnimData md = new BFRES.MatAnimData();

                                md.Pat0Tex     = mta.Pat0[CurTex];
                                md.SamplerName = inf.Name;
                                md.Frame       = 0;

                                mat.matCurves.Add(md);
                            }
                            CurTex++;
                        }
                    }

                    int CurCurve = 0;
                    foreach (AnimCurve cr in matanim.Curves)
                    {
                        for (int i = 0; i < (ushort)cr.Frames.Length; i++)
                        {
                            BFRES.MatAnimData md = new BFRES.MatAnimData();

                            foreach (PatternAnimInfo inf in matanim.PatternAnimInfos)
                            {
                                if (inf.CurveIndex == CurCurve)
                                {
                                    md.SamplerName = inf.Name;
                                }
                            }

                            if (tex.TextureRefs != null || tex.TextureRefNames != null)
                            {
                                if (cr.KeyType == AnimCurveKeyType.SByte)
                                {
                                    md.CurveIndex = CurCurve;

                                    if (cr.Scale != 0)
                                    {
                                        int   test = (int)cr.Keys[i, 0];
                                        float key  = cr.Offset + test * cr.Scale;
                                        md.Pat0Tex = (mta.Pat0[(int)key]);
                                        md.Frame   = (int)cr.Frames[i];
                                    }
                                    else
                                    {
                                        int test = (int)cr.Keys[i, 0];
                                        int key  = cr.Offset + test;
                                        md.Pat0Tex = (mta.Pat0[(int)key]);
                                        md.Frame   = (int)cr.Frames[i];
                                        //Console.WriteLine($"{md.Frame} {md.Pat0Tex}");
                                    }
                                }
                            }
                            mat.matCurves.Add(md);
                        }
                        CurCurve++;
                    }

                    foreach (BFRES.MatAnimData md in mat.matCurves)
                    {
                        //Console.WriteLine($"At frame {md.Frame} show {md.Pat0Tex} {md.SamplerName}");
                    }

                    mta.matEntries.Add(mat);
                }
            }
Esempio n. 19
0
        public void Replace(string FileName, ResFile resFileNX, ResU.ResFile resFileU)
        {
            string ext = Utils.GetExtension(FileName);

            if (ext == ".bfska")
            {
                bool IsSwitch = BfresUtilies.IsSubSectionSwitch(FileName);

                if (resFileU != null)
                {
                    //If it's a switch animation try to conver it to wii u
                    if (IsSwitch)
                    {
                        var ska = new SkeletalAnim();
                        ska.Import(FileName);
                        SkeletalAnimU      = BfresPlatformConverter.FSKAConvertSwitchToWiiU(ska);
                        SkeletalAnimU.Name = Text;
                        LoadAnim(SkeletalAnimU);
                    }
                    else
                    {
                        SkeletalAnimU.Import(FileName, resFileU);
                        SkeletalAnimU.Name = Text;
                        LoadAnim(SkeletalAnimU);
                    }
                }
                else
                {
                    if (IsSwitch)
                    {
                        SkeletalAnim.Import(FileName);
                        SkeletalAnim.Name = Text;
                        LoadAnim(SkeletalAnim);
                    }
                    else
                    {
                        //Create a new wii u skeletal anim and try to convert it instead
                        var ska = new ResU.SkeletalAnim();
                        ska.Import(FileName, new ResU.ResFile());
                        SkeletalAnim      = BfresPlatformConverter.FSKAConvertWiiUToSwitch(ska);
                        SkeletalAnim.Name = Text;
                        LoadAnim(SkeletalAnim);
                    }
                }
            }
            else if (ext == ".anim")
            {
                FromAnim(FileName);
            }
            else if (ext == ".seanim")
            {
                STSkeleton skeleton = GetActiveSkeleton();

                if (skeleton != null)
                {
                    var ska = FromGeneric(SEANIM.Read(FileName, skeleton));
                    ska.Loop = this.CanLoop;
                    UpdateAnimation(ska);
                }
                else
                {
                    STErrorDialog.Show("No matching skeleton bones found to assign!", "Skeleton Importer", "");
                }
            }
            else if (ext == ".smd")
            {
                STSkeleton skeleton = GetActiveSkeleton();

                if (skeleton != null)
                {
                    var ska = FromGeneric(SMD.Read(FileName, skeleton));
                    ska.Loop = this.CanLoop;
                    UpdateAnimation(ska);
                }
                else
                {
                    STErrorDialog.Show("No matching skeleton bones found to assign!", "Skeleton Importer", "");
                }
            }
            else if (ext == ".chr0")
            {
                FromChr0(FileName, resFileU != null);
            }
            else if (ext == ".dae")
            {
                //   FromAssimp(FileName, resFileU != null);
            }
            else if (ext == ".fbx")
            {
                //   FromAssimp(FileName, resFileU != null);
            }
        }
        /// <summary>
        /// Processes the given xcode project to add or change the supplied parameters
        /// </summary>
        /// <param name="xCodeProjFileName">filename of the Xcode project to change</param>
        /// <param name="frameworks">list of Apple standard frameworks to add to the project</param>
        /// <param name="resFiles">list resource files added to the project</param>
        private static void ProcessPbxProj(string xCodeProjFileName, Framework[] frameworks, ResFile[] resFiles)
        {
            // Open up the file generated by Unity and read into memory as a list of lines for processing
            var pbxprojFilename = Path.Combine(xCodeProjFileName, "project.pbxproj");
            var lines = File.ReadAllLines(pbxprojFilename);


            // Work out which of the resfiles exist and remove them if they don't, this
            // is because if using frame markers there may not be a qcar-resources.dat
            var newResFiles = new List<ResFile>();
            foreach (var rf in resFiles)
                if (Directory.Exists(Path.Combine(xCodeProjFileName, "../Data/Raw/" + rf.Name)))
                {
                    newResFiles.Add(rf);
                }
            resFiles = newResFiles.ToArray();

            // Next open up an empty project.pbxproj for writing and iterate over the old
            // file copying the original file and inserting anything extra we need
            var pbxproj = File.CreateText(pbxprojFilename);

            // As we iterate through the list we'll record which section of the
            // project.pbxproj we are currently in
            var section = "";

            // We use these booleans to decide whether we have already added the list of
            // build files to the link line.  This is needed because there could be multiple
            // build targets and they are not named in the project.pbxproj
            var frameworksBuildAdded = false;
            var resBuildAdded = false;

            // Build a list of the files already added to the project.  Then use it to
            // avoid adding anything to the project twice
            var existingFiles = ReadExistingFiles(lines);
            var filteredFrameworks = new List<Framework>();
            foreach (var framework in frameworks)
                if (!existingFiles.Contains(framework.Name))
                    filteredFrameworks.Add(framework);
            frameworks = filteredFrameworks.ToArray();

            var filteredResFiles = new List<ResFile>();
            foreach (var resFile in resFiles)
                if (!existingFiles.Contains(resFile.Name))
                    filteredResFiles.Add(resFile);
            resFiles = filteredResFiles.ToArray();



            // Now iterate through the project adding any new lines where needed
            for (int i = 0; i < lines.Length; i++)
            {
                var line = lines[i];
                pbxproj.WriteLine(line);

                // Each section starts with a comment such as
                // /* Begin PBXBuildFile section */"
                if (line.Length > 3 && line.Substring(3).StartsWith("Begin"))
                {
                    section = line.Split(' ')[2];
                    if (section == "PBXBuildFile")
                    {
                        foreach (var framework in frameworks)
                            AddBuildFile(pbxproj, framework);
                        foreach (var resfile in resFiles)
                            AddBuildFile(pbxproj, resfile);
                    }
                    if (
                        section == "PBXFileReference")
                    {
                        foreach (var framework in frameworks)
                            AddFrameworkFileReference(pbxproj, framework);
                        foreach (var resfile in resFiles)
                            AddResFileReference(pbxproj, resfile);
                    }
                }
                if (line.Length > 3 && line.Substring(3).StartsWith("End"))
                {
                    section = "";
                }

                if (section == "PBXFrameworksBuildPhase")
                {
                    if (line.Trim().StartsWith("files"))
                        if (!frameworksBuildAdded)
                            foreach (var framework in frameworks)
                            {
                                AddFrameworksBuildPhase(pbxproj, framework);
                                frameworksBuildAdded = true;
                            }
                }

                // The PBXResourcesBuildPhase section is what appears in XCode as "Link
                // Binary With Libraries".  As with the frameworks we make the assumption the
                // first target is always "Unity-iPhone" as the name of the target itself is
                // not listed in project.pbxproj
                if (section == "PBXResourcesBuildPhase")
                {
                    if (line.Trim().StartsWith("files"))
                        if (!resBuildAdded)
                            foreach (var resfile in resFiles)
                            {
                                AddResourcesBuildPhase(pbxproj, resfile);
                                resBuildAdded = true;
                            }
                }

                // The PBXGroup is the section that appears in XCode as "Copy Bundle Resources". 
                if (section == "PBXGroup")
                {
                    if (line.Trim().StartsWith("children") &&
                        (lines[i - 2].Trim().Split(' ')[2] == "CustomTemplate"))
                    {
                        foreach (var resfile in resFiles)
                            AddGroup(pbxproj, resfile);
                        foreach (var framework in frameworks)
                            AddGroup(pbxproj, framework);
                    }
                }

                // The PBXShellScriptBuildPhase appears in Xcode 4 as "Run Script", we need to delete the QCAR
                // directory from the app to avoid a duplicate copy
                if (section == "PBXShellScriptBuildPhase")
                {
                    if (line.Trim().StartsWith("shellScript"))
                    {
                        pbxproj.Flush(); 
                        pbxproj.BaseStream.Seek(-3, SeekOrigin.Current);
                        
                        pbxproj.WriteLine("\\nrm -rf \\\"$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Data/Raw/QCAR\\\"\";");
                    }
                }

                // change for Unity 4.2 because header search path needs to be in HEADER_SEARCH_PATHS group
                if (section == "XCBuildConfiguration")
                {
                    if (line.Trim().StartsWith("HEADER_SEARCH_PATHS = ("))
                        pbxproj.WriteLine("\t\t\t\t\t\"$(SRCROOT)/Libraries\",");
                }

                //add C++11 support by explicitly linking to libc++
                if (line.Trim().StartsWith("OTHER_LDFLAGS = ("))
                {
                    pbxproj.WriteLine("\t\t\t\t\t\"-lc++\",");
                }

            }
            pbxproj.Close();
        }
Esempio n. 21
0
 internal ResFileWiiULoader(IResData resData, ResFile resFile, string fileName)
     : base(resData, resFile, fileName)
 {
     ByteOrder = ByteOrder.BigEndian;
 }
Esempio n. 22
0
 public void Save(Stream stream)
 {
     SaveWrappers();
     ResFile.Save(stream);
 }
Esempio n. 23
0
        public static AnimationGroupNode Read(string filename, ResFile TargetWiiUBFRES)
        {
            FileData f = new FileData(filename);

            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);
            if (SwitchCheck == 0x20202020)
            {
                //    SwitchAnim2WiiU(path); //Hacky auto convert switch anims to wii u


                ResNSW.ResFile b = new ResNSW.ResFile(filename);

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

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

                int i = 0;
                foreach (ResNSW.SkeletalAnim ska in b.SkeletalAnims)
                {
                    Animation a = new Animation(ska.Name);
                    ThisAnimation.Nodes.Add(a);

                    a.FrameCount = ska.FrameCount;
                    i++;
                    try
                    {
                        foreach (Syroot.NintenTools.NSW.Bfres.BoneAnim bn in ska.BoneAnims)
                        {
                            FSKANode bonean = new FSKANode(bn);

                            Animation.KeyNode bone = new Animation.KeyNode("");
                            a.Bones.Add(bone);
                            if (ska.FlagsRotate == ResNSW.SkeletalAnimFlagsRotate.EulerXYZ)
                            {
                                bone.RotType = Animation.RotationType.EULER;
                            }
                            else
                            {
                                bone.RotType = Animation.RotationType.QUATERNION;
                            }

                            bone.Text = bonean.Text;

                            for (int Frame = 0; Frame < ska.FrameCount; Frame++)
                            {
                                //Set base/start values for bones.
                                //Note. BOTW doesn't use base values as it uses havok engine. Need to add option to disable these
                                if (Frame == 0 && Runtime.HasNoAnimationBaseValues == false)
                                {
                                    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
                                    });
                                    bone.XROT.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.rot.X
                                    });
                                    bone.YROT.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.rot.Y
                                    });
                                    bone.ZROT.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.rot.Z
                                    });
                                    bone.XPOS.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.pos.X
                                    });
                                    bone.YPOS.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.pos.Y
                                    });
                                    bone.ZPOS.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.pos.Z
                                    });
                                }
                                foreach (FSKATrack track in bonean.tracks)
                                {
                                    Animation.KeyFrame frame = new Animation.KeyFrame();
                                    frame.InterType = Animation.InterpolationType.HERMITE;
                                    frame.Frame     = Frame;

                                    FSKAKey left  = track.GetLeft(Frame);
                                    FSKAKey right = track.GetRight(Frame);
                                    float   value;



                                    value = Animation.Hermite(Frame, left.frame, right.frame, 0, 0, left.unk1, right.unk1);

                                    // interpolate the value and apply
                                    switch (track.flag)
                                    {
                                    case (int)TrackType.XPOS: frame.Value = value; bone.XPOS.Keys.Add(frame); break;

                                    case (int)TrackType.YPOS: frame.Value = value; bone.YPOS.Keys.Add(frame); break;

                                    case (int)TrackType.ZPOS: frame.Value = value; bone.ZPOS.Keys.Add(frame); break;

                                    case (int)TrackType.XROT: frame.Value = value; bone.XROT.Keys.Add(frame); break;

                                    case (int)TrackType.YROT: frame.Value = value; bone.YROT.Keys.Add(frame); break;

                                    case (int)TrackType.ZROT: frame.Value = value; bone.ZROT.Keys.Add(frame); break;

                                    case (int)TrackType.XSCA: frame.Value = value; bone.XSCA.Keys.Add(frame); break;

                                    case (int)TrackType.YSCA: frame.Value = value; bone.YSCA.Keys.Add(frame); break;

                                    case (int)TrackType.ZSCA: frame.Value = value; bone.ZSCA.Keys.Add(frame); break;
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                    }
                }
                return(ThisAnimation);
            }
            else
            {
                f.eof();

                TargetWiiUBFRES = new ResFile(filename);

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

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

                int i = 0;
                foreach (SkeletalAnim ska in TargetWiiUBFRES.SkeletalAnims.Values)
                {
                    Animation a = new Animation(ska.Name);
                    ThisAnimation.Nodes.Add(a);

                    a.FrameCount = ska.FrameCount;
                    i++;
                    try
                    {
                        foreach (BoneAnim bn in ska.BoneAnims)
                        {
                            FSKANodeWiiU bonean = new FSKANodeWiiU(bn);

                            Animation.KeyNode bone = new Animation.KeyNode("");
                            a.Bones.Add(bone);
                            if (ska.FlagsRotate == SkeletalAnimFlagsRotate.EulerXYZ)
                            {
                                bone.RotType = Animation.RotationType.EULER;
                            }
                            else
                            {
                                bone.RotType = Animation.RotationType.QUATERNION;
                            }

                            bone.Text = bonean.Text;


                            for (int Frame = 0; Frame < ska.FrameCount; Frame++)
                            {
                                //Set base/start values for bones.
                                //Note. BOTW doesn't use base values as it uses havok engine. Need to add option to disable these
                                if (Frame == 0 && Runtime.HasNoAnimationBaseValues == false)
                                {
                                    bone.XSCA.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.sca.X
                                    });
                                    bone.YSCA.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.sca.Y
                                    });
                                    bone.ZSCA.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.sca.Z
                                    });
                                    bone.XROT.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.rot.X
                                    });
                                    bone.YROT.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.rot.Y
                                    });
                                    bone.ZROT.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.rot.Z
                                    });
                                    bone.XPOS.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.pos.X
                                    });
                                    bone.YPOS.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.pos.Y
                                    });
                                    bone.ZPOS.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.pos.Z
                                    });
                                }
                                foreach (FSKATrack track in bonean.tracks)
                                {
                                    Animation.KeyFrame frame = new Animation.KeyFrame();
                                    frame.InterType = Animation.InterpolationType.HERMITE;
                                    frame.Frame     = Frame;

                                    FSKAKey left  = track.GetLeft(Frame);
                                    FSKAKey right = track.GetRight(Frame);
                                    float   value;



                                    value = Animation.Hermite(Frame, left.frame, right.frame, 0, 0, left.unk1, right.unk1);

                                    // interpolate the value and apply
                                    switch (track.flag)
                                    {
                                    case (int)TrackType.XPOS: frame.Value = value; bone.XPOS.Keys.Add(frame); break;

                                    case (int)TrackType.YPOS: frame.Value = value; bone.YPOS.Keys.Add(frame); break;

                                    case (int)TrackType.ZPOS: frame.Value = value; bone.ZPOS.Keys.Add(frame); break;

                                    case (int)TrackType.XROT: frame.Value = value; bone.XROT.Keys.Add(frame); break;

                                    case (int)TrackType.YROT: frame.Value = value; bone.YROT.Keys.Add(frame); break;

                                    case (int)TrackType.ZROT: frame.Value = value; bone.ZROT.Keys.Add(frame); break;

                                    case (int)TrackType.XSCA: frame.Value = value; bone.XSCA.Keys.Add(frame); break;

                                    case (int)TrackType.YSCA: frame.Value = value; bone.YSCA.Keys.Add(frame); break;

                                    case (int)TrackType.ZSCA: frame.Value = value; bone.ZSCA.Keys.Add(frame); break;
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                    }
                }
                return(ThisAnimation);
            }
        }
Esempio n. 24
0
 internal ResFileWiiULoader(IResData resData, ResFile resFile, Stream stream, bool leaveOpen = false)
     : base(resData, resFile, stream, leaveOpen)
 {
     ByteOrder = ByteOrder.BigEndian;
 }
Esempio n. 25
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);
        }
Esempio n. 26
0
 internal ResFileWiiUSaver(IResData resData, ResFile resFile, string fileName)
     : base(resData, resFile, fileName)
 {
 }
        private static void AddResFileReference(StreamWriter pbxProj, ResFile resfile)
        {
            Debug.Log("Adding data file reference " + resfile.Name);

            var id = resfile.FileRefId;
            var lastKnownFileType = resfile.LastKnownType;
            var name = resfile.Name;

            pbxProj.WriteLine("\t\t" + id + " /* " + name +
                              " */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = " +
                              lastKnownFileType + "; name = " + name + "; path = Data/Raw/" + name +
                              "; sourceTree = SOURCE_ROOT; };");
        }
Esempio n. 28
0
        public void Read(ResFile TargetSwitchBFRES, FileData f)
        {
            Nodes.Add(TModels);
            Nodes.Add(TMaterialAnim);
            Nodes.Add(TVisualAnim);
            Nodes.Add(TShapeAnim);
            Nodes.Add(TSceneAnim);
            Nodes.Add(TEmbedded);
            ImageKey         = "bfres";
            SelectedImageKey = "bfres";

            FSKACount = TargetSwitchBFRES.SkeletalAnims.Count;
            FVISCount = TargetSwitchBFRES.BoneVisibilityAnims.Count;
            FMAACount = TargetSwitchBFRES.MaterialAnims.Count;

            Console.WriteLine("Name = " + TargetSwitchBFRES.Name);

            foreach (ExternalFile ext in TargetSwitchBFRES.ExternalFiles)
            {
                f = new FileData(ext.Data);

                f.Endian = Endianness.Little;

                string EmMagic = f.readString(f.pos(), 4);

                if (EmMagic.Equals("BNTX")) //Textures
                {
                    int  temp = f.pos();
                    BNTX t    = new BNTX();
                    t.ReadBNTX(f);
                    TEmbedded.Nodes.Add(t);
                }
            }

            int ModelCur = 0;

            //FMDLs -Models-
            foreach (Model mdl in TargetSwitchBFRES.Models)
            {
                FMDL_Model model = new FMDL_Model(); //This will store VBN data and stuff
                model.Text = mdl.Name;

                TModels.Nodes.Add(model);

                ReadSkeleton(model, mdl);

                model.skeleton.reset();
                model.skeleton.update();

                //MeshTime!!
                foreach (Shape shp in mdl.Shapes)
                {
                    Mesh poly = new Mesh();
                    poly.Text          = shp.Name;
                    poly.MaterialIndex = shp.MaterialIndex;
                    poly.matrFlag      = shp.VertexSkinCount;
                    poly.fsklindx      = shp.BoneIndex;

                    TModels.Nodes[ModelCur].Nodes.Add(poly);


                    ReadVertexBuffer(mdl, shp, poly);


                    //  int LODCount = shp.Meshes.Count - 1; //For going to the lowest poly LOD mesh
                    int LODCount = 0;

                    uint   FaceCount    = FaceCount = shp.Meshes[LODCount].IndexCount;
                    uint[] indicesArray = shp.Meshes[LODCount].GetIndices().ToArray();

                    poly.BoundingCount = shp.SubMeshBoundings.Count;

                    for (int face = 0; face < FaceCount; face++)
                    {
                        poly.faces.Add((int)indicesArray[face] + (int)shp.Meshes[LODCount].FirstVertex);
                    }

                    foreach (Bounding bnd in shp.SubMeshBoundings)
                    {
                        Mesh.BoundingBox box = new Mesh.BoundingBox();
                        box.Center = new Vector3(bnd.Center.X, bnd.Center.Y, bnd.Center.Z);
                        box.Extent = new Vector3(bnd.Extent.X, bnd.Extent.Y, bnd.Extent.Z);

                        poly.boundingBoxes.Add(box); //Each box is by LOD mesh. This will be in a seperate class later so only one will be added
                    }
                    foreach (float r in shp.RadiusArray)
                    {
                        poly.radius.Add(r);
                    }

                    // Read materials
                    Material mat = mdl.Materials[shp.MaterialIndex];

                    poly.material.Name = mat.Name;

                    ReadTextureRefs(mat, poly);
                    ReadShaderParams(mat, poly);
                    ReadRenderInfo(mat, poly);

                    foreach (Sampler smp in mdl.Materials[shp.MaterialIndex].Samplers)
                    {
                        SamplerInfo s = new SamplerInfo();
                        s.WrapModeU = (int)smp.WrapModeU;
                        s.WrapModeV = (int)smp.WrapModeV;
                        s.WrapModeW = (int)smp.WrapModeW;
                        poly.material.samplerinfo.Add(s);
                    }

                    model.poly.Add(poly);
                }
                models.Add(model);
                ModelCur++;
            }
        }
Esempio n. 29
0
        public void Read(ResFile TargetSwitchBFRES, FileData f)
        {
            Nodes.Add(TModels);
            Nodes.Add(TMaterialAnim);
            Nodes.Add(TVisualAnim);
            Nodes.Add(TShapeAnim);
            Nodes.Add(TSceneAnim);
            Nodes.Add(TEmbedded);
            ImageKey         = "bfres";
            SelectedImageKey = "bfres";

            AnimationCountTotal = TargetSwitchBFRES.SkeletalAnims.Count
                                  + TargetSwitchBFRES.BoneVisibilityAnims.Count
                                  + TargetSwitchBFRES.MaterialAnims.Count
                                  + TargetSwitchBFRES.ShapeAnims.Count;

            FSKACount = TargetSwitchBFRES.SkeletalAnims.Count;
            FVISCount = TargetSwitchBFRES.BoneVisibilityAnims.Count;
            FMAACount = TargetSwitchBFRES.MaterialAnims.Count;
            FSHACount = TargetSwitchBFRES.ShapeAnims.Count;

            Console.WriteLine("Name = " + TargetSwitchBFRES.Name);

            int ModelCur = 0;

            //FMDLs -Models-
            foreach (Model mdl in TargetSwitchBFRES.Models)
            {
                FMDL_Model model = new FMDL_Model(); //This will store VBN data and stuff
                model.Text = mdl.Name;

                TModels.Nodes.Add(model);

                ReadSkeleton(model, mdl);

                model.skeleton.reset();
                model.skeleton.update();

                foreach (int node in model.Node_Array)
                {
                    Console.WriteLine(model.skeleton.bones[node].Text);
                }

                //MeshTime!!
                foreach (Shape shp in mdl.Shapes)
                {
                    Mesh poly = new Mesh();
                    poly.Text            = shp.Name;
                    poly.MaterialIndex   = shp.MaterialIndex;
                    poly.VertexSkinCount = shp.VertexSkinCount;
                    poly.boneIndx        = shp.BoneIndex;
                    poly.fmdlIndx        = ModelCur;

                    foreach (int bn in shp.SkinBoneIndices)
                    {
                        poly.BoneIndexList.Add(model.skeleton.bones[bn].Text, bn);
                    }

                    TModels.Nodes[ModelCur].Nodes.Add(poly);


                    ReadVertexBuffer(mdl, shp, poly, model);

                    poly.BoundingCount = shp.SubMeshBoundings.Count;

                    int CurLOD = 0;
                    foreach (var lod in shp.Meshes)
                    {
                        Mesh.LOD_Mesh lodmsh = new Mesh.LOD_Mesh();
                        lodmsh.index = CurLOD++;

                        uint   FaceCount    = lod.IndexCount;
                        uint[] indicesArray = lod.GetIndices().ToArray();


                        for (int face = 0; face < FaceCount; face++)
                        {
                            lodmsh.faces.Add((int)indicesArray[face] + (int)lod.FirstVertex);
                        }

                        poly.lodMeshes.Add(lodmsh);
                    }

                    foreach (Bounding bnd in shp.SubMeshBoundings)
                    {
                        Mesh.BoundingBox box = new Mesh.BoundingBox();
                        box.Center = new Vector3(bnd.Center.X, bnd.Center.Y, bnd.Center.Z);
                        box.Extent = new Vector3(bnd.Extent.X, bnd.Extent.Y, bnd.Extent.Z);

                        poly.boundingBoxes.Add(box); //Each box is by LOD mesh. This will be in a seperate class later so only one will be added
                    }
                    foreach (float r in shp.RadiusArray)
                    {
                        poly.radius.Add(r);
                    }

                    // Read materials
                    Material mat = mdl.Materials[shp.MaterialIndex];

                    poly.material.Name = mat.Name;

                    int SampIndex = 0;
                    foreach (var smp in mat.SamplerDict)
                    {
                        poly.material.Samplers.Add(smp.Key, SampIndex);
                        SampIndex++;
                    }

                    MaterialData.ShaderAssign shaderassign = new MaterialData.ShaderAssign();

                    if (mat.ShaderAssign != null)
                    {
                        shaderassign.ShaderModel   = mat.ShaderAssign.ShadingModelName;
                        shaderassign.ShaderArchive = mat.ShaderAssign.ShaderArchiveName;

                        int o = 0;
                        foreach (var op in mat.ShaderAssign.ShaderOptionDict)
                        {
                            shaderassign.options.Add(op.Key, mat.ShaderAssign.ShaderOptions[o]);
                            o++;
                        }
                        int sa = 0;
                        foreach (var smp in mat.ShaderAssign.SamplerAssignDict)
                        {
                            //       Console.WriteLine($"{smp.Key} ---> {mat.ShaderAssign.SamplerAssigns[sa]}");
                            if (!shaderassign.samplers.ContainsKey(mat.ShaderAssign.SamplerAssigns[sa]))
                            {
                                shaderassign.samplers.Add(mat.ShaderAssign.SamplerAssigns[sa], smp.Key);
                            }
                            sa++;
                        }

                        int va = 0;
                        foreach (var att in mat.ShaderAssign.AttribAssignDict)
                        {
                            shaderassign.attributes.Add(att.Key, mat.ShaderAssign.AttribAssigns[va]);
                            va++;
                        }
                    }
                    else
                    {
                        shaderassign.ShaderModel   = "Not Assigned";
                        shaderassign.ShaderArchive = "Not Assigned";
                    }
                    poly.material.shaderassign = shaderassign;

                    ReadTextureRefs(mat, poly);
                    if (mat.ShaderParamData != null)
                    {
                        ReadShaderParams(mat, poly);
                    }
                    if (mat.RenderInfos != null)
                    {
                        ReadRenderInfo(mat, poly);
                    }

                    foreach (Sampler smp in mdl.Materials[shp.MaterialIndex].Samplers)
                    {
                        SamplerInfo s = new SamplerInfo();
                        s.WrapModeU = (int)smp.WrapModeU;
                        s.WrapModeV = (int)smp.WrapModeV;
                        s.WrapModeW = (int)smp.WrapModeW;
                        poly.material.samplerinfo.Add(s);
                    }

                    model.poly.Add(poly);
                }
                models.Add(model);
                ModelCur++;
            }
        }
Esempio n. 30
0
            public CachedModel(ResFile bfres, string textureArc)
            {
                bool loadTextures = !Properties.Settings.Default.DoNotLoadTextures;

                if (loadTextures && textureArc != null && File.Exists(Program.TryGetPathViaProject("ObjectData", textureArc + ".szs")) /*&& textureArc != "SingleModeBossSharedTextures" && textureArc != "SingleModeSharedTextures"*/)
                {
                    if (!texArcCache.ContainsKey(textureArc))
                    {
                        SARCExt.SarcData objArc = SARCExt.SARC.UnpackRamN(YAZ0.Decompress(Program.TryGetPathViaProject("ObjectData", textureArc + ".szs")));

                        Dictionary <string, int> arc = new Dictionary <string, int>();
                        texArcCache.Add(textureArc, arc);
                        foreach (KeyValuePair <string, TextureShared> textureEntry in new ResFile(new MemoryStream(objArc.Files[textureArc + ".bfres"])).Textures)
                        {
                            arc.Add(textureEntry.Key, UploadTexture(textureEntry.Value));
                        }
                    }
                }
                else if (loadTextures && textureArc != null)
                {
                    var filePath = Program.TryGetPathViaProject("ObjectData", textureArc);
                    if (Directory.Exists(filePath))
                    {
                        if (!texArcCache.ContainsKey(textureArc))
                        {
                            Dictionary <string, int> arc = new Dictionary <string, int>();
                            var filePaths = Directory.GetFiles(filePath);
                            texArcCache.Add(textureArc, arc);
                            foreach (string fileName in filePaths)
                            {
                                var image = new System.Drawing.Bitmap(fileName);
                                int texID = GL.GenTexture();

                                GL.BindTexture(TextureTarget.Texture2D, texID);
                                System.Drawing.Imaging.BitmapData data = image.LockBits(new System.Drawing.Rectangle(0, 0, image.Width, image.Height),
                                                                                        System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0,
                                              OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);

                                image.UnlockBits(data);
                                image.Dispose();

                                GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);

                                arc.Add(System.IO.Path.GetFileNameWithoutExtension(fileName), texID);

                                //var imageForm = new System.Windows.Forms.Form();
                                //imageForm.BackgroundImage = image;
                                //imageForm.Show();
                            }
                        }
                    }
                }

                Model mdl = bfres.Models[0];

                vaos = new VertexArrayObject[mdl.Shapes.Count];
                indexBufferLengths = new int[mdl.Shapes.Count];
                textures           = new int[mdl.Shapes.Count];
                wrapModes          = new (int, int)[mdl.Shapes.Count];
Esempio n. 31
0
        static ILogRecord LogEntry(string key, bool enabled, bool timeStampPrintable)
        {
            var logFile = ResFile.AsLog(EngineConf.LogDirectory, EngineConf.GetLogBasename(key));

            return(new LogRecord(logFile, enabled, timeStampPrintable));
        }
Esempio n. 32
0
        public static Task HandleFestival(RomType romType, Dictionary <string, byte[]> data, FestivalSetting previousFestival, FestivalSetting newFestival, byte[] rawFile)
        {
            // Check if this is the same
            if (previousFestival.FestivalId == newFestival.FestivalId)
            {
                //return Task.FromResult(0);
            }

            // Construct the path
            string s3Path = $"/splatoon/festival/{romType.ToString()}/{newFestival.FestivalId}";

            // Deserialize the FestivalSetting dynamically
            dynamic settingDynamic = ByamlLoader.GetByamlDynamic(rawFile);

            // Serialize the FestivalSetting to JSON
            string json = JsonConvert.SerializeObject(settingDynamic);

            // Upload to S3
            S3Api.TransferFile(Encoding.UTF8.GetBytes(json), s3Path, "setting.json", "application/json");

            // Load the panel texture file
            using (MemoryStream panelStream = new MemoryStream(data[FileType.FestivalPanelTexture.GetPath()]))
            {
                // Parse the BFRES
                ResFile panelRes = new ResFile(panelStream);

                // Load the BNTX
                using (MemoryStream bntxStream = new MemoryStream(panelRes.ExternalFiles[0].Data))
                {
                    // Parse the BNTX
                    BinaryTexture bt = new BinaryTexture(bntxStream);

                    // Decode the first texture
                    if (PixelDecoder.TryDecode(bt.Textures[0], out Bitmap Img))
                    {
                        // Open a destination MemoryStream
                        using (MemoryStream bitmapStream = new MemoryStream())
                        {
                            // Write the bitmap as a PNG to the MemoryStream
                            Img.Save(bitmapStream, ImageFormat.Png);

                            // Get the data
                            byte[] imageData = bitmapStream.ToArray();

                            // Upload to S3
                            S3Api.TransferFile(imageData, s3Path, "panel.png");

                            // Write to local
                            File.WriteAllBytes(string.Format(FileCache.FESTIVAL_PANEL_PATH, romType.ToString(), newFestival.FestivalId), imageData);
                        }
                    }
                }
            }

            lock (WebFileHandler.Lock)
            {
                // Get the WebConfig
                JelonzoBotWebConfig webConfig = ((JelonzoBotConfiguration)Configuration.LoadedConfiguration).WebConfig;

                // Connect to the remote server if needed
                WebFileHandler.Connect(webConfig);

                // Format the container list path
                string manifestPath = webConfig.LatestFestivalManifestPath;

                // Check if the file exists
                LatestFestivalManifest manifest;
                if (WebFileHandler.Exists(manifestPath))
                {
                    // Deserialize the manifest
                    manifest = WebFileHandler.ReadAllText <LatestFestivalManifest>(manifestPath);
                }
                else
                {
                    // Create a new manifest
                    manifest = new LatestFestivalManifest();
                    manifest.NorthAmerica = FileCache.GetLatestFestivalSettingForRomType(RomType.NorthAmerica).FestivalId;
                    manifest.Europe       = FileCache.GetLatestFestivalSettingForRomType(RomType.Europe).FestivalId;
                    manifest.Japan        = FileCache.GetLatestFestivalSettingForRomType(RomType.Japan).FestivalId;
                }

                // Update the manifest
                switch (romType)
                {
                case RomType.NorthAmerica:
                    manifest.NorthAmerica = newFestival.FestivalId;
                    break;

                case RomType.Europe:
                    manifest.Europe = newFestival.FestivalId;
                    break;

                case RomType.Japan:
                    manifest.Japan = newFestival.FestivalId;
                    break;

                default:
                    throw new Exception("Invalid RomType");
                }

                // Upload the manifest
                WebFileHandler.WriteSerializedJson(manifestPath, manifest);

                // Get the FestivalSetting JSON path
                string path = webConfig.FestivalSettingPath;
                switch (romType)
                {
                case RomType.NorthAmerica:
                    path = string.Format(path, "na");
                    break;

                case RomType.Europe:
                    path = string.Format(path, "eu");
                    break;

                case RomType.Japan:
                    path = string.Format(path, "jp");
                    break;

                default:
                    throw new Exception("Invalid RomType");
                }

                // Upload to the server
                WebFileHandler.WriteAllText(path, json);

                // Disconnect
                WebFileHandler.Disconnect();
            }

            return(Task.FromResult(0));
        }
 private static void AddResourcesBuildPhase(StreamWriter pbxProj, ResFile resfile)
 {
     var id = resfile.Id;
     var name = resfile.Name;
     Debug.Log("Adding build phase " + name);
     pbxProj.WriteLine("\t\t\t\t" + id + " /* " + name + " in Resources */,");
 }