C++ 钩住了Direct3D 9,但我的东西没有画出来

C++ 钩住了Direct3D 9,但我的东西没有画出来,c++,hook,direct3d,dll-injection,direct3d9,C++,Hook,Direct3d,Dll Injection,Direct3d9,大家好,我正在搞一些DLL注入的东西。因此,我下载了一个简单的Direct3D 9示例应用程序(它只显示一个立方体),我想对其进行操作 我已经成功地钩住了这个应用程序的EndScene和Reset功能,现在只想为当前绘制的帧添加更多的灯光 以下是我的EndScene函数: HRESULT WINAPI myEndScene(LPDIRECT3DDEVICE9 pDevice) { lightHackTest2(pDevice); auto ret = origEndScene(p

大家好,我正在搞一些DLL注入的东西。因此,我下载了一个简单的Direct3D 9示例应用程序(它只显示一个立方体),我想对其进行操作

我已经成功地钩住了这个应用程序的EndScene和Reset功能,现在只想为当前绘制的帧添加更多的灯光

以下是我的EndScene函数:

HRESULT WINAPI myEndScene(LPDIRECT3DDEVICE9 pDevice) {
    lightHackTest2(pDevice);
    auto ret = origEndScene(pDevice);
    placeHooks();
    return ret;
}
void lightHackTest2(LPDIRECT3DDEVICE9 pDevice) {
    pDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(100, 100, 100));
}

void lightHackTest(LPDIRECT3DDEVICE9 pDevice) {
    D3DLIGHT9 light;
    ZeroMemory(&light, sizeof(light));
    light.Type = D3DLIGHT_DIRECTIONAL;
    light.Diffuse.r = 0.5f;
    light.Diffuse.g = 0.5f;
    light.Diffuse.b = 0.5f;
    light.Diffuse.a = 1.0f;
    light.Direction.x = -1.0f;
    light.Direction.y = -0.5f;
    light.Direction.z = -1.0f;

    pDevice->SetLight(0, &light);
    pDevice->LightEnable(0, TRUE);
}
下面是我的lightHackTest2函数:

HRESULT WINAPI myEndScene(LPDIRECT3DDEVICE9 pDevice) {
    lightHackTest2(pDevice);
    auto ret = origEndScene(pDevice);
    placeHooks();
    return ret;
}
void lightHackTest2(LPDIRECT3DDEVICE9 pDevice) {
    pDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(100, 100, 100));
}

void lightHackTest(LPDIRECT3DDEVICE9 pDevice) {
    D3DLIGHT9 light;
    ZeroMemory(&light, sizeof(light));
    light.Type = D3DLIGHT_DIRECTIONAL;
    light.Diffuse.r = 0.5f;
    light.Diffuse.g = 0.5f;
    light.Diffuse.b = 0.5f;
    light.Diffuse.a = 1.0f;
    light.Direction.x = -1.0f;
    light.Direction.y = -0.5f;
    light.Direction.z = -1.0f;

    pDevice->SetLight(0, &light);
    pDevice->LightEnable(0, TRUE);
}
这些函数实际上会被调用(使用一些MessageBox进行检查),但在场景中一切都保持不变


我是否应用了错误的灯光?

考虑到D3D管道的复杂性,我不认为在一些随机应用程序中仅在结束场景之前设置灯光就可以保证产生任何更改。您可能想在管道的早期添加light way,但我正在关注一个教程系列,作者就是这样做的,并且成功地完成了。