Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invisible Enemies #4209

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions soh/soh/Enhancements/game-interactor/GameInteractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class GameInteractor {
DEFINE_HOOK(OnFlagSet, void(int16_t flagType, int16_t flag));
DEFINE_HOOK(OnFlagUnset, void(int16_t flagType, int16_t flag));
DEFINE_HOOK(OnSceneSpawnActors, void());
DEFINE_HOOK(OnRoomInit, void(int16_t sceneNum, int8_t roomNum));
DEFINE_HOOK(OnPlayerUpdate, void());
DEFINE_HOOK(OnOcarinaSongAction, void());
DEFINE_HOOK(OnShopSlotChange, void(uint8_t cursorIndex, int16_t price));
Expand Down
4 changes: 4 additions & 0 deletions soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ void GameInteractor_ExecuteOnSceneSpawnActors() {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnSceneSpawnActors>();
}

void GameInteractor_ExecuteOnRoomInit(int16_t sceneId, int8_t roomNum) {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnRoomInit>(sceneId, roomNum);
}

void GameInteractor_ExecuteOnPlayerUpdate() {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnPlayerUpdate>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void GameInteractor_ExecuteOnSceneFlagUnset(int16_t sceneNum, int16_t flagType,
void GameInteractor_ExecuteOnFlagSet(int16_t flagType, int16_t flag);
void GameInteractor_ExecuteOnFlagUnset(int16_t flagType, int16_t flag);
void GameInteractor_ExecuteOnSceneSpawnActors();
void GameInteractor_ExecuteOnRoomInit(int16_t sceneId, int8_t roomNum);
void GameInteractor_ExecuteOnPlayerUpdate();
void GameInteractor_ExecuteOnOcarinaSongAction();
void GameInteractor_ExecuteOnActorInit(void* actor);
Expand Down
30 changes: 30 additions & 0 deletions soh/soh/Enhancements/modes/InvisibleEnemies.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "soh/OTRGlobals.h"
#include "InvisibleEnemies.h"
#include "libultraship/libultraship.h"
#include "soh/Enhancements/game-interactor/GameInteractor.h"

extern "C" {
#include "macros.h"
#include "z64.h"
extern PlayState* gPlayState;
}

void RegisterInvisibleEnemies() {
static uint32_t enemyLensReactHookId = 0;
static uint32_t roomLensModeHookId = 0;
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnActorInit>(enemyLensReactHookId);
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnRoomInit>(roomLensModeHookId);

if (CVarGetInteger(CVAR_ENHANCEMENT("InvisibleEnemies"), 0)) {
enemyLensReactHookId =
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnActorInit>([](void* actorx) {
Actor* actor = (Actor*)actorx;
if (actor->category == ACTORCAT_ENEMY) {
actor->flags |= ACTOR_FLAG_LENS;
}
});

roomLensModeHookId = GameInteractor::Instance->RegisterGameHook<GameInteractor::OnRoomInit>(
[](int16_t sceneId, int8_t roomNum) { gPlayState->roomCtx.curRoom.lensMode = LENS_MODE_HIDE_ACTORS; });
}
}
6 changes: 6 additions & 0 deletions soh/soh/Enhancements/modes/InvisibleEnemies.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef INVISIBLE_ENEMIES_H
#define INVISIBLE_ENEMIES_H

void RegisterInvisibleEnemies();

#endif // INVISIBLE_ENEMIES_H
1 change: 1 addition & 0 deletions soh/soh/Enhancements/mods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1433,4 +1433,5 @@ void InitMods() {
RegisterPatchHandHandler();
RegisterHurtContainerModeHandler();
RegisterPauseMenuHooks();
RegisterInvisibleEnemies();
}
1 change: 1 addition & 0 deletions soh/soh/Enhancements/mods.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdint.h>
#include "modes/InvisibleEnemies.h"

#ifndef MODS_H
#define MODS_H
Expand Down
4 changes: 4 additions & 0 deletions soh/soh/SohMenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,10 @@ void DrawEnhancementsMenu() {
"- Each Heart Container or full Heart Piece reduces Links hearts by 1.\n"
"- Can be enabled retroactively after a File has already started.");

if (UIWidgets::PaddedEnhancementCheckbox("Invisible Enemies", CVAR_ENHANCEMENT("InvisibleEnemies"), true, false)) {
RegisterInvisibleEnemies();
}
UIWidgets::Tooltip("Enemies will appear invisible without using the Lens of Truth. Requires scene reload to take effect.");
ImGui::EndMenu();
}

Expand Down
3 changes: 3 additions & 0 deletions soh/soh/z_scene_otr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "soh/resource/type/scenecommand/SetSoundSettings.h"
#include "soh/resource/type/scenecommand/SetEchoSettings.h"
#include "soh/resource/type/scenecommand/SetAlternateHeaders.h"
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"

extern Ship::IResource* OTRPlay_LoadFile(PlayState* play, const char* fileName);
extern "C" s32 Object_Spawn(ObjectContext* objectCtx, s16 objectId);
Expand Down Expand Up @@ -520,6 +521,8 @@ extern "C" s32 OTRfunc_8009728C(PlayState* play, RoomContext* roomCtx, s32 roomN

SPDLOG_INFO("Room Init - curRoom.num: {0:#x}", roomCtx->curRoom.num);

GameInteractor_ExecuteOnRoomInit(play->sceneNum, roomCtx->curRoom.num);

return 1;
}

Expand Down
Loading