Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
Label continueLabel = generator.DefineLabel();
Label jmp = generator.DefineLabel();
Label skip = generator.DefineLabel();
Label nothing = generator.DefineLabel();

LocalBuilder changingRoleEventArgs = generator.DeclareLocal(typeof(ChangingRoleEventArgs));
LocalBuilder player = generator.DeclareLocal(typeof(API.Features.Player));
Expand Down Expand Up @@ -156,6 +157,22 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
newInstructions.Count - 1,
new[]
{
// if (player == null)
// goto nothing;
new CodeInstruction(OpCodes.Ldloc_S, player.LocalIndex),
new(OpCodes.Brfalse_S, nothing),

// if (player.ReferenceHub == null)
// goto nothing;
new CodeInstruction(OpCodes.Ldloc_S, player.LocalIndex),
new CodeInstruction(OpCodes.Callvirt, PropertyGetter(typeof(API.Features.Player), nameof(API.Features.Player.ReferenceHub))),
new(OpCodes.Brfalse_S, nothing),

// if (ReferenceHub.LocalHub == null)
// goto nothing;
new CodeInstruction(OpCodes.Call, PropertyGetter(typeof(ReferenceHub), nameof(ReferenceHub.LocalHub))),
new(OpCodes.Brfalse_S, nothing),

// if (player.ReferenceHub == ReferenceHub.LocalHub)
// goto skip;
new(OpCodes.Ldloc_S, player.LocalIndex),
Expand All @@ -164,6 +181,9 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Call, Method(typeof(ReferenceHub), "op_Equality")),
new(OpCodes.Brtrue_S, skip),

// nothing
new CodeInstruction(OpCodes.Nop).WithLabels(nothing),

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

Expand Down Expand Up @@ -259,4 +279,4 @@ private static void ChangeInventory(ChangingRoleEventArgs ev)
}
}
}
}
}