Skip to content
11 changes: 6 additions & 5 deletions EXILED/Exiled.API/Features/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Exiled.API.Features
{
#pragma warning disable SA1401
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -43,6 +44,11 @@ namespace Exiled.API.Features
/// </summary>
public static class Map
{
/// <summary>
/// Gets a list of <see cref="PocketDimensionTeleport"/>s on the map.
/// </summary>
internal static List<PocketDimensionTeleport> TeleportsValue = new();

private static AmbientSoundPlayer ambientSoundPlayer;

private static SqueakSpawner squeakSpawner;
Expand Down Expand Up @@ -114,11 +120,6 @@ public static bool IsDecontaminationEnabled
/// </summary>
public static SqueakSpawner SqueakSpawner => squeakSpawner ??= Object.FindObjectOfType<SqueakSpawner>();

/// <summary>
/// Gets a list of <see cref="PocketDimensionTeleport"/>s on the map.
/// </summary>
internal static List<PocketDimensionTeleport> TeleportsValue { get; } = new();

/// <summary>
/// Broadcasts a message to all <see cref="Player">players</see>.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion EXILED/Exiled.API/Features/Roles/Scp106Role.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public bool IsSubmerged
public bool SinkholeState
{
get => StalkAbility.StalkActive;
set => StalkAbility.StalkActive = value;
set => StalkAbility.ServerSetStalk(value);
}

/// <summary>
Expand Down
11 changes: 1 addition & 10 deletions EXILED/Exiled.Events/EventArgs/Player/SpawningEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,11 @@ public class SpawningEventArgs : IPlayerEvent
/// <param name="rotation">
/// <inheritdoc cref="HorizontalRotation" />
/// </param>
/// <param name="oldRole">
/// the spawned player's old <see cref="PlayerRoleBase">role</see>.
/// </param>
public SpawningEventArgs(Player player, Vector3 position, float rotation, PlayerRoleBase oldRole)
public SpawningEventArgs(Player player, Vector3 position, float rotation)
{
Player = player;
Position = position;
HorizontalRotation = rotation;
OldRole = Role.Create(oldRole);
}

/// <summary>
Expand All @@ -62,10 +58,5 @@ public SpawningEventArgs(Player player, Vector3 position, float rotation, Player
/// Rotation will apply only for <see cref="FpcRole"/>.
/// </remarks>
public float HorizontalRotation { get; set; }

/// <summary>
/// Gets the player's old <see cref="PlayerRoleBase">role</see>.
/// </summary>
public Role OldRole { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ public class UpgradingPlayerEventArgs : IPlayerEvent, IDeniableEvent
/// <param name="upgradeItems">
/// <inheritdoc cref="UpgradeItems" />
/// </param>
/// <param name="moveVector">
/// <inheritdoc cref="OutputPosition" />
/// <param name="outputPos">
/// <inheritdoc cref="OutputPosition"/>
/// </param>
public UpgradingPlayerEventArgs(Player player, bool upgradeItems, bool heldOnly, Scp914KnobSetting setting, Vector3 moveVector)
public UpgradingPlayerEventArgs(Player player, bool upgradeItems, bool heldOnly, Scp914KnobSetting setting, Vector3 outputPos)
{
Player = player;
UpgradeItems = upgradeItems;
HeldOnly = heldOnly;
KnobSetting = setting;
OutputPosition = player.Position + moveVector;
OutputPosition = outputPos;
}

/// <summary>
Expand Down
25 changes: 12 additions & 13 deletions EXILED/Exiled.Events/EventArgs/Server/RespawningTeamEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,19 @@ public class RespawningTeamEventArgs : IDeniableEvent
/// <param name="players">
/// <inheritdoc cref="Players" />
/// </param>
/// <param name="queue">
/// <inheritdoc cref="SpawnQueue" />
/// </param>
/// <param name="maxRespawn">
/// <inheritdoc cref="MaximumRespawnAmount" />
/// </param>
/// <param name="nextKnownTeam">
/// <param name="wave">
/// <inheritdoc cref="NextKnownTeam" />
/// </param>
/// <param name="isAllowed">
/// <inheritdoc cref="IsAllowed" />
/// </param>
public RespawningTeamEventArgs(List<Player> players, Queue<RoleTypeId> queue, int maxRespawn, SpawnableWaveBase nextKnownTeam, bool isAllowed = true)
public RespawningTeamEventArgs(List<Player> players, int maxRespawn, SpawnableWaveBase wave)
{
Players = players;
MaximumRespawnAmount = maxRespawn;
SpawnQueue = queue;
NextKnownTeam = nextKnownTeam;
IsAllowed = isAllowed;
SpawnQueue = WaveSpawner.SpawnQueue;
Wave = wave;
IsAllowed = true;
}

/// <summary>
Expand All @@ -74,9 +68,14 @@ public int MaximumRespawnAmount
}

/// <summary>
/// Gets or sets a value indicating what the next respawnable team is.
/// Gets or sets a value indicating what the next wave is.
/// </summary>
public SpawnableWaveBase Wave { get; set; }

/// <summary>
/// Gets a value indicating what the next respawnable team is.
/// </summary>
public SpawnableWaveBase NextKnownTeam { get; set; }
public SpawnableTeamType NextKnownTeam => Wave.TargetFaction.GetSpawnableTeam();

/// <summary>
/// Gets or sets a value indicating whether the spawn can occur.
Expand Down
2 changes: 1 addition & 1 deletion EXILED/Exiled.Events/Patches/Events/Map/FillingLocker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new[]
{
// FillingLockerEventArgs ev = new(ItemPickupBase, loockerChamber)
new(OpCodes.Ldloc_S, 4),
new(OpCodes.Ldloc_S, 5),
new(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Newobj, GetDeclaredConstructors(typeof(FillingLockerEventArgs))[0]),
new(OpCodes.Dup),
Expand Down
16 changes: 4 additions & 12 deletions EXILED/Exiled.Events/Patches/Events/Map/SpawningTeamVehicle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
Label retLabel = generator.DefineLabel();
Label continueLabel = generator.DefineLabel();

LocalBuilder ev = generator.DeclareLocal(typeof(SpawningTeamVehicleEventArgs));
LocalBuilder msg = generator.DeclareLocal(typeof(WaveUpdateMessage));

int offset = 1;
Expand All @@ -47,21 +46,19 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi

// if (type != RespawnEffectsController.EffectType.Selection)
// goto continueLabel;
new(OpCodes.Ldloc_S, msg.LocalIndex),
new(OpCodes.Ldloca_S, msg.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(WaveUpdateMessage), nameof(WaveUpdateMessage.IsTrigger))),
new(OpCodes.Brfalse_S, continueLabel),

// team
new(OpCodes.Ldarg_1),
// wave
new(OpCodes.Ldarg_0),

// true
new(OpCodes.Ldc_I4_1),

// SpawningTeamVehicleEventArgs ev = new(SpawnableTeamType, bool);
// SpawningTeamVehicleEventArgs ev = new(SpawnableWaveBase, bool);
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(SpawningTeamVehicleEventArgs))[0]),
new(OpCodes.Dup),
new(OpCodes.Dup),
new(OpCodes.Stloc_S, ev.LocalIndex),

// Handlers.Map.OnSpawningTeamVehicle(ev);
new(OpCodes.Call, Method(typeof(Handlers.Map), nameof(Handlers.Map.OnSpawningTeamVehicle))),
Expand All @@ -71,11 +68,6 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Callvirt, PropertyGetter(typeof(SpawningTeamVehicleEventArgs), nameof(SpawningTeamVehicleEventArgs.IsAllowed))),
new(OpCodes.Brfalse_S, retLabel),

// team = ev.Team
new(OpCodes.Ldloc_S, ev),
new(OpCodes.Callvirt, PropertyGetter(typeof(SpawningTeamVehicleEventArgs), nameof(SpawningTeamVehicleEventArgs.Team))),
new(OpCodes.Starg_S, 1),

new CodeInstruction(OpCodes.Ldloc_S, msg.LocalIndex).WithLabels(continueLabel),
});

Expand Down
33 changes: 10 additions & 23 deletions EXILED/Exiled.Events/Patches/Events/Player/Shooting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ namespace Exiled.Events.Patches.Events.Player

using HarmonyLib;

using InventorySystem.Items.Firearms;
using InventorySystem.Items.Firearms.BasicMessages;
using InventorySystem.Items.Firearms.Modules;
using InventorySystem.Items.Firearms.Modules.Misc;

using static HarmonyLib.AccessTools;

Expand All @@ -29,41 +31,33 @@ namespace Exiled.Events.Patches.Events.Player
/// </summary>
[EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.Shooting))]

// [HarmonyPatch(typeof(FirearmBasicMessagesHandler), nameof(FirearmBasicMessagesHandler.ServerShotReceived))]
[HarmonyPatch(typeof(ShotBacktrackData), nameof(ShotBacktrackData.ProcessShot))]
internal static class Shooting
{
/*
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

Label isAllowedLabel = generator.DefineLabel();
Label returnLabel = generator.DefineLabel();

LocalBuilder ev = generator.DeclareLocal(typeof(ShootingEventArgs));

int offset = -2;
int index = newInstructions.FindIndex(instruction => instruction.Calls(Method(typeof(IActionModule), nameof(IActionModule.ServerAuthorizeShot)))) + offset;
int offset = 1;
int index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Stloc_2) + offset;

newInstructions.InsertRange(
index,
new[]
{
// Player.Get(referenceHub)
new CodeInstruction(OpCodes.Ldloc_0).MoveLabelsFrom(newInstructions[index]),
// Player.Get(firearm.Owner)
new(OpCodes.Ldarg_1),
new(OpCodes.Callvirt, PropertyGetter(typeof(Firearm), nameof(Firearm.Owner))),
new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),

// firearm
new(OpCodes.Ldloc_1),

// msg
new(OpCodes.Ldarg_1),
new CodeInstruction(OpCodes.Ldarg_1).MoveLabelsFrom(newInstructions[index]),

// ShootingEventArgs ev = new(Player, firearm, ShotMessage)
// ShootingEventArgs ev = new(Player, firearm)
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(ShootingEventArgs))[0]),
new(OpCodes.Dup),
new(OpCodes.Dup),
new(OpCodes.Stloc, ev.LocalIndex),

// Handlers.Player.OnShooting(ev)
new(OpCodes.Call, Method(typeof(Handlers.Player), nameof(Handlers.Player.OnShooting))),
Expand All @@ -72,12 +66,6 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
// return;
new(OpCodes.Callvirt, PropertyGetter(typeof(ShootingEventArgs), nameof(ShootingEventArgs.IsAllowed))),
new(OpCodes.Brfalse_S, returnLabel),

// isAllowedLabel:
// msg = ev.ShotMessage
new CodeInstruction(OpCodes.Ldloc_S, ev.LocalIndex).WithLabels(isAllowedLabel),
new(OpCodes.Callvirt, PropertyGetter(typeof(ShootingEventArgs), nameof(ShootingEventArgs.ShotMessage))),
new(OpCodes.Starg_S, 1),
});

newInstructions[newInstructions.Count - 1].WithLabels(returnLabel);
Expand All @@ -87,6 +75,5 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi

ListPool<CodeInstruction>.Pool.Return(newInstructions);
}
*/
}
}
15 changes: 5 additions & 10 deletions EXILED/Exiled.Events/Patches/Events/Player/Spawning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,16 @@ namespace Exiled.Events.Patches.Events.Player
/// Adds the <see cref="Handlers.Player.Spawning"/> event.
/// Fix for spawning in void.
/// </summary>
[HarmonyPatch]
[HarmonyPatch(typeof(RoleSpawnpointManager), nameof(RoleSpawnpointManager.SetPosition))]
internal static class Spawning
{
private static MethodInfo TargetMethod()
{
return Method(TypeByName("PlayerRoles.FirstPersonControl.Spawnpoints.RoleSpawnpointManager").GetNestedTypes(all)[1], "<Init>b__2_0");
}

private static bool Prefix(ReferenceHub hub, PlayerRoleBase prevRole, PlayerRoleBase newRole)
private static bool Prefix(ReferenceHub hub, PlayerRoleBase newRole)
{
if (newRole.ServerSpawnReason == RoleChangeReason.Destroyed || !Player.TryGet(hub, out Player player))
return true;

Vector3 oldPosition = hub.transform.position;
float oldRotation = (prevRole as IFpcRole)?.FpcModule.MouseLook.CurrentVertical ?? 0;
float oldRotation = 0;

if (newRole is IFpcRole fpcRole)
{
Expand All @@ -51,7 +46,7 @@ private static bool Prefix(ReferenceHub hub, PlayerRoleBase prevRole, PlayerRole
oldRotation = horizontalRot;
}

SpawningEventArgs ev = new(player, oldPosition, oldRotation, prevRole);
SpawningEventArgs ev = new(player, oldPosition, oldRotation);

Handlers.Player.OnSpawning(ev);

Expand All @@ -60,7 +55,7 @@ private static bool Prefix(ReferenceHub hub, PlayerRoleBase prevRole, PlayerRole
}
else
{
Handlers.Player.OnSpawning(new(player, oldPosition, oldRotation, prevRole));
Handlers.Player.OnSpawning(new(player, oldPosition, oldRotation));
}

return false;
Expand Down
14 changes: 6 additions & 8 deletions EXILED/Exiled.Events/Patches/Events/Player/SpawningRagdoll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,19 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi

LocalBuilder ev = generator.DeclareLocal(typeof(SpawningRagdollEventArgs));

int offset = 0;
int offset = 1;
int index = newInstructions.FindIndex(instruction => instruction.Calls(PropertySetter(typeof(BasicRagdoll), nameof(BasicRagdoll.NetworkInfo)))) + offset;

newInstructions.InsertRange(index, new CodeInstruction[]
{
// RagdollInfo loads into stack before il inject
// ragdoll.NetworkInfo
new(OpCodes.Ldloc_1),
new(OpCodes.Callvirt, PropertyGetter(typeof(BasicRagdoll), nameof(BasicRagdoll.NetworkInfo))),

// true
new(OpCodes.Ldc_I4_1),

// SpawningRagdollEventArgs ev = new(RagdollInfo, bool)
// SpawningRagdollEventArgs ev = new(ragdoll, RagdollInfo, bool)
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(SpawningRagdollEventArgs))[0]),
new(OpCodes.Dup),
new(OpCodes.Dup),
Expand All @@ -71,7 +73,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Callvirt, PropertyGetter(typeof(SpawningRagdollEventArgs), nameof(SpawningRagdollEventArgs.IsAllowed))),
new(OpCodes.Brtrue_S, cnt),

// gameobject loads into stack before il inject
// destroy ragdoll and ret null
new(OpCodes.Ldloc_1),
new(OpCodes.Callvirt, PropertyGetter(typeof(BasicRagdoll), nameof(BasicRagdoll.gameObject))),
new(OpCodes.Call, Method(typeof(Object), nameof(Object.Destroy), new[] { typeof(Object) })),
Expand All @@ -96,10 +98,6 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi

// ragdoll.gameObject.transform.localScale = targetScale
new(OpCodes.Callvirt, PropertySetter(typeof(Transform), nameof(Transform.localScale))),

// load ragdollInfo into stack*/
new(OpCodes.Ldloc_S, ev.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(SpawningRagdollEventArgs), nameof(SpawningRagdollEventArgs.Info))),
});

newInstructions.InsertRange(newInstructions.Count - 2, new CodeInstruction[]
Expand Down
Loading