示例#1
0
文件: BTAB.cs 项目: esmayl/dstools
 internal void Write(BinaryWriterEx bw, int nameOffset, int nameOffset2)
 {
     bw.WriteInt32(nameOffset);
     bw.WriteInt32(0);
     bw.WriteInt32(nameOffset2);
     bw.WriteInt32(0);
     bw.WriteInt32(AtlasIndex);
     bw.WriteVector2(AtlasOffset);
     bw.WriteVector2(AtlasScale);
     bw.WriteInt32(0);
 }
示例#2
0
 internal void Write(BinaryWriterEx bw, long partNameOffset, long materialNameOffset)
 {
     bw.WriteVarint(partNameOffset);
     bw.WriteVarint(materialNameOffset);
     bw.WriteInt32(AtlasID);
     bw.WriteVector2(UVOffset);
     bw.WriteVector2(UVScale);
     if (bw.VarintLong)
     {
         bw.WriteInt32(0);
     }
 }
示例#3
0
            internal void WriteValues(BinaryWriterEx bw, int groupIndex, int paramIndex, int valuesOffset)
            {
                bw.FillInt32($"ValuesOffset{groupIndex}:{paramIndex}", (int)bw.Position - valuesOffset);
                for (int i = 0; i < Values.Count; i++)
                {
                    object value = Values[i];
                    switch (Type)
                    {
                    case ParamType.Byte:
                        bw.WriteInt32((byte)value);
                        break;

                    case ParamType.Short:
                        bw.WriteInt16((short)value);
                        break;

                    case ParamType.IntA:
                        bw.WriteInt32((int)value);
                        break;

                    case ParamType.BoolA:
                        bw.WriteBoolean((bool)value);
                        break;

                    case ParamType.IntB:
                        bw.WriteInt32((int)value);
                        break;

                    case ParamType.Float:
                        bw.WriteSingle((float)value);
                        break;

                    case ParamType.BoolB:
                        bw.WriteBoolean((bool)value);
                        break;

                    case ParamType.Float2:
                        bw.WriteVector2((Vector2)value);
                        bw.WriteInt32(0);
                        bw.WriteInt32(0);
                        break;

                    case ParamType.Float3:
                        bw.WriteVector3((Vector3)value);
                        bw.WriteInt32(0);
                        break;

                    case ParamType.Float4:
                        bw.WriteVector4((Vector4)value);
                        break;

                    case ParamType.Byte4:
                        bw.WriteBytes((byte[])value);
                        break;
                    }
                }
                bw.Pad(4);
            }
示例#4
0
            internal void WriteValues(BinaryWriterEx bw, int groupIndex, int paramIndex, int valuesOffset)
            {
                bw.FillInt32($"ValuesOffset{groupIndex}:{paramIndex}", (int)bw.Position - valuesOffset);
                for (int i = 0; i < Values.Count; i++)
                {
                    object value = Values[i];
                    switch (Type)
                    {
                    case ParamType.Unk1:
                        bw.WriteInt32((int)value);
                        break;

                    case ParamType.Unk2:
                        bw.WriteInt16((short)value);
                        break;

                    case ParamType.Unk3:
                        bw.WriteInt32((int)value);
                        break;

                    case ParamType.Unk5:
                        bw.WriteBoolean((bool)value);
                        break;

                    case ParamType.Unk7:
                        bw.WriteInt32((int)value);
                        break;

                    case ParamType.Unk9:
                        bw.WriteSingle((float)value);
                        break;

                    case ParamType.UnkB:
                        bw.WriteBoolean((bool)value);
                        break;

                    case ParamType.UnkC:
                        bw.WriteVector2((Vector2)value);
                        bw.WriteInt32(0);
                        bw.WriteInt32(0);
                        break;

                    case ParamType.UnkD:
                        bw.WriteVector4((Vector4)value);
                        break;

                    case ParamType.UnkE:
                        bw.WriteVector4((Vector4)value);
                        break;

                    case ParamType.UnkF:
                        bw.WriteInt32((int)value);
                        break;
                    }
                }
                bw.Pad(4);
            }
示例#5
0
            internal void Write(BinaryWriterEx bw, int index)
            {
                bw.ReserveInt32($"TexturePath{index}");
                bw.ReserveInt32($"TextureType{index}");
                bw.WriteVector2(Scale);

                bw.WriteByte(Unk10);
                bw.WriteBoolean(Unk11);
                bw.WriteByte(0);
                bw.WriteByte(0);

                bw.WriteSingle(Unk14);
                bw.WriteSingle(Unk18);
                bw.WriteSingle(Unk1C);
            }
示例#6
0
        /// <summary>
        /// Serializes file data to a stream.
        /// </summary>
        protected override void Write(BinaryWriterEx bw)
        {
            bw.BigEndian = false;
            bw.WriteUInt32((uint)Version);
            bw.BigEndian = Version == CCMVer.DemonsSouls;

            bw.ReserveInt32("FileSize");
            bw.WriteInt16(FullWidth);
            bw.WriteInt16(TexWidth);
            bw.WriteInt16(TexHeight);

            if (Version == CCMVer.DemonsSouls || Version == CCMVer.DarkSouls1)
            {
                bw.WriteInt16(Unk0E);
                bw.ReserveInt16("CodeGroupCount");
                bw.WriteInt16((short)Glyphs.Count);
            }
            else if (Version == CCMVer.DarkSouls2)
            {
                bw.ReserveInt16("TexRegionCount");
                bw.WriteInt16((short)Glyphs.Count);
                bw.WriteInt16(0);
            }

            bw.WriteInt32(0x20);
            bw.ReserveInt32("GlyphOffset");
            bw.WriteByte(Unk1C);
            bw.WriteByte(Unk1D);
            bw.WriteByte(TexCount);
            bw.WriteByte(0);

            var codes = new List <int>(Glyphs.Keys);

            codes.Sort();
            if (Version == CCMVer.DemonsSouls || Version == CCMVer.DarkSouls1)
            {
                var codeGroups = new List <CodeGroup>();
                for (int i = 0; i < Glyphs.Count;)
                {
                    int startCode  = codes[i];
                    int glyphIndex = i;
                    for (i++; i < Glyphs.Count && codes[i] == codes[i - 1] + 1; i++)
                    {
                        ;
                    }
                    int endCode = codes[i - 1];
                    codeGroups.Add(new CodeGroup(startCode, endCode, glyphIndex));
                }

                bw.FillInt16("CodeGroupCount", (short)codeGroups.Count);
                foreach (CodeGroup group in codeGroups)
                {
                    group.Write(bw);
                }

                bw.FillInt32("GlyphOffset", (int)bw.Position);
                foreach (int code in codes)
                {
                    Glyph glyph = Glyphs[code];
                    bw.WriteVector2(glyph.UV1);
                    bw.WriteVector2(glyph.UV2);
                    bw.WriteInt16(glyph.PreSpace);
                    bw.WriteInt16(glyph.Width);
                    bw.WriteInt16(glyph.Advance);
                    bw.WriteInt16(glyph.TexIndex);
                }
            }
            else if (Version == CCMVer.DarkSouls2)
            {
                var texRegionsByCode = new Dictionary <int, TexRegion>(Glyphs.Count);
                var texRegions       = new HashSet <TexRegion>();
                foreach (int code in codes)
                {
                    Glyph glyph  = Glyphs[code];
                    short x1     = (short)Math.Round(glyph.UV1.X * TexWidth);
                    short y1     = (short)Math.Round(glyph.UV1.Y * TexHeight);
                    short x2     = (short)Math.Round(glyph.UV2.X * TexWidth);
                    short y2     = (short)Math.Round(glyph.UV2.Y * TexHeight);
                    var   region = new TexRegion(x1, y1, x2, y2);
                    texRegionsByCode[code] = region;
                    texRegions.Add(region);
                }

                bw.FillInt16("TexRegionCount", (short)texRegions.Count);
                var texRegionOffsets = new Dictionary <TexRegion, int>(texRegions.Count);
                foreach (TexRegion region in texRegions)
                {
                    texRegionOffsets[region] = (int)bw.Position;
                    region.Write(bw);
                }

                bw.FillInt32("GlyphOffset", (int)bw.Position);
                foreach (int code in codes)
                {
                    Glyph glyph = Glyphs[code];
                    bw.WriteInt32(code);
                    bw.WriteInt32(texRegionOffsets[texRegionsByCode[code]]);
                    bw.WriteInt16(glyph.TexIndex);
                    bw.WriteInt16(glyph.PreSpace);
                    bw.WriteInt16(glyph.Width);
                    bw.WriteInt16(glyph.Advance);
                    bw.WriteInt32(0);
                    bw.WriteInt32(0);
                }
            }

            bw.FillInt32("FileSize", (int)bw.Position);
        }