music: add option to mute other players area sounds

This commit is contained in:
Owain van Brakel
2019-11-05 23:19:23 +01:00
parent 319fbf046e
commit 7caff006da
8 changed files with 74 additions and 6 deletions

View File

@@ -27,10 +27,13 @@ package net.runelite.mixins;
import net.runelite.api.SoundEffectVolume;
import net.runelite.api.events.AreaSoundEffectPlayed;
import net.runelite.api.events.SoundEffectPlayed;
import net.runelite.api.mixins.Copy;
import net.runelite.api.mixins.FieldHook;
import net.runelite.api.mixins.Inject;
import net.runelite.api.mixins.Mixin;
import net.runelite.api.mixins.Replace;
import net.runelite.api.mixins.Shadow;
import net.runelite.rs.api.RSActor;
import net.runelite.rs.api.RSClient;
import net.runelite.rs.api.RSPcmStream;
import net.runelite.rs.api.RSRawPcmStream;
@@ -46,6 +49,9 @@ public abstract class SoundEffectMixin implements RSClient
@Inject
private static int lastSoundEffectCount;
@Inject
private static RSActor lastSoundEffectSourceActor;
@Inject
@Override
public void playSoundEffect(int id)
@@ -106,6 +112,23 @@ public abstract class SoundEffectMixin implements RSClient
getSoundEffectAudioQueue().addSubStream((RSPcmStream) rawPcmStream);
}
@Copy("updateActorSequence")
public static void rs$updateActorSequence(RSActor actor, int size)
{
throw new RuntimeException();
}
@Replace("updateActorSequence")
public static void rl$updateActorSequence(RSActor actor, int size)
{
lastSoundEffectSourceActor = actor;
rs$updateActorSequence(actor, size);
lastSoundEffectSourceActor = null;
}
@FieldHook("soundEffectCount")
@Inject
public static void queuedSoundEffectCountChanged(int idx)
@@ -115,15 +138,17 @@ public abstract class SoundEffectMixin implements RSClient
{
int soundIndex = soundCount - 1;
int packedLocation = client.getSoundLocations()[soundIndex];
boolean consumed;
if (packedLocation == 0)
{
// Regular sound effect
SoundEffectPlayed event = new SoundEffectPlayed();
SoundEffectPlayed event = new SoundEffectPlayed(lastSoundEffectSourceActor);
event.setSoundId(client.getQueuedSoundEffectIDs()[soundIndex]);
event.setDelay(client.getQueuedSoundEffectDelays()[soundIndex]);
client.getCallbacks().post(SoundEffectPlayed.class, event);
consumed = event.isConsumed();
}
else
{
@@ -133,16 +158,24 @@ public abstract class SoundEffectMixin implements RSClient
int y = (packedLocation >> 8) & 0xFF;
int range = (packedLocation) & 0xFF;
AreaSoundEffectPlayed event = new AreaSoundEffectPlayed();
AreaSoundEffectPlayed event = new AreaSoundEffectPlayed(lastSoundEffectSourceActor);
event.setSoundId(client.getQueuedSoundEffectIDs()[soundIndex]);
event.setSceneX(x);
event.setSceneY(y);
event.setRange(range);
event.setDelay(client.getQueuedSoundEffectDelays()[soundIndex]);
client.getCallbacks().post(AreaSoundEffectPlayed.class, event);
consumed = event.isConsumed();
}
if (consumed)
{
soundCount--;
client.setQueuedSoundEffectCount(soundCount);
}
}
lastSoundEffectCount = soundCount;
}
}