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 2 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
21 changes: 21 additions & 0 deletions EXILED/Exiled.API/Features/Roles/Scp3114Role.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,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;
Dance.DanceVariant = (int)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);
}
}
}
61 changes: 61 additions & 0 deletions EXILED/Exiled.Events/Patches/Fixes/ServerSideDancesPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// -----------------------------------------------------------------------
// <copyright file="ServerSideDancesPatch.cs" company="Exiled Team">
// Copyright (c) Exiled 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 UnityEngine;

/// <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);

newInstructions.InsertRange(7, new List<CodeInstruction>()
NotZer0Two marked this conversation as resolved.
Show resolved Hide resolved
{
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)
{
Npc npc = Npc.Get(__instance.Owner);
NotZer0Two marked this conversation as resolved.
Show resolved Hide resolved
if (npc != null && __instance.DanceVariant != byte.MaxValue)
{
writer.WriteByte((byte)__instance.DanceVariant);
return;
}

writer.WriteByte((byte)Random.Range(0, 255));
return;
}
}
}