diff --git a/include/DLL_VERSION.H b/include/DLL_VERSION.H index 5551147..cbb0afd 100644 --- a/include/DLL_VERSION.H +++ b/include/DLL_VERSION.H @@ -3,7 +3,7 @@ #define TBF_MAJOR 0 #define TBF_MINOR 1 -#define TBF_BUILD 6 +#define TBF_BUILD 7 #define TBF_REV 0 diff --git a/src/render.cpp b/src/render.cpp index d481fb0..28dae20 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -52,6 +52,10 @@ DrawIndexedPrimitiveUP_pfn D3D9DrawIndexedPrimitiveUP_Original SK_SetPresentParamsD3D9_pfn SK_SetPresentParamsD3D9_Original = nullptr; +extern bool pending_loads (void); +extern void TBFix_LoadQueuedTextures (void); + + bool fullscreen_blit = false; bool needs_aspect = false; bool world_radial = false; @@ -492,12 +496,6 @@ HRESULT STDMETHODCALLTYPE D3D9EndScene_Detour (IDirect3DDevice9* This) { - extern bool pending_loads (void); - if (pending_loads ()) { - extern void TBFix_LoadQueuedTextures (void); - TBFix_LoadQueuedTextures (); - } - // Ignore anything that's not the primary render device. if (This != tbf::RenderFix::pDevice) return D3D9EndScene_Original (This); @@ -505,6 +503,10 @@ D3D9EndScene_Detour (IDirect3DDevice9* This) if (GetCurrentThreadId () != InterlockedExchangeAdd (&tbf::RenderFix::dwRenderThreadID, 0)) return D3D9EndScene_Original (This); + if (pending_loads ()) { + TBFix_LoadQueuedTextures (); + } + // EndScene is invoked multiple times per-frame, but we // are only interested in the first. if (scene_count++ > 0) @@ -1428,12 +1430,22 @@ D3D9DrawIndexedPrimitiveUP_Detour ( IDirect3DDevice9* This, } - void tbf::RenderFix::Reset ( IDirect3DDevice9 *This, D3DPRESENT_PARAMETERS *pPresentationParameters ) { - tex_mgr.reset (); + static volatile + ULONG reset_count = 0UL; + + if (InterlockedIncrement (&reset_count) == 1UL) + tex_mgr.Init (); + + else { + if (pending_loads ()) + TBFix_LoadQueuedTextures (); + + tex_mgr.reset (); + } vs_checksums.clear (); ps_checksums.clear (); @@ -1460,11 +1472,11 @@ __stdcall D3D9Reset_Detour ( IDirect3DDevice9 *This, D3DPRESENT_PARAMETERS *pPresentationParameters ) { + tbf::RenderFix::Reset (This, pPresentationParameters); + if (tbf::RenderFix::pDevice != nullptr && This != tbf::RenderFix::pDevice) return D3D9Reset_Original (This, pPresentationParameters); - tbf::RenderFix::Reset (This, pPresentationParameters); - HRESULT hr = D3D9Reset_Original (This, pPresentationParameters); @@ -1651,8 +1663,6 @@ tbf::RenderFix::Init (void) { d3dx9_43_dll = LoadLibrary (L"D3DX9_43.DLL"); - tex_mgr.Init (); - TBF_CreateDLLHook2 ( config.system.injector.c_str (), "D3D9SetSamplerState_Override", D3D9SetSamplerState_Detour, (LPVOID*)&D3D9SetSamplerState_Original, diff --git a/src/textures.cpp b/src/textures.cpp index 33a96ad..efdf6f1 100644 --- a/src/textures.cpp +++ b/src/textures.cpp @@ -1636,6 +1636,9 @@ TBFix_LoadQueuedTextures (void) tbf::RenderFix::tex_mgr.updateOSD (); ++loads; + + // Remove the temporary reference + load->pDest->Release (); } delete load; @@ -2017,9 +2020,12 @@ D3DXCreateTextureFromFileInMemoryEx_Detour ( load_op->pSrcData = new uint8_t [SrcDataSize]; load_op->SrcDataSize = SrcDataSize; + swprintf (load_op->wszFilename, L"Resample_%x.dds", checksum); + memcpy (load_op->pSrcData, pSrcData, SrcDataSize); - load_op->pDest = *ppTexture; + (*ppTexture)->AddRef (); + load_op->pDest = *ppTexture; resample_pool->postJob (load_op); } diff --git a/tbf.VC.db b/tbf.VC.db index a6973d2..f6d3ecf 100644 Binary files a/tbf.VC.db and b/tbf.VC.db differ diff --git a/version.ini b/version.ini index e684b39..85a0419 100644 Binary files a/version.ini and b/version.ini differ