Skip to content
Open
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
48 changes: 47 additions & 1 deletion Celeste.Mod.mm/Patches/Dust.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
using Microsoft.Xna.Framework;
using System;
using Celeste;
using Microsoft.Xna.Framework;
using Mono.Cecil;
using Monocle;
using MonoMod;
using MonoMod.Cil;

namespace Celeste {
// Dust is static.
Expand All @@ -7,5 +13,45 @@ class patch_Dust {
public static void Burst(Vector2 position, float direction, int count = 1) {
Dust.Burst(position, direction, count, null);
}

[MonoModIgnore]
[PatchDustBurst]
public static extern void Burst(Vector2 position, float direction, int count, ParticleType particleType);

[MonoModIgnore]
[PatchDustBurst]
public static extern void BurstFG(Vector2 position, float direction, int count, float range, ParticleType particleType);

}
}

namespace MonoMod {

/// <summary>
/// Add an early return if Engine.Scene is not a Level, to avoid a crash.
/// </summary>
[MonoModCustomMethodAttribute(nameof(MonoModRules.PatchDustBurst))]
class PatchDustBurstAttribute : Attribute {}

static partial class MonoModRules {

public static void PatchDustBurst(ILContext context, CustomAttribute attrib) {
ILCursor cursor = new ILCursor(context);

ILLabel beforeRet = cursor.DefineLabel();
int loc = -1;

cursor.GotoNext(MoveType.After,
instr => instr.MatchIsinst(out var _),
instr => instr.MatchStloc(out loc));
cursor.EmitLdloc(loc);
cursor.EmitBrfalse(beforeRet);

cursor.GotoNext(MoveType.Before,
instr => instr.MatchRet());
cursor.MarkLabel(beforeRet);
}

}

}
Loading