diff --git a/fishy/__main__.py b/fishy/__main__.py index ac219c7..ed8191b 100644 --- a/fishy/__main__.py +++ b/fishy/__main__.py @@ -10,7 +10,8 @@ import fishy from fishy import web, helper, gui from fishy.engine.common.event_handler import EngineEventHandler from fishy.gui import GUI, splash -from fishy.helper import Config, hotkey +from fishy.helper import hotkey +from fishy.helper.config import config def check_window_name(title): @@ -22,11 +23,11 @@ def check_window_name(title): # noinspection PyBroadException -def initialize(c: Config, window_to_hide): - helper.create_shortcut_first(c) - helper.initialize_uid(c) +def initialize(window_to_hide): + helper.create_shortcut_first() + helper.initialize_uid() - new_session = web.get_session(c) + new_session = web.get_session() if new_session is None: logging.error("Couldn't create a session, some features might not work") print(f"created session {new_session}") @@ -44,14 +45,14 @@ def initialize(c: Config, window_to_hide): except Exception: logging.error(traceback.format_exc()) - if not c.get("debug", False) and check_window_name(win32gui.GetWindowText(window_to_hide)): + if not config.get("debug", False) and check_window_name(win32gui.GetWindowText(window_to_hide)): win32gui.ShowWindow(window_to_hide, win32con.SW_HIDE) helper.install_thread_excepthook() sys.excepthook = helper.unhandled_exception_logging helper.check_addon("ProvisionsChalutier") - if c.get("debug", False): + if config.get("debug", False): helper.check_addon("FooAddon") @@ -63,20 +64,19 @@ def main(): pil_logger.setLevel(logging.INFO) window_to_hide = win32gui.GetForegroundWindow() - c = Config() - if not gui.check_eula(c): + if not gui.check_eula(): return - bot = EngineEventHandler(c, lambda: gui_window) - gui_window = GUI(c, lambda: bot) + bot = EngineEventHandler(lambda: gui_window) + gui_window = GUI(lambda: bot) hotkey.initalize() gui_window.start() logging.info(f"Fishybot v{fishy.__version__}") - initialize(c, window_to_hide) + initialize(window_to_hide) bot.start_event_handler() diff --git a/fishy/engine/common/IEngine.py b/fishy/engine/common/IEngine.py index 1987623..6fe5043 100644 --- a/fishy/engine/common/IEngine.py +++ b/fishy/engine/common/IEngine.py @@ -3,7 +3,7 @@ from abc import ABC, abstractmethod from threading import Thread from typing import Callable -from fishy.gui.funcs import GUIFuncs, GUIFuncsMock +from fishy.gui.funcs import GUIFuncsMock if typing.TYPE_CHECKING: from fishy.gui import GUI @@ -11,12 +11,11 @@ if typing.TYPE_CHECKING: class IEngine(ABC): - def __init__(self, config, gui_ref: 'Callable[[], GUI]'): + def __init__(self, gui_ref: 'Callable[[], GUI]'): self.get_gui = gui_ref self.start = False self.window = None self.thread = None - self.config = config @property def gui(self): diff --git a/fishy/engine/common/event_handler.py b/fishy/engine/common/event_handler.py index 7c7f0f5..e7a0d7f 100644 --- a/fishy/engine/common/event_handler.py +++ b/fishy/engine/common/event_handler.py @@ -4,12 +4,12 @@ from fishy.engine.fullautofisher.engine import FullAuto class EngineEventHandler: - def __init__(self, config, gui_ref): + def __init__(self, gui_ref): self.event_handler_running = True self.event = [] - self.semi_fisher_engine = SemiFisherEngine(config, gui_ref) - self.full_fisher_engine = FullAuto(config, gui_ref) + self.semi_fisher_engine = SemiFisherEngine(gui_ref) + self.full_fisher_engine = FullAuto(gui_ref) def start_event_handler(self): while self.event_handler_running: diff --git a/fishy/engine/common/window.py b/fishy/engine/common/window.py index 64e3bab..9004ef8 100644 --- a/fishy/engine/common/window.py +++ b/fishy/engine/common/window.py @@ -1,5 +1,4 @@ import logging -from enum import Enum from typing import List import cv2 @@ -82,7 +81,6 @@ class WindowClient: """ Displays the processed image for debugging purposes :param ready_img: send ready image, just show the `ready_img` directly - :param name: unique name for the image, used to create a new window :param resize: scale the image to make small images more visible :param func: function to process the image """ diff --git a/fishy/engine/common/window_server.py b/fishy/engine/common/window_server.py index 1c675dc..f38eb4c 100644 --- a/fishy/engine/common/window_server.py +++ b/fishy/engine/common/window_server.py @@ -12,6 +12,7 @@ from win32api import GetSystemMetrics import numpy as np from PIL import ImageGrab +from fishy.helper.config import config class Status(Enum): @@ -31,7 +32,7 @@ class WindowServer: status = Status.STOPPED -def init(borderless: bool): +def init(): """ Executed once before the main loop, Finds the game window, and calculates the offset to remove the title bar @@ -42,7 +43,7 @@ def init(borderless: bool): client_rect = win32gui.GetClientRect(WindowServer.hwnd) WindowServer.windowOffset = math.floor(((rect[2] - rect[0]) - client_rect[2]) / 2) WindowServer.titleOffset = ((rect[3] - rect[1]) - client_rect[3]) - WindowServer.windowOffset - if borderless: + if config.get("borderless"): WindowServer.titleOffset = 0 WindowServer.status = Status.RUNNING except pywintypes.error: @@ -93,7 +94,7 @@ def start(): if WindowServer.status == Status.RUNNING: return - init(False) + init() if WindowServer.status == Status.RUNNING: Thread(target=run).start() diff --git a/fishy/engine/fullautofisher/calibrate.py b/fishy/engine/fullautofisher/calibrate.py index 879cbe6..ab05fac 100644 --- a/fishy/engine/fullautofisher/calibrate.py +++ b/fishy/engine/fullautofisher/calibrate.py @@ -1,12 +1,12 @@ import math import logging import time -from threading import Thread from fishy.engine.fullautofisher.engine import FullAuto from pynput import keyboard, mouse from fishy.helper import hotkey +from fishy.helper.config import config from fishy.helper.helper import wait_until from fishy.helper.hotkey import Key @@ -85,7 +85,7 @@ class Calibrate(): time_to_reach_bottom = time.time() - y_cal_start_time self.engine.factors = move_factor, rot_factor, time_to_reach_bottom - self.engine.config.set("full_auto_factors", self.engine.factors) + config.set("full_auto_factors", self.engine.factors) logging.info(self.engine.factors) hotkey.free_key(Key.F8) diff --git a/fishy/engine/fullautofisher/engine.py b/fishy/engine/fullautofisher/engine.py index 3babba9..3ce3218 100644 --- a/fishy/engine/fullautofisher/engine.py +++ b/fishy/engine/fullautofisher/engine.py @@ -5,17 +5,17 @@ import logging import time import numpy as np -import pywintypes import pytesseract from fishy.engine import SemiFisherEngine from fishy.engine.common.window import WindowClient -from fishy.engine.semifisher import fishing_event, fishing_mode +from fishy.engine.semifisher import fishing_mode from fishy.engine.common.IEngine import IEngine from pynput import keyboard, mouse -from fishy.helper import Config, hotkey +from fishy.helper import hotkey +from fishy.helper.config import config from fishy.helper.hotkey import Key mse = mouse.Controller() @@ -78,9 +78,9 @@ def unassign_keys(): class FullAuto(IEngine): rotate_by = 30 - def __init__(self, config, gui_ref): - super().__init__(config, gui_ref) - self.factors = self.config.get("full_auto_factors", None) + def __init__(self, gui_ref): + super().__init__(gui_ref) + self.factors = config.get("full_auto_factors", None) self._tesseract_dir = None self._target = None @@ -96,7 +96,7 @@ class FullAuto(IEngine): self.window = WindowClient(color=cv2.COLOR_RGB2GRAY, show_name="Full auto debug") self.window.crop = get_crop_coods(self.window) - self._tesseract_dir = self.config.get("tesseract_dir", None) + self._tesseract_dir = config.get("tesseract_dir", None) if self._tesseract_dir is None: logging.warning("Can't start without Tesseract Directory") @@ -189,7 +189,7 @@ class FullAuto(IEngine): def set_target(self): t = self.get_coods()[:-1] - self.config.set("target", t) + config.set("target", t) print(f"target_coods are {t}") def initalize_keys(self): @@ -213,9 +213,8 @@ class FullAuto(IEngine): if __name__ == '__main__': logging.getLogger("").setLevel(logging.DEBUG) # noinspection PyTypeChecker - c = Config() - bot = FullAuto(c, None) - fisher = SemiFisherEngine(c, None) + bot = FullAuto(None) + fisher = SemiFisherEngine(None) hotkey.initalize() fisher.toggle_start() bot.toggle_start() diff --git a/fishy/engine/fullautofisher/player.py b/fishy/engine/fullautofisher/player.py index dd6d649..e4b7307 100644 --- a/fishy/engine/fullautofisher/player.py +++ b/fishy/engine/fullautofisher/player.py @@ -1,9 +1,6 @@ -import json import logging import pickle -import time -from threading import Thread -from tkinter.filedialog import asksaveasfile, askopenfile +from tkinter.filedialog import askopenfile from fishy.engine.fullautofisher.engine import FullAuto diff --git a/fishy/engine/fullautofisher/recorder.py b/fishy/engine/fullautofisher/recorder.py index 2cf0c8c..7011860 100644 --- a/fishy/engine/fullautofisher/recorder.py +++ b/fishy/engine/fullautofisher/recorder.py @@ -1,8 +1,6 @@ -import json import logging import pickle import time -from threading import Thread from tkinter.filedialog import asksaveasfile from fishy.engine.fullautofisher.engine import FullAuto diff --git a/fishy/engine/semifisher/engine.py b/fishy/engine/semifisher/engine.py index 2426bd2..1f82ab9 100644 --- a/fishy/engine/semifisher/engine.py +++ b/fishy/engine/semifisher/engine.py @@ -20,8 +20,8 @@ if typing.TYPE_CHECKING: class SemiFisherEngine(IEngine): - def __init__(self, config, gui_ref: 'Callable[[], GUI]'): - super().__init__(config, gui_ref) + def __init__(self, gui_ref: 'Callable[[], GUI]'): + super().__init__(gui_ref) self.fishPixWindow = None def run(self): @@ -76,6 +76,6 @@ class SemiFisherEngine(IEngine): if __name__ == '__main__': logging.getLogger("").setLevel(logging.DEBUG) # noinspection PyTypeChecker - fisher = SemiFisherEngine(None, None) + fisher = SemiFisherEngine(None) fisher.toggle_start() diff --git a/fishy/engine/semifisher/fishing_event.py b/fishy/engine/semifisher/fishing_event.py index ea01cd8..30aac2b 100644 --- a/fishy/engine/semifisher/fishing_event.py +++ b/fishy/engine/semifisher/fishing_event.py @@ -14,6 +14,8 @@ from fishy.engine.semifisher.fishing_mode import State from fishy.helper import helper import keyboard +from fishy.helper.config import config + class FishEvent: fishCaught = 0 @@ -34,6 +36,9 @@ class FishEvent: def init(): # todo load config fishing_mode.subscribers.append(fisher_callback) + FishEvent.action_key = config.get("action_key", 'e') + FishEvent.uid = config.get("uid") + FishEvent.sound = config.get("sound_notification", False) def destroy(): diff --git a/fishy/gui/config_top.py b/fishy/gui/config_top.py index fe19042..e2eb3d4 100644 --- a/fishy/gui/config_top.py +++ b/fishy/gui/config_top.py @@ -6,6 +6,7 @@ from fishy.gui.notification import _give_notification_link from tkinter import * from tkinter.ttk import * +from fishy.helper.config import config from fishy.helper.popup import PopUp if typing.TYPE_CHECKING: @@ -14,8 +15,8 @@ if typing.TYPE_CHECKING: def start_fullfisher_config(gui: 'GUI'): def save(): - gui._config.set("tesseract_dir", tesseract_entry.get(), False) - gui._config.save_config() + gui.config.set("tesseract_dir", tesseract_entry.get(), False) + gui.config.save_config() top = PopUp(save, gui._root, background=gui._root["background"]) controls_frame = Frame(top) @@ -23,7 +24,7 @@ def start_fullfisher_config(gui: 'GUI'): Label(controls_frame, text="Tesseract Directory:").grid(row=0, column=0) tesseract_entry = Entry(controls_frame, justify=CENTER) - tesseract_entry.insert(0, gui._config.get("tesseract_dir", "")) + tesseract_entry.insert(0, config.get("tesseract_dir", "")) tesseract_entry.grid(row=0, column=1) controls_frame.pack(padx=(5, 5), pady=(5, 5)) @@ -32,10 +33,10 @@ def start_fullfisher_config(gui: 'GUI'): def start_semifisher_config(gui: 'GUI'): def save(): - gui._config.set("action_key", action_key_entry.get(), False) - gui._config.set("borderless", borderless.instate(['selected']), False) - gui._config.set("sound_notification", sound.instate(['selected']), False) - gui._config.save_config() + gui.config.set("action_key", action_key_entry.get(), False) + gui.config.set("borderless", borderless.instate(['selected']), False) + gui.config.set("sound_notification", sound.instate(['selected']), False) + gui.config.save_config() top = PopUp(save, gui._root, background=gui._root["background"]) controls_frame = Frame(top) @@ -48,22 +49,22 @@ def start_semifisher_config(gui: 'GUI'): variable=gui._notify) gui._notify_check.grid(row=0, column=1) gui._notify_check['state'] = DISABLED - is_subbed = web.is_subbed(gui._config.get('uid')) + is_subbed = web.is_subbed(config.get('uid')) if is_subbed[1]: gui._notify_check['state'] = NORMAL gui._notify.set(is_subbed[0]) Label(controls_frame, text="Fullscreen: ").grid(row=1, column=0, pady=(5, 5)) - borderless = Checkbutton(controls_frame, var=BooleanVar(value=gui._config.get("borderless"))) + borderless = Checkbutton(controls_frame, var=BooleanVar(value=config.get("borderless"))) borderless.grid(row=1, column=1) Label(controls_frame, text="Action Key:").grid(row=2, column=0) action_key_entry = Entry(controls_frame, justify=CENTER) action_key_entry.grid(row=2, column=1) - action_key_entry.insert(0, gui._config.get("action_key", "e")) + action_key_entry.insert(0, config.get("action_key", "e")) Label(controls_frame, text="Sound Notification: ").grid(row=3, column=0, pady=(5, 5)) - sound = Checkbutton(controls_frame, var=BooleanVar(value=gui._config.get("sound_notification"))) + sound = Checkbutton(controls_frame, var=BooleanVar(value=config.get("sound_notification"))) sound.grid(row=3, column=1) controls_frame.pack(padx=(5, 5), pady=(5, 5)) diff --git a/fishy/gui/funcs.py b/fishy/gui/funcs.py index 729af60..40ef022 100644 --- a/fishy/gui/funcs.py +++ b/fishy/gui/funcs.py @@ -1,6 +1,9 @@ from tkinter import messagebox import typing + +from fishy.helper.config import config + if typing.TYPE_CHECKING: from fishy.gui import GUI @@ -47,6 +50,6 @@ class GUIFuncs: def start_engine(self): def start_engine(): - self.gui._config.set("last_started", self.gui._engine_var.get()) + config.set("last_started", self.gui._engine_var.get()) self.gui.engines[self.gui._engine_var.get()][1]() self.gui.call_in_thread(start_engine) diff --git a/fishy/gui/gui.py b/fishy/gui/gui.py index 445fbcc..43fb696 100644 --- a/fishy/gui/gui.py +++ b/fishy/gui/gui.py @@ -1,6 +1,6 @@ import logging from tkinter import OptionMenu, Button -from typing import List, Callable +from typing import List, Callable, Optional import threading from ttkthemes import ThemedTk @@ -10,18 +10,15 @@ from fishy.gui import config_top from fishy.gui.funcs import GUIFuncs from . import main_gui from .log_config import GUIStreamHandler -from fishy.helper import Config +from ..helper.config import config class GUI: - def __init__(self, config: Config, get_engine: Callable[[], EngineEventHandler]): - """ - :param config: used to get and set configuration settings - """ + def __init__(self, get_engine: Callable[[], EngineEventHandler]): self.funcs = GUIFuncs(self) self.get_engine = get_engine - self._config = config + self.config = config self._start_restart = False self._destroyed = True self._log_strings = [] @@ -29,13 +26,13 @@ class GUI: self._bot_running = False # UI items - self._root: ThemedTk + self._root: Optional[ThemedTk] = None self._console = None self._start_button = None self._notify = None self._notify_check = None - self._engine_select: OptionMenu - self._config_button: Button + self._engine_select: Optional[OptionMenu] = None + self._config_button: Optional[Button] = None self._engine_var = None self._thread = threading.Thread(target=self.create, args=()) @@ -56,7 +53,7 @@ class GUI: "Semi Fisher": [lambda: config_top.start_semifisher_config(self), self.engine.toggle_semifisher], } - if self._config.get('debug', False): + if config.get('debug', False): engines["Full-Auto Fisher"] = [lambda: config_top.start_fullfisher_config(self), self.engine.toggle_fullfisher] return engines diff --git a/fishy/gui/main_gui.py b/fishy/gui/main_gui.py index 14d5be5..efd1222 100644 --- a/fishy/gui/main_gui.py +++ b/fishy/gui/main_gui.py @@ -10,6 +10,7 @@ from fishy import helper import typing from fishy.helper import hotkey +from ..helper.config import config from ..helper.hotkey import Key if typing.TYPE_CHECKING: @@ -17,7 +18,7 @@ if typing.TYPE_CHECKING: def _apply_theme(gui: 'GUI'): - dark = gui._config.get("dark_mode", True) + dark = config.get("dark_mode", True) gui._root["theme"] = "equilux" if dark else "breeze" gui._console["background"] = "#707070" if dark else "#ffffff" gui._console["fg"] = "#ffffff" if dark else "#000000" @@ -39,11 +40,11 @@ def _create(gui: 'GUI'): filemenu.add_command(label="Create Anti-Ghost Shortcut", command=lambda: helper.create_shortcut(True)) def _toggle_mode(): - gui._config.set("dark_mode", not gui._config.get("dark_mode", True)) + config.set("dark_mode", not config.get("dark_mode", True)) gui._start_restart = True dark_mode_var = IntVar() - dark_mode_var.set(int(gui._config.get('dark_mode', True))) + dark_mode_var.set(int(config.get('dark_mode', True))) filemenu.add_checkbutton(label="Dark Mode", command=_toggle_mode, variable=dark_mode_var) @@ -54,10 +55,10 @@ def _create(gui: 'GUI'): command=lambda: gui.engine.check_pixel_val()) debug_var = IntVar() - debug_var.set(int(gui._config.get('debug', False))) + debug_var.set(int(config.get('debug', False))) def keep_console(): - gui._config.set("debug", bool(debug_var.get())) + config.set("debug", bool(debug_var.get())) logging.debug("Restart to update the changes") debug_menu.add_checkbutton(label="Keep Console", command=keep_console, variable=debug_var) @@ -84,7 +85,7 @@ def _create(gui: 'GUI'): gui._engine_var = StringVar(start_frame) labels = list(engines.keys()) - last_started = gui._config.get("last_started", labels[0]) + last_started = config.get("last_started", labels[0]) gui._engine_select = OptionMenu(start_frame, gui._engine_var, last_started, *labels) gui._engine_select.pack(side=LEFT) diff --git a/fishy/gui/notification.py b/fishy/gui/notification.py index aff6d09..21b270f 100644 --- a/fishy/gui/notification.py +++ b/fishy/gui/notification.py @@ -7,6 +7,7 @@ from fishy import web import typing from fishy.libs.tkhtmlview import HTMLLabel +from ..helper.config import config if typing.TYPE_CHECKING: from . import GUI @@ -14,8 +15,8 @@ if typing.TYPE_CHECKING: # noinspection PyProtectedMember def _give_notification_link(gui: 'GUI'): - if web.is_subbed(gui._config.get("uid"))[0]: - web.unsub(gui._config.get("uid")) + if web.is_subbed(config.get("uid"))[0]: + web.unsub(config.get("uid")) return # set notification checkbutton @@ -26,8 +27,8 @@ def _give_notification_link(gui: 'GUI'): top_running[0] = False def check(): - if web.sub(gui._config.get("uid"), discord_name.get()): - if web.is_subbed(gui._config.get("uid"), False)[0]: + if web.sub(config.get("uid"), discord_name.get()): + if web.is_subbed(config.get("uid"), False)[0]: gui._notify.set(1) messagebox.showinfo("Note!", "Notification configured successfully!") quit_top() diff --git a/fishy/gui/terms_gui.py b/fishy/gui/terms_gui.py index e3f84fa..1f36a1d 100644 --- a/fishy/gui/terms_gui.py +++ b/fishy/gui/terms_gui.py @@ -5,20 +5,20 @@ from tkinter.ttk import * from PIL import Image, ImageTk from fishy import helper, web -from fishy.helper import Config +from fishy.helper.config import config -hyperlinkPattern = re.compile(r'\[(?P