Live prompts: call lnInit from each symbol class's constructor

In the second run in the title, Main's initialiser ran (the run-time
sentinels were found, four copies) but lnMade stayed 0: the hook in
mx.core.SpriteAsset never ran. The three movies that load the glyph movie
each define mx.core.SpriteAsset too, and theirs is the one used. The 38
Main_Button_N classes and platform_xbsx.input_icons.Main are defined only
in the glyph movie (the loaders' document classes are generic_movie.Main,
hud.Main and map_scripted_movie.Main), so each Main_Button_N constructor
now calls Main.lnInit(this) in a try block and SpriteAsset is left as it
is. 459 bytes to spare.
This commit is contained in:
ubiquitarianism
2026-11-29 23:20:51 -05:00
parent 1fb8c4bfef
commit 69454e705a
3 changed files with 38 additions and 20 deletions

View File

@ -294,8 +294,12 @@ tells it the family in use. `LEONIDA_PROMPTS_LIVE=0` turns it off (one family's
already are and counts a switch in `lnShown`; `lnInit` counts the prompt in `lnMade`, shows and adds an
`enterFrame` listener; `lnTick` shows on each frame while the sprite is on the stage,
and otherwise swaps its listener for an `addedToStage` one (`lnAdded`, which puts it back), so prompts taken off
the stage cost nothing and are not kept alive by a frame listener. `SpriteAsset`'s constructor calls
`Main.lnInit(this)` after its own work, in a try block. A prompt on screen therefore follows a switch on the next
the stage cost nothing and are not kept alive by a frame listener. The constructor of each `Main_Button_<N>`
calls `Main.lnInit(this)` after its own work, in a try block. (Hooking their shared base `mx.core.SpriteAsset`
once did not work: the three movies that load this one each define `mx.core.SpriteAsset` too, 45, 91 and 81
classes in all, and the second run's counters stayed at 0. Their document classes are
`platform_xbsx.generic_movie.Main`, `platform_xbsx.hud.Main` and `platform_xbsx.map_scripted_movie.Main`, so
`platform_xbsx.input_icons.Main`, whose initialiser makes the sentinels, is this movie's own.) A prompt on screen therefore follows a switch on the next
frame, not only the next prompt made.
- `lnLo` and `lnHi` hold sentinels (the doubles whose bytes are `LEONIDA1`, `LEONIDA2`), which `Main`'s static
initialiser computes before its own code (half of each, from the pool, times 2): they are in no copy of the movie
@ -350,10 +354,15 @@ writes that missed. Both are changed above. What the next run's log tells:
- `prompts made` rising but `switched` not rising on a switch: the writes miss the slots the code reads;
- `in_movie` or `implausible` above 0: finds of another kind were seen and left out.
The second run (2026-11-29, sentinels made at run time): found 7 s after the serve, `stride=8 copies=4`, no
reject, so `Main`'s initialiser ran in four copies and its slots are raw doubles; every switch was written to all
four, but `prompts made 0, pictures switched 0` for minutes with prompts on screen: the `SpriteAsset` hook never
ran (above).
### Not proven until it runs in the title
Whether Scaleform runs the added code at all (its verifier), whether a symbol's frame children exist when
`SpriteAsset`'s constructor runs (if not, `lnShow` finds no `p` and the first frame shows the PlayStation glyph until
its constructor runs (if not, `lnShow` finds no `p` and the first frame shows the PlayStation glyph until
the first `enterFrame`), whether `enterFrame` reaches the icons, and how it stores a class's `Number` slots
(raw doubles, or `Value`s of 16 or 24 bytes, are all searched; another layout logs `not found`). The memory search's
time on the title's heap is not measured; the log line says it.

View File

@ -288,7 +288,7 @@ def hooked():
abc = title_like_abc()
added = live.hook(abc)
vm = VM(abc, abc.find_class(live.MAIN))
ctor = abc.instances[abc.find_class(live.ASSET)].iinit
ctor = abc.instances[abc.find_class("Main_Button_30")].iinit
return abc, added, vm, ctor
@ -329,7 +329,9 @@ class AbcFile(unittest.TestCase):
class Code(unittest.TestCase):
def test_the_added_code_passes_the_checks(self):
abc, added, _, _ = hooked()
self.assertEqual(len(added.bodies), 5, "four methods and the constructor")
self.assertEqual(len(added.bodies), 4 + len(N), "four methods and the 38 constructors")
asset = abc.body_of(abc.instances[abc.find_class(live.ASSET)].iinit)
self.assertEqual(asset.code, live.PLAIN_CONSTRUCTOR, "the shared base is left as it is")
for body in added.bodies:
stack, scope = live.check_body(abc, body)
self.assertLessEqual(stack, body.max_stack)
@ -381,7 +383,7 @@ class Code(unittest.TestCase):
with self.assertRaises(ValueError):
live.hook(abc) # twice
abc = title_like_abc()
abc.body_of(abc.instances[abc.find_class(live.ASSET)].iinit).code = bytes([0xD0, 0x30, 0x47])
abc.body_of(abc.instances[abc.find_class("Main_Button_59")].iinit).code = bytes([0xD0, 0x30, 0x47])
with self.assertRaises(ValueError):
live.hook(abc)
abc = title_like_abc()
@ -517,8 +519,9 @@ class Movie(unittest.TestCase):
abc = A.parse(body[body.index(b"\0", 4) + 1:])
main = abc.find_class(live.MAIN)
self.assertIn("lnFamily", [abc.text(abc.multinames[t.name][2]) for t in abc.classes[main][1]])
ctor = abc.body_of(abc.instances[abc.find_class(live.ASSET)].iinit)
self.assertEqual(len(ctor.exceptions), 1)
for n in N:
ctor = abc.body_of(abc.instances[abc.find_class("Main_Button_%d" % n)].iinit)
self.assertEqual(len(ctor.exceptions), 1, n)
def test_it_does_not_fit_when_the_room_is_not_there(self):
small = standin()

View File

@ -25,9 +25,13 @@ movie carries two:
pieces (``p`` onwards) visible; ``lnInit(sprite)`` counts, shows and listens for ``enterFrame``, ``lnTick`` shows again
on each frame while the sprite is on the stage (a prompt already on screen follows a switch) and otherwise trades
the frame listener for an ``addedToStage`` one, ``lnAdded``, so a prompt taken off the stage costs nothing;
- the constructor of ``mx.core.SpriteAsset``, the base of all 38 symbol classes and of nothing else, calls
``Main.lnInit(this)`` after its own work, inside a try block: whatever goes wrong there, the prompt is made as
before. Each of the four methods is a try block too.
- the constructor of each of the 38 ``Main_Button_<N>`` classes calls ``Main.lnInit(this)`` after its own work,
inside a try block: whatever goes wrong there, the prompt is made as before. Each of the four methods is a try
block too. (A first version hooked their base, ``mx.core.SpriteAsset``, once: but the three movies that load this
one define ``mx.core.SpriteAsset`` too, the loader's definition is the one used, and in the title the hook never
ran: ``lnMade`` stayed 0, 2026-11-29. ``Main_Button_<N>`` and ``platform_xbsx.input_icons.Main`` are defined only
here; the other movies' document classes are ``platform_xbsx.generic_movie.Main``, ``...hud.Main`` and
``...map_scripted_movie.Main``.)
* the runtime (leonida-hle, ``modules/glyphs.rs`` and ``glyphs/live.rs``) finds ``lnLo, lnFamily, lnHi`` in the
title's memory by the sentinels, a few seconds after it served the movie, and writes ``lnFamily`` whenever the
device in use changes.
@ -66,7 +70,7 @@ ASSET = "mx.core:SpriteAsset"
BUTTON = "platform_xbsx.input_icons:Main_Button_"
FIRST_PAD = "p" # the name of the first pad piece in each sprite (drawn over the keyboard pieces)
# The title's SpriteAsset constructor: getlocal0, pushscope, getlocal0, constructsuper 0, returnvoid.
# The title's symbol class constructor: getlocal0, pushscope, getlocal0, constructsuper 0, returnvoid.
PLAIN_CONSTRUCTOR = bytes.fromhex("d030d0490047")
# ---------------------------------------------------------------- AVM2 instructions used here
@ -250,9 +254,9 @@ def hook(abc):
for name in (b"lnFamily", b"lnShow"):
if name in abc.strings[1:]:
raise ValueError("the block already has the live prompt code")
ctor = abc.body_of(abc.instances[asset].iinit)
if ctor.code != PLAIN_CONSTRUCTOR or ctor.exceptions:
raise ValueError("%s's constructor is not the plain one this tool extends" % ASSET)
ctors = [abc.body_of(abc.instances[i].iinit) for i in buttons]
if any(ctor.code != PLAIN_CONSTRUCTOR or ctor.exceptions for ctor in ctors):
raise ValueError("a symbol class's constructor is not the plain one this tool extends")
for raw in (SENTINEL_LOW, SENTINEL_HIGH, FAMILY_UNSET):
if struct.pack("<Q", raw) in abc.doubles[1:]:
raise ValueError("the block already holds a sentinel")
@ -364,7 +368,7 @@ def hook(abc):
method(tick, 3, 4, write_tick)
method(added, 3, 4, write_added)
# The constructor of SpriteAsset: its own work, then Main.lnInit(this) in a try block.
# Each symbol class's constructor: its own work, then Main.lnInit(this) in a try block.
a = Asm()
a.out += PLAIN_CONSTRUCTOR[:-1]
start = a.here()
@ -373,10 +377,12 @@ def hook(abc):
a.op(RETURNVOID)
handler = a.here()
a.op(POP).op(RETURNVOID)
ctor.code = a.code()
ctor.exceptions = [(start, end, handler, 0, 0)]
ctor.max_stack = max(ctor.max_stack, 2)
out.bodies.append(ctor)
code = a.code()
for ctor in ctors:
ctor.code = code
ctor.exceptions = [(start, end, handler, 0, 0)]
ctor.max_stack = max(ctor.max_stack, 2)
out.bodies.append(ctor)
# Main's static initialiser: the sentinels first, made from their halves, then the title's own code.
a = Asm()