Skip to content

Commit

Permalink
yamatotototo
Browse files Browse the repository at this point in the history
  • Loading branch information
IRacle1 committed Aug 3, 2024
1 parent d88d592 commit f108caa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

LocalBuilder scp106Role = generator.DeclareLocal(typeof(Scp106Role));
Label continueLabel = generator.DefineLabel();

int offset = 1;
int index = newInstructions.FindLastIndex(x => x.operand == (object)Method(typeof(SpawnProtected), nameof(SpawnProtected.CheckPlayer))) + offset;

Label continueLabel = generator.DefineLabel();
Label skip = (Label)newInstructions[index].operand;

index += offset;
Expand All @@ -49,14 +51,14 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new CodeInstruction(OpCodes.Ldfld, Field(typeof(ReferenceHub), nameof(ReferenceHub.roleManager))),
new CodeInstruction(OpCodes.Callvirt, PropertyGetter(typeof(PlayerRoleManager), nameof(PlayerRoleManager.CurrentRole))),
new CodeInstruction(OpCodes.Isinst, typeof(Scp106Role)),
new CodeInstruction(OpCodes.Stloc_0),
new CodeInstruction(OpCodes.Stloc_S, scp106Role.LocalIndex),

// if (scp106Role is null) goto continueLabel
new CodeInstruction(OpCodes.Ldloc_0),
new CodeInstruction(OpCodes.Ldloc_S, scp106Role.LocalIndex),
new CodeInstruction(OpCodes.Brfalse_S, continueLabel),

// if (!scp106Role.IsSubmerged) goto skip
new CodeInstruction(OpCodes.Ldloc_0),
new CodeInstruction(OpCodes.Ldloc_S, scp106Role.LocalIndex),
new CodeInstruction(OpCodes.Callvirt, PropertyGetter(typeof(Scp106Role), nameof(Scp106Role.IsSubmerged))),
new CodeInstruction(OpCodes.Brtrue_S, skip),
});
Expand Down
25 changes: 17 additions & 8 deletions EXILED/Exiled.Events/Patches/Fixes/Scp3114FriendlyFireFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ namespace Exiled.Events.Patches.Fixes
using System.Reflection.Emit;

using API.Features.Pools;

using Exiled.API.Features;

using Footprinting;
using HarmonyLib;
using InventorySystem.Items.Pickups;
Expand All @@ -33,27 +36,33 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

Label cnt = generator.DefineLabel();

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

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

Label skip = (Label)newInstructions[index].operand;
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(OpCodes.Call, Method(typeof(PlayerRolesUtils), nameof(PlayerRolesUtils.GetTeam), new[] { typeof(RoleTypeId) })),
new(OpCodes.Ldc_I4_0),
new(OpCodes.Ceq),
new CodeInstruction(OpCodes.Brtrue_S, skip),
});

offset = 0;
index = newInstructions.FindIndex(x => x.operand == (object)Field(typeof(RoomLightController), nameof(RoomLightController.Instances))) + offset;
new(OpCodes.Brfalse_S, cnt),

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

newInstructions[index].labels.Add(skip);
new CodeInstruction(OpCodes.Nop).WithLabels(cnt),
});

for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

// replace Contains with StartWith
int index = newInstructions.FindIndex(x => x.operand == (object)Method(typeof(string), nameof(string.Contains)));
int index = newInstructions.FindIndex(x => x.operand == (object)Method(typeof(string), nameof(string.Contains), new[] { typeof(string) }));
newInstructions[index].operand = Method(typeof(string), nameof(string.StartsWith), new System.Type[] { typeof(string) });

for (int z = 0; z < newInstructions.Count; z++)
Expand Down

0 comments on commit f108caa

Please sign in to comment.