From 85b028e3e707886c229ecc3d9ab6aaab81cdaf7b Mon Sep 17 00:00:00 2001
From: "Nick I. A" <109136581+xEntenKoeniqx@users.noreply.github.com>
Date: Sat, 13 Aug 2022 00:52:34 +0200
Subject: [PATCH] Added NAudio and first voice test
---
RageCoop.Client/Main.cs | 19 ++++++
RageCoop.Client/Menus/Sub/SettingsMenu.cs | 24 +++-----
RageCoop.Client/RageCoop.Client.csproj | 31 ++++++++++
RageCoop.Client/Settings.cs | 4 ++
RageCoop.Client/Sync/Voice.cs | 75 +++++++++++++++++++++++
RageCoop.Client/packages.config | 10 +++
RageCoop.Server/Settings.cs | 5 ++
7 files changed, 152 insertions(+), 16 deletions(-)
create mode 100644 RageCoop.Client/Sync/Voice.cs
diff --git a/RageCoop.Client/Main.cs b/RageCoop.Client/Main.cs
index 8548de9..1ad0c9b 100644
--- a/RageCoop.Client/Main.cs
+++ b/RageCoop.Client/Main.cs
@@ -47,6 +47,8 @@ namespace RageCoop.Client
///
public Main()
{
+ Sync.Voice.InitRecording();
+
Worker = new Worker("RageCoop.Client.Main.Worker", Logger);
try
{
@@ -110,6 +112,8 @@ namespace RageCoop.Client
private bool _lastDead;
private void OnTick(object sender, EventArgs e)
{
+
+
P= Game.Player.Character;
PlayerPosition=P.ReadPosition();
@@ -211,8 +215,23 @@ namespace RageCoop.Client
_lastDead=P.IsDead;
Ticked++;
}
+ private bool recording = false;
private void OnKeyDown(object sender, KeyEventArgs e)
{
+ if (e.KeyCode == Keys.B)
+ {
+ if (!recording)
+ {
+ recording = true;
+ Sync.Voice.StartRecording();
+ }
+ else
+ {
+ Sync.Voice.StopRecording();
+ recording = false;
+ }
+ }
+
if (MainChat.Focused)
{
MainChat.OnKeyDown(e.KeyCode);
diff --git a/RageCoop.Client/Menus/Sub/SettingsMenu.cs b/RageCoop.Client/Menus/Sub/SettingsMenu.cs
index dbe080f..530ac69 100644
--- a/RageCoop.Client/Menus/Sub/SettingsMenu.cs
+++ b/RageCoop.Client/Menus/Sub/SettingsMenu.cs
@@ -6,9 +6,6 @@ using System.Windows.Forms;
namespace RageCoop.Client.Menus
{
- ///
- /// Don't use it!
- ///
internal static class SettingsMenu
{
public static NativeMenu Menu = new NativeMenu("RAGECOOP", "Settings", "Go to the settings")
@@ -20,43 +17,39 @@ 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 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());
private static NativeItem _vehicleSoftLimit = new NativeItem("Vehicle limit (soft)", "The game won't spawn more NPC traffic if the limit is exceeded. \n-1 for unlimited (not recommended).", Main.Settings.WorldVehicleSoftLimit.ToString());
- ///
- /// Don't use it!
- ///
static SettingsMenu()
{
Menu.Banner.Color = Color.FromArgb(225, 0, 0, 0);
Menu.Title.Color = Color.FromArgb(255, 165, 0);
_disableTrafficItem.CheckboxChanged += DisableTrafficCheckboxChanged;
- _disablePauseAlt.CheckboxChanged+=_disablePauseAlt_CheckboxChanged;
+ _disablePauseAlt.CheckboxChanged+= DisablePauseAltCheckboxChanged;
_flipMenuItem.CheckboxChanged += FlipMenuCheckboxChanged;
- _menuKey.Activated+=ChaneMenuKey;
- _passengerKey.Activated+=ChangePassengerKey;
- _vehicleSoftLimit.Activated+=vehicleSoftLimit_Activated;
+ _menuKey.Activated+= ChaneMenuKey;
+ _passengerKey.Activated+= ChangePassengerKey;
+ _vehicleSoftLimit.Activated+= VehicleSoftLimitActivated;
Menu.Add(_disableTrafficItem);
Menu.Add(_disablePauseAlt);
Menu.Add(_flipMenuItem);
+ Menu.Add(_disableVoice);
Menu.Add(_menuKey);
Menu.Add(_passengerKey);
Menu.Add(_vehicleSoftLimit);
}
-
-
- private static void _disablePauseAlt_CheckboxChanged(object sender, EventArgs e)
+ private static void DisablePauseAltCheckboxChanged(object sender, EventArgs e)
{
Main.Settings.DisableAlternatePause=_disablePauseAlt.Checked;
Util.SaveSettings();
}
- private static void vehicleSoftLimit_Activated(object sender, EventArgs e)
+ private static void VehicleSoftLimitActivated(object sender, EventArgs e)
{
try
{
@@ -110,6 +103,5 @@ namespace RageCoop.Client.Menus
Main.Settings.FlipMenu = _flipMenuItem.Checked;
Util.SaveSettings();
}
-
}
}
diff --git a/RageCoop.Client/RageCoop.Client.csproj b/RageCoop.Client/RageCoop.Client.csproj
index 75217c7..e85c33d 100644
--- a/RageCoop.Client/RageCoop.Client.csproj
+++ b/RageCoop.Client/RageCoop.Client.csproj
@@ -57,6 +57,7 @@
+
@@ -97,6 +98,30 @@
True
True
+
+ ..\packages\Microsoft.Win32.Registry.4.7.0\lib\net461\Microsoft.Win32.Registry.dll
+
+
+ ..\packages\NAudio.2.1.0\lib\net472\NAudio.dll
+
+
+ ..\packages\NAudio.Asio.2.1.0\lib\netstandard2.0\NAudio.Asio.dll
+
+
+ ..\packages\NAudio.Core.2.1.0\lib\netstandard2.0\NAudio.Core.dll
+
+
+ ..\packages\NAudio.Midi.2.1.0\lib\netstandard2.0\NAudio.Midi.dll
+
+
+ ..\packages\NAudio.Wasapi.2.1.0\lib\netstandard2.0\NAudio.Wasapi.dll
+
+
+ ..\packages\NAudio.WinForms.2.1.0\lib\net472\NAudio.WinForms.dll
+
+
+ ..\packages\NAudio.WinMM.2.1.0\lib\netstandard2.0\NAudio.WinMM.dll
+
False
..\libs\Newtonsoft.Json.dll
@@ -205,6 +230,9 @@
True
True
+
+ ..\packages\System.Security.AccessControl.4.7.0\lib\net461\System.Security.AccessControl.dll
+
..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net463\System.Security.Cryptography.Algorithms.dll
True
@@ -225,6 +253,9 @@
True
True
+
+ ..\packages\System.Security.Principal.Windows.4.7.0\lib\net461\System.Security.Principal.Windows.dll
+
..\packages\System.Text.RegularExpressions.4.3.0\lib\net463\System.Text.RegularExpressions.dll
True
diff --git a/RageCoop.Client/Settings.cs b/RageCoop.Client/Settings.cs
index 0b6a723..a3e87a6 100644
--- a/RageCoop.Client/Settings.cs
+++ b/RageCoop.Client/Settings.cs
@@ -27,6 +27,10 @@ namespace RageCoop.Client
/// Don't use it!
///
public bool FlipMenu { get; set; } = false;
+ ///
+ /// Don't use it!
+ ///
+ public bool Voice { get; set; } = false;
///
/// LogLevel for RageCoop.
diff --git a/RageCoop.Client/Sync/Voice.cs b/RageCoop.Client/Sync/Voice.cs
new file mode 100644
index 0000000..d36234d
--- /dev/null
+++ b/RageCoop.Client/Sync/Voice.cs
@@ -0,0 +1,75 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Threading;
+
+using NAudio.Wave;
+
+namespace RageCoop.Client.Sync
+{
+ internal static class Voice
+ {
+ private static WaveInEvent _waveIn;
+ private static BufferedWaveProvider _waveProvider = new BufferedWaveProvider(new WaveFormat(16000, 16, 1));
+
+ private static Thread _thread;
+
+ public static void StopRecording()
+ {
+ _waveIn.StopRecording();
+ GTA.UI.Notification.Show("STOPPED [1]");
+ }
+
+ public static void InitRecording()
+ {
+ _thread = new Thread(new ThreadStart(() =>
+ {
+ while (true)
+ {
+ using (var wo = new WaveOutEvent())
+ {
+ wo.Init(_waveProvider);
+ wo.Play();
+
+ while (wo.PlaybackState == PlaybackState.Playing)
+ {
+ Thread.Sleep(100);
+ }
+ }
+ }
+ }));
+
+ _thread.Start();
+
+ _waveIn = new WaveInEvent
+ {
+ DeviceNumber = 0,
+ BufferMilliseconds = 20,
+ NumberOfBuffers = 1,
+ WaveFormat = _waveProvider.WaveFormat
+ };
+ _waveIn.DataAvailable += WaveInDataAvailable;
+ GTA.UI.Notification.Show("INIT");
+ }
+
+ public static void StartRecording()
+ {
+ _waveIn.StartRecording();
+ GTA.UI.Notification.Show("STARTED");
+ }
+
+ private static void WaveInDataAvailable(object sender, WaveInEventArgs e)
+ {
+ if (_waveIn == null)
+ return;
+
+ try
+ {
+ _waveProvider.AddSamples(e.Buffer, 0, e.BytesRecorded);
+ } catch (Exception ex)
+ {
+ // if some happens along the way...
+ }
+ }
+ }
+}
diff --git a/RageCoop.Client/packages.config b/RageCoop.Client/packages.config
index fae344e..9f7a5f3 100644
--- a/RageCoop.Client/packages.config
+++ b/RageCoop.Client/packages.config
@@ -5,6 +5,14 @@
+
+
+
+
+
+
+
+
@@ -38,10 +46,12 @@
+
+
diff --git a/RageCoop.Server/Settings.cs b/RageCoop.Server/Settings.cs
index ba591cf..329e302 100644
--- a/RageCoop.Server/Settings.cs
+++ b/RageCoop.Server/Settings.cs
@@ -95,6 +95,11 @@
///
public bool UseZeroTier { get; set; } = false;
+ ///
+ /// Use in-game voice chat to communicate with other players
+ ///
+ public bool UseVoice { get; set; } = false;
+
///
/// The zerotier network id to join, default value is zerotier's public Earth network.
///