-
Notifications
You must be signed in to change notification settings - Fork 0
/
rec.cpp
176 lines (172 loc) · 4.25 KB
/
rec.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
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <Windows.h>
#include <TlHelp32.h>
#include <string>
#include <Psapi.h>
#include <cstring>
#include <fstream>
#include <sstream>
#include <algorithm>
using namespace std;
#pragma comment(lib, "Psapi")
#pragma comment(lib,"Winmm.lib")
HWND osu;
BOOL CALLBACK enumWindowsProc(HWND hwnd, LPARAM lParam) {
DWORD procid;
GetWindowThreadProcessId (hwnd, &procid);
char buffer[65536];
int txtlen=GetWindowTextLength(hwnd);
GetWindowTextA(hwnd, buffer, txtlen);
if(string(buffer).compare("osu!") == 0) {
cout << "found osu" << endl;
osu = hwnd;
}
return true;
}
int readAddresses(int& audio, int& base, int& rmb, int&lmb) {
ifstream address("address.txt");
if(address.good()) {
for(int j = 0; j < 4; j++) {
string toGet;
getline(address,toGet);
stringstream ss;
ss << toGet;
int i;
ss >> hex >> i;
if(ss.fail()) {
cout << "Error parsing address" << endl;
return -1;
}
cout << "using address " << i << endl;
switch(j) {
case 0:
audio = i;
break;
case 1:
base = i;
break;
case 2:
rmb = i;
break;
case 3:
lmb = i;
break;
}
}
address.close();
return 0;
} else {
cout << "could not open address.txt" << endl;
}
return -1;
}
int main(int argc, _TCHAR* argv[])
{
EnumWindows(enumWindowsProc, 0);
if(osu == NULL) {
cout <<"no hwnd " << GetLastError() << endl;
} else {
DWORD proc_id;
GetWindowThreadProcessId(osu,&proc_id);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proc_id);
if(!hProcess)
{
}
else
{
//my values incase i forgot to include address.txt, wont work for others
int audioA = 0x002954ac;
int baseA = 0x02de97fc;
int rmbA = 0x002953f0;
int lmbA = 0x00295398;
int result = readAddresses(audioA,baseA,rmbA,lmbA);
if(result != 0) {
cout << "failed to open settings, using default" << endl;
}
start :
DWORD test;
int mouseA = 0;
bool started = false, offset = 0;
string sTitle;
char title [128];
while (!started)
{
title [128];
int txtlen = GetWindowTextLength(osu);
GetWindowTextA(osu, title, txtlen);
sTitle = title;
if (sTitle != "osu!")
{
started = true;
}
Sleep(1);
}
string song = sTitle.substr(8);
string sub2 = song.substr(song.length() - 5);
if (sub2 == "-----")
{
song = song.substr(0, song.length() - 24);
}
char illegal [] = {'*', '\\', '/', '|', '?', '<', '>', '?', '\"', ':'};
for(int t = 0; t < (sizeof(illegal) / sizeof(char)); t++) {
replace(song.begin(), song.end(), illegal[t], ' ');
}
ofstream replay("replays\\" + song + ".txt");
if(!replay.good()) {
cout << "could not open file for writing" << endl;
return -1;
} else {
cout << "writing " << song << ".txt" << endl;
}
cout << "starting read" << endl;
int initial = 0;
int diff = 0;
int go = 0, second = 0;
int audioOff = 0;
while(started) {
while (!go)
{
ReadProcessMemory(hProcess, (LPVOID)audioA, &test, sizeof(test), 0);
audioOff = test;
if (audioOff == 0)
{
second = 1;
ReadProcessMemory(hProcess, (LPVOID)baseA, &test, sizeof(test), 0);
mouseA = test;
}
if (second && audioOff > 0)
{
go = 1;
initial = timeGetTime();
}
}
int x,y, rmb, lmb;
ReadProcessMemory(hProcess, (LPVOID)rmbA, &test, sizeof(test), 0);
rmb = test;
ReadProcessMemory(hProcess, (LPVOID)lmbA, &test, sizeof(test), 0);
lmb = test;
ReadProcessMemory(hProcess,(LPVOID)(mouseA+4), &test, sizeof(test),0);
x = test;
ReadProcessMemory(hProcess,(LPVOID)(mouseA+8), &test, sizeof(test),0);
y = test;
diff = timeGetTime() - initial;
replay << x << "," << y << "," << diff << "," << rmb << "," << lmb << endl;
int txtlen = GetWindowTextLength(osu);
GetWindowTextA(osu, title, txtlen);
sTitle = title;
if (sTitle == "osu!")
{
started = false;
}
Sleep(2);
}
replay.close();
cout << "replay record finished, listening again" << endl;
goto start;
}
}
system("pause");
return 0;
}