Skip to content

Commit

Permalink
- Fix potential NRE
Browse files Browse the repository at this point in the history
  • Loading branch information
DrakiaXYZ committed Jul 30, 2023
1 parent 51290d5 commit 5d9d469
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Internal/CustomLayerWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ public CustomLayerWrapper(Type customLayerType, BotOwner bot, int priority) : ba
{
Logger = BepInEx.Logging.Logger.CreateLogSource(GetType().Name);
customLayer = (CustomLayer)Activator.CreateInstance(customLayerType, new object[] { bot, priority });

if (_logicInstanceDictField == null)
{
Type botAgentType = typeof(AICoreLogicAgentClass);
_logicInstanceDictField = AccessTools.Field(botAgentType, "dictionary_0");
}
}

public override AILogicActionResultStruct GetDecision()
Expand Down Expand Up @@ -123,6 +117,12 @@ static internal BaseNodeClass GetLogicInstance(BotOwner botOwner)
return null;
}

if (_logicInstanceDictField == null)
{
Type botAgentType = typeof(AICoreLogicAgentClass);
_logicInstanceDictField = AccessTools.Field(botAgentType, "dictionary_0");
}

BotLogicDecision logicDecision = botOwner.Brain.Agent.LastResult().Action;
var aiCoreNodeDict = _logicInstanceDictField.GetValue(botOwner.Brain.Agent) as IDictionary;
return aiCoreNodeDict[logicDecision] as BaseNodeClass;
Expand Down

0 comments on commit 5d9d469

Please sign in to comment.