diff --git a/metamod/extra/example/Makefile b/metamod/extra/example/Makefile new file mode 100644 index 0000000..03baa29 --- /dev/null +++ b/metamod/extra/example/Makefile @@ -0,0 +1,45 @@ +HLSDK = include/hlsdk +METAMOD = include/metamod + +NAME = example_plugin + +COMPILER = g++ + +OBJECTS = *.cpp + +LINK = + +OPT_FLAGS = -O3 -msse3 -flto -funroll-loops -fomit-frame-pointer -fno-stack-protector + +INCLUDE = -I. -I$(HLSDK)/common -I$(HLSDK)/dlls -I$(HLSDK)/engine \ + -I$(HLSDK)/game_shared -I$(HLSDK)/pm_shared -I$(HLSDK)/public -I$(METAMOD) + +BIN_DIR = Release +CFLAGS = $(OPT_FLAGS) + +CFLAGS += -g -DNDEBUG -Dlinux -D__linux__ -D__USE_GNU -std=gnu++11 -shared + +OBJ_LINUX := $(OBJECTS:%.c=$(BIN_DIR)/%.o) + +$(BIN_DIR)/%.o: %.c + $(COMPILER) $(INCLUDE) $(CFLAGS) -o $@ -c $< + +all: + mkdir -p $(BIN_DIR) + + $(MAKE) $(NAME) && strip -x $(BIN_DIR)/$(NAME)_mm_i386.so + +$(NAME): $(OBJ_LINUX) + $(COMPILER) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -o$(BIN_DIR)/$(NAME)_mm_i386.so + +check: + cppcheck $(INCLUDE) --quiet --max-configs=100 -D__linux__ -DNDEBUG . + +debug: + $(MAKE) all DEBUG=false + +default: all + +clean: + rm -rf Release/*.o + rm -rf Release/$(NAME)_mm_i386.so \ No newline at end of file diff --git a/metamod/extra/example/dllapi.cpp b/metamod/extra/example/dllapi.cpp index f627ee0..3376810 100644 --- a/metamod/extra/example/dllapi.cpp +++ b/metamod/extra/example/dllapi.cpp @@ -129,14 +129,12 @@ NEW_DLL_FUNCTIONS g_NewDllFunctionTable_Post = C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion) { - if (!pFunctionTable) - { - ALERT(at_logged, __FUNCTION__ " called with null pFunctionTable"); + if (!pFunctionTable) { + ALERT(at_logged, "%s called with null pFunctionTable", __FUNCTION__); return FALSE; } - if (*interfaceVersion != INTERFACE_VERSION) - { - ALERT(at_logged, __FUNCTION__ " version mismatch; requested=%d ours=%d", *interfaceVersion, INTERFACE_VERSION); + if (*interfaceVersion != INTERFACE_VERSION) { + ALERT(at_logged, "%s version mismatch; requested=%d ours=%d", __FUNCTION__, *interfaceVersion, INTERFACE_VERSION); *interfaceVersion = INTERFACE_VERSION; return FALSE; } @@ -147,14 +145,12 @@ C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersi C_DLLEXPORT int GetEntityAPI2_Post(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion) { - if (!pFunctionTable) - { - ALERT(at_logged, __FUNCTION__ " called with null pFunctionTable"); + if (!pFunctionTable) { + ALERT(at_logged, "%s called with null pFunctionTable", __FUNCTION__); return FALSE; } - if (*interfaceVersion != INTERFACE_VERSION) - { - ALERT(at_logged, __FUNCTION__ " version mismatch; requested=%d ours=%d", *interfaceVersion, INTERFACE_VERSION); + if (*interfaceVersion != INTERFACE_VERSION) { + ALERT(at_logged, "%s version mismatch; requested=%d ours=%d", __FUNCTION__, *interfaceVersion, INTERFACE_VERSION); *interfaceVersion = INTERFACE_VERSION; return FALSE; } @@ -165,14 +161,12 @@ C_DLLEXPORT int GetEntityAPI2_Post(DLL_FUNCTIONS *pFunctionTable, int *interface C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *interfaceVersion) { - if (!pNewFunctionTable) - { - ALERT(at_logged, __FUNCTION__ " called with null pNewFunctionTable"); + if (!pNewFunctionTable) { + ALERT(at_logged, "%s called with null pNewFunctionTable", __FUNCTION__); return FALSE; } - if (*interfaceVersion != NEW_DLL_FUNCTIONS_VERSION) - { - ALERT(at_logged, __FUNCTION__ " version mismatch; requested=%d ours=%d", *interfaceVersion, NEW_DLL_FUNCTIONS_VERSION); + if (*interfaceVersion != NEW_DLL_FUNCTIONS_VERSION) { + ALERT(at_logged, "%s version mismatch; requested=%d ours=%d", __FUNCTION__, *interfaceVersion, NEW_DLL_FUNCTIONS_VERSION); *interfaceVersion = NEW_DLL_FUNCTIONS_VERSION; return FALSE; } @@ -183,14 +177,12 @@ C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *in C_DLLEXPORT int GetNewDLLFunctions_Post(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *interfaceVersion) { - if (!pNewFunctionTable) - { - ALERT(at_logged, __FUNCTION__ " called with null pNewFunctionTable"); + if (!pNewFunctionTable) { + ALERT(at_logged, "%s called with null pNewFunctionTable", __FUNCTION__); return FALSE; } - if (*interfaceVersion != NEW_DLL_FUNCTIONS_VERSION) - { - ALERT(at_logged, __FUNCTION__ " version mismatch; requested=%d ours=%d", *interfaceVersion, NEW_DLL_FUNCTIONS_VERSION); + if (*interfaceVersion != NEW_DLL_FUNCTIONS_VERSION) { + ALERT(at_logged, "%s version mismatch; requested=%d ours=%d", __FUNCTION__, *interfaceVersion, NEW_DLL_FUNCTIONS_VERSION); *interfaceVersion = NEW_DLL_FUNCTIONS_VERSION; return FALSE; } diff --git a/metamod/extra/example/engine_api.cpp b/metamod/extra/example/engine_api.cpp index bbff912..92c4c94 100644 --- a/metamod/extra/example/engine_api.cpp +++ b/metamod/extra/example/engine_api.cpp @@ -348,11 +348,11 @@ enginefuncs_t g_EngineFunctionsTable_Post = C_DLLEXPORT int GetEngineFunctions(enginefuncs_t *pengfuncsFromEngine, int *interfaceVersion) { if (!pengfuncsFromEngine) { - ALERT(at_logged, __FUNCTION__ " called with null pengfuncsFromEngine"); + ALERT(at_logged, "%s called with null pengfuncsFromEngine", __FUNCTION__); return FALSE; } if (*interfaceVersion != ENGINE_INTERFACE_VERSION) { - ALERT(at_logged, __FUNCTION__ " version mismatch; requested=%d ours=%d", *interfaceVersion, ENGINE_INTERFACE_VERSION); + ALERT(at_logged, "%s version mismatch; requested=%d ours=%d", __FUNCTION__, *interfaceVersion, ENGINE_INTERFACE_VERSION); *interfaceVersion = ENGINE_INTERFACE_VERSION; return FALSE; } @@ -363,14 +363,12 @@ C_DLLEXPORT int GetEngineFunctions(enginefuncs_t *pengfuncsFromEngine, int *inte C_DLLEXPORT int GetEngineFunctions_Post(enginefuncs_t *pengfuncsFromEngine, int *interfaceVersion) { - if (!pengfuncsFromEngine) - { - ALERT(at_logged, __FUNCTION__ " called with null pengfuncsFromEngine"); + if (!pengfuncsFromEngine) { + ALERT(at_logged, "%s called with null pengfuncsFromEngine", __FUNCTION__); return FALSE; } - if (*interfaceVersion != ENGINE_INTERFACE_VERSION) - { - ALERT(at_logged, __FUNCTION__ " version mismatch; requested=%d ours=%d", *interfaceVersion, ENGINE_INTERFACE_VERSION); + if (*interfaceVersion != ENGINE_INTERFACE_VERSION) { + ALERT(at_logged, "%s version mismatch; requested=%d ours=%d", __FUNCTION__, *interfaceVersion, ENGINE_INTERFACE_VERSION); *interfaceVersion = ENGINE_INTERFACE_VERSION; return FALSE; } diff --git a/metamod/extra/example/ex_rehlds_api.h b/metamod/extra/example/ex_rehlds_api.h index 47e9f6e..3555e56 100644 --- a/metamod/extra/example/ex_rehlds_api.h +++ b/metamod/extra/example/ex_rehlds_api.h @@ -1,5 +1,9 @@ #pragma once +#ifdef __GNUC__ +enum class sv_delta_s; +#endif + #include extern IRehldsApi* g_RehldsApi; diff --git a/metamod/extra/example/meta_api.cpp b/metamod/extra/example/meta_api.cpp index 0d8de23..70757c1 100644 --- a/metamod/extra/example/meta_api.cpp +++ b/metamod/extra/example/meta_api.cpp @@ -43,7 +43,7 @@ C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, m gpMetaGlobals = pMGlobals; gpGamedllFuncs = pGamedllFuncs; - g_engfuncs.pfnServerPrint("\n###############\n# Hello World! #\n###############\n\n"); + g_engfuncs.pfnServerPrint("\n################\n# Hello World! #\n################\n\n"); memcpy(pFunctionTable, &gMetaFunctionTable, sizeof(META_FUNCTIONS)); return TRUE; diff --git a/metamod/extra/example/public_amalgamation.cpp b/metamod/extra/example/public_amalgamation.cpp index 25d5daf..13a3e02 100644 --- a/metamod/extra/example/public_amalgamation.cpp +++ b/metamod/extra/example/public_amalgamation.cpp @@ -2,4 +2,4 @@ #include #include "sys_shared.cpp" #include "interface.cpp" -#include "crc32c.cpp" + diff --git a/metamod/src/dllapi.cpp b/metamod/src/dllapi.cpp index b7c0ed1..ad3ac05 100644 --- a/metamod/src/dllapi.cpp +++ b/metamod/src/dllapi.cpp @@ -12,7 +12,7 @@ NEW_DLL_FUNCTIONS sNewFunctionTable; NEW_DLL_FUNCTIONS sNewFunctionTable_jit; NEW_DLL_FUNCTIONS *pHookedNewDllFunctions = &sNewFunctionTable; -void MM_PRE_HOOK EXT_FUNC mm_ClientConnect(edict_t *pEntity, const char *, const char *, char [128]) +void MM_PRE_HOOK EXT_FUNC mm_ClientConnect(edict_t *pEntity, const char *, const char *, char[128]) { g_players.clear_player_cvar_query(pEntity); } diff --git a/metamod/src/dllapi.h b/metamod/src/dllapi.h index 8b1d856..b3effdd 100644 --- a/metamod/src/dllapi.h +++ b/metamod/src/dllapi.h @@ -14,6 +14,10 @@ #define C_DLLEXPORT extern "C" DLLEXPORT #endif +#ifndef _WIN32 +#define WINAPI +#endif + typedef void (*FN_GAMEINIT)(); // Typedefs for these are provided in SDK engine/eiface.h, but I didn't