Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
15 changes: 0 additions & 15 deletions Celeste.Mod.mm/Patches/Actor.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#pragma warning disable CS0626 // Method, operator, or accessor is marked external and has no attributes on it

using Microsoft.Xna.Framework;
using MonoMod;

namespace Celeste {
class patch_Actor : Actor {

private Vector2 movementCounter = default;

public patch_Actor(Vector2 position)
: base(position) {
// no-op. MonoMod ignores this - we only need this to make the compiler shut up.
Expand All @@ -18,17 +15,5 @@ protected bool TrySquishWiggle(CollisionData data) {
return TrySquishWiggle(data, 3, 3);
}

// Patch MoveToX/Y to replicate XNA's behaviour on FNA

[MonoModReplace]
public new void MoveToX(float toX, Collision onCollide = null) {
MoveH((float) ((double) toX - Position.X - movementCounter.X), onCollide);
}

[MonoModReplace]
public new void MoveToY(float toY, Collision onCollide = null) {
MoveV((float) ((double) toY - Position.Y - movementCounter.Y), onCollide);
}

}
}
24 changes: 0 additions & 24 deletions Celeste.Mod.mm/Patches/Bumper.cs

This file was deleted.

80 changes: 0 additions & 80 deletions Celeste.Mod.mm/Patches/DreamBlock.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
using Microsoft.Xna.Framework;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Monocle;
using MonoMod;
using MonoMod.Cil;
using System;
using System.Collections;
using System.Runtime.CompilerServices;
using System.Linq;

namespace Celeste {
class patch_DreamBlock : DreamBlock {

internal Vector2 movementCounter {
[MonoModLinkTo("Celeste.Platform", "get__movementCounter")] get;
}

private bool playerHasDreamDash;
private LightOcclude occlude;
private float whiteHeight;
Expand All @@ -38,10 +28,6 @@ public void ctor(Vector2 position, float width, float height, Vector2? node, boo
ctor(position, width, height, node, fastMoving, oneUse, false);
}

[MonoModIgnore]
[PatchDreamBlockSetup]
public new extern void Setup();

public void DeactivateNoRoutine() {
if (playerHasDreamDash) {
playerHasDreamDash = false;
Expand Down Expand Up @@ -199,71 +185,5 @@ private Vector2 PutInside(Vector2 pos) {
}
return pos;
}

// Patch XNA/FNA jank in Tween.OnUpdate lambda
[MonoModPatch("<>c__DisplayClass22_0")]
class patch_AddedLambdas {

[MonoModPatch("<>4__this")]
private patch_DreamBlock _this = default;
private Vector2 start = default, end = default;

[MonoModReplace]
[MonoModPatch("<Added>b__0")]
public void TweenUpdateLambda(Tween t) {
// Patch this to always behave like XNA
// This is absolutely hecking ridiculous and a perfect example of why we want to switch to .NET Core
// The Y member gets downcast but not the X one because of JIT jank
double lerpX = start.X + ((double) end.X - start.X) * t.Eased, lerpY = start.Y + ((double) end.Y - start.Y) * t.Eased;
float moveHDelta = (float) (lerpX - _this.Position.X - _this.movementCounter.X), moveVDelta = (float) ((double) JITBarrier((float) lerpY) - _this.Position.Y - _this.movementCounter.Y);
if (_this.Collidable) {
_this.MoveH(moveHDelta);
_this.MoveV(moveVDelta);
} else {
_this.MoveHNaive(moveHDelta);
_this.MoveVNaive(moveVDelta);
}
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static float JITBarrier(float v) => v;

}

}
}

namespace MonoMod {
/// <summary>
/// Patches <see cref="Celeste.DreamBlock.Setup()" /> to not rely on
/// non-IEEE 754 compliant .NET Framework jank anymore, by patching the
/// dream block particle count calculation to be done using doubles (the x86
/// .NET Framework JIT uses 80 bit x87 registers for this calculation,
/// however 64 bit doubles seem to have enough precision to end up at the
/// same results). This fixes issue #556.
/// </summary>
[MonoModCustomMethodAttribute(nameof(MonoModRules.PatchDreamBlockSetup))]
class PatchDreamBlockSetupAttribute : Attribute {}

static partial class MonoModRules {

public static void PatchDreamBlockSetup(ILContext context, CustomAttribute attrib) {
// Patch instructions before the 'conv.i4' cast to use doubles instead of floats
for (int i = 0; i < context.Instrs.Count; i++) {
Instruction instr = context.Instrs[i];

if (instr.MatchConvI4())
break;

// call(virt) <method returning float>
if (instr.MatchCallOrCallvirt(out MethodReference method) && method.ReturnType.MetadataType == MetadataType.Single)
context.Instrs.Insert(++i, Instruction.Create(OpCodes.Conv_R8)); // cast return value to double

// ldc.r4 <float constant>
if (instr.MatchLdcR4(out float val))
context.Instrs[i] = Instruction.Create(OpCodes.Ldc_R8, (double) val);
}
}

}
}
38 changes: 0 additions & 38 deletions Celeste.Mod.mm/Patches/FNA/MathHelper.cs

This file was deleted.

Loading
Loading