Rebzzel / kiero

Universal graphical hook for a D3D9-D3D12, OpenGL and Vulkan based games.
MIT License
1.01k stars 217 forks source link

[DX11] Hook DirectX #13

Closed Kade-github closed 4 years ago

Kade-github commented 4 years ago

Alright, so basically I'm trying to hook into DirectX into a unity game right,

and no work.

It doesn't crash, it says the method is working, and it does nothing.

(Trying to add ImGui)

CreateGui:

    void gui::CreateGui()
    {
        kiero::Status::Enum st = kiero::init(kiero::RenderType::D3D11);
        if (st == kiero::Status::Enum::Success)
        {
            if (kiero::bind(8, (void**)&oPresent, hkPresent11) == kiero::Status::Success)
                std::cout << "Binded to DirectX\n";
            else
                std::cout << "Failed to bind to DirectX\n";
        }
        else
        {
            const char* f;
            switch (st)
            {
            case kiero::Status::AlreadyInitializedError:
                f = "already done";
                break;
            case kiero::Status::ModuleNotFoundError:
                f = "module aint found";
                break;
            case kiero::Status::NotInitializedError:
                f = "no init";
                break;
            case kiero::Status::NotSupportedError:
                f = "no support";
                break;
            case kiero::Status::UnknownError:
                f = "idkfk";
                break;
            }
            std::cout << "Failed to load Hooking Lib. Status: " << st << "\n";
        }
    }

Hook:

long __stdcall hkPresent11(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags)
{
    static bool init = false;

    if (!init)
    {
        DXGI_SWAP_CHAIN_DESC desc;
        pSwapChain->GetDesc(&desc);

        ID3D11Device* device;
        pSwapChain->GetDevice(__uuidof(ID3D11Device), (void**)&device);

        ID3D11DeviceContext* context;
        device->GetImmediateContext(&context);

        ImGui::CreateContext();
        ImGui_ImplWin32_Init(desc.OutputWindow);
        ImGui_ImplDX11_Init(device, context);

        init = true;
    }

    ImGui::ShowAboutWindow();

    return oPresent(pSwapChain, SyncInterval, Flags);
}

Thanks.

Kade-github commented 4 years ago

By saying the method is working, I mean I have a print function that literally says its working. It's getting called, but the ImGui GUI doesn't appear.

Rebzzel commented 4 years ago

Hello, @KadeDev!

Hook working, but you calling the imgui is not correct. I'll just leave IT here. I hope this gives you a big idea.

Have a nice day!

Kade-github commented 4 years ago

Oh was that really the problem? I ended up fixing it on my own heh, sorry for the late response. This is a really great library!