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
41 changes: 41 additions & 0 deletions Celeste.Mod.mm/Patches/Monocle/ParticleType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using MonoMod;
using System;
using System.Collections.Generic;
using Mono.Cecil;
using MonoMod.Cil;

namespace Monocle {
class patch_ParticleType : ParticleType
{
[Obsolete("Unused. ParticleType instances are not added automatically.")]
private static List<ParticleType> AllTypes;

[MonoModIgnore]
[MonoModConstructor]
[PatchParticleTypeCtor]
public extern void ctor();

[MonoModIgnore]
[MonoModConstructor]
[PatchParticleTypeCtor]
public extern void ctor(ParticleType copyFrom);
}
}

namespace MonoMod {
/// <summary>
/// Patches the <see cref="Monocle.ParticleType"/> constructor to prevent it from adding all instances to an unused static list, which would keep them all alive forever.
/// </summary>
[MonoModCustomMethodAttribute(nameof(MonoModRules.PatchParticleTypeCtor))]
class PatchParticleTypeCtorAttribute : Attribute { }

static partial class MonoModRules {
public static void PatchParticleTypeCtor(ILContext context, CustomAttribute attrib) {
ILCursor cursor = new(context);

// remove the `AllTypes.Add(this);` call
cursor.GotoNext(MoveType.Before, instr => instr.MatchLdsfld("Monocle.ParticleType", "AllTypes"));
cursor.RemoveRange(3);
}
}
}
Loading