Exemplo n.º 1
0
        public static H3D OpenAsH3D(Stream Input, GFPackage.Header Header)
        {
            H3D Output;

            //Model
            Input.Seek(Header.Entries[0].Address, SeekOrigin.Begin);

            GFModelPack MdlPack = new GFModelPack(Input);

            Output = MdlPack.ToH3D();

            //Animations
            Input.Seek(Header.Entries[1].Address, SeekOrigin.Begin);

            GFMotionPack MotPack = new GFMotionPack(Input);

            Output.Merge(MotPack.ToH3D(MdlPack.Models[0].Skeleton));

            //Texture
            if (Header.Entries.Length > 3 && Header.Entries[3].Length >= 4)
            {
                Input.Seek(Header.Entries[3].Address, SeekOrigin.Begin);

                BinaryReader Reader = new BinaryReader(Input);

                uint MagicNum = Reader.ReadUInt32();

                if (MagicNum == 0x15041213)
                {
                    Input.Seek(-4, SeekOrigin.Current);

                    GFTexture Tex = new GFTexture(Reader);

                    Output.Textures.Add(Tex.ToH3DTexture());
                }
            }

            return(Output);
        }
Exemplo n.º 2
0
        public static H3D IdentifyByMagic(Stream Stream, H3DDict <H3DBone> Skeleton, string FileName)
        {
            H3D Output = null;

            if (Stream.Length > 4)
            {
                BinaryReader Reader = new BinaryReader(Stream);

                uint MagicNum = Reader.ReadUInt32();

                Stream.Seek(-4, SeekOrigin.Current);

                string Magic = Encoding.ASCII.GetString(Reader.ReadBytes(4));

                Stream.Seek(0, SeekOrigin.Begin);

                if (Magic.StartsWith("BCH"))
                {
                    return(H3D.Open(Reader.ReadBytes((int)Stream.Length)));
                }
                else if (Magic.StartsWith("MOD") && FileName != null)
                {
                    return(LoadMTModel(Reader, FileName, Path.GetDirectoryName(FileName)));
                }
                else if (Magic.StartsWith("TEX") && FileName != null)
                {
                    return(new MTTexture(Reader, Path.GetFileNameWithoutExtension(FileName)).ToH3D());
                }
                else if (Magic.StartsWith("MFX"))
                {
                    MTShader = new MTShaderEffects(Reader);
                }
                else if (Magic.StartsWith("CGFX"))
                {
                    return(Gfx.Open(Stream));
                }
                else if (Magic.StartsWith("CMIF"))
                {
                    return(new CMIFFile(Stream).ToH3D());
                }
                else
                {
                    switch (MagicNum)
                    {
                    case GFModel.MagicNum:
                        GFModel Model = new GFModel(Reader, "Model");
                        Output = Model.ToH3D();
                        Output.SourceData.Add(Model);

                        break;

                    case GFTexture.MagicNum:
                        //Can be GFShader or GFTexture
                        Reader.BaseStream.Seek(0x8, SeekOrigin.Current);

                        string GFMagicStr = StringUtils.ReadPaddedString(Reader, 8);

                        if (GFMagicStr == GFTexture.MagicStr)
                        {
                            Reader.BaseStream.Seek(-0x10, SeekOrigin.Current);
                            Output = new H3D();
                            Output.Textures.Add(new GFTexture(Reader).ToH3DTexture());
                        }
                        else
                        {
                            Reader.BaseStream.Seek(0x8, SeekOrigin.Current);
                            GFMagicStr = StringUtils.ReadPaddedString(Reader, 8);

                            if (GFMagicStr == GFShader.MagicStr)
                            {
                                Reader.BaseStream.Seek(-0x18, SeekOrigin.Current);
                                Output = new H3D();
                                Output.SourceData.Add(new GFShader(Reader));
                            }
                        }

                        break;

                    case GFModelPack.MagicNum:
                        if (GFModelPack.IsModelPack(Reader))
                        {
                            Output = new GFModelPack(Reader).ToH3D();
                        }
                        break;

                    case GFMotion.MagicNum:
                        if (Skeleton != null)
                        {
                            Output = new H3D();

                            GFMotion Motion = new GFMotion(Reader, 0);

                            H3DAnimation    SklAnim = Motion.ToH3DSkeletalAnimation(Skeleton);
                            H3DMaterialAnim MatAnim = Motion.ToH3DMaterialAnimation();
                            H3DAnimation    VisAnim = Motion.ToH3DVisibilityAnimation();

                            if (SklAnim != null)
                            {
                                Output.SkeletalAnimations.Add(SklAnim);
                            }
                            if (MatAnim != null)
                            {
                                Output.MaterialAnimations.Add(MatAnim);
                            }
                            if (VisAnim != null)
                            {
                                Output.VisibilityAnimations.Add(VisAnim);
                            }
                        }

                        break;
                    }

                    if (GFMotionPack.IsGFL2MotionPack(Reader))
                    {
                        GFMotionPack Pack = new GFMotionPack(Reader);
                        Output = Pack.ToH3D(Skeleton);
                    }
                    if (GF1MotionPack.IsGFL1MotionPack(Reader))
                    {
                        Output = new GF1MotionPack(Reader).ToH3D(Skeleton);
                    }
                }
            }

            return(Output);
        }