Skip to content

Make safetyhook a shared library #2308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ jobs:

# Setup Python for AMBuild
- uses: actions/setup-python@v5
name: Setup Python 3.8
name: Setup Python 3.9
with:
python-version: 3.8
python-version: 3.9
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
Expand Down
5 changes: 4 additions & 1 deletion AMBuildScript
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,10 @@ class SMConfig(object):

for task in self.libsafetyhook:
if task.target.arch == binary.compiler.target.arch:
binary.compiler.linkflags += [task.binary]
if task.target.platform == 'windows':
binary.compiler.linkflags += [task.binary.path.removesuffix('.dll') + '.lib']
else:
binary.compiler.linkflags += [task.binary]
return
raise Exception('No suitable build of safetyhook was found.')

Expand Down
14 changes: 13 additions & 1 deletion core/logic_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,26 @@ void CoreProviderImpl::InitializeBridge()
bool CoreProviderImpl::LoadBridge(char *error, size_t maxlength)
{
char file[PLATFORM_MAX_PATH];
char myerror[255];

/* Load safetyhook first. The core & extensions might depend on it */
g_SMAPI->PathFormat(file,
sizeof(file),
"%s/bin/" PLATFORM_ARCH_FOLDER "safetyhook." PLATFORM_LIB_EXT,
g_SourceMod.GetSourceModPath());

safetyhook_ = ke::SharedLib::Open(file, myerror, sizeof(myerror));
if (!safetyhook_) {
ke::SafeSprintf(error, maxlength, "failed to load %s: %s", file, myerror);
return false;
}

/* Now it's time to load the logic binary */
g_SMAPI->PathFormat(file,
sizeof(file),
"%s/bin/" PLATFORM_ARCH_FOLDER "sourcemod.logic." PLATFORM_LIB_EXT,
g_SourceMod.GetSourceModPath());

char myerror[255];
logic_ = ke::SharedLib::Open(file, myerror, sizeof(myerror));
if (!logic_) {
ke::SafeSprintf(error, maxlength, "failed to load %s: %s", file, myerror);
Expand Down
1 change: 1 addition & 0 deletions core/provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class CoreProviderImpl : public CoreProvider
}

private:
ke::RefPtr<ke::SharedLib> safetyhook_;
ke::RefPtr<ke::SharedLib> logic_;
LogicInitFunction logic_init_;
GameHooks hooks_;
Expand Down
1 change: 0 additions & 1 deletion extensions/dhooks/DynamicHooks/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#else
#include <macro-assembler-x86.h>
#include <jit/jit_helpers.h>
#include <CDetour/detourhelpers.h>
using namespace sp;
#endif

Expand Down
147 changes: 0 additions & 147 deletions public/CDetour/detourhelpers.h

This file was deleted.

1 change: 1 addition & 0 deletions public/CDetour/detours.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#ifndef _INCLUDE_SOURCEMOD_DETOURS_H_
#define _INCLUDE_SOURCEMOD_DETOURS_H_

#define SAFETYHOOK_SHARED_LIB true
#include "safetyhook.hpp"
#include <smsdk_ext.h>

Expand Down
7 changes: 7 additions & 0 deletions tools/buildbot/PackageScript
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ helpers = SM.package_helpers
helpers.builder = builder
folder_map = helpers.CreateFolders(folder_list)

# Copy safetyhook
for cxx_task in SM.libsafetyhook:
if cxx_task.target.arch == 'x86_64' in cxx_task.binary.path:
builder.AddCopy(cxx_task.binary, folder_map['addons/sourcemod/bin/x64'])
else:
builder.AddCopy(cxx_task.binary, folder_map['addons/sourcemod/bin'])

# Copy binaries.
for cxx_task in SM.binaries:
# mms expects our loader (sourcemod_mm) to exist in /bin/
Expand Down
Loading