private static void OnCompressedGump(PacketReader p, PacketHandlerEventArgs e) { p.Seek(7, SeekOrigin.Begin); if (p.ReadUInt32() != 0x776CCCC1) { return; } p.Seek(19, SeekOrigin.Begin); p.Seek(p.ReadInt32(), SeekOrigin.Current); int lines = p.ReadInt32(), cLen = p.ReadInt32(), dLen = p.ReadInt32(); byte[] buffer = new byte[dLen]; ZLib.uncompress(buffer, ref dLen, p.CopyBytes(p.Position, cLen - 4), cLen - 4); for (int i = 0, pos = 0; i < lines; i++) { int strLen = (buffer[pos++] << 8) | buffer[pos++]; string str = Encoding.BigEndianUnicode.GetString(buffer, pos, strLen * 2); if (str.Trim() == "a sea horse") { WorldEx.SendMessage("Sea Horse!!! " + World.Player.Position); } pos += strLen * 2; } }
public void Write(Stream input, uint offset) { using (var bw = new BinaryWriterX(input, true)) { bw.BaseStream.Position = offset; if (State == ArchiveFileState.Archived) { base.FileData.CopyTo(bw.BaseStream); bw.WriteAlignment(0x10, (byte)new Random().Next()); } else { if (entry.decompSize == 0) { entry.offset = offset; entry.compSize = (uint)base.FileData.Length; base.FileData.CopyTo(bw.BaseStream); bw.WriteAlignment(0x10, (byte)new Random().Next()); } else { entry.offset = offset; entry.decompSize = (uint)base.FileData.Length; var comp = ZLib.Compress(base.FileData); entry.compSize = (uint)comp.Length; bw.Write(comp); bw.WriteAlignment(0x10, (byte)new Random().Next()); } } } }
private static byte[] CompressData(byte[] data) { byte[] prefix = { 0x00, 0x00, 0x06, 0x00 }; // These bytes are important, otherwise the game won't launch byte[] compressedData = ZLib.CompressData(data); return(prefix.Concat(compressedData).ToArray()); }
public SaveResult Save(string filename = "") { SaveResult result = SaveResult.Success; if (!string.IsNullOrEmpty(filename)) { FileInfo = new FileInfo(filename); } try { var ms = new MemoryStream(); _sarc.Save(ms, true); using (var bw = new BinaryWriterX(FileInfo.Create())) { bw.Write(BitConverter.GetBytes((int)ms.Length).Reverse().ToArray()); bw.Write(ZLib.Compress(ms.ToArray())); } } catch { result = SaveResult.Failure; } return(result); }
private static void Main(string[] args) { Options.Initialize(args); Encoding.Initalize(Settings.Default.UseUTF8); ZLib.Initialize(); try { AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; Settings.Default.Reload(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var main = new MainView(); foreach (string arg in Options.Value.Plugins) { main.LoadPlugin(arg); } try { Application.Run(main); Settings.Default.Save(); } catch (Exception ex) { MessageBox.Show("Error running main window: \n" + ex, Resources.ErrorText); } } catch (Exception ex) { MessageBox.Show("Error initializing main view: \n" + ex, Resources.ErrorText); } }
/// <summary> /// Read the metadata using the supplied reader. /// </summary> /// <param name="reader">The reader to use to read the metadata with. It is /// already positioned at the first byte of metadata.</param> /// <param name="nCompressedLen">The length of the compressed metadata. The first /// four bytes is the size of the uncompressed data.</param> public BookMetaData DeserializeMetaData(BinaryReader reader, int nCompressedLen) { Debug.WriteLineIf(s_bDebugMode, "Reading metadata"); byte[] byUncompressedData = ZLib.Decompress(reader, nCompressedLen); Debug.WriteLineIf(s_bDebugMode, "Parsing metadata"); MemoryStream xmlStream = new MemoryStream(byUncompressedData); XmlSerializer serializer = new XmlSerializer(typeof(BookMetaData)); XmlTextReader xreader = new XmlTextReader(xmlStream); BookMetaData metaData = null; try { metaData = (BookMetaData)serializer.Deserialize(xreader); } catch (Exception e) { Debug.WriteLineIf(s_bDebugMode, e.ToString()); } xreader.Close(); return(metaData); }
internal static void Obj_AI_Base_OnStealth(Obj_AI_Base sender, Obj_AI_BaseMissileClientDataEventArgs args) { #region Stealth var attacker = sender as Obj_AI_Hero; if (attacker == null || attacker.IsAlly || !attacker.IsValid) { return; } foreach (var hero in ZLib.GetUnits().Where(h => h.Instance.Distance(attacker) <= 1000)) { foreach (var entry in ZLib.CachedSpells.Where(s => s.EventTypes.Contains(EventType.Stealth))) { if (entry.SpellName.ToLower() == args.SpellData.Name.ToLower()) { EmulateDamage(sender, hero, new Gamedata { SpellName = "Stealth" }, EventType.Stealth, "process.onstealth"); break; } } } #endregion }
private ServerPacket MakeCreatePacket(WorldObject obj) { BinWriter w = new BinWriter(); w.Write(0); w.Write((uint)0); w.Write(2); obj.AddCreateObject(w, false, true); int count = 1; if (obj.ObjectType == OBJECTTYPE.PLAYER) { PlayerObject plr = obj as PlayerObject; count += plr.Inventory.AddCreateInventory(w, false); } w.Set(0, count); ServerPacket pkg = new ServerPacket(SMSG.COMPRESSED_UPDATE_OBJECT); byte[] compressed = ZLib.Compress(w.GetBuffer(), 0, (int)w.BaseStream.Length); pkg.Write((int)w.BaseStream.Length); pkg.Write(compressed); pkg.Finish(); return(pkg); }
public uint Write(Stream stream) { using (var bw = new BinaryWriterX(stream, true)) { if (State == ArchiveFileState.Archived) { base.FileData.Position = 0; base.FileData.CopyTo(bw.BaseStream); return((uint)base.FileData.Length); } else { if (compressed) { var comp = ZLib.Compress(FileData); bw.Write(comp.Length); bw.Write((comp.Length + 0xf) & ~0xf); bw.WritePadding(0x18); bw.Write(comp); bw.WriteAlignment(); return((uint)((comp.Length + 0xf) & ~0xf) + 0x20); } else { bw.Write((uint)FileData.Length); bw.Write((uint)((FileData.Length + 0xf) & ~0xf)); bw.WritePadding(0x18); FileData.CopyTo(bw.BaseStream); bw.WriteAlignment(); return((uint)((FileData.Length + 0xf) & ~0xf) + 0x20); } } } }
public uint CompressPacket(byte[] data, ServerOpcodes opcode) { byte[] uncompressedData = BitConverter.GetBytes((ushort)opcode).Combine(data); uint bufferSize = ZLib.deflateBound(_compressionStream, (uint)uncompressedData.Length); byte[] outPrt = new byte[bufferSize]; _compressionStream.next_out = 0; _compressionStream.avail_out = bufferSize; _compressionStream.out_buf = outPrt; _compressionStream.next_in = 0; _compressionStream.avail_in = (uint)uncompressedData.Length; _compressionStream.in_buf = uncompressedData; int z_res = ZLib.deflate(_compressionStream, 2); if (z_res != 0) { Log.outError(LogFilter.Network, "Can't compress packet data (zlib: deflate) Error code: {0} msg: {1}", z_res, _compressionStream.msg); return(0); } uint compressedSize = bufferSize - _compressionStream.avail_out; Buffer.BlockCopy(outPrt, 0, data, 0, (int)compressedSize); return(compressedSize); }
private void ReadInitialLoadSegment(ref ShockwaveReader input, AfterBurnerMapEntry[] entries, Dictionary <int, ChunkItem> chunks) { //First entry in the AfterBurnerMap must be ILS. AfterBurnerMapEntry ilsEntry = entries[0]; input.Advance(ilsEntry.Offset); //TODO: this shouldn't be here ReadOnlySpan <byte> compressedData = input.ReadBytes(ilsEntry.Length); Span <byte> decompressedData = ilsEntry.DecompressedLength <= 1024 ? stackalloc byte[ilsEntry.DecompressedLength] : new byte[ilsEntry.DecompressedLength]; ZLib.Decompress(compressedData, decompressedData); ShockwaveReader ilsReader = new ShockwaveReader(decompressedData, input.IsBigEndian); while (ilsReader.IsDataAvailable) { int id = ilsReader.Read7BitEncodedInt(); AfterBurnerMapEntry entry = entries.FirstOrDefault(e => e.Id == id); //TODO: Chunk entries as dictionary if (entry == null) { break; } chunks.Add(id, Read(ref ilsReader, entry.Header)); } }
public ChunkReader(byte[] expectedMagicNumber, Stream stream, HashSet <ChunkId> knownChunkList = null) { _knownChunkList = knownChunkList; // Check file type byte[] magicNumber = new byte[expectedMagicNumber.Length]; stream.Read(magicNumber, 0, expectedMagicNumber.Length); if (!magicNumber.SequenceEqual(expectedMagicNumber)) { throw new NotSupportedException("The header of the file was unrecognizable. Most likely it is not a valid file."); } // Check chunk type uint chunkVersion = new BinaryReader(stream).ReadUInt32(); if ((chunkVersion & 0x7fffffffu) != 0) { throw new NotSupportedException("Chunk version " + chunkVersion + " is not supported"); } if ((chunkVersion & 0x80000000u) != 0) { int compressedSize = new BinaryReader(stream).ReadInt32(); byte[] compressedBuffer = new byte[compressedSize]; stream.Read(compressedBuffer, 0, compressedSize); byte[] decompressedBuffer = ZLib.DecompressData(compressedBuffer); _reader = new BinaryReaderEx(new MemoryStream(decompressedBuffer)); } else { _reader = new BinaryReaderEx(stream); } }
public static Packet Compress(Packet p) { byte[] source = p.Compile(false); if (source.Length > 100 && source.Length < 60000) { byte[] dest = new byte[(int)(source.Length * 1.001) + 1]; int destSize = dest.Length; ZLibError error = ZLib.compress2(dest, ref destSize, source, source.Length, ZLibCompressionLevel.Z_BEST_COMPRESSION); // best compression (slowest) if (error != ZLibError.Z_OK) { log.Error(String.Format("Unable to compress admin packet, zlib error: {0}", error)); return(p); } else { return(new AdminCompressedPacket(dest, destSize, source.Length)); } } else { return(p); } }
public void Write(Stream output, long offset, ByteOrder byteOrder) { using (var bw = new BinaryWriterX(output, true, byteOrder)) { Metadata.Offset = (int)offset; if (State == ArchiveFileState.Archived) { base.FileData.CopyTo(bw.BaseStream); } else { if (CompressionLevel != CompressionLevel.NoCompression) { var bytes = ZLib.Compress(FileData, CompressionLevel, true); bw.Write(bytes); Metadata.CompressedSize = bytes.Length; } else { FileData.CopyTo(bw.BaseStream); Metadata.CompressedSize = (int)FileData.Length; } Metadata.UncompressedSize = System == Platform.CTR ? (int)(FileData.Length & 0x00FFFFFF) : (int)(FileData.Length << 3); } } }
public static Packet Compress(Packet p) { int length; byte[] source = p.Compile(false, out length); if (length > 100 && length < 60000) { byte[] dest = new byte[(int)(length * 1.001) + 1]; int destSize = dest.Length; ZLibError error = ZLib.compress2(dest, ref destSize, source, length, ZLibCompressionLevel.Z_BEST_COMPRESSION); // best compression (slowest) if (error != ZLibError.Z_OK) { Console.WriteLine("WARNING: Unable to compress admin packet, zlib error: {0}", error); return(p); } else { return(new AdminCompressedPacket(dest, destSize, length)); } } else { return(p); } }
internal void CreatePlayerObject(bool isClient) { try { // at enter world DebugLogger.Logger.Log("I have a feeling... that this is whats causing it to not work."); BinWriter w = new BinWriter(); w.Write((byte)1); w.Write((uint)0); if (isClient == false) { w.Write((byte)2); Console.WriteLine("DEBUG: 2"); } else { w.Write((byte)3); Console.WriteLine("DEBUG: 3"); } m_player.AddCreateObject(w, true, true); BinWriter pkg = new BinWriter(); pkg.Write((int)w.BaseStream.Length); pkg.Write(ZLib.Compress(w.GetBuffer(), 0, (int)w.BaseStream.Length)); Send(SMSG.COMPRESSED_UPDATE_OBJECT, pkg); m_player.updateTime(); } catch (Exception exp) { DebugLogger.Logger.Log("", exp); } }
void InitializeHandler(SocketAsyncEventArgs args) { if (args.SocketError != SocketError.Success) { CloseSocket(); return; } if (args.BytesTransferred > 0) { if (_packetBuffer.GetRemainingSpace() > 0) { // need to receive the header int readHeaderSize = Math.Min(args.BytesTransferred, _packetBuffer.GetRemainingSpace()); _packetBuffer.Write(args.Buffer, 0, readHeaderSize); if (_packetBuffer.GetRemainingSpace() > 0) { // Couldn't receive the whole header this time. AsyncReadWithCallback(InitializeHandler); return; } ByteBuffer buffer = new ByteBuffer(_packetBuffer.GetData()); string initializer = buffer.ReadString((uint)ClientConnectionInitialize.Length); if (initializer != ClientConnectionInitialize) { CloseSocket(); return; } byte terminator = buffer.ReadUInt8(); if (terminator != '\n') { CloseSocket(); return; } // Initialize the zlib stream _compressionStream = new ZLib.z_stream(); // Initialize the deflate algo... var z_res1 = ZLib.deflateInit2(_compressionStream, 1, 8, -15, 8, 0); if (z_res1 != 0) { CloseSocket(); Log.outError(LogFilter.Network, "Can't initialize packet compression (zlib: deflateInit2_) Error code: {0}", z_res1); return; } _packetBuffer.Reset(); HandleSendAuthSession(); AsyncRead(); return; } } AsyncReadWithCallback(InitializeHandler); }
internal override void SaveData(BinaryWriter writer) { var position = writer.BaseStream.Position; WriteString(writer, Name); uint realSize; var compressed = false; byte[] data; using (var stream = new MemoryStream()) { var dataWriter = new BinaryWriter(stream); foreach (var subRecord in this.SubRecords) { subRecord.SaveData(dataWriter); } realSize = (uint)stream.Length; if (Properties.Settings.Default.UseDefaultRecordCompression) { compressed = ((this.Flags1 & 0x00040000) != 0) || (Properties.Settings.Default.EnableAutoCompress && Compressor.CompressRecord(Name)) || (Properties.Settings.Default.EnableCompressionLimit && (realSize >= Properties.Settings.Default.CompressionLimit)); } data = stream.ToArray(); if (compressed) { data = ZLib.Compress(data); } } var dataSize = (uint)data.Length; var flags = this.Flags1 & ~0x00040000U; if (compressed) { dataSize += 4; flags |= 0x00040000; Debug.WriteLineIf( this.dataSize != dataSize, string.Format( "COMPRESSED RECORD [NAME={0} AT POSITION={1}] SIZE DIFFERS FROM ORIGINAL: ORIGINAL={2} ACTUAL={3}, RAW RECORD SIZE={4}", Name, position, this.dataSize, dataSize, realSize)); } writer.Write(dataSize); // Size of compressed section + length writer.Write(flags); writer.Write(this.FormID); writer.Write(this.Flags2); writer.Write(this.Flags3); if (compressed) { writer.Write(realSize); } writer.Write(data, 0, data.Length); }
static void OnItemVendor(int msgID, BinReader data) { uint charID = data.ReadUInt32(); uint itemId = data.ReadUInt32(); int price = data.ReadInt32(); WorldClient client = WorldServer.GetClientByCharacterID(charID); if (client == null) { return; } if (client.Player.Money < price) { Chat.System(client, "You do not have the required funds for this item"); return; } DBItem newitem = (DBItem)DBManager.GetDBObject(typeof(DBItem), itemId); if (newitem == null) { Chat.System(client, "Item not found"); return; } newitem.Template = (DBItemTemplate)DBManager.GetDBObject(typeof(DBItemTemplate), newitem.TemplateID); if (newitem.Template == null) { Chat.System(client, "Item Template not found"); return; } Console.WriteLine("Slot:" + newitem.OwnerSlot); if (newitem.OwnerSlot == 0) { newitem.OwnerSlot = client.Player.Inventory.GetOpenBackpackSlot(); } DBManager.SaveDBObject(newitem); ItemObject NewObj = (ItemObject)client.Player.Inventory.CreateItem(newitem); // client.Player.MapTile.Map.Enter(NewObj); BinWriter w = new BinWriter(); w.Write(1); w.Write((byte)0); NewObj.AddCreateObject(w, false, true); ServerPacket pkg = new ServerPacket(SMSG.COMPRESSED_UPDATE_OBJECT); byte[] compressed = ZLib.Compress(w.GetBuffer(), 0, (int)w.BaseStream.Length); pkg.Write((int)w.BaseStream.Length); pkg.Write(compressed); pkg.Finish(); client.Player.MapTile.SendSurrounding(pkg); client.Player.Money = client.Player.Money - price; client.Player.UpdateData(); // Chat.System (client, "Buy Item working on Worldserver side"); }
// Used for protobuf json strings. public static byte[] Compress <T>(T data, string prefix) { var jsonData = Encoding.UTF8.GetBytes($"{prefix}:{CreateString(data)}\0"); var jsonDataLength = BitConverter.GetBytes(jsonData.Length); var uncompressedAdler = BitConverter.GetBytes(Adler32.Calculate(jsonData)).Reverse().ToArray(); return(jsonDataLength.Combine(ZLib.Compress(jsonData), uncompressedAdler)); }
//public unsafe T[] GetData<T>(int compressedSize, int uncompressedSize) where T : struct //{ // T[] data = new T[uncompressedSize]; // IntPtr destPtr = (IntPtr) UnsafeMemoryManager.AsPointer(ref data); // ZLib.Decompress(PositionAddress, compressedSize, 0, destPtr, uncompressedSize); // return data; //} public unsafe byte[] GetData(int compressedSize, int uncompressedSize) { byte[] data = new byte[uncompressedSize]; fixed(byte *destPtr = data) ZLib.Decompress(PositionAddress, compressedSize, 0, (IntPtr)destPtr, uncompressedSize); return(data); }
public void Load(string filename) { FileInfo = new FileInfo(filename); using (var br = new BinaryReaderX(FileInfo.OpenRead())) { br.ReadBytes(4); _sarc = new SARC(new MemoryStream(ZLib.Decompress(new MemoryStream(br.ReadBytes((int)FileInfo.Length - 4))))); } }
internal static byte[] Decode(byte[] arr, AesDecryptor aesDecryptor, ref int recvIdx) { byte flag = arr[0]; bool ziped = ((flag & 0x80) == 0x80); bool aesed = ((flag & 0x40) == 0x40); bool crced = ((flag & 0x20) == 0x20); int idx = flag & 0x1F; if (recvIdx == idx) { recvIdx++; if (recvIdx > 0x1F) { recvIdx = 0; } Byte[] bcrc = new Byte[4]; Buffer.BlockCopy(arr, 1, bcrc, 0, 4); int crc32 = BitConverter.ToInt32(bcrc, 0); Byte[] data = new Byte[arr.Length - 1 - 4]; Buffer.BlockCopy(arr, 1 + 4, data, 0, data.Length); int ncrc32 = 0; if (crced) { ncrc32 = Crc.Crc32(data); } if (ncrc32 == crc32) { if (aesed) { data = aesDecryptor.Decrypt(data); } if (ziped) { data = ZLib.UnZip(data); } if (data != null) { return(data); } else { TcpLogger.LogError("Recv Decode data null"); } } else { TcpLogger.LogError("Recv error crc32 " + crc32 + " ncrc32" + ncrc32); } } else { TcpLogger.LogError("Recv error idx " + idx + " lidx" + recvIdx); } return(null); }
public void SendPacket(ServerPacket packet) { if (!IsOpen()) { return; } packet.LogPacket(_worldSession); packet.WritePacketData(); var data = packet.GetData(); ServerOpcodes opcode = packet.GetOpcode(); PacketLog.Write(data, (uint)opcode, GetRemoteIpAddress(), GetRemotePort(), _connectType, false); ByteBuffer buffer = new ByteBuffer(); int packetSize = data.Length; if (packetSize > 0x400 && _worldCrypt.IsInitialized) { buffer.WriteInt32(packetSize + 2); buffer.WriteUInt32(ZLib.adler32(ZLib.adler32(0x9827D8F1, BitConverter.GetBytes((ushort)opcode), 2), data, (uint)packetSize)); byte[] compressedData; uint compressedSize = CompressPacket(data, opcode, out compressedData); buffer.WriteUInt32(ZLib.adler32(0x9827D8F1, compressedData, compressedSize)); buffer.WriteBytes(compressedData, compressedSize); packetSize = (ushort)(compressedSize + 12); opcode = ServerOpcodes.CompressedPacket; data = buffer.GetData(); } buffer = new ByteBuffer(); buffer.WriteUInt16((ushort)opcode); buffer.WriteBytes(data); packetSize += 2 /*opcode*/; data = buffer.GetData(); PacketHeader header = new PacketHeader(); header.Size = packetSize; _worldCrypt.Encrypt(ref data, ref header.Tag); ByteBuffer byteBuffer = new ByteBuffer(); header.Write(byteBuffer); byteBuffer.WriteBytes(data); AsyncWrite(byteBuffer.GetData()); }
public override Task Load() { return(Task.Run(() => { string path = Path.Combine(FileManager.UoFolderPath, "multi.mul"); string pathidx = Path.Combine(FileManager.UoFolderPath, "multi.idx"); if (File.Exists(path) && File.Exists(pathidx)) { _file = new UOFileMul(path, pathidx, Constants.MAX_MULTI_DATA_INDEX_COUNT, 14); } else { throw new FileNotFoundException(); } Count = _itemOffset = FileManager.ClientVersion >= ClientVersions.CV_7090 ? UnsafeMemoryManager.SizeOf <MultiBlockNew>() : UnsafeMemoryManager.SizeOf <MultiBlock>(); string uopPath = Path.Combine(FileManager.UoFolderPath, "MultiCollection.uop"); if (File.Exists(uopPath)) { Count = Constants.MAX_MULTI_DATA_INDEX_COUNT; _fileUop = new UOFileUopNoFormat(uopPath); _reader = new DataReader(); for (int i = 0; i < _fileUop.Entries.Length; i++) { long offset = _fileUop.Entries[i].Offset; int csize = _fileUop.Entries[i].Length; int dsize = _fileUop.Entries[i].DecompressedLength; _fileUop.Seek(offset); byte[] cdata = _fileUop.ReadArray <byte>(csize); byte[] ddata = new byte[dsize]; ZLib.Decompress(cdata, 0, ddata, dsize); _reader.SetData(ddata, dsize); uint id = _reader.ReadUInt(); if (id < Constants.MAX_MULTI_DATA_INDEX_COUNT && id < _file.Entries.Length) { ref UOFileIndex3D index = ref _file.Entries[id]; int count = _reader.ReadInt(); index = new UOFileIndex3D(offset, csize, dsize, (int)MathHelper.Combine(count, index.Extra)); } } _reader.ReleaseData(); } }));
public static byte[] GetDecompressedData(string pakFilePath) { using (FileStream stream = new FileStream(pakFilePath, FileMode.Open, FileAccess.Read)) { byte[] bytes = new byte[stream.Length]; stream.Read(bytes, 0, (int)stream.Length); bytes = bytes.Skip(4).ToArray(); return(ZLib.DecompressData(bytes)); } }
/// <summary> /// Builds a compressed payload from the current content's data. /// </summary> /// <param name="opcode">The packet's opcode.</param> /// <returns>A new compressed payload.</returns> public byte[] GetCompressedPayload(short opcode) { byte[] compressedData = ZLib.CompressData(_contentData); byte[] packetId = BigEndian.GetBytes(opcode); byte[] size = BigEndian.GetBytes(compressedData.Length + sizeof(int)); byte[] compressionFlag = { 1 }; // true byte[] decompressedSize = LittleEndian.GetBytes(_contentData.Length); byte[] padding = { 0, 0, 0, 0 }; return(Sequence.Concat(packetId, size, compressionFlag, decompressedSize, compressedData, padding)); }
public static bool Initialize() { ByteRef dec = null; zlib = new ZLib(); ReadToVector("decompress.dat", ref dec); ReadToVector("compress.dat", ref zlib.enc); zlib.val = new ByteRef(0); PopulateJumpTable(ref zlib.val, ref zlib.jump, ref dec); return(false); }
public static void OnAuthSession(RealmServerSession session, CmsgAuthSession handler) { // Check the version of client trying to connect [5875] // DONE: Check Account session.Users = MainForm.Database.GetAccount(handler.ClientAccount); // Kick if existing // Check if account is banned // DONE: Set Crypt Hash Player session.PacketCrypto = new VanillaCrypt(); session.PacketCrypto.Init(session.Users.sessionkey); // Disconnect clients trying to enter with an invalid build //if (handler.Build < 5875 || handler.Build > 6141) // Disconnect clients trying to enter with an invalid build // If server full then queue, If GM/Admin let in // DONE: Addons info reading #region NOT USED var addonData = handler.ReadBytes((int)handler.BaseStream.Length - (int)handler.BaseStream.Position); var decompressed = ZLib.Decompress(addonData); //RealmServerSession.DumpPacket(decompressed); List <string> addOnsNames = new List <string>(); using (var reader = new PacketReader(new MemoryStream(decompressed))) { var count = reader.BaseStream.Length / sizeof(int); for (var i = 0; i < count; ++i) { //var addonName = reader.ReadString(); //if (addonName.Equals("")) continue; //addOnsNames.Add(addonName); } } #endregion // Update [IP / Build] // Create Log // Init Warden // DONE: Send Addon Packet session.SendPacket(new SmsgAddonInfo(addOnsNames)); // DONE: Send packet session.SendPacket(new SmsgAuthResponse()); }
/// <summary> /// Initializes a new instance of PayloadReader using the specified payload data. If the payload is compressed, it is automatically decompressed. /// </summary> /// <param name="payload">The payload data to be read.</param> /// <remarks> /// The null bytes padding is ignored by the reader. /// </remarks> public PayloadReader(byte[] payload) { Data = payload; if (CompressionFlag) { byte[] firstPart = Sequence.ReadBlock(Data, 0, 11); byte[] decompressedContent = ZLib.DecompressData(Sequence.ReadBlock(Data, 11, Size - 4)); byte[] nullBytesPadding = new byte[3]; Data = Sequence.Concat(firstPart, decompressedContent, nullBytesPadding); } }