Skip to content

Commit

Permalink
refactor: reimplement justPressedSnQ
Browse files Browse the repository at this point in the history
  • Loading branch information
DemoJameson committed Oct 3, 2023
1 parent 1c9bb45 commit d12c131
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
3 changes: 0 additions & 3 deletions CelesteTAS-EverestInterop/Source/EverestInterop/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ private static void Celeste_Update(On.Celeste.Celeste.orig_Update orig, Celeste.
orig(self, gameTime);
Manager.AdvanceThroughHiddenFrame = false;

if (!IsPause() && SaveAndQuitReenterCommand.JustPressedSnQ > 0)
SaveAndQuitReenterCommand.JustPressedSnQ--;

if (TasSettings.HideFreezeFrames && oldFreezeTimer > 0f && oldFreezeTimer > Engine.FreezeTimer) {
Manager.AdvanceThroughHiddenFrame = true;
loops += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using System.Collections.Generic;
using System.Reflection;
using Celeste;
using Mono.Cecil.Cil;
using Monocle;
using MonoMod.Cil;
using TAS.Module;
using TAS.Utils;

Expand Down Expand Up @@ -42,10 +42,7 @@ private IEnumerator Routine() {
}
}

// Cant be bool, because the update would set it to false, before the command gets executed
// 1 means that it was pressed on the previous frame
public static int JustPressedSnQ = 0;

private static bool justPressedSnQ = false;
public static SaveAndQuitReenterMode? LocalMode;
public static SaveAndQuitReenterMode? GlobalModeParsing;
public static SaveAndQuitReenterMode? GlobalModeRuntime;
Expand Down Expand Up @@ -88,12 +85,11 @@ private static void Load() {
typeof(Level)
.GetNestedType("<>c__DisplayClass149_0", BindingFlags.NonPublic)
.GetMethod("<Pause>b__8", BindingFlags.NonPublic | BindingFlags.Instance)
.IlHook(IlSaveAndQuit);
}

private static void IlSaveAndQuit(ILContext il) {
var cursor = new ILCursor(il);
cursor.EmitDelegate<Action>(() => JustPressedSnQ = 2);
.IlHook((cursor, _) => cursor.Emit(OpCodes.Ldc_I4_1)
.Emit(OpCodes.Stsfld, typeof(SaveAndQuitReenterCommand).GetFieldInfo(nameof(justPressedSnQ))));

typeof(Level).GetMethod("Update").IlHook((cursor, _) => cursor.Emit(OpCodes.Ldc_I4_0)
.Emit(OpCodes.Stsfld, typeof(SaveAndQuitReenterCommand).GetFieldInfo(nameof(justPressedSnQ))));
}

[ClearInputs]
Expand All @@ -112,7 +108,7 @@ private static void ParseFileEnd() {
private static void DisableRun() {
LocalMode = null;
GlobalModeRuntime = null;
JustPressedSnQ = 0;
justPressedSnQ = false;
}

[TasCommand("SaveAndQuitReenter", ExecuteTiming = ExecuteTiming.Parse | ExecuteTiming.Runtime)]
Expand Down Expand Up @@ -174,7 +170,7 @@ private static void SaveAndQuitReenter(string[] args, int studioLine, string fil
return;
}

if (JustPressedSnQ != 1) {
if (!justPressedSnQ) {
AbortTas("SaveAndQuitReenter must be exactly after pressing the \"Save & Quit\" button");
return;
}
Expand Down

0 comments on commit d12c131

Please sign in to comment.