-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathProgram.cs
More file actions
76 lines (66 loc) · 2.96 KB
/
Program.cs
File metadata and controls
76 lines (66 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System.CommandLine;
using TypeTreeGeneratorAPI;
using TypeTreeGeneratorAPI.TypeTreeGenerator;
class Program
{
static async Task<int> Main(string[] args)
{
var unityVersionOption = new Option<string>(
aliases: ["--unity-version", "-uv"],
description: "The Unity Version of the game"
)
{ IsRequired = true };
var backendOption = new Option<string>(
aliases: ["--backend", "-b"],
description: "The backend to use (AssetStudio, AssetsTools, AssetRipper)",
getDefaultValue: () => "AssetsTools"
);
var monoDirectoryOption = new Option<string?>(
aliases: ["--mono-directory", "-md"],
description: "The path to a directory containing .dll files"
);
var il2cppAssemblyPathOption = new Option<string?>(
aliases: ["--il2cpp-assembly", "-ia"],
description: "The path to an il2cpp assembly (GameAssembly.dll, libil2cpp.so)"
);
var il2cppMetadataPathOption = new Option<string?>(
aliases: ["--il2cpp-metadata", "-im"],
description: "The path to an il2cpp metadata file (global-metadata.dat)"
);
var rootCommand = new RootCommand("TypeTreeGeneratorAPI");
rootCommand.AddOption(unityVersionOption);
rootCommand.AddOption(backendOption);
rootCommand.AddOption(monoDirectoryOption);
rootCommand.AddOption(il2cppAssemblyPathOption);
rootCommand.AddOption(il2cppMetadataPathOption);
rootCommand.SetHandler((unityVersion, backend, monoDirectory, il2cppAssembly, il2CppMetadata) =>
{
var handle = new TypeTreeGeneratorHandle(backend, unityVersion);
if (monoDirectory is not null)
{
foreach (var dll_fp in Directory.GetFiles(monoDirectory, "*.dll"))
{
var dll = File.ReadAllBytes(dll_fp);
handle.Instance.LoadDll(dll);
}
}
if (il2cppAssembly is not null && il2CppMetadata is not null)
{
var assembly = File.ReadAllBytes(il2cppAssembly);
var metadata = File.ReadAllBytes(il2CppMetadata);
handle.Instance.LoadIl2Cpp(assembly, metadata);
}
foreach (var (assemblyName, fullName) in handle.Instance.GetMonoBehaviourDefinitions())
{
var nodes = handle.Instance.GenerateTreeNodes(assemblyName, fullName)!;
if (nodes == null || nodes.Count == 0)
continue;
Console.WriteLine($"{assemblyName} - {fullName}");
Console.WriteLine(nodes.Count);
Console.WriteLine(TypeTreeNodeSerializer.ToJson(nodes));
}
},
unityVersionOption, backendOption, monoDirectoryOption, il2cppAssemblyPathOption, il2cppMetadataPathOption);
return await rootCommand.InvokeAsync(args);
}
}