From 6218d8eee724132b8e24f2d82411e6265c5dc0f3 Mon Sep 17 00:00:00 2001
From: hzqst <113660872@qq.com>
Date: Sat, 30 Dec 2023 21:28:39 +0800
Subject: [PATCH] Add cvar r_studio_viewmodel_lightdir_adjust
---
Plugins/Renderer/gl_draw.cpp | 66 ++++++++++++++++++++++++++++++++-
Plugins/Renderer/gl_hooks.cpp | 1 +
Plugins/Renderer/gl_studio.cpp | 17 ++++++---
Plugins/Renderer/gl_studio.h | 1 -
scripts/build-MetaHook-blob.bat | 3 +-
src/MetaHook.vcxproj | 1 -
6 files changed, 78 insertions(+), 11 deletions(-)
diff --git a/Plugins/Renderer/gl_draw.cpp b/Plugins/Renderer/gl_draw.cpp
index 533a1bb1..0d55bc96 100644
--- a/Plugins/Renderer/gl_draw.cpp
+++ b/Plugins/Renderer/gl_draw.cpp
@@ -2120,6 +2120,8 @@ bool LoadImageGenericRGBA8(const char *filename, byte* buf, size_t bufSize, FIBI
return true;
}
+#if 0
+
bool LoadImageGenericRGB8(const char* filename, byte* buf, size_t bufSize, FIBITMAP* fiB, gl_loadtexture_state_t* state)
{
size_t pos = 0;
@@ -2158,6 +2160,8 @@ bool LoadImageGenericRGB8(const char* filename, byte* buf, size_t bufSize, FIBIT
return true;
}
+#endif
+
bool LoadImagePaletteRGBA8(const char* filename, byte* buf, size_t bufSize, FIBITMAP* fiB, gl_loadtexture_state_t* state)
{
size_t pos = 0;
@@ -2197,6 +2201,8 @@ bool LoadImagePaletteRGBA8(const char* filename, byte* buf, size_t bufSize, FIBI
return true;
}
+#if 0
+
bool LoadImagePaletteRGB8(const char* filename, byte* buf, size_t bufSize, FIBITMAP* fiB, gl_loadtexture_state_t* state)
{
size_t pos = 0;
@@ -2236,6 +2242,8 @@ bool LoadImagePaletteRGB8(const char* filename, byte* buf, size_t bufSize, FIBIT
return true;
}
+#endif
+
bool LoadImageGeneric(const char *filename, const char* pathId, byte *buf, size_t bufSize, gl_loadtexture_state_t *state, bool throw_warning_on_missing)
{
FileHandle_t fileHandle = FILESYSTEM_ANY_OPEN(filename, "rb", pathId);
@@ -2328,14 +2336,34 @@ bool LoadImageGeneric(const char *filename, const char* pathId, byte *buf, size_
if (colorType == FIC_RGBALPHA)
{
- if (!LoadImageGenericRGBA8(filename, buf, bufSize, scopedBitmap.get(), state))
+ FIBITMAP* fiB32 = FreeImage_ConvertTo32Bits(scopedBitmap.get());
+
+ if (!fiB32)
+ {
+ gEngfuncs.Con_Printf("LoadImageGeneric: Could not load %s, FreeImage_ConvertTo32Bits failed.\n", filename);
+ return false;
+ }
+
+ CScopedFIBitmap scopedBitmap32(fiB32);
+
+ if (!LoadImageGenericRGBA8(filename, buf, bufSize, scopedBitmap32.get(), state))
{
return false;
}
}
else if (colorType == FIC_RGB)
{
- if (!LoadImageGenericRGBA8(filename, buf, bufSize, scopedBitmap.get(), state))
+ FIBITMAP* fiB24 = FreeImage_ConvertTo24Bits(scopedBitmap.get());
+
+ if (!fiB24)
+ {
+ gEngfuncs.Con_Printf("LoadImageGeneric: Could not load %s, FreeImage_ConvertTo24Bits failed.\n", filename);
+ return false;
+ }
+
+ CScopedFIBitmap scopedBitmap24(fiB24);
+
+ if (!LoadImageGenericRGBA8(filename, buf, bufSize, scopedBitmap24.get(), state))
{
return false;
}
@@ -2518,6 +2546,8 @@ void __fastcall enginesurface_drawSetTextureFile(void* pthis, int dummy, int tex
(const char*)texloader_buffer, state.width, state.height,
hardwareFilter, true);
+ (*currenttexture) = -1;
+ GL_Bind(textureId);
GL_UploadCompressedTexture(&state);
bLoaded = true;
@@ -2528,6 +2558,8 @@ void __fastcall enginesurface_drawSetTextureFile(void* pthis, int dummy, int tex
(const char *)texloader_buffer, state.width, state.height,
hardwareFilter, true);
+ (*currenttexture) = -1;
+ GL_Bind(textureId);
GL_UploadCompressedTexture(&state);
bLoaded = true;
@@ -2546,6 +2578,11 @@ void __fastcall enginesurface_drawSetTextureFile(void* pthis, int dummy, int tex
gPrivateFuncs.enginesurface_drawSetTextureRGBA(pthis, dummy, textureId,
(const char*)state.mipmaps[0].data, state.mipmaps[0].width, state.mipmaps[0].height,
hardwareFilter, true);
+
+ //(*currenttexture) = -1;
+ //GL_Bind(textureId);
+ //GL_UploadUncompressedTexture(&state);
+
bLoaded = true;
}
if (!bLoaded && LoadImageGeneric(filepath, NULL, texloader_buffer, sizeof(texloader_buffer), &state, false) && state.mipmaps.size() > 0)
@@ -2553,6 +2590,11 @@ void __fastcall enginesurface_drawSetTextureFile(void* pthis, int dummy, int tex
gPrivateFuncs.enginesurface_drawSetTextureRGBA(pthis, dummy, textureId,
(const char*)state.mipmaps[0].data, state.mipmaps[0].width, state.mipmaps[0].height,
hardwareFilter, true);
+
+ //(*currenttexture) = -1;
+ //GL_Bind(textureId);
+ //GL_UploadUncompressedTexture(&state);
+
bLoaded = true;
}
}
@@ -2569,6 +2611,11 @@ void __fastcall enginesurface_drawSetTextureFile(void* pthis, int dummy, int tex
gPrivateFuncs.enginesurface_drawSetTextureRGBA(pthis, dummy, textureId,
(const char*)state.mipmaps[0].data, state.mipmaps[0].width, state.mipmaps[0].height,
hardwareFilter, true);
+
+ //(*currenttexture) = -1;
+ //GL_Bind(textureId);
+ //GL_UploadUncompressedTexture(&state);
+
bLoaded = true;
}
if (!bLoaded && LoadImageGeneric(filepath, NULL, texloader_buffer, sizeof(texloader_buffer), &state, false) && state.mipmaps.size() > 0)
@@ -2576,6 +2623,11 @@ void __fastcall enginesurface_drawSetTextureFile(void* pthis, int dummy, int tex
gPrivateFuncs.enginesurface_drawSetTextureRGBA(pthis, dummy, textureId,
(const char*)state.mipmaps[0].data, state.mipmaps[0].width, state.mipmaps[0].height,
hardwareFilter, true);
+
+ //(*currenttexture) = -1;
+ //GL_Bind(textureId);
+ //GL_UploadUncompressedTexture(&state);
+
bLoaded = true;
}
}
@@ -2592,6 +2644,11 @@ void __fastcall enginesurface_drawSetTextureFile(void* pthis, int dummy, int tex
gPrivateFuncs.enginesurface_drawSetTextureRGBA(pthis, dummy, textureId,
(const char*)state.mipmaps[0].data, state.mipmaps[0].width, state.mipmaps[0].height,
hardwareFilter, true);
+
+ //(*currenttexture) = -1;
+ //GL_Bind(textureId);
+ //GL_UploadUncompressedTexture(&state);
+
bLoaded = true;
}
if (!bLoaded && LoadImageGeneric(filepath, NULL, texloader_buffer, sizeof(texloader_buffer), &state, false) && state.mipmaps.size() > 0)
@@ -2599,6 +2656,11 @@ void __fastcall enginesurface_drawSetTextureFile(void* pthis, int dummy, int tex
gPrivateFuncs.enginesurface_drawSetTextureRGBA(pthis, dummy, textureId,
(const char*)state.mipmaps[0].data, state.mipmaps[0].width, state.mipmaps[0].height,
hardwareFilter, true);
+
+ //(*currenttexture) = -1;
+ //GL_Bind(textureId);
+ //GL_UploadUncompressedTexture(&state);
+
bLoaded = true;
}
}
diff --git a/Plugins/Renderer/gl_hooks.cpp b/Plugins/Renderer/gl_hooks.cpp
index 73f912c2..67bc3c77 100644
--- a/Plugins/Renderer/gl_hooks.cpp
+++ b/Plugins/Renderer/gl_hooks.cpp
@@ -508,6 +508,7 @@ void R_FillAddress(void)
{
auto pString = (PCHAR)pinst->detail->x86.operands[0].imm;
if (!memcmp(pString, "Failed to query GL vendor", sizeof("Failed to query GL vendor") - 1) ||
+ !memcmp(pString, "Failed to query gl vendor", sizeof("Failed to query gl vendor") - 1) ||
!memcmp(pString, "GL_VENDOR: %s", sizeof("GL_VENDOR: %s") - 1))
{
ctx->bFoundPushString = true;
diff --git a/Plugins/Renderer/gl_studio.cpp b/Plugins/Renderer/gl_studio.cpp
index 30eeac51..152d9c25 100644
--- a/Plugins/Renderer/gl_studio.cpp
+++ b/Plugins/Renderer/gl_studio.cpp
@@ -81,6 +81,8 @@ cvar_t* r_studio_debug = NULL;
MapConVar* r_studio_base_specular = NULL;
MapConVar* r_studio_celshade_specular = NULL;
+cvar_t* r_studio_viewmodel_lightdir_adjust = NULL;
+
cvar_t* r_studio_celshade = NULL;
cvar_t* r_studio_celshade_midpoint = NULL;
cvar_t* r_studio_celshade_softness = NULL;
@@ -656,7 +658,6 @@ void R_UseStudioProgram(program_state_t state, studio_program_t* progOutput)
SHADER_UNIFORM(prog, r_hair_shadow_offset, "r_hair_shadow_offset");
SHADER_UNIFORM(prog, r_outline_dark, "r_outline_dark");
SHADER_UNIFORM(prog, r_uvscale, "r_uvscale");
- SHADER_UNIFORM(prog, entityPos, "entityPos");
}
g_StudioProgramTable[state] = prog;
@@ -670,11 +671,6 @@ void R_UseStudioProgram(program_state_t state, studio_program_t* progOutput)
{
GL_UseProgram(prog.program);
- if (prog.entityPos != -1)
- {
- glUniform3f(prog.entityPos, (*rotationmatrix)[0][3], (*rotationmatrix)[1][3], (*rotationmatrix)[2][3]);
- }
-
if (prog.r_base_specular != -1)
{
vec4_t values = { 0 };
@@ -1097,6 +1093,8 @@ void R_InitStudio(void)
{
r_studio_debug = gEngfuncs.pfnRegisterVariable("r_studio_debug", "0", FCVAR_CLIENTDLL);
+ r_studio_viewmodel_lightdir_adjust = gEngfuncs.pfnRegisterVariable("r_studio_viewmodel_lightdir_adjust", "0", FCVAR_ARCHIVE | FCVAR_CLIENTDLL);
+
r_studio_celshade = gEngfuncs.pfnRegisterVariable("r_studio_celshade", "1", FCVAR_ARCHIVE | FCVAR_CLIENTDLL);
r_studio_celshade_midpoint = gEngfuncs.pfnRegisterVariable("r_studio_celshade_midpoint", "-0.1", FCVAR_ARCHIVE | FCVAR_CLIENTDLL);
r_studio_celshade_softness = gEngfuncs.pfnRegisterVariable("r_studio_celshade_softness", "0.05", FCVAR_ARCHIVE | FCVAR_CLIENTDLL);
@@ -1657,6 +1655,13 @@ void R_StudioDrawVBOBegin(studio_vbo_t* VBOData)
memcpy(StudioUBO.r_plightvec, r_plightvec, sizeof(vec3_t));
+ if (r_draw_drawviewmodel && r_studio_viewmodel_lightdir_adjust->value > 0)
+ {
+ StudioUBO.r_plightvec[2] = StudioUBO.r_plightvec[2] * clamp(r_studio_viewmodel_lightdir_adjust->value, 0, 1);
+
+ VectorNormalize(StudioUBO.r_plightvec);
+ }
+
vec3_t entity_origin = { (*rotationmatrix)[0][3], (*rotationmatrix)[1][3], (*rotationmatrix)[2][3] };
memcpy(StudioUBO.entity_origin, entity_origin, sizeof(vec3_t));
diff --git a/Plugins/Renderer/gl_studio.h b/Plugins/Renderer/gl_studio.h
index ac120bd6..3ce629a9 100644
--- a/Plugins/Renderer/gl_studio.h
+++ b/Plugins/Renderer/gl_studio.h
@@ -43,7 +43,6 @@ typedef struct
int r_hair_specular_smooth;
int r_hair_shadow_offset;
int r_uvscale;
- int entityPos;
}studio_program_t;
typedef struct studio_vbo_vertex_s
diff --git a/scripts/build-MetaHook-blob.bat b/scripts/build-MetaHook-blob.bat
index 35d77ab4..de9e4dc1 100644
--- a/scripts/build-MetaHook-blob.bat
+++ b/scripts/build-MetaHook-blob.bat
@@ -20,4 +20,5 @@ if exist "%InstallDir%\Common7\Tools\vsdevcmd.bat" (
"%InstallDir%\Common7\Tools\vsdevcmd.bat"
MSBuild.exe MetaHook.sln "/target:MetaHook" /p:Configuration="Release_blob" /p:Platform="Win32"
-)
\ No newline at end of file
+)
+
diff --git a/src/MetaHook.vcxproj b/src/MetaHook.vcxproj
index ca7e9a8e..d2a16564 100644
--- a/src/MetaHook.vcxproj
+++ b/src/MetaHook.vcxproj
@@ -148,7 +148,6 @@
true
$(CapstoneLibrariesDirectory)
$(CapstoneLibraryFiles);ntdll.lib;%(AdditionalDependencies)
- false
$(ExePostBuildCommand)