Skip to content

Commit

Permalink
Fixed Badeline last node crash (#657)
Browse files Browse the repository at this point in the history
Co-authored-by: DemoJameson <[email protected]>
  • Loading branch information
nhruo123 and DemoJameson authored Aug 5, 2023
1 parent 71a954e commit 09fca26
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions Celeste.Mod.mm/Content/Dialog/English.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
POSTCARD_MISSINGTUTORIAL= {big}Oops!{/big}{n}The playback tutorial {#ff1144}((tutorial)){#} could not be found.{n}Check your {#44adf7}log.txt{#} for more info.
POSTCARD_TILEXMLERROR= {big}Oops!{/big}{n}There was an error parsing a tileset in {#ff1144}((path)){#}{n}Check your {#44adf7}log.txt{#} for more info.
POSTCARD_XMLERROR= {big}Oops!{/big}{n}{#ff1144}((path)){#} has a syntax error.{n}Check your {#44adf7}log.txt{#} for more info.
POSTCARD_BOSSLASTNODEHIT= {big}Oops!{/big}{n}{#ff1144}Badeline Boss{#} entity was hit on its last node, please add an additional node outside of the current room to ensure the player never hits it.

# Main Menu
MENU_TITLETOUCH= TOUCH
Expand Down
23 changes: 22 additions & 1 deletion Celeste.Mod.mm/Patches/FinalBoss.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma warning disable CS0626 // Method, operator, or accessor is marked external and has no attributes on it
#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value

using System;
using Celeste.Mod;
using Microsoft.Xna.Framework;
using Mono.Cecil;
using Mono.Cecil.Cil;
Expand All @@ -13,6 +15,10 @@ class patch_FinalBoss : FinalBoss {

private bool canChangeMusic;

private int nodeIndex;

private Vector2[] nodes;

public patch_FinalBoss(EntityData e, Vector2 offset)
: base(e, offset) {
// no-op. MonoMod ignores this - we only need this to make the compiler shut up.
Expand All @@ -30,14 +36,29 @@ public void ctor(EntityData data, Vector2 offset) {
[PatchBadelineBossOnPlayer] // ... except for manually manipulating the method via MonoModRules
public new extern void OnPlayer(Player player);

private extern void orig_PushPlayer(Player player);

private void PushPlayer(Player player) {
// ensure we are not hitting the last node
if (nodeIndex >= nodes.Length) {
Logger.Log(LogLevel.Warn, "FinalBoss",
"FinalBoss entity was hit on its last node, please add an additional node outside of the current room to ensure the player never hits it.");
patch_LevelEnter.ErrorMessage = Dialog.Get("postcard_bosslastnodehit");

// we want to call LevelEnter.Go explicitly instant of letting CheckForErrors call it to prevent double triggers of postcard
LevelEnter.Go((Scene as Level).Session, false);
} else {
orig_PushPlayer(player);
}
}

public bool CanChangeMusic(bool value) {
Level level = Scene as Level;
if (level.Session.Area.GetLevelSet() == "Celeste")
return value;

return canChangeMusic;
}

}
}

Expand Down

0 comments on commit 09fca26

Please sign in to comment.