forked from andreashagstrom/SpawnCodeGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
339 lines (306 loc) · 16.6 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
using SpawnCodeGenerator.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
namespace SpawnCodeGenerator
{
class Program
{
/// <summary>
/// Constants for the file names
/// </summary>
private const string PREFIX = "ArkSpawnCodeGen_";
private const string PRIMAL_ITEMS_PREFIX = PREFIX + "Primal_Items_";
private const string SPAWNCODES_PREFIX = PREFIX + "Spawncodes_";
private const string SUMMERY_FILE = PREFIX + "Summery";
private const string BLUEPRINT_FILE = PREFIX + "Blueprints";
private const string ENGRAM_FILE = PREFIX + "Engrams";
private const string PRIMAL_ITEMS_FILE = PRIMAL_ITEMS_PREFIX + "Items";
private const string SPAWNCODE_ITEMS_FILE = SPAWNCODES_PREFIX + "Items";
private const string SPAWNCODE_CREATURE_FILE = SPAWNCODES_PREFIX + "Creatures";
private const string OUTPUT_PATH = "Output/";
private static string PATH_PREFIX = "/Game/Mods/";
private static string ORIGINAL_PATH = "/Game/Mods/";
/// <summary>
/// List of all read files
/// </summary>
private static List<Summery> summeryFile = new List<Summery>();
private static List<string> blueprintFile = new List<string>();
private static List<string> engramFile = new List<string>();
private static List<string> primalItemsFile = new List<string>();
private static List<string> spawncodeItemsFile = new List<string>();
private static List<string> spawncodeCreatureFile = new List<string>();
/// <summary>
/// Save all found files
/// </summary>
private static string[] files;
/// <summary>
/// Constructor of ArkSpanCodeGen
/// </summary>
/// <param name="args"></param>
public static void Main(string[] args)
{
var path = Directory.GetCurrentDirectory();
var modFolder = path.Split('\\').Last();
var modId = GetValidModFolder(modFolder);
ORIGINAL_PATH += modFolder;
PATH_PREFIX += modId;
Console.WriteLine(Environment.NewLine);
WriteColor(@"[$$$$$$$$\ $$\ $$\ $$$$$$\ $$\]", ConsoleColor.DarkGreen);
WriteColor(@"[$$ _____|\__| $$ | $$ __$$\ $$ |]", ConsoleColor.DarkGreen);
WriteColor(@"[$$ | $$\ $$$$$$\ $$$$$$$\ $$$$$$\ $$ / \__| $$$$$$\ $$$$$$$ | $$$$$$\ $$$$$$\]", ConsoleColor.DarkGreen);
WriteColor(@"[$$$$$\ $$ |$$ __$$\ $$ _____|\_$$ _|$$$$$$\ $$ | $$ __$$\ $$ __$$ |$$ __$$\ $$ __$$\]", ConsoleColor.DarkGreen);
WriteColor(@"[$$ __| $$ |$$ | \__|\$$$$$$\ $$ | \______|$$ | $$ / $$ |$$ / $$ |$$$$$$$$ |$$ | \__|]", ConsoleColor.DarkGreen);
WriteColor(@"[$$ | $$ |$$ | \____$$\ $$ |$$\ $$ | $$\ $$ | $$ |$$ | $$ |$$ ____|$$ |]", ConsoleColor.DarkGreen);
WriteColor(@"[$$ | $$ |$$ | $$$$$$$ | \$$$$ | \$$$$$$ |\$$$$$$ |\$$$$$$$ |\$$$$$$$\ $$ |]", ConsoleColor.DarkGreen);
WriteColor(@"[\__| \__|\__| \_______/ \____/ \______/ \______/ \_______| \_______|\__|]", ConsoleColor.DarkGreen);
Console.WriteLine(Environment.NewLine);
WriteColor(@"[//--Informationen------------------------------------------------]", ConsoleColor.DarkGreen);
WriteColor($"[// Title:] {Assembly.GetEntryAssembly().GetName().Name}", ConsoleColor.DarkGreen);
WriteColor($"[// Version:] {Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyFileVersionAttribute>().Version}", ConsoleColor.DarkGreen);
WriteColor($"[// Autor:] {Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyCopyrightAttribute>().Copyright}", ConsoleColor.DarkGreen);
WriteColor(@"[//--Settings-----------------------------------------------------]", ConsoleColor.DarkGreen);
WriteColor($"[// Output folder:] {OUTPUT_PATH}", ConsoleColor.DarkGreen);
WriteColor($"[// Mod Id folder name:] {modId} (Absolute path: {PATH_PREFIX})", ConsoleColor.DarkGreen);
WriteColor($"[// Mod folder name:] {modFolder} (Absolute path: {ORIGINAL_PATH})", ConsoleColor.DarkGreen);
WriteColor(@"[//---------------------------------------------------------------]", ConsoleColor.DarkGreen);
WriteColor($"[// Blueprints:] To read blueprints they must begin with BP_", ConsoleColor.DarkGreen);
WriteColor($"[// Engrams:] To read engrams they must begin with EngramEntry", ConsoleColor.DarkGreen);
WriteColor($"[// Primal Item:] To read primal and spawncode items they must begin with PrimalItem", ConsoleColor.DarkGreen);
WriteColor($"[// Spawncode Dino:] To read creatures and tamed creatures they must begin with Character_BP", ConsoleColor.DarkGreen);
WriteColor(@"[//---------------------------------------------------------------]", ConsoleColor.DarkGreen);
Console.WriteLine(Environment.NewLine);
WriteColor($"[Push a random key to start the process]", ConsoleColor.DarkRed);
Console.WriteLine(Environment.NewLine);
Console.ReadKey();
files = Directory.GetFiles(Directory.GetCurrentDirectory());
if (IsArkModFolder())
{
ParseFiles();
WriteFiles();
Console.WriteLine(Environment.NewLine);
WriteColor(@"[//--Informationen------------------------------------------------]", ConsoleColor.DarkGreen);
WriteColor($"[// Read files:] {summeryFile.Count} Total, {engramFile.Count} Engrams, {blueprintFile.Count} Blueprints, {primalItemsFile.Count} Primal Items, {spawncodeItemsFile.Count} Spawncode Items, {spawncodeCreatureFile.Count} Spawncode Creatures", ConsoleColor.DarkGreen);
WriteColor($"[//] Looks like all worked fine ;)", ConsoleColor.DarkGreen);
WriteColor(@"[//---------------------------------------------------------------]", ConsoleColor.DarkGreen);
Console.WriteLine(Environment.NewLine);
}
else
{
WriteColor(@"[//--Error--------------------------------------------------------]", ConsoleColor.DarkRed);
WriteColor($"[// Error:] This folder dont have a PrimalGameData.", ConsoleColor.DarkRed);
WriteColor(@"[//---------------------------------------------------------------]", ConsoleColor.DarkRed);
}
Console.ReadKey();
}
/// <summary>
/// Check if the folder is a mod id. If then try to read a modmeta.info file to get the original name
/// </summary>
/// <param name="baseFolder">Foldername of the mod</param>
/// <returns>Original name of the mod folder</returns>
static string GetValidModFolder(string baseFolder)
{
int modId;
string modName = "";
bool isMod = int.TryParse(baseFolder, out modId);
if(!isMod)
{
return baseFolder;
}
foreach (var file in Directory.GetFiles("./"))
{
var filename = file.Split('\\').Last();
if (filename.Equals("./modmeta.info"))
{
var parts = File.ReadAllText(filename).Split('/');
if (parts.Count() >= 3)
{
modName = parts[3];
}
}
}
return string.IsNullOrEmpty(modName) ? baseFolder : modName;
}
/// <summary>
/// Parse all files and save them into list of strings
/// </summary>
static void ParseFiles()
{
Directory.CreateDirectory(OUTPUT_PATH);
// Delete files if exist
File.Delete(OUTPUT_PATH + SUMMERY_FILE + ".txt");
File.Delete(OUTPUT_PATH + BLUEPRINT_FILE + ".txt");
File.Delete(OUTPUT_PATH + ENGRAM_FILE + ".txt");
File.Delete(OUTPUT_PATH + PRIMAL_ITEMS_FILE + ".txt");
File.Delete(OUTPUT_PATH + SPAWNCODE_ITEMS_FILE + ".txt");
File.Delete(OUTPUT_PATH + SPAWNCODE_CREATURE_FILE + ".txt");
var path = Directory.GetCurrentDirectory();
var allItems = Directory.GetFiles(Directory.GetCurrentDirectory(), "*", SearchOption.AllDirectories);
foreach (var item in allItems)
{
var filename = Path.GetFileNameWithoutExtension(item);
if (filename.StartsWith("EngramEntry"))
{
var s = filename + "_C";
summeryFile.Add(new Summery
{
Type = SummeryEnum.ENGRAM,
Value = s
});
engramFile.Add(s);
continue;
}
if (filename.StartsWith("BP_"))
{
var s = ((char)34) + "Blueprint'" + item.Replace(path, PATH_PREFIX).Replace(".uasset", "." + filename).Replace(@"\", "/") + "'" + ((char)34);
summeryFile.Add(new Summery
{
Type = SummeryEnum.BLUEPRINT,
Value = s
});
blueprintFile.Add(s);
continue;
}
if (filename.StartsWith("PrimalItem"))
{
var s = "admincheat GiveItem " + ((char)34) + "Blueprint'" + item.Replace(path, PATH_PREFIX).Replace(".uasset", "." + filename).Replace(@"\", "/") + "'" + ((char)34) + " 1 1 0";
var ss = ((char)34) + "Blueprint'" + item.Replace(path, PATH_PREFIX).Replace(".uasset", "." + filename).Replace(@"\", "/") + "'" + ((char)34);
summeryFile.Add(new Summery
{
Type = SummeryEnum.SPAWNCODE_ITEM,
Value = s
});
summeryFile.Add(new Summery
{
Type = SummeryEnum.PRIMAL_ITEM,
Value = s
});
primalItemsFile.Add(ss);
spawncodeItemsFile.Add(s);
continue;
}
if (filename.Contains("Character_BP"))
{
var s = "admincheat SpawnDino " + ((char)34) + "Blueprint'" + item.Replace(path, PATH_PREFIX).Replace(".uasset", "." + filename).Replace(@"\", "/") + "'" + ((char)34) + " 500 0 0 120";
var ss = "admincheat GMSummon " + ((char)34) + filename + ((char)34) + " 120";
summeryFile.Add(new Summery
{
Type = SummeryEnum.SPAWNCODE_CREATURE,
Value = s
});
summeryFile.Add(new Summery
{
Type = SummeryEnum.SPAWNCODE_CREATURE,
Value = ss
});
continue;
}
}
}
/// <summary>
/// Write the content to the files
/// </summary>
static void WriteFiles()
{
WriteColor(@"[//--Summery------------------------------------------------------]", ConsoleColor.Cyan);
var type = "";
foreach (var item in summeryFile.OrderBy(el => el.Type))
{
if (type.Equals("") || !type.Equals(item.Type.ToString()))
{
if (!type.Equals(""))
{
File.AppendAllText(OUTPUT_PATH + SUMMERY_FILE + ".txt", $"//-------------------------------------------------------------------" + Environment.NewLine + Environment.NewLine);
}
type = item.Type.ToString();
File.AppendAllText(OUTPUT_PATH + SUMMERY_FILE + ".txt", $"//--{item.Type}------------------------------------------------------" + Environment.NewLine);
}
File.AppendAllText(OUTPUT_PATH + SUMMERY_FILE + ".txt", item.Value + Environment.NewLine);
WriteColor($"[// {item.Type}] {item.Value}", ConsoleColor.Cyan);
}
WriteColor(@"[//---------------------------------------------------------------]", ConsoleColor.Cyan);
Console.WriteLine(Environment.NewLine);
WriteColor(@"[//--Blueprints---------------------------------------------------]", ConsoleColor.Cyan);
foreach (var item in blueprintFile)
{
File.AppendAllText(OUTPUT_PATH + BLUEPRINT_FILE + ".txt", item + Environment.NewLine);
WriteColor($"[//] {item}", ConsoleColor.Cyan);
}
WriteColor(@"[//---------------------------------------------------------------]", ConsoleColor.Cyan);
Console.WriteLine(Environment.NewLine);
WriteColor(@"[//--Engrams------------------------------------------------------]", ConsoleColor.Cyan);
foreach (var item in engramFile)
{
File.AppendAllText(OUTPUT_PATH + ENGRAM_FILE + ".txt", item + Environment.NewLine);
WriteColor($"[//] {item}", ConsoleColor.Cyan);
}
WriteColor(@"[//---------------------------------------------------------------]", ConsoleColor.Cyan);
Console.WriteLine(Environment.NewLine);
WriteColor(@"[//--SpawncodeItems-----------------------------------------------]", ConsoleColor.Cyan);
foreach (var item in spawncodeItemsFile)
{
File.AppendAllText(OUTPUT_PATH + SPAWNCODE_ITEMS_FILE + ".txt", item + Environment.NewLine);
WriteColor($"[//] {item}", ConsoleColor.Cyan);
}
WriteColor(@"[//---------------------------------------------------------------]", ConsoleColor.Cyan);
Console.WriteLine(Environment.NewLine);
WriteColor(@"[//--PrimalItems--------------------------------------------------]", ConsoleColor.Cyan);
foreach (var item in primalItemsFile)
{
File.AppendAllText(OUTPUT_PATH + PRIMAL_ITEMS_FILE + ".txt", item + Environment.NewLine);
WriteColor($"[//] {item}", ConsoleColor.Cyan);
}
WriteColor(@"[//---------------------------------------------------------------]", ConsoleColor.Cyan);
Console.WriteLine(Environment.NewLine);
WriteColor(@"[//--CreatureSpawncodes-------------------------------------------]", ConsoleColor.Cyan);
foreach (var item in spawncodeCreatureFile)
{
File.AppendAllText(OUTPUT_PATH + SPAWNCODE_CREATURE_FILE + ".txt", item + Environment.NewLine);
WriteColor($"[//] {item}", ConsoleColor.Cyan);
}
WriteColor(@"[//---------------------------------------------------------------]", ConsoleColor.Cyan);
Console.WriteLine(Environment.NewLine);
}
/// <summary>
/// Write some coloring console messages for the user
/// https://stackoverflow.com/questions/2743260/is-it-possible-to-write-to-the-console-in-colour-in-net
/// </summary>
/// <param name="message">Message to write</param>
/// <param name="color">ConsoleColor value of the color</param>
static void WriteColor(string message, ConsoleColor color)
{
var pieces = Regex.Split(message, @"(\[[^\]]*\])");
for (int i = 0; i < pieces.Length; i++)
{
string piece = pieces[i];
if (piece.StartsWith("[") && piece.EndsWith("]"))
{
Console.ForegroundColor = color;
piece = piece.Substring(1, piece.Length - 2);
}
Console.Write(piece);
Console.ResetColor();
}
Console.WriteLine();
}
/// <summary>
/// Check if the folder has a file called PrimalGameData
/// </summary>
/// <returns>true if file exists otherwise false</returns>
private static bool IsArkModFolder()
{
foreach (string s in files)
{
string filename = Path.GetFileNameWithoutExtension(s);
if (filename.StartsWith("PrimalGameData"))
{
return true;
}
}
return false;
}
}
}