Compare commits

...
2 Commits
Author SHA1 Message Date
aeon0 3fa0471198 New release v0.4.2 (#129)
* Bump version to v0.4.2

* add license

* visible error msg
2021-11-27 08:54:22 +01:00
aeon0 0b318e1131 Add user info about window offset search (#128)
* Bump version to: 0.4.1

* More cmd info regarding offset search

* english
2021-11-27 07:51:29 +01:00
6 changed files with 53 additions and 20 deletions
+20
View File
@@ -0,0 +1,20 @@
Copyright (c) 2012-2021 Scott Chacon and others
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+5
View File
@@ -12,6 +12,7 @@ botty_dir = f"botty_v{__version__}"
new_dev_version_code = None
if len(sys.argv) == 2:
print(f"Releasing new version: {sys.argv[1]}")
os.system(f"git checkout -b new-release-v{sys.argv[1]}")
botty_dir = f"botty_v{sys.argv[1]}"
version_code = ""
with open('src/version.py', 'r') as f:
@@ -21,6 +22,8 @@ if len(sys.argv) == 2:
new_dev_version_code = f"{version_code[0]}= '{sys.argv[1]}-dev'"
with open('src/version.py', 'w') as f:
f.write(new_version_code)
else:
raise ValueError("Please provide new version")
# clean up
def clean_up():
@@ -62,3 +65,5 @@ clean_up()
if new_dev_version_code is not None:
with open('src/version.py', 'w') as f:
f.write(new_dev_version_code)
os.system(f'git add .')
os.system(f'git commit -m "Bump version to v{sys.argv[1]}"')
+2 -1
View File
@@ -125,7 +125,8 @@ class Bot:
def on_create_game(self):
self._game_stats.log_start_game()
self._template_finder.search_and_wait("D2_LOGO_HS", roi=self._config.ui_roi["hero_selection_logo"])
self._ui_manager.start_game()
if not self._ui_manager.start_game():
return
self._template_finder.search_and_wait(["A5_TOWN_1", "A5_TOWN_0"])
self._tp_is_up = False
self._curr_location = Location.A5_TOWN_START
+23 -16
View File
@@ -26,22 +26,29 @@ class Screen:
# auto find offests
res_str = "" if self._config.general['res'] == "1920_1080" else "_1280_720"
template = load_template(f"assets/templates{res_str}/main_menu_top_left.png", 1.0)
img = self.grab()
self._sct = mss()
res = cv2.matchTemplate(img, template, cv2.TM_CCOEFF_NORMED)
_, max_val, _, max_pos = cv2.minMaxLoc(res)
if max_val > 0.9:
offset_left, offset_top = max_pos
Logger.debug(f"Set offsets: left {offset_left}px, top {offset_top}px")
self._monitor_roi["top"] += offset_top
self._monitor_roi["left"] += offset_left
self._monitor_x_range = (self._monitor_roi["left"] + 10, self._monitor_roi["left"] + self._monitor_roi["width"] - 10)
self._monitor_y_range = (self._monitor_roi["top"] + 10, self._monitor_roi["top"] + self._monitor_roi["height"] - 10)
self._monitor_roi["width"] = self._config.ui_pos["screen_width"]
self._monitor_roi["height"] = self._config.ui_pos["screen_height"]
else:
Logger.error("Could not find top left corner of window to set offset, shutting down")
raise RuntimeError("Could not determine window offset")
start = time.time()
found_offsets = False
Logger.info("Searching for window offsets. Make sure D2R is in focus and you are on the hero selection screen")
while time.time() - start < 20:
img = self.grab()
self._sct = mss()
res = cv2.matchTemplate(img, template, cv2.TM_CCOEFF_NORMED)
_, max_val, _, max_pos = cv2.minMaxLoc(res)
if max_val > 0.9:
offset_left, offset_top = max_pos
Logger.debug(f"Set offsets: left {offset_left}px, top {offset_top}px")
self._monitor_roi["top"] += offset_top
self._monitor_roi["left"] += offset_left
self._monitor_x_range = (self._monitor_roi["left"] + 10, self._monitor_roi["left"] + self._monitor_roi["width"] - 10)
self._monitor_y_range = (self._monitor_roi["top"] + 10, self._monitor_roi["top"] + self._monitor_roi["height"] - 10)
self._monitor_roi["width"] = self._config.ui_pos["screen_width"]
self._monitor_roi["height"] = self._config.ui_pos["screen_height"]
found_offsets = True
break
if not found_offsets:
Logger.error("Could not find top left corner of D2R window to set offset, shutting down")
raise RuntimeError("Could not determine window offset. Please make sure you have the D2R window " +
f"focused and that you are on the hero selection screen when pressing {self._config.general['resume_key']}")
def convert_monitor_to_screen(self, screen_coord: Tuple[float, float]) -> Tuple[float, float]:
return (screen_coord[0] - self._monitor_roi["left"], screen_coord[1] - self._monitor_roi["top"])
+2 -2
View File
@@ -154,8 +154,8 @@ class UiManager():
# Might be in online mode?
found_btn, _ = self._template_finder.search("PLAY_BTN", img, roi=self._config.ui_roi["play_btn"], threshold=0.8)
if found_btn:
Logger.error("Botty only works for single player. Please switch to offline mode!")
os._exit(1)
Logger.error("Botty only works for single player. Please switch to offline mode and restart botty!")
return False
time.sleep(3.0)
difficulty=self._config.general["difficulty"].lower()
+1 -1
View File
@@ -1 +1 @@
__version__ = '0.4.1-dev'
__version__ = '0.4.2-dev'