You are viewing a potentially older version of this package. View all versions.
LJS-AiFree-1.1.0 icon

AiFree

Monsters never abandon their targets when you move away, and Trolls no longer get blocked by walls for damage they should have landed.

Date uploaded a week ago
Version 1.1.0
Download link LJS-AiFree-1.1.0.zip
Downloads 5
Dependency string LJS-AiFree-1.1.0

This mod requires the following mods to function

denikson-BepInExPack_Valheim-5.4.2202 icon
denikson-BepInExPack_Valheim

BepInEx pack for Valheim. Preconfigured and includes unstripped Unity DLLs.

Preferred version: 5.4.2202

README

AiFree

Monsters don't stop just because you left.

In vanilla Valheim, monster AI freezes the moment you move too far away — enemy factions stop fighting each other, tamed wolves stand idle while your base burns, and the world around you silently pauses the instant you step through a portal.

AiFree removes that limitation.


What It Does

AI Timeout Removal

Vanilla Valheim monsters abandon their current target after 30 seconds of not sensing it.
AiFree prevents this: as long as the target is alive, the monster never gives up.

  • Two enemy factions mid-battle? They keep fighting.
  • A troll chasing a deer into the woods? It follows through.
  • Your tamed wolf cornered by greylings? It keeps defending.

When the target dies, the AI clears normally — no zombie behavior, no infinite aggro loops.

Zone Loading (Portal Coverage)

When you portal to another area, Valheim unloads the old zone — stopping all AI completely.
AiFree pins the zone of any actively-fighting monster in memory, keeping it simulated even when you're on the other side of the world.

  • Portal away mid-raid: the raid plays out for real.
  • Leave your tamed creatures at home: they'll actually fight back.
  • Come back to find the aftermath, not a freeze-frame.

Troll Wall-Block Fix

Vanilla melee hit detection stops at the first collider a swing connects with. If a wall sits between a Troll and a player within its swing range, the wall silently absorbs the hit and the player behind it takes nothing — even though the Troll's club should have crushed through.

AiFree adds a supplemental check: if a player in range was blocked from the Troll's attack by a wall, the Troll's own weapon damage is applied directly to that player. The original wall-damage logic is untouched — this only fills in the case vanilla misses.

  • Fixed behavior, no config toggle.
  • Scoped to Troll only for now (easy to extend to other large monsters later).

Configuration

Located in BepInEx/config/captain.aifree.cfg

Key Default Description
SenseTimeout 0 Seconds before a monster gives up on a living target. 0 = never. Original game value: 30
KeepZonesLoaded true Keep combat zones loaded when the player is far away. Covers portal travel in singleplayer.

Compatibility

  • BepInEx 5.4.x required
  • No known conflicts with other AI mods
  • Works in singleplayer and dedicated servers
  • Safe to add/remove mid-save

How It Works (Technical)

MonsterAI patchUpdateTarget() Prefix
Resets m_timeSinceSensedTargetCreature to 0 before the 30-second check fires, as long as the target character is alive. Uses AccessTools.Field for private field access.

ZNetScene patchRemoveObjects() Prefix
Before the engine destroys out-of-range GameObjects, adds any actively-fighting monster's ZDO (and its target's ZDO) to the currentNearObjects list. This earmarks them as "near" — preventing destruction and keeping the AI update loop running.

Attack patchOnAttackTrigger() Postfix (Troll only)
After the original melee hit detection runs, checks every player within the Troll's attack range and forward arc. If a piece/piece_nonsolid collider blocks the straight line between the attack origin and a player, that player was the one vanilla's raycast-and-break logic missed — the Troll's weapon damage (ItemDrop.ItemData.GetDamage(), never hardcoded) is applied to them directly via Character.Damage(). All Attack-type field/method access goes through AccessTools (this DLL build doesn't fully expose Attack members, even ones marked public in decompiled source — calling them directly throws MethodAccessException/FieldAccessException and can stall other monsters' updates).


Changelog

v1.1.0

  • Troll — Fixed melee attacks being silently absorbed by walls instead of reaching players standing behind them within range.

v1.0.0

  • Initial release: AI Timeout Removal, Zone Loading (Portal Coverage).

Source

Author: Captain
GitHub: https://github.com/KorCaptain