0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 08:50:43 -05:00
modules/project/Aki.PrePatch/AkiBotsPrePatcher.cs
kiobu cc2377bf72 fix: difficulties response parsing (!113)
fixed bot difficulties model to match server response for `/singleplayer/settings/bot/difficulties`
also bumps up the sptBear and sptUsec enums so they don't collide with new pmcUSEC and pmcBEAR

Reviewed-on: SPT-AKI/Modules#113
Co-authored-by: kiobu <kiobu@sdf.org>
Co-committed-by: kiobu <kiobu@sdf.org>
2024-04-28 08:17:13 +00:00

75 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using BepInEx.Logging;
using Mono.Cecil;
namespace Aki.PrePatch
{
public static class AkiBotsPrePatcher
{
public static IEnumerable<string> TargetDLLs { get; } = new[] { "Assembly-CSharp.dll" };
public static int sptUsecValue = 51;
public static int sptBearValue = 52;
private static string _sptPluginFolder = "plugins/spt";
public static void Patch(ref AssemblyDefinition assembly)
{
// Make sure the user hasn't deleted the SPT plugins folder
string assemblyFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string sptPluginPath = Path.GetFullPath(Path.Combine(assemblyFolder, "..", _sptPluginFolder));
if (!ValidateSpt(sptPluginPath))
{
string message = $"'{sptPluginPath}' or required plugin files not found.\n\n" +
"Please re-install SPT. Exiting.";
MessageBoxHelper.Show(message, "[SPT-AKI] Missing Core Files", MessageBoxHelper.MessageBoxType.OK);
Environment.Exit(0);
return;
}
var botEnums = assembly.MainModule.GetType("EFT.WildSpawnType");
var sptUsec = new FieldDefinition("sptUsec",
FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal | FieldAttributes.HasDefault,
botEnums)
{ Constant = sptUsecValue };
var sptBear = new FieldDefinition("sptBear",
FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal | FieldAttributes.HasDefault,
botEnums)
{ Constant = sptBearValue };
botEnums.Fields.Add(sptUsec);
botEnums.Fields.Add(sptBear);
}
private static bool ValidateSpt(string sptPluginPath)
{
ManualLogSource logger = Logger.CreateLogSource(nameof(AkiBotsPrePatcher));
// Validate that the SPT plugin path exists
if (!Directory.Exists(sptPluginPath))
{
logger.LogError($"'{sptPluginPath}' directory not found");
return false;
}
// Validate that the folder exists, and contains our plugins
string[] sptPlugins = new string[] { "aki-core.dll", "aki-custom.dll", "aki-singleplayer.dll" };
string[] foundPlugins = Directory.GetFiles(sptPluginPath).Select(x => Path.GetFileName(x)).ToArray();
foreach (string plugin in sptPlugins)
{
if (!foundPlugins.Contains(plugin))
{
return false;
}
}
return true;
}
}
}