//
// UILayer::handleKeypress from 0x1404cd830 to 0x1404cde4e (1566 bytes)
//
// 3 xrefs:
// > UILayer::keyDown @ 0x1404cde5d
// > UILayer::keyUp @ 0x1404cde7d
// > ??> @ 0x1406dd490
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
// Hidden C++ exception states: #wind=13
void UILayer::handleKeypress(UILayer *a1, cocos2d::enumKeyCodes a2, bool a3, double a4)
{
GameManager *v5; // rcx
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rcx
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rcx
GameManager *v12; // rcx
__int64 v13; // rax
__int64 v14; // rcx
__int64 v15; // rcx
std::vector
*p_m_queuedButtons; // rcx
std::_Vector_val>::pointer Mylast; // rdx
__int64 v18; // rcx
PlayLayer *v19; // rcx
void *v20; // [rsp+20h] [rbp-20h]
void *v21; // [rsp+20h] [rbp-20h]
void *v22; // [rsp+20h] [rbp-20h]
void *v23; // [rsp+20h] [rbp-20h]
void *v24; // [rsp+20h] [rbp-20h]
void *v25; // [rsp+20h] [rbp-20h]
void *v26; // [rsp+20h] [rbp-20h]
void *v27; // [rsp+20h] [rbp-20h]
__int128 v28; // [rsp+28h] [rbp-18h] BYREF
double v29; // [rsp+38h] [rbp-8h]
if ( a2 > CONTROLLER_A )
{
switch ( a2 )
{
case 1002:
case 1015:
LABEL_43:
if ( a3 )
{
if ( a1->m_p2Jumping )
return;
a1->m_p2Jumping = 1;
WORD2(v28) = 257;
}
else
{
a1->m_p2Jumping = 0;
WORD2(v28) = 256;
}
break;
case 1003:
LABEL_57:
if ( a3 )
goto LABEL_58;
return;
case 1007:
LABEL_51:
if ( a3 )
{
if ( !a1->m_editorMode )
{
if ( a1->m_checkpointBtnDown )
{
LABEL_58:
if ( !a1->m_editorMode && a1->m_gameLayer->m_isPracticeMode )
{
v18 = qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v27 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v27);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v18 = qword_1406C2ED8;
}
v19 = *(PlayLayer **)(v18 + 520);
if ( v19 && v19->m_isPracticeMode )
PlayLayer::removeCheckpoint(v19, 0);
}
}
else
{
a1->m_checkpointBtnDown = 1;
if ( a1->m_gameLayer->m_isPracticeMode )
UILayer::onCheck(a1, nullptr);
}
}
}
else
{
a1->m_checkpointBtnDown = 0;
}
return;
case 1009:
case 1010:
LABEL_65:
if ( a3 && !a1->m_editorMode )
UILayer::onPause(a1, nullptr);
return;
case 1013:
goto LABEL_35;
case 1025:
case 1033:
LABEL_47:
LODWORD(v28) = 2;
WORD2(v28) = a3;
goto LABEL_39;
case 1026:
case 1034:
case 1041:
LABEL_49:
LODWORD(v28) = 2;
BYTE4(v28) = a3;
BYTE5(v28) = 1;
goto LABEL_39;
case 1027:
case 1035:
LABEL_48:
LODWORD(v28) = 3;
WORD2(v28) = a3;
goto LABEL_39;
case 1028:
case 1036:
case 1043:
LABEL_50:
LODWORD(v28) = 3;
BYTE4(v28) = a3;
BYTE5(v28) = 1;
goto LABEL_39;
default:
return;
}
}
else
{
if ( a2 != CONTROLLER_A )
{
switch ( a2 )
{
case KEY_Escape:
goto LABEL_65;
case KEY_Space:
case KEY_W:
goto LABEL_35;
case KEY_Left:
goto LABEL_49;
case KEY_Up:
goto LABEL_43;
case KEY_Right:
goto LABEL_50;
case KEY_A:
goto LABEL_47;
case KEY_D:
goto LABEL_48;
case KEY_P:
if ( a3 && !a1->m_editorMode )
{
v12 = (GameManager *)qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v24 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v24);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v12 = (GameManager *)qword_1406C2ED8;
}
if ( GameManager::getGameVariable(v12, "0163") )
{
v13 = qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v25 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v25);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v13 = qword_1406C2ED8;
}
v14 = *(_QWORD *)(v13 + 520);
if ( v14 && *(_BYTE *)(v14 + 12784) )
{
GameManager::toggleGameVariable((GameManager *)v14, "0166");
v15 = qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v26 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v26);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v15 = qword_1406C2ED8;
}
PlayLayer::updateDebugDrawSettings(*(PlayLayer **)(v15 + 520));
}
}
}
break;
case KEY_R:
if ( a3 && !a1->m_editorMode )
{
v5 = (GameManager *)qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v20 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v20);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v5 = (GameManager *)qword_1406C2ED8;
}
if ( GameManager::getGameVariable(v5, "0163") )
{
v6 = qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v21 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v21);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v6 = qword_1406C2ED8;
}
v7 = *(_QWORD *)(v6 + 520);
if ( v7 && !*(_BYTE *)(v7 + 13680) && !*(_BYTE *)(v7 + 14717) && a1->m_pauseBtn->isEnabled(a1->m_pauseBtn) )
{
*(_QWORD *)&a1->m_p1TouchId = -1;
UILayer::resetUINodeState(a1);
v9 = cocos2d::CCDirector::sharedDirector(v8);
v10 = (*(__int64 (__fastcall **)(__int64))(*(_QWORD *)v9 + 176LL))(v9);
v11 = qword_1406C2ED8;
if ( *(_BYTE *)(v10 + 89) )
{
if ( !qword_1406C2ED8 )
{
v22 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v22);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v11 = qword_1406C2ED8;
}
PlayLayer::fullReset(*(PlayLayer **)(v11 + 520));
}
else
{
if ( !qword_1406C2ED8 )
{
v23 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v23);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v11 = qword_1406C2ED8;
}
(*(void (__fastcall **)(_QWORD))(**(_QWORD **)(v11 + 520) + 1408LL))(*(_QWORD *)(v11 + 520));
}
}
}
}
break;
case KEY_X:
goto LABEL_57;
case KEY_Z:
goto LABEL_51;
default:
return;
}
return;
}
LABEL_35:
if ( a3 )
{
if ( a1->m_p1Jumping )
return;
a1->m_p1Jumping = 1;
WORD2(v28) = 1;
}
else
{
a1->m_p1Jumping = 0;
WORD2(v28) = 0;
}
}
LODWORD(v28) = 1;
LABEL_39:
HIWORD(v28) = 0;
*(_QWORD *)((char *)&v28 + 6) = 0;
v29 = a4;
p_m_queuedButtons = &a1->m_gameLayer->m_queuedButtons;
Mylast = a1->m_gameLayer->m_queuedButtons._Mypair._Myval2._Mylast;
if ( Mylast == a1->m_gameLayer->m_queuedButtons._Mypair._Myval2._Myend )
{
sub_140253010(p_m_queuedButtons, Mylast, (__int64)&v28);
}
else
{
*(_OWORD *)&Mylast->m_button = v28;
Mylast->m_timestamp = v29;
++p_m_queuedButtons->_Mypair._Myval2._Mylast;
}
}