diff --git a/include/DLL_VERSION.H b/include/DLL_VERSION.H index 7527e30..e206b1b 100644 --- a/include/DLL_VERSION.H +++ b/include/DLL_VERSION.H @@ -4,7 +4,7 @@ #define TBF_MAJOR 0 #define TBF_MINOR 9 #define TBF_BUILD 3 -#define TBF_REV 1 +#define TBF_REV 2 diff --git a/include/textures.h b/include/textures.h index 715dab0..ea19569 100644 --- a/include/textures.h +++ b/include/textures.h @@ -198,10 +198,11 @@ namespace RenderFix { getUsedRenderTargets (void); void trackRenderTarget (IDirect3DBaseTexture9* rt); bool isRenderTarget (IDirect3DBaseTexture9* rt); + bool isUsedRenderTarget (IDirect3DBaseTexture9* rt); void queueScreenshot (wchar_t* wszFileName, bool hudless = true); bool wantsScreenshot (void); - HRESULT takeScreenshot (IDirect3DBaseTexture9* pTex); + HRESULT takeScreenshot (IDirect3DSurface9* pSurf); BOOL isTexturePowerOfTwo (UINT sampler) diff --git a/src/render.cpp b/src/render.cpp index b75195a..49b5d7a 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -32,7 +32,6 @@ #include #include -#include tbf::RenderFix::tbf_draw_states_s tbf::RenderFix::draw_state; @@ -391,35 +390,6 @@ D3D9SetVertexShader_Detour (IDirect3DDevice9* This, if (tbf::RenderFix::tracked_rt.active) tbf::RenderFix::tracked_rt.vertex_shaders.insert (vs_checksum); - - - CComPtr pTexture = nullptr; - - if (SUCCEEDED (This->GetTexture (0, &pTexture)) && tbf::RenderFix::tex_mgr.wantsScreenshot ()) - { - if (vs_checksum == 0x1a97b826 /*ps_checksum == 0x46618c0a*/ && tbf::RenderFix::tex_mgr.isRenderTarget (pTexture)) - { - CComPtr pTex = nullptr; - - if (SUCCEEDED (pTexture->QueryInterface (IID_PPV_ARGS (&pTex)))) - { - D3DSURFACE_DESC desc; - - if (SUCCEEDED (pTex->GetLevelDesc (0, &desc))) - { - static int passes = 0; - - if ( desc.Width == tbf::RenderFix::width && - desc.Height == tbf::RenderFix::height && passes++ > 1 ) - { - tbf::RenderFix::tex_mgr.takeScreenshot (pTexture); - passes = 0; - } - } - } - } - } - return D3D9SetVertexShader_Original (This, pShader); } diff --git a/src/textures.cpp b/src/textures.cpp index f6b7780..1c84349 100644 --- a/src/textures.cpp +++ b/src/textures.cpp @@ -94,10 +94,15 @@ tbf::RenderFix::TextureManager iSK_Logger* tex_log = nullptr; #include +#include // Textures that are missing mipmaps std::set incomplete_textures; + +// Cleanup +std::queue screenshots; + tbf::RenderFix::pad_buttons_t tbf::RenderFix::pad_buttons; // D3DXSaveSurfaceToFile issues a StretchRect, but we don't want to log that... @@ -602,6 +607,12 @@ tbf::RenderFix::TextureManager::applyTexture (IDirect3DBaseTexture9* pTex) used.render_targets.insert (pTex); } +bool +tbf::RenderFix::TextureManager::isUsedRenderTarget (IDirect3DBaseTexture9* pTex) +{ + return used.render_targets.count (pTex) != 0; +} + void tbf::RenderFix::TextureManager::resetUsedTextures (void) { @@ -688,6 +699,29 @@ D3D9SetTexture_Detour ( } + if (tbf::RenderFix::tex_mgr.wantsScreenshot ()) + { + if ( Sampler == 1 && vs_checksum == 0x1a97b826 && + ps_checksum == 0x46618c0a && + tbf::RenderFix::tex_mgr.isRenderTarget (pTexture) ) + { + D3DSURFACE_DESC surf_desc; + CComPtr pSurf = nullptr; + + if (SUCCEEDED (This->GetRenderTarget (0, &pSurf))) + { + pSurf->GetDesc (&surf_desc); + + if ( surf_desc.Width == tbf::RenderFix::width && + surf_desc.Height == tbf::RenderFix::height ) + { + tbf::RenderFix::tex_mgr.takeScreenshot (pSurf); + } + } + } + } + + void* dontcare; if ( pTexture != nullptr && pTexture->QueryInterface (IID_SKTextureD3D9, &dontcare) == S_OK ) @@ -3043,6 +3077,11 @@ tbf::RenderFix::TextureManager::Init (void) GetProcAddress ( tbf::RenderFix::d3dx9_43_dll, "D3DXSaveTextureToFileW" ); + D3DXSaveSurfaceToFileW = + (D3DXSaveSurfaceToFile_pfn) + GetProcAddress ( tbf::RenderFix::d3dx9_43_dll, + "D3DXSaveSurfaceToFileW" ); + D3DXCreateTextureFromFile = (D3DXCreateTextureFromFile_pfn) GetProcAddress ( tbf::RenderFix::d3dx9_43_dll, @@ -3161,6 +3200,14 @@ tbf::RenderFix::TextureManager::Shutdown (void) time_saved / frame_time ); tex_log->close (); + while (! screenshots.empty ()) + { + std::wstring file_to_delete = screenshots.front (); + screenshots.pop (); + + DeleteFileW (file_to_delete.c_str ()); + } + FreeLibrary (d3dx9_43_dll); } @@ -4185,7 +4232,7 @@ tbf::RenderFix::TextureManager::wantsScreenshot (void) } HRESULT -tbf::RenderFix::TextureManager::takeScreenshot (IDirect3DBaseTexture9* pTex) +tbf::RenderFix::TextureManager::takeScreenshot (IDirect3DSurface9* pSurf) { static int count = 0; @@ -4199,43 +4246,31 @@ tbf::RenderFix::TextureManager::takeScreenshot (IDirect3DBaseTexture9* pTex) want_screenshot = false; - D3DSURFACE_DESC desc; - - CComPtr pRealTex = nullptr; - - pTex->QueryInterface (IID_PPV_ARGS (&pRealTex)); - - pRealTex->GetLevelDesc (0, &desc); + D3DSURFACE_DESC desc; + pSurf->GetDesc (&desc); - start_load (); - HRESULT hr = D3DXSaveTextureToFile (wszOut, D3DXIFF_TGA, pTex, nullptr); + HRESULT hr = + D3DXSaveSurfaceToFileW ( wszOut, + D3DXIFF_TGA, pSurf, + nullptr, nullptr ); - if (SUCCEEDED (hr)) { + if (SUCCEEDED (hr)) + { extern HMODULE hInjectorDLL; - typedef void (WINAPI *SK_SteamAPI_AddScreenshotToLibrary_pfn)(const char *pchFilename, const char *pchThumbnailFilename, int nWidth, int nHeight); + typedef void (WINAPI *SK_SteamAPI_AddScreenshotToLibrary_pfn) + (const char *pchFilename, const char *pchThumbnailFilename, int nWidth, int nHeight); - static SK_SteamAPI_AddScreenshotToLibrary_pfn SK_SteamAPI_AddScreenshotToLibrary = - (SK_SteamAPI_AddScreenshotToLibrary_pfn) - GetProcAddress (hInjectorDLL, "SK_SteamAPI_AddScreenshotToLibrary"); + static SK_SteamAPI_AddScreenshotToLibrary_pfn + SK_SteamAPI_AddScreenshotToLibrary = + (SK_SteamAPI_AddScreenshotToLibrary_pfn) + GetProcAddress ( hInjectorDLL, + "SK_SteamAPI_AddScreenshotToLibrary" ); SK_SteamAPI_AddScreenshotToLibrary (szOut, nullptr, desc.Width, desc.Height); - // Wait for SSteam to finish -- this is a stupid hack, but I don't want to bother with a callback :) - CreateThread (nullptr, 0, - [](LPVOID user) -> - DWORD - { - Sleep (5000UL); - DeleteFileA ((char *)user); - free (user); - CloseHandle (GetCurrentThread ()); - return 0; - }, _strdup (szOut), - 0x00, - nullptr ); + screenshots.push (wszOut); } - end_load (); return hr; } \ No newline at end of file diff --git a/version.ini b/version.ini index 9170381..ff281c0 100644 Binary files a/version.ini and b/version.ini differ