Skip to content
This repository was archived by the owner on Jan 31, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "ext/imgui"]
path = ext/imgui
url = https://github.com/iWanheda/imgui.git
24 changes: 23 additions & 1 deletion based.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,15 @@
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)build\</OutDir>
<IntDir>$(SolutionDir)build\intermediates\</IntDir>
<IncludePath>$(DXSDK_DIR)Include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x86;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)build\</OutDir>
<IntDir>$(SolutionDir)build\intermediates\</IntDir>
<IncludePath>$(DXSDK_DIR)Include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x86;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
Expand Down Expand Up @@ -147,6 +151,13 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="ext\imgui\imgui.cpp" />
<ClCompile Include="ext\imgui\imgui_demo.cpp" />
<ClCompile Include="ext\imgui\imgui_draw.cpp" />
<ClCompile Include="ext\imgui\imgui_impl_dx9.cpp" />
<ClCompile Include="ext\imgui\imgui_impl_win32.cpp" />
<ClCompile Include="ext\imgui\imgui_tables.cpp" />
<ClCompile Include="ext\imgui\imgui_widgets.cpp" />
<ClCompile Include="ext\minhook\buffer.c" />
<ClCompile Include="ext\minhook\hde\hde32.c" />
<ClCompile Include="ext\minhook\hde\hde64.c" />
Expand All @@ -156,10 +167,19 @@
<ClCompile Include="src\core\hooks.cpp" />
<ClCompile Include="src\core\interfaces.cpp" />
<ClCompile Include="src\core\netvars.cpp" />
<ClCompile Include="src\gui\cmenu.cpp" />
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\util\memory.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ext\imgui\imconfig.h" />
<ClInclude Include="ext\imgui\imgui.h" />
<ClInclude Include="ext\imgui\imgui_impl_dx9.h" />
<ClInclude Include="ext\imgui\imgui_impl_win32.h" />
<ClInclude Include="ext\imgui\imgui_internal.h" />
<ClInclude Include="ext\imgui\imstb_rectpack.h" />
<ClInclude Include="ext\imgui\imstb_textedit.h" />
<ClInclude Include="ext\imgui\imstb_truetype.h" />
<ClInclude Include="ext\minhook\buffer.h" />
<ClInclude Include="ext\minhook\hde\hde32.h" />
<ClInclude Include="ext\minhook\hde\hde64.h" />
Expand All @@ -172,9 +192,11 @@
<ClInclude Include="src\core\hooks.h" />
<ClInclude Include="src\core\interfaces.h" />
<ClInclude Include="src\core\netvars.h" />
<ClInclude Include="src\gui\cmenu.hpp" />
<ClInclude Include="src\util\hash.h" />
<ClInclude Include="src\util\memory.h" />
<ClInclude Include="src\valve\cclientclass.h" />
<ClInclude Include="src\valve\ccolor.h" />
<ClInclude Include="src\valve\centity.h" />
<ClInclude Include="src\valve\iglowmanager.h" />
<ClInclude Include="src\valve\ckeyvalues.h" />
Expand All @@ -197,4 +219,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
54 changes: 54 additions & 0 deletions based.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,30 @@
<ClCompile Include="src\core\globals.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ext\imgui\imgui.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ext\imgui\imgui_demo.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ext\imgui\imgui_draw.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ext\imgui\imgui_impl_dx9.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ext\imgui\imgui_impl_win32.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ext\imgui\imgui_tables.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ext\imgui\imgui_widgets.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\gui\cmenu.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ext\minhook\hde\hde32.h">
Expand Down Expand Up @@ -149,5 +173,35 @@
<ClInclude Include="src\valve\cutlvector.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ext\imgui\imconfig.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ext\imgui\imgui.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ext\imgui\imgui_impl_dx9.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ext\imgui\imgui_impl_win32.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ext\imgui\imgui_internal.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ext\imgui\imstb_rectpack.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ext\imgui\imstb_textedit.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ext\imgui\imstb_truetype.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\valve\ccolor.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\gui\cmenu.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions ext/imgui
Submodule imgui added at 71bba2
92 changes: 92 additions & 0 deletions src/core/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

// include minhook for epic hookage
#include "../../ext/minhook/minhook.h"
#include "../gui/cmenu.hpp"

#include <intrin.h>

// Instance our menu class, perhaps we could use smart pointers?
static CMenu menu;

void hooks::Setup() noexcept
{
MH_Initialize();
Expand All @@ -23,6 +27,20 @@ void hooks::Setup() noexcept
reinterpret_cast<void**>(&CreateMoveOriginal)
);

// EndScene hook
MH_CreateHook(
memory::Get(interfaces::device, 42),
&EndScene,
reinterpret_cast<void**>(&EndSceneOriginal)
);

// Reset hook
MH_CreateHook(
memory::Get(interfaces::device, 16),
&Reset,
reinterpret_cast<void**>(&ResetOriginal)
);

MH_EnableHook(MH_ALL_HOOKS);
}

Expand Down Expand Up @@ -70,3 +88,77 @@ bool __stdcall hooks::CreateMove(float frameTime, CUserCmd* cmd) noexcept

return false;
}

LONG __stdcall hooks::EndScene(IDirect3DDevice9* device) noexcept
{
static const auto retAddr = _ReturnAddress();
const auto result = EndSceneOriginal(device, device);

if (_ReturnAddress() == retAddr)
return result;

// This prevents OBS from capturing our ESP/Menu, of course cazz you will not want to have this XD
// You can change this in main.cpp or just click F12 and go to definition
#if CAZZ_BIG_MAN == FALSE
static std::uintptr_t gameOverlayRetAddr = 0;

if (!gameOverlayRetAddr)
{
MEMORY_BASIC_INFORMATION memInfo;
VirtualQuery(_ReturnAddress(), &memInfo, sizeof(MEMORY_BASIC_INFORMATION));

char fileName[MAX_PATH];
GetModuleFileNameA(reinterpret_cast<HMODULE>(memInfo.AllocationBase), fileName, MAX_PATH);

if (strstr(fileName, "gameoverlay"))
gameOverlayRetAddr = reinterpret_cast<std::uintptr_t>(_ReturnAddress());
}

if (gameOverlayRetAddr != reinterpret_cast<std::uintptr_t>(_ReturnAddress()))
return result;
#endif

menu.Setup(device);

ImGui_ImplDX9_NewFrame();
ImGui_ImplWin32_NewFrame();

ImGui::NewFrame();

// Exercise: Get Input class and disable game input when the menu is open :D
menu.Render();

ImGui::EndFrame();

ImGui::Render();
ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());

return result;
}

HRESULT __stdcall hooks::Reset(IDirect3DDevice9* device, D3DPRESENT_PARAMETERS* params) noexcept
{
ImGui_ImplDX9_InvalidateDeviceObjects();
const auto result = ResetOriginal(device, device, params);
ImGui_ImplDX9_CreateDeviceObjects();

return result;
}

WNDPROC oldWindow = reinterpret_cast<WNDPROC>(
SetWindowLongPtr(FindWindowA("Valve001", nullptr), GWL_WNDPROC, reinterpret_cast<LONG_PTR>(hooks::WndProcess))
);

extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(
HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

LRESULT __stdcall hooks::WndProcess(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (GetAsyncKeyState(GUI_KEY) & 1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use GetAsyncKeyState in WndProc??? Just check wParam(?) and uMsg 😟

menu.Press();

if (menu.IsOpen() && ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam))
return 1L;

return CallWindowProc(oldWindow, hWnd, uMsg, wParam, lParam);
}
19 changes: 19 additions & 0 deletions src/core/hooks.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#pragma once
#include "interfaces.h"

#include <d3d9.h>

#include "../../ext/imgui/imgui.h"
#include "../../ext/imgui/imgui_impl_win32.h"
#include "../../ext/imgui/imgui_impl_dx9.h"

namespace hooks
{
// call once to emplace all hooks
Expand All @@ -18,4 +24,17 @@ namespace hooks
using CreateMoveFn = bool(__thiscall*)(IClientModeShared*, float, CUserCmd*) noexcept;
inline CreateMoveFn CreateMoveOriginal = nullptr;
bool __stdcall CreateMove(float frameTime, CUserCmd* cmd) noexcept;

// EndScene hook for our imgay menu
using EndSceneFn = long(__thiscall*)(void*, IDirect3DDevice9*) noexcept;
inline EndSceneFn EndSceneOriginal = nullptr;
long __stdcall EndScene(IDirect3DDevice9*) noexcept;

// Reset hook
using ResetFn = HRESULT(__thiscall*)(void*, IDirect3DDevice9*, D3DPRESENT_PARAMETERS*) noexcept;
inline ResetFn ResetOriginal = nullptr;
HRESULT __stdcall Reset(IDirect3DDevice9*, D3DPRESENT_PARAMETERS*) noexcept;

// WndProc hook
static LRESULT __stdcall WndProcess(HWND, UINT, WPARAM, LPARAM);
}
1 change: 1 addition & 0 deletions src/core/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void interfaces::Setup() noexcept
studioRender = Capture<IStudioRender>("studiorender.dll", "VStudioRender026");
engine = Capture<IVEngineClient>("engine.dll", "VEngineClient014");
modelInfo = Capture<IVModelInfo>("engine.dll", "VModelInfoClient004");
device = **reinterpret_cast<IDirect3DDevice9***>(memory::PatternScan("shaderapidx9.dll", "A1 ? ? ? ? 50 8B 08 FF 51 0C") + 0x1);

// get the exported KeyValuesSystem function
if (const HINSTANCE handle = GetModuleHandle("vstdlib.dll"))
Expand Down
5 changes: 5 additions & 0 deletions src/core/interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include "../valve/ivengineclient.h"
#include "../valve/ivmodelinfo.h"

#include "../../ext/imgui/imgui.h"
#include "../../ext/imgui/imgui_impl_dx9.h"
#include "../../ext/imgui/imgui_impl_win32.h"

// learn more about interfaces -> https://www.youtube.com/watch?v=C0wGdwnaArA
namespace interfaces
{
Expand All @@ -34,6 +38,7 @@ namespace interfaces
inline IStudioRender* studioRender = nullptr;
inline IVEngineClient* engine = nullptr;
inline IVModelInfo* modelInfo = nullptr;
inline IDirect3DDevice9* device = nullptr;

// other
inline void* keyValuesSystem = nullptr;
Expand Down
46 changes: 46 additions & 0 deletions src/gui/cmenu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "cmenu.hpp"

void CMenu::Setup(IDirect3DDevice9* device) noexcept
{
if (!dxSetup)
{
ImGui::CreateContext();

ImGui_ImplWin32_Init(FindWindowA("Valve001", nullptr));
ImGui_ImplDX9_Init(device);

// Here you can initialize
// textures, fonts, etc...

dxSetup = true;
}
}

void CMenu::Render() noexcept
{
// If the menu isn't open
if (!IsOpen()) return;

ImGui::SetNextWindowSize(ImVec2(370.f, 420.f));
ImGui::Begin("based", &guiOpen, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize);
{
// I would make this const but I can't cuz reference :')
static bool cazzAwesome = true;
// This one I'll let you choose
static float cazzDSize = 2;

ImGui::Checkbox("cazz is fucking awesome", &cazzAwesome);
ImGui::SliderFloat("cazz's d size", &cazzDSize, 2, 45);
}
ImGui::End();
}

void CMenu::Press() noexcept
{
guiOpen = !guiOpen;
}

bool CMenu::IsOpen() noexcept
{
return guiOpen;
}
23 changes: 23 additions & 0 deletions src/gui/cmenu.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include "../../ext/imgui/imgui.h"
#include "../../ext/imgui/imgui_impl_win32.h"
#include "../../ext/imgui/imgui_impl_dx9.h"

#include <Windows.h>
#include <cstdint>

inline constexpr std::uint8_t GUI_KEY = VK_INSERT;

class CMenu
{
public:
void Setup(IDirect3DDevice9*) noexcept;
void Render() noexcept;
void Press() noexcept;
bool IsOpen() noexcept;

private:
bool guiOpen = false,
dxSetup = false;
};
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// expose our cheat to main.cpp
#include "core/hooks.h"

#define CAZZ_BIG_MAN FALSE

// setup our cheat & unload it when exit key is pressed
DWORD WINAPI Setup(LPVOID lpParam)
{
Expand Down