Skip to content

Commit

Permalink
feat: unlock 120 fps
Browse files Browse the repository at this point in the history
  • Loading branch information
moesnow committed Mar 2, 2024
1 parent 00b6744 commit f41773d
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 6 deletions.
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)
2 changes: 1 addition & 1 deletion tasks/game/starrailcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pyautogui
from typing import Literal, Optional
from utils.gamecontroller import GameController
from utils.registry.star_rail_resolution import get_game_resolution, set_game_resolution
from utils.registry.star_rail_setting import get_game_resolution, set_game_resolution
from utils.registry.game_auto_hdr import get_game_auto_hdr, set_game_auto_hdr


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
# Specify the registry key path
registry_key_path = r"SOFTWARE\miHoYo\崩坏:星穹铁道"
# Specify the value name
value_name = "GraphicsSettings_PCResolution_h431323223"
resolution_value_name = "GraphicsSettings_PCResolution_h431323223"
graphics_value_name = "GraphicsSettings_Model_h2986158309"


def get_game_resolution() -> Optional[Tuple[int, int, bool]]:
Expand All @@ -18,7 +19,7 @@ def get_game_resolution() -> Optional[Tuple[int, int, bool]]:
- If the registry value exists and data is valid, it returns a tuple (width, height, isFullScreen) representing the game resolution.
- If the registry value does not exist or data is invalid, it returns None or raises ValueError.
"""
value = read_registry_value(winreg.HKEY_CURRENT_USER, registry_key_path, value_name)
value = read_registry_value(winreg.HKEY_CURRENT_USER, registry_key_path, resolution_value_name)
if value:
data_dict = json.loads(value.decode('utf-8').strip('\x00'))

Expand Down Expand Up @@ -49,7 +50,52 @@ def set_game_resolution(width: int, height: int, is_fullscreen: bool) -> None:
'isFullScreen': is_fullscreen
}
data = (json.dumps(data_dict) + '\x00').encode('utf-8')
write_registry_value(winreg.HKEY_CURRENT_USER, registry_key_path, value_name, data, winreg.REG_BINARY)
write_registry_value(winreg.HKEY_CURRENT_USER, registry_key_path, resolution_value_name, data, winreg.REG_BINARY)


def get_game_fps() -> Optional[int]:
"""
Return the game FPS settings from the registry value.
This function does not take any parameters.
"""
value = read_registry_value(winreg.HKEY_CURRENT_USER, registry_key_path, graphics_value_name)
if value:
data_dict = json.loads(value.decode('utf-8').strip('\x00'))

# Validate data format
if 'FPS' in data_dict:
if isinstance(data_dict['FPS'], int):
return data_dict['FPS']
else:
raise ValueError("Registry data is invalid: FPS must be of type int.")
else:
raise ValueError("Registry data is missing required fields: FPS.")

return None


def set_game_fps(fps: int) -> None:
"""
Set the FPS of the game.
Parameters:
- fps
"""
value = read_registry_value(winreg.HKEY_CURRENT_USER, registry_key_path, graphics_value_name)

data_dict = json.loads(value.decode('utf-8').strip('\x00'))

# Validate data format
if 'FPS' in data_dict:
if isinstance(data_dict['FPS'], int):
data_dict['FPS'] = fps
data = (json.dumps(data_dict) + '\x00').encode('utf-8')
write_registry_value(winreg.HKEY_CURRENT_USER, registry_key_path, graphics_value_name, data, winreg.REG_BINARY)
else:
raise ValueError("Registry data is invalid: FPS must be of type int.")
else:
raise ValueError("Registry data is missing required fields: FPS.")


def read_registry_value(key, sub_key, value_name):
Expand Down Expand Up @@ -78,7 +124,7 @@ def read_registry_value(key, sub_key, value_name):
raise Exception(f"Error reading registry value: {e}")


def write_registry_value(key, sub_key, value_name, data, mode):
def write_registry_value(key, sub_key, value_name, data, mode) -> None:
"""
Write a registry value to the specified registry key.
Expand Down

0 comments on commit f41773d

Please sign in to comment.