mirror of
https://github.com/fishyboteso/fishyboteso.git
synced 2024-08-30 18:32:13 +00:00
added a null check in get_coords
changed print_exec to print in both console and fishy fixed engine couldn't be stoped with toggle fixed full auto stop getting called multiple times due to inactive stop set logging for d3dshot to info, to remove debug logs caused by it
This commit is contained in:
parent
9bcde7e922
commit
4ea27ae7da
@ -2,19 +2,18 @@ import ctypes
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
import win32con
|
||||
import win32gui
|
||||
|
||||
import fishy
|
||||
from fishy import gui, helper, web
|
||||
from fishy.constants import chalutier, lam2, fishyqr, libgps
|
||||
from fishy.engine.common.event_handler import EngineEventHandler
|
||||
from fishy.gui import GUI, splash, update_dialog
|
||||
from fishy.helper import hotkey
|
||||
from fishy.helper.active_poll import active
|
||||
from fishy.helper.config import config
|
||||
from fishy.helper.helper import print_exc
|
||||
from fishy.helper.hotkey.hotkey_process import hotkey
|
||||
from fishy.helper.migration import Migration
|
||||
|
||||
@ -58,7 +57,7 @@ def initialize(window_to_hide):
|
||||
if update_now:
|
||||
helper.auto_upgrade()
|
||||
except Exception:
|
||||
logging.error(traceback.format_exc())
|
||||
print_exc()
|
||||
|
||||
if not config.get("debug", False) and check_window_name(win32gui.GetWindowText(window_to_hide)):
|
||||
win32gui.ShowWindow(window_to_hide, win32con.SW_HIDE)
|
||||
@ -76,10 +75,10 @@ def main():
|
||||
|
||||
print("launching please wait...")
|
||||
|
||||
pil_logger = logging.getLogger('PIL')
|
||||
pil_logger.setLevel(logging.INFO)
|
||||
|
||||
# todo set log level info for d3dshot too
|
||||
info_logger = ["comtypes", "PIL"]
|
||||
for i in info_logger:
|
||||
pil_logger = logging.getLogger(i)
|
||||
pil_logger.setLevel(logging.INFO)
|
||||
|
||||
window_to_hide = win32gui.GetForegroundWindow()
|
||||
|
||||
|
@ -10,6 +10,7 @@ from playsound import playsound
|
||||
from fishy.engine.common.window import WindowClient
|
||||
from fishy.gui.funcs import GUIFuncsMock
|
||||
from fishy.helper import helper
|
||||
from fishy.helper.helper import print_exc
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from fishy.gui import GUI
|
||||
@ -39,7 +40,7 @@ class IEngine:
|
||||
if self.state == 0:
|
||||
self.turn_on()
|
||||
else:
|
||||
self.turn_on()
|
||||
self.turn_off()
|
||||
|
||||
def turn_on(self):
|
||||
self.state = 1
|
||||
@ -65,7 +66,7 @@ class IEngine:
|
||||
try:
|
||||
self.run()
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
print_exc()
|
||||
self.state = 0
|
||||
self.gui.bot_started(False)
|
||||
self.window.destroy()
|
||||
|
@ -38,7 +38,7 @@ def get_qr_location(og_img):
|
||||
cv2.drawContours(mask, cnt, i, 255, -1)
|
||||
x, y, w, h = cv2.boundingRect(cnt[i])
|
||||
qr_result = decode(og_img[y:h + y, x:w + x],
|
||||
symbols=[ZBarSymbol.QRCODE])
|
||||
symbols=[ZBarSymbol.QRCODE])
|
||||
if qr_result:
|
||||
valid_crops.append(((x, y, x + w, y + h), area))
|
||||
|
||||
|
@ -12,6 +12,7 @@ import win32gui
|
||||
from ctypes import windll
|
||||
|
||||
from fishy.helper.config import config
|
||||
from fishy.helper.helper import print_exc
|
||||
|
||||
|
||||
class Status(Enum):
|
||||
@ -92,7 +93,7 @@ def run():
|
||||
try:
|
||||
loop()
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
print_exc()
|
||||
WindowServer.status = Status.CRASHED
|
||||
|
||||
if WindowServer.status == Status.CRASHED:
|
||||
|
@ -20,7 +20,7 @@ from fishy.engine.semifisher import fishing_event, fishing_mode
|
||||
from fishy.engine.semifisher.fishing_mode import FishingMode
|
||||
from fishy.helper import hotkey
|
||||
from fishy.helper.config import config
|
||||
from fishy.helper.helper import wait_until, is_eso_active, sign
|
||||
from fishy.helper.helper import wait_until, is_eso_active, sign, print_exc
|
||||
|
||||
mse = mouse.Controller()
|
||||
kb = keyboard.Controller()
|
||||
@ -73,7 +73,7 @@ class FullAuto(IEngine):
|
||||
self.mode.run()
|
||||
except Exception:
|
||||
logging.error("exception occurred while running full auto mode")
|
||||
traceback.print_exc()
|
||||
print_exc()
|
||||
|
||||
def _pre_run_checks(self):
|
||||
if self.window.get_capture() is None:
|
||||
@ -99,10 +99,11 @@ class FullAuto(IEngine):
|
||||
|
||||
def stop_on_inactive(self):
|
||||
def func():
|
||||
logging.info("stop on inactive started")
|
||||
wait_until(lambda: not is_eso_active() or self.start != 1)
|
||||
self.turn_off()
|
||||
logging.info("stop on inactive stopped")
|
||||
logging.debug("stop on inactive started")
|
||||
wait_until(lambda: not is_eso_active() or not self.start)
|
||||
if self.start and not is_eso_active():
|
||||
self.turn_off()
|
||||
logging.debug("stop on inactive stopped")
|
||||
Thread(target=func).start()
|
||||
|
||||
def get_coords(self):
|
||||
@ -113,7 +114,8 @@ class FullAuto(IEngine):
|
||||
todo its waiting for qr which doesn't block the engine when commanded to close
|
||||
"""
|
||||
img = self.window.processed_image(func=image_pre_process)
|
||||
return get_values_from_image(img)[:3]
|
||||
values = get_values_from_image(img)
|
||||
return values[:3] if values else None
|
||||
|
||||
def move_to(self, target) -> bool:
|
||||
current = self.get_coords()
|
||||
|
@ -20,7 +20,7 @@ kb = keyboard.Controller()
|
||||
offset = 0
|
||||
|
||||
|
||||
def get_crop_coods(window):
|
||||
def get_crop_coords(window):
|
||||
img = window.get_capture()
|
||||
img = cv2.inRange(img, 0, 1)
|
||||
|
||||
@ -37,6 +37,8 @@ def get_crop_coods(window):
|
||||
x, y, w, h = cv2.boundingRect(cnt[i])
|
||||
return x, y + offset, x + w, y + h - offset
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def _update_factor(key, value):
|
||||
full_auto_factors = config.get("full_auto_factors", {})
|
||||
|
@ -75,6 +75,7 @@ class Player(IMode):
|
||||
|
||||
self.i = find_nearest(self.timeline, coords)[0]
|
||||
logging.info("starting player")
|
||||
return True
|
||||
|
||||
def _loop(self):
|
||||
action = self.timeline[self.i]
|
||||
|
@ -9,7 +9,7 @@ class Test:
|
||||
self.target = None
|
||||
|
||||
# noinspection PyProtectedMember
|
||||
def print_coods(self):
|
||||
def print_coords(self):
|
||||
logging.info(self.engine.get_coords())
|
||||
|
||||
def set_target(self):
|
||||
|
@ -12,6 +12,7 @@ from fishy.engine.common.qr_detection import get_qr_location, get_values_from_im
|
||||
from fishy.engine.common.window import WindowClient
|
||||
from fishy.engine.semifisher import fishing_event, fishing_mode
|
||||
from fishy.engine.semifisher.fishing_event import FishEvent
|
||||
from fishy.helper.helper import print_exc
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from fishy.gui import GUI
|
||||
@ -31,7 +32,12 @@ class SemiFisherEngine(IEngine):
|
||||
logging.info("Starting the bot engine, look at the fishing hole to start fishing")
|
||||
Thread(target=self._wait_and_check).start()
|
||||
|
||||
self.window.crop = get_qr_location(self.window.get_capture())
|
||||
capture = self.window.get_capture()
|
||||
if capture is None:
|
||||
logging.error("couldn't get game capture")
|
||||
return
|
||||
|
||||
self.window.crop = get_qr_location(capture)
|
||||
if not self.window.crop:
|
||||
logging.error("FishyQR not found, try to drag it around and try again")
|
||||
return
|
||||
@ -42,7 +48,7 @@ class SemiFisherEngine(IEngine):
|
||||
self._engine_loop()
|
||||
except Exception:
|
||||
logging.error("exception occurred while running engine loop")
|
||||
traceback.print_exc()
|
||||
print_exc()
|
||||
|
||||
fishing_event.unsubscribe()
|
||||
|
||||
@ -52,7 +58,7 @@ class SemiFisherEngine(IEngine):
|
||||
capture = self.window.processed_image(func=image_pre_process)
|
||||
|
||||
# if window server crashed
|
||||
if not capture:
|
||||
if capture is None:
|
||||
logging.error("Couldn't capture window stopping engine")
|
||||
return
|
||||
|
||||
@ -61,9 +67,8 @@ class SemiFisherEngine(IEngine):
|
||||
# if fishyqr fails to get read multiple times, stop the bot
|
||||
if not values:
|
||||
skip_count += 1
|
||||
logging.error(f"Couldn't read values from FishyQR, skipping {skip_count}/5")
|
||||
if skip_count >= 5:
|
||||
logging.error("Stopping engine...")
|
||||
logging.error("Couldn't read values from FishyQR, Stopping engine...")
|
||||
return
|
||||
else:
|
||||
skip_count = 0
|
||||
|
@ -8,10 +8,9 @@ from dataclasses import dataclass
|
||||
|
||||
from ttkthemes import ThemedTk
|
||||
|
||||
from fishy.engine.common.event_handler import EngineEventHandler, IEngineHandler
|
||||
from fishy.engine.common.event_handler import IEngineHandler
|
||||
from fishy.gui import config_top
|
||||
from fishy.gui.funcs import GUIFuncs
|
||||
from fishy.web import web
|
||||
|
||||
from ..helper.config import config
|
||||
from ..helper.helper import wait_until
|
||||
|
@ -12,6 +12,9 @@ class GUIStreamHandler(StreamHandler):
|
||||
self.gui = gui
|
||||
|
||||
def emit(self, record):
|
||||
# todo implement verbose/debug option to show more info
|
||||
# formatter = Formatter('%(name)s - %(levelname)s - %(message)s')
|
||||
# self.setFormatter(formatter)
|
||||
msg = self.format(record)
|
||||
self.gui.call_in_thread(lambda: _write_to_console(self.gui, msg))
|
||||
|
||||
|
@ -157,7 +157,7 @@ def create_shortcut(anti_ghosting: bool):
|
||||
|
||||
logging.info("Shortcut created")
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
print_exc()
|
||||
logging.error("Couldn't create shortcut")
|
||||
|
||||
|
||||
@ -219,7 +219,7 @@ def install_addon(name, url, v=None):
|
||||
return 0
|
||||
except Exception:
|
||||
logging.error("Could not install Add-On " + name + ", try doing it manually")
|
||||
traceback.print_exc()
|
||||
print_exc()
|
||||
return 1
|
||||
|
||||
|
||||
@ -276,3 +276,8 @@ def kill_thread(thread):
|
||||
if res > 1:
|
||||
ctypes.pythonapi.PyThreadState_SetAsyncExc(thread_id, 0)
|
||||
print('Exception raise failure')
|
||||
|
||||
|
||||
def print_exc():
|
||||
logging.error(traceback.format_exc())
|
||||
traceback.print_exc()
|
||||
|
Loading…
Reference in New Issue
Block a user