harbor run -t openthoughts/tasktrove-mix-h10-reward-binary-v2-mix-h10-binary-0227harbor download openthoughts/tasktrove-mix-h10-reward-binary-v2-mix-h10-binary-0227solution file
from __future__ import annotations
import json
from pathlib import Path
from typing import TYPE_CHECKING, Any, cast
import UnityPy # type: ignore[import]
from src.story_deserializer import deserialize_story
from ..config import BundleType, Config
from ..protocols import Extractable
if TYPE_CHECKING:
from ..asset_bundle import AssetBundle
class BundleFile(Extractable):
__slots__ = (
"_parent_path",
"_object",
"_type",
"_data",
"image",
"script",
"container",
"_asset_name",
)
def __init__(
self, pcr_file: AssetBundle, obj: UnityPy.environment.ObjectReader
) -> None:
self._parent_path: Path = pcr_file.path.parent.parent
self._object: UnityPy.environment.ObjectReader | None = obj
self._type: BundleType = BundleType(obj.type.name)
self._data: Any = None
self.image: Any = None
self.script: Any = None
self.container: str | None = None
self._asset_name: str | None = None
# for Protocol
self._name = self.name
self._path = self.path
self._size = self.size
@property
def parent_path(self) -> Path:
return self._parent_path
@property
def type(self) -> BundleType:
return self._type
@property
def data(self) -> Any:
if self._data is None and self._object:
self._data = self._object.read()
self._object = None
return self._data
@property
def extention(self) -> str:
if self.is_image:
return Config().image_format
if self.is_text:
if "storydata" in self._asset_name:
return ".json"
return ".txt"
return ""
@property
def name(self) -> str:
if self._asset_name is None and self.data:
self._asset_name = self.data.name
if self._asset_name:
return self._asset_name + self.extention
else:
raise Exception("Name cannot be None.")
@property
def size(self) -> int:
return 0
@property
def path(self) -> Path:
if self.data:
self.container = cast(str | None, self.data.container)
if self.container:
str_path = self.container.replace(
"assets/_elementsresources/resources", "a"
)
return Path(str_path).parent / self.name
else:
return self._parent_path / self.name
@property
def is_image(self) -> bool:
return self.type in [BundleType.
Complete the code above, taking into account the cross-file context provided. Your solution must work correctly with the related files in the project.
Place your complete solution in /app/solution.py