music: add option to mute other players area sounds
This commit is contained in:
@@ -24,11 +24,16 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.api.events;
|
package net.runelite.api.events;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import net.runelite.api.Actor;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class AreaSoundEffectPlayed implements Event
|
public class AreaSoundEffectPlayed implements Event
|
||||||
{
|
{
|
||||||
|
@Nullable
|
||||||
|
private final Actor source;
|
||||||
|
|
||||||
private int soundId;
|
private int soundId;
|
||||||
private int sceneX;
|
private int sceneX;
|
||||||
private int sceneY;
|
private int sceneY;
|
||||||
|
|||||||
@@ -24,11 +24,16 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.api.events;
|
package net.runelite.api.events;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import net.runelite.api.Actor;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class SoundEffectPlayed implements Event
|
public class SoundEffectPlayed implements Event
|
||||||
{
|
{
|
||||||
|
@Nullable
|
||||||
|
private final Actor source;
|
||||||
|
|
||||||
private int soundId;
|
private int soundId;
|
||||||
private int delay;
|
private int delay;
|
||||||
|
|
||||||
|
|||||||
@@ -87,4 +87,14 @@ public interface MusicConfig extends Config
|
|||||||
hidden = true
|
hidden = true
|
||||||
)
|
)
|
||||||
void setAreaSoundEffectVolume(int vol);
|
void setAreaSoundEffectVolume(int vol);
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "muteOtherAreaSounds",
|
||||||
|
name = "Mute others' area sounds",
|
||||||
|
description = "Mute area sounds caused from other players"
|
||||||
|
)
|
||||||
|
default boolean muteOtherAreaSounds()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -37,13 +37,16 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import net.runelite.api.Actor;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.GameState;
|
import net.runelite.api.GameState;
|
||||||
|
import net.runelite.api.Player;
|
||||||
import net.runelite.api.ScriptID;
|
import net.runelite.api.ScriptID;
|
||||||
import net.runelite.api.SoundEffectID;
|
import net.runelite.api.SoundEffectID;
|
||||||
import net.runelite.api.SpriteID;
|
import net.runelite.api.SpriteID;
|
||||||
import net.runelite.api.VarClientInt;
|
import net.runelite.api.VarClientInt;
|
||||||
import net.runelite.api.VarPlayer;
|
import net.runelite.api.VarPlayer;
|
||||||
|
import net.runelite.api.events.AreaSoundEffectPlayed;
|
||||||
import net.runelite.api.events.ConfigChanged;
|
import net.runelite.api.events.ConfigChanged;
|
||||||
import net.runelite.api.events.GameStateChanged;
|
import net.runelite.api.events.GameStateChanged;
|
||||||
import net.runelite.api.events.ScriptCallbackEvent;
|
import net.runelite.api.events.ScriptCallbackEvent;
|
||||||
@@ -136,6 +139,7 @@ public class MusicPlugin extends Plugin
|
|||||||
eventBus.subscribe(VarClientIntChanged.class, this, this::onVarClientIntChanged);
|
eventBus.subscribe(VarClientIntChanged.class, this, this::onVarClientIntChanged);
|
||||||
eventBus.subscribe(VolumeChanged.class, this, this::onVolumeChanged);
|
eventBus.subscribe(VolumeChanged.class, this, this::onVolumeChanged);
|
||||||
eventBus.subscribe(ScriptCallbackEvent.class, this, this::onScriptCallbackEvent);
|
eventBus.subscribe(ScriptCallbackEvent.class, this, this::onScriptCallbackEvent);
|
||||||
|
eventBus.subscribe(AreaSoundEffectPlayed.class, this, this::onAreaSoundEffectPlayed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onGameStateChanged(GameStateChanged gameStateChanged)
|
private void onGameStateChanged(GameStateChanged gameStateChanged)
|
||||||
@@ -558,4 +562,15 @@ public class MusicPlugin extends Plugin
|
|||||||
client.getIntStack()[client.getIntStackSize() - 1] = -1;
|
client.getIntStack()[client.getIntStackSize() - 1] = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onAreaSoundEffectPlayed(AreaSoundEffectPlayed areaSoundEffectPlayed)
|
||||||
|
{
|
||||||
|
Actor source = areaSoundEffectPlayed.getSource();
|
||||||
|
if (source != client.getLocalPlayer()
|
||||||
|
&& source instanceof Player
|
||||||
|
&& musicConfig.muteOtherAreaSounds())
|
||||||
|
{
|
||||||
|
areaSoundEffectPlayed.consume();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -27,10 +27,13 @@ package net.runelite.mixins;
|
|||||||
import net.runelite.api.SoundEffectVolume;
|
import net.runelite.api.SoundEffectVolume;
|
||||||
import net.runelite.api.events.AreaSoundEffectPlayed;
|
import net.runelite.api.events.AreaSoundEffectPlayed;
|
||||||
import net.runelite.api.events.SoundEffectPlayed;
|
import net.runelite.api.events.SoundEffectPlayed;
|
||||||
|
import net.runelite.api.mixins.Copy;
|
||||||
import net.runelite.api.mixins.FieldHook;
|
import net.runelite.api.mixins.FieldHook;
|
||||||
import net.runelite.api.mixins.Inject;
|
import net.runelite.api.mixins.Inject;
|
||||||
import net.runelite.api.mixins.Mixin;
|
import net.runelite.api.mixins.Mixin;
|
||||||
|
import net.runelite.api.mixins.Replace;
|
||||||
import net.runelite.api.mixins.Shadow;
|
import net.runelite.api.mixins.Shadow;
|
||||||
|
import net.runelite.rs.api.RSActor;
|
||||||
import net.runelite.rs.api.RSClient;
|
import net.runelite.rs.api.RSClient;
|
||||||
import net.runelite.rs.api.RSPcmStream;
|
import net.runelite.rs.api.RSPcmStream;
|
||||||
import net.runelite.rs.api.RSRawPcmStream;
|
import net.runelite.rs.api.RSRawPcmStream;
|
||||||
@@ -46,6 +49,9 @@ public abstract class SoundEffectMixin implements RSClient
|
|||||||
@Inject
|
@Inject
|
||||||
private static int lastSoundEffectCount;
|
private static int lastSoundEffectCount;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private static RSActor lastSoundEffectSourceActor;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Override
|
@Override
|
||||||
public void playSoundEffect(int id)
|
public void playSoundEffect(int id)
|
||||||
@@ -106,6 +112,23 @@ public abstract class SoundEffectMixin implements RSClient
|
|||||||
getSoundEffectAudioQueue().addSubStream((RSPcmStream) rawPcmStream);
|
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")
|
@FieldHook("soundEffectCount")
|
||||||
@Inject
|
@Inject
|
||||||
public static void queuedSoundEffectCountChanged(int idx)
|
public static void queuedSoundEffectCountChanged(int idx)
|
||||||
@@ -115,15 +138,17 @@ public abstract class SoundEffectMixin implements RSClient
|
|||||||
{
|
{
|
||||||
int soundIndex = soundCount - 1;
|
int soundIndex = soundCount - 1;
|
||||||
int packedLocation = client.getSoundLocations()[soundIndex];
|
int packedLocation = client.getSoundLocations()[soundIndex];
|
||||||
|
boolean consumed;
|
||||||
|
|
||||||
if (packedLocation == 0)
|
if (packedLocation == 0)
|
||||||
{
|
{
|
||||||
// Regular sound effect
|
// Regular sound effect
|
||||||
|
|
||||||
SoundEffectPlayed event = new SoundEffectPlayed();
|
SoundEffectPlayed event = new SoundEffectPlayed(lastSoundEffectSourceActor);
|
||||||
event.setSoundId(client.getQueuedSoundEffectIDs()[soundIndex]);
|
event.setSoundId(client.getQueuedSoundEffectIDs()[soundIndex]);
|
||||||
event.setDelay(client.getQueuedSoundEffectDelays()[soundIndex]);
|
event.setDelay(client.getQueuedSoundEffectDelays()[soundIndex]);
|
||||||
client.getCallbacks().post(SoundEffectPlayed.class, event);
|
client.getCallbacks().post(SoundEffectPlayed.class, event);
|
||||||
|
consumed = event.isConsumed();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -133,16 +158,24 @@ public abstract class SoundEffectMixin implements RSClient
|
|||||||
int y = (packedLocation >> 8) & 0xFF;
|
int y = (packedLocation >> 8) & 0xFF;
|
||||||
int range = (packedLocation) & 0xFF;
|
int range = (packedLocation) & 0xFF;
|
||||||
|
|
||||||
AreaSoundEffectPlayed event = new AreaSoundEffectPlayed();
|
AreaSoundEffectPlayed event = new AreaSoundEffectPlayed(lastSoundEffectSourceActor);
|
||||||
event.setSoundId(client.getQueuedSoundEffectIDs()[soundIndex]);
|
event.setSoundId(client.getQueuedSoundEffectIDs()[soundIndex]);
|
||||||
event.setSceneX(x);
|
event.setSceneX(x);
|
||||||
event.setSceneY(y);
|
event.setSceneY(y);
|
||||||
event.setRange(range);
|
event.setRange(range);
|
||||||
event.setDelay(client.getQueuedSoundEffectDelays()[soundIndex]);
|
event.setDelay(client.getQueuedSoundEffectDelays()[soundIndex]);
|
||||||
client.getCallbacks().post(AreaSoundEffectPlayed.class, event);
|
client.getCallbacks().post(AreaSoundEffectPlayed.class, event);
|
||||||
|
consumed = event.isConsumed();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (consumed)
|
||||||
|
{
|
||||||
|
soundCount--;
|
||||||
|
client.setQueuedSoundEffectCount(soundCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
lastSoundEffectCount = soundCount;
|
lastSoundEffectCount = soundCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4136,7 +4136,7 @@ public final class Client extends GameShell implements Usernamed {
|
|||||||
var15 = npcIndices[var1];
|
var15 = npcIndices[var1];
|
||||||
NPC var25 = npcs[var15];
|
NPC var25 = npcs[var15];
|
||||||
if (var25 != null) {
|
if (var25 != null) {
|
||||||
HitSplatDefinition.calculateActorPosition(var25, var25.definition.size);
|
HitSplatDefinition.updateActorSequence(var25, var25.definition.size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -415,8 +415,8 @@ public class HitSplatDefinition extends DualNode {
|
|||||||
signature = "(Lbz;IB)V",
|
signature = "(Lbz;IB)V",
|
||||||
garbageValue = "-26"
|
garbageValue = "-26"
|
||||||
)
|
)
|
||||||
@Export("calculateActorPosition")
|
@Export("updateActorSequence")
|
||||||
static final void calculateActorPosition(Actor var0, int var1) {
|
static final void updateActorSequence(Actor var0, int var1) {
|
||||||
int var2;
|
int var2;
|
||||||
if (var0.field925 > Client.cycle) {
|
if (var0.field925 > Client.cycle) {
|
||||||
WorldMapDecoration.method386(var0);
|
WorldMapDecoration.method386(var0);
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ public class WorldMapData_1 extends AbstractWorldMapData {
|
|||||||
for (int var2 = 0; var2 < var0; ++var2) {
|
for (int var2 = 0; var2 < var0; ++var2) {
|
||||||
Player var3 = Client.players[var1[var2]];
|
Player var3 = Client.players[var1[var2]];
|
||||||
if (var3 != null) {
|
if (var3 != null) {
|
||||||
HitSplatDefinition.calculateActorPosition(var3, 1);
|
HitSplatDefinition.updateActorSequence(var3, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user