Skip to content

Reimplement 23 UI::Rendering TextureRenderCore functions at 100% - #364

Merged
gynt merged 35 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-TextureRenderCore-100
Nov 7, 2026
Merged

gynt merged 35 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-TextureRenderCore-100

Conversation

@kotijekriv

@kotijekriv kotijekriv commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Twenty-three UI::Rendering TextureRenderCore functions at 100%, each with its status line: the RGB555 -> RGB565 conversion loops, the gfx / GM file loading and the constructor, and the TGX / GM / face renderers.

All of them continue gynt's work, in an area he agreed on Discord (2026-11-06) we may take: his 2026-10-04 commits on origin/reimpl/TextureRenderCore (the asm loops among them), and his C drafts on his fork's reimpl/UI-Rendering-development. Every commit body cites his commit by hash, says what was already his and what changed, and credits him as co-author. Workers B and A each took half of the area; this PR is both halves together. No change to TextureRenderCore.hpp is left: gynt's Ghidra sync eef6f66 took all four into main, bitmapsFaces_0x94 as a plain ushort*, which this PR now follows (a2dd7d0), and main is merged in (d96eff7). The PR still adds the new RGB555To565Asm.hpp (below), so the declaration/type change label stays until that file is on main.

Other PRs: the ready #348, #349, #352, #353, #354, #357, #358 and #359; the drafts #313, #318, #321, #327, #328, #356, #360 and #363 (two more TextureRenderCore functions, near 100%).

Built on top of main (1c29459) with the bundled MSVC1400-SP1, natively on Windows, against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a). An alone build of the branch reads 100.0% raw and normalized for all 23, and for main's six users of the retyped fields, 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 three fresh-eyes reviews (each function compiled and compared byte for byte with the original, attributions checked against the whole history; their 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.

The handwritten conversion loop

The original converts RGB555 to RGB565 with a handwritten asm loop (AGENTS.md's signals: cmp edx, 0, word stack slots, a parameter slot reused for red). gynt recovered it in e9a1e28, cdaccb4 and 8d62e58. Here it's factored into RGB555To565Asm.hpp, in the form of main's LinkageNeighbourAsm.hpp: MACRO_RGB555_TO_565_PIXEL(RED, SKIP_TEST, SKIP_LABEL) and a loop macro built on it. Four functions use it, and each matches the original instruction for instruction, jump sizes included: transformRawWithMarkerUnkToRGB555To565, transformTileObjectToRGB565, transformRawToRGB555To565, and transformTgxFromRGB555ToRGB565, whose two pixel bodies are byte-identical to the others (87 bytes with the 0xF81F test, 81 without). A commit of its own adds the header to tools/import/injected-headers/ with a write_patches entry, as main does for LinkageNeighbourAsm.hpp (e66d143, 302acd9), so the next Ghidra import keeps it. The other asm blocks are as small as they can be: the pointer stays in edi across the loops, and the row offset uses mul, which C doesn't emit.

Header changes

Update: all four are on main since eef6f66. After the merge, all 25 functions and main's six users of the retyped fields read reccmp 100.0%.

  • TextureRenderCore::bitmapFaceSizes holds 36 ints (it was [28] plus field_0x108..0x124): the constructor mallocs 36 x 8448 bytes (one face each) and zeroes 0x98..0x124 as one run (a loop over 36 matches; 28 plus eight fields doesn't); SharePlayerName copies face n + 27, and SetPlayerNameUnk copies faces 20..27 to 28..35 (0x00489C0E). gynt's newer header has 28 plus eight "zeroed in constructor only" fields; his indices (0-19, 19 + slot) all fit in 36. Nothing on main uses the eight fields.
  • gmAndGfxImageDataBuffer is a byte*: all 14 accesses in the exe are malloc / free, byte offsets or byte reads.
  • gmProcessedImageData is a byte*: nine files on the branch, and main's transformTgxCompressedImageToRGB565, cast it for byte arithmetic.
  • bitmapsFaces_0x94 is a ushort* (this PR first had ushort (*)[66][64]; gynt's sync chose the plain pointer): the faces are 66 rows of 64 RGB565 pixels (8448 bytes), and face n starts at bitmapsFaces_0x94 + n * 66 * 64, which compiles to the original's imul reg, reg, 0x2100.

Main's users compile the same: checkIfGfxTgxStartsWithTransparentPixels, readBitmapFace, RenderPlayerAvatars, transformTgxCompressedImageToRGB565 and the rest. Small commits drop their now-redundant casts, and the constructor casts its two mallocs to the new types so every commit builds.

/GL

transformTilesetToRGB565 (0x00455290) calls transformTileObjectToRGB565 (0x0044CAE0) and keeps this in ecx across the call, as the original does, only when both files are built with /GL. With the caller alone, it spills this exactly as with neither. Both go into the list (gynt's unchanged file reaches 100% with them too), placed among the other UI/Rendering entries.

Behaviour

All 23 behave as the original does. gynt's newer copies of two of them (63cc49f, and his fork's reimpl/UI-MenuItems-development, 405b988) differ from the binary in two places; ours follow his earlier drafts, which match it:

  • loadGmFiles: the newer copies count 242 files instead of 241 when there's no "null" entry.
  • renderGM: the newer copies send every image type, animations included, through the TGX renderer.
    His asm in drawTgxOnFlaggedSurface and renderTgxWithColorAndBlendingUnk read the surface pointer through this; the original reads the global, and so does ours.
Function Address gynt's commit
transformRawWithMarkerUnkToRGB555To565 0x0044C940 cdaccb4
transformTgxFromRGB555ToRGB565 0x0044C9C0 f7163ef
transformTileObjectToRGB565 0x0044CAE0 e9a1e28
transformRawToRGB555To565 0x0044CB60 8d62e58
drawBitmapFace 0x0044CD40 b0012e8, 63cc49f
renderFacesSmallUnk 0x0044CE00 711809e
renderBlendedBlackBox 0x0044F020 74226ca
renderTgxWithColorUnk 0x0044F6F0 a6053d6
renderTgxWithColorAndBlendingUnk 0x0044F850 a501cdd
loadGfxFile 0x00454620 42f6c99
loadGFX8 0x00454700 4a40da6
loadGfxAtBufferEnd 0x004547C0 e3c6eb1
renderLoadedGfx 0x00454900 7c3049b, 63cc49f
renderGfxTgxWithBlending 0x004549F0 3aeeada
drawTgxOnFlaggedSurface 0x00454A60 246507f
loadCampaignMapGfxUnk 0x00454CB0 37368ca
Constructor_TextureRenderCore 0x00455050 636bfa1, 63cc49f
transformTilesetToRGB565 0x00455290 63cc49f
renderGM 0x00455300 9de7fc1
renderGMWithBlending 0x00455390 756ed2e
drawTgxGmOnFlaggedSurface 0x004554A0 fcb3ffa
renderGMWithAlphaMask 0x004557B0 92ec6d0
loadGmFiles 0x00455C60 df9b346

Several of his drafts read below 100% on his branches but 100% unchanged in our build (loadGfxFile 91.8%, loadGfxAtBufferEnd 91.7%, renderFacesSmallUnk 96.3%): their numbers came from his build settings, not the source. Each commit body says which.

Kept as they are, and why

Each was measured; a one-line comment in the code says why. Among them: drawBitmapFace and renderFacesSmallUnk read the global, not this (this->: quick_diff 0.9804 -> 0.5524 and 0.9903 -> 0.8155); renderFacesSmallUnk's column loop keeps != (< 32: 0.8348); loadGmFiles' pointer walks (indexing: 0.7313) and counter steps (0.9385); renderGM's two tests (one test with ||: 0.6585); renderTgxWithColorAndBlendingUnk keeps 32 - blendStrengthUnk in the parameter (a fresh local: reccmp 93.6%) and the map arm first (swapped: 0.8319).

Proposed, not changed here

  • loadGmFiles' parameter is a char (*)[1000] (the file name table). That changes a declaration and its resolver in the generated .func.hpp, so we left it for a later PR or gynt's sync.
  • Names from gynt's newer branch (reimpl/Wilps-2026-10-18): drawBitmapFaceHalfSize, renderTgxImage, renderPalettedTgx, loadCampaignMapPalettes, drawBitmapFaceWithBlend.
  • The gfx file header read by the load functions could be a GfxFileHeader struct.

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
renderTgxWithColorAndBlendingUnk 0x0044F850 3d17527 (2026-11-02, "swap if/else arms across UI/Rendering, BuildingM")
renderTgxWithColorUnk 0x0044F6F0 3d17527 (2026-11-02, "swap if/else arms across UI/Rendering, BuildingM")
renderGfxTgxWithBlending 0x004549F0 dff12c8 (2026-09-30, 49.32%)
renderFacesSmallUnk 0x0044CE00 3d17527 (2026-11-02, "swap if/else arms across UI/Rendering, BuildingM")
drawBitmapFace 0x0044CD40 3d17527 (2026-11-02, "swap if/else arms across UI/Rendering, BuildingM")

🤖 Generated with Claude Code

kotijekriv and others added 30 commits November 7, 2026 09:25
… pixel conversion

A hand-written header, not a generated one, in the form of main's LinkageNeighbourAsm.hpp: the RGB555 to RGB565
conversion the original has as handwritten assembly, as one pixel macro and two loop macros around it (with and without
the 0xf81f transparency-marker test). The whole loop is the same instruction stream in 0x0044C940, 0x0044CAE0 and
0x0044CB60, and the pixel body is twice more in transformTgxFromRGB555ToRGB565 (0x0044C9C0, at 0x0044CA08 and
0x0044CA6D), never as a call. The asm is gynt's: his cdaccb4, e9a1e28 and 8d62e58
(origin/reimpl/TextureRenderCore, 2026-10-04, each "100.0% Reimplemented"; the status file on that branch still has his
earlier 3.6 to 6.8% for them) write it out in each function, with the same _colorPtr, _blue and _green locals and red in
the dead imageOffset parameter's slot. This header factors it out: the pixel macro takes the red slot as a parameter
(imageOffset in the loops, tgxDataPtr in 0x0044C9C0), the locals are ushort in place of word ptr overrides, and the
immediates are in 0x form. Its comment says how the code is recognised and which names the enclosing function has to
provide. The three loop functions follow later in this branch; the next commit keeps the file through a Ghidra
re-import.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mirrors e66d143 (the write_patches entry) and 302acd9 (which added the injected copy), which did this for
LinkageNeighbourAsm.hpp: the importer regenerates the headers under src/, and acc2156 deleted main's
LinkageNeighbourAsm.hpp that way until write_patches() rewrote it from tools/import/injected-headers/. The
hand-written RGB555To565Asm.hpp of the commit before gets the same: an identical copy under injected-headers and
one write_patches entry. The two copies have to be edited together; the importer rewrites src's copy from the
injected one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It was int[28] followed by eight int fields, field_0x108 to field_0x124; it is one array of 36, one size per face slot
of bitmapsFaces_0x94. The constructor (0x00455050) allocates bitmapsFaces_0x94 as 304128 bytes, 36 faces of 8448
(0x2100, readBitmapFace's FACE_SIZE), and zeroes 0x98 to 0x124 as one run from one zeroed register: a loop over 36 ints
compiles to the original's instructions (quick_diff 1.0000), the loop over 28 plus the eight fields does not (0.9380:
the fields are stored from another register). readBitmapFace (0x0046C5A0) stores each face's size at the face's index;
faces 0 to 19 come from faces.bmp, 20 to 27 are the players' (slot + 19 in SharePlayerName, AssignPlayerIDToPlayerSlot,
AskForPlayerSlotAssignment, UpdateSkirmishGameMenuFaceBitmap and CrusadeMap_Main, and in RenderPlayerAvatars's read),
and SharePlayerName (0x00483850) copies face n + 27 into a player's slot, so the buffer holds faces past 27. gynt's
TextureRenderCore.hpp on his fork's reimpl/Wilps-2026-10-18 gives the table 28 slots, from those same indices (0 to 19
and 19 + slot), and keeps the next eight as fields "zeroed in TextureRenderCore constructor only"; the indices fit in
36, and the face buffer's size and the constructor's single zeroing run are what say the table is 36 long. A linear
sweep of the exe's code finds no instruction that references 0x108 to 0x124 of the object (0x01FEA198 to 0x01FEA1B4) by
address, and no code on main names the eight fields. Offsets and the class size stay the same. The constructor follows
later in this branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It was void*. The original only allocates and frees it or addresses it by bytes: the malloc at 0x00455144 and the
free at 0x0044C82C; + offsetInBuffer at 0x00454661, 0x00454741, 0x004547E6 (- backwardsOffsetInBuffer), 0x00454908,
0x004549F8 and 0x004558E8 (+ 8); a byte read at 0x004549C4; the read destination at 0x00455B12 and +
DAT_GMImageOffsets[i] at 0x00455BCB (loadGMFile); reads into buf + i and byte reads at 0x004D708F, 0x004D70D0 and
0x004D7100 through the global instance. loadGfxFile, loadGfxAtBufferEnd, renderLoadedGfx, loadGFX8 and
renderGfxTgxWithBlending later in this branch use it without (byte*) casts, and the constructor casts malloc's
result once; they compile the same (quick_diff unchanged). Main's one user,
checkIfGfxTgxStartsWithTransparentPixels (0x004549C0), compiles the same with either type (quick_diff 1.0000); the
next commit drops its now redundant (byte*) cast.

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

The commit before makes TextureRenderCore.gmAndGfxImageDataBuffer a byte*, so main's
((byte*)this->gmAndGfxImageDataBuffer)[byteIndex] is this->gmAndGfxImageDataBuffer[byteIndex]. It is a commit of its
own so that the header commit stays header-only. The includes now start with ../TextureRenderCore.func.hpp (which
brings TextureRenderCore.hpp and GfxRef.hpp), as the style lint asks of every file a PR touches. quick_diff 1.0000
with and without the cast; reccmp 100.0%.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
transformRawWithMarkerUnkToRGB555To565 converts imageSize bytes of RGB555 pixels to RGB565 in place, from imageOffset
into the processed image data, and leaves pixels equal to 0xf81f untouched: magenta already in RGB565, the transparency
marker (the header's SKIPPING_MARKER loop). The loop is handwritten assembly in the original, the same instruction
stream in 0x0044C940, 0x0044CAE0 and 0x0044CB60: cmp edx, 0 where MSVC emits test, the pixel read with mov ax, word ptr
[esi] and every channel worked in 16-bit registers, the loop closed with a jmp back to its test. From gynt's asm in
cdaccb4 (origin/reimpl/TextureRenderCore, 2026-10-04, 100.0% there). Changed: the loop is the shared macro of
RGB555To565Asm.hpp (earlier in this branch); the locals are ushort, so the asm needs no word ptr overrides; the pointer
sum is (byte*) instead of (int); a line says the asm writes _blue and _green. Red stays in the dead imageOffset
parameter's slot, as in his file and the original (a third local instead: 85% in our 11-03 measurement). quick_diff
cannot measure it (it folds the asm's named stack slots into one token). Measured in a clean alone build of the branch
on main 1c29459: 100.0% raw and normalized.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
transformTileObjectToRGB565 converts one tile object, 512 bytes or 256 pixels, from RGB555 to RGB565 in place, from
imageOffset into the processed image data. The loop is handwritten assembly in the original, the same instruction stream
in 0x0044C940, 0x0044CAE0 and 0x0044CB60: cmp edx, 0 where MSVC emits test, the pixel read with mov ax, word ptr [esi]
and every channel worked in 16-bit registers, the loop closed with a jmp back to its test. From gynt's asm in e9a1e28
(origin/reimpl/TextureRenderCore, 2026-10-04, 100.0% there). Changed: the loop is the shared macro of RGB555To565Asm.hpp
(earlier in this branch); the locals are ushort, so the asm needs no word ptr overrides; the pointer sum is (byte*)
instead of (int); a line says the asm writes _blue and _green. Red stays in the dead imageOffset parameter's slot, as in
his file and the original (a third local instead: 85% in our 11-03 measurement). 512 is in decimal (his 200h). His C
draft on his fork's reimpl/UI-Rendering-development is at 12.5%. quick_diff cannot measure it (it folds the asm's named
stack slots into one token). Measured in a clean alone build of the branch on main 1c29459: 100.0% raw and normalized.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
transformRawToRGB555To565 converts imageSize bytes of RGB555 pixels to RGB565 in place, from imageOffset into the
processed image data. The loop is handwritten assembly in the original, the same instruction stream in 0x0044C940,
0x0044CAE0 and 0x0044CB60: cmp edx, 0 where MSVC emits test, the pixel read with mov ax, word ptr [esi] and every
channel worked in 16-bit registers, the loop closed with a jmp back to its test. From gynt's asm in 8d62e58
(origin/reimpl/TextureRenderCore, 2026-10-04, 100.0% there). Changed: the loop is the shared macro of RGB555To565Asm.hpp
(earlier in this branch); the locals are ushort, so the asm needs no word ptr overrides; the pointer sum is (byte*)
instead of (int); a line says the asm writes _blue and _green. Red stays in the dead imageOffset parameter's slot, as in
his file and the original (a third local instead: 85% in our 11-03 measurement). quick_diff cannot measure it (it folds
the asm's named stack slots into one token). Measured in a clean alone build of the branch on main 1c29459: 100.0% raw
and normalized.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
renderBlendedBlackBox darkens the box from (drawX, drawY) to (drawXEnd, drawYEnd), both ends included, on the
pencil surface: each pixel that is not black gets its colour components looked up in the blend strength's row of
DAT_BlendFilterArrays. Strengths above 32 count down again (64 - strength, clamped at 64); the tables are built on
first use. The pixel loops are handwritten assembly in the original (cmp dx, 0 where MSVC emits test, the colour
components worked in 16-bit registers, the loop closed with a jmp back to its test, mul for the row offset), one
block for RGB555 and one for RGB565.

From gynt's 74226ca on reimpl/TextureRenderCore (2026-10-04, 91.9%: "Asm loops recovered, two extra locals for
globals"; earlier 2f3c3a0 at 9.1%; his fork's reimpl/UI-Rendering-development has the C draft 63cc49f at
14.3%). His commit already has both asm blocks instruction for instruction, the clamp as two ifs (the compiler
threads the jump from the first into the second's subtraction, as in the original) and the table row kept in
blendStrengthUnk's stack slot.

Changed here: his _surfacePtr and _horizontalByteSize locals dropped, because the asm names
DAT_PencilRenderCore::instance's fields as the original reads the globals (0x0044F07E, 0x0044F08E), as main's
ApplyBlending does; that closed his last 8%. The table row as short* const blendTable =
DAT_BlendFilterArrays::instance[blendStrengthUnk][0], which the asm reads, instead of (int)((char*)table + strength
* 0x200) stored back into the parameter: MSVC gives the local the parameter's dead stack slot, so the code is the
same. else in place of return; decimals; snake_case labels; his plate comment dropped.

quick_diff gives the same 109 instructions with only the asm's named stack slots differing, which it cannot
resolve. Measured in a clean alone build of the branch on main 1c29459: 100.0% raw and normalized.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
renderTgxWithColorAndBlendingUnk blends fillColorUnk into the surface under a TGX picture, each pixel by the
picture's green channel times (32 - blendStrengthUnk) / 32, clipped to the surface's height range: the surface, its
line jump and the colour mode's channel shifts are picked in C, the token loop is handwritten assembly in the
original, transcribed in an __asm block. From gynt's renderTgxWithColorAndBlendingUnk.cpp in a501cdd
(origin/reimpl/TextureRenderCore, 2026-10-04, 97.1% there). Changed: the asm reads the surface pointer from
DAT_TextureRenderCoreObject::instance.currentRenderSurface, as the original does (through this in his file, which
cost an instruction and the stack slot this needs); for the menu surface the line jump is computed before the line
width, as in the original's instruction order (and as drawTgxOnFlaggedSurface has it); his draw labels for the 0x00
and 0x40 tokens swapped to match what they do (token 0, TT_STREAM_OF_PIXELS, reads a source pixel per destination
pixel, 0x40 blends one pixel over the run), as drawTgxOnFlaggedSurface and renderTgxWithColorUnk have them; the red
channel's shift in a local redShift instead of reusing width (MSVC gives it width's dead slot: the same code); the
TgxToken names in the token decode and snake_case labels, as the siblings; the locals named without underscores, in
his declaration order, which gives the original's stack slots (-16 heightStart, -12 lineBytes, -8 lineJump, -4
greenShift in our listing); 32, 10, 11, 4056 and 4056 * 2 as decimals; the asm's other hex immediates in 0x form;
the unused usings dropped; clang-format off around the asm; and comments. Kept, with a comment each: 32 -
blendStrengthUnk in the parameter's own slot (a fresh local: reccmp 100.0% -> 93.6%) and the map arm first (== with
the arms swapped: quick_diff 0.8678 -> 0.8319). quick_diff gives the same 295 instructions; besides the asm's named
stack slots it shows only and bl/al, TT_TGX_PIXEL_HEADER printed as -0x20 in our listing, the same byte. Measured
in a clean alone build of the branch on main 1c29459: 100.0% raw and normalized.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
loadGfxFile loads a gfx file into the image buffer after the files loaded so far, if it still fits into the buffer's
18250000 bytes (0x1167910), converts it to RGB565 when the game runs in that mode, and records the file's offset, width
and height. From gynt's loadGfxFile.cpp in 42f6c99 (origin/reimpl/TextureRenderCore, 2026-10-04, 91.8% there).
Changed: the bound test turned round, 0x1167910 < (int)(_currentBufferSize + _size) to offset + size > 18250000, with
size an int as getCurrentResourceSize returns it (his size_t is why the cast was needed; the compare stays signed, jle
as in the original); the locals declared where they are assigned (const size, offset and destination); the success flag
folded into a truthiness test; the destination as a byte* into the buffer, a byte* since the header commit earlier in
this branch, instead of (void*)((int)buffer + offset), so destination + 8 instead of (int)_tgxLoadLocation + 8; the
width and height read as ((int*)destination)[0] and [1]; - 8, ++ and - 1 instead of + -8, + 1 and + -1; the
TextureRenderCore.func.hpp include it had twice and the unused FileResourceType, ColorMode and BOOLEnum includes and
usings dropped; and comments. quick_diff gives the same 61 instructions for his file and this one (0.9836; the one
difference is the 0x1167910 immediate, which quick_diff cannot tell from an exe address). His file unchanged reads
100.0% raw and normalized in our alone build too (tmp/trc-try 039583df2 on main 1c29459), so his 91.8% came from his
build, not from the source. Measured in a clean alone build of the branch on main 1c29459: 100.0% raw and normalized.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
loadGfxAtBufferEnd loads a gfx file (the menu edges, for example, as TheRedDaemon's comment said), packed backwards from
the end of the buffer's 18250000 bytes (0x1167910; the decompiler showed it as an address in DAT_GameState, which gynt
replaced), and records it like loadGfxFile. From gynt's loadGfxAtBufferEnd.cpp in e3c6eb1
(origin/reimpl/TextureRenderCore, 2026-10-04, 91.7% there). Changed: size an int, as getCurrentResourceSize returns it,
which drops the (int) on _size in the destination sum (his - (int)_size); the locals declared where they are assigned
(const size and destination; the returned index is computed in the return); the success flag folded into a truthiness
test; the destination as a byte* into the buffer, a byte* since the header commit, so destination + 8; the (char
const*)((int)fileName) cast dropped (resolveResourceFileName takes char const*); the width and height read as
((int*)destination)[0] and [1]; 0x1167910 as decimal, and the redundant parentheses of his (0x1167910 - ...) - _size
dropped; - 1, - 8 and -- instead of + -1, + -8 and + -1; the TextureRenderCore.func.hpp include it had twice dropped;
the decompilerscript plate and block comments turned into line comments; the unused FileResourceType, ColorMode,
BOOLEnum and DAT_GameState includes and usings dropped. quick_diff gives the same 72 instructions for his file and this
one (0.9722, the only difference the 0x1167910 immediate). His file unchanged reads 100.0% raw and normalized in our
alone build too (tmp/trc-try 039583df2 on main 1c29459), so his 91.7% came from his build, not from the source.
Measured in a clean alone build of the branch on main 1c29459: 100.0% raw and normalized.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
renderLoadedGfx draws a gfx file loaded by loadGfxFile or loadGfxAtBufferEnd through
renderFunctionResponsibleForManyGameObjects, with drawBufferChoiceValue switched to
currentRenderSurfaceIdentifierUnk_0x8 for that one call; the pixels follow the file's 8-byte header. From gynt's
renderLoadedGfx.cpp on his fork's reimpl/UI-Rendering-development (63cc49f, 2026-10-25, 75.0% there). His earlier
commits 7c3049b on reimpl/TextureRenderCore (2026-10-03, 71.9%) and 3f52283 on his fork (2026-09-30, 71.88%)
have the same function: saving drawBufferChoiceValue, switching it to currentRenderSurfaceIdentifierUnk_0x8 for the
call and restoring it after are his. Changed: the source pointer is named, between saving drawBufferChoiceValue and
switching it, which is where the original computes it (inline in the call, as in his file: quick_diff 0.7500; named
before the save: 0.8438; here: 1.0000, 32/32); the sum pointer first, buffer + offset + 8, without a cast since the
buffer is a byte* (header commit), instead of his offset + 8 + (int)buffer; the saved value const and named
savedTarget; the duplicated TextureRenderCore.func.hpp include dropped; and comments. Measured in a clean alone
build of the branch on main 1c29459: 100.0% raw and normalized.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
drawTgxOnFlaggedSurface decodes a TGX picture onto the menu or the map surface, whichever
currentRenderSurfaceIdentifierUnk_0x8 names, clipped to renderingRect_16c854: the surface and its line jump are
picked in C, the height clipped at the bottom, and the token loop (transparent runs, pixel streams, repeated
pixels, line ends, each run clipped left and right, the rows above the top skipped) is handwritten assembly in the
original, transcribed in an __asm block. From gynt's drawTgxOnFlaggedSurface.cpp in 246507f
(origin/reimpl/TextureRenderCore, 2026-10-04, 98.6% there). Changed: the asm reads the surface pointer from
DAT_TextureRenderCoreObject::instance.currentRenderSurface, as the original does (through this in his file, which
cost an instruction and the stack slot this needs); the draw part's labels for the 0x00 and 0x40 tokens swapped to
match what they do (0x00 copies a pixel stream, 0x40 repeats one pixel), as the skip part already had them; the
line jump in a local lineJump instead of reusing gfxWidth (MSVC gives it gfxWidth's dead slot: the same code); the
TgxToken names in the token decode and snake_case labels, as renderTgxWithColorUnk; the C locals const and declared
where they are assigned, without underscores; 4056 and 4056 * 2 for the map surface's width instead of 0xfd8 and
0x1fb0; - gfxWidth * 2 instead of + gfxWidth * -2; the asm's hex immediates in 0x form, as main's asm has them; the
unused RenderTarget using dropped; clang-format off around the asm; and comments. quick_diff gives the same 215
instructions; besides the asm's named stack slots it shows only and bl/al, TT_TGX_PIXEL_HEADER printed as -0x20 in
our listing, the same byte. Measured in a clean alone build of the branch on main 1c29459: 100.0% raw and
normalized.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
loadCampaignMapGfxUnk loads the campaign map's six palettes (the .act files named in
DAT_BlendingDefinedData.campaign_map_england, 256 RGB triples each) and converts every colour to the screen's
RGB565 or RGB555 into campaignMapColorMapsUnk_0x16c886, keeping magenta (0xfc1f in RGB555) as the transparency
marker 0xf81f. From gynt's 37368ca on reimpl/TextureRenderCore (2026-10-04, 88.2%: "Component locals widened and
loop bound made resolver-relative"), which already has the colour components as ushort locals with green read first
(red first: quick_diff 0.8716); his fork's reimpl/UI-Rendering-development has the earlier C form 63cc49f at
13.9%. Changed: plain for loops over the six files and the 256 colours instead of the decompiler's pointer walks
over the name array and the palette (MSVC unrolls the colour loop four times on its own, as in the original, where
his plate says MSVC1400 does not unroll and writes the four conversions out); the palette as byte[256][3]; the
s_act_005a5064 pointer for the "act" extension; countof and sizeof for the loop bounds and the palette's size; the
masks as ~7 and ~3 (his 0xfff8 and 0xfffc; the same code) and the RGB555 top bit as 1 << 15; the two magentas named
in an enum built from their bit fields; main's names. quick_diff 0.9797, 147/149, the rest its artefacts (the
security cookie's name, two alignment jumps, ret 0). Measured in a clean alone build of the branch on main
1c29459: 100.0% raw and normalized.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Constructor_TextureRenderCore keeps the buffer sizes (the second unknown buffer is half the first), sets the
defaults, calls clearSomeMemory, then allocates the processed image buffer, the two unknown buffers when
unknownMemSize is not 0, the gm and gfx buffer and the face buffer; bufferAllocStateUnk_0x0 records which
allocation failed (1, 2 or 3). From gynt's Constructor_TextureRenderCore.cpp on his fork's
reimpl/UI-Rendering-development (63cc49f, 2026-10-25, 52.1% there). His earlier commits 636bfa1 on
reimpl/TextureRenderCore (2026-10-03, 49.0%) and 4411bcf on his fork (2026-10-01, 49.03%) have the same code: the
sizes stored first with the second unknown buffer at half size, the defaults, the clearSomeMemory call and the
allocations with the failure codes 1, 2 and 3 are his. Changed: an early return for each failed allocation, as the
original has them (his nested ifs share one failure block); the unknownMemSize tests with the non-zero case first,
as in the original; the face sizes zeroed in one loop over the 36 ints (countof) of the header commit earlier in
this branch (quick_diff: the nested form 0.6279, early returns with 28 + 8 stores 0.9380, this 1.0000, 129/129);
malloc's result cast to byte* for gmAndGfxImageDataBuffer, a byte* since the other header commit; main's field
names (field_0x2c, field_0x128, field_0x12c, colorPaletteOverride); 36 * 8448 for the face buffer; NULL and truth
tests for the pointers; the plate comment and the unused usings and includes dropped; and comments. Measured in a
clean alone build of the branch on main 1c29459: 100.0% raw and normalized.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
renderGMWithBlending draws picture imageID (counted from 1) of a gm file: interface elements and compressed images
through renderFunctionResponsibleForManyGameObjects, or renderInterfaceOrBuildingOccupationArea when blended, and
animations through renderUnitAnimationUnk or renderUnitAnimationWithBlendingUnk; a blend strength of 32 draws
nothing and 0 draws unblended. From gynt's 756ed2e on reimpl/TextureRenderCore (2026-10-04, 69.4%: "Dispatch
block order"), which already has the early returns for strength 32 and for the unblended case and the index
computed once; his fork's reimpl/UI-Rendering-development has the earlier nested-if form 63cc49f at 21.2%.
Changed: one else-if arm per image type, the two identical calls in their own arms, and the image type read in each
test, which is what gives the original's jumps and registers (his || with a local, in the early-return form:
quick_diff 0.8000; one arm per type with a local: 0.8235; a switch: 0.9059; this: 1.0000, 85/85); main's
GMFirstPictureIndex for the renamed GMTotalPicturesProcessed; - 1 instead of + -1; the source pointer as byte*
arithmetic, pointer first as main's transformTgxCompressedImageToRGB565 writes it, instead of offset + (int)pointer
(quick_diff 1.0000 either way); (byte*)source instead of (byte*)((int)...); the (int) casts on width and height
dropped; 32 as decimal; the duplicated TextureRenderCore.func.hpp include and the unused usings and includes
dropped; and comments. Measured in a clean alone build of the branch on main 1c29459: 100.0% raw and normalized.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
drawTgxGmOnFlaggedSurface draws picture imageIndexInGm (counted from 1) of a gm file, when the file holds interface
elements or compressed images, through drawTgxOnFlaggedSurface. From gynt's drawTgxGmOnFlaggedSurface.cpp in fcb3ffa
(origin/reimpl/TextureRenderCore, 2026-10-04, 95.7% raw and 100% normalized there). Changed: main has since renamed the
global GMTotalPicturesProcessed (0x00D7CE90) to GMFirstPictureIndex, so the file uses that name and include (his file
does not compile on main without it); the locals declared where they are assigned (const imageIndex and source), - 1
instead of + -1; the source pointer as byte* arithmetic, pointer first as main's transformTgxCompressedImageToRGB565
writes it, instead of offset + (int)pointer (quick_diff 1.0000 either way); OpenSHC:: names in place of his IO:: and
UI::; the TextureRenderCore.func.hpp include it had twice and the unused GmImageType using dropped; and comments. The
two image-type tests stay separate, as in the original (one test with ||: quick_diff 1.0000 -> 0.3014). quick_diff
1.0000 (47/47). Measured in a clean alone build of the branch on main 1c29459: 100.0% raw and normalized.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TextureRenderCore::loadGFX8, gynt's code from 4a40da6 on reimpl/TextureRenderCore (92.3% recorded there,
2026-10-04; that branch's status file still reads 85.4%). Gynt's fork's reimpl/Wilps-2026-10-18 (8ca7861,
2026-10-27) carries the file unchanged. It loads a .gfx8 file into the image buffer behind the last loaded one,
refuses it when it would pass the buffer's 18250000 bytes, records the next image's offset and this one's width and
height (the file's first two ints), and returns the new image's index. His last step, incrementing totalLoadedGfx
in memory and returning the new value - 1, was the fix: the copy in gynt's fork's reimpl/UI-Rendering-development
(63cc49f, 91.3%) still returns a copy of the count taken before the increment.

His unchanged file reads reccmp 100.0% in our build (Globals and function resolvers on, --ignore-security-cookie),
so the gap from 92.3% lies in how it was measured then, not in the code. quick_diff reads 0.9808 for his file and
this one alike (only the buffer limit, which it shows as a symbol).

This commit restyles it: named const locals at first use for _size / _destination / _currentBufferFillSize; the
size as int, which getCurrentResourceSize returns, so the bound test needs no (int) cast; the bound test turned
round and in decimal (0x1167910 < (int)(...) -> offset + size > 18250000); the BOOLEnum _success local folded into
a truth test; the cast on the file name dropped; the destination as a byte* into the buffer, with no casts
(gmAndGfxImageDataBuffer is a byte* since this branch's header commit); ((int*)destination)[0] / [1] for the header
ints; ++ and - 1 for = x + 1 and + -1; IO:: written OpenSHC::IO::; the BOOLEnum and FileResourceType includes and
his two usings dropped; comments. reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TextureRenderCore::renderGMWithAlphaMask, from gynt's 92ec6d0 on reimpl/TextureRenderCore (67.4% recorded there,
2026-10-04), after main's rename GMTotalPicturesProcessed -> GMFirstPictureIndex (gynt's fork's
reimpl/Wilps-2026-10-18 (8ca7861, 2026-10-27) already has it). His step already returns after the isZoom2 path
and reads this->gmProcessedImageData; the copy in gynt's fork's reimpl/UI-Rendering-development (63cc49f, 46.1%)
still went on to draw the image a second time through the mask.

His file reads reccmp 72.0% in our build (quick_diff 0.7273). Two differences were left. The original draws the
mask with renderGM on the global DAT_TextureRenderCoreObject (mov ecx, DAT_TextureRenderCoreObject at 0x0045586A),
not on this (with this: quick_diff 1.0000 -> 0.7841). And it reads the alpha surface pointer into a local before
the zoom test (loaded at 0x004557B8; read at its use: quick_diff 1.0000 -> 0.9091).

Restyled: named const locals for the picture indices; imageData as a byte* for pvVar2, one cast for both calls;
savedTarget for _tempBufferChoiceValueUnk; a truth test on isZoom2; - 1 for + -1; the (void*) and int casts
dropped; the duplicate TextureRenderCore.func.hpp include and the unused using RenderTarget dropped; comments in
main's kept form. The mask's width is re-read from currentImageWidth after the store, as in his draft (MSVC uses
the stored register; a local for it gives the same code). 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>
TextureRenderCore::transformTgxFromRGB555ToRGB565, gynt's code from f7163ef on reimpl/TextureRenderCore (100.0%
recorded there, 2026-10-04; that branch's status file still reads 7.8%). Gynt's fork's reimpl/Wilps-2026-10-18
(8ca7861, 2026-10-27) carries f7163ef unchanged; his reimpl/UI-Rendering-development (63cc49f) is a separate
line without the 10-04 commits and still has the C form at 8.9%. His file reads reccmp 100.0% in our build.

The original's loop is handwritten assembly: mov ecx, 0 at 0x0044C9DD, cmp edx, 0 where MSVC emits test, every
channel computed in 16-bit registers, the red channel parked in tgxDataPtr's own slot ([ebp + 8]). His commit
explains why the parameter copy stays C++: mov eax, [ebp + 8] comes before the ebx/esi saves, which only a
compiler-generated statement does. The instruction stream is unchanged here. The pixel conversion is the macro
RGB555To565Asm.hpp holds for 0x0044C940, 0x0044CAE0 and 0x0044CB60, so it is MACRO_RGB555_TO_565_PIXEL here, twice:
with the marker test at the stream pixel (0x0044CA08), without it at the repeating pixel (0x0044CA6D), with
tgxDataPtr's dead slot holding red. The __asm block is split around the two expansions (asm labels are
function-scoped); the je to repeating_pixels stays short and the one to transparent_pixels near, as in the
original.

This commit restyles it: the TgxToken constants by name in the asm through using declarations (TT_TGX_PIXEL_HEADER,
TT_TGX_PIXEL_LENGTH, TT_NEWLINE, TT_REPEATING_PIXELS, TT_TRANSPARENT_PIXELS); the locals in the order tgxPtr,
_blue, _green, the header's names (his were _blue, _green, _texPtr; both orders match), with ushort channels for
his int ones; ushort* const for his TgxTokenByte* (the cast dropped); labels named after the token kinds; his plate
comment dropped; one-line comments on why the parameter is copied and who writes the channels. quick_diff cannot
name the slots of an asm block (0.7711, 83 of 83 instructions, the rest equal); reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TextureRenderCore::renderTgxWithColorUnk, from gynt's a6053d6 on reimpl/TextureRenderCore (87.0% recorded there,
2026-10-04; gynt's fork's reimpl/UI-Rendering-development has an older C form at 14.3%; gynt's fork's
reimpl/Wilps-2026-10-18 (8ca7861, 2026-10-27) renames the function renderTgxWithSolidColor). His commit found the
split: the surface choice and the height clamp are C++, the token loop is handwritten assembly (push ebx / push edi
at 0x0044F769, mov ecx, 0, mul edx). His file reads reccmp 87.0% in our build. Four differences were left, all
fixed here:

- The asm reads the surface pointer straight from the global, mov edi,
  DAT_TextureRenderCoreObject::instance.currentRenderSurface, as renderFunctionResponsibleForManyGameObjects on
  main does; his body says inline asm cannot name a :: global, and his mov eax, this plus a field offset spilled
  this into an extra stack slot.
- The fill colour is loaded once before each fill loop: the original's loops jump back to the store (jne
  0x0044F821, jne 0x0044F835), not to the mov ax above it.
- The screen-menu branch computes the row step from the global before storing lineBytes, so the original keeps
  byteSizeOfOneHorizontalLine - width * 2 in esi (saved in the prologue) while eax loads the height range
  (quick_diff 0.7570 -> 0.8016).
- The clamp is height + yPos > heightEnd (cmp edx, eax; jle at 0x0044F75A), where his had the operands the other
  way round.

His labels had the stream and repeating blocks swapped: token 0 (TT_STREAM_OF_PIXELS) is the block whose loop steps
the source per pixel (add esi, 2 inside the loop at 0x0044F838), token 64 the one that skips one source pixel
before it.

Kept: the map arm first with != (== with the arms swapped: quick_diff 0.8016 -> 0.7115), and the four locals
declared before the if, as both arms assign them. Restyled: the row step in a local lineJump where his draft reused
width (lineJump and lineBytes, the names its siblings use) (MSVC gives it width's dead slot: the same code, reccmp
100.0%); TgxToken names in the asm through using declarations; labels named after the token kinds; decimal
constants (4056, the map surface's width in pixels, and 4056 * 2 for its line); plain local names; the unused using
RenderTarget dropped; one-line comments in place of the long NOTE block. quick_diff 0.8016 (126 of 126
instructions; it cannot name the asm block's slots); reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TextureRenderCore::renderGfxTgxWithBlending, from gynt's 3aeeada on reimpl/TextureRenderCore (49.3% recorded
there, 2026-10-04; the copy in gynt's fork's reimpl/UI-Rendering-development reads 52.1%). It draws a loaded .gfx
image blended onto the surface named by currentRenderSurfaceIdentifierUnk_0x8, for blend strengths 0-31 only. His
file reads reccmp 52.1% in our build.

Rewritten from the binary. In the source that matches, drawBufferChoiceValue is saved first and the image address
is worked out before the blend test (the lea at 0x00454A0C; the compiler schedules the save's load after it, at
0x00454A18; the address first in the source: quick_diff 1.0000 -> 0.9211). The render target is restored only on
the drawing path: the skip at 0x00454A1B jumps straight to the epilogue (restored on both paths, as in the draft:
0.8947). Blend strengths outside 0-31 return early; the draft's (uint) bound test is written blendStrengthUnk < 0
|| blendStrengthUnk > 31 (the same cmp ebx, 31; ja, and the guarded form gives the same code).

Restyled: savedTarget and source as const locals, the names its sibling renderLoadedGfx uses; the image address
with no cast but the (ushort*), as gmAndGfxImageDataBuffer is a byte* since this branch's header commit; the
duplicate TextureRenderCore.func.hpp include dropped, decimal bound, comments in main's kept form. 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>
TextureRenderCore::loadGmFiles, from gynt's df9b346 on reimpl/TextureRenderCore (27.0% recorded there,
2026-10-04, "Fixed off-by-one in the unterminated-table counter; string compare expands differently"; earlier
f3c5b26 and d4c4277 at 27.0%). Gynt's fork's reimpl/Wilps-2026-10-18 (8ca7861, 2026-10-27) carries df9b346
with GMFirstPictureIndex and loadCampaignMapGfxUnk renamed loadCampaignMapPalettes. His other line, 63cc49f on
gynt's fork's reimpl/UI-Rendering-development (29.4% recorded) and gynt's fork's reimpl/UI-MenuItems-development
(405b988, 2026-11-02), steps the count by 2 when no "null" is found (242 where the binary has 241: the one add
eax, 1 at 0x00455C92). This commit keeps df9b346's behaviour. It counts the names in the 240 x 1000-byte list up
to the "null" entry for the loading bar, loads each .gm1 in turn (recording its first picture index in
GMFirstPictureIndex), loads the campaign map gfx and sets the font set size. His df9b346 file reads reccmp 29.4%
in our build.

Rewritten from the binary. The two byte-compare loops in the draft are strcmp against s_null_005a506c: MSVC's
intrinsic for a constant string is mov ecx, 5; xor edx, edx; repe cmpsb (0x00455C7A and 0x00455CBE), the same
pattern as the cheat sheet's strcmp example and main's loadWavSounds (memcmp expands differently). Both counters
step at the top of their loops (add eax, 1 at 0x00455C70, add ebp, 1 at 0x00455CB4), so each for loop steps its
counter first thing in the body (++i in the for header: quick_diff 0.9538 -> 0.9385). The loading bar's extra step
when no "null" is found is a found flag that MSVC folds away (n + 1 after a plain loop: 0.9385); it ties with the
draft's goto, so there is no goto. The names are walked by pointer, as the original steps a register and then the
parameter's own slot (add dword ptr [esp + 0x14], 1000 at 0x00455CE5; indexing: 0.7313).

Restyled: GMFirstPictureIndex for main's renamed GMTotalPicturesProcessed, the gm id 87 as GID_FONT_STRONGHOLD_AA,
the found flag a BOOLEnum, loadingBarSteps for the count (it holds the files + 1), comments in main's kept form,
the string's text above each strcmp. quick_diff 0.9538 (only the listing's spelling of repe cmpsb and the division
constant, which quick_diff misreads; the listing has 0x66666667 like the original); reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TextureRenderCore::renderGM, from gynt's 9de7fc1 on reimpl/TextureRenderCore (70.7% recorded there, 2026-10-04:
"Dispatch block order"; earlier f1ae7c4 and 481bb86 at 12.9%). Gynt's fork's reimpl/Wilps-2026-10-18
(8ca7861, 2026-10-27) carries it with GMFirstPictureIndex and the callees renamed renderTgxImage and
renderPalettedTgx. His other line, 63cc49f on gynt's fork's reimpl/UI-Rendering-development (15.1%) and gynt's
fork's reimpl/UI-MenuItems-development (405b988, 2026-11-02), calls 0x0044D3D0 outside the type test, so every
type, animations too, goes through it; this commit keeps 9de7fc1's behaviour, which is the binary's. It draws
picture imageID of a .gm1 through the renderer for its image type: interface elements and compressed images through
renderFunctionResponsibleForManyGameObjects, animations through renderUnitAnimationUnk. His 9de7fc1 file reads
reccmp 43.9% in our build.

The original tests the type with compares in the order 1, 6, 2 (cmp esi, 1; je; cmp esi, 6; jne at 0x0045532B), so
it is no switch (as a switch: quick_diff 0.7073, MSVC's sorted sub chain). It is an if / else if chain with the
same call in the first two arms: MSVC keeps one copy and jumps forward into it from the first test. With type == 1
|| type == 6 the shared call lands at the end (0.6585); with returns in the arms the second test lands after the
call (0.9512). The image type is read after the image address, which puts gmID in esi and imageID in edx as in the
original (type first: 0.8193).

Restyled: imageIndex and source as const locals, the names of its sibling drawTgxGmOnFlaggedSurface; the image type
as the field's own GmImageTypeInt; byte* arithmetic for the image address; the GmImageType names; the
one-call-per-arm comment in the sibling's form. 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>
TextureRenderCore::renderFacesSmallUnk, from gynt's 711809e on reimpl/TextureRenderCore (96.3% recorded there,
2026-10-04: "Switch dispatch, row-start pointer and hoisted line step"; earlier 7a27623 and da98557 at 43.9%).
fork-6and8's tip carries the same file (its status line still says 43.9%); gynt's fork's reimpl/Wilps-2026-10-18
(8ca7861, 2026-10-27) carries it renamed drawBitmapFaceHalfSize; 63cc49f on gynt's fork's
reimpl/UI-Rendering-development and gynt's fork's reimpl/UI-MenuItems-development (405b988, 2026-11-02) have an
if / else chain through this->currentRenderSurface. It draws a face bitmap (64 x 66 pixels) at half size, every
other pixel of every other row, skipping magenta. His 711809e file reads reccmp 96.3% in our build.

What was left was the row step. The original hoists it in bytes before setting the row counter (sar eax, 1; add
eax, eax; mov ebp, 33 at 0x0044CE61) and steps with lea ecx, [eax + ebx]. With gynt's pre-loop pixels-per-line
local MSVC folds the doubling into lea ecx, [ebx + eax*2] (quick_diff 0.9608); with the division inside the loop
and down-counting loops it hoists the doubling after the counter (reccmp 98.1%); a pre-loop byte step swaps the lea
operands (98.1%). Count-up for loops give the original's order: MSVC turns them into the same down-counters (ebp =
33, edi = 32) but sets the counter after the hoisted step. The column loop needs != to stay rolled (column < 32:
0.9903 -> 0.8348); the row loop with < is the same code. The surface is stored through the global (this->: 0.9903
-> 0.8155).

Restyled: for loops with the row start as a loop-scoped const local, face / surface / lineByteWidth / pixel for the
draft's names, the button arm as one assignment each (the same code), byte* arithmetic for the bitmap address, 66 *
64 * 2 and 4056 * 2 for the face's and the map line's bytes, comments in main's kept form. quick_diff 0.9903 (only
the jmp over the loop's alignment padding, which the listing writes as npad); reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TextureRenderCore::transformTilesetToRGB565, gynt's code from 63cc49f on gynt's fork's
reimpl/UI-Rendering-development (37.5% there; 7292e3a on reimpl/TextureRenderCore has 29.2% and e5cd892 29.17%;
gynt's fork's reimpl/Wilps-2026-10-18 (8ca7861, 2026-10-27) carries 7292e3a with UI:: for OpenSHC::UI:: and the
plate comment dropped). It converts a tileset image to RGB565: the 512-byte tile through
transformTileObjectToRGB565 (0x0044CAE0), then, when the image header's direction is set, the TGX data after it
through transformTgxFromRGB555ToRGB565.

The original keeps this in ecx across the first call and reads [ecx + 0x78] after it (0x004552BF): LTCG, possible
because the callee's handwritten loop never touches ecx. So this file and transformTileObjectToRGB565.cpp (the loop
macro of RGB555To565Asm.hpp; reimplement: SHC_3BB0A8C1_0x0044CAE0, 1c36692, earlier in this PR) go into
cmake/compiler-flags-gl.txt; both entries are needed, as with the caller alone in /GL it spills this into esi as
without LTCG (quick_diff 0.4167). With both in /GL his unchanged 63cc49f file reads reccmp 100.0% in our build,
so the /GL entries are the fix. The callee stays at 100.0% in /GL, and 0x004552A5 is its only caller.

Restyled: byte* arithmetic for the TGX address instead of the int casts, decimal 512, the duplicate
TextureRenderCore.func.hpp include dropped, a comment. reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TextureRenderCore::drawBitmapFace, from gynt's b0012e8 on reimpl/TextureRenderCore (76.4% recorded there,
2026-10-04: "Pixel local typed unsigned"; 22bca4d before it also 76.4%, ffd4161 and d469777 at 64.2%). The
same file is the tip of fork-6and8/reimpl/TextureRenderCore and is on gynt's fork's reimpl/Wilps-2026-10-18
(8ca7861, 2026-10-27) unchanged. His other line, 63cc49f on gynt's fork's reimpl/UI-Rendering-development
(64.2%) and gynt's fork's reimpl/UI-MenuItems-development (405b988, 2026-11-02), already stores the surface in
each branch and reads it back, which this commit takes up. It draws a 64 x 66 face bitmap onto the current render
surface, skipping magenta pixels. His b0012e8 file reads reccmp 76.4% in our build.

Two things were left. The original sets the row counter after doubling the row step (lea ebx, [eax + eax]; mov edi,
66 at 0x0044CDAF): count-up for loops give that order, where gynt's down-counting do-whiles set the counter first.
And the original holds the face pointer in esi and the surface in edi, which then becomes the row counter: with a
surface local MSVC swaps the two (quick_diff 0.9804 -> 0.7255), so each switch arm stores the surface straight into
DAT_TextureRenderCoreObject::instance.currentRenderSurface, as in 63cc49f, and the pixel address is worked out
from it (the stores are merged into one, as in the original at 0x0044CDA6; through this: 0.5524). The colour read
and the face step stay together before the test, as in the original (add esi, 2 at 0x0044CDD3).

Restyled: for loops, face / pixel / rowSkip / lineByteWidth for the draft's names, byte* arithmetic for the bitmap
address, 66 * 64 * 2, 4056 - 64 and 4056 * 2 for the face's bytes, the row gap and the map line's bytes, comments
in main's kept form. quick_diff 0.9804 (only the two jmps over the loops' alignment padding, which the listing
writes as npad); reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he next two header commits

The next two commits make TextureRenderCore.gmProcessedImageData a byte* and bitmapsFaces_0x94 a ushort
(*)[66][64]. _malloc returns void*, so the constructor casts both results, as it already does for
gmAndGfxImageDataBuffer. The casts also compile with today's void* fields, so every commit builds, and the header
commits stay header-only. quick_diff 1.0000; reccmp 100.0%.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It was void*. Every user adds a byte offset to it: the GM pictures' DAT_GMImageOffsets entries or an imageOffset
parameter in drawTgxGmOnFlaggedSurface (0x004554A0), renderGM (0x00455300), renderGMWithAlphaMask (0x004557B0),
renderGMWithBlending (0x00455390), transformRawToRGB555To565 (0x0044CB60), transformRawWithMarkerUnkToRGB555To565
(0x0044C940), transformTileObjectToRGB565 (0x0044CAE0), transformTilesetToRGB565 (0x00455290) and main's
transformTgxCompressedImageToRGB565 (0x00455270), all of which cast it to byte* first, and main's ApplyBlending,
BlitMapImageWithVerticalClip and RenderTerrainTilesCenterPiece, which cast it to char* (four casts). The
constructor mallocs it (0x004550BB). The exe has more absolute reads of 0x01FEA108 than this branch covers; the
ones above all add byte offsets (add reg, [0x01FEA108] or [reg + 0x78]).

The next commit drops the branch's nine byte* casts and main's one in transformTgxCompressedImageToRGB565. Main's
three char* users keep their casts, which still compile. Measured with this and the next two commits, in one alone
build: the branch's 24 functions and main's six users of the two retyped fields (ApplyBlending,
BlitMapImageWithVerticalClip, RenderTerrainTilesCenterPiece, transformTgxCompressedImageToRGB565, readBitmapFace,
setBMPFacesToMagenta) all read reccmp 100.0%, as on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kotijekriv and others added 2 commits November 7, 2026 10:07
It was void*. It holds the 36 face bitmaps, each 64 x 66 RGB565 pixels, 8448 (0x2100) bytes: the constructor
mallocs 36 * 8448 bytes (0x0045515E); drawBitmapFace (0x0044CD40) and renderFacesSmallUnk (0x0044CE00) step to face
n with imul 0x2100 and read 64 pixels a row over 66 rows (renderFacesSmallUnk every other one of each); main's
readBitmapFace and setBMPFacesToMagenta work in FACE_SIZE = 66 * 64 * 2. With the type, face n is
bitmapsFaces_0x94[n] and the 8448 and the byte* casts go.

The next commit drops the casts in drawBitmapFace and renderFacesSmallUnk; main's two users keep theirs, which
still compile. Measured together with the gmProcessedImageData commit: every user at reccmp 100.0% (see there).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gmProcessedImageData is a byte* and bitmapsFaces_0x94 a ushort (*)[66][64] since the two commits before. So the
(byte*) casts on gmProcessedImageData go in drawTgxGmOnFlaggedSurface, renderGM, renderGMWithAlphaMask,
renderGMWithBlending, transformRawToRGB555To565, transformRawWithMarkerUnkToRGB555To565,
transformTileObjectToRGB565, transformTilesetToRGB565 and main's transformTgxCompressedImageToRGB565, and
drawBitmapFace and renderFacesSmallUnk take face n as bitmapsFaces_0x94[n][0] instead of a byte* sum with 8448.
transformTgxCompressedImageToRGB565 also loses its duplicate TextureRenderCore.func.hpp include, which the checker
flags in a touched file. Main's ApplyBlending, BlitMapImageWithVerticalClip, RenderTerrainTilesCenterPiece,
readBitmapFace and setBMPFacesToMagenta keep their casts, which still compile; they are not touched here.
quick_diff unchanged for every file; reccmp 100.0% for all 30 functions measured (the branch's 24 and main's six
users).

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 7, 2026
int field_0x120; // 0x00000120 length: 4
int field_0x124; // 0x00000124 length: 4
byte* gmAndGfxImageDataBuffer; // 0x00000090 length: 4
ushort (*bitmapsFaces_0x94)[66][64]; // 0x00000094 length: 4

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the [66][64] part really necessary in the header for the 100% match?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question: no, it isn't needed. Your Ghidra sync (eef6f66) settled it anyway, with ushort* bitmapsFaces_0x94, so I followed it. I merged main into the branch (d96eff7), and the branch's TextureRenderCore.hpp is now the same as main's. drawBitmapFace and renderFacesSmallUnk take face n as bitmapsFaces_0x94 + n * 66 * 64, and the constructor casts its malloc to ushort* (a2dd7d0). MSVC folds that into the same imul reg, reg, 0x2100 the original has (0x0044CD46 in drawBitmapFace and 0x0044CE0A in renderFacesSmallUnk, each followed by add reg, [ecx + 0x94]). The constructor also writes the buffer's size as countof(this->bitmapFaceSizes) * 66 * 64 * sizeof(ushort) now, one 64 x 66 face bitmap per entry, instead of the raw 36 * 8448. Both give the same push 0x4a400.

Measured after the merge, in one alone build, all 31 read reccmp 100.0%:

  • the branch's 25 functions, including drawBitmapFace (0x0044CD40), renderFacesSmallUnk (0x0044CE00) and Constructor_TextureRenderCore (0x00455050)
  • main's six users of the retyped fields: readBitmapFace (0x0046C5A0), setBMPFacesToMagenta (0x00472230), RenderPlayerAvatars (0x004D8AE0, which reads bitmapFaceSizes[playerID + 19]), ApplyBlending, BlitMapImageWithVerticalClip and RenderTerrainTilesCenterPiece. They compile the same, so I left them alone.

The rest of your sync matches what this PR had: bitmapFaceSizes[36] and both byte* buffers. So the PR no longer changes TextureRenderCore.hpp. The only header it still adds is the injected RGB555To565Asm.hpp (in UI/Rendering/TextureRenderCore/ and tools/import/injected-headers/), so the declaration label stays until that file is on main.

kotijekriv and others added 3 commits November 7, 2026 20:00
Follows main's header sync eef6f66, which types the field the same way; the merge of main after the next commit
leaves this PR with no change to TextureRenderCore.hpp. 8a7df40 typed it ushort (*)[66][64]. The array part is
not needed for the match: with a plain ushort*, face n is bitmapsFaces_0x94 + n * 66 * 64, and MSVC folds that into
the same imul reg, reg, 0x2100 the original has (drawBitmapFace at 0x0044CD46, renderFacesSmallUnk at 0x0044CE0A,
each followed by add reg, [ecx + 0x94]). The element type stays ushort: the field holds the 36 face bitmaps, each
64 x 66 RGB565 pixels (8448 bytes), and main's setBMPFacesToMagenta fills them with fillMemory_ShortValue.

Measured with the next commit in one alone build: drawBitmapFace (0x0044CD40), renderFacesSmallUnk (0x0044CE00),
Constructor_TextureRenderCore (0x00455050) and main's readBitmapFace (0x0046C5A0) and setBMPFacesToMagenta
(0x00472230) all read reccmp 100.0%. Main's two users cast the field and compile the same; they are not touched.
This commit is header-only, as AGENTS.md asks; the build needs the next commit, because no cast in the
constructor's assignment compiles with both the old and the new type.

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

bitmapsFaces_0x94 is a ushort* since the commit before. drawBitmapFace and renderFacesSmallUnk take face n as
bitmapsFaces_0x94 + n * 66 * 64 instead of bitmapsFaces_0x94[n][0]. The constructor casts its malloc to ushort* and
writes the buffer's size as countof(this->bitmapFaceSizes) * 66 * 64 * sizeof(ushort), one 64 x 66 RGB565 bitmap
per entry of bitmapFaceSizes, where it had the raw 36 * 8448; both fold to the same push 0x4a400. quick_diff
unchanged; reccmp 100.0% for the three and for main's readBitmapFace and setBMPFacesToMagenta, which are not
touched.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gynt
gynt merged commit 6d45c01 into sourcehold:main Nov 7, 2026
3 of 4 checks passed
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.

2 participants