@@ -13,8 +13,7 @@ internal class Program
1313 [ STAThread ]
1414 private static void Main ( string [ ] args )
1515 {
16- config = JsonSerializer . Deserialize < Config > (
17- File . ReadAllText ( AppDomain . CurrentDomain . BaseDirectory + @"config.json" ) ) ;
16+ config = JsonSerializer . Deserialize < Config > ( File . ReadAllText ( Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , "config.json" ) ) ) ;
1817 GenerateReplaceNameMap ( ) ;
1918 string il2cppPath = null ;
2019 string metadataPath = null ;
@@ -29,8 +28,9 @@ private static void Main(string[] args)
2928 }
3029 }
3130
32- if ( args . Length > 3 )
31+ if ( args . Length < 3 )
3332 {
33+ Console . WriteLine ( "ERROR: Not enough arguments." ) ;
3434 ShowHelp ( ) ;
3535 return ;
3636 }
@@ -41,8 +41,12 @@ private static void Main(string[] args)
4141 {
4242 if ( File . Exists ( arg ) )
4343 {
44- var file = File . ReadAllBytes ( arg ) ;
45- if ( BitConverter . ToUInt32 ( file , 0 ) == 0xFAB11BAF )
44+ UInt32 magicBytes = 0 ;
45+ using ( FileStream fileStream = File . OpenRead ( arg ) )
46+ {
47+ magicBytes = new BinaryReader ( fileStream ) . ReadUInt32 ( ) ;
48+ }
49+ if ( magicBytes == 0xFAB11BAF )
4650 {
4751 metadataPath = arg ;
4852 }
@@ -58,41 +62,29 @@ private static void Main(string[] args)
5862 }
5963 }
6064
61- outputDir ??= AppDomain . CurrentDomain . BaseDirectory ;
62- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
65+ if ( string . IsNullOrEmpty ( outputDir ) || ! Directory . Exists ( outputDir ) )
66+ {
67+ Console . WriteLine ( "ERROR: The specified output folder does not exist." ) ;
68+ ShowHelp ( ) ;
69+ return ;
70+ }
71+ outputDir = Path . GetFullPath ( outputDir ) + Path . DirectorySeparatorChar ;
6372 {
64- if ( il2cppPath == null )
73+ if ( il2cppPath == null || metadataPath == null )
6574 {
66- var ofd = new OpenFileDialog { Filter = "Il2Cpp binary file|*.*" } ;
67- if ( ofd . ShowDialog ( ) )
68- {
69- il2cppPath = ofd . FileName ;
70- ofd . Filter = "global-metadata|global-metadata.dat" ;
71- if ( ofd . ShowDialog ( ) )
72- {
73- metadataPath = ofd . FileName ;
74- }
75- else
76- {
77- return ;
78- }
79- }
80- else
81- {
82- return ;
83- }
75+ Console . WriteLine ( "ERROR: Missing required input files." ) ;
76+ ShowHelp ( ) ;
77+ return ;
8478 }
8579 }
86-
8780 if ( il2cppPath == null )
8881 {
8982 ShowHelp ( ) ;
9083 return ;
9184 }
92-
9385 if ( metadataPath == null )
9486 {
95- Console . WriteLine ( "ERROR: Metadata file not found or encrypted." ) ;
87+ Console . WriteLine ( $ "ERROR: Metadata file not found or encrypted.") ;
9688 }
9789 else
9890 {
@@ -147,8 +139,8 @@ private static void ShowHelp()
147139 private static bool Init ( string il2cppPath , string metadataPath , out Metadata metadata , out Il2Cpp il2Cpp )
148140 {
149141 Console . WriteLine ( "Initializing metadata..." ) ;
150- var metadataBytes = File . ReadAllBytes ( metadataPath ) ;
151- metadata = new Metadata ( new MemoryStream ( metadataBytes ) ) ;
142+ var metadataStream = File . OpenRead ( metadataPath ) ;
143+ metadata = new Metadata ( metadataStream ) ;
152144 Console . WriteLine ( $ "Metadata Version: { metadata . Version } ") ;
153145
154146 Console . WriteLine ( "Initializing il2cpp file..." ) ;
0 commit comments