Skip to content

Reimplement 17 rendering, UI and GameSynchronyState functions (not yet 100%) - #313

Draft
kotijekriv wants to merge 119 commits into
sourcehold:mainfrom
kotijekriv:reimpl/batch1-development
Draft

kotijekriv wants to merge 119 commits into
sourcehold:mainfrom
kotijekriv:reimpl/batch1-development

Conversation

@kotijekriv

@kotijekriv kotijekriv commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Seventeen functions I couldn't get to 100%, opened as a draft so others can continue from here. Each comes with its status line saying what's left. Twenty more started here and are at 100% now, so they left this PR: nine in #323 and four in #348 in the same push, then RenderAnimatedTutorialFloatOverlay in #409, reinitWindow in #417, RenderTextPageProgressBar in #429, activateModalDialog2 in #435, RenderStatusMenu_Population in #436, renderMinimapTileStripWithLuminescence in #465 and openBuildingStatusMenuForBuildingID in #484.

This is one of three PRs for one batch, each kept under 50 files as discussed on Discord:

Built on top of main (e086ba7, merged in ee318b7) with the bundled MSVC1400-SP1, natively on Windows, against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a). This branch was built and measured on its own (every reimplemented .cpp it contains), with the struct resolvers and the 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.

One header commit stays, for PlayerListAndNpcButtons (6fbedac). RenderGreatestLordScreen's tables got a header (7010cd2) and lost it again (a78c061): they measure better as separate arrays; see the updates below. The earlier header changes are gone: main's Ghidra sync a9401a7 took in the six colours of our shared commit (gynt's colour point on #323). This draft uses COL_C2F0EB, and names COL_FFFFFF and COL_0000FF too, where it wrote them as numbers (same code). Main 72b2732 is merged in, with the sync's new names used (DAT_RenderMap_*, INT_00ec082c, CHAR_00eb0e44, which also drops a (char) cast); every function measures what its status line records. The seven globals it retyped to int (DAT_00ed3170, DAT_00b98428, DAT_00b9842c, DAT_00b98430, DAT_00b9845c, DAT_00ed2784, DAT_CurrentButtonPictureInGm) are on main since 12854bc, and every file here that uses them compiles to the same code without its (int) casts (fb337c1).

The earlier OS.hpp change is gone: main took the calling convention in a521bf7, and after gynt's question takeScreenshot writes with the compiler's own std::ofstream, so nothing here calls basic_ofstream_write any more (74dbb76). For the record: it is VC8's operator<<(basic_ostream<char>&, char), so its second parameter is a char, not a uint.

Other changes:

Class Function Address Now What's left
AIMessageQueue playAiLordMessage 0x004B7C90 74.5% Register allocation: the original keeps the text's measured width (tested again at the end) in ebx and reads x from its stack slot; ours gives y and x the two registers and keeps the width in a slot, so the pushes and pops move with it
AlphaAndButtonSurface isMouseOnButtonImageUnk 0x004630D0 93.5% Alpha branch's pixel index is reassociated
BinkControlClass copyBinkToVideoBuffer 0x00408FC0 84.1% Reg alloc only
BuildingMenus RenderBuildingMenu_ChapelAndChurch 0x0043C1E0 87.6% (4252b19) The husband's id and the three text counters swap edx and esi, two text arms are laid out the other way round, and DAT_RenderedUnitOwner is stored behind the sprite id. The allocator ranks the three counters above the husband's id and serves them first; the original serves the id first
GameSynchronyState determineGameTicksToPerform 0x00487A30 75.6% (2a8e423) this stays in edi across the call to computeLatencyAdjustmentFromMatchTimes, where the original reuses ecx: it was built knowing that function (see below)
LobbyMenu MenuItemActionHandler_LobbyMenu_PlayerListAndNpcButtons 0x00440E50 66.9% (7a66e19) Register naming from the first test on: the original keeps activeModalDialogID in eax and buttonID in ecx, ours the other way round; the original also computes the slot index -200 - buttonID before the array read, which MSVC folds into the address for us
MinimapViewState locatePlayerKeepPositionsOnMinimap 0x004B5F70 61.1% (0822f53) Register allocation: ours keeps the row in ebp and the row's base tile in a slot, the original the other way round (by the compiler's register keys the two score 47 and 40)
Rendering BlitMapImageWithVerticalClipAndYOffset 0x00454080 86.3% The C++ part before the asm keeps its values in other registers; the asm matches
Rendering RenderGreatestLordScreen 0x004D5810 59.8% (11aa0bf) The frame is 4 bytes larger; ours keeps 0 in esi across the kill loop and saves esi and edi at the start; the original keeps the icons' y in ebx and reloads x; the sort's current and next swap ecx and eax
Rendering RenderMissionObjectivesUnk 0x004D76A0 70.6% (0d98ae6) y and the text width swap esi and edi (offset's register key is above y's); the original subtracts 9 from y at the win timer and offsets its uses
StatusMenus RenderStatusMenu_Army 0x00447FA0 49.7% (ced54a4) Register allocation: ours keeps the constant 1 in ebx (the counter's increment and the bonus line's TRUEs) where the original keeps 0 there
StatusMenus RenderStatusMenu_Food 0x0043FAC0 86.8% (27225f8) In the loop body the player index, y and the stock sit in ecx, eax and edx in the original, in edx, ecx and eax in ours
StatusMenus RenderStatusMenu_Popularity 0x0043E6C0 99.3% (bfbd2a2) In three of the event lines' percentages the two operands of the lea that adds the layout and the menu position come the other way round ([edx + eax - 0x1] against ours [eax + edx - 0x1]); the argument written in either order, or through locals, gives the same
WindowAndDirectDraw bltMapGameSurfaceToScreen 0x004706E0 82.1% (a21b439) The original stores the destination's right and bottom once, after both branches (right in eax, bottom in ecx); ours stores them in each branch
WindowAndDirectDraw prepareWindowAndDDraw_2Unk 0x004729B0 79.1% Callee-saved register swap only
WindowAndDirectDraw renderBltAndFlip 0x00470040 57.2% The original keeps 0 in ebp throughout and request in its stack slot; ours gives request ebp, keeps no 0 in a register and later keeps 2 in ebx
WindowAndDirectDraw takeScreenshot 0x00479540 86.4% Library calls reccmp can't map; reg rotation

determineGameTicksToPerform measures 75.6% now (it was 69.4%; the same with the file on the /GL list, as in this draft, and off it). The original reads this->ticksBehindFastestPlayer through ecx right after calling computeLatencyAdjustmentFromMatchTimes (0x0047E5B0; the read is at 0x00487A9A), so it was compiled knowing that the callee leaves ecx alone, as /GL does. Ours calls the original through its resolver and keeps this in edi across the call. With a 96.4% draft of the callee compiled into the same file and its resolver on, quick_diff gives the original's listing: 1.0000, its 182 instructions. So this function can reach 100% once the callee does and both files are on the /GL list. The callee is 0% on main; what keeps that draft at 96.4% is that MSVC keeps mapTimeInTicksSinglePlayer in a register after the loop, where the original reads it again.

Update (2026-11-25)

  • locatePlayerKeepPositionsOnMinimap rises from 55.9% to 61.1% (0822f53, 59.1% normalised, in a narrow build on this branch). The row parity's other value is read from the viewport's height on its own: as viewportHeight + 1 from the local, the compiler recomputes it in every row, where the original keeps it in a stack slot of its own. Now it does too, and the frame is the original's size.

  • RenderStatusMenu_Army rises from 40.2% to 49.7% (17958ed at 43.2%, ced54a4 at 49.7%, 50.1% normalised, in narrow builds on this branch). The panel's top is read from the menu's y on its own: computed from the y local, the compiler folds it into every use as y plus a constant and keeps y in a register for the whole function. Then the fear-factor part draws its line at a y of its own (textY = top + 25): with its eight uses on the top, the top's register key was above the loop's stepped values, so ours kept it in a register through the loop. Now the top is in its stack slot and the loop's i * 46 in a register, as in the original.

  • RenderGreatestLordScreen rises from 59.1% to 59.8% (11aa0bf, 59.5% normalised, in a narrow build on this branch). The tables are separate arrays again, in the original's frame order: as one struct, the date written into the statistic orders takes the address of every table, so the compiler reads the star count again in each pass of the star loop and saves the callee-saved registers at the start. As separate arrays only the statistic orders have their address taken, and the star loop counts down from one read, as in the original. The icons' y is computed in each row from the row's y, and the sort compares the losses and the buildings lost as current > next, as the original does. (d924f3e measured separate arrays 1.5 points below the struct; with the icons' y per row they now measure 0.7 above it.)

  • RenderMissionObjectivesUnk rises from 58.2% to 70.6% (0d98ae6, 67.4% normalised, in a narrow build on this branch). Builder mode's page height starts from the visible height in a value of its own: rounded in place, its register key (the score the allocator serves the callee-saved registers by) was above y's, so y and the first pass's counter took other registers than the original's for the whole function. The two passes share one counter, the declarations follow the original's stores, and the map name is read before the call that draws it.

  • GreatestLordTablesUnk gets a header of its own (7010cd2), as gynt asks on Audio: match playRandomBackgroundMusicUnk (100%), improve updateAmbie… #488 ("When declaring new types, create new .hpp files, don't hide them in .cpp files!"), and RenderGreatestLordScreen takes it from there (1f6ca71). Same code: quick_diff 0.5369 before and after, 59.1% raw in a narrow build. Dropped again in a78c061: see the RenderGreatestLordScreen entry above.

  • RenderStatusMenu_Popularity's comments (a4445fb): the ale chain is a ladder, the counters' comment names the next free row, and the rations' try is in backticks. The listing is the same.

Header changes (7010cd2, dropped again in a78c061)

UI/Rendering/GreatestLordTablesUnk.hpp came and went. It held the tables behind the Greatest Lord screen, one entry per player slot (index 0 unused), points, stars, overallOrder, kills and losses (9 ints each) and statOrder[16][9], 0x2F4 bytes. They are RenderGreatestLordScreen's locals: the original keeps them in one block of its stack frame and fills the statistic orders with one strided loop, which is why they were one struct. As separate arrays they measure better (59.1% to 59.8% raw): as one struct, the date the screen writes into the statistic orders takes the address of every table. No header is left for them.

Update (2026-11-24, later)

  • RenderStatusMenu_Popularity joins this draft (bfbd2a2): 99.3% raw, 92.0% normalised, in a narrow build on this branch. It comes from gynt's draft (5a9a253 at 48.63%, 218a0c0, ca6119f at 59.7%, his newest 08c492b, on his fork's reimpl/UI-StatusMenus-development) and is rewritten section by section from the listing, on main's names. What made the difference: the report keeps one running total, which the event sum starts and each section adds to right after its percentage is drawn (add ebp, esi); each section has a value of its own; the rows of the active events are an array in counting order, as the original keeps them side by side in its frame (as seven locals they take other slots and the registers rotate after the count: 0.8616 against 0.8895 in quick_diff); every text's y and x go through locals, y first, as the original reads them; and the thresholds are written as the original compares them (<=). The rations and the taxes stay one compare per value and the ale a ladder, each with a comment: (rations - 2) * 100, a switch on the taxes and aleCoverage / 25 * 50 all lose the match.
  • The six section values and the rows are declared without a value (SG 24): each value is set in every arm of its if / else chain, and a row only for an active event, which is the only one read.
  • Open questions there: ownsChurchUnk and ownsCathedralUnk are tested != 0, as the original does; whether they only ever hold 0 or 1 (a BOOLEnum) is not shown yet. For a rations value outside 0 to 4 the original reads the fire row as the food value, which is indeterminate unless a fire is active; it is kept, with a fixme.
  • For whoever continues: a row pointer (int const* const layout = DAT_PopularityMessageLayout::instance[eventRows[i]];) in the six event lines with a value reads 99.8%; only the lions line's two leas stay swapped. It is not in this draft: a pointer in six of the seven blocks, only for the code it gives, costs more in review than the half point.

Update (2026-11-24)

  • MenuItemActionHandler_LobbyMenu_PlayerListAndNpcButtons joins this draft (7a66e19): 66.9% raw, 62.0% normalised, in a narrow build on main. It comes from gynt's draft (efd2c3f, 49.29%, on his fork's reimpl/UI-MenuItems) and is rewritten from the binary. All 148 instructions are there; what is left is in its row. The slot is read as a char and copied to the player ID: a single int tested with < 1 drops the original's byte test (147 instructions). Main 0268112 is merged in first (af9b9d8) for the generated headers the function uses.

Header changes (6fbedac, a commit of its own)

  • GameCommandType: GCT_UNKNOWN_85 = 85, between 84 and 86. The round table's slot button queues command 0x55 (push 0x55 at 0x0044104A, into queueCommand 0x00489100, whose parameter is a GameCommandType). It looks like the host's request to a human player's slot: the slot stays pending in slotActionPending until removePlayerFromLobby clears it.
  • SoundEffectID: SEID_UNKNOWN_0x60 = 96, between 92 and 97. The same branch schedules sound effect 0x60 (push 0x60 at 0x0044105E, into scheduleSFXVariation 0x00449D50, which indexes the sound structures with it, as ChooseRandomNumberOfEnemies_Main does with SEID_UNKNOWN_0x79).
  • SoundEffectID: SEID_UNKNOWN_0xFC = 252, between 0xFB and 0xFD. The random-enemies button sets up sound effect 0xFC (push 0xfc at 0x00440FD1, into setUpSFXToPlayUnk 0x00449C40, whose parameter is a SoundEffectID).

SoundEffectID numbers its values as DE's eSFX does (DE/SHCDE/eSFX.hpp: SEID_WOOD_CHOP = FX_CHOP = 2, SEID_UNKNOWN_0x104 = FX_EXTREME_TROOPS_CLICK = 260). eSFX names 96 FX_ARMOUR_HIT and 252 FX_DICE (the random-enemies dialog's dice), which confirms the two values; SEID_DICE is an option if wanted. All three are named like their unknown neighbours and stay here until main's generated headers have them.

Update (2026-11-23, later)

  • openBuildingStatusMenuForBuildingID is at 100% and left this PR for UI: openBuildingStatusMenuForBuildingID at 100%, out of the draft #313 #484. The countdown call's 1 is the barracks' menu tab: with the tab declared without a value and its 1 set in the barracks' arm (the one arm of the second switch that kept the initial value), the 1 stays in esi and the call pushes esi, as in the original. Its file leaves this draft (3510e11) and its status line goes back to main's. The reading in the 2026-11-23 section below (constant reuse, no source form) does not hold for this function.

Update (2026-11-23)

  • determineGameTicksToPerform: 69.4% to 75.6% (2a8e423). Each change comes from the original's listing. The game speed is read into a local at the top, 40 when it is 0, as the original keeps it in esi from its fourth instruction on. The single-player arm no longer copies this->relativeTickTime into DAT_GameSynchronyState::instance: the original's arm (0x00487B1D) stores only mapTimeInTicksSinglePlayer. The tick duration is one if-else chain, so the copy of the result sits at the join (0x00487B51). The carry is added into DAT_MillisecCarry::instance and read back from it (0x00487B59). The commit cites gynt's 97f46eb, 1ef7e0e and 6cbbfc2, and credits him as co-author. What is left is in the paragraph under the table.
  • Two status lines give their reason now. openBuildingStatusMenuForBuildingID stays at 86.1% (bf88fea): the pushed 1 is the constant-reuse case that tools/compiler-internals/msvc-backend.md describes in "A defect class: which constant gets the callee-saved register". playAiLordMessage stays at 74.5% (b098102): MSVC's allocator ranks y and x above the text's width, and the original keeps the width in a register. Fourteen source forms gave the same listing or a worse one.
  • Tried again, no change, nothing committed:
    • RenderBuildingMenu_ChapelAndChurch: the counters and the husband's id are one rank apart in the allocator. Six forms (the counters spelled out, the wife's type as a local, only one of the two id locals, the two wedding-off checks swapped, the switch as an if-else chain) are no better.
    • renderBltAndFlip: reading request through a local and storing it back, the frame time difference as a local before the test, and the menu bar test's second compare against its first operand. None keeps a 0 in ebp.
    • locatePlayerKeepPositionsOnMinimap: viewportHeight + 1 as a const local gives the same listing.
    • RenderStatusMenu_Army: reading the top from DAT_MenuHandlerState::instance.y keeps it as its own value, but in a register; the loop's allocation stays the other way round.
    • RenderMissionObjectivesUnk: all 120 declaration orders of its first five locals read within 0.3 points of each other.
    • isMouseOnButtonImageUnk: the original computes the two offsets as values before the draw-buffer store and adds width * dy + dx; ours folds dx into the sum. Six forms of the index are no better.
    • bltMapGameSurfaceToScreen: three forms. Right and bottom set in both branches and stored once after them, as at the original's join (its 83 instructions, but a lower score); the windowed branch's four edges as locals, in all 24 orders; right and bottom as one POINT. Right and bottom keep their eax and ecx swap.
    • BlitMapImageWithVerticalClipAndYOffset: computing the draw y as the original does, with the skip counter declared after the next-skip one, gives the original's frame stores and load order; the C++ part's registers still differ.
    • copyBinkToVideoBuffer: the loop body as a helper in all six parameter orders; the three callee-saved values (0, 1, this) still rotate.
    • prepareWindowAndDDraw_2Unk and RenderStatusMenu_Food: three and four forms; the swap and the loop body's rotation stay.

Update (2026-11-22)

Update (2026-11-20)

  • activateModalDialog2 (0x004B2820) is at 100% and moves to UI: three more functions at 100%: the building menu's DoInitial, the credits' prepare and activateModalDialog2 #435 (2c68bde). Its file leaves this draft and its status line goes back to main's.
  • One more draft improved: locatePlayerKeepPositionsOnMinimap, 48.2% to 55.9% raw (54.8% normalised), in 5a6f690. The keep test reads the building type into an int local and tests the range on it, which gives the original's one-compare range check (add edx, -0x28; cmp edx, 4; ja); on the short field MSVC compared the 16-bit value twice. Measured on 5a6f690's tree, in a narrow build with the struct resolvers and the function's own resolver on. The draft started from gynt's version; the commit cites it and credits him as co-author.
  • RenderStatusMenu_Population (0x0043F6A0) is at 100% and moves to UI: the population report's graph at 100% #436 (da64dd7). Its file leaves this draft and its status line goes back to main's.
  • RenderBuildingMenu_ChapelAndChurch has a clean text now (4252b19): the decompiler's temporaries are gone, with three using lines and two includes it no longer needs, and it compiles to the same code (87.6% raw, 81.9% normalised, in a narrow build on main 3458fea in which this file and Reimplement 3 UI::MenuItems functions from gynt's drafts (not yet 100%) #328's ProcessScribeAnimationChange were built together, with the struct resolvers and the two functions' own resolvers on). The commit body lists what the original's listing shows about the differences that are left, and what was tried.

Update (2026-11-19)

  • RenderTextPageProgressBar (0x004DAFB0) is at 100% and moves to UI: the text page's progress bar and the round table at 100% #429 (cab19bf). Its file leaves this draft and its status line goes back to main's.
  • Three drafts improved. Each number was measured on 27225f8's tree, with the struct resolvers and the three functions' own resolvers on (a narrow build of the three files). Each file is unchanged since the commit that improved it. All three drafts started from gynt's versions; each commit cites them and credits him as co-author.
Function Commit Before Now (raw / normalised) What changed
openBuildingStatusMenuForBuildingID cb62724 72.1% 86.1% / 63.8% The second switch's case order now matches the original's block layout. case BT_STATUE (menu tab 89) sits between the dog cage and the shrine, and case BT_SIEGETOWER_PLACED just before the barracks. The original folds both into earlier copies of the same code, and with the statue case last MSVC kept the later copy instead
bltMapGameSurfaceToScreen a21b439 71.5% 82.1% / 76.9% The windowed branch computes the destination rectangle from the parameters (clientLeft - cameraX + windowedX - 32), not from the source rectangle's fields, and stores it right, left, top, bottom
RenderStatusMenu_Food 27225f8 85.3% 86.8% / 73.5% The four stocks' x is its own induction variable (int x = left + 12; ... x += 80;), which gives the original's setup order before the loop

Review round (2026-11-04)

The points from the review of #311 are applied here too, in every file: no findings in code comments, string pointers from string-literals.hpp, decimal numbers (hex only for bit operations), the ColorsEnum names for the text colours, compound assignments and prefix ++/--, truthiness tests, first includes ../<Folder>.func.hpp, no unused usings, declarations at first use, the strcpy deprecation pragma. Also: prepareWindowAndDDraw_2Unk lost a (void*)((int)...) cast, and copyBinkToVideoBuffer and renderBltAndFlip have named parameters. Every change compiles to the same code as before, except determineGameTicksToPerform, which went from 68.3% to 69.4%.

Kept on purpose:

  • determineGameTicksToPerform, bltMapGameSurfaceToScreen and renderBltAndFlip compare currentlyInGameUnk_0xa4 and NOTSelfBufferOrWindowMode_0xf8 with TRUE, because the original compares with 1. A truthiness test measures 69.4% -> 43.1% for determineGameTicksToPerform, and for bltMapGameSurfaceToScreen 82.1% -> 79.8% raw (76.9% -> 79.5% normalised; re-measured on 27225f8's tree).

Open for others to continue

  • The __asm blitters (renderFunctionResponsibleForManyGameObjects, RenderTerrainTilesCenterPiece, ApplyBlending, BlitMapImageWithVerticalClip, renderMinimapPreview) are at 100% in Reimplement 13 functions from our drafts at 100% #323: inline asm can name a resolver global after all, once the C++ has used it (Reimplement 13 functions from our drafts at 100% #323 explains how).
  • BlitMapImageWithVerticalClipAndYOffset (86.3%) stays here. Its asm ended with a pop ebx that has no push in our build (in the original the pop is the compiler's own epilogue), so it popped ebx twice and returned with the caller's esi, edi and ebx wrong. That is fixed (79.7% to 86.3%; BlitMapImageWithVerticalClip had the same bug). The asm matches now; the C++ part before it keeps its values in other registers.
  • takeScreenshot (86.4%): it uses the compiler's own std::ofstream throughout now, as gynt asked: the file object and every byte write (file << c). reccmp can't map the calls into our copy of the library to the game's statically linked copy (constructor, destructor, operator<<, and _free for the path string), so raw drops from 88.2% to 86.4% while normalized rises from 89.9% to 91.4%. The rest is a register rotation and the addresses of the inline-copied file name strings.
  • copyBinkToVideoBuffer (84.1%): the instructions match; only the callee-saved registers holding 0, 1 and this rotate. It's the first .cpp to call DirectDraw through ddraw.h's C++ interface (surface->Lock(...)); happy to change that if you prefer another form.
  • Most of the rest is register allocation or scheduling, as each status line says. RenderStatusMenu_Army (40.2%) is the furthest off.

Not included, because my versions didn't beat gynt's drafts:

  • StatusMenus: Overview 85.0, Popularity 65.0, Chimp 56.7;
  • BuildingMenus: Marketplace_Trade 99.0, Armory 80.6, Keep 66.7;
  • UI-Core: generateMinimapImage 74.7, convertLoadedMinimapColors 63.6, drawMinimap 32.8;
  • several GameSynchronyState functions between 35.9 and 97.4.

🤖 Generated with Claude Code

kotijekriv and others added 30 commits November 3, 2026 19:41
…s; own handler tables

The TGX blitter: C++ around the two handwritten __asm blocks transcribed from the binary.
All seven locals sit in the original's frame slots (names and declaration order both
matter in this unoptimised function). Left: the asm reads currentRenderSurface through
`this` (inline asm cannot name a resolver global), and the handler tables are our own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It was listed before the file existed. With resolvers on, takeScreenshot measures 37.1% with
/GL and 85.4% without: LTCG gives our STL instantiations custom calling conventions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Plain std::ofstream lines up with the game's statically linked VC8 STL; the call and vtable
targets differ. Also left: volatile register choice in the byte-writing loops, and one ecx
reload before copyData that only goes away with fillMemory.cpp in the same translation unit.
Needs src/OpenSHC/IO/ResourceManager/paths.cpp in the build list (direct call).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Same instructions as the original; only the callee-saved registers holding 0, 1 and `this`
rotate. Their use counts already match the original's (25, 10, 7).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Its body is VC8's operator<<(basic_ostream<char>&, char): the callers clean the stack
(add esp, 8), and the second argument is the character. Declared __stdcall with a uint,
every call through the resolver would have leaked 8 bytes of stack. No other file calls it.

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

The bytes now go through the game's own operator<< (OS::basic_ofstream_write) via its
resolver, as in the original: 85.4 -> 87.1% (data resolvers on); the five calls match.
The stream object is still our library's std::ofstream (same VC8 layout). Left: the
inlined parts of the game's ofstream constructor/destructor (vtables, _Stinit, close),
volatile register choice in the byte loops, one ecx reload before copyData.

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

WindowAndDirectDraw::prepareWindowAndDDraw_2Unk, from gynt's version on his fork's
reimpl/UI-Rendering-development (66.7%). The retry is a plain while loop that falls
back to 800x600 once and otherwise posts the close message, the saved blit mode is
scoped to the first if, and pendingMenuRedraw is written through the global
instance as in the original. The instructions now match; only edi and ebx (the
constant 1 and the saved blit mode) are swapped. Loading the saved mode before the
if gives the original's registers but moves the load (74.6%).

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

WindowAndDirectDraw::reinitWindow, from gynt's version on his fork's
reimpl/UI-Rendering-development (58.6%). The fullscreen check reads the global
instance as the original does, and the fullscreen branch returns after SetFocus
instead of falling through to the client-rect code. What's left is only which of
eax/ecx/edx each windowHandle reload uses; if/else, nested and early-return shapes
all tie.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…gisters in the windowed branch

WindowAndDirectDraw::bltMapGameSurfaceToScreen, from gynt's version on his fork's
reimpl/UI-Rendering-development (55.6%). Early returns, a cameraOffsetX local (the
original keeps it in ebp, loaded before the windowed/fullscreen branch, with zero
in edi), and the destination rect written as the source rect shifted by the
client origin minus the camera. What's left is the order of the windowed branch's
arithmetic and which scratch registers it uses: the original computes right and
bottom into eax/ecx so both branches share the last two stores. Without the
local those stores merge but zero moves to ebp (56.8%).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…am_1 takes the register instead

WindowAndDirectDraw::renderBltAndFlip, rewritten from gynt's version on his fork's
reimpl/UI-Rendering-development (46.5%). The menu overlay block (modes 2, 3 and 4)
appears twice in the original, word for word, after the map blit and after the
flip, so it's a static __forceinline helper here. The overlay test, the
resolution and the final pendingBltMode reset go through the global instance, as
in the original; the fullscreen path BltFasts to &clientOnScreenCoords, and the
flag is a BOOL (a dword 0/1 in the original). What's left is register allocation:
the original keeps zero in ebp and leaves param_1 in its stack slot, ours gives
param_1 ebp and uses immediate zeros, which shifts much of the function.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…x is reassociated

AlphaAndButtonSurface::isMouseOnButtonImageUnk, from gynt's version on his fork's
reimpl/UI-BuildingMenus-100 (65.4%). The picture number is compared signed, the
image index is computed once for the width and height reads, and the magenta
tests are 16-bit (ushort) compares as in the original. In the alpha branch the
original computes mouseX - ButtonX on its own and adds it to width * y; ours
folds it into width * y - ButtonX + mouseX. Locals, int casts, a row pointer and
computing it before the global store all compile the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…offsets around the statue case

AlphaAndButtonSurface::openBuildingStatusMenuForBuildingID, restructured from gynt's
version on his fork's reimpl/UI-Rendering-development (55.0%). The original tests
someone else's building first (statue, then a switch that only selects most
types and lets allied walls and towers and editor outposts through), falls into
the owner path, and lays out the owner switch's cases in its own order (roughly
by menu tab), which is reproduced here; the two early returns are separate ifs.
The building field is field203_0x2c6 on main (field241_0x2c6 on the branch).
What's left: the original keeps the 0x59 statue block in the visitor branch and
the owner STATUE case jumps back to it; ours keeps it in the owner switch, which
shifts the jump offsets after it.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The second bar and the blit only run outside an in-game menu (if/else in the original).

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The message only closes once its video or speech has finished: the draft had empty ifs where the original returns.

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

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

Rewritten from the asm: the decompiler had split the ranking tables into ~20 overlapping arrays and the draft's init loop wrote past the end of one of them. Left: the frame is 8 bytes larger (iconY and the player index are spilled where the original keeps them in ebx/esi), which shifts every stack offset. Separate arrays (points, stars, overallOrder + one block for kills, losses and the 16 orders) put every array in the original's slot and raise the normalized match, but measured 1.5 points lower raw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from the asm with both passes, the two progress bars and the builder-mode description as the original has them. Left: register assignment (loop index, y and the number width sit in different callee-saved registers), which renames most of the function.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The four pixel loops (555/565, normal/zoomed out) are handwritten assembly in the original and are transcribed from the binary; the setup stays C++ and the locals are declared so they land in the original's frame slots. Left: the setup loads the row and the image pointer into other registers, and the asm reaches surfacePointer_mapGame, DrawSomeX and unknownSpecificPointer through two static pointers (inline asm cannot name a resolver global), two extra instructions per loop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The two copy loops (normal and zoomed out) are handwritten assembly in the original and are transcribed from the binary; the clipping stays C++, with the locals in the original's frame slots. The draft fell through an empty if where the original returns when there are no rows. Left: ebx is pushed in the prologue where the original pushes it after the early return, and the asm reaches four globals through static pointers (inline asm cannot name a resolver global).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The two copy loops are handwritten assembly in the original and are transcribed from the binary; the clipping stays C++, with the locals in the original's frame slots. The draft fell through an empty if where the original returns when there are no rows. Left: the clipping prologue holds the row count, skip and next skip in other registers (esi/ecx/edx rotated), and the asm reaches four globals through static pointers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The copies are handwritten assembly in the original and are transcribed from the binary; the range check stays C++, with drawY and source in the original's frame slots. Left: the asm reaches surfacePointer_mapGame, DrawSomeX and unknownSpecificPointer through two static pointers (inline asm cannot name a resolver global), two extra instructions per path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main renamed the global GMTotalPicturesProcessed (same address, int[240]) to GMFirstPictureIndex in 0d1fdb6,
so RenderGoldValue no longer compiled on this branch's base.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
playAiLordMessage's param_1/param_2 are x/y; RenderAnimatedTutorialFloatOverlay's are x/y too, its offset local and
goto labels are named and '+ -N' is '- N' (rule 15); its imported comment is a short // note. RenderGoldValue's two
colour ternaries are if/else (rule 23). RenderGreatestLordScreen declares one more variable at first use (rule 24).
Measured: no function changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DAT_SomeTextArrayIndex is written through the global instance, as the original does. Left: two stores of the dialog stack push are scheduled after the activateModalDialog arguments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The original only clears the other dialogs when there is no previous dialog to return to; the draft called clearAnyOtherModalDialogs every time. Left: one store of the dialog stack shift is scheduled after the compare.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The original returns after converting the click; the draft fell through and always wrote -1 to both outputs. The row is read with a short cast (movsx). Left: the tileX pointer and the orientation offset sit in swapped callee-saved registers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The copy loop is handwritten assembly in the original (mov reg, 0 and mul), transcribed into __asm. Left: inline asm cannot name a resolver global, so the pencil surface is reached through a static pointer (two extra instructions).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kotijekriv kotijekriv changed the title Reimplement 17 rendering, UI and GameSynchronyState functions (not yet 100%) Reimplement 16 rendering, UI and GameSynchronyState functions (not yet 100%) Nov 22, 2026
kotijekriv and others added 4 commits November 23, 2026 02:11
….1%, with the reason

Its one differing instruction is the second argument of the extendResourceCountdownForPlayerBuildingsOfType call:
the original pushes esi, which holds the menu tab's initial 1 on every path to the call (the statue's 0x59 jumps
past it, 0x0046335A), and ours pushes the immediate 1. The 1 in esi is used for the later compares in both. Writing
menuTab as the argument, assigning its 1 in each arm of the owner test, or typing the constant as 1u or (dword)1
does not change it: constant propagation replaces the variable before register allocation, the class
tools/compiler-internals/msvc-backend.md describes under "A defect class: which constant gets the callee-saved
register". Only the status line changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What is left is the allocation of three values. The original keeps the message's measured width (the second
measure, tested again at the end) in ebx, spills it only around the speaker's name block, keeps y in ebp and reads
x from its stack slot each time. Ours gives y ebx and x ebp, and keeps the width in a stack slot throughout, so the
pushes and pops move with it (218 instructions against 215). The compiler's own candidate keys for ours, read
with reg_scores.py: y 170, x 92, the width 67, so the width is served after both. Fourteen source forms give the
same listing or a worse one: the width declared first, at function scope, before `now` or initialised; the height
declared in each arm; both as one SIZE local (worse); the name's measures at function scope or sharing the text's
height; the name's left edge as a local; the text's top edge summed in another order; and four spellings of the
face's top edge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e its callee is known, as under /GL

The draft is Gynt's (his 97f46eb at 64.7%, 1ef7e0e at 18.78%, and 6cbbfc2, which flipped comparisons in
it) with our style commits. Four changes against it, each read from the original's listing. The game speed is read
into a local at the top, 40 when it is 0, as the original keeps it in esi from its fourth instruction on; the
single-player arm keeps that value and the multiplayer arm sets it from the skirmish speed. The single-player arm
no longer copies this->relativeTickTime into DAT_GameSynchronyState::instance: the original's arm (0x00487B1D)
stores only mapTimeInTicksSinglePlayer, and the multiplayer arm's stores are the original's own, so the local that
carried the value to the join is gone. The tick duration is one if-else chain whose arms each assign it once (the
draft divided the assigned value again), so the copy of the result sits at the join (0x00487B51) and not in both
paths. The carry is summed into DAT_MillisecCarry::instance and read back from it, so it is loaded before the
stopwatch's difference is added (0x00487B59), as in the original.

What is left is the call. The original reads this->ticksBehindFastestPlayer through ecx right after calling
computeLatencyAdjustmentFromMatchTimes (0x00487A9A), so it was built knowing that function leaves ecx alone, as /GL
does; ours calls the original through its resolver and keeps this in edi across the call. quick_diff: 0.8000 (178
instructions against 182) with the callee proxied; with a draft of the callee (96.4%) compiled into the same unit
and its resolver on, 1.0000, the original's 182 instructions. Real build off the /GL list, the callee proxied:
75.6% (the draft read 69.4%).

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AlphaAndButtonSurface::openBuildingStatusMenuForBuildingID (0x00463310) reaches reccmp 100.0 (normalized 100.0) on
main 0e4a83b and goes out with a ready PR of its own. Its file leaves this draft and its status line goes back
to main's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kotijekriv kotijekriv changed the title Reimplement 16 rendering, UI and GameSynchronyState functions (not yet 100%) Reimplement 15 rendering, UI and GameSynchronyState functions (not yet 100%) Nov 23, 2026
gynt added a commit to kotijekriv/OpenSHC that referenced this pull request Nov 24, 2026
…credits' prepare and activateModalDialog2 (sourcehold#435)

* reimplement: SHC_3BB0A8C1_0x004398B0 100.0% Reimplemented

BuildingAndStatusMenu::MenuView_BuildingAndStatusMenu_DoInitial, from gynt's draft on his fork's
reimpl/UI-MenuViews-development (his newest scored commit on the file is 24a37e8 at 96.23%; the newest commit on
the file, e9bc49c, is on his reimpl/UI-MenuItems-development), through our draft bef74ae (96.3%, in the draft
PR sourcehold#356), which restored the y store at 640x480.

Two differences were left, and both come from one thing: a store that both arms of an if / else share was written
once behind the arms. The compiler merges the arms' identical ends, so the instructions come out the same either
way, but what it decides before that merge does not:

- DAT_MenuHandlerState::instance.y at the function's start. Written in each arm, ebp is saved behind the merged
  store and the load of the tab type (push ebp at 0x004398FF), as in the original. Written once behind the arms,
  ebp is saved in front of the store.

- drawBufferChoiceValue = RT_MAP_GAME at the end of the 1024x768 and the 1024x600 blocks. The function stores 99
  sixteen times, so the compiler holds 99 in ecx (lea ecx, [ebx + 99] at 0x00439986). The original uses that
  register only up to the first call and stores the immediate in every later block. Written once behind the arms,
  our compiler loaded 99 into ecx again at each block's end (13 times). Written in each arm of those two blocks, it
  does not.

Measured: quick_diff 1.0000 with 1069 instructions on both sides; reccmp 100.0% (normalized 100.0%) alone, data
resolvers and its own resolver on. Not run in game.

Tried on the way, all without effect on the 99: where the 99 stores sit in the first two blocks, a local for the
99, the second store reading the index back, and the four callees in the same translation unit (quick_diff 0.7860).

The text against the draft: pendingMenuRedraw is a BOOLEnum, so it is tested by truthiness and stored FALSE; in the
first two blocks, where each arm is now complete by itself, leftGfx is declared in the arm with its value.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* reimplement: SHC_3BB0A8C1_0x004261E0 100.0% Reimplemented

Credits::MenuView_Credits_Prepare, from gynt's draft on his fork's reimpl/UI-MenuViews-development (his scored commit
on the file is 458bcd5 at 80.00%, and the branch's status line records 82.1% since 71e725a; the newest commit
on the file, 0295332, is on his reimpl/UI-MenuItems-development), through our draft 3480be0 (82.1%, his code in
main's style, in the draft PR sourcehold#356).

One change: each arm of the test empties the list of loaded pictures itself (totalLoadedGfx = 0), where the draft
had one store in front of the test. The original keeps 0 in edi for the whole function (xor edi, edi at 0x004261E2,
six uses) and saves esi and edi at the start. With one store our compiler used the immediate 0 everywhere and saved
esi only in front of its first use. With the store in each arm it keeps 0 in edi, and the two stores still come out
as one, between the compare and the jump (0x004261EA), where the single store stood too. Presumably the compiler
counts the uses of 0 before it merges the two stores.

Measured: reccmp 100.0% (normalized 100.0%) alone, data resolvers and its own resolver on. Not run in game.

The text against the draft: the string pointers have their texts as comments.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* reimplement: SHC_3BB0A8C1_0x004B2820 100.0% Reimplemented

MenuModalComposition::activateModalDialog2, from gynt's drafts: 06829d8 at 53.6% on sourcehold's reimpl/UI-Core;
b1c48ad at 50.64% and 10280b1, whose status line records 53.7%, on his fork's reimpl/UI-Core-development; the
newest commit on the file, 1eaeddd, is on his reimpl/UI-MenuItems-development. Through our draft 950e83e
(82.7%, in the draft PR sourcehold#313).

What was left: our compiler kept a zero in esi for the whole function (xor esi, esi at the start and again behind
the copy of the modal), where the original compares with and stores the immediate 0 and saves esi only around that
copy. The last block decided it. It had the result of getAreWeInAInGameMenu and the dialog's x and y in locals in
front of the test. Now the call is tested directly and each arm has its own x and y. The original loads y and x
between the call's test and the jump (0x004B29F2 to 0x004B29FA), which is where the compiler puts loads that both
arms start with, and tests the result with test eax, eax. With that form no zero register is left.

Checked against the binary: the function returns when the next stored AI lord message starts playing (jne at
0x004B2854), and in game it blits only the map surface's rectangle (the two blits are the arms of one test, each
followed by its own end, 0x004B2A2A and 0x004B2A4D). All four of gynt's versions of the file (06829d8, 8ca7861,
10280b1, 1eaeddd) go on from the in-game blit to the menu surface's blit, and 10280b1 and 1eaeddd have an
empty if where the first return is. Our draft 950e83e had both right already.

Measured: quick_diff 0.9895 with 191 instructions on both sides (what differs is how the two listings print a
rep movsd and an import call); reccmp 100.0% (normalized 100.0%) alone, data resolvers and its own resolver on. Not
run in game.

The text against the draft: the unused BOOLEnum using and include are gone; the border style masks are written in
decimal, (32 | 512) for the two tiled styles and 1024, as the bits have no names yet; the imported note on the copy
is gone, as in main's activateModalDialog.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
gynt added a commit to kotijekriv/OpenSHC that referenced this pull request Nov 24, 2026
…#436)

StatusMenus::RenderStatusMenu_Population, from gynt's drafts: a92aa37 at 59.18% and 142ef0b at 64.1%, the
second on sourcehold's reimpl/UI-StatusMenus; 73.2% in the status line of 67318e1 on his fork's
reimpl/UI-StatusMenus-development; the newest commit on the file, e30b3f0, is on his
reimpl/UI-MenuItems-development. Through our drafts 4faa418 (82.4%, on our fork kotijekriv's
reimpl/UI-StatusMenus-development) and 6a2b835 (93.8%, in the draft PR sourcehold#313).

Two differences were left, in two different loops, with one cause: the year labels' loop took the label's years as
label * 5.
The compiler turns that into a counter of its own either way (add ebp, 5 at 0x0043F999), but with the
multiplication in the source
- the sum of the first year and the label's years was an lea into a third register, where the original adds in
  place (add ecx, ebp at 0x0043F985), and
- in the next loop, the bars' loop, the three scratch registers came out rotated (the screen width in ecx where
  the original has eax, at 0x0043F9F0).
With the years as a second counter of the for loop (years += 5) both are gone. That the next loop followed
suggests the compiler hands out scratch registers in turn, so one temporary more shifts the choices behind it.

Measured: quick_diff 0.9984 with 318 instructions against 317; the one line is the jmp over the padding in front
of the labels' loop (0x0043F926), which our listing shows as padding. reccmp 100.0% (normalized 100.0%) alone, data
resolvers and its own resolver on. Not run in game.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
gynt added a commit to kotijekriv/OpenSHC that referenced this pull request Nov 24, 2026
* reimplement: SHC_3BB0A8C1_0x004B5330 100.0% Reimplemented

MinimapViewState::renderMinimapTileStripWithLuminescence, the minimap's second picture: for a strip of
the screen tile rows it takes the colour of what stands on each tile (moat, trees, plain tiles with one
display flag, or the first entry of MiniMapDefinedData's table that shares a bit with the tile's flags),
scales it by the tile's luminescence (RGB555 or RGB565) and writes it into the second minimap buffer, at
full or at half size; a tile without a colour takes the terrain picture's pixel. It is the sibling of
renderMinimapTileColors (0x004B58D0) and is written the same way, from the original's listing.

The function was a 21.4% draft in sourcehold#313 ("Pixel store and registers differ"). sourcehold#313's version started from
gynt's draft as it stood on his fork's reimpl/UI-Core-development, 10280b1 (2026-10-25; status line
"9.3% | Reimplemented, asm differs"), with the body rewritten from the listing. His newest version is
4a1f8dd (2026-11-02, a style pass over the UI folders; "9.0% | Style pass, asm differs") on
reimpl/UI-MenuItems-development, where 1056d3f, 2da2d36 and b60bb72 are earlier steps of it
(9.03%); 24080c9 and 1955a67 (9.0%) are the same draft on reimpl/UI-Core (sourcehold#256). No behaviour change
against sourcehold#313's code (the strip's end is now divided signed, as in the original; the same for every real
argument). What sourcehold#313 changed against every version of the draft stays:

- `mapSize <= 200` where the draft has `< 200` (every 200 by 200 map);
- the return past the strip's end, which the draft lacks (reached by drawMinimap's 2% strips). gynt has it
  himself in 8ca7861 on reimpl/Wilps-2026-10-18;
- the second buffer written through `this`, as in the original, where every version of the draft goes
  through the global instance (the same address while `this` is DAT_MinimapViewState);
- the screen tile table indexed from its base on today's main (not the draft's mistake: its `- 8` was right
  for the header of its day).

What the match needed:

- The pixel stores are handwritten assembly in the original: the same two stores as in
  renderMinimapTileColors, with the address computation of renderMinimapPreview and drawCurrentPixel
  (`add eax, eax` and a `mul edx` by the row pitch, here the constant 400). Two `__asm` blocks, one per
  size. No frame pointer, as in the original.
- The colour is a 16-bit local, and the blue channel and the mix are written out in both colour-mode
  arms. Here the original has one shared end for the two arms: the compiler merges the two identical
  ends itself. Written once behind the arms, the registers of the whole block are different ones.
- The channels initialised blue, green, red; red's and green's masks as statements right after their
  caps, blue's in the mix, as in renderMinimapTileColors.
- The table loop: the entry's bits in a local that is set before the tile's flags are read, the first
  test on that local and the loop's test on the table. The two tests take their operands in the order
  the variables are first set; with the first test on the table and the loop's on the local, both come
  out swapped. A flag tells "no entry" from "found"; the compiler turns it into the two jumps.
  The loop is a guarded do-while: a plain while loop reads 99.7% (one of the two tests swapped, whether
  it tests the local or the table), and a for loop with a break at its end compiles to two instructions
  more.
- The five simple initialisations before the buffer and the strip rows, so that every stack slot is the
  original's; the row base holding the orientation's offset first; the viewport height read from the
  global a second time; the column loop's bound in its test; the tile read before x and y; y inside the
  tile loop and a copy of x at the top of the full-size branch; the row base stepped in the row loop's
  header.

The channel masks have names in a small file-local enum, as in renderMinimapTileColors.

Measured in a narrow build on main 3458fea of this file alone (main is now 812d149: sourcehold#399 and sourcehold#398 add
only the optional function-visibility units, off by default), struct resolvers and its resolver on:
100.0% raw and normalised, no diff entry. Not run in game.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* headers: ColorChannelMask, the channel bits of an RGB555 and an RGB565 colour

A new enum in OpenSHC::Rendering beside ColorMode: the masks of the red, green and blue channels in the two
colour modes. renderMinimapTileStripWithLuminescence (and renderMinimapTileColors) scale each channel of a
minimap colour by the tile's light and cap it at these masks; they had them as a file-local enum.

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

* renderMinimapTileStripWithLuminescence: name the numbers by main's constants

Review: the channel masks come from the new ColorChannelMask header enum; the map's 400 rows and its 200-tile
size from Map::MapConstants (MC_MAP_XY_LIMIT, MC_MAP_SIZE_200); the screen tile table's start, its two row
lengths (200 and 201) and its 80400 entries per orientation from Rendering::Enums::ViewportConstants. The
orientation offsets are VC_SCREEN_POINT_TABLE_START + k * VC_SCREEN_POINT_TABLE_SIZE, and 401 is a short and a
long row. The two inline assembly blocks take the buffer's row length from a file-local enum, since inline
assembly cannot name a qualified constant.

The same code: the quick compile's listing is unchanged, and a narrow build of this file reads 100.0 raw and
normalised with no diff entry.

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

* renderMinimapTileStripWithLuminescence: the small map's margin and the buffer's row from map constants

Review: the first row for a map of up to 200 tiles is the margin around it, (MC_MAP_XY_LIMIT -
MC_MAP_SIZE_200) / 2, and the assembly's row length is a buffer row of MC_MAP_XY_LIMIT / 2 pixels in bytes
(both minimap buffers are 400 rows of 200 ushorts).

The same code: the quick compile's listing is unchanged, and a narrow build of this file reads 100.0 raw and
normalised with no diff entry.

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

---------

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
kotijekriv and others added 3 commits November 24, 2026 22:03
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ee values PlayerListAndNpcButtons passes

Three enum values the generated headers do not have yet, all passed by
MenuItemActionHandler_LobbyMenu_PlayerListAndNpcButtons (0x00440E50). Each is named the way its unknown neighbours
are.

- GameCommandType gets `GCT_UNKNOWN_85 = 85` between 84 and 86: the round table's slot button queues command 0x55
  for a human player's slot (`push 0x55` at 0x0044104A, into queueCommand 0x00489100, whose parameter is a
  GameCommandType).
- SoundEffectID gets `SEID_UNKNOWN_0x60 = 96` between 92 and 97: the same branch schedules sound effect 0x60 (`push
  0x60` at 0x0044105E, into scheduleSFXVariation 0x00449D50, which indexes the sound structures with it, as
  ChooseRandomNumberOfEnemies_Main does with SEID_UNKNOWN_0x79).
- SoundEffectID gets `SEID_UNKNOWN_0xFC = 252` between 0xFB and 0xFD: the random-enemies button sets up sound
  effect 0xFC (`push 0xfc` at 0x00440FD1, into setUpSFXToPlayUnk 0x00449C40, whose parameter is a SoundEffectID).

SoundEffectID numbers its values as DE's eSFX does (DE/SHCDE/eSFX.hpp: SEID_WOOD_CHOP = FX_CHOP = 2), and eSFX
names 96 FX_ARMOUR_HIT and 252 FX_DICE (the random-enemies dialog's dice), which confirms the two values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LobbyMenu::MenuItemActionHandler_LobbyMenu_PlayerListAndNpcButtons, from gynt's draft (efd2c3f, 49.29%, on his
fork's reimpl/UI-MenuItems; 48.6% in 8725ec5 on reimpl/UI-MenuItems-development), rewritten from the binary. A
click on one's own row of the player list toggles it, -101 opens the AI lord select, -102 the round table, -103 the
random-enemies dialog (with SEID_UNKNOWN_0xFC from the header commit before this one), and the buttons from -201
down act on a round-table slot: a human player gets command 85 (GCT_UNKNOWN_85, the same header commit) once, with
sound effect 0x60 (SEID_UNKNOWN_0x60), and an AI is removed from the slot after its lord's message 21.

All 148 instructions are there; what is left is register naming from the first test on: the original keeps
activeModalDialogID in eax and buttonID in ecx, we have them the other way round, and no form of the first tests
moved it (nested returns, a local for the dialog read once at the top or after the first test, a switch or an
else-if chain for -101 to -103). The original also computes the slot index -200 - buttonID before the array read
(mov eax, -0xc8; sub eax, ecx), where MSVC folds it into the address for us in every form tried. The slot is read
as a char and copied to the player ID: one int tested with `< 1` drops the byte test (147 instructions).

reccmp 66.9% raw (62.0% normalised) in a narrow build on main 0268112 with the header commit.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the declaration/type change This requires changes to the generated/exported types or definitions. label Nov 24, 2026
@kotijekriv kotijekriv changed the title Reimplement 15 rendering, UI and GameSynchronyState functions (not yet 100%) Reimplement 16 rendering, UI and GameSynchronyState functions (not yet 100%) Nov 24, 2026
… one running total

StatusMenus::RenderStatusMenu_Popularity, from gynt's draft on his fork's reimpl/UI-StatusMenus-development
(5a9a253 at 48.63%, 218a0c0 at 59.3%, ca6119f at 59.7%, 67318e1 at 67.36% for the folder, his style
commits 1eaeddd, 4a1f8dd, e30b3f0, e9bc49c, and 08c492b, his newest, which writes `gold <= 0` where
the original tests it), rewritten section by section from the listing on main's names: the six event fields are
currentPlaguePenalty, currentLionsPenalty, currentBanditsPenalty, currentFirePenalty, currentMarriageBoost and
currentJesterBoost, and the layout table is the DAT_PopularityMessageLayout global.

What the listing asked for:
- The report keeps one running total (ebp): the event sum starts it in the counting section, with 400 for a fair,
  and each section adds its value right after its percentage is drawn (`add ebp, esi`, 0x0043E920 on). Summed once
  at the end, the values each stayed alive to the end (0.59 quick, against 0.82 for the running total at that
  step).
- Each section's value is a local of its own (food, tax, crowding, fear, religion, ale), as the original keeps each
  in esi only until it is added.
- The active events are counted with two counters zeroed before the first call (the original's edi and esi), each
  active event taking the next row. The rows are an array in counting order, as the original keeps them side by
  side in its frame; as seven locals they take other slots and the scratch registers rotate from the end of the
  count on (0.8616 against 0.8895 at that step). The page count is 2 for more than two events, else 1, written as
  an if / else (`(activeEvents > 2) + 1` gives 0.8826 there), and the page is reset when `page >= pageCount`.
- The thresholds are written as the original tests them: crowding `<= 100` to `<= 180`, religion `<= 24`, `<= 49`,
  `<= 74`, `<= 94`, the unpaid bribe's test `gold <= 0`, and the food variety behind `foodTypesEaten != 0 &&
  foodTypesEaten != 1`. The rations, the taxes and the ale stay one compare per value: `(rations - 2) * 100` gives
  0.8335 and a switch on the taxes 0.8198, against 0.8512 at that step, and `aleCoverage / 25 * 50` 0.8685 against
  0.8895.
- The gold and the title's x and y are read before the draw-buffer store, as in the original (the gold read at its
  test gives 0.8217 against 0.8512).
- Every text's y and x go through locals, y first, as the original reads them: inlined in the section titles 0.7837
  against 0.8512, in the event lines 0.8895 against 0.9826, and in the month line 0.9826 against 0.9930.
- For a rations value outside 0 to 4 the original reads the fire row's slot as the food value; kept, with a fixme.

What is left (quick_diff 0.9930, 860 of 860 instructions): in three of the event lines' percentages the two
operands of the `lea` that adds the layout and the menu position come the other way round (`[edx + eax - 0x1]`
against ours `[eax + edx - 0x1]`); the argument written in either order, or through locals, gives the same.

reccmp 99.3% raw (92.0% normalised) in a narrow build on this branch.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kotijekriv kotijekriv changed the title Reimplement 16 rendering, UI and GameSynchronyState functions (not yet 100%) Reimplement 17 rendering, UI and GameSynchronyState functions (not yet 100%) Nov 24, 2026
kotijekriv and others added 9 commits November 25, 2026 00:08
…xt free row)

StatusMenus::RenderStatusMenu_Popularity (from gynt's draft: 5a9a253 at 48.63%, 218a0c0 at 59.3%, ca6119f
at 59.7%, and 08c492b, his newest), comments only; the listing is the same (quick_diff 0.9930):
- The ale chain is a ladder (`< 25` to `< 100`), as crowding and religion are, not one compare per value.
- The counters' comment: nextRow is the next free row of the list.
- The rations' try is written as code, in backticks.

Two corrections to the step before's message: the ale stays a ladder (not one compare per value), and the page
count's `(activeEvents > 2) + 1` gives 0.8826 against 0.8895.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a header of its own

gynt on sourcehold#488: "When declaring new types, create new .hpp files, don't hide them in .cpp files!" The tables
RenderGreatestLordScreen (0x004D5810) keeps in one block of its frame get UI/Rendering/GreatestLordTablesUnk.hpp,
in the folder's namespace OpenSHC::UI::Rendering, laid out as the folder's other type headers are (packed, field
offsets, the size asserted: 0x2F4). The next commit moves the .cpp onto it.

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

UI::Rendering::RenderGreatestLordScreen (0x004D5810) drops the struct it declared in the .cpp and includes
UI/Rendering/GreatestLordTablesUnk.hpp, as gynt asks on sourcehold#488. The code is unchanged, and so is the listing
(quick_diff 0.5369, the same 1277 instructions).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lue of its own, one counter for both passes

UI::Rendering::RenderMissionObjectivesUnk, from the listing and the compiler's register keys (the scores its
allocator serves the callee-saved registers by):
- Builder mode's page height starts from the visible height in a value of its own (`int const visible = 377 -
  offset;`), not rounded in place in pageHeight. The key of the value rounded in place was above y's, so it took
  esi, and y and the first pass's counter took other registers than the original's for the whole function
  (quick_diff 0.6203, now 0.7556). The page height is the same number either way.
- The two passes over the objectives share one counter, as the original keeps it in one register (0.6063 against
  0.6101).
- The declarations follow the original's stores (value, eventIndex, column, then boxX; 0.6114).
- The map name is read into a local before the call that draws it, as the original calls it before the other
  arguments are pushed (0.6203).

What is left (780 against 787 instructions): y and the text width swap esi and edi (offset's key is above y's); the
original subtracts 9 from y at the win timer block and offsets its uses (y + 9, + 10, + 8, then += 30 where ours
writes y, + 1, - 1, += 21); and the first pass's loop has one `jmp` more at its entry in the original.

reccmp 70.6% raw (67.4% normalised) in a narrow build on this branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ays, the icons' y per row

UI::Rendering::RenderGreatestLordScreen, from the listing. Earlier work on this function: gynt's 46a1621
(40.9%), 9e9cf4d (41.3%) and his newest, 3d17527; this file was rewritten from the listing in d924f3e,
which measured separate arrays 1.5 points below the struct. With the icons' y per row they now measure 0.7 above
it.
- The tables are separate arrays again, in the original's frame order (points, stars, overallOrder, kills, losses,
  statOrder). As one struct, the date written into the statistic orders takes the address of every table, so the
  compiler reads the star count again in each pass of the star loop and saves the callee-saved registers at the
  start. As separate arrays only the statistic orders have their address taken: the star loop counts down from one
  read and two of the saves move to the sort, as in the original (quick_diff 0.5736, now 0.5918). The loops' totals
  are killCount and lossCount, since the arrays have the names.
- The icons' y is computed in each row from the row's y (`y - 18`). As a variable of its own, stepped by 45 next to
  y, it and an `iconY - 5` hoisted out of the lords loop each took a stack slot (0.5432, now 0.5736).
- The sort compares the losses and the buildings lost as `current > next`, as the original does (`jle`), not as
  `next < current` (0.5369, now 0.5432).
The behaviour is the same: the date goes into the statistic orders as before, the icons' y is the row's y - 18 in
every row, and the compares are the same tests.

Tried without a gain: a local of its own per bonus section and per statistic in the sort, the draw loop's player
declared in the loop, the sort's pass and the rank as two variables, the stars loop counting down in the source,
the kill loops' compares the other way round, and the tables in a block of their own with the date in its own
buffer (0.5939, but the frame grows by the buffer: the compiler does not place it over the dead tables).

What is left (1261 against 1267 instructions): the frame is 4 bytes larger; ours keeps 0 in esi across the kill
loop and saves esi and edi at the start (the original zeroes with ecx); the original keeps the icons' y in ebx and
reloads x, ours keeps x in a register; and the sort's current and next swap ecx and eax.

reccmp 59.8% raw (59.5% normalised) in a narrow build on this branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s are separate arrays

The header from 7010cd2 goes again. The commit before this one measures the Greatest Lord screen's tables as
separate arrays (59.1% to 59.8% raw): as one struct, the date the screen writes into the statistic orders takes the
address of every table. Nothing else uses it.

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

StatusMenus::RenderStatusMenu_Army. Earlier work on this function: gynt's 5dfe9f3 (24.6%), 20645fd (25.72%),
ea6ed85 (30.9%), 1e5387d (31.3%) and his newest, e9bc49c; this file comes from his draft, reworked in
a6118a2. The panel's top is read from the menu's y on its own (`DAT_MenuHandlerState::instance.y + 447`) instead
of being computed from the y local. Computed from y, the compiler folds it into every use as y plus a constant, so
y stays in ebx for the whole function. Read on its own it is a value of its own, as in the original (quick_diff
0.4226, now 0.4436). The value is the same: nothing writes the menu's y in between.

Tried without a gain: the top declared before the loop (0.4286) and declared first (0.4135).

What is left (263 against 269 instructions): ours keeps the top in ebx through the loop where the original keeps it
in a stack slot and gives ebp to the loop's `i * 46`, so both of the loop's stepped values sit in slots in ours (by
the compiler's register keys the top scores 113 against 104 for each of the loop's three stepped values).

reccmp 43.2% raw (43.2% normalised) in a narrow build on this branch.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lue of its own

StatusMenus::RenderStatusMenu_Army (gynt's draft: 5dfe9f3 at 24.6%, 20645fd at 25.72%, ea6ed85 at 30.9%,
1e5387d at 31.3% and his newest, e9bc49c; reworked in a6118a2): the fear-factor part draws its line at a y
of its own (`int const textY = top + 25;`) instead of `top + 25` at each of its eight uses. With the uses on the
top, its register key (the score the compiler's allocator serves the callee-saved registers by) was above the
loop's stepped values, so ours kept the top in ebx through the loop and both stepped values in slots. Now the top
is in its stack slot and the loop's `i * 46` in a register, as in the original (quick_diff 0.4436, now 0.5253; with
the value declared before the Total Troops branch too, 0.5245).

What is left (264 against 269 instructions): ours keeps the constant 1 in ebx (the counter's increment and the
bonus line's `TRUE`s) where the original keeps 0 there, so the zero arguments come from ecx in ours.

reccmp 49.7% raw (50.1% normalised) in a narrow build on this branch.

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

MinimapViewState::locatePlayerKeepPositionsOnMinimap (from gynt's draft: 700b4c2 at 22.89%, 3ac3d3b at 22.9%
and his newest, 10280b1; reworked in 3ccb2cf): the row parity's other value is read from the viewport's
height on its own (`int const otherParity = ...viewportHeight + 1;`) and the parity is compared with and set to it.
As `viewportHeight + 1` from the local, the compiler recomputes it in every row, where the original keeps it in a
stack slot of its own next to the viewport height; now it does too, and the frame is the original's size
(quick_diff 0.6463, now 0.6809). The value is the same: nothing writes the viewport's height in between.

What is left (164 against 165 instructions): ours keeps the row in ebp and the row's base tile in a slot, the
original the other way round.

reccmp 61.1% raw (59.1% normalised) in a narrow build on this branch.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gynt added a commit to gynt/OpenSHC that referenced this pull request Nov 25, 2026
…#327 and sourcehold#328, with two header changes (sourcehold#417)

* reimplement: SHC_3BB0A8C1_0x004708F0 100.0% Reimplemented, register allocation only (sourcehold#414)

WindowAndDirectDraw::reinitWindow, moved out of our draft sourcehold#313 with one comment line added. The draft came from
gynt's version on his fork's reimpl/UI-Rendering-development (3768087 at 56.90%, a8b64eb at 56.9%, and
63cc49f of 2026-10-25, his newest commit on the file) and reached 80.4% in 685b039.

Register allocation only, per sourcehold#414: reccmp reads 80.4 (normalized 80.5), and the 56 instructions of both sides are
the same instructions in the same order with the same memory operands. What differs is which of eax, ecx and edx
holds each reload of windowHandle (and the address of the second corner) before it is pushed: eleven lines.
if/else, nested and early-return shapes of the two branches all compile to the same code.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* reimplement: SHC_3BB0A8C1_0x00493E20 100.0% Reimplemented

VideoOptions::MenuItemActionHandler_VideoOptions_Main, rewritten from the listing on top of gynt's draft: aae2c08
(57.14%, his fork's development), cd76e7f (57.7%, upstream's reimpl/UI-MenuItems), 8725ec5 (61.5%, his fork's
reimpl/UI-MenuItems-development) and 8ca7861 of 2026-10-27, his newest commit on the file (his fork's
reimpl/Wilps-2026-10-18: the same code with newer field names). Our mechanical pass b2d7696 in draft sourcehold#328 read
61.5% as well.

What the match needed:
- case 11 keeps the resolution in a local through the loop and stores it once after it; the draft worked on the
  field, which stores it in every round;
- case 18 reads the new resolution once and calls setExtraActiveModalDialog in every arm of the chain, in the
  original's order of arms. The draft set two position locals and called once, which shares the pushes. Two
  neighbouring arms with the same position joined by || read 0.8055 in quick_diff, so each resolution has its arm;
- popModalDialog is called at the end of case 18 and in case 17: the compiler shares the one tail jump;
- no goto and no position locals are left, and the loop is a for with its exit test in the header (a BOOLEnum
  that stands in for the original's do-while): the compiler puts the test at the end of the round, where the
  original has it.

Names instead of numbers: CT_WINDOWS_LIKE_CURSOR, CT_ANI_CURSOR and SS_NORMAL. The parameter is button, as in most
handlers on main; the buttons have no enum, so each case says what it does.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* reimplement: SHC_3BB0A8C1_0x004C0CF0 100.0% Reimplemented

SiegeAttackingForceAndStartGoods::MenuItemRenderFunction_SiegeAttackingForceAndStartGoods_Main, rewritten from the
listing on top of gynt's draft: ce671d7 and 37bf917 (40.1%, upstream's reimpl/UI-MenuItems), f0479fc,
b83dff2 and d7600c8 (44.39% to 52.82%, his fork's reimpl/UI-MenuItems), then 25b481a (54.75%), 9743554
(52.49%) and 6aa5d32 of 2026-11-02, his newest commit on the file (his fork's reimpl/UI-MenuItems-development).
Our mechanical pass 7b18743 and 53bea5f in draft sourcehold#328 read 53.8%.

What the match needed:
- one if / else-if chain with the draw buffer set back once, at the end. The draft returned from every arm, each
  with its own store; written once, the compiler copies the store into the arms as the original has it, and esi
  is pushed before the first branch;
- renderGM for a unit's picture is written in both arms that draw one (rows 20 to 29 and 40 to 49). Shared after
  the chain it reads 0.7479 in quick_diff;
- the row is -1 - button (or esi, -1 / sub esi, eax), not -button - 1;
- every amount is drawn by a call in each arm of the colour test. One call with the colour as a ?: reads 0.9320
  (neg / sbb / and / add for the colour), with a colour local 0.9608.

Behaviour: none of the draft's forms differed in what they draw.

Readability, all measured equal: rows 20 to 29 read SEC_SiegeInformation[index - 20] and rows 40 to 49
SEC_Section1067.siegeEngineCounts[index - 40] (the draft indexed SEC_StartingResources[index + 5] for both, which
is the same address); the picture's height comes from DAT_GMImageHeaders as in TriggerInvasion_Main, not from a
cast on PTR_ARRAY_Unknown_UnitGMHeights; index >= 40 && index < 50 for the unsigned range test.

reccmp: 99.2% raw. The two lines that differ are the picture table's address 0x00B98782 (imh[first + picture - 1]
.height), 14 bytes before DAT_GMImageHeaders: reccmp prints it as a number on the original's side and, on ours, as
an offset from whichever variable of our DLL lies there (Instance<int,15544744>+2, DAT_ButtonX's instance). Only
the name of the resolved address differs, which the project records as 100% (TriggerInvasion_Main in sourcehold#349 has the
same two lines).

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* headers: DAT_SentOrRequestedGoodsAmount is an int

The amount the send / request goods dialog works with is compared as a signed value wherever it is read in
MenuItemActionHandler_AlliesSendAndRequestGoods_Main (0x004B14C0):
- 0x004B15E6: mov ecx, [0x00DF428C] / test ecx, ecx / jle: no amount chosen. An unsigned test would be je;
- 0x004B16ED: mov ecx, [0x00DF428C] / cmp eax, ecx / jge against the room getResourceSpace returned;
- 0x004B183A: cmp [the player's gold], esi / jge, and 0x004B1863 jl, 0x004B1870 cmp eax, esi / jge, with the
  amount in esi.
As undefined4 (unsigned) each of these needs an (int) cast. Its only user on main, MenuItemActionHandler_Allies_Main
(0x004B12D0), assigns to it and stays at 100.0% with the change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* reimplement: SHC_3BB0A8C1_0x004B14C0 100.0% Reimplemented

AlliesSendAndRequestGoods::MenuItemActionHandler_AlliesSendAndRequestGoods_Main, rewritten from the listing on top
of gynt's draft: c7cfed8 and 8ee5623 (32.9%, upstream's reimpl/UI-MenuItems), cbc63a3, 17cbc68 and
df54f4e (56.22% to 57.83%, his fork's reimpl/UI-MenuItems), 8725ec5 (58.2%) and 0e551f6 of 2026-11-02, his
newest commit on the file (his fork's reimpl/UI-MenuItems-development). Our 1f29978 in draft sourcehold#328 read 60.5%.

Behaviour, where the draft differed from the original:
- buttons 21 and 50 to 53 return after their one store, and any other button but 100 returns after opening the
  allies dialog. The draft went on from each of them into button 100's path;
- button 102 (cancel) queues its command only when the send dialog is open and DAT_00df4284 is set. The draft
  queued it always;
- when a request fails for want of a building or of room, the original plays at most the one warning that fits
  the fail state and closes the dialog. The draft played the third warning in every case and, after a missing
  building, went on to the room test;
- a request that is accepted queues the command and closes the dialog; the draft also played the "goods not
  sent" clip after it;
- button 100 does nothing after the request path. The draft fell into the send path.

What the match needed:
- button 100 holds the whole confirm path and the other buttons' activateModalDialog comes last, which puts the
  return block where the original has it (with the test turned round it read 0.9305 in quick_diff);
- the request path is one if / else-if chain that closes the dialog once at its end, with the five command
  stores and queueCommand written in both arms that send. The "not enough" arm comes first in the second
  (accepted first reads 0.9732);
- good <= -1, as the original compares with -1 (good < 0 reads 0.9923);
- the send path has one local for the resource, one for the type it is stored as, and one for the amount.

Uses the header commit before this one (the amount is an int), so no cast on it is left.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* headers: IngameInvasionEventItemContent has an int at 0xA4

MenuItemActionHandler_General_EventSlider (0x004B9E50) reads the four bytes at 0xA4 as one int, the highest value
of the invasion's slider: mov eax, dword ptr [0x01667EEC] at 0x004B9E86 (DAT_MapPropertiesState's
invasionEventContent + 0xA4), which it then stores to *maxValue and clamps field_0xa8 with. The header had them as
undefined1 padding_0xa4[4], which needs *(int*)&...padding_0xa4[0] to read. Named field_0xa4 like its neighbours
field_0xa0 and field_0xa8; the struct's size and layout are unchanged, and nothing on main names the padding.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* reimplement: SHC_3BB0A8C1_0x004B9E50 100.0% Reimplemented

General::MenuItemActionHandler_General_EventSlider, from gynt's draft: cbdee60 and 7c31877 (45.3%, upstream's
reimpl/UI-MenuItems), d0aa6c7 and 899dcd2 (55.93% and 69.21%, his fork's reimpl/UI-MenuItems), 514b907
(83.26%) and dd1a7c4 of 2026-11-02, his newest commit on the file (his fork's reimpl/UI-MenuItems-development).
Our 2001534 and bddd6be in draft sourcehold#327 read 88.0%.

What the match needed, on top of the draft:
- the two range tests against the limit compare *currentValue > limit (cmp [ecx], eax / jle); the draft had
  limit < *currentValue, which swaps the operands;
- in the repeat slider's switch, case 7 comes before case 4, as it already did in the months slider's. That alone
  took it from register names only (0.9322 in quick_diff, the three small blocks of the months slider on rotated
  registers) to every instruction.

Readability, all measured equal: the lists of cases that only break are gone from both switches on the slider;
the two step cases use ++ and --, as the invasion slider's do, and no longer the limit's local; no cast on the
byte fields, read or written; the
parameters are slider and scrollbarEvent, as main's other slider handlers have the second; the amount sliders'
cases are written as their event type plus one (the function compares the type with slider - 1).

Uses the header commit before this one (the invasion's limit is an int field).

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* reimplement: SHC_3BB0A8C1_0x0042D140 100.0% Reimplemented

SinglePlayerMapChoice::MenuItemRenderFunction_SingleplayerMapChoice_ButtonsAndHands, rewritten from the listing on
top of gynt's draft: 582f0a0 and 6918f23 (14.3%, upstream's reimpl/UI-MenuItems), 47663d0 (29.50%, his
fork's development), 1ff44c3 to eaf674d (20.55% to 44.64%, his fork's reimpl/UI-MenuItems), b4b1f65 (45.29%)
and dd1a7c4 of 2026-11-02, his newest commit on the file (his fork's reimpl/UI-MenuItems-development). Our
dcaa477, 53bea5f and 07a33e2 in draft sourcehold#328 read 46.8%.

Behaviour: unchanged. The draft cleared DAT_ButtonUnknownZero after the switch for buttons 2 and 65; here each of
the two clears it itself, before its call, as the original does. The draft's gotos into a shared text call are gone.

What the match needed:
- every case breaks to one store of the draw buffer at the end (the compiler copies it into the arms, with
  pop edi before it, as the original has it); the draft stored and returned in every arm;
- each text is drawn by a call of its own in each arm of the colour test, and renderBasicButton is called in
  each of button 74's three arms and button 77's two;
- case 78 is written out with its own store and return: the original's switch has a table entry for it, though
  it ends in the same block as the default (with a plain break, or left to the default, the range check reads
  cmp eax, 178 where the original has 179);
- the map-index sum in button 65 is DAT_MapSelectionScrollOffset + DAT_MapSelectionRelativeSelected: the other
  order loads the two fields the other way round (reccmp 99.6%; quick_diff does not see it).

Readability, measured equal: X + W / 2 and X + W - 10 for the text positions.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* reimplement: SHC_3BB0A8C1_0x004708F0 80.4% Reimplemented, register choice only

WindowAndDirectDraw::reinitWindow's status line carries its measured percentage instead of 100% (the review asked
for the lower percentage with a remark). A narrow build of this branch's head c6df741, both resolver sets on,
sourcehold's reccmp with --ignore-security-cookie: 80.4% raw, 80.5% normalised. Both sides have the same 56
instructions in the same order with the same memory operands; the difference is which of eax, ecx and edx loads
this->windowHandle in front of the SetFocus, ClientToScreen and UpdateWindow calls (sourcehold#414). The code is unchanged.

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

---------

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>

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

declaration/type change This requires changes to the generated/exported types or definitions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants