Skip to content

Reimplement 5 scenario editor menu and modal functions at 100% - #354

Merged
gynt merged 23 commits into
sourcehold:mainfrom
kotijekriv:reimpl/batch17-100
Nov 8, 2026
Merged

gynt merged 23 commits into
sourcehold:mainfrom
kotijekriv:reimpl/batch17-100

Conversation

@kotijekriv

@kotijekriv kotijekriv commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Five scenario editor functions at 100%, each with its status line: the new-event condition and action menus, the scenario editor's main buttons, and two modal dialogs (an unused "set name" box and the new-event-action banner).

Three come from our draft #328, which held gynt's drafts from his fork's reimpl/UI-MenuItems-development; they were rewritten from the binary, and #328 drops them in the same push. The two modals are gynt's code from his fork's reimpl/UI-MenuModals-100 (his closed #252), measured 100% unchanged on today's main and only restyled. Every commit body says what changed against the draft, and the commits built on his drafts credit him as co-author. Header changes, each in a commit of its own (below), so this PR needs the declaration/type change label. gynt's Ghidra sync eef6f66 took two of them into main (allOrAnyCondition and MapPropertiesState::flag) and e32319b the two enums, and 3a1c7f7 the slider callback types (the field and every callback parameter as NoArgCallback*, and setModalSliderParameters' int* param_5). Main is merged in (545cce6), and no header change is left. Main kept setSliderParameters' and setSliderParameters2's destinations as undefined* and dword, which this PR now follows: BaseMenuButtons casts its four destinations to undefined*, and setSliderParameters2.cpp is main's file with the NoArgCallback* callback, which also makes it compile again on main. int* and short* would fit those two destinations (the function stores them into the int* and short* destination fields), so they're listed below as proposed. The modal's switch over ScenarioEventType uses the enum's names since 3e330e1 (gynt's review); the other switches are over button numbers, which have no enum yet.

Other PRs: the ready #348, #349, #352 and #353, the ready #355 (UI::MenuModals), and the drafts #313, #318, #321, #327 and #328.

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

It went through the same checks as #352: a fresh-eyes review of every file (every case and jump-table target compared with the original's disassembly, texts against cr.tex; its points applied and measured), openshc-pr-check with no errors, and status_regression.py, which finds nothing below a known score on main or any fork.

Header changes

IngameScenarioEventItemContent::allOrAnyCondition is a short.

allOrAnyCondition (byte, +0x08) and magic (byte, +0x09) become one short allOrAnyCondition (982cfdf). Every access in the exe is 16-bit, and nothing touches +0x09 on its own:

  • initializeScenarioEvent sets it with mov word ptr [ecx + 0x18], 1 (0x004B77B8);
  • createScenarioEventForNextMonth and createChainedMissionOutcomeEvents clear it with mov word ptr [.. + 0x5C8], 0 (0x004BDA3A, 0x004BDC16, 0x004BDD06, 0x004BDDF8);
  • the NewEventCondition handler toggles it with xor word ptr [eax + 0x01653E20], 1 (0x004B965E);
  • the NewEventCondition render tests it with cmp word ptr [..], 0 (0x004C0296), and the in-game event check in 0x004C35B0 with cmp word ptr [ebp + 0x5C8], 0 (0x004C37E7).

0 shows "Any of these" and 1 "All of these". Nothing on main uses either field. gynt's open #293 already writes the pair as one word (*(short*)&...allOrAnyCondition = 0, four places), which still compiles with the short, where the cast becomes a no-op. The unused ScenarioEventItem.hpp keeps its old byte pair.

After TheRedDaemon's review, the proven proposals are header changes too, and the functions use them (014186a):

  • ScenarioEventType: the 39 event types, named from cr.tex TEXT_SCENARIO 128-155 and 177-187, the texts the action menu draws (6ad389d). 2, 26 and 27 are SET_MESSAGE, SET_WIN_AND_MESSAGE and SET_LOSE_AND_MESSAGE; 31-38 have only placeholder texts.

  • ScenarioEventConditionIndex: the 40 condition indexes, named from TEXT_SCENARIO 106-125 and 190-209 (ce5a036). They stay an array, as the condition menu loops over all 40 and the parallel tables (EventConditionMaxValue and the others) use the same index.

  • MapPropertiesState::flag is a BOOLEnum: its only store in the exe is 1, and its readers compare it with 0 (a51fffd).

  • MenuModalComposition's slider callback is a no-argument function, not a SliderActionHandler (gynt's question, answered in the thread with the addresses). The exe calls the stored sliderCallbackFunction only when the modal closes, with nothing pushed (0x004B0F90, 0x004B0FF2, 0x004B1020, 0x004B1082, and a tail jmp at 0x004B10C0); all six functions the exe stores there read no stack argument. With main's Util::FunctionTypes::NoArgCallback, each in a commit of its own:

    • setSliderParameters(int, int, int, int* destination, NoArgCallback*) (7e208ed, 24e4699): every destination is an int, so BaseMenuButtons' eight casts are gone;
    • setSliderParameters2 takes a NoArgCallback* (458be7f) and a short* destination (efc999d): it goes into destination2, which the slider handler writes with word stores only (0x004AA71C, 0x004AA736, 0x004AA762);
    • setModalSliderParameters takes a NoArgCallback* (9ab2552) and an int* param_5 (b216471): it goes into destination, written with dword stores only (0x004AA6E3, 0x004AA6F8, 0x004AA755);
    • the field sliderCallbackFunction is a NoArgCallback* (7dde7b8).

    setSliderParameters2.cpp and main's UnusedWinCondition_Options drop their casts (b53888f) and stay at 100.0%; BaseMenuButtons stays at 98.8% raw (only call targets differ). gynt's 100% setModalSliderParameters on his fork (e31bef6, reimplement remaining OpenSHC::UI namespaces (57 functions, 10 at 100%) #256) will need int* param_5, NoArgCallback* param_6 to match the declaration, and his OverlaySlider_Deselect compares the field with NULL instead of (undefined*)0x0.

Behaviour fixed compared with the drafts

  • NewEventAction_Main (0x004C0860): three bugs in the draft: buttons 38-40 drew "Select Message" and then hid it (the break led to DAT_ButtonUnknownZero = 1); 178's highlighted row fell into the plain draw and was hidden; the plain rows with an icon (146, 148) were hidden after drawing. This version returns where the original does.
  • BaseMenuButtons and NewEventCondition behave as their drafts did; the drafts' out-of-range indexing (SEC_StartingResources[indexStored + 5], which is SEC_SiegeInformation[indexStored - 20], and the condition tables through unknown3 offsets) and the gotos are gone. BaseMenuButtons' button 43 formats the event's year and never uses it, as the original does (0x004B86E5); a fixme line says so.
Class Function Address Raw Notes
NewEventCondition MenuItemRenderFunction_NewEventCondition_Main 0x004C01B0 99.7% From #328 (72.8%). Only the RenderScenarioButtonWithText tail-call targets differ while its resolver is off; with it on, 100.0% raw.
EditScenario MenuItemActionHandler_EditScenario_BaseMenuButtons 0x004B8220 98.8% From #328 (73.5%). Only atol and, while the SumUnitPoints / RestoreScenarioGold resolvers are off, the slider callbacks differ; with them on, 99.5% raw (atol only).
NewEventAction MenuItemRenderFunction_NewEventAction_Main 0x004C0860 99.3% From #328 (62.3%); the fixes above. Only the tail-call targets differ while RenderScenarioButtonWithText's resolver is off; with it on, 100.0% raw.
UnusedSetName MenuModalRenderFunction_UnusedSetName 0x004266E0 100.0% gynt's code (97.9% on his fork), restyled.
NewEventAction MenuModalRenderFunction_NewEventAction 0x004ABAB0 100.0% gynt's code (97.7% on his fork), restyled.

Kept as they are, and why

Each was measured; a one-line comment in the code says why.

  • NewEventCondition: the text number copied from the button before the 5000 check (after it: quick_diff 0.9440 -> 0.8940); case 2000 before 1000 and every box case testing !interacting first, so the box blocks are shared as in the original (in turn: 0.9109; interacting first: 0.8223); the four box cases separate, as the original has four entry blocks; two calls per colour in -1 (a colour local: 0.9237); 209's ten tests written out (loops: 0.8543), and the 20-22 run (a loop: 0.8708).
  • BaseMenuButtons: the text group before the text index (index first: 0.9573 -> 0.9197); the subType stores written out (a loop: 0.9001).
  • NewEventAction_Main: the row's text copied from the button before selectedButton (selectedButton first: 0.9184 -> 0.9143; decrementing a copy of the parameter: 0.2490); both draws in the not-highlighted row (one draw: 0.7731); iconOffset at the top (at first use: 0.8907).

Proposed, not changed here

  • MenuModalComposition::setSliderParameters' destination as an int* and setSliderParameters2's as a short*: the first is stored into the int* destination field, the second into short* destination2, which the slider handler writes with word stores only (0x004AA71C, 0x004AA736, 0x004AA762). Main keeps undefined* and dword after its sync, so this PR follows it.

Names only, for the Ghidra side:

  • MissionAestheticsDefinedData::field_0x170[5] = {156, 9, 10, 11, 12}: the texts "Any", "Rat", "Snake", "Pig", "Wolf" for the opponent conditions, e.g. EventConditionOpponentTextOffsets (our next MenuModals PR uses this field too). field_0x345c[22]: the start-goods rows' resource types.
  • MapPropertiesState::field_0x1356c is only ever set to 0, never read. invasionTroopIndex is also the selected condition row in the condition dialog. EventConditionParamKind: 0 none, 1 a goods option, 2 an opponent.

gynt's other commits on these functions

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

Function Address His other commits
MenuItemRenderFunction_NewEventCondition_Main 0x004C01B0 1ef2cac (2026-10-27, 72.18%)
MenuItemRenderFunction_NewEventAction_Main 0x004C0860 27bb93a (2026-10-09, 61.82%); 8725ec5 (2026-10-25, "UI-MenuItems average 73.57% -> 75.19%, 55 of 256")
MenuModalRenderFunction_UnusedSetName 0x004266E0 4165153 (2026-10-03, 91.5%); 6987e8c (2026-10-25, "UI-MenuModals average 65.91% -> 73.85%, 5 of 36")
MenuModalRenderFunction_NewEventAction 0x004ABAB0 6054323 (2026-10-03, 91.9%); 6987e8c (2026-10-25, "UI-MenuModals average 65.91% -> 73.85%, 5 of 36")

🤖 Generated with Claude Code

kotijekriv and others added 6 commits November 7, 2026 01:21
The scenario event's all/any switch at +0x08 of the content (+0x18 of the event) is read and written as one word
everywhere in the exe: initializeScenarioEvent sets it with mov word ptr [ecx + 0x18], 1 at 0x004B77B8;
createScenarioEventForNextMonth and createChainedMissionOutcomeEvents clear it with mov word ptr [.. + 0x5C8], 0 at
0x004BDA3A, 0x004BDC16, 0x004BDD06 and 0x004BDDF8; the NewEventCondition handler toggles it with xor word ptr [eax +
0x01653E20], 1 at 0x004B965E; the NewEventCondition render (0x004C01B0) tests it with cmp word ptr [eax +
0x01653E20], 0 at 0x004C0296, and the in-game event check in 0x004C35B0 with cmp word ptr [ebp + 0x5C8], 0 at
0x004C37E7. Nothing touches +0x09 on its own, so the byte pair allOrAnyCondition / magic is one short (0 is "Any of
these", 1 "All of these").

Nothing on main uses either field. gynt's open sourcehold#293 already writes the pair as one word
(*(short*)&...allOrAnyCondition = 0 in createScenarioEventForNextMonth.cpp and three times in
createChainedMissionOutcomeEvents.cpp) and still compiles with the short, where the cast becomes a no-op. The unused
ScenarioEventItem.hpp keeps its old byte pair (and conditions[39]); it is left as it is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_NewEventCondition_Main, rewritten from the binary (gynt's draft from his fork's
reimpl/UI-MenuItems-development, 72.8% in sourcehold#328). The new-event-condition menu: -1 shows the event's month, 104 and
126 pick the button text from the event's all/any switch ("Any of these" / "All of these") and the current condition
("Active" / "Inactive"), 106 to 125 and 190 to 209 are the 40 condition rows (name, option text and value, grey when
off; 209, "Win Timer", first checks whether any of ten conditions is on), 1000 to 2002 are the value boxes of the
current condition, and everything else is a plain scenario button.

The rows go through the condition structs (conditions[slot].enabled / subType / value) and the named tables
(EventConditionMaxValue, EventConditionParamKind, EventConditionValueScale, EventConditionOptionTextOffsets) instead
of the draft's pointer arithmetic and unknown3 offsets. The parameter is button, as in main's other render
functions; enabled and allOrAnyCondition (0/1 only) are tested by truthiness; the literal text numbers and ParamKind
1/2 have comments.

Kept forms: textNumber is copied from button before the 5000 check (copied after the check: quick_diff 0.9440 ->
0.8940); case 2000 comes before 1000 and every box case tests !interacting first, so the box blocks are shared as in
the original (in turn: 0.9109; interacting first: 0.8223); the four box cases stay separate, as the original has
four entry blocks. The month button's x is X + W / 2 (W / 2 + X, as in 2002: reccmp 99.7% -> 99.3%), and it keeps
one call per colour (one call with a colour local: quick_diff 0.9440 -> 0.9237). Case 209's ten condition tests are
written out (a loop over 4 to 7: 0.8543; over 20 to 22: 0.8708). default: is now the last label (a tie).
quick_diff's 0.9440 is all artifacts (colour immediates, ret, jump tables, the tail calls' target).

reccmp reads 99.7%: only the targets of two RenderScenarioButtonWithText tail calls differ (normalized 100.0%).
Needs the allOrAnyCondition header commit before it.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemActionHandler_EditScenario_BaseMenuButtons, rewritten from the binary (gynt's draft from his fork's
reimpl/UI-MenuItems-development, 73.5% in sourcehold#328). The scenario editor's main buttons: 3 goes back to the map's
properties with the typed start year, 38 opens the trader settings, 41 the attacking force (siege map) or the
starting goods, 79 the starting popularity slider, -1 steps the start month, 42 and 43 add a new invasion or event,
168 and 169 the attacking force's gold and partial pitch sliders, 171 the building availability, and 61, 166 and 167
the scenario's gold, rations and taxes (with the extra options on).

Against the draft: no gotos (the shared slider tail and the "not on a siege map" block come from MSVC merging the
identical endings), the new event through scenarioEvents[currentEventID] instead of a pointer local, the attacking
force's text through SEC_SiegeInformation[indexStored - 20] instead of SEC_StartingResources[indexStored + 5] past
the array's end (the same address; the original reloads indexStored after the call), and the text slots by their
TAIT names. Same behaviour. 43 formats the event's year and never uses it, as the original does at 0x004B86E5: a
fixme line says so. The slider titles ("Popularity", "Starting Gold", "Starting Pitch", "Gold") and the attacking
force's rows starting at 20 have comments; each of 41, 42 and 43 has its own text buffer, and 166 no longer has a
return of its own (both ties).

Kept forms: in 168, 169 and 61 textGroup is set before textIndex, so their tail is shared as in the original
(textIndex first: quick_diff 0.9573 -> 0.9197). The new event's subType stores are written out (a for loop over 5 to
7: 0.9001). quick_diff's 0.9573 is all artifacts (the cookie symbol, ret, the jump table).

reccmp reads 98.8%: only the atol call target and the slider callbacks' addresses differ (we push the SumUnitPoints
/ RestoreScenarioGold resolvers' trampolines where the original pushes the functions).

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_NewEventAction_Main, rewritten from the binary (gynt's draft from his fork's
reimpl/UI-MenuItems-development, 62.3% in sourcehold#328). The new-event-action menu: 37 to 40 are scenario buttons (38 to 40
show "Select Message", each only for its message action: Lose & Message 27, Win & Message 26, Message 2, otherwise
hidden through DAT_ButtonUnknownZero); 128 to 155 and 177 to 187 are the action rows for event types 0 to 38: the
current type's row is highlighted with its value (or "%" and the value for 178) and counts down the slider popup,
the others are drawn plain; 146 and 148 show an icon after " - ", and 148 "Archers" is drawn with 146's text,
"Bandits".

It fixes three bugs of the draft: 38 to 40 drew "Select Message" and then hid it (the break led to
DAT_ButtonUnknownZero = 1); 178's highlighted row fell into the plain draw and was hidden; the plain rows with an
icon (146, 148) were hidden after drawing. This version returns where the original does. The parameter is button, as
in main's other render functions.

Kept forms: the row's text is copied from button before selectedButton, the copy the original keeps in the
parameter's stack slot for the value switch at the end (selectedButton first: quick_diff 0.9184 -> 0.9143;
decrementing a copy of the parameter instead: 0.2490). The not-highlighted row has the same draw on both sides of
the hover test (one draw without the test: 0.7731), and iconOffset is declared at the top (at its first use in the
rows' block: 0.8907). quick_diff's 0.9184 is all artifacts (colour immediates, ret, jump tables, the tail calls'
target).

reccmp reads 99.3%: only the targets of three RenderScenarioButtonWithText tail calls differ (normalized 100.0%).

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuModalRenderFunction_UnusedSetName, gynt's code from his fork, branch reimpl/UI-MenuModals-100 (97.9% "asm
differs" there). Unchanged, it measures reccmp 100.0% here, with today's headers, the resolvers on and
--ignore-security-cookie. This commit only restyles it: his reused iVar1 = (width + -400) / 2 becomes int const
margin = (width - 400) / 2 and (x - iVar1) + width becomes x - margin + width; the text's position goes straight
into the call (y + 15, width / 2 + x; a tie with locals); decimal constants, COL_CCFAFF, line comments in place of
the script's block comments, a comment on the 400 pixel title box; the five unused using-declarations and the
BOOLEnum.hpp include are dropped and BGR24.hpp becomes ColorsEnum.hpp. Same generated code (quick_diff and reccmp
unchanged).

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuModalRenderFunction_NewEventAction, gynt's code from his fork, branch reimpl/UI-MenuModals-100 (97.7% "asm
differs" there). Unchanged, it measures reccmp 100.0% here, with today's headers, the resolvers on and
--ignore-security-cookie. This commit only restyles it: his seven decompiler temporaries (xParam, iVar2, TVar3,
BVar4, iVar5, iVar6, BVar7) go, with the constants and both labels' positions passed straight into the calls (a tie
with locals), so the case needs no block; TEXT_SCENARIO for the banner's group; decimal case labels and constants;
COL_CCFAFF; line comments in place of the script's block comments; the four unused using-declarations and the
BOOLEnum.hpp include are dropped and BGR24.hpp becomes ColorsEnum.hpp. Same generated code (quick_diff and reccmp
unchanged).

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

@TheRedDaemon TheRedDaemon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some questions, mostly.

Also regarding the proposed changes:
Are they not certain or full proved? Or do you want to provide them later?
If no to both: If you can figure structures and types out that are related to your functions, you are always free to add these header changes.

Comment thread status/addresses-SHC-3BB0A8C1.txt Resolved
Comment thread status/addresses-SHC-3BB0A8C1.txt Resolved
kotijekriv and others added 6 commits November 7, 2026 03:09
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
IngameScenarioEventItemContent::ScenarioEventType holds 0 to 38. The game names each type by a text of the
scenario group (cr.tex group 199): the new-event-action menu (0x004C0860) draws type t's row with text 128 + t for
0 to 27 and 149 + t for 28 to 38 (rows 128-155 and 177-187, compared with item - 128 against ScenarioEventType),
and the new-event dialog (0x004AB790) prints ScenarioEventType + 128, + 21 above 155. The enum takes its names
from those texts: 0 Win, 1 Lose, 2 Message, ... 26 Win & Message, 27 Lose & Message, 28 Turn Off Repeating
Invasions, 29 Theft from granary, 30 Fire!. Text 138 repeats "Message" for type 10 (SET_MESSAGE_10); types 31 to
38 only have placeholder texts ("Action 32" ..) and are SET_UNKNOWN_31 .. 38. The field stays an int, so nothing
on main compiles differently; the new-event-action menu uses the names for its message types 27, 26 and 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The 40 entries of IngameScenarioEventItemContent::conditions have fixed meanings, and the exe uses the index both
as an array index and in loops: MissionAestheticsDefinedData's EventConditionMaxValue, EventConditionParamKind and
EventConditionValueScale are [40] tables indexed by it, the new-event dialog (0x004AB790) loops over all 40, and
the new-event-condition menu (0x004C01B0) maps its rows 106-125 and 190-209 to conditions 0 to 39. So an enum for
the index fits, not a struct. The names are the texts the game shows for them (cr.tex group 199, text 106 + i for
0 to 19 and 170 + i for 20 to 39): 0 Auto-Stop, 1 Population, ... 22 Maximum Cruelty, 23 Maximum Pleasantness, 39
Win Timer. Text 123 repeats "Weapons Acquired" for 17 (SECI_WEAPONS_ACQUIRED_17); 24 to 38 only have placeholder
texts ("Event Condition 24" ..) and are SECI_UNKNOWN_24 .. 38. Nothing on main uses the conditions array by a
literal index.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MapPropertiesState::flag (+0x13578) only ever holds 0 or 1: the exe's only store is the 1 in the scenario editor's
new-event button (mov dword ptr [..+0x13578], 1 at 0x004B86CA in 0x004B8220), and its three readers test it
against 0 (0x004BA57E, 0x004BFE3F, 0x004BFF1D). BOOLEnum is a typedef of int, so the size and every access stay
the same. No function on main uses the field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oid() callback

setSliderParameters (0x004AA480) stores its destination into MenuModalComposition::destination, which the header
already types int* (mov [ecx + 0x58], eax at 0x004AA512), and its callback into sliderCallbackFunction. Every
caller in the exe passes the address of an int (MapPropertiesState::SEC_StartingPopularity,
SEC_StartingResources[...], DAT_CopyOfScenarioGold) and a no-argument __cdecl function (Helpers::SumUnitPoints
0x004B8200, Helpers::RestoreScenarioGold 0x004B8210). The signature becomes (int minimum, int maximum, int value,
int* destination, void(__cdecl* callbackFunction)()), here and in its resolver, and the scenario editor's four
calls lose their (undefined*) / (void*) casts. Main has no other caller; the drafts in sourcehold#327 and batch4-development
that call it with the old casts will need the same edit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TheRedDaemon's review of sourcehold#354: the proven proposals become header changes (the commits before this one), and the
functions use them. NewEventCondition_Main and NewEventAction_Main name the conditions by
ScenarioEventConditionIndex and the event types by ScenarioEventType; BaseMenuButtons passes the slider
destinations as int* and its callbacks without casts (setSliderParameters takes int* and void(__cdecl*)()),
and stores TRUE in MapPropertiesState::flag. Same generated code: reccmp as before (99.7 / 98.8 / 99.3).

The status remarks now say when the differences show: with the RenderScenarioButtonWithText (0x004BA910),
SumUnitPoints (0x004B8200) and RestoreScenarioGold (0x004B8210) resolvers on, NewEventCondition_Main and
NewEventAction_Main read 100.0% raw, and BaseMenuButtons 99.5% raw, where only its three atol calls differ (our
CRT's atol against the game's copy).

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

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Most of the proposals were proven; I had kept them out only to keep the PR to the functions. They're in now, each in a header commit of its own with its evidence, and the functions use them:

  • ScenarioEventType, an enum for the 39 event types (6ad389d);
  • ScenarioEventConditionIndex, an enum for the 40 condition indexes (ce5a036);
  • MapPropertiesState::flag as a BOOLEnum: its only store in the exe is 1, and every reader compares it with 0 (a51fffd);
  • MenuModalComposition::setSliderParameters(int, int, int, int* destination, void(__cdecl*)()): every destination is an int and every callback a void(), so the eight casts are gone (7e208ed; nothing on main calls it).

Left as proposals: the two field names (field_0x170's opponent texts and field_0x345c's goods order), since names are on the Ghidra side, and our next MenuModals PR also uses field_0x170. I'll do the same in our other open PRs: proven types go in as header commits, and only names and unproven guesses stay in the list. Answers to your questions are in the threads. 3b921b7..014186a merges main and adds the header commits and one commit moving three functions to the new names. Same generated code; the checker is clean.

Comment thread src/OpenSHC/UI/MenuModalComposition.hpp Resolved
TheRedDaemon
TheRedDaemon previously approved these changes Nov 7, 2026

@TheRedDaemon TheRedDaemon left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is fine from my side, but consider the question of gynt.

kotijekriv and others added 8 commits November 7, 2026 19:58
…ack*

7e208ed typed its callback void(__cdecl*)(); main already has that type as Util::FunctionTypes::NoArgCallback, so
the parameter uses it, here and in the resolver. It is not a SliderActionHandler (void(int, int, int*, int*,
int*)). The modal stores the callback in sliderCallbackFunction (+0x60), and the exe reads that field in three
functions only (five reads), each right after activateModalDialog(MMT_NONE, FALSE), and calls it with no arguments:
call eax with nothing pushed for it and no add esp after at 0x004B0F90 and 0x004B0FF2
(MenuItemActionHandler_OverlaySlider_Deselect, 0x004B0F70) and at 0x004B1020 and 0x004B1082
(MenuItemActionHandler_UnusedWinCondition_DeselectUnk, 0x004B1000), and a tail jmp eax at 0x004B10C0
(MenuItemActionHandler_UnusedWinCondition_Options, 0x004B1090, on main, which calls it as (void (*)())). The
overlay slider's own SliderActionHandler is MenuItemActionHandler_OverlaySlider_Slider (0x004AA600, the MIT_SLIDER
item at 0x005ED588); it writes the value through destination and destination2 and never reads +0x60.
OverlaySlider_Deselect is the handler of the item before it (0x005ED538).

7e208ed named only the scenario editor's two callbacks. The exe calls setSliderParameters 14 times, from
MenuItemActionHandler_General_AdvancedGameOptions (0x00429A40, four calls),
MenuItemActionHandler_EditScenario_BaseMenuButtons (0x004B8220, four), MenuItemActionHandler_NewInvasion_UnitButtons
(0x004B9110), MenuItemActionHandler_NewEventAction_Main (0x004B9C00),
MenuItemActionHandler_SiegeAttackingForceAndStartGoods_Main (0x004BA5C0, three) and
MenuItemActionHandler_TriggerInvasion_Main (0x004BBD90), and passes six different callbacks. All six read no stack
argument and end in a plain ret, and main's resolvers already declare each void(__cdecl*)():
Synchrony::Commands::QueueChangeGameIntensityOrBalance (0x00429630, three calls),
UI::Helpers::CallbackSetMultiplayerSpeedLevel (0x00429650, one), Global::DoNothing (0x00469F10, two),
UI::Helpers::SumUnitPoints (0x004B8200, six; a tail jmp to a thiscall at 0x004B7FA0 that reads only ecx),
UI::Helpers::RestoreScenarioGold (0x004B8210, one) and UI::Helpers::CaptureCurrentTimeToUnknownTime01 (0x004B9610,
one). The two sibling setters are called once each, with two of the same callbacks: setSliderParameters2
(0x004B9762) with CaptureCurrentTimeToUnknownTime01 and setModalSliderParameters (0x00429C48) with
QueueChangeGameIntensityOrBalance.

The callers compile unchanged. The header commits of this series don't build on their own; measured in one alone
build with all of them and the commit that updates the users (the last one before the merge of main):
setSliderParameters2 (0x004AA540) and MenuItemActionHandler_UnusedWinCondition_Options (0x004B1090) read reccmp
100.0%, and MenuItemActionHandler_EditScenario_BaseMenuButtons (0x004B8220) reads 98.8% raw, as before (only the
atol call and the callback trampolines differ, so it stays recorded at 100%).

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

Its callbackFunction was undefined*. setSliderParameters2 (0x004AA540) stores it in sliderCallbackFunction (mov
[ecx + 0x60], edx at 0x004AA5F0), which the exe calls with no arguments (see the commit before), and its one
caller, MenuItemActionHandler_NewEventCondition_Main (call at 0x004B9762), passes
UI::Helpers::CaptureCurrentTimeToUnknownTime01 (0x004B9610), a void(__cdecl*)() in main's resolver. So the
parameter becomes a NoArgCallback*, here and in the resolver. This commit is header-only, as AGENTS.md asks:
main's setSliderParameters2.cpp takes the new type in its own signature in the last commit of this series, and the
build needs that commit; it then reads reccmp 100.0%. Main has no caller; the 0x004B9620 draft on
reimpl/UI-MenuItems-3-development-2 casts its argument to undefined* and will need the cast dropped.

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

destination was a dword. setSliderParameters2 (0x004AA540) stores it in destination2 (mov [ecx + 0x5c], eax at
0x004AA5D2) and clears destination. destination2 is a short*, and the overlay slider's handler (0x004AA600) writes
through it with word stores only (mov word ptr [edx], cx at 0x004AA71C, [ecx], dx at 0x004AA736 and [ecx], ax at
0x004AA762), where it writes through destination with dword stores. The one caller,
MenuItemActionHandler_NewEventCondition_Main (call at 0x004B9762), passes the address of a short: it pushes lea
eax, [eax*4 + 0x1653e24] as destination and, as value, what it reads from there with movsx eax, word ptr [eax]. So
the parameter becomes a short*, here and in the resolver, and setSliderParameters2.cpp's (short*) cast goes in the
commit that updates the users. Main has no caller; the 0x004B9620 draft on reimpl/UI-MenuItems-3-development-2
already holds it in a short* local and can drop its (dword) cast.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er is a NoArgCallback*

param_6 was undefined*. setModalSliderParameters (0x004AA930) stores it in sliderCallbackFunction (mov edx, [esp +
0x18]; mov [ecx + 0x60], edx at 0x004AA956 and 0x004AA964), which the exe calls with no arguments, and its one
caller, MenuItemActionHandler_General_AdvancedGameOptions (call at 0x00429C48, on DAT_MenuModalComposition1),
passes Synchrony::Commands::QueueChangeGameIntensityOrBalance (0x00429630), a void(__cdecl*)() in main's resolver.
So param_6 becomes a NoArgCallback*, here and in the resolver; the name stays Ghidra's. Main has no implementation
or caller. gynt's 100% setModalSliderParameters on origin/reimpl/UI-Core (e31bef6, sourcehold#256) defines it with
undefined* param_5, undefined* param_6, so his definition will need NoArgCallback* param_6 (and int* param_5, the
next commit) to match this declaration (C2511 otherwise), as setSliderParameters2.cpp does in the last commit here.

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

param_5 was undefined*. setModalSliderParameters (0x004AA930) stores it in destination (mov edx, [esp + 0x14]; mov
[ecx + 0x58], edx at 0x004AA94F and 0x004AA953), and param_4 in sliderValue. destination is an int*, and the
overlay slider's handler (0x004AA600) writes through it with dword stores only (mov [edx], ecx at 0x004AA6E3,
[ecx], edx at 0x004AA6F8 and [esi], eax at 0x004AA755). The one caller,
MenuItemActionHandler_General_AdvancedGameOptions (call at 0x00429C48), passes 0x01A24658 as param_5 and, as
param_4, the dword it reads from there (mov eax, [0x1a24658]). So param_5 becomes an int*, here and in the
resolver; the name stays Ghidra's. Main has no implementation or caller. gynt's e31bef6 stores it as
this->destination = (int*)param_5; with this commit and the one before, his definition changes once for both
parameters, and the cast can go.

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

It was pointer (void*). The exe writes it only in the three setters (mov [ecx + 0x60], edx at 0x004AA530 in
setSliderParameters, 0x004AA5F0 in setSliderParameters2, 0x004AA964 in setModalSliderParameters), whose callback
parameters are NoArgCallback* since the commits before, and reads it only at 0x004B0F87, 0x004B0FE9, 0x004B1017,
0x004B1079 and 0x004B10B7, each a NULL test and then a call or tail jump with no arguments (see the first commit of
this series). There is no other access to either instance's +0x60 (absolute 0x01FE7CF0 for
DAT_MenuModalComposition1, 0x024036D8 for DAT_MenuModalComposition2).

In the next commit main's setSliderParameters2.cpp takes the typed parameters in its signature and
MenuItemActionHandler_UnusedWinCondition_Options drops its (void (*)()) cast. Measured with the commits before and
the next one, in one alone build: setSliderParameters2 (0x004AA540) and
MenuItemActionHandler_UnusedWinCondition_Options (0x004B1090) read reccmp 100.0%, and
MenuItemActionHandler_EditScenario_BaseMenuButtons (0x004B8220) reads 98.8% raw, as before (only the atol call and
the callback trampolines differ, so it stays recorded at 100%). gynt's OverlaySlider_Deselect (a2803eb, 100%, on
his fork's reimpl/UI-MenuItems-development) compares the field with (undefined*)0x0, which will need to become
NULL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ions use the typed parameters

setSliderParameters2 (0x004AA540) takes short* destination and NoArgCallback* callbackFunction in its definition,
as the header has since the commits before; the header commits are header-only, so this one makes the branch build
again. destination goes into destination2 without its (short*) cast.
MenuItemActionHandler_UnusedWinCondition_Options (0x004B1090) calls sliderCallbackFunction, a NoArgCallback* since
the commit before, without its (void (*)()) cast; its first include is the relative ../Unused.func.hpp, as the
checker asks of a touched file, and the unused using lines for MenuModalType and BOOLEnum go with the BOOLEnum.hpp
include (MMT_NONE is written out in full and FALSE is the Windows macro). quick_diff unchanged; reccmp 100.0% for
both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kotijekriv and others added 2 commits November 7, 2026 23:37
e32319b adds this branch's ScenarioEventConditionIndex.hpp and ScenarioEventType.hpp: the same enums, without
our two comment lines; both add/add conflicts resolved to main's version. Its scenarioEventType rename is in
ScenarioEventItem, not in IngameScenarioEventItemContent, whose ScenarioEventType this branch reads, so no file
changes. MenuModalComposition's NoArgCallback* and int* / short* parameter types are not in main yet and stay in
this branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gynt on sourcehold#354: the cases of MenuModalRenderFunction_NewEventAction's switch over the event's ScenarioEventType were
numbers. They are now SET_TRAVELING_FAIR, SET_PLAGUE ... SET_ARCHERS, SET_THEFT_FROM_GRANARY and SET_FIRE (5,
11-20, 29, 30). The other switches in this branch are over button numbers (TEXT_SCENARIO text numbers, no enum
yet) and stay numbers; its comparisons with an event type or a condition index already use the names. Codegen
unchanged: quick_diff 0.9107 before and after, reccmp 100.0%.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kotijekriv added a commit to kotijekriv/OpenSHC that referenced this pull request Nov 7, 2026
gynt on sourcehold#354 asked why a switch used numbers where an enum has names. The NewMapMapsize, UnusedChooseAvailableKeeps
and UnusedChooseGameType DoEveryFrame switches now name 160, 200 and 300 as MC_MAP_SIZE_160, _200 and _300, and the
default size 400 as MC_MAP_SIZE_400, as main's checkKeepEnclosed does. 100 has no name in MapConstants and stays a
number. quick_diff gives all three the same 0.9760 as before (only the cookie, the colour immediate, the jump table's
labels and ret / ret 0 differ). No other numeric case or comparison in this branch has an enum: missionNumber1to20
(1000, 1) and section1066 (2) are plain ints.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kotijekriv added a commit to kotijekriv/OpenSHC that referenced this pull request Nov 7, 2026
…Index values

As gynt asked on sourcehold#354, cases over a value that has an enum use its names. The objective loops run over the scenario
conditions 0 to 38 and draw the win timer (39) apart: conditions 18 and 19 (4 cattle farms, 2 inns) are skipped in
the builder mode, 17 shares 6's text and 15 shares 8's, and the cases with a number column are population, gold
and the percent / maximum conditions 20 to 23. So the 32 case labels, the loop bounds, the comparisons and the
indexes into INT_ARRAY_00ed2630 and conditions[] now use the SECI_ names (main's ScenarioEventConditionIndex,
e32319b). Codegen unchanged: quick_diff 0.5846 before and after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3a1c7f7 takes this branch's MenuModalComposition changes but two: sliderCallbackFunction and every callback
parameter are NoArgCallback*, and setModalSliderParameters takes int* param_5, as here, while setSliderParameters
keeps undefined* destination and setSliderParameters2 dword destination (int* and short* here). Both headers are
resolved to main's version, so the branch changes no header. setSliderParameters2.cpp follows main's types (dword
destination, stored through (short*) as main's file does; NoArgCallback* callback), and BaseMenuButtons passes its
four slider destinations as undefined*. reccmp unchanged: setSliderParameters2 100.0%, BaseMenuButtons 98.8%
(only the atol call target and the two callbacks differ while their resolvers are off).

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 03827fa Nov 8, 2026
4 checks passed
6and8 pushed a commit to 6and8/OpenSHC that referenced this pull request Nov 8, 2026
* headers: DAT_00b95954 is a BOOLEnum

Every store is 0 or 1: 0x004254C0 stores ebx, zeroed at 0x004254B6, and 0x004E1F08 stores ecx, set to 1 in
Unknown26_CampaignRelatedUnk_DoEveryFrame. Every read compares it with 0 or 1: cmp .., 0 three times, cmp .., 1 twice
(at 0x0046B806 among them) and 0x004261E4 against a zeroed edi. The type changes from undefined4 to BOOLEnum, with the
include and using as in main's BOOLEnum_00ed279c. Ghidra would name it BOOLEnum_00b95954; the name stays, so that the
sync can rename it together with its users. Its users compile to the same code before and after: main's
playDarMehqOrGlory and switchToMenuView are 100.0% raw and normalized in clean alone builds of this branch without and
with this commit, which compare equal over all 1827 functions; this branch's Unknown26_CampaignRelatedUnk_DoEveryFrame
and Credits_Prepare in the MenuViews draft measure the same in quick_diff.

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

* headers: GameCore.descriptionUseStringTable and mapLoadedForEditor are BOOLEnums

descriptionUseStringTable (0x01FE8678) is stored 0 at 0x0042EE75 and 0x0042FA76, 1 at 0x00474EE6, and from registers
holding 0 or 1 at 0x0042F0C1 (ebx, zeroed at 0x0042F012), 0x00474ECA (ebx, zeroed at 0x00474E62) and 0x00448922 (ebp,
set to 1 at 0x004485F0); readMapOrSavFile also reads it from the map file. mapLoadedForEditor (0x01FE9AA8) is stored 1
at 0x004300C9, 0x00430614 and 0x00494610, and from esi (zeroed at 0x00425EA1) at 0x00425F1D and edi (set to 1 at
0x0042F989) at 0x0042FA96. Every read of either compares it with 0 or with a register, and the registers checked hold 0
(ecx at 0x0042E940, and esi at 0x0042E05B and 0x0042E06F, where this branch's MapEditorProperties_Prepare matches with
truth tests). Both change from dword to BOOLEnum. All their users compile to the same code before and after (quick_diff,
same ratio and length each): main's switchToMenuView, readMapOrSavFile, writeMapOrSaveFile, InitializeBasicMap,
MenuItemRenderFunction_MapEditorProperties_MainButtons, MenuItemActionHandler_SaveLoadMap_Buttons,
MenuItemActionHandler_UnusedChooseAvailableKeeps_Main and _UnusedChooseGameType_Main, and this branch's
MapEditorProperties_Prepare and Unknown26_CampaignRelatedUnk_DoEveryFrame. The names stay.

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

* reimplement: SHC_3BB0A8C1_0x0042DFD0 100.0% Reimplemented

MenuView_MapEditorProperties_Prepare opens the map editor's properties view: it closes the third modal, resets the text
input, loads frontend_builder2.tgx, in a multiplayer map counts the players with a first building and clears every
player's and the map's start goods, and measures the height of the map's description. From gynt's 46f3f38 on his
fork's reimpl/UI-MenuViews-development (85.71% there, "Shared call duplicated"), first written in 24305ee and
8f42b3d (59.5%): the function's reads and stores, the per-arm renderMultilineTextUnk calls and the positive
descriptionStringTableIndex test are his. Changed here: the two pointer loops become index loops over players 1 to 8 and
the 25 start goods (with the draft's walking pointers MSVC addresses the start resources from an offset register:
quick_diff 1.0000 -> 0.9429); the building test reads playerDataArray[player].buildingEntryInfos[0].id, the field the
draft reached through a cast 0x3D8 bytes before startResources; main's INT_00b95b74 for DAT_00b95b74 and
TAIT_NINE__FILTER_B for 9; COL_000000 for the black colour; truth tests on mapLoadedForEditor and
descriptionUseStringTable, BOOLEnums since the header commit before this one; 0x13 and 0x168 are 19 and 360; the (int)
cast on descriptionStringTableIndex, piVar2 to piVar4, five using lines and three unused includes go; main's namespace
form; the file name's s_ pointer with its text above it; comments say what the loops and the height are. This file was
measured as it stands in a clean alone build of the branch on main eef6f66: 100.0% raw, 100.0% normalized.

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

* reimplement: SHC_3BB0A8C1_0x0042F3F0 100.0% Reimplemented

MenuView_NewMapMapsize_DoEveryFrame draws the screen's title, "Select New Map Size" (TEXT_MAPEDIT 20), and a minimap
preview of the map at its size, framed twice in black, with the size as text above its top right corner. Written from
the original's instructions, with gynt's draft (3a10a44 on his fork's reimpl/UI-MenuViews-development, 83.46% there;
earlier 35d66b7 at 64.5% and 4cfdc42 at 62.32%) for the reads: the two switches, the first the original's jump table
and the second its sub / je chain with default first, are his. His goto from default into case 200 goes, as both arms
written out are merged by MSVC as in the original. Two forms are kept for the register allocation, each with a one-line
comment: the title's position in two locals, y first (inline: quick_diff 0.9760 -> 0.7200, x first: 0.9600), and the
label's x in its own local (x += previewSize: 0.8617). Also: main's namespace form, as in the sibling Prepare;
s__dx_d_005a22fc for "%dx%d" with its text above it; COL_C2F0EB, COL_000000 and TTA_RIGHT for 0xc2f0eb, 0 and -1;
needsRedraw = TRUE; decimals for 0x1e, 0x32, 0x3b, 0x122 and the frame offsets; the casts on the frame colour go; the
draft's eleven decompiler locals become x, y, centerX, centerY, mapSize, previewSize, sizeText, titleX, titleY and
labelX; comments say what is drawn, that x and y become the preview's top left corner and that a 100 map gets the
default 200 frame. quick_diff 0.9760 leaves the security cookie, the colour immediate, the jump table's labels and ret /
ret 0. This file was measured as it stands in a clean alone build of the branch on main eef6f66: 100.0% raw, 100.0%
normalized.

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

* reimplement: SHC_3BB0A8C1_0x0042FAC0 100.0% Reimplemented

MenuView_UnusedChooseAvailableKeeps_DoEveryFrame draws the screen's title, "Select Keep Types" (TEXT_MAPEDIT 21), and a
minimap preview of the map at its size, framed twice in black, with the size as text above its top right corner. The
body is the one of NewMapMapsize's 0x0042F3F0 with its own title, and the original's instructions are the same but for
that text index. Written from the original's instructions, with gynt's draft (96f71d9 on his fork's
reimpl/UI-MenuViews-development, 83.46% there; earlier 69751c0 at 64.5% and cef13ed at 62.32%) for the reads: the
two switches, the first the original's jump table and the second its sub / je chain with default first, are his. His
goto from default into case 200 goes, as both arms written out are merged by MSVC as in the original. Two forms are kept
for the register allocation, each with a one-line comment: the title's position in two locals, y first (inline:
quick_diff 0.9760 -> 0.7200, x first: 0.9600), and the label's x in its own local (x += previewSize: 0.8617). Also:
main's namespace form, as in the sibling Prepare; s__dx_d_005a22fc for "%dx%d" with its text above it; COL_C2F0EB,
COL_000000 and TTA_RIGHT for 0xc2f0eb, 0 and -1; needsRedraw = TRUE; decimals for 0x1e, 0x32, 0x3b, 0x122 and the frame
offsets; the casts on the frame colour go; the draft's eleven decompiler locals become x, y, centerX, centerY, mapSize,
previewSize, sizeText, titleX, titleY and labelX; comments say what is drawn, that x and y become the preview's top left
corner and that a 100 map gets the default 200 frame. quick_diff 0.9760 leaves the security cookie, the colour
immediate, the jump table's labels and ret / ret 0. This file was measured as it stands in a clean alone build of the
branch on main eef6f66: 100.0% raw, 100.0% normalized.

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

* reimplement: SHC_3BB0A8C1_0x00430150 100.0% Reimplemented

MenuView_UnusedChooseGameType_DoEveryFrame draws the screen's title, "Select Game Type" (TEXT_MAPEDIT 27), and a minimap
preview of the map at its size, framed twice in black, with the size as text above its top right corner. The body is the
one of NewMapMapsize's 0x0042F3F0 with its own title, and the original's instructions are the same but for that text
index. Written from the original's instructions, with gynt's draft (7425729 on his fork's
reimpl/UI-MenuViews-development, 83.46% there; earlier 431d154 at 64.5% and 27bdc15 at 63.19%) for the reads: the
two switches, the first the original's jump table and the second its sub / je chain with default first, are his. His
goto from default into case 200 goes, as both arms written out are merged by MSVC as in the original. Two forms are kept
for the register allocation, each with a one-line comment: the title's position in two locals, y first (inline:
quick_diff 0.9760 -> 0.7200, x first: 0.9600), and the label's x in its own local (x += previewSize: 0.8617). Also:
main's namespace form, as in the sibling Prepare; s__dx_d_005a22fc for "%dx%d" with its text above it; COL_C2F0EB,
COL_000000 and TTA_RIGHT for 0xc2f0eb, 0 and -1; needsRedraw = TRUE; decimals for 0x1e, 0x32, 0x3b, 0x122 and the frame
offsets; the casts on the frame colour go; the draft's eleven decompiler locals become x, y, centerX, centerY, mapSize,
previewSize, sizeText, titleX, titleY and labelX; comments say what is drawn, that x and y become the preview's top left
corner and that a 100 map gets the default 200 frame. quick_diff 0.9760 leaves the security cookie, the colour
immediate, the jump table's labels and ret / ret 0. This file was measured as it stands in a clean alone build of the
branch on main eef6f66: 100.0% raw, 100.0% normalized.

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

* reimplement: SHC_3BB0A8C1_0x004D8CB0 100.0% Reimplemented

MenuView_CrusadeMap_Prepare loads the trail's map picture, keeps each trail's progress within its missions, and counts
into DAT_SkirmishTrailRelated1 three less one for each of the current trail's missions so far that was skipped with the
chicken, not below 0. From gynt's ba34388 on his fork's reimpl/UI-MenuViews-development (82.46% there, "Dropped goto
restored in trail-type chain"), first written in 75c2542 and 387ad88 (65.9%): the function's reads and stores, the
three chicken counts and the trail-type chain are his. Changed here: each count becomes a for loop up to the trail's
furthest mission, read once into a const local, behind a test of it, with the counter set before the test and the clamp
to 0 inside it: the draft's guard `< 1` compiled to cmp 1 / jl where the original tests the zero register with jle
(written `> 0` now), and the original skips the clamp when nothing was counted (quick_diff 0.8686 -> 0.9708). Two shapes
stay, each with a one-line comment: the counter outside the for (declared in it, each loop gets a second guard, 91
instructions against the original's 86: quick_diff 0.9379) and a totalLoadedGfx store in each arm (one store after
picking the file name, as the original's one store at 0x004D8CE1: 0.9123). Also: 0x31, 0x1d, 0x13 and -0x4b0 are 49, 29,
19 and -1200; the (int) casts on the progress fields and on DAT_SkirmishTrailRelated1, which are int, go; INT_00ed2bdc =
FALSE, as main's CrusadeMapAndEndscreen writes it; `+ -1` is a decrement; iVar1 is mission and the furthest mission
furthestMission; main's namespace form; the unused using goes; a fixme says the original clamps the warchest progress
when the extreme one passes 19 (the store at 0x004D8D22), which the code keeps; the s_ pointers with their text above
them. quick_diff 0.9708 leaves the timeGetTime import call, ret / ret 0 and the alignment jump the original has before
its third loop. This file was measured as it stands in a clean alone build of the branch on main eef6f66: 100.0% raw,
100.0% normalized.

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

* reimplement: SHC_3BB0A8C1_0x004DC9E0 100.0% Reimplemented

MenuView_GameLost_DoEveryFrame keeps the game-lost screen up until it may leave: in skirmish and multiplayer, behind the
greatest-lord screen, only once BOOLEnum_00ed279c is set (0x004DCA4A to 0x004DCA63); otherwise also once draggingStopped
is set, which it sets itself when no video plays, or in a campaign mission 5 seconds after the first frame that gets
there. Then it ends both speech streams (SoundSystem::endSpeechStreamsAndResetLoopFlags, 0x00424700, inlined), stops the
videos and goes back to the menu the game came from. Written from the original's instructions, with gynt's draft
(9df20a9 on his fork's reimpl/UI-MenuViews-development, 65.81% there; earlier 29597e4 and 5ddb422 at 33.9%) for
the reads: its returning arms, the extreme / warchest / skirmish order and the inverted MT_ECONOMIC test are his.
Changed: one skipStoreSKMasters = 0 at the end in place of a store and a return in each arm, which MSVC copies into the
arms itself; with a store in each arm it keeps 0 in ebx all through the function (quick_diff 0.9221 -> 0.6937); the
video test before the greatest-lord screen, as the original's jumps run (the other way round: 0.9026); the goto past the
leave test is a timedOut flag (the goto measures the same); the builder's map type a switch, as the original's sub / je
(if / else: 0.9121); truth tests on the BOOLEnums and on skipStoreSKMasters, except isSkirmishTrail == TRUE, which the
original compares with 1. Also: main's namespace form; main's BOOLEnum_00ed279c for INT_00ed279c; the speech streams'
flags indexed by SND_STR_SPEECH_1 and _2; NULL for (HBINK)0x0; 0x51, 0x33 and 0x16 are 81, 51 and 22; comments for the
SKMasters slots, SelectCrusade_Main's argument, the "Quit Mission" action and the inlined call. quick_diff 0.9221 leaves
the timeGetTime import calls and ret / ret 0. This file was measured as it stands in a clean alone build of the branch
on main eef6f66: 100.0% raw, 100.0% normalized.

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

* reimplement: SHC_3BB0A8C1_0x004E1E70 100.0% Reimplemented

MenuView_Unknown26_CampaignRelatedUnk_DoEveryFrame plays the sequence its Prepare built with BuildIntroLogoSequence
(credits-script elements and videos) frame by frame and, once it is over, switches to the next view. From gynt's
f4756df on his fork's reimpl/UI-MenuViews-development (titled 100.00%): returning after every switchToMenuView and
testing missions past 21 first are his; his d40842f on top of it only added (int) casts, and only his earlier
288b1cd, 0ef5f8b, faaf06c and 43d1ef1 went on after the switch. Changed here: early returns in place of his
nesting, no iVar1, no casts (the bink counters are int), 21 for 0x15, ++ for the + 1, TRUE for DAT_00b95954 (a BOOLEnum
since this branch's first header commit), main's namespace form, and comments: mission 1000 is the intro sequence, and
DAT_00b95954 makes switchToMenuView play the end credits' music. quick_diff 0.9057 leaves ret / ret 0. This file was
measured as it stands in a clean alone build of the branch on main eef6f66: 100.0% raw, 100.0% normalized.

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

* style: the twins' map sizes by their MapConstants names

gynt on sourcehold#354 asked why a switch used numbers where an enum has names. The NewMapMapsize, UnusedChooseAvailableKeeps
and UnusedChooseGameType DoEveryFrame switches now name 160, 200 and 300 as MC_MAP_SIZE_160, _200 and _300, and the
default size 400 as MC_MAP_SIZE_400, as main's checkKeepEnclosed does. 100 has no name in MapConstants and stays a
number. quick_diff gives all three the same 0.9760 as before (only the cookie, the colour immediate, the jump table's
labels and ret / ret 0 differ). No other numeric case or comparison in this branch has an enum: missionNumber1to20
(1000, 1) and section1066 (2) are plain ints.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Gynt <gynt@users.noreply.github.com>
kotijekriv added a commit to kotijekriv/OpenSHC that referenced this pull request Nov 9, 2026
gynt asked on sourcehold#354 why the case labels do not use the enum names. In this draft the switched value
has an enum on main in one place: MenuItemActionHandler_General_EventSlider's two switches on the current event's
ScenarioEventType now name their 13 cases (SET_TRAVELING_FAIR, SET_PLAGUE ... SET_THEFT_FROM_GRANARY, SET_FIRE), and
MenuItemActionHandler_NewEventAction_Main's test of the new type compares with SET_MESSAGE, SET_WIN_AND_MESSAGE and
SET_LOSE_AND_MESSAGE. The other switches here are on button numbers, slider steps and fields with no enum
(activeTacticalPower, unitControlsRelated, TextEditorState.field_0x23970), so they keep their numbers. The code is
unchanged: quick_diff gives the same output for both files before and after.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kotijekriv added a commit to kotijekriv/OpenSHC that referenced this pull request Nov 9, 2026
gynt asked on sourcehold#354 why the case labels do not use the enum names. Where the switched value has an
enum on main this draft now uses it: MenuItemRenderFunction_LobbyMenu_PlayerListAndNpcButtons's switch on a player's
currentAIArray entry names its ten cases by AITypeA (the European lords, AITA_RAT ... AITA_ABBOT), and
MenuItemActionHandler_Roundtable_Main's two tests of it compare with AITA_RAT and AITA_SULTAN (the genie's "Not the
rodent" line is the rat's); MenuItemRenderFunction_VideoOptions_Main's switch on menuCurrentlySelectedResolution names
its 15 cases by ScreenResolutionEnum, each matching the text it draws (SRE_800x600 ... SRE_1024x600). The other
switches here are on button numbers, GM picture indices, key codes and fields with no enum, so they keep their numbers.
The code is unchanged: quick_diff gives the same output for all three files before and after.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants