summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/color.h425
-rw-r--r--src/heavens-gate.vcxproj1
-rw-r--r--src/heavens-gate.vcxproj.filters3
-rw-r--r--src/util.h5
4 files changed, 434 insertions, 0 deletions
diff --git a/src/color.h b/src/color.h
new file mode 100644
index 0000000..1717023
--- /dev/null
+++ b/src/color.h
@@ -0,0 +1,425 @@
+#pragma once
+#include "typedef.h"
+
+struct FCLR;
+struct ICLR;
+struct CLR;
+
+// float to int conversion
+#pragma warning( disable: 4244 )
+
+struct CLR {
+ U8 r, g, b, a;
+
+ CLR operator*( float v ) {
+ CLR ret = *this;
+
+ ret.r *= v;
+ ret.g *= v;
+ ret.b *= v;
+ ret.a *= v;
+
+ return ret;
+ }
+
+ CLR operator/( float v ) {
+ CLR ret = *this;
+
+ float inv = 1.f / v;
+
+ ret.r *= inv;
+ ret.g *= inv;
+ ret.b *= inv;
+ ret.a *= inv;
+
+ return ret;
+ }
+
+ CLR operator/=( float v ) {
+ float inv = 1.f / v;
+
+ r *= inv;
+ g *= inv;
+ b *= inv;
+ a *= inv;
+
+ return *this;
+ }
+
+ CLR operator*=( float v ) {
+ r *= v;
+ g *= v;
+ b *= v;
+ a *= v;
+
+ return *this;
+ }
+
+ CLR operator+( const CLR& other ) {
+ CLR ret = *this;
+
+ ret.r += other.r;
+ ret.g += other.g;
+ ret.b += other.b;
+ ret.a += other.a;
+
+ return ret;
+ }
+
+ CLR operator-( const CLR& other ) {
+ CLR ret = *this;
+
+ ret.r -= other.r;
+ ret.g -= other.g;
+ ret.b -= other.b;
+ ret.a -= other.a;
+
+ return ret;
+ }
+
+ CLR operator+=( const CLR& other ) {
+ r += other.r;
+ g += other.g;
+ b += other.b;
+ a += other.a;
+
+ return *this;
+ }
+
+ CLR operator-=( const CLR& other ) {
+ r -= other.r;
+ g -= other.g;
+ b -= other.b;
+ a -= other.a;
+
+ return *this;
+ }
+
+ static CLR from_hsb( F32 h, F32 s, F32 b ) {
+ F32 c = s * b;
+ F32 x = c * (1 - abs((int)(h / 60) % 2 - 1));
+ F32 m = b - c;
+
+ F32 _r, _g, _b;
+
+ if (h < 60) {
+ _r = c;
+ _g = x;
+ _b = 0;
+ } else if (h < 120) {
+ _r = x;
+ _g = c;
+ _b = 0;
+ } else if (h < 180) {
+ _r = 0;
+ _g = c;
+ _b = x;
+ } else if (h < 240) {
+ _r = 0;
+ _g = x;
+ _b = c;
+ } else if (h < 300) {
+ _r = x;
+ _g = 0;
+ _b = c;
+ } else {
+ _r = c;
+ _g = 0;
+ _b = x;
+ }
+
+ return {
+ (U8)((_r + m) * 255),
+ (U8)((_g + m) * 255),
+ (U8)((_b + m) * 255),
+ 255
+ };
+ }
+};
+
+struct FCLR {
+ F32 r, g, b, a;
+
+ FCLR operator*( float v ) {
+ FCLR ret = *this;
+
+ ret.r *= v;
+ ret.g *= v;
+ ret.b *= v;
+ ret.a *= v;
+
+ return ret;
+ }
+
+ FCLR operator/( float v ) {
+ FCLR ret = *this;
+
+ float inv = 1.f / v;
+
+ ret.r *= inv;
+ ret.g *= inv;
+ ret.b *= inv;
+ ret.a *= inv;
+
+ return ret;
+ }
+
+ FCLR operator/=( float v ) {
+ float inv = 1.f / v;
+
+ r *= inv;
+ g *= inv;
+ b *= inv;
+ a *= inv;
+
+ return *this;
+ }
+
+ FCLR operator*=( float v ) {
+ r *= v;
+ g *= v;
+ b *= v;
+ a *= v;
+
+ return *this;
+ }
+
+ FCLR operator+( const FCLR& other ) {
+ FCLR ret = *this;
+
+ ret.r += other.r;
+ ret.g += other.g;
+ ret.b += other.b;
+ ret.a += other.a;
+
+ return ret;
+ }
+
+ FCLR operator-( const FCLR& other ) {
+ FCLR ret = *this;
+
+ ret.r -= other.r;
+ ret.g -= other.g;
+ ret.b -= other.b;
+ ret.a -= other.a;
+
+ return ret;
+ }
+
+ FCLR operator+=( const FCLR& other ) {
+ r += other.r;
+ g += other.g;
+ b += other.b;
+ a += other.a;
+
+ return *this;
+ }
+
+ FCLR operator-=( const FCLR& other ) {
+ r -= other.r;
+ g -= other.g;
+ b -= other.b;
+ a -= other.a;
+
+ return *this;
+ }
+
+ static FCLR from_hsb( F32 h, F32 s, F32 b ) {
+ F32 c = s * b;
+ F32 x = c * (1 - abs((int)(h / 60) % 2 - 1));
+ F32 m = b - c;
+
+ F32 _r, _g, _b;
+
+ if (h < 60) {
+ _r = c;
+ _g = x;
+ _b = 0;
+ } else if (h < 120) {
+ _r = x;
+ _g = c;
+ _b = 0;
+ } else if (h < 180) {
+ _r = 0;
+ _g = c;
+ _b = x;
+ } else if (h < 240) {
+ _r = 0;
+ _g = x;
+ _b = c;
+ } else if (h < 300) {
+ _r = x;
+ _g = 0;
+ _b = c;
+ } else {
+ _r = c;
+ _g = 0;
+ _b = x;
+ }
+
+ return {
+ _r + m,
+ _g + m,
+ _b + m,
+ 1.f
+ };
+ }
+
+ CLR to_byte() {
+ return {
+ (U8)(r * 255.f),
+ (U8)(g * 255.f),
+ (U8)(b * 255.f),
+ (U8)(a * 255.f)
+ };
+ }
+};
+
+struct ICLR {
+ I32 r, g, b, a;
+
+ ICLR operator*( float v ) {
+ ICLR ret = *this;
+
+ ret.r *= v;
+ ret.g *= v;
+ ret.b *= v;
+ ret.a *= v;
+
+ return ret;
+ }
+
+ ICLR operator/( float v ) {
+ ICLR ret = *this;
+
+ float inv = 1.f / v;
+
+ ret.r *= inv;
+ ret.g *= inv;
+ ret.b *= inv;
+ ret.a *= inv;
+
+ return ret;
+ }
+
+ ICLR operator/=( float v ) {
+ float inv = 1.f / v;
+
+ r *= inv;
+ g *= inv;
+ b *= inv;
+ a *= inv;
+
+ return *this;
+ }
+
+ ICLR operator*=( float v ) {
+ r *= v;
+ g *= v;
+ b *= v;
+ a *= v;
+
+ return *this;
+ }
+
+ ICLR operator+( const ICLR& other ) {
+ ICLR ret = *this;
+
+ ret.r += other.r;
+ ret.g += other.g;
+ ret.b += other.b;
+ ret.a += other.a;
+
+ return ret;
+ }
+
+ ICLR operator-( const ICLR& other ) {
+ ICLR ret = *this;
+
+ ret.r -= other.r;
+ ret.g -= other.g;
+ ret.b -= other.b;
+ ret.a -= other.a;
+
+ return ret;
+ }
+
+ ICLR operator+=( const ICLR& other ) {
+ r += other.r;
+ g += other.g;
+ b += other.b;
+ a += other.a;
+
+ return *this;
+ }
+
+ ICLR operator-=( const ICLR& other ) {
+ r -= other.r;
+ g -= other.g;
+ b -= other.b;
+ a -= other.a;
+
+ return *this;
+ }
+
+ static ICLR from_hsb( F32 h, F32 s, F32 b ) {
+ F32 c = s * b;
+ F32 x = c * (1 - abs((int)(h / 60) % 2 - 1));
+ F32 m = b - c;
+
+ F32 _r, _g, _b;
+
+ if (h < 60) {
+ _r = c;
+ _g = x;
+ _b = 0;
+ } else if (h < 120) {
+ _r = x;
+ _g = c;
+ _b = 0;
+ } else if (h < 180) {
+ _r = 0;
+ _g = c;
+ _b = x;
+ } else if (h < 240) {
+ _r = 0;
+ _g = x;
+ _b = c;
+ } else if (h < 300) {
+ _r = x;
+ _g = 0;
+ _b = c;
+ } else {
+ _r = c;
+ _g = 0;
+ _b = x;
+ }
+
+ return {
+ (I32)((_r + m) * 255),
+ (I32)((_g + m) * 255),
+ (I32)((_b + m) * 255),
+ 255
+ };
+ }
+
+ CLR to_byte() {
+ return {
+ (U8)r,
+ (U8)g,
+ (U8)b,
+ (U8)a
+ };
+ }
+
+ FCLR to_float() {
+ return {
+ (F32)r,
+ (F32)g,
+ (F32)b,
+ (F32)a
+ };
+ }
+};
+
+#pragma warning( default: 4244 )
diff --git a/src/heavens-gate.vcxproj b/src/heavens-gate.vcxproj
index a7a20bc..e2e0742 100644
--- a/src/heavens-gate.vcxproj
+++ b/src/heavens-gate.vcxproj
@@ -209,6 +209,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="asmutil.h" />
+ <ClInclude Include="color.h" />
<ClInclude Include="cs2\cs2.h" />
<ClInclude Include="cs2\entity.h" />
<ClInclude Include="cs2\hack.h" />
diff --git a/src/heavens-gate.vcxproj.filters b/src/heavens-gate.vcxproj.filters
index 2140028..25a909f 100644
--- a/src/heavens-gate.vcxproj.filters
+++ b/src/heavens-gate.vcxproj.filters
@@ -93,6 +93,9 @@
<ClInclude Include="perf.h">
<Filter>Util</Filter>
</ClInclude>
+ <ClInclude Include="color.h">
+ <Filter>Util</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Console">
diff --git a/src/util.h b/src/util.h
index 1277047..0ee2a8a 100644
--- a/src/util.h
+++ b/src/util.h
@@ -4,6 +4,7 @@
#pragma once
#include <chrono>
#include <windows.h>
+#include <string.h>
#include <stdio.h>
#include <thread>
@@ -33,6 +34,7 @@ struct STR {
char data[size]{};
};
+#ifndef _WIN64
template < U32 size >
struct WSTR {
WSTR() = default;
@@ -44,6 +46,7 @@ struct WSTR {
wchar_t data[size]{};
};
+#endif
template < typename t >
STR< 32 > u_num_to_string_hex( t num ) {
@@ -72,6 +75,7 @@ STR< size > u_widebyte_to_ansi( const wchar_t* str ) {
return ret;
}
+#ifndef _WIN64
template < U32 size = 128 >
WSTR< size > u_ansi_to_widebyte( const char* str ) {
WSTR< size > ret;
@@ -82,6 +86,7 @@ WSTR< size > u_ansi_to_widebyte( const char* str ) {
return ret;
}
+#endif
inline U8 u_set_debug_privilege() {
HANDLE token;