Guest User

Untitled

a guest
Dec 15th, 2017
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. const int oCZoneMusic_HeroStatus = 10111520;
  2.  
  3. //-------- Library -------- //
  4. var int CMusic_Inited;
  5. var int CMusic_Library;
  6. var int Lib_PlayMusic;
  7. var int Lib_SetVolume;
  8. var int Lib_Tidy;
  9.  
  10. //-------- MusicSystem -------- //
  11. var int CMusic_VolumeInited;
  12. var int CMusic_MusicVolume;
  13. var int CMusic_HeroStatus_Last;
  14. var int CMusic_LastZone;
  15. var string CMusic_OldTheme;
  16.  
  17. func void CMusic_Init()
  18. {
  19. if(CMusic_Inited){ return; };
  20.  
  21. CMusic_Library = LoadLibrary("CMusic.dll");
  22. Lib_PlayMusic = GetProcAddress(CMusic_Library, "PlayMusic");
  23. Lib_SetVolume = GetProcAddress(CMusic_Library, "SetVolume");
  24. Lib_Tidy = GetProcAddress(CMusic_Library, "Tidy");
  25. CMusic_Inited = true;
  26. };
  27.  
  28. func void CMusic_Play(var string file, var int vol, var int IsInstant)
  29. {
  30. CMusic_Init();
  31. CALL_IntParam(IsInstant);
  32. CALL_PtrParam(vol);
  33. CALL_cStringPtrParam(file);
  34. CALL__cdecl(Lib_PlayMusic);
  35. };
  36.  
  37. func void CMusic_SetVolume(var int vol)
  38. {
  39. CMusic_Init();
  40. CALL_PtrParam(vol);
  41. CALL__cdecl(Lib_SetVolume);
  42. };
  43.  
  44. func void CMusic_Tidy()
  45. {
  46. CMusic_Init();
  47. CALL__cdecl(Lib_Tidy);
  48. };
  49.  
  50. func int CMusic_GetVolume(var string vol)
  51. {
  52. var int firstChar; firstChar = STR_GetCharAt(vol, 0);
  53. var int result; result = mkf(1);
  54.  
  55. //ToDo: Maybe use zSTRING::ToFloat Method...
  56. if(firstChar != 49) //'1' in ASCII
  57. {
  58. var string AfterCom; AfterCom = STR_SubStr(vol, 2, STR_Len(vol) - 2);
  59. var int min; min = 4;
  60. if(min > STR_Len(AfterCom)){
  61. min = STR_Len(AfterCom);
  62. };
  63. AfterCom = STR_SubStr(vol, 2, min);
  64. var int ret; ret = STR_ToInt(AfterCom);
  65. var int mret; mret = Math_Power(10, min);
  66. result = divf(mkf(ret), mkf(mret));
  67. };
  68. return result;
  69. };
  70.  
  71. func void CMusic_VolumeUpdate()
  72. {
  73. var string MusicVol; MusicVol = MEM_GetGothOpt ("SOUND", "musicVolume");
  74. var string MusicEnable; MusicEnable = MEM_GetGothOpt ("SOUND", "musicEnabled");
  75.  
  76. if(STR_ToInt(MusicEnable) == 0)
  77. {
  78. CMusic_MusicVolume = FLOATNULL;
  79. }
  80. else
  81. {
  82. CMusic_MusicVolume = CMusic_GetVolume(MusicVol);
  83. };
  84. CMusic_SetVolume(CMusic_MusicVolume);
  85. };
  86.  
  87. func string CMusic_GetTheme()
  88. {
  89. var string zone; zone = "";
  90. var int vob;
  91. vob = MEM_ReadInt(10111524);
  92.  
  93. if(vob)
  94. {
  95. zone = MEM_ReadString(vob + 16);
  96. }
  97. else
  98. {
  99. return "";
  100. };
  101.  
  102. if(STR_Len(zone) > 3)
  103. {
  104. var string res; res = STR_SubStr(zone, STR_Len(zone) - 3, STR_Len(zone));
  105. if(STR_Len(res) > 0){
  106. return res;
  107. };
  108. };
  109. return "";
  110. };
  111.  
  112. func string CMusic_GetWorldTheme()
  113. {
  114. //ToDO: Other worlds...
  115. MEM_PushStringParam(CMusic_GetTheme());
  116. MEM_Call(CMusic_DEF_Soundtrack_NW);
  117. return MEM_PopStringResult();
  118. };
  119.  
  120. func string CMusic_GetFightTheme()
  121. {
  122. //ToDO: Other worlds...
  123. MEM_PushStringParam(CMusic_GetTheme());
  124. MEM_Call(CMusic_DEF_Soundtrack_NW_FGT);
  125. return MEM_PopStringResult();
  126. };
  127.  
  128. func void CMusic_SetTheme()
  129. {
  130. var int IsInstant; IsInstant = 0;
  131. var string filename;
  132. var int HeroStatus; HeroStatus = MEM_ReadInt(oCZoneMusic_HeroStatus);
  133.  
  134. filename = CMusic_GetWorldTheme();
  135.  
  136. if(Hlp_StrCmp(filename, CMusic_OldTheme) && herostatus == CMusic_HeroStatus_Last)
  137. {
  138. return;
  139. }
  140. else
  141. {
  142. CMusic_OldTheme = filename;
  143. };
  144.  
  145. if(HeroStatus <= 1)
  146. {
  147. filename = CMusic_GetWorldTheme();
  148. }
  149. else
  150. {
  151. filename = CMusic_GetFightTheme();
  152. IsInstant = true;
  153. };
  154. //Debug: ToDO:
  155. PrintS("New!");
  156. PrintS(filename);
  157.  
  158. CMusic_Play(filename, CMusic_MusicVolume, IsInstant);
  159. CMusic_HeroStatus_Last = HeroStatus;
  160. };
  161.  
  162. func void CMusic_Callback()
  163. {
  164. if(MEM_Game.singleStep){
  165. return;
  166. };
  167.  
  168. if(!CMusic_VolumeInited)
  169. {
  170. CMusic_VolumeUpdate();
  171. CMusic_VolumeInited = true;
  172. };
  173.  
  174. var int zone;
  175. var int herostatus;
  176.  
  177. if(CMusic_MusicVolume == FLOATNULL){
  178. return;
  179. };
  180.  
  181. //ToDO: BossFights
  182. zone = MEM_ReadInt(10111524);
  183. if(zone)
  184. {
  185. if(zone != CMusic_LastZone)
  186. {
  187. CMusic_SetTheme();
  188. }
  189. else
  190. {
  191. herostatus = MEM_ReadInt(oCZoneMusic_HeroStatus);
  192.  
  193. if(herostatus != CMusic_HeroStatus_Last)
  194. {
  195. PrintS("New oHeroStatus!");
  196. var string file; file = CMusic_GetWorldTheme();
  197. CMusic_SetTheme();
  198. CMusic_OldTheme = file;
  199. };
  200. };
  201. CMusic_LastZone = zone;
  202. };
  203.  
  204. CMusic_Tidy();
  205. };
  206.  
  207. func void CMusic_ReInit()
  208. {
  209. CMusic_Inited = false;
  210. CMusic_VolumeInited = false;
  211. };
Advertisement
Add Comment
Please, Sign In to add comment