Slayer Points command and some Renaming. (#966)
* Renaming and Tests for Sound Effects in cache. * SlayerPlugin: added !points command.
This commit is contained in:
committed by
Tyler Bochard
parent
bde9e9c236
commit
eaeedbaadb
@@ -27,11 +27,16 @@ package net.runelite.cache;
|
||||
import com.google.common.io.Files;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import java.io.File;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import net.runelite.cache.definitions.loaders.sound.SoundEffectLoader;
|
||||
import net.runelite.cache.definitions.sound.SoundEffectDefinition;
|
||||
import net.runelite.cache.definitions.loaders.sound.SoundEffectTrackLoader;
|
||||
import net.runelite.cache.definitions.sound.SoundEffectTrackDefinition;
|
||||
import net.runelite.cache.fs.Archive;
|
||||
import net.runelite.cache.fs.Index;
|
||||
import net.runelite.cache.fs.Storage;
|
||||
@@ -42,6 +47,11 @@ import org.junit.rules.TemporaryFolder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.sound.sampled.AudioFileFormat;
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
|
||||
public class SoundEffectsDumperTest
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(SoundEffectsDumperTest.class);
|
||||
@@ -68,14 +78,68 @@ public class SoundEffectsDumperTest
|
||||
{
|
||||
byte[] contents = archive.decompress(storage.loadArchive(archive));
|
||||
|
||||
SoundEffectLoader soundEffectLoader = new SoundEffectLoader();
|
||||
SoundEffectDefinition soundEffect = soundEffectLoader.load(contents);
|
||||
SoundEffectTrackLoader setLoader = new SoundEffectTrackLoader();
|
||||
SoundEffectTrackDefinition soundEffect = setLoader.load(contents);
|
||||
|
||||
Files.asCharSink(new File(dumpDir, archive.getArchiveId() + ".json"), Charset.defaultCharset()).write(gson.toJson(soundEffect));
|
||||
Files.write(gson.toJson(soundEffect), new File(dumpDir, archive.getArchiveId() + ".json"), Charset.defaultCharset());
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("Dumped {} sound effects to {}", count, dumpDir);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractWavTest() throws IOException
|
||||
{
|
||||
File dumpDir = folder.newFolder();
|
||||
int count = 0;
|
||||
|
||||
try (Store store = new Store(StoreLocation.LOCATION))
|
||||
{
|
||||
store.load();
|
||||
|
||||
Storage storage = store.getStorage();
|
||||
Index index = store.getIndex(IndexType.SOUNDEFFECTS);
|
||||
|
||||
for (Archive archive : index.getArchives())
|
||||
{
|
||||
byte[] contents = archive.decompress(storage.loadArchive(archive));
|
||||
|
||||
SoundEffectTrackLoader setLoader = new SoundEffectTrackLoader();
|
||||
SoundEffectTrackDefinition soundEffect = setLoader.load(contents);
|
||||
try
|
||||
{
|
||||
Object audioStream;
|
||||
byte[] data = soundEffect.mix();
|
||||
|
||||
AudioFormat audioFormat = new AudioFormat(22050.0f, 8, 1, true, false);
|
||||
audioStream = new AudioInputStream(new ByteArrayInputStream(data), audioFormat, data.length);
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
AudioSystem.write((AudioInputStream) audioStream, AudioFileFormat.Type.WAVE, bos);
|
||||
data = bos.toByteArray();
|
||||
|
||||
FileOutputStream fos = new FileOutputStream(new File(dumpDir, archive.getArchiveId() + ".wav"));
|
||||
|
||||
try
|
||||
{
|
||||
fos.write(data);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fos.close();
|
||||
}
|
||||
|
||||
++count;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("Dumped {} sound effects to {}", count, dumpDir);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user