Add a suffix of a stable hash of the original filename to texture paths.

This commit is contained in:
Ottermandias 2022-12-29 21:11:38 +01:00
parent 5b3d5d1e67
commit cc55ebb28f
2 changed files with 23 additions and 0 deletions

View file

@ -144,6 +144,7 @@ public static class CustomizationSwap
var newPath = ReplaceAnyRace( path, race );
newPath = ReplaceAnyBody( newPath, slot, idFrom );
newPath = AddSuffix( newPath, ".tex", $"_{Path.GetFileName(texture.Path).GetStableHashCode():x8}", true );
if( newPath != path )
{
texture.Path = addedDashes ? newPath.Replace( "--", string.Empty ) : newPath;

View file

@ -109,4 +109,26 @@ public static class ItemSwap
file = null;
return false;
}
public static int GetStableHashCode( this string str )
{
unchecked
{
var hash1 = 5381;
var hash2 = hash1;
for( var i = 0; i < str.Length && str[ i ] != '\0'; i += 2 )
{
hash1 = ( ( hash1 << 5 ) + hash1 ) ^ str[ i ];
if( i == str.Length - 1 || str[ i + 1 ] == '\0' )
{
break;
}
hash2 = ( ( hash2 << 5 ) + hash2 ) ^ str[ i + 1 ];
}
return hash1 + hash2 * 1566083941;
}
}
}