forked from Exiled-Official/EXILED
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
[Exiled::API]
StopDancing and StartDancing for SCP-3114 Role (#…
…189) * Added Dance * Fix for DanceType.None * Fixes * Removed Debug message * Fixed the difference --------- Co-authored-by: Yamato <[email protected]> Co-authored-by: VALERA771 <[email protected]>
- Loading branch information
1 parent
ff302f9
commit 607e85d
Showing
3 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
EXILED/Exiled.Events/Patches/Fixes/ServerSideDancesPatch.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters