Skip to content

Commit b896a73

Browse files
Bonjemuslouis1706
andauthored
fix: Scale fix (#571)
* scale fix first attempt * 2 attempt * 3 attempt * 4 attempt * Add fix for when player reconnect Scale not working * Remove TryCatch & error --------- Co-authored-by: Yamato <louismonneyron5@yahoo.com>
1 parent e6f1edf commit b896a73

4 files changed

Lines changed: 32 additions & 35 deletions

File tree

EXILED/Exiled.API/Features/Player.cs

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ public ScpSpawnPreferences.SpawnPreferences ScpPreferences
699699
public Vector3 Scale
700700
{
701701
get => ReferenceHub.transform.localScale;
702-
set => SetScale(value, List);
702+
set => SetScale(value);
703703
}
704704

705705
/// <summary>
@@ -2065,27 +2065,25 @@ public void Disconnect(string reason = null) =>
20652065
/// </summary>
20662066
public void ResetStamina() => Stamina = StaminaStat.MaxValue;
20672067

2068+
/// <summary>
2069+
/// Sets the scale of a player on the server side.
2070+
/// </summary>
2071+
/// <param name="scale">The scale to set.</param>
2072+
public void SetScale(Vector3 scale)
2073+
{
2074+
ReferenceHub.transform.localScale = scale;
2075+
new SyncedScaleMessages.ScaleMessage(scale, ReferenceHub).SendToAuthenticated();
2076+
}
2077+
20682078
/// <summary>
20692079
/// Sets the scale of a player on the server side.
20702080
/// </summary>
20712081
/// <param name="scale">The scale to set.</param>
20722082
/// <param name="viewers">Who should see the updated scale.</param>
20732083
public void SetScale(Vector3 scale, IEnumerable<Player> viewers)
20742084
{
2075-
if (scale == Scale)
2076-
return;
2077-
2078-
try
2079-
{
2080-
ReferenceHub.transform.localScale = scale;
2081-
2082-
foreach (Player target in viewers)
2083-
Server.SendSpawnMessage?.Invoke(null, new object[] { NetworkIdentity, target.Connection });
2084-
}
2085-
catch (Exception exception)
2086-
{
2087-
Log.Error($"{nameof(SetScale)} error: {exception}");
2088-
}
2085+
ReferenceHub.transform.localScale = scale;
2086+
new SyncedScaleMessages.ScaleMessage(scale, ReferenceHub).SendToHubsConditionally(x => x != null && viewers.Contains(Get(x)));
20892087
}
20902088

20912089
/// <summary>
@@ -2095,21 +2093,9 @@ public void SetScale(Vector3 scale, IEnumerable<Player> viewers)
20952093
/// <param name="viewers">Who should see the fake scale.</param>
20962094
public void SetFakeScale(Vector3 fakeScale, IEnumerable<Player> viewers)
20972095
{
2098-
Vector3 currentScale = Scale;
2099-
2100-
try
2101-
{
2102-
ReferenceHub.transform.localScale = fakeScale;
2103-
2104-
foreach (Player target in viewers)
2105-
Server.SendSpawnMessage.Invoke(null, new object[] { NetworkIdentity, target.Connection });
2106-
2107-
ReferenceHub.transform.localScale = currentScale;
2108-
}
2109-
catch (Exception ex)
2110-
{
2111-
Log.Error($"{nameof(SetFakeScale)}: {ex}");
2112-
}
2096+
SyncedScaleMessages.ScaleMessage scaleMessage = new(fakeScale, ReferenceHub);
2097+
foreach (Player player in viewers)
2098+
player.Connection.Send(scaleMessage, 0);
21132099
}
21142100

21152101
/// <summary>

EXILED/Exiled.API/Features/Roles/FpcRole.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ public Vector3 Gravity
7676
set => FirstPersonController.FpcModule.Motor.GravityController.Gravity = value;
7777
}
7878

79+
/// <summary>
80+
/// Gets or sets the player's scale.
81+
/// </summary>
82+
public Vector3 Scale
83+
{
84+
get => FirstPersonController.FpcModule.Motor.ScaleController.Scale;
85+
set => FirstPersonController.FpcModule.Motor.ScaleController.Scale = value;
86+
}
87+
7988
/// <summary>
8089
/// Gets or sets a value indicating whether if the player should get <see cref="Enums.DamageType.Falldown"/> damage.
8190
/// </summary>

EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ public virtual void AddRole(Player player)
564564
Log.Debug($"{Name}: Setting health values.");
565565
player.Health = MaxHealth;
566566
player.MaxHealth = MaxHealth;
567-
player.Scale = Scale;
567+
Timing.CallDelayed(0.1f, () => player.Scale = Scale); // To fix : remove the delay in 14.1.2 once the crash issue is resolved
568568
if (Gravity.HasValue && player.Role is FpcRole fpcRole)
569569
fpcRole.Gravity = Gravity.Value;
570570
Vector3 position = GetSpawnPosition();
@@ -627,7 +627,6 @@ public virtual void RemoveRole(Player player)
627627
TrackedPlayers.Remove(player);
628628
player.CustomInfo = string.Empty;
629629
player.InfoArea |= PlayerInfoArea.Role | PlayerInfoArea.Nickname;
630-
player.Scale = Vector3.one;
631630
if (CustomAbilities is not null)
632631
{
633632
foreach (CustomAbility ability in CustomAbilities)

EXILED/Exiled.Events/Handlers/Internal/Round.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ namespace Exiled.Events.Handlers.Internal
2929
using InventorySystem.Items.Usables;
3030
using InventorySystem.Items.Usables.Scp244.Hypothermia;
3131
using PlayerRoles;
32+
using PlayerRoles.FirstPersonControl;
3233
using PlayerRoles.RoleAssign;
34+
using UnityEngine;
35+
using Utils.Networking;
3336
using Utils.NonAllocLINQ;
3437

3538
/// <summary>
@@ -114,10 +117,10 @@ public static void OnVerified(VerifiedEventArgs ev)
114117
ev.Player.SendFakeSyncVar(room.RoomLightControllerNetIdentity, typeof(RoomLightController), nameof(RoomLightController.NetworkLightsEnabled), false);
115118
}
116119

117-
// TODO: Remove if this has been fixed for https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/947
118-
if (ev.Player.TryGetEffect(out Hypothermia hypothermia))
120+
// Fix bug that player that Join do not receive information about other players Scale
121+
foreach (Player player in ReferenceHub.AllHubs.Select(Player.Get))
119122
{
120-
hypothermia.SubEffects = hypothermia.SubEffects.Where(x => x.GetType() != typeof(PostProcessSubEffect)).ToArray();
123+
player.SetFakeScale(player.Scale, new List<Player>() { ev.Player });
121124
}
122125
}
123126

0 commit comments

Comments
 (0)