@@ -46,6 +46,7 @@ std::unique_ptr<Hook> directx_device9_endscene_hook{nullptr};
4646std::unique_ptr<Hook> directx_device9_reset_hook{nullptr };
4747std::unique_ptr<Hook> directx_device11_swapchain_present_hook{nullptr };
4848
49+ IDirect3DTexture9* debug_texture = nullptr ;
4950IDirect3DDevice9* current_dx_device = nullptr ;
5051void HookD3D9Device (IDirect3DDevice9* pDevice, bool force = false ) noexcept ;
5152
@@ -1015,28 +1016,30 @@ HRESULT __stdcall D3D9Device_EndScene(IDirect3DDevice9* device) noexcept
10151016 D3DVIEWPORT9 viewport;
10161017 if (SUCCEEDED (device->GetViewport (&viewport)))
10171018 {
1019+ std::int32_t x = 0 ;
1020+ std::int32_t y = 0 ;
10181021 std::int32_t width = static_cast <std::int32_t >(viewport.Width );
10191022 std::int32_t height = static_cast <std::int32_t >(viewport.Height );
10201023
1021- std::int32_t x = 0 ;
1022- std::int32_t y = 0 ;
1024+ std::int32_t applet_x = 0 ;
1025+ std::int32_t applet_y = 0 ;
10231026 std::size_t applet_width = 0 ;
10241027 std::size_t applet_height = 0 ;
10251028
1026- control_center->get_applet_dimensions (&x, &y, &applet_width, &applet_height);
1027- control_center->set_target_dimensions (static_cast <std::int32_t >(applet_width), static_cast <std::int32_t >(applet_height));
1029+ control_center->get_applet_dimensions (&applet_x, &applet_y, &applet_width, &applet_height);
10281030
1029- /* if (width != applet_width || height != applet_height)
1030- {
1031- // Possibly menu open, render normally
1032- return directx_device9_endscene_hook->call<HRESULT, decltype(D3D9Device_EndScene)>(device);
1033- }*/
1034-
1035- control_center->set_target_dimensions (static_cast <std::int32_t >(width), static_cast <std::int32_t >(height));
1031+ // Terrible. RuneLite's UI flickers with icons because it draws like trash
1032+ // So we need to feed the client the Applet's Width/Height and not the Viewport's Width/Height
1033+ // Even though the ViewPort is what's being drawn on. RL draws outside that.
1034+ control_center->set_target_dimensions (applet_width, applet_height);
10361035
10371036 bool minimized = false ;
10381037 ImageFormat image_format = control_center->get_image_format ();
1039- dx_read_pixels (device, control_center->get_image (), width, height, minimized, image_format);
1038+
1039+ if (width <= applet_width && height == applet_height)
1040+ {
1041+ dx_read_pixels (device, control_center->get_image (), width, height, minimized, image_format);
1042+ }
10401043
10411044 IDirect3DStateBlock9* block;
10421045 device->CreateStateBlock (D3DSBT_ALL, &block);
@@ -1046,19 +1049,21 @@ HRESULT __stdcall D3D9Device_EndScene(IDirect3DDevice9* device) noexcept
10461049 device->SetRenderState (D3DRS_FOGENABLE, FALSE );
10471050 device->SetRenderState (D3DRS_ZENABLE, D3DZB_FALSE);
10481051 device->SetRenderState (D3DRS_CULLMODE, D3DCULL_NONE);
1049- device->SetRenderState (D3DRS_ALPHABLENDENABLE, TRUE ); // DISABLED
1052+ device->SetRenderState (D3DRS_ALPHABLENDENABLE, TRUE );
10501053 device->SetRenderState (D3DRS_BLENDOP, D3DBLENDOP_ADD);
10511054 device->SetRenderState (D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
10521055 device->SetRenderState (D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
10531056
1054- if (control_center-> get_debug_graphics () && !minimized )
1057+ if (width <= applet_width && height == applet_height )
10551058 {
1056- static IDirect3DTexture9* texture = nullptr ;
1057- dx_load_texture (device, texture, image_format, control_center->get_debug_image (), width, height);
1058-
1059- if (texture)
1059+ if (control_center->get_debug_graphics () && !minimized)
10601060 {
1061- dx_draw_texture (device, texture, image_format, 0.0 , 0.0 , static_cast <float >(width), static_cast <float >(height));
1061+ dx_load_texture (device, debug_texture, image_format, control_center->get_debug_image (), width, height);
1062+
1063+ if (debug_texture)
1064+ {
1065+ dx_draw_texture (device, debug_texture, image_format, 0.0 , 0.0 , static_cast <float >(width), static_cast <float >(height));
1066+ }
10621067 }
10631068 }
10641069
@@ -1120,6 +1125,12 @@ void HookD3D9Device(IDirect3DDevice9* pDevice, bool force) noexcept
11201125 current_dx_device = pDevice;
11211126 auto * vTable = *reinterpret_cast <DWORD_PTR**>(pDevice);
11221127
1128+ // Release the debug texture
1129+ if (debug_texture)
1130+ {
1131+ debug_texture->Release ();
1132+ }
1133+
11231134 // Hook EndScene
11241135 auto * endscene = reinterpret_cast <decltype (D3D9Device_EndScene)*>(vTable[42 ]);
11251136 directx_device9_endscene_hook = std::make_unique<Hook>(reinterpret_cast <void *>(endscene), reinterpret_cast <void *>(D3D9Device_EndScene));
@@ -1130,6 +1141,7 @@ void HookD3D9Device(IDirect3DDevice9* pDevice, bool force) noexcept
11301141 directx_device9_reset_hook = std::make_unique<Hook>(reinterpret_cast <void *>(reset), reinterpret_cast <void *>(D3D9Device_Reset));
11311142 directx_device9_reset_hook->apply ();
11321143
1144+ // Validate that functions were actually hooked
11331145 if (!directx_device9_endscene_hook->is_enabled ())
11341146 {
11351147 current_dx_device = nullptr ;
0 commit comments