We need hook "GL_LoadTexture" engine function.
GL_LOADTEXTURE_SIG from hw.dll(3266) engine, can not use for other engine version.
1 #include <metahook.h> 2 #include "qgl.h" 3 #include "surface.h" 4 5 extern DWORD g_dwEngineBase, g_dwEngineSize; 6 7 #define GL_LOADTEXTURE_SIG "xA1xC8x20xECx01x8Bx4Cx24x20x8Bx54x24x1Cx50x8Bx44" 8 9 int (*g_pfnGL_LoadTexture)(char *identifier, int textureType, int width, int height, BYTE *data, int mipmap, int iType, BYTE *pPal) = 0; 10 11 int GL_LoadTexture(char *identifier, int textureType, int width, int height, BYTE *data, int mipmap, int iType, BYTE *pPal) 12 { 13 if (width > 512 || height > 512) 14 { 15 static BYTE buffer[2048 * 2048 * 3]; 16 17 for (DWORD i = 0; i < width * height; ++i) 18 { 19 buffer[(i * 3) + 0] = pPal[(data[i] * 3) + 0]; 20 buffer[(i * 3) + 1] = pPal[(data[i] * 3) + 1]; 21 buffer[(i * 3) + 2] = pPal[(data[i] * 3) + 2]; 22 } 23 24 int id = g_pSurface->CreateNewTextureID(); 25 26 qglBindTexture(GL_TEXTURE_2D, id); 27 qglTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer); 28 qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 29 qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 30 31 return id; 32 } 33 34 return g_pfnGL_LoadTexture(identifier, textureType, width, height, data, mipmap, iType, pPal); 35 } 36 37 void Hook_InstallHook(void) 38 { 39 g_pfnGL_LoadTexture = (int (*)(char *, int, int, int, BYTE *, int, int, BYTE *))g_pMetaHookAPI->SearchPattern((void *)g_dwEngineBase, g_dwEngineSize, GL_LOADTEXTURE_SIG, sizeof(GL_LOADTEXTURE_SIG) - 1); 40 41 if (g_pfnGL_LoadTexture) 42 { 43 g_pMetaHookAPI->InlineHook(g_pfnGL_LoadTexture, GL_LoadTexture, (void *&)g_pfnGL_LoadTexture); 44 } 45 }