-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
CelesteTAS-EverestInterop/Source/EverestInterop/BetterInvincible.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using MonoMod.Cil; | ||
using Celeste; | ||
using TAS.Module; | ||
using TAS.Utils; | ||
|
||
namespace TAS.EverestInterop; | ||
internal static class BetterInvincible { | ||
// merged from TAS Helper | ||
|
||
// make you invincible while still make tas sync | ||
// it will not persist after SL, and that's what we want! | ||
|
||
// if it (before savepoint) gets deleted, then tas file changes, so it should be detected and disable run will be invoked, and savestate will be cleared | ||
// if it (after savepoint) gets deleted, .... yeah it just gets deleted, when restart from savestate, Invincible = false will be loaded (as it's saved as such) | ||
|
||
// note that if you use RESTART hotkey ("=" by default), then LoadState will be invoked (if it's saved), but DisableRun won't!! | ||
|
||
public static bool Invincible = false; | ||
|
||
[Initialize] | ||
|
||
private static void Initialize() { | ||
typeof(Player).GetMethod("orig_Die").IlHook(il => { | ||
ILCursor cursor = new ILCursor(il); | ||
if (cursor.TryGotoNext(MoveType.After, ins => ins.MatchLdfld<Assists>("Invincible"))) { | ||
cursor.EmitDelegate(ModifyInvincible); | ||
} | ||
}); | ||
} | ||
|
||
|
||
[DisableRun] | ||
private static void OnDisableRun() { | ||
Invincible = false; | ||
} | ||
|
||
private static bool ModifyInvincible(bool origValue) { | ||
// Manager.Running may be redundant.. | ||
return origValue || (Invincible && Manager.Running && TasSettings.BetterInvincible); // safe guard, in case that disable run thing doesn't work somehow | ||
} | ||
|
||
public static bool Handle(Assists assist, bool value) { | ||
if (!Manager.Running || !TasSettings.BetterInvincible) { | ||
return false; | ||
} | ||
bool beforeInvincible = assist.Invincible; | ||
if (beforeInvincible == value) { | ||
return true; | ||
} | ||
if (!beforeInvincible) { | ||
assist.Invincible = false; | ||
SaveData.Instance.Assists = assist; | ||
// Assists is a struct, so it needs to be re-assign | ||
} | ||
Invincible = !beforeInvincible; | ||
// if originally invincible = true, but set to false, then betterInv = false | ||
// if originally inv = false, but set to true, then inv = false, and betterInv = true | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters