#include "DeviceSpoofer.h"
#include "Client.h"

auto DeviceSpoofer::onConnectionRequest(std::string* deviceId) -> void {
	std::random_device rd;
	std::mt19937 gen(rd());
	std::uniform_int_distribution<uint64_t> dis64;
	std::uniform_int_distribution<uint32_t> dis32;

	static auto to_hex = [](uint64_t value, int width) {
		return std::format("{:0{}x}", value, width);
		};

	generated =
		to_hex(dis32(gen), 8) + "-" +
		to_hex(dis32(gen) & 0xFFFF, 4) + "-" +
		to_hex((dis32(gen) & 0x0FFF) | 0x4000, 4) + "-" +
		to_hex((dis32(gen) & 0x3FFF) | 0x8000, 4) + "-" +
		to_hex(dis64(gen), 12).substr(0, 12);
	
	*deviceId = generated;

	spoofed = true;
}

auto DeviceSpoofer::onWorldTick(Player* _this) -> void {
	if (enabled && spoofed) {
		_this->setDeviceId(generated);

		Client::notifications.push_back({ _("Information"), _("Spoofed your device id!"), 5.f, 100.f });

		spoofed = false;
	}
}
