Only update world and sky materials when changes are made.
Signed-off-by: aixxe <me@aixxe.net>
This commit is contained in:
parent
468fbe5d07
commit
f09c083a43
|
@ -1,3 +1,5 @@
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "Hooks.h"
|
#include "Hooks.h"
|
||||||
|
|
||||||
typedef void (*FrameStageNotify_t) (IBaseClientDLL*, ClientFrameStage_t);
|
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;
|
bool GUI::ASUS::Enabled = true;
|
||||||
float GUI::ASUS::Color[4] = {1, 1, 1, 0.75};
|
float GUI::ASUS::Color[4] = {1, 1, 1, 0.75};
|
||||||
|
|
||||||
|
std::unordered_map<MaterialHandle_t, ImColor> material_colors;
|
||||||
|
|
||||||
void Hooks::FrameStageNotify(IBaseClientDLL* thisptr, ClientFrameStage_t stage) {
|
void Hooks::FrameStageNotify(IBaseClientDLL* thisptr, ClientFrameStage_t stage) {
|
||||||
// Get the original function and store it statically.
|
// Get the original function and store it statically.
|
||||||
static FrameStageNotify_t oFrameStageNotify = clientdll_hook->GetOriginalFunction<FrameStageNotify_t>(35);
|
static FrameStageNotify_t oFrameStageNotify = clientdll_hook->GetOriginalFunction<FrameStageNotify_t>(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) {
|
if (stage == ClientFrameStage_t::FRAME_NET_UPDATE_POSTDATAUPDATE_END) {
|
||||||
for (MaterialHandle_t i = matsystem->FirstMaterial(); i != matsystem->InvalidMaterial(); i = matsystem->NextMaterial(i)) {
|
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);
|
IMaterial* material = matsystem->GetMaterial(i);
|
||||||
|
|
||||||
// No Sky
|
// Check for 'SkyBox textures' group.
|
||||||
if (!strcmp(material->GetTextureGroupName(), TEXTURE_GROUP_SKYBOX)) {
|
if (!strcmp(material->GetTextureGroupName(), TEXTURE_GROUP_SKYBOX)) {
|
||||||
if (GUI::NoSky::Enabled) {
|
if (material_colors.find(i) == material_colors.end())
|
||||||
material->ColorModulate(GUI::NoSky::Color[0], GUI::NoSky::Color[1], GUI::NoSky::Color[2]);
|
material_colors.emplace(i, ImColor());
|
||||||
} else {
|
|
||||||
material->ColorModulate(1, 1, 1);
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for 'World textures' group.
|
||||||
if (!strcmp(material->GetTextureGroupName(), TEXTURE_GROUP_WORLD)) {
|
if (!strcmp(material->GetTextureGroupName(), TEXTURE_GROUP_WORLD)) {
|
||||||
// ASUS walls.
|
if (material_colors.find(i) == material_colors.end())
|
||||||
if (GUI::ASUS::Enabled) {
|
material_colors.emplace(i, ImColor());
|
||||||
material->ColorModulate(GUI::ASUS::Color[0], GUI::ASUS::Color[1], GUI::ASUS::Color[2]);
|
|
||||||
material->AlphaModulate(GUI::ASUS::Color[3]);
|
ImColor color = ImColor(1.0f, 1.0f, 1.0f);
|
||||||
} else {
|
|
||||||
material->ColorModulate(1, 1, 1);
|
if (GUI::ASUS::Enabled)
|
||||||
material->AlphaModulate(1);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue