import cv2
from PIL import ImageGrab
import numpy as np
import keyboard
import time
import winsound
import os
import mss
from colorama import Fore, Style, init
import threading
import timeit
import json
CONFIG_FILE = "config.json"
def load_config():
if os.path.exists(CONFIG_FILE):
with open(CONFIG_FILE, "r") as config_file:
config = json.load(config_file)
return config
else:
return None
def save_config(config):
with open(CONFIG_FILE, "w") as config_file:
json.dump(config, config_file, indent=2)
def display_ascii_art():
init()
art = Fore.CYAN + r"""ascii"""
print(art)
time.sleep(3)
os.system("cls") # コンソールをクリア
アスキーアートの表示
display_ascii_art()
設定が必要な場合は設定
config = load_config()
if config is None:
print("初期設定が必要です")
trigger_key = input("ホットキーを入力して下さい 例|tab, c, alt + c など: ")
valid_colors = {"1": "purple", "2": "red", "3": "yellow"}
color_choice = ""
while color_choice not in valid_colors:
print("カラーを選んで下さい:")
print("1. Purple")
print("2. Red")
print("3. Yellow")
color_choice = input("ハイライトカラーを記号で入力して下さい: ")
color = valid_colors[color_choice]
config = {
"trigger_key": trigger_key,
"color": color
}
save_config(config)
ボットプログラムの開始
TRIGGER_KEY = config["trigger_key"]
COLOR_NAME = config["color"]
if COLOR_NAME == "purple":
COLOR = np.array([250, 100, 250])
elif COLOR_NAME == "red":
COLOR = np.array([255, 0, 0])
elif COLOR_NAME == "yellow":
COLOR = np.array([252, 252, 84])
S_HEIGHT, S_WIDTH = (mss.mss().monitors[0]["width"], mss.mss().monitors[0]["height"])
TOLERANCE = 32
GRABZONE = 10
SWITCH_KEY = "ctrl + tab"
GRABZONE_KEY_UP = "ctrl + up"
GRABZONE_KEY_DOWN = "ctrl + down"
MODE_KEYS = ["f1", "f2", "f3", "f4", "f5"]
MODES = ["SHERIFF", "SPECTRE", "GUARDIAN/SHOTGUN", "VANDAL/PHANTOM", "MARSHAL/OPERATOR SCOPE"]
DELAY_TIMES = [0.00, 0, 0, 0, 0.1]
SHOOTING_TIMES = [0.7, 0, 0, 0.13, 0]
class FoundEnemy(Exception):
pass
class MellyBOT:
def init(self):
self.toggled = False
self.mode = 0
self.last_reac = 0
self.scan_count_interval = 10000
self.current_scan_count = 0
self.bot_thread = threading.Thread(target=self.bot_thread)
self.bot_thread.daemon = True
self.bot_thread.start()
def toggle(self):
self.toggled = not self.toggled
def switch(self):
self.mode = (self.mode + 1) % len(MODES)
def click(self):
if self.mode < len(DELAY_TIMES) and not np.any([keyboard.is_pressed(key) for key in ['w', 'a', 's', 'd']]):
keyboard.press_and_release('i')
time.sleep(SHOOTING_TIMES[self.mode])
elif self.mode >= len(DELAY_TIMES):
while not keyboard.is_pressed('ctrl'):
time.sleep(0.1)
def approx(self, rgb):
return np.all((COLOR - TOLERANCE) < rgb) and np.all(rgb < (COLOR + TOLERANCE))
def grab(self):
screenshot = ImageGrab.grab(bbox=(int(S_HEIGHT / 2 - GRABZONE), int(S_WIDTH / 2 - GRABZONE),
int(S_HEIGHT / 2 + GRABZONE), int(S_WIDTH / 2 + GRABZONE)))
return np.array(screenshot)
def scan(self):
self.current_scan_count += 1
start_time = timeit.default_timer()
screenshot_array = self.grab()
lower_bound, upper_bound = COLOR - TOLERANCE, COLOR + TOLERANCE
approx_mask = cv2.inRange(screenshot_array, lower_bound, upper_bound)
if np.any(approx_mask):
self.last_reac = int((timeit.default_timer() - start_time) * 1000)
self.click()
elapsed_time = timeit.default_timer() - start_time
if elapsed_time < 0.000001 / self.scan_count_interval:
time.sleep(0.000001 / self.scan_count_interval - elapsed_time)
def change_scan_count_interval(self, interval):
self.scan_count_interval = interval
def bot_thread(self):
while True:
if self.toggled:
self.scan()
time.sleep(0.001 / self.scan_count_interval)
def print_banner(bot):
os.system("cls")
active_status = Fore.GREEN + "ON" + Style.RESET_ALL if bot.toggled else Fore.RED + "OFF" + Style.RESET_ALL
print(Style.BRIGHT + Fore.RED + "MellyBOT v1.0" + Style.RESET_ALL)
print("===== Controls =====")
print(f"ステータス : {active_status} | ホットキー: {Fore.YELLOW}{TRIGGER_KEY}{Style.RESET_ALL}")
print("銃の変更 f(1 - 5)", Fore.YELLOW + Style.RESET_ALL)
print("認識範囲の変更 :", Fore.YELLOW + f"{GRABZONE_KEY_UP}/{GRABZONE_KEY_DOWN}" + Style.RESET_ALL)
print("====================")
print("現在の銃 :", Fore.CYAN + f"{MODES[bot.mode]}" + Style.RESET_ALL)
# 色の表記を変更
print("ハイライトカラー :", end=" ")
if COLOR_NAME == "purple":
print(Fore.MAGENTA + f"{COLOR_NAME.capitalize()}" + Style.RESET_ALL)
elif COLOR_NAME == "red":
print(Fore.RED + f"{COLOR_NAME.capitalize()}" + Style.RESET_ALL)
elif COLOR_NAME == "yellow":
print(Fore.YELLOW + f"{COLOR_NAME.capitalize()}" + Style.RESET_ALL)
if GRABZONE > 0:
range_info = f"{GRABZONE}x{GRABZONE}"
print("認識範囲 :", Fore.CYAN + f"{range_info}" + Style.RESET_ALL)
else:
print("認識範囲 :", Fore.CYAN + "これ以上値は下がりません" + Style.RESET_ALL)
ボットインスタンスの生成
bot = MellyBOT()
while True:
if keyboard.is_pressed(SWITCH_KEY):
bot.switch()
winsound.Beep(200, 200)
print_banner(bot)
while keyboard.is_pressed(SWITCH_KEY):
pass
elif keyboard.is_pressed(GRABZONE_KEY_UP):
GRABZONE += 1
print_banner(bot)
winsound.Beep(400, 200)
while keyboard.is_pressed(GRABZONE_KEY_UP):
pass
elif keyboard.is_pressed(GRABZONE_KEY_DOWN):
GRABZONE -= 1
print_banner(bot)
winsound.Beep(300, 200)
while keyboard.is_pressed(GRABZONE_KEY_DOWN):
pass
elif keyboard.is_pressed(TRIGGER_KEY):
bot.toggle()
print_banner(bot)
if bot.toggled:
winsound.Beep(440, 75)
winsound.Beep(700, 100)
else:
winsound.Beep(440, 75)
winsound.Beep(200, 100)
while keyboard.is_pressed(TRIGGER_KEY):
pass
else:
for key_combination, new_mode in zip(MODE_KEYS, range(len(MODES))):
if keyboard.is_pressed(key_combination):
bot.mode = new_mode
winsound.Beep(200, 200)
print_banner(bot)
while keyboard.is_pressed(key_combination):
pass
time.sleep(0.01) # 待機時間を短縮
このコードを高速化してください