public D2pFile(string file) { FilePath = file; m_reader = new BigEndianReader(File.OpenRead(file)); InternalOpen(); }
public static EntityGraphicalElementData ReadFromStream(EleInstance instance, int id, BigEndianReader reader) { var data = new EntityGraphicalElementData(instance, id); data.EntityLook = reader.ReadUTF7BitLength(); data.HorizontalSymmetry = reader.ReadBoolean(); if (instance.Version >= 7) { data.PlayAnimation = reader.ReadBoolean(); } if (instance.Version >= 6) { data.PlayAnimStatic = reader.ReadBoolean(); } if (instance.Version >= 5) { data.MinDelay = reader.ReadUInt(); data.MaxDelay = reader.ReadUInt(); } return data; }
public static ParticlesGraphicalElementData ReadFromStream(EleInstance instance, int id, BigEndianReader reader) { var data = new ParticlesGraphicalElementData(instance, id); data.ScriptId = reader.ReadShort(); return data; }
private void ChangeStream(Stream stream) { m_stream.Dispose(); m_reader.Dispose(); m_stream = stream; m_reader = new BigEndianReader(m_stream); }
public SwlFile(Stream stream) { m_stream = stream; m_reader = new BigEndianReader(m_stream); Classes = new List<string>(); ReadFile(); }
public static new BoundingBoxGraphicalElementData ReadFromStream(EleInstance instance, int id, BigEndianReader reader) { var data = new BoundingBoxGraphicalElementData(instance, id); data.Gfx = reader.ReadInt(); data.Height = reader.ReadUInt(); data.HorizontalSymmetry = reader.ReadBoolean(); data.Origin = new System.Drawing.Point(reader.ReadShort(), reader.ReadShort()); data.Size = new System.Drawing.Point(reader.ReadShort(), reader.ReadShort()); return data; }
public static DlmFixture ReadFromStream(DlmMap map, BigEndianReader reader) { var fixture = new DlmFixture(map); fixture.FixtureId = reader.ReadInt(); fixture.Offset = new System.Drawing.Point(reader.ReadShort(), reader.ReadShort()); fixture.Rotation = reader.ReadShort(); fixture.ScaleX = reader.ReadShort(); fixture.ScaleY = reader.ReadShort(); fixture.Hue = reader.ReadByte() << 16 | reader.ReadByte() << 8 | reader.ReadByte(); fixture.Alpha = reader.ReadByte(); return fixture; }
public static DlmCell ReadFromStream(DlmLayer layer, BigEndianReader reader) { var cell = new DlmCell(layer); cell.Id = reader.ReadShort(); cell.Elements = new DlmBasicElement[reader.ReadShort()]; for (int i = 0; i < cell.Elements.Length; i++) { DlmBasicElement element = DlmBasicElement.ReadFromStream(cell, reader); cell.Elements[i] = element; } return cell; }
public static new AnimatedGraphicalElementData ReadFromStream(EleInstance instance, int id, BigEndianReader reader) { var data = new AnimatedGraphicalElementData(instance, id); data.Gfx = reader.ReadInt(); data.Height = reader.ReadUInt(); data.HorizontalSymmetry = reader.ReadBoolean(); data.Origin = new System.Drawing.Point(reader.ReadShort(), reader.ReadShort()); data.Size = new System.Drawing.Point(reader.ReadShort(), reader.ReadShort()); if (instance.Version == 4) { data.MinDelay = reader.ReadUInt(); data.MaxDelay = reader.ReadUInt(); } return data; }
public static EleGraphicalData ReadFromStream(EleInstance instance, BigEndianReader reader) { var id = reader.ReadInt(); var type = (EleGraphicalElementTypes)reader.ReadByte(); switch (type) { case EleGraphicalElementTypes.ANIMATED: return AnimatedGraphicalElementData.ReadFromStream(instance, id, reader); case EleGraphicalElementTypes.BLENDED: return BlendedGraphicalElementData.ReadFromStream(instance, id, reader); case EleGraphicalElementTypes.BOUNDING_BOX: return BoundingBoxGraphicalElementData.ReadFromStream(instance, id, reader); case EleGraphicalElementTypes.ENTITY: return EntityGraphicalElementData.ReadFromStream(instance, id, reader); case EleGraphicalElementTypes.NORMAL: return NormalGraphicalElementData.ReadFromStream(instance, id, reader); case EleGraphicalElementTypes.PARTICLES: return ParticlesGraphicalElementData.ReadFromStream(instance, id, reader); default: throw new Exception("Unknown graphical data of type " + type); } }
public static EleInstance ReadFromStream(BigEndianReader reader) { var instance = new EleInstance(); instance.Version = reader.ReadByte(); var count = reader.ReadUInt(); for (int i = 0; i < count; i++) { var elem = EleGraphicalData.ReadFromStream(instance, reader); instance.GraphicalDatas.Add(elem.Id, elem); } if (instance.Version >= 8) { var gfxCount = reader.ReadInt(); for (int i = 0; i < gfxCount; i++) { instance.GfxJpgMap.Add(reader.ReadInt(), true); } } return instance; }
public DlmReader(string filePath, string decryptionKey) { m_stream = File.OpenRead(filePath); m_reader = new BigEndianReader(m_stream); DecryptionKey = decryptionKey; }
public DlmReader(Stream stream) { m_stream = stream; m_reader = new BigEndianReader(m_stream); }
public DlmReader(string filePath) { m_stream = File.OpenRead(filePath); m_reader = new BigEndianReader(m_stream); }
private void BuildMessage() { if (m_buffer.BytesAvailable <= 0) return; if (m_currentMessage == null) m_currentMessage = new MessagePart(); // if message is complete if (m_currentMessage.Build(m_buffer)) { var messageDataReader = new BigEndianReader(m_currentMessage.Data); var message = MessageBuilder.BuildMessage((uint)m_currentMessage.MessageId.Value, messageDataReader); LastActivity = DateTime.Now; OnMessageReceived(message); m_currentMessage = null; BuildMessage(); // there is maybe a second message in the buffer } }
private void InternalOpen() { if (!Stream.CanSeek) m_reader = m_reader.ReadBytesInNewBigEndianReader((int) m_reader.BytesAvailable); if (m_reader.ReadByte() != 2 || m_reader.ReadByte() != 1) throw new FileLoadException("Corrupted d2p header"); ReadTable(); ReadProperties(); ReadEntriesDefinitions(); }
public D2pFile() { IndexTable = new D2pIndexTable(this); m_reader = new BigEndianReader(new byte[0]); }
public static DlmCellData ReadFromStream(DlmMap map, short id, BigEndianReader reader) { var cell = new DlmCellData(map, id); cell.Floor = (short) (reader.ReadByte()*10); if (cell.Floor == -1280) { return cell; } cell.LosMov = reader.ReadByte(); cell.Speed = reader.ReadByte(); cell.MapChangeData = reader.ReadByte(); if (map.Version > 5) { cell.MoveZone = reader.ReadByte(); } return cell; }
public virtual void Receive(byte[] data, int offset, int count) { lock (m_recvLocker) { m_buffer.Add(data, offset, count); while (m_buffer.BytesAvailable > 0) { if (m_currentMessage == null) m_currentMessage = new MessagePart(); // if message is complete if (m_currentMessage.Build(m_buffer)) { var messageDataReader = new BigEndianReader(m_currentMessage.Data); NetworkMessage message = MessageBuilder.BuildMessage((uint)m_currentMessage.MessageId.Value, messageDataReader); LastActivity = DateTime.Now; OnMessageReceived(message); m_currentMessage = null; } } } }
public DlmReader(Stream stream, string decryptionKey) { m_stream = stream; m_reader = new BigEndianReader(m_stream); DecryptionKey = decryptionKey; }
/// <summary> /// Build or continue building the message. Returns true if the resulted message is valid and ready to be parsed /// </summary> public bool Build(BigEndianReader reader) { if (IsValid) return true; if (reader.BytesAvailable >= 2 && !Header.HasValue) { Header = reader.ReadShort(); } if (LengthBytesCount.HasValue && reader.BytesAvailable >= LengthBytesCount && !Length.HasValue) { if (LengthBytesCount < 0 || LengthBytesCount > 3) throw new Exception("Malformated Message Header, invalid bytes number to read message length (inferior to 0 or superior to 3)"); Length = 0; // 3..0 or 2..0 or 1..0 for (int i = LengthBytesCount.Value - 1; i >= 0; i--) { Length |= reader.ReadByte() << (i * 8); } } // first case : no data read if (Data == null && Length.HasValue) { if (Length == 0) Data = new byte[0]; // enough bytes in the buffer to build a complete message if (reader.BytesAvailable >= Length) { Data = reader.ReadBytes(Length.Value); } // not enough bytes, so we read what we can else if (Length > reader.BytesAvailable) { Data = reader.ReadBytes((int) reader.BytesAvailable); } } //second case : the message was split and it missed some bytes if (Data != null && Length.HasValue && Data.Length < Length) { int bytesToRead = 0; // still miss some bytes ... if (Data.Length + reader.BytesAvailable < Length) bytesToRead = (int)reader.BytesAvailable; // there is enough bytes in the buffer to complete the message :) else if(Data.Length + reader.BytesAvailable >= Length) bytesToRead = Length.Value - Data.Length; if(bytesToRead != 0) { int oldLength = Data.Length; Array.Resize(ref m_data, (int)( Data.Length + bytesToRead )); Array.Copy(reader.ReadBytes(bytesToRead), 0, Data, oldLength, bytesToRead); } } return IsValid; }
public static DlmMap ReadFromStream(BigEndianReader givenReader, DlmReader dlmReader) { var reader = givenReader; var map = new DlmMap(); map.Version = reader.ReadByte(); map.Id = reader.ReadInt(); if (map.Version >= 7) { map.Encrypted = reader.ReadBoolean(); map.EncryptionVersion = reader.ReadByte(); var len = reader.ReadInt(); if (map.Encrypted) { var key = dlmReader.DecryptionKey; if (key == null && dlmReader.DecryptionKeyProvider != null) key = dlmReader.DecryptionKeyProvider(map.Id); if (key == null) { throw new InvalidOperationException(string.Format("Cannot decrypt the map {0} without decryption key", map.Id)); } var data = reader.ReadBytes(len); var encodedKey = Encoding.Default.GetBytes(key); if (key.Length > 0) { for (int i = 0; i < data.Length; i++) { data[i] = (byte)( data[i] ^ encodedKey[i % key.Length] ); } reader = new BigEndianReader(new MemoryStream(data)); } } } map.RelativeId = reader.ReadUInt(); map.MapType = reader.ReadByte(); map.SubAreaId = reader.ReadInt(); map.TopNeighbourId = reader.ReadInt(); map.BottomNeighbourId = reader.ReadInt(); map.LeftNeighbourId = reader.ReadInt(); map.RightNeighbourId = reader.ReadInt(); map.ShadowBonusOnEntities = reader.ReadInt(); if (map.Version >= 3) { map.BackgroundColor = Color.FromArgb(reader.ReadByte(), reader.ReadByte(), reader.ReadByte()); } if (map.Version >= 4) { map.ZoomScale = reader.ReadUShort(); map.ZoomOffsetX = reader.ReadShort(); map.ZoomOffsetY = reader.ReadShort(); } map.UseLowPassFilter = reader.ReadByte() == 1; map.UseReverb = reader.ReadByte() == 1; if (map.UseReverb) { map.PresetId = reader.ReadInt(); } { map.PresetId = -1; } map.BackgroudFixtures = new DlmFixture[reader.ReadByte()]; for (int i = 0; i < map.BackgroudFixtures.Length; i++) { map.BackgroudFixtures[i] = DlmFixture.ReadFromStream(map, reader); } map.ForegroundFixtures = new DlmFixture[reader.ReadByte()]; for (int i = 0; i < map.ForegroundFixtures.Length; i++) { map.ForegroundFixtures[i] = DlmFixture.ReadFromStream(map, reader); } reader.ReadInt(); map.GroundCRC = reader.ReadInt(); map.Layers = new DlmLayer[reader.ReadByte()]; for (int i = 0; i < map.Layers.Length; i++) { map.Layers[i] = DlmLayer.ReadFromStream(map, reader); } map.Cells = new DlmCellData[CellCount]; int? lastMoveZone = null; for (short i = 0; i < map.Cells.Length; i++) { map.Cells[i] = DlmCellData.ReadFromStream(map, i, reader); if (!lastMoveZone.HasValue) lastMoveZone = map.Cells[i].MoveZone; else if (lastMoveZone != map.Cells[i].MoveZone) // if a cell is different the new system is used map.UsingNewMovementSystem = true; } return map; }
public static new DlmGraphicalElement ReadFromStream(DlmCell cell, BigEndianReader reader) { var element = new DlmGraphicalElement(cell); element.m_elementId = reader.ReadUInt(); element.m_hue = new ColorMultiplicator(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), false); element.m_shadow = new ColorMultiplicator(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), false); if (cell.Layer.Map.Version <= 4) { element.m_offset.X = reader.ReadByte(); element.m_offset.Y = reader.ReadByte(); element.m_pixelOffset.X = (int) (element.m_offset.X * CELL_HALF_WIDTH); element.m_pixelOffset.Y = (int) (element.m_offset.Y * CELL_HALF_HEIGHT); } else { element.m_pixelOffset.X = reader.ReadShort(); element.m_pixelOffset.Y = reader.ReadShort(); element.m_offset.X = (int)( element.m_pixelOffset.X / CELL_HALF_WIDTH ); element.m_offset.Y = (int)( element.m_pixelOffset.Y / CELL_HALF_HEIGHT ); } element.m_altitude = reader.ReadByte(); element.m_identifier = reader.ReadUInt(); element.CalculateFinalTeint(); return element; }
private void Initialize() { using (var reader = new BigEndianReader(new StreamReader(m_uri).BaseStream)) { var indexPos = reader.ReadInt(); reader.Seek(indexPos, SeekOrigin.Begin); var indexLen = reader.ReadInt(); for (int i = 0; i < indexLen; i += 8) { var key = reader.ReadInt(); var dataPos = reader.ReadInt(); var pos = (int)reader.BaseStream.Position; reader.Seek(dataPos, SeekOrigin.Begin); m_indexes.Add(key, reader.ReadUTF()); reader.Seek(pos, SeekOrigin.Begin); } while (reader.BytesAvailable > 0) { var key = reader.ReadUTF(); var dataPos = reader.ReadInt(); var pos = (int)reader.BaseStream.Position; reader.Seek(dataPos, SeekOrigin.Begin); m_textIndexes.Add(key, reader.ReadUTF()); reader.Seek(pos, SeekOrigin.Begin); } } }