Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <plugin\plugin.h>
- #include <game_sa\RenderWare.h>
- #include <d3d9.h>
- #include <patch\CPatch.h>
- #define g_D3Dpp ((D3DPRESENT_PARAMETERS *)0xC9C040)
- #define D3DFMT_INTZ ((D3DFORMAT)(MAKEFOURCC('I','N','T','Z')))
- #define D3DFMT_RAWZ ((D3DFORMAT)(MAKEFOURCC('R','A','W','Z')))
- #define D3DFMT_DF24 ((D3DFORMAT)(MAKEFOURCC('D','F','2','4')))
- #define D3DFMT_DF16 ((D3DFORMAT)(MAKEFOURCC('D','F','1','6')))
- void __declspec(naked) DisableAutoDepth_Exe()
- {
- g_D3Dpp->EnableAutoDepthStencil = FALSE;
- }
- class IRasterDepthTexture
- {
- public:
- static bool m_bCreated;
- static IDirect3DTexture9 *m_pDepthTexture;
- static void Patch()
- {
- plugin::Core::RegisterFunc(plugin::eFuncType::FUNC_SHUTDOWN_RW, Destroy);
- plugin::Core::RegisterFunc(plugin::eFuncType::FUNC_BEFORE_RESET, Destroy);
- plugin::Core::RegisterFunc(plugin::eFuncType::FUNC_AFTER_RESET, Reset);
- CPatch::RedirectCall(0x7F6DC0, DisableAutoDepth_Exe);
- CPatch::Nop(0x7F6DC0, 6);
- CPatch::RedirectCall(0x7F67ED, Create);
- CPatch::Nop(0x7F67F2, 1);
- // remove multi-sampling stuff
- CPatch::Nop(0x7F7011, 2);
- CPatch::SetChar(0x7F7019, 0xEB);
- }
- static void __stdcall Create(int a, int b)
- {
- D3DFORMAT format;
- if(rwD3D9CheckValidZBufferTextureFormat(D3DFMT_INTZ))
- format = D3DFMT_INTZ;
- else if(rwD3D9CheckValidZBufferTextureFormat(D3DFMT_RAWZ))
- format = D3DFMT_RAWZ;
- else if(rwD3D9CheckValidZBufferTextureFormat(D3DFMT_DF24))
- format = D3DFMT_DF24;
- else if(rwD3D9CheckValidZBufferTextureFormat(D3DFMT_DF16))
- format = D3DFMT_DF16;
- else
- {
- MessageBox(*(HWND *)RsGlobal->ps, "Your videocard doesn't support no one of available depth formats", "shaderAPI.cleo",
- MB_OK|MB_ICONERROR);
- format = g_D3Dpp->BackBufferFormat;
- }
- RwD3DDevice->CreateTexture(g_D3Dpp->BackBufferWidth, g_D3Dpp->BackBufferHeight,
- 1, D3DUSAGE_DEPTHSTENCIL, format, D3DPOOL_DEFAULT, &m_pDepthTexture, NULL);
- m_pDepthTexture->GetSurfaceLevel(0, (IDirect3DSurface9 **)0xC97C2C);
- RwD3DDevice->SetDepthStencilSurface(*(IDirect3DSurface9 **)0xC97C2C);
- m_bCreated = true;
- // Create effect pool for shaders. TODO: make FUNC_DEVICE_CREATION for plugin project.
- if(D3DXCreateEffectPool(&ShaderOpcodes::effectPool) != D3D_OK)
- MessageBox(*(HWND *)RsGlobal->ps, "Failed to create effect pool", "shaderAPI.cleo", MB_OK|MB_ICONERROR);
- }
- static void Reset()
- {
- D3DFORMAT format;
- if(!m_bCreated)
- return;
- if(rwD3D9CheckValidZBufferTextureFormat(D3DFMT_INTZ))
- format = D3DFMT_INTZ;
- else if(rwD3D9CheckValidZBufferTextureFormat(D3DFMT_RAWZ))
- format = D3DFMT_RAWZ;
- else if(rwD3D9CheckValidZBufferTextureFormat(D3DFMT_DF24))
- format = D3DFMT_DF24;
- else if(rwD3D9CheckValidZBufferTextureFormat(D3DFMT_DF16))
- format = D3DFMT_DF16;
- else
- {
- MessageBox(*(HWND *)RsGlobal->ps, "Your videocard doesn't support no one of available depth formats", "shaderAPI.cleo",
- MB_OK|MB_ICONERROR);
- format = g_D3Dpp->BackBufferFormat;
- }
- RwD3DDevice->CreateTexture(g_D3Dpp->BackBufferWidth, g_D3Dpp->BackBufferHeight,
- 1, D3DUSAGE_DEPTHSTENCIL, format, D3DPOOL_DEFAULT, &m_pDepthTexture, NULL);
- m_pDepthTexture->GetSurfaceLevel(0, (IDirect3DSurface9 **)0xC97C2C);
- RwD3DDevice->SetDepthStencilSurface(*(IDirect3DSurface9 **)0xC97C2C);
- }
- static void Destroy()
- {
- if(m_pDepthTexture)
- {
- (*(IDirect3DSurface9 **)0xC97C2C)->Release();
- (*(IDirect3DSurface9 **)0xC97C2C) = NULL;
- m_pDepthTexture->Release();
- m_pDepthTexture = NULL;
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement