From 11d105dd2361d090de087eae89f3b9f6af8b2635 Mon Sep 17 00:00:00 2001 From: warquys <64769541+warquys@users.noreply.github.com> Date: Wed, 14 Dec 2022 16:45:34 +0100 Subject: [PATCH] Push Code To Public --- VT-Api/Core/Audio/AudioManager.cs | 10 +++--- VT-Api/Core/Audio/Controller.cs | 31 ++++++++++++++----- VT-Api/Core/Audio/FakeMicrophone.cs | 5 +-- VT-Api/Core/Translation/TranslationManager.cs | 2 +- .../ItemPatches/ChangeIntoGrenadePatch.cs | 4 +-- VT-Api/VtController.cs | 12 +++---- 6 files changed, 41 insertions(+), 23 deletions(-) diff --git a/VT-Api/Core/Audio/AudioManager.cs b/VT-Api/Core/Audio/AudioManager.cs index 9d5806f..d29886d 100644 --- a/VT-Api/Core/Audio/AudioManager.cs +++ b/VT-Api/Core/Audio/AudioManager.cs @@ -6,7 +6,7 @@ namespace VT_Api.Core.Audio { - public class AudioManager + internal class AudioManager { #region Attributes & Properties public static AudioManager Get => Singleton.Instance; @@ -16,7 +16,8 @@ public class AudioManager #endregion #region Constructors & Destructor - internal AudioManager() { + internal AudioManager() + { Synapse.Api.Logger.Get.Debug("AudioRun"); } @@ -27,13 +28,12 @@ internal AudioManager() { internal void Init() { - //_controller = new Controller(); + _controller = new Controller(); } public void Loop(bool enabled) { _controller.Loop = enabled; - //Synapse.Api.Logger.Get.Info($"Loop : {_controller.Loop}"); } private void UnmutePlayer(Player player) @@ -45,6 +45,8 @@ private void UnmutePlayer(Player player) private void MutePlayer(Player player) { var id = player.Radio.mirrorIgnorancePlayer._playerId; + if (_controller.MutedPlayers.Contains(id)) + return; _controller.MutePlayer(id); } diff --git a/VT-Api/Core/Audio/Controller.cs b/VT-Api/Core/Audio/Controller.cs index 3ff646b..3c0d6cf 100644 --- a/VT-Api/Core/Audio/Controller.cs +++ b/VT-Api/Core/Audio/Controller.cs @@ -17,9 +17,24 @@ internal class Controller public FakeMicrophone Microphone; public bool Loop { get; set; } - public float Volume { get; set; } = 1; - public readonly List MutedPlayers = new List(); + public float _volume; + /// + /// It was in % + /// + public float Volume + { + get + { + return _volume * 100; + } + set + { + _volume = Mathf.Clamp(value, 0, 100) / 100; + } + } + + public List MutedPlayers { get; } = new List(); #endregion #region Constructors & Destructor @@ -36,11 +51,12 @@ public Controller() public void UnMutePlayer(string playerId) { MutedPlayers.Remove(playerId); - UnMutePlayer(playerId); - Comms.PlayerChannels.Open(playerId, false, ChannelPriority.Default, Volume); + Comms.PlayerChannels.Open(playerId, false, ChannelPriority.Default, _volume); } + public void MutePlayer(string playerId) { + MutedPlayers.Add(playerId); var channel = Comms.PlayerChannels._openChannelsBySubId.FirstOrDefault(x => x.Value.TargetId == playerId); Comms.PlayerChannels.Close(channel.Value); } @@ -68,7 +84,7 @@ public IEnumerator PlayFromFile(string path, float volume = 100, bool loo yield return Timing.WaitForOneFrame; yield return Timing.WaitForOneFrame; - Volume = Mathf.Clamp(volume, 0, 100) / 100; + Volume = volume; RefreshChannels(); Microphone.File = new FileStream(path, FileMode.Open); @@ -90,7 +106,7 @@ public void RefreshChannels() foreach (var channel in Comms.PlayerChannels._openChannelsBySubId.Values.ToList()) { Comms.PlayerChannels.Close(channel); - Comms.PlayerChannels.Open(channel.TargetId, false, ChannelPriority.Default, Volume); + Comms.PlayerChannels.Open(channel.TargetId, false, ChannelPriority.Default, _volume); } } @@ -112,10 +128,9 @@ private void OnWaitingForPlayers() private void OnPlayerJoinedSession(VoicePlayerState player) { - Comms.PlayerChannels.Open(player.Name, false, ChannelPriority.Default, Volume); + Comms.PlayerChannels.Open(player.Name, false, ChannelPriority.Default, _volume); } #endregion - } } diff --git a/VT-Api/Core/Audio/FakeMicrophone.cs b/VT-Api/Core/Audio/FakeMicrophone.cs index 6de848e..449e358 100644 --- a/VT-Api/Core/Audio/FakeMicrophone.cs +++ b/VT-Api/Core/Audio/FakeMicrophone.cs @@ -1,4 +1,5 @@ -using Dissonance.Audio.Capture; +using Dissonance; +using Dissonance.Audio.Capture; using Dissonance.Networking; using NAudio.Wave; using System; @@ -24,7 +25,7 @@ internal class FakeMicrophone : MonoBehaviour, IMicrophoneCapture private readonly WaveFormat _format = new WaveFormat(48000, 1); private readonly float[] _frame = new float[960]; - private readonly byte[] _frameBytes = new byte[960 * 4]; + private readonly byte[] _frameBytes = new byte[960 * sizeof(float)]; private float _elapsedTime; diff --git a/VT-Api/Core/Translation/TranslationManager.cs b/VT-Api/Core/Translation/TranslationManager.cs index b2f6aa0..55c176f 100644 --- a/VT-Api/Core/Translation/TranslationManager.cs +++ b/VT-Api/Core/Translation/TranslationManager.cs @@ -14,7 +14,7 @@ namespace VT_Api.Core.Translation { - public class TranslationManager + internal class TranslationManager { #region Properties & Variables diff --git a/VT-Api/Patches/VtEvent/ItemPatches/ChangeIntoGrenadePatch.cs b/VT-Api/Patches/VtEvent/ItemPatches/ChangeIntoGrenadePatch.cs index c1ba035..9d6115e 100644 --- a/VT-Api/Patches/VtEvent/ItemPatches/ChangeIntoGrenadePatch.cs +++ b/VT-Api/Patches/VtEvent/ItemPatches/ChangeIntoGrenadePatch.cs @@ -12,7 +12,7 @@ namespace VT_Api.Patches.VtEvent.ItemPatches class ChangeIntoFragPatch { [HarmonyPrefix] - private static bool ExplosionDetectedPatch(TimedGrenadePickup __instance, Footprint attacker, Vector3 source, float range) + private static bool ExplosionDetectedPatch(TimedGrenadePickup __instance, object attacker, Vector3 error, Vector3 source, float range) { try { @@ -28,7 +28,7 @@ private static bool ExplosionDetectedPatch(TimedGrenadePickup __instance, Footpr return false; __instance._replaceNextFrame = true; - __instance._attacker = attacker; + __instance._attacker = (Footprint)attacker; } return false; } diff --git a/VT-Api/VtController.cs b/VT-Api/VtController.cs index c69e4ea..fda50e4 100644 --- a/VT-Api/VtController.cs +++ b/VT-Api/VtController.cs @@ -26,7 +26,7 @@ public class VtController public static VtController Get { get; private set; } internal AutoRegisterManager AutoRegister { get => Singleton.Instance; } // nothing public (yet) - public AudioManager Audio { get => Singleton.Instance; } + internal AudioManager Audio { get => Singleton.Instance; } // need patch internal MiniGameManager MinGames { get => Singleton.Instance; } // not finish public RoleManager Role { get => Singleton.Instance; } public TeamManager Team { get => Singleton.Instance; } @@ -34,7 +34,7 @@ public class VtController public MapAndRoundManger MapAction { get => Singleton.Instance; } public NetworkLiar NetworkLiar { get => Singleton.Instance; } public ItemManager Item { get => Singleton.Instance; } - public TranslationManager Translation { get => Singleton.Instance; } + internal TranslationManager Translation { get => Singleton.Instance; } // not finish internal NpcManger Npc { get => Singleton.Instance; } // not finish internal CommandHandler Commands { get => Singleton.Instance; } // nothing public (yet) @@ -97,16 +97,16 @@ private void LogMessage() private void InitAll() { TryInit(AutoRegister.Init, "Initialising AutoRegister failed"); - TryInit(Audio.Init, "Initialising Audio failed"); - TryInit(MinGames.Init, "Initialising MinGames failed"); + //TryInit(Audio.Init, "Initialising Audio failed"); + //TryInit(MinGames.Init, "Initialising MinGames failed"); TryInit(Events.Init, "Initialising Events failed"); TryInit(Commands.Init, "Initialising Commands failed"); TryInit(Configs.Init, "Initialising Configs failed"); TryInit(Team.Init, "Initialising Team failed"); TryInit(Role.Init, "Initialising Role failed"); TryInit(Item.Init, "Initialising Item failed"); - TryInit(Translation.Init, "Initialising Translation failed"); - TryInit(Npc.Init, "Initialising Npc failed"); + //TryInit(Translation.Init, "Initialising Translation failed"); + //TryInit(Npc.Init, "Initialising Npc failed"); } private void TryInit(Action init, string msg)