Last active
October 2, 2024 21:54
-
-
Save Byrom90/2787b598b1e52d6f970b0d07a6e38c21 to your computer and use it in GitHub Desktop.
Xbox 360 Dashboard D3D Render hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Rough setup that will draw a static rectangle over the top of the dashboard | |
// Toggle by pressing both thumbsticks | |
// Credit to the1domo for the basics here: https://www.unknowncheats.me/forum/xbox/179692-d3d-hook-xbox360.html | |
/* | |
// Function we can use to resolve the d3d display device | |
HRESULT XuiRenderGetDevice( | |
HXUIDC hDC, | |
IDirect3DDevice9 **ppDevice | |
) | |
*/ | |
void DrawFilledRect(IDirect3DDevice9* pDevice, float x0, float y0, float width, float height) { | |
//Byrom_Dbg("DrawFilledRect called!"); | |
D3DCOLOR rectColor = D3DCOLOR_RGBA(169, 169, 169, 180); //D3DCOLOR_XRGB(169, 169, 169); | |
D3DRECT BarRect = { x0, y0, x0 + width, y0 + height }; | |
pDevice->Clear(1, &BarRect, D3DCLEAR_TARGET | D3DCLEAR_TARGET, rectColor, 0, 0); | |
} | |
BOOL ButtonHeldPreviously = FALSE; // Prevents toggling the menu on each call due to the buttons still being held | |
BOOL ShowMenu = FALSE; // Determines whether or not to render the menu | |
void CustomRender(HXUIDC hDC) { | |
if (hDC) { | |
XINPUT_STATE xstate; | |
if (XInputGetState(0, &xstate) == ERROR_SUCCESS) { | |
if (xstate.Gamepad.wButtons == (XINPUT_GAMEPAD_LEFT_THUMB | XINPUT_GAMEPAD_RIGHT_THUMB)) { | |
//Byrom_Dbg("CustomRender button combo pressed!"); | |
if (!ButtonHeldPreviously) | |
{ | |
ButtonHeldPreviously = TRUE; // Ensures this will only run again after the buttons have been released | |
ShowMenu = !ShowMenu; // Toggle the menu | |
} | |
} | |
else | |
ButtonHeldPreviously = FALSE; // Next call will alow toggling the menu again | |
} | |
if (ShowMenu) | |
{ | |
IDirect3DDevice9* pDevice; | |
XuiRenderGetDevice(hDC, &pDevice); // Resolve the d3d device. Prob better to do this once and store the result | |
if (pDevice) | |
{ | |
//Byrom_Dbg("D3D device found!"); | |
DrawFilledRect(pDevice, 60, 60, 500, 500); | |
} | |
} | |
} | |
} | |
#define Dash_XuiRenderEnd 0x9221CD28 // dash.xex 17559 | |
Detour XuiRenderEndDetour; | |
HRESULT XuiRenderEndHook(HXUIDC hDC) | |
{ | |
auto Original = XuiRenderEndDetour.GetOriginal<decltype(&XuiRenderEndHook)>(); | |
//Byrom_Dbg("XuiRenderEndHook called!"); | |
CustomRender(hDC); // Do any extra stuff here | |
HRESULT Result = Original(hDC); | |
return Result; | |
} | |
void HookRender() | |
{ | |
Byrom_Dbg("Applying XuiRenderEnd hook at %08X", Dash_XuiRenderEnd); | |
XuiRenderEndDetour = Detour::Detour((void*)Dash_XuiRenderEnd, XuiRenderEndHook); | |
XuiRenderEndDetour.Install(); | |
} | |
void UnhookRender() | |
{ | |
Byrom_Dbg("Unhooking XuiRenderEnd"); | |
XuiRenderEndDetour.Remove(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment