@@ -166,6 +166,10 @@ public class UnrealReader : BinaryReader
166
166
{
167
167
private readonly byte [ ] _IndexBuffer = new byte [ 5 ] ;
168
168
169
+ // Allow bulk reading of strings if the package is not big endian encoded.
170
+ // Generally this is the case for most packages, but some games have big endian encoded packages, where a string is serialized per byte.
171
+ private bool CanBulkRead => Archive . BigEndianCode == false ; // Must get, because this is not initialized before the constructor initiation.
172
+
169
173
// Dirty hack to implement crypto-reading, pending overhaul ;)
170
174
public UnrealReader ( IUnrealArchive archive , Stream baseStream ) : base ( baseStream ) => Archive = archive ;
171
175
@@ -182,14 +186,18 @@ public string ReadString(int length)
182
186
if ( length > 0 ) // ANSI
183
187
{
184
188
byte [ ] chars = new byte [ size ] ;
185
- #if HUXLEY
186
- BaseStream . Read ( chars , 0 , chars . Length ) ;
187
- #else
188
- for ( int i = 0 ; i < chars . Length ; ++ i )
189
+
190
+ if ( CanBulkRead )
189
191
{
190
- BaseStream . Read ( chars , i , 1 ) ;
192
+ BaseStream . Read ( chars , 0 , chars . Length ) ;
193
+ }
194
+ else
195
+ {
196
+ for ( int i = 0 ; i < chars . Length ; ++ i )
197
+ {
198
+ BaseStream . Read ( chars , i , 1 ) ;
199
+ }
191
200
}
192
- #endif
193
201
194
202
return chars [ size - 1 ] == '\0 '
195
203
? Encoding . ASCII . GetString ( chars , 0 , chars . Length - 1 )
@@ -198,25 +206,28 @@ public string ReadString(int length)
198
206
199
207
if ( length < 0 ) // UNICODE
200
208
{
201
- #if HUXLEY
202
- byte [ ] chars = new byte [ size * 2 ] ;
203
- BaseStream . Read ( chars , 0 , chars . Length ) ;
204
-
205
- return chars [ ( size * 2 ) - 2 ] == '\0 ' && chars [ ( size * 2 ) - 1 ] == '\0 '
206
- ? Encoding . Unicode . GetString ( chars , 0 , chars . Length - 2 )
207
- : Encoding . Unicode . GetString ( chars , 0 , chars . Length ) ;
208
- #else
209
- char [ ] chars = new char [ size ] ;
210
- for ( int i = 0 ; i < chars . Length ; ++ i )
209
+ if ( CanBulkRead )
211
210
{
212
- char w = ( char ) ReadInt16 ( ) ;
213
- chars [ i ] = w ;
211
+ byte [ ] chars = new byte [ size * 2 ] ;
212
+ BaseStream . Read ( chars , 0 , chars . Length ) ;
213
+
214
+ return chars [ ( size * 2 ) - 2 ] == '\0 ' && chars [ ( size * 2 ) - 1 ] == '\0 '
215
+ ? Encoding . Unicode . GetString ( chars , 0 , chars . Length - 2 )
216
+ : Encoding . Unicode . GetString ( chars , 0 , chars . Length ) ;
214
217
}
218
+ else
219
+ {
220
+ char [ ] chars = new char [ size ] ;
221
+ for ( int i = 0 ; i < chars . Length ; ++ i )
222
+ {
223
+ char w = ( char ) ReadInt16 ( ) ;
224
+ chars [ i ] = w ;
225
+ }
215
226
216
- return chars [ size - 1 ] == '\0 '
217
- ? new string ( chars , 0 , chars . Length - 1 )
218
- : new string ( chars ) ;
219
- #endif
227
+ return chars [ size - 1 ] == '\0 '
228
+ ? new string ( chars , 0 , chars . Length - 1 )
229
+ : new string ( chars ) ;
230
+ }
220
231
}
221
232
222
233
return string . Empty ;
0 commit comments