mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-10-06 01:58:13 -07:00
sdk: add get_module_info, get_plugin_directory, d3d9 callbacks (#908)
## Link to GitHub Issue or related Pull Request, if one exists n/a ## Description of change To make plugin development easier, add `get_module_info` and `get_plugin_directory` to deal with common tasks for hooking DLLs and reading INI files. Also, add the ability to register for d3d9 present callbacks via `register_d3d9`, which makes it significantly easier for plugins to draw things on screen. ## Testing See sample code.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "launcher/shutdown.h"
|
||||
#include "misc/wintouchemu.h"
|
||||
#include "overlay/overlay.h"
|
||||
#include "sdk/d3d9.h"
|
||||
#include "util/detour.h"
|
||||
#include "util/deferlog.h"
|
||||
#include "util/flags_helper.h"
|
||||
@@ -1511,6 +1512,8 @@ void graphics_d3d9_on_present(
|
||||
device->EndScene();
|
||||
}
|
||||
|
||||
sdk::d3d9::draw(hFocusWindow, device);
|
||||
|
||||
// after the overlay render so the screenshot includes toasts / menus
|
||||
if (GRAPHICS_SCREENSHOT_INCLUDE_OVERLAY) {
|
||||
graphics_d3d9_process_screenshot(device, wrapped_device);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "games/gitadora/gitadora.h"
|
||||
#include "hooks/graphics/graphics.h"
|
||||
#include "overlay/overlay.h"
|
||||
#include "sdk/d3d9.h"
|
||||
#include "util/flags_helper.h"
|
||||
#include "util/utils.h"
|
||||
#include "cfg/screen_resize.h"
|
||||
@@ -136,6 +137,7 @@ ULONG STDMETHODCALLTYPE WrappedIDirect3DDevice9::Release() {
|
||||
|
||||
// release owned objects if there are no more references
|
||||
if (local_refs == 0) {
|
||||
sdk::d3d9::destroy(this->pReal);
|
||||
if (this->main_swapchain) {
|
||||
this->main_swapchain->Release();
|
||||
this->main_swapchain = nullptr;
|
||||
@@ -632,6 +634,8 @@ HRESULT STDMETHODCALLTYPE WrappedIDirect3DDevice9::Reset(
|
||||
}
|
||||
}
|
||||
|
||||
sdk::d3d9::invalidate(pReal);
|
||||
|
||||
// reset overlay
|
||||
if (overlay::OVERLAY && overlay::OVERLAY->uses_device(pReal)) {
|
||||
overlay::OVERLAY->reset_invalidate();
|
||||
@@ -643,6 +647,7 @@ HRESULT STDMETHODCALLTYPE WrappedIDirect3DDevice9::Reset(
|
||||
d3d9_readback::discard_snapshot_targets(pReal);
|
||||
|
||||
HRESULT res = pReal->Reset(pPresentationParameters);
|
||||
sdk::d3d9::reset_complete(pReal, SUCCEEDED(res));
|
||||
|
||||
// recreate overlay
|
||||
if (overlay::OVERLAY && overlay::OVERLAY->uses_device(pReal) && SUCCEEDED(res)) {
|
||||
@@ -673,7 +678,9 @@ HRESULT STDMETHODCALLTYPE WrappedIDirect3DDevice9::Present(
|
||||
gfdm_small_head.compose(this);
|
||||
}
|
||||
|
||||
CHECK_RESULT(pReal->Present(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion));
|
||||
const HRESULT result = pReal->Present(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
|
||||
sdk::d3d9::present_complete(pReal, result);
|
||||
CHECK_RESULT(result);
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE WrappedIDirect3DDevice9::GetBackBuffer(
|
||||
@@ -2088,8 +2095,10 @@ HRESULT STDMETHODCALLTYPE WrappedIDirect3DDevice9::PresentEx(
|
||||
|
||||
graphics_d3d9_on_present(hFocusWindow, pReal, this);
|
||||
|
||||
CHECK_RESULT(static_cast<IDirect3DDevice9Ex *>(pReal)->PresentEx(
|
||||
pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags));
|
||||
const HRESULT result = static_cast<IDirect3DDevice9Ex *>(pReal)->PresentEx(
|
||||
pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
|
||||
sdk::d3d9::present_complete(pReal, result);
|
||||
CHECK_RESULT(result);
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE WrappedIDirect3DDevice9::GetGPUThreadPriority(
|
||||
@@ -2336,6 +2345,8 @@ HRESULT STDMETHODCALLTYPE WrappedIDirect3DDevice9::ResetEx(
|
||||
}
|
||||
}
|
||||
|
||||
sdk::d3d9::invalidate(pReal);
|
||||
|
||||
// reset overlay
|
||||
if (overlay::OVERLAY && overlay::OVERLAY->uses_device(pReal)) {
|
||||
overlay::OVERLAY->reset_invalidate();
|
||||
@@ -2350,6 +2361,8 @@ HRESULT STDMETHODCALLTYPE WrappedIDirect3DDevice9::ResetEx(
|
||||
gfdm_parameters.presentation_parameters,
|
||||
gfdm_parameters.fullscreen_display_modes);
|
||||
|
||||
sdk::d3d9::reset_complete(pReal, SUCCEEDED(res));
|
||||
|
||||
if (is_gfdm_two_head_exclusive()
|
||||
&& SUCCEEDED(res)
|
||||
&& gfdm_parameters.recovery_candidate)
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "games/gitadora/gitadora.h"
|
||||
#include "hooks/graphics/graphics.h"
|
||||
#include "sdk/d3d9.h"
|
||||
#include "util/logging.h"
|
||||
|
||||
#include "d3d9_device.h"
|
||||
@@ -558,6 +559,7 @@ HRESULT graphics_d3d9_gfdm_recover_two_head_present_mode(
|
||||
temporary_parameters[1].FullScreen_RefreshRateInHz = alternate_small.RefreshRate;
|
||||
temporary_modes[1] = alternate_small;
|
||||
|
||||
sdk::d3d9::invalidate(device);
|
||||
HRESULT temporary_result = device->ResetEx(temporary_parameters, temporary_modes);
|
||||
const bool temporary_settled =
|
||||
temporary_result == D3D_OK
|
||||
@@ -574,6 +576,8 @@ HRESULT graphics_d3d9_gfdm_recover_two_head_present_mode(
|
||||
restore_result == D3D_OK
|
||||
&& gfdm_wait_for_small_mode(desired_parameters[1].hDeviceWindow, desired_modes[1]);
|
||||
|
||||
sdk::d3d9::reset_complete(device, SUCCEEDED(restore_result));
|
||||
|
||||
if (temporary_result != D3D_OK) {
|
||||
return temporary_result;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "avs/game.h"
|
||||
#include "hooks/graphics/graphics.h"
|
||||
#include "sdk/d3d9.h"
|
||||
|
||||
#include "d3d9_backend.h"
|
||||
#include "d3d9_device.h"
|
||||
@@ -140,6 +141,9 @@ HRESULT STDMETHODCALLTYPE WrappedIDirect3DSwapChain9::Present(const RECT *pSourc
|
||||
result = recovery_failure;
|
||||
}
|
||||
}
|
||||
if (should_run_hooks) {
|
||||
sdk::d3d9::present_complete(pDev->pReal, result);
|
||||
}
|
||||
CHECK_RESULT(result);
|
||||
}
|
||||
HRESULT STDMETHODCALLTYPE WrappedIDirect3DSwapChain9::GetFrontBufferData(IDirect3DSurface9 *pDestSurface) {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <chrono>
|
||||
#include <set>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
@@ -396,7 +397,12 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
|
||||
// terminate
|
||||
if (uMsg == WM_CLOSE) {
|
||||
log_info("graphics", "detected WM_CLOSE, terminating...");
|
||||
launcher::shutdown(0);
|
||||
static std::once_flag shutdown_requested;
|
||||
std::call_once(shutdown_requested, [] {
|
||||
std::thread([] {
|
||||
launcher::shutdown(0);
|
||||
}).detach();
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user