Skip to content

Commit

Permalink
Merge pull request #166 from moesnow/refactor
Browse files Browse the repository at this point in the history
feat: auto hdr && unlock 120 fps
  • Loading branch information
moesnow authored Mar 2, 2024
2 parents 0a37634 + f41773d commit cf6f519
Show file tree
Hide file tree
Showing 30 changed files with 882 additions and 600 deletions.
2 changes: 1 addition & 1 deletion app/card/samplecardview1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ..common.style_sheet import StyleSheet
from managers.config_manager import config

from tasks.base.command import start_task
from tasks.base.tasks import start_task
from ..tools.disclaimer import disclaimer

import base64
Expand Down
28 changes: 14 additions & 14 deletions app/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
from .tools.disclaimer import disclaimer

from managers.config_manager import config
import subprocess
from utils.gamecontroller import GameController
import base64
import os


class MainWindow(MSFluentWindow):
Expand Down Expand Up @@ -111,8 +110,19 @@ def initNavigation(self):
disclaimer(self)

def startGame(self):
game = GameController(config.game_path, config.game_process_name, config.game_title_name, 'UnityWndClass')
try:
if os.system(f"cmd /C start \"\" \"{config.game_path}\""):
if game.start_game():
InfoBar.success(
title=self.tr('启动成功(^∀^●)'),
content="",
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.TOP,
duration=1000,
parent=self
)
else:
InfoBar.warning(
title=self.tr('启动失败(╥╯﹏╰╥)'),
content="",
Expand All @@ -122,17 +132,7 @@ def startGame(self):
duration=1000,
parent=self
)
return False
InfoBar.success(
title=self.tr('启动成功(^∀^●)'),
content="",
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.TOP,
duration=1000,
parent=self
)
except Exception:
except:
InfoBar.warning(
title=self.tr('启动失败(╥╯﹏╰╥)'),
content="",
Expand Down
6 changes: 3 additions & 3 deletions app/setting_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .card.rangesettingcard1 import RangeSettingCard1
from .card.pushsettingcard1 import PushSettingCardInstance, PushSettingCardEval, PushSettingCardDate, PushSettingCardKey, PushSettingCardTeam
from managers.config_manager import config
from tasks.base.command import start_task
from tasks.base.tasks import start_task
from .tools.check_update import checkUpdate
import os

Expand Down Expand Up @@ -505,8 +505,8 @@ def __initCard(self):
)
self.autoSetResolutionEnableCard = SwitchSettingCard1(
FIF.FULL_SCREEN,
self.tr('启用自动修改分辨率'),
"通过软件启动游戏会自动修改 1920x1080 分辨率,不影响手动启动游戏(未测试国际服)",
self.tr('启用自动修改分辨率并关闭自动 HDR'),
"通过软件启动游戏会自动修改 1920x1080 分辨率并关闭自动 HDR,不影响手动启动游戏(未测试国际服)",
"auto_set_resolution_enable"
)
self.autoSetGamePathEnableCard = SwitchSettingCard1(
Expand Down
47 changes: 46 additions & 1 deletion app/tools_interface.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QLabel, QVBoxLayout, QSpacerItem
from qfluentwidgets import FluentIcon as FIF
from qfluentwidgets import SettingCardGroup, PushSettingCard, ScrollArea
from qfluentwidgets import SettingCardGroup, PushSettingCard, ScrollArea, InfoBar, InfoBarPosition
from .common.style_sheet import StyleSheet
from utils.registry.star_rail_setting import get_game_fps, set_game_fps


class ToolsInterface(ScrollArea):
Expand All @@ -27,6 +28,12 @@ def __init__(self, parent=None):
self.tr("游戏截图"),
self.tr("检查程序获取的图像是否正确,支持OCR识别文字(可用于复制副本名称)")
)
self.unlockfpsCard = PushSettingCard(
self.tr('解锁'),
FIF.SPEED_HIGH,
self.tr("解锁帧率"),
self.tr("通过修改注册表解锁120帧率,如已解锁,再次点击将恢复60帧率(未测试国际服)")
)

self.__initWidget()

Expand All @@ -49,6 +56,7 @@ def __initLayout(self):

self.ToolsGroup.addSettingCard(self.automaticPlotCard)
self.ToolsGroup.addSettingCard(self.gameScreenshotCard)
self.ToolsGroup.addSettingCard(self.unlockfpsCard)

self.ToolsGroup.titleLabel.setHidden(True)

Expand All @@ -70,6 +78,43 @@ def __onAutomaticPlotCardClicked(self):
from tasks.tools.automatic_plot import automatic_plot
automatic_plot()

def __onUnlockfpsCardClicked(self):
try:
fps = get_game_fps()
if fps == 120:
set_game_fps(60)
InfoBar.success(
title=self.tr('恢复60成功(^∀^●)'),
content="",
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.TOP,
duration=1000,
parent=self
)
else:
set_game_fps(120)
InfoBar.success(
title=self.tr('解锁120成功(^∀^●)'),
content="",
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.TOP,
duration=1000,
parent=self
)
except:
InfoBar.warning(
title=self.tr('解锁失败(╥╯﹏╰╥)'),
content="",
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.TOP,
duration=1000,
parent=self
)

def __connectSignalToSlot(self):
self.gameScreenshotCard.clicked.connect(self.__onGameScreenshotCardClicked)
self.automaticPlotCard.clicked.connect(self.__onAutomaticPlotCardClicked)
self.unlockfpsCard.clicked.connect(self.__onUnlockfpsCardClicked)
7 changes: 3 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
os.chdir(os.path.dirname(sys.executable) if getattr(sys, 'frozen', False)
else os.path.dirname(os.path.abspath(__file__)))

from tasks.version.version import Version
from tasks.version import Version
from managers.notify_manager import notify
from managers.logger_manager import logger
from managers.config_manager import config
from managers.ocr_manager import ocr
from managers.translate_manager import _
from tasks.game.game import Game
from tasks.game.start import Start
from tasks.game import Game
from tasks.daily.daily import Daily
import tasks.activity as activity
import tasks.reward as reward
Expand Down Expand Up @@ -131,7 +130,7 @@ def main(action=None):
automatic_plot()

elif action == "game":
Start.launch_game()
Game.start()

elif action == "notify":
run_notify_action()
Expand Down
8 changes: 4 additions & 4 deletions tasks/base/download.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from tqdm import tqdm
import urllib.request
import subprocess
import os


def download_with_progress(download_url, save_path):
from tqdm import tqdm
import urllib.request
import subprocess
import os

aria2_path = os.path.abspath("./assets/aria2/aria2c.exe")

Expand Down
7 changes: 4 additions & 3 deletions tasks/base/pythonchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from managers.logger_manager import logger
from managers.config_manager import config
from managers.translate_manager import _
from tasks.base.command import subprocess_with_stdout
from tasks.base.windowswitcher import WindowSwitcher
from utils.command import subprocess_with_stdout
from utils.gamecontroller import GameController
from packaging.version import parse
import subprocess
import tempfile
Expand Down Expand Up @@ -68,7 +68,8 @@ def install():

if PythonChecker.check(destination_path):
config.set_value("python_exe_path", destination_path)
WindowSwitcher.check_and_switch(config.game_title_name)
game = GameController(config.game_path, config.game_process_name, config.game_title_name, 'UnityWndClass', logger)
game.switch_to_game()
return

logger.info(_("安装完成,请重启程序,包括图形界面"))
Expand Down
35 changes: 4 additions & 31 deletions tasks/base/command.py → tasks/base/tasks.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,11 @@

def subprocess_with_timeout(command, timeout, working_directory=None, env=None):
import subprocess
process = None
try:
process = subprocess.Popen(command, cwd=working_directory, env=env)
process.communicate(timeout=timeout)
if process.returncode == 0:
return True
except subprocess.TimeoutExpired:
if process is not None:
process.terminate()
process.wait()
return False


def subprocess_with_stdout(command):
import subprocess
try:
# 使用subprocess运行命令并捕获标准输出
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
# 检查命令是否成功执行
if result.returncode == 0:
# 返回标准输出的内容
return result.stdout.strip()
return None
except Exception:
return None
from utils.command import subprocess_with_stdout
import subprocess
import sys
import os


def start_task(command):
# 为什么 Windows 这么难用呢
import subprocess
import sys
import os
# 检查是否是 PyInstaller 打包的可执行文件
if getattr(sys, 'frozen', False):
if subprocess_with_stdout(["where", "wt.exe"]) is not None:
Expand Down
43 changes: 0 additions & 43 deletions tasks/base/windowswitcher.py

This file was deleted.

3 changes: 1 addition & 2 deletions tasks/daily/daily.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from managers.config_manager import config
from managers.screen_manager import screen
from managers.translate_manager import _
from tasks.base.date import Date
from utils.date import Date
from tasks.daily.photo import Photo
from tasks.daily.fight import Fight
from tasks.weekly.universe import Universe
Expand All @@ -13,7 +13,6 @@
from tasks.power.power import Power
from tasks.daily.tasks import Tasks
from tasks.daily.himekotry import HimekoTry
from tasks.base.date import Date
from tasks.weekly.echoofwar import Echoofwar


Expand Down
7 changes: 4 additions & 3 deletions tasks/daily/fight.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from tasks.base.base import Base
from tasks.base.team import Team
from tasks.base.pythonchecker import PythonChecker
from tasks.game.resolution import Resolution
from tasks.base.command import subprocess_with_timeout
from tasks.game.starrailcontroller import StarRailController
from utils.command import subprocess_with_timeout
import subprocess
import sys
import os
Expand Down Expand Up @@ -80,7 +80,8 @@ def before_start():
@staticmethod
def start():
logger.hr(_("准备锄大地"), 0)
Resolution.check(config.game_title_name, 1920, 1080)
game = StarRailController(config.game_path, config.game_process_name, config.game_title_name, 'UnityWndClass', logger)
game.check_resolution(1920, 1080)
if Fight.before_start():
# 切换队伍
if config.fight_team_enable:
Expand Down
Loading

0 comments on commit cf6f519

Please sign in to comment.