Skip to content

Commit

Permalink
Merge pull request #116 from alliedmodders/🍿
Browse files Browse the repository at this point in the history
Update/improve Source 2 support
  • Loading branch information
psychonic committed Sep 28, 2023
2 parents b5846d1 + 6196318 commit 4401a94
Show file tree
Hide file tree
Showing 77 changed files with 10,998 additions and 13,649 deletions.
23 changes: 15 additions & 8 deletions AMBuildScript
Expand Up @@ -34,7 +34,7 @@ CSGO = {
'mac': ['x86_64']
}
Source2 = {
'windows': ['x86', 'x86_64'],
'windows': ['x86_64'],
'linux': ['x86_64'],
}
Insurgency = {
Expand Down Expand Up @@ -73,7 +73,6 @@ PossibleSDKs = {
'eye': SDK('HL2SDK-EYE', '2.eye', '5', 'EYE', WinOnly, 'eye'),
'mcv': SDK('HL2SDKMCV', '2.mcv', '22', 'MCV', MCV, 'mcv'),
'csgo': SDK('HL2SDKCSGO', '2.csgo', '23', 'CSGO', CSGO, 'csgo'),
'dota': SDK('HL2SDKDOTA', '2.dota', '24', 'DOTA', [], 'dota'),
'portal2': SDK('HL2SDKPORTAL2', '2.portal2', '18', 'PORTAL2', [], 'portal2'),
'blade': SDK('HL2SDKBLADE', '2.blade', '19', 'BLADE', Blade, 'blade'),
'insurgency': SDK('HL2SDKINSURGENCY', '2.insurgency', '20', 'INSURGENCY', Insurgency, 'insurgency'),
Expand All @@ -82,6 +81,8 @@ PossibleSDKs = {
'bms': SDK('HL2SDKBMS', '2.bms', '11', 'BMS', WinLinux, 'bms'),
'mock': SDK('HL2SDK-MOCK', '2.mock', '999', 'MOCK', Mock, 'mock'),
'pvkii': SDK('HL2SDKPVKII', '2.pvkii', '10', 'PVKII', WinLinux, 'pvkii'),
'dota': SDK('HL2SDKDOTA', '2.dota', '24', 'DOTA', Source2, 'dota'),
'cs2': SDK('HL2SDKCS2', '2.cs2', '25', 'CS2', Source2, 'cs2'),
}

def ResolveEnvPath(env, folder):
Expand Down Expand Up @@ -394,13 +395,15 @@ class MMSConfig(object):
if compiler.target.arch == 'x86_64':
compiler.defines += ['X64BITS', 'PLATFORM_64BITS']

if sdk.name in ['css', 'hl2dm', 'dods', 'sdk2013', 'bms', 'tf2', 'l4d', 'nucleardawn', 'l4d2', 'dota', 'pvkii']:
if sdk.name in ['css', 'hl2dm', 'dods', 'sdk2013', 'bms', 'tf2', 'l4d', 'nucleardawn', 'l4d2', 'dota', 'cs2', 'pvkii']:
if compiler.target.platform in ['linux', 'mac']:
compiler.defines += ['NO_HOOK_MALLOC', 'NO_MALLOC_OVERRIDE']

if sdk.name in ['csgo', 'blade', 'pvkii'] and compiler.target.platform == 'linux':
compiler.linkflags += ['-lstdc++']

if sdk.name in ['dota', 'cs2']:
compiler.defines += ['META_IS_SOURCE2']

for path in paths:
compiler.cxxincludes += [os.path.join(sdk.path, *path)]
Expand Down Expand Up @@ -476,7 +479,7 @@ class MMSConfig(object):
compiler.linkflags += ['-Wl,-z,origin']
compiler.postlink += [tier1]

if sdk.name in ['blade', 'insurgency', 'doi', 'csgo', 'dota']:
if sdk.name in ['blade', 'insurgency', 'doi', 'csgo', 'cs2', 'dota']:
if compiler.target.arch == 'x86_64':
compiler.postlink += [os.path.join(lib_folder, 'interfaces.a')]
else:
Expand All @@ -495,8 +498,10 @@ class MMSConfig(object):
dynamic_libs = ['libtier0_srv.so', 'libvstdlib_srv.so']
elif compiler.target.arch == 'x86_64' and sdk.name in ['csgo', 'mock']:
dynamic_libs = ['libtier0_client.so', 'libvstdlib_client.so']
elif sdk.name in ['l4d', 'blade', 'insurgency', 'doi', 'csgo', 'dota', 'pvkii', 'mcv']:
dynamic_libs = ['libtier0.so', 'libvstdlib.so']
elif sdk.name in ['l4d', 'blade', 'insurgency', 'doi', 'csgo', 'cs2', 'dota', 'pvkii', 'mcv']:
dynamic_libs = ['libtier0.so']
if sdk.name not in ['dota', 'cs2']:
dynamic_libs += ['libvstdlib.so']
else:
dynamic_libs = ['tier0_i486.so', 'vstdlib_i486.so']
if sdk.name in ['csgo', 'blade']:
Expand All @@ -505,8 +510,10 @@ class MMSConfig(object):
binary.compiler.linkflags.append('-liconv')
dynamic_libs = ['libtier0.dylib', 'libvstdlib.dylib']
elif compiler.target.platform == 'windows':
libs = ['tier0', 'tier1', 'vstdlib']
if sdk.name in ['swarm', 'blade', 'insurgency', 'doi', 'mcv', 'csgo', 'dota']:
libs = ['tier0', 'tier1']
if sdk.name not in ['dota', 'cs2']:
libs += ['vstdlib']
if sdk.name in ['swarm', 'blade', 'insurgency', 'doi', 'mcv', 'csgo', 'cs2', 'dota']:
libs.append('interfaces')
if sdk.name == 'bms':
libs.append('mathlib')
Expand Down
19 changes: 15 additions & 4 deletions core/AMBuilder
Expand Up @@ -17,17 +17,28 @@ for sdk_name in MMS.sdks:
'metamod_oslink.cpp',
'metamod_plugins.cpp',
'metamod_util.cpp',
'provider/console.cpp',
'provider/provider_ep2.cpp',
'provider/provider_base.cpp',
'sourcehook/sourcehook.cpp',
'sourcehook/sourcehook_impl_chookidman.cpp',
'sourcehook/sourcehook_impl_chookmaninfo.cpp',
'sourcehook/sourcehook_impl_cproto.cpp',
'sourcehook/sourcehook_impl_cvfnptr.cpp',
'gamedll_bridge.cpp',
'vsp_bridge.cpp'
'gamedll_bridge.cpp'
]

if sdk_name in ['dota', 'cs2']:
binary.sources += [
'provider/source2/provider_source2.cpp',
os.path.join(sdk.path, 'tier1', 'convar.cpp'),
os.path.join(sdk.path, 'public', 'tier0', 'memoverride.cpp')
]
else:
binary.sources += [
'provider/source/provider_source.cpp',
'provider/source/provider_source_console.cpp',
'vsp_bridge.cpp'
]

# Source2 hack. TODO: check this more deterministically, "are we doing an x64 build?"
if binary.compiler.target.arch == 'x86':
binary.sources += ['sourcehook/sourcehook_hookmangen.cpp']
Expand Down
10 changes: 9 additions & 1 deletion core/ISmmAPI.h
Expand Up @@ -53,6 +53,14 @@ class ConCommandBase;
#define MMIFACE_SH_HOOKMANAUTOGEN "IHookManagerAutoGen" /**< SourceHook::IHookManagerAutoGen Pointer */
#define IFACE_MAXNUM 999 /**< Maximum interface version */

#if defined META_IS_SOURCE2
typedef CPlayerSlot MMSPlayer_t;
static const MMSPlayer_t MMSPlayer_INVALID = CPlayerSlot(-1);
#else
typedef edict_t* MMSPlayer_t;
static const MMSPlayer_t MMSPlayer_INVALID = nullptr;
#endif

typedef void* (*CreateInterfaceFn)(const char *pName, int *pReturnCode);

class IServerPluginCallbacks;
Expand Down Expand Up @@ -255,7 +263,7 @@ namespace SourceMM
* @param client Client edict pointer.
* @param fmt Formatted string to print to the client.
*/
virtual void ClientConPrintf(edict_t *client, const char *fmt, ...) =0;
virtual void ClientConPrintf(MMSPlayer_t client, const char *fmt, ...) =0;

/**
* @brief Wrapper around InterfaceSearch(). Assumes no maximum.
Expand Down
2 changes: 1 addition & 1 deletion core/ISmmPlugin.h
Expand Up @@ -40,7 +40,7 @@
#include <ISmmPluginExt.h>

#ifndef META_NO_HL2SDK
#if SOURCE_ENGINE == SE_DOTA
#if META_IS_SOURCE2
#include <interfaces/interfaces.h>
#else
#include <tier1/interface.h>
Expand Down
1 change: 1 addition & 0 deletions core/ISmmPluginExt.h
Expand Up @@ -63,6 +63,7 @@
#define SOURCE_ENGINE_MOCK 25 /**< Mock source engine */
#define SOURCE_ENGINE_PVKII 26 /**< Pirates, Vikings, and Knights II */
#define SOURCE_ENGINE_MCV 27 /**< Military Conflict: Vietnam */
#define SOURCE_ENGINE_CS2 28 /**< Counter-Strike 2 */

#define METAMOD_PLAPI_VERSION 16 /**< Version of this header file */
#define METAMOD_PLAPI_NAME "ISmmPlugin" /**< Name of the plugin interface */
Expand Down
183 changes: 0 additions & 183 deletions core/Makefile

This file was deleted.

7 changes: 4 additions & 3 deletions core/gamedll_bridge.cpp
Expand Up @@ -28,7 +28,7 @@
#include "metamod_plugins.h"
#include "metamod_util.h"
#include <loader_bridge.h>
#include "provider/provider_ep2.h"
#include "provider/provider_base.h"

using namespace SourceMM;

Expand All @@ -38,7 +38,8 @@ class GameDllBridge : public IGameDllBridge
virtual bool DLLInit_Pre(const gamedll_bridge_info *info, char *buffer, size_t maxlength)
{
server = (IServerGameDLL *) info->isgd;
g_Metamod.SetGameDLLInfo((CreateInterfaceFn) info->gsFactory,
g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory,
info->dllInterfaceName,
info->dllVersion,
true);
g_Metamod.SetVSPListener(info->vsp_listener_path);
Expand All @@ -63,7 +64,7 @@ class GameDllBridge : public IGameDllBridge
SourceHook::MemFuncInfo mfi;

mfi.isVirtual = false;
#if SOURCE_ENGINE == SE_DOTA
#ifdef META_IS_SOURCE2
SourceHook::GetFuncInfo(&IServerGameDLL::Shutdown, mfi);
#else
SourceHook::GetFuncInfo(&IServerGameDLL::DLLShutdown, mfi);
Expand Down

0 comments on commit 4401a94

Please sign in to comment.