diff --git a/Plugins/Renderer/gl_hooks.cpp b/Plugins/Renderer/gl_hooks.cpp index 5137c87e..0337d16b 100644 --- a/Plugins/Renderer/gl_hooks.cpp +++ b/Plugins/Renderer/gl_hooks.cpp @@ -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; @@ -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 }; @@ -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; } diff --git a/Plugins/Renderer/gl_rmain.cpp b/Plugins/Renderer/gl_rmain.cpp index 26d6e1d6..1576e525 100644 --- a/Plugins/Renderer/gl_rmain.cpp +++ b/Plugins/Renderer/gl_rmain.cpp @@ -2314,6 +2314,7 @@ void R_NewMap(void) R_NewMapLight(); R_StudioFlushAllSkins(); + R_StudioClearVBOCache(); R_StudioReloadVBOCache(); //This is for GoldSrc diff --git a/Plugins/Renderer/gl_studio.cpp b/Plugins/Renderer/gl_studio.cpp index f9908c8f..85bd26b4 100644 --- a/Plugins/Renderer/gl_studio.cpp +++ b/Plugins/Renderer/gl_studio.cpp @@ -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]; @@ -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) @@ -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) { @@ -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) { @@ -989,7 +997,9 @@ void R_ShutdownStudio(void) { g_StudioProgramTable.clear(); - R_StudioBoneCaches_StartFrame(); + R_StudioClearAllBoneCaches(); + R_StudioFlushAllSkins(); + R_StudioClearVBOCache(); } void R_InitStudio(void) diff --git a/Plugins/Renderer/gl_studio.h b/Plugins/Renderer/gl_studio.h index ed0bfdd1..6f9b66e0 100644 --- a/Plugins/Renderer/gl_studio.h +++ b/Plugins/Renderer/gl_studio.h @@ -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); diff --git a/src/BlobThreadManager.cpp b/src/BlobThreadManager.cpp index c31687d7..c4129c29 100644 --- a/src/BlobThreadManager.cpp +++ b/src/BlobThreadManager.cpp @@ -181,6 +181,7 @@ BOOL WINAPI BlobCloseHandle(HANDLE hObject) BlobEnterCritSection(); bool bFoundAlive = BlobFindAndRemoveAliveThread(hObject); + bool bAdded = false; if (bFoundAlive) @@ -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) diff --git a/src/metahook.cpp b/src/metahook.cpp index 410061ab..bb031b44 100644 --- a/src/metahook.cpp +++ b/src/metahook.cpp @@ -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;