Added NAudio and first voice test
This commit is contained in:
@ -47,6 +47,8 @@ namespace RageCoop.Client
|
||||
/// </summary>
|
||||
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);
|
||||
|
@ -6,9 +6,6 @@ using System.Windows.Forms;
|
||||
|
||||
namespace RageCoop.Client.Menus
|
||||
{
|
||||
/// <summary>
|
||||
/// Don't use it!
|
||||
/// </summary>
|
||||
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());
|
||||
|
||||
/// <summary>
|
||||
/// Don't use it!
|
||||
/// </summary>
|
||||
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;
|
||||
_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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,7 @@
|
||||
<Compile Include="Sync\Entities\SyncedVehicle.cs" />
|
||||
<Compile Include="Sync\EntityPool.cs" />
|
||||
<Compile Include="Sync\SyncEvents.cs" />
|
||||
<Compile Include="Sync\Voice.cs" />
|
||||
<Compile Include="Util\Memory.cs" />
|
||||
<Compile Include="Util\NativeCaller.cs" />
|
||||
<Compile Include="Util\PedConfigFlags.cs" />
|
||||
@ -97,6 +98,30 @@
|
||||
<Private>True</Private>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Win32.Registry, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Win32.Registry.4.7.0\lib\net461\Microsoft.Win32.Registry.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NAudio, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NAudio.2.1.0\lib\net472\NAudio.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NAudio.Asio, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NAudio.Asio.2.1.0\lib\netstandard2.0\NAudio.Asio.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NAudio.Core, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NAudio.Core.2.1.0\lib\netstandard2.0\NAudio.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NAudio.Midi, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NAudio.Midi.2.1.0\lib\netstandard2.0\NAudio.Midi.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NAudio.Wasapi, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NAudio.Wasapi.2.1.0\lib\netstandard2.0\NAudio.Wasapi.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NAudio.WinForms, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NAudio.WinForms.2.1.0\lib\net472\NAudio.WinForms.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NAudio.WinMM, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NAudio.WinMM.2.1.0\lib\netstandard2.0\NAudio.WinMM.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\libs\Newtonsoft.Json.dll</HintPath>
|
||||
@ -205,6 +230,9 @@
|
||||
<Private>True</Private>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Security.AccessControl, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Security.AccessControl.4.7.0\lib\net461\System.Security.AccessControl.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Security.Cryptography.Algorithms, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net463\System.Security.Cryptography.Algorithms.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
@ -225,6 +253,9 @@
|
||||
<Private>True</Private>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Security.Principal.Windows, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Security.Principal.Windows.4.7.0\lib\net461\System.Security.Principal.Windows.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Text.RegularExpressions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Text.RegularExpressions.4.3.0\lib\net463\System.Text.RegularExpressions.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
|
@ -27,6 +27,10 @@ namespace RageCoop.Client
|
||||
/// Don't use it!
|
||||
/// </summary>
|
||||
public bool FlipMenu { get; set; } = false;
|
||||
/// <summary>
|
||||
/// Don't use it!
|
||||
/// </summary>
|
||||
public bool Voice { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// LogLevel for RageCoop.
|
||||
|
75
RageCoop.Client/Sync/Voice.cs
Normal file
75
RageCoop.Client/Sync/Voice.cs
Normal file
@ -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...
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -5,6 +5,14 @@
|
||||
<package id="Microsoft.Extensions.ObjectPool" version="6.0.8" targetFramework="net48" />
|
||||
<package id="Microsoft.NETCore.Platforms" version="1.1.0" targetFramework="net48" />
|
||||
<package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net48" />
|
||||
<package id="Microsoft.Win32.Registry" version="4.7.0" targetFramework="net481" />
|
||||
<package id="NAudio" version="2.1.0" targetFramework="net481" />
|
||||
<package id="NAudio.Asio" version="2.1.0" targetFramework="net481" />
|
||||
<package id="NAudio.Core" version="2.1.0" targetFramework="net481" />
|
||||
<package id="NAudio.Midi" version="2.1.0" targetFramework="net481" />
|
||||
<package id="NAudio.Wasapi" version="2.1.0" targetFramework="net481" />
|
||||
<package id="NAudio.WinForms" version="2.1.0" targetFramework="net481" />
|
||||
<package id="NAudio.WinMM" version="2.1.0" targetFramework="net481" />
|
||||
<package id="NETStandard.Library" version="1.6.1" targetFramework="net48" />
|
||||
<package id="SharpZipLib" version="1.3.3" targetFramework="net48" />
|
||||
<package id="System.AppContext" version="4.3.0" targetFramework="net48" />
|
||||
@ -38,10 +46,12 @@
|
||||
<package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="net48" />
|
||||
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net48" />
|
||||
<package id="System.Runtime.Numerics" version="4.3.0" targetFramework="net48" />
|
||||
<package id="System.Security.AccessControl" version="4.7.0" targetFramework="net481" />
|
||||
<package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net48" />
|
||||
<package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net48" />
|
||||
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net48" />
|
||||
<package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net48" />
|
||||
<package id="System.Security.Principal.Windows" version="4.7.0" targetFramework="net481" />
|
||||
<package id="System.Text.Encoding" version="4.3.0" targetFramework="net48" />
|
||||
<package id="System.Text.Encoding.Extensions" version="4.3.0" targetFramework="net48" />
|
||||
<package id="System.Text.RegularExpressions" version="4.3.0" targetFramework="net48" />
|
||||
|
@ -95,6 +95,11 @@
|
||||
/// </summary>
|
||||
public bool UseZeroTier { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Use in-game voice chat to communicate with other players
|
||||
/// </summary>
|
||||
public bool UseVoice { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// The zerotier network id to join, default value is zerotier's public Earth network.
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user