Skip to content
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
44 changes: 44 additions & 0 deletions .github/workflows/build-amxx-dll.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build AMXX DLL (x86)

on:
push:
branches:
- fix-312-metamod-r-abi
workflow_dispatch:

jobs:
build-amxx:
runs-on: windows-2022
env:
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
VCPKG_DEFAULT_TRIPLET: x86-windows-static
VCPKG_DEFAULT_HOST_TRIPLET: x86-windows-static
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: Set up vcpkg
uses: lukka/run-vcpkg@v11
with:
vcpkgJsonGlob: vcpkg.json
vcpkgDirectory: ${{ env.VCPKG_ROOT }}
vcpkgGitCommitId: ef7dbf94b9198bc58f45951adcf1f041fcbc5ea0
runVcpkgInstall: false

- name: Configure and build AMXX DLL
uses: lukka/run-cmake@v10
with:
configurePreset: github-actions
buildPreset: github-actions
buildPresetAdditionalArgs: "['--target', 'bugfixedapi_amxx']"
env:
VCPKG_FORCE_SYSTEM_BINARIES: 1

- name: Upload DLL (and debug symbols if present)
uses: actions/upload-artifact@v4
with:
name: bugfixedapi-amxx-x86
path: _build/github-actions/**/bugfixedapi_amxx.dll
if-no-files-found: error
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -457,4 +457,4 @@ add_custom_target( ci-client )
add_dependencies( ci-client client test_client )

add_custom_target( ci-server )
add_dependencies( ci-server server test_server bugfixedapi_amxx )
add_dependencies( ci-server server test_server bugfixedapi_amxx test_bugfixedapi_enginefuncs_abi )
1 change: 1 addition & 0 deletions src/bugfixedapi_amxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set( SOURCE_FILES

amxxmodule.cpp
amxxmodule.h
enginefuncs_abi.h
moduleconfig.h
IGameConfigs.h
ITextParsers.h
Expand Down
7 changes: 4 additions & 3 deletions src/bugfixedapi_amxx/amxxmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <stdlib.h>
#include <stdio.h>
#include "amxxmodule.h"
#include "enginefuncs_abi.h"

/************* METAMOD SUPPORT *************/
#ifdef USE_METAMOD
Expand Down Expand Up @@ -2137,7 +2138,7 @@ C_DLLEXPORT int GetEngineFunctions(enginefuncs_t *pengfuncsFromEngine, int *inte
*interfaceVersion = ENGINE_INTERFACE_VERSION;
return (FALSE);
}
memcpy(pengfuncsFromEngine, &g_EngineFuncs_Table, sizeof(enginefuncs_t));
metamod_abi::CopyEngineFuncsPrefix(pengfuncsFromEngine, &g_EngineFuncs_Table);
g_pengfuncsTable = pengfuncsFromEngine;
return TRUE;
}
Expand All @@ -2157,7 +2158,7 @@ C_DLLEXPORT int GetEngineFunctions_Post(enginefuncs_t *pengfuncsFromEngine, int
*interfaceVersion = ENGINE_INTERFACE_VERSION;
return (FALSE);
}
memcpy(pengfuncsFromEngine, &g_EngineFuncs_Post_Table, sizeof(enginefuncs_t));
metamod_abi::CopyEngineFuncsPrefix(pengfuncsFromEngine, &g_EngineFuncs_Post_Table);
g_pengfuncsTable_Post = pengfuncsFromEngine;
return TRUE;
}
Expand Down Expand Up @@ -2320,7 +2321,7 @@ C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)

C_DLLEXPORT void WINAPI GiveFnptrsToDll(enginefuncs_t *pengfuncsFromEngine, globalvars_t *pGlobals)
{
memcpy(&g_engfuncs, pengfuncsFromEngine, sizeof(enginefuncs_t));
metamod_abi::InitializeEngineFuncsFromHost(g_engfuncs, pengfuncsFromEngine);
gpGlobals = pGlobals;
}

Expand Down
21 changes: 21 additions & 0 deletions src/bugfixedapi_amxx/enginefuncs_abi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <stddef.h>
#include <string.h>

namespace metamod_abi
{
constexpr size_t EngineFuncsPrefixSize =
offsetof(enginefuncs_t, pfnPEntityOfEntIndexAllEntities);

inline void CopyEngineFuncsPrefix(void *destination, const void *source)
{
memcpy(destination, source, EngineFuncsPrefixSize);
}

inline void InitializeEngineFuncsFromHost(enginefuncs_t &destination, const void *source)
{
destination = {};
CopyEngineFuncsPrefix(&destination, source);
}
}
24 changes: 24 additions & 0 deletions src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ if( BUILD_TESTING )
server/sv_exports.h
)

add_executable( test_bugfixedapi_enginefuncs_abi
bugfixedapi_enginefuncs_abi.cpp
)

target_include_directories( test_bugfixedapi_enginefuncs_abi PRIVATE
${CMAKE_SOURCE_DIR}/src/bugfixedapi_amxx
${GAME_COMMON_INCLUDE_PATHS}
${CMAKE_SOURCE_DIR}/external/metamod/metamod
${SOURCE_SDK_INCLUDE_PATHS}
)

target_compile_definitions( test_bugfixedapi_enginefuncs_abi PRIVATE
${GAME_COMMON_DEFINES}
${SOURCE_SDK_DEFINES}
USE_METAMOD
HAVE_STDINT_H
MATHLIB_USE_C_ASSERT
MATHLIB_VECTOR_NONTRIVIAL
)

#-----------------------------------------------------------------

add_executable( test_client
Expand Down Expand Up @@ -111,6 +131,10 @@ if( BUILD_TESTING )
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/workdir"
)

add_test( NAME server_bugfixedapi_enginefuncs_abi
COMMAND test_bugfixedapi_enginefuncs_abi
)

set_tests_properties( client server PROPERTIES ENVIRONMENT "LD_LIBRARY_PATH=.:$ENV{LD_LIBRARY_PATH}")

endif()
42 changes: 42 additions & 0 deletions src/tests/bugfixedapi_enginefuncs_abi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <string.h>

#include "extdll.h"
#include "enginefuncs_abi.h"

static edict_t *StubEntityOfEntIndex(int)
{
return nullptr;
}

int main()
{
enginefuncs_t source{};
source.pfnPEntityOfEntIndexAllEntities = StubEntityOfEntIndex;

struct GuardedDestination
{
unsigned char table[metamod_abi::EngineFuncsPrefixSize];
unsigned char guard[16];
} guarded;
memset(&guarded, 0xA5, sizeof(guarded));

metamod_abi::CopyEngineFuncsPrefix(guarded.table, &source);
if (memcmp(guarded.table, &source, sizeof(guarded.table)) != 0)
return 1;

for (unsigned char value : guarded.guard)
{
if (value != 0xA5)
return 2;
}

enginefuncs_t imported{};
imported.pfnPEntityOfEntIndexAllEntities = StubEntityOfEntIndex;
metamod_abi::InitializeEngineFuncsFromHost(imported, &source);
if (memcmp(&imported, &source, metamod_abi::EngineFuncsPrefixSize) != 0)
return 3;
if (imported.pfnPEntityOfEntIndexAllEntities != nullptr)
return 4;

return 0;
}