forked from Exiled-Official/EXILED
-
Notifications
You must be signed in to change notification settings - Fork 110
feat: [Exiled::API] StopDancing and StartDancing for SCP-3114 Role
#189
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cdcef30
Added Dance
NotZer0Two 63319ce
Fix for DanceType.None
NotZer0Two 95a71ca
Fixes
NotZer0Two 17ea8a8
Removed Debug message
NotZer0Two 8145ac0
Fixed the difference
NotZer0Two 3c28730
Merge branch 'dev' into Dance
louis1706 9860297
Merge branch 'dev' into Dance
VALERA771 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
61 changes: 61 additions & 0 deletions
61
EXILED/Exiled.Events/Patches/Fixes/ServerSideDancesPatch.cs
This file contains hidden or 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,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>() | ||
| { | ||
| 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.
Outdated
|
||
| if (npc != null && __instance.DanceVariant != byte.MaxValue) | ||
| { | ||
| writer.WriteByte((byte)__instance.DanceVariant); | ||
| return; | ||
| } | ||
|
|
||
| writer.WriteByte((byte)Random.Range(0, 255)); | ||
| return; | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.