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

Move some cheats to Shipinit #4819

Open
wants to merge 13 commits 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
27 changes: 27 additions & 0 deletions soh/soh/Enhancements/Cheats/DekuStick.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <libultraship/bridge.h>
#include "soh/Enhancements/enhancementTypes.h"
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
#include "soh/ShipInit.hpp"

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

#define CVAR_DEKU_STICK_NAME CVAR_CHEAT("DekuStick")
#define CVAR_DEKU_STICK_DEFAULT DEKU_STICK_NORMAL
#define CVAR_DEKU_STICK_VALUE CVarGetInteger(CVAR_DEKU_STICK_NAME, CVAR_DEKU_STICK_DEFAULT)

void RegisterDekuStickCheats() {
COND_VB_SHOULD(VB_DEKU_STICK_BREAK, CVAR_DEKU_STICK_VALUE != DEKU_STICK_NORMAL, { *should = false; });
COND_VB_SHOULD(VB_DEKU_STICK_BURN_OUT, CVAR_DEKU_STICK_VALUE != DEKU_STICK_NORMAL, { *should = false; });
COND_VB_SHOULD(VB_DEKU_STICK_BURN_DOWN, CVAR_DEKU_STICK_VALUE != DEKU_STICK_NORMAL, { *should = false; });
COND_VB_SHOULD(VB_DEKU_STICK_BE_ON_FIRE, CVAR_DEKU_STICK_VALUE == DEKU_STICK_UNBREAKABLE_AND_ALWAYS_ON_FIRE, {
Player* player = GET_PLAYER(gPlayState);
player->unk_860 = 200; // Keeps the stick's flame lit
player->unk_85C = 1.0f; // Ensures the stick is the proper length
*should = true;
});
}

static RegisterShipInitFunc initFunc(RegisterDekuStickCheats, { CVAR_DEKU_STICK_NAME });
27 changes: 27 additions & 0 deletions soh/soh/Enhancements/Cheats/EasyISG.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <libultraship/bridge.h>
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
#include "soh/ShipInit.hpp"

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

#define CVAR_EASY_ISG_NAME CVAR_CHEAT("EasyISG")
#define CVAR_EASY_ISG_DEFAULT 0
#define CVAR_EASY_ISG_VALUE CVarGetInteger(CVAR_EASY_ISG_NAME, CVAR_EASY_ISG_DEFAULT)

void OnGameFrameUpdateEasyISG() {
if (!GameInteractor::IsSaveLoaded(true)) {
return;
}

Player* player = GET_PLAYER(gPlayState);
player->meleeWeaponState = 1;
}

void RegisterEasyISG() {
COND_HOOK(OnGameFrameUpdate, CVAR_EASY_ISG_VALUE, OnGameFrameUpdateEasyISG);
}

static RegisterShipInitFunc initFunc(RegisterEasyISG, { CVAR_EASY_ISG_NAME });
28 changes: 28 additions & 0 deletions soh/soh/Enhancements/Cheats/EasyQPA.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <libultraship/bridge.h>
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
#include "soh/ShipInit.hpp"

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

#define CVAR_EASY_QPA_NAME CVAR_CHEAT("EasyQPA")
#define CVAR_EASY_QPA_DEFAULT 0
#define CVAR_EASY_QPA_VALUE CVarGetInteger(CVAR_EASY_QPA_NAME, CVAR_EASY_QPA_DEFAULT)

void OnGameFrameUpdateEasyQPA() {
if (!GameInteractor::IsSaveLoaded(true)) {
return;
}

Player* player = GET_PLAYER(gPlayState);
player->meleeWeaponQuads[0].info.toucher.dmgFlags = 0x16171617;
player->meleeWeaponQuads[1].info.toucher.dmgFlags = 0x16171617;
}

void RegisterEasyQPA() {
COND_HOOK(OnGameFrameUpdate, CVAR_EASY_QPA_VALUE, OnGameFrameUpdateEasyQPA);
}

static RegisterShipInitFunc initFunc(RegisterEasyQPA, { CVAR_EASY_QPA_NAME });
39 changes: 39 additions & 0 deletions soh/soh/Enhancements/Cheats/FreezeTime.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <libultraship/bridge.h>
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
#include "soh/ShipInit.hpp"
#include "z64save.h"

extern "C" SaveContext gSaveContext;

#define CVAR_FREEZE_TIME_NAME CVAR_CHEAT("FreezeTime")
#define CVAR_FREEZE_TIME_DEFAULT 0
#define CVAR_FREEZE_TIME_VALUE CVarGetInteger(CVAR_FREEZE_TIME_NAME, CVAR_FREEZE_TIME_DEFAULT)

#define CVAR_PREV_TIME_NAME CVAR_GENERAL("PrevTime")
#define CVAR_PREV_TIME_DEFAULT -1
#define CVAR_PREV_TIME_VALUE CVarGetInteger(CVAR_PREV_TIME_NAME, CVAR_PREV_TIME_DEFAULT)

void OnGameFrameUpdateFreezeTime() {
if (!GameInteractor::IsSaveLoaded(true)) {
return;
}

if (CVAR_PREV_TIME_VALUE == CVAR_PREV_TIME_DEFAULT) {
CVarSetInteger(CVAR_PREV_TIME_NAME, gSaveContext.dayTime);
}

gSaveContext.dayTime = CVAR_PREV_TIME_VALUE;
}

void RegisterFreezeTime() {
static HOOK_ID hookId = 0;
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnGameFrameUpdate>(hookId);
hookId = 0;
if (CVAR_FREEZE_TIME_VALUE) {
hookId = GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameFrameUpdate>(OnGameFrameUpdateFreezeTime);
} else {
CVarClear(CVAR_PREV_TIME_NAME);
}
}

static RegisterShipInitFunc initFunc(RegisterFreezeTime, { CVAR_FREEZE_TIME_NAME });
35 changes: 35 additions & 0 deletions soh/soh/Enhancements/Cheats/Infinite/Ammo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <libultraship/bridge.h>
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
#include "soh/ShipInit.hpp"
#include "z64save.h"

extern "C" {
extern SaveContext gSaveContext;
#include "variables.h"
#include "macros.h"
}

#define CVAR_INFINITE_AMMO_NAME CVAR_CHEAT("InfiniteAmmo")
#define CVAR_INFINITE_AMMO_DEFAULT 0
#define CVAR_INFINITE_AMMO_VALUE CVarGetInteger(CVAR_INFINITE_AMMO_NAME, CVAR_INFINITE_AMMO_DEFAULT)

void OnGameFrameUpdateInfiniteAmmo() {
if (!GameInteractor::IsSaveLoaded(true)) {
return;
}

AMMO(ITEM_STICK) = CUR_CAPACITY(UPG_STICKS);
AMMO(ITEM_NUT) = CUR_CAPACITY(UPG_NUTS);
AMMO(ITEM_BOMB) = CUR_CAPACITY(UPG_BOMB_BAG);
AMMO(ITEM_BOW) = CUR_CAPACITY(UPG_QUIVER);
AMMO(ITEM_SLINGSHOT) = CUR_CAPACITY(UPG_BULLET_BAG);
if (INV_CONTENT(ITEM_BOMBCHU) != ITEM_NONE) {
AMMO(ITEM_BOMBCHU) = 50;
}
}

void RegisterInfiniteAmmo() {
COND_HOOK(OnGameFrameUpdate, CVAR_INFINITE_AMMO_VALUE, OnGameFrameUpdateInfiniteAmmo);
}

static RegisterShipInitFunc initFunc(RegisterInfiniteAmmo, { CVAR_INFINITE_AMMO_NAME });
24 changes: 24 additions & 0 deletions soh/soh/Enhancements/Cheats/Infinite/Health.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <libultraship/bridge.h>
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
#include "soh/ShipInit.hpp"
#include "z64save.h"

extern "C" SaveContext gSaveContext;

#define CVAR_INFINITE_HEALTH_NAME CVAR_CHEAT("InfiniteHealth")
#define CVAR_INFINITE_HEALTH_DEFAULT 0
#define CVAR_INFINITE_HEALTH_VALUE CVarGetInteger(CVAR_INFINITE_HEALTH_NAME, CVAR_INFINITE_HEALTH_DEFAULT)

void OnGameFrameUpdateInfiniteHealth() {
if (!GameInteractor::IsSaveLoaded(true)) {
return;
}

gSaveContext.health = gSaveContext.healthCapacity;
}

void RegisterInfiniteHealth() {
COND_HOOK(OnGameFrameUpdate, CVAR_INFINITE_HEALTH_VALUE, OnGameFrameUpdateInfiniteHealth);
}

static RegisterShipInitFunc initFunc(RegisterInfiniteHealth, { CVAR_INFINITE_HEALTH_NAME });
24 changes: 24 additions & 0 deletions soh/soh/Enhancements/Cheats/Infinite/Magic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <libultraship/bridge.h>
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
#include "soh/ShipInit.hpp"
#include "z64save.h"

extern "C" SaveContext gSaveContext;

#define CVAR_INFINITE_MAGIC_NAME CVAR_CHEAT("InfiniteMagic")
#define CVAR_INFINITE_MAGIC_DEFAULT 0
#define CVAR_INFINITE_MAGIC_VALUE CVarGetInteger(CVAR_INFINITE_MAGIC_NAME, CVAR_INFINITE_MAGIC_DEFAULT)

void OnGameFrameUpdateInfiniteMagic() {
if (!GameInteractor::IsSaveLoaded(true)) {
return;
}

gSaveContext.magic = gSaveContext.magicLevel * MAGIC_NORMAL_METER;
}

void RegisterInfiniteMagic() {
COND_HOOK(OnGameFrameUpdate, CVAR_INFINITE_MAGIC_VALUE, OnGameFrameUpdateInfiniteMagic);
}

static RegisterShipInitFunc initFunc(RegisterInfiniteMagic, { CVAR_INFINITE_MAGIC_NAME });
32 changes: 32 additions & 0 deletions soh/soh/Enhancements/Cheats/Infinite/Money.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <libultraship/bridge.h>
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
#include "soh/ShipInit.hpp"
#include "z64save.h"
#include "variables.h"

extern "C" {
extern SaveContext gSaveContext;
extern s32 Flags_GetRandomizerInf(RandomizerInf flag);
#include "macros.h"
}

#define CVAR_INFINITE_MONEY_NAME CVAR_CHEAT("InfiniteMoney")
#define CVAR_INFINITE_MONEY_DEFAULT 0
#define CVAR_INFINITE_MONEY_VALUE CVarGetInteger(CVAR_INFINITE_MONEY_NAME, CVAR_INFINITE_MONEY_DEFAULT)

void OnGameFrameUpdateInfiniteMoney() {
if (
!GameInteractor::IsSaveLoaded(true) ||
(IS_RANDO && !Flags_GetRandomizerInf(RAND_INF_HAS_WALLET))
) {
return;
}

gSaveContext.rupees = CUR_CAPACITY(UPG_WALLET);
}

void RegisterInfiniteMoney() {
COND_HOOK(OnGameFrameUpdate, CVAR_INFINITE_MONEY_VALUE, OnGameFrameUpdateInfiniteMoney);
}

static RegisterShipInitFunc initFunc(RegisterInfiniteMoney, { CVAR_INFINITE_MONEY_NAME });
24 changes: 24 additions & 0 deletions soh/soh/Enhancements/Cheats/Infinite/NayrusLove.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <libultraship/bridge.h>
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
#include "soh/ShipInit.hpp"
#include "z64save.h"

extern "C" SaveContext gSaveContext;

#define CVAR_INFINITE_NAYRUS_LOVE_NAME CVAR_CHEAT("InfiniteNayru")
#define CVAR_INFINITE_NAYRUS_LOVE_DEFAULT 0
#define CVAR_INFINITE_NAYRUS_LOVE_VALUE CVarGetInteger(CVAR_INFINITE_NAYRUS_LOVE_NAME, CVAR_INFINITE_NAYRUS_LOVE_DEFAULT)

void OnGameFrameUpdateInfiniteNayrusLove() {
if (!GameInteractor::IsSaveLoaded(true)) {
return;
}

gSaveContext.nayrusLoveTimer = 0x44B;
}

void RegisterInfiniteNayrusLove() {
COND_HOOK(OnGameFrameUpdate, CVAR_INFINITE_NAYRUS_LOVE_VALUE, OnGameFrameUpdateInfiniteNayrusLove);
}

static RegisterShipInitFunc initFunc(RegisterInfiniteNayrusLove, { CVAR_INFINITE_NAYRUS_LOVE_NAME });
4 changes: 2 additions & 2 deletions soh/soh/Enhancements/Cheats/MoonJump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#include "soh/ShipInit.hpp"

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

#define CVAR_MOON_JUMP_NAME "gCheats.MoonJumpOnL"
#define CVAR_MOON_JUMP_NAME CVAR_CHEAT("MoonJumpOnL")
#define CVAR_MOON_JUMP_DEFAULT 0
#define CVAR_MOON_JUMP_VALUE CVarGetInteger(CVAR_MOON_JUMP_NAME, CVAR_MOON_JUMP_DEFAULT)

Expand Down
26 changes: 26 additions & 0 deletions soh/soh/Enhancements/Cheats/UnrestrictedItems.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <libultraship/bridge.h>
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
#include "soh/ShipInit.hpp"

extern "C" PlayState* gPlayState;

#define CVAR_UNRESTRICTED_ITEMS_NAME CVAR_CHEAT("NoRestrictItems")
#define CVAR_UNRESTRICTED_ITEMS_DEFAULT 0
#define CVAR_UNRESTRICTED_ITEMS_VALUE CVarGetInteger(CVAR_UNRESTRICTED_ITEMS_NAME, CVAR_UNRESTRICTED_ITEMS_DEFAULT)

void OnGameFrameUpdateUnrestrictedItems() {
if (!GameInteractor::IsSaveLoaded(true)) {
return;
}

// do not allow the use of sun's song even with the cheat
u8 sunsBackup = gPlayState->interfaceCtx.restrictions.sunsSong;
memset(&gPlayState->interfaceCtx.restrictions, 0, sizeof(gPlayState->interfaceCtx.restrictions));
gPlayState->interfaceCtx.restrictions.sunsSong = sunsBackup;
}

void RegisterUnrestrictedItems() {
COND_HOOK(OnGameFrameUpdate, CVAR_UNRESTRICTED_ITEMS_VALUE, OnGameFrameUpdateUnrestrictedItems);
}

static RegisterShipInitFunc initFunc(RegisterUnrestrictedItems, { CVAR_UNRESTRICTED_ITEMS_NAME });
58 changes: 0 additions & 58 deletions soh/soh/Enhancements/cheat_hook_handlers.cpp

This file was deleted.

6 changes: 0 additions & 6 deletions soh/soh/Enhancements/cheat_hook_handlers.h

This file was deleted.

2 changes: 1 addition & 1 deletion soh/soh/Enhancements/game-interactor/GameInteractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ struct HookInfo {
#define COND_VB_SHOULD(id, condition, body) \
{ \
static HOOK_ID hookId = 0; \
GameInteractor::Instance->UnregisterGameHookForID<GameInteractor::ShouldVanillaBehavior>(hookId); \
GameInteractor::Instance->UnregisterGameHookForID<GameInteractor::OnVanillaBehavior>(hookId); \
hookId = 0; \
if (condition) { \
hookId = REGISTER_VB_SHOULD(id, body); \
Expand Down
Loading