forked from RusFeniks/MinecraftUpdater-ClientSide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameManager.cs
More file actions
79 lines (66 loc) · 3.64 KB
/
GameManager.cs
File metadata and controls
79 lines (66 loc) · 3.64 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
77
78
79
using System;
using System.Diagnostics;
using System.IO;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Windows;
namespace MinecraftUpdater
{
class GameManager
{
public GameManager() {}
public void Run(string gamePath, string javaPath, int RAM, string login, string password, string customParams)
{
if (Regex.IsMatch(gamePath, "[А-я ]+"))
{
MessageBox.Show("Путь до клиента игры содержит пробелы, либо символы, отличные от латинницы.\n" +
"Это может вызвать ошибки при запуске игры. Настоятельно рекомендуется изменить путь в настройках лаунчера.", "Ошибка пути");
return;
}
string userModsFolderPath = Path.Combine(gamePath, "UserMods");
if(Directory.Exists(userModsFolderPath))
{
string modsFolder = Path.Combine(gamePath, "mods");
string[] userMods = Directory.GetFiles(userModsFolderPath);
foreach(string userMod in userMods)
{
string fileInModsFolder = Path.Combine(modsFolder, Path.GetFileName(userMod));
if(!File.Exists(fileInModsFolder))
{
File.Copy(userMod, fileInModsFolder);
}
}
}
string launchFilePath = Path.Combine(gamePath, ".init");
// Основная строка запуска, содержащая список всех требуемых библиотек, а также различные оптимизации лежит в файле .launch
if (!File.Exists(launchFilePath))
{
MessageBox.Show("Отсутствует файл с параметрами запуска.\n" +
"Убедитесь, что путь до клиента указан верно и клиент имеет последние обновления.", "Ошибка запуска");
return;
}
byte[] uuidHash = MD5.Create().ComputeHash(BitConverter.GetBytes(login.GetHashCode()));
string uuid = BitConverter.ToString(uuidHash).Replace("-", "").ToLower();
byte[] passwordHash = MD5.Create().ComputeHash(BitConverter.GetBytes(password.GetHashCode()));
File.WriteAllText(Path.Combine(gamePath, ".sl_password"), BitConverter.ToString(passwordHash).Replace("-", "").ToLower());
string launchString = File.ReadAllText(launchFilePath);
launchString = launchString.Replace("%login%", login);
launchString = launchString.Replace("%ram%", RAM.ToString());
launchString = launchString.Replace("%javaPath%", javaPath);
launchString = launchString.Replace("%gamePath%", gamePath);
launchString = launchString.Replace("%uuid%", uuid);
launchString = launchString.Replace("%customParams%", customParams);
try
{
Directory.SetCurrentDirectory(Path.Combine(gamePath));
Process java = Process.Start(javaPath, launchString);
Environment.Exit(0);
}
catch (Exception error)
{
MessageBox.Show($"Не могу запустить процесс {javaPath}: {error.Message}\nУбедитесь что у вас установлена Java 8");
}
return;
}
}
}