示例#1
0
        public override void Update(EndianWriter writer)
        {
            base.Update(writer);

            writer.SeekTo(SourceOffset + AmmoOffset);
            writer.WriteInt16(_remainingAmmo);
            writer.Skip(2);
            writer.WriteInt16(_clipAmmo);
        }
示例#2
0
        public static void WriteGuid(this EndianWriter stream, Guid value)
        {
            var data = value.ToByteArray();

            Debug.Assert(data.Length == 16);

            stream.WriteInt32(BitConverter.ToInt32(data, 0));
            stream.WriteInt16(BitConverter.ToInt16(data, 4));
            stream.WriteInt16(BitConverter.ToInt16(data, 6));
            stream.Write(data, 8, 8);
        }
示例#3
0
        /// <summary>
        /// Writes a Vector2 to a stream
        /// </summary>
        /// <param name="writer">Output stream</param>
        /// <param name="type">Datatype to write object as</param>
        public static void Write(this Vector2 vector, EndianWriter writer, IOType type)
        {
            switch (type)
            {
            case IOType.Short:
                writer.WriteInt16((short)vector.X);
                writer.WriteInt16((short)vector.Y);
                break;

            case IOType.Float:
                writer.WriteSingle(vector.X);
                writer.WriteSingle(vector.Y);
                break;

            default:
                throw new ArgumentException($"Type {type} not available for Vector2");
            }
        }
示例#4
0
        /// <summary>
        /// Writes a Vector3 to a stream
        /// </summary>
        /// <param name="writer">Output stream</param>
        /// <param name="type">Datatype to write object as</param>
        public static void Write(this Vector3 vector, EndianWriter writer, IOType type)
        {
            switch (type)
            {
            case IOType.Short:
                writer.WriteInt16((short)vector.X);
                writer.WriteInt16((short)vector.Y);
                writer.WriteInt16((short)vector.Z);
                break;

            case IOType.Float:
                writer.WriteSingle(vector.X);
                writer.WriteSingle(vector.Y);
                writer.WriteSingle(vector.Z);
                break;

            case IOType.BAMS16:
                writer.WriteInt16((short)DegToBAMS(vector.X));
                writer.WriteInt16((short)DegToBAMS(vector.Y));
                writer.WriteInt16((short)DegToBAMS(vector.Z));
                break;

            case IOType.BAMS32:
                writer.WriteInt32(DegToBAMS(vector.X));
                writer.WriteInt32(DegToBAMS(vector.Y));
                writer.WriteInt32(DegToBAMS(vector.Z));
                break;

            default:
                throw new ArgumentException($"Type {type} not available for struct Vector3");
            }
        }
示例#5
0
            /// <summary>
            /// Writes the strip to a byte stream
            /// </summary>
            /// <param name="writer">Output stream</param>
            /// <param name="userAttribs">Amount of user attributes</param>
            /// <param name="hasUV">Whether the polygons carry uv data</param>
            /// <param name="HDUV">Whether the uv data repeats at 1024, not 256</param>
            /// <param name="hasNormal">Whether the polygons carry normal data</param>
            /// <param name="hasColor">Whether the polygons carry color data</param>
            public void Write(EndianWriter writer, byte userAttribs, bool hasUV, bool HDUV, bool hasNormal, bool hasColor)
            {
                short length = (short)Math.Min(Corners.Length, short.MaxValue);

                writer.WriteInt16(Reversed ? (short)-length : length);

                bool  flag1      = userAttribs > 0;
                bool  flag2      = userAttribs > 1;
                bool  flag3      = userAttribs > 2;
                float multiplier = HDUV ? 1024 : 256;

                for (int i = 0; i < length; i++)
                {
                    Corner c = Corners[i];
                    writer.WriteUInt16(c.Index);
                    if (hasUV)
                    {
                        (c.Texcoord * multiplier).Write(writer, IOType.Short);
                    }
                    if (hasNormal)
                    {
                        c.Normal.Write(writer, IOType.Float);
                    }
                    else if (hasColor)
                    {
                        c.Color.Write(writer, IOType.ARGB8_16);
                    }


                    if (flag1 && i > 1)
                    {
                        writer.WriteUInt16(c.UserFlag1);
                        if (flag2)
                        {
                            writer.WriteUInt16(c.UserFlag2);
                            if (flag3)
                            {
                                writer.WriteUInt16(c.UserFlag3);
                            }
                        }
                    }
                }
            }