Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
change color upon on/off toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
KawaiiKraken committed Sep 30, 2023
1 parent d945b74 commit b40e0de
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 20 deletions.
73 changes: 54 additions & 19 deletions klimV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// random TODO more sensible variable and function names

typedef UINT ( CALLBACK* LPFNDLLSTARTOVERLAY )( bool );
typedef UINT ( CALLBACK* LPFNDLLUPDATEOVERLAYLINE )( LPTSTR, int );
typedef UINT ( CALLBACK* LPFNDLLUPDATEOVERLAYLINE )( LPTSTR, int, COLORREF );

using namespace std;

Expand Down Expand Up @@ -70,6 +70,7 @@ unsigned long block_traffic( LPVOID lpParam );
char myNetRules[1000];
const char *err_str;
INT16 priority = 1000;
COLORREF colorDefault, colorOff, colorOn;



Expand Down Expand Up @@ -484,6 +485,9 @@ void setGlobalPathToIni(){ // this function does a bit too much, should prob spl
WritePrivateProfileString( L"hotkeys", L"hotkey_suspend", L"p", filePath );
WritePrivateProfileString( L"hotkeys", L"modkey_suspend", L"ctrl", filePath );
WritePrivateProfileString( L"other", L"useOverlay", L"true", filePath );
WritePrivateProfileString( L"other", L"colorDefault", L"0x00FFFFFF", filePath );
WritePrivateProfileString( L"other", L"colorOn", L"0x000000FF", filePath );
WritePrivateProfileString( L"other", L"colorOff", L"0x00FFFFFF", filePath );

}
wcsncpy_s( pathToIni, sizeof( pathToIni ), filePath, sizeof( pathToIni ) );
Expand Down Expand Up @@ -666,38 +670,45 @@ int __cdecl main( int argc, char** argv ){
}
printf( "pathToIni %ls\n", pathToIni );

GetPrivateProfileStringW( L"other", L"colorDefault", NULL, wc_buffer, sizeof(wc_buffer), pathToIni );
colorDefault = wcstol(wc_buffer, NULL, 16);
GetPrivateProfileStringW( L"other", L"colorOn", NULL, wc_buffer, sizeof(wc_buffer), pathToIni );
colorOn = wcstol(wc_buffer, NULL, 16);
GetPrivateProfileStringW( L"other", L"colorOff", NULL, wc_buffer, sizeof(wc_buffer), pathToIni );
colorOff = wcstol(wc_buffer, NULL, 16);

setVarsFromIni();


lpfnDllStartOverlay(useOverlay);
// TODO make this into a function
wchar_t* wcstring = new wchar_t[200];
triggerHotkeyString( wcstring, 200, hotkey_3074, modkey_3074, (wchar_t *)L"3074", (wchar_t*)L"" );
lpfnDllUpdateOverlayLine( (wchar_t*)wcstring, 1 );
lpfnDllUpdateOverlayLine( wcstring, 1, colorDefault);

triggerHotkeyString( wcstring, 200, hotkey_3074_UL, modkey_3074_UL, (wchar_t *)L"3074UL", (wchar_t*)L"" );
lpfnDllUpdateOverlayLine( wcstring, 2 );
lpfnDllUpdateOverlayLine( wcstring, 2, colorDefault);

triggerHotkeyString( wcstring, 200, hotkey_27k, modkey_27k, (wchar_t *)L"27k", (wchar_t*)L"" );
lpfnDllUpdateOverlayLine( wcstring, 3 );
lpfnDllUpdateOverlayLine( wcstring, 3, colorDefault);

triggerHotkeyString( wcstring, 200, hotkey_27k_UL, modkey_27k_UL, (wchar_t *)L"27kUL", (wchar_t*)L"" );
lpfnDllUpdateOverlayLine( wcstring, 4 );
lpfnDllUpdateOverlayLine( wcstring, 4, colorDefault);

triggerHotkeyString( wcstring, 200, hotkey_30k, modkey_30k, (wchar_t *)L"30k", (wchar_t*)L"" );
lpfnDllUpdateOverlayLine( wcstring, 5 );
lpfnDllUpdateOverlayLine( wcstring, 5, colorDefault);

triggerHotkeyString( wcstring, 200, hotkey_7k, modkey_7k, (wchar_t *)L"7k", (wchar_t*)L"" );
lpfnDllUpdateOverlayLine( wcstring, 6 );
lpfnDllUpdateOverlayLine( wcstring, 6, colorDefault);

triggerHotkeyString( wcstring, 200, hotkey_game, modkey_game, (wchar_t *)L"game", (wchar_t*)L"" );
lpfnDllUpdateOverlayLine( wcstring, 7 );
lpfnDllUpdateOverlayLine( wcstring, 7, colorDefault);

triggerHotkeyString( wcstring, 200, hotkey_suspend, modkey_suspend, (wchar_t *)L"suspend", (wchar_t*)L"" );
lpfnDllUpdateOverlayLine( wcstring, 8 );
lpfnDllUpdateOverlayLine( wcstring, 8, colorDefault);

triggerHotkeyString( wcstring, 200, hotkey_exitapp, modkey_exitapp, (wchar_t *)L"close", (wchar_t*)L"" );
lpfnDllUpdateOverlayLine( wcstring, 9 );
lpfnDllUpdateOverlayLine( wcstring, 9, colorDefault);

delete []wcstring;

Expand Down Expand Up @@ -757,102 +768,124 @@ void combinerules(){
}

void toggle3074(){
COLORREF color;
state3074 = !state3074;
printf( "state3074 %s\n", state3074 ? "true" : "false" );
wchar_t* wcstring = new wchar_t[200];
if ( state3074 ){
triggerHotkeyString( wcstring, 200, hotkey_3074, modkey_3074, (wchar_t *)L"3074", (wchar_t*)L" on" );
color = colorOn;
} else {
triggerHotkeyString( wcstring, 200, hotkey_3074, modkey_3074, (wchar_t *)L"3074", (wchar_t*)L" off" );
color = colorOff;
}
lpfnDllUpdateOverlayLine( wcstring, 1 );
lpfnDllUpdateOverlayLine( wcstring, 1, color);
delete []wcstring;
}

void toggle3074_UL(){
COLORREF color;
state3074_UL = !state3074_UL;
printf( "state3074UL %s\n", state3074_UL ? "true" : "false" );
wchar_t* wcstring = new wchar_t[200];
if ( state3074_UL ){
triggerHotkeyString( wcstring, 200, hotkey_3074_UL, modkey_3074_UL, (wchar_t *)L"3074UL", (wchar_t*)L" on" );
color = colorOn;
} else {
triggerHotkeyString( wcstring, 200, hotkey_3074_UL, modkey_3074_UL, (wchar_t *)L"3074UL", (wchar_t*)L" off" );
color = colorOff;
}
lpfnDllUpdateOverlayLine( wcstring, 2 );
lpfnDllUpdateOverlayLine( wcstring, 2, color);
delete []wcstring;
}

void toggle27k(){
COLORREF color;
state27k = !state27k;
printf( "state3074UL %s\n", state27k ? "true" : "false" );
wchar_t* wcstring = new wchar_t[200];
if ( state27k ){
triggerHotkeyString( wcstring, 200, hotkey_27k, modkey_27k, (wchar_t *)L"27k", (wchar_t*)L" on" );
color = colorOn;
} else {
triggerHotkeyString( wcstring, 200, hotkey_27k, modkey_27k, (wchar_t *)L"27k", (wchar_t*)L" off" );
color = colorOff;
}
lpfnDllUpdateOverlayLine( wcstring, 3 );
lpfnDllUpdateOverlayLine( wcstring, 3, color);
delete []wcstring;
}

void toggle27k_UL(){
COLORREF color;
state27k_UL = !state27k_UL;
printf( "state3074UL %s\n", state27k_UL ? "true" : "false" );
wchar_t* wcstring = new wchar_t[200];
if ( state27k_UL ){
triggerHotkeyString( wcstring, 200, hotkey_27k_UL, modkey_27k_UL, (wchar_t *)L"27kUL", (wchar_t*)L" on" );
color = colorOn;
} else {
triggerHotkeyString( wcstring, 200, hotkey_27k_UL, modkey_27k_UL, (wchar_t *)L"27kUL", (wchar_t*)L" off" );
color = colorOff;
}
lpfnDllUpdateOverlayLine( wcstring, 4 );
lpfnDllUpdateOverlayLine( wcstring, 4, color);
delete []wcstring;
}


void toggle30k(){
COLORREF color;
state30k = !state30k;
printf( "state30k %s\n", state30k ? "true" : "false" );
wchar_t* wcstring = new wchar_t[200];
if ( state30k ){
triggerHotkeyString( wcstring, 200, hotkey_30k, modkey_30k, (wchar_t *)L"30k", (wchar_t*)L" on" );
color = colorOn;
} else {
triggerHotkeyString( wcstring, 200, hotkey_30k, modkey_30k, (wchar_t *)L"30k", (wchar_t*)L" off" );
color = colorOff;
}
lpfnDllUpdateOverlayLine( wcstring, 5 );
lpfnDllUpdateOverlayLine( wcstring, 5, color);
delete []wcstring;
}

void toggle7k(){
COLORREF color;
state7k = !state7k;
printf( "state7k %s\n", state7k ? "true" : "false" );
wchar_t* wcstring = new wchar_t[200];
if ( state7k ){
triggerHotkeyString( wcstring, 200, hotkey_7k, modkey_7k, (wchar_t *)L"7k", (wchar_t*)L" on" );
color = colorOn;
} else {
triggerHotkeyString( wcstring, 200, hotkey_7k, modkey_7k, (wchar_t *)L"7k", (wchar_t*)L" off" );
color = colorOff;
}
lpfnDllUpdateOverlayLine( wcstring, 6 );
lpfnDllUpdateOverlayLine( wcstring, 6, color);
delete []wcstring;
}

void toggleGame(){
COLORREF color;
state_game = !state_game;
printf( "state_game %s\n", state_game ? "true" : "false" );
wchar_t* wcstring = new wchar_t[200];
if ( state_game ){
ShellExecute(NULL, NULL, L"powershell.exe", L"-ExecutionPolicy bypass -noe -c New-NetQosPolicy -Name 'Destiny2-Limit' -AppPathNameMatchCondition 'destiny2.exe' -ThrottleRateActionBitsPerSecond 800KB", NULL, SW_HIDE);
triggerHotkeyString( wcstring, 200, hotkey_game, modkey_game, (wchar_t *)L"game", (wchar_t*)L" on" );
color = colorOn;
} else {
ShellExecute(NULL, NULL, L"powershell.exe", L"-ExecutionPolicy bypass -c Remove-NetQosPolicy -Name 'Destiny2-Limit' -Confirm:$false", NULL, SW_HIDE);
triggerHotkeyString( wcstring, 200, hotkey_game, modkey_game, (wchar_t *)L"game", (wchar_t*)L" off" );
color = colorOff;
}
lpfnDllUpdateOverlayLine( wcstring, 7 );
lpfnDllUpdateOverlayLine( wcstring, 7, color);
delete []wcstring;

}


void toggleSuspend(){
COLORREF color;
if ( isD2Active() ){
DWORD pid = 0;
// shitty way to get pid but eh
Expand All @@ -864,6 +897,7 @@ void toggleSuspend(){

if ( state_suspend ){
triggerHotkeyString( wcstring, 200, hotkey_suspend, modkey_suspend, (wchar_t *)L"suspend", (wchar_t*)L" on" );
color = colorOn;
if ( pid != 0 ){
printf( "pid: %lu\n", pid );
procHandle = OpenProcess( 0x1F0FFF, 0, pid ); // TODO remove magic numbers
Expand All @@ -874,8 +908,9 @@ void toggleSuspend(){
}

} else {
triggerHotkeyString( wcstring, 200, hotkey_suspend, modkey_suspend, (wchar_t *)L"suspend", (wchar_t*)L" off" );
color = colorOff;
if ( pid != 0 ){
triggerHotkeyString( wcstring, 200, hotkey_suspend, modkey_suspend, (wchar_t *)L"suspend", (wchar_t*)L" off" );
procHandle = OpenProcess( 0x1F0FFF, 0, pid ); // TODO remove magic numbers
if ( procHandle != NULL ){
printf( "resuming match\n" );
Expand All @@ -886,7 +921,7 @@ void toggleSuspend(){
if ( procHandle != NULL ){
CloseHandle( procHandle );
}
lpfnDllUpdateOverlayLine( wcstring, 8 );
lpfnDllUpdateOverlayLine( wcstring, 8, color);
delete []wcstring;
}
}
Expand Down
5 changes: 4 additions & 1 deletion krekens_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ HANDLE threadHandle = nullptr;
int nCmdShow = NULL;
bool isOverlay;
RECT screenSize;
COLORREF colors[10];

//using namespace std;

RECT myDrawText(wchar_t* text, int index, RECT rect, HDC hdc){
SetTextColor(hdc, colors[index]);
DrawText(hdc, ::mytext[index], -1, &rect, NULL);
DrawText(hdc, ::mytext[index], -1, &rect, DT_CALCRECT);
rect.top = rect.bottom;
Expand Down Expand Up @@ -192,8 +194,9 @@ __declspec( dllexport ) DWORD WINAPI startOverlay( bool isOverlayArg ) // TODO s
return 0;
}

__declspec(dllexport) DWORD WINAPI updateOverlayLine( LPTSTR text, int linenum ) // TODO split into multiple functions
__declspec(dllexport) DWORD WINAPI updateOverlayLine( LPTSTR text, int linenum, COLORREF color) // TODO split into multiple functions
{
colors[linenum-1] = color;
wcscpy_s(::mytext[linenum-1], text);
printf("1: mytext[%d] = \"%ls\"\n", linenum-1, ::mytext[linenum-1]);
RedrawWindow(hwnd, NULL, NULL, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN);
Expand Down

0 comments on commit b40e0de

Please sign in to comment.