DezzyCode Forum
Sign in with DiscordLogin

Following tamed deer + OdinHorse 1.9.1: NullReferenceException flood, players can't walk

LockedBugFixed 0.1.5 by Dollar_Sprouts · yesterday

Status
Fixed 0.1.5
Version
0.1.4
Mode
Multiplayer / server

Steps to reproduce

1. Install BetrTame 0.1.4 and OdinHorse 1.9.1 (server and clients).
2. Tame a deer with BetrTame.
3. Tell the deer to follow you (E).
4. Try to walk: you can still jump but can't move, and BepInEx/LogOutput.log fills with the NullReferenceException below (~50 per second).
Log excerpt
NullReferenceException: Object reference not set to an instance of an object
OdinHorse.OdinHorse+Tamed_Follow_patch.Prefix (GameObject go, Single dt, BaseAI& __instance)
(wrapper dynamic-method) BaseAI.DMD<BaseAI::Follow>(BaseAI,GameObject,single)
BetrTame.Animals+Think.Prefix (AnimalAI __instance, Single dt, Boolean& __result)
(wrapper dynamic-method) AnimalAI.DMD<AnimalAI::UpdateAI>(AnimalAI,single)
MonoUpdatersExtra.UpdateAI (...)
MonoUpdaters.FixedUpdate ()
Dollar_Sprouts Newcomer #1

Hi, and thanks for BetrTame! It's working well for us: it sets up 71 creatures, and greydwarf and deer taming work. We hit one compatibility problem, and we have one note.

Setup

  • Dedicated Linux server, Valheim 1.0.20 (network version 41), BepInExPack 5.4.2351
  • Mods on server and clients: BetrTame 0.1.4, Jotunn 2.30.2, ValheimPlus (Grantapher fork) 0.10.2.0, OdinHorse 1.9.1, shrooms 1.5.0
  • Clients: one native Linux client, one Windows 10 client
  • BetrTame config changes: Taming time = 0.25, Growing up time = 0.25, wild stars Enabled = false, knocked out Enabled = false. Everything else is default, including Command every tame = true.

Bug: players can jump but not walk while a tamed deer follows
After we tamed a deer and set it to follow, both players could still jump but could no longer walk. The client's BepInEx log showed about 50 errors per second (over 4,700 in total), all the same (see the log excerpt below).

Cause: OdinHorse puts a prefix on BaseAI.Follow that does (__instance as MonsterAI).GetFollowTarget() for every tamed creature. BetrTame's Animals.Think calls BaseAI.Follow for AnimalAI tames like deer, so the cast gives null and the prefix throws. The throw happens inside MonoUpdaters.FixedUpdate, which cuts off the rest of that physics update, so player movement stops working.

Strictly speaking this is OdinHorse's bug. But only BetrTame calls Follow on an AnimalAI, so other BetrTame users with OdinHorse will hit it too. A note in the README, or a guard on your side, could save people some confusion.

Our workaround: a small plugin that loads after OdinHorse and skips OdinHorse's prefix unless the AI is a MonsterAI with a follow target:

[BepInPlugin("metaphaze.OdinHorseFollowFix", "OdinHorseFollowFix", "1.0.0")]
[BepInDependency("Raelaziel.OdinHorse")]
public class Plugin : BaseUnityPlugin
{
    private void Awake()
    {
        var target = AccessTools.Method("OdinHorse.OdinHorse+Tamed_Follow_patch:Prefix");
        if (target == null) return;
        new Harmony("metaphaze.OdinHorseFollowFix").Patch(target,
            prefix: new HarmonyMethod(AccessTools.Method(typeof(Plugin), nameof(Guard))));
    }

    // __2 = OdinHorse's "ref BaseAI __instance" (its prefix is static, so bind by position)
    private static bool Guard(ref BaseAI __2, ref bool __result)
    {
        var monster = __2 as MonsterAI;
        if (monster != null && monster.GetFollowTarget() != null) return true;
        __result = true;   // tell Harmony to run the original BaseAI.Follow
        return false;
    }
}

Note: speed multipliers stack with ValheimPlus
The config description says "Taming time" and "Growing up time" also apply to the game's own tames (boar, wolf, lox, ...). ValheimPlus has its own [Tameable] tameTimeMultiplier and [Procreation] maturityDurationMultiplier, so with both turned on the speed-ups multiply. To avoid that, we set the ValheimPlus ones to 0 and let BetrTame handle them. A short README note about this could help other ValheimPlus users.

Thanks again for the mod!

P.S. A possible fix on BetrTame's side: in Animals.Think, move AnimalAI followers with MoveTo() yourself instead of calling BaseAI.Follow (or wrap that call in try/catch), so other mods' Follow patches can't break it.

0
Dollar_Sprouts Newcomer #2

Deutsche Fassung (gleicher Inhalt wie oben, Code und Log unverändert)

Hallo und danke für BetrTame! Bei uns läuft es gut: 71 Kreaturen werden eingerichtet, und das Zähmen von Greydwarfs und Hirschen funktioniert. Wir sind auf ein Kompatibilitätsproblem gestoßen und haben einen Hinweis.

Setup

  • Dedizierter Linux-Server, Valheim 1.0.20 (Netzwerkversion 41), BepInExPack 5.4.2351
  • Mods auf Server und Clients: BetrTame 0.1.4, Jotunn 2.30.2, ValheimPlus (Grantapher-Fork) 0.10.2.0, OdinHorse 1.9.1, shrooms 1.5.0
  • Clients: ein nativer Linux-Client, ein Windows-10-Client
  • Geänderte BetrTame-Einstellungen: Taming time = 0.25, Growing up time = 0.25, Wild stars Enabled = false, Knocked out Enabled = false. Alles andere ist Standard, auch Command every tame = true.

Bug: Spieler können springen, aber nicht laufen, während ein gezähmter Hirsch folgt
Nachdem wir einen Hirsch gezähmt und auf „Folgen“ gestellt hatten, konnten beide Spieler noch springen, aber nicht mehr laufen. Das BepInEx-Log des Clients zeigte etwa 50 Fehler pro Sekunde (insgesamt über 4.700), immer dieselbe NullReferenceException (siehe Log oben).

Ursache: OdinHorse hängt einen Prefix an BaseAI.Follow, der für jede gezähmte Kreatur (__instance as MonsterAI).GetFollowTarget() aufruft. BetrTames Animals.Think ruft BaseAI.Follow für AnimalAI-Tiere wie Hirsche auf, deshalb ergibt der Cast null und der Prefix wirft eine Exception. Das passiert innerhalb von MonoUpdaters.FixedUpdate und bricht den Rest dieses Physik-Updates ab, deshalb funktioniert die Spielerbewegung nicht mehr.

Genau genommen ist das ein Bug in OdinHorse. Aber nur BetrTame ruft Follow für eine AnimalAI auf, also werden andere BetrTame-Nutzer mit OdinHorse auch darauf stoßen. Ein Hinweis in der README oder eine Absicherung auf deiner Seite würde ihnen Verwirrung ersparen.

Unser Workaround: ein kleines Plugin, das nach OdinHorse lädt und dessen Prefix überspringt, außer die KI ist eine MonsterAI mit Folgeziel (Code siehe oben).

Hinweis: Die Geschwindigkeits-Multiplikatoren wirken zusammen mit ValheimPlus doppelt
Laut Config-Beschreibung gelten „Taming time“ und „Growing up time“ auch für die normalen Zähmungen des Spiels (Eber, Wolf, Lox, ...). ValheimPlus hat eigene Werte ([Tameable] tameTimeMultiplier und [Procreation] maturityDurationMultiplier). Wenn beide aktiv sind, multiplizieren sich die Beschleunigungen. Deshalb haben wir die ValheimPlus-Werte auf 0 gesetzt und lassen BetrTame das übernehmen. Ein kurzer README-Hinweis könnte anderen ValheimPlus-Nutzern helfen.

P.S. Eine mögliche Lösung auf BetrTames Seite: in Animals.Think AnimalAI-Begleiter selbst mit MoveTo() bewegen, statt BaseAI.Follow aufzurufen (oder den Aufruf in try/catch packen), damit Follow-Patches anderer Mods das nicht kaputt machen können.

Danke nochmal für die Mod!

0
Dezzy😈 DEV #3

Hey, thanks a lot for the detailed report! 🙂

Good news: I’ve already fixed the deer and OdinHorse problem. You can read about it here in this thread. BetrTames Actually but I didn't see a selection for it. The fix is in the next update, so deer will follow you normally again with OdinHorse installed, and you’ll be able to walk. After that you can remove your little plugin.

And yes, you’re right about ValheimPlus: if both change the taming and growing time, it gets twice as fast. The way you did it is exactly right, just set it in one place.

Thanks again, and have fun with your tames!

KindRegards(DezzyCode);

Install a mod from a zip →

0

This topic is locked. New replies are not possible.