Repository navigation
Expand file tree
/
Copy pathBanModBepInExVersionGuard.cs
More file actions
209 lines (168 loc) · 7.11 KB
/
Copy pathBanModBepInExVersionGuard.cs
File metadata and controls
209 lines (168 loc) · 7.11 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
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
using BepInEx;
using HarmonyLib;
using System;
using System.Diagnostics;
using System.Reflection;
using UnityEngine;
using Debug = UnityEngine.Debug;
namespace BanMod
{
internal static class BanModBepInExVersionGuard
{
private const string RequiredVersion = "6.0.0-be.735";
private static bool _checked;
internal static void CheckAndWarn()
{
if (_checked)
return;
_checked = true;
string detectedVersion = GetLoadedBepInExVersion();
string detectedBuild = GetShortBepInExVersion(detectedVersion);
try
{
Debug.Log("[BANMOD] Loaded BepInEx version: " + detectedVersion);
}
catch { }
if (IsRequiredVersion(detectedVersion))
return;
string message =
"<size=135%><b><color=#FF3B30>⚠ WARNING ⚠</color></b></size>\n\n" +
"<size=115%><b><color=#FF9500>Incompatible BepInEx version detected!</color></b></size>\n\n" +
"<color=#FFFFFF>Required BepInEx version</color>\n" +
"<color=#34C759><b>" + RequiredVersion + "</b></color>\n\n" +
"<color=#FFFFFF>Detected BepInEx version</color>\n" +
"<color=#FF453A><b>" + detectedBuild + "</b></color>\n\n" +
"<color=#FFD60A><b>BanMod may not work correctly with this BepInEx version.</b></color>\n\n" +
"<size=115%><b><color=#64D2FF>HOW TO FIX IT</color></b></size>\n\n" +
"<b>1.</b> Close <b>Among Us</b> completely.\n\n" +
"<b>2.</b> Open the official BanMod GitHub release page:\n" +
"<color=#5AC8FA><u>https://github.com/GiannBart/BanMod/releases/latest</u></color>\n\n" +
"<b>3.</b> Download the <b>ZIP file that matches your game platform</b> " +
"(for example <b>Steam / Itch.io</b> or the corresponding version for your installation).\n\n" +
"<b>4.</b> Open your Among Us installation folder.\n\n" +
"<b>5.</b> Delete the existing:\n" +
"<color=#FF9F0A><b>BepInEx/core</b></color>\n" +
"folder before installing the new files.\n\n" +
"<b>6.</b> It is also recommended to delete:\n" +
"<color=#FF9F0A><b>BepInEx/interop</b></color>\n" +
"so that BepInEx can regenerate it correctly on the next launch.\n\n" +
"<b>7.</b> Extract the contents of the downloaded BanMod ZIP " +
"<b>directly into the Among Us folder</b> and allow Windows to replace existing files.\n\n" +
"<color=#FF453A><b>IMPORTANT:</b></color>\n" +
"Do <b>NOT</b> replace only <b>BepInEx.Core.dll</b> and do not mix files from different " +
"BepInEx versions. The entire BepInEx runtime must use the same build.\n\n" +
"<b>8.</b> Start Among Us again.\n" +
"BepInEx should now report:\n" +
"<color=#34C759><b>" + RequiredVersion + "</b></color>\n\n" +
"<size=90%><color=#8E8E93>" +
"If this warning still appears after reinstalling, verify that you extracted the correct " +
"ZIP into the actual Among Us installation directory." +
"</color></size>";
try
{
Debug.LogWarning(
"[BANMOD] Unsupported BepInEx version. Required: " +
RequiredVersion + " | Detected: " + detectedVersion);
}
catch { }
try
{
BanModCommunicationUi.EnsureCreated();
if (BanModCommunicationUi.Instance != null)
{
BanModCommunicationUi.Instance.ShowMessagePopup(
"BANMOD - BepInEx",
message
);
return;
}
}
catch (Exception ex)
{
try
{
Debug.LogWarning(
"[BANMOD] Could not show BepInEx version popup: " +
ex.Message);
}
catch { }
}
}
internal static string GetLoadedBepInExVersion()
{
try
{
Assembly coreAssembly = typeof(Paths).Assembly;
AssemblyInformationalVersionAttribute informational =
coreAssembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
if (informational != null &&
!string.IsNullOrWhiteSpace(informational.InformationalVersion))
{
return informational.InformationalVersion.Trim();
}
try
{
if (!string.IsNullOrWhiteSpace(coreAssembly.Location))
{
FileVersionInfo versionInfo =
FileVersionInfo.GetVersionInfo(coreAssembly.Location);
if (versionInfo != null &&
!string.IsNullOrWhiteSpace(versionInfo.ProductVersion))
{
return versionInfo.ProductVersion.Trim();
}
}
}
catch { }
Version assemblyVersion = coreAssembly.GetName().Version;
return assemblyVersion != null
? assemblyVersion.ToString()
: "unknown";
}
catch (Exception ex)
{
try
{
Debug.LogWarning(
"[BANMOD] Failed to detect BepInEx version: " +
ex.Message);
}
catch { }
return "unknown";
}
}
private static string GetShortBepInExVersion(string version)
{
if (string.IsNullOrWhiteSpace(version))
return "unknown";
int plusIndex = version.IndexOf('+');
if (plusIndex > 0)
return version.Substring(0, plusIndex);
return version;
}
private static bool IsRequiredVersion(string version)
{
if (string.IsNullOrWhiteSpace(version))
return false;
string value = version.Trim();
if (!value.StartsWith(
RequiredVersion,
StringComparison.OrdinalIgnoreCase))
{
return false;
}
if (value.Length == RequiredVersion.Length)
return true;
return value.Length > RequiredVersion.Length &&
value[RequiredVersion.Length] == '+';
}
}
[HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.Start))]
internal static class BanModBepInExVersionGuardMainMenuPatch
{
private static void Postfix()
{
BanModBepInExVersionGuard.CheckAndWarn();
}
}
}