From f71b2b2a504ccd1ad386c6a6a10e7e673ab62fa7 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:07:05 +0100 Subject: [PATCH 01/34] TextureRenderCore: add RGB555To565Asm.hpp, the original's handwritten 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 cdaccb483, e9a1e28bb and 8d62e5863 (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 Co-Authored-By: Claude Opus 5.5 --- .../TextureRenderCore/RGB555To565Asm.hpp | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/RGB555To565Asm.hpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/RGB555To565Asm.hpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/RGB555To565Asm.hpp new file mode 100644 index 0000000000..7449abd5a9 --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/RGB555To565Asm.hpp @@ -0,0 +1,91 @@ +/** + HAND WRITTEN - not generated. + + path: 'OpenSHC/UI/Rendering/TextureRenderCore/RGB555To565Asm.hpp' + + Converting RGB555 pixels to RGB565 in place is handwritten assembly in the original, and it is a + MACRO: the identical instruction stream appears, never as a call, as the whole loop in + transformRawWithMarkerUnkToRGB555To565 (0x0044C940), transformTileObjectToRGB565 (0x0044CAE0) and + transformRawToRGB555To565 (0x0044CB60), and as the pixel body twice in transformTgxFromRGB555ToRGB565 + (0x0044C9C0: at 0x0044CA08 with the marker test, at 0x0044CA6D without). It is recognisable by + + - "cmp edx, 0" where MSVC would emit "test edx, edx", + - the pixel read with "mov ax, word ptr [esi]" and every channel computed in 16-bit registers, + where MSVC would emit movzx and work in 32 bits, + - the loop closed with an unconditional "jmp" back to its test. + + Red goes into a dead parameter's stack slot, as in the original. + + The macros expect these names in the enclosing function: + + ushort _blue declared after the pixel pointer + ushort _green declared after _blue + RED the dead parameter that holds red: imageOffset in the loops, tgxDataPtr in + 0x0044C9C0 + + and the loops also + + ushort* _colorPtr the first pixel, gmProcessedImageData + imageOffset, declared first + int imageOffset the parameter + + MACRO_RGB555_TO_565_PIXEL converts the pixel at [esi], then steps edx back by 2 and esi on by 2. With + MACRO_ASM_SKIP_MARKER_TEST and MACRO_ASM_SKIP_MARKER_LABEL it leaves pixels equal to 0xf81f untouched; + that is magenta already encoded as RGB565, the transparency marker. COUNT is the buffer size in bytes. + All of them clobber eax and ebx, the loops also edx and esi. They define assembler labels, so a loop + can be expanded once per function, and the pixel macro more than once, but with the skip label once. +*/ + +#pragma once + +// clang-format off + +#define MACRO_ASM_NONE +#define MACRO_ASM_SKIP_MARKER_TEST \ + __asm cmp ax, 0xf81f \ + __asm je skip_color +#define MACRO_ASM_SKIP_MARKER_LABEL \ + __asm skip_color: + +#define MACRO_RGB555_TO_565_PIXEL(RED, SKIP_TEST, SKIP_LABEL) \ + __asm mov ax, word ptr [esi] \ + SKIP_TEST \ + __asm mov bx, ax \ + __asm and bx, 0x1f \ + __asm mov _blue, bx \ + __asm mov bx, ax \ + __asm and bx, 0x3e0 \ + __asm shr bx, 5 \ + __asm mov _green, bx \ + __asm mov bx, ax \ + __asm and bx, 0x7c00 \ + __asm shr bx, 10 \ + __asm mov word ptr RED, bx \ + __asm mov ax, _blue \ + __asm mov bx, _green \ + __asm shl bx, 6 \ + __asm add ax, bx \ + __asm mov bx, word ptr RED \ + __asm shl bx, 11 \ + __asm add ax, bx \ + __asm mov word ptr [esi], ax \ + SKIP_LABEL \ + __asm sub edx, 2 \ + __asm add esi, 2 + +#define MACRO_RGB555_TO_565_LOOP_IMPL(COUNT, SKIP_TEST, SKIP_LABEL) \ + __asm mov esi, _colorPtr \ + __asm mov edx, COUNT \ + __asm next_color: \ + __asm cmp edx, 0 \ + __asm jle done \ + MACRO_RGB555_TO_565_PIXEL(imageOffset, SKIP_TEST, SKIP_LABEL) \ + __asm jmp next_color \ + __asm done: + +#define MACRO_RGB555_TO_565_LOOP(COUNT) \ + MACRO_RGB555_TO_565_LOOP_IMPL(COUNT, MACRO_ASM_NONE, MACRO_ASM_NONE) + +#define MACRO_RGB555_TO_565_LOOP_SKIPPING_MARKER(COUNT) \ + MACRO_RGB555_TO_565_LOOP_IMPL(COUNT, MACRO_ASM_SKIP_MARKER_TEST, MACRO_ASM_SKIP_MARKER_LABEL) + +// clang-format on From 1cb7eec91a824448b43e8aa46cd6d78a8b87d44a Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:07:05 +0100 Subject: [PATCH 02/34] [IMPORT]: add custom RGB555To565Asm.hpp Mirrors e66d14349 (the write_patches entry) and 302acd9f6 (which added the injected copy), which did this for LinkageNeighbourAsm.hpp: the importer regenerates the headers under src/, and acc215645 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 --- tools/import/ghidra-importer.py | 4 + .../injected-headers/RGB555To565Asm.hpp | 91 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 tools/import/injected-headers/RGB555To565Asm.hpp diff --git a/tools/import/ghidra-importer.py b/tools/import/ghidra-importer.py index d38fca89f3..5ffdf5d3c4 100644 --- a/tools/import/ghidra-importer.py +++ b/tools/import/ghidra-importer.py @@ -335,6 +335,10 @@ def write_patches(output_dir: pathlib.Path): (output_dir / "OpenSHC/Map/Navigation/PathFindingState/" / "LinkageNeighbourAsm.hpp").write_bytes( (pathlib.Path(__file__).parent / "injected-headers" / "LinkageNeighbourAsm.hpp").read_bytes() ) + + (output_dir / "OpenSHC/UI/Rendering/TextureRenderCore/" / "RGB555To565Asm.hpp").write_bytes( + (pathlib.Path(__file__).parent / "injected-headers" / "RGB555To565Asm.hpp").read_bytes() + ) pass # Overwrite hpp files in this function if not args.dry_run: diff --git a/tools/import/injected-headers/RGB555To565Asm.hpp b/tools/import/injected-headers/RGB555To565Asm.hpp new file mode 100644 index 0000000000..7449abd5a9 --- /dev/null +++ b/tools/import/injected-headers/RGB555To565Asm.hpp @@ -0,0 +1,91 @@ +/** + HAND WRITTEN - not generated. + + path: 'OpenSHC/UI/Rendering/TextureRenderCore/RGB555To565Asm.hpp' + + Converting RGB555 pixels to RGB565 in place is handwritten assembly in the original, and it is a + MACRO: the identical instruction stream appears, never as a call, as the whole loop in + transformRawWithMarkerUnkToRGB555To565 (0x0044C940), transformTileObjectToRGB565 (0x0044CAE0) and + transformRawToRGB555To565 (0x0044CB60), and as the pixel body twice in transformTgxFromRGB555ToRGB565 + (0x0044C9C0: at 0x0044CA08 with the marker test, at 0x0044CA6D without). It is recognisable by + + - "cmp edx, 0" where MSVC would emit "test edx, edx", + - the pixel read with "mov ax, word ptr [esi]" and every channel computed in 16-bit registers, + where MSVC would emit movzx and work in 32 bits, + - the loop closed with an unconditional "jmp" back to its test. + + Red goes into a dead parameter's stack slot, as in the original. + + The macros expect these names in the enclosing function: + + ushort _blue declared after the pixel pointer + ushort _green declared after _blue + RED the dead parameter that holds red: imageOffset in the loops, tgxDataPtr in + 0x0044C9C0 + + and the loops also + + ushort* _colorPtr the first pixel, gmProcessedImageData + imageOffset, declared first + int imageOffset the parameter + + MACRO_RGB555_TO_565_PIXEL converts the pixel at [esi], then steps edx back by 2 and esi on by 2. With + MACRO_ASM_SKIP_MARKER_TEST and MACRO_ASM_SKIP_MARKER_LABEL it leaves pixels equal to 0xf81f untouched; + that is magenta already encoded as RGB565, the transparency marker. COUNT is the buffer size in bytes. + All of them clobber eax and ebx, the loops also edx and esi. They define assembler labels, so a loop + can be expanded once per function, and the pixel macro more than once, but with the skip label once. +*/ + +#pragma once + +// clang-format off + +#define MACRO_ASM_NONE +#define MACRO_ASM_SKIP_MARKER_TEST \ + __asm cmp ax, 0xf81f \ + __asm je skip_color +#define MACRO_ASM_SKIP_MARKER_LABEL \ + __asm skip_color: + +#define MACRO_RGB555_TO_565_PIXEL(RED, SKIP_TEST, SKIP_LABEL) \ + __asm mov ax, word ptr [esi] \ + SKIP_TEST \ + __asm mov bx, ax \ + __asm and bx, 0x1f \ + __asm mov _blue, bx \ + __asm mov bx, ax \ + __asm and bx, 0x3e0 \ + __asm shr bx, 5 \ + __asm mov _green, bx \ + __asm mov bx, ax \ + __asm and bx, 0x7c00 \ + __asm shr bx, 10 \ + __asm mov word ptr RED, bx \ + __asm mov ax, _blue \ + __asm mov bx, _green \ + __asm shl bx, 6 \ + __asm add ax, bx \ + __asm mov bx, word ptr RED \ + __asm shl bx, 11 \ + __asm add ax, bx \ + __asm mov word ptr [esi], ax \ + SKIP_LABEL \ + __asm sub edx, 2 \ + __asm add esi, 2 + +#define MACRO_RGB555_TO_565_LOOP_IMPL(COUNT, SKIP_TEST, SKIP_LABEL) \ + __asm mov esi, _colorPtr \ + __asm mov edx, COUNT \ + __asm next_color: \ + __asm cmp edx, 0 \ + __asm jle done \ + MACRO_RGB555_TO_565_PIXEL(imageOffset, SKIP_TEST, SKIP_LABEL) \ + __asm jmp next_color \ + __asm done: + +#define MACRO_RGB555_TO_565_LOOP(COUNT) \ + MACRO_RGB555_TO_565_LOOP_IMPL(COUNT, MACRO_ASM_NONE, MACRO_ASM_NONE) + +#define MACRO_RGB555_TO_565_LOOP_SKIPPING_MARKER(COUNT) \ + MACRO_RGB555_TO_565_LOOP_IMPL(COUNT, MACRO_ASM_SKIP_MARKER_TEST, MACRO_ASM_SKIP_MARKER_LABEL) + +// clang-format on From d6d2014e12ce8725f469691d0b15768513f6e1fb Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:07:05 +0100 Subject: [PATCH 03/34] headers: TextureRenderCore.bitmapFaceSizes holds 36 ints 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 --- src/OpenSHC/UI/Rendering/TextureRenderCore.hpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore.hpp b/src/OpenSHC/UI/Rendering/TextureRenderCore.hpp index e2a219521d..81b93b118b 100644 --- a/src/OpenSHC/UI/Rendering/TextureRenderCore.hpp +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore.hpp @@ -68,15 +68,7 @@ namespace UI { int gmAndGfxImageDataBufferSize_0x8c; // 0x0000008C length: 4 void* gmAndGfxImageDataBuffer; // 0x00000090 length: 4 void* bitmapsFaces_0x94; // 0x00000094 length: 4 - int bitmapFaceSizes[28]; // 0x00000098 length: 112 - int field_0x108; // 0x00000108 length: 4 - int field_0x10c; // 0x0000010C length: 4 - int field_0x110; // 0x00000110 length: 4 - int field_0x114; // 0x00000114 length: 4 - int field_0x118; // 0x00000118 length: 4 - int field_0x11c; // 0x0000011C length: 4 - int field_0x120; // 0x00000120 length: 4 - int field_0x124; // 0x00000124 length: 4 + int bitmapFaceSizes[36]; // 0x00000098 length: 144 int field_0x128; // 0x00000128 length: 4 int field_0x12c; // 0x0000012C length: 4 undefined1 padding_0x130[1004]; // 0x00000130 length: 1004 From 8344fca333ce49cc70a06e7e6cc36186048cf854 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:07:05 +0100 Subject: [PATCH 04/34] headers: TextureRenderCore.gmAndGfxImageDataBuffer is a byte* 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 --- src/OpenSHC/UI/Rendering/TextureRenderCore.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore.hpp b/src/OpenSHC/UI/Rendering/TextureRenderCore.hpp index 81b93b118b..bca7c888bf 100644 --- a/src/OpenSHC/UI/Rendering/TextureRenderCore.hpp +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore.hpp @@ -66,7 +66,7 @@ namespace UI { int unknownMemSize_2_0x84; // 0x00000084 length: 4 void* address2; // 0x00000088 length: 4 int gmAndGfxImageDataBufferSize_0x8c; // 0x0000008C length: 4 - void* gmAndGfxImageDataBuffer; // 0x00000090 length: 4 + byte* gmAndGfxImageDataBuffer; // 0x00000090 length: 4 void* bitmapsFaces_0x94; // 0x00000094 length: 4 int bitmapFaceSizes[36]; // 0x00000098 length: 144 int field_0x128; // 0x00000128 length: 4 From d593ea7912ca77c64e808488d40a386ebacf712f Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 09:23:36 +0100 Subject: [PATCH 05/34] checkIfGfxTgxStartsWithTransparentPixels: drop the cast the byte* buffer 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 --- .../checkIfGfxTgxStartsWithTransparentPixels.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/checkIfGfxTgxStartsWithTransparentPixels.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/checkIfGfxTgxStartsWithTransparentPixels.cpp index 246f0c37b5..3010f5c990 100644 --- a/src/OpenSHC/UI/Rendering/TextureRenderCore/checkIfGfxTgxStartsWithTransparentPixels.cpp +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/checkIfGfxTgxStartsWithTransparentPixels.cpp @@ -1,7 +1,7 @@ -#include "OpenSHC/IO/Graphics/GfxRef.hpp" +#include "../TextureRenderCore.func.hpp" + #include "OpenSHC/IO/Graphics/TgxToken.hpp" -#include "OpenSHC/UI/Rendering/TextureRenderCore.hpp" #include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" @@ -13,7 +13,7 @@ namespace UI { BOOLEnum TextureRenderCore::checkIfGfxTgxStartsWithTransparentPixels(int gfxIndex) { int byteIndex = this->loadedGfxArray[gfxIndex].offsetInBuffer + 8; - byte checkByte = ((byte*)this->gmAndGfxImageDataBuffer)[byteIndex]; + byte checkByte = this->gmAndGfxImageDataBuffer[byteIndex]; if ((checkByte & OpenSHC::IO::Graphics::TT_TGX_PIXEL_HEADER) == OpenSHC::IO::Graphics::TT_TRANSPARENT_PIXELS) { return TRUE; From 8c4f735d9af05199e4032077517f41e002eb1a6b Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:07:05 +0100 Subject: [PATCH 06/34] reimplement: SHC_3BB0A8C1_0x0044C940 100.0% Reimplemented 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 cdaccb483 (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 1c294596c: 100.0% raw and normalized. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- ...transformRawWithMarkerUnkToRGB555To565.cpp | 22 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/transformRawWithMarkerUnkToRGB555To565.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/transformRawWithMarkerUnkToRGB555To565.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/transformRawWithMarkerUnkToRGB555To565.cpp new file mode 100644 index 0000000000..8cb2ec745e --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/transformRawWithMarkerUnkToRGB555To565.cpp @@ -0,0 +1,22 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/UI/Rendering/TextureRenderCore/RGB555To565Asm.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + // FUNCTION: STRONGHOLDCRUSADER 0x0044C940 + void TextureRenderCore::transformRawWithMarkerUnkToRGB555To565(int imageOffset, int imageSize) + { + // The conversion loop is handwritten assembly in the original, see RGB555To565Asm.hpp. + ushort* _colorPtr = (ushort*)((byte*)this->gmProcessedImageData + imageOffset); + // written by the asm below + ushort _blue; + ushort _green; + MACRO_RGB555_TO_565_LOOP_SKIPPING_MARKER(imageSize) + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 6e036f9340..33203dc2ea 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16903,7 +16903,7 @@ SHC_3BB0A8C1_0x0044C850 | 0.0% | Pending SHC_3BB0A8C1_0x0044C8F0 | 0.0% | Pending -SHC_3BB0A8C1_0x0044C940 | 0.0% | Pending +SHC_3BB0A8C1_0x0044C940 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0044C9C0 | 0.0% | Pending From 1c3669232511f27cf08ee0c687a684f9366278a3 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:07:06 +0100 Subject: [PATCH 07/34] reimplement: SHC_3BB0A8C1_0x0044CAE0 100.0% Reimplemented 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 e9a1e28bb (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 1c294596c: 100.0% raw and normalized. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../transformTileObjectToRGB565.cpp | 23 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/transformTileObjectToRGB565.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/transformTileObjectToRGB565.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/transformTileObjectToRGB565.cpp new file mode 100644 index 0000000000..b87d4e4fe0 --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/transformTileObjectToRGB565.cpp @@ -0,0 +1,23 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/UI/Rendering/TextureRenderCore/RGB555To565Asm.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + // FUNCTION: STRONGHOLDCRUSADER 0x0044CAE0 + void TextureRenderCore::transformTileObjectToRGB565(int imageOffset) + { + // The conversion loop is handwritten assembly in the original, see RGB555To565Asm.hpp. + ushort* _colorPtr = (ushort*)((byte*)this->gmProcessedImageData + imageOffset); + // written by the asm below + ushort _blue; + ushort _green; + // a tile object is 512 bytes, 256 pixels + MACRO_RGB555_TO_565_LOOP(512) + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 33203dc2ea..d33dc7761a 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16907,7 +16907,7 @@ SHC_3BB0A8C1_0x0044C940 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0044C9C0 | 0.0% | Pending -SHC_3BB0A8C1_0x0044CAE0 | 0.0% | Pending +SHC_3BB0A8C1_0x0044CAE0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0044CB60 | 0.0% | Pending From fa867c2f9c055ba0951e29176aa3c438bc19ab3a Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:07:06 +0100 Subject: [PATCH 08/34] reimplement: SHC_3BB0A8C1_0x0044CB60 100.0% Reimplemented 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 8d62e5863 (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 1c294596c: 100.0% raw and normalized. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../transformRawToRGB555To565.cpp | 22 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/transformRawToRGB555To565.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/transformRawToRGB555To565.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/transformRawToRGB555To565.cpp new file mode 100644 index 0000000000..3b533d154c --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/transformRawToRGB555To565.cpp @@ -0,0 +1,22 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/UI/Rendering/TextureRenderCore/RGB555To565Asm.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + // FUNCTION: STRONGHOLDCRUSADER 0x0044CB60 + void TextureRenderCore::transformRawToRGB555To565(int imageOffset, int imageSize) + { + // The conversion loop is handwritten assembly in the original, see RGB555To565Asm.hpp. + ushort* _colorPtr = (ushort*)((byte*)this->gmProcessedImageData + imageOffset); + // written by the asm below + ushort _blue; + ushort _green; + MACRO_RGB555_TO_565_LOOP(imageSize) + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index d33dc7761a..bb0417d201 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16909,7 +16909,7 @@ SHC_3BB0A8C1_0x0044C9C0 | 0.0% | Pending SHC_3BB0A8C1_0x0044CAE0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0044CB60 | 0.0% | Pending +SHC_3BB0A8C1_0x0044CB60 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0044CBE0 | 100.0% | Reimplemented From 6030b3aca46c65ed31d87a36b6c03313eb8d1b16 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:07:06 +0100 Subject: [PATCH 09/34] reimplement: SHC_3BB0A8C1_0x0044F020 100.0% Reimplemented 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 74226ca76 on reimpl/TextureRenderCore (2026-10-04, 91.9%: "Asm loops recovered, two extra locals for globals"; earlier 2f3c3a0ed at 9.1%; his fork's reimpl/UI-Rendering-development has the C draft 63cc49fb3 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 1c294596c: 100.0% raw and normalized. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../renderBlendedBlackBox.cpp | 127 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/renderBlendedBlackBox.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/renderBlendedBlackBox.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderBlendedBlackBox.cpp new file mode 100644 index 0000000000..445a56112c --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderBlendedBlackBox.cpp @@ -0,0 +1,127 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/UI/Rendering.func.hpp" +#include "OpenSHC/Rendering/ColorMode.hpp" + +#include "OpenSHC/Globals/DAT_BlendFilterArrays.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + // The pixel loops are handwritten assembly in the original, transcribed here from the binary. + + // FUNCTION: STRONGHOLDCRUSADER 0x0044F020 + void TextureRenderCore::renderBlendedBlackBox( + int drawX, int drawY, int drawXEnd, int drawYEnd, int blendStrengthUnk) + { + // darkens the box, both ends included, on the pencil surface; black pixels stay black + // bytes from the end of one row of the box to the start of the next + int const lineJump = DAT_PencilRenderCore::instance.horizontalByteSize - 2 + (drawX - drawXEnd) * 2; + // strengths above 32 count down again: 33 is 31, 64 and above are 0 + if (blendStrengthUnk > 64) { + blendStrengthUnk = 64; + } + if (blendStrengthUnk > 32) { + blendStrengthUnk = 64 - blendStrengthUnk; + } + // built on first use: the full-strength table's last entry is 0 until then + if (DAT_BlendFilterArrays::instance[32][31][0] == 0) { + MACRO_CALL(OpenSHC::UI::Rendering_Func::InitBlendFilterArraysUnk)(); + } + // the strength's table row; MSVC gives it the parameter's stack slot, as in the original + short* const blendTable = DAT_BlendFilterArrays::instance[blendStrengthUnk][0]; + if (DAT_WindowAndDirectDraw::instance.colorBitMode == OpenSHC::Rendering::RGB_555) { + // clang-format off + __asm { + mov edi, DAT_PencilRenderCore::instance.surfacePtr + mov eax, drawX + add eax, eax + add edi, eax + mov eax, drawY + mov edx, DAT_PencilRenderCore::instance.horizontalByteSize + mul edx + add edi, eax + row_555: + mov ecx, drawX + mov esi, blendTable + pixel_555: + cmp ecx, drawXEnd + jg row_end_555 + mov dx, word ptr [edi] + cmp dx, 0 + je next_555 + movzx ebx, dx + and bx, 0x1f + mov ax, word ptr [esi + ebx*8] + mov bx, dx + shr bx, 5 + and bx, 0x1f + or ax, word ptr [esi + ebx*8 + 2] + shr dx, 10 + and edx, 0x1f + or ax, word ptr [esi + edx*8 + 4] + mov word ptr [edi], ax + next_555: + add edi, 2 + add ecx, 1 + jmp pixel_555 + row_end_555: + add drawY, 1 + add edi, lineJump + mov eax, drawY + cmp eax, drawYEnd + jle row_555 + } + // clang-format on + } else { + // clang-format off + __asm { + mov edi, DAT_PencilRenderCore::instance.surfacePtr + mov eax, drawX + add eax, eax + add edi, eax + mov eax, drawY + mov edx, DAT_PencilRenderCore::instance.horizontalByteSize + mul edx + add edi, eax + row_565: + mov ecx, drawX + mov esi, blendTable + pixel_565: + cmp ecx, drawXEnd + jg row_end_565 + mov dx, word ptr [edi] + cmp dx, 0 + je next_565 + movzx ebx, dx + and bx, 0x1f + mov ax, word ptr [esi + ebx*8] + mov bx, dx + shr bx, 5 + and bx, 0x3f + or ax, word ptr [esi + ebx*8 + 2] + shr dx, 11 + and edx, 0x1f + or ax, word ptr [esi + edx*8 + 4] + mov word ptr [edi], ax + next_565: + add edi, 2 + add ecx, 1 + jmp pixel_565 + row_end_565: + add drawY, 1 + add edi, lineJump + mov eax, drawY + cmp eax, drawYEnd + jle row_565 + } + // clang-format on + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index bb0417d201..16e15a51db 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16953,7 +16953,7 @@ SHC_3BB0A8C1_0x0044E510 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0044E630 | 0.0% | Pending -SHC_3BB0A8C1_0x0044F020 | 0.0% | Pending +SHC_3BB0A8C1_0x0044F020 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0044F170 | 0.0% | Pending From 0d3c9c37e5a13e97918bca21ae991d4a9058b9bd Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:07:06 +0100 Subject: [PATCH 10/34] reimplement: SHC_3BB0A8C1_0x0044F850 100.0% Reimplemented 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 a501cdd8b (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 1c294596c: 100.0% raw and normalized. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../renderTgxWithColorAndBlendingUnk.cpp | 327 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 328 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/renderTgxWithColorAndBlendingUnk.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/renderTgxWithColorAndBlendingUnk.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderTgxWithColorAndBlendingUnk.cpp new file mode 100644 index 0000000000..45ca237dc9 --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderTgxWithColorAndBlendingUnk.cpp @@ -0,0 +1,327 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/IO/Graphics/TgxToken.hpp" +#include "OpenSHC/Rendering/ColorMode.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" + +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + using OpenSHC::IO::Graphics::TT_REPEATING_PIXELS; + using OpenSHC::IO::Graphics::TT_STREAM_OF_PIXELS; + using OpenSHC::IO::Graphics::TT_TGX_PIXEL_HEADER; + using OpenSHC::IO::Graphics::TT_TGX_PIXEL_LENGTH; + using OpenSHC::IO::Graphics::TT_TRANSPARENT_PIXELS; + + // The drawing loop is handwritten assembly in the original, transcribed here from the binary. + + // FUNCTION: STRONGHOLDCRUSADER 0x0044F850 + void TextureRenderCore::renderTgxWithColorAndBlendingUnk( + int xPos, int yPos, int width, int height, ushort* imageSource, ushort fillColorUnk, int blendStrengthUnk) + { + // blends fillColorUnk into the surface under a TGX picture, by each pixel's green channel times + // (32 - blendStrengthUnk) / 32; clipped to the surface's height range + // declared before the ifs because both arms assign them + int greenShift; + int redShift; + int lineJump; + int lineBytes; + int heightStart; + int heightEnd; + // inverted in the parameter's own slot (a fresh local: reccmp 100.0% -> 93.6%) + blendStrengthUnk = 32 - blendStrengthUnk; + // map arm first (== with the arms swapped: quick_diff 0.8678 -> 0.8319) + if (this->drawBufferChoiceValue != OpenSHC::Rendering::Enums::RT_SCREEN_MENU) { + DAT_TextureRenderCoreObject::instance.currentRenderSurface + = DAT_WindowAndDirectDraw::instance.surfacePointer_mapGame; + // the map surface is 4056 pixels wide + lineJump = (4056 - width) * 2; + lineBytes = 4056 * 2; + heightStart = this->mapGameSurfaceHeightRange.start; + heightEnd = this->mapGameSurfaceHeightRange.end; + } else { + DAT_TextureRenderCoreObject::instance.currentRenderSurface + = DAT_WindowAndDirectDraw::instance.surfacePointer_screenMenu; + lineJump = DAT_WindowAndDirectDraw::instance.byteSizeOfOneHorizontalLine - width * 2; + lineBytes = DAT_WindowAndDirectDraw::instance.byteSizeOfOneHorizontalLine; + heightStart = this->screenMenuSurfaceHeightRange.start; + heightEnd = this->screenMenuSurfaceHeightRange.end; + } + if (height + yPos > heightEnd) { + height = heightEnd - yPos; + if (height <= 0) { + return; + } + } + if (DAT_WindowAndDirectDraw::instance.colorBitMode == OpenSHC::Rendering::RGB_555) { + greenShift = 5; + redShift = 10; + } else { + greenShift = 6; + redShift = 11; + } + // clang-format off + __asm { + mov esi, imageSource + mov edi, DAT_TextureRenderCoreObject::instance.currentRenderSurface + mov eax, xPos + cmp eax, 0 + jl done + add eax, eax + add edi, eax + mov eax, yPos + mov ebx, heightStart + cmp eax, ebx + jge add_y_offset + sub ebx, eax + mov eax, ebx + cmp height, eax + jle done + sub height, eax + skip_token: + mov ecx, 0 + mov bl, byte ptr [esi] + mov cl, byte ptr [esi] + and bl, TT_TGX_PIXEL_HEADER + and cl, TT_TGX_PIXEL_LENGTH + add esi, 1 + cmp bl, TT_TRANSPARENT_PIXELS + je skip_token + cmp bl, TT_STREAM_OF_PIXELS + je skip_stream + cmp bl, TT_REPEATING_PIXELS + je skip_repeating + jmp skip_newline + skip_stream: + add ecx, 1 + add ecx, ecx + add esi, ecx + jmp skip_token + skip_repeating: + add esi, 2 + jmp skip_token + skip_newline: + sub eax, 1 + cmp eax, 0 + jg skip_token + mov eax, heightStart + add_y_offset: + mov edx, lineBytes + mul edx + add edi, eax + mov edx, height + draw_token: + push edx + mov ecx, 0 + mov al, byte ptr [esi] + mov cl, byte ptr [esi] + and al, TT_TGX_PIXEL_HEADER + and cl, TT_TGX_PIXEL_LENGTH + add esi, 1 + cmp al, TT_TRANSPARENT_PIXELS + je draw_transparent + cmp al, TT_STREAM_OF_PIXELS + je draw_stream + cmp al, TT_REPEATING_PIXELS + je draw_repeating + pop edx + add edi, lineJump + sub edx, 1 + cmp edx, 0 + jg draw_token + jmp done + draw_transparent: + add ecx, 1 + add ecx, ecx + add edi, ecx + pop edx + jmp draw_token + draw_repeating: + mov edx, 0 + mov dx, word ptr [esi] + add esi, 2 + add ecx, 1 + mov bx, word ptr fillColorUnk + push cx + mov cx, word ptr greenShift + shr dx, cl + and dx, 0x1f + pop cx + mov eax, blendStrengthUnk + mul dx + shr ax, 5 + mov dx, ax + cmp dx, 0x1f + je repeating_opaque + repeating_blend: + push bx + push cx + mov ax, bx + push bx + and ax, 0x1f + mov cx, word ptr [edi] + and cx, 0x1f + sub ax, cx + imul ax, dx + shr ax, 5 + mov bx, word ptr [edi] + and bx, 0x1f + add ax, bx + and ax, 0x1f + pop bx + push ax + mov ax, bx + push bx + mov cx, word ptr greenShift + shr ax, cl + and ax, 0x1f + mov bx, word ptr [edi] + shr bx, cl + and bx, 0x1f + sub ax, bx + imul ax, dx + shr ax, 5 + mov bx, word ptr [edi] + shr bx, cl + and bx, 0x1f + add ax, bx + and ax, 0x1f + shl ax, cl + pop bx + push ax + mov ax, bx + mov cx, word ptr redShift + shr ax, cl + and ax, 0x1f + mov bx, word ptr [edi] + shr bx, cl + and bx, 0x1f + sub ax, bx + imul ax, dx + shr ax, 5 + mov bx, word ptr [edi] + shr bx, cl + and bx, 0x1f + add ax, bx + and ax, 0x1f + shl ax, cl + mov bx, ax + pop ax + add bx, ax + pop ax + add bx, ax + pop cx + mov word ptr [edi], bx + pop bx + add edi, 2 + sub ecx, 1 + jne repeating_blend + pop edx + jmp draw_token + repeating_opaque: + mov word ptr [edi], bx + add edi, 2 + sub ecx, 1 + jne repeating_opaque + pop edx + jmp draw_token + draw_stream: + add ecx, 1 + stream_pixel: + mov dx, word ptr [esi] + push cx + mov cx, word ptr greenShift + shr dx, cl + and dx, 0x1f + pop cx + mov eax, blendStrengthUnk + mul dx + shr ax, 5 + mov dx, ax + mov ax, word ptr fillColorUnk + cmp dx, 0x1f + je stream_opaque + mov bx, ax + push cx + mov ax, bx + push bx + and ax, 0x1f + mov cx, word ptr [edi] + and cx, 0x1f + sub ax, cx + imul ax, dx + shr ax, 5 + mov bx, word ptr [edi] + and bx, 0x1f + add ax, bx + and ax, 0x1f + pop bx + push ax + mov ax, bx + push bx + mov cx, word ptr greenShift + shr ax, cl + and ax, 0x1f + mov bx, word ptr [edi] + shr bx, cl + and bx, 0x1f + sub ax, bx + imul ax, dx + shr ax, 5 + mov bx, word ptr [edi] + shr bx, cl + and bx, 0x1f + add ax, bx + and ax, 0x1f + shl ax, cl + pop bx + push ax + mov ax, bx + mov cx, word ptr redShift + shr ax, cl + and ax, 0x1f + mov bx, word ptr [edi] + shr bx, cl + and bx, 0x1f + sub ax, bx + imul ax, dx + shr ax, 5 + mov bx, word ptr [edi] + shr bx, cl + and bx, 0x1f + add ax, bx + and ax, 0x1f + shl ax, cl + mov bx, ax + pop ax + add bx, ax + pop ax + add bx, ax + pop cx + mov word ptr [edi], bx + add esi, 2 + add edi, 2 + sub ecx, 1 + jne stream_pixel + pop edx + jmp draw_token + stream_opaque: + mov word ptr [edi], ax + add esi, 2 + add edi, 2 + sub ecx, 1 + jne stream_pixel + pop edx + jmp draw_token + done: + } + // clang-format on + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 16e15a51db..64fffb86c4 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16959,7 +16959,7 @@ SHC_3BB0A8C1_0x0044F170 | 0.0% | Pending SHC_3BB0A8C1_0x0044F6F0 | 0.0% | Pending -SHC_3BB0A8C1_0x0044F850 | 0.0% | Pending +SHC_3BB0A8C1_0x0044F850 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0044FBF0 | 0.0% | Pending From 6c9e276288833f9688280c62b5415b9e427272be Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:07:06 +0100 Subject: [PATCH 11/34] reimplement: SHC_3BB0A8C1_0x00454620 100.0% Reimplemented 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 42f6c996b (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 1c294596c), so his 91.8% came from his build, not from the source. Measured in a clean alone build of the branch on main 1c294596c: 100.0% raw and normalized. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../TextureRenderCore/loadGfxFile.cpp | 45 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/loadGfxFile.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/loadGfxFile.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/loadGfxFile.cpp new file mode 100644 index 0000000000..bc9a067b15 --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/loadGfxFile.cpp @@ -0,0 +1,45 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/IO/ResourceManager.func.hpp" + +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + // FUNCTION: STRONGHOLDCRUSADER 0x00454620 + int TextureRenderCore::loadGfxFile(char const* tgxFileName) + { + // loads a gfx file after the ones loaded so far, if it still fits into the buffer's 18250000 bytes + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::resolveResourceFileName, DAT_ResourceManager::ptr)( + OpenSHC::IO::FRT_GFX, tgxFileName); + int const size = MACRO_CALL_MEMBER( + OpenSHC::IO::ResourceManager_Func::getCurrentResourceSize, DAT_ResourceManager::ptr)(); + int const offset = this->loadedGfxArray[this->totalLoadedGfx].offsetInBuffer; + if (offset + size > 18250000) { + return -1; + } + byte* const destination = this->gmAndGfxImageDataBuffer + offset; + if (!MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::readCurrentResourceIntoDestination, + DAT_ResourceManager::ptr)(destination, size)) { + return -1; + } + // the picture's 8-byte header holds its width and height + if (DAT_WindowAndDirectDraw::instance.colorBitMode == OpenSHC::Rendering::RGB_565) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::transformTgxFromRGB555ToRGB565, this)( + (ushort*)(destination + 8), DAT_ResourceManager::instance.loadPositionInCurrentResource - 8); + } + this->loadedGfxArray[this->totalLoadedGfx + 1].offsetInBuffer + = this->loadedGfxArray[this->totalLoadedGfx].offsetInBuffer + + DAT_ResourceManager::instance.loadPositionInCurrentResource; + this->loadedGfxArray[this->totalLoadedGfx].width = ((int*)destination)[0]; + this->loadedGfxArray[this->totalLoadedGfx].height = ((int*)destination)[1]; + ++this->totalLoadedGfx; + return this->totalLoadedGfx - 1; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 64fffb86c4..5aa83efbe2 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16973,7 +16973,7 @@ SHC_3BB0A8C1_0x00453B00 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00454080 | 0.0% | Pending -SHC_3BB0A8C1_0x00454620 | 0.0% | Pending +SHC_3BB0A8C1_0x00454620 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00454700 | 0.0% | Pending From 09b8359e79735253be485caa9f691a6406d35d91 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:07:07 +0100 Subject: [PATCH 12/34] reimplement: SHC_3BB0A8C1_0x004547C0 100.0% Reimplemented 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 e3c6eb19e (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 1c294596c), so his 91.7% came from his build, not from the source. Measured in a clean alone build of the branch on main 1c294596c: 100.0% raw and normalized. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../TextureRenderCore/loadGfxAtBufferEnd.cpp | 48 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/loadGfxAtBufferEnd.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/loadGfxAtBufferEnd.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/loadGfxAtBufferEnd.cpp new file mode 100644 index 0000000000..2847f57d28 --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/loadGfxAtBufferEnd.cpp @@ -0,0 +1,48 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/IO/ResourceManager.func.hpp" + +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + // FUNCTION: STRONGHOLDCRUSADER 0x004547C0 + int TextureRenderCore::loadGfxAtBufferEnd(char* fileName) + { + // loads a gfx file (the menu edges, for example), packed backwards from the end of the buffer's 18250000 + // bytes + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::resolveResourceFileName, DAT_ResourceManager::ptr)( + OpenSHC::IO::FRT_GFX, fileName); + int const size = MACRO_CALL_MEMBER( + OpenSHC::IO::ResourceManager_Func::getCurrentResourceSize, DAT_ResourceManager::ptr)(); + byte* const destination = this->gmAndGfxImageDataBuffer + - this->loadedGfxArray[this->backwardsLoadedGfxIndex_0x16C850].backwardsOffsetInBuffer - size + + 18250000; + if (!MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::readCurrentResourceIntoDestination, + DAT_ResourceManager::ptr)(destination, size)) { + return -1; + } + // the picture's 8-byte header holds its width and height + if (DAT_WindowAndDirectDraw::instance.colorBitMode == OpenSHC::Rendering::RGB_565) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::transformTgxFromRGB555ToRGB565, this)( + (ushort*)(destination + 8), DAT_ResourceManager::instance.loadPositionInCurrentResource - 8); + } + this->loadedGfxArray[this->backwardsLoadedGfxIndex_0x16C850].offsetInBuffer = 18250000 + - this->loadedGfxArray[this->backwardsLoadedGfxIndex_0x16C850].backwardsOffsetInBuffer - size; + this->loadedGfxArray[this->backwardsLoadedGfxIndex_0x16C850 - 1].backwardsOffsetInBuffer + = this->loadedGfxArray[this->backwardsLoadedGfxIndex_0x16C850].backwardsOffsetInBuffer + + DAT_ResourceManager::instance.loadPositionInCurrentResource; + this->loadedGfxArray[this->backwardsLoadedGfxIndex_0x16C850].backwardsOffsetInBuffer + = this->loadedGfxArray[this->backwardsLoadedGfxIndex_0x16C850 - 1].backwardsOffsetInBuffer; + this->loadedGfxArray[this->backwardsLoadedGfxIndex_0x16C850].width = ((int*)destination)[0]; + this->loadedGfxArray[this->backwardsLoadedGfxIndex_0x16C850].height = ((int*)destination)[1]; + --this->backwardsLoadedGfxIndex_0x16C850; + return this->backwardsLoadedGfxIndex_0x16C850 + 1; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 5aa83efbe2..3e54cffa3e 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16977,7 +16977,7 @@ SHC_3BB0A8C1_0x00454620 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00454700 | 0.0% | Pending -SHC_3BB0A8C1_0x004547C0 | 0.0% | Pending +SHC_3BB0A8C1_0x004547C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004548D0 | 100.0% | Reimplemented From 5442a70cf982dc62d4b6932bbc35d4cf67614921 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:07:07 +0100 Subject: [PATCH 13/34] reimplement: SHC_3BB0A8C1_0x00454900 100.0% Reimplemented 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 (63cc49fb3, 2026-10-25, 75.0% there). His earlier commits 7c3049be3 on reimpl/TextureRenderCore (2026-10-03, 71.9%) and 3f5228375 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 1c294596c: 100.0% raw and normalized. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../TextureRenderCore/renderLoadedGfx.cpp | 25 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/renderLoadedGfx.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/renderLoadedGfx.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderLoadedGfx.cpp new file mode 100644 index 0000000000..f92952f6e8 --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderLoadedGfx.cpp @@ -0,0 +1,25 @@ +#include "../TextureRenderCore.func.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + // FUNCTION: STRONGHOLDCRUSADER 0x00454900 + void TextureRenderCore::renderLoadedGfx(int loadedGfxIndex, int xPos, int yPos) + { + // draws a gfx file loaded by loadGfxFile or loadGfxAtBufferEnd, on the surface + // currentRenderSurfaceIdentifierUnk_0x8 names for this one call + RenderTargetInt const savedTarget = this->drawBufferChoiceValue; + // pixels after the 8-byte header, named before the target switch (inline: quick_diff 1.0000 -> 0.7500) + ushort* const source + = (ushort*)(this->gmAndGfxImageDataBuffer + this->loadedGfxArray[loadedGfxIndex].offsetInBuffer + 8); + this->drawBufferChoiceValue = this->currentRenderSurfaceIdentifierUnk_0x8; + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderFunctionResponsibleForManyGameObjects, this)(xPos, + yPos, this->loadedGfxArray[loadedGfxIndex].width, this->loadedGfxArray[loadedGfxIndex].height, source); + this->drawBufferChoiceValue = savedTarget; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 3e54cffa3e..1b225ba3b6 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16981,7 +16981,7 @@ SHC_3BB0A8C1_0x004547C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004548D0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00454900 | 0.0% | Pending +SHC_3BB0A8C1_0x00454900 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00454960 | 100.0% | Reimplemented From 46cc90ef5d8e4a972b971fd20e191d0bec841704 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:07:07 +0100 Subject: [PATCH 14/34] reimplement: SHC_3BB0A8C1_0x00454A60 100.0% Reimplemented 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 246507fa6 (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 1c294596c: 100.0% raw and normalized. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../drawTgxOnFlaggedSurface.cpp | 247 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/drawTgxOnFlaggedSurface.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/drawTgxOnFlaggedSurface.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/drawTgxOnFlaggedSurface.cpp new file mode 100644 index 0000000000..0bb3ffc9c9 --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/drawTgxOnFlaggedSurface.cpp @@ -0,0 +1,247 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/IO/Graphics/TgxToken.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" + +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + using OpenSHC::IO::Graphics::TT_REPEATING_PIXELS; + using OpenSHC::IO::Graphics::TT_STREAM_OF_PIXELS; + using OpenSHC::IO::Graphics::TT_TGX_PIXEL_HEADER; + using OpenSHC::IO::Graphics::TT_TGX_PIXEL_LENGTH; + using OpenSHC::IO::Graphics::TT_TRANSPARENT_PIXELS; + + // The drawing loop is handwritten assembly in the original, transcribed here from the binary. + + // FUNCTION: STRONGHOLDCRUSADER 0x00454A60 + void TextureRenderCore::drawTgxOnFlaggedSurface( + int xPos, int yPos, int gfxWidth, int gfxHeight, ushort* tgxSourcePtr) + { + // decodes a TGX picture onto the current render surface, clipped to renderingRect_16c854 + int const top = this->renderingRect_16c854.top; + int const left = this->renderingRect_16c854.left; + int const bottom = this->renderingRect_16c854.bottom; + int const right = this->renderingRect_16c854.right; + // declared before the switch because both cases assign them; lineJump is from one row's end to the next + int lineJump; + int lineBytes; + switch (this->currentRenderSurfaceIdentifierUnk_0x8) { + case OpenSHC::Rendering::Enums::RT_MAP_GAME: + DAT_TextureRenderCoreObject::instance.currentRenderSurface + = DAT_WindowAndDirectDraw::instance.surfacePointer_mapGame; + // the map surface is 4056 pixels wide + lineJump = (4056 - gfxWidth) * 2; + lineBytes = 4056 * 2; + break; + case OpenSHC::Rendering::Enums::RT_SCREEN_MENU: + DAT_TextureRenderCoreObject::instance.currentRenderSurface + = DAT_WindowAndDirectDraw::instance.surfacePointer_screenMenu; + lineJump = DAT_WindowAndDirectDraw::instance.byteSizeOfOneHorizontalLine - gfxWidth * 2; + lineBytes = DAT_WindowAndDirectDraw::instance.byteSizeOfOneHorizontalLine; + break; + } + if (gfxHeight + yPos > bottom) { + gfxHeight = bottom - yPos; + if (gfxHeight <= 0) { + return; + } + } + // clang-format off + __asm { + mov esi, tgxSourcePtr + mov edi, DAT_TextureRenderCoreObject::instance.currentRenderSurface + mov eax, xPos + add eax, eax + add edi, eax + mov eax, yPos + mov ebx, top + cmp eax, ebx + jge add_y_offset + sub ebx, eax + mov eax, ebx + cmp gfxHeight, eax + jle done + sub gfxHeight, eax + skip_token: + mov ecx, 0 + mov bl, byte ptr [esi] + mov cl, byte ptr [esi] + and bl, TT_TGX_PIXEL_HEADER + and cl, TT_TGX_PIXEL_LENGTH + add esi, 1 + cmp bl, TT_TRANSPARENT_PIXELS + je skip_token + cmp bl, TT_STREAM_OF_PIXELS + je skip_stream + cmp bl, TT_REPEATING_PIXELS + je skip_repeating + jmp skip_newline + skip_stream: + add ecx, 1 + add ecx, ecx + add esi, ecx + jmp skip_token + skip_repeating: + add esi, 2 + jmp skip_token + skip_newline: + sub eax, 1 + cmp eax, 0 + jg skip_token + mov eax, top + add_y_offset: + mov edx, lineBytes + mul edx + add edi, eax + mov edx, gfxHeight + mov ebx, xPos + draw_token: + mov ecx, 0 + mov al, byte ptr [esi] + mov cl, byte ptr [esi] + and al, TT_TGX_PIXEL_HEADER + and cl, TT_TGX_PIXEL_LENGTH + add esi, 1 + cmp al, TT_TRANSPARENT_PIXELS + je draw_transparent + cmp al, TT_STREAM_OF_PIXELS + je draw_stream + cmp al, TT_REPEATING_PIXELS + je draw_repeating + mov ebx, xPos + add edi, lineJump + sub edx, 1 + cmp edx, 0 + jg draw_token + jmp done + draw_transparent: + add ecx, 1 + add ebx, ecx + add ecx, ecx + add edi, ecx + jmp draw_token + draw_repeating: + mov eax, 0 + add ecx, 1 + cmp ebx, right + jl repeating_clip + repeating_advance: + add ebx, ecx + add ecx, ecx + add edi, ecx + add esi, 2 + jmp draw_token + repeating_clip: + cmp ebx, left + jge repeating_right + mov eax, ecx + add eax, ebx + cmp eax, left + jle repeating_advance + mov eax, left + sub eax, ebx + sub ecx, eax + add ebx, eax + add eax, eax + add edi, eax + repeating_right: + mov eax, ecx + add eax, ebx + cmp eax, right + jl repeating_copy + push edx + mov edx, eax + sub edx, right + sub ecx, edx + mov ax, word ptr [esi] + repeating_clip_loop: + mov word ptr [edi], ax + add edi, 2 + add ebx, 1 + sub ecx, 1 + jne repeating_clip_loop + add ebx, edx + add edx, edx + add edi, edx + pop edx + add esi, 2 + jmp draw_token + repeating_copy: + mov ax, word ptr [esi] + repeating_copy_loop: + mov word ptr [edi], ax + add edi, 2 + add ebx, 1 + sub ecx, 1 + jne repeating_copy_loop + add esi, 2 + jmp draw_token + draw_stream: + add ecx, 1 + cmp ebx, right + jl stream_clip + stream_advance: + add ebx, ecx + add ecx, ecx + add esi, ecx + add edi, ecx + jmp draw_token + stream_clip: + cmp ebx, left + jge stream_right + mov eax, ecx + add eax, ebx + cmp eax, left + jle stream_advance + mov eax, left + sub eax, ebx + sub ecx, eax + add ebx, eax + add eax, eax + add esi, eax + add edi, eax + stream_right: + mov eax, ecx + add eax, ebx + cmp eax, right + jl stream_copy + push edx + mov edx, eax + sub edx, right + sub ecx, edx + stream_clip_loop: + mov ax, word ptr [esi] + mov word ptr [edi], ax + add esi, 2 + add edi, 2 + add ebx, 1 + sub ecx, 1 + jne stream_clip_loop + add ebx, edx + add edx, edx + add esi, edx + add edi, edx + pop edx + jmp draw_token + stream_copy: + mov ax, word ptr [esi] + mov word ptr [edi], ax + add esi, 2 + add edi, 2 + add ebx, 1 + sub ecx, 1 + jne stream_copy + jmp draw_token + done: + } + // clang-format on + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 1b225ba3b6..ab46868abd 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16991,7 +16991,7 @@ SHC_3BB0A8C1_0x004549C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004549F0 | 0.0% | Pending -SHC_3BB0A8C1_0x00454A60 | 0.0% | Pending +SHC_3BB0A8C1_0x00454A60 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00454CB0 | 0.0% | Pending From 7092040df1440b0c6f25a333674d1c620d544341 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:07:07 +0100 Subject: [PATCH 15/34] reimplement: SHC_3BB0A8C1_0x00454CB0 100.0% Reimplemented 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 37368ca63 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 63cc49fb3 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 1c294596c: 100.0% raw and normalized. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../loadCampaignMapGfxUnk.cpp | 51 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/loadCampaignMapGfxUnk.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/loadCampaignMapGfxUnk.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/loadCampaignMapGfxUnk.cpp new file mode 100644 index 0000000000..7228260217 --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/loadCampaignMapGfxUnk.cpp @@ -0,0 +1,51 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/IO/ResourceManager.func.hpp" +#include "OpenSHC/Rendering/ColorMode.hpp" +#include "OpenSHC/string-literals.hpp" + +#include "OpenSHC/Globals/DAT_BlendingDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + // magenta as RGB555 with the top bit set, and as RGB565 + enum { MAGENTA_555 = 1 << 15 | 31 << 10 | 31, MAGENTA_565 = 31 << 11 | 31 }; + + // FUNCTION: STRONGHOLDCRUSADER 0x00454CB0 + void TextureRenderCore::loadCampaignMapGfxUnk() + { + // the campaign map's six palettes (.act files, 256 RGB triples each), as screen colours + for (int map = 0; map < countof(DAT_BlendingDefinedData::instance.campaign_map_england); ++map) { + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::resolveResourceFileName, DAT_ResourceManager::ptr)( + OpenSHC::IO::FRT_GFX8, (char const*)DAT_BlendingDefinedData::instance.campaign_map_england[map]); + byte palette[256][3]; + // "act" + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::readFirstPartOfCurrentResourceIntoMemory, + DAT_ResourceManager::ptr)(palette, sizeof(palette), (char*)s_act_005a5064); + for (int i = 0; i < countof(palette); ++i) { + // green read first (red first: quick_diff 0.9797 -> 0.8716) + ushort const green = palette[i][1]; + ushort const red = palette[i][0]; + ushort const blue = palette[i][2] >> 3; + ushort colour; + if (DAT_WindowAndDirectDraw::instance.colorBitMode == OpenSHC::Rendering::RGB_565) { + colour = ((red & ~7) * 32 + (green & ~3)) * 8 + blue; + } else { + colour = (((red & ~7) * 32 + (green & ~7)) * 4 + blue) | 1 << 15; + } + // RGB555 magenta (top bit set) becomes the RGB565 marker; the test runs in both modes + if (colour == MAGENTA_555) { + colour = MAGENTA_565; + } + this->campaignMapColorMapsUnk_0x16c886[map][i] = colour; + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index ab46868abd..0e1afb7768 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16993,7 +16993,7 @@ SHC_3BB0A8C1_0x004549F0 | 0.0% | Pending SHC_3BB0A8C1_0x00454A60 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00454CB0 | 0.0% | Pending +SHC_3BB0A8C1_0x00454CB0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00454CE0 | 0.0% | Pending From bf5081d689573c1587a918726e54897d5327ed7b Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:07:08 +0100 Subject: [PATCH 16/34] reimplement: SHC_3BB0A8C1_0x00455050 100.0% Reimplemented 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 (63cc49fb3, 2026-10-25, 52.1% there). His earlier commits 636bfa1fc on reimpl/TextureRenderCore (2026-10-03, 49.0%) and 4411bcf0c 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 1c294596c: 100.0% raw and normalized. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../Constructor_TextureRenderCore.cpp | 73 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/Constructor_TextureRenderCore.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/Constructor_TextureRenderCore.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/Constructor_TextureRenderCore.cpp new file mode 100644 index 0000000000..7ba1fe5544 --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/Constructor_TextureRenderCore.cpp @@ -0,0 +1,73 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/OS.func.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + // FUNCTION: STRONGHOLDCRUSADER 0x00455050 + TextureRenderCore* TextureRenderCore::Constructor_TextureRenderCore( + int processedImageDataBufferSize, int gmAndGfxImageDataBufferSize, int unknownMemSize) + { + // the buffer sizes are kept here and allocated below; the second unknown buffer is half the first + this->gmProcessedImageDataBufferSize_0x74 = processedImageDataBufferSize; + this->gmAndGfxImageDataBufferSize_0x8c = gmAndGfxImageDataBufferSize; + if (unknownMemSize != 0) { + this->unknownMemSize_1_0x7c = unknownMemSize; + this->unknownMemSize_2_0x84 = unknownMemSize / 2; + } else { + this->unknownMemSize_1_0x7c = 0; + this->unknownMemSize_2_0x84 = 0; + } + this->bufferAllocStateUnk_0x0 = 0; + this->drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME; + this->currentRenderSurfaceIdentifierUnk_0x8 = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + this->field_0x128 = 0; + this->field_0x12c = 0; + this->field_0x2c = 1; + this->isZoom2 = 0; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::clearSomeMemory, this)(); + this->unknownSfxAndGmRelatedFlag = FALSE; + // bufferAllocStateUnk_0x0 records a failed allocation: 1 for an image buffer, 2 and 3 for the other two + this->gmProcessedImageData + = MACRO_CALL(OpenSHC::OS_Func::_malloc)(this->gmProcessedImageDataBufferSize_0x74); + if (!this->gmProcessedImageData) { + this->bufferAllocStateUnk_0x0 = 1; + return this; + } + if (unknownMemSize != 0) { + this->unknownMemPtr_1_0x80 = MACRO_CALL(OpenSHC::OS_Func::_malloc)(this->unknownMemSize_1_0x7c); + if (!this->unknownMemPtr_1_0x80) { + this->bufferAllocStateUnk_0x0 = 2; + return this; + } + this->address2 = MACRO_CALL(OpenSHC::OS_Func::_malloc)(this->unknownMemSize_2_0x84); + if (!this->address2) { + this->bufferAllocStateUnk_0x0 = 3; + return this; + } + } else { + this->unknownMemPtr_1_0x80 = NULL; + this->address2 = NULL; + } + this->gmAndGfxImageDataBuffer + = (byte*)MACRO_CALL(OpenSHC::OS_Func::_malloc)(this->gmAndGfxImageDataBufferSize_0x8c); + if (!this->gmAndGfxImageDataBuffer) { + this->bufferAllocStateUnk_0x0 = 1; + return this; + } + this->totalLoadedGfx = 0; + this->colorPaletteOverride = 0; + // room for 36 faces of 8448 bytes (readBitmapFace's FACE_SIZE), and their sizes, none loaded yet + this->bitmapsFaces_0x94 = MACRO_CALL(OpenSHC::OS_Func::_malloc)(36 * 8448); + for (int i = 0; i < countof(this->bitmapFaceSizes); ++i) { + this->bitmapFaceSizes[i] = 0; + } + return this; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 0e1afb7768..9da5f73b28 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -17005,7 +17005,7 @@ SHC_3BB0A8C1_0x00454EF0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00454F00 | 0.0% | Pending -SHC_3BB0A8C1_0x00455050 | 0.0% | Pending +SHC_3BB0A8C1_0x00455050 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00455250 | 100.0% | Reimplemented From 2585581fae06c186db587c5c7c2962561260a7c2 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:07:08 +0100 Subject: [PATCH 17/34] reimplement: SHC_3BB0A8C1_0x00455390 100.0% Reimplemented 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 756ed2eba 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 63cc49fb3 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 1c294596c: 100.0% raw and normalized. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../renderGMWithBlending.cpp | 65 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/renderGMWithBlending.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGMWithBlending.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGMWithBlending.cpp new file mode 100644 index 0000000000..6e59e2647a --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGMWithBlending.cpp @@ -0,0 +1,65 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/IO/Graphics/GmImageType.hpp" + +#include "OpenSHC/Globals/DAT_GMImageHeaders.hpp" +#include "OpenSHC/Globals/DAT_GMImageOffsets.hpp" +#include "OpenSHC/Globals/GMFirstPictureIndex.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + // FUNCTION: STRONGHOLDCRUSADER 0x00455390 + void TextureRenderCore::renderGMWithBlending(GmID GmID, int imageID, int drawX, int drawY, int blendStrengthUnk) + { + // picture imageID of the gm file, counted from 1; a blend strength of 32 draws nothing, 0 draws unblended + int const imageIndex = GMFirstPictureIndex::instance[GmID] + imageID - 1; + ushort* const source + = (ushort*)((byte*)this->gmProcessedImageData + DAT_GMImageOffsets::instance[imageIndex]); + if (blendStrengthUnk == 32) { + return; + } + // one branch per image type, the type read in each test (|| and a local: quick_diff 1.0000 -> 0.8000) + if (blendStrengthUnk == 0) { + if (this->gmFileHeaderColorpaletteArray[GmID].ImageType + == OpenSHC::IO::Graphics::GIT_InterfaceElement) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderFunctionResponsibleForManyGameObjects, + this)(drawX, drawY, DAT_GMImageHeaders::instance.imh[imageIndex].width, + DAT_GMImageHeaders::instance.imh[imageIndex].height, source); + } else if (this->gmFileHeaderColorpaletteArray[GmID].ImageType + == OpenSHC::IO::Graphics::GIT_CompressedImage) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderFunctionResponsibleForManyGameObjects, + this)(drawX, drawY, DAT_GMImageHeaders::instance.imh[imageIndex].width, + DAT_GMImageHeaders::instance.imh[imageIndex].height, source); + } else if (this->gmFileHeaderColorpaletteArray[GmID].ImageType + == OpenSHC::IO::Graphics::GIT_Animation) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderUnitAnimationUnk, this)( + drawX, drawY, DAT_GMImageHeaders::instance.imh[imageIndex].width, + DAT_GMImageHeaders::instance.imh[imageIndex].height, (byte*)source); + } + return; + } + if (this->gmFileHeaderColorpaletteArray[GmID].ImageType == OpenSHC::IO::Graphics::GIT_InterfaceElement) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderInterfaceOrBuildingOccupationArea, this)( + drawX, drawY, DAT_GMImageHeaders::instance.imh[imageIndex].width, + DAT_GMImageHeaders::instance.imh[imageIndex].height, source, blendStrengthUnk); + } else if (this->gmFileHeaderColorpaletteArray[GmID].ImageType + == OpenSHC::IO::Graphics::GIT_CompressedImage) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderInterfaceOrBuildingOccupationArea, this)( + drawX, drawY, DAT_GMImageHeaders::instance.imh[imageIndex].width, + DAT_GMImageHeaders::instance.imh[imageIndex].height, source, blendStrengthUnk); + } else if (this->gmFileHeaderColorpaletteArray[GmID].ImageType == OpenSHC::IO::Graphics::GIT_Animation) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderUnitAnimationWithBlendingUnk, + this)(drawX, drawY, DAT_GMImageHeaders::instance.imh[imageIndex].width, + DAT_GMImageHeaders::instance.imh[imageIndex].height, (byte*)source, blendStrengthUnk); + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 9da5f73b28..8c3cd97272 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -17017,7 +17017,7 @@ SHC_3BB0A8C1_0x004552E0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00455300 | 0.0% | Pending -SHC_3BB0A8C1_0x00455390 | 0.0% | Pending +SHC_3BB0A8C1_0x00455390 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004554A0 | 0.0% | Pending From 93286741cde994ee11e57e2fc0d4a5ec6febd3db Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:07:08 +0100 Subject: [PATCH 18/34] reimplement: SHC_3BB0A8C1_0x004554A0 100.0% Reimplemented 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 fcb3ffa25 (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 1c294596c: 100.0% raw and normalized. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../drawTgxGmOnFlaggedSurface.cpp | 36 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/drawTgxGmOnFlaggedSurface.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/drawTgxGmOnFlaggedSurface.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/drawTgxGmOnFlaggedSurface.cpp new file mode 100644 index 0000000000..659cf0aff8 --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/drawTgxGmOnFlaggedSurface.cpp @@ -0,0 +1,36 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/IO/Graphics/GmImageType.hpp" + +#include "OpenSHC/Globals/DAT_GMImageHeaders.hpp" +#include "OpenSHC/Globals/DAT_GMImageOffsets.hpp" +#include "OpenSHC/Globals/GMFirstPictureIndex.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + // FUNCTION: STRONGHOLDCRUSADER 0x004554A0 + void TextureRenderCore::drawTgxGmOnFlaggedSurface(GmID gmId, int imageIndexInGm, int xPos, int yPos) + { + // picture imageIndexInGm of the gm file, counted from 1 + int const imageIndex = GMFirstPictureIndex::instance[gmId] + imageIndexInGm - 1; + ushort* const source + = (ushort*)((byte*)this->gmProcessedImageData + DAT_GMImageOffsets::instance[imageIndex]); + // interface elements and compressed images draw the same way + // two tests as in the original (one test with ||: quick_diff 1.0000 -> 0.3014) + if (this->gmFileHeaderColorpaletteArray[gmId].ImageType == OpenSHC::IO::Graphics::GIT_InterfaceElement) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::drawTgxOnFlaggedSurface, this)(xPos, + yPos, DAT_GMImageHeaders::instance.imh[imageIndex].width, + DAT_GMImageHeaders::instance.imh[imageIndex].height, source); + } + if (this->gmFileHeaderColorpaletteArray[gmId].ImageType == OpenSHC::IO::Graphics::GIT_CompressedImage) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::drawTgxOnFlaggedSurface, this)(xPos, + yPos, DAT_GMImageHeaders::instance.imh[imageIndex].width, + DAT_GMImageHeaders::instance.imh[imageIndex].height, source); + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 8c3cd97272..3b1fc2a3e7 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -17019,7 +17019,7 @@ SHC_3BB0A8C1_0x00455300 | 0.0% | Pending SHC_3BB0A8C1_0x00455390 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004554A0 | 0.0% | Pending +SHC_3BB0A8C1_0x004554A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00455540 | 0.0% | Pending From b41983f730e98ebe10552273339437531ac703a9 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:32:14 +0100 Subject: [PATCH 19/34] reimplement: SHC_3BB0A8C1_0x00454700 100.0% Reimplemented TextureRenderCore::loadGFX8, gynt's code from 4a40da6ae 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 (8ca78619c, 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 (63cc49fb3, 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 Co-Authored-By: Claude Opus 5.5 --- .../Rendering/TextureRenderCore/loadGFX8.cpp | 40 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/loadGFX8.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/loadGFX8.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/loadGFX8.cpp new file mode 100644 index 0000000000..c97e11c2e1 --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/loadGFX8.cpp @@ -0,0 +1,40 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/IO/ResourceManager.func.hpp" + +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + // FUNCTION: STRONGHOLDCRUSADER 0x00454700 + int TextureRenderCore::loadGFX8(char* gfx8Filename) + { + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::resolveResourceFileName, DAT_ResourceManager::ptr)( + OpenSHC::IO::FRT_GFX8, gfx8Filename); + int const size = MACRO_CALL_MEMBER( + OpenSHC::IO::ResourceManager_Func::getCurrentResourceSize, DAT_ResourceManager::ptr)(); + int const offset = this->loadedGfxArray[this->totalLoadedGfx].offsetInBuffer; + // Only if it still fits into the buffer's 18250000 bytes + if (offset + size > 18250000) { + return -1; + } + byte* const destination = this->gmAndGfxImageDataBuffer + offset; + if (!MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::readCurrentResourceIntoDestination, + DAT_ResourceManager::ptr)(destination, size)) { + return -1; + } + this->loadedGfxArray[this->totalLoadedGfx + 1].offsetInBuffer + = this->loadedGfxArray[this->totalLoadedGfx].offsetInBuffer + + DAT_ResourceManager::instance.loadPositionInCurrentResource; + // The file starts with the image's width and height + this->loadedGfxArray[this->totalLoadedGfx].width = ((int*)destination)[0]; + this->loadedGfxArray[this->totalLoadedGfx].height = ((int*)destination)[1]; + ++this->totalLoadedGfx; + return this->totalLoadedGfx - 1; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 3b1fc2a3e7..7c47bc2e05 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16975,7 +16975,7 @@ SHC_3BB0A8C1_0x00454080 | 0.0% | Pending SHC_3BB0A8C1_0x00454620 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00454700 | 0.0% | Pending +SHC_3BB0A8C1_0x00454700 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004547C0 | 100.0% | Reimplemented From d60605d341bcdedf6afe7596d8511092047c349c Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:32:14 +0100 Subject: [PATCH 20/34] reimplement: SHC_3BB0A8C1_0x004557B0 100.0% Reimplemented TextureRenderCore::renderGMWithAlphaMask, from gynt's 92ec6d040 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 (8ca78619c, 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 (63cc49fb3, 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 Co-Authored-By: Claude Opus 5.5 --- .../renderGMWithAlphaMask.cpp | 57 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/renderGMWithAlphaMask.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGMWithAlphaMask.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGMWithAlphaMask.cpp new file mode 100644 index 0000000000..cbe1e16822 --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGMWithAlphaMask.cpp @@ -0,0 +1,57 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" + +#include "OpenSHC/Globals/AlphaAndButtonSurfaceObj.hpp" +#include "OpenSHC/Globals/COL_MAGENTA.hpp" +#include "OpenSHC/Globals/DAT_GMImageHeaders.hpp" +#include "OpenSHC/Globals/DAT_GMImageOffsets.hpp" +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/GMFirstPictureIndex.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + // FUNCTION: STRONGHOLDCRUSADER 0x004557B0 + void TextureRenderCore::renderGMWithAlphaMask( + GmID gmID, int imageID, int xPos, int yPos, GmID maskGmID, int alphaImageID, int blendStrength) + { + byte* const imageData = (byte*)this->gmProcessedImageData; + // Read before the zoom test (read at its use: quick_diff 1.0000 -> 0.9091) + ushort* const alphaSurface = AlphaAndButtonSurfaceObj::instance.surfacePtr; + // With isZoom2 set the image is drawn blended, without the mask + if (DAT_TextureRenderCoreObject::instance.isZoom2) { + int const picture = GMFirstPictureIndex::instance[gmID] + imageID - 1; + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderInterfaceOrBuildingOccupationArea, this)(xPos, + yPos, DAT_GMImageHeaders::instance.imh[picture].width, + DAT_GMImageHeaders::instance.imh[picture].height, + (ushort*)(imageData + DAT_GMImageOffsets::instance[picture]), blendStrength); + return; + } + // Clear the alpha surface to magenta, draw the mask into it, then draw the image through it + int const maskPicture = GMFirstPictureIndex::instance[maskGmID] + alphaImageID - 1; + AlphaAndButtonSurfaceObj::instance.currentImageWidth = DAT_GMImageHeaders::instance.imh[maskPicture].width; + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ShortValue, DAT_LowLevelMemory::ptr)( + DAT_GMImageHeaders::instance.imh[maskPicture].height + * AlphaAndButtonSurfaceObj::instance.currentImageWidth * 2, + COL_MAGENTA::instance.shortValue, alphaSurface); + RenderTargetInt const savedTarget = DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_BUTTON_AND_ALPHA; + // The original draws the mask through the global instance (with this: quick_diff 1.0000 -> 0.7841) + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)((eGM)maskGmID, alphaImageID, 0, 0); + int const picture = GMFirstPictureIndex::instance[gmID] + imageID - 1; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = savedTarget; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGmWithPreparedAlphaMask, this)(xPos, + yPos, DAT_GMImageHeaders::instance.imh[picture].width, DAT_GMImageHeaders::instance.imh[picture].height, + (ushort*)(imageData + DAT_GMImageOffsets::instance[picture]), blendStrength); + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 7c47bc2e05..7f192ad746 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -17023,7 +17023,7 @@ SHC_3BB0A8C1_0x004554A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00455540 | 0.0% | Pending -SHC_3BB0A8C1_0x004557B0 | 0.0% | Pending +SHC_3BB0A8C1_0x004557B0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004558E0 | 0.0% | Pending From b67b8bbc0b9a635ae8a14a50a9d258bdf3bbfd9d Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:32:14 +0100 Subject: [PATCH 21/34] reimplement: SHC_3BB0A8C1_0x0044C9C0 100.0% Reimplemented TextureRenderCore::transformTgxFromRGB555ToRGB565, gynt's code from f7163ef85 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 (8ca78619c, 2026-10-27) carries f7163ef85 unchanged; his reimpl/UI-Rendering-development (63cc49fb3) 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 Co-Authored-By: Claude Opus 5.5 --- .../transformTgxFromRGB555ToRGB565.cpp | 76 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/transformTgxFromRGB555ToRGB565.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/transformTgxFromRGB555ToRGB565.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/transformTgxFromRGB555ToRGB565.cpp new file mode 100644 index 0000000000..832f2d442e --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/transformTgxFromRGB555ToRGB565.cpp @@ -0,0 +1,76 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/IO/Graphics/TgxToken.hpp" +#include "OpenSHC/UI/Rendering/TextureRenderCore/RGB555To565Asm.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + using OpenSHC::IO::Graphics::TT_NEWLINE; + using OpenSHC::IO::Graphics::TT_REPEATING_PIXELS; + using OpenSHC::IO::Graphics::TT_TGX_PIXEL_HEADER; + using OpenSHC::IO::Graphics::TT_TGX_PIXEL_LENGTH; + using OpenSHC::IO::Graphics::TT_TRANSPARENT_PIXELS; + + // FUNCTION: STRONGHOLDCRUSADER 0x0044C9C0 + void TextureRenderCore::transformTgxFromRGB555ToRGB565(ushort* tgxDataPtr, int tgxByteSize) + { + // Copied in C++: the original copies the parameter before saving ebx and esi + ushort* const tgxPtr = tgxDataPtr; + // Written by the asm only; red waits in tgxDataPtr's slot, dead once copied + ushort _blue; + ushort _green; + // Handwritten in the original; a token's top three bits are its kind, the low five its run length - 1 + // clang-format off + __asm { + mov esi, tgxPtr + mov edx, tgxByteSize + + next_token: + cmp edx, 0 + jle done + mov ecx, 0 + mov al, byte ptr [esi] + mov cl, byte ptr [esi] + and al, TT_TGX_PIXEL_HEADER + and cl, TT_TGX_PIXEL_LENGTH + add ecx, 1 + sub edx, 1 + add esi, 1 + cmp al, TT_NEWLINE + je newline + cmp al, TT_REPEATING_PIXELS + je repeating_pixels + cmp al, TT_TRANSPARENT_PIXELS + je transparent_pixels + + stream_pixel: + } + MACRO_RGB555_TO_565_PIXEL(tgxDataPtr, MACRO_ASM_SKIP_MARKER_TEST, MACRO_ASM_SKIP_MARKER_LABEL) + __asm { + sub ecx, 1 + cmp ecx, 0 + jle next_token + jmp stream_pixel + + repeating_pixels: + } + MACRO_RGB555_TO_565_PIXEL(tgxDataPtr, MACRO_ASM_NONE, MACRO_ASM_NONE) + __asm { + jmp next_token + + transparent_pixels: + jmp next_token + + newline: + jmp next_token + + done: + } + // clang-format on + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 7f192ad746..8fd93c982f 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16905,7 +16905,7 @@ SHC_3BB0A8C1_0x0044C8F0 | 0.0% | Pending SHC_3BB0A8C1_0x0044C940 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0044C9C0 | 0.0% | Pending +SHC_3BB0A8C1_0x0044C9C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0044CAE0 | 100.0% | Reimplemented From e401895c04600c57f3b80ab785e23af30adf1206 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:32:14 +0100 Subject: [PATCH 22/34] reimplement: SHC_3BB0A8C1_0x0044F6F0 100.0% Reimplemented TextureRenderCore::renderTgxWithColorUnk, from gynt's a6053d69d 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 (8ca78619c, 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 Co-Authored-By: Claude Opus 5.5 --- .../renderTgxWithColorUnk.cpp | 156 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/renderTgxWithColorUnk.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/renderTgxWithColorUnk.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderTgxWithColorUnk.cpp new file mode 100644 index 0000000000..cb08a350b9 --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderTgxWithColorUnk.cpp @@ -0,0 +1,156 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/IO/Graphics/TgxToken.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" + +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + using OpenSHC::IO::Graphics::TT_REPEATING_PIXELS; + using OpenSHC::IO::Graphics::TT_STREAM_OF_PIXELS; + using OpenSHC::IO::Graphics::TT_TGX_PIXEL_HEADER; + using OpenSHC::IO::Graphics::TT_TGX_PIXEL_LENGTH; + using OpenSHC::IO::Graphics::TT_TRANSPARENT_PIXELS; + + // FUNCTION: STRONGHOLDCRUSADER 0x0044F6F0 + void TextureRenderCore::renderTgxWithColorUnk( + int xPos, int yPos, int width, int height, ushort* imageSource, ushort fillColorUnk) + { + // Draws the TGX image's shape in one colour: every stream or repeating pixel becomes fillColorUnk + // Declared before the if because both arms assign them; lineJump is from one row's end to the next + int lineJump; + int lineBytes; + int heightStart; + int heightEnd; + // Map arm first (== with the arms swapped: quick_diff 0.8016 -> 0.7115) + if (this->drawBufferChoiceValue != OpenSHC::Rendering::Enums::RT_SCREEN_MENU) { + DAT_TextureRenderCoreObject::instance.currentRenderSurface + = DAT_WindowAndDirectDraw::instance.surfacePointer_mapGame; + // The map surface is 4056 pixels wide + lineJump = (4056 - width) * 2; + heightStart = this->mapGameSurfaceHeightRange.start; + lineBytes = 4056 * 2; + heightEnd = this->mapGameSurfaceHeightRange.end; + } else { + DAT_TextureRenderCoreObject::instance.currentRenderSurface + = DAT_WindowAndDirectDraw::instance.surfacePointer_screenMenu; + lineJump = DAT_WindowAndDirectDraw::instance.byteSizeOfOneHorizontalLine - width * 2; + lineBytes = DAT_WindowAndDirectDraw::instance.byteSizeOfOneHorizontalLine; + heightStart = this->screenMenuSurfaceHeightRange.start; + heightEnd = this->screenMenuSurfaceHeightRange.end; + } + if (height + yPos > heightEnd) { + height = heightEnd - yPos; + if (height <= 0) { + return; + } + } + // The token loop is handwritten assembly in the original + // clang-format off + __asm { + mov esi, imageSource + mov edi, DAT_TextureRenderCoreObject::instance.currentRenderSurface + mov eax, xPos + cmp eax, 0 + jl done + add eax, eax + add edi, eax + mov eax, yPos + mov ebx, heightStart + cmp eax, ebx + jge add_y_offset + + // Rows above heightStart: skip their tokens without drawing + sub ebx, eax + mov eax, ebx + cmp height, eax + jle done + sub height, eax + skip_token: + mov ecx, 0 + mov bl, byte ptr [esi] + mov cl, byte ptr [esi] + and bl, TT_TGX_PIXEL_HEADER + and cl, TT_TGX_PIXEL_LENGTH + add esi, 1 + cmp bl, TT_TRANSPARENT_PIXELS + je skip_token + cmp bl, TT_STREAM_OF_PIXELS + je skip_stream + cmp bl, TT_REPEATING_PIXELS + je skip_repeating + jmp skip_newline + skip_stream: + add ecx, 1 + add ecx, ecx + add esi, ecx + jmp skip_token + skip_repeating: + add esi, 2 + jmp skip_token + skip_newline: + sub eax, 1 + cmp eax, 0 + jg skip_token + mov eax, heightStart + + add_y_offset: + mov edx, lineBytes + mul edx + add edi, eax + mov edx, height + draw_token: + mov ecx, 0 + mov al, byte ptr [esi] + mov cl, byte ptr [esi] + and al, TT_TGX_PIXEL_HEADER + and cl, TT_TGX_PIXEL_LENGTH + add esi, 1 + cmp al, TT_TRANSPARENT_PIXELS + je draw_transparent + cmp al, TT_STREAM_OF_PIXELS + je draw_stream + cmp al, TT_REPEATING_PIXELS + je draw_repeating + add edi, lineJump + sub edx, 1 + cmp edx, 0 + jg draw_token + jmp done + draw_transparent: + add ecx, 1 + add ecx, ecx + add edi, ecx + jmp draw_token + draw_repeating: + add esi, 2 + add ecx, 1 + mov ax, fillColorUnk + repeating_pixel: + mov word ptr [edi], ax + add edi, 2 + sub ecx, 1 + jne repeating_pixel + jmp draw_token + draw_stream: + add ecx, 1 + mov ax, fillColorUnk + stream_pixel: + mov word ptr [edi], ax + add esi, 2 + add edi, 2 + sub ecx, 1 + jne stream_pixel + jmp draw_token + done: + } + // clang-format on + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 8fd93c982f..2ef8e41838 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16957,7 +16957,7 @@ SHC_3BB0A8C1_0x0044F020 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0044F170 | 0.0% | Pending -SHC_3BB0A8C1_0x0044F6F0 | 0.0% | Pending +SHC_3BB0A8C1_0x0044F6F0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0044F850 | 100.0% | Reimplemented From 3290e40fff124d8c4aec4ec7131d174d5616a4c4 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:32:14 +0100 Subject: [PATCH 23/34] reimplement: SHC_3BB0A8C1_0x004549F0 100.0% Reimplemented TextureRenderCore::renderGfxTgxWithBlending, from gynt's 3aeeada9c 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 Co-Authored-By: Claude Opus 5.5 --- .../renderGfxTgxWithBlending.cpp | 28 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/renderGfxTgxWithBlending.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGfxTgxWithBlending.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGfxTgxWithBlending.cpp new file mode 100644 index 0000000000..f44c07273e --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGfxTgxWithBlending.cpp @@ -0,0 +1,28 @@ +#include "../TextureRenderCore.func.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + // FUNCTION: STRONGHOLDCRUSADER 0x004549F0 + void TextureRenderCore::renderGfxTgxWithBlending(int gfxIndex, int x, int y, int blendStrengthUnk) + { + // Saved before the image address is worked out (address first: quick_diff 1.0000 -> 0.9211) + RenderTargetInt const savedTarget = this->drawBufferChoiceValue; + // The pixels follow the 8-byte header (width and height) + ushort* const source + = (ushort*)(this->gmAndGfxImageDataBuffer + this->loadedGfxArray[gfxIndex].offsetInBuffer + 8); + // Only blend strengths 0-31 are drawn (the target restored on both paths: quick_diff 1.0000 -> 0.8947) + if (blendStrengthUnk < 0 || blendStrengthUnk > 31) { + return; + } + this->drawBufferChoiceValue = this->currentRenderSurfaceIdentifierUnk_0x8; + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderInterfaceOrBuildingOccupationArea, this)(x, y, + this->loadedGfxArray[gfxIndex].width, this->loadedGfxArray[gfxIndex].height, source, blendStrengthUnk); + this->drawBufferChoiceValue = savedTarget; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 2ef8e41838..1c1d988461 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16989,7 +16989,7 @@ SHC_3BB0A8C1_0x00454990 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004549C0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004549F0 | 0.0% | Pending +SHC_3BB0A8C1_0x004549F0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00454A60 | 100.0% | Reimplemented From d452b69978da3e10ca15b08db43387773bbbe720 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:59:01 +0100 Subject: [PATCH 24/34] reimplement: SHC_3BB0A8C1_0x00455C60 100.0% Reimplemented TextureRenderCore::loadGmFiles, from gynt's df9b34687 on reimpl/TextureRenderCore (27.0% recorded there, 2026-10-04, "Fixed off-by-one in the unterminated-table counter; string compare expands differently"; earlier f3c5b261d and d4c4277b1 at 27.0%). Gynt's fork's reimpl/Wilps-2026-10-18 (8ca78619c, 2026-10-27) carries df9b34687 with GMFirstPictureIndex and loadCampaignMapGfxUnk renamed loadCampaignMapPalettes. His other line, 63cc49fb3 on gynt's fork's reimpl/UI-Rendering-development (29.4% recorded) and gynt's fork's reimpl/UI-MenuItems-development (405b98871, 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 df9b34687'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 df9b34687 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 Co-Authored-By: Claude Opus 5.5 --- .../TextureRenderCore/loadGmFiles.cpp | 62 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/loadGmFiles.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/loadGmFiles.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/loadGmFiles.cpp new file mode 100644 index 0000000000..43075de955 --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/loadGmFiles.cpp @@ -0,0 +1,62 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/IO/Graphics/GmID.hpp" +#include "OpenSHC/string-literals.hpp" + +#include "OpenSHC/Globals/DAT_LoadingBarProgress.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/GMFirstPictureIndex.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + // FUNCTION: STRONGHOLDCRUSADER 0x00455C60 + void TextureRenderCore::loadGmFiles(char* fileNameArray) + { + // Up to 240 names of 1000 bytes; the loading bar gets one step per file plus one + // A found flag, not n + 1 after a plain loop (n + 1: quick_diff 0.9538 -> 0.9385) + int loadingBarSteps = 0; + BOOLEnum found = FALSE; + for (char* fileName = fileNameArray; loadingBarSteps < 240; fileName += 1000) { + ++loadingBarSteps; + // "null" ends the list + if (!strcmp(fileName, s_null_005a506c)) { + found = TRUE; + break; + } + } + if (!found) { + ++loadingBarSteps; + } + DAT_LoadingBarProgress::instance = loadingBarSteps; + this->gmNumberOfProcessedPictures = 1; + this->gmFileID = 1; + this->gmSizeOfProcessedPictures_0x44 = 0; + // The count steps first (++i in the for header: quick_diff 0.9538 -> 0.9385); the names are walked, as + // the original steps a register and then the parameter's slot (indexing: quick_diff 0.9538 -> 0.7313) + for (int i = 0; i < 240;) { + ++i; + // "null" ends the list + if (!strcmp(fileNameArray, s_null_005a506c)) { + break; + } + GMFirstPictureIndex::instance[this->gmFileID] = this->gmNumberOfProcessedPictures; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::loadGMFile, this)( + (GmID)this->gmFileID, fileNameArray); + fileNameArray += 1000; + this->gmNumberOfProcessedPictures + += this->gmFileHeaderColorpaletteArray[this->gmFileID].numberOfPicturesInFile; + ++this->gmFileID; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::loadCampaignMapGfxUnk, this)(); + // The font's .gm1 holds five font sets of the same size + DAT_TextManagerObject::instance.sizeOfOneFontSet_0x3c + = this->gmFileHeaderColorpaletteArray[OpenSHC::IO::Graphics::GID_FONT_STRONGHOLD_AA] + .numberOfPicturesInFile + / 5; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 1c1d988461..a55e0f4c49 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -17033,7 +17033,7 @@ SHC_3BB0A8C1_0x004559B0 | 0.0% | Pending SHC_3BB0A8C1_0x00455B70 | 0.0% | Pending -SHC_3BB0A8C1_0x00455C60 | 0.0% | Pending +SHC_3BB0A8C1_0x00455C60 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00455D40 | 100.0% | Reimplemented From 0e99baa12bf957f416d8aacb5a9fa6b7241c8d73 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:59:01 +0100 Subject: [PATCH 25/34] reimplement: SHC_3BB0A8C1_0x00455300 100.0% Reimplemented TextureRenderCore::renderGM, from gynt's 9de7fc1f5 on reimpl/TextureRenderCore (70.7% recorded there, 2026-10-04: "Dispatch block order"; earlier f1ae7c4af and 481bb8649 at 12.9%). Gynt's fork's reimpl/Wilps-2026-10-18 (8ca78619c, 2026-10-27) carries it with GMFirstPictureIndex and the callees renamed renderTgxImage and renderPalettedTgx. His other line, 63cc49fb3 on gynt's fork's reimpl/UI-Rendering-development (15.1%) and gynt's fork's reimpl/UI-MenuItems-development (405b98871, 2026-11-02), calls 0x0044D3D0 outside the type test, so every type, animations too, goes through it; this commit keeps 9de7fc1f5'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 9de7fc1f5 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 Co-Authored-By: Claude Opus 5.5 --- .../Rendering/TextureRenderCore/renderGM.cpp | 41 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/renderGM.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGM.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGM.cpp new file mode 100644 index 0000000000..79fef48a0f --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGM.cpp @@ -0,0 +1,41 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/IO/Graphics/GmImageType.hpp" + +#include "OpenSHC/Globals/DAT_GMImageHeaders.hpp" +#include "OpenSHC/Globals/DAT_GMImageOffsets.hpp" +#include "OpenSHC/Globals/GMFirstPictureIndex.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + // FUNCTION: STRONGHOLDCRUSADER 0x00455300 + void TextureRenderCore::renderGM(eGM gmID, int imageID, int drawX, int drawY) + { + // imageID counts from 1 within the gm file + int const imageIndex = GMFirstPictureIndex::instance[gmID] + imageID - 1; + ushort* const source + = (ushort*)((byte*)this->gmProcessedImageData + DAT_GMImageOffsets::instance[imageIndex]); + OpenSHC::IO::Graphics::GmImageTypeInt const imageType = this->gmFileHeaderColorpaletteArray[gmID].ImageType; + // One call per arm, as the original (one test with ||: quick_diff 1.0000 -> 0.6585) + if (imageType == OpenSHC::IO::Graphics::GIT_InterfaceElement) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderFunctionResponsibleForManyGameObjects, this)( + drawX, drawY, DAT_GMImageHeaders::instance.imh[imageIndex].width, + DAT_GMImageHeaders::instance.imh[imageIndex].height, source); + } else if (imageType == OpenSHC::IO::Graphics::GIT_CompressedImage) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderFunctionResponsibleForManyGameObjects, this)( + drawX, drawY, DAT_GMImageHeaders::instance.imh[imageIndex].width, + DAT_GMImageHeaders::instance.imh[imageIndex].height, source); + } else if (imageType == OpenSHC::IO::Graphics::GIT_Animation) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderUnitAnimationUnk, this)(drawX, + drawY, DAT_GMImageHeaders::instance.imh[imageIndex].width, + DAT_GMImageHeaders::instance.imh[imageIndex].height, (byte*)source); + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index a55e0f4c49..81fe0b0d77 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -17015,7 +17015,7 @@ SHC_3BB0A8C1_0x00455290 | 0.0% | Pending SHC_3BB0A8C1_0x004552E0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00455300 | 0.0% | Pending +SHC_3BB0A8C1_0x00455300 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00455390 | 100.0% | Reimplemented From bbe6673f8ff7dfa4f43db2ddbe96c01c73bc3517 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:59:01 +0100 Subject: [PATCH 26/34] reimplement: SHC_3BB0A8C1_0x0044CE00 100.0% Reimplemented TextureRenderCore::renderFacesSmallUnk, from gynt's 711809e9c on reimpl/TextureRenderCore (96.3% recorded there, 2026-10-04: "Switch dispatch, row-start pointer and hoisted line step"; earlier 7a2762374 and da985571d 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 (8ca78619c, 2026-10-27) carries it renamed drawBitmapFaceHalfSize; 63cc49fb3 on gynt's fork's reimpl/UI-Rendering-development and gynt's fork's reimpl/UI-MenuItems-development (405b98871, 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 711809e9c 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 Co-Authored-By: Claude Opus 5.5 --- .../TextureRenderCore/renderFacesSmallUnk.cpp | 55 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/renderFacesSmallUnk.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/renderFacesSmallUnk.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderFacesSmallUnk.cpp new file mode 100644 index 0000000000..090059edea --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderFacesSmallUnk.cpp @@ -0,0 +1,55 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" + +#include "OpenSHC/Globals/AlphaAndButtonSurfaceObj.hpp" +#include "OpenSHC/Globals/COL_MAGENTA.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + // FUNCTION: STRONGHOLDCRUSADER 0x0044CE00 + void TextureRenderCore::renderFacesSmallUnk(int facesIndex, int drawX, int drawY) + { + // A face bitmap is 64 x 66 pixels; the small face draws every other pixel of every other row + ushort* face = (ushort*)((byte*)this->bitmapsFaces_0x94 + facesIndex * (66 * 64 * 2)); + ushort* surface; + int lineByteWidth; + switch (this->drawBufferChoiceValue) { + case OpenSHC::Rendering::Enums::RT_MAP_GAME: + surface = DAT_WindowAndDirectDraw::instance.surfacePointer_mapGame; + lineByteWidth = 4056 * 2; + break; + case OpenSHC::Rendering::Enums::RT_BUTTON_AND_ALPHA: + surface = AlphaAndButtonSurfaceObj::instance.surfacePtr; + lineByteWidth = AlphaAndButtonSurfaceObj::instance.currentImageWidth * 2; + break; + default: + surface = DAT_WindowAndDirectDraw::instance.surfacePointer_screenMenu; + lineByteWidth = DAT_WindowAndDirectDraw::instance.byteSizeOfOneHorizontalLine; + break; + } + // Stored through the global (this->: quick_diff 0.9903 -> 0.8155) + DAT_TextureRenderCoreObject::instance.currentRenderSurface = surface; + ushort* pixel = (ushort*)((byte*)surface + lineByteWidth * drawY + drawX * 2); + for (int row = 0; row < 33; ++row) { + ushort* const rowStart = pixel; + // != keeps the column loop rolled (column < 32: quick_diff 0.9903 -> 0.8348) + for (int column = 0; column != 32; ++column) { + if (*face != (ushort)COL_MAGENTA::instance.shortValue) { + *pixel = *face; + } + ++pixel; + face += 2; + } + face += 64; + pixel = rowStart + lineByteWidth / 2; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 81fe0b0d77..a9b01f05e8 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16933,7 +16933,7 @@ SHC_3BB0A8C1_0x0044CDC0 | 0.0% | Pending SHC_3BB0A8C1_0x0044CDD0 | 0.0% | Pending -SHC_3BB0A8C1_0x0044CE00 | 0.0% | Pending +SHC_3BB0A8C1_0x0044CE00 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0044CE80 | 0.0% | Pending From 7fb2040c79303005120a20b85ee5ed8baedf32ab Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:59:01 +0100 Subject: [PATCH 27/34] reimplement: SHC_3BB0A8C1_0x00455290 100.0% Reimplemented TextureRenderCore::transformTilesetToRGB565, gynt's code from 63cc49fb3 on gynt's fork's reimpl/UI-Rendering-development (37.5% there; 7292e3af8 on reimpl/TextureRenderCore has 29.2% and e5cd892f3 29.17%; gynt's fork's reimpl/Wilps-2026-10-18 (8ca78619c, 2026-10-27) carries 7292e3af8 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, 1c3669232, 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 63cc49fb3 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 Co-Authored-By: Claude Opus 5.5 --- cmake/compiler-flags-gl.txt | 2 ++ .../transformTilesetToRGB565.cpp | 26 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/transformTilesetToRGB565.cpp diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index 7a4a662301..82b685cb99 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -111,6 +111,8 @@ src/OpenSHC/UI/Rendering/RenderButtonImageWithBlending.cpp src/OpenSHC/UI/Helpers/SetTribesPatrolButtonPressed.cpp src/OpenSHC/UI/MenuItems/BuildMenu/MenuItemActionHandler_BuildMenu_UnitActionButtons.cpp src/OpenSHC/UI/Rendering/RenderCurrentNotActiveButtonWithPossibleAlphaTexOnCurrentSurfaceUnk.cpp +src/OpenSHC/UI/Rendering/TextureRenderCore/transformTilesetToRGB565.cpp +src/OpenSHC/UI/Rendering/TextureRenderCore/transformTileObjectToRGB565.cpp src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_DrawbridgeOpenClose.cpp src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_GatehouseOpenClose.cpp src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_WorkshopWeaponSelection.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/transformTilesetToRGB565.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/transformTilesetToRGB565.cpp new file mode 100644 index 0000000000..e8ecf97895 --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/transformTilesetToRGB565.cpp @@ -0,0 +1,26 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/Globals/DAT_GMImageHeaders.hpp" +#include "OpenSHC/Globals/DAT_GMImageOffsets.hpp" +#include "OpenSHC/Globals/DAT_GMImageSizes.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + // FUNCTION: STRONGHOLDCRUSADER 0x00455290 + void TextureRenderCore::transformTilesetToRGB565(int imageIndex) + { + // A tile object is a 512-byte tile, followed by TGX data when its direction is set + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::transformTileObjectToRGB565, this)( + DAT_GMImageOffsets::instance[imageIndex]); + if (DAT_GMImageHeaders::instance.imh[imageIndex].direction != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::transformTgxFromRGB555ToRGB565, this)( + (ushort*)((byte*)this->gmProcessedImageData + DAT_GMImageOffsets::instance[imageIndex] + 512), + DAT_GMImageSizes::instance[imageIndex] - 512); + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index a9b01f05e8..d875e1fb4c 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -17011,7 +17011,7 @@ SHC_3BB0A8C1_0x00455250 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00455270 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00455290 | 0.0% | Pending +SHC_3BB0A8C1_0x00455290 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004552E0 | 100.0% | Reimplemented From 26a203367b3f375522fd631c01f110f05aeaceab Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 08:59:01 +0100 Subject: [PATCH 28/34] reimplement: SHC_3BB0A8C1_0x0044CD40 100.0% Reimplemented TextureRenderCore::drawBitmapFace, from gynt's b0012e838 on reimpl/TextureRenderCore (76.4% recorded there, 2026-10-04: "Pixel local typed unsigned"; 22bca4d6a before it also 76.4%, ffd4161b9 and d469777d8 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 (8ca78619c, 2026-10-27) unchanged. His other line, 63cc49fb3 on gynt's fork's reimpl/UI-Rendering-development (64.2%) and gynt's fork's reimpl/UI-MenuItems-development (405b98871, 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 b0012e838 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 63cc49fb3, 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 Co-Authored-By: Claude Opus 5.5 --- .../TextureRenderCore/drawBitmapFace.cpp | 59 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/drawBitmapFace.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/drawBitmapFace.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/drawBitmapFace.cpp new file mode 100644 index 0000000000..fecb3e8b89 --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/drawBitmapFace.cpp @@ -0,0 +1,59 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" + +#include "OpenSHC/Globals/AlphaAndButtonSurfaceObj.hpp" +#include "OpenSHC/Globals/COL_MAGENTA.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + // FUNCTION: STRONGHOLDCRUSADER 0x0044CD40 + void TextureRenderCore::drawBitmapFace(int bitmapFaceIndex, int xPos, int yPos) + { + // A face bitmap is 64 x 66 pixels; rowSkip is the surface's gap between two face rows + int rowSkip; + int lineByteWidth; + ushort* face = (ushort*)((byte*)this->bitmapsFaces_0x94 + bitmapFaceIndex * (66 * 64 * 2)); + // Stored through the global in each arm (a surface local: quick_diff 0.9804 -> 0.7255; this->: 0.5524) + switch (this->drawBufferChoiceValue) { + case OpenSHC::Rendering::Enums::RT_MAP_GAME: + DAT_TextureRenderCoreObject::instance.currentRenderSurface + = DAT_WindowAndDirectDraw::instance.surfacePointer_mapGame; + rowSkip = 4056 - 64; + lineByteWidth = 4056 * 2; + break; + case OpenSHC::Rendering::Enums::RT_BUTTON_AND_ALPHA: + DAT_TextureRenderCoreObject::instance.currentRenderSurface + = AlphaAndButtonSurfaceObj::instance.surfacePtr; + rowSkip = AlphaAndButtonSurfaceObj::instance.currentImageWidth - 64; + lineByteWidth = AlphaAndButtonSurfaceObj::instance.currentImageWidth * 2; + break; + default: + DAT_TextureRenderCoreObject::instance.currentRenderSurface + = DAT_WindowAndDirectDraw::instance.surfacePointer_screenMenu; + rowSkip = DAT_WindowAndDirectDraw::instance.byteSizeOfOneHorizontalLine / 2 - 64; + lineByteWidth = DAT_WindowAndDirectDraw::instance.byteSizeOfOneHorizontalLine; + break; + } + ushort* pixel = (ushort*)((byte*)DAT_TextureRenderCoreObject::instance.currentRenderSurface + + lineByteWidth * yPos + xPos * 2); + for (int row = 0; row < 66; ++row) { + for (int column = 0; column < 64; ++column) { + ushort const color = *face; + ++face; + if (color != (ushort)COL_MAGENTA::instance.shortValue) { + *pixel = color; + } + ++pixel; + } + pixel += rowSkip; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index d875e1fb4c..ebe443b73f 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16927,7 +16927,7 @@ SHC_3BB0A8C1_0x0044CD10 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0044CD30 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0044CD40 | 0.0% | Pending +SHC_3BB0A8C1_0x0044CD40 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0044CDC0 | 0.0% | Pending From 8e4c48a20be303de5ed1255129e9bc5374b919f4 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 09:38:28 +0100 Subject: [PATCH 29/34] Constructor_TextureRenderCore: cast the two mallocs to the types of the 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 --- .../TextureRenderCore/Constructor_TextureRenderCore.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/Constructor_TextureRenderCore.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/Constructor_TextureRenderCore.cpp index 7ba1fe5544..c176e41d19 100644 --- a/src/OpenSHC/UI/Rendering/TextureRenderCore/Constructor_TextureRenderCore.cpp +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/Constructor_TextureRenderCore.cpp @@ -32,7 +32,7 @@ namespace UI { this->unknownSfxAndGmRelatedFlag = FALSE; // bufferAllocStateUnk_0x0 records a failed allocation: 1 for an image buffer, 2 and 3 for the other two this->gmProcessedImageData - = MACRO_CALL(OpenSHC::OS_Func::_malloc)(this->gmProcessedImageDataBufferSize_0x74); + = (byte*)MACRO_CALL(OpenSHC::OS_Func::_malloc)(this->gmProcessedImageDataBufferSize_0x74); if (!this->gmProcessedImageData) { this->bufferAllocStateUnk_0x0 = 1; return this; @@ -61,7 +61,7 @@ namespace UI { this->totalLoadedGfx = 0; this->colorPaletteOverride = 0; // room for 36 faces of 8448 bytes (readBitmapFace's FACE_SIZE), and their sizes, none loaded yet - this->bitmapsFaces_0x94 = MACRO_CALL(OpenSHC::OS_Func::_malloc)(36 * 8448); + this->bitmapsFaces_0x94 = (ushort(*)[66][64])MACRO_CALL(OpenSHC::OS_Func::_malloc)(36 * 8448); for (int i = 0; i < countof(this->bitmapFaceSizes); ++i) { this->bitmapFaceSizes[i] = 0; } From 008439dfef79570c98647dae77a725c3559bd347 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 09:38:29 +0100 Subject: [PATCH 30/34] headers: TextureRenderCore.gmProcessedImageData is a byte* 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 --- src/OpenSHC/UI/Rendering/TextureRenderCore.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore.hpp b/src/OpenSHC/UI/Rendering/TextureRenderCore.hpp index bca7c888bf..8b0c9f187e 100644 --- a/src/OpenSHC/UI/Rendering/TextureRenderCore.hpp +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore.hpp @@ -60,7 +60,7 @@ namespace UI { dword mbr_0x6c; // 0x0000006C length: 4 dword colorPaletteOverride; // 0x00000070 length: 4 int gmProcessedImageDataBufferSize_0x74; // 0x00000074 length: 4 - void* gmProcessedImageData; // 0x00000078 length: 4 + byte* gmProcessedImageData; // 0x00000078 length: 4 int unknownMemSize_1_0x7c; // 0x0000007C length: 4 void* unknownMemPtr_1_0x80; // 0x00000080 length: 4 int unknownMemSize_2_0x84; // 0x00000084 length: 4 From 8a7df4079308543b3108bc313572e9d1bd0d4731 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 09:38:29 +0100 Subject: [PATCH 31/34] headers: TextureRenderCore.bitmapsFaces_0x94 is a ushort (*)[66][64] 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 --- src/OpenSHC/UI/Rendering/TextureRenderCore.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore.hpp b/src/OpenSHC/UI/Rendering/TextureRenderCore.hpp index 8b0c9f187e..49899e9e50 100644 --- a/src/OpenSHC/UI/Rendering/TextureRenderCore.hpp +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore.hpp @@ -67,7 +67,7 @@ namespace UI { void* address2; // 0x00000088 length: 4 int gmAndGfxImageDataBufferSize_0x8c; // 0x0000008C length: 4 byte* gmAndGfxImageDataBuffer; // 0x00000090 length: 4 - void* bitmapsFaces_0x94; // 0x00000094 length: 4 + ushort (*bitmapsFaces_0x94)[66][64]; // 0x00000094 length: 4 int bitmapFaceSizes[36]; // 0x00000098 length: 144 int field_0x128; // 0x00000128 length: 4 int field_0x12c; // 0x0000012C length: 4 From 0f2349902c5733362a1a96ac4837f270348aa8bb Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 09:38:29 +0100 Subject: [PATCH 32/34] TextureRenderCore: drop the casts the two retyped fields make redundant 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 --- src/OpenSHC/UI/Rendering/TextureRenderCore/drawBitmapFace.cpp | 2 +- .../Rendering/TextureRenderCore/drawTgxGmOnFlaggedSurface.cpp | 3 +-- .../UI/Rendering/TextureRenderCore/renderFacesSmallUnk.cpp | 2 +- src/OpenSHC/UI/Rendering/TextureRenderCore/renderGM.cpp | 3 +-- .../UI/Rendering/TextureRenderCore/renderGMWithAlphaMask.cpp | 2 +- .../UI/Rendering/TextureRenderCore/renderGMWithBlending.cpp | 3 +-- .../Rendering/TextureRenderCore/transformRawToRGB555To565.cpp | 2 +- .../transformRawWithMarkerUnkToRGB555To565.cpp | 2 +- .../TextureRenderCore/transformTgxCompressedImageToRGB565.cpp | 4 +--- .../TextureRenderCore/transformTileObjectToRGB565.cpp | 2 +- .../Rendering/TextureRenderCore/transformTilesetToRGB565.cpp | 2 +- 11 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/drawBitmapFace.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/drawBitmapFace.cpp index fecb3e8b89..b740046835 100644 --- a/src/OpenSHC/UI/Rendering/TextureRenderCore/drawBitmapFace.cpp +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/drawBitmapFace.cpp @@ -17,7 +17,7 @@ namespace UI { // A face bitmap is 64 x 66 pixels; rowSkip is the surface's gap between two face rows int rowSkip; int lineByteWidth; - ushort* face = (ushort*)((byte*)this->bitmapsFaces_0x94 + bitmapFaceIndex * (66 * 64 * 2)); + ushort* face = this->bitmapsFaces_0x94[bitmapFaceIndex][0]; // Stored through the global in each arm (a surface local: quick_diff 0.9804 -> 0.7255; this->: 0.5524) switch (this->drawBufferChoiceValue) { case OpenSHC::Rendering::Enums::RT_MAP_GAME: diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/drawTgxGmOnFlaggedSurface.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/drawTgxGmOnFlaggedSurface.cpp index 659cf0aff8..07266caf06 100644 --- a/src/OpenSHC/UI/Rendering/TextureRenderCore/drawTgxGmOnFlaggedSurface.cpp +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/drawTgxGmOnFlaggedSurface.cpp @@ -15,8 +15,7 @@ namespace UI { { // picture imageIndexInGm of the gm file, counted from 1 int const imageIndex = GMFirstPictureIndex::instance[gmId] + imageIndexInGm - 1; - ushort* const source - = (ushort*)((byte*)this->gmProcessedImageData + DAT_GMImageOffsets::instance[imageIndex]); + ushort* const source = (ushort*)(this->gmProcessedImageData + DAT_GMImageOffsets::instance[imageIndex]); // interface elements and compressed images draw the same way // two tests as in the original (one test with ||: quick_diff 1.0000 -> 0.3014) if (this->gmFileHeaderColorpaletteArray[gmId].ImageType == OpenSHC::IO::Graphics::GIT_InterfaceElement) { diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/renderFacesSmallUnk.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderFacesSmallUnk.cpp index 090059edea..d8a1123869 100644 --- a/src/OpenSHC/UI/Rendering/TextureRenderCore/renderFacesSmallUnk.cpp +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderFacesSmallUnk.cpp @@ -15,7 +15,7 @@ namespace UI { void TextureRenderCore::renderFacesSmallUnk(int facesIndex, int drawX, int drawY) { // A face bitmap is 64 x 66 pixels; the small face draws every other pixel of every other row - ushort* face = (ushort*)((byte*)this->bitmapsFaces_0x94 + facesIndex * (66 * 64 * 2)); + ushort* face = this->bitmapsFaces_0x94[facesIndex][0]; ushort* surface; int lineByteWidth; switch (this->drawBufferChoiceValue) { diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGM.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGM.cpp index 79fef48a0f..e00352149d 100644 --- a/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGM.cpp +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGM.cpp @@ -15,8 +15,7 @@ namespace UI { { // imageID counts from 1 within the gm file int const imageIndex = GMFirstPictureIndex::instance[gmID] + imageID - 1; - ushort* const source - = (ushort*)((byte*)this->gmProcessedImageData + DAT_GMImageOffsets::instance[imageIndex]); + ushort* const source = (ushort*)(this->gmProcessedImageData + DAT_GMImageOffsets::instance[imageIndex]); OpenSHC::IO::Graphics::GmImageTypeInt const imageType = this->gmFileHeaderColorpaletteArray[gmID].ImageType; // One call per arm, as the original (one test with ||: quick_diff 1.0000 -> 0.6585) if (imageType == OpenSHC::IO::Graphics::GIT_InterfaceElement) { diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGMWithAlphaMask.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGMWithAlphaMask.cpp index cbe1e16822..39f27c4351 100644 --- a/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGMWithAlphaMask.cpp +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGMWithAlphaMask.cpp @@ -19,7 +19,7 @@ namespace UI { void TextureRenderCore::renderGMWithAlphaMask( GmID gmID, int imageID, int xPos, int yPos, GmID maskGmID, int alphaImageID, int blendStrength) { - byte* const imageData = (byte*)this->gmProcessedImageData; + byte* const imageData = this->gmProcessedImageData; // Read before the zoom test (read at its use: quick_diff 1.0000 -> 0.9091) ushort* const alphaSurface = AlphaAndButtonSurfaceObj::instance.surfacePtr; // With isZoom2 set the image is drawn blended, without the mask diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGMWithBlending.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGMWithBlending.cpp index 6e59e2647a..b12de8049d 100644 --- a/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGMWithBlending.cpp +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderGMWithBlending.cpp @@ -15,8 +15,7 @@ namespace UI { { // picture imageID of the gm file, counted from 1; a blend strength of 32 draws nothing, 0 draws unblended int const imageIndex = GMFirstPictureIndex::instance[GmID] + imageID - 1; - ushort* const source - = (ushort*)((byte*)this->gmProcessedImageData + DAT_GMImageOffsets::instance[imageIndex]); + ushort* const source = (ushort*)(this->gmProcessedImageData + DAT_GMImageOffsets::instance[imageIndex]); if (blendStrengthUnk == 32) { return; } diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/transformRawToRGB555To565.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/transformRawToRGB555To565.cpp index 3b533d154c..6c677c7e25 100644 --- a/src/OpenSHC/UI/Rendering/TextureRenderCore/transformRawToRGB555To565.cpp +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/transformRawToRGB555To565.cpp @@ -10,7 +10,7 @@ namespace UI { void TextureRenderCore::transformRawToRGB555To565(int imageOffset, int imageSize) { // The conversion loop is handwritten assembly in the original, see RGB555To565Asm.hpp. - ushort* _colorPtr = (ushort*)((byte*)this->gmProcessedImageData + imageOffset); + ushort* _colorPtr = (ushort*)(this->gmProcessedImageData + imageOffset); // written by the asm below ushort _blue; ushort _green; diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/transformRawWithMarkerUnkToRGB555To565.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/transformRawWithMarkerUnkToRGB555To565.cpp index 8cb2ec745e..f8c9f7cc78 100644 --- a/src/OpenSHC/UI/Rendering/TextureRenderCore/transformRawWithMarkerUnkToRGB555To565.cpp +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/transformRawWithMarkerUnkToRGB555To565.cpp @@ -10,7 +10,7 @@ namespace UI { void TextureRenderCore::transformRawWithMarkerUnkToRGB555To565(int imageOffset, int imageSize) { // The conversion loop is handwritten assembly in the original, see RGB555To565Asm.hpp. - ushort* _colorPtr = (ushort*)((byte*)this->gmProcessedImageData + imageOffset); + ushort* _colorPtr = (ushort*)(this->gmProcessedImageData + imageOffset); // written by the asm below ushort _blue; ushort _green; diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/transformTgxCompressedImageToRGB565.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/transformTgxCompressedImageToRGB565.cpp index 4038a632a7..11e3a8693d 100644 --- a/src/OpenSHC/UI/Rendering/TextureRenderCore/transformTgxCompressedImageToRGB565.cpp +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/transformTgxCompressedImageToRGB565.cpp @@ -1,7 +1,5 @@ #include "../TextureRenderCore.func.hpp" -#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" - #include "OpenSHC/Globals/DAT_GMImageOffsets.hpp" #include "OpenSHC/Globals/DAT_GMImageSizes.hpp" #include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" @@ -14,7 +12,7 @@ namespace UI { void TextureRenderCore::transformTgxCompressedImageToRGB565(int imageIndex) { MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::transformTgxFromRGB555ToRGB565, this)( - (ushort*)((byte*)this->gmProcessedImageData + DAT_GMImageOffsets::instance[imageIndex]), + (ushort*)(this->gmProcessedImageData + DAT_GMImageOffsets::instance[imageIndex]), DAT_GMImageSizes::instance[imageIndex]); } diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/transformTileObjectToRGB565.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/transformTileObjectToRGB565.cpp index b87d4e4fe0..fdfda12bc9 100644 --- a/src/OpenSHC/UI/Rendering/TextureRenderCore/transformTileObjectToRGB565.cpp +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/transformTileObjectToRGB565.cpp @@ -10,7 +10,7 @@ namespace UI { void TextureRenderCore::transformTileObjectToRGB565(int imageOffset) { // The conversion loop is handwritten assembly in the original, see RGB555To565Asm.hpp. - ushort* _colorPtr = (ushort*)((byte*)this->gmProcessedImageData + imageOffset); + ushort* _colorPtr = (ushort*)(this->gmProcessedImageData + imageOffset); // written by the asm below ushort _blue; ushort _green; diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/transformTilesetToRGB565.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/transformTilesetToRGB565.cpp index e8ecf97895..8d939b9f96 100644 --- a/src/OpenSHC/UI/Rendering/TextureRenderCore/transformTilesetToRGB565.cpp +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/transformTilesetToRGB565.cpp @@ -16,7 +16,7 @@ namespace UI { DAT_GMImageOffsets::instance[imageIndex]); if (DAT_GMImageHeaders::instance.imh[imageIndex].direction != 0) { MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::transformTgxFromRGB555ToRGB565, this)( - (ushort*)((byte*)this->gmProcessedImageData + DAT_GMImageOffsets::instance[imageIndex] + 512), + (ushort*)(this->gmProcessedImageData + DAT_GMImageOffsets::instance[imageIndex] + 512), DAT_GMImageSizes::instance[imageIndex] - 512); } } From 6e3f0dbcde21dda046e8c1ec13f618d1f339c045 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 20:00:00 +0100 Subject: [PATCH 33/34] headers: TextureRenderCore.bitmapsFaces_0x94 is a ushort* Follows main's header sync eef6f667a, which types the field the same way; the merge of main after the next commit leaves this PR with no change to TextureRenderCore.hpp. 8a7df4079 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 --- src/OpenSHC/UI/Rendering/TextureRenderCore.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore.hpp b/src/OpenSHC/UI/Rendering/TextureRenderCore.hpp index 49899e9e50..61d86ddadb 100644 --- a/src/OpenSHC/UI/Rendering/TextureRenderCore.hpp +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore.hpp @@ -67,7 +67,7 @@ namespace UI { void* address2; // 0x00000088 length: 4 int gmAndGfxImageDataBufferSize_0x8c; // 0x0000008C length: 4 byte* gmAndGfxImageDataBuffer; // 0x00000090 length: 4 - ushort (*bitmapsFaces_0x94)[66][64]; // 0x00000094 length: 4 + ushort* bitmapsFaces_0x94; // 0x00000094 length: 4 int bitmapFaceSizes[36]; // 0x00000098 length: 144 int field_0x128; // 0x00000128 length: 4 int field_0x12c; // 0x0000012C length: 4 From a2dd7d03eb2195d2b9f6e58199cc4d96d1b62433 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 20:00:10 +0100 Subject: [PATCH 34/34] TextureRenderCore: take the faces through the plain ushort* bitmapsFaces_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 --- .../TextureRenderCore/Constructor_TextureRenderCore.cpp | 5 +++-- .../UI/Rendering/TextureRenderCore/drawBitmapFace.cpp | 2 +- .../UI/Rendering/TextureRenderCore/renderFacesSmallUnk.cpp | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/Constructor_TextureRenderCore.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/Constructor_TextureRenderCore.cpp index c176e41d19..07920fbee7 100644 --- a/src/OpenSHC/UI/Rendering/TextureRenderCore/Constructor_TextureRenderCore.cpp +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/Constructor_TextureRenderCore.cpp @@ -60,8 +60,9 @@ namespace UI { } this->totalLoadedGfx = 0; this->colorPaletteOverride = 0; - // room for 36 faces of 8448 bytes (readBitmapFace's FACE_SIZE), and their sizes, none loaded yet - this->bitmapsFaces_0x94 = (ushort(*)[66][64])MACRO_CALL(OpenSHC::OS_Func::_malloc)(36 * 8448); + // room for one 64 x 66 RGB565 face bitmap per entry of bitmapFaceSizes, and their sizes, none loaded yet + this->bitmapsFaces_0x94 = (ushort*)MACRO_CALL(OpenSHC::OS_Func::_malloc)( + countof(this->bitmapFaceSizes) * 66 * 64 * sizeof(ushort)); for (int i = 0; i < countof(this->bitmapFaceSizes); ++i) { this->bitmapFaceSizes[i] = 0; } diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/drawBitmapFace.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/drawBitmapFace.cpp index b740046835..071ad53ca4 100644 --- a/src/OpenSHC/UI/Rendering/TextureRenderCore/drawBitmapFace.cpp +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/drawBitmapFace.cpp @@ -17,7 +17,7 @@ namespace UI { // A face bitmap is 64 x 66 pixels; rowSkip is the surface's gap between two face rows int rowSkip; int lineByteWidth; - ushort* face = this->bitmapsFaces_0x94[bitmapFaceIndex][0]; + ushort* face = this->bitmapsFaces_0x94 + bitmapFaceIndex * 66 * 64; // Stored through the global in each arm (a surface local: quick_diff 0.9804 -> 0.7255; this->: 0.5524) switch (this->drawBufferChoiceValue) { case OpenSHC::Rendering::Enums::RT_MAP_GAME: diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/renderFacesSmallUnk.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderFacesSmallUnk.cpp index d8a1123869..65c9d59008 100644 --- a/src/OpenSHC/UI/Rendering/TextureRenderCore/renderFacesSmallUnk.cpp +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/renderFacesSmallUnk.cpp @@ -15,7 +15,7 @@ namespace UI { void TextureRenderCore::renderFacesSmallUnk(int facesIndex, int drawX, int drawY) { // A face bitmap is 64 x 66 pixels; the small face draws every other pixel of every other row - ushort* face = this->bitmapsFaces_0x94[facesIndex][0]; + ushort* face = this->bitmapsFaces_0x94 + facesIndex * 66 * 64; ushort* surface; int lineByteWidth; switch (this->drawBufferChoiceValue) {