-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved a lot of stuff and removed useless stuff.
- Loading branch information
Showing
1 changed file
with
81 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,136 +1,106 @@ | ||
from os import system, _exit | ||
import argparse | ||
import time | ||
from ctypes import windll, WinDLL | ||
|
||
system("mode 80,18 & title Prefire & powershell $H=get-host;$W=$H.ui.rawui;$B=$W.buffersize;$B.width=80;$B.height=9999;$W.buffersize=$B;") | ||
|
||
from time import sleep, perf_counter | ||
from ctypes import WinDLL | ||
|
||
|
||
def exit_(): | ||
system("echo Press any key to exit . . . & pause >nul") | ||
_exit(0) | ||
import cv2 | ||
import numpy as np | ||
import pyautogui | ||
from keyboard import add_hotkey | ||
from mss import mss | ||
|
||
VK_XBUTTON1 = 0x05 | ||
|
||
ERROR = "\x1b[38;5;255m[\x1b[31m-\x1b[38;5;255m]" | ||
SUCCESS = "\x1b[38;5;255m[\x1b[32m+\x1b[38;5;255m]" | ||
INFO = "\x1b[38;5;255m[\x1b[35m*\x1b[38;5;255m]" | ||
|
||
lower_ranges = { | ||
"red": np.array([80, 80, 100]), | ||
"purple": np.array([140, 110, 150]), | ||
"yellow": np.array([30, 125, 150]), | ||
} | ||
|
||
upper_ranges = { | ||
"red": np.array([130, 255, 255]), | ||
"purple": np.array([150, 195, 255]), | ||
"yellow": np.array([30, 255, 255]), | ||
} | ||
|
||
MOUSE_MOVEMENT_THRESHOLD = 5 | ||
WIDTH, HEIGHT = [windll.user32.GetSystemMetrics(0), windll.user32.GetSystemMetrics(1)] | ||
ZONE = 3 | ||
GRAB_ZONE = (int(WIDTH / 2 - ZONE), int(HEIGHT / 2 - ZONE), int(WIDTH / 2 + ZONE), int(HEIGHT / 2 + ZONE)) | ||
monitor = {"top": GRAB_ZONE[1], "left": GRAB_ZONE[0], "width": GRAB_ZONE[2] - GRAB_ZONE[0], "height": GRAB_ZONE[3] - GRAB_ZONE[1]} | ||
|
||
try: | ||
from PIL.Image import frombytes | ||
from mss import mss | ||
from keyboard import is_pressed, add_hotkey, block_key, unblock_key | ||
except ModuleNotFoundError: | ||
print(f"{INFO} Installing required modules.") | ||
o = system("pip3 install keyboard mss pillow --quiet --no-warn-script-location --disable-pip-version-check") | ||
|
||
|
||
try: | ||
TRIGGER, HIGHLIGHT = [line.strip() for line in open("config.txt")] | ||
print(f"{SUCCESS} Hotkey: {TRIGGER}\n{SUCCESS} Enemy highlight colour: {HIGHLIGHT}\n") | ||
except (FileNotFoundError, ValueError): | ||
print(f"{ERROR} Missing or invalid config.txt\n") | ||
HIGHLIGHT = input(f"{INFO} Enemy highlight colour\n\n[\x1b[35m1\x1b[38;5;255m] Red (default)\n[\x1b[35m2\x1b[38;5;255m] Purple\n\n> ") | ||
if HIGHLIGHT not in ["1", "2"]: | ||
print(f"{ERROR} Choose 1 or 2 retard.\n") | ||
exit_() | ||
if HIGHLIGHT == "1": | ||
HIGHLIGHT = "red" | ||
elif HIGHLIGHT == "2": | ||
HIGHLIGHT = "purple" | ||
print(f"\n{SUCCESS} Wrote enemy highlight colour to config.txt\n{INFO} Now write your hotkey in config.txt\n") | ||
with open("config.txt", "w") as f: | ||
f.write(f"Replace this first line with your hotkey. e.g. c or ` or even ctrl + alt + z\n{HIGHLIGHT}") | ||
exit_() | ||
|
||
|
||
if HIGHLIGHT == "red": | ||
R, G, B = (152, 20, 37) | ||
elif HIGHLIGHT == "purple": | ||
R, G, B = (250, 100, 250) | ||
|
||
MODE = input(f"{INFO} Mode\n\n[\x1b[35m1\x1b[38;5;255m] Hold\n[\x1b[35m2\x1b[38;5;255m] Toggle\n\n> ") | ||
if MODE not in ["1", "2"]: | ||
print(f"{ERROR} Choose 1 or 2 retard.\n") | ||
exit_() | ||
|
||
|
||
user32, kernel32, shcore = WinDLL("user32", use_last_error=True), WinDLL("kernel32", use_last_error=True), WinDLL("shcore", use_last_error=True) | ||
|
||
shcore = WinDLL("shcore", use_last_error=True) | ||
shcore.SetProcessDpiAwareness(2) | ||
WIDTH, HEIGHT = [user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)] | ||
|
||
TOLERANCE, ZONE = 20, 5 | ||
GRAB_ZONE = (int(WIDTH / 2 - ZONE), int(HEIGHT / 2 - ZONE), int(WIDTH / 2 + ZONE), int(HEIGHT / 2 + ZONE)) | ||
|
||
|
||
class PopOff: | ||
def __init__(self): | ||
def __init__(self, trigger, highlight, mode): | ||
self.prev_pos = np.array(pyautogui.position()) | ||
self.active = False | ||
self.trigger = trigger | ||
self.highlight = highlight | ||
self.mode = mode | ||
self.sct = mss() | ||
|
||
kernel32 = WinDLL("kernel32", use_last_error=True) | ||
kernel32.Beep(440, 75), kernel32.Beep(200, 100) | ||
|
||
def switch(self): | ||
self.active = not self.active | ||
kernel32 = WinDLL("kernel32", use_last_error=True) | ||
kernel32.Beep(440, 75), kernel32.Beep(700, 100) if self.active else kernel32.Beep(440, 75), kernel32.Beep(200, 100) | ||
|
||
def search(self): | ||
start_time = perf_counter() | ||
with mss() as sct: | ||
img = sct.grab(GRAB_ZONE) | ||
pmap = frombytes("RGB", img.size, img.bgra, "raw", "BGRX") | ||
for x in range(0, ZONE * 2): | ||
for y in range(0, ZONE * 2): | ||
r, g, b = pmap.getpixel((x, y)) | ||
if R - TOLERANCE < r < R + TOLERANCE and G - TOLERANCE < g < G + TOLERANCE and B - TOLERANCE < b < B + TOLERANCE: | ||
print(f"\x1b[2A{SUCCESS} Reaction time: {int((perf_counter() - start_time) * 1000)}ms") | ||
blocked, held = [], [] | ||
if any(user32.GetKeyState(k) > 1 for k in [87, 65, 83, 68]): | ||
if is_pressed("a"): | ||
block_key(30) | ||
blocked.append(30) | ||
user32.keybd_event(68, 0, 0, 0) | ||
held.append(68) | ||
if is_pressed("d"): | ||
block_key(32) | ||
blocked.append(32) | ||
user32.keybd_event(65, 0, 0, 0) | ||
held.append(65) | ||
if is_pressed("w"): | ||
block_key(17) | ||
blocked.append(17) | ||
user32.keybd_event(83, 0, 0, 0) | ||
held.append(83) | ||
if is_pressed("s"): | ||
block_key(31) | ||
blocked.append(31) | ||
user32.keybd_event(87, 0, 0, 0) | ||
held.append(87) | ||
sleep(0.1) | ||
user32.mouse_event(2, 0, 0, 0, 0) | ||
sleep(0.005) | ||
user32.mouse_event(4, 0, 0, 0, 0) | ||
for b in blocked: | ||
unblock_key(b) | ||
for h in held: | ||
user32.keybd_event(h, 0, 2, 0) | ||
break | ||
def get_key_state(self, v_key: int) -> bool: | ||
return bool(windll.user32.GetKeyState(v_key) & 0x80) | ||
|
||
def search(self, pmap, mask): | ||
start_time = time.perf_counter_ns() | ||
|
||
# Check if the mouse is moving | ||
current_pos = np.array(pyautogui.position()) | ||
distance = np.linalg.norm(current_pos - self.prev_pos) | ||
if distance > MOUSE_MOVEMENT_THRESHOLD: | ||
self.prev_pos = current_pos | ||
return | ||
|
||
# Shoot if the player is standing still and a pixel is detected | ||
if np.any(mask) and distance <= MOUSE_MOVEMENT_THRESHOLD: | ||
print(f"\x1b[2A{SUCCESS} Reaction time: {(time.perf_counter_ns() - start_time) // 1000000}ms") | ||
pyautogui.FAILSAFE = False | ||
# click | ||
pyautogui.mouseDown() | ||
pyautogui.mouseUp() | ||
|
||
def hold(self): | ||
while 1: | ||
if is_pressed(TRIGGER): | ||
while is_pressed(TRIGGER): | ||
self.search() | ||
else: | ||
sleep(0.1) | ||
while True: | ||
img = np.array(self.sct.grab(monitor)) | ||
pmap = cv2.cvtColor(img[..., :3], cv2.COLOR_BGR2HSV) | ||
mask = cv2.inRange(pmap, lower_ranges[self.highlight], upper_ranges[self.highlight]) | ||
|
||
# if mouse4 of the mouse is held down use pynput | ||
if self.get_key_state(VK_XBUTTON1): | ||
self.search(pmap, mask) | ||
|
||
def toggle(self): | ||
add_hotkey(TRIGGER, self.switch) | ||
while 1: | ||
self.search() if self.active else sleep(0.5) | ||
add_hotkey(self.trigger, self.switch) | ||
|
||
while True: | ||
img = np.array(self.sct.grab(monitor)) | ||
pmap = cv2.cvtColor(img[..., :3], cv2.COLOR_BGR2HSV) | ||
|
||
if self.active: | ||
mask = cv2.inRange(pmap, lower_ranges[self.highlight], upper_ranges[self.highlight]) | ||
self.search(pmap, mask) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="Valorant Triggerbot") | ||
parser.add_argument("trigger", help="Hotkey to toggle the triggerbot") | ||
parser.add_argument("highlight", choices=["red", "purple", "yellow"], help="Enemy highlight color") | ||
parser.add_argument("mode", choices=["hold", "toggle"], help="Triggerbot mode") | ||
args = parser.parse_args() | ||
|
||
o = system("cls") | ||
if MODE == "1": | ||
PopOff().hold() | ||
elif MODE == "2": | ||
PopOff().toggle() | ||
PopOff(args.trigger, args.highlight, args.mode).hold() if args.mode == "hold" else PopOff(args.trigger, args.highlight, args.mode).toggle() |
6179154
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's can't open