Skip to content

Commit

Permalink
added config
Browse files Browse the repository at this point in the history
  • Loading branch information
WWYDF committed Oct 9, 2024
1 parent d3249c7 commit 40553e6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/Dissonance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public void SetupIncomingAudio(string targetDUID, int pSlot)
OverrideBlend(audioSourceComponent);
audioSourceComponent.spatialize = true;
audioSourceComponent.spatializePostEffects = true;
audioSourceComponent.maxDistance = 50.0f;
audioSourceComponent.minDistance = 1.0f;
audioSourceComponent.maxDistance = ProximityConfig.changeMaxDistance.Value;
audioSourceComponent.minDistance = ProximityConfig.changeMinDistance.Value;
voicePlaybackComponent._IsApplyingAudioSpatialization_k__BackingField = true;
MainPlugin.SendLog.LogInfo("[SetupAudio] Successfully enabled audio spatialization.");

Expand All @@ -103,23 +103,23 @@ public async void LinkPositionUpdater(PlayerAgent player, GameObject userObject)
var playerClone = player;
var userClone = userObject;

MainPlugin.SendLog.LogInfo($"Linking {playerName}'s position!");
MainPlugin.SendLog.LogInfo($"[PlayerLink] Linking {playerName}'s position!");
while (isInLevel && GameStateManager.CurrentStateName.ToString() == "InLevel") // Basically while true when in level.
{
if (player == null || userObject == null || !userObject.activeInHierarchy)
{
MainPlugin.SendLog.LogError($"Connection to player unexpectedly severed!");
MainPlugin.SendLog.LogError($"[PlayerLink] Connection to player unexpectedly severed!");
break;
}

userClone.transform.position = playerClone.Position;
userClone.transform.forward = playerClone.Forward;

// MainPlugin.SendLog.LogInfo($"Updated {playerName}'s X position and X rotation to {playerClone.Position.x}, {playerClone.Forward.x}");
await Task.Delay(50); // tune this
await Task.Delay(ProximityConfig.changePollingFrequency.Value);

}
MainPlugin.SendLog.LogInfo($"Unlinked {playerName}! ({isInLevel}, {GameStateManager.CurrentStateName.ToString()})");
MainPlugin.SendLog.LogInfo($"[PlayerLink] Unlinked {playerName}! ({isInLevel}, {GameStateManager.CurrentStateName.ToString()})");
}

public async void OverrideBlend(AudioSource audioSourceComponent)
Expand Down
20 changes: 19 additions & 1 deletion src/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@
using ProximityChat.SteamComms;
using ProximityChat.Dissonance;
using UnityEngine;
using BepInEx.Configuration;

namespace ProximityChat
{
[BepInPlugin("net.devante.gtfo.proximitychat", "ProximityChat", "1.0.0")]
public class ProximityConfig
{
public static ConfigEntry<float> changeMaxDistance;
public static ConfigEntry<float> changeMinDistance;
public static ConfigEntry<int> changePollingFrequency;
public static ConfigEntry<bool> enableSleeperWake;
public static ConfigEntry<bool> enableHardMode;
}

[BepInPlugin("net.devante.gtfo.proximitychat", "ProximityChat", "0.4")]
public class MainPlugin : BasePlugin
{
// Setup instance linking.
Expand Down Expand Up @@ -38,6 +48,14 @@ public static MainPlugin Instance

public override void Load() // Runs once when plugin is loaded.
{
// Enable Config
ProximityConfig.changeMaxDistance = Config.Bind("Proximity Settings", "Maximum Distance", 52f, "How far should you be able to hear other players?");
ProximityConfig.changeMinDistance = Config.Bind("Proximity Settings", "Minimum Distance", 2f, "How close should other players have to be in order to be at full volume?");
ProximityConfig.changePollingFrequency = Config.Bind("Proximity Settings", "Polling Rate", 50, "How fast Player Positions should be updated in milliseconds.");

ProximityConfig.enableSleeperWake = Config.Bind("SleeperWake", "Enabled", false, "Allows sleepers to wake up from talking near them. [HOST ONLY]");
ProximityConfig.enableHardMode = Config.Bind("SleeperWake", "Use Hard Mode?", false, "Makes sleepers instantly wake up from talking near them. (Requires base to be enabled)");

// Grab instances.
dissonanceInstance = DissonanceUtils.Instance;
slotManagerInstance = SlotManager.Instance;
Expand Down
3 changes: 1 addition & 2 deletions src/SteamComms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public void Init()
public void HostSteamP2P()
{
var DSObj = rootInstance.globalDS;
var p2pComms = DSObj.GetComponent<global::Dissonance.Integrations.SteamworksP2P.SteamworksP2PCommsNetwork>();
var p2pServer = p2pComms.Server;
var p2pServer = DSObj.GetComponent<global::Dissonance.Integrations.SteamworksP2P.SteamworksP2PCommsNetwork>().Server;

var serverClients = p2pServer._clients;
var clientsByName = serverClients._clientsByName;
Expand Down

0 comments on commit 40553e6

Please sign in to comment.