diff --git a/core/AMBuilder b/core/AMBuilder index a956833..9d0790e 100644 --- a/core/AMBuilder +++ b/core/AMBuilder @@ -17,7 +17,6 @@ for sdk_name in MMS.sdks: 'metamod_oslink.cpp', 'metamod_plugins.cpp', 'metamod_util.cpp', - 'provider/console.cpp', 'provider/provider_base.cpp', 'sourcehook/sourcehook.cpp', 'sourcehook/sourcehook_impl_chookidman.cpp', @@ -31,7 +30,10 @@ for sdk_name in MMS.sdks: if sdk_name in ['dota', 'cs2']: binary.sources += ['provider/source2/provider_source2.cpp'] else: - binary.sources += ['provider/source/provider_source.cpp'] + binary.sources += [ + 'provider/source/provider_source.cpp', + 'provider/source/provider_source_console.cpp' + ] # Source2 hack. TODO: check this more deterministically, "are we doing an x64 build?" if binary.compiler.target.arch == 'x86': diff --git a/core/provider/console.h b/core/provider/console.h deleted file mode 100644 index dbae221..0000000 --- a/core/provider/console.h +++ /dev/null @@ -1,55 +0,0 @@ -/** - * vim: set ts=4 : - * ====================================================== - * Metamod:Source - * Copyright (C) 2004-2008 AlliedModders LLC and authors. - * All rights reserved. - * ====================================================== - * - * This software is provided 'as-is', without any express or implied warranty. - * In no event will the authors be held liable for any damages arising from - * the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software in a - * product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - * - * Version: $Id$ - */ - -#ifndef _INCLUDE_CONSOLE_MMS_H_ -#define _INCLUDE_CONSOLE_MMS_H_ - -#include -#include "convar.h" -#include -#include - -class SMConVarAccessor : public IConCommandBaseAccessor -{ -public: - bool RegisterConCommandBase(ConCommandBase *pCommand); - bool Register(ConCommandBase *pCommand); - void Unregister(ConCommandBase *pCommand); - void RemoveMetamodCommands(); -#if SOURCE_ENGINE < SE_ORANGEBOX - bool InitConCommandBaseList(); -private: - ConCommandBase **m_TopConCommandBase; -#endif -private: - SourceHook::List m_RegisteredCommands; -}; - -extern SMConVarAccessor g_SMConVarAccessor; - -#endif //_INCLUDE_CONSOLE_MMS_H_ - diff --git a/core/provider/provider_base.cpp b/core/provider/provider_base.cpp index c60f317..0776190 100644 --- a/core/provider/provider_base.cpp +++ b/core/provider/provider_base.cpp @@ -32,7 +32,6 @@ #include #include "../metamod_util.h" #include "provider_base.h" -#include "console.h" #include "metamod_console.h" #include #include "metamod.h" diff --git a/core/provider/source/provider_source.cpp b/core/provider/source/provider_source.cpp index a376caa..cef0a7c 100644 --- a/core/provider/source/provider_source.cpp +++ b/core/provider/source/provider_source.cpp @@ -24,7 +24,6 @@ */ #include "provider_source.h" -#include "../console.h" #include #include #include @@ -99,7 +98,7 @@ void SourceProvider::Notify_DLLInit_Pre(CreateInterfaceFn engineFactory, g_pCVar = icvar; #endif - g_SMConVarAccessor.RegisterConCommandBase(&meta_local_cmd); + m_ConVarAccessor.RegisterConCommandBase(&meta_local_cmd); #if SOURCE_ENGINE == SE_EPISODEONE /* The Ship is the only game known at this time that uses the pre-Episode One engine */ @@ -133,7 +132,7 @@ void SourceProvider::Notify_DLLShutdown_Pre() SH_REMOVE_HOOK(IServerGameDLL, LevelInit, server, SH_MEMBER(this, &SourceProvider::Hook_LevelInit), true); SH_REMOVE_HOOK(IServerGameDLL, LevelShutdown, server, SH_MEMBER(this, &SourceProvider::Hook_LevelShutdown), true); - g_SMConVarAccessor.RemoveMetamodCommands(); + m_ConVarAccessor.RemoveMetamodCommands(); #if SOURCE_ENGINE < SE_ORANGEBOX if (g_Metamod.IsLoadedAsGameDLL()) @@ -362,17 +361,17 @@ bool SourceProvider::IsConCommandBaseACommand(ConCommandBase* pCommand) IConCommandBaseAccessor* SourceProvider::GetConCommandBaseAccessor() { - return &g_SMConVarAccessor; + return &m_ConVarAccessor; } bool SourceProvider::RegisterConCommandBase(ConCommandBase* pCommand) { - return g_SMConVarAccessor.Register(pCommand); + return m_ConVarAccessor.Register(pCommand); } void SourceProvider::UnregisterConCommandBase(ConCommandBase* pCommand) { - return g_SMConVarAccessor.Unregister(pCommand); + return m_ConVarAccessor.Unregister(pCommand); } ConVar* SourceProvider::CreateConVar(const char* name, @@ -392,7 +391,7 @@ ConVar* SourceProvider::CreateConVar(const char* name, ConVar* pVar = new ConVar(name, defval, newflags, help); - g_SMConVarAccessor.RegisterConCommandBase(pVar); + m_ConVarAccessor.RegisterConCommandBase(pVar); return pVar; } diff --git a/core/provider/source/provider_source.h b/core/provider/source/provider_source.h index 267e8fd..67951aa 100644 --- a/core/provider/source/provider_source.h +++ b/core/provider/source/provider_source.h @@ -31,10 +31,11 @@ #include "../provider_base.h" #include #include +#include class SourceProvider : public BaseProvider { -public: +public: // BaseProvider virtual void Notify_DLLInit_Pre(CreateInterfaceFn engineFactory, CreateInterfaceFn serverFactory) override; virtual void Notify_DLLShutdown_Pre() override; virtual bool ProcessVDF(const char* file, char path[], size_t path_len, char alias[], size_t alias_len) override; @@ -58,7 +59,25 @@ public: virtual int GetUserMessageCount() override; virtual int FindUserMessage(const char* name, int* size = nullptr) override; virtual const char* GetUserMessage(int index, int* size = nullptr) override; -public: // Hook callbacks that map to provider callbacks +public: // IConCommandBaseAccessor + class SourceConVarAccessor : public IConCommandBaseAccessor + { + virtual bool RegisterConCommandBase(ConCommandBase* pCommand) override; + private: + bool Register(ConCommandBase* pCommand); + void Unregister(ConCommandBase* pCommand); + void RemoveMetamodCommands(); +#if SOURCE_ENGINE < SE_ORANGEBOX + bool InitConCommandBaseList(); + private: + ConCommandBase** m_TopConCommandBase = nullptr; +#endif + private: + SourceHook::List m_RegisteredCommands; + + friend class SourceProvider; + } m_ConVarAccessor; +public: bool Hook_GameInit(); bool Hook_LevelInit(char const* pMapName, char const* pMapEntities, char const* pOldLevel, char const* pLandmarkName, bool loadGame, bool background); diff --git a/core/provider/console.cpp b/core/provider/source/provider_source_console.cpp similarity index 85% rename from core/provider/console.cpp rename to core/provider/source/provider_source_console.cpp index f75a081..c3dbaa6 100644 --- a/core/provider/console.cpp +++ b/core/provider/source/provider_source_console.cpp @@ -25,20 +25,14 @@ * Version: $Id$ */ -#include "console.h" -#include "provider_base.h" -#include "metamod_util.h" - -using namespace SourceHook; - -SMConVarAccessor g_SMConVarAccessor; +#include "provider_source.h" #if SOURCE_ENGINE >= SE_ORANGEBOX #else #define RegisterConCommand RegisterConCommandBase #endif -bool SMConVarAccessor::RegisterConCommandBase(ConCommandBase *pCommand) +bool SourceProvider::SourceConVarAccessor::RegisterConCommandBase(ConCommandBase *pCommand) { m_RegisteredCommands.push_back(pCommand); #if SOURCE_ENGINE < SE_ALIENSWARM @@ -49,7 +43,7 @@ bool SMConVarAccessor::RegisterConCommandBase(ConCommandBase *pCommand) return true; } -bool SMConVarAccessor::Register(ConCommandBase *pCommand) +bool SourceProvider::SourceConVarAccessor::Register(ConCommandBase *pCommand) { #if SOURCE_ENGINE < SE_ALIENSWARM pCommand->SetNext(NULL); @@ -59,7 +53,7 @@ bool SMConVarAccessor::Register(ConCommandBase *pCommand) return true; } -void SMConVarAccessor::RemoveMetamodCommands() +void SourceProvider::SourceConVarAccessor::RemoveMetamodCommands() { List::iterator iter; @@ -73,7 +67,7 @@ void SMConVarAccessor::RemoveMetamodCommands() /* Signature for ICvar::GetCommands() in vstdlib for Win32 and Linux. * * 20226EE0 A1 50 5C 5A 20 mov eax,dword ptr ds:[205A5C50h] <-- What we want - * 20226EE5 C3 ret + * 20226EE5 C3 ret */ #define CMDLIST_SIG "\xA1\x2A\x2A\x2A\x2A\xC3" #define CMDLIST_SIGLEN 6 @@ -87,7 +81,7 @@ void SMConVarAccessor::RemoveMetamodCommands() * This craziness eliminates the need for the eternal command/cvar used previously which * could have caused a crash as a result of registering commands/cvars more than once. */ -bool SMConVarAccessor::InitConCommandBaseList() +bool SourceProvider::SourceConVarAccessor::InitConCommandBaseList() { char *vfunc = (char *)SH_GET_ORIG_VFNPTR_ENTRY(icvar, &ICvar::GetCommands); @@ -96,7 +90,7 @@ bool SMConVarAccessor::InitConCommandBaseList() /* Get address from displacement... * * Add 5 because it's relative to next instruction: - * Opcode <1 byte> + 32-bit displacement <4 bytes> + * Opcode <1 byte> + 32-bit displacement <4 bytes> */ vfunc += *reinterpret_cast(vfunc + 1) + 5; } @@ -140,7 +134,7 @@ bool SMConVarAccessor::InitConCommandBaseList() } #endif -void SMConVarAccessor::Unregister(ConCommandBase *pCommand) +void SourceProvider::SourceConVarAccessor::Unregister(ConCommandBase *pCommand) { #if SOURCE_ENGINE >= SE_ORANGEBOX icvar->UnregisterConCommand(pCommand); @@ -166,7 +160,7 @@ void SMConVarAccessor::Unregister(ConCommandBase *pCommand) pCommand->SetNext(NULL); return; } - + pPrev = pCur; pCur = const_cast(pCur->GetNext()); @@ -183,4 +177,3 @@ void SMConVarAccessor::Unregister(ConCommandBase *pCommand) } #endif } - diff --git a/core/provider/source2/provider_source2.cpp b/core/provider/source2/provider_source2.cpp index 88d88fb..76c80ff 100644 --- a/core/provider/source2/provider_source2.cpp +++ b/core/provider/source2/provider_source2.cpp @@ -24,7 +24,6 @@ */ #include "provider_source2.h" -#include "../console.h" #include #include #include @@ -122,7 +121,9 @@ void Source2Provider::Notify_DLLInit_Pre(CreateInterfaceFn engineFactory, g_pCVar = icvar; +#ifdef S2_CONVAR_UNFINISHED g_SMConVarAccessor.RegisterConCommandBase(&meta_local_cmd); +#endif if (gameclients) { @@ -139,7 +140,9 @@ void Source2Provider::Notify_DLLInit_Pre(CreateInterfaceFn engineFactory, void Source2Provider::Notify_DLLShutdown_Pre() { +#ifdef S2_CONVAR_UNFINISHED g_SMConVarAccessor.RemoveMetamodCommands(); +#endif } bool Source2Provider::ProcessVDF(const char* file, char path[], size_t path_len, char alias[], size_t alias_len) @@ -241,37 +244,57 @@ void Source2Provider::ServerCommand(const char* cmd) const char* Source2Provider::GetConVarString(ConVar* convar) { +#ifdef S2_CONVAR_UNFINISHED if (convar == NULL) { return NULL; } return convar->GetString(); +#else + return ""; +#endif } void Source2Provider::SetConVarString(ConVar* convar, const char* str) { +#ifdef S2_CONVAR_UNFINISHED convar->SetValue(str); +#endif } bool Source2Provider::IsConCommandBaseACommand(ConCommandBase* pCommand) { +#ifdef S2_CONVAR_UNFINISHED return pCommand->IsCommand(); +#else + return false; +#endif } IConCommandBaseAccessor* Source2Provider::GetConCommandBaseAccessor() { +#ifdef S2_CONVAR_UNFINISHED return &g_SMConVarAccessor; +#else + return nullptr; +#endif } bool Source2Provider::RegisterConCommandBase(ConCommandBase* pCommand) { +#ifdef S2_CONVAR_UNFINISHED return g_SMConVarAccessor.Register(pCommand); +#else + return true; +#endif } void Source2Provider::UnregisterConCommandBase(ConCommandBase* pCommand) { +#ifdef S2_CONVAR_UNFINISHED return g_SMConVarAccessor.Unregister(pCommand); +#endif } ConVar* Source2Provider::CreateConVar(const char* name, @@ -279,6 +302,7 @@ ConVar* Source2Provider::CreateConVar(const char* name, const char* help, int flags) { +#ifdef S2_CONVAR_UNFINISHED int newflags = 0; if (flags & ConVarFlag_Notify) { @@ -294,6 +318,9 @@ ConVar* Source2Provider::CreateConVar(const char* name, g_SMConVarAccessor.RegisterConCommandBase(pVar); return pVar; +#else + return nullptr; +#endif } class GlobCommand : public IMetamodSourceCommandInfo