diff --git a/requirements.txt b/requirements.txt index c3a5a2a..2f5e4ee 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ aiohttp==3.8.1 appdirs~=1.4.4 aiopath~=0.6.10 -setuptools~=59.3.0 +setuptools==60.9.3 xdelta3~=0.0.5 \ No newline at end of file diff --git a/worthless/patcher.py b/worthless/patcher.py index a957542..dcd121d 100644 --- a/worthless/patcher.py +++ b/worthless/patcher.py @@ -93,6 +93,32 @@ class Patcher: """ await self._download_repo() + async def _patch_unityplayer_fallback(self): + # xdelta3-python doesn't work becuase it's outdated. + 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") + unity_path.rename(self._gamedir.joinpath("UnityPlayer.dll.bak")) + await asyncio.create_subprocess_exec("xdelta3", "-d", "-s", str(self._gamedir.joinpath("UnityPlayer.dll.bak")), + str(self._patch_path.joinpath("{}/patch_files/{}".format(gamever, patch))), + str(self._gamedir.joinpath("UnityPlayer.dll")), cwd=self._gamedir) + + async def _patch_xlua_fallback(self): + # xdelta3-python doesn't work becuase it's outdated. + 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)) + xlua_path.rename(self._gamedir.joinpath("{}/Plugins/xlua.dll.bak").format(data_name)) + await asyncio.create_subprocess_exec("xdelta3", "-d", "-s", + str(self._gamedir.joinpath("{}/Plugins/xlua.dll.bak".format(data_name))), + str(self._patch_path.joinpath("{}/patch_files/{}".format(gamever, patch))), + str(self._gamedir.joinpath("{}/Plugins/xlua.dll".format(data_name))), + cwd=self._gamedir) + def _patch_unityplayer(self): if self._overseas: patch = "unityplayer_patch_os.vcdiff" @@ -113,23 +139,30 @@ class Patcher: 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")) + xlua_path.rename(self._gamedir.joinpath("{}/Plugins/xlua.dll.bak".format(data_name))) 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): + def apply_xlua_patch(self, fallback=True): + if fallback: + asyncio.run(self._patch_xlua_fallback()) + return self._patch_xlua() - def apply_patch(self, crash_fix=False) -> None: + def apply_patch(self, crash_fix=False, fallback=True) -> None: """ Patch the game (and optionally patch xLua if specified) + :param fallback: :param crash_fix: Whether to patch xLua or not :return: None """ - self._patch_unityplayer() + if fallback: + asyncio.run(self._patch_unityplayer_fallback()) + else: + self._patch_unityplayer() if crash_fix: - self._patch_xlua() + self.apply_xlua_patch(fallback=fallback) def _revert_file(self, original_file: str, base_file: Path, ignore_error=False): original_path = self._gamedir.joinpath(original_file + ".bak").resolve()