From 982cfdfd3fa16b86f6daf151cdaf8d08cbfaf60f Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 01:21:49 +0100 Subject: [PATCH 01/19] headers: IngameScenarioEventItemContent::allOrAnyCondition is a short 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 #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 --- .../Game/ScenarioEvents/IngameScenarioEventItemContent.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/OpenSHC/Game/ScenarioEvents/IngameScenarioEventItemContent.hpp b/src/OpenSHC/Game/ScenarioEvents/IngameScenarioEventItemContent.hpp index dd8971b910..bbf10bcfc0 100644 --- a/src/OpenSHC/Game/ScenarioEvents/IngameScenarioEventItemContent.hpp +++ b/src/OpenSHC/Game/ScenarioEvents/IngameScenarioEventItemContent.hpp @@ -22,8 +22,7 @@ namespace Game { int actionData; // 0x00000000 length: 4 int ScenarioEventType; // 0x00000004 length: 4 - byte allOrAnyCondition; // 0x00000008 length: 1 - byte magic; // 0x00000009 length: 1 + short allOrAnyCondition; // 0x00000008 length: 2 byte repeat; // 0x0000000A length: 1 byte repeatMonths; // 0x0000000B length: 1 ScenarioEventCondition conditions[40]; // 0x0000000C length: 160 From 5af554519e54a6ae0097c8affdeab68c23ec574c Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 01:21:50 +0100 Subject: [PATCH 02/19] reimplement: SHC_3BB0A8C1_0x004C01B0 100.0% Reimplemented MenuItemRenderFunction_NewEventCondition_Main, rewritten from the binary (gynt's draft from his fork's reimpl/UI-MenuItems-development, 72.8% in #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 Co-Authored-By: Claude Opus 5.5 --- ...mRenderFunction_NewEventCondition_Main.cpp | 353 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 354 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/NewEventCondition/MenuItemRenderFunction_NewEventCondition_Main.cpp diff --git a/src/OpenSHC/UI/MenuItems/NewEventCondition/MenuItemRenderFunction_NewEventCondition_Main.cpp b/src/OpenSHC/UI/MenuItems/NewEventCondition/MenuItemRenderFunction_NewEventCondition_Main.cpp new file mode 100644 index 0000000000..be94c62f41 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/NewEventCondition/MenuItemRenderFunction_NewEventCondition_Main.cpp @@ -0,0 +1,353 @@ +#include "../NewEventCondition.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering.func.hpp" +#include "OpenSHC/UI/Rendering/AlphaAndButtonSurface.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/RoundedBoxEdgeRoundingLevel.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/AlphaAndButtonSurfaceObj.hpp" +#include "OpenSHC/Globals/COL_BLUE.hpp" +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonH.hpp" +#include "OpenSHC/Globals/DAT_ButtonUnknownZero.hpp" +#include "OpenSHC/Globals/DAT_ButtonW.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_MissionAestheticsDefinedData.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004C01B0 + void NewEventCondition::MenuItemRenderFunction_NewEventCondition_Main(int button, ...) + { + // The condition's text, copied at the start (copied after the check: quick_diff 0.9440 -> 0.8940) + int textNumber = button; + DAT_ButtonUnknownZero::instance = FALSE; + if (button > 5000) { + return; + } + switch (button) { + case -1: + // The event's month: X + W / 2 here (W / 2 + X, as in 2002: reccmp 99.7% -> 99.3%) + // One call per colour (one call with a colour local: quick_diff 0.9440 -> 0.9237) + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + if (!DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_MONTHS, + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .header.month + + 12, + DAT_ButtonX::instance + DAT_ButtonW::instance / 2, DAT_ButtonY::instance + 6, + OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_C2F0EB, 18, FALSE); + } else { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_MONTHS, + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .header.month + + 12, + DAT_ButtonX::instance + DAT_ButtonW::instance / 2, DAT_ButtonY::instance + 6, + OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE); + } + return; + case 126: + if (!DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .enabled) { + // "Inactive" + button = 127; + } + // as 19 + case 19: + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderScenarioButtonWithText)(button); + return; + case 104: + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.allOrAnyCondition) { + // "All of these" + button = 105; + } + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderScenarioButtonWithText)(button); + return; + case 209: { + // "Win Timer" (row 39) only while one of these conditions is on: else DAT_ButtonUnknownZero + BOOLEnum anyEnabled = FALSE; + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[1] + .enabled) { + anyEnabled = TRUE; + } + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[4] + .enabled) { + anyEnabled = TRUE; // Written out (a loop over 4 to 7: quick_diff 0.9440 -> 0.8543) + } + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[5] + .enabled) { + anyEnabled = TRUE; + } + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[6] + .enabled) { + anyEnabled = TRUE; + } + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[7] + .enabled) { + anyEnabled = TRUE; + } + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[17] + .enabled) { + anyEnabled = TRUE; + } + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[20] + .enabled) { + anyEnabled = TRUE; // Written out (a loop over 20 to 22: quick_diff 0.9440 -> 0.8708) + } + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[21] + .enabled) { + anyEnabled = TRUE; + } + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[22] + .enabled) { + anyEnabled = TRUE; + } + if (!DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[23] + .enabled + && !anyEnabled) { + DAT_ButtonUnknownZero::instance = TRUE; + return; + } + } + // as 190 to 208 + case 190: // conditions 20 to 39 + case 191: + case 192: + case 193: + case 194: + case 195: + case 196: + case 197: + case 198: + case 199: + case 200: + case 201: + case 202: + case 203: + case 204: + case 205: + case 206: + case 207: + case 208: + button -= 64; + case 106: // conditions 0 to 19 + case 107: + case 108: + case 109: + case 110: + case 111: + case 112: + case 113: + case 114: + case 115: + case 116: + case 117: + case 118: + case 119: + case 120: + case 121: + case 122: + case 123: + case 124: + case 125: { + int const slot = button - 106; + DAT_ButtonCurrentlyInteracting::instance = DAT_MapPropertiesState::instance.invasionTroopIndex == slot; + uint color = OpenSHC::Rendering::Colors::COL_C2F0EB; + if (DAT_ButtonCurrentlyInteracting::instance) { + color = OpenSHC::Rendering::Colors::COL_CCFAFF; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + // "Food Acquired" (111) and "Weapons Acquired" (112, 123) show "Goods Acquired" (113) + if (textNumber == 111 || textNumber == 112 || textNumber == 113 || textNumber == 123) { + textNumber = 113; + } + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[slot] + .enabled) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_SCENARIO, textNumber, DAT_ButtonX::instance + 5, + DAT_ButtonY::instance + 7, OpenSHC::Text::TTA_LEFT, color, 18, FALSE); + if (DAT_MissionAestheticsDefinedData::instance.EventConditionMaxValue[slot] == 0) { + return; + } + // ParamKind 1: one of EventConditionOptionTextOffsets (goods); 2: one of field_0x170 (an opponent) + if (DAT_MissionAestheticsDefinedData::instance.EventConditionParamKind[slot] == 1) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_SCENARIO, + DAT_MissionAestheticsDefinedData::instance + .EventConditionOptionTextOffsets[DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[slot] + .subType], + DAT_ButtonX::instance + 14, DAT_ButtonY::instance + 7, OpenSHC::Text::TTA_LEFT, color, 18, + TRUE); + } + if (DAT_MissionAestheticsDefinedData::instance.EventConditionParamKind[slot] == 2) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_SCENARIO, + DAT_MissionAestheticsDefinedData::instance.field_0x170[DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[slot] + .subType], + DAT_ButtonX::instance + 14, DAT_ButtonY::instance + 7, OpenSHC::Text::TTA_LEFT, color, 18, + TRUE); + } + MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::renderNumberToScreen, DAT_TextManagerObject::ptr)( + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[slot] + .value + * DAT_MissionAestheticsDefinedData::instance.EventConditionValueScale[slot], + DAT_ButtonW::instance + DAT_ButtonX::instance - 8, DAT_ButtonY::instance + 7, + OpenSHC::Text::TTA_RIGHT, color, 18, FALSE); + return; + } + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_SCENARIO, textNumber, DAT_ButtonX::instance + 5, DAT_ButtonY::instance + 7, + OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_7F7F7F, 18, FALSE); + return; + } + case 1001: + if (DAT_MissionAestheticsDefinedData::instance + .EventConditionMaxValue[DAT_MapPropertiesState::instance.invasionTroopIndex] + == 0) { + return; + } + if (!DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBoxWithRoundedEdges, + DAT_PencilRenderCore::ptr)(DAT_ButtonX::instance, DAT_ButtonY::instance, + DAT_ButtonW::instance + DAT_ButtonX::instance, DAT_ButtonH::instance + DAT_ButtonY::instance, + OpenSHC::UI::Enums::RBERL_SLIGHT); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBoxWithRoundedEdgesAndColor, + DAT_PencilRenderCore::ptr)(DAT_ButtonX::instance, DAT_ButtonY::instance, + DAT_ButtonW::instance + DAT_ButtonX::instance, DAT_ButtonH::instance + DAT_ButtonY::instance, + COL_BLUE::instance.shortValue, OpenSHC::UI::Enums::RBERL_SLIGHT); + } + return; + // 2000 before 1000, !interacting first (in turn: quick_diff 0.9440 -> 0.9109; interacting first: 0.8223) + case 2000: + if (DAT_MissionAestheticsDefinedData::instance + .EventConditionParamKind[DAT_MapPropertiesState::instance.invasionTroopIndex] + == 0) { + return; + } + if (!DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBoxWithRoundedEdges, + DAT_PencilRenderCore::ptr)(DAT_ButtonX::instance, DAT_ButtonY::instance, + DAT_ButtonW::instance + DAT_ButtonX::instance, DAT_ButtonH::instance + DAT_ButtonY::instance, + OpenSHC::UI::Enums::RBERL_SLIGHT); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBoxWithRoundedEdgesAndColor, + DAT_PencilRenderCore::ptr)(DAT_ButtonX::instance, DAT_ButtonY::instance, + DAT_ButtonW::instance + DAT_ButtonX::instance, DAT_ButtonH::instance + DAT_ButtonY::instance, + COL_BLUE::instance.shortValue, OpenSHC::UI::Enums::RBERL_SLIGHT); + } + return; + case 1000: + if (DAT_MissionAestheticsDefinedData::instance + .EventConditionMaxValue[DAT_MapPropertiesState::instance.invasionTroopIndex] + == 0) { + return; + } + if (!DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBoxWithRoundedEdges, + DAT_PencilRenderCore::ptr)(DAT_ButtonX::instance, DAT_ButtonY::instance, + DAT_ButtonW::instance + DAT_ButtonX::instance, DAT_ButtonH::instance + DAT_ButtonY::instance, + OpenSHC::UI::Enums::RBERL_SLIGHT); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBoxWithRoundedEdgesAndColor, + DAT_PencilRenderCore::ptr)(DAT_ButtonX::instance, DAT_ButtonY::instance, + DAT_ButtonW::instance + DAT_ButtonX::instance, DAT_ButtonH::instance + DAT_ButtonY::instance, + COL_BLUE::instance.shortValue, OpenSHC::UI::Enums::RBERL_SLIGHT); + } + return; + case 2002: + if (DAT_MissionAestheticsDefinedData::instance + .EventConditionParamKind[DAT_MapPropertiesState::instance.invasionTroopIndex] + == 1) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_SCENARIO, + DAT_MissionAestheticsDefinedData::instance + .EventConditionOptionTextOffsets[DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .subType], + DAT_ButtonW::instance / 2 + DAT_ButtonX::instance, DAT_ButtonY::instance + 8, + OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_C2F0EB, 18, FALSE); + } + if (DAT_MissionAestheticsDefinedData::instance + .EventConditionParamKind[DAT_MapPropertiesState::instance.invasionTroopIndex] + != 2) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_SCENARIO, + DAT_MissionAestheticsDefinedData::instance.field_0x170[DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .subType], + DAT_ButtonW::instance / 2 + DAT_ButtonX::instance, DAT_ButtonY::instance + 8, + OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_C2F0EB, 18, FALSE); + return; + case 2001: + if (DAT_MissionAestheticsDefinedData::instance + .EventConditionParamKind[DAT_MapPropertiesState::instance.invasionTroopIndex] + == 0) { + return; + } + if (!DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBoxWithRoundedEdges, + DAT_PencilRenderCore::ptr)(DAT_ButtonX::instance, DAT_ButtonY::instance, + DAT_ButtonW::instance + DAT_ButtonX::instance, DAT_ButtonH::instance + DAT_ButtonY::instance, + OpenSHC::UI::Enums::RBERL_SLIGHT); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBoxWithRoundedEdgesAndColor, + DAT_PencilRenderCore::ptr)(DAT_ButtonX::instance, DAT_ButtonY::instance, + DAT_ButtonW::instance + DAT_ButtonX::instance, DAT_ButtonH::instance + DAT_ButtonY::instance, + COL_BLUE::instance.shortValue, OpenSHC::UI::Enums::RBERL_SLIGHT); + } + return; + default: + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderScenarioButtonWithText)(button); + return; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index a105efbb9b..1ea91de334 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -32329,7 +32329,7 @@ SHC_3BB0A8C1_0x004C01A5 | 0.0% | Pending SHC_3BB0A8C1_0x004C01A6 | 0.0% | Pending -SHC_3BB0A8C1_0x004C01B0 | 0.0% | Pending +SHC_3BB0A8C1_0x004C01B0 | 100.0% | Reimplemented, only the RenderScenarioButtonWithText tail call targets differ SHC_3BB0A8C1_0x004C0770 | 0.0% | Pending From e7718d60cc2b65956c9e2ecbc0b098cecf3a8a22 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 01:21:50 +0100 Subject: [PATCH 03/19] reimplement: SHC_3BB0A8C1_0x004B8220 100.0% Reimplemented MenuItemActionHandler_EditScenario_BaseMenuButtons, rewritten from the binary (gynt's draft from his fork's reimpl/UI-MenuItems-development, 73.5% in #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 Co-Authored-By: Claude Opus 5.5 --- ...onHandler_EditScenario_BaseMenuButtons.cpp | 306 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 307 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/EditScenario/MenuItemActionHandler_EditScenario_BaseMenuButtons.cpp diff --git a/src/OpenSHC/UI/MenuItems/EditScenario/MenuItemActionHandler_EditScenario_BaseMenuButtons.cpp b/src/OpenSHC/UI/MenuItems/EditScenario/MenuItemActionHandler_EditScenario_BaseMenuButtons.cpp new file mode 100644 index 0000000000..2ab926a839 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/EditScenario/MenuItemActionHandler_EditScenario_BaseMenuButtons.cpp @@ -0,0 +1,306 @@ +#include "../EditScenario.func.hpp" + +#include "OpenSHC/Game/GameCore.func.hpp" +#include "OpenSHC/Game/ScenarioEvents/InGameEventUnionVersion.func.hpp" +#include "OpenSHC/Map/MapPropertiesState.func.hpp" +#include "OpenSHC/OS.func.hpp" +#include "OpenSHC/Text/UserTextHandler.func.hpp" +#include "OpenSHC/UI/Helpers.func.hpp" +#include "OpenSHC/UI/MenuModalComposition.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Game/Resources/ResourceType.hpp" +#include "OpenSHC/Map/MapType2.hpp" +#include "OpenSHC/Text/TextArrayIndexType.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" +#include "OpenSHC/string-literals.hpp" + +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_CopyOfScenarioGold.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition2.hpp" +#include "OpenSHC/Globals/DAT_MissionAestheticsDefinedData.hpp" +#include "OpenSHC/Globals/DAT_StopHandlingMenuItems.hpp" +#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp" + +#include + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x004B8220 + void EditScenario::MenuItemActionHandler_EditScenario_BaseMenuButtons(int button, ...) + { + if (DAT_MenuModalComposition1::instance.activeModalDialogID != OpenSHC::UI::Enums::MMT_NONE) { + return; + } + switch (button) { + case 3: + // back to the map's properties with the typed start year + DAT_MapPropertiesState::instance.SEC_StartingYear + = atol(MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::getTextArrayPointer, + DAT_UserTextHandlerState::ptr)(OpenSHC::Text::TAIT_UNKNOWN_10)); + if (DAT_MapPropertiesState::instance.year_copy != DAT_MapPropertiesState::instance.SEC_StartingYear) { + DAT_GameState::instance.mapAndTime.month = DAT_MapPropertiesState::instance.SEC_StartingMonth; + DAT_GameState::instance.mapAndTime.year = DAT_MapPropertiesState::instance.SEC_StartingYear; + } + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_MAP_EDITOR_PROPERTIES, 0); + return; + case 38: + // the trader settings; not on a siege map + if (DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 == OpenSHC::Map::MT_SIEGE) { + DAT_StopHandlingMenuItems::instance = 0; + return; + } + DAT_MapPropertiesState::instance.indexStored = 0; + MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::resetToTextIndex, DAT_UserTextHandlerState::ptr)( + OpenSHC::Text::TAIT_NINE__FILTER_B); + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(OpenSHC::UI::Enums::MMT_TRADER_SETTINGS, FALSE); + return; + case 41: { + char text[12]; + // the attacking force on a siege map, the starting goods otherwise + if (DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 == OpenSHC::Map::MT_SIEGE) { + // The attacking force's rows start at 20 + DAT_MapPropertiesState::instance.indexStored = 20; + MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::resetToTextIndex, + DAT_UserTextHandlerState::ptr)(OpenSHC::Text::TAIT_UNKNOWN_12); + // "%d" + MACRO_CALL(OpenSHC::OS_Func::_sprintf)(text, s__d_005aa7f0, + DAT_MapPropertiesState::instance + .SEC_SiegeInformation[DAT_MapPropertiesState::instance.indexStored - 20]); + MACRO_CALL_MEMBER( + OpenSHC::Text::UserTextHandler_Func::copyIntoTextArray, DAT_UserTextHandlerState::ptr)(text); + MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::resetToTextIndex, + DAT_UserTextHandlerState::ptr)(OpenSHC::Text::TAIT_NINE__FILTER_B); + DAT_MapPropertiesState::instance.DAT_MapEditorUnitPointsSum = MACRO_CALL_MEMBER( + OpenSHC::Map::MapPropertiesState_Func::sumUnitPoints, DAT_MapPropertiesState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(OpenSHC::UI::Enums::MMT_UNUSED_SIEGE_ATTACKING_FORCEUnk, FALSE); + return; + } + DAT_MapPropertiesState::instance.indexStored = 0; + MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::resetToTextIndex, DAT_UserTextHandlerState::ptr)( + OpenSHC::Text::TAIT_UNKNOWN_12); + // "%d" + MACRO_CALL(OpenSHC::OS_Func::_sprintf)(text, s__d_005aa7f0, + DAT_MapPropertiesState::instance.SEC_StartingResources[DAT_MissionAestheticsDefinedData::instance + .field_0x345c[DAT_MapPropertiesState::instance.indexStored]]); + MACRO_CALL_MEMBER( + OpenSHC::Text::UserTextHandler_Func::copyIntoTextArray, DAT_UserTextHandlerState::ptr)(text); + MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::resetToTextIndex, DAT_UserTextHandlerState::ptr)( + OpenSHC::Text::TAIT_NINE__FILTER_B); + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(OpenSHC::UI::Enums::MMT_START_GOODS, FALSE); + return; + } + case 79: + // the starting popularity slider; not on a siege map + if (DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 == OpenSHC::Map::MT_SIEGE) { + DAT_StopHandlingMenuItems::instance = 0; + return; + } + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::setSliderParameters, + DAT_MenuModalComposition2::ptr)(0, 100, DAT_MapPropertiesState::instance.SEC_StartingPopularity, + (undefined*)&DAT_MapPropertiesState::instance.SEC_StartingPopularity, + (void*)MACRO_CALL(OpenSHC::UI::Helpers_Func::SumUnitPoints)); + DAT_MenuModalComposition2::instance.textGroup = OpenSHC::DE::SHCDE::TEXT_SCENARIO; + // "Popularity" + DAT_MenuModalComposition2::instance.textIndex = 79; + MACRO_CALL_MEMBER( + OpenSHC::UI::MenuModalComposition_Func::setExtraActiveModalDialog, DAT_MenuModalComposition2::ptr)( + OpenSHC::UI::Enums::MMT_OVERLAY_SLIDER, DAT_ButtonX::instance - 2, DAT_ButtonY::instance + 25); + return; + case -1: + // the start month, from December round to January + ++DAT_MapPropertiesState::instance.SEC_StartingMonth; + if (DAT_MapPropertiesState::instance.SEC_StartingMonth >= 12) { + DAT_MapPropertiesState::instance.SEC_StartingMonth = 0; + } + DAT_GameState::instance.mapAndTime.month = DAT_MapPropertiesState::instance.SEC_StartingMonth; + DAT_GameState::instance.mapAndTime.year = DAT_MapPropertiesState::instance.SEC_StartingYear; + return; + case 42: { + char text[12]; + // a new invasion, on an invasion map + if (DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 != OpenSHC::Map::MT_INVASION) { + return; + } + DAT_MapPropertiesState::instance.currentEventID = DAT_MapPropertiesState::instance.eventsCount; + ++DAT_MapPropertiesState::instance.eventsCount; + DAT_MapPropertiesState::instance.editedEventType = 1; + MACRO_CALL_MEMBER(OpenSHC::Game::ScenarioEvents::InGameEventUnionVersion_Func::resetEvent, + &DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID])(); + DAT_MapPropertiesState::instance.SEC_StartingYear + = atol(MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::getTextArrayPointer, + DAT_UserTextHandlerState::ptr)(OpenSHC::Text::TAIT_UNKNOWN_10)); + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .header.year = DAT_MapPropertiesState::instance.SEC_StartingYear; + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .header.month = DAT_MapPropertiesState::instance.SEC_StartingMonth; + MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::resetToTextIndex, DAT_UserTextHandlerState::ptr)( + OpenSHC::Text::TAIT_UNKNOWN_14); + // "" + MACRO_CALL_MEMBER( + OpenSHC::Text::UserTextHandler_Func::copyIntoTextArray, DAT_UserTextHandlerState::ptr)(s__005a5339); + MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::resetToTextIndex, DAT_UserTextHandlerState::ptr)( + OpenSHC::Text::TAIT_UNKNOWN_11); + // "%d" + MACRO_CALL(OpenSHC::OS_Func::_sprintf)(text, s__d_005aa7f0, + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .header.year); + MACRO_CALL_MEMBER( + OpenSHC::Text::UserTextHandler_Func::copyIntoTextArray, DAT_UserTextHandlerState::ptr)(text); + DAT_MapPropertiesState::instance.field_0x1356c = 0; + DAT_MapPropertiesState::instance.offset = 0; + DAT_MapPropertiesState::instance.indexStored = 0; + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(OpenSHC::UI::Enums::MMT_NEW_INVASION, FALSE); + return; + } + case 43: { + char text[12]; + // a new event; not on a just-build map + if (DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 == OpenSHC::Map::MT_JUST_BUILD) { + return; + } + DAT_MapPropertiesState::instance.currentEventID = DAT_MapPropertiesState::instance.eventsCount; + ++DAT_MapPropertiesState::instance.eventsCount; + DAT_MapPropertiesState::instance.editedEventType = 3; + MACRO_CALL_MEMBER(OpenSHC::Game::ScenarioEvents::InGameEventUnionVersion_Func::initializeScenarioEvent, + &DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID])(); + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[0] + .enabled = 1; + // Written out (a for loop over 5 to 7: quick_diff 0.9573 -> 0.9001) + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[5] + .subType = 10; + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[6] + .subType = 10; + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[7] + .subType = 10; + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[17] + .subType = 10; + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[22] + .value = 5; + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[23] + .value = 5; + DAT_MapPropertiesState::instance.SEC_StartingYear + = atol(MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::getTextArrayPointer, + DAT_UserTextHandlerState::ptr)(OpenSHC::Text::TAIT_UNKNOWN_10)); + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .header.year = DAT_MapPropertiesState::instance.SEC_StartingYear; + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .header.month = DAT_MapPropertiesState::instance.SEC_StartingMonth; + DAT_MapPropertiesState::instance.invasionTroopIndex = 0; + DAT_MapPropertiesState::instance.flag = 1; + // fixme: the formatted year is not used (the original does the same, 0x004B86E5) + // "%d" + MACRO_CALL(OpenSHC::OS_Func::_sprintf)(text, s__d_005aa7f0, + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .header.year); + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(OpenSHC::UI::Enums::MMT_NEW_EVENT, FALSE); + return; + } + case 168: + // the attacking force's gold slider, on a siege map + // textGroup first (168, 169, 61): a shared tail (textIndex first: quick_diff 0.9573 -> 0.9197) + if (DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 != OpenSHC::Map::MT_SIEGE) { + return; + } + MACRO_CALL_MEMBER( + OpenSHC::UI::MenuModalComposition_Func::setSliderParameters, DAT_MenuModalComposition2::ptr)(0, + 10000, DAT_MapPropertiesState::instance.SEC_StartingResources[OpenSHC::Game::Resources::RT_GOLD], + (undefined*)&DAT_MapPropertiesState::instance + .SEC_StartingResources[OpenSHC::Game::Resources::RT_GOLD], + (void*)MACRO_CALL(OpenSHC::UI::Helpers_Func::SumUnitPoints)); + DAT_MenuModalComposition2::instance.textGroup = OpenSHC::DE::SHCDE::TEXT_SCENARIO; + // "Starting Gold" + DAT_MenuModalComposition2::instance.textIndex = 168; + MACRO_CALL_MEMBER( + OpenSHC::UI::MenuModalComposition_Func::setExtraActiveModalDialog, DAT_MenuModalComposition2::ptr)( + OpenSHC::UI::Enums::MMT_OVERLAY_SLIDER, DAT_ButtonX::instance - 2, DAT_ButtonY::instance + 25); + return; + case 169: + // the attacking force's partial pitch slider, on a siege map + if (DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 != OpenSHC::Map::MT_SIEGE) { + return; + } + MACRO_CALL_MEMBER( + OpenSHC::UI::MenuModalComposition_Func::setSliderParameters, DAT_MenuModalComposition2::ptr)(0, 100, + DAT_MapPropertiesState::instance.SEC_StartingResources[OpenSHC::Game::Resources::RT_PARTIALPITCH], + (undefined*)&DAT_MapPropertiesState::instance + .SEC_StartingResources[OpenSHC::Game::Resources::RT_PARTIALPITCH], + (void*)MACRO_CALL(OpenSHC::UI::Helpers_Func::SumUnitPoints)); + DAT_MenuModalComposition2::instance.textGroup = OpenSHC::DE::SHCDE::TEXT_SCENARIO; + // "Starting Pitch" + DAT_MenuModalComposition2::instance.textIndex = 169; + MACRO_CALL_MEMBER( + OpenSHC::UI::MenuModalComposition_Func::setExtraActiveModalDialog, DAT_MenuModalComposition2::ptr)( + OpenSHC::UI::Enums::MMT_OVERLAY_SLIDER, DAT_ButtonX::instance - 2, DAT_ButtonY::instance + 25); + return; + case 171: + // the building availability + DAT_MapPropertiesState::instance.DAT_BuildingAvailabilityScrollbarOffset = 0; + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(OpenSHC::UI::Enums::MMT_BUILDING_AVAILABILITY, FALSE); + return; + case 61: + // the scenario's gold slider, with the extra options on + if (!DAT_GameState::instance.mapAndTime.editScenarioExtraOptions) { + return; + } + DAT_CopyOfScenarioGold::instance = DAT_GameState::instance.mapAndTime.scenarioGold; + MACRO_CALL_MEMBER( + OpenSHC::UI::MenuModalComposition_Func::setSliderParameters, DAT_MenuModalComposition2::ptr)(0, + 10000, DAT_CopyOfScenarioGold::instance, (undefined*)DAT_CopyOfScenarioGold::ptr, + (void*)MACRO_CALL(OpenSHC::UI::Helpers_Func::RestoreScenarioGold)); + DAT_MenuModalComposition2::instance.textGroup = OpenSHC::DE::SHCDE::TEXT_SCENARIO; + // "Gold" + DAT_MenuModalComposition2::instance.textIndex = 61; + MACRO_CALL_MEMBER( + OpenSHC::UI::MenuModalComposition_Func::setExtraActiveModalDialog, DAT_MenuModalComposition2::ptr)( + OpenSHC::UI::Enums::MMT_OVERLAY_SLIDER, DAT_ButtonX::instance - 2, DAT_ButtonY::instance + 25); + return; + case 166: + // the rations setting, 0 to 4 and round again, with the extra options on + if (!DAT_GameState::instance.mapAndTime.editScenarioExtraOptions) { + return; + } + ++DAT_GameState::instance.mapAndTime.scenarioRationsSetting; + if (DAT_GameState::instance.mapAndTime.scenarioRationsSetting >= 5) { + DAT_GameState::instance.mapAndTime.scenarioRationsSetting = 0; + } + return; + case 167: + // the tax setting, 0 to 9 and round again, with the extra options on + if (!DAT_GameState::instance.mapAndTime.editScenarioExtraOptions) { + return; + } + ++DAT_GameState::instance.mapAndTime.scenarioTaxesSetting; + if (DAT_GameState::instance.mapAndTime.scenarioTaxesSetting >= 10) { + DAT_GameState::instance.mapAndTime.scenarioTaxesSetting = 0; + } + return; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 1ea91de334..89196826c5 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -27111,7 +27111,7 @@ SHC_3BB0A8C1_0x004B8200 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004B8210 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004B8220 | 0.0% | Pending +SHC_3BB0A8C1_0x004B8220 | 100.0% | Reimplemented, only the atol call target and the slider callbacks' resolver addresses differ SHC_3BB0A8C1_0x004B88A4 | 0.0% | Pending From 179de22a5ce8baea70c635e9fa407ad30eef4712 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 01:21:50 +0100 Subject: [PATCH 04/19] reimplement: SHC_3BB0A8C1_0x004C0860 100.0% Reimplemented MenuItemRenderFunction_NewEventAction_Main, rewritten from the binary (gynt's draft from his fork's reimpl/UI-MenuItems-development, 62.3% in #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 Co-Authored-By: Claude Opus 5.5 --- ...ItemRenderFunction_NewEventAction_Main.cpp | 224 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 225 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/NewEventAction/MenuItemRenderFunction_NewEventAction_Main.cpp diff --git a/src/OpenSHC/UI/MenuItems/NewEventAction/MenuItemRenderFunction_NewEventAction_Main.cpp b/src/OpenSHC/UI/MenuItems/NewEventAction/MenuItemRenderFunction_NewEventAction_Main.cpp new file mode 100644 index 0000000000..5869be4352 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/NewEventAction/MenuItemRenderFunction_NewEventAction_Main.cpp @@ -0,0 +1,224 @@ +#include "../NewEventAction.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/MenuModalComposition.func.hpp" +#include "OpenSHC/UI/Rendering.func.hpp" +#include "OpenSHC/UI/Rendering/AlphaAndButtonSurface.func.hpp" +#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eGM.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/string-literals.hpp" + +#include "OpenSHC/Globals/AlphaAndButtonSurfaceObj.hpp" +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonUnknownZero.hpp" +#include "OpenSHC/Globals/DAT_ButtonW.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition2.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x004C0860 + void NewEventAction::MenuItemRenderFunction_NewEventAction_Main(int button, ...) + { + DAT_ButtonUnknownZero::instance = FALSE; + // The row's text, and the button for the value (selectedButton first: quick_diff 0.9184 -> 0.9143) + int textNumber = button; + int const selectedButton = button; + int iconOffset = -1; + switch (button) { + // 38 to 40 show "Select Message" (text 40), each for one message action + case 37: + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderScenarioButtonWithText)(button); + return; + case 38: + // Lose & Message (27) + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.ScenarioEventType + == 27) { + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderScenarioButtonWithText)(button + 2); + return; + } + DAT_ButtonUnknownZero::instance = TRUE; + return; + case 39: + // Win & Message (26) + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.ScenarioEventType + == 26) { + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderScenarioButtonWithText)(button + 1); + return; + } + DAT_ButtonUnknownZero::instance = TRUE; + return; + case 40: + // Message (2) + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.ScenarioEventType + == 2) { + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderScenarioButtonWithText)(button); + return; + } + DAT_ButtonUnknownZero::instance = TRUE; + return; + // the action rows: 128 to 155 are event types 0 to 27, 177 to 187 are 28 to 38 + case 177: + case 178: + case 179: + case 180: + case 181: + case 182: + case 183: + case 184: + case 185: + case 186: + case 187: + button -= 21; + case 128: + case 129: + case 130: + case 131: + case 132: + case 133: + case 134: + case 135: + case 136: + case 137: + case 138: + case 139: + case 140: + case 141: + case 142: + case 143: + case 144: + case 145: + case 146: + case 147: + case 148: + case 149: + case 150: + case 151: + case 152: + case 153: + case 154: + case 155: + // "Archers" (148) is drawn as "Bandits" (146) with the other icon + if (textNumber == 148) { + textNumber = 146; + iconOffset = 0; + } else if (textNumber == 146) { + iconOffset = 2; + } + if (button - 128 + == DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.ScenarioEventType) { + DAT_ButtonCurrentlyInteracting::instance = TRUE; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_SCENARIO, textNumber, DAT_ButtonX::instance + 14, + DAT_ButtonY::instance + 7, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, + FALSE); + if (iconOffset > -1) { + // " - " + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, + DAT_TextManagerObject::ptr)(s___005a2304, DAT_ButtonX::instance + 20, + DAT_ButtonY::instance + 7, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_CCFAFF, + 18, TRUE, 0); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2, iconOffset + 128, + DAT_TextManagerObject::instance.currentXOffset_0x0 + DAT_ButtonX::instance + 23, + DAT_ButtonY::instance + 3); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_MAP_GAME; + } + if (DAT_MapPropertiesState::instance.sliderPopupDelay != 0) { + --DAT_MapPropertiesState::instance.sliderPopupDelay; + if (DAT_MapPropertiesState::instance.sliderPopupDelay == 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::setExtraActiveModalDialog, + DAT_MenuModalComposition2::ptr)(OpenSHC::UI::Enums::MMT_OVERLAY_SLIDER, + DAT_MapPropertiesState::instance.sliderPopupX, + DAT_MapPropertiesState::instance.sliderPopupY); + } + } + switch (selectedButton) { + case 132: + case 139: + case 145: + case 146: + case 148: + case 179: + MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.actionData, + DAT_ButtonW::instance + DAT_ButtonX::instance - 14, DAT_ButtonY::instance + 7, + OpenSHC::Text::TTA_RIGHT, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, 0); + return; + case 178: + // "%" + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, + DAT_TextManagerObject::ptr)(s_percentage_005a2770, + DAT_ButtonW::instance + DAT_ButtonX::instance - 14, DAT_ButtonY::instance + 7, + OpenSHC::Text::TTA_RIGHT, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, 0); + MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.actionData, + DAT_ButtonW::instance + DAT_ButtonX::instance - 28, DAT_ButtonY::instance + 7, + OpenSHC::Text::TTA_RIGHT, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, 0); + return; + } + return; + } + // The same draw in both branches (one draw without the test: quick_diff 0.9184 -> 0.7731) + if (!DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_SCENARIO, textNumber, DAT_ButtonX::instance + 14, + DAT_ButtonY::instance + 7, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_C2F0EB, 18, + FALSE); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_SCENARIO, textNumber, DAT_ButtonX::instance + 14, + DAT_ButtonY::instance + 7, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_C2F0EB, 18, + FALSE); + } + if (iconOffset > -1) { + // " - " + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + s___005a2304, DAT_ButtonX::instance + 20, DAT_ButtonY::instance + 7, OpenSHC::Text::TTA_LEFT, + OpenSHC::Rendering::Colors::COL_C2F0EB, 18, TRUE, 0); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2, iconOffset + 128, + DAT_TextManagerObject::instance.currentXOffset_0x0 + DAT_ButtonX::instance + 23, + DAT_ButtonY::instance + 3); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_MAP_GAME; + } + return; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 89196826c5..3ec968a220 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -32765,7 +32765,7 @@ SHC_3BB0A8C1_0x004C085C | 0.0% | Pending SHC_3BB0A8C1_0x004C085D | 0.0% | Pending -SHC_3BB0A8C1_0x004C0860 | 0.0% | Pending +SHC_3BB0A8C1_0x004C0860 | 100.0% | Reimplemented, only the RenderScenarioButtonWithText tail call targets differ SHC_3BB0A8C1_0x004C0BF8 | 0.0% | Pending From 35925f144fc3d5151d8a499d5fedf016b1682231 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 01:21:51 +0100 Subject: [PATCH 05/19] reimplement: SHC_3BB0A8C1_0x004266E0 100.0% Reimplemented 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 Co-Authored-By: Claude Opus 5.5 --- .../MenuModalRenderFunction_UnusedSetName.cpp | 34 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuModals/UnusedSetName/MenuModalRenderFunction_UnusedSetName.cpp diff --git a/src/OpenSHC/UI/MenuModals/UnusedSetName/MenuModalRenderFunction_UnusedSetName.cpp b/src/OpenSHC/UI/MenuModals/UnusedSetName/MenuModalRenderFunction_UnusedSetName.cpp new file mode 100644 index 0000000000..2604e68591 --- /dev/null +++ b/src/OpenSHC/UI/MenuModals/UnusedSetName/MenuModalRenderFunction_UnusedSetName.cpp @@ -0,0 +1,34 @@ +#include "../UnusedSetName.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/Text/TextAlignment.hpp" +#include "OpenSHC/UI/Enums/RoundedBoxEdgeRoundingLevel.hpp" + +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuModals { + + // FUNCTION: STRONGHOLDCRUSADER 0x004266E0 + void UnusedSetName::MenuModalRenderFunction_UnusedSetName(int x, int y, int width, int height) + { + // a 400 pixel wide title box in the middle of the dialog + int const margin = (width - 400) / 2; + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBoxWithRoundedEdges, DAT_PencilRenderCore::ptr)( + margin + x, y + 10, x - margin + width, y + 60, OpenSHC::UI::Enums::RBERL_STRONG); + // "Enter Your Title" + 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_MAINOPTIONS, 6), + width / 2 + x, y + 15, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, 15, FALSE, 0); + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 3ec968a220..87fd7e910e 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -6771,7 +6771,7 @@ SHC_3BB0A8C1_0x00426600 | 0.0% | Pending SHC_3BB0A8C1_0x004266A0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004266E0 | 0.0% | Pending +SHC_3BB0A8C1_0x004266E0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00426750 | 100.0% | Reimplemented From 3b921b798d112ff69e617ad2a6315723630f1489 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 01:21:52 +0100 Subject: [PATCH 06/19] reimplement: SHC_3BB0A8C1_0x004ABAB0 100.0% Reimplemented 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 Co-Authored-By: Claude Opus 5.5 --- ...MenuModalRenderFunction_NewEventAction.cpp | 55 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuModals/NewEventAction/MenuModalRenderFunction_NewEventAction.cpp diff --git a/src/OpenSHC/UI/MenuModals/NewEventAction/MenuModalRenderFunction_NewEventAction.cpp b/src/OpenSHC/UI/MenuModals/NewEventAction/MenuModalRenderFunction_NewEventAction.cpp new file mode 100644 index 0000000000..8edc795ce0 --- /dev/null +++ b/src/OpenSHC/UI/MenuModals/NewEventAction/MenuModalRenderFunction_NewEventAction.cpp @@ -0,0 +1,55 @@ +#include "../NewEventAction.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/Text/TextAlignment.hpp" + +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuModals { + + // FUNCTION: STRONGHOLDCRUSADER 0x004ABAB0 + void NewEventAction::MenuModalRenderFunction_NewEventAction(int x, int y, int width, int height) + { + // "Event Actions" + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawHeaderTextBanner, + DAT_PencilRenderCore::ptr)(OpenSHC::DE::SHCDE::TEXT_SCENARIO, 103, x, y, width, height); + // the actions that repeat label their two fields + switch (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.ScenarioEventType) { + case 5: + case 11: + case 12: + case 13: + case 14: + case 15: + case 16: + case 17: + case 18: + case 19: + case 20: + case 29: + case 30: + // "Repeat (months)" + 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_SCENARIO, 175), + x + 390, y + 461, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, 0); + // "Repeat Count" + 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_SCENARIO, 176), + x + 390, y + 496, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, 0); + break; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 87fd7e910e..0e2ae26e7f 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -25559,7 +25559,7 @@ SHC_3BB0A8C1_0x004AB790 | 0.0% | Pending SHC_3BB0A8C1_0x004ABA20 | 0.0% | Pending -SHC_3BB0A8C1_0x004ABAB0 | 0.0% | Pending +SHC_3BB0A8C1_0x004ABAB0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004ABB70 | 0.0% | Pending From 6ad389de8dc3a16bf76c1eea8b55d43abebfd783 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 02:43:26 +0100 Subject: [PATCH 07/19] headers: ScenarioEventType enum for the scenario event types 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 --- .../Enums/ScenarioEventType.hpp | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/OpenSHC/Game/ScenarioEvents/Enums/ScenarioEventType.hpp diff --git a/src/OpenSHC/Game/ScenarioEvents/Enums/ScenarioEventType.hpp b/src/OpenSHC/Game/ScenarioEvents/Enums/ScenarioEventType.hpp new file mode 100644 index 0000000000..1f4dd7ce9b --- /dev/null +++ b/src/OpenSHC/Game/ScenarioEvents/Enums/ScenarioEventType.hpp @@ -0,0 +1,65 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Game/ScenarioEvents/Enums/ScenarioEventType.hpp' +*/ + +#pragma once + +namespace OpenSHC { +namespace Game { + namespace ScenarioEvents { + namespace Enums { + // IngameScenarioEventItemContent::ScenarioEventType; the names are cr.tex scenario texts 128-155 and + // 177-187 + typedef enum ScenarioEventType { + + SET_WIN = 0, // 0x00000000 + SET_LOSE = 1, // 0x00000001 + SET_MESSAGE = 2, // 0x00000002 + SET_LION_SLEEPS = 3, // 0x00000003 + SET_LION_AWAKES = 4, // 0x00000004 + SET_TRAVELING_FAIR = 5, // 0x00000005 + SET_TIME_OFF = 6, // 0x00000006 + SET_TIME_ON = 7, // 0x00000007 + SET_CEDE_CASTLE = 8, // 0x00000008 + SET_CROSSBOW_AVAILABLE = 9, // 0x00000009 + SET_MESSAGE_10 = 10, // 0x0000000A + SET_PLAGUE = 11, // 0x0000000B + SET_WHEAT_DISEASE = 12, // 0x0000000C + SET_HOPS_WEEVIL = 13, // 0x0000000D + SET_APPLE_BLIGHT = 14, // 0x0000000E + SET_TREE_FUNGUS = 15, // 0x0000000F + SET_RABBIT_EXPLOSION = 16, // 0x00000010 + SET_LION_ATTACK = 17, // 0x00000011 + SET_BANDITS = 18, // 0x00000012 + SET_MAD_COWS = 19, // 0x00000013 + SET_ARCHERS = 20, // 0x00000014 + SET_MARRIAGE = 21, // 0x00000015 + SET_JESTER = 22, // 0x00000016 + SET_MISSION_SPECIAL = 23, // 0x00000017 + SET_AUTO_BINKS_ON = 24, // 0x00000018 + SET_AUTO_BINKS_OFF = 25, // 0x00000019 + SET_WIN_AND_MESSAGE = 26, // 0x0000001A + SET_LOSE_AND_MESSAGE = 27, // 0x0000001B + SET_TURN_OFF_REPEATING_INVASIONS = 28, // 0x0000001C + SET_THEFT_FROM_GRANARY = 29, // 0x0000001D + SET_FIRE = 30, // 0x0000001E + SET_UNKNOWN_31 = 31, // 0x0000001F + SET_UNKNOWN_32 = 32, // 0x00000020 + SET_UNKNOWN_33 = 33, // 0x00000021 + SET_UNKNOWN_34 = 34, // 0x00000022 + SET_UNKNOWN_35 = 35, // 0x00000023 + SET_UNKNOWN_36 = 36, // 0x00000024 + SET_UNKNOWN_37 = 37, // 0x00000025 + SET_UNKNOWN_38 = 38 // 0x00000026 + + } ScenarioEventType; + + static_assert_cpp98_obj(sizeof(ScenarioEventType) == 4, ScenarioEventType); + } // namespace Enums + } // namespace ScenarioEvents +} // namespace Game +} // namespace OpenSHC From ce5a0361791b2756f3c53ecb004529c08e3ee70b Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 02:43:26 +0100 Subject: [PATCH 08/19] headers: ScenarioEventConditionIndex enum for the 40 event conditions 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 --- .../Enums/ScenarioEventConditionIndex.hpp | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/OpenSHC/Game/ScenarioEvents/Enums/ScenarioEventConditionIndex.hpp diff --git a/src/OpenSHC/Game/ScenarioEvents/Enums/ScenarioEventConditionIndex.hpp b/src/OpenSHC/Game/ScenarioEvents/Enums/ScenarioEventConditionIndex.hpp new file mode 100644 index 0000000000..9e4c30d3c1 --- /dev/null +++ b/src/OpenSHC/Game/ScenarioEvents/Enums/ScenarioEventConditionIndex.hpp @@ -0,0 +1,66 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Game/ScenarioEvents/Enums/ScenarioEventConditionIndex.hpp' +*/ + +#pragma once + +namespace OpenSHC { +namespace Game { + namespace ScenarioEvents { + namespace Enums { + // Index into IngameScenarioEventItemContent::conditions and the EventCondition* tables; the names are + // cr.tex scenario texts 106-125 and 190-209 + typedef enum ScenarioEventConditionIndex { + + SECI_AUTO_STOP = 0, // 0x00000000 + SECI_POPULATION = 1, // 0x00000001 + SECI_LORD_KILLED = 2, // 0x00000002 + SECI_ENEMY_LORD_KILLED = 3, // 0x00000003 + SECI_GOLD_ACQUIRED = 4, // 0x00000004 + SECI_FOOD_ACQUIRED = 5, // 0x00000005 + SECI_WEAPONS_ACQUIRED = 6, // 0x00000006 + SECI_GOODS_ACQUIRED = 7, // 0x00000007 + SECI_NO_ENEMY_AND_INVASIONS_LEFT = 8, // 0x00000008 + SECI_KEEP_ENCLOSED = 9, // 0x00000009 + SECI_NO_LIONS_ON_MAP = 10, // 0x0000000A + SECI_ANY_ENEMY_ON_MAP = 11, // 0x0000000B + SECI_NO_PEOPLE_LEFT = 12, // 0x0000000C + SECI_YOUR_TROOPS_KILLED = 13, // 0x0000000D + SECI_ENEMY_TROOPS_KILLED = 14, // 0x0000000E + SECI_NO_ENEMY_ON_MAP = 15, // 0x0000000F + SECI_CATHEDRAL_DESTROYED = 16, // 0x00000010 + SECI_WEAPONS_ACQUIRED_17 = 17, // 0x00000011 + SECI_4_CATTLE_FARMS = 18, // 0x00000012 + SECI_2_INNS = 19, // 0x00000013 + SECI_PERCENT_BLESSED = 20, // 0x00000014 + SECI_PERCENT_DRINKING_ALE = 21, // 0x00000015 + SECI_MAXIMUM_CRUELTY = 22, // 0x00000016 + SECI_MAXIMUM_PLEASANTNESS = 23, // 0x00000017 + SECI_UNKNOWN_24 = 24, // 0x00000018 + SECI_UNKNOWN_25 = 25, // 0x00000019 + SECI_UNKNOWN_26 = 26, // 0x0000001A + SECI_UNKNOWN_27 = 27, // 0x0000001B + SECI_UNKNOWN_28 = 28, // 0x0000001C + SECI_UNKNOWN_29 = 29, // 0x0000001D + SECI_UNKNOWN_30 = 30, // 0x0000001E + SECI_UNKNOWN_31 = 31, // 0x0000001F + SECI_UNKNOWN_32 = 32, // 0x00000020 + SECI_UNKNOWN_33 = 33, // 0x00000021 + SECI_UNKNOWN_34 = 34, // 0x00000022 + SECI_UNKNOWN_35 = 35, // 0x00000023 + SECI_UNKNOWN_36 = 36, // 0x00000024 + SECI_UNKNOWN_37 = 37, // 0x00000025 + SECI_UNKNOWN_38 = 38, // 0x00000026 + SECI_WIN_TIMER = 39 // 0x00000027 + + } ScenarioEventConditionIndex; + + static_assert_cpp98_obj(sizeof(ScenarioEventConditionIndex) == 4, ScenarioEventConditionIndex); + } // namespace Enums + } // namespace ScenarioEvents +} // namespace Game +} // namespace OpenSHC From a51fffdcd8fc4b982f0b0fc819ea9764f2095ed1 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 02:43:26 +0100 Subject: [PATCH 09/19] headers: MapPropertiesState::flag is a BOOLEnum 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 --- src/OpenSHC/Map/MapPropertiesState.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenSHC/Map/MapPropertiesState.hpp b/src/OpenSHC/Map/MapPropertiesState.hpp index 5aead0c5ec..ac3242f0a0 100644 --- a/src/OpenSHC/Map/MapPropertiesState.hpp +++ b/src/OpenSHC/Map/MapPropertiesState.hpp @@ -78,7 +78,7 @@ namespace Map { int field_0x1356c; // 0x0001356C length: 4 undefined4 invasionTroopIndex; // 0x00013570 length: 4 int DAT_BuildingAvailabilityScrollbarOffset; // 0x00013574 length: 4 - undefined4 flag; // 0x00013578 length: 4 + BOOLEnum flag; // 0x00013578 length: 4 int offset; // 0x0001357C length: 4 int indexStored; // 0x00013580 length: 4 int selectedAbsoluteIndex; // 0x00013584 length: 4 From 7e208ed8b15c5d365c5211db2e4ed22bd5010b08 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 02:43:27 +0100 Subject: [PATCH 10/19] headers: MenuModalComposition::setSliderParameters takes int* and a void() 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 #327 and batch4-development that call it with the old casts will need the same edit. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/UI/MenuModalComposition.func.hpp | 2 +- src/OpenSHC/UI/MenuModalComposition.hpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/UI/MenuModalComposition.func.hpp b/src/OpenSHC/UI/MenuModalComposition.func.hpp index 27cb7835ba..f9f47f44ee 100644 --- a/src/OpenSHC/UI/MenuModalComposition.func.hpp +++ b/src/OpenSHC/UI/MenuModalComposition.func.hpp @@ -44,7 +44,7 @@ namespace UI { Address::SHC_3BB0A8C1_0x004AA3E0, &MenuModalComposition::fillWithMenuModalDimensions) fillWithMenuModalDimensions; - MACRO_FUNCTION_RESOLVER(void (MenuModalComposition::*)(int, int, int, undefined*, void*), false, + MACRO_FUNCTION_RESOLVER(void (MenuModalComposition::*)(int, int, int, int*, void(__cdecl*)()), false, Address::SHC_3BB0A8C1_0x004AA480, &MenuModalComposition::setSliderParameters) setSliderParameters; diff --git a/src/OpenSHC/UI/MenuModalComposition.hpp b/src/OpenSHC/UI/MenuModalComposition.hpp index 1e62eb360a..4fe94c14bf 100644 --- a/src/OpenSHC/UI/MenuModalComposition.hpp +++ b/src/OpenSHC/UI/MenuModalComposition.hpp @@ -71,7 +71,8 @@ namespace UI { void fillWithMenuModalDimensions(int* xPtr, int* yPtr, int* widthPtr, int* heigthPtr); - void setSliderParameters(int minimum, int maximum, int value, undefined* destination, void* callbackFunction); + void setSliderParameters( + int minimum, int maximum, int value, int* destination, void(__cdecl* callbackFunction)()); void setSliderParameters2( dword minimum, dword maximum, dword value, dword destination, undefined* callbackFunction); From 014186a3015c22488e184d2a99be0967e7a0c42a Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 03:10:08 +0100 Subject: [PATCH 11/19] reimplement: three functions use the new header names TheRedDaemon's review of #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 --- ...onHandler_EditScenario_BaseMenuButtons.cpp | 38 +++++++++---------- ...ItemRenderFunction_NewEventAction_Main.cpp | 10 ++--- ...mRenderFunction_NewEventCondition_Main.cpp | 21 +++++----- status/addresses-SHC-3BB0A8C1.txt | 6 +-- 4 files changed, 36 insertions(+), 39 deletions(-) diff --git a/src/OpenSHC/UI/MenuItems/EditScenario/MenuItemActionHandler_EditScenario_BaseMenuButtons.cpp b/src/OpenSHC/UI/MenuItems/EditScenario/MenuItemActionHandler_EditScenario_BaseMenuButtons.cpp index 2ab926a839..3ce720bf3b 100644 --- a/src/OpenSHC/UI/MenuItems/EditScenario/MenuItemActionHandler_EditScenario_BaseMenuButtons.cpp +++ b/src/OpenSHC/UI/MenuItems/EditScenario/MenuItemActionHandler_EditScenario_BaseMenuButtons.cpp @@ -9,6 +9,7 @@ #include "OpenSHC/UI/MenuModalComposition.func.hpp" #include "OpenSHC/DE/SHCDE/eTextSections.hpp" #include "OpenSHC/Game/Resources/ResourceType.hpp" +#include "OpenSHC/Game/ScenarioEvents/Enums/ScenarioEventConditionIndex.hpp" #include "OpenSHC/Map/MapType2.hpp" #include "OpenSHC/Text/TextArrayIndexType.hpp" #include "OpenSHC/UI/Enums/MenuModalType.hpp" @@ -109,8 +110,8 @@ namespace UI { } MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::setSliderParameters, DAT_MenuModalComposition2::ptr)(0, 100, DAT_MapPropertiesState::instance.SEC_StartingPopularity, - (undefined*)&DAT_MapPropertiesState::instance.SEC_StartingPopularity, - (void*)MACRO_CALL(OpenSHC::UI::Helpers_Func::SumUnitPoints)); + &DAT_MapPropertiesState::instance.SEC_StartingPopularity, + MACRO_CALL(OpenSHC::UI::Helpers_Func::SumUnitPoints)); DAT_MenuModalComposition2::instance.textGroup = OpenSHC::DE::SHCDE::TEXT_SCENARIO; // "Popularity" DAT_MenuModalComposition2::instance.textIndex = 79; @@ -179,26 +180,26 @@ namespace UI { &DAT_MapPropertiesState::instance .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID])(); DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] - .data.scenario.conditions[0] + .data.scenario.conditions[OpenSHC::Game::ScenarioEvents::Enums::SECI_AUTO_STOP] .enabled = 1; // Written out (a for loop over 5 to 7: quick_diff 0.9573 -> 0.9001) DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] - .data.scenario.conditions[5] + .data.scenario.conditions[OpenSHC::Game::ScenarioEvents::Enums::SECI_FOOD_ACQUIRED] .subType = 10; DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] - .data.scenario.conditions[6] + .data.scenario.conditions[OpenSHC::Game::ScenarioEvents::Enums::SECI_WEAPONS_ACQUIRED] .subType = 10; DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] - .data.scenario.conditions[7] + .data.scenario.conditions[OpenSHC::Game::ScenarioEvents::Enums::SECI_GOODS_ACQUIRED] .subType = 10; DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] - .data.scenario.conditions[17] + .data.scenario.conditions[OpenSHC::Game::ScenarioEvents::Enums::SECI_WEAPONS_ACQUIRED_17] .subType = 10; DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] - .data.scenario.conditions[22] + .data.scenario.conditions[OpenSHC::Game::ScenarioEvents::Enums::SECI_MAXIMUM_CRUELTY] .value = 5; DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] - .data.scenario.conditions[23] + .data.scenario.conditions[OpenSHC::Game::ScenarioEvents::Enums::SECI_MAXIMUM_PLEASANTNESS] .value = 5; DAT_MapPropertiesState::instance.SEC_StartingYear = atol(MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::getTextArrayPointer, @@ -208,7 +209,7 @@ namespace UI { DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] .header.month = DAT_MapPropertiesState::instance.SEC_StartingMonth; DAT_MapPropertiesState::instance.invasionTroopIndex = 0; - DAT_MapPropertiesState::instance.flag = 1; + DAT_MapPropertiesState::instance.flag = TRUE; // fixme: the formatted year is not used (the original does the same, 0x004B86E5) // "%d" MACRO_CALL(OpenSHC::OS_Func::_sprintf)(text, s__d_005aa7f0, @@ -227,9 +228,8 @@ namespace UI { MACRO_CALL_MEMBER( OpenSHC::UI::MenuModalComposition_Func::setSliderParameters, DAT_MenuModalComposition2::ptr)(0, 10000, DAT_MapPropertiesState::instance.SEC_StartingResources[OpenSHC::Game::Resources::RT_GOLD], - (undefined*)&DAT_MapPropertiesState::instance - .SEC_StartingResources[OpenSHC::Game::Resources::RT_GOLD], - (void*)MACRO_CALL(OpenSHC::UI::Helpers_Func::SumUnitPoints)); + &DAT_MapPropertiesState::instance.SEC_StartingResources[OpenSHC::Game::Resources::RT_GOLD], + MACRO_CALL(OpenSHC::UI::Helpers_Func::SumUnitPoints)); DAT_MenuModalComposition2::instance.textGroup = OpenSHC::DE::SHCDE::TEXT_SCENARIO; // "Starting Gold" DAT_MenuModalComposition2::instance.textIndex = 168; @@ -245,9 +245,8 @@ namespace UI { MACRO_CALL_MEMBER( OpenSHC::UI::MenuModalComposition_Func::setSliderParameters, DAT_MenuModalComposition2::ptr)(0, 100, DAT_MapPropertiesState::instance.SEC_StartingResources[OpenSHC::Game::Resources::RT_PARTIALPITCH], - (undefined*)&DAT_MapPropertiesState::instance - .SEC_StartingResources[OpenSHC::Game::Resources::RT_PARTIALPITCH], - (void*)MACRO_CALL(OpenSHC::UI::Helpers_Func::SumUnitPoints)); + &DAT_MapPropertiesState::instance.SEC_StartingResources[OpenSHC::Game::Resources::RT_PARTIALPITCH], + MACRO_CALL(OpenSHC::UI::Helpers_Func::SumUnitPoints)); DAT_MenuModalComposition2::instance.textGroup = OpenSHC::DE::SHCDE::TEXT_SCENARIO; // "Starting Pitch" DAT_MenuModalComposition2::instance.textIndex = 169; @@ -267,10 +266,9 @@ namespace UI { return; } DAT_CopyOfScenarioGold::instance = DAT_GameState::instance.mapAndTime.scenarioGold; - MACRO_CALL_MEMBER( - OpenSHC::UI::MenuModalComposition_Func::setSliderParameters, DAT_MenuModalComposition2::ptr)(0, - 10000, DAT_CopyOfScenarioGold::instance, (undefined*)DAT_CopyOfScenarioGold::ptr, - (void*)MACRO_CALL(OpenSHC::UI::Helpers_Func::RestoreScenarioGold)); + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::setSliderParameters, + DAT_MenuModalComposition2::ptr)(0, 10000, DAT_CopyOfScenarioGold::instance, + DAT_CopyOfScenarioGold::ptr, MACRO_CALL(OpenSHC::UI::Helpers_Func::RestoreScenarioGold)); DAT_MenuModalComposition2::instance.textGroup = OpenSHC::DE::SHCDE::TEXT_SCENARIO; // "Gold" DAT_MenuModalComposition2::instance.textIndex = 61; diff --git a/src/OpenSHC/UI/MenuItems/NewEventAction/MenuItemRenderFunction_NewEventAction_Main.cpp b/src/OpenSHC/UI/MenuItems/NewEventAction/MenuItemRenderFunction_NewEventAction_Main.cpp index 5869be4352..0312429075 100644 --- a/src/OpenSHC/UI/MenuItems/NewEventAction/MenuItemRenderFunction_NewEventAction_Main.cpp +++ b/src/OpenSHC/UI/MenuItems/NewEventAction/MenuItemRenderFunction_NewEventAction_Main.cpp @@ -7,6 +7,7 @@ #include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" #include "OpenSHC/DE/SHCDE/eGM.hpp" #include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Game/ScenarioEvents/Enums/ScenarioEventType.hpp" #include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" #include "OpenSHC/Rendering/Enums/RenderTarget.hpp" #include "OpenSHC/Text/TextAlignment.hpp" @@ -42,30 +43,27 @@ namespace UI { MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderScenarioButtonWithText)(button); return; case 38: - // Lose & Message (27) if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] .data.scenario.ScenarioEventType - == 27) { + == OpenSHC::Game::ScenarioEvents::Enums::SET_LOSE_AND_MESSAGE) { MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderScenarioButtonWithText)(button + 2); return; } DAT_ButtonUnknownZero::instance = TRUE; return; case 39: - // Win & Message (26) if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] .data.scenario.ScenarioEventType - == 26) { + == OpenSHC::Game::ScenarioEvents::Enums::SET_WIN_AND_MESSAGE) { MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderScenarioButtonWithText)(button + 1); return; } DAT_ButtonUnknownZero::instance = TRUE; return; case 40: - // Message (2) if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] .data.scenario.ScenarioEventType - == 2) { + == OpenSHC::Game::ScenarioEvents::Enums::SET_MESSAGE) { MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderScenarioButtonWithText)(button); return; } diff --git a/src/OpenSHC/UI/MenuItems/NewEventCondition/MenuItemRenderFunction_NewEventCondition_Main.cpp b/src/OpenSHC/UI/MenuItems/NewEventCondition/MenuItemRenderFunction_NewEventCondition_Main.cpp index be94c62f41..9c1c9f0a0c 100644 --- a/src/OpenSHC/UI/MenuItems/NewEventCondition/MenuItemRenderFunction_NewEventCondition_Main.cpp +++ b/src/OpenSHC/UI/MenuItems/NewEventCondition/MenuItemRenderFunction_NewEventCondition_Main.cpp @@ -5,6 +5,7 @@ #include "OpenSHC/UI/Rendering/AlphaAndButtonSurface.func.hpp" #include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" #include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Game/ScenarioEvents/Enums/ScenarioEventConditionIndex.hpp" #include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" #include "OpenSHC/Rendering/Enums/RenderTarget.hpp" #include "OpenSHC/Text/TextAlignment.hpp" @@ -86,52 +87,52 @@ namespace UI { // "Win Timer" (row 39) only while one of these conditions is on: else DAT_ButtonUnknownZero BOOLEnum anyEnabled = FALSE; if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] - .data.scenario.conditions[1] + .data.scenario.conditions[OpenSHC::Game::ScenarioEvents::Enums::SECI_POPULATION] .enabled) { anyEnabled = TRUE; } if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] - .data.scenario.conditions[4] + .data.scenario.conditions[OpenSHC::Game::ScenarioEvents::Enums::SECI_GOLD_ACQUIRED] .enabled) { anyEnabled = TRUE; // Written out (a loop over 4 to 7: quick_diff 0.9440 -> 0.8543) } if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] - .data.scenario.conditions[5] + .data.scenario.conditions[OpenSHC::Game::ScenarioEvents::Enums::SECI_FOOD_ACQUIRED] .enabled) { anyEnabled = TRUE; } if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] - .data.scenario.conditions[6] + .data.scenario.conditions[OpenSHC::Game::ScenarioEvents::Enums::SECI_WEAPONS_ACQUIRED] .enabled) { anyEnabled = TRUE; } if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] - .data.scenario.conditions[7] + .data.scenario.conditions[OpenSHC::Game::ScenarioEvents::Enums::SECI_GOODS_ACQUIRED] .enabled) { anyEnabled = TRUE; } if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] - .data.scenario.conditions[17] + .data.scenario.conditions[OpenSHC::Game::ScenarioEvents::Enums::SECI_WEAPONS_ACQUIRED_17] .enabled) { anyEnabled = TRUE; } if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] - .data.scenario.conditions[20] + .data.scenario.conditions[OpenSHC::Game::ScenarioEvents::Enums::SECI_PERCENT_BLESSED] .enabled) { anyEnabled = TRUE; // Written out (a loop over 20 to 22: quick_diff 0.9440 -> 0.8708) } if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] - .data.scenario.conditions[21] + .data.scenario.conditions[OpenSHC::Game::ScenarioEvents::Enums::SECI_PERCENT_DRINKING_ALE] .enabled) { anyEnabled = TRUE; } if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] - .data.scenario.conditions[22] + .data.scenario.conditions[OpenSHC::Game::ScenarioEvents::Enums::SECI_MAXIMUM_CRUELTY] .enabled) { anyEnabled = TRUE; } if (!DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] - .data.scenario.conditions[23] + .data.scenario.conditions[OpenSHC::Game::ScenarioEvents::Enums::SECI_MAXIMUM_PLEASANTNESS] .enabled && !anyEnabled) { DAT_ButtonUnknownZero::instance = TRUE; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index f397c73f95..939870b1a6 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -27111,7 +27111,7 @@ SHC_3BB0A8C1_0x004B8200 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004B8210 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004B8220 | 100.0% | Reimplemented, only the atol call target and the slider callbacks' resolver addresses differ +SHC_3BB0A8C1_0x004B8220 | 100.0% | Reimplemented, only the atol call target differs (and the slider callbacks while the SumUnitPoints and RestoreScenarioGold resolvers are off) SHC_3BB0A8C1_0x004B88A4 | 0.0% | Pending @@ -32329,7 +32329,7 @@ SHC_3BB0A8C1_0x004C01A5 | 0.0% | Pending SHC_3BB0A8C1_0x004C01A6 | 0.0% | Pending -SHC_3BB0A8C1_0x004C01B0 | 100.0% | Reimplemented, only the RenderScenarioButtonWithText tail call targets differ +SHC_3BB0A8C1_0x004C01B0 | 100.0% | Reimplemented, only the RenderScenarioButtonWithText tail call targets differ, while its resolver is off SHC_3BB0A8C1_0x004C0770 | 0.0% | Pending @@ -32765,7 +32765,7 @@ SHC_3BB0A8C1_0x004C085C | 0.0% | Pending SHC_3BB0A8C1_0x004C085D | 0.0% | Pending -SHC_3BB0A8C1_0x004C0860 | 100.0% | Reimplemented, only the RenderScenarioButtonWithText tail call targets differ +SHC_3BB0A8C1_0x004C0860 | 100.0% | Reimplemented, only the RenderScenarioButtonWithText tail call targets differ, while its resolver is off SHC_3BB0A8C1_0x004C0BF8 | 0.0% | Pending From 24e4699da0fd3952fc239c33e1f95641b19c624c Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 19:58:28 +0100 Subject: [PATCH 12/19] headers: MenuModalComposition::setSliderParameters takes a NoArgCallback* 7e208ed8b 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). 7e208ed8b 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 --- src/OpenSHC/UI/MenuModalComposition.func.hpp | 2 +- src/OpenSHC/UI/MenuModalComposition.hpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/UI/MenuModalComposition.func.hpp b/src/OpenSHC/UI/MenuModalComposition.func.hpp index f9f47f44ee..3825d5a2d9 100644 --- a/src/OpenSHC/UI/MenuModalComposition.func.hpp +++ b/src/OpenSHC/UI/MenuModalComposition.func.hpp @@ -44,7 +44,7 @@ namespace UI { Address::SHC_3BB0A8C1_0x004AA3E0, &MenuModalComposition::fillWithMenuModalDimensions) fillWithMenuModalDimensions; - MACRO_FUNCTION_RESOLVER(void (MenuModalComposition::*)(int, int, int, int*, void(__cdecl*)()), false, + MACRO_FUNCTION_RESOLVER(void (MenuModalComposition::*)(int, int, int, int*, NoArgCallback*), false, Address::SHC_3BB0A8C1_0x004AA480, &MenuModalComposition::setSliderParameters) setSliderParameters; diff --git a/src/OpenSHC/UI/MenuModalComposition.hpp b/src/OpenSHC/UI/MenuModalComposition.hpp index 4fe94c14bf..5af858aef6 100644 --- a/src/OpenSHC/UI/MenuModalComposition.hpp +++ b/src/OpenSHC/UI/MenuModalComposition.hpp @@ -11,6 +11,7 @@ #include "OpenSHC/UI/Enums/MenuModalType.hpp" #include "OpenSHC/UI/Enums/MenuModalTypeInt.hpp" #include "OpenSHC/UI/MenuModal.hpp" +#include "OpenSHC/Util/FunctionTypes/NoArgCallback.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" namespace OpenSHC { @@ -19,6 +20,7 @@ namespace UI { using OpenSHC::UI::MenuModal; using OpenSHC::UI::Enums::MenuModalType; using OpenSHC::UI::Enums::MenuModalTypeInt; + using OpenSHC::Util::FunctionTypes::NoArgCallback; using OpenSHC::WindowsHelper::Enums::BOOLEnum; #pragma pack(push, 1) @@ -72,7 +74,7 @@ namespace UI { void fillWithMenuModalDimensions(int* xPtr, int* yPtr, int* widthPtr, int* heigthPtr); void setSliderParameters( - int minimum, int maximum, int value, int* destination, void(__cdecl* callbackFunction)()); + int minimum, int maximum, int value, int* destination, NoArgCallback* callbackFunction); void setSliderParameters2( dword minimum, dword maximum, dword value, dword destination, undefined* callbackFunction); From 458be7fc17deb80236270fc3905f71c8ccf4a1b7 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 19:58:28 +0100 Subject: [PATCH 13/19] headers: MenuModalComposition::setSliderParameters2 takes a NoArgCallback* 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 --- src/OpenSHC/UI/MenuModalComposition.func.hpp | 2 +- src/OpenSHC/UI/MenuModalComposition.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/UI/MenuModalComposition.func.hpp b/src/OpenSHC/UI/MenuModalComposition.func.hpp index 3825d5a2d9..c2ec440fe9 100644 --- a/src/OpenSHC/UI/MenuModalComposition.func.hpp +++ b/src/OpenSHC/UI/MenuModalComposition.func.hpp @@ -48,7 +48,7 @@ namespace UI { Address::SHC_3BB0A8C1_0x004AA480, &MenuModalComposition::setSliderParameters) setSliderParameters; - MACRO_FUNCTION_RESOLVER(void (MenuModalComposition::*)(dword, dword, dword, dword, undefined*), false, + MACRO_FUNCTION_RESOLVER(void (MenuModalComposition::*)(dword, dword, dword, dword, NoArgCallback*), false, Address::SHC_3BB0A8C1_0x004AA540, &MenuModalComposition::setSliderParameters2) setSliderParameters2; diff --git a/src/OpenSHC/UI/MenuModalComposition.hpp b/src/OpenSHC/UI/MenuModalComposition.hpp index 5af858aef6..420044ba01 100644 --- a/src/OpenSHC/UI/MenuModalComposition.hpp +++ b/src/OpenSHC/UI/MenuModalComposition.hpp @@ -77,7 +77,7 @@ namespace UI { int minimum, int maximum, int value, int* destination, NoArgCallback* callbackFunction); void setSliderParameters2( - dword minimum, dword maximum, dword value, dword destination, undefined* callbackFunction); + dword minimum, dword maximum, dword value, dword destination, NoArgCallback* callbackFunction); void setModalSliderParameters( int param_1, int param_2, dword param_3, dword param_4, undefined* param_5, undefined* param_6); From efc999d1eabc6c627857337b0cd9ba96764b779c Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 19:58:28 +0100 Subject: [PATCH 14/19] headers: MenuModalComposition::setSliderParameters2 takes a short* destination 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 --- src/OpenSHC/UI/MenuModalComposition.func.hpp | 2 +- src/OpenSHC/UI/MenuModalComposition.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/UI/MenuModalComposition.func.hpp b/src/OpenSHC/UI/MenuModalComposition.func.hpp index c2ec440fe9..d168d8efee 100644 --- a/src/OpenSHC/UI/MenuModalComposition.func.hpp +++ b/src/OpenSHC/UI/MenuModalComposition.func.hpp @@ -48,7 +48,7 @@ namespace UI { Address::SHC_3BB0A8C1_0x004AA480, &MenuModalComposition::setSliderParameters) setSliderParameters; - MACRO_FUNCTION_RESOLVER(void (MenuModalComposition::*)(dword, dword, dword, dword, NoArgCallback*), false, + MACRO_FUNCTION_RESOLVER(void (MenuModalComposition::*)(dword, dword, dword, short*, NoArgCallback*), false, Address::SHC_3BB0A8C1_0x004AA540, &MenuModalComposition::setSliderParameters2) setSliderParameters2; diff --git a/src/OpenSHC/UI/MenuModalComposition.hpp b/src/OpenSHC/UI/MenuModalComposition.hpp index 420044ba01..9c41a2491b 100644 --- a/src/OpenSHC/UI/MenuModalComposition.hpp +++ b/src/OpenSHC/UI/MenuModalComposition.hpp @@ -77,7 +77,7 @@ namespace UI { int minimum, int maximum, int value, int* destination, NoArgCallback* callbackFunction); void setSliderParameters2( - dword minimum, dword maximum, dword value, dword destination, NoArgCallback* callbackFunction); + dword minimum, dword maximum, dword value, short* destination, NoArgCallback* callbackFunction); void setModalSliderParameters( int param_1, int param_2, dword param_3, dword param_4, undefined* param_5, undefined* param_6); From 9ab2552461bc09bad5f5dee3d3e17f242941dc66 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 19:58:28 +0100 Subject: [PATCH 15/19] headers: MenuModalComposition::setModalSliderParameters' last parameter 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 (e31bef6b6, #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 --- src/OpenSHC/UI/MenuModalComposition.func.hpp | 4 ++-- src/OpenSHC/UI/MenuModalComposition.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpenSHC/UI/MenuModalComposition.func.hpp b/src/OpenSHC/UI/MenuModalComposition.func.hpp index d168d8efee..8744928379 100644 --- a/src/OpenSHC/UI/MenuModalComposition.func.hpp +++ b/src/OpenSHC/UI/MenuModalComposition.func.hpp @@ -52,8 +52,8 @@ namespace UI { Address::SHC_3BB0A8C1_0x004AA540, &MenuModalComposition::setSliderParameters2) setSliderParameters2; - MACRO_FUNCTION_RESOLVER(void (MenuModalComposition::*)(int, int, dword, dword, undefined*, undefined*), false, - Address::SHC_3BB0A8C1_0x004AA930, &MenuModalComposition::setModalSliderParameters) + MACRO_FUNCTION_RESOLVER(void (MenuModalComposition::*)(int, int, dword, dword, undefined*, NoArgCallback*), + false, Address::SHC_3BB0A8C1_0x004AA930, &MenuModalComposition::setModalSliderParameters) setModalSliderParameters; MACRO_FUNCTION_RESOLVER(void (MenuModalComposition::*)(), false, Address::SHC_3BB0A8C1_0x004B0B30, diff --git a/src/OpenSHC/UI/MenuModalComposition.hpp b/src/OpenSHC/UI/MenuModalComposition.hpp index 9c41a2491b..bd46325897 100644 --- a/src/OpenSHC/UI/MenuModalComposition.hpp +++ b/src/OpenSHC/UI/MenuModalComposition.hpp @@ -80,7 +80,7 @@ namespace UI { dword minimum, dword maximum, dword value, short* destination, NoArgCallback* callbackFunction); void setModalSliderParameters( - int param_1, int param_2, dword param_3, dword param_4, undefined* param_5, undefined* param_6); + int param_1, int param_2, dword param_3, dword param_4, undefined* param_5, NoArgCallback* param_6); void renderMenuModal(); From b2164711b1a6e34fc995e3131da7a1e167b5b33f Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 19:58:28 +0100 Subject: [PATCH 16/19] headers: MenuModalComposition::setModalSliderParameters' param_5 is an 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 e31bef6b6 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 --- src/OpenSHC/UI/MenuModalComposition.func.hpp | 4 ++-- src/OpenSHC/UI/MenuModalComposition.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpenSHC/UI/MenuModalComposition.func.hpp b/src/OpenSHC/UI/MenuModalComposition.func.hpp index 8744928379..6adf2d1875 100644 --- a/src/OpenSHC/UI/MenuModalComposition.func.hpp +++ b/src/OpenSHC/UI/MenuModalComposition.func.hpp @@ -52,8 +52,8 @@ namespace UI { Address::SHC_3BB0A8C1_0x004AA540, &MenuModalComposition::setSliderParameters2) setSliderParameters2; - MACRO_FUNCTION_RESOLVER(void (MenuModalComposition::*)(int, int, dword, dword, undefined*, NoArgCallback*), - false, Address::SHC_3BB0A8C1_0x004AA930, &MenuModalComposition::setModalSliderParameters) + MACRO_FUNCTION_RESOLVER(void (MenuModalComposition::*)(int, int, dword, dword, int*, NoArgCallback*), false, + Address::SHC_3BB0A8C1_0x004AA930, &MenuModalComposition::setModalSliderParameters) setModalSliderParameters; MACRO_FUNCTION_RESOLVER(void (MenuModalComposition::*)(), false, Address::SHC_3BB0A8C1_0x004B0B30, diff --git a/src/OpenSHC/UI/MenuModalComposition.hpp b/src/OpenSHC/UI/MenuModalComposition.hpp index bd46325897..152d803957 100644 --- a/src/OpenSHC/UI/MenuModalComposition.hpp +++ b/src/OpenSHC/UI/MenuModalComposition.hpp @@ -80,7 +80,7 @@ namespace UI { dword minimum, dword maximum, dword value, short* destination, NoArgCallback* callbackFunction); void setModalSliderParameters( - int param_1, int param_2, dword param_3, dword param_4, undefined* param_5, NoArgCallback* param_6); + int param_1, int param_2, dword param_3, dword param_4, int* param_5, NoArgCallback* param_6); void renderMenuModal(); From 7dde7b82d3cf1c86b25bfc6cd868272c37d1b796 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 19:58:28 +0100 Subject: [PATCH 17/19] headers: MenuModalComposition::sliderCallbackFunction is a NoArgCallback* 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 (a2803eb4b, 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 --- src/OpenSHC/UI/MenuModalComposition.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenSHC/UI/MenuModalComposition.hpp b/src/OpenSHC/UI/MenuModalComposition.hpp index 152d803957..8753b4ef0a 100644 --- a/src/OpenSHC/UI/MenuModalComposition.hpp +++ b/src/OpenSHC/UI/MenuModalComposition.hpp @@ -42,7 +42,7 @@ namespace UI { dword sliderValue; // 0x00000054 length: 4 int* destination; // 0x00000058 length: 4 short* destination2; // 0x0000005C length: 4 - pointer sliderCallbackFunction; // 0x00000060 length: 4 + NoArgCallback* sliderCallbackFunction; // 0x00000060 length: 4 dword mbr_0x64; // 0x00000064 length: 4 int disappearAfter; // 0x00000068 length: 4 dword mbr_0x6c; // 0x0000006C length: 4 From b53888f92c1f1eee8936aff9e9ce3b5c8892f113 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 19:58:28 +0100 Subject: [PATCH 18/19] MenuModalComposition: setSliderParameters2 and UnusedWinCondition_Options 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 --- .../MenuItemActionHandler_UnusedWinCondition_Options.cpp | 9 +++------ .../UI/MenuModalComposition/setSliderParameters2.cpp | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/OpenSHC/UI/MenuItems/Unused/MenuItemActionHandler_UnusedWinCondition_Options.cpp b/src/OpenSHC/UI/MenuItems/Unused/MenuItemActionHandler_UnusedWinCondition_Options.cpp index b5431f1b5c..f3bb312349 100644 --- a/src/OpenSHC/UI/MenuItems/Unused/MenuItemActionHandler_UnusedWinCondition_Options.cpp +++ b/src/OpenSHC/UI/MenuItems/Unused/MenuItemActionHandler_UnusedWinCondition_Options.cpp @@ -1,7 +1,7 @@ -#include "OpenSHC/UI/MenuItems/Unused.func.hpp" +#include "../Unused.func.hpp" + #include "OpenSHC/UI/MenuModalComposition.func.hpp" #include "OpenSHC/UI/Enums/MenuModalType.hpp" -#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" @@ -10,9 +10,6 @@ namespace UI { namespace MenuItems { namespace Unused { - using OpenSHC::UI::Enums::MenuModalType; - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x004B1090 void MenuItemActionHandler_UnusedWinCondition_Options(int value, ...) { @@ -24,7 +21,7 @@ namespace UI { MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, DAT_MenuModalComposition1::ptr)(OpenSHC::UI::Enums::MMT_NONE, FALSE); if (DAT_MenuModalComposition1::instance.sliderCallbackFunction != NULL) { - ((void (*)())DAT_MenuModalComposition1::instance.sliderCallbackFunction)(); + DAT_MenuModalComposition1::instance.sliderCallbackFunction(); } } diff --git a/src/OpenSHC/UI/MenuModalComposition/setSliderParameters2.cpp b/src/OpenSHC/UI/MenuModalComposition/setSliderParameters2.cpp index a4cda0f72d..1a85a134ed 100644 --- a/src/OpenSHC/UI/MenuModalComposition/setSliderParameters2.cpp +++ b/src/OpenSHC/UI/MenuModalComposition/setSliderParameters2.cpp @@ -7,7 +7,7 @@ namespace UI { // FUNCTION: STRONGHOLDCRUSADER 0x004AA540 void MenuModalComposition::setSliderParameters2( - dword minimum, dword maximum, dword value, dword destination, undefined* callbackFunction) + dword minimum, dword maximum, dword value, short* destination, NoArgCallback* callbackFunction) { int const range = maximum - minimum; this->sliderMinimum = minimum; @@ -28,7 +28,7 @@ namespace UI { } else { this->sliderValue = value; } - this->destination2 = (short*)destination; + this->destination2 = destination; this->destination = NULL; Menu_OverlaySlider::instance.one = 1; this->textGroup = -1; From 3e330e1f0492c248eee3d713cdaf98e02067c9f9 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 23:38:48 +0100 Subject: [PATCH 19/19] NewEventAction: the event type switch uses ScenarioEventType's names gynt on #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 --- ...MenuModalRenderFunction_NewEventAction.cpp | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/OpenSHC/UI/MenuModals/NewEventAction/MenuModalRenderFunction_NewEventAction.cpp b/src/OpenSHC/UI/MenuModals/NewEventAction/MenuModalRenderFunction_NewEventAction.cpp index 8edc795ce0..578a728b1d 100644 --- a/src/OpenSHC/UI/MenuModals/NewEventAction/MenuModalRenderFunction_NewEventAction.cpp +++ b/src/OpenSHC/UI/MenuModals/NewEventAction/MenuModalRenderFunction_NewEventAction.cpp @@ -3,6 +3,7 @@ #include "OpenSHC/Text/TextManager.func.hpp" #include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" #include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Game/ScenarioEvents/Enums/ScenarioEventType.hpp" #include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" #include "OpenSHC/Text/TextAlignment.hpp" @@ -23,19 +24,19 @@ namespace UI { // the actions that repeat label their two fields switch (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] .data.scenario.ScenarioEventType) { - case 5: - case 11: - case 12: - case 13: - case 14: - case 15: - case 16: - case 17: - case 18: - case 19: - case 20: - case 29: - case 30: + case OpenSHC::Game::ScenarioEvents::Enums::SET_TRAVELING_FAIR: + case OpenSHC::Game::ScenarioEvents::Enums::SET_PLAGUE: + case OpenSHC::Game::ScenarioEvents::Enums::SET_WHEAT_DISEASE: + case OpenSHC::Game::ScenarioEvents::Enums::SET_HOPS_WEEVIL: + case OpenSHC::Game::ScenarioEvents::Enums::SET_APPLE_BLIGHT: + case OpenSHC::Game::ScenarioEvents::Enums::SET_TREE_FUNGUS: + case OpenSHC::Game::ScenarioEvents::Enums::SET_RABBIT_EXPLOSION: + case OpenSHC::Game::ScenarioEvents::Enums::SET_LION_ATTACK: + case OpenSHC::Game::ScenarioEvents::Enums::SET_BANDITS: + case OpenSHC::Game::ScenarioEvents::Enums::SET_MAD_COWS: + case OpenSHC::Game::ScenarioEvents::Enums::SET_ARCHERS: + case OpenSHC::Game::ScenarioEvents::Enums::SET_THEFT_FROM_GRANARY: + case OpenSHC::Game::ScenarioEvents::Enums::SET_FIRE: // "Repeat (months)" MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset,