• [MetaHook] Load large texture from model


    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 }
  • 相关阅读:
    Java学习笔记二.2
    Java学习笔记二.1
    Java学习笔记一
    cookie和session笔记
    编码知识笔记
    新手前端笔记之--css盒子
    新手前端笔记之--初识css
    新手前端笔记之--必备的标签
    新手前端笔记之--初识html标签
    二叉树总结
  • 原文地址:https://www.cnblogs.com/crsky/p/4703022.html
Copyright © 2020-2023  润新知