Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Fixes to Player Management and added Udon test scene for player values
Browse files Browse the repository at this point in the history
Throw Exceptions when trying to set player locomotion settings on remote clients (VRChat throws an NRE)
Fixed NRE for getting players by id and getting ids by players.
  • Loading branch information
CyanLaser committed Jan 24, 2021
1 parent 91c2d90 commit da7b431
Show file tree
Hide file tree
Showing 9 changed files with 1,391 additions and 26 deletions.
1 change: 1 addition & 0 deletions CyanEmu/Scripts/CyanEmuPlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ public Quaternion GetRotation()

public Vector3 GetVelocity()
{
// TODO fix value
return characterController_.velocity;
}

Expand Down
76 changes: 50 additions & 26 deletions CyanEmu/Scripts/CyanEmuPlayerManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using UnityEngine;
using VRC.SDKBase;

Expand Down Expand Up @@ -104,17 +105,24 @@ public static int GetMasterID()

public static VRCPlayerApi LocalPlayer()
{
return players[localPlayerID];
return GetPlayerByID(localPlayerID);
}

public static VRCPlayerApi GetPlayerByID(int playerID)
{
return players[playerID];
players.TryGetValue(playerID, out VRCPlayerApi player);
return player;
}

public static int GetPlayerID(VRCPlayerApi player)
{
return playerIDs[player];
if (player == null)
{
return -1;
}

playerIDs.TryGetValue(player, out int playerId);
return playerId;
}

public static bool IsMaster(VRCPlayerApi player)
Expand All @@ -129,40 +137,55 @@ public static bool IsLocalPlayerMaster()

public static void EnablePickups(VRCPlayerApi player, bool enabled)
{
if (!player.isLocal)
{
player.LogWarning("[VRCPlayerAPI.EnablePickups] EnablePickups for remote players will do nothing.");
return;
}

// TODO
}

public static void Immobilize(VRCPlayerApi player, bool immobilized)
{
if (!player.isLocal)
{
throw new Exception("[VRCPlayerAPI.Immobilize] You cannot set remote players Immobilized");
}

// TODO
}

public static void TeleportToOrientationLerp(VRCPlayerApi player, Vector3 position, Quaternion rotation, VRC_SceneDescriptor.SpawnOrientation orientation, bool lerp)
{
// Ignore lerp since there is no networking here
TeleportToOrientation(player, position, rotation, orientation);
}

public static void TeleportToOrientation(VRCPlayerApi player, Vector3 position, Quaternion rotation, VRC_SceneDescriptor.SpawnOrientation orientation)
{
if (!player.isLocal)
{
player.LogWarning("[VRCPlayerAPI.TeleportTo] Teleporting remote players will do nothing.");
return;
}

// Ignore lerp since there is no networking here
player.GetPlayerController().Teleport(position, rotation, orientation == VRC_SceneDescriptor.SpawnOrientation.AlignRoomWithSpawnPoint);
}

public static void TeleportToOrientation(VRCPlayerApi player, Vector3 position, Quaternion rotation, VRC_SceneDescriptor.SpawnOrientation orientation)
{
TeleportToOrientationLerp(player, position, rotation, VRC_SceneDescriptor.SpawnOrientation.Default, false);
}

public static void TeleportTo(VRCPlayerApi player, Vector3 position, Quaternion rotation)
{
if (!player.isLocal)
{
return;
}
player.GetPlayerController().Teleport(position, rotation, false);
TeleportToOrientationLerp(player, position, rotation, VRC_SceneDescriptor.SpawnOrientation.Default, false);
}

public static void PlayHapticEventInHand(VRCPlayerApi player, VRC_Pickup.PickupHand hand, float f1, float f2, float f3)
{
if (!player.isLocal)
{
player.LogWarning("[VRCPlayerAPI.PlayHapticEventInHand] PlayHapticEventInHand for remote players will do nothing.");
return;
}

// TODO
}

Expand Down Expand Up @@ -220,7 +243,7 @@ public static float GetRunSpeed(VRCPlayerApi player)
{
if (!player.isLocal)
{
return 0;
throw new Exception("[VRCPlayerAPI.GetRunSpeed] You cannot get run speed for remote clients!");
}
return player.GetPlayerController().GetRunSpeed();
}
Expand All @@ -229,7 +252,7 @@ public static void SetRunSpeed(VRCPlayerApi player, float speed)
{
if (!player.isLocal)
{
return;
throw new Exception("[VRCPlayerAPI.SetRunSpeed] You cannot set run speed for remote clients!");
}
player.GetPlayerController().SetRunSpeed(speed);
}
Expand All @@ -238,7 +261,7 @@ public static float GetStrafeSpeed(VRCPlayerApi player)
{
if (!player.isLocal)
{
return 0;
throw new Exception("[VRCPlayerAPI.GetStrafeSpeed] You cannot get strafe speed for remote clients!");
}
return player.GetPlayerController().GetStrafeSpeed();
}
Expand All @@ -247,7 +270,7 @@ public static void SetStrafeSpeed(VRCPlayerApi player, float speed)
{
if (!player.isLocal)
{
return;
throw new Exception("[VRCPlayerAPI.SetStrafeSpeed] You cannot set strafe speed for remote clients!");
}
player.GetPlayerController().SetStrafeSpeed(speed);
}
Expand All @@ -256,7 +279,7 @@ public static float GetWalkSpeed(VRCPlayerApi player)
{
if (!player.isLocal)
{
return 0;
throw new Exception("[VRCPlayerAPI.GetWalkSpeed] You cannot get walk speed for remote clients!");
}
return player.GetPlayerController().GetWalkSpeed();
}
Expand All @@ -265,7 +288,7 @@ public static void SetWalkSpeed(VRCPlayerApi player, float speed)
{
if (!player.isLocal)
{
return;
throw new Exception("[VRCPlayerAPI.SetWalkSpeed] You cannot set walk speed for remote clients!");
}
player.GetPlayerController().SetWalkSpeed(speed);
}
Expand All @@ -274,7 +297,7 @@ public static float GetJumpImpulse(VRCPlayerApi player)
{
if (!player.isLocal)
{
return 0;
throw new Exception("[VRCPlayerAPI.GetJumpImpulse] You cannot get jump impulse for remote clients!");
}
return player.GetPlayerController().GetJump();
}
Expand All @@ -283,7 +306,7 @@ public static void SetJumpImpulse(VRCPlayerApi player, float jump)
{
if (!player.isLocal)
{
return;
throw new Exception("[VRCPlayerAPI.SetJumpImpulse] You cannot set jump impulse for remote clients!");
}
player.GetPlayerController().SetJump(jump);
}
Expand All @@ -292,7 +315,7 @@ public static float GetGravityStrength(VRCPlayerApi player)
{
if (!player.isLocal)
{
return 0;
throw new Exception("[VRCPlayerAPI.GetGravityStrength] You cannot get gravity strength for remote clients!");
}
return player.GetPlayerController().GetGravityStrength();
}
Expand All @@ -301,7 +324,7 @@ public static void SetGravityStrength(VRCPlayerApi player, float gravity)
{
if (!player.isLocal)
{
return;
throw new Exception("[VRCPlayerAPI.SetGravityStrength] You cannot set gravity strength for remote clients!");
}
player.GetPlayerController().SetGravityStrength(gravity);
}
Expand Down Expand Up @@ -338,7 +361,8 @@ public static bool IsGrounded(VRCPlayerApi player)
{
if (!player.isLocal)
{
return false;
// TODO verify remote player values when not grounded.
return true;
}
return player.GetPlayerController().IsGrounded();
}
Expand Down
Loading

0 comments on commit da7b431

Please sign in to comment.