Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // TODO: Eventually make some information globals so we can display randomization debug information inside the menu
- namespace autoclicker {
- float target;
- float cps;
- void run();
- void deviate();
- void spike();
- void fluctuate();
- void set_after_for(bool& condition, util::timer& timer, float after, float time);
- std::vector<float> delays;
- void test_randomization();
- }
- enum class e_spike : uint8_t {
- none = 0,
- up,
- down
- };
- // This code is pretty messy
- // I think it would be pretty nice if I generate the delays around 100 ahead so I can test it all the time
- void autoclicker::run() {
- target = mouse_down ? settings::cps : 5.0f;
- deviate();
- spike();
- fluctuate();
- if (!mouse_down) {
- delays.clear();
- return;
- }
- if (settings::only_mc && hwnd != GetForegroundWindow())
- return;
- // No point in clicking at this low of a cps
- if (cps < 1.5f)
- return;
- static util::timer timer;
- static auto delay = 0.0f;
- // Subtract that 1ms just to try to make it a bit more accurate
- if (!timer.has_time_passed(std::chrono::duration<float>(delay)))
- return;
- timer.reset();
- // Ignore test timer for debugging
- static util::timer test;
- // Send mouse down input
- INPUT input = { 0 };
- static bool holding = false;
- if (!holding) {
- input.type = INPUT_MOUSE;
- input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
- ::SendInput(1, &input, sizeof(INPUT));
- test.reset();
- }
- // TODO: Incorporate blockhit
- // Random hold if break blocks is disabled
- static util::timer hold_timer;
- static auto hold_delay = 0.0f;
- if (!settings::break_blocks) {
- if (hold_timer.has_time_passed(std::chrono::duration<float>(hold_delay))) {
- hold_timer.reset();
- hold_delay = util::random(0.02f, 0.05f);
- holding = false;
- }
- else {
- holding = true;
- return;
- }
- }
- else {
- hold_delay = 0.0f;
- }
- // Send mouse up input
- input = { 0 };
- input.type = INPUT_MOUSE;
- input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
- ::SendInput(1, &input, sizeof(INPUT));
- delay = (1.0f / cps) - hold_delay;
- delays.push_back(cps);
- test_randomization();
- //printf("[autoclicker] target %f\tcps %f\n", target, cps);
- }
- // There are some somewhat magic seeming numbers in how this autoclickers randomization is setup but at least its
- // not like those ones using ms delays instead of seconds so its readable
- void autoclicker::deviate() {
- static util::timer timer;
- static auto update = util::random(3.0f, 15.0f);
- static auto deviation = 0.0f;
- if (timer.has_time_passed(std::chrono::duration<float>(update))) {
- timer.reset();
- update = util::random<float>(3.0f, 15.0f);
- deviation = util::random<float>(-2.0f, 0.5f);
- printf("[deviate] %fcps for %fs\n", deviation, update);
- }
- // TODO: Slowly go downwards overtime and even stop and restart since no one can click the same cps forever
- target += deviation;
- }
- // This includes dropping even though I do think dropping should be less rare
- void autoclicker::spike() {
- static util::timer timer;
- static auto after = util::random<float>(5.0f, 20.0f);
- static auto time = util::random<float>(0.2f, 0.8f);
- static e_spike spike_stage = e_spike::none;
- static bool spiking;
- // Check for when it stops spiking
- static auto previous = spiking;
- if (!previous && spiking) {
- spike_stage = (e_spike)util::random<uint16_t>(1, 2);
- printf("[spike] %d for %fs\n", (int)spike_stage, time);
- }
- if (previous && !spiking) {
- spike_stage = e_spike::none;
- after = util::random<float>(5.0f, 20.0f);
- time = util::random<float>(0.2f, 0.8f);
- printf("[spike] none for %fs\n", after);
- }
- previous = spiking;
- set_after_for(spiking, timer, after, time);
- switch (spike_stage) {
- case e_spike::none:
- break;
- case e_spike::up:
- target += settings::up;
- break;
- case e_spike::down:
- target -= settings::down;
- break;
- default:
- break;
- }
- }
- // TODO: Make all fields customizable
- void autoclicker::fluctuate() {
- constexpr auto delay = 0.1f;
- constexpr auto radius = 2.0f;
- static util::timer timer;
- if (!timer.has_time_passed(std::chrono::duration<float>(delay)))
- return;
- timer.reset();
- // Normal fluctuation
- const auto previous = cps;
- cps += util::random(-0.5f, 0.4f);
- const auto step = 1.0f / delay;
- // TODO: I'm fairly sure this math is so so incorrect, I just cba to fix it right after waking up
- const auto exp = (target - cps) / radius;
- //printf("[fluctuate] target %fcps\tcurrent %fcps\tcalculation %f\n", target, cps, exp);
- // Will make it take 2 seconds to reach desired target
- cps += util::random(exp / (step * 1.5f), exp / (step * 2.0f));
- //printf("[fluctuate] change %f\n", cps - previous);
- }
- void autoclicker::set_after_for(bool& condition, util::timer &timer, float after, float time) {
- if (!condition && timer.has_time_passed(std::chrono::duration<float>(after))) {
- timer.reset();
- condition = true;
- }
- if (condition && timer.has_time_passed(std::chrono::duration<float>(time))) {
- timer.reset();
- condition = false;
- }
- }
- // Mimic some of these checks
- // https://github.com/sim0n/Baldr/tree/master/src/main/java/net/rifttech/baldr/check/impl/autoclicker
- void autoclicker::test_randomization() {
- // This could cause overflows
- float sum = std::accumulate(delays.begin(), delays.end(), 0.0f);
- float average = sum / static_cast<float>(delays.size());
- std::vector<float> differences(delays.size());
- std::transform(delays.begin(), delays.end(), differences.begin(), [average](float x) {
- return x - average;
- });
- float squared_differences = std::inner_product(differences.begin(), differences.end(), differences.begin(), 0.0f);
- float standard_deviation = std::sqrt(squared_differences / (float)delays.size());
- if (standard_deviation < 0.45f) {
- //printf("[alert] standard deviation is too low %f\n", standard_deviation);
- }
- else {
- //printf("[randomization] standard deviation %f\n", standard_deviation);
- }
- // There is 100% a better way to calculate this
- float r = 0.0f;
- for (auto difference : differences) {
- r += std::pow(difference, 4.0f);
- }
- const auto kurtosis = (float)differences.size() * r / std::pow(squared_differences, 2.0f);
- if (kurtosis <= 0.0f) {
- //printf("[alert] kurtosis is too low %f\n", kurtosis);
- }
- else {
- //printf("[randomization] kurtosis %f\n", kurtosis);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement