Skip to content

Commit

Permalink
Fix bugs with apostrophes, and cleanup actor states on reload
Browse files Browse the repository at this point in the history
  • Loading branch information
MinLL committed Nov 6, 2024
1 parent f759784 commit 814096d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
30 changes: 15 additions & 15 deletions Scripts/Source/minai_AIFF.psc
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,6 @@ Function InitFollow()
bHasFollowPlayer = True
EndFunction

Function CleanupFollow()
If !bHasFollowPlayer
Main.Debug("[FollowTarget] CleanupFollow follow not enable")
Return
EndIf

actor[] actors = GetNearbyAI()
int i = 0
while i < actors.Length
EndFollowTarget(actors[i], true)
i += 1
EndWhile
EndFunction

Function Maintenance(minai_MainQuestController _main)
if (main.GetVersion() != main.CurrentVersion)
Main.Info("AIFF - Maintenance: Version update detected. Resetting action registry.")
Expand Down Expand Up @@ -124,7 +110,21 @@ Function Maintenance(minai_MainQuestController _main)
; StoreContext("minai", "testKey", "This is dynamically persisted context!", 1200)

InitFollow()
CleanupFollow()
CleanupStates()
EndFunction

Function CleanupStates()
actor[] actors = GetNearbyAI()
int i = 0
while i < actors.Length
actor akTarget = actors[i]
SetActorVariable(akTarget, "inCombat", akTarget.GetCombatState() > 0)
SetActorVariable(akTarget, "hostileToPlayer", akTarget.IsHostileToActor(player))
SetActorVariable(akTarget, "isBleedingOut", akTarget.isBleedingOut())
SetActorVariable(akTarget, "scene", akTarget.GetCurrentScene())
EndFollowTarget(actors[i], true)
i += 1
EndWhile
EndFunction

Function StartFollowTarget(actor akNpc, actor akTarget)
Expand Down
Binary file modified Scripts/minai_AIFF.pex
Binary file not shown.
2 changes: 2 additions & 0 deletions minai_plugin/globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
require_once("util.php");
if ($GLOBALS["HERIKA_NAME"] == "Player")
return;
if (!isset($GLOBALS["speaker"]))
$GLOBALS["speaker"] = $GLOBALS["HERIKA_NAME"];
$race = str_replace(" ", "", strtolower(GetActorValue($GLOBALS["speaker"], "Race")));
$gender = strtolower(GetActorValue($GLOBALS["speaker"], "Gender"));
$fallback = $GLOBALS["voicetype_fallbacks"][$gender.$race];
Expand Down
24 changes: 12 additions & 12 deletions minai_plugin/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@
$name = strtolower($name);
$GLOBALS[MINAI_ACTOR_VALUE_CACHE][$name] = [];

$idPrefix = $GLOBALS["db"]->escape("_minai_{$name}//");

$idPrefix = "_minai_{$name}//";
$origLength = strlen($idPrefix);
$idPrefix = $GLOBALS["db"]->escape($idPrefix);
$query = "select * from conf_opts where LOWER(id) like LOWER('{$idPrefix}%')";
$ret = $GLOBALS["db"]->fetchAll($query);

// error_log("Building cache for $name");
foreach ($ret as $row) {
//do this instead of split // because $name could have // in it
$key = substr(strtolower($row['id']), strlen($idPrefix));
$key = substr(strtolower($row['id']), $origLength);
$value = $row['value'];
// error_log($name . ':: (' . $key . ') ' . $row['id'] . ' = ' . $row['value']);
$GLOBALS[MINAI_ACTOR_VALUE_CACHE][$name][$key] = $value;
}
}
Expand All @@ -50,17 +52,15 @@ function CanVibrate($name) {
// Return the specified actor value.
// Caches the results of several queries that are repeatedly referenced.
Function GetActorValue($name, $key, $preserveCase=false, $skipCache=false) {
$name = addslashes($name);
$key = addslashes($key);

// error_log("Looking up $name: $key");
If (!$preserveCase && !$skipCache) {
$name = strtolower($name);
$key = strtolower($key);

If (!HasActorValueCache($name)) {
BuildActorValueCache($name);
}

// error_log("Checking cache: $name, $key");
$ret = GetActorValueCache($name, $key);
return $ret === null ? "" : strtolower($ret);
}
Expand All @@ -81,8 +81,8 @@ function CanVibrate($name) {
}

Function IsEnabled($name, $key) {
$name = strtolower($name);
return $GLOBALS["db"]->fetchAll("select 1 from conf_opts where LOWER(id)=LOWER('_minai_{$name}//{$key}') and LOWER(value)=LOWER('TRUE')");
$name = strtolower($GLOBALS["db"]->escape($name));
return $GLOBALS["db"]->fetchAll("select 1 from conf_opts where LOWER(id)=LOWER('_minai_{$name}//{$key}') and LOWER(value)=LOWER('TRUE')");
}

Function IsSexActive() {
Expand Down Expand Up @@ -181,8 +181,8 @@ function CanVibrate($name) {


Function IsActionEnabled($actionName) {
$actionName = strtolower($actionName);
return $GLOBALS["db"]->fetchAll("select 1 from conf_opts where LOWER(id)=LOWER('_minai_ACTION//{$actionName}') and LOWER(value)=LOWER('TRUE')");
$actionName = strtolower($GLOBALS["db"]->escape($actionName));
return $GLOBALS["db"]->fetchAll("select 1 from conf_opts where LOWER(id)=LOWER('_minai_ACTION//{$actionName}') and LOWER(value)=LOWER('TRUE')");
}


Expand Down

0 comments on commit 814096d

Please sign in to comment.