Repository navigation
UI: the single-player game launch at 100% - #466
Merged
TheRedDaemon merged 3 commits intoNov 22, 2026
Merged
Conversation
Actions::LaunchSinglePlayerGameUnk starts a single-player game on a map: it loads the map picked in the map choice (or, called with 1, the map whose name standaloneFilename already holds), sets what can be made and recruited, applies the mission type's rules and opens the first menu view. For a siege that is the map's siege engines as an attack wave scaled by the difficulty, the attacker's troops (the ones picked in the map choice in the advanced mode, otherwise 70% of the map's for a player in slot 2) and no peasants; for an invasion on difficulty 1 to 3 (from the map choice always 1: its start button sets it), on a map for which mapHasCertainEvent says no, it takes every fourth, third or second of the player's own units away until a quarter, a third or half of their troop value is gone. 663 instructions, written from the original's listing. The fields it uses come from gynt's draft, under main's names today. The draft goes back to ce7ebb0 (2026-10-02, "reimplement: SHC_3BB0A8C1_0x0042C620 25.26% Style pass, asm differs"). Its best score, 28.35%, is ca39d7b (2026-10-03, the same subject), where he merged the draft's split name buffer (`char local_7e0[4]` and a `local_7dc[1004]` that nothing used) into one of 1008 bytes; his 409e2a3 ("Split buffer merged", on sourcehold's own reimpl/UI-Core) makes the same change and says why. The newest version is 15e5712 (2026-11-02, "style: rule 12, import 76 string literals across UI/Rendering and Helpers") on his fork's reimpl/UI-MenuItems-development, whose status line reads "28.4% | Style pass, asm differs". reimpl/UI-Core-development has it at 27.1% (10280b1) and reimpl/UI-Core (sourcehold#256) at 26.3% (2f1c52c); both still have the 4-byte name buffer. That draft does not compile on today's main: DAT_SiegeInformationArray is `int[7][3]` now, and two SiegeUnitCounts fields, Building's tower engine field and PlayerData's keep entry have other names. No behaviour change against the draft: read block by block, both do the same. One thing a literal port would get wrong: the draft reads the picked map from DAT_ArrayOfMapIndices[scroll offset + selection - 1], which was right for the header of its day (the array started one entry later); on main the array starts where the original reads it, so the index has no `- 1`. gynt's own newer export (8ca7861 on reimpl/Wilps-2026-10-18) has it without the `- 1` too. What the match needed, each measured against its alternative: - The two name buffers are char[1005] and char[1001] (the frame's size, as gynt found in 409e2a3). - The first six "can be made" stores in the order crossbow, pike, sword, bow, spear, mace; in ascending order two of the stores move. - The picked map's index as selection + scroll offset; the other way round swaps the two loads. - The nine recruitable flags cleared in front of the loop that copies the fourteen recruitable values. Behind it the loop takes the register that holds the function's zero, and the zero is no longer in a register from the first test of the argument on. - The siege numbers are zeroed by their own `if (type != siege)` in front of the siege's peasant loop. As the else arm of that loop's test, the three blocks before it stay in the written order; the original has them behind the keep's part of the function. - The twenty siege troop counts are walked as an array in all three places (copy, 70%, zero). The header has twenty named fields; twenty written zero stores take the function's zero register where the original makes a new one. - In the invasion block the unit counter is declared in front of the value total; the other way round the two are set to zero in the other order. - The last menu call written in each arm; one call with a `? :` argument computes the number without a jump. - The argument is compared with 1 at the end, as in the original; a truth test compares with zero. The mission types (0 just build, 1 economic, 2 siege, 3 invasion) are plain numbers with a comment, as in main's other files: DAT_MapMissionType has no enum, and a file-local one changes two registers of the second map name call (declared alone, without a single use). Measured in a narrow build on main 3458fea of this file alone (main is now 812d149: sourcehold#399 and sourcehold#398 add only the optional function-visibility units, off by default), struct resolvers and its resolver on: 100.0% raw and normalised, no diff entry. Not run in game. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
TheRedDaemon
requested changes
Nov 22, 2026
Review: the six "can be made" settings (MapPropertiesState's SEC_*Producible_save shorts and GameCore's *Producible_logic ints) and the nine euroRecruitableCopy_* flags are only ever 0 or 1 in the original: every store is a 1 or a 0, a toggle with `xor 1` (the map editor) or a copy between the two sets of fields, and every read tests against 0. They now take TRUE and FALSE. Main has no 16-bit BOOLEnum, so the short fields keep their type; no header changes. One comment says what the nine flags are. The same code: the quick compile's listing is unchanged, and a narrow build of this file reads 100.0 raw and normalised with no diff entry. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review: euroRecruitable is indexed by the unit type counted from UT_E_ARCHER (main's IsEuroUnitRecruitableUnk reads it as euroRecruitable[unitType - UT_E_ARCHER]), so the seven tests behind the copy loop are written euroRecruitable[UT_E_XBOW - UT_E_ARCHER] and so on. The same code: the quick compile's listing is unchanged, and a narrow build of this file reads 100.0 raw and normalised with no diff entry. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TheRedDaemon
approved these changes
Nov 22, 2026
This was referenced Nov 22, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One function at 100%, written from the original's listing with gynt's draft beside it for the names. No header changes. No behaviour change against his draft; one index differs because main's header has moved since (below).
Actions::LaunchSinglePlayerGameUnkgynt's draft goes back to ce7ebb0 (2026-10-02, "reimplement: SHC_3BB0A8C1_0x0042C620 25.26% Style pass, asm differs"). Its best score, 28.35%, is ca39d7b (2026-10-03, the same subject), where he merged the draft's split name buffer (
char local_7e0[4]and alocal_7dc[1004]that nothing used) into one of 1008 bytes. His 409e2a3 ("Split buffer merged", on sourcehold's own reimpl/UI-Core) makes the same change and says why: the compiler dropped the unused half, so the frame came out 0x3fc against the original's 0x7e8, and the map's name overflowed the 4-byte buffer. The newest version is 15e5712 (2026-11-02, "style: rule 12, import 76 string literals across UI/Rendering and Helpers") on his fork's reimpl/UI-MenuItems-development, whose status line reads "28.4% | Style pass, asm differs". reimpl/UI-Core (#256) has the draft at 26.3% (2f1c52c), from before the merge. Its reimpl/UI-Core-development has it at 27.1% (10280b1), with the 4-byte buffer again. The draft does not compile on today's main (32 errors, all from names and types that have changed since: below), so there is no number for it from our build.Update (review)
SEC_*Producible_saveshorts and GameCore's*Producible_logicints) and the nineeuroRecruitableCopy_*flags are only ever 0 or 1 in the original, so they now takeTRUEandFALSE. Main has no 16-bitBOOLEnum, so the short fields keep their type; no header changes. (Its commit message says the values are copied "between the two sets of fields": the shorts are only stored as 1 or 0, or toggled in the map editor, and read into GameCore's ints, never the other way.)euroRecruitableis indexed by the unit type counted fromUT_E_ARCHER, as main'sIsEuroUnitRecruitableUnkreads it, so the seven tests are writteneuroRecruitable[UT_E_XBOW - UT_E_ARCHER]and so on.Measured
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie. The struct resolvers and the function resolvers are enabled locally (not committed). In the full build 0x004314E0 (theMapEditorLandscaping_GeneralButtonshandler) is left out and its resolver stays off, as in main's baseline.countof, which compiles to the same listing), with both resolver sets on: 0 failed of 2,424 compile steps, 99.57 over 2,440 functions, against 99.58 over 2,439 for main alone (built at f489b72; 3458fea only adds files undertools/, and cmake: optional wrapper units built from function-visibility.txt #399 and cmake: function-visibility.txt, which callers must see which callees' bodies #398 add the optional function-visibility units, off by default). The new function reads 100.0 raw and normalised there too, with no diff entry, and so does its caller on main,MenuItemActionHandler_SingleplayerMapChoice_ButtonsAndHands(0x0042D640), as before. Two functions on main read lower, and it is how reccmp prints a constant, not their code:Menu::handleMenuItems(0x004F6280) reads 97.9 (91.4 normalised) andMenu::Constructor_Menu(0x004F4100) reads 98.4 (95.2), both 100.0 before. Both compare a menu item's type with the constant 0x11000000, five compares in all. In this build's layout a symbol of our DLL lies at exactly the address 0x11000000, so reccmp prints the constant as that symbol's name on our side. The instructions are the same on both sides; UI: three more functions at 100%: the building menu's DoInitial, the credits' prepare and activateModalDialog2 #435 and UI: the credits scroll's fade and the win/defeat window at 100% #437 describe the same two readings. Every other main function reads exactly what it read before (unrounded 99.5746 against 99.5759 raw and 99.5439 against 99.5492 normalised; with those two at 100.0 it would be 99.5761 and 99.5494, as UI: the minimap's terrain colours at 100% #461's build, which also adds one function at 100%, reads).lea reg, [reg], anopand amov edi, edi, and three short jumps over them), in its order; reccmp's diff for the function is empty. The four-entry jump table of the mission type's switch (0x0042D130) is the original's, entry for entry.What the function does, and the draft
It starts a single-player game on a map. The original calls it from two places: the map choice's start button (
MenuItemActionHandler_SingleplayerMapChoice_ButtonsAndHandson main, a jump at 0x0042D72B, with 0) andMenuItemActionHandler_General_LaunchOrQuitMultiplayerGameUnk(0x00494D17, in #442, with 1: a builder game, after it has set the menu view that gynt's newer export callsMVT_RESTARTING_CUSTOM_MAP). With 0 the map is the one picked in the map list; with 1 it is the one whose namestandaloneFilenamealready holds.GCT_ASK_FOR_SLOT_ASSIGNMENT), keeping its own, sets everything to "can be made" and "can be recruited", builds the map's file name and loads the map. Behind the load the six weapon settings are set again, together with the game's own copies.mapHasCertainEventsays no: the troop value of the player's own units is added up, and every fourth, third or second of them is deleted (in up to three passes) until a quarter, a third or half of that value is gone. From the map choice it is always the first. Its start button sets the difficulty to 1 for an invasion (and for "just build") right before the call (0x0042D71D,MenuItemActionHandler_SingleplayerMapChoice_ButtonsAndHandson main), andloadMapkeeps it (it saves it at 0x004C62D2 and writes it back at 0x004C639D). For a deletedUT_S_MANGONELorUT_S_BALLISTAthe building on its tile has its tower engine type cleared.mapU4Int1starts with 600 gold.Read block by block against the listing, 15e5712 does all of this the way the original does. (Its two
strcats start from(char*)&local_7e4 + 3, Ghidra's way of writing "one byte before the buffer"; that holds only while the compiler putslocal_7e4right in front of the buffer, as the original's frame has it. Here they arestrcat.) What a port of it to today's main needs:DAT_ArrayOfMapIndices[scroll offset + selection - 1]. That was right for the header of its day, where the array started one entry later ([500]at 0x884). Since 12854bc main has it as[501]at 0x880, which is where the original reads it (0x0042C6B9:mov edx, [eax*4 + 0x1126e28]), so here the index has no- 1. With the- 1kept, today's main would load the list's entry before the picked one. gynt's own newer export (8ca7861 on reimpl/Wilps-2026-10-18) has it without the- 1too.DAT_SiegeInformationArrayisint[7][3]on main (7c6bb9e) where the draft's header hadint[21]. This file takes it as 20 numbers in a row through a pointer to its first element, as main'sMenuItemActionHandler_SingleplayerMapChoice_MapTabledoes.buildMenuTab = BMTT_CASTLE, the union member for the build menu that opens next. The draft writes the same 10 astabType = BASMTT_HUNTERSHUT.SiegeUnitCounts::field_0x48/field_0x4c,Building::defensiveTowerEngineType(the draft'scontainsSiegeMangonel1OrBallista2) andPlayerData::buildingEntryInfos[0](the draft'skeep).What got it to 100%
Each of these was measured against the alternative it names:
if (type != 2)in front ofif (type == 2) { peasants }. With the zeroing as that test's else arm, all blocks stay in the written order (140 lines of the listing differ).xor eax, eax) although the function holds a zero inebx. Written as loops, the compiler makes exactly that; twenty written zero stores takeebxinstead.MenuItemActionHandler_MapEditorProperties_MainButtons(UI: the map editor's properties buttons handler at 100% #441). Behind the loop, the loop's copies take the register that holds the zero, and the zero is no longer in a register from the first test of the argument on (the string loops then test withtest cl, clwhere the original hascmp cl, bl).char[1005]andchar[1001]: a map name's 1001 bytes (GameCore::standaloneFilename,ResourceManager::mapNames) and four more for ".map". That the frame needs both is gynt's find (409e2a3, above). With 1000 each, the frame is 0x7DC against the original's 0x7E8.? :argument computes the number without a jump (neg; sbb; and).eaxandecxswap). So the mission types are numbers with a comment, as in main's other files.Things in the file that look odd and are the original's
standaloneFilenamebehind it (when called with 1).type == 2 && slot == 1insidetype == 2): the original has both tests (0x0042C9C9 and 0x0042CA16). Without the second one 30 lines of the listing differ.siegeEngineCounts[3]goes to score 2 and[2]to score 3, and[5]to score 8: the same pairs as inMenuItemActionHandler_MapEditorProperties_MainButtons(UI: the map editor's properties buttons handler at 100% #441). By the names in gynt's newer export (below), the map's list has the siege tower before the battering ram and the wave's list has the ram first, and[5]is the wave'ssiegeEngineSlot8Count.siegeInformation.arabianArchers(0x0042CC7B and 0x0042CC8C store the same register).if (type != 2)followed byif (type == 2): see the block order above.totalis first the sum of the troop values and then the value still to take away, andpass = 10ends the passes from inside the unit loop: the original has one register for the first and the store of 10 for the second (0x0042CFCD).counterdeclared in front oftotal, and the argument compared with 1 at the end (0x0042D0BB): see above. A truth test compares with zero there.missionNumber1to20 = 28(0x0042CD92): the original's number, outside the 1 to 20 that main's sound code tests the field for.Checker CHECKs (not changed)
siegeUnits, tosiegeInformation.archers): the three loops over the twenty counts need the struct as an array, and the header has twenty named fields (a finding below).(short)casts oncurrentResources[RT_GOLD]: anintstored into the twoshortfieldslastMonthsGoldandbeforeLastMonthsGold.DAT_00b960dcis a placeholder name (a finding below).Header findings (nothing changed here)
functioninsrc/precomp/addresses-SHC-3BB0A8C1.hpp(no labels) and stand asPendingin the status list. Both are loop heads inside this function, which runs to 0x0042D12F: the second map name copy's loop and the head of the three passes, each behind alignment fillers. 0x0042D130 to 0x0042D13C (four/pointerlines, also Pending in the status list) are its jump table's four entries.DAT_MapMissionTypeis anundefined4with four values: 0 just build, 1 economic, 2 siege, 3 invasion (the comment in main'sMenuItemActionHandler_ScenarioDescription_Mainsays the same). An enum in the header would name them in the eight files on main that use it, and in this one.SiegeUnitCountsis walked as an array of 20 by the original (here three times; UI: the map editor's properties buttons handler at 100% #441'sMenuItemActionHandler_MapEditorProperties_MainButtonscopies it field by field). An array view beside the named fields, asBarracksRecruitabilityShorthas one, would do without the pointer. Main's header already has the map's own copy,MapPropertiesState::SEC_SiegeInformation, asint[20](8125c61), and this file indexes that directly.SiegeUnitCounts::arabianArchers) is the number this function also stores asSEC_Section1067.tunnelersCount. Main'sMenuItemActionHandler_SingleplayerMapChoice_MapTablealso writes 70% of the tunnelers into slot 10 of the same picked army (siegeUnits[10] = ... tunnelersCount * 7 / 10).param_1) is 0 or 1 at both call sites; this file calls ituseStandaloneFilename, and it could beBOOLEnumthere.DefensiveTowerEngineTypehas no value for 0. This file writes 0 (no engine) intoBuilding::defensiveTowerEngineType, as Reimplement 33 Synchrony::Commands functions at 100% #415, One more Map::Units function at 100%: UpdateMangonel #445 and One more Map::Units function at 100%: UpdateBallista #451 do.LaunchStandaloneMapGamethere,DAT_00b960dcisDAT_MenuFadeState,MVT_UNKNOWN_49_DOES_NOTHINGUnkisMVT_RESTARTING_CUSTOM_MAP,GameCore::gameSuspendedisbriefingOpenedFromInGameandWindowAndDirectDraw::unk_resetViewportRelatedispendingOverlayBltMode.pathfindingUpdate_0x4a8ab0isclearObstaclesAroundSignposts.AttackInfo::inv_countiscurrentAttackWaveSlotandsomeSinglePlayerScoreiswaveSiegeEngineCounts. The sixSEC_Section1067.siegeEngineCountsarecatapults,trebuchets,siegeTowers,batteringRams,portableShieldsandsiegeEngineSlot8Count.jesterIDUnk/someUnitIDSelfRef_2arejesterUnitID/jesterUnitUID, andladyIDUnk/someUnitIDSelfRefareladyUnitID/ladyUnitUID.unitJesterRelated/unitLadyRelatedarejesterEnabled/ladyEnabled, andPlayerData::startResourcesispendingResources.selectedLordType_2Unk/selectedLordTypeUnkaresinglePlayerMapLordType/localSelectedLordType,missionNumber1to20ismissionNumber, andSiegeUnitCounts::field_0x48/field_0x4careunknownUnitCount18/unknownUnitCount19.🤖 Generated with Claude Code