namespace VK {
void Hook(HWND hwnd) {
if (!CreateDeviceVK( )) {
LOG("[!] CreateDeviceVK() failed.\n");
return;
}
void* fnAcquireNextImageKHR = reinterpret_cast<void*>(vkGetDeviceProcAddr(g_FakeDevice, "vkAcquireNextImageKHR"));
void* fnAcquireNextImage2KHR = reinterpret_cast<void*>(vkGetDeviceProcAddr(g_FakeDevice, "vkAcquireNextImage2KHR"));
void* fnQueuePresentKHR = reinterpret_cast<void*>(vkGetDeviceProcAddr(g_FakeDevice, "vkQueuePresentKHR"));
void* fnCreateSwapchainKHR = reinterpret_cast<void*>(vkGetDeviceProcAddr(g_FakeDevice, "vkCreateSwapchainKHR"));
if (g_FakeDevice) {
vkDestroyDevice(g_FakeDevice, g_Allocator);
g_FakeDevice = NULL;
}
if (fnAcquireNextImageKHR) {
g_Hwnd = hwnd;
// Hook
LOG("[+] Vulkan: fnAcquireNextImageKHR: 0x%p\n", fnAcquireNextImageKHR);
LOG("[+] Vulkan: fnAcquireNextImage2KHR: 0x%p\n", fnAcquireNextImage2KHR);
LOG("[+] Vulkan: fnQueuePresentKHR: 0x%p\n", fnQueuePresentKHR);
LOG("[+] Vulkan: fnCreateSwapchainKHR: 0x%p\n", fnCreateSwapchainKHR);
static MH_STATUS aniStatus = MH_CreateHook(reinterpret_cast<void**>(fnAcquireNextImageKHR), &hkAcquireNextImageKHR, reinterpret_cast<void**>(&oAcquireNextImageKHR));
static MH_STATUS ani2Status = MH_CreateHook(reinterpret_cast<void**>(fnAcquireNextImage2KHR), &hkAcquireNextImage2KHR, reinterpret_cast<void**>(&oAcquireNextImage2KHR));
static MH_STATUS qpStatus = MH_CreateHook(reinterpret_cast<void**>(fnQueuePresentKHR), &hkQueuePresentKHR, reinterpret_cast<void**>(&oQueuePresentKHR));
static MH_STATUS csStatus = MH_CreateHook(reinterpret_cast<void**>(fnCreateSwapchainKHR), &hkCreateSwapchainKHR, reinterpret_cast<void**>(&oCreateSwapchainKHR));
MH_EnableHook(fnAcquireNextImageKHR);
MH_EnableHook(fnAcquireNextImage2KHR);
MH_EnableHook(fnQueuePresentKHR);
MH_EnableHook(fnCreateSwapchainKHR);
}
}
void Unhook( ) {
if (ImGui::GetCurrentContext( )) {
if (ImGui::GetIO( ).BackendRendererUserData)
ImGui_ImplVulkan_Shutdown( );
if (ImGui::GetIO( ).BackendPlatformUserData)
ImGui_ImplWin32_Shutdown( );
ImGui::DestroyContext( );
}
CleanupDeviceVulkan( );
}
} // namespace VK