Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
Patches fix (#203)
Browse files Browse the repository at this point in the history
* dying fix

* interacting generator fix
  • Loading branch information
IRacle1 authored Jan 2, 2023
1 parent 462be85 commit 1adde2a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Exiled.Events/Patches/Events/Player/DyingAndDied.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Ldarg_0),
new(OpCodes.Ldfld, Field(typeof(PlayerStats), nameof(PlayerStats._hub))),
new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),
/*new(OpCodes.Dup),*/
new(OpCodes.Dup),
new(OpCodes.Stloc_S, player.LocalIndex),

// handler
Expand Down
51 changes: 17 additions & 34 deletions Exiled.Events/Patches/Events/Player/InteractingGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Shared.Rent(instructions);

LocalBuilder player = generator.DeclareLocal(typeof(API.Features.Player));
LocalBuilder isAllowedUnlocking = generator.DeclareLocal(typeof(bool));

Label isOpening = generator.DefineLabel();
Label isActivating = generator.DefineLabel();
Label check = generator.DefineLabel();
Label check2 = generator.DefineLabel();
Label notAllowed = generator.DefineLabel();
Label skip = generator.DefineLabel();
Label skip2 = generator.DefineLabel();
Label @break = newInstructions.FindLast(instruction => instruction.IsLdarg(0)).labels[0];

int offset = 1;
Expand Down Expand Up @@ -154,41 +156,35 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new CodeInstruction(OpCodes.Nop).WithLabels(skip),
});

offset = -8;
index = newInstructions.FindIndex(
instruction => instruction.Calls(Method(typeof(Scp079Generator), nameof(Scp079Generator.ServerGrantTicketsConditionally)))) + offset;
offset = -5;
index = newInstructions.FindLastIndex(instruction => instruction.Calls(Method(typeof(Scp079Generator), nameof(Scp079Generator.RpcDenied)))) + offset;

// remove base game unlocking, we will unlock generator and grant tickets after UnlockingGeneratorEventArgs invokation and allowed check
newInstructions.RemoveRange(index, 9);
newInstructions.RemoveRange(index, 7);

offset = -5;
index = newInstructions.FindIndex(instruction => instruction.Calls(Method(typeof(Scp079Generator), nameof(Scp079Generator.RpcDenied)))) + offset;
offset = 0;
int index2 = newInstructions.FindLastIndex(instruction => instruction.LoadsConstant(51)) + offset;

newInstructions.InsertRange(
index,
new[]
{
// isAllowed var set
new(OpCodes.Ldc_I4_0),
new(OpCodes.Br_S, skip2),
new CodeInstruction(OpCodes.Ldc_I4_1).MoveLabelsFrom(newInstructions[index2]),
new CodeInstruction(OpCodes.Stloc_S, isAllowedUnlocking.LocalIndex).WithLabels(skip2),

// player
new CodeInstruction(OpCodes.Ldloc_S, player.LocalIndex).MoveLabelsFrom(newInstructions[index]),
new(OpCodes.Ldloc_S, player.LocalIndex),

// this
new(OpCodes.Ldarg_0),

// true
new(OpCodes.Ldc_I4_0),
});

index += 3;

// remove base game cooldown logic and RpcDenied (same as unlocking)
newInstructions.RemoveRange(index, 6);
// isAllowed
new(OpCodes.Ldloc_S, isAllowedUnlocking.LocalIndex),

newInstructions.InsertRange(
index,
new[]
{
// UnlockingGeneratorEventArgs ev = new(Player, Scp079Generator, bool)
new CodeInstruction(OpCodes.Newobj, GetDeclaredConstructors(typeof(UnlockingGeneratorEventArgs))[0]),
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(UnlockingGeneratorEventArgs))[0]),
new(OpCodes.Dup),

// Player.OnUnlockingGenerator(ev)
Expand All @@ -198,19 +194,6 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
// goto notAllowed;
new(OpCodes.Callvirt, PropertyGetter(typeof(UnlockingGeneratorEventArgs), nameof(UnlockingGeneratorEventArgs.IsAllowed))),
new(OpCodes.Brfalse_S, notAllowed),

// this.ServerSetFlag(GeneratorFlags.Unlocked, true)
new(OpCodes.Ldarg_0),
new(OpCodes.Ldc_I4_2), // GeneratorFlags.Unlocked
new(OpCodes.Ldc_I4_1),
new(OpCodes.Callvirt, Method(typeof(Scp079Generator), nameof(Scp079Generator.ServerSetFlag))),

// this.ServerGrantTicketsConditionally(new Footprinting.Footprint(ply), 0.5f)
new(OpCodes.Ldarg_0),
new(OpCodes.Ldarg_1),
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(Footprint))[0]),
new(OpCodes.Ldc_R4, 0.5f),
new(OpCodes.Call, Method(typeof(Scp079Generator), nameof(Scp079Generator.ServerGrantTicketsConditionally))),
});

offset = -5;
Expand Down

0 comments on commit 1adde2a

Please sign in to comment.