-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathContinuum.cpp
161 lines (137 loc) · 3.95 KB
/
Continuum.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
#include "DiscordBridge.h"
std::string ReadString(HANDLE handle, size_t address, size_t len)
{
std::string value;
SIZE_T read;
value.resize(len);
if (ReadProcessMemory(handle, (LPVOID)address, &value[0], len, &read)) {
return value;
}
return "";
}
void Continuum::startGameClient()
{
STARTUPINFO si;
PROCESS_INFORMATION processInfo;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&processInfo, sizeof(processInfo));
if (CreateProcess(L"Continuum_main.exe", L"cmd", NULL, NULL, TRUE, 0, NULL, NULL, &si, &processInfo))
{
WaitForSingleObject(processInfo.hProcess, INFINITE);
gHandle = processInfo.hProcess;
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
}
return;
}
DWORD Continuum::getGameProcess()
{
PROCESSENTRY32 entry;
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
entry.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(snapshot, &entry))
{
do
{
if (!lstrcmpi(entry.szExeFile, L"Continuum_main.exe"))
{
CloseHandle(snapshot);
return entry.th32ProcessID;
}
} while (Process32Next(snapshot, &entry));
}
CloseHandle(snapshot);
}
bool Continuum::isSteamUser()
{
char path[MAX_PATH];
GetCurrentDirectoryA(MAX_PATH, path);
std::string fullpath = path;
if (fullpath.find("Steam") != fullpath.npos) // simple but works
return true;
else
return false;
}
bool Continuum::inGame()
{
HWND hwnd;
if (state.cont.isSteamUser())
hwnd = FindWindow(0, _T("Subspace Continuum")); // steam users
else
if (FindWindow(0, _T("Continuum")) == NULL)
hwnd = FindWindow(0, _T("Subspace Continuum")); // discord installs
else
hwnd = FindWindow(0, _T("Continuum")); // legacy
if (GetForegroundWindow() == hwnd) // active game window
return true;
else
return false;
}
int Continuum::gameWindow()
{
char text[32];
HWND alt = GetForegroundWindow();
GetWindowTextA(alt, text, 32);
if ((CMPSTART("Subspace Continuum 0.40 -", text) || (CMPSTART("Continuum 0.40 -", text)))) // chat menu
return 1;
else if ((CMPSTART("Subspace Continuum 0.40", text) || (CMPSTART("Continuum 0.40", text)))) // launcher
return 2;
else
if ((FindWindow(0, _T("Continuum")) == NULL) && (FindWindow(0, _T("Subspace Continuum")) == NULL)) // not idling in game but launcher open
return 4;
else // true idle
return 3;
}
std::wstring Continuum::getRegValue(std::wstring val)
{
HKEY hKey;
if (RegOpenKeyEx(HKEY_CURRENT_USER, L"SOFTWARE\\Continuum\\State", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
throw "Registry entry not found!";
DWORD type, cbData, buff;
if (RegQueryValueEx(hKey, val.c_str(), NULL, &type, NULL, &cbData) != ERROR_SUCCESS)
RegCloseKey(hKey);
std::wstring value(cbData / sizeof(wchar_t), L'\0');
if (type == REG_DWORD) // ie. ship number
{
if (RegQueryValueEx(hKey, val.c_str(), NULL, &type, (LPBYTE)&buff, &cbData) != ERROR_SUCCESS)
RegCloseKey(hKey);
return std::to_wstring(buff);
}
else if (type == REG_SZ) // ie. zone name/skin
{
if (RegQueryValueEx(hKey, val.c_str(), NULL, NULL, reinterpret_cast<LPBYTE>(&value[0]), &cbData) != ERROR_SUCCESS)
RegCloseKey(hKey);
size_t firstNull = value.find_first_of(L'\0');
if (firstNull != std::string::npos)
value.resize(firstNull);
return value;
}
RegCloseKey(hKey);
}
/*
// TODO: Get player's ship by reading from memory. Unable to get base address for some reason now.
uintptr_t Continuum::GetModuleBaseAddress(DWORD dwProcID)
{
uintptr_t ModuleBaseAddress = 0;
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, dwProcID);
if (hSnapshot != INVALID_HANDLE_VALUE)
{
MODULEENTRY32 ModuleEntry32;
ModuleEntry32.dwSize = sizeof(MODULEENTRY32);
if (Module32First(hSnapshot, &ModuleEntry32))
{
do
{
if (!_wcsicmp(ModuleEntry32.szModule, L"Continuum_main.exe"))
{
ModuleBaseAddress = (uintptr_t)ModuleEntry32.modBaseAddr;
break;
}
} while (Module32Next(hSnapshot, &ModuleEntry32));
}
}
CloseHandle(hSnapshot);
return ModuleBaseAddress;
}
*/