Add and enable SteamWorks GS Detours (+CDetour).

This commit is contained in:
KyleSanderson
2014-01-14 17:54:32 -07:00
parent 54b9500974
commit a39fdfc731
5 changed files with 127 additions and 1 deletions
+7 -1
View File
@@ -25,8 +25,13 @@ PROJECT = SteamWorks
#Uncomment for Metamod: Source enabled extension
#USEMETA = true
USESH = true
USECD = true
OBJECTS = sdk/smsdk_ext.cpp extension.cpp swgameserver.cpp swgamedata.cpp swforwards.cpp gsnatives.cpp swgshooks.cpp ssnatives.cpp
OBJECTS = sdk/smsdk_ext.cpp extension.cpp swgameserver.cpp swgamedata.cpp swforwards.cpp gsnatives.cpp swgshooks.cpp swgsdetours.cpp ssnatives.cpp
ifeq "$(USECD)" "true"
OBJECTS += CDetour/detours.cpp asm/asm.c
endif
##############################################
### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
@@ -218,6 +223,7 @@ $(BIN_DIR)/%.o: %.cpp
all: check
mkdir -p $(BIN_DIR)/sdk
mkdir -p $(BIN_DIR)/CDetour
if [ "$(USEMETA)" = "true" ]; then \
ln -sf $(HL2LIB)/$(LIB_PREFIX)vstdlib$(LIB_SUFFIX); \
ln -sf $(HL2LIB)/$(LIB_PREFIX)tier0$(LIB_SUFFIX); \
+2
View File
@@ -48,6 +48,7 @@ bool SteamWorks::SDK_OnLoad(char *error, size_t maxlength, bool late)
this->pSWForward = new SteamWorksForwards;
this->pGSNatives = new SteamWorksGSNatives;
this->pGSHooks = new SteamWorksGSHooks;
this->pGSDetours = new SteamWorksGSDetours;
this->pSSNatives = new SteamWorksSSNatives;
return true;
}
@@ -55,6 +56,7 @@ bool SteamWorks::SDK_OnLoad(char *error, size_t maxlength, bool late)
void SteamWorks::SDK_OnUnload()
{
delete this->pSSNatives;
delete this->pGSDetours;
delete this->pGSHooks;
delete this->pGSNatives;
delete this->pSWForward;
+2
View File
@@ -48,6 +48,7 @@
#include "gsnatives.h"
#include "swgshooks.h"
#include "ssnatives.h"
#include "swgsdetours.h"
/**
* @brief Sample implementation of the SDK Extension.
@@ -136,6 +137,7 @@ public:
SteamWorksGSNatives *pGSNatives;
SteamWorksGSHooks *pGSHooks;
SteamWorksSSNatives *pSSNatives;
SteamWorksGSDetours *pGSDetours;
};
extern SteamWorks g_SteamWorks;
+81
View File
@@ -0,0 +1,81 @@
/*
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, either version 3 of the License, or
(at your option) any later version.
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"
DETOUR_DECL_STATIC0(SteamAPIShutdown, void)
{
DETOUR_STATIC_CALL(SteamAPIShutdown)(); /* We're not a monster. */
if (g_SteamWorks.pSWGameServer == NULL)
{
return;
}
g_SteamWorks.pSWGameServer->Reset();
}
SteamWorksGSDetours::SteamWorksGSDetours()
{
#if defined POSIX
const char *pLibSteamPath = "./bin/libsteam_api.so";
#elif defined WIN32_LEAN_AND_MEAN
const char *pLibSteamPath = "./bin/steam_api.dll"; /* Naming from SteamTools. */
#endif
IGameConfig *pConfig = NULL;
if (g_SteamWorks.pSWGameData)
{
pConfig = g_SteamWorks.pSWGameData->GetGameData();
if (pConfig)
{
pLibSteamPath = pConfig->GetKeyValue("LibSteamAPI");
}
}
ILibrary *pLibrary = libsys->OpenLibrary(pLibSteamPath, NULL, 0);
void *pAddress = NULL;
if (pLibrary != NULL)
{
const char *pFunctionName = "SteamGameServer_Shutdown";
pAddress = pLibrary->GetSymbolAddress(pFunctionName);
pLibrary->CloseLibrary();
}
if (pAddress == NULL)
{
this->m_pShutdownDetour = NULL;
return;
}
CDetourManager::Init(g_pSM->GetScriptingEngine(), pConfig);
this->m_pShutdownDetour = DETOUR_CREATE_STATIC_FIXED(SteamAPIShutdown, pAddress);
if (this->m_pShutdownDetour != NULL)
{
this->m_pShutdownDetour->EnableDetour();
}
}
SteamWorksGSDetours::~SteamWorksGSDetours()
{
if (this->m_pShutdownDetour != NULL)
{
this->m_pShutdownDetour->Destroy();
this->m_pShutdownDetour = NULL;
}
}
+35
View File
@@ -0,0 +1,35 @@
/*
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, either version 3 of the License, or
(at your option) any later version.
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).
*/
#pragma once
#include "smsdk_ext.h"
#include "steam_gameserver.h"
#include "CDetour/detours.h"
class SteamWorksGSDetours
{
public:
SteamWorksGSDetours();
~SteamWorksGSDetours();
private:
CDetour *m_pShutdownDetour;
};
#include "extension.h"