├── .gitignore ├── LICENSE ├── README.md ├── img └── menu-tutorial.png └── src ├── draw.cpp ├── draw.h ├── input.cpp ├── input.h ├── inst4kill.cpp ├── menu.cpp ├── menu.h ├── tools.cpp └── tools.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 andretharada 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # inst4kill-d3d-menu 2 | Simple menu with C++ and D3D9 3 | 4 | ![menu-tutorial](https://github.com/andretharada/inst4kill-d3d-menu/blob/master/img/menu-tutorial.png) 5 | 6 | # Navigation 7 | 8 | ## General 9 | * Mouse: move menu, scroll items and change values 10 | * Arrows: navigate and change values 11 | 12 | ## Shortcuts 13 | * Tabs and items 14 | * Shift + ↑: go to the first item 15 | * Shift + ↓: go to the last item 16 | * Shift + ←: previous tab 17 | * Shift + →: next tab 18 | * Menu color 19 | * Ctrl + ←: previous menu color 20 | * Ctrl + →: next menu color 21 | -------------------------------------------------------------------------------- /img/menu-tutorial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andretharada/inst4kill-d3d-menu/95925d69e612090f4650417ae8f77a701ab081cb/img/menu-tutorial.png -------------------------------------------------------------------------------- /src/draw.cpp: -------------------------------------------------------------------------------- 1 | #include "draw.h" 2 | 3 | Draw draw; 4 | 5 | int Draw::TextWidth(string Text) 6 | { 7 | RECT rect = {0, 0, 0, 0}; 8 | draw.font->DrawText(NULL, Text.c_str(), -1, &rect, DT_CALCRECT, NULL); 9 | return rect.right - rect.left; 10 | } 11 | 12 | void Draw::Text(int x, int y, string text, D3DCOLOR color, bool isBordered, TextAlignment eAlignment) 13 | { 14 | RECT rect; 15 | 16 | if (isBordered) 17 | { 18 | struct ShadowStruct { int x; int y; }; 19 | ShadowStruct shadowOffset[] = {{-1, 0}, {+1, 0}, {0, -1}, {0, +1}}; 20 | 21 | for (int i = 0; i < GetSizeOf(shadowOffset); i++) 22 | { 23 | SetRect(&rect, x + shadowOffset[i].x, y + shadowOffset[i].y, x + shadowOffset[i].x, y + shadowOffset[i].y); 24 | this->font->DrawTextA(NULL, text.c_str(), -1, &rect, eAlignment | DT_NOCLIP, BlackColor(100)); 25 | } 26 | } 27 | else 28 | { 29 | SetRect(&rect, x + 1, y + 1, x + 1, y + 1); 30 | this->font->DrawTextA(NULL, text.c_str(), -1, &rect, eAlignment | DT_NOCLIP, BlackColor(50)); 31 | } 32 | 33 | SetRect(&rect, x, y, x, y); 34 | this->font->DrawTextA(NULL, text.c_str(), -1, &rect, eAlignment | DT_NOCLIP, color); 35 | } 36 | 37 | void Draw::Line(float x, float y, float x2, float y2, D3DCOLOR color) 38 | { 39 | Vertex v[2] = 40 | { 41 | {x, y, 0.0f, 1.0f, color}, 42 | {x2, y2, 0.0f, 1.0f, color}, 43 | }; 44 | this->device->DrawPrimitiveUP(D3DPT_LINELIST, 1, v, sizeof(Vertex)); 45 | } 46 | 47 | void Draw::Border(float x, float y, float w, float h, D3DCOLOR color) 48 | { 49 | Vertex vertices[6] = 50 | { 51 | x + w, y, 0.0f, 1.0f, color, 0.0f, 0.0f, 52 | x + w, y + h, 0.0f, 1.0f, color, 0.0f, 0.0f, 53 | x, y + h, 0.0f, 1.0f, color, 0.0f, 0.0f, 54 | 55 | x, y + h, 0.0f, 1.0f, color, 0.0f, 0.0f, 56 | x, y, 0.0f, 1.0f, color, 0.0f, 0.0f, 57 | x + w, y, 0.0f, 1.0f, color, 0.0f, 0.0f, 58 | }; 59 | 60 | this->device->DrawPrimitiveUP(D3DPT_LINESTRIP, 5, vertices, sizeof(Vertex)); 61 | } 62 | 63 | void Draw::Rectangle(float x, float y, float w, float h, D3DCOLOR startColor, D3DCOLOR endColor, D3DCOLOR borderColor) 64 | { 65 | if (endColor == NULL) 66 | endColor = startColor; 67 | 68 | Vertex vertices[4] = 69 | { 70 | x, y, 0.0f, 1.0f, startColor, 0.0f, 0.0f, 71 | x + w, y, 0.0f, 1.0f, startColor, 1.0f, 0.0f, 72 | 73 | x + w, y + h, 0.0f, 1.0f, endColor, 1.0f, 1.0f, 74 | x, y + h, 0.0f, 1.0f, endColor, 0.0f, 1.0f, 75 | }; 76 | 77 | this->device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, vertices, sizeof(Vertex)); 78 | 79 | if (borderColor != NULL) 80 | Border(x - 1, y - 1, w + 1, h + 1, borderColor); 81 | } -------------------------------------------------------------------------------- /src/draw.h: -------------------------------------------------------------------------------- 1 | #ifndef __DRAW_H__ 2 | #define __DRAW_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include "tools.h" 8 | 9 | #pragma comment(lib, "d3d9.lib") 10 | #pragma comment(lib, "d3dx9.lib") 11 | 12 | using namespace std; 13 | 14 | enum TextAlignment { kLeft, kCenter, kRight }; 15 | 16 | class Draw 17 | { 18 | public: 19 | Draw() 20 | { 21 | isInitialized = false; 22 | } 23 | 24 | LPD3DXFONT font; 25 | D3DVIEWPORT9 viewport; 26 | 27 | void Init() { this->isInitialized = true; } 28 | bool IsInitialized() { return this->isInitialized; } 29 | 30 | int TextWidth(string text); 31 | void Text(int x, int y, string text, D3DCOLOR color, bool isBordered = false, TextAlignment eAlignment = TextAlignment::kLeft); 32 | void Line(float x, float y, float x2, float y2, D3DCOLOR color); 33 | void Border(float x, float y, float w, float h, D3DCOLOR color); 34 | void Rectangle(float x, float y, float w, float h, D3DCOLOR startColor, D3DCOLOR endColor = NULL, D3DCOLOR borderColor = NULL); 35 | 36 | unsigned int GetScreenWidth() { return this->viewport.Width; } 37 | unsigned int GetScreenHeight() { return this->viewport.Height; } 38 | 39 | LPDIRECT3DDEVICE9 GetDevice() { return this->device; } 40 | void SetDevice(LPDIRECT3DDEVICE9 device) { this->device = device; } 41 | private: 42 | struct Vertex 43 | { 44 | float x, y, z, h; 45 | D3DCOLOR color; 46 | float tu, tv; 47 | static DWORD FVF; 48 | }; 49 | 50 | bool isInitialized; 51 | LPDIRECT3DDEVICE9 device; 52 | }; 53 | 54 | #define opacity(v) (255 * v) / 100 55 | 56 | #define RedColor(a) D3DCOLOR_ARGB(opacity(a), 255, 0, 0) 57 | #define GreenColor(a) D3DCOLOR_ARGB(opacity(a), 0, 255, 0) 58 | #define BlueColor(a) D3DCOLOR_ARGB(opacity(a), 0, 0, 255) 59 | #define YellowColor(a) D3DCOLOR_ARGB(opacity(a), 255, 255, 0) 60 | #define OrangeColor(a) D3DCOLOR_ARGB(opacity(a), 255, 125, 0) 61 | #define WhiteColor(a) D3DCOLOR_ARGB(opacity(a), 255, 255, 255) 62 | #define BlackColor(a) D3DCOLOR_ARGB(opacity(a), 0, 0, 0) 63 | 64 | extern Draw draw; 65 | 66 | #endif //__DRAW_H__ -------------------------------------------------------------------------------- /src/input.cpp: -------------------------------------------------------------------------------- 1 | #include "input.h" 2 | 3 | Input input; 4 | 5 | void Input::Init() 6 | { 7 | if (SUCCEEDED(DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&lpDIObject, NULL))) 8 | { 9 | this->lpDIObject->CreateDevice(GUID_SysMouse, &lpDIMouseDevice, NULL); 10 | this->lpDIMouseDevice->SetDataFormat(&c_dfDIMouse2); 11 | this->lpDIMouseDevice->SetCooperativeLevel(GetActiveWindow(), DISCL_BACKGROUND | DISCL_NONEXCLUSIVE); 12 | this->lpDIMouseDevice->Acquire(); 13 | } 14 | } 15 | 16 | void Input::Update() 17 | { 18 | if (lpDIMouseDevice->GetDeviceState(sizeof(DIMOUSESTATE2), &MouseState) == DIERR_INPUTLOST) 19 | { 20 | this->lpDIMouseDevice->Acquire(); 21 | } 22 | } -------------------------------------------------------------------------------- /src/input.h: -------------------------------------------------------------------------------- 1 | #ifndef __INPUT_H__ 2 | #define __INPUT_H__ 3 | 4 | #define DIRECTINPUT_VERSION 0x800 5 | 6 | #include 7 | #include 8 | 9 | #pragma comment(lib, "dinput8.lib") 10 | #pragma comment(lib, "dxguid.lib") 11 | 12 | class Input 13 | { 14 | public: 15 | void Init(); 16 | void Update(); 17 | 18 | bool IsKeyUp(int key) { return !(MouseState.rgbButtons[key] &0x80); } 19 | bool IsKeyDown(int key) { return (MouseState.rgbButtons[key] &0x80); } 20 | bool IsScrollUp() { return MouseState.lZ > 0; } 21 | bool IsScrollDown() { return MouseState.lZ < 0; } 22 | 23 | private: 24 | LPDIRECTINPUTDEVICE8 lpDIMouseDevice; 25 | LPDIRECTINPUT8 lpDIObject; 26 | 27 | DIMOUSESTATE2 MouseState; 28 | }; 29 | 30 | extern Input input; 31 | 32 | #endif //__INPUT_H__ -------------------------------------------------------------------------------- /src/inst4kill.cpp: -------------------------------------------------------------------------------- 1 | #define WIN32_LEAN_AND_MEAN 2 | #define VC_EXTRA_LEAN 3 | 4 | #include "draw.h" 5 | #include "input.h" 6 | #include "menu.h" 7 | #include "tools.h" 8 | 9 | DWORD* FindVTable(); 10 | 11 | string onOff[] = { "Off", "On" }; 12 | string aimBone[] = { "Torso", "Upper Torso", "Head", "Neck", "Nuts" }; 13 | string aimAngle[] = { "360", "180", "90", "45", "30", "15" }; 14 | string multiplier[] = { "Off", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10" }; 15 | string aimTime[] = { "Instant", "100ms", "200ms", "300ms", "400ms", "500ms", "600ms", "700ms", "800ms", "900ms", "1000ms" }; 16 | string keys[] = { "LClick", "MClick", "RClick", "Alt", "Ctrl", "Shift" }; 17 | 18 | string moduleList[] = { "d3d9.dll" }; 19 | 20 | void InitializeMenu() 21 | { 22 | menu.Header("inst4kill - Premium"); 23 | 24 | menu.AddTab("Visual"); 25 | menu.AddItem("Chams", onOff); 26 | menu.AddItem("No Fog", onOff); 27 | menu.AddItem("Crosshair", onOff); 28 | menu.AddItem("Name ESP", onOff); 29 | menu.AddItem("Box ESP", onOff); 30 | menu.AddItem("Line ESP", onOff); 31 | menu.AddItem("Distance ESP", onOff); 32 | menu.AddItem("Health ESP", onOff); 33 | menu.AddItem("Skeleton ESP", onOff); 34 | menu.AddItem("Explosive ESP", onOff); 35 | menu.AddItem("Pickup ESP", onOff); 36 | menu.AddItem("All Players", onOff); 37 | 38 | menu.AddTab("Aimbot"); 39 | menu.AddItem("Aimbot", onOff); 40 | menu.AddItem("Aim Key", keys, 6); 41 | menu.AddItem("Aim Bone", aimBone, 5); 42 | menu.AddItem("Auto Switch", onOff); 43 | menu.AddItem("Aim Angle", aimAngle, 6); 44 | menu.AddItem("Smooth Aim", aimTime, 11); 45 | menu.AddItem("Aim Thru Walls", onOff); 46 | menu.AddItem("Friendly Fire", onOff); 47 | menu.AddItem("Off After Kill", onOff); 48 | 49 | menu.AddTab("Stats"); 50 | menu.AddItem("Recoil Control", multiplier, 11); 51 | menu.AddItem("Spread Control", multiplier, 11); 52 | menu.AddItem("Rapid Fire", onOff); 53 | menu.AddItem("Far Pickup", onOff); 54 | menu.AddItem("Fly Mode", onOff); 55 | menu.AddItem("Super Speed", multiplier, 11); 56 | menu.AddItem("Super Jump", multiplier, 11); 57 | 58 | menu.AddTab("Misc"); 59 | menu.AddItem("Super Pickup", onOff); 60 | menu.AddItem("Free Run", onOff); 61 | menu.AddItem("Head Glitch", onOff); 62 | menu.AddItem("Chat Spam", onOff); 63 | menu.AddItem("Voice Spam", onOff); 64 | menu.AddItem("Ghost Mode", onOff); 65 | menu.AddItem("Glitcher Mode", onOff); 66 | menu.AddItem("Tele Kill", onOff); 67 | } 68 | 69 | typedef HRESULT (WINAPI* oPresent)(LPDIRECT3DDEVICE9 pDevice, const RECT *pSourceRect, const RECT *pDestRect, HWND hDestWindowOverride, const RGNDATA *pDirtyRegion); 70 | oPresent pPresent; 71 | 72 | HRESULT WINAPI hkPresent(LPDIRECT3DDEVICE9 pDevice, const RECT* pSourceRect, const RECT* pDestRect, HWND hDestWindowOverride, const RGNDATA* pDirtyRegion) 73 | { 74 | if (!draw.IsInitialized()) 75 | { 76 | draw.SetDevice(pDevice); 77 | D3DXCreateFontA(draw.GetDevice(), 16, 0, FW_NORMAL, 1, 0, DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS, CLEARTYPE_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Calibri", &draw.font); 78 | 79 | input.Init(); 80 | draw.Init(); 81 | } 82 | 83 | draw.GetDevice()->GetViewport(&draw.viewport); 84 | 85 | draw.GetDevice()->SetTexture(NULL, NULL); 86 | draw.GetDevice()->SetRenderState(D3DRS_ALPHABLENDENABLE, D3DZB_TRUE); 87 | draw.GetDevice()->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); 88 | draw.GetDevice()->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1); 89 | 90 | input.Update(); 91 | menu.Render(); 92 | 93 | draw.GetDevice()->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); 94 | 95 | return pPresent(pDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion); 96 | } 97 | 98 | DWORD CALLBACK MainThread(LPVOID lpArgs) 99 | { 100 | while (!tools.IsReadyForHook(moduleList, GetSizeOf(moduleList))) 101 | Sleep(25); 102 | 103 | InitializeMenu(); 104 | 105 | DWORD* pVTable = FindVTable(); 106 | pPresent = (oPresent)tools.DetourFunction((PBYTE)pVTable[17], (PBYTE)&hkPresent, 5); 107 | 108 | return EXIT_SUCCESS; 109 | } 110 | 111 | BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved) 112 | { 113 | if (dwReason == DLL_PROCESS_ATTACH) 114 | { 115 | CreateThread(0, 0, (LPTHREAD_START_ROUTINE)MainThread, 0, 0, 0); 116 | } 117 | return TRUE; 118 | } 119 | 120 | static LRESULT CALLBACK MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 121 | { 122 | return DefWindowProc(hWnd, uMsg, wParam, lParam); 123 | } 124 | 125 | DWORD* FindVTable() 126 | { 127 | WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, "DX", NULL}; 128 | RegisterClassEx(&wc); 129 | HWND hWnd = CreateWindowA("DX", NULL, WS_OVERLAPPEDWINDOW, 100, 100, 300, 300, GetDesktopWindow(), NULL, wc.hInstance, NULL); 130 | 131 | LPDIRECT3D9 pD3D = Direct3DCreate9(D3D_SDK_VERSION); 132 | 133 | D3DPRESENT_PARAMETERS presentParameters; 134 | ZeroMemory(&presentParameters, sizeof(presentParameters)); 135 | presentParameters.Windowed = TRUE; 136 | presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD; 137 | presentParameters.BackBufferFormat = D3DFMT_UNKNOWN; 138 | 139 | LPDIRECT3DDEVICE9 pDevice; 140 | pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentParameters, &pDevice); 141 | 142 | DWORD* pVTable = (DWORD*)pDevice; 143 | pVTable = (DWORD*)pVTable[0]; 144 | DestroyWindow(hWnd); 145 | return pVTable; 146 | } -------------------------------------------------------------------------------- /src/menu.cpp: -------------------------------------------------------------------------------- 1 | #include "menu.h" 2 | 3 | Menu menu; 4 | 5 | #define StartColor D3DCOLOR_ARGB(255, 33, 33, 33) 6 | #define EndColor D3DCOLOR_ARGB(255, 20, 20, 20) 7 | #define BorderColor D3DCOLOR_ARGB(255, 0, 0, 0) 8 | #define SelectionColor D3DCOLOR_ARGB(255, 13, 13, 13) 9 | #define OffColor D3DCOLOR_ARGB(255, 135, 135, 135) 10 | #define ColorOffset D3DCOLOR_ARGB(0, 25, 25, 25) 11 | 12 | Menu::Menu() 13 | { 14 | // menu 15 | this->menuInfo.x = 50; // posição x do menu 16 | this->menuInfo.y = 150; // posição y do menu 17 | this->menuInfo.w = 300; // largura do menu 18 | this->menuInfo.isShown = true; // visibilidade do menu 19 | 20 | // item 21 | this->itemInfo.num = 0; // número de itens 22 | this->itemInfo.index = 0; // índice atual 23 | 24 | // tab 25 | this->tabInfo.num = 0; // número de abas 26 | this->tabInfo.index = 0; // aba atual 27 | 28 | // scroll 29 | this->scrollInfo.num = 7; // quantidade de itens exibidos 30 | this->scrollInfo.index = 0; // índice do scroll 31 | 32 | // color 33 | this->colorInfo.num = 0; // número de cores 34 | this->colorInfo.index = 0; // índice da cor 35 | } 36 | 37 | void Menu::AddTab(string name) 38 | { 39 | this->tabs[this->tabInfo.num].name = name; 40 | this->tabs[this->tabInfo.num].pos = itemInfo.num; 41 | this->tabInfo.num++; 42 | } 43 | 44 | void Menu::AddItem(string name, string* display, int max, int value) 45 | { 46 | this->items[this->itemInfo.num].name = name; 47 | this->items[this->itemInfo.num].display = display; 48 | this->items[this->itemInfo.num].max = max - 1; 49 | this->items[this->itemInfo.num].value = value; 50 | this->itemInfo.num++; 51 | } 52 | 53 | void Menu::Render() 54 | { 55 | if (GetAsyncKeyState(VK_INSERT) &1) 56 | this->menuInfo.isShown = !this->IsShown(); 57 | 58 | if (!this->IsShown()) 59 | return; 60 | 61 | // propriedades 62 | int x = this->menuInfo.x; // posição x 63 | int y = this->menuInfo.y; // posição y 64 | int w = this->menuInfo.w; // largura 65 | int h = (this->scrollInfo.num * 16) + 8; // altura 66 | 67 | // altura dividida pelo número de abas 68 | int tabHeight = h/this->tabInfo.num; 69 | // largura da aba representa 1/4 da largura total - equivalente a 25% 70 | int tabWidth = w/4; 71 | 72 | // retorna a posição do cursor de acordo com a janela 73 | GetCursorPos(&this->c.pos); 74 | ScreenToClient(GetActiveWindow(), &this->c.pos); 75 | 76 | // navegação 77 | this->MouseSetup(); 78 | this->MouseScrollNavigation(x + tabWidth + 5, y + 25, w - tabWidth - 20, (this->scrollInfo.num * 16)); 79 | this->KeyboardNavigation(); 80 | 81 | // mover pelo cabeçalho 82 | this->DragMenu(x, y, w, 20); 83 | 84 | // cabeçalho 85 | draw.Rectangle(x, y, w, 20, StartColor, EndColor, BorderColor); 86 | draw.Text(x + w/2, y + 2, this->menuInfo.title, OffColor, false, TextAlignment::kCenter); 87 | 88 | // preencher o menu de acordo com a largura das abas 89 | draw.Rectangle(x + tabWidth + 1, y + 21, w - tabWidth - 1, h, StartColor, EndColor, BorderColor); 90 | 91 | // rodapé 92 | draw.Rectangle(x, y + h + 22, w, 20, StartColor, EndColor, BorderColor); 93 | 94 | // componentes 95 | this->DrawSelection(x + tabWidth + 5, y + 20 + (this->itemInfo.index - this->scrollInfo.index) * 16 + 6, w - tabWidth - 20); 96 | this->DrawTabs(x, y + 21, tabWidth, tabHeight); 97 | this->DrawItems(x + tabWidth + 10, y + 20, w); 98 | this->DrawScrollBar(x + w - 10, y + 27, h - 15); 99 | 100 | // cores 101 | this->DrawColors(x, y, w, h + 28); 102 | 103 | //cursor 104 | draw.Rectangle(c.pos.x, c.pos.y, 10, 10, StartColor, EndColor, BorderColor); 105 | } 106 | 107 | void Menu::MouseSetup() 108 | { 109 | this->c.isLClicked = GetAsyncKeyState(VK_LBUTTON) &1 ? true : false; 110 | this->c.isRClicked = GetAsyncKeyState(VK_RBUTTON) &1 ? true : false; 111 | this->c.isHolding = GetAsyncKeyState(VK_LBUTTON) ? true : false; 112 | } 113 | 114 | void Menu::MouseScrollNavigation(float x, float y, float w, float h) 115 | { 116 | if (this->IsMouseOver(x, y, w, h)) 117 | { 118 | if (input.IsScrollUp() && this->scrollInfo.index > 0) 119 | { 120 | this->scrollInfo.index--; 121 | this->itemInfo.index--; 122 | } 123 | 124 | if (input.IsScrollDown() && this->scrollInfo.index < this->NumScrollItems()) 125 | { 126 | this->scrollInfo.index++; 127 | this->itemInfo.index++; 128 | } 129 | } 130 | } 131 | 132 | void Menu::KeyboardNavigation() 133 | { 134 | // fixar índice dos itens para alterar seu valor 135 | int index = this->FirstTabIndex() + this->itemInfo.index; 136 | 137 | if (GetAsyncKeyState(VK_UP) &1 && this->itemInfo.index > 0) 138 | { 139 | if (GetAsyncKeyState(VK_LSHIFT) < 0) 140 | { 141 | this->Update(); 142 | } 143 | else 144 | { 145 | if (this->itemInfo.index < this->scrollInfo.index + 1) 146 | this->scrollInfo.index--; 147 | 148 | this->itemInfo.index--; 149 | } 150 | } 151 | if (GetAsyncKeyState(VK_DOWN) &1 && this->itemInfo.index < this->NumTabItems() - 1) 152 | { 153 | if (GetAsyncKeyState(VK_LSHIFT) < 0) 154 | { 155 | this->itemInfo.index = this->NumTabItems() - 1; 156 | 157 | if (this->NumScrollItems() > 0) 158 | this->scrollInfo.index = this->NumScrollItems(); 159 | } 160 | else 161 | { 162 | if (this->itemInfo.index > this->scrollInfo.index + (this->scrollInfo.num - 2)) 163 | this->scrollInfo.index++; 164 | 165 | this->itemInfo.index++; 166 | } 167 | } 168 | if (GetAsyncKeyState(VK_LEFT) &1) 169 | { 170 | if (GetAsyncKeyState(VK_LSHIFT) < 0) 171 | { 172 | if (this->tabInfo.index > 0) 173 | { 174 | this->tabInfo.index--; 175 | Update(); 176 | } 177 | } 178 | else if (GetAsyncKeyState(VK_CONTROL) < 0) 179 | { 180 | if (this->colorInfo.index > 0) 181 | this->colorInfo.index--; 182 | } 183 | else 184 | { 185 | if (this->items[index].value > 0 && this->itemInfo.index >= 0 ) 186 | this->items[index].value--; 187 | } 188 | } 189 | if (GetAsyncKeyState(VK_RIGHT) &1) 190 | { 191 | if (GetAsyncKeyState(VK_LSHIFT) < 0) 192 | { 193 | if (this->tabInfo.index < this->tabInfo.num - 1) 194 | { 195 | this->tabInfo.index++; 196 | this->Update(); 197 | } 198 | } 199 | else if (GetAsyncKeyState(VK_CONTROL) < 0) 200 | { 201 | if (this->colorInfo.index < this->colorInfo.num - 1) 202 | this->colorInfo.index++; 203 | } 204 | else if (this->items[index].value < this->items[index].max && this->itemInfo.index >= 0) 205 | this->items[index].value++; 206 | } 207 | } 208 | 209 | void Menu::DrawSelection(int x, int y, int w) 210 | { 211 | if (this->itemInfo.index >= 0) 212 | { 213 | draw.Rectangle(x, y, w, 14, D3DCOLOR_ARGB(255, 4, 4, 4)); 214 | draw.Rectangle(x + 1, y + 1, w - 1, 13, SelectionColor); 215 | } 216 | } 217 | 218 | void Menu::DrawTabs(int x, int y, int w, int h) 219 | { 220 | for (int i = 0; i < this->tabInfo.num; i++) 221 | { 222 | D3DCOLOR color = this->tabInfo.index == i ? this->menuInfo.color : OffColor; 223 | 224 | if (this->tabInfo.index == i) 225 | draw.Rectangle(x, y + i * h, w, h, EndColor, StartColor, BorderColor); 226 | else 227 | draw.Rectangle(x, y + i * h, w, h, StartColor, EndColor, BorderColor); 228 | 229 | if (this->IsMouseOver(x, y + (i * h), w, h) && this->tabInfo.index != i) 230 | { 231 | // highlight 232 | color += ColorOffset; 233 | 234 | if (this->IsLClicked()) 235 | { 236 | this->tabInfo.index = i; 237 | this->Update(); 238 | } 239 | } 240 | // centralizar horizontalmente x + w/2 241 | // posicionar verticalmente de acordo com o índice o altura (i * h) 242 | // centralizar verticalmente com o centro da aba (h/2) 243 | // subtrair o a posição do topo do texto -8 244 | draw.Text(x + w/2, y + (i * h) + (h/2) - 8, this->tabs[i].name, color, false, TextAlignment::kCenter); 245 | } 246 | } 247 | 248 | void Menu::MouseNavigation(int itemIndex) 249 | { 250 | if (this->IsLClicked()) 251 | { 252 | if (this->items[itemIndex].value < this->items[itemIndex].max) 253 | this->items[itemIndex].value++; 254 | else 255 | this->items[itemIndex].value = 0; 256 | } 257 | 258 | if (this->IsRClicked()) 259 | { 260 | if (this->items[itemIndex].value > 0) 261 | this->items[itemIndex].value--; 262 | else 263 | this->items[itemIndex].value = this->items[itemIndex].max; 264 | } 265 | } 266 | 267 | void Menu::DrawItems(int x, int y, int w) 268 | { 269 | int itemOffset = y; 270 | 271 | for (int i = this->FirstScrollIndex(); i <= this->LastScrollIndex(); i++) 272 | { 273 | D3DCOLOR color = this->items[i].value > 0 ? this->menuInfo.color : OffColor; 274 | 275 | // nome da função 276 | draw.Text(x, itemOffset + 5, this->items[i].name.c_str(), color); 277 | 278 | // lista de opções 279 | draw.Text(x + w - w/4 - 30, itemOffset + 5, this->items[i].display[this->items[i].value], color, false, TextAlignment::kRight); 280 | 281 | if (this->IsMouseOver(x - 5, itemOffset + 5, w - w/4 - 20, 16)) 282 | { 283 | this->itemInfo.index = i - this->FirstScrollIndex() + this->scrollInfo.index; 284 | this->MouseNavigation(i); 285 | } 286 | // espaçamento de 16px para cada item no menu 287 | itemOffset += 16; 288 | } 289 | } 290 | 291 | void Menu::DrawColors(int x, int y, int w, int h) 292 | { 293 | D3DCOLOR colors[] = 294 | { 295 | D3DCOLOR_ARGB(255, 255, 0, 70), // vermelho 296 | D3DCOLOR_ARGB(255, 0, 120, 210), // azul 297 | D3DCOLOR_ARGB(255, 0, 210, 70), // verde água 298 | D3DCOLOR_ARGB(255, 255, 240, 0), // amarelo 299 | D3DCOLOR_ARGB(255, 255, 120, 0), // laranja 300 | }; 301 | 302 | this->colorInfo.num = GetSizeOf(colors); 303 | 304 | // posicão x inicial relativo à largura total de todas as cores 305 | x += w - (this->colorInfo.num * 15); // crescente 306 | 307 | for (int i = 0; i < this->colorInfo.num; i++) 308 | { 309 | if (this->colorInfo.index == i) 310 | { 311 | draw.Rectangle(x + (i * 15) - 1, y + h - 1, 10, 10, colors[i], NULL, BorderColor); 312 | } 313 | else 314 | { 315 | if (this->IsMouseOver(x + (i * 15) - 1, y + h - 1, 10, 10)) 316 | { 317 | if (this->IsLClicked()) 318 | this->colorInfo.index = i; 319 | 320 | draw.Rectangle(x + (i * 15) - 1, y + h - 1, 10, 10, colors[i], NULL, SelectionColor); 321 | } 322 | else 323 | draw.Rectangle(x + (i * 15), y + h, 8, 8, colors[i]); 324 | } 325 | this->menuInfo.color = colors[this->colorInfo.index]; 326 | } 327 | } 328 | 329 | void Menu::DrawScrollBar(int x, int y, int h) 330 | { 331 | // base do scroll 332 | draw.Rectangle(x, y, 1, h, BorderColor, NULL, BorderColor); 333 | 334 | // percentual de preenchimento de acordo com a quantidade de itens 335 | float fillPercentage = min((this->scrollInfo.num * 100)/this->NumTabItems(), 100); 336 | 337 | // tamanho do scroll é relativo ao percentual de preenchimento 338 | float scrollHeight = (fillPercentage * h)/100; 339 | 340 | // offset de acordo com o tamanho do scroll 341 | int scrollOffset = this->HasScroll() ? ((h - scrollHeight)/this->NumScrollItems()) : 0; 342 | 343 | // posição de acordo com o índice do scroll 344 | int indexOffset = this->scrollInfo.index * scrollOffset; 345 | 346 | // preencher de acordo com o índice e posição do scroll 347 | draw.Rectangle(x, y, 1, indexOffset - 1, StartColor, NULL, BorderColor); 348 | 349 | // desenhar scroll 350 | draw.Rectangle(x - 2, y + indexOffset, 6, scrollHeight, StartColor, EndColor, BorderColor); 351 | } 352 | 353 | void Menu::DragMenu(int x, int y, int w, int h) 354 | { 355 | if (!this->IsHolding()) 356 | this->menuInfo.isDragging = false; 357 | 358 | if (this->menuInfo.isDragging) { 359 | this->menuInfo.x = this->c.pos.x - this->c.offset.x; 360 | this->menuInfo.y = this->c.pos.y - this->c.offset.y; 361 | } 362 | 363 | if (this->IsMouseOver(x, y, w, h)) { 364 | this->c.offset.x = this->c.pos.x - this->menuInfo.x; 365 | this->c.offset.y = this->c.pos.y - this->menuInfo.y; 366 | this->menuInfo.isDragging = true; 367 | } 368 | } 369 | -------------------------------------------------------------------------------- /src/menu.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andretharada/inst4kill-d3d-menu/95925d69e612090f4650417ae8f77a701ab081cb/src/menu.h -------------------------------------------------------------------------------- /src/tools.cpp: -------------------------------------------------------------------------------- 1 | #include "tools.h" 2 | 3 | Tools tools; 4 | 5 | bool Tools::IsReadyForHook(string* moduleList, int numModules) 6 | { 7 | for (int moduleIndex = 0; moduleIndex < numModules; moduleIndex++) 8 | { 9 | if (GetModuleHandle(moduleList[moduleIndex].c_str()) != NULL) 10 | { 11 | if (moduleIndex == numModules - 1) 12 | return true; 13 | } 14 | else 15 | return false; 16 | } 17 | 18 | return false; 19 | } 20 | 21 | void* Tools::DetourFunction(PBYTE src, const PBYTE dst, const int len) 22 | { 23 | BYTE* jmp = (BYTE*)malloc(len + 5); 24 | DWORD dwBack; 25 | VirtualProtect(src, len, PAGE_EXECUTE_READWRITE, &dwBack); 26 | memcpy(jmp, src, len); 27 | jmp += len; 28 | jmp[0] = 0xE9; 29 | *(DWORD*)(jmp + 1) = (DWORD)(src + len - jmp) - 5; 30 | memset(src, 0x90, len); 31 | src[0] = 0xE9; 32 | *(DWORD*)(src + 1) = (DWORD)(dst - src) - 5; 33 | for (int i = 5; i < len; i++) 34 | src[i] = 0x90; 35 | VirtualProtect(src, len, dwBack, &dwBack); 36 | FlushInstructionCache(GetCurrentProcess, src, len); // 37 | return (jmp - len); 38 | } 39 | 40 | void Tools::HideModule(HINSTANCE hModule) 41 | { 42 | DWORD dwPEB_LDR_DATA = 0; 43 | _asm 44 | { 45 | pushad; 46 | pushfd; 47 | mov eax, fs:[30h]; 48 | mov eax, [eax+0Ch]; 49 | mov dwPEB_LDR_DATA, eax; 50 | mov esi, [eax+0Ch]; 51 | mov edx, [eax+10h]; 52 | LoopInLoadOrderModuleList: 53 | lodsd; 54 | mov esi, eax; 55 | mov ecx, [eax+18h]; 56 | cmp ecx, hModule; 57 | jne SkipA 58 | mov ebx, [eax] 59 | mov ecx, [eax+4] 60 | mov [ecx], ebx 61 | mov [ebx+4], ecx 62 | jmp InMemoryOrderModuleList 63 | SkipA: 64 | cmp edx, esi 65 | jne LoopInLoadOrderModuleList 66 | InMemoryOrderModuleList: 67 | mov eax, dwPEB_LDR_DATA 68 | mov esi, [eax+14h] 69 | mov edx, [eax+18h] 70 | LoopInMemoryOrderModuleList: 71 | lodsd 72 | mov esi, eax 73 | mov ecx, [eax+10h] 74 | cmp ecx, hModule 75 | jne SkipB 76 | mov ebx, [eax] 77 | mov ecx, [eax+4] 78 | mov [ecx], ebx 79 | mov [ebx+4], ecx 80 | jmp InInitializationOrderModuleList 81 | SkipB: 82 | cmp edx, esi 83 | jne LoopInMemoryOrderModuleList 84 | InInitializationOrderModuleList: 85 | mov eax, dwPEB_LDR_DATA 86 | mov esi, [eax+1Ch] 87 | mov edx, [eax+20h] 88 | LoopInInitializationOrderModuleList: 89 | lodsd 90 | mov esi, eax 91 | mov ecx, [eax+08h] 92 | cmp ecx, hModule 93 | jne SkipC 94 | mov ebx, [eax] 95 | mov ecx, [eax+4] 96 | mov [ecx], ebx 97 | mov [ebx+4], ecx 98 | jmp Finished 99 | SkipC: 100 | cmp edx, esi 101 | jne LoopInInitializationOrderModuleList 102 | Finished: 103 | popfd; 104 | popad; 105 | } 106 | } 107 | 108 | void Tools::EraseHeader(HINSTANCE hModule) 109 | { 110 | if (!hModule) 111 | return; 112 | 113 | DWORD size, protect; 114 | PIMAGE_DOS_HEADER pDoH = (PIMAGE_DOS_HEADER)(hModule); 115 | PIMAGE_NT_HEADERS pNtH = (PIMAGE_NT_HEADERS)((LONG)hModule + ((PIMAGE_DOS_HEADER)hModule)->e_lfanew); 116 | 117 | size = sizeof(IMAGE_DOS_HEADER); 118 | if (VirtualProtect(pDoH, size, PAGE_READWRITE, &protect)) 119 | for (DWORD i = 0; i < size; i++) 120 | *(BYTE*)((BYTE*)pDoH + i) = 0; 121 | 122 | size = sizeof(IMAGE_NT_HEADERS); 123 | if (pNtH && VirtualProtect(pNtH, size, PAGE_READWRITE, &protect)) 124 | for (DWORD i = 0; i < size; i++) 125 | *(BYTE*)((BYTE*)pNtH + i) = 0; 126 | 127 | return; 128 | } -------------------------------------------------------------------------------- /src/tools.h: -------------------------------------------------------------------------------- 1 | #ifndef __TOOLS_H__ 2 | #define __TOOLS_H__ 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | class Tools 10 | { 11 | public: 12 | bool IsReadyForHook(string* ModuleList, int NumModules); 13 | void* DetourFunction(PBYTE src, const PBYTE dst, const int len); 14 | void HideModule(HINSTANCE hModule); 15 | void EraseHeader(HINSTANCE hModule); 16 | }; 17 | 18 | // quantidade de elementos em um array 19 | #define GetSizeOf(a) sizeof(a)/sizeof(*a) 20 | 21 | extern Tools tools; 22 | 23 | #endif //__TOOLS_H__ --------------------------------------------------------------------------------