mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-11-19 13:17:10 +00:00
Merge pull request #12 from Rubyboat1207/audio-resource
Added Loadable Audio Resource Asset
This commit is contained in:
3 files changed
+72
-2
No files matched your search
@@ -46,6 +46,6 @@ jobs:
|
||||
files: MiraAPI/bin/Release/net6.0/MiraAPI.dll
|
||||
|
||||
- name: Push NuGet package
|
||||
if: github.repository == 'All-Of-Us-Mods/MiraAPI' && github.ref == 'refs/heads/master'
|
||||
if: github.ref_type == 'tag'
|
||||
run: |
|
||||
dotnet nuget push {MiraAPI/bin/Release/AllOfUs.MiraAPI.*.nupkg} --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
|
||||
dotnet nuget push MiraAPI/bin/Release/AllOfUs.MiraAPI.*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Cpp2IL.Core.Extensions;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Utilities.Assets;
|
||||
|
||||
/// <summary>
|
||||
/// A utility class for loading .WAV audio assets from the DLL's embedded resources.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the wave file.</param>
|
||||
public class LoadableAudioResourceAsset(string path) : LoadableAsset<AudioClip>
|
||||
{
|
||||
private readonly Assembly _assembly = Assembly.GetCallingAssembly();
|
||||
|
||||
/// <summary>
|
||||
/// Loads the asset from embedded resources.
|
||||
/// </summary>
|
||||
/// <returns>The asset to load.</returns>
|
||||
/// <exception cref="NotSupportedException">Attempted to load an Audio file in non WAV format.</exception>
|
||||
/// <exception cref="FileNotFoundException">Stream failed to load. Check if the name of your asset was correct.</exception>
|
||||
public override AudioClip LoadAsset()
|
||||
{
|
||||
var assetStream = _assembly.GetManifestResourceStream(path) ??
|
||||
throw new FileNotFoundException(
|
||||
"Stream failed to load. Check if the name of your asset was correct.");
|
||||
var audioBytes = assetStream.ReadFully();
|
||||
|
||||
var riffHeader = Encoding.ASCII.GetString(audioBytes.SubArray(0, 4));
|
||||
var waveHeader = Encoding.ASCII.GetString(audioBytes.SubArray(8, 4));
|
||||
|
||||
if (riffHeader != "RIFF" || waveHeader != "WAVE")
|
||||
{
|
||||
throw new NotSupportedException($"Attempted to load an Audio file in non WAV format '{path}'.");
|
||||
}
|
||||
|
||||
int channels = BitConverter.ToInt16(audioBytes, 22);
|
||||
var sampleRate = BitConverter.ToInt32(audioBytes, 24);
|
||||
var dataSize = BitConverter.ToInt32(audioBytes, 40);
|
||||
|
||||
var audioData = new float[dataSize / 2];
|
||||
for (var i = 0; i < audioData.Length; i++)
|
||||
{
|
||||
audioData[i] = BitConverter.ToInt16(audioBytes, 44 + i * 2) / 32768.0f;
|
||||
}
|
||||
|
||||
var audioClip = AudioClip.Create(
|
||||
path,
|
||||
audioData.Length,
|
||||
channels,
|
||||
sampleRate,
|
||||
false
|
||||
);
|
||||
audioClip.SetData(audioData, 0);
|
||||
|
||||
return audioClip;
|
||||
}
|
||||
}
|
||||
@@ -177,6 +177,15 @@ public class MyOptionsGroup : AbstractOptionGroup
|
||||
|
||||
An example can be found [here](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Options/Roles/CustomRoleSettings.cs).
|
||||
|
||||
## Custom Murders
|
||||
Mira API provides it's own implementation for murders. Our implementation allows for more customization on kills, and helps bypass server checks.
|
||||
You can use `PlayerControl.RpcCustomMurder` to perform a networked custom murder, or `PlayerControl.CustomMurder` to normally perform a custom murder.
|
||||
For example:
|
||||
```cs
|
||||
PlayerControl.LocalPlayer.RpcCustomMurder(Target, createDeadBody: false, teleportMurderer: false, playKillSound: false, resetKillTimer: false, showKillAnim: false);
|
||||
```
|
||||
This will kill a player without creating a dead body and without teleporting the murderer.
|
||||
|
||||
## Buttons
|
||||
|
||||
Mira API provides a simple interface for adding ability buttons to the game. There is only 2 steps:
|
||||
|
||||
Reference in new issue
Block a user