@@ -28,20 +28,21 @@ public virtual async Task LoadAsync(string fileName)
28
28
if ( ! File . Exists ( fileName ) )
29
29
throw new FileNotFoundException ( $ "file does not exists: '{ fileName } '") ;
30
30
31
- // File > Bytes > XOR > ToString > Replace > Base64 > Gzip
32
31
#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 ) ;
34
33
#else
35
34
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 ) ;
38
35
#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 ) ;
41
38
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 ) ) ) ;
44
42
43
+ DataPlist = new Plist ( Encoding . ASCII . GetBytes ( gZipDecompress ) ) ;
44
+ }
45
+
45
46
/// <summary>
46
47
/// Saves class data to a file as a game save<br/><br/>
47
48
/// Before saving, make sure that you have closed the game. Otherwise, after closing, the game will overwrite the file<br/>
0 commit comments