Skip to content

Commit

Permalink
patch fixes and optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
IRacle1 committed Dec 26, 2024
1 parent e183f91 commit b0e2aa8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
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);

int offset = 2;
int offset = -5;
int index = newInstructions.FindIndex(x => x.opcode == OpCodes.Ldloc_S) + offset;

Label continueLabel = generator.DefineLabel();
Expand Down
10 changes: 3 additions & 7 deletions EXILED/Exiled.Events/Patches/Events/Scp1507/Scream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,9 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

int index = newInstructions.FindIndex(x => x.opcode == OpCodes.Ldarg_0);

Label retLabel = generator.DefineLabel();

newInstructions[newInstructions.Count - 1].labels.Add(retLabel);

newInstructions.InsertRange(
index,
new CodeInstruction[]
newInstructions.InsertRange(0, new CodeInstruction[]
{
// Player.Get(this.Owner);
new(OpCodes.Ldarg_0),
Expand All @@ -62,6 +56,8 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Brfalse_S, retLabel),
});

newInstructions[newInstructions.Count - 1].labels.Add(retLabel);

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 @@ -73,6 +73,8 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Ldloc_S, ev.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(FindingPositionEventArgs), nameof(FindingPositionEventArgs.Spawnpoint))),
new(OpCodes.Stind_Ref),

new(OpCodes.Br_S, continueLabel),
});

for (int z = 0; z < newInstructions.Count; z++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
LocalBuilder ev = generator.DeclareLocal(typeof(GrantingGiftEventArgs));

int offset = -1;
int index = newInstructions.FindLastIndex(x => x.opcode == OpCodes.Ldfld && x.operand == (object)Field(typeof(Scp2536GiftBase), nameof(Scp2536GiftBase.ObtainedBy))) + offset;
int index = newInstructions.FindLastIndex(x => x.LoadsField(Field(typeof(Scp2536GiftBase), nameof(Scp2536GiftBase.ObtainedBy)))) + offset;

newInstructions.InsertRange(index, new CodeInstruction[]
{
Expand Down
4 changes: 2 additions & 2 deletions EXILED/Exiled.Events/Patches/Events/Scp2536/OpeningGift.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
Label retLabel = generator.DefineLabel();

int offset = -3;
int index = newInstructions.FindLastIndex(x => x.operand == (object)Method(typeof(Scp2536GiftController), nameof(Scp2536GiftController.RpcSetGiftState))) + offset;
int index = newInstructions.FindLastIndex(x => x.Calls(Method(typeof(Scp2536GiftController), nameof(Scp2536GiftController.RpcSetGiftState)))) + offset;

newInstructions.InsertRange(index, new CodeInstruction[]
{
// Player.Get(hub);
new(OpCodes.Ldarg_1),
new CodeInstruction(OpCodes.Ldarg_1).MoveLabelsFrom(newInstructions[index]),
new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),

// true
Expand Down

0 comments on commit b0e2aa8

Please sign in to comment.