Files
SM-SteamWorks/Extension/swgsdetours.cpp
T
A1m` a86fc4af91 Fix circular includes and include cleanup (#3)
* Fix circular includes and include cleanup

Fixed a bug where other *.h header files would include extension.h, which itself
was already included in those same headers, creating a circular dependency cycle.
This caused build errors and made compilation unpredictable.

To resolve this:
- Moved implementation-only includes to .cpp files where they are actually needed.
- Added forward declarations where possible to avoid pulling in unnecessary headers.
- Ensured extension.h only contains declarations that require full type definitions.

This improves build stability and compilation time.

* Clean up includes and fix build errors

- Replaced full includes with forward declarations where possible
- Moved implementation-only includes from .h to .cpp files
- Added missing includes for stdint.h and Steam interfaces
- This significantly reduces compilation time and prevents future dependency issues

* Switch to SourceMod SDK smsdk_ext instead of local copy
2026-07-13 21:43:05 +00:00

126 lines
3.5 KiB
C++

/*
This file is part of SourcePawn SteamWorks.
SourcePawn SteamWorks is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, as per version 3 of the License.
SourcePawn SteamWorks 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 SourcePawn SteamWorks. If not, see <http://www.gnu.org/licenses/>.
Author: Kyle Sanderson (KyleS).
*/
#include "swgsdetours.h"
#include "extension.h"
#include "swgameserver.h"
#include "swgshooks.h"
#include "swgamedata.h"
#include <steam_gameserver.h>
DETOUR_DECL_STATIC0(SteamAPIShutdown, void)
{
if (g_SteamWorks.pSWGameServer != NULL)
{
if (g_SteamWorks.pGSHooks != NULL)
{
g_SteamWorks.pGSHooks->RemoveHooks(g_SteamWorks.pSWGameServer->GetGameServer(), false);
}
g_SteamWorks.pSWGameServer->Reset();
}
DETOUR_STATIC_CALL(SteamAPIShutdown)(); /* We're not a monster. */
}
DETOUR_DECL_STATIC6(SteamGameServer_InitSafeDetour, bool, uint32, unIP, uint16, usSteamPort, uint16, usGamePort, uint16, usQueryPort, EServerMode, eServerMode, const char *, pchVersionString)
{
bool bRet = DETOUR_STATIC_CALL(SteamGameServer_InitSafeDetour)(unIP, usSteamPort, usGamePort, usQueryPort, eServerMode, pchVersionString); /* Call to init game interfaces. */
if (g_SteamWorks.pSWGameServer != NULL && g_SteamWorks.pGSHooks != NULL)
{
g_SteamWorks.pGSHooks->AddHooks(g_SteamWorks.pSWGameServer->GetGameServer());
}
return bRet;
}
SteamWorksGSDetours::SteamWorksGSDetours()
{
const char *pLibSteamPath = g_SteamWorks.pSWGameServer->GetLibraryPath();
void *pSteamSafeInitAddress = NULL;
void *pSteamShutdownAddress = NULL;
const char *pInitSafeFuncName = "SteamGameServer_InitSafe";
const char *pShutdownFuncName = "SteamGameServer_Shutdown";
IGameConfig *pConfig = NULL;
if (g_SteamWorks.pSWGameData)
{
pConfig = g_SteamWorks.pSWGameData->GetGameData();
if (pConfig != NULL)
{
pConfig->GetMemSig(pShutdownFuncName, &pSteamShutdownAddress);
pConfig->GetMemSig(pInitSafeFuncName, &pSteamSafeInitAddress);
}
}
ILibrary *pLibrary = libsys->OpenLibrary(pLibSteamPath, NULL, 0);
if (pLibrary != NULL)
{
if (pSteamShutdownAddress == NULL)
{
pSteamShutdownAddress = pLibrary->GetSymbolAddress(pShutdownFuncName);
}
if (pSteamSafeInitAddress == NULL)
{
pSteamSafeInitAddress = pLibrary->GetSymbolAddress(pInitSafeFuncName);
}
pLibrary->CloseLibrary();
}
CDetourManager::Init(g_pSM->GetScriptingEngine(), pConfig);
if (pSteamShutdownAddress != NULL)
{
this->m_pShutdownDetour = DETOUR_CREATE_STATIC_FIXED(SteamAPIShutdown, pSteamShutdownAddress);
this->m_pShutdownDetour->EnableDetour();
}
else
{
this->m_pShutdownDetour = NULL;
}
if (pSteamSafeInitAddress != NULL)
{
this->m_pSafeInitDetour = DETOUR_CREATE_STATIC_FIXED(SteamGameServer_InitSafeDetour, pSteamSafeInitAddress);
this->m_pSafeInitDetour->EnableDetour();
}
else
{
this->m_pSafeInitDetour = NULL;
}
}
SteamWorksGSDetours::~SteamWorksGSDetours()
{
if (this->m_pShutdownDetour != NULL)
{
this->m_pShutdownDetour->Destroy();
this->m_pShutdownDetour = NULL;
}
if (this->m_pSafeInitDetour != NULL)
{
this->m_pSafeInitDetour->Destroy();
this->m_pSafeInitDetour = NULL;
}
}