diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ffdcf3a..81066e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-20.04] - sourcemod-version: [1.11-dev] + sourcemod-version: [master] include: - os: ubuntu-20.04 target-archs: x86,x86_64 @@ -24,15 +24,16 @@ jobs: sudo apt install -yq --no-install-recommends g++-multilib - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: + submodules: recursive path: extension - name: Checkout SourceMod - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: alliedmodders/sourcemod ref: ${{ matrix.sourcemod-version }} @@ -40,20 +41,20 @@ jobs: submodules: recursive - name: Checkout AMBuild - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: alliedmodders/ambuild path: ambuild - name: Checkout sm-ext-common - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: srcdslab/sm-ext-common path: sourcemod/extensions/sm-ext-common - name: Install sourcemod dependencies run: | - bash sourcemod/tools/checkout-deps.sh -m -s ${{ matrix.sdks }} + bash sourcemod/tools/checkout-deps.sh -m -s "${{ matrix.sdks }}" - name: Install AMBuild uses: BSFishy/pip-action@v1 @@ -67,15 +68,26 @@ jobs: BREAKPAD_SYMBOL_SERVER: ${{ secrets.BREAKPAD_SYMBOL_SERVER }} run: | mkdir build && cd build - python ../configure.py --enable-optimize --targets=${{ matrix.target-archs }} --sdks=${{ matrix.sdks }} + python ../configure.py --enable-optimize --targets=${{ matrix.target-archs }} --sdks="${{ matrix.sdks }}" ambuild + - name: Prepare artifact structure + run: | + # linux-x86_64 + mkdir -p artifact/linux-x86_64/addons/sourcemod/extensions + cp -r extension/addons/sourcemod/* artifact/linux-x86_64/addons/sourcemod/ + cp extension/build/CSSFixes.ext.2.css/linux-x86_64/CSSFixes.ext.2.css.so artifact/linux-x86_64/addons/sourcemod/extensions/ + # linux-x86 + mkdir -p artifact/linux-x86/addons/sourcemod/extensions + cp -r extension/addons/sourcemod/* artifact/linux-x86/addons/sourcemod/ + cp extension/build/CSSFixes.ext.2.css/linux-x86/CSSFixes.ext.2.css.so artifact/linux-x86/addons/sourcemod/extensions/ + - name: Upload artifact uses: actions/upload-artifact@v4 with: - name: ${{ runner.os }} - path: extension/build/package - + name: CSSFixes + path: artifact/** + if-no-files-found: error release: name: Release @@ -85,22 +97,22 @@ jobs: steps: - name: Download artifacts - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4 - name: Package run: | version=`echo $GITHUB_REF | sed "s/refs\/tags\///"` if [ -d "./Linux/" ]; then cd ./Linux/ - tar -czf ../${{ github.event.repository.name }}-${version}-linux.tar.gz -T <(\ls -1) + tar -czf ../${{ github.event.repository.name }}-${version}-linux.tar.gz -T <(\ls -) fi if [ -d "./macOS/" ]; then cd ./macOS/ - tar -czf ../${{ github.event.repository.name }}-${version}-mac.tar.gz -T <(\ls -1) + tar -czf ../${{ github.event.repository.name }}-${version}-mac.tar.gz -T <(\ls -) fi if [ -d "./Windows/" ]; then cd ./Windows/ - tar -czf ../${{ github.event.repository.name }}-${version}-windows.tar.gz -T <(\ls -1) + tar -czf ../${{ github.event.repository.name }}-${version}-windows.tar.gz -T <(\ls -) fi - name: Release diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d789c86 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*build/ +*vs diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..9abf89d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "hl2sdk-manifests"] + path = hl2sdk-manifests + url = https://github.com/alliedmodders/hl2sdk-manifests diff --git a/AMBuildScript b/AMBuildScript index 23e2389..d95ac20 100644 --- a/AMBuildScript +++ b/AMBuildScript @@ -1,39 +1,5 @@ # vim: set sts=2 ts=8 sw=2 tw=99 et ft=python: -import os, sys -import traceback - -class SDK(object): - def __init__(self, sdk, ext, aDef, name, platform, dir): - self.folder = 'hl2sdk-' + dir - self.envvar = sdk - self.ext = ext - self.code = aDef - self.define = name - self.platform = platform - self.name = dir - self.path = None # Actual path - self.platformSpec = platform - - # By default, nothing supports x64. - if type(platform) is list: - self.platformSpec = {p: ['x86'] for p in platform} - else: - self.platformSpec = platform - - def shouldBuild(self, targets): - for cxx in targets: - if cxx.target.platform in self.platformSpec: - if cxx.target.arch in self.platformSpec[cxx.target.platform]: - return True - return False - -WinOnly = ['windows'] -WinLinux = ['windows', 'linux'] -WinLinuxMac = ['windows', 'linux', 'mac'] - -PossibleSDKs = { - 'css': SDK('HL2SDKCSS', '2.css', '6', 'CSS', WinLinuxMac, 'css'), -} +import os def ResolveEnvPath(env, folder): if env in os.environ: @@ -64,30 +30,43 @@ def SetArchFlags(compiler): if compiler.target.arch == 'x86_64': compiler.defines += ['WIN64'] +hl2sdk_manifests_path = None + +# First we check if the manifest exists in the current path +hl2sdk_manifests_path = os.path.join(builder.sourcePath, 'hl2sdk-manifests/SdkHelpers.ambuild') + +if not os.path.exists(hl2sdk_manifests_path): + # manifests does not exists in the project file, use the path from --hl2sdk-manifest-path + if not builder.options.hl2sdk_manifest: + raise Exception('HL2SDK Manifest root path not set! (--hl2sdk-manifest-path)') + else: + hl2sdk_manifests_path = os.path.join(builder.options.hl2sdk_manifest, 'SdkHelpers.ambuild') + + if not os.path.exists(hl2sdk_manifests_path): + raise Exception('Could not find SdkHelpers.ambuild in the given HL2SDK Manifest path!') + + +SdkHelpers = builder.Eval(hl2sdk_manifests_path, { + 'Project': 'sm-extension' +}) + class ExtensionConfig(object): def __init__(self): + self.sdk_manifests = [] self.sdks = {} - self.binaries = [] - self.spvm = [] + self.sdk_targets = [] self.extensions = [] self.generated_headers = None - self.sm_root = None self.mms_root = None - self.mysql_root = {} - self.spcomp = None - self.spcomp_bins = None - self.smx_files = {} - self.versionlib = None + self.sm_root = None self.all_targets = [] self.target_archs = set() - + self.libsafetyhook = {} if builder.options.targets: target_archs = builder.options.targets.split(',') else: - target_archs = ['x86'] - if builder.backend != 'amb2': - target_archs.append('x86_64') + target_archs = ['x86', 'x86_64'] for arch in target_archs: try: @@ -104,82 +83,73 @@ class ExtensionConfig(object): if not self.all_targets: raise Exception('No suitable C/C++ compiler was found.') + def use_auto_versioning(self): + if builder.backend != 'amb2': + return False + return not getattr(builder.options, 'disable_auto_versioning', False) + @property def tag(self): if builder.options.debug == '1': return 'Debug' return 'Release' - def detectProductVersion(self): - builder.AddConfigureFile('product.version') + 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) - # For OS X dylib versioning - import re - with open(os.path.join(builder.sourcePath, 'product.version'), 'r') as fp: - productContents = fp.read() - m = re.match('(\d+)\.(\d+)\.(\d+).*', productContents) - if m == None: - self.productVersion = '1.0.0' - else: - major, minor, release = m.groups() - self.productVersion = '{0}.{1}.{2}'.format(major, minor, release) + def shouldIncludeSdk(self, sdk): + return not sdk.get('source2', False) def detectSDKs(self): - sdk_list = builder.options.sdks.split(',') - use_none = sdk_list[0] == 'none' - use_all = sdk_list[0] == 'all' - use_present = sdk_list[0] == 'present' + sdk_list = [s for s in builder.options.sdks.split(',') if s] + SdkHelpers.sdk_filter = self.shouldIncludeSdk + SdkHelpers.find_sdk_path = self.findSdkPath + SdkHelpers.findSdks(builder, self.all_targets, sdk_list) - for sdk_name in PossibleSDKs: - sdk = PossibleSDKs[sdk_name] - if sdk.shouldBuild(self.all_targets): - if builder.options.hl2sdk_root: - sdk_path = os.path.join(builder.options.hl2sdk_root, sdk.folder) - else: - sdk_path = ResolveEnvPath(sdk.envvar, sdk.folder) - if sdk_path is None or not os.path.isdir(sdk_path): - if use_all or sdk_name in sdk_list: - raise Exception('Could not find a valid path for {0}'.format(sdk.envvar)) - continue - if use_all or use_present or sdk_name in sdk_list: - sdk.path = Normalize(sdk_path) - self.sdks[sdk_name] = sdk - - if len(self.sdks) < 1 and len(sdk_list) and not use_none: - raise Exception('No applicable SDKs were found, nothing to do') - - if builder.options.sm_path: - self.sm_root = builder.options.sm_path - else: - self.sm_root = ResolveEnvPath('SOURCEMOD18', 'sourcemod-1.10') - if not self.sm_root: - self.sm_root = ResolveEnvPath('SOURCEMOD', 'sourcemod-source') - if not self.sm_root: - self.sm_root = ResolveEnvPath('SOURCEMOD_DEV', 'sourcemod-central') - if not self.sm_root: - 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) + self.sdks = SdkHelpers.sdks + self.sdk_manifests = SdkHelpers.sdk_manifests + self.sdk_targets = SdkHelpers.sdk_targets if builder.options.mms_path: self.mms_root = builder.options.mms_path else: - self.mms_root = ResolveEnvPath('MMSOURCE110', 'mmsource-1.10') + self.mms_root = ResolveEnvPath('MMSOURCE112', 'mmsource-1.12') + if not self.mms_root: + self.mms_root = ResolveEnvPath('MMSOURCE', 'metamod-source') if not self.mms_root: self.mms_root = ResolveEnvPath('MMSOURCE_DEV', 'metamod-source') if not self.mms_root: self.mms_root = ResolveEnvPath('MMSOURCE_DEV', 'mmsource-central') - if not self.mms_root: - self.mms_root = ResolveEnvPath('MMSOURCE_DEV', 'metamod') 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) + if builder.options.sm_path: + self.sm_root = builder.options.sm_path + else: + self.sm_root = ResolveEnvPath('SOURCEMOD112', 'sourcemod-1.12') + if not self.sm_root: + self.sm_root = ResolveEnvPath('SOURCEMOD', 'sourcemod') + if not self.sm_root: + self.sm_root = ResolveEnvPath('SOURCEMOD_DEV', 'sourcemod') + if not self.sm_root: + self.sm_root = ResolveEnvPath('SOURCEMOD_DEV', 'sourcemod-central') + + 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 configure(self): - if not set(self.target_archs).issubset(['x86', 'x86_64']): + + allowed_archs = ['x86','x86_64'] + + if not set(self.target_archs).issubset(allowed_archs): raise Exception('Unknown target architecture: {0}'.format(self.target_archs)) for cxx in self.all_targets: @@ -187,21 +157,21 @@ class ExtensionConfig(object): def configure_cxx(self, cxx): if cxx.family == 'msvc': - if cxx.version < 1900: - raise Exception('Only MSVC 2015 and later are supported, c++14 support is required.') - if cxx.family == 'gcc': - if cxx.version < 'gcc-4.9': - raise Exception('Only GCC versions 4.9 or greater are supported, c++14 support is required.') - if cxx.family == 'clang': - if cxx.version < 'clang-3.4': - raise Exception('Only clang versions 3.4 or greater are supported, c++14 support is required.') + if cxx.version < 1914 and builder.options.generator != 'vs': + raise Exception(f'Only MSVC 2017 15.7 and later are supported, full C++17 support is required. ({str(cxx.version)} < 1914)') + elif cxx.family == 'gcc': + if cxx.version < 'gcc-8': + raise Exception('Only GCC versions 8 or later are supported, full C++17 support is required.') + elif cxx.family == 'clang': + if cxx.version < 'clang-5': + raise Exception('Only clang versions 5 or later are supported, full C++17 support is required.') if cxx.like('gcc'): self.configure_gcc(cxx) elif cxx.family == 'msvc': self.configure_msvc(cxx) - # Optimizaiton + # Optimization if builder.options.opt == '1': cxx.defines += ['NDEBUG'] @@ -217,11 +187,6 @@ class ExtensionConfig(object): elif cxx.target.platform == 'windows': self.configure_windows(cxx) - # Finish up. - cxx.includes += [ - os.path.join(self.sm_root, 'public'), - ] - def configure_gcc(self, cxx): cxx.defines += [ 'stricmp=strcasecmp', @@ -239,50 +204,31 @@ class ExtensionConfig(object): '-Wno-unused', '-Wno-switch', '-Wno-array-bounds', - '-msse', '-fvisibility=hidden', ] - if cxx.version == 'apple-clang-6.0' or cxx.version == 'clang-3.4': - cxx.cxxflags += ['-std=c++1y'] - else: - cxx.cxxflags += ['-std=c++14'] + if cxx.target.arch in ['x86', 'x86_64']: + cxx.cflags += ['-msse'] cxx.cxxflags += [ '-fno-threadsafe-statics', '-Wno-non-virtual-dtor', '-Wno-overloaded-virtual', + '-Wno-register', '-fvisibility-inlines-hidden', + '-std=c++17', ] + have_gcc = cxx.family == 'gcc' have_clang = cxx.family == 'clang' - if cxx.version >= 'clang-3.9' or cxx.version == 'clang-3.4' or cxx.version > 'apple-clang-6.0': - cxx.cxxflags += ['-Wno-expansion-to-defined'] - if cxx.version == 'clang-3.9' or cxx.version == 'apple-clang-8.0': - cxx.cflags += ['-Wno-varargs'] - if cxx.version >= 'clang-3.4' or cxx.version >= 'apple-clang-7.0': - cxx.cxxflags += ['-Wno-inconsistent-missing-override'] - if cxx.version >= 'clang-2.9' or cxx.version >= 'apple-clang-3.0': - cxx.cxxflags += ['-Wno-null-dereference'] - if have_clang or (cxx.version >= 'gcc-4.6'): - cxx.cflags += ['-Wno-narrowing'] - if have_clang or (cxx.version >= 'gcc-4.7'): - cxx.cxxflags += ['-Wno-delete-non-virtual-dtor'] - if cxx.version >= 'gcc-4.8': - cxx.cflags += ['-Wno-unused-result'] - if cxx.version >= 'gcc-9.0': - cxx.cxxflags += ['-Wno-class-memaccess', '-Wno-packed-not-aligned'] + + # Work around errors from smsdk_ext.cpp if have_clang: cxx.cxxflags += ['-Wno-implicit-exception-spec-mismatch'] - if cxx.version >= 'apple-clang-5.1' or cxx.version >= 'clang-3.4': - cxx.cxxflags += ['-Wno-deprecated-register'] - else: - cxx.cxxflags += ['-Wno-deprecated'] - cxx.cflags += ['-Wno-sometimes-uninitialized'] # Work around SDK warnings. - if cxx.version >= 'clang-10.0': + if cxx.version >= 'clang-10.0' or cxx.version >= 'apple-clang-12.0': cxx.cflags += [ '-Wno-implicit-int-float-conversion', '-Wno-tautological-overlap-compare', @@ -293,20 +239,13 @@ class ExtensionConfig(object): cxx.cflags += ['-Wno-maybe-uninitialized'] if builder.options.opt == '1': - cxx.cflags += [ - '-O3', - '-fexperimental-new-pass-manager', - '-mllvm', - '-inline-threshold=1000', - '-mllvm', - '-vectorize-loops', - '-ftree-vectorize', - ] + cxx.cflags += ['-O3'] # Don't omit the frame pointer. cxx.cflags += ['-fno-omit-frame-pointer'] def configure_msvc(self, cxx): + if builder.options.debug == '1': cxx.cflags += ['/MTd'] cxx.linkflags += ['/NODEFAULTLIB:libcmt'] @@ -325,6 +264,7 @@ class ExtensionConfig(object): '/EHsc', '/GR-', '/TP', + '/std:c++17', ] cxx.linkflags += [ 'kernel32.lib', @@ -353,7 +293,7 @@ class ExtensionConfig(object): cxx.cflags += ['/Oy-'] def configure_linux(self, cxx): - cxx.defines += ['_LINUX', 'POSIX', '_FILE_OFFSET_BITS=64'] + cxx.defines += ['LINUX', '_LINUX', 'POSIX', '_FILE_OFFSET_BITS=64'] cxx.linkflags += ['-lm'] if cxx.family == 'gcc': cxx.linkflags += ['-static-libgcc'] @@ -363,9 +303,9 @@ class ExtensionConfig(object): def configure_mac(self, cxx): cxx.defines += ['OSX', '_OSX', 'POSIX', 'KE_ABSOLUTELY_NO_STL'] - cxx.cflags += ['-mmacosx-version-min=10.7'] + cxx.cflags += ['-mmacosx-version-min=10.15'] cxx.linkflags += [ - '-mmacosx-version-min=10.7', + '-mmacosx-version-min=10.15', '-stdlib=libc++', '-lc++', ] @@ -373,70 +313,20 @@ class ExtensionConfig(object): def configure_windows(self, cxx): cxx.defines += ['WIN32', '_WINDOWS'] - - def add_libamtl(self): - # Add libamtl. - self.libamtl = {} - for cxx in self.all_targets: - def get_configure_fn(cxx): - return lambda builder, name: self.StaticLibrary(builder, cxx, name) - extra_vars = {'Configure': get_configure_fn(cxx)} - libamtl = builder.Build('public/amtl/amtl/AMBuilder', extra_vars) - self.libamtl[cxx.target.arch] = libamtl.binary - - def AddVersioning(self, binary): - if binary.compiler.target.platform == 'windows': - binary.sources += ['version.rc'] - binary.compiler.rcdefines += [ - 'BINARY_NAME="{0}"'.format(binary.outputFile), - 'RC_COMPILE', - ] - elif binary.compiler.target.platform == 'mac': - if binary.type == 'library': - binary.compiler.postlink += [ - '-compatibility_version', '1.0.0', - '-current_version', self.productVersion - ] - return binary def LibraryBuilder(self, compiler, name): binary = compiler.Library(name) self.AddVersioning(binary) if binary.compiler.like('msvc'): binary.compiler.linkflags += ['/SUBSYSTEM:WINDOWS'] + self.AddCxxCompat(binary) return binary - def ProgramBuilder(self, compiler, name): - binary = compiler.Program(name) - self.AddVersioning(binary) - if '-static-libgcc' in binary.compiler.linkflags: - binary.compiler.linkflags.remove('-static-libgcc') - if '-lgcc_eh' in binary.compiler.linkflags: - binary.compiler.linkflags.remove('-lgcc_eh') - if binary.compiler.like('gcc'): - binary.compiler.linkflags += ['-lstdc++', '-lpthread'] - if binary.compiler.like('msvc'): - binary.compiler.linkflags += ['/SUBSYSTEM:CONSOLE'] - return binary - - def StaticLibraryBuilder(self, compiler, name): - return compiler.StaticLibrary(name) - def Library(self, context, compiler, name): compiler = compiler.clone() SetArchFlags(compiler) return self.LibraryBuilder(compiler, name) - def Program(self, context, compiler, name): - compiler = compiler.clone() - SetArchFlags(compiler) - return self.ProgramBuilder(compiler, name) - - def StaticLibrary(self, context, compiler, name): - compiler = compiler.clone() - SetArchFlags(compiler) - return self.StaticLibraryBuilder(compiler, name) - def ConfigureForExtension(self, context, compiler): compiler.cxxincludes += [ os.path.join(context.currentSourcePath), @@ -446,9 +336,27 @@ class ExtensionConfig(object): os.path.join(self.sm_root, 'sourcepawn', 'include'), os.path.join(self.sm_root, 'public', 'amtl', 'amtl'), os.path.join(self.sm_root, 'public', 'amtl'), - os.path.join(self.sm_root, 'extensions', 'sm-ext-common', 'include'), ] return compiler + + def AddCDetour(self, binary): + public_path = os.path.join(self.sm_root, 'public') + binary.sources += [ + os.path.join(public_path, 'CDetour', 'detours.cpp'), + os.path.join(public_path, 'safetyhook', 'src', 'allocator.cpp'), + os.path.join(public_path, 'safetyhook', 'src', 'easy.cpp'), + os.path.join(public_path, 'safetyhook', 'src', 'inline_hook.cpp'), + os.path.join(public_path, 'safetyhook', 'src', 'mid_hook.cpp'), + os.path.join(public_path, 'safetyhook', 'src', 'os.linux.cpp'), + os.path.join(public_path, 'safetyhook', 'src', 'utility.cpp'), + os.path.join(public_path, 'safetyhook', 'src', 'vmt_hook.cpp'), + os.path.join(public_path, 'safetyhook', 'zydis', 'Zydis.c') + ] + + binary.compiler.includes += [ + os.path.join(public_path, 'safetyhook', 'include'), + os.path.join(public_path, 'safetyhook', 'zydis'), + ] def ExtLibrary(self, context, compiler, name): binary = self.Library(context, compiler, name) @@ -456,6 +364,12 @@ class ExtensionConfig(object): self.ConfigureForExtension(context, binary.compiler) return binary + def AddCxxCompat(self, binary): + if binary.compiler.target.platform == 'linux': + binary.sources += [ + os.path.join(self.sm_root, 'public', 'amtl', 'compat', 'stdcxx.cpp'), + ] + def ConfigureForHL2(self, context, binary, sdk): compiler = binary.compiler SetArchFlags(compiler) @@ -465,134 +379,10 @@ class ExtensionConfig(object): os.path.join(self.mms_root, 'core', 'sourcehook'), ] - defines = ['SE_' + PossibleSDKs[i].define + '=' + PossibleSDKs[i].code for i in PossibleSDKs] - compiler.defines += defines + for other_sdk in self.sdk_manifests: + compiler.defines += ['SE_{}={}'.format(other_sdk['define'], other_sdk['code'])] - paths = [ - ['public'], - ['public', 'engine'], - ['public', 'mathlib'], - ['public', 'vstdlib'], - ['public', 'tier0'], - ['public', 'tier1'] - ] - if sdk.name == 'episode1' or sdk.name == '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']) - - compiler.defines += ['SOURCE_ENGINE=' + sdk.code] - - if sdk.name in ['sdk2013', 'bms'] and compiler.like('gcc'): - # The 2013 SDK already has these in public/tier0/basetypes.h - compiler.defines.remove('stricmp=strcasecmp') - compiler.defines.remove('_stricmp=strcasecmp') - compiler.defines.remove('_snprintf=snprintf') - compiler.defines.remove('_vsnprintf=vsnprintf') - - if compiler.like('msvc'): - compiler.defines += ['COMPILER_MSVC'] - if compiler.target.arch == 'x86': - compiler.defines += ['COMPILER_MSVC32'] - elif compiler.target.arch == 'x86_64': - compiler.defines += ['COMPILER_MSVC64'] - compiler.linkflags += ['legacy_stdio_definitions.lib'] - else: - compiler.defines += ['COMPILER_GCC'] - - if compiler.target.arch == 'x86_64': - compiler.defines += ['X64BITS', 'PLATFORM_64BITS'] - - # For everything after Swarm, this needs to be defined for entity networking - # to work properly with sendprop value changes. - if sdk.name in ['blade', 'insurgency', 'doi', 'csgo']: - compiler.defines += ['NETWORK_VARS_ENABLED'] - - if sdk.name in ['css', 'hl2dm', 'dods', 'sdk2013', 'bms', 'tf2', 'l4d', 'nucleardawn', 'l4d2']: - if compiler.target.platform in ['linux', 'mac']: - compiler.defines += ['NO_HOOK_MALLOC', 'NO_MALLOC_OVERRIDE'] - - if compiler.target.platform == 'linux': - if sdk.name in ['csgo', 'blade']: - compiler.linkflags.remove('-static-libstdc++') - compiler.defines += ['_GLIBCXX_USE_CXX11_ABI=0'] - - for path in paths: - compiler.cxxincludes += [os.path.join(sdk.path, *path)] - - if compiler.target.platform == 'linux': - if sdk.name == 'episode1': - lib_folder = os.path.join(sdk.path, 'linux_sdk') - elif sdk.name in ['sdk2013', 'bms']: - lib_folder = os.path.join(sdk.path, 'lib', 'public', 'linux32') - elif compiler.target.arch == 'x86_64': - lib_folder = os.path.join(sdk.path, 'lib', 'linux64') - else: - lib_folder = os.path.join(sdk.path, 'lib', 'linux') - elif compiler.target.platform == 'mac': - if sdk.name in ['sdk2013', 'bms']: - lib_folder = os.path.join(sdk.path, 'lib', 'public', 'osx32') - elif compiler.target.arch == 'x86_64': - lib_folder = os.path.join(sdk.path, 'lib', 'osx64') - else: - lib_folder = os.path.join(sdk.path, 'lib', 'mac') - - if compiler.target.platform in ['linux', 'mac']: - if sdk.name in ['sdk2013', 'bms'] or compiler.target.arch == 'x86_64': - compiler.postlink += [ - os.path.join(lib_folder, 'tier1.a'), - os.path.join(lib_folder, 'mathlib.a') - ] - else: - compiler.postlink += [ - os.path.join(lib_folder, 'tier1_i486.a'), - os.path.join(lib_folder, 'mathlib_i486.a') - ] - - if sdk.name in ['blade', 'insurgency', 'doi', 'csgo']: - if compiler.target.arch == 'x86_64': - compiler.postlink += [os.path.join(lib_folder, 'interfaces.a')] - else: - compiler.postlink += [os.path.join(lib_folder, 'interfaces_i486.a')] - - dynamic_libs = [] - if compiler.target.platform == 'linux': - if sdk.name in ['css', 'hl2dm', 'dods', 'tf2', 'sdk2013', 'bms', 'nucleardawn', 'l4d2', 'insurgency', 'doi']: - dynamic_libs = ['libtier0_srv.so', 'libvstdlib_srv.so'] - elif compiler.target.arch == 'x86_64' and sdk.name in ['csgo', 'blade']: - dynamic_libs = ['libtier0_client.so', 'libvstdlib_client.so'] - elif sdk.name in ['l4d', 'blade', 'insurgency', 'doi', 'csgo']: - dynamic_libs = ['libtier0.so', 'libvstdlib.so'] - else: - dynamic_libs = ['tier0_i486.so', 'vstdlib_i486.so'] - elif compiler.target.platform == 'mac': - compiler.linkflags.append('-liconv') - dynamic_libs = ['libtier0.dylib', 'libvstdlib.dylib'] - elif compiler.target.platform == 'windows': - libs = ['tier0', 'tier1', 'vstdlib', 'mathlib'] - if sdk.name in ['swarm', 'blade', 'insurgency', 'doi', 'csgo']: - libs.append('interfaces') - for lib in libs: - if compiler.target.arch == 'x86': - lib_path = os.path.join(sdk.path, 'lib', 'public', lib) + '.lib' - elif compiler.target.arch == 'x86_64': - lib_path = os.path.join(sdk.path, 'lib', 'public', 'win64', lib) + '.lib' - compiler.linkflags.append(lib_path) - - for library in dynamic_libs: - source_path = os.path.join(lib_folder, library) - output_path = os.path.join(binary.localFolder, library) - - # Ensure the output path exists. - context.AddFolder(binary.localFolder) - output = context.AddSymlink(source_path, output_path) - - compiler.weaklinkdeps += [output] - compiler.linkflags[0:0] = [library] + SdkHelpers.configureCxx(context, binary, sdk) return binary @@ -601,43 +391,32 @@ class ExtensionConfig(object): self.ConfigureForExtension(context, binary.compiler) return self.ConfigureForHL2(context, binary, sdk) - def HL2Project(self, context, compiler, name): - project = context.LibraryProject(name) - self.ConfigureForExtension(context, compiler) - return project - def HL2Config(self, project, context, compiler, name, sdk): binary = project.Configure(compiler, name, - '{0} - {1} {2}'.format(self.tag, sdk.name, compiler.target.arch)) - self.AddVersioning(binary) + '{0} - {1} {2}'.format(self.tag, sdk['name'], compiler.target.arch)) + self.AddCxxCompat(binary) return self.ConfigureForHL2(context, binary, sdk) def HL2ExtConfig(self, project, context, compiler, name, sdk): binary = project.Configure(compiler, name, - '{0} - {1} {2}'.format(self.tag, sdk.name, compiler.target.arch)) - self.AddVersioning(binary) + '{0} - {1} {2}'.format(self.tag, sdk['name'], compiler.target.arch)) + self.AddCxxCompat(binary) self.ConfigureForHL2(context, binary, sdk) self.ConfigureForExtension(context, binary.compiler) return binary -if getattr(builder, 'target', None) is not None: - sys.stderr.write("Your output folder was configured for AMBuild 2.1, and SourceMod is now\n") - sys.stderr.write("configured to use AMBuild 2.2. Please remove your output folder and\n") - sys.stderr.write("reconfigure to continue.\n") - os._exit(1) - -SM = ExtensionConfig() -SM.detectSDKs() -SM.configure() +Extension = ExtensionConfig() +Extension.detectSDKs() +Extension.configure() # This will clone the list and each cxx object as we recurse, preventing child # scripts from messing up global state. -builder.targets = builder.CloneableList(SM.all_targets) +builder.targets = builder.CloneableList(Extension.all_targets) -if builder.backend == 'amb2': - BuildScripts = [ - 'AMBuilder', - 'PackageScript', - ] +BuildScripts = [ + 'AMBuilder', + 'PackageScript', +] + +builder.Build(BuildScripts, { 'Extension': Extension }) -builder.Build(BuildScripts, { 'SM': SM}) diff --git a/AMBuilder b/AMBuilder index 1eb7708..2d290de 100644 --- a/AMBuilder +++ b/AMBuilder @@ -1,44 +1,36 @@ # vim: set sts=2 ts=8 sw=2 tw=99 et ft=python: import os +if not "SM" in globals(): + SM = Extension + projectName = 'CSSFixes' -for cxx in builder.targets: - for sdk_name in SM.sdks: - sdk = SM.sdks[sdk_name] +project = builder.LibraryProject(projectName) +project.sources += [ + 'extension.cpp', + os.path.join(SM.sm_root, 'public', 'smsdk_ext.cpp') +] - if not cxx.target.arch in sdk.platformSpec[cxx.target.platform]: +for sdk_name in SM.sdks: + sdk = SM.sdks[sdk_name] + if sdk['name'] in ['mock']: + continue + + for cxx in builder.targets: + cxx.defines += ['HAVE_STRING_H']; + if not cxx.target.arch in sdk['platforms'][cxx.target.platform]: continue - binary = SM.HL2Library(builder, cxx, projectName + '.ext.' + sdk.ext, sdk) + binary = Extension.HL2ExtConfig(project, builder, cxx, projectName + '.ext.' + sdk['extension'], sdk) + + SM.AddCDetour(binary) + + binary.compiler.cxxflags += [ + '-Wno-dangling-else', + '-Wno-unknown-pragmas', + '-Wno-unused-result', + '-Wno-sign-compare', + ] - binary.compiler.defines += [ - 'HAVE_STRING_H', - ] - - if cxx.target.platform == 'linux': - cxx.postlink += ['-lpthread', '-lrt'] - elif cxx.target.platform == 'mac': - cxx.cflags += ['-Wno-deprecated-declarations'] - cxx.postlink += ['-framework', 'CoreServices'] - - if cxx.family == 'gcc' or cxx.family == 'clang': - cxx.cxxflags += ['-fno-rtti'] - elif cxx.family == 'msvc': - cxx.cxxflags += ['/GR-'] - - binary.sources += [ - 'extension.cpp', - os.path.join(SM.sm_root, 'extensions', 'sm-ext-common', 'mathstubs.c'), - os.path.join(SM.sm_root, 'public', 'smsdk_ext.cpp'), - os.path.join(SM.sm_root, 'public', 'CDetour', 'detours.cpp'), - os.path.join(SM.sm_root, 'public', 'asm', 'asm.c'), - os.path.join(SM.sm_root, 'public', 'libudis86', 'decode.c'), - os.path.join(SM.sm_root, 'public', 'libudis86', 'itab.c'), - os.path.join(SM.sm_root, 'public', 'libudis86', 'syn-att.c'), - os.path.join(SM.sm_root, 'public', 'libudis86', 'syn-intel.c'), - os.path.join(SM.sm_root, 'public', 'libudis86', 'syn.c'), - os.path.join(SM.sm_root, 'public', 'libudis86', 'udis86.c'), - ] - - SM.extensions += [builder.Add(binary)] +SM.extensions += builder.Add(project) diff --git a/PackageScript b/PackageScript index 1644866..88f1cad 100644 --- a/PackageScript +++ b/PackageScript @@ -1,57 +1,27 @@ -# vim: set ts=8 sts=2 sw=2 tw=99 et ft=python: -import os +# vim: set sts=2 ts=8 sw=2 tw=99 et: +import sys +from ambuild2 import run -# This is where the files will be output to -# package is the default -builder.SetBuildFolder('package') +# Simple extensions do not need to modify this file. -# Add any folders you need to this list -folder_list = [ - 'addons/sourcemod/extensions', - 'addons/sourcemod/scripting/include', - 'addons/sourcemod/gamedata' -] +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('--hl2sdk-manifest-path', type=str, dest='hl2sdk_manifest', default=None, + help='Path to HL2SDK Manifests') +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') -if 'x86_64' in SM.target_archs: - folder_list.extend([ - 'addons/sourcemod/extensions/x64', - ]) +parser.options.add_argument('--enable-debug', action='store_const', const='1', dest='debug', + help='Enable debugging symbols') +parser.options.add_argument('--enable-optimize', action='store_const', const='1', dest='opt', + help='Enable optimization') +parser.options.add_argument('-s', '--sdks', default='present', dest='sdks', + help='Build against specified SDKs; valid args are "none", "all", "present",' + ' or comma-delimited list of engine names') +parser.options.add_argument('--targets', type=str, dest='targets', default=None, + help="Override the target architecture (use commas to separate multiple targets).") +parser.Configure() -# Create the distribution folder hierarchy. -folder_map = {} -for folder in folder_list: - norm_folder = os.path.normpath(folder) - folder_map[folder] = builder.AddFolder(norm_folder) - -# Copy binaries. -for cxx_task in SM.extensions: - if cxx_task.target.arch == 'x86_64': - builder.AddCopy(cxx_task.binary, folder_map['addons/sourcemod/extensions/x64']) - else: - builder.AddCopy(cxx_task.binary, folder_map['addons/sourcemod/extensions']) - -# Do all straight-up file copies from the source tree. -def CopyFiles(src, dest, files): - if not dest: - dest = src - dest_entry = folder_map[dest] - for source_file in files: - source_path = os.path.join(builder.sourcePath, src, source_file) - dest_path = os.path.join(dest_entry.path, source_file) - if not os.path.isfile(str(dest_path)): - builder.AddCopy(source_path, dest_entry) - -# Gamedata -CopyFiles('addons/sourcemod/gamedata', 'addons/sourcemod/gamedata', - [ 'CSSFixes.games.txt' ] -) - -# Include -CopyFiles('addons/sourcemod/scripting/include', 'addons/sourcemod/scripting/include', - [ 'CSSFixes.inc' ] -) - -# Autoload extension -CopyFiles('addons/sourcemod/extensions', 'addons/sourcemod/extensions', - [ 'CSSFixes.autoload' ] -) diff --git a/configure.py b/configure.py index 2804d35..88f1cad 100755 --- a/configure.py +++ b/configure.py @@ -1,39 +1,27 @@ -# vim: set ts=2 sw=2 tw=99 noet: +# vim: set sts=2 ts=8 sw=2 tw=99 et: import sys -try: - from ambuild2 import run, util -except: - try: - import ambuild - sys.stderr.write('It looks like you have AMBuild 1 installed, but this project uses AMBuild 2.\n') - sys.stderr.write('Upgrade to the latest version of AMBuild to continue.\n') - except: - sys.stderr.write('AMBuild must be installed to build this project.\n') - sys.stderr.write('http://www.alliedmods.net/ambuild\n') - sys.exit(1) +from ambuild2 import run -# Hack to show a decent upgrade message, which wasn't done until 2.2. -ambuild_version = getattr(run, 'CURRENT_API', '2.1') -if ambuild_version.startswith('2.1'): - sys.stderr.write("AMBuild 2.2 or higher is required; please update\n") - sys.exit(1) - -parser = run.BuildParser(sourcePath = sys.path[0], api='2.2') +# 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('--mms-path', type=str, dest='mms_path', default=None, - help='Path to Metamod:Source') + help='Root search folder for HL2SDKs') +parser.options.add_argument('--hl2sdk-manifest-path', type=str, dest='hl2sdk_manifest', default=None, + help='Path to HL2SDK Manifests') 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') parser.options.add_argument('--enable-optimize', action='store_const', const='1', dest='opt', help='Enable optimization') -parser.options.add_argument('-s', '--sdks', default='all', dest='sdks', - help='Build against specified SDKs; valid args are "all", "present", or ' - 'comma-delimited list of engine names (default: %default)') +parser.options.add_argument('-s', '--sdks', default='present', dest='sdks', + help='Build against specified SDKs; valid args are "none", "all", "present",' + ' or comma-delimited list of engine names') parser.options.add_argument('--targets', type=str, dest='targets', default=None, - help="Override the target architecture (use commas to separate multiple targets).") - + help="Override the target architecture (use commas to separate multiple targets).") parser.Configure() + diff --git a/extension.cpp b/extension.cpp index 274dc26..5380672 100644 --- a/extension.cpp +++ b/extension.cpp @@ -40,6 +40,9 @@ #include #include +#define VPROF_ENABLED +#include + #define SetBit(A,I) ((A)[(I) >> 5] |= (1 << ((I) & 31))) #define ClearBit(A,I) ((A)[(I) >> 5] &= ~(1 << ((I) & 31))) #define CheckBit(A,I) !!((A)[(I) >> 5] & (1 << ((I) & 31))) @@ -149,69 +152,77 @@ static struct SrcdsPatch // 0: game_ui should not apply FL_ONTRAIN flag, else client prediction turns off { "_ZN7CGameUI5ThinkEv", - (unsigned char *)"\xC7\x44\x24\x04\x10\x00\x00\x00\x89\x34\x24\xE8\x00\x00\x00\x00", - "xxxxxxxxxxxx????", - (unsigned char *)"\xC7\x44\x24\x04\x10\x00\x00\x00\x89\x34\x24\x90\x90\x90\x90\x90", + (unsigned char *)"\x0F\x82\xC4\x03\x00\x00\x83\xEC\x08\x6A\x10\x53\xE8\x91\x00\xF5\xFF", + "xx????xx?x?xx????", + (unsigned char *)"\x0F\x82\xC4\x03\x00\x00\x83\xEC\x08\x6A\x10\x53\x90\x90\x90\x90\x90", "cstrike/bin/server_srv.so" }, // 1: player_speedmod should not turn off flashlight { "_ZN17CMovementSpeedMod13InputSpeedModER11inputdata_t", - (unsigned char *)"\xFF\x90\x8C\x05\x00\x00\x85\xC0\x0F\x85\x85\x02\x00\x00", - "xxxxxxxxxxxxxx", - (unsigned char *)"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90", + (unsigned char *)"\x8B\x90\xA4\x05\x00\x00\x81\xFA\x10\x6E\x3E\x00\x0F\x85\xC7\x02\x00\x00\x8B\x80\xA0\x05\x00\x00\x3D\x00\x6E\x3E\x00\x0F\x85\xEE\x02\x00\x00", + "xx????xx????xx????xx????x????xx????", + (unsigned char *)"\x8B\x90\xA4\x05\x00\x00\x81\xFA\x10\x6E\x3E\x00\x0F\x84\xC7\x02\x00\x00\x8B\x80\xA0\x05\x00\x00\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90", "cstrike/bin/server_srv.so" }, // 2: only select CT spawnpoints { "_ZN9CCSPlayer19EntSelectSpawnPointEv", - (unsigned char *)"\x89\x1C\x24\xE8\x00\x00\x00\x00\x83\xF8\x03\x74\x6B", - "xxxx????xxxxx", - (unsigned char *)"\x89\x1C\x24\x90\x90\x90\x90\x90\x90\x90\x90\xEB\x6B", + (unsigned char *)"\x74\x57\x83\xEC\x0C\x53\xE8\x6E\x34\xCA\xFF\x83\xC4\x10\x83\xF8\x02\x0F\x84", + "x?xx?xx????xx?xx?xx", + (unsigned char *)"\xEB\x57\x83\xEC\x0C\x53\xE8\x6E\x34\xCA\xFF\x83\xC4\x10\x83\xF8\x02\x0F\x84", "cstrike/bin/server_srv.so" }, // 3: don't check if we have T spawns { "_ZN12CCSGameRules18NeededPlayersCheckERb", - (unsigned char *)"\x74\x0E\x8B\x83\x80\x02\x00\x00\x85\xC0\x0F\x85\x9E\x00\x00\x00\xC7\x04\x24\xAC\xF7\x87\x00\xE8\xC2\x82\x91\x00", - "xxxxxxxxxxxxxxxx????????????", - (unsigned char *)"\x0F\x85\xA8\x00\x00\x00\x8B\x83\x80\x02\x00\x00\x85\xC0\x0F\x85\x9A\x00\x00\x00\x90\x90\x90\x90\x90\x90\x90\x90", + (unsigned char *)"\x74\x0A\x8B\x83\x94\x02\x00\x00\x85\xC0\x75\x4A\x83\xEC\x0C\x68\xE8\xCF\x93\x00\xE8\xA9\x46\x52\x00\x5A\x59", + "xxxx????xxx?xx?x????x????xx", + (unsigned char *)"\x75\x54\x8B\x83\x94\x02\x00\x00\x85\xC0\x75\x4A\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90", "cstrike/bin/server_srv.so" }, // 5: disable alive check in point_viewcontrol->Disable { "_ZN14CTriggerCamera7DisableEv", - (unsigned char *)"\x8B\x10\x89\x04\x24\xFF\x92\x08\x01\x00\x00\x84\xC0\x0F\x84\x58\xFF\xFF\xFF", - "xxxxxxx??xxxxxx?xxx", - (unsigned char *)"\x8B\x10\x89\x04\x24\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90", + (unsigned char *)"\x0F\x84\x47\x02\x00\x00\xF6\x83\x40\x01\x00\x00\x20\x0F\x85", + "xx????xx?????xx", + (unsigned char *)"\x90\x90\x90\x90\x90\x90\xF6\x83\x40\x01\x00\x00\x20\x0F\x85", "cstrike/bin/server_srv.so" }, // 6: disable player->m_takedamage = DAMAGE_NO in point_viewcontrol->Enable { "_ZN14CTriggerCamera6EnableEv", - (unsigned char *)"\xC6\x86\x00\x00\x00\x00\x00\x8B\x83\x00\x00\x00\x00\xA8\x20", - "xx?????xx????xx", - (unsigned char *)"\x90\x90\x90\x90\x90\x90\x90\x8B\x83\x00\x00\x00\x00\xA8\x20", + (unsigned char *)"\xC6\x80\xFD\x00\x00\x00\x00\x8B\x83", + "xxxxxxxxx", + (unsigned char *)"\x90\x90\x90\x90\x90\x90\x90\x8B\x83", "cstrike/bin/server_srv.so", 0x600 }, // 7: disable player->m_takedamage = m_nOldTakeDamage in point_viewcontrol->Disable { "_ZN14CTriggerCamera7DisableEv", - (unsigned char *)"\x89\xF9\x38\x8E\xFD\x00\x00\x00\x0F\x84\xCA\xFD\xFF\xFF", - "xxxx?xxxxxxxxx", - (unsigned char *)"\x89\xF9\x38\x8E\xFD\x00\x00\x00\x90\xE9\xCA\xFD\xFF\xFF", + (unsigned char *)"\x74\x1A\x8B\x16\x8B\x92\x04\x02\x00\x00\x81\xFA\x30\xF9\x29\x00\x0F\x85", + "x?xxxx????xx????xx", + (unsigned char *)"\xEB\x1A\x8B\x16\x8B\x92\x04\x02\x00\x00\x81\xFA\x30\xF9\x29\x00\x0F\x85", "cstrike/bin/server_srv.so" }, // 8: userinfo stringtable don't write fakeclient field { "_ZN11CBaseClient12FillUserInfoER13player_info_s", - (unsigned char *)"\xFF\x50\x70\x88\x46\x6C", - "xxxxxx", - (unsigned char *)"\x90\x90\x90\x90\x90\x90", + (unsigned char *)"\x88\x46\x6C", + "xxx", + (unsigned char *)"\x90\x90\x90", "bin/engine_srv.so" }, - // 9: fix server lagging resulting from too many ConMsgs due to packet spam + // 9: dont reset cash to 16000 when buying an item + { + "_ZN9CCSPlayer10AddAccountEibbPKc", + (unsigned char *)"\x3D\x80\x3E\x00\x00\x0F\x8F\x00\x00\x00\x00\x8D\x65", + "x????xx????xx", + (unsigned char *)"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x8D\x65", + "cstrike/bin/server_srv.so" + }, + // 10: fix server lagging resulting from too many ConMsgs due to packet spam { "_ZN8CNetChan19ProcessPacketHeaderEP11netpacket_s", (unsigned char *)"_Z6ConMsgPKcz", @@ -221,7 +232,7 @@ static struct SrcdsPatch 0x7d1, 100, true, "bin/libtier0_srv.so" }, - // 10: fix server lagging resulting from too many ConMsgs due to packet spam + // 11: fix server lagging resulting from too many ConMsgs due to packet spam { "_Z11NET_GetLongiP11netpacket_s", (unsigned char *)"Msg", @@ -231,7 +242,8 @@ static struct SrcdsPatch 0x800, 100, true, "bin/libtier0_srv.so" }, - // 11: Always transmit point_viewcontrol (for debugging) + // 12: Always transmit point_viewcontrol (for debugging) + /* { "_ZN14CTriggerCamera19UpdateTransmitStateEv", (unsigned char *)"\x74\x16", @@ -239,22 +251,32 @@ static struct SrcdsPatch (unsigned char *)"\xEB\x16", "cstrike/bin/server_srv.so" }, - // 12: CTriggerCamera::FollowTarget: Don't early return when the player handle is null + */ + // 13: CTriggerCamera::FollowTarget: Don't early return when the player handle is null { "_ZN14CTriggerCamera12FollowTargetEv", - (unsigned char *)"\x74\x1B\x89\xD0\x25\x00\x00\x00\x00\xC1\xE0\x04", - "xxxxx????xxx", - (unsigned char *)"\xEB\x23\x89\xD0\x25\x00\x00\x00\x00\xC1\xE0\x04", + (unsigned char *)"\x0F\x84\xD6\x02\x00\x00\x83\xFA\xFF", + "xxxxxxxxx", + (unsigned char *)"\x90\x90\x90\x90\x90\x90\x83\xFA\xFF", "cstrike/bin/server_srv.so" }, - // 13: CGameMovement::LadderMove NOP out player->SetGravity( 0 ); + // 14: CGameMovement::LadderMove NOP out player->SetGravity( 0 ); + // This is in a cloned function which has a weird symbol (_ZN13CGameMovement10LadderMoveEv_part_0) so I went with the function right before it { - "_ZN13CGameMovement10LadderMoveEv", - (unsigned char *)"\xC7\x80\x78\x02\x00\x00\x00\x00\x00\x00", - "xxxxxxx???", - (unsigned char *)"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90", + "_ZN13CGameMovement12CheckFallingEv", + (unsigned char *)"\xC7\x80\xA4\x02\x00\x00\x00\x00\x00\x00\x8B\x03\x8B\x80", + "xx????????xxxx", + (unsigned char *)"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x8B\x03\x8B\x80", "cstrike/bin/server_srv.so" }, + // 18: Remove weird filename handle check in CZipPackFile::GetFileInfo that broke loading mixed case files in bsp pakfiles + { + "_ZN12CZipPackFile11GetFileInfoEPKcRiRxS2_S2_Rt", + (unsigned char *)"\x75\x00\x8B\x09", + "x?xx", + (unsigned char *)"\x90\x90\x8B\x09", + "bin/dedicated_srv.so" + }, }; class CBaseEntity; @@ -326,7 +348,6 @@ DETOUR_DECL_MEMBER1(DETOUR_InputTestActivator, void, inputdata_t *, inputdata) const char *pszNonEdicts[] = { - "ambient_generic", "game_score", "game_text", "game_ui", @@ -342,6 +363,8 @@ const char *pszNonEdicts[] = DETOUR_DECL_MEMBER1(DETOUR_PostConstructor, void, const char *, szClassname) { + VPROF_ENTER_SCOPE("CSSFixes::DETOUR_PostConstructor"); + CBaseEntity *pEntity = (CBaseEntity *)this; static datamap_t *pMap = gamehelpers->GetDataMap(pEntity); @@ -371,6 +394,8 @@ DETOUR_DECL_MEMBER1(DETOUR_PostConstructor, void, const char *, szClassname) } DETOUR_MEMBER_CALL(DETOUR_PostConstructor)(szClassname); + + VPROF_EXIT_SCOPE(); } // Implementation for custom filter entities @@ -424,15 +449,23 @@ DETOUR_DECL_MEMBER2(DETOUR_PassesFilterImpl, bool, CBaseEntity*, pCaller, CBaseE // Switch new entity classnames to ones that can be instantiated while keeping the classname keyvalue intact so it can be used later DETOUR_DECL_STATIC2(DETOUR_CreateEntityByName, CBaseEntity*, const char*, className, int, iForceEdictIndex) { + VPROF_ENTER_SCOPE("CSSFixes::DETOUR_CreateEntityByName"); + // Nice of valve to expose CBaseFilter as filter_base :) if (strcasecmp(className, "filter_activator_context") == 0) className = "filter_base"; - return DETOUR_STATIC_CALL(DETOUR_CreateEntityByName)(className, iForceEdictIndex); + CBaseEntity *pEntity = DETOUR_STATIC_CALL(DETOUR_CreateEntityByName)(className, iForceEdictIndex); + + VPROF_EXIT_SCOPE(); + + return pEntity; } DETOUR_DECL_MEMBER2(DETOUR_KeyValue, bool, const char *, szKeyName, const char *, szValue) { + VPROF_ENTER_SCOPE("CSSFixes::DETOUR_KeyValue"); + CBaseEntity *pEntity = (CBaseEntity *)this; // Fix crash bug in engine @@ -474,7 +507,11 @@ DETOUR_DECL_MEMBER2(DETOUR_KeyValue, bool, const char *, szKeyName, const char * vecAbsVelocity->Init(tmp[0], tmp[1], tmp[2]); } - return DETOUR_MEMBER_CALL(DETOUR_KeyValue)(szKeyName, szValue); + bool bHandled = DETOUR_MEMBER_CALL(DETOUR_KeyValue)(szKeyName, szValue); + + VPROF_EXIT_SCOPE(); + + return bHandled; } /* Ignore players in +USE trace */ @@ -492,7 +529,7 @@ DETOUR_DECL_MEMBER3(DETOUR_CTraceFilterSimple, void, const IHandleEntity *, pass DETOUR_MEMBER_CALL(DETOUR_CTraceFilterSimple)(passedict, collisionGroup, pExtraShouldHitFunc); // If we're in FindUseEntity right now then switch out the VTable - if(g_InFindUseEntity) + if (g_InFindUseEntity) *(uintptr_t *)this = g_CTraceFilterNoNPCsOrPlayer; } @@ -768,6 +805,8 @@ bool CSSFixes::SDK_OnLoad(char *error, size_t maxlength, bool late) g_SH_SkipTwoEntitiesShouldHitEntity = SH_ADD_DVPHOOK(CTraceFilterSkipTwoEntities, ShouldHitEntity, g_CTraceFilterSkipTwoEntities, SH_STATIC(ShouldHitEntity), true); g_SH_SimpleShouldHitEntity = SH_ADD_DVPHOOK(CTraceFilterSimple, ShouldHitEntity, g_CTraceFilterSimple, SH_STATIC(ShouldHitEntity), true); + bool bSuccess = true; + // Apply all patches for(size_t i = 0; i < sizeof(gs_Patches) / sizeof(*gs_Patches); i++) { @@ -777,19 +816,19 @@ bool CSSFixes::SDK_OnLoad(char *error, size_t maxlength, bool late) void *pBinary = dlopen(pPatch->pLibrary, RTLD_NOW); if(!pBinary) { - snprintf(error, maxlength, "Could not dlopen %s", pPatch->pLibrary); - SDK_OnUnload(); - return false; + g_pSM->LogError(myself, "Could not dlopen %s", pPatch->pLibrary); + bSuccess = false; + continue; } pPatch->pAddress = (uintptr_t)memutils->ResolveSymbol(pBinary, pPatch->pSignature); dlclose(pBinary); if(!pPatch->pAddress) { - snprintf(error, maxlength, "Could not find symbol: %s in %s (%p)", + g_pSM->LogError(myself, "Could not find symbol: %s in %s (%p)", pPatch->pSignature, pPatch->pLibrary, pBinary); - SDK_OnUnload(); - return false; + bSuccess = false; + continue; } SrcdsPatch::Restore **ppRestore = &pPatch->pRestore; @@ -799,19 +838,19 @@ bool CSSFixes::SDK_OnLoad(char *error, size_t maxlength, bool late) void *pFunctionBinary = dlopen(pPatch->pFunctionLibrary, RTLD_NOW); if(!pFunctionBinary) { - snprintf(error, maxlength, "Could not dlopen %s", pPatch->pFunctionLibrary); - SDK_OnUnload(); - return false; + g_pSM->LogError(myself, "Could not dlopen %s", pPatch->pFunctionLibrary); + bSuccess = false; + continue; } pPatch->pSignatureAddress = (uintptr_t)memutils->ResolveSymbol(pFunctionBinary, (char *)pPatch->pPatchSignature); dlclose(pFunctionBinary); if(!pPatch->pSignatureAddress) { - snprintf(error, maxlength, "Could not find patch signature symbol: %s in %s (%p)", + g_pSM->LogError(myself, "Could not find patch signature symbol: %s in %s (%p)", (char *)pPatch->pPatchSignature, pPatch->pFunctionLibrary, pFunctionBinary); - SDK_OnUnload(); - return false; + bSuccess = false; + continue; } } @@ -830,9 +869,9 @@ bool CSSFixes::SDK_OnLoad(char *error, size_t maxlength, bool late) if(found) break; - snprintf(error, maxlength, "Could not find patch signature for symbol: %s", pPatch->pSignature); - SDK_OnUnload(); - return false; + g_pSM->LogError(myself, "Could not find patch signature for symbol: %s", pPatch->pSignature); + bSuccess = false; + continue; } ofs = pPatchAddress - pPatch->pAddress + PatchLen; @@ -854,6 +893,12 @@ bool CSSFixes::SDK_OnLoad(char *error, size_t maxlength, bool late) } } + if (!bSuccess) + { + SDK_OnUnload(); + return false; + } + return true; } diff --git a/hl2sdk-manifests b/hl2sdk-manifests new file mode 160000 index 0000000..f559b1c --- /dev/null +++ b/hl2sdk-manifests @@ -0,0 +1 @@ +Subproject commit f559b1cc8f9e47d88e13bd46a220c32ec26af7b6 diff --git a/smsdk_config.h b/smsdk_config.h index b92f5a6..ed1499a 100644 --- a/smsdk_config.h +++ b/smsdk_config.h @@ -40,7 +40,7 @@ /* Basic information exposed publicly */ #define SMEXT_CONF_NAME "CSSFixes" #define SMEXT_CONF_DESCRIPTION "Patches bugs in the CSS server binary and more..." -#define SMEXT_CONF_VERSION "1.18" +#define SMEXT_CONF_VERSION "1.2" #define SMEXT_CONF_AUTHOR "BotoX" #define SMEXT_CONF_URL "" #define SMEXT_CONF_LOGTAG "CSSFIXES"