Skip to content

Commit

Permalink
Update for 3.7.0 / 25793
Browse files Browse the repository at this point in the history
- Some classes are now named in ACS, so needed to update those
- Switch method retrieval from names to parameter comparison
  • Loading branch information
DrakiaXYZ committed Aug 13, 2023
1 parent 5d9d469 commit 9b33e54
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 31 deletions.
4 changes: 2 additions & 2 deletions BigBrainPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

namespace DrakiaXYZ.BigBrain
{
[BepInPlugin("xyz.drakia.bigbrain", "DrakiaXYZ-BigBrain", "0.2.0.0")]
[BepInDependency("com.spt-aki.core", "3.6.0")]
[BepInPlugin("xyz.drakia.bigbrain", "DrakiaXYZ-BigBrain", "0.3.0.0")]
[BepInDependency("com.spt-aki.core", "3.7.0")]
internal class BigBrainPlugin : BaseUnityPlugin
{
private void Awake()
Expand Down
2 changes: 1 addition & 1 deletion Brains/BrainManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static object GetActiveLayer(BotOwner botOwner)
return null;
}

BotBaseBrainClass botBrainStrategy = _strategyField.GetValue(botOwner.Brain.Agent) as BotBaseBrainClass;
BaseBrain botBrainStrategy = _strategyField.GetValue(botOwner.Brain.Agent) as BaseBrain;
if (botBrainStrategy == null)
{
return null;
Expand Down
2 changes: 1 addition & 1 deletion Patches/BotAgentUpdatePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static bool PatchPrefix(object __instance)
#endif

// Get values we'll use later
BotBaseBrainClass strategy = _strategyField.GetValue(__instance) as BotBaseBrainClass;
BaseBrain strategy = _strategyField.GetValue(__instance) as BaseBrain;
var aiCoreNodeDict = _logicInstanceDictField.GetValue(__instance) as IDictionary;

// Update the brain, this is instead of method_10 in the original code
Expand Down
11 changes: 8 additions & 3 deletions Patches/BotBaseBrainActivateLayerPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

using AICoreLogicLayerClass = AICoreLayerClass<BotLogicDecision>;
Expand All @@ -18,12 +19,16 @@ internal class BotBaseBrainActivateLayerPatch : ModulePatch

protected override MethodBase GetTargetMethod()
{
Type botBaseBrainClassType = typeof(BotBaseBrainClass);
Type aiCoreStrategyClassType = botBaseBrainClassType.BaseType;
Type baaseBrainType = typeof(BaseBrain);
Type aiCoreStrategyClassType = baaseBrainType.BaseType;

_activeLayerListField = AccessTools.Field(aiCoreStrategyClassType, "list_0");

return AccessTools.Method(aiCoreStrategyClassType, "method_4");
return AccessTools.GetDeclaredMethods(aiCoreStrategyClassType).Single(x =>
{
var parms = x.GetParameters();
return (parms.Length == 1 && parms[0].ParameterType == typeof(AICoreLogicLayerClass) && parms[0].Name == "layer");
});
}

[PatchPrefix]
Expand Down
21 changes: 13 additions & 8 deletions Patches/BotBaseBrainActivatePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using EFT;
using HarmonyLib;
using System;
using System.Linq;
using System.Reflection;

namespace DrakiaXYZ.BigBrain.Patches
Expand All @@ -14,24 +15,28 @@ namespace DrakiaXYZ.BigBrain.Patches
internal class BotBaseBrainActivatePatch : ModulePatch
{
private static FieldInfo _botOwnerField;
private static MethodInfo _addLayer;
private static MethodInfo _addLayerMethod;
protected override MethodBase GetTargetMethod()
{
Type botLogicBrainType = typeof(BotBaseBrainClass);
Type botBaseBrainType = botLogicBrainType.BaseType;
Type baseBrainType = typeof(BaseBrain);
Type aiCoreStrategyType = baseBrainType.BaseType;

_botOwnerField = AccessTools.Field(botLogicBrainType, "botOwner_0");
_addLayer = AccessTools.Method(botBaseBrainType, "method_0");
_botOwnerField = AccessTools.GetDeclaredFields(baseBrainType).Single(x => x.FieldType == typeof(BotOwner));
_addLayerMethod = AccessTools.GetDeclaredMethods(aiCoreStrategyType).Single(x =>
{
var parms = x.GetParameters();
return (parms.Length == 3 && parms[0].Name == "index" && parms[1].Name == "layer");
});

return AccessTools.Method(botBaseBrainType, "Activate");
return AccessTools.Method(aiCoreStrategyType, "Activate");
}

[PatchPrefix]
public static void PatchPrefix(object __instance)
{
try
{
BotBaseBrainClass botBrain = __instance as BotBaseBrainClass;
BaseBrain botBrain = __instance as BaseBrain;
BotOwner botOwner = (BotOwner)_botOwnerField.GetValue(botBrain);

foreach (BrainManager.LayerInfo layerInfo in BrainManager.Instance.CustomLayers.Values)
Expand All @@ -42,7 +47,7 @@ public static void PatchPrefix(object __instance)
#if DEBUG
Logger.LogDebug($" Injecting {customLayerWrapper.Name()}({layerInfo.customLayerId}) with priority {layerInfo.customLayerPriority}");
#endif
_addLayer.Invoke(botBrain, new object[] { layerInfo.customLayerId, customLayerWrapper, true });
_addLayerMethod.Invoke(botBrain, new object[] { layerInfo.customLayerId, customLayerWrapper, true });
}
}
}
Expand Down
21 changes: 15 additions & 6 deletions Patches/BotBaseBrainAddLayerPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

using AICoreLogicLayerClass = AICoreLayerClass<BotLogicDecision>;
Expand All @@ -20,20 +21,28 @@ internal class BotBaseBrainAddLayerPatch : ModulePatch

protected override MethodBase GetTargetMethod()
{
Type botLogicBrainType = typeof(BotBaseBrainClass);
Type botBaseBrainType = botLogicBrainType.BaseType;
Type baseBrainType = typeof(BaseBrain);
Type aiCoreStrategyType = baseBrainType.BaseType;

_layerDictionary = AccessTools.Field(botBaseBrainType, "dictionary_0");
_activateLayerMethod = AccessTools.Method(botBaseBrainType, "method_4");
_layerDictionary = AccessTools.Field(aiCoreStrategyType, "dictionary_0");
_activateLayerMethod = AccessTools.GetDeclaredMethods(aiCoreStrategyType).Single(x =>
{
var parms = x.GetParameters();
return (parms.Length == 1 && parms[0].ParameterType == typeof(AICoreLogicLayerClass) && parms[0].Name == "layer");
});

return AccessTools.Method(botBaseBrainType, "method_0");
return AccessTools.GetDeclaredMethods(aiCoreStrategyType).Single(x =>
{
var parms = x.GetParameters();
return (parms.Length == 3 && parms[0].Name == "index" && parms[1].Name == "layer");
});
}

[PatchPrefix]
public static bool PatchPrefix(object __instance, int index, AICoreLogicLayerClass layer, bool activeOnStart, ref bool __result)
{
// Make sure we're not excluding this layer from this brain
BotBaseBrainClass botBrain = __instance as BotBaseBrainClass;
BaseBrain botBrain = __instance as BaseBrain;
foreach (BrainManager.ExcludeLayerInfo excludeInfo in BrainManager.Instance.ExcludeLayers)
{
if (layer.Name() == excludeInfo.excludeLayerName && excludeInfo.excludeLayerBrains.Contains(botBrain.ShortName()))
Expand Down
16 changes: 8 additions & 8 deletions Patches/BotBaseBrainUpdatePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ internal class BotBaseBrainUpdatePatch : ModulePatch

protected override MethodBase GetTargetMethod()
{
Type botLogicBrainType = typeof(BotBaseBrainClass);
Type botBaseBrainType = botLogicBrainType.BaseType;
Type baseBrainType = typeof(BaseBrain);
Type aiCoreStrategyType = baseBrainType.BaseType;

string activeLayerPropertyName = Utils.GetPropertyNameByType(botBaseBrainType, typeof(AICoreLogicLayerClass));
_activeLayerGetter = AccessTools.PropertyGetter(botBaseBrainType, activeLayerPropertyName);
_activeLayerSetter = AccessTools.PropertySetter(botBaseBrainType, activeLayerPropertyName);
string activeLayerPropertyName = Utils.GetPropertyNameByType(aiCoreStrategyType, typeof(AICoreLogicLayerClass));
_activeLayerGetter = AccessTools.PropertyGetter(aiCoreStrategyType, activeLayerPropertyName);
_activeLayerSetter = AccessTools.PropertySetter(aiCoreStrategyType, activeLayerPropertyName);

_activeLayerListField = Utils.GetFieldByType(botBaseBrainType, typeof(List<AICoreLogicLayerClass>));
_onLayerChangedToField = Utils.GetFieldByType(botBaseBrainType, typeof(Action<AICoreLogicLayerClass>));
_activeLayerListField = Utils.GetFieldByType(aiCoreStrategyType, typeof(List<AICoreLogicLayerClass>));
_onLayerChangedToField = Utils.GetFieldByType(aiCoreStrategyType, typeof(Action<AICoreLogicLayerClass>));

return AccessTools.Method(botBaseBrainType, "Update");
return AccessTools.Method(aiCoreStrategyType, "Update");
}

[PatchPrefix]
Expand Down
7 changes: 6 additions & 1 deletion Patches/BotBrainCreateLogicNodePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using EFT;
using HarmonyLib;
using System;
using System.Linq;
using System.Reflection;

namespace DrakiaXYZ.BigBrain.Patches
Expand All @@ -16,7 +17,11 @@ internal class BotBrainCreateLogicNodePatch : ModulePatch

protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(BotBrainClass), "method_0");
return AccessTools.GetDeclaredMethods(typeof(StandartBotBrain)).Single(x =>
{
var parms = x.GetParameters();
return (parms.Length == 1 && parms[0].ParameterType == typeof(BotLogicDecision) && parms[0].Name == "decision");
});
}

[PatchPrefix]
Expand Down
2 changes: 1 addition & 1 deletion Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.2.0.0")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: TarkovVersion(25206)]
[assembly: TarkovVersion(25793)]

0 comments on commit 9b33e54

Please sign in to comment.