protected override void Parse(EndianBinaryReader r) { X = r.ReadInt32(); Z = r.ReadInt32(); //int ArraySize = ReadVarInt(r); throw new NotImplementedException(); }
protected override void Parse(EndianBinaryReader r) { EID = ReadVarInt(r); Type = r.ReadSByte(); Position = new CoordDouble(); Position.X = ((double)r.ReadInt32()) / 32; Position.Y = ((double)r.ReadInt32()) / 32; Position.Z = ((double)r.ReadInt32()) / 32; }
public UItem(EndianBinaryReader r) { X = r.ReadInt32(); Z = r.ReadInt32(); OccupiedBitmap = r.ReadInt16(); AdditionalBitmap = r.ReadInt16(); #if DEBUG if (AdditionalBitmap != 0) Log.WriteServer("AdditionalData: " + AdditionalBitmap.ToString("X")); #endif }
protected override void Parse(EndianBinaryReader r) { EffectID = (SoundEffects)r.ReadInt32(); Position = CoordInt.Read(r); SoundData = r.ReadInt32(); SoundByte = r.ReadByte(); //Debug.WriteLine(DebugPacket.Read(r)); #if DEBUGPACKET if (EffectID.ToString() == ((int)EffectID).ToString()) throw new NotImplementedException(EffectID.ToString()); #endif }
protected override void Parse(EndianBinaryReader r) { Event = (Action)r.ReadByte(); if (Event == Action.End) { Duration = ReadVarInt(r); EntityID = r.ReadInt32(); } if (Event == Action.Dead) { PlayerID = ReadVarInt(r); EntityID = r.ReadInt32(); Message = ReadString8(r); } }
protected override void Parse(EndianBinaryReader r) { ParticleID = r.ReadInt32(); LongDistance = r.ReadBoolean(); Position = new CoordDouble(); Position.X = r.ReadSingle(); Position.Y = r.ReadSingle(); Position.Z = r.ReadSingle(); Size = new CoordDouble(); Size.X = r.ReadSingle(); Size.Y = r.ReadSingle(); Size.Z = r.ReadSingle(); Speed = r.ReadSingle(); Count = r.ReadInt32(); Debug.WriteLine(this); }
protected override void Parse(EndianBinaryReader r) { EID = r.ReadInt32(); Status = (EntityStatuses)r.ReadByte(); #if DEBUGPACKET if (Status.ToString() == ((int)Status).ToString()) throw new NotImplementedException(Status.ToString()); #endif }
protected override void Parse(EndianBinaryReader r) { int columnCount = r.ReadInt16(); int compressedLength = r.ReadInt32(); Unknown = r.ReadBoolean(); CompressedChunkColumns = r.ReadBytesOrThrow(compressedLength); ColumnMeta = new UItem[columnCount]; for (int n = 0; n < columnCount; n++) { ColumnMeta [n] = new UItem(r); } }
private void ReadLength() { lenBuffer = new byte[4]; using (MiscUtil.IO.EndianBinaryReader reader = new MiscUtil.IO.EndianBinaryReader(EndianBitConverter.Big, new MemoryStream(incomingBuffer), Encoding.UTF8)) { int len = reader.ReadInt32(); if (len < 0 || len >= ClientConnection.packetLen) { throw new IOException("Packet len " + len + " is out of range!"); } incomingBuffer = new byte[len]; } }
protected override void Parse(EndianBinaryReader r) { Dimension = (Dimensions)r.ReadInt32(); Difficulty = r.ReadByte(); Mode = (GameMode)r.ReadByte(); #if DEBUGPACKET if (Dimension.ToString() == ((int)Dimension).ToString()) throw new NotImplementedException(Dimension.ToString()); if (Mode.ToString() == ((int)Mode).ToString()) throw new NotImplementedException(Mode.ToString()); #endif LevelType = ReadString8(r); }
protected override void Parse(EndianBinaryReader r) { EntityID = r.ReadInt32(); GameMode = (GameMode)r.ReadByte(); Dimension = (Dimensions)r.ReadSByte(); Difficulty = r.ReadByte(); MaxPlayers = r.ReadByte(); LevelType = ReadString8(r); ReducedDebug = r.ReadBoolean(); #if DEBUGPACKET if (Dimension.ToString() == ((int)Dimension).ToString()) throw new NotImplementedException(Dimension.ToString()); if (GameMode.ToString() == ((int)GameMode).ToString()) throw new NotImplementedException(GameMode.ToString()); #endif }
protected override void Parse(EndianBinaryReader r) { WindowID = r.ReadByte(); InventoryType = ReadString8(r); WindowTitle = ReadString8(r); NumberOfSlots = r.ReadByte(); if (InventoryType == "EntityHorse") Unknown = r.ReadInt32(); #if DEBUGPACKET Console.WriteLine("Horse Window Unknown: " + Unknown); if (InventoryTypes.Contains(InventoryType) == false) { Console.WriteLine("Unknown InventoryType: " + InventoryType); throw new NotImplementedException(InventoryType); } #endif }
protected override void Parse(EndianBinaryReader r) { Position = new CoordDouble(); Position.X = r.ReadSingle(); Position.Y = r.ReadSingle(); Position.Z = r.ReadSingle(); Radius = r.ReadSingle(); int count = r.ReadInt32(); Records = new Record[count]; for (int n = 0; n < count; n++) { Records [n] = new Record(); Records [n].X = r.ReadSByte(); Records [n].Y = r.ReadSByte(); Records [n].Z = r.ReadSByte(); } PlayerMotion = new float[3]; PlayerMotion [0] = r.ReadSingle(); PlayerMotion [1] = r.ReadSingle(); PlayerMotion [2] = r.ReadSingle(); }
protected override void Parse(EndianBinaryReader r) { EID = ReadVarInt(r); Type = (Vehicles)r.ReadByte(); #if DEBUGPACKET if (Type.ToString() == ((int)Type).ToString()) throw new NotImplementedException(Type.ToString()); #endif if (Type == Vehicles.Unknown) Console.WriteLine(); Position = ReadAbsInt(r); Yaw = r.ReadSByte(); Pitch = r.ReadSByte(); SourceEntity = r.ReadInt32(); if (SourceEntity <= 0) return; short vx = r.ReadInt16(); short vy = r.ReadInt16(); short vz = r.ReadInt16(); Velocity = new CoordInt(vx, vy, vz); }
protected override void Parse(EndianBinaryReader r) { EID = ReadVarInt(r); int count = r.ReadInt32(); //Console.Write("DEBx2C: " + EID + " "); for(int n = 0; n < count; n++) { var p = new Property(); p.Key = ReadString8(r); p.Val = r.ReadDouble(); int sub = ReadVarInt(r); p.List = new List<PropData>(); for (int s = 0; s < sub; s++) { var sd = new PropData(); sd.UUIDpart1 = r.ReadInt64(); sd.UUIDpart2 = r.ReadInt64(); sd.Amount = r.ReadDouble(); sd.Operation = r.ReadByte(); p.List.Add(sd); } Properties.Add(p); } //Debug.WriteLine(this); }
private void Work(object arg) { CalculationOptions opt = arg as CalculationOptions; NetworkStream ns = null; Success = false; try { ns = TcpHelper.OpenStream(Host, 1); byte[] magic = new byte[4]; ns.Read(magic, 0, 4); uint v = BitConverter.ToUInt32(magic, 0); bool be = (v == 0xAFDE0000); // Renderer sends 00 00 DE AF, if its reversed all is in big endian EndianBitConverter ec; if (be) ec = new BigEndianBitConverter(); else ec = new LittleEndianBitConverter(); using (EndianBinaryWriter bw = new EndianBinaryWriter(ec, ns)) using (EndianBinaryReader br = new EndianBinaryReader(ec, ns)) { bw.Write((uint)0x0000FEED); // Write rational coordinates foreach (BigRational r in new[] { opt.MinRe, opt.MaxRe, opt.MinIm, opt.MaxIm }) { int sign = r.Numerator.Sign; byte[] num = BigInteger.Abs(r.Numerator).ToByteArray(); bw.Write(sign); bw.Write(num.Length); bw.Write(num); num = BigInteger.Abs(r.Denominator).ToByteArray(); bw.Write(num.Length); bw.Write(num); } bw.Write(opt.IterationCount); bw.Write(opt.Width); bw.Write(opt.Height); bw.Write(opt.XOff); bw.Write(opt.XSkip); bw.Write(opt.XMax); bw.Write(opt.YOff); bw.Write(opt.YSkip); bw.Write(opt.YMax); bw.Write(opt.OrbitStart); bw.Write(opt.OrbitLength); bw.Write(opt.BulbChecking ? 1U : 0U); int ok = br.ReadInt32(); if (ok != 200) throw new InvalidOperationException(); // TODO Proper exception // Sent parameters, now read all orbits OrbitMap map = new OrbitMap(); int orbitsComing = 0; while ((orbitsComing = br.ReadInt32()) >= 0) { for (int i = 0; i < orbitsComing; i++) { int o_x = br.ReadInt32(); int o_y = br.ReadInt32(); BigRational re, im; re = ReadRational(br); im = ReadRational(br); BigComplex o_c = new BigComplex(re, im); uint o_iter = br.ReadUInt32(); // Number of iterations before escape uint o_orbs = br.ReadUInt32(); // Offset of the orbit uint o_orbl = br.ReadUInt32(); // Length of the orbit Orbit orbit = new Orbit(o_x, o_y, o_c, o_iter, o_orbs, o_orbl); for (uint j = 0; j < o_orbl; j++) { re = ReadRational(br); im = ReadRational(br); orbit.Add(re, im); } map.AddOrbit(orbit); } } Result = map; // Set the result so it can be combined with work from the other threads } ns.Close(); Success = true; } catch (Exception) // TODO error handling ? Just log the message and be done { Success = false; } finally { if (ns != null) ns.Close(); (WaitHandle as ManualResetEvent).Set(); // Public signal that I'm done } }
protected override void Parse(EndianBinaryReader r) { EID = r.ReadInt32(); VehicleID = r.ReadInt32(); Leash = r.ReadBoolean(); }
public void Parse(EndianBinaryReader reader, uint size) { var maxReadPos = reader.BaseStream.Position + size; while(reader.BaseStream.Position < maxReadPos) { if (objectStack.Count != 0) { var count = reader.ReadUInt16(); var propString = ""; for (var i = 0; i < count; i++) { propString += (char) reader.ReadByte(); } objectStack.Peek().CurrentProperty = propString; } var type = (Globals.Amf0Types)reader.ReadByte(); switch (type) { case Globals.Amf0Types.Number: { var value = reader.ReadDouble(); if(objectStack.Count != 0) { objectStack.Peek().Numbers.Add(objectStack.Peek().CurrentProperty, value); } else { amfData.Numbers.Add(value); } } break; case Globals.Amf0Types.Boolean: { var value = reader.ReadBoolean(); if (objectStack.Count != 0) { objectStack.Peek().Booleans.Add(objectStack.Peek().CurrentProperty, value); } else { amfData.Booleans.Add(value); } } break; case Globals.Amf0Types.String: { var count = reader.ReadUInt16(); var pushString = ""; for (var i = 0; i < count; i++) { pushString += (char) reader.ReadByte(); } if (objectStack.Count != 0) { objectStack.Peek().Strings.Add(objectStack.Peek().CurrentProperty, pushString); } else { amfData.Strings.Add(pushString); } } break; case Globals.Amf0Types.Null: if (objectStack.Count != 0) { objectStack.Peek().Nulls++; } else { amfData.Nulls++; } break; case Globals.Amf0Types.Object: case Globals.Amf0Types.Array: { if(type == Globals.Amf0Types.Array) { var arrayLength = reader.ReadInt32(); } var objectAdd = new AmfObject(); objectStack.Push(objectAdd); } break; case Globals.Amf0Types.ObjectEnd: { if(objectStack.Count == 1) { amfData.Objects.Add(objectStack.Pop()); } else if(objectStack.Count > 1) { var mostRecentObject = objectStack.Pop(); objectStack.Peek().Objects.Add(objectStack.Peek().CurrentProperty, mostRecentObject); } } break; default: throw new ArgumentOutOfRangeException(); } /* switch (type) { case Amf0Types.Array: case Amf0Types.Object: { if(type == Amf0Types.Array) { var arrayLength = reader.ReadInt32(); Console.WriteLine("Array:" + arrayLength); } bool hasProperty = false; string property = ""; var objectAdd = new AmfObject(); while (reader.BaseStream.Position < maxReadPos) { if(!hasProperty) { property = ""; var propertyStringLength = reader.ReadUInt16(); for (var i = 0; i < propertyStringLength; i++) { property += (char)reader.ReadByte(); } hasProperty = true; } if (hasProperty == true) { if(property.Length == 0) { amfData.Objects.Add(objectAdd); break; } var objtype = (Amf0Types)reader.ReadByte(); parseType(objtype, reader, ref objectAdd.Nulls, objectNumbers: objectAdd.Numbers, objectBooleans: objectAdd.Booleans, objectStrings: objectAdd.Strings, property: property); hasProperty = false; } } } break; default: parseType(type, reader, ref amfData.Nulls, amfData.Numbers, amfData.Booleans, amfData.Strings); break; }*/ } }
internal BigRational ReadRational(EndianBinaryReader reader) { int sign = reader.ReadInt32(); long len = reader.ReadInt64(); byte[] num = new byte[len + 1]; // Extra byte for sign forcing positive value long l = ReadLongBuffer(num, len, reader); if (l != len) throw new InvalidOperationException(); // Non recoverable.. len = reader.ReadInt64(); byte[] den = new byte[len + 1]; // Extra byte on the end for positive sign l = ReadLongBuffer(den, len, reader); if (l != len) throw new InvalidOperationException(); // TODO Create a new ProtocolException() for when server sends unexpected data return new BigRational(new BigInteger(num) * sign, new BigInteger(den)); }
protected override void ParseChunkData(System.IO.MemoryStream memory) { base.ParseChunkData(memory); var reader = new EndianBinaryReader(EndianBitConverter.Big, memory); WindowSize = reader.ReadInt32(); }