Repository navigation
UI: the lobby's player list render function at 100% - #446
Open
kotijekriv wants to merge 1 commit into
Open
kotijekriv wants to merge 1 commit into
kotijekriv wants to merge 1 commit into
Conversation
LobbyMenu::MenuItemRenderFunction_LobbyMenu_PlayerListAndNpcButtons, rewritten from the original's listing. gynt's draft: f0e6b48 at 56.46% ("Style pass, asm differs") on his fork's reimpl/UI-MenuItems, whose status line records 56.5%; his reimpl/UI-MenuItems-development records 56.5% too ("Reimplemented, asm differs"; the newest commits on the file there are 8725ec5, a reimplementation commit, and 5084980, a style commit). Our draft (8c967b4, then five style commits up to 07a33e2; 58.8% in the draft PR sourcehold#328) was his code with a mechanical pass. The function draws the parts of the lobby's player list, one menu item per call, chosen by the item's number: 0 the three headings; above 10 a seat's row (its group's icons, the help texts under the mouse, and text 402 for a player or the AI lord's text); 1 to 10 a seat's picture, a second one for the host's seat, and the player's or the AI lord's name; -1 to -9 a seat's button; -101 to -103 three single buttons; -200 and below a seat's button for the host. Each range ends in a return; the last three leave through RenderCurrentButtonToScreenMenuWithBlendingUnk. Seven behaviour fixes against the draft. The draft's ranges were separate ifs without an else and partly without a return, so: - For the host, after the headings (0) it ran on into the code for -1 to -9, with the seat at index 0 (visible in the draft's listing: a jmp to that code's single-player test, which returns in a single player skirmish). - After a seat's name (1 to 10) it ran on into the same code with the seat at index -button, before the array, and cleared ButtonUnknownZero again, which the original leaves set. - Above 10 it went on to the AI lord's text after a player's text, and drew it whenever the seat also had an AI type; 1 to 10 it drew the AI lord's text (for a seat without an AI lord too) and then the name. The original draws one of the two: it returns after the player's (0x00427BBE and 0x00427D65) and draws the AI lord's only for a seat that has one. - An AI lord's seat button (-1 to -9, and -200 and below) was drawn twice for the host: after the button the draft ran on to the function's last lines, which draw the current button. The original leaves through the first draw (tail jumps at 0x00427EB7 and 0x00428025). - In the last range a player's seat ran on after its button was drawn too: it then called isAIPlayer with the alpha value in place of the seat's number and could draw the button again. - -102 set ButtonUnknownZero only for someone who is not the host. The original sets it first (0x00427F0E), so for the host it stays set while another dialog is open. - -103 outside a single player skirmish set ButtonUnknownZero, cleared it again and went on to the button. The original returns with it set (0x00427F40 to 0x0042802A). The first two, the AI lord's button and -102 are in the draft's listing; the others are read from its source. What decided the match, each measured with that one thing changed (reccmp in the narrow build described below): - The two headings with an x offset take x through a local. Written in the call, x is loaded late: 96.2% (79.2% normalized). - Where two or three calls differ in one argument, each arm has its own call, and the compiler shares the call: the three help texts (their number in a local: 92.3%, 82.7%) and the two colours of a name (the colour in a local: 92.7%, 83.4%). - A player's seat button takes its picture number, 206 or 207, by if / else. As the draft's `207 - (value != 0)`: 96.2% (82.7%). - The last range is `if (isHost) { ... return; }` with the code for everyone else after it; that code is also -103's exit. With `if (!isHost) { ...; return; }` first: 96.1% (81.8%). - -101 looks for an empty seat with a flag set in the loop. With the loop's index tested after it: 96.8% (85.9%). Measured later with our own exact listing compare against the original's 604 instructions (differing lines, the final text has 0): text 402's two colours take a call in each arm too (the colour in a local and one call: 328; set by if / else: 107), and the group array is read again after the help text's call where the original reads it again (with the `group` local there: 330). These compile to the same listing, and the plainer form stands: the flag in -101 where the draft had a goto into -103's clear; the AI type switched from the field where a local would do; the two icon rows in either order; the picture number by if / else where a conditional expression would do. The text numbers carry their texts from the game's cr.tex (group 79) as comments, and the button pictures 206, 207, 626 and 627 are named from GmDataIndex. Neither changes the listing: this text compiles to the same instructions, line for line, as the text the builds below measured (the tree of 12b9d934e). Measured in a narrow build on main 3458fea of that text and the five finished functions it calls, their resolvers on: AModalDialogIsActiveButIsNotQuitting (0x00427210), renderGMWithAlphaMask (0x004557B0), renderGMWithBlending (0x00455390), isAIPlayer (0x004010B0) and RenderCurrentButtonToScreenMenuWithBlendingUnk (0x00464370), which five paths tail-call. reccmp 100.0, normalized 100.0, no diff line. Without the callees' files in the list the function reads 99.4% (100.0% normalized): the tail jumps then go to a trampoline, and four of the five read differently. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One function at 100%, moved out of our open draft #328, from gynt's draft. No header changes. Seven behaviour fixes against the draft (below).
MenuItems::LobbyMenu::MenuItemRenderFunction_LobbyMenu_PlayerListAndNpcButtonsOur draft was gynt's code with a mechanical pass; gynt's best, 56.5%, is f0e6b48 on his fork's reimpl/UI-MenuItems.
Measured
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie. The struct resolvers and the function resolvers are enabled locally (not committed).AModalDialogIsActiveButIsNotQuitting(0x00427210),renderGMWithAlphaMask(0x004557B0),renderGMWithBlending(0x00455390),isAIPlayer(0x004010B0) andRenderCurrentButtonToScreenMenuWithBlendingUnk(0x00464370), which five paths tail-call. The function reads 100.0 raw and normalised, with no diff line. The first four stay at 100.0.RenderCurrentButtonToScreenMenuWithBlendingUnkreads 16.9 in that narrow build. It is on main's/GLlist, and its own callee is not in the build. In the full build it reads 100.0, as on main.tools/). The new function reads 100.0 raw and normalised there too, with no diff entry, and no function on main moves.The behaviour fixes
The function draws one part of the lobby's player list per call, chosen by the menu item's number. The draft had the number's ranges as separate
ifs withoutelse, and some without areturn. So:-button, before the array, and clearedDAT_ButtonUnknownZeroagain, which the original leaves set. This is in the draft's listing too.isAIPlayerwith the alpha value in place of the seat's number and could draw the button again.DAT_ButtonUnknownZeroonly for someone who is not the host. The original sets it first (0x00427F0E), so for the host it stays set while another dialog is open.DAT_ButtonUnknownZero, cleared it again and went on to the button. The original returns with it set (0x00427F40 to 0x0042802A).The seat's texts, -103 and the player's seat in the last range are read from the draft's source; the others are in its listing.
What got it to 100%
The ranges are: 0 the three headings; above 10 a seat's row (its group's icons, the help texts under the mouse, "Human" or the AI lord's kind); 1 to 10 a seat's picture and the player's or the AI lord's name; -1 to -9 a seat's button; -101 to -103 three single buttons; -200 and below a seat's button for the host. The last three leave through
RenderCurrentButtonToScreenMenuWithBlendingUnk.The function is written from the original's listing now: one
ifper range, each ending in areturn, and no goto. Our draft read 573 instructions against the original's 604. What decided the match, each measured with one thing changed:if/else. As the draft's207 - (value != 0): 96.2% (82.7%).if (isHost) { … return; }, with the code for everyone else after it. That code is also -103's exit (0x0042802A). Withif (!isHost) { …; return; }first: 96.1% (81.8%).if/else: 107), and the group array is read again after the help text's call (thegrouplocal there: 330).Four choices gave the same code, and we took the plainer form: the flag in -101 where the draft had a goto, the AI type switched from the field where a local would do, the two icon rows in either order, and
if/elsefor the picture number where a conditional expression would do (main's style bot flags those).The single-change variants were built before the last two edits (the
if/elsefor the picture number, one unused include removed), which do not change the code.Things in the file that look odd and are the original's
(strength - 32) * 32 / 32 + 32at every call. The original computes it each time (shl eax, 5, then a signed division by 32); the two icon rows multiply by 22.drawBufferChoiceValueis set toRT_SCREEN_MENUtwice in a seat's row (0x00427958, 0x00427A40).groupholds it; the local there loses the match.Header findings (nothing changed here)
renderPlayerEntryInLobbyat 0x00427CB2, without a type. The address lies inside this function: it is the operand of the instruction at 0x00427CB0.TextManager::field_0x30is set to 1 before a player's name is drawn (0x00427D07).DAT_ButtonUnknownZerois TRUE here for the seats' rows and names (1 and up), for -101 without an empty seat, for -102 for someone who is not the host or behind another dialog, for -103 outside a single player skirmish, and in the last range for someone who is not the host or on their own seat; FALSE in the other cases. A lead for a name: the item takes no clicks.DAT_PlayerSlotArraySomeValue[slot]picks the other picture (206 for 207) of a player's seat button. A lead: it may be the seat's ready state.The checker's 1 CHECK
field_0x30🤖 Generated with Claude Code