fix(fenrir): enter the Ulv's sleep by its real state path

scripts/dump_controller.py reads an AnimatorController's states and
transitions offline from Valheim's bundles with UnityPy. On
ulv_animator it shows the entry state "check sleeping" picks Sleep only
at start-up and Movement has no way back into it, so the bool alone
could never work. The cross-fade now targets "Base Layer.Sleep".
This commit is contained in:
kanym 2026-10-17 19:22:24 +02:00
commit e83c3c5d74
2 changed files with 111 additions and 3 deletions

105
scripts/dump_controller.py Normal file
View file

@ -0,0 +1,105 @@
r"""Dump a Unity AnimatorController's parameters, states and transitions from Valheim's own files.
Reads the game's asset files offline, so animator state and parameter names are read, not guessed.
Setup, once (UnityPy into a folder of your choice, not into the repo):
python -m pip install --target C:\path o\pylib UnityPy
Usage (Windows paths: a Git Bash "/c/..." path does not resolve for a Windows Python):
python -I scripts/dump_controller.py C:\path o\pylib "<Valheim> alheim_Data" ulv_animator wolf_animator
Pass valheim_Data to search everything (slow, a few minutes), or a single bundle file to read
only that one. Creature animators live in valheim_Data\StreamingAssets\SoftRef\Bundles; the
Fenrir forms' four (wolf, ulv, fenring, fenring_cultist) are all in bundle c4210710 as of 1.0.20.
A controller's name is the one dumpanim prints ("controller 'ulv_animator'").
"""
import os, sys, json
sys.path.insert(0, sys.argv[1])
import UnityPy # noqa: E402
data_dir = sys.argv[2]
wanted = set(sys.argv[3:])
candidates = [data_dir] if os.path.isfile(data_dir) else []
for root, _, files in ([] if os.path.isfile(data_dir) else os.walk(data_dir)):
for f in files:
p = os.path.join(root, f)
if f.endswith(('.resS', '.resource', '.manifest', '.json', '.dll', '.csv', '.txt', '.info', '.config')):
continue
if os.path.getsize(p) < 1024:
continue
candidates.append(p)
found = {}
for path in candidates:
try:
env = UnityPy.load(path)
except Exception:
continue
for obj in env.objects:
if obj.type.name != 'AnimatorController':
continue
try:
name = obj.peek_name()
except Exception:
name = None
if name is None:
try:
name = obj.read().m_Name
except Exception:
continue
if name not in wanted or name in found:
continue
tree = obj.read_typetree()
found[name] = (path, tree)
if len(found) == len(wanted):
break
for name, (path, tree) in found.items():
print(f'=== {name} ({os.path.basename(path)})')
tos = {int(k): v for k, v in tree.get('m_TOS', [])}
print('m_TOS (hash -> name):')
for h, v in sorted(tos.items(), key=lambda kv: kv[1]):
print(f' {h:>12} {v}')
ctrl = tree.get('m_Controller', {})
params = ctrl.get('m_Values', {}).get('data', {}).get('m_ValueArray', [])
print('parameters:')
for p in params:
print(f" {tos.get(p.get('m_ID'), p.get('m_ID'))} type={p.get('m_Type')}")
for sm_i, sm in enumerate(ctrl.get('m_StateMachineArray', [])):
sm = sm.get('data', sm)
states = sm.get('m_StateConstantArray', [])
print(f'state machine {sm_i}: {len(states)} states, default index {sm.get("m_DefaultState")}')
any_tr = sm.get('m_AnyStateTransitionConstantArray', [])
def describe(tr):
tr = tr.get('data', tr)
conds = []
for c in tr.get('m_ConditionConstantArray', []):
c = c.get('data', c)
conds.append(f"{tos.get(c.get('m_EventID'), c.get('m_EventID'))} mode={c.get('m_ConditionMode')} th={c.get('m_EventThreshold')}")
dest = tr.get('m_DestinationState')
return dest, conds
names = []
for st in states:
st = st.get('data', st)
names.append(tos.get(st.get('m_NameID'), st.get('m_NameID')))
for i, st in enumerate(states):
st = st.get('data', st)
print(f' [{i}] state "{names[i]}" fullPath="{tos.get(st.get("m_FullPathID"), st.get("m_FullPathID"))}" tag="{tos.get(st.get("m_TagID"), st.get("m_TagID"))}"')
for tr in st.get('m_TransitionConstantArray', []):
dest, conds = describe(tr)
dname = names[dest] if isinstance(dest, int) and 0 <= dest < len(names) else dest
print(f' -> {dname} when {conds}')
for tr in any_tr:
dest, conds = describe(tr)
dname = names[dest] if isinstance(dest, int) and 0 <= dest < len(names) else dest
print(f' AnyState -> {dname} when {conds}')
missing = wanted - set(found)
if missing:
print('not found:', ', '.join(sorted(missing)))