//
// SecretLayer2::onDoor from 0x946240 to 0x946678 (1080 bytes)
//
// 3 xrefs:
// > ??> @ 0xa3f50
// > SecretLayer2::init @ 0x942998
// > ??> @ 0x122dab8
//
// 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
//
void SecretLayer2::onDoor(SecretLayer2 *a1, cocos2d::CCObject *a2)
{
GameManager *v3; // x0
char v4; // cf
char v5; // zf
int m_doorDialogIndex; // w0
int v7; // w0
DialogObject *v8; // x0
DialogLayer *v9; // x23
void *v10; // x0
void *v11; // x0
void *v12; // x0
cocos2d::CCDirector *v13; // x20
cocos2d::CCScene *v14; // x0
cocos2d::CCTransitionFade *v15; // x0
unsigned int *v16; // x1
int v17; // w2
unsigned int *v18; // x1
int v19; // w2
unsigned int *v20; // x1
int v21; // w2
__int64 v22; // [xsp+50h] [xbp+50h] BYREF
__int64 v23; // [xsp+58h] [xbp+58h] BYREF
__int64 v24; // [xsp+60h] [xbp+60h] BYREF
v3 = GameManager::sharedState();
if ( GameManager::getUGV(v3, &byte_F2CA20) )
{
v13 = cocos2d::CCDirector::sharedDirector();
v14 = SecretLayer3::scene();
v15 = cocos2d::CCTransitionFade::create(0.5, v14);
cocos2d::CCDirector::replaceScene(v13, v15);
}
else
{
sub_D153B8((int)&v22, "Not allowed");
m_doorDialogIndex = a1->m_doorDialogIndex;
if ( m_doorDialogIndex < 0 )
v7 = llroundf((float)((float)rand() * 4.6566e-10) * 10.0);
else
v7 = m_doorDialogIndex + 1;
a1->m_doorDialogIndex = v7;
if ( !(!v5 & v4) )
{
switch ( v7 )
{
case 0:
goto LABEL_5;
case 1:
sub_D1798C(&v22, "Its too dangerous, just stay here.", 34);
break;
case 2:
sub_D1798C(&v22, "Leave that alone...", 19);
break;
case 3:
sub_D1798C(&v22, "That area is off limits.", 24);
break;
case 4:
sub_D1798C(&v22, "I keep that door locked.\nRubRub's orders.", 47);
break;
case 5:
sub_D1798C(&v22, "I've only been down there once. Its pretty creepy.", 56);
break;
case 6:
sub_D1798C(&v22, "Just forget about it.", 21);
break;
case 7:
sub_D1798C(&v22, "Some things are best left alone.", 32);
break;
case 8:
sub_D1798C(&v22, "Even I dont want to go down there.", 34);
break;
case 9:
sub_D1798C(&v22, "Off. Limits.", 19);
break;
case 10:
sub_D1798C(&v22, "Does the word locked mean nothing to you?", 41);
break;
default:
a1->m_doorDialogIndex = 0;
LABEL_5:
sub_D1798C(&v22, "Sorry, I can't let you in.", 32);
break;
}
}
sub_D153B8((int)&v23, "The Keymaster");
sub_D18D28(&v24);
v8 = (DialogObject *)DialogObject::create(1.0, (__int64)&v23, (__int64)&v24, 2, 0, (int)&unk_FFFFFF);
v9 = DialogLayer::create(v8, (int)&dword_0 + 2);
v10 = (void *)(v24 - 24);
if ( (__int64 *)(v24 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v20 = (unsigned int *)(v24 - 8);
do
v21 = __ldaxr(v20);
while ( __stlxr(v21 - 1, v20) );
}
else
{
v21 = *(_DWORD *)(v24 - 8);
*(_DWORD *)(v24 - 8) = v21 - 1;
}
if ( v21 <= 0 )
operator delete(v10);
}
v11 = (void *)(v23 - 24);
if ( (__int64 *)(v23 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v18 = (unsigned int *)(v23 - 8);
do
v19 = __ldaxr(v18);
while ( __stlxr(v19 - 1, v18) );
}
else
{
v19 = *(_DWORD *)(v23 - 8);
*(_DWORD *)(v23 - 8) = v19 - 1;
}
if ( v19 <= 0 )
operator delete(v11);
}
a1->addChild_0(a1, v9, 100);
DialogLayer::updateChatPlacement(v9, Center);
DialogLayer::animateInRandomSide(v9);
v12 = (void *)(v22 - 24);
if ( (__int64 *)(v22 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v16 = (unsigned int *)(v22 - 8);
do
v17 = __ldaxr(v16);
while ( __stlxr(v17 - 1, v16) );
}
else
{
v17 = *(_DWORD *)(v22 - 8);
*(_DWORD *)(v22 - 8) = v17 - 1;
}
if ( v17 <= 0 )
operator delete(v12);
}
}
}