hudhook
hudhook copied to clipboard
Add a way to check backend at runtime
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?
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!
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
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
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.