Skip to content

Commit

Permalink
HUDless is working as intended now.
Browse files Browse the repository at this point in the history
  • Loading branch information
andon authored and andon committed Feb 11, 2017
1 parent 9a2dd6b commit 6b77546
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 61 deletions.
2 changes: 1 addition & 1 deletion include/DLL_VERSION.H
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define TBF_MAJOR 0
#define TBF_MINOR 9
#define TBF_BUILD 3
#define TBF_REV 1
#define TBF_REV 2



Expand Down
3 changes: 2 additions & 1 deletion include/textures.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 0 additions & 30 deletions src/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

#include <d3d9.h>
#include <d3d9types.h>
#include <atlbase.h>

tbf::RenderFix::tbf_draw_states_s
tbf::RenderFix::draw_state;
Expand Down Expand Up @@ -391,35 +390,6 @@ D3D9SetVertexShader_Detour (IDirect3DDevice9* This,
if (tbf::RenderFix::tracked_rt.active)
tbf::RenderFix::tracked_rt.vertex_shaders.insert (vs_checksum);



CComPtr <IDirect3DBaseTexture9> 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 <IDirect3DTexture9> 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);
}

Expand Down
93 changes: 64 additions & 29 deletions src/textures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,15 @@ tbf::RenderFix::TextureManager
iSK_Logger* tex_log = nullptr;

#include <set>
#include <queue>

// Textures that are missing mipmaps
std::set <IDirect3DBaseTexture9 *> incomplete_textures;


// Cleanup
std::queue <std::wstring> screenshots;

tbf::RenderFix::pad_buttons_t tbf::RenderFix::pad_buttons;

// D3DXSaveSurfaceToFile issues a StretchRect, but we don't want to log that...
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 <IDirect3DSurface9> 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 )
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}

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

Expand All @@ -4199,43 +4246,31 @@ tbf::RenderFix::TextureManager::takeScreenshot (IDirect3DBaseTexture9* pTex)

want_screenshot = false;

D3DSURFACE_DESC desc;

CComPtr <IDirect3DTexture9> 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;
}
Binary file modified version.ini
Binary file not shown.

0 comments on commit 6b77546

Please sign in to comment.