Skip to content

UI: the chat dialog's buttons at 100% - #472

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

kotijekriv wants to merge 1 commit into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round48-100

Conversation

@kotijekriv

Copy link
Copy Markdown
Contributor

One function at 100%, written from the original's listing with gynt's draft beside it for the names. No header changes. One behaviour fix against every version of his draft (below).

Function Address Before reccmp raw Normalised
Chat::MenuItemActionHandler_Chat_MostButtons 0x0048F590 gynt's 59.6% 100.0% 100.0%

gynt's draft goes back to 51c5f22 (2026-10-02, "reimplement: SHC_3BB0A8C1_0x0048F590 42.22% Style pass, asm differs"). The same file is a4de844 (42.2%) on his fork's reimpl/UI-MenuItems, which is what #254 had when it closed, and it is also on sourcehold's own reimpl/UI-MenuItems. He took it further on that branch: e1c66a1 (2026-10-08, 47.09%), 8c21931 (57.57%) and ab1c46e (2026-10-11, "reimplement: SHC_3BB0A8C1_0x0048F590 59.60% Style pass, asm differs"), the best score. The newest version is 6aa5d32 (2026-11-02, "style: rule 11 across UI/MenuItems, and a scaled-pointer bug it exposed") on reimpl/UI-MenuItems-development. 19 other branches of his fork (reimpl/UI-Core-100 among them) have the 42.2% file as 637c6b0 (2026-10-06).

Measured

  • Setup: the bundled MSVC1400-SP1 against the Steam 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).
  • Narrow build: this commit's file alone, on main 0e4a83b: 100.0 raw and normalised, with no diff line.
  • Full build: an all-on build of this branch's previous cut on main 0e4a83b (the same code: this cut writes the receiver flags as TRUE / FALSE and adds comments, and compiles to the same listing), with both resolver sets on, and with 0x004314E0 (the MapEditorLandscaping_GeneralButtons handler) left out and its resolver off, as in main's baseline: 0 failed of 2,426 compile steps, 99.58 over 2,442 functions. The new function reads 100.0 raw and normalised there too, with no diff entry. Against main's baseline build (made at f489b72, 2,439 functions) the only other differences are main's own since then: One more UI::MenuModals function at 100%: ProgressBarBox #467's MenuModalRenderFunction_ProgressBarBox and UI: the single-player game launch at 100% #466's LaunchSinglePlayerGameUnk read 100.0, and Constructor_MenuModal_ProgressBarBox reads 100.0 (93.8 before One more UI::MenuModals function at 100%: ProgressBarBox #467). Every other function reads exactly what it read before (unrounded 99.5790 raw and 99.5529 normalised; 2,326 functions at 100.0 raw).
  • Instructions: the original's 147 (148 with one alignment filler, lea ecx, [ecx] at 0x0048F76D), in its order; the switch's byte table (0x0048F81C, 39 entries for the buttons 31 to 69) and jump table (0x0048F800, 7 entries) are the original's, entry for entry.
  • Checks: our local style checker gives 0 ERROR and 11 CHECK (below).
  • Not run in game.

What the function does

It handles the chat dialog's buttons. A negative button sends the next message to that one player only (all nine receiver flags cleared, that player's set), 31 to everyone, 32 to nobody (the chat menu's eight player buttons pass -1 to -8; no button of it passes 32), and 35 to the own team (the players whose team is the sender's). 33 sends the message and closes the dialog, as 34 does without sending; a message that is empty or only spaces is neither sent nor closes it. 69 opens the allies dialog, with the Genie's "Your allies" when the Genie voice is on. Whatever the button, the sender's own flag is set at the end.

Behaviour against the draft

Read block by block against every version of gynt's draft. One difference, in the send button (33), in two forms:

  • ab1c46e, 8725ec5 and 6aa5d32: the loop that skips leading spaces returns after its first pass. A message that starts with a space and is longer than one character returns at once: it is not sent, the dialog stays open, and the sender's flag is not set (a single space is handled right).
  • 51c5f22 to 637c6b0 and a4de844 (the 42.2% file, reimplement OpenSHC::UI::MenuItems (256 functions, 27 at 100%) #254's), e1c66a1, 8c21931, 9205629 and 8ca7861: the same loop has no return, so a message of spaces only runs on to its terminating zero and is sent, and the dialog closes.
  • The original (0x0048F781 to 0x0048F78B) looks for the first character other than a space: found, it sends and closes the dialog; not found, it only sets the sender's flag.

The rest does what the draft does. The draft's case 35 sets the sender's flag inside its last team test as well; that store is redundant, as the flag is set behind the switch either way.

What got it to 100%

Each of these was measured against the alternative it names:

  • One counter for all the loops. With a counter per loop, the text scan's address comes out [edx + eax] (counter first) instead of the original's [eax + edx]. Where i is declared without a value makes no difference; a fresh counter in each loop does.
  • The negative button's arm has no return of its own and ends in the sender's store behind the switch, as the cases do. With a return there, the compiler builds the constant 1 from the zero register (lea edi, [ebx + 1] where the original has mov edi, 1).
  • Its index is written buttonID < 0 ? -buttonID : buttonID. The arm already knows that the button is negative, so this compiles to the original's neg eax and an indexed store. A plain -buttonID is folded into the address (base - 4 * buttonID, five instructions instead of two), and so is the same negation in a local or through an unsigned cast. Declared in front of the clears, a local keeps the neg, but in the wrong place. abs(buttonID) puts its cdq/xor in front of the clears.
  • The cases in the original's order (35 before 33): in number order, 78 lines of the quick compile's listing differ.

Things in the file that look odd and are the original's

  • The conditional on a value the arm already knows is negative: see above; it is what the compiler needs to keep the negation as a value of its own.
  • int i; at the top, used by all six loops: see above.

Checker CHECKs (not changed)

  • 7 x SG 24 (a counter declared outside its loop): the one counter, see above.
  • SG 23 (a ternary) twice, once as the style-lint bot's: the conditional, see above (its comment says what was measured), and the line that says the style-lint bot will post that ternary once, when the PR opens.
  • 6 case labels are numbers: these are the chat dialog's button numbers, which have no enum on main (main's other chat handlers and MenuItemActionHandler_InGameMenu_MainButtons take their button numbers as numbers too). They come from the chat menu's item table (MenuItems_Chat, 0x00603108): -1 to -8 for the eight player buttons, then 31, 69, 35, 33 and 34. No button passes 32.

Proposed, not changed here

  • GameSynchronyState::DAT_ChatMessageReceiverArray holds only 0 or 1 (this function, SendMessageToPlayer's ^= 1, and the chat dialog's render function tests it as a flag), so it is written TRUE/FALSE here. The header keeps int[9]: as a BOOLEnum[9], SendMessageToPlayer's ^= 1 would not compile. Main's SendMessageToPlayer still writes = 1 to the same array and is not changed here.
  • The function's name: gynt's newer export, 8ca7861 (reimpl/Wilps-2026-10-18), names it MenuItemActionHandler_Chat_RecipientAndSendButtons.
  • The chat buttons could be a header enum: -1 to -8 the players, 31 everyone, 32 nobody, 33 send, 34 close, 35 the own team, 69 the allies dialog. None exists on main.
  • DAT_ChatTauntOrMessage is undefined4 but holds an int: 0 for the typed text (here), 1 to 20 for a taunt, and 10000 at 0x004296E9, 0x00429EC1, 0x0042A027 and 0x0042A407.

🤖 Generated with Claude Code

MenuItemActionHandler_Chat_MostButtons, the chat dialog's buttons: a negative button sends the message to that
one player only, 31 to everyone, 32 to nobody, 35 to the own team. 33 sends the message and closes the dialog,
as 34 does without sending; a message that is empty or only spaces is neither sent nor closes it. 69 opens the
allies dialog. The sender always gets the message too. Written from the original's instructions, with gynt's
draft beside it for the reads: his best is 59.60% (ab1c46e on his fork's reimpl/UI-MenuItems), the newest
6aa5d32 on reimpl/UI-MenuItems-development.

Behaviour against the draft, in every version: case 33's space-skipping loop. In ab1c46e, 8725ec5 and
6aa5d32 the loop returns after its first pass, so a message that starts with a space and is longer than one
character returns at once: it is not sent, the dialog stays open, and the sender's flag is not set. In
51c5f22 to 637c6b0 and a4de844 (the 42.2% file, sourcehold#254's), e1c66a1, 8c21931, 9205629 and
8ca7861 it has no return, so a message of spaces only is sent and the dialog closes. The original sends only
a message with a character other than a space, and sets the sender's flag either way.

The receiver flags are written TRUE / FALSE (they hold only 0 or 1). What the match needed: one counter for all
the loops (a counter per loop swaps the text scan's address registers); the negative button's arm without a
return of its own, ending in the sender's store behind the switch as the cases do (with a return there the
constant 1 is built from the 0 register); its index written as `buttonID < 0 ? -buttonID : buttonID` (a plain
-buttonID is folded into the address); the cases in the original's order (35 before 33).

Measured in a narrow build of this file on main 0e4a83b with both resolver sets on: 100.0% raw and
normalised. Not run in game.

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

Copy link
Copy Markdown

Style guide reading (advisory, posted once)

1 possible deviation(s) from REIMPLEMENTATION_STYLE_GUIDE.md across 1 of the 1 reimplemented .cpp file(s) in this PR.

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.

rule what it asks hits
23 Prefer if-else over ternary 1
Where

Rule 23 — Prefer if-else over ternary

  • src/OpenSHC/UI/MenuItems/Chat/MenuItemActionHandler_Chat_MostButtons.cpp:35 — ternary; the guide prefers extending the if-else chain

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