PROC sys_wglGetProcAddress(LPCSTR ProcName) { if (!strcmp(ProcName,"glMultiTexCoord2fARB")) { orig_glMultiTexCoord2fARB=(func_glMultiTexCoord2fARB_t)orig_wglGetProcAddress(ProcName); return (FARPROC)sys_glMultiTexCoord2fARB; } else if (!strcmp(ProcName,"glBindTextureEXT")) { orig_BindTextureEXT=(func_BindTextureEXT_t)orig_wglGetProcAddress(ProcName); return (FARPROC)sys_BindTextureEXT; } else if(!strcmp(ProcName,"glActiveTextureARB")) { orig_glActiveTextureARB=(func_glActiveTextureARB_t)orig_wglGetProcAddress(ProcName); return (FARPROC)sys_glActiveTextureARB; } return orig_wglGetProcAddress(ProcName); }
void sys_glLinkProgram(GLuint program) { // Link the original program now that the correct shaders are swapped (*orig_glLinkProgram)(program); //Check for error GLint LinkOK = 0; orig_glGetProgramiv = (func_glGetProgramiv_t)orig_wglGetProcAddress("glGetProgramiv"); (*orig_glGetProgramiv)(program, GL_LINK_STATUS, &LinkOK); if (LinkOK == GL_FALSE) { CheckLinkState(program); } }
void sys_glCompileShader(GLuint shader) { // Compile the shader (*orig_glCompileShader)(shader); // Check to see if the compile was ok GLint OK = GL_FALSE; orig_glGetShaderiv = (func_glGetShaderiv_t)orig_wglGetProcAddress("glGetShaderiv"); (*orig_glGetShaderiv)(shader, GL_COMPILE_STATUS, &OK); if (OK == GL_FALSE) { CheckCompileState(shader); exit(0); } }
PROC sys_wglGetProcAddress(LPCSTR ProcName) { std::string injectionPoint = g_reader->GetInjectionPoint(); if (!strcmp(ProcName, "glUseProgram")) { orig_glUseProgram = (funct_glUseProgram_t)orig_wglGetProcAddress(ProcName); return (FARPROC)sys_glUseProgram; } // ARB Variant else if (!strcmp(ProcName, "glUseProgramObjectARB")) { orig_glUseProgramObjectARB = (funct_glUseProgram_t)orig_wglGetProcAddress(ProcName); return (FARPROC)sys_glUseProgramObjectARB; } else if (!strcmp(ProcName, "glCreateProgram")) { orig_glCreateProgram = (funct_glCreateProgram_t)orig_wglGetProcAddress(ProcName); return (FARPROC)sys_glCreateProgram; } else if (!strcmp(ProcName, "glAttachShader")) { orig_glAttachShader = (func_glAttachShader_t)orig_wglGetProcAddress(ProcName); return (FARPROC)sys_glAttachShader; } else if (!strcmp(ProcName, "glShaderSource")) { orig_glShaderSource = (funct_glShaderSource_t)orig_wglGetProcAddress(ProcName); return (FARPROC)sys_glShaderSource; } else if (!strcmp(ProcName, "glBindFramebuffer")) { orig_glBindFramebuffer = (func_glBindFramebuffer_t)orig_wglGetProcAddress(ProcName); return (FARPROC)sys_glBindFramebuffer; } else if (!strcmp(ProcName, "glBindFramebufferEXT")) { orig_glBindFramebuffer = (func_glBindFramebuffer_t)orig_wglGetProcAddress(ProcName); return (FARPROC)sys_glBindFramebuffer; } else if (!strcmp(ProcName, "glBindFramebufferARB")) { orig_glBindFramebuffer = (func_glBindFramebuffer_t)orig_wglGetProcAddress(ProcName); return (FARPROC)sys_glBindFramebuffer; } else if (!strcmp(ProcName, "glLinkProgram")) { orig_glLinkProgram = (func_glLinkProgram_t)orig_wglGetProcAddress(ProcName); return (FARPROC)sys_glLinkProgram; } else if (!strcmp(ProcName, "glCompileShader")) { orig_glCompileShader = (func_glCompileShader)orig_wglGetProcAddress(ProcName); return (FARPROC)sys_glCompileShader; } return orig_wglGetProcAddress(ProcName); }
// We will inject the stereo here void sys_glAttachShader(GLuint program, GLuint shader) { m_opengl32Mutex.lock(); orig_glCompileShader = (func_glCompileShader)orig_wglGetProcAddress("glCompileShader"); if (orig_glCompileShader == 0x0) add_log("glCompileShader not found !!!!"); orig_glGetShaderiv = (func_glGetShaderiv_t)orig_wglGetProcAddress("glGetShaderiv"); if (orig_glGetShaderiv == 0x0) add_log("glGetShaderiv not found !!!!"); // Add the CRC of the program std::string programSring = std::to_string(program); DWORD progCRC32 = crc32buf(programSring.c_str(), programSring.length()); // Get the correct shader type // Get the instance ShaderManager *shaderManager = ShaderManager::getInstance(); // Depends on what type of shader it is we do stuff if (shaderManager->isShaderType(shader, GL_VERTEX_SHADER)) { //get the original shader Source std::string shaderSource = shaderManager->getShaderSource(shader); // Calculate the CRC32 before we do any injection // Otherwise the CRC32 will change DWORD crc32 = crc32buf(shaderSource.c_str(), shaderSource.length()); crc32 += progCRC32; if (shaderManager->GetVertexInjectionState()) { //Apply the custom shaders // If we failed apply normal injection if (shaderManager->ApplyExceptionShaders(shaderSource, GL_VERTEX_SHADER, crc32) == false) { //Insert Stereo shaderSource = shaderManager->injectStereoScopy(shaderSource, program); } } // Swap the Source shaderManager->applyShaderSource(shader, shaderSource, NULL); // Store it as an existing shader EXISTING_SHADER_T currentShader; currentShader.m_CRC32 = crc32; currentShader.m_programId = program; currentShader.m_shaderId = shader; currentShader.m_shaderSourceCode = shaderSource; currentShader.m_shaderType = GL_VERTEX_SHADER; // Push it back shaderManager->addExistingShaderInfo(currentShader); // Export the Source ExportShader("Vertex", currentShader.m_programId, currentShader.m_CRC32, currentShader.m_shaderSourceCode); // We also need to compile the shader before attaching it //Compile shader (*orig_glCompileShader)(shader); //Test compile GLint statusOk = 0; (*orig_glGetShaderiv)(shader, GL_COMPILE_STATUS, &statusOk); if (statusOk == GL_FALSE) { CheckCompileState(shader); } } else if (shaderManager->isShaderType(shader, GL_FRAGMENT_SHADER)) { //get the original shader Source std::string shaderSource = shaderManager->getShaderSource(shader); // Calculate the CRC32 DWORD crc32 = crc32buf(shaderSource.c_str(), shaderSource.length()); crc32 += progCRC32; if (shaderManager->GetVertexInjectionState()) { //Apply the custom shaders // If we failed apply normal injection if (shaderManager->ApplyExceptionShaders(shaderSource, GL_FRAGMENT_SHADER, crc32) == false) { // This only happens in development mode. #ifdef DEBUG_WRAPPER //Insert Stereo shaderSource = shaderManager->injectFragmentModification(shaderSource, program); #endif } } // Swap the Source shaderManager->applyShaderSource(shader, shaderSource, NULL); // Store it as an existing shader EXISTING_SHADER_T currentShader; currentShader.m_CRC32 = crc32; currentShader.m_programId = program; currentShader.m_shaderId = shader; currentShader.m_shaderSourceCode = shaderSource; currentShader.m_shaderType = GL_FRAGMENT_SHADER; // Push it back shaderManager->addExistingShaderInfo(currentShader); // Export the Source ExportShader("Pixel", currentShader.m_programId, currentShader.m_CRC32, currentShader.m_shaderSourceCode); //Compile shader (*orig_glCompileShader)(shader); // We also need to compile the shader before attaching it //Test compile GLint statusOk = 0; (*orig_glGetShaderiv)(shader, GL_COMPILE_STATUS, &statusOk); if (statusOk == GL_FALSE) { CheckCompileState(shader); } } // We attach after we swapped the sources (*orig_glAttachShader)(program, shader); m_opengl32Mutex.unlock(); }