forked from flarialmc/dll
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
200 lines (156 loc) · 6.45 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#pragma once
#include <windows.h>
#include <algorithm>
#include "src/Client/Client.hpp"
#include "src/Client/Events/EventHandler.hpp"
#include "src/Client/Hook/Hooks/Render/ResizeHook.hpp"
#include "src/Client/Hook/Hooks/Game/RaknetTick.hpp"
#include "src/Client/Module/Modules/Nick/NickListener.hpp"
#include <kiero.h>
#include <wininet.h>
std::chrono::steady_clock::time_point lastBeatTime;
std::string replaceAll(std::string subject, const std::string& search,
const std::string& replace);
std::string DownloadString(std::string URL);
std::string removeColorCodes(const std::string& input);
DWORD WINAPI init(HMODULE real)
{
#ifndef NDEBUG
if (GetConsoleWindow() == nullptr) {
AllocConsole();
SetConsoleTitleA("Flarial-Debugger");
FILE *out;
freopen_s(&out, ("CONOUT$"), ("w"), stdout);
}
#endif
Client::initialize();
Logger::info("[Client] Initializing");
/*
std::thread statusThread([]() {
while (true) {
auto now = std::chrono::steady_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(now - lastBeatTime);
if(!Client::disable) {
if(SDK::hasInstanced && SDK::clientInstance != nullptr) {
if (SDK::clientInstance->getLocalPlayer() != nullptr) {
if(elapsed >= std::chrono::seconds(60)) {
ModuleManager::onlineUsers.clear();
std::string name = SDK::clientInstance->getLocalPlayer()->playerName;
ModuleManager::onlineUsers.push_back(Utils::removeColorCodes(name));
std::string pp = DownloadString("https://api.flarial.net/users");
json playersDict = json::parse(pp);
int totalPlaytime = 0;
int numberOfPlayers = 0;
for (const auto& player : playersDict.items()) {
std::time_t unixTimestamp = player.value()["lastbeat"];
std::chrono::time_point<std::chrono::system_clock> timePoint = std::chrono::system_clock::from_time_t(unixTimestamp);
ModuleManager::onlineUsers.push_back(Utils::removeNonAlphanumeric(player.key()));
//std::cout << Utils::removeNonAlphanumeric(player.key()) << std::endl;
}
std::string ipToSend;
if (!Client::settings.getSettingByName<bool>("anonymousApi")->value) {
if (RaknetTickHook::towriteip.find("none") != std::string::npos) ipToSend = "in.singleplayer";
else if (!RaknetTickHook::towriteip.empty()) ipToSend = RaknetTickHook::towriteip;
else ipToSend = "in.singleplayer";
} else ipToSend = "is.anonymous";
auto module = ModuleManager::getModule("Nick");
if(SDK::clientInstance != nullptr)
if(SDK::clientInstance->getLocalPlayer() != nullptr)
if (module->isEnabled()) {
name = Utils::removeNonAlphanumeric(Utils::removeColorCodes(NickListener::original));
}
// send thing
std::cout << DownloadString(std::format("https://api.flarial.net/heartbeat/{}/{}",Utils::removeColorCodes(name),ipToSend))
+ " " + std::format("https://api.flarial.net/heartbeat/{}/{}",
Utils::removeColorCodes(name),
ipToSend) << std::endl;
lastBeatTime = now;
}
}
}
Sleep(60);
} else break;
}
});
statusThread.detach();
*/
while (true) {
if (Client::disable) {
break;
} else {
Sleep(50); // wtf 50ms too high
}
}
Client::SaveSettings();
Logger::info("Uninitializing Client");
EventHandler::unregisterAll();
ModuleManager::terminate();
HookManager::terminate();
kiero::shutdown();
Logger::debug("[Kiero] Shut down Kiero.");
ResizeHook::cleanShit();
MH_DisableHook(MH_ALL_HOOKS);
MH_Uninitialize();
Logger::debug("[MinHook] Freeing Library.");
Sleep(100);
FreeLibraryAndExitThread(real, 1);
}
BOOL APIENTRY DllMain(HMODULE instance, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)init, instance, 0, nullptr);
break;
case DLL_PROCESS_DETACH:
ModuleManager::terminate();
}
return TRUE;
}
std::string DownloadString(std::string URL) {
HINTERNET interwebs = InternetOpenA("Samsung Smart Fridge", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, NULL);
HINTERNET urlFile;
std::string rtn;
if (interwebs) {
urlFile = InternetOpenUrlA(interwebs, URL.c_str(), NULL, NULL, NULL, NULL);
if (urlFile) {
char buffer[2000];
DWORD bytesRead;
do {
InternetReadFile(urlFile, buffer, 2000, &bytesRead);
rtn.append(buffer, bytesRead);
memset(buffer, 0, 2000);
} while (bytesRead);
InternetCloseHandle(interwebs);
InternetCloseHandle(urlFile);
std::string p = replaceAll(rtn, "|n", "\r\n");
return p;
}
}
InternetCloseHandle(interwebs);
std::string p = replaceAll(rtn, "|n", "\r\n");
return p;
}
std::string replaceAll(std::string subject, const std::string& search,
const std::string& replace) {
size_t pos = 0;
while ((pos = subject.find(search, pos)) != std::string::npos) {
subject.replace(pos, search.length(), replace);
pos += replace.length();
}
return subject;
}
std::string removeColorCodes(const std::string& input) {
std::string result;
bool skipNext = false;
for (char c : input) {
if (skipNext) {
skipNext = false;
} else if (c == L'§') {
skipNext = true;
} else {
result += c;
}
}
return result;
}