forked from HarbourMasters/Shipwright
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port over ShipInit from 2Ship (HarbourMasters#4756)
* Port over ShipInit and transform Moon Jump as example * Clean up moon jump * Updated moon jump structure & cvar defines
- Loading branch information
Showing
7 changed files
with
108 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" { | ||
#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 }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters