Skip to content

Commit

Permalink
texel - calc aux hash for PC2
Browse files Browse the repository at this point in the history
  • Loading branch information
HENDRIX-ZT2 committed Nov 20, 2024
1 parent deac0d0 commit c2ae0ce
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
6 changes: 3 additions & 3 deletions __version__.py
Original file line number Diff line number Diff line change
@@ -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"
19 changes: 19 additions & 0 deletions modules/formats/DDS.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
23 changes: 23 additions & 0 deletions modules/formats/shared.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import contextlib
import functools
import logging
import os
import struct
import time

Expand Down Expand Up @@ -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("<I", id_hash)])

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "cobra-tools"
version = "2024.11.18"
version = "2024.11.19"
readme = "README.md"
license = { file = "LICENSE" }
requires-python = "==3.11.*"
Expand Down

0 comments on commit c2ae0ce

Please sign in to comment.