This commit is contained in:
Sardelka 2022-08-14 10:36:08 +08:00
commit a7dab1e0e1
5 changed files with 25 additions and 29 deletions

View File

@ -204,7 +204,7 @@ namespace RageCoop.Client
Sync.Voice.StartRecording();
return;
}
else if (Sync.Voice.IsRecording)
else if (Sync.Voice.IsRecording())
{
Sync.Voice.StopRecording();
return;

View File

@ -17,7 +17,7 @@ namespace RageCoop.Client.Menus
private static readonly NativeCheckboxItem _disableTrafficItem = new NativeCheckboxItem("Disable Traffic (NPCs/Vehicles)", "Local traffic only", Main.Settings.DisableTraffic);
private static readonly NativeCheckboxItem _flipMenuItem = new NativeCheckboxItem("Flip menu", Main.Settings.FlipMenu);
private static readonly NativeCheckboxItem _disablePauseAlt = new NativeCheckboxItem("Disable Alternate Pause", "Don't freeze game time when Esc pressed", Main.Settings.DisableTraffic);
private static readonly NativeCheckboxItem _disableVoice = new NativeCheckboxItem("Enable/Disable the voice", Main.Settings.Voice);
private static readonly NativeCheckboxItem _disableVoice = new NativeCheckboxItem("Enable voice", "Check your GTA:V settings to find the right key on your keyboard for PushToTalk and talk to your friends", Main.Settings.Voice);
private static NativeItem _menuKey = new NativeItem("Menu Key", "The key to open menu", Main.Settings.MenuKey.ToString());
private static NativeItem _passengerKey = new NativeItem("Passenger Key", "The key to enter a vehicle as passenger", Main.Settings.PassengerKey.ToString());
@ -47,9 +47,12 @@ namespace RageCoop.Client.Menus
private static void DisableVoiceCheckboxChanged(object sender, EventArgs e)
{
if (_disableVoice.Checked && !Sync.Voice.WasInitialized())
if (_disableVoice.Checked)
{
Sync.Voice.InitRecording();
if (Networking.IsOnServer && !Sync.Voice.WasInitialized())
{
Sync.Voice.Init();
}
} else {
Sync.Voice.ClearAll();
}

View File

@ -79,7 +79,7 @@ namespace RageCoop.Client
Main.MainChat.Init();
if (Main.Settings.Voice && !Sync.Voice.WasInitialized())
{
Sync.Voice.InitRecording();
Sync.Voice.Init();
}
GTA.UI.Notification.Show("~g~Connected!");
});
@ -95,7 +95,7 @@ namespace RageCoop.Client
if (PlayerList.Players.TryGetValue(p.ID,out var player))
{
player.Connection=message.SenderConnection;
Main.Logger.Debug($"Direct connectionn to {player.Username} established");
Main.Logger.Debug($"Direct connection to {player.Username} established");
}
else
{

View File

@ -6,15 +6,13 @@ namespace RageCoop.Client.Sync
{
internal static class Voice
{
private static bool _initialized = false;
public static bool IsRecording = false;
private static WaveInEvent _waveIn;
private static BufferedWaveProvider _waveProvider = new BufferedWaveProvider(new WaveFormat(16000, 16, 1));
private static readonly BufferedWaveProvider _waveProvider = new BufferedWaveProvider(new WaveFormat(16000, 16, 1));
private static Thread _thread;
public static bool WasInitialized() => _initialized;
public static bool WasInitialized() => _thread != null;
public static bool IsRecording() => _waveIn != null;
public static void ClearAll()
{
_waveProvider.ClearBuffer();
@ -26,25 +24,21 @@ namespace RageCoop.Client.Sync
_thread.Abort();
_thread = null;
}
_initialized = false;
}
public static void StopRecording()
{
if (_waveIn != null)
{
_waveIn.StopRecording();
_waveIn.Dispose();
_waveIn = null;
}
if (!IsRecording())
return;
IsRecording = false;
_waveIn.StopRecording();
_waveIn.Dispose();
_waveIn = null;
}
public static void InitRecording()
public static void Init()
{
if (_initialized)
if (WasInitialized())
return;
// I tried without thread but the game will lag without
@ -65,17 +59,13 @@ namespace RageCoop.Client.Sync
}
}));
_thread.Start();
_initialized = true;
}
public static void StartRecording()
{
if (IsRecording)
if (IsRecording())
return;
IsRecording = true;
_waveIn = new WaveInEvent
{
DeviceNumber = 0,
@ -95,7 +85,7 @@ namespace RageCoop.Client.Sync
private static void WaveInDataAvailable(object sender, WaveInEventArgs e)
{
if (_waveIn == null || !IsRecording)
if (!IsRecording())
return;
Networking.SendVoiceMessage(e.Buffer, e.BytesRecorded);

View File

@ -486,7 +486,10 @@ namespace RageCoop.Server
case PacketType.Voice:
{
Forward(data.GetPacket<Packets.Voice>(),sender,ConnectionChannel.Voice);
if (Settings.UseVoice)
{
Forward(data.GetPacket<Packets.Voice>(), sender, ConnectionChannel.Voice);
}
}
break;