Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Dec 25, 2023
1 parent ad07ae0 commit 836c225
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Build/svencoop/renderer/shader/studio_shader.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ vec3 R_StudioCelShade(vec3 v_color, vec3 normalWS, vec3 lightdirWS, float specul
vec4 lightdirLS = v_invbonematrix * vec4(L, 0.0);

#if defined(STUDIO_NF_CELSHADE_FACE)
lightdirLS.z = 0;
lightdirLS.z *= 0.001;
#else
lightdirLS.z *= 0.01;
#endif
Expand Down
39 changes: 27 additions & 12 deletions Plugins/Renderer/gl_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ void R_FillAddress(void)
{
gPrivateFuncs.R_SetupGL = (decltype(gPrivateFuncs.R_SetupGL))Search_Pattern(R_SETUPGL_SIG_BLOB);
}

Sig_FuncNotFound(R_SetupGL);

if (g_iEngineType == ENGINE_SVENGINE)
Expand Down Expand Up @@ -3570,7 +3571,7 @@ void R_FillAddress(void)
if (1)
{
const char sigs[] = "\x68\x2A\x2A\x2A\x2A\x68\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\x83\xC4\x08";
addr = (DWORD)g_pMetaHookAPI->SearchPattern((void *)gPrivateFuncs.R_SetupGL, 0x700, sigs, sizeof(sigs) - 1);
addr = (DWORD)Search_Pattern_From_Size((void *)gPrivateFuncs.R_SetupGL, 0x700, sigs);
Sig_AddrNotFound(gWorldToScreen);
gWorldToScreen = *(decltype(gWorldToScreen)*)(addr + 6);
gScreenToWorld = *(decltype(gScreenToWorld)*)(addr + 1);
Expand Down Expand Up @@ -5593,20 +5594,31 @@ void R_FillAddress(void)

}

if (1)
{
#define R_WORLD_MATRIX_SIG "\x68\x2A\x2A\x2A\x2A\x68\xA6\x0B\x00\x00"
addr = (DWORD)g_pMetaHookAPI->SearchPattern((void *)gPrivateFuncs.R_SetupGL, 0x600, R_WORLD_MATRIX_SIG, sizeof(R_WORLD_MATRIX_SIG) - 1);
Sig_AddrNotFound(r_world_matrix);
r_world_matrix = *(float **)(addr + 1);
addr = (DWORD)Search_Pattern_From_Size((void*)gPrivateFuncs.R_SetupGL, 0x600, R_WORLD_MATRIX_SIG);
Sig_AddrNotFound(r_world_matrix);
r_world_matrix = *(float**)(addr + 1);

#define R_PROJ_MATRIX_SIG "\x68\x2A\x2A\x2A\x2A\x68\xA7\x0B\x00\x00"
addr = (DWORD)g_pMetaHookAPI->SearchPattern((void *)gPrivateFuncs.R_SetupGL, 0x500, R_PROJ_MATRIX_SIG, sizeof(R_PROJ_MATRIX_SIG) - 1);
Sig_AddrNotFound(r_projection_matrix);
r_projection_matrix = *(float **)(addr + 1);
addr = (DWORD)Search_Pattern_From_Size((void*)gPrivateFuncs.R_SetupGL, 0x500, R_PROJ_MATRIX_SIG);
Sig_AddrNotFound(r_projection_matrix);
r_projection_matrix = *(float**)(addr + 1);

#define TMP_PALETTE_SIG "\x68\x2A\x2A\x2A\x2A\x6A\x00\x6A\x00"
addr = (DWORD)g_pMetaHookAPI->SearchPattern((void *)gPrivateFuncs.R_StudioSetupSkin, 0x600, TMP_PALETTE_SIG, sizeof(TMP_PALETTE_SIG) - 1);
Sig_AddrNotFound(tmp_palette);
tmp_palette = *(void **)(addr + 1);
addr = (DWORD)Search_Pattern_From_Size((void*)gPrivateFuncs.R_StudioSetupSkin, 0x600, TMP_PALETTE_SIG);
Sig_AddrNotFound(tmp_palette);
tmp_palette = *(void**)(addr + 1);
}

if (g_iEngineType == ENGINE_SVENGINE)
{
#define VERTICAL_FOV_SIG_SVENGINE "\x50\xFF\x15\x2A\x2A\x2A\x2A\x83\x3D\x2A\x2A\x2A\x2A\x00"
addr = (DWORD)Search_Pattern_From_Size((void*)gPrivateFuncs.R_SetupGL, 0x120, VERTICAL_FOV_SIG_SVENGINE, sizeof(VERTICAL_FOV_SIG_SVENGINE) - 1);
Sig_AddrNotFound(vertical_fov_SvEngine);
vertical_fov_SvEngine = *(decltype(vertical_fov_SvEngine)*)(addr + 9);
}

if (1)
{
Expand Down Expand Up @@ -6311,6 +6323,7 @@ void R_FillAddress(void)
}
#endif

#if 0
if (1)
{
#define URL_INFO_STRING "url_info"
Expand Down Expand Up @@ -6349,6 +6362,7 @@ void R_FillAddress(void)
Sig_FuncNotFound(DLL_SetModKey);

}
#endif

if (1)
{
Expand Down Expand Up @@ -7261,6 +7275,7 @@ void R_UninstallHooksForEngineDLL(void)
Uninstall_Hook(triapi_RenderMode);
Uninstall_Hook(Draw_MiptexTexture);
Uninstall_Hook(BuildGammaTable);
//Uninstall_Hook(DLL_SetModKey);

Uninstall_Hook(studioapi_StudioDynamicLight);
Uninstall_Hook(studioapi_StudioCheckBBox);
Expand Down Expand Up @@ -7298,15 +7313,15 @@ void R_InstallHooks(void)
Install_InlineHook(triapi_RenderMode);
Install_InlineHook(Draw_MiptexTexture);
Install_InlineHook(BuildGammaTable);
Install_InlineHook(DLL_SetModKey);
//Install_InlineHook(DLL_SetModKey);
}

int WINAPI GL_RedirectedGenTexture(void)
{
return GL_GenTexture();
}

void R_RedirectBlobEngineOpenGLTextures(void)
void R_RedirectLegacyOpenGLTextureAllocation(void)
{
if (!bHasOfficialGLTexAllocSupport)
{
Expand Down
8 changes: 5 additions & 3 deletions Plugins/Renderer/gl_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ extern float *gScreenToWorld;
extern overviewInfo_t *gDevOverview;
extern mplane_t *frustum;

extern qboolean* vertical_fov_SvEngine;

extern int *r_framecount;
extern int *r_visframecount;

Expand Down Expand Up @@ -198,7 +200,7 @@ extern int glheight;
extern bool bEnforceStretchAspect;
extern bool bUseBindless;
extern bool bUseOITBlend;
extern bool bVerticalFov;
//extern bool bVerticalFov;//unused
extern bool bUseLegacyTextureLoader;
extern bool bHasOfficialFBOSupport;
extern bool bHasOfficialGLTexAllocSupport;
Expand Down Expand Up @@ -310,7 +312,7 @@ void R_FillAddress(void);
void R_InstallHooks(void);
void R_UninstallHooksForEngineDLL(void);
void R_UninstallHooksForClientDLL(void);
void R_RedirectBlobEngineOpenGLTextures(void);
void R_RedirectLegacyOpenGLTextureAllocation(void);

void GammaToLinear(float *color);
void R_LoadSkyBox_SvEngine(const char *name);
Expand Down Expand Up @@ -517,7 +519,7 @@ TEMPENTITY *EngineGetTempTentByIndex(int index);

void RemoveFileExtension(std::string& filePath);

void DLL_SetModKey(void *pinfo, char *pkey, char *pvalue);
//void DLL_SetModKey(void *pinfo, char *pkey, char *pvalue);

extern GLint r_viewport[4];
extern float r_entity_matrix[4][4];
Expand Down
14 changes: 11 additions & 3 deletions Plugins/Renderer/gl_rmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ float *gScreenToWorld = NULL;
overviewInfo_t *gDevOverview = NULL;
mplane_t *frustum = NULL;

qboolean* vertical_fov_SvEngine = NULL;

int *g_bUserFogOn = NULL;
float *g_UserFogColor = NULL;
float *g_UserFogDensity = NULL;
Expand Down Expand Up @@ -196,7 +198,7 @@ FBO_Container_t *g_CurrentFBO = NULL;
bool bEnforceStretchAspect = false;
bool bUseBindless = true;
bool bUseOITBlend = false;
bool bVerticalFov = false;
//bool bVerticalFov = false;
bool bUseLegacyTextureLoader = false;
bool bHasOfficialFBOSupport = false;
bool bHasOfficialGLTexAllocSupport = true;
Expand Down Expand Up @@ -1553,7 +1555,7 @@ void GLAPIENTRY GL_DebugOutputCallback(GLenum source, GLenum type, GLuint id, GL
if (0 == strncmp(message, "API_ID_RECOMPILE_FRAGMENT_SHADER", sizeof("API_ID_RECOMPILE_FRAGMENT_SHADER") - 1))
return;

gEngfuncs.Con_Printf("GL_DebugOutputCallback: source:[%X], type:[%X], id:[%X], message:[%s]\n", source, type, id, message);
gEngfuncs.Con_DPrintf("GL_DebugOutputCallback: source:[%X], type:[%X], id:[%X], message:[%s]\n", source, type, id, message);
}

void GL_Init(void)
Expand Down Expand Up @@ -1581,7 +1583,11 @@ void GL_Init(void)
//No vanilla detail texture support
(*detTexSupported) = false;

#ifdef _DEBUG
if (1)
#else
if (gEngfuncs.CheckParm("-gl_debugoutput", NULL))
#endif
{
glDebugMessageCallback(GL_DebugOutputCallback, 0);
glEnable(GL_DEBUG_OUTPUT);
Expand Down Expand Up @@ -2074,6 +2080,7 @@ void GL_EndRendering(void)
}
}

#if 0
void DLL_SetModKey(void *pinfo, char *pkey, char *pvalue)
{
gPrivateFuncs.DLL_SetModKey(pinfo, pkey, pvalue);
Expand All @@ -2083,6 +2090,7 @@ void DLL_SetModKey(void *pinfo, char *pkey, char *pvalue)
bVerticalFov = atoi(pvalue) ? true : false;
}
}
#endif

void R_InitCvars(void)
{
Expand Down Expand Up @@ -2183,7 +2191,7 @@ void R_InitCvars(void)

default_fov = gEngfuncs.pfnGetCvarPointer("default_fov");

r_vertical_fov = gEngfuncs.pfnRegisterVariable("r_vertical_fov", bVerticalFov ? "1" : "0", FCVAR_CLIENTDLL | FCVAR_ARCHIVE);
r_vertical_fov = gEngfuncs.pfnRegisterVariable("r_vertical_fov", (vertical_fov_SvEngine && (*vertical_fov_SvEngine)) ? "1" : "0", FCVAR_CLIENTDLL | FCVAR_ARCHIVE);

gl_widescreen_yfov = gEngfuncs.pfnGetCvarPointer("gl_widescreen_yfov");
if(!gl_widescreen_yfov)
Expand Down
4 changes: 2 additions & 2 deletions Plugins/Renderer/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void IPluginsV4::LoadEngine(cl_enginefunc_t *pEngfuncs)

R_FillAddress();
R_InstallHooks();
R_RedirectBlobEngineOpenGLTextures();
R_RedirectLegacyOpenGLTextureAllocation();
}

void IPluginsV4::LoadClient(cl_exportfuncs_t *pExportFunc)
Expand Down Expand Up @@ -113,7 +113,7 @@ void IPluginsV4::LoadClient(cl_exportfuncs_t *pExportFunc)
pExportFunc->HUD_PlayerMoveInit = HUD_PlayerMoveInit;
pExportFunc->V_CalcRefdef = V_CalcRefdef;

Uninstall_Hook(DLL_SetModKey);
//Uninstall_Hook(DLL_SetModKey);
}

void IPluginsV4::ExitGame(int iResult)
Expand Down
4 changes: 2 additions & 2 deletions Plugins/Renderer/privatehook.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ typedef struct
void(*triapi_RenderMode)(int mode);
void(*triapi_Color4f) (float r, float g, float b, float a);
void(__fastcall *enginesurface_drawFlushText)(void *pthis, int);
void(*DLL_SetModKey)(void *pinfo, char *pkey, char *pvalue);
//void(*DLL_SetModKey)(void *pinfo, char *pkey, char *pvalue);
void(*SCR_BeginLoadingPlaque)(qboolean reconnect);
qboolean(*Host_IsSinglePlayerGame)(void);
void *(*Hunk_AllocName)(int size, const char *name);
Expand Down Expand Up @@ -158,7 +158,7 @@ extern hook_t *g_phook_Mod_UnloadSpriteTextures;
extern hook_t *g_phook_triapi_RenderMode;
extern hook_t *g_phook_Draw_MiptexTexture;
extern hook_t *g_phook_BuildGammaTable;
extern hook_t *g_phook_DLL_SetModKey;
//extern hook_t *g_phook_DLL_SetModKey;

//extern hook_t *g_phook_studioapi_RestoreRenderer;
extern hook_t *g_phook_studioapi_StudioDynamicLight;
Expand Down

0 comments on commit 836c225

Please sign in to comment.