Skip to content

One more UI::MenuItems function at 100%: InGameMenu ProcessScribeAnimationChange - #468

Open
kotijekriv wants to merge 1 commit into
sourcehold:mainfrom
kotijekriv:reimpl/UI-A-scribe-100
Open

kotijekriv wants to merge 1 commit into
sourcehold:mainfrom
kotijekriv:reimpl/UI-A-scribe-100

Conversation

@kotijekriv

Copy link
Copy Markdown
Contributor

One more function at 100%, with no header changes and no line for cmake/compiler-flags-gl.txt. One behaviour fix against gynt's newest drafts: they leave the frame's copy one step behind after a step of phase 0 or 2 (in the code; the game most likely never enters those phases, below). His older copies return in the wrong places too. He fixed both of those himself, but the oldest copy is still on sourcehold's reimpl/UI-MenuItems and on 20 of his fork's branches. InGameMenu::MenuItemActionHandler_InGameMenu_ProcessScribeAnimationChange steps the scribe's animation in the in-game menu. While a tax setting is animated it moves the frame every 60 milliseconds through three phases; otherwise it sets the frame that shows the player's popularity. It is from gynt's draft on his fork's reimpl/UI-MenuItems, and the commit credits him as co-author.

Function Address Before After
InGameMenu::MenuItemActionHandler_InGameMenu_ProcessScribeAnimationChange 0x00433370 gynt's draft 29.4% (d5895e2; before it 24.6% at 668d05f, 26.74% at cee8a6a and 35.68% at 1831d14; 29.1% at 8725ec5 on his reimpl/UI-MenuItems-development) 100.0%, off the /GL list and on it

Measured.

  • Setup: the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie.
  • Full build: an all-on build of this branch on main 812d149, with main's own /GL list and with 0x004314E0 (the MapEditorLandscaping_GeneralButtons handler) left out and its resolver off, as in main's baseline: 0 failed of 2,424 compile steps, 99.57 over 2,440 functions, against 99.58 over 2,439 for main alone (built at f489b72; 3458fea only adds files under tools/, and cmake: optional wrapper units built from function-visibility.txt #399 and cmake: function-visibility.txt, which callers must see which callees' bodies #398 add the optional function-visibility units, off by default). MenuItemActionHandler_InGameMenu_ProcessScribeAnimationChange reads 100.0 raw and normalised there too, with no diff entry; it has no caller in code. Two functions on main read lower, and it is how reccmp prints a constant, not their code: Menu::handleMenuItems (0x004F6280) reads 97.9 (91.4 normalised) and Menu::Constructor_Menu (0x004F4100) reads 98.4 (95.2), both 100.0 before. Both compare a menu item's type with the constant 0x11000000, and in this build's layout a symbol of our DLL lies at exactly that address, so reccmp prints the constant as that symbol's name on our side; the instructions are the same on both sides, as UI: three more functions at 100%: the building menu's DoInitial, the credits' prepare and activateModalDialog2 #435 and UI: the credits scroll's fade and the win/defeat window at 100% #437 describe. Every other main function reads exactly what it read before (unrounded 99.5746 against 99.5759 raw and 99.5439 against 99.5492 normalised; with those two at 100.0 it would be 99.5761 and 99.5494).
  • Our own narrower run: the 133 files of main's /GL list that exist on main, and this file, off the list: 144 functions, average 99.56. The function reads 100.0% raw and normalised, with no diff entries, and the same with the file on the list. The same build without the file has 143 functions, and each of them reads the same. The builds had this file with one comment worded differently; quick_diff gives the same 129 instructions, line for line, for that text and for this one. The first cut (other comments, the phase cases in the order 2, 1, 0, the parameter named button) read the same in the same two builds. The sources were main's at 3458fea; main's two commits since (02fab42, 812d149) add cmake files only, with the new option off. main has since gained 25d2e9e (feat(import): update requirements and documentation of tools/import #456), which changes only tools/import.
  • Instructions: the original's 129, in its order; reccmp's diff for the function is empty. The switch on the tax setting has a jump table of four entries (0x00433499).
  • Please measure with both resolver switches on (the Globals and the function resolvers), as our numbers are.
  • Checks: our local style checker gives 0 ERROR and 1 CHECK (the case labels are numbers; below); our local fixer finds nothing to change.
  • Not run in game.

Against the drafts

The function is rewritten against the original instructions; the rewrite was first in our draft #328. Against gynt's newest copies one thing in the behaviour changes, and it is what the original does. His older copies also differ in where they return. He fixed those himself, and the returns here are the original's:

  • The frame's copy. At its end the function compares scribeAnimationFrameCopy with the frame and stores the frame there. In his 29% texts (from 65a026c on: 29.41%, 29.4% and 29.1%) the value compared and stored is a local that the two stepping phases do not update: when phase 0 or phase 2 moves the frame one up or down, the copy gets the frame from before the step, so countdown is set one step late. The original has the new frame in the register it compares and stores (0x0043342B to 0x0043343F, 0x0043345C to 0x00433470, then 0x0043352B and 0x00433545). Here the frame is the global itself, so the copy gets the new frame. In the game this most likely never shows. The only code that starts a setting, Helpers::SetTaxesSetting_unknown (0x00433560), starts it in phase 1, and the exe has no other store to scribeAnimationPhase than this function's = 1 (0x00433477). So phases 0 and 2 do not seem to run.
  • Three returns, which he restored himself. His 24.6% text (668d05f, on sourcehold's reimpl/UI-MenuItems; with his style passes as cf563c2 on 20 of his fork's branches) has empty bodies where the function returns: for the editor, for game mode 6, and for a step that comes less than 60 milliseconds after the last one. That copy animates in every mode and at every call. He restored the 60 millisecond return in cee8a6a (26.74%) and the two game-mode returns in 1831d14 (35.68%). The 29% texts have all three, and so does this one (0x00433378, 0x00433381, 0x004333AF).
  • A return too many, which he fixed himself. His 26.74% and 35.68% texts (cee8a6a, 1831d14) return behind every step, and when a sequence reaches its end. So while a setting is animated, the second switch and the copy's test are never reached. The original goes on to them from every step (the jumps to 0x00433485 and 0x0043348A) and from the end of a sequence (0x00433525 falls through to 0x0043352B). His 65a026c ("switch was unreachable, rebuil[t]", 29.41%) took those returns out, and so does this text. The same commit brought in the local that leaves the frame's copy behind (above).

The rest is the same: the same tests, the same three phases, the same sequences for the three settings.

What got it to 100%

Our draft's last text read 93.3%: the original's 129 instructions, with one difference. The zero that the compiler keeps in a register was in ebp, where the original has ebx (0x0043338F), and ebx was not used at all.

  • The phase was a local, loaded from scribeAnimationPhase and stored back with it. A local is one more value the compiler wants to give a register: it got one, and the zero got the next. With the global written at each use the compiler keeps the phase in edi itself (0x004333B5, 0x00433472), as the original does, and the zero gets ebx: 129 instructions against 129, no difference.
  • The frame is written the same way, scribeAnimationFrame at each use. For the frame a local gives the same listing; the global is the plainer text, and it is what makes the copy's fix above plain to see.
  • Each entry of a setting's sequence is read into a local and tested. The 93.3% text read the table twice instead, because with the phase and frame in locals the single read stored the wrong register (0x0043351E: the original stores eax there, behind its mov eax, ecx). In this form the local gives the original's instructions.
  • The phase switch's cases are in the order 0, 1, 2, as the animation runs (gynt's newest text had 2, 1, 0): the same listing.
  • The three settings' cases stay written out. The original has their common end once (from 0x00433518). Written once, with a goto from the first two cases, the compiler no longer keeps the zero in a register (126 instructions).

quick_diff reads 1.0000: 129 instructions against 129.

No line for cmake/compiler-flags-gl.txt

Kept as they are

  • slot is a local: written out at its two uses, the zero is no longer kept in a register of its own and the match is lost (127 instructions).
  • now is a DWORD, and the 60 millisecond test casts the difference to int: the original compares it signed (jl at 0x004333AF).
  • The numbers (60 milliseconds, the frames 6 and 11, the phases 0 to 2, the settings 0 to 3) are plain numbers. The case labels are numbers too (the checker's note): the two switched fields are plain ints on main, with no enum to name them.

What some placeholders hold (nothing changed here)

  • GameCore::taxesSettingUnk: 0 while no setting is animated; 1 to 3 choose ScribeAnimationFrames1 to 3. It is set by Helpers::SetTaxesSetting_unknown (0x00433560, on main), and only while it is 0. Its callers pass 1, 2 or 3 (the calls at 0x0043AA4F, 0x0043B409, 0x004460DF and 0x004460F1). The same function sets the phase to 1, scribeAnimationFrame2 to 0 and taxestimeUnk to the time. gynt's Wilps branch calls it scribeReactionType.
  • ScribeAnimationFrames1 to 3: frames 12 to 22, 23 to 33 and 34 to 44, each ended by a 0. The popularity's frames are 1 to 11, hence the > 11 in phase 2 (a comment in the code says so).
  • GameCore::scribeAnimationPhase: 0 moves the frame to 6, 1 plays the sequence, 2 moves back to the popularity's frame.
  • GameCore::scribeAnimationFrame2: the place in the sequence. GameCore::taxestimeUnk: the time of the last step (gynt's Wilps branch: scribeAnimLastTickMs).
  • GameCore::countdown: set to 1 when the frame changed or monthChanged is set.
  • GM_SIEGE_THAT: the game mode 6, as main's GameMode2.hpp names it.

Other PRs

🤖 Generated with Claude Code

InGameMenu::MenuItemActionHandler_InGameMenu_ProcessScribeAnimationChange, rewritten against the original
instructions from Gynt's draft (d5895e2 at 29.4%, the file's newest commit on his fork's reimpl/UI-MenuItems;
before it 24.6% at 668d05f, 26.74% at cee8a6a and 35.68% at 1831d14; 29.1% at 8725ec5 on his
reimpl/UI-MenuItems-development; the 24.6% text, as cf563c2, on 20 of his other branches). The rewrite was first
in our draft sourcehold#328 (85.2% at ecef1ca, 93.3% at b730ba6).
One thing in the behaviour differs from his newest copies, as the original has it: the frame's copy
(scribeAnimationFrameCopy) gets the frame after a step of phase 0 or 2, where his 29% texts (from 65a026c on)
compare and store a local that those steps do not update (the original: 0x0043352B and 0x00433545 with the stepped
value). The returns he got right himself: his 24.6% text has empty bodies for the three returns (0x00433378,
0x00433381, 0x004333AF), which he restored in cee8a6a (the 60 ms one) and 1831d14 (the game modes);
cee8a6a also returned behind every step and at a sequence's end, which he took out in 65a026c ("switch was
unreachable"), as the original has it (0x00433485, 0x0043348A, 0x0043352B). Here the returns are the original's.
The 93.3% text had the original's 129 instructions with one difference: the zero the compiler keeps in a register
was in ebp, where the original has ebx (0x0043338F), and ebx was unused. Here:
- the phase is the global itself at each use, not a local that is loaded from it and stored back. A local is one
  more candidate for a register and took one in front of the zero; with the global the compiler keeps the phase in
  edi itself (0x004333B5, 0x00433472) and the zero gets ebx;
- the frame is written the same way (a local for it gives the same listing);
- each entry of a setting's sequence is read into a local and tested (the 93.3% text read the table twice, which
  this form no longer needs);
- the phase switch's cases are in the order 0, 1, 2, as the animation runs (the same listing).

No line for cmake/compiler-flags-gl.txt: the file reads 100.0% off the /GL list, and 100.0% on it too.

reccmp in a build of main's whole /GL list (the 133 files that exist) and this file, off the list, with every
resolver of those files on: 144 functions, average 99.56. The function 100.0% raw and normalised, no differing
line, and the same with the file on the list. The other 143 functions of main's list read the same as without the
file. The sources are main's at 3458fea; main's two commits since (02fab42, 812d149) add cmake files only,
with the new option off.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant