# Gate 18: the castle grounds' RABBITS, and the Lakitu with the camera.
#
# ov085 is the first overlay the port mounts that is neither the engine
# overlay (ov002) nor the level's own (ov009). It is an ACTOR overlay: six
# classes that several levels pull in, of which the castle grounds names two.
#
#   RABBIT      (187) x12   the twelve glowing rabbits, an AI actor that
#                           flees the nearest player and is caught by touch
#   LAKITU_BRO  (235) x1    the cameraman, who reads the real Camera's own
#                           state to place himself
#
# THE CONFIG'S NAMES ARE NOT SHIFTED HERE, and that is a finding rather than
# an assumption: ov009 taught the port to check. Every one of ov085's six
# factories installs a vtable whose slot 0 is its OWN class's InitResources
# and whose slot 16 is its OWN D1 --
#
#   daKinopio_c_classInit          -> _ZTV11daKinopio_c      slot0 Toad::InitResources
#   daPeach_c_classInit -> _ZTV9daPeach_c         slot0 PrincessPeach::...
#   daMip_c_classInit        -> _ZTV7daMip_c           slot0 Rabbit::InitResources
#   daObj_Mip_Key_c_classInit     -> _ZTV15daObj_Mip_Key_c  slot0 RabbitKey::...
#   daC_Jugem_c_classInit     -> _ZTV11daC_Jugem_c      slot0 LakituBro::...
#   daObjKanban_c_classInit      -> _ZTV13daObjKanban_c    slot0 WallSign::...
#
# -- so the block before each factory really is that factory's class, and the
# ROM's own RTTI names agree (daMip_c is the rabbit, daC_Jugem_c the Lakitu).

# ---- RABBIT (actor 187, ov085), x12 ---------------------------------------
# InitResources loads the model, threads a MovingCylinderClsn and a
# WithMeshClsn, picks the rabbit's path out of the level's own path table and
# seeds its RNG from the star count. Behavior is the chase: it takes the
# closest player, runs the flee/idle/caught state machine and moves through
# the two colliders.
# QUARANTINED at the main->port sync (lane SYNC5, the wave-7 fold merge): MSVC
# refuses main's shape for this TU (C2624 and C3640, an extern declaration of
# a function-local class type: forbidden outright by C++ ([basic.link]),
# measured unreachable by every MSVC conformance switch (/permissive included,
# probed 2026-09-13)). It is a decomp-side item, not a port one: see
# runs/link100/out/SYNC5/decomp_side.md. The row returns when main lands the
# fix.
#src/actors/daMip_c.cpp
# slot 18: the rabbit is the first class on this level to override
# Actor::OnYoshiTryEat rather than inherit it

# ---- LAKITU_BRO (actor 235, ov085), x1 ------------------------------------
# The cameraman on the bridge. His Behavior reads the live Camera -- the one
# gate 13 hosted -- and places himself relative to it, which is why he can be
# tried at all rather than deferred with the rest of the cutscene actors.
src/d_a_c_jugem.c
# _ZN9LakituBro13InitResourcesEv: HOST COPY at unmatched/TexSeq_Caller_LakituBro.cpp
# (wired in CMakeLists). Its TextureSequence::Prepare call passes two arguments; the
# host wrapper reshapes them into a 3-param thiscall and derefs an unwritten third
# stack slot, so the host copy passes the real third argument. See that file's header.
# _ZN9LakituBro8BehaviorEv is NOT here. It dispatches an mwcc
# pointer-to-member out of an eleven-entry state table, and MSVC forms a PMF
# over an incomplete class as the four-word general representation -- the
# gate-16 case for the third time. Host copy plus the state seat in
# port/unmatched/LakituBro_Behavior.cpp.
src/_ZN9LakituBro16CleanupResourcesEv.cpp
src/_ZN9LakituBro16OnPendingDestroyEv.cpp

# ---- the overlay's own static initialisers --------------------------------
# Six sinits. Every SharedFilePtr the two classes load through is constructed
# here, and the port runs them where the DS runs them: after the mount, before
# anything spawns.
src/__sinit_ov085_0212f2a8.c
src/__sinit_ov085_0212f3a0.c
src/__sinit_ov085_0212f5ec.c
src/__sinit_ov085_0212f9bc.c
src/__sinit_ov085_0212fa40.c
src/__sinit_ov085_0212fdb0.c

# ---- RABBIT: the destructor pair -------------------------------------------
# Both are hosted rather than trapped, and the reason is the mirror of gate
# 17's: each spells the SAME table by a different name -- D1 by the config's
# _ZTV6Rabbit, D0 by the ROM's own _ZTV7daMip_c -- so one host array satisfies
# both with the right bytes. hal/actor_classes.cpp carries the alias.

# ---- RABBIT: the eight states and the ring they close over -----------------
# __sinit_ov085_0212f5ec builds eight State objects out of sixteen
# {function, delta} statics, and Rabbit::Behavior dispatches whichever one is
# at +0x364 every frame. Fifteen of the sixteen are here.
#
# THE SIXTEENTH IS NOT DECOMPILED. ov085 0x0212b8dc, 0x338 bytes, is the Main
# half of state 0x021306cc -- the state Rabbit::InitResources itself enters on
# its last line -- and src/ has no C for it at all. It is seated by name in
# hal/actor_overlays.cpp, and on the castle grounds with a fresh save it is
# never reached: rabbit id 7 (MIPS) is the only one whose InitResources
# survives the save gate, and his own Behavior returns on its first line while
# data_0209caa0 word 2 bit 17 is clear. Measured both ways -- 3000 frames
# fault-free as the level boots, and the named trap firing on frame one with
# the two save bits forced on.
# r0-passthrough: _ZN7daMip_c13StateIdleMainEv (the RABBIT's state Main) calls
# Actor::ClosestPlayer() with no argument, relying on `this` riding ARM r0. Host
# copy port/unmatched/Ov085_Rabbit_b8dc.cpp passes `c`; the byte-locked src is
# unchanged. (the actor-187 RABBIT null-this +0x5c crash)
# src/actors/daMip_c.cpp

# ---- RABBIT_KEY (actor 229, ov085): the caught rabbit's GRANT actor --------
# daObj_Mip_Key_c, vtable _ZTV9RabbitKey / _ZTV15daObj_Mip_Key_c at 0x021301d8.
# When the caught-dialog rabbit state (_ZN7daMip_c15StateCaughtMainEv, above) ends the talk
# it calls Actor::Spawn(0xe5, ...) to make one of these at the rabbit's spot. THIS
# is the actor that grants progress: its PMF state machine (dispatched by
# RabbitKey::Behavior out of this+0x188, the same four-word MSVC PMF the rabbit
# carries) writes the save "caught" bit (func_02013868 -> data_0209caa0[3]), plays
# the caught cutscene (Player::SetNoControlState, gate 10), and on the eighth catch
# opens StartMinigameMenu. Absent this class the id-229 spawn was declined by the
# prespawn gate and the whole grant was skipped silently -- no key, and the never
# set save bit re-entered and stuck the caught dialog on a re-talk. Registered in
# hal/actor_classes.inc (id 229), vtable fill hal/actor_classes.cpp, three faces in
# hal/method_faces.cpp. Every callee below is a matched TU; no host copy needed.
src/d_a_obj_mip_key.c
src/_ZN9RabbitKey13InitResourcesEv.cpp
src/_ZN9RabbitKey8BehaviorEv.cpp
# _ZN9RabbitKey6RenderEv is NOT here: the third ov085 render host copy
# (port/unmatched/Ov085_Renders.cpp). Its shadow-struct Model slot-5 dispatch
# is a cdecl call into the __fastcall mv_render -- garbage `this` in ECX,
# measured as a frame-1 DEP fault on the spawn-assisted key.
src/_ZN9RabbitKey16CleanupResourcesEv.cpp
src/_ZN9RabbitKey16OnPendingDestroyEv.cpp
src/_ZN9RabbitKeyD1Ev.cpp
# RETIRED at SLICE1: body now in src/_ZN9RabbitKeyD1Ev.cpp. MSVC folds the ROM destructor variants into one symbol, so only one of a class two per-function destructor TUs can be compiled.
#src/_ZN9RabbitKeyD0Ev.cpp
# the state machine: d268 is the PMF dispatcher, d038 the caught entry (save bit +
# cutscene), cd80 the main (DisplaySaving/StartMinigameMenu/EndTalk), cd0c the
# talk-teardown, d108 the approach-then-caught, d24c a small setter, d2b8 the
# shadow/matrix helper, e480 the Kill.
src/func_ov085_0212cd0c.cpp
src/func_ov085_0212cd80.c
src/func_ov085_0212d038.c
src/func_ov085_0212d108.c
src/func_ov085_0212d24c.c
# func_ov085_0212d268 is NOT here: the seat-and-enter's real MSVC
# pointer-to-member call is the gate-16 case (a PMF over an incomplete class is
# the four-word general representation, reading sixteen bytes from the ROM's
# eight-byte pair and dispatching thiscall at cdecl hosts). Host copy with the
# dispatch hand-rolled: port/unmatched/RabbitKey_StateSeat.cpp (CMakeLists).
src/func_ov085_0212d2b8.cpp
src/func_ov085_0212e480.c
# the save/menu ring the grant reaches: the caught-bit writer and its companion,
# the minigame-menu entry, and a save-side counter. func_02012790 (the sound this
# path also calls) is already compiled in slice_gate10.
src/func_02013868.c
src/func_0201361c.c
src/StartMinigameMenu.c
src/func_02013944.c

# ---- LAKITU_BRO: the destructor pair and the eleven states -----------------
# Same D1/D0 shape (config _ZTV9LakituBro, RTTI _ZTV11daC_Jugem_c), and a
# state machine twice the rabbit's -- twenty-two bodies, all of them matched.
# His states are why he is here at all: they call Camera::SetPos and
# Camera::SetLookAt, so the cameraman drives the real Camera gate 13 hosted.
src/_ZN9LakituBroD1Ev.cpp
# RETIRED at SLICE1: body now in src/_ZN9LakituBroD1Ev.cpp. MSVC folds the ROM destructor variants into one symbol, so only one of a class two per-function destructor TUs can be compiled.
#src/_ZN9LakituBroD0Ev.cpp
# func_ov085_0212d5dc, LakituBro's LAST OPENING STATE, is back (run linkfull,
# lane RS4PORT). It used to call func_ov002_020c3e8c() with the player riding
# ARM r0 from ClosestPlayer's return, so unmatched/Ov085_LakituBro_IntroEnd.cpp
# hosted it. main #3106 passes that player; this per-function file carries the
# hunk from main's src/game/actors/d_a_c_jugem.cpp (the SYNC8C route (a)
# back-port), byte-identical under mwccarm 2004/b56.
src/func_ov085_0212d5dc.cpp
src/func_ov085_0212d724.c
src/func_ov085_0212d73c.c
src/func_ov085_0212d8ec.c
# LakituBro r0-passthrough set: func_ov085_0212d9b8/dd10/e310/e4a4 each call
# Actor::ClosestPlayer() with no argument (this rode ARM r0). HOST COPIES pass the
# state body's own receiver at port/unmatched/Ov085_LakituBro_ClosestPlayer.cpp.
# e4a4 is the caught/grab state caught taking a leaked receiver on a level-1 run.
# RETIRED by run link100 wave 15 lane SEAT15B (LINK15 BATCH 1): all four matched
# sources now PASS the ClosestPlayer receiver, so the host copies had nothing left
# to work around and Ov085_LakituBro_ClosestPlayer.cpp is deleted.
src/func_ov085_0212d9b8.c
src/func_ov085_0212db04.cpp
src/func_ov085_0212dbdc.c
src/func_ov085_0212dcfc.c
src/func_ov085_0212dd10.cpp
src/func_ov085_0212ddc4.cpp
src/func_ov085_0212de5c.cpp
src/func_ov085_0212df84.cpp
src/func_ov085_0212e078.cpp
src/func_ov085_0212e180.c
src/func_ov085_0212e19c.c
src/func_ov085_0212e2ec.c
src/func_ov085_0212e310.cpp
src/func_ov085_0212e4a4.c
src/func_ov085_0212e59c.c
src/func_ov085_0212e5ac.c
src/func_ov085_0212e720.c
src/func_ov085_0212e728.cpp
src/func_ov085_0212e778.cpp
src/func_ov085_0212e858.c

# ---- the engine ring the two classes close over ----------------------------
# The rabbit's catch path reaches Message and the save block (PrepareTalk
# ducks the music and sets a flag; NumGlowingRabbitsFound counts save bits),
# its carry path reaches Actor::UpdateCarry, and the Lakitu's states reach the
# Camera's two setters. func_0203c178 is an arm9 veneer whose `.word` carries
# the THUMB bit -- see the alias in hal/method_faces.cpp.
src/Vec3_ApproachHorz.c
src/_ZN8dActor_c11UpdateCarryER6PlayerRK7Vector3.cpp
# _ZN8dActor_c18HorzAngleToCPlayerEv: HOST COPY at unmatched/Actor_ClosestPlayerWrappers.cpp
# (wired in CMakeLists). The matched C calls Actor::ClosestPlayer() with no argument
# and relies on `this` being live in ARM r0; cdecl drops it, so ClosestPlayer measures
# from garbage+0x5c. That is the RABBIT fault in crash 9e164e92 (read at 0x0000005c).
src/_ZN6Camera6SetPosERK7Vector3.cpp
src/_ZN6Camera9SetLookAtERK7Vector3.cpp
src/actors/Player.cpp
src/_ZN7Message11PrepareTalkEv.cpp
src/_ZN7Message13DisplaySavingEt.cpp
src/_ZN7Message7EndTalkEv.cpp
src/_ZN8SaveData22NumGlowingRabbitsFoundEv.cpp
src/func_02013890.c
src/func_02016acc.c
src/func_0203c178.c
src/func_ov002_020d228c.cpp
