aboutsummaryrefslogtreecommitdiff
path: root/client/src/main.cpp
diff options
context:
space:
mode:
authorauth12 <[email protected]>2020-08-03 21:08:06 +0100
committerauth12 <[email protected]>2020-08-03 21:08:06 +0100
commitad8cf7c80590b96ad4e61f3f4eb397704a22ee4b (patch)
treef376bc6ce8b7ababd4bcc67bee748c6e1d672b0c /client/src/main.cpp
parentStarted security. (diff)
downloadloader-ad8cf7c80590b96ad4e61f3f4eb397704a22ee4b.tar.xz
loader-ad8cf7c80590b96ad4e61f3f4eb397704a22ee4b.zip
Added ui.
Diffstat (limited to 'client/src/main.cpp')
-rw-r--r--client/src/main.cpp297
1 files changed, 197 insertions, 100 deletions
diff --git a/client/src/main.cpp b/client/src/main.cpp
index 8737196..c5f3036 100644
--- a/client/src/main.cpp
+++ b/client/src/main.cpp
@@ -8,36 +8,18 @@
#include "hwid/hwid.h"
#include "util/apiset.h"
#include "security/security.h"
+#include "ui/ui.h"
-int main(int argc, char* argv[]) {
- tcp::client client;
-
- std::thread sec_thread{ security::thread, std::ref(client) };
- sec_thread.join();
+bool init(tcp::client& client) {
client.start("127.0.0.1", 6666);
if (!client) {
- io::log_error("failed to start client.");
-
- io::log("press enter...");
-
- std::cin.get();
-
- return 0;
+ return false;
}
client.connect_event.add([&]() { io::log("connected."); });
- std::thread t{ tcp::client::monitor, std::ref(client) };
- t.detach();
-
- std::thread mapper_thread{ mmap::thread, std::ref(client) };
- mapper_thread.detach();
-
- /*std::thread sec_thread{ security::thread, std::ref(client) };
- sec_thread.detach();*/
-
client.receive_event.add([&](tcp::packet_t& packet) {
if (!packet) return;
auto message = packet();
@@ -46,7 +28,7 @@ int main(int argc, char* argv[]) {
if (id == tcp::packet_id::session) {
client.session_id = packet.session_id;
- uint16_t ver{0};
+ uint16_t ver{ 0 };
for (int i = 0; i < message.size(); ++i) {
if (i % 2) { // skip characters in between
continue;
@@ -56,50 +38,35 @@ int main(int argc, char* argv[]) {
}
if (client.ver != ver) {
- io::log_error("please update your client.");
+ client.session_result = tcp::session_result::version_mismatch;
+
+ std::this_thread::sleep_for(std::chrono::seconds(5));
+
client.shutdown();
return;
}
auto hwid = hwid::fetch();
+
int ret = client.write(tcp::packet_t(hwid, tcp::packet_type::write, client.session_id, tcp::packet_id::hwid));
if (ret <= 0) {
- io::log_error("failed to send hwid.");
- client.shutdown();
- return;
- }
- }
+ client.session_result = tcp::session_result::hwid_fail;
- if (id == tcp::packet_id::login_resp) {
- auto j = nlohmann::json::parse(message);
-
- auto res = j["result"].get<int>();
+ std::this_thread::sleep_for(std::chrono::seconds(5));
- if (res == tcp::login_result::banned) {
- io::log_error("your account is banned.");
client.shutdown();
return;
}
- if (res == tcp::login_result::login_fail) {
- io::log_error("please check your username or password.");
- client.shutdown();
- return;
- }
+ client.state = tcp::client_state::idle;
+ }
- if (res == tcp::login_result::hwid_mismatch) {
- io::log_error("please reset your hwid on the forums.");
- client.shutdown();
- return;
- }
+ if (id == tcp::packet_id::login_resp) {
+ auto j = nlohmann::json::parse(message);
- if (res == tcp::login_result::server_error) {
- io::log_error("internal server error, please contact a developer.");
- client.shutdown();
- return;
- }
+ client.login_result = j["result"].get<int>();
- if (res == tcp::login_result::login_success) {
+ if (client.login_result == tcp::login_result::login_success) {
auto games = j["games"];
for (auto& [key, value] : games.items()) {
uint8_t version = value["version"];
@@ -145,85 +112,215 @@ int main(int argc, char* argv[]) {
io::log("{}:{}->{} {}", packet.seq, packet.session_id, message, id);
});
+}
- std::string u;
- getline(std::cin, u);
+int WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPSTR cmd_args, int show_cmd) {
+ AllocConsole();
- std::string p;
- getline(std::cin, p);
+ FILE* fp = nullptr;
+ freopen_s(&fp, "CONIN$", "r", stdin);
+ freopen_s(&fp, "CONOUT$", "w", stdout);
+ freopen_s(&fp, "CONOUT$", "w", stderr);
- auto l = fmt::format("{},{}", u, p);
+ g_syscalls.init();
- int ret = client.write(tcp::packet_t(l, tcp::packet_type::write,
- client.session_id,
- tcp::packet_id::login_req));
+ tcp::client client;
- if (ret <= 0) {
- io::log_error("failed to send login req packet.");
- client.shutdown();
+ if (!init(client)) {
+ MessageBoxA(0, "Server error.", "client", MB_OK);
- io::log("press enter...");
+
+ return 0;
+ }
+
+ std::thread mon{ tcp::client::monitor, std::ref(client) };
+ mon.detach();
+
+ std::thread mapper_thread{ mmap::thread, std::ref(client) };
+ mapper_thread.detach();
+
+ std::thread sec_thread{ security::thread, std::ref(client) };
+ sec_thread.detach();
+
+ auto hwnd = ui::create(inst, { 430, 330 });
+
+ if (!ui::create_device(hwnd)) {
+ io::log_error("failed to create device.");
std::cin.get();
return 0;
}
- while (client.state != tcp::client_state::logged_in) {
- if (!client) {
- io::log("press enter...");
- std::cin.get();
+ ShowWindow(hwnd, show_cmd);
+
+ ImGui::CreateContext();
+
+ ImGui::StyleColorsDark();
+
+ ImGui::GetIO().IniFilename = nullptr;
- return 0;
+ ImGui_ImplWin32_Init(hwnd);
+ ImGui_ImplDX11_Init(ui::device, ui::device_context);
+
+ MSG msg;
+ std::memset(&msg, 0, sizeof(msg));
+ while (msg.message != WM_QUIT) {
+ if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ continue;
}
- std::this_thread::sleep_for(std::chrono::seconds(1));
- }
+ if (!client)
+ break;
- for (auto& dat : client.games) {
- io::log("[{}]{} : {}", dat.id, dat.name, dat.version);
- }
+ // Start the Dear ImGui frame
+ ImGui_ImplDX11_NewFrame();
+ ImGui_ImplWin32_NewFrame();
+ ImGui::NewFrame();
- io::log("please select a game :");
+ ImGui::SetNextWindowSize(ImVec2{400, 250}, ImGuiCond_::ImGuiCond_Always);
+ ImGui::SetNextWindowPos(ImVec2{0, 0}, ImGuiCond_::ImGuiCond_Always);
+ ImGui::Begin("##main", 0, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove |
+ ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_MenuBar);
- int id;
- std::cin >> id;
- std::cin.ignore();
- auto it = std::find_if(client.games.begin(), client.games.end(), [&](game_data_t& dat) {
- return dat.id == id;
- });
- client.selected_game = *it;
+ if (client.state == tcp::client_state::connecting) {
+ if (client.session_result == -1) {
+ ImGui::Text("connecting...");
+ }
+
+ if (client.session_result == tcp::session_result::hwid_fail) {
+ ImGui::Text("internal client error.");
+ }
- nlohmann::json j;
- j["id"] = client.selected_game.process_name;
- j["x64"] = client.selected_game.x64;
+ if (client.session_result == tcp::session_result::version_mismatch) {
+ ImGui::Text("please update your client.");
+ }
+ }
- ret = client.write(tcp::packet_t(j.dump(), tcp::packet_type::write,
- client.session_id,
- tcp::packet_id::game_select));
+ if (client.state == tcp::client_state::idle) {
+ static std::array<char, 128> u;
+ ImGui::InputText("Username", &u[0], u.size());
- if (ret <= 0) {
- io::log_error("failed to send game select packet.");
- client.shutdown();
+ static std::array<char, 128> p;
+ ImGui::InputText("Password", &p[0], p.size());
- io::log("press enter...");
+ if (ImGui::Button("login")) {
+ auto l = fmt::format("{},{}", u.data(), p.data());
- std::cin.get();
+ int ret = client.write(tcp::packet_t(l, tcp::packet_type::write,
+ client.session_id,
+ tcp::packet_id::login_req));
- return 0;
- }
+ if (ret <= 0) {
+ ImGui::Text("failed to send request, please try again.");
+ }
+ }
- client.state = tcp::client_state::waiting;
+ auto res = client.login_result;
+ if (res != -1) {
+ if (res == tcp::login_result::banned) {
+ MessageBoxA(hwnd, "your account is banned.", "client", MB_OK);
- while (client) {
- std::this_thread::sleep_for(std::chrono::seconds(5));
- }
+ client.shutdown();
+ break;
+ }
+
+ if (res == tcp::login_result::login_fail) {
+ ImGui::Text("please check your username or password.");
+ }
+
+ if (res == tcp::login_result::hwid_mismatch) {
+ MessageBoxA(hwnd, "please reset your hwid on the forums.", "client", MB_OK);
+
+ client.shutdown();
+ break;
+ }
+
+ if (res == tcp::login_result::server_error) {
+ MessageBoxA(hwnd, "internal server error, please contact a developer.", "client", MB_OK);
+
+ client.shutdown();
+ break;
+ }
+
+ if (res == tcp::login_result::login_success) {
+ ImGui::Text("logged in.");
+ }
+ }
+ }
+
+ if (client.state == tcp::client_state::logged_in) {
+ ImGui::BeginChild("list", ImVec2(150, 300));
+ static auto getter = [](void* data, int idx, const char** out_text) -> bool {
+ auto game_data = reinterpret_cast<game_data_t*>(data);
+ if (out_text)
+ *out_text = game_data[idx].name.c_str();
+ return true;
+ };
+
+ static int i = -1;
+ ImGui::ListBox("##dd", &i, getter, (void*)client.games.data(), client.games.size());
+ ImGui::EndChild();
+
+ ImGui::SameLine();
+
+ ImGui::BeginChild("dat", ImVec2(250, 300));
+ if (i >= 0 && i < client.games.size()) {
+ auto game = client.games[i];
+ ImGui::Text("version %d", game.version);
+
+ if (ImGui::Button("inject")) {
+ client.selected_game = game;
- io::log("press enter...");
+ nlohmann::json j;
+ j["id"] = client.selected_game.process_name;
+ j["x64"] = client.selected_game.x64;
+
+ int ret = client.write(tcp::packet_t(j.dump(), tcp::packet_type::write,
+ client.session_id,
+ tcp::packet_id::game_select));
+
+ if (ret <= 0) {
+ ImGui::Text("Failed to send request, please try again.");
+ }
+
+ client.state = tcp::client_state::waiting;
+ }
+ }
+ ImGui::EndChild();
+ }
- std::cin.get();
+ if (client.state == tcp::client_state::waiting) {
+ ImGui::Text("please wait.");
+ }
+
+ if (client.state == tcp::client_state::imports_ready) {
+ ImGui::Text("please wait.");
+ }
+
+ if (client.state == tcp::client_state::image_ready) {
+ ImGui::Text("please wait.");
+ }
+
+
+ if (client.state == tcp::client_state::injected) {
+ ImGui::Text("done.");
+ }
+
+ ImGui::End();
+
+ ImGui::Render();
+ ui::device_context->OMSetRenderTargets(1, &ui::main_render_target, NULL);
+ ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
+
+ ui::swap_chain->Present(1, 0);
+ }
- return 0;
+ ImGui_ImplDX11_Shutdown();
+ ImGui_ImplWin32_Shutdown();
+ ImGui::DestroyContext();
}