Skip to content

Commit 9f7f269

Browse files
authored
Merge pull request #174 from EverestAPI/camera_catchup_speed_trigger
Camera Catchup Speed Trigger (for high speed situations)
2 parents 1870da2 + 37d9341 commit 9f7f269

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

Ahorn/lang/en_gb.lang

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,6 @@ placements.entities.SpringCollab2020/SeekerStatueCustomColors.tooltips.trailColo
273273
# Custom Respawn Time Refill
274274
placements.entities.SpringCollab2020/CustomRespawnTimeRefill.tooltips.twoDash=Whether the refill should give two dashes.
275275
placements.entities.SpringCollab2020/CustomRespawnTimeRefill.tooltips.respawnTime=The delay (in seconds) before the refill respawns after being collected.
276+
277+
# Camera Catchup Speed Trigger
278+
placements.triggers.SpringCollab2020/CameraCatchupSpeedTrigger.tooltips.catchupSpeed=Raise this value to have the camera scroll quicker to its target. Vanilla values are 8 during the temple fall cutscene, and 1 everywhere else.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module SpringCollab2020CameraCatchupSpeedTrigger
2+
3+
using ..Ahorn, Maple
4+
5+
@mapdef Trigger "SpringCollab2020/CameraCatchupSpeedTrigger" CameraCatchupSpeedTrigger(x::Integer, y::Integer, width::Integer=Maple.defaultTriggerWidth, height::Integer=Maple.defaultTriggerHeight,
6+
catchupSpeed::Number=1.0)
7+
8+
const placements = Ahorn.PlacementDict(
9+
"Camera Catchup Speed (Spring Collab 2020)" => Ahorn.EntityPlacement(
10+
CameraCatchupSpeedTrigger,
11+
"rectangle"
12+
)
13+
)
14+
15+
end

SpringCollab2020Module.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public override void Load() {
3232
BlockJellySpawnTrigger.Load();
3333
StrawberryIgnoringLighting.Load();
3434
SeekerCustomColors.Load();
35+
CameraCatchupSpeedTrigger.Load();
3536
}
3637

3738
public override void LoadContent(bool firstLoad) {
@@ -59,6 +60,7 @@ public override void Unload() {
5960
BlockJellySpawnTrigger.Unload();
6061
StrawberryIgnoringLighting.Unload();
6162
SeekerCustomColors.Unload();
63+
CameraCatchupSpeedTrigger.Unload();
6264
}
6365

6466
public override void PrepareMapDataProcessors(MapDataFixup context) {
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using Celeste.Mod.Entities;
2+
using Microsoft.Xna.Framework;
3+
using Mono.Cecil.Cil;
4+
using Monocle;
5+
using MonoMod.Cil;
6+
using MonoMod.RuntimeDetour;
7+
using System;
8+
9+
namespace Celeste.Mod.SpringCollab2020.Triggers {
10+
[CustomEntity("SpringCollab2020/CameraCatchupSpeedTrigger")]
11+
[Tracked]
12+
class CameraCatchupSpeedTrigger : Trigger {
13+
private static ILHook playerOrigUpdateHook;
14+
15+
public static void Load() {
16+
playerOrigUpdateHook = new ILHook(typeof(Player).GetMethod("orig_Update"), modPlayerOrigUpdate);
17+
}
18+
19+
public static void Unload() {
20+
playerOrigUpdateHook?.Dispose();
21+
}
22+
23+
private static void modPlayerOrigUpdate(ILContext il) {
24+
ILCursor cursor = new ILCursor(il);
25+
26+
// we're looking for: 1f - (float)Math.Pow(0.01f / num2, Engine.DeltaTime)
27+
if (cursor.TryGotoNext(
28+
instr => instr.MatchLdcR4(0.01f),
29+
instr => instr.OpCode == OpCodes.Ldloc_S,
30+
instr => instr.MatchDiv())) {
31+
32+
// and we want to position the cursor just after loading num2
33+
cursor.Index += 2;
34+
35+
Logger.Log("SpringCollab2020/CameraCatchupSpeedTrigger", $"Inserting code to mod camera catchup speed at {cursor.Index} in IL for Player.orig_Update()");
36+
37+
// this delegate will allow us to turn num2 into something else.
38+
cursor.Emit(OpCodes.Ldarg_0);
39+
cursor.EmitDelegate<Func<float, Player, float>>((orig, self) => {
40+
CameraCatchupSpeedTrigger trigger = self.CollideFirst<CameraCatchupSpeedTrigger>();
41+
if (trigger != null) {
42+
return trigger.catchupSpeed;
43+
}
44+
return orig;
45+
});
46+
}
47+
}
48+
49+
50+
private float catchupSpeed;
51+
52+
public CameraCatchupSpeedTrigger(EntityData data, Vector2 offset) : base(data, offset) {
53+
catchupSpeed = data.Float("catchupSpeed", 1f);
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)