1- using TypeTreeGeneratorAPI ;
1+ using System . CommandLine ;
2+ using TypeTreeGeneratorAPI ;
3+ using TypeTreeGeneratorAPI . TypeTreeGenerator ;
24
3- if ( args . Length < 2 )
5+ class Program
46{
5- Console . WriteLine ( "Usage: TypeTreeGeneratorCLI <unity_version> <dll directory>" ) ;
6- Console . WriteLine ( "Usage: TypeTreeGeneratorCLI <unity_version> <il2cpp assembly> <il2cpp metadata>" ) ;
7- return ;
8- }
7+ static async Task < int > Main ( string [ ] args )
8+ {
9+ var unityVersionOption = new Option < string > (
10+ aliases : [ "--unity-version" , "-uv" ] ,
11+ description : "The Unity Version of the game"
12+ )
13+ { IsRequired = true } ;
914
10- var generator = new TypeTreeGenerator_AssetStudio ( args [ 0 ] ) ;
15+ var backendOption = new Option < string > (
16+ aliases : [ "--backend" , "-b" ] ,
17+ description : "The backend to use (AssetStudio, AssetsTools, AssetRipper)" ,
18+ getDefaultValue : ( ) => "AssetsTools"
19+ ) ;
1120
12- if ( args . Length == 2 )
13- {
14- var dll_dir = args [ 1 ] ;
15- foreach ( var dll_fp in Directory . GetFiles ( dll_dir , "*.dll" ) )
16- {
17- var dll = File . ReadAllBytes ( dll_fp ) ;
18- generator . LoadDLL ( dll ) ;
21+
22+ var monoDirectoryOption = new Option < string ? > (
23+ aliases : [ "--mono-directory" , "-md" ] ,
24+ description : "The path to a directory containing .dll files"
25+ ) ;
26+
27+ var il2cppAssemblyPathOption = new Option < string ? > (
28+ aliases : [ "--il2cpp-assembly" , "-ia" ] ,
29+ description : "The path to an il2cpp assembly (GameAssembly.dll, libil2cpp.so)"
30+ ) ;
31+
32+ var il2cppMetadataPathOption = new Option < string ? > (
33+ aliases : [ "--il2cpp-metadata" , "-im" ] ,
34+ description : "The path to an il2cpp metadata file (global-metadata.dat)"
35+ ) ;
36+
37+ var rootCommand = new RootCommand ( "TypeTreeGeneratorAPI" ) ;
38+ rootCommand . AddOption ( unityVersionOption ) ;
39+ rootCommand . AddOption ( backendOption ) ;
40+ rootCommand . AddOption ( monoDirectoryOption ) ;
41+ rootCommand . AddOption ( il2cppAssemblyPathOption ) ;
42+ rootCommand . AddOption ( il2cppMetadataPathOption ) ;
43+
44+ rootCommand . SetHandler ( ( unityVersion , backend , monoDirectory , il2cppAssembly , il2CppMetadata ) =>
45+ {
46+ var handle = new TypeTreeGeneratorHandle ( backend , unityVersion ) ;
47+ if ( monoDirectory is not null )
48+ {
49+ foreach ( var dll_fp in Directory . GetFiles ( monoDirectory , "*.dll" ) )
50+ {
51+ var dll = File . ReadAllBytes ( dll_fp ) ;
52+ handle . Instance . LoadDll ( dll ) ;
53+ }
54+ }
55+ if ( il2cppAssembly is not null && il2CppMetadata is not null )
56+ {
57+ var assembly = File . ReadAllBytes ( il2cppAssembly ) ;
58+ var metadata = File . ReadAllBytes ( il2CppMetadata ) ;
59+ handle . Instance . LoadIl2Cpp ( assembly , metadata ) ;
60+ }
61+
62+ foreach ( var ( assemblyName , fullName ) in handle . Instance . GetMonoBehaviourDefinitions ( ) )
63+ {
64+ var nodes = handle . Instance . GenerateTreeNodes ( assemblyName , fullName ) ! ;
65+ if ( nodes == null || nodes . Count == 0 )
66+ continue ;
67+ Console . WriteLine ( $ "{ assemblyName } - { fullName } ") ;
68+ Console . WriteLine ( nodes . Count ) ;
69+ Console . WriteLine ( TypeTreeNodeSerializer . ToJson ( nodes ) ) ;
70+ }
71+ } ,
72+ unityVersionOption , backendOption , monoDirectoryOption , il2cppAssemblyPathOption , il2cppMetadataPathOption ) ;
73+
74+ return await rootCommand . InvokeAsync ( args ) ;
1975 }
2076}
21- else if ( args . Length == 3 )
22- {
23- var assembly_fp = args [ 1 ] ;
24- var metadata_fp = args [ 2 ] ;
25- var assembly = File . ReadAllBytes ( assembly_fp ) ;
26- var metadata = File . ReadAllBytes ( metadata_fp ) ;
27- generator . LoadIL2CPP ( assembly , metadata ) ;
28- }
29-
30- foreach ( var def in generator . GetMonoBehaviourDefinitions ( ) )
31- {
32- var nodes = generator . GenerateTreeNodes ( def . Module . Name , def . FullName ) ! ;
33- if ( nodes . Count == 0 )
34- continue ;
35- Console . WriteLine ( $ "{ def . Module . Name } - { def . FullName } ") ;
36- Console . WriteLine ( nodes . Count ) ;
37- Console . WriteLine ( TypeTreeNodeSerializer . ToJson ( nodes ) ) ;
38- }
0 commit comments