We need hook "GL_LoadTexture" engine function.
GL_LOADTEXTURE_SIG from hw.dll(3266) engine, can not use for other engine version.
#include <metahook.h>
#include "qgl.h"
#include "surface.h" extern DWORD g_dwEngineBase, g_dwEngineSize; #define GL_LOADTEXTURE_SIG "\xA1\xC8\x20\xEC\x01\x8B\x4C\x24\x20\x8B\x54\x24\x1C\x50\x8B\x44" int (*g_pfnGL_LoadTexture)(char *identifier, int textureType, int width, int height, BYTE *data, int mipmap, int iType, BYTE *pPal) = ; int GL_LoadTexture(char *identifier, int textureType, int width, int height, BYTE *data, int mipmap, int iType, BYTE *pPal)
{
if (width > || height > )
{
static BYTE buffer[ * * ]; for (DWORD i = ; i < width * height; ++i)
{
buffer[(i * ) + ] = pPal[(data[i] * ) + ];
buffer[(i * ) + ] = pPal[(data[i] * ) + ];
buffer[(i * ) + ] = pPal[(data[i] * ) + ];
} int id = g_pSurface->CreateNewTextureID(); qglBindTexture(GL_TEXTURE_2D, id);
qglTexImage2D(GL_TEXTURE_2D, , GL_RGB, width, height, , GL_RGB, GL_UNSIGNED_BYTE, buffer);
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); return id;
} return g_pfnGL_LoadTexture(identifier, textureType, width, height, data, mipmap, iType, pPal);
} void Hook_InstallHook(void)
{
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) - ); if (g_pfnGL_LoadTexture)
{
g_pMetaHookAPI->InlineHook(g_pfnGL_LoadTexture, GL_LoadTexture, (void *&)g_pfnGL_LoadTexture);
}
}