Skip to content

Commit

Permalink
新增 | 现在可以通过快捷键隐藏叠加层了
Browse files Browse the repository at this point in the history
新增 | pyinstaller 打包的配置
新增 | 检测频率现在会显示在左上角
  • Loading branch information
Mufanc committed Sep 10, 2021
1 parent ce2b157 commit 64d7b1f
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/venv/
/detects/clips/*
/build/
/dist/
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
### 这个脚本有什么特色?

* 直接在游戏画面上通过叠加层显示信息,直截了当,便于调试
* 游戏中按下 <kbd>Alt</kbd> + <kbd>小键盘「.」</kbd> 来显示/隐藏叠加层

* 使用相对距离定位进度条,不会因为 ui 布局变化而影响检测效果

Expand All @@ -22,6 +23,10 @@

### 使用教程:

> 💡 Release 版本现已发布,下载后直接解压即可使用,[点击这里](releases/latest) 跳转到下载页
>
> ![](images/quick-start.png)
* 首先下载项目代码到本地

```shell
Expand Down
6 changes: 6 additions & 0 deletions build-project.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@echo off
del /f /s /q build
del /f /s /q dist
pyinstaller -y main.spec
xcopy detects dist\main\detects\ /e

2 changes: 2 additions & 0 deletions detects/detects.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Default: 1600x900

detects:
- name: button
convert: 'gray' # 颜色转换,会通过 cv2.COLOR_BGR2{{convert.upper()}} 进行转换
Expand Down
7 changes: 6 additions & 1 deletion hotkeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@


class HotKey(Thread):
def __init__(self, callback):
def __init__(self, overlay, callback):
super().__init__()
self.overlay = overlay
self.callback = callback
self.daemon = True

def run(self):
for i in range(10):
key_id = base + i
user32.RegisterHotKey(None, key_id, MOD_ALT, VK_NUMPAD0 + i)
user32.RegisterHotKey(None, base + 10, MOD_ALT, VK_DECIMAL)
try:
msg = wintypes.MSG()
while True:
Expand All @@ -28,6 +30,9 @@ def run(self):
for i in range(10):
if msg.wParam == base + i:
self.callback(i)
if msg.wParam == base + 10:
self.overlay.switch()
finally:
for i in range(10):
user32.UnregisterHotKey(None, base + i)
user32.UnregisterHotKey(None, base + 10)
Binary file added images/quick-start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 22 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import ctypes
import sys
import cv2
from threading import Thread
from time import sleep
from time import strftime
Expand All @@ -8,10 +11,18 @@
from overlay import Overlay


def mark_dps(cover):
text, font = f'dps:{last_dps}', cv2.FONT_HERSHEY_COMPLEX
rect, _ = cv2.getTextSize(text, font, 0.7, 2)
color = (0, 255, 0) if last_dps > 10 else (0, 0, 255)
cv2.putText(cover, text, (0, rect[1]), font, 0.7, color, 2)


def timer():
global dps
global dps, last_dps
while True:
print(f'\r[{strftime("%H:%M:%S")}] {dps} detects per second.', end='')
last_dps = dps
dps = 0
sleep(1)

Expand All @@ -30,7 +41,7 @@ def main():
while overlay is None:
sleep(0.1)
last_cap = None
HotKey(lambda idx: clip_image(last_cap, idx)).start()
HotKey(overlay, lambda idx: clip_image(last_cap, idx)).start()
while True:
image = manager.screencap()
last_cap = image
Expand All @@ -48,13 +59,18 @@ def main():
manager.mouse_down()
sleep(0.3)
manager.mouse_up()
mark_dps(cover)
overlay.update(cover)
overlay.follow(manager)
dps += 1


if __name__ == '__main__':
dps = 0
manager = Manager('UnityWndClass', '原神')
overlay = None
main()
if ctypes.windll.shell32.IsUserAnAdmin():
dps = 0
last_dps = 0
manager = Manager('UnityWndClass', '原神')
overlay = None
main()
else: # 以管理员身份重启
ctypes.windll.shell32.ShellExecuteW(None, 'runas', sys.executable, __file__, None, 1)
44 changes: 44 additions & 0 deletions main.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- mode: python ; coding: utf-8 -*-


block_cipher = None


a = Analysis(['main.py'],
pathex=['E:\\Projects\\Python\\Genshin - SmartFishingRod'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)

exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='main',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=False,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='main')
9 changes: 9 additions & 0 deletions overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(self):
root.attributes('-topmost', True)
# root.after_idle(root.attributes, '-topmost', True)

self.visible = True
self.hwnd = wintypes.HANDLE(int(root.frame(), 16)).value
win32gui.SetWindowLong(self.hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT | WS_EX_LAYERED)
# win32gui.SetLayeredWindowAttributes(self.hwnd, 0, 0, LWA_ALPHA)
Expand All @@ -41,3 +42,11 @@ def update(self, image):
)
self.panel.configure(image=self.image)
self.panel.image = self.image

def switch(self):
if self.visible:
self.visible = False
self.root.withdraw()
else:
self.visible = True
self.root.deiconify()

0 comments on commit 64d7b1f

Please sign in to comment.