Skip to content

Reimplement 5 UI::MenuModals and DisplayElements functions at 100% - #357

Merged
gynt merged 12 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-MenuModals-2-100
Nov 7, 2026
Merged

gynt merged 12 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-MenuModals-2-100

Conversation

@kotijekriv

@kotijekriv kotijekriv commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Five more functions at 100%, each with its status line: two UI::MenuModals renders (the new-event dialog's condition list and the tutorial box) and three UI::DisplayElements (the multiplayer lag notice, and the time-until-victory and time-until-defeat bars).

All five continue gynt's drafts on his fork, in areas he agreed on Discord (2026-11-06) we may take: the modals from reimpl/UI-MenuModals-development, the display elements from reimpl/UI-DisplayElements-pr-development (his work after the closed #249). Every commit body says what changed against the draft and why, and each credits him as co-author. No header change is left: gynt's Ghidra sync eef6f66 took the five into main, and main is merged in. Main names two of the globals INT_00df5644 and INT_00df5564, the second as an int rather than this PR's BOOLEnum; TutorialBox uses the new names (8b02cf2). Three files go into cmake/compiler-flags-gl.txt (below).

Other PRs: the ready #348, #349, #352, #353 and #354, the ready #358 (PencilRenderCore), and the drafts #313, #318, #321, #327, #328 and #356.

Built on top of main (1c29459) with the bundled MSVC1400-SP1, natively on Windows, against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), with the struct and function resolvers enabled locally (not committed), using sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie. None of it has been run in game.

It went through the same checks as #354: a fresh-eyes review of every file (behaviour compared with the original's disassembly call by call, texts against cr.tex, every header change checked with a sweep of the exe; its points applied and measured), openshc-pr-check with no errors, and status_regression.py, which finds nothing below a known score on main or any fork.

Header changes

Update: all five are on main since eef6f66, DAT_00df5564 as int INT_00df5564. Main's two users of it no longer compile there; #368 moves them to the new name. The evidence below is kept for the record.

  • GCT_UNKNOWN_99 in GameCommandType (435fbdb10): the lag notice queues command 99 (push 0x63 before queueCommand at 0x004B2587 and 0x004B2781, the exe's only two). The command table at 0x00B38E10 holds 0x00485650 at [99], which sends the 2-byte lagNotificationCode to the other players. Ghidra had rendered it as GCT_SEND_RESYNC_TILEMAPDATA2 | GCT_CHANGE_RATIONS.
  • DAT_00df5644 is an int (6627e5fbf): the tutorial's button-hint toggle. Its six accesses are the exe's only ones, all in TutorialBox; the compare after the increment is signed (jle at 0x004BCD0D / 0x004BCD15), and it's used as an index.
  • MapPropertiesState::SEC_Section1090 and SEC_Section1080 are ints (916587d45): the Win Timer's total and remaining ticks. Both are set to conditions[39].value * 800 at 0x004C3EAE / 0x004C3EB4, processSingleplayerEvents counts 1080 down behind a signed jle, loadMap clears it, and the objectives panel (0x004D7990) and the victory bar divide by 1090 with cdq; idiv.
  • DAT_00df5564 is a BOOLEnum: its three writers store 0, 1 and 0 (0x004BC728, 0x004BC770, 0x004BD2DD). Main's two users, SetTutorialHintActiveWithTimestamp and UpdateTutorialStepAndProgress, still measure 100%.
  • MapPropertiesState::SEC_Section1081 is a BOOLEnum: every store is 0 or 1 (1 at 0x004C3EC1, 0 at 0x004C3EF6, 0 in loadMap), and its readers compare it with 0.

No .cpp on main uses any of these fields.

/GL

RenderTimeUntilDefeatDisplayElement (0x004B2280) keeps the half width in edx across the first GetIfDisplayElementStateNotZero call, and the month ticks across the second, which needs LTCG. That file, GetIfDisplayElementStateNotZero.cpp and its callee FindDisplayElementWithID.cpp go into the list: with the caller alone, or with only the first callee, it stays at 79.6%; with all three it reaches 100% here, and both callees stay at 100.0%.

Class Function Address Raw Draft (gynt's fork)
MenuModals MenuModalRenderFunction_NewEvent 0x004AB790 100.0% 86.7%
MenuModals MenuModalRenderFunction_TutorialBox 0x004BCBA0 100.0% 91.6%
DisplayElements RenderSomeMultiplayerInfoUnkDisplayElement28 0x004B2530 100.0% 99.5%; his code, restyled
DisplayElements RenderTimeUntilVictoryDisplayElement 0x004B1EB0 100.0% 98.1%
DisplayElements RenderTimeUntilDefeatDisplayElement 0x004B2280 100.0% 70.9%; needs the /GL entries

None of the five changes behaviour against its draft: each did what the original does, and the changes are shape, names and types. One oddity is kept as the original has it, with a fixme line: the tutorial box's button hint passes the blend strength as keepOffsetX and 0 as the blend (push 0 / push ebx at 0x004BCE75 / 0x004BCE77).

Kept as they are, and why

Each was measured; a one-line comment in the code says why. quick_diff's baselines below 1.0 here are colour immediates and ret / ret 0.

  • TutorialBox: the body text's offset in a local (in the call: quick_diff 0.9764 -> 0.9291); the hint text read into a local and again in each arm, as the original reloads it (0.9333); a second test of the hint flag rather than an else (0.9261); width >> 1, as the original has no rounding fix (/ 2: 0.8745).
  • NewEvent: the option text in a local, read after the "(" (in the call: 0.9476 -> 0.8429).
  • Victory bar: posX becomes the bar's centre (a centre local: quick_diff 0.9810 -> 0.9620). Defeat bar: the left edge written out at each use (a left local: reccmp 100.0% -> 91.1%), and posX as the centre (a centre local: reccmp 98.5%).
  • Lag notice: gynt's nesting (early returns: quick_diff 0.9395 -> 0.6573).

Proposed, not changed here

Names only, for the Ghidra side:

  • DAT_00df5564 tutorialHintActive, INT_00df5648 tutorialHintWasActive (last frame's value), DAT_00df5644 tutorialHintIndex (0 or 1, alternating; picks button text 3 or 4 and speech 34 or 35), DAT_00df5540 tutorialTransitionMode (0, 1 or 2), DAT_00df5558 tutorialStepPage.
  • MissionAestheticsDefinedData::field_0x41e4 tutorialSpeechFileNames (char[46][3][32]), field_0x170 the opponent condition texts ("Any", "Rat", "Snake", "Pig", "Wolf").
  • MapPropertiesState::SEC_Section1090 / SEC_Section1080 / SEC_Section1081 winTimerTotalTicks / winTimerTicksLeft / winTimerActive; GameSynchronyState::lagNotificationCode is a TEXT_MULTIPLAYER_CONNECTION number (65 "Timed Out", 66 "Ejected", 67 "Back in the Game!").

gynt's other commits on these functions

Each commit body names the commits it continues. gynt has more on the same functions on his fork, and they are credited here too: his best-scoring commit on the address and his newest one on the file, where the body doesn't name them. Where one of them is at 100%, his version already matched the original, and a fix this text describes for that function was only against the earlier draft it names.

Function Address His other commits
MenuModalRenderFunction_NewEvent 0x004AB790 c6a0448 (2026-10-27, 86.68%)
MenuModalRenderFunction_TutorialBox 0x004BCBA0 e343c99 (2026-10-27, 91.59%); e9bc49c (2026-11-02, "swap if/else arms across the UI view and modal f")
RenderSomeMultiplayerInfoUnkDisplayElement28 0x004B2530 12f28d2 (2026-10-26, 99.53%); e9bc49c (2026-11-02, "swap if/else arms across the UI view and modal f")
RenderTimeUntilVictoryDisplayElement 0x004B1EB0 1d0312e (2026-10-27, 98.1%); 77f2f9f (2026-10-27, "98.07% divide before the global store")
RenderTimeUntilDefeatDisplayElement 0x004B2280 5171430 (2026-10-27, 98.5%); d2794d8 (2026-10-27, "70.94% drop the goto and a reused local")

🤖 Generated with Claude Code

kotijekriv and others added 10 commits November 7, 2026 02:51
RenderSomeMultiplayerInfoUnkDisplayElement28 (0x004B2530) queues command 99: push 0x63 before
GameSynchronyState::queueCommand at 0x004B2587 (which the lag notice 0x43 path joins from 0x004B26B0) and at
0x004B2781. These are the exe's only queueCommand calls with 99 (2 of the 11 push 0x63 in .text go to 0x00489100).
Ghidra rendered it as GCT_SEND_RESYNC_TILEMAPDATA2 | GCT_CHANGE_RATIONS (64 | 35). The command handler table at
0x00B38E10 holds, at [99], 0x00485650: it sends the 2-byte lagNotificationCode, and on the other machines stores
the code and sets DAT_SomeTime = timeGetTime(); [98] is 0x004855C0, which sets laggingPlayerIDUnk and shows
display element 28. The enum has no value 99 yet; named like its neighbour GCT_UNKNOWN_98. The values are
explicit, so nothing renumbers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tutorial's button-hint speech toggle. Its six accesses are the exe's only ones, all in
MenuModalRenderFunction_TutorialBox: reads at 0x004BCD05, 0x004BCD41, 0x004BCE14 and 0x004BCE42, writes at
0x004BCD10 and 0x004BCD17. The compare after the increment is signed (cmp eax, 1; jle at 0x004BCD0D / 0x004BCD15),
and the value is used as an index (* 96, + 3). TutorialBox is its only user on main, on this branch and in the
exe, and it drops its (int) cast with this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…f undefined4

The Win Timer's total and remaining ticks. Every access in the exe is signed: 0x004C3EAE / 0x004C3EB4 (in
0x004C35B0) set both to conditions[39].value * 800 (condition 39 is "Win Timer", text 209), right after showing
DEID_TIME_UNTIL_VICTORY at 0x004C3E87; processSingleplayerEvents (0x004C31A0) counts 1080 down at 0x004C343E-4B
behind a signed jle; loadMap (0x004C62C0) clears it at 0x004C65D0; the objectives panel's "Time Until Victory" bar
(0x004D7990) reads 1090 - 1080 at 0x004D7D1F / 0x004D7D2C with a signed jle and imul 250; cdq; idiv 1090; and
RenderTimeUntilVictoryDisplayElement (0x004B1EB0) divides by 1090 with cdq; idiv at 0x004B2060 / 0x004B2066. No
function on main uses either field; the victory timer drops its two (int) casts with this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tutorial's button-hint flag only ever holds 0 or 1. Its three writers in the exe: 0x004BC728 (= 0, ecx zeroed
at 0x004BC6FF), SetTutorialHintActiveWithTimestamp 0x004BC770 (= 1) and UpdateTutorialStepAndProgress 0x004BD2DD
(= 0); its readers test it against 0, and INT_00df5648 only ever takes its value (0x004BCDA4). BOOLEnum is a
typedef of int, so the size and every access stay the same. Main's two users, SetTutorialHintActiveWithTimestamp
and UpdateTutorialStepAndProgress, compile to the same code (measured).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Win Timer's on switch (+0x13548). Every store in the exe is 0 or 1: 1 at 0x004C3EC1 and 0 at 0x004C3EF6 (both in
0x004C35B0, which also sets the timer's ticks), and 0 in loadMap at 0x004C65D6 (ebx, zeroed at 0x004C63D7 and kept
across the calls in between). Its readers compare it with 0 (0x004C3436 in processSingleplayerEvents, 0x004C3E93,
0x004C3EE1, 0x004D7D12). No function on main uses the field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuModalRenderFunction_NewEvent, from gynt's reimpl/UI-MenuModals-development (86.7% there, after main's rename
field92_0x170 -> field_0x170). Rewritten on the struct fields: each condition is
scenarioEvents[currentEventID].data.scenario.conditions[i] (enabled, subType, value) instead of the draft's
*(char*)((int)&...data + (event * 0x39 + i) * 4 + 0xf) casts; his do-while becomes a for with continue; his reused
eventIndex local is split into conditionText and eventText, and the end's x = x + 0x9e / eventIndex = y + 0x17c
parameter reuse is passed straight into the call; the banner's group is TEXT_SCENARIO; the brackets are the
s_brace_close_005a2778 "(" and s_brace_open_005a2774 ")" pointers (the generated names have the two the wrong way
round). Comments name the text ranges (conditions 106-125 then 190 on, the four "... Acquired" conditions shown as
113, event actions 128-155 then 177 on) and the condition kinds (1 a resource, 2 a lord).

Kept forms: the option's text offset is read into a local after the "(" is drawn (in the call: quick_diff 0.9476
-> 0.8429), and the loop counter (bound countof(...conditions)) is declared before the loop, between rowsDrawn and
rowY (declared in the for: 0.9476 -> 0.9372; the original zeroes the counter first, at 0x004AB7BD). quick_diff
leaves only ret / ret 0 and the colour constant; reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuModalRenderFunction_TutorialBox, from gynt's reimpl/UI-MenuModals-development (91.6% there, after main's
renames field1248_0x41e4 -> field_0x41e4 and field1_0x4 -> field_0x4). What was left were register choices in the
text under the frame. The body text's offset is worked out into a local before its call (in the call: quick_diff
0.9764 -> 0.9291), and the button hint's text offset is read into a local for measuring and again in each arm, as
the original reloads it from memory there (in the calls: 0.9764 -> 0.9333). The hint is a second test of
DAT_00df5564, not an else (else: 0.9764 -> 0.9261); nothing in between writes it (its writers are 0x004BC728,
0x004BC770 and 0x004BD2DD). The centre is width >> 1 + x, as the original has no rounding fix (/ 2: 0.9764 ->
0.8745). quick_diff's 0.9764 is ret / ret 0, the colour constants and the cookie's slot, which reccmp ignores.

Restyled: decimal constants, no (int) cast on DAT_00df5644 (int since its header commit), truth tests for the
sound checks and for DAT_00df5564 / INT_00df5648 (0/1 only), blendStrength for the draft's keepOffsetX (it goes to
the blendStrength parameters; in the one-line hint the original passes it as renderTextToScreen's keepOffsetX and
0 as the blend, push 0 / push ebx at 0x004BCE75 / 0x004BCE77: a fixme line says so), the s__s_s_005aa800 and
s_fx_speech__005a64cc pointers for the speech file name, COL_CCFAFF / COL_C2F0EB / COL_0000FF, the plain inner
tile's own call explained, the hint's two texts and its 35-pixel height test in a comment. reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RenderSomeMultiplayerInfoUnkDisplayElement28, gynt's code from gynt's reimpl/UI-DisplayElements-pr-development
(his work after the closed sourcehold#249) (99.5% there). It measures reccmp 100.0% unchanged with both resolver sets on,
and this commit only restyles it: main's DisplayElements form (a namespace, not a class), the duplicate
UI/DisplayElements.func.hpp include dropped, decimal constants, COL_C2F0EB / COL_CCFAFF / COL_7F7F7F,
GCT_UNKNOWN_99 (added in its own commit) for the GCT_SEND_RESYNC_TILEMAPDATA2 | GCT_CHANGE_RATIONS that Ghidra
made of 99, DWORD const currentTime for _currentTime, own names for the two locals the draft reused (textY/textX
for the name, secondsLeft and buttonTextY for the eject button), BVar7 inlined into its if, truth tests for the
BOOLEnum results, line comments (the three lag notice texts "Timed Out", "Back in the Game!" and "Ejected"; the
countdown is the 60 s drop limit).

gynt's nesting stays: early returns for the DAT_SomeTime != 0 and !isHost cases measured quick_diff 0.9395 ->
0.6573 (reccmp 100.0% -> 67.3%). quick_diff is unchanged at 0.9395 (only ret / ret 0, colours and the tail-call
jumps); reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RenderTimeUntilVictoryDisplayElement, from gynt's reimpl/UI-DisplayElements-pr-development (his work after the
closed sourcehold#249) (98.1% there). The only difference was the operand order of three lea instructions: with a centre
local of its own (gynt's iVar1) MSVC writes [half + posX] where the original has [posX + half]. posX itself
becomes the bar's centre (a centre local: quick_diff 0.9810 -> 0.9620; the rest is ret / ret 0 and the colour
constant). The bar's left edge is written out at each use, as in the defeat timer (a tie with a local). Restyled
to main's DisplayElements form (a namespace, not a class) like RenderNoRushDisplayElementUnk: decimal constants
and posX -= N (the 14 offsets are (screen width - 800) / 2), barWidth and halfWidth for iVar4 and iVar3, the
xParam/yParam copies, the colour casts and the (int) casts dropped (SEC_Section1090/1080 are int since their
header commit), posX += 10 + halfWidth, COL_C2F0EB. DAT_00df4290 is this bar's width + 16, which
RenderTimeUntilDefeatDisplayElement adds to its own position. reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RenderTimeUntilDefeatDisplayElement, from gynt's reimpl/UI-DisplayElements-pr-development (his work after the
closed sourcehold#249) (70.9% there). The original keeps the half width (edx) live across the first
GetIfDisplayElementStateNotZero call and the month ticks (edx) across the second, which needs LTCG: this file,
GetIfDisplayElementStateNotZero.cpp and its callee FindDisplayElementWithID.cpp go into
cmake/compiler-flags-gl.txt. With the caller alone, or the caller and GetIfDisplayElementStateNotZero, it stays at
79.6%; all three give 91.1%, and both callees stay at 100.0%. The rest was a register rotation from a left local;
the bar's left edge is written out as posX - halfWidth at each use (a left local: reccmp 100.0% -> 91.1%). posX
becomes the bar's centre (posX += 10 + halfWidth), as in RenderTimeUntilVictoryDisplayElement (a centre local:
reccmp 100.0% -> 98.5%), and the file is restyled like that one, with deadlineTicks, elapsedMonthTicks and
ticksLeft for iVar4, iVar5 and local_c.

None of the other callers of the two callees (switchToMenuView, updateDateAndTime, MainButtons and four
DisplayElements) is in /GL, so their own code does not change: switchToMenuView reads 98.7% and MainButtons 99.8%
raw here (100.0% normalized, call targets only), and main's status lines have both at 100.0%. reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kotijekriv and others added 2 commits November 7, 2026 17:45
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…00df5644

gynt's header sync (eef6f66) renamed DAT_00df5564 to INT_00df5564 and DAT_00df5644 to INT_00df5644, both int;
this branch had typed the first a BOOLEnum (f6e4e44), and the merge before takes main's. The function only tests
INT_00df5564 for truth and copies it into INT_00df5648, so the new names are all it needs. reccmp 100.0%.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gynt
gynt added this pull request to the merge queue Nov 7, 2026
Merged via the queue into sourcehold:main with commit 2181425 Nov 7, 2026
4 checks passed
6and8 pushed a commit to 6and8/OpenSHC that referenced this pull request Nov 8, 2026
…ter the flag (sourcehold#375)

The script matched `, false` followed by `, Address::...` with exactly one space, so a resolver that clang-format
wrapped after the flag (`false,` then a line break and `Address::...`) was never flipped. 540 of main's 3,663 function
resolvers are wrapped that way. With such a callee left off, nothing hooks or calls our function, and /GL gives it
a register calling convention, which reccmp then reads low.

That is what sourcehold#357's GetIfDisplayElementStateNotZero (81.8) and RenderTimeUntilDefeatDisplayElement (54.5) showed in
a full build: their resolvers are wrapped, FindDisplayElementWithID's is not. In an alone build of the three, the
old pattern flips only FindDisplayElementWithID and reads 100.0 / 81.8 / 54.5; `\s*,\s*Address` flips all three
and reads 100.0 / 100.0 / 100.0. The batch helpers (enable_local_functions.py, common.py) already allow the line
break.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants