1+ using GBX . NET . PAK ;
2+
3+ var hashes = new Dictionary < string , string > ( ) ;
4+
5+ foreach ( var filePath in Directory . GetFiles ( "../../../../../Resources" , "FileHashes_*.txt" ) )
6+ {
7+ foreach ( var line in File . ReadLines ( filePath ) )
8+ {
9+ var parts = line . Split ( ' ' , 2 , StringSplitOptions . RemoveEmptyEntries ) ;
10+
11+ if ( parts . Length != 2 )
12+ {
13+ continue ;
14+ }
15+
16+ var hash = parts [ 0 ] ;
17+ var fileName = parts [ 1 ] ;
18+
19+ hashes [ hash ] = fileName ;
20+ }
21+ }
22+
23+ using ( var writer = File . CreateText ( "../../../../../Resources/FileHashes.txt" ) )
24+ {
25+ foreach ( var ( hash , name ) in hashes . OrderBy ( x => x . Value ) . ThenBy ( x => x . Key ) )
26+ {
27+ await writer . WriteLineAsync ( $ "{ hash } { name } ") ;
28+ }
29+ }
30+
31+ var keyLookup = ParseKeysFromTxt ( "../../../../../Resources/BaseKeys.txt" ) . ToLookup ( x => x . Item1 , x => x . Item2 ) ;
32+
33+ Directory . CreateDirectory ( "../../../../../Resources/FileHashes" ) ;
34+
35+ var directoryPath = args [ 0 ] ;
36+
37+ foreach ( var pakFilePath in Directory . EnumerateFiles ( directoryPath , "*.pak" ) . Concat ( Directory . EnumerateFiles ( directoryPath , "*.Pack.Gbx" ) ) )
38+ {
39+ foreach ( var key in keyLookup [ Path . GetFileNameWithoutExtension ( pakFilePath ) ] )
40+ {
41+ try
42+ {
43+ using var pak = await Pak . ParseAsync ( pakFilePath , key ) ;
44+
45+ var perPakHashes = new Dictionary < string , string > ( ) ;
46+ var perPakHashesPath = $ "../../../../../Resources/FileHashes/{ Path . GetFileNameWithoutExtension ( pakFilePath ) } .txt";
47+
48+ if ( File . Exists ( perPakHashesPath ) )
49+ {
50+ foreach ( var line in File . ReadLines ( perPakHashesPath ) )
51+ {
52+ var parts = line . Split ( ' ' , 2 , StringSplitOptions . RemoveEmptyEntries ) ;
53+
54+ if ( parts . Length != 2 )
55+ {
56+ continue ;
57+ }
58+
59+ var hash = parts [ 0 ] ;
60+ var fileName = parts [ 1 ] ;
61+
62+ perPakHashes [ hash ] = fileName ;
63+ }
64+ }
65+
66+ foreach ( var ( _, file ) in pak . Files )
67+ {
68+ if ( hashes . TryGetValue ( file . Name , out var fileName ) )
69+ {
70+ perPakHashes [ file . Name ] = fileName ;
71+ }
72+ }
73+
74+ if ( perPakHashes . Count > 0 )
75+ {
76+ using var writer = File . CreateText ( perPakHashesPath ) ;
77+
78+ foreach ( var ( hash , name ) in perPakHashes . OrderBy ( x => x . Value ) . ThenBy ( x => x . Key ) )
79+ {
80+ await writer . WriteLineAsync ( $ "{ hash } { name } ") ;
81+ }
82+ }
83+ }
84+ catch
85+ {
86+
87+ }
88+ }
89+ }
90+
91+ static IEnumerable < ( string , byte [ ] ) > ParseKeysFromTxt ( string keysFileName )
92+ {
93+ foreach ( var line in File . ReadLines ( keysFileName ) )
94+ {
95+ var parts = line . Split ( ' ' , 2 , StringSplitOptions . RemoveEmptyEntries ) ;
96+
97+ if ( parts . Length != 2 )
98+ {
99+ continue ;
100+ }
101+
102+ var pak = parts [ 0 ] ;
103+ var key = Convert . FromHexString ( parts [ 1 ] ) ;
104+
105+ yield return ( pak , key ) ;
106+ }
107+ }
0 commit comments