diff --git a/src/s_sound.c b/src/s_sound.c index e614f929..00f0eadd 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -718,16 +718,9 @@ void S_ChangeMusic(int musicnum, int looping) // load & register it music->data = W_CacheLumpNum(music->lumpnum, PU_STATIC); - if (extra_music && trakinfo_found) + if (extra_music) { - const char *extra = - S_GetExtra(music->data, W_LumpLength(music->lumpnum), extra_music); - if (extra) - { - music->lumpnum = W_GetNumForName(extra); - Z_Free(music->data); - music->data = W_CacheLumpNum(music->lumpnum, PU_STATIC); - } + S_GetExtra(music, extra_music); } // julian: added lump length music->handle = I_RegisterSong(music->data, W_LumpLength(music->lumpnum)); @@ -782,16 +775,9 @@ void S_ChangeMusInfoMusic(int lumpnum, int looping) music->lumpnum = lumpnum; music->data = W_CacheLumpNum(music->lumpnum, PU_STATIC); - if (extra_music && trakinfo_found) + if (extra_music) { - const char *extra = - S_GetExtra(music->data, W_LumpLength(music->lumpnum), extra_music); - if (extra) - { - music->lumpnum = W_GetNumForName(extra); - Z_Free(music->data); - music->data = W_CacheLumpNum(music->lumpnum, PU_STATIC); - } + S_GetExtra(music, extra_music); } music->handle = I_RegisterSong(music->data, W_LumpLength(music->lumpnum)); diff --git a/src/s_trakinfo.c b/src/s_trakinfo.c index bb9c14b9..da79769c 100644 --- a/src/s_trakinfo.c +++ b/src/s_trakinfo.c @@ -21,6 +21,8 @@ #include "m_json.h" #include "m_misc.h" #include "sha1.h" +#include "sounds.h" +#include "w_wad.h" boolean trakinfo_found; @@ -70,15 +72,21 @@ void S_ParseTrakInfo(int lumpnum) trakinfo_found = true; } -const char *S_GetExtra(byte *data, int length, extra_music_t type) +void S_GetExtra(musicinfo_t *music, extra_music_t type) { + if (!trakinfo_found) + { + return; + } + sha1_context_t sha1_context; sha1_digest_t digest; SHA1_Init(&sha1_context); - SHA1_Update(&sha1_context, data, length); + SHA1_Update(&sha1_context, music->data, W_LumpLength(music->lumpnum)); SHA1_Final(digest, &sha1_context); + const char *extra = NULL; trakinfo_t *trak; array_foreach(trak, trakinfo) { @@ -86,13 +94,28 @@ const char *S_GetExtra(byte *data, int length, extra_music_t type) { if (type == EXMUS_REMIX) { - return trak->remix; + extra = trak->remix; } else { - return trak->midi; + extra = trak->midi; } + break; } } - return NULL; + if (!extra) + { + I_Printf(VB_DEBUG, "TRAKINFO: extra track is not found"); + return; + } + + int lumpnum = W_GetNumForName(extra); + if (lumpnum < 0) + { + I_Printf(VB_ERROR, "TRAKINFO: lump '%s' is not found", extra); + return; + } + music->lumpnum = lumpnum; + Z_Free(music->data); + music->data = W_CacheLumpNum(music->lumpnum, PU_STATIC); } diff --git a/src/s_trakinfo.h b/src/s_trakinfo.h index 8557f2a1..fed73135 100644 --- a/src/s_trakinfo.h +++ b/src/s_trakinfo.h @@ -27,6 +27,8 @@ typedef enum EXMUS_ORIGINAL } extra_music_t; -const char *S_GetExtra(byte *data, int length, extra_music_t type); +struct musicinfo_s; + +void S_GetExtra(struct musicinfo_s *music, extra_music_t type); #endif diff --git a/src/sounds.h b/src/sounds.h index c3155d93..ca418d15 100644 --- a/src/sounds.h +++ b/src/sounds.h @@ -81,7 +81,8 @@ typedef struct sfxinfo_s // MusicInfo struct. // -typedef struct { +typedef struct musicinfo_s +{ // up to 6-character name char *name;