Created 2 years ago2022-07-16 14:09:26 UTC by JacksBestGaming
#include "cl_dll.h"
#include "com_model.h"
#include "r_studioint.h"
#include <array>
extern engine_studio_api_t IEngineStudio;
typedef std::array<unsigned char, 3> rgb_color;
// Converts hue (in degrees) to 8bpc linear RGB, with 100% saturation and brightness
constexpr rgb_color hueToRgb(int hue) {
rgb_color result{};
if (hue < 0 || hue >= 360) { // Out of range, make it red
hue = 0;
}
const int cycleProgress = hue % 120;
const int channelA = hue / 120;
const int channelB = (channelA + 1) % result.size();
if (cycleProgress < 60) {
// If hue is between 0 and 59 inclusive, channelA is 0. The result is between #FF0000 and #FFFA00 inclusive
// If hue is between 120 and 179 inclusive, channelA is 1. The result is between #00FF00 and #00FFFA inclusive
// If hue is between 240 and 299 inclusive, channelA is 2. The result is between #0000FF and #FA00FF inclusive
result[channelA] = 255;
result[channelB] = (unsigned char) ((cycleProgress * 255) / 60);
} else {
// If hue is between 60 and 119 inclusive, channelA is 0. The result is between #FFFF00 and #04FF00 inclusive
// If hue is between 180 and 239 inclusive, channelA is 1. The result is between #00FFFF and #0004FF inclusive
// If hue is between 300 and 359 inclusive, channelA is 2. The result is between #FF00FF and #FF0004 inclusive
result[channelA] = (unsigned char) (((120 - cycleProgress) * 255) / 60);
result[channelB] = 255;
}
return result;
}
rgb_color getPlayerTopColorRgb(int playerIndex) {
rgb_color result { 255, 255, 255 };
if (playerIndex >= 0 && playerIndex < gEngfuncs.GetMaxClients())
const player_info_t * const playerInfo = IEngineStudio.PlayerInfo(playerIndex);
if (playerInfo) {
const int topColorHue = playerInfo->topcolor;
result = hueToRgb(topColorHue);
}
}
return result;
}
rgb_color getLocalPlayerTopColorRgb() {
rgb_color result { 255, 255, 255 };
const cl_entity_t * const localPlayer = gEngfuncs.GetLocalPlayer();
if (localPlayer) {
const int playerEntityIndex = localPlayer->index;
const int playerIndex = playerEntityIndex - 1;
result = getPlayerTopColorRgb(playerIndex);
}
return result;
}