Skip to content

Commit

Permalink
ReShade Compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaldaien committed Jan 16, 2017
1 parent 28f27a3 commit 202530b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion include/DLL_VERSION.H
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#define TBF_MAJOR 0
#define TBF_MINOR 1
#define TBF_BUILD 6
#define TBF_BUILD 7
#define TBF_REV 0


Expand Down
34 changes: 22 additions & 12 deletions src/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -492,19 +496,17 @@ 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);

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)
Expand Down Expand Up @@ -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 ();
Expand All @@ -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);

Expand Down Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion src/textures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1636,6 +1636,9 @@ TBFix_LoadQueuedTextures (void)
tbf::RenderFix::tex_mgr.updateOSD ();

++loads;

// Remove the temporary reference
load->pDest->Release ();
}

delete load;
Expand Down Expand Up @@ -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);
}
Expand Down
Binary file modified tbf.VC.db
Binary file not shown.
Binary file modified version.ini
Binary file not shown.

0 comments on commit 202530b

Please sign in to comment.