Skip to content

Commit

Permalink
Fix dynamic shader loading crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Ch40zz committed Mar 8, 2024
1 parent 2d99642 commit 792f6a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
14 changes: 5 additions & 9 deletions CCHookReloaded/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,11 @@ EMod InitializeMod()
}\n\
}");

// Disable dynamic shader loading for ET:Legacy client. they have a bug which crashes the game on `vid_restart`...
if (!off::cur.IsEtLegacy())
{
media.coverShader = eng::RegisterAndLoadShader(coverShaderText.decrypt(), spoofSeed + 0);
media.plainShader = eng::RegisterAndLoadShader(plainShaderText.decrypt(), spoofSeed + 1);
media.quadShader = eng::RegisterAndLoadShader(quadShaderText.decrypt(), spoofSeed + 2);
media.plasticShader = eng::RegisterAndLoadShader(plasticShaderText.decrypt(), spoofSeed + 3);
media.circleShader = eng::RegisterAndLoadShader(circleShaderText.decrypt(), spoofSeed + 4);
}
media.coverShader = eng::RegisterAndLoadShader(coverShaderText.decrypt(), spoofSeed + 0);
media.plainShader = eng::RegisterAndLoadShader(plainShaderText.decrypt(), spoofSeed + 1);
media.quadShader = eng::RegisterAndLoadShader(quadShaderText.decrypt(), spoofSeed + 2);
media.plasticShader = eng::RegisterAndLoadShader(plasticShaderText.decrypt(), spoofSeed + 3);
media.circleShader = eng::RegisterAndLoadShader(circleShaderText.decrypt(), spoofSeed + 4);

media.railCoreShader = DoSyscall(CG_R_REGISTERSHADERNOMIP, XorString("railCore"));
media.onFireShader = DoSyscall(CG_R_REGISTERSHADERNOMIP, XorString("entityOnFire1"));
Expand Down
16 changes: 15 additions & 1 deletion CCHookReloaded/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,20 @@ namespace eng
return 0;

(void)DoSyscall(CG_R_LOADDYNAMICSHADER, shaderName, newShaderData);
return DoSyscall(CG_R_REGISTERSHADER, shaderName);
qhandle_t shaderHandle = DoSyscall(CG_R_REGISTERSHADER, shaderName);

// Immediately delete the dynamic shaders after registration.
// ET:Legacy client crashes otherwise, as they have a bug which crashes the game on `vid_restart` when the dynamic shader list isn't empty...
//
// Crash callstack:
// R_InitShaders()
// CreateExternalShaders()
// R_FindShader("projectionShadow")
// FindShaderInShaderText()
// if (!dptr->shadertext || !strlen(dptr->shadertext))
// dptr->shadertext == 0xAAAAAAAA
DoSyscall(CG_R_LOADDYNAMICSHADER, nullptr, nullptr);

return shaderHandle;
}
}

0 comments on commit 792f6a3

Please sign in to comment.