0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00

Improved client mod whitelisting feature (!75)

* Turns out the Chainloader can be accessed from outside a BepInPlugin. Whoops
* A user-friendly error will be displayed before the game exits so that it's clear as to what's going wrong. Should prevent reports of crashing on game load now

Co-authored-by: Terkoiz <terkoiz@spt.dev>
Reviewed-on: SPT-AKI/Modules#75
Co-authored-by: Terkoiz <terkoiz@noreply.dev.sp-tarkov.com>
Co-committed-by: Terkoiz <terkoiz@noreply.dev.sp-tarkov.com>
This commit is contained in:
Terkoiz 2024-02-02 13:59:10 +00:00 committed by chomp
parent 9f158b6db3
commit a69eaabe35
2 changed files with 33 additions and 44 deletions

View File

@ -1,12 +1,7 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Aki.Common; using Aki.Common;
using Aki.Core.Patches; using Aki.Core.Patches;
using BepInEx; using BepInEx;
using BepInEx.Bootstrap;
using UnityEngine;
namespace Aki.Core namespace Aki.Core
{ {
@ -14,7 +9,7 @@ namespace Aki.Core
class AkiCorePlugin : BaseUnityPlugin class AkiCorePlugin : BaseUnityPlugin
{ {
// Temp static logger field, remove along with plugin whitelisting before release // Temp static logger field, remove along with plugin whitelisting before release
private static BepInEx.Logging.ManualLogSource _logger; internal static BepInEx.Logging.ManualLogSource _logger;
public void Awake() public void Awake()
{ {
@ -42,41 +37,5 @@ namespace Aki.Core
Logger.LogInfo("Completed: Aki.Core"); Logger.LogInfo("Completed: Aki.Core");
} }
/// <summary>
/// See <see cref="PreventClientModsPatch"/> for explanation on why this is needed.
/// Yes, I know this is jank but it's temporary and will be removed before release :)
/// </summary>
internal static void CheckForNonWhitelistedPlugins()
{
var whitelistedPlugins = new HashSet<string>
{
"com.spt-aki.core",
"com.spt-aki.custom",
"com.spt-aki.debugging",
"com.spt-aki.singleplayer",
"com.bepis.bepinex.configurationmanager",
"com.terkoiz.freecam",
"com.sinai.unityexplorer",
"com.cwx.debuggingtool-dxyz",
"com.cwx.debuggingtool",
"xyz.drakia.botdebug",
"com.kobrakon.camunsnap",
"RuntimeUnityEditor"
};
var disallowedPlugins = Chainloader.PluginInfos.Values.Select(pi => pi.Metadata.GUID).Except(whitelistedPlugins).ToArray();
if (disallowedPlugins.Any())
{
_logger.LogError($"One or more non-whitelisted plugins were detected. Mods are not allowed in BleedingEdge builds of SPT. Illegal plugins:\n{string.Join("\n", disallowedPlugins)}");
// Delay game shutdown by a little bit, since logging sometimes doesn't have enough time to write to file
Task.Run(() =>
{
Task.Delay(500);
Application.Quit(0);
});
}
}
} }
} }

View File

@ -1,5 +1,9 @@
using System.Reflection; using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Aki.Reflection.Patching; using Aki.Reflection.Patching;
using BepInEx.Bootstrap;
using EFT; using EFT;
using HarmonyLib; using HarmonyLib;
@ -18,7 +22,33 @@ namespace Aki.Core.Patches
[PatchPrefix] [PatchPrefix]
private static void Prefix() private static void Prefix()
{ {
AkiCorePlugin.CheckForNonWhitelistedPlugins(); CheckForNonWhitelistedPlugins();
}
private static void CheckForNonWhitelistedPlugins()
{
var whitelistedPlugins = new HashSet<string>
{
"com.spt-aki.core",
"com.spt-aki.custom",
"com.spt-aki.debugging",
"com.spt-aki.singleplayer",
"com.bepis.bepinex.configurationmanager",
"com.terkoiz.freecam",
"com.sinai.unityexplorer",
"com.cwx.debuggingtool-dxyz",
"com.cwx.debuggingtool",
"xyz.drakia.botdebug",
"com.kobrakon.camunsnap",
"RuntimeUnityEditor"
};
var disallowedPlugins = Chainloader.PluginInfos.Values.Select(pi => pi.Metadata.GUID).Except(whitelistedPlugins).ToArray();
if (disallowedPlugins.Any())
{
AkiCorePlugin._logger.LogError($"One or more non-whitelisted plugins were detected. Mods are not allowed in BleedingEdge builds of SPT. Illegal plugins:\n{string.Join("\n", disallowedPlugins)}");
throw new Exception("Non-debug client mods have been detected. Mods are not allowed in BleedingEdge builds of SPT - please remove them before playing!");
}
} }
} }
} }