Fix and improve nightmode (see description)

This commit first of all fixes nightmode, then second of all makes it more customizeable, and the third point is that it fixes antiafk
This commit is contained in:
BenCat07 2020-05-15 21:34:23 +02:00
parent fce61ade5a
commit 2df0a31256
3 changed files with 64 additions and 16 deletions

View File

@ -31,7 +31,10 @@
</Box>
<Box padding="12 6 6 6" width="content" height="content" name="Misc" x="195" y="110">
<List width="180">
<AutoVariable width="fill" target="visual.night-mode" label="Nightmode" min="0" max="50" step="0.1"/>
<AutoVariable width="fill" target="visual.night-mode.gui" label="Nightmode (GUI)" min="0" max="100" step="0.1"/>
<AutoVariable width="fill" target="visual.night-mode.world" label="Nightmode (World)" min="0" max="100" step="0.1"/>
<AutoVariable width="fill" target="visual.night-mode.gui-color" label="Nightmode Color (GUI)"/>
<AutoVariable width="fill" target="visual.night-mode.world-color" label="Nightmode Color (World)"/>
<AutoVariable width="fill" target="explosionspheres.enabled" label="Draw Explosion Spheres"/>
<LabeledObject width="fill" label="Ragdoll Override">
<Select target="visual.ragdoll-mode">

View File

@ -79,6 +79,12 @@ static void updateAntiAfk()
current_user_cmd->buttons &= ~(IN_DUCK | IN_JUMP);
else
current_user_cmd->buttons = IN_DUCK | IN_JUMP;
// Game also checks if you move if you are in spawn, so spam movement keys alternatingly
bool flip = false;
current_late_user_cmd->buttons |= flip ? IN_FORWARD : IN_BACK;
// Flip flip
flip = !flip;
if (anti_afk_timer.check(afk_timer->m_nValue * 60 * 1000 + 1000))
{
anti_afk_timer.update();
@ -830,7 +836,7 @@ static InitRoutine init_pyrovision([]() {
}
if (!after && cmdrate->GetInt() != oldCmdRate)
cmdrate->SetValue(oldCmdRate);
});;
});
#endif
});
#endif

View File

@ -11,10 +11,21 @@
#include "hacks/Backtrack.hpp"
#include "AntiAntiAim.hpp"
static settings::Float nightmode{ "visual.night-mode", "0" };
static settings::Float nightmode_gui{ "visual.night-mode.gui", "0" };
static settings::Float nightmode_world{ "visual.night-mode.world", "0" };
static settings::Rgba nightmode_gui_color{ "visual.night-mode.gui-color", "000000FF" };
static settings::Rgba nightmode_world_color{ "visual.night-mode.world-color", "000000FF" };
static settings::Boolean no_shake{ "visual.no-shake", "true" };
static float old_nightmode{ 0.0f };
// Previous values
static float old_nightmode_world{ 0.0f };
static float old_nightmode_gui{ 0.0f };
static rgba_t old_nightmode_world_color(0.0f, 0.0f, 0.0f, 1.0f);
static rgba_t old_nightmode_gui_color(0.0f, 0.0f, 0.0f, 1.0f);
// Which strings trigger this nightmode option
std::vector<std::string> world_strings = { "SkyBox", "World" };
std::vector<std::string> gui_strings = { "Other", "VGUI" };
namespace hooked_methods
{
@ -26,7 +37,7 @@ DEFINE_HOOKED_METHOD(FrameStageNotify, void, void *this_, ClientFrameStage_t sta
PROF_SECTION(FrameStageNotify_TOTAL);
if (old_nightmode != *nightmode)
if (old_nightmode_gui != *nightmode_gui || old_nightmode_world != *nightmode_world || old_nightmode_world_color != *nightmode_world_color || old_nightmode_gui_color != *nightmode_gui_color)
{
static ConVar *r_DrawSpecificStaticProp = g_ICvar->FindVar("r_DrawSpecificStaticProp");
if (!r_DrawSpecificStaticProp)
@ -42,20 +53,48 @@ DEFINE_HOOKED_METHOD(FrameStageNotify, void, void *this_, ClientFrameStage_t sta
if (!pMaterial)
continue;
if (strstr(pMaterial->GetTextureGroupName(), "World") || strstr(pMaterial->GetTextureGroupName(), "StaticProp"))
// 0 = do not filter, 1 = Gui filter, 2 = World filter
int should_filter = 0;
auto name = std::string(pMaterial->GetTextureGroupName());
for (auto &entry : gui_strings)
if (name.find(entry) != name.npos)
should_filter = 1;
for (auto &entry : world_strings)
if (name.find(entry) != name.npos)
should_filter = 2;
if (should_filter)
{
if (float(nightmode) > 0.0f)
if (should_filter == 1 && *nightmode_gui > 0.0f)
{
if (strstr(pMaterial->GetTextureGroupName(), "StaticProp"))
pMaterial->ColorModulate(1.0f - float(nightmode) / 100.0f, 1.0f - float(nightmode) / 100.0f, 1.0f - float(nightmode) / 100.0f);
else
pMaterial->ColorModulate((1.0f - float(nightmode) / 100.0f) / 6.0f, (1.0f - float(nightmode) / 100.0f) / 6.0f, (1.0f - float(nightmode) / 100.0f) / 6.0f);
// Map to PI/2 so we get full color scale
rgba_t draw_color = colors::Fade(colors::white, *nightmode_gui_color, (*nightmode_gui / 100.0f) * (PI / 2), 1.0f);
pMaterial->ColorModulate(draw_color.r, draw_color.g, draw_color.b);
pMaterial->AlphaModulate((*nightmode_gui_color).a);
}
else if (should_filter == 2 && *nightmode_world > 0.0f)
{
// Map to PI/2 so we get full color scale
rgba_t draw_color = colors::Fade(colors::white, *nightmode_world_color, (*nightmode_world / 100.0f) * (PI / 2), 1.0f);
pMaterial->ColorModulate(draw_color.r, draw_color.g, draw_color.b);
pMaterial->AlphaModulate((*nightmode_world_color).a);
}
else
{
pMaterial->ColorModulate(1.0f, 1.0f, 1.0f);
}
}
old_nightmode = *nightmode;
}
old_nightmode_gui = *nightmode_gui;
old_nightmode_gui_color = *nightmode_gui_color;
old_nightmode_world = *nightmode_world;
old_nightmode_world_color = *nightmode_world_color;
}
if (!g_IEngine->IsInGame())