Skip to content

Scene animations (.ANM)

Every scene archive holds one <scene>.ANM: all the animations its characters, cutscenes and animated objects use, the per-model animation variation tables and the animation meta keys (frame events such as footsteps). It is a CHUNKFILE tree. The engine keeps the whole file in memory for the scene (ZEngineDataBase::m_pPackedAnims) and reads most of it in place.

This page was read from src/engine/zstdlib/chunk.h, src/engine/animation/animation.cpp, src/engine/zstdlib/zanimfile.cpp and src/engine/geomsextend/zlnkobj.cpp, and checked against all 71 files. tools/port/scene/anm.py parses and rewrites every one byte for byte (ANM: 71/71 identical; also in roundtrip.py). It decodes the animation database and the variation buffers, and can drop animations from a scene (subset).

Loading

  1. AllocSequence (enginedatabase.cpp:1062) reads the file if its size is positive (GetAnimsData, line 489).
  2. After the textures are installed, FindChild(ANIMCHUNK_MANAGER_DATA) hands the chunk's data to Animation::Manager::LoadDataBlock (enginedatabase.cpp:1138, animation.cpp:212). That function points its members into the buffer and also looks up chunks 8 and 9 of the file root. A missing chunk 8 or 9 is a null dereference, so every file needs both. Chunk 8 is empty in 45 files and chunk 9 in all 71.
  3. Chunk 7 is read by ZAnimTemplatesNames::Init (zanimfile.cpp:142). Chunks 6 are read when a ZLNKOBJ gets its animation collection property (SetAnimCollectionProperty, LoadAnimVariationsBuffer, zlnkobj.cpp:420). No PS2 code reads chunk 5.

CHUNKFILE (chunk.h)

Every chunk is Name (uint32) and m_lTotalSize (uint32). The top two bits of the size word give the kind, the low 30 bits the chunk's size in bytes, header included. Words are read byte by byte (PackedWord), but on the disc every chunk is 4-byte aligned and a multiple of 4 long.

Kind (bits 31–30) After the size word Data
0: plain the data this + 8, size − 8 bytes
1: DataPieces DataOffset, NrDataPieces, PieceSizes[n] this + DataOffset
2: ChildChunks DataOffset, NrChunks, then the children this + DataOffset, after the last child
3: ChildChunksAndData DataOffset, NrChunks, NrDataPieces, PieceSizes[n], children this + DataOffset

FirstChild is at this + 16 for kind 2. Next is this + size. On the disc only kinds 0 and 2 occur, and in every kind-2 chunk the children end exactly at DataOffset (887 chunks). anm.py computes every size and offset and supports all four kinds.

The root chunk's name is the multi-character constant 'ANM' (0x00414e4d: the bytes 4d 4e 41 00), kind 2, its size the file size, with no data of its own. In all 71 files its children come in this order: the 5/6 pairs, then 7, 8, 9 and 4.

Name Kind Count Contents
5 2 one per collection (816 over 26 files; 0 in 45) data: "anmcol:animationdatabase#<collection>", NUL-padded to 4. One plain child whose name is a count n and whose data is n uint32. In 658 of 816 it lists the animation index of every pair of the collection's variation lists, in order. Not read on the PS2
6 0 one per collection, after its 5 the variation buffer (below)
4 0 1 the animation database (below)
7 0 1 template names (below); 0 templates in 45 files
8 0 1 meta keys
9 0 1 meta key strings

Chunk 4: the animation database

LoadDataBlock reads 13 int32 and then the arrays, back to back:

Field Meaning
m_Animcount number of Animation::Header records
m_Pos byte size of m_Data, the packed animation streams
m_BoneNames.m_Size, m_AnimNames.m_Size, m_PoseNames.m_Size byte sizes of the three name lists
m_BoneNames.m_Count, m_AnimNames.m_Count, m_PoseNames.m_Count entries in each list
m_SizeUncompressed, m_StateSize, m_HumanQuatSize, m_QuatSize, m_PoseSize totals. LoadDataBlock stores them and nothing reads them: the state cache they would size (Manager::m_Cache) is never created. m_StateSize and m_PoseSize are the byte sizes of the distinct state and pose streams in m_Data (all 71 PS2 and 68 PC files)
Header[m_Animcount] 0x40 bytes each
m_Data[m_Pos] the streams
bone, anim, pose names NUL-terminated names. Each list is padded with zero bytes to its m_Size (the bone list is a fixed 2,048 bytes in M00), so m_Count counts the real names

Two bytes of padding follow the lists in 9 files. LoadDataBlock assigns header i the i-th animation name. The file stores 0 in the m_Name pointer slot.

Animation::Header (animation.h:302), 0x40 bytes: m_States, m_OrgStartFrame, m_Frames, m_RealFPS (int16; 25, 26 or 50), m_Mask, m_Size, m_StateOffset, m_QuatOffset, m_GroundOffset, m_MetaDataOffset, m_PoseDataOffset, m_BlendFrames (float), m_CycleDist[3] (float), m_OldControl, m_SoundIndex, m_Name.

  • m_Mask bits (HEADERMASK_*): 0x2 has quaternions, 0x4 has state, 0x8 upper body, 0x10 uncompressed, 0x20 has pose, 0x40 ground animated, 0x04000000 discrete frames. Bit 0 is set in 1,251 headers and has no identified PS2 reader.
  • The four stream offsets are byte offsets into m_Data; −1 means absent (for example 10,127 of 12,955 headers have no pose data).
  • m_MetaDataOffset is a byte offset into chunk 8. There the first 16-byte ZMetaKey holds the key count in lFrame (GetMetaKeyDataLength, animation.cpp:2786), and that many ZMetaKey {lFrame, lValue, length, lStringOffset} follow. A key with lValue 0x400 would name a string at lStringOffset in chunk 9 (ZMetaKey::GetString), but chunk 9 is empty on the disc.
  • m_SoundIndex is a byte offset in the SND. Of the 3,672 nonzero entries, 3,671 name a Seq and one names a Set (M10_Roulette#Roulette_Player_Win_1).
  • Headers can share streams: 13 scenes list an animation called extra several times with identical headers. 211 of the headers' stream ranges overlap another header's.

The disc's databases hold 12,955 animations. 45 of the 71 are empty: the front-end, news, briefing and loading scenes. Animations are found by full name, for example anim:Cutscenes/M00/M00_SwingKing#M00_SwingKing_Phone (ZActor::GetAnim, the .PRP animation properties through GetREFByName), or by index (Animation::FromIndex; the variation lists; save games). Header::GetRef is index + 1.

Bone ids in the streams are indices into the bone name list (ZNameList::GetId; the first 60 are Animation::EBoneID, so 56 is Ground). Pose ids index the pose name list.

The streams in m_Data (StreamPacker)

State, quaternion, ground and pose streams all have one format, read by StreamPacker::DePackVector (any frame) and DePackBlock (one 8-frame block, for the state cache, which is never created) in src/engine/animation/streampacker.cpp. DePackState passes m_StateOffset with ZHumanState::m_StateId2Pos as the id-to-slot table, DePackQuats m_QuatOffset with the model's bone table (ZBoneQuat, 12 floats a bone), GetGround m_GroundOffset with only Ground mapped, DePackPose m_PoseDataOffset with the pose table. Animations with HEADERMASK_HasUncompressed use none of this (int32 bone count and ids at m_StateOffset, QuatPos {q[4], v[3]}[bones][frames] at m_QuatOffset); none occur on either disc.

A stream for an animation of n = m_Frames samples is cut into slots = (n + 7) / 8 blocks of 8 frames:

Bytes Field
1 size: number of channels
2 × size channel ids (uint16): state ids, bone ids or pose ids
size lps: per channel, low nibble type, high nibble bits
0 or 1 pad to an even offset
2 number of floats the stream writes (Σ 4·quats + floats over the channels); not read
2 headerssize, in 16-bit words
2 keyframesize, in bytes
2 × headerssize the header bit stream
2 × (slots + 1) offsets[]: where each block starts in the key data, in 16-bit words; offsets[slots] is its size
2 × offsets[slots] key data: per block, keyframesize bytes of key frame values, then the block's deltas

Bit streams are read LSB first from little-endian bytes (GETBITS: three bytes at bit >> 3, shifted by bit & 7). A channel's type selects (aInfo, the same table in both functions):

type value range (low, width) floats quaternion
0 angle (wraps around) −π, 2π 1 –
1 float −1, 2 1 –
2 float low and high are two int16 in the header stream 1 –
3 quaternion – 0 bits bits a component
4–8 bone: quaternion + position ±10, ±100, ±1,000, ±10,000, ±100,000 3 12 bits a component

For each block the decoder runs through the channels in order, and for each channel reads from three cursors: the header stream (restarted at its start for every block), the block's key frame (key1, at offsets[block]), the next block's key frame (key2, at offsets[block + 1], or key1 again in the last block) and the block's deltas (at offsets[block] + keyframesize):

  • type 2: two int16 (low, high) from the header stream.
  • a quaternion: 4 header bits: bit 0 "constant", bits 1–3 the axis code. Not constant: 3 bits of axis code from key1 and key2 and 3 bits per frame from the deltas (frames 1 to wrap − 1, where wrap is 8, or the frames left in the last block). Then three components, each: qbits + 1 header bits (bit 0 constant, the rest a base value v); not constant: 4 header bits band − 1, band bits from key1 and key2 (added to v), 4 delta bits local, then wrap − 1 signed local-bit deltas, each added to the previous frame. A sample is axis code = 2·axis + sign; the three stored components are value · 1.42 / 2^qbits − 0.71 in the other three slots in order, and the axis component is sign · sqrt(1 − Σ) (identity when Σ ≥ 1).
  • each float: the same scheme with bits + 1 header bits; the value is integer · width / (2^bits − 1) + low (afLookup). Type 0 is interpolated around the circle.

DePackVector takes frame ⌊f⌋ from key1 plus the deltas and frame ⌊f⌋ + 1 from the next delta (or key2 at the end of a block), and blends them (qpul for quaternions). For types 4–8 the floats land at slot + 9 and are copied to slot + 4 (ZBoneQuat::m_vPosition). Streams start at even offsets, and in every file the distinct streams tile m_Data exactly, with no gaps.

State streams (ZHumanState, 104 floats): ids 0–9 are the ten quaternions (EQuatIds, type 3, slot 4·id), ids 10–73 the 64 floats (slot id + 30; ZHumanState::m_Names: pelvis, feet and hand positions are type 2, every joint angle is type 0). On the PS2 quaternions 0, 7 and 9 have 14 bits and the rest 10 (SetCompressionRatio's precisions: 14 for pelvis and the two clavicles); type 0 channels have 11 bits; type 2 channels 6 to 14. Quaternion streams use types 4–6 (and 1 for pose weights), ground streams types 4–6 with the one id 56.

Chunk 6: animation variation buffers

The data is the collection name, NUL-padded to 4 bytes, then a ZAnimVariationBuffer (zanimfile.cpp):

  • int32 number of variation lists;
  • each list: SFlagOffsetPair {iFlags, iOffset} pairs up to and including one with iFlags 0. iOffset is an animation index (all 89,139 on the disc are in range). ZAnimVariation::GetAnimOffset picks the pair whose non-random flag bits match the actor's state, weighting the random bits (ANIMVAR_RANDOM50 1, RANDOM33 2, RANDOM10 4; ONEHANDEDWEAPON 8);
  • one uint32 slot (zero on the disc) — FindAnimListStart points m_pAnimList at the iOffset field of the pair after the last list;
  • int32 n and n int32: for each template id, the byte offset of its list from the start of the buffer, or −1. Every non-negative value on the disc is the start of a list.

Chunk 7: template names

int32 count, then count pairs {name offset, template id}, then the names. Names are sorted with strcmp for FindAnimVariationHandle's binary search, and the template id indexes the variation buffers' template list. Example: /AI/Deny_Access_01 → 101.

Keeping or subsetting animations

A new level will most likely reuse the game's character animations. The simplest route is to copy a whole _main scene's ANM: everything in it is relative to the file, and the only reference out of it is m_SoundIndex (into that scene's SND).

anm.subset(anm, keep) keeps the animations named or indexed in keep. It drops the other headers and names, renumbers the animation indices in every variation list, removes lists that name a dropped animation (their template entries become −1), and rewrites chunk 5 to match. m_Data and chunks 8 and 9 stay whole, so headers keep their stream and meta offsets. anm.py selftest keeps every second animation of a scene. It checks the kept headers and that every template entry whose list survives resolves to the same animations. On M00 that leaves 446 of 891 animations, 4,335 template entries intact and 4,596 at −1, and the file shrinks from 3,579,688 to 3,476,285 bytes. All 71 files pass.

Animations referenced by name from the .PRP or scripts must be kept. Index references from save games do not matter for a new level.

A minimal new scene

  • An ANM is optional: with size 0 no Animation::Manager is made, and actors cannot animate.
  • With an ANM, the root needs children 4, 8 and 9 (LoadDataBlock dereferences 8 and 9 unconditionally), and chunk 7 for templates. Chunks 5 and 6 are only needed by models whose .PRP names an animation collection.
  • Header m_SoundIndex values must be valid in the new scene's SND, or 0.

PC version

Measured over the 68 scene ANMs of the Steam release against their PS2 twins (tools/port/tests/pc_animations_test.cpp). The PC file has the PS2 layout, and the unchanged PS2 engine reads it.

  • Same container. The same chunk tree with the children in the same order. Chunks 5, 6, 7 and 8 are byte-identical in 63 files; chunk 9 is empty in all 68. Chunk 4 has the same 13 words, 0x40-byte headers, m_Data and name lists. The 2 bytes of padding after the name lists are in different files: 9 PS2 files (HITMANBLOODMONEY, M01, M08, M09, M11 and M12 main, the M01, M03 and M11 premissions) and 5 PC files (M00, M04, M05, M09 and M13 main).
  • Same animations, a few more. 12,955 PS2 animations all have a PC twin of the same name. The PC has 8 more: Hero_UB_WeaponHandling#UB_Reload_Airrifle and Hero_1Person#UB_1P_Hold_AirRifle, both in M06, M11 and M12 main, one in M08 and M10 main. They are inserted in the list, so later animation indices move by 1 or 2, and the variation lists and template ids move with them (chunk 7 gains /Reload/Airrifle and /FirstPerson/UB_1P_Hold_AirRifle). The files are consistent with themselves: resolved by name, all 347,440 (template, collection) variation lists equal the PS2 ones, and the meta keys of all 12,955 animations are identical (m_MetaDataOffset differs in 2,067 headers only because chunk 8 moved).
  • Headers. For all 12,955 pairs, m_States, m_OrgStartFrame, m_Frames, m_RealFPS, m_Mask, m_BlendFrames, m_CycleDist[3], m_OldControl and which streams are present are identical. m_Size differs in 11,343 (the state streams are larger). m_SoundIndex differs in all 3,672 non-zero values, because it is a byte offset into the scene's .SND, whose PC layout differs.
  • Bones. The bone name lists differ in 4 files: HITMANBLOODMONEY and M13 main have the same names in another order, M06 main adds 9 xtra_*mus_* bones and M10 main 7 (bone01... bone_lampattach_01). So 551 quaternion streams in M06 and M10 name other bone ids. Decoded with ids mapped by name, all 20,384 quaternion, ground and pose streams of paired animations give bit-identical floats.
  • State streams. These are the only encoding difference. They have the same channels, ids and types, but every PC state channel is quantised with 14 bits (696,468 of 696,468, counting each header's stream). The PS2 used 14 bits for quaternions 0, 7 and 9 and 10 for the others, 11 for every angle, 12 to 14 for the pelvis floats (ids 10–15), 14 for the hand positions and 6 to 13 for the foot positions (ids 16–18, 21–23), chosen per animation. 0 of 11,373 state streams are byte-identical. On M00 the state total is 3,872,274 bytes against 2,879,452; over the 68 files it is 46.7 MB against 34.7 MB (+35%), and the files are 57.5 MB against 45.4 MB. The PC executable carries the same decoder: the two 9-entry aInfo tables at file offsets 0x3fda78 and 0x3fdaf8 of the unpacked exe, afLookup at 0x381eb8, and the 1.42 and 0.71 quaternion constants.
  • Manager words. m_Pos, m_StateSize (still the sum of distinct state streams) and the name list sizes and counts follow from the above. m_SizeUncompressed and m_HumanQuatSize differ only in the 5 scenes with extra animations. m_QuatSize and m_PoseSize are identical.

Conversion

port/engine/system/_sdl/pcdata/pcanimations.{h,cpp}: PcConvertAnimations(pData, lSize, pRemap, pContext, &pOut, &lOut, &Report) returns a malloc'd copy of the member. Before copying it checks everything the engine dereferences. That covers the chunk tree, chunks 4, 8 and 9 (LoadDataBlock needs all three), the manager words against the chunk size, one name per header, the meta key ranges in chunk 8, the template names, and every variation list's animation index and template offset. It also walks every stream through every block, checking the channel types (< 9), the ids (state < 74, bones < 1023, ground = 56, poses < 127) and that each bit read stays inside the stream. No re-encoding is needed: the PS2 format represents the PC data exactly, and keeping it keeps the PC precision. Animation indices, names, bone ids and offsets are unchanged, so the PC .PRP names, variation lists and templates stay valid. Save games made on PS2 data do not carry over, because animation indices differ in 5 scenes. The optional pRemap callback rewrites each non-zero m_SoundIndex (PC SND offset to converted SND offset). It is needed only if the SND converter moves Seq records.

All 68 PC members are accepted, and so are their 68 PS2 twins. The output equals the input, and the whole set takes 69 ms, the worst file 5.6 ms (M00 main, 4.6 MB), with no memory beyond the copy. 31,000 damaged copies of three files were each accepted or rejected without a read past the member, which ends against an inaccessible page (--fuzz).

What the engine sees: PC against PS2

The test decodes every paired state stream of both files with the engine's own StreamPacker::DePackVector (linked from src/), called as DePackState calls it, at every whole and half frame: 11,373 streams, 1,363,511 frames. The differences are the PS2's coarser quantisation:

Channels max mean
quaternions 0, 7, 9 (14 bits on both) 0 0
other quaternions (10 bits on the PS2) 0.219° (component 0.0016) 0.047°
angles, type 0 (11 bits on the PS2) 0.0048 rad (0.27°) 0.00075 rad
pelvis floats 0–5, type 2 (12–14 bits on the PS2) 0.00061 0.00003–0.0001
foot positions, type 2 (6–13 bits on the PS2) 0.0713 0.0090
hand positions, type 2 (14 bits on both) 0 0

Measured in PS2 quantisation steps on hideout_main (whole frames), 10-bit quaternion components are within half a step. 96% of angle samples are within half a step and the largest is 1.55 steps. Type 2 floats are within 1.5 steps, and most bit depths within 0.6. So the PC values are the same animation data at a finer quantisation.

F="-target x86_64-windows-gnu -O2 -DNON_MATCHING -fsigned-char -fno-strict-aliasing -fno-delete-null-pointer-checks
   -ffp-contract=off -std=gnu++98 -fno-exceptions -fno-rtti -nostdinc++ -Isrc -Iport"
zig c++ $F tools/port/tests/pc_animations_test.cpp port/engine/system/_sdl/pcdata/pcanimations.cpp \
    port/engine/system/_sdl/pcdata/pcanimmerge.cpp \
    src/engine/animation/streampacker.cpp src/engine/zstdlib/zmath.cpp -o build/pc-only/anm/pc_animations_test.exe
build/pc-only/anm/pc_animations_test.exe build/pc-only/corpus-pc build/pc-only/corpus-ps2 [-v]
build/pc-only/anm/pc_animations_test.exe --fuzz build/pc-only/corpus-pc/M00_M00_MAIN/Scenes/M00/M00_main.ANM 3000

Who plays the eight extra animations

No code names them. They are the air rifle's (Rifle_Airrifle_Tranquilizer_01, weapon type 4, WT_RIFLE), and the weapon's template in the scene .PRP names them through three ZRTString properties of ZHM3ItemTemplateWeapon: m_pAnimNameActorReload (0x17c) is /Reload/Airrifle, m_pAnimName1stPersonAim (0x184) /FirstPerson/UB_1P_Hold_AirRifle and m_pAnimName1stPersonRecoil (0x188) /FirstPerson/UB_1P_Recoil_AirRifle. The PS2 and PC .PRP of every main scene from M01 to M13 and the hideout have these strings (M00's has no air rifle); neither executable has them: both have the same sixteen /Reload/ names, seven for the weapon types and nine for the custom weapons' upgrades. Two functions, the same on both, look the names up in chunk 7:

  • Reload. ZHM3WeaponsControl::UpdateWeaponInfo (PS2 0x368ef0, PC 0x62ea70) takes GetAnimNameActorReload and asks ZHitman3::GetAnimHeaderFromHandleName for it. When that finds nothing it falls back by weapon type; for WT_RIFLE that is m_pReloadRifle, /Reload/Rifle_AK, which no mission scene has on either platform (0 of 68 PC and 71 PS2 files). So the PS2 air rifle reloads with no animation: ZHitmanActionReloadItem gets a null header and the dart is back in the magazine on the next frame.
  • First person. ZHM3ItemTemplateWeapon::ClassInit2 (0x3899ac) resolves the aim and recoil names to m_1stPersonAimId and m_1stPersonRecoilId with ZAnimTemplatesNames::FindAnimVariationHandle. ZHitman3::GetAimAnim (0x326810) uses the aim handle when it is valid and otherwise returns ZLNKWHANDS::GetAimAnim, which is 0 for a rifle. With no aim animation 47's arms stay down and the rifle is not in the first-person picture.

The only air rifle lying in a mission is in A New Life (M05, Items!Weapons!Airgun_tranquilizer), whose scene has all three on both platforms; the test hook below finds none in M00, M06 or M11. A player who leaves A New Life with it finds it in the hideout and can take it into the later missions, and five of those lack animations on the disc. Which scenes lack them (template ids are the PS2's; "—" is missing):

Scene /Reload/Airrifle /FirstPerson/UB_1P_Hold_AirRifle /FirstPerson/UB_1P_Recoil_AirRifle
M06 main — — 469
M08 main 434 — 511
M10 main — 472 510
M11 main — — 536
M12 main — — 492
M00 to M05, M09, M13 main, the hideout (M05: 426, 467, 506) present present present

OPENBLOOD_PCANIM_TEST=airrifle (debug-ui.md) shows it in M06 from the disc: the template names are read from the .PRP, both lookups fail (id -1), the reload animation is none, the magazine is full again one frame after the reload starts, and GetAimAnim in first person is none (aim and recoil). From the PC installation (the PC's own M06, template ids 393 and 434) and from the disc with pc_animations, the reload is anim:Hero/Hero_UB_WeaponHandling#UB_Reload_Airrifle (101 frames at 25 fps; the reload action runs from frame 301 to 405 of the test, and the dart returns when it ends), and the first-person aim is anim:Hero/Hero_1Person#UB_1P_Hold_AirRifle with the recoil #UB_1P_Recoil_AirR (the name is cut short in the data of both platforms). Since the PS2 code asks for the animations by name, adding them to the data is all it takes; no game function is replaced.

The PC animations in the PS2 game

pc_animations (Enhancements) gives a disc run the PC precision and the air rifle's animations without moving anything the rest of the game refers to by number: animation indices (save games, Animation::FromIndex, the variation lists), template ids (ZAnimVariationHandle), bone and pose ids and the .SND offsets in m_SoundIndex. PcMergeAnimations (port/engine/system/_sdl/pcdata/pcanimmerge.cpp) builds the member from both scenes' files:

  1. Both members pass PcCheckAnimations. Animations are paired by name, the k-th of a name with the k-th (a stable sort of each name list; the 13 scenes' repeated extra pair in order).
  2. A paired PS2 animation whose PC twin has the same m_Frames, m_Mask and state channels (ids and types, in order) takes the PC state stream; m_Size, which nothing reads, becomes the PC's. Everything else in its header stays: the quaternion, ground and pose streams (they decode to the PC's floats bit for bit), m_MetaDataOffset and m_SoundIndex. 11,373 of 11,373 state streams are replaced; the other 1,582 paired animations have no state stream.
  3. A PC animation without a PS2 twin is appended after the PS2 ones, with its name after the PS2 names. Its quaternion, ground and pose channel ids are mapped to the PS2 bone and pose lists by name (an id past the PC bone list is an Animation::EBoneID, kept); one that cannot be mapped leaves the animation out. Its meta keys are appended to chunk 8. A non-zero m_SoundIndex (a PC .SND offset) becomes the PS2 offset that the paired animations with that PC offset have, or 0 when they disagree or there is none. The eight air-rifle animations have no sound and no meta keys (their keys are empty lists), and their two bones have the same ids in both lists.
  4. m_Data is rebuilt from the streams still named: the PS2's (state streams of animations that keep theirs, all quaternion, ground and pose streams), then the PC state streams and the appended animations' streams, each copied whole (StreamLength: header, tables, key data) at an even offset and deduplicated by offset, since headers share streams. m_StateSize is recounted; m_SizeUncompressed and m_HumanQuatSize, which nothing reads, are the PC's when every PC animation is in.
  5. A PC template the PS2 lacks gets the next free id after the PS2's highest (M06: /FirstPerson/UB_1P_Hold_AirRifle 564 and /Reload/Airrifle 565, where the PC has 434 and 393). In every chunk 6 buffer whose collection the PC also has, the PC's list for that template is appended after the PS2 lists, with its animation indices mapped to the merged numbering, and the template offsets are extended to the new id. Chunk 7 gets the new entries, sorted by strcmp for FindAnimVariationHandle; the PS2 names keep their offsets and the new names follow them.
  6. The root keeps the PS2 children in their order, with chunks 4, 6 (where changed), 7 and 8 rebuilt as plain chunks padded to 4 bytes. Chunks 5 and 9 and the bone and pose lists are the PS2's. The result must pass PcCheckAnimations, or the disc's member is used.

The disc run reaches it through PcDataMember (pcdata/pcdata.cpp), which in disc mode converts only the .ANM and only with the setting on. It reads the PS2 member from the mounted archive and the PC member from the PC scene zip (PcSceneZipPath, PcSceneZipMember); a scene with no PC twin (the boot menu, the attract mode) or a member that does not merge keeps the disc's. ZEngineDataBase::GetAnimsSize and GetAnimsData then size and load the merged bytes, which the cache drops once loaded.

Measured with pc_animations_test --merge over the 68 scene pairs (the build line above):

  • 68 merged, none failed, 230 to 280 ms in all and 19 to 23 ms for the slowest scene. The members total 57,466,372 bytes against the PS2's 45,411,240 and the PC's 57,454,084. In the game it takes 23 to 46 ms per scene (log line pc animations:).
  • 11,373 state streams from the PC, 8 animations appended (2 in M06, M11 and M12, 1 in M08 and M10), 0 left out, 8 templates and 119 variation lists added (M06: 40), 0 sounds to map.
  • Strict checks, 0 errors: every PS2 index keeps its name, header fields (bar the stream offsets and a replaced state's m_Size), meta keys and m_SoundIndex; its quaternion, ground and pose streams are the PS2 bytes and its state stream the PC twin's bytes; every PS2 template keeps its id and, in every buffer, a list with the same flags and animation names; every PC template is present and its lists name the PC's animations; chunk 7 is sorted.
  • Setting off against on, decoded by the engine's StreamPacker::DePackVector at every whole and half frame (1,363,511 frames of 11,373 state streams): quaternions differ by at most 0.2185° (mean 0.0466°; 0 for quaternions 0, 7 and 9), angles by 0.0048 rad (0.27°, mean 0.00075), type 2 floats by 0.0713 (mean 0.0027); 20,384 quaternion, ground and pose streams decode identically. Against the PC member, the 11,381 state streams of the merged file are byte-identical and the 20,392 others decode identically.
build/pc-only/anm/pc_animations_test.exe --merge build/pc-only/corpus-pc build/pc-only/corpus-ps2 [-v]

Unknown

  • subset still cannot compact m_Data. The stream format is known now (above), and so are the stream extents (header, tables and key data), but a header's streams are not one contiguous range (1,235 headers have a stream beyond min(offsets) + m_Size), and headers share streams.
  • What m_SizeUncompressed, m_HumanQuatSize and m_QuatSize count. Nothing reads them.
  • Chunk 5's 158 lists that do not equal the flattened pairs, and the crowd animation headers (Manager::m_pCrowdHeaders), which are not set from this file.