diff options
author | Emma Miler <emma.pi@protonmail.com> | 2023-04-11 20:49:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-11 20:49:16 +0200 |
commit | 450d0b1ed437cf37b4309af952af8904f3f07768 (patch) | |
tree | 3f0fd39b5663b5c3f4b9e76c70cc4987f22d66c7 /NorthstarDLL/shared/gamepresence.cpp | |
parent | 72da1da5b4c04ccc1154853a308cab6459c60b79 (diff) | |
download | NorthstarLauncher-450d0b1ed437cf37b4309af952af8904f3f07768.tar.gz NorthstarLauncher-450d0b1ed437cf37b4309af952af8904f3f07768.zip |
Plugin system v2 (#343)
* Some work
* Rewrite gamestate presence
* Add plugin system logger
* Format changes
* Format chjange
* Fix gamestate stuff
* some callback stuff
* move around invite stuff
* move invite to funcs
* fix presence server data
* Actually call InformSQVMCreated
* bruh
* Fix TODO's
* Formatting
* Fix filters
* Add InformDLLLoads
* Fix plugin handle always being 0
* Formatting
* Fix merge issues
* Formatting
* Mods can add files compiled at SQVM init
* Some Small Fixes
* Add changes from review
* Fix load failure
* Add new squirrel functions
* actually call InformSQVMDestroyed
* add CreateObject function
* answers to complaints
* remove snake cases from GameStatePresence
---------
Co-authored-by: cat_or_not <41955154+catornot@users.noreply.github.com>
Diffstat (limited to 'NorthstarDLL/shared/gamepresence.cpp')
-rw-r--r-- | NorthstarDLL/shared/gamepresence.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/NorthstarDLL/shared/gamepresence.cpp b/NorthstarDLL/shared/gamepresence.cpp new file mode 100644 index 00000000..86a87526 --- /dev/null +++ b/NorthstarDLL/shared/gamepresence.cpp @@ -0,0 +1,81 @@ +#include "pch.h" + +#include "gamepresence.h" +#include "plugins/pluginbackend.h" +#include "plugins/plugins.h" +#include "dedicated/dedicated.h" +#include "server/serverpresence.h" +#include "masterserver/masterserver.h" +#include "squirrel/squirrel.h" + +GameStatePresence* g_pGameStatePresence; + +GameStatePresence::GameStatePresence() +{ + g_pServerPresence->AddPresenceReporter(&m_GameStateServerPresenceReporter); +} + +void GameStateServerPresenceReporter::RunFrame(double flCurrentTime, const ServerPresence* pServerPresence) +{ + g_pGameStatePresence->id = pServerPresence->m_sServerId; + g_pGameStatePresence->name = pServerPresence->m_sServerName; + g_pGameStatePresence->description = pServerPresence->m_sServerDesc; + g_pGameStatePresence->password = pServerPresence->m_Password; + + g_pGameStatePresence->map = pServerPresence->m_MapName; + g_pGameStatePresence->playlist = pServerPresence->m_PlaylistName; + g_pGameStatePresence->currentPlayers = pServerPresence->m_iPlayerCount; + g_pGameStatePresence->maxPlayers = pServerPresence->m_iMaxPlayers; + + g_pGameStatePresence->isLocal = !IsDedicatedServer(); +} + +void GameStatePresence::RunFrame() +{ + if (g_pSquirrel<ScriptContext::UI>->m_pSQVM != nullptr && g_pSquirrel<ScriptContext::UI>->m_pSQVM->sqvm != nullptr) + g_pSquirrel<ScriptContext::UI>->Call("NorthstarCodeCallback_GenerateUIPresence"); + + if (g_pSquirrel<ScriptContext::CLIENT>->m_pSQVM != nullptr && g_pSquirrel<ScriptContext::CLIENT>->m_pSQVM->sqvm != nullptr) + { + auto test = g_pSquirrel<ScriptContext::CLIENT>->Call("NorthstarCodeCallback_GenerateGameState"); + } + g_pPluginCommunicationhandler->GeneratePresenceObjects(); +} + +ADD_SQFUNC("void", NSPushGameStateData, "GameStateStruct gamestate", "", ScriptContext::CLIENT) +{ + SQStructInstance* structInst = g_pSquirrel<ScriptContext::CLIENT>->m_pSQVM->sqvm->_stackOfCurrentFunction[1]._VAL.asStructInstance; + g_pGameStatePresence->map = structInst->data[0]._VAL.asString->_val; + g_pGameStatePresence->mapDisplayname = structInst->data[1]._VAL.asString->_val; + g_pGameStatePresence->playlist = structInst->data[2]._VAL.asString->_val; + g_pGameStatePresence->playlistDisplayname = structInst->data[3]._VAL.asString->_val; + + g_pGameStatePresence->currentPlayers = structInst->data[4]._VAL.asInteger; + g_pGameStatePresence->maxPlayers = structInst->data[5]._VAL.asInteger; + g_pGameStatePresence->ownScore = structInst->data[6]._VAL.asInteger; + g_pGameStatePresence->otherHighestScore = structInst->data[7]._VAL.asInteger; + g_pGameStatePresence->maxScore = structInst->data[8]._VAL.asInteger; + g_pGameStatePresence->timestampEnd = ceil(structInst->data[9]._VAL.asFloat); + + if (g_pMasterServerManager->m_currentServer) + { + g_pGameStatePresence->id = g_pMasterServerManager->m_currentServer->id; + g_pGameStatePresence->name = g_pMasterServerManager->m_currentServer->name; + g_pGameStatePresence->description = g_pMasterServerManager->m_currentServer->description; + g_pGameStatePresence->password = g_pMasterServerManager->m_sCurrentServerPassword; + } + + return SQRESULT_NOTNULL; +} + +ADD_SQFUNC("void", NSPushUIPresence, "UIPresenceStruct presence", "", ScriptContext::UI) +{ + SQStructInstance* structInst = g_pSquirrel<ScriptContext::UI>->m_pSQVM->sqvm->_stackOfCurrentFunction[1]._VAL.asStructInstance; + + g_pGameStatePresence->isLoading = structInst->data[0]._VAL.asInteger; + g_pGameStatePresence->isLobby = structInst->data[1]._VAL.asInteger; + g_pGameStatePresence->loadingLevel = structInst->data[2]._VAL.asString->_val; + g_pGameStatePresence->uiMap = structInst->data[3]._VAL.asString->_val; + + return SQRESULT_NOTNULL; +} |