CPU opponents (com/ai, com/deck, com/param, com/stNN/comdataN.cad + executable)
Our own reading of PDUWP.exe and of the
files; the shared notes gave the first leads for
.epa / .cad / decks
(credited above) and are corrected here where
the code says otherwise.
converter/comdata.py dumps the nav
file and the parameter file through structs
(synthetic test
converter/tests/test_comdata.py);
the AI scripts disassemble with
ssbdump.py (“Menu script VM”: same
container, same interpreter, built-in group 4).
No script listing is kept in the repo. “C” is
the character object, “P” = C + 0x40 its combat
part, “I” = C + 0x14248 its input block, units
0.1 m, ticks 1/30 s, angles 15-bit unless
degrees are named.
The pieces
| Piece | What it is | Used by versus-vs-CPU |
|---|---|---|
com/ai/eneprog006.ssb |
the general fighter script (the largest: one
main, ~7000 instructions) |
yes: the only script name in the executable (0x1402f54c8) |
com/ai/eneprog000…005(.ssb, _nodef, _noNdef),
eneprog_freya |
story enemies and partners, named by the
mission data; the _nodef /
_noNdef variants drop defensive
branches |
no (story) |
com/ai/chkprog000,
rootchk, motchk |
developer check scripts: read the debug pad (0x40E1 / 0x40E2), hand out skills, teleport | no |
com/deck/* (405 files) |
100-byte arsenals (Esper-RE / wiki deck layout: index, 16-byte name, 30 skill ids, school count) named by the mission data; three 660-byte long forms (not read here) | no: the versus CPU gets its 30 skills from a deck record in memory (below) |
com/param/enemyparam.epa |
82 parameter records | yes: record 20 |
com/stNN/comdataN.cad |
navigation mesh and stored routes of a stage | yes |
com/single2.csv |
a table of single battles (role, deck or model, script, small integers; loader 0x140192530) for a developer battle menu | no |
com/stNN/camdata.cam |
spectator camera spots, not AI data (“Play camera”) | – |
enemyparam.epa
(1004 bytes)
u32 count (82), then 100 records
of 10 bytes (unused ones zero). Pointer kept at
0x1404c0188; record i is read at file offset 4 +
10·i.
| Offset | Type | Field | Conf. |
|---|---|---|---|
| 0 | s8 | start health of the CPU
player: the character setup (0x14024e790) passes
it to the combat part’s init in the place where
a human gets the mode’s health from
gsdata (correction
to the shared notes’ “character index”); 20 in
all 82 records |
M |
| 1..9 | s8[9] | copied, sign-extended, into AI script variables 30..38 when the controller is set up (0x14017b020 / 0x14017b100) | H |
What eneprog006 does with them
(read from its disassembly; M):
30 = who to fight (a selector for the target
choice: 0 in the versus record; values 0–6
occur), 31 = the decision interval in ticks (30
everywhere: the script reloads a countdown
variable from it, so it re-decides once a
second), 32..35 = four percentages, each
compared with a fresh random 0..99 before one
kind of action (32 gates the attack decision at
each interval; 33, 34 and 35 gate three reactive
branches), 36 = a percentage for an occasional
move to another area (3 / 6 / 9 / 12 / 15 over a
five-step series), 37 = a movement style switch
(0, 1 or 2), 38 = a kind passed to one of its
checks (0–3). The records come in series of five
whose percentages fall 88 / 77 / 66 / 55 / 44
while byte 7 rises: five strength
steps. eneprog000…005 read
none of them. Record 20 (the versus one) is the
strongest step of its series: all four
percentages 88, byte 7 = 3. There is no
reaction-delay or aim-error field: the
CPU’s “difficulty” is how often it acts; its aim
is the lock (below).
comdataN.cad:
the navigation file
Loader 0x140176420: directory
com/st%02d with stage id
mod 10, file comdata%d.cad
with the variant number (0x1404c51f0), so the
stage variants (st13, st23 …) share the base
stage’s directory. Pointer kept at 0x1404c0180.
st01 has only a 6252-byte compact file (the
shared notes describe it; not read here). Every
other file is 674,312 bytes of fixed-capacity
tables (struct NavFile in
comdata.py):
| Offset | Content |
|---|---|
| 0x00000 | u32 vertex count, then 1000 × vec3 |
| 0x02EE4 | u32 area count, then 128 × area (0x54 bytes) |
| 0x058E8 | u32 edge count, then 512 × edge (0x2C bytes) |
| 0x0B0EC | u32 count, then 30 × point A {vec3, s32 area, s32 id, f32 value} |
| 0x0B3C0 | u32 count, then 30 × point B {vec3, s32 area} |
| 0x0B5A4 | 5 route sets, each s32[128][128]: offset into the route pool for (from, to), −1 = none |
| 0x5B5A4 | u8[128] one byte per area (an area number; role not followed) |
| 0x5B624 | u32 bytes used in the pool |
| 0x5B628 | u8[300000] route pool |
Area:
s32 flags, s16[16] (mostly −1, not followed), s32[4] corner vertices, s16[16] edge indices (−1 = none).
A convex quad the CPU may stand on. Flags: bits
4 and 8 (mask 0xC) = closed (never a goal, ends
any route through it; no file sets them, so they
are set at run time, L); bit 2
= an exit area: a route may leave it to an area
it shares no edge with (a drop or a launch: all
16,478 edge-less steps in st07’s routes start in
such an area) and the straight-walk test stops
at it; bit 1 seen on many areas, not
followed.
Edge:
vec3 start, vec3 end, s32 area a, s32 area b, s32 flags, f32 length, s32 gate area.
The border between two areas. Flag bit 1 = one
way (a → b only, read in the route length sum
0x1401790e0); with a gate area the edge is
passable only while that area has flag bit 4
(0x14017a084, M).
Routes. A route from area i
to area j is the byte string at pool[set[i][j]]
read up to the first byte equal to
j (0xFF ends a broken one): the areas
to enter in order. Routes share bytes, so they
are not terminated. Verified by
comdata.py’s check on the real
files: in st02 / st03 / st04 every area’s edges
name it and every stored route steps over shared
edges (st03: 76 areas, 118 edges, 5,700 / 3,694
/ 5,700 / 4,984 / 4,984 routes in the five sets,
0 broken); in st06 / st07 / st08 the only
edge-less steps leave a bit-2 area (and sets 2
and 4 hold the routes through them: st07 has
3,641 routes in set 0 and 15,132 in set 2);
st05 does not check clean (96
edge references and 978 routes fail: a stale
table or a layout difference in that file, not
followed). Which set is used (0x140178d00,
0x140179420): set 0 by default;
set 2 first when the
controller’s movement mode is 2 (script built-in
0x4055; 0x4052 sets it back to 0); set
4 when the caller asks for the
alternative; sets 1 and 3 are
the fallbacks when the chosen route would cross
a closed area or the area to avoid.
M for the roles; the tables
themselves H.
Queries the code makes: the area under a point = among the areas whose quad contains the point in plan (0x1401771b0) the one nearest in height, accepted within 20 units of height (0x140176e90; 0x140176f90 then falls back to a nearest area); the straight-walk test (0x140179f80): from the start area cross the edge the segment cuts into the next area, at most 16 times, failing at a closed or bit-2 area: 1 = the goal can be walked to in a straight line.
The CPU player object
Embedded in the character at C + 0x142d0 (“N”); set up by the character setup when the player record carries a CPU record (0x140176c80), or from a story record (0x140176d40).
| Field | Meaning | Conf. |
|---|---|---|
| N + 0x00 | 1 = this character is CPU driven | H |
| N + 0x08 | back pointer to C | H |
| N + 0x10 | “cannot act” flag, set each tick from the action state and ground flag; the goal built-ins do nothing while it is set | M |
| N + 0x38 | move strength written to the input block (1.0) | H |
| N + 0x3c | this tick’s straight-walk result from the body to the goal | H |
| N + 0x40 / + 0x44 | evade request and its heading (built-in 0x4031) | H |
| N + 0x48 | movement mode 0 / 2 (route set choice) | H |
| N + 0x50, + 0x5c | the goal: the point steered at this tick, and the final destination | H / M |
| N + 0x68, + 0x6c | route cursor and the current route, 128 area bytes (0xFF = empty) | H |
| N + 0xf8, + 0x120, + 0x130 | stuck counters: ticks off the mesh, ticks without moving 50 units² from the last anchor, ticks in the last three areas | M |
| N + 0x138 | AI controller (0x24F0
bytes): + 0x0c target player slot, + 0x18
enabled, + 0x20 script thread (“Menu script VM”
thread layout; value stack N + 0x1a8 … + 0x21a8,
0x400 entries), + 0x2070 variable
block, + 0x2230 script buffer (0x8000
bytes from the character’s pool), + 0x2238 “deck
named” flag, + 0x2240 / + 0x2390 the two file
loaders (com/ai,
com/deck) |
H |
Variable block (global
0x1404bc5f0 points at the running controller’s;
0x1404bbea0 at the controller):
+0x00 iterator of built-in 0x40B1,
+0x04 50 integer
variables (0..49), +0xCC
20 vector variables (3 floats
each). Both are zeroed at setup; integers 30..38
then get the parameter record. The script has no
other persistent state (its stack frame dies
every tick).
How often it runs, and what a tick does
Character tick → 0x1401775b0, once per game tick (30 Hz), for a CPU character only:
- Input block reset: I + 0x04 … + 0x33 zeroed (sticks, held / previous / pressed bits, move strength and direction), the slot permutation I + 0x30[4] set to 0, 1, 2, 3.
- Script (0x14017b220),
skipped while the pause global 0x1404bc9d4 is 1
or the controller is disabled: the thread is
restarted at the script’s function
main(0x1402ab5d0) and run with a budget of 50,000 instructions. Somainruns from its first instruction every tick; waiting is done with countdown variables, not yields. - Lock from the script’s target slot (controller + 0x0c): if that player exists with health > 0, the lock index C + 0x13f20 = its body record index and the lock state C + 0x13f1c = 1 / 2 / 3 by the distance held in the pair table (≤ 80, ≤ 300, beyond); else index −1. No button, no camera turn needed: the CPU’s aim is a perfect lock on the slot it chose, and casts then take the target exactly as a human’s do.
- Navigation (0x1401776c0,
0x140177f60; only while N + 0x10 is 0): stuck
bookkeeping, route following toward the goal,
and a pass over nearby stage objects (within 50
units) to steer around them. Before them (every
tick) N + 0x3c = the straight-walk test
(0x140179f80) from the body to the goal
point N + 0x50. (cpuvm review 2,
M):
- Follower (0x1401776c0): stuck bookkeeping first (no progress = not 50 units² from the anchor N + 0x114; counter N + 0x120). Then nothing more while N + 0x3c is set, or while the goal is under 5 units away (0x1402f7f18). Otherwise, with the body’s area (N + 0x20, last valid) and the destination’s area (N + 0x34, last valid, the nearest-area lookup of the destination): no route (N + 0x68 = −1) → plan one (0x140178d00 with argument 0: the stored route body area → destination area, set 2 then set 0 in movement mode 2, else set 0; argument ≠ 0 takes set 4 first), also when 0x1401792b0 rejects the body’s area; body in the destination’s area → goal = the destination; still no route → goal = the body’s own position and N + 0x134 = 1 (it stands); else the next route area (0x1401791f0) and the edge into it (N + 0x30) give the goal (a point on that edge, 0x140177c15 on, not read). Off the nav for more than 30 ticks → 0x140178470 (the recovery that sets the give-up flag N + 0x110; not read).
- Object pass (0x140177f60, after the
follower, every tick): the stage objects within
50 units (squared distance < 2500,
0x1402f823c) of the body that take part (object
flag 0x2000000, or the class’s vtable + 0x98
query with 4), at most 32; for each, its
collision spheres (vtable + 0x1F0, index →
centre and radius, until it returns false). A
sphere counts when the height halfway between
the body and the goal lies inside it, its plan
distance to the segment body → goal
(0x140193df0: plan point-to-segment, the nearer
end outside it) is under its radius + half the
body’s width (+0x12EA4 × 0.5), and it lies ahead
(plan dot product of goal − body and centre −
body > 0). The goal then becomes the sphere’s
centre at the body’s height plus (radius + half
width) along the plan perpendicular to centre −
body, on the goal’s side (the sign of the plan
cross product); the pass moves on to the next
object. Not read: which classes
answer the
- 0x98 query and what the base class’s sphere list holds.
- Steering (0x140178ad0): on the ground, if the goal is more than 5 units away in plan, I + 0x20 (move strength) = 1.0 and I + 0x28 (move direction) = the heading from the body to the goal point; else strength stays 0 and the character stops. In the air the strength is cut to 0 once the remaining fall would carry it past the goal (M). An evade request, in action states 0, 1 or 8 only: the evade button bit 0x1000000 is set in the held word and cleared in the previous word (a fresh press), and the facing C + 0x12e68 and move direction are set to the requested heading.
So decisions become inputs: the CPU never calls character actions. It fills the same input block the local pad fill (0x140256580) writes for a human: pressed slot-button bits, the evade bit, move strength and direction; the lock fields are written directly. Everything downstream (cast checks, aura, cooldowns, animation, hits) is the human path. H for the block writes; the human fill’s own derivation of strength / direction from the stick was not re-read here.
Script built-ins the AI scripts use (group 4, table 0x1403f0090)
Arguments in handler order (the last pushed
first, as in “Menu script VM”). “v” = a vector
variable index, “p” = a player slot 0–3, “s” = a
skill slot 0–3, “id” = a skill id. All
M unless marked; the ones
marked H are a few instructions
and were checked against how
eneprog006 uses them.
| Id | Meaning |
|---|---|
| 0x4000(i, x) / 0x4001(i) | write / read integer variable i (H) |
| 0x4002(dst, src) | copy a vector variable (H) |
| 0x4010(a, b) | distance between two vector variables, in metres (units × 0.1, truncated) (H) |
| 0x4012(v) / 0x401F(v) | area under the point: with / without the nearest-area fallback (−1 none) |
| 0x4013(v) | set the goal to the point (both goal fields) |
| 0x4014(area) | set the goal to an area’s centre unless the area is closed; 1 = done |
| 0x4015(v, x, y, z) | add (x, y, z) × 10 to a vector variable |
| 0x4017(a, b) | heading from point a to point b in degrees 0–359 (H) |
| 0x4018(a, b) | straight-walk test between two points |
| 0x401C / 0x401D / 0x401E(v, k) | x / y / z of a vector variable × k ÷ 10 |
| 0x4020(n) | random integer 0 … n − 1 (C
rand, 15 bits)
(H) |
| 0x4021(a, b) | a − b wrapped to −180 … 179 degrees (H) |
| 0x4025(a, b) | the distance in metres (× 0.1, truncated) between the centres of areas a and b (corner means) (corrected 11-10 cpuvm: not a point into v) |
| 0x4030(s) | press skill button s: ORs the slot’s button mask (I + 0x40 + 4·s) into the pressed word I + 0x1c; under status 0x24 (the slot shuffle) it goes through the permutation I + 0x30, which step 1 keeps at identity (H) |
| 0x4031(deg) | evade (the character’s jump or roll) toward a heading (H) |
| 0x4032(v) / 0x4033(v, w) / 0x4034(v) | plan a route to a point (0x14017a1a0, with an optional second point; 0x14017a750 is a variant); the result says whether a route was set |
| 0x4035(deg) | the evade check (handler 0x14020e020) (decoded cpu2): when the character’s evade skill (charaset +0x36, in memory 0x1404c024c) is set 3 subtype 8 (a dash; record words 0x52 / 0x54), the straight-walk test (0x140179f80) from the character’s position to the point word 0x56 × 10 units away at that heading (degrees × 32768 / 360 angle units, the heading convention of 0x4017); 1 for any other evade skill. The script turns the evade by 180° when it gets 0 |
| 0x4038() | ticks without progress (N + 0x120) |
| 0x403B() / 0x4053() | has a route / drop the route |
| 0x403C() | where the CPU is on its way (decoded 11-10 cpuvm): 0 when the destination’s area (nearest area) is missing or closed, or there is no route and no straight walk; when the body is in the destination’s area the goal becomes the destination and it returns 2 within 7 units in plan (0x1402f7f40), else 1; with this tick’s straight-walk flag (N + 0x3c) goal = destination, 1; when the body is in the route’s last area: 1 if that isn’t the destination’s area, else goal = destination and 2 within a squared distance of 30 (0x1402f7fd8), else 1; otherwise (unless it can’t act) goal = destination, 1 |
| 0x4052() / 0x4055() | movement mode 0 / 2 |
| 0x4060(p) / 0x4061() | set / read the target player slot (the lock, step 3) (H) |
| 0x4070() | own player slot (H) |
| 0x4071(p, v) | player p’s position into v (only if present and locally simulated) (H) |
| 0x4072(p, v) | player p’s start position into v |
| 0x4073(p) | player p’s facing in degrees |
| 0x4075(a, b) | the pair table’s integer for players a, b (0x1404bbe20 + (4a + b)·8; its float half is the distance used by the lock grade): clear sight (decoded 11-10 cpuvm), 1 when the segment between their points C + 0xe0 is clear of the stage (C + 0xe0 is the translation row of the body matrix 0x1402513a0 rebuilds each tick: the facing rotation placed at the world position of the model joint behind the pointer C + 0x13dc0; the previous tick’s matrix is kept at C + 0xf0; docs 11-12: the joint is the torso root node, about 11.1–12.1 u over the feet at rest by model, animated: “Body point, sight point and aim point”; our point is 1.2 m up) (0x1401641b0 with an empty player mask; hits of collision kind 0x10 pass); one pair is refreshed per tick by 0x14012a960 and mirrored to [b][a]. The script stores it in variable 10 and fires only when it is set |
| 0x4076(p) / 0x4077(p) / 0x4078(p) | health / aura level / current aura of player p (P + 0x0c, + 0x18, + 0x1c) |
| 0x4079(p, n) | player p has status slot n active (0x14024d4d0) |
| 0x407A(p) | team of player p (−1 absent) |
| 0x407B(p) | cards p can still take (decoded 11-10 cpuvm), in battles with a deck: 30 − the cards drawn from p’s deck (0x140585c00[p], counted up by the draw at 0x140158840) + p’s capsules standing on the field (0x140585c20[p], counted from the capsule states); otherwise the character’s C + 0x17158. The script goes for capsules only while it is above 1 |
| 0x407C(p) | coarse state of player p: 1 free, 2 casting (action states 10–12), 3 action state 17, 4 the character’s own “busy” test, 5 down, 6 not in play, 0 not locally simulated |
| 0x407D(p) | the slot being cast while in action states 10–12, else −1 |
| 0x4086(p) | the evade skill record of player p’s
character (decoded 11-11 cpu2): the
in-memory character table (0x1404c01e0, 0xA0
bytes per character) at +0x6C, which is the
charaset file’s +0x36 (our
movement.json evade record). The
script compares it with a fixed record number to
pick its evade handling |
| 0x4087(p) | the kinesis pick (decoded cpu2): when C + 0x10 is 0 it returns 0x14012e160(C + 0x12e40, the facing word at C + 0x12e5c), else −1. 0x14012e160 takes the first 32 throwable stage objects (table 0x1405322c8, count 0x1405322bc) in table order whose squared distance is < 10000 (100 units) and answers the nearest one within ±0x1000 angle units of the facing (0x8000 a turn; angle = atan2(dx, dz) × 5215.189) or with squared distance ≤ 625, −1 when none. The script reads “≠ −1” as “may use a ranged attack” (classes 2 and 4) |
| 0x4090(p, s) | skill id in slot s (−1 empty) (H) |
| 0x4092(p, s) / 0x4099(p, s) | that skill’s type (record 0x0E) / behavior (0x7A, only for skill set 0) |
| 0x4093(p, s) | the slot’s remaining uses word (slot + 0x10) |
| 0x4094(p, s) | slot is ready: filled, state word 0 and no pending object |
| 0x4096(p, s, x) | compares: 1 when the slot state word equals x (corrected 11-10 cpuvm: not a write) |
| 0x4098(p, s), 0x40A5(id) | attack class of a skill (0x140167970): 0 not an attack, 1 lunge (melee kinds), 2 other ranges, 4 long range, 5 behaviors 8 / 9 (mines) |
| 0x40A1 / 0x40A2 / 0x40A6 / 0x40A8 / 0x40A9 / 0x40AC / 0x40AD / 0x40AF(id) | skill record fields: type 0x0E / skill set 0x52 / behavior 0x7A / 0x54 of set 2 / health cost 0x2E / 0x5C / hit effect 0x62 / 0x50 |
| 0x40AB(id) | 0x140167a10 (a second classification, L) |
| 0x40B0() / 0x40B1() | reset / advance the shot iterator over all 4 × 48 skill objects: the next live attack object that is not a melee kind (behaviors 3, 12, 13, 14) nor behavior 4; −1 at the end |
| 0x40B2(o) / 0x40B3(o, v) / 0x40B7(o) | that object’s owner slot / position into v / the slot of the player it is aimed at |
| 0x40BA(o) | the shot threat (decoded cpu2 for behaviours 0 / 11): handler 0x1402105a0 → 0x14020f9a0, the ticks until shot o reaches the CPU, 0 when it doesn’t threaten it. 0 for a shot that can’t hit the CPU, a set other than 0, the melee behaviours (3, 12, 13, 14; 0x140167910) and behaviour 4; shot state 3 goes to 0x14020f8c0. A jump table by behaviour: 0/11 → 0x14020facc, 1 → 0x14020fdff, 2 → 0x140210073, 5 → 0x1402102af, 6 → 0x140210052, 7 → 0x140210488, 9 → 0x140210510, 10 → 0x140210361, 15/16 → 0x1402104cc, others 0. Behaviours 0/11: aimed at the CPU, the stage segment must be clear (0x1401641b0) unless collision word 0x6A is 2 or 3, the cosine between the heading and the CPU must be > 0.5, and the answer is (distance − (CPU radius + shot radius)) / speed truncated, 0 when more than the ticks left; aimed at another player 0; aimed at no one, the closest point (0x140193fd0) of p0 → p0 + dir · speed · ticks left, and when the CPU point is within reach of it the ticks to it. Behaviours 15/16: when the shot’s caster is on another side than the CPU, its ticks left minus record word 0x7e (0x14020d0c0: the word at 0x7e for set 0 behaviour 15/16 records, else −1), else 0. Behaviour 6: when the shot’s target is the CPU, the shot’s int at +0x1cc, else 0. Shot fields: +0x100 position, +0xf0 direction, +0x190 radius, +0x1c0 / +0x1d0 speed, +0x18 ticks left, +0x48 target. The CPU point is raised by C + 0x12e98 (docs 11-12, doc-body, M: read in the code, not run) The rest of the table. Arguments (handler 0x1402105a0): the CPU point P = feet + centre height, the radius R = C + 0x12E9C (5 u), and a flag W = the nav straight-walk test 0x140179f80 between P and the shot position. reach = R + shot radius (+0x190). Sign: in every “reach” formula the code computes trunc((reach − distance) / speed), so the value is 0 or negative while the shot is outside reach (behaviours 0 / 11 included: the “more than the ticks left” cut can then never trip); the script only tests it for non-zero and stores it in variable 18, so read the magnitude as the ticks. Behaviour 1 (parabola): aimed at the CPU → the shot’s flight ticks left (+0x1d4: set at init to lifetime − 30, rewritten by the update); aimed at someone else → 0; aimed at no one → with g = +0x1cc, vy = +0x1c4, y0 = shot y: t_up = vy / g, apex = y0 + 0.5·g·t_up², T = t_up + sqrt(2·(apex − P.y) / g); 0 when P.y is over the apex, when P.y > y0 with vy < 0, or T ≤ 0; landing point = shot position + forward(yaw +0x1d0) × speed (+0x1c0) × T; the answer is trunc(T) when the horizontal distance landing point → P is under the record’s blast radius (word 0x64 × 0.1, 0x14020d010), else 0. Behaviour 2 (fall): aimed at the CPU → the stage line P → shot must be clear unless collision word 0x6A is 2 or 3, the shot must be higher than P, answer trunc((reach − distance) / speed +0x1c0); aimed at someone else 0; aimed at no one → the closest-point rule of behaviours 0 / 11 (segment p0 → p0 + dir·speed·ticks left, within reach, ticks = distance along it / speed). Behaviour 5 (crawl): 0 when W = 0; aimed at the CPU → trunc((reach − horizontal distance) / speed +0x1c4), no sight test; someone else 0; no one → behaviour 2’s closest-point rule with speed +0x1c4. Behaviour 6 (multishot): aimed at the CPU → the arc ticks left (+0x1cc: written by the init 0x1402666b0 at 0x140266b36 as 2 × trunc( |
| 0x40E5(p, n) | a health change (decoded cpu2): handler 0x140210e80, for p in 0..3 0x14024d7a0(player p, n): when the battle-mode global 0x1404bc9d4 is non-zero (the battle start 0x140128990 / 0x140128fc0 stores its mode argument there: 2 for a single battle, 4 / 5 for the network modes, 6 for split-screen, so it is set in every versus battle; the one start that passes 0 is the special battle the script built-in at 0x140212720 begins) and p’s health is above 0, n is added to it (clamped to the maximum at +0x10); at 0 or less the player is knocked out (0x14024e000). It also keeps a per-player damage tally (0x1405b15f0 / 0x1405b15f8). The script calls it with (self, −100) when it is at a capsule and none of its four slots passes its checks |
| 0x40C0(a, b) / 0x40C1(a, b, v) | capsule [a][b] (3 per group in the capsule block 0x140584f80): its content when it is out (state 2), else −1 / its position into v |
| 0x40C2() / 0x40C3() | what the character has in reach this tick (decoded 11-10 cpuvm): kind (C + 0x17160) / index (C + 0x17164), rebuilt each tick by 0x140251550: 1 = one of its own capsules (index = the capsule slot, from 0x14014f630), 2 = the object 0x1402516a0 finds, 3 = an entry of the table 0x14058bd30, 0 = nothing (index −1). The script presses the slot to take a capsule when the kind is 1 and the index is the capsule it walked to |
| 0x40C5() … 0x40C8() | the environment in force
(decoded 11-11 cpu2), all from the
entry the “active” pick 0x14017c4c0 returns (the
table 0x14058bd30, one 0x1c-byte entry per
player: position, skill id, start tick, end
tick; the pick is the one
PdEnvironment._pick builds, rules
in “Environments (set 5)”). 0x40C5: its skill
id, −1 when none (match mode 5, or the story
flags 0x1404bc950 = 6 with 0x1404bbed8 > 0,
give −1 or a forced id instead). 0x40C6: 1 when
it can be captured now: it has a skill, its end
is −1 or later than now, and start + guard <
now (guard = record word 0x56 when the skill set
word 0x52 is 5, else −1). 0x40C7(v): its cast
point into vector v. 0x40C8: its entry index,
i.e. the owner’s player slot |
| 0x40D0() | the match tick counter 0x1404bc63c |
| 0x40D2() | number of nav areas |
| 0x41A9() / 0x41AA() | a story value (0x1404c01d8), −1 in versus |
| 0x40E0, 0x40E8 | empty (developer print) |
| 0x40E1 … 0x40EF | developer only: debug pad, give a skill to a slot, set health / aura, teleport to the start point, apply a status. Only the three check scripts use them |
Also there, unused by the shipped scripts:
0x4040 … 0x4043 read the nav file’s two point
lists. ssbdump.py --calls on
eneprog006 lists 75 distinct
built-ins; the table covers all of them.
How versus gets a CPU
- The online and local versus lobbies have
no CPU slot: nothing in the
lobby code builds a CPU record. The one
versus-vs-CPU path is built-in
0x4295 (0x140214770), called by
the multiplayer menu’s one-on-one CPU battle
screen (menu script
livedbtl, resultslivedbtlres). It builds a fixed CPU record at 0x1405b18b0: parameter record 20, scripteneprog006.ssb, deck name empty; two players; match mode 0x1404bc5dc = 0; the stage from the menu’s choice (0x1401907a0). H for the record, M for the menu’s role. - CPU record (what the player
setup record points to at + 0x20; 0 = human): +
0x14 and
- 0x18 = 20 here (+ 0x18 is the parameter record index, H), + 0x20 a display name,
- 0x31 deck file name (char[21]), + 0x46 AI script file name.
- Deck: with an empty deck
name no
com/deckfile is read; the 30 skills of slot 1 are taken from the deck record in memory at 0x1404bc8e0 (skills at + 0x14, school count at- 0x50, the deck file layout), dealt by the same deck set-up routine as the human’s (0x14014f830). The record is filled by menu built-in 0x4293 from the row the player picked on the online ranking list (the ranked player’s arsenal, downloaded): H, (doc-answers) “Open questions settled” 7.
- Character: the player setup record’s + 0x08, as for a human; set by the same menu.
- 2v2 CPU team-mates: none in versus. Story partners use the second setup path (0x140176d40: record + 0x34 parameter index, + 0x1a script base name, + 0x04 deck name). The scripts themselves are team-aware (0x407A), so a CPU team-mate only needs a slot, a team and a target choice.
Confidence. File layouts and
the tick order H (read in the
code, comdata.py checks on the
files). Built-in meanings M (a
few H, a few
L, marked). The navigation
functions’ insides, the 660-byte decks and the
compact st01 file L / not
read.
Not decoded: the follower’s
edge point and off-nav recovery (0x140177c15 on,
0x140178470), the planner’s pass over a copied
route (0x140178e20), the object pass’s sphere
source (vtable + 0x1F0), 0x14017a1a0 and
0x14017a750 line by line; who sets area flags 4
/ 8; the area record’s first 16 words and the
per-area byte; point lists A / B (A carries an
id and a float per point: probably marked spots
with a radius); the pair table’s writer
(0x1404bbe20); eneprog006’s own
decision tree beyond the parameter uses
above.
Implementation notes for the rebuild
- Interpret the game’s script, do not
re-implement it.
eneprog006.ssbis read from the user’s copy at run time (code words and its small string pool stay out of the repo), run by a GDScript interpreter of the 32 opcodes (“Menu script VM”, ~200 lines): restartmainevery 30 Hz tick with a 50,000-instruction budget, 50 integer + 20 vector variables per CPU, variables 30..38 fromenemyparam.eparecord 20. - Outputs go into the same input struct as a human’s pad: pressed slot bits, the evade bit with a heading, move strength 1.0 + direction toward the goal when it is more than 5 units away; the lock is set from the target slot each tick with the 80 / 300 grades. Nothing else may be special-cased for a CPU.
- Built-ins, ranked by need
(calls in
eneprog006): variables and maths (0x4000, 0x4001, 0x4002, 0x4010, 0x4017, 0x4020, 0x4021); self and players (0x4070, 0x4071, 0x4076–0x407C, 0x407A); slots and skills (0x4090, 0x4092, 0x4094, 0x4098, 0x40A1, 0x40A5, 0x40A6); actions (0x4030, 0x4031, 0x4060 / 0x4061, 0x4013); then capsules (0x40C0, 0x40C1), incoming shots (0x40B0–0x40B7, 0x40BA), environment (0x40C5–0x40C8), time (0x40D0); last navigation (0x4012, 0x4014, 0x4018, 0x401F, 0x4032–0x403C, 0x4052 / 0x4055, 0x40D2). An unimplemented built-in must return 0 and be logged, not guessed. - Navigation: convert
comdataN.cadwithcomdata.py(areas, edges, route sets; a few hundred KB of JSON per stage, user-side only). Smallest faithful mover: area under a point, straight-walk test, route lookup (set 0, set 2 in mode 2), goal = next area’s centre until the last area, then the point. The game’s stuck recovery is not decoded: a rebuilt one is a placeholder (ledger row). - Set-up: health from the parameter record’s byte 0, the CPU’s deck dealt by the normal deck set-up, the same character table as a human. Offer the five strength steps of a record series as the difficulty choice only as our own extension (the game’s versus battle always uses record 20).
- Our present bot (
main.gd) stays a placeholder until the interpreter runs; the Palace (st03) nav file has 76 areas and no bit-2 exits, so it is the easy first stage.
Rebuild implementation (cpuvm) (11-10)
- Converter
converter/cpuexport.py(GPL-3.0, beside comdata.py) writes, from the user’s own copy:cpu/ai/<name>.ssb(copied byte for byte),cpu/enemyparam.json(health byte + variables 30..38 per record),cpu/decks.json(the 100-bytecom/deckrecords: file name, 30 cards, school capacity, rule flags; plus skill record 0 ofgsdata_<lang>.datas"aura_card"),<stage>/nav<N>.json(comdata.nav_json + the five route-set offset tables + the used route pool, base64). - Deck cards are skill record
indices (the
recordfield of skills.json, notid): the school-capacity rule holds for all 404 decks read that way (232 when read as ids). A −1 card is an aura card; in the match deck an aura card is card id 0, so a slot holding one reads skill record 0 (type 0, word 0x50 = 0, skill set word 0x52 = 4). The script finds aura cards by word 0x50 = 0 and attack cards by word 0x50 ≤ 40. - Slot state word (slot object at P + 0x348 + 0x50·k, field + 0x24, read as P + 0x36c by 0x4094 / 0x4096): rebuilt every tick by 0x14026205f; −1 when the player isn’t in play; bit 2 when the slot’s cost (slot + 0x18, adjusted by status 30) is more than the current aura, bit 1 as well when the aura level is below it, bit 1 alone when the level is below record word 0x2A; a negative record cost (word 0x28) needs the current aura at the constant 0x1402f7da8; bits 0x10 and 0x8 come from 0x140262470 and 0x140262d80, 0x20 from slot state 2, and 0x4 when the character refuses the skill (its vtable + 0x38). So “ready” includes affordability.
- Rebuild side
(
godot/scripts/script/pd_script_vm.gd,godot/scripts/cpu/): PdScriptVm (the 32 opcode values and the native-call convention as in “Menu script VM”: 30 with a handler, 0x0B and 0x0C stop with the error bit as the game’s do; built-ins are a table id → Callable; an unknown id returns 0 and is logged once); PdNav (area lookup, routes, straight walk); CpuInput (an InputSource: each tick restartsmainwith a 50,000-instruction budget, then turns the script’s outputs into the normal PlayerInput: slot presses, the evade press with its heading, the stick toward the goal past 5 units, and the lock as lock presses).--cpuputs it on the rival (local matches only: a network session ignores it). What is ours rather than decoded is listed in PLACEHOLDERS.md (rows “CPU …”).