Repository navigation
One more UI::MenuItems function at 100%: LobbyMenu MapDesc - #464
kotijekriv wants to merge 2 commits into
Conversation
LobbyMenu::MenuItemRenderFunction_LobbyMenu_MapDesc, from Gynt's draft (de3ed4f at 56.20% on his fork's reimpl/UI-MenuItems; 26.1% at 9745a3f on his closed sourcehold#254's reimpl/UI-MenuItems, 54.84% at 3df2040 on his fork's reimpl/UI-MenuItems-development). The drafts are the decompiler's output. One behaviour fix against them: behind a description from the string table they go on and draw the map's own description text as well, where the original leaves with a tail jump to setScreenMenuSurfaceHeightRangeToResolution (0x00428965); here the function ends there too. Their map index [offset + selected - 1] is this text's [offset + selected]: in main's header the array begins one element earlier. Rewritten against the original instructions: - the box and its seven lines are a __forceinline function with the four edges as parameters, in the order (bottom, top, left, right). The original stores the right edge and the box's right edge (right - 20) where they are defined and reads them back (0x0042861F, 0x00428626, 0x00428646), keeps left - 1 in the second slot and recomputes right + 1 per line; written in the function with locals, the second value stays in a register and nothing is stored. The parameter order decides the edges' registers (top ebx, bottom ebp); four other orders differ. Plain inline is not expanded for this body (209 instructions against 288), off the /GL list and on it (39.9% in a build with the file on the list); Gynt's draft sourcehold#396 makes FunctionResolver.h's get() functions __forceinline for the same reason; - the lookup of the title and the title's draw are written in both arms of the host test: the original pushes the lookup's arguments in each arm (0x004287AB, 0x004287B3) and shares everything from the call on (0x004287BD). With the title's draw in both arms too, the compiler joins the tails itself and the scratch registers and x's register (edi) are the original's; - the title's x is written out as x - 100 at its four uses (as a local: quick_diff 0.7552); - the lookup's out-parameter is declared in each arm of the host test: at the function's scope its address stays live to the end, the frame gets a third slot and the last call is no longer a tail jump (284 instructions). 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), this file and setScreenMenuSurfaceHeightRangeToResolution.cpp (on main at 100%, not on the list; the function's tail jumps go to it), all off the list, with every resolver of those files on: 145 functions, average 99.57. The function 100.0% raw and normalised, no differing line. With the file on the list the same: 100.0% raw and normalised, no differing line. The other 143 functions of main's list read the same as without the two files. Without the callee's file in the build reccmp has no name for the target of the tail jump at 0x00428903 and reads 99.7% raw, 100.0% normalised. The builds had an earlier text of this file (other comments, another name for the helper, right - 20 written out in the lines, the out-parameter in a block around both arms); quick_diff gives the same 288 instructions, line for line, for both texts. 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>
|
|
||
| // The box, its outline and the scroll bar's column: inlined in the original, with the four edges as parameters | ||
| // in this order. Plain `inline` is not expanded for this body; written into the function the match is lost. | ||
| __forceinline static void drawDescriptionFrame(int bottom, int top, int left, int right) |
There was a problem hiding this comment.
Adding this logic into the function inside a scope with {} and creating the four parameters as locals inside the scope in parameters order does not work, I assume?
It is ok otherwise and for us, I just assume __forceinline is among the things the original very unlikely used.
There was a problem hiding this comment.
It works, with the locals in the reverse order. With the frame written into the function inside a {} scope and the four edges as locals there, in the parameters' order (bottom, top, left, right), the compiler gives the same 288 instructions but the edges get other registers (quick_diff 0.9306). Declared in the reverse order (right, left, top, bottom), the listing is the original's: quick_diff 1.0000, and a real build reads 100.0% raw and normalised, off the /GL list and on it (the on-list build still had boxRight, which gives the same listing).
So the helper and the __forceinline are gone: b6f03c1 writes the frame into the function, in a scope with int const right, left, top, bottom, and a comment says why that order. As far as we can tell, an inlined call binds its arguments from the last parameter to the first, so the helper's order turns around once the code is in the function. The braces don't change the listing (without them it is the same); they keep the four names to the frame, as you suggested. In this form the box's right edge needs no local of its own either (right - 20 written out gives the same listing), so boxRight is gone too.
Our text said that written into the function the match is lost. That was true of the forms we had tried, not of this one. The PR text is updated.
…ion, no __forceinline helper LobbyMenu::MenuItemRenderFunction_LobbyMenu_MapDesc (0x004285F0), after review: the box, its outline and the scroll bar's column are written into the function in a scope of their own, with the four edges as int const locals, in place of the __forceinline helper drawDescriptionFrame. The edges are declared right, left, top, bottom, the reverse of the helper's parameters (bottom, top, left, right): in the parameters' order the edges' registers differ (quick_diff 0.9306, the same 288 instructions); in the reverse order the listing is the original's (1.0000). The braces do not change the listing; they keep the four names to the frame. The box's right edge is written out as right - 20 (the helper needed it in a local; here it gives the same listing). The same instructions as the helper form. The function is from Gynt's draft (de3ed4f at 56.20%; his newest, 3df2040, at 54.84%), as the first commit says; this one changes only how the frame is written. reccmp, the same narrow builds as before (main's /GL list, this file and setScreenMenuSurfaceHeightRangeToResolution.cpp): 145 functions, average 99.57; the function 100.0% raw and normalised, no differing line, off the /GL list and on it (that build had the box's right edge in a local; quick_diff gives the same 288 instructions); this text itself, off the list: the same. 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>
One more function at 100%, with no header changes and no line for
cmake/compiler-flags-gl.txt. One behaviour fix against gynt's drafts: behind a description from the string table they go on and draw the map's own description text as well; here the function returns there, as the original does (below).LobbyMenu::MenuItemRenderFunction_LobbyMenu_MapDescdraws the lobby's map description: a blended box with an outline and a scroll bar column, the map's title, "Balanced" or "Unbalanced", and the description text, either the map's own or one from the string table. It is from gynt's draft on his fork'sreimpl/UI-MenuItems, and both commits credit him as co-author.LobbyMenu::MenuItemRenderFunction_LobbyMenu_MapDesc/GLlist and on itMeasured.
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie./GLlist and with 0x004314E0 (theMapEditorLandscaping_GeneralButtonshandler) left out and its resolver off, as in main's baseline: 0 failed of 2,424 compile steps, 99.58 over 2,440 functions, against 99.58 over 2,439 for main alone (built at f489b72; 3458fea only adds files undertools/, 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).MenuItemRenderFunction_LobbyMenu_MapDescreads 100.0 raw and normalised there too, with no diff entry. Every main function reads exactly what it read before (unrounded 99.5761 against 99.5759 raw, 99.5494 against 99.5492 normalised; 2,323 against 2,322 functions at 100.0 raw). The same build of the first commit, 9fc48ca, reads the same for every function, line for line./GLlist that exist on main, this file, andsetScreenMenuSurfaceHeightRangeToResolution.cpp(on main at 100% and not on the list; this function ends in tail jumps to it), all off the list: 145 functions, average 99.57. The function reads 100.0% raw and normalised, with no diff entries. The same build with the file on the list reads the same: 145 functions, average 99.57, the function 100.0% raw and normalised with no diff entries. The same build without the two files has 143 functions, and each of them reads the same. Without the callee's file in the build reccmp has no name for the target of the tail jump at 0x00428903, and the function reads 99.7% raw and 100.0% normalised with that one line. The builds had an earlier text of this file (other comments, another name for the helper,right - 20written out in the lines, and the out-parameter in a block around both arms); quick_diff gives the same 288 instructions, line for line, for that text and for the first commit's. The second commit, b6f03c1, which writes the frame into the function (see below), reads the same in the same two builds (100.0% raw and normalised off the list and on it, with no diff entries; those builds had the box's right edge in a local, and a build of this text off the list reads the same). The sources were main's at 3458fea; main's two commits since (02fab42, 812d149) add cmake files only, with the new option off.DAT_00b960f4at seven lines, and the title lookup's out-parameter at two, declared without a value; both below); our local fixer finds nothing to change.Against the drafts
gynt's drafts are the decompiler's output, and up to one point they compute what the original computes: the same box and seven lines, the same tests, the same texts at the same places.
The one point is a missing return. For a map whose description is a string table text, all of his copies draw that text and set the clip range back, then go on: they draw the map's own description text as well and set the range back a second time. The original leaves the function there. Both description texts end in a tail jump to
setScreenMenuSurfaceHeightRangeToResolution(0x00428903 for the map's own text, 0x00428965 for the string table's), and the decompiler shows the second as a plain call with the other text behind it. Here each of the two ends the function, as the original does. The copies are 9745a3f (26.1%), 3df2040 (54.84%), de3ed4f (56.20%), the 53.3% text that 20 of his fork's branches carry and the copy on reimpl/Wilps-2026-10-18 (8ca7861).The map index is the same element. His drafts read
DAT_ArrayOfMapIndices[offset + selected - 1]and this text reads[offset + selected]: in his branches' header the array begins at 0x884, behind a field of its own, and in main's at 0x880 with 501 elements. His reimpl/Wilps-2026-10-18 has the array at 0x880 as well (mapIndexList, with his note that Ghidra shows every access as[i-1]), and its copy reads[offset + selected], as this one does.What got it to 100%
The function is rewritten against the original instructions, on our dev branch (not public): 71.4%, then 100.0%. Three things in the original's listing do not come out of the plain text, and each needed its own form.
int constlocals. The original stores the right edge at its definition and reads it back from its slot at every use (0x0042861F, 0x0042866B), and it stores the box's right edge, the right edge less 20, at its definition too and reads it back for the box call (0x00428626, 0x00428646); it keeps the left edge less 1 in the second slot (0x00428672) and recomputes the right edge plus 1 for each line. With the edges declared as below, all of that comes out as the original has it.ebxand bottomebp, as the original has them (0x0042864C, 0x00428635). In the order bottom, top, left, right their registers differ (quick_diff 0.9306, the same 288 instructions). The braces do not change the listing; they keep the four names to the frame.__forceinline. The first commit had the frame as a__forceinlinehelper with the edges as parameters (bottom, top, left, right); plaininlinewas not expanded for it (209 instructions against 288, and 39.9% in a real build on the/GLlist). Written into the function, the edges match when declared in the reverse of the helper's order: as far as we can tell, an inlined call binds its arguments from the last parameter to the first. b6f03c1 does that (the review's suggestion, with the order reversed).edi.x - 100at each of its four uses. As a local the match is lost (quick_diff 0.7552).quick_diff reads 1.0000: 288 instructions against 288.
No line for
cmake/compiler-flags-gl.txt/GLlist, and 100.0% on it too (the same build with the line added). So it needs no line.cmake/function-visibility.txt(cmake: function-visibility.txt, which callers must see which callees' bodies #398) either: the manifest names neither this function nor any of its callees.Kept as they are
x - 100written out: see above. Comments in the code say why.(strength - 32) * 16 / 32 + 32for the box and* 32 / 32for the texts, written out at each use: the original computes them so (the texts' form comes back to the strength itself, the box's to half of it plus 16). A comment in the code says so.= 0the compiler adds a store that the original does not have (289 instructions against 288). Declared once at the function's scope, its address stays live to the end: the frame gets a third slot and the last call is no longer a tail jump (284 instructions), where the original ends in two tail jumps tosetScreenMenuSurfaceHeightRangeToResolution(0x00428903, 0x00428965). This is the cheat sheet's "Blocks and Scopes" note on locals whose address goes to a function. A comment in the code says so.right - 20: the original stores it at its definition and reads it back for the box call (0x00428626, 0x00428646); with the edges declared as above that comes out without a local of its own (with one, the same listing).fileNameandtitleare locals with one use each: written into the calls that use them, the match is lost (the file name: the same 288 instructions with other registers; the title: 307 instructions). A comment in the code says so.What some placeholders hold (nothing changed here)
DAT_00b960f4: subtracted from the y of every text here. gynt's reimpl/Wilps-2026-10-18 has it asmapDescScrollOffset, the scroll offset of the description; the exe refers to it in 38 places.GameCore::savedMapBalance: not zero for a map saved as unbalanced (text 412 "Unbalanced", else 411 "Balanced").TextManager::renderMultilineText5UnkandrenderMultilineTextUnk: gynt's Wilps branch has them asrenderWrappedTextandrenderWrappedTextById.Other PRs
🤖 Generated with Claude Code