0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 05:50:44 -05:00
modules/project/Aki.PrePatch/AkiBotsPrePatcher.cs

75 lines
2.8 KiB
C#
Raw Normal View History

using System;
2023-03-03 18:52:31 +00:00
using System.Collections.Generic;
using System.IO;
using System.Linq;
using BepInEx.Logging;
2023-03-03 18:52:31 +00:00
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;
2023-03-03 18:52:31 +00:00
private static string _sptPluginFolder = "plugins/spt";
2023-03-03 18:52:31 +00:00
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;
}
2023-03-03 18:52:31 +00:00
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;
}
2023-03-03 18:52:31 +00:00
}
}