[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 "\xA1\xC8\x20\xEC\x01\x8B\x4C\x24\x20\x8B\x54\x24\x1C\x50\x8B\x44"
 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 }
时间: 2024-10-10 13:18:38

[MetaHook] Load large texture from model的相关文章

[MetaHook] Load TGA texture to OpenGL

This function load a *.tga texture file and convert to OpenGL pixel format, uncompress only. 1 #pragma pack(1) 2 3 struct TgaHeader 4 { 5 unsigned char m_IDLength; 6 unsigned char m_ColorMapType; 7 unsigned char m_ImageType; 8 unsigned short m_CMapSt

[MetaHook] Load DTX texture to OpenGL

This function load a LithTech *.dtx texture file and convert to OpenGL pixel format, compressed support. Use FileSystem interface. :D 1 #pragma pack(1) 2 3 struct DtxHeader 4 { 5 unsigned int iResType; 6 int iVersion; 7 unsigned short usWidth; 8 unsi

Projective Texture的原理与实现 【转】

Projective Texture是比较常见的一种技术,实现起来代码也就区区的不过百行,了解其原理及技术细节是我们的重点,知其然,知其所以然. 粗略的说就是想象场景中有台投影仪(Projector),texture就是我们投影的内容,把纹理放在近裁剪面(near clip plane)上,沿着投影仪的方向把纹理投影到场景中.Xheartblue兄翻译了一篇文章,很好的给投影纹理的原理进行的阐述[1],有兴趣阅读原文 的可以访问这里[2],这本书可以是好东东啊!! 在这里有几个概念不能混淆 了:

&quot;NHibernate.Exceptions.GenericADOException: could not load an entity&quot; 解决方案

今天,测试一个项目的时候,抛出了这个莫名其妙的异常,然后就开始了一天的调试之旅... 花了很长时间,没有从代码找出任何问题... 那么到底哪里出问题呢? 根据下面那段长长的错误日志: 2017-01-06 17:07:03,680 [19] XxxXxxxx.Web.Mvc.Controllers.WarningController - UnhandleError guest /master/poitem NHibernate.Exceptions.GenericADOException: co

UnityException: Texture is not readable

原地址:http://blog.csdn.net/emoonight/article/details/18002913 fore you can save or load a Texture, you must make it editable. To do this, click the Texture in the Project hierarchy, set the Texture Type toAdvanced and then select Read/Write Enabled Uni

ExtJS笔记 Ext.data.Model

A Model represents some object that your application manages. For example, one might define a Model for Users, Products, Cars, or any other real-world object that we want to model in the system. Models are registered via the model manager, and are us

yii2 源码分析 model类分析 (五)

模型类是数据模型的基类.此类继承了组件类,实现了3个接口 先介绍一下模型类前面的大量注释说了什么: * 模型类是数据模型的基类.此类继承了组件类,实现了3个接口 * 实现了IteratorAggregate(聚合式迭代器)接口,实现了ArrayAccess接口,可以像数组一样访问对象,这两个接口是php自带 * Arrayable接口是yii2框架自带 * 模型实现了以下常用功能: * * - 属性声明: 默认情况下,每个公共类成员都被认为是模型属性 * - 属性标签: 每个属性可以与用于显示目

three.js 源码注释(三十四)Texture/Texture.js

商域无疆 (http://blog.csdn.net/omni360/) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:商域无疆 -  本博客专注于 敏捷开发及移动和物联设备研究:数据可视化.GOLANG.Html5.WEBGL.THREE.JS,否则,出自本博客的文章拒绝转载或再转载,谢谢合作. 俺也是刚开始学,好多地儿肯定不对还请见谅. 以下代码是THREE.JS 源码文件中Texture/Texture.js文件的注释. 更多更新在 : https://gi

OpenGL学习--07--模型加载(obj)

1.tutorial07.cpp // Include standard headers #include <stdio.h> #include <stdlib.h> #include <vector> // Include GLEW #include <GL/glew.h> // Include GLFW #include <glfw3.h> GLFWwindow* window; // Include GLM #include <glm