//
// KeybindingsLayer::layerForPage from 0x852b1c to 0x852d1c (512 bytes)
//
// 2 xrefs:
// > KeybindingsLayer::addKeyPair @ 0x852db4
// > ??> @ 0x70848
//
// 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
//
cocos2d::CCLayer *KeybindingsLayer::layerForPage(KeybindingsLayer *a1, int a2)
{
cocos2d::CCDictionary *m_values; // x20
char *v5; // x0
cocos2d::CCLayer *v6; // x20
char *v7; // x0
unsigned int *v9; // x1
int v10; // w2
cocos2d::CCDictionary *v11; // x26
char *v12; // x0
char *v13; // x21
unsigned int *v14; // x1
int v15; // w0
std::string v16; // [xsp+60h] [xbp+60h] BYREF
m_values = a1->m_values;
v5 = (char *)KeybindingsLayer::layerKey(a1, a2);
sub_D153B8((int)&v16, v5);
v6 = (cocos2d::CCLayer *)cocos2d::CCDictionary::objectForKey(m_values, &v16);
v7 = (char *)v16.m_data.m_data - 24;
if ( (__int64 *)v16.m_data.m_data - 3 == &qword_124B6B0 )
goto LABEL_2;
if ( &pthread_create )
{
v9 = (unsigned int *)((char *)v16.m_data.m_data - 8);
do
v10 = __ldaxr(v9);
while ( __stlxr(v10 - 1, v9) );
}
else
{
v10 = *((_DWORD *)v16.m_data.m_data - 2);
*((_DWORD *)v16.m_data.m_data - 2) = v10 - 1;
}
if ( v10 > 0 )
{
LABEL_2:
if ( v6 )
return v6;
}
else
{
operator delete(v7);
if ( v6 )
return v6;
}
v6 = cocos2d::CCLayer::create();
a1->m_mainLayer->addChild(a1->m_mainLayer, v6);
v11 = a1->m_values;
v12 = (char *)KeybindingsLayer::layerKey(a1, a2);
sub_D153B8((int)&v16, v12);
cocos2d::CCDictionary::setObject((int)v11, v6);
v13 = (char *)v16.m_data.m_data - 24;
if ( (__int64 *)v16.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v14 = (unsigned int *)((char *)v16.m_data.m_data - 8);
do
v15 = __ldaxr(v14);
while ( __stlxr(v15 - 1, v14) );
}
else
{
v15 = *((_DWORD *)v16.m_data.m_data - 2);
*((_DWORD *)v16.m_data.m_data - 2) = v15 - 1;
}
if ( v15 <= 0 )
operator delete(v13);
}
v6->setVisible(v6, 0);
return v6;
}