Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <d3d9.h>
- #include <d3dx9.h>
- #include <Mmsystem.h>
- #include <time.h>
- #include <stdio.h>
- #include <iostream>
- #include <string>
- #include <sstream>
- #include "CDetour/CDetour.h"
- #include "ImGui/imgui.h"
- #include "ImGui/imgui_impl_dx9.h"
- #include "ImGui/imgui_internal.h"
- #pragma comment( lib, "winmm.lib" )
- #pragma comment( lib, "d3d9.lib" )
- #pragma comment( lib, "d3dx9.lib" )
- CDetour d3dcreateDetour;
- CDetour d3d9endsceneDetour;
- CDetour d3d9resetDetour;
- ID3DXFont *Fonte;
- IDirect3DDevice9 *pInterface;
- bool CriarComponentes = true;
- bool b2 = false;
- int __stdcall DllMain( HMODULE, DWORD, LPVOID );
- void ApplyHooks( int );
- void __stdcall myCreateDevice( IDirect3D9*, UINT, D3DDEVTYPE, HWND, DWORD, D3DPRESENT_PARAMETERS* , IDirect3DDevice9 ** );
- void __stdcall myEndScene( IDirect3DDevice9* );
- HRESULT __stdcall myReset( IDirect3DDevice9*, D3DPRESENT_PARAMETERS* );
- WNDPROC oriWndProc = NULL;
- extern LRESULT ImGui_ImplDX9_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
- bool isImGUiOK = false, testbool;
- float testslider;
- bool bShowMenu;
- D3DDEVICE_CREATION_PARAMETERS d3dcp;
- LRESULT CALLBACK hWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- if (ImGui_ImplDX9_WndProcHandler(hwnd, uMsg, wParam, lParam) && GetKeyState(VK_INSERT) == 1)
- {
- return 1l;
- }
- return CallWindowProc(oriWndProc, hwnd, uMsg, wParam, lParam);
- }
- void MenuRender()
- {
- if (!bShowMenu)
- return;
- std::cout << "atleast we reach a point" << std::endl;
- ImGui_ImplDX9_NewFrame();
- if (ImGui::Begin("Test Menu", 0, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_ShowBorders))
- {
- ImGui::Text("Example");
- if (ImGui::Button("Start", ImVec2(50, 25)))
- {
- }
- ImGui::SameLine();
- ImGui::SliderFloat("Slider", &testslider, 0, 360);
- ImGui::Checkbox("CheckBox Function", &testbool);
- ImGui::End();
- }
- ImGui::Render();
- std::cout << "WE GOOD" << std::endl;
- }
- void WriteTextOnScreen( int X, int Y, D3DCOLOR Cor, const char *Texto, ...)
- {
- RECT Rect; Rect.bottom = Y + 1000; Rect.left = X; Rect.right = X + 1000; Rect.top = Y;
- char sTexto[256];
- va_list vArgumentList;
- va_start( vArgumentList, Texto);
- _vsnprintf_s( sTexto, sizeof( sTexto), sizeof( sTexto), Texto, vArgumentList );
- va_end( vArgumentList );
- //BORDER BLACK
- RECT Rect2 = { X + 1, Y + 1, X + 1, Y + 1 };
- Fonte->DrawTextA( NULL, sTexto, -1, &Rect2, DT_NOCLIP, 0xFF000000 );
- Fonte->DrawTextA( NULL, sTexto, -1, &Rect, 0, Cor );
- }
- void __stdcall myEndScene(LPDIRECT3DDEVICE9 UnidadeD3D9 )
- {
- if( CriarComponentes )
- {
- D3DXCreateFontA( UnidadeD3D9, 16, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS, 6, DEFAULT_PITCH | FF_DONTCARE, "Arial", &Fonte );
- CriarComponentes = false;
- }
- if( Fonte )
- WriteTextOnScreen( 10, 10, D3DCOLOR_ARGB( 255, 0, 255, 0 ), "Testing D3D9 SRO Hooking !" );
- if (!isImGUiOK)
- {
- ImGuiIO& io = ImGui::GetIO();
- io.DeltaTime = 1.0f / 60.0f;
- UnidadeD3D9->GetCreationParameters(&d3dcp);
- io.Fonts->AddFontDefault();
- if (!ImGui_ImplDX9_Init(&d3dcp, UnidadeD3D9))
- std::cout << "here a ba4a" << std::endl;
- isImGUiOK = true;
- }
- if (GetAsyncKeyState(VK_INSERT) & 1)
- {
- bShowMenu = !bShowMenu;
- }
- DWORD dwOld_D3DRS_COLORWRITEENABLE;
- UnidadeD3D9->GetRenderState(D3DRS_COLORWRITEENABLE, &dwOld_D3DRS_COLORWRITEENABLE); // Lets us draw without Net_Graph
- UnidadeD3D9->SetRenderState(D3DRS_COLORWRITEENABLE, 0xffffffff);
- MenuRender();
- UnidadeD3D9->SetRenderState(D3DRS_COLORWRITEENABLE, dwOld_D3DRS_COLORWRITEENABLE);
- ImGui::GetIO().MouseDrawCursor = bShowMenu;
- }
- HRESULT __stdcall myReset( IDirect3DDevice9 *UnidadeD3D9, D3DPRESENT_PARAMETERS* PresentationParameters )
- {
- __asm pushad
- if( Fonte ){
- Fonte->OnLostDevice();
- }
- HRESULT hRetn = (HRESULT)d3d9resetDetour.Org( UnidadeD3D9, PresentationParameters );
- if( SUCCEEDED( hRetn ) ){
- if(Fonte)
- Fonte->OnResetDevice();
- }
- __asm popad
- return hRetn;
- }
- void __stdcall myCreateDevice( IDirect3D9* d3d, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DDevice9 **ppReturnedDeviceInterface )
- {
- d3dcreateDetour.Org( d3d, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface );
- pInterface = *ppReturnedDeviceInterface;
- if( !b2 )
- ApplyHooks( 2 );
- }
- void ApplyHooks( int nType )
- {
- if( nType == 1 )
- {
- unsigned long* pD3DVTable;
- IDirect3D9* pD3D = Direct3DCreate9( D3D_SDK_VERSION );
- if( !pD3D ) // INVALID OBJECT
- return;
- pD3DVTable = (unsigned long*)*(unsigned long*)pD3D;
- pD3D->Release();
- // pD3DVTable[16] = IDirect3D9::CreateDevice
- d3dcreateDetour.Detour( (unsigned char*)pD3DVTable[16], (unsigned char*)myCreateDevice );
- d3dcreateDetour.Apply();
- }
- else if( nType == 2 )
- {
- unsigned long* pD3D9VTable;
- if( !pInterface )
- return;
- pD3D9VTable = (unsigned long*)*(unsigned long*)pInterface;
- // pD3D9VTable[42] = IDirect3DDevice9::EndScene
- d3d9endsceneDetour.Detour( (unsigned char*)pD3D9VTable[42], (unsigned char*)myEndScene, true );
- d3d9endsceneDetour.Apply();
- // pD3D9VTable[16] = IDirect3DDevice9::Reset
- d3d9resetDetour.Detour( (unsigned char*)pD3D9VTable[16], (unsigned char*)myReset );
- d3d9resetDetour.Apply();
- b2 = true;
- }
- }
- void User_Initialize()
- {
- Sleep(2000);
- oriWndProc = (WNDPROC)SetWindowLongPtr(FindWindow(NULL, "SRO_Client"),
- GWL_WNDPROC, (LONG)(LONG_PTR)hWndProc);
- if (oriWndProc == NULL)
- std::cout << "Failed to hook wndproc " << std::endl;
- else
- std::cout << "nice hook wndproc " << std::endl;
- }
- int __stdcall DllMain( HMODULE hModule, DWORD dwReason, LPVOID )
- {
- DisableThreadLibraryCalls( hModule );
- if( dwReason == DLL_PROCESS_ATTACH )
- {
- AllocConsole();
- freopen("CONIN$", "r", stdin);
- freopen("CONOUT$", "w", stdout);
- std::cout << "--------------------------------" << std::endl;
- std::cout << "Sro Library starting in debug mode" << std::endl;
- std::cout << "Compile time " << __DATE__ << " " << __TIME__ << std::endl;
- std::cout << "--------------------------------" << std::endl;
- std::cout << "New SRO Window TEST Initialized " << std::endl;
- std::cout << "--------------------------------" << std::endl;
- ApplyHooks( 1 );
- CreateThread(0, 0, (LPTHREAD_START_ROUTINE)User_Initialize, 0, 0, 0);
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement