//
// cocos2d::CCTouchDispatcher::touches from 0x1004cc540 to 0x1004ccb8b (1611 bytes)
//
// 8 xrefs:
// > cocos2d::CCTouchDispatcher::touchesBegan @ 0x1004ccbad
// > sub_1004CCBC0 @ 0x1004ccbd1
// > cocos2d::CCTouchDispatcher::touchesMoved @ 0x1004ccbf0
// > sub_1004CCC00 @ 0x1004ccc14
// > cocos2d::CCTouchDispatcher::touchesEnded @ 0x1004ccc30
// > sub_1004CCC40 @ 0x1004ccc54
// > cocos2d::CCTouchDispatcher::touchesCancelled @ 0x1004ccc70
// > sub_1004CCC80 @ 0x1004ccc94
//
// 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 __fastcall cocos2d::CCTouchDispatcher::touches(
cocos2d::CCTouchDispatcher *a1,
cocos2d::CCSet *a2,
cocos2d::CCEvent *a3,
unsigned int a4)
{
cocos2d::CCTouchDispatcher *v5; // r12
int v6; // r15d
int v7; // eax
cocos2d::CCSet *v8; // r13
cocos2d::CCSetIterator v9; // r15
cocos2d::CCArray *m_pTargetedHandlers; // rax
cocos2d::ccArray *data; // rax
cocos2d::CCObject *v12; // r13
cocos2d::CCTouchHandler **arr; // r14
unsigned __int64 v14; // rbx
cocos2d::CCTargetedTouchHandler *v15; // r12
cocos2d::CCTouchDelegate *Delegate; // rax
cocos2d::CCSet *ClaimedTouches; // rax
std::__tree_end_node *>::pointer left; // rax
std::__tree_end_node *> *v19; // rbx
bool v20; // zf
cocos2d::CCTouchDelegate *v21; // rax
cocos2d::CCSet *v22; // rax
cocos2d::CCTargetedTouchHandler *v23; // r12
cocos2d::CCSet *v24; // rax
cocos2d::CCTouchDelegate *v25; // rax
cocos2d::CCTouchDelegate *v26; // rax
cocos2d::CCArray *m_pStandardHandlers; // rax
cocos2d::ccArray *v28; // rax
cocos2d::CCTouchHandler **v29; // rbx
unsigned __int64 v30; // r14
cocos2d::CCTouchDelegate *v31; // rax
cocos2d::CCTouchDelegate *v32; // rax
cocos2d::CCTouchDelegate *v33; // rax
cocos2d::CCTouchDelegate *v34; // rax
cocos2d::_ccCArray *m_pHandlersToRemove; // rdi
unsigned __int64 v36; // rbx
cocos2d::CCArray *m_pHandlersToAdd; // rdi
cocos2d::ccArray *v38; // rax
__int64 num; // rcx
cocos2d::CCTouchHandler **v40; // rax
cocos2d::CCTouchHandler *v41; // rdi
cocos2d::CCArray *v42; // rax
__int64 v43; // rdx
cocos2d::ccArray *v44; // rax
cocos2d::CCTouchHandler **v45; // r12
cocos2d::CCTouchHandler *v46; // r13
int Priority; // r15d
int v48; // ebx
cocos2d::CCTouchDelegate *v49; // r13
cocos2d::CCArray *v50; // rax
cocos2d::ccArray *v51; // rax
cocos2d::CCTouchHandler **v52; // r12
cocos2d::CCTouchHandler *v53; // r13
int v54; // r15d
int v55; // ebx
cocos2d::CCTouchDelegate *v56; // r13
cocos2d::CCSet *v58; // [rsp+10h] [rbp-60h]
unsigned int v59; // [rsp+18h] [rbp-58h]
cocos2d::CCTouchHandler **v60; // [rsp+18h] [rbp-58h]
unsigned __int64 v61; // [rsp+20h] [rbp-50h]
unsigned __int64 v62; // [rsp+20h] [rbp-50h]
int v63; // [rsp+28h] [rbp-48h]
unsigned __int64 v64; // [rsp+28h] [rbp-48h]
bool v65; // [rsp+30h] [rbp-40h]
cocos2d::CCArray *v66; // [rsp+30h] [rbp-40h]
int m_type; // [rsp+44h] [rbp-2Ch]
int v69; // [rsp+44h] [rbp-2Ch]
int v70; // [rsp+44h] [rbp-2Ch]
v5 = a1;
a1->m_bLocked = 1;
v6 = sub_100720070(a1->m_pTargetedHandlers);
v7 = sub_100720070(a1->m_pStandardHandlers);
v63 = v7;
v65 = v6 != 0 && v7 != 0;
if ( v65 )
{
v8 = cocos2d::CCSet::mutableCopy(a2);
m_type = a1->m_sHandlerHelperData[a4].m_type;
}
else
{
m_type = a1->m_sHandlerHelperData[a4].m_type;
v8 = a2;
if ( !v6 )
{
v8 = a2;
if ( !v7 )
goto LABEL_52;
goto LABEL_35;
}
}
v9.__ptr_ = cocos2d::CCSet::begin(a2).__ptr_;
if ( v9.__ptr_ != cocos2d::CCSet::end(a2).__ptr_ )
{
v59 = a4;
v58 = v8;
while ( 1 )
{
m_pTargetedHandlers = v5->m_pTargetedHandlers;
if ( m_pTargetedHandlers )
{
data = m_pTargetedHandlers->data;
if ( data->num )
break;
}
LABEL_17:
left = v9.__ptr_[1].__left_;
if ( left )
{
do
{
v19 = (std::__tree_end_node *> *)left;
left = *(std::__tree_end_node *>::pointer *)left;
}
while ( left );
}
else
{
do
{
v19 = (std::__tree_end_node *> *)v9.__ptr_[2].__left_;
v20 = v19->__left_ == (std::__tree_end_node *>::pointer)v9.__ptr_;
v9.__ptr_ = v19;
}
while ( !v20 );
}
v9.__ptr_ = v19;
v5 = a1;
if ( v19 == cocos2d::CCSet::end(a2).__ptr_ )
{
v8 = v58;
goto LABEL_34;
}
}
v12 = (cocos2d::CCObject *)v9.__ptr_[4].__left_;
arr = (cocos2d::CCTouchHandler **)data->arr;
v14 = (unsigned __int64)&arr[data->num - 1];
if ( !v59 )
{
while ( 1 )
{
v15 = (cocos2d::CCTargetedTouchHandler *)*arr;
if ( !*arr )
goto LABEL_17;
Delegate = cocos2d::CCTouchHandler::getDelegate(*arr);
if ( ((unsigned __int8 (__fastcall *)(cocos2d::CCTouchDelegate *, cocos2d::CCObject *, cocos2d::CCEvent *))Delegate->ccTouchBegan)(
Delegate,
v12,
a3) )
{
ClaimedTouches = cocos2d::CCTargetedTouchHandler::getClaimedTouches(v15);
cocos2d::CCSet::addObject(ClaimedTouches, v12);
if ( cocos2d::CCTargetedTouchHandler::isSwallowsTouches(v15) )
goto LABEL_15;
}
if ( (unsigned __int64)++arr > v14 )
goto LABEL_17;
}
}
while ( 1 )
{
v23 = (cocos2d::CCTargetedTouchHandler *)*arr;
if ( !*arr )
goto LABEL_17;
v24 = cocos2d::CCTargetedTouchHandler::getClaimedTouches((cocos2d::CCTargetedTouchHandler *)*arr);
if ( cocos2d::CCSet::containsObject(v24, v12) )
break;
LABEL_25:
if ( (unsigned __int64)++arr > v14 )
goto LABEL_17;
}
if ( m_type == 3 )
{
v26 = cocos2d::CCTouchHandler::getDelegate(v23);
((void (__fastcall *)(cocos2d::CCTouchDelegate *, cocos2d::CCObject *, cocos2d::CCEvent *))v26->ccTouchCancelled)(
v26,
v12,
a3);
}
else
{
if ( m_type != 2 )
{
if ( m_type == 1 )
{
v25 = cocos2d::CCTouchHandler::getDelegate(v23);
((void (__fastcall *)(cocos2d::CCTouchDelegate *, cocos2d::CCObject *, cocos2d::CCEvent *))v25->ccTouchMoved)(
v25,
v12,
a3);
}
LABEL_24:
if ( cocos2d::CCTargetedTouchHandler::isSwallowsTouches(v23) )
{
LABEL_15:
if ( v65 )
cocos2d::CCSet::removeObject(v58, v12);
goto LABEL_17;
}
goto LABEL_25;
}
v21 = cocos2d::CCTouchHandler::getDelegate(v23);
((void (__fastcall *)(cocos2d::CCTouchDelegate *, cocos2d::CCObject *, cocos2d::CCEvent *))v21->ccTouchEnded)(
v21,
v12,
a3);
}
v22 = cocos2d::CCTargetedTouchHandler::getClaimedTouches(v23);
cocos2d::CCSet::removeObject(v22, v12);
goto LABEL_24;
}
LABEL_34:
if ( !v63 )
goto LABEL_52;
LABEL_35:
if ( cocos2d::CCSet::count(v8) > 0 )
{
m_pStandardHandlers = v5->m_pStandardHandlers;
if ( m_pStandardHandlers )
{
v28 = m_pStandardHandlers->data;
if ( v28->num )
{
v29 = (cocos2d::CCTouchHandler **)v28->arr;
v30 = (unsigned __int64)&v29[v28->num - 1];
switch ( m_type )
{
case 0:
do
{
if ( !*v29 )
break;
v31 = cocos2d::CCTouchHandler::getDelegate(*v29);
((void (__fastcall *)(cocos2d::CCTouchDelegate *, cocos2d::CCSet *, cocos2d::CCEvent *))v31->ccTouchesBegan)(
v31,
v8,
a3);
++v29;
}
while ( (unsigned __int64)v29 <= v30 );
break;
case 1:
do
{
if ( !*v29 )
break;
v34 = cocos2d::CCTouchHandler::getDelegate(*v29);
((void (__fastcall *)(cocos2d::CCTouchDelegate *, cocos2d::CCSet *, cocos2d::CCEvent *))v34->ccTouchesMoved)(
v34,
v8,
a3);
++v29;
}
while ( (unsigned __int64)v29 <= v30 );
break;
case 2:
do
{
if ( !*v29 )
break;
v32 = cocos2d::CCTouchHandler::getDelegate(*v29);
((void (__fastcall *)(cocos2d::CCTouchDelegate *, cocos2d::CCSet *, cocos2d::CCEvent *))v32->ccTouchesEnded)(
v32,
v8,
a3);
++v29;
}
while ( (unsigned __int64)v29 <= v30 );
break;
case 3:
do
{
if ( !*v29 )
break;
v33 = cocos2d::CCTouchHandler::getDelegate(*v29);
((void (__fastcall *)(cocos2d::CCTouchDelegate *, cocos2d::CCSet *, cocos2d::CCEvent *))v33->ccTouchesCancelled)(
v33,
v8,
a3);
++v29;
}
while ( (unsigned __int64)v29 <= v30 );
break;
default:
break;
}
}
}
}
LABEL_52:
if ( v65 )
{
cocos2d::CCObject::release(v8);
v5->m_bLocked = 0;
if ( !v5->m_bToRemove )
{
LABEL_54:
if ( !v5->m_bToAdd )
goto LABEL_55;
LABEL_62:
v5->m_bToAdd = 0;
m_pHandlersToAdd = v5->m_pHandlersToAdd;
if ( m_pHandlersToAdd )
{
v38 = m_pHandlersToAdd->data;
num = v38->num;
if ( v38->num )
{
v40 = (cocos2d::CCTouchHandler **)v38->arr;
v64 = (unsigned __int64)&v40[num - 1];
do
{
v41 = *v40;
if ( !*v40 )
break;
v60 = v40;
if ( __dynamic_cast(
v41,
(const struct __class_type_info *)&`typeinfo for'cocos2d::CCTouchHandler,
(const struct __class_type_info *)&`typeinfo for'cocos2d::CCTargetedTouchHandler,
0) )
{
v42 = v5->m_pTargetedHandlers;
v43 = 0;
v66 = v42;
if ( v42 )
{
v44 = v42->data;
if ( v44->num )
{
v45 = (cocos2d::CCTouchHandler **)v44->arr;
v61 = (unsigned __int64)&v45[v44->num - 1];
v43 = 0;
do
{
v46 = *v45;
if ( !*v45 )
break;
v69 = v43;
Priority = cocos2d::CCTouchHandler::getPriority(v46);
v48 = cocos2d::CCTouchHandler::getPriority(v41);
v49 = cocos2d::CCTouchHandler::getDelegate(v46);
if ( v49 == cocos2d::CCTouchHandler::getDelegate(v41) )
goto LABEL_66;
v43 = (unsigned int)(Priority < v48) + v69;
++v45;
}
while ( (unsigned __int64)v45 <= v61 );
}
}
}
else
{
v50 = v5->m_pStandardHandlers;
v43 = 0;
v66 = v50;
if ( v50 )
{
v51 = v50->data;
if ( v51->num )
{
v52 = (cocos2d::CCTouchHandler **)v51->arr;
v62 = (unsigned __int64)&v52[v51->num - 1];
v43 = 0;
do
{
v53 = *v52;
if ( !*v52 )
break;
v70 = v43;
v54 = cocos2d::CCTouchHandler::getPriority(v53);
v55 = cocos2d::CCTouchHandler::getPriority(v41);
v56 = cocos2d::CCTouchHandler::getDelegate(v53);
if ( v56 == cocos2d::CCTouchHandler::getDelegate(v41) )
goto LABEL_66;
v43 = (unsigned int)(v54 < v55) + v70;
++v52;
}
while ( (unsigned __int64)v52 <= v62 );
}
}
}
sub_1007201F0(v66, v41, v43);
LABEL_66:
v40 = v60 + 1;
v5 = a1;
}
while ( (unsigned __int64)(v60 + 1) <= v64 );
m_pHandlersToAdd = v5->m_pHandlersToAdd;
}
sub_100720270(m_pHandlersToAdd);
if ( v5->m_bToQuit )
goto LABEL_56;
}
else
{
sub_100720270(0);
if ( v5->m_bToQuit )
goto LABEL_56;
}
return;
}
}
else
{
v5->m_bLocked = 0;
if ( !v5->m_bToRemove )
goto LABEL_54;
}
v5->m_bToRemove = 0;
m_pHandlersToRemove = v5->m_pHandlersToRemove;
if ( m_pHandlersToRemove->num )
{
v36 = 0;
do
{
cocos2d::CCTouchDispatcher::forceRemoveDelegate(v5, (cocos2d::CCTouchDelegate *)m_pHandlersToRemove->arr[v36++]);
m_pHandlersToRemove = v5->m_pHandlersToRemove;
}
while ( v36 < m_pHandlersToRemove->num );
}
sub_1006682A0();
if ( v5->m_bToAdd )
goto LABEL_62;
LABEL_55:
if ( v5->m_bToQuit )
{
LABEL_56:
v5->m_bToQuit = 0;
sub_100720270(v5->m_pStandardHandlers);
sub_100720270(v5->m_pTargetedHandlers);
}
}