Skip to content

tools: Enable-Reimplemented-Functions also flips resolvers wrapped after the flag - #375

Merged
gynt merged 1 commit into
sourcehold:mainfrom
kotijekriv:fix/enable-functions-wrapped-resolvers
Nov 8, 2026
Merged

gynt merged 1 commit into
sourcehold:mainfrom
kotijekriv:fix/enable-functions-wrapped-resolvers

Conversation

@kotijekriv

Copy link
Copy Markdown
Contributor

tools/reimplementation-control/Enable-Reimplemented-Functions.ps1 misses every function resolver that clang-format wrapped after its flag. Its pattern expects , false and then , Address::SHC_3BB0A8C1_... with exactly one space between them, so a resolver written as false, + line break + Address::... is never flipped. 540 of main's 3,663 function resolvers are wrapped that way. This PR allows any whitespace there (\s*,\s*Address), the same as the batch helpers (enable_local_functions.py, common.py) already do. Nothing else changes.

What it fixes

With such a resolver left off, nothing hooks or calls our function, and with /GL the compiler is free to give it a register calling convention, which reccmp then reads low. #357's /GL trio showed it in a full build: FindDisplayElementWithID's resolver isn't wrapped, the other two are.

Function Old script This PR
FindDisplayElementWithID 100.0% 100.0%
GetIfDisplayElementStateNotZero 81.8% 100.0%
RenderTimeUntilDefeatDisplayElement 54.5% 100.0%

The hooked calls the game makes are not affected either way: a function is hooked only when its resolver is on, and then its address is taken, so its calling convention stays standard. The low readings came only from the measurement setup.

Measured

A full build of main (303fe1c, every .cpp under src/OpenSHC, the struct resolvers on, the function resolvers flipped as each script flips them), with the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a) and sourcehold's reccmp (cce67bcab, --resolve-wrapped-calls --ignore-security-cookie):

  • Of the 79 functions at 100% in the status file that read lower with the old script, 18 read 100% with this one, and doImplode and doExplode improve (96.3 -> 98.8 and 95.8 -> 98.6). 10 of the 18 have wrapped resolvers themselves; 6 call a callee whose wrapped resolver is now flipped.
  • Nothing reads worse: 0 of 1,943 functions. The average goes from 97.47% to 97.78%.
  • 11 of the wrapped functions among the 79 stay below 100% for other reasons (4 in WideCharMultiByteState, 2 DecoderBuffer hashes, doImplode, doExplode, createWindow, lightUpBuilding, resolveResourceFileName).

To link, that build needed two local edits in the generated src/symbols/data.asm, which #368 describes (DAT_PerformanceCounterFrequency declared as a U_LARGE_INTEGER struct where _LARGE_INTEGER is a union, and DPLAY_InterfacePointer in a dplay namespace). They're not in this PR.

Enable-Reimplemented-Data.ps1 doesn't have the problem: its pattern doesn't depend on what follows the flag, and no struct resolver on main is wrapped.

Other PRs: the ready #354 and #374 (a fix for main), and the drafts #313, #318, #321, #327, #328, #356, #360 and #363.

🤖 Generated with Claude Code

…ter the flag

The script matched `, false` followed by `, Address::...` with exactly one space, so a resolver that clang-format
wrapped after the flag (`false,` then a line break and `Address::...`) was never flipped. 540 of main's 3,663 function
resolvers are wrapped that way. With such a callee left off, nothing hooks or calls our function, and /GL gives it
a register calling convention, which reccmp then reads low.

That is what sourcehold#357's GetIfDisplayElementStateNotZero (81.8) and RenderTimeUntilDefeatDisplayElement (54.5) showed in
a full build: their resolvers are wrapped, FindDisplayElementWithID's is not. In an alone build of the three, the
old pattern flips only FindDisplayElementWithID and reads 100.0 / 81.8 / 54.5; `\s*,\s*Address` flips all three
and reads 100.0 / 100.0 / 100.0. The batch helpers (enable_local_functions.py, common.py) already allow the line
break.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gynt
gynt added this pull request to the merge queue Nov 8, 2026
Merged via the queue into sourcehold:main with commit 6ae8b37 Nov 8, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants