Skip to content

Commit d066d2d

Browse files
committed
Add Function Angle Bind
1 parent 783b6ec commit d066d2d

File tree

15 files changed

+223
-124
lines changed

15 files changed

+223
-124
lines changed

ErScripts/CS2Binds.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,25 @@ void ErScripts::CS2Binds() {
4747
ErScripts::CommandsSender(7, std::format("callvote kick {}", globals::localPlayerSlotNumber));
4848
}
4949
}
50+
51+
static bool isBindPressed = false;
52+
if (cfg->angleBindState) {
53+
bool isPressed = GetAsyncKeyState(cfg->angleBindBind) & 0x8000;
54+
if (isPressed && !isBindPressed) {
55+
float yaw = 0.0f;
56+
if (globals::isScope) {
57+
yaw = roundf((cfg->angleBindDegree / (globals::config->sensitivity * globals::config->zoomSensitivity * 0.4444444444f) / globals::config->yaw) * 10000.0f) / 10000.0f;
58+
}
59+
else {
60+
yaw = roundf((cfg->angleBindDegree / globals::config->sensitivity / globals::config->yaw) * 10000.0f) / 10000.0f;
61+
}
62+
ErScripts::CommandsSender(7, std::format("yaw {} 1 0", yaw));
63+
isBindPressed = true;
64+
}
65+
else if (!isPressed && isBindPressed) {
66+
isBindPressed = false;
67+
}
68+
}
5069
}
5170

5271
std::this_thread::sleep_for(std::chrono::milliseconds(10));

ErScripts/Config.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ void Config::load(const std::string& filename) {
9191
read(json["chat-spammer"]["bind"], chatSpammerBind);
9292
read(json["chat-spammer"]["text"], chatSpammerText);
9393

94+
/* Angle Bind */
95+
read(json["angle-bind"]["state"], angleBindState);
96+
read(json["angle-bind"]["bind"], angleBindBind);
97+
read(json["angle-bind"]["degree"], angleBindDegree);
98+
9499
/* Watermark */
95100
read(json["watermark"]["state"], watermarkState);
96101
read(json["watermark"]["gradient"]["state"], watermarkGradientState);
@@ -204,6 +209,11 @@ void Config::save(const std::string& filename) const {
204209
json["chat-spammer"]["bind"] = chatSpammerBind;
205210
json["chat-spammer"]["text"] = chatSpammerText;
206211

212+
/* Angle Bind */
213+
json["angle-bind"]["state"] = angleBindState;
214+
json["angle-bind"]["bind"] = angleBindBind;
215+
json["angle-bind"]["degree"] = angleBindDegree;
216+
207217
/* Watermark */
208218
json["watermark"]["state"] = watermarkState;
209219
json["watermark"]["gradient"]["state"] = watermarkGradientState;

ErScripts/Config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ class Config {
9494
int chatSpammerBind{ 0 };
9595
std::string chatSpammerText{ "Enhance Your Skills with emp0ry.github.io/cs2-ErScripts/" };
9696

97+
/* Angle Bind */
98+
bool angleBindState{ false };
99+
int angleBindBind{ 0 };
100+
float angleBindDegree{ 180.0f };
101+
97102
/* Watermark */
98103
bool watermarkState{ true };
99104
bool watermarkGradientState{ true };

ErScripts/Crosshair.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ void ErScripts::Crosshair() {
99
if (ErScripts::GetWindowState() && ErScripts::GetCursorState()) {
1010

1111
// No longer needed because the print_changed_convars command is used for it
12-
/*if (globals::crosshairUpdaterState) {
12+
/*if (globals::configUpdaterState) {
1313
ErScripts::CommandsSender("host_writeconfig");
1414
std::this_thread::sleep_for(std::chrono::milliseconds(200));
1515
Logger::logInfo("Crosshair Updater");
1616
globals::crosshair = SteamTools::getCrosshairSettings("730");
1717
SteamTools::printCrosshairSettings(*globals::crosshair);
18-
globals::crosshairUpdaterState = false;
18+
globals::configUpdaterState = false;
1919
}*/
2020

21-
if (cfg->sniperCrosshairState && globals::sniperCrosshairState) {
21+
if (globals::sniperCrosshairState) {
2222
std::vector<int> pixelColor1 = GetPixelColor(globals::posX + 1, globals::posY + 1);
2323
std::vector<int> pixelColor2 = GetPixelColor(globals::posX + 1, globals::posY + globals::height - 6);
2424

@@ -37,10 +37,6 @@ void ErScripts::Crosshair() {
3737

3838
oldRecoilCrosshairState = cfg->recoilCrosshairState;
3939
}
40-
41-
if (globals::crosshairUpdaterState) {
42-
ErScripts::CommandsSender(3, "print_changed_convars");
43-
}
4440
}
4541
std::this_thread::sleep_for(std::chrono::milliseconds(10));
4642
}

ErScripts/ErScripts.cpp

Lines changed: 73 additions & 64 deletions
Large diffs are not rendered by default.

ErScripts/Globals.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ namespace globals {
1818
bool localPlayerIsActivityPlaying = false;
1919
std::string steamid = "", nickname = "";
2020

21-
bool crosshairUpdaterState = true;
22-
std::optional<SteamTools::Crosshair> crosshair;
21+
std::optional<SteamTools::Config> config;
2322

2423
int cs2_ping = 0;
2524
}

ErScripts/Globals.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ namespace globals {
2121
extern bool localPlayerIsActivityPlaying;
2222
extern std::string steamid, nickname;
2323

24-
extern bool crosshairUpdaterState;
25-
extern std::optional<SteamTools::Crosshair> crosshair;
24+
extern std::optional<SteamTools::Config> config;
2625

2726
extern int cs2_ping;
2827
}

ErScripts/Menu.cpp

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ inline const char* erScriptsExitKeyName = GetKeyName(cfg->erScriptsExitBind);
7474
inline bool erScriptsExitButtonState = false;
7575
inline const char* chatSpammerKeyName = GetKeyName(cfg->chatSpammerBind);
7676
inline bool chatSpammerButtonState = false;
77+
inline const char* angleBindKeyName = GetKeyName(cfg->angleBindBind);
78+
inline bool angleBindButtonState = false;
7779
inline char killSayText[256]{};
7880
inline char chatSpammerText[256]{};
7981
inline char killSoundFileName[256]{};
@@ -155,6 +157,7 @@ void Overlay::Menu() noexcept {
155157
RoundStartAlertMenu();
156158
AutoStopMenu();
157159
ChatSpammerMenu();
160+
AngleBindMenu();
158161
GradientManagerMenu();
159162
WatermarkMenu();
160163
FPSLimitMenu();
@@ -181,6 +184,7 @@ void Overlay::Menu() noexcept {
181184
erScriptsMenuKeyName = GetKeyName(cfg->erScriptsMenuBind);
182185
erScriptsExitKeyName = GetKeyName(cfg->erScriptsExitBind);
183186
chatSpammerKeyName = GetKeyName(cfg->chatSpammerBind);
187+
angleBindKeyName = GetKeyName(cfg->angleBindBind);
184188

185189
if (ImGui::FindWindowByName(" Bomb Timer"))
186190
ImGui::SetWindowPos(" Bomb Timer", { cfg->bombTimerPos[0], cfg->bombTimerPos[1] });
@@ -334,19 +338,19 @@ void Overlay::SniperCrosshairMenu() noexcept {
334338
ImGui::TableSetColumnIndex(0);
335339
ImGui::Checkbox("Sniper Crosshair", &cfg->sniperCrosshairState);
336340
ImGui::TableSetColumnIndex(1);
337-
if (ImageButton("##SniperCrosshairReloader", (ImTextureID)reloadTexture, { 22, 22 })) {
338-
globals::crosshairUpdaterState = true;
339-
}
341+
//if (ImageButton("##SniperCrosshairReloader", (ImTextureID)reloadTexture, { 22, 22 })) {
342+
// globals::configUpdaterState = true;
343+
//}
340344
}
341345

342346
void Overlay::RecoilCrosshairMenu() noexcept {
343347
ImGui::TableNextRow();
344348
ImGui::TableSetColumnIndex(0);
345349
ImGui::Checkbox("Recoil Crosshair", &cfg->recoilCrosshairState);
346350
ImGui::TableSetColumnIndex(1);
347-
if (ImageButton("##RecoilCrosshairReloader", (ImTextureID)reloadTexture, { 22, 22 })) {
348-
globals::crosshairUpdaterState = true;
349-
}
351+
//if (ImageButton("##RecoilCrosshairReloader", (ImTextureID)reloadTexture, { 22, 22 })) {
352+
// globals::configUpdaterState = true;
353+
//}
350354
}
351355

352356
void Overlay::RGBCrosshairMenu() noexcept {
@@ -770,6 +774,46 @@ void Overlay::ChatSpammerMenu() noexcept {
770774
}
771775
}
772776

777+
void Overlay::AngleBindMenu() noexcept {
778+
ImGui::TableNextRow();
779+
ImGui::TableSetColumnIndex(0);
780+
781+
ImGui::Checkbox("Angle Bind", &cfg->angleBindState);
782+
ImGui::TableSetColumnIndex(1);
783+
784+
if (ImageButton("##AngleBind", (ImTextureID)settingsTexture, { 22, 22 })) {
785+
ImGui::OpenPopup("Angle Bind Settings");
786+
}
787+
788+
if (ImGui::BeginPopup("Angle Bind Settings", ImGuiWindowFlags_NoResize)) {
789+
if (ImGui::BeginTable("Angle Bind Settings Table", 2, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoPadInnerX)) {
790+
// Hotkey
791+
ImGui::TableNextRow();
792+
ImGui::TableSetColumnIndex(0);
793+
ImGui::Text("Hotkey ");
794+
ImGui::TableSetColumnIndex(1);
795+
angleBindKeyName = GetKeyName(cfg->angleBindBind);
796+
if (ImGui::Button(std::format("{}##PixelTrigger", angleBindKeyName).c_str(), ImVec2(80.0f, 22.0f))) {
797+
angleBindButtonState = !angleBindButtonState;
798+
}
799+
Hotkey(&angleBindButtonState, &angleBindKeyName, &cfg->angleBindBind);
800+
801+
// Degree
802+
ImGui::TableNextRow();
803+
ImGui::TableSetColumnIndex(0);
804+
ImGui::Text("Degree ");
805+
ImGui::TableSetColumnIndex(1);
806+
ImGui::PushItemWidth(100.0f);
807+
ImGui::SliderFloat("##AngleBindDegree", &cfg->angleBindDegree, -180.f, 180.f, "%.2f");
808+
ImGui::PopItemWidth();
809+
810+
ImGui::EndTable();
811+
}
812+
813+
ImGui::EndPopup();
814+
}
815+
}
816+
773817
void Overlay::FPSLimitMenu() noexcept {
774818
ImGui::TableNextRow();
775819
ImGui::TableSetColumnIndex(0);

ErScripts/Overlay.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class Overlay {
6969
void RoundStartAlertMenu() noexcept;
7070
void AutoStopMenu() noexcept;
7171
void ChatSpammerMenu() noexcept;
72+
void AngleBindMenu() noexcept;
7273
void GradientManagerMenu() noexcept;
7374
void WatermarkMenu() noexcept;
7475
void FPSLimitMenu() noexcept;
@@ -77,7 +78,7 @@ class Overlay {
7778
//void RenderEsp() noexcept;
7879

7980
FLOAT RenderText(ImFont* font, const std::string& text, const ImVec2& position, const float size, const ImColor& color, const bool centerX, const bool centerY, const bool outline, const bool background) noexcept;
80-
void RenderCrosshair(const std::optional<SteamTools::Crosshair>& ch);
81+
void RenderCrosshair(const std::optional<SteamTools::Config>& ch);
8182
void CircularTimer(const ImVec2& pos, const float min, const float max, const float& time, const int points_count, const float radius, const float thickness, const bool top, const ImColor& color);
8283
ID3D11ShaderResourceView* LoadTextureFromPNGShellcode(unsigned char* icon_png, unsigned int icon_png_size);
8384
bool ImageButton(const char* str_id, ImTextureID imageTexture, const ImVec2& size);

ErScripts/OverlayHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ FLOAT Overlay::RenderText(ImFont* font, const std::string& text, const ImVec2& p
4545
#define XScale(x) (x * ((float)globals::width / 640.f))
4646
#define YScale(y) (y * ((float)globals::height / 480.f))
4747

48-
void Overlay::RenderCrosshair(const std::optional<SteamTools::Crosshair>& ch) {
48+
void Overlay::RenderCrosshair(const std::optional<SteamTools::Config>& ch) {
4949
if (!ch.has_value() || ch->isEmpty()) {
5050
return;
5151
}

0 commit comments

Comments
 (0)