Skip to content

Commit

Permalink
movelocalplayer function hook
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbo committed Jan 12, 2021
1 parent c07ab20 commit c8ad68c
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 52 deletions.
2 changes: 2 additions & 0 deletions AssaultCube-Multihack.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,10 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="src\base.cpp" />
<ClCompile Include="src\hacks\Teleport.cpp" />
<ClCompile Include="src\hooks\c2sinfo.cpp" />
<ClCompile Include="src\hooks\hooks.cpp" />
<ClCompile Include="src\hooks\movelocalplayer.cpp" />
<ClCompile Include="src\hooks\servertoclient.cpp" />
<ClCompile Include="src\hooks\ShowCursor.cpp" />
<ClCompile Include="src\hooks\SwapBuffers.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions AssaultCube-Multihack.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
<ClCompile Include="src\hooks\servertoclient.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\hacks\Teleport.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\hooks\movelocalplayer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\pch.h">
Expand Down
59 changes: 34 additions & 25 deletions src/base.cpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
#include <pch.h>
#include <base.h>

HMODULE Base::Data::hModule = NULL;
HWND Base::Data::hWindow = NULL;
mem::module_t Base::Data::m_opengl;
mem::module_t Base::Data::m_ac_client;
mem::module_t Base::Data::m_sdl;
mem::voidptr_t Base::Data::pSwapBuffers = nullptr;
mem::voidptr_t Base::Data::pShowCursor = nullptr;
mem::voidptr_t Base::Data::p_c2sinfo = nullptr;
mem::voidptr_t Base::Data::p_servertoclient = nullptr;
SwapBuffers_t Base::Data::oSwapBuffers = nullptr;
WndProc_t Base::Data::oWndProc = nullptr;
ShowCursor_t Base::Data::oShowCursor = nullptr;
c2sinfo_t Base::Data::o_c2sinfo = nullptr;
servertoclient_t Base::Data::o_servertoclient = nullptr;
mem::size_t Base::Data::szSwapBuffers = 5;
mem::size_t Base::Data::szShowCursor = 5;
mem::size_t Base::Data::sz_c2sinfo = 5;
mem::size_t Base::Data::sz_servertoclient = 6;
UINT Base::Data::WMKeys[0xFE];
bool Base::Data::InitSwapBuffers = false;
bool Base::Data::IsUnloaded = false;
bool Base::Data::ShowMenu = true;
HGLRC Base::Data::glContext = NULL;
HGLRC Base::Data::oContext = NULL;
AC_Client Base::Data::game;
HMODULE Base::Data::hModule = NULL;
HWND Base::Data::hWindow = NULL;
mem::module_t Base::Data::m_opengl;
mem::module_t Base::Data::m_ac_client;
mem::module_t Base::Data::m_sdl;
mem::voidptr_t Base::Data::pSwapBuffers = nullptr;
mem::voidptr_t Base::Data::pShowCursor = nullptr;
mem::voidptr_t Base::Data::p_c2sinfo = nullptr;
mem::voidptr_t Base::Data::p_servertoclient = nullptr;
mem::voidptr_t Base::Data::p_movelocalplayer = nullptr;
SwapBuffers_t Base::Data::oSwapBuffers = nullptr;
WndProc_t Base::Data::oWndProc = nullptr;
ShowCursor_t Base::Data::oShowCursor = nullptr;
c2sinfo_t Base::Data::o_c2sinfo = nullptr;
servertoclient_t Base::Data::o_servertoclient = nullptr;
movelocalplayer_t Base::Data::o_movelocalplayer = nullptr;
mem::size_t Base::Data::szSwapBuffers = 5;
mem::size_t Base::Data::szShowCursor = 5;
mem::size_t Base::Data::sz_c2sinfo = 5;
mem::size_t Base::Data::sz_servertoclient = 6;
mem::size_t Base::Data::sz_movelocalplayer = 8;
UINT Base::Data::WMKeys[0xFE];
bool Base::Data::InitSwapBuffers = false;
bool Base::Data::IsUnloaded = false;
bool Base::Data::ShowMenu = true;
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];

DWORD WINAPI ExitThread(LPVOID lpReserved);

Expand All @@ -41,6 +49,7 @@ void Base::Init(HMODULE hMod)
Data::pShowCursor = mem::in::get_symbol(Data::m_sdl, "SDL_ShowCursor");
Data::p_c2sinfo = (mem::voidptr_t)Data::game.c2sinfo;
Data::p_servertoclient = (mem::voidptr_t)Data::game.servertoclient;
Data::p_movelocalplayer = (mem::voidptr_t)Data::game.movelocalplayer;
Hooks::Init();
}

Expand Down
61 changes: 34 additions & 27 deletions src/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,41 @@ namespace Base

namespace Data
{
extern HMODULE hModule;
extern HWND hWindow;
extern mem::module_t m_opengl;
extern mem::module_t m_ac_client;
extern mem::module_t m_sdl;
extern mem::voidptr_t pSwapBuffers;
extern mem::voidptr_t pShowCursor;
extern mem::voidptr_t p_c2sinfo;
extern mem::voidptr_t p_servertoclient;
extern SwapBuffers_t oSwapBuffers;
extern ShowCursor_t oShowCursor;
extern WndProc_t oWndProc;
extern c2sinfo_t o_c2sinfo;
extern servertoclient_t o_servertoclient;
extern mem::size_t szSwapBuffers;
extern mem::size_t szShowCursor;
extern mem::size_t sz_c2sinfo;
extern mem::size_t sz_servertoclient;
extern UINT WMKeys[0xFE];
extern bool InitSwapBuffers;
extern bool IsUnloaded;
extern bool ShowMenu;
extern HGLRC glContext;
extern HGLRC oContext;
extern AC_Client game;
extern HMODULE hModule;
extern HWND hWindow;
extern mem::module_t m_opengl;
extern mem::module_t m_ac_client;
extern mem::module_t m_sdl;
extern mem::voidptr_t pSwapBuffers;
extern mem::voidptr_t pShowCursor;
extern mem::voidptr_t p_c2sinfo;
extern mem::voidptr_t p_servertoclient;
extern mem::voidptr_t p_movelocalplayer;
extern SwapBuffers_t oSwapBuffers;
extern ShowCursor_t oShowCursor;
extern WndProc_t oWndProc;
extern c2sinfo_t o_c2sinfo;
extern servertoclient_t o_servertoclient;
extern movelocalplayer_t o_movelocalplayer;
extern mem::size_t szSwapBuffers;
extern mem::size_t szShowCursor;
extern mem::size_t sz_c2sinfo;
extern mem::size_t sz_servertoclient;
extern mem::size_t sz_movelocalplayer;
extern UINT WMKeys[0xFE];
extern bool InitSwapBuffers;
extern bool IsUnloaded;
extern bool ShowMenu;
extern HGLRC glContext;
extern HGLRC oContext;
extern AC_Client game;

namespace Settings
{

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

namespace Keys
Expand All @@ -59,7 +65,7 @@ namespace Base

namespace Hacks
{

void Teleport();
}

namespace Hooks
Expand All @@ -71,5 +77,6 @@ namespace Base
int SDLCALL ShowCursor(int toggle);
void c2sinfo(playerent* d);
void servertoclient(int chan, uchar* buf, int len, bool demo);
void movelocalplayer();
}
}
32 changes: 32 additions & 0 deletions src/hacks/Teleport.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <pch.h>
#include <base.h>

/* Not yet implemented */

void Base::Hacks::Teleport()
{
if (Data::Settings::TeleportSaveQueued)
{
Data::Settings::TeleportPosition[0] = Data::game.player1->o.x;
Data::Settings::TeleportPosition[1] = Data::game.player1->o.y;
Data::Settings::TeleportPosition[2] = Data::game.player1->o.z;
Data::Settings::TeleportSaveQueued = false;
}

if (Data::Settings::TeleportQueued)
{
Data::game.player1->o.x = Data::Settings::TeleportPosition[0];
Data::game.player1->o.y = Data::Settings::TeleportPosition[1];
Data::game.player1->o.z = Data::Settings::TeleportPosition[2];
Data::Settings::TeleportQueued = false;
}

if(Data::Settings::TeleportForce[0])
Data::game.player1->o.x = Data::Settings::TeleportPosition[0];

if (Data::Settings::TeleportForce[1])
Data::game.player1->o.x = Data::Settings::TeleportPosition[1];

if (Data::Settings::TeleportForce[2])
Data::game.player1->o.x = Data::Settings::TeleportPosition[2];
}
8 changes: 8 additions & 0 deletions src/hooks/SwapBuffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ BOOL __stdcall Base::Hooks::SwapBuffers(_In_ HDC hdc)
{
ImGui::Begin("ImGui Window");
ImGui::Text("Test ImGUI Window");

ImGui::SliderFloat3("Teleport Position", Data::Settings::TeleportPosition, -5000, 5000);
ImGui::Checkbox("Force Teleport X", &Data::Settings::TeleportForce[0]);
ImGui::Checkbox("Force Teleport Y", &Data::Settings::TeleportForce[1]);
ImGui::Checkbox("Force Teleport Z", &Data::Settings::TeleportForce[2]);
if (ImGui::Button("Save Pos")) Data::Settings::TeleportSaveQueued = true;
if (ImGui::Button("Teleport")) Data::Settings::TeleportQueued = true;

if (ImGui::Button("Detach"))
{
ImGui::End();
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ void Base::Hooks::Init()
Data::oShowCursor = (ShowCursor_t)mem::in::detour_trampoline(Data::pShowCursor, (mem::voidptr_t)Hooks::ShowCursor, Data::szShowCursor, mem::MEM_DT_M1);
Data::o_c2sinfo = (c2sinfo_t)mem::in::detour_trampoline(Data::p_c2sinfo, (mem::voidptr_t)Hooks::c2sinfo, Data::sz_c2sinfo, mem::MEM_DT_M1);
Data::o_servertoclient = (servertoclient_t)mem::in::detour_trampoline(Data::p_servertoclient, (mem::voidptr_t)Hooks::servertoclient, Data::sz_servertoclient, mem::MEM_DT_M1);
Data::o_movelocalplayer = (movelocalplayer_t)mem::in::detour_trampoline(Data::p_movelocalplayer, (mem::voidptr_t)Hooks::movelocalplayer, Data::sz_movelocalplayer);
}

void Base::Hooks::Shutdown()
{
SetWindowLongPtr(Data::hWindow, GWL_WNDPROC, (LONG_PTR)Data::oWndProc);
mem::in::detour_restore(Data::p_movelocalplayer, (mem::byte_t*)Data::o_movelocalplayer, Data::sz_movelocalplayer);
mem::in::detour_restore(Data::p_servertoclient, (mem::byte_t*)Data::o_servertoclient, Data::sz_servertoclient);
mem::in::detour_restore(Data::p_c2sinfo, (mem::byte_t*)Data::o_c2sinfo, Data::sz_c2sinfo);
mem::in::detour_restore(Data::pSwapBuffers, (mem::byte_t*)Data::oSwapBuffers, Data::szSwapBuffers);
mem::in::detour_restore(Data::pShowCursor, (mem::byte_t*)Data::oShowCursor, Data::szShowCursor);
}
7 changes: 7 additions & 0 deletions src/hooks/movelocalplayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <pch.h>
#include <base.h>

void Base::Hooks::movelocalplayer()
{
return Data::o_movelocalplayer();
}

0 comments on commit c8ad68c

Please sign in to comment.