// Create and parse the GameMessage that handles the next opcode public static GameMessage ParseMessage(GameBitBuffer buffer) { GameMessage msg = null; Opcodes opcode = (Opcodes)buffer.ReadInt(9); if (MessageTypes.ContainsKey(opcode)) { msg = (GameMessage)FormatterServices.GetUninitializedObject(MessageTypes[opcode]); typeof(GameMessage).GetProperty("Id").SetValue(msg, (int)opcode, null); msg.Parse(buffer); } return(msg as GameMessage); }