WIP game patcher
Now worthless can patch the game using xdelta3-python
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import asyncio
|
||||
import xdelta3
|
||||
import tarfile
|
||||
import appdirs
|
||||
from pathlib import Path
|
||||
@ -23,6 +23,7 @@ class Patcher:
|
||||
data_dir = Path(data_dir)
|
||||
self._patch_path = data_dir.joinpath("Patch")
|
||||
self._temp_path = data_dir.joinpath("Temp/Patcher")
|
||||
self._overseas = overseas
|
||||
self._installer = Installer(self._gamedir, overseas=overseas, data_dir=self._temp_path)
|
||||
self._launcher = Launcher(self._gamedir, overseas=overseas)
|
||||
|
||||
@ -56,7 +57,6 @@ class Patcher:
|
||||
pass
|
||||
else:
|
||||
return await archive.read()
|
||||
return
|
||||
|
||||
async def _download_repo(self):
|
||||
if shutil.which("git"):
|
||||
@ -91,14 +91,43 @@ class Patcher:
|
||||
"""
|
||||
await self._download_repo()
|
||||
|
||||
def _patch_unityplayer(self):
|
||||
if self._overseas:
|
||||
patch = "unityplayer_patch_os.vcdiff"
|
||||
else:
|
||||
patch = "unityplayer_patch_cn.vcdiff"
|
||||
gamever = "".join(self._installer.get_game_version().split("."))
|
||||
unity_path = self._gamedir.joinpath("UnityPlayer.dll")
|
||||
patch_bytes = self._patch_path.joinpath("{}/patch_files/{}".format(gamever, patch)).read_bytes()
|
||||
patched_unity_bytes = xdelta3.decode(unity_path.read_bytes(), patch_bytes)
|
||||
unity_path.rename(self._gamedir.joinpath("UnityPlayer.dll.bak"))
|
||||
with Path(self._gamedir.joinpath("UnityPlayer.dll")).open("wb") as f:
|
||||
f.write(patched_unity_bytes)
|
||||
|
||||
def _patch_xlua(self):
|
||||
patch = "xlua_patch.vcdiff"
|
||||
gamever = "".join(self._installer.get_game_version().split("."))
|
||||
data_name = self._installer.get_game_data_name()
|
||||
xlua_path = self._gamedir.joinpath("{}/Plugins/xlua.dll".format(data_name))
|
||||
patch_bytes = self._patch_path.joinpath("{}/patch_files/{}".format(gamever, patch)).read_bytes()
|
||||
patched_xlua_bytes = xdelta3.decode(xlua_path.read_bytes(), patch_bytes)
|
||||
xlua_path.rename(self._gamedir.joinpath("xlua.dll.bak"))
|
||||
with Path(self._gamedir.joinpath("{}/Plugins/xlua.dll".format(data_name)).open("wb") as f:
|
||||
f.write(patched_xlua_bytes)
|
||||
|
||||
def apply_xlua_patch(self):
|
||||
self._patch_xlua()
|
||||
|
||||
def apply_patch(self, crash_fix=False) -> None:
|
||||
"""
|
||||
Patch the game (and optionally patch the login door crash fix if specified)
|
||||
Patch the game (and optionally patch xLua if specified)
|
||||
|
||||
:param crash_fix: Whether to patch the login door crash fix or not
|
||||
:param crash_fix: Whether to patch xLua or not
|
||||
:return: None
|
||||
"""
|
||||
pass
|
||||
self._patch_unityplayer()
|
||||
if crash_fix:
|
||||
self._patch_xlua()
|
||||
|
||||
def _revert_file(self, original_file: str, base_file: Path, ignore_error=False):
|
||||
original_path = self._gamedir.joinpath(original_file + ".bak").resolve()
|
||||
|
||||
Reference in New Issue
Block a user