|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include "../../../../SDK/SDK.hpp" |
| 4 | +#include "../../../../SDK//Client/Network/Packet/PlaySoundPacket.hpp" |
| 5 | +#include "../../../../SDK//Client/Network/Packet/TextPacket.hpp" |
| 6 | +#include <format> |
| 7 | +#include "../../../Events/Listener.hpp" |
| 8 | +#include "../../../Events/Input/KeyEvent.hpp" |
| 9 | +#include "../Module.hpp" |
| 10 | +#include "../../../GUI/Engine/Engine.hpp" |
| 11 | +#include <Windows.h> |
| 12 | +#include <chrono> |
| 13 | +#include "../../../../SDK/SDK.hpp" |
| 14 | +#include "../../../../SDK//Client/Network/Packet/CommandRequestPacket.hpp" |
| 15 | +#include <format> |
| 16 | +#include "../../../Events/Listener.hpp" |
| 17 | +#include "../../../Events/Input/KeyEvent.hpp" |
| 18 | +#include "../Module.hpp" |
| 19 | +#include "../../../GUI/Engine/Engine.hpp" |
| 20 | +#include <Windows.h> |
| 21 | +#include <chrono> |
| 22 | +#include <iostream> |
| 23 | +#include <iomanip> |
| 24 | +#include <vector> |
| 25 | +#include <random> |
| 26 | + |
| 27 | +class AutoRQListener : public Listener { |
| 28 | + Module *module; |
| 29 | + |
| 30 | + std::string currentGame = ""; |
| 31 | + bool triggered = false; |
| 32 | + |
| 33 | + |
| 34 | + static std::vector<uint8_t> generateUUIDBytes() { |
| 35 | + std::random_device rd; |
| 36 | + std::mt19937 gen(rd()); |
| 37 | + std::uniform_int_distribution<> dis(0, 255); |
| 38 | + |
| 39 | + std::vector<uint8_t> uuidBytes(16); |
| 40 | + for (int i = 0; i < 16; ++i) { |
| 41 | + uuidBytes[i] = static_cast<uint8_t>(dis(gen)); |
| 42 | + } |
| 43 | + |
| 44 | + // Set the version to 4 |
| 45 | + uuidBytes[6] = (uuidBytes[6] & 0x0F) | 0x40; |
| 46 | + |
| 47 | + // Set the variant to RFC 4122 |
| 48 | + uuidBytes[8] = (uuidBytes[8] & 0x3F) | 0x80; |
| 49 | + |
| 50 | + return uuidBytes; |
| 51 | + } |
| 52 | + |
| 53 | + static std::string convertUUIDBytesToString(const std::vector<uint8_t>& uuidBytes) { |
| 54 | + std::stringstream ss; |
| 55 | + |
| 56 | + for (const auto& byte : uuidBytes) { |
| 57 | + ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(byte); |
| 58 | + } |
| 59 | + |
| 60 | + return ss.str(); |
| 61 | + } |
| 62 | + |
| 63 | + // Function to modify and return the UUID bytes |
| 64 | + static std::vector<uint8_t> UUIDtoMC() { |
| 65 | + // Generate a UUID v4 |
| 66 | + std::vector<uint8_t> uuidBytes = generateUUIDBytes(); |
| 67 | + |
| 68 | + // Reverse the first 8 bytes |
| 69 | + for (int i = 0; i < 4; ++i) { |
| 70 | + std::swap(uuidBytes[i], uuidBytes[7 - i]); |
| 71 | + } |
| 72 | + |
| 73 | + // Reverse the next 8 bytes |
| 74 | + for (int i = 8; i < 12; ++i) { |
| 75 | + std::swap(uuidBytes[i], uuidBytes[15 - i]); |
| 76 | + } |
| 77 | + |
| 78 | + return uuidBytes; |
| 79 | + } |
| 80 | + |
| 81 | + |
| 82 | + void onPacketReceive(PacketEvent &event) override { |
| 83 | + MinecraftPacketIds id = event.getPacket()->getId(); |
| 84 | + |
| 85 | + // TODO: add support for other servers (look for "won the game" text) |
| 86 | + if (id == MinecraftPacketIds::PlaySoundA) { |
| 87 | + auto *pkt = reinterpret_cast<PlaySoundPacket *>(event.getPacket()); |
| 88 | + |
| 89 | + if (pkt->mName == "raid.horn" || |
| 90 | + pkt->mName == "raid.horn") { |
| 91 | + triggered = true; |
| 92 | + std::shared_ptr<Packet> packet = SDK::createPacket(77); |
| 93 | + auto* command_packet = reinterpret_cast<CommandRequestPacket*>(packet.get()); |
| 94 | + |
| 95 | + command_packet->command = "/connection"; |
| 96 | + |
| 97 | + command_packet->origin.type = CommandOriginType::Player; |
| 98 | + |
| 99 | + command_packet->InternalSource = true; |
| 100 | + |
| 101 | + SDK::clientInstance->getPacketSender()->sendToServer(command_packet); |
| 102 | + |
| 103 | + } //std::cout << pkt->mName << std::endl; |
| 104 | + |
| 105 | + } |
| 106 | + else if (id == MinecraftPacketIds::Text) { |
| 107 | + auto* pkt = reinterpret_cast<TextPacket*>(event.getPacket()); |
| 108 | + //if (pkt->type == TextPacketType::SYSTEM) { |
| 109 | + std::string textToCheck = "You are connected to server name "; |
| 110 | + std::string textToCheckToSilence = "You are connected"; |
| 111 | + if (pkt->message.find(textToCheck) != std::string::npos && triggered) { |
| 112 | + std::string server = pkt->message.replace(0, textToCheck.length(), ""); |
| 113 | + std::regex pattern("\\d+"); |
| 114 | + std::string name = std::regex_replace(server, pattern, ""); |
| 115 | + FlarialGUI::Notify("Preparing Q: " + name); |
| 116 | + std::thread t([name]() { |
| 117 | + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); |
| 118 | + |
| 119 | + FlarialGUI::Notify("Executing command /q " + name); |
| 120 | + |
| 121 | + std::shared_ptr<Packet> packet = SDK::createPacket(77); |
| 122 | + auto* command_packet = reinterpret_cast<CommandRequestPacket*>(packet.get()); |
| 123 | + command_packet->command = "/q " + name; |
| 124 | + |
| 125 | + command_packet->origin.type = CommandOriginType::Player; |
| 126 | + |
| 127 | + command_packet->InternalSource = true; |
| 128 | + SDK::clientInstance->getPacketSender()->sendToServer(command_packet); |
| 129 | + }); |
| 130 | + t.detach(); |
| 131 | + triggered = false; |
| 132 | + pkt->message = ""; |
| 133 | + |
| 134 | + } |
| 135 | + else if (pkt->message.find(textToCheckToSilence) != std::string::npos) { |
| 136 | + pkt->message = ""; |
| 137 | + } |
| 138 | + //} |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + void onPacketSend(PacketEvent &event) override { |
| 143 | + /*if (event.getPacket()->getId() == MinecraftPacketIds::Text) { |
| 144 | + TextPacket *pkt = reinterpret_cast<TextPacket *>(event.getPacket()); |
| 145 | + std::cout << pkt->message << std::endl; |
| 146 | + |
| 147 | + } |
| 148 | + */ |
| 149 | + } |
| 150 | + |
| 151 | +public: |
| 152 | + explicit AutoRQListener(const char string[5], Module * |
| 153 | + |
| 154 | + module) { |
| 155 | + this->name = string; |
| 156 | + this->module = module; |
| 157 | + } |
| 158 | +}; |
0 commit comments