GameInteractor Base + Moon Jump (#40)

* GameInteractor Base + Moon Jump

* readd checkbox post merge
This commit is contained in:
inspectredc
2024-05-22 09:04:58 -05:00
committed by Garrett Cox
parent fb832cd5e2
commit 7c4772efaa
9 changed files with 138 additions and 0 deletions
+3
View File
@@ -276,6 +276,9 @@ void DrawDeveloperToolsMenu() {
"Right, and open the debug menu with L on the pause screen"
});
UIWidgets::CVarCheckbox("No Clip", "gDeveloperTools.NoClip");
UIWidgets::CVarCheckbox("Moon Jump on L", "gDeveloperTools.MoonJumpOnL", {
.tooltip = "Holding L makes you float into the air"
});
if (gPlayState != NULL) {
UIWidgets::PaddedSeparator();
UIWidgets::Checkbox("Frame Advance", (bool*)&gPlayState->frameAdvCtx.enabled, {
+5
View File
@@ -55,6 +55,8 @@ CrowdControl* CrowdControl::Instance;
#include "BenJsonConversions.hpp"
#include "Enhancements/controls/SohInputEditorWindow.h"
#include "Enhancements/GameInteractor/GameInteractor.h"
#include "Enhancements/mods.h"
// Resource Types/Factories
#include "2s2h/resource/type/Animation.h"
@@ -86,6 +88,7 @@ CrowdControl* CrowdControl::Instance;
#include "2s2h/resource/importer/TextureAnimationFactory.h"
OTRGlobals* OTRGlobals::Instance;
GameInteractor* GameInteractor::Instance;
extern "C" char** cameraStrings;
std::vector<std::shared_ptr<std::string>> cameraStdStrings;
@@ -301,7 +304,9 @@ extern "C" void InitOTR() {
#endif
OTRGlobals::Instance = new OTRGlobals();
GameInteractor::Instance = new GameInteractor();
BenGui::SetupGuiElements();
InitMods();
clearMtx = (uintptr_t)&gMtxClear;
//OTRMessage_Init();
@@ -0,0 +1,3 @@
#include "GameInteractor.h"
#include <libultraship/bridge.h>
@@ -0,0 +1,53 @@
#ifndef GAME_INTERACTOR_H
#define GAME_INTERACTOR_H
#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(OnGameStateMainFinish, void());
DEFINE_HOOK(OnGameStateDrawFinish, void());
DEFINE_HOOK(OnGameStateUpdate, void());
// Game Actions
class RawAction {
};
};
#endif // __cplusplus
#endif // GAME_INTERACTOR_H
@@ -0,0 +1,15 @@
#include "GameInteractorHooks.h"
// Gameplay
void GameInteractor_ExecuteOnGameStateMainFinish() {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnGameStateMainFinish>();
}
void GameInteractor_ExecuteOnGameStateDrawFinish() {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnGameStateDrawFinish>();
}
void GameInteractor_ExecuteOnGameStateUpdate() {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnGameStateUpdate>();
}
@@ -0,0 +1,14 @@
#include "GameInteractor.h"
#ifdef __cplusplus
extern "C" {
#endif
// Gameplay
void GameInteractor_ExecuteOnGameStateMainFinish();
void GameInteractor_ExecuteOnGameStateDrawFinish();
void GameInteractor_ExecuteOnGameStateUpdate();
#ifdef __cplusplus
}
#endif
+29
View File
@@ -0,0 +1,29 @@
#include "mods.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;
}
void RegisterMoonJumpOnL() {
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameStateUpdate>([]() {
if (!gPlayState) return;
if (CVarGetInteger("gDeveloperTools.MoonJumpOnL", 0)) {
Player* player = GET_PLAYER(gPlayState);
if (CHECK_BTN_ANY(gPlayState->state.input[0].cur.button, BTN_L)) {
player->actor.velocity.y = 6.34375f;
}
}
});
}
void InitMods() {
RegisterMoonJumpOnL();
}
+9
View File
@@ -0,0 +1,9 @@
#ifdef __cplusplus
extern "C" {
#endif
void InitMods();
#ifdef __cplusplus
}
#endif
+7
View File
@@ -13,6 +13,8 @@
#include "overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope.h"
#include "debug.h"
#include "Enhancements/GameInteractor/GameInteractorHooks.h"
s32 gFramerateDivisor = 1;
f32 gFramerateDivisorF = 1.0f;
f32 gFramerateDivisorHalf = 1.0f / 2.0f;
@@ -148,10 +150,15 @@ void GameState_Update(GameState* gameState) {
gameState->main(gameState);
GameInteractor_ExecuteOnGameStateMainFinish();
if (R_PAUSE_BG_PRERENDER_STATE != PAUSE_BG_PRERENDER_PROCESS) {
GameState_Draw(gameState, gfxCtx);
GameInteractor_ExecuteOnGameStateDrawFinish();
GameState_DrawEnd(gfxCtx);
}
GameInteractor_ExecuteOnGameStateUpdate();
}
void GameState_IncrementFrameCount(GameState* gameState) {