Skip to content

Commit c0ac009

Browse files
committed
bugfix, run a tas with a save state twice, then hotkeys failed and even game crash, due to SimplifiedSpinner.OnLevelAddEntity, EntityList.ToAdd can be null
1 parent 43dc9ec commit c0ac009

File tree

3 files changed

+5
-20
lines changed

3 files changed

+5
-20
lines changed

Entities/SimplifiedSpinner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private static void OnLoadLevel(On.Celeste.Level.orig_LoadLevel orig, Level self
115115

116116
private static void OnLevelAddEntity(On.Monocle.EntityList.orig_UpdateLists orig, EntityList self) {
117117
if (self.Scene is Level) {
118-
AddingEntities |= self.ToAdd.Count > 0;
118+
AddingEntities |= self.ToAdd is { } var && var.Count > 0;
119119
}
120120
orig(self);
121121
}

Module/TASHelperModule.cs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ public TASHelperModule() {
1212

1313
public override Type SettingsType => typeof(TASHelperSettings);
1414
public override void Load() {
15-
On.Monocle.MInput.Update += HotkeysSaveSettings;
1615
On.Celeste.Level.Render += HotkeysPressed;
1716
Loader.HelperLoad();
1817
Loader.EntityLoad();
1918
}
2019

2120
public override void Unload() {
22-
On.Monocle.MInput.Update -= HotkeysSaveSettings;
2321
On.Celeste.Level.Render -= HotkeysPressed;
2422
Loader.HelperUnload();
2523
Loader.EntityUnload();
@@ -45,21 +43,11 @@ public override void CreateModMenuSection(TextMenu menu, bool inGame, EventInsta
4543
TASHelperMenu.CreateMenu(this, menu, inGame);
4644
}
4745

48-
49-
private static void HotkeysSaveSettings(On.Monocle.MInput.orig_Update orig) {
50-
orig();
51-
if (TASHelperSettings.hotkeysPressed) {
52-
Instance.SaveSettings();
53-
TASHelperSettings.hotkeysPressed = false;
54-
}
55-
// some part of MInput_Update is taken over by CelesteTAS, in that case orig() will not be called
56-
// so we can't press hotkeys here
57-
}
58-
5946
private static void HotkeysPressed(On.Celeste.Level.orig_Render orig, Level self) {
6047
orig(self);
61-
TASHelperSettings.hotkeysPressed = TasHelperSettings.SettingsHotkeysPressed();
62-
// if you call Instance.SaveSettings() here, then the game will crash if you open Menu-Mod Options in a Level and close the menu.
48+
if (TasHelperSettings.SettingsHotkeysPressed()) {
49+
Instance.SaveSettings();
50+
}
6351
}
6452
}
6553

Module/TASHelperSettings.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
using Microsoft.Xna.Framework;
44
using Microsoft.Xna.Framework.Input;
55
using Monocle;
6-
using System.Collections.Generic;
7-
using System.Linq;
86
using TAS.EverestInterop;
97
using static Celeste.Mod.TASHelper.Module.TASHelperSettings;
108
using static TAS.EverestInterop.Hotkeys;
@@ -442,7 +440,6 @@ public ButtonBinding KeyPixelGridWidth {
442440

443441
private List<Hotkey> Hotkeys = new();
444442

445-
internal static bool hotkeysPressed = false;
446443
public bool SettingsHotkeysPressed() {
447444
if (Engine.Scene is not Level level) {
448445
return false;
@@ -474,7 +471,7 @@ public bool SettingsHotkeysPressed() {
474471
MainSwitch = MainSwitchThreeStates ? MainSwitchModes.OnlyDefault : MainSwitchModes.AllowAll;
475472
break;
476473
}
477-
// it may happen that MainSwitchThreeStates = false but MainSwitch = OnlyDefault... it's ok
474+
// it may happen that MainSwitchThreeStates = false but MainSwitch = OnlyDefault... it's ok
478475
case MainSwitchModes.OnlyDefault: MainSwitch = MainSwitchModes.AllowAll; break;
479476
case MainSwitchModes.AllowAll: MainSwitch = MainSwitchModes.Off; break;
480477
}

0 commit comments

Comments
 (0)