Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #9 from VT-DevGiT/devlopement
Browse files Browse the repository at this point in the history
V1.3.0
  • Loading branch information
warquys authored Dec 14, 2022
2 parents 139cdb6 + ec805c3 commit 0fc06f8
Show file tree
Hide file tree
Showing 54 changed files with 1,379 additions and 273 deletions.
13 changes: 13 additions & 0 deletions .idea/.idea.VT-Api/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/.idea.VT-Api/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.VT-Api/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.VT-Api/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Exemple-Plugin/Exemple-Plugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@
<HintPath>..\packages\Lib.Harmony.2.2.1\lib\net48\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SynapseSL.2.10.0\lib\net472\Assembly-CSharp.dll</HintPath>
<HintPath>..\packages\SynapseSL.2.10.1\lib\net472\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SynapseSL.2.10.0\lib\net472\Assembly-CSharp-firstpass.dll</HintPath>
<HintPath>..\packages\SynapseSL.2.10.1\lib\net472\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="LiteDB, Version=5.0.11.0, Culture=neutral, PublicKeyToken=4ee40123013c9f27, processorArchitecture=MSIL">
<HintPath>..\packages\LiteDB.5.0.11\lib\net45\LiteDB.dll</HintPath>
</Reference>
<Reference Include="Mirror, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SynapseSL.2.10.0\lib\net472\Mirror.dll</HintPath>
<HintPath>..\packages\SynapseSL.2.10.1\lib\net472\Mirror.dll</HintPath>
</Reference>
<Reference Include="Synapse, Version=2.10.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SynapseSL.2.10.0\lib\net472\Synapse.dll</HintPath>
<Reference Include="Synapse, Version=2.10.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SynapseSL.2.10.1\lib\net472\Synapse.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -59,13 +59,13 @@
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SynapseSL.2.10.0\lib\net472\UnityEngine.dll</HintPath>
<HintPath>..\packages\SynapseSL.2.10.1\lib\net472\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SynapseSL.2.10.0\lib\net472\UnityEngine.CoreModule.dll</HintPath>
<HintPath>..\packages\SynapseSL.2.10.1\lib\net472\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SynapseSL.2.10.0\lib\net472\UnityEngine.PhysicsModule.dll</HintPath>
<HintPath>..\packages\SynapseSL.2.10.1\lib\net472\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
<Reference Include="YamlDotNet, Version=11.0.0.0, Culture=neutral, PublicKeyToken=ec19458f3c15af5e, processorArchitecture=MSIL">
<HintPath>..\packages\YamlDotNet.11.2.1\lib\net45\YamlDotNet.dll</HintPath>
Expand Down
2 changes: 1 addition & 1 deletion Exemple-Plugin/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<packages>
<package id="Lib.Harmony" version="2.2.1" targetFramework="net48" />
<package id="LiteDB" version="5.0.11" targetFramework="net48" />
<package id="SynapseSL" version="2.10.0" targetFramework="net48" />
<package id="SynapseSL" version="2.10.1" targetFramework="net48" />
<package id="YamlDotNet" version="11.2.1" targetFramework="net48" />
</packages>
18 changes: 12 additions & 6 deletions VT-Api/Config/Config.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
using Synapse.Config;
using Synapse.Translation;
using VT_Api.Core;
using VT_Api.Reflexion;

namespace VT_Api.Config
{
public class Config
{
public static Config Get { get => VtController.Get.Configs; }

public VtApiConfiguration VtConfiguration;
#region Properties & Variable
public static Config Get => Singleton<Config>.Instance;


public SynapseTranslation<VtApiTranslation> VtTranslation;
public VtApiConfiguration VtConfiguration { get; private set; }
public SynapseTranslation<VtApiTranslation> VtTranslation { get; private set; }
public SynapseConfiguration SynapseConfiguration => Synapse.Server.Get.Configs.GetFieldValueOrPerties<SynapseConfiguration>("synapseConfiguration");
#endregion

#region Constructor & Destructor
internal Config() { }
#endregion


#region Methods
internal void Init()
{
VtTranslation = new SynapseTranslation<VtApiTranslation>(SynapseController.Server.Files.GetTranslationPath("Vt-Api"));
Expand All @@ -36,12 +41,13 @@ internal void Init()
RankOver = "VOUS POUVEZ LUI DONNER DES ORDRES",
RankSame = "MÊME NIVEAU D'ACCRÉDITATION",
RankUnder = "SUIVEZ SES ORDRES",
DefaultDeathMessage = "Vous avez été tué par:\\n%PlayerName%\\nen tent que:\\n%RoleName%"
DefaultDeathMessage = "Vous avez été tué par:\\n%PlayerName%\\nen tant que:\\n%RoleName%"

}, "FRENCH");

VtConfiguration = new VtApiConfiguration();
VtConfiguration = Synapse.Server.Get.Configs.GetOrSetDefault("VT-API", new VtApiConfiguration());
}
#endregion
}
}
2 changes: 2 additions & 0 deletions VT-Api/Config/VtApiTranslation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ public class VtApiTranslation : IPluginTranslation

[Description("The death message when you are kill by a custom class of the VT-API")]
public string DefaultDeathMessage { get; set; } = "You were killed by\\n%PlayerName%\\nas\\n%RoleName%";


}
}
79 changes: 79 additions & 0 deletions VT-Api/Core/Audio/AudioManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using MEC;
using Synapse.Api;
using System.IO;
using UnityEngine;
using VT_Api.Extension;

namespace VT_Api.Core.Audio
{
public class AudioManager
{
#region Attributes & Properties
public static AudioManager Get => Singleton<AudioManager>.Instance;

private Controller _controller;

#endregion

#region Constructors & Destructor
internal AudioManager() {

Synapse.Api.Logger.Get.Debug("AudioRun");
}

#endregion

#region Methods

internal void Init()
{
//_controller = new Controller();
}

public void Loop(bool enabled)
{
_controller.Loop = enabled;
//Synapse.Api.Logger.Get.Info($"Loop : {_controller.Loop}");
}

private void UnmutePlayer(Player player)
{
var id = player.Radio.mirrorIgnorancePlayer._playerId;
_controller.UnMutePlayer(id);
}

private void MutePlayer(Player player)
{
var id = player.Radio.mirrorIgnorancePlayer._playerId;
_controller.MutePlayer(id);
}

public bool Play(string mpgFilePath)
{
if (!File.Exists(mpgFilePath))
{
Synapse.Api.Logger.Get.Info($"File not found : {mpgFilePath}");
return false;
}

Timing.RunCoroutine(_controller.PlayFromFile(mpgFilePath));
//Synapse.Api.Logger.Get.Info("Playing.");
return true;
}

public void Stop()
{
_controller.Stop();
//Synapse.Api.Logger.Get.Info("Stopped.");
}

public void Volume(uint volume)
{
_controller.Volume = Mathf.Clamp(volume, 0, 100) / 100;
_controller.RefreshChannels();

//Synapse.Api.Logger.Get.Info($"Volume set to {volume}.");
}
#endregion
}
}
121 changes: 121 additions & 0 deletions VT-Api/Core/Audio/Controller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
using Assets._Scripts.Dissonance;
using Dissonance;
using MEC;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
using VT_Api.Reflexion;

namespace VT_Api.Core.Audio
{
internal class Controller
{

#region Attributes & Properties
public DissonanceComms Comms => Radio.comms;
public FakeMicrophone Microphone;

public bool Loop { get; set; }
public float Volume { get; set; } = 1;

public readonly List<string> MutedPlayers = new List<string>();
#endregion

#region Constructors & Destructor

public Controller()
{
Microphone = Comms.gameObject.AddComponent<FakeMicrophone>();
Microphone.AudioController = this;
InitEvents();
}
#endregion

#region Methods
public void UnMutePlayer(string playerId)
{
MutedPlayers.Remove(playerId);
UnMutePlayer(playerId);
Comms.PlayerChannels.Open(playerId, false, ChannelPriority.Default, Volume);
}
public void MutePlayer(string playerId)
{
var channel = Comms.PlayerChannels._openChannelsBySubId.FirstOrDefault(x => x.Value.TargetId == playerId);
Comms.PlayerChannels.Close(channel.Value);
}

private void InitEvents()
{
Synapse.Server.Get.Events.Round.RoundRestartEvent += OnRestartingRound;
Synapse.Server.Get.Events.Round.WaitingForPlayersEvent += OnWaitingForPlayers;

}

public IEnumerator<float> PlayFromFile(string path, float volume = 100, bool loop = false)
{
if (string.IsNullOrWhiteSpace(path))
yield break;

if (!File.Exists(path))
{
Synapse.Api.Logger.Get.Error($"Error File not found: {path}.");
yield break;
}

Stop();

yield return Timing.WaitForOneFrame;
yield return Timing.WaitForOneFrame;

Volume = Mathf.Clamp(volume, 0, 100) / 100;
RefreshChannels();

Microphone.File = new FileStream(path, FileMode.Open);
Microphone.Stop = false;
Comms._capture.SetField("_microphone", Microphone);
Comms.ResetMicrophoneCapture();
Comms.IsMuted = false;
Loop = loop;
}

public void Stop()
{
if (Microphone != null)
Microphone.Stop = true;
}

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);
}
}

#endregion


#region Events
private void OnRestartingRound()
{
Comms.OnPlayerJoinedSession -= OnPlayerJoinedSession;
}

private void OnWaitingForPlayers()
{
Comms.OnPlayerJoinedSession += OnPlayerJoinedSession;
Synapse.Server.Get.Host.Radio.Network_syncPrimaryVoicechatButton = true;
Synapse.Server.Get.Host.DissonanceUserSetup.NetworkspeakingFlags = SpeakingFlags.IntercomAsHuman;
}

private void OnPlayerJoinedSession(VoicePlayerState player)
{
Comms.PlayerChannels.Open(player.Name, false, ChannelPriority.Default, Volume);
}

#endregion

}
}
Loading

0 comments on commit 0fc06f8

Please sign in to comment.