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

feature: hook r_shadows cvar to restore shadows in pre-25th anniversary versions #545

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

SmileyAG
Copy link
Collaborator

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 all

But 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 to GL_FALSE was chosen, and then at the end of the function returning everything to its original state
This 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

@SmileyAG SmileyAG marked this pull request as draft July 14, 2024 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants