示例#1
0
 public static int DecodeInt(SendTableProperty prop, IBitStream reader)
 {
     if (prop.Flags.HasFlagFast(SendPropertyFlags.VarInt))
     {
         if (prop.Flags.HasFlagFast(SendPropertyFlags.Unsigned))
         {
             return((int)reader.ReadVarInt());
         }
         else
         {
             Trace.WriteLine("signed varints are not implemented. BAAAAAAD.", "PropDecoder:DecodeInt()");
             return((int)reader.ReadVarInt());
         }
     }
     else
     {
         if (prop.Flags.HasFlagFast(SendPropertyFlags.Unsigned))
         {
             return((int)reader.ReadInt(prop.NumberOfBits));
         }
         else
         {
             return(reader.ReadSignedInt(prop.NumberOfBits));
         }
     }
 }
示例#2
0
 public static int DecodeInt(SendTableProperty prop, IBitStream reader)
 {
     if (prop.Flags.HasFlagFast(SendPropertyFlags.VarInt))
     {
         if (prop.Flags.HasFlagFast(SendPropertyFlags.Unsigned))
         {
             return((int)reader.ReadVarInt());
         }
         else
         {
             return((int)reader.ReadSignedVarInt());
         }
     }
     else
     {
         if (prop.Flags.HasFlagFast(SendPropertyFlags.Unsigned))
         {
             return((int)reader.ReadInt(prop.NumberOfBits));
         }
         else
         {
             return(reader.ReadSignedInt(prop.NumberOfBits));
         }
     }
 }
示例#3
0
 static int DecodeInt(SendTableProperty prop, IBitStream reader)
 {
     if ((prop.Flags & SendPropertyFlags.VarInt) == SendPropertyFlags.VarInt)
     {
         if ((prop.Flags & SendPropertyFlags.Unsigned) == SendPropertyFlags.Unsigned)
         {
             return((int)reader.ReadVarInt());
         }
         else
         {
             // TODO implement
             throw new NotImplementedException("signed varints are not implemented. BAAAAAAD.");
             //return (int)reader.ReadVarInt();
         }
     }
     else
     {
         if ((prop.Flags & SendPropertyFlags.Unsigned) == SendPropertyFlags.Unsigned)
         {
             return((int)reader.ReadInt(prop.NumberOfBits));
         }
         else
         {
             return(reader.ReadSignedInt(prop.NumberOfBits));
         }
     }
 }
示例#4
0
        private static bool DecodeSpecialFloat(SendTableProperty prop, IBitStream reader, out float result)
        {
            if (prop.Flags.HasFlagFast(SendPropertyFlags.Coord))
            {
                result = ReadBitCoord(reader);
                return(true);
            }

            if (prop.Flags.HasFlagFast(SendPropertyFlags.CoordMp))
            {
                result = ReadBitCoordMP(reader, false, false);
                return(true);
            }

            if (prop.Flags.HasFlagFast(SendPropertyFlags.CoordMpLowPrecision))
            {
                result = ReadBitCoordMP(reader, false, true);
                return(true);
            }

            if (prop.Flags.HasFlagFast(SendPropertyFlags.CoordMpIntegral))
            {
                result = ReadBitCoordMP(reader, true, false);
                return(true);
            }

            if (prop.Flags.HasFlagFast(SendPropertyFlags.NoScale))
            {
                result = reader.ReadFloat();
                return(true);
            }

            if (prop.Flags.HasFlagFast(SendPropertyFlags.Normal))
            {
                result = ReadBitNormal(reader);
                return(true);
            }

            if (prop.Flags.HasFlagFast(SendPropertyFlags.CellCoord))
            {
                result = ReadBitCellCoord(reader, prop.NumberOfBits, false, false);
                return(true);
            }

            if (prop.Flags.HasFlagFast(SendPropertyFlags.CellCoordLowPrecision))
            {
                result = ReadBitCellCoord(reader, prop.NumberOfBits, true, false);
                return(true);
            }

            if (prop.Flags.HasFlagFast(SendPropertyFlags.CellCoordIntegral))
            {
                result = ReadBitCellCoord(reader, prop.NumberOfBits, false, true);
                return(true);
            }

            result = 0;

            return(false);
        }
示例#5
0
        public static Vector DecodeVectorXY(SendTableProperty prop, IBitStream reader)
        {
            Vector v = new Vector();

            v.X = DecodeFloat(prop, reader);
            v.Y = DecodeFloat(prop, reader);

            return(v);
        }
示例#6
0
        public static Vector3 DecodeVectorXY(SendTableProperty prop, IBitStream reader)
        {
            Vector3 v = new Vector3();

            v.x = DecodeFloat(prop, reader);
            v.y = DecodeFloat(prop, reader);

            return(v);
        }
示例#7
0
        public static Vector DecodeVectorXY(SendTableProperty prop, IBitStream reader)
        {
            var v = new Vector
            {
                X = DecodeFloat(prop, reader),
                Y = DecodeFloat(prop, reader)
            };

            return(v);
        }
示例#8
0
        public static float DecodeFloat(SendTableProperty prop, IBitStream reader)
        {
            ulong dwInterp;

            if (DecodeSpecialFloat(prop, reader, out var fVal))
            {
                return(fVal);
            }


            //Encoding: The range between lowVal and highVal is splitted into the same steps.
            //Read an int, fit it into the range.
            dwInterp = reader.ReadInt(prop.NumberOfBits);
            fVal     = (float)dwInterp / ((1 << prop.NumberOfBits) - 1);
            fVal     = prop.LowValue + (prop.HighValue - prop.LowValue) * fVal;

            return(fVal);
        }
示例#9
0
        public static long DecodeInt64(SendTableProperty prop, IBitStream reader)
        {
            if (prop.Flags.HasFlagFast(SendPropertyFlags.VarInt))
            {
                if (prop.Flags.HasFlagFast(SendPropertyFlags.Unsigned))
                {
                    return(reader.ReadVarInt());
                }
                else
                {
                    return(reader.ReadSignedVarInt());
                }
            }
            else
            {
                bool isNegative = false;
                uint low        = 0;
                uint high       = 0;

                if (prop.Flags.HasFlag(SendPropertyFlags.Unsigned))
                {
                    low  = reader.ReadInt(32);
                    high = reader.ReadInt(prop.NumberOfBits - 32);
                }
                else
                {
                    isNegative = reader.ReadBit();
                    low        = reader.ReadInt(32);
                    high       = reader.ReadInt(prop.NumberOfBits - 32 - 1);
                }

                long result = ((long)high << 32) | low;

                if (isNegative)
                {
                    result = -result;
                }

                return(result);
            }
        }
示例#10
0
        public static Vector DecodeVector(SendTableProperty prop, IBitStream reader)
        {
            if (prop.Flags.HasFlagFast(SendPropertyFlags.Normal))
            {
            }

            var v = new Vector
            {
                X = DecodeFloat(prop, reader),
                Y = DecodeFloat(prop, reader)
            };

            if (!prop.Flags.HasFlagFast(SendPropertyFlags.Normal))
            {
                v.Z = DecodeFloat(prop, reader);
            }
            else
            {
                var isNegative = reader.ReadBit();

                //v0v0v1v1 in original instead of margin.
                var absolute = v.X * v.X + v.Y * v.Y;
                if (absolute < 1.0f)
                {
                    v.Z = (float)Math.Sqrt(1 - absolute);
                }
                else
                {
                    v.Z = 0f;
                }

                if (isNegative)
                {
                    v.Z *= -1;
                }
            }

            return(v);
        }
示例#11
0
        static Vector DecodeVector(SendTableProperty prop, IBitStream reader)
        {
            if ((prop.Flags & SendPropertyFlags.Normal) == SendPropertyFlags.Normal)
            {
            }

            Vector v = new Vector();

            v.X = DecodeFloat(prop, reader);
            v.Y = DecodeFloat(prop, reader);

            if ((prop.Flags & SendPropertyFlags.Normal) != SendPropertyFlags.Normal)
            {
                v.Z = DecodeFloat(prop, reader);
            }
            else
            {
                bool isNegative = reader.ReadBit();

                //v0v0v1v1 in original instead of margin.
                float absolute = v.X * v.X + v.Y * v.Y;
                if (absolute < 1.0f)
                {
                    v.Z = (float)Math.Sqrt(1 - absolute);
                }
                else
                {
                    v.Z = 0f;
                }

                if (isNegative)
                {
                    v.Z *= -1;
                }
            }

            return(v);
        }
示例#12
0
        public static Vector3 DecodeVector(SendTableProperty prop, IBitStream reader)
        {
            if (prop.Flags.HasFlagFast(SendPropertyFlags.Normal))
            {
            }

            Vector3 v = new Vector3();

            v.x = DecodeFloat(prop, reader);
            v.y = DecodeFloat(prop, reader);

            if (!prop.Flags.HasFlagFast(SendPropertyFlags.Normal))
            {
                v.z = DecodeFloat(prop, reader);
            }
            else
            {
                bool isNegative = reader.ReadBit();

                //v0v0v1v1 in original instead of margin.
                float absolute = v.x * v.x + v.y * v.y;
                if (absolute < 1.0f)
                {
                    v.z = (float)Math.Sqrt(1 - absolute);
                }
                else
                {
                    v.z = 0f;
                }

                if (isNegative)
                {
                    v.z *= -1;
                }
            }

            return(v);
        }
示例#13
0
 public static string DecodeString(SendTableProperty prop, IBitStream reader)
 {
     return(Encoding.Default.GetString(reader.ReadBytes((int)reader.ReadInt(9))));
 }