This repository was archived by the owner on May 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
168 lines (128 loc) · 5.4 KB
/
Program.cs
File metadata and controls
168 lines (128 loc) · 5.4 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
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
using Fluxzy.Utils.Curl;
using HydraDotNet.Core.Extensions;
using Microsoft.Win32;
using System.Diagnostics;
using System.Net;
using System.Numerics;
using System.Security.Claims;
using YamlDotNet.RepresentationModel;
using static Emulator.FirstBootHelpers;
namespace Emulator
{
internal class Program
{
private static Process? clashProcess;
private static PacketHandling? proxy;
private static bool hasShutDown = false;
static async Task Main(string[] args)
{
//Handle closing app
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
Console.CancelKeyPress += Console_CancelKeyPress;
//Starting
Console.WriteLine("Starting up...");
Console.WriteLine("Loading settings...");
Settings settings = new Settings();
//Load inv and randomize things
InventoryContainer.randomizeThings();
//Start clash
int fluxzyPort = int.TryParse(settings.SettingsData["General"]["FluxzyPort"], out int validfluxzyport) ? validfluxzyport : 8888;
int clashPort = int.TryParse(settings.SettingsData["General"]["ClashPort"], out int validclashport) ? validclashport : 7890;
Console.WriteLine("Starting clash...");
clashProcess = DependencyHelpers.startClash(clashPort, fluxzyPort);
if (clashProcess == null) Debug.exitWithError("Could not start clash!");
Debug.printSuccess(String.Format("Clash successfully started on address 127.0.0.1:{0}", clashPort));
//Start fluxzy proxy
Console.WriteLine("Starting fluxzy proxy...");
//Parse some settings
bool firstBoot = bool.TryParse(settings.SettingsData["General"]["FirstBoot"], out bool firstBootResult) ? firstBootResult : true;
if (firstBoot)
{
Console.Clear();
printFirstBootMessage("You will be prompted to accept a certificate. (This is necessary for the application to work)");
printFirstBootMessage("Please press 'Yes' on the certificate");
}
proxy = new PacketHandling(fluxzyPort);
await proxy.startProxy(new IPEndPoint(IPAddress.Loopback, clashPort), fluxzyPort);
if (firstBoot)
{
handleFirstBoot(settings);
}
Debug.printSuccess(String.Format("Fluxzy proxy successfully started on address 127.0.0.1:{0}", fluxzyPort));
Debug.printSuccess("Configured clash as system-wide proxy.");
Debug.printCaution("If you shutdown your PC during app usage, your proxy settings will not be automatically reverted!");
Debug.printCaution("Manually turn off 'Use a proxy server' in Windows proxy settings if you cannot connect to the internet!");
//Keep alive
await Task.Delay(-1);
}
private static void CurrentDomain_ProcessExit(object? sender, EventArgs e)
{
Task.Run(shutDown).Wait();
}
private static void Console_CancelKeyPress(object? sender, ConsoleCancelEventArgs e)
{
e.Cancel = true;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Shutting down...");
Console.ResetColor();
Task.Run(shutDown).Wait();
Environment.Exit(0);
}
private static async Task shutDown()
{
if (hasShutDown) return;
hasShutDown = true;
//Shutdown fluxzy proxy
if (proxy != null && proxy.Proxy != null)
{
await proxy.Proxy.DisposeAsync();
}
//Shutdown clash process
if (clashProcess != null && !clashProcess.HasExited)
{
clashProcess.Kill();
clashProcess.WaitForExit();
clashProcess?.Close();
clashProcess?.Dispose();
}
}
private static void handleFirstBoot(Settings settings)
{
Console.Clear();
printFirstBootMessage("Your game must be patched in order for this application to work.");
//Try to auto-find game
string? pakFolderPath = getMk1SteamFolder();
if (pakFolderPath != null)
{
printFirstBootMessage(String.Format("MK1 Pak folder path found at: {0} ", pakFolderPath));
}
else
{
while (pakFolderPath == null)
{
pakFolderPath = providePathManually();
}
}
//Gather aes
string? aes = null;
while (aes == null)
{
aes = provideAES();
}
printFirstBootMessage("Beginning unpacking... (Do not close the program during this process)");
patchGame(pakFolderPath, aes);
printFirstBootMessage("Successful patching!");
//Disable first boot
settings.SettingsData["General"]["FirstBoot"] = "false";
try
{
settings.Parser.WriteFile("settings.ini", settings.SettingsData);
}
catch (Exception e)
{
Debug.printError("Could not write to settings.ini file!");
Debug.printError("Full exception: " + e);
}
}
}
}