From f09c083a433be367f16c66db05a7e0b6aade714d Mon Sep 17 00:00:00 2001 From: aixxe Date: Fri, 23 Dec 2016 21:31:54 +0000 Subject: [PATCH] Only update world and sky materials when changes are made. Signed-off-by: aixxe --- src/Hooks/FrameStageNotify.cpp | 57 ++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/src/Hooks/FrameStageNotify.cpp b/src/Hooks/FrameStageNotify.cpp index 4379d64..146d5b5 100644 --- a/src/Hooks/FrameStageNotify.cpp +++ b/src/Hooks/FrameStageNotify.cpp @@ -1,3 +1,5 @@ +#include + #include "Hooks.h" typedef void (*FrameStageNotify_t) (IBaseClientDLL*, ClientFrameStage_t); @@ -8,34 +10,63 @@ float GUI::NoSky::Color[3] = {0, 0, 0.275}; bool GUI::ASUS::Enabled = true; float GUI::ASUS::Color[4] = {1, 1, 1, 0.75}; +std::unordered_map material_colors; + void Hooks::FrameStageNotify(IBaseClientDLL* thisptr, ClientFrameStage_t stage) { // Get the original function and store it statically. static FrameStageNotify_t oFrameStageNotify = clientdll_hook->GetOriginalFunction(35); - // Really should move this somewhere else. Doesn't need to be called this often. + // Restore skybox & world materials to original state when disconnected. + if (!engine->IsConnected() && material_colors.size() > 0) { + for (const auto& it: material_colors) { + IMaterial* material = matsystem->GetMaterial(it.first); + + material->ColorModulate(1, 1, 1); + material->AlphaModulate(1); + } + + material_colors.clear(); + } + if (stage == ClientFrameStage_t::FRAME_NET_UPDATE_POSTDATAUPDATE_END) { for (MaterialHandle_t i = matsystem->FirstMaterial(); i != matsystem->InvalidMaterial(); i = matsystem->NextMaterial(i)) { + // Get the material from the current handle. IMaterial* material = matsystem->GetMaterial(i); - // No Sky + // Check for 'SkyBox textures' group. if (!strcmp(material->GetTextureGroupName(), TEXTURE_GROUP_SKYBOX)) { - if (GUI::NoSky::Enabled) { - material->ColorModulate(GUI::NoSky::Color[0], GUI::NoSky::Color[1], GUI::NoSky::Color[2]); - } else { - material->ColorModulate(1, 1, 1); + if (material_colors.find(i) == material_colors.end()) + material_colors.emplace(i, ImColor()); + + ImColor color = ImColor(1.0f, 1.0f, 1.0f); + + if (GUI::NoSky::Enabled) + color = ImColor(GUI::NoSky::Color[0], GUI::NoSky::Color[1], GUI::NoSky::Color[2]); + + if (material_colors.at(i) != color) { + material->ColorModulate(color.Value.x, color.Value.y, color.Value.z); + + material_colors.at(i) = color; } continue; } + // Check for 'World textures' group. if (!strcmp(material->GetTextureGroupName(), TEXTURE_GROUP_WORLD)) { - // ASUS walls. - if (GUI::ASUS::Enabled) { - material->ColorModulate(GUI::ASUS::Color[0], GUI::ASUS::Color[1], GUI::ASUS::Color[2]); - material->AlphaModulate(GUI::ASUS::Color[3]); - } else { - material->ColorModulate(1, 1, 1); - material->AlphaModulate(1); + if (material_colors.find(i) == material_colors.end()) + material_colors.emplace(i, ImColor()); + + ImColor color = ImColor(1.0f, 1.0f, 1.0f); + + if (GUI::ASUS::Enabled) + color = ImColor(GUI::ASUS::Color[0], GUI::ASUS::Color[1], GUI::ASUS::Color[2], GUI::ASUS::Color[3]); + + if (material_colors.at(i) != color) { + material->ColorModulate(color.Value.x, color.Value.y, color.Value.z); + material->AlphaModulate(color.Value.w); + + material_colors.at(i) = color; } } }