Losser
Platinum Üye
- Katılım
- 30 Tem 2021
- Mesajlar
- 119
- Beğeniler
- 33
Elimde CSS ESP kod var bunu pythona çevirmek istiyorum yardımcı olabilecek var mı?
[/CODE]
Kod:
// MADE BY Losser
#include <wrl/client.h>
#include <windows.h>
#include <iostream>
#include <dxgi.h>
#include <dxgi1_2.h>
#include <d3d11.h>
#include <stdlib.h>
#include <fstream>
#include <chrono> // for high_resolution_clock
#pragma comment(lib,"d3d11.lib")
using namespace std;
#define PROCESS_NAME L"VALORANT "
using Microsoft::WRL::ComPtr;
ComPtr<ID3D11Device> lDevice;
ComPtr<ID3D11DeviceContext> lImmediateContext;
D3D11_TEXTURE2D_DESC desc;
D3D_DRIVER_TYPE gDriverTypes[] = {
D3D_DRIVER_TYPE_HARDWARE
};
UINT gNumDriverTypes = ARRAYSIZE(gDriverTypes);
// Feature levels supported
D3D_FEATURE_LEVEL gFeatureLevels[] = {
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_1
};
UINT gNumFeatureLevels = ARRAYSIZE(gFeatureLevels);
void ScreenGrab() {
// ==== FIND WINDOW ====
HDC hdc_target;
RECT rect;
HWND window = FindWindowW(NULL, PROCESS_NAME);
GetClientRect(window, &rect);
// ==== SCALING FACTOR ====
HDC monitor = GetDC(window); // GetDC(NULL);
int current = GetDeviceCaps(monitor, VERTRES);
int total = GetDeviceCaps(monitor, DESKTOPVERTRES);
uint32_t width = (rect.right - rect.left) * total / current;
uint32_t height = (rect.bottom - rect.top) * total / current;
// ==== CREATE DEVICE ====
ComPtr<IDXGISurface1> gdiSurface;
ComPtr<ID3D11Texture2D> texture;
HRESULT hr(E_FAIL);
D3D_FEATURE_LEVEL lFeatureLevel;
for(UINT DriverTypeIndex = 0; DriverTypeIndex < gNumDriverTypes; ++DriverTypeIndex)
{
hr = D3D11CreateDevice(
nullptr,
gDriverTypes[DriverTypeIndex],
nullptr,
0,
gFeatureLevels,
gNumFeatureLevels,
D3D11_SDK_VERSION,
&lDevice,
&lFeatureLevel,
&lImmediateContext);
if(SUCCEEDED(hr))
{
// Device creation success, no need to loop anymore
break;
}
lDevice.Reset();
lImmediateContext.Reset();
}
// ==== CREATE TEXTURE ====
desc.Width = width;
desc.Height = height;
desc.ArraySize = 1;
desc.MipLevels = 1;
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = 40;
desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
desc.CPUAccessFlags = 0;
hr = lDevice->CreateTexture2D(&desc, NULL, &texture);
if(FAILED(hr)) {
cout << "Failed to create texture" << endl;
return;
}
hr = texture->QueryInterface(__uuidof(IDXGISurface1), (void**)&gdiSurface);
if(FAILED(hr)) {
cout << "Failed to create GDI surface" << endl;
return;
}
// ==== SCEENGRAB ====
// REUSE desc FOR FRAMECOPY
desc.BindFlags = 0;
desc.MiscFlags &= D3D11_RESOURCE_MISC_TEXTURECUBE;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.Usage = D3D11_USAGE_STAGING;
unsigned short last_r = 0;
unsigned short last_g = 0;
unsigned short last_b = 0;
auto start = std::chrono::high_resolution_clock::now();
cout << "Starting at " << width << "x" << height << endl;
while(true)
{
//Sleep(1);
HDC hDC = nullptr;
gdiSurface->GetDC(true, &hDC);
hdc_target = GetDC(window);
// === THE COPY TEXTURE ===
while(!BitBlt(hDC, 0, 0, width, height, hdc_target, 0, 0, SRCCOPY)) {
cout << "FAILED" << endl;
Sleep(1000);
}
// VERY IMPORTANT TO RELEASE BEFORE COPY
ReleaseDC(NULL, hdc_target);
gdiSurface->ReleaseDC(nullptr);
// === COPY TO CPU ===
D3D11_MAPPED_SUBRESOURCE tempsubsource;
ID3D11Texture2D* pFrameCopy = nullptr;
hr = lDevice->CreateTexture2D(&desc, nullptr, &pFrameCopy);
if(FAILED(hr)) {
continue;
}
lImmediateContext->CopyResource(pFrameCopy, texture.Get());
hr = lImmediateContext->Map(pFrameCopy, 0, D3D11_MAP_READ, 0, &tempsubsource);
void* d = tempsubsource.pData;
char* data = reinterpret_cast<char*>(d);
if(FAILED(hr)) {
continue;
}
for(int y = 0; y < desc.Height; y++) {
for(int x = 0; x < desc.Width; x++) {
int base = (x + y * desc.Width) * 4;
unsigned short red = data[base + 2] & 255;
unsigned short green = data[base + 1] & 255;
unsigned short blue = data[base] & 255;
// INSERT MOVE CODE HERE
}
}
// DEBUGGING
/*
ofstream img("debugpic.ppm"); //#include <fstream>
img << "P3" << endl;
img << desc.Width << endl;
img << desc.Height << endl;
img << "255" << endl;
for(int y = 0; y < desc.Height; y++) {
std::cout << y << "/" << desc.Height << endl;
for(int x = 0; x < desc.Width; x++) {
int base = (x + y * desc.Width) * 4;
unsigned short red = data[base + 2] & 255;
unsigned short green = data[base + 1] & 255;
unsigned short blue = data[base] & 255;
img << red << " " << green << " " << blue << "\n";
}
}
return;*/
if(pFrameCopy != nullptr) {
lImmediateContext->Unmap(pFrameCopy, 0);
pFrameCopy->Release();
lImmediateContext->Flush();
}
// TESTING FRAME UPDATE, REMOVE THIS
int base = (100 + 100 * desc.Width) * 4;
unsigned short red = data[base + 2];
unsigned short green = data[base + 1];
unsigned short blue = data[base];
if((last_b != blue || last_g != green || last_r != red) && (red > 0 && blue > 0 && green > 0)) {
auto finish = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = finish - start;
cout << "Time: " << (elapsed.count()*1000) << "ms" << endl;
start = std::chrono::high_resolution_clock::now();
last_b = blue;
last_g = green;
last_r = red;
}
}
}
int main(void)
{
ScreenGrab();
}
Kod:
#define M_PI 3.14159265358979323846
#define RADTODEG 180 / M_PI
#define DEGTORAD M_PI / 180
bool flickAim = true;
int flickAimTime = 30;
bool isZommed = false;
void SetIsZoomed() { // CALL THIS EVERY FRAME
isZommed = GetAsyncKeyState(VK_RBUTTON);
}
int Full360() {
return isZommed ? full360 : (full360 * 8 / 10);
}
int GetCoordsX(int delta, int total) {
double lookAt = delta * 2.0 / total;
double degrees = atan(lookAt * tan((isZommed ? 41.5 : 52.0) * DEGTORAD)) * RADTODEG;
return (Full360() * degrees) / 360;
}
int GetCoordsY(int delta, int total) {
double lookAt = delta * 2.0 / total;
double degrees = atan(lookAt * tan((isZommed ? 26.5 : 36) * DEGTORAD)) * RADTODEG;
return (Full360() * degrees) / 360;
}
Kod:
void MoveMouseFromScreenPosition(Vector2 front, int height, int width) {
SetIsZoomed();
int moveX = GetCoordsX(front.x, width);
int moveY = GetCoordsY(front.y, height);
if(flickAim) {
MoveMouse(moveX, moveY);
Sleep(flickAimTime);
}
else {
MoveMouse(moveX * speed, moveY * speed);
}
}
Moderatör tarafında düzenlendi: