public SignMapEntity DeserializeFromByteArray(byte[] data) { if (data.Length < SignMapEntity.DATA_SIZE) //using < for comparison because data will be an unknown length based on message { throw new ArgumentException("Data is improperly size for serialization", nameof(data)); } var sign = new SignMapEntity() .WithX(numberEncoderService.DecodeNumber(data[0])) .WithY(numberEncoderService.DecodeNumber(data[1])); var titleAndMessageLength = numberEncoderService.DecodeNumber(data[2], data[3]) - 1; if (data.Length != SignMapEntity.DATA_SIZE + titleAndMessageLength) { throw new ArgumentException("Data is improperly sized for deserialization", nameof(data)); } var rawTitleAndMessage = data.Skip(4).Take(titleAndMessageLength).ToArray(); var titleLength = numberEncoderService.DecodeNumber(data[4 + titleAndMessageLength]); var titleAndMessage = mapStringEncoderService.DecodeMapString(rawTitleAndMessage); sign = sign.WithTitle(titleAndMessage.Substring(0, titleLength)) .WithMessage(titleAndMessage.Substring(titleLength)); return(sign); }
public bool NeedsFileForLogin(InitFileType fileType, short optionalID = 0) { var expectedChecksum = _numberEncoderService.DecodeNumber(_loginFileChecksumProvider.MapChecksum); var expectedLength = _loginFileChecksumProvider.MapLength; return(fileType == InitFileType.Map ? NeedMap(optionalID, expectedChecksum, expectedLength) : NeedPub(fileType)); }
public UnknownMapEntity DeserializeFromByteArray(byte[] data) { if (data.Length != UnknownMapEntity.DATA_SIZE) { throw new ArgumentException("Data is improperly sized for deserialization", nameof(data)); } return(new UnknownMapEntity() .WithX(_numberEncoderService.DecodeNumber(data[0])) .WithY(_numberEncoderService.DecodeNumber(data[1])) .WithRawData(data)); }
public async Task RunReceiveLoopAsync() { while (!_backgroundReceiveCTS.IsCancellationRequested) { var lengthData = await _socket.ReceiveAsync(2, _backgroundReceiveCTS.Token); if (_backgroundReceiveCTS.IsCancellationRequested || lengthData.Length != 2) { break; } var length = _numberEncoderService.DecodeNumber(lengthData); var packetData = await _socket.ReceiveAsync(length, _backgroundReceiveCTS.Token); if (_backgroundReceiveCTS.IsCancellationRequested || packetData.Length != length) { break; } var packet = _packetProcessActions.DecodeData(packetData); LogReceivedPacket(packet); _packetHandlingActions.EnqueuePacketForHandling(packet); } }
private void ReadFromStream(Stream mem, INumberEncoderService numberEncoderService) { mem.Seek(3, SeekOrigin.Begin); var checksum = new byte[4]; mem.Read(checksum, 0, 4); CheckSum = numberEncoderService.DecodeNumber(checksum); var lenBytes = new byte[2]; mem.Read(lenBytes, 0, 2); var recordsInFile = (short)numberEncoderService.DecodeNumber(lenBytes); mem.Seek(1, SeekOrigin.Current); var rawData = new byte[ESFRecord.DATA_SIZE]; for (int i = 1; i <= recordsInFile && mem.Position < mem.Length; ++i) { var nameLength = numberEncoderService.DecodeNumber((byte)mem.ReadByte()); var shoutLength = numberEncoderService.DecodeNumber((byte)mem.ReadByte()); var rawName = new byte[nameLength]; var rawShout = new byte[shoutLength]; mem.Read(rawName, 0, nameLength); mem.Read(rawShout, 0, shoutLength); mem.Read(rawData, 0, ESFRecord.DATA_SIZE); var record = new ESFRecord { ID = i, Name = Encoding.ASCII.GetString(rawName), Shout = Encoding.ASCII.GetString(rawShout) }; record.DeserializeFromByteArray(rawData, numberEncoderService); _data.Add(record); } if (recordsInFile != Length) { throw new IOException("Mismatch between expected length and actual length!"); } }
public void DeserializeFromByteArray(byte[] recordBytes, INumberEncoderService numberEncoderService) { if (recordBytes.Length != DATA_SIZE) { throw new ArgumentOutOfRangeException(nameof(recordBytes), "Data is not properly sized for correct deserialization"); } Base = (byte)numberEncoderService.DecodeNumber(recordBytes[0]); Type = (byte)numberEncoderService.DecodeNumber(recordBytes[1]); Str = (short)numberEncoderService.DecodeNumber(recordBytes[2], recordBytes[3]); Int = (short)numberEncoderService.DecodeNumber(recordBytes[4], recordBytes[5]); Wis = (short)numberEncoderService.DecodeNumber(recordBytes[6], recordBytes[7]); Agi = (short)numberEncoderService.DecodeNumber(recordBytes[8], recordBytes[9]); Con = (short)numberEncoderService.DecodeNumber(recordBytes[10], recordBytes[11]); Cha = (short)numberEncoderService.DecodeNumber(recordBytes[12], recordBytes[13]); }
public ChestSpawnMapEntity DeserializeFromByteArray(byte[] data) { if (data.Length != ChestSpawnMapEntity.DATA_SIZE) { throw new ArgumentException("Data is improperly sized for deserialization", nameof(data)); } return(new ChestSpawnMapEntity() .WithX(_numberEncoderService.DecodeNumber(data[0])) .WithY(_numberEncoderService.DecodeNumber(data[1])) .WithKey((ChestKey)_numberEncoderService.DecodeNumber(data[2], data[3])) .WithSlot((byte)_numberEncoderService.DecodeNumber(data[4])) .WithItemID((short)_numberEncoderService.DecodeNumber(data[5], data[6])) .WithRespawnTime((short)_numberEncoderService.DecodeNumber(data[7], data[8])) .WithAmount(_numberEncoderService.DecodeNumber(data[9], data[10], data[11]))); }
public WarpMapEntity DeserializeFromByteArray(byte[] data) { if (data.Length != WarpMapEntity.DATA_SIZE) { throw new ArgumentException("Data is improperly sized for deserialization", nameof(data)); } return(new WarpMapEntity() .WithX(_numberEncoderService.DecodeNumber(data[0])) .WithDestinationMapID((short)_numberEncoderService.DecodeNumber(data[1], data[2])) .WithDestinationMapX((byte)_numberEncoderService.DecodeNumber(data[3])) .WithDestinationMapY((byte)_numberEncoderService.DecodeNumber(data[4])) .WithLevelRequirement((byte)_numberEncoderService.DecodeNumber(data[5])) .WithDoorType((DoorSpec)_numberEncoderService.DecodeNumber(data[6], data[7]))); }
public void DeserializeFromByteArray(byte[] recordBytes, INumberEncoderService numberEncoderService) { if (recordBytes.Length != DATA_SIZE) { throw new ArgumentOutOfRangeException(nameof(recordBytes), "Data is not properly sized for correct deserialization"); } Icon = (short)numberEncoderService.DecodeNumber(recordBytes[0], recordBytes[1]); Graphic = (short)numberEncoderService.DecodeNumber(recordBytes[2], recordBytes[3]); TP = (short)numberEncoderService.DecodeNumber(recordBytes[4], recordBytes[5]); SP = (short)numberEncoderService.DecodeNumber(recordBytes[6], recordBytes[7]); CastTime = (byte)numberEncoderService.DecodeNumber(recordBytes[8]); Type = (SpellType)numberEncoderService.DecodeNumber(recordBytes[11]); TargetRestrict = (SpellTargetRestrict)numberEncoderService.DecodeNumber(recordBytes[17]); Target = (SpellTarget)numberEncoderService.DecodeNumber(recordBytes[18]); MinDam = (short)numberEncoderService.DecodeNumber(recordBytes[23], recordBytes[24]); MaxDam = (short)numberEncoderService.DecodeNumber(recordBytes[25], recordBytes[26]); Accuracy = (short)numberEncoderService.DecodeNumber(recordBytes[27], recordBytes[28]); HP = (short)numberEncoderService.DecodeNumber(recordBytes[34], recordBytes[35]); }
public IMapFileProperties DeserializeFromByteArray(byte[] data) { IMapFileProperties properties = new MapFileProperties(); if (data.Length != MapFileProperties.DATA_SIZE) { throw new ArgumentException("Data is not sized correctly for proper deserialization", nameof(data)); } var typeString = Encoding.ASCII.GetString(data.Take(3).ToArray()); if (typeString != properties.FileType) { throw new FormatException("Data is not correctly formatted! Must be an EMF file header"); } var checksumArray = data.Skip(3).Take(4).ToArray(); var mapNameArray = data.Skip(7).Take(24).ToArray(); var mapName = _mapStringEncoderService.DecodeMapString(mapNameArray); properties = properties.WithChecksum(checksumArray) .WithName(mapName) .WithPKAvailable(_numberEncoderService.DecodeNumber(data[31]) == 3 || (mapNameArray[0] == 0xFF && mapNameArray[1] == 0x01)) .WithEffect((MapEffect)_numberEncoderService.DecodeNumber(data[32])) .WithMusic((byte)_numberEncoderService.DecodeNumber(data[33])) .WithMusicExtra((byte)_numberEncoderService.DecodeNumber(data[34])) .WithAmbientNoise((short)_numberEncoderService.DecodeNumber(data[35], data[36])) .WithWidth((byte)_numberEncoderService.DecodeNumber(data[37])) .WithHeight((byte)_numberEncoderService.DecodeNumber(data[38])) .WithFillTile((short)_numberEncoderService.DecodeNumber(data[39], data[40])) .WithMapAvailable(_numberEncoderService.DecodeNumber(data[41]) == 1) .WithScrollAvailable(_numberEncoderService.DecodeNumber(data[42]) == 1) .WithRelogX((byte)_numberEncoderService.DecodeNumber(data[43])) .WithRelogY((byte)_numberEncoderService.DecodeNumber(data[44])) .WithUnknown2((byte)_numberEncoderService.DecodeNumber(data[45])); return(properties); }
public byte PeekChar() { ThrowIfOutOfBounds(0); return((byte)_encoderService.DecodeNumber(RawData[ReadPosition])); }
public void DeserializeFromByteArray(byte[] recordBytes, INumberEncoderService numberEncoderService) { if (recordBytes.Length != DATA_SIZE) { throw new ArgumentOutOfRangeException(nameof(recordBytes), "Data is not properly sized for correct deserialization"); } Graphic = (short)numberEncoderService.DecodeNumber(recordBytes[0], recordBytes[1]); Type = (ItemType)numberEncoderService.DecodeNumber(recordBytes[2]); SubType = (ItemSubType)numberEncoderService.DecodeNumber(recordBytes[3]); Special = (ItemSpecial)numberEncoderService.DecodeNumber(recordBytes[4]); HP = (short)numberEncoderService.DecodeNumber(recordBytes[5], recordBytes[6]); TP = (short)numberEncoderService.DecodeNumber(recordBytes[7], recordBytes[8]); MinDam = (short)numberEncoderService.DecodeNumber(recordBytes[9], recordBytes[10]); MaxDam = (short)numberEncoderService.DecodeNumber(recordBytes[11], recordBytes[12]); Accuracy = (short)numberEncoderService.DecodeNumber(recordBytes[13], recordBytes[14]); Evade = (short)numberEncoderService.DecodeNumber(recordBytes[15], recordBytes[16]); Armor = (short)numberEncoderService.DecodeNumber(recordBytes[17], recordBytes[18]); Str = (byte)numberEncoderService.DecodeNumber(recordBytes[20]); Int = (byte)numberEncoderService.DecodeNumber(recordBytes[21]); Wis = (byte)numberEncoderService.DecodeNumber(recordBytes[22]); Agi = (byte)numberEncoderService.DecodeNumber(recordBytes[23]); Con = (byte)numberEncoderService.DecodeNumber(recordBytes[24]); Cha = (byte)numberEncoderService.DecodeNumber(recordBytes[25]); Light = (byte)numberEncoderService.DecodeNumber(recordBytes[26]); Dark = (byte)numberEncoderService.DecodeNumber(recordBytes[27]); Earth = (byte)numberEncoderService.DecodeNumber(recordBytes[28]); Air = (byte)numberEncoderService.DecodeNumber(recordBytes[29]); Water = (byte)numberEncoderService.DecodeNumber(recordBytes[30]); Fire = (byte)numberEncoderService.DecodeNumber(recordBytes[31]); ScrollMap = numberEncoderService.DecodeNumber(recordBytes[32], recordBytes[33], recordBytes[34]); ScrollX = (byte)numberEncoderService.DecodeNumber(recordBytes[35]); ScrollY = (byte)numberEncoderService.DecodeNumber(recordBytes[36]); LevelReq = (short)numberEncoderService.DecodeNumber(recordBytes[37], recordBytes[38]); ClassReq = (short)numberEncoderService.DecodeNumber(recordBytes[39], recordBytes[40]); StrReq = (short)numberEncoderService.DecodeNumber(recordBytes[41], recordBytes[42]); IntReq = (short)numberEncoderService.DecodeNumber(recordBytes[43], recordBytes[44]); WisReq = (short)numberEncoderService.DecodeNumber(recordBytes[45], recordBytes[46]); AgiReq = (short)numberEncoderService.DecodeNumber(recordBytes[47], recordBytes[48]); ConReq = (short)numberEncoderService.DecodeNumber(recordBytes[49], recordBytes[50]); ChaReq = (short)numberEncoderService.DecodeNumber(recordBytes[51], recordBytes[52]); Weight = (byte)numberEncoderService.DecodeNumber(recordBytes[55]); Size = (ItemSize)numberEncoderService.DecodeNumber(recordBytes[57]); if (ID == 365 && Name == "Gun") { SubType = ItemSubType.Ranged; } }
private List <NPCSpawnMapEntity> ReadNPCSpawns(MemoryStream ms) { var npcSpawns = new List <NPCSpawnMapEntity>(); var collectionSize = _numberEncoderService.DecodeNumber((byte)ms.ReadByte()); for (int i = 0; i < collectionSize; ++i) { var npcSpawnData = new byte[NPCSpawnMapEntity.DATA_SIZE]; ms.Read(npcSpawnData, 0, NPCSpawnMapEntity.DATA_SIZE); npcSpawns.Add(_npcSpawnMapEntitySerializer.DeserializeFromByteArray(npcSpawnData)); } return(npcSpawns); }
public void DeserializeFromByteArray(byte[] recordBytes, INumberEncoderService numberEncoderService) { if (recordBytes.Length != DATA_SIZE) { throw new ArgumentOutOfRangeException(nameof(recordBytes), "Data is not properly sized for correct deserialization"); } Graphic = numberEncoderService.DecodeNumber(recordBytes[0], recordBytes[1]); Boss = (short)numberEncoderService.DecodeNumber(recordBytes[3], recordBytes[4]); Child = (short)numberEncoderService.DecodeNumber(recordBytes[5], recordBytes[6]); Type = (NPCType)numberEncoderService.DecodeNumber(recordBytes[7], recordBytes[8]); VendorID = (short)numberEncoderService.DecodeNumber(recordBytes[9], recordBytes[10]); HP = numberEncoderService.DecodeNumber(recordBytes[11], recordBytes[12], recordBytes[13]); MinDam = (short)numberEncoderService.DecodeNumber(recordBytes[16], recordBytes[17]); MaxDam = (short)numberEncoderService.DecodeNumber(recordBytes[18], recordBytes[19]); Accuracy = (short)numberEncoderService.DecodeNumber(recordBytes[20], recordBytes[21]); Evade = (short)numberEncoderService.DecodeNumber(recordBytes[22], recordBytes[23]); Armor = (short)numberEncoderService.DecodeNumber(recordBytes[24], recordBytes[25]); Exp = (ushort)numberEncoderService.DecodeNumber(recordBytes[36], recordBytes[37]); }