From 6fce41bf0922bfa6e0aad7232ca9dd879395cfb1 Mon Sep 17 00:00:00 2001 From: ledoge <8040316+ledoge@users.noreply.github.com> Date: Sat, 27 Nov 2021 20:03:08 +0100 Subject: [PATCH] Disable LUT when HDCP is active --- dwm_lut.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/dwm_lut.c b/dwm_lut.c index 39fb373..2833606 100644 --- a/dwm_lut.c +++ b/dwm_lut.c @@ -23,6 +23,8 @@ const unsigned char COverlayContext_OverlaysEnabled_bytes[] = {0x75, 0x04, 0x32, const int COverlayContext_DeviceClipBox_offset = -0x120; +const int IOverlaySwapChain_HardwareProtected_offset = -0xbc; + const unsigned char COverlayContext_Present_bytes_w11[] = {0x48, 0x33, 0xc4, 0x48, 0x89, 0x44, 0x24, 0x50, 0x48, 0x8b, 0xb1, 0xa0, 0x2b, 0x00, 0x00, 0x48, 0x8b, 0xfa, 0x48, 0x8b, 0xd9, 0x48, 0x85, 0xf6}; const int IOverlaySwapChain_IDXGISwapChain_offset_w11 = -0x148; @@ -31,6 +33,8 @@ const unsigned char COverlayContext_OverlaysEnabled_bytes_w11[] = {0x74, 0x09, 0 const int COverlayContext_DeviceClipBox_offset_w11 = 0x462c; +const int IOverlaySwapChain_HardwareProtected_offset_w11 = -0xec; + bool isWindows11; #pragma push_macro("bool") @@ -623,17 +627,22 @@ COverlayContext_Present_t *COverlayContext_Present_real_orig; long COverlayContext_Present_hook(void *this, void *overlaySwapChain, unsigned int a3, rectVec *rectVec, unsigned int a5, bool a6) { if (__builtin_return_address(0) < (void *) COverlayContext_Present_real_orig) { - IDXGISwapChain *swapChain; - if (isWindows11) { - swapChain = *(IDXGISwapChain **) ((unsigned char *) overlaySwapChain + IOverlaySwapChain_IDXGISwapChain_offset_w11); + if (isWindows11 && *((bool *) overlaySwapChain + IOverlaySwapChain_HardwareProtected_offset_w11) || + !isWindows11 && *((bool *) overlaySwapChain + IOverlaySwapChain_HardwareProtected_offset)) { + RemoveLUTActiveTarget(this); } else { - swapChain = *(IDXGISwapChain **) ((unsigned char *) overlaySwapChain + IOverlaySwapChain_IDXGISwapChain_offset); - } + IDXGISwapChain *swapChain; + if (isWindows11) { + swapChain = *(IDXGISwapChain **) ((unsigned char *) overlaySwapChain + IOverlaySwapChain_IDXGISwapChain_offset_w11); + } else { + swapChain = *(IDXGISwapChain **) ((unsigned char *) overlaySwapChain + IOverlaySwapChain_IDXGISwapChain_offset); + } - if (ApplyLUT(this, swapChain, rectVec->start, rectVec->end - rectVec->start)) { - AddLUTActiveTarget(this); - } else { - RemoveLUTActiveTarget(this); + if (ApplyLUT(this, swapChain, rectVec->start, rectVec->end - rectVec->start)) { + AddLUTActiveTarget(this); + } else { + RemoveLUTActiveTarget(this); + } } } return COverlayContext_Present_orig(this, overlaySwapChain, a3, rectVec, a5, a6);