-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
135 lines (108 loc) · 4.21 KB
/
Program.cs
File metadata and controls
135 lines (108 loc) · 4.21 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
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Management;
namespace Fallout76Proxy
{
class BethesdaLauncherMissedException : Exception { public BethesdaLauncherMissedException(string message) : base(message) { } };
class NotStartedException : Exception { public NotStartedException(string message) : base(message) { } };
class TooManyStartedException : Exception { public TooManyStartedException(string message) : base(message) { } };
class StrangeArguments : Exception { public StrangeArguments(string message) : base(message) { } };
class Program
{
enum ModEnablerState
{
None,
Disabled,
Enabled
}
static string GetCommandLine(string ProcessName)
{
ManagementClass mngmtClass = new ManagementClass("Win32_Process");
foreach (ManagementObject o in mngmtClass.GetInstances())
{
if (o["Name"].Equals(ProcessName))
{
return (string) o["CommandLine"];
}
}
throw new NotStartedException("Can't get Fallout76 arguments");
}
static bool Fallout76Exists()
{
Process[] fallouts76 = Process.GetProcessesByName("Fallout76");
return fallouts76.Count() > 0;
}
static ModEnablerState GetModEnablerState()
{
if (!File.Exists("mods.txt"))
{
return ModEnablerState.None;
}
string content = File.ReadAllText("mods.txt");
ModEnablerState modEnablerState = (ModEnablerState) Enum.Parse(typeof(ModEnablerState), content);
return modEnablerState;
}
static void SetModEnablerState(ModEnablerState modEnablerState)
{
string content = modEnablerState.ToString();
File.WriteAllText("mods.txt", content);
}
static void ModsManagerProcess()
{
if (GetModEnablerState() == ModEnablerState.None)
{
Console.WriteLine("Would you like to try mods enabler?");
Console.WriteLine("It will be add all BA2 mods from game folder to Fallout76Custom at each start.");
Console.WriteLine("Also it detecting mods conflicts.");
Console.WriteLine("\nWrite Y to enable this feature or anything else to skip.");
Console.WriteLine("You can change it anytime by removing mods.txt near this exe.");
ConsoleKeyInfo userChoose = Console.ReadKey();
Console.WriteLine();
if (userChoose.Key == ConsoleKey.Y)
{
SetModEnablerState(ModEnablerState.Enabled);
}
else
{
SetModEnablerState(ModEnablerState.Disabled);
}
}
if (GetModEnablerState() == ModEnablerState.Enabled)
{
ModManager modManager = new ModManager();
modManager.Process();
}
}
static void Launch()
{
Console.Title = "Fallout76 Steam overlay";
ModsManagerProcess();
if (!BethesdaLauncher.Installed())
throw new BethesdaLauncherMissedException("Try to reinstall bethesda launcher.");
Console.WriteLine("Starting Fallout76 from BethesdaLauncher.");
BethesdaLauncher.Start(BethesdaGames.Fallout76);
Console.WriteLine("Waiting for game started.");
GameManager fallout76 = new GameManager("Fallout76");
fallout76.WaitFor();
Console.WriteLine("Restarting Fallout 76 as child process.");
fallout76.RestartAsChild();
Console.WriteLine("Closing BethesdaLauncher.");
BethesdaLauncher.Stop();
}
static void Main(string[] args)
{
try
{
Launch();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
Console.WriteLine("\nPress any key to exit...");
Console.Read();
}
}
}
}