diff --git a/core/metamod.cpp b/core/metamod.cpp index 29288b7..c6c9e5b 100644 --- a/core/metamod.cpp +++ b/core/metamod.cpp @@ -314,6 +314,8 @@ LoadPluginsFromFile(const char *filepath, int &skipped) { #if defined WIN32 || defined _WIN32 ext = ".dll"; +#elif defined __APPLE__ + ext = ".dylib"; #else ext = "_i486.so"; #endif @@ -481,7 +483,7 @@ mm_StartupMetamod(bool is_vsp_load) ConVarFlag_SpOnly); mm_basedir = provider->CreateConVar("mm_basedir", -#if defined __linux__ +#if defined __linux__ || defined __APPLE__ "addons/metamod", #else "addons\\metamod", @@ -1123,6 +1125,8 @@ ProcessVDF(const char *path, bool &skipped) file, #if defined WIN32 || defined _WIN32 ".dll" +#elif defined __APPLE__ + ".dylib" #else "_i486.so" #endif diff --git a/core/metamod.h b/core/metamod.h index 6fc9712..615059b 100644 --- a/core/metamod.h +++ b/core/metamod.h @@ -39,7 +39,7 @@ #include #include #include "metamod_provider.h" -#include "version.h" +#include using namespace SourceMM; diff --git a/core/metamod_console.cpp b/core/metamod_console.cpp index ab35b0b..6771cc4 100644 --- a/core/metamod_console.cpp +++ b/core/metamod_console.cpp @@ -425,6 +425,8 @@ bool Command_Meta(IMetamodSourceCommandInfo *info) const char *ext = UTIL_GetExtension(file); #if defined WIN32 || defined _WIN32 ext = ext ? "" : ".dll"; +#elif defined __APPLE__ + ext = ext ? "" : ".dylib"; #else ext = ext ? "" : "_i486.so"; #endif @@ -547,6 +549,8 @@ bool Command_Meta(IMetamodSourceCommandInfo *info) const char *ext = UTIL_GetExtension(file); #if defined WIN32 || defined _WIN32 ext = ext ? "" : ".dll"; +#elif defined __APPLE__ + ext = ext ? "" : ".dylib"; #else ext = ext ? "" : "_i486.so"; #endif diff --git a/core/metamod_oslink.cpp b/core/metamod_oslink.cpp index 562a7e5..2ec065d 100644 --- a/core/metamod_oslink.cpp +++ b/core/metamod_oslink.cpp @@ -27,9 +27,9 @@ #include #include "metamod_oslink.h" -#include +#include #include -#ifdef __linux +#if defined __linux__ || defined __APPLE__ #include #endif @@ -57,7 +57,7 @@ const char *dlerror() } #endif -#if defined __linux__ +#if defined __linux_ || defined __APPLE___ int GetLastError() { return errno; @@ -82,7 +82,7 @@ bool GetFileOfAddress(void *pAddr, char *buffer, size_t maxlength) return false; HMODULE dll = (HMODULE)mem.AllocationBase; GetModuleFileName(dll, (LPTSTR)buffer, maxlength); -#elif defined __linux__ +#elif defined __linux__ || defined __APPLE__ Dl_info info; if (!dladdr(pAddr, &info)) return false; diff --git a/core/metamod_oslink.h b/core/metamod_oslink.h index eb1b11a..f38eda3 100644 --- a/core/metamod_oslink.h +++ b/core/metamod_oslink.h @@ -51,11 +51,15 @@ #define PATH_SEP_CHAR '\\' #define ALT_SEP_CHAR '/' #define PATH_SIZE MAX_PATH - #define SERVER_DLL "server.dll" #define strcasecmp stricmp inline bool _IsPathSepChar(char c) { return (c == '/' || c == '\\'); } -#elif defined __linux__ - #define OS_LINUX +#elif defined __linux__ || defined __APPLE__ + #if defined __linux__ + #define OS_LINUX + #elif defined __APPLE__ + #define OS_DARWIN + #include + #endif #include #include #include @@ -69,11 +73,10 @@ #define PATH_SIZE PATH_MAX #define stricmp strcasecmp #define strnicmp strncasecmp - #define SERVER_DLL "server_i486.so" inline bool _IsPathSepChar(char c) { return (c == '/'); } #endif -#if defined __linux__ +#if defined __linux__ || defined __APPLE__ #include int GetLastError(); #endif @@ -103,7 +106,7 @@ bool GetFileOfAddress(void *pAddr, char *buffer, size_t maxlength); #endif #endif -#ifndef __linux__ +#if !defined __linux__ && !defined __APPLE__ #define snprintf _snprintf #if defined _MSC_VER && _MSC_VER < 1500 #define vsnprintf _vsnprintf diff --git a/core/metamod_util.cpp b/core/metamod_util.cpp index 6d6bfea..cd9575a 100644 --- a/core/metamod_util.cpp +++ b/core/metamod_util.cpp @@ -197,7 +197,7 @@ inline bool pathchar_sep(char a) { #if defined WIN32 return (a == '/' || a == '\\'); -#elif defined __linux__ +#else return (a == '/'); #endif } @@ -208,7 +208,7 @@ inline bool pathstr_isabsolute(const char *str) return (pathchar_isalpha(str[0]) && str[1] == ':' && pathchar_sep(str[2])); -#elif defined __linux__ +#else return (str[0] == '/'); #endif } diff --git a/loader/gamedll.cpp b/loader/gamedll.cpp index 35a2c2c..15c9460 100644 --- a/loader/gamedll.cpp +++ b/loader/gamedll.cpp @@ -54,6 +54,8 @@ static char mm_path[PLATFORM_MAX_PATH]; #if defined _WIN32 #define SERVER_NAME "server.dll" +#elif defined __APPLE__ +#define SERVER_NAME "server.dylib" #elif defined __linux__ #define SERVER_NAME "server" LIB_SUFFIX #endif diff --git a/loader/loader.cpp b/loader/loader.cpp index 6cbe809..c6ef8f0 100644 --- a/loader/loader.cpp +++ b/loader/loader.cpp @@ -81,6 +81,9 @@ static const char *backend_names[] = #if defined _WIN32 #define LIBRARY_EXT ".dll" #define LIBRARY_MINEXT ".dll" +#elif defined __APPLE__ +#define LIBRARY_EXT ".dylib" +#define LIBRARY_MINEXT ".dylib" #elif defined __linux__ #define LIBRARY_EXT LIB_SUFFIX #define LIBRARY_MINEXT ".so" @@ -179,6 +182,9 @@ mm_GetProcAddress(const char *name) #if defined _WIN32 #define TIER0_NAME "bin\\tier0.dll" #define VSTDLIB_NAME "bin\\vstdlib.dll" +#elif defined __APPLE__ +#define TIER0_NAME "bin/libtier0.dylib" +#define VSTDLIB_NAME "bin/libvstdlib.dylib" #elif defined __linux__ #define TIER0_NAME "bin/" LIB_PREFIX "tier0" LIB_SUFFIX #define VSTDLIB_NAME "bin/" LIB_PREFIX "vstdlib" LIB_SUFFIX diff --git a/loader/loader.h b/loader/loader.h index 0df31ad..ca95a70 100644 --- a/loader/loader.h +++ b/loader/loader.h @@ -40,26 +40,33 @@ #define SH_COMP_MSVC 2 #if defined WIN32 +#define SH_SYS SH_SYS_WIN32 +#define SH_XP SH_XP_WINAPI +#define SH_COMP SH_COMP_MSVC #define WINDOWS_LEAN_AND_MEAN #include #include #define PLATFORM_MAX_PATH MAX_PATH -#define SH_SYS SH_SYS_WIN32 -#define SH_XP SH_XP_WINAPI -#define SH_COMP SH_COMP_MSVC #define PATH_SEP_STR "\\" #define PATH_SEP_CHAR '\\' #define ALT_SEP_CHAR '/' -#elif defined __linux__ +#elif defined __linux__ || defined __APPLE__ +#if defined __linux__ +#define SH_SYS SH_SYS_LINUX +#elif defined __APPLE__ +#define SH_SYS SH_SYS_APPLE +#endif +#define SH_XP SH_XP_POSIX +#define SH_COMP SH_COMP_GCC #include #include #include #include +#if SH_SYS == SH_SYS_APPLE +#include +#endif typedef void * HMODULE; #define PLATFORM_MAX_PATH PATH_MAX -#define SH_SYS SH_SYS_LINUX -#define SH_XP SH_XP_POSIX -#define SH_COMP SH_COMP_GCC #define PATH_SEP_STR "/" #define PATH_SEP_CHAR '/' #define ALT_SEP_CHAR '\\' diff --git a/loader/utility.cpp b/loader/utility.cpp index f551031..1d2a2a0 100644 --- a/loader/utility.cpp +++ b/loader/utility.cpp @@ -270,7 +270,7 @@ mm_ResolvePath(const char *path, char *buffer, size_t maxlength) { #if defined _WIN32 return _fullpath(buffer, path, maxlength) != NULL; -#elif defined __linux__ +#elif defined __linux__ || defined __APPLE__ assert(maxlength >= PATH_MAX); return realpath(path, buffer) != NULL; #endif @@ -289,7 +289,7 @@ mm_LoadLibrary(const char *path, char *buffer, size_t maxlength) mm_GetPlatformError(buffer, maxlength); return NULL; } -#elif defined __linux__ +#elif defined __linux__ || defined __APPLE__ lib = dlopen(path, RTLD_NOW); if (lib == NULL) @@ -307,7 +307,7 @@ mm_GetLibAddress(void *lib, const char *name) { #if defined _WIN32 return GetProcAddress((HMODULE)lib, name); -#elif defined __linux__ +#elif defined __linux__ || defined __APPLE__ return dlsym(lib, name); #endif } @@ -317,7 +317,7 @@ mm_UnloadLibrary(void *lib) { #if defined _WIN32 FreeLibrary((HMODULE)lib); -#else +#elif defined __linux__ || defined __APPLE__ dlclose(lib); #endif } @@ -333,7 +333,7 @@ mm_GetFileOfAddress(void *pAddr, char *buffer, size_t maxlength) return false; HMODULE dll = (HMODULE)mem.AllocationBase; GetModuleFileName(dll, (LPTSTR)buffer, maxlength); -#elif defined __linux__ +#elif defined __linux__ || defined __APPLE__ Dl_info info; if (!dladdr(pAddr, &info)) return false;