#include <Windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
#include "detours.h"	//detours 3.0 (google microsoft detours)
#pragma comment (lib, "detours.lib") //detours 3.0
#include <vector>
using namespace std;
 
//==========================================================================================================================
 
signed int __stdcall hkDrawIndexedPrimitive(LPDIRECT3DDEVICE9 Device, D3DPRIMITIVETYPE Type, INT BaseVertexIndex, UINT MinIndex, UINT NumVertices, UINT StartIndex, UINT primCount);
typedef HRESULT(__stdcall* DrawIndexedPrimitive_t)(LPDIRECT3DDEVICE9, D3DPRIMITIVETYPE, INT, UINT, UINT, UINT, UINT);
DrawIndexedPrimitive_t OrigDrawIndexedPrimitive;
 
signed int __stdcall hkEndScene(LPDIRECT3DDEVICE9 Device);
typedef HRESULT (__stdcall* EndScene_t)(LPDIRECT3DDEVICE9);
EndScene_t OrigEndScene;
 
//==========================================================================================================================
 
// settings
DWORD aimkey=VK_SHIFT;				//aimkey (google Virtual-Key Codes)
int aimfov=20;						//aim fov in %
int aimheight=130;					//adjust aim height, 0 = feet , 130 neck??
int aimsmooth=5;					//aim smooth (mouse accel messes with aiming)
 
// get stride
IDirect3DVertexBuffer9 *pStreamData;
UINT XOffset = 0;
UINT Stride = 0;
 
// get pshader
IDirect3DPixelShader9* pShader;
UINT psData;
 
//get vshader
IDirect3DVertexShader9* vShader;
UINT vsData;
 
//get viewport
D3DVIEWPORT9 viewport;
 
//models
bool MODELS;
 
//==========================================================================================================================
 
void DrawPoint(LPDIRECT3DDEVICE9 Device, int baseX, int baseY, int baseW, int baseH, D3DCOLOR Cor)
{
	D3DRECT BarRect = { baseX, baseY, baseX + baseW, baseY + baseH };
	Device->Clear(1, &BarRect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, Cor, 0,  0);
}
 
struct ModelInfo_t
{
    D3DXVECTOR3 Position2D;
    D3DXVECTOR3 Position3D;
	float CrosshairDistance;
};
vector<ModelInfo_t*>ModelInfo;
 
float GetDistance( float Xx, float Yy, float xX, float yY )
{
    return sqrt( ( yY-Yy ) * ( yY-Yy ) + ( xX-Xx ) * ( xX-Xx ) );
}
 
void AddModel(LPDIRECT3DDEVICE9 Device)
{
	ModelInfo_t* pModel = new ModelInfo_t;
 
	D3DXMATRIX matrix, m1;
	D3DXVECTOR4 position;
	D3DXVECTOR4 input;
	Device->GetViewport(&viewport);
	Device->GetVertexShaderConstantF(0, matrix, 4);
 
	input.y = (float)aimheight;
 
	D3DXMatrixTranspose(&matrix, &matrix);
	D3DXVec4Transform(&position, &input, &matrix);
 
	position.x = input.x * matrix._11 + input.y * matrix._21 + input.z * matrix._31 + matrix._41;
	position.y = input.x * matrix._12 + input.y * matrix._22 + input.z * matrix._32 + matrix._42;
	position.z = input.x * matrix._13 + input.y * matrix._23 + input.z * matrix._33 + matrix._43;
	position.w = input.x * matrix._14 + input.y * matrix._24 + input.z * matrix._34 + matrix._44;
 
	pModel->Position2D.x = ((position.x / position.w) * (viewport.Width / 2)) + viewport.X + (viewport.Width / 2);
	pModel->Position2D.y = viewport.Y + (viewport.Height / 2) - ((position.y / position.w) * (viewport.Height / 2));
 
	ModelInfo.push_back(pModel);
}
 
HRESULT __stdcall myDrawIndexedPrimitive(LPDIRECT3DDEVICE9 Device, D3DPRIMITIVETYPE Type, INT BaseVertexIndex, UINT MinIndex, UINT nVertices, UINT sIndex, UINT pCount)
{
	//get stride
    if(Device->GetStreamSource(0, &pStreamData, &XOffset, &Stride) == D3D_OK)
    if( pStreamData != NULL ){ pStreamData->Release(); pStreamData = NULL; }
 
	//get psdata
	if (SUCCEEDED(Device->GetPixelShader(&pShader)))
		if (pShader != NULL)
			if (SUCCEEDED(pShader->GetFunction(NULL, &psData)))
				if (pShader != NULL){ pShader->Release(); pShader = NULL; }
 
	//get vsdata
	if (SUCCEEDED(Device->GetVertexShader(&vShader)))
		if (vShader != NULL)
			if (SUCCEEDED(vShader->GetFunction(NULL, &vsData)))
				if (vShader != NULL){ vShader->Release(); vShader = NULL; }
 
	//get models
	if (Stride == 72)//if (Stride == 72 && psData == 4720 && vsData == 656)
		MODELS = true;
	else MODELS = false;
	
	//worldtoscreen
	if(MODELS)
	{
		AddModel(Device);
	}
 
	//wallhack
	if (Stride == 72)
	{
		Device->SetRenderState(D3DRS_ZENABLE, FALSE);
		OrigDrawIndexedPrimitive(Device, Type, BaseVertexIndex, MinIndex, nVertices, sIndex, pCount);
		Device->SetRenderState(D3DRS_ZENABLE, TRUE);
	}
 
    return OrigDrawIndexedPrimitive(Device, Type, BaseVertexIndex, MinIndex, nVertices, sIndex, pCount);
}
 
HRESULT __stdcall myEndScene(LPDIRECT3DDEVICE9 Device)
{
	if (ModelInfo.size() != NULL)
	{
		UINT BestTarget = -1;
		DOUBLE fClosestPos = 99999;
 
		for (size_t i = 0; i < ModelInfo.size(); i += 1)
		{
			//drawpoint on targets (Esp)
			DrawPoint(Device, (int)ModelInfo[i]->Position2D.x, (int)ModelInfo[i]->Position2D.y, 8, 8, 0xFFFF0000);
 
			//get screen center
			float ScreenCenterX = viewport.Width / 2.0f;
			float ScreenCenterY = viewport.Height / 2.0f;
 
			//aimfov
			float radiusx = aimfov * (ScreenCenterX / 100);
			float radiusy = aimfov * (ScreenCenterY / 100);
 
			//get crosshairdistance
			ModelInfo[i]->CrosshairDistance = GetDistance(ModelInfo[i]->Position2D.x, ModelInfo[i]->Position2D.y, ScreenCenterX, ScreenCenterY);
 
			//if in fov
			if (ModelInfo[i]->Position2D.x >= ScreenCenterX - radiusx && ModelInfo[i]->Position2D.x <= ScreenCenterX + radiusx && ModelInfo[i]->Position2D.y >= ScreenCenterY - radiusy && ModelInfo[i]->Position2D.y <= ScreenCenterY + radiusy)
 
				//get closest/nearest target to crosshair
				if (ModelInfo[i]->CrosshairDistance < fClosestPos)
				{
				fClosestPos = ModelInfo[i]->CrosshairDistance;
				BestTarget = i;
				}
		}
 
		//if nearest target to crosshair
		if (BestTarget != -1)
		{
			double DistX = (double)ModelInfo[BestTarget]->Position2D.x - viewport.Width / 2.0f;
			double DistY = (double)ModelInfo[BestTarget]->Position2D.y - viewport.Height / 2.0f;
 
			//aimsmooth
			DistX /= aimsmooth;
			DistY /= aimsmooth;
 
			//if aimkey is pressed
			if ((GetAsyncKeyState(aimkey) & 0x8000))
				mouse_event(MOUSEEVENTF_MOVE, (DWORD)DistX, (DWORD)DistY, NULL, NULL); //doaim, move mouse to x & y
		}
 
		ModelInfo.clear();
	}
 
	return OrigEndScene(Device);
}
 
//==========================================================================================================================
 
#include <Psapi.h>
#pragma comment(lib, "Psapi.lib")
bool bCompare(const BYTE* pData, const BYTE* bMask, const char* szMask)
{
    for(;*szMask;++szMask,++pData,++bMask)
        if(*szMask=='x' && *pData!=*bMask ) 
            return false;
 
    return (*szMask) == NULL;
}
 
DWORD FindPattern(DWORD dwAddress,DWORD dwLen,BYTE *bMask,char * szMask)
{
    for(DWORD i=0; i < dwLen; i++)
        if( bCompare( (BYTE*)( dwAddress+i ),bMask,szMask) )
            return (DWORD)(dwAddress+i);
 
    return 0;
}
 
void Hook()
{
	DWORD *vtbl;
 
	// wait for the d3dx dll
	DWORD hD3D = 0;
	do {
		hD3D = (DWORD)GetModuleHandleA("d3d9.dll");
		Sleep(10);
	} while (!hD3D);
	DWORD adre = FindPattern(hD3D, 0x128000, (PBYTE)"\xC7\x06\x00\x00\x00\x00\x89\x86\x00\x00\x00\x00\x89\x86", "xx????xx????xx");
 
	if (adre)
	{
		memcpy(&vtbl, (void*)(adre + 2), 4);
 
		//ms detours 3.0
		OrigDrawIndexedPrimitive = (HRESULT(__stdcall*)(LPDIRECT3DDEVICE9, D3DPRIMITIVETYPE, INT, UINT, UINT, UINT, UINT))vtbl[82];
		OrigEndScene = (HRESULT(__stdcall*)(LPDIRECT3DDEVICE9))vtbl[42];
 
		DetourTransactionBegin();
		DetourUpdateThread(GetCurrentThread());
		DetourAttach(&(PVOID&)OrigDrawIndexedPrimitive, myDrawIndexedPrimitive);
		DetourAttach(&(PVOID&)OrigEndScene, myEndScene);
		DetourTransactionCommit();
	}
}
 
//==========================================================================================================================
 
BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD Reason, LPVOID Reserved)
{
	DisableThreadLibraryCalls(hinstDll);
 
    switch(Reason)
    {
    case DLL_PROCESS_ATTACH:
        CreateThread(0, 0, (LPTHREAD_START_ROUTINE)&Hook, 0, 0, 0);
        break;
 
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
} 

C++ Online Compiler

Write, Run & Share C++ code online using OneCompiler's C++ online compiler for free. It's one of the robust, feature-rich online compilers for C++ language, running on the latest version 17. Getting started with the OneCompiler's C++ compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as C++ and start coding!

Read inputs from stdin

OneCompiler's C++ online compiler supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample program which takes name as input and print your name with hello.

#include <iostream>
#include <string>
using namespace std;

int main() 
{
    string name;
    cout << "Enter name:";
    getline (cin, name);
    cout << "Hello " << name;
    return 0;
}

About C++

C++ is a widely used middle-level programming language.

  • Supports different platforms like Windows, various Linux flavours, MacOS etc
  • C++ supports OOPS concepts like Inheritance, Polymorphism, Encapsulation and Abstraction.
  • Case-sensitive
  • C++ is a compiler based language
  • C++ supports structured programming language
  • C++ provides alot of inbuilt functions and also supports dynamic memory allocation.
  • Like C, C++ also allows you to play with memory using Pointers.

Syntax help

Loops

1. If-Else:

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.

2. Switch:

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;    
} 

3. For:

For loop is used to iterate a set of statements based on a condition.

for(Initialization; Condition; Increment/decrement){  
  //code  
} 

4. While:

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 
}  

5. Do-While:

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); 

Functions

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. Function gets run only when it is called.

How to declare a Function:

return_type function_name(parameters);

How to call a Function:

function_name (parameters)

How to define a Function:

return_type function_name(parameters) {  
 // code
}