-
Автор темы
- #1
menu.cpp:
void menu::SetupMenu(LPDIRECT3DDEVICE9 devic) noexcept
{
auto params = D3DDEVICE_CREATION_PARAMETERS{ };
device->GetCreationParameters(¶ms);
window = params.hFocusWindow;
//Ошибка тут
originalWindowProcess = reinterpret_cast<WNDPROC>(SetWindowLongPtr(window, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(WindowProcess)));
ImGui::CreateContext();
ImGui::StyleColorsDark();
ImGui_ImplWin32_Init(window);
ImGui_ImplDX9_Init(device);
setup_menu = true;
}
hooks.cpp:
void Setup()
{
if (MH_Initialize())
throw std::runtime_error("Unable to initialize minhook");
//Тут ошибка
if (MH_CreateHook(hooks::VirtualFunction(menu::device, 42), &EndScene, reinterpret_cast<void**>(&hooks::EndSceneOriginal)))
throw std::runtime_error("Unable to hook EndScene");
//Тут ошибка
if (MH_CreateHook(hooks::VirtualFunction(menu::device, 16), &Reset, reinterpret_cast<void**>(&hooks::ResetOriginal)))
throw std::runtime_error("Unable to hook Reset");
if (MH_EnableHook(MH_ALL_HOOKS))
throw std::runtime_error("Unable to enable hooks");
menu::DestroyDirectX();
}
Функция EndScene:
long __stdcall EndScene(IDirect3DDevice9* device) noexcept
{
static const auto returnAddress = _ReturnAddress();
const auto result = hooks::EndSceneOriginal(device, device);
if (_ReturnAddress() == returnAddress)
return result;
if (!menu::setup_menu)
menu::SetupMenu(device);
if (menu::open_menu)
menu::Render();
return result;
}
Функция Reset:
HRESULT __stdcall Reset(IDirect3DDevice9* device, D3DPRESENT_PARAMETERS* params) noexcept
{
ImGui_ImplDX9_InvalidateDeviceObjects();
const auto result = hooks::ResetOriginal(device, device, params);
ImGui_ImplDX9_CreateDeviceObjects();
return result;
}
Функция WindowProcess:
LRESULT CALLBACK WindowProcess(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
//open menu
if (GetAsyncKeyState(VK_INSERT) & 1)
menu::open_menu = !menu::open_menu;
//msg
if (menu::open_menu && ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam)) return 1L;
return CallWindowProc(menu::originalWindowProcess, hWnd, msg, wParam, lParam);
}