From 1d1afa83d213a9a2e50c5ddb5a24bc2c35c3d0a6 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Wed, 18 Nov 2026 14:30:09 +0100 Subject: [PATCH 1/3] reimplement: SHC_3BB0A8C1_0x00442640 100.0% Reimplemented LobbyMenu::MenuItemActionHandler_LobbyMenu_LobbyscreenStartButtonClick, from gynt's draft (c0a2f526c at 40.85% on his fork's development; c88d7a213 at 40.8% on upstream's reimpl/UI-MenuItems; f53ef94be to d81f02ff1, 54.93% to 69.03%, his fork's reimpl/UI-MenuItems; a4fb7c279 of 2026-10-28 on his fork's reimpl/Wilps-2026-10-18; 99cb9058a at 80.53%, 35aef556d at 80.71% and dd1a7c48c of 2026-11-02, his newest commit on the file, on his fork's reimpl/UI-MenuItems-development) and our cb601a074 and 1918de9f5 in draft #327 (90.7%). 90.3% -> 100.0% on main 3458fea34: - case 4 sets the draw buffer back once, after the if / else that launches the game: the original pops three registers before that store in the skirmish arm (pop esi / pop ebp / pop ebx / mov / pop edi / ret); - the two keep-position loops read keepPositions[position].x where they use it, with no local, which gives lea ebp, [eax + edi + 572] with x as the base (a local gave [edi + eax + 572]); - the map index. Case 4 writes its two sums as DAT_MapSelectionScrollOffset + DAT_MapSelectionRelativeSelected, and case 105 takes its index through a local that is declared before the switch. That gives both cases the original's two loads and add (0x0044284E: edx, eax, add eax, edx; 0x00442AD8: ecx, edx, add edx, ecx). The three sums are coupled: of 32 combinations (each case's sum written out, as a block-scope local or as this local, in both operand orders) only this one and its twin with case 105's operands swapped match. A block-scope local in case 105 swaps case 4's loads, which is why the declaration stands before the switch, with one comment line. The local starts at 0, which nothing reads: declared without a value, style rule 24 asks for it in case 105, and the code is the same either way. quick_diff reads 0.9956: its two lines are a tail jump it prints as a label and the jmp over the first loop's alignment padding; it cannot see the load order, since it prints both fields as [G]. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 Co-Authored-By: Claude Opus 5.5 --- ..._LobbyMenu_LobbyscreenStartButtonClick.cpp | 292 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 293 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemActionHandler_LobbyMenu_LobbyscreenStartButtonClick.cpp diff --git a/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemActionHandler_LobbyMenu_LobbyscreenStartButtonClick.cpp b/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemActionHandler_LobbyMenu_LobbyscreenStartButtonClick.cpp new file mode 100644 index 0000000000..d623e40635 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemActionHandler_LobbyMenu_LobbyscreenStartButtonClick.cpp @@ -0,0 +1,292 @@ +#include "../LobbyMenu.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Game/GameCore.func.hpp" +#include "OpenSHC/Random/RNG.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Text/UserTextHandler.func.hpp" +#include "OpenSHC/UI/Actions.func.hpp" +#include "OpenSHC/UI/MenuItems/General.func.hpp" +#include "OpenSHC/UI/MenuTextInputState.func.hpp" +#include "OpenSHC/Audio/SFX/SoundEffectID.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" + +#include "OpenSHC/Globals/DAT_00b960dc.hpp" +#include "OpenSHC/Globals/DAT_00b960f4.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_MouseState.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" +#include "OpenSHC/Globals/INT_00b95960.hpp" +#include "OpenSHC/Globals/INT_00b95b74.hpp" +#include "OpenSHC/Globals/INT_00b95f64.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x00442640 + void LobbyMenu::MenuItemActionHandler_LobbyMenu_LobbyscreenStartButtonClick(int action, ...) + { + if (DAT_00b960dc::instance != 0) { + return; + } + if (DAT_MenuTextInputState::instance.currentModalDialog != OpenSHC::UI::Enums::MMT_NO_MENU) { + return; + } + // case 105's index, declared here: declared in its case, the two loads of case 4's sum swap + int mapIndex = 0; + switch (action) { + case -1: + // chat scroll up + if (DAT_GameSynchronyState::instance.chatScrollOffset < 15) { + ++DAT_GameSynchronyState::instance.chatScrollOffset; + } + break; + case -2: + // chat scroll down + if (DAT_GameSynchronyState::instance.chatScrollOffset > 0) { + --DAT_GameSynchronyState::instance.chatScrollOffset; + } + break; + case 1: + // load game: only when every occupied slot is ready + if (!DAT_GameSynchronyState::instance.isHost) { + break; + } + for (int player = 1; player < countof(DAT_GameSynchronyState::instance.currentPlayerFullIDArray); + ++player) { + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[player] != -1 + && DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[player] == 0) { + return; + } + } + if (MACRO_CALL_MEMBER( + OpenSHC::Synchrony::GameSynchronyState_Func::checkPlayerSetValid, DAT_GameSynchronyState::ptr)() + >= 2) { + DAT_MenuTextInputState::instance.field_0x9c = 1; + MACRO_CALL_MEMBER( + OpenSHC::UI::MenuTextInputState_Func::loadOrSaveGame, DAT_MenuTextInputState::ptr)(9); + DAT_GameSynchronyState::instance.reparseMaps = TRUE; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + } + break; + case 2: + // leave the lobby + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME; + if (DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_SKIRMISH_SINGLE_PLAYER) { + MACRO_CALL_MEMBER( + OpenSHC::Text::UserTextHandler_Func::resetToTextIndex, DAT_UserTextHandlerState::ptr)(9); + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_MAIN_MENU, 0); + if (DAT_MenuModalComposition1::instance.activeModalDialogID == OpenSHC::UI::Enums::MMT_ROUNDTABLE + || DAT_MenuModalComposition1::instance.activeModalDialogID + == OpenSHC::UI::Enums::MMT_BASIC_AI_LORD_SELECT + || DAT_MenuModalComposition1::instance.activeModalDialogID + == OpenSHC::UI::Enums::MMT_EXTENDED_AI_LORD_SELECT) { + DAT_MenuModalComposition1::instance.activeModalDialogID = OpenSHC::UI::Enums::MMT_NONE; + } + } else { + DAT_GameSynchronyState::instance.currentGameMode = OpenSHC::Game::GM_MULTIPLAYER_END_OF_GAME; + MACRO_CALL_MEMBER( + OpenSHC::Text::UserTextHandler_Func::resetToTextIndex, DAT_UserTextHandlerState::ptr)(9); + DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 7; + MACRO_CALL(OpenSHC::UI::MenuItems::General_Func:: + MenuItemActionHandler_General_LaunchOrQuitMultiplayerGameUnk)(22); + if (DAT_MenuModalComposition1::instance.activeModalDialogID == OpenSHC::UI::Enums::MMT_ROUNDTABLE + || DAT_MenuModalComposition1::instance.activeModalDialogID + == OpenSHC::UI::Enums::MMT_BASIC_AI_LORD_SELECT + || DAT_MenuModalComposition1::instance.activeModalDialogID + == OpenSHC::UI::Enums::MMT_EXTENDED_AI_LORD_SELECT) { + DAT_MenuModalComposition1::instance.activeModalDialogID = OpenSHC::UI::Enums::MMT_NONE; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::reorderTeamsAndPositions, + DAT_GameSynchronyState::ptr)(); + } + } + break; + case -20: + case 3: + // ready button + if (DAT_GameSynchronyState::instance.flag_0x7aad8 + && DAT_GameSynchronyState::instance.DAT_TwoIfNotHost == 2) { + DAT_GameSynchronyState::instance + .DAT_PlayerSlotArraySomeValue[DAT_GameSynchronyState::instance.currentPlayerSlotID] ^= 1; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_HOST_ANNOUNCE_TEAMS_AND_POSITIONS); + } + if (DAT_GameSynchronyState::instance.isHost + && DAT_GameSynchronyState::instance + .DAT_PlayerSlotArraySomeValue[DAT_GameSynchronyState::instance.currentPlayerSlotID] + != 0) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_CHANGE_GAME_INTENSITY_OR_BALANCE); + } + break; + case 4: + // start the game: only when every occupied slot is ready + if (!DAT_GameSynchronyState::instance.isHost) { + break; + } + for (int player = 1; player < countof(DAT_GameSynchronyState::instance.currentPlayerFullIDArray); + ++player) { + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[player] != -1 + && DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[player] == 0) { + return; + } + } + if (MACRO_CALL_MEMBER( + OpenSHC::Synchrony::GameSynchronyState_Func::checkPlayerSetValid, DAT_GameSynchronyState::ptr)() + >= 2 + && DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset + + DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected + >= 0 + && DAT_GameSynchronyState::instance + .unknownMapRelatedReceivedDataArray[DAT_MenuTextInputState::instance + .DAT_ArrayOfMapIndices[DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset + + DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected]] + > 0) { + MACRO_CALL_MEMBER(OpenSHC::Random::RNG_Func::setTimeBasedSeed, SEC_RNG::ptr)(); + MACRO_CALL_MEMBER( + OpenSHC::Text::UserTextHandler_Func::resetToTextIndex, DAT_UserTextHandlerState::ptr)(9); + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = 0; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_TRIGGER_LOBBY_PLAYER_INFORMATION_REFRESH); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_CHANGE_GAME_INTENSITY_OR_BALANCE); + if (DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_SKIRMISH_SINGLE_PLAYER) { + DAT_GameCore::instance.isSkirmishTrail = FALSE; + MACRO_CALL(OpenSHC::UI::Actions_Func::LaunchSkirmishGame)(0); + } else { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_START_MULTIPLAYER_GAME); + } + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_MAP_GAME; + } + break; + case -10: + // map list scroll up + if (DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset > 0) { + --DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset; + if (DAT_GameSynchronyState::instance.isHost) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_CHANGE_MAP_SELECTION); + } + } + break; + case -11: + // map list scroll down + if (DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset + < DAT_GameSynchronyState::instance.DAT_MapSelectionTotalNumber - 8) { + ++DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset; + if (DAT_GameSynchronyState::instance.isHost) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_CHANGE_MAP_SELECTION); + } + } + break; + case -100: + // map description scroll up + DAT_00b960f4::instance -= 14; + if (DAT_00b960f4::instance < -19) { + DAT_00b960f4::instance = -19; + } + break; + case -101: { + // map description scroll down + int const limit = INT_00b95b74::instance - 114; + if (DAT_00b960f4::instance < limit) { + DAT_00b960f4::instance += 14; + if (DAT_00b960f4::instance > limit) { + DAT_00b960f4::instance = limit; + } + } + break; + } + case -200: + // pick up the keep position under the mouse + if (!DAT_GameSynchronyState::instance.isHost) { + break; + } + for (int position = 0; position < countof(DAT_GameCore::instance.keepPositions); ++position) { + if (DAT_GameCore::instance.keepPositions[position].x < 0 + || DAT_MouseState::instance.screenSpaceX < DAT_GameCore::instance.keepPositions[position].x + + DAT_WindowAndDirectDraw::instance.mainMenuBorderWidth + 572 + || DAT_MouseState::instance.screenSpaceX > DAT_GameCore::instance.keepPositions[position].x + + DAT_WindowAndDirectDraw::instance.mainMenuBorderWidth + 595) { + continue; + } + int const y = DAT_GameCore::instance.keepPositions[position].y + + DAT_WindowAndDirectDraw::instance.mainMenuBorderHeight; + if (DAT_MouseState::instance.screenSpaceY < y + 3 + || DAT_MouseState::instance.screenSpaceY > y + 35) { + continue; + } + INT_00b95960::instance = DAT_GameSynchronyState::instance.playerPositionsArray[position]; + INT_00b95f64::instance = position; + return; + } + break; + case -201: + // drop it on the keep position under the mouse: swap the two players' positions + if (!DAT_GameSynchronyState::instance.isHost) { + break; + } + if (INT_00b95960::instance >= 0) { + for (int position = 0; position < countof(DAT_GameCore::instance.keepPositions); ++position) { + if (DAT_GameCore::instance.keepPositions[position].x < 0 + || DAT_MouseState::instance.screenSpaceX < DAT_GameCore::instance.keepPositions[position].x + + DAT_WindowAndDirectDraw::instance.mainMenuBorderWidth + 572 + || DAT_MouseState::instance.screenSpaceX > DAT_GameCore::instance.keepPositions[position].x + + DAT_WindowAndDirectDraw::instance.mainMenuBorderWidth + 595) { + continue; + } + int const y = DAT_GameCore::instance.keepPositions[position].y + + DAT_WindowAndDirectDraw::instance.mainMenuBorderHeight; + if (DAT_MouseState::instance.screenSpaceY < y + 3 + || DAT_MouseState::instance.screenSpaceY > y + 35) { + continue; + } + int const dragged + = DAT_GameSynchronyState::instance.playerPositionsArray[INT_00b95f64::instance]; + DAT_GameSynchronyState::instance.playerPositionsArray[INT_00b95f64::instance] + = DAT_GameSynchronyState::instance.playerPositionsArray[position]; + DAT_GameSynchronyState::instance.playerPositionsArray[position] = dragged; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_HOST_ANNOUNCE_TEAMS_AND_POSITIONS); + break; + } + } + INT_00b95960::instance = -1; + break; + case 105: + mapIndex = DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset + + DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected; + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 + = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[mapIndex]; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_UNKNOWN_103); + break; + case 413: + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::setUpSFXToPlayUnk, DAT_SFXState::ptr)( + OpenSHC::Audio::SFX::SEID_UNKNOWN_0xFD); + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_RANKING_GAMES, 0); + break; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b62540e14f..20fde2b22c 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -13693,7 +13693,7 @@ SHC_3BB0A8C1_0x00442230 | 0.0% | Pending SHC_3BB0A8C1_0x00442300 | 0.0% | Pending -SHC_3BB0A8C1_0x00442640 | 0.0% | Pending +SHC_3BB0A8C1_0x00442640 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004429C0 | 0.0% | Pending From cd3bf5707c42617b1183b007b7ae7f4a992268ea Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Wed, 18 Nov 2026 14:08:00 +0100 Subject: [PATCH 2/3] reimplement: SHC_3BB0A8C1_0x00492DE0 100.0% Reimplemented SaveLoadMap::MenuItemActionHandler_SaveLoadMap_TableHeader, rewritten from the binary with gynt's draft for the names (f788afb14 at 17.2% on upstream's reimpl/UI-MenuItems; 54e57c4e1 and 21d4dcf9a at 47.81% and 49.40% on his fork's reimpl/UI-MenuItems; 8725ec523 at 49.4% on his reimpl/UI-MenuItems-development, his newest reimplement commit on the file). reccmp 100.0 (normalized 100.0) on main 3458fea34 with the data and its own function resolver on; the draft reads 47.8 there. The array index changed with the header. gynt's draft uses DAT_ArrayOfMapIndices[i - 1] and [i], which was right on his branch, where the array is declared at offset 0x884. Main's sync 12854bcf4 (2026-11-04) moved the declared start to 0x880, so the original's 0x01126E28 and 0x01126E2C are [i] and [i + 1] here. - The order store is in each arm and previewedListIndex = -1 is written once after the if / else. MSVC copies that store into both arms, after the last pop, as the original has it; only the order store sits between the pops. Written in each arm, it keeps -1 in ebx and pushes ebx at the top, and the first sort's two loops lose their alignment padding. - The swap reads the moved element into a local inside the if. With both elements in locals before the test they land in each other's registers. - fileListEntryCount is read in the loop condition: the original reloads it after each swap's stores. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- ...mActionHandler_SaveLoadMap_TableHeader.cpp | 95 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/SaveLoadMap/MenuItemActionHandler_SaveLoadMap_TableHeader.cpp diff --git a/src/OpenSHC/UI/MenuItems/SaveLoadMap/MenuItemActionHandler_SaveLoadMap_TableHeader.cpp b/src/OpenSHC/UI/MenuItems/SaveLoadMap/MenuItemActionHandler_SaveLoadMap_TableHeader.cpp new file mode 100644 index 0000000000..230d9826e9 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/SaveLoadMap/MenuItemActionHandler_SaveLoadMap_TableHeader.cpp @@ -0,0 +1,95 @@ +#include "../SaveLoadMap.func.hpp" + +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x00492DE0 + void SaveLoadMap::MenuItemActionHandler_SaveLoadMap_TableHeader(int button, ...) + { + // the header's arrows, -1 to -4, choose the column and the order the sort below turns round + if (button < 0) { + button = -1 - button; + switch (button) { + case 0: + DAT_MenuTextInputState::instance.fileListSortOrder = 1; + break; + case 1: + DAT_MenuTextInputState::instance.fileListSortOrder = 0; + button = 0; + break; + case 2: + DAT_MenuTextInputState::instance.fileListSortOrder = 3; + button = 1; + break; + case 3: + DAT_MenuTextInputState::instance.fileListSortOrder = 2; + button = 1; + break; + } + } + switch (button) { + case 1: + // by the file's time: a bubble sort, one way or the other + if (DAT_MenuTextInputState::instance.fileListSortOrder == 2) { + for (int swaps = 1; swaps != 0;) { + swaps = 0; + for (int i = 0; i < DAT_MenuTextInputState::instance.fileListEntryCount - 1; ++i) { + if (DAT_ResourceManager::instance + .mapFileTimes[DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i]] + > DAT_ResourceManager::instance + .mapFileTimes[DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1]]) { + int const moved = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i]; + DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i] + = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1]; + DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1] = moved; + ++swaps; + } + } + } + DAT_MenuTextInputState::instance.fileListSortOrder = 3; + } else { + for (int swaps = 1; swaps != 0;) { + swaps = 0; + for (int i = 0; i < DAT_MenuTextInputState::instance.fileListEntryCount - 1; ++i) { + if (DAT_ResourceManager::instance + .mapFileTimes[DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i]] + < DAT_ResourceManager::instance + .mapFileTimes[DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1]]) { + int const moved = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i]; + DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i] + = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1]; + DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1] = moved; + ++swaps; + } + } + } + DAT_MenuTextInputState::instance.fileListSortOrder = 2; + } + DAT_MenuTextInputState::instance.previewedListIndex = -1; + return; + case 0: + // by name: the list as it was read, or the other way round + if (DAT_MenuTextInputState::instance.fileListSortOrder == 0) { + for (int i = 0; i < DAT_MenuTextInputState::instance.fileListEntryCount; ++i) { + DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i] + = DAT_MenuTextInputState::instance.fileListEntryCount - i - 1; + } + DAT_MenuTextInputState::instance.fileListSortOrder = 1; + } else { + for (int i = 0; i < DAT_MenuTextInputState::instance.fileListEntryCount; ++i) { + DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i] = i; + } + DAT_MenuTextInputState::instance.fileListSortOrder = 0; + } + DAT_MenuTextInputState::instance.previewedListIndex = -1; + return; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 20fde2b22c..a7061eafaa 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23525,7 +23525,7 @@ SHC_3BB0A8C1_0x00492C60 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00492C90 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00492DE0 | 0.0% | Pending +SHC_3BB0A8C1_0x00492DE0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00492E70 | 0.0% | Pending From 2ee45e587ecd86a728a39b3c0fe5662eb6b5a009 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Wed, 18 Nov 2026 14:10:34 +0100 Subject: [PATCH 3/3] reimplement: SHC_3BB0A8C1_0x004269E0 100.0% Reimplemented HistoricMissionSelect::MenuItemRenderFunction_HistoricMissionSelect_MissionRows, rewritten from the binary with gynt's draft for the names (298b3af4e at 20.6% on upstream's reimpl/UI-MenuItems; 633d78492 at 41.41% on his fork's reimpl/UI-MenuItems; 626fd6817 at 44.53% on his reimpl/UI-MenuItems-development, his newest reimplement commit on the file). reccmp 100.0 (normalized 100.0) on main 3458fea34 with the data and its own function resolver on; the draft reads 45.3 there. Behaviour: a mission not reached yet is drawn as a greyed cell and the function returns (0x00426A53). The draft went on and drew the number and the name over it. - The number and the name are written in each of the three arms, and DAT_ButtonUnknownZero = FALSE once after them: MSVC hoists the arms' common pushes and shares the tail, as the original has it. - The number's position is written out in each arm; with locals for it the two loads come in the other order. - In the selected arm the name's position and index are read into locals before the nested call, Y, X, then the index, which gives the original's registers for that call. - The locked test compares (int)(DAT_00b96100 - row - 1): the global is an undefined4, and the original's jle is signed. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- ...tion_HistoricMissionSelect_MissionRows.cpp | 89 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/HistoricMissionSelect/MenuItemRenderFunction_HistoricMissionSelect_MissionRows.cpp diff --git a/src/OpenSHC/UI/MenuItems/HistoricMissionSelect/MenuItemRenderFunction_HistoricMissionSelect_MissionRows.cpp b/src/OpenSHC/UI/MenuItems/HistoricMissionSelect/MenuItemRenderFunction_HistoricMissionSelect_MissionRows.cpp new file mode 100644 index 0000000000..20df47dbd0 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/HistoricMissionSelect/MenuItemRenderFunction_HistoricMissionSelect_MissionRows.cpp @@ -0,0 +1,89 @@ +#include "../HistoricMissionSelect.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" + +#include "OpenSHC/Globals/DAT_00b95b2c.hpp" +#include "OpenSHC/Globals/DAT_00b96100.hpp" +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonUnknownZero.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x004269E0 + void HistoricMissionSelect::MenuItemRenderFunction_HistoricMissionSelect_MissionRows(int row, ...) + { + if (DAT_MenuTextInputState::instance.currentModalDialog == OpenSHC::UI::Enums::MMT_NO_MENU + && DAT_MenuModalComposition1::instance.activeModalDialogID == OpenSHC::UI::Enums::MMT_NONE) { + // a mission not reached yet is drawn greyed, with no text + if (!DAT_GameCore::instance.unlockAllHistoricalCampaigns + && (int)(DAT_00b96100::instance - row - 1) + > (&DAT_GameCore::instance.scenarioProgress.progressCallToArms)[DAT_00b95b2c::instance]) { + DAT_ButtonCurrentlyInteracting::instance = FALSE; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawTableCellBackground, + DAT_PencilRenderCore::ptr)(FALSE, row, 0); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_MAP_GAME; + DAT_ButtonUnknownZero::instance = TRUE; + return; + } + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::PencilRenderCore_Func::drawTableCellBackground, DAT_PencilRenderCore::ptr)( + DAT_00b96100::instance - row - 1 == DAT_GameCore::instance.missionNumber1to20, row, 0); + int const number = -row; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME; + // written in each arm: MSVC then hoists the calls' common pushes, as the original has them + if (number == DAT_GameCore::instance.missionNumber1to20) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumberToScreen2, + DAT_TextManagerObject::ptr)(number, DAT_ButtonX::instance + 8, DAT_ButtonY::instance + 5, + OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_CCFAFF, 19, FALSE, 0); + // read before the nested call, in the order the original loads them + int const nameY = DAT_ButtonY::instance + 5; + int const nameX = DAT_ButtonX::instance + 30; + int const mission = DAT_00b96100::instance - row - 1; + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_MISSION_NAMES, mission), + nameX, nameY, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_CCFAFF, 19, FALSE, 0); + } else if (DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumberToScreen2, + DAT_TextManagerObject::ptr)(number, DAT_ButtonX::instance + 8, DAT_ButtonY::instance + 5, + OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_CCFAFF, 19, FALSE, 0); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_MISSION_NAMES, DAT_00b96100::instance - row - 1, + DAT_ButtonX::instance + 30, DAT_ButtonY::instance + 5, OpenSHC::Text::TTA_LEFT, + OpenSHC::Rendering::Colors::COL_CCFAFF, 19, FALSE); + } else { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumberToScreen2, + DAT_TextManagerObject::ptr)(number, DAT_ButtonX::instance + 8, DAT_ButtonY::instance + 5, + OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_C2F0EB, 19, FALSE, 0); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_MISSION_NAMES, DAT_00b96100::instance - row - 1, + DAT_ButtonX::instance + 30, DAT_ButtonY::instance + 5, OpenSHC::Text::TTA_LEFT, + OpenSHC::Rendering::Colors::COL_C2F0EB, 19, FALSE); + } + DAT_ButtonUnknownZero::instance = FALSE; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index a7061eafaa..f343067b9a 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -6781,7 +6781,7 @@ SHC_3BB0A8C1_0x00426830 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004268C0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004269E0 | 0.0% | Pending +SHC_3BB0A8C1_0x004269E0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00426B80 | 100.0% | Reimplemented