mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-07-29 19:18:58 -07:00
Port over ShipInit from 2Ship (#4756)
* Port over ShipInit and transform Moon Jump as example * Clean up moon jump * Updated moon jump structure & cvar defines
This commit is contained in:
parent
f0b02d6c7e
commit
f8fa4416de
7 changed files with 108 additions and 29 deletions
26
soh/soh/Enhancements/Cheats/MoonJump.cpp
Normal file
26
soh/soh/Enhancements/Cheats/MoonJump.cpp
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#include <libultraship/bridge.h>
|
||||||
|
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
|
||||||
|
#include "soh/ShipInit.hpp"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "macros.h"
|
||||||
|
extern PlayState* gPlayState;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CVAR_MOON_JUMP_NAME "gCheats.MoonJumpOnL"
|
||||||
|
#define CVAR_MOON_JUMP_DEFAULT 0
|
||||||
|
#define CVAR_MOON_JUMP_VALUE CVarGetInteger(CVAR_MOON_JUMP_NAME, CVAR_MOON_JUMP_DEFAULT)
|
||||||
|
|
||||||
|
void OnPlayerUpdateMoonJump() {
|
||||||
|
Player* player = GET_PLAYER(gPlayState);
|
||||||
|
|
||||||
|
if (player != nullptr && CHECK_BTN_ANY(gPlayState->state.input[0].cur.button, BTN_L)) {
|
||||||
|
player->actor.velocity.y = 6.34375f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegisterMoonJump() {
|
||||||
|
COND_HOOK(OnPlayerUpdate, CVAR_MOON_JUMP_VALUE, OnPlayerUpdateMoonJump);
|
||||||
|
}
|
||||||
|
|
||||||
|
static RegisterShipInitFunc initFunc(RegisterMoonJump, { CVAR_MOON_JUMP_NAME });
|
|
@ -592,15 +592,43 @@ struct HookInfo {
|
||||||
#define GET_CURRENT_REGISTERING_INFO(type) HookRegisteringInfo{}
|
#define GET_CURRENT_REGISTERING_INFO(type) HookRegisteringInfo{}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define REGISTER_VB_SHOULD(flag, body) \
|
#define REGISTER_VB_SHOULD(flag, body) \
|
||||||
GameInteractor::Instance->RegisterGameHookForID<GameInteractor::OnVanillaBehavior>( \
|
GameInteractor::Instance->RegisterGameHookForID<GameInteractor::OnVanillaBehavior>( \
|
||||||
flag, [](GIVanillaBehavior _, bool* should, va_list _originalArgs) { \
|
flag, [](GIVanillaBehavior _, bool* should, va_list _originalArgs) { \
|
||||||
va_list args; \
|
va_list args; \
|
||||||
va_copy(args, _originalArgs); \
|
va_copy(args, _originalArgs); \
|
||||||
body; \
|
body; \
|
||||||
va_end(args); \
|
va_end(args); \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
#define COND_HOOK(hookType, condition, body) \
|
||||||
|
{ \
|
||||||
|
static HOOK_ID hookId = 0; \
|
||||||
|
GameInteractor::Instance->UnregisterGameHook<GameInteractor::hookType>(hookId); \
|
||||||
|
hookId = 0; \
|
||||||
|
if (condition) { \
|
||||||
|
hookId = GameInteractor::Instance->RegisterGameHook<GameInteractor::hookType>(body); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
#define COND_ID_HOOK(hookType, id, condition, body) \
|
||||||
|
{ \
|
||||||
|
static HOOK_ID hookId = 0; \
|
||||||
|
GameInteractor::Instance->UnregisterGameHookForID<GameInteractor::hookType>(hookId); \
|
||||||
|
hookId = 0; \
|
||||||
|
if (condition) { \
|
||||||
|
hookId = GameInteractor::Instance->RegisterGameHookForID<GameInteractor::hookType>(id, body); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
#define COND_VB_SHOULD(id, condition, body) \
|
||||||
|
{ \
|
||||||
|
static HOOK_ID hookId = 0; \
|
||||||
|
GameInteractor::Instance->UnregisterGameHookForID<GameInteractor::ShouldVanillaBehavior>(hookId); \
|
||||||
|
hookId = 0; \
|
||||||
|
if (condition) { \
|
||||||
|
hookId = REGISTER_VB_SHOULD(id, body); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
class GameInteractor {
|
class GameInteractor {
|
||||||
public:
|
public:
|
||||||
static GameInteractor* Instance;
|
static GameInteractor* Instance;
|
||||||
|
|
|
@ -146,21 +146,6 @@ void RegisterInfiniteNayrusLove() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterMoonJumpOnL() {
|
|
||||||
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameFrameUpdate>([]() {
|
|
||||||
if (!GameInteractor::IsSaveLoaded(true)) return;
|
|
||||||
|
|
||||||
if (CVarGetInteger(CVAR_CHEAT("MoonJumpOnL"), 0) != 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 RegisterInfiniteISG() {
|
void RegisterInfiniteISG() {
|
||||||
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameFrameUpdate>([]() {
|
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameFrameUpdate>([]() {
|
||||||
if (!GameInteractor::IsSaveLoaded(true)) return;
|
if (!GameInteractor::IsSaveLoaded(true)) return;
|
||||||
|
@ -1473,7 +1458,6 @@ void InitMods() {
|
||||||
RegisterInfiniteAmmo();
|
RegisterInfiniteAmmo();
|
||||||
RegisterInfiniteMagic();
|
RegisterInfiniteMagic();
|
||||||
RegisterInfiniteNayrusLove();
|
RegisterInfiniteNayrusLove();
|
||||||
RegisterMoonJumpOnL();
|
|
||||||
RegisterInfiniteISG();
|
RegisterInfiniteISG();
|
||||||
RegisterEzQPA();
|
RegisterEzQPA();
|
||||||
RegisterUnrestrictedItems();
|
RegisterUnrestrictedItems();
|
||||||
|
|
|
@ -127,6 +127,7 @@ Sail* Sail::Instance;
|
||||||
#include "soh/resource/importer/BackgroundFactory.h"
|
#include "soh/resource/importer/BackgroundFactory.h"
|
||||||
|
|
||||||
#include "soh/config/ConfigUpdaters.h"
|
#include "soh/config/ConfigUpdaters.h"
|
||||||
|
#include "soh/ShipInit.hpp"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "src/overlays/actors/ovl_En_Dns/z_en_dns.h"
|
#include "src/overlays/actors/ovl_En_Dns/z_en_dns.h"
|
||||||
|
@ -1150,6 +1151,7 @@ extern "C" void InitOTR() {
|
||||||
conf->RunVersionUpdates();
|
conf->RunVersionUpdates();
|
||||||
|
|
||||||
SohGui::SetupGuiElements();
|
SohGui::SetupGuiElements();
|
||||||
|
ShipInit::InitAll();
|
||||||
AudioCollection::Instance = new AudioCollection();
|
AudioCollection::Instance = new AudioCollection();
|
||||||
ActorDB::Instance = new ActorDB();
|
ActorDB::Instance = new ActorDB();
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
|
43
soh/soh/ShipInit.hpp
Normal file
43
soh/soh/ShipInit.hpp
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#ifndef SHIP_INIT_HPP
|
||||||
|
#define SHIP_INIT_HPP
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <set>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
struct ShipInit {
|
||||||
|
static std::unordered_map<std::string, std::vector<std::function<void()>>>& GetAll() {
|
||||||
|
static std::unordered_map<std::string, std::vector<std::function<void()>>> shipInitFuncs;
|
||||||
|
return shipInitFuncs;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void InitAll() {
|
||||||
|
ShipInit::Init("*");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Init(const std::string& path) {
|
||||||
|
auto& shipInitFuncs = ShipInit::GetAll();
|
||||||
|
for (const auto& initFunc : shipInitFuncs[path]) {
|
||||||
|
initFunc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RegisterShipInitFunc {
|
||||||
|
RegisterShipInitFunc(std::function<void()> initFunc, const std::set<std::string>& updatePaths = {}) {
|
||||||
|
auto& shipInitFuncs = ShipInit::GetAll();
|
||||||
|
|
||||||
|
shipInitFuncs["*"].push_back(initFunc);
|
||||||
|
|
||||||
|
for (const auto& path : updatePaths) {
|
||||||
|
shipInitFuncs[path].push_back(initFunc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
#endif // SHIP_INIT_HPP
|
|
@ -239,6 +239,7 @@ namespace UIWidgets {
|
||||||
if (CustomCheckbox(text, &val, disabled, disabledGraphic)) {
|
if (CustomCheckbox(text, &val, disabled, disabledGraphic)) {
|
||||||
CVarSetInteger(cvarName, val);
|
CVarSetInteger(cvarName, val);
|
||||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
||||||
|
ShipInit::Init(cvarName);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,6 +299,7 @@ namespace UIWidgets {
|
||||||
selected = i;
|
selected = i;
|
||||||
changed = true;
|
changed = true;
|
||||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
||||||
|
ShipInit::Init(cvarName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,3 @@
|
||||||
//
|
|
||||||
// UIWidgets.hpp
|
|
||||||
// soh
|
|
||||||
//
|
|
||||||
// Created by David Chavez on 25.08.22.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef UIWidgets_hpp
|
#ifndef UIWidgets_hpp
|
||||||
#define UIWidgets_hpp
|
#define UIWidgets_hpp
|
||||||
|
|
||||||
|
@ -17,6 +10,7 @@
|
||||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||||
#endif
|
#endif
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
|
#include "soh/ShipInit.hpp"
|
||||||
|
|
||||||
namespace UIWidgets {
|
namespace UIWidgets {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue