Skip to content

Commit

Permalink
Fix timing issues in DNet
Browse files Browse the repository at this point in the history
  • Loading branch information
DaXcess committed Mar 5, 2024
1 parent c2a7396 commit 9d4a9c3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
1 change: 0 additions & 1 deletion Source/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class Config(ConfigFile file)
public ConfigEntry<TurnProviderOption> TurnProvider = file.Bind("Input", "TurnProvider", TurnProviderOption.Snap, new ConfigDescription($"Specify which turning provider your player uses, if any.", new AcceptableValueEnum<TurnProviderOption>()));
public ConfigEntry<float> SmoothTurnSpeedModifier { get; } = file.Bind("Input", "SmoothTurnSpeedModifier", 1f, new ConfigDescription("A multiplier that is added to the smooth turning speed. Requires turn provider to be set to smooth.", new AcceptableValueRange<float>(0.25f, 5)));
public ConfigEntry<float> SnapTurnSize { get; } = file.Bind("Input", "SnapTurnSize", 45f, new ConfigDescription("The amount of rotation that is applied when performing a snap turn. Requires turn provider to be set to snap.", new AcceptableValueRange<float>(10, 180)));
public ConfigEntry<float> SpectateCameraSpeedModifier { get; } = file.Bind("Input", "SpectateCameraSpeedModifier", 2f, new ConfigDescription("Specifies how fast the camera should pivot around a spectated player.", new AcceptableValueRange<float>(0.5f, 5)));
public ConfigEntry<bool> ToggleSprint { get; } = file.Bind("Input", "ToggleSprint", false, "Whether the sprint button should toggle sprint instead of having to hold it down.");
public ConfigEntry<float> MovementSprintToggleCooldown { get; } = file.Bind("Input", "MovementSprintToggleCooldown", 1f, new ConfigDescription("The amount of seconds that you need to stand still for sprint to be toggled off automatically. Requires sprint toggle to be enabled.", new AcceptableValueRange<float>(0, 60)));
public ConfigEntry<string> ControllerBindingsOverrideProfile { get; } = file.Bind("Input", "ControllerBindingsOverrideProfile", "", "Specify the name of a controler profile you would like to use. Keep empty to use the built-in controller profiles. You can find a list of available controller profiles on https://github.com/DaXcess/LCVR-Controller-Profiles. To test a local profile, specify a path using the file protocol (e.g. file:///C:/Users/.../profile.inputactions)");
Expand Down
37 changes: 21 additions & 16 deletions Source/Networking/DNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,6 @@ private static IEnumerator HandleHandshakeResponse(ushort sender, bool isInVR)
if (!isInVR)
yield break;

// Re-initialize player if already present
if (players.TryGetValue(sender, out var networkPlayer))
{
Object.Destroy(networkPlayer);
players.Remove(sender);
}

// Wait until client is a part of the peers list
yield return new WaitUntil(() => peers.TryGetClientInfoById(sender, out _));

Expand All @@ -290,25 +283,37 @@ private static IEnumerator HandleHandshakeResponse(ushort sender, bool isInVR)

yield return new WaitUntil(() => player.Tracker != null);

// Ignore players that have already been registered
if (players.TryGetValue(sender, out var networkPlayer))
yield break;

var playerObject = ((NfgoPlayer)player.Tracker!).gameObject;
var playerController = playerObject.GetComponent<PlayerControllerB>();
networkPlayer = playerObject.AddComponent<VRNetPlayer>();

logger.LogInfo($"Found VR player {playerController.playerUsername}");

players.Add(sender, networkPlayer);
if (!players.TryAdd(sender, networkPlayer))
{
Logger.LogError("VR player already exists? Emergency nuking the network connection for this player!");

Object.Destroy(networkPlayer);
OnPlayerLeftSession(player);

yield break;
}

foreach (var item in playerController.ItemSlots.Where(val => val != null))
{
// Add or enable VR item script on item if there is one for this item
if (Player.Items.items.TryGetValue(item.itemProperties.itemName, out var type))
{
var component = (MonoBehaviour)item.GetComponent(type);
if (component == null)
item.gameObject.AddComponent(type);
else
component.enabled = true;
}
if (!Player.Items.items.TryGetValue(item.itemProperties.itemName, out var type))
continue;

var component = (MonoBehaviour)item.GetComponent(type);
if (component == null)
item.gameObject.AddComponent(type);
else
component.enabled = true;
}
}

Expand Down
9 changes: 5 additions & 4 deletions Source/Player/Spectating/EnemyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ internal static class SpectatorEnemyPatches
[HarmonyPrefix]
private static bool NutcrackerCheckForLocalPlayer(ref bool __result)
{
if (StartOfRound.Instance.localPlayerController.isPlayerDead)
if (!StartOfRound.Instance.localPlayerController.isPlayerDead)
{
__result = false;
return false;
return true;
}

return true;
__result = false;
return false;

}

/// <summary>
Expand Down

0 comments on commit 9d4a9c3

Please sign in to comment.