Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int oCZoneMusic_HeroStatus = 10111520;
- //-------- Library -------- //
- var int CMusic_Inited;
- var int CMusic_Library;
- var int Lib_PlayMusic;
- var int Lib_SetVolume;
- var int Lib_Tidy;
- //-------- MusicSystem -------- //
- var int CMusic_VolumeInited;
- var int CMusic_MusicVolume;
- var int CMusic_HeroStatus_Last;
- var int CMusic_LastZone;
- var string CMusic_OldTheme;
- func void CMusic_Init()
- {
- if(CMusic_Inited){ return; };
- CMusic_Library = LoadLibrary("CMusic.dll");
- Lib_PlayMusic = GetProcAddress(CMusic_Library, "PlayMusic");
- Lib_SetVolume = GetProcAddress(CMusic_Library, "SetVolume");
- Lib_Tidy = GetProcAddress(CMusic_Library, "Tidy");
- CMusic_Inited = true;
- };
- func void CMusic_Play(var string file, var int vol, var int IsInstant)
- {
- CMusic_Init();
- CALL_IntParam(IsInstant);
- CALL_PtrParam(vol);
- CALL_cStringPtrParam(file);
- CALL__cdecl(Lib_PlayMusic);
- };
- func void CMusic_SetVolume(var int vol)
- {
- CMusic_Init();
- CALL_PtrParam(vol);
- CALL__cdecl(Lib_SetVolume);
- };
- func void CMusic_Tidy()
- {
- CMusic_Init();
- CALL__cdecl(Lib_Tidy);
- };
- func int CMusic_GetVolume(var string vol)
- {
- var int firstChar; firstChar = STR_GetCharAt(vol, 0);
- var int result; result = mkf(1);
- //ToDo: Maybe use zSTRING::ToFloat Method...
- if(firstChar != 49) //'1' in ASCII
- {
- var string AfterCom; AfterCom = STR_SubStr(vol, 2, STR_Len(vol) - 2);
- var int min; min = 4;
- if(min > STR_Len(AfterCom)){
- min = STR_Len(AfterCom);
- };
- AfterCom = STR_SubStr(vol, 2, min);
- var int ret; ret = STR_ToInt(AfterCom);
- var int mret; mret = Math_Power(10, min);
- result = divf(mkf(ret), mkf(mret));
- };
- return result;
- };
- func void CMusic_VolumeUpdate()
- {
- var string MusicVol; MusicVol = MEM_GetGothOpt ("SOUND", "musicVolume");
- var string MusicEnable; MusicEnable = MEM_GetGothOpt ("SOUND", "musicEnabled");
- if(STR_ToInt(MusicEnable) == 0)
- {
- CMusic_MusicVolume = FLOATNULL;
- }
- else
- {
- CMusic_MusicVolume = CMusic_GetVolume(MusicVol);
- };
- CMusic_SetVolume(CMusic_MusicVolume);
- };
- func string CMusic_GetTheme()
- {
- var string zone; zone = "";
- var int vob;
- vob = MEM_ReadInt(10111524);
- if(vob)
- {
- zone = MEM_ReadString(vob + 16);
- }
- else
- {
- return "";
- };
- if(STR_Len(zone) > 3)
- {
- var string res; res = STR_SubStr(zone, STR_Len(zone) - 3, STR_Len(zone));
- if(STR_Len(res) > 0){
- return res;
- };
- };
- return "";
- };
- func string CMusic_GetWorldTheme()
- {
- //ToDO: Other worlds...
- MEM_PushStringParam(CMusic_GetTheme());
- MEM_Call(CMusic_DEF_Soundtrack_NW);
- return MEM_PopStringResult();
- };
- func string CMusic_GetFightTheme()
- {
- //ToDO: Other worlds...
- MEM_PushStringParam(CMusic_GetTheme());
- MEM_Call(CMusic_DEF_Soundtrack_NW_FGT);
- return MEM_PopStringResult();
- };
- func void CMusic_SetTheme()
- {
- var int IsInstant; IsInstant = 0;
- var string filename;
- var int HeroStatus; HeroStatus = MEM_ReadInt(oCZoneMusic_HeroStatus);
- filename = CMusic_GetWorldTheme();
- if(Hlp_StrCmp(filename, CMusic_OldTheme) && herostatus == CMusic_HeroStatus_Last)
- {
- return;
- }
- else
- {
- CMusic_OldTheme = filename;
- };
- if(HeroStatus <= 1)
- {
- filename = CMusic_GetWorldTheme();
- }
- else
- {
- filename = CMusic_GetFightTheme();
- IsInstant = true;
- };
- //Debug: ToDO:
- PrintS("New!");
- PrintS(filename);
- CMusic_Play(filename, CMusic_MusicVolume, IsInstant);
- CMusic_HeroStatus_Last = HeroStatus;
- };
- func void CMusic_Callback()
- {
- if(MEM_Game.singleStep){
- return;
- };
- if(!CMusic_VolumeInited)
- {
- CMusic_VolumeUpdate();
- CMusic_VolumeInited = true;
- };
- var int zone;
- var int herostatus;
- if(CMusic_MusicVolume == FLOATNULL){
- return;
- };
- //ToDO: BossFights
- zone = MEM_ReadInt(10111524);
- if(zone)
- {
- if(zone != CMusic_LastZone)
- {
- CMusic_SetTheme();
- }
- else
- {
- herostatus = MEM_ReadInt(oCZoneMusic_HeroStatus);
- if(herostatus != CMusic_HeroStatus_Last)
- {
- PrintS("New oHeroStatus!");
- var string file; file = CMusic_GetWorldTheme();
- CMusic_SetTheme();
- CMusic_OldTheme = file;
- };
- };
- CMusic_LastZone = zone;
- };
- CMusic_Tidy();
- };
- func void CMusic_ReInit()
- {
- CMusic_Inited = false;
- CMusic_VolumeInited = false;
- };
Advertisement
Add Comment
Please, Sign In to add comment