Skip to content

Commit

Permalink
attempt adding tw
Browse files Browse the repository at this point in the history
  • Loading branch information
thesadru committed Sep 25, 2024
1 parent 0e555f1 commit 8ae5fb1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
23 changes: 13 additions & 10 deletions arkprts/assets/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import io
import json
import logging
import os
import pathlib
import re
import shlex
Expand All @@ -33,7 +32,7 @@
UnityPyAsset = typing.Any
UnityPyObject = typing.Any

UPDATED_FBS = {"cn": False, "yostar": False}
UPDATED_FBS = {"cn": False, "yostar": False, "tw": False}


def asset_path_to_server_filename(path: str) -> str:
Expand Down Expand Up @@ -124,16 +123,14 @@ def run_flatbuffers(
return pathlib.Path(output_directory) / (pathlib.Path(fbs_path).stem + ".json")


def resolve_fbs_schema_directory(server: typing.Literal["cn", "yostar"]) -> pathlib.Path:
def resolve_fbs_schema_directory(server: typing.Literal["cn", "yostar", "tw"]) -> pathlib.Path:
"""Resolve the flatbuffers schema directory."""
path = os.environ.get(f"FLATBUFFERS_SCHEMA_DIR_{server.upper()}")
if path:
return pathlib.Path(path)
if server == "tw":
return netn.APPDATA_DIR / "ArknightsFlatbuffers" / "tw"

core_path = netn.APPDATA_DIR / "ArknightsFBS"
core_path.mkdir(parents=True, exist_ok=True)
path = core_path / server / "OpenArknightsFBS" / "FBS"
os.environ[f"FLATBUFFERS_SCHEMA_DIR_{server.upper()}"] = str(path)
return path


Expand All @@ -147,6 +144,12 @@ async def update_fbs_schema(*, force: bool = False) -> None:
directory = resolve_fbs_schema_directory(server).parent # pyright: ignore[reportArgumentType]
await git.download_repository("MooncellWiki/OpenArknightsFBS", directory, branch=branch, force=force)

if not UPDATED_FBS["tw"] or force:
UPDATED_FBS["tw"] = True
await git.download_repository(
"ArknightsAssets/ArknightsFlatbuffers", netn.APPDATA_DIR / "ArknightsFlatbuffers", force=force,
)


def recursively_collapse_keys(obj: typing.Any) -> typing.Any:
"""Recursively collapse arknights flatc dictionaries."""
Expand Down Expand Up @@ -181,9 +184,9 @@ def decrypt_fbs_file(

fbs_path = tempdir / (table_name + ".bytes")
fbs_path.write_bytes(data)
fbs_schema_path = resolve_fbs_schema_directory(server="cn" if server in ("cn", "bili") else "yostar") / (
table_name + ".fbs"
)
fbs_schema_path = resolve_fbs_schema_directory(
server="cn" if server in ("cn", "bili") else "tw" if server == "tw" else "yostar",
) / (table_name + ".fbs")
output_directory = tempdir / "output"

output_path = run_flatbuffers(fbs_path, fbs_schema_path, output_directory)
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
package_data={"arkprts": ["py.typed"]},
install_requires=["aiohttp", "pydantic==2.*"],
extras_require={
"all": ["rsa", "pycryptodome", "UnityPy", "bson"],
"all": ["rsa", "pycryptodome", "UnityPy==1.10.18", "bson"],
"rsa": ["rsa"],
"aes": ["pycryptodome"],
"assets": ["UnityPy", "pycryptodome", "bson"],
"assets": ["UnityPy==1.10.18", "pycryptodome", "bson"],
},
long_description=pathlib.Path("README.md").read_text(encoding="utf-8"),
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 8ae5fb1

Please sign in to comment.