STEAM GROUP
Special K - "Kaldaien's Mod" Special☆K
STEAM GROUP
Special K - "Kaldaien's Mod" Special☆K
454
IN-GAME
3,231
ONLINE
Founded
May 23, 2016
Language
English
All Discussions > Development > Topic Details
blu Jun 3, 2019 @ 2:28am
Need help building custom injector
I chatted with @Aemony about SK for a while and he told me that SKIM injects SK into EVERY process on the system. I wanted to make something more smart (that checks on window creation if the process loaded any of the generic renderAPI dlls ("dxgi.dll", "d3d8.dll", "d3d9.dll", "d3d9ex.dll", "opengl32.dll", "d3d11.dll", "dxcore.dll") and then inject SK if it hasn't been injected already. I came as far as https://i.imgur.com/W5J60d3.png but SK is not showing up in game, does it need more specialized injection than just LoadLibrary?

https://github.com/Bluscream/SpecialK-Injector
< >
Showing 1-15 of 19 comments
Aemony Jun 3, 2019 @ 8:37am 
LoadLibrary triggers DllMain, no? I imagine some of the checks Special K is built around (global CBT hooks and local wrapper DLLs) evaluate as false which prevents it from fully initializing itself.

https://gitlab.com/Kaldaien/SpecialK/blob/0.10.xdr/src/SpecialK.cpp#L248
Last edited by Aemony; Jun 3, 2019 @ 8:38am
blu Jun 3, 2019 @ 9:33am 
So what do i need to change in my injector to make SK accept the injection? I'm not good at C++ :(
Aemony Jun 3, 2019 @ 10:17am 
Originally posted by blu:
So what do i need to change in my injector to make SK accept the injection? I'm not good at C++ :(

Diagnose what's evaluating as false and preventing the full execution, followed by compiling a variant of SK that doesn't have that behavior?

:conwayshrug:

I ain't a developer, so you'll have to see what Kaldaien comes up with.
blu Jun 3, 2019 @ 10:21am 
Well, the thing is i don't even get logs from SK. Neither in
C:\Users\blusc\Documents\My Mods\SpecialK\Profiles
nor in the directory of the injector nor in the game directory
Last edited by blu; Jun 3, 2019 @ 10:21am
Aemony Jun 3, 2019 @ 10:23am 
Special K doesn't create logs if it isn't fully initialized. Otherwise your Documents\My Mods\SpecialK\Profiles folder would've been filled with logs for all sorts of processes SK got loaded into but never fully initialized within.
blu Jun 3, 2019 @ 10:31am 
Makes sense, but that makes it hard to debug in this case, maybe Kal can help us out a bit.
Kaldaien Jun 3, 2019 @ 2:27pm 
Your description is already how SKIM works. It has a global hook that triggers whenever an application creates a window.
blu Jun 3, 2019 @ 2:28pm 
Originally posted by Kaldaien:
Your description is already how SKIM works. It has a global hook that triggers whenever an application creates a window.
If you've read carefully, mine only injects if the created window is not "whitelisted" AND uses a rendering API like dxgi

Could you try to answer the question how injecting SK differs from normal LoadLibraryA ?
Last edited by blu; Jun 3, 2019 @ 2:29pm
Kaldaien Jun 3, 2019 @ 2:31pm 
Originally posted by blu:
Originally posted by Kaldaien:
Your description is already how SKIM works. It has a global hook that triggers whenever an application creates a window.
If you've read carefully, mine only injects if the created window is not "whitelisted" AND uses a rendering API like dxgi
That's the same as SKIM as well, with the added exception that anything that has steam_api.dll loaded is an additional valid injection target. Likewise, if a game has a file path that doesn't include SteamApps, then it must match a whitelist or the DLL loads but does not initialize itself.

If I simply denied loading the DLL, it would utterly destroy system performance because the DLL would be checking its whitelist constantly. It's important to partially initialize the DLL with an event that listens for global unload.
Last edited by Kaldaien; Jun 3, 2019 @ 2:32pm
blu Jun 3, 2019 @ 2:42pm 
that's just sad
Last edited by blu; Jun 3, 2019 @ 2:42pm
Kaldaien Jun 3, 2019 @ 2:48pm 
SKIM doesn't actually do any of this stuff though, the DLL exports a few functions to start/stop/restart injection and SKIM is just a graphical frontend that is checking the state of global injection.

All injection-related code is actually in src/injection/injection.cpp, and src/SpecialK.cpp.

I came to this design after looking at other potential systems including simpler shim DLLs and finding a high potential for deadlock if LoadLibrary (...) is called during window creation in an application.

Shim loading can work, but it really needs to be done using the offical application compatibility layer in Windows, which loads your DLL as a substitute for some other DLL or for a specific imported DLL function. That prevents deadlocks and also loads the DLL earlier and less often. I considered using that but it would have made Special K less flexible than I'd like, so I went about optimizing the thing into a single self-hosting DLL with partial initialization and on-demand unload support.



I can point you to the regular expression matching code for the whitelist if you'd like to make some kind of change to the whitelisting, but I'd really like to keep injection handled by the DLL itself. I am obsesed with performance and that's the only way to keep injection overhead down to levels I am happy with.
Aemony Jun 3, 2019 @ 2:55pm 
And imagine! All of this came from a need to delay global injection so that it would allow games to start up fully before starting (and failing) to hook the appropriate swapchains or them.

On that note, Kal, wouldn’t it be semi-easy to add some form of global delay for the global injection before SK starts to fully initialize? As in, at the moment it typically starts to initialize the rest of SK in a process it instead goes and takes a nap for X number of seconds?

Or that part of the code is too heavily disconnected from how it reads config files and whatnot so this isn’t possible?

I think that’s the gist of it. If SK supported e.g. a “60 seconds delayed global injection” method or similar, it would allow users to use SK in games where hooking them directly on launch would otherwise end up in issues.
Kaldaien Jun 4, 2019 @ 4:44pm 
Actually, there are now two config files in Special K. There's the AppCache that maps the .exe filename to a more human readable name for the global profile, and then there's the SpecialK.ini file.

In theory, I could add a delay config parameter to the appcache database, but more than half of Special K's features disappear if you delay code injection and it gets worse the longer you delay the stuff so I've never been eager to implement this. I've delayed the one or two things where it's necessary (SteamAPI and input) but render APIs completely breakdown if delayed.
blu Jun 4, 2019 @ 4:57pm 
Hmm, thats a really nasty state, do you think it's better to ditch SK for that game and continue using ReShade only?
Kaldaien Jun 4, 2019 @ 5:53pm 
Yeah, I'd avoid using Special K in that game. I'm not a fan of games that use really restrictive DRM, so I don't see myself supporting that developer.
< >
Showing 1-15 of 19 comments
Per page: 1530 50

All Discussions > Development > Topic Details