Skip to content

Commit

Permalink
Add HUDless screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
andon authored and andon committed Feb 10, 2017
1 parent 9b2fbd4 commit 9a2dd6b
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 71 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 0
#define TBF_REV 1



Expand Down
20 changes: 12 additions & 8 deletions include/textures.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ namespace RenderFix {
void trackRenderTarget (IDirect3DBaseTexture9* rt);
bool isRenderTarget (IDirect3DBaseTexture9* rt);

void queueScreenshot (wchar_t* wszFileName, bool hudless = true);
bool wantsScreenshot (void);
HRESULT takeScreenshot (IDirect3DBaseTexture9* pTex);


BOOL isTexturePowerOfTwo (UINT sampler)
Expand All @@ -225,17 +228,18 @@ namespace RenderFix {
} used;

std::unordered_map <uint32_t, tbf::RenderFix::Texture*> textures;
float time_saved = 0.0f;
LONG64 bytes_saved = 0LL;
float time_saved = 0.0f;
LONG64 bytes_saved = 0LL;

ULONG hits = 0UL;
ULONG misses = 0UL;
ULONG hits = 0UL;
ULONG misses = 0UL;

LONG64 basic_size = 0LL;
LONG64 injected_size = 0LL;
ULONG injected_count = 0UL;
LONG64 basic_size = 0LL;
LONG64 injected_size = 0LL;
ULONG injected_count = 0UL;

std::string osd_stats = "";
std::string osd_stats = "";
bool want_screenshot = false;

CRITICAL_SECTION cs_cache;
} extern tex_mgr;
Expand Down
6 changes: 3 additions & 3 deletions src/ImGui/control_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ TBFix_DrawConfigUI (void)
ImGui::GetIO ();

io.FontGlobalScale = config.input.ui.scale;
const LONG font_size = ImGui::GetFont ()->FontSize * io.FontGlobalScale;
const float font_size = ImGui::GetFont ()->FontSize * io.FontGlobalScale;

ImGui::SetNextWindowPosCenter (ImGuiSetCond_Always);
ImGui::SetNextWindowSizeConstraints (ImVec2 (665, 50), ImVec2 ( ImGui::GetIO ().DisplaySize.x * 0.95f,
Expand Down Expand Up @@ -766,7 +766,7 @@ TBFix_DrawConfigUI (void)

ImGui::Columns (2);

for (int i = 0 ; i < std::min (config.audio.channels, channels); i++)
for (UINT i = 0 ; i < std::min (config.audio.channels, channels); i++)
{
if (SUCCEEDED (pMeterInfo->GetChannelsPeakValues (channels, channel_peaks_)))
{
Expand Down Expand Up @@ -838,7 +838,7 @@ TBFix_DrawConfigUI (void)
if (tbf::SoundFix::wasapi_init)
{
ImGui::PushStyleVar (ImGuiStyleVar_ChildWindowRounding, 16.0f);
ImGui::BeginChild ("Audio Details", ImVec2 (0, font_size * 6), true);
ImGui::BeginChild ("Audio Details", ImVec2 (0.0f, font_size * 6.0f), true);

ImGui::Columns (3);
ImGui::Text (""); ImGui::NextColumn ();
Expand Down
70 changes: 43 additions & 27 deletions src/ImGui/mod_tools.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _CRT_SECURE_NO_WARNINGS

#define NOMINMAX

#include "DLL_VERSION.H"
Expand All @@ -17,7 +19,7 @@
void
TBF_DrawFileList (void)
{
const LONG font_size = ImGui::GetFont ()->FontSize * ImGui::GetIO ().FontGlobalScale;
const float font_size = ImGui::GetFont ()->FontSize * ImGui::GetIO ().FontGlobalScale;

ImGui::PushItemWidth (500.0f);

Expand Down Expand Up @@ -238,7 +240,7 @@ TBF_DrawFileList (void)
bool
TBFix_TextureModDlg (void)
{
const LONG font_size = ImGui::GetFont ()->FontSize * ImGui::GetIO ().FontGlobalScale;
const float font_size = ImGui::GetFont ()->FontSize * ImGui::GetIO ().FontGlobalScale;

bool show_dlg = true;

Expand All @@ -250,7 +252,7 @@ TBFix_TextureModDlg (void)

if (ImGui::CollapsingHeader ("Preliminary Documentation"))
{
ImGui::BeginChild ("ModDescription", ImVec2 (font_size * 66, font_size * 25), true);
ImGui::BeginChild ("ModDescription", ImVec2 (font_size * 66.0f, font_size * 25.0f), true);
ImGui::TextColored (ImVec4 (0.9f, 0.7f, 0.5f, 1.0f), "Texture Modding Overview"); ImGui::SameLine ();
ImGui::Text (" (Full Writeup Pending)");

Expand Down Expand Up @@ -292,8 +294,8 @@ TBFix_TextureModDlg (void)

if (ImGui::CollapsingHeader ("Live Texture View", ImGuiTreeNodeFlags_CollapsingHeader | ImGuiTreeNodeFlags_DefaultOpen))
{
static LONG last_ht = 256L;
static LONG last_width = 256L;
static float last_ht = 256.0f;
static float last_width = 256.0f;

static std::vector <std::string> list_contents;
static bool list_dirty = false;
Expand All @@ -303,7 +305,7 @@ TBFix_TextureModDlg (void)
extern uint32_t tex_dbg_idx;
extern uint32_t debug_tex_id;

ImGui::BeginChild ("ToolHeadings", ImVec2 (font_size * 66, font_size * 2.5), false, ImGuiWindowFlags_AlwaysUseWindowPadding);
ImGui::BeginChild ("ToolHeadings", ImVec2 (font_size * 66.0f, font_size * 2.5f), false, ImGuiWindowFlags_AlwaysUseWindowPadding);

if (ImGui::Button ("Refresh Textures"))
{
Expand Down Expand Up @@ -377,7 +379,7 @@ TBFix_TextureModDlg (void)
ImGui::PushStyleColor (ImGuiCol_Border, ImVec4 (0.9f, 0.7f, 0.5f, 1.0f));

ImGui::BeginChild ( "Item List",
ImVec2 ( font_size * 6, std::max (font_size * 15, last_ht)),
ImVec2 ( font_size * 6.0f, std::max (font_size * 15.0f, last_ht)),
true, ImGuiWindowFlags_AlwaysAutoResize );

if (textures_used_last_dump.size ())
Expand Down Expand Up @@ -434,8 +436,8 @@ TBFix_TextureModDlg (void)
ImGui::SameLine ();
ImGui::PushStyleVar (ImGuiStyleVar_ChildWindowRounding, 20.0f);

last_ht = std::max (last_ht, 16L);
last_width = std::max (last_width, 16L);
last_ht = std::max (last_ht, 16.0f);
last_width = std::max (last_width, 16.0f);

if (debug_tex_id != 0x00)
{
Expand All @@ -448,12 +450,15 @@ TBFix_TextureModDlg (void)

if (SUCCEEDED (pTex->d3d9_tex->pTex->GetLevelDesc (0, &desc)))
{
ImGui::PushStyleColor (ImGuiCol_Border, ImVec4 (0.5f, 0.5f, 0.5f, 1.0f));
ImGui::BeginChild ( "Item Selection",
ImVec2 (std::max (font_size * 19, (LONG)desc.Width + 24), desc.Height + font_size * 10), true, ImGuiWindowFlags_AlwaysAutoResize );
ImGui::PushStyleColor (ImGuiCol_Border, ImVec4 (0.5f, 0.5f, 0.5f, 1.0f));
ImGui::BeginChild ( "Item Selection",
ImVec2 ( std::max (font_size * 19.0f, (float)desc.Width + 24.0f),
(float)desc.Height + font_size * 10.0f),
true,
ImGuiWindowFlags_AlwaysAutoResize );

last_width = desc.Width;
last_ht = desc.Height + font_size * 10;
last_width = (float)desc.Width;
last_ht = (float)desc.Height + font_size * 10.0f;

extern std::wstring
SK_D3D9_FormatToStr (D3DFORMAT Format, bool include_ordinal = true);
Expand Down Expand Up @@ -510,7 +515,10 @@ TBFix_TextureModDlg (void)
{
ImGui::PushStyleColor (ImGuiCol_Border, ImVec4 (0.5f, 0.5f, 0.5f, 1.0f));
ImGui::BeginChild ( "Item Selection2",
ImVec2 (std::max (font_size * 19, (LONG)desc.Width + 24), desc.Height + font_size * 10), true, ImGuiWindowFlags_AlwaysAutoResize );
ImVec2 ( std::max (font_size * 19.0f, (float)desc.Width + 24.0f),
(float)desc.Height + font_size * 10.0f),
true,
ImGuiWindowFlags_AlwaysAutoResize );

extern std::wstring
SK_D3D9_FormatToStr (D3DFORMAT Format, bool include_ordinal = true);
Expand Down Expand Up @@ -572,8 +580,8 @@ TBFix_TextureModDlg (void)

if (ImGui::CollapsingHeader ("Live Render Target View"))
{
static LONG last_ht = 256L;
static LONG last_width = 256L;
static float last_ht = 256.0f;
static float last_width = 256.0f;

static std::vector <std::string> list_contents;
static bool list_dirty = true;
Expand All @@ -593,7 +601,7 @@ TBFix_TextureModDlg (void)
{
char szDesc [16] = { };

sprintf (szDesc, "%08x", (uintptr_t)it);
sprintf (szDesc, "%llx", (uintptr_t)it);

list_contents.push_back (szDesc);

Expand All @@ -608,7 +616,7 @@ TBFix_TextureModDlg (void)
ImGui::PushStyleColor (ImGuiCol_Border, ImVec4 (0.9f, 0.7f, 0.5f, 1.0f));

ImGui::BeginChild ( "Item List2",
ImVec2 ( font_size * 6, std::max (font_size * 15, last_ht)),
ImVec2 ( font_size * 6.0f, std::max (font_size * 15.0f, last_ht)),
true, ImGuiWindowFlags_AlwaysAutoResize );

if (render_textures.size ())
Expand Down Expand Up @@ -678,20 +686,20 @@ TBFix_TextureModDlg (void)

if (SUCCEEDED (pTex->GetLevelDesc (0, &desc)))
{
int shaders = std::max ( tbf::RenderFix::tracked_rt.pixel_shaders.size (),
tbf::RenderFix::tracked_rt.vertex_shaders.size () );
size_t shaders = std::max ( tbf::RenderFix::tracked_rt.pixel_shaders.size (),
tbf::RenderFix::tracked_rt.vertex_shaders.size () );

ImGui::SameLine ();

ImGui::PushStyleColor (ImGuiCol_Border, ImVec4 (0.5f, 0.5f, 0.5f, 1.0f));
ImGui::BeginChild ( "Item Selection3",
ImVec2 ( std::max (128L, (LONG)desc.Width / 2 + 24),
std::max (256L, (LONG)desc.Height / 2) + 64 + shaders * 19),
ImVec2 ( std::max (128.0f, (float)desc.Width / 2.0f + 24.0f),
std::max (256.0f, (float)desc.Height / 2.0f) + 64.0f + (float)shaders * 19.0f),
true,
ImGuiWindowFlags_AlwaysAutoResize );

last_width = desc.Width / 2;
last_ht = (LONG)(desc.Height / 2) + font_size * 3 + shaders * font_size;
last_width = (float)desc.Width / 2.0f;
last_ht = (float)desc.Height / 2.0f + font_size * 3.0f + (float)shaders * font_size;

extern std::wstring
SK_D3D9_FormatToStr (D3DFORMAT Format, bool include_ordinal = true);
Expand All @@ -706,9 +714,9 @@ TBFix_TextureModDlg (void)
ImGui::Separator ();

ImGui::PushStyleColor (ImGuiCol_Border, ImVec4 (0.95f, 0.95f, 0.05f, 1.0f));
ImGui::BeginChildFrame (0, ImVec2 ((float)desc.Width / 2 + 8, (float)desc.Height / 2 + 8), ImGuiWindowFlags_ShowBorders);
ImGui::BeginChildFrame (0, ImVec2 ((float)desc.Width / 2.0f + 8.0f, (float)desc.Height / 2.0f + 8.0f), ImGuiWindowFlags_ShowBorders);
ImGui::Image ( pTex,
ImVec2 ((float)desc.Width / 2, (float)desc.Height / 2),
ImVec2 ((float)desc.Width / 2.0f, (float)desc.Height / 2.0f),
ImVec2 (0,0), ImVec2 (1,1),
ImColor (255,255,255,255), ImColor (255,255,255,128)
);
Expand Down Expand Up @@ -739,6 +747,14 @@ TBFix_TextureModDlg (void)
ImGui::EndGroup ();
}

if (ImGui::CollapsingHeader ("Live Shader View"))
{
ImGui::TreePush ("");
ImGui::Text ("TODO");
// Vertex Shader List ==> Pixel Shader List ==> Disassembled Shaders ==> Textures / RenderTargets Used
ImGui::TreePop ();
}

if (ImGui::CollapsingHeader ("Misc. Settings"))
{
ImGui::TreePush ("");
Expand Down
7 changes: 5 additions & 2 deletions src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ SK_TBF_PluginKeyPress ( BOOL Control,
*SK_GetCommandProcessor ();

if (Control && Shift)
{
if (vkCode == VK_DELETE) {
{
if (vkCode == VK_F10)
tbf::RenderFix::tex_mgr.queueScreenshot (L"Screenshot.dds");

else if (vkCode == VK_DELETE) {
config.render.osd_disclaimer = (! config.render.osd_disclaimer);
}

Expand Down
10 changes: 5 additions & 5 deletions src/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ static bool list_dirty = true;
void
TBF_DrawRemapList (void)
{
const LONG font_size = ImGui::GetFont ()->FontSize * ImGui::GetIO ().FontGlobalScale;
const float font_size = ImGui::GetFont ()->FontSize * ImGui::GetIO ().FontGlobalScale;

struct enumerated_remap_s
{
Expand Down Expand Up @@ -291,11 +291,11 @@ TBF_DrawRemapList (void)
ImGui::PushStyleVar (ImGuiStyleVar_ChildWindowRounding, 0.0f);
ImGui::PushStyleColor (ImGuiCol_Border, ImVec4 (0.4f, 0.6f, 0.9f, 1.0f));

#define REMAP_LIST_WIDTH font_size * 30
#define REMAP_LIST_HEIGHT font_size * 5
#define REMAP_LIST_WIDTH font_size * 30.0f
#define REMAP_LIST_HEIGHT font_size * 5.0f

ImGui::BeginChild ( "Remap List",
ImVec2 ( REMAP_LIST_WIDTH, std::max (44UL, font_size * ((unsigned long)remaps.size () + 3)) ),
ImVec2 ( REMAP_LIST_WIDTH, std::max (44.0f, font_size * ((float)remaps.size () + 3.0f)) ),
true,
ImGuiWindowFlags_AlwaysAutoResize );

Expand Down Expand Up @@ -411,7 +411,7 @@ tbf::KeyboardFix::DrawControlPanel (void)
bool
tbf::KeyboardFix::RemapDialog (void)
{
const LONG font_size = ImGui::GetFont ()->FontSize * ImGui::GetIO ().FontGlobalScale;
const float font_size = ImGui::GetFont ()->FontSize * ImGui::GetIO ().FontGlobalScale;
static bool was_open = false;

if (ImGui::BeginPopupModal ("Keyboard Remap", NULL, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_ShowBorders))
Expand Down
36 changes: 34 additions & 2 deletions src/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

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

tbf::RenderFix::tbf_draw_states_s
tbf::RenderFix::draw_state;
Expand Down Expand Up @@ -385,11 +386,40 @@ D3D9SetVertexShader_Detour (IDirect3DDevice9* This,
vs_checksum = vs_checksums [pShader];
g_pVS = pShader;

////tbf::RenderFix::last_frame.vertex_shaders.insert (vs_checksum);
tbf::RenderFix::last_frame.vertex_shaders.insert (vs_checksum);

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 Expand Up @@ -452,7 +482,7 @@ D3D9SetPixelShader_Detour (IDirect3DDevice9* This,
ps_checksum = ps_checksums [pShader];
g_pPS = pShader;

////tbf::RenderFix::last_frame.pixel_shaders.insert (ps_checksum);
tbf::RenderFix::last_frame.pixel_shaders.insert (ps_checksum);

if (tbf::RenderFix::tracked_rt.active)
tbf::RenderFix::tracked_rt.pixel_shaders.insert (ps_checksum);
Expand Down Expand Up @@ -711,6 +741,8 @@ D3D9EndFrame_Post (HRESULT hr, IUnknown* device)
tbf::RenderFix::tracked_rt.vertex_shaders.clear ();
tbf::RenderFix::tracked_rt.pixel_shaders.clear ();

tbf::RenderFix::last_frame.clear ();

//if (config.framerate.minimize_latency)
//tbf::FrameRateFix::RenderTick ();

Expand Down
Loading

0 comments on commit 9a2dd6b

Please sign in to comment.