From 7aec329e3661c302d9e2fb252e179c072d888f79 Mon Sep 17 00:00:00 2001 From: Ryan Stecker Date: Sun, 3 Mar 2024 16:45:58 -0600 Subject: [PATCH 01/10] Add initial ambuild2 boilerplate. --- .gitignore | 2 + AMBuildScript | 631 ++++++++++++++++++++++++++++++++++++ buildbot/BreakpadSymbols | 39 +++ buildbot/PackageScript | 59 ++++ buildbot/Versioning | 50 +++ buildbot/generate_header.py | 61 ++++ buildbot/pushbuild.txt | 1 + configure.py | 58 ++++ product.version | 1 + src/AMBuilder | 31 ++ src/extension.cpp | 2 +- src/smsdk_config.h | 84 +++++ src/version.h | 27 ++ src/version.rc | 45 +++ 14 files changed, 1090 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 AMBuildScript create mode 100644 buildbot/BreakpadSymbols create mode 100644 buildbot/PackageScript create mode 100644 buildbot/Versioning create mode 100644 buildbot/generate_header.py create mode 100644 buildbot/pushbuild.txt create mode 100644 configure.py create mode 100644 product.version create mode 100644 src/AMBuilder create mode 100644 src/smsdk_config.h create mode 100644 src/version.h create mode 100644 src/version.rc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3d94e71 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# AMBuild2 build outputs +build/ diff --git a/AMBuildScript b/AMBuildScript new file mode 100644 index 0000000..84e8509 --- /dev/null +++ b/AMBuildScript @@ -0,0 +1,631 @@ +# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python: +import os, sys + +# Simple extensions do not need to modify this file. + + +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 + + +WinLinux = ["windows", "linux"] +TF2 = {"windows": ["x86", "x86_64"], "linux": ["x86", "x86_64"]} +CSGO = {"windows": ["x86"], "linux": ["x86", "x86_64"]} + +PossibleSDKs = { + # 'episode1': SDK('HL2SDK', '1.ep1', '1', 'EPISODEONE', WinLinux, 'episode1'), + # 'darkm': SDK('HL2SDK-DARKM', '2.darkm', '2', 'DARKMESSIAH', WinOnly, 'darkm'), + # 'orangebox': SDK('HL2SDKOB', '2.ep2', '3', 'ORANGEBOX', WinLinux, 'orangebox'), + # 'bgt': SDK('HL2SDK-BGT', '2.bgt', '4', 'BLOODYGOODTIME', WinOnly, 'bgt'), + # 'eye': SDK('HL2SDK-EYE', '2.eye', '5', 'EYE', WinOnly, 'eye'), + "css": SDK("HL2SDKCSS", "2.css", "6", "CSS", WinLinux, "css"), + "hl2dm": SDK("HL2SDKHL2DM", "2.hl2dm", "7", "HL2DM", WinLinux, "hl2dm"), + "dods": SDK("HL2SDKDODS", "2.dods", "8", "DODS", WinLinux, "dods"), + "sdk2013": SDK("HL2SDK2013", "2.sdk2013", "9", "SDK2013", WinLinux, "sdk2013"), + # 'bms': SDK('HL2SDKBMS', '2.bms', '11', 'BMS', WinLinux, 'bms'), + "tf2": SDK("HL2SDKTF2", "2.tf2", "12", "TF2", TF2, "tf2"), + "l4d": SDK("HL2SDKL4D", "2.l4d", "13", "LEFT4DEAD", WinLinux, "l4d"), + # 'nucleardawn': SDK('HL2SDKND', '2.nd', '14', 'NUCLEARDAWN', WinLinuxMac, 'nucleardawn'), + # 'contagion': SDK('HL2SDKCONTAGION', '2.contagion', '15', 'CONTAGION', WinOnly, 'contagion'), + "l4d2": SDK("HL2SDKL4D2", "2.l4d2", "16", "LEFT4DEAD2", WinLinux, "l4d2"), + # 'swarm': SDK('HL2SDK-SWARM', '2.swarm', '17', 'ALIENSWARM', WinOnly, 'swarm'), + # 'portal2': SDK('HL2SDKPORTAL2', '2.portal2', '18', 'PORTAL2', [], 'portal2'), + # 'insurgency': SDK('HL2SDKINSURGENCY', '2.insurgency', '19', 'INSURGENCY', WinLinuxMac, 'insurgency'), + # 'blade': SDK('HL2SDKBLADE', '2.blade', '21', 'BLADE', WinLinux, 'blade'), + "csgo": SDK("HL2SDKCSGO", "2.csgo", "23", "CSGO", CSGO, "csgo"), +} + + +def ResolveEnvPath(env, folder): + if env in os.environ: + path = os.environ[env] + if os.path.isdir(path): + return path + return None + + 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)) + + +def SetArchFlags(compiler): + if compiler.behavior == "gcc": + if compiler.target.arch == "x86_64": + compiler.cflags += ["-fPIC"] + elif compiler.like("msvc"): + if compiler.target.arch == "x86_64": + compiler.defines += ["WIN64"] + + +class ExtensionConfig(object): + def __init__(self): + self.sdks = {} + self.binaries = [] + self.extensions = [] + self.generated_headers = None + self.productVersion = None + self.mms_root = None + self.sm_root = None + self.all_targets = [] + self.target_archs = set() + + if builder.options.targets: + target_archs = builder.options.targets.split(",") + else: + target_archs = ["x86", "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: + # Error if archs were manually overridden. + if builder.options.targets: + raise + print("Skipping target {}: {}".format(arch, e)) + continue + self.all_targets.append(cxx) + + if not self.all_targets: + raise Exception("No suitable C/C++ compiler was found.") + + def use_auto_versioning(self): + return not getattr(builder.options, "disable_auto_versioning", False) + + 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, + ] + if self.use_auto_versioning(): + binary.compiler.sourcedeps += self.generated_headers + return binary + + @property + def tag(self): + if builder.options.debug == "1": + return "Debug" + return "Release" + + def detectProductVersion(self): + builder.AddConfigureFile("product.version") + + # 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 detectSDKs(self): + sdk_list = builder.options.sdks.split(" ") + use_all = sdk_list[0] == "all" + use_present = sdk_list[0] == "present" + + 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( + os.path.realpath(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: + raise Exception("At least one SDK must be available.") + + if builder.options.sm_path: + self.sm_root = os.path.realpath(builder.options.sm_path) + else: + self.sm_root = ResolveEnvPath("SOURCEMOD", "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) + + if builder.options.mms_path: + self.mms_root = builder.options.mms_path + else: + self.mms_root = ResolveEnvPath("MMSOURCE110", "mmsource-1.10") + if not self.mms_root: + self.mms_root = ResolveEnvPath("MMSOURCE", "metamod-source") + if not self.mms_root: + self.mms_root = ResolveEnvPath("MMSOURCE_DEV", "mmsource-central") + + 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 configure(self): + + if not set(self.target_archs).issubset(["x86", "x86_64"]): + raise Exception( + "Unknown target architecture: {0}".format(self.target_archs) + ) + + for cxx in self.all_targets: + self.configure_cxx(cxx) + + 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.like("gcc"): + self.configure_gcc(cxx) + elif cxx.family == "msvc": + self.configure_msvc(cxx) + cxx.defines += ["HAVE_STRING_H"] + + # Optimizaiton + 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 == "mac": + self.configure_mac(cxx) + elif cxx.target.platform == "windows": + self.configure_windows(cxx) + + cxx.includes += [ + os.path.join(self.sm_root, "public"), + ] + + if self.use_auto_versioning(): + cxx.defines += ["SM_GENERATED_BUILD"] + cxx.includes += [os.path.join(builder.buildPath, "includes")] + + def configure_gcc(self, cxx): + cxx.defines += [ + "stricmp=strcasecmp", + "_stricmp=strcasecmp", + "_snprintf=snprintf", + "_vsnprintf=vsnprintf", + "typeof=__typeof__", + "HAVE_STDINT_H", + "GNUC", + ] + cxx.cflags += [ + "-pipe", + "-fno-strict-aliasing", + "-Wall", + "-Wno-unused", + "-Wno-switch", + "-Wno-array-bounds", + "-msse", + "-fvisibility=hidden", + ] + cxx.cxxflags += [ + "-std=c++14", + "-fno-threadsafe-statics", + "-Wno-non-virtual-dtor", + "-Wno-overloaded-virtual", + "-fvisibility-inlines-hidden", + "-fpermissive", + ] + + have_gcc = cxx.vendor == "gcc" + have_clang = cxx.vendor == "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"] + + 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": + cxx.cflags += [ + "-Wno-implicit-int-float-conversion", + "-Wno-tautological-overlap-compare", + ] + + if have_gcc: + cxx.cflags += ["-mfpmath=sse"] + + if builder.options.opt == "1": + cxx.cflags += ["-O3"] + + def configure_msvc(self, cxx): + if builder.options.debug == "1": + cxx.cflags += ["/MTd"] + cxx.linkflags += ["/NODEFAULTLIB:libcmt"] + else: + cxx.cflags += ["/MT"] + cxx.defines += [ + "_CRT_SECURE_NO_DEPRECATE", + "_CRT_SECURE_NO_WARNINGS", + "_CRT_NONSTDC_NO_DEPRECATE", + "_ITERATOR_DEBUG_LEVEL=0", + ] + cxx.cflags += [ + "/W3", + ] + cxx.cxxflags += [ + "/EHsc", + "/TP", + ] + cxx.linkflags += [ + "/MACHINE:X86", + "kernel32.lib", + "user32.lib", + "gdi32.lib", + "winspool.lib", + "comdlg32.lib", + "advapi32.lib", + "shell32.lib", + "ole32.lib", + "oleaut32.lib", + "uuid.lib", + "odbc32.lib", + "odbccp32.lib", + ] + + if builder.options.opt == "1": + cxx.cflags += ["/Ox", "/Zo"] + cxx.linkflags += ["/OPT:ICF", "/OPT:REF"] + + if builder.options.debug == "1": + cxx.cflags += ["/Od", "/RTC1"] + + # This needs to be after our optimization flags which could otherwise disable it. + # Don't omit the frame pointer. + cxx.cflags += ["/Oy-"] + + def configure_linux(self, cxx): + cxx.defines += ["_LINUX", "POSIX"] + cxx.linkflags += ["-Wl,--exclude-libs,ALL", "-lm"] + if cxx.vendor == "gcc": + cxx.linkflags += ["-static-libgcc"] + elif cxx.vendor == "clang": + cxx.linkflags += ["-lgcc_eh"] + cxx.linkflags += ["-static-libstdc++"] + + def configure_mac(self, cxx): + cxx.defines += ["OSX", "_OSX", "POSIX"] + cxx.cflags += ["-mmacosx-version-min=10.7"] + cxx.linkflags += [ + "-mmacosx-version-min=10.7", + "-arch", + "i386", + "-lstdc++", + "-stdlib=libstdc++", + ] + cxx.cxxflags += ["-stdlib=libstdc++"] + + def configure_windows(self, cxx): + cxx.defines += ["WIN32", "_WINDOWS"] + + def ConfigureForExtension(self, context, compiler): + 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, "sourcepawn", "include"), + os.path.join(self.sm_root, "public", "amtl", "amtl"), + os.path.join(self.sm_root, "public", "amtl"), + ] + return compiler + + def ConfigureForHL2(self, context, binary, sdk): + compiler = binary.compiler + SetArchFlags(compiler) + + compiler.cxxincludes += [ + os.path.join(self.mms_root, "core"), + os.path.join(self.mms_root, "core", "sourcehook"), + ] + + defines = ["RAD_TELEMETRY_DISABLED"] + defines += [ + "SE_" + PossibleSDKs[i].define + "=" + PossibleSDKs[i].code + for i in PossibleSDKs + ] + compiler.defines += defines + + 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", "mock"]: + 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] + + return binary + + 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) + 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) + self.ConfigureForHL2(context, binary, sdk) + self.ConfigureForExtension(context, binary.compiler) + return binary + + +Extension = ExtensionConfig() +Extension.detectProductVersion() +Extension.detectSDKs() +Extension.configure() + +if Extension.use_auto_versioning(): + Extension.generated_headers = builder.Build("buildbot/Versioning") + +builder.targets = builder.CloneableList(Extension.all_targets) +# Add additional buildscripts here +BuildScripts = ["src/AMBuilder", "buildbot/PackageScript", "buildbot/BreakpadSymbols"] + +builder.Build(BuildScripts, {"Extension": Extension}) diff --git a/buildbot/BreakpadSymbols b/buildbot/BreakpadSymbols new file mode 100644 index 0000000..a85f0bf --- /dev/null +++ b/buildbot/BreakpadSymbols @@ -0,0 +1,39 @@ +# vim: set ts=2 sw=2 tw=99 noet ft=python: +import os, sys + +UPLOAD_SCRIPT = os.path.join(Extension.sm_root, 'tools', 'buildbot', 'upload_symbols.py') + +if 'BREAKPAD_SYMBOL_SERVER' in os.environ: + symbolServer = os.environ['BREAKPAD_SYMBOL_SERVER'] + builder.SetBuildFolder('breakpad-symbols') + + for cxx_task in Extension.extensions: + if cxx_task.target.platform in ['windows']: + debug_entry = cxx_task.debug + else: + debug_entry = cxx_task.binary + + debug_file = os.path.join(builder.buildPath, debug_entry.path) + if cxx_task.target.platform == 'linux': + argv = ['dump_syms', debug_file, os.path.dirname(debug_file)] + elif cxx_task.target.platform == 'mac': + # Required once dump_syms is updated on the slaves. + #argv = ['dump_syms', '-g', debug_file + '.dSYM', debug_file] + argv = ['dump_syms', debug_file + '.dSYM'] + elif cxx_task.target.platform == 'windows': + argv = ['dump_syms.exe', debug_file] + + plat_dir = os.path.dirname(debug_file) + bin_dir = os.path.split(plat_dir)[0] + + symbol_file = '{}-{}-{}.breakpad'.format( + os.path.split(bin_dir)[1], + cxx_task.target.platform, + cxx_task.target.arch) + + argv = [sys.executable, UPLOAD_SCRIPT, symbol_file] + argv + builder.AddCommand( + inputs = [UPLOAD_SCRIPT, debug_entry], + argv = argv, + outputs = [symbol_file] + ) \ No newline at end of file diff --git a/buildbot/PackageScript b/buildbot/PackageScript new file mode 100644 index 0000000..22db35f --- /dev/null +++ b/buildbot/PackageScript @@ -0,0 +1,59 @@ +# vim: set ts=2 sw=2 tw=99 noet ft=python: +import os +import shutil +import ambuild.osutil as osutil +from ambuild.command import Command + +builder.SetBuildFolder("package") + + +def CreateFolders(folders): + dict = {} + for folder in folders: + path = os.path.normpath(folder) + dict[folder] = builder.AddFolder(path) + return dict + + +def CopyFiles(src, dest, filter_ext=None): + source_path = os.path.join(builder.sourcePath, src) + if os.path.isfile(source_path): + builder.AddCopy(source_path, dest) + return + for entry in os.listdir(source_path): + entry_path = os.path.join(source_path, entry) + if not os.path.isfile(entry_path): + continue + if filter_ext: + _, ext = os.path.splitext(entry) + if filter_ext != ext: + continue + builder.AddCopy(entry_path, dest) + + +folders = CreateFolders( + [ + "addons/sourcemod/extensions", + "addons/sourcemod/extensions/x64", + "addons/sourcemod/gamedata", + "addons/sourcemod/scripting", + "addons/sourcemod/scripting/include", + ] +) + +pdblog = open(os.path.join(builder.buildPath, "pdblog.txt"), "wt") +for cxx_task in Extension.extensions: + if cxx_task.target.arch == "x86_64": + builder.AddCopy(cxx_task.binary, folders["addons/sourcemod/extensions/x64"]) + else: + builder.AddCopy(cxx_task.binary, folders["addons/sourcemod/extensions"]) + pdblog.write(cxx_task.debug.path + "\n") +pdblog.close() + +CopyFiles("sourcemod/gamedata/collisionhook.txt", folders["addons/sourcemod/gamedata"]) +CopyFiles( + "sourcemod/scripting/include/collisionhook.inc", + folders["addons/sourcemod/scripting/include"], +) + +debug_info = [] diff --git a/buildbot/Versioning b/buildbot/Versioning new file mode 100644 index 0000000..e3647da --- /dev/null +++ b/buildbot/Versioning @@ -0,0 +1,50 @@ +# vim: set ts=8 sts=2 sw=2 tw=99 et ft=python: +import os, sys +import re + +builder.SetBuildFolder('/') +includes = builder.AddFolder('includes') + +argv = [ + sys.executable, + os.path.join(builder.sourcePath, 'buildbot', 'generate_header.py'), + os.path.join(builder.sourcePath), + os.path.join(builder.buildPath, 'includes'), +] + +outputs = [ + os.path.join(builder.buildFolder, 'includes', 'version_auto.h') +] + +repo_head_path = os.path.join(builder.sourcePath, 'product.version') +if os.path.exists(os.path.join(builder.sourcePath, '.git')): + with open(os.path.join(builder.sourcePath, '.git', 'HEAD')) as fp: + head_contents = fp.read().strip() + if re.search('^[a-fA-F0-9]{40}$', head_contents): + repo_head_path = os.path.join(builder.sourcePath, '.git', 'HEAD') + else: + git_state = head_contents.split(':')[1].strip() + repo_head_path = os.path.join(builder.sourcePath, '.git', git_state) + if not os.path.exists(repo_head_path): + repo_head_path = os.path.join(builder.sourcePath, '.git', 'HEAD') + +sources = [ + os.path.join(builder.sourcePath, 'product.version'), + repo_head_path, + argv[1] +] + +for source in sources: + if not os.path.exists(source): + print(source) +for source in sources: + if not os.path.exists(source): + print(source) + +output_nodes = builder.AddCommand( + inputs=sources, + argv=argv, + outputs=outputs +) + +rvalue = output_nodes \ No newline at end of file diff --git a/buildbot/generate_header.py b/buildbot/generate_header.py new file mode 100644 index 0000000..eeb508b --- /dev/null +++ b/buildbot/generate_header.py @@ -0,0 +1,61 @@ +# vim: set ts=2 sw=2 tw=99 noet ft=python: +import os, sys +import re +import subprocess + +argv = sys.argv[1:] +if len(argv) < 2: + sys.stderr.write('Usage: generate_header.py \n') + sys.exit(1) + +SourceFolder = os.path.abspath(os.path.normpath(argv[0])) +OutputFolder = os.path.normpath(argv[1]) + +def run_and_return(argv): + text = subprocess.check_output(argv) + if str != bytes: + text = str(text, 'utf-8') + return text.strip() + +def GetGHVersion(): + p = run_and_return(['hg', 'parent', '-R', SourceFolder]) + m = re.match('changeset:\s+(\d+):(.+)', p.stdoutText) + if m == None: + raise Exception('Could not determine repository version') + return m.groups() + +def GetGitVersion(): + revision_count = run_and_return(['git', 'rev-list', '--count', 'HEAD']) + revision_hash = run_and_return(['git', 'log', '--pretty=format:%h:%H', '-n', '1']) + shorthash, longhash = revision_hash.split(':') + + return revision_count, shorthash + +rev = None +cset = None +rev, cset = GetGitVersion() + +productFile = open(os.path.join(SourceFolder, 'product.version'), 'r') +productContents = productFile.read() +productFile.close() +m = re.match('(\d+)\.(\d+)\.(\d+)(.*)', productContents) +if m == None: + raise Exception('Could not detremine product version') +major, minor, release, tag = m.groups() + +incFile = open(os.path.join(OutputFolder, 'version_auto.h'), 'w') +incFile.write(""" +#ifndef _AUTO_VERSION_INFORMATION_H_ +#define _AUTO_VERSION_INFORMATION_H_ +#define SM_BUILD_TAG \"{0}\" +#define SM_BUILD_UNIQUEID \"{1}:{2}\" SM_BUILD_TAG +#define SM_VERSION \"{3}.{4}.{5}\" +#define SM_FULL_VERSION SM_VERSION SM_BUILD_TAG +#define SM_FILE_VERSION {6},{7},{8},0 +#endif /* _AUTO_VERSION_INFORMATION_H_ */ +""".format(tag, rev, cset, major, minor, release, major, minor, release)) +incFile.close() + +filename_versioning = open(os.path.join(OutputFolder, 'filename_versioning.txt'), 'w') +filename_versioning.write("{0}.{1}.{2}-git{3}-{4}".format(major, minor, release, rev, cset)) +filename_versioning.close() \ No newline at end of file diff --git a/buildbot/pushbuild.txt b/buildbot/pushbuild.txt new file mode 100644 index 0000000..87e1ac9 --- /dev/null +++ b/buildbot/pushbuild.txt @@ -0,0 +1 @@ +Lemons. diff --git a/configure.py b/configure.py new file mode 100644 index 0000000..3e48de3 --- /dev/null +++ b/configure.py @@ -0,0 +1,58 @@ +# vim: set sts=2 ts=8 sw=2 tw=99 et: +import sys +from ambuild2 import run + +# 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" +) +parser.options.add_argument( + "--sm-path", type=str, dest="sm_path", default=None, help="Path to SourceMod" +) +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( + "--enable-auto-versioning", + action="store_false", + dest="disable_auto_versioning", + default=True, + help="Enables the auto versioning script", +) +parser.options.add_argument( + "-s", + "--sdks", + default="all", + dest="sdks", + help='Build against specified SDKs; valid args are "all", "present", or ' + "space-delimited list of engine names (default: %default)", +) +parser.options.add_argument( + "--targets", + type=str, + dest="targets", + default=None, + help="Override the target architecture (use commas to separate multiple targets).", +) +parser.Configure() diff --git a/product.version b/product.version new file mode 100644 index 0000000..afaf360 --- /dev/null +++ b/product.version @@ -0,0 +1 @@ +1.0.0 \ No newline at end of file diff --git a/src/AMBuilder b/src/AMBuilder new file mode 100644 index 0000000..87f0d9a --- /dev/null +++ b/src/AMBuilder @@ -0,0 +1,31 @@ +# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python: +import os, sys + +projectname = "collisionhook" + +project = builder.LibraryProject(projectname + ".ext") +project.sources = [ + "extension.cpp", + os.path.join(Extension.sm_root, "public", "smsdk_ext.cpp"), + os.path.join(Extension.sm_root, "public", "CDetour", "detours.cpp"), + os.path.join(Extension.sm_root, "public", "asm", "asm.c"), + os.path.join(Extension.sm_root, "public", "libudis86", "decode.c"), + os.path.join(Extension.sm_root, "public", "libudis86", "itab.c"), + os.path.join(Extension.sm_root, "public", "libudis86", "syn-att.c"), + os.path.join(Extension.sm_root, "public", "libudis86", "syn-intel.c"), + os.path.join(Extension.sm_root, "public", "libudis86", "syn.c"), + os.path.join(Extension.sm_root, "public", "libudis86", "udis86.c"), +] + +for sdk_name in Extension.sdks: + sdk = Extension.sdks[sdk_name] + + for cxx in builder.targets: + if not cxx.target.arch in sdk.platformSpec[cxx.target.platform]: + continue + + binary = Extension.HL2ExtConfig( + project, builder, cxx, projectname + ".ext." + sdk.ext, sdk + ) + +Extension.extensions = builder.Add(project) diff --git a/src/extension.cpp b/src/extension.cpp index 70507d6..a809bd9 100644 --- a/src/extension.cpp +++ b/src/extension.cpp @@ -3,7 +3,7 @@ #include "extension.h" #include "sourcehook.h" -#include "detours.h" +#include "CDetour/detours.h" #include "vphysics_interface.h" #include "ihandleentity.h" diff --git a/src/smsdk_config.h b/src/smsdk_config.h new file mode 100644 index 0000000..3cff7b7 --- /dev/null +++ b/src/smsdk_config.h @@ -0,0 +1,84 @@ +/** + * vim: set ts=4 : + * ============================================================================= + * SourceMod Sample Extension + * 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_CONFIG_H_ +#define _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_ + +/** + * @file smsdk_config.h + * @brief Contains macros for configuring basic extension information. + */ + + #include "version.h" // SM_FULL_VERSION + +/* Basic information exposed publicly */ +#define SMEXT_CONF_NAME "CollisionHook" +#define SMEXT_CONF_DESCRIPTION "Hook on entity collision" +#define SMEXT_CONF_VERSION SM_FULL_VERSION +#define SMEXT_CONF_AUTHOR "VoiDeD" +#define SMEXT_CONF_URL "http://saxtonhell.com" +#define SMEXT_CONF_LOGTAG "CLHOOK" +#define SMEXT_CONF_LICENSE "GPL" +#define SMEXT_CONF_DATESTRING __DATE__ + +/** + * @brief Exposes plugin's main interface. + */ +#define SMEXT_LINK(name) SDKExtension *g_pExtensionIface = name; + +/** + * @brief Sets whether or not this plugin required Metamod. + * NOTE: Uncomment to enable, comment to disable. + */ +#define SMEXT_CONF_METAMOD + +/** Enable interfaces you want to use here by uncommenting lines */ +#define SMEXT_ENABLE_FORWARDSYS +//#define SMEXT_ENABLE_HANDLESYS +//#define SMEXT_ENABLE_PLAYERHELPERS +//#define SMEXT_ENABLE_DBMANAGER +#define SMEXT_ENABLE_GAMECONF +//#define SMEXT_ENABLE_MEMUTILS +#define SMEXT_ENABLE_GAMEHELPERS +//#define SMEXT_ENABLE_TIMERSYS +//#define SMEXT_ENABLE_THREADER +//#define SMEXT_ENABLE_LIBSYS +//#define SMEXT_ENABLE_MENUS +//#define SMEXT_ENABLE_ADTFACTORY +//#define SMEXT_ENABLE_PLUGINSYS +//#define SMEXT_ENABLE_ADMINSYS +//#define SMEXT_ENABLE_TEXTPARSERS +//#define SMEXT_ENABLE_USERMSGS +//#define SMEXT_ENABLE_TRANSLATOR +//#define SMEXT_ENABLE_NINVOKE +//#define SMEXT_ENABLE_ROOTCONSOLEMENU + +#endif // _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_ diff --git a/src/version.h b/src/version.h new file mode 100644 index 0000000..11591f5 --- /dev/null +++ b/src/version.h @@ -0,0 +1,27 @@ +#ifndef _INCLUDE_VERSION_INFORMATION_H_ +#define _INCLUDE_VERSION_INFORMATION_H_ + +/** + * @file Contains version information. + * @brief This file will redirect to an autogenerated version if being compiled via + * the build scripts. + */ + +#if defined SM_GENERATED_BUILD +#include "version_auto.h" +#else + +#ifndef SM_GENERATED_BUILD +#undef BINARY_NAME +#define BINARY_NAME "collisionhook.ext.dll\0" +#endif + +#define SM_BUILD_TAG "-manual" +#define SM_BUILD_UNIQUEID "[MANUAL BUILD]" +#define SM_VERSION "1.0.0" +#define SM_FULL_VERSION SM_VERSION SM_BUILD_TAG +#define SM_FILE_VERSION 1,0,0,0 + +#endif + +#endif /* _INCLUDE_VERSION_INFORMATION_H_ */ diff --git a/src/version.rc b/src/version.rc new file mode 100644 index 0000000..8b40f5b --- /dev/null +++ b/src/version.rc @@ -0,0 +1,45 @@ +#include "winres.h" + +#include + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif + +#ifndef SM_GENERATED_BUILD +#define BINARY_NAME "collisionhook.ext.dll\0" +#endif + +VS_VERSION_INFO VERSIONINFO + FILEVERSION SM_FILE_VERSION + PRODUCTVERSION SM_FILE_VERSION + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "Comments", "CollisionHook Extension" + VALUE "FileDescription", "SourceMod CollisionHook Extension" + VALUE "FileVersion", SM_BUILD_UNIQUEID + VALUE "InternalName", "CollisionHook" + VALUE "LegalCopyright", "Copyright (c) 2012, Ryan Stecker" + VALUE "OriginalFilename", BINARY_NAME + VALUE "ProductName", "CollisionHook Extension" + VALUE "ProductVersion", SM_FULL_VERSION + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0409, 0x04B0 + END +END From 9bb8a449eb9c420cef92eac0308fcc21143cc29f Mon Sep 17 00:00:00 2001 From: Ryan Stecker Date: Sun, 3 Mar 2024 16:46:10 -0600 Subject: [PATCH 02/10] Removed unused files. --- src/CDetour/detourhelpers.h | 98 -------- src/CDetour/detours.cpp | 192 --------------- src/CDetour/detours.h | 245 ------------------- src/asm/asm.c | 421 -------------------------------- src/asm/asm.h | 40 --- src/sdk/smsdk_config.h | 82 ------- src/sdk/smsdk_ext.cpp | 471 ------------------------------------ src/sdk/smsdk_ext.h | 342 -------------------------- 8 files changed, 1891 deletions(-) delete mode 100644 src/CDetour/detourhelpers.h delete mode 100644 src/CDetour/detours.cpp delete mode 100644 src/CDetour/detours.h delete mode 100644 src/asm/asm.c delete mode 100644 src/asm/asm.h delete mode 100644 src/sdk/smsdk_config.h delete mode 100644 src/sdk/smsdk_ext.cpp delete mode 100644 src/sdk/smsdk_ext.h diff --git a/src/CDetour/detourhelpers.h b/src/CDetour/detourhelpers.h deleted file mode 100644 index 85cda0e..0000000 --- a/src/CDetour/detourhelpers.h +++ /dev/null @@ -1,98 +0,0 @@ -/** - * vim: set ts=4 : - * ============================================================================= - * SourceMod - * Copyright (C) 2004-2007 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: detourhelpers.h 248 2008-08-27 00:56:22Z pred $ - */ - -#ifndef _INCLUDE_SOURCEMOD_DETOURHELPERS_H_ -#define _INCLUDE_SOURCEMOD_DETOURHELPERS_H_ - -#if defined PLATFORM_POSIX -#include -#define PAGE_SIZE 4096 -#define ALIGN(ar) ((long)ar & ~(PAGE_SIZE-1)) -#define PAGE_EXECUTE_READWRITE PROT_READ|PROT_WRITE|PROT_EXEC -#endif - -struct patch_t -{ - patch_t() - { - patch[0] = 0; - bytes = 0; - } - unsigned char patch[20]; - size_t bytes; -}; - -inline void ProtectMemory(void *addr, int length, int prot) -{ -#if defined PLATFORM_POSIX - void *addr2 = (void *)ALIGN(addr); - mprotect(addr2, sysconf(_SC_PAGESIZE), prot); -#elif defined PLATFORM_WINDOWS - DWORD old_prot; - VirtualProtect(addr, length, prot, &old_prot); -#endif -} - -inline void SetMemPatchable(void *address, size_t size) -{ - ProtectMemory(address, (int)size, PAGE_EXECUTE_READWRITE); -} - -inline void DoGatePatch(unsigned char *target, void *callback) -{ - SetMemPatchable(target, 20); - - target[0] = 0xFF; /* JMP */ - target[1] = 0x25; /* MEM32 */ - *(void **)(&target[2]) = callback; -} - -inline void ApplyPatch(void *address, int offset, const patch_t *patch, patch_t *restore) -{ - ProtectMemory(address, 20, PAGE_EXECUTE_READWRITE); - - unsigned char *addr = (unsigned char *)address + offset; - if (restore) - { - for (size_t i=0; ibytes; i++) - { - restore->patch[i] = addr[i]; - } - restore->bytes = patch->bytes; - } - - for (size_t i=0; ibytes; i++) - { - addr[i] = patch->patch[i]; - } -} - -#endif //_INCLUDE_SOURCEMOD_DETOURHELPERS_H_ diff --git a/src/CDetour/detours.cpp b/src/CDetour/detours.cpp deleted file mode 100644 index 71aba44..0000000 --- a/src/CDetour/detours.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/** -* vim: set ts=4 : -* ============================================================================= -* SourceMod -* 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: detours.cpp 248 2008-08-27 00:56:22Z pred $ -*/ - -#include "detours.h" -#include - -ISourcePawnEngine *CDetourManager::spengine = NULL; -IGameConfig *CDetourManager::gameconf = NULL; - -void CDetourManager::Init(ISourcePawnEngine *spengine, IGameConfig *gameconf) -{ - CDetourManager::spengine = spengine; - CDetourManager::gameconf = gameconf; -} - -CDetour *CDetourManager::CreateDetour(void *callbackfunction, void **trampoline, const char *signame) -{ - CDetour *detour = new CDetour(callbackfunction, trampoline, signame); - if (detour) - { - if (!detour->Init(spengine, gameconf)) - { - delete detour; - return NULL; - } - - return detour; - } - - return NULL; -} - -CDetour::CDetour(void *callbackfunction, void **trampoline, const char *signame) -{ - enabled = false; - detoured = false; - detour_address = NULL; - detour_trampoline = NULL; - this->signame = signame; - this->detour_callback = callbackfunction; - spengine = NULL; - gameconf = NULL; - this->trampoline = trampoline; -} - -bool CDetour::Init(ISourcePawnEngine *spengine, IGameConfig *gameconf) -{ - this->spengine = spengine; - this->gameconf = gameconf; - - if (!CreateDetour()) - { - enabled = false; - return enabled; - } - - enabled = true; - - return enabled; -} - -void CDetour::Destroy() -{ - DeleteDetour(); - delete this; -} - -bool CDetour::IsEnabled() -{ - return enabled; -} - -bool CDetour::CreateDetour() -{ - if (!gameconf->GetMemSig(signame, &detour_address)) - { - g_pSM->LogError(myself, "Could not locate %s - Disabling detour", signame); - return false; - } - - if (!detour_address) - { - g_pSM->LogError(myself, "Sigscan for %s failed - Disabling detour to prevent crashes", signame); - return false; - } - - detour_restore.bytes = copy_bytes((unsigned char *)detour_address, NULL, OP_JMP_SIZE+1); - - /* First, save restore bits */ - for (size_t i=0; iAllocatePageMemory(CodeSize); - spengine->SetReadWrite(wr.outbase); - wr.outptr = wr.outbase; - detour_trampoline = wr.outbase; - goto jit_rewind; - } - - spengine->SetReadExecute(wr.outbase); - - *trampoline = detour_trampoline; - - return true; -} - -void CDetour::DeleteDetour() -{ - if (detoured) - { - DisableDetour(); - } - - if (detour_trampoline) - { - /* Free the allocated trampoline memory */ - spengine->FreePageMemory(detour_trampoline); - detour_trampoline = NULL; - } -} - -void CDetour::EnableDetour() -{ - if (!detoured) - { - DoGatePatch((unsigned char *)detour_address, &detour_callback); - detoured = true; - } -} - -void CDetour::DisableDetour() -{ - if (detoured) - { - /* Remove the patch */ - ApplyPatch(detour_address, 0, &detour_restore, NULL); - detoured = false; - } -} diff --git a/src/CDetour/detours.h b/src/CDetour/detours.h deleted file mode 100644 index 00d3776..0000000 --- a/src/CDetour/detours.h +++ /dev/null @@ -1,245 +0,0 @@ -/** -* vim: set ts=4 : -* ============================================================================= -* SourceMod -* 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: detours.h 257 2008-09-23 03:12:13Z pred $ -*/ - -#ifndef _INCLUDE_SOURCEMOD_DETOURS_H_ -#define _INCLUDE_SOURCEMOD_DETOURS_H_ - -#include "extension.h" -#include -#include -#include "detourhelpers.h" - -/** - * CDetours class for SourceMod Extensions by pRED* - * detourhelpers.h entirely stolen from CSS:DM and were written by BAILOPAN (I assume). - * asm.h/c from devmaster.net (thanks cybermind) edited by pRED* to handle gcc -fPIC thunks correctly - * Concept by Nephyrin Zey (http://www.doublezen.net/) and Windows Detour Library (http://research.microsoft.com/sn/detours/) - * Member function pointer ideas by Don Clugston (http://www.codeproject.com/cpp/FastDelegate.asp) - */ - -#define DETOUR_MEMBER_CALL(name) (this->*name##_Actual) -#define DETOUR_STATIC_CALL(name) (name##_Actual) - -#define DETOUR_DECL_STATIC0(name, ret) \ -ret (*name##_Actual)(void) = NULL; \ -ret name(void) - -#define DETOUR_DECL_STATIC1(name, ret, p1type, p1name) \ -ret (*name##_Actual)(p1type) = NULL; \ -ret name(p1type p1name) - -#define DETOUR_DECL_STATIC2(name, ret, p1type, p1name, p2type, p2name) \ -ret (*name##_Actual)(p1type, p2type) = NULL; \ -ret name(p1type p1name, p2type p2name) - -#define DETOUR_DECL_STATIC4(name, ret, p1type, p1name, p2type, p2name, p3type, p3name, p4type, p4name) \ -ret (*name##_Actual)(p1type, p2type, p3type, p4type) = NULL; \ -ret name(p1type p1name, p2type p2name, p3type p3name, p4type p4name) - -#define DETOUR_DECL_MEMBER0(name, ret) \ -class name##Class \ -{ \ -public: \ - ret name(); \ - static ret (name##Class::* name##_Actual)(void); \ -}; \ -ret (name##Class::* name##Class::name##_Actual)(void) = NULL; \ -ret name##Class::name() - -#define DETOUR_DECL_MEMBER1(name, ret, p1type, p1name) \ -class name##Class \ -{ \ -public: \ - ret name(p1type p1name); \ - static ret (name##Class::* name##_Actual)(p1type); \ -}; \ -ret (name##Class::* name##Class::name##_Actual)(p1type) = NULL; \ -ret name##Class::name(p1type p1name) - -#define DETOUR_DECL_MEMBER2(name, ret, p1type, p1name, p2type, p2name) \ -class name##Class \ -{ \ -public: \ - ret name(p1type p1name, p2type p2name); \ - static ret (name##Class::* name##_Actual)(p1type, p2type); \ -}; \ -ret (name##Class::* name##Class::name##_Actual)(p1type, p2type) = NULL; \ -ret name##Class::name(p1type p1name, p2type p2name) - -#define DETOUR_DECL_MEMBER3(name, ret, p1type, p1name, p2type, p2name, p3type, p3name) \ -class name##Class \ -{ \ -public: \ - ret name(p1type p1name, p2type p2name, p3type p3name); \ - static ret (name##Class::* name##_Actual)(p1type, p2type, p3type); \ -}; \ -ret (name##Class::* name##Class::name##_Actual)(p1type, p2type, p3type) = NULL; \ -ret name##Class::name(p1type p1name, p2type p2name, p3type p3name) - -#define DETOUR_DECL_MEMBER4(name, ret, p1type, p1name, p2type, p2name, p3type, p3name, p4type, p4name) \ -class name##Class \ -{ \ -public: \ - ret name(p1type p1name, p2type p2name, p3type p3name, p4type p4name); \ - static ret (name##Class::* name##_Actual)(p1type, p2type, p3type, p4type); \ -}; \ -ret (name##Class::* name##Class::name##_Actual)(p1type, p2type, p3type, p4type) = NULL; \ -ret name##Class::name(p1type p1name, p2type p2name, p3type p3name, p4type p4name) - - -#define GET_MEMBER_CALLBACK(name) (void *)GetCodeAddress(&name##Class::name) -#define GET_MEMBER_TRAMPOLINE(name) (void **)(&name##Class::name##_Actual) - -#define GET_STATIC_CALLBACK(name) (void *)&name -#define GET_STATIC_TRAMPOLINE(name) (void **)&name##_Actual - -#define DETOUR_CREATE_MEMBER(name, gamedata) CDetourManager::CreateDetour(GET_MEMBER_CALLBACK(name), GET_MEMBER_TRAMPOLINE(name), gamedata); -#define DETOUR_CREATE_STATIC(name, gamedata) CDetourManager::CreateDetour(GET_STATIC_CALLBACK(name), GET_STATIC_TRAMPOLINE(name), gamedata); - - -class GenericClass {}; -typedef void (GenericClass::*VoidFunc)(); - -inline void *GetCodeAddr(VoidFunc mfp) -{ - return *(void **)&mfp; -} - -/** - * Converts a member function pointer to a void pointer. - * This relies on the assumption that the code address lies at mfp+0 - * This is the case for both g++ and later MSVC versions on non virtual functions but may be different for other compilers - * Based on research by Don Clugston : http://www.codeproject.com/cpp/FastDelegate.asp - */ -#define GetCodeAddress(mfp) GetCodeAddr(reinterpret_cast(mfp)) - -class CDetourManager; - -class CDetour -{ -public: - - bool IsEnabled(); - - /** - * These would be somewhat self-explanatory I hope - */ - void EnableDetour(); - void DisableDetour(); - - void Destroy(); - - friend class CDetourManager; - -protected: - CDetour(void *callbackfunction, void **trampoline, const char *signame); - - bool Init(ISourcePawnEngine *spengine, IGameConfig *gameconf); -private: - - /* These create/delete the allocated memory */ - bool CreateDetour(); - void DeleteDetour(); - - bool enabled; - bool detoured; - - patch_t detour_restore; - /* Address of the detoured function */ - void *detour_address; - /* Address of the allocated trampoline function */ - void *detour_trampoline; - /* Address of the callback handler */ - void *detour_callback; - /* The function pointer used to call our trampoline */ - void **trampoline; - - const char *signame; - ISourcePawnEngine *spengine; - IGameConfig *gameconf; -}; - -class CDetourManager -{ -public: - - static void Init(ISourcePawnEngine *spengine, IGameConfig *gameconf); - - /** - * Creates a new detour - * - * @param callbackfunction Void pointer to your detour callback function. - * @param trampoline Address of the trampoline pointer - * @param signame Section name containing a signature to fetch from the gamedata file. - * @return A new CDetour pointer to control your detour. - * - * Example: - * - * CBaseServer::ConnectClient(netadr_s &, int, int, int, char const*, char const*, char const*, int) - * - * Define a new class with the required function and a member function pointer to the same type: - * - * class CBaseServerDetour - * { - * public: - * bool ConnectClient(void *netaddr_s, int, int, int, char const*, char const*, char const*, int); - * static bool (CBaseServerDetour::* ConnectClient_Actual)(void *netaddr_s, int, int, int, char const*, char const*, char const*, int); - * } - * - * void *callbackfunc = GetCodeAddress(&CBaseServerDetour::ConnectClient); - * void **trampoline = (void **)(&CBaseServerDetour::ConnectClient_Actual); - * - * Creation: - * CDetourManager::CreateDetour(callbackfunc, trampoline, "ConnectClient"); - * - * Usage: - * - * CBaseServerDetour::ConnectClient(void *netaddr_s, int, int, int, char const*, char const*, char const*, int) - * { - * //pre hook code - * bool result = (this->*ConnectClient_Actual)(netaddr_s, rest of params); - * //post hook code - * return result; - * } - * - * Note we changed the netadr_s reference into a void* to avoid needing to define the type - */ - static CDetour *CreateDetour(void *callbackfunction, void **trampoline, const char *signame); - - friend class CBlocker; - friend class CDetour; - -private: - static ISourcePawnEngine *spengine; - static IGameConfig *gameconf; -}; - -#endif // _INCLUDE_SOURCEMOD_DETOURS_H_ diff --git a/src/asm/asm.c b/src/asm/asm.c deleted file mode 100644 index b984fef..0000000 --- a/src/asm/asm.c +++ /dev/null @@ -1,421 +0,0 @@ -#include "asm.h" - -#ifndef WIN32 -#define _GNU_SOURCE -#include -#include - -#define REG_EAX 0 -#define REG_ECX 1 -#define REG_EDX 2 -#define REG_EBX 3 - -#define IA32_MOV_REG_IMM 0xB8 // encoding is +r -#endif - -extern void Msg( const char *, ... ); - -/** -* Checks if a call to a fpic thunk has just been written into dest. -* If found replaces it with a direct mov that sets the required register to the value of pc. -* -* @param dest Destination buffer where a call opcode + addr (5 bytes) has just been written. -* @param pc The program counter value that needs to be set (usually the next address from the source). -* @noreturn -*/ -void check_thunks(unsigned char *dest, unsigned char *pc) -{ -#if defined WIN32 - return; -#else - /* Step write address back 4 to the start of the function address */ - unsigned char *writeaddr = dest - 4; - unsigned char *calloffset = *(unsigned char **)writeaddr; - unsigned char *calladdr = (unsigned char *)(dest + (unsigned int)calloffset); - - /* Lookup name of function being called */ - if ((*calladdr == 0x8B) && (*(calladdr+2) == 0x24) && (*(calladdr+3) == 0xC3)) - { - //a thunk maybe? - char movByte = IA32_MOV_REG_IMM; - - /* Calculate the correct mov opcode */ - switch (*(calladdr+1)) - { - case 0x04: - { - movByte += REG_EAX; - break; - } - case 0x1C: - { - movByte += REG_EBX; - break; - } - case 0x0C: - { - movByte += REG_ECX; - break; - } - case 0x14: - { - movByte += REG_EDX; - break; - } - default: - { - Msg("Unknown thunk: %c\n", *(calladdr+1)); - break; - } - } - - /* Move our write address back one to where the call opcode was */ - writeaddr--; - - - /* Write our mov */ - *writeaddr = movByte; - writeaddr++; - - /* Write the value - The provided program counter value */ - *(void **)writeaddr = (void *)pc; - writeaddr += 4; - } - - return; -#endif -} - -//if dest is NULL, returns minimum number of bytes needed to be copied -//if dest is not NULL, it will copy the bytes to dest as well as fix CALLs and JMPs -//http://www.devmaster.net/forums/showthread.php?t=2311 -int copy_bytes(unsigned char *func, unsigned char* dest, int required_len) { - int bytecount = 0; - - while(bytecount < required_len && *func != 0xCC) - { - // prefixes F0h, F2h, F3h, 66h, 67h, D8h-DFh, 2Eh, 36h, 3Eh, 26h, 64h and 65h - int operandSize = 4; - int FPU = 0; - int twoByte = 0; - unsigned char opcode = 0x90; - unsigned char modRM = 0xFF; - while(*func == 0xF0 || - *func == 0xF2 || - *func == 0xF3 || - (*func & 0xFC) == 0x64 || - (*func & 0xF8) == 0xD8 || - (*func & 0x7E) == 0x62) - { - if(*func == 0x66) - { - operandSize = 2; - } - else if((*func & 0xF8) == 0xD8) - { - FPU = *func; - if (dest) - *dest++ = *func++; - else - func++; - bytecount++; - break; - } - - if (dest) - *dest++ = *func++; - else - func++; - bytecount++; - } - - // two-byte opcode byte - if(*func == 0x0F) - { - twoByte = 1; - if (dest) - *dest++ = *func++; - else - func++; - bytecount++; - } - - // opcode byte - opcode = *func++; - if (dest) *dest++ = opcode; - bytecount++; - - // mod R/M byte - modRM = 0xFF; - if(FPU) - { - if((opcode & 0xC0) != 0xC0) - { - modRM = opcode; - } - } - else if(!twoByte) - { - if((opcode & 0xC4) == 0x00 || - (opcode & 0xF4) == 0x60 && ((opcode & 0x0A) == 0x02 || (opcode & 0x09) == 0x09) || - (opcode & 0xF0) == 0x80 || - (opcode & 0xF8) == 0xC0 && (opcode & 0x0E) != 0x02 || - (opcode & 0xFC) == 0xD0 || - (opcode & 0xF6) == 0xF6) - { - modRM = *func++; - if (dest) *dest++ = modRM; - bytecount++; - } - } - else - { - if((opcode & 0xF0) == 0x00 && (opcode & 0x0F) >= 0x04 && (opcode & 0x0D) != 0x0D || - (opcode & 0xF0) == 0x30 || - opcode == 0x77 || - (opcode & 0xF0) == 0x80 || - (opcode & 0xF0) == 0xA0 && (opcode & 0x07) <= 0x02 || - (opcode & 0xF8) == 0xC8) - { - // No mod R/M byte - } - else - { - modRM = *func++; - if (dest) *dest++ = modRM; - bytecount++; - } - } - - // SIB - if((modRM & 0x07) == 0x04 && - (modRM & 0xC0) != 0xC0) - { - if (dest) - *dest++ = *func++; //SIB - else - func++; - bytecount++; - } - - // mod R/M displacement - - // Dword displacement, no base - if((modRM & 0xC5) == 0x05) { - if (dest) { - *(unsigned int*)dest = *(unsigned int*)func; - dest += 4; - } - func += 4; - bytecount += 4; - } - - // Byte displacement - if((modRM & 0xC0) == 0x40) { - if (dest) - *dest++ = *func++; - else - func++; - bytecount++; - } - - // Dword displacement - if((modRM & 0xC0) == 0x80) { - if (dest) { - *(unsigned int*)dest = *(unsigned int*)func; - dest += 4; - } - func += 4; - bytecount += 4; - } - - // immediate - if(FPU) - { - // Can't have immediate operand - } - else if(!twoByte) - { - if((opcode & 0xC7) == 0x04 || - (opcode & 0xFE) == 0x6A || // PUSH/POP/IMUL - (opcode & 0xF0) == 0x70 || // Jcc - opcode == 0x80 || - opcode == 0x83 || - (opcode & 0xFD) == 0xA0 || // MOV - opcode == 0xA8 || // TEST - (opcode & 0xF8) == 0xB0 || // MOV - (opcode & 0xFE) == 0xC0 || // RCL - opcode == 0xC6 || // MOV - opcode == 0xCD || // INT - (opcode & 0xFE) == 0xD4 || // AAD/AAM - (opcode & 0xF8) == 0xE0 || // LOOP/JCXZ - opcode == 0xEB || - opcode == 0xF6 && (modRM & 0x30) == 0x00) // TEST - { - if (dest) - *dest++ = *func++; - else - func++; - bytecount++; - } - else if((opcode & 0xF7) == 0xC2) // RET - { - if (dest) { - *(unsigned short*)dest = *(unsigned short*)func; - dest += 2; - } - func += 2; - bytecount += 2; - } - else if((opcode & 0xFC) == 0x80 || - (opcode & 0xC7) == 0x05 || - (opcode & 0xF8) == 0xB8 || - (opcode & 0xFE) == 0xE8 || // CALL/Jcc - (opcode & 0xFE) == 0x68 || - (opcode & 0xFC) == 0xA0 || - (opcode & 0xEE) == 0xA8 || - opcode == 0xC7 || - opcode == 0xF7 && (modRM & 0x30) == 0x00) - { - if (dest) { - //Fix CALL/JMP offset - if ((opcode & 0xFE) == 0xE8) { - if (operandSize == 4) - { - *(long*)dest = ((func + *(long*)func) - dest); - - //pRED* edit. func is the current address of the call address, +4 is the next instruction, so the value of $pc - check_thunks(dest+4, func+4); - } - else - *(short*)dest = ((func + *(short*)func) - dest); - - } else { - if (operandSize == 4) - *(unsigned long*)dest = *(unsigned long*)func; - else - *(unsigned short*)dest = *(unsigned short*)func; - } - dest += operandSize; - } - func += operandSize; - bytecount += operandSize; - - } - } - else - { - if(opcode == 0xBA || // BT - opcode == 0x0F || // 3DNow! - (opcode & 0xFC) == 0x70 || // PSLLW - (opcode & 0xF7) == 0xA4 || // SHLD - opcode == 0xC2 || - opcode == 0xC4 || - opcode == 0xC5 || - opcode == 0xC6) - { - if (dest) - *dest++ = *func++; - else - func++; - } - else if((opcode & 0xF0) == 0x80) // Jcc -i - { - if (dest) { - if (operandSize == 4) - *(unsigned long*)dest = *(unsigned long*)func; - else - *(unsigned short*)dest = *(unsigned short*)func; - - dest += operandSize; - } - func += operandSize; - bytecount += operandSize; - } - } - } - - return bytecount; -} - -//insert a specific JMP instruction at the given location -void inject_jmp(void* src, void* dest) { - *(unsigned char*)src = OP_JMP; - *(long*)((unsigned char*)src+1) = (long)((unsigned char*)dest - ((unsigned char*)src + OP_JMP_SIZE)); -} - -//fill a given block with NOPs -void fill_nop(void* src, unsigned int len) { - unsigned char* src2 = (unsigned char*)src; - while (len) { - *src2++ = OP_NOP; - --len; - } -} - -void* eval_jump(void* src) { - unsigned char* addr = (unsigned char*)src; - - if (!addr) return 0; - - //import table jump - if (addr[0] == OP_PREFIX && addr[1] == OP_JMP_SEG) { - addr += 2; - addr = *(unsigned char**)addr; - //TODO: if addr points into the IAT - return *(void**)addr; - } - - //8bit offset - else if (addr[0] == OP_JMP_BYTE) { - addr = &addr[OP_JMP_BYTE_SIZE] + *(char*)&addr[1]; - //mangled 32bit jump? - if (addr[0] = OP_JMP) { - addr = addr + *(int*)&addr[1]; - } - return addr; - } - /* - //32bit offset - else if (addr[0] == OP_JMP) { - addr = &addr[OP_JMP_SIZE] + *(int*)&addr[1]; - } - */ - - return addr; -} -/* -from ms detours package -static bool detour_is_imported(PBYTE pbCode, PBYTE pbAddress) -{ - MEMORY_BASIC_INFORMATION mbi; - VirtualQuery((PVOID)pbCode, &mbi, sizeof(mbi)); - __try { - PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)mbi.AllocationBase; - if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE) { - return false; - } - - PIMAGE_NT_HEADERS pNtHeader = (PIMAGE_NT_HEADERS)((PBYTE)pDosHeader + - pDosHeader->e_lfanew); - if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) { - return false; - } - - if (pbAddress >= ((PBYTE)pDosHeader + - pNtHeader->OptionalHeader - .DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress) && - pbAddress < ((PBYTE)pDosHeader + - pNtHeader->OptionalHeader - .DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress + - pNtHeader->OptionalHeader - .DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].Size)) { - return true; - } - return false; - } - __except(EXCEPTION_EXECUTE_HANDLER) { - return false; - } -} -*/ diff --git a/src/asm/asm.h b/src/asm/asm.h deleted file mode 100644 index 6086232..0000000 --- a/src/asm/asm.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef __ASM_H__ -#define __ASM_H__ - -#define OP_JMP 0xE9 -#define OP_JMP_SIZE 5 - -#define OP_NOP 0x90 -#define OP_NOP_SIZE 1 - -#define OP_PREFIX 0xFF -#define OP_JMP_SEG 0x25 - -#define OP_JMP_BYTE 0xEB -#define OP_JMP_BYTE_SIZE 2 - -#ifdef __cplusplus -extern "C" { -#endif - -void check_thunks(unsigned char *dest, unsigned char *pc); - -//if dest is NULL, returns minimum number of bytes needed to be copied -//if dest is not NULL, it will copy the bytes to dest as well as fix CALLs and JMPs -//http://www.devmaster.net/forums/showthread.php?t=2311 -int copy_bytes(unsigned char *func, unsigned char* dest, int required_len); - -//insert a specific JMP instruction at the given location -void inject_jmp(void* src, void* dest); - -//fill a given block with NOPs -void fill_nop(void* src, unsigned int len); - -//evaluate a JMP at the target -void* eval_jump(void* src); - -#ifdef __cplusplus -} -#endif - -#endif //__ASM_H__ diff --git a/src/sdk/smsdk_config.h b/src/sdk/smsdk_config.h deleted file mode 100644 index 7c48377..0000000 --- a/src/sdk/smsdk_config.h +++ /dev/null @@ -1,82 +0,0 @@ -/** - * vim: set ts=4 : - * ============================================================================= - * SourceMod Sample Extension - * 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_CONFIG_H_ -#define _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_ - -/** - * @file smsdk_config.h - * @brief Contains macros for configuring basic extension information. - */ - -/* Basic information exposed publicly */ -#define SMEXT_CONF_NAME "CollisionHook" -#define SMEXT_CONF_DESCRIPTION "Hook on entity collision" -#define SMEXT_CONF_VERSION "0.2" -#define SMEXT_CONF_AUTHOR "VoiDeD" -#define SMEXT_CONF_URL "http://saxtonhell.com" -#define SMEXT_CONF_LOGTAG "CLHOOK" -#define SMEXT_CONF_LICENSE "GPL" -#define SMEXT_CONF_DATESTRING __DATE__ - -/** - * @brief Exposes plugin's main interface. - */ -#define SMEXT_LINK(name) SDKExtension *g_pExtensionIface = name; - -/** - * @brief Sets whether or not this plugin required Metamod. - * NOTE: Uncomment to enable, comment to disable. - */ -#define SMEXT_CONF_METAMOD - -/** Enable interfaces you want to use here by uncommenting lines */ -#define SMEXT_ENABLE_FORWARDSYS -//#define SMEXT_ENABLE_HANDLESYS -//#define SMEXT_ENABLE_PLAYERHELPERS -//#define SMEXT_ENABLE_DBMANAGER -#define SMEXT_ENABLE_GAMECONF -//#define SMEXT_ENABLE_MEMUTILS -#define SMEXT_ENABLE_GAMEHELPERS -//#define SMEXT_ENABLE_TIMERSYS -//#define SMEXT_ENABLE_THREADER -//#define SMEXT_ENABLE_LIBSYS -//#define SMEXT_ENABLE_MENUS -//#define SMEXT_ENABLE_ADTFACTORY -//#define SMEXT_ENABLE_PLUGINSYS -//#define SMEXT_ENABLE_ADMINSYS -//#define SMEXT_ENABLE_TEXTPARSERS -//#define SMEXT_ENABLE_USERMSGS -//#define SMEXT_ENABLE_TRANSLATOR -//#define SMEXT_ENABLE_NINVOKE -//#define SMEXT_ENABLE_ROOTCONSOLEMENU - -#endif // _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_ diff --git a/src/sdk/smsdk_ext.cpp b/src/sdk/smsdk_ext.cpp deleted file mode 100644 index a9714cf..0000000 --- a/src/sdk/smsdk_ext.cpp +++ /dev/null @@ -1,471 +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.h" - -/** - * @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 -#if defined SMEXT_ENABLE_ROOTCONSOLEMENU -IRootConsole *rootconsole = 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 defined SMEXT_ENABLE_ROOTCONSOLEMENU - SM_GET_IFACE(ROOTCONSOLE, rootconsole); -#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) -{ - free(ptr); -} - -void operator delete[](void * ptr) -{ - free(ptr); -} -#endif - diff --git a/src/sdk/smsdk_ext.h b/src/sdk/smsdk_ext.h deleted file mode 100644 index 024a9f4..0000000 --- a/src/sdk/smsdk_ext.h +++ /dev/null @@ -1,342 +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.h - * @brief Contains wrappers for making Extensions easier to write. - */ - -#include "smsdk_config.h" -#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_ENABLE_ROOTCONSOLEMENU -#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_ From 87762586bdcc712732f0083362324a7580265deb Mon Sep 17 00:00:00 2001 From: Ryan Stecker Date: Sun, 3 Mar 2024 16:46:20 -0600 Subject: [PATCH 03/10] Cleanup. --- src/.gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/.gitignore b/src/.gitignore index e3d9d33..4a0d027 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -399,4 +399,8 @@ FodyWeavers.xsd # ignore temp/build directories msvc10/Debug*/ -msvc10/Release*/ \ No newline at end of file +msvc10/Release*/ + +# AMBuild2 outputs +includes/ +pdblog.txt From 77ad110b7b96135294f0a7dfe8d849800205a110 Mon Sep 17 00:00:00 2001 From: Ryan Stecker Date: Sun, 3 Mar 2024 17:04:26 -0600 Subject: [PATCH 04/10] Fix windows x64 build. --- AMBuildScript | 1 - 1 file changed, 1 deletion(-) diff --git a/AMBuildScript b/AMBuildScript index 84e8509..4e1476e 100644 --- a/AMBuildScript +++ b/AMBuildScript @@ -366,7 +366,6 @@ class ExtensionConfig(object): "/TP", ] cxx.linkflags += [ - "/MACHINE:X86", "kernel32.lib", "user32.lib", "gdi32.lib", From 53fbee25eb49c00df855490a8fb1349d4cfd2fa3 Mon Sep 17 00:00:00 2001 From: Ryan Stecker Date: Sun, 3 Mar 2024 17:04:39 -0600 Subject: [PATCH 05/10] Don't upload symbols. --- AMBuildScript | 2 +- buildbot/BreakpadSymbols | 39 --------------------------------------- 2 files changed, 1 insertion(+), 40 deletions(-) delete mode 100644 buildbot/BreakpadSymbols diff --git a/AMBuildScript b/AMBuildScript index 4e1476e..33501c7 100644 --- a/AMBuildScript +++ b/AMBuildScript @@ -625,6 +625,6 @@ if Extension.use_auto_versioning(): builder.targets = builder.CloneableList(Extension.all_targets) # Add additional buildscripts here -BuildScripts = ["src/AMBuilder", "buildbot/PackageScript", "buildbot/BreakpadSymbols"] +BuildScripts = ["src/AMBuilder", "buildbot/PackageScript"] builder.Build(BuildScripts, {"Extension": Extension}) diff --git a/buildbot/BreakpadSymbols b/buildbot/BreakpadSymbols deleted file mode 100644 index a85f0bf..0000000 --- a/buildbot/BreakpadSymbols +++ /dev/null @@ -1,39 +0,0 @@ -# vim: set ts=2 sw=2 tw=99 noet ft=python: -import os, sys - -UPLOAD_SCRIPT = os.path.join(Extension.sm_root, 'tools', 'buildbot', 'upload_symbols.py') - -if 'BREAKPAD_SYMBOL_SERVER' in os.environ: - symbolServer = os.environ['BREAKPAD_SYMBOL_SERVER'] - builder.SetBuildFolder('breakpad-symbols') - - for cxx_task in Extension.extensions: - if cxx_task.target.platform in ['windows']: - debug_entry = cxx_task.debug - else: - debug_entry = cxx_task.binary - - debug_file = os.path.join(builder.buildPath, debug_entry.path) - if cxx_task.target.platform == 'linux': - argv = ['dump_syms', debug_file, os.path.dirname(debug_file)] - elif cxx_task.target.platform == 'mac': - # Required once dump_syms is updated on the slaves. - #argv = ['dump_syms', '-g', debug_file + '.dSYM', debug_file] - argv = ['dump_syms', debug_file + '.dSYM'] - elif cxx_task.target.platform == 'windows': - argv = ['dump_syms.exe', debug_file] - - plat_dir = os.path.dirname(debug_file) - bin_dir = os.path.split(plat_dir)[0] - - symbol_file = '{}-{}-{}.breakpad'.format( - os.path.split(bin_dir)[1], - cxx_task.target.platform, - cxx_task.target.arch) - - argv = [sys.executable, UPLOAD_SCRIPT, symbol_file] + argv - builder.AddCommand( - inputs = [UPLOAD_SCRIPT, debug_entry], - argv = argv, - outputs = [symbol_file] - ) \ No newline at end of file From d735633d2147afb061a453cf9c98232e2ee5017c Mon Sep 17 00:00:00 2001 From: Ryan Stecker Date: Sun, 3 Mar 2024 17:07:28 -0600 Subject: [PATCH 06/10] Try add CI. --- .github/workflows/ci.yml | 152 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..122a7ff --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,152 @@ +name: Extension builder + +on: + push: + branches: [action, master] + pull_request: + branches: [action, master] + +jobs: + build: + strategy: + matrix: + os: [ubuntu-20.04, windows-2019, ubuntu-latest, windows-latest] + include: + - os: ubuntu-20.04 + cc: clang-10 + cxx: clang++-10 + - os: windows-2019 + cc: msvc + - os: ubuntu-latest + cc: clang + cxx: clang++ + - os: windows-latest + cc: msvc + fail-fast: false + + name: ${{ matrix.os }} - ${{ matrix.cc }} + runs-on: ${{ matrix.os }} + + env: + PROJECT: "collisionhook" + SDKS: "css hl2dm dods tf2" + MMSOURCE_VERSION: "1.11" + SOURCEMOD_VERSION: "1.11" + CACHE_PATH: ${{ github.workspace }}/cache + steps: + - name: Concatenate SDK Names + shell: bash + run: | + # Paranoia + SDKS_VAR="${{env.SDKS}}" + # This will be used in our cache key + echo "SDKS_KEY=${SDKS_VAR//[[:blank:]]/}" >> $GITHUB_ENV + + - name: Linux dependencies + if: startsWith(runner.os, 'Linux') + run: | + sudo dpkg --add-architecture i386 + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + gcc-multilib g++-multilib libstdc++6 lib32stdc++6 \ + libc6-dev libc6-dev-i386 linux-libc-dev \ + linux-libc-dev:i386 lib32z1-dev ${{ matrix.cc }} + + - uses: actions/setup-python@v4 + name: Setup Python 3.9 + with: + python-version: 3.9 + + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip setuptools wheel + + - uses: actions/checkout@v3 + name: Repository checkout + with: + fetch-depth: 0 + path: extension + + - uses: actions/cache@v3 + name: Cache dependencies + env: + cache-name: collisionhook-cache + with: + path: ${{ env.CACHE_PATH }} + key: ${{ runner.os }}-build-${{ env.cache-name }}-sm${{ env.SOURCEMOD_VERSION }}-mmsource${{ env.MMSOURCE_VERSION }}-${{ env.SDKS_KEY }} + + - shell: bash + name: Install dependencies + run: | + mkdir -p "${{ env.CACHE_PATH }}" + cd "${{ env.CACHE_PATH }}" + shallow_checkout () { + # Param 1 is origin + # Param 2 is branch + # Param 3 is name + if [ ! -d "$3" ]; then + git clone "$1" --depth 1 --branch "$2" "$3" + fi + cd "$3" + git remote set-url origin "$1" + git fetch --depth 1 origin "$2" + git checkout --force --recurse-submodules FETCH_HEAD + git submodule init + git submodule update --depth 1 + cd .. + } + # We are aware of what we are doing! + git config --global advice.detachedHead false + # Verify github cache, and see if we don't have the sdks already cloned and update them + for sdk in ${{ env.SDKS }} + do + shallow_checkout "https://github.com/alliedmodders/hl2sdk" "${sdk}" "hl2sdk-${sdk}" + done + shallow_checkout "https://github.com/alliedmodders/ambuild" "master" "ambuild" + shallow_checkout "https://github.com/alliedmodders/sourcemod" "${{env.SOURCEMOD_VERSION}}-dev" "sourcemod" + shallow_checkout "https://github.com/alliedmodders/metamod-source/" "${{env.MMSOURCE_VERSION}}-dev" "metamod-source" + # But maybe others aren't (also probably unnecessary because git actions but paranoia) + git config --global advice.detachedHead true + + - name: Setup AMBuild + shell: bash + run: | + cd "${{ env.CACHE_PATH }}" + python -m pip install ./ambuild + + - name: Select clang compiler + if: startsWith(runner.os, 'Linux') + run: | + echo "CC=${{ matrix.cc }}" >> $GITHUB_ENV + echo "CXX=${{ matrix.cxx }}" >> $GITHUB_ENV + ${{ matrix.cc }} --version + ${{ matrix.cxx }} --version + + - name: Build + shell: bash + working-directory: src + run: | + mkdir build + cd build + python ../configure.py --enable-auto-versioning --enable-optimize --sdks="${{ env.SDKS }}" --mms-path="${{ env.CACHE_PATH }}/metamod-source" --hl2sdk-root="${{ env.CACHE_PATH }}" --sm-path="${{ env.CACHE_PATH }}/sourcemod" + ambuild + + PLATFORM="${{ runner.os }}" + FILENAME="$(cat ./includes/filename_versioning.txt)" + ZIP_FILENAME="${{ env.PROJECT }}-${FILENAME}-${PLATFORM,}.zip" + + echo "ZIP_FILENAME=${ZIP_FILENAME}" >> $GITHUB_ENV + + - name: Package release - Windows + if: github.event_name == 'push' && github.ref == 'refs/heads/action' && startsWith(matrix.os, 'windows-latest') + working-directory: build/package + run: Compress-Archive -Path * -Destination ${{ env.ZIP_FILENAME }} + + - name: Package release + if: github.event_name == 'push' && github.ref == 'refs/heads/action' && startsWith(matrix.os, 'ubuntu-latest') + working-directory: build/package + run: zip -r "${{ env.ZIP_FILENAME }}" . + + - uses: actions/upload-artifact@v4 + with: + path: "${{ env.ZIP_FILENAME }}" From 4dec86cff2e1145fbc7065b57832a38cc1a83395 Mon Sep 17 00:00:00 2001 From: Ryan Stecker Date: Sun, 3 Mar 2024 17:12:02 -0600 Subject: [PATCH 07/10] Fix CI cwd. --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 122a7ff..8cc80da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -124,7 +124,7 @@ jobs: - name: Build shell: bash - working-directory: src + working-directory: extension run: | mkdir build cd build @@ -139,12 +139,12 @@ jobs: - name: Package release - Windows if: github.event_name == 'push' && github.ref == 'refs/heads/action' && startsWith(matrix.os, 'windows-latest') - working-directory: build/package + working-directory: extension/build/package run: Compress-Archive -Path * -Destination ${{ env.ZIP_FILENAME }} - name: Package release if: github.event_name == 'push' && github.ref == 'refs/heads/action' && startsWith(matrix.os, 'ubuntu-latest') - working-directory: build/package + working-directory: extension/build/package run: zip -r "${{ env.ZIP_FILENAME }}" . - uses: actions/upload-artifact@v4 From 57975a3b84c95a529414ffa749e2dd55b93e3047 Mon Sep 17 00:00:00 2001 From: Ryan Stecker Date: Sun, 3 Mar 2024 17:24:10 -0600 Subject: [PATCH 08/10] Fix win64 CI. --- .github/workflows/ci.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8cc80da..7260dba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -80,6 +80,7 @@ jobs: run: | mkdir -p "${{ env.CACHE_PATH }}" cd "${{ env.CACHE_PATH }}" + shallow_checkout () { # Param 1 is origin # Param 2 is branch @@ -95,16 +96,25 @@ jobs: git submodule update --depth 1 cd .. } + # We are aware of what we are doing! git config --global advice.detachedHead false + # Verify github cache, and see if we don't have the sdks already cloned and update them for sdk in ${{ env.SDKS }} do + # TODO: remove these conditionals once https://github.com/alliedmodders/hl2sdk/pull/198 is merged + if [ "${sdk}" == "tf2" ]; then + shallow_checkout "https://github.com/Kenzzer/hl2sdk" "tf2_win64" "hl2sdk-tf2" + else shallow_checkout "https://github.com/alliedmodders/hl2sdk" "${sdk}" "hl2sdk-${sdk}" + fi done + shallow_checkout "https://github.com/alliedmodders/ambuild" "master" "ambuild" shallow_checkout "https://github.com/alliedmodders/sourcemod" "${{env.SOURCEMOD_VERSION}}-dev" "sourcemod" shallow_checkout "https://github.com/alliedmodders/metamod-source/" "${{env.MMSOURCE_VERSION}}-dev" "metamod-source" + # But maybe others aren't (also probably unnecessary because git actions but paranoia) git config --global advice.detachedHead true From e3643ff6de8cc326b268bb52bf6f6325c495ce4b Mon Sep 17 00:00:00 2001 From: Ryan Stecker Date: Sun, 3 Mar 2024 17:24:24 -0600 Subject: [PATCH 09/10] Only upload artifacts on pushes. --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7260dba..f86d820 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -107,7 +107,7 @@ jobs: if [ "${sdk}" == "tf2" ]; then shallow_checkout "https://github.com/Kenzzer/hl2sdk" "tf2_win64" "hl2sdk-tf2" else - shallow_checkout "https://github.com/alliedmodders/hl2sdk" "${sdk}" "hl2sdk-${sdk}" + shallow_checkout "https://github.com/alliedmodders/hl2sdk" "${sdk}" "hl2sdk-${sdk}" fi done @@ -158,5 +158,8 @@ jobs: run: zip -r "${{ env.ZIP_FILENAME }}" . - uses: actions/upload-artifact@v4 + name: Upload artifacts + if: github.event_name == 'push' && github.ref == 'refs/heads/action' + working-directory: extension/build/package with: path: "${{ env.ZIP_FILENAME }}" From 49eefcb0a45657377fdbdf55df0a3002b848a7a4 Mon Sep 17 00:00:00 2001 From: Ryan Stecker Date: Sun, 3 Mar 2024 17:26:18 -0600 Subject: [PATCH 10/10] Maybe fix artifact upload. --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f86d820..d339e6a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -160,6 +160,5 @@ jobs: - uses: actions/upload-artifact@v4 name: Upload artifacts if: github.event_name == 'push' && github.ref == 'refs/heads/action' - working-directory: extension/build/package with: - path: "${{ env.ZIP_FILENAME }}" + path: "extension/build/package/${{ env.ZIP_FILENAME }}"