- Katılım
- 22 May 2021
- Mesajlar
- 1,473
- Beğeniler
- 333
C++ Team Fortress 2 BunnyHop Yapımı
1-C++ boş proje oluşturun ve main.cpp memory.h isminde iki adet dosya oluşturun
2-Size verdiğim kodu yapıştırın
İşte bu kadar derleyip kullanabilirsiniz iyi oyunlar...
memory.h:
main.cpp:
1-C++ boş proje oluşturun ve main.cpp memory.h isminde iki adet dosya oluşturun
2-Size verdiğim kodu yapıştırın
İşte bu kadar derleyip kullanabilirsiniz iyi oyunlar...
memory.h:
C:
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <TlHelp32.h>
#include <cstdint>
#include <string_view>
class Memory
{
private:
std::uintptr_t processId = 0;
void* processHandle = nullptr;
public:
// Constructor that finds the process id
// and opens a handle
Memory(const std::string_view processName) noexcept
{
::PROCESSENTRY32 entry = { };
entry.dwSize = sizeof(::PROCESSENTRY32);
const auto snapShot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
while (::Process32Next(snapShot, &entry))
{
if (!processName.compare(entry.szExeFile))
{
processId = entry.th32ProcessID;
processHandle = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);
break;
}
}
// Free handle
if (snapShot)
::CloseHandle(snapShot);
}
// Destructor that frees the opened handle
~Memory()
{
if (processHandle)
::CloseHandle(processHandle);
}
// Returns the base address of a module by name
const std::uintptr_t GetModuleAddress(const std::string_view moduleName) const noexcept
{
::MODULEENTRY32 entry = { };
entry.dwSize = sizeof(::MODULEENTRY32);
const auto snapShot = ::CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, processId);
std::uintptr_t result = 0;
while (::Module32Next(snapShot, &entry))
{
if (!moduleName.compare(entry.szModule))
{
result = reinterpret_cast<std::uintptr_t>(entry.modBaseAddr);
break;
}
}
if (snapShot)
::CloseHandle(snapShot);
return result;
}
// Read process memory
template <typename T>
constexpr const T Read(const std::uintptr_t& address) const noexcept
{
T value = { };
::ReadProcessMemory(processHandle, reinterpret_cast<const void*>(address), &value, sizeof(T), NULL);
return value;
}
// Write process memory
template <typename T>
constexpr void Write(const std::uintptr_t& address, const T& value) const noexcept
{
::WriteProcessMemory(processHandle, reinterpret_cast<void*>(address), &value, sizeof(T), NULL);
}
};
main.cpp:
C++:
#include "memory.h"
#include <thread>
#include <iostream>
namespace offsets
{
constexpr auto localPlayer = 0xC3F6C0;
constexpr auto flags = 0x37C;
constexpr auto forceJump = 0xC6E460;
constexpr auto entityList = 0xC4D1EC;
constexpr auto teamNum = 0xB0;
}
__declspec(align(16)) struct Color
{
constexpr Color(const float r, const float g, const float b, const float a = 1.f) noexcept :
r(r), g(g), b(b), a(a) { }
float r, g, b, a;
};
int main()
{
const auto mem = Memory("hl2.exe");
std::cout << "Team Fortess 2 found!" << std::endl;
const auto client = mem.GetModuleAddress("client.dll");
std::cout << "client.dll -> " << "0x" << std::hex << client << std::dec << std::endl;
constexpr const auto color = Color{ 1.f, 0.f, 1.f };
while (true)
{
// we don't need this running a billion times per second :)
std::this_thread::sleep_for(std::chrono::milliseconds(1));
const auto localPlayer = mem.Read<std::uintptr_t>(client + offsets::localPlayer);
if (!localPlayer)
continue;
const auto localPlayerTeam = mem.Read<std::uintptr_t>(localPlayer + offsets::teamNum);
const auto localPlayerFlags = mem.Read<std::uintptr_t>(localPlayer + offsets::flags);
// bhop
if (GetAsyncKeyState(VK_SPACE))
(localPlayerFlags & (1 << 0)) ?
mem.Write<std::uintptr_t>(client + offsets::forceJump, 6) :
mem.Write<std::uintptr_t>(client + offsets::forceJump, 4);
}
}