diff options
-rw-r--r-- | src/koopatlas/core.cpp | 14 | ||||
-rw-r--r-- | src/music.cpp | 42 |
2 files changed, 36 insertions, 20 deletions
diff --git a/src/koopatlas/core.cpp b/src/koopatlas/core.cpp index 317c86c..5734300 100644 --- a/src/koopatlas/core.cpp +++ b/src/koopatlas/core.cpp @@ -2,6 +2,7 @@ #include "koopatlas/camera.h" #include "koopatlas/player.h" #include "koopatlas/subplayer.h" +#include "music.h" extern "C" void LoadMapScene(); @@ -192,7 +193,11 @@ bool WMInit_LoadResources2(void *ptr) { OSReport("Load map: %s\n", wm->mapPath); } - return wm->mapData.load(wm->mapPath); + if (wm->mapData.load(wm->mapPath)) { + wm->playBGM(); + return true; + } else + return false; } bool WMInit_SetupWait(void *ptr) { @@ -302,8 +307,6 @@ bool WMInit_SetupWipe(void *ptr) { SpammyReport("WMInit_SetupWipe returning true\n"); - wm->playBGM(); - return true; } @@ -416,7 +419,6 @@ int dScKoopatlas_c::onCreate() { return true; } -u8 hijackMusicWithSongName(const char *songName, int themeID, bool hasFast, bool useDrums, int *wantRealStreamID); extern "C" void PlaySoundWithFunctionB4(void *spc, nw4r::snd::SoundHandle *handle, int id, int unk); void dScKoopatlas_c::playBGM() { @@ -442,11 +444,12 @@ void dScKoopatlas_c::playBGM() { int realStreamID; OSReport("I'm going to play %s!\n", cleanName); - hijackMusicWithSongName(cleanName, -1, false, false, &realStreamID); + hijackMusicWithSongName(cleanName, -1, false, 16, 8, &realStreamID); OSReport("Real Stream ID: %d\n", realStreamID); PlaySoundWithFunctionB4(SoundRelatedClass, &bgm, realStreamID, 1); currentBGMTrack = GetSaveFile()->GetBlock(-1)->currentMapMusic; + OSReport("Enabling track %d by setting bitfield 0x%x to volume 1.0f and bitfield 0x%x to volume 0.0f; both over 0 frames\n", currentBGMTrack, 1 << currentBGMTrack, 0xFF ^ (1 << currentBGMTrack)); bgm.SetTrackVolume(0xFF ^ (1 << currentBGMTrack), 0, 0.0f); bgm.SetTrackVolume(1 << currentBGMTrack, 0, 1.0f); } @@ -455,6 +458,7 @@ void dScKoopatlas_c::setBGMTrack(int trackID) { if (currentBGMTrack == trackID) return; + OSReport("Enabling track %d and disabling track %d by setting bitfield 0x%x to volume 1.0f and bitfield 0x%x to volume 0.0f; both over 30 frames\n", trackID, currentBGMTrack, 1 << trackID, 1 << currentBGMTrack); bgm.SetTrackVolume(1 << currentBGMTrack, 30, 0.0f); bgm.SetTrackVolume(1 << trackID, 30, 1.0f); currentBGMTrack = trackID; diff --git a/src/music.cpp b/src/music.cpp index f3089ca..5d8eab9 100644 --- a/src/music.cpp +++ b/src/music.cpp @@ -1,11 +1,13 @@ #include <game.h> #include <sfx.h> +#include "music.h" struct HijackedStream { //const char *original; //const char *originalFast; u32 stringOffset; u32 stringOffsetFast; + u32 infoOffset; u8 originalID; int streamID; }; @@ -100,16 +102,16 @@ const char* SongNameList [] = { Hijacker Hijackers[2] = { { { - {/*"athletic_lr.n.32.brstm", "athletic_fast_lr.n.32.brstm",*/ _I(0x4A8F8), _I(0x4A938), 4, STRM_BGM_ATHLETIC}, - {/*"BGM_SIRO.32.brstm", "BGM_SIRO_fast.32.brstm",*/ _I(0x4B2E8), _I(0x4B320), 10, STRM_BGM_SHIRO} + {/*"athletic_lr.n.32.brstm", "athletic_fast_lr.n.32.brstm",*/ _I(0x4A8F8), _I(0x4A938), _I(0x476C4), 4, STRM_BGM_ATHLETIC}, + {/*"BGM_SIRO.32.brstm", "BGM_SIRO_fast.32.brstm",*/ _I(0x4B2E8), _I(0x4B320), _I(0x48164), 10, STRM_BGM_SHIRO} }, 0, 0 }, { { - {/*"STRM_BGM_CHIJOU.brstm", "STRM_BGM_CHIJOU_FAST.brstm",*/ _I(0x4A83C), _I(0x4A8B4), 1, STRM_BGM_CHIJOU}, - {/*"STRM_BGM_CHIKA.brstm", "STRM_BGM_CHIKA_FAST.brstm",*/ _I(0x4A878), _I(0x4A780), 2, STRM_BGM_CHIKA}, + {/*"STRM_BGM_CHIJOU.brstm", "STRM_BGM_CHIJOU_FAST.brstm",*/ _I(0x4A83C), _I(0x4A8B4), 0, 1, STRM_BGM_CHIJOU}, + {/*"STRM_BGM_CHIKA.brstm", "STRM_BGM_CHIKA_FAST.brstm",*/ _I(0x4A878), _I(0x4A780), 0, 2, STRM_BGM_CHIKA}, }, 0, 0 } @@ -121,18 +123,9 @@ inline char *BrsarInfoOffset(u32 offset) { } void FixFilesize(u32 streamNameOffset); -u8 hijackMusicWithSongName(const char *songName, int themeID, bool hasFast, bool useDrums, int *wantRealStreamID); -extern "C" u8 after_course_getMusicForZone(u8 realThemeID) { - if (realThemeID < 100) - return realThemeID; - - bool usesDrums = (realThemeID >= 200); - return hijackMusicWithSongName(SongNameList[realThemeID-100], realThemeID, true, usesDrums, 0); -} - -u8 hijackMusicWithSongName(const char *songName, int themeID, bool hasFast, bool useDrums, int *wantRealStreamID) { - Hijacker *hj = &Hijackers[useDrums ? 1 : 0]; +u8 hijackMusicWithSongName(const char *songName, int themeID, bool hasFast, int channelCount, int trackCount, int *wantRealStreamID) { + Hijacker *hj = &Hijackers[channelCount==4?1:0]; // do we already have this theme in this slot? // if so, don't switch streams @@ -151,6 +144,15 @@ u8 hijackMusicWithSongName(const char *songName, int themeID, bool hasFast, bool // write the stream's info HijackedStream *stream = &hj->stream[hj->currentStream]; + if (stream->infoOffset) { + u16 *thing = (u16*)(BrsarInfoOffset(stream->infoOffset) + 4); + OSReport("Modifying stream info, at offset %x which is at pointer %x\n", stream->infoOffset, thing); + OSReport("It currently has: channel count %d, track bitfield 0x%x\n", thing[0], thing[1]); + thing[0] = channelCount; + thing[1] = (1 << trackCount) - 1; + OSReport("It has been set to: channel count %d, track bitfield 0x%x\n", thing[0], thing[1]); + } + sprintf(BrsarInfoOffset(stream->stringOffset), "new/%s.er", songName); sprintf(BrsarInfoOffset(stream->stringOffsetFast), hasFast?"new/%s_F.er":"new/%s.er", songName); @@ -189,3 +191,13 @@ void FixFilesize(u32 streamNameOffset) { } + +extern "C" u8 after_course_getMusicForZone(u8 realThemeID) { + if (realThemeID < 100) + return realThemeID; + + bool usesDrums = (realThemeID >= 200); + return hijackMusicWithSongName(SongNameList[realThemeID-100], realThemeID, true, usesDrums?4:2, usesDrums?2:1, 0); +} + + |