Skip to content

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

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

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

Conversation

@kotijekriv

@kotijekriv kotijekriv commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Sixteen 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. Nineteen 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 and renderMinimapTileStripWithLuminescence in #465.

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.

No header change left: 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
AlphaAndButtonSurface openBuildingStatusMenuForBuildingID 0x00463310 86.1% (cb62724) The second argument of the extendResourceCountdownForPlayerBuildingsOfType call: the original pushes esi, which holds the menu tab's initial 1, and ours pushes the constant; that one byte moves every later jump. MSVC replaces the menu tab's variable with the constant before it allocates registers, so no spelling of the source asks for the reuse
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)
MinimapViewState locatePlayerKeepPositionsOnMinimap 0x004B5F70 55.9% (5a6f690) Frame one slot smaller: the original keeps viewportHeight + 1 in its own stack slot, ours computes it again for each row; the row index sits in a slot in the original and in ebp in ours
Rendering BlitMapImageWithVerticalClipAndYOffset 0x00454080 86.3% The C++ part before the asm keeps its values in other registers; the asm matches
Rendering RenderGreatestLordScreen 0x004D5810 58.8% Frame 8 bytes larger, reg alloc
Rendering RenderMissionObjectivesUnk 0x004D76A0 58.2% Register assignment: the original keeps 0 in ebp (its first loop counts from it) and y in esi; ours has them in edi and ebp
StatusMenus RenderStatusMenu_Army 0x00447FA0 40.2% Register allocation: ours folds the panel's top (y + 447) into each use and keeps y; the original keeps the top in a slot and i * 46 in ebp, where ours keeps both induction values in slots
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
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-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 and others added 4 commits November 17, 2026 05:08
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- BlitMapImageWithVerticalClipAndYOffset (0x00454080): the asm labels get the names BlitMapImageWithVerticalClip
  uses on main for the same blocks (row_start, copy_whole_row, copy_right_half, copy_left_half, copy_middle,
  next_image, done, and their zoom_ forms with _odd), instead of addresses; height is adjusted with +=.
- RenderMissionObjectivesUnk: the four numberWidth sums are written with +=.
- takeScreenshot: the sprintf format is the s_ pointer from string-literals.hpp.
- renderMinimapTileStripWithLuminescence: clang-format.

quick_diff gives the same instructions as before for the first three; takeScreenshot reads the same 0.8571, with
only the compiler's temporary names changed by the larger include.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main's Ghidra syncs moved SkirmishStatistics' start and end dates into tail.tail1 (yearStart, monthStart, yearEnd,
monthEnd) and made drawHeaderTextBanner's first parameter an eTextSections; the "Greatest Lord" banner is
TEXT_MP_RANK (225). quick_diff 0.5519 on main e086ba7, where the draft did not compile before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WindowAndDirectDraw::reinitWindow (0x004708F0) is 100% by register allocation only (sourcehold#414): the same 56
instructions in the same order with the same memory operands, and only eax, ecx and edx differ on eleven lines. It
goes out with the ready PR built from reimpl/worker-C-ui-100 (dcb47ae). Its file leaves this draft and its status
line goes back to main's.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
kotijekriv and others added 4 commits November 19, 2026 21:51
Rendering::RenderTextPageProgressBar (0x004DAFB0) reaches reccmp 100.0 (normalized 100.0) on main 3458fea and goes
out with the ready branch reimpl/UI-B-round22-100 (7289c46). Its file leaves this draft and its status line goes
back to main's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The draft is restructured from gynt's version (8f3342a at 53.1%; his newest commit on the file is 63cc49f,
on his fork's reimpl/UI-Rendering-development), by way of this draft's 8e65f98.

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 (the first statue block after the owner test, and the first switch's
select-and-return block); with the statue case last, MSVC kept the later copy just before the menu tail instead
(72.1). Measured with reccmp on main 3458fea: 86.1 (normalized 63.8).

Left: the extend call's second argument. The original pushes esi, which holds the menu tab's initial 1 there; ours
pushes the constant (`push 1`), one byte shorter, which moves every later jump. Passing menuTab, TRUE, an int menu tab
and two definitions of it all compile to `push 1`.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The draft is from gynt's version (c594fcf at 54.3%; his newest commit on the file is 63cc49f, on his fork's
reimpl/UI-Rendering-development), by way of this draft's 303f94b.

The windowed branch's destination rectangle is computed from the parameters (`clientLeft - cameraX + windowedX - 32`)
instead of from the source rectangle's fields, and stored right, left, top, bottom (all 24 orders measured, the best
four of them with four ways of writing the sums). Measured with reccmp on main 3458fea: 82.1 (normalized 76.9), from 71.5.

Left: the original stores destinationRect.right and .bottom once, in the join after both branches, with right in eax
and bottom in ecx; ours stores them in each branch.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The draft is from gynt's version (33fd4e9 at 73.7%; his newest commit on the file is 67318e1), by way of this
draft's 288841e.

The four stocks' x is its own induction variable (`int x = left + 12;` ... `x += 80;`), which puts the original's
`add edi, 0xc` before the array pointer's setup. Measured with reccmp on main 3458fea: 86.8 (normalized 73.5), from
85.3.

Left: in the loop body the player index, y and the stock value sit in ecx, eax and edx in the original and in edx,
ecx and eax in ours; six other ways of writing the call on top of this (locals for the stock, the player, y or the
resource type, the operand order of y) tie.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kotijekriv kotijekriv changed the title Reimplement 22 rendering, UI and GameSynchronyState functions (not yet 100%) Reimplement 19 rendering, UI and GameSynchronyState functions (not yet 100%) Nov 19, 2026
The keep test reads the building type into an int local and tests the range on it. The original sign-extends the
type and checks the range in one compare (`movsx edx, ...; add edx, -0x28; cmp edx, 4; ja`); with the two
comparisons on the short field MSVC compared the 16-bit value twice (`cmp dx, 0x28; jl; cmp dx, 0x2c; jg`). A
switch over the five keep types compiles the same as the int local. Measured with reccmp on this commit (a narrow
build of the file, data and its own resolver on): 55.9, normalized 54.8, from 48.2.

The draft is from gynt's version (700b4c2 at 22.89%; his newest commit on the file is 10280b1), by way of this
draft's 3ccb2cf.

Left: the original's frame has one more slot. It keeps viewportHeight + 1 in its own stack slot, where ours
recomputes it for each row; a named local for it (const or not) compiles the same as the expression.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuModalComposition::activateModalDialog2 (0x004B2820) reaches reccmp 100.0 (normalized 100.0) on main 3458fea
and goes out with the ready branch reimpl/UI-B-round24-100 (d93e88d). Its file leaves this draft and its status
line goes back to main's.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@kotijekriv kotijekriv changed the title Reimplement 19 rendering, UI and GameSynchronyState functions (not yet 100%) Reimplement 18 rendering, UI and GameSynchronyState functions (not yet 100%) Nov 20, 2026
kotijekriv and others added 2 commits November 20, 2026 13:33
StatusMenus::RenderStatusMenu_Population (0x0043F6A0) reaches reccmp 100.0 (normalized 100.0) on main 3458fea and
goes out with the ready branch reimpl/UI-B-round25-100 (cf5277a). Its file leaves this draft and its status line
goes back to main's.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…es gone, same code

BuildingMenus::RenderBuildingMenu_ChapelAndChurch without the decompiler's iVar / BVar temporaries: the constant
arguments stand in the calls, the positions that are read in front of a nested call keep their locals (y, then x),
and the names are read as char. The three using-declarations the rewrite left without a use (BGR24, TextAlignment,
BOOLEnum) are gone, and BGR24.hpp and BOOLEnum.hpp with them. It compiles to the same code as before (quick_diff
0.8980, 343 instructions on both sides; reccmp 87.6%, 81.9% normalized, in a narrow build on main 3458fea).

Left, from the original's listing: the husband's id is in edx and the three text counters in esi (ours the other
way round, which also delays the store of the husband's type); the tanner's and the default text's arms are laid
out the other way round (0x0043C436 and 0x0043C454); DAT_RenderedUnitOwner is stored in front of the sprite id
(0x0043C4E4); the wife's first name is read into dl. One counter variable for the three cases, locals for the
two ids or the wife's type, and ++ inside the test do not help.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@kotijekriv kotijekriv changed the title Reimplement 18 rendering, UI and GameSynchronyState functions (not yet 100%) Reimplement 17 rendering, UI and GameSynchronyState functions (not yet 100%) Nov 20, 2026
MinimapViewState::renderMinimapTileStripWithLuminescence (0x004B5330) reaches reccmp 100.0 (normalized 100.0) on
main 812d149 and goes out with the ready branch reimpl/UI-B-round45-100 (590aed0). Its file leaves this draft
and its status line goes back to main's.

Co-Authored-By: Claude Fable 5.2 <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 3 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>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants