Code:
// spd.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdafx.h"
#include "ConsoleColor.h"
#include <iostream>
#include <Windows.h>
#include "fb.h"
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "interception.lib")
using namespace std;
float GetSpeed(HANDLE hProc){
// Read memory of pointer + offset and display data
DWORD ClientGameContext = 0x23bd8ac;
DWORD buffer;
float CurrentSpeed = 1;
int newValue = 0;
ReadProcessMemory(hProc,(LPCVOID)(ClientGameContext), &buffer, 4, NULL);
ReadProcessMemory(hProc,(LPCVOID)(buffer + 0x30), (void*)&buffer, sizeof(buffer), NULL);
ReadProcessMemory(hProc,(LPCVOID)(buffer + 0xbc), (void*)&buffer, sizeof(buffer), NULL);
ReadProcessMemory(hProc,(LPCVOID)(buffer + 0x3D8), (void*)&buffer, sizeof(buffer), NULL);
ReadProcessMemory(hProc,(LPCVOID)(buffer + 0x98), &CurrentSpeed, sizeof(CurrentSpeed), NULL);
CurrentSpeed = CurrentSpeed * 3.6;
Sleep(5);
return CurrentSpeed;
}
#define KEYEVENTF_SCANCODE 0x008
#define KEYEVENTF_SCANCODE2 0x008
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Jet Cruise Control 0.1 beta" << endl;
// find exe window called and allocate to hWnd
HWND hWnd = FindWindow(0, L"Battlefield 3™");
if (hWnd == 0){
cout << "Error, Could not find Battlefield 3" << endl;
}
else {
cout << "Battlefield 3 found" << endl;
// Get the window process thread id of hWnd and allocate to proc_id
DWORD proc_id;
GetWindowThreadProcessId(hWnd, &proc_id);
// Open process process thread (proc_id)
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proc_id);
if (!hProc) {
cout << "Error, Could not open process" << endl;
}
else {
cout << "Process opened" << endl;
cout << "Hold F1 to maintain 315 speed" << endl;
while (1 == 1){
if(GetAsyncKeyState(VK_F1)){
float CurrentSpeed = 1;
CurrentSpeed = GetSpeed(hProc);
cout << green << "Your current speed is: " << CurrentSpeed << endl; // let the user know value
while (CurrentSpeed > 312 && CurrentSpeed > 10){
INPUT input;
memset(&input,0,sizeof(INPUT));
input.type=INPUT_KEYBOARD;
input.ki.dwFlags = KEYEVENTF_SCANCODE2;
input.ki.wScan = 0x01f; //Scan code for direct input key S.
SendInput(1,&input,sizeof(INPUT));
CurrentSpeed = GetSpeed(hProc);
cout << green << "Your current speed is: " << CurrentSpeed << endl; // let the user know value
if (CurrentSpeed <= 312 && CurrentSpeed > 10) {
INPUT inputoff;
memset(&inputoff,0,sizeof(INPUT));
inputoff.type=INPUT_KEYBOARD;
inputoff.ki.dwFlags = KEYEVENTF_KEYUP;
inputoff.ki.wScan = 0x01f; //Scan code for direct input key S.
SendInput(1,&inputoff,sizeof(INPUT));
CurrentSpeed = GetSpeed(hProc);
}
}
while (CurrentSpeed < 312 && CurrentSpeed > 10){
INPUT input;
memset(&input,0,sizeof(INPUT));
input.type=INPUT_KEYBOARD;
input.ki.dwFlags = KEYEVENTF_SCANCODE2;
input.ki.wScan = 0x011; //Scan code for direct input key W.
SendInput(1,&input,sizeof(INPUT));
CurrentSpeed = GetSpeed(hProc);
if (CurrentSpeed >= 312 && CurrentSpeed > 10) {
INPUT inputoff;
memset(&inputoff,0,sizeof(INPUT));
inputoff.type=INPUT_KEYBOARD;
inputoff.ki.dwFlags = KEYEVENTF_KEYUP;
inputoff.ki.wScan = 0x011; //Scan code for direct input key W.
SendInput(1,&inputoff,sizeof(INPUT));
CurrentSpeed = GetSpeed(hProc);
}
}
}
}
}
}
cout << "Press any button to exit" << endl;
cin.get();
return 0;
}