From f829cd6fe9380fb1aea34d701d7912689a514ecd Mon Sep 17 00:00:00 2001 From: Kenzzer Date: Mon, 7 Oct 2024 21:53:48 +0200 Subject: [PATCH 1/2] Setup x64 --- .gitmodules | 3 + AMBuildScript | 661 ++++++++-------------- build.bat | 7 - configure.py | 25 +- extension/AMBuilder | 42 +- extension/extension.hpp | 51 +- extension/msvc10/tf2items.vcxproj | 128 ----- extension/msvc10/tf2items.vcxproj.filters | 38 -- extension/msvc10/tf2items.vcxproj.user | 3 - hl2sdk-manifests | 1 + tf2.items.txt | 7 +- 11 files changed, 298 insertions(+), 668 deletions(-) create mode 100644 .gitmodules delete mode 100644 build.bat delete mode 100644 extension/msvc10/tf2items.vcxproj delete mode 100644 extension/msvc10/tf2items.vcxproj.filters delete mode 100644 extension/msvc10/tf2items.vcxproj.user create mode 160000 hl2sdk-manifests diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..fce44cc --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "hl2sdk-manifests"] + path = hl2sdk-manifests + url = https://github.com/alliedmodders/hl2sdk-manifests.git diff --git a/AMBuildScript b/AMBuildScript index 53e0245..da3698b 100644 --- a/AMBuildScript +++ b/AMBuildScript @@ -1,429 +1,232 @@ -# vim: set ts=2 sw=2 tw=99 noet ft=python: -import os -import sys -from ambuild.command import Command -from ambuild.command import ShellCommand -from ambuild.command import SymlinkCommand - -class ExtractDebugInfoCommand(Command): - def __init__(self, binary, outfile): - Command.__init__(self) - self.binary = binary - self.outfile = outfile - - def run(self, runner, job): - if not self.binary.NeedsRelink(self.outfile): - return - - if AMBuild.target['platform'] == 'linux': - job.AddCommand(ShellCommand('objcopy --only-keep-debug ' + self.outfile + ' ' + self.outfile + '.dbg')) - job.AddCommand(ShellCommand('objcopy --strip-debug ' + self.outfile)) - job.AddCommand(ShellCommand('objcopy --add-gnu-debuglink=' + os.path.basename(self.outfile) + '.dbg ' + self.outfile)) - elif AMBuild.target['platform'] == 'darwin': - job.AddCommand(ShellCommand('dsymutil ' + self.outfile)) - job.AddCommand(ShellCommand('strip -S ' + self.outfile)) - -class SM: - def __init__(self): - self.compiler = Cpp.Compiler() - - #Build SDK info - self.possibleSdks = { } - self.possibleSdks['ep1'] = {'sdk': 'HL2SDK', 'ext': '1.ep1', 'def': '1', - 'name': 'EPISODEONE', 'platform': []} - self.possibleSdks['ep2'] = {'sdk': 'HL2SDKOB', 'ext': '2.ep2', 'def': '3', - 'name': 'ORANGEBOX', 'platform': []} - self.possibleSdks['css'] = {'sdk': 'HL2SDKCSS', 'ext': '2.css', 'def': '6', - 'name': 'CSS', 'platform': []} - self.possibleSdks['ep2v'] = {'sdk': 'HL2SDKOBVALVE', 'ext': '2.ep2v', 'def': '7', - 'name': 'ORANGEBOXVALVE', 'platform': ['windows', 'linux', 'darwin']} - self.possibleSdks['l4d'] = {'sdk': 'HL2SDKL4D', 'ext': '2.l4d', 'def': '8', - 'name': 'LEFT4DEAD', 'platform': []} - self.possibleSdks['l4d2'] = {'sdk': 'HL2SDKL4D2', 'ext': '2.l4d2', 'def': '9', - 'name': 'LEFT4DEAD2', 'platform': []} - self.possibleSdks['darkm'] = {'sdk': 'HL2SDK-DARKM', 'ext': '2.darkm', 'def': '2', - 'name': 'DARKMESSIAH', 'platform': []} - self.possibleSdks['swarm'] = {'sdk': 'HL2SDK-SWARM', 'ext': '2.swarm', 'def': '10', - 'name': 'ALIENSWARM', 'platform': []} - self.possibleSdks['bgt'] = {'sdk': 'HL2SDK-BGT', 'ext': '2.bgt', 'def': '4', - 'name': 'BLOODYGOODTIME', 'platform': []} - self.possibleSdks['eye'] = {'sdk': 'HL2SDK-EYE', 'ext': '2.eye', 'def': '5', - 'name': 'EYE', 'platform': []} - self.possibleSdks['csgo'] = {'sdk': 'HL2SDKCSGO', 'ext': '2.csgo', 'def': '12', - 'name': 'CSGO', 'platform': []} - - self.sdkInfo = { } - - if AMBuild.mode == 'config': - #Detect compilers - self.compiler.DetectAll(AMBuild) - - #Detect variables - envvars = { 'MMSOURCE19': 'mmsource-1.9', - 'SOURCEMOD14': 'sourcemod-1.4', - 'HL2SDKCSS': 'hl2sdk-css', - 'HL2SDKOBVALVE': 'hl2sdk-ob-valve', - 'HL2SDKL4D': 'hl2sdk-l4d', - 'HL2SDKL4D2': 'hl2sdk-l4d2', - 'HL2SDKCSGO': 'hl2sdk-csgo' - } - - if AMBuild.target['platform'] != 'darwin': - envvars['HL2SDK'] = 'hl2sdk' - envvars['HL2SDKOB'] = 'hl2sdk-ob' - - if AMBuild.target['platform'] == 'windows': - envvars['HL2SDK-DARKM'] = 'hl2sdk-darkm' - envvars['HL2SDK-SWARM'] = 'hl2sdk-swarm' - envvars['HL2SDK-BGT'] = 'hl2sdk-bgt' - envvars['HL2SDK-EYE'] = 'hl2sdk-eye' - - # Finds if a dict with `key` set to `value` is present on the dict of dicts `dictionary` - def findDictByKey(dictionary, key, value): - for index in dictionary: - elem = dictionary[index] - if elem[key] == value: - return (elem, index) - return None - - for i in envvars: - if i in os.environ: - path = os.environ[i] - if not os.path.isdir(path): - raise Exception('Path for {0} was not found: {1}'.format(i, path)) - elif i.startswith('HL2SDK'): - (info, sdk) = findDictByKey(self.possibleSdks, 'sdk', i) - self.sdkInfo[sdk] = info - else: - head = os.getcwd() - oldhead = None - while head != None and head != oldhead: - path = os.path.join(head, envvars[i]) - if os.path.isdir(path): - break - oldhead = head - head, tail = os.path.split(head) - if i.startswith('HL2SDK'): - if head != None and head != oldhead: - (info, sdk) = findDictByKey(self.possibleSdks, 'sdk', i) - self.sdkInfo[sdk] = info - elif head == None or head == oldhead: - raise Exception('Could not find a valid path for {0}'.format(i)) - AMBuild.cache.CacheVariable(i, path) - - if len(self.sdkInfo) < 1: - raise Exception('At least one SDK must be available.') - - AMBuild.cache.CacheVariable('sdkInfo', self.sdkInfo) - - #Set up defines - cxx = self.compiler.cxx - if isinstance(cxx, Cpp.CompatGCC): - if isinstance(cxx, Cpp.GCC): - self.vendor = 'gcc' - elif isinstance(cxx, Cpp.Clang): - self.vendor = 'clang' - self.compiler.AddToListVar('CDEFINES', 'stricmp=strcasecmp') - self.compiler.AddToListVar('CDEFINES', '_stricmp=strcasecmp') - self.compiler.AddToListVar('CDEFINES', '_snprintf=snprintf') - self.compiler.AddToListVar('CDEFINES', '_vsnprintf=vsnprintf') - self.compiler.AddToListVar('CFLAGS', '-pipe') - self.compiler.AddToListVar('CFLAGS', '-fno-strict-aliasing') - if (self.vendor == 'gcc' and cxx.majorVersion >= 4) or self.vendor == 'clang': - self.compiler.AddToListVar('CFLAGS', '-fvisibility=hidden') - self.compiler.AddToListVar('CXXFLAGS', '-fvisibility-inlines-hidden') - self.compiler.AddToListVar('CFLAGS', '-Wall') - #self.compiler.AddToListVar('CFLAGS', '-Werror') - self.compiler.AddToListVar('CFLAGS', '-Wno-uninitialized') - self.compiler.AddToListVar('CFLAGS', '-Wno-unused') - self.compiler.AddToListVar('CFLAGS', '-Wno-switch') - self.compiler.AddToListVar('CFLAGS', '-msse') - self.compiler.AddToListVar('CFLAGS', '-g3') - self.compiler.AddToListVar('CFLAGS', '-m32') - self.compiler.AddToListVar('POSTLINKFLAGS', '-m32') - self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions') - self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics') - self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor') - self.compiler.AddToListVar('CXXFLAGS', '-Wno-overloaded-virtual') - self.compiler.AddToListVar('CXXFLAGS', '-std=c++11') - if (self.vendor == 'gcc' and cxx.majorVersion >= 4 and cxx.minorVersion >= 3) or \ - (self.vendor == 'clang' and cxx.majorVersion >= 3): - self.compiler.AddToListVar('CXXFLAGS', '-Wno-delete-non-virtual-dtor') - self.compiler.AddToListVar('CDEFINES', 'HAVE_STDINT_H') - self.compiler.AddToListVar('CDEFINES', 'GNUC') - if self.vendor == 'gcc': - self.compiler.AddToListVar('CFLAGS', '-mfpmath=sse') - elif isinstance(cxx, Cpp.MSVC): - self.vendor = 'msvc' - if AMBuild.options.debug == '1': - self.compiler.AddToListVar('CFLAGS', '/MTd') - self.compiler.AddToListVar('POSTLINKFLAGS', '/NODEFAULTLIB:libcmt') - else: - self.compiler.AddToListVar('CFLAGS', '/MT') - self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_DEPRECATE') - self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_WARNINGS') - self.compiler.AddToListVar('CDEFINES', '_CRT_NONSTDC_NO_DEPRECATE') - self.compiler.AddToListVar('CXXFLAGS', '/EHsc') - self.compiler.AddToListVar('CFLAGS', '/W3') - self.compiler.AddToListVar('CFLAGS', '/nologo') - self.compiler.AddToListVar('CFLAGS', '/Zi') - self.compiler.AddToListVar('CXXFLAGS', '/TP') - self.compiler.AddToListVar('POSTLINKFLAGS', '/DEBUG') - self.compiler.AddToListVar('POSTLINKFLAGS', '/MACHINE:X86') - self.compiler.AddToListVar('POSTLINKFLAGS', '/SUBSYSTEM:WINDOWS') - self.compiler.AddToListVar('POSTLINKFLAGS', 'kernel32.lib') - self.compiler.AddToListVar('POSTLINKFLAGS', 'user32.lib') - self.compiler.AddToListVar('POSTLINKFLAGS', 'gdi32.lib') - self.compiler.AddToListVar('POSTLINKFLAGS', 'winspool.lib') - self.compiler.AddToListVar('POSTLINKFLAGS', 'comdlg32.lib') - self.compiler.AddToListVar('POSTLINKFLAGS', 'advapi32.lib') - self.compiler.AddToListVar('POSTLINKFLAGS', 'shell32.lib') - self.compiler.AddToListVar('POSTLINKFLAGS', 'ole32.lib') - self.compiler.AddToListVar('POSTLINKFLAGS', 'oleaut32.lib') - self.compiler.AddToListVar('POSTLINKFLAGS', 'uuid.lib') - self.compiler.AddToListVar('POSTLINKFLAGS', 'odbc32.lib') - self.compiler.AddToListVar('POSTLINKFLAGS', 'odbccp32.lib') - - #Optimization - if AMBuild.options.opt == '1': - self.compiler.AddToListVar('CDEFINES', 'NDEBUG') - if self.vendor == 'gcc' or self.vendor == 'clang': - self.compiler.AddToListVar('CFLAGS', '-O3') - elif self.vendor == 'msvc': - self.compiler.AddToListVar('CFLAGS', '/Ox') - self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:ICF') - self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:REF') - - #Debugging - if AMBuild.options.debug == '1': - self.compiler.AddToListVar('CDEFINES', 'DEBUG') - self.compiler.AddToListVar('CDEFINES', '_DEBUG') - if self.vendor == 'msvc': - self.compiler.AddToListVar('CFLAGS', '/Od') - self.compiler.AddToListVar('CFLAGS', '/RTC1') - - #Platform-specifics - if AMBuild.target['platform'] == 'linux': - self.compiler.AddToListVar('CDEFINES', '_LINUX') - self.compiler.AddToListVar('CDEFINES', 'POSIX') - if self.vendor == 'gcc': - self.compiler.AddToListVar('POSTLINKFLAGS', '-static-libgcc') - if self.vendor == 'clang': - self.compiler.AddToListVar('POSTLINKFLAGS', '-lgcc_eh') - elif AMBuild.target['platform'] == 'darwin': - self.compiler.AddToListVar('CDEFINES', 'OSX') - self.compiler.AddToListVar('CDEFINES', '_OSX') - self.compiler.AddToListVar('CDEFINES', 'POSIX') - self.compiler.AddToListVar('POSTLINKFLAGS', '-mmacosx-version-min=10.5') - self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'i386']) - self.compiler.AddToListVar('POSTLINKFLAGS', '-lstdc++') - - # For OS X dylib versioning - import re - productFile = open(os.path.join(AMBuild.sourceFolder, 'product.version'), 'r') - productContents = productFile.read() - productFile.close() - m = re.match('(\d+)\.(\d+)\.(\d+).*', productContents) - if m == None: - self.version = '1.0.0' - else: - major, minor, release = m.groups() - self.version = '{0}.{1}.{2}'.format(major, minor, release) - AMBuild.cache.CacheVariable('version', self.version) - elif AMBuild.target['platform'] == 'windows': - self.compiler.AddToListVar('CDEFINES', 'WIN32') - self.compiler.AddToListVar('CDEFINES', '_WINDOWS') - - #Finish up - self.compiler.AddToListVar('CDEFINES', 'NO_HOOK_MALLOC') - self.compiler.AddToListVar('CDEFINES', 'NO_MALLOC_OVERRIDE') - self.compiler.AddToListVar('CDEFINES', 'SOURCEMOD_BUILD') - self.compiler.AddToListVar('CDEFINES', 'SM_GENERATED_BUILD') - self.compiler.AddToListVar('CINCLUDES', - os.path.join(AMBuild.outputFolder, 'includes')) - self.compiler.ToConfig(AMBuild, 'compiler') - AMBuild.cache.CacheVariable('vendor', self.vendor) - self.targetMap = { } - AMBuild.cache.CacheVariable('targetMap', self.targetMap) - else: - self.sdkInfo = AMBuild.cache['sdkInfo'] - self.compiler.FromConfig(AMBuild, 'compiler') - self.targetMap = AMBuild.cache['targetMap'] - - if AMBuild.target['platform'] == 'windows': - self.compiler.AddToListVar('RCINCLUDES', os.path.join(AMBuild.sourceFolder, 'extension')) - self.mmsPath = AMBuild.cache['MMSOURCE19'] - - def DefaultCompiler(self): - return self.compiler.Clone() - - def JobMatters(self, jobname): - file = sys._getframe().f_code.co_filename - if AMBuild.mode == 'config': - self.targetMap[jobname] = file - return True - if len(AMBuild.args) == 0: - return True - if not jobname in AMBuild.args: - return False - - def AutoVersion(self, folder, binary): - if AMBuild.target['platform'] == 'windows': - env = {'RCDEFINES': ['BINARY_NAME="' + binary.binaryFile + '"', 'SM_GENERATED_BUILD']} - binary.AddResourceFile(os.path.join(folder, 'version.rc' ), env) - elif AMBuild.target['platform'] == 'darwin' and isinstance(binary, Cpp.LibraryBuilder): - binary.compiler['POSTLINKFLAGS'].extend(['-compatibility_version', '1.0.0']) - binary.compiler['POSTLINKFLAGS'].extend(['-current_version', AMBuild.cache['version']]) - else: - return - - def ExtractDebugInfo(self, job, binary): - src = os.path.join('..', AMBuild.outputFolder, job.workFolder, binary.binaryFile) - job.AddCommand(ExtractDebugInfoCommand(binary, src)) - - def PreSetupHL2Job(self, job, builder, sdk): - info = self.sdkInfo[sdk] - sdkPath = AMBuild.cache[info['sdk']] - if AMBuild.target['platform'] == 'linux': - if sdk == 'ep1': - staticLibs = os.path.join(sdkPath, 'linux_sdk') - else: - staticLibs = os.path.join(sdkPath, 'lib', 'linux') - workFolder = os.path.join(AMBuild.outputFolder, job.workFolder) - if sdk == 'ep2v': - libs = ['tier1_i486.a', 'mathlib_i486.a', 'libvstdlib_srv.so', 'libtier0_srv.so'] - for lib in libs: - link = os.path.join(workFolder, lib) - target = os.path.join(staticLibs, lib) - try: - os.lstat(link) - except: - job.AddCommand(SymlinkCommand(link, target)) - elif sdk in ['css', 'l4d', 'l4d2', 'csgo']: - libs = ['tier1_i486.a', 'mathlib_i486.a', 'libvstdlib.so', 'libtier0.so'] - if sdk == 'csgo': - libs.append('interfaces_i486.a') - for lib in libs: - link = os.path.join(workFolder, lib) - target = os.path.join(staticLibs, lib) - try: - os.lstat(link) - except: - job.AddCommand(SymlinkCommand(link, target)) - else: - libs = ['tier1_i486.a', 'mathlib_i486.a', 'vstdlib_i486.so', 'tier0_i486.so'] - for lib in libs: - link = os.path.join(workFolder, lib) - target = os.path.join(staticLibs, lib) - try: - os.lstat(link) - except: - job.AddCommand(SymlinkCommand(link, target)) - elif AMBuild.target['platform'] == 'darwin': - staticLibs = os.path.join(sdkPath, 'lib', 'mac') - workFolder = os.path.join(AMBuild.outputFolder, job.workFolder) - libs = ['tier1_i486.a', 'mathlib_i486.a', 'libvstdlib.dylib', 'libtier0.dylib'] - if sdk == 'csgo': - libs.append('interfaces_i486.a') - for lib in libs: - link = os.path.join(workFolder, lib) - target = os.path.join(staticLibs, lib) - try: - os.lstat(link) - except: - job.AddCommand(SymlinkCommand(link, target)) - elif AMBuild.target['platform'] == 'windows': - libs = ['tier0', 'tier1', 'vstdlib', 'mathlib'] - if sdk in ['swarm', 'csgo']: - libs.append('interfaces') - for lib in libs: - libPath = os.path.join(sdkPath, 'lib', 'public', lib) + '.lib' - builder.RebuildIfNewer(libPath) - builder['POSTLINKFLAGS'].append(libPath) - - def PostSetupHL2Job(self, job, builder, sdk): - if AMBuild.target['platform'] in ['linux', 'darwin']: - builder.AddObjectFiles(['tier1_i486.a', 'mathlib_i486.a']) - if sdk == 'csgo': - builder.AddObjectFiles(['interfaces_i486.a']) - - def DefaultHL2Compiler(self, path, sdk, noLink = False, oldMms = '-legacy'): - compiler = self.DefaultCompiler() - - mms = 'core' - if sdk == 'ep1': - mms += oldMms - - compiler['CXXINCLUDES'].append(os.path.join(self.mmsPath, mms)) - compiler['CXXINCLUDES'].append(os.path.join(self.mmsPath, mms, 'sourcehook')) - - info = self.possibleSdks - compiler['CDEFINES'].extend(['SE_' + info[i]['name'] + '=' + info[i]['def'] for i in info]) - - paths = [['public'], ['public', 'engine'], ['public', 'mathlib'], ['public', 'vstdlib'], ['public', 'tier0'], ['public', 'tier1']] - if sdk == 'ep1' or sdk == 'darkm': - paths.append(['public', 'dlls']) - paths.append(['game_shared']) - else: - paths.append(['public', 'game', 'server']) - paths.append(['public', 'toolframework']) - paths.append(['game', 'shared']) - paths.append(['common']) - - info = self.sdkInfo[sdk] - sdkPath = AMBuild.cache[info['sdk']] - - compiler['CDEFINES'].append('SOURCE_ENGINE=' + info['def']) - - if sdk in ['swarm','csgo']: - if AMBuild.target['platform'] == 'windows': - compiler['CDEFINES'].extend(['COMPILER_MSVC', 'COMPILER_MSVC32']) - else: - compiler['CDEFINES'].extend(['COMPILER_GCC', 'POSIX']) - - if sdk == 'ep1': - if AMBuild.target['platform'] == 'linux': - staticLibs = os.path.join(sdkPath, 'linux_sdk') - else: - if AMBuild.target['platform'] == 'linux': - staticLibs = os.path.join(sdkPath, 'lib', 'linux') - elif AMBuild.target['platform'] == 'darwin': - staticLibs = os.path.join(sdkPath, 'lib', 'mac') - - for i in paths: - compiler['CXXINCLUDES'].append(os.path.join(sdkPath, *i)) - - if not noLink: - if AMBuild.target['platform'] == 'linux': - compiler['POSTLINKFLAGS'][0:0] = ['-lm'] - if sdk == 'ep2v': - compiler['POSTLINKFLAGS'][0:0] = ['libtier0_srv.so'] - compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib_srv.so'] - elif sdk in ['css', 'l4d', 'l4d2', 'csgo']: - compiler['POSTLINKFLAGS'][0:0] = ['libtier0.so'] - compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.so'] - else: - compiler['POSTLINKFLAGS'][0:0] = ['tier0_i486.so'] - compiler['POSTLINKFLAGS'][0:0] = ['vstdlib_i486.so'] - elif AMBuild.target['platform'] == 'darwin': - compiler['POSTLINKFLAGS'][0:0] = ['libtier0.dylib'] - compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.dylib'] - - return compiler - -sm = SM() -globals = { - 'SM': sm -} - -AMBuild.Include(os.path.join('buildbot', 'Versioning'), globals) - -FileList = [ - ['extension', 'AMBuilder'], - ['buildbot', 'PackageScript'], - ['buildbot', 'BreakpadSymbols'] - ] - -for parts in FileList: - AMBuild.Include(os.path.join(*parts), globals) - +# vim: set ts=2 sw=2 tw=99 noet ft=python: +import os, sys, shutil + +def ResolveEnvPath(env, folder=None): + if env in os.environ: + path = os.environ[env] + if os.path.isdir(path): + return path + return None + + if folder: + head = os.getcwd() + oldhead = None + while head != None and head != oldhead: + path = os.path.join(head, folder) + if os.path.isdir(path): + return path + oldhead = head + head, tail = os.path.split(head) + + return None + +def Normalize(path): + return os.path.abspath(os.path.normpath(path)) + +SdkHelpers = builder.Eval('hl2sdk-manifests/SdkHelpers.ambuild', { 'Project': 'tf2attrib' }) + +class Config(object): + def __init__(self): + self.mms_root = None + self.sm_root = None + self.extension = None + self.targets = [] + self.target_archs = set() + + if builder.options.targets: + target_archs = builder.options.targets.split(',') + else: + target_archs = ['x86_64'] + + for arch in target_archs: + try: + cxx = builder.DetectCxx(target_arch = arch) + self.target_archs.add(cxx.target.arch) + except Exception as e: + if builder.options.targets: + raise + print('Skipping target {}: {}'.format(arch, e)) + continue + self.targets.append(cxx) + + if not self.targets: + raise Exception('No suitable C/C++ compiler was found.') + + @property + def tag(self): + if builder.options.debug == '1': + return 'Debug' + return 'Release' + + def shouldIncludeSdk(self, sdk): + return not sdk.get('source2', False) + + def findSdkPath(self, sdk_name): + dir_name = 'hl2sdk-{}'.format(sdk_name) + if builder.options.hl2sdk_root: + sdk_path = os.path.join(builder.options.hl2sdk_root, dir_name) + if os.path.exists(sdk_path): + return sdk_path + return ResolveEnvPath('HL2SDK{}'.format(sdk_name.upper()), dir_name) + + def retrieve_sdk(self): + sdk_list = ['tf2'] + SdkHelpers.sdk_filter = self.shouldIncludeSdk + SdkHelpers.find_sdk_path = self.findSdkPath + SdkHelpers.findSdks(builder, self.targets, sdk_list) + + self.sdks = SdkHelpers.sdks + self.sdk_manifests = SdkHelpers.sdk_manifests + self.sdk_targets = SdkHelpers.sdk_targets + + def retrieve_sm(self): + if builder.options.sm_path: + self.sm_root = builder.options.sm_path + else: + self.sm_root = ResolveEnvPath('SOURCEMOD', 'sourcemod') + + if not self.sm_root or not os.path.isdir(self.sm_root): + raise Exception('Could not find a source copy of SourceMod') + self.sm_root = Normalize(self.sm_root) + + def retrieve_mms(self): + if builder.options.mms_path: + self.mms_root = builder.options.mms_path + else: + self.mms_root = ResolveEnvPath('MMSOURCE', 'metamod-source') + + if not self.mms_root or not os.path.isdir(self.mms_root): + raise Exception('Could not find a source copy of Metamod:Source') + self.mms_root = Normalize(self.mms_root) + + def use_auto_versioning(self): + return not builder.options.disable_auto_versioning + + def configure_cxx(self, cxx): + if cxx.like('gcc'): + self.configure_gcc(cxx) + elif cxx.family == 'msvc': + self.configure_msvc(cxx) + + # 64bits + if cxx.target.arch == 'x86_64': + cxx.defines += ['TF2ITEMS_x64'] + + # Optimization + if builder.options.opt == '1': + cxx.defines += ['NDEBUG'] + + # Debugging + if builder.options.debug == '1': + cxx.defines += ['DEBUG', '_DEBUG'] + + # Platform-specifics + if cxx.target.platform == 'linux': + self.configure_linux(cxx) + elif cxx.target.platform == 'windows': + self.configure_windows(cxx) + + if self.use_auto_versioning(): + cxx.defines += ['GIT_ACTION_BUILD'] + + def configure_gcc(self, cxx): + cxx.cflags += [ + '-fPIC', + '-pipe', + '-fno-strict-aliasing', + '-fvisibility=hidden', + '-fvisibility-inlines-hidden', + '-Wall', + '-Werror', + '-msse' + ] + + cxx.defines += [ + 'HAVE_STDINT_H', + 'GNUC' + ] + + cxx.cxxflags += [ + '-std=c++17', + '-fno-threadsafe-statics', + '-Wno-non-virtual-dtor', + '-Wno-overloaded-virtual', + '-Wno-implicit-exception-spec-mismatch', + '-Wno-unused-private-field' + ] + + if builder.options.opt == '1': + cxx.cflags += ['-O3'] + return + + def configure_msvc(self, cxx): + cxx.cxxflags += [ + '/EHsc', + '/std:c++17' + ] + + return + + def configure_linux(self, cxx): + cxx.defines += ['_LINUX', 'POSIX'] + return + + def configure_windows(self, cxx): + cxx.defines += ['_WINDOWS'] + if cxx.target.arch == 'x86': + cxx.defines += ['WIN32'] + elif cxx.target.arch == 'x86_64': + cxx.defines += ['WIN64'] + return + + def configure(self): + self.retrieve_sm() + self.retrieve_mms() + self.retrieve_sdk() + + for cxx in self.targets: + self.configure_cxx(cxx) + + def configure_sdk(self, binary, context, sdk): + for other_sdk in self.sdk_manifests: + binary.compiler.defines += ['SE_{}={}'.format(other_sdk['define'], other_sdk['code'])] + SdkHelpers.configureCxx(context, binary, sdk) + + def configure_extension(self, binary, context): + binary.compiler.cxxincludes += [ + os.path.join(context.currentSourcePath), + os.path.join(self.sm_root, 'public'), + os.path.join(self.sm_root, 'public', 'extensions'), + os.path.join(self.sm_root, 'public', 'amtl', 'amtl'), + os.path.join(self.sm_root, 'public', 'amtl'), + os.path.join(self.sm_root, 'sourcepawn', 'include') + ] + + binary.compiler.cxxincludes += [ + os.path.join(self.mms_root, 'core'), + os.path.join(self.mms_root, 'core', 'sourcehook'), + ] + + def ConfigureLibrary(self, project, name, compiler, context): + binary = project.Configure(compiler, name, '{0} - {1}'.format(self.tag, compiler.target.arch)) + binary.compiler.cxxincludes += [ + os.path.join(context.currentSourcePath) + ] + return binary + + def ConfigureExtension(self, project, compiler, context): + binary = self.ConfigureLibrary(project, project.name, compiler, context) + self.configure_extension(binary, context) + return binary + + def ConfigureExtensionSDK(self, project, compiler, context, sdk): + binary = self.ConfigureLibrary(project, project.name + '.' + sdk['extension'], compiler, context) + self.configure_extension(binary, context) + self.configure_sdk(binary, context, sdk) + return binary + +Extension = Config() +Extension.configure() + +BuildScripts = ['extension/AMBuilder'] +builder.Build(BuildScripts, { 'Extension': Extension }) \ No newline at end of file diff --git a/build.bat b/build.bat deleted file mode 100644 index 7e6f83d..0000000 --- a/build.bat +++ /dev/null @@ -1,7 +0,0 @@ -mkdir build -cd build -call "%VS120COMNTOOLS%\vsvars32.bat" -..\configure.py -build.py -pause -cd .. \ No newline at end of file diff --git a/configure.py b/configure.py index f0f2aa0..e4ba86a 100644 --- a/configure.py +++ b/configure.py @@ -1,10 +1,23 @@ -# vim: set ts=2 sw=2 tw=99 noet: +# vim: set sts=2 ts=8 sw=2 tw=99 et: import sys -import ambuild.runner as runner +from ambuild2 import run -run = runner.Runner() -run.options.add_option('--enable-debug', action='store_const', const='1', dest='debug', +# Simple extensions do not need to modify this file. + +parser = run.BuildParser(sourcePath = sys.path[0], api='2.2') + +parser.options.add_argument('--hl2sdk-root', type=str, dest='hl2sdk_root', default=None, + help='Root search folder for HL2SDKs') +parser.options.add_argument('--sm-path', type=str, dest='sm_path', default=None, + help='Path to SourceMod') +parser.options.add_argument('--mms-path', type=str, dest='mms_path', default=None, + help='Path to Metamod:Source') +parser.options.add_argument('--enable-debug', action='store_const', const='1', dest='debug', help='Enable debugging symbols') -run.options.add_option('--enable-optimize', action='store_const', const='1', dest='opt', +parser.options.add_argument('--enable-optimize', action='store_const', const='1', dest='opt', help='Enable optimization') -run.Configure(sys.path[0]) +parser.options.add_argument('--enable-auto-versioning', action='store_false', dest='disable_auto_versioning', + default=True, help='Enables the auto versioning script') +parser.options.add_argument('--targets', type=str, dest='targets', default=None, + help="Override the target architecture (use commas to separate multiple targets).") +parser.Configure() \ No newline at end of file diff --git a/extension/AMBuilder b/extension/AMBuilder index d7ab2f1..df55b05 100644 --- a/extension/AMBuilder +++ b/extension/AMBuilder @@ -1,34 +1,18 @@ -# vim: set ts=2 sw=2 tw=99 noet ft=python: +# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python: import os -for i in SM.sdkInfo: - sdk = SM.sdkInfo[i] - if AMBuild.target['platform'] not in sdk['platform']: - continue +project = builder.LibraryProject('tf2items.ext') +project.sources = [ + 'extension.cpp', + 'sdk/smsdk_ext.cpp' +] - compiler = SM.DefaultHL2Compiler('extension', i) - - compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'extension')) - compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'extension', 'sdk')) - - compiler['CXXINCLUDES'].append(os.path.join(AMBuild.cache['SOURCEMOD14'], 'public')) - compiler['CXXINCLUDES'].append(os.path.join(AMBuild.cache['SOURCEMOD14'], 'public', 'sourcepawn')) +sdk = Extension.sdks['tf2'] - if compiler.cc.name == 'gcc': - compiler['CFLAGS'].append('-Wno-parentheses') +for cxx in Extension.targets: + if not cxx.target.arch in sdk['platforms'][cxx.target.platform]: + continue + binary = Extension.ConfigureExtensionSDK(project, cxx, builder, sdk) + binary.compiler.cxxincludes += [ os.path.join(builder.currentSourcePath, 'sdk') ] - if i != 'ep1': - compiler['CDEFINES'].append('HOOKING_ENABLED') - - name = 'tf2items.ext.' + sdk['ext'] - extension = AMBuild.AddJob(name) - binary = Cpp.LibraryBuilder(name, AMBuild, extension, compiler) - SM.PreSetupHL2Job(extension, binary, i) - - binary.AddSourceFiles(os.path.join('extension', 'sdk'), ['smsdk_ext.cpp']) - binary.AddSourceFiles('extension', ['extension.cpp']) - - SM.PostSetupHL2Job(extension, binary, i) - SM.AutoVersion('extension', binary) - SM.ExtractDebugInfo(extension, binary) - binary.SendToJob() +Extension.extension = builder.Add(project) \ No newline at end of file diff --git a/extension/extension.hpp b/extension/extension.hpp index c886d01..69ee0b0 100644 --- a/extension/extension.hpp +++ b/extension/extension.hpp @@ -82,9 +82,6 @@ class CEconItemAttribute int32 m_nRefundableCurrency; //12 }; -#pragma pack(push, 4) - - class CEconItemHandle { public: @@ -123,45 +120,49 @@ class CEconItemView public: void *m_pVTable; //0 - uint16 m_iItemDefinitionIndex; //4 + uint16 m_iItemDefinitionIndex; //4 // 8 - int32 m_iEntityQuality; //8 - uint32 m_iEntityLevel; //12 + int32 m_iEntityQuality; //8 // 12 + uint32 m_iEntityLevel; //12 // 16 - uint64 m_iItemID; //16 - uint32 m_iItemIDHigh; //24 - uint32 m_iItemIDLow; //28 + uint64 m_iItemID; //16 // 24 + uint32 m_iItemIDHigh; //24 // 32 + uint32 m_iItemIDLow; //28 // 36 - uint32 m_iAccountID; //32 + uint32 m_iAccountID; //32 // 40 - uint32 m_iInventoryPosition; //36 + uint32 m_iInventoryPosition; //36 // 44 - CEconItemHandle m_ItemHandle; //40 (44, 48, 52, 56, 60) + CEconItemHandle m_ItemHandle; //40 (44, 48, 52, 56, 60) // 48 - bool m_bColorInit; //64 - bool m_bPaintOverrideInit; //65 - bool m_bHasPaintOverride; //66 + bool m_bColorInit; //64 // 80 + bool m_bPaintOverrideInit; //65 // 81 + bool m_bHasPaintOverride; //66 // 82 //67 - float m_flOverrideIndex; //68 - uint32 m_unRGB; //72 - uint32 m_unAltRGB; //76 + float m_flOverrideIndex; //68 // 84 + uint32 m_unRGB; //72 // 88 + uint32 m_unAltRGB; //76 // 92 - int32 m_iTeamNumber; //80 + int32 m_iTeamNumber; //80 // 96 - bool m_bInitialized; //84 + bool m_bInitialized; //84 // 100 - CAttributeList m_AttributeList; //88 (92, 96, 100, 104, 108, 112) - CAttributeList m_NetworkedDynamicAttributesForDemos; //116 (120, 124, 128, 132, 136, 140) + CAttributeList m_AttributeList; //88 (92, 96, 100, 104, 108, 112) // 104 + CAttributeList m_NetworkedDynamicAttributesForDemos; //116 (120, 124, 128, 132, 136, 140) // 152 - bool m_bDoNotIterateStaticAttributes; //144 + bool m_bDoNotIterateStaticAttributes; //144 // 200 }; -#pragma pack(pop) - +#ifdef TF2ITEMS_x64 +static_assert(sizeof(CEconItemView) == 208, "CEconItemView - incorrect size on this compiler"); +static_assert(sizeof(CEconItemHandle) == 32, "CEconItemHandle - incorrect size on this compiler"); +static_assert(sizeof(CAttributeList) == 48, "CAttributeList - incorrect size on this compiler"); +#else static_assert(sizeof(CEconItemView) == 148, "CEconItemView - incorrect size on this compiler"); static_assert(sizeof(CEconItemHandle) == 24, "CEconItemHandle - incorrect size on this compiler"); static_assert(sizeof(CAttributeList) == 28, "CAttributeList - incorrect size on this compiler"); +#endif // enable to debug memory layout issues #if 0 diff --git a/extension/msvc10/tf2items.vcxproj b/extension/msvc10/tf2items.vcxproj deleted file mode 100644 index 42d1220..0000000 --- a/extension/msvc10/tf2items.vcxproj +++ /dev/null @@ -1,128 +0,0 @@ - - - - - Debug - Orange Box Valve - Win32 - - - Release - Orange Box Valve - Win32 - - - - {B3E797CF-4E77-4C9D-B8A8-7589B6902206} - tf2items - Win32Proj - - - - DynamicLibrary - MultiByte - true - - - DynamicLibrary - MultiByte - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - $(SolutionDir)$(Configuration)\ - $(Configuration)\ - true - $(SolutionDir)$(Configuration)\ - $(Configuration)\ - false - AllRules.ruleset - - - AllRules.ruleset - - - false - $(ProjectName).ext.2.ep2v.dll - $(ProjectName).ext.2.ep2v - - - - /D SE_EPISODEONE=1 /D SE_DARKMESSIAH=2 /D SE_ORANGEBOX=3 /D SE_ORANGEBOXVALVE=4 /D SE_LEFT4DEAD=5 /D SE_LEFT4DEAD2=6 %(AdditionalOptions) - Disabled - ..;..\sdk;$(SOURCEMOD13)\public\;$(SOURCEMOD13)\public\sourcepawn\;$(HL2SDKOBVALVE)\game\shared\;$(HL2SDKOBVALVE)\game\server\;$(HL2SDKOBVALVE)\public;$(HL2SDKOBVALVE)\public\engine;$(HL2SDKOBVALVE)\public\game\server;$(HL2SDKOBVALVE)\public\tier0;$(HL2SDKOBVALVE)\public\tier1;$(MMSOURCE18)\core;$(MMSOURCE18)\core\sourcehook;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;_USRDLL;SDK_EXPORTS;_CRT_SECURE_NO_DEPRECATE;SOURCEMOD_BUILD;SOURCE_ENGINE=4;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebug - NotSet - false - - - Level3 - EditAndContinue - false - - - $(HL2SDKOBVALVE)\lib\public\tier0.lib;$(HL2SDKOBVALVE)\lib\public\tier1.lib;$(HL2SDKOBVALVE)\lib\public\vstdlib.lib;%(AdditionalDependencies) - $(OutDir)$(ProjectName).ext.2.ep2v.dll - LIBC;LIBCD;LIBCMT;%(IgnoreSpecificDefaultLibraries) - true - Windows - false - - - MachineX86 - - - - - /MP /D SE_EPISODEONE=1 /D SE_DARKMESSIAH=2 /D SE_ORANGEBOX=3 /D SE_ORANGEBOXVALVE=4 /D SE_LEFT4DEAD=5 /D SE_LEFT4DEAD2=6 %(AdditionalOptions) - Speed - ..;..\sdk;$(SOURCEMOD13)\public\;$(SOURCEMOD13)\public\sourcepawn\;$(HL2SDKOBVALVE)\game\shared\;$(HL2SDKOBVALVE)\game\server\;$(HL2SDKOBVALVE)\public;$(HL2SDKOBVALVE)\public\engine;$(HL2SDKOBVALVE)\public\game\server;$(HL2SDKOBVALVE)\public\tier0;$(HL2SDKOBVALVE)\public\tier1;$(MMSOURCE18)\core;$(MMSOURCE18)\core\sourcehook;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;_USRDLL;SDK_EXPORTS;_CRT_SECURE_NO_DEPRECATE;SOURCEMOD_BUILD;SOURCE_ENGINE=4;%(PreprocessorDefinitions) - MultiThreaded - NotSet - false - - - Level3 - true - ProgramDatabase - - - $(HL2SDKOBVALVE)\lib\public\tier0.lib;$(HL2SDKOBVALVE)\lib\public\tier1.lib;$(HL2SDKOBVALVE)\lib\public\vstdlib.lib;%(AdditionalDependencies) - LinkVerbose - $(OutDir)$(ProjectName).ext.2.ep2v.dll - LIBC;LIBCD;LIBCMTD;%(IgnoreSpecificDefaultLibraries) - true - Windows - true - true - false - - - MachineX86 - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/extension/msvc10/tf2items.vcxproj.filters b/extension/msvc10/tf2items.vcxproj.filters deleted file mode 100644 index cb7650c..0000000 --- a/extension/msvc10/tf2items.vcxproj.filters +++ /dev/null @@ -1,38 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {31958233-BB2D-4e41-A8F9-CE8A4684F436} - - - - - Source Files - - - SourceMod SDK - - - - - Header Files - - - SourceMod SDK - - - SourceMod SDK - - - Header Files - - - \ No newline at end of file diff --git a/extension/msvc10/tf2items.vcxproj.user b/extension/msvc10/tf2items.vcxproj.user deleted file mode 100644 index 695b5c7..0000000 --- a/extension/msvc10/tf2items.vcxproj.user +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/hl2sdk-manifests b/hl2sdk-manifests new file mode 160000 index 0000000..2ae4644 --- /dev/null +++ b/hl2sdk-manifests @@ -0,0 +1 @@ +Subproject commit 2ae4644db6459ae16da7e3900260bbd6aa7ba03d diff --git a/tf2.items.txt b/tf2.items.txt index 907a9dd..13a3235 100644 --- a/tf2.items.txt +++ b/tf2.items.txt @@ -6,9 +6,10 @@ { "GiveNamedItem" { - "windows" "486" - "linux" "493" - "mac" "493" + "windows" "486" + "windows64" "486" + "linux" "493" + "linux64" "493" } } } From 4ca30a6b8f547ecece569e553b9df8e66516ebb2 Mon Sep 17 00:00:00 2001 From: Kenzzer <14257866+kenzzer@users.noreply.github.com> Date: Sat, 11 Apr 2026 11:48:23 +0000 Subject: [PATCH 2/2] Add KHook support --- AMBuildScript | 3 +- extension/AMBuilder | 5 +- extension/extension.cpp | 181 ++----- extension/extension.hpp | 2 +- .../sdk/{smsdk_config.hpp => smsdk_config.h} | 0 extension/sdk/smsdk_ext.cpp | 465 ------------------ extension/sdk/smsdk_ext.hpp | 339 ------------- hl2sdk-manifests | 2 +- tf2.items.txt | 8 +- 9 files changed, 54 insertions(+), 951 deletions(-) rename extension/sdk/{smsdk_config.hpp => smsdk_config.h} (100%) delete mode 100644 extension/sdk/smsdk_ext.cpp delete mode 100644 extension/sdk/smsdk_ext.hpp diff --git a/AMBuildScript b/AMBuildScript index da3698b..e564b0a 100644 --- a/AMBuildScript +++ b/AMBuildScript @@ -195,6 +195,7 @@ class Config(object): def configure_extension(self, binary, context): binary.compiler.cxxincludes += [ os.path.join(context.currentSourcePath), + os.path.join(context.currentSourcePath, 'sdk'), os.path.join(self.sm_root, 'public'), os.path.join(self.sm_root, 'public', 'extensions'), os.path.join(self.sm_root, 'public', 'amtl', 'amtl'), @@ -204,7 +205,7 @@ class Config(object): binary.compiler.cxxincludes += [ os.path.join(self.mms_root, 'core'), - os.path.join(self.mms_root, 'core', 'sourcehook'), + os.path.join(self.mms_root, 'third_party', 'khook', 'include'), ] def ConfigureLibrary(self, project, name, compiler, context): diff --git a/extension/AMBuilder b/extension/AMBuilder index df55b05..00123e2 100644 --- a/extension/AMBuilder +++ b/extension/AMBuilder @@ -4,7 +4,7 @@ import os project = builder.LibraryProject('tf2items.ext') project.sources = [ 'extension.cpp', - 'sdk/smsdk_ext.cpp' + os.path.join(Extension.sm_root, 'public', 'smsdk_ext.cpp') ] sdk = Extension.sdks['tf2'] @@ -12,7 +12,10 @@ sdk = Extension.sdks['tf2'] for cxx in Extension.targets: if not cxx.target.arch in sdk['platforms'][cxx.target.platform]: continue + oldcode = sdk['extension'] + sdk['extension'] = '2.ep2v' binary = Extension.ConfigureExtensionSDK(project, cxx, builder, sdk) + sdk['extension'] = oldcode binary.compiler.cxxincludes += [ os.path.join(builder.currentSourcePath, 'sdk') ] Extension.extension = builder.Add(project) \ No newline at end of file diff --git a/extension/extension.cpp b/extension/extension.cpp index 50e2bf2..a33b5c9 100644 --- a/extension/extension.cpp +++ b/extension/extension.cpp @@ -40,11 +40,18 @@ #include "extension.hpp" TF2Items g_TF2Items; - SMEXT_LINK(&g_TF2Items); -SH_DECL_HOOK2_void(IServerGameClients, ClientPutInServer, SH_NOATTRIB, 0, edict_t *, char const *); -SH_DECL_MANUALHOOK4(MHook_GiveNamedItem, 0, 0, 0, CBaseEntity *, char const *, int, CEconItemView *, bool); +class CBaseEntity {}; +class CBasePlayer : public CBaseEntity {}; +class CTFPlayer : public CBasePlayer {}; + +KHook::Return Hook_ClientPutInServer_POST(IServerGameClients*, edict_t*, const char*); +KHook::Virtual g_Hook_ClientPutInServer(&IServerGameClients::ClientPutInServer, nullptr, Hook_ClientPutInServer_POST); + +KHook::Return Hook_GiveNamedItem_PRE(CTFPlayer* player, char const*, int, CEconItemView*, bool); +KHook::Return Hook_GiveNamedItem_POST(CTFPlayer* player, char const*, int, CEconItemView*, bool); +KHook::Virtual g_MHook_GiveNamedItem(Hook_GiveNamedItem_PRE, Hook_GiveNamedItem_POST); ICvar *icvar = NULL; IServerGameClients *gameclients = NULL; @@ -55,10 +62,7 @@ ConVar HookTFBot("tf2items_bothook", "1", FCVAR_NONE, "Hook intelligent TF2 bots IGameConfig *g_pGameConf = NULL; -int GiveNamedItem_player_Hook = 0; -int GiveNamedItem_bot_Hook = 0; -int GiveNamedItem_player_Hook_Post = 0; -int GiveNamedItem_bot_Hook_Post = 0; +bool GiveNamedItem_Hook = false; int ClientPutInServer_Hook = 0; IForward *g_pForwardGiveItem = NULL; @@ -95,7 +99,7 @@ sp_nativeinfo_t g_ExtensionNatives[] = { NULL, NULL } }; -CBaseEntity *Hook_GiveNamedItem(char const *szClassname, int iSubType, CEconItemView *cscript, bool b) +KHook::Return Hook_GiveNamedItem_PRE(CTFPlayer* player, char const* szClassname, int iSubType, CEconItemView* cscript, bool b) { #if defined TF2ITEMS_DEBUG_HOOKING || defined TF2ITEMS_DEBUG_HOOKING_GNI g_pSM->LogMessage(myself, "GiveNamedItem called."); @@ -106,15 +110,12 @@ CBaseEntity *Hook_GiveNamedItem(char const *szClassname, int iSubType, CEconItem g_pSM->LogMessage(myself, ">>> Start of GiveNamedItem call."); #endif - CBasePlayer *player = META_IFACEPTR(CBasePlayer); - if (cscript == NULL || szClassname == NULL) { #if defined TF2ITEMS_DEBUG_HOOKING_GNI g_pSM->LogMessage(myself, "(cscript == NULL || szClassname == NULL), RETURN_META_VALUE(MRES_IGNORED, NULL);"); #endif // TF2ITEMS_DEBUG_HOOKING_GNI - - RETURN_META_VALUE(MRES_IGNORED, NULL); + return { KHook::Action::Ignore }; } // Retrieve client index. @@ -177,13 +178,13 @@ CBaseEntity *Hook_GiveNamedItem(char const *szClassname, int iSubType, CEconItem switch(cellResults) { case Pl_Continue: { - RETURN_META_VALUE(MRES_IGNORED, NULL); + return { KHook::Action::Ignore }; } case Pl_Changed: { TScriptedItemOverride *pScriptedItemOverride = GetScriptedItemOverrideFromHandle(cellOverrideHandle); if (pScriptedItemOverride == NULL) { - RETURN_META_VALUE(MRES_IGNORED, NULL); + return { KHook::Action::Ignore }; } // Execute the new attributes set and we're done! @@ -234,32 +235,24 @@ CBaseEntity *Hook_GiveNamedItem(char const *szClassname, int iSubType, CEconItem newitem.m_iEntityQuality = 0; } - RETURN_META_VALUE_MNEWPARAMS(MRES_HANDLED, NULL, MHook_GiveNamedItem, (finalitem, iSubType, &newitem, ((pScriptedItemOverride->m_bFlags & FORCE_GENERATION) == FORCE_GENERATION))); + KHook::Recall({ KHook::Action::Ignore, nullptr } , player, finalitem, iSubType, &newitem, ((pScriptedItemOverride->m_bFlags & FORCE_GENERATION) == FORCE_GENERATION)); } case Pl_Handled: case Pl_Stop: { - RETURN_META_VALUE(MRES_SUPERCEDE, NULL); + return { KHook::Action::Supersede, nullptr }; } } - RETURN_META_VALUE(MRES_IGNORED, NULL); + return { KHook::Action::Ignore }; } -CBaseEntity *Hook_GiveNamedItem_Post(char const *szClassname, int iSubType, CEconItemView *cscript, bool b) +KHook::Return Hook_GiveNamedItem_POST(CTFPlayer* player, char const* szClassname, int iSubType, CEconItemView* cscript, bool b) { - CBaseEntity *player = META_IFACEPTR(CBaseEntity); - - CBaseEntity *pItemEntiy; - if (META_RESULT_STATUS >= MRES_OVERRIDE) - { - pItemEntiy = META_RESULT_OVERRIDE_RET(CBaseEntity *); - } else { - pItemEntiy = META_RESULT_ORIG_RET(CBaseEntity *); - } + CBaseEntity *pItemEntiy = *(CBaseEntity**)KHook::GetCurrentValuePtr(); if (!player || !szClassname || !cscript || !pItemEntiy) - RETURN_META_VALUE(MRES_IGNORED, pItemEntiy); + return { KHook::Action::Ignore }; int client = gamehelpers->EntityToBCompatRef(player); int iEntityIndex = gamehelpers->EntityToBCompatRef(pItemEntiy); @@ -272,7 +265,7 @@ CBaseEntity *Hook_GiveNamedItem_Post(char const *szClassname, int iSubType, CEco g_pForwardGiveItem_Post->PushCell(iEntityIndex); g_pForwardGiveItem_Post->Execute(NULL); - RETURN_META_VALUE(MRES_IGNORED, pItemEntiy); + return { KHook::Action::Ignore }; } void CSCICopy(CEconItemView *olditem, CEconItemView *newitem) @@ -328,7 +321,16 @@ void CSCICopy(CEconItemView *olditem, CEconItemView *newitem) */ } -void Hook_ClientPutInServer(edict_t *pEntity, char const *playername) +void SetupHook(CBasePlayer* player) { + if (GiveNamedItem_Hook) { + return; + } + + g_MHook_GiveNamedItem.AddGlobal((CTFPlayer*)player); + GiveNamedItem_Hook = true; +} + +KHook::Return Hook_ClientPutInServer_POST(IServerGameClients* clients, edict_t* pEntity, const char* playername) { #ifdef TF2ITEMS_DEBUG_HOOKING g_pSM->LogMessage(myself, "ClientPutInServer called."); @@ -339,7 +341,7 @@ void Hook_ClientPutInServer(edict_t *pEntity, char const *playername) CBaseEntity *baseentity = pEntity->m_pNetworkable->GetBaseEntity(); if(!baseentity) { - return; + return { KHook::Action::Ignore }; } CBasePlayer *player = (CBasePlayer *)baseentity; @@ -353,57 +355,10 @@ void Hook_ClientPutInServer(edict_t *pEntity, char const *playername) g_pSM->LogMessage(myself, "---------------------------------------"); #endif - if (HookTFBot.GetBool() && strcmp(pEntity->GetClassName(), "tf_bot") == 0) - { - if(GiveNamedItem_bot_Hook == 0) - { - GiveNamedItem_bot_Hook = SH_ADD_MANUALVPHOOK(MHook_GiveNamedItem, player, SH_STATIC(Hook_GiveNamedItem), false); -#ifdef TF2ITEMS_DEBUG_HOOKING - g_pSM->LogMessage(myself, "GiveNamedItem hooked (bot)."); -#endif // TF2ITEMS_DEBUG_HOOKING - } - - if(GiveNamedItem_bot_Hook_Post == 0) - { - GiveNamedItem_bot_Hook_Post = SH_ADD_MANUALVPHOOK(MHook_GiveNamedItem, player, SH_STATIC(Hook_GiveNamedItem_Post), true); -#ifdef TF2ITEMS_DEBUG_HOOKING - g_pSM->LogMessage(myself, "GiveNamedItem hooked (bot) (post)."); -#endif // TF2ITEMS_DEBUG_HOOKING - } - } else { - if(GiveNamedItem_player_Hook == 0) - { - GiveNamedItem_player_Hook = SH_ADD_MANUALVPHOOK(MHook_GiveNamedItem, player, SH_STATIC(Hook_GiveNamedItem), false); -#ifdef TF2ITEMS_DEBUG_HOOKING - g_pSM->LogMessage(myself, "GiveNamedItem hooked (player)."); -#endif // TF2ITEMS_DEBUG_HOOKING - } - - if(GiveNamedItem_player_Hook_Post == 0) - { - GiveNamedItem_player_Hook_Post = SH_ADD_MANUALVPHOOK(MHook_GiveNamedItem, player, SH_STATIC(Hook_GiveNamedItem_Post), true); -#ifdef TF2ITEMS_DEBUG_HOOKING - g_pSM->LogMessage(myself, "GiveNamedItem hooked (player)."); -#endif // TF2ITEMS_DEBUG_HOOKING - } - - if (!HookTFBot.GetBool() && ClientPutInServer_Hook != 0) { - SH_REMOVE_HOOK_ID(ClientPutInServer_Hook); - ClientPutInServer_Hook = 0; -#ifdef TF2ITEMS_DEBUG_HOOKING - g_pSM->LogMessage(myself, "ClientPutInServer unhooked."); -#endif // TF2ITEMS_DEBUG_HOOKING - } - } - - if (ClientPutInServer_Hook != 0 && GiveNamedItem_player_Hook != 0 && GiveNamedItem_bot_Hook != 0) { - SH_REMOVE_HOOK_ID(ClientPutInServer_Hook); - ClientPutInServer_Hook = 0; -#ifdef TF2ITEMS_DEBUG_HOOKING - g_pSM->LogMessage(myself, "ClientPutInServer unhooked."); -#endif // TF2ITEMS_DEBUG_HOOKING - } + SetupHook(player); + g_Hook_ClientPutInServer.Remove(clients); } + return { KHook::Action::Ignore }; } bool TF2Items::SDK_OnLoad(char *error, size_t maxlen, bool late) { @@ -424,7 +379,7 @@ bool TF2Items::SDK_OnLoad(char *error, size_t maxlen, bool late) { snprintf(error, maxlen, "Could not find offset for GiveNamedItem"); return false; } else { - SH_MANUALHOOK_RECONFIGURE(MHook_GiveNamedItem, iOffset, 0, 0); + g_MHook_GiveNamedItem.Configure(iOffset); g_pSM->LogMessage(myself, "\"GiveNamedItem\" offset = %d", iOffset); } @@ -460,26 +415,20 @@ bool TF2Items::SDK_OnLoad(char *error, size_t maxlen, bool late) { } // Done, hook the BasePlayer - GiveNamedItem_player_Hook = SH_ADD_MANUALVPHOOK(MHook_GiveNamedItem, pBasePlayer, SH_STATIC(Hook_GiveNamedItem), false); - - if (GiveNamedItem_player_Hook != 0) - { + SetupHook(pBasePlayer); #ifdef TF2ITEMS_DEBUG_HOOKING - g_pSM->LogMessage(myself, "GiveNamedItem hooked."); + g_pSM->LogMessage(myself, "GiveNamedItem hooked."); #endif // TF2ITEMS_DEBUG_HOOKING - break; - } } } - if (GiveNamedItem_player_Hook == 0) + if (!GiveNamedItem_Hook) { #ifdef TF2ITEMS_DEBUG_HOOKING g_pSM->LogMessage(myself, "Is a NOT late load or no players found, attempting to hook ClientPutInServer."); #endif // TF2ITEMS_DEBUG_HOOKING - ClientPutInServer_Hook = SH_ADD_HOOK_STATICFUNC(IServerGameClients, ClientPutInServer, gameclients, Hook_ClientPutInServer, true); - + g_Hook_ClientPutInServer.Add(gameclients); #ifdef TF2ITEMS_DEBUG_HOOKING g_pSM->LogMessage(myself, "ClientPutInServer hooked."); #endif // TF2ITEMS_DEBUG_HOOKING @@ -533,51 +482,6 @@ bool TF2Items::SDK_OnMetamodUnload(char *error, size_t maxlen) g_pSM->LogMessage(myself, "SDK_OnMetamodUnload called."); #endif // TF2ITEMS_DEBUG_HOOKING - if (ClientPutInServer_Hook != 0) - { - SH_REMOVE_HOOK_ID(ClientPutInServer_Hook); - ClientPutInServer_Hook = 0; - -#ifdef TF2ITEMS_DEBUG_HOOKING - g_pSM->LogMessage(myself, "ClientPutInServer unhooked."); -#endif // TF2ITEMS_DEBUG_HOOKING - } -#ifdef TF2ITEMS_DEBUG_HOOKING - else { - g_pSM->LogMessage(myself, "ClientPutInServer did not need to be unhooked."); - } -#endif // TF2ITEMS_DEBUG_HOOKING - - if (GiveNamedItem_player_Hook != 0) - { - SH_REMOVE_HOOK_ID(GiveNamedItem_player_Hook); - GiveNamedItem_player_Hook = 0; - -#ifdef TF2ITEMS_DEBUG_HOOKING - g_pSM->LogMessage(myself, "GiveNamedItem unhooked."); -#endif // TF2ITEMS_DEBUG_HOOKING - } -#ifdef TF2ITEMS_DEBUG_HOOKING - else { - g_pSM->LogMessage(myself, "GiveNamedItem did not need to be unhooked."); - } -#endif // TF2ITEMS_DEBUG_HOOKING - - if (GiveNamedItem_player_Hook_Post != 0) - { - SH_REMOVE_HOOK_ID(GiveNamedItem_player_Hook_Post); - GiveNamedItem_player_Hook_Post = 0; - -#ifdef TF2ITEMS_DEBUG_HOOKING - g_pSM->LogMessage(myself, "GiveNamedItem (post) unhooked."); -#endif // TF2ITEMS_DEBUG_HOOKING - } -#ifdef TF2ITEMS_DEBUG_HOOKING - else { - g_pSM->LogMessage(myself, "GiveNamedItem (post) did not need to be unhooked."); - } -#endif // TF2ITEMS_DEBUG_HOOKING - return true; } @@ -640,8 +544,7 @@ static cell_t TF2Items_GiveNamedItem(IPluginContext *pContext, const cell_t *par #endif // Call the function. - CBaseEntity *tempItem = NULL; - tempItem = SH_MCALL(pEntity, MHook_GiveNamedItem)(strWeaponClassname, 0, &hScriptCreatedItem, ((pScriptedItemOverride->m_bFlags & FORCE_GENERATION) == FORCE_GENERATION)); + CBaseEntity *tempItem = g_MHook_GiveNamedItem.CallOriginal((CTFPlayer*)pEntity, strWeaponClassname, 0, &hScriptCreatedItem, ((pScriptedItemOverride->m_bFlags & FORCE_GENERATION) == FORCE_GENERATION)); if (tempItem == NULL) { diff --git a/extension/extension.hpp b/extension/extension.hpp index 69ee0b0..5ca78ed 100644 --- a/extension/extension.hpp +++ b/extension/extension.hpp @@ -26,7 +26,7 @@ * @brief TF2Items extension code header. */ -#include "smsdk_ext.hpp" +#include "smsdk_ext.h" //#include "iplayerinfo.h" //#include "convar.h" diff --git a/extension/sdk/smsdk_config.hpp b/extension/sdk/smsdk_config.h similarity index 100% rename from extension/sdk/smsdk_config.hpp rename to extension/sdk/smsdk_config.h diff --git a/extension/sdk/smsdk_ext.cpp b/extension/sdk/smsdk_ext.cpp deleted file mode 100644 index 14bc62f..0000000 --- a/extension/sdk/smsdk_ext.cpp +++ /dev/null @@ -1,465 +0,0 @@ -/** - * vim: set ts=4 : - * ============================================================================= - * SourceMod Base Extension Code - * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. - * ============================================================================= - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, version 3.0, as published by the - * Free Software Foundation. - * - * This program 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 - * this program. If not, see . - * - * As a special exception, AlliedModders LLC gives you permission to link the - * code of this program (as well as its derivative works) to "Half-Life 2," the - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software - * by the Valve Corporation. You must obey the GNU General Public License in - * all respects for all other code used. Additionally, AlliedModders LLC grants - * this exception to all derivative works. AlliedModders LLC defines further - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), - * or . - * - * Version: $Id$ - */ - -#include -#include -#include "smsdk_ext.hpp" - -/** - * @file smsdk_ext.cpp - * @brief Contains wrappers for making Extensions easier to write. - */ - -IExtension *myself = NULL; /**< Ourself */ -IShareSys *g_pShareSys = NULL; /**< Share system */ -IShareSys *sharesys = NULL; /**< Share system */ -ISourceMod *g_pSM = NULL; /**< SourceMod helpers */ -ISourceMod *smutils = NULL; /**< SourceMod helpers */ - -#if defined SMEXT_ENABLE_FORWARDSYS -IForwardManager *g_pForwards = NULL; /**< Forward system */ -IForwardManager *forwards = NULL; /**< Forward system */ -#endif -#if defined SMEXT_ENABLE_HANDLESYS -IHandleSys *g_pHandleSys = NULL; /**< Handle system */ -IHandleSys *handlesys = NULL; /**< Handle system */ -#endif -#if defined SMEXT_ENABLE_PLAYERHELPERS -IPlayerManager *playerhelpers = NULL; /**< Player helpers */ -#endif //SMEXT_ENABLE_PLAYERHELPERS -#if defined SMEXT_ENABLE_DBMANAGER -IDBManager *dbi = NULL; /**< DB Manager */ -#endif //SMEXT_ENABLE_DBMANAGER -#if defined SMEXT_ENABLE_GAMECONF -IGameConfigManager *gameconfs = NULL; /**< Game config manager */ -#endif //SMEXT_ENABLE_DBMANAGER -#if defined SMEXT_ENABLE_MEMUTILS -IMemoryUtils *memutils = NULL; -#endif //SMEXT_ENABLE_DBMANAGER -#if defined SMEXT_ENABLE_GAMEHELPERS -IGameHelpers *gamehelpers = NULL; -#endif -#if defined SMEXT_ENABLE_TIMERSYS -ITimerSystem *timersys = NULL; -#endif -#if defined SMEXT_ENABLE_ADTFACTORY -IADTFactory *adtfactory = NULL; -#endif -#if defined SMEXT_ENABLE_THREADER -IThreader *threader = NULL; -#endif -#if defined SMEXT_ENABLE_LIBSYS -ILibrarySys *libsys = NULL; -#endif -#if defined SMEXT_ENABLE_PLUGINSYS -SourceMod::IPluginManager *plsys; -#endif -#if defined SMEXT_ENABLE_MENUS -IMenuManager *menus = NULL; -#endif -#if defined SMEXT_ENABLE_ADMINSYS -IAdminSystem *adminsys = NULL; -#endif -#if defined SMEXT_ENABLE_TEXTPARSERS -ITextParsers *textparsers = NULL; -#endif -#if defined SMEXT_ENABLE_USERMSGS -IUserMessages *usermsgs = NULL; -#endif -#if defined SMEXT_ENABLE_TRANSLATOR -ITranslator *translator = NULL; -#endif -#if defined SMEXT_ENABLE_NINVOKE -INativeInterface *ninvoke = NULL; -#endif - -/** Exports the main interface */ -PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI() -{ - return g_pExtensionIface; -} - -SDKExtension::SDKExtension() -{ -#if defined SMEXT_CONF_METAMOD - m_SourceMMLoaded = false; - m_WeAreUnloaded = false; - m_WeGotPauseChange = false; -#endif -} - -bool SDKExtension::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late) -{ - g_pShareSys = sharesys = sys; - myself = me; - -#if defined SMEXT_CONF_METAMOD - m_WeAreUnloaded = true; - - if (!m_SourceMMLoaded) - { - if (error) - { - snprintf(error, maxlength, "Metamod attach failed"); - } - return false; - } -#endif - SM_GET_IFACE(SOURCEMOD, g_pSM); - smutils = g_pSM; -#if defined SMEXT_ENABLE_HANDLESYS - SM_GET_IFACE(HANDLESYSTEM, g_pHandleSys); - handlesys = g_pHandleSys; -#endif -#if defined SMEXT_ENABLE_FORWARDSYS - SM_GET_IFACE(FORWARDMANAGER, g_pForwards); - forwards = g_pForwards; -#endif -#if defined SMEXT_ENABLE_PLAYERHELPERS - SM_GET_IFACE(PLAYERMANAGER, playerhelpers); -#endif -#if defined SMEXT_ENABLE_DBMANAGER - SM_GET_IFACE(DBI, dbi); -#endif -#if defined SMEXT_ENABLE_GAMECONF - SM_GET_IFACE(GAMECONFIG, gameconfs); -#endif -#if defined SMEXT_ENABLE_MEMUTILS - SM_GET_IFACE(MEMORYUTILS, memutils); -#endif -#if defined SMEXT_ENABLE_GAMEHELPERS - SM_GET_IFACE(GAMEHELPERS, gamehelpers); -#endif -#if defined SMEXT_ENABLE_TIMERSYS - SM_GET_IFACE(TIMERSYS, timersys); -#endif -#if defined SMEXT_ENABLE_ADTFACTORY - SM_GET_IFACE(ADTFACTORY, adtfactory); -#endif -#if defined SMEXT_ENABLE_THREADER - SM_GET_IFACE(THREADER, threader); -#endif -#if defined SMEXT_ENABLE_LIBSYS - SM_GET_IFACE(LIBRARYSYS, libsys); -#endif -#if defined SMEXT_ENABLE_PLUGINSYS - SM_GET_IFACE(PLUGINSYSTEM, plsys); -#endif -#if defined SMEXT_ENABLE_MENUS - SM_GET_IFACE(MENUMANAGER, menus); -#endif -#if defined SMEXT_ENABLE_ADMINSYS - SM_GET_IFACE(ADMINSYS, adminsys); -#endif -#if defined SMEXT_ENABLE_TEXTPARSERS - SM_GET_IFACE(TEXTPARSERS, textparsers); -#endif -#if defined SMEXT_ENABLE_USERMSGS - SM_GET_IFACE(USERMSGS, usermsgs); -#endif -#if defined SMEXT_ENABLE_TRANSLATOR - SM_GET_IFACE(TRANSLATOR, translator); -#endif - - if (SDK_OnLoad(error, maxlength, late)) - { -#if defined SMEXT_CONF_METAMOD - m_WeAreUnloaded = true; -#endif - return true; - } - - return false; -} - -bool SDKExtension::IsMetamodExtension() -{ -#if defined SMEXT_CONF_METAMOD - return true; -#else - return false; -#endif -} - -void SDKExtension::OnExtensionPauseChange(bool state) -{ -#if defined SMEXT_CONF_METAMOD - m_WeGotPauseChange = true; -#endif - SDK_OnPauseChange(state); -} - -void SDKExtension::OnExtensionsAllLoaded() -{ - SDK_OnAllLoaded(); -} - -void SDKExtension::OnExtensionUnload() -{ -#if defined SMEXT_CONF_METAMOD - m_WeAreUnloaded = true; -#endif - SDK_OnUnload(); -} - -const char *SDKExtension::GetExtensionAuthor() -{ - return SMEXT_CONF_AUTHOR; -} - -const char *SDKExtension::GetExtensionDateString() -{ - return SMEXT_CONF_DATESTRING; -} - -const char *SDKExtension::GetExtensionDescription() -{ - return SMEXT_CONF_DESCRIPTION; -} - -const char *SDKExtension::GetExtensionVerString() -{ - return SMEXT_CONF_VERSION; -} - -const char *SDKExtension::GetExtensionName() -{ - return SMEXT_CONF_NAME; -} - -const char *SDKExtension::GetExtensionTag() -{ - return SMEXT_CONF_LOGTAG; -} - -const char *SDKExtension::GetExtensionURL() -{ - return SMEXT_CONF_URL; -} - -bool SDKExtension::SDK_OnLoad(char *error, size_t maxlength, bool late) -{ - return true; -} - -void SDKExtension::SDK_OnUnload() -{ -} - -void SDKExtension::SDK_OnPauseChange(bool paused) -{ -} - -void SDKExtension::SDK_OnAllLoaded() -{ -} - -#if defined SMEXT_CONF_METAMOD - -PluginId g_PLID = 0; /**< Metamod plugin ID */ -ISmmPlugin *g_PLAPI = NULL; /**< Metamod plugin API */ -SourceHook::ISourceHook *g_SHPtr = NULL; /**< SourceHook pointer */ -ISmmAPI *g_SMAPI = NULL; /**< SourceMM API pointer */ - -IVEngineServer *engine = NULL; /**< IVEngineServer pointer */ -IServerGameDLL *gamedll = NULL; /**< IServerGameDLL pointer */ - -/** Exposes the extension to Metamod */ -SMM_API void *PL_EXPOSURE(const char *name, int *code) -{ -#if defined METAMOD_PLAPI_VERSION - if (name && !strcmp(name, METAMOD_PLAPI_NAME)) -#else - if (name && !strcmp(name, PLAPI_NAME)) -#endif - { - if (code) - { - *code = IFACE_OK; - } - return static_cast(g_pExtensionIface); - } - - if (code) - { - *code = IFACE_FAILED; - } - - return NULL; -} - -bool SDKExtension::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late) -{ - PLUGIN_SAVEVARS(); - -#if !defined METAMOD_PLAPI_VERSION - GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); - GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); -#else - GET_V_IFACE_ANY(GetServerFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); - GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); -#endif - - m_SourceMMLoaded = true; - - return SDK_OnMetamodLoad(ismm, error, maxlen, late); -} - -bool SDKExtension::Unload(char *error, size_t maxlen) -{ - if (!m_WeAreUnloaded) - { - if (error) - { - snprintf(error, maxlen, "This extension must be unloaded by SourceMod."); - } - return false; - } - - return SDK_OnMetamodUnload(error, maxlen); -} - -bool SDKExtension::Pause(char *error, size_t maxlen) -{ - if (!m_WeGotPauseChange) - { - if (error) - { - snprintf(error, maxlen, "This extension must be paused by SourceMod."); - } - return false; - } - - m_WeGotPauseChange = false; - - return SDK_OnMetamodPauseChange(true, error, maxlen); -} - -bool SDKExtension::Unpause(char *error, size_t maxlen) -{ - if (!m_WeGotPauseChange) - { - if (error) - { - snprintf(error, maxlen, "This extension must be unpaused by SourceMod."); - } - return false; - } - - m_WeGotPauseChange = false; - - return SDK_OnMetamodPauseChange(false, error, maxlen); -} - -const char *SDKExtension::GetAuthor() -{ - return GetExtensionAuthor(); -} - -const char *SDKExtension::GetDate() -{ - return GetExtensionDateString(); -} - -const char *SDKExtension::GetDescription() -{ - return GetExtensionDescription(); -} - -const char *SDKExtension::GetLicense() -{ - return SMEXT_CONF_LICENSE; -} - -const char *SDKExtension::GetLogTag() -{ - return GetExtensionTag(); -} - -const char *SDKExtension::GetName() -{ - return GetExtensionName(); -} - -const char *SDKExtension::GetURL() -{ - return GetExtensionURL(); -} - -const char *SDKExtension::GetVersion() -{ - return GetExtensionVerString(); -} - -bool SDKExtension::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late) -{ - return true; -} - -bool SDKExtension::SDK_OnMetamodUnload(char *error, size_t maxlength) -{ - return true; -} - -bool SDKExtension::SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength) -{ - return true; -} - -#endif - -/* Overload a few things to prevent libstdc++ linking */ -#if defined __linux__ || defined __APPLE__ -extern "C" void __cxa_pure_virtual(void) -{ -} - -void *operator new(size_t size) -{ - return malloc(size); -} - -void *operator new[](size_t size) -{ - return malloc(size); -} - -void operator delete(void *ptr) noexcept -{ - free(ptr); -} - -void operator delete[](void * ptr) noexcept -{ - free(ptr); -} -#endif - diff --git a/extension/sdk/smsdk_ext.hpp b/extension/sdk/smsdk_ext.hpp deleted file mode 100644 index a3de9b3..0000000 --- a/extension/sdk/smsdk_ext.hpp +++ /dev/null @@ -1,339 +0,0 @@ -/** - * vim: set ts=4 : - * ============================================================================= - * SourceMod Base Extension Code - * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. - * ============================================================================= - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, version 3.0, as published by the - * Free Software Foundation. - * - * This program 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 - * this program. If not, see . - * - * As a special exception, AlliedModders LLC gives you permission to link the - * code of this program (as well as its derivative works) to "Half-Life 2," the - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software - * by the Valve Corporation. You must obey the GNU General Public License in - * all respects for all other code used. Additionally, AlliedModders LLC grants - * this exception to all derivative works. AlliedModders LLC defines further - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), - * or . - * - * Version: $Id$ - */ - -#ifndef _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_ -#define _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_ - -/** - * @file smsdk_ext.hpp - * @brief Contains wrappers for making Extensions easier to write. - */ - -#include "smsdk_config.hpp" -#include -#include -#include -#include -#include -#if defined SMEXT_ENABLE_FORWARDSYS -#include -#endif //SMEXT_ENABLE_FORWARDSYS -#if defined SMEXT_ENABLE_PLAYERHELPERS -#include -#endif //SMEXT_ENABLE_PlAYERHELPERS -#if defined SMEXT_ENABLE_DBMANAGER -#include -#endif //SMEXT_ENABLE_DBMANAGER -#if defined SMEXT_ENABLE_GAMECONF -#include -#endif -#if defined SMEXT_ENABLE_MEMUTILS -#include -#endif -#if defined SMEXT_ENABLE_GAMEHELPERS -#include -#endif -#if defined SMEXT_ENABLE_TIMERSYS -#include -#endif -#if defined SMEXT_ENABLE_ADTFACTORY -#include -#endif -#if defined SMEXT_ENABLE_THREADER -#include -#endif -#if defined SMEXT_ENABLE_LIBSYS -#include -#endif -#if defined SMEXT_ENABLE_PLUGINSYS -#include -#endif -#if defined SMEXT_ENABLE_MENUS -#include -#endif -#if defined SMEXT_ENABLE_ADMINSYS -#include -#endif -#if defined SMEXT_ENABLE_TEXTPARSERS -#include -#endif -#if defined SMEXT_ENABLE_USERMSGS -#include -#endif -#if defined SMEXT_ENABLE_TRANSLATOR -#include -#endif -#if defined SMEXT_ENABLE_NINVOKE -#include -#endif - -#if defined SMEXT_CONF_METAMOD -#include -#include -#endif - -using namespace SourceMod; -using namespace SourcePawn; - -class SDKExtension : -#if defined SMEXT_CONF_METAMOD - public ISmmPlugin, -#endif - public IExtensionInterface -{ -public: - /** Constructor */ - SDKExtension(); -public: - /** - * @brief This is called after the initial loading sequence has been processed. - * - * @param error Error message buffer. - * @param maxlength Size of error message buffer. - * @param late Whether or not the module was loaded after map load. - * @return True to succeed loading, false to fail. - */ - virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late); - - /** - * @brief This is called right before the extension is unloaded. - */ - virtual void SDK_OnUnload(); - - /** - * @brief This is called once all known extensions have been loaded. - */ - virtual void SDK_OnAllLoaded(); - - /** - * @brief Called when the pause state is changed. - */ - virtual void SDK_OnPauseChange(bool paused); - -#if defined SMEXT_CONF_METAMOD - /** - * @brief Called when Metamod is attached, before the extension version is called. - * - * @param error Error buffer. - * @param maxlength Maximum size of error buffer. - * @param late Whether or not Metamod considers this a late load. - * @return True to succeed, false to fail. - */ - virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late); - - /** - * @brief Called when Metamod is detaching, after the extension version is called. - * NOTE: By default this is blocked unless sent from SourceMod. - * - * @param error Error buffer. - * @param maxlength Maximum size of error buffer. - * @return True to succeed, false to fail. - */ - virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength); - - /** - * @brief Called when Metamod's pause state is changing. - * NOTE: By default this is blocked unless sent from SourceMod. - * - * @param paused Pause state being set. - * @param error Error buffer. - * @param maxlength Maximum size of error buffer. - * @return True to succeed, false to fail. - */ - virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength); -#endif - -public: //IExtensionInterface - virtual bool OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late); - virtual void OnExtensionUnload(); - virtual void OnExtensionsAllLoaded(); - - /** Returns whether or not this is a Metamod-based extension */ - virtual bool IsMetamodExtension(); - - /** - * @brief Called when the pause state changes. - * - * @param state True if being paused, false if being unpaused. - */ - virtual void OnExtensionPauseChange(bool state); - - /** Returns name */ - virtual const char *GetExtensionName(); - /** Returns URL */ - virtual const char *GetExtensionURL(); - /** Returns log tag */ - virtual const char *GetExtensionTag(); - /** Returns author */ - virtual const char *GetExtensionAuthor(); - /** Returns version string */ - virtual const char *GetExtensionVerString(); - /** Returns description string */ - virtual const char *GetExtensionDescription(); - /** Returns date string */ - virtual const char *GetExtensionDateString(); -#if defined SMEXT_CONF_METAMOD -public: //ISmmPlugin - /** Called when the extension is attached to Metamod. */ - virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlength, bool late); - /** Returns the author to MM */ - virtual const char *GetAuthor(); - /** Returns the name to MM */ - virtual const char *GetName(); - /** Returns the description to MM */ - virtual const char *GetDescription(); - /** Returns the URL to MM */ - virtual const char *GetURL(); - /** Returns the license to MM */ - virtual const char *GetLicense(); - /** Returns the version string to MM */ - virtual const char *GetVersion(); - /** Returns the date string to MM */ - virtual const char *GetDate(); - /** Returns the logtag to MM */ - virtual const char *GetLogTag(); - /** Called on unload */ - virtual bool Unload(char *error, size_t maxlength); - /** Called on pause */ - virtual bool Pause(char *error, size_t maxlength); - /** Called on unpause */ - virtual bool Unpause(char *error, size_t maxlength); -private: - bool m_SourceMMLoaded; - bool m_WeAreUnloaded; - bool m_WeGotPauseChange; -#endif -}; - -extern SDKExtension *g_pExtensionIface; -extern IExtension *myself; - -extern IShareSys *g_pShareSys; -extern IShareSys *sharesys; /* Note: Newer name */ -extern ISourceMod *g_pSM; -extern ISourceMod *smutils; /* Note: Newer name */ - -/* Optional interfaces are below */ -#if defined SMEXT_ENABLE_FORWARDSYS -extern IForwardManager *g_pForwards; -extern IForwardManager *forwards; /* Note: Newer name */ -#endif //SMEXT_ENABLE_FORWARDSYS -#if defined SMEXT_ENABLE_HANDLESYS -extern IHandleSys *g_pHandleSys; -extern IHandleSys *handlesys; /* Note: Newer name */ -#endif //SMEXT_ENABLE_HANDLESYS -#if defined SMEXT_ENABLE_PLAYERHELPERS -extern IPlayerManager *playerhelpers; -#endif //SMEXT_ENABLE_PLAYERHELPERS -#if defined SMEXT_ENABLE_DBMANAGER -extern IDBManager *dbi; -#endif //SMEXT_ENABLE_DBMANAGER -#if defined SMEXT_ENABLE_GAMECONF -extern IGameConfigManager *gameconfs; -#endif //SMEXT_ENABLE_DBMANAGER -#if defined SMEXT_ENABLE_MEMUTILS -extern IMemoryUtils *memutils; -#endif -#if defined SMEXT_ENABLE_GAMEHELPERS -extern IGameHelpers *gamehelpers; -#endif -#if defined SMEXT_ENABLE_TIMERSYS -extern ITimerSystem *timersys; -#endif -#if defined SMEXT_ENABLE_ADTFACTORY -extern IADTFactory *adtfactory; -#endif -#if defined SMEXT_ENABLE_THREADER -extern IThreader *threader; -#endif -#if defined SMEXT_ENABLE_LIBSYS -extern ILibrarySys *libsys; -#endif -#if defined SMEXT_ENABLE_PLUGINSYS -extern SourceMod::IPluginManager *plsys; -#endif -#if defined SMEXT_ENABLE_MENUS -extern IMenuManager *menus; -#endif -#if defined SMEXT_ENABLE_ADMINSYS -extern IAdminSystem *adminsys; -#endif -#if defined SMEXT_ENABLE_USERMSGS -extern IUserMessages *usermsgs; -#endif -#if defined SMEXT_ENABLE_TRANSLATOR -extern ITranslator *translator; -#endif -#if defined SMEXT_ENABLE_NINVOKE -extern INativeInterface *ninvoke; -#endif - -#if defined SMEXT_CONF_METAMOD -PLUGIN_GLOBALVARS(); -extern IVEngineServer *engine; -extern IServerGameDLL *gamedll; -#endif - -/** Creates a SourceMod interface macro pair */ -#define SM_MKIFACE(name) SMINTERFACE_##name##_NAME, SMINTERFACE_##name##_VERSION -/** Automates retrieving SourceMod interfaces */ -#define SM_GET_IFACE(prefix, addr) \ - if (!g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)) \ - { \ - if (error != NULL && maxlength) \ - { \ - size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \ - if (len >= maxlength) \ - { \ - error[maxlength - 1] = '\0'; \ - } \ - } \ - return false; \ - } -/** Automates retrieving SourceMod interfaces when needed outside of SDK_OnLoad() */ -#define SM_GET_LATE_IFACE(prefix, addr) \ - g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr) -/** Validates a SourceMod interface pointer */ -#define SM_CHECK_IFACE(prefix, addr) \ - if (!addr) \ - { \ - if (error != NULL && maxlength) \ - { \ - size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \ - if (len >= maxlength) \ - { \ - error[maxlength - 1] = '\0'; \ - } \ - } \ - return false; \ - } - -#endif // _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_ diff --git a/hl2sdk-manifests b/hl2sdk-manifests index 2ae4644..c018a99 160000 --- a/hl2sdk-manifests +++ b/hl2sdk-manifests @@ -1 +1 @@ -Subproject commit 2ae4644db6459ae16da7e3900260bbd6aa7ba03d +Subproject commit c018a994478d6c31f70ded7adec7aa9e2c40bb1a diff --git a/tf2.items.txt b/tf2.items.txt index 13a3235..e79ae11 100644 --- a/tf2.items.txt +++ b/tf2.items.txt @@ -6,10 +6,10 @@ { "GiveNamedItem" { - "windows" "486" - "windows64" "486" - "linux" "493" - "linux64" "493" + "windows64" "487" + "windows" "487" + "linux" "494" + "linux64" "494" } } }