Skip to content

Commit

Permalink
Fix a bug that SubtitlePanel's round corners were broken while loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Sep 17, 2023
1 parent 4d10284 commit 093efb7
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Plugins/CaptionMod/CaptionMod.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<ClCompile>
<AdditionalOptions>/MP %(AdditionalOptions)</AdditionalOptions>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>.\;..\;..\..\;..\..\HLSDK\cl_dll;..\..\HLSDK\common;..\..\HLSDK\engine;..\..\HLSDK\pm_shared;..\..\HLSDK\public;..\..\Interface;.\SourceSDK;.\VGUI;.\vgui_controls;.\SourceSDK\tier0;.\SourceSDK\tier1;.\SourceSDK\vstdlib;..\..\SteamSDK\;..\..\capstone\include\capstone\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.\;..\;..\..\;..\..\HLSDK\cl_dll;..\..\HLSDK\common;..\..\HLSDK\engine;..\..\HLSDK\pm_shared;..\..\HLSDK\public;..\..\Interface;.\SourceSDK;.\VGUI;.\vgui_controls;.\SourceSDK\tier0;.\SourceSDK\tier1;.\SourceSDK\vstdlib;..\..\SteamSDK\;..\..\capstone\include\capstone\;..\..\glew\include\GL;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;STEAM_API_NODLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>Async</ExceptionHandling>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
Expand All @@ -90,7 +90,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>OpenGL32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>if exist "$(MetaHookGameDirectory)" copy "$(OutDir)$(TargetName)$(TargetExt)" "$(MetaHookGameDirectory)$(MetaHookModName)\metahook\plugins\"</Command>
Expand Down
10 changes: 10 additions & 0 deletions Plugins/CaptionMod/SubtitlePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <KeyValues.h>
#include <FileSystem.h>

#include <glew.h>

#include "SubtitlePanel.h"
#include "privatefuncs.h"

Expand Down Expand Up @@ -585,6 +587,9 @@ void SubtitlePanel::VidInit(void)

void SubtitlePanel::Paint(void)
{
//if (SCR_IsLoadingVisible())
// return;

int x;

int iPanelWidth, iPanelHeight;
Expand Down Expand Up @@ -672,6 +677,11 @@ void SubtitlePanel::PaintBackground(void)
if(h <= 0)
return;

//if (SCR_IsLoadingVisible())
// return;

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

//Cornor is maximum at 1/4 wide or tall
r = min(min(m_iScaledCornorSize, h / 4), w / 4);

Expand Down
48 changes: 48 additions & 0 deletions Plugins/CaptionMod/privatefuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#define S_STARTSTATICSOUND_SIG "\x83\xEC\x44\x53\x55\x8B\x6C\x24\x58\x56\x85\xED\x57"
#define S_LOADSOUND_SIG "\x81\xEC\x2A\x2A\x00\x00\x53\x8B\x9C\x24\x2A\x2A\x00\x00\x55\x56\x8A\x03\x57"

#define SCR_BEGIN_LOADING_PLAQUE "\x6A\x01\xE8\x2A\x2A\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x83\xC4\x04\x83\xF8\x03"

double *cl_time = NULL;
double *cl_oldtime = NULL;

Expand All @@ -36,6 +38,8 @@ vec3_t *listener_origin = NULL;

char (*s_pBaseDir)[512] = NULL;

qboolean* scr_drawloading = NULL;

char m_szCurrentLanguage[128] = { 0 };

private_funcs_t gPrivateFuncs = {0};
Expand All @@ -58,6 +62,11 @@ PVOID VGUIClient001_CreateInterface(HINTERFACEMODULE hModule)
return Sys_GetFactory(hModule);
}

bool SCR_IsLoadingVisible()
{
return scr_drawloading && (*scr_drawloading) == 1 ? true : false;
}

void Engine_FillAddress(void)
{
if (g_iEngineType == ENGINE_SVENGINE)
Expand Down Expand Up @@ -121,6 +130,45 @@ void Engine_FillAddress(void)
Sig_FuncNotFound(S_LoadSound);
}

gPrivateFuncs.SCR_BeginLoadingPlaque = (decltype(gPrivateFuncs.SCR_BeginLoadingPlaque))Search_Pattern(SCR_BEGIN_LOADING_PLAQUE);
Sig_FuncNotFound(SCR_BeginLoadingPlaque);

if (1)
{
g_pMetaHookAPI->DisasmRanges(gPrivateFuncs.SCR_BeginLoadingPlaque, 0x100, [](void* inst, PUCHAR address, size_t instLen, int instCount, int depth, PVOID context) {
auto pinst = (cs_insn*)inst;

if (!scr_drawloading &&
pinst->id == X86_INS_MOV &&
pinst->detail->x86.op_count == 2 &&
pinst->detail->x86.operands[0].type == X86_OP_MEM &&
pinst->detail->x86.operands[0].mem.base == 0 &&
pinst->detail->x86.operands[0].mem.index == 0 &&
(PUCHAR)pinst->detail->x86.operands[0].mem.disp > (PUCHAR)g_dwEngineDataBase &&
(PUCHAR)pinst->detail->x86.operands[0].mem.disp < (PUCHAR)g_dwEngineDataBase + g_dwEngineDataSize &&
pinst->detail->x86.operands[1].type == X86_OP_IMM &&
pinst->detail->x86.operands[1].imm == 1)
{
//C7 05 60 66 00 08 01 00 00 00 mov scr_drawloading, 1
scr_drawloading = (decltype(scr_drawloading))pinst->detail->x86.operands[0].mem.disp;
}

if (scr_drawloading)
return TRUE;

if (address[0] == 0xCC)
return TRUE;

if (pinst->id == X86_INS_RET)
return TRUE;

return FALSE;
}, 0, NULL);

Sig_VarNotFound(scr_drawloading);
}


if (g_iEngineType == ENGINE_SVENGINE)
{
#define CL_VIEWENTITY_SIG_SVENGINE "\x68\x2A\x2A\x2A\x2A\x50\x6A\x06\xFF\x35\x2A\x2A\x2A\x2A\xE8"
Expand Down
11 changes: 7 additions & 4 deletions Plugins/CaptionMod/privatefuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ typedef struct

int(*FileSystem_SetGameDirectory)(const char *pDefaultDir, const char *pGameDir);

//vgui2
char *(*V_strncpy)(char *a1, const char *a2, size_t a3);

//Engine Sound

void (*S_Init)(void);
sfx_t *(*S_FindName)(char *name, int *pfInCache);//hooked
void (*S_StartDynamicSound)(int entnum, int entchannel, sfx_t *sfx, float *origin, float fvol, float attenuation, int flags, int pitch);//hooked
Expand Down Expand Up @@ -59,7 +55,12 @@ typedef struct
//VGUI1
void (__fastcall *vgui_TextImage_paint)(vgui1_TextImage *pthis, int, void *panel);

//VGUI2
char* (*V_strncpy)(char* a1, const char* a2, size_t a3);

//Engine
void(*SCR_BeginLoadingPlaque)(qboolean reconnect);

client_textmessage_t *(*pfnTextMessageGet)(const char *pName);

void(*MessageMode_f)(void);
Expand Down Expand Up @@ -103,3 +104,5 @@ extern char m_szCurrentLanguage[128];
extern private_funcs_t gPrivateFuncs;

cl_entity_t *EngineGetViewEntity(void);

bool SCR_IsLoadingVisible();

0 comments on commit 093efb7

Please sign in to comment.