diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 6c874283..278c2054 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -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 }} \ No newline at end of file + dotnet nuget push MiraAPI/bin/Release/AllOfUs.MiraAPI.*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} \ No newline at end of file diff --git a/MiraAPI/Utilities/Assets/LoadableAudioResourceAsset.cs b/MiraAPI/Utilities/Assets/LoadableAudioResourceAsset.cs new file mode 100644 index 00000000..381e9bc2 --- /dev/null +++ b/MiraAPI/Utilities/Assets/LoadableAudioResourceAsset.cs @@ -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; + +/// +/// A utility class for loading .WAV audio assets from the DLL's embedded resources. +/// +/// The path of the wave file. +public class LoadableAudioResourceAsset(string path) : LoadableAsset +{ + private readonly Assembly _assembly = Assembly.GetCallingAssembly(); + + /// + /// Loads the asset from embedded resources. + /// + /// The asset to load. + /// Attempted to load an Audio file in non WAV format. + /// Stream failed to load. Check if the name of your asset was correct. + 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; + } +} diff --git a/README.md b/README.md index 9a8b11d4..383a41dd 100644 --- a/README.md +++ b/README.md @@ -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: