Rebzzel / kiero

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

i have a skill issue #60

Open BiscuteOwO opened 7 months ago

BiscuteOwO commented 7 months ago

well its like kiero::init(kiero::RenderType::D3D11); 👇 kiero::bind(8, (void)&oEndScene, hkEndScene); 👇 kiero::shutdown(); 👇 kiero::init(kiero::RenderType::D3D11); 👇 kiero::bind(8, (void)&oEndScene, hkEndScene); the last bind will not work for some reason, and i tried on d3d12, things still happen, what can i do

fadillzzz commented 7 months ago

I think it's because MH_RemoveHook(MH_ALL_HOOKS) is never called during the shutdown process. So when the second call to bind reaches the following lines, it fails with Status::UnknownError

        if (MH_CreateHook(target, _function, _original) != MH_OK || MH_EnableHook(target) != MH_OK) {
            return Status::UnknownError;
        }

Just a guess, though. Didn't try it myself, but see if you can fix it by adding that MH_RemoveHook(MH_ALL_HOOKS) call. in the kiero::shutdown function.

BiscuteOwO commented 7 months ago

uhh, it still happens sir, and seems it cant get swapchain info on second init, i try to init d3d11 and hook it, when program find out the target is not using d3d11 then hook d3d12, and can not hook present, but the part of hook to get g_pD3D12CommandQueue is fine

fadillzzz commented 7 months ago

I had a similar issue when trying to make a mod menu. What I did was hook a DX12 function to retrieve the command queue, sleep the thread for 2 seconds, then if the command queue was captured successfully, continue using DX12 as normal (hook the present function). Otherwise, unbind and shutdown kiero and reinitialize with D3D11 and then hook the present function. It's a bit of a hackish solution but it works.


        bool init() {
            if (kiero::init(kiero::RenderType::D3D12) == kiero::Status::Success) {
                kiero::bind(54, (void **)&oExecuteCommandLists, hookExecuteCommandLists);

                std::this_thread::sleep_for(std::chrono::seconds(2));

                if (commandQueue == nullptr) {
                    kiero::unbind(54);
                    kiero::shutdown();
                    return false;
                }

                kiero::bind(140, (void **)&oPresent, hookPresent);

                return true;
            }

            return false;
        }

        void initCaller() {
          if (init()) {
            // we're using DX12
          } else {
            // reinitialize kiero with DX11 here and hook the present function
          }
        }
BiscuteOwO commented 7 months ago

uh i figured it out, the second bind's index(both dx11 dx12) refers to same swapchain address, and this make second hook failed, thank you mate