Skip to content

Commit

Permalink
Replace namehash function with correct jenkins function
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyman192 committed Apr 2, 2024
1 parent 45a41be commit e40a803
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ModelImporter/import_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ def _add_empty_to_scene(self, scene_node: SceneNodeData,
j = 3 - empty_obj.NMSReference_props.num_lods
for _ in range(j):
lods.append(0)
empty_obj.NMSReference_props.lod_levels = lods
empty_obj.NMSReference_props.lod_levels = lods[:3]
empty_obj.NMSReference_props.has_lods = True

# Add a custom property so that if it is exported with the
Expand Down
18 changes: 14 additions & 4 deletions NMS/classes/Object.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# as child objects.

from typing import Optional
from zlib import crc32

from .TkSceneNodeData import TkSceneNodeData
from .TkSceneNodeAttributeData import TkSceneNodeAttributeData
Expand All @@ -16,6 +15,19 @@
TYPES = ['MESH', 'LOCATOR', 'COLLISION', 'MODEL', 'REFERENCE']


def jenkins_one_at_a_time(data: str) -> int:
# https://en.wikipedia.org/wiki/Jenkins_hash_function#one_at_a_time
hash = 0
for char in data.upper():
hash = (hash + ord(char)) & 0xFFFFFFFF
hash = (hash + (hash << 10)) & 0xFFFFFFFF
hash = (hash ^ (hash >> 6)) & 0xFFFFFFFF
hash = (hash + (hash << 3)) & 0xFFFFFFFF
hash = (hash ^ (hash >> 11)) & 0xFFFFFFFF
hash = (hash + (hash << 15)) & 0xFFFFFFFF
return hash


class Object():
""" Structure:
TkSceneNodeData:
Expand Down Expand Up @@ -219,9 +231,7 @@ def NameHash(self) -> int:
orig_name_hash = self.orig_node_data.get('NameHash', None)
if orig_name_hash:
return orig_name_hash
byte_name = bytes(self.Name, encoding='utf-8')
# do bit operation to ensure it's always unsigned
return crc32(byte_name) & 0xFFFFFFFF
return jenkins_one_at_a_time(self.Name)


class Locator(Object):
Expand Down
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bl_info = {
"name": "No Man's Sky Development Kit",
"author": "gregkwaste, monkeyman192",
"version": (0, 9, 25),
"version": (0, 9, "26a"),
"blender": (4, 0, 0),
"location": "File > Export/Import",
"description": "Create NMS scene structures and export to NMS File format",
Expand Down

0 comments on commit e40a803

Please sign in to comment.