improve track selection entropy

This commit is contained in:
Nikita Vilunov 2024-10-28 22:40:39 +01:00
parent 89a41f9640
commit f274513bb5
1 changed files with 14 additions and 2 deletions

View File

@ -1,6 +1,8 @@
using System.Collections; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Cryptography;
using BepInEx; using BepInEx;
using HarmonyLib; using HarmonyLib;
using UnityEngine; using UnityEngine;
@ -129,7 +131,17 @@ namespace MuzikaGromche
{ {
// ...and start modded music // ...and start modded music
var seed = RoundManager.Instance.dungeonGenerator.Generator.ChosenSeed; 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"); Debug.Log($"Seed is {seed}, chosen track is {trackId} out of {Plugin.Tracks.Length} tracks");
Plugin.CurrentTrack = Plugin.Tracks[trackId]; Plugin.CurrentTrack = Plugin.Tracks[trackId];
__instance.popUpTimer = Plugin.CurrentTrack.WindUpTimer; __instance.popUpTimer = Plugin.CurrentTrack.WindUpTimer;