public static CelestialLog FromStream(IStarboundStream stream) { CelestialLog log = new CelestialLog(); byte[] logDat = stream.ReadUInt8Array(); using (StarboundStream s = new StarboundStream(logDat)) { uint visited = s.ReadUInt32(); for (int i = 0; i < visited; i++) { log.Visited.Add(s.ReadSystemCoordinate()); } uint sectors = s.ReadUInt32(); for (int i = 0; i < sectors; i++) { log.Sectors.Add(new LogSector { SectorName = s.ReadString(), Unknown = s.ReadBoolean() }); } s.ReadUInt8(); //unknown log.CurrentSystem = s.ReadSystemCoordinate(); log.CurrentLocation = s.ReadWorldCoordinate(); log.HomeCoordinate = s.ReadWorldCoordinate(); } return(log); }
public IEnumerable <IPacket> UpdateBuffer(bool shouldCopy) { if (shouldCopy) { PacketBuffer.AddRange(NetworkBuffer); } Queue <byte[]> toProcess = new Queue <byte[]>(); toProcess.Enqueue(PacketBuffer.ToArray()); while (toProcess.Count > 0) { byte[] arr = toProcess.Dequeue(); using (StarboundStream s = new StarboundStream(arr)) { if (WorkingLength == long.MaxValue && s.Length > 1) { _packetId = s.ReadUInt8(); try { WorkingLength = s.ReadSignedVLQ(); } catch { WorkingLength = long.MaxValue; yield break; } DataIndex = (int)s.Position; Compressed = WorkingLength < 0; if (Compressed) { WorkingLength = -WorkingLength; } } if (WorkingLength != long.MaxValue) { if (s.Length >= WorkingLength + DataIndex) { if (s.Position != DataIndex) { s.Seek(DataIndex, SeekOrigin.Begin); } byte[] data = s.ReadUInt8Array((int)WorkingLength); if (Compressed) { data = ZlibStream.UncompressBuffer(data); } //todo Omit this after testing //SharpStarLogger.DefaultLogger.Info(string.Format("{0}{1}","ID : ",_packetId)); IPacket packet = Decode(_packetId, data); WorkingLength = long.MaxValue; byte[] rest = s.ReadToEnd(); PacketBuffer = rest.ToList(); if (rest.Length > 0) { toProcess.Enqueue(rest); } yield return(packet); } } } } }