Skip to content

Reimplement 5 UI::Rendering PencilRenderCore functions at 100% - #358

Merged
gynt merged 10 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-PencilRenderCore-1-100
Nov 7, 2026
Merged

gynt merged 10 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-PencilRenderCore-1-100

Conversation

@kotijekriv

@kotijekriv kotijekriv commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Five UI::Rendering PencilRenderCore functions at 100%, each with its status line: a filled box, a dimmed box, a 4x4 pixel pattern over the whole screen, and the two diagonal line routines.

All five continue gynt's drafts from his fork's reimpl/UI-Rendering-development (63cc49f), in an area he agreed on Discord (2026-11-06) we may take; none is in his open #294, which has three other PencilRenderCore functions. The two diagonals were rewritten from the binary as Bresenham lines (his drafts read 44.8% and 38.8%). Every commit body says what changed against the draft and why, and each credits him as co-author. No header change is left: gynt's Ghidra sync eef6f66 took all three into main, and main is merged in (9abcf90).

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

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

It went through the same checks as #354: a fresh-eyes review of every file (each step compared with the original's disassembly, the Bresenham error terms, their signs and the end conditions included; its points applied and measured), openshc-pr-check with no errors, and status_regression.py, which finds nothing below a known score on main or any fork.

Header changes

Update: all three are on main since eef6f66.

All three in PencilRenderCore; no function on main uses any of these fields.

  • currentX and currentY are ints: setupPencil (0x00468C80) stores the clipped left and top into them after signed clamps (jge at 0x00468C9F, jl at 0x00468CB8), and drawPixelPattern4x4OverWholeScreen compares them signed with the resolution (jl at 0x0047132B and 0x00471339). With dword, its loops needed (int) casts.
  • moveDirectionXUnk_0x20 and moveDirectionYUnk_0x24 are ints: setupPencil sets each to +1 or -1 (setle and lea [ecx + ecx - 1], 0x00468D83-0x00468DA4).
  • drawStartX/Y and drawEndX/Y are ints: setupPencil clamps the edges with signed compares and stores the smaller as the start and the larger as the end (0x00468C9F-0x00468DD2). gynt's open Reimplement 18 UI rendering, minimap and credits functions #294 casts them to (int); those casts become no-ops.
Function Address Raw Draft What changed
drawColorBox 0x00470E90 100.0% 96.3% The height counts down before the row moves on, as in the original: for (; currentHeight_0x2c >= 0; --currentHeight_0x2c, ++drawStartY) (the draft had the two the other way round).
dimBox 0x00471050 100.0% 96.3% The same.
drawPixelPattern4x4OverWholeScreen 0x004712E0 100.0% 93.1% Two for loops over the fields instead of guarded do-whiles (quick_diff 0.7857 -> 0.9643; the rest is ret / ret 0).
drawDiagonalWiderThanHighUnk 0x00471280 100.0% 44.8% Rewritten from the binary: one pixel per step along x, and a step along y too while the error term is positive.
drawDiagonalHeigherThanWideUnk 0x00471220 100.0% 38.8% The same, mostly vertical.

None of the five changes behaviour against its draft: the drafts drew the same pixels in the same order. The changes are shape, names and types.

Kept as they are, and why

  • The diagonals: the major-axis step stays in each arm of the if, as the original has it (once after the if: quick_diff 0.9722 -> 0.8286 and 0.8857). Their loops count down the existing field (currentWidth_0x28 / currentHeight_0x2c) rather than a counter of their own, because the original decrements the field itself and leaves it at -1.

Proposed, not changed here

Names only, for the Ghidra side:

gynt's other commits on these functions

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

Function Address His other commits
drawColorBox 0x00470E90 a42e350 (2026-10-03, 63.2%)
dimBox 0x00471050 5c53b4d (2026-09-30, 60.71%)
drawPixelPattern4x4OverWholeScreen 0x004712E0 3762027 (2026-09-30, 86.21%)
drawDiagonalWiderThanHighUnk 0x00471280 5d5a669 (2026-10-03, 37.7%)
drawDiagonalHeigherThanWideUnk 0x00471220 2e2c7d3 (2026-10-03, 31.9%)

🤖 Generated with Claude Code

kotijekriv and others added 8 commits November 7, 2026 02:49
setupPencil (0x00468C80) stores the clipped left and top into them (mov [ebp + 0x10], edi and mov [ebp + 0x14],
edx at 0x00468D8A / 0x00468D8D) after signed clamps (test edi, edi; jge at 0x00468C9F; cmp edi, 0xFD8; jl at
0x00468CB8). drawPixelPattern4x4OverWholeScreen (0x004712E0) steps both over the screen and compares them signed
with the resolution (jl at 0x0047132B for currentX, at 0x00471339 for currentY), and passes them to
drawPixelPattern4x4(int drawX, int drawY). With dword the loops need (int) casts to keep the jl. No function on main
uses either field.

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

setupPencil (0x00468C80) sets both to +1 or -1: xor ecx, ecx; cmp edi, esi; setle cl; lea ecx, [ecx + ecx - 1];
mov [ebp + 0x20], ecx at 0x00468D83-0x00468D94, and the same from the top / bottom compare into +0x24 at
0x00468D97-0x00468DA4. The two Bresenham functions add them to currentX / currentY, which are int. No function on
main uses either field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
setupPencil (0x00468C80) clamps left, top, right and bottom with signed compares (test edi, edi; jge at 0x00468C9F;
cmp edi, 0xFD8; jl at 0x00468CB8, and the same for the others), then stores the smaller of left / right into
drawStartX and the larger into drawEndX after a signed jle (0x00468D9E-0x00468DB4), and the same for top / bottom
into drawStartY / drawEndY (0x00468DB7-0x00468DD2). No function on main uses these fields; gynt's open sourcehold#294 casts
them to (int), and those casts become no-ops with this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PencilRenderCore::drawColorBox, gynt's draft from his fork's reimpl/UI-Rendering-development (63cc49f; 96.3%
"asm differs" there; his closed sourcehold#255 had an older form). The box is set up with setupPencil and then filled with
drawHorizontalLine row by row from the top. The original decrements the remaining height before it moves
drawStartY down; the draft's for loop (height in the increment, drawStartY in the body) did it the other way
round, which was the whole gap. Now both go in the for's step, --currentHeight_0x2c, ++drawStartY, in the
original's order. Also: an early return when setupPencil reports nothing to draw, in place of the BOOLEnum local
and the != FALSE test, and the unused includes and using dropped. quick_diff 1.0000; reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PencilRenderCore::dimBox, gynt's draft from his fork's reimpl/UI-Rendering-development (63cc49f; 96.3% "asm
differs" there; his closed sourcehold#255 had an older form). The box is set up with setupPencil and then darkened with
dimHorizontalLine row by row from the top. The original decrements the remaining height before it moves drawStartY
down; the draft's for loop (height in the increment, drawStartY in the body) did it the other way round, which was
the whole gap. Now both go in the for's step, --currentHeight_0x2c, ++drawStartY, in the original's order. Also:
an early return when setupPencil reports nothing to draw, in place of the BOOLEnum local and the != FALSE test,
and the unused includes and using dropped. quick_diff 1.0000; reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PencilRenderCore::drawPixelPattern4x4OverWholeScreen, gynt's draft from his fork's reimpl/UI-Rendering-development
(63cc49f; 93.1% "asm differs" there; his closed sourcehold#255 had an older form). It tiles the 4x4 pixel pattern over the
whole screen, keeping the position in currentX / currentY. The draft's do-while loops behind if guards become two
for loops over the fields, which put the inner compare's load in the original's register (quick_diff 0.7857 ->
0.9643; the rest is ret / ret 0). With currentX and currentY int (the header commit before this one) the (int)
casts go. reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PencilRenderCore::drawDiagonalWiderThanHighUnk, gynt's draft from his fork's reimpl/UI-Rendering-development
(63cc49f; 44.8% "asm differs" there; his closed sourcehold#255 had an older form), rewritten from the binary. A Bresenham
line for the mostly horizontal case: one pixel per step along x (currentWidth_0x28 counts down), with a step along
y as well while the error term is positive. The error term starts at 2 * height - width and grows by 2 * height on
a straight step and by 2 * (height - width) on a diagonal one (straightStep and diagonalStep), as the original
keeps them (ebx, ebp, edi). The draft did the same, but moved x once after the if, where the original moves it in
each arm (once after the if: quick_diff 0.9722 -> 0.8286), and kept its iVar locals. quick_diff leaves only ret /
ret 0; reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PencilRenderCore::drawDiagonalHeigherThanWideUnk, gynt's draft from his fork's reimpl/UI-Rendering-development
(63cc49f; 38.8% "asm differs" there; his closed sourcehold#255 had an older form), rewritten from the binary. The same
Bresenham line as drawDiagonalWiderThanHighUnk for the mostly vertical case: one pixel per step along y
(currentHeight_0x2c counts down), with a step along x as well while the error term is positive; the error term
starts at 2 * width - height and grows by 2 * width (straightStep) or by 2 * (width - height) (diagonalStep). The
draft did the same, but moved y once after the if, where the original moves it in each arm (once after the if:
quick_diff 0.9722 -> 0.8857), and kept its iVar locals. quick_diff leaves only ret / ret 0; reccmp 100.0%.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the declaration/type change This requires changes to the generated/exported types or definitions. label Nov 7, 2026
…rement

drawDiagonalHeigherThanWideUnk (0x00471220) and drawDiagonalWiderThanHighUnk (0x00471280) had the measurement in
their comment (moving the major axis once after the if: quick_diff 0.9722 -> 0.8857 and 0.9722 -> 0.8286). The
numbers go to the PR text; the comment keeps one line on why the major axis moves in each arm. Comments only, no
code change.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gynt
gynt added this pull request to the merge queue Nov 7, 2026
Merged via the queue into sourcehold:main with commit 120ea34 Nov 7, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants