@@ -28,20 +28,21 @@ public virtual async Task LoadAsync(string fileName)
2828 if ( ! File . Exists ( fileName ) )
2929 throw new FileNotFoundException ( $ "file does not exists: '{ fileName } '") ;
3030
31- // File > Bytes > XOR > ToString > Replace > Base64 > Gzip
3231#if NETSTANDARD2_1
33- var data = await File . ReadAllBytesAsync ( fileName ) ;
32+ await using var file = new FileStream ( fileName , FileMode . Open , FileAccess . Read , FileShare . Read , 4096 , useAsync : true ) ;
3433#else
3534 using var file = new FileStream ( fileName , FileMode . Open , FileAccess . Read , FileShare . Read , 4096 , useAsync : true ) ;
36- var data = new byte [ file . Length ] ;
37- var read = await file . ReadAsync ( data , 0 , data . Length ) ;
3835#endif
39- var dataZip = Encoding . ASCII . GetString ( Crypt . XOR ( data , 0xB ) ) . Split ( ' \0 ' ) [ 0 ] ;
40- var resultPlist = Crypt . GZipDecompress ( GameConvert . FromBase64 ( dataZip ) ) ;
36+ var data = new byte [ file . Length ] ;
37+ await file . ReadAsync ( data , 0 , data . Length ) ;
4138
42- DataPlist = new Plist ( Encoding . ASCII . GetBytes ( resultPlist ) ) ;
43- }
39+ var xor = Crypt . XOR ( data , 0xB ) ;
40+ var index = xor . AsSpan ( ) . IndexOf ( ( byte ) 0 ) ;
41+ var gZipDecompress = Crypt . GZipDecompress ( GameConvert . FromBase64 ( Encoding . ASCII . GetString ( xor , 0 , index >= 0 ? index : xor . Length ) ) ) ;
4442
43+ DataPlist = new Plist ( Encoding . ASCII . GetBytes ( gZipDecompress ) ) ;
44+ }
45+
4546 /// <summary>
4647 /// Saves class data to a file as a game save<br/><br/>
4748 /// Before saving, make sure that you have closed the game. Otherwise, after closing, the game will overwrite the file<br/>
0 commit comments