Crusader_Decomp/docs/usecode-event-slots-combine-cast-fast-area.md
Maddo 6d4972933f Refactor USECODE tooling documentation and enhance map-viewer decompiler
- Updated the USECODE Tool Improvement Plan to focus on the map-viewer decompiler/editor, emphasizing its role as the primary development target for USECODE editing and recompilation.
- Revised the tooling comparison document to include the newer map-viewer decompiler, clarifying its purpose and distinguishing it from the Python parser.
- Introduced a new ClearAvatarInStasisProcessEntry structure in the entity dispatch entry header, along with related process creation and execution logic in the ProcessKernel.
- Implemented the setItemShape method in LiveFixedMapItems to allow dynamic shape updates for items.
- Enhanced the teleporter process to handle avatar stasis and integrated it into the game main loop, ensuring proper process management and state handling.
- Added tests for the new functionality, including shape setting and teleporter process behavior, to ensure correctness and stability.
2026-10-06 00:01:20 +02:00

7.7 KiB

combine, cast, and fast area in Crusader usecode

This note checks whether the suspicious inherited event labels combine (slot 0x0C) and cast (slot 0x11) are actually used by shipped Crusader usecode, and tightens the current explanation for enterFastArea / leaveFastArea.

Summary

  • combine survives in the event vocabulary and has a live Remorse native dispatch path, but current shipped Crusader exports do not show any recovered slot_0C handler bodies.
  • cast is used in Crusader, but the live behaviors look like explicit scripted activation/dispatch lanes, not a classic RPG spell system.
  • fast area in Crusader is best read as an authored proximity/trigger region around an object or controller. Entering or leaving that region fires usecode callbacks.

Evidence Scope

Primary evidence for this note comes from the generated pseudocode exports in Crusader-Map-Viewer/map_renderer/site/data/usecode/*, the local crusader-disasm corpus, and existing Crusader notes on trigger/controller families.

combine (slot 0x0C)

In simple terms

Think of combine as an optional reaction hook, not a command to merge items: native code updates an item's Q (used here as its quantity) and may then ask the item's class script to handle slot 0x0C. The native stack routine does the actual merging. The inspected Remorse scripts have no handler for this slot, so there is no extra usecode reaction and the native quantity or stack operation continues.

What is actually present

  • The inherited Crusader/U8 event table still names event C as combine.
  • Current generated usecode exports show zero slot_0C_combine.txt files in these shipped corpora:
    • remorse
    • remorse-101
    • remorse-demo
    • regret
  • The exported pseudocode search found zero direct class-event .combine(...) callsites. This does not mean the native event is never attempted: Remorse usecode calls the separate Item::I_setQAndCombine intrinsic twice in MISS1EGG::cachein.

What the Remorse executable does

Ghidra identifies 10a0:0dd1 as the native handler for Remorse intrinsic 0x00CF, Item::I_setQAndCombine(Item *, int16 q). The body writes q into the item's quality field, calls Item_Combine, and returns; the intrinsic catalog counts two calls in one Remorse event body. In MISS1EGG::cachein (class_id 0x090D, slot 0x04), both release and non-release branches create a BA_41_CLIP, set its quantity to 25 through this intrinsic, then continue moving the item into the avatar's inventory.

Item_Combine (10a0:2ad2) is only a callback wrapper. It invokes Usecode_ItemCallEvent with mask 0x1000 and UC_Combine (slot 0x0C), returning the created process id if the event is handled, otherwise 0. Its only direct native caller in the Remorse xref scan is Item_SetQAndCallCombineEvent (10a0:0dd1). That helper ignores the returned process id and returns void; it neither waits for the callback nor uses it to approve or reject the quantity change.

The actual item merge is performed by its caller. For example, Item_TryStackItems checks equal shape and quantity/reagent family (and equal frame for reagents), sums the quantities, then either updates one stack and destroys the other or caps one at 0x29A and leaves the remainder on the second. It calls the quality-and-event helper during those updates. Item_Create, NPC_UseOneShot, and NPC_CheckForEmptyAmmo also use the helper for initial or changing weapon/ammo quantities. So slot 0x0C is a post-quality-change notification hook in these paths, not the item-merging algorithm.

The usecode intrinsic 0x00CF is Remorse-specific: the Regret intrinsic catalog maps ordinal 0x00CF to Item::isOn, not Item::I_setQAndCombine. Do not transfer this intrinsic number across games.

  • The disasm corpus still exposes a separate item helper named Item::I_setQAndCombine(Item *, int16 q).
  • In the local MISS1EGG disassembly, that helper is called immediately after item creation to stamp item state before the created item is positioned and added to inventory.
  • That is evidence that Crusader still retained some item-side combine-related helper semantics in native/intrinsic code, but it is not evidence of a shipped usecode slot 0x0C event body.

Best current read

combine is a confirmed native callback slot, but it has no recovered handler body in the inspected corpora. In Remorse, a real usecode intrinsic call sets an item's quantity and attempts the callback; because no class has a slot-0x0C body, there is no authored callback behavior in those archives. The intrinsic's quantity write and its caller's inventory/stack logic still proceed. A direct bytecode class/event call to slot 0x0C would use ordinary class/slot dispatch; it would not implicitly combine two items.

cast (slot 0x11)

No Remorse usage

  • In the No Remorse exported corpora, slot_11_cast.txt appears exactly once per build variant examined:
    • remorse: AVATAR/slot_11_cast.txt
    • remorse-101: AVATAR/slot_11_cast.txt
    • remorse-demo: AVATAR/slot_11_cast.txt
  • AVATAR::cachein directly spawns AVATAR.cast(0, arg_06).
  • The recovered AVATAR::cast body does not look like spellcasting. It:
    • excludes the process
    • waits 10 ticks
    • reads the avatar map id
    • selects a music track based on odd-numbered map ids (1, 3, 5, ... 29)

Regret usage

  • Regret exposes a wider slot_11_cast set: CARD_EW, CARD_NS, CONT_FL, CRUSADER, KEYPADEW, KEYPADNS, SECUREW, and SECURNS.
  • Representative Regret cast bodies such as CARD_NS::cast and KEYPADNS::cast behave like controller/trigger activators:
    • create a local sprite effect
    • play SFX
    • wait/suspend through helper slots
    • dispatch into TRIGGER.slot_20

Best current read

In Crusader, cast is a real event slot, but the live evidence does not support reading it as a general magic or spell lane. The stronger read is explicit scripted activation/dispatch callback, with behavior chosen per class:

  • No Remorse AVATAR.cast is a delayed map-music dispatch hook.
  • Regret CARD_* / KEYPAD* cast is a controller activation path that fans out into trigger logic.

enterFastArea / leaveFastArea

What the current evidence rules out

  • The Crusader evidence does not fit a fast movement zone or generic speed-boost interpretation.

What the current evidence supports

  • MONSTER::enterFastArea is the verified automatic activation lane for frame-0 0x04D0 NPC spawners.
  • TIMER::enterFastArea / leaveFastArea only arm a worker lane; the real delayed work happens later in TIMER.slot_20.
  • SPECIAL::enterFastArea / leaveFastArea use their entry/exit callbacks as phase/control inputs rather than as locomotion modifiers.
  • BRO_BOOT::enterFastArea and related controller families use the same event pair as proximity-trigger hooks for nearby scripted behavior.

Best current read

A fast area in Crusader is best described as an authored proximity/activation region associated with an item or controller class. When an actor crosses into or out of that region, the corresponding usecode slot fires so the object can arm, disarm, spawn, gate, or route scripted behavior.

That explanation fits the current environmental/controller families much better than movement speed area, and it matches the existing evidence for spawners, timers, specials, boots, cameras, and other trigger-like objects.

Practical naming guidance

  • Keep combine as a compatibility/historical hint only.
  • Keep cast as the slot label for compatibility, but document it as a scripted activation/dispatch hook in Crusader.
  • Prefer proximity/activation region when explaining enterFastArea / leaveFastArea.