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

Fix nre error on role #66

Merged
merged 3 commits into from
Sep 23, 2024
Merged
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
7 changes: 3 additions & 4 deletions EXILED/Exiled.API/Features/Roles/Role.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@ namespace Exiled.API.Features.Roles
using System;

using Enums;

using Exiled.API.Features.Core;
using Exiled.API.Features.Spawn;
using Exiled.API.Interfaces;
using Extensions;

using PlayerRoles;
using PlayerRoles.PlayableScps.Scp049.Zombies;

using UnityEngine;

using FilmmakerGameRole = PlayerRoles.Filmmaker.FilmmakerRole;
using HumanGameRole = PlayerRoles.HumanRole;
using NoneGameRole = PlayerRoles.NoneRole;
using OverwatchGameRole = PlayerRoles.Spectating.OverwatchRole;
using Scp049GameRole = PlayerRoles.PlayableScps.Scp049.Scp049Role;
using Scp079GameRole = PlayerRoles.PlayableScps.Scp079.Scp079Role;
Expand Down Expand Up @@ -229,7 +227,8 @@ public virtual void Set(RoleTypeId newRole, SpawnReason reason, RoleSpawnFlags s
SpectatorGameRole spectatorRole => new SpectatorRole(spectatorRole),
HumanGameRole humanRole => new HumanRole(humanRole),
FilmmakerGameRole filmmakerRole => new FilmMakerRole(filmmakerRole),
_ => new NoneRole(role),
NoneGameRole noneRole => new NoneRole(noneRole),
_ => null,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi

Label returnLabel = generator.DefineLabel();
Label continueLabel = generator.DefineLabel();
Label continueLabel1 = generator.DefineLabel();
Label continueLabel2 = generator.DefineLabel();
Label jmp = generator.DefineLabel();

LocalBuilder changingRoleEventArgs = generator.DeclareLocal(typeof(ChangingRoleEventArgs));
Expand All @@ -55,15 +53,10 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new[]
{
// player = Player.Get(this._hub)
//
// if (player == null)
// goto continueLabel;
new CodeInstruction(OpCodes.Ldarg_0),
new(OpCodes.Call, PropertyGetter(typeof(PlayerRoleManager), nameof(PlayerRoleManager.Hub))),
new(OpCodes.Call, Method(typeof(API.Features.Player), nameof(API.Features.Player.Get), new[] { typeof(ReferenceHub) })),
new(OpCodes.Dup),
new(OpCodes.Stloc_S, player.LocalIndex),
new(OpCodes.Brfalse_S, continueLabel),

// if (Player.IsVerified)
// goto jmp
Expand Down Expand Up @@ -133,17 +126,10 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
int index = newInstructions.FindIndex(
instruction => instruction.Calls(Method(typeof(GameObjectPools.PoolObject), nameof(GameObjectPools.PoolObject.SetupPoolObject)))) + offset;

newInstructions[index].WithLabels(continueLabel1);

newInstructions.InsertRange(
index,
new[]
{
// if (player == null)
// continue
new CodeInstruction(OpCodes.Ldloc_S, player.LocalIndex),
new(OpCodes.Brfalse_S, continueLabel1),

// player.Role = Role.Create(roleBase);
new CodeInstruction(OpCodes.Ldloc_S, player.LocalIndex),
new(OpCodes.Ldloc_2),
Expand All @@ -154,22 +140,10 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
offset = 1;
index = newInstructions.FindIndex(i => i.Calls(Method(typeof(PlayerRoleManager.RoleChanged), nameof(PlayerRoleManager.RoleChanged.Invoke)))) + offset;

newInstructions[index].labels.Add(continueLabel2);

newInstructions.InsertRange(
index,
new[]
new CodeInstruction[]
{
// if (player == null)
// continue
new CodeInstruction(OpCodes.Ldloc_S, player.LocalIndex),
new(OpCodes.Brfalse_S, continueLabel2),

// if (changingRoleEventArgs == null)
// continue
new CodeInstruction(OpCodes.Ldloc_S, changingRoleEventArgs.LocalIndex),
new(OpCodes.Brfalse_S, continueLabel2),

// changingRoleEventArgs
new(OpCodes.Ldloc_S, changingRoleEventArgs.LocalIndex),

Expand All @@ -181,11 +155,6 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
newInstructions.Count - 1,
new[]
{
// if (player == null)
// continue
new CodeInstruction(OpCodes.Ldloc_S, player.LocalIndex),
new(OpCodes.Brfalse_S, returnLabel),

// player
new CodeInstruction(OpCodes.Ldloc_S, player.LocalIndex),

Expand Down
Loading