Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [Exiled::API] StopDancing and StartDancing for SCP-3114 Role #189

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion EXILED/Exiled.API/Features/Roles/Scp3114Role.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public float WarningTime
/// <summary>
/// Gets or sets the bound dance.
/// </summary>
internal DanceType DanceType { get; set; }
internal DanceType DanceType { get; set; } = DanceType.None;

/// <summary>
/// Updates the identity of SCP-3114.
Expand Down Expand Up @@ -250,5 +250,26 @@ public void PlaySound(Scp3114VoiceLines.VoiceLinesName voiceLine = Scp3114VoiceL
/// <param name="alreadySpawned">The List of Roles already spawned.</param>
/// <returns>The Spawn Chance.</returns>
public float GetSpawnChance(List<RoleTypeId> alreadySpawned) => Base is ISpawnableScp spawnableScp ? spawnableScp.GetSpawnChance(alreadySpawned) : 0;

/// <summary>
/// SCP-3114 starts dancing.
/// </summary>
/// <param name="danceType">The dance you want to do.</param>
public void StartDancing(DanceType danceType)
{
Dance.IsDancing = true;
DanceType = danceType;
Dance._serverStartPos = new RelativePositioning.RelativePosition(Dance.CastRole.FpcModule.Position);
Dance.ServerSendRpc(true);
}

/// <summary>
/// Stops the SCP-3114 from Dancing.
/// </summary>
public void StopDancing()
{
Dance.IsDancing = false;
Dance.ServerSendRpc(true);
}
}
}
72 changes: 72 additions & 0 deletions EXILED/Exiled.Events/Patches/Fixes/ServerSideDancesPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// -----------------------------------------------------------------------
// <copyright file="ServerSideDancesPatch.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

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;

/// <summary>
/// Patches the <see cref="Scp3114Dance.DanceVariant"/>.
/// Fix that the game doesn't write this.
/// </summary>
[HarmonyPatch(typeof(Scp3114Dance), nameof(Scp3114Dance.ServerWriteRpc))]
internal class ServerSideDancesPatch
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.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<CodeInstruction>()
{
new CodeInstruction(OpCodes.Br_S, skip),
});

foreach (CodeInstruction instruction in newInstructions)
yield return instruction;

ListPool<CodeInstruction>.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;
}
}
}
1 change: 0 additions & 1 deletion EXILED/Exiled.Example/Commands/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace Exiled.Example.Commands
using System;

using CommandSystem;

using Exiled.API.Features;
using Exiled.API.Features.Pickups;

Expand Down
Loading