diff --git a/Plugins/BulletPhysics/exportfuncs.cpp b/Plugins/BulletPhysics/exportfuncs.cpp index 57cd199e..b5dc4ed4 100644 --- a/Plugins/BulletPhysics/exportfuncs.cpp +++ b/Plugins/BulletPhysics/exportfuncs.cpp @@ -39,6 +39,7 @@ cvar_t *bv_ragdoll_sleepaftertime = NULL; cvar_t *bv_ragdoll_sleeplinearvel = NULL; cvar_t *bv_ragdoll_sleepangularvel = NULL; cvar_t *chase_active = NULL; +cvar_t* sv_cheats = NULL; const int RagdollRenderState_None = 0; const int RagdollRenderState_Monster = 1; @@ -57,6 +58,16 @@ cl_entity_t* r_worldentity = NULL; model_t* CounterStrike_RedirectPlayerModel(model_t* original_model, int PlayerNumber, int* modelindex); +bool AllowCheats() +{ + if (g_iEngineType == ENGINE_SVENGINE) + { + return (*allow_cheats) != 0; + } + + return (sv_cheats->value != 0) ? true : false; +} + typedef enum { ACT_RESET, @@ -1384,6 +1395,7 @@ void HUD_Init(void) bv_ragdoll_sleeplinearvel = gEngfuncs.pfnRegisterVariable("bv_ragdoll_sleeplinearvel", "5", FCVAR_CLIENTDLL | FCVAR_ARCHIVE); bv_ragdoll_sleepangularvel = gEngfuncs.pfnRegisterVariable("bv_ragdoll_sleepangularvel", "3", FCVAR_CLIENTDLL | FCVAR_ARCHIVE); + sv_cheats = gEngfuncs.pfnGetCvarPointer("sv_cheats"); chase_active = gEngfuncs.pfnGetCvarPointer("chase_active"); cl_minmodels = gEngfuncs.pfnGetCvarPointer("cl_minmodels"); cl_min_ct = gEngfuncs.pfnGetCvarPointer("cl_min_ct"); @@ -1573,7 +1585,10 @@ void HUD_DrawNormalTriangles(void) { gExportfuncs.HUD_DrawNormalTriangles(); - gPhysicsManager.DebugDraw(); + if (AllowCheats()) + { + gPhysicsManager.DebugDraw(); + } } void HUD_CreateEntities(void) diff --git a/Plugins/BulletPhysics/exportfuncs.h b/Plugins/BulletPhysics/exportfuncs.h index aa074ef4..42ba8f01 100644 --- a/Plugins/BulletPhysics/exportfuncs.h +++ b/Plugins/BulletPhysics/exportfuncs.h @@ -29,4 +29,5 @@ void HUD_Shutdown(void); void HUD_CreateEntities(void); msurface_t* GetWorldSurfaceByIndex(int index); -int GetWorldSurfaceIndex(msurface_t* surf); \ No newline at end of file +int GetWorldSurfaceIndex(msurface_t* surf); +bool AllowCheats(); \ No newline at end of file diff --git a/Plugins/BulletPhysics/privatehook.cpp b/Plugins/BulletPhysics/privatehook.cpp index 4bf3dc36..2ad7756c 100644 --- a/Plugins/BulletPhysics/privatehook.cpp +++ b/Plugins/BulletPhysics/privatehook.cpp @@ -43,6 +43,9 @@ void* mod_known = NULL; int* mod_numknown = NULL; TEMPENTITY* gTempEnts = NULL; +//Sven Co-op only +int* allow_cheats = NULL; + int* g_iUser1 = NULL; int* g_iUser2 = NULL; @@ -149,6 +152,41 @@ void Engine_FillAddreess(void) } } + if (g_iEngineType == ENGINE_SVENGINE) + { + auto CL_Set_ServerExtraInfo = g_pMetaHookAPI->FindCLParseFuncByName("svc_sendextrainfo"); + + Sig_VarNotFound(CL_Set_ServerExtraInfo); + + g_pMetaHookAPI->DisasmRanges(CL_Set_ServerExtraInfo, 0x100, [](void* inst, PUCHAR address, size_t instLen, int instCount, int depth, PVOID context) + { + auto pinst = (cs_insn*)inst; + + if (pinst->id == X86_INS_MOV && + pinst->detail->x86.op_count == 2 && + pinst->detail->x86.operands[0].type == X86_OP_MEM && + pinst->detail->x86.operands[1].type == X86_OP_REG && + pinst->detail->x86.operands[1].reg == X86_REG_EAX) + { + allow_cheats = (decltype(allow_cheats))pinst->detail->x86.operands[0].mem.disp; + } + + if (allow_cheats) + return TRUE; + + if (address[0] == 0xCC) + return TRUE; + + if (pinst->id == X86_INS_RET) + return TRUE; + + return FALSE; + + }, 0, NULL); + + Sig_VarNotFound(allow_cheats); + } + 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" diff --git a/Plugins/BulletPhysics/privatehook.h b/Plugins/BulletPhysics/privatehook.h index 2b792e95..4cd20f31 100644 --- a/Plugins/BulletPhysics/privatehook.h +++ b/Plugins/BulletPhysics/privatehook.h @@ -79,6 +79,8 @@ extern void *mod_known; extern int *mod_numknown; extern TEMPENTITY *gTempEnts; +extern int* allow_cheats; + extern int *g_iUser1; extern int *g_iUser2; diff --git a/Plugins/Renderer/exportfuncs.cpp b/Plugins/Renderer/exportfuncs.cpp index c53c8538..f6f2cc7a 100644 --- a/Plugins/Renderer/exportfuncs.cpp +++ b/Plugins/Renderer/exportfuncs.cpp @@ -103,192 +103,85 @@ void HUD_DrawTransparentTriangles(void) int HUD_Redraw(float time, int intermission) { //TODO - if(r_water_debug && r_water_debug->value > 0) + if (AllowCheats()) { - glDisable(GL_BLEND); - glDisable(GL_ALPHA_TEST); - glColor4f(1, 1, 1, 1); - - glEnable(GL_TEXTURE_2D); - switch ((int)r_water_debug->value) + if (r_water_debug && r_water_debug->value > 0) { - case 1: - if (g_WaterReflectCaches[0].reflectmap) - R_DrawHUDQuad_Texture(g_WaterReflectCaches[0].reflectmap, glwidth / 2, glheight / 2); - break; - case 2: - if (g_WaterReflectCaches[0].refractmap) - R_DrawHUDQuad_Texture(g_WaterReflectCaches[0].refractmap, glwidth / 2, glheight / 2); - break; - case 3: - if (g_WaterReflectCaches[1].reflectmap) - R_DrawHUDQuad_Texture(g_WaterReflectCaches[1].reflectmap, glwidth / 2, glheight / 2); - break; - case 4: - if (g_WaterReflectCaches[1].refractmap) - R_DrawHUDQuad_Texture(g_WaterReflectCaches[1].refractmap, glwidth / 2, glheight / 2); - break; - //case 3: - // R_DrawHUDQuad_Texture(g_LastPortalTextureId, glwidth / 2, glheight / 2); - // break; - default: - break; - } - } - else if(r_shadow_debug && r_shadow_debug->value && current_shadow_texture && current_shadow_texture->depth_stencil) - { - glDisable(GL_BLEND); - glDisable(GL_ALPHA_TEST); - glColor4f(1,1,1,1); - - glEnable(GL_TEXTURE_2D); - - GL_Bind(current_shadow_texture->depth_stencil); - - hud_debug_program_t prog = { 0 }; - R_UseHudDebugProgram(HUD_DEBUG_SHADOW, &prog); - - glBegin(GL_QUADS); - glTexCoord2f(0,1); - glVertex3f(0,0,0); - glTexCoord2f(1,1); - glVertex3f(glwidth/2,0,0); - glTexCoord2f(1,0); - glVertex3f(glwidth/2,glheight/2,0); - glTexCoord2f(0,0); - glVertex3f(0,glheight/2,0); - glEnd(); - - glEnable(GL_ALPHA_TEST); - glEnable(GL_BLEND); - GL_UseProgram(0); - } - else if(r_light_debug && r_light_debug->value) - { - glDisable(GL_BLEND); - glDisable(GL_ALPHA_TEST); - glColor4f(1,1,1,1); + glDisable(GL_BLEND); + glDisable(GL_ALPHA_TEST); + glColor4f(1, 1, 1, 1); - glDisable(GL_TEXTURE_2D); - glEnable(GL_TEXTURE_2D_ARRAY); + glEnable(GL_TEXTURE_2D); + switch ((int)r_water_debug->value) + { + case 1: + if (g_WaterReflectCaches[0].reflectmap) + R_DrawHUDQuad_Texture(g_WaterReflectCaches[0].reflectmap, glwidth / 2, glheight / 2); + break; + case 2: + if (g_WaterReflectCaches[0].refractmap) + R_DrawHUDQuad_Texture(g_WaterReflectCaches[0].refractmap, glwidth / 2, glheight / 2); + break; + case 3: + if (g_WaterReflectCaches[1].reflectmap) + R_DrawHUDQuad_Texture(g_WaterReflectCaches[1].reflectmap, glwidth / 2, glheight / 2); + break; + case 4: + if (g_WaterReflectCaches[1].refractmap) + R_DrawHUDQuad_Texture(g_WaterReflectCaches[1].refractmap, glwidth / 2, glheight / 2); + break; + //case 3: + // R_DrawHUDQuad_Texture(g_LastPortalTextureId, glwidth / 2, glheight / 2); + // break; + default: + break; + } + } + else if (r_shadow_debug && r_shadow_debug->value && current_shadow_texture && current_shadow_texture->depth_stencil) + { + glDisable(GL_BLEND); + glDisable(GL_ALPHA_TEST); + glColor4f(1, 1, 1, 1); - hud_debug_program_t prog = {0}; - R_UseHudDebugProgram(HUD_DEBUG_TEXARRAY, &prog); + glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D_ARRAY, s_GBufferFBO.s_hBackBufferTex); + GL_Bind(current_shadow_texture->depth_stencil); - if (prog.layer != -1) - glUniform1f(prog.layer, r_light_debug->value - 1); + hud_debug_program_t prog = { 0 }; + R_UseHudDebugProgram(HUD_DEBUG_SHADOW, &prog); - glBegin(GL_QUADS); - glTexCoord2f(0,1); - glVertex3f(0,0,0); - glTexCoord2f(1,1); - glVertex3f(glwidth/2,0,0); - glTexCoord2f(1,0); - glVertex3f(glwidth/2,glheight/2,0); - glTexCoord2f(0,0); - glVertex3f(0,glheight/2,0); - glEnd(); + glBegin(GL_QUADS); + glTexCoord2f(0, 1); + glVertex3f(0, 0, 0); + glTexCoord2f(1, 1); + glVertex3f(glwidth / 2, 0, 0); + glTexCoord2f(1, 0); + glVertex3f(glwidth / 2, glheight / 2, 0); + glTexCoord2f(0, 0); + glVertex3f(0, glheight / 2, 0); + glEnd(); - glEnable(GL_TEXTURE_2D); - glDisable(GL_TEXTURE_2D_ARRAY); + glEnable(GL_ALPHA_TEST); + glEnable(GL_BLEND); + GL_UseProgram(0); + } + else if (r_light_debug && r_light_debug->value) + { + glDisable(GL_BLEND); + glDisable(GL_ALPHA_TEST); + glColor4f(1, 1, 1, 1); - glEnable(GL_ALPHA_TEST); + glDisable(GL_TEXTURE_2D); + glEnable(GL_TEXTURE_2D_ARRAY); - GL_UseProgram(0); - } - else if(r_hdr_debug && r_hdr_debug->value) - { - glDisable(GL_BLEND); - glDisable(GL_ALPHA_TEST); - glColor4f(1,1,1,1); + hud_debug_program_t prog = { 0 }; + R_UseHudDebugProgram(HUD_DEBUG_TEXARRAY, &prog); - glEnable(GL_TEXTURE_2D); - FBO_Container_t *pFBO = NULL; - switch((int)r_hdr_debug->value) - { - case 1: - pFBO = &s_DownSampleFBO[0];break; - case 2: - pFBO = &s_DownSampleFBO[1];break; - case 3: - pFBO = &s_LuminFBO[0]; break; - case 4: - pFBO = &s_LuminFBO[1]; break; - case 5: - pFBO = &s_LuminFBO[2]; break; - case 6: - pFBO = &s_Lumin1x1FBO[0]; break; - case 7: - pFBO = &s_Lumin1x1FBO[1]; break; - case 8: - pFBO = &s_Lumin1x1FBO[2]; break; - case 9: - pFBO = &s_BrightPassFBO;break; - case 10: - pFBO = &s_BlurPassFBO[0][0];break; - case 11: - pFBO = &s_BlurPassFBO[0][1];break; - case 12: - pFBO = &s_BlurPassFBO[1][0];break; - case 13: - pFBO = &s_BlurPassFBO[1][1];break; - case 14: - pFBO = &s_BlurPassFBO[2][0];break; - case 15: - pFBO = &s_BlurPassFBO[2][1];break; - case 16: - pFBO = &s_BrightAccumFBO;break; - case 17: - pFBO = &s_ToneMapFBO;break; - case 18: - pFBO = &s_BackBufferFBO; break; - default: - break; - } + glBindTexture(GL_TEXTURE_2D_ARRAY, s_GBufferFBO.s_hBackBufferTex); - if(pFBO) - { - glBindTexture(GL_TEXTURE_2D, pFBO->s_hBackBufferTex); - glBegin(GL_QUADS); - glTexCoord2f(0,1); - glVertex3f(0,0,0); - glTexCoord2f(1,1); - glVertex3f(glwidth/2, 0,0); - glTexCoord2f(1,0); - glVertex3f(glwidth/2, glheight/2,0); - glTexCoord2f(0,0); - glVertex3f(0, glheight/2,0); - glEnd(); - } - } - else if (r_ssao_debug && r_ssao_debug->value) - { - glDisable(GL_BLEND); - glDisable(GL_ALPHA_TEST); - glColor4f(1, 1, 1, 1); - - glEnable(GL_TEXTURE_2D); - int texId = 0; - switch ((int)r_ssao_debug->value) - { - case 1: - //GL_UseProgram(drawdepth.program); - texId = s_BackBufferFBO.s_hBackBufferDepthTex; break; - case 2: - texId = s_DepthLinearFBO.s_hBackBufferTex; break; - case 3: - texId = s_HBAOCalcFBO.s_hBackBufferTex; break; - case 4: - texId = s_HBAOCalcFBO.s_hBackBufferTex2; break; - default: - break; - } + if (prog.layer != -1) + glUniform1f(prog.layer, r_light_debug->value - 1); - if (texId) - { - glBindTexture(GL_TEXTURE_2D, texId); glBegin(GL_QUADS); glTexCoord2f(0, 1); glVertex3f(0, 0, 0); @@ -300,9 +193,120 @@ int HUD_Redraw(float time, int intermission) glVertex3f(0, glheight / 2, 0); glEnd(); + glEnable(GL_TEXTURE_2D); + glDisable(GL_TEXTURE_2D_ARRAY); + + glEnable(GL_ALPHA_TEST); + GL_UseProgram(0); } + else if (r_hdr_debug && r_hdr_debug->value) + { + glDisable(GL_BLEND); + glDisable(GL_ALPHA_TEST); + glColor4f(1, 1, 1, 1); + + glEnable(GL_TEXTURE_2D); + FBO_Container_t* pFBO = NULL; + switch ((int)r_hdr_debug->value) + { + case 1: + pFBO = &s_DownSampleFBO[0]; break; + case 2: + pFBO = &s_DownSampleFBO[1]; break; + case 3: + pFBO = &s_LuminFBO[0]; break; + case 4: + pFBO = &s_LuminFBO[1]; break; + case 5: + pFBO = &s_LuminFBO[2]; break; + case 6: + pFBO = &s_Lumin1x1FBO[0]; break; + case 7: + pFBO = &s_Lumin1x1FBO[1]; break; + case 8: + pFBO = &s_Lumin1x1FBO[2]; break; + case 9: + pFBO = &s_BrightPassFBO; break; + case 10: + pFBO = &s_BlurPassFBO[0][0]; break; + case 11: + pFBO = &s_BlurPassFBO[0][1]; break; + case 12: + pFBO = &s_BlurPassFBO[1][0]; break; + case 13: + pFBO = &s_BlurPassFBO[1][1]; break; + case 14: + pFBO = &s_BlurPassFBO[2][0]; break; + case 15: + pFBO = &s_BlurPassFBO[2][1]; break; + case 16: + pFBO = &s_BrightAccumFBO; break; + case 17: + pFBO = &s_ToneMapFBO; break; + case 18: + pFBO = &s_BackBufferFBO; break; + default: + break; + } + + if (pFBO) + { + glBindTexture(GL_TEXTURE_2D, pFBO->s_hBackBufferTex); + glBegin(GL_QUADS); + glTexCoord2f(0, 1); + glVertex3f(0, 0, 0); + glTexCoord2f(1, 1); + glVertex3f(glwidth / 2, 0, 0); + glTexCoord2f(1, 0); + glVertex3f(glwidth / 2, glheight / 2, 0); + glTexCoord2f(0, 0); + glVertex3f(0, glheight / 2, 0); + glEnd(); + } + } + else if (r_ssao_debug && r_ssao_debug->value) + { + glDisable(GL_BLEND); + glDisable(GL_ALPHA_TEST); + glColor4f(1, 1, 1, 1); + + glEnable(GL_TEXTURE_2D); + int texId = 0; + switch ((int)r_ssao_debug->value) + { + case 1: + //GL_UseProgram(drawdepth.program); + texId = s_BackBufferFBO.s_hBackBufferDepthTex; break; + case 2: + texId = s_DepthLinearFBO.s_hBackBufferTex; break; + case 3: + texId = s_HBAOCalcFBO.s_hBackBufferTex; break; + case 4: + texId = s_HBAOCalcFBO.s_hBackBufferTex2; break; + default: + break; + } + + if (texId) + { + glBindTexture(GL_TEXTURE_2D, texId); + glBegin(GL_QUADS); + glTexCoord2f(0, 1); + glVertex3f(0, 0, 0); + glTexCoord2f(1, 1); + glVertex3f(glwidth / 2, 0, 0); + glTexCoord2f(1, 0); + glVertex3f(glwidth / 2, glheight / 2, 0); + glTexCoord2f(0, 0); + glVertex3f(0, glheight / 2, 0); + glEnd(); + + GL_UseProgram(0); + } + } } + return gExportfuncs.HUD_Redraw(time, intermission); } diff --git a/Plugins/Renderer/gl_hooks.cpp b/Plugins/Renderer/gl_hooks.cpp index 9d395691..26c89d40 100644 --- a/Plugins/Renderer/gl_hooks.cpp +++ b/Plugins/Renderer/gl_hooks.cpp @@ -4234,8 +4234,37 @@ void R_FillAddress(void) gDevOverview = (decltype(gDevOverview))ctx.Candidates[0]; Sig_VarNotFound(gDevOverview); + } + + if (g_iEngineType == ENGINE_SVENGINE) + { + g_pMetaHookAPI->DisasmRanges(gPrivateFuncs.CL_IsDevOverviewMode, 0x50, [](void* inst, PUCHAR address, size_t instLen, int instCount, int depth, PVOID context) + { + auto pinst = (cs_insn*)inst; + + if (pinst->id == X86_INS_CMP && + pinst->detail->x86.op_count == 2 && + pinst->detail->x86.operands[0].type == X86_OP_MEM && + pinst->detail->x86.operands[1].type == X86_OP_IMM && + pinst->detail->x86.operands[1].imm == 0) + { + allow_cheats = (decltype(allow_cheats))pinst->detail->x86.operands[0].mem.disp; + } + + if (allow_cheats) + return TRUE; + + if (address[0] == 0xCC) + return TRUE; + + if (pinst->id == X86_INS_RET) + return TRUE; + + return FALSE; + }, 0, NULL); + Sig_VarNotFound(allow_cheats); } if (1) diff --git a/Plugins/Renderer/gl_local.h b/Plugins/Renderer/gl_local.h index 87bb5c05..3dfdb535 100644 --- a/Plugins/Renderer/gl_local.h +++ b/Plugins/Renderer/gl_local.h @@ -191,6 +191,8 @@ extern bool* detTexSupported; extern cache_system_t(*cache_head); +extern int* allow_cheats; + extern int* allocated_textures; extern int glx; @@ -330,6 +332,7 @@ void R_RenderView_SvEngine(int a1); bool R_IsRenderingPortal(void); qboolean R_CullBox(vec3_t mins, vec3_t maxs); qboolean Host_IsSinglePlayerGame(); +bool AllowCheats(); void R_ForceCVars(qboolean mp); void R_NewMap(void); void GL_BuildLightmaps(void); diff --git a/Plugins/Renderer/gl_rmain.cpp b/Plugins/Renderer/gl_rmain.cpp index f437b8cd..90b212f3 100644 --- a/Plugins/Renderer/gl_rmain.cpp +++ b/Plugins/Renderer/gl_rmain.cpp @@ -131,7 +131,10 @@ bool* detTexSupported = NULL; cache_system_t(*cache_head) = NULL; -//blob engine only +//Sven Co-op only +int* allow_cheats = NULL; + +//Blob Engine only int* allocated_textures = NULL; //client dll @@ -217,7 +220,6 @@ FBO_Container_t *g_CurrentRenderingFBO = NULL; bool bNoStretchAspect = true; bool bUseBindless = true; bool bUseOITBlend = false; -//bool bVerticalFov = false; bool bUseLegacyTextureLoader = false; bool bHasOfficialFBOSupport = false; bool bHasOfficialGLTexAllocSupport = true; @@ -276,6 +278,7 @@ cvar_t *gl_fog = NULL; cvar_t *gl_wireframe = NULL; cvar_t *gl_ansio = NULL; cvar_t *developer = NULL; +cvar_t* sv_cheats = NULL; cvar_t *gl_round_down = NULL; cvar_t *gl_picmip = NULL; cvar_t *gl_max_size = NULL; @@ -318,6 +321,16 @@ qboolean Host_IsSinglePlayerGame() return gPrivateFuncs.Host_IsSinglePlayerGame(); } +bool AllowCheats() +{ + if (g_iEngineType == ENGINE_SVENGINE) + { + return (*allow_cheats) != 0; + } + + return (sv_cheats->value != 0) ? true : false; +} + /* Purpose : Check if the box specified by mins and maxs in world space can be culled by camera frustrum, return true on culled */ @@ -2368,6 +2381,8 @@ void R_InitCvars(void) developer = gEngfuncs.pfnGetCvarPointer("developer"); + sv_cheats = gEngfuncs.pfnGetCvarPointer("sv_cheats"); + gEngfuncs.Cvar_SetValue("r_detailtextures", 1); gl_ansio = gEngfuncs.pfnGetCvarPointer("gl_ansio"); @@ -2460,7 +2475,7 @@ void R_ForceCVars(qboolean mp) if (gPrivateFuncs.R_ForceCVars) return gPrivateFuncs.R_ForceCVars(mp); - //TODO implement this for 3266 + //TODO implement this for 3266, inlined ? } void R_AddReferencedTextures(std::set &textures)