diff --git a/EXILED/Exiled.API/Features/Roles/Scp3114Role.cs b/EXILED/Exiled.API/Features/Roles/Scp3114Role.cs index ab157b92c..64f6b3408 100644 --- a/EXILED/Exiled.API/Features/Roles/Scp3114Role.cs +++ b/EXILED/Exiled.API/Features/Roles/Scp3114Role.cs @@ -221,7 +221,7 @@ public float WarningTime /// /// Gets or sets the bound dance. /// - internal DanceType DanceType { get; set; } + internal DanceType DanceType { get; set; } = DanceType.None; /// /// Updates the identity of SCP-3114. @@ -250,5 +250,26 @@ public void PlaySound(Scp3114VoiceLines.VoiceLinesName voiceLine = Scp3114VoiceL /// The List of Roles already spawned. /// The Spawn Chance. public float GetSpawnChance(List alreadySpawned) => Base is ISpawnableScp spawnableScp ? spawnableScp.GetSpawnChance(alreadySpawned) : 0; + + /// + /// SCP-3114 starts dancing. + /// + /// The dance you want to do. + public void StartDancing(DanceType danceType) + { + Dance.IsDancing = true; + DanceType = danceType; + Dance._serverStartPos = new RelativePositioning.RelativePosition(Dance.CastRole.FpcModule.Position); + Dance.ServerSendRpc(true); + } + + /// + /// Stops the SCP-3114 from Dancing. + /// + public void StopDancing() + { + Dance.IsDancing = false; + Dance.ServerSendRpc(true); + } } } \ No newline at end of file diff --git a/EXILED/Exiled.Events/Patches/Fixes/ServerSideDancesPatch.cs b/EXILED/Exiled.Events/Patches/Fixes/ServerSideDancesPatch.cs new file mode 100644 index 000000000..114f14c0a --- /dev/null +++ b/EXILED/Exiled.Events/Patches/Fixes/ServerSideDancesPatch.cs @@ -0,0 +1,72 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.Patches.Fixes +{ +#pragma warning disable SA1313 + using System.Collections.Generic; + using System.Reflection.Emit; + + using API.Features.Pools; + using Exiled.API.Features; + using HarmonyLib; + using Mirror; + using PlayerRoles.PlayableScps.Scp3114; + using PlayerRoles.Subroutines; + using UnityEngine; + + using static HarmonyLib.AccessTools; + + using Scp3114Role = API.Features.Roles.Scp3114Role; + + /// + /// Patches the . + /// Fix that the game doesn't write this. + /// + [HarmonyPatch(typeof(Scp3114Dance), nameof(Scp3114Dance.ServerWriteRpc))] + internal class ServerSideDancesPatch + { + private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + { + List newInstructions = ListPool.Pool.Get(instructions); + + Label skip = generator.DefineLabel(); + + newInstructions.Add(new CodeInstruction(OpCodes.Ret)); + newInstructions[newInstructions.Count - 1].labels.Add(skip); + + int offset = 4; + int index = newInstructions.FindIndex(x => x.Calls(Method(typeof(SubroutineBase), nameof(SubroutineBase.ServerWriteRpc)))) + offset; + + newInstructions.InsertRange(index, new List() + { + new CodeInstruction(OpCodes.Br_S, skip), + }); + + foreach (CodeInstruction instruction in newInstructions) + yield return instruction; + + ListPool.Pool.Return(newInstructions); + } + + private static void Postfix(ref Scp3114Dance __instance, NetworkWriter writer) + { + Player player = Player.Get(__instance.Owner); + + Scp3114Role role = player.Role as Scp3114Role; + + if (player != null && role.DanceType != API.Enums.DanceType.None) + { + writer.WriteByte((byte)role.DanceType); + return; + } + + writer.WriteByte((byte)Random.Range(0, 255)); + return; + } + } +} diff --git a/EXILED/Exiled.Example/Commands/Test.cs b/EXILED/Exiled.Example/Commands/Test.cs index b15a3f0f7..6b5b4be49 100644 --- a/EXILED/Exiled.Example/Commands/Test.cs +++ b/EXILED/Exiled.Example/Commands/Test.cs @@ -10,7 +10,6 @@ namespace Exiled.Example.Commands using System; using CommandSystem; - using Exiled.API.Features; using Exiled.API.Features.Pickups;