[mod menu] new: option to hide server in debug menu

- Client.hpp: add bool variable and methods
- hooks.cpp: save/load value from common.bin
- main.cpp: change
- StageSceneStateServerConfig: add button to the mod menu to toggle it
This commit is contained in:
Robin C. Ladiges 2024-05-29 09:12:45 +02:00
parent e1bd6d8785
commit 65582aafea
No known key found for this signature in database
GPG key ID: B494D3DF92661B99
5 changed files with 64 additions and 25 deletions

View file

@ -30,7 +30,8 @@ class StageSceneStateServerConfig : public al::HostStateBase<al::Scene>, public
GAMEMODECONFIG, GAMEMODECONFIG,
GAMEMODESWITCH, GAMEMODESWITCH,
SETIP, SETIP,
SETPORT SETPORT,
HIDESERVER
}; };
virtual al::MessageSystem* getMessageSystem(void) const override; virtual al::MessageSystem* getMessageSystem(void) const override;
@ -41,6 +42,7 @@ class StageSceneStateServerConfig : public al::HostStateBase<al::Scene>, public
void exeMainMenu(); void exeMainMenu();
void exeOpenKeyboardIP(); void exeOpenKeyboardIP();
void exeOpenKeyboardPort(); void exeOpenKeyboardPort();
void exeHideServer();
void exeGamemodeConfig(); void exeGamemodeConfig();
void exeGamemodeSelect(); void exeGamemodeSelect();
void exeSaveData(); void exeSaveData();
@ -79,6 +81,11 @@ class StageSceneStateServerConfig : public al::HostStateBase<al::Scene>, public
inline void activateInput(); inline void activateInput();
inline void deactivateInput(); inline void deactivateInput();
// Main Menu Options
static constexpr int mMainMenuOptionsCount = 5;
sead::SafeArray<sead::WFixedSafeString<0x200>, mMainMenuOptionsCount>* mMainMenuOptions = nullptr;
const sead::WFixedSafeString<0x200>* getMainMenuOptions();
bool mIsDecideConfig = false; bool mIsDecideConfig = false;
}; };
@ -86,6 +93,7 @@ namespace {
NERVE_HEADER(StageSceneStateServerConfig, MainMenu) NERVE_HEADER(StageSceneStateServerConfig, MainMenu)
NERVE_HEADER(StageSceneStateServerConfig, OpenKeyboardIP) NERVE_HEADER(StageSceneStateServerConfig, OpenKeyboardIP)
NERVE_HEADER(StageSceneStateServerConfig, OpenKeyboardPort) NERVE_HEADER(StageSceneStateServerConfig, OpenKeyboardPort)
NERVE_HEADER(StageSceneStateServerConfig, HideServer)
NERVE_HEADER(StageSceneStateServerConfig, GamemodeConfig) NERVE_HEADER(StageSceneStateServerConfig, GamemodeConfig)
NERVE_HEADER(StageSceneStateServerConfig, GamemodeSelect) NERVE_HEADER(StageSceneStateServerConfig, GamemodeSelect)
NERVE_HEADER(StageSceneStateServerConfig, SaveData) NERVE_HEADER(StageSceneStateServerConfig, SaveData)

View file

@ -131,7 +131,7 @@ class Client {
static sead::Heap *getClientHeap() { return sInstance ? sInstance->mHeap : nullptr; } static sead::Heap *getClientHeap() { return sInstance ? sInstance->mHeap : nullptr; }
static int getMaxPlayerCount() { return sInstance ? sInstance->maxPuppets + 1 : 10;} static int getMaxPlayerCount() { return sInstance ? sInstance->maxPuppets + 1 : 10; }
static const int getCurrentPort(); static const int getCurrentPort();
@ -151,6 +151,10 @@ class Client {
static const char* getCurrentIP(); static const char* getCurrentIP();
static bool isServerHidden() { return sInstance ? sInstance->mServerHidden : true; }
static void setServerHidden(bool hide) { if (sInstance) { sInstance->mServerHidden = hide; } }
static void toggleServerHidden() { if (sInstance) { sInstance->mServerHidden = !sInstance->mServerHidden; } }
static nn::account::Uid getClientId() { return sInstance ? sInstance->mUserID : nn::account::Uid::EmptyId;} static nn::account::Uid getClientId() { return sInstance ? sInstance->mUserID : nn::account::Uid::EmptyId;}
static sead::FixedSafeString<0x20> getUsername() { return sInstance ? sInstance->mUsername : sead::FixedSafeString<0x20>::cEmptyString;} static sead::FixedSafeString<0x20> getUsername() { return sInstance ? sInstance->mUsername : sead::FixedSafeString<0x20>::cEmptyString;}
@ -239,8 +243,8 @@ class Client {
Keyboard* mKeyboard = nullptr; // keyboard for setting server IP Keyboard* mKeyboard = nullptr; // keyboard for setting server IP
hostname mServerIP; hostname mServerIP;
int mServerPort = 0; int mServerPort = 0;
bool mServerHidden = false;
bool waitForGameInit = true; bool waitForGameInit = true;
bool mIsFirstConnect = true; bool mIsFirstConnect = true;

View file

@ -37,6 +37,7 @@ void saveWriteHook(al::ByamlWriter* saveByml) {
const char *serverIP = Client::getCurrentIP(); const char *serverIP = Client::getCurrentIP();
const int serverPort = Client::getCurrentPort(); const int serverPort = Client::getCurrentPort();
const bool serverHidden = Client::isServerHidden();
if (serverIP) { if (serverIP) {
saveByml->addString("ServerIP", serverIP); saveByml->addString("ServerIP", serverIP);
@ -50,6 +51,8 @@ void saveWriteHook(al::ByamlWriter* saveByml) {
saveByml->addInt("ServerPort", 0); saveByml->addInt("ServerPort", 0);
} }
saveByml->addBool("ServerHidden", serverHidden);
saveByml->pop(); saveByml->pop();
} }
@ -57,6 +60,7 @@ bool saveReadHook(int* padRumbleInt, al::ByamlIter const& saveByml, char const*
const char *serverIP = ""; const char *serverIP = "";
int serverPort = 0; int serverPort = 0;
bool serverHidden = false;
if (al::tryGetByamlString(&serverIP, saveByml, "ServerIP")) { if (al::tryGetByamlString(&serverIP, saveByml, "ServerIP")) {
Client::setLastUsedIP(serverIP); Client::setLastUsedIP(serverIP);
@ -66,6 +70,10 @@ bool saveReadHook(int* padRumbleInt, al::ByamlIter const& saveByml, char const*
Client::setLastUsedPort(serverPort); Client::setLastUsedPort(serverPort);
} }
if (al::tryGetByamlBool(&serverHidden, saveByml, "ServerHidden")) {
Client::setServerHidden(serverHidden);
}
return al::tryGetByamlS32(padRumbleInt, saveByml, padRumbleKey); return al::tryGetByamlS32(padRumbleInt, saveByml, padRumbleKey);
} }

View file

@ -113,19 +113,19 @@ void drawMainHook(HakoniwaSequence *curSequence, sead::Viewport *viewport, sead:
gTextWriter->setCursorFromTopLeft(sead::Vector2f(10.f, (dispHeight / 3) + 30.f)); gTextWriter->setCursorFromTopLeft(sead::Vector2f(10.f, (dispHeight / 3) + 30.f));
gTextWriter->setScaleFromFontHeight(20.f); gTextWriter->setScaleFromFontHeight(20.f);
if (isConnected) { if (Client::isServerHidden()) {
gTextWriter->printf( gTextWriter->printf(
"Server: %s:%d | %d/%d Players\n", isConnected ? "Server: <hidden> | %d/%d Players\n" : "Server: <hidden>\n",
socket->getIP(), isConnected ? Client::getConnectCount() + 1 : 0,
socket->getPort(), isConnected ? Client::getMaxPlayerCount() : 0
Client::getConnectCount() + 1,
Client::getMaxPlayerCount()
); );
} else { } else {
gTextWriter->printf( gTextWriter->printf(
"Server: %s:%d\n", isConnected ? "Server: %s:%d | %d/%d Players\n" : "Server: %s:%d\n",
socket->getIP(), socket->getIP(),
socket->getPort() socket->getPort(),
isConnected ? Client::getConnectCount() + 1 : 0,
isConnected ? Client::getMaxPlayerCount() : 0
); );
} }
gTextWriter->printf("Your TCP status: %s\n", socket->getStateChar()); gTextWriter->printf("Your TCP status: %s\n", socket->getStateChar());

View file

@ -41,17 +41,16 @@ StageSceneStateServerConfig::StageSceneStateServerConfig(const char *name, al::S
mMainOptionsList->unkInt1 = 1; mMainOptionsList->unkInt1 = 1;
mMainOptionsList->initDataNoResetSelected(4); mMainOptionsList->initDataNoResetSelected(mMainMenuOptionsCount);
sead::SafeArray<sead::WFixedSafeString<0x200>, 4>* mainMenuOptions = mMainMenuOptions = new sead::SafeArray<sead::WFixedSafeString<0x200>, mMainMenuOptionsCount>();
new sead::SafeArray<sead::WFixedSafeString<0x200>, 4>(); mMainMenuOptions->mBuffer[ServerConfigOption::GAMEMODECONFIG].copy(u"Gamemode Config");
mMainMenuOptions->mBuffer[ServerConfigOption::GAMEMODESWITCH].copy(u"Change Gamemode");
mMainMenuOptions->mBuffer[ServerConfigOption::SETIP].copy(u"Change Server IP");
mMainMenuOptions->mBuffer[ServerConfigOption::SETPORT].copy(u"Change Server Port");
mMainMenuOptions->mBuffer[ServerConfigOption::HIDESERVER].copy(u"Hide Server in Debug (OFF)"); // TBD
mainMenuOptions->mBuffer[ServerConfigOption::GAMEMODECONFIG].copy(u"Gamemode Config"); mMainOptionsList->addStringData(getMainMenuOptions(), "TxtContent");
mainMenuOptions->mBuffer[ServerConfigOption::GAMEMODESWITCH].copy(u"Change Gamemode");
mainMenuOptions->mBuffer[ServerConfigOption::SETIP].copy(u"Change Server IP");
mainMenuOptions->mBuffer[ServerConfigOption::SETPORT].copy(u"Change Server Port");
mMainOptionsList->addStringData(mainMenuOptions->mBuffer, "TxtContent");
// WIP work on RollPartsData, not exactly working out atm // WIP work on RollPartsData, not exactly working out atm
// RollPartsData* testArr = new RollPartsData[2](); // RollPartsData* testArr = new RollPartsData[2]();
@ -176,6 +175,10 @@ void StageSceneStateServerConfig::exeMainMenu() {
al::setNerve(this, &nrvStageSceneStateServerConfigOpenKeyboardPort); al::setNerve(this, &nrvStageSceneStateServerConfigOpenKeyboardPort);
break; break;
} }
case ServerConfigOption::HIDESERVER: {
al::setNerve(this, &nrvStageSceneStateServerConfigHideServer);
break;
}
default: default:
kill(); kill();
break; break;
@ -221,6 +224,16 @@ void StageSceneStateServerConfig::exeOpenKeyboardPort() {
} }
} }
void StageSceneStateServerConfig::exeHideServer() {
if (al::isFirstStep(this)) {
Client::toggleServerHidden();
mMainOptionsList->initDataNoResetSelected(mMainMenuOptionsCount);
mMainOptionsList->addStringData(getMainMenuOptions(), "TxtContent");
mMainOptionsList->updateParts();
al::setNerve(this, &nrvStageSceneStateServerConfigSaveData);
}
}
void StageSceneStateServerConfig::exeGamemodeConfig() { void StageSceneStateServerConfig::exeGamemodeConfig() {
if (al::isFirstStep(this)) { if (al::isFirstStep(this)) {
mGamemodeConfigMenu = &mGamemodeConfigMenus[GameModeManager::instance()->getGameMode()]; mGamemodeConfigMenu = &mGamemodeConfigMenus[GameModeManager::instance()->getGameMode()];
@ -347,10 +360,16 @@ void StageSceneStateServerConfig::deactivateInput() {
mIsDecideConfig = true; mIsDecideConfig = true;
} }
const sead::WFixedSafeString<0x200>* StageSceneStateServerConfig::getMainMenuOptions() {
mMainMenuOptions->mBuffer[ServerConfigOption::HIDESERVER].copy(Client::isServerHidden() ? u"Hide Server in Debug (ON) " : u"Hide Server in Debug (OFF)");
return mMainMenuOptions->mBuffer;
}
namespace { namespace {
NERVE_IMPL(StageSceneStateServerConfig, MainMenu) NERVE_IMPL(StageSceneStateServerConfig, MainMenu)
NERVE_IMPL(StageSceneStateServerConfig, OpenKeyboardIP) NERVE_IMPL(StageSceneStateServerConfig, OpenKeyboardIP)
NERVE_IMPL(StageSceneStateServerConfig, OpenKeyboardPort) NERVE_IMPL(StageSceneStateServerConfig, OpenKeyboardPort)
NERVE_IMPL(StageSceneStateServerConfig, HideServer)
NERVE_IMPL(StageSceneStateServerConfig, GamemodeConfig) NERVE_IMPL(StageSceneStateServerConfig, GamemodeConfig)
NERVE_IMPL(StageSceneStateServerConfig, GamemodeSelect) NERVE_IMPL(StageSceneStateServerConfig, GamemodeSelect)
NERVE_IMPL(StageSceneStateServerConfig, SaveData) NERVE_IMPL(StageSceneStateServerConfig, SaveData)