Advertisement
Dimitri_UA

RW GTASA INTZ

Jul 28th, 2014
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.96 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include <plugin\plugin.h>
  4. #include <game_sa\RenderWare.h>
  5. #include <d3d9.h>
  6. #include <patch\CPatch.h>
  7.  
  8. #define g_D3Dpp ((D3DPRESENT_PARAMETERS *)0xC9C040)
  9.  
  10. #define D3DFMT_INTZ ((D3DFORMAT)(MAKEFOURCC('I','N','T','Z')))
  11. #define D3DFMT_RAWZ ((D3DFORMAT)(MAKEFOURCC('R','A','W','Z')))
  12. #define D3DFMT_DF24 ((D3DFORMAT)(MAKEFOURCC('D','F','2','4')))
  13. #define D3DFMT_DF16 ((D3DFORMAT)(MAKEFOURCC('D','F','1','6')))
  14.  
  15. void __declspec(naked) DisableAutoDepth_Exe()
  16. {
  17.     g_D3Dpp->EnableAutoDepthStencil = FALSE;
  18. }
  19.  
  20. class IRasterDepthTexture
  21. {
  22. public:
  23.     static bool m_bCreated;
  24.     static IDirect3DTexture9 *m_pDepthTexture;
  25.  
  26.     static void Patch()
  27.     {
  28.         plugin::Core::RegisterFunc(plugin::eFuncType::FUNC_SHUTDOWN_RW, Destroy);
  29.         plugin::Core::RegisterFunc(plugin::eFuncType::FUNC_BEFORE_RESET, Destroy);
  30.         plugin::Core::RegisterFunc(plugin::eFuncType::FUNC_AFTER_RESET, Reset);
  31.         CPatch::RedirectCall(0x7F6DC0, DisableAutoDepth_Exe);
  32.         CPatch::Nop(0x7F6DC0, 6);
  33.         CPatch::RedirectCall(0x7F67ED, Create);
  34.         CPatch::Nop(0x7F67F2, 1);
  35.         // remove multi-sampling stuff
  36.         CPatch::Nop(0x7F7011, 2);
  37.         CPatch::SetChar(0x7F7019, 0xEB);
  38.     }
  39.  
  40.     static void __stdcall Create(int a, int b)
  41.     {
  42.         D3DFORMAT format;
  43.         if(rwD3D9CheckValidZBufferTextureFormat(D3DFMT_INTZ))
  44.             format = D3DFMT_INTZ;
  45.         else if(rwD3D9CheckValidZBufferTextureFormat(D3DFMT_RAWZ))
  46.             format = D3DFMT_RAWZ;
  47.         else if(rwD3D9CheckValidZBufferTextureFormat(D3DFMT_DF24))
  48.             format = D3DFMT_DF24;
  49.         else if(rwD3D9CheckValidZBufferTextureFormat(D3DFMT_DF16))
  50.             format = D3DFMT_DF16;
  51.         else
  52.         {
  53.             MessageBox(*(HWND *)RsGlobal->ps, "Your videocard doesn't support no one of available depth formats", "shaderAPI.cleo",
  54.                 MB_OK|MB_ICONERROR);
  55.             format = g_D3Dpp->BackBufferFormat;
  56.         }
  57.         RwD3DDevice->CreateTexture(g_D3Dpp->BackBufferWidth, g_D3Dpp->BackBufferHeight,
  58.             1, D3DUSAGE_DEPTHSTENCIL, format, D3DPOOL_DEFAULT, &m_pDepthTexture, NULL);
  59.         m_pDepthTexture->GetSurfaceLevel(0, (IDirect3DSurface9 **)0xC97C2C);
  60.         RwD3DDevice->SetDepthStencilSurface(*(IDirect3DSurface9 **)0xC97C2C);
  61.         m_bCreated = true;
  62.         // Create effect pool for shaders. TODO: make FUNC_DEVICE_CREATION for plugin project.
  63.         if(D3DXCreateEffectPool(&ShaderOpcodes::effectPool) != D3D_OK)
  64.             MessageBox(*(HWND *)RsGlobal->ps, "Failed to create effect pool", "shaderAPI.cleo", MB_OK|MB_ICONERROR);
  65.     }
  66.  
  67.     static void Reset()
  68.     {
  69.         D3DFORMAT format;
  70.         if(!m_bCreated)
  71.             return;
  72.         if(rwD3D9CheckValidZBufferTextureFormat(D3DFMT_INTZ))
  73.             format = D3DFMT_INTZ;
  74.         else if(rwD3D9CheckValidZBufferTextureFormat(D3DFMT_RAWZ))
  75.             format = D3DFMT_RAWZ;
  76.         else if(rwD3D9CheckValidZBufferTextureFormat(D3DFMT_DF24))
  77.             format = D3DFMT_DF24;
  78.         else if(rwD3D9CheckValidZBufferTextureFormat(D3DFMT_DF16))
  79.             format = D3DFMT_DF16;
  80.         else
  81.         {
  82.             MessageBox(*(HWND *)RsGlobal->ps, "Your videocard doesn't support no one of available depth formats", "shaderAPI.cleo",
  83.                 MB_OK|MB_ICONERROR);
  84.             format = g_D3Dpp->BackBufferFormat;
  85.         }
  86.         RwD3DDevice->CreateTexture(g_D3Dpp->BackBufferWidth, g_D3Dpp->BackBufferHeight,
  87.             1, D3DUSAGE_DEPTHSTENCIL, format, D3DPOOL_DEFAULT, &m_pDepthTexture, NULL);
  88.         m_pDepthTexture->GetSurfaceLevel(0, (IDirect3DSurface9 **)0xC97C2C);
  89.         RwD3DDevice->SetDepthStencilSurface(*(IDirect3DSurface9 **)0xC97C2C);
  90.     }
  91.  
  92.     static void Destroy()
  93.     {
  94.         if(m_pDepthTexture)
  95.         {
  96.             (*(IDirect3DSurface9 **)0xC97C2C)->Release();
  97.             (*(IDirect3DSurface9 **)0xC97C2C) = NULL;
  98.             m_pDepthTexture->Release();
  99.             m_pDepthTexture = NULL;
  100.         }
  101.     }
  102. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement