Advertisement
NoTextForSpeech

roblox-colorbot

Feb 24th, 2024 (edited)
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 21.09 KB | None | 0 0
  1. import keyboard # Library that relates to reading and writing keyboard inputs
  2. import os
  3. import mss # Takes screenshot
  4. import configparser
  5. import cv2 # Reads through screenshot
  6. import numpy as np # Works with CV2
  7. import win32api # Windows API that I just use for mouse button keybinds and mouse movement to an enemy
  8. import win32con
  9. from threading import Thread
  10. from colorama import Fore, Style # Makes the colorful text in the console
  11. import ctypes # Also Windows API to move the mouse
  12. import time # Allows for specific time delays and such
  13. import pygetwindow as gw # Only takes screenshots when youre actually playing
  14. from urllib.request import urlopen
  15. from webbrowser import open as openwebpage
  16. import math
  17. #importing all the modules we need to run the code.
  18.  
  19.  
  20. # its important that you change (if youre using pyinstaller) os.path.dirname(__file__) to os.path.dirname(os.path.dirname(__file__))
  21. config_file_path = os.path.join(os.path.dirname(__file__), "config.ini") # Searching for the file called config.ini to read settings
  22.  
  23. try: # checks for updates using the version number we defined earlier, pasted from andrewdarkyy cuz im lazy and his colorbot is just a modded version of mine so like who cares
  24.     if not "9" in urlopen("https://pastebin.com/raw/t0pxbWr8").read().decode("utf-8"):
  25.         print("HI")
  26.         while True:
  27.             time.sleep(0.1)
  28. except Exception as e:
  29.     print("Error checking update: ", e)
  30.     print("Continuing anyway!")
  31.     time.sleep(5)
  32.     pass
  33.  
  34. try:
  35.     config = configparser.ConfigParser() #this is separating all the config options you set.
  36.     config.optionxform = str
  37.     config.read(config_file_path)
  38. except Exception as e:
  39.         print("Error reading config:", e)
  40.  
  41. def rbxfocused():
  42.     try:
  43.         return "Roblox" == gw.getActiveWindow().title
  44.     except:
  45.         return False
  46.  
  47. def change_config_setting(setting_name, new_value): #changing the config settings ... duh.
  48.     try:
  49.         config.set("Config", setting_name, str(new_value))
  50.         with open(config_file_path, "w") as configfile:
  51.             config.write(configfile)
  52.         load()  # Update global variables after changing config
  53.         print(f"Config setting '{setting_name}' changed to {new_value}")
  54.     except Exception as e:
  55.         print(f"Error changing config setting '{setting_name}': {e}")
  56.  
  57. def load(): #loading the settings, duh.
  58.     global sct, center, screenshot, AIM_KEY, SWITCH_MODE_KEY, FOV_KEY_UP, FOV_KEY_DOWN, CAM_FOV, AIM_OFFSET_Y, AIM_OFFSET_X, AIM_SPEED_X, AIM_SPEED_Y, upper, lower, UPDATE_KEY, AIM_FOV, BINDMODE, COLOR, colorname, toggleholdmodes, TRIGGERBOT, TRIGGERBOT_DELAY, SMOOTHENING, SMOOTH_FACTOR, TRIGGERBOT_DISTANCE, user32, kernel
  59.     #these are essential variables that show the settings of the application.
  60.     os.system("title Colorbot")
  61.     toggleholdmodes = ("Hold", "Toggle") #this is a tuple of [0, 1] where hold is 0, toggle is 1.
  62.     user32 = ctypes.windll.user32
  63.     kernel = np.ones((3, 3), np.uint8) # 3x3 array of 1s for structuring purposes
  64.    
  65.  
  66.     try:
  67.         buffer = open(os.path.join(os.path.dirname(__file__), "lastlaunch.txt"), "r")
  68.         currenttime = time.time()
  69.         if currenttime - float(buffer.read()) >= 17990:
  70.             buffer2 = open(os.path.join(os.path.dirname(__file__), "lastlaunch.txt"), "w+")
  71.             buffer2.write(str(currenttime))
  72.             buffer2.close()
  73.             openwebpage("https://discord.gg/nDREsRUj9V")
  74.         buffer.close()
  75.     except:
  76.         buffer = open(os.path.join(os.path.dirname(__file__), "lastlaunch.txt"), "w+")
  77.         buffer.write(str(time.time()))
  78.         buffer.close()
  79.         openwebpage("https://discord.gg/nDREsRUj9V")
  80.    
  81.     try: #read the config file again, just in case if the user changed the settings while the program was running.
  82.         config = configparser.ConfigParser() #this is separating all the config options you set.
  83.         config.optionxform = str
  84.         config.read(config_file_path)
  85.     except Exception as e:
  86.         print("Error reading config:", e)
  87.    
  88.     try:
  89.         BINDMODE = config.get("Config", "BINDMODE")
  90.         if (
  91.             BINDMODE.lower() == "win32"
  92.             or BINDMODE.lower() == "win32api"
  93.             or BINDMODE.lower() == "win"
  94.         ):
  95.             AIM_KEY_STRING = config.get("Config", "AIM_KEY")
  96.             if "win32con" in AIM_KEY_STRING:
  97.                 AIM_KEY = eval(AIM_KEY_STRING, {"win32con": win32con})
  98.             else:
  99.                 AIM_KEY = str(AIM_KEY_STRING)
  100.         if (
  101.             BINDMODE.lower() == "keyboard"
  102.             or BINDMODE.lower() == "k"
  103.             or BINDMODE.lower() == "key"
  104.         ):
  105.             AIM_KEY = config.get("Config", "AIM_KEY")
  106.         SWITCH_MODE_KEY = config.get("Config", "SWITCH_MODE_KEY")
  107.         UPDATE_KEY = config.get("Config", "UPDATE_KEY")
  108.         FOV_KEY_UP = config.get("Config", "FOV_KEY_UP")
  109.         FOV_KEY_DOWN = config.get("Config", "FOV_KEY_DOWN")
  110.         CAM_FOV = int(config.get("Config", "CAM_FOV"))
  111.         AIM_FOV = int(config.get("Config", "AIM_FOV"))
  112.         AIM_OFFSET_Y = int(config.get("Config", "AIM_OFFSET_Y"))
  113.         AIM_OFFSET_X = int(config.get("Config", "AIM_OFFSET_X"))
  114.         AIM_SPEED_X = float(config.get("Config", "AIM_SPEED_X"))
  115.         AIM_SPEED_Y = float(config.get("Config", "AIM_SPEED_Y"))
  116.         TRIGGERBOT = config.get("Config", "TRIGGERBOT")
  117.         TRIGGERBOT_DELAY = int(config.get("Config", "TRIGGERBOT_DELAY"))
  118.         TRIGGERBOT_DISTANCE = int(config.get("Config", "TRIGGERBOT_DISTANCE"))
  119.         SMOOTHENING = config.get("Config", "SMOOTHENING")
  120.         SMOOTH_FACTOR = float(config.get("Config", "SMOOTH_FACTOR"))
  121.         UPPER_COLOR = tuple(map(int, config.get("Config", "UPPER_COLOR").split(', '))) # pasted from the modded colorbot but we're partnered so its chill
  122.         LOWER_COLOR = tuple(map(int, config.get("Config", "LOWER_COLOR").split(', ')))
  123.         if SMOOTH_FACTOR <= 0:
  124.             SMOOTHENING = "disabled"
  125.         COLOR = config.get("Config", "COLOR")
  126.         if COLOR.lower() == "yellow":
  127.             colorname = Fore.YELLOW
  128.             upper = np.array((38, 255, 203), dtype="uint8") # The upper and lower ranges defined are the colors that the aimbot will detect and shoot at
  129.             lower = np.array((30, 255, 201), dtype="uint8") # It's basically a group of a VERY specific shade of yellow (in this case) that it will shoot at and nothing else. The format is HSV, which differs from RGB.
  130.         if COLOR.lower() == "blue":
  131.             colorname = Fore.BLUE
  132.             upper = np.array((123, 255, 217), dtype="uint8")
  133.             lower = np.array((113, 206, 189), dtype="uint8")
  134.         if COLOR.lower() == "pink" or COLOR.lower() == "magenta" or COLOR.lower() == "purple":
  135.             colorname = Fore.MAGENTA
  136.             upper = np.array((150, 255, 201), dtype="uint8")
  137.             lower = np.array((150, 255, 200), dtype="uint8")
  138.         if COLOR.lower() == "green":
  139.             colorname = Fore.GREEN
  140.             upper = np.array((60, 255, 201), dtype="uint8")
  141.             lower = np.array((60, 255, 201), dtype="uint8")
  142.         if COLOR.lower() == "cyan":
  143.             colorname = Fore.CYAN
  144.             upper = np.array((90, 255, 201), dtype="uint8")
  145.             lower = np.array((90, 255, 201), dtype="uint8")
  146.         if COLOR.lower() == "red":
  147.             colorname = Fore.RED
  148.             upper = np.array((0, 255, 201), dtype="uint8")
  149.             lower = np.array((0, 255, 201), dtype="uint8")
  150.         if COLOR.lower() == "custom":
  151.             colorname = Fore.WHITE
  152.             upper = np.array(UPPER_COLOR, dtype="uint8")
  153.             lower = np.array(LOWER_COLOR, dtype="uint8")
  154.         if COLOR.lower() == "0000ff":
  155.             colorname = Fore.BLUE
  156.             upper = np.array((123, 255, 255), dtype="uint8")
  157.             lower = np.array((120, 147, 69), dtype="uint8")
  158.         if COLOR.lower() == "aimblox":
  159.             colorname = Fore.LIGHTRED_EX
  160.             upper = np.array((4, 225, 206), dtype="uint8")
  161.             lower = np.array((0, 175, 119), dtype="uint8")
  162.         if COLOR.lower() == "black":
  163.             colorname = Fore.WHITE
  164.             upper = np.array((0, 0, 0), dtype="uint8")
  165.             lower = np.array((0, 0, 0), dtype="uint8")
  166.         sct = mss.mss()
  167.         screenshot = sct.monitors[0] #this is the settings for the screen capture, the program screenshots your first monitor and continues to look for enemies.
  168.         screenshot["left"] = int((screenshot["width"] / 2) - (CAM_FOV / 2))
  169.         screenshot["top"] = int((screenshot["height"] / 2) - (CAM_FOV / 2))
  170.         screenshot["width"] = CAM_FOV
  171.         screenshot["height"] = CAM_FOV
  172.         center = CAM_FOV / 2
  173.  
  174.     except Exception as e:
  175.         print("Error loading settings:", e)
  176. load()
  177.  
  178. def lclc():
  179.     try:
  180.         return win32api.GetAsyncKeyState(AIM_KEY) < 0 #checking if the aim key is pressed (mouse buttons)
  181.     except Exception as e:
  182.         print("Error checking key state:", e)
  183.  
  184. class trb0t:
  185.     def __init__(self): #initialize the code, first set the variables for default settings.
  186.         self.AIMtoggled = False
  187.         self.switchmode = 1 # as i said earlier, the array is 0-1, 0 being hold, 1 being toggle. the default is TOGGLE as you can see.
  188.         self.__clicks = 0 # clicks to keep track of colorbot
  189.         self.__shooting = False
  190.  
  191.     def __stop(self):
  192.         oldclicks = self.__clicks
  193.         time.sleep(.05)
  194.         if self.__clicks == oldclicks:
  195.             user32.mouse_event(0x0004)
  196.  
  197.     def __delayedaim(self):
  198.         self.__shooting = True
  199.         time.sleep(TRIGGERBOT_DELAY / 1000)
  200.         user32.mouse_event(0x0002)
  201.         self.__clicks += 1
  202.         Thread(target = self.__stop).start()
  203.         self.__shooting = False
  204.  
  205.     def process(self): #process all images we're capturing
  206.         if rbxfocused():
  207.             try:
  208.                 img = np.array(sct.grab(screenshot)) #grab screenshot
  209.                 hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) #grab hsv color format
  210.                 mask = cv2.inRange(hsv, lower, upper) # create a mask of only the enemy colors
  211.                 dilated = cv2.dilate(mask, kernel, iterations=5) # dilation makes objects appear larger for the aimbot
  212.                 thresh = cv2.threshold(dilated, 60, 255, cv2.THRESH_BINARY)[1] # threshold
  213.                 (contours, hierarchy) = cv2.findContours(
  214.                     thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE # find contours
  215.                 )
  216.                 if len(contours) != 0: # if enemies are on screen: (or if there are contours of enemies on screen)
  217.                     contour = max(contours, key=cv2.contourArea)
  218.                     topmost = tuple(contour[contour[:, :, 1].argmin()][0]) #finds the highest contour vertically (highest point of the enemy, their head)
  219.                     x = topmost[0] - center + AIM_OFFSET_X # calculating the perfect center of the enemy's head by offsetting it a set amount of pixels
  220.                     y = topmost[1] - center + AIM_OFFSET_Y
  221.                     distance = math.sqrt(x**2 + y**2) # basic distance in a 2d plane. calculated using pythagorean theorem.
  222.                     if distance <= AIM_FOV:
  223.                         x2 = x * AIM_SPEED_X
  224.                         y2 = y * AIM_SPEED_Y
  225.                         x2 = int(x2)
  226.                         y2 = int(y2)
  227.                         if SMOOTHENING.lower() != "disabled":
  228.                             if distance >= SMOOTH_FACTOR:
  229.                                 user32.mouse_event(0x0001, x2, y2, 0, 0) #move the mouse towards, usually should feel like aimassist.
  230.                         else:
  231.                             user32.mouse_event(0x0001, x2, y2, 0, 0) #move the mouse towards, usually should feel like aimassist.
  232.                         if TRIGGERBOT != "disabled" and distance <= TRIGGERBOT_DISTANCE:
  233.                             if TRIGGERBOT_DELAY != 0:
  234.                                 if self.__shooting == False:
  235.                                     Thread(target = self.__delayedaim).start()
  236.                             else:
  237.                                 user32.mouse_event(0x0002)
  238.                                 self.__clicks += 1
  239.                                 Thread(target = self.__stop).start()
  240.                        
  241.             except Exception as e:
  242.                 print("Error in processing:", e)
  243.  
  244.     def AIMtoggle(self):
  245.         try:
  246.             self.AIMtoggled = not self.AIMtoggled
  247.             time.sleep(0.1) # very short cooldown to stop it from thinking we're rapid toggling.
  248.         except Exception as e:
  249.             print("Error toggling AIM:", e)
  250.  
  251.     def modeswitch(self): #switch the modes from again, the array, from 0 to 1, 0 being hold, 1 being toggle.
  252.         try:
  253.             if self.switchmode == 0:
  254.                 self.switchmode = 1
  255.             elif self.switchmode == 1:
  256.                 self.switchmode = 0
  257.             time.sleep(0.1)
  258.         except Exception as e:
  259.             print("Error switching modes:", e)
  260.  
  261.  
  262. def print_banner(b0t: trb0t): #Printing the information
  263.     try:
  264.         os.system("cls") # First clearing the terminal, to then re-print with the new information. Note the colorama formatting with styling and colors!
  265.         print(
  266.             Style.BRIGHT
  267.             + Fore.CYAN
  268.             + """
  269.    _   ___  ___ ___ _  _   _   _       ___ ___  _    ___  ___ ___  ___ _____
  270.   /_\ | _ \/ __| __| \| | /_\ | |     / __/ _ \| |  / _ \| _ \ _ )/ _ \_   _|
  271.  / _ \|   /\__ \ _|| .` |/ _ \| |__  | (_| (_) | |_| (_) |   / _ \ (_) || |  
  272. /_/ \_\_|_\|___/___|_|\_/_/ \_\____|  \___\___/|____\___/|_|_\___/\___/ |_|                                                                                                                                                                                                                      
  273. """
  274.             + Style.RESET_ALL
  275.         )
  276.         print("====== Controls ======")
  277.         print("Activate colorbot    :", Fore.YELLOW + str(AIM_KEY) + Style.RESET_ALL)
  278.         if SWITCH_MODE_KEY != "disabled":
  279.             print("Switch toggle/hold   :", Fore.YELLOW + SWITCH_MODE_KEY + Style.RESET_ALL)
  280.         if UPDATE_KEY != "disabled":
  281.             print("Update Config        :", Fore.YELLOW + UPDATE_KEY + Style.RESET_ALL)
  282.         if FOV_KEY_UP != "disabled" and FOV_KEY_DOWN != "disabled":
  283.             print(
  284.                 "Change FOV           :",
  285.                 Fore.YELLOW + FOV_KEY_UP + "/" + FOV_KEY_DOWN + Style.RESET_ALL,
  286.             )
  287.         print("==== Information =====")
  288.         print(
  289.             "Toggle/Hold Mode     :",
  290.             Fore.CYAN + toggleholdmodes[b0t.switchmode] + Style.RESET_ALL,
  291.         )
  292.         print("Aim FOV              :", Fore.CYAN + str(AIM_FOV) + Style.RESET_ALL)
  293.         print("Cam FOV              :", Fore.CYAN + str(CAM_FOV) + Style.RESET_ALL)
  294.         if TRIGGERBOT != "disabled":
  295.             print("Triggerbot           :", Fore.GREEN + "On" + Style.RESET_ALL)
  296.         else:
  297.             print("Triggerbot           :", Fore.RED + "Off" + Style.RESET_ALL)
  298.         if TRIGGERBOT_DELAY != 0:
  299.             print("Triggerbot Delay     :", Fore.GREEN + str(TRIGGERBOT_DELAY) + Style.RESET_ALL)
  300.         if SMOOTHENING != "disabled":
  301.             print("Smoothening          :", Fore.GREEN + "On" + Style.RESET_ALL)
  302.             print("Smoothening Factor   :", Fore.CYAN + str(SMOOTH_FACTOR) + Style.RESET_ALL)
  303.         else:
  304.             print("Smoothening          :", Fore.RED + "Off" + Style.RESET_ALL)
  305.         if TRIGGERBOT_DELAY != 0:
  306.             print("Triggerbot Delay     :", Fore.GREEN + str(TRIGGERBOT_DELAY) + Style.RESET_ALL)
  307.         print(
  308.             "Aim Speed            :",
  309.             Fore.CYAN
  310.             + "X: "
  311.             + str(AIM_SPEED_X)
  312.             + " Y: "
  313.             + str(AIM_SPEED_Y)
  314.             + Style.RESET_ALL,
  315.         )
  316.         print(
  317.             "Aim Offset           :",
  318.             Fore.CYAN
  319.             + "X: "
  320.             + str(AIM_OFFSET_X)
  321.             + " Y: "
  322.             + str(AIM_OFFSET_Y)
  323.             + Style.RESET_ALL,
  324.         )
  325.         print(
  326.             "Aim Activated        :",
  327.             (Fore.GREEN if b0t.AIMtoggled else Fore.RED)
  328.             + str(b0t.AIMtoggled)
  329.             + Style.RESET_ALL,
  330.         )
  331.         print(
  332.             "Enemy Color          :",
  333.             str(colorname + COLOR) + Style.RESET_ALL
  334.                     )
  335.         print("======================")
  336.         print(
  337.             Style.BRIGHT
  338.             + Fore.CYAN
  339.             + "https://discord.gg/nDREsRUj9V for configs and help!"
  340.             + "\nIf you didn't download this from https://github.com/Seconb/Roblox-Colorbot, it's not legit!"
  341.             + Style.RESET_ALL
  342.         )
  343.     except Exception as e:
  344.         print("Error printing banner:", e)
  345.  
  346. if __name__ == "__main__":
  347.     b0t = trb0t()
  348.     try:
  349.         print_banner(b0t) #to update information or print initial info.
  350.         while True:
  351.             # under each if statement, we first check if the key is set to disabled (if it is disabled, then it will not function. this allows the user to disable keys they don't wish to use.
  352.             if SWITCH_MODE_KEY != "disabled" and keyboard.is_pressed(SWITCH_MODE_KEY):
  353.                 b0t.modeswitch() #switching the mode if the user presses the switch mode key AND its not disabled.
  354.                 print_banner(b0t) #updating the information
  355.             if FOV_KEY_UP != "disabled" and keyboard.is_pressed(FOV_KEY_UP):
  356.                 change_config_setting("AIM_FOV", AIM_FOV+5) #same thing as before, just adding 5 increments to the fov.
  357.                 print_banner(b0t)
  358.             if FOV_KEY_DOWN != "disabled" and keyboard.is_pressed(FOV_KEY_DOWN):
  359.                 change_config_setting("AIM_FOV", AIM_FOV-5) #same thing as before just removing 5 increments
  360.                 print_banner(b0t)
  361.             if UPDATE_KEY != "disabled" and keyboard.is_pressed(UPDATE_KEY):
  362.                 load() #updating the settings if the user presses the update key.
  363.                 print_banner(b0t)
  364.            
  365.  
  366.             time.sleep(0.1) #.1s cooldown as a way of preventing lag and mispresses
  367.  
  368.             if (
  369.                 BINDMODE.lower() == "win32"
  370.                 or BINDMODE.lower() == "win32api"
  371.                 or BINDMODE.lower() == "win" #make all strings lowercase just in case if someone in config typed it out as WIN32API, which the code wouldn't recognize.
  372.             ): # this is mostly for the mouse buttons.
  373.                 if lclc(): #if user is holding down on the key or a key.
  374.                     if b0t.switchmode == 0: #if mode is on [**0**, 1] (means if 0) which is hold.
  375.                         while lclc(): #while the user is holding the key.
  376.                             if not b0t.AIMtoggled:
  377.                                 b0t.AIMtoggle() #and if the aim isn't already activated, activate it.
  378.                                 print_banner(b0t) #update info
  379.                                 while b0t.AIMtoggled:
  380.                                     b0t.process() #while it is on/activated THEN process all screen capture, note that it doesn't process information unless activated.
  381.                                     if not lclc():
  382.                                         b0t.AIMtoggle() #if user stops holding the key, it'll turn off the colorbot.
  383.                                         print_banner(b0t) #update info.
  384.                     if b0t.switchmode == 1: #if mode is on [0, **1**] (means if toggled)
  385.                         b0t.AIMtoggle() # activate it forever until user presses again.
  386.                         print_banner(b0t)
  387.                         while b0t.AIMtoggled: #while it is toggled
  388.                             b0t.process() # process the images.
  389.                             if lclc():
  390.                                 b0t.AIMtoggle() # if user presses the button, then deactivate
  391.                                 print_banner(b0t) #update info
  392.             else:
  393.                 if keyboard.is_pressed(AIM_KEY): #else if the user uses keyboard config, then look for keyboard buttons instead.
  394.                     if b0t.switchmode == 0:
  395.                         while keyboard.is_pressed(AIM_KEY): # SAME EXACT PROCESS AS THE MOUSE KEY PRESSES ABOVE, REFER THERE.
  396.                             if not b0t.AIMtoggled:
  397.                                 b0t.AIMtoggle()
  398.                                 print_banner(b0t)
  399.                                 while b0t.AIMtoggled:
  400.                                     b0t.process()
  401.                                     if not keyboard.is_pressed(AIM_KEY):
  402.                                         b0t.AIMtoggle()
  403.                                         print_banner(b0t)
  404.                     if b0t.switchmode == 1:
  405.                         b0t.AIMtoggle() # SAME EXACT PROCESS AS THE MOUSE KEY PRESSES ABOVE, REFER THERE.
  406.                         print_banner(b0t)
  407.                         while b0t.AIMtoggled:
  408.                             b0t.process()
  409.                             if keyboard.is_pressed(AIM_KEY):
  410.                                 b0t.AIMtoggle()
  411.                                 print_banner(b0t)
  412.     except Exception as e:
  413.         print("An error occurred:", e) #the end, DM befia on discord if you need clarity. Info by, duh, befia or taylor.
  414.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement