Advertisement
Dimitri_UA

vc_mip

May 10th, 2014
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <stdio.h>
  3. #include <patch\CPatch.h>
  4. #include <game_sa\RenderWare.h>
  5.  
  6. #define NativeTexRead(stream, pTex) ((bool (__cdecl *)(int, RwTexture **))0x63EFE0)(stream, pTex)
  7. #define RwRasterGetNumLevels(raster) ((signed int (__cdecl *)(RwRaster *))0x655420)(raster)
  8.  
  9. #pragma pack(push, 1)
  10. struct TextureRasterNativeStream
  11. {
  12.   int rasterFormat;
  13.   int d3d9Format;
  14.   unsigned __int16 width;
  15.   unsigned __int16 height;
  16.   unsigned __int8 stride;
  17.   char numLevels;
  18.   unsigned __int8 rasterType;
  19.   char compressionType;
  20. };
  21. #pragma pack(pop)
  22.  
  23. TextureRasterNativeStream texInfo;
  24.  
  25. #define StreamRead(stream, pInfo, len) ((bool (__cdecl *)(int, TextureRasterNativeStream *, unsigned int))0x6454B0)(stream, pInfo, len)
  26.  
  27. unsigned int ReadTextureInfo(int stream, TextureRasterNativeStream *info, unsigned int len)
  28. {
  29.     unsigned int result = StreamRead(stream, info, len);
  30.     memcpy(&texInfo, info, sizeof(TextureRasterNativeStream));
  31.     return result;
  32. }
  33.  
  34. #define d3dCreateTexture(width, height, numLevels, format, pTexture) ((signed int (__stdcall *)(unsigned int, int, int, unsigned int, int, unsigned int, int, unsigned int))*(unsigned int *)(**(unsigned int **)0x7897A8 + 0x50))(*(unsigned int *)0x7897A8, width, height, numLevels, 0, format, 1, pTexture)
  35.  
  36. signed int gtaCreateTexture(int width, int height, unsigned int numLevels, unsigned int format, unsigned int pTexture)
  37. {
  38.     // Get the raster
  39.     RwRaster *raster = (RwRaster *)(pTexture - *(unsigned int *)0xA0D8B0);
  40.     unsigned int levels = texInfo.numLevels;
  41.     if((raster->cFormat & 0x80u) == 0)
  42.         levels = 1;
  43.     return d3dCreateTexture(width, height, levels, format, pTexture);
  44. }
  45.  
  46. void ViceMipsPatch()
  47. {
  48.     CPatch::RedirectCall(0x63F09B, ReadTextureInfo);
  49.     CPatch::RedirectCall(0x63F19F, gtaCreateTexture);
  50.     CPatch::Nop(0x63F0B9, 8);
  51. }
  52.  
  53. void ViceMips()
  54. {
  55.     ViceMipsPatch();
  56. }
  57.  
  58. BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved)
  59. {
  60.     switch(reason)
  61.     {
  62.     case DLL_PROCESS_ATTACH:
  63.         ViceMips();
  64.     }
  65.     return TRUE;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement