コード例 #1
0
        public override void Load(Stream fileStream)
        {
            // Header
            var reader = new GensReader(fileStream);

            Header = reader.ReadHeader();

            // Root Node
            uint shaderOffset    = reader.ReadUInt32();
            uint subShaderOffset = reader.ReadUInt32();
            uint texsetOffset    = reader.ReadUInt32();
            uint texturesOffset  = reader.ReadUInt32();

            MaterialFlag      = reader.ReadByte(); // ?
            NoBackFaceCulling = reader.ReadBoolean();
            AdditiveBlending  = reader.ReadBoolean();
            UnknownFlag1      = reader.ReadByte();

            byte paramCount   = reader.ReadByte();
            byte padding1     = reader.ReadByte();
            byte unknownFlag2 = reader.ReadByte(); // Might be an enum, might just be a boolean?
            byte textureCount = reader.ReadByte();

            uint paramsOffset = reader.ReadUInt32();
            uint padding2     = reader.ReadUInt32();
            uint unknown1     = reader.ReadUInt32();

            // Padding/Unknown Value Checks
            if (padding1 != 0)
            {
                Console.WriteLine($"WARNING: Material Padding1 != 0 ({padding1})");
            }

            if (unknownFlag2 > 1)
            {
                Console.WriteLine($"WARNING: Material UnknownFlag2 > 1 ({unknownFlag2})");
            }

            if (padding2 != 0)
            {
                Console.WriteLine($"WARNING: Material Padding2 != 0 ({padding2})");
            }

            // Shader Name
            reader.JumpTo(shaderOffset, false);
            ShaderName = reader.ReadNullTerminatedString();

            // Sub-Shader Name
            reader.JumpTo(subShaderOffset, false);
            SubShaderName = reader.ReadNullTerminatedString();

            // Parameter Offsets
            var paramOffsets = new uint[paramCount];

            reader.JumpTo(paramsOffset, false);

            for (uint i = 0; i < paramCount; ++i)
            {
                paramOffsets[i] = reader.ReadUInt32();
            }

            // Parameters
            parameters.Clear();
            for (uint i = 0; i < paramCount; ++i)
            {
                reader.JumpTo(paramOffsets[i], false);
                var param = new Parameter()
                {
                    ParamFlag1 = reader.ReadUInt16(),
                    ParamFlag2 = reader.ReadUInt16()
                };

                uint paramNameOffset  = reader.ReadUInt32();
                uint paramValueOffset = reader.ReadUInt32();

                // Parameter Name
                reader.JumpTo(paramNameOffset, false);
                param.Name = reader.ReadNullTerminatedString();

                // Parameter Value
                reader.JumpTo(paramValueOffset, false);
                param.Value = reader.ReadVector4();

                parameters.Add(param);
            }

            // Texset
            reader.JumpTo(texsetOffset, false);
            if (Header.RootNodeType == 1) // TODO: Maybe check for textureCount < 1 instead?
            {
                TexsetName = reader.ReadNullTerminatedString();
            }
            else
            {
                Texset.Read(reader, textureCount);

                // Texture Offsets
                var texOffsets = new uint[textureCount];
                reader.JumpTo(texturesOffset, false);

                for (uint i = 0; i < textureCount; ++i)
                {
                    texOffsets[i] = reader.ReadUInt32();
                }

                // Textures
                for (int i = 0; i < textureCount; ++i)
                {
                    reader.JumpTo(texOffsets[i], false);
                    Texset.Textures[i].Read(reader);
                }
            }
        }