diff options
author | cat_or_not <41955154+catornot@users.noreply.github.com> | 2023-11-05 20:21:50 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-06 02:21:50 +0100 |
commit | bb822b7638d5ae9bc4499ff76edc74f3741e6518 (patch) | |
tree | 558886bd28dc53d1004e235be1c1543c5ec2fd9f /NorthstarDLL | |
parent | 583bae6e1a7e35eec2c5cb4383bc0089f6ee6781 (diff) | |
download | NorthstarLauncher-1.20.0.tar.gz NorthstarLauncher-1.20.0.zip |
Plugins v3 (#472)v1.20.1-rc2v1.20.1-rc1v1.20.0-rc3v1.20.0
- nuked presence logic ( moved to the discord rpc plugin )
- more exposed sq functions
- exposed dll addresses
- `g_pCVar` is exposed
- added "userdata" to plugin's async call
- added runframe to plugins
Diffstat (limited to 'NorthstarDLL')
-rw-r--r-- | NorthstarDLL/CMakeLists.txt | 2 | ||||
-rw-r--r-- | NorthstarDLL/core/convar/concommand.cpp | 4 | ||||
-rw-r--r-- | NorthstarDLL/core/convar/convar.cpp | 10 | ||||
-rw-r--r-- | NorthstarDLL/core/hooks.cpp | 7 | ||||
-rw-r--r-- | NorthstarDLL/dllmain.cpp | 2 | ||||
-rw-r--r-- | NorthstarDLL/engine/hoststate.cpp | 2 | ||||
-rw-r--r-- | NorthstarDLL/plugins/plugin_abi.h | 89 | ||||
-rw-r--r-- | NorthstarDLL/plugins/pluginbackend.cpp | 53 | ||||
-rw-r--r-- | NorthstarDLL/plugins/pluginbackend.h | 4 | ||||
-rw-r--r-- | NorthstarDLL/plugins/plugins.cpp | 16 | ||||
-rw-r--r-- | NorthstarDLL/plugins/plugins.h | 8 | ||||
-rw-r--r-- | NorthstarDLL/shared/gamepresence.cpp | 79 | ||||
-rw-r--r-- | NorthstarDLL/shared/gamepresence.h | 47 | ||||
-rw-r--r-- | NorthstarDLL/squirrel/squirrel.cpp | 29 | ||||
-rw-r--r-- | NorthstarDLL/squirrel/squirrel.h | 2 | ||||
-rw-r--r-- | NorthstarDLL/squirrel/squirrelclasstypes.h | 6 |
16 files changed, 100 insertions, 260 deletions
diff --git a/NorthstarDLL/CMakeLists.txt b/NorthstarDLL/CMakeLists.txt index 54ed1967..5c275887 100644 --- a/NorthstarDLL/CMakeLists.txt +++ b/NorthstarDLL/CMakeLists.txt @@ -124,8 +124,6 @@ add_library(NorthstarDLL SHARED "shared/exploit_fixes/exploitfixes_utf8parser.cpp" "shared/exploit_fixes/ns_limits.cpp" "shared/exploit_fixes/ns_limits.h" - "shared/gamepresence.cpp" - "shared/gamepresence.h" "shared/keyvalues.cpp" "shared/keyvalues.h" "shared/maxplayers.cpp" diff --git a/NorthstarDLL/core/convar/concommand.cpp b/NorthstarDLL/core/convar/concommand.cpp index 732e0d1f..41f54c76 100644 --- a/NorthstarDLL/core/convar/concommand.cpp +++ b/NorthstarDLL/core/convar/concommand.cpp @@ -3,6 +3,7 @@ #include "engine/r2engine.h" #include "plugins/pluginbackend.h" +#include "plugins/plugin_abi.h" #include <iostream> @@ -151,5 +152,6 @@ ON_DLL_LOAD("engine.dll", ConCommand, (CModule module)) ConCommandConstructor = module.Offset(0x415F60).RCast<ConCommandConstructorType>(); AddMiscConCommands(); - g_pPluginCommunicationhandler->m_sEngineData.ConCommandConstructor = (void*)ConCommandConstructor; + g_pPluginCommunicationhandler->m_sEngineData.ConCommandConstructor = + reinterpret_cast<PluginConCommandConstructorType>(ConCommandConstructor); } diff --git a/NorthstarDLL/core/convar/convar.cpp b/NorthstarDLL/core/convar/convar.cpp index 9aaaca66..594989c2 100644 --- a/NorthstarDLL/core/convar/convar.cpp +++ b/NorthstarDLL/core/convar/convar.cpp @@ -4,6 +4,7 @@ #include "core/sourceinterface.h" #include "plugins/pluginbackend.h" +#include "plugins/plugin_abi.h" #include <float.h> @@ -40,10 +41,11 @@ ON_DLL_LOAD("engine.dll", ConVar, (CModule module)) R2::g_pCVarInterface = new SourceInterface<CCvar>("vstdlib.dll", "VEngineCvar007"); R2::g_pCVar = *R2::g_pCVarInterface; - g_pPluginCommunicationhandler->m_sEngineData.conVarMalloc = (void*)conVarMalloc; - g_pPluginCommunicationhandler->m_sEngineData.conVarRegister = (void*)conVarRegister; - g_pPluginCommunicationhandler->m_sEngineData.ConVar_Vtable = (void*)g_pConVar_Vtable; - g_pPluginCommunicationhandler->m_sEngineData.IConVar_Vtable = (void*)g_pIConVar_Vtable; + g_pPluginCommunicationhandler->m_sEngineData.conVarMalloc = reinterpret_cast<PluginConVarMallocType>(conVarMalloc); + g_pPluginCommunicationhandler->m_sEngineData.conVarRegister = reinterpret_cast<PluginConVarRegisterType>(conVarRegister); + g_pPluginCommunicationhandler->m_sEngineData.ConVar_Vtable = reinterpret_cast<void*>(g_pConVar_Vtable); + g_pPluginCommunicationhandler->m_sEngineData.IConVar_Vtable = reinterpret_cast<void*>(g_pIConVar_Vtable); + g_pPluginCommunicationhandler->m_sEngineData.g_pCVar = reinterpret_cast<void*>(R2::g_pCVar); } //----------------------------------------------------------------------------- diff --git a/NorthstarDLL/core/hooks.cpp b/NorthstarDLL/core/hooks.cpp index 4363c0e2..da7f9f3e 100644 --- a/NorthstarDLL/core/hooks.cpp +++ b/NorthstarDLL/core/hooks.cpp @@ -1,4 +1,5 @@ #include "dedicated/dedicated.h" +#include "plugins/pluginbackend.h" #include <iostream> #include <wchar.h> @@ -409,7 +410,10 @@ HMODULE, WINAPI, (LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)) moduleAddress = _LoadLibraryExA(lpLibFileName, hFile, dwFlags); if (moduleAddress) + { CallLoadLibraryACallbacks(lpLibFileName, moduleAddress); + InformPluginsDLLLoad(fs::path(lpLibFileName), moduleAddress); + } return moduleAddress; } @@ -448,7 +452,10 @@ HMODULE, WINAPI, (LPCWSTR lpLibFileName)) HMODULE moduleAddress = _LoadLibraryW(lpLibFileName); if (moduleAddress) + { CallLoadLibraryWCallbacks(lpLibFileName, moduleAddress); + InformPluginsDLLLoad(fs::path(lpLibFileName), moduleAddress); + } return moduleAddress; } diff --git a/NorthstarDLL/dllmain.cpp b/NorthstarDLL/dllmain.cpp index 1a80b3ed..d82c9ffb 100644 --- a/NorthstarDLL/dllmain.cpp +++ b/NorthstarDLL/dllmain.cpp @@ -8,7 +8,6 @@ #include "plugins/pluginbackend.h" #include "util/version.h" #include "squirrel/squirrel.h" -#include "shared/gamepresence.h" #include "server/serverpresence.h" #include "rapidjson/document.h" @@ -61,7 +60,6 @@ bool InitialiseNorthstar() g_pServerPresence = new ServerPresenceManager(); - g_pGameStatePresence = new GameStatePresence(); g_pPluginManager = new PluginManager(); g_pPluginCommunicationhandler = new PluginCommunicationHandler(); g_pPluginManager->LoadPlugins(); diff --git a/NorthstarDLL/engine/hoststate.cpp b/NorthstarDLL/engine/hoststate.cpp index 2ad21fcf..1734a1c3 100644 --- a/NorthstarDLL/engine/hoststate.cpp +++ b/NorthstarDLL/engine/hoststate.cpp @@ -187,7 +187,7 @@ void, __fastcall, (CHostState* self, double flCurrentTime, float flFrameTime)) if (g_pSquirrel<ScriptContext::SERVER>->m_pSQVM != nullptr && g_pSquirrel<ScriptContext::SERVER>->m_pSQVM->sqvm != nullptr) g_pSquirrel<ScriptContext::SERVER>->ProcessMessageBuffer(); - g_pGameStatePresence->RunFrame(); + g_pPluginManager->RunFrame(); } ON_DLL_LOAD_RELIESON("engine.dll", HostState, ConVar, (CModule module)) diff --git a/NorthstarDLL/plugins/plugin_abi.h b/NorthstarDLL/plugins/plugin_abi.h index c9fa9d25..16b26a1c 100644 --- a/NorthstarDLL/plugins/plugin_abi.h +++ b/NorthstarDLL/plugins/plugin_abi.h @@ -1,16 +1,7 @@ #pragma once -#include <string> #include "squirrel/squirrelclasstypes.h" -#define ABI_VERSION 2 - -enum GameState -{ - LOADING = 0, - MAINMENU = 1, - LOBBY = 2, - INGAME = 3 -}; +#define ABI_VERSION 3 enum PluginLoadDLL { @@ -33,6 +24,7 @@ struct SquirrelFunctions sq_compilebufferType __sq_compilebuffer; sq_callType __sq_call; sq_raiseerrorType __sq_raiseerror; + sq_compilefileType __sq_compilefile; sq_newarrayType __sq_newarray; sq_arrayappendType __sq_arrayappend; @@ -48,10 +40,6 @@ struct SquirrelFunctions sq_pushassetType __sq_pushasset; sq_pushvectorType __sq_pushvector; sq_pushobjectType __sq_pushobject; - sq_getthisentityType __sq_getthisentity; - sq_getobjectType __sq_getobject; - - sq_stackinfosType __sq_stackinfos; sq_getstringType __sq_getstring; sq_getintegerType __sq_getinteger; @@ -61,14 +49,22 @@ struct SquirrelFunctions sq_getassetType __sq_getasset; sq_getuserdataType __sq_getuserdata; sq_getvectorType __sq_getvector; + sq_getthisentityType __sq_getthisentity; + sq_getobjectType __sq_getobject; + + sq_stackinfosType __sq_stackinfos; sq_createuserdataType __sq_createuserdata; sq_setuserdatatypeidType __sq_setuserdatatypeid; sq_getfunctionType __sq_getfunction; sq_schedule_call_externalType __sq_schedule_call_external; + sq_getentityfrominstanceType __sq_getentityfrominstance; sq_GetEntityConstantType __sq_GetEntityConstant_CBaseEntity; + + sq_pushnewstructinstanceType __sq_pushnewstructinstance; + sq_sealstructslotType __sq_sealstructslot; }; struct MessageSource @@ -89,9 +85,28 @@ struct LogMsg int pluginHandle; }; -typedef void (*loggerfunc_t)(LogMsg* msg); -typedef void (*PLUGIN_RELAY_INVITE_TYPE)(const char* invite); -typedef void* (*CreateObjectFunc)(ObjectType type); +extern "C" +{ + typedef void (*loggerfunc_t)(LogMsg* msg); + typedef void (*PLUGIN_RELAY_INVITE_TYPE)(const char* invite); + typedef void* (*CreateObjectFunc)(ObjectType type); + + typedef void (*PluginFnCommandCallback_t)(void* command); + typedef void (*PluginConCommandConstructorType)( + void* newCommand, const char* name, PluginFnCommandCallback_t callback, const char* helpString, int flags, void* parent); + typedef void (*PluginConVarRegisterType)( + void* pConVar, + const char* pszName, + const char* pszDefaultValue, + int nFlags, + const char* pszHelpString, + bool bMin, + float fMin, + bool bMax, + float fMax, + void* pCallback); + typedef void (*PluginConVarMallocType)(void* pConVarMaloc, int a2, int a3); +} struct PluginNorthstarData { @@ -109,37 +124,12 @@ struct PluginInitFuncs struct PluginEngineData { - void* ConCommandConstructor; - void* conVarMalloc; - void* conVarRegister; + PluginConCommandConstructorType ConCommandConstructor; + PluginConVarMallocType conVarMalloc; + PluginConVarRegisterType conVarRegister; void* ConVar_Vtable; void* IConVar_Vtable; -}; - -struct PluginGameStatePresence -{ - const char* id; - const char* name; - const char* description; - const char* password; - - bool isServer; - bool isLocal; - GameState state; - - const char* map; - const char* mapDisplayname; - const char* playlist; - const char* playlistDisplayname; - - int currentPlayers; - int maxPlayers; - - int ownScore; - int otherHighestScore; // NOTE: The highest score OR the second highest score if we have the highest - int maxScore; - - int timestampEnd; + void* g_pCVar; }; /// <summary> Async communication within the plugin system @@ -157,8 +147,5 @@ typedef void (*PLUGIN_INIT_SQVM_TYPE)(SquirrelFunctions* funcs); typedef void (*PLUGIN_INFORM_SQVM_CREATED_TYPE)(ScriptContext context, CSquirrelVM* sqvm); typedef void (*PLUGIN_INFORM_SQVM_DESTROYED_TYPE)(ScriptContext context); -// Async Communication types - -// Northstar -> Plugin -typedef void (*PLUGIN_PUSH_PRESENCE_TYPE)(PluginGameStatePresence* data); -typedef void (*PLUGIN_INFORM_DLL_LOAD_TYPE)(PluginLoadDLL dll, void* data); +typedef void (*PLUGIN_INFORM_DLL_LOAD_TYPE)(const char* dll, PluginEngineData* data, void* dllPtr); +typedef void (*PLUGIN_RUNFRAME)(); diff --git a/NorthstarDLL/plugins/pluginbackend.cpp b/NorthstarDLL/plugins/pluginbackend.cpp index f9766235..850394ac 100644 --- a/NorthstarDLL/plugins/pluginbackend.cpp +++ b/NorthstarDLL/plugins/pluginbackend.cpp @@ -7,6 +7,8 @@ #include "core/convar/concommand.h" +#include <filesystem> + #define EXPORT extern "C" __declspec(dllexport) AUTOHOOK_INIT() @@ -36,52 +38,13 @@ void PluginCommunicationHandler::PushRequest(PluginDataRequestType type, PluginR requestQueue.push(PluginDataRequest {type, func}); } -void PluginCommunicationHandler::GeneratePresenceObjects() +void InformPluginsDLLLoad(fs::path dllPath, void* address) { - PluginGameStatePresence presence {}; - - presence.id = g_pGameStatePresence->id.c_str(); - presence.name = g_pGameStatePresence->name.c_str(); - presence.description = g_pGameStatePresence->description.c_str(); - presence.password = g_pGameStatePresence->password.c_str(); - - presence.isServer = g_pGameStatePresence->isServer; - presence.isLocal = g_pGameStatePresence->isLocal; - - if (g_pGameStatePresence->isLoading) - presence.state = GameState::LOADING; - else if (g_pGameStatePresence->uiMap == "") - presence.state = GameState::MAINMENU; - else if (g_pGameStatePresence->map == "mp_lobby" && g_pGameStatePresence->isLocal && g_pGameStatePresence->isLobby) - presence.state = GameState::LOBBY; - else - presence.state = GameState::INGAME; + std::string dllName = dllPath.filename().string(); - presence.map = g_pGameStatePresence->map.c_str(); - presence.mapDisplayname = g_pGameStatePresence->mapDisplayname.c_str(); - presence.playlist = g_pGameStatePresence->playlist.c_str(); - presence.playlistDisplayname = g_pGameStatePresence->playlistDisplayname.c_str(); + void* data = NULL; + if (strncmp(dllName.c_str(), "engine.dll", 10) == 0) + data = &g_pPluginCommunicationhandler->m_sEngineData; - presence.currentPlayers = g_pGameStatePresence->currentPlayers; - presence.maxPlayers = g_pGameStatePresence->maxPlayers; - presence.ownScore = g_pGameStatePresence->ownScore; - presence.otherHighestScore = g_pGameStatePresence->otherHighestScore; - presence.maxScore = g_pGameStatePresence->maxScore; - presence.timestampEnd = g_pGameStatePresence->timestampEnd; - g_pPluginManager->PushPresence(&presence); -} - -ON_DLL_LOAD_RELIESON("engine.dll", PluginBackendEngine, ConCommand, (CModule module)) -{ - g_pPluginManager->InformDLLLoad(PluginLoadDLL::ENGINE, &g_pPluginCommunicationhandler->m_sEngineData); -} - -ON_DLL_LOAD_RELIESON("client.dll", PluginBackendClient, ConCommand, (CModule module)) -{ - g_pPluginManager->InformDLLLoad(PluginLoadDLL::CLIENT, nullptr); -} - -ON_DLL_LOAD_RELIESON("server.dll", PluginBackendServer, ConCommand, (CModule module)) -{ - g_pPluginManager->InformDLLLoad(PluginLoadDLL::SERVER, nullptr); + g_pPluginManager->InformDLLLoad(dllName.c_str(), data, address); } diff --git a/NorthstarDLL/plugins/pluginbackend.h b/NorthstarDLL/plugins/pluginbackend.h index bcbccbd8..fc66a597 100644 --- a/NorthstarDLL/plugins/pluginbackend.h +++ b/NorthstarDLL/plugins/pluginbackend.h @@ -1,6 +1,5 @@ #pragma once #include "plugin_abi.h" -#include "shared/gamepresence.h" #include <queue> #include <mutex> @@ -30,8 +29,6 @@ class PluginCommunicationHandler void RunFrame(); void PushRequest(PluginDataRequestType type, PluginRespondDataCallable func); - void GeneratePresenceObjects(); - public: std::queue<PluginDataRequest> requestQueue = {}; std::mutex requestMutex; @@ -39,4 +36,5 @@ class PluginCommunicationHandler PluginEngineData m_sEngineData {}; }; +void InformPluginsDLLLoad(fs::path dllPath, void* address); extern PluginCommunicationHandler* g_pPluginCommunicationhandler; diff --git a/NorthstarDLL/plugins/plugins.cpp b/NorthstarDLL/plugins/plugins.cpp index 18610e2e..121512e5 100644 --- a/NorthstarDLL/plugins/plugins.cpp +++ b/NorthstarDLL/plugins/plugins.cpp @@ -174,10 +174,10 @@ std::optional<Plugin> PluginManager::LoadPlugin(fs::path path, PluginInitFuncs* plugin.inform_sqvm_created = (PLUGIN_INFORM_SQVM_CREATED_TYPE)GetProcAddress(pluginLib, "PLUGIN_INFORM_SQVM_CREATED"); plugin.inform_sqvm_destroyed = (PLUGIN_INFORM_SQVM_DESTROYED_TYPE)GetProcAddress(pluginLib, "PLUGIN_INFORM_SQVM_DESTROYED"); - plugin.push_presence = (PLUGIN_PUSH_PRESENCE_TYPE)GetProcAddress(pluginLib, "PLUGIN_RECEIVE_PRESENCE"); - plugin.inform_dll_load = (PLUGIN_INFORM_DLL_LOAD_TYPE)GetProcAddress(pluginLib, "PLUGIN_INFORM_DLL_LOAD"); + plugin.run_frame = (PLUGIN_RUNFRAME)GetProcAddress(pluginLib, "PLUGIN_RUNFRAME"); + plugin.handle = m_vLoadedPlugins.size(); plugin.logger = std::make_shared<ColoredLogger>(plugin.displayName.c_str(), NS::Colors::PLUGIN); RegisterLogger(plugin.logger); @@ -298,24 +298,24 @@ void PluginManager::InformSQVMDestroyed(ScriptContext context) } } -void PluginManager::PushPresence(PluginGameStatePresence* data) +void PluginManager::InformDLLLoad(const char* dll, void* data, void* dllPtr) { for (auto plugin : m_vLoadedPlugins) { - if (plugin.push_presence != NULL) + if (plugin.inform_dll_load != NULL) { - plugin.push_presence(data); + plugin.inform_dll_load(dll, (PluginEngineData*)data, dllPtr); } } } -void PluginManager::InformDLLLoad(PluginLoadDLL dll, void* data) +void PluginManager::RunFrame() { for (auto plugin : m_vLoadedPlugins) { - if (plugin.inform_dll_load != NULL) + if (plugin.run_frame != NULL) { - plugin.inform_dll_load(dll, data); + plugin.run_frame(); } } } diff --git a/NorthstarDLL/plugins/plugins.h b/NorthstarDLL/plugins/plugins.h index ffa277d0..d91b2811 100644 --- a/NorthstarDLL/plugins/plugins.h +++ b/NorthstarDLL/plugins/plugins.h @@ -30,8 +30,9 @@ class Plugin PLUGIN_INFORM_SQVM_CREATED_TYPE inform_sqvm_created; PLUGIN_INFORM_SQVM_DESTROYED_TYPE inform_sqvm_destroyed; - PLUGIN_PUSH_PRESENCE_TYPE push_presence; PLUGIN_INFORM_DLL_LOAD_TYPE inform_dll_load; + + PLUGIN_RUNFRAME run_frame; }; class PluginManager @@ -46,9 +47,10 @@ class PluginManager void InformSQVMLoad(ScriptContext context, SquirrelFunctions* s); void InformSQVMCreated(ScriptContext context, CSquirrelVM* sqvm); void InformSQVMDestroyed(ScriptContext context); - void PushPresence(PluginGameStatePresence* data); - void InformDLLLoad(PluginLoadDLL dll, void* data); + void InformDLLLoad(const char* dll, void* data, void* dllPtr); + + void RunFrame(); private: std::string pluginPath; diff --git a/NorthstarDLL/shared/gamepresence.cpp b/NorthstarDLL/shared/gamepresence.cpp deleted file mode 100644 index 11cb7ade..00000000 --- a/NorthstarDLL/shared/gamepresence.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#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; -} diff --git a/NorthstarDLL/shared/gamepresence.h b/NorthstarDLL/shared/gamepresence.h deleted file mode 100644 index 439ec65c..00000000 --- a/NorthstarDLL/shared/gamepresence.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include "server/serverpresence.h" - -class GameStateServerPresenceReporter : public ServerPresenceReporter -{ - void RunFrame(double flCurrentTime, const ServerPresence* pServerPresence); -}; - -class GameStatePresence -{ - public: - std::string id; - std::string name; - std::string description; - std::string password; // NOTE: May be empty - - bool isServer; - bool isLocal = false; - bool isLoading; - bool isLobby; - std::string loadingLevel; - - std::string uiMap; - - std::string map; - std::string mapDisplayname; - std::string playlist; - std::string playlistDisplayname; - - int currentPlayers; - int maxPlayers; - - int ownScore; - int otherHighestScore; // NOTE: The highest score OR the second highest score if we have the highest - int maxScore; - - int timestampEnd; - - GameStatePresence(); - void RunFrame(); - - protected: - GameStateServerPresenceReporter m_GameStateServerPresenceReporter; -}; - -extern GameStatePresence* g_pGameStatePresence; diff --git a/NorthstarDLL/squirrel/squirrel.cpp b/NorthstarDLL/squirrel/squirrel.cpp index 429ef8b0..e43686d7 100644 --- a/NorthstarDLL/squirrel/squirrel.cpp +++ b/NorthstarDLL/squirrel/squirrel.cpp @@ -164,6 +164,7 @@ template <ScriptContext context> void SquirrelManager<context>::GenerateSquirrel s->__sq_compilebuffer = __sq_compilebuffer; s->__sq_call = __sq_call; s->__sq_raiseerror = __sq_raiseerror; + s->__sq_compilefile = __sq_compilefile; s->__sq_newarray = __sq_newarray; s->__sq_arrayappend = __sq_arrayappend; @@ -179,12 +180,8 @@ template <ScriptContext context> void SquirrelManager<context>::GenerateSquirrel s->__sq_pushasset = __sq_pushasset; s->__sq_pushvector = __sq_pushvector; s->__sq_pushobject = __sq_pushobject; - s->__sq_getstring = __sq_getstring; - s->__sq_getthisentity = __sq_getthisentity; - s->__sq_getobject = __sq_getobject; - - s->__sq_stackinfos = __sq_stackinfos; + s->__sq_getstring = __sq_getstring; s->__sq_getinteger = __sq_getinteger; s->__sq_getfloat = __sq_getfloat; s->__sq_getbool = __sq_getbool; @@ -192,24 +189,32 @@ template <ScriptContext context> void SquirrelManager<context>::GenerateSquirrel s->__sq_getasset = __sq_getasset; s->__sq_getuserdata = __sq_getuserdata; s->__sq_getvector = __sq_getvector; + s->__sq_getthisentity = __sq_getthisentity; + s->__sq_getobject = __sq_getobject; + + s->__sq_stackinfos = __sq_stackinfos; + s->__sq_createuserdata = __sq_createuserdata; s->__sq_setuserdatatypeid = __sq_setuserdatatypeid; s->__sq_getfunction = __sq_getfunction; + s->__sq_schedule_call_external = AsyncCall_External; + s->__sq_getentityfrominstance = __sq_getentityfrominstance; s->__sq_GetEntityConstant_CBaseEntity = __sq_GetEntityConstant_CBaseEntity; - s->__sq_schedule_call_external = AsyncCall_External; + s->__sq_pushnewstructinstance = __sq_pushnewstructinstance; + s->__sq_sealstructslot = __sq_sealstructslot; } // Allows for generating squirrelmessages from plugins. -// Not used in this version, but will be used later -void AsyncCall_External(ScriptContext context, const char* func_name, SquirrelMessage_External_Pop function) +void AsyncCall_External(ScriptContext context, const char* func_name, SquirrelMessage_External_Pop function, void* userdata) { SquirrelMessage message {}; message.functionName = func_name; message.isExternal = true; message.externalFunc = function; + message.userdata = userdata; switch (context) { case ScriptContext::CLIENT: @@ -651,9 +656,11 @@ template <ScriptContext context> void SquirrelManager<context>::ProcessMessageBu pushobject(m_pSQVM->sqvm, &functionobj); // Push the function object pushroottable(m_pSQVM->sqvm); - if (message.isExternal) + int argsAmount = message.args.size(); + + if (message.isExternal && message.externalFunc != NULL) { - message.externalFunc(m_pSQVM->sqvm); + argsAmount = message.externalFunc(m_pSQVM->sqvm, message.userdata); } else { @@ -664,7 +671,7 @@ template <ScriptContext context> void SquirrelManager<context>::ProcessMessageBu } } - _call(m_pSQVM->sqvm, message.args.size()); + _call(m_pSQVM->sqvm, argsAmount); } } diff --git a/NorthstarDLL/squirrel/squirrel.h b/NorthstarDLL/squirrel/squirrel.h index 427eb03c..50dd31d0 100644 --- a/NorthstarDLL/squirrel/squirrel.h +++ b/NorthstarDLL/squirrel/squirrel.h @@ -51,7 +51,7 @@ const char* GetContextName_Short(ScriptContext context); eSQReturnType SQReturnTypeFromString(const char* pReturnType); const char* SQTypeNameFromID(const int iTypeId); -void AsyncCall_External(ScriptContext context, const char* func_name, SquirrelMessage_External_Pop function); +void AsyncCall_External(ScriptContext context, const char* func_name, SquirrelMessage_External_Pop function, void* userdata); ScriptContext ScriptContextFromString(std::string string); diff --git a/NorthstarDLL/squirrel/squirrelclasstypes.h b/NorthstarDLL/squirrel/squirrelclasstypes.h index ac813334..c193f2fc 100644 --- a/NorthstarDLL/squirrel/squirrelclasstypes.h +++ b/NorthstarDLL/squirrel/squirrelclasstypes.h @@ -116,8 +116,9 @@ concept is_iterable = requires(std::ranges::range_value_t<T> x) // clang-format on -typedef void (*SquirrelMessage_External_Pop)(HSquirrelVM* sqvm); -typedef void (*sq_schedule_call_externalType)(ScriptContext context, const char* funcname, SquirrelMessage_External_Pop function); +typedef int (*SquirrelMessage_External_Pop)(HSquirrelVM* sqvm, void* userdata); +typedef void (*sq_schedule_call_externalType)( + ScriptContext context, const char* funcname, SquirrelMessage_External_Pop function, void* userdata); class SquirrelMessage { @@ -125,6 +126,7 @@ class SquirrelMessage std::string functionName; FunctionVector args; bool isExternal = false; + void* userdata = NULL; SquirrelMessage_External_Pop externalFunc = NULL; }; |