Skip to content

Commit

Permalink
Adds a compatibility layer to remove select Aki patches if they are d…
Browse files Browse the repository at this point in the history
…etected
  • Loading branch information
paulov-t committed May 1, 2024
1 parent 2af53a8 commit 43e805a
Showing 1 changed file with 62 additions and 39 deletions.
101 changes: 62 additions & 39 deletions Source/StayInTarkovPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
using StayInTarkov.AkiSupport.Singleplayer.Patches.RaidFix;
using System.Reflection;
using HarmonyLib;
using TMPro;

namespace StayInTarkov
{
Expand All @@ -42,12 +43,11 @@ namespace StayInTarkov
/// </summary>
[BepInPlugin("com.stayintarkov", "StayInTarkov", "1.11")]
[BepInProcess("EscapeFromTarkov.exe")]
// Ensure nobody tries to load this module with Fika
// Ensure nobody tries to load this module with Fika. They wont be compatible :)
[BepInIncompatibility("com.fika.core")]
// Ensure nobody tries to load this module with Aki Custom
//[BepInDependency("com.spt-aki.core", BepInDependency.DependencyFlags.SoftDependency)]
//[BepInDependency("com.spt-aki.singleplayer", BepInDependency.DependencyFlags.SoftDependency)]
//[BepInDependency("com.spt-aki.custom", BepInDependency.DependencyFlags.SoftDependency)]
[BepInDependency("com.spt-aki.singleplayer", BepInDependency.DependencyFlags.SoftDependency)]
[BepInDependency("com.spt-aki.custom", BepInDependency.DependencyFlags.SoftDependency)]
public class StayInTarkovPlugin : BaseUnityPlugin
{
/// <summary>
Expand Down Expand Up @@ -93,12 +93,42 @@ public class StayInTarkovPlugin : BaseUnityPlugin
public delegate void OnGameLoadedHandler(object sender, EventArgs e);
public event OnGameLoadedHandler OnGameLoaded;

private string[] SPTPatchesToRemove => [
"AddEnemyToAllGroupsInBotZonePatch",
"AirdropPatch",
"AirdropFlarePatch",
"AmmoUsedCounterPatch",
"ArmorDamageCounterPatch",
"BotDifficultyPatch",
"BotTemplateLimitPatch",
"BTRInteractionPatch",
"BTRExtractPassengersPatch",
"BTRPatch",
"DogtagPatch",
"EmptyInfilFixPatch",
"LabsKeycardRemovalPatch",
"LoadOfflineRaidScreenPatch",
"MaxBotPatch",
"OfflineSpawnPointPatch",
"OfflineRaidSettingsMenuPatch",
"ScavExfilPatch",
"ScavLateStartPatch",
"ScavLateStartPatch",
"ScavProfileLoadPatch",
"ScavRepAdjustmentPatch",
"ScavSellAllPriceStorePatch",
"ScavSellAllRequestPatch",
"VersionLabelPatch"
];

async Task Awake()
{
Instance = this;
Settings = new PluginConfigSettings(Logger, Config);
LogDependancyErrors();

DisableSPT();

// Gather the Major/Minor numbers of EFT ASAP
new VersionLabelPatch(Config).Enable();
OnGameLoaded += StayInTarkovPlugin_OnGameLoaded;
Expand All @@ -125,16 +155,20 @@ async Task Awake()
Logger.LogInfo($"Stay in Tarkov is loaded!");
}

void DisableSPT()
{
DisableAkiSingleplayer();
DisableAkiCustom();
}

private void StayInTarkovPlugin_OnGameLoaded(object sender, EventArgs e)
{
// Log the list
LogLoadedPlugins();

// Apply actions dependant on the list
//DisableAkiSingleplayer();
//DisableAkiCustom();
}



private void DisableAkiSingleplayer()
{
if (Chainloader.PluginInfos.Any(x => x.Key == "com.spt-aki.singleplayer"))
Expand All @@ -155,32 +189,13 @@ private void DisableAkiSingleplayer()
var akiPluginModulePatchTypes = akiPluginType.Assembly.GetTypes()
.Where(x => x.BaseType != null && x.BaseType.Name == "ModulePatch").ToArray();

var modulePatchType = akiPluginModulePatchTypes[0].BaseType;
if (modulePatchType == null)
{
Logger.LogError($"Unable to find modulePatchType");
if (!akiPluginModulePatchTypes.Any())
return;
}

var _harmony = ReflectionHelpers.GetFieldFromTypeByFieldType(modulePatchType, typeof(Harmony));
if (_harmony == null)
foreach (var removeType in SPTPatchesToRemove)
{
Logger.LogError($"Unable to find _harmony");
return;
RemovePatch(akiPluginModulePatchTypes, removeType);
}


//Harmony.UnpatchID(akiPluginModulePatchTypes.First(x => x.FullName == "Aki.SinglePlayer.Patches.Progression.OfflineSaveProfilePatch").Name);
//foreach(var akiPluginModulePatch in akiPluginModulePatchTypes)
//{
// Logger.LogInfo($"-> Removed {akiPluginModulePatch.FullName}");
// Harmony.UnpatchID(akiPluginModulePatch.Name);
//}


GameObject.Destroy(akiPlugin);
Logger.LogInfo($"AkiSingleplayerPlugin Removed.");

}
}

Expand All @@ -204,22 +219,30 @@ private void DisableAkiCustom()
var akiPluginModulePatchTypes = akiPluginType.Assembly.GetTypes()
.Where(x => x.BaseType != null && x.BaseType.Name == "ModulePatch");

GameObject.Destroy(akiPlugin);
Logger.LogInfo($"Aki Custom Removed.");
if (!akiPluginModulePatchTypes.Any())
return;

foreach (var akiPluginModulePatch in akiPluginModulePatchTypes)
foreach (var removeType in SPTPatchesToRemove)
{
Logger.LogInfo($"-> Removed {akiPluginModulePatch.FullName}");
Harmony.UnpatchID(akiPluginModulePatch.Name);
RemovePatch(akiPluginModulePatchTypes, removeType);
}

Logger.LogInfo(StayInTarkovPlugin.EFTVersionMajor);

VersionNumberClass.Current.Major = StayInTarkovPlugin.EFTVersionMajor;
VersionLabelPatch.DisplaySITVersionLabel(StayInTarkovPlugin.EFTVersionMajor, null);
}
}

private void RemovePatch(IEnumerable<Type> types, string typeToRemove)
{
var p = types.FirstOrDefault(x => x.Name == typeToRemove);
if (p != null)
RemovePatch(p);
}

private void RemovePatch(Type typeToRemove)
{
ReflectionHelpers.GetMethodForType(typeToRemove, "Disable").Invoke(Activator.CreateInstance(typeToRemove), []);
Logger.LogInfo($"-> Removed {typeToRemove.FullName}");
}

public void LogLoadedPlugins()
{
#if DEBUG
Expand Down

0 comments on commit 43e805a

Please sign in to comment.