// This code creates a cheat DLL for your game using the provided offsets
// It includes an ESP feature to draw boxes and skeletons around enemies and teammates
// The colors of the ESP can be changed using an ImGui menu
// It also has a triggerbot feature to automatically shoot when the crosshair is over an enemy
// The triggerbot delay can be adjusted in the ImGui menu as well
// The menu is toggled with the Insert key and the DLL cleans up after injection
#include <Windows.h>
#include <d3d11.h>
#include <imgui.h>
#include <imgui_impl_dx11.h>
#include <imgui_impl_win32.h>
#include "Offsets.h"
// ESP colors
ImVec4 enemyColor = ImVec4(1.0f, 0.0f, 0.0f, 1.0f); // Red
ImVec4 teamColor = ImVec4(0.0f, 1.0f, 0.0f, 1.0f); // Green
// Triggerbot delay in ms
int triggerbotDelay = 100;
// Toggle menu state
bool showMenu = false;
// DirectX device and context pointers
ID3D11Device* g_pd3dDevice = NULL;
ID3D11DeviceContext* g_pd3dDeviceContext = NULL;
// Original WndProc to restore on eject
WNDPROC oWndProc;
// Function to draw ESP box and skeleton
void DrawESP(Entity* entity, ImVec4 color)
{
// Get entity position and bone positions
Vector3 entityPos = entity->GetPosition();
Vector3 head = entity->GetBonePosition(8);
Vector3 neck = entity->GetBonePosition(7);
Vector3 chest = entity->GetBonePosition(6);
Vector3 pelvis = entity->GetBonePosition(0);
// Convert 3D positions to 2D screen positions
Vector2 headScreen, neckScreen, chestScreen, pelvisScreen;
if (WorldToScreen(head, headScreen) &&
WorldToScreen(neck, neckScreen) &&
WorldToScreen(chest, chestScreen) &&
WorldToScreen(pelvis, pelvisScreen))
{
// Calculate box dimensions
float width = abs(headScreen.x - pelvisScreen.x) * 0.3f;
float height = abs(headScreen.y - pelvisScreen.y);
// Draw box
DrawBox(pelvisScreen.x - width, headScreen.y, width*2, height, color);
// Draw skeleton
DrawLine(headScreen, neckScreen, color);
DrawLine(neckScreen, chestScreen, color);
DrawLine(chestScreen, pelvisScreen, color);
}
}
// Triggerbot function
void Triggerbot(Entity* localPlayer, Entity* entity)
{
// Check if entity is valid and an enemy
if (entity && entity->IsAlive() && !entity->IsDormant() &&
entity->GetTeam() != localPlayer->GetTeam())
{
// Get crosshair position
Vector2 crosshair = Vector2(GetSystemMetrics(SM_CXSCREEN)/2, GetSystemMetrics(SM_CYSCREEN)/2);
// Get entity head position
Vector3 head = entity->GetBonePosition(8);
Vector2 headScreen;
if (WorldToScreen(head, headScreen))
{
// Check if crosshair is over head
if (crosshair.Distance(headScreen) < 5)
{
// Shoot with delay
Sleep(triggerbotDelay);
localPlayer->ForceAttack();
}
}
}
}
// Render function called every frame
void Render()
{
// Get local player
Entity* localPlayer = GetLocalPlayer();
if (!localPlayer)
return;
// Loop through all entities
for (int i = 1; i <= GetMaxClients(); i++)
{
Entity* entity = GetEntityByIndex(i);
if (entity)
{
// Draw ESP on entities
if (entity->IsAlive() && !entity->IsDormant())
{
if (entity->GetTeam() == localPlayer->GetTeam())
DrawESP(entity, teamColor);
else
DrawESP(entity, enemyColor);
}
// Run triggerbot
Triggerbot(localPlayer, entity);
}
}
// Toggle menu with Insert key
if (GetAsyncKeyState(VK_INSERT) & 1)
showMenu = !showMenu;
// Render ImGui menu
if (showMenu)
{
ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
ImGui::Begin("Cheat Menu");
ImGui::ColorEdit4("Enemy Color", (float*)&enemyColor);
ImGui::ColorEdit4("Team Color", (float*)&teamColor);
ImGui::SliderInt("Triggerbot Delay (ms)", &triggerbotDelay, 0, 1000);
ImGui::End();
ImGui::Render();
g_pd3dDeviceContext->OMSetRenderTargets(1, &g_mainRenderTargetView, NULL);
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
}
}
// Hook for EndScene to draw our visuals
HRESULT __stdcall hkEndScene(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags)
{
static bool init = false;
if (!init)
{
// Get device and context pointers
if (SUCCEEDED(pSwapChain->GetDevice(__uuidof(ID3D11Device), (void**)&g_pd3dDevice)))
{
g_pd3dDevice->GetImmediateContext(&g_pd3dDeviceContext);
DXGI_SWAP_CHAIN_DESC sd;
pSwapChain->GetDesc(&sd);
g_hWnd = sd.OutputWindow;
// Setup ImGui
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
ImGui::StyleColorsDark();
ImGui_ImplWin32_Init(g_hWnd);
ImGui_ImplDX11_Init(g_pd3dDevice, g_pd3dDeviceContext);
}
init = true;
}
// Render our visuals
Render();
return oEndScene(pSwapChain, SyncInterval, Flags);
}
// Hook for WndProc to handle input
extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT __stdcall WndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
// Pass input to ImGui
if (ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam))
return true;
// Call original WndProc
return CallWindowProc(oWndProc, hWnd, uMsg, wParam, lParam);
}
// Entry point
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
// Hook EndScene
IDXGISwapChain* pSwapChain;
D3D11_VIEWPORT vp;
UINT numVPs = 1;
g_pD3D11DeviceContext->RSGetViewports(&numVPs, &vp);
DXGI_SWAP_CHAIN_DESC sd;
pSwapChain->GetDesc(&sd);
g_hWnd = sd.OutputWindow;
oWndProc = (WNDPROC)SetWindowLongPtr(g_hWnd, GWLP_WNDPROC, (LONG_PTR)WndProc);
oEndScene = (tEndScene)TrampHook((char*)pSwapChain, (char*)hkEndScene, 18);
// Update offsets
Offset::UpdateOffsets();
break;
}
case DLL_PROCESS_DETACH:
{
// Unhook EndScene
TrampHook((char*)pSwapChain, (char*)oEndScene, 18);
// Restore original WndProc
SetWindowLongPtr(g_hWnd, GWLP_WNDPROC, (LONG_PTR)oWndProc);
// Cleanup ImGui
ImGui_ImplDX11_Shutdown();
ImGui_ImplWin32_Shutdown();
ImGui::DestroyContext();
break;
}
}
return TRUE;
} Write, Run & Share C Language code online using OneCompiler's C online compiler for free. It's one of the robust, feature-rich online compilers for C language, running the latest C version which is C18. Getting started with the OneCompiler's C editor is really simple and pretty fast. The editor shows sample boilerplate code when you choose language as 'C' and start coding!
OneCompiler's C online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample C program which takes name as input and print your name with hello.
#include <stdio.h>
int main()
{
char name[50];
printf("Enter name:");
scanf("%s", name);
printf("Hello %s \n" , name );
return 0;
}
C language is one of the most popular general-purpose programming language developed by Dennis Ritchie at Bell laboratories for UNIX operating system. The initial release of C Language was in the year 1972. Most of the desktop operating systems are written in C Language.
When ever you want to perform a set of operations based on a condition if-else is used.
if(conditional-expression) {
// code
} else {
// code
}
You can also use if-else for nested Ifs and if-else-if ladder when multiple conditions are to be performed on a single variable.
Switch is an alternative to if-else-if ladder.
switch(conditional-expression) {
case value1:
// code
break; // optional
case value2:
// code
break; // optional
...
default:
// code to be executed when all the above cases are not matched;
}
For loop is used to iterate a set of statements based on a condition.
for(Initialization; Condition; Increment/decrement){
// code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while(condition) {
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition);
Array is a collection of similar data which is stored in continuous memory addresses. Array values can be fetched using index. Index starts from 0 to size-1.
data-type array-name[size];
data-type array-name[size][size];
Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
Two types of functions are present in C
Library functions are the in-built functions which are declared in header files like printf(),scanf(),puts(),gets() etc.,
User defined functions are the ones which are written by the programmer based on the requirement.
return_type function_name(parameters);
function_name (parameters)
return_type function_name(parameters) {
//code
}