Skip to content

Commit

Permalink
Add plugin interface
Browse files Browse the repository at this point in the history
  • Loading branch information
xen-000 committed Mar 4, 2024
1 parent 2b16f0e commit dacb860
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
]

Expand Down
41 changes: 41 additions & 0 deletions public/imultiaddonmanager.h
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

#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;
};
43 changes: 43 additions & 0 deletions src/multiaddonmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
13 changes: 13 additions & 0 deletions src/multiaddonmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down Expand Up @@ -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 *);
Expand Down Expand Up @@ -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;
};

0 comments on commit dacb860

Please sign in to comment.