graphics: option to include subscreens in screenshot (#866)

## Link to GitHub Issue or related Pull Request, if one exists
#0

## Description of change
Adds `-screenshotsub`. Off by default. When on, screenshots include the
subscreens. All subscreens are captured, even if they are hidden from
view. Works for all four screens of gitadora arena model as well.

This should also fix an issue with API / companion app not capturing
gitadora subscreen correctly.

Note: only done for DX9... DX11 will need another PR to make this work.

Unrelated to this PR, there seems to be a bug with gitadora not
accepting mouse or api touch input.

## Testing
This commit is contained in:
bicarus
2026-08-14 04:05:50 -07:00
committed by GitHub
parent c6cd72c528
commit f5888609a8
11 changed files with 257 additions and 70 deletions
@@ -1478,7 +1478,7 @@ static void graphics_d3d9_ldj_on_present(IDirect3DDevice9 *wrapped_device) {
void graphics_d3d9_on_present( void graphics_d3d9_on_present(
HWND hFocusWindow, HWND hFocusWindow,
IDirect3DDevice9 *device, IDirect3DDevice9 *device,
IDirect3DDevice9 *wrapped_device) { WrappedIDirect3DDevice9 *wrapped_device) {
// image resize / orientation swap. run here (the present path) rather than from `EndScene`, // image resize / orientation swap. run here (the present path) rather than from `EndScene`,
// which may fire several times per frame on multi-pass / render-to-texture games. this is the // which may fire several times per frame on multi-pass / render-to-texture games. this is the
@@ -1493,7 +1493,7 @@ void graphics_d3d9_on_present(
// before the overlay render so the screenshot excludes it // before the overlay render so the screenshot excludes it
if (!GRAPHICS_SCREENSHOT_INCLUDE_OVERLAY) { if (!GRAPHICS_SCREENSHOT_INCLUDE_OVERLAY) {
graphics_d3d9_process_screenshot(device, SUB_SWAP_CHAIN); graphics_d3d9_process_screenshot(device, wrapped_device);
} }
// Do overlay init as many d3d9 hooks create a dummy instance to get vtable offsets and never // Do overlay init as many d3d9 hooks create a dummy instance to get vtable offsets and never
@@ -1517,7 +1517,7 @@ void graphics_d3d9_on_present(
// after the overlay render so the screenshot includes toasts / menus // after the overlay render so the screenshot includes toasts / menus
if (GRAPHICS_SCREENSHOT_INCLUDE_OVERLAY) { if (GRAPHICS_SCREENSHOT_INCLUDE_OVERLAY) {
graphics_d3d9_process_screenshot(device, SUB_SWAP_CHAIN); graphics_d3d9_process_screenshot(device, wrapped_device);
} }
// for IIDX TDJ / SDVX UFC, handle subscreen // for IIDX TDJ / SDVX UFC, handle subscreen
@@ -1535,7 +1535,7 @@ void graphics_d3d9_on_present(
} }
// API capture always includes the overlay // API capture always includes the overlay
graphics_d3d9_process_capture(device, SUB_SWAP_CHAIN); graphics_d3d9_process_capture(device, wrapped_device);
} }
void update_backbuffer_dimensions(D3DPRESENT_PARAMETERS *params) { void update_backbuffer_dimensions(D3DPRESENT_PARAMETERS *params) {
@@ -4,6 +4,8 @@
#include "d3d9_gfdm.h" #include "d3d9_gfdm.h"
struct WrappedIDirect3DDevice9;
// {EEE9CCF6-53D6-4326-9AE5-60921B3DB394} // {EEE9CCF6-53D6-4326-9AE5-60921B3DB394}
static const GUID IID_WrappedIDirect3D9 = { static const GUID IID_WrappedIDirect3D9 = {
0xeee9ccf6, 0x53d6, 0x4326, { 0x9a, 0xe5, 0x60, 0x92, 0x1b, 0x3d, 0xb3, 0x94 } 0xeee9ccf6, 0x53d6, 0x4326, { 0x9a, 0xe5, 0x60, 0x92, 0x1b, 0x3d, 0xb3, 0x94 }
@@ -13,7 +15,7 @@ void graphics_d3d9_init();
void graphics_d3d9_on_present( void graphics_d3d9_on_present(
HWND hFocusWindow, HWND hFocusWindow,
IDirect3DDevice9 *device, IDirect3DDevice9 *device,
IDirect3DDevice9 *wrapped_device); WrappedIDirect3DDevice9 *wrapped_device);
void graphics_d3d9_notify_subscreen_present(); void graphics_d3d9_notify_subscreen_present();
@@ -23,6 +23,11 @@
#include "shaders/vertex_shader.h" #include "shaders/vertex_shader.h"
#endif #endif
// maps arena's cached additional swap chains (SMALL, LEFT, RIGHT) to screen numbers.
// MAIN is the implicit swap chain, is not in those slots, and is always screen 0.
// screen 1 is the subscreen for every other game, so SMALL takes that number here too.
static constexpr int GFDM_ARENA_SLOT_SCREENS[] { 1, 2, 3 };
#define CHECK_RESULT_FMT(x, fmt, ...) \ #define CHECK_RESULT_FMT(x, fmt, ...) \
HRESULT __ret = (x); \ HRESULT __ret = (x); \
if (GRAPHICS_LOG_HRESULT && FAILED(__ret)) [[unlikely]] { \ if (GRAPHICS_LOG_HRESULT && FAILED(__ret)) [[unlikely]] { \
@@ -336,20 +341,25 @@ HRESULT STDMETHODCALLTYPE WrappedIDirect3DDevice9::CreateAdditionalSwapChain(
int index = 0; int index = 0;
bool create_swap_chain = false; bool create_swap_chain = false;
bool create_fake_swap_chain = false; bool create_fake_swap_chain = false;
bool arena_slot = false;
if (avs::game::is_model({"LDJ", "KFC", "M39"})) { if (avs::game::is_model({"LDJ", "KFC", "M39"})) {
create_swap_chain = true; create_swap_chain = true;
} else if (games::gitadora::is_arena_model() && } else if (games::gitadora::is_arena_model() &&
(GRAPHICS_PREVENT_SECONDARY_WINDOWS || GRAPHICS_GITADORA_HIDE_SIDE_WINDOWS)) { (GRAPHICS_SCREENSHOT_SUBSCREENS ||
GRAPHICS_PREVENT_SECONDARY_WINDOWS ||
GRAPHICS_GITADORA_HIDE_SIDE_WINDOWS)) {
if (pPresentationParameters->BackBufferWidth == 800) { if (pPresentationParameters->BackBufferWidth == 800) {
// SMALL (subscreen) // SMALL (subscreen)
create_swap_chain = true; create_swap_chain = true;
arena_slot = true;
index = 0; index = 0;
} else if (pPresentationParameters->BackBufferWidth == 1080) { } else if (pPresentationParameters->BackBufferWidth == 1080) {
// LEFT/RIGHT // LEFT/RIGHT
create_swap_chain = true; create_swap_chain = true;
arena_slot = true;
index = 1; index = 1;
if (sub_swapchain[index] || fake_sub_swapchain[index]) { if (sub_swapchain[index] || fake_sub_swapchain[index]) {
index = 2; index = 2;
@@ -361,6 +371,11 @@ HRESULT STDMETHODCALLTYPE WrappedIDirect3DDevice9::CreateAdditionalSwapChain(
} }
} }
// the api lists screens from this registry, so arena heads need their logical numbers in it
if (arena_slot) {
graphics_screens_register(GFDM_ARENA_SLOT_SCREENS[index]);
}
if (create_fake_swap_chain) { if (create_fake_swap_chain) {
if (!fake_sub_swapchain[index]) { if (!fake_sub_swapchain[index]) {
log_info( log_info(
@@ -539,6 +554,64 @@ UINT STDMETHODCALLTYPE WrappedIDirect3DDevice9::GetNumberOfSwapChains() {
return n; return n;
} }
void WrappedIDirect3DDevice9::get_screenshot_screens(std::vector<int> &screens) const {
if (games::gitadora::is_arena_model()) {
screens.push_back(0);
// every head the game renders into, whether or not it reaches a display
for (int slot = 0; slot < 3; slot++) {
if (sub_swapchain[slot] != nullptr || fake_sub_swapchain[slot] != nullptr) {
screens.push_back(GFDM_ARENA_SLOT_SCREENS[slot]);
}
}
return;
}
graphics_screens_get(screens);
// the sub screen is only registered once the game asks for it by index
if (sub_swapchain[0] != nullptr &&
avs::game::is_model({"LDJ", "KFC", "M39"}) &&
std::find(screens.begin(), screens.end(), 1) == screens.end())
{
screens.push_back(1);
}
}
HRESULT WrappedIDirect3DDevice9::get_screenshot_swap_chain(
UINT iSwapChain,
IDirect3DSwapChain9 **ppSwapChain)
{
if (ppSwapChain == nullptr) {
return D3DERR_INVALIDCALL;
}
// the game numbers the two-head SMALL head itself; keep screen 1 meaning SMALL
if (games::gitadora::is_arena_model() && is_gfdm_two_head_exclusive() && iSwapChain == 1) {
return GetSwapChain(gfdm_logical_small_swapchain, ppSwapChain);
}
if (games::gitadora::is_arena_model()) {
for (int slot = 0; slot < 3; slot++) {
if (GFDM_ARENA_SLOT_SCREENS[slot] != (int) iSwapChain) {
continue;
}
if (sub_swapchain[slot] != nullptr) {
sub_swapchain[slot]->AddRef();
*ppSwapChain = sub_swapchain[slot];
return D3D_OK;
}
if (fake_sub_swapchain[slot] != nullptr) {
fake_sub_swapchain[slot]->AddRef();
*ppSwapChain = fake_sub_swapchain[slot];
return D3D_OK;
}
}
}
return GetSwapChain(iSwapChain, ppSwapChain);
}
HRESULT STDMETHODCALLTYPE WrappedIDirect3DDevice9::Reset( HRESULT STDMETHODCALLTYPE WrappedIDirect3DDevice9::Reset(
D3DPRESENT_PARAMETERS *pPresentationParameters) D3DPRESENT_PARAMETERS *pPresentationParameters)
{ {
@@ -3,6 +3,7 @@
#include <array> #include <array>
#include <atomic> #include <atomic>
#include <mutex> #include <mutex>
#include <vector>
#include <initguid.h> #include <initguid.h>
#include <d3d9.h> #include <d3d9.h>
@@ -234,6 +235,10 @@ struct WrappedIDirect3DDevice9 : IDirect3DDevice9Ex {
virtual HRESULT STDMETHODCALLTYPE GetDisplayModeEx(UINT iSwapChain, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation) override; virtual HRESULT STDMETHODCALLTYPE GetDisplayModeEx(UINT iSwapChain, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation) override;
#pragma endregion #pragma endregion
// logical screens the game draws, and the swap chain each one lives on
void get_screenshot_screens(std::vector<int> &screens) const;
HRESULT get_screenshot_swap_chain(UINT iSwapChain, IDirect3DSwapChain9 **ppSwapChain);
bool is_gfdm_two_head_exclusive() const; bool is_gfdm_two_head_exclusive() const;
bool is_gfdm_logical_small_swapchain(UINT swapchain) const; bool is_gfdm_logical_small_swapchain(UINT swapchain) const;
bool is_gfdm_logical_side_swapchain(UINT swapchain) const; bool is_gfdm_logical_side_swapchain(UINT swapchain) const;
@@ -1,10 +1,13 @@
#include "d3d9_screenshot.h" #include "d3d9_screenshot.h"
#include <cstdint> #include <cstdint>
#include <filesystem>
#include <memory> #include <memory>
#include <mutex>
#include <optional> #include <optional>
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector>
#include <external/robin_hood.h> #include <external/robin_hood.h>
@@ -21,6 +24,8 @@
#include "util/logging.h" #include "util/logging.h"
#include "util/threadpool.h" #include "util/threadpool.h"
#include "d3d9_device.h"
#ifdef __GNUC__ #ifdef __GNUC__
typedef decltype(D3DXSaveSurfaceToFileA) *D3DXSaveSurfaceToFileA_t; typedef decltype(D3DXSaveSurfaceToFileA) *D3DXSaveSurfaceToFileA_t;
#else #else
@@ -36,6 +41,9 @@ typedef HRESULT (WINAPI *D3DXSaveSurfaceToFileA_t)(
static bool ATTEMPTED_D3DX9_LOAD_LIBRARY = false; static bool ATTEMPTED_D3DX9_LOAD_LIBRARY = false;
// genpath picks free filenames by probing the disk, so only one save may run at a time
static std::mutex SCREENSHOT_SAVE_M;
namespace { namespace {
enum class ImageRequestKind { enum class ImageRequestKind {
@@ -57,6 +65,7 @@ struct SurfaceReleaser {
using SurfacePtr = std::unique_ptr<IDirect3DSurface9, SurfaceReleaser>; using SurfacePtr = std::unique_ptr<IDirect3DSurface9, SurfaceReleaser>;
struct BackbufferCopy { struct BackbufferCopy {
int screen {};
D3DSURFACE_DESC desc {}; D3DSURFACE_DESC desc {};
SurfacePtr surface; SurfacePtr surface;
}; };
@@ -142,7 +151,7 @@ static void save_capture(
graphics_capture_enqueue(screen, pixels.release(), width, height); graphics_capture_enqueue(screen, pixels.release(), width, height);
} }
static void save_screenshot( static bool save_screenshot(
const std::string &file_path, const std::string &file_path,
D3DFORMAT format, D3DFORMAT format,
UINT width, UINT width,
@@ -156,7 +165,7 @@ static void save_screenshot(
HRESULT hr = surface->LockRect(&finished_copy, nullptr, 0); HRESULT hr = surface->LockRect(&finished_copy, nullptr, 0);
if (FAILED(hr)) { if (FAILED(hr)) {
log_warning("graphics::d3d9", "failed to lock screenshot surface, hr={}", FMT_HRESULT(hr)); log_warning("graphics::d3d9", "failed to lock screenshot surface, hr={}", FMT_HRESULT(hr));
return; return false;
} }
const size_t pitch = finished_copy.Pitch; const size_t pitch = finished_copy.Pitch;
@@ -170,7 +179,7 @@ static void save_screenshot(
hr = surface->UnlockRect(); hr = surface->UnlockRect();
if (FAILED(hr)) { if (FAILED(hr)) {
log_warning("graphics::d3d9", "failed to unlock screenshot surface, hr={}", FMT_HRESULT(hr)); log_warning("graphics::d3d9", "failed to unlock screenshot surface, hr={}", FMT_HRESULT(hr));
return; return false;
} }
} }
@@ -210,7 +219,10 @@ static void save_screenshot(
} }
} }
if (D3DXSaveSurfaceToFileA_ptr != nullptr) { if (D3DXSaveSurfaceToFileA_ptr == nullptr) {
log_warning("graphics::d3d9", "Direct3D save helper function not available");
return false;
}
// save to file // save to file
log_info("graphics::d3d9", "saving screenshot to {}", file_path); log_info("graphics::d3d9", "saving screenshot to {}", file_path);
@@ -219,39 +231,33 @@ static void save_screenshot(
if (FAILED(save_result)) { if (FAILED(save_result)) {
log_warning("graphics::d3d9", "Failed to save screenshot"); log_warning("graphics::d3d9", "Failed to save screenshot");
overlay::notifications::add( return false;
overlay::notifications::Severity::Error,
"Screenshot failed to save");
return;
} }
// save to clipboard return true;
clipboard::copy_image(file_path); }
overlay::notifications::add( // screen 0 keeps the plain name so existing tooling and the clipboard copy are unaffected
overlay::notifications::Severity::Success, static std::string screenshot_path_for_screen(const std::string &primary_path, int screen) {
fmt::format("Screenshot saved: {}", fileutils::basename(file_path))); if (screen == 0) {
} else { return primary_path;
log_warning("graphics::d3d9", "Direct3D save helper function not available");
} }
const std::filesystem::path path(primary_path);
return (path.parent_path() /
fmt::format("{}_{}{}", path.stem().string(), screen, path.extension().string()))
.string();
} }
static std::optional<BackbufferCopy> acquire_backbuffer_copy( static std::optional<BackbufferCopy> acquire_backbuffer_copy(
IDirect3DDevice9 *device, IDirect3DSwapChain9 *sub_swap_chain, int screen) { IDirect3DDevice9 *device, IDirect3DSwapChain9 *swap_chain, int screen) {
HRESULT hr = S_OK;
// TODO: verify screen is a valid swapchain
IDirect3DSurface9 *buffer = nullptr; IDirect3DSurface9 *buffer = nullptr;
if (sub_swap_chain != nullptr && screen & 1) { HRESULT hr = swap_chain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &buffer);
hr = sub_swap_chain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &buffer);
} else {
hr = device->GetBackBuffer(screen, 0, D3DBACKBUFFER_TYPE_MONO, &buffer);
}
if (FAILED(hr) || buffer == nullptr) { if (FAILED(hr) || buffer == nullptr) {
log_warning("graphics::d3d9", log_warning("graphics::d3d9",
"failed to get back buffer, hr={}", "failed to get back buffer for screen {}, hr={}",
screen,
FMT_HRESULT(hr)); FMT_HRESULT(hr));
return std::nullopt; return std::nullopt;
} }
@@ -293,6 +299,7 @@ static std::optional<BackbufferCopy> acquire_backbuffer_copy(
buffer->Release(); buffer->Release();
return BackbufferCopy { return BackbufferCopy {
.screen = screen,
.desc = desc, .desc = desc,
.surface = SurfacePtr(temp_surface), .surface = SurfacePtr(temp_surface),
}; };
@@ -300,10 +307,12 @@ static std::optional<BackbufferCopy> acquire_backbuffer_copy(
static void dispatch_surface_save( static void dispatch_surface_save(
const ImageRequest &request, const ImageRequest &request,
BackbufferCopy copy) { std::vector<BackbufferCopy> copies,
auto surface_process = [request, copy = std::move(copy)]() { size_t screen_count) {
auto surface_process = [request, screen_count, copies = std::move(copies)]() {
switch (request.kind) { switch (request.kind) {
case ImageRequestKind::Capture: case ImageRequestKind::Capture: {
const auto &copy = copies.front();
save_capture( save_capture(
request.screen, request.screen,
copy.desc.Format, copy.desc.Format,
@@ -311,16 +320,61 @@ static void dispatch_surface_save(
copy.desc.Height, copy.desc.Height,
copy.surface.get()); copy.surface.get());
break; break;
}
case ImageRequestKind::Screenshot: { case ImageRequestKind::Screenshot: {
auto file_path = graphics_screenshot_genpath(); std::lock_guard<std::mutex> lock(SCREENSHOT_SAVE_M);
if (!file_path.empty()) {
save_screenshot( std::vector<int> screens;
file_path, screens.reserve(copies.size());
for (const auto &copy : copies) {
screens.push_back(copy.screen);
}
const auto base_path = graphics_screenshot_genpath(screens);
if (base_path.empty()) {
break;
}
// screens missing from copies already failed to be acquired
size_t failed = screen_count - copies.size();
std::string primary_path;
std::string notify_path;
for (const auto &copy : copies) {
const auto path = screenshot_path_for_screen(base_path, copy.screen);
if (!save_screenshot(
path,
copy.desc.Format, copy.desc.Format,
copy.desc.Width, copy.desc.Width,
copy.desc.Height, copy.desc.Height,
copy.surface.get()); copy.surface.get())) {
failed++;
continue;
}
if (notify_path.empty()) {
notify_path = path;
}
if (copy.screen == 0) {
primary_path = path;
}
}
// only the primary screen goes to the clipboard, but any saved file is a success
if (!primary_path.empty()) {
clipboard::copy_image(primary_path);
}
if (!notify_path.empty()) {
overlay::notifications::add(
overlay::notifications::Severity::Success,
fmt::format("Screenshot saved: {}", fileutils::basename(notify_path)));
} else {
overlay::notifications::add(
overlay::notifications::Severity::Error,
"Screenshot failed to save");
}
if (failed > 0) {
log_warning("graphics::d3d9", "{} screenshot screen(s) missing", failed);
} }
break; break;
} }
@@ -350,27 +404,53 @@ static void dispatch_surface_save(
static void process_image_request( static void process_image_request(
IDirect3DDevice9 *device, IDirect3DDevice9 *device,
IDirect3DSwapChain9 *sub_swap_chain, WrappedIDirect3DDevice9 *wrapped_device,
const ImageRequest &request) { const ImageRequest &request) {
auto copy = acquire_backbuffer_copy( const bool screenshot = request.kind == ImageRequestKind::Screenshot;
device,
sub_swap_chain, std::vector<int> screens { request.screen };
request.screen); if (screenshot && GRAPHICS_SCREENSHOT_SUBSCREENS) {
if (!copy.has_value()) { screens.clear();
if (request.kind == ImageRequestKind::Capture) { wrapped_device->get_screenshot_screens(screens);
graphics_capture_skip(request.screen);
} }
std::vector<BackbufferCopy> copies;
copies.reserve(screens.size());
for (const int screen : screens) {
std::optional<BackbufferCopy> copy;
IDirect3DSwapChain9 *swap_chain = nullptr;
HRESULT hr = wrapped_device->get_screenshot_swap_chain(screen, &swap_chain);
if (FAILED(hr) || swap_chain == nullptr) {
log_warning("graphics::d3d9",
"failed to get swap chain for screen {}, hr={}",
screen,
FMT_HRESULT(hr));
} else {
copy = acquire_backbuffer_copy(device, swap_chain, screen);
swap_chain->Release();
}
if (copy.has_value()) {
copies.emplace_back(std::move(*copy));
} else if (!screenshot) {
graphics_capture_skip(request.screen);
return;
}
}
if (copies.empty()) {
return; return;
} }
dispatch_surface_save(request, std::move(*copy)); dispatch_surface_save(request, std::move(copies), screens.size());
} }
void graphics_d3d9_process_screenshot( void graphics_d3d9_process_screenshot(
IDirect3DDevice9 *device, IDirect3DDevice9 *device,
IDirect3DSwapChain9 *sub_swap_chain) { WrappedIDirect3DDevice9 *wrapped_device) {
if (graphics_screenshot_consume()) { if (graphics_screenshot_consume()) {
process_image_request(device, sub_swap_chain, ImageRequest { process_image_request(device, wrapped_device, ImageRequest {
.kind = ImageRequestKind::Screenshot, .kind = ImageRequestKind::Screenshot,
.screen = 0, .screen = 0,
}); });
@@ -379,10 +459,10 @@ void graphics_d3d9_process_screenshot(
void graphics_d3d9_process_capture( void graphics_d3d9_process_capture(
IDirect3DDevice9 *device, IDirect3DDevice9 *device,
IDirect3DSwapChain9 *sub_swap_chain) { WrappedIDirect3DDevice9 *wrapped_device) {
int screen = 0; int screen = 0;
if (graphics_capture_consume(&screen)) { if (graphics_capture_consume(&screen)) {
process_image_request(device, sub_swap_chain, ImageRequest { process_image_request(device, wrapped_device, ImageRequest {
.kind = ImageRequestKind::Capture, .kind = ImageRequestKind::Capture,
.screen = screen, .screen = screen,
}); });
@@ -2,10 +2,12 @@
#include <d3d9.h> #include <d3d9.h>
struct WrappedIDirect3DDevice9;
void graphics_d3d9_process_screenshot( void graphics_d3d9_process_screenshot(
IDirect3DDevice9 *device, IDirect3DDevice9 *device,
IDirect3DSwapChain9 *sub_swap_chain); WrappedIDirect3DDevice9 *wrapped_device);
void graphics_d3d9_process_capture( void graphics_d3d9_process_capture(
IDirect3DDevice9 *device, IDirect3DDevice9 *device,
IDirect3DSwapChain9 *sub_swap_chain); WrappedIDirect3DDevice9 *wrapped_device);
+14 -3
View File
@@ -119,6 +119,7 @@ uint32_t GRAPHICS_FS_ORIGINAL_HEIGHT = 0;
std::string GRAPHICS_DEVICEID = "PCI\\VEN_1002&DEV_7146"; std::string GRAPHICS_DEVICEID = "PCI\\VEN_1002&DEV_7146";
std::string GRAPHICS_SCREENSHOT_DIR = ".\\screenshots"; std::string GRAPHICS_SCREENSHOT_DIR = ".\\screenshots";
bool GRAPHICS_SCREENSHOT_INCLUDE_OVERLAY = false; bool GRAPHICS_SCREENSHOT_INCLUDE_OVERLAY = false;
bool GRAPHICS_SCREENSHOT_SUBSCREENS = false;
static decltype(ChangeDisplaySettingsA) *ChangeDisplaySettingsA_orig = nullptr; static decltype(ChangeDisplaySettingsA) *ChangeDisplaySettingsA_orig = nullptr;
static decltype(ChangeDisplaySettingsExA) *ChangeDisplaySettingsExA_orig = nullptr; static decltype(ChangeDisplaySettingsExA) *ChangeDisplaySettingsExA_orig = nullptr;
@@ -1531,7 +1532,7 @@ bool graphics_capture_receive_jpeg(int screen, TooJpeg::WRITE_ONE_BYTE receiver,
return success; return success;
} }
std::string graphics_screenshot_genpath() { std::string graphics_screenshot_genpath(const std::vector<int> &screens) {
// verify dir path // verify dir path
if (GRAPHICS_SCREENSHOT_DIR.empty()) { if (GRAPHICS_SCREENSHOT_DIR.empty()) {
@@ -1556,11 +1557,21 @@ std::string graphics_screenshot_genpath() {
auto tm_now = *std::gmtime(&t_now); auto tm_now = *std::gmtime(&t_now);
auto prefix = to_string(std::put_time(&tm_now, "%Y%m%d")); auto prefix = to_string(std::put_time(&tm_now, "%Y%m%d"));
// find next filename // find next filename; the whole set has to be free so one shot stays numbered together
size_t id = 0; size_t id = 0;
while (true) { while (true) {
auto filepath = fmt::format("{}\\{}_{}.png", GRAPHICS_SCREENSHOT_DIR, prefix, id); auto filepath = fmt::format("{}\\{}_{}.png", GRAPHICS_SCREENSHOT_DIR, prefix, id);
if (!fileutils::file_exists(filepath)) { bool available = !fileutils::file_exists(filepath);
for (const auto screen : screens) {
if (!available) {
break;
}
if (screen != 0) {
available = !fileutils::file_exists(fmt::format(
"{}\\{}_{}_{}.png", GRAPHICS_SCREENSHOT_DIR, prefix, id, screen));
}
}
if (available) {
return filepath; return filepath;
} }
+3 -1
View File
@@ -112,6 +112,7 @@ extern bool FAKE_SUBSCREEN_ADAPTER;
extern std::string GRAPHICS_DEVICEID; extern std::string GRAPHICS_DEVICEID;
extern std::string GRAPHICS_SCREENSHOT_DIR; extern std::string GRAPHICS_SCREENSHOT_DIR;
extern bool GRAPHICS_SCREENSHOT_INCLUDE_OVERLAY; extern bool GRAPHICS_SCREENSHOT_INCLUDE_OVERLAY;
extern bool GRAPHICS_SCREENSHOT_SUBSCREENS;
// Direct3D 9 settings // Direct3D 9 settings
extern std::optional<UINT> D3D9_ADAPTER; extern std::optional<UINT> D3D9_ADAPTER;
@@ -146,7 +147,8 @@ bool graphics_capture_receive_jpeg(int screen, TooJpeg::WRITE_ONE_BYTE receiver,
bool rgb = true, int quality = 80, bool downsample = true, int divide = 0, bool rgb = true, int quality = 80, bool downsample = true, int divide = 0,
uint64_t *timestamp = nullptr, uint64_t *timestamp = nullptr,
int *width = nullptr, int *height = nullptr); int *width = nullptr, int *height = nullptr);
std::string graphics_screenshot_genpath(); // the returned path is for screen 0; any extra screens only reserve their suffixed names
std::string graphics_screenshot_genpath(const std::vector<int> &screens = {});
// graphics_windowed.cpp // graphics_windowed.cpp
void graphics_windowed_wndproc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); void graphics_windowed_wndproc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+3
View File
@@ -1106,6 +1106,9 @@ int main_implementation(int argc, char *argv[]) {
if (options[launcher::Options::ScreenshotIncludeOverlay].value_bool()) { if (options[launcher::Options::ScreenshotIncludeOverlay].value_bool()) {
GRAPHICS_SCREENSHOT_INCLUDE_OVERLAY = true; GRAPHICS_SCREENSHOT_INCLUDE_OVERLAY = true;
} }
if (options[launcher::Options::ScreenshotSubscreens].value_bool()) {
GRAPHICS_SCREENSHOT_SUBSCREENS = true;
}
if (options[launcher::Options::DisableColoredOutput].value_bool()) { if (options[launcher::Options::DisableColoredOutput].value_bool()) {
logger::COLOR = false; logger::COLOR = false;
} }
+8
View File
@@ -3405,6 +3405,14 @@ static const std::vector<OptionDefinition> OPTION_DEFINITIONS = {
.type = OptionType::Bool, .type = OptionType::Bool,
.category = "General Overlay", .category = "General Overlay",
}, },
{
// ScreenshotSubscreens
.title = "Include Subscreens in Screenshots",
.name = "screenshotsub",
.desc = "Saves each subscreen as a separate PNG alongside the primary screenshot.",
.type = OptionType::Bool,
.category = "General Overlay",
},
}; };
const std::vector<std::string> &launcher::get_categories(Options::OptionsCategory category) { const std::vector<std::string> &launcher::get_categories(Options::OptionsCategory category) {
+2 -1
View File
@@ -321,7 +321,8 @@ namespace launcher {
OBSWebSocketPort, OBSWebSocketPort,
OBSWebSocketPassword, OBSWebSocketPassword,
OBSWebSocketDebug, OBSWebSocketDebug,
ScreenshotIncludeOverlay ScreenshotIncludeOverlay,
ScreenshotSubscreens
}; };
enum class OptionsCategory { enum class OptionsCategory {