Skip to content

Commit

Permalink
Port Mini Heart Door Unfix Controller from FLCC
Browse files Browse the repository at this point in the history
  • Loading branch information
maddie480 authored Aug 12, 2024
1 parent 6c47c64 commit 00c078c
Show file tree
Hide file tree
Showing 6 changed files with 2,532 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Ahorn/entities/maxHelpingHandMiniHeartDoorUnfixController.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module MaxHelpingHandMiniHeartDoorUnfixController

using ..Ahorn, Maple

@mapdef Entity "MaxHelpingHand/MiniHeartDoorUnfixController" MiniHeartDoorUnfixController(x::Integer, y::Integer)

const placements = Ahorn.PlacementDict(
"Mini Heart Door Unfix Controller (Maddie's Helping Hand)" => Ahorn.EntityPlacement(
MiniHeartDoorUnfixController
)
)

function Ahorn.selection(entity::MiniHeartDoorUnfixController)
x, y = Ahorn.position(entity)

return Ahorn.Rectangle(x - 12, y - 12, 24, 24)
end

Ahorn.render(ctx::Ahorn.Cairo.CairoContext, entity::MiniHeartDoorUnfixController, room::Maple.Room) = Ahorn.drawImage(ctx, "ahorn/miniheartdoorunfix", -12, -12)

end
50 changes: 50 additions & 0 deletions Entities/MiniHeartDoorUnfixController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Celeste;
using Celeste.Mod.Entities;
using Microsoft.Xna.Framework;
using Mono.Cecil.Cil;
using Monocle;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;

namespace Celeste.Mod.MaxHelpingHand.Entities {
// This controller reverts this fix, and was made to fix a map from Etpio in FLCC: https://github.com/EverestAPI/CelesteCollabUtils2/pull/60
[CustomEntity("MaxHelpingHand/MiniHeartDoorUnfixController")]
[Tracked]
class MiniHeartDoorUnfixController : Entity {
private static ILHook miniHeartDoorHook = null;

public static void Initialize() {
if (miniHeartDoorHook != null) return;

Type miniHeartDoorClass = Everest.Modules.FirstOrDefault(module => module.GetType().ToString() == "Celeste.Mod.CollabUtils2.CollabModule")?.GetType().Assembly

Check failure on line 19 in Entities/MiniHeartDoorUnfixController.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Type' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 19 in Entities/MiniHeartDoorUnfixController.cs

View workflow job for this annotation

GitHub Actions / build

'ReadOnlyCollection<EverestModule>' does not contain a definition for 'FirstOrDefault' and no accessible extension method 'FirstOrDefault' accepting a first argument of type 'ReadOnlyCollection<EverestModule>' could be found (are you missing a using directive or an assembly reference?)
.GetType("Celeste.Mod.CollabUtils2.Entities.MiniHeartDoor");

if (miniHeartDoorClass != null) {
miniHeartDoorHook = new ILHook(miniHeartDoorClass.GetMethod("Update"), modMiniHeartDoorUpdate);
}
}

public static void Unload() {
miniHeartDoorHook?.Dispose();
miniHeartDoorHook = null;
}

private static void modMiniHeartDoorUpdate(ILContext il) {
ILCursor cursor = new ILCursor(il);

while(cursor.TryGotoNext(MoveType.After, instr => instr.MatchCall<HeartGemDoor>("get_Opened"))) {
cursor.Emit(OpCodes.Ldarg_0);
cursor.EmitDelegate<Func<bool, HeartGemDoor, bool>>((orig, self) => {

Check failure on line 37 in Entities/MiniHeartDoorUnfixController.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Func<,,>' could not be found (are you missing a using directive or an assembly reference?)
if (self.Scene.Tracker.CountEntities<MiniHeartDoorUnfixController>() > 0) {
// this condition wasn't here before the fix, so we want to make it true!
return true;
}
return orig;
});
}
}

public MiniHeartDoorUnfixController(EntityData data, Vector2 offset) : base(data.Position + offset) { }
}
}
Loading

0 comments on commit 00c078c

Please sign in to comment.