-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
182 lines (167 loc) · 5.55 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//Copyright (c) 2020 Jacob Large
//This program is a fully external tool for assisting in bunnyhopping in all games based on the Orange Box engine.
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <cstring>
#include "CProcess.h"
#include <time.h>
//Struct to store offsets, gamewindow, and game name
struct offset
{
offset();
DWORD ON_GROUND;
DWORD SPECTATING;
DWORD OVERLAY;
DWORD WATER;
HWND game;
char *gameName;
};
//Initializer function to set all members to NULL
offset::offset()
{
ON_GROUND = NULL;
SPECTATING = NULL;
OVERLAY = NULL;
game = NULL;
}
//Prototype functions
bool isSpectating();
bool onGround();
bool overlayOpen();
void bhopLoop(const offset&);
void sendSpace(const offset &addrs);
void findGame(offset &addrs);
//Global variables
int grounded = -1;
int overlay = -1;
int spectate = -1;
int water = -1;
int grmax = 0;
double timestart;
CProcess worker;
int main()
{
SetConsoleTitle("svHop External Sven Co-op Bunnyhop Tool");
while (1){
std::cout << "svHop External Sven Co-op Bunnyhop Tool by Lagunka" << std::endl;
std::cout << "Waiting for Sven Co-op..." << std::endl;
worker.Initialize();//Searches for svencoop.exe
std::cout << "svencoop.exe found. Waiting for game window..." << std::endl;
offset addrs;//Creates a struct object for storing offsets and game name
findGame(addrs);//Searches for a source game window
bhopLoop(addrs);//Main loop for bhopping
Sleep(2000);
worker.dwEngine = 0;
worker.dwOverlay = 0;
delete[] addrs.gameName;//Free the memory allocated for the dynamic array
}
return 0;
}
//Reads the process memory to see if the client is on ground
//Because the values can start becoming other than 0 and 1 (3 and 4 for example) some fixes were applied
bool onGround(offset addrs)
{
if (grounded > grmax)//Stores the max value of the address
grmax = grounded;
while (grmax - 1 > grounded)//If max value is more than 1 more of the min value, it lowers it to be 1 more again
grmax -= 1;
ReadProcessMemory(worker.hProcess, (LPVOID)(worker.dwEngine + addrs.ON_GROUND), &grounded, sizeof(grounded), 0);//reads the process memory and stores the value to grounded
if (grounded == grmax)
timestart = time(NULL);
else
timestart = 0.0;
return grounded == grmax;//returns true if grounded is at it's max, false if not.
}
//Function to check if the client is in the water
bool isInWater(offset addrs)
{
ReadProcessMemory(worker.hProcess, (LPVOID)(worker.dwEngine + addrs.WATER), &water, sizeof(water), 0);
return water == 3;
}
//Function to check if the client is in spectate (only applies to CS:S and DOD:S)
bool isSpectating(offset addrs)
{
ReadProcessMemory(worker.hProcess, (LPVOID)(worker.dwEngine + addrs.SPECTATING), &spectate, sizeof(spectate), 0);
return spectate == 1;
}
//Function to check if the steam overlay is open so spaces don't get sent while typing
bool overlayOpen(offset addrs)
{
ReadProcessMemory(worker.hProcess, (LPVOID)(worker.dwOverlay + addrs.OVERLAY), &overlay, sizeof(overlay), 0);
return overlay == 1;
}
//This function loops until a proper game window is found
void findGame(offset &addrs)
{
addrs.game = NULL;
while (!addrs.game)//Loop while addrs.game is NULL
{
if (FindWindow(NULL, "Sven Co-op"))
{
addrs.gameName = new char[strlen("Sven Co-op") + 1];
strcpy(addrs.gameName, "Sven Co-op");
addrs.game = FindWindow(NULL, addrs.gameName);
addrs.SPECTATING = 0x34A530;
addrs.ON_GROUND = 0x34606C;
addrs.OVERLAY = 0x146670;
addrs.WATER = 0x34A54C;
}
else if (FindWindow(NULL, "Sven Co-op listen server - Sven Co-op"))
{
addrs.gameName = new char[strlen("Sven Co-op") + 1];
strcpy(addrs.gameName, "Sven Co-op");
addrs.game = FindWindow(NULL, "Sven Co-op listen server - Sven Co-op");
addrs.SPECTATING = 0x34A530;
addrs.ON_GROUND = 0x34606C;
addrs.OVERLAY = 0x146670;
addrs.WATER = 0x34A54C;
}
}
std::cout << "Found game: " << addrs.gameName << std::endl;
}
//Function to send a single space key press to the window
void sendSpace(const offset &addrs)
{
SendMessage(addrs.game, WM_KEYUP, VK_SPACE, 0x390000);
Sleep(10);
SendMessage(addrs.game, WM_KEYDOWN, VK_SPACE, 0x390000);
}
//Function that loops and checks if the user is holding space
void bhopLoop(const offset &addrs)
{
std::cout << "The tool is now active, \nIMPORTANT: Leave this window open while the tool is in use." << std::endl;
int bhop_enable = 1;//bhop enable defaults to perfect
int space = 0;
DWORD pStatus;
GetExitCodeProcess(worker.hProcess, &pStatus);
srand(time(NULL));//Seed the random number generator
while (pStatus == 259)
{
GetExitCodeProcess(worker.hProcess, &pStatus);
Sleep(20);
if (GetAsyncKeyState(VK_SPACE) && bhop_enable && onGround(addrs) && !overlayOpen(addrs) && !isSpectating(addrs))
{
space = 1;
sendSpace(addrs);
Sleep(20);
}
//reset space var to 0
else if (!GetAsyncKeyState(VK_SPACE) && space){
SendMessage(addrs.game, WM_KEYUP, VK_SPACE, 0x390000);
space = 0;
}
//User is in water and not touching the ground, so simulate +jump until they are out of the water, touch ground, or let go of space
else if (isInWater(addrs)&& GetAsyncKeyState(VK_SPACE) && !onGround(addrs))
{
SendMessage(addrs.game, WM_KEYDOWN, VK_SPACE, 0x390000);
while (isInWater(addrs) && GetAsyncKeyState(VK_SPACE) && !onGround(addrs)){
space = 1;
Sleep(10);
}
SendMessage(addrs.game, WM_KEYUP, VK_SPACE, 0x390000);
space = 0;
}
}
system("cls");
}