Skip to content

Commit

Permalink
Add HyperEnemies mode
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjoecox committed Dec 4, 2024
1 parent 11340f1 commit 15196cc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mm/2s2h/BenGui/SearchableMenuItems.h
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,8 @@ void AddEnhancements() {
WIDGET_CVAR_CHECKBOX },
{ "Time Moves when you Move", "gModes.TimeMovesWhenYouMove",
"Time only moves when Link is not standing still.", WIDGET_CVAR_CHECKBOX },
{ "Hyper Enemies", "gModes.HyperEnemies",
"Double the rate at which enemies are updated, making them more difficult", WIDGET_CVAR_CHECKBOX },
{ "Mirrored World",
"gModes.MirroredWorld.Mode",
"Mirrors the world horizontally.",
Expand Down
34 changes: 34 additions & 0 deletions mm/2s2h/Enhancements/Modes/HyperEnemies.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <libultraship/bridge.h>
#include "2s2h/GameInteractor/GameInteractor.h"
#include "2s2h/ShipInit.hpp"

extern "C" {
#include "variables.h"
#include "functions.h"
}

#define CVAR_NAME "gModes.HyperEnemies"
#define CVAR CVarGetInteger(CVAR_NAME, 0)

void RegisterHyperEnemies() {
COND_HOOK(OnActorUpdate, CVAR, [](Actor* actor) {
if (actor->category != ACTORCAT_ENEMY) {
return;
}

if (Player_InBlockingCsMode(gPlayState, GET_PLAYER(gPlayState))) {
return;
}

if (actor->update != NULL) {
// Everywhere we need to disable the collision checks already checks if frameAdvance is enabled, so we abuse
// that temporarily. This doesn't have any _known_ side effects :)
bool prevFrameAdv = gPlayState->frameAdvCtx.enabled;
gPlayState->frameAdvCtx.enabled = true;
actor->update(actor, gPlayState);
gPlayState->frameAdvCtx.enabled = prevFrameAdv;
}
});
}

static RegisterShipInitFunc initFunc(RegisterHyperEnemies, { CVAR_NAME });

0 comments on commit 15196cc

Please sign in to comment.