decomp(candidatebox): match createAnmPane_ and link tiCandidateBox #1300

Merged
coah80 merged 1 commits from agent/w0929/opus-candbox-land into main 2026-10-09 02:23:22 +00:00
5 changed files with 138 additions and 31 deletions

View File

@@ -17727,7 +17727,7 @@ __vt__Q39textinput4util9Animation = .data:0x8165D258; // type:object size:0x24
@STRING@GetTextColor__Q34nw4r3lyt7TextBoxCFUl = .data:0x8165D28C; // type:object size:0x41 data:string
scT_prdc_Text_00 = .data:0x8165D2D0; // type:object size:0xF data:string
scP_prdc_scrl_Left = .data:0x8165D2E0; // type:object size:0x11 data:string
scCandidatePaneData = .data:0x8165D2F8; // type:object size:0x680
csPaneToAnimation__Q29textinput12candidatebox = .data:0x8165D2F8; // type:object size:0x680 scope:local
@9934 = .data:0x8165D978; // type:object size:0x9 scope:local data:string
@9935 = .data:0x8165D984; // type:object size:0x9 scope:local data:string
@9936 = .data:0x8165D990; // type:object size:0xB scope:local data:string

View File

@@ -912,7 +912,7 @@ config.libs = [
Object(Matching, "keyboard/tiPcKeyboard.cpp", extra_cflags=["-O4,p"]),
Object(Matching, "keyboard/tiCellPhone.cpp", extra_cflags=["-O4,p"]),
Object(NonMatching, "keyboard/tiInputForm.cpp", extra_cflags=["-O4,p"]),
Object(NonMatching, "keyboard/tiCandidateBox.cpp", extra_cflags=["-O4,p"]),
Object(Matching, "keyboard/tiCandidateBox.cpp", extra_cflags=["-O4,p"]),
Object(Matching, "keyboard/tiToolBar.cpp", extra_cflags=["-O4,p"]),
Object(Matching, "keyboard/tiPredictLang.cpp", extra_cflags=["-O4,p"]),
Object(Matching, "keyboard/tiSignWindow.cpp", extra_cflags=["-O4,p"]),

View File

@@ -77,7 +77,7 @@ namespace textinput {
class Base : public CommandSender {
public:
#ifdef TIMANAGER_IMPLEMENTATION
#if defined(TIMANAGER_IMPLEMENTATION) || defined(TI_CANDIDATEBOX_SAMPLE_CLASS)
Base(Manager* manager) : mpCandidates(NULL), mpAllocator(NULL), mbOn(false), mbInvalid(true), meLanguage(USA), mpManager(manager) {}
#endif
virtual ~Base();
@@ -114,7 +114,7 @@ namespace textinput {
class EventHandler : public nw4rmanager::TiEventHandler {
public:
#ifdef TIMANAGER_IMPLEMENTATION
#if defined(TIMANAGER_IMPLEMENTATION) || defined(TI_CANDIDATEBOX_SAMPLE_CLASS)
EventHandler(LayoutByNW4R* layout) : mpLayoutByNW4R(layout) {}
#endif
virtual void onTiEvent(gui::PaneComponent* paneComponent, u32 event, Input* input) override; // 0x18
@@ -302,7 +302,7 @@ namespace textinput {
// TODO
class LayoutByNW4R : public Base, public nw4rmanager::Layout, public UIObj::Listener {
public:
#ifdef TIMANAGER_IMPLEMENTATION
#if defined(TIMANAGER_IMPLEMENTATION) || defined(TI_CANDIDATEBOX_SAMPLE_CLASS)
LayoutByNW4R(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* accessor, EventObserver* observer, const char* layoutName)
: Base(manager), nw4rmanager::Layout(accessor, layoutName, observer), mEventHandler(this), mpTiString(NULL),
mTextArea(0, this, this), mLeftScroll(1, this, this), mRightScroll(2, this, this), mOnOffButton(3, this, this),
@@ -371,6 +371,15 @@ namespace textinput {
bool mbActive;
};
#ifdef TI_CANDIDATEBOX_SAMPLE_CLASS
class Sample : public LayoutByNW4R {
public:
Sample(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* accessor, EventObserver* observer, const char* layoutName)
: LayoutByNW4R(manager, accessor, observer, layoutName) {}
virtual ~Sample() {}
};
#endif
class CandidateTextAnmPane : public nw4rmanager::AnmPane {
public:
CandidateTextAnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer)

View File

@@ -1,5 +1,7 @@
#define TI_CANDIDATEBOX_IMPLEMENTATION
#define TI_CANDIDATEBOX_SAMPLE_CLASS
#include "keyboard/tiCandidateBox.h"
#undef TI_CANDIDATEBOX_SAMPLE_CLASS
#include "keyboard/tiManager.h"
@@ -60,11 +62,7 @@ namespace textinput {
{ANM_InvalidOff, "fs_VK_predictInput_a_invalidMode_OFF.brlan"},
};
struct CandidatePaneData {
PaneToAnimation panes[26];
};
extern "C" const CandidatePaneData scCandidatePaneData __attribute__((aligned(8))) = {{
static const PaneToAnimation csPaneToAnimation[] = {
{KT_CandidateText, "N_predictInput", 1, NULL, {&csAninationFile[0]}},
{KT_ScrollButton,
"P_prdc_scrl_Left",
@@ -195,7 +193,7 @@ namespace textinput {
6,
NULL,
{&csAninationFile[0], &csAninationFile[8], &csAninationFile[9], &csAninationFile[10], &csAninationFile[11], &csAninationFile[12]}},
}};
};
void CandidateBoxCaller::Candidates::addCandidate(const wchar_t* wcString) {
wcsncpy(szwcPredicted[mNumCandidate], wcString, ARRAY_LENGTH(szwcPredicted[0]));
@@ -376,50 +374,44 @@ namespace textinput {
}
void LayoutByNW4R::createAnmPane_(MEMAllocator* allocator) {
u32 animationCount;
const char* forceAddName;
u16 i;
for (i = 0; i < ARRAY_LENGTH(scCandidatePaneData.panes); i++) {
const PaneToAnimation& p = scCandidatePaneData.panes[i];
for (u16 i = 0; i < ARRAY_LENGTH(csPaneToAnimation); i++) {
const PaneToAnimation& paneAnimations = csPaneToAnimation[i];
CandidateTextAnmPane* pane = NULL;
switch (p.type) {
switch (paneAnimations.type) {
case KT_ScrollButton: {
void* pBtnBuf = MEMAllocFromAllocator(allocator, sizeof(CandidateScrollAnmPane));
pane = new (pBtnBuf) CandidateScrollAnmPane(getPane(p.paneName), NULL);
pane = new (pBtnBuf) CandidateScrollAnmPane(getPane(paneAnimations.paneName), NULL);
break;
}
case KT_CandidateText: {
void* pBtnBuf = MEMAllocFromAllocator(allocator, sizeof(CandidateTextAnmPane));
pane = new (pBtnBuf) CandidateTextAnmPane(getPane(p.paneName), NULL);
pane = new (pBtnBuf) CandidateTextAnmPane(getPane(paneAnimations.paneName), NULL);
break;
}
case KT_OnOffButton: {
void* pBtnBuf = MEMAllocFromAllocator(allocator, sizeof(OnOffAnmPane));
pane = new (pBtnBuf) OnOffAnmPane(getPane(p.paneName), &mOnOffButton);
pane = new (pBtnBuf) OnOffAnmPane(getPane(paneAnimations.paneName), &mOnOffButton);
break;
}
case KT_Window: {
void* pBtnBuf = MEMAllocFromAllocator(allocator, sizeof(PredictWindow));
pane = new (pBtnBuf) PredictWindow(getPane(p.paneName), &mTextWindow);
pane = new (pBtnBuf) PredictWindow(getPane(paneAnimations.paneName), &mTextWindow);
break;
}
}
nw4r::ut::List_Append(&mAnmPanes, pane);
forceAddName = p.forceAddName;
animationCount = p.count;
for (u16 j = 0; j < animationCount; j++) {
const AnimationFile* const& animation = p.pAnims[j];
void* pResource = mpMultiArcResourceAccessor->GetResource(0, animation->fileName);
for (u16 j = 0; j < paneAnimations.count; j++) {
void* pResource = mpMultiArcResourceAccessor->GetResource(0, paneAnimations.pAnims[j]->fileName);
AnimTransformPane* transform =
static_cast<AnimTransformPane*>(getLayout()->CreateAnimTransform(pResource, mpMultiArcResourceAccessor));
if (forceAddName == NULL) {
pane->addAnimation(allocator, animation->id, transform, false, true);
if (paneAnimations.forceAddName == NULL) {
pane->addAnimation(allocator, paneAnimations.pAnims[j]->id, transform, false, true);
} else {
pane->forceAddAnimation(allocator, animation->id, transform, forceAddName, false, true);
pane->forceAddAnimation(allocator, paneAnimations.pAnims[j]->id, transform, paneAnimations.forceAddName, false, true);
}
}
}
@@ -678,8 +670,8 @@ namespace textinput {
}
void LayoutByNW4R::cancelStateFocusIn() {
const PaneToAnimation* pane = scCandidatePaneData.panes;
for (int i = 0; i < ARRAY_LENGTH(scCandidatePaneData.panes); i++) {
const PaneToAnimation* pane = csPaneToAnimation;
for (int i = 0; i < ARRAY_LENGTH(csPaneToAnimation); i++) {
CandidateTextAnmPane* p = static_cast<CandidateTextAnmPane*>(searchAnmPane(pane->paneName));
if (p != NULL) {
switch (p->getKeyType()) {
@@ -1766,3 +1758,48 @@ namespace textinput {
} // namespace candidatebox
} // namespace textinput
inline void textinput::util::Animation::startAnm(AnimObserver* observer, f32 start, f32 end, f32 duration, void* data) {
mfStartPoint = start;
mfEndPoint = end;
mfAnimationTime = duration;
mfCurrentFrame = 0.0f;
mbInAnimation = true;
mpAnimObserver = observer;
mpData = data;
mbSE = false;
if (observer) observer->onAnmEvent(AnimObserver::AE_0, data);
}
inline void textinput::util::Animation::calc() {
if (mbInAnimation) {
if (mfCurrentFrame < mfAnimationTime) {
mfCurrentFrame = 1.0f + mfCurrentFrame;
} else {
if (mbInAnimation && mpAnimObserver) {
mpAnimObserver->onAnmEvent(AnimObserver::AE_1, mpData);
}
mbInAnimation = false;
}
}
}
inline f32 textinput::util::Animation::getValue() {
return hermiteInterporation(mfCurrentFrame, 0.0f, mfStartPoint, 0.0f, mfAnimationTime, mfEndPoint, 0.0f);
}
inline bool textinput::util::Animation::isActive() {
return mbInAnimation;
}
inline void textinput::util::Animation::setSEFlag(bool flag) {
mbSE = flag;
}
inline bool textinput::util::Animation::isSEFlag() {
return mbSE;
}
inline void textinput::util::Animation::stop() {
mbInAnimation = false;
}

View File

@@ -0,0 +1,61 @@
# opus-candbox attempts
Worktree `sol-high`, branch `agent/w1009/o-candbox`, base `72e9c8d6`. Unit `src/keyboard/tiCandidateBox`, last open function `LayoutByNW4R::createAnmPane_` (6/216, count r23 and slot r31 swapped). Read opus-common.md, levers.md, effort-policy entries, sol-x9 log, sol-m4 log (branch `agent/w1009/candbox-max`), saved sol-r12/sol-y11 diffs.
Baseline: full build OK, DOL `26116613...`, odiff 6/216, pool identical 57/57. combosweep (single and pairwise pragmas): `base 6 -> 6`, no hit.
## Root cause
`tiPredictLang::create` is already exact and has the same inner loop with the same struct (`char paneName[20]`, `count`, `forceAddName`, `pAnims[8]`). Its target has count r31 and slot r23, which is what createAnmPane_ needs.
A private mwdbg trace of `tiPredictLang::create` (port 19931 copy of the launcher, shared tool unchanged) shows why. The slot base `p + j*4` is IRO CSE temp `@7026` (vreg r45) and forceAddName is IRO temp `@7028` (r44). Both are numbered after the named locals and before the hoisted constructor constants, so they simplify before the constants and color after them (slot r23). Count is a late anonymous load hoisted out of the loop condition (r131), so it colors first (r31).
The same natural loop inside tiCandidateBox (`j < paneAnimations.count`, `paneAnimations.pAnims[j]->` three times) gives 220 insns. No IRO temps are created, the slot is recomputed in each branch, and constant `2` survives pass-1 spilling.
Table declaration trials with that loop:
| trial | table | result |
| --- | --- | --- |
| 01 | `extern "C" const CandidatePaneData scCandidatePaneData` (struct wrapper, aligned(8)) | 158/220 |
| 02 | `static const CandidatePaneData` (struct wrapper) | 158/220 |
| 03 | `extern "C" const PaneToAnimation[]` (plain array) | 158/220 |
| 04 | `static const PaneToAnimation[]` (plain array, no aligned) | **0/216** |
IRO only CSEs the table loads and addresses when the table is a static plain array, which is how every sibling unit declares it (`csPaneToAnimation`). The `CandidatePaneData` wrapper and `extern "C"` were decomp scaffolding. Without `aligned(8)` the table still lands at .data 0x28, size 0x680.
## Source changes
- Table: `static const PaneToAnimation csPaneToAnimation[]`, same name as tiToolBar/tiPredictLang/pctype. Removed the unused `CandidatePaneData` struct.
- `createAnmPane_`: the tiPredictLang/tiToolBar loop form, with no count/forceAddName/animation locals.
- symbols.txt: `scCandidatePaneData` -> `csPaneToAnimation__Q29textinput12candidatebox` (scope:local). Same address and size. Only tiCandidateBox referenced the old name.
Unit after this: 112/112 functions, code 100%, data 100%, all sections 100%, pool identical.
## Link (Matching flip)
First flip: DOL `8d444a7b...`. Two causes, both checked against the original objects:
1. Thunk order. Target `@36@__dt__` comes before `@36@setRootPaneScaleFor4x3..init`; ours put it last (already true on the old baseline). This is the "move to end on touch" thunk list (eggAudioExpMgr, lever 12). tiPredictLang/tiToolBar/tiCellPhone fix it with a header `Sample : public LayoutByNW4R` behind a `*_SAMPLE_CLASS` macro, and `__vt__Q39textinput12candidatebox6Sample` exists in the DOL. A Sample with only `virtual ~Sample() {}` does not move the thunks. It needs the inline constructor, so the Base/EventHandler/LayoutByNW4R constructor guards also accept `TI_CANDIDATEBOX_SAMPLE_CLASS`, as tiPredictLang.h does. After that, all 112 common functions are in target order. Proof it is required: removing it leaves the wrong thunk order and DOL `5507fb9e...`.
2. Weak vtable hole. The target has 0x40 zero bytes between `__vt__...AnmObserver` (0xd48) and `__vt__Q39textinput4util12AnimObserver` (0xd94). Ours left only the deduplicated gui::EventHandler copy (0x18), so everything after shifted by -0x20/-0x24. util::Animation methods were inline in the original: they sit as scattered weak functions in tiInputForm's .text, and MyTiManager.cpp already defines them `inline`. UITextArea has a `util::Animation` member, so the original object also emitted a weak `__vt__Q39textinput4util9Animation` (0x24, kept from tiInputForm). EventHandler 0x18 at 0xd58 + Animation 0x24 at 0xd70 ends at 0xd94. I added the same inline definitions as MyTiManager.cpp at the end of tiCandidateBox.cpp, with startAnm in this TU's declared parameter order. Only virtual calls exist, so no code changes. .data is now 0xda0, the target size.
Flip with both: full build OK, `build/43U/main.dol` SHA1 `26116613f624061ba99c8d1a299aaa6efa85670d`.
Trial snapshots: `/tmp/opus-candbox/trials/`. Captures: `/tmp/opus-candbox-cap-predictlang`, `/tmp/opus-candbox-cap-f01`.
## Gate
```text
full build: ok
main.dol sha1: 26116613f624061ba99c8d1a299aaa6efa85670d
[src/keyboard/tiCandidateBox] pool: IDENTICAL
[src/keyboard/tiCandidateBox] objdiff: code 24000/24000 data 4652/4652 functions 112/112 fuzzy 100.0000 linked code 24000
[src/keyboard/tiCandidateBox] instruction-exact functions: 112/112
regressions vs baseline: 0
global matched_code_percent: 98.14728 -> 98.17613
global complete_code_percent: 91.22256 -> 92.02384
forbidden patterns added (net, per file): 0
readability warnings (net, per file; must be 0 in the final result): 0
GATE PASS
```
origin/main moved to `82783c6e` during the run (BS2Update lines in configure.py/symbols.txt only, no overlap). Not rebased.