Skip to content

Commit 39b8aac

Browse files
authored
"Targetable Gold Skulltula" Cheat (#5986)
1 parent ba0ecc5 commit 39b8aac

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
2+
#include "soh/ShipInit.hpp"
3+
#include <spdlog/spdlog.h>
4+
#include <vector>
5+
6+
extern "C" {
7+
#include "functions.h"
8+
#include "macros.h"
9+
#include "src/overlays/actors/ovl_En_Sw/z_en_sw.h"
10+
11+
extern PlayState* gPlayState;
12+
}
13+
14+
static constexpr int32_t CVAR_GSTARGETABLE_DEFAULT = 0;
15+
#define CVAR_GSTARGETABLE_NAME CVAR_CHEAT("GSTargetable")
16+
#define CVAR_GSTARGETABLE_VALUE CVarGetInteger(CVAR_GSTARGETABLE_NAME, CVAR_GSTARGETABLE_DEFAULT)
17+
18+
static void OnActorInitGSTargetable(void* refActor) {
19+
EnSw* enSw = reinterpret_cast<EnSw*>(refActor);
20+
21+
if (enSw->actor.naviEnemyId == 0x20) {
22+
// Enable Targeting this Gold Skulltula, if visible by default
23+
if (enSw->actor.scale.x >= 0.0139999995f) {
24+
enSw->actor.flags |= ACTOR_FLAG_ATTENTION_ENABLED;
25+
}
26+
27+
// By default Gold Skulltulas are categorized as NPCs (blue cursor) which feels wrong.
28+
// Change the category to Misc (green cursor) instead.
29+
// It might be possible to change the category to Enemy but doing so will likely affect Clear Rooms.
30+
Actor_ChangeCategory(gPlayState, &gPlayState->actorCtx, &enSw->actor, ACTORCAT_MISC);
31+
}
32+
}
33+
34+
static void OnEnemyDefeatGSTargetable(void* refActor) {
35+
EnSw* enSw = reinterpret_cast<EnSw*>(refActor);
36+
37+
if (enSw->actor.naviEnemyId == 0x20) {
38+
// Disable Targeting immediately when the Gold Skulltula is defeated (like regular Skullwalltulas)
39+
enSw->actor.flags &= ~ACTOR_FLAG_ATTENTION_ENABLED;
40+
}
41+
}
42+
43+
static void OnActorUpdateGSTargetable(void* refActor) {
44+
EnSw* enSw = reinterpret_cast<EnSw*>(refActor);
45+
46+
// Handle Night GS Spawning/Despawning
47+
if ((enSw->actor.naviEnemyId == 0x20) && (((enSw->actor.params & 0xE000) >> 0xD) == 2) &&
48+
(enSw->actor.colChkInfo.health > 0)) {
49+
if (enSw->actor.scale.x < 0.0139999995f) {
50+
// Night GS Despawn
51+
enSw->actor.flags &= ~ACTOR_FLAG_ATTENTION_ENABLED;
52+
}
53+
if (enSw->actor.scale.x >= 0.0139999995f) {
54+
// Night GS Spawn
55+
enSw->actor.flags |= ACTOR_FLAG_ATTENTION_ENABLED;
56+
}
57+
}
58+
}
59+
60+
static void UpdateGSTargetable() {
61+
if (gPlayState != nullptr) {
62+
if (CVAR_GSTARGETABLE_VALUE) {
63+
SPDLOG_DEBUG("GSTargetable has been toggled on");
64+
65+
// Find all Gold Skulltulas that are in NPC category
66+
std::vector<Actor*> goldSkulltulasInNPCCategory;
67+
68+
Actor* actorNPC = gPlayState->actorCtx.actorLists[ACTORCAT_NPC].head;
69+
while (actorNPC != nullptr) {
70+
if ((actorNPC->id == ACTOR_EN_SW) && (actorNPC->naviEnemyId == 0x20)) {
71+
goldSkulltulasInNPCCategory.push_back(actorNPC);
72+
}
73+
actorNPC = actorNPC->next;
74+
}
75+
76+
// Move all NPC Gold Skulltulas to Misc category
77+
for (auto& actor : goldSkulltulasInNPCCategory) {
78+
Actor_ChangeCategory(gPlayState, &gPlayState->actorCtx, actor, ACTORCAT_MISC);
79+
}
80+
81+
// Make all Gold Skulltulas in Misc category targetable, if visible
82+
Actor* actorMisc = gPlayState->actorCtx.actorLists[ACTORCAT_MISC].head;
83+
while (actorMisc != nullptr) {
84+
if ((actorMisc->id == ACTOR_EN_SW) && (actorMisc->naviEnemyId == 0x20) &&
85+
(actorMisc->scale.x >= 0.0139999995f)) {
86+
actorMisc->flags |= ACTOR_FLAG_ATTENTION_ENABLED;
87+
}
88+
actorMisc = actorMisc->next;
89+
}
90+
} else {
91+
SPDLOG_DEBUG("GSTargetable has been toggled off");
92+
93+
// Make all Gold Skulltulas in NPC category not targetable
94+
Actor* actorNPC = gPlayState->actorCtx.actorLists[ACTORCAT_NPC].head;
95+
while (actorNPC != nullptr) {
96+
if ((actorNPC->id == ACTOR_EN_SW) && (actorNPC->naviEnemyId == 0x20)) {
97+
actorNPC->flags &= ~ACTOR_FLAG_ATTENTION_ENABLED;
98+
}
99+
actorNPC = actorNPC->next;
100+
}
101+
102+
// Make all Gold Skulltulas in Misc category not targetable
103+
Actor* actorMisc = gPlayState->actorCtx.actorLists[ACTORCAT_MISC].head;
104+
while (actorMisc != nullptr) {
105+
if ((actorMisc->id == ACTOR_EN_SW) && (actorMisc->naviEnemyId == 0x20)) {
106+
actorMisc->flags &= ~ACTOR_FLAG_ATTENTION_ENABLED;
107+
}
108+
actorMisc = actorMisc->next;
109+
}
110+
}
111+
}
112+
}
113+
114+
static void RegisterGSTargetable() {
115+
UpdateGSTargetable();
116+
117+
COND_ID_HOOK(OnActorInit, ACTOR_EN_SW, CVAR_GSTARGETABLE_VALUE, OnActorInitGSTargetable);
118+
COND_ID_HOOK(OnEnemyDefeat, ACTOR_EN_SW, CVAR_GSTARGETABLE_VALUE, OnEnemyDefeatGSTargetable);
119+
COND_ID_HOOK(OnActorUpdate, ACTOR_EN_SW, CVAR_GSTARGETABLE_VALUE, OnActorUpdateGSTargetable);
120+
}
121+
122+
static RegisterShipInitFunc initFunc(RegisterGSTargetable, { CVAR_GSTARGETABLE_NAME });

soh/soh/SohGui/SohMenuEnhancements.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,6 +1752,9 @@ void SohMenu::AddMenuEnhancements() {
17521752
AddWidget(path, "Disable Haunted Wasteland Sandstorm", WIDGET_CVAR_CHECKBOX)
17531753
.CVar(CVAR_CHEAT("DisableSandstorm"))
17541754
.Options(CheckboxOptions().Tooltip("Disables sandstorm effect in Haunted Wasteland."));
1755+
AddWidget(path, "Targetable Gold Skulltula", WIDGET_CVAR_CHECKBOX)
1756+
.CVar(CVAR_CHEAT("GSTargetable"))
1757+
.Options(CheckboxOptions().Tooltip("Allows Z-Targeting Gold Skulltulas."));
17551758

17561759
AddWidget(path, "Glitch Aids", WIDGET_SEPARATOR_TEXT);
17571760
AddWidget(path, "Easy Frame Advancing with Pause", WIDGET_CVAR_CHECKBOX)

0 commit comments

Comments
 (0)