From 5cd391a31b9758408f997c0c6d85a4f5f18c8be1 Mon Sep 17 00:00:00 2001 From: Kyle Sanderson Date: Sat, 5 Mar 2016 17:32:16 -0800 Subject: [PATCH] Add SteamWorks_SendMessageToGC (untested as well). --- Extension/AMBuilder | 1 + Extension/extension.cpp | 2 ++ Extension/extension.h | 2 ++ Extension/gcnatives.cpp | 53 ++++++++++++++++++++++++++++++++++++ Extension/gcnatives.h | 36 ++++++++++++++++++++++++ Pawn/includes/SteamWorks.inc | 2 ++ 6 files changed, 96 insertions(+) create mode 100644 Extension/gcnatives.cpp create mode 100644 Extension/gcnatives.h diff --git a/Extension/AMBuilder b/Extension/AMBuilder index 64a0ae4..61c7815 100644 --- a/Extension/AMBuilder +++ b/Extension/AMBuilder @@ -11,6 +11,7 @@ project.sources += [ 'swgshooks.cpp', 'swgsdetours.cpp', 'ssnatives.cpp', + 'gcnatives.cpp', 'swhttp.cpp', 'swhttprequest.cpp', 'swgchooks.cpp', diff --git a/Extension/extension.cpp b/Extension/extension.cpp index b0c2d75..aa6a4e0 100644 --- a/Extension/extension.cpp +++ b/Extension/extension.cpp @@ -56,11 +56,13 @@ bool SteamWorks::SDK_OnLoad(char *error, size_t maxlength, bool late) this->pGSDetours = new SteamWorksGSDetours; this->pSSNatives = new SteamWorksSSNatives; this->pGCHooks = new SteamWorksGCHooks; + this->pGCNatives = new SteamWorksGCNatives; return true; } void SteamWorks::SDK_OnUnload() { + delete this->pGCNatives; delete this->pGCHooks; delete this->pSSNatives; delete this->pGSDetours; diff --git a/Extension/extension.h b/Extension/extension.h index ea96b49..87858fa 100644 --- a/Extension/extension.h +++ b/Extension/extension.h @@ -49,6 +49,7 @@ #include "swgshooks.h" #include "swgchooks.h" #include "ssnatives.h" +#include "gcnatives.h" #include "swgsdetours.h" #include "swhttp.h" @@ -144,6 +145,7 @@ public: SteamWorksHTTP *pSWHTTP; SteamWorksHTTPNatives *pSWHTTPNatives; SteamWorksGCHooks *pGCHooks; + SteamWorksGCNatives *pGCNatives; }; extern SteamWorks g_SteamWorks; diff --git a/Extension/gcnatives.cpp b/Extension/gcnatives.cpp new file mode 100644 index 0000000..7ae0540 --- /dev/null +++ b/Extension/gcnatives.cpp @@ -0,0 +1,53 @@ +/* + 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 . + + Author: Kyle Sanderson (KyleS). +*/ + +#include "gcnatives.h" + +static ISteamGameCoordinator *GetSteamGCPointer(void) +{ + return g_SteamWorks.pSWGameServer->GetGameCoordinator(); +} + +static cell_t sm_GCSendMessage(IPluginContext *pContext, const cell_t *params) +{ + ISteamGameCoordinator *pGC = GetSteamGCPointer(); + if (pGC == NULL) + { + return static_cast(k_EGCResultNotLoggedOn); + } + + char *pData; + pContext->LocalToString(params[2], &pData); + + return static_cast(pGC->SendMessage(params[1], pData, params[3])); +} + +static sp_nativeinfo_t gcnatives[] = { + {"SteamWorks_SendMessageToGC", sm_GCSendMessage}, + {NULL, NULL} +}; + +SteamWorksGCNatives::SteamWorksGCNatives() +{ + sharesys->AddNatives(myself, gcnatives); +} + +SteamWorksGCNatives::~SteamWorksGCNatives() +{ + /* We tragically can't remove ourselves... hopefully no one uses this class, you know, like a class. */ +} diff --git a/Extension/gcnatives.h b/Extension/gcnatives.h new file mode 100644 index 0000000..c1bbe92 --- /dev/null +++ b/Extension/gcnatives.h @@ -0,0 +1,36 @@ +/* + 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 . + + Author: Kyle Sanderson (KyleS). +*/ + +#pragma once +#include "steam_gameserver.h" +#include "isteamgamecoordinator.h" + +#include "smsdk_ext.h" + +#ifdef _WIN32 +#undef SendMessage +#endif + +class SteamWorksGCNatives +{ + public: + SteamWorksGCNatives(); + ~SteamWorksGCNatives(); +}; + +#include "extension.h" \ No newline at end of file diff --git a/Pawn/includes/SteamWorks.inc b/Pawn/includes/SteamWorks.inc index 738d0ff..69461d4 100644 --- a/Pawn/includes/SteamWorks.inc +++ b/Pawn/includes/SteamWorks.inc @@ -299,6 +299,8 @@ forward EGCResults:SteamWorks_GCSendMessage(unMsgType, const String:pubData[], c forward SteamWorks_GCMsgAvailable(cubData); forward EGCResults:SteamWorks_GCRetreiveMessage(punMsgType, const String:pubDest[], cubDest, pcubMsgSize); +native EGCResults:SteamWorks_SendMessageToGC(unMsgType, const String:pubData[], cubData); + public Extension:__ext_SteamWorks = { name = "SteamWorks",