Skip to content

Commit

Permalink
feat: make no low health effect toggleable any time
Browse files Browse the repository at this point in the history
  • Loading branch information
Clazex committed Jan 26, 2023
1 parent 4a20942 commit 229fb4b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 18 deletions.
2 changes: 1 addition & 1 deletion GodSeekerPlus/GodSeekerPlus.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>GodSeekerPlus</AssemblyTitle>
<Version>0.22.0</Version>
<Version>0.23.0</Version>
<Description>A Hollow Knight mod to enhance your Godhome experience</Description>
<Authors>Clazex</Authors>

Expand Down
76 changes: 59 additions & 17 deletions GodSeekerPlus/Modules/Cosmetic/NoLowHealthEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,84 @@
namespace GodSeekerPlus.Modules.Cosmetic;

public sealed class NoLowHealthEffect : Module {
public override ToggleableLevel ToggleableLevel => ToggleableLevel.ReloadSave;
private static readonly GameObjectRef healthRef =
new(GameObjectRef.DONT_DESTROY_ON_LOAD, "_GameCameras", "HudCamera", "Hud Canvas", "Health");

private protected override void Load() {
private static readonly GameObjectRef damageEffectsRef =
new(GameObjectRef.DONT_DESTROY_ON_LOAD, "Knight", "Effects", "Damage Effect");

public NoLowHealthEffect() =>
On.PlayMakerFSM.Start += ModifyFSM;

private protected override void Load() {
IL.HeroAnimationController.PlayIdle += RemoveAnimation;

if (Ref.HC != null) {
Fsm fsm = GameObjectUtil.FindGameObjectByRef(Ref.DDOL, healthRef).LocateMyFSM("Low Health FX").Fsm;

if (fsm.ActiveStateName is "Low Health On Entry" or "Low Health") {
fsm.SetState("Idle");
}
}
}

private protected override void Unload() {
On.PlayMakerFSM.Start -= ModifyFSM;
IL.HeroAnimationController.PlayIdle -= RemoveAnimation;

if (Ref.HC != null) {
Fsm fsm = GameObjectUtil.FindGameObjectByRef(Ref.DDOL, healthRef).LocateMyFSM("Low Health FX").Fsm;

if (fsm.ActiveStateName == "Idle") {
fsm.SetState("Low Health?");
}
}
}

private void ModifyFSM(On.PlayMakerFSM.orig_Start orig, PlayMakerFSM self) {
orig(self);

if (self is {
name: "Health",
FsmName: "Low Health FX"
}) {
if (self.FsmName == "Low Health FX" && healthRef.MatchGameObject(self.gameObject)) {
ModifyLowHealthFXFSM(self);
} else if (self is {
name: "Damage Effect",
FsmName: "Knight Damage"
}) {
} else if (self.FsmName == "Knight Damage" && damageEffectsRef.MatchGameObject(self.gameObject)) {
ModifyDamageEffectFSM(self);
}
}

private static void ModifyLowHealthFXFSM(PlayMakerFSM fsm) {
fsm.ChangeTransition("Init", "LOW", "Idle");
fsm.ChangeTransition("HUD In HP Check", "LOW", "Idle");
fsm.RemoveTransition("Idle", "HERO DAMAGED");
private void ModifyLowHealthFXFSM(PlayMakerFSM fsm) {
bool shouldActivate() => Loaded;

fsm.Intercept(new TransitionInterceptor() {
fromState = "Init",
eventName = "LOW",
toStateDefault = "Low Health On Entry",
toStateCustom = "Idle",
shouldIntercept = shouldActivate
});

fsm.Intercept(new TransitionInterceptor() {
fromState = "HUD In HP Check",
eventName = "LOW",
toStateDefault = "Low Health On Entry",
toStateCustom = "Idle",
shouldIntercept = shouldActivate
});

fsm.Intercept(new TransitionInterceptor() {
fromState = "Idle",
eventName = "HERO DAMAGED",
toStateDefault = "Low Health Pause",
toStateCustom = "Idle",
shouldIntercept = shouldActivate
});
}

private static void ModifyDamageEffectFSM(PlayMakerFSM fsm) =>
fsm.ChangeTransition("Check Focus Prompt", FsmEvent.Finished.Name, "Leak");
private void ModifyDamageEffectFSM(PlayMakerFSM fsm) => fsm.Intercept(new TransitionInterceptor() {
fromState = "Check Focus Prompt",
eventName = FsmEvent.Finished.Name,
toStateDefault = "Last HP?",
toStateCustom = "Leak",
shouldIntercept = () => Loaded
});

private static void RemoveAnimation(ILContext il) {
int index = new ILCursor(il).Goto(0).GotoNext(
Expand Down

0 comments on commit 229fb4b

Please sign in to comment.