├── .gitignore ├── README.md ├── main.py └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | venv 3 | *.spec 4 | build 5 | dist 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 简介 2 | 3 | 这是一个因为梗而创作的程序 4 | 5 | **检测到你的屏幕白色占比超过90%那么将自动启动原神** 6 | 7 | 来源于群友的一个视频@Tokeii0 8 | 9 |
10 | 11 | ## 本源码包含的技术 12 | 13 | - 检测屏幕白色像素比例(cv2) 14 | - 获取原神路径(原神没有把路径放入注册表,我通过获取快捷方式拼接的路径) 15 | - 将原神窗口置顶 16 | 17 |
18 | 19 | ## 如何使用本源码 20 | 21 | ### 从源码使用: 22 | 23 | ``` 24 | git clone https://github.com/YinBuLiao/GenshinImpact_Start.git 25 | cd GenshinImpact_Start 26 | pip install requirements.txt 27 | python main.py(需要使用管理员权限运行) 28 | ``` 29 | 30 | ### 从release下载: 31 | 32 | - 将软件下载以后以管理员模式启动程序 33 | 34 | ## 特别感谢 35 | 36 | - [Tokeii0](https://github.com/Tokeii0) 37 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | import time 4 | import cv2 5 | import numpy as np 6 | import pyautogui 7 | import win32com.client 8 | import win32con 9 | import win32gui 10 | from PIL import ImageGrab 11 | 12 | # 检查原神是否已经启动 13 | if os.system('tasklist /FI "IMAGENAME eq YuanShen.exe" 2>NUL | find /I /N "YuanShen.exe">NUL') == 0: 14 | print("原神 已在运行!") 15 | os.system('pause') 16 | exit() 17 | # 获取屏幕分辨率 18 | screen_width, screen_height = pyautogui.size() 19 | pyautogui.FAILSAFE = False # 关闭FailSafe 20 | 21 | while True: 22 | # 截图 23 | screenshot = cv2.cvtColor(np.array(ImageGrab.grab(bbox=(0, 0, screen_width, screen_height))), cv2.COLOR_BGR2RGB) 24 | # 计算屏幕白色像素比例 25 | white_pixels = np.count_nonzero(screenshot >= [250, 250, 250]) 26 | total_pixels = screenshot.shape[0] * screenshot.shape[1] 27 | white_percentage = white_pixels / total_pixels * 100 28 | print(f"屏幕含原量{white_percentage}%") 29 | # 判断是否满足启动条件 30 | if white_percentage >= 90: 31 | break 32 | # 获取快捷方式路径 33 | shortcut = r'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\原神\原神.lnk' 34 | 35 | # 解析快捷方式获取安装路径 36 | shell = win32com.client.Dispatch("WScript.Shell") 37 | install_dir = shell.CreateShortCut(shortcut) 38 | install_dir = install_dir.TargetPath.replace('launcher.exe', '') 39 | 40 | # 拼接游戏exe路径 41 | game_exe = os.path.join(install_dir, 'Genshin Impact Game', 'YuanShen.exe') 42 | 43 | # 创建过渡用的白色图片 44 | transition_steps = 35 45 | white_image = np.full((screen_height, screen_width, 3), 255, dtype=np.uint8) 46 | 47 | # 创建过渡窗口并置顶 48 | cv2.namedWindow('Transition', cv2.WND_PROP_FULLSCREEN) 49 | cv2.setWindowProperty('Transition', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) 50 | transition_window = pyautogui.getWindowsWithTitle("Transition")[0] 51 | pyautogui.moveTo(transition_window.left, transition_window.top) 52 | cv2.imshow('Transition', screenshot) 53 | hwnd = win32gui.FindWindow(None, "Transition") 54 | CVRECT = cv2.getWindowImageRect("Transition") 55 | win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 0, 0, screen_width, screen_height, 56 | win32con.SWP_SHOWWINDOW) 57 | 58 | # 原神,启动! 59 | subprocess.Popen(game_exe) 60 | 61 | # 进行过渡并在过渡窗口上显示 62 | for step in range(transition_steps): 63 | alpha = (step + 1) / transition_steps 64 | blended_image = cv2.addWeighted(screenshot, 1 - alpha, white_image, alpha, 0) 65 | cv2.imshow('Transition', blended_image) 66 | cv2.waitKey(10) 67 | 68 | # 枚举窗口,找到名称包含"原神"的窗口 69 | while True: 70 | windows = pyautogui.getWindowsWithTitle("原神") 71 | if windows: 72 | # 找到窗口并置顶 73 | time.sleep(5) 74 | window = windows[0] 75 | pyautogui.moveTo(window.left, window.top) 76 | print(f"原神 启动!") 77 | break 78 | time.sleep(1) 79 | cv2.destroyWindow('Transition') -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | opencv-python 2 | pyautogui 3 | numpy 4 | subprocess 5 | pywin32 --------------------------------------------------------------------------------