From f274513bb58108697f846e9367cad63bca6b9fe5 Mon Sep 17 00:00:00 2001 From: Nikita Vilunov Date: Mon, 28 Oct 2024 22:40:39 +0100 Subject: [PATCH] improve track selection entropy --- MuzikaGromche/Plugin.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/MuzikaGromche/Plugin.cs b/MuzikaGromche/Plugin.cs index 254b847..b6de3df 100644 --- a/MuzikaGromche/Plugin.cs +++ b/MuzikaGromche/Plugin.cs @@ -1,6 +1,8 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Security.Cryptography; using BepInEx; using HarmonyLib; using UnityEngine; @@ -129,7 +131,17 @@ namespace MuzikaGromche { // ...and start modded music var seed = RoundManager.Instance.dungeonGenerator.Generator.ChosenSeed; - var trackId = seed % Plugin.Tracks.Length; + var sha = SHA256.Create(); + var hash = sha.ComputeHash(BitConverter.GetBytes(seed)); + var trackId = 0; + foreach (var t in hash) + { + // modulus division on byte array + trackId *= 256 % Plugin.Tracks.Length; + trackId %= Plugin.Tracks.Length; + trackId += t % Plugin.Tracks.Length; + trackId %= Plugin.Tracks.Length; + } Debug.Log($"Seed is {seed}, chosen track is {trackId} out of {Plugin.Tracks.Length} tracks"); Plugin.CurrentTrack = Plugin.Tracks[trackId]; __instance.popUpTimer = Plugin.CurrentTrack.WindUpTimer;