Repository navigation
UI: LobbyMenu DoEveryFrame at 100%, with the gotos the match needs - #500
Conversation
LobbyMenu::MenuView_LobbyMenu_DoEveryFrame, rewritten from the binary with gynt's draft for the names (d283417 at 50.97% on his fork's development; e9e2437 at 54.19% on his reimpl/UI-MenuViews-development; 08c492b of 2026-11-02 on his reimpl/UI-MenuItems-development, his newest reimplement commit on the file). reccmp 100.0 (normalized 100.0) on main 709b429 with the data and its own function resolver on; quick_diff reads the draft 0.6142 there. The array index changed with the header. gynt's draft uses DAT_ArrayOfMapIndices[i - 1], which was right on his branch, where the array is declared at offset 0x884 and his loop's counter starts at 0. Main's sync 12854bc (2026-11-04) moved the declared start to 0x880, so the original's 0x01126E28 (0x004487E9, 0x004488B0) is element 0, and the index here ([mapCount], [index]) is one lower than in the draft. - The step to the next face is written in both arms of the loop. As one copy after the arms the count is kept on the stack and every register in the loop moves. - The two searches for a map with enough places keep three gotos, because both end in the same block. gynt on sourcehold#396 (2026-11-25): "The goto's are necessary for the match. There was no code form that could remove these goto's!" The goto-free forms measured in quick_diff, on an original of 724 instructions (0.9938 is quick_diff's ceiling on this function): gotos, as committed 723 instructions 0.9938 reccmp 100.0 a found index set before a break 730 instructions 0.9464 __forceinline helpers, early returns 740 instructions 0.9385 static or inline helpers, not inlined 688 instructions 0.9391 - The search starts from the sum of scroll offset and selection written out; a local for it swaps a mov and a cmp. - The box's positions are declared with left before right and top before bottom, after the flag is cleared: those six orders tie at 0.9938 in quick_diff and the others read lower. - RelativeSelected = -1 is stored again inside the test for -1, which the original does (0x00448950). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Style guide reading (advisory, posted once) 3 possible deviation(s) from REIMPLEMENTATION_STYLE_GUIDE.md across 1 of the 1 reimplemented The match comes first. Where the ugly form is what matched, it stays -- that is the guide's own overriding rule, and rule 21 asks for a one-line comment saying what was measured so the next reader does not retry it. This report is posted once, when the PR opens, and is not repeated on later pushes.
WhereRule 20 — Keep nesting low; no
|
|
It would be amazing if we find a solution for the goto's! |
|
Thanks for the review! We'd like that too. Here's what we tried so far: two goto-free forms of the two searches, a |
One more UI function at 100%, out of the draft #422. It is rewritten from the binary, with gynt's draft for the names.
LobbyMenu::MenuView_LobbyMenu_DoEveryFrameNo header changes in this PR.
Proposed, not changed here:
GameCommandTypehas no value for 106, so the code casts the number. I'd proposeGCT_UNKNOWN_106 = 106between 105 and 107, named like the enum's other unnamed commands. The function queues command 106 while it sends the map to the other players (push 0x6aat 0x00448642, intoqueueCommand0x00489100, whose parameter is aGameCommandType). gynt's draft writes the number asGCT_START_OR_STOP_SEND_MAP_FILEUnk | GCT_MULTIPLAYER_INITIATE_ANNOUNCE_HOST(104 | 2), which is how Ghidra printed 106. I left the header alone because that one line moves a function on main: with it, our full build readLaunchSinglePlayerGameUnk(0x0042C620, UI: the single-player game launch at 100% #466) at 99.4 raw / 83.3 normalised instead of 100.0, register allocation only (Compiler randomness: adding Enums and Typedefs causes different bytecode because of different code folding #414): oneaddof the two selection fields has eax and ecx swapped. That file includesGameCommandType.hpp, and a quick compile of it reads 0.9854 with the line and 0.9900 without, with exactly that swap. So it waits for you, if you want it in Ghidra.DAT_00b960dc,DAT_00b960f8andGameSynchronyState::lobbyMapSortOrderareundefined4, so the function casts each of them once. I'd proposeintfor all three:DAT_00b960dcis tested< 0andDAT_00b960f8>= 66, and the original compares both signed (jgeat 0x00448367,jlat 0x0044874D).lobbyMapSortOrderis only negated here (negat 0x00448977), which is the same for signed and unsigned values; the cast there only keeps MSVC from warning about a minus on an unsigned value. Main'sMenuItemActionHandler_LobbyMenu_MapSelectHeadercasts it too, to compare it< 5.LaunchSinglePlayerGameUnk,LobbyscreenStartButtonClick,MapDescScrollbarandMapSelectHeaderforDAT_00b960dc,PeasantBuildAndRightClickMenuSelectionforDAT_00b960f8, andMapSelectHeaderforlobbyMapSortOrder. I haven't measured them, so the headers are unchanged.Measured.
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie..cppand its status line. The full build of the first cut, f1fcf329c (the same function before the review fixes, with the same cast for 106), was an all-on build with both resolver sets on and main's own/GLlist, next to the same build of main 709b429 in the same clone. Seven files that don't compile on main yet were left out of both with their resolvers off:requestGoods(0x004D1F00),MenuItemActionHandler_Allies_Main(0x004B12D0),hasEnoughGoldForMoat(0x0040CAC0), and the four UnitsState files the Reimplement 47 UnitsState functions at 100% and restyle 28 more #378 sync leaves behind (getFirstSelectedUnitID,nonEuroRecruit,queueDisbandAndAttackCommand3Params,setPositionOfUnit). 0 of 2,651 compile steps failed and it linked; 99.6874 raw / 99.6551 normalised over 2,667 functions, against main's 99.6821 / 99.6462 over 2,666, and nothing read lower. Three functions went up to 100.0:Constructor_MenuView_LobbyMenu(90.0), which pushes this function's address and now resolves it, andhandleMenuItems(97.9) andConstructor_Menu(98.4), whose 0x11000000 compares main's layout prints as a symbol of our DLL.undefined4reads and command 106), the''terminator, the gotos with theirindex, and two notes on truth tests (theBOOLEnumflags are tested bare, the counts and the three-state fade value against 0). Not run in game.The three gotos
The function searches the map list twice for a map with enough places, and both searches end in the same block. On #422 I asked whether three gotos are acceptable there. gynt said the same of his own gotos on #396 (2026-11-25), about
updateGfxLayer: "The goto's are necessary for the match. There was no code form that could remove these goto's!" He marked two more there "Also not removable".These are the goto-free forms I measured, on an original of 724 instructions. Each changes only the map search, and all were compiled in one run:
foundindex, set before abreakout of each loop__forceinlinehelpers with early returnsstaticorinlinehelpers (not inlined)0.9938 is as high as quick_diff goes on this function; reccmp reads 100.0. Each goto has a one-line comment; the style bot will still post its three goto findings.
Kept for the match
DAT_MapSelectionRelativeSelected = -1is stored again inside the test for -1, as the original does (0x00448950).movand acmp.elapsed / -40: the original multiplies by 0x99999999, the constant of a division by -40 (gynt's draft shows it as* -0x66666667), so it is not written-= elapsed / 40.DAT_ArrayOfMapIndicesfrom 0x884 to 0x880, so the original's 0x01126E28 is element 0.What the placeholders hold
These are read from how the code uses them, and the names are unchanged.
DAT_00b960dc: the lobby's fade. Below 0 the lobby fades in from dark, and this sets it back to 0 at the end; above 0 it fades to dark and then ends the menu switch delay. 0 means no fade.DWORD_00b95b1c: the time the fade started. The fade's step is the time since then; this function sets it after it has read the map list again, andLaunchSinglePlayerGameUnksets it just before it setsDAT_00b960dcto 1.INT_00b960f0: the time the last part of the lobby's face bitmap was sent.DAT_00b960f8: the number of the next part to send, from 0 to 65.INT_00b960fc: the time of the last 30-second refresh of the player information.INT_00b95958: a non-host redraws the map description at that refresh only while this is 0. I don't know what it means.INT_00b95b74: probably the map description text's height. It is reset for each map that is read.DAT_00b960f4: the map description's scroll offset, reset the same way.INT_00b95f6c: 1 while the mouse is over the box of the players' faces.Out of #422
#422 keeps
MenuItemRenderFunction_OptionsMenu_Buttonsand its #414 question.🤖 Generated with Claude Code