From b3188a6344ec1314fb02a4793429d18bc320c2d4 Mon Sep 17 00:00:00 2001 From: BenCat07 Date: Thu, 30 Jul 2020 11:03:18 +0200 Subject: [PATCH] Only change color if it has changed in nightmode settings This also fixes a more common crash on config load --- src/hooks/visual/FrameStageNotify.cpp | 30 +++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/hooks/visual/FrameStageNotify.cpp b/src/hooks/visual/FrameStageNotify.cpp index 5f4f8f56..1bd7b863 100644 --- a/src/hooks/visual/FrameStageNotify.cpp +++ b/src/hooks/visual/FrameStageNotify.cpp @@ -65,26 +65,44 @@ DEFINE_HOOKED_METHOD(FrameStageNotify, void, void *this_, ClientFrameStage_t sta if (should_filter) { - if (should_filter == 1 && *nightmode_gui > 0.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); + // Check for change + float r, g, b, a; + pMaterial->GetColorModulation(&r, &g, &b); + a = pMaterial->GetAlphaModulation(); + + if (r != draw_color.r || g != draw_color.g || b != draw_color.b) + pMaterial->ColorModulate(draw_color.r, draw_color.g, draw_color.b); + if (a != draw_color.a) + 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); + // Check for change + float r, g, b, a; + pMaterial->GetColorModulation(&r, &g, &b); + a = pMaterial->GetAlphaModulation(); + if (r != draw_color.r || g != draw_color.g || b != draw_color.b) + pMaterial->ColorModulate(draw_color.r, draw_color.g, draw_color.b); + if (a != draw_color.a) + pMaterial->AlphaModulate((*nightmode_world_color).a); } else { - pMaterial->ColorModulate(1.0f, 1.0f, 1.0f); + float r, g, b, a; + pMaterial->GetColorModulation(&r, &g, &b); + a = pMaterial->GetAlphaModulation(); + if (r != 1.0f || g != 1.0f || b != 1.0f) + pMaterial->ColorModulate(1.0f, 1.0f, 1.0f); + if (a != 1.0f) + pMaterial->AlphaModulate(1.0f); } } }