Esempio n. 1
0
void checkOpenGLHook() {
	static bool bCheckHookActive = false;
	if (bCheckHookActive) {
		ods("OpenGL: Recursion in checkOpenGLHook");
		return;
	}

	bCheckHookActive = true;

	if (!bHooked) {
		HMODULE hGL = GetModuleHandle("OpenGL32.DLL");

		if (lookupSymbols(hGL)) {
			char procname[1024];
			GetModuleFileName(NULL, procname, 1024);
			ods("OpenGL: Hooking into OpenGL App %s", procname);

			// Add a ref to ourselves; we do NOT want to get unloaded directly from this process.
			HMODULE hTempSelf = NULL;
			GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, reinterpret_cast<LPCTSTR>(&checkOpenGLHook), &hTempSelf);

#define INJECT(handle, name) {\
	o##name = reinterpret_cast<t##name>(GetProcAddress(handle, #name));\
	if (o##name) {\
		hh##name.setup(reinterpret_cast<voidFunc>(o##name), reinterpret_cast<voidFunc>(my##name));\
		o##name = (t##name) hh##name.call;\
	} else {\
		ods("OpenGL: Could not resolve symbol %s in %s", #name, #handle);\
	}\
}
			INJECT(hGL, wglSwapBuffers);
		}
	} else {
		hhwglSwapBuffers.check();
	}

	bCheckHookActive = false;
}
Esempio n. 2
0
void checkOpenGLHook() {
    if (bChaining) {
        return;
        ods("Causing a chain");
    }

    bChaining = true;

    HMODULE hGL = GetModuleHandle("OpenGL32.DLL");

    if (hGL != NULL) {
        if (! bHooked) {
            char procname[1024];
            GetModuleFileName(NULL, procname, 1024);
            fods("OpenGL: Unhooked OpenGL App %s", procname);
            bHooked = true;

            // Add a ref to ourselves; we do NOT want to get unloaded directly from this process.
            GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, reinterpret_cast<char *>(&checkOpenGLHook), &hSelf);

            INJECT(wglSwapBuffers);
            // INJECT(wglSwapLayerBuffers);

            GLDEF(wglCreateContext);
            GLDEF(glGenTextures);
            GLDEF(glDeleteTextures);
            GLDEF(glEnable);
            GLDEF(glDisable);
            GLDEF(glBlendFunc);
            GLDEF(glColorMaterial);
            GLDEF(glViewport);
            GLDEF(glMatrixMode);
            GLDEF(glLoadIdentity);
            GLDEF(glOrtho);
            GLDEF(glBindTexture);
            GLDEF(glPushMatrix);
            GLDEF(glColor4ub);
            GLDEF(glTranslatef);
            GLDEF(glBegin);
            GLDEF(glEnd);
            GLDEF(glTexCoord2f);
            GLDEF(glVertex2f);
            GLDEF(glPopMatrix);
            GLDEF(glTexParameteri);
            GLDEF(glTexEnvi);
            GLDEF(glTexImage2D);
            GLDEF(glTexSubImage2D);
            GLDEF(glPixelStorei);
            GLDEF(wglMakeCurrent);
            GLDEF(wglGetCurrentContext);
            GLDEF(wglGetCurrentDC);

            hGL = GetModuleHandle("GDI32.DLL");
            if (hGL) {
                // INJECT(SwapBuffers);
                GLDEF(GetDeviceCaps);
            } else {
                ods("OpenGL: Failed to find GDI32");
            }
        } else {
            hhwglSwapBuffers.check();
        }
    }

    bChaining = false;
}
Esempio n. 3
0
void LGL::InjectAPITracer( sEnvironment* E, sLGLAPI* OldAPI )
{
	APIHook = *OldAPI;
	Env = E;

	sLGLAPI API = *OldAPI;

	INJECT( glActiveTexture )
	INJECT( glAttachShader )
	INJECT( glBeginQuery )
	INJECT( glBindAttribLocation )
	INJECT( glBindBuffer )
	INJECT( glBindBufferBase )
	INJECT( glBindFragDataLocation )
	INJECT( glBindFramebuffer )
	INJECT( glBindTexture )
	INJECT( glBlendFunc )
	INJECT( glBufferData )
	INJECT( glBufferSubData )
	INJECT( glCheckFramebufferStatus )
	INJECT( glClear )
	INJECT( glClearColor )
	INJECT( glClearDepth )
	INJECT( glClearStencil )
	INJECT( glColorMask )
	INJECT( glCompileShader )
	INJECT( glCompressedTexImage2D )
	INJECT( glCompressedTexImage3D )
	INJECT( glCreateProgram )
	INJECT( glCreateShader )
	INJECT( glCullFace )
	INJECT( glDebugMessageCallbackARB )
	INJECT( glDebugMessageControlARB )
	INJECT( glDeleteBuffers )
	INJECT( glDeleteFramebuffers )
	INJECT( glDeleteProgram )
	INJECT( glDeleteQueries )
	INJECT( glDeleteShader )
	INJECT( glDeleteTextures )
	INJECT( glDepthMask )
	INJECT( glDisable )
	INJECT( glDisablei )
	INJECT( glDisableVertexAttribArray )
	INJECT( glDrawArrays )
	INJECT( glDrawArraysInstanced )
	INJECT( glDrawBuffers )
	INJECT( glDrawElements )
	INJECT( glDrawElementsInstanced )
	INJECT( glEnable )
	INJECT( glEnablei )
	INJECT( glEnableVertexAttribArray )
	INJECT( glEndQuery )
	INJECT( glFinish )
	INJECT( glFlush )
	INJECT( glFramebufferTexture2D )
	INJECT( glFramebufferTexture3D )
	INJECT( glGenBuffers )
	INJECT( glGenerateMipmap )
	INJECT( glGenFramebuffers )
	INJECT( glGenQueries )
	INJECT( glGenTextures )
	INJECT( glGetActiveAttrib )
	INJECT( glGetActiveUniform )
	INJECT( glGetActiveUniformBlockiv )
	INJECT( glGetAttribLocation )
	INJECT( glGetCompressedTexImage )
	INJECT( glGetDebugMessageLogARB )
	//INJECT(glGetError)
	INJECT( glGetIntegerv )
	INJECT( glGetProgramBinary );
	INJECT( glGetProgramInfoLog )
	INJECT( glGetProgramiv )
	INJECT( glGetQueryObjectiv )
	INJECT( glGetQueryObjectui64v )
	INJECT( glGetShaderInfoLog )
	INJECT( glGetShaderiv )
	INJECT( glGetString )
	INJECT( glGetTexImage )
	INJECT( glGetTexLevelParameteriv )
	INJECT( glGetUniformLocation )
	INJECT( glIsProgram )
	INJECT( glIsShader )
	INJECT( glLinkProgram )
	INJECT( glPatchParameteri )
	INJECT( glPixelStorei )
	INJECT( glPolygonMode )
	INJECT( glProgramBinary )
	INJECT( glProgramParameteri )
	INJECT( glReadBuffer )
	INJECT( glReadPixels )
	INJECT( glShaderSource )
	INJECT( glTexSubImage2D )
	INJECT( glTexImage2D )
	INJECT( glTexImage3D )
	INJECT( glTexParameterf )
	INJECT( glTexParameteri )
	INJECT( glUniform1f )
	INJECT( glUniform1fv )
	INJECT( glUniform1i )
	INJECT( glUniform1iv )
	INJECT( glUniform3fv )
	INJECT( glUniform4fv )
	INJECT( glUniformBlockBinding )
	INJECT( glUniformMatrix3fv )
	INJECT( glUniformMatrix4fv )
	INJECT( glUseProgram )
	INJECT( glValidateProgram )
	INJECT( glVertexAttribPointer )
	INJECT( glViewport );

	*OldAPI = API;
}