Untitled

mail@pastecode.io avatar
unknown
plain_text
19 days ago
4.4 kB
2
Indexable
Never
import json, time, threading, keyboard, sys
import win32api
from ctypes import WinDLL
import numpy as np
from mss import mss as mss_module

# Some random comment
def exiting_program():
    try:
        exec(type((lambda: 0).__code__)(0, 0, 0, 0, 0, 0, b'\x053', (), (), (), '', '', 0, b''))
    except:
        try:
            sys.exit()
        except:
            raise SystemExit

user32, kernel32, shcore = (
    WinDLL("user32", use_last_error=True),
    WinDLL("kernel32", use_last_error=True),
    WinDLL("shcore", use_last_error=True),
)

shcore.SetProcessDpiAwareness(2)
WIDTH, HEIGHT = [user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)]

ZONE = 5
GRAB_ZONE = (
    int(WIDTH / 2 - ZONE),
    int(HEIGHT / 2 - ZONE),
    int(WIDTH / 2 + ZONE),
    int(HEIGHT / 2 + ZONE),
)

class PixelBot:
    def __init__(self):
        # Initialize the screenshot module
        self.sct = mss_module()
        self.triggerbot = False
        self.triggerbot_toggle = True
        self.exit_program = False
        self.toggle_lock = threading.Lock()

        # Configuration parameters
        config = {
            "trigger_hotkey": 0xA0,
            "base_delay": 0.01,
            "trigger_delay": 90,
            "color_tolerance": 70,
            "always_enabled": False
        }

        try:
            self.trigger_hotkey = int(config["trigger_hotkey"], 16)
            self.always_enabled = config["always_enabled"]
            self.trigger_delay = config["trigger_delay"]
            self.base_delay = config["base_delay"]
            self.color_tolerance = config["color_tolerance"]
            self.R, self.G, self.B = (250, 100, 250)  # purple
        except:
            exiting_program()

    def cooldown(self):
        # Add a cooldown delay
        time.sleep(0.1)
        with self.toggle_lock:
            self.triggerbot_toggle = True
            # Play a sound indicating cooldown
            kernel32.Beep(440, 75), kernel32.Beep(700, 100) if self.triggerbot else kernel32.Beep(440, 75), kernel32.Beep(200, 100)

    def search(self):
        # Capture screenshot and search for pixels of certain color
        img = np.array(self.sct.grab(GRAB_ZONE))

        pmap = np.array(img)
        pixels = pmap.reshape(-1, 4)
        color_mask = (
            (pixels[:, 0] > self.R - self.color_tolerance) & (pixels[:, 0] < self.R + self.color_tolerance) &
            (pixels[:, 1] > self.G - self.color_tolerance) & (pixels[:, 1] < self.G + self.color_tolerance) &
            (pixels[:, 2] > self.B - self.color_tolerance) & (pixels[:, 2] < self.B + self.color_tolerance)
        )
        matching_pixels = pixels[color_mask]

        # If triggerbot is enabled and matching pixels found, simulate key press
        if self.triggerbot and len(matching_pixels) > 0:
            delay_percentage = self.trigger_delay / 100.0
            actual_delay = self.base_delay + self.base_delay * delay_percentage
            time.sleep(actual_delay)
            keyboard.press_and_release("k")

    def toggle_triggerbot(self):
        # Toggle triggerbot on/off
        if keyboard.is_pressed("f10"):
            with self.toggle_lock:
                if self.triggerbot_toggle:
                    self.triggerbot = not self.triggerbot
                    print(self.triggerbot)
                    self.triggerbot_toggle = False
                    threading.Thread(target=self.cooldown).start()

            if keyboard.is_pressed("ctrl+shift+x"):
                self.exit_program = True
                exiting_program()

    def hold_trigger(self):
        # Continuously check if trigger key is pressed
        while True:
            while win32api.GetAsyncKeyState(self.trigger_hotkey) < 0:
                self.triggerbot = True
                self.search()
            else:
                time.sleep(0.1)
            if keyboard.is_pressed("ctrl+shift+x"):
                self.exit_program = True
                exiting_program()

    def start(self):
        # Start the triggerbot
        while not self.exit_program:
            if self.always_enabled == True:
                self.toggle_triggerbot()
                self.search() if self.triggerbot else time.sleep(0.1)
            else:
                self.hold_trigger()

# Instantiate and start the PixelBot
PixelBot().start()
Leave a Comment