-
Notifications
You must be signed in to change notification settings - Fork 41
/
Program.cs
139 lines (125 loc) · 6.06 KB
/
Program.cs
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System;
using System.Windows.Forms;
using System.IO;
using ProtoDumper.Outputs;
namespace ProtoDumper {
public class Program {
public enum ExportType {
Proto,
TypeScript
}
private const string HelpParam = "--help";
private const string HelpParamShort = "-h";
private const string DontDeleteOldProtosParam = "--dont-delete-old-protos";
private const string AssemblyPathParam = "--assembly-path=";
private const string OutputPathParam = "--output-path=";
private const string ExportTypeParam = "--export-type=";
private const string ExportExtensionParam = "--export-file-extension=";
[STAThread]
public static void Main(string[] args) {
var assemblyPath = "";
var outputPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Output") + "\\";
ExportType exportType = ExportType.Proto;
var exportFileExtension = "";
var dontDeleteOldProtos = false;
// If args are empty and assembly path is not defined, popup asking for the assembly
if (args.Length == 0 && assemblyPath == "") {
var ofd = new OpenFileDialog();
ofd.Filter = "Assembly-CSharp.dll|*";
Console.WriteLine("Please select the Assembly with Proto definitions.");
if (ofd.ShowDialog() == DialogResult.OK) {
assemblyPath = ofd.FileName;
}
}
// Read args
else if (args.Length > 0) {
// Inspired on Il2CppAssemblyUnhollower's argument system, thanks knah
foreach (var arg in args) {
if (arg == HelpParam || arg == HelpParamShort) {
ShowHelp();
return;
}
else if (arg == DontDeleteOldProtosParam) {
dontDeleteOldProtos = true;
}
else if (arg.StartsWith(AssemblyPathParam)) {
assemblyPath = arg.Substring(AssemblyPathParam.Length);
}
else if (arg.StartsWith(ExportTypeParam)) {
var exportTypeParam = arg.Substring(ExportTypeParam.Length).ToLower();
switch (exportTypeParam) {
case "typescript":
case "ts":
exportType = ExportType.TypeScript;
break;
case "proto":
exportType = ExportType.Proto;
break;
default:
Console.WriteLine($"Could not find export type ${exportTypeParam}! Valid types: typescript, proto");
exportType = ExportType.Proto;
break;
}
}
else if (arg.StartsWith(OutputPathParam)) {
outputPath = arg.Substring(OutputPathParam.Length);
}
else if (arg.StartsWith(ExportExtensionParam)) {
exportFileExtension = arg.Substring(ExportExtensionParam.Length);
}
else {
Console.WriteLine($"Unrecognized option {arg}, use -h for help.");
}
}
}
if (assemblyPath == "") {
Console.WriteLine("Assembly path not found!");
ShowHelp();
Exit();
return;
}
Console.WriteLine("Parsing protos...");
var protoParser = new ProtoParser(assemblyPath);
var protos = protoParser.Parse();
Console.WriteLine("Proto parsing done!");
var outputDirectory = new DirectoryInfo(outputPath);
if (outputDirectory.Exists && !dontDeleteOldProtos) {
Console.WriteLine("Old protos found! Deleting.");
outputDirectory.Delete(true);
}
Console.WriteLine($"Dumping to folder: {outputDirectory.FullName}");
Directory.CreateDirectory(outputDirectory.FullName);
// outputDirectory.Create();
switch (exportType) {
case ExportType.TypeScript:
Console.WriteLine("Using export type \"TypeScript\".");
var dumperTs = new TypeScriptDumper(protos, outputDirectory.FullName);
dumperTs.Dump(exportFileExtension == "" ? "ts" : exportFileExtension);
break;
case ExportType.Proto:
Console.WriteLine("Using export type \"Proto\".");
var dumperProto = new BaseDumper(protos, outputDirectory.FullName);
dumperProto.Dump(exportFileExtension == "" ? "proto" : exportFileExtension);
break;
}
Console.WriteLine("Done!");
Exit();
}
// Also based on Unhollower
private static void ShowHelp() {
Console.WriteLine("Usage: ProtoDumper [parameters]");
Console.WriteLine("Possible parameters:");
Console.WriteLine($"\t{HelpParam}, {HelpParamShort} - Optional. Show this help");
Console.WriteLine($"\t{DontDeleteOldProtosParam} - Optional. Stop the program from deleting old protos");
Console.WriteLine($"\t{AssemblyPathParam} - Optional. Path to the assembly that contains protos");
Console.WriteLine($"\t{OutputPathParam} - Optional. Output path");
Console.WriteLine($"\t{ExportTypeParam} - Optional. Export type, can be typescript or proto");
Console.WriteLine($"\t{ExportExtensionParam} - Optional. File extension used in the exported files");
}
private static void Exit() {
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
Environment.Exit(0);
}
}
}