Skip to content

Commit 8e32084

Browse files
authored
Build extension against new TF2 sdk, add safetyhook as detour backend (#63)
1 parent 7da7e90 commit 8e32084

File tree

14 files changed

+46
-1041
lines changed

14 files changed

+46
-1041
lines changed

.github/workflows/ci-extension.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ jobs:
3535
# We currently only support tf2 - however when we support more sdks
3636
# we will have to deal with the special case of our custom tf2 + AM's sdks
3737
SDKS: '["tf2"]'
38-
MMSOURCE_VERSION: '1.10'
39-
SOURCEMOD_VERSION: '1.11'
38+
MMSOURCE_VERSION: '1.11'
39+
SOURCEMOD_VERSION: '1.12'
4040
CACHE_PATH: ${{ github.workspace }}/cache
4141
steps:
4242

4343
- uses: actions/checkout@v4
4444
name: Repository checkout
4545
with:
4646
fetch-depth: 0
47+
submodules: true
4748
path: CBaseNPC
4849

4950
- uses: actions/checkout@v4
@@ -71,7 +72,7 @@ jobs:
7172
- uses: actions/checkout@v4
7273
name: Custom TF2 SDK checkout
7374
with:
74-
repository: TF2-DMB/hl2sdk-tf2
75+
repository: alliedmodders/hl2sdk
7576
ref: tf2
7677
path: cache/hl2sdk-tf2
7778

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "third_party/safetyhook"]
2+
path = third_party/safetyhook
3+
url = [email protected]:alliedmodders/safetyhook.git

AMBuildScript

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class ExtensionConfig(object):
9999
self.smapi_path = None
100100
self.all_targets = []
101101
self.target_archs = set()
102+
self.libsafetyhook = {}
102103

103104
if self.build_extension():
104105
if builder.options.targets:
@@ -265,8 +266,6 @@ class ExtensionConfig(object):
265266
# Platform-specifics
266267
if cxx.target.platform == 'linux':
267268
self.configure_linux(cxx)
268-
elif cxx.target.platform == 'mac':
269-
self.configure_mac(cxx)
270269
elif cxx.target.platform == 'windows':
271270
self.configure_windows(cxx)
272271

@@ -283,10 +282,6 @@ class ExtensionConfig(object):
283282

284283
def configure_gcc(self, cxx):
285284
cxx.defines += [
286-
'stricmp=strcasecmp',
287-
'_stricmp=strcasecmp',
288-
'_snprintf=snprintf',
289-
'_vsnprintf=vsnprintf',
290285
'typeof=__typeof__',
291286
'HAVE_STDINT_H',
292287
'GNUC',
@@ -299,8 +294,9 @@ class ExtensionConfig(object):
299294
'-Wno-unused',
300295
'-Wno-switch',
301296
'-Wno-array-bounds',
297+
'-Wno-implicit-exception-spec-mismatch',
298+
'-Wno-dangling-else',
302299
'-msse',
303-
'-m32',
304300
'-fvisibility=hidden',
305301
]
306302
cxx.cxxflags += [
@@ -387,7 +383,7 @@ class ExtensionConfig(object):
387383
]
388384

389385
if builder.options.opt == '1':
390-
cxx.cflags += ['/Ox', '/Zo', '-O3']
386+
cxx.cflags += ['/Ox', '/Zo']
391387
cxx.linkflags += ['/OPT:ICF', '/OPT:REF']
392388

393389
if builder.options.debug == '1':
@@ -398,28 +394,28 @@ class ExtensionConfig(object):
398394
cxx.cflags += ['/Oy-']
399395

400396
def configure_linux(self, cxx):
401-
cxx.defines += ['_LINUX', 'POSIX']
397+
cxx.defines += ['_LINUX', 'POSIX', 'LINUX']
402398
cxx.linkflags += ['-Wl,--exclude-libs,ALL', '-lm']
403399
if cxx.vendor == 'gcc':
404400
cxx.linkflags += ['-static-libgcc']
405401
elif cxx.vendor == 'clang':
406402
cxx.linkflags += ['-lgcc_eh']
407403
cxx.linkflags += ['-static-libstdc++']
408-
409-
def configure_mac(self, cxx):
410-
cxx.defines += ['OSX', '_OSX', 'POSIX']
411-
cxx.cflags += ['-mmacosx-version-min=10.7']
412-
cxx.linkflags += [
413-
'-mmacosx-version-min=10.7',
414-
'-arch', 'i386',
415-
'-lstdc++',
416-
'-stdlib=libstdc++',
417-
]
418-
cxx.cxxflags += ['-stdlib=libstdc++']
404+
cxx.cflags += ["-march=pentium4", "-march=core2", "-msse2", "-mfpmath=sse"]
419405

420406
def configure_windows(self, cxx):
421407
cxx.defines += ['WIN32', '_WINDOWS']
422408

409+
def AddCDetour(self, binary):
410+
binary.sources += [ os.path.join(self.sm_root, 'public', 'CDetour', 'detours.cpp') ]
411+
binary.compiler.cxxincludes += [ os.path.join(builder.sourcePath, 'third_party', 'safetyhook', 'include') ]
412+
413+
for task in self.libsafetyhook:
414+
if task.target.arch == binary.compiler.target.arch:
415+
binary.compiler.linkflags += [task.binary]
416+
return
417+
raise Exception('No suitable build of safetyhook was found.')
418+
423419
def ConfigureForExtension(self, context, compiler):
424420
compiler.cxxincludes += [
425421
os.path.join(context.currentSourcePath),
@@ -464,13 +460,6 @@ class ExtensionConfig(object):
464460

465461
compiler.defines += ['SOURCE_ENGINE=' + sdk.code]
466462

467-
if sdk.name in ['tf2', 'sdk2013', 'bms'] and compiler.like('gcc'):
468-
# The 2013 SDK already has these in public/tier0/basetypes.h
469-
compiler.defines.remove('stricmp=strcasecmp')
470-
compiler.defines.remove('_stricmp=strcasecmp')
471-
compiler.defines.remove('_snprintf=snprintf')
472-
compiler.defines.remove('_vsnprintf=vsnprintf')
473-
474463
if compiler.like('msvc'):
475464
compiler.defines += ['COMPILER_MSVC']
476465
if compiler.target.arch == 'x86':
@@ -509,7 +498,7 @@ class ExtensionConfig(object):
509498
elif compiler.target.arch == 'x86_64':
510499
lib_folder = os.path.join(sdk.path, 'lib', 'linux64')
511500
else:
512-
lib_folder = os.path.join(sdk.path, 'lib', 'linux')
501+
lib_folder = os.path.join(sdk.path, 'lib', 'public', 'linux')
513502
elif compiler.target.platform == 'mac':
514503
if sdk.name in ['sdk2013', 'bms']:
515504
lib_folder = os.path.join(sdk.path, 'lib', 'public', 'osx32')
@@ -555,9 +544,9 @@ class ExtensionConfig(object):
555544
libs.append('interfaces')
556545
for lib in libs:
557546
if compiler.target.arch == 'x86':
558-
lib_path = os.path.join(sdk.path, 'lib', 'public', lib) + '.lib'
547+
lib_path = os.path.join(sdk.path, 'lib', 'public', 'x86', lib) + '.lib'
559548
elif compiler.target.arch == 'x86_64':
560-
lib_path = os.path.join(sdk.path, 'lib', 'public', 'win64', lib) + '.lib'
549+
lib_path = os.path.join(sdk.path, 'lib', 'public', 'x64', lib) + '.lib'
561550
compiler.linkflags.append(lib_path)
562551

563552
for library in dynamic_libs:
@@ -617,6 +606,17 @@ if Extension.build_extension():
617606
Extension.detectSDKs()
618607
Extension.configure()
619608

609+
class SafetyHookShim(object):
610+
def __init__(self):
611+
self.all_targets = {}
612+
self.libsafetyhook = {}
613+
614+
if Extension.build_extension():
615+
SafetyHook = SafetyHookShim()
616+
SafetyHook.all_targets = Extension.all_targets
617+
builder.Build(os.path.join('third_party/safetyhook/AMBuilder'), {'SafetyHook': SafetyHook })
618+
Extension.libsafetyhook = SafetyHook.libsafetyhook
619+
620620
if Extension.use_auto_versioning():
621621
Extension.generated_headers = builder.Build(
622622
'tools/Versioning',

extension/AMBuilder

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ project.sources = [
1212
'pluginentityfactory.cpp',
1313
'toolsnav_mesh.cpp',
1414
'toolsnextbot.cpp',
15-
'CDetour/detours.cpp',
16-
'asm/asm.c',
1715
'helpers.cpp',
1816
'sourcesdk/NextBot/Path/NextBotPath.cpp',
1917
'sourcesdk/NextBot/Path/NextBotPathFollow.cpp',
@@ -69,7 +67,7 @@ project.sources = [
6967
'natives/nextbotplayer.cpp',
7068
'natives/tf/nav.cpp',
7169
'natives/tf/nav/area.cpp',
72-
'smsdk_ext.cpp'
70+
os.path.join(Extension.sm_root, 'public', 'smsdk_ext.cpp')
7371
]
7472

7573
for sdk_name in Extension.sdks:
@@ -80,6 +78,7 @@ for sdk_name in Extension.sdks:
8078
continue
8179

8280
binary = Extension.HL2ExtConfig(project, builder, cxx, 'cbasenpc.ext.' + sdk.ext, sdk)
81+
Extension.AddCDetour(binary)
8382
binary.compiler.cxxincludes += [
8483
os.path.join(builder.currentSourcePath, 'sourcesdk'),
8584
os.path.join(builder.currentSourcePath, 'sourcesdk/NextBot'),

extension/CDetour/detourhelpers.h

Lines changed: 0 additions & 99 deletions
This file was deleted.

0 commit comments

Comments
 (0)