improve stream safety

This commit is contained in:
TotallyNotElite 2019-06-10 14:46:43 +02:00
parent 9cd64d810f
commit 7e1dde5067
5 changed files with 53 additions and 7 deletions

View File

@ -29,9 +29,10 @@ set(Game "tf2" CACHE STRING "Target game")
set(GameValues "tf2;hl2dm;dab;tf2c;css;dynamic" CACHE INTERNAL "List of supported game types")
set_property(CACHE Game PROPERTY STRINGS ${GameValues})
set(DrawType "IMGUI" CACHE STRING "Target drawing api")
set(Visuals_DrawType "IMGUI" CACHE STRING "Target drawing api")
set(DrawTypes "No Visuals;Glez;Engine;IMGUI;IMGUI Streamproof" CACHE INTERNAL "Select the drawing api that cathook should use")
set_property(CACHE DrawType PROPERTY STRINGS ${DrawTypes})
set_property(CACHE Visuals_DrawType PROPERTY STRINGS ${DrawTypes})
set(Visuals_EnforceStreamSafety 1 CACHE BOOL "If a streamsafe drawing method is used, this will remove features that are not streamsafe.")
set(EnableVisuals 0)
set(EnableGlezDrawing 0)
@ -39,19 +40,25 @@ set(EnableEngineDrawing 0)
set(EnableImGuiDrawing 0)
set(ExternalDrawing 0)
if(NOT DrawType STREQUAL "No Visuals")
if(NOT Visuals_DrawType STREQUAL "No Visuals")
set(EnableVisuals 1)
endif()
if(DrawType STREQUAL "Glez")
if(Visuals_DrawType STREQUAL "Glez")
set(EnableGlezDrawing 1)
elseif(DrawType STREQUAL "Engine")
elseif(Visuals_DrawType STREQUAL "Engine")
set(EnableEngineDrawing 1)
elseif(DrawType STREQUAL "IMGUI")
elseif(Visuals_DrawType STREQUAL "IMGUI")
set(EnableImGuiDrawing 1)
elseif(DrawType STREQUAL "IMGUI Streamproof")
elseif(Visuals_DrawType STREQUAL "IMGUI Streamproof")
set(EnableImGuiDrawing 1)
set(ExternalDrawing 1)
endif()
if (NOT ExternalDrawing)
set(Visuals_ForceStreamSafety 0)
endif()
message(${Visuals_ForceStreamSafety})
set(EnableUnityBuilds 1 CACHE BOOL "Enable Profiler")
set(EnableProfiler 0 CACHE BOOL "Enable Profiler")

View File

@ -22,3 +22,4 @@
#define ENABLE_ENGINE_DRAWING @EnableEngineDrawing@
#define ENABLE_IMGUI_DRAWING @EnableImGuiDrawing@
#define EXTERNAL_DRAWING @ExternalDrawing@
#define ENFORCE_STREAM_SAFETY @Visuals_EnforceStreamSafety@

View File

@ -33,6 +33,7 @@ static ChIRC::ChIRC irc;
void printmsg(std::string &usr, std::string &msg)
{
#if !ENFORCE_STREAM_SAFETY
if (msg.size() > 256 || usr.size() > 256)
{
logging::Info("IRC: Message too large.");
@ -42,6 +43,7 @@ void printmsg(std::string &usr, std::string &msg)
logging::Info("[IRC] %s: %s", usr.c_str(), msg.c_str());
else
PrintChat("\x07%06X[IRC] %s\x01: %s", 0xe05938, usr.c_str(), msg.c_str());
#endif
}
void printmsgcopy(std::string usr, std::string msg)
{

View File

@ -38,6 +38,7 @@ CatCommand fix_black_chams("fix_black_chams", "Fix Black Chams", []() {
void EffectChams::Init()
{
#if !ENFORCE_STREAM_SAFETY
if (init)
return;
logging::Info("Init EffectChams...");
@ -69,20 +70,25 @@ void EffectChams::Init()
}
logging::Info("Init done!");
init = true;
#endif
}
void EffectChams::BeginRenderChams()
{
#if !ENFORCE_STREAM_SAFETY
drawing = true;
CMatRenderContextPtr ptr(GET_RENDER_CONTEXT);
g_IVRenderView->SetBlend(1.0f);
#endif
}
void EffectChams::EndRenderChams()
{
#if !ENFORCE_STREAM_SAFETY
drawing = false;
CMatRenderContextPtr ptr(GET_RENDER_CONTEXT);
g_IVModelRender->ForcedMaterialOverride(nullptr);
#endif
}
static rgba_t data[33] = { colors::empty };
void EffectChams::SetEntityColor(CachedEntity *ent, rgba_t color)
@ -203,6 +209,9 @@ rgba_t EffectChams::ChamsColor(IClientEntity *entity)
bool EffectChams::ShouldRenderChams(IClientEntity *entity)
{
#if ENFORCE_STREAM_SAFETY
return false;
#endif
if (!isHackActive() || !*effect_chams::enable || CE_BAD(LOCAL_E))
return false;
if (entity->entindex() < 0)
@ -262,6 +271,7 @@ bool EffectChams::ShouldRenderChams(IClientEntity *entity)
void EffectChams::RenderChamsRecursive(IClientEntity *entity)
{
#if !ENFORCE_STREAM_SAFETY
if (!isHackActive() || !*effect_chams::enable)
return;
entity->DrawModel(1);
@ -297,10 +307,12 @@ void EffectChams::RenderChamsRecursive(IClientEntity *entity)
}
attach = g_IEntityList->GetClientEntity(*(int *) ((uintptr_t) attach + netvar.m_Collision - 20) & 0xFFF);
}
#endif
}
void EffectChams::RenderChams(IClientEntity *entity)
{
#if !ENFORCE_STREAM_SAFETY
if (!isHackActive() || !*effect_chams::enable)
return;
CMatRenderContextPtr ptr(GET_RENDER_CONTEXT);
@ -326,9 +338,11 @@ void EffectChams::RenderChams(IClientEntity *entity)
RenderChamsRecursive(entity);
}
}
#endif
}
void EffectChams::Render(int x, int y, int w, int h)
{
#if !ENFORCE_STREAM_SAFETY
PROF_SECTION(DRAW_chams);
if (!isHackActive())
return;
@ -350,6 +364,7 @@ void EffectChams::Render(int x, int y, int w, int h)
RenderChams(entity);
}
EndRenderChams();
#endif
}
EffectChams g_EffectChams;
CScreenSpaceEffectRegistration *g_pEffectChams = nullptr;

View File

@ -129,6 +129,7 @@ CatCommand fix_black_glow("fix_black_glow", "Fix Black Glow", []() {
void EffectGlow::Init()
{
#if !ENFORCE_STREAM_SAFETY
if (init)
return;
logging::Info("Init Glow...");
@ -202,6 +203,7 @@ void EffectGlow::Init()
logging::Info("Init done!");
init = true;
#endif
}
void EffectGlow::Shutdown()
@ -262,6 +264,9 @@ rgba_t EffectGlow::GlowColor(IClientEntity *entity)
bool EffectGlow::ShouldRenderGlow(IClientEntity *entity)
{
#if ENFORCE_STREAM_SAFETY
return false;
#endif
static CachedEntity *ent;
if (entity->entindex() < 0)
return false;
@ -316,6 +321,7 @@ bool EffectGlow::ShouldRenderGlow(IClientEntity *entity)
void EffectGlow::BeginRenderGlow()
{
#if !ENFORCE_STREAM_SAFETY
drawing = true;
CMatRenderContextPtr ptr(GET_RENDER_CONTEXT);
ptr->ClearColor4ub(0, 0, 0, 0);
@ -326,19 +332,23 @@ void EffectGlow::BeginRenderGlow()
ptr->ClearBuffers(true, false);
mat_unlit_z->AlphaModulate(1.0f);
ptr->DepthRange(0.0f, 0.01f);
#endif
}
void EffectGlow::EndRenderGlow()
{
#if !ENFORCE_STREAM_SAFETY
drawing = false;
CMatRenderContextPtr ptr(GET_RENDER_CONTEXT);
ptr->DepthRange(0.0f, 1.0f);
g_IVModelRender->ForcedMaterialOverride(nullptr);
ptr->PopRenderTargetAndViewport();
#endif
}
void EffectGlow::StartStenciling()
{
#if !ENFORCE_STREAM_SAFETY
static ShaderStencilState_t state;
state.Reset();
state.m_bEnable = true;
@ -366,10 +376,12 @@ void EffectGlow::StartStenciling()
g_IVRenderView->SetBlend(0.0f);
mat_unlit->AlphaModulate(1.0f);
g_IVModelRender->ForcedMaterialOverride(*solid_when ? mat_unlit : mat_unlit_z);
#endif
}
void EffectGlow::EndStenciling()
{
#if !ENFORCE_STREAM_SAFETY
static ShaderStencilState_t state;
state.Reset();
g_IVModelRender->ForcedMaterialOverride(nullptr);
@ -377,11 +389,14 @@ void EffectGlow::EndStenciling()
state.SetStencilState(ptr);
ptr->DepthRange(0.0f, 1.0f);
g_IVRenderView->SetBlend(1.0f);
#endif
}
void EffectGlow::DrawToStencil(IClientEntity *entity)
{
#if !ENFORCE_STREAM_SAFETY
DrawEntity(entity);
#endif
}
void EffectGlow::DrawToBuffer(IClientEntity *entity)
@ -390,6 +405,7 @@ void EffectGlow::DrawToBuffer(IClientEntity *entity)
void EffectGlow::DrawEntity(IClientEntity *entity)
{
#if !ENFORCE_STREAM_SAFETY
static IClientEntity *attach;
static int passes;
passes = 0;
@ -415,18 +431,22 @@ void EffectGlow::DrawEntity(IClientEntity *entity)
}
attach = g_IEntityList->GetClientEntity(*(int *) ((uintptr_t) attach + netvar.m_Collision - 20) & 0xFFF);
}
#endif
}
void EffectGlow::RenderGlow(IClientEntity *entity)
{
#if !ENFORCE_STREAM_SAFETY
CMatRenderContextPtr ptr(GET_RENDER_CONTEXT);
g_IVRenderView->SetColorModulation(GlowColor(entity));
g_IVModelRender->ForcedMaterialOverride(mat_unlit_z);
DrawEntity(entity);
#endif
}
void EffectGlow::Render(int x, int y, int w, int h)
{
#if !ENFORCE_STREAM_SAFETY
if (!enable)
return;
if (!isHackActive() || (clean_screenshots && g_IEngine->IsTakingScreenshot()) || g_Settings.bInvalid)
@ -482,6 +502,7 @@ void EffectGlow::Render(int x, int y, int w, int h)
{
SS_Null.SetStencilState(ptr);
}
#endif
}
EffectGlow g_EffectGlow;