//
// ShaderLayer::setupShader from 0x9f7224 to 0x9f772c (1288 bytes)
//
// 5 xrefs:
// > GameManager::applicationWillEnterForeground @ 0x5f3ec8
// > GameManager::applicationWillEnterForeground @ 0x5f3efc
// > ShaderLayer::update @ 0x9f9c94
// > ShaderLayer::init @ 0x9f9d04
// > ??> @ 0xacc98
//
// 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 ShaderLayer::setupShader(ShaderLayer *a1, bool a2)
{
_BOOL4 v2; // w22
cocos2d::CCSprite *m_sprite; // x0
cocos2d::CCRenderTexture *m_renderTexture; // x0
cocos2d::CCShaderCache *v6; // x0
cocos2d::CCGLProgram *v7; // x0
cocos2d::CCDirector *v8; // x0
const cocos2d::CCSize *v9; // x0
float height; // s9
cocos2d::CCDirector *v11; // x0
float v12; // s0
cocos2d::CCDirector *v13; // x0
float v14; // s0
float v15; // s9
cocos2d::CCDirector *v16; // x0
cocos2d::CCDirector *v17; // x0
cocos2d::CCDirector *v18; // x0
float v19; // s0
cocos2d::CCSprite *v20; // x0
cocos2d::CCSprite_vtbl *v21; // x2
cocos2d::CCRenderTexture *v22; // x1
cocos2d::CCSprite *v23; // x22
void (__fastcall *setTexture)(cocos2d::CCSprite *__hidden, cocos2d::CCTexture2D *); // x23
__int64 v25; // x0
__int64 v26; // x0
cocos2d::CCTexture2D *v27; // x0
cocos2d::CCSprite *v28; // x22
void (__fastcall *setTextureRect)(cocos2d::CCSprite *__hidden, const cocos2d::CCRect *); // x23
GameManager *v30; // x0
bool GameVariable; // w0
cocos2d::CCGLProgram *m_shader; // x22
void *v33; // x0
cocos2d::CCGLProgram *v34; // x22
cocos2d::CCShaderCache *v35; // x0
unsigned int *v36; // x2
int v37; // w1
char *v38; // [xsp+58h] [xbp+58h]
cocos2d::CCSize v39; // [xsp+60h] [xbp+60h] BYREF
cocos2d::CCRect v40; // [xsp+68h] [xbp+68h] BYREF
v2 = a2;
m_sprite = a1->m_sprite;
if ( m_sprite )
{
m_sprite->removeMeAndCleanup(m_sprite);
a1->m_sprite = nullptr;
}
m_renderTexture = a1->m_renderTexture;
if ( m_renderTexture )
{
cocos2d::CCObject::release(m_renderTexture);
a1->m_renderTexture = nullptr;
}
v6 = cocos2d::CCShaderCache::sharedShaderCache();
v7 = cocos2d::CCShaderCache::programForKey(v6, "custom_program");
a1->m_shader = v7;
if ( v7 )
{
if ( !v2 )
goto LABEL_7;
cocos2d::CCGLProgram::reset(v7);
}
else
{
v34 = (cocos2d::CCGLProgram *)operator new(0x78u);
cocos2d::CCGLProgram::CCGLProgram(v34);
a1->m_shader = v34;
v35 = cocos2d::CCShaderCache::sharedShaderCache();
cocos2d::CCShaderCache::addProgram(v35, a1->m_shader, "custom_program");
cocos2d::CCObject::release(a1->m_shader);
}
m_shader = a1->m_shader;
v38 = (char *)vertTest();
uberShader((__int64)&v40);
cocos2d::CCGLProgram::initWithVertexShaderByteArray(m_shader, v38, *(const char **)&v40.origin);
v33 = (void *)(*(_QWORD *)&v40.origin - 24LL);
if ( (__int64 *)(*(_QWORD *)&v40.origin - 24LL) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v36 = (unsigned int *)(*(_QWORD *)&v40.origin - 8LL);
do
v37 = __ldaxr(v36);
while ( __stlxr(v37 - 1, v36) );
}
else
{
v37 = *(_DWORD *)(*(_QWORD *)&v40.origin - 8LL);
*(_DWORD *)(*(_QWORD *)&v40.origin - 8LL) = v37 - 1;
}
if ( v37 <= 0 )
operator delete(v33);
}
cocos2d::CCGLProgram::addAttribute(a1->m_shader, "a_position", 0);
cocos2d::CCGLProgram::addAttribute(a1->m_shader, "a_color", 1u);
cocos2d::CCGLProgram::addAttribute(a1->m_shader, "a_texCoord", 2u);
cocos2d::CCGLProgram::link(a1->m_shader);
cocos2d::CCGLProgram::updateUniforms(a1->m_shader);
GameManager::sharedState()->m_shouldResetShader = 0;
LABEL_7:
v8 = cocos2d::CCDirector::sharedDirector();
v9 = v8->m_pobOpenGLView->getFrameSize(v8->m_pobOpenGLView);
cocos2d::CCSize::CCSize(&v39, v9);
cocos2d::CCSize::operator=(&a1->m_screenSize, &v39);
height = v39.height;
v11 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getWinSize(v11);
v12 = 1.0 / (float)(a1->m_screenSize.height / a1->m_screenSize.width);
a1->m_scaleFactor = height / v40.origin.y;
a1->m_aspectRatio = v12;
v13 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getContentScaleFactor(v13);
v15 = v14;
v16 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::setContentScaleFactor(v16, 1.0);
a1->m_renderTexture = cocos2d::CCRenderTexture::create((int)v39.width, (int)v39.height);
v17 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::setContentScaleFactor(v17, v15);
v18 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getScreenScaleFactorW(v18);
a1->m_shockWaveTimeMult = (float)(1.0 / v19) * 1.2019;
cocos2d::CCSize::CCSize((cocos2d::CCSize *)&v40, 0.0, 0.0);
cocos2d::CCSize::operator=(&a1->m_targetTextureSizeExtra, &v40);
cocos2d::CCObject::retain(a1->m_renderTexture);
v20 = cocos2d::CCSprite::create();
v21 = v20->cocos2d::CCNodeRGBA::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
v22 = a1->m_renderTexture;
v23 = v20;
a1->m_sprite = v20;
setTexture = v21->setTexture;
v25 = (__int64)v22->getSprite(v22);
v26 = (*(__int64 (__fastcall **)(__int64))(*(_QWORD *)v25 + 1056LL))(v25);
setTexture(v23, (cocos2d::CCTexture2D *)v26);
v27 = a1->m_sprite->getTexture(a1->m_sprite);
v27->getContentSize(v27);
cocos2d::CCSize::operator=(&a1->m_textureContentSize, &v40);
cocos2d::CCSize::CCSize((cocos2d::CCSize *)&v40, v39.width, v39.height);
cocos2d::CCSize::operator=(&a1->m_targetTextureSize, &v40);
v28 = a1->m_sprite;
setTextureRect = v28->setTextureRect;
cocos2d::CCRect::CCRect(&v40, -1.0, -1.0, a1->m_targetTextureSize.width + 2.0, a1->m_targetTextureSize.height + 2.0);
setTextureRect(v28, &v40);
a1->m_sprite->setPosition(a1->m_sprite, &stru_1243F90);
a1->m_sprite->setAnchorPoint(a1->m_sprite, &stru_1243F90);
cocos2d::CCSprite::setFlipY(a1->m_sprite, 1);
a1->addChild(a1, a1->m_sprite);
v30 = GameManager::sharedState();
GameVariable = GameManager::getGameVariable(v30, "0155");
a1->m_configuredAntiAlias = !GameVariable;
ShaderLayer::toggleAntiAlias(a1, !GameVariable);
a1->m_sprite->setShaderProgram(a1->m_sprite, a1->m_shader);
ShaderLayer::setupCommonUniforms(a1);
ShaderLayer::setupShockWaveUniforms(a1);
ShaderLayer::setupShockLineUniforms(a1);
ShaderLayer::setupGlitchUniforms(a1);
ShaderLayer::setupChromaticUniforms(a1);
ShaderLayer::setupChromaticGlitchUniforms(a1);
ShaderLayer::setupLensCircleShader(a1);
ShaderLayer::setupRadialBlurShader(a1);
ShaderLayer::setupBulgeShader(a1);
ShaderLayer::setupPinchShader(a1);
ShaderLayer::setupMotionBlurShader(a1);
ShaderLayer::setupGrayscaleShader(a1);
ShaderLayer::setupSepiaShader(a1);
ShaderLayer::setupInvertColorShader(a1);
ShaderLayer::setupHueShiftShader(a1);
ShaderLayer::setupColorChangeShader(a1);
ShaderLayer::setupSplitScreenShader(a1);
}