From 70eb0e944346eebbebded119735c40110a62e78b Mon Sep 17 00:00:00 2001 From: tretrauit Date: Tue, 6 Feb 2024 11:48:16 +0700 Subject: [PATCH] feat: add hi3 stub HI3 isn't working atm, don't expect too much --- pyproject.toml | 4 +- vollerei/{honkai => hi3}/__init__.py | 0 vollerei/hi3/constants.py | 24 ++++++ vollerei/{honkai => hi3}/launcher/__init__.py | 0 vollerei/hi3/launcher/enums.py | 9 +++ vollerei/hi3/launcher/game.py | 73 +++++++++++++++++++ .../{honkai => hi3}/launcher/interface.py | 0 vollerei/hi3/patcher.py | 6 ++ vollerei/honkai/patcher.py | 0 vollerei/hsr/patcher.py | 2 + 10 files changed, 117 insertions(+), 1 deletion(-) rename vollerei/{honkai => hi3}/__init__.py (100%) create mode 100644 vollerei/hi3/constants.py rename vollerei/{honkai => hi3}/launcher/__init__.py (100%) create mode 100644 vollerei/hi3/launcher/enums.py create mode 100644 vollerei/hi3/launcher/game.py rename vollerei/{honkai => hi3}/launcher/interface.py (100%) create mode 100644 vollerei/hi3/patcher.py delete mode 100644 vollerei/honkai/patcher.py diff --git a/pyproject.toml b/pyproject.toml index 989c77a..041aa84 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,10 +16,12 @@ cleo = "^2.1.0" pytest = "^7.3.1" pre-commit = "^3.3.3" - [tool.poetry.group.cli.dependencies] tqdm = "^4.65.0" +[tool.poetry.scripts] +vollerei = 'vollerei.cli:run' + [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" diff --git a/vollerei/honkai/__init__.py b/vollerei/hi3/__init__.py similarity index 100% rename from vollerei/honkai/__init__.py rename to vollerei/hi3/__init__.py diff --git a/vollerei/hi3/constants.py b/vollerei/hi3/constants.py new file mode 100644 index 0000000..54fceae --- /dev/null +++ b/vollerei/hi3/constants.py @@ -0,0 +1,24 @@ +class LAUNCHER_API: + """Launcher API constants.""" + + RESOURCE_PATH: str = "mdk/launcher/api/resource" + OS: dict = { + "url": "https://hkrpg-launcher-static.hoyoverse.com/hkrpg_global/", + "params": { + "channel_id": 1, + "key": "vplOVX8Vn7cwG8yb", + "launcher_id": 35, + }, + } + ASIA: dict = {} + CN: dict = { + "url": "https://api-launcher.mihoyo.com/hkrpg_cn/mdk/launcher/api/resource", + "params": { + "channel_id": 1, + "key": "6KcVuOkbcqjJomjZ", + "launcher_id": 33, + }, + } + + +LATEST_VERSION = (7, 2, 0) diff --git a/vollerei/honkai/launcher/__init__.py b/vollerei/hi3/launcher/__init__.py similarity index 100% rename from vollerei/honkai/launcher/__init__.py rename to vollerei/hi3/launcher/__init__.py diff --git a/vollerei/hi3/launcher/enums.py b/vollerei/hi3/launcher/enums.py new file mode 100644 index 0000000..fe1f2e0 --- /dev/null +++ b/vollerei/hi3/launcher/enums.py @@ -0,0 +1,9 @@ +from enum import Enum + + +class GameChannel(Enum): + Global = 0 + Asia = 1 + Taiwan = 2 + Korea = 3 + China = 4 diff --git a/vollerei/hi3/launcher/game.py b/vollerei/hi3/launcher/game.py new file mode 100644 index 0000000..b4f5d70 --- /dev/null +++ b/vollerei/hi3/launcher/game.py @@ -0,0 +1,73 @@ +from configparser import ConfigParser +from io import IOBase +from os import PathLike +from pathlib import Path +from vollerei.abc.launcher.game import GameABC +from vollerei.common import ConfigFile, functions +from vollerei.common.api import resource +from vollerei.common.enums import VoicePackLanguage +from vollerei.exceptions.game import ( + GameAlreadyUpdatedError, + GameNotInstalledError, + PreDownloadNotAvailable, + ScatteredFilesNotAvailableError, +) +from vollerei.hi3.launcher.enums import GameChannel +from vollerei.hsr.launcher import api +from vollerei import paths +from vollerei.utils import download + + +class Game(GameABC): + """ + Manages the game installation + + Since channel detection isn't implemented yet, most functions assume you're + using the overseas version of the game. You can override channel by setting + the property `channel_override` to the channel you want to use. + """ + + def __init__(self, path: PathLike = None, cache_path: PathLike = None): + self._path: Path | None = Path(path) if path else None + if not cache_path: + cache_path = paths.cache_path + cache_path = Path(cache_path) + self.cache: Path = cache_path.joinpath("game/hi3/") + self.cache.mkdir(parents=True, exist_ok=True) + self._version_override: tuple[int, int, int] | None = None + self._channel_override: GameChannel | None = None + + @property + def version_override(self) -> tuple[int, int, int] | None: + """ + Overrides the game version. + + This can be useful if you want to override the version of the game + and additionally working around bugs. + """ + return self._version_override + + @version_override.setter + def version_override(self, version: tuple[int, int, int] | str | None): + if isinstance(version, str): + version = tuple(int(i) for i in version.split(".")) + self._version_override = version + + @property + def channel_override(self) -> GameChannel | None: + """ + Overrides the game channel. + + Because game channel detection isn't implemented yet, you may need + to use this for some functions to work. + + This can be useful if you want to override the channel of the game + and additionally working around bugs. + """ + return self._channel_override + + @channel_override.setter + def channel_override(self, channel: GameChannel | str | None): + if isinstance(channel, str): + channel = GameChannel[channel] + self._channel_override = channel diff --git a/vollerei/honkai/launcher/interface.py b/vollerei/hi3/launcher/interface.py similarity index 100% rename from vollerei/honkai/launcher/interface.py rename to vollerei/hi3/launcher/interface.py diff --git a/vollerei/hi3/patcher.py b/vollerei/hi3/patcher.py new file mode 100644 index 0000000..1ddc0f6 --- /dev/null +++ b/vollerei/hi3/patcher.py @@ -0,0 +1,6 @@ +from vollerei.hsr.patcher import Patcher, PatchType + + +# Re-exports Patcher and PatchType from HSR because they use the same patcher +# which is Jadeite. +__all__ = ["Patcher", "PatchType"] diff --git a/vollerei/honkai/patcher.py b/vollerei/honkai/patcher.py deleted file mode 100644 index e69de29..0000000 diff --git a/vollerei/hsr/patcher.py b/vollerei/hsr/patcher.py index d49a053..5a15635 100644 --- a/vollerei/hsr/patcher.py +++ b/vollerei/hsr/patcher.py @@ -188,6 +188,8 @@ class Patcher(PatcherABC): Unpatch the game If you use Jadeite (by default), this will just delete Jadeite files. + Note that Honkai Impact 3rd uses Jadeite too, so executing this will + delete the files needed by both games. Args: game (Game): The game to unpatch