SuperMarioOdysseyOnline/source/hooks.cpp
Amethyst-szs 69d6a732c7
refac: abstracting game mode
- change: general game mode management more abstract and less H&S oriented
- change: split 8bit updateType into 4bit game mode and 4bit update type.
- change: don't process packets from other game modes (legacy mode for backwards compatibility)
- change: cache game mode of other players in puppet, resend GameModeInf on detected game mode change
- change: send gamemode NONE when H&S is selected but not active
- change: improved distance calculations in squared distance space
- change: change from hider to seeker when dead even if there are no other players
- fix: add hours to the minutes for the H&S GameModeInf packet
- fix: set milliseconds and hours when receiving time from server
- fix: keep the new time from the server for longer than a single frame
- fix: reset H&S icon after receiving a new state from the server
- refac: move code to generate PlayerList into own abstract LayoutPlayerList class.
- refac: to_string() method for GameTime to simplify code in the Game Mode Icon class.
- refac: rename TagInf packet to GameModeInf packet
- refac: remove param from `SocketClient::tryGetPacket()` (unused)
- refac: move all H&S specific files into the same directory (out of layouts)
- refac: move GameModeTimer.cpp from source/server/hns/ to source/server/gamemode/
- refac: clean up some unused, duplicate or complicated imports
- [mod menu] change: use the game mode name in the options & menu title
- [mod menu] change: select the next game mode in the game mode select menu
- [mod menu] change: possibility to always change the gravity setting in the H&S config menu
- [mod menu] add: toggle options to control mario/cappy collision/bounciness

(cherry picked from commit a9b2c87aa0)
(cherry picked from commit 918f61fbfd619d781d88dc74878d392c48cfa480)
(cherry picked from commit 96aff7dd7167d8244acef7884fa3503d4c3f868a)
(cherry picked from commit 0fb6413ec91bbf679e9f8cea1aa512159101fa46)
(cherry picked from commit ab78a812fd18781655ccf38e803f619ea427d1ac)

Co-authored-by: Robin C. Ladiges <rcl.git@blackpinguin.de>
2024-10-27 00:38:05 +02:00

221 lines
7.1 KiB
C++

#include <sys/types.h>
#include "al/byaml/ByamlIter.h"
#include "al/byaml/writer/ByamlWriter.h"
#include "al/execute/ExecuteDirector.h"
#include "al/execute/ExecuteOrder.h"
#include "al/execute/ExecuteTable.h"
#include "al/execute/ExecuteTableHolderDraw.h"
#include "al/execute/ExecuteTableHolderUpdate.h"
#include "al/scene/Scene.h"
#include "al/util.hpp"
#include "al/util/GraphicsUtil.h"
#include "al/util/KitUtil.h"
#include "game/Actors/WorldEndBorderKeeper.h"
#include "game/Player/PlayerActorHakoniwa.h"
#include "game/StageScene/StageSceneStateOption.h"
#include "game/StageScene/StageSceneStatePauseMenu.h"
#include "game/StageScene/StageSceneStateServerConfig.hpp"
#include "logger.hpp"
#include "main.hpp"
#include "rs/util.hpp"
#include "rs/util/InputUtil.h"
#include "sead/basis/seadNew.h"
#include "sead/math/seadVector.h"
#include "sead/prim/seadSafeString.h"
#include "server/Client.hpp"
#include "server/gamemode/GameModeBase.hpp"
#include "server/gamemode/GameModeManager.hpp"
bool comboBtnHook(int port) {
GameModeManager* gmm = GameModeManager::instance();
// only switch to combo if the gamemode is active
if (!gmm->isActive()) {
return al::isPadTriggerDown(port);
}
// only if the gamemode wants it
GameModeBase* mode = gmm->getMode<GameModeBase>();
if (!mode || mode->ignoreComboBtn()) {
return false;
}
return !al::isPadHoldL(port) && al::isPadTriggerDown(port);
}
void saveWriteHook(al::ByamlWriter* saveByml) {
const char* serverIP = Client::getCurrentIP();
const int serverPort = Client::getCurrentPort();
const bool serverHidden = Client::isServerHidden();
if (serverIP) {
saveByml->addString("ServerIP", serverIP);
} else {
saveByml->addString("ServerIP", "127.0.0.1");
}
if (serverPort) {
saveByml->addInt("ServerPort", serverPort);
} else {
saveByml->addInt("ServerPort", 0);
}
saveByml->addBool("ServerHidden", serverHidden);
saveByml->pop();
}
bool saveReadHook(int* padRumbleInt, al::ByamlIter const& saveByml, char const* padRumbleKey) {
const char* serverIP = "";
int serverPort = 0;
bool serverHidden = false;
if (al::tryGetByamlString(&serverIP, saveByml, "ServerIP")) {
Client::setLastUsedIP(serverIP);
}
if (al::tryGetByamlS32(&serverPort, saveByml, "ServerPort")) {
Client::setLastUsedPort(serverPort);
}
if (al::tryGetByamlBool(&serverHidden, saveByml, "ServerHidden")) {
Client::setServerHidden(serverHidden);
}
return al::tryGetByamlS32(padRumbleInt, saveByml, padRumbleKey);
}
bool registerShineToList(Shine* shineActor) {
if (shineActor->mShineIdx >= 0) {
Client::tryRegisterShine(shineActor);
}
return al::isAlive(shineActor);
}
void overrideHelpFadeNerve(StageSceneStatePauseMenu* thisPtr) {
// Set label in menu inside LocalizedData/${lang}/MessageData/LayoutMessage.szs/Menu.msbt/Menu_Help
thisPtr->exeServerConfig();
al::setNerve(thisPtr, &nrvStageSceneStatePauseMenuServerConfig);
}
StageSceneStateServerConfig* sceneStateServerConfig = nullptr;
void initStateHook(
StageSceneStatePauseMenu* thisPtr,
char const* stateName,
al::Scene* host,
al::LayoutInitInfo const& initInfo,
FooterParts* footer,
GameDataHolder* data,
bool unkBool
) {
thisPtr->mStateOption = new StageSceneStateOption(stateName, host, initInfo, footer, data, unkBool);
sceneStateServerConfig = new StageSceneStateServerConfig("ServerConfig", host, initInfo, footer, data, unkBool);
}
void initNerveStateHook(
StageSceneStatePauseMenu* stateParent,
StageSceneStateOption* stateOption,
al::Nerve const* executingNerve,
char const* stateName
) {
al::initNerveState(stateParent, stateOption, executingNerve, stateName);
al::initNerveState(stateParent, sceneStateServerConfig, &nrvStageSceneStatePauseMenuServerConfig, "CustomNerveOverride");
}
// skips starting both coin counters
void startCounterHook(CoinCounter* thisPtr) {
if (!GameModeManager::instance()->isModeRequireUI()) {
thisPtr->tryStart();
}
}
// Simple hook that can be used to override isModeE3 checks to enable/disable certain behaviors
bool modeE3Hook() {
return GameModeManager::instance()->isModeRequireUI();
}
// Skips ending the play guide layout if a mode is active, since the mode would have already ended it
void playGuideEndHook(al::SimpleLayoutAppearWaitEnd* thisPtr) {
if (!GameModeManager::instance()->isModeRequireUI()) {
thisPtr->end();
}
}
// Gravity Hooks
void initHackCapHook(al::LiveActor* cappy) {
al::initActorPoseTQGSV(cappy);
}
al::PlayerHolder* createTicketHook(StageScene* curScene) {
// only creates custom camera ticket if the mode wants it
GameModeBase* mode = GameModeManager::instance()->getMode<GameModeBase>();
if (mode && mode->hasCustomCamera()) {
al::CameraDirector* director = curScene->getCameraDirector();
if (director && director->mFactory) {
mode->createCustomCameraTicket(director);
}
}
return al::getScenePlayerHolder(curScene);
}
bool borderPullBackHook(WorldEndBorderKeeper* thisPtr) {
bool isFirstStep = al::isFirstStep(thisPtr);
if (isFirstStep && GameModeManager::instance()->isActive()) {
GameModeBase* mode = GameModeManager::instance()->getMode<GameModeBase>();
if (mode) {
mode->onBorderPullBackFirstStep(thisPtr->mActor);
}
}
return isFirstStep;
}
void drawTableHook(al::ExecuteDirector* thisPtr, const al::ExecuteSystemInitInfo& initInfo) {
thisPtr->mUpdateTableCount = updateTableSize;
thisPtr->mUpdateTables = new al::ExecuteTableHolderUpdate*[thisPtr->mUpdateTableCount]();
for (int i = 0; i < thisPtr->mUpdateTableCount; i++) {
thisPtr->mUpdateTables[i] = new al::ExecuteTableHolderUpdate();
const al::ExecuteTable& curTable = updateTable[i];
// Logger::log("Update Table Name: %s Count: %d\n", curTable.mName, curTable.mExecuteOrderCount);
thisPtr->mUpdateTables[i]->init(curTable.mName, initInfo, curTable.mExecuteOrders, curTable.mExecuteOrderCount);
}
thisPtr->mDrawTableCount = drawTableSize;
thisPtr->mDrawTables = new al::ExecuteTableHolderDraw*[thisPtr->mDrawTableCount]();
for (int i = 0; i < thisPtr->mDrawTableCount; i++) {
thisPtr->mDrawTables[i] = new al::ExecuteTableHolderDraw();
const al::ExecuteTable* curTable = &drawTable[i];
// Logger::log("Draw Table Name: %s Count: %d\n", curTable->mName, curTable->mExecuteOrderCount);
thisPtr->mDrawTables[i]->init(curTable->mName, initInfo, curTable->mExecuteOrders, curTable->mExecuteOrderCount);
}
thisPtr->mRequestKeeper = new al::ExecuteRequestKeeper(thisPtr->mRequestMax);
}
void updateStateHook(al::Scene* scene) {
al::executeUpdateList(scene->mActorKit, "OnlineUpdateExecutors", "PuppetActor");
rs::updateEffectSystemEnv(scene);
}
void updateDrawHook(al::ExecuteDirector* thisPtr, const char* listName, const char* kit) {
thisPtr->drawList("OnlineDrawExecutors", "PuppetActor");
Logger::log("Updating Draw List for: %s %s\n", listName, kit);
thisPtr->drawList(listName, kit);
}