warvulture

This commit is contained in:
Ferdinando 2026-08-16 07:44:44 +02:00
commit 0aa1dc4dc8
19 changed files with 2432 additions and 24 deletions

View file

@ -11,19 +11,63 @@ namespace RacesOfValheim
// notices the player - not what a "press E to talk" merchant should do. Skipping Update()
// entirely leaves Interactable.Interact() (E opens StoreGui) and Hoverable.GetHoverText()
// (the "E - Talk" prompt) untouched, since neither of those depends on Update() running.
//
// The same prefix also refuses to run Update() on a Trader that has no rig to drive, which is
// the general form of a bug that reached a tester: Trader.Start() resolves m_animator and
// m_lookAt with GetComponentInChildren, and Update() then dereferences BOTH with no null check -
// m_animator.SetBool("Stand", ...) and m_lookAt.ResetTarget() on the branch taken whenever no
// player is nearby, which is most frames. A building is not a creature and has neither, so a
// Trader bolted onto one threw a NullReferenceException every frame and filled the BepInEx
// console. The prefabs that do that (the Dvergar bank, the Trol totem, the Hive Market) now
// disable their Trader outright, which is the real fix; this check is the net under it, and it
// costs one cached field read per trader per frame.
[HarmonyPatch(typeof(Trader), "Update")]
public static class FactionMerchantSuppressAmbientPatch
{
// Both fields are private in the assembly this project compiles against. Resolved once
// rather than through Traverse, because this runs on every trader on every frame.
private static readonly AccessTools.FieldRef<Trader, Animator> AnimatorField =
AccessTools.FieldRefAccess<Trader, Animator>("m_animator");
private static readonly AccessTools.FieldRef<Trader, LookAt> LookAtField =
AccessTools.FieldRefAccess<Trader, LookAt>("m_lookAt");
public static bool Prefix(Trader __instance)
{
if (((Component)__instance).GetComponent<FactionMerchant>() != null)
{
return false;
}
if (AnimatorField(__instance) == null || LookAtField(__instance) == null)
{
return false;
}
return true;
}
}
// Trader.Start() ends with InvokeRepeating("RandomTalk", m_randomTalkInterval,
// m_randomTalkInterval), and a Trader added with AddComponent comes up with that interval at
// zero, because nobody authored it in the editor. On a faction merchant the repeat is pure
// waste for as long as the creature exists: RandomTalk's first act is to read the animator's
// "Stand" bool, and nothing ever sets it, because Update() - the only thing that would - is
// suppressed for these by the patch above. So it wakes up, asks one question, answers no, and
// is scheduled again.
//
// Cancelled in a postfix rather than by skipping Start with a prefix: Start also resolves
// m_animator and m_lookAt and snaps a SnapToGround rig to the terrain, and none of that is in
// the way. Only the timer is.
[HarmonyPatch(typeof(Trader), "Start")]
public static class FactionMerchantStopRandomTalkPatch
{
public static void Postfix(Trader __instance)
{
if (((Component)__instance).GetComponent<FactionMerchant>() == null) return;
__instance.CancelInvoke("RandomTalk");
}
}
// Player.FindHoverObject() always figures out m_hoveringCreature correctly (it only
// needs a Character component on the hit collider, no Hoverable/Interactable
// involved) but separately sets m_hovering - the field the "E - Talk" prompt and the