From c2ae0ceab39f34b24c0a48175890e5214bdbd6a7 Mon Sep 17 00:00:00 2001 From: HENDRIX-ZT2 <28632661+HENDRIX-ZT2@users.noreply.github.com> Date: Wed, 20 Nov 2024 17:38:59 +0100 Subject: [PATCH] texel - calc aux hash for PC2 --- __init__.py | 2 +- __version__.py | 6 +++--- modules/formats/DDS.py | 19 +++++++++++++++++++ modules/formats/shared.py | 23 +++++++++++++++++++++++ pyproject.toml | 2 +- 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/__init__.py b/__init__.py index 04ec94555..667ae896e 100644 --- a/__init__.py +++ b/__init__.py @@ -3,7 +3,7 @@ "name": "Frontier's Cobra Engine Formats", "author": "Harlequinz Ego, HENDRIX et al.", "blender": (4, 0, 0), - "version": (2024, 11, 18), + "version": (2024, 11, 19), "location": "File > Import-Export", "description": "Import-Export models, skeletons and animations", "warning": "", diff --git a/__version__.py b/__version__.py index 74e8213a0..d18780aed 100644 --- a/__version__.py +++ b/__version__.py @@ -1,4 +1,4 @@ # this file is auto-generated by the pre-commit hook increment_version.py -VERSION = "2024.11.18" -COMMIT_HASH = "986059478" -COMMIT_TIME = "Mon Nov 18 16:49:32 2024 +0100" +VERSION = "2024.11.19" +COMMIT_HASH = "deac0d086" +COMMIT_TIME = "Tue Nov 19 17:06:41 2024 +0100" diff --git a/modules/formats/DDS.py b/modules/formats/DDS.py index 4f3374f22..bff193cb4 100644 --- a/modules/formats/DDS.py +++ b/modules/formats/DDS.py @@ -9,6 +9,7 @@ from generated.formats.tex.compounds.TexHeader import TexHeader from generated.formats.tex.compounds.TexturestreamHeader import TexturestreamHeader from modules.formats.BaseFormat import MemStructLoader, BaseFile +from modules.formats.shared import fnv64, encode_int64_base32 from ovl_util import texconv, imarray @@ -388,3 +389,21 @@ def get_tiles(self, size_info): class TexelLoader(BaseFile): extension = ".texel" + def get_aux_path(self, aux_suffix): + """Get path of aux file from ovl name and texel name""" + # Full Archive path: + # Win64\ovldata\Content0\Worlds\DefaultSandbox.ovl + # File in Archive: + # /zz159oeel9rhs8ex.texel + # File in tex header: + # zz159oeel9rhs8ex + # Input Text + # text = b"defaultsandbox_/zz159oeel9rhs8ex_texel" + # Resulting Lookup: + # XERY2OUE5ECDC_.aux + # Result: + # XERY2OUE5ECDC + assert not aux_suffix + text = f"{self.ovl.basename}_{self.name.replace('.', '_')}".lower().encode() + hash_value = fnv64(text) + return os.path.join(self.ovl.dir, f"{encode_int64_base32(hash_value)}_.aux") diff --git a/modules/formats/shared.py b/modules/formats/shared.py index cc70c378c..4555098d7 100644 --- a/modules/formats/shared.py +++ b/modules/formats/shared.py @@ -1,6 +1,7 @@ import contextlib import functools import logging +import os import struct import time @@ -28,6 +29,28 @@ def djb2(s): return n & 0xFFFFFFFF +def fnv64(data): + hash_ = 0xcbf29ce484222325 + for b in data: + hash_ *= 0x100000001b3 + hash_ &= 0xffffffffffffffff + hash_ ^= b + return hash_ + + +def encode_int64_base32(integer, charset="ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"): + """Encodes a 64-bit integer into a base32 string with a custom charset.""" + encoded = "" + while integer > 0: + index = integer & 0x1F + encoded += charset[index] + integer >>= 5 + + return encoded + + + + def fmt_hash(id_hash): return "".join([f"{b:02X}" for b in struct.pack("