game interactor example stuff

This commit is contained in:
inspectredc
2023-10-06 23:38:16 +01:00
parent 85a0ab17b1
commit d0d7e684c2
11 changed files with 164 additions and 0 deletions
+4
View File
@@ -105,6 +105,10 @@ file(GLOB_RECURSE ALL_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"src/port/*.h"
"src/port/*.c"
"src/port/*.cpp"
"src/port/Enhancements/*.h"
"src/port/Enhancements/*.cpp"
"src/port/Enhancements/game-interactor/*.h"
"src/port/Enhancements/game-interactor/*.cpp"
"src/port/importer/*.cpp"
"src/port/importer/types/*.cpp"
"text/*.c"
+5
View File
@@ -29,6 +29,8 @@
#include "course_table.h"
#include "rumble_init.h"
#include "port/Enhancements/game-interactor/GameInteractor_Hooks.h"
#define PLAY_MODE_NORMAL 0
#define PLAY_MODE_PAUSED 2
#define PLAY_MODE_CHANGE_AREA 3
@@ -1153,6 +1155,9 @@ s32 update_level(void) {
enable_background_sound();
}
// Updates only when in game, i.e. past the save select screen
GameInteractor_ExecuteOnGameFrameUpdate();
return changeLevel;
}
+7
View File
@@ -35,6 +35,8 @@
#include "rumble_init.h"
#include "animation_table.h"
#include "port/Enhancements/game-interactor/GameInteractor_Hooks.h"
u32 unused80339F10;
u8 unused80339F1C[20];
@@ -1455,6 +1457,7 @@ void update_mario_health(struct MarioState *m) {
if ((m->input & INPUT_IN_POISON_GAS) && !(m->action & ACT_FLAG_INTANGIBLE)) {
if (!(m->flags & MARIO_METAL_CAP) && !gDebugLevelSelect) {
m->health -= 4;
GameInteractor_ExecuteOnHealthChange(m->health);
}
} else {
if ((m->action & ACT_FLAG_SWIMMING) && !(m->action & ACT_FLAG_INTANGIBLE)) {
@@ -1465,8 +1468,10 @@ void update_mario_health(struct MarioState *m) {
// If using the debug level select, do not lose any HP to water.
if ((m->pos[1] >= (m->waterLevel - 140)) && !terrainIsSnow) {
m->health += 0x1A;
GameInteractor_ExecuteOnHealthChange(m->health);
} else if (!gDebugLevelSelect) {
m->health -= (terrainIsSnow ? 3 : 1);
GameInteractor_ExecuteOnHealthChange(m->health);
}
}
}
@@ -1475,10 +1480,12 @@ void update_mario_health(struct MarioState *m) {
if (m->healCounter > 0) {
m->health += 0x40;
m->healCounter--;
GameInteractor_ExecuteOnHealthChange(m->health);
}
if (m->hurtCounter > 0) {
m->health -= 0x40;
m->hurtCounter--;
GameInteractor_ExecuteOnHealthChange(m->health);
}
if (m->health > 0x880) {
+5
View File
@@ -11,6 +11,8 @@
#include "texts_table.h"
#include "port/importer/DialogFactory.h"
#include "port/importer/DictionaryFactory.h"
#include "port/Enhancements/game-interactor/GameInteractor.h"
#include "port/Enhancements/mods.h"
#include <Fast3D/gfx_pc.h>
#include <Fast3D/gfx_rendering_api.h>
@@ -23,6 +25,7 @@ extern "C" {
}
GameEngine* GameEngine::Instance;
GameInteractor* GameInteractor::Instance;
GameEngine::GameEngine(){
std::vector<std::string> OTRFiles;
@@ -58,6 +61,8 @@ GameEngine::GameEngine(){
void GameEngine::Create(){
GameEngine::Instance = new GameEngine();
GameInteractor::Instance = new GameInteractor();
InitMods();
GameUI::SetupGuiElements();
}
@@ -0,0 +1,12 @@
#include "GameInteractor.h"
bool GameInteractor::IsSaveLoaded() {
// todo
return false;
}
bool GameInteractor::IsGameplayPaused() {
// todo
return false;
}
@@ -0,0 +1,50 @@
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
#include <vector>
#include <functional>
#define DEFINE_HOOK(name, type) \
struct name { \
typedef std::function<type> fn; \
}
class GameInteractor {
public:
static GameInteractor* Instance;
// Game State
class State {
};
// 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(OnGameFrameUpdate, void());
DEFINE_HOOK(OnHealthChange, void(int16_t health));
// Helpers
static bool IsSaveLoaded();
static bool IsGameplayPaused();
class RawAction {
};
};
#endif // __cplusplus
@@ -0,0 +1,12 @@
#include "GameInteractor_Hooks.h"
// Gameplay
// Updates only when in game, i.e. past the save select screen
void GameInteractor_ExecuteOnGameFrameUpdate() {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnGameFrameUpdate>();
}
void GameInteractor_ExecuteOnHealthChange(int16_t health) {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnHealthChange>(health);
}
@@ -0,0 +1,13 @@
#include "GameInteractor.h"
#ifdef __cplusplus
extern "C" {
#endif
// Gameplay
void GameInteractor_ExecuteOnGameFrameUpdate();
void GameInteractor_ExecuteOnHealthChange(int16_t health);
#ifdef __cplusplus
}
#endif
+34
View File
@@ -0,0 +1,34 @@
#include "mods.h"
#include <libultraship/bridge.h>
#include "game-interactor/GameInteractor.h"
#include "game/level_update.h"
extern MarioState* gMarioState;
#define MARIO_HEALTH_MAX 0x880
void RegisterInfiniteHealth() {
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnHealthChange>([](int16_t health) {
if (!gMarioState) return;
if (CVarGetInteger("gInfiniteHealth", 0) != 0) {
gMarioState->health = MARIO_HEALTH_MAX;
}
});
}
void RegisterInfiniteLives() {
// There may be a better hook that can be made, rather than doing this every frame
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameFrameUpdate>([]() {
if (!gMarioState) return;
if (CVarGetInteger("gInfiniteLives", 0) != 0) {
gMarioState->numLives = 100;
}
});
}
void InitMods() {
RegisterInfiniteHealth();
RegisterInfiniteLives();
}
+9
View File
@@ -0,0 +1,9 @@
#ifdef __cplusplus
extern "C" {
#endif
void InitMods();
#ifdef __cplusplus
}
#endif
+13
View File
@@ -303,6 +303,15 @@ void DrawEnhancementsMenu() {
}
}
void DrawCheatsMenu() {
if (ImGui::BeginMenu("Cheats")) {
UIWidgets::PaddedEnhancementCheckbox("Infinite Health", "gInfiniteHealth", true, false);
UIWidgets::PaddedEnhancementCheckbox("Infinite Lives", "gInfiniteLives", true, false);
ImGui::EndMenu();
}
}
void GameMenuBar::DrawElement() {
if(ImGui::BeginMenuBar()){
DrawMenuBarIcon();
@@ -321,6 +330,10 @@ void GameMenuBar::DrawElement() {
DrawEnhancementsMenu();
ImGui::SetCursorPosY(0.0f);
DrawCheatsMenu();
ImGui::PopStyleVar(1);
ImGui::EndMenuBar();
}