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

Add a way to check backend at runtime #63

Open
etra0 opened this issue Dec 15, 2022 · 4 comments
Open

Add a way to check backend at runtime #63

etra0 opened this issue Dec 15, 2022 · 4 comments
Labels

Comments

@etra0
Copy link
Contributor

etra0 commented Dec 15, 2022

Ugh, so, recently, The Witcher 3 was updated and now provides two binaries, one that uses DX12 and the other one that uses DX11. Most of the other code is shared so the tool works by only changing the into_hook type.

I can easily produce two DLLs for each one using some compile-time features, but I'm not to keen into that solution.

I'm also thinking what's an easy way of detecting this at runtime? A stupidly simple way I think is using GetModuleHandle to check which DLL is loaded?

@veeenu
Copy link
Owner

veeenu commented Dec 15, 2022

I think matching against loaded DLLs would be more than enough for 99% of use cases, but I have also been briefly looking into querying the COM interfaces, though I'm afraid that would be flimsier.

As per how to have double hooks in hudhook, until a feature like this lands (I'd like it to!) you could just roll-your-own DllMain method where you first determine what backend is being used, and then conditionally setup the hooks. I think if you copy the macro code verbatim for that you should be good to go!

@veeenu
Copy link
Owner

veeenu commented Mar 1, 2024

These are the modules which are available in the games I have tried.

Looking at this list it should be possible to build a best-effort backend checker. Funnily enough, both the OpenGL 3 and the DirectX 11 renderers work for Baldur's Gate so either result would be fine, but for Elden Ring which also loads OpenGL that is not true. So at a minimum I'd introduce a priority mechanism where dx12 > dx11 > dx9 > opengl3

immagine

@etra0
Copy link
Contributor Author

etra0 commented Mar 1, 2024

At the end of the day I ended up doing something incredibly idiotic but it did work heh, haven't had the need to do anything more extensive.

https://github.com/etra0/litcher/blob/c4526c07f04a20b58596d99b50fa8b7068e41480/src/detect_api.rs#L3-L17

@veeenu
Copy link
Owner

veeenu commented Mar 1, 2024

Well, that's not much different from the way I'd have implemented something like that :D

Thinking about it, I guess this kind of logic might depend heavily on each client's needs, so not sure whether to include it as a first-party thing. It would probably still be a good idea to have a cookbook of these strategies in hudbook, so I'm keeping this open to track that.

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

No branches or pull requests

2 participants