Add sounds to devtools

This commit is contained in:
WooxSolo
2018-10-18 21:35:30 +02:00
committed by Adam
parent 438fbc9b0d
commit 45766fd65e
7 changed files with 308 additions and 5 deletions

View File

@@ -24,25 +24,41 @@
*/
package net.runelite.mixins;
import net.runelite.api.events.AreaSoundEffectPlayed;
import net.runelite.api.events.SoundEffectPlayed;
import net.runelite.api.mixins.FieldHook;
import net.runelite.api.mixins.Inject;
import net.runelite.api.mixins.Mixin;
import net.runelite.api.mixins.Shadow;
import net.runelite.rs.api.RSClient;
import net.runelite.rs.api.RSSoundEffect;
@Mixin(RSClient.class)
public abstract class PlaySoundEffectMixin implements RSClient
public abstract class SoundEffectMixin implements RSClient
{
@Shadow("clientInstance")
private static RSClient client;
@Inject
private static int lastSoundEffectCount;
@Inject
@Override
public void playSoundEffect(int id)
{
playSoundEffect(id, 0, 0, 0);
playSoundEffect(id, 0, 0, 0, 0);
}
@Inject
@Override
public void playSoundEffect(int id, int x, int y, int range)
{
playSoundEffect(id, x, y, range, 0);
}
@Inject
@Override
public void playSoundEffect(int id, int x, int y, int range, int delay)
{
int position = ((x & 255) << 16) + ((y & 255) << 8) + (range & 255);
@@ -54,11 +70,51 @@ public abstract class PlaySoundEffectMixin implements RSClient
int queuedSoundEffectCount = getQueuedSoundEffectCount();
queuedSoundEffectIDs[queuedSoundEffectCount] = id;
queuedSoundEffectLoops[queuedSoundEffectCount] = 0;
queuedSoundEffectDelays[queuedSoundEffectCount] = 0;
queuedSoundEffectLoops[queuedSoundEffectCount] = 1;
queuedSoundEffectDelays[queuedSoundEffectCount] = delay;
audioEffects[queuedSoundEffectCount] = null;
soundLocations[queuedSoundEffectCount] = position;
setQueuedSoundEffectCount(queuedSoundEffectCount + 1);
}
@FieldHook("queuedSoundEffectCount")
@Inject
public static void queuedSoundEffectCountChanged(int idx)
{
int soundCount = client.getQueuedSoundEffectCount();
if (soundCount == lastSoundEffectCount + 1)
{
int soundIndex = soundCount - 1;
int packedLocation = client.getSoundLocations()[soundIndex];
if (packedLocation == 0)
{
// Regular sound effect
SoundEffectPlayed event = new SoundEffectPlayed();
event.setSoundId(client.getQueuedSoundEffectIDs()[soundIndex]);
event.setDelay(client.getQueuedSoundEffectDelays()[soundIndex]);
client.getCallbacks().post(event);
}
else
{
// Area sound effect
int x = (packedLocation >> 16) & 0xFF;
int y = (packedLocation >> 8) & 0xFF;
int range = (packedLocation) & 0xFF;
AreaSoundEffectPlayed event = new AreaSoundEffectPlayed();
event.setSoundId(client.getQueuedSoundEffectIDs()[soundIndex]);
event.setSceneX(x);
event.setSceneY(y);
event.setRange(range);
event.setDelay(client.getQueuedSoundEffectDelays()[soundIndex]);
client.getCallbacks().post(event);
}
}
lastSoundEffectCount = soundCount;
}
}