Replace old non-deterministic hash method with a deterministic one (Et tu, Brute python3?)

This commit is contained in:
LoafyLemon 2024-09-05 10:00:09 +01:00
parent 0630997a99
commit 791457c884
11 changed files with 14 additions and 10 deletions

View File

@ -23,7 +23,7 @@ init python:
def generate_hash(self):
bodyparts_hash = str([x[0]._hash for x in self.char.states.values() if istype(x[0], DollBodypart) and x[2]])
salt = str( [self.char.name, self.char.pose, str(self.matrix.__hash__()), bodyparts_hash])
return hash(salt)
return hashstring(salt)
@functools.cache
def get_layers(self, hash):

View File

@ -16,7 +16,7 @@ init 1 python:
def generate_hash(self):
salt = str( [self.name, self.type, self.char.pose, self.id, str(self.char.body._hash)] )
return hash(salt)
return hashstring(salt)
@functools.cache
def get_layers(self, hash, subpath=""):

View File

@ -67,7 +67,7 @@ init python:
def generate_hash(self):
salt = str( [self.name, self.char.pose, self.type, self.id, str(self.color), str(self.char.body._hash)] )
return hash(salt)
return hashstring(salt)
@functools.cache # <- TODO: Reevaluate if this function should allow multiple caches (aside from different subpaths)
def get_layers(self, hash, subpath=""):

View File

@ -30,7 +30,7 @@ init python:
tracking_object = self.tracking_object
tracking_hash = str(tracking_object._hash) if tracking_object else "default"
salt = str( [self.name, self.char.pose, self.type, self.id, str(self.color), str(self.char.body._hash)] ) + tracking_hash
return hash(salt)
return hashstring(salt)
@functools.cache
def get_layers(self, hash, subpath="", _ignore_equipped=False):

View File

@ -21,7 +21,7 @@ init python:
def generate_hash(self):
salt = str( [self.char.name, self.char.pose, str(self.char.face._hash), str(self.char.face._hash), str([x[0]._hash for x in self.char.states.values() if x[0] and x[2]]), sorted(list(self._cum.items()))] )
return hash(salt)
return hashstring(salt)
def set_cum(self, *args, **kwargs):
if args:

View File

@ -25,7 +25,7 @@ init python:
def generate_hash(self):
salt = str( [self.char.name, self.char.pose, str(self.char.body._hash), sorted(list(self._face.items()))] )
return hash(salt)
return hashstring(salt)
@functools.cache
def get_layers(self, hash, subpath=""):

View File

@ -86,7 +86,7 @@ init python:
def generate_hash(self):
clothes_hash = str([x[0]._hash for x in self.states.values() if istype(x[0], (DollCloth, DollClothDynamic, DollMakeup)) and x[2]])
salt = str( [self.name, self.pose, str(self.body._hash), str(self.face._hash), str(self.cum._hash), clothes_hash] )
return hash(salt)
return hashstring(salt)
def show(self, force=False, ignore_skipping=False):
if renpy.get_screen(("wardrobe", "animatedCG", "studio")) or renpy.showing("cg"):

View File

@ -10,7 +10,7 @@ init python:
def generate_hash(self):
salt = str( [self.name, self.type, self.char.pose, self.id, str(self.color), str(self.char.face._hash), str(self.char.body._hash)] )
return hash(salt)
return hashstring(salt)
@functools.cache
def get_layers(self, hash, subpath=""):

View File

@ -38,7 +38,7 @@ init python:
def generate_hash(self):
salt = str( [x._hash for x in self.group] ) + str(self.schedule)
return hash(salt)
return hashstring(salt)
def delete(self):
if self in self.char.outfits:

View File

@ -51,7 +51,7 @@ init -1 python:
self.action, self.hovered, self.unhovered, self.tooltip, self.decoration, self.zorder, self.hidden, self.overlay]
)
return hash(salt)
return hashstring(salt)
def set_image(self, idle, hover=None):
self.idle = idle

View File

@ -10,11 +10,15 @@ init python early:
import re
import functools
import timeit as timeit_module
import hashlib
from operator import itemgetter
from collections import OrderedDict
get_volume_preference = renpy.game.preferences.get_volume
def hashstring(input_string):
return int(hashlib.md5(input_string.encode("utf-8")).hexdigest(), 16)
def num_to_word(n, readable=True):
"""Transcript numbers (integers) into readable words."""
n = int(n)