diff --git a/AMBuilder b/AMBuilder index 46a42d7..c2a6c80 100644 --- a/AMBuilder +++ b/AMBuilder @@ -39,6 +39,7 @@ for sdk_target in MMSPlugin.sdk_targets: binary.compiler.cxxincludes += [ os.path.join(builder.sourcePath, 'src', 'cs2_sdk'), os.path.join(builder.sourcePath, 'src', 'utils'), + os.path.join(builder.sourcePath, 'public'), os.path.join(builder.sourcePath, 'vendor', 'funchook', 'include'), ] diff --git a/public/imultiaddonmanager.h b/public/imultiaddonmanager.h new file mode 100644 index 0000000..6a7d278 --- /dev/null +++ b/public/imultiaddonmanager.h @@ -0,0 +1,41 @@ +/** + * ============================================================================= + * MultiAddonManager + * Copyright (C) 2024 xen + * ============================================================================= + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, version 3.0, as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#pragma once + +#define MULTIADDONMANAGER_INTERFACE "MultiAddonManager001" + +class IMultiAddonManager +{ +public: + // These add/remove to the internal list without reloading anything + // pszWorkshopID is the workshop ID in string form (e.g. "3157463861") + virtual bool AddAddon(const char *pszWorkshopID) = 0; + virtual bool RemoveAddon(const char *pszWorkshopID) = 0; + + // Returns true if the given addon is mounted in the filesystem + virtual bool IsAddonMounted(const char *pszWorkshopID) = 0; + + // Refresh addons, applying any changes from add/remove + // This will trigger a map reload once all addons are updated and mounted + virtual void RefreshAddons() = 0; + + // Clear the internal list and unmount all addons excluding the current workshop map + virtual void ClearAddons() = 0; +}; diff --git a/src/multiaddonmanager.cpp b/src/multiaddonmanager.cpp index 2b582f5..21050d2 100644 --- a/src/multiaddonmanager.cpp +++ b/src/multiaddonmanager.cpp @@ -117,6 +117,9 @@ INetworkGameServer *g_pNetworkGameServer = nullptr; CSteamGameServerAPIContext g_SteamAPI; CGlobalVars *gpGlobals = nullptr; +// Interface to other plugins +CAddonManagerInterface g_AddonManagerInterface; + PLUGIN_EXPOSE(MultiAddonManager, g_MultiAddonManager); bool MultiAddonManager::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late) { @@ -227,6 +230,19 @@ bool MultiAddonManager::Unload(char *error, size_t maxlen) return true; } +void *MultiAddonManager::OnMetamodQuery(const char *iface, int *ret) +{ + if (V_strcmp(iface, MULTIADDONMANAGER_INTERFACE)) + { + if (ret) + *ret = META_IFACE_FAILED; + + return nullptr; + } + + return &g_AddonManagerInterface; +} + void MultiAddonManager::BuildAddonPath(const char *pszAddon, char *buf, size_t len) { // The workshop is stored relative to the working directory for whatever reason @@ -449,6 +465,8 @@ bool MultiAddonManager::AddAddon(const char *pszAddon, bool bRefresh = false) if (bRefresh) RefreshAddons(); + + return true; } bool MultiAddonManager::RemoveAddon(const char *pszAddon, bool bRefresh = false) @@ -771,3 +789,28 @@ const char *MultiAddonManager::GetURL() { return "https://github.com/Source2ZE/MultiAddonManager"; } + +bool CAddonManagerInterface::AddAddon(const char *pszAddon) +{ + return g_MultiAddonManager.AddAddon(pszAddon); +} + +bool CAddonManagerInterface::RemoveAddon(const char *pszAddon) +{ + return g_MultiAddonManager.RemoveAddon(pszAddon); +} + +bool CAddonManagerInterface::IsAddonMounted(const char *pszAddon) +{ + return g_MultiAddonManager.m_MountedAddons.Find(pszAddon) != -1; +} + +void CAddonManagerInterface::RefreshAddons() +{ + g_MultiAddonManager.RefreshAddons(true); +} + +void CAddonManagerInterface::ClearAddons() +{ + g_MultiAddonManager.ClearAddons(); +} \ No newline at end of file diff --git a/src/multiaddonmanager.h b/src/multiaddonmanager.h index 16fd992..75161b5 100644 --- a/src/multiaddonmanager.h +++ b/src/multiaddonmanager.h @@ -26,6 +26,7 @@ #include "utlvector.h" #include "steam/steam_api_common.h" #include "steam/isteamugc.h" +#include "imultiaddonmanager.h" #ifdef _WIN32 #define ROOTBIN "/bin/win64/" @@ -70,6 +71,7 @@ class MultiAddonManager : public ISmmPlugin, public IMetamodListener public: bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late); bool Unload(char *error, size_t maxlen); + void *OnMetamodQuery(const char *iface, int *ret); public: //hooks void Hook_GameServerSteamAPIActivated(); void Hook_StartupServer(const GameSessionConfiguration_t &config, ISource2WorldSession *, const char *); @@ -113,3 +115,14 @@ class MultiAddonManager : public ISmmPlugin, public IMetamodListener extern MultiAddonManager g_MultiAddonManager; PLUGIN_GLOBALVARS(); + +// Interface to other plugins +class CAddonManagerInterface : IMultiAddonManager +{ +public: + virtual bool AddAddon(const char *pszAddon) override; + virtual bool RemoveAddon(const char *pszAddon) override; + virtual bool IsAddonMounted(const char *pszAddon) override; + virtual void RefreshAddons() override; + virtual void ClearAddons() override; +};