Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vulkan tip #1

Open
bruhmoment21 opened this issue Aug 2, 2022 · 1 comment
Open

vulkan tip #1

bruhmoment21 opened this issue Aug 2, 2022 · 1 comment

Comments

@bruhmoment21
Copy link

bruhmoment21 commented Aug 2, 2022

hey i am the guy that helped you get vulkan to work. so i had nothing else on my mind at this time and wanted to make vulkan hook work even without steam overlay(for performance reasons or idk). i dropped steps in real language (english) and in code so basically.

  1. we want to hook this func because this method has the important things u need specifically m_device. this is m_device class
  2. after we got m_device we need to get our 3 functions vkAcquireImageKHR, vkQueuePresentKHR, vkCreateSwapchain addressess.
  3. hook them

New Vulkan::Hook (not c+p ready btw). GetHandle and GetProcAddress are crossplatform wrappers they are dlopen and dlsym.

void Hook( ) {
        const Module::CachedModule* hDXVKLib = Module::GetHandle("libdxvk_d3d9.so");
        if (!hDXVKLib)
            return;

        void* fnPresentImage = Module::GetProcAddress(hDXVKLib->hHandle, "_ZN4dxvk2vk9Presenter12presentImageEv");
        if (fnPresentImage) {
            HOOK(PresentImage);
        }
    }

Presenter::presentImage Hook (old Vulkan::Hook)

static CHook<VkResult VKAPI_CALL(uintptr_t)> oPresentImage;
static VkResult VKAPI_CALL hkPresentImage(uintptr_t ecx) {
    // just check things so u dont hook twice or sum
    if (ecx && !oAcquireNextImageKHR.originalFn) {
        // offsets are easy to find in ida everything is exported.
        uintptr_t m_device = *reinterpret_cast<uintptr_t*>(ecx + 0x10);
        if (m_device) {
            if (!CreateDeviceVK( )) {
                LOG("[katehook] CreateDeviceVK() failed\n");
                return oPresentImage.originalFn(ecx);
            }

            void* fnAcquireNextImageKHR = *reinterpret_cast<void**>(m_device + 0x458);
            void* fnQueuePresentKHR = *reinterpret_cast<void**>(m_device + 0x460);
            void* fnCreateSwapchainKHR = *reinterpret_cast<void**>(m_device + 0x440);

            if (g_FakeDevice) {
                vkDestroyDevice(g_FakeDevice, g_Allocator);
                g_FakeDevice = NULL;
            }

            if (fnAcquireNextImageKHR) {
                HOOK(AcquireNextImageKHR);
                HOOK(QueuePresentKHR);
                HOOK(CreateSwapchainKHR);
            }
        }
    }

    return oPresentImage.originalFn(ecx);
}

edit: this should work for every game that uses dxvk most probably (on linux tho).

@Sumandora
Copy link
Owner

Alright, will keep this for the future.
I have more important work on this project right now, so I will be sticking to that first.
If the master branch gets more stable, I might merge the vulkan support into master and then I'm going to try to implement this.
The master branch just crashes from time to time right now and this is a issue that has to be addressed first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants