public SendTable(IBitStream bitstream) { DemoInfo.SendTable dataTable = new DemoInfo.SendTable(); foreach (var prop in dataTable.Parse(bitstream)) { SendTableProperty property = new SendTableProperty() { DataTableName = prop.DtName, HighValue = prop.HighValue, LowValue = prop.LowValue, Name = prop.VarName, NumberOfBits = prop.NumBits, NumberOfElements = prop.NumElements, Priority = prop.Priority, RawFlags = prop.Flags, RawType = prop.Type }; properties.Add(property); } this.Name = dataTable.NetTableName; this.IsEnd = dataTable.IsEnd; }
public static Vector DecodeVector(SendTableProperty prop, IBitStream reader) { if (prop.Flags.HasFlagFast(SendPropertyFlags.Normal)) { } Vector v = new Vector(); 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; }
void FlattenDataTable(int serverClassIndex) { SendTable table = DataTables[ServerClasses[serverClassIndex].DataTableID]; CurrentExcludes.Clear(); CurrentBaseclasses = new List <ServerClass> (); //NOT .clear because we use *this* reference //LITERALLY 3 lines later. @main--, this is warning for you. GatherExcludesAndBaseclasses(table, true); ServerClasses [serverClassIndex].BaseClasses = CurrentBaseclasses; GatherProps(table, serverClassIndex, ""); var flattenedProps = ServerClasses[serverClassIndex].FlattenedProps; List <int> priorities = new List <int>(); priorities.Add(64); priorities.AddRange(flattenedProps.Select(a => a.Prop.Priority).Distinct()); priorities.Sort(); int start = 0; for (int priorityIndex = 0; priorityIndex < priorities.Count; priorityIndex++) { int priority = priorities[priorityIndex]; while (true) { int currentProp = start; while (currentProp < flattenedProps.Count) { SendTableProperty prop = flattenedProps[currentProp].Prop; if (prop.Priority == priority || (priority == 64 && prop.Flags.HasFlagFast(SendPropertyFlags.ChangesOften))) { if (start != currentProp) { FlattenedPropEntry temp = flattenedProps[start]; flattenedProps[start] = flattenedProps[currentProp]; flattenedProps[currentProp] = temp; } start++; break; } currentProp++; } if (currentProp == flattenedProps.Count) { break; } } } }
public static float DecodeFloat(SendTableProperty prop, IBitStream reader) { float fVal = 0.0f; ulong dwInterp; if (DecodeSpecialFloat(prop, reader, out 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; }
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); } } }
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); } } }
void GatherProps_IterateProps(SendTable table, int ServerClassIndex, List <FlattenedPropEntry> flattenedProps, string prefix) { for (int i = 0; i < table.Properties.Count; i++) { SendTableProperty property = table.Properties[i]; if (property.Flags.HasFlagFast(SendPropertyFlags.InsideArray) || property.Flags.HasFlagFast(SendPropertyFlags.Exclude) || IsPropExcluded(table, property)) { continue; } if (property.Type == SendPropertyType.DataTable) { SendTable subTable = GetTableByName(property.DataTableName); if (property.Flags.HasFlagFast(SendPropertyFlags.Collapsible)) { //we don't prefix Collapsible stuff, since it is just derived mostly GatherProps_IterateProps(subTable, ServerClassIndex, flattenedProps, prefix); } else { //We do however prefix everything else string nfix = prefix + ((property.Name.Length > 0) ? property.Name + "." : ""); GatherProps(subTable, ServerClassIndex, nfix); } } else { if (property.Type == SendPropertyType.Array) { flattenedProps.Add(new FlattenedPropEntry(prefix + property.Name, property, table.Properties[i - 1])); } else { flattenedProps.Add(new FlattenedPropEntry(prefix + property.Name, property, null)); } } } }
bool IsPropExcluded(SendTable table, SendTableProperty prop) { return(CurrentExcludes.Exists(a => table.Name == a.DTName && prop.Name == a.VarName)); }
public FlattenedPropEntry(string propertyName, SendTableProperty prop, SendTableProperty arrayElementProp) { this.Prop = prop; this.ArrayElementProp = arrayElementProp; this.PropertyName = propertyName; }
static bool DecodeSpecialFloat(SendTableProperty prop, IBitStream reader, out float result) { if (prop.Flags.HasFlagFast(SendPropertyFlags.Coord)) { result = ReadBitCoord(reader); return true; } else if (prop.Flags.HasFlagFast(SendPropertyFlags.CoordMp)) { result = ReadBitCoordMP(reader, false, false); return true; } else if (prop.Flags.HasFlagFast(SendPropertyFlags.CoordMpLowPrecision)) { result = ReadBitCoordMP(reader, false, true); return true; } else if (prop.Flags.HasFlagFast(SendPropertyFlags.CoordMpIntegral)) { result = ReadBitCoordMP(reader, true, false); return true; } else if (prop.Flags.HasFlagFast(SendPropertyFlags.NoScale)) { result = reader.ReadFloat(); return true; } else if (prop.Flags.HasFlagFast(SendPropertyFlags.Normal)) { result = ReadBitNormal(reader); return true; } else if (prop.Flags.HasFlagFast(SendPropertyFlags.CellCoord)) { result = ReadBitCellCoord(reader, prop.NumberOfBits, false, false); return true; } else if (prop.Flags.HasFlagFast(SendPropertyFlags.CellCoordLowPrecision)) { result = ReadBitCellCoord(reader, prop.NumberOfBits, true, false); return true; } else if (prop.Flags.HasFlagFast(SendPropertyFlags.CellCoordIntegral)) { result = ReadBitCellCoord(reader, prop.NumberOfBits, false, true); return true; } result = 0; return false; }
public static Vector DecodeVectorXY(SendTableProperty prop, IBitStream reader) { Vector v = new Vector(); v.X = DecodeFloat(prop, reader); v.Y = DecodeFloat(prop, reader); return v; }
public static string DecodeString(SendTableProperty prop, IBitStream reader) { return Encoding.Default.GetString(reader.ReadBytes((int)reader.ReadInt(9))); }
bool IsPropExcluded(SendTable table, SendTableProperty prop) { return CurrentExcludes.Exists(a => table.Name == a.DTName && prop.Name == a.VarName); }