@@ -35,40 +35,23 @@ public static IMessage Deserialize(BinaryReader reader, IMessage messageBase)
35
35
36
36
for ( var i = 0 ; i < attributeCount ; i ++ )
37
37
{
38
- var attributeName = GetAttributeName ( reader , messageType ) ;
38
+ var attributeNameAsBytes = GetAttributeNameAsBytes ( reader , messageType ) ;
39
39
40
40
var attributeType = reader . ReadByte ( ) ;
41
41
42
42
var value = XFireAttributeFactory . Instance . GetAttribute ( attributeType ) . ReadValue ( reader ) ;
43
43
44
44
var field = fieldInfo
45
45
. Where ( a => a . GetCustomAttribute < XMessageField > ( ) != null )
46
- . FirstOrDefault ( a =>
47
- {
48
- var attribute = a . GetCustomAttribute < XMessageField > ( ) ;
49
- if ( attribute != null )
50
- {
51
- if ( attributeName . Length == 1 )
52
- {
53
- // If attributeName is a single byte, compare with the attribute's NameAsBytes
54
- return attribute . NameAsBytes . SequenceEqual ( attributeName ) ;
55
- }
56
- else
57
- {
58
- // If attributeName is a byte array with length > 1, compare with the attribute's Name converted to string
59
- return Encoding . UTF8 . GetString ( attributeName ) == attribute . Name ;
60
- }
61
- }
62
- return false ;
63
- } ) ;
46
+ . FirstOrDefault ( a => a . GetCustomAttribute < XMessageField > ( ) . NameAsBytes . SequenceEqual ( attributeNameAsBytes ) ) ;
64
47
65
48
if ( field != null )
66
49
{
67
50
field . SetValue ( messageBase , value ) ;
68
51
}
69
52
else
70
53
{
71
- Debug . WriteLine ( $ "WARN: No attribute defined for { attributeName } on class { messageType . Name } ") ;
54
+ Debug . WriteLine ( $ "WARN: No attribute defined for { attributeNameAsBytes } on class { messageType . Name } ") ;
72
55
}
73
56
}
74
57
@@ -77,9 +60,11 @@ public static IMessage Deserialize(BinaryReader reader, IMessage messageBase)
77
60
return messageBase ;
78
61
}
79
62
80
- private static byte [ ] GetAttributeName ( BinaryReader reader , Type messageType )
63
+ private static byte [ ] GetAttributeNameAsBytes ( BinaryReader reader , Type messageType )
81
64
{
82
- HashSet < Type > messageTypeSet = new HashSet < Type >
65
+ // These messages contain a single field represented by a byte value instead of
66
+ // the usual first byte representing the attribute name length.
67
+ var messagesWithoutAttributeNames = new HashSet < Type >
83
68
{
84
69
typeof ( StatusChange ) ,
85
70
typeof ( GameServerFetchAll ) ,
@@ -92,21 +77,14 @@ private static byte[] GetAttributeName(BinaryReader reader, Type messageType)
92
77
typeof ( UserRequestAdvancedInfo )
93
78
} ;
94
79
95
- byte count = messageTypeSet . Contains ( messageType ) ? ( byte ) 1 : reader . ReadByte ( ) ;
96
80
97
- // Check if count is 1, indicating a single byte
98
- if ( count == 1 )
99
- {
100
- // Read the single byte and treat it as a numeric value
101
- byte numericValue = reader . ReadByte ( ) ;
102
- return [ numericValue ] ;
103
- }
104
- else
81
+ if ( messagesWithoutAttributeNames . Contains ( messageType ) )
105
82
{
106
- // Read the bytes for the attribute name
107
- var readBytes = reader . ReadBytes ( count ) ;
108
- return readBytes ;
83
+ return [ reader . ReadByte ( ) ] ;
109
84
}
85
+
86
+ var length = reader . ReadByte ( ) ;
87
+ return reader . ReadBytes ( length ) ;
110
88
}
111
89
112
90
public static byte [ ] Serialize ( IMessage message )
0 commit comments