Skip to content

Commit

Permalink
Support compiling CRCAdapter with unsafe for building
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquegemignani committed Jul 13, 2024
1 parent dc45bec commit dbfd352
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/mercury_engine_data_structures/formats/property_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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)
Expand Down

0 comments on commit dbfd352

Please sign in to comment.