Skip to content

Commit

Permalink
fix: Code hot-reloading support
Browse files Browse the repository at this point in the history
  • Loading branch information
psyGamer committed Jan 1, 2025
1 parent 6454557 commit bfbaa1c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CelesteTAS-EverestInterop/Source/EverestInterop/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private static void Load() {
IL.Monocle.Engine.Update += IL_Engine_Update;

typeof(GameInput)
.GetMethod(nameof(GameInput.UpdateGrab))
.GetMethod(nameof(GameInput.UpdateGrab))!
.SkipMethod(IsPaused);

// The original mod makes the MInput.Update call conditional and invokes UpdateInputs afterwards.
Expand Down
23 changes: 10 additions & 13 deletions CelesteTAS-EverestInterop/Source/TAS/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,26 @@ private static void Initialize() {
// Hot-reloading support
[Load]
private static void RestoreStudioTasFilePath() {
Controller.FilePath = Engine.Instance.GetDynamicDataInstance()
.Get<string>("CelesteTAS_FilePath");
if (Engine.Instance.GetDynamicDataInstance().Get<string>("CelesteTAS_FilePath") is { } filePath) {
Controller.FilePath = filePath;
}

Everest.Events.AssetReload.OnBeforeReload += OnAssetReload;
// Stop TAS to avoid blocking reload
typeof(AssetReloadHelper)
.GetMethodInfo(nameof(AssetReloadHelper.Do))
.HookBefore(DisableRun);
}

[Unload]
private static void SaveStudioTasFilePath() {
Engine.Instance.GetDynamicDataInstance()
.Set("CelesteTAS_FilePath", Controller.FilePath);

Everest.Events.AssetReload.OnBeforeReload -= OnAssetReload;
Engine.Instance.GetDynamicDataInstance().Set("CelesteTAS_FilePath", Controller.FilePath);

Controller.Stop();
Controller.Clear();
}

private static void OnAssetReload(bool silent) => DisableRun();
#endif

public static void EnableRun()
{
public static void EnableRun() {
if (Running) {
return;
}
Expand All @@ -104,8 +102,7 @@ public static void EnableRun()
Savestates.EnableRun();
}

public static void DisableRun()
{
public static void DisableRun() {
if (!Running) {
return;
}
Expand Down

0 comments on commit bfbaa1c

Please sign in to comment.