Skip to content

Commit

Permalink
added custom crosshair
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbo committed Jan 12, 2021
1 parent c8ad68c commit 4b75183
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 8 deletions.
1 change: 1 addition & 0 deletions AssaultCube-Multihack.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="src\base.cpp" />
<ClCompile Include="src\hacks\Crosshair.cpp" />
<ClCompile Include="src\hacks\Teleport.cpp" />
<ClCompile Include="src\hooks\c2sinfo.cpp" />
<ClCompile Include="src\hooks\hooks.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions AssaultCube-Multihack.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
<ClCompile Include="src\hooks\movelocalplayer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\hacks\Crosshair.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\pch.h">
Expand Down
21 changes: 17 additions & 4 deletions src/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

HMODULE Base::Data::hModule = NULL;
HWND Base::Data::hWindow = NULL;
RECT Base::Data::WindowRect = {};
int Base::Data::WindowWidth = 0;
int Base::Data::WindowHeight = 0;
mem::module_t Base::Data::m_opengl;
mem::module_t Base::Data::m_ac_client;
mem::module_t Base::Data::m_sdl;
Expand Down Expand Up @@ -30,10 +33,20 @@ HGLRC Base::Data::glContext = NULL;
HGLRC Base::Data::oContext = NULL;
AC_Client Base::Data::game;

bool Base::Data::Settings::TeleportQueued = false;
bool Base::Data::Settings::TeleportSaveQueued = false;
float Base::Data::Settings::TeleportPosition[3];
bool Base::Data::Settings::TeleportForce[3];
bool Base::Data::Settings::EnableCrosshair = false;
float Base::Data::Settings::CrosshairLength = 10;
float Base::Data::Settings::CrosshairThickness = 3;
float Base::Data::Settings::CrosshairGap = 2;
bool Base::Data::Settings::CrosshairTop = true;
bool Base::Data::Settings::CrosshairLeft = true;
bool Base::Data::Settings::CrosshairBottom = true;
bool Base::Data::Settings::CrosshairRight = true;
float Base::Data::Settings::CrosshairColor[4] = { 1.0f, 0.0f, 0.0f, 1.0f };

bool Base::Data::Settings::TeleportQueued = false;
bool Base::Data::Settings::TeleportSaveQueued = false;
float Base::Data::Settings::TeleportPosition[3];
bool Base::Data::Settings::TeleportForce[3];

DWORD WINAPI ExitThread(LPVOID lpReserved);

Expand Down
22 changes: 18 additions & 4 deletions src/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ namespace Base
{
extern HMODULE hModule;
extern HWND hWindow;
extern RECT WindowRect;
extern int WindowWidth;
extern int WindowHeight;
extern mem::module_t m_opengl;
extern mem::module_t m_ac_client;
extern mem::module_t m_sdl;
Expand Down Expand Up @@ -50,10 +53,20 @@ namespace Base

namespace Settings
{
extern bool TeleportQueued;
extern bool TeleportSaveQueued;
extern float TeleportPosition[3];
extern bool TeleportForce[3];
extern bool EnableCrosshair;
extern float CrosshairLength;
extern float CrosshairThickness;
extern float CrosshairGap;
extern bool CrosshairTop;
extern bool CrosshairLeft;
extern bool CrosshairBottom;
extern bool CrosshairRight;
extern float CrosshairColor[4];

extern bool TeleportQueued;
extern bool TeleportSaveQueued;
extern float TeleportPosition[3];
extern bool TeleportForce[3];
}

namespace Keys
Expand All @@ -66,6 +79,7 @@ namespace Base
namespace Hacks
{
void Teleport();
void Crosshair();
}

namespace Hooks
Expand Down
54 changes: 54 additions & 0 deletions src/hacks/Crosshair.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <pch.h>
#include <base.h>

void Base::Hacks::Crosshair()
{
if (Data::Settings::EnableCrosshair)
{
ImDrawList* Draw = ImGui::GetBackgroundDrawList();
ImVec2 WindowCenter = ImVec2((float)Data::WindowWidth / 2, (float)Data::WindowHeight / 2);
ImColor LineColor = ImColor(Data::Settings::CrosshairColor[0], Data::Settings::CrosshairColor[1], Data::Settings::CrosshairColor[2], Data::Settings::CrosshairColor[3]);
float LineThickness = Data::Settings::CrosshairThickness;

if (Data::Settings::CrosshairTop)
{
ImVec2 LineTop[2] = {
ImVec2(WindowCenter.x, WindowCenter.y - Data::Settings::CrosshairGap),
ImVec2(WindowCenter.x, WindowCenter.y - Data::Settings::CrosshairGap - Data::Settings::CrosshairLength)
};

Draw->AddLine(LineTop[0], LineTop[1], LineColor, LineThickness);
}

if (Data::Settings::CrosshairLeft)
{
ImVec2 LineLeft[2] = {
ImVec2(WindowCenter.x - Data::Settings::CrosshairGap, WindowCenter.y),
ImVec2(WindowCenter.x - Data::Settings::CrosshairGap - Data::Settings::CrosshairLength, WindowCenter.y)
};

Draw->AddLine(LineLeft[0], LineLeft[1], LineColor, LineThickness);
}

if (Data::Settings::CrosshairBottom)
{
ImVec2 LineBottom[2] = {
ImVec2(WindowCenter.x, WindowCenter.y + Data::Settings::CrosshairGap),
ImVec2(WindowCenter.x, WindowCenter.y + Data::Settings::CrosshairGap + Data::Settings::CrosshairLength)
};

Draw->AddLine(LineBottom[0], LineBottom[1], LineColor, LineThickness);
}


if (Data::Settings::CrosshairRight)
{
ImVec2 LineRight[2] = {
ImVec2(WindowCenter.x + Data::Settings::CrosshairGap, WindowCenter.y),
ImVec2(WindowCenter.x + Data::Settings::CrosshairGap + Data::Settings::CrosshairLength, WindowCenter.y)
};

Draw->AddLine(LineRight[0], LineRight[1], LineColor, LineThickness);
}
}
}
19 changes: 19 additions & 0 deletions src/hooks/SwapBuffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@ BOOL __stdcall Base::Hooks::SwapBuffers(_In_ HDC hdc)
Data::InitSwapBuffers = true;
}

GetClientRect(Data::hWindow, &Data::WindowRect);
Data::WindowWidth = Data::WindowRect.right - Data::WindowRect.left;
Data::WindowHeight = Data::WindowRect.bottom - Data::WindowRect.top;

wglMakeCurrent(hdc, Data::glContext);

ImGui_ImplOpenGL2_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();

Hacks::Crosshair();

if (Data::ShowMenu)
{
ImGui::Begin("ImGui Window");
Expand All @@ -47,6 +53,19 @@ BOOL __stdcall Base::Hooks::SwapBuffers(_In_ HDC hdc)
if (ImGui::Button("Save Pos")) Data::Settings::TeleportSaveQueued = true;
if (ImGui::Button("Teleport")) Data::Settings::TeleportQueued = true;

ImGui::Checkbox("Enable Crosshair", &Data::Settings::EnableCrosshair);
if (Data::Settings::EnableCrosshair)
{
ImGui::SliderFloat("Crosshair Length", &Data::Settings::CrosshairLength, 0, 100, "%.0f");
ImGui::SliderFloat("Crosshair Thickness", &Data::Settings::CrosshairThickness, 0, 100, "%.0f");
ImGui::SliderFloat("Crosshair Gap", &Data::Settings::CrosshairGap, 0, 100, "%.0f");
ImGui::Checkbox("Crosshair Top", &Data::Settings::CrosshairTop);
ImGui::Checkbox("Crosshair Left", &Data::Settings::CrosshairLeft);
ImGui::Checkbox("Crosshair Bottom", &Data::Settings::CrosshairBottom);
ImGui::Checkbox("Crosshair Right", &Data::Settings::CrosshairRight);
ImGui::ColorEdit4("Crosshair Color", Data::Settings::CrosshairColor);
}

if (ImGui::Button("Detach"))
{
ImGui::End();
Expand Down

0 comments on commit 4b75183

Please sign in to comment.