From 9a2dd6bef1c676979e30c7fe78400e94b3f95ad0 Mon Sep 17 00:00:00 2001 From: andon Date: Fri, 10 Feb 2017 17:09:55 -0500 Subject: [PATCH] Add HUDless screenshots --- include/DLL_VERSION.H | 2 +- include/textures.h | 20 +++--- src/ImGui/control_panel.cpp | 6 +- src/ImGui/mod_tools.cpp | 70 ++++++++++++--------- src/input.cpp | 7 ++- src/keyboard.cpp | 10 +-- src/render.cpp | 36 ++++++++++- src/sound.cpp | 6 +- src/textures.cpp | 117 ++++++++++++++++++++++++++++++------ version.ini | Bin 12034 -> 12318 bytes 10 files changed, 203 insertions(+), 71 deletions(-) diff --git a/include/DLL_VERSION.H b/include/DLL_VERSION.H index ca26b18..7527e30 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 0 +#define TBF_REV 1 diff --git a/include/textures.h b/include/textures.h index 20c0358..715dab0 100644 --- a/include/textures.h +++ b/include/textures.h @@ -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) @@ -225,17 +228,18 @@ namespace RenderFix { } used; std::unordered_map 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; diff --git a/src/ImGui/control_panel.cpp b/src/ImGui/control_panel.cpp index 0fbb50d..99fc3fb 100644 --- a/src/ImGui/control_panel.cpp +++ b/src/ImGui/control_panel.cpp @@ -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, @@ -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_))) { @@ -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 (); diff --git a/src/ImGui/mod_tools.cpp b/src/ImGui/mod_tools.cpp index d28e9ef..90e86ba 100644 --- a/src/ImGui/mod_tools.cpp +++ b/src/ImGui/mod_tools.cpp @@ -1,3 +1,5 @@ +#define _CRT_SECURE_NO_WARNINGS + #define NOMINMAX #include "DLL_VERSION.H" @@ -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); @@ -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; @@ -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)"); @@ -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 list_contents; static bool list_dirty = false; @@ -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")) { @@ -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 ()) @@ -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) { @@ -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); @@ -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); @@ -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 list_contents; static bool list_dirty = true; @@ -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); @@ -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 ()) @@ -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); @@ -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) ); @@ -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 (""); diff --git a/src/input.cpp b/src/input.cpp index e440005..a594cd7 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -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); } diff --git a/src/keyboard.cpp b/src/keyboard.cpp index d3238e4..797ed10 100644 --- a/src/keyboard.cpp +++ b/src/keyboard.cpp @@ -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 { @@ -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 ); @@ -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)) diff --git a/src/render.cpp b/src/render.cpp index 37456c7..b75195a 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -32,6 +32,7 @@ #include #include +#include tbf::RenderFix::tbf_draw_states_s tbf::RenderFix::draw_state; @@ -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 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); } @@ -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); @@ -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 (); diff --git a/src/sound.cpp b/src/sound.cpp index 6969464..034b102 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -186,7 +186,7 @@ HRESULT WINAPI DSound_GetSpeakerConfig (IDirectSound *This, _Out_ LPDWORD pdwSpeakerConfig) { - audio_log->Log ( L"[!] %s (%08Xh, %08Xh) - " + audio_log->Log ( L"[!] %s (%ph, %ph) - " L"[Calling Thread: 0x%04x]", L"IDirectSound::GetSpeakerConfig", This, @@ -217,7 +217,7 @@ HRESULT WINAPI DSound_SetSpeakerConfig (IDirectSound *This, _In_ DWORD dwSpeakerConfig) { - audio_log->Log ( L"[!] %s (%08Xh, %08Xh) - " + audio_log->Log ( L"[!] %s (%ph, %ph) - " L"[Calling Thread: 0x%04x]", L"IDirectSound::SetSpeakerConfig", This, dwSpeakerConfig, @@ -247,7 +247,7 @@ HRESULT WINAPI DSound_GetSpeakerConfig8 (IDirectSound8 *This, _Out_ LPDWORD pdwSpeakerConfig) { - audio_log->Log ( L"[!] %s (%08Xh, %08Xh) - " + audio_log->Log ( L"[!] %s (%ph, %ph) - " L"[Calling Thread: 0x%04x]", L"IDirectSound8::GetSpeakerConfig", This, pdwSpeakerConfig, diff --git a/src/textures.cpp b/src/textures.cpp index c780538..f6b7780 100644 --- a/src/textures.cpp +++ b/src/textures.cpp @@ -45,6 +45,9 @@ #include #include +#include +#include + #define TBFIX_TEXTURE_DIR L"TBFix_Res" #define TBFIX_TEXTURE_EXT L".dds" @@ -672,18 +675,19 @@ D3D9SetTexture_Detour ( //Sampler, pTexture ); //} + extern uint32_t vs_checksum; + extern uint32_t ps_checksum; + tbf::RenderFix::tex_mgr.applyTexture (pTexture); tbf::RenderFix::tracked_rt.active = (pTexture == tbf::RenderFix::tracked_rt.tracking_tex); if (tbf::RenderFix::tracked_rt.active) { - extern uint32_t vs_checksum; - extern uint32_t ps_checksum; - - tbf::RenderFix::tracked_rt.pixel_shaders.insert (vs_checksum); - tbf::RenderFix::tracked_rt.pixel_shaders.insert (ps_checksum); + tbf::RenderFix::tracked_rt.vertex_shaders.insert (vs_checksum); + tbf::RenderFix::tracked_rt.pixel_shaders.insert (ps_checksum); } + void* dontcare; if ( pTexture != nullptr && pTexture->QueryInterface (IID_SKTextureD3D9, &dontcare) == S_OK ) @@ -1701,15 +1705,16 @@ InjectTexture (tbf_tex_load_s* load) { wchar_t arc_name [MAX_PATH] = { }; CFileInStream arc_stream; - CLookToRead look_stream; + std::unique_ptr + look_stream (new CLookToRead ()); ISzAlloc thread_alloc; ISzAlloc thread_tmp_alloc; FileInStream_CreateVTable (&arc_stream); - LookToRead_CreateVTable (&look_stream, False); + LookToRead_CreateVTable (look_stream.get (), False); - look_stream.realStream = &arc_stream.s; - LookToRead_Init (&look_stream); + look_stream->realStream = &arc_stream.s; + LookToRead_Init (look_stream.get ()); thread_alloc.Alloc = SzAlloc; thread_alloc.Free = SzFree; @@ -1742,7 +1747,7 @@ InjectTexture (tbf_tex_load_s* load) SzArEx_Init (&arc); - if (SzArEx_Open (&arc, &look_stream.s, &thread_alloc, &thread_tmp_alloc) != SZ_OK) + if (SzArEx_Open (&arc, &look_stream->s, &thread_alloc, &thread_tmp_alloc) != SZ_OK) { tex_log->Log ( L"[Inject Tex] ** Cannot open archive file: %s", arc_name ); @@ -1774,7 +1779,7 @@ InjectTexture (tbf_tex_load_s* load) size_t offset = 0; size_t decomp_size = 0; - SzArEx_Extract ( &arc, &look_stream.s, fileno, + SzArEx_Extract ( &arc, &look_stream->s, fileno, &block_idx, &out, &out_len, &offset, &decomp_size, &thread_alloc, &thread_tmp_alloc ); @@ -1854,10 +1859,10 @@ TBFix_UpdateQueueOSD (void) if (is_resampling) { - int count = queue_len + resample_count; + size_t count = queue_len + resample_count; char szFormatted [64]; - sprintf (szFormatted, " Resampling: %li texture", count); + sprintf (szFormatted, " Resampling: %zi texture", count); resampling_text = szFormatted; resampling_text += (count != 1) ? 's' : ' '; @@ -1876,10 +1881,10 @@ TBFix_UpdateQueueOSD (void) if (is_streaming) { - int count = stream_count + to_stream; + size_t count = stream_count + to_stream; char szFormatted [64]; - sprintf (szFormatted, " Streaming: %li texture", count); + sprintf (szFormatted, " Streaming: %zi texture", count); streaming_text = szFormatted; streaming_text += (count != 1) ? 's' : ' '; @@ -3782,13 +3787,15 @@ void TBF_RefreshDataSources (void) { CFileInStream arc_stream; - CLookToRead look_stream; + + std::unique_ptr + look_stream (new CLookToRead ()); FileInStream_CreateVTable (&arc_stream); - LookToRead_CreateVTable (&look_stream, False); + LookToRead_CreateVTable (look_stream.get (), False); - look_stream.realStream = &arc_stream.s; - LookToRead_Init (&look_stream); + look_stream->realStream = &arc_stream.s; + LookToRead_Init (look_stream.get ()); injectable_textures.clear (); archives.clear (); @@ -3955,7 +3962,7 @@ TBF_RefreshDataSources (void) SzArEx_Init (&arc); if ( SzArEx_Open ( &arc, - &look_stream.s, + &look_stream->s, &thread_alloc, &thread_tmp_alloc ) == SZ_OK ) { @@ -4161,4 +4168,74 @@ tbf::RenderFix::TextureManager::reloadTexture (uint32_t checksum) TBFix_LoadQueuedTextures (); return true; +} + +void +tbf::RenderFix::TextureManager::queueScreenshot ( wchar_t* wszFileName, + bool hudless ) +{ + want_screenshot = true; + //screenshot_file = wszFileName; +} + +bool +tbf::RenderFix::TextureManager::wantsScreenshot (void) +{ + return want_screenshot; +} + +HRESULT +tbf::RenderFix::TextureManager::takeScreenshot (IDirect3DBaseTexture9* pTex) +{ + static int count = 0; + + wchar_t wszOut [MAX_PATH] = { }; + char szOut [MAX_PATH] = { }; + + _swprintf (wszOut, L"TBFix_Screenshot%lu.tga", count ); + + GetCurrentDirectoryA (MAX_PATH, szOut); + sprintf ( szOut, "%s\\TBFix_Screenshot%lu.tga", szOut, count++); + + want_screenshot = false; + + D3DSURFACE_DESC desc; + + CComPtr pRealTex = nullptr; + + pTex->QueryInterface (IID_PPV_ARGS (&pRealTex)); + + pRealTex->GetLevelDesc (0, &desc); + + start_load (); + HRESULT hr = D3DXSaveTextureToFile (wszOut, D3DXIFF_TGA, pTex, nullptr); + + if (SUCCEEDED (hr)) { + extern HMODULE hInjectorDLL; + + 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"); + + 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 ); + } + end_load (); + + return hr; } \ No newline at end of file diff --git a/version.ini b/version.ini index bc9e0c313af5e8d77306e3d679f8f84bf9d11589..9170381ab132fcd04787d20473a4dfb36fc28987 100644 GIT binary patch delta 151 zcmZpQo0qU5fSFm3!Ej=s_T(z&7Dk=PtSp}Xi41uRDGUk>9t@!jE(|#gsSL$Hr~t&t z3`Ia*Dp0W3l0k q2l90oOc@L}i?dE;n*2<)WwH*3z$8HyW=jU+$p@v3H!ow4Q3n7Yx+22> delta 56 zcmbQ2&=j{JfO%q(*5o?o7Ip=OM20+ul*!C2o}7*hDL|MCkI J<`W!Y>Hyjj5AXm0