forked from TazTxUK/MusicModCallback
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
760 lines (696 loc) · 23.6 KB
/
main.lua
File metadata and controls
760 lines (696 loc) · 23.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
if MMC then return end
local MusicModCallback = RegisterMod("Music Mod Callback", 1)
MMC = {}
MMC.Version = "1.2"
local newmusicenum = {
MUSIC_NULL = 0,
MUSIC_BASEMENT = Isaac.GetMusicIdByName("Basement"),
MUSIC_CAVES = Isaac.GetMusicIdByName("Caves"),
MUSIC_DEPTHS = Isaac.GetMusicIdByName("Depths"),
MUSIC_CELLAR = Isaac.GetMusicIdByName("Cellar"),
MUSIC_CATACOMBS = Isaac.GetMusicIdByName("Catacombs"),
MUSIC_NECROPOLIS = Isaac.GetMusicIdByName("Necropolis"),
MUSIC_WOMB_UTERO = Isaac.GetMusicIdByName("Womb/Utero"),
MUSIC_GAME_OVER = Isaac.GetMusicIdByName("Game Over"),
MUSIC_BOSS = Isaac.GetMusicIdByName("Boss"),
MUSIC_CATHEDRAL = Isaac.GetMusicIdByName("Cathedral"),
MUSIC_SHEOL = Isaac.GetMusicIdByName("Sheol"),
MUSIC_DARK_ROOM = Isaac.GetMusicIdByName("Dark Room"),
MUSIC_CHEST = Isaac.GetMusicIdByName("Chest"),
MUSIC_BURNING_BASEMENT = Isaac.GetMusicIdByName("Burning Basement"),
MUSIC_FLOODED_CAVES = Isaac.GetMusicIdByName("Flooded Caves"),
MUSIC_DANK_DEPTHS = Isaac.GetMusicIdByName("Dank Depths"),
MUSIC_SCARRED_WOMB = Isaac.GetMusicIdByName("Scarred Womb"),
MUSIC_BLUE_WOMB = Isaac.GetMusicIdByName("Blue Womb"),
MUSIC_MOM_BOSS = Isaac.GetMusicIdByName("Boss (Depths - Mom)"),
MUSIC_MOMS_HEART_BOSS = Isaac.GetMusicIdByName("Boss (Womb - Mom's Heart)"),
MUSIC_ISAAC_BOSS = Isaac.GetMusicIdByName("Boss (Cathedral - Isaac)"),
MUSIC_SATAN_BOSS = Isaac.GetMusicIdByName("Boss (Sheol - Satan)"),
MUSIC_DARKROOM_BOSS = Isaac.GetMusicIdByName("Boss (Dark Room)"),
MUSIC_BLUEBABY_BOSS = Isaac.GetMusicIdByName("Boss (Chest - ???)"),
MUSIC_BOSS2 = Isaac.GetMusicIdByName("Boss (alternate)"),
MUSIC_HUSH_BOSS = Isaac.GetMusicIdByName("Boss (Blue Womb - Hush)"),
MUSIC_ULTRAGREED_BOSS = Isaac.GetMusicIdByName("Boss (Ultra Greed)"),
MUSIC_LIBRARY_ROOM = Isaac.GetMusicIdByName("Library Room"),
MUSIC_SECRET_ROOM = Isaac.GetMusicIdByName("Secret Room"),
MUSIC_DEVIL_ROOM = Isaac.GetMusicIdByName("Devil Room"),
MUSIC_ANGEL_ROOM = Isaac.GetMusicIdByName("Angel Room"),
MUSIC_SHOP_ROOM = Isaac.GetMusicIdByName("Shop Room"),
MUSIC_ARCADE_ROOM = Isaac.GetMusicIdByName("Arcade Room"),
MUSIC_BOSS_OVER = Isaac.GetMusicIdByName("Boss Room (empty)"),
MUSIC_CHALLENGE_FIGHT = Isaac.GetMusicIdByName("Challenge Room (fight)"),
MUSIC_CREDITS = Isaac.GetMusicIdByName("Credits"),
MUSIC_TITLE = Isaac.GetMusicIdByName("Title Screen"),
MUSIC_TITLE_AFTERBIRTH = Isaac.GetMusicIdByName("Title Screen (Afterbirth)"),
MUSIC_JINGLE_BOSS = Isaac.GetMusicIdByName("Boss (jingle)"),
MUSIC_JINGLE_BOSS_OVER = Isaac.GetMusicIdByName("Boss Death (jingle)"),
MUSIC_JINGLE_HOLYROOM_FIND = Isaac.GetMusicIdByName("Holy Room Find (jingle)"),
MUSIC_JINGLE_SECRETROOM_FIND = Isaac.GetMusicIdByName("Secret Room Find (jingle)"),
MUSIC_JINGLE_TREASUREROOM_ENTRY_0 = Isaac.GetMusicIdByName("Treasure Room Entry (jingle) 1"),
MUSIC_JINGLE_TREASUREROOM_ENTRY_1 = Isaac.GetMusicIdByName("Treasure Room Entry (jingle) 2"),
MUSIC_JINGLE_TREASUREROOM_ENTRY_2 = Isaac.GetMusicIdByName("Treasure Room Entry (jingle) 3"),
MUSIC_JINGLE_TREASUREROOM_ENTRY_3 = Isaac.GetMusicIdByName("Treasure Room Entry (jingle) 4"),
MUSIC_JINGLE_CHALLENGE_ENTRY = Isaac.GetMusicIdByName("Challenge Room Entry (jingle)"),
MUSIC_JINGLE_CHALLENGE_OUTRO = Isaac.GetMusicIdByName("Challenge Room Outro (jingle)"),
MUSIC_JINGLE_GAME_OVER = Isaac.GetMusicIdByName("Game Over (jingle)"),
MUSIC_JINGLE_DEVILROOM_FIND = Isaac.GetMusicIdByName("Devil Room appear (jingle)"),
MUSIC_JINGLE_GAME_START = Isaac.GetMusicIdByName("Game start (jingle)"),
MUSIC_JINGLE_NIGHTMARE = Isaac.GetMusicIdByName("Nightmare"),
MUSIC_JINGLE_BOSS_OVER2 = Isaac.GetMusicIdByName("Boss Death Alternate (jingle)"),
MUSIC_JINGLE_HUSH_OVER = Isaac.GetMusicIdByName("Boss Hush Death (jingle)"),
MUSIC_INTRO_VOICEOVER = Isaac.GetMusicIdByName("Intro Voiceover"),
MUSIC_EPILOGUE_VOICEOVER = Isaac.GetMusicIdByName("Epilogue Voiceover"),
MUSIC_VOID = Isaac.GetMusicIdByName("Void"),
MUSIC_VOID_BOSS = Isaac.GetMusicIdByName("Boss (Void)"),
NUM_MUSIC = Isaac.GetMusicIdByName("Boss (Void)") + 1,
}
local musicmgr = MusicManager()
MusicPreMMC = MusicPreMMC or Music
local redirectmusicenum = {}
for i,v in pairs(MusicPreMMC) do
if v < MusicPreMMC.NUM_MUSIC and redirectmusicenum[v] ~= newmusicenum[i] then
redirectmusicenum[v] = newmusicenum[i]
end
end
Music = newmusicenum
local function correctedTrackNum(n)
if redirectmusicenum[n] then
return redirectmusicenum[n]
end
return n
end
local addMusicCallback
local removeMusicCallback
local musicQueue
local musicCrossfade
local musicPlay
local Callbacks = {}
local usernolayers = false
local roomclearbefore = false
local challengedonebefore = false
local challengeactivebefore = false
local previousgreedwave = 0
local previousbosscount = 0
local waitingforgamestjingle = true
local satanfightstage = 0
local doorprevstates = {}
local inbadstage = false
local stageapiexists = false
local overridemusicmgrfuncs = {
Play = function(badself, track, vol) return musicPlay(track, nil, true) end,
Fadein = function(badself, track, vol) return musicCrossfade(track, nil, true) end,
Crossfade = function(badself, track) return musicCrossfade(track, nil) end,
Queue = function(badself, track) return musicQueue(track, true) end,
Fadeout = function(badself, ...) return musicmgr:Fadeout(...) end,
Pause = function(badself, ...) return musicmgr:Pause(...) end,
Resume = function(badself, ...) return musicmgr:Resume(...) end,
EnableLayer = function(badself, ...) return musicmgr:EnableLayer(...) end,
DisableLayer = function(badself, ...) return musicmgr:DisableLayer(...) end,
IsLayerEnabled = function(badself, ...) return musicmgr:IsLayerEnabled(...) end,
Enable = function(badself, ...) return musicmgr:Enable(...) end,
Disable = function(badself, ...) return musicmgr:Disable(...) end,
IsEnabled = function(badself, ...) return musicmgr:IsEnabled(...) end,
PitchSlide = function(badself, ...) return musicmgr:PitchSlide(...) end,
ResetPitch = function(badself, ...) return musicmgr:ResetPitch(...) end,
VolumeSlide = function(badself, ...) return musicmgr:VolumeSlide(...) end,
UpdateVolume = function(badself, ...) return musicmgr:UpdateVolume(...) end,
GetCurrentMusicID = function(badself, ...) return musicmgr:GetCurrentMusicID(...) end,
GetQueuedMusicID = function(badself, ...) return musicmgr:GetQueuedMusicID(...) end,
}
overridemusicmgrfuncs.__index = overridemusicmgrfuncs
local overridemusicmgr = {}
setmetatable(overridemusicmgr, overridemusicmgrfuncs)
local weakfunc = function() return end
local weakmusicmgrfuncs = {
Play = weakfunc,
Fadein = weakfunc,
Crossfade = weakfunc,
Queue = weakfunc
}
weakmusicmgrfuncs.__index = weakmusicmgrfuncs
local weakmusicmgr = {}
setmetatable(weakmusicmgr, weakmusicmgrfuncs)
setmetatable(weakmusicmgrfuncs, overridemusicmgrfuncs)
if Isaac.HasModData(MusicModCallback) then
local dat = Isaac.LoadModData(MusicModCallback)
if dat == "0" then
usernolayers = true
elseif dat == "1" then
usernolayers = false
end
end
local function getStageMusic()
local level = Game():GetLevel()
local stage = level:GetStage()
local stage_type = level:GetStageType()
if stage_type == StageType.STAGETYPE_GREEDMODE then
if stage == LevelStage.STAGE1_GREED then
return Music.MUSIC_BURNING_BASEMENT
elseif stage == LevelStage.STAGE2_GREED then
return Music.MUSIC_FLOODED_CAVES
elseif stage == LevelStage.STAGE3_GREED then
return Music.MUSIC_DANK_DEPTHS
elseif stage == LevelStage.STAGE4_GREED then
return Music.MUSIC_WOMB_UTERO
elseif stage == LevelStage.STAGE5_GREED then
return Music.MUSIC_SHEOL
elseif stage == LevelStage.STAGE6_GREED then
return Music.MUSIC_SHOP_ROOM
elseif stage == LevelStage.STAGE7_GREED then
return Music.MUSIC_SHOP_ROOM
end
else
if stage == LevelStage.STAGE1_1 or stage == LevelStage.STAGE1_2 then
if stage_type == StageType.STAGETYPE_ORIGINAL then
return Music.MUSIC_BASEMENT
elseif stage_type == StageType.STAGETYPE_WOTL then
return Music.MUSIC_CELLAR
elseif stage_type == StageType.STAGETYPE_AFTERBIRTH then
return Music.MUSIC_BURNING_BASEMENT
end
elseif stage == LevelStage.STAGE2_1 or stage == LevelStage.STAGE2_2 then
if stage_type == StageType.STAGETYPE_ORIGINAL then
return Music.MUSIC_CAVES
elseif stage_type == StageType.STAGETYPE_WOTL then
return Music.MUSIC_CATACOMBS
elseif stage_type == StageType.STAGETYPE_AFTERBIRTH then
return Music.MUSIC_FLOODED_CAVES
end
elseif stage == LevelStage.STAGE3_1 or stage == LevelStage.STAGE3_2 then
if stage_type == StageType.STAGETYPE_ORIGINAL then
return Music.MUSIC_DEPTHS
elseif stage_type == StageType.STAGETYPE_WOTL then
return Music.MUSIC_NECROPOLIS
elseif stage_type == StageType.STAGETYPE_AFTERBIRTH then
return Music.MUSIC_DANK_DEPTHS
end
elseif stage == LevelStage.STAGE4_1 or stage == LevelStage.STAGE4_2 then
if stage_type == StageType.STAGETYPE_ORIGINAL then
return Music.MUSIC_WOMB_UTERO
elseif stage_type == StageType.STAGETYPE_WOTL then
return Music.MUSIC_WOMB_UTERO
elseif stage_type == StageType.STAGETYPE_AFTERBIRTH then
return Music.MUSIC_SCARRED_WOMB
end
elseif stage == LevelStage.STAGE4_3 then
return Music.MUSIC_BLUE_WOMB
elseif stage == LevelStage.STAGE5 then
if stage_type == StageType.STAGETYPE_ORIGINAL then
return Music.MUSIC_SHEOL
elseif stage_type == StageType.STAGETYPE_WOTL then
return Music.MUSIC_CATHEDRAL
end
elseif stage == LevelStage.STAGE6 then
if stage_type == StageType.STAGETYPE_ORIGINAL then
return Music.MUSIC_DARK_ROOM
elseif stage_type == StageType.STAGETYPE_WOTL then
return Music.MUSIC_CHEST
end
elseif stage == LevelStage.STAGE7 then
return Music.MUSIC_VOID
end
end
return Music.MUSIC_TITLE
end
local function getGenericBossMusic()
local room = Game():GetRoom()
if room:GetDecorationSeed() % 2 == 0 then
return Music.MUSIC_BOSS
else
return Music.MUSIC_BOSS2
end
end
local function getBossMusic()
local room = Game():GetRoom()
if room:GetBossID() == 6 then
return Music.MUSIC_MOM_BOSS
elseif room:GetBossID() == 8 then
return Music.MUSIC_MOMS_HEART_BOSS
elseif room:GetBossID() == 25 then
return Music.MUSIC_MOMS_HEART_BOSS
elseif room:GetBossID() == 24 then
return Music.MUSIC_DEVIL_ROOM
elseif room:GetBossID() == 39 then
return Music.MUSIC_ISAAC_BOSS
elseif room:GetBossID() == 40 then
return Music.MUSIC_BLUEBABY_BOSS
elseif room:GetBossID() == 54 then
return Music.MUSIC_DARKROOM_BOSS
elseif room:GetBossID() == 55 then
return Music.MUSIC_DEVIL_ROOM
elseif room:GetBossID() == 62 then
return Music.MUSIC_ULTRAGREED_BOSS
elseif room:GetBossID() == 63 then
return Music.MUSIC_BLUEBABY_BOSS
elseif room:GetBossID() == 70 then
return Music.MUSIC_VOID_BOSS
end
return getGenericBossMusic()
end
local function getMusicTrack()
local game = Game()
local room = game:GetRoom()
local roomtype = room:GetType()
local level = game:GetLevel()
local roomdesc = level:GetCurrentRoomDesc()
if roomtype == RoomType.ROOM_MINIBOSS or roomdesc.SurpriseMiniboss then
if room:IsClear() then
return Music.MUSIC_BOSS_OVER
else
return getGenericBossMusic()
end
elseif roomtype == RoomType.ROOM_DEFAULT then
return getStageMusic()
elseif roomtype == RoomType.ROOM_SHOP then
if (game:IsGreedMode() or level:GetStage() ~= LevelStage.STAGE4_3) then
return Music.MUSIC_SHOP_ROOM
else
return getStageMusic()
end
elseif roomtype == RoomType.ROOM_TREASURE then
if room:IsFirstVisit() and (game:IsGreedMode() or level:GetStage() ~= LevelStage.STAGE4_3) then
local rng = math.random(0,3)
local jingle
if rng == 0 then
jingle = Music.MUSIC_JINGLE_TREASUREROOM_ENTRY_0
elseif rng == 1 then
jingle = Music.MUSIC_JINGLE_TREASUREROOM_ENTRY_1
elseif rng == 2 then
jingle = Music.MUSIC_JINGLE_TREASUREROOM_ENTRY_2
elseif rng == 3 then
jingle = Music.MUSIC_JINGLE_TREASUREROOM_ENTRY_3
end
return jingle, getStageMusic()
else
return getStageMusic()
end
elseif roomtype == RoomType.ROOM_BOSS then
if room:IsClear() then
return Music.MUSIC_BOSS_OVER
else
if room:GetBossID() == 0 then
return getGenericBossMusic()
else
return Music.MUSIC_JINGLE_BOSS
end
end
elseif roomtype == RoomType.ROOM_SECRET then
return Music.MUSIC_SECRET_ROOM
elseif roomtype == RoomType.ROOM_SUPERSECRET then
return Music.MUSIC_SECRET_ROOM
elseif roomtype == RoomType.ROOM_ARCADE then
return Music.MUSIC_ARCADE_ROOM
elseif roomtype == RoomType.ROOM_DEVIL then
return Music.MUSIC_DEVIL_ROOM
elseif roomtype == RoomType.ROOM_ANGEL then
return Music.MUSIC_ANGEL_ROOM
elseif roomtype == RoomType.ROOM_LIBRARY then
return Music.MUSIC_LIBRARY_ROOM
elseif roomtype == RoomType.ROOM_CHALLENGE then
return Music.MUSIC_BOSS_OVER
elseif roomtype == RoomType.ROOM_BOSSRUSH then
return Music.MUSIC_BOSS_OVER
else
return getStageMusic()
end
-- ROOM_DUNGEON
end
function addMusicCallback(ref, func, ...)
assert(type(ref) == "table" and ref.Name, "Expected registered mod table for 1st argument, got "..type(ref))
assert(type(func) == "function", "Expected function for 2nd argument, got "..type(func))
local tracks = {...}
for i=1,#tracks do
local v = tracks[i]
tracks[i] = tonumber(v)
end
if #tracks == 0 then tracks = nil end
Callbacks[#Callbacks + 1] = {ref = ref.Name, func = func, tracks = tracks}
end
function removeMusicCallback(ref)
assert(type(ref) == "table" and ref.Name, "Expected registered mod table for 1st argument, got "..type(ref))
for i=1,#Callbacks do
local v = Callbacks[i]
if v.ref == ref.Name then
table.remove(Callbacks, i)
i = i - 1
end
end
end
local function iterateThroughCallbacks(track) -- returns correct track
for i=1,#Callbacks do
local v = Callbacks[i]
local trackincallback = false
if v.tracks then
for j,k in ipairs(v.tracks) do
if k == track then
trackincallback = true
break
end
end
else
trackincallback = true
end
if trackincallback then
local s, res, res2 = pcall(v.func, v.ref, track)
if s then
res = tonumber(res)
if res then
return res, tonumber(res2)
end
else
Isaac.ConsoleOutput("Error in music mod callback: "..res.."\n")
end
end
end
return track
end
function musicCrossfade(track, track2)
local replacedtrack2 = false
local id, id2 = iterateThroughCallbacks(track or false)
if id2 then replacedtrack2 = true end
id2 = id2 or track2
if not id then
return
elseif id > 0 then
if musicmgr:GetCurrentMusicID() ~= id then
musicmgr:Crossfade(correctedTrackNum(id))
end
if id2 and id2 > 0 then
if replacedtrack2 then
musicmgr:Queue(correctedTrackNum(id2))
else
musicQueue(id2)
end
end
elseif id < 0 then
if id2 then
if id2 == 0 then
return
elseif id2 < 0 then
musicmgr:Fadeout()
return
end
if replacedtrack2 then
musicmgr:Crossfade(correctedTrackNum(id2))
else
musicCrossfade(id2, nil)
end
else
musicmgr:Fadeout()
end
end
end
function musicPlay(track, track2)
local replacedtrack2 = false
local id, id2 = iterateThroughCallbacks(track or false)
if id2 then replacedtrack2 = true end
id2 = id2 or track2
if id and id > 0 then
if musicmgr:GetCurrentMusicID() ~= id then
musicmgr:Play(correctedTrackNum(id),1)
musicmgr:UpdateVolume()
end
elseif id == 0 then
return
elseif id < 0 then
if id2 then
if id2 == 0 then
return
elseif id2 < 0 then
musicmgr:Fadeout()
return
end
if replacedtrack2 then
musicmgr:Play(correctedTrackNum(id2),1)
musicmgr:UpdateVolume()
else
musicPlay(id2, nil)
end
else
musicmgr:Fadeout()
end
return
end
if id2 and id2 > 0 then
if replacedtrack2 then
musicmgr:Queue(correctedTrackNum(id2))
else
musicQueue(id2)
end
end
end
function musicQueue(track)
local id = iterateThroughCallbacks(track or false)
if id and id > 0 then
musicmgr:Queue(correctedTrackNum(id))
end
end
MusicModCallback:AddCallback(ModCallbacks.MC_POST_NEW_LEVEL, function()
if StageAPI and StageAPI.Loaded then
stageapiexists = true
else
stageapiexists = false
end
if stageapiexists then
if StageAPI.InNewStage() then
inbadstage = true
-- musicmgr:Play(getStageMusic(),1) -- StageAPI waits for other music to play.
-- StageAPI.Music = overridemusicmgr
StageAPI.Music = overridemusicmgr
else
inbadstage = false
StageAPI.Music = weakmusicmgr
end
else
inbadstage = false
end
end)
MusicModCallback:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, function()
if not inbadstage then
local room = Game():GetRoom()
previousgreedwave = 0
previousbosscount = 0
satanfightstage = 0
challengeactivebefore = room:IsAmbushActive()
challengedonebefore = room:IsAmbushDone()
roomclearbefore = room:IsClear()
if not waitingforgamestjingle then
musicCrossfade(getMusicTrack())
end
if usernolayers or MMC.DisableMusicLayers then
musicmgr:DisableLayer()
end
for i=0,7 do
local door = room:GetDoor(i)
if door then
doorprevstates[i] = door.State
end
end
end
end)
MusicModCallback:AddCallback(ModCallbacks.MC_POST_NPC_DEATH, function(self, ent)
if ent.Type == 102 and ent.Variant == 2 then
musicCrossfade(Music.MUSIC_HUSH_BOSS)
end
end)
MusicModCallback:AddCallback(ModCallbacks.MC_PRE_GAME_EXIT, function()
waitingforgamestjingle = true
roomclearbefore = false
challengedonebefore = false
challengeactivebefore = false
previousgreedwave = 0
previousbosscount = 0
satanfightstage = 0
end)
MusicModCallback:AddCallback(ModCallbacks.MC_EXECUTE_CMD, function(self, cmd, params)
if cmd == "mmclayer" then
if params == "0" then
usernolayers = true
Isaac.SaveModData(MusicModCallback, "0")
musicmgr:DisableLayer()
return "Disabled music layers.\n"
elseif params == "1" then
usernolayers = false
Isaac.SaveModData(MusicModCallback, "1")
return "Enabled music layers.\n"
end
end
end)
MusicModCallback:AddCallback(ModCallbacks.MC_POST_RENDER, function()
if inbadstage then return end
local room = Game():GetRoom()
local level = Game():GetLevel()
local roomclearnow = room:IsClear()
local challengedonenow = room:IsAmbushDone()
local challengeactivenow = room:IsAmbushActive()
local roomdesc = Game():GetLevel():GetCurrentRoomDesc()
if waitingforgamestjingle and room:GetFrameCount() > 10 then
if room:GetType() == RoomType.ROOM_BOSS and not room:IsClear() then
musicCrossfade(getBossMusic())
else
musicCrossfade(getMusicTrack())
end
waitingforgamestjingle = false
return
end
if Game():IsGreedMode() then
local currentgreedwave = Game():GetLevel().GreedModeWave
if room:GetType() == RoomType.ROOM_BOSS then
local currentbosscount = Isaac.CountBosses()
if room:GetBossID() == 62 then
if satanfightstage == 0 then
if currentbosscount == 0 then
satanfightstage = 2
musicCrossfade(Music.MUSIC_BOSS_OVER)
return
end
satanfightstage = 1
musicCrossfade(getBossMusic())
elseif satanfightstage == 1 then
for i,v in ipairs(Isaac.GetRoomEntities()) do
if v.Type == EntityType.ENTITY_ULTRA_GREED then
if v:ToNPC().State == 9001 then
satanfightstage = 2
musicCrossfade(Music.MUSIC_JINGLE_BOSS_OVER, Music.MUSIC_BOSS_OVER)
end
break
end
end
end
else
if currentbosscount > 0 and room:GetFrameCount() == 1 then
musicCrossfade(getBossMusic())
end
if currentbosscount == 0 and previousbosscount > 0 then
local bossjingle
if room:GetDecorationSeed() % 2 == 0 then
bossjingle = Music.MUSIC_JINGLE_BOSS_OVER
else
bossjingle = Music.MUSIC_JINGLE_BOSS_OVER2
end
musicCrossfade(bossjingle, Music.MUSIC_BOSS_OVER)
end
end
previousbosscount = currentbosscount
else
if level:GetStage() == LevelStage.STAGE6_GREED then
if room:GetType() == RoomType.ROOM_DEFAULT then
if currentgreedwave < 9 then
if roomclearbefore and not roomclearnow then
musicCrossfade(Music.MUSIC_CHALLENGE_FIGHT)
end
if roomclearnow and not roomclearbefore then
musicCrossfade(Music.MUSIC_JINGLE_CHALLENGE_OUTRO, Music.MUSIC_SHOP_ROOM)
end
end
end
end
if room:GetType() == RoomType.ROOM_DEFAULT then
if roomclearbefore and not roomclearnow then
if currentgreedwave == 9 or currentgreedwave == 10 then
musicCrossfade(Music.MUSIC_BOSS2)
elseif currentgreedwave == 11 then
musicCrossfade(Music.MUSIC_SATAN_BOSS)
end
elseif roomclearnow and not roomclearbefore then
if currentgreedwave >= 9 then
musicCrossfade(Music.MUSIC_JINGLE_BOSS_OVER2, Music.MUSIC_BOSS_OVER)
end
end
end
end
previousgreedwave = currentgreedwave
else
if room:GetType() == RoomType.ROOM_CHALLENGE or room:GetType() == RoomType.ROOM_BOSSRUSH then
if challengeactivenow and not challengeactivebefore then
musicCrossfade(Music.MUSIC_CHALLENGE_FIGHT)
end
if challengedonenow and not challengedonebefore then
musicCrossfade(Music.MUSIC_JINGLE_CHALLENGE_OUTRO, Music.MUSIC_BOSS_OVER)
end
elseif room:GetType() == RoomType.ROOM_TREASURE then
if room:GetFrameCount() == 1 then
musicQueue(getStageMusic())
end
elseif room:GetType() == RoomType.ROOM_BOSS then
local currentbosscount = Isaac.CountBosses()
if currentbosscount > 0 and room:GetFrameCount() == 1 then
satanfightstage = 0
musicCrossfade(getBossMusic())
end
if room:GetFrameCount() > 1 then
if room:GetBossID() == 24 then
if satanfightstage == 0 and currentbosscount > 1 then
musicCrossfade(getGenericBossMusic())
satanfightstage = 1
elseif satanfightstage == 1 and currentbosscount == 1 then
musicCrossfade(Music.MUSIC_SATAN_BOSS)
satanfightstage = 2
end
elseif room:GetBossID() == 55 then
if Isaac.GetPlayer(0).Position.Y < 540 and satanfightstage == 0 and room:GetFrameCount() > 10 then
musicCrossfade(Music.MUSIC_SATAN_BOSS)
satanfightstage = 3
end
else
satanfightstage = 0
end
end
if currentbosscount == 0 and previousbosscount > 0 then
local bossjingle
if room:GetDecorationSeed() % 2 == 0 then
bossjingle = Music.MUSIC_JINGLE_BOSS_OVER
else
bossjingle = Music.MUSIC_JINGLE_BOSS_OVER2
end
musicCrossfade(bossjingle, Music.MUSIC_BOSS_OVER)
end
previousbosscount = currentbosscount
elseif room:GetType() == RoomType.ROOM_MINIBOSS or roomdesc.SurpriseMiniboss then
local currentbosscount = Isaac.CountBosses()
if currentbosscount == 0 and previousbosscount > 0 then
local bossjingle
if room:GetDecorationSeed() % 2 == 0 then
bossjingle = Music.MUSIC_JINGLE_BOSS_OVER
else
bossjingle = Music.MUSIC_JINGLE_BOSS_OVER2
end
musicCrossfade(bossjingle, Music.MUSIC_BOSS_OVER)
end
previousbosscount = currentbosscount
end
end
--SECRET ROOM DOORS
for i=0,7 do
local door = room:GetDoor(i)
if door then
if door.TargetRoomType == RoomType.ROOM_SECRET or door.TargetRoomType == RoomType.ROOM_SUPERSECRET then
if door.State == 2 and doorprevstates[i] == 1 then
if Game():GetLevel():GetRoomByIdx(door.TargetRoomIndex).VisitedCount == 0 then
musicPlay(Music.MUSIC_JINGLE_SECRETROOM_FIND, getMusicTrack())
end
end
end
end
end
for i=0,7 do
local door = room:GetDoor(i)
if door then
doorprevstates[i] = door.State
end
end
challengedonebefore = challengedonenow
challengeactivebefore = challengeactivenow
roomclearbefore = roomclearnow
end)
MMC.GetMusicTrack = getMusicTrack
MMC.GetBossTrack = getBossMusic
MMC.GetStageTrack = getStageMusic
MMC.GetGenericBossTrack = getGenericBossMusic
MMC.AddMusicCallback = addMusicCallback
MMC.RemoveMusicCallback = removeMusicCallback
-- MMC.GetCallbacks = function() return Callbacks end
MMC.InCustomStage = function() return inbadstage end
MMC.Manager = function() return overridemusicmgr end
MMC.DisableMusicLayers = false
MMC.Initialised = true