mirror of
https://github.com/izzy2lost/2ship2harkinian-Android.git
synced 2026-06-19 01:20:08 -07:00
fd anywhere using hooks (plus splitting enhancements out into files) (#226)
* fd anywhere using hooks (plus splitting enhancements out into files) Co-authored-by: aMannus <mannusmenting@gmail.com> Co-authored-by: Archez <Archez@users.noreply.github.com> * add guards to headers * Update mm/src/code/z_parameter.c Co-authored-by: Garrett Cox <garrettjcox@gmail.com> * clean * macro magic * Apply suggestions from code review --------- Co-authored-by: aMannus <mannusmenting@gmail.com> Co-authored-by: Archez <Archez@users.noreply.github.com> Co-authored-by: Garrett Cox <garrettjcox@gmail.com>
This commit is contained in:
committed by
Garrett Cox
co-authored by
aMannus
Archez
Garrett Cox
parent
dfe0e1d6c2
commit
90cb488263
@@ -288,7 +288,15 @@ extern std::shared_ptr<HudEditorWindow> mHudEditorWindow;
|
||||
|
||||
void DrawEnhancementsMenu() {
|
||||
if (UIWidgets::BeginMenu("Enhancements")) {
|
||||
|
||||
if (UIWidgets::BeginMenu("Masks")) {
|
||||
UIWidgets::CVarCheckbox("Fierce Deity's Mask Anywhere", "gEnhancements.Masks.FierceDeitysAnywhere", {
|
||||
.tooltip = "Allow using Fierce Deity's mask outside of boss rooms."
|
||||
});
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
UIWidgets::CVarCheckbox("Fast Text", "gEnhancements.TimeSavers.FastText", {
|
||||
.tooltip = "Speeds up text rendering, and enables holding of B progress to next message"
|
||||
});
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "Infinite.h"
|
||||
#include <libultraship/bridge.h>
|
||||
#include "Enhancements/GameInteractor/GameInteractor.h"
|
||||
#include "variables.h"
|
||||
|
||||
void RegisterInfiniteCheats() {
|
||||
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameStateUpdate>([]() {
|
||||
if (gPlayState == nullptr) return;
|
||||
|
||||
if (CVarGetInteger("gCheats.InfiniteHealth", 0)) {
|
||||
gSaveContext.save.saveInfo.playerData.health = gSaveContext.save.saveInfo.playerData.healthCapacity;
|
||||
}
|
||||
|
||||
if (CVarGetInteger("gCheats.InfiniteMagic", 0)) {
|
||||
uint8_t magicLevel = gSaveContext.save.saveInfo.playerData.magicLevel;
|
||||
if (magicLevel == 1) {
|
||||
gSaveContext.save.saveInfo.playerData.magic = MAGIC_NORMAL_METER;
|
||||
} else if (magicLevel == 2) {
|
||||
gSaveContext.save.saveInfo.playerData.magic = MAGIC_DOUBLE_METER;
|
||||
}
|
||||
}
|
||||
|
||||
if (CVarGetInteger("gCheats.InfiniteRupees", 0)) {
|
||||
gSaveContext.save.saveInfo.playerData.rupees = CUR_CAPACITY(UPG_WALLET);
|
||||
}
|
||||
|
||||
if (CVarGetInteger("gCheats.InfiniteConsumables", 0)) {
|
||||
AMMO(ITEM_BOW) = CUR_CAPACITY(UPG_QUIVER);
|
||||
AMMO(ITEM_BOMB) = CUR_CAPACITY(UPG_BOMB_BAG);
|
||||
AMMO(ITEM_BOMBCHU) = CUR_CAPACITY(UPG_BOMB_BAG);
|
||||
AMMO(ITEM_DEKU_STICK) = CUR_CAPACITY(UPG_DEKU_STICKS);
|
||||
AMMO(ITEM_DEKU_NUT) = CUR_CAPACITY(UPG_DEKU_NUTS);
|
||||
AMMO(ITEM_MAGIC_BEANS) = 20;
|
||||
AMMO(ITEM_POWDER_KEG) = 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#ifndef CHEATS_INFINITE_H
|
||||
#define CHEATS_INFINITE_H
|
||||
|
||||
void RegisterInfiniteCheats();
|
||||
|
||||
#endif // CHEATS_INFINITE_H
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "MoonJump.h"
|
||||
#include <libultraship/bridge.h>
|
||||
#include "Enhancements/GameInteractor/GameInteractor.h"
|
||||
#include "variables.h"
|
||||
|
||||
static uint32_t moonJumpOnLGameStateUpdateHookId = 0;
|
||||
void RegisterMoonJumpOnL() {
|
||||
if (moonJumpOnLGameStateUpdateHookId) {
|
||||
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnGameStateUpdate>(moonJumpOnLGameStateUpdateHookId);
|
||||
moonJumpOnLGameStateUpdateHookId = 0;
|
||||
}
|
||||
|
||||
if (CVarGetInteger("gCheats.MoonJumpOnL", 0)) {
|
||||
moonJumpOnLGameStateUpdateHookId = GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameStateUpdate>([]() {
|
||||
if (gPlayState == nullptr) return;
|
||||
|
||||
Player* player = GET_PLAYER(gPlayState);
|
||||
|
||||
if (CHECK_BTN_ANY(gPlayState->state.input[0].cur.button, BTN_L)) {
|
||||
player->actor.velocity.y = 6.34375f;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#ifndef CHEATS_MOONJUMP_H
|
||||
#define CHEATS_MOONJUMP_H
|
||||
|
||||
void RegisterMoonJumpOnL();
|
||||
|
||||
#endif // CHEATS_MOONJUMP_H
|
||||
@@ -1,83 +1,13 @@
|
||||
#include "Enhancements.h"
|
||||
#include <libultraship/bridge.h>
|
||||
#include "GameInteractor/GameInteractor.h"
|
||||
|
||||
extern "C" {
|
||||
#include <z64.h>
|
||||
#include "macros.h"
|
||||
// #include "functions.h"
|
||||
#include "variables.h"
|
||||
extern PlayState* gPlayState;
|
||||
}
|
||||
|
||||
static uint32_t moonJumpOnLGameStateUpdateHookId = 0;
|
||||
void RegisterMoonJumpOnL() {
|
||||
if (moonJumpOnLGameStateUpdateHookId) {
|
||||
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnGameStateUpdate>(moonJumpOnLGameStateUpdateHookId);
|
||||
moonJumpOnLGameStateUpdateHookId = 0;
|
||||
}
|
||||
|
||||
if (CVarGetInteger("gCheats.MoonJumpOnL", 0)) {
|
||||
moonJumpOnLGameStateUpdateHookId = GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameStateUpdate>([]() {
|
||||
if (!gPlayState) return;
|
||||
|
||||
Player* player = GET_PLAYER(gPlayState);
|
||||
|
||||
if (CHECK_BTN_ANY(gPlayState->state.input[0].cur.button, BTN_L)) {
|
||||
player->actor.velocity.y = 6.34375f;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void RegisterTimeSaversHooks() {
|
||||
GameInteractor::Instance->RegisterGameHookForID<GameInteractor::ShouldVanillaBehavior>(GI_VB_PLAY_ENTRANCE_CS, [](GIVanillaBehavior _, bool* should, void* __) {
|
||||
if (CVarGetInteger("gEnhancements.TimeSavers.SkipEntranceCutscenes", 0)) {
|
||||
*should = false;
|
||||
}
|
||||
});
|
||||
GameInteractor::Instance->RegisterGameHookForID<GameInteractor::ShouldVanillaBehavior>(GI_VB_SHOW_TITLE_CARD, [](GIVanillaBehavior _, bool* should, void* __) {
|
||||
if (CVarGetInteger("gEnhancements.TimeSavers.HideTitleCards", 0)) {
|
||||
*should = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void RegisterInfiniteCheats() {
|
||||
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameStateUpdate>([]() {
|
||||
if (!gPlayState) return;
|
||||
|
||||
if (CVarGetInteger("gCheats.InfiniteHealth", 0)) {
|
||||
gSaveContext.save.saveInfo.playerData.health = gSaveContext.save.saveInfo.playerData.healthCapacity;
|
||||
}
|
||||
|
||||
if (CVarGetInteger("gCheats.InfiniteMagic", 0)) {
|
||||
uint8_t magicLevel = gSaveContext.save.saveInfo.playerData.magicLevel;
|
||||
if (magicLevel == 1) {
|
||||
gSaveContext.save.saveInfo.playerData.magic = MAGIC_NORMAL_METER;
|
||||
} else if (magicLevel == 2) {
|
||||
gSaveContext.save.saveInfo.playerData.magic = MAGIC_DOUBLE_METER;
|
||||
}
|
||||
}
|
||||
|
||||
if (CVarGetInteger("gCheats.InfiniteRupees", 0)) {
|
||||
gSaveContext.save.saveInfo.playerData.rupees = CUR_CAPACITY(UPG_WALLET);
|
||||
}
|
||||
|
||||
if (CVarGetInteger("gCheats.InfiniteConsumables", 0)) {
|
||||
AMMO(ITEM_BOW) = CUR_CAPACITY(UPG_QUIVER);
|
||||
AMMO(ITEM_BOMB) = CUR_CAPACITY(UPG_BOMB_BAG);
|
||||
AMMO(ITEM_BOMBCHU) = CUR_CAPACITY(UPG_BOMB_BAG);
|
||||
AMMO(ITEM_DEKU_STICK) = CUR_CAPACITY(UPG_DEKU_STICKS);
|
||||
AMMO(ITEM_DEKU_NUT) = CUR_CAPACITY(UPG_DEKU_NUTS);
|
||||
AMMO(ITEM_MAGIC_BEANS) = 20;
|
||||
AMMO(ITEM_POWDER_KEG) = 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void InitEnhancements() {
|
||||
RegisterMoonJumpOnL();
|
||||
// Cheats
|
||||
RegisterInfiniteCheats();
|
||||
RegisterMoonJumpOnL();
|
||||
|
||||
// Masks
|
||||
RegisterFierceDeityAnywhere();
|
||||
|
||||
// Time Savers
|
||||
RegisterTimeSaversHooks();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
#ifndef ENHANCEMENTS_H
|
||||
#define ENHANCEMENTS_H
|
||||
|
||||
#include "Cheats/MoonJump.h"
|
||||
#include "Cheats/Infinite.h"
|
||||
#include "Masks/FierceDeityAnywhere.h"
|
||||
#include "TimeSavers/TimeSavers.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void InitEnhancements();
|
||||
void RegisterMoonJumpOnL();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // ENHANCEMENTS_H
|
||||
|
||||
@@ -13,6 +13,7 @@ typedef enum {
|
||||
// Vanilla condition: gSaveContext.showTitleCard
|
||||
GI_VB_SHOW_TITLE_CARD,
|
||||
GI_VB_PLAY_ENTRANCE_CS,
|
||||
GI_VB_DISABLE_FD_MASK
|
||||
} GIVanillaBehavior;
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -216,6 +217,8 @@ bool GameInteractor_ShouldActorDraw(Actor* actor);
|
||||
void GameInteractor_ExecuteOnActorDraw(Actor* actor);
|
||||
|
||||
bool GameInteractor_Should(GIVanillaBehavior flag, bool result, void* optionalArg);
|
||||
#define REGISTER_VB_SHOULD(flag, body) \
|
||||
GameInteractor::Instance->RegisterGameHookForID<GameInteractor::ShouldVanillaBehavior>(flag, [](GIVanillaBehavior _, bool* should, void* opt) body)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#include <libultraship/bridge.h>
|
||||
#include "Enhancements/GameInteractor/GameInteractor.h"
|
||||
|
||||
void RegisterFierceDeityAnywhere() {
|
||||
REGISTER_VB_SHOULD(GI_VB_DISABLE_FD_MASK, {
|
||||
if (CVarGetInteger("gEnhancements.Masks.FierceDeitysAnywhere", 0)) {
|
||||
*should = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#ifndef MASKS_FD_ANYWHERE_H
|
||||
#define MASKS_FD_ANYWHERE_H
|
||||
|
||||
void RegisterFierceDeityAnywhere();
|
||||
|
||||
#endif // MASKS_FD_ANYWHERE_H
|
||||
@@ -0,0 +1,15 @@
|
||||
#include <libultraship/bridge.h>
|
||||
#include "Enhancements/GameInteractor/GameInteractor.h"
|
||||
|
||||
void RegisterTimeSaversHooks() {
|
||||
REGISTER_VB_SHOULD(GI_VB_PLAY_ENTRANCE_CS, {
|
||||
if (CVarGetInteger("gEnhancements.TimeSavers.SkipEntranceCutscenes", 0)) {
|
||||
*should = false;
|
||||
}
|
||||
});
|
||||
REGISTER_VB_SHOULD(GI_VB_SHOW_TITLE_CARD, {
|
||||
if (CVarGetInteger("gEnhancements.TimeSavers.HideTitleCards", 0)) {
|
||||
*should = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#ifndef TIMESAVERS_H
|
||||
#define TIMESAVERS_H
|
||||
|
||||
void RegisterTimeSaversHooks();
|
||||
|
||||
#endif // TIMESAVERS_H
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "BenPort.h"
|
||||
#include <string.h>
|
||||
#include "BenGui/HudEditor.h"
|
||||
#include "Enhancements/GameInteractor/GameInteractor.h"
|
||||
|
||||
// #region 2S2H [Port] Asset tables we can pull from instead of from ROM
|
||||
#define dgEmptyTexture "__OTR__textures/virtual/gEmptyTexture"
|
||||
@@ -2191,9 +2192,13 @@ void Interface_UpdateButtonsPart2(PlayState* play) {
|
||||
}
|
||||
} else if (GET_CUR_FORM_BTN_ITEM(i) == ITEM_MASK_FIERCE_DEITY) {
|
||||
// Fierce Deity's Mask is equipped
|
||||
if ((play->sceneId != SCENE_MITURIN_BS) && (play->sceneId != SCENE_HAKUGIN_BS) &&
|
||||
(play->sceneId != SCENE_SEA_BS) && (play->sceneId != SCENE_INISIE_BS) &&
|
||||
(play->sceneId != SCENE_LAST_BS)) {
|
||||
u8 vanillaSceneConditionResult =
|
||||
(play->sceneId != SCENE_MITURIN_BS) &&
|
||||
(play->sceneId != SCENE_HAKUGIN_BS) &&
|
||||
(play->sceneId != SCENE_SEA_BS) &&
|
||||
(play->sceneId != SCENE_INISIE_BS) &&
|
||||
(play->sceneId != SCENE_LAST_BS);
|
||||
if (GameInteractor_Should(GI_VB_DISABLE_FD_MASK, vanillaSceneConditionResult, NULL)) {
|
||||
if (gSaveContext.buttonStatus[i] != BTN_DISABLED) {
|
||||
gSaveContext.buttonStatus[i] = BTN_DISABLED;
|
||||
restoreHudVisibility = true;
|
||||
|
||||
Reference in New Issue
Block a user