Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public SavingByAntiScp207EventArgs(ReferenceHub player, float damageAmount, Dama
Handler = handler;
HitboxType = hitboxType;
DamageAmount = damageAmount;
DamageMultiplier = (Player.Health + Player.ArtificialHealth - AntiScp207.DeathSaveHealth) / damageAmount;
IsAllowed = true;
}

/// <summary>
Expand All @@ -46,14 +44,9 @@ public SavingByAntiScp207EventArgs(ReferenceHub player, float damageAmount, Dama
public float DamageAmount { get; }

/// <summary>
/// Gets or sets the multiplier for the damage that is applied when the event is allowed.
/// Gets or sets the health amount the player will have after being saved from death.
/// </summary>
public float DamageMultiplier { get; set; }

/// <summary>
/// Gets or sets the multiplier for the damage that if event denied.
/// </summary>
public float DeniedDamageMultiplier { get; set; } = 1;
public float DeathSaveHealth { get; set; } = AntiScp207.DeathSaveHealth;

/// <summary>
/// Gets the damage handler that describes the incoming damage.
Expand All @@ -69,6 +62,6 @@ public SavingByAntiScp207EventArgs(ReferenceHub player, float damageAmount, Dama
/// Gets or sets a value indicating whether the event is allowed.
/// If set to <c>false</c>, the event will be denied.
/// </summary>
public bool IsAllowed { get; set; }
public bool IsAllowed { get; set; } = true;
}
}
22 changes: 11 additions & 11 deletions EXILED/Exiled.Events/Patches/Events/Player/SavingByAntiScp207.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

Label skipLabel = generator.DefineLabel();
LocalBuilder ev = generator.DeclareLocal(typeof(SavingByAntiScp207EventArgs));

int index = newInstructions.FindLastIndex(x => x.opcode == OpCodes.Ldloc_1);

Label skipLabel = generator.DefineLabel();
Label gotoEventLabel = newInstructions[index].labels[0];
List<Label> mainLogicLabels = newInstructions[index].ExtractLabels();

newInstructions[index].labels = new List<Label> { skipLabel };
newInstructions[index].WithLabels(skipLabel);

newInstructions.InsertRange(index, new CodeInstruction[]
{
// this.Hub
new CodeInstruction(OpCodes.Ldarg_0).WithLabels(gotoEventLabel),
new CodeInstruction(OpCodes.Ldarg_0).WithLabels(mainLogicLabels),
new(OpCodes.Call, PropertyGetter(typeof(StatusEffectBase), nameof(StatusEffectBase.Hub))),

// damageAmount
Expand All @@ -64,24 +64,24 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Call, Method(typeof(Handlers.Player), nameof(Handlers.Player.OnSavingByAntiScp207))),

// if (!ev.IsAllowed)
// return ev.DeniedDamageMultiplier;
// return 1f;
new(OpCodes.Ldloc_S, ev.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(SavingByAntiScp207EventArgs), nameof(SavingByAntiScp207EventArgs.IsAllowed))),
new(OpCodes.Brtrue_S, skipLabel),

new(OpCodes.Ldloc_S, ev.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(SavingByAntiScp207EventArgs), nameof(SavingByAntiScp207EventArgs.DeniedDamageMultiplier))),
new(OpCodes.Ldc_R4, 1f),
new(OpCodes.Ret),
});

index = newInstructions.FindLastIndex(i => i.opcode == OpCodes.Ldloc_2);
const int Offset = 1;
index = newInstructions.FindLastIndex(i => i.opcode == OpCodes.Ldloc_1) + Offset;

newInstructions.RemoveAt(index);
newInstructions.InsertRange(index, new CodeInstruction[]
{
// return ev.DamageMultiplier;
// module.CurValue = ev.DeathSaveHealth;
new(OpCodes.Ldloc_S, ev.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(SavingByAntiScp207EventArgs), nameof(SavingByAntiScp207EventArgs.DamageMultiplier))),
new(OpCodes.Ret),
new(OpCodes.Callvirt, PropertyGetter(typeof(SavingByAntiScp207EventArgs), nameof(SavingByAntiScp207EventArgs.DeathSaveHealth))),
});

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