repo: upload files

This commit is contained in:
tretrauit 2023-06-13 04:03:47 +07:00
commit 7c60dc18a6
33 changed files with 725 additions and 0 deletions

160
.gitignore vendored Normal file
View File

@ -0,0 +1,160 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 tretrauit
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

32
README.md Normal file
View File

@ -0,0 +1,32 @@
# Vollerei
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
An open-source launcher for anime games
## Why?
I've done [worthless-launcher](https://tretrauit.gitlab.io/worthless-launcher) for an open-world anime game,
since I want to support other anime games and the launcher code is very messy, this launcher was made.
## Features
+ Nothing, I haven't written any code yet.
### Notes
This launcher tries to mimic the official launcher behaviour as much as possible but if a ban appears, I will
not be responsible for it. (*Turn-based game* have a ban wave already, see AAGL discord for more info)
## Alternatives
This launcher focuses on the API and CLI, for GUI-based launcher you may want to check out:
+ [An Anime Game Launcher](https://aagl.launcher.moe/) - That famous launcher for an open-world anime game.
+ [Yaagl]
+ [Honkers launcher](https://github.com/an-anime-team/honkers-launcher) - Another launcher for an anime game.
+ [Honkers Railway](https://github.com/an-anime-team/the-honkers-railway-launcher) - A launcher for a turn-based anime game.
## License
[MIT](./LICENSE)

89
poetry.lock generated Normal file
View File

@ -0,0 +1,89 @@
# This file is automatically @generated by Poetry 1.5.0 and should not be changed by hand.
[[package]]
name = "colorama"
version = "0.4.6"
description = "Cross-platform colored terminal text."
optional = false
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
files = [
{file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"},
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
]
[[package]]
name = "iniconfig"
version = "2.0.0"
description = "brain-dead simple config-ini parsing"
optional = false
python-versions = ">=3.7"
files = [
{file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"},
{file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"},
]
[[package]]
name = "packaging"
version = "23.1"
description = "Core utilities for Python packages"
optional = false
python-versions = ">=3.7"
files = [
{file = "packaging-23.1-py3-none-any.whl", hash = "sha256:994793af429502c4ea2ebf6bf664629d07c1a9fe974af92966e4b8d2df7edc61"},
{file = "packaging-23.1.tar.gz", hash = "sha256:a392980d2b6cffa644431898be54b0045151319d1e7ec34f0cfed48767dd334f"},
]
[[package]]
name = "platformdirs"
version = "3.5.1"
description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"."
optional = false
python-versions = ">=3.7"
files = [
{file = "platformdirs-3.5.1-py3-none-any.whl", hash = "sha256:e2378146f1964972c03c085bb5662ae80b2b8c06226c54b2ff4aa9483e8a13a5"},
{file = "platformdirs-3.5.1.tar.gz", hash = "sha256:412dae91f52a6f84830f39a8078cecd0e866cb72294a5c66808e74d5e88d251f"},
]
[package.extras]
docs = ["furo (>=2023.3.27)", "proselint (>=0.13)", "sphinx (>=6.2.1)", "sphinx-autodoc-typehints (>=1.23,!=1.23.4)"]
test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.3.1)", "pytest-cov (>=4)", "pytest-mock (>=3.10)"]
[[package]]
name = "pluggy"
version = "1.0.0"
description = "plugin and hook calling mechanisms for python"
optional = false
python-versions = ">=3.6"
files = [
{file = "pluggy-1.0.0-py2.py3-none-any.whl", hash = "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"},
{file = "pluggy-1.0.0.tar.gz", hash = "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159"},
]
[package.extras]
dev = ["pre-commit", "tox"]
testing = ["pytest", "pytest-benchmark"]
[[package]]
name = "pytest"
version = "7.3.1"
description = "pytest: simple powerful testing with Python"
optional = false
python-versions = ">=3.7"
files = [
{file = "pytest-7.3.1-py3-none-any.whl", hash = "sha256:3799fa815351fea3a5e96ac7e503a96fa51cc9942c3753cda7651b93c1cfa362"},
{file = "pytest-7.3.1.tar.gz", hash = "sha256:434afafd78b1d78ed0addf160ad2b77a30d35d4bdf8af234fe621919d9ed15e3"},
]
[package.dependencies]
colorama = {version = "*", markers = "sys_platform == \"win32\""}
iniconfig = "*"
packaging = "*"
pluggy = ">=0.12,<2.0"
[package.extras]
testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "xmlschema"]
[metadata]
lock-version = "2.0"
python-versions = "^3.11"
content-hash = "b34ef1fca1c3d1052c3cd98113215a31309abdebdc436b62c81257507b0cb1ed"

18
pyproject.toml Normal file
View File

@ -0,0 +1,18 @@
[tool.poetry]
name = "vollerei"
version = "0.1.0"
description = "An open-source launcher for anime games"
authors = ["tretrauit <tretrauit@gmail.com>"]
license = "MIT"
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.11"
platformdirs = "^3.5.1"
[tool.poetry.group.dev.dependencies]
pytest = "^7.3.1"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

0
vollerei/__init__.py Normal file
View File

0
vollerei/abc/__init__.py Normal file
View File

View File

View File

@ -0,0 +1,93 @@
from abc import ABC, abstractmethod
from os import PathLike
class GameABC(ABC):
"""
Manages the game installation
"""
def __init__(self, path: PathLike = None):
pass
@abstractmethod
def is_installed(self) -> bool:
"""
Check if the game is installed
"""
pass
@abstractmethod
def install_game(self, game_path: PathLike = None):
"""
Install the game
If path is not specified then it'll use self.path, if that is
not specified too then it'll raise an exception.
Args:
game_path (PathLike, optional): Path to install the game to.
Returns:
None
"""
pass
@abstractmethod
def install_game_from_archive(
self, archive: PathLike, game_path: PathLike = None
) -> None:
"""
Install the game from an archive
If path is not specified then it'll use self.path, if that is
not specified too then it'll raise an exception.
Args:
archive (PathLike): Path to the archive.
game_path (PathLike, optional): Path to install the game to.
"""
@abstractmethod
def install_update_from_archive(
self, archive: PathLike, game_path: PathLike = None
) -> None:
"""
Install the update from an archive
Args:
archive (PathLike): Path to the archive
game_path (PathLike, optional): Path to the game. Defaults to None.
"""
pass
@abstractmethod
def get_version(self) -> tuple[int, int, int]:
"""
Get the game version
If the game is not installed, it'll return (0, 0, 0).
"""
pass
@abstractmethod
def get_update(self):
"""
Get the game update
"""
pass
@abstractmethod
def get_voiceover_update(self, language: str):
"""
Get the voiceover update
"""
pass
@abstractmethod
def get_channel(self):
"""
Get the game channel
"""
pass

View File

16
vollerei/abc/patcher.py Normal file
View File

@ -0,0 +1,16 @@
from abc import ABC, abstractmethod
from vollerei.abc.launcher.game import GameABC
class PatcherABC(ABC):
def __init__(self, *args, **kwargs):
pass
@abstractmethod
def patch_game(self, game: GameABC):
pass
@abstractmethod
def unpatch_game(self, game: GameABC):
pass

24
vollerei/constants.py Normal file
View File

@ -0,0 +1,24 @@
from platformdirs import PlatformDirs
# Common
telemetry_hosts = [
# Global
"log-upload-os.hoyoverse.com",
"sg-public-data-api.hoyoverse.com",
# China
"dump.gamesafe.qq.com",
"log-upload.mihoyo.com",
"public-data-api.mihoyo.com",
]
# HSR
astra_repo = "https://notabug.org/mkrsym1/astra"
jadeite_repo = "https://codeberg.org/mkrsym1/jadeite/"
hsr_latest_version = (1, 1, 0)
base_dirs = PlatformDirs("vollerei", "tretrauit", roaming=True)
tools_data_path = base_dirs.site_data_path.joinpath("tools")
tools_cache_path = base_dirs.site_cache_path.joinpath("tools")
tools_cache_path.mkdir(parents=True, exist_ok=True)
launcher_cache_path = base_dirs.site_cache_path.joinpath("launcher")
launcher_cache_path.mkdir(parents=True, exist_ok=True)

View File

@ -0,0 +1,4 @@
class VollereiError(Exception):
"""Base class for exceptions in this module."""
pass

View File

@ -0,0 +1,13 @@
from vollerei.exceptions import VollereiError
class GameError(VollereiError):
"""Base class for exceptions in related to the game installation."""
pass
class GameNotInstalledError(GameError):
"""Exception raised when the game is not installed."""
pass

View File

@ -0,0 +1,13 @@
from vollerei.exceptions import VollereiError
class PatcherError(VollereiError):
"""Base class for exceptions in related to the patcher."""
pass
class VersionNotSupportedError(PatcherError):
"""Exception raised when the game version is not supported."""
pass

View File

View File

View File

View File

View File

View File

View File

View File

0
vollerei/hsr/__init__.py Normal file
View File

View File

View File

@ -0,0 +1,17 @@
from os import PathLike
from pathlib import Path
from vollerei.abc.launcher.game import GameABC
class Game(GameABC):
def __init__(self, path: PathLike = None):
self.path: Path | None = Path(path) if path else None
def is_installed(self) -> bool:
if self.path is None:
return False
if (
not self.path.joinpath("StarRail.exe").exists()
or not self.path.joinpath("StarRailBase.dll").exists()
):
return False

View File

61
vollerei/hsr/patcher.py Normal file
View File

@ -0,0 +1,61 @@
from vollerei.abc.patcher import PatcherABC
from vollerei.exceptions.game import GameNotInstalledError
from vollerei.exceptions.patcher import VersionNotSupportedError
from vollerei.hsr.launcher.game import Game
from vollerei.utils.git import Git
from vollerei.constants import tools_data_path, astra_repo, jadeite_repo
from enum import Enum
class PatchType(Enum):
"""
Patch type
Astra: The old patch which patch the game directly (not recommended).
Jadeite: The new patch which patch the game in memory by DLL injection.
"""
Astra: int = 0
Jadeite: int = 1
class Patcher(PatcherABC):
def __init__(self, patch_type: PatchType = PatchType.Jadeite):
self._patch_type: PatchType = patch_type
self._path = tools_data_path.joinpath("patcher")
self._git = Git()
@property
def patch_type(self) -> PatchType:
return self._patch_type
@patch_type.setter
def patch_type(self, value: PatchType):
self._patch_type = value
def _update_astra(self):
self._git.pull_or_clone(astra_repo, self._path.joinpath("astra"))
def _update_jadeite(self):
self._git.pull_or_clone(jadeite_repo, self._path.joinpath("jadeite"))
def update_patch(self):
match self._patch_type:
case PatchType.Astra:
self._update_astra()
case PatchType.Jadeite:
self._update_jadeite()
def _patch_astra(self, game: Game):
if game.get_version() != (1, 0, 5):
raise VersionNotSupportedError(
"Only version 1.0.5 is supported by Astra patch."
)
def _patch_jadeite(self, game: Game):
pass
def patch_game(self, game: Game):
if not game.is_installed():
raise GameNotInstalledError("Game is not installed")

View File

@ -0,0 +1,45 @@
import subprocess
from pathlib import Path
from shutil import which
from vollerei.utils.git.exceptions import GitCloneError, GitNotInstalled
class Git:
"""
Quick wrapper around git binary
"""
def __init__(self) -> None:
pass
@staticmethod
def check_git():
"""
Check for git installation, if not found raise GitNotInstalled
"""
if not which("git"):
raise GitNotInstalled("git is not installed")
def pull_or_clone(self, url: str, path: str = None) -> None:
self.check_git()
"""
Pulls or clones a git repository
If the repository already exists and the url matches, it'll be pulled.
"""
if path is None:
path = Path.cwd().joinpath(Path(url).stem)
try:
origin_url = subprocess.check_output(
["git", "config", "--get", "remote.origin.url"], cwd=path
).decode()
if origin_url != url:
raise subprocess.CalledProcessError
subprocess.check_call(["git", "pull"], cwd=path)
except subprocess.CalledProcessError:
try:
subprocess.check_call(["git", "clone", url, path])
except subprocess.CalledProcessError as e:
raise GitCloneError(
f"Failed to clone or update repository {url} to {path}"
) from e

View File

@ -0,0 +1,22 @@
class GitError(Exception):
"""Base class for git errors"""
pass
class GitCloneError(GitError):
"""Raised when git clone fails"""
pass
class GitPullError(GitError):
"""Raised when git pull fails"""
pass
class GitNotInstalled(GitError):
"""Raised when git is not installed"""
pass

View File

View File

@ -0,0 +1,81 @@
import platform
import subprocess
import requests
from os import PathLike
from zipfile import ZipFile
from shutil import which
from vollerei.constants import tools_cache_path
from vollerei.utils.xdelta3.exceptions import (
Xdelta3NotInstalledError,
Xdelta3PatchError,
)
class Xdelta3:
"""
Quick wrapper around xdelta3 binary
"""
def __init__(self) -> None:
self._xdelta3_path = tools_cache_path.joinpath("xdelta3")
self._xdelta3_path.mkdir(parents=True, exist_ok=True)
def _get_binary(self, recurse=None) -> str:
if which("xdelta3"):
return "xdelta3"
if platform.system() == "Windows":
for path in self._xdelta3_path.glob("*.exe"):
return path
if recurse is None:
recurse = 3
elif recurse == 0:
raise Xdelta3NotInstalledError(
"xdelta3 is not installed and can't be automatically installed"
)
else:
recurse -= 1
self.download()
return self.get_binary(recurse=recurse)
raise Xdelta3NotInstalledError("xdelta3 is not installed")
def get_binary(self) -> str:
"""
Get xdelta3 binary
"""
return self._get_binary()
def download(self):
"""
Download xdelta3 binary
"""
url = None
if platform.system() != "Windows":
raise NotImplementedError(
"xdelta3 binary is not available for this platform, please install it manually" # noqa: E501
)
match platform.machine():
case "AMD64":
url = "https://github.com/jmacd/xdelta-gpl/releases/download/v3.1.0/xdelta3-3.1.0-x86_64.exe.zip"
case "i386":
url = "https://github.com/jmacd/xdelta-gpl/releases/download/v3.1.0/xdelta3-3.1.0-i686.exe.zip"
case "i686":
url = "https://github.com/jmacd/xdelta-gpl/releases/download/v3.1.0/xdelta3-3.1.0-i686.exe.zip"
with requests.get(url, stream=True) as r:
with open(self._xdelta3_path.joinpath("xdelta3.zip"), "wb") as f:
for chunk in r.iter_content(chunk_size=32768):
f.write(chunk)
with ZipFile(self._xdelta3_path.joinpath("xdelta3.zip")) as z:
z.extractall(self._xdelta3_path)
def patch_file(self, patch: PathLike, target: PathLike, output: PathLike):
"""
Patch a file
"""
try:
subprocess.check_call(
[self.get_binary(), "-d", "-s", patch, target, output]
)
except subprocess.CalledProcessError as e:
raise Xdelta3PatchError(
f"xdelta3 failed with exit code {e.returncode}"
) from e

View File

@ -0,0 +1,16 @@
class Xdelta3Error(Exception):
"""Base class for xdelta3 errors"""
pass
class Xdelta3NotInstalledError(Xdelta3Error):
"""Raised when xdelta3 is not installed"""
pass
class Xdelta3PatchError(Xdelta3Error):
"""Raised when xdelta3 patch fails"""
pass