Shipwright/soh/soh/Enhancements/game-interactor/GameInteractor.h

144 lines
4.9 KiB
C
Raw Normal View History

#pragma once
#ifndef GameInteractor_h
#define GameInteractor_h
#include "GameInteractionEffect.h"
[GI] Item_Give and OnReceiveItem updates (#2580) * Changed OnReceiveItem hook to pass GetItemEntry, which required the following changes: Reworked the references to it in `z_parameter` to call a single function with the item return and hook call in it for ease of editing. Modified the pendingSale functionality to set and pass a modIndex value as well, as mod items (like randomizer) in shops still use the vanilla sale path. * Missed some files for the pendingSale changes. Also added Randomizer_Item_Give to the OnReceiveItem system. * Ice traps now trigger OnReceiveItem. * All ice traps truly do work now. As a side effect, item autosave doesn't work for shop/scrub/merchant transactions, requires new OnSaleEnded hook that can also call the autosave. * Removed unnecessary calls to ItemTable_RetrieveEntry where GetItemEntry properties were being used to call it. General code cleanup. * Added OnSaleEnd hook for when rupees are finished deducting after a sale. Migrated AutoSave to its own function, registered AutoSave function to OnReceiveItem and OnSaleEnd hooks to help with autsaving after buying items. Some futureproofing for AutoSave function with parameters for skipping autosave, for when transition end is migrated to AutoSave function (whether through direct call or through a hook). * Renamed hook paramaters, and registered hook function parameters, to a more descriptive alternative. * Missed a couple, fixed a typo. * One more missed paramater name refactor. Refactored all references to OnReceiveItem to OnItemReceive to mirror upcoming full hook refactor for name ordering conventions. Up-to-date with develop.
2023-03-12 03:00:03 -04:00
#include "soh/Enhancements/item-tables/ItemTableTypes.h"
typedef enum {
/* 0x00 */ GI_LINK_SIZE_NORMAL,
/* 0x01 */ GI_LINK_SIZE_GIANT,
/* 0x02 */ GI_LINK_SIZE_MINISH,
/* 0x03 */ GI_LINK_SIZE_PAPER,
/* 0x04 */ GI_LINK_SIZE_RESET
} GILinkSize;
typedef enum {
/* 0x00 */ GI_GRAVITY_LEVEL_LIGHT,
/* 0x01 */ GI_GRAVITY_LEVEL_NORMAL,
/* 0x02 */ GI_GRAVITY_LEVEL_HEAVY,
} GIGravityLevel;
#ifdef __cplusplus
extern "C" {
#endif
uint8_t GameInteractor_NoUIActive();
GILinkSize GameInteractor_GetLinkSize();
void GameInteractor_SetLinkSize(GILinkSize size);
uint8_t GameInteractor_InvisibleLinkActive();
uint8_t GameInteractor_OneHitKOActive();
uint8_t GameInteractor_PacifistModeActive();
uint8_t GameInteractor_DisableZTargetingActive();
uint8_t GameInteractor_ReverseControlsActive();
int32_t GameInteractor_DefenseModifier();
int32_t GameInteractor_RunSpeedModifier();
GIGravityLevel GameInteractor_GravityLevel();
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
2023-02-15 14:30:34 -05:00
#include <vector>
#include <functional>
#define DEFINE_HOOK(name, type) \
struct name { \
typedef std::function<type> fn; \
}
class GameInteractor {
public:
static GameInteractor* Instance;
// Gsme State
class State {
public:
static bool NoUIActive;
static GILinkSize LinkSize;
static bool InvisibleLinkActive;
static bool OneHitKOActive;
static bool PacifistModeActive;
static bool DisableZTargetingActive;
static bool ReverseControlsActive;
static int32_t DefenseModifier;
static int32_t RunSpeedModifier;
static GIGravityLevel GravityLevel;
static void SetPacifistMode(bool active);
};
// Effects
static GameInteractionEffectQueryResult CanApplyEffect(GameInteractionEffectBase* effect);
static GameInteractionEffectQueryResult ApplyEffect(GameInteractionEffectBase* effect);
static GameInteractionEffectQueryResult RemoveEffect(GameInteractionEffectBase* effect);
2023-02-15 14:30:34 -05:00
// Game Hooks
template <typename H> struct RegisteredGameHooks { inline static std::vector<typename H::fn> functions; };
template <typename H> void RegisterGameHook(typename H::fn h) { RegisteredGameHooks<H>::functions.push_back(h); }
template <typename H, typename... Args> void ExecuteHooks(Args&&... args) {
for (auto& fn : RegisteredGameHooks<H>::functions) {
fn(std::forward<Args>(args)...);
}
}
DEFINE_HOOK(OnLoadGame, void(int32_t fileNum));
DEFINE_HOOK(OnExitGame, void(int32_t fileNum));
DEFINE_HOOK(OnGameFrameUpdate, void());
[GI] Item_Give and OnReceiveItem updates (#2580) * Changed OnReceiveItem hook to pass GetItemEntry, which required the following changes: Reworked the references to it in `z_parameter` to call a single function with the item return and hook call in it for ease of editing. Modified the pendingSale functionality to set and pass a modIndex value as well, as mod items (like randomizer) in shops still use the vanilla sale path. * Missed some files for the pendingSale changes. Also added Randomizer_Item_Give to the OnReceiveItem system. * Ice traps now trigger OnReceiveItem. * All ice traps truly do work now. As a side effect, item autosave doesn't work for shop/scrub/merchant transactions, requires new OnSaleEnded hook that can also call the autosave. * Removed unnecessary calls to ItemTable_RetrieveEntry where GetItemEntry properties were being used to call it. General code cleanup. * Added OnSaleEnd hook for when rupees are finished deducting after a sale. Migrated AutoSave to its own function, registered AutoSave function to OnReceiveItem and OnSaleEnd hooks to help with autsaving after buying items. Some futureproofing for AutoSave function with parameters for skipping autosave, for when transition end is migrated to AutoSave function (whether through direct call or through a hook). * Renamed hook paramaters, and registered hook function parameters, to a more descriptive alternative. * Missed a couple, fixed a typo. * One more missed paramater name refactor. Refactored all references to OnReceiveItem to OnItemReceive to mirror upcoming full hook refactor for name ordering conventions. Up-to-date with develop.
2023-03-12 03:00:03 -04:00
DEFINE_HOOK(OnItemReceive, void(GetItemEntry itemEntry));
DEFINE_HOOK(OnSaleEnd, void(GetItemEntry itemEntry));
2023-03-02 03:27:28 -05:00
DEFINE_HOOK(OnSceneInit, void(int16_t sceneNum));
DEFINE_HOOK(OnPlayerUpdate, void());
DEFINE_HOOK(OnPlayerBonk, void());
2023-02-15 14:30:34 -05:00
DEFINE_HOOK(OnSaveFile, void(int32_t fileNum));
DEFINE_HOOK(OnLoadFile, void(int32_t fileNum));
DEFINE_HOOK(OnDeleteFile, void(int32_t fileNum));
2023-03-02 03:27:28 -05:00
DEFINE_HOOK(OnDialogMessage, void());
DEFINE_HOOK(OnPresentTitleCard, void());
DEFINE_HOOK(OnInterfaceUpdate, void());
DEFINE_HOOK(OnKaleidoscopeUpdate, void(int16_t inDungeonScene));
DEFINE_HOOK(OnPresentFileSelect, void());
DEFINE_HOOK(OnUpdateFileSelectSelection, void(uint16_t optionIndex));
DEFINE_HOOK(OnUpdateFileCopySelection, void(uint16_t optionIndex));
DEFINE_HOOK(OnUpdateFileCopyConfirmationSelection, void(uint16_t optionIndex));
DEFINE_HOOK(OnUpdateFileEraseSelection, void(uint16_t optionIndex));
DEFINE_HOOK(OnUpdateFileEraseConfirmationSelection, void(uint16_t optionIndex));
DEFINE_HOOK(OnUpdateFileAudioSelection, void(uint8_t optionIndex));
DEFINE_HOOK(OnUpdateFileTargetSelection, void(uint8_t optionIndex));
DEFINE_HOOK(OnSetGameLanguage, void());
2023-02-15 14:30:34 -05:00
// Helpers
static bool IsSaveLoaded();
static bool IsGameplayPaused();
static bool CanSpawnEnemy();
class RawAction {
public:
static void AddOrRemoveHealthContainers(int16_t amount);
static void AddOrRemoveMagic(int8_t amount);
static void HealOrDamagePlayer(int16_t hearts);
static void SetPlayerHealth(int16_t hearts);
static void SetLinkInvisibility(bool active);
static void SetWeatherStorm(bool active);
static void ForceEquipBoots(int8_t boots);
static void FreezePlayer();
static void BurnPlayer();
static void ElectrocutePlayer();
static void KnockbackPlayer(float strength);
static void GiveDekuShield();
static void SpawnCuccoStorm();
static void ForceInterfaceUpdate();
static GameInteractionEffectQueryResult SpawnEnemyWithOffset(uint32_t enemyId, int32_t enemyParams);
};
};
#endif /* __cplusplus */
#endif /* GameInteractor_h */