Added support for updating game & applying voiceover packs

Implemented & Improved some CLI commands.
Currently working in 2.5.0 version.

A few more work and this should be fully usable,,,
This commit is contained in:
2022-02-17 02:43:21 +07:00
parent da3ee30ab1
commit b1a9223c19
4 changed files with 197 additions and 23 deletions

View File

@ -1,15 +1,17 @@
import asyncio
import tarfile
import constants
import appdirs
import aiofiles
from pathlib import Path
import shutil
import aiohttp
import asyncio
from worthless import constants
from worthless.launcher import Launcher
from worthless.installer import Installer
class Patcher:
def __init__(self, gamedir=Path.cwd(), data_dir: str | Path = None, patch_url: str = None):
def __init__(self, gamedir=Path.cwd(), data_dir: str | Path = None, patch_url: str = None, overseas=True):
self._gamedir = gamedir
self._patch_url = (patch_url if patch_url else constants.PATCH_GIT_URL).replace('http://', 'https://')
if not data_dir:
@ -21,6 +23,8 @@ class Patcher:
data_dir = Path(data_dir)
self._patch_path = data_dir.joinpath("Patch")
self._temp_path = data_dir.joinpath("Temp/Patcher")
self._installer = Installer(self._gamedir, overseas=overseas, data_dir=self._temp_path)
self._launcher = Launcher(self._gamedir, overseas=overseas)
@staticmethod
async def _get(url, **kwargs) -> aiohttp.ClientResponse:
@ -96,10 +100,42 @@ class Patcher:
"""
pass
def revert_patch(self):
def _revert_file(self, original_file: str, base_file: Path, ignore_error=False):
original_path = self._gamedir.joinpath(original_file + ".bak").resolve()
target_file = self._gamedir.joinpath(original_file).resolve()
if original_path.exists():
if abs(base_file.stat().st_mtime_ns - original_path.stat().st_mtime_ns) > 3600:
if not ignore_error:
raise RuntimeError("{} is not for this game version.".format(original_path.name))
original_path.unlink(missing_ok=True)
else:
target_file.unlink(missing_ok=True)
original_path.rename(target_file)
def revert_patch(self, ignore_errors=True) -> None:
"""
Revert the patch (and revert the login door crash fix if patched)
:return: None
"""
pass
game_exec = self._gamedir.joinpath(asyncio.run(self._launcher.get_resource_info()).game.latest.entry)
revert_files = [
"UnityPlayer.dll",
self._installer.get_game_data_name() + "upload_crash.exe",
self._installer.get_game_data_name() + "Plugins/crashreport.exe",
self._installer.get_game_data_name() + "Plugins/xlua.dll",
]
for file in revert_files:
self._revert_file(file, game_exec, ignore_errors)
self._gamedir.joinpath("launcher.bat").unlink(missing_ok=True)
self._gamedir.joinpath("mhyprot2_running.reg").unlink(missing_ok=True)
def get_files(extensions):
all_files = []
for ext in extensions:
all_files.extend(self._gamedir.glob(ext))
return all_files
files = get_files(('*.dxvk-cache', '*_d3d9.log', '*_d3d11.log', '*_dxgi.log'))
for file in files:
file.unlink(missing_ok=True)