Skip to content

Commit 019ee4e

Browse files
mattwolf0Measurity
andauthored
feat(launcher): warn when BepInEx mods are detected before starting (SubnauticaNitrox#2569)
Co-authored-by: Measurity <1107063+Measurity@users.noreply.github.com>
1 parent 064b974 commit 019ee4e

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

Nitrox.Launcher/Models/Utils/GameInspect.cs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
4+
using System.Linq;
35
using System.Threading.Tasks;
46
using Nitrox.Launcher.Models.Services;
57
using Nitrox.Launcher.ViewModels;
68
using Nitrox.Model.Core;
7-
using Nitrox.Model.Helper;
89
using Nitrox.Model.Logger;
910
using Nitrox.Model.Platforms.OS.Shared;
1011

@@ -20,7 +21,7 @@ public static async Task<bool> IsOutdatedGameAndNotify(string gameInstallDir, Di
2021
try
2122
{
2223
ArgumentException.ThrowIfNullOrWhiteSpace(gameInstallDir);
23-
24+
2425
string gameVersionFile = Path.Combine(gameInstallDir, GameInfo.Subnautica.DataFolder, "StreamingAssets", "SNUnmanagedData", "plastic_status.ignore");
2526
if (int.TryParse(await File.ReadAllTextAsync(gameVersionFile), out int gameVersion) && gameVersion < NitroxEnvironment.GameMinimumVersion)
2627
{
@@ -57,8 +58,40 @@ public static bool WarnIfGameProcessExists(GameInfo game)
5758
{
5859
return false;
5960
}
60-
6161
LauncherNotifier.Warning($"An instance of {game.FullName} is already running");
6262
return true;
6363
}
64+
65+
public static void WarnIfBepInExMods(string gameDir)
66+
{
67+
if (string.IsNullOrWhiteSpace(gameDir) || !Directory.Exists(gameDir))
68+
{
69+
return;
70+
}
71+
string bepRoot = Path.Combine(gameDir, "BepInEx");
72+
if (!Directory.Exists(bepRoot))
73+
{
74+
return;
75+
}
76+
77+
int modDllCount = GetDllPaths(Path.Combine(bepRoot, "plugins")).Count();
78+
modDllCount += GetDllPaths(Path.Combine(bepRoot, "patchers")).Count();
79+
if (modDllCount > 0)
80+
{
81+
Log.Warn($"BepInEx plugins detected: {modDllCount}");
82+
LauncherNotifier.Warning($"BepInEx mod(s) were detected ({modDllCount}). Nitrox multiplayer does not support mods and they may cause instability.");
83+
}
84+
85+
static IEnumerable<string> GetDllPaths(string path)
86+
{
87+
try
88+
{
89+
return Directory.EnumerateFiles(path, "*.dll", SearchOption.AllDirectories);
90+
}
91+
catch (IOException)
92+
{
93+
return [];
94+
}
95+
}
96+
}
6497
}

Nitrox.Launcher/ViewModels/LaunchGameViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ private async Task StartMultiplayerAsync(string[]? args = null)
158158
Log.Warn("Seems like QModManager is installed");
159159
LauncherNotifier.Warning("QModManager Detected in the game folder");
160160
}
161+
GameInspect.WarnIfBepInExMods(NitroxUser.GamePath);
161162

162163
return true;
163164
});

0 commit comments

Comments
 (0)