feature: hook r_shadows cvar to restore shadows in pre-25th anniversary versions #545
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reason for draft status
Draft for now only because I want to rebase it normally as soon as a series of requests related to restructuring would be in the master and change it to comply with the new standards (same reason goes for #473 too)
And besides, I was too lazy to look for patterns and offsets for other builds at the moment of making it, so here for now I can only guarantee support for build 6153 for the Windows version
Explanation
Since at least the NGHL build (or maybe this happened earlier), Valve stopped registering a cvar to enable shadows and returned it only with 25th anniversary version
But the shadow code itself and the calls to the shadow function remained in engine-side (
studioapi_GL_StudioDrawShadow
) and client-side (https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/cl_dll/StudioModelRenderer.cpp#L2082)In general, to restore shadows you need to find the
r_shadows
pointer in the engine (since traverse in the cvars linked list will not give results), then bring it to register the cvar and that's allBut shadows have an obvious issue with depth fighting, and as a fix, the option of changing arguments of the glDepthMask call already existing at the beginning of the function from
GL_TRUE
toGL_FALSE
was chosen, and then at the end of the function returning everything to its original stateThis is achieved by using a hook for the engine wrapper of these GL functions called QGL and then redirecting to our own wrapper: https://github.com/id-Software/Quake-2/blob/master/ref_gl/qgl.h
This can, of course, be achieved without patterns and offsets, by directly hooking GL functions from system libraries, but in my opinion this will clearly create more issues due to a more dependent environment, so I'd say let the engine cook instead