diff --git a/readme.txt b/readme.txt index 5920165..41f47f3 100644 --- a/readme.txt +++ b/readme.txt @@ -42,6 +42,8 @@ https://github.com/dborth/vbagx/releases * Added ability to load external fonts and activated Japanese/Korean translations. Simply put the ko.ttf or jp.ttf in the app directory +* Added ability to customize background music. Simply put a bg_music.ogg + in the app directory * Added ability to change preview image source with + button (thanks Zalo!) [2.3.8 - January 4, 2019] diff --git a/source/fileop.cpp b/source/fileop.cpp index 2e46ef6..f72ac17 100644 --- a/source/fileop.cpp +++ b/source/fileop.cpp @@ -894,6 +894,35 @@ size_t LoadFont(char * filepath) fclose(file); return loadSize; } + +void LoadBgMusic() +{ + char filepath[MAXPATHLEN]; + sprintf(filepath, "%s/bg_music.ogg", appPath); + FILE *file = fopen (filepath, "rb"); + if(!file) { + return; + } + + fseeko(file,0,SEEK_END); + size_t ogg_size = ftello(file); + + if(ogg_size == 0) { + return; + } + + u8 * ogg_data = (u8 *)mem2_malloc(ogg_size); + + if(!ogg_data) { + return; + } + + fseeko(file, 0, SEEK_SET); + fread (ogg_data, 1, ogg_size, file); + fclose(file); + bg_music = ogg_data; + bg_music_size = ogg_size; +} #endif /**************************************************************************** diff --git a/source/fileop.h b/source/fileop.h index a103bb3..a745358 100644 --- a/source/fileop.h +++ b/source/fileop.h @@ -37,6 +37,7 @@ size_t LoadFile(char * rbuffer, char *filepath, size_t length, size_t buffersize size_t LoadFile(char * filepath, bool silent); size_t LoadSzFile(char * filepath, unsigned char * rbuffer); size_t LoadFont(char *filepath); +void LoadBgMusic(); size_t SaveFile(char * buffer, char *filepath, size_t datasize, bool silent); size_t SaveFile(char * filepath, size_t datasize, bool silent); diff --git a/source/menu.cpp b/source/menu.cpp index 3de0cb4..8190a39 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -80,6 +80,9 @@ static char progressMsg[201]; static int progressDone = 0; static int progressTotal = 0; +u8 * bg_music; +u32 bg_music_size; + /**************************************************************************** * ResumeGui * @@ -4791,7 +4794,7 @@ MainMenu (int menu) #ifndef NO_SOUND if(firstRun) { - bgMusic = new GuiSound(bg_music_ogg, bg_music_ogg_size, SOUND_OGG); + bgMusic = new GuiSound(bg_music, bg_music_size, SOUND_OGG); bgMusic->SetVolume(GCSettings.MusicVolume); bgMusic->SetLoop(true); enterSound = new GuiSound(enter_ogg, enter_ogg_size, SOUND_OGG); diff --git a/source/menu.h b/source/menu.h index 575669f..0a8dc58 100644 --- a/source/menu.h +++ b/source/menu.h @@ -27,6 +27,9 @@ void CancelAction(); void ShowProgress (const char *msg, int done, int total); void ChangeLanguage(); +extern u8 * bg_music; +extern u32 bg_music_size; + enum { MENU_EXIT = -1, diff --git a/source/preferences.cpp b/source/preferences.cpp index 590e687..9b1cf64 100644 --- a/source/preferences.cpp +++ b/source/preferences.cpp @@ -848,6 +848,12 @@ bool LoadPrefs() CreateDirectory(dirPath); } +#ifdef HW_RVL + bg_music = (u8 * )bg_music_ogg; + bg_music_size = bg_music_ogg_size; + LoadBgMusic(); +#endif + ChangeLanguage(); return prefFound; }