Example #1
0
        public void Write(FileWriter writer, LayoutHeader header)
        {
            if (MatColor != STColor8.White)
            {
                HasMaterialColor = true;
            }
            if (!ChanControl.HasDefaults())
            {
                HasChannelControl = true;
            }
            if (!BlendMode.HasDefaults())
            {
                HasBlendMode = true;
            }
            if (!((AlphaCompare)AlphaCompare).HasDefaults())
            {
                HasAlphaCompare = true;
            }

            if (TextureMaps?.Length > 0 && TexCoordGens?.Count == 0)
            {
                TexCoordGens = new List <TexCoordGenEntry>(TextureMaps.Length);
                for (int i = 0; i < TextureMaps?.Length; i++)
                {
                    TexCoordGens[i] = new TexCoordGenEntry();
                }
            }

            flags = 0;
            if (HasMaterialColor)
            {
                flags |= (1 << 27);
            }

            if (HasChannelControl)
            {
                flags |= (1 << 25);
            }

            if (HasBlendMode)
            {
                flags |= (1 << 24);
            }

            if (HasAlphaCompare)
            {
                flags |= (1 << 23);
            }

            flags |= (uint)((TevStages.Length & 31) << 18);
            flags |= (uint)((IndirectStages.Count & 0x7) << 15);
            flags |= (uint)((IndirectTexTransforms.Count & 0x3) << 13);
            if (HasTevSwapTable)
            {
                flags |= (1 << 12);
            }

            flags |= (uint)((TexCoordGens.Count & 0xF) << 8);
            flags |= (uint)((TextureTransforms.Length & 0xF) << 4);
            flags |= (uint)((TextureMaps.Length & 0xF) << 0);


            writer.WriteString(Name, 0x14);
            writer.Write(BlackColor.ToColor16());
            writer.Write(WhiteColor.ToColor16());
            writer.Write(ColorRegister3.ToColor16());
            writer.Write(TevColor1);
            writer.Write(TevColor2);
            writer.Write(TevColor3);
            writer.Write(TevColor4);
            writer.Write(flags);

            for (int i = 0; i < TextureMaps.Length; i++)
            {
                ((TextureRef)TextureMaps[i]).Write(writer);
            }

            for (int i = 0; i < TextureTransforms.Length; i++)
            {
                TextureTransforms[i].Write(writer);
            }

            for (int i = 0; i < TexCoordGens.Count; i++)
            {
                TexCoordGens[i].Write(writer);
            }

            if (HasChannelControl)
            {
                ChanControl.Write(writer);
            }
            if (HasMaterialColor)
            {
                writer.Write(MatColor);
            }
            if (HasTevSwapTable)
            {
                TevSwapModeTable.Write(writer);
            }

            for (int i = 0; i < IndirectTexTransforms.Count; i++)
            {
                IndirectTexTransforms[i].Write(writer);
            }

            for (int i = 0; i < IndirectStages.Count; i++)
            {
                IndirectStages[i].Write(writer);
            }

            for (int i = 0; i < TevStages.Length; i++)
            {
                ((TevStage)TevStages[i]).Write(writer);
            }

            if (HasAlphaCompare)
            {
                AlphaCompare.Write(writer);
            }
            if (HasBlendMode)
            {
                BlendMode.Write(writer);
            }
        }
Example #2
0
        public void Write(FileWriter writer, LayoutHeader header)
        {
            writer.WriteString(Name, 20);
            writer.Write(BlackColor);
            writer.Write(WhiteColor);
            writer.Write(TevConstantColors);
            long flagPos = writer.Position;

            writer.Write(flags);

            if (TextureMaps?.Length > 0 && TexCoordGens?.Length == 0)
            {
                TexCoordGens = new BxlytTexCoordGen[TextureMaps.Length];
                for (int i = 0; i < TextureMaps?.Length; i++)
                {
                    TexCoordGens[i] = new TexCoordGen();
                }
            }

            flags = 0;
            for (int i = 0; i < TextureMaps?.Length; i++)
            {
                flags += Bit.BitInsert(1, 1, 2, 30);
                ((TextureRef)TextureMaps[i]).Write(writer);
            }

            for (int i = 0; i < TextureTransforms?.Length; i++)
            {
                flags += Bit.BitInsert(1, 1, 2, 28);
                ((BxlytTextureTransform)TextureTransforms[i]).Write(writer);
            }

            for (int i = 0; i < TexCoordGens?.Length; i++)
            {
                flags += Bit.BitInsert(1, 1, 2, 26);
                ((TexCoordGen)TexCoordGens[i]).Write(writer);
            }

            for (int i = 0; i < TevStages?.Length; i++)
            {
                flags += Bit.BitInsert(1, 1, 2, 24);
                ((TevStage)TevStages[i]).Write(writer);
            }
            if (AlphaCompare != null && EnableAlphaCompare)
            {
                flags += Bit.BitInsert(1, 1, 1, 22);
                AlphaCompare.Write(writer);
            }
            if (BlendMode != null && EnableBlend)
            {
                flags += Bit.BitInsert(1, 1, 2, 20);
                BlendMode.Write(writer);
            }
            if (BlendModeLogic != null && EnableBlendLogic)
            {
                flags += Bit.BitInsert(1, 1, 2, 18);
                BlendModeLogic.Write(writer);
            }
            if (IndParameter != null && EnableIndParams)
            {
                flags += Bit.BitInsert(1, 1, 1, 17);
                IndParameter.Write(writer);
            }

            for (int i = 0; i < ProjTexGenParams.Length; i++)
            {
                flags += Bit.BitInsert(1, 1, 2, 15);
                ProjTexGenParams[i].Write(writer);
            }

            if (FontShadowParameter != null && EnableFontShadowParams)
            {
                flags += Bit.BitInsert(1, 1, 1, 14);
                FontShadowParameter.Write(writer);
            }

            if (AlphaInterpolation)
            {
                flags += Bit.BitInsert(1, 1, 1, 13);
            }

            using (writer.TemporarySeek(flagPos, System.IO.SeekOrigin.Begin)) {
                writer.Write(flags);
            }
        }