Skip to content

Commit

Permalink
Patch fix 1 (#225)
Browse files Browse the repository at this point in the history
PositionSpawnScp0492Fix patch #223 
Scp3114FriendlyFireFix #224
  • Loading branch information
Misaka-ZeroTwo authored Nov 27, 2024
1 parent 71cf637 commit ed8a22e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 182 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,7 @@ NuGet.config
_site/

# JSON Schemas
JSON/
JSON/

# Mac DS_Store
.DS_Store
56 changes: 0 additions & 56 deletions EXILED/Exiled.Events/Patches/Fixes/PositionSpawnScp0492Fix.cs
Original file line number Diff line number Diff line change
@@ -1,56 +0,0 @@
// -----------------------------------------------------------------------
// <copyright file="PositionSpawnScp0492Fix.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
{
using System.Collections.Generic;
using System.Reflection.Emit;

using API.Features;
using API.Features.Pools;
using Exiled.Events.EventArgs.Player;

using HarmonyLib;

using PlayerRoles.PlayableScps.Scp049;

using UnityEngine;

using static HarmonyLib.AccessTools;

/// <summary>
/// Patches <see cref="Scp049ResurrectAbility.ServerComplete"/> delegate.
/// Removes useless position setter for Scp0492.
/// </summary>
[HarmonyPatch(typeof(Scp049ResurrectAbility), nameof(Scp049ResurrectAbility.ServerComplete))]
internal static class PositionSpawnScp0492Fix
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

Label continueLabel = generator.DefineLabel();

LocalBuilder player = generator.DeclareLocal(typeof(Player));
LocalBuilder eventArgs = generator.DeclareLocal(typeof(SpawningEventArgs));

const int toRemove = 7;

const int offset = -1;
int index = newInstructions.FindLastIndex(instruction => instruction.Calls(PropertyGetter(typeof(Component), nameof(Component.transform)))) + offset;

newInstructions[index + toRemove].MoveLabelsFrom(newInstructions[index]);

newInstructions.RemoveRange(index, toRemove);

for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];

ListPool<CodeInstruction>.Pool.Return(newInstructions);
}
}
}
125 changes: 0 additions & 125 deletions EXILED/Exiled.Events/Patches/Fixes/Scp3114FriendlyFireFix.cs
Original file line number Diff line number Diff line change
@@ -1,125 +0,0 @@
// -----------------------------------------------------------------------
// <copyright file="Scp3114FriendlyFireFix.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 SA1402 // File may only contain a single type
using System.Collections.Generic;
using System.Reflection.Emit;

using API.Features.Pools;

using Exiled.API.Features;

using Footprinting;
using HarmonyLib;
using InventorySystem.Items.Pickups;
using InventorySystem.Items.ThrowableProjectiles;
using PlayerRoles;
using PlayerStatsSystem;

using static HarmonyLib.AccessTools;

/// <summary>
/// Patches the <see cref="Scp2176Projectile.ServerShatter()"/> delegate.
/// Fix Throwing a ghostlight with Scp in the room stun 079.
/// Bug reported to NW (https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/55).
/// </summary>
[HarmonyPatch(typeof(Scp2176Projectile), nameof(Scp2176Projectile.ServerShatter))]
internal class Scp3114FriendlyFireFix
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

Label cnt = generator.DefineLabel();

int offset = 0;
int index = newInstructions.FindIndex(x => x.LoadsField(Field(typeof(RoomLightController), nameof(RoomLightController.Instances)))) + offset;

Label skip = newInstructions[index].labels[0];

offset = -3;
index += offset;

newInstructions.InsertRange(index, new[]
{
// if (this.PreviousOwner.Role.GetTeam() is Team.SCPs)
new CodeInstruction(OpCodes.Ldarg_0).MoveLabelsFrom(newInstructions[index]),
new(OpCodes.Ldfld, Field(typeof(Scp2176Projectile), nameof(Scp2176Projectile.PreviousOwner))),
new(OpCodes.Ldfld, Field(typeof(Footprint), nameof(Footprint.Role))),
new(OpCodes.Call, Method(typeof(PlayerRolesUtils), nameof(PlayerRolesUtils.GetTeam), new[] { typeof(RoleTypeId) })),
new(OpCodes.Ldc_I4_0),
new(OpCodes.Ceq),

new(OpCodes.Brfalse_S, cnt),

new(OpCodes.Pop),
new(OpCodes.Br_S, skip),

new CodeInstruction(OpCodes.Nop).WithLabels(cnt),
});

for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];

ListPool<CodeInstruction>.Pool.Return(newInstructions);
}
}

/// <summary>
/// Patches the <see cref="CollisionDetectionPickup.ProcessCollision(UnityEngine.Collision)"/> delegate.
/// Fix Throwing a ghostlight with Scp in the room stun 079.
/// Bug reported to NW (https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/55).
/// </summary>
[HarmonyPatch(typeof(CollisionDetectionPickup), nameof(CollisionDetectionPickup.ProcessCollision))]
internal class Scp3114FriendlyFireFix2 : AttackerDamageHandler
{
#pragma warning disable SA1600 // Elements should be documented
public Scp3114FriendlyFireFix2(Footprint attacker, float damage)
{
Attacker = attacker;
Damage = damage;
AllowSelfDamage = false;
ServerLogsText = "Scp3114 Fix";
}

public override Footprint Attacker { get; set; }

public override bool AllowSelfDamage { get; }

public override float Damage { get; set; }

public override string ServerLogsText { get; }

#pragma warning restore SA1600 // Elements should be documented

private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

int offset = 0;
int index = newInstructions.FindLastIndex(x => x.opcode == OpCodes.Ldnull) + offset;

// replace null with new Scp3114FriendlyFireFix2(this.PreviousOwner, num2)
newInstructions.RemoveAt(index);
newInstructions.InsertRange(index, new CodeInstruction[]
{
// new Scp3114FriendlyFireFix2(this.PreviousOwner, num2)
new(OpCodes.Ldarg_0),
new(OpCodes.Ldfld, Field(typeof(CollisionDetectionPickup), nameof(CollisionDetectionPickup.PreviousOwner))),
new(OpCodes.Ldloc_3),
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(Scp3114FriendlyFireFix2))[0]),
});

for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];

ListPool<CodeInstruction>.Pool.Return(newInstructions);
}
}
}

0 comments on commit ed8a22e

Please sign in to comment.