Skip to content

Commit af9aae0

Browse files
committed
Add VSync option to FPS Limiter
Check for CZ75-Auto in AutoPistol Update the console, menu and keystrokes title Hide the overlay from the taskbar
1 parent e9ae96c commit af9aae0

File tree

9 files changed

+73
-56
lines changed

9 files changed

+73
-56
lines changed

ErScripts/AutoPistol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
void ErScripts::AutoPistol() {
44
std::thread([]() {
55
while (!globals::finish) {
6-
if (cfg->autoPistolState && globals::pistolState && !globals::revolverState) {
6+
if (cfg->autoPistolState && globals::pistolState && !globals::revolverState && !globals::cz75aState) {
77
if (ErScripts::GetWindowState() && ErScripts::GetCursorState()) {
88
if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
99
ErScripts::CommandsSender(6, "attack 1 1 0");

ErScripts/GSIServer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ void GSIServer::handleJsonPayload(const nlohmann::json& data) {
7979
globals::isBombInWeapons = handleIsBombInWeapons(playerData);
8080
globals::localPlayerKills = handleLocalPlayerKills(playerData);
8181
globals::localPlayerIsActivityPlaying = handleIsLocalPlayerActivityPlaying(playerData);
82-
globals::revolverState = handlIsActiveWeaponRevolver(playerData);
82+
globals::revolverState = handlActiveWeaponState(playerData, "weapon_revolver");
83+
globals::cz75aState = handlActiveWeaponState(playerData, "weapon_cz75a");
8384
}
8485

8586
bool GSIServer::handleSniperCrosshairState(const nlohmann::json& data) {
@@ -137,7 +138,7 @@ bool GSIServer::handleIsLocalPlayerActivityPlaying(const std::optional<nlohmann:
137138
return playerData && playerData->contains("activity") && (*playerData)["activity"].get<std::string>() == "playing";
138139
}
139140

140-
bool GSIServer::handlIsActiveWeaponRevolver(const std::optional<nlohmann::json>& playerData) {
141+
bool GSIServer::handlActiveWeaponState(const std::optional<nlohmann::json>& playerData, const std::string weaponName) {
141142
if (!playerData && !playerData->contains("weapons") || !(*playerData)["weapons"].is_object()) {
142143
return false;
143144
}
@@ -146,7 +147,7 @@ bool GSIServer::handlIsActiveWeaponRevolver(const std::optional<nlohmann::json>&
146147
if (weapon.contains("name") && weapon.contains("state")) {
147148
std::string name = weapon["name"].get<std::string>();
148149
std::string state = weapon["state"].get<std::string>();
149-
if (name == "weapon_revolver" && (state == "active")) {
150+
if (name == weaponName && (state == "active")) {
150151
return true;
151152
}
152153
}

ErScripts/GSIServer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class GSIServer {
2828
bool handleRoundStartState(const nlohmann::json& data); // Checks if round is live
2929
bool handleIsBombInWeapons(const std::optional<nlohmann::json>& playerData); // Checks for bomb in inventory
3030
int handleLocalPlayerKills(const std::optional<nlohmann::json>& playerData); // Gets local player kills
31-
bool handleIsLocalPlayerActivityPlaying(const std::optional<nlohmann::json>& playerData); // Checks if player activity is "playing"
32-
bool handlIsActiveWeaponRevolver(const std::optional<nlohmann::json>& playerData); // Checks if player activity is "playing"
31+
bool handleIsLocalPlayerActivityPlaying(const std::optional<nlohmann::json>& playerData); // Checks if player activity is "playing"
32+
bool handlActiveWeaponState(const std::optional<nlohmann::json>& playerData, const std::string weaponName); // Checks for active weapon
3333

3434
public:
3535
void run(); // Starts server in a thread

ErScripts/Globals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace globals {
1111
double bombTime = 0.0l;
1212
bool knifeState = false;
1313
bool pistolState = false;
14-
bool revolverState = false;
14+
bool revolverState = false, cz75aState = false;
1515
bool roundStartState = false;
1616
bool isBombInWeapons = false;
1717
int localPlayerKills = 0, localPlayerSlotNumber = 0;

ErScripts/Globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace globals {
1414
extern double bombTime;
1515
extern bool knifeState;
1616
extern bool pistolState;
17-
extern bool revolverState;
17+
extern bool revolverState, cz75aState;
1818
extern bool roundStartState;
1919
extern bool isBombInWeapons;
2020
extern int localPlayerKills, localPlayerSlotNumber;

ErScripts/Menu.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ inline char killSoundFileName[256]{};
7777
inline char roundStartAlertFileName[256]{};
7878

7979
void Overlay::Menu() noexcept {
80+
// Get the current window title
81+
char window_title[32];
82+
if (!GetConsoleTitleA(window_title, sizeof(window_title)))
83+
window_title[0] = '\0';
84+
8085
// Custom style
8186
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 12.0f); // Rounded window corners
8287
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 6.0f); // Rounded frames (slider background)
@@ -98,20 +103,16 @@ void Overlay::Menu() noexcept {
98103
ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, ImVec4(0.0f, 0.6f, 1.2f, 1.0f)); // Brighter blue when active
99104

100105
ImGui::PushFont(menu_font);
101-
ImGui::Begin(" ErScripts", &isFinish, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoCollapse);
106+
ImGui::Begin(std::format(" {}", window_title).c_str(), &isFinish, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoCollapse);
102107

103108
static ImVec2 menu_size = { 213.f, 272.f };
104109

105110
static bool one_time = true;
106111
if (one_time) {
107112
ImGui::SetWindowSize(menu_size);
108-
//menu_size = ImGui::GetWindowSize();
109-
//Logger::logInfo(std::format("Menu Size: {} x {}", menu_size.x, menu_size.y));
110113

111-
//if (menu_size.x > 150 && menu_size.y > 150) {
112-
ImGui::SetWindowPos(" ErScripts", { globals::width / 2 - menu_size.x / 2, globals::height / 2 - menu_size.y / 2 });
114+
ImGui::SetWindowPos(std::format(" {}", window_title).c_str(), {globals::width / 2 - menu_size.x / 2, globals::height / 2 - menu_size.y / 2});
113115
one_time = false;
114-
//}
115116
}
116117

117118
// Clamp the window position to stay within screen boundaries
@@ -131,7 +132,7 @@ void Overlay::Menu() noexcept {
131132
}
132133

133134
if ((menu_pos.x != ImGui::GetWindowPos().x || menu_pos.y != ImGui::GetWindowPos().y) && (GetAsyncKeyState(VK_LBUTTON) & 0x8000) == 0) {
134-
ImGui::SetWindowPos(" ErScripts", menu_pos);
135+
ImGui::SetWindowPos(std::format(" {}", window_title).c_str(), menu_pos);
135136
}
136137

137138
if (ImGui::BeginTable("Settings Table", 2, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoPadInnerX)) {
@@ -717,12 +718,20 @@ void Overlay::FPSLimitMenu() noexcept {
717718

718719
if (ImGui::BeginPopup("FPS Limiter Settings")) {
719720
if (ImGui::BeginTable("FPS Limiter Settings Table", 2, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoPadInnerX)) {
721+
ImGui::TableNextRow();
722+
ImGui::TableSetColumnIndex(0);
723+
ImGui::Text("VSync ");
724+
ImGui::TableSetColumnIndex(1);
725+
ImGui::Checkbox("##VSync", &cfg->vsyncState);
726+
720727
ImGui::TableNextRow();
721728
ImGui::TableSetColumnIndex(0);
722729
ImGui::Text("FPS Limit ");
723730
ImGui::TableSetColumnIndex(1);
724731
ImGui::PushItemWidth(100);
732+
if (cfg->vsyncState) ImGui::BeginDisabled();
725733
ImGui::SliderInt("##FpsLimiterSlide", &cfg->fpsLimiter, 60, 500, "%d fps");
734+
if (cfg->vsyncState) ImGui::EndDisabled();
726735
ImGui::PopItemWidth();
727736

728737
ImGui::EndTable();

ErScripts/Overlay.cpp

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,27 @@ void LimitFPS(int fpsLimit) {
7070

7171
void Overlay::OverlayLoop() noexcept {
7272
// Create application window
73-
WNDCLASSEXW wc = { sizeof(wc), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandleW(nullptr), nullptr, nullptr, nullptr, nullptr, L"GDI+ Hook Window Class", nullptr };
74-
::RegisterClassExW(&wc);
75-
window_handle = ::CreateWindowW(wc.lpszClassName, L"GDI+ Window (Lightshot.exe)", WS_POPUP, 0, 0, globals::width, globals::height, nullptr, nullptr, wc.hInstance, nullptr);
73+
WNDCLASSEXW wc = { sizeof(wc), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(nullptr), nullptr, nullptr, nullptr, nullptr, L"GDI+ Hook Window Class", nullptr };
74+
::RegisterClassEx(&wc);
75+
window_handle = ::CreateWindow(wc.lpszClassName, L"GDI+ Window (Lightshot.exe)", WS_POPUP, 0, 0, globals::width, globals::height, nullptr, nullptr, wc.hInstance, nullptr);
76+
77+
SetWindowLongPtr(window_handle, GWL_EXSTYLE, WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_TOOLWINDOW);
78+
SetLayeredWindowAttributes(window_handle, 0, 255, LWA_ALPHA);
79+
MARGINS margins = { -1, -1, -1, -1 };
80+
DwmExtendFrameIntoClientArea(window_handle, &margins);
7681

7782
// Initialize Direct3D
7883
if (!CreateDeviceD3D()) {
7984
CleanupDeviceD3D();
80-
::UnregisterClassW(wc.lpszClassName, wc.hInstance);
85+
::UnregisterClass(wc.lpszClassName, wc.hInstance);
8186
globals::finish = true;
8287
return;
8388
}
8489

85-
// Show the window
86-
::ShowWindow(window_handle, SW_SHOW);
90+
//::ShowWindow(window_handle, SW_SHOW);
91+
SetWindowPos(window_handle, HWND_TOPMOST, globals::posX, globals::posY, globals::width, globals::height, SWP_SHOWWINDOW | SWP_NOACTIVATE);
8792
::UpdateWindow(window_handle);
8893

89-
MARGINS margins = { -1, -1, -1, -1 };
90-
DwmExtendFrameIntoClientArea(window_handle, &margins);
91-
SetWindowLongPtrW(window_handle, GWL_EXSTYLE, WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_TOOLWINDOW);
92-
SetLayeredWindowAttributes(window_handle, 0, 255, LWA_ALPHA);
93-
//SetWindowPos(window_handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
94-
9594
// Setup Dear ImGui context
9695
IMGUI_CHECKVERSION();
9796
ImGui::CreateContext();
@@ -124,9 +123,22 @@ void Overlay::OverlayLoop() noexcept {
124123
};
125124

126125
menu_font = io.Fonts->AddFontFromFileTTF("C:/Windows/Fonts/arial.ttf", 16.f, nullptr, small_range);
126+
if (menu_font == nullptr) {
127+
Logger::logWarning("Failed to load font arial.ttf, falling back to default font");
128+
menu_font = io.Fonts->AddFontDefault();
129+
}
130+
127131
arial_font = io.Fonts->AddFontFromFileTTF("C:/Windows/Fonts/arial.ttf", 32.f, nullptr, full_range);
132+
if (arial_font == nullptr) {
133+
Logger::logWarning("Failed to load font arial.ttf, falling back to default font");
134+
arial_font = io.Fonts->AddFontDefault();
135+
}
136+
128137
bold_font = io.Fonts->AddFontFromFileTTF("C:/Windows/Fonts/ariblk.ttf", 32.f, nullptr, small_range);
129-
//weapon_font = io.Fonts->AddFontFromMemoryTTF(&shell_weapon_font, sizeof(shell_weapon_font), 32.f);
138+
if (bold_font == nullptr) {
139+
Logger::logWarning("Failed to load font ariblk.ttf, falling back to default font");
140+
bold_font = io.Fonts->AddFontDefault();
141+
}
130142

131143
// Setup Dear ImGui style
132144
ImGui::StyleColorsDark();
@@ -138,14 +150,17 @@ void Overlay::OverlayLoop() noexcept {
138150
ErScripts::GetWindowInfo(globals::width, globals::height, globals::posX, globals::posY);
139151

140152
CleanupRenderTarget();
141-
SetWindowPos(window_handle, (HWND)-1, globals::posX, globals::posY, globals::width, globals::height, 0);
142153
g_pSwapChain->ResizeBuffers(0, globals::width, globals::height, DXGI_FORMAT_UNKNOWN, 0);
143154
CreateRenderTarget();
144155

145156
std::thread(&Overlay::Handler, this).detach();
146157

147158
const float clear_color[4]{ 0 };
148-
//UINT prevWidth = globals::width, prevHeight = globals::height;
159+
160+
// Disable navigation keys (Ctrtl + Tab)
161+
ImGuiContext& g = *GImGui;
162+
g.ConfigNavWindowingKeyNext = 0;
163+
g.ConfigNavWindowingKeyPrev = 0;
149164

150165
// Main loop
151166
while (!globals::finish) {
@@ -172,17 +187,6 @@ void Overlay::OverlayLoop() noexcept {
172187
}
173188
g_SwapChainOccluded = false;
174189

175-
/*if (prevWidth != globals::width || prevHeight != globals::height) {
176-
CleanupRenderTarget();
177-
SetWindowPos(window_handle, HWND_TOPMOST, 0, 0, globals::width, globals::height, SWP_NOMOVE | SWP_NOSIZE);
178-
g_pSwapChain->ResizeBuffers(0, globals::width, globals::height, DXGI_FORMAT_UNKNOWN, 0);
179-
180-
prevWidth = globals::width;
181-
prevHeight = globals::height;
182-
183-
CreateRenderTarget();
184-
}*/
185-
186190
// Start the Dear ImGui frame
187191
ImGui_ImplDX11_NewFrame();
188192
ImGui_ImplWin32_NewFrame();
@@ -197,18 +201,6 @@ void Overlay::OverlayLoop() noexcept {
197201
if (ErScripts::GetWindowState()) {
198202
Overlay::Render();
199203

200-
/*static bool prevMenuState = false;
201-
if (globals::menuState != prevMenuState) {
202-
prevMenuState = globals::menuState;
203-
204-
if (globals::menuState) {
205-
SetWindowLongPtrW(window_handle, GWL_EXSTYLE, WS_EX_TOPMOST | WS_EX_LAYERED | WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE);
206-
}
207-
else {
208-
SetWindowLongPtrW(window_handle, GWL_EXSTYLE, WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE);
209-
}
210-
}*/
211-
212204
if (globals::menuState) Overlay::Menu();
213205
}
214206

@@ -224,7 +216,7 @@ void Overlay::OverlayLoop() noexcept {
224216
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
225217

226218
// Present
227-
HRESULT hr = g_pSwapChain->Present(/*cfg->vsyncState*/ 0, 0);
219+
HRESULT hr = g_pSwapChain->Present(cfg->vsyncState, 0);
228220
g_SwapChainOccluded = (hr == DXGI_STATUS_OCCLUDED);
229221
}
230222

ErScripts/Render.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ void Overlay::Render() noexcept {
1616
RGBColor gradient_color;
1717

1818
if (cfg->watermarkState) {
19+
bool initilizeWatermark = false;
20+
char window_title[32];
21+
22+
if (!initilizeWatermark) {
23+
// Get the current window title
24+
if (!GetConsoleTitleA(window_title, sizeof(window_title)))
25+
window_title[0] = '\0';
26+
initilizeWatermark = true;
27+
}
28+
1929
// Get FPS directly from ImGui
2030
//float fps = ImGui::GetIO().Framerate;
2131

@@ -52,7 +62,7 @@ void Overlay::Render() noexcept {
5262
timeStr += gmtOffset;
5363

5464
// Format watermark text
55-
std::string watermarkText = std::format(" ErScripts | {} | Ping {}ms | {}", globals::nickname, globals::cs2_ping, timeStr);
65+
std::string watermarkText = std::format(" {} | {} | Ping {}ms | {}", window_title, globals::nickname, globals::cs2_ping, timeStr);
5666

5767
ImGui::SetNextWindowBgAlpha(cfg->watermarkTransparency);
5868

@@ -176,6 +186,7 @@ void Overlay::Render() noexcept {
176186

177187
if (cfg->keystrokesState) {
178188
static bool isKeystrokesWindowInitilized = false;
189+
179190
ImGui::SetNextWindowBgAlpha(0.5f);
180191

181192
if (!isKeystrokesWindowInitilized) {

ErScripts/main.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
#include "ErScripts.h"
55
#include "Overlay.h"
66

7+
#define APP_VERSION "1.1.3"
8+
79
int main() {
810
if (!IsDebuggerPresent()) {
911
/* Auto updater */
10-
Updater updater("1.1.2", "emp0ry", "cs2-ErScripts", "ErScripts");
12+
Updater updater(APP_VERSION, "emp0ry", "cs2-ErScripts", "ErScripts");
1113
if (updater.checkAndUpdate())
1214
return 0;
1315

@@ -30,6 +32,8 @@ int main() {
3032
return -1;
3133
}
3234

35+
SetConsoleTitleA(std::format("ErScripts {}", APP_VERSION).c_str());
36+
3337
std::cout << "[-] *---------------------------------------*" << std::endl;
3438
std::cout << "[>] | ErScripts by emp0ry |" << std::endl;
3539
std::cout << "[>] | Github - https://github.com/emp0ry/ |" << std::endl;

0 commit comments

Comments
 (0)