public TypeInfo FindSubType(StreamReader reader, out int identifier) { identifier = 0; var current = this.typeInfo; while (current != null) { if (current.KnownType == null) { return(current); } reader.Position = current.KnownType.Offset; switch (current.KnownType.IdentifierType) { case IdentifierType.Byte: identifier = reader.ReadByte(); break; case IdentifierType.Int16: identifier = reader.ReadInt16(); break; case IdentifierType.Int32: identifier = reader.ReadInt32(); break; default: return(null); } var subType = current.GetSubType(identifier); if (subType == null) { return(null); } current = subType; } return(null); }
public TypeInfo FindSubType(StreamReader reader) { var current = this.typeInfo; while (current != null) { if (current.KnownType == null) { return current; } reader.Position = current.KnownType.Offset; int identifier; switch (current.KnownType.IdentifierType) { case IdentifierType.Byte: identifier = reader.ReadByte(); break; case IdentifierType.Int16: identifier = reader.ReadInt16(); break; case IdentifierType.Int32: identifier = reader.ReadInt32(); break; default: return null; } var subType = current.GetSubType(identifier); if (subType == null) { return null; } current = subType; } return null; }
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}"); } }