Skip to content

Commit

Permalink
Add _external.txt support for sprites.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Feb 20, 2024
1 parent 61bbd0e commit f82fc54
Show file tree
Hide file tree
Showing 19 changed files with 481 additions and 73 deletions.
4 changes: 4 additions & 0 deletions Build/svencoop/sprites/radio_external.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"classname" "sprite_efx"
"flags" "EF_NOBLOOM"
}
4 changes: 4 additions & 0 deletions Build/svencoop/sprites/voiceicon_external.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"classname" "sprite_efx"
"flags" "EF_NOBLOOM"
}
10 changes: 4 additions & 6 deletions Plugins/Renderer/enginedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ typedef struct alight_s
#define EF_HITBOXCOLLISIONS 0x200 //! Use hitbox collisions
#define EF_FORCESKYLIGHT 0x400 //! Forces the model to be lit by skybox lighting

//Renderer specified flags for studio models
//Renderer specified flags added by hzqst
#define EF_OUTLINE 0x1000
#define EF_NOBLOOM 0x2000

#define kRenderFxDrawDeferedTransparentMeshes 0x80000000

Expand Down Expand Up @@ -432,16 +433,14 @@ typedef struct hull_s
int lastclipnode;
vec3_t clip_mins;
vec3_t clip_maxs;
}
hull_t;
}hull_t;

typedef struct mspriteframe_s
{
int width;
int height;
float up, down, left, right;
int gl_texturenum;
//int ssbo_index;//Added by hooking Hunk_Alloc
}mspriteframe_t;

typedef struct
Expand Down Expand Up @@ -469,8 +468,7 @@ typedef struct msprite_s
float beamlength;
void *cachespot;
mspriteframedesc_t frames[1];
}
msprite_t;
}msprite_t;

typedef struct
{
Expand Down
106 changes: 106 additions & 0 deletions Plugins/Renderer/gl_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@
#define MOD_UNLOADSPRITETEXTURES_HL25 "\x55\x8B\xEC\x81\xEC\x04\x01\x00\x00\xA1\x2A\x2A\x2A\x2A\x33\xC5\x89\x45\xFC\x57\x8B\x7D\x08\x83\x7F\x44\x01"
#define MOD_UNLOADSPRITETEXTURES_SVENGINE "\x81\xEC\x04\x01\x00\x00\xA1\x2A\x2A\x2A\x2A\x33\xC4\x89\x84\x24\x00\x01\x00\x00\x57\x8B\xBC\x24\x0C\x01\x00\x00"

#define MOD_LOADSPRITEMODEL_BLOB "\x53\x55\x56\x57\x8B\x7C\x24\x18\x8B\x47\x04\x50\xFF\x15"
#define MOD_LOADSPRITEMODEL_NEW2 MOD_LOADSPRITEMODEL_BLOB
#define MOD_LOADSPRITEMODEL_NEW "\x55\x8B\xEC\x51\x53\x56\x57\x8B\x7D\x0C\x8B\x47\x04\x50\xFF\x15"
#define MOD_LOADSPRITEMODEL_HL25 "\x55\x8B\xEC\x83\xEC\x08\x2A\x2A\x8B\x75\x0C\x2A\xFF\x2A\x04\xFF\x15"
#define MOD_LOADSPRITEMODEL_SVENGINE "\x83\xEC\x08\x2A\x2A\x2A\x8B\x2A\x24\x1C\x2A\xFF\x2A\x04\xFF\x15"

#define R_INITPARTICLETEXTURE_BLOB "\xA1\x2A\x2A\x2A\x2A\x81\xEC\x2A\x2A\x00\x00\x8B\xC8\x40"
#define R_INITPARTICLETEXTURE_COMMON "\x68\x01\x14\x00\x00\x68\x08\x19\x00\x00\x6A\x00\x6A\x08\x6A\x08"

Expand Down Expand Up @@ -2475,6 +2481,103 @@ void R_FillAddress(void)
}
Sig_FuncNotFound(Mod_UnloadSpriteTextures);

if (g_iEngineType == ENGINE_SVENGINE)
{
const char sigs1[] = "Sprite \"%s\" has wrong version number";
auto Sprite_String = Search_Pattern_Data(sigs1);
if (!Sprite_String)
Sprite_String = Search_Pattern_Rdata(sigs1);
if (Sprite_String)
{
char pattern[] = "\x68\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\x83\xC4";
*(DWORD*)(pattern + 1) = (DWORD)Sprite_String;
auto Sprite_PushString = (PUCHAR)Search_Pattern(pattern);
if (Sprite_PushString)
{
auto Sprite_Function = (PUCHAR)g_pMetaHookAPI->ReverseSearchFunctionBegin(Sprite_PushString, 0x100);
if (Sprite_Function)
{
gPrivateFuncs.Mod_LoadSpriteModel = (decltype(gPrivateFuncs.Mod_LoadSpriteModel))Sprite_Function;
}
}
}
}
else
{
const char sigs1[] = "Mod_LoadSpriteModel: Invalid # of frame";
auto Sprite_String = Search_Pattern_Data(sigs1);
if (!Sprite_String)
Sprite_String = Search_Pattern_Rdata(sigs1);
if (Sprite_String)
{
char pattern[] = "\x68\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\x83\xC4";
*(DWORD*)(pattern + 1) = (DWORD)Sprite_String;
auto Sprite_PushString = (PUCHAR)Search_Pattern(pattern);
if (Sprite_PushString)
{
auto Sprite_Function = (PUCHAR)g_pMetaHookAPI->ReverseSearchFunctionBegin(Sprite_PushString, 0x300);
if (Sprite_Function)
{
gPrivateFuncs.Mod_LoadSpriteModel = (decltype(gPrivateFuncs.Mod_LoadSpriteModel))Sprite_Function;
}
}
}
}

if (!gPrivateFuncs.Mod_LoadSpriteModel)
{
if (g_iEngineType == ENGINE_SVENGINE)
{
gPrivateFuncs.Mod_LoadSpriteModel = (decltype(gPrivateFuncs.Mod_LoadSpriteModel))Search_Pattern(MOD_LOADSPRITEMODEL_SVENGINE);
}
else if (g_iEngineType == ENGINE_GOLDSRC_HL25)
{
gPrivateFuncs.Mod_LoadSpriteModel = (decltype(gPrivateFuncs.Mod_LoadSpriteModel))Search_Pattern(MOD_LOADSPRITEMODEL_HL25);
}
else if (g_iEngineType == ENGINE_GOLDSRC)
{
gPrivateFuncs.Mod_LoadSpriteModel = (decltype(gPrivateFuncs.Mod_LoadSpriteModel))Search_Pattern(MOD_LOADSPRITEMODEL_NEW);
if (!gPrivateFuncs.Mod_LoadSpriteModel)
gPrivateFuncs.Mod_LoadSpriteModel = (decltype(gPrivateFuncs.Mod_LoadSpriteModel))Search_Pattern(MOD_LOADSPRITEMODEL_NEW2);
}
else if (g_iEngineType == ENGINE_GOLDSRC_BLOB)
{
gPrivateFuncs.Mod_LoadSpriteModel = (decltype(gPrivateFuncs.Mod_LoadSpriteModel))Search_Pattern(MOD_LOADSPRITEMODEL_BLOB);
}
}
Sig_FuncNotFound(Mod_LoadSpriteModel);

if (1)
{
const char pattern[] = "\xC7\x05\x2A\x2A\x2A\x2A\x00\x00\x00\x00\xE8";

PUCHAR SearchBegin = (PUCHAR)g_dwEngineTextBase;
PUCHAR SearchLimit = (PUCHAR)g_dwEngineTextBase + g_dwEngineTextSize;
while (SearchBegin < SearchLimit)
{
PUCHAR pFound = (PUCHAR)Search_Pattern_From_Size(SearchBegin, SearchLimit - SearchBegin, pattern);
if (pFound)
{
const char pattern2[] = "\x83\xC4\x2A\xC7\x05\x2A\x2A\x2A\x2A\x01\x00\x00\x00";
PUCHAR pFound2 = (PUCHAR)Search_Pattern_From_Size(pFound, 0x30, pattern2);
if (pFound2)
{
if (*(ULONG_PTR*)(pFound2 + 5) == *(ULONG_PTR*)(pFound + 2))
{
gSpriteMipMap = (decltype(gSpriteMipMap))*(ULONG_PTR*)(pFound + 2);
break;
}
}

SearchBegin = pFound + Sig_Length(pattern);
}
else
{
break;
}
}
}

//Engine's R_AddTEntity is not used anymore
if (g_iEngineType == ENGINE_SVENGINE)
{
Expand Down Expand Up @@ -7448,6 +7551,7 @@ static hook_t *g_phook_enginesurface_drawSetTextureFile = NULL;
static hook_t *g_phook_enginesurface_drawFlushText = NULL;
static hook_t *g_phook_Mod_LoadStudioModel = NULL;
static hook_t *g_phook_Mod_LoadBrushModel = NULL;
static hook_t *g_phook_Mod_LoadSpriteModel = NULL;
static hook_t *g_phook_Mod_UnloadSpriteTextures = NULL;
static hook_t *g_phook_triapi_RenderMode = NULL;
static hook_t *g_phook_triapi_BoxInPVS = NULL;
Expand Down Expand Up @@ -7491,6 +7595,7 @@ void R_UninstallHooksForEngineDLL(void)
Uninstall_Hook(enginesurface_drawSetTextureFile);
Uninstall_Hook(enginesurface_drawFlushText);
Uninstall_Hook(Mod_LoadStudioModel);
Uninstall_Hook(Mod_LoadSpriteModel);
Uninstall_Hook(Mod_UnloadSpriteTextures);
Uninstall_Hook(triapi_RenderMode);
Uninstall_Hook(triapi_BoxInPVS);
Expand Down Expand Up @@ -7537,6 +7642,7 @@ void R_InstallHooks(void)
Install_InlineHook(enginesurface_drawSetTextureFile);
Install_InlineHook(enginesurface_drawFlushText);
Install_InlineHook(Mod_LoadStudioModel);
Install_InlineHook(Mod_LoadSpriteModel);
Install_InlineHook(Mod_UnloadSpriteTextures);
Install_InlineHook(triapi_RenderMode);
Install_InlineHook(triapi_BoxInPVS);
Expand Down
65 changes: 39 additions & 26 deletions Plugins/Renderer/gl_hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,19 +409,20 @@ void GL_BlitFrameBufferToFrameBufferDepthStencil(FBO_Container_t* src, FBO_Conta
}

/*
Purpose: Do downsample from src FBO to dst, the current rendering FBO is set to dst
Purpose: Down sample from src_color to dst, the current rendering FBO is set to dst
*/
void R_DownSample(FBO_Container_t *src, FBO_Container_t *dst, qboolean filter2x2)
void R_DownSample(FBO_Container_t *src_color, FBO_Container_t* src_stencil, FBO_Container_t *dst, bool bUseFilter2x2, bool bUseStencilFilter)
{
GL_BindFrameBuffer(dst);

glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
vec4_t vecClearColor = { 0, 0, 0, 0 };
GL_ClearColor(vecClearColor);
GL_ClearStencil(0xFF);

if(filter2x2)
if(bUseFilter2x2)
{
GL_UseProgram(pp_downsample2x2.program);
glUniform2f(pp_downsample2x2.texelsize, 2.0f / src->iWidth, 2.0f / src->iHeight);
glUniform2f(pp_downsample2x2.texelsize, 2.0f / src_color->iWidth, 2.0f / src_color->iHeight);
}
else
{
Expand All @@ -430,17 +431,29 @@ void R_DownSample(FBO_Container_t *src, FBO_Container_t *dst, qboolean filter2x2

glViewport(glx, gly, dst->iWidth, dst->iHeight);

GL_Bind(src->s_hBackBufferTex);
GL_Bind(src_color->s_hBackBufferTex);

glDrawArrays(GL_TRIANGLES, 0, 3);
if (bUseStencilFilter && src_stencil)
{
GL_BlitFrameBufferToFrameBufferStencilOnly(src_stencil, dst);
GL_BeginStencilCompareNotEqual(STENCIL_MASK_NO_BLOOM, STENCIL_MASK_NO_BLOOM);

glDrawArrays(GL_TRIANGLES, 0, 3);

GL_EndStencil();
}
else
{
glDrawArrays(GL_TRIANGLES, 0, 3);
}
}

void R_LuminPass(FBO_Container_t *src, FBO_Container_t *dst, int type)
{
GL_BindFrameBuffer(dst);

glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
vec4_t vecClearColor = { 0, 0, 0, 0 };
GL_ClearColor(vecClearColor);

if(type == LUMPASS_LOG)
{
Expand Down Expand Up @@ -469,8 +482,8 @@ void R_LuminAdaptation(FBO_Container_t *src, FBO_Container_t *dst, FBO_Container
{
GL_BindFrameBuffer(dst);

glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
vec4_t vecClearColor = { 0, 0, 0, 0 };
GL_ClearColor(vecClearColor);

GL_UseProgram(pp_luminadapt.program);
glUniform1f(pp_luminadapt.frametime, frametime * math_clamp(r_hdr_adaptation->GetValue(), 0.1, 100));
Expand All @@ -492,8 +505,8 @@ void R_BrightPass(FBO_Container_t *src, FBO_Container_t *dst, FBO_Container_t *l
{
GL_BindFrameBuffer(dst);

glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
vec4_t vecClearColor = { 0, 0, 0, 0 };
GL_ClearColor(vecClearColor);

GL_UseProgram(pp_brightpass.program);
glUniform1i(pp_brightpass.baseTex, 0);
Expand All @@ -516,8 +529,8 @@ void R_BlurPass(FBO_Container_t *src, FBO_Container_t *dst, qboolean vertical)
{
GL_BindFrameBuffer(dst);

glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
vec4_t vecClearColor = { 0, 0, 0, 0 };
GL_ClearColor(vecClearColor);

if(vertical)
{
Expand All @@ -541,8 +554,8 @@ void R_BrightAccum(FBO_Container_t *blur1, FBO_Container_t *blur2, FBO_Container
{
GL_BindFrameBuffer(dst);

glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
vec4_t vecClearColor = { 0, 0, 0, 0 };
GL_ClearColor(vecClearColor);

glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
Expand All @@ -567,8 +580,8 @@ void R_ToneMapping(FBO_Container_t *src, FBO_Container_t *dst, FBO_Container_t *
{
GL_BindFrameBuffer(dst);

glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
vec4_t vecClearColor = { 0, 0, 0, 0 };
GL_ClearColor(vecClearColor);

GL_UseProgram(pp_tonemap.program);
glUniform1i(pp_tonemap.baseTex, 0);
Expand Down Expand Up @@ -615,7 +628,7 @@ bool R_IsHDREnabled(void)
return true;
}

void R_HDR(FBO_Container_t* src, FBO_Container_t* dst)
void R_HDR(FBO_Container_t* src_color, FBO_Container_t* src_stencil, FBO_Container_t* dst)
{
GL_BeginProfile(&Profile_DoHDR);

Expand All @@ -626,8 +639,8 @@ void R_HDR(FBO_Container_t* src, FBO_Container_t* dst)
glDisable(GL_BLEND);
glColor4f(1, 1, 1, 1);

R_DownSample(src, &s_DownSampleFBO[0], false);//(1->1/4)
R_DownSample(&s_DownSampleFBO[0], &s_DownSampleFBO[1], false);//(1/4)->(1/16)
R_DownSample(src_color, src_stencil, &s_DownSampleFBO[0], true, true);//(1->1/4)
R_DownSample(&s_DownSampleFBO[0], NULL, &s_DownSampleFBO[1], true, false);//(1/4)->(1/16)

//Log Luminance DownSample from .. (RGB16F to R32F)
R_LuminPass(&s_DownSampleFBO[1], &s_LuminFBO[0], LUMPASS_LOG);//(1/16)->64x64
Expand All @@ -640,7 +653,7 @@ void R_HDR(FBO_Container_t* src, FBO_Container_t* dst)
R_LuminPass(&s_LuminFBO[2], &s_Lumin1x1FBO[2], LUMPASS_EXP);//4x4->1x1

//Luminance Adaptation
R_LuminAdaptation(&s_Lumin1x1FBO[2], &s_Lumin1x1FBO[!last_luminance], &s_Lumin1x1FBO[last_luminance], *cl_time - *cl_oldtime);
R_LuminAdaptation(&s_Lumin1x1FBO[2], &s_Lumin1x1FBO[!last_luminance], &s_Lumin1x1FBO[last_luminance], (*cl_time) - (*cl_oldtime));
last_luminance = !last_luminance;

//Bright Pass (with 1/16)
Expand All @@ -660,7 +673,7 @@ void R_HDR(FBO_Container_t* src, FBO_Container_t* dst)
R_BrightAccum(&s_BlurPassFBO[0][1], &s_BlurPassFBO[1][1], &s_BlurPassFBO[2][1], &s_BrightAccumFBO);

//Tone mapping
R_ToneMapping(src, &s_ToneMapFBO, &s_BrightAccumFBO, &s_Lumin1x1FBO[last_luminance]);
R_ToneMapping(src_color, &s_ToneMapFBO, &s_BrightAccumFBO, &s_Lumin1x1FBO[last_luminance]);

GL_UseProgram(0);

Expand Down Expand Up @@ -1033,7 +1046,7 @@ void R_AmbientOcclusion(FBO_Container_t* src, FBO_Container_t* dst)
glBlendFunc(GL_ZERO, GL_SRC_COLOR);

//Only draw on brush surfaces
GL_BeginStencilCompareEqual(STENCIL_MASK_WORLD, STENCIL_MASK_WORLD | STENCIL_MASK_WATER | STENCIL_MASK_STUDIO_MODEL | STENCIL_MASK_SPRITE_MODEL);
GL_BeginStencilCompareEqual(STENCIL_MASK_WORLD, STENCIL_MASK_WORLD | STENCIL_MASK_WATER | STENCIL_MASK_STUDIO_MODEL);

GL_UseProgram(hbao_blur2.program);

Expand Down
2 changes: 1 addition & 1 deletion Plugins/Renderer/gl_hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ bool R_IsGammaBlendEnabled();
void R_GammaCorrection(FBO_Container_t* src, FBO_Container_t* dst);
void R_GammaUncorrection(FBO_Container_t* src, FBO_Container_t* dst);
bool R_IsAmbientOcclusionEnabled(void);
void R_HDR(FBO_Container_t* src, FBO_Container_t*);
void R_HDR(FBO_Container_t* src_color, FBO_Container_t* src_stencil, FBO_Container_t*);
bool R_IsHDREnabled(void);
void R_FXAA(FBO_Container_t* src, FBO_Container_t* dst);
bool R_IsFXAAEnabled(void);
Expand Down
9 changes: 7 additions & 2 deletions Plugins/Renderer/gl_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ extern int *c_brush_polys;
extern int(*rtable)[20][20];
extern void *tmp_palette;

extern int* gSpriteMipMap;

//fog
extern int *g_bUserFogOn;
extern float *g_UserFogColor;
Expand Down Expand Up @@ -475,6 +477,9 @@ void R_FreeBindlessTexturesForSkybox();
void R_SaveProgramStates_f(void);
void R_LoadProgramStates_f(void);

void R_LoadLegacyOpenGLMatrixForViewModel();
void R_LoadLegacyOpenGLMatrixForWorld();

void COM_FileBase(const char *in, char *out);

//framebuffer
Expand Down Expand Up @@ -579,10 +584,10 @@ extern bool g_bIsCounterStrike;
#define STENCIL_MASK_WORLD 1
#define STENCIL_MASK_WATER 2
#define STENCIL_MASK_STUDIO_MODEL 4
#define STENCIL_MASK_SPRITE_MODEL 8
#define STENCIL_MASK_NO_BLOOM 8
#define STENCIL_MASK_HAS_OUTLINE 0x10
#define STENCIL_MASK_HAS_SHADOW 0x20
#define STENCIL_MASK_HAS_DECAL 0x40
#define STENCIL_MASK_HAS_FLATSHADE 0x80

#define STENCIL_MASK_HAS_FOG (STENCIL_MASK_WORLD | STENCIL_MASK_WATER | STENCIL_MASK_STUDIO_MODEL | STENCIL_MASK_SPRITE_MODEL)
#define STENCIL_MASK_HAS_FOG (STENCIL_MASK_WORLD | STENCIL_MASK_WATER | STENCIL_MASK_STUDIO_MODEL)
Loading

0 comments on commit f82fc54

Please sign in to comment.