Skip to content

Commit

Permalink
Fix a bug that cache_head could not be found under engine 8684
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Dec 23, 2023
1 parent 1123d5c commit 1972ac6
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 5 deletions.
44 changes: 43 additions & 1 deletion Plugins/Renderer/gl_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5901,7 +5901,18 @@ void R_FillAddress(void)
{
cache_head = (decltype(cache_head))pinst->detail->x86.operands[1].imm;
}

else if (!cache_head &&
pinst->id == X86_INS_CMP &&
pinst->detail->x86.op_count == 2 &&
pinst->detail->x86.operands[0].type == X86_OP_MEM &&
(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 &&
(PUCHAR)pinst->detail->x86.operands[1].imm > (PUCHAR)g_dwEngineDataBase &&
(PUCHAR)pinst->detail->x86.operands[1].imm < (PUCHAR)g_dwEngineDataBase + g_dwEngineDataSize)
{
cache_head = (decltype(cache_head))pinst->detail->x86.operands[1].imm;
}
if (cache_head)
return TRUE;

Expand All @@ -5923,6 +5934,10 @@ void R_FillAddress(void)
{
int gfCustomBuild_instCount;
int push_0F_instCount;

PVOID gfCustomBuild_candidate;
int gfCustomBuild_candidate_reg;
int gfCustomBuild_candidate_instCount;
}Draw_MiptexTexture_ctx;

Draw_MiptexTexture_ctx ctx = { 0 };
Expand All @@ -5943,6 +5958,33 @@ void R_FillAddress(void)
pinst->detail->x86.operands[1].imm == 0 )
{
gfCustomBuild = (decltype(gfCustomBuild))pinst->detail->x86.operands[0].mem.disp;

ctx->gfCustomBuild_instCount = instCount;
}

if (!gfCustomBuild &&
pinst->id == X86_INS_MOV &&
pinst->detail->x86.op_count == 2 &&
pinst->detail->x86.operands[0].type == X86_OP_REG &&
pinst->detail->x86.operands[1].type == X86_OP_MEM &&
pinst->detail->x86.operands[1].mem.base == 0 &&
(PUCHAR)pinst->detail->x86.operands[1].mem.disp > (PUCHAR)g_dwEngineDataBase &&
(PUCHAR)pinst->detail->x86.operands[1].mem.disp < (PUCHAR)g_dwEngineDataBase + g_dwEngineDataSize)
{
ctx->gfCustomBuild_candidate = (decltype(ctx->gfCustomBuild_candidate))pinst->detail->x86.operands[1].mem.disp;
ctx->gfCustomBuild_candidate_reg = pinst->detail->x86.operands[0].reg;
ctx->gfCustomBuild_candidate_instCount = instCount;
}

if (!gfCustomBuild &&
instCount == ctx->gfCustomBuild_candidate_instCount + 1 &&
pinst->id == X86_INS_TEST &&
pinst->detail->x86.op_count == 2 &&
pinst->detail->x86.operands[0].type == X86_OP_REG &&
pinst->detail->x86.operands[1].type == X86_OP_REG &&
pinst->detail->x86.operands[0].reg == ctx->gfCustomBuild_candidate_reg)
{
gfCustomBuild = (decltype(gfCustomBuild))ctx->gfCustomBuild_candidate;
ctx->gfCustomBuild_instCount = instCount;
}

Expand Down
1 change: 1 addition & 0 deletions Plugins/Renderer/gl_rmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2314,6 +2314,7 @@ void R_NewMap(void)
R_NewMapLight();

R_StudioFlushAllSkins();
R_StudioClearVBOCache();
R_StudioReloadVBOCache();

//This is for GoldSrc
Expand Down
16 changes: 13 additions & 3 deletions Plugins/Renderer/gl_studio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ bool R_StudioHasHairShadow()
return r_draw_hashair && r_draw_hasface && r_studio_hair_shadow->value > 0 && !r_draw_shadowcaster;
}

void R_StudioBoneCaches_StartFrame()
void R_StudioClearAllBoneCaches()
{
for (int i = 0; i < MAX_STUDIO_BONE_CACHES - 1; i++)
g_StudioBoneCaches[i].m_next = &g_StudioBoneCaches[i + 1];
Expand All @@ -137,6 +137,11 @@ void R_StudioBoneCaches_StartFrame()
g_StudioBoneCacheManager.clear();
}

void R_StudioBoneCaches_StartFrame()
{
R_StudioClearAllBoneCaches();
}

studio_bone_cache* R_StudioBoneCacheAlloc()
{
if (!g_pStudioBoneFreeCaches)
Expand Down Expand Up @@ -397,7 +402,7 @@ studio_vbo_t* R_PrepareStudioVBO(studiohdr_t* studiohdr)
return VBOData;
}

void R_StudioReloadVBOCache(void)
void R_StudioClearVBOCache(void)
{
for (size_t i = 0; i < g_StudioVBOCache.size(); ++i)
{
Expand Down Expand Up @@ -431,7 +436,10 @@ void R_StudioReloadVBOCache(void)
g_StudioVBOCache[i] = NULL;
}
}
}

void R_StudioReloadVBOCache(void)
{
//Reload VBOCache for all existing models
for (int i = 0; i < EngineGetNumKnownModel(); ++i)
{
Expand Down Expand Up @@ -989,7 +997,9 @@ void R_ShutdownStudio(void)
{
g_StudioProgramTable.clear();

R_StudioBoneCaches_StartFrame();
R_StudioClearAllBoneCaches();
R_StudioFlushAllSkins();
R_StudioClearVBOCache();
}

void R_InitStudio(void)
Expand Down
1 change: 1 addition & 0 deletions Plugins/Renderer/gl_studio.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ extern MapConVar* r_studio_shade_specularpow;
void R_StudioBoneCaches_StartFrame();
studio_vbo_t *R_PrepareStudioVBO(studiohdr_t *studiohdr);
void R_StudioLoadExternalFile(model_t *mod, studiohdr_t *studiohdr, studio_vbo_t *VBOData);
void R_StudioClearVBOCache(void);
void R_StudioReloadVBOCache(void);
void R_StudioFlushAllSkins();
void R_ShutdownStudio(void);
Expand Down
9 changes: 9 additions & 0 deletions src/BlobThreadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ BOOL WINAPI BlobCloseHandle(HANDLE hObject)
BlobEnterCritSection();

bool bFoundAlive = BlobFindAndRemoveAliveThread(hObject);

bool bAdded = false;

if (bFoundAlive)
Expand Down Expand Up @@ -294,6 +295,14 @@ void BlobWaitForAliveThreadsToShutdown(void)
WaitForMultipleObjects(numThreads, hThreads, TRUE, INFINITE);

memset(g_hBlobAliveThread, 0, sizeof(g_hBlobAliveThread));

for (DWORD i = 0; i < numThreads; ++i)
{
if (hThreads[i])
{
CloseHandle(hThreads[i]);
}
}
}

void BlobWaitForClosedThreadsToShutdown(void)
Expand Down
7 changes: 6 additions & 1 deletion src/metahook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1908,8 +1908,13 @@ hook_t *MH_IATHook(HMODULE hModule, const char *pszModuleName, const char *pszFu

auto pThunk = (IMAGE_THUNK_DATA *)((ULONG_PTR)hModule + pImport->FirstThunk);

while (pThunk->u1.Function != dwFuncAddr)
while (pThunk->u1.Function != dwFuncAddr && pThunk->u1.Function)
{
pThunk++;
}

if(!pThunk->u1.Function)
return NULL;

tagIATDATA *info = new tagIATDATA;
info->pAPIInfoAddr = &pThunk->u1.Function;
Expand Down

0 comments on commit 1972ac6

Please sign in to comment.