public PacketInspector() { this.typeInfo = new TypeInfo(typeof(MessageBody)); }
private void InitializeSubTypes() { this.subTypes.Clear(); var types = this.type.Assembly.GetTypes().Where(t => t.BaseType == this.type); foreach (var subType in types) { var contract = subType.GetCustomAttributes(typeof(AoContractAttribute), false) .Cast<AoContractAttribute>() .FirstOrDefault(); if (contract == null) { continue; } var typeInfo = new TypeInfo(subType); this.subTypes.Add(contract.Identifier, typeInfo); } }
private void ProcessIPCMessage(byte[] msgBytes) { try { using (MemoryStream stream = new MemoryStream(msgBytes)) { StreamReader reader = new StreamReader(stream) { Position = 0 }; if (reader.ReadUInt16() != 0xFFFF) { return; } ushort len = reader.ReadUInt16(); if (len != msgBytes.Length) { return; } byte channelId = reader.ReadByte(); if (channelId != _channelId) { return; } int charId = reader.ReadInt32(); if (charId == Game.ClientInst) { return; } reader.Position = 2; TypeInfo subTypeInfo = _packetInspector.FindSubType(reader, out int opCode); if (subTypeInfo == null) { return; } var serializer = _serializerResolver.GetSerializer(subTypeInfo.Type); if (serializer == null) { return; } reader.Position = 11; SerializationContext serializationContext = new SerializationContext(_serializerResolver); IPCMessage message = (IPCMessage)serializer.Deserialize(reader, serializationContext); if (_callbacks.ContainsKey(opCode)) { _callbacks[opCode]?.Invoke(charId, message); } } } catch (Exception e) { //If you get this message and it concerns you please create an issue or contact me on Discord! Chat.WriteLine($"Failed to process IPC message {e.Message}"); } }