-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathAcceptanceTrackSwitchSystem.cs
More file actions
35 lines (32 loc) · 1.57 KB
/
AcceptanceTrackSwitchSystem.cs
File metadata and controls
35 lines (32 loc) · 1.57 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
using System.Collections.Generic;
using System.Reflection;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using CalamityModMusic.Items.Placeables;
namespace CalamityModMusic
{
public class AcceptanceTrackSwitchSystem : ModSystem
{
public override void PostSetupContent()
{
// This makes it so that the SCal "Acceptance" event records a regular acceptance music box, despite them
// technically being 2 separate tracks
if (!Main.dedServ)
{
// `musicToItem` is a Dictionary of music slots to item types that is used to
// convert music boxes while music is playing
//
// It is marked as internal, so we need to use reflection to modify it directly, but
// by doing so we can make it so that 2 different tracks point to the same music box
FieldInfo info = typeof(MusicLoader).GetField("musicToItem", BindingFlags.NonPublic | BindingFlags.Static);
var musicToItem = (Dictionary<int, int>)info.GetValue(null);
int musicSlot = MusicLoader.GetMusicSlot(CalamityModMusic.Instance, "Sounds/Music/CalamitasDefeat_LongFade");
int itemType = ModContent.ItemType<CalamitasDefeatMusicBox>();
// The FieldInfo returns the same Dictionary instance as the one in the music loader,
// so the field does not need to have its value re-set so long as the Dictionary is modified
musicToItem[musicSlot] = itemType;
}
}
}
}