From 29d74146580837f60cdeb332baf4d2dc36647673 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sun, 22 Nov 2026 05:37:30 +0100 Subject: [PATCH] reimplement: SHC_3BB0A8C1_0x00468AD0 100.0% Reimplemented ScrollingHandler::handleScrolling, from Gynt's draft (4c73c67b03 at 23.6% on his closed #256's reimpl/UI-Core; the same percentage at 10280b1610 on his fork's reimpl/UI-Core-development and at 3d17527d65 on reimpl/UI-MenuItems-development). The draft is the decompiler's output. One behaviour fix against it: with no direction the original resets the scroll state and returns (0x00468BD3). In these drafts the block has no return, so it went on into the scrolling code, set isScrolling again and overwrote the base distance and timeScrolling with those of an elapsed time of about 0. His fork's reimpl/Wilps-2026-10-18 (8ca78619cd), a copy with other field names, has the return. Rewritten against the original instructions: - the direction is one if / else if chain on up, down, left and right, with left tested before right under up and under down; - isScrolling is set in both arms of the direction test, and a second if on it holds the rest of the no-direction block. As far as we can tell, the compiler knows the flag on both paths and drops the second test, but only after it has placed the blocks: the block keeps the second if's place, and the switch's compare chain and slow case then move up in front of it. That is the original, which has the block between the slow and the fast case (0x00468BAF). As one if with a return, in front of the store, the block stays in front of the switch (86.9%); as the else arm of the direction test it goes behind the function's end, with its stores reordered; - the speed is a switch, with interval -= interval / 3 for fast and interval += interval / 2 for slow. For the fast case the compiler divides by -3 and adds, as the original does (0x00468BD4); interval += interval / -3, or the third in a local of its own, gives the same listing; - (int)scrollDistanceLimit, as the original divides it signed (the field is undefined4 in the header, like the interval and the minimum, which it also uses as int); - the elapsed time goes straight into timeScrolling and the quotient into scrollDistanceBase (locals for them give the same listing); the four flags are cleared down, up, right, left in both places, which the compiler emits last one first here, as the original has them (left, right, up, down). No line for cmake/compiler-flags-gl.txt: the file reads 100.0% off the /GL list, and 100.0% on it too. It calls nothing but timeGetTime. reccmp in a build of main's whole /GL list (the 133 files that exist) and this file as committed, off the list, with every resolver of those files on: 144 functions, average 99.56. handleScrolling 100.0% raw and normalised, no differing line, and the same with the file on the list. The same build without the file has 143 functions, and each of them reads the same. The sources are main's at 3458fea34; main's two commits since (02fab423c, 812d149696) add cmake files only, with the new option off. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../UI/ScrollingHandler/handleScrolling.cpp | 97 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/ScrollingHandler/handleScrolling.cpp diff --git a/src/OpenSHC/UI/ScrollingHandler/handleScrolling.cpp b/src/OpenSHC/UI/ScrollingHandler/handleScrolling.cpp new file mode 100644 index 0000000000..cf4eef4400 --- /dev/null +++ b/src/OpenSHC/UI/ScrollingHandler/handleScrolling.cpp @@ -0,0 +1,97 @@ +#include "../ScrollingHandler.func.hpp" + +#include "OpenSHC/UI/Enums/MenuModalType.hpp" +#include "OpenSHC/UI/ScrollDirection.hpp" +#include "OpenSHC/UI/ScrollSpeed.hpp" + +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" + +namespace OpenSHC { +namespace UI { + + // FUNCTION: STRONGHOLDCRUSADER 0x00468AD0 + void ScrollingHandler::handleScrolling() + { + int interval = this->scrollAccelerationInterval; + int maxDistance = (int)this->scrollDistanceLimit * 2 / 3; + // the held keys scroll too, while no dialog is open + if (DAT_MenuTextInputState::instance.currentModalDialog == OpenSHC::UI::Enums::MMT_NO_MENU) { + if (this->rightKeyDown_0x18) { + this->scrollRight = TRUE; + } + if (this->leftKeyDown_0x1c) { + this->scrollLeft = TRUE; + } + if (this->upKeyDown_0x24) { + this->scrollUp = TRUE; + } + if (this->downKeyDown_0x20) { + this->scrollDown = TRUE; + } + } + if (this->scrollUp) { + if (this->scrollLeft) { + this->scrollDirection_0x4 = OpenSHC::UI::SD_UP_LEFT; + } else if (this->scrollRight) { + this->scrollDirection_0x4 = OpenSHC::UI::SD_UP_RIGHT; + } else { + this->scrollDirection_0x4 = OpenSHC::UI::SD_UP; + } + } else if (this->scrollDown) { + if (this->scrollLeft) { + this->scrollDirection_0x4 = OpenSHC::UI::SD_DOWN_LEFT; + } else if (this->scrollRight) { + this->scrollDirection_0x4 = OpenSHC::UI::SD_DOWN_RIGHT; + } else { + this->scrollDirection_0x4 = OpenSHC::UI::SD_DOWN; + } + } else if (this->scrollLeft) { + this->scrollDirection_0x4 = OpenSHC::UI::SD_LEFT; + } else if (this->scrollRight) { + this->scrollDirection_0x4 = OpenSHC::UI::SD_RIGHT; + } else { + this->scrollDirection_0x4 = OpenSHC::UI::SD_NONE; + } + // set here and tested below: as one test with the no-direction block in it, the match is lost + if (this->scrollDirection_0x4 != OpenSHC::UI::SD_NONE) { + this->isScrolling_0x0 = TRUE; + } else { + this->isScrolling_0x0 = FALSE; + } + // no direction: back to the minimum distance; the stop time and the scrolling time are both now + if (!this->isScrolling_0x0) { + this->scrollDistanceBase = this->scrollDistanceMin; + DWORD const now = timeGetTime(); + this->scrollDown = FALSE; + this->scrollUp = FALSE; + this->scrollRight = FALSE; + this->scrollLeft = FALSE; + this->timeOfLastNotScroll_0x40 = now; + this->timeScrolling_0x44 = now; + return; + } + // fast: the interval less a third, the maximum at 133%; slow: the interval plus a half, half the maximum + switch (this->scrollSpeedSetting_0x38) { + case OpenSHC::UI::SS_FAST: + interval -= interval / 3; + maxDistance = maxDistance * 133 / 100; + break; + case OpenSHC::UI::SS_SLOW: + interval += interval / 2; + maxDistance /= 2; + break; + } + // the longer the scrolling lasts, the further a step goes, up to the maximum + this->timeScrolling_0x44 = timeGetTime() - this->timeOfLastNotScroll_0x40; + this->scrollDistanceBase = this->timeScrolling_0x44 / interval; + if (this->scrollDistanceBase > maxDistance) { + this->scrollDistanceBase = maxDistance; + } + this->scrollDown = FALSE; + this->scrollUp = FALSE; + this->scrollRight = FALSE; + this->scrollLeft = FALSE; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b62540e14f..37d6ac920f 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -20091,7 +20091,7 @@ SHC_3BB0A8C1_0x00468A20 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00468A90 | 0.0% | Pending -SHC_3BB0A8C1_0x00468AD0 | 0.0% | Pending +SHC_3BB0A8C1_0x00468AD0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00468C30 | 100.0% | Reimplemented