From dbfd3522e3d6703ca4baa12a6e161e6aa3deebfb Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Sat, 13 Jul 2024 15:51:00 +0300 Subject: [PATCH] Support compiling CRCAdapter with unsafe for building --- .../formats/property_enum.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/mercury_engine_data_structures/formats/property_enum.py b/src/mercury_engine_data_structures/formats/property_enum.py index 6725389e..47ba5f6d 100644 --- a/src/mercury_engine_data_structures/formats/property_enum.py +++ b/src/mercury_engine_data_structures/formats/property_enum.py @@ -108,9 +108,6 @@ def _parse_hashset_{n}(io, this): return f"_inverted_hashes_{n}[_parse_hashset_{n}(io, this)]" def _emitbuild(self, code: construct.CodeGen): - if self.allow_unknowns: - raise NotImplementedError - n = self.hash_set.name code.append("from mercury_engine_data_structures.formats.property_enum import HashSet") @@ -123,7 +120,17 @@ def _build_hashset_{n}(obj, io, this): def _build_hashset_{n}(obj, io, this): return {construct.Int32ul._compilebuild(code)} """) - return f"(_build_hashset_{n}(_known_hashes_{n}[obj], io, this), obj)[1]" + if self.allow_unknowns: + code.append(f""" + def _hash_{n}(obj): + result = _known_hashes_{n}.get(obj) + if result is None: + result = TARGET_GAME.hash_asset(obj) + return result + """) + return f"(_build_hashset_{n}(obj if isinstance(obj, int) else _hash_{n}(obj), io, this), obj)[1]" + else: + return f"(_build_hashset_{n}(_known_hashes_{n}[obj], io, this), obj)[1]" PropertyEnum = CRCAdapter(HashSet.PROPERTY)