diff --git a/Modules/CustomSounds.cs b/Modules/CustomSounds.cs index 1ee86de50..4ef887e44 100644 --- a/Modules/CustomSounds.cs +++ b/Modules/CustomSounds.cs @@ -14,32 +14,40 @@ public static class CustomSoundsManager public static void RPCPlayCustomSound(this PlayerControl pc, string sound, float volume = 1f, float pitch = 1f, bool force = false) { - if (!force && (!AmongUsClient.Instance.AmHost || !pc.IsModdedClient())) return; - - if (pc == null || PlayerControl.LocalPlayer.PlayerId == pc.PlayerId) + try { - Play(sound, volume, pitch); - return; - } + if (!force && (!AmongUsClient.Instance.AmHost || !pc.IsModdedClient())) return; - MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.PlayCustomSound, SendOption.None, pc.OwnerId); - writer.Write(sound); - writer.Write(volume); - writer.Write(pitch); - AmongUsClient.Instance.FinishRpcImmediately(writer); + if (!pc || PlayerControl.LocalPlayer.PlayerId == pc.PlayerId) + { + Play(sound, volume, pitch); + return; + } + + MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.PlayCustomSound, SendOption.None, pc.OwnerId); + writer.Write(sound); + writer.Write(volume); + writer.Write(pitch); + AmongUsClient.Instance.FinishRpcImmediately(writer); + } + catch (Exception e) { Utils.ThrowException(e); } } public static void RPCPlayCustomSoundAll(string sound, float volume = 1f, float pitch = 1f) { - if (!AmongUsClient.Instance.AmHost) return; + try + { + if (!AmongUsClient.Instance.AmHost) return; - Play(sound, volume, pitch); + Play(sound, volume, pitch); - MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.PlayCustomSound, SendOption.None); - writer.Write(sound); - writer.Write(volume); - writer.Write(pitch); - AmongUsClient.Instance.FinishRpcImmediately(writer); + MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.PlayCustomSound, SendOption.None); + writer.Write(sound); + writer.Write(volume); + writer.Write(pitch); + AmongUsClient.Instance.FinishRpcImmediately(writer); + } + catch (Exception e) { Utils.ThrowException(e); } } public static void ReceiveRPC(MessageReader reader) @@ -49,31 +57,35 @@ public static class CustomSoundsManager public static void Play(string sound, float volume = 1f, float pitch = 1f) { - if (!Constants.ShouldPlaySfx() || !Main.EnableCustomSoundEffect.Value || !OperatingSystem.IsWindows()) return; - - string path = SoundsPath + sound + ".wav"; - if (!Directory.Exists(SoundsPath)) Directory.CreateDirectory(SoundsPath); - - DirectoryInfo folder = new(SoundsPath); - if ((folder.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) folder.Attributes = FileAttributes.Hidden; - - if (!File.Exists(path)) + try { - Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("EHR.Resources.Sounds." + sound + ".wav"); + if (!Constants.ShouldPlaySfx() || !Main.EnableCustomSoundEffect.Value || !OperatingSystem.IsWindows()) return; - if (stream == null) + string path = SoundsPath + sound + ".wav"; + if (!Directory.Exists(SoundsPath)) Directory.CreateDirectory(SoundsPath); + + DirectoryInfo folder = new(SoundsPath); + if ((folder.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) folder.Attributes = FileAttributes.Hidden; + + if (!File.Exists(path)) { - Logger.Warn($"Could not find sound: {sound}", "CustomSounds"); - return; + Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("EHR.Resources.Sounds." + sound + ".wav"); + + if (stream == null) + { + Logger.Warn($"Could not find sound: {sound}", "CustomSounds"); + return; + } + + FileStream fileStream = File.Create(path); + stream.CopyTo(fileStream); + fileStream.Close(); } - FileStream fileStream = File.Create(path); - stream.CopyTo(fileStream); - fileStream.Close(); + StartPlay(path, volume, pitch); + Logger.Msg($"Playing sound: {sound}", "CustomSounds"); } - - StartPlay(path, volume, pitch); - Logger.Msg($"Playing sound: {sound}", "CustomSounds"); + catch (Exception e) { Utils.ThrowException(e); } } private static readonly Dictionary audioCache = []; @@ -86,7 +98,7 @@ public static class CustomSoundsManager audioCache[path] = clip; } - if (clip != null) + if (clip) SoundManager.Instance.PlaySoundImmediate(clip, false, volume); } diff --git a/Modules/OnlinePresetsManager.cs b/Modules/OnlinePresetsManager.cs index cf4786b7a..5ce1e00e6 100644 --- a/Modules/OnlinePresetsManager.cs +++ b/Modules/OnlinePresetsManager.cs @@ -92,11 +92,15 @@ public static class OnlinePresetsManager Object.Destroy(row.transform.FindChild("Value_TMP (1)").gameObject); Object.Destroy(row.transform.FindChild("ValueBox").gameObject); + + row.OnValueChanged = new Action(menu.ValueChanged); + row.LabelBackground.transform.localScale += new Vector3(1f, 0f, 0f); + row.TitleText.GetComponent().sizeDelta = new(5.7f, 0.37f); TextMeshPro plusText = row.PlusBtn.GetComponentInChildren(); plusText.DestroyTranslator(); plusText.text = "ⓘ"; - row.PlusBtn.transform.localPosition += new Vector3(2.1f, 0f, 0f); + row.PlusBtn.transform.localPosition += new Vector3(1.8f, 0f, 0f); row.PlusBtn.OnClick = new(); row.PlusBtn.OnClick.AddListener((UnityAction)(() => { @@ -105,9 +109,6 @@ public static class OnlinePresetsManager plusText.text = b ? "∅" : "ⓘ"; })); - row.OnValueChanged = new Action(menu.ValueChanged); - row.LabelBackground.transform.localScale += new Vector3(1f, 0f, 0f); - row.TitleText.GetComponent().sizeDelta = new(5.7f, 0.37f); row.MinusBtn.transform.localPosition += new Vector3(1.7f, 0f, 0f); row.MinusBtn.OnClick = new(); row.MinusBtn.OnClick.AddListener((UnityAction)(() => diff --git a/Roles/Standard/Impostor/Concealing/Duellist.cs b/Roles/Standard/Impostor/Concealing/Duellist.cs index a9aeb0240..ea43ed41f 100644 --- a/Roles/Standard/Impostor/Concealing/Duellist.cs +++ b/Roles/Standard/Impostor/Concealing/Duellist.cs @@ -55,7 +55,7 @@ public class Duellist : RoleBase { if (!IsEnable) return false; - if (duellist == null || target == null) return false; + if (!duellist || !target) return false; Vector2 pos = Pelican.GetBlackRoomPS(); @@ -66,7 +66,7 @@ public class Duellist : RoleBase if (DuelPair.TryGetValue(duellist.PlayerId, out byte previousTargetId)) { PlayerControl previousTarget = GetPlayerById(previousTargetId); - if (previousTarget != null) previousTarget.TPToRandomVent(); + if (previousTarget) previousTarget.TPToRandomVent(); } duellist.TP(pos);