コード例 #1
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(BfshaFileLoader loader)
        {
            Property = loader.ReadUInt32();
            uint Size = loader.ReadUInt32();

            BufferOffset = loader.ReadUInt64();
            Reserved     = loader.ReadBytes(16);
        }
コード例 #2
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(BfshaFileLoader loader)
        {
            uint size = loader.ReadUInt32();

            DecompressedSize = loader.ReadUInt32();
            ulong codePointer = loader.ReadUInt64();

            loader.Seek((int)codePointer, System.IO.SeekOrigin.Begin);
            CompressedData = loader.ReadBytes((int)size);
        }
コード例 #3
0
        void IResData.Load(BfshaFileLoader loader)
        {
            ShaderInfoData = loader.LoadSection <ShaderInfoData>();
            uint memorySize = loader.ReadUInt32();

            loader.ReadUInt32(); //padding
            //Stores a bunch of 0s
            MemoryData = loader.LoadCustom(() => loader.ReadBytes((int)memorySize));
            loader.ReadUInt64(); //offset to parent shader variation
            ShaderReflection = loader.Load <ShaderReflection>();
            loader.Seek(32);     //reserved
        }
コード例 #4
0
        void IResData.Load(BfshaFileLoader loader)
        {
            Strings.Clear();
            loader.Seek(-0x14, System.IO.SeekOrigin.Current);
            uint Signature   = loader.ReadUInt32();
            uint blockOffset = loader.ReadUInt32();
            long BlockSize   = loader.ReadInt64();
            uint StringCount = loader.ReadUInt32();

            for (int i = 0; i < StringCount + 1; i++)
            {
                ushort size = loader.ReadUInt16();
                Strings.Add(loader.ReadString(BinaryStringFormat.ZeroTerminated));
                loader.Align(2);
            }
        }
コード例 #5
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(BfshaFileLoader loader)
        {
            Name       = loader.LoadString();
            ChoiceDict = loader.LoadDict();
            long ChoiceValuesOffset = loader.ReadOffset();
            byte choiceCount        = loader.ReadByte();

            DefaultIndex = loader.ReadByte();   //Index to default choice value
            BlockOffset  = loader.ReadUInt16(); // Uniform block offset.
            flag         = loader.ReadByte();
            keyOffset    = loader.ReadByte();   //Offset for key table
            flags0       = loader.ReadByte();   //Flags for choices
            flags1       = loader.ReadByte();
            flags2       = loader.ReadUInt32();
            uint padding = loader.ReadUInt32();

            Choices = loader.LoadCustom(() => loader.ReadUInt32s(choiceCount), ChoiceValuesOffset);
        }
コード例 #6
0
 private Node ReadNode(BfshaFileLoader loader)
 {
     return(new Node()
     {
         Reference = loader.ReadUInt32(),
         IdxLeft = loader.ReadUInt16(),
         IdxRight = loader.ReadUInt16(),
         Key = loader.LoadString(),
     });
 }
コード例 #7
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(BfshaFileLoader loader)
        {
            uint dataPointer = loader.ReadUInt32();
            uint size        = loader.ReadUInt32();
            uint handle      = loader.ReadUInt32();

            Stride = loader.ReadUInt16();
            ushort numBuffering   = loader.ReadUInt16();
            uint   contextPointer = loader.ReadUInt32();

            Data = loader.LoadCustom(() =>
            {
                byte[][] data = new byte[numBuffering][];
                for (int i = 0; i < numBuffering; i++)
                {
                    data[i] = loader.ReadBytes((int)size);
                }
                return(data);
            });
        }
コード例 #8
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(BfshaFileLoader loader)
        {
            loader.CheckSignature(_signature); //Same binary header as BNSH, BFRES, ETC
            uint padding = loader.ReadUInt32();

            VersionMajor      = loader.ReadInt16();
            VersionMinor      = loader.ReadByte();
            VersionMicro      = loader.ReadByte();
            ByteOrder         = loader.ReadEnum <ByteOrder>(false);
            Alignment         = loader.ReadByte();
            TargetAddressSize = loader.ReadByte();                  //Thanks MasterF0X for pointing out the layout of the these
            uint OffsetToFileName      = loader.ReadUInt32();
            uint OffsetPath            = loader.ReadUInt32();
            uint RelocationTableOffset = loader.ReadUInt32();
            uint sizFile              = loader.ReadUInt32();
            long shaderArchiveOffset  = loader.ReadOffset();
            long StringPoolOffset     = loader.ReadOffset();
            long ShaderingModelOffset = loader.ReadOffset();

            Name = loader.LoadString();
            Path = loader.LoadString();
            long ShaderModelArrayOffset = loader.ReadOffset();

            ShaderModelDict = loader.LoadDict();
            var padding2 = loader.ReadUInt64();
            var unk1     = loader.ReadUInt64();
            var unk2     = loader.ReadUInt64();

            ushort ModelCount = loader.ReadUInt16();
            ushort flag       = loader.ReadUInt16();

            loader.ReadUInt16();
            if (VersionMinor >= 7) //padding
            {
                loader.ReadUInt16();
            }

            ShaderModels = loader.LoadList <ShaderModel>(ModelCount, ShaderModelArrayOffset);
        }
コード例 #9
0
        // ---- METHODS (INTERNAL) -------------------------------------------------------------------------------------

        void IResData.Load(BfshaFileLoader loader)
        {
            // Read the header.
            uint signature = loader.ReadUInt32(); //Always 0x00000000
            int  numNodes  = loader.ReadInt32();  // Excludes root node.

            int i = 0;
            // Read the nodes including the root node.
            List <Node> nodes = new List <Node>();

            for (; numNodes >= 0; numNodes--)
            {
                nodes.Add(ReadNode(loader));
                i++;
            }
            _nodes = nodes;
        }
コード例 #10
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(BfshaFileLoader loader)
        {
            Type   = loader.ReadByte();
            Format = loader.ReadEnum <ShaderFormat>(false);
            loader.Seek(2); //padding
            CompressionType  = loader.ReadUInt32();
            VertexShaderCode = ReadShaderCode(loader, Format);
            TessellationControlShaderCode    = ReadShaderCode(loader, Format);
            TessellationEvaluationShaderCode = ReadShaderCode(loader, Format);
            GeometryShaderCode = ReadShaderCode(loader, Format);
            PixelShaderCode    = ReadShaderCode(loader, Format);
            ComputeShaderCode  = ReadShaderCode(loader, Format);

            if (VertexShaderCode != null)
            {
                VertexShaderCode.ShaderType = ShaderType.VERTEX;
            }
            if (TessellationControlShaderCode != null)
            {
                TessellationControlShaderCode.ShaderType = ShaderType.TESS0;
            }
            if (TessellationEvaluationShaderCode != null)
            {
                TessellationEvaluationShaderCode.ShaderType = ShaderType.TESS1;
            }
            if (GeometryShaderCode != null)
            {
                GeometryShaderCode.ShaderType = ShaderType.GEOMETRY;
            }
            if (PixelShaderCode != null)
            {
                PixelShaderCode.ShaderType = ShaderType.PIXEL;
            }
            if (ComputeShaderCode != null)
            {
                ComputeShaderCode.ShaderType = ShaderType.COMPUTE;
            }

            loader.Seek(40); //padding
        }
コード例 #11
0
        void IResData.Load(BfshaFileLoader loader)
        {
            ShaderVariations = new List <ShaderVariation>();
            StringTable      = new StringTable();

            loader.CheckSignature(_signature);
            uint padding = loader.ReadUInt32();

            SetVersionInfo(loader.ReadUInt32());
            ByteOrder         = loader.ReadEnum <ByteOrder>(false);
            Alignment         = loader.ReadByte();
            TargetAddressSize = loader.ReadByte(); //Thanks MasterF0X for pointing out the layout of the these
            uint   OffsetToFileName      = loader.ReadUInt32();
            ushort flag                  = loader.ReadUInt16();
            ushort blockOffset           = loader.ReadUInt16();
            uint   RelocationTableOffset = loader.ReadUInt32();
            uint   sizFile               = loader.ReadUInt32();

            loader.Seek(64); //Padding

            if (OffsetToFileName != 0)
            {
                using (loader.TemporarySeek(OffsetToFileName, SeekOrigin.Begin))
                {
                    Name = loader.ReadString(BinaryStringFormat.ZeroTerminated);
                }
            }

            //GRSC Section
            loader.CheckSignature(_grscSignature);
            loader.Seek(12); //Block header
            Unknown  = loader.ReadUInt16();
            Unknown2 = loader.ReadUInt16();
            Unknown3 = loader.ReadByte();
            Unknown4 = loader.ReadUInt32();
            uint VariationCount = loader.ReadUInt32();

            ShaderVariations = loader.LoadList <ShaderVariation>((int)VariationCount);
            loader.ReadInt64();
            Unknown5 = loader.ReadUInt64();
        }
コード例 #12
0
        void IResData.Load(BfshaFileLoader loader)
        {
            Name = loader.LoadString();
            long staticOptionArrayOffset = loader.ReadOffset();

            StaticOptionDict = loader.LoadDict();
            long dynamicOptionArrayOffset = loader.ReadOffset();

            DynamiOptionDict = loader.LoadDict();
            long attribArrayOffset = loader.ReadOffset();

            AttributeDict = loader.LoadDict();
            long samplerArrayOffset = loader.ReadOffset();

            SamplersDict = loader.LoadDict();

            if (loader.BfshaFile.VersionMinor >= 8)
            {
                loader.ReadInt64();
                loader.ReadInt64();
            }

            long uniformBlockArrayOffset = loader.ReadOffset();

            UniformBlockDict = loader.LoadDict();
            long uniformArrayOffset = loader.ReadOffset();

            if (loader.BfshaFile.VersionMinor >= 7)
            {
                loader.ReadInt64();
                loader.ReadInt64();
                loader.ReadInt64();
            }

            long shaderProgramArrayOffset = loader.ReadOffset();
            long tableOffset         = loader.ReadOffset();
            long shaderArchiveOffset = loader.ReadOffset();
            long shaderInfoOffset    = loader.ReadOffset();
            long shaderFileOffset    = loader.ReadOffset();

            loader.ReadUInt64();

            if (loader.BfshaFile.VersionMinor >= 7)
            {
                //padding
                loader.ReadInt64();
                loader.ReadInt64();
            }

            loader.ReadUInt64();
            loader.ReadUInt64();

            uint uniformCount = loader.ReadUInt32();

            if (loader.BfshaFile.VersionMinor <= 7)
            {
                loader.ReadUInt32();
            }
            int    defaultProgramIndex = loader.ReadInt32();
            ushort staticOptionCount   = loader.ReadUInt16();
            ushort dynamicOptionCount  = loader.ReadUInt16();
            ushort shaderProgramCount  = loader.ReadUInt16();
            byte   staticKeyLength     = loader.ReadByte();
            byte   dynamicKeyLength    = loader.ReadByte();
            byte   attribCount         = loader.ReadByte();
            byte   samplerCount        = loader.ReadByte();

            if (loader.BfshaFile.VersionMinor >= 8)
            {
                byte imageCount = loader.ReadByte();
            }

            byte uniformBlockCount = loader.ReadByte();

            loader.ReadBytes(5);

            if (loader.BfshaFile.VersionMinor >= 7)
            {
                loader.ReadBytes(6);
            }

            System.Console.WriteLine($"shaderFileOffset " + shaderFileOffset);
            System.Console.WriteLine($"Sampler " + samplerCount);
            System.Console.WriteLine($"attribCount " + attribCount);
            System.Console.WriteLine($"dynamicOptionCount " + dynamicOptionCount);
            System.Console.WriteLine($"staticOptionArrayOffset " + staticOptionArrayOffset);
            System.Console.WriteLine($"staticOptionCount " + staticOptionCount);

            if (loader.BfshaFile.VersionMinor >= 8)
            {
                loader.ReadBytes(7);
            }
            if (loader.BfshaFile.VersionMinor < 7)
            {
                loader.ReadBytes(4);
            }

            System.Console.WriteLine($"end pos " + loader.Position);

            int BnshSize = 0;

            if (shaderFileOffset != 0)
            {
                //Go into the bnsh file and get the file size
                using (loader.TemporarySeek(shaderFileOffset + 0x1C, System.IO.SeekOrigin.Begin))
                {
                    BnshSize = (int)loader.ReadUInt32();
                }
            }

            byte[] BinaryShaderData = loader.LoadCustom(() => loader.ReadBytes(BnshSize), shaderFileOffset);
            BnshFile = new BnshFile(new System.IO.MemoryStream(BinaryShaderData));

            StaticOptions = loader.LoadList <ShaderOption>(staticOptionCount, staticOptionArrayOffset);
            DynamiOptions = loader.LoadList <ShaderOption>(dynamicOptionCount, dynamicOptionArrayOffset);
            Attributes    = loader.LoadList <Attribute>(attribCount, attribArrayOffset);
            Samplers      = loader.LoadList <Sampler>(samplerCount, samplerArrayOffset);
            UniformBlocks = loader.LoadList <UniformBlock>(uniformBlockCount, uniformBlockArrayOffset);
            UniformVars   = loader.LoadList <UniformVar>((int)uniformCount, uniformArrayOffset);
        }
コード例 #13
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(BfshaFileLoader loader)
        {
            long FrameArrayOffset = loader.ReadOffset();
            long KeyArrayOffset   = loader.ReadOffset();

            _flags = loader.ReadUInt16();
            ushort numKey = loader.ReadUInt16();

            AnimDataOffset = loader.ReadUInt32();
            StartFrame     = loader.ReadSingle();
            EndFrame       = loader.ReadSingle();
            Scale          = loader.ReadSingle();
            Offset         = loader.ReadSingle();
            Delta          = loader.ReadSingle();
            int padding = loader.ReadInt32();

            Frames = loader.LoadCustom(() =>
            {
                switch (FrameType)
                {
                case AnimCurveFrameType.Single:
                    return(loader.ReadSingles(numKey));

                case AnimCurveFrameType.Decimal10x5:
                    float[] dec10x5Frames = new float[numKey];
                    for (int i = 0; i < numKey; i++)
                    {
                        dec10x5Frames[i] = (float)loader.ReadDecimal10x5();
                    }
                    return(dec10x5Frames);

                case AnimCurveFrameType.Byte:
                    float[] byteFrames = new float[numKey];
                    for (int i = 0; i < numKey; i++)
                    {
                        byteFrames[i] = loader.ReadByte();
                    }
                    return(byteFrames);

                default:
                    throw new ResException($"Invalid {nameof(FrameType)}.");
                }
            }, FrameArrayOffset);
            Keys = loader.LoadCustom(() =>
            {
                int elementsPerKey = ElementsPerKey;
                float[,] keys      = new float[numKey, elementsPerKey];
                switch (KeyType)
                {
                case AnimCurveKeyType.Single:
                    for (int i = 0; i < numKey; i++)
                    {
                        for (int j = 0; j < elementsPerKey; j++)
                        {
                            keys[i, j] = loader.ReadSingle();
                        }
                    }
                    break;

                case AnimCurveKeyType.Int16:
                    for (int i = 0; i < numKey; i++)
                    {
                        for (int j = 0; j < elementsPerKey; j++)
                        {
                            keys[i, j] = loader.ReadInt16();
                        }
                    }
                    break;

                case AnimCurveKeyType.SByte:
                    for (int i = 0; i < numKey; i++)
                    {
                        for (int j = 0; j < elementsPerKey; j++)
                        {
                            keys[i, j] = loader.ReadSByte();
                        }
                    }
                    break;

                default:
                    throw new ResException($"Invalid {nameof(KeyType)}.");
                }
                return(keys);
            }, KeyArrayOffset);
        }