This repository has been archived by the owner on Nov 16, 2020. It is now read-only.
forked from Ultraporing/ao-id-extractor
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
217 lines (192 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
using ao_id_extractor.Extractors;
using ao_id_extractor.Helpers;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace ao_id_extractor
{
public static class ProcessExtensions
{
private static string FindIndexedProcessName(int pid)
{
var processName = Process.GetProcessById(pid).ProcessName;
var processesByName = Process.GetProcessesByName(processName);
string processIndexdName = null;
for (var index = 0; index < processesByName.Length; index++)
{
processIndexdName = index == 0 ? processName : processName + "#" + index;
var processId = new PerformanceCounter("Process", "ID Process", processIndexdName);
if ((int)processId.NextValue() == pid)
{
return processIndexdName;
}
}
return processIndexdName;
}
private static Process FindPidFromIndexedProcessName(string indexedProcessName)
{
var parentId = new PerformanceCounter("Process", "Creating Process ID", indexedProcessName);
return Process.GetProcessById((int)parentId.NextValue());
}
public static Process Parent(this Process process)
{
return FindPidFromIndexedProcessName(FindIndexedProcessName(process.Id));
}
}
public static class Program
{
[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool AllocConsole();
public static string OutputFolderPath { get; set; }
public static ExportType ExportType { get; set; }
public static ExportMode ExportMode { get; set; }
public static string MainGameFolder { get; set; }
private static void PrintCmdHelp()
{
Console.WriteLine("How to use:\nao-id-extractor.exe modeID outFormat [outFolder]\n" +
"modeID\t\t#Extraction 0=Item Extraction, 1=Location Extraction, 2=Dump All, 3=Extract Items & Locations, 4=Everything\n" +
"outFormat\t#l=Text List, j=JSON b=Both\n" +
"[outFolder]\t#OPTIONAL: Output folder path. Default: current directory\n" +
"[gameFolder]\t#OPTIONAL: Location of the main AlbionOnline folder");
}
private static void ParseCommandline(string[] args)
{
if (args.Length >= 2)
{
var exportMode = int.Parse(args[0]);
if (exportMode >= 0 && exportMode <= 4)
{
ExportMode = (ExportMode)exportMode;
}
else
{
PrintCmdHelp();
return;
}
if (args[1] == "l" || args[1] == "j" || args[1] == "b")
{
ExportType = ExportType.Both;
switch (args[1])
{
case "l":
ExportType = ExportType.TextList;
break;
case "j":
ExportType = ExportType.Json;
break;
}
}
else
{
PrintCmdHelp();
return;
}
if (args.Length >= 3)
{
if (string.IsNullOrWhiteSpace(args[2]))
{
OutputFolderPath = Directory.GetCurrentDirectory();
}
else
{
OutputFolderPath = args[2];
}
}
if (args.Length == 4)
{
MainGameFolder = args[3];
}
}
else
{
PrintCmdHelp();
return;
}
}
[STAThread]
private static void Main(string[] args)
{
OutputFolderPath = "";
MainGameFolder = "";
var parentName = Process.GetCurrentProcess().Parent().ProcessName;
ParseCommandline(args);
if (parentName != "cmd")
{
var mainWindow = new MainWindow();
Application.EnableVisualStyles();
Console.SetOut(new MultiTextWriter(new ControlWriter(mainWindow.ConsoleBox), Console.Out));
Application.Run(mainWindow);
return;
}
else
{
AllocConsole();
RunExtractions();
}
Console.Out.WriteLine("\nPress Any Key to Quit");
Console.ReadKey();
}
public static void RunExtractions()
{
Console.Out.WriteLine("#---- Starting Extraction Operation ----#");
string exportTypeString;
if (ExportType == ExportType.TextList)
{
exportTypeString = "Text List";
}
else if (ExportType == ExportType.Json)
{
exportTypeString = "JSON";
}
else
{
exportTypeString = "Text List and JSON";
}
var localizationData = new LocalizationData();
switch (ExportMode)
{
case ExportMode.Item_Extraction:
ExtractItems(localizationData, exportTypeString);
break;
case ExportMode.Location_Extraction:
ExtractLocations(exportTypeString);
break;
case ExportMode.Dump_All_XML:
DumpAllXml();
break;
case ExportMode.Extract_Items_Locations:
ExtractItems(localizationData, exportTypeString);
ExtractLocations(exportTypeString);
break;
case ExportMode.Everything:
ExtractItems(localizationData, exportTypeString);
ExtractLocations(exportTypeString);
DumpAllXml();
break;
}
Console.Out.WriteLine("#---- Finished Extraction Operation ----#");
}
public static void ExtractItems(LocalizationData localizationData, string exportTypeString)
{
Console.Out.WriteLine("--- Starting Extraction of Items as " + exportTypeString + " ---");
new ItemExtractor().Extract(localizationData);
Console.Out.WriteLine("--- Extraction Complete! ---");
}
public static void ExtractLocations(string exportTypeString)
{
Console.Out.WriteLine("--- Starting Extraction of Locations as " + exportTypeString + " ---");
new LocationExtractor().Extract();
Console.Out.WriteLine("--- Extraction Complete! ---");
}
public static void DumpAllXml()
{
Console.Out.WriteLine("--- Starting Extraction of All Files as XML ---");
new BinaryDumper().Extract();
Console.Out.WriteLine("--- Extraction Complete! ---");
}
}
}