From 3fe1da17089f932773d87e529635b9a938991f34 Mon Sep 17 00:00:00 2001 From: MuriloChianfa <60560085+MuriloChianfa@users.noreply.github.com> Date: Fri, 6 May 2022 01:34:48 -0300 Subject: [PATCH] Adding food eater module --- core/GUI.py | 3 +++ core/SendToClient.py | 4 ++++ engine/ScanFood.py | 12 ++++++++++++ modules/FoodEater.py | 16 ++++++++++++---- modules/Root.py | 3 ++- scripts/conf.json | 2 +- 6 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 engine/ScanFood.py diff --git a/core/GUI.py b/core/GUI.py index 681e47c..639f2c6 100644 --- a/core/GUI.py +++ b/core/GUI.py @@ -203,6 +203,9 @@ def addRadioImage(self, text, variable, value, position, command=None, image=Non def After(self, Time, Function): return self.windowID.after(Time, Function) + def deiconify(self): + return self.windowID.deiconify() + @staticmethod def openImage(image, size): ImageID = Image.open(image) diff --git a/core/SendToClient.py b/core/SendToClient.py index fe97aeb..b4256df 100644 --- a/core/SendToClient.py +++ b/core/SendToClient.py @@ -15,6 +15,8 @@ import win32api import win32con +from time import sleep + from conf.HexMapKeys import KeyToHex from conf.conf_manager import ConfManager @@ -81,8 +83,10 @@ def Press(self, Key): def PressHotkey(self, Option, Key): win32api.keybd_event(KeyToHex.get(Option, ""), 0, 0, 0) + sleep(.05) win32api.SendMessage(self.hwnd, win32con.WM_KEYDOWN, KeyToHex.get(Key, ""), 0) win32api.SendMessage(self.hwnd, win32con.WM_KEYUP, KeyToHex.get(Key, ""), 0) + sleep(.05) win32api.keybd_event(KeyToHex.get(Option, ""), 0, win32con.KEYEVENTF_KEYUP, 0) ''' diff --git a/engine/ScanFood.py b/engine/ScanFood.py new file mode 100644 index 0000000..a0ae7e4 --- /dev/null +++ b/engine/ScanFood.py @@ -0,0 +1,12 @@ +from core.HookWindow import LocateImage + + +def scan_food(stats_positions): + starving = [0, 0] + + starving[0], starving[1] = LocateImage('images/PlayerStats/Starving.png', Precision=0.9, Region=( + stats_positions[0], stats_positions[1], stats_positions[2], stats_positions[3])) + + if starving[0] != 0 and starving[1] != 0: + return True + return False diff --git a/modules/FoodEater.py b/modules/FoodEater.py index 4192d3b..ae375a8 100644 --- a/modules/FoodEater.py +++ b/modules/FoodEater.py @@ -2,6 +2,8 @@ Food eater module """ +from time import sleep + from conf.Hotkeys import Hotkey from core.GUI import * @@ -9,6 +11,8 @@ from core.GUISetter import GUISetter, check_gui from core.ThreadManager import ThreadManager +from engine.ScanFood import scan_food + class FoodEater: started = False @@ -16,13 +20,14 @@ class FoodEater: gui_changes = [] - def __init__(self, root, MOUSE_OPTION): + def __init__(self, root, stats_positions, MOUSE_OPTION): self.root = root self.window = GUI('FoodEater', 'Module: Food Eater') self.window.DefaultWindow('FoodEater', [306, 191], [1.2, 2.29]) self.Setter = GUISetter("FoodEaterLoader") self.SendToClient = Hotkey(MOUSE_OPTION) self.ThreadManager = ThreadManager("ThreadFoodEater") + self.stats_positions = stats_positions self.gui_vars() self.gui() @@ -60,7 +65,10 @@ def pause(self): def execute(self): while FoodEater.enabled: - print('Hotkey to eat food: ', self.food_hotkey.get()) + if scan_food(self.stats_positions): + self.SendToClient.Press(self.food_hotkey.get()) + print("Starving... pressing: ", self.food_hotkey.get()) + sleep(0.5) def destroy(self): check_gui(FoodEater.gui_changes, self.init_check_print, self.check_print.get(), 'CheckPrint') @@ -96,8 +104,8 @@ def gui(self): if not FoodEater.enabled: self.enabled_button = self.window.addButton('FoodEater: OFF', self.trigger, [287, 23], [11, 132]) else: - self.enabled_button = self.window.addButton('FoodEater: ON', self.trigger, [287, 23], [11, 132]) \ - .configure(relief=SUNKEN, bg=rgb((158, 46, 34))) + self.enabled_button = self.window.addButton('FoodEater: ON', self.trigger, [287, 23], [11, 132]) + self.enabled_button.configure(relief=SUNKEN, bg=rgb((158, 46, 34))) self.ok_button = self.window.addButton('Ok', self.destroy, [73, 21], [115, 161]) diff --git a/modules/Root.py b/modules/Root.py index cd1ad17..0386e5a 100644 --- a/modules/Root.py +++ b/modules/Root.py @@ -61,6 +61,7 @@ class root: def __init__(self, CharName, LoadedJson): self.root = GUI('root', 'TibiaAuto V12') self.root.MainWindow('Main', [357, 530], [2, 2.36]) + self.root.deiconify() self.root.addMinimalLabel(f'Logged as: {CharName}', [14, 14]) @@ -292,7 +293,7 @@ def OpenCreatureInfo(): def OpenFoodEater(): - FoodEater(root, MOUSE_OPTION) + FoodEater(root, StatsPositions, MOUSE_OPTION) def OpenFPSChanger(): diff --git a/scripts/conf.json b/scripts/conf.json index 9758b68..4fc65d5 100644 --- a/scripts/conf.json +++ b/scripts/conf.json @@ -1,5 +1,5 @@ { - "configured": true, + "configured": false, "hwnd": 460820, "preferences_name": "NewConfig.json", "platform": "windows"