From 837efcea369467bf69c98e9d7cc5d0e57ad43c64 Mon Sep 17 00:00:00 2001
From: AppleHair <95587502+AppleHair@users.noreply.github.com>
Date: Mon, 10 Jun 2024 19:42:27 +0300
Subject: [PATCH] [BUGFIX] Made freeplay use the metadata to get the
 instrumental suffix

Song previews in freeplay will now use the instrumental suffix from the current difficulty's corresponding song variation metadata instead of using the variation id as an instrumental suffix and checking only the "erect" variation.
---
 source/funkin/ui/freeplay/FreeplayState.hx | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/source/funkin/ui/freeplay/FreeplayState.hx b/source/funkin/ui/freeplay/FreeplayState.hx
index 3b003cf89..92410622f 100644
--- a/source/funkin/ui/freeplay/FreeplayState.hx
+++ b/source/funkin/ui/freeplay/FreeplayState.hx
@@ -1882,7 +1882,10 @@ class FreeplayState extends MusicBeatSubState
     }
     else
     {
-      var potentiallyErect:String = (currentDifficulty == "erect") || (currentDifficulty == "nightmare") ? "-erect" : "";
+      var previewSong:Null<Song> = SongRegistry.instance.fetchEntry(daSongCapsule.songData.songId);
+      var instSuffix:String = previewSong?.getDifficulty(currentDifficulty,
+        previewSong?.variations ?? Constants.DEFAULT_VARIATION_LIST)?.characters?.instrumental ?? '';
+      instSuffix = (instSuffix != '') ? '-$instSuffix' : '';
       FunkinSound.playMusic(daSongCapsule.songData.songId,
         {
           startingVolume: 0.0,
@@ -1890,7 +1893,7 @@ class FreeplayState extends MusicBeatSubState
           restartTrack: false,
           mapTimeChanges: false, // The music metadata is not alongside the audio file so this won't work.
           pathsFunction: INST,
-          suffix: potentiallyErect,
+          suffix: instSuffix,
           partialParams:
             {
               loadPartial: true,