Added support for Mac OS X and building with clang (bug 5601, r=dvander).

This commit is contained in:
Scott Ehlert 2013-02-13 01:14:37 -06:00
parent b0fe6c83e2
commit 40c1fee55a
191 changed files with 3835 additions and 1946 deletions

View File

@ -153,7 +153,7 @@ void CmdMngr::setCmdLink(CmdLink** a, Command* c, bool sorted)
{ {
int i = strcmp(c->getCommand(), (*a)->cmd->getCommand()); int i = strcmp(c->getCommand(), (*a)->cmd->getCommand());
if ((i < 0) || (i == 0) && (strcmp(c->getArgument(), (*a)->cmd->getArgument()) < 0)) if ((i < 0) || ((i == 0) && (strcmp(c->getArgument(), (*a)->cmd->getArgument()) < 0)))
break; break;
a = &(*a)->next; a = &(*a)->next;

View File

@ -144,7 +144,6 @@ public:
class CSPForward class CSPForward
{ {
friend class CForwardMngr; friend class CForwardMngr;
const char *m_FuncName;
int m_NumParams; int m_NumParams;
ForwardParam m_ParamTypes[FORWARD_MAX_PARAMS]; ForwardParam m_ParamTypes[FORWARD_MAX_PARAMS];

View File

@ -35,7 +35,7 @@
#include "format.h" #include "format.h"
#include "amxmod_compat.h" #include "amxmod_compat.h"
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
#define _snprintf snprintf #define _snprintf snprintf
#endif #endif
@ -108,7 +108,7 @@ size_t CLangMngr::strip(char *str, char *newstr, bool makelower)
int flag = 0; int flag = 0;
size_t strln = strlen(str); size_t strln = strlen(str);
for (i = strln - 1; i >= 0; i--) for (i = strln - 1; i < strln; i--)
{ {
if (str[i] == '\n' || str[i] == ' ' || str[i] == '\t') if (str[i] == '\n' || str[i] == ' ' || str[i] == '\t')
{ {

View File

@ -111,7 +111,7 @@ void LogEventsMngr::CLogEvent::registerFilter(char* filter)
filters = new LogCond(cmp->pos, aa, filters); filters = new LogCond(cmp->pos, aa, filters);
} }
void LogEventsMngr::setLogString(char* frmt, va_list& vaptr) void LogEventsMngr::setLogString(const char* frmt, va_list& vaptr)
{ {
++logCounter; ++logCounter;
int len = vsnprintf(logString, 255, frmt, vaptr); int len = vsnprintf(logString, 255, frmt, vaptr);
@ -128,7 +128,7 @@ void LogEventsMngr::setLogString(char* frmt, va_list& vaptr)
logArgc = 0; logArgc = 0;
} }
void LogEventsMngr::setLogString(char* frmt, ...) void LogEventsMngr::setLogString(const char* frmt, ...)
{ {
++logCounter; ++logCounter;
va_list logArgPtr; va_list logArgPtr;

View File

@ -141,8 +141,8 @@ public:
CLogEvent* registerLogEvent(CPluginMngr::CPlugin* plugin, int func, int pos); CLogEvent* registerLogEvent(CPluginMngr::CPlugin* plugin, int func, int pos);
inline bool logEventsExist() { return arelogevents; } inline bool logEventsExist() { return arelogevents; }
void setLogString(char* frmt, va_list& vaptr); void setLogString(const char* frmt, va_list& vaptr);
void setLogString(char* frmt, ...); void setLogString(const char* frmt, ...);
void parseLogString(); void parseLogString();
void executeLogEvents(); void executeLogEvents();

View File

@ -342,7 +342,7 @@ public:
} }
} }
m_AuthData[sizeof(m_AuthData)-1]=0; m_AuthData[arraysize(m_AuthData)-1]=0;
}; };
const cell *GetAuthID(void) const const cell *GetAuthID(void) const
@ -361,7 +361,7 @@ public:
} }
} }
m_Password[sizeof(m_Password)-1]=0; m_Password[arraysize(m_Password)-1]=0;
}; };
const cell *GetPass(void) const const cell *GetPass(void) const

View File

@ -220,7 +220,7 @@ bool CModule::queryModule()
m_Handle = DLLOAD(m_Filename.c_str()); // load file m_Handle = DLLOAD(m_Filename.c_str()); // load file
if (!m_Handle) if (!m_Handle)
{ {
#if defined __linux__ #if defined(__linux__) || defined(__APPLE__)
AMXXLOG_Log("[AMXX] Module \"%s\" failed to load (%s)", m_Filename.c_str(), dlerror()); AMXXLOG_Log("[AMXX] Module \"%s\" failed to load (%s)", m_Filename.c_str(), dlerror());
#endif #endif
m_Status = MODULE_BADLOAD; m_Status = MODULE_BADLOAD;

View File

@ -244,7 +244,7 @@ public:
if (is_space(v[len-1])) if (is_space(v[len-1]))
{ {
for (i=len-1; i>=0; i--) for (i=len-1; i<len; i--)
{ {
if (!is_space(v[i]) if (!is_space(v[i])
|| (is_space(v[i]) && i==0)) || (is_space(v[i]) && i==0))

View File

@ -1,18 +1,18 @@
#(C)2004-2005 AMX Mod X Development Team # (C)2004-2013 AMX Mod X Development Team
# Makefile written by David "BAILOPAN" Anderson # Makefile written by David "BAILOPAN" Anderson
HLSDK = ../../hlsdk ###########################################
### EDIT THESE PATHS FOR YOUR OWN SETUP ###
###########################################
HLSDK = ../../hlsdk/multiplayer
MM_ROOT = ../../metamod/metamod MM_ROOT = ../../metamod/metamod
#####################################
### EDIT BELOW FOR OTHER PROJECTS ### ### EDIT BELOW FOR OTHER PROJECTS ###
#####################################
OPT_FLAGS = -O2 -fno-strict-aliasing -funroll-loops -s -fomit-frame-pointer -pipe -DNDEBUG PROJECT = amxmodx
DEBUG_FLAGS = -g -ggdb3
CPP = gcc-4.1
NAME = amxmodx
BIN_SUFFIX_32 = mm_i386.so
BIN_SUFFIX_64 = mm_amd64.so
OBJECTS = meta_api.cpp CFile.cpp CVault.cpp vault.cpp float.cpp file.cpp modules.cpp \ OBJECTS = meta_api.cpp CFile.cpp CVault.cpp vault.cpp float.cpp file.cpp modules.cpp \
CMisc.cpp CTask.cpp string.cpp amxmodx.cpp CEvent.cpp CCmd.cpp CLogEvent.cpp \ CMisc.cpp CTask.cpp string.cpp amxmodx.cpp CEvent.cpp CCmd.cpp CLogEvent.cpp \
@ -23,98 +23,125 @@ OBJECTS = meta_api.cpp CFile.cpp CVault.cpp vault.cpp float.cpp file.cpp modules
amxmod_compat.cpp nongpl_matches.cpp CFlagManager.cpp datastructs.cpp \ amxmod_compat.cpp nongpl_matches.cpp CFlagManager.cpp datastructs.cpp \
trie_natives.cpp trie_natives.cpp
LINK = -lgcc -static-libgcc ##############################################
### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
##############################################
INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared -I$(HLSDK)/game_shared \ C_OPT_FLAGS = -DNDEBUG -O2 -funroll-loops -fomit-frame-pointer -pipe
-I$(MM_ROOT) -Lzlib -I$(HLSDK)/common C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3
C_GCC4_FLAGS = -fvisibility=hidden
CPP_GCC4_FLAGS = -fvisibility-inlines-hidden
CPP = gcc
CPP_OSX = clang
GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) LINK = -Lzlib
ifeq "$(GCC_VERSION)" "4" INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/common -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared \
OPT_FLAGS += -fvisibility=hidden -fvisibility-inlines-hidden -I$(MM_ROOT)
################################################
### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ###
################################################
OS := $(shell uname -s)
ifeq "$(OS)" "Darwin"
OBJECTS += JIT/amxexecn-darwin.o JIT/amxjitsn-darwin.o JIT/natives-darwin-x86.o \
JIT/helpers-darwin-x86.o
CPP = $(CPP_OSX)
LIB_EXT = dylib
LIB_SUFFIX = _mm
CFLAGS += -DOSX
LINK += -dynamiclib -lstdc++ -mmacosx-version-min=10.5 -Wl,-read_only_relocs,suppress -lz-darwin
else
OBJECTS += JIT/amxexecn.o JIT/amxjitsn.o JIT/natives-x86.o JIT/helpers-x86.o
LIB_EXT = so
LIB_SUFFIX = _mm_i386
CFLAGS += -DLINUX
LINK += -shared -lz
endif endif
LINK += -m32 -lm -ldl
CFLAGS += -DAMX_NOPROPLIST -DPAWN_CELL_SIZE=32 -DJIT -DASM32 -DHAVE_STDINT_H -fno-strict-aliasing \
-m32 -Wall -Werror
CPPFLAGS += -fno-exceptions -fno-rtti
BINARY = $(PROJECT)$(LIB_SUFFIX).$(LIB_EXT)
ifeq "$(DEBUG)" "true" ifeq "$(DEBUG)" "true"
BIN_DIR = Debug BIN_DIR = Debug
CFLAGS = $(DEBUG_FLAGS) CFLAGS += $(C_DEBUG_FLAGS)
else else
BIN_DIR = Release BIN_DIR = Release
CFLAGS = $(OPT_FLAGS) CFLAGS += $(C_OPT_FLAGS)
LINK += -s
endif endif
ifeq "$(BINLOG)" "true" ifeq "$(BINLOG)" "true"
NAME := $(NAME)_bl LIB_SUFFIX := _bl$(LIB_SUFFIX)
BIN_DIR := $(BIN_DIR)BinLog BIN_DIR := $(BIN_DIR)BinLog
OBJECTS += binlog.cpp OBJECTS += binlog.cpp
CFLAGS += -DBINLOG_ENABLED CFLAGS += -DBINLOG_ENABLED
endif endif
CFLAGS += -DLINUX -DAMX_NOPROPLIST -Wall -Werror -DHAVE_STDINT_H -static-libgcc -fno-rtti -fno-exceptions IS_CLANG := $(shell $(CPP) --version | head -1 | grep clang > /dev/null && echo "1" || echo "0")
ifeq "$(AMD64)" "true" ifeq "$(IS_CLANG)" "1"
BINARY = $(NAME)_$(BIN_SUFFIX_64) CPP_MAJOR := $(shell $(CPP) --version | grep clang | sed "s/.*version \([0-9]\)*\.[0-9]*.*/\1/")
CFLAGS += -DPAWN_CELL_SIZE=64 -DHAVE_I64 -DAMD64 -m64 CPP_MINOR := $(shell $(CPP) --version | grep clang | sed "s/.*version [0-9]*\.\([0-9]\)*.*/\1/")
LINK += -lz64
OBJECTS += JIT/natives-amd64.o
else else
BINARY = $(NAME)_$(BIN_SUFFIX_32) CPP_MAJOR := $(shell $(CPP) -dumpversion >&1 | cut -b1)
OBJECTS += JIT/amxexecn.o JIT/amxjitsn.o JIT/natives-x86.o CPP_MINOR := $(shell $(CPP) -dumpversion >&1 | cut -b3)
OBJECTS += JIT/helpers-x86.o
CFLAGS += -DPAWN_CELL_SIZE=32 -DJIT -DASM32
LINK += -lz
OPT_FLAGS += -march=i586
CFLAGS += -m32
endif endif
OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) # Clang || GCC >= 4
ifeq "$(shell expr $(IS_CLANG) \| $(CPP_MAJOR) \>= 4)" "1"
CFLAGS += $(C_GCC4_FLAGS)
CPPFLAGS += $(CPP_GCC4_FLAGS)
endif
# Clang >= 3 || GCC >= 4.7
ifeq "$(shell expr $(IS_CLANG) \& $(CPP_MAJOR) \>= 3 \| $(CPP_MAJOR) \>= 4 \& $(CPP_MINOR) \>= 7)" "1"
CFLAGS += -Wno-delete-non-virtual-dtor
endif
# OS is Linux and not using clang
ifeq "$(shell expr $(OS) \= Linux \& $(IS_CLANG) \= 0)" "1"
LINK += -static-libgcc
endif
OBJ_BIN := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o)
# This will break if we include other Makefiles, but is fine for now. It allows
# us to make a copy of this file that uses altered paths (ie. Makefile.mine)
# or other changes without mucking up the original.
MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
$(BIN_DIR)/%.o: %.cpp $(BIN_DIR)/%.o: %.cpp
$(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $< $(CPP) $(INCLUDE) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
all: all:
mkdir -p $(BIN_DIR) mkdir -p $(BIN_DIR)
$(MAKE) amxmodx $(MAKE) -f $(MAKEFILE_NAME) $(PROJECT)
amd64:
rm -f zlib/libz.a
$(MAKE) all AMD64=true
amd64_debug:
rm -f zlib/libz.a
$(MAKE) all AMD64=true DEBUG=true
amd64_binlog:
rm -f zlib/libz.a
$(MAKE) all AMD64=true BINLOG=true
amd64_binlog_debug:
rm -f zlib/libz.a
$(MAKE) all AMD64=true BINLOG=true DEBUG=true
binlog: binlog:
$(MAKE) all BINLOG=true $(MAKE) -f $(MAKEFILE_NAME) all BINLOG=true
binlog_debug: binlog_debug:
$(MAKE) all BINLOG=true DEBUG=true $(MAKE) -f $(MAKEFILE_NAME) all BINLOG=true DEBUG=true
amxmodx: $(OBJ_LINUX) $(PROJECT): $(OBJ_BIN)
$(CPP) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) $(CPP) $(INCLUDE) $(OBJ_BIN) $(LINK) -o $(BIN_DIR)/$(BINARY)
debug: debug:
$(MAKE) all DEBUG=true $(MAKE) -f $(MAKEFILE_NAME) all DEBUG=true
default: all default: all
clean: clean:
rm -rf Release/*.o rm -rf $(BIN_DIR)/*.o
rm -rf Release/$(NAME)_$(BIN_SUFFIX_32) rm -f $(BIN_DIR)/$(BINARY)
rm -rf Release/$(NAME)_$(BIN_SUFFIX_64)
rm -rf ReleaseBinLog/*.o
rm -rf ReleaseBinLog/$(NAME)_bl_$(BIN_SUFFIX_32)
rm -rf ReleaseBinLog/$(NAME)_bl_$(BIN_SUFFIX_64)
rm -rf Debug/*.o
rm -rf Debug/$(NAME)_$(BIN_SUFFIX_32)
rm -rf Debug/$(NAME)_$(BIN_SUFFIX_64)
rm -rf DebugBinLog/*.o
rm -rf DebugBinLog/$(NAME)_bl_$(BIN_SUFFIX_32)
rm -rf DebugBinLog/$(NAME)_bl_$(BIN_SUFFIX_64)

View File

@ -48,7 +48,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include "osdefs.h" #include "osdefs.h"
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#include <sclinux.h> #include <sclinux.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
@ -436,7 +436,7 @@ int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, cell *params)
hdr=(AMX_HEADER *)amx->base; hdr=(AMX_HEADER *)amx->base;
assert(hdr->natives<=hdr->libraries); assert(hdr->natives<=hdr->libraries);
#if defined AMX_NATIVETABLE #if defined AMX_NATIVETABLE
if (index<NULL) { if (index<0) {
assert(-(index+1)<(sizeof(AMX_NATIVETABLE)/sizeof(AMX_NATIVETABLE)[0])); assert(-(index+1)<(sizeof(AMX_NATIVETABLE)/sizeof(AMX_NATIVETABLE)[0]));
f=(AMX_NATIVETABLE)[-(index+1)]; f=(AMX_NATIVETABLE)[-(index+1)];
} else { } else {
@ -932,7 +932,7 @@ int AMXAPI amx_Init(AMX *amx, void *program)
#define ALIGN(addr) (addr) #define ALIGN(addr) (addr)
#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
/* Linux already has mprotect() */ /* Linux already has mprotect() */
/* But wants the address aligned! */ /* But wants the address aligned! */
@ -1014,10 +1014,10 @@ int AMXAPI amx_InitJIT(AMX *amx,void *compiled_program,void *reloc_table)
#if defined AMX_CLEANUP #if defined AMX_CLEANUP
int AMXAPI amx_Cleanup(AMX *amx) int AMXAPI amx_Cleanup(AMX *amx)
{ {
#if (defined _Windows || defined LINUX || defined __FreeBSD__ || defined __OpenBSD__) && !defined AMX_NODYNALOAD #if (defined _Windows || defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__) && !defined AMX_NODYNALOAD
#if defined _Windows #if defined _Windows
typedef int (FAR WINAPI *AMX_ENTRY)(AMX FAR *amx); typedef int (FAR WINAPI *AMX_ENTRY)(AMX FAR *amx);
#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
typedef int (*AMX_ENTRY)(AMX *amx); typedef int (*AMX_ENTRY)(AMX *amx);
#endif #endif
AMX_HEADER *hdr; AMX_HEADER *hdr;
@ -1027,7 +1027,7 @@ int AMXAPI amx_Cleanup(AMX *amx)
#endif #endif
/* unload all extension modules */ /* unload all extension modules */
#if (defined _Windows || defined LINUX || defined __FreeBSD__ || defined __OpenBSD__) && !defined AMX_NODYNALOAD #if (defined _Windows || defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__) && !defined AMX_NODYNALOAD
hdr=(AMX_HEADER *)amx->base; hdr=(AMX_HEADER *)amx->base;
assert(hdr->magic==AMX_MAGIC); assert(hdr->magic==AMX_MAGIC);
numlibraries=NUMENTRIES(hdr,libraries,pubvars); numlibraries=NUMENTRIES(hdr,libraries,pubvars);
@ -1040,14 +1040,14 @@ int AMXAPI amx_Cleanup(AMX *amx)
strcat(funcname,"Cleanup"); strcat(funcname,"Cleanup");
#if defined _Windows #if defined _Windows
libcleanup=(AMX_ENTRY)GetProcAddress((HINSTANCE)lib->address,funcname); libcleanup=(AMX_ENTRY)GetProcAddress((HINSTANCE)lib->address,funcname);
#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
libcleanup=(AMX_ENTRY)dlsym((void*)lib->address,funcname); libcleanup=(AMX_ENTRY)dlsym((void*)lib->address,funcname);
#endif #endif
if (libcleanup!=NULL) if (libcleanup!=NULL)
libcleanup(amx); libcleanup(amx);
#if defined _Windows #if defined _Windows
FreeLibrary((HINSTANCE)lib->address); FreeLibrary((HINSTANCE)lib->address);
#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
dlclose((void*)lib->address); dlclose((void*)lib->address);
#endif #endif
} /* if */ } /* if */
@ -3695,7 +3695,7 @@ int AMXAPI amx_GetAddr(AMX *amx,cell amx_addr,cell **phys_addr)
data=(amx->data!=NULL) ? amx->data : amx->base+(int)hdr->dat; data=(amx->data!=NULL) ? amx->data : amx->base+(int)hdr->dat;
assert(phys_addr!=NULL); assert(phys_addr!=NULL);
if (amx_addr>=amx->hea && amx_addr<amx->stk || amx_addr<0 || amx_addr>=amx->stp) { if ((amx_addr>=amx->hea && amx_addr<amx->stk) || amx_addr<0 || amx_addr>=amx->stp) {
*phys_addr=NULL; *phys_addr=NULL;
return AMX_ERR_MEMACCESS; return AMX_ERR_MEMACCESS;
} /* if */ } /* if */
@ -4094,7 +4094,7 @@ int AMXAPI amx_GetLibraries(AMX *amx)
return numLibraries; return numLibraries;
} }
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
#define _snprintf snprintf #define _snprintf snprintf
#endif #endif

View File

@ -24,7 +24,7 @@
#if defined FREEBSD && !defined __FreeBSD__ #if defined FREEBSD && !defined __FreeBSD__
#define __FreeBSD__ #define __FreeBSD__
#endif #endif
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#include <sclinux.h> #include <sclinux.h>
#endif #endif
@ -34,7 +34,7 @@
#if defined HAVE_STDINT_H #if defined HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#else #else
#if defined __LCC__ || defined __DMC__ || defined LINUX #if defined __LCC__ || defined __DMC__ || defined LINUX || defined __APPLE__
#if defined HAVE_INTTYPES_H #if defined HAVE_INTTYPES_H
#include <inttypes.h> #include <inttypes.h>
#else #else
@ -190,7 +190,7 @@ typedef int (AMXAPI *AMX_NATIVE_FILTER)(struct tagAMX *amx, int index);
#endif #endif
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__ #if defined LINUX || defined __FreeBSD__ || defined __APPLE__
#pragma pack(1) /* structures must be packed (byte-aligned) */ #pragma pack(1) /* structures must be packed (byte-aligned) */
#elif defined MACOS && defined __MWERKS__ #elif defined MACOS && defined __MWERKS__
#pragma options align=mac68k #pragma options align=mac68k
@ -442,7 +442,7 @@ int AMXAPI amx_GetStringOld(char *dest,const cell *source,int use_wchar);
amx_Register((amx), amx_NativeInfo((name),(func)), 1); amx_Register((amx), amx_NativeInfo((name),(func)), 1);
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__ #if defined LINUX || defined __FreeBSD__ || defined __APPLE__
#pragma pack() /* reset default packing */ #pragma pack() /* reset default packing */
#elif defined MACOS && defined __MWERKS__ #elif defined MACOS && defined __MWERKS__
#pragma options align=reset #pragma options align=reset

View File

@ -180,7 +180,7 @@ static cell AMX_NATIVE_CALL setarg(AMX *amx, cell *params)
/* adjust the address in "value" in case of an array access */ /* adjust the address in "value" in case of an array access */
value+=params[2]*sizeof(cell); value+=params[2]*sizeof(cell);
/* verify the address */ /* verify the address */
if (value<0 || value>=amx->hea && value<amx->stk) if (value<0 || (value>=amx->hea && value<amx->stk))
return 0; return 0;
/* set the value indirectly */ /* set the value indirectly */
* (cell *)(data+(int)value) = params[3]; * (cell *)(data+(int)value) = params[3];

View File

@ -462,8 +462,8 @@ int AMXAPI dbg_GetVariable(AMX_DBG *amxdbg, const char *symname, ucell scopeaddr
break; break;
/* check the range, keep a pointer to the symbol with the smallest range */ /* check the range, keep a pointer to the symbol with the smallest range */
if (strcmp(amxdbg->symboltbl[index]->name, symname) == 0 if (strcmp(amxdbg->symboltbl[index]->name, symname) == 0
&& (codestart == 0 && codeend == 0 && ((codestart == 0 && codeend == 0)
|| amxdbg->symboltbl[index]->codestart >= codestart && amxdbg->symboltbl[index]->codeend <= codeend)) || (amxdbg->symboltbl[index]->codestart >= codestart && amxdbg->symboltbl[index]->codeend <= codeend)))
{ {
*sym = amxdbg->symboltbl[index]; *sym = amxdbg->symboltbl[index];
codestart = amxdbg->symboltbl[index]->codestart; codestart = amxdbg->symboltbl[index]->codestart;

View File

@ -49,7 +49,7 @@ extern "C" {
#endif #endif
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__ #if defined LINUX || defined __FreeBSD__ || defined __APPLE__
#pragma pack(1) /* structures must be packed (byte-aligned) */ #pragma pack(1) /* structures must be packed (byte-aligned) */
#elif defined MACOS && defined __MWERKS__ #elif defined MACOS && defined __MWERKS__
#pragma options align=mac68k #pragma options align=mac68k
@ -156,7 +156,7 @@ int AMXAPI dbg_GetArrayDim(AMX_DBG *amxdbg, const AMX_DBG_SYMBOL *sym, const AMX
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__ #if defined LINUX || defined __FreeBSD__ || defined __APPLE__
#pragma pack() /* reset default packing */ #pragma pack() /* reset default packing */
#elif defined MACOS && defined __MWERKS__ #elif defined MACOS && defined __MWERKS__
#pragma options align=reset #pragma options align=reset

View File

@ -303,14 +303,6 @@
%endif %endif
%endmacro %endmacro
%ifdef WIN32
section .data exec
%else
section .text
%endif
global asm_runJIT, _asm_runJIT global asm_runJIT, _asm_runJIT
global amx_exec_jit, _amx_exec_jit global amx_exec_jit, _amx_exec_jit
global getMaxCodeSize, _getMaxCodeSize global getMaxCodeSize, _getMaxCodeSize
@ -436,15 +428,6 @@ reloc_done:
pop ebp pop ebp
ret ret
; GWMV:
; The code below modifies itself to store the arguments to the Pawn opcodes
; in the compiled code. This is fine, but the .text section in an ELF executable
; is usually marked read-only, that's why this code is in the .data section.
%ifndef WIN32
section .data exec
%endif
OP_LOAD_PRI: OP_LOAD_PRI:
;nop; ;nop;
putval j_load_pri+2 putval j_load_pri+2
@ -1052,7 +1035,7 @@ OP_CALL:
j_call: j_call:
;call 12345678h ; tasm chokes on this out of a sudden ;call 12345678h ; tasm chokes on this out of a sudden
_PUSH 0 _PUSH 0
j_call_e8 j_call_e8:
db 0e8h, 0, 0, 0, 0 db 0e8h, 0, 0, 0, 0
CHECKCODESIZE j_call CHECKCODESIZE j_call
@ -2591,4 +2574,4 @@ _amx_opcodelist_jit:
DD OP_FLOAT_ROUND ; DA DD OP_FLOAT_ROUND ; DA
DD OP_FLOAT_CMP ; DA DD OP_FLOAT_CMP ; DA
END END:

View File

@ -146,7 +146,7 @@ static cell AMX_NATIVE_CALL server_print(AMX *amx, cell *params) /* 1 param */
static cell AMX_NATIVE_CALL engclient_print(AMX *amx, cell *params) /* 3 param */ static cell AMX_NATIVE_CALL engclient_print(AMX *amx, cell *params) /* 3 param */
{ {
int len; int len = 0;
char *msg; char *msg;
if (params[1] == 0) if (params[1] == 0)
@ -481,7 +481,7 @@ static cell AMX_NATIVE_CALL is_dedicated_server(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL is_linux_server(AMX *amx, cell *params) static cell AMX_NATIVE_CALL is_linux_server(AMX *amx, cell *params)
{ {
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
return 1; return 1;
#else #else
return 0; return 0;
@ -1005,7 +1005,7 @@ static cell AMX_NATIVE_CALL get_user_team(AMX *amx, cell *params) /* 3 param */
if (params[3]) if (params[3])
{ {
char *szTeam = ""; const char *szTeam = "";
switch (iTeam) switch (iTeam)
{ {
@ -3843,7 +3843,7 @@ static cell AMX_NATIVE_CALL amx_mkdir(AMX *amx, cell *params)
char *path = get_amxstring(amx, params[1], 0, len); char *path = get_amxstring(amx, params[1], 0, len);
char *realpath = build_pathname("%s", path); char *realpath = build_pathname("%s", path);
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
return mkdir(realpath, 0700); return mkdir(realpath, 0700);
#else #else
return mkdir(realpath); return mkdir(realpath);

View File

@ -32,7 +32,7 @@
#ifndef AMXMODX_H #ifndef AMXMODX_H
#define AMXMODX_H #define AMXMODX_H
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include "sclinux.h" #include "sclinux.h"
@ -86,7 +86,7 @@ extern AMX_NATIVE_INFO vector_Natives[];
extern AMX_NATIVE_INFO g_SortNatives[]; extern AMX_NATIVE_INFO g_SortNatives[];
extern AMX_NATIVE_INFO g_DataStructNatives[]; extern AMX_NATIVE_INFO g_DataStructNatives[];
#ifndef __linux__ #if defined(_WIN32)
#define DLLOAD(path) (DLHANDLE)LoadLibrary(path) #define DLLOAD(path) (DLHANDLE)LoadLibrary(path)
#define DLPROC(m, func) GetProcAddress(m, func) #define DLPROC(m, func) GetProcAddress(m, func)
#define DLFREE(m) FreeLibrary(m) #define DLFREE(m) FreeLibrary(m)
@ -107,14 +107,14 @@ extern AMX_NATIVE_INFO g_DataStructNatives[];
#endif #endif
#endif #endif
#ifndef __linux__ #if defined(_WIN32)
typedef HINSTANCE DLHANDLE; typedef HINSTANCE DLHANDLE;
#else #else
typedef void* DLHANDLE; typedef void* DLHANDLE;
#define INFINITE 0xFFFFFFFF #define INFINITE 0xFFFFFFFF
#endif #endif
#ifndef __linux__ #if defined(_WIN32)
#define PATH_SEP_CHAR '\\' #define PATH_SEP_CHAR '\\'
#define ALT_SEP_CHAR '/' #define ALT_SEP_CHAR '/'
#else #else
@ -139,7 +139,7 @@ int UTIL_ReadFlags(const char* c);
void UTIL_ClientPrint(edict_t *pEntity, int msg_dest, char *msg); void UTIL_ClientPrint(edict_t *pEntity, int msg_dest, char *msg);
void UTIL_FakeClientCommand(edict_t *pEdict, const char *cmd, const char *arg1 = NULL, const char *arg2 = NULL); void UTIL_FakeClientCommand(edict_t *pEdict, const char *cmd, const char *arg1 = NULL, const char *arg2 = NULL);
void UTIL_GetFlags(char* flags, int flag); void UTIL_GetFlags(char* flags, int flag);
void UTIL_HudMessage(edict_t *pEntity, const hudtextparms_t &textparms, char *pMessage); void UTIL_HudMessage(edict_t *pEntity, const hudtextparms_t &textparms, const char *pMessage);
void UTIL_IntToString(int value, char *output); void UTIL_IntToString(int value, char *output);
void UTIL_ShowMOTD(edict_t *client, char *motd, int mlen, const char *name); void UTIL_ShowMOTD(edict_t *client, char *motd, int mlen, const char *name);
void UTIL_ShowMenu(edict_t* pEntity, int slots, int time, char *menu, int mlen); void UTIL_ShowMenu(edict_t* pEntity, int slots, int time, char *menu, int mlen);
@ -276,8 +276,8 @@ void modules_callPluginsUnloaded();
void modules_callPluginsUnloading(); void modules_callPluginsUnloading();
cell* get_amxaddr(AMX *amx, cell amx_addr); cell* get_amxaddr(AMX *amx, cell amx_addr);
char* build_pathname(char *fmt, ...); char* build_pathname(const char *fmt, ...);
char* build_pathname_r(char *buffer, size_t maxlen, char *fmt, ...); char* build_pathname_r(char *buffer, size_t maxlen, const char *fmt, ...);
char* format_amxstring(AMX *amx, cell *params, int parm, int& len); char* format_amxstring(AMX *amx, cell *params, int parm, int& len);
AMX* get_amxscript(int, void**, const char**); AMX* get_amxscript(int, void**, const char**);
const char* get_amxscriptname(AMX* amx); const char* get_amxscriptname(AMX* amx);
@ -292,8 +292,8 @@ int unload_amxscript(AMX* amx, void** program);
void copy_amxmemory(cell* dest, cell* src, int len); void copy_amxmemory(cell* dest, cell* src, int len);
void get_modname(char*); void get_modname(char*);
void print_srvconsole(char *fmt, ...); void print_srvconsole(const char *fmt, ...);
void report_error(int code, char* fmt, ...); void report_error(int code, const char* fmt, ...);
void* alloc_amxmemory(void**, int size); void* alloc_amxmemory(void**, int size);
void free_amxmemory(void **ptr); void free_amxmemory(void **ptr);
// get_localinfo // get_localinfo

View File

@ -42,7 +42,7 @@
#define PACKED #define PACKED
#endif #endif
#if defined __linux__ #if defined(__linux__) || defined(__APPLE__)
#pragma pack(1) /* structures must be packed (byte-aligned) */ #pragma pack(1) /* structures must be packed (byte-aligned) */
#else #else
#pragma pack(1) /* structures must be packed (byte-aligned) */ #pragma pack(1) /* structures must be packed (byte-aligned) */
@ -127,7 +127,7 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
for (mint8_t i = 0; i < m_Bh.numPlugins; i++) for (mint8_t i = 0; i < m_Bh.numPlugins; i++)
{ {
pe = &(m_Bh.plugins[i]); pe = &(m_Bh.plugins[(unsigned)i]);
DATAREAD(&pe->cellsize, sizeof(mint8_t), 1); DATAREAD(&pe->cellsize, sizeof(mint8_t), 1);
DATAREAD(&pe->disksize, sizeof(int32_t), 1); DATAREAD(&pe->disksize, sizeof(int32_t), 1);
DATAREAD(&pe->imagesize, sizeof(int32_t), 1); DATAREAD(&pe->imagesize, sizeof(int32_t), 1);
@ -137,7 +137,7 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
for (mint8_t i = 0; i < m_Bh.numPlugins; i++) for (mint8_t i = 0; i < m_Bh.numPlugins; i++)
{ {
pe = &(m_Bh.plugins[i]); pe = &(m_Bh.plugins[(unsigned)i]);
if (pe->cellsize == m_CellSize) if (pe->cellsize == m_CellSize)
{ {

View File

@ -35,12 +35,12 @@
// 3 = HL Logs // 3 = HL Logs
#include <time.h> #include <time.h>
#ifndef __linux__ #if defined(_WIN32)
#include <io.h> #include <io.h>
#endif #endif
#include "amxmodx.h" #include "amxmodx.h"
#ifndef __linux__ #if defined(_WIN32WIN32)
#define vsnprintf _vsnprintf #define vsnprintf _vsnprintf
#endif #endif
@ -137,7 +137,7 @@ void CLog::MapChange()
{ {
// create dir if not existing // create dir if not existing
char file[256]; char file[256];
#ifdef __linux #if defined(__linux__) || defined(__APPLE__)
mkdir(build_pathname_r(file, sizeof(file)-1, "%s", g_log_dir.c_str()), 0700); mkdir(build_pathname_r(file, sizeof(file)-1, "%s", g_log_dir.c_str()), 0700);
#else #else
mkdir(build_pathname_r(file, sizeof(file)-1, "%s", g_log_dir.c_str())); mkdir(build_pathname_r(file, sizeof(file)-1, "%s", g_log_dir.c_str()));

View File

@ -46,7 +46,7 @@ bool BinLog::Open()
if (!DirExists(path)) if (!DirExists(path))
{ {
mkdir(path mkdir(path
#if defined __linux__ #if defined(__linux__) || defined(__APPLE__)
, 0755 , 0755
#endif #endif
); );

View File

@ -215,8 +215,7 @@ public:
int ShiftUpFrom(size_t which) int ShiftUpFrom(size_t which)
{ {
// No point shifting this. // No point shifting this.
if (this->count < 0 || if (which > this->count)
which > this->count)
{ {
return 0; return 0;
@ -254,8 +253,7 @@ public:
int Delete(size_t which) int Delete(size_t which)
{ {
// No point shifting this. // No point shifting this.
if (this->count < 0 || if (which >= this->count)
which >= this->count)
{ {
return 0; return 0;
} }

View File

@ -614,9 +614,9 @@ void Debugger::FmtGenericMsg(AMX *amx, int error, char buffer[], size_t maxLengt
if (a) if (a)
filename = (*a).getName(); filename = (*a).getName();
size_t len = strlen(filename); size_t len = strlen(filename);
for (size_t i=len-1; i>=0; i--) for (size_t i=len-1; i<len; i--)
{ {
if (filename[i] == '/' || filename[i] == '\\' && i != len - 1) if ((filename[i] == '/' || filename[i] == '\\') && i != len - 1)
{ {
filename = &(filename[i+1]); filename = &(filename[i+1]);
break; break;

View File

@ -43,7 +43,7 @@
#endif #endif
// header file for unlink() // header file for unlink()
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
#include <unistd.h> #include <unistd.h>
#else #else
#define WINDOWS_LEAN_AND_MEAN #define WINDOWS_LEAN_AND_MEAN
@ -784,7 +784,7 @@ static cell AMX_NATIVE_CALL amx_ungetc(AMX *amx, cell *params)
return ungetc(static_cast<int>(params[2]), fp); return ungetc(static_cast<int>(params[2]), fp);
} }
#if defined __linux__ #if defined(__linux__) || defined(__APPLE__)
#define _rmdir rmdir #define _rmdir rmdir
#endif #endif
@ -817,7 +817,7 @@ static cell AMX_NATIVE_CALL amx_rename(AMX *amx, cell *params)
snprintf(f_new_r, sizeof(f_new_r)-1, "%s", fnew); snprintf(f_new_r, sizeof(f_new_r)-1, "%s", fnew);
} }
#if defined __linux__ #if defined(__linux__) || defined(__APPLE__)
return (rename(f_old_r, f_new_r) == 0); return (rename(f_old_r, f_new_r) == 0);
#elif defined WIN32 #elif defined WIN32
return MoveFileA(f_old_r, f_new_r); return MoveFileA(f_old_r, f_new_r);

View File

@ -29,6 +29,11 @@
return 0; \ return 0; \
} }
template size_t atcprintf<cell, cell>(cell *, size_t, const cell *, AMX *, cell *, int *);
template size_t atcprintf<char, cell>(char *, size_t, const cell *, AMX *, cell *, int *);
template size_t atcprintf<cell, char>(cell *, size_t, const char *, AMX *, cell *, int *);
template size_t atcprintf<char, char>(char *, size_t, const char *, AMX *, cell *, int *);
THash<String, lang_err> BadLang_Table; THash<String, lang_err> BadLang_Table;
static cvar_t *amx_mldebug = NULL; static cvar_t *amx_mldebug = NULL;

View File

@ -43,7 +43,7 @@ _amxx_CpuSupport:
.fail: .fail:
xor eax, eax xor eax, eax
.end .end:
pop ebx pop ebx

View File

@ -185,7 +185,7 @@ unsigned char *MD5::raw_digest(){
char *MD5::hex_digest(){ const char *MD5::hex_digest(){
int i; int i;
char *s= new char[33]; char *s= new char[33];
@ -205,7 +205,7 @@ char *MD5::hex_digest(){
} }
char *MD5::hex_digest(char buffer[33]){ const char *MD5::hex_digest(char buffer[33]){
int i; int i;

View File

@ -59,8 +59,8 @@ public:
// methods to acquire finalized result // methods to acquire finalized result
unsigned char *raw_digest (); // digest as a 16-byte binary array unsigned char *raw_digest (); // digest as a 16-byte binary array
char * hex_digest (); // digest as a 33-byte ascii-hex string const char *hex_digest (); // digest as a 33-byte ascii-hex string
char * hex_digest (char buffer[33]); //same as above, passing buffer const char *hex_digest (char buffer[33]); //same as above, passing buffer

View File

@ -198,7 +198,7 @@ void BuildPluginFileList(const char *initialdir, CStack<String *> & files)
} }
_findclose(handle); _findclose(handle);
#elif defined __linux__ #elif defined(__linux__) || defined(__APPLE__)
build_pathname_r(path, sizeof(path)-1, "%s/", initialdir); build_pathname_r(path, sizeof(path)-1, "%s/", initialdir);
struct dirent *ep; struct dirent *ep;
DIR *dp; DIR *dp;
@ -254,7 +254,7 @@ void LoadExtraPluginsFromDir(const char *initialdir)
// Precache stuff from force consistency calls // Precache stuff from force consistency calls
// or check for pointed files won't be done // or check for pointed files won't be done
int C_PrecacheModel(char *s) int C_PrecacheModel(const char *s)
{ {
if (!g_forcedmodules) if (!g_forcedmodules)
{ {
@ -269,7 +269,7 @@ int C_PrecacheModel(char *s)
RETURN_META_VALUE(MRES_IGNORED, 0); RETURN_META_VALUE(MRES_IGNORED, 0);
} }
int C_PrecacheSound(char *s) int C_PrecacheSound(const char *s)
{ {
if (!g_forcedsounds) if (!g_forcedsounds)
{ {
@ -731,7 +731,7 @@ void C_ServerDeactivate_Post()
time(&td); time(&td);
tm *curTime = localtime(&td); tm *curTime = localtime(&td);
int i = 0; int i = 0;
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
mkdir(build_pathname("%s/memreports", get_localinfo("amxx_basedir", "addons/amxmodx")), 0700); mkdir(build_pathname("%s/memreports", get_localinfo("amxx_basedir", "addons/amxmodx")), 0700);
#else #else
mkdir(build_pathname("%s/memreports", get_localinfo("amxx_basedir", "addons/amxmodx"))); mkdir(build_pathname("%s/memreports", get_localinfo("amxx_basedir", "addons/amxmodx")));
@ -740,7 +740,7 @@ void C_ServerDeactivate_Post()
{ {
char buffer[256]; char buffer[256];
sprintf(buffer, "%s/memreports/D%02d%02d%03d", get_localinfo("amxx_basedir", "addons/amxmodx"), curTime->tm_mon + 1, curTime->tm_mday, i); sprintf(buffer, "%s/memreports/D%02d%02d%03d", get_localinfo("amxx_basedir", "addons/amxmodx"), curTime->tm_mon + 1, curTime->tm_mday, i);
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
mkdir(build_pathname("%s", g_log_dir.c_str()), 0700); mkdir(build_pathname("%s", g_log_dir.c_str()), 0700);
if (mkdir(build_pathname(buffer), 0700) < 0) if (mkdir(build_pathname(buffer), 0700) < 0)
#else #else
@ -1083,7 +1083,7 @@ void C_StartFrame_Post(void)
tm *curTime = localtime(&td); tm *curTime = localtime(&td);
int i = 0; int i = 0;
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
mkdir(build_pathname("%s/memreports", get_localinfo("amxx_basedir", "addons/amxmodx")), 0700); mkdir(build_pathname("%s/memreports", get_localinfo("amxx_basedir", "addons/amxmodx")), 0700);
#else #else
mkdir(build_pathname("%s/memreports", get_localinfo("amxx_basedir", "addons/amxmodx"))); mkdir(build_pathname("%s/memreports", get_localinfo("amxx_basedir", "addons/amxmodx")));
@ -1092,7 +1092,7 @@ void C_StartFrame_Post(void)
{ {
char buffer[256]; char buffer[256];
sprintf(buffer, "%s/memreports/D%02d%02d%03d", get_localinfo("amxx_basedir", "addons/amxmodx"), curTime->tm_mon + 1, curTime->tm_mday, i); sprintf(buffer, "%s/memreports/D%02d%02d%03d", get_localinfo("amxx_basedir", "addons/amxmodx"), curTime->tm_mon + 1, curTime->tm_mday, i);
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
mkdir(build_pathname("%s", g_log_dir.c_str()), 0700); mkdir(build_pathname("%s", g_log_dir.c_str()), 0700);
if (mkdir(build_pathname(buffer), 0700) < 0) if (mkdir(build_pathname(buffer), 0700) < 0)
#else #else
@ -1285,7 +1285,7 @@ void C_TraceLine_Post(const float *v1, const float *v2, int fNoMonsters, edict_t
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);
} }
void C_AlertMessage(ALERT_TYPE atype, char *szFmt, ...) void C_AlertMessage(ALERT_TYPE atype, const char *szFmt, ...)
{ {
if (atype != at_logged) if (atype != at_logged)
{ {
@ -1329,7 +1329,7 @@ void C_AlertMessage(ALERT_TYPE atype, char *szFmt, ...)
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);
} }
void C_ChangeLevel(char *map, char *what) void C_ChangeLevel(const char *map, const char *what)
{ {
int ret = executeForwards(FF_ChangeLevel, map); int ret = executeForwards(FF_ChangeLevel, map);
if (ret) if (ret)
@ -1371,7 +1371,7 @@ void C_CvarValue2(const edict_t *pEdict, int requestId, const char *cvar, const
RETURN_META(MRES_HANDLED); RETURN_META(MRES_HANDLED);
} }
C_DLLEXPORT int Meta_Query(char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs) C_DLLEXPORT int Meta_Query(const char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs)
{ {
gpMetaUtilFuncs = pMetaUtilFuncs; gpMetaUtilFuncs = pMetaUtilFuncs;
*pPlugInfo = &Plugin_info; *pPlugInfo = &Plugin_info;
@ -1535,7 +1535,7 @@ C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
return (TRUE); return (TRUE);
} }
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
// linux prototype // linux prototype
C_DLLEXPORT void GiveFnptrsToDll(enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals) C_DLLEXPORT void GiveFnptrsToDll(enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals)
{ {

View File

@ -29,8 +29,11 @@
* version. * version.
*/ */
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
#if defined(__linux__)
#include <malloc.h> #include <malloc.h>
#endif
#include <stdlib.h> #include <stdlib.h>
#include <sys/mman.h> #include <sys/mman.h>
#include "sclinux.h" #include "sclinux.h"
@ -86,7 +89,7 @@ bool DirExists(const char *dir)
return false; return false;
} }
void report_error(int code, char* fmt, ...) void report_error(int code, const char* fmt, ...)
{ {
va_list argptr; va_list argptr;
char string[256]; char string[256];
@ -106,7 +109,7 @@ void report_error(int code, char* fmt, ...)
} }
} }
void print_srvconsole(char *fmt, ...) void print_srvconsole(const char *fmt, ...)
{ {
va_list argptr; va_list argptr;
static char string[384]; static char string[384];
@ -340,11 +343,14 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64
if ((err = amx_InitJIT(amx, (void *)rt, (void *)np)) == AMX_ERR_NONE) if ((err = amx_InitJIT(amx, (void *)rt, (void *)np)) == AMX_ERR_NONE)
{ {
//amx->base = (unsigned char FAR *)realloc(np, amx->code_size); //amx->base = (unsigned char FAR *)realloc(np, amx->code_size);
#ifndef __linux__ #if defined(_WIN32)
amx->base = (unsigned char *)VirtualAlloc(NULL, amx->code_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); amx->base = (unsigned char *)VirtualAlloc(NULL, amx->code_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
#else #elif defined(__GNUC__)
//posix_memalign((void **)&(amx->base), sysconf(_SC_PAGESIZE), amx->code_size); # if defined(__APPLE__)
amx->base = (unsigned char *)valloc(amx->code_size);
# else
amx->base = (unsigned char *)memalign(sysconf(_SC_PAGESIZE), amx->code_size); amx->base = (unsigned char *)memalign(sysconf(_SC_PAGESIZE), amx->code_size);
# endif
mprotect((void *)amx->base, amx->code_size, PROT_READ|PROT_WRITE|PROT_EXEC); mprotect((void *)amx->base, amx->code_size, PROT_READ|PROT_WRITE|PROT_EXEC);
#endif #endif
if (amx->base) if (amx->base)
@ -641,7 +647,7 @@ int unload_amxscript(AMX* amx, void** program)
return AMX_ERR_NONE; return AMX_ERR_NONE;
#if defined JIT #if defined JIT
#if defined __linux__ #if defined(__linux__) || defined(__APPLE__)
if ((flags & AMX_FLAG_JITC) != AMX_FLAG_JITC) if ((flags & AMX_FLAG_JITC) != AMX_FLAG_JITC)
{ {
delete [] prg; delete [] prg;
@ -720,7 +726,7 @@ void get_modname(char* buffer)
strcpy(buffer, g_mod_name.c_str()); strcpy(buffer, g_mod_name.c_str());
} }
char* build_pathname(char *fmt, ...) char* build_pathname(const char *fmt, ...)
{ {
static char string[256]; static char string[256];
int b; int b;
@ -746,7 +752,7 @@ char* build_pathname(char *fmt, ...)
return string; return string;
} }
char *build_pathname_r(char *buffer, size_t maxlen, char *fmt, ...) char *build_pathname_r(char *buffer, size_t maxlen, const char *fmt, ...)
{ {
snprintf(buffer, maxlen, "%s%c", g_mod_name.c_str(), PATH_SEP_CHAR); snprintf(buffer, maxlen, "%s%c", g_mod_name.c_str(), PATH_SEP_CHAR);
@ -771,7 +777,7 @@ char *build_pathname_r(char *buffer, size_t maxlen, char *fmt, ...)
} }
// build pathname based on addons dir // build pathname based on addons dir
char* build_pathname_addons(char *fmt, ...) char* build_pathname_addons(const char *fmt, ...)
{ {
static char string[256]; static char string[256];
@ -875,7 +881,7 @@ bool ConvertModuleName(const char *pathString, String &path)
path.append(PATH_SEP_CHAR); path.append(PATH_SEP_CHAR);
path.append(tmpname); path.append(tmpname);
path.append("_amxx"); path.append("_amxx");
#if defined __linux__ #if defined(__linux__) || defined(__APPLE__)
#if defined AMD64 || PAWN_CELL_SIZE==64 #if defined AMD64 || PAWN_CELL_SIZE==64
path.append("_amd64"); path.append("_amd64");
#else #else
@ -888,6 +894,8 @@ bool ConvertModuleName(const char *pathString, String &path)
path.append(".dll"); path.append(".dll");
#elif defined __linux__ #elif defined __linux__
path.append(".so"); path.append(".so");
#elif defined __APPLE__
path.append(".dylib");
#endif #endif
return true; return true;
@ -1179,8 +1187,6 @@ void modules_callPluginsUnloading()
// new functions // new functions
int MNF_AddNatives(AMX_NATIVE_INFO* natives) int MNF_AddNatives(AMX_NATIVE_INFO* natives)
{ {
CList<CModule, const char *>::iterator a = g_modules.begin();
if (!g_CurrentlyCalledModule || g_ModuleCallReason != ModuleCall_Attach) if (!g_CurrentlyCalledModule || g_ModuleCallReason != ModuleCall_Attach)
return FALSE; // may only be called from attach return FALSE; // may only be called from attach
@ -1191,8 +1197,6 @@ int MNF_AddNatives(AMX_NATIVE_INFO* natives)
int MNF_AddNewNatives(AMX_NATIVE_INFO *natives) int MNF_AddNewNatives(AMX_NATIVE_INFO *natives)
{ {
CList<CModule, const char *>::iterator a = g_modules.begin();
if (!g_CurrentlyCalledModule || g_ModuleCallReason != ModuleCall_Attach) if (!g_CurrentlyCalledModule || g_ModuleCallReason != ModuleCall_Attach)
return FALSE; // may only be called from attach return FALSE; // may only be called from attach

View File

@ -35,7 +35,7 @@
#include "amx.h" #include "amx.h"
#undef DLLEXPORT #undef DLLEXPORT
#ifndef __linux__ #if defined(_WIN32)
#define DLLEXPORT __declspec(dllexport) #define DLLEXPORT __declspec(dllexport)
#else #else
#define DLLEXPORT __attribute__((visibility("default"))) #define DLLEXPORT __attribute__((visibility("default")))

View File

@ -35,8 +35,11 @@
#include "libraries.h" #include "libraries.h"
#include "format.h" #include "format.h"
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
#if defined(__linux__)
#include <malloc.h> #include <malloc.h>
#endif
#include <stdlib.h> #include <stdlib.h>
#include <sys/mman.h> #include <sys/mman.h>
#include "sclinux.h" #include "sclinux.h"
@ -479,12 +482,16 @@ static cell AMX_NATIVE_CALL register_native(AMX *amx, cell *params)
//we'll apply a safety buffer too //we'll apply a safety buffer too
//make our function //make our function
int size = amxx_DynaCodesize(); int size = amxx_DynaCodesize();
#ifndef __linux__ #if defined(_WIN32)
DWORD temp; DWORD temp;
pNative->pfn = new char[size + 10]; pNative->pfn = new char[size + 10];
VirtualProtect(pNative->pfn, size+10, PAGE_EXECUTE_READWRITE, &temp); VirtualProtect(pNative->pfn, size+10, PAGE_EXECUTE_READWRITE, &temp);
#else #elif defined(__GNUC__)
# if defined(__APPLE__)
pNative->pfn = (char *)valloc(size+10);
# else
pNative->pfn = (char *)memalign(sysconf(_SC_PAGESIZE), size+10); pNative->pfn = (char *)memalign(sysconf(_SC_PAGESIZE), size+10);
# endif
mprotect((void *)pNative->pfn, size+10, PROT_READ|PROT_WRITE|PROT_EXEC); mprotect((void *)pNative->pfn, size+10, PROT_READ|PROT_WRITE|PROT_EXEC);
#endif #endif

View File

@ -39,6 +39,10 @@
#include <endian.h> #include <endian.h>
#endif #endif
#if defined __APPLE__
#include <sys/types.h>
#endif
/* Linux NOW has these */ /* Linux NOW has these */
#if !defined BIG_ENDIAN #if !defined BIG_ENDIAN
#define BIG_ENDIAN 4321 #define BIG_ENDIAN 4321

View File

@ -20,10 +20,10 @@
#define stricmp(a,b) strcasecmp(a,b) #define stricmp(a,b) strcasecmp(a,b)
#define strnicmp(a,b,c) strncasecmp(a,b,c) #define strnicmp(a,b,c) strncasecmp(a,b,c)
#if defined __linux__ && !defined _snprintf #if ( defined(__linux__) || defined(__APPLE__) ) && !defined _snprintf
#define _snprintf snprintf #define _snprintf snprintf
#endif #endif
#if defined __linux__ && !defined _vsnprintf #if ( defined(__linux__) || defined(__APPLE__) ) && !defined _vsnprintf
//#define _vsnprintf vsnprintf //#define _vsnprintf vsnprintf
#endif #endif
@ -40,6 +40,10 @@
*/ */
#if !defined __BYTE_ORDER #if !defined __BYTE_ORDER
# include <stdlib.h> # include <stdlib.h>
# if defined __APPLE__
# include <sys/types.h>
# define __BYTE_ORDER BYTE_ORDER
# endif
#endif #endif
#if defined __OpenBSD__ #if defined __OpenBSD__

View File

@ -2240,7 +2240,7 @@ static META_FUNCTIONS g_MetaFunctions_Table =
GetEngineFunctions_Post GetEngineFunctions_Post
}; };
C_DLLEXPORT int Meta_Query(char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs) C_DLLEXPORT int Meta_Query(const char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs)
{ {
if ((int) CVAR_GET_FLOAT("developer") != 0) if ((int) CVAR_GET_FLOAT("developer") != 0)
UTIL_LogPrintf("[%s] dev: called: Meta_Query; version=%s, ours=%s\n", UTIL_LogPrintf("[%s] dev: called: Meta_Query; version=%s, ours=%s\n",
@ -2334,7 +2334,7 @@ C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
// linux prototype // linux prototype
C_DLLEXPORT void GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals ) { C_DLLEXPORT void GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals ) {
@ -3050,7 +3050,7 @@ char* UTIL_VarArgs( char *format, ... )
// UTIL_LogPrintf - Prints a logged message to console. // UTIL_LogPrintf - Prints a logged message to console.
// Preceded by LOG: ( timestamp ) < message > // Preceded by LOG: ( timestamp ) < message >
//========================================================= //=========================================================
void UTIL_LogPrintf( char *fmt, ... ) void UTIL_LogPrintf( const char *fmt, ... )
{ {
va_list argptr; va_list argptr;
static char string[1024]; static char string[1024];

View File

@ -20,11 +20,16 @@
// DLL Export // DLL Export
#undef DLLEXPORT #undef DLLEXPORT
#ifndef __linux__ #if defined(_WIN32)
#define DLLEXPORT __declspec(dllexport) #define DLLEXPORT __declspec(dllexport)
#else #else
#define DLLEXPORT __attribute__((visibility("default"))) #define DLLEXPORT __attribute__((visibility("default")))
#endif
#if defined(__linux__) && !defined(LINUX)
#define LINUX #define LINUX
#elif defined(__APPLE__) && !defined(OSX)
#define OSX
#endif #endif
#undef C_DLLEXPORT #undef C_DLLEXPORT
@ -66,7 +71,7 @@ struct amxx_module_info_s
#if defined HAVE_STDINT_H #if defined HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#else #else
#if defined __LCC__ || defined __DMC__ || defined LINUX #if defined __LCC__ || defined __DMC__ || defined LINUX || defined __APPLE__
#if defined HAVE_INTTYPES_H #if defined HAVE_INTTYPES_H
#include <inttypes.h> #include <inttypes.h>
#else #else
@ -308,7 +313,7 @@ typedef int (AMXAPI *AMX_DEBUG)(struct tagAMX *amx);
#endif #endif
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__ #if defined LINUX || defined __FreeBSD__ || defined __APPLE__
#pragma pack(1) /* structures must be packed (byte-aligned) */ #pragma pack(1) /* structures must be packed (byte-aligned) */
#elif defined MACOS && defined __MWERKS__ #elif defined MACOS && defined __MWERKS__
#pragma options align=mac68k #pragma options align=mac68k
@ -395,7 +400,7 @@ enum {
}; };
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined __linux__ #if defined(__linux__) || defined(__APPLE__)
#pragma pack() /* reset default packing */ #pragma pack() /* reset default packing */
#else #else
#pragma pack(pop) /* reset previous packing */ #pragma pack(pop) /* reset previous packing */
@ -406,7 +411,7 @@ enum {
// ***** declare functions ***** // ***** declare functions *****
#ifdef USE_METAMOD #ifdef USE_METAMOD
void UTIL_LogPrintf( char *fmt, ... ); void UTIL_LogPrintf( const char *fmt, ... );
void UTIL_HudMessage(CBaseEntity *pEntity, const hudtextparms_t &textparms, const char *pMessage); void UTIL_HudMessage(CBaseEntity *pEntity, const hudtextparms_t &textparms, const char *pMessage);
short FixedSigned16( float value, float scale ); short FixedSigned16( float value, float scale );
unsigned short FixedUnsigned16( float value, float scale ); unsigned short FixedUnsigned16( float value, float scale );
@ -833,11 +838,11 @@ int FN_AllowLagCompensation_Post(void);
#ifdef FN_PrecacheModel #ifdef FN_PrecacheModel
int FN_PrecacheModel(char *s); int FN_PrecacheModel(const char *s);
#endif // FN_PrecacheModel #endif // FN_PrecacheModel
#ifdef FN_PrecacheSound #ifdef FN_PrecacheSound
int FN_PrecacheSound(char *s); int FN_PrecacheSound(const char *s);
#endif // FN_PrecacheSound #endif // FN_PrecacheSound
#ifdef FN_SetModel #ifdef FN_SetModel
@ -857,7 +862,7 @@ void FN_SetSize(edict_t *e, const float *rgflMin, const float *rgflMax);
#endif // FN_SetSize #endif // FN_SetSize
#ifdef FN_ChangeLevel #ifdef FN_ChangeLevel
void FN_ChangeLevel(char *s1, char *s2); void FN_ChangeLevel(const char *s1, const char *s2);
#endif // FN_ChangeLevel #endif // FN_ChangeLevel
#ifdef FN_GetSpawnParms #ifdef FN_GetSpawnParms
@ -1261,19 +1266,19 @@ char *FN_GetInfoKeyBuffer(edict_t *e);
#endif // FN_GetInfoKeyBuffer #endif // FN_GetInfoKeyBuffer
#ifdef FN_InfoKeyValue #ifdef FN_InfoKeyValue
char *FN_InfoKeyValue(char *infobuffer, char *key); char *FN_InfoKeyValue(char *infobuffer, const char *key);
#endif // FN_InfoKeyValue #endif // FN_InfoKeyValue
#ifdef FN_SetKeyValue #ifdef FN_SetKeyValue
void FN_SetKeyValue(char *infobuffer, char *key, char *value); void FN_SetKeyValue(char *infobuffer, const char *key, const char *value);
#endif // FN_SetKeyValue #endif // FN_SetKeyValue
#ifdef FN_SetClientKeyValue #ifdef FN_SetClientKeyValue
void FN_SetClientKeyValue(int clientIndex, char *infobuffer, char *key, char *value); void FN_SetClientKeyValue(int clientIndex, char *infobuffer, const char *key, const char *value);
#endif // FN_SetClientKeyValue #endif // FN_SetClientKeyValue
#ifdef FN_IsMapValid #ifdef FN_IsMapValid
int FN_IsMapValid(char *filename); int FN_IsMapValid(const char *filename);
#endif // FN_IsMapValid #endif // FN_IsMapValid
#ifdef FN_StaticDecal #ifdef FN_StaticDecal
@ -1281,7 +1286,7 @@ void FN_StaticDecal(const float *origin, int decalIndex, int entityIndex, int mo
#endif // FN_StaticDecal #endif // FN_StaticDecal
#ifdef FN_PrecacheGeneric #ifdef FN_PrecacheGeneric
int FN_PrecacheGeneric(char *s); int FN_PrecacheGeneric(const char *s);
#endif // FN_PrecacheGeneric #endif // FN_PrecacheGeneric
#ifdef FN_GetPlayerUserId #ifdef FN_GetPlayerUserId
@ -1414,11 +1419,11 @@ const char *FN_GetPlayerAuthId(edict_t *e);
#ifdef FN_PrecacheModel_Post #ifdef FN_PrecacheModel_Post
int FN_PrecacheModel_Post(char *s); int FN_PrecacheModel_Post(const char *s);
#endif // FN_PrecacheModel_Post #endif // FN_PrecacheModel_Post
#ifdef FN_PrecacheSound_Post #ifdef FN_PrecacheSound_Post
int FN_PrecacheSound_Post(char *s); int FN_PrecacheSound_Post(const char *s);
#endif // FN_PrecacheSound_Post #endif // FN_PrecacheSound_Post
#ifdef FN_SetModel_Post #ifdef FN_SetModel_Post
@ -1438,7 +1443,7 @@ void FN_SetSize_Post(edict_t *e, const float *rgflMin, const float *rgflMax);
#endif // FN_SetSize_Post #endif // FN_SetSize_Post
#ifdef FN_ChangeLevel_Post #ifdef FN_ChangeLevel_Post
void FN_ChangeLevel_Post(char *s1, char *s2); void FN_ChangeLevel_Post(const char *s1, const char *s2);
#endif // FN_ChangeLevel_Post #endif // FN_ChangeLevel_Post
#ifdef FN_GetSpawnParms_Post #ifdef FN_GetSpawnParms_Post
@ -1842,19 +1847,19 @@ char *FN_GetInfoKeyBuffer_Post(edict_t *e);
#endif // FN_GetInfoKeyBuffer_Post #endif // FN_GetInfoKeyBuffer_Post
#ifdef FN_InfoKeyValue_Post #ifdef FN_InfoKeyValue_Post
char *FN_InfoKeyValue_Post(char *infobuffer, char *key); char *FN_InfoKeyValue_Post(char *infobuffer, const char *key);
#endif // FN_InfoKeyValue_Post #endif // FN_InfoKeyValue_Post
#ifdef FN_SetKeyValue_Post #ifdef FN_SetKeyValue_Post
void FN_SetKeyValue_Post(char *infobuffer, char *key, char *value); void FN_SetKeyValue_Post(char *infobuffer, const char *key, const char *value);
#endif // FN_SetKeyValue_Post #endif // FN_SetKeyValue_Post
#ifdef FN_SetClientKeyValue_Post #ifdef FN_SetClientKeyValue_Post
void FN_SetClientKeyValue_Post(int clientIndex, char *infobuffer, char *key, char *value); void FN_SetClientKeyValue_Post(int clientIndex, char *infobuffer, const char *key, const char *value);
#endif // FN_SetClientKeyValue_Post #endif // FN_SetClientKeyValue_Post
#ifdef FN_IsMapValid_Post #ifdef FN_IsMapValid_Post
int FN_IsMapValid_Post(char *filename); int FN_IsMapValid_Post(const char *filename);
#endif // FN_IsMapValid_Post #endif // FN_IsMapValid_Post
#ifdef FN_StaticDecal_Post #ifdef FN_StaticDecal_Post
@ -1862,7 +1867,7 @@ void FN_StaticDecal_Post(const float *origin, int decalIndex, int entityIndex, i
#endif // FN_StaticDecal_Post #endif // FN_StaticDecal_Post
#ifdef FN_PrecacheGeneric_Post #ifdef FN_PrecacheGeneric_Post
int FN_PrecacheGeneric_Post(char *s); int FN_PrecacheGeneric_Post(const char *s);
#endif // FN_PrecacheGeneric_Post #endif // FN_PrecacheGeneric_Post
#ifdef FN_GetPlayerUserId_Post #ifdef FN_GetPlayerUserId_Post
@ -2116,7 +2121,7 @@ typedef int (*PFN_ADD_NEW_NATIVES) (const AMX_NATIVE_INFO * /*list*/);
typedef char * (*PFN_BUILD_PATHNAME) (const char * /*format*/, ...); typedef char * (*PFN_BUILD_PATHNAME) (const char * /*format*/, ...);
typedef char * (*PFN_BUILD_PATHNAME_R) (char * /*buffer*/, size_t /* maxlen */, const char * /* format */, ...); typedef char * (*PFN_BUILD_PATHNAME_R) (char * /*buffer*/, size_t /* maxlen */, const char * /* format */, ...);
typedef cell * (*PFN_GET_AMXADDR) (AMX * /*amx*/, cell /*offset*/); typedef cell * (*PFN_GET_AMXADDR) (AMX * /*amx*/, cell /*offset*/);
typedef void (*PFN_PRINT_SRVCONSOLE) (char * /*format*/, ...); typedef void (*PFN_PRINT_SRVCONSOLE) (const char * /*format*/, ...);
typedef const char * (*PFN_GET_MODNAME) (void); typedef const char * (*PFN_GET_MODNAME) (void);
typedef const char * (*PFN_GET_AMXSCRIPTNAME) (int /*id*/); typedef const char * (*PFN_GET_AMXSCRIPTNAME) (int /*id*/);
typedef AMX * (*PFN_GET_AMXSCRIPT) (int /*id*/); typedef AMX * (*PFN_GET_AMXSCRIPT) (int /*id*/);
@ -2175,8 +2180,8 @@ typedef void (*PFN_DEALLOCATOR) (const char* /*filename*/, const unsigned i
typedef int (*PFN_AMX_EXEC) (AMX* /*amx*/, cell* /*return val*/, int /*index*/); typedef int (*PFN_AMX_EXEC) (AMX* /*amx*/, cell* /*return val*/, int /*index*/);
typedef int (*PFN_AMX_EXECV) (AMX* /*amx*/, cell* /*return val*/, int /*index*/, int /*numparams*/, cell[] /*params*/); typedef int (*PFN_AMX_EXECV) (AMX* /*amx*/, cell* /*return val*/, int /*index*/, int /*numparams*/, cell[] /*params*/);
typedef int (*PFN_AMX_ALLOT) (AMX* /*amx*/, int /*length*/, cell* /*amx_addr*/, cell** /*phys_addr*/); typedef int (*PFN_AMX_ALLOT) (AMX* /*amx*/, int /*length*/, cell* /*amx_addr*/, cell** /*phys_addr*/);
typedef int (*PFN_AMX_FINDPUBLIC) (AMX* /*amx*/, char* /*func name*/, int* /*index*/); typedef int (*PFN_AMX_FINDPUBLIC) (AMX* /*amx*/, const char* /*func name*/, int* /*index*/);
typedef int (*PFN_AMX_FINDNATIVE) (AMX* /*amx*/, char* /*func name*/, int* /*index*/); typedef int (*PFN_AMX_FINDNATIVE) (AMX* /*amx*/, const char* /*func name*/, int* /*index*/);
typedef int (*PFN_LOAD_AMXSCRIPT) (AMX* /*amx*/, void** /*code*/, const char* /*path*/, char[64] /*error info*/, int /* debug */); typedef int (*PFN_LOAD_AMXSCRIPT) (AMX* /*amx*/, void** /*code*/, const char* /*path*/, char[64] /*error info*/, int /* debug */);
typedef int (*PFN_UNLOAD_AMXSCRIPT) (AMX* /*amx*/,void** /*code*/); typedef int (*PFN_UNLOAD_AMXSCRIPT) (AMX* /*amx*/,void** /*code*/);
typedef cell (*PFN_REAL_TO_CELL) (REAL /*x*/); typedef cell (*PFN_REAL_TO_CELL) (REAL /*x*/);

View File

@ -19,7 +19,7 @@
#endif #endif
#include <new> #include <new>
#include <malloc.h> #include <stdlib.h>
//namespace SourceHook //namespace SourceHook
//{ //{

View File

@ -54,12 +54,12 @@
typedef List<THashNode *> * NodePtr; typedef List<THashNode *> * NodePtr;
public: public:
class const_iterator; class const_iterator;
THash() : m_Buckets(NULL), m_numBuckets(0), m_percentUsed(0.0f), m_items(0) THash() : m_Buckets(NULL), m_numBuckets(0), m_percentUsed(0.0f)
{ {
_Refactor(); _Refactor();
} }
THash(const THash &other) : m_Buckets(new NodePtr[other.m_numBuckets]), THash(const THash &other) : m_Buckets(new NodePtr[other.m_numBuckets]),
m_numBuckets(other.m_numBuckets), m_percentUsed(other.m_percentUsed), m_items(0) m_numBuckets(other.m_numBuckets), m_percentUsed(other.m_percentUsed)
{ {
for (size_t i=0; i<m_numBuckets; i++) for (size_t i=0; i<m_numBuckets; i++)
m_Buckets[i] = NULL; m_Buckets[i] = NULL;
@ -82,10 +82,6 @@
_Clear(); _Clear();
_Refactor(); _Refactor();
} }
size_t size()
{
return m_items;
}
size_t GetBuckets() size_t GetBuckets()
{ {
return m_numBuckets; return m_numBuckets;
@ -122,7 +118,6 @@
delete [] m_Buckets; delete [] m_Buckets;
m_Buckets = NULL; m_Buckets = NULL;
m_numBuckets = 0; m_numBuckets = 0;
m_items = 0;
} }
public: public:
template <typename U> template <typename U>
@ -229,8 +224,6 @@
} }
} }
public: public:
friend class iterator;
friend class const_iterator;
class iterator class iterator
{ {
friend class THash; friend class THash;
@ -304,8 +297,6 @@
*this = tmp; *this = tmp;
// :TODO: Maybe refactor to a lower size if required // :TODO: Maybe refactor to a lower size if required
m_items--;
} }
private: private:
void _Inc() void _Inc()
@ -454,6 +445,8 @@
const THash *hash; const THash *hash;
bool end; bool end;
}; };
friend class iterator;
friend class const_iterator;
public: public:
iterator begin() iterator begin()
{ {

View File

@ -34,7 +34,7 @@
#include <new> #include <new>
#include <string.h> #include <string.h>
#include <malloc.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
enum NodeType enum NodeType

View File

@ -10,7 +10,7 @@
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
#define strnicmp strncasecmp #define strnicmp strncasecmp
#endif #endif
@ -336,8 +336,10 @@ char *strptime(const char *buf, const char *fmt, struct tm *tm, short addthem)
if (0 <= ti.qS) (*defoper) ( &tm->tm_sec , ti.qS ); if (0 <= ti.qS) (*defoper) ( &tm->tm_sec , ti.qS );
if (0 <= ti.qM) (*defoper) ( &tm->tm_min , ti.qM ); //tm->tm_min = ti.qM; if (0 <= ti.qM) (*defoper) ( &tm->tm_min , ti.qM ); //tm->tm_min = ti.qM;
if (0 <= ti.qI) if (0 <= ti.qI)
{
if (0 <= ti.qp) ti.qH = ti.qI % 12 + ti.qp * 12; if (0 <= ti.qp) ti.qH = ti.qI % 12 + ti.qp * 12;
else (*defoper) ( &tm->tm_hour , ti.qI ); //tm->tm_hour = ti.qI; else (*defoper) ( &tm->tm_hour , ti.qI ); //tm->tm_hour = ti.qI;
}
if (0 <= ti.qH) (*defoper) ( &tm->tm_hour , ti.qH ); //tm->tm_hour = ti.qH; if (0 <= ti.qH) (*defoper) ( &tm->tm_hour , ti.qH ); //tm->tm_hour = ti.qH;
if (0 <= ti.qZ) (*defoper) ( &tm->tm_isdst , ti.qZ - 1 ); //tm->tm_isdst = ti.qZ - 1; if (0 <= ti.qZ) (*defoper) ( &tm->tm_isdst , ti.qZ - 1 ); //tm->tm_isdst = ti.qZ - 1;
if (0 <= ti.qy) ti.qY = ti.qy; if (0 <= ti.qy) ti.qY = ti.qy;

View File

@ -32,7 +32,7 @@
#include <time.h> #include <time.h>
#include "amxmodx.h" #include "amxmodx.h"
#if defined __linux__ && !defined _vsnprintf #if ( defined(__linux__) || defined(__APPLE__) ) && !defined _vsnprintf
#define _vsnprintf vsnprintf #define _vsnprintf vsnprintf
#endif #endif
@ -157,8 +157,8 @@ void UTIL_IntToString(int value, char *output)
if (tho) if (tho)
{ {
aaa += sprintf(&output[aaa], words[tho]); aaa += sprintf(&output[aaa], "%s", words[tho]);
aaa += sprintf(&output[aaa], words[29]); aaa += sprintf(&output[aaa], "%s", words[29]);
value = value % 1000; value = value % 1000;
} }
@ -166,8 +166,8 @@ void UTIL_IntToString(int value, char *output)
if (hun) if (hun)
{ {
aaa += sprintf(&output[aaa], words[hun]); aaa += sprintf(&output[aaa], "%s", words[hun]);
aaa += sprintf(&output[aaa], words[28]); aaa += sprintf(&output[aaa], "%s", words[28]);
value = value % 100; value = value % 100;
} }
@ -175,10 +175,10 @@ void UTIL_IntToString(int value, char *output)
int unit = value % 10; int unit = value % 10;
if (ten) if (ten)
aaa += sprintf(&output[aaa], words[(ten > 1) ? (ten + 18) : (unit + 10)]); aaa += sprintf(&output[aaa], "%s", words[(ten > 1) ? (ten + 18) : (unit + 10)]);
if (ten != 1 && (unit || (!value && !hun && !tho))) if (ten != 1 && (unit || (!value && !hun && !tho)))
sprintf(&output[aaa], words[unit]); sprintf(&output[aaa], "%s", words[unit]);
} }
char* UTIL_SplitHudMessage(const char *src) char* UTIL_SplitHudMessage(const char *src)
@ -242,7 +242,7 @@ short FixedSigned16(float value, float scale)
return (short)output; return (short)output;
} }
void UTIL_HudMessage(edict_t *pEntity, const hudtextparms_t &textparms, char *pMessage) void UTIL_HudMessage(edict_t *pEntity, const hudtextparms_t &textparms, const char *pMessage)
{ {
if (pEntity) if (pEntity)
MESSAGE_BEGIN(MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, NULL, pEntity); MESSAGE_BEGIN(MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, NULL, pEntity);

View File

@ -1,46 +1,107 @@
#(C)2004-2005 AMX Mod X Development Team # (C)2004-2013 AMX Mod X Development Team
# Makefile written by David "BAILOPAN" Anderson # Makefile written by David "BAILOPAN" Anderson
#####################################
### EDIT BELOW FOR OTHER PROJECTS ### ### EDIT BELOW FOR OTHER PROJECTS ###
#####################################
OPT_FLAGS = -O3 -funroll-loops -s -pipe -fno-strict-aliasing PROJECT = amxxpc
DEBUG_FLAGS = -g -ggdb3
CPP = gcc-4.1
BINARY = amxxpc
OBJECTS = amx.cpp amxxpc.cpp Binary.cpp OBJECTS = amx.cpp amxxpc.cpp Binary.cpp
LINK = -lz /lib32/libstdc++.a ##############################################
### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
##############################################
INCLUDE = -I. -L. C_OPT_FLAGS = -DNDEBUG -O2 -funroll-loops -fomit-frame-pointer -pipe
C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3
C_GCC4_FLAGS = -fvisibility=hidden
CPP_GCC4_FLAGS = -fvisibility-inlines-hidden
CPP = gcc
CPP_OSX = clang
LINK =
INCLUDE = -I.
################################################
### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ###
################################################
OS := $(shell uname -s)
ifeq "$(OS)" "Darwin"
CPP = $(CPP_OSX)
LIB_SUFFIX = _osx
CFLAGS += -DOSX
LINK += -lstdc++ -mmacosx-version-min=10.5 -lz-darwin
else
LIB_SUFFIX =
CFLAGS += -DLINUX
LINK += -lz /lib32/libstdc++.a
endif
LINK += -m32 -lm -ldl -L.
CFLAGS += -DAMX_ANSIONLY -DHAVE_STDINT_H -fno-strict-aliasing \
-m32 -Wall -Werror
CPPFLAGS += -fexceptions -fno-rtti
BINARY = $(PROJECT)$(LIB_SUFFIX)
ifeq "$(DEBUG)" "true" ifeq "$(DEBUG)" "true"
BIN_DIR = Debug BIN_DIR = Debug
CFLAGS = $(DEBUG_FLAGS) CFLAGS += $(C_DEBUG_FLAGS)
else else
BIN_DIR = Release BIN_DIR = Release
CFLAGS = $(OPT_FLAGS) CFLAGS += $(C_OPT_FLAGS)
endif endif
CFLAGS += -DLINUX -DNDEBUG -Wno-deprecated -fexceptions -DHAVE_STDINT_H -DAMX_ANSIONLY -fno-rtti -static-libgcc IS_CLANG := $(shell $(CPP) --version | head -1 | grep clang > /dev/null && echo "1" || echo "0")
OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) ifeq "$(IS_CLANG)" "1"
CPP_MAJOR := $(shell $(CPP) --version | grep clang | sed "s/.*version \([0-9]\)*\.[0-9]*.*/\1/")
CPP_MINOR := $(shell $(CPP) --version | grep clang | sed "s/.*version [0-9]*\.\([0-9]\)*.*/\1/")
else
CPP_MAJOR := $(shell $(CPP) -dumpversion >&1 | cut -b1)
CPP_MINOR := $(shell $(CPP) -dumpversion >&1 | cut -b3)
endif
# Clang || GCC >= 4
ifeq "$(shell expr $(IS_CLANG) \| $(CPP_MAJOR) \>= 4)" "1"
CFLAGS += $(C_GCC4_FLAGS)
CPPFLAGS += $(CPP_GCC4_FLAGS)
endif
# Clang >= 3 || GCC >= 4.7
ifeq "$(shell expr $(IS_CLANG) \& $(CPP_MAJOR) \>= 3 \| $(CPP_MAJOR) \>= 4 \& $(CPP_MINOR) \>= 7)" "1"
CFLAGS += -Wno-delete-non-virtual-dtor
endif
# OS is Linux and not using clang
ifeq "$(shell expr $(OS) \= Linux \& $(IS_CLANG) \= 0)" "1"
LINK += -static-libgcc
endif
OBJ_BIN := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o)
# This will break if we include other Makefiles, but is fine for now. It allows
# us to make a copy of this file that uses altered paths (ie. Makefile.mine)
# or other changes without mucking up the original.
MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
$(BIN_DIR)/%.o: %.cpp $(BIN_DIR)/%.o: %.cpp
$(CPP) $(INCLUDE) $(CFLAGS) -m32 -o $@ -c $< $(CPP) $(INCLUDE) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
all: all:
mkdir -p $(BIN_DIR) mkdir -p $(BIN_DIR)
$(MAKE) amxxpc $(MAKE) -f $(MAKEFILE_NAME) $(PROJECT)
amxxpc: $(OBJ_LINUX) $(PROJECT): $(OBJ_BIN)
$(CPP) $(INCLUDE) $(CFLAGS) -m32 $(OBJ_LINUX) $(LINK) -ldl -lm -o$(BIN_DIR)/$(BINARY) $(CPP) $(INCLUDE) $(OBJ_BIN) $(LINK) -o $(BIN_DIR)/$(BINARY)
default: all default: all
clean: clean:
rm -rf Release/*.o rm -rf $(BIN_DIR)/*.o
rm -rf Release/$(BINARY) rm -f $(BIN_DIR)/$(BINARY)
rm -rf Debug/*.o
rm -rf Debug/$(BINARY)

View File

@ -42,7 +42,7 @@
#include <stddef.h> /* for wchar_t */ #include <stddef.h> /* for wchar_t */
#include <string.h> #include <string.h>
#include "osdefs.h" #include "osdefs.h"
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#include <sclinux.h> #include <sclinux.h>
#if !defined AMX_NODYNALOAD #if !defined AMX_NODYNALOAD
#include <dlfcn.h> #include <dlfcn.h>
@ -815,12 +815,12 @@ static void expand(unsigned char *code, long codesize, long memsize)
int AMXAPI amx_Init(AMX *amx,void *program) int AMXAPI amx_Init(AMX *amx,void *program)
{ {
AMX_HEADER *hdr; AMX_HEADER *hdr;
#if (defined _Windows || defined LINUX || defined __FreeBSD__ || defined __OpenBSD__) && !defined AMX_NODYNALOAD #if (defined _Windows || defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__) && !defined AMX_NODYNALOAD
char libname[sNAMEMAX+8]; /* +1 for '\0', +3 for 'amx' prefix, +4 for extension */ char libname[sNAMEMAX+8]; /* +1 for '\0', +3 for 'amx' prefix, +4 for extension */
#if defined _Windows #if defined _Windows
typedef int (FAR WINAPI *AMX_ENTRY)(AMX _FAR *amx); typedef int (FAR WINAPI *AMX_ENTRY)(AMX _FAR *amx);
HINSTANCE hlib; HINSTANCE hlib;
#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
typedef int (*AMX_ENTRY)(AMX *amx); typedef int (*AMX_ENTRY)(AMX *amx);
void *hlib; void *hlib;
#endif #endif
@ -965,7 +965,7 @@ int AMXAPI amx_Init(AMX *amx,void *program)
amx_BrowseRelocate(amx); amx_BrowseRelocate(amx);
/* load any extension modules that the AMX refers to */ /* load any extension modules that the AMX refers to */
#if (defined _Windows || defined LINUX || defined __FreeBSD__ || defined __OpenBSD__) && !defined AMX_NODYNALOAD #if (defined _Windows || defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__) && !defined AMX_NODYNALOAD
hdr=(AMX_HEADER *)amx->base; hdr=(AMX_HEADER *)amx->base;
numlibraries=NUMENTRIES(hdr,libraries,pubvars); numlibraries=NUMENTRIES(hdr,libraries,pubvars);
for (i=0; i<numlibraries; i++) { for (i=0; i<numlibraries; i++) {
@ -981,7 +981,7 @@ int AMXAPI amx_Init(AMX *amx,void *program)
if (hlib<=HINSTANCE_ERROR) if (hlib<=HINSTANCE_ERROR)
hlib=NULL; hlib=NULL;
#endif #endif
#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
strcat(libname,".so"); strcat(libname,".so");
hlib=dlopen(libname,RTLD_NOW); hlib=dlopen(libname,RTLD_NOW);
#endif #endif
@ -995,7 +995,7 @@ int AMXAPI amx_Init(AMX *amx,void *program)
strcat(funcname,"Init"); strcat(funcname,"Init");
#if defined _Windows #if defined _Windows
libinit=(AMX_ENTRY)GetProcAddress(hlib,funcname); libinit=(AMX_ENTRY)GetProcAddress(hlib,funcname);
#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
libinit=(AMX_ENTRY)dlsym(hlib,funcname); libinit=(AMX_ENTRY)dlsym(hlib,funcname);
#endif #endif
if (libinit!=NULL) if (libinit!=NULL)
@ -1029,7 +1029,7 @@ int AMXAPI amx_Init(AMX *amx,void *program)
return !VirtualProtect(addr, len, p, &prev); return !VirtualProtect(addr, len, p, &prev);
} }
#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
/* Linux already has mprotect() */ /* Linux already has mprotect() */
@ -1104,10 +1104,10 @@ int AMXAPI amx_InitJIT(AMX *amx,void *compiled_program,void *reloc_table)
#if defined AMX_CLEANUP #if defined AMX_CLEANUP
int AMXAPI amx_Cleanup(AMX *amx) int AMXAPI amx_Cleanup(AMX *amx)
{ {
#if (defined _Windows || defined LINUX || defined __FreeBSD__ || defined __OpenBSD__) && !defined AMX_NODYNALOAD #if (defined _Windows || defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__) && !defined AMX_NODYNALOAD
#if defined _Windows #if defined _Windows
typedef int (FAR WINAPI *AMX_ENTRY)(AMX FAR *amx); typedef int (FAR WINAPI *AMX_ENTRY)(AMX FAR *amx);
#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
typedef int (*AMX_ENTRY)(AMX *amx); typedef int (*AMX_ENTRY)(AMX *amx);
#endif #endif
AMX_HEADER *hdr; AMX_HEADER *hdr;
@ -1117,7 +1117,7 @@ int AMXAPI amx_Cleanup(AMX *amx)
#endif #endif
/* unload all extension modules */ /* unload all extension modules */
#if (defined _Windows || defined LINUX || defined __FreeBSD__ || defined __OpenBSD__) && !defined AMX_NODYNALOAD #if (defined _Windows || defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__) && !defined AMX_NODYNALOAD
hdr=(AMX_HEADER *)amx->base; hdr=(AMX_HEADER *)amx->base;
assert(hdr->magic==AMX_MAGIC); assert(hdr->magic==AMX_MAGIC);
numlibraries=NUMENTRIES(hdr,libraries,pubvars); numlibraries=NUMENTRIES(hdr,libraries,pubvars);
@ -1130,14 +1130,14 @@ int AMXAPI amx_Cleanup(AMX *amx)
strcat(funcname,"Cleanup"); strcat(funcname,"Cleanup");
#if defined _Windows #if defined _Windows
libcleanup=(AMX_ENTRY)GetProcAddress((HINSTANCE)lib->address,funcname); libcleanup=(AMX_ENTRY)GetProcAddress((HINSTANCE)lib->address,funcname);
#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
libcleanup=(AMX_ENTRY)dlsym((void*)lib->address,funcname); libcleanup=(AMX_ENTRY)dlsym((void*)lib->address,funcname);
#endif #endif
if (libcleanup!=NULL) if (libcleanup!=NULL)
libcleanup(amx); libcleanup(amx);
#if defined _Windows #if defined _Windows
FreeLibrary((HINSTANCE)lib->address); FreeLibrary((HINSTANCE)lib->address);
#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
dlclose((void*)lib->address); dlclose((void*)lib->address);
#endif #endif
} /* if */ } /* if */
@ -1666,7 +1666,7 @@ int AMXAPI amx_PushString(AMX *amx, cell *amx_addr, cell **phys_addr, const char
* fast "indirect threaded" interpreter. * fast "indirect threaded" interpreter.
*/ */
#define NEXT(cip) goto **cip++ #define NEXT(cip) goto *(const void *)*cip++
int AMXAPI amx_Exec(AMX *amx, cell *retval, int index) int AMXAPI amx_Exec(AMX *amx, cell *retval, int index)
{ {
@ -1846,14 +1846,14 @@ static const void * const amx_opcodelist[] = {
NEXT(cip); NEXT(cip);
op_load_i: op_load_i:
/* verify address */ /* verify address */
if (pri>=hea && pri<stk || (ucell)pri>=(ucell)amx->stp) if ((pri>=hea && pri<stk) || (ucell)pri>=(ucell)amx->stp)
ABORT(amx,AMX_ERR_MEMACCESS); ABORT(amx,AMX_ERR_MEMACCESS);
pri= * (cell *)(data+(int)pri); pri= * (cell *)(data+(int)pri);
NEXT(cip); NEXT(cip);
op_lodb_i: op_lodb_i:
GETPARAM(offs); GETPARAM(offs);
/* verify address */ /* verify address */
if (pri>=hea && pri<stk || (ucell)pri>=(ucell)amx->stp) if ((pri>=hea && pri<stk) || (ucell)pri>=(ucell)amx->stp)
ABORT(amx,AMX_ERR_MEMACCESS); ABORT(amx,AMX_ERR_MEMACCESS);
switch (offs) { switch (offs) {
case 1: case 1:
@ -1919,14 +1919,14 @@ static const void * const amx_opcodelist[] = {
NEXT(cip); NEXT(cip);
op_stor_i: op_stor_i:
/* verify address */ /* verify address */
if (alt>=hea && alt<stk || (ucell)alt>=(ucell)amx->stp) if ((alt>=hea && alt<stk) || (ucell)alt>=(ucell)amx->stp)
ABORT(amx,AMX_ERR_MEMACCESS); ABORT(amx,AMX_ERR_MEMACCESS);
*(cell *)(data+(int)alt)=pri; *(cell *)(data+(int)alt)=pri;
NEXT(cip); NEXT(cip);
op_strb_i: op_strb_i:
GETPARAM(offs); GETPARAM(offs);
/* verify address */ /* verify address */
if (alt>=hea && alt<stk || (ucell)alt>=(ucell)amx->stp) if ((alt>=hea && alt<stk) || (ucell)alt>=(ucell)amx->stp)
ABORT(amx,AMX_ERR_MEMACCESS); ABORT(amx,AMX_ERR_MEMACCESS);
switch (offs) { switch (offs) {
case 1: case 1:
@ -1943,7 +1943,7 @@ static const void * const amx_opcodelist[] = {
op_lidx: op_lidx:
offs=pri*sizeof(cell)+alt; offs=pri*sizeof(cell)+alt;
/* verify address */ /* verify address */
if (offs>=hea && offs<stk || (ucell)offs>=(ucell)amx->stp) if ((offs>=hea && offs<stk) || (ucell)offs>=(ucell)amx->stp)
ABORT(amx,AMX_ERR_MEMACCESS); ABORT(amx,AMX_ERR_MEMACCESS);
pri= * (cell *)(data+(int)offs); pri= * (cell *)(data+(int)offs);
NEXT(cip); NEXT(cip);
@ -1951,7 +1951,7 @@ static const void * const amx_opcodelist[] = {
GETPARAM(offs); GETPARAM(offs);
offs=(pri << (int)offs)+alt; offs=(pri << (int)offs)+alt;
/* verify address */ /* verify address */
if (offs>=hea && offs<stk || (ucell)offs>=(ucell)amx->stp) if ((offs>=hea && offs<stk) || (ucell)offs>=(ucell)amx->stp)
ABORT(amx,AMX_ERR_MEMACCESS); ABORT(amx,AMX_ERR_MEMACCESS);
pri= * (cell *)(data+(int)offs); pri= * (cell *)(data+(int)offs);
NEXT(cip); NEXT(cip);
@ -2388,13 +2388,13 @@ static const void * const amx_opcodelist[] = {
/* verify top & bottom memory addresses, for both source and destination /* verify top & bottom memory addresses, for both source and destination
* addresses * addresses
*/ */
if (pri>=hea && pri<stk || (ucell)pri>=(ucell)amx->stp) if ((pri>=hea && pri<stk) || (ucell)pri>=(ucell)amx->stp)
ABORT(amx,AMX_ERR_MEMACCESS); ABORT(amx,AMX_ERR_MEMACCESS);
if ((pri+offs)>hea && (pri+offs)<stk || (ucell)(pri+offs)>(ucell)amx->stp) if (((pri+offs)>hea && (pri+offs)<stk) || (ucell)(pri+offs)>(ucell)amx->stp)
ABORT(amx,AMX_ERR_MEMACCESS); ABORT(amx,AMX_ERR_MEMACCESS);
if (alt>=hea && alt<stk || (ucell)alt>=(ucell)amx->stp) if ((alt>=hea && alt<stk) || (ucell)alt>=(ucell)amx->stp)
ABORT(amx,AMX_ERR_MEMACCESS); ABORT(amx,AMX_ERR_MEMACCESS);
if ((alt+offs)>hea && (alt+offs)<stk || (ucell)(alt+offs)>(ucell)amx->stp) if (((alt+offs)>hea && (alt+offs)<stk) || (ucell)(alt+offs)>(ucell)amx->stp)
ABORT(amx,AMX_ERR_MEMACCESS); ABORT(amx,AMX_ERR_MEMACCESS);
memcpy(data+(int)alt, data+(int)pri, (int)offs); memcpy(data+(int)alt, data+(int)pri, (int)offs);
NEXT(cip); NEXT(cip);
@ -2403,22 +2403,22 @@ static const void * const amx_opcodelist[] = {
/* verify top & bottom memory addresses, for both source and destination /* verify top & bottom memory addresses, for both source and destination
* addresses * addresses
*/ */
if (pri>=hea && pri<stk || (ucell)pri>=(ucell)amx->stp) if ((pri>=hea && pri<stk) || (ucell)pri>=(ucell)amx->stp)
ABORT(amx,AMX_ERR_MEMACCESS); ABORT(amx,AMX_ERR_MEMACCESS);
if ((pri+offs)>hea && (pri+offs)<stk || (ucell)(pri+offs)>(ucell)amx->stp) if (((pri+offs)>hea && (pri+offs)<stk) || (ucell)(pri+offs)>(ucell)amx->stp)
ABORT(amx,AMX_ERR_MEMACCESS); ABORT(amx,AMX_ERR_MEMACCESS);
if (alt>=hea && alt<stk || (ucell)alt>=(ucell)amx->stp) if ((alt>=hea && alt<stk) || (ucell)alt>=(ucell)amx->stp)
ABORT(amx,AMX_ERR_MEMACCESS); ABORT(amx,AMX_ERR_MEMACCESS);
if ((alt+offs)>hea && (alt+offs)<stk || (ucell)(alt+offs)>(ucell)amx->stp) if (((alt+offs)>hea && (alt+offs)<stk) || (ucell)(alt+offs)>(ucell)amx->stp)
ABORT(amx,AMX_ERR_MEMACCESS); ABORT(amx,AMX_ERR_MEMACCESS);
pri=memcmp(data+(int)alt, data+(int)pri, (int)offs); pri=memcmp(data+(int)alt, data+(int)pri, (int)offs);
NEXT(cip); NEXT(cip);
op_fill: op_fill:
GETPARAM(offs); GETPARAM(offs);
/* verify top & bottom memory addresses */ /* verify top & bottom memory addresses */
if (alt>=hea && alt<stk || (ucell)alt>=(ucell)amx->stp) if ((alt>=hea && alt<stk) || (ucell)alt>=(ucell)amx->stp)
ABORT(amx,AMX_ERR_MEMACCESS); ABORT(amx,AMX_ERR_MEMACCESS);
if ((alt+offs)>hea && (alt+offs)<stk || (ucell)(alt+offs)>(ucell)amx->stp) if (((alt+offs)>hea && (alt+offs)<stk) || (ucell)(alt+offs)>(ucell)amx->stp)
ABORT(amx,AMX_ERR_MEMACCESS); ABORT(amx,AMX_ERR_MEMACCESS);
for (i=(int)alt; offs>=(int)sizeof(cell); i+=sizeof(cell), offs-=sizeof(cell)) for (i=(int)alt; offs>=(int)sizeof(cell); i+=sizeof(cell), offs-=sizeof(cell))
*(cell *)(data+i) = pri; *(cell *)(data+i) = pri;
@ -3592,7 +3592,7 @@ int AMXAPI amx_GetAddr(AMX *amx,cell amx_addr,cell **phys_addr)
data=(amx->data!=NULL) ? amx->data : amx->base+(int)hdr->dat; data=(amx->data!=NULL) ? amx->data : amx->base+(int)hdr->dat;
assert(phys_addr!=NULL); assert(phys_addr!=NULL);
if (amx_addr>=amx->hea && amx_addr<amx->stk || amx_addr<0 || amx_addr>=amx->stp) { if ((amx_addr>=amx->hea && amx_addr<amx->stk) || amx_addr<0 || amx_addr>=amx->stp) {
*phys_addr=NULL; *phys_addr=NULL;
return AMX_ERR_MEMACCESS; return AMX_ERR_MEMACCESS;
} /* if */ } /* if */

View File

@ -24,7 +24,7 @@
#if defined FREEBSD && !defined __FreeBSD__ #if defined FREEBSD && !defined __FreeBSD__
#define __FreeBSD__ #define __FreeBSD__
#endif #endif
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#include <sclinux.h> #include <sclinux.h>
#endif #endif
@ -34,7 +34,7 @@
#if defined HAVE_STDINT_H #if defined HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#else #else
#if defined __LCC__ || defined __DMC__ || defined LINUX #if defined __LCC__ || defined __DMC__ || defined LINUX || defined __APPLE__
#if defined HAVE_INTTYPES_H #if defined HAVE_INTTYPES_H
#include <inttypes.h> #include <inttypes.h>
#else #else
@ -188,7 +188,7 @@ typedef int (AMXAPI *AMX_DEBUG)(struct tagAMX *amx);
#endif #endif
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__ #if defined LINUX || defined __FreeBSD__ || defined __APPLE__
#pragma pack(1) /* structures must be packed (byte-aligned) */ #pragma pack(1) /* structures must be packed (byte-aligned) */
#elif defined MACOS && defined __MWERKS__ #elif defined MACOS && defined __MWERKS__
#pragma options align=mac68k #pragma options align=mac68k
@ -416,7 +416,7 @@ int AMXAPI amx_UTF8Put(char *string, char **endptr, int maxchars, cell value);
amx_Register((amx), amx_NativeInfo((name),(func)), 1); amx_Register((amx), amx_NativeInfo((name),(func)), 1);
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__ #if defined LINUX || defined __FreeBSD__ || defined __APPLE__
#pragma pack() /* reset default packing */ #pragma pack() /* reset default packing */
#elif defined MACOS && defined __MWERKS__ #elif defined MACOS && defined __MWERKS__
#pragma options align=reset #pragma options align=reset

View File

@ -49,7 +49,7 @@ extern "C" {
#endif #endif
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__ #if defined LINUX || defined __FreeBSD__ || defined __APPLE__
#pragma pack(1) /* structures must be packed (byte-aligned) */ #pragma pack(1) /* structures must be packed (byte-aligned) */
#elif defined MACOS && defined __MWERKS__ #elif defined MACOS && defined __MWERKS__
#pragma options align=mac68k #pragma options align=mac68k
@ -156,7 +156,7 @@ int AMXAPI dbg_GetArrayDim(AMX_DBG *amxdbg, const AMX_DBG_SYMBOL *sym, const AMX
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__ #if defined LINUX || defined __FreeBSD__ || defined __APPLE__
#pragma pack() /* reset default packing */ #pragma pack() /* reset default packing */
#elif defined MACOS && defined __MWERKS__ #elif defined MACOS && defined __MWERKS__
#pragma options align=reset #pragma options align=reset

View File

@ -1,5 +1,5 @@
#include <stdio.h> #include <stdio.h>
#ifdef __linux__ #if defined(__linux__) | defined (__APPLE__)
#include <unistd.h> #include <unistd.h>
#else #else
#include <fcntl.h> #include <fcntl.h>
@ -29,25 +29,26 @@ void WriteBh(BinaryWriter *bw, BinPlugin *bh);
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct abl pl32; struct abl pl32;
struct abl pl64;
#ifdef _DEBUG #ifdef _DEBUG
printf("debug clamp\n"); printf("debug clamp\n");
getchar(); getchar();
#endif #endif
#ifdef __linux__ #if defined(__linux__)
HINSTANCE lib = NULL; HINSTANCE lib = NULL;
if (FileExists("./amxxpc32.so")) if (FileExists("./amxxpc32.so"))
lib = dlmount("./amxxpc32.so"); lib = dlmount("./amxxpc32.so");
else else
lib = dlmount("amxxpc32.so"); lib = dlmount("amxxpc32.so");
#elif defined(__APPLE__)
HINSTANCE lib = dlmount("amxxpc32.dylib");
#else #else
HINSTANCE lib = dlmount("amxxpc32.dll"); HINSTANCE lib = dlmount("amxxpc32.dll");
#endif #endif
if (!lib) if (!lib)
{ {
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
printf("compiler failed to instantiate: %s\n", dlerror()); printf("compiler failed to instantiate: %s\n", dlerror());
#else #else
printf("compiler failed to instantiate: %d\n", GetLastError()); printf("compiler failed to instantiate: %d\n", GetLastError());
@ -60,7 +61,7 @@ int main(int argc, char **argv)
if (!sc32 || !pc_printf) if (!sc32 || !pc_printf)
{ {
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
printf("compiler failed to link: %p.\n",sc32); printf("compiler failed to link: %p.\n",sc32);
#else #else
printf("compiler failed to link: %d.\n", GetLastError()); printf("compiler failed to link: %d.\n", GetLastError());
@ -69,7 +70,7 @@ int main(int argc, char **argv)
} }
pc_printf("Welcome to the AMX Mod X %s Compiler.\n", VERSION_STRING); pc_printf("Welcome to the AMX Mod X %s Compiler.\n", VERSION_STRING);
pc_printf("Copyright (c) 1997-2006 ITB CompuPhase, AMX Mod X Team\n\n"); pc_printf("Copyright (c) 1997-2013 ITB CompuPhase, AMX Mod X Team\n\n");
if (argc < 2) if (argc < 2)
{ {
@ -243,7 +244,7 @@ char *swiext(const char *file, const char *ext, int isO)
int i = 0, pos = -1, j = 0; int i = 0, pos = -1, j = 0;
int fileLen = strlen(file); int fileLen = strlen(file);
int extLen = strlen(ext); int extLen = strlen(ext);
int max = 0, odirFlag = -1; int odirFlag = -1;
for (i=fileLen-1; i>=0; i--) for (i=fileLen-1; i>=0; i--)
{ {
@ -339,7 +340,7 @@ void show_help()
printf("\t-r[name] write cross reference report to console or to specified file\n"); printf("\t-r[name] write cross reference report to console or to specified file\n");
} }
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
bool FileExists(const char *file) bool FileExists(const char *file)
{ {
FILE *fp = fopen(file, "rb"); FILE *fp = fopen(file, "rb");

View File

@ -5,7 +5,7 @@
#define MAGIC_HEADER2 0x414D5858 #define MAGIC_HEADER2 0x414D5858
#define MAGIC_VERSION 0x0300 #define MAGIC_VERSION 0x0300
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
# include <dlfcn.h> # include <dlfcn.h>
#else #else
# include <windows.h> # include <windows.h>
@ -13,7 +13,7 @@
#include <string.h> #include <string.h>
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
# define dlmount(x) dlopen(x, RTLD_NOW|RTLD_GLOBAL) # define dlmount(x) dlopen(x, RTLD_NOW|RTLD_GLOBAL)
typedef void* HINSTANCE; typedef void* HINSTANCE;
#else #else
@ -65,7 +65,7 @@ struct BinPlugin
int32_t offs; //file offset int32_t offs; //file offset
}; };
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
bool FileExists(const char *file); bool FileExists(const char *file);
#endif #endif

View File

@ -39,6 +39,10 @@
#include <endian.h> #include <endian.h>
#endif #endif
#if defined __APPLE__
#include <sys/types.h>
#endif
/* Linux NOW has these */ /* Linux NOW has these */
#if !defined BIG_ENDIAN #if !defined BIG_ENDIAN
#define BIG_ENDIAN 4321 #define BIG_ENDIAN 4321

View File

@ -32,6 +32,10 @@
*/ */
#if !defined __BYTE_ORDER #if !defined __BYTE_ORDER
# include <stdlib.h> # include <stdlib.h>
# if defined __APPLE__
# include <sys/types.h>
# define __BYTE_ORDER BYTE_ORDER
# endif
#endif #endif
#if defined __OpenBSD__ || defined __FreeBSD__ #if defined __OpenBSD__ || defined __FreeBSD__

View File

@ -1,46 +1,108 @@
#(C)2004-2005 AMX Mod X Development Team # (C)2004-2013 AMX Mod X Development Team
# Makefile written by David "BAILOPAN" Anderson # Makefile written by David "BAILOPAN" Anderson
#####################################
### EDIT BELOW FOR OTHER PROJECTS ### ### EDIT BELOW FOR OTHER PROJECTS ###
#####################################
OPT_FLAGS = -O3 -funroll-loops -s -pipe -fno-strict-aliasing -fvisibility=hidden PROJECT = amxxpc32
DEBUG_FLAGS = -g -ggdb3 OBJECTS = sc1.c sc2.c sc3.c sc4.c sc5.c sc6.c sc7.c scvars.c scmemfil.c scstate.c sclist.c sci18n.c \
CPP = gcc-4.1 scexpand.c pawncc.c libpawnc.c prefix.c memfile.c
NAME = amxxpc32
OBJECTS = sc1.c sc2.c sc3.c sc4.c sc5.c sc6.c sc7.c scvars.c scmemfil.c \ ##############################################
scstate.c sclist.c sci18n.c scexpand.c pawncc.c libpawnc.c prefix.c \ ### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
memfile.c ##############################################
C_OPT_FLAGS = -DNDEBUG -O2 -funroll-loops -fomit-frame-pointer -pipe
C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3
C_GCC4_FLAGS = -fvisibility=hidden
CPP_GCC4_FLAGS = -fvisibility-inlines-hidden
CPP = gcc
CPP_OSX = clang
LINK = -lpthread LINK = -lpthread
INCLUDE = -I. INCLUDE = -I.
BINARY = $(NAME).so ################################################
BIN_DIR = Release ### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ###
CFLAGS += -DPAWN_CELL_SIZE=32 ################################################
CFLAGS += -DLINUX -DNDEBUG -DHAVE_STDINT_H -DENABLE_BINRELOC -DNO_MAIN -DPAWNC_DLL -static-libgcc OS := $(shell uname -s)
CFLAGS += $(OPT_FLAGS) ifeq "$(OS)" "Darwin"
OBJ_LINUX := $(OBJECTS:%.c=$(BIN_DIR)/%.o) CPP = $(CPP_OSX)
LIB_EXT = dylib
CFLAGS += -DOSX
LINK += -dynamiclib -mmacosx-version-min=10.5
else
LIB_EXT = so
CFLAGS += -DLINUX
LINK += -shared
endif
LINK += -m32 -lm -ldl
CFLAGS += -DENABLE_BINRELOC -DNO_MAIN -DPAWNC_DLL -DHAVE_STDINT_H -fno-strict-aliasing -m32 -Wall \
-Werror
CPPFLAGS += -fexceptions -fno-rtti
BINARY = $(PROJECT).$(LIB_EXT)
ifeq "$(DEBUG)" "true"
BIN_DIR = Debug
CFLAGS += $(C_DEBUG_FLAGS)
else
BIN_DIR = Release
CFLAGS += $(C_OPT_FLAGS)
endif
IS_CLANG := $(shell $(CPP) --version | head -1 | grep clang > /dev/null && echo "1" || echo "0")
ifeq "$(IS_CLANG)" "1"
CPP_MAJOR := $(shell $(CPP) --version | grep clang | sed "s/.*version \([0-9]\)*\.[0-9]*.*/\1/")
CPP_MINOR := $(shell $(CPP) --version | grep clang | sed "s/.*version [0-9]*\.\([0-9]\)*.*/\1/")
else
CPP_MAJOR := $(shell $(CPP) -dumpversion >&1 | cut -b1)
CPP_MINOR := $(shell $(CPP) -dumpversion >&1 | cut -b3)
endif
# Clang || GCC >= 4
ifeq "$(shell expr $(IS_CLANG) \| $(CPP_MAJOR) \>= 4)" "1"
CFLAGS += $(C_GCC4_FLAGS)
CPPFLAGS += $(CPP_GCC4_FLAGS)
endif
# Clang >= 3 || GCC >= 4.7
ifeq "$(shell expr $(IS_CLANG) \& $(CPP_MAJOR) \>= 3 \| $(CPP_MAJOR) \>= 4 \& $(CPP_MINOR) \>= 7)" "1"
CFLAGS += -Wno-delete-non-virtual-dtor
endif
# OS is Linux and not using clang
ifeq "$(shell expr $(OS) \= Linux \& $(IS_CLANG) \= 0)" "1"
LINK += -static-libgcc
endif
OBJ_BIN := $(OBJECTS:%.c=$(BIN_DIR)/%.o)
# This will break if we include other Makefiles, but is fine for now. It allows
# us to make a copy of this file that uses altered paths (ie. Makefile.mine)
# or other changes without mucking up the original.
MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
$(BIN_DIR)/%.o: %.c $(BIN_DIR)/%.o: %.c
$(CPP) $(INCLUDE) $(CFLAGS) -m32 -o $@ -c $< $(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $<
all: all:
mkdir -p Release mkdir -p $(BIN_DIR)
$(MAKE) pawn_make $(MAKE) -f $(MAKEFILE_NAME) $(PROJECT)
pawn_make: $(OBJ_LINUX) $(PROJECT): $(OBJ_BIN)
$(CPP) $(INCLUDE) $(CFLAGS) -m32 $(OBJ_LINUX) $(LINK) -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) $(CPP) $(INCLUDE) $(OBJ_BIN) $(LINK) -o $(BIN_DIR)/$(BINARY)
debug:
$(MAKE) all DEBUG=true
default: all default: all
clean: clean:
rm -rf Release/*.o rm -rf $(BIN_DIR)/*.o
rm -rf Release/$(BINARY) rm -f $(BIN_DIR)/$(BINARY)

View File

@ -33,7 +33,7 @@
#if defined FREEBSD && !defined __FreeBSD__ #if defined FREEBSD && !defined __FreeBSD__
#define __FreeBSD__ #define __FreeBSD__
#endif #endif
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#include <sclinux.h> #include <sclinux.h>
#endif #endif
@ -43,7 +43,7 @@
#if defined HAVE_STDINT_H #if defined HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#else #else
#if defined __LCC__ || defined __DMC__ || defined LINUX #if defined __LCC__ || defined __DMC__ || defined LINUX || defined __APPLE__
#if defined HAVE_INTTYPES_H #if defined HAVE_INTTYPES_H
#include <inttypes.h> #include <inttypes.h>
#else #else
@ -197,7 +197,7 @@ typedef int (AMXAPI *AMX_DEBUG)(struct tagAMX *amx);
#endif #endif
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__ #if defined LINUX || defined __FreeBSD__ || defined __APPLE__
#pragma pack(1) /* structures must be packed (byte-aligned) */ #pragma pack(1) /* structures must be packed (byte-aligned) */
#elif defined MACOS && defined __MWERKS__ #elif defined MACOS && defined __MWERKS__
#pragma options align=mac68k #pragma options align=mac68k
@ -425,7 +425,7 @@ int AMXAPI amx_UTF8Put(char *string, char **endptr, int maxchars, cell value);
amx_Register((amx), amx_NativeInfo((name),(func)), 1); amx_Register((amx), amx_NativeInfo((name),(func)), 1);
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__ #if defined LINUX || defined __FreeBSD__ || defined __APPLE__
#pragma pack() /* reset default packing */ #pragma pack() /* reset default packing */
#elif defined MACOS && defined __MWERKS__ #elif defined MACOS && defined __MWERKS__
#pragma options align=reset #pragma options align=reset

View File

@ -49,7 +49,7 @@ extern "C" {
#endif #endif
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__ #if defined LINUX || defined __FreeBSD__ || defined __APPLE__
#pragma pack(1) /* structures must be packed (byte-aligned) */ #pragma pack(1) /* structures must be packed (byte-aligned) */
#elif defined MACOS && defined __MWERKS__ #elif defined MACOS && defined __MWERKS__
#pragma options align=mac68k #pragma options align=mac68k
@ -156,7 +156,7 @@ int AMXAPI dbg_GetArrayDim(AMX_DBG *amxdbg, const AMX_DBG_SYMBOL *sym, const AMX
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__ #if defined LINUX || defined __FreeBSD__ || defined __APPLE__
#pragma pack() /* reset default packing */ #pragma pack() /* reset default packing */
#elif defined MACOS && defined __MWERKS__ #elif defined MACOS && defined __MWERKS__
#pragma options align=reset #pragma options align=reset

View File

@ -30,7 +30,7 @@
#if defined PAWNC_DLL #if defined PAWNC_DLL
#ifndef __linux__ #if !defined(__linux__) && !defined(__APPLE__)
#include "dllmain.c" #include "dllmain.c"
#endif #endif
@ -39,9 +39,6 @@
# define UNUSED_PARAM(p) ((void)(p)) # define UNUSED_PARAM(p) ((void)(p))
# endif # endif
static char *argv[MAX_ARGS];
static int argc;
#if PAWN_CELL_SIZE==32 #if PAWN_CELL_SIZE==32
#define EXCOMPILER Compile32 #define EXCOMPILER Compile32
#else #else

View File

@ -10,6 +10,7 @@ memfile_t *memfile_creat(const char *name, size_t init)
mf.size = init; mf.size = init;
mf.base = (char *)malloc(init); mf.base = (char *)malloc(init);
mf.usedoffs = 0; mf.usedoffs = 0;
mf.name = NULL;
if (!mf.base) if (!mf.base)
{ {
return NULL; return NULL;

View File

@ -9,7 +9,7 @@
#endif #endif
#endif #endif
#include <malloc.h> #include <stdlib.h>
typedef struct memfile_s typedef struct memfile_s
{ {

View File

@ -41,6 +41,10 @@
#include <endian.h> #include <endian.h>
#endif #endif
#if defined __APPLE__
#include <sys/types.h>
#endif
/* Linux NOW has these */ /* Linux NOW has these */
#if !defined BIG_ENDIAN #if !defined BIG_ENDIAN
#define BIG_ENDIAN 4321 #define BIG_ENDIAN 4321

View File

@ -63,7 +63,7 @@
#define PREPROC_TERM '\x7f'/* termination character for preprocessor expressions (the "DEL" code) */ #define PREPROC_TERM '\x7f'/* termination character for preprocessor expressions (the "DEL" code) */
#define sDEF_PREFIX "default.inc" /* default prefix filename */ #define sDEF_PREFIX "default.inc" /* default prefix filename */
#if defined WIN32 #if defined WIN32 || defined __clang__
#define INVISIBLE #define INVISIBLE
#else #else
#define INVISIBLE __attribute__((visibility("protected"))) #define INVISIBLE __attribute__((visibility("protected")))

View File

@ -35,9 +35,10 @@
#include <io.h> #include <io.h>
#endif #endif
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#include <sclinux.h> #include <sclinux.h>
#include <prefix.h> /* from BinReloc, see www.autopackage.org */ #include <prefix.h> /* from BinReloc, see www.autopackage.org */
#include <unistd.h>
#endif #endif
#if defined FORTIFY #if defined FORTIFY
@ -421,7 +422,7 @@ int pc_compile(int argc, char *argv[])
void *inpfmark; void *inpfmark;
int lcl_packstr,lcl_needsemicolon,lcl_tabsize; int lcl_packstr,lcl_needsemicolon,lcl_tabsize;
#if !defined SC_LIGHT #if !defined SC_LIGHT
int hdrsize; int hdrsize=0;
#endif #endif
/* set global variables to their initial value */ /* set global variables to their initial value */
@ -1248,9 +1249,9 @@ static void setconfig(char *root)
/* add the default "include" directory */ /* add the default "include" directory */
#if defined __WIN32__ || defined _WIN32 #if defined __WIN32__ || defined _WIN32
GetModuleFileName(NULL,path,_MAX_PATH); GetModuleFileName(NULL,path,_MAX_PATH);
#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
/* see www.autopackage.org for the BinReloc module */ /* see www.autopackage.org for the BinReloc module */
ptr = SELFPATH; ptr = (char *)SELFPATH;
if (!ptr) if (!ptr)
ptr = root; ptr = root;
strncpy(path,ptr,sizeof path); strncpy(path,ptr,sizeof path);
@ -1922,7 +1923,7 @@ static int declloc(int fstatic)
int dim[sDIMEN_MAX]; int dim[sDIMEN_MAX];
int numdim; int numdim;
int fconst; int fconst;
int staging_start; int staging_start=0;
fconst=matchtoken(tCONST); fconst=matchtoken(tCONST);
do { do {
@ -1948,7 +1949,7 @@ static int declloc(int fstatic)
* level might indicate a bug. * level might indicate a bug.
* NOTE - don't bother with the error if there's no valid function! * NOTE - don't bother with the error if there's no valid function!
*/ */
if ((sym=findloc(name))!=NULL && sym->compound!=nestlevel || findglb(name)!=NULL) if (((sym=findloc(name))!=NULL && sym->compound!=nestlevel) || findglb(name)!=NULL)
if (curfunc!=NULL && (curfunc->usage & uNATIVE)) if (curfunc!=NULL && (curfunc->usage & uNATIVE))
error(219,name); /* variable shadows another symbol */ error(219,name); /* variable shadows another symbol */
while (matchtoken('[')){ while (matchtoken('[')){
@ -2863,7 +2864,7 @@ static int operatoradjust(int opertok,symbol *sym,char *opername,int resulttag)
error(62); /* number or placement of the operands does not fit the operator */ error(62); /* number or placement of the operands does not fit the operator */
} /* switch */ } /* switch */
if (tags[0]==0 && (opertok!='=' && tags[1]==0 || opertok=='=' && resulttag==0)) if (tags[0]==0 && ((opertok!='=' && tags[1]==0) || (opertok=='=' && resulttag==0)))
error(64); /* cannot change predefined operators */ error(64); /* cannot change predefined operators */
/* change the operator name */ /* change the operator name */
@ -3045,7 +3046,7 @@ static void funcstub(int native)
tok=lex(&val,&str); tok=lex(&val,&str);
if (native) { if (native) {
if (tok==tPUBLIC || tok==tSTOCK || tok==tSTATIC || tok==tSYMBOL && *str==PUBLIC_CHAR) if (tok==tPUBLIC || tok==tSTOCK || tok==tSTATIC || (tok==tSYMBOL && *str==PUBLIC_CHAR))
error(42); /* invalid combination of class specifiers */ error(42); /* invalid combination of class specifiers */
} else { } else {
if (tok==tPUBLIC || tok==tSTOCK || tok==tSTATIC) if (tok==tPUBLIC || tok==tSTOCK || tok==tSTATIC)
@ -3166,7 +3167,7 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc
tag= (firsttag>=0) ? firsttag : pc_addtag(NULL); tag= (firsttag>=0) ? firsttag : pc_addtag(NULL);
tok=lex(&val,&str); tok=lex(&val,&str);
assert(!fpublic); assert(!fpublic);
if (tok==tNATIVE || tok==tPUBLIC && stock) if (tok==tNATIVE || (tok==tPUBLIC && stock))
error(42); /* invalid combination of class specifiers */ error(42); /* invalid combination of class specifiers */
if (tok==tOPERATOR) { if (tok==tOPERATOR) {
opertok=operatorname(symbolname); opertok=operatorname(symbolname);
@ -3512,7 +3513,7 @@ static int declargs(symbol *sym)
error(10); /* illegal function or declaration */ error(10); /* illegal function or declaration */
} /* switch */ } /* switch */
} while (tok=='&' || tok==tLABEL || tok==tCONST } while (tok=='&' || tok==tLABEL || tok==tCONST
|| tok!=tELLIPS && matchtoken(',')); /* more? */ || (tok!=tELLIPS && matchtoken(','))); /* more? */
/* if the next token is not ",", it should be ")" */ /* if the next token is not ",", it should be ")" */
needtoken(')'); needtoken(')');
} /* if */ } /* if */
@ -3873,7 +3874,7 @@ static void make_report(symbol *root,FILE *log,char *sourcefile)
continue; continue;
if ((sym->usage & uREAD)==0) if ((sym->usage & uREAD)==0)
continue; continue;
fprintf(log,"\t\t<member name=\"T:%s\" value=\"%ld\">\n",funcdisplayname(symname,sym->name),sym->addr); fprintf(log,"\t\t<member name=\"T:%s\" value=\"%ld\">\n",funcdisplayname(symname,sym->name),(long)sym->addr);
if (sym->tag!=0) { if (sym->tag!=0) {
tagsym=find_tag_byval(sym->tag); tagsym=find_tag_byval(sym->tag);
assert(tagsym!=NULL); assert(tagsym!=NULL);
@ -3883,7 +3884,7 @@ static void make_report(symbol *root,FILE *log,char *sourcefile)
if ((enumroot=sym->dim.enumlist)!=NULL) { if ((enumroot=sym->dim.enumlist)!=NULL) {
enumroot=enumroot->next; /* skip root */ enumroot=enumroot->next; /* skip root */
while (enumroot!=NULL) { while (enumroot!=NULL) {
fprintf(log,"\t\t\t<member name=\"C:%s\" value=\"%ld\">\n",funcdisplayname(symname,enumroot->name),enumroot->value); fprintf(log,"\t\t\t<member name=\"C:%s\" value=\"%ld\">\n",funcdisplayname(symname,enumroot->name),(long)enumroot->value);
/* find the constant with this name and get the tag */ /* find the constant with this name and get the tag */
ref=findglb(enumroot->name); ref=findglb(enumroot->name);
if (ref!=NULL) { if (ref!=NULL) {
@ -3919,7 +3920,7 @@ static void make_report(symbol *root,FILE *log,char *sourcefile)
continue; continue;
if ((sym->usage & uREAD)==0 || (sym->usage & (uENUMFIELD | uENUMROOT))!=0) if ((sym->usage & uREAD)==0 || (sym->usage & (uENUMFIELD | uENUMROOT))!=0)
continue; continue;
fprintf(log,"\t\t<member name=\"C:%s\" value=\"%ld\">\n",funcdisplayname(symname,sym->name),sym->addr); fprintf(log,"\t\t<member name=\"C:%s\" value=\"%ld\">\n",funcdisplayname(symname,sym->name),(long)sym->addr);
if (sym->tag!=0) { if (sym->tag!=0) {
tagsym=find_tag_byval(sym->tag); tagsym=find_tag_byval(sym->tag);
assert(tagsym!=NULL); assert(tagsym!=NULL);
@ -4039,7 +4040,7 @@ static void make_report(symbol *root,FILE *log,char *sourcefile)
for (arg=0; sym->dim.arglist[arg].ident!=0; arg++) { for (arg=0; sym->dim.arglist[arg].ident!=0; arg++) {
int dim,paraminfo; int dim,paraminfo;
char *outer_start,*inner_start; char *outer_start,*inner_start;
int outer_length,inner_length; int outer_length=0,inner_length=0;
if (sym->dim.arglist[arg].ident==iVARARGS) if (sym->dim.arglist[arg].ident==iVARARGS)
fprintf(log,"\t\t\t<param name=\"...\">\n"); fprintf(log,"\t\t\t<param name=\"...\">\n");
else else
@ -5248,7 +5249,7 @@ static void doreturn(void)
if ((rettype & uRETVALUE)!=0) { if ((rettype & uRETVALUE)!=0) {
int retarray=(ident==iARRAY || ident==iREFARRAY); int retarray=(ident==iARRAY || ident==iREFARRAY);
/* there was an earlier "return" statement in this function */ /* there was an earlier "return" statement in this function */
if (sub==NULL && retarray || sub!=NULL && !retarray) if ((sub==NULL && retarray) || (sub!=NULL && !retarray))
error(79); /* mixing "return array;" and "return value;" */ error(79); /* mixing "return array;" and "return value;" */
} /* if */ } /* if */
rettype|=uRETVALUE; /* function returns a value */ rettype|=uRETVALUE; /* function returns a value */
@ -5257,7 +5258,7 @@ static void doreturn(void)
if (!matchtag(curfunc->tag,tag,TRUE)) if (!matchtag(curfunc->tag,tag,TRUE))
error(213); /* tagname mismatch */ error(213); /* tagname mismatch */
if (ident==iARRAY || ident==iREFARRAY) { if (ident==iARRAY || ident==iREFARRAY) {
int dim[sDIMEN_MAX],numdim; int dim[sDIMEN_MAX],numdim=0;
cell arraysize; cell arraysize;
assert(sym!=NULL); assert(sym!=NULL);
if (sub!=NULL) { if (sub!=NULL) {

View File

@ -27,7 +27,7 @@
#include <ctype.h> #include <ctype.h>
#include <math.h> #include <math.h>
#include "sc.h" #include "sc.h"
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#include <sclinux.h> #include <sclinux.h>
#endif #endif
@ -198,7 +198,7 @@ SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths)
char path[_MAX_PATH]; char path[_MAX_PATH];
strncpy(path,ptr,sizeof path); strncpy(path,ptr,sizeof path);
path[sizeof path - 1]='\0'; /* force '\0' termination */ path[sizeof path - 1]='\0'; /* force '\0' termination */
strncat(path,name,sizeof(path)-strlen(path)); strncat(path,name,sizeof(path) - strlen(path) - 1);
path[sizeof path - 1]='\0'; path[sizeof path - 1]='\0';
result=plungequalifiedfile(path); result=plungequalifiedfile(path);
} /* while */ } /* while */
@ -408,7 +408,7 @@ static void stripcom(unsigned char *line)
#if !defined SC_LIGHT #if !defined SC_LIGHT
/* collect the comment characters in a string */ /* collect the comment characters in a string */
if (icomment==2) { if (icomment==2) {
if (skipstar && (*line!='\0' && *line<=' ' || *line=='*')) { if (skipstar && ((*line!='\0' && *line<=' ') || *line=='*')) {
/* ignore leading whitespace and '*' characters */ /* ignore leading whitespace and '*' characters */
} else if (commentidx<COMMENT_LIMIT+COMMENT_MARGIN-1) { } else if (commentidx<COMMENT_LIMIT+COMMENT_MARGIN-1) {
comment[commentidx++]=(char)((*line!='\n') ? *line : ' '); comment[commentidx++]=(char)((*line!='\n') ? *line : ' ');
@ -585,22 +585,9 @@ static int htoi(cell *val,const unsigned char *curptr)
} }
#if defined __GNUC__ #if defined __GNUC__
static double pow10(int value) static double pow10(double d)
{ {
double res=1.0; return pow(10, d);
while (value>=4) {
res*=10000.0;
value-=5;
} /* while */
while (value>=2) {
res*=100.0;
value-=2;
} /* while */
while (value>=1) {
res*=10.0;
value-=1;
} /* while */
return res;
} }
#endif #endif
@ -1210,7 +1197,7 @@ static int command(void)
sym=findloc(str); sym=findloc(str);
if (sym==NULL) if (sym==NULL)
sym=findglb(str); sym=findglb(str);
if (sym==NULL || sym->ident!=iFUNCTN && sym->ident!=iREFFUNC && (sym->usage & uDEFINE)==0) { if (sym==NULL || (sym->ident!=iFUNCTN && sym->ident!=iREFFUNC && (sym->usage & uDEFINE)==0)) {
error(17,str); /* undefined symbol */ error(17,str); /* undefined symbol */
} else { } else {
outval(sym->addr,FALSE); outval(sym->addr,FALSE);
@ -1644,7 +1631,7 @@ static void substallpatterns(unsigned char *line,int buffersize)
if (strncmp((char*)start,"defined",7)==0 && !isalpha((char)*(start+7))) { if (strncmp((char*)start,"defined",7)==0 && !isalpha((char)*(start+7))) {
start+=7; /* skip "defined" */ start+=7; /* skip "defined" */
/* skip white space & parantheses */ /* skip white space & parantheses */
while (*start<=' ' && *start!='\0' || *start=='(') while ((*start<=' ' && *start!='\0') || *start=='(')
start++; start++;
/* skip the symbol behind it */ /* skip the symbol behind it */
while (isalpha(*start) || isdigit(*start) || *start=='_') while (isalpha(*start) || isdigit(*start) || *start=='_')
@ -1946,7 +1933,7 @@ SC_FUNC int lex(cell *lexvalue,char **lexsym)
error(220); error(220);
} /* if */ } /* if */
} /* if */ } /* if */
} else if (*lptr=='\"' || *lptr==sc_ctrlchar && *(lptr+1)=='\"') } else if (*lptr=='\"' || (*lptr==sc_ctrlchar && *(lptr+1)=='\"'))
{ /* unpacked string literal */ { /* unpacked string literal */
_lextok=tSTRING; _lextok=tSTRING;
stringflags= (*lptr==sc_ctrlchar) ? RAWMODE : 0; stringflags= (*lptr==sc_ctrlchar) ? RAWMODE : 0;
@ -1959,9 +1946,9 @@ SC_FUNC int lex(cell *lexvalue,char **lexsym)
lptr+=1; /* skip final quote */ lptr+=1; /* skip final quote */
else else
error(37); /* invalid (non-terminated) string */ error(37); /* invalid (non-terminated) string */
} else if (*lptr=='!' && *(lptr+1)=='\"' } else if ((*lptr=='!' && *(lptr+1)=='\"')
|| *lptr=='!' && *(lptr+1)==sc_ctrlchar && *(lptr+2)=='\"' || (*lptr=='!' && *(lptr+1)==sc_ctrlchar && *(lptr+2)=='\"')
|| *lptr==sc_ctrlchar && *(lptr+1)=='!' && *(lptr+2)=='\"') || (*lptr==sc_ctrlchar && *(lptr+1)=='!' && *(lptr+2)=='\"'))
{ /* packed string literal */ { /* packed string literal */
_lextok=tSTRING; _lextok=tSTRING;
stringflags= (*lptr==sc_ctrlchar || *(lptr+1)==sc_ctrlchar) ? RAWMODE : 0; stringflags= (*lptr==sc_ctrlchar || *(lptr+1)==sc_ctrlchar) ? RAWMODE : 0;
@ -2053,7 +2040,7 @@ SC_FUNC int matchtoken(int token)
int tok; int tok;
tok=lex(&val,&str); tok=lex(&val,&str);
if (tok==token || token==tTERM && (tok==';' || tok==tENDEXPR)) { if (tok==token || (token==tTERM && (tok==';' || tok==tENDEXPR))) {
return 1; return 1;
} else if (!sc_needsemicolon && token==tTERM && (_lexnewline || !freading)) { } else if (!sc_needsemicolon && token==tTERM && (_lexnewline || !freading)) {
/* Push "tok" back, because it is the token following the implicit statement /* Push "tok" back, because it is the token following the implicit statement
@ -2418,7 +2405,7 @@ SC_FUNC void delete_symbols(symbol *root,int level,int delete_labels,int delete_
{ {
symbol *sym,*parent_sym; symbol *sym,*parent_sym;
constvalue *stateptr; constvalue *stateptr;
int mustdelete; int mustdelete=0;
/* erase only the symbols with a deeper nesting level than the /* erase only the symbols with a deeper nesting level than the
* specified nesting level */ * specified nesting level */

View File

@ -929,7 +929,7 @@ static int hier14(value *lval1)
} /* if */ } /* if */
if (lval3.sym->dim.array.level!=level) if (lval3.sym->dim.array.level!=level)
return error(48); /* array dimensions must match */ return error(48); /* array dimensions must match */
else if (ltlength<val || exactmatch && ltlength>val || val==0) else if (ltlength<val || (exactmatch && ltlength>val) || val==0)
return error(47); /* array sizes must match */ return error(47); /* array sizes must match */
else if (lval3.ident!=iARRAYCELL && !matchtag(lval3.sym->x.idxtag,idxtag,TRUE)) else if (lval3.ident!=iARRAYCELL && !matchtag(lval3.sym->x.idxtag,idxtag,TRUE))
error(229,(lval2.sym!=NULL) ? lval2.sym->name : lval3.sym->name); /* index tag mismatch */ error(229,(lval2.sym!=NULL) ? lval2.sym->name : lval3.sym->name); /* index tag mismatch */
@ -1124,7 +1124,7 @@ static int hier2(value *lval)
int tag,paranthese; int tag,paranthese;
cell val; cell val;
char *st; char *st;
symbol *sym; symbol *sym=NULL;
int saveresult; int saveresult;
tok=lex(&val,&st); tok=lex(&val,&st);
@ -1247,7 +1247,7 @@ static int hier2(value *lval)
lval->constval=1; /* preset */ lval->constval=1; /* preset */
if (sym->ident==iARRAY || sym->ident==iREFARRAY) { if (sym->ident==iARRAY || sym->ident==iREFARRAY) {
int level; int level;
symbol *idxsym; symbol *idxsym=NULL;
for (level=0; matchtoken('['); level++) { for (level=0; matchtoken('['); level++) {
idxsym=NULL; idxsym=NULL;
if (level==sym->dim.array.level && matchtoken(tSYMBOL)) { if (level==sym->dim.array.level && matchtoken(tSYMBOL)) {
@ -1293,7 +1293,7 @@ static int hier2(value *lval)
} /* if */ } /* if */
if (sym->ident==iARRAY || sym->ident==iREFARRAY) { if (sym->ident==iARRAY || sym->ident==iREFARRAY) {
int level; int level;
symbol *idxsym; symbol *idxsym=NULL;
for (level=0; matchtoken('['); level++) { for (level=0; matchtoken('['); level++) {
idxsym=NULL; idxsym=NULL;
if (level==sym->dim.array.level && matchtoken(tSYMBOL)) { if (level==sym->dim.array.level && matchtoken(tSYMBOL)) {
@ -1462,7 +1462,7 @@ restart:
} /* if */ } /* if */
if (close==']') { if (close==']') {
/* normal array index */ /* normal array index */
if (lval2.constval<0 || sym->dim.array.length!=0 && sym->dim.array.length<=lval2.constval) if (lval2.constval<0 || (sym->dim.array.length!=0 && sym->dim.array.length<=lval2.constval))
error(32,sym->name); /* array index out of bounds */ error(32,sym->name); /* array index out of bounds */
if (lval2.constval!=0) { if (lval2.constval!=0) {
/* don't add offsets for zero subscripts */ /* don't add offsets for zero subscripts */
@ -1479,8 +1479,8 @@ restart:
} /* if */ } /* if */
} else { } else {
/* character index */ /* character index */
if (lval2.constval<0 || sym->dim.array.length!=0 if (lval2.constval<0 || (sym->dim.array.length!=0
&& sym->dim.array.length*((8*sizeof(cell))/sCHARBITS)<=(ucell)lval2.constval) && sym->dim.array.length*((8*sizeof(cell))/sCHARBITS)<=(ucell)lval2.constval))
error(32,sym->name); /* array index out of bounds */ error(32,sym->name); /* array index out of bounds */
if (lval2.constval!=0) { if (lval2.constval!=0) {
/* don't add offsets for zero subscripts */ /* don't add offsets for zero subscripts */
@ -2035,8 +2035,8 @@ static int nesting=0;
* function argument; a literal string may be smaller than * function argument; a literal string may be smaller than
* the function argument. * the function argument.
*/ */
if (lval.constval>0 && arg[argidx].dim[0]!=lval.constval if ((lval.constval>0 && arg[argidx].dim[0]!=lval.constval)
|| lval.constval<0 && arg[argidx].dim[0] < -lval.constval) || (lval.constval<0 && arg[argidx].dim[0] < -lval.constval))
error(47); /* array sizes must match */ error(47); /* array sizes must match */
} /* if */ } /* if */
} /* if */ } /* if */

View File

@ -235,7 +235,7 @@ SC_FUNC void begdseg(void)
SC_FUNC void setline(int chkbounds) SC_FUNC void setline(int chkbounds)
{ {
if ((sc_debug & sSYMBOLIC)!=0 || chkbounds && (sc_debug & sCHKBOUNDS)!=0) { if ((sc_debug & sSYMBOLIC)!=0 || (chkbounds && (sc_debug & sCHKBOUNDS)!=0)) {
/* generate a "break" (start statement) opcode rather than a "line" opcode /* generate a "break" (start statement) opcode rather than a "line" opcode
* because earlier versions of Small/Pawn have an incompatible version of the * because earlier versions of Small/Pawn have an incompatible version of the
* line opcode * line opcode
@ -719,7 +719,7 @@ SC_FUNC void ffcall(symbol *sym,const char *label,int numargs)
stgwrite(sym->name); stgwrite(sym->name);
} /* if */ } /* if */
if (sc_asmfile if (sc_asmfile
&& (label!=NULL || !isalpha(sym->name[0]) && sym->name[0]!='_' && sym->name[0]!=sc_ctrlchar)) && (label!=NULL || (!isalpha(sym->name[0]) && sym->name[0]!='_' && sym->name[0]!=sc_ctrlchar)))
{ {
stgwrite("\t; "); stgwrite("\t; ");
stgwrite(symname); stgwrite(symname);

View File

@ -25,7 +25,7 @@
#if defined __WIN32__ || defined _WIN32 || defined __MSDOS__ #if defined __WIN32__ || defined _WIN32 || defined __MSDOS__
#include <io.h> #include <io.h>
#endif #endif
#if defined LINUX || defined __GNUC__ #if defined LINUX || defined __APPLE__ || defined __GNUC__
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <stdio.h> #include <stdio.h>
@ -132,7 +132,7 @@ static short lastfile;
} /* if */ } /* if */
va_end(argptr); va_end(argptr);
if (number>=100 && number<200 || errnum>25){ if ((number>=100 && number<200) || errnum>25){
if (strlen(errfname)==0) { if (strlen(errfname)==0) {
va_start(argptr,number); va_start(argptr,number);
pc_error(0,"\nCompilation aborted.",NULL,0,0,argptr); pc_error(0,"\nCompilation aborted.",NULL,0,0,argptr);

View File

@ -30,7 +30,7 @@
#endif #endif
#include "sc.h" #include "sc.h"
#include "amxdbg.h" #include "amxdbg.h"
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#include <sclinux.h> #include <sclinux.h>
#endif #endif
@ -895,7 +895,7 @@ SC_FUNC int assemble(FILE *fout,FILE *fin)
instr=skipwhitespace(line); instr=skipwhitespace(line);
/* ignore empty lines and labels (labels have a special syntax, so these /* ignore empty lines and labels (labels have a special syntax, so these
* must be parsed separately) */ * must be parsed separately) */
if (*instr=='\0' || tolower(*instr)=='l' && *(instr+1)=='.') if (*instr=='\0' || (tolower(*instr)=='l' && *(instr+1)=='.'))
continue; continue;
/* get to the end of the instruction (make use of the '\n' that fgets() /* get to the end of the instruction (make use of the '\n' that fgets()
* added at the end of the line; this way we will *always* drop on a * added at the end of the line; this way we will *always* drop on a

View File

@ -457,18 +457,18 @@ static int matchsequence(char *start,char *end,char *pattern,
case ' ': case ' ':
if (*start!='\t' && *start!=' ') if (*start!='\t' && *start!=' ')
return FALSE; return FALSE;
while (start<end && *start=='\t' || *start==' ') while ((start<end && *start=='\t') || *start==' ')
start++; start++;
break; break;
case '!': case '!':
while (start<end && *start=='\t' || *start==' ') while ((start<end && *start=='\t') || *start==' ')
start++; /* skip trailing white space */ start++; /* skip trailing white space */
if (*start!='\n') if (*start!='\n')
return FALSE; return FALSE;
assert(*(start+1)=='\0'); assert(*(start+1)=='\0');
start+=2; /* skip '\n' and '\0' */ start+=2; /* skip '\n' and '\0' */
if (*(pattern+1)!='\0') if (*(pattern+1)!='\0')
while (start<end && *start=='\t' || *start==' ') while ((start<end && *start=='\t') || *start==' ')
start++; /* skip leading white space of next instruction */ start++; /* skip leading white space of next instruction */
break; break;
default: default:

View File

@ -47,7 +47,7 @@
#define _MAX_PATH 250 #define _MAX_PATH 250
#endif #endif
#if !defined DIRSEP_CHAR #if !defined DIRSEP_CHAR
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE___
#define DIRSEP_CHAR '/' #define DIRSEP_CHAR '/'
#elif defined macintosh #elif defined macintosh
#define DIRSEP_CHAR ':' #define DIRSEP_CHAR ':'
@ -339,7 +339,7 @@ SC_FUNC cell get_utf8_char(const unsigned char *string,const unsigned char **end
/* the code positions 0xd800--0xdfff and 0xfffe & 0xffff do not /* the code positions 0xd800--0xdfff and 0xfffe & 0xffff do not
* exist in UCS-4 (and hence, they do not exist in Unicode) * exist in UCS-4 (and hence, they do not exist in Unicode)
*/ */
if (result>=0xd800 && result<=0xdfff || result==0xfffe || result==0xffff) if ((result>=0xd800 && result<=0xdfff) || result==0xfffe || result==0xffff)
return -1; return -1;
} /* if */ } /* if */
break; break;

View File

@ -32,6 +32,10 @@
*/ */
#if !defined __BYTE_ORDER #if !defined __BYTE_ORDER
# include <stdlib.h> # include <stdlib.h>
# if defined __APPLE__
# include <sys/types.h>
# define __BYTE_ORDER BYTE_ORDER
# endif
#endif #endif
#if defined __OpenBSD__ || defined __FreeBSD__ #if defined __OpenBSD__ || defined __FreeBSD__

View File

@ -238,7 +238,7 @@ SC_FUNC stringlist *insert_path(char *path)
{ {
char *extra_path = malloc(strlen(path) + 16); char *extra_path = malloc(strlen(path) + 16);
strcpy(extra_path, path); strcpy(extra_path, path);
#if defined __linux__ #if defined __linux__ || defined __APPLE__
strcat(extra_path, "/amxmod_compat/"); strcat(extra_path, "/amxmod_compat/");
#elif defined WIN32 || defined _WIN32 #elif defined WIN32 || defined _WIN32
strcat(extra_path, "\\amxmod_compat\\"); strcat(extra_path, "\\amxmod_compat\\");
@ -444,10 +444,10 @@ SC_FUNC stringlist *insert_dbgsymbol(symbol *sym)
/* address tag:name codestart codeend ident vclass [tag:dim ...] */ /* address tag:name codestart codeend ident vclass [tag:dim ...] */
#if PAWN_CELL_SIZE==32 #if PAWN_CELL_SIZE==32
if (sym->ident==iFUNCTN) if (sym->ident==iFUNCTN)
sprintf(string,"S:%08lx %x:%s %08lx %08lx %x %x",sym->addr,sym->tag, sprintf(string,"S:%08x %x:%s %08x %08x %x %x",sym->addr,sym->tag,
symname,sym->addr,sym->codeaddr,sym->ident,sym->vclass); symname,sym->addr,sym->codeaddr,sym->ident,sym->vclass);
else else
sprintf(string,"S:%08lx %x:%s %08lx %08lx %x %x",sym->addr,sym->tag, sprintf(string,"S:%08x %x:%s %08x %08x %x %x",sym->addr,sym->tag,
symname,sym->codeaddr,code_idx,sym->ident,sym->vclass); symname,sym->codeaddr,code_idx,sym->ident,sym->vclass);
#elif PAWN_CELL_SIZE==64 #elif PAWN_CELL_SIZE==64
if (sym->ident==iFUNCTN) if (sym->ident==iFUNCTN)

View File

@ -51,7 +51,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "sc.h" #include "sc.h"
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ #if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#include <sclinux.h> #include <sclinux.h>
#endif #endif

View File

@ -261,6 +261,116 @@
cstrike_item_candrop 63 cstrike_item_candrop 63
cstrike_item_getmaxspeed 78 cstrike_item_getmaxspeed 78
@end @end
@section cstrike mac
pev 4
base 0x0
spawn 0
precache 1
keyvalue 3
objectcaps 6
activate 7
setobjectcollisionbox 8
classify 9
deathnotice 10
traceattack 11
takedamage 12
takehealth 13
killed 14
bloodcolor 15
tracebleed 16
istriggered 17
mymonsterpointer 18
mysquadmonsterpointer 19
gettogglestate 20
addpoints 21
addpointstoteam 22
addplayeritem 23
removeplayeritem 24
giveammo 25
getdelay 26
ismoving 27
overridereset 28
damagedecal 29
settogglestate 30
startsneaking 31
stopsneaking 32
oncontrols 33
issneaking 34
isalive 35
isbspmodel 36
reflectgauss 37
hastarget 38
isinworld 39
isplayer 40
isnetclient 41
teamid 42
getnexttarget 43
think 44
touch 45
use 46
blocked 47
respawn 48
updateowner 49
fbecomeprone 50
center 51
eyeposition 52
earposition 53
bodytarget 54
illumination 55
fvisible 56
fvecvisible 57
player_jump 76
player_duck 77
player_prethink 78
player_postthink 79
player_getgunposition 80
player_shouldfadeondeath 66
player_impulsecommands 83
player_updateclientdata 82
item_addtoplayer 59
item_addduplicate 60
item_getiteminfo 61
item_candeploy 62
item_deploy 64
item_canholster 66
item_holster 67
item_updateiteminfo 68
item_preframe 69
item_postframe 70
item_drop 71
item_kill 72
item_attachtoplayer 73
item_primaryammoindex 74
item_secondaryammoindex 75
item_updateclientdata 76
item_getweaponptr 77
item_itemslot 79
weapon_extractammo 80
weapon_extractclipammo 81
weapon_addweapon 82
weapon_playemptysound 83
weapon_resetemptysound 84
weapon_sendweaponanim 85
weapon_isusable 86
weapon_primaryattack 87
weapon_secondaryattack 88
weapon_reload 89
weapon_weaponidle 90
weapon_retireweapon 91
weapon_shouldweaponidle 92
weapon_usedecrement 93
cstrike_restart 2
cstrike_roundrespawn 84
cstrike_item_candrop 63
cstrike_item_getmaxspeed 78
@end
@section dod linux @section dod linux
pev 0 pev 0
base 0x154 base 0x154
@ -1747,8 +1857,112 @@
weapon_retireweapon 87 weapon_retireweapon 87
weapon_shouldweaponidle 88 weapon_shouldweaponidle 88
weapon_usedecrement 89 weapon_usedecrement 89
@end @end
@section valve mac
pev 4
base 0x0
spawn 0
precache 1
keyvalue 2
objectcaps 5
activate 6
setobjectcollisionbox 7
classify 8
deathnotice 9
traceattack 10
takedamage 11
takehealth 12
killed 13
bloodcolor 14
tracebleed 15
istriggered 16
mymonsterpointer 17
mysquadmonsterpointer 18
gettogglestate 19
addpoints 20
addpointstoteam 21
addplayeritem 22
removeplayeritem 23
giveammo 24
getdelay 25
ismoving 26
overridereset 27
damagedecal 28
settogglestate 29
startsneaking 30
stopsneaking 31
oncontrols 32
issneaking 33
isalive 34
isbspmodel 35
reflectgauss 36
hastarget 37
isinworld 38
isplayer 39
isnetclient 40
teamid 41
getnexttarget 42
think 43
touch 44
use 45
blocked 46
respawn 47
updateowner 48
fbecomeprone 49
center 50
eyeposition 51
earposition 52
bodytarget 53
illumination 54
fvisible 55
fvecvisible 56
player_jump 125
player_duck 126
player_prethink 127
player_postthink 128
player_getgunposition 119
player_shouldfadeondeath 60
player_impulsecommands 130
player_updateclientdata 129
item_addtoplayer 58
item_addduplicate 59
item_getiteminfo 60
item_candeploy 61
item_deploy 62
item_canholster 63
item_holster 64
item_updateiteminfo 65
item_preframe 66
item_postframe 67
item_drop 68
item_kill 69
item_attachtoplayer 70
item_primaryammoindex 71
item_secondaryammoindex 72
item_updateclientdata 73
item_getweaponptr 74
item_itemslot 75
weapon_extractammo 76
weapon_extractclipammo 77
weapon_addweapon 78
weapon_playemptysound 79
weapon_resetemptysound 80
weapon_sendweaponanim 81
weapon_isusable 82
weapon_primaryattack 83
weapon_secondaryattack 84
weapon_reload 85
weapon_weaponidle 86
weapon_retireweapon 87
weapon_shouldweaponidle 88
weapon_usedecrement 89
@end
; Sven-Coop has no linux binaries. This makes disassembly much harder. ; Sven-Coop has no linux binaries. This makes disassembly much harder.
; These offsets were contributed by ts2do ; These offsets were contributed by ts2do
@section SvenCoop windows @section SvenCoop windows

View File

@ -1,10 +1,14 @@
#include <assert.h> #include <assert.h>
#include <malloc.h> #include <stdlib.h>
#include "cstrike.h" #include "cstrike.h"
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
#include <sys/mman.h> #include <sys/mman.h>
#define PAGE_EXECUTE_READWRITE PROT_READ|PROT_WRITE|PROT_EXEC #define PAGE_EXECUTE_READWRITE PROT_READ|PROT_WRITE|PROT_EXEC
#if defined(__linux)
#include <malloc.h>
#endif
#endif #endif
/* Utils */ /* Utils */
@ -65,7 +69,7 @@ void CtrlDetour_ClientCommand(bool set)
if (!g_UseBotArgs) if (!g_UseBotArgs)
{ {
#if defined __linux__ #if defined(__linux__) || defined(__APPLE__)
/* Find the DLL */ /* Find the DLL */
char dll[256]; char dll[256];
if (!UTIL_GetLibraryOfAddress(target, dll, sizeof(dll))) if (!UTIL_GetLibraryOfAddress(target, dll, sizeof(dll)))
@ -142,8 +146,12 @@ unsigned char *UTIL_CodeAlloc(size_t size)
{ {
#if defined WIN32 #if defined WIN32
return (unsigned char *)VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); return (unsigned char *)VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
#elif defined __GNUC__
#if defined __APPLE__
unsigned char *addr = (unsigned char *)valloc(size);
#else #else
unsigned char *addr = (unsigned char *)memalign(sysconf(_SC_PAGESIZE), size); unsigned char *addr = (unsigned char *)memalign(sysconf(_SC_PAGESIZE), size);
#endif
mprotect(addr, size, PROT_READ|PROT_WRITE|PROT_EXEC); mprotect(addr, size, PROT_READ|PROT_WRITE|PROT_EXEC);
return addr; return addr;
#endif #endif
@ -160,7 +168,7 @@ void UTIL_CodeFree(unsigned char *addr)
void UTIL_MemProtect(void *addr, int length, int prot) void UTIL_MemProtect(void *addr, int length, int prot)
{ {
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
#define ALIGN(ar) ((long)ar & ~(sysconf(_SC_PAGESIZE)-1)) #define ALIGN(ar) ((long)ar & ~(sysconf(_SC_PAGESIZE)-1))
void *addr2 = (void *)ALIGN(addr); void *addr2 = (void *)ALIGN(addr);
mprotect(addr2, sysconf(_SC_PAGESIZE), prot); mprotect(addr2, sysconf(_SC_PAGESIZE), prot);
@ -172,7 +180,7 @@ void UTIL_MemProtect(void *addr, int length, int prot)
bool UTIL_GetLibraryOfAddress(void *memInBase, char *buffer, size_t maxlength) bool UTIL_GetLibraryOfAddress(void *memInBase, char *buffer, size_t maxlength)
{ {
#if defined __linux__ #if defined(__linux__) || defined(__APPLE__)
Dl_info info; Dl_info info;
if (!dladdr(memInBase, &info)) if (!dladdr(memInBase, &info))
{ {

View File

@ -1,78 +1,123 @@
#(C)2004-2005 AMX Mod X Development Team # (C)2004-2013 AMX Mod X Development Team
# Makefile written by David "BAILOPAN" Anderson # Makefile written by David "BAILOPAN" Anderson
HLSDK = ../../../../hlsdk ###########################################
### EDIT THESE PATHS FOR YOUR OWN SETUP ###
###########################################
HLSDK = ../../../../hlsdk/multiplayer
MM_ROOT = ../../../../metamod/metamod MM_ROOT = ../../../../metamod/metamod
#####################################
### EDIT BELOW FOR OTHER PROJECTS ### ### EDIT BELOW FOR OTHER PROJECTS ###
#####################################
OPT_FLAGS = -O2 -funroll-loops -s -pipe -fomit-frame-pointer -fno-strict-aliasing PROJECT = cstrike
DEBUG_FLAGS = -g -ggdb3
CPP = gcc-4.1
NAME = cstrike
BIN_SUFFIX_32 = amxx_i386.so
BIN_SUFFIX_64 = amxx_amd64.so
OBJECTS = sdk/amxxmodule.cpp CstrikePlayer.cpp cstrike.cpp CstrikeHacks.cpp OBJECTS = sdk/amxxmodule.cpp CstrikePlayer.cpp cstrike.cpp CstrikeHacks.cpp
##############################################
### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
##############################################
C_OPT_FLAGS = -DNDEBUG -O2 -funroll-loops -fomit-frame-pointer -pipe
C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3
C_GCC4_FLAGS = -fvisibility=hidden
CPP_GCC4_FLAGS = -fvisibility-inlines-hidden
CPP = gcc
CPP_OSX = clang
LINK = LINK =
INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared -I$(HLSDK)/game_shared \ INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/common -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared \
-I$(MM_ROOT) -I$(HLSDK)/common -Isdk -I$(MM_ROOT) -Isdk
GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) ################################################
### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ###
################################################
ifeq "$(GCC_VERSION)" "4" OS := $(shell uname -s)
OPT_FLAGS += -fvisibility=hidden -fvisibility-inlines-hidden
ifeq "$(OS)" "Darwin"
CPP = $(CPP_OSX)
LIB_EXT = dylib
LIB_SUFFIX = _amxx
CFLAGS += -DOSX
LINK += -dynamiclib -lstdc++ -mmacosx-version-min=10.5
else
LIB_EXT = so
LIB_SUFFIX = _amxx_i386
CFLAGS += -DLINUX
LINK += -shared
endif endif
LINK += -m32 -lm -ldl
CFLAGS += -DPAWN_CELL_SIZE=32 -DJIT -DASM32 -DHAVE_STDINT_H -fno-strict-aliasing -m32 -Wall -Werror
CPPFLAGS += -fno-exceptions -fno-rtti
BINARY = $(PROJECT)$(LIB_SUFFIX).$(LIB_EXT)
ifeq "$(DEBUG)" "true" ifeq "$(DEBUG)" "true"
BIN_DIR = Debug BIN_DIR = Debug
CFLAGS = $(DEBUG_FLAGS) CFLAGS += $(C_DEBUG_FLAGS)
else else
BIN_DIR = Release BIN_DIR = Release
CFLAGS = $(OPT_FLAGS) CFLAGS += $(C_OPT_FLAGS)
LINK += -s
endif endif
CFLAGS += -DNDEBUG -Wall -Wno-non-virtual-dtor -Werror -fno-exceptions -DHAVE_STDINT_H -fno-rtti -static-libgcc -m32 IS_CLANG := $(shell $(CPP) --version | head -1 | grep clang > /dev/null && echo "1" || echo "0")
ifeq "$(AMD64)" "true" ifeq "$(IS_CLANG)" "1"
BINARY = $(NAME)_$(BIN_SUFFIX_64) CPP_MAJOR := $(shell $(CPP) --version | grep clang | sed "s/.*version \([0-9]\)*\.[0-9]*.*/\1/")
CFLAGS += -DPAWN_CELL_SIZE=64 -DHAVE_I64 -m64 CPP_MINOR := $(shell $(CPP) --version | grep clang | sed "s/.*version [0-9]*\.\([0-9]\)*.*/\1/")
else else
BINARY = $(NAME)_$(BIN_SUFFIX_32) CPP_MAJOR := $(shell $(CPP) -dumpversion >&1 | cut -b1)
CFLAGS += -DPAWN_CELL_SIZE=32 -DJIT -DASM32 CPP_MINOR := $(shell $(CPP) -dumpversion >&1 | cut -b3)
OPT_FLAGS += -march=i586
endif endif
OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) # Clang || GCC >= 4
ifeq "$(shell expr $(IS_CLANG) \| $(CPP_MAJOR) \>= 4)" "1"
CFLAGS += $(C_GCC4_FLAGS)
CPPFLAGS += $(CPP_GCC4_FLAGS)
endif
# Clang >= 3 || GCC >= 4.7
ifeq "$(shell expr $(IS_CLANG) \& $(CPP_MAJOR) \>= 3 \| $(CPP_MAJOR) \>= 4 \& $(CPP_MINOR) \>= 7)" "1"
CFLAGS += -Wno-delete-non-virtual-dtor
endif
# OS is Linux and not using clang
ifeq "$(shell expr $(OS) \= Linux \& $(IS_CLANG) \= 0)" "1"
LINK += -static-libgcc
endif
OBJ_BIN := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o)
# This will break if we include other Makefiles, but is fine for now. It allows
# us to make a copy of this file that uses altered paths (ie. Makefile.mine)
# or other changes without mucking up the original.
MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
$(BIN_DIR)/%.o: %.cpp $(BIN_DIR)/%.o: %.cpp
$(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $< $(CPP) $(INCLUDE) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
all: all:
mkdir -p $(BIN_DIR) mkdir -p $(BIN_DIR)
mkdir -p $(BIN_DIR)/sdk mkdir -p $(BIN_DIR)/sdk
$(MAKE) cstrike $(MAKE) -f $(MAKEFILE_NAME) $(PROJECT)
amd64: $(PROJECT): $(OBJ_BIN)
$(MAKE) all AMD64=true $(CPP) $(INCLUDE) $(OBJ_BIN) $(LINK) -o $(BIN_DIR)/$(BINARY)
cstrike: $(OBJ_LINUX)
$(CPP) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -shared -ldl -lm -o$(BIN_DIR)/$(BINARY)
debug: debug:
$(MAKE) all DEBUG=true $(MAKE) -f $(MAKEFILE_NAME) all DEBUG=true
default: all default: all
clean: clean:
rm -rf Release/sdk/*.o rm -rf $(BIN_DIR)/*.o
rm -rf Release/*.o rm -rf $(BIN_DIR)/sdk/*.o
rm -rf Release/$(NAME)_$(BIN_SUFFIX_32) rm -f $(BIN_DIR)/$(BINARY)
rm -rf Release/$(NAME)_$(BIN_SUFFIX_64)
rm -rf Debug/sdk/*.o
rm -rf Debug/*.o
rm -rf Debug/$(NAME)_$(BIN_SUFFIX_32)
rm -rf Debug/$(NAME)_$(BIN_SUFFIX_64)

View File

@ -49,7 +49,7 @@ bool UTIL_IsPlayer(AMX* amx, edict_t* pPlayer) {
return player; return player;
} }
void UTIL_TextMsg_Generic(edict_t* pPlayer, char* message) void UTIL_TextMsg_Generic(edict_t* pPlayer, const char* message)
{ {
MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "TextMsg", NULL), NULL, pPlayer); MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "TextMsg", NULL), NULL, pPlayer);
WRITE_BYTE(HUD_PRINTCENTER); // 1 = console, 2 = console, 3 = chat, 4 = center WRITE_BYTE(HUD_PRINTCENTER); // 1 = console, 2 = console, 3 = chat, 4 = center
@ -746,7 +746,7 @@ static cell AMX_NATIVE_CALL cs_set_user_defusekit(AMX *amx, cell *params) // cs_
pPlayer->v.body = 1; pPlayer->v.body = 1;
char* icon; const char* icon;
if (params[6] != -1) if (params[6] != -1)
{ {
int len; int len;

View File

@ -44,7 +44,7 @@
#define GETCLIENTKEYVALUE (*g_engfuncs.pfnInfoKeyValue) #define GETCLIENTKEYVALUE (*g_engfuncs.pfnInfoKeyValue)
#define CREATENAMEDENTITY (*g_engfuncs.pfnCreateNamedEntity) #define CREATENAMEDENTITY (*g_engfuncs.pfnCreateNamedEntity)
#if defined __linux__ #if defined(__linux__) || defined (__APPLE__)
#define EXTRAOFFSET 5 // offsets 5 higher in Linux builds #define EXTRAOFFSET 5 // offsets 5 higher in Linux builds
#define EXTRAOFFSET_WEAPONS 4 // weapon offsets are obviously only 4 steps higher on Linux! #define EXTRAOFFSET_WEAPONS 4 // weapon offsets are obviously only 4 steps higher on Linux!
#define ACTUAL_EXTRA_OFFSET 20 // actual, byte-addressable offset #define ACTUAL_EXTRA_OFFSET 20 // actual, byte-addressable offset
@ -52,7 +52,7 @@
#define EXTRAOFFSET 0 // no change in Windows builds #define EXTRAOFFSET 0 // no change in Windows builds
#define EXTRAOFFSET_WEAPONS 0 #define EXTRAOFFSET_WEAPONS 0
#define ACTUAL_EXTRA_OFFSET 0 #define ACTUAL_EXTRA_OFFSET 0
#endif // defined __linux__ #endif // defined(__linux__) || defined(__APPLE__)
/* /*
Offset history: Offset history:
041029: 041029:
@ -158,6 +158,8 @@
#if defined __linux__ #if defined __linux__
#define CS_DETOURCOPYBYTES_CLIENTCOMMAND 6 #define CS_DETOURCOPYBYTES_CLIENTCOMMAND 6
#elif defined __APPLE__
#define CS_DETOURCOPYBYTES_CLIENTCOMMAND 5
#else #else
#define CS_DETOURCOPYBYTES_CLIENTCOMMAND 6 #define CS_DETOURCOPYBYTES_CLIENTCOMMAND 6
#define CS_CLICMD_OFFS_USEBOTARGS 2 #define CS_CLICMD_OFFS_USEBOTARGS 2

View File

@ -2240,7 +2240,7 @@ static META_FUNCTIONS g_MetaFunctions_Table =
GetEngineFunctions_Post GetEngineFunctions_Post
}; };
C_DLLEXPORT int Meta_Query(char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs) C_DLLEXPORT int Meta_Query(const char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs)
{ {
if ((int) CVAR_GET_FLOAT("developer") != 0) if ((int) CVAR_GET_FLOAT("developer") != 0)
UTIL_LogPrintf("[%s] dev: called: Meta_Query; version=%s, ours=%s\n", UTIL_LogPrintf("[%s] dev: called: Meta_Query; version=%s, ours=%s\n",
@ -2334,7 +2334,7 @@ C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
// linux prototype // linux prototype
C_DLLEXPORT void GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals ) { C_DLLEXPORT void GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals ) {
@ -3050,7 +3050,7 @@ char* UTIL_VarArgs( char *format, ... )
// UTIL_LogPrintf - Prints a logged message to console. // UTIL_LogPrintf - Prints a logged message to console.
// Preceded by LOG: ( timestamp ) < message > // Preceded by LOG: ( timestamp ) < message >
//========================================================= //=========================================================
void UTIL_LogPrintf( char *fmt, ... ) void UTIL_LogPrintf( const char *fmt, ... )
{ {
va_list argptr; va_list argptr;
static char string[1024]; static char string[1024];

View File

@ -20,11 +20,16 @@
// DLL Export // DLL Export
#undef DLLEXPORT #undef DLLEXPORT
#ifndef __linux__ #if defined(_WIN32)
#define DLLEXPORT __declspec(dllexport) #define DLLEXPORT __declspec(dllexport)
#else #else
#define DLLEXPORT __attribute__((visibility("default"))) #define DLLEXPORT __attribute__((visibility("default")))
#endif
#if defined(__linux__) && !defined(LINUX)
#define LINUX #define LINUX
#elif defined(__APPLE__) && !defined(OSX)
#define OSX
#endif #endif
#undef C_DLLEXPORT #undef C_DLLEXPORT
@ -66,7 +71,7 @@ struct amxx_module_info_s
#if defined HAVE_STDINT_H #if defined HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#else #else
#if defined __LCC__ || defined __DMC__ || defined LINUX #if defined __LCC__ || defined __DMC__ || defined LINUX || defined __APPLE__
#if defined HAVE_INTTYPES_H #if defined HAVE_INTTYPES_H
#include <inttypes.h> #include <inttypes.h>
#else #else
@ -308,7 +313,7 @@ typedef int (AMXAPI *AMX_DEBUG)(struct tagAMX *amx);
#endif #endif
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__ #if defined LINUX || defined __FreeBSD__ || defined __APPLE__
#pragma pack(1) /* structures must be packed (byte-aligned) */ #pragma pack(1) /* structures must be packed (byte-aligned) */
#elif defined MACOS && defined __MWERKS__ #elif defined MACOS && defined __MWERKS__
#pragma options align=mac68k #pragma options align=mac68k
@ -395,7 +400,7 @@ enum {
}; };
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined __linux__ #if defined(__linux__) || defined(__APPLE__)
#pragma pack() /* reset default packing */ #pragma pack() /* reset default packing */
#else #else
#pragma pack(pop) /* reset previous packing */ #pragma pack(pop) /* reset previous packing */
@ -406,7 +411,7 @@ enum {
// ***** declare functions ***** // ***** declare functions *****
#ifdef USE_METAMOD #ifdef USE_METAMOD
void UTIL_LogPrintf( char *fmt, ... ); void UTIL_LogPrintf( const char *fmt, ... );
void UTIL_HudMessage(CBaseEntity *pEntity, const hudtextparms_t &textparms, const char *pMessage); void UTIL_HudMessage(CBaseEntity *pEntity, const hudtextparms_t &textparms, const char *pMessage);
short FixedSigned16( float value, float scale ); short FixedSigned16( float value, float scale );
unsigned short FixedUnsigned16( float value, float scale ); unsigned short FixedUnsigned16( float value, float scale );
@ -833,11 +838,11 @@ int FN_AllowLagCompensation_Post(void);
#ifdef FN_PrecacheModel #ifdef FN_PrecacheModel
int FN_PrecacheModel(char *s); int FN_PrecacheModel(const char *s);
#endif // FN_PrecacheModel #endif // FN_PrecacheModel
#ifdef FN_PrecacheSound #ifdef FN_PrecacheSound
int FN_PrecacheSound(char *s); int FN_PrecacheSound(const char *s);
#endif // FN_PrecacheSound #endif // FN_PrecacheSound
#ifdef FN_SetModel #ifdef FN_SetModel
@ -857,7 +862,7 @@ void FN_SetSize(edict_t *e, const float *rgflMin, const float *rgflMax);
#endif // FN_SetSize #endif // FN_SetSize
#ifdef FN_ChangeLevel #ifdef FN_ChangeLevel
void FN_ChangeLevel(char *s1, char *s2); void FN_ChangeLevel(const char *s1, const char *s2);
#endif // FN_ChangeLevel #endif // FN_ChangeLevel
#ifdef FN_GetSpawnParms #ifdef FN_GetSpawnParms
@ -1261,19 +1266,19 @@ char *FN_GetInfoKeyBuffer(edict_t *e);
#endif // FN_GetInfoKeyBuffer #endif // FN_GetInfoKeyBuffer
#ifdef FN_InfoKeyValue #ifdef FN_InfoKeyValue
char *FN_InfoKeyValue(char *infobuffer, char *key); char *FN_InfoKeyValue(char *infobuffer, const char *key);
#endif // FN_InfoKeyValue #endif // FN_InfoKeyValue
#ifdef FN_SetKeyValue #ifdef FN_SetKeyValue
void FN_SetKeyValue(char *infobuffer, char *key, char *value); void FN_SetKeyValue(char *infobuffer, const char *key, const char *value);
#endif // FN_SetKeyValue #endif // FN_SetKeyValue
#ifdef FN_SetClientKeyValue #ifdef FN_SetClientKeyValue
void FN_SetClientKeyValue(int clientIndex, char *infobuffer, char *key, char *value); void FN_SetClientKeyValue(int clientIndex, char *infobuffer, const char *key, const char *value);
#endif // FN_SetClientKeyValue #endif // FN_SetClientKeyValue
#ifdef FN_IsMapValid #ifdef FN_IsMapValid
int FN_IsMapValid(char *filename); int FN_IsMapValid(const char *filename);
#endif // FN_IsMapValid #endif // FN_IsMapValid
#ifdef FN_StaticDecal #ifdef FN_StaticDecal
@ -1281,7 +1286,7 @@ void FN_StaticDecal(const float *origin, int decalIndex, int entityIndex, int mo
#endif // FN_StaticDecal #endif // FN_StaticDecal
#ifdef FN_PrecacheGeneric #ifdef FN_PrecacheGeneric
int FN_PrecacheGeneric(char *s); int FN_PrecacheGeneric(const char *s);
#endif // FN_PrecacheGeneric #endif // FN_PrecacheGeneric
#ifdef FN_GetPlayerUserId #ifdef FN_GetPlayerUserId
@ -1414,11 +1419,11 @@ const char *FN_GetPlayerAuthId(edict_t *e);
#ifdef FN_PrecacheModel_Post #ifdef FN_PrecacheModel_Post
int FN_PrecacheModel_Post(char *s); int FN_PrecacheModel_Post(const char *s);
#endif // FN_PrecacheModel_Post #endif // FN_PrecacheModel_Post
#ifdef FN_PrecacheSound_Post #ifdef FN_PrecacheSound_Post
int FN_PrecacheSound_Post(char *s); int FN_PrecacheSound_Post(const char *s);
#endif // FN_PrecacheSound_Post #endif // FN_PrecacheSound_Post
#ifdef FN_SetModel_Post #ifdef FN_SetModel_Post
@ -1438,7 +1443,7 @@ void FN_SetSize_Post(edict_t *e, const float *rgflMin, const float *rgflMax);
#endif // FN_SetSize_Post #endif // FN_SetSize_Post
#ifdef FN_ChangeLevel_Post #ifdef FN_ChangeLevel_Post
void FN_ChangeLevel_Post(char *s1, char *s2); void FN_ChangeLevel_Post(const char *s1, const char *s2);
#endif // FN_ChangeLevel_Post #endif // FN_ChangeLevel_Post
#ifdef FN_GetSpawnParms_Post #ifdef FN_GetSpawnParms_Post
@ -1842,19 +1847,19 @@ char *FN_GetInfoKeyBuffer_Post(edict_t *e);
#endif // FN_GetInfoKeyBuffer_Post #endif // FN_GetInfoKeyBuffer_Post
#ifdef FN_InfoKeyValue_Post #ifdef FN_InfoKeyValue_Post
char *FN_InfoKeyValue_Post(char *infobuffer, char *key); char *FN_InfoKeyValue_Post(char *infobuffer, const char *key);
#endif // FN_InfoKeyValue_Post #endif // FN_InfoKeyValue_Post
#ifdef FN_SetKeyValue_Post #ifdef FN_SetKeyValue_Post
void FN_SetKeyValue_Post(char *infobuffer, char *key, char *value); void FN_SetKeyValue_Post(char *infobuffer, const char *key, const char *value);
#endif // FN_SetKeyValue_Post #endif // FN_SetKeyValue_Post
#ifdef FN_SetClientKeyValue_Post #ifdef FN_SetClientKeyValue_Post
void FN_SetClientKeyValue_Post(int clientIndex, char *infobuffer, char *key, char *value); void FN_SetClientKeyValue_Post(int clientIndex, char *infobuffer, const char *key, const char *value);
#endif // FN_SetClientKeyValue_Post #endif // FN_SetClientKeyValue_Post
#ifdef FN_IsMapValid_Post #ifdef FN_IsMapValid_Post
int FN_IsMapValid_Post(char *filename); int FN_IsMapValid_Post(const char *filename);
#endif // FN_IsMapValid_Post #endif // FN_IsMapValid_Post
#ifdef FN_StaticDecal_Post #ifdef FN_StaticDecal_Post
@ -1862,7 +1867,7 @@ void FN_StaticDecal_Post(const float *origin, int decalIndex, int entityIndex, i
#endif // FN_StaticDecal_Post #endif // FN_StaticDecal_Post
#ifdef FN_PrecacheGeneric_Post #ifdef FN_PrecacheGeneric_Post
int FN_PrecacheGeneric_Post(char *s); int FN_PrecacheGeneric_Post(const char *s);
#endif // FN_PrecacheGeneric_Post #endif // FN_PrecacheGeneric_Post
#ifdef FN_GetPlayerUserId_Post #ifdef FN_GetPlayerUserId_Post
@ -2116,7 +2121,7 @@ typedef int (*PFN_ADD_NEW_NATIVES) (const AMX_NATIVE_INFO * /*list*/);
typedef char * (*PFN_BUILD_PATHNAME) (const char * /*format*/, ...); typedef char * (*PFN_BUILD_PATHNAME) (const char * /*format*/, ...);
typedef char * (*PFN_BUILD_PATHNAME_R) (char * /*buffer*/, size_t /* maxlen */, const char * /* format */, ...); typedef char * (*PFN_BUILD_PATHNAME_R) (char * /*buffer*/, size_t /* maxlen */, const char * /* format */, ...);
typedef cell * (*PFN_GET_AMXADDR) (AMX * /*amx*/, cell /*offset*/); typedef cell * (*PFN_GET_AMXADDR) (AMX * /*amx*/, cell /*offset*/);
typedef void (*PFN_PRINT_SRVCONSOLE) (char * /*format*/, ...); typedef void (*PFN_PRINT_SRVCONSOLE) (const char * /*format*/, ...);
typedef const char * (*PFN_GET_MODNAME) (void); typedef const char * (*PFN_GET_MODNAME) (void);
typedef const char * (*PFN_GET_AMXSCRIPTNAME) (int /*id*/); typedef const char * (*PFN_GET_AMXSCRIPTNAME) (int /*id*/);
typedef AMX * (*PFN_GET_AMXSCRIPT) (int /*id*/); typedef AMX * (*PFN_GET_AMXSCRIPT) (int /*id*/);
@ -2175,8 +2180,8 @@ typedef void (*PFN_DEALLOCATOR) (const char* /*filename*/, const unsigned i
typedef int (*PFN_AMX_EXEC) (AMX* /*amx*/, cell* /*return val*/, int /*index*/); typedef int (*PFN_AMX_EXEC) (AMX* /*amx*/, cell* /*return val*/, int /*index*/);
typedef int (*PFN_AMX_EXECV) (AMX* /*amx*/, cell* /*return val*/, int /*index*/, int /*numparams*/, cell[] /*params*/); typedef int (*PFN_AMX_EXECV) (AMX* /*amx*/, cell* /*return val*/, int /*index*/, int /*numparams*/, cell[] /*params*/);
typedef int (*PFN_AMX_ALLOT) (AMX* /*amx*/, int /*length*/, cell* /*amx_addr*/, cell** /*phys_addr*/); typedef int (*PFN_AMX_ALLOT) (AMX* /*amx*/, int /*length*/, cell* /*amx_addr*/, cell** /*phys_addr*/);
typedef int (*PFN_AMX_FINDPUBLIC) (AMX* /*amx*/, char* /*func name*/, int* /*index*/); typedef int (*PFN_AMX_FINDPUBLIC) (AMX* /*amx*/, const char* /*func name*/, int* /*index*/);
typedef int (*PFN_AMX_FINDNATIVE) (AMX* /*amx*/, char* /*func name*/, int* /*index*/); typedef int (*PFN_AMX_FINDNATIVE) (AMX* /*amx*/, const char* /*func name*/, int* /*index*/);
typedef int (*PFN_LOAD_AMXSCRIPT) (AMX* /*amx*/, void** /*code*/, const char* /*path*/, char[64] /*error info*/, int /* debug */); typedef int (*PFN_LOAD_AMXSCRIPT) (AMX* /*amx*/, void** /*code*/, const char* /*path*/, char[64] /*error info*/, int /* debug */);
typedef int (*PFN_UNLOAD_AMXSCRIPT) (AMX* /*amx*/,void** /*code*/); typedef int (*PFN_UNLOAD_AMXSCRIPT) (AMX* /*amx*/,void** /*code*/);
typedef cell (*PFN_REAL_TO_CELL) (REAL /*x*/); typedef cell (*PFN_REAL_TO_CELL) (REAL /*x*/);

View File

@ -1,78 +1,123 @@
#(C)2004-2005 AMX Mod X Development Team # (C)2004-2013 AMX Mod X Development Team
# Makefile written by David "BAILOPAN" Anderson # Makefile written by David "BAILOPAN" Anderson
HLSDK = ../../../../hlsdk ###########################################
### EDIT THESE PATHS FOR YOUR OWN SETUP ###
###########################################
HLSDK = ../../../../hlsdk/multiplayer
MM_ROOT = ../../../../metamod/metamod MM_ROOT = ../../../../metamod/metamod
#####################################
### EDIT BELOW FOR OTHER PROJECTS ### ### EDIT BELOW FOR OTHER PROJECTS ###
#####################################
OPT_FLAGS = -O3 -funroll-loops -s -pipe -fomit-frame-pointer -fno-strict-aliasing PROJECT = csx
DEBUG_FLAGS = -g -ggdb3
CPP = gcc-4.1
NAME = csx
BIN_SUFFIX_32 = amxx_i386.so
BIN_SUFFIX_64 = amxx_amd64.so
OBJECTS = sdk/amxxmodule.cpp CRank.cpp CMisc.cpp meta_api.cpp rank.cpp usermsg.cpp OBJECTS = sdk/amxxmodule.cpp CRank.cpp CMisc.cpp meta_api.cpp rank.cpp usermsg.cpp
##############################################
### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
##############################################
C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -fomit-frame-pointer -pipe
C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3
C_GCC4_FLAGS = -fvisibility=hidden
CPP_GCC4_FLAGS = -fvisibility-inlines-hidden
CPP = gcc
CPP_OSX = clang
LINK = LINK =
INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared -I$(HLSDK)/game_shared \ INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/common -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared \
-I$(MM_ROOT) -I$(HLSDK)/common -Isdk -I$(MM_ROOT) -Isdk
GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) ################################################
### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ###
################################################
ifeq "$(GCC_VERSION)" "4" OS := $(shell uname -s)
OPT_FLAGS += -fvisibility=hidden -fvisibility-inlines-hidden
ifeq "$(OS)" "Darwin"
CPP = $(CPP_OSX)
LIB_EXT = dylib
LIB_SUFFIX = _amxx
CFLAGS += -DOSX
LINK += -dynamiclib -lstdc++ -mmacosx-version-min=10.5
else
LIB_EXT = so
LIB_SUFFIX = _amxx_i386
CFLAGS += -DLINUX
LINK += -shared
endif endif
LINK += -m32 -lm -ldl
CFLAGS += -DPAWN_CELL_SIZE=32 -DJIT -DASM32 -DHAVE_STDINT_H -fno-strict-aliasing -m32 -Wall -Werror
CPPFLAGS += -fno-exceptions -fno-rtti
BINARY = $(PROJECT)$(LIB_SUFFIX).$(LIB_EXT)
ifeq "$(DEBUG)" "true" ifeq "$(DEBUG)" "true"
BIN_DIR = Debug BIN_DIR = Debug
CFLAGS = $(DEBUG_FLAGS) CFLAGS += $(C_DEBUG_FLAGS)
else else
BIN_DIR = Release BIN_DIR = Release
CFLAGS = $(OPT_FLAGS) CFLAGS += $(C_OPT_FLAGS)
LINK += -s
endif endif
CFLAGS += -DNDEBUG -Wall -Wno-non-virtual-dtor -Werror -fno-exceptions -DHAVE_STDINT_H -static-libgcc -fno-rtti -m32 IS_CLANG := $(shell $(CPP) --version | head -1 | grep clang > /dev/null && echo "1" || echo "0")
ifeq "$(AMD64)" "true" ifeq "$(IS_CLANG)" "1"
BINARY = $(NAME)_$(BIN_SUFFIX_64) CPP_MAJOR := $(shell $(CPP) --version | grep clang | sed "s/.*version \([0-9]\)*\.[0-9]*.*/\1/")
CFLAGS += -DPAWN_CELL_SIZE=64 -DHAVE_I64 -m64 CPP_MINOR := $(shell $(CPP) --version | grep clang | sed "s/.*version [0-9]*\.\([0-9]\)*.*/\1/")
else else
BINARY = $(NAME)_$(BIN_SUFFIX_32) CPP_MAJOR := $(shell $(CPP) -dumpversion >&1 | cut -b1)
CFLAGS += -DPAWN_CELL_SIZE=32 -DJIT -DASM32 CPP_MINOR := $(shell $(CPP) -dumpversion >&1 | cut -b3)
OPT_FLAGS += -march=i586
endif endif
OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) # Clang || GCC >= 4
ifeq "$(shell expr $(IS_CLANG) \| $(CPP_MAJOR) \>= 4)" "1"
CFLAGS += $(C_GCC4_FLAGS)
CPPFLAGS += $(CPP_GCC4_FLAGS)
endif
# Clang >= 3 || GCC >= 4.7
ifeq "$(shell expr $(IS_CLANG) \& $(CPP_MAJOR) \>= 3 \| $(CPP_MAJOR) \>= 4 \& $(CPP_MINOR) \>= 7)" "1"
CFLAGS += -Wno-delete-non-virtual-dtor
endif
# OS is Linux and not using clang
ifeq "$(shell expr $(OS) \= Linux \& $(IS_CLANG) \= 0)" "1"
LINK += -static-libgcc
endif
OBJ_BIN := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o)
# This will break if we include other Makefiles, but is fine for now. It allows
# us to make a copy of this file that uses altered paths (ie. Makefile.mine)
# or other changes without mucking up the original.
MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
$(BIN_DIR)/%.o: %.cpp $(BIN_DIR)/%.o: %.cpp
$(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $< $(CPP) $(INCLUDE) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
all: all:
mkdir -p $(BIN_DIR) mkdir -p $(BIN_DIR)
mkdir -p $(BIN_DIR)/sdk mkdir -p $(BIN_DIR)/sdk
$(MAKE) csx $(MAKE) -f $(MAKEFILE_NAME) $(PROJECT)
amd64: $(PROJECT): $(OBJ_BIN)
$(MAKE) all AMD64=true $(CPP) $(INCLUDE) $(OBJ_BIN) $(LINK) -o $(BIN_DIR)/$(BINARY)
csx: $(OBJ_LINUX)
$(CPP) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -shared -ldl -lm -o$(BIN_DIR)/$(BINARY)
debug: debug:
$(MAKE) all DEBUG=true $(MAKE) -f $(MAKEFILE_NAME) all DEBUG=true
default: all default: all
clean: clean:
rm -rf Release/sdk/*.o rm -rf $(BIN_DIR)/*.o
rm -rf Release/*.o rm -rf $(BIN_DIR)/sdk/*.o
rm -rf Release/$(NAME)_$(BIN_SUFFIX_32) rm -f $(BIN_DIR)/$(BINARY)
rm -rf Release/$(NAME)_$(BIN_SUFFIX_64)
rm -rf Debug/sdk/*.o
rm -rf Debug/*.o
rm -rf Debug/$(NAME)_$(BIN_SUFFIX_32)
rm -rf Debug/$(NAME)_$(BIN_SUFFIX_64)

View File

@ -2240,7 +2240,7 @@ static META_FUNCTIONS g_MetaFunctions_Table =
GetEngineFunctions_Post GetEngineFunctions_Post
}; };
C_DLLEXPORT int Meta_Query(char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs) C_DLLEXPORT int Meta_Query(const char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs)
{ {
if ((int) CVAR_GET_FLOAT("developer") != 0) if ((int) CVAR_GET_FLOAT("developer") != 0)
UTIL_LogPrintf("[%s] dev: called: Meta_Query; version=%s, ours=%s\n", UTIL_LogPrintf("[%s] dev: called: Meta_Query; version=%s, ours=%s\n",
@ -2334,7 +2334,7 @@ C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
// linux prototype // linux prototype
C_DLLEXPORT void GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals ) { C_DLLEXPORT void GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals ) {
@ -3050,7 +3050,7 @@ char* UTIL_VarArgs( char *format, ... )
// UTIL_LogPrintf - Prints a logged message to console. // UTIL_LogPrintf - Prints a logged message to console.
// Preceded by LOG: ( timestamp ) < message > // Preceded by LOG: ( timestamp ) < message >
//========================================================= //=========================================================
void UTIL_LogPrintf( char *fmt, ... ) void UTIL_LogPrintf( const char *fmt, ... )
{ {
va_list argptr; va_list argptr;
static char string[1024]; static char string[1024];

View File

@ -20,11 +20,16 @@
// DLL Export // DLL Export
#undef DLLEXPORT #undef DLLEXPORT
#ifndef __linux__ #if defined(_WIN32)
#define DLLEXPORT __declspec(dllexport) #define DLLEXPORT __declspec(dllexport)
#else #else
#define DLLEXPORT __attribute__((visibility("default"))) #define DLLEXPORT __attribute__((visibility("default")))
#endif
#if defined(__linux__) && !defined(LINUX)
#define LINUX #define LINUX
#elif defined(__APPLE__) && !defined(OSX)
#define OSX
#endif #endif
#undef C_DLLEXPORT #undef C_DLLEXPORT
@ -66,7 +71,7 @@ struct amxx_module_info_s
#if defined HAVE_STDINT_H #if defined HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#else #else
#if defined __LCC__ || defined __DMC__ || defined LINUX #if defined __LCC__ || defined __DMC__ || defined LINUX || defined __APPLE__
#if defined HAVE_INTTYPES_H #if defined HAVE_INTTYPES_H
#include <inttypes.h> #include <inttypes.h>
#else #else
@ -308,7 +313,7 @@ typedef int (AMXAPI *AMX_DEBUG)(struct tagAMX *amx);
#endif #endif
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__ #if defined LINUX || defined __FreeBSD__ || defined __APPLE__
#pragma pack(1) /* structures must be packed (byte-aligned) */ #pragma pack(1) /* structures must be packed (byte-aligned) */
#elif defined MACOS && defined __MWERKS__ #elif defined MACOS && defined __MWERKS__
#pragma options align=mac68k #pragma options align=mac68k
@ -395,7 +400,7 @@ enum {
}; };
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined __linux__ #if defined(__linux__) || defined(__APPLE__)
#pragma pack() /* reset default packing */ #pragma pack() /* reset default packing */
#else #else
#pragma pack(pop) /* reset previous packing */ #pragma pack(pop) /* reset previous packing */
@ -406,7 +411,7 @@ enum {
// ***** declare functions ***** // ***** declare functions *****
#ifdef USE_METAMOD #ifdef USE_METAMOD
void UTIL_LogPrintf( char *fmt, ... ); void UTIL_LogPrintf( const char *fmt, ... );
void UTIL_HudMessage(CBaseEntity *pEntity, const hudtextparms_t &textparms, const char *pMessage); void UTIL_HudMessage(CBaseEntity *pEntity, const hudtextparms_t &textparms, const char *pMessage);
short FixedSigned16( float value, float scale ); short FixedSigned16( float value, float scale );
unsigned short FixedUnsigned16( float value, float scale ); unsigned short FixedUnsigned16( float value, float scale );
@ -833,11 +838,11 @@ int FN_AllowLagCompensation_Post(void);
#ifdef FN_PrecacheModel #ifdef FN_PrecacheModel
int FN_PrecacheModel(char *s); int FN_PrecacheModel(const char *s);
#endif // FN_PrecacheModel #endif // FN_PrecacheModel
#ifdef FN_PrecacheSound #ifdef FN_PrecacheSound
int FN_PrecacheSound(char *s); int FN_PrecacheSound(const char *s);
#endif // FN_PrecacheSound #endif // FN_PrecacheSound
#ifdef FN_SetModel #ifdef FN_SetModel
@ -857,7 +862,7 @@ void FN_SetSize(edict_t *e, const float *rgflMin, const float *rgflMax);
#endif // FN_SetSize #endif // FN_SetSize
#ifdef FN_ChangeLevel #ifdef FN_ChangeLevel
void FN_ChangeLevel(char *s1, char *s2); void FN_ChangeLevel(const char *s1, const char *s2);
#endif // FN_ChangeLevel #endif // FN_ChangeLevel
#ifdef FN_GetSpawnParms #ifdef FN_GetSpawnParms
@ -1261,19 +1266,19 @@ char *FN_GetInfoKeyBuffer(edict_t *e);
#endif // FN_GetInfoKeyBuffer #endif // FN_GetInfoKeyBuffer
#ifdef FN_InfoKeyValue #ifdef FN_InfoKeyValue
char *FN_InfoKeyValue(char *infobuffer, char *key); char *FN_InfoKeyValue(char *infobuffer, const char *key);
#endif // FN_InfoKeyValue #endif // FN_InfoKeyValue
#ifdef FN_SetKeyValue #ifdef FN_SetKeyValue
void FN_SetKeyValue(char *infobuffer, char *key, char *value); void FN_SetKeyValue(char *infobuffer, const char *key, const char *value);
#endif // FN_SetKeyValue #endif // FN_SetKeyValue
#ifdef FN_SetClientKeyValue #ifdef FN_SetClientKeyValue
void FN_SetClientKeyValue(int clientIndex, char *infobuffer, char *key, char *value); void FN_SetClientKeyValue(int clientIndex, char *infobuffer, const char *key, const char *value);
#endif // FN_SetClientKeyValue #endif // FN_SetClientKeyValue
#ifdef FN_IsMapValid #ifdef FN_IsMapValid
int FN_IsMapValid(char *filename); int FN_IsMapValid(const char *filename);
#endif // FN_IsMapValid #endif // FN_IsMapValid
#ifdef FN_StaticDecal #ifdef FN_StaticDecal
@ -1281,7 +1286,7 @@ void FN_StaticDecal(const float *origin, int decalIndex, int entityIndex, int mo
#endif // FN_StaticDecal #endif // FN_StaticDecal
#ifdef FN_PrecacheGeneric #ifdef FN_PrecacheGeneric
int FN_PrecacheGeneric(char *s); int FN_PrecacheGeneric(const char *s);
#endif // FN_PrecacheGeneric #endif // FN_PrecacheGeneric
#ifdef FN_GetPlayerUserId #ifdef FN_GetPlayerUserId
@ -1414,11 +1419,11 @@ const char *FN_GetPlayerAuthId(edict_t *e);
#ifdef FN_PrecacheModel_Post #ifdef FN_PrecacheModel_Post
int FN_PrecacheModel_Post(char *s); int FN_PrecacheModel_Post(const char *s);
#endif // FN_PrecacheModel_Post #endif // FN_PrecacheModel_Post
#ifdef FN_PrecacheSound_Post #ifdef FN_PrecacheSound_Post
int FN_PrecacheSound_Post(char *s); int FN_PrecacheSound_Post(const char *s);
#endif // FN_PrecacheSound_Post #endif // FN_PrecacheSound_Post
#ifdef FN_SetModel_Post #ifdef FN_SetModel_Post
@ -1438,7 +1443,7 @@ void FN_SetSize_Post(edict_t *e, const float *rgflMin, const float *rgflMax);
#endif // FN_SetSize_Post #endif // FN_SetSize_Post
#ifdef FN_ChangeLevel_Post #ifdef FN_ChangeLevel_Post
void FN_ChangeLevel_Post(char *s1, char *s2); void FN_ChangeLevel_Post(const char *s1, const char *s2);
#endif // FN_ChangeLevel_Post #endif // FN_ChangeLevel_Post
#ifdef FN_GetSpawnParms_Post #ifdef FN_GetSpawnParms_Post
@ -1842,19 +1847,19 @@ char *FN_GetInfoKeyBuffer_Post(edict_t *e);
#endif // FN_GetInfoKeyBuffer_Post #endif // FN_GetInfoKeyBuffer_Post
#ifdef FN_InfoKeyValue_Post #ifdef FN_InfoKeyValue_Post
char *FN_InfoKeyValue_Post(char *infobuffer, char *key); char *FN_InfoKeyValue_Post(char *infobuffer, const char *key);
#endif // FN_InfoKeyValue_Post #endif // FN_InfoKeyValue_Post
#ifdef FN_SetKeyValue_Post #ifdef FN_SetKeyValue_Post
void FN_SetKeyValue_Post(char *infobuffer, char *key, char *value); void FN_SetKeyValue_Post(char *infobuffer, const char *key, const char *value);
#endif // FN_SetKeyValue_Post #endif // FN_SetKeyValue_Post
#ifdef FN_SetClientKeyValue_Post #ifdef FN_SetClientKeyValue_Post
void FN_SetClientKeyValue_Post(int clientIndex, char *infobuffer, char *key, char *value); void FN_SetClientKeyValue_Post(int clientIndex, char *infobuffer, const char *key, const char *value);
#endif // FN_SetClientKeyValue_Post #endif // FN_SetClientKeyValue_Post
#ifdef FN_IsMapValid_Post #ifdef FN_IsMapValid_Post
int FN_IsMapValid_Post(char *filename); int FN_IsMapValid_Post(const char *filename);
#endif // FN_IsMapValid_Post #endif // FN_IsMapValid_Post
#ifdef FN_StaticDecal_Post #ifdef FN_StaticDecal_Post
@ -1862,7 +1867,7 @@ void FN_StaticDecal_Post(const float *origin, int decalIndex, int entityIndex, i
#endif // FN_StaticDecal_Post #endif // FN_StaticDecal_Post
#ifdef FN_PrecacheGeneric_Post #ifdef FN_PrecacheGeneric_Post
int FN_PrecacheGeneric_Post(char *s); int FN_PrecacheGeneric_Post(const char *s);
#endif // FN_PrecacheGeneric_Post #endif // FN_PrecacheGeneric_Post
#ifdef FN_GetPlayerUserId_Post #ifdef FN_GetPlayerUserId_Post
@ -2116,7 +2121,7 @@ typedef int (*PFN_ADD_NEW_NATIVES) (const AMX_NATIVE_INFO * /*list*/);
typedef char * (*PFN_BUILD_PATHNAME) (const char * /*format*/, ...); typedef char * (*PFN_BUILD_PATHNAME) (const char * /*format*/, ...);
typedef char * (*PFN_BUILD_PATHNAME_R) (char * /*buffer*/, size_t /* maxlen */, const char * /* format */, ...); typedef char * (*PFN_BUILD_PATHNAME_R) (char * /*buffer*/, size_t /* maxlen */, const char * /* format */, ...);
typedef cell * (*PFN_GET_AMXADDR) (AMX * /*amx*/, cell /*offset*/); typedef cell * (*PFN_GET_AMXADDR) (AMX * /*amx*/, cell /*offset*/);
typedef void (*PFN_PRINT_SRVCONSOLE) (char * /*format*/, ...); typedef void (*PFN_PRINT_SRVCONSOLE) (const char * /*format*/, ...);
typedef const char * (*PFN_GET_MODNAME) (void); typedef const char * (*PFN_GET_MODNAME) (void);
typedef const char * (*PFN_GET_AMXSCRIPTNAME) (int /*id*/); typedef const char * (*PFN_GET_AMXSCRIPTNAME) (int /*id*/);
typedef AMX * (*PFN_GET_AMXSCRIPT) (int /*id*/); typedef AMX * (*PFN_GET_AMXSCRIPT) (int /*id*/);
@ -2175,8 +2180,8 @@ typedef void (*PFN_DEALLOCATOR) (const char* /*filename*/, const unsigned i
typedef int (*PFN_AMX_EXEC) (AMX* /*amx*/, cell* /*return val*/, int /*index*/); typedef int (*PFN_AMX_EXEC) (AMX* /*amx*/, cell* /*return val*/, int /*index*/);
typedef int (*PFN_AMX_EXECV) (AMX* /*amx*/, cell* /*return val*/, int /*index*/, int /*numparams*/, cell[] /*params*/); typedef int (*PFN_AMX_EXECV) (AMX* /*amx*/, cell* /*return val*/, int /*index*/, int /*numparams*/, cell[] /*params*/);
typedef int (*PFN_AMX_ALLOT) (AMX* /*amx*/, int /*length*/, cell* /*amx_addr*/, cell** /*phys_addr*/); typedef int (*PFN_AMX_ALLOT) (AMX* /*amx*/, int /*length*/, cell* /*amx_addr*/, cell** /*phys_addr*/);
typedef int (*PFN_AMX_FINDPUBLIC) (AMX* /*amx*/, char* /*func name*/, int* /*index*/); typedef int (*PFN_AMX_FINDPUBLIC) (AMX* /*amx*/, const char* /*func name*/, int* /*index*/);
typedef int (*PFN_AMX_FINDNATIVE) (AMX* /*amx*/, char* /*func name*/, int* /*index*/); typedef int (*PFN_AMX_FINDNATIVE) (AMX* /*amx*/, const char* /*func name*/, int* /*index*/);
typedef int (*PFN_LOAD_AMXSCRIPT) (AMX* /*amx*/, void** /*code*/, const char* /*path*/, char[64] /*error info*/, int /* debug */); typedef int (*PFN_LOAD_AMXSCRIPT) (AMX* /*amx*/, void** /*code*/, const char* /*path*/, char[64] /*error info*/, int /* debug */);
typedef int (*PFN_UNLOAD_AMXSCRIPT) (AMX* /*amx*/,void** /*code*/); typedef int (*PFN_UNLOAD_AMXSCRIPT) (AMX* /*amx*/,void** /*code*/);
typedef cell (*PFN_REAL_TO_CELL) (REAL /*x*/); typedef cell (*PFN_REAL_TO_CELL) (REAL /*x*/);

View File

@ -67,7 +67,7 @@ void CPlayer::killPlayer(){
pEdict->v.weapons = 0; pEdict->v.weapons = 0;
} }
void CPlayer::setTeamName( char *szName ){ void CPlayer::setTeamName( const char *szName ){
for (int i=0;i<16;i++){ for (int i=0;i<16;i++){
*( (char*)pEdict->pvPrivateData + STEAM_PDOFFSET_TEAMNAME + i ) = szName[i]; *( (char*)pEdict->pvPrivateData + STEAM_PDOFFSET_TEAMNAME + i ) = szName[i];

View File

@ -32,7 +32,7 @@
#ifndef CMISC_H #ifndef CMISC_H
#define CMISC_H #define CMISC_H
#ifndef __linux__ #if defined(_WIN32)
#define LINUXOFFSET 0 #define LINUXOFFSET 0
#else #else
#define LINUXOFFSET 5 #define LINUXOFFSET 5
@ -53,7 +53,7 @@
// DoD Control Point // DoD Control Point
struct pd_dcp { struct pd_dcp {
int iunk_0; int iunk_0;
#ifndef __linux__ #if defined(_WIN32)
int iunk_1; // windows only int iunk_1; // windows only
#endif #endif
int iunk_2; // pointer edict_t* int iunk_2; // pointer edict_t*
@ -82,7 +82,7 @@ struct pd_dcp {
int iunk_36; // pointer entvars_t* int iunk_36; // pointer entvars_t*
int unknown_block2[52]; int unknown_block2[52];
int iunk_89; // pointer entvars_t* int iunk_89; // pointer entvars_t*
#ifdef __linux__ #if defined (__linux__) || defined (__APPLE__)
int iunk_extra1; int iunk_extra1;
int iunk_extra2; int iunk_extra2;
int iunk_extra3; int iunk_extra3;
@ -129,7 +129,7 @@ struct pd_dca {
int iunk_0; int iunk_0;
int iunk_1; int iunk_1;
int iunk_2; int iunk_2;
#ifndef __linux__ #if defined(_WIN32)
int iunk_3; // if def windows int iunk_3; // if def windows
#endif #endif
@ -150,7 +150,7 @@ struct pd_dca {
float angles_z; // 15 float angles_z; // 15
// 16-135 // 16-135
#ifndef __linux__ #if defined(_WIN32)
int unknown_block_16[111]; int unknown_block_16[111];
#else #else
int unknown_block_16[116]; // linux +5 more int unknown_block_16[116]; // linux +5 more
@ -263,7 +263,7 @@ public:
void PutInServer(); void PutInServer();
void Disconnect(); void Disconnect();
void killPlayer(); void killPlayer();
void setTeamName( char *szName ); void setTeamName( const char *szName );
void getTeamName( char *szName ); void getTeamName( char *szName );
inline bool IsBot(){ inline bool IsBot(){

View File

@ -1,67 +1,123 @@
#(C)2004-2005 AMX Mod X Development Team # (C)2004-2013 AMX Mod X Development Team
# Makefile written by David "BAILOPAN" Anderson # Makefile written by David "BAILOPAN" Anderson
HLSDK = ../../../../hlsdk ###########################################
### EDIT THESE PATHS FOR YOUR OWN SETUP ###
###########################################
HLSDK = ../../../../hlsdk/multiplayer
MM_ROOT = ../../../../metamod/metamod MM_ROOT = ../../../../metamod/metamod
#####################################
### EDIT BELOW FOR OTHER PROJECTS ### ### EDIT BELOW FOR OTHER PROJECTS ###
#####################################
OPT_FLAGS = -O3 -funroll-loops -s -pipe -fno-strict-aliasing PROJECT = dodfun
DEBUG_FLAGS = -g -ggdb3
CPP = gcc-4.1
NAME = dodfun
BIN_SUFFIX = amxx_i386.so
OBJECTS = sdk/amxxmodule.cpp NBase.cpp CMisc.cpp NPD.cpp Utils.cpp usermsg.cpp moduleconfig.cpp OBJECTS = sdk/amxxmodule.cpp NBase.cpp CMisc.cpp NPD.cpp Utils.cpp usermsg.cpp moduleconfig.cpp
##############################################
### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
##############################################
C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -fomit-frame-pointer -pipe
C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3
C_GCC4_FLAGS = -fvisibility=hidden
CPP_GCC4_FLAGS = -fvisibility-inlines-hidden
CPP = gcc
CPP_OSX = clang
LINK = LINK =
INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared -I$(HLSDK)/game_shared \ INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/common -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared \
-I$(MM_ROOT) -I$(HLSDK)/common -Isdk -I$(MM_ROOT) -Isdk
GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) ################################################
### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ###
################################################
ifeq "$(GCC_VERSION)" "4" OS := $(shell uname -s)
OPT_FLAGS += -fvisibility=hidden -fvisibility-inlines-hidden
ifeq "$(OS)" "Darwin"
CPP = $(CPP_OSX)
LIB_EXT = dylib
LIB_SUFFIX = _amxx
CFLAGS += -DOSX
LINK += -dynamiclib -lstdc++ -mmacosx-version-min=10.5
else
LIB_EXT = so
LIB_SUFFIX = _amxx_i386
CFLAGS += -DLINUX
LINK += -shared
endif endif
LINK += -m32 -lm -ldl
CFLAGS += -DPAWN_CELL_SIZE=32 -DJIT -DASM32 -DHAVE_STDINT_H -fno-strict-aliasing -m32 -Wall -Werror
CPPFLAGS += -fno-exceptions -fno-rtti
BINARY = $(PROJECT)$(LIB_SUFFIX).$(LIB_EXT)
ifeq "$(DEBUG)" "true" ifeq "$(DEBUG)" "true"
BIN_DIR = Debug BIN_DIR = Debug
CFLAGS = $(DEBUG_FLAGS) CFLAGS += $(C_DEBUG_FLAGS)
else else
BIN_DIR = Release BIN_DIR = Release
CFLAGS = $(OPT_FLAGS) CFLAGS += $(C_OPT_FLAGS)
LINK += -s
endif endif
CFLAGS += -DNDEBUG -Wall -Wno-non-virtual-dtor -Werror -fno-exceptions -DHAVE_STDINT_H -static-libgcc -fno-rtti -m32 IS_CLANG := $(shell $(CPP) --version | head -1 | grep clang > /dev/null && echo "1" || echo "0")
BINARY = $(NAME)_$(BIN_SUFFIX) ifeq "$(IS_CLANG)" "1"
CFLAGS += -DPAWN_CELL_SIZE=32 -DJIT -DASM32 CPP_MAJOR := $(shell $(CPP) --version | grep clang | sed "s/.*version \([0-9]\)*\.[0-9]*.*/\1/")
OPT_FLAGS += -march=i586 CPP_MINOR := $(shell $(CPP) --version | grep clang | sed "s/.*version [0-9]*\.\([0-9]\)*.*/\1/")
else
CPP_MAJOR := $(shell $(CPP) -dumpversion >&1 | cut -b1)
CPP_MINOR := $(shell $(CPP) -dumpversion >&1 | cut -b3)
endif
OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) # Clang || GCC >= 4
ifeq "$(shell expr $(IS_CLANG) \| $(CPP_MAJOR) \>= 4)" "1"
CFLAGS += $(C_GCC4_FLAGS)
CPPFLAGS += $(CPP_GCC4_FLAGS)
endif
# Clang >= 3 || GCC >= 4.7
ifeq "$(shell expr $(IS_CLANG) \& $(CPP_MAJOR) \>= 3 \| $(CPP_MAJOR) \>= 4 \& $(CPP_MINOR) \>= 7)" "1"
CFLAGS += -Wno-delete-non-virtual-dtor
endif
# OS is Linux and not using clang
ifeq "$(shell expr $(OS) \= Linux \& $(IS_CLANG) \= 0)" "1"
LINK += -static-libgcc
endif
OBJ_BIN := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o)
# This will break if we include other Makefiles, but is fine for now. It allows
# us to make a copy of this file that uses altered paths (ie. Makefile.mine)
# or other changes without mucking up the original.
MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
$(BIN_DIR)/%.o: %.cpp $(BIN_DIR)/%.o: %.cpp
$(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $< $(CPP) $(INCLUDE) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
all: all:
mkdir -p $(BIN_DIR) mkdir -p $(BIN_DIR)
mkdir -p $(BIN_DIR)/sdk mkdir -p $(BIN_DIR)/sdk
$(MAKE) dodfun $(MAKE) -f $(MAKEFILE_NAME) $(PROJECT)
dodfun: $(OBJ_LINUX) $(PROJECT): $(OBJ_BIN)
$(CPP) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) $(CPP) $(INCLUDE) $(OBJ_BIN) $(LINK) -o $(BIN_DIR)/$(BINARY)
debug: debug:
$(MAKE) all DEBUG=true $(MAKE) -f $(MAKEFILE_NAME) all DEBUG=true
default: all default: all
clean: clean:
rm -rf Release/sdk/*.o rm -rf $(BIN_DIR)/*.o
rm -rf Release/*.o rm -rf $(BIN_DIR)/sdk/*.o
rm -rf Release/$(NAME)_$(BIN_SUFFIX) rm -f $(BIN_DIR)/$(BINARY)
rm -rf Debug/sdk/*.o
rm -rf Debug/*.o
rm -rf Debug/$(NAME)_$(BIN_SUFFIX)

View File

@ -2240,7 +2240,7 @@ static META_FUNCTIONS g_MetaFunctions_Table =
GetEngineFunctions_Post GetEngineFunctions_Post
}; };
C_DLLEXPORT int Meta_Query(char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs) C_DLLEXPORT int Meta_Query(const char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs)
{ {
if ((int) CVAR_GET_FLOAT("developer") != 0) if ((int) CVAR_GET_FLOAT("developer") != 0)
UTIL_LogPrintf("[%s] dev: called: Meta_Query; version=%s, ours=%s\n", UTIL_LogPrintf("[%s] dev: called: Meta_Query; version=%s, ours=%s\n",
@ -2334,7 +2334,7 @@ C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
// linux prototype // linux prototype
C_DLLEXPORT void GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals ) { C_DLLEXPORT void GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals ) {
@ -3050,7 +3050,7 @@ char* UTIL_VarArgs( char *format, ... )
// UTIL_LogPrintf - Prints a logged message to console. // UTIL_LogPrintf - Prints a logged message to console.
// Preceded by LOG: ( timestamp ) < message > // Preceded by LOG: ( timestamp ) < message >
//========================================================= //=========================================================
void UTIL_LogPrintf( char *fmt, ... ) void UTIL_LogPrintf( const char *fmt, ... )
{ {
va_list argptr; va_list argptr;
static char string[1024]; static char string[1024];

View File

@ -20,11 +20,16 @@
// DLL Export // DLL Export
#undef DLLEXPORT #undef DLLEXPORT
#ifndef __linux__ #if defined(_WIN32)
#define DLLEXPORT __declspec(dllexport) #define DLLEXPORT __declspec(dllexport)
#else #else
#define DLLEXPORT __attribute__((visibility("default"))) #define DLLEXPORT __attribute__((visibility("default")))
#endif
#if defined(__linux__) && !defined(LINUX)
#define LINUX #define LINUX
#elif defined(__APPLE__) && !defined(OSX)
#define OSX
#endif #endif
#undef C_DLLEXPORT #undef C_DLLEXPORT
@ -66,7 +71,7 @@ struct amxx_module_info_s
#if defined HAVE_STDINT_H #if defined HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#else #else
#if defined __LCC__ || defined __DMC__ || defined LINUX #if defined __LCC__ || defined __DMC__ || defined LINUX || defined __APPLE__
#if defined HAVE_INTTYPES_H #if defined HAVE_INTTYPES_H
#include <inttypes.h> #include <inttypes.h>
#else #else
@ -308,7 +313,7 @@ typedef int (AMXAPI *AMX_DEBUG)(struct tagAMX *amx);
#endif #endif
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__ #if defined LINUX || defined __FreeBSD__ || defined __APPLE__
#pragma pack(1) /* structures must be packed (byte-aligned) */ #pragma pack(1) /* structures must be packed (byte-aligned) */
#elif defined MACOS && defined __MWERKS__ #elif defined MACOS && defined __MWERKS__
#pragma options align=mac68k #pragma options align=mac68k
@ -395,7 +400,7 @@ enum {
}; };
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined __linux__ #if defined(__linux__) || defined(__APPLE__)
#pragma pack() /* reset default packing */ #pragma pack() /* reset default packing */
#else #else
#pragma pack(pop) /* reset previous packing */ #pragma pack(pop) /* reset previous packing */
@ -406,7 +411,7 @@ enum {
// ***** declare functions ***** // ***** declare functions *****
#ifdef USE_METAMOD #ifdef USE_METAMOD
void UTIL_LogPrintf( char *fmt, ... ); void UTIL_LogPrintf( const char *fmt, ... );
void UTIL_HudMessage(CBaseEntity *pEntity, const hudtextparms_t &textparms, const char *pMessage); void UTIL_HudMessage(CBaseEntity *pEntity, const hudtextparms_t &textparms, const char *pMessage);
short FixedSigned16( float value, float scale ); short FixedSigned16( float value, float scale );
unsigned short FixedUnsigned16( float value, float scale ); unsigned short FixedUnsigned16( float value, float scale );
@ -833,11 +838,11 @@ int FN_AllowLagCompensation_Post(void);
#ifdef FN_PrecacheModel #ifdef FN_PrecacheModel
int FN_PrecacheModel(char *s); int FN_PrecacheModel(const char *s);
#endif // FN_PrecacheModel #endif // FN_PrecacheModel
#ifdef FN_PrecacheSound #ifdef FN_PrecacheSound
int FN_PrecacheSound(char *s); int FN_PrecacheSound(const char *s);
#endif // FN_PrecacheSound #endif // FN_PrecacheSound
#ifdef FN_SetModel #ifdef FN_SetModel
@ -857,7 +862,7 @@ void FN_SetSize(edict_t *e, const float *rgflMin, const float *rgflMax);
#endif // FN_SetSize #endif // FN_SetSize
#ifdef FN_ChangeLevel #ifdef FN_ChangeLevel
void FN_ChangeLevel(char *s1, char *s2); void FN_ChangeLevel(const char *s1, const char *s2);
#endif // FN_ChangeLevel #endif // FN_ChangeLevel
#ifdef FN_GetSpawnParms #ifdef FN_GetSpawnParms
@ -1261,19 +1266,19 @@ char *FN_GetInfoKeyBuffer(edict_t *e);
#endif // FN_GetInfoKeyBuffer #endif // FN_GetInfoKeyBuffer
#ifdef FN_InfoKeyValue #ifdef FN_InfoKeyValue
char *FN_InfoKeyValue(char *infobuffer, char *key); char *FN_InfoKeyValue(char *infobuffer, const char *key);
#endif // FN_InfoKeyValue #endif // FN_InfoKeyValue
#ifdef FN_SetKeyValue #ifdef FN_SetKeyValue
void FN_SetKeyValue(char *infobuffer, char *key, char *value); void FN_SetKeyValue(char *infobuffer, const char *key, const char *value);
#endif // FN_SetKeyValue #endif // FN_SetKeyValue
#ifdef FN_SetClientKeyValue #ifdef FN_SetClientKeyValue
void FN_SetClientKeyValue(int clientIndex, char *infobuffer, char *key, char *value); void FN_SetClientKeyValue(int clientIndex, char *infobuffer, const char *key, const char *value);
#endif // FN_SetClientKeyValue #endif // FN_SetClientKeyValue
#ifdef FN_IsMapValid #ifdef FN_IsMapValid
int FN_IsMapValid(char *filename); int FN_IsMapValid(const char *filename);
#endif // FN_IsMapValid #endif // FN_IsMapValid
#ifdef FN_StaticDecal #ifdef FN_StaticDecal
@ -1281,7 +1286,7 @@ void FN_StaticDecal(const float *origin, int decalIndex, int entityIndex, int mo
#endif // FN_StaticDecal #endif // FN_StaticDecal
#ifdef FN_PrecacheGeneric #ifdef FN_PrecacheGeneric
int FN_PrecacheGeneric(char *s); int FN_PrecacheGeneric(const char *s);
#endif // FN_PrecacheGeneric #endif // FN_PrecacheGeneric
#ifdef FN_GetPlayerUserId #ifdef FN_GetPlayerUserId
@ -1414,11 +1419,11 @@ const char *FN_GetPlayerAuthId(edict_t *e);
#ifdef FN_PrecacheModel_Post #ifdef FN_PrecacheModel_Post
int FN_PrecacheModel_Post(char *s); int FN_PrecacheModel_Post(const char *s);
#endif // FN_PrecacheModel_Post #endif // FN_PrecacheModel_Post
#ifdef FN_PrecacheSound_Post #ifdef FN_PrecacheSound_Post
int FN_PrecacheSound_Post(char *s); int FN_PrecacheSound_Post(const char *s);
#endif // FN_PrecacheSound_Post #endif // FN_PrecacheSound_Post
#ifdef FN_SetModel_Post #ifdef FN_SetModel_Post
@ -1438,7 +1443,7 @@ void FN_SetSize_Post(edict_t *e, const float *rgflMin, const float *rgflMax);
#endif // FN_SetSize_Post #endif // FN_SetSize_Post
#ifdef FN_ChangeLevel_Post #ifdef FN_ChangeLevel_Post
void FN_ChangeLevel_Post(char *s1, char *s2); void FN_ChangeLevel_Post(const char *s1, const char *s2);
#endif // FN_ChangeLevel_Post #endif // FN_ChangeLevel_Post
#ifdef FN_GetSpawnParms_Post #ifdef FN_GetSpawnParms_Post
@ -1842,19 +1847,19 @@ char *FN_GetInfoKeyBuffer_Post(edict_t *e);
#endif // FN_GetInfoKeyBuffer_Post #endif // FN_GetInfoKeyBuffer_Post
#ifdef FN_InfoKeyValue_Post #ifdef FN_InfoKeyValue_Post
char *FN_InfoKeyValue_Post(char *infobuffer, char *key); char *FN_InfoKeyValue_Post(char *infobuffer, const char *key);
#endif // FN_InfoKeyValue_Post #endif // FN_InfoKeyValue_Post
#ifdef FN_SetKeyValue_Post #ifdef FN_SetKeyValue_Post
void FN_SetKeyValue_Post(char *infobuffer, char *key, char *value); void FN_SetKeyValue_Post(char *infobuffer, const char *key, const char *value);
#endif // FN_SetKeyValue_Post #endif // FN_SetKeyValue_Post
#ifdef FN_SetClientKeyValue_Post #ifdef FN_SetClientKeyValue_Post
void FN_SetClientKeyValue_Post(int clientIndex, char *infobuffer, char *key, char *value); void FN_SetClientKeyValue_Post(int clientIndex, char *infobuffer, const char *key, const char *value);
#endif // FN_SetClientKeyValue_Post #endif // FN_SetClientKeyValue_Post
#ifdef FN_IsMapValid_Post #ifdef FN_IsMapValid_Post
int FN_IsMapValid_Post(char *filename); int FN_IsMapValid_Post(const char *filename);
#endif // FN_IsMapValid_Post #endif // FN_IsMapValid_Post
#ifdef FN_StaticDecal_Post #ifdef FN_StaticDecal_Post
@ -1862,7 +1867,7 @@ void FN_StaticDecal_Post(const float *origin, int decalIndex, int entityIndex, i
#endif // FN_StaticDecal_Post #endif // FN_StaticDecal_Post
#ifdef FN_PrecacheGeneric_Post #ifdef FN_PrecacheGeneric_Post
int FN_PrecacheGeneric_Post(char *s); int FN_PrecacheGeneric_Post(const char *s);
#endif // FN_PrecacheGeneric_Post #endif // FN_PrecacheGeneric_Post
#ifdef FN_GetPlayerUserId_Post #ifdef FN_GetPlayerUserId_Post
@ -2116,7 +2121,7 @@ typedef int (*PFN_ADD_NEW_NATIVES) (const AMX_NATIVE_INFO * /*list*/);
typedef char * (*PFN_BUILD_PATHNAME) (const char * /*format*/, ...); typedef char * (*PFN_BUILD_PATHNAME) (const char * /*format*/, ...);
typedef char * (*PFN_BUILD_PATHNAME_R) (char * /*buffer*/, size_t /* maxlen */, const char * /* format */, ...); typedef char * (*PFN_BUILD_PATHNAME_R) (char * /*buffer*/, size_t /* maxlen */, const char * /* format */, ...);
typedef cell * (*PFN_GET_AMXADDR) (AMX * /*amx*/, cell /*offset*/); typedef cell * (*PFN_GET_AMXADDR) (AMX * /*amx*/, cell /*offset*/);
typedef void (*PFN_PRINT_SRVCONSOLE) (char * /*format*/, ...); typedef void (*PFN_PRINT_SRVCONSOLE) (const char * /*format*/, ...);
typedef const char * (*PFN_GET_MODNAME) (void); typedef const char * (*PFN_GET_MODNAME) (void);
typedef const char * (*PFN_GET_AMXSCRIPTNAME) (int /*id*/); typedef const char * (*PFN_GET_AMXSCRIPTNAME) (int /*id*/);
typedef AMX * (*PFN_GET_AMXSCRIPT) (int /*id*/); typedef AMX * (*PFN_GET_AMXSCRIPT) (int /*id*/);
@ -2175,8 +2180,8 @@ typedef void (*PFN_DEALLOCATOR) (const char* /*filename*/, const unsigned i
typedef int (*PFN_AMX_EXEC) (AMX* /*amx*/, cell* /*return val*/, int /*index*/); typedef int (*PFN_AMX_EXEC) (AMX* /*amx*/, cell* /*return val*/, int /*index*/);
typedef int (*PFN_AMX_EXECV) (AMX* /*amx*/, cell* /*return val*/, int /*index*/, int /*numparams*/, cell[] /*params*/); typedef int (*PFN_AMX_EXECV) (AMX* /*amx*/, cell* /*return val*/, int /*index*/, int /*numparams*/, cell[] /*params*/);
typedef int (*PFN_AMX_ALLOT) (AMX* /*amx*/, int /*length*/, cell* /*amx_addr*/, cell** /*phys_addr*/); typedef int (*PFN_AMX_ALLOT) (AMX* /*amx*/, int /*length*/, cell* /*amx_addr*/, cell** /*phys_addr*/);
typedef int (*PFN_AMX_FINDPUBLIC) (AMX* /*amx*/, char* /*func name*/, int* /*index*/); typedef int (*PFN_AMX_FINDPUBLIC) (AMX* /*amx*/, const char* /*func name*/, int* /*index*/);
typedef int (*PFN_AMX_FINDNATIVE) (AMX* /*amx*/, char* /*func name*/, int* /*index*/); typedef int (*PFN_AMX_FINDNATIVE) (AMX* /*amx*/, const char* /*func name*/, int* /*index*/);
typedef int (*PFN_LOAD_AMXSCRIPT) (AMX* /*amx*/, void** /*code*/, const char* /*path*/, char[64] /*error info*/, int /* debug */); typedef int (*PFN_LOAD_AMXSCRIPT) (AMX* /*amx*/, void** /*code*/, const char* /*path*/, char[64] /*error info*/, int /* debug */);
typedef int (*PFN_UNLOAD_AMXSCRIPT) (AMX* /*amx*/,void** /*code*/); typedef int (*PFN_UNLOAD_AMXSCRIPT) (AMX* /*amx*/,void** /*code*/);
typedef cell (*PFN_REAL_TO_CELL) (REAL /*x*/); typedef cell (*PFN_REAL_TO_CELL) (REAL /*x*/);

View File

@ -37,7 +37,7 @@
#define DODMAX_CUSTOMWPNS 5 // custom weapons #define DODMAX_CUSTOMWPNS 5 // custom weapons
#define DODMAX_WEAPONS 42 + DODMAX_CUSTOMWPNS #define DODMAX_WEAPONS 42 + DODMAX_CUSTOMWPNS
#ifndef __linux__ #if defined(_WIN32)
#define LINUXOFFSET 0 #define LINUXOFFSET 0
#else #else
#define LINUXOFFSET 5 #define LINUXOFFSET 5

View File

@ -1,67 +1,123 @@
#(C)2004-2005 AMX Mod X Development Team # (C)2004-2013 AMX Mod X Development Team
# Makefile written by David "BAILOPAN" Anderson # Makefile written by David "BAILOPAN" Anderson
HLSDK = ../../../../hlsdk ###########################################
### EDIT THESE PATHS FOR YOUR OWN SETUP ###
###########################################
HLSDK = ../../../../hlsdk/multiplayer
MM_ROOT = ../../../../metamod/metamod MM_ROOT = ../../../../metamod/metamod
#####################################
### EDIT BELOW FOR OTHER PROJECTS ### ### EDIT BELOW FOR OTHER PROJECTS ###
#####################################
OPT_FLAGS = -O3 -funroll-loops -s -pipe -fno-strict-aliasing PROJECT = dodx
DEBUG_FLAGS = -g -ggdb3
CPP = gcc-4.1
NAME = dodx
BIN_SUFFIX = amxx_i386.so
OBJECTS = sdk/amxxmodule.cpp CRank.cpp CMisc.cpp NBase.cpp NRank.cpp usermsg.cpp Utils.cpp moduleconfig.cpp OBJECTS = sdk/amxxmodule.cpp CRank.cpp CMisc.cpp NBase.cpp NRank.cpp usermsg.cpp Utils.cpp moduleconfig.cpp
##############################################
### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
##############################################
C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -fomit-frame-pointer -pipe
C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3
C_GCC4_FLAGS = -fvisibility=hidden
CPP_GCC4_FLAGS = -fvisibility-inlines-hidden
CPP = gcc
CPP_OSX = clang
LINK = LINK =
INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared -I$(HLSDK)/game_shared \ INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/common -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared \
-I$(MM_ROOT) -I$(HLSDK)/common -Isdk -I$(MM_ROOT) -Isdk
GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) ################################################
### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ###
################################################
ifeq "$(GCC_VERSION)" "4" OS := $(shell uname -s)
OPT_FLAGS += -fvisibility=hidden -fvisibility-inlines-hidden
ifeq "$(OS)" "Darwin"
CPP = $(CPP_OSX)
LIB_EXT = dylib
LIB_SUFFIX = _amxx
CFLAGS += -DOSX
LINK += -dynamiclib -lstdc++ -mmacosx-version-min=10.5
else
LIB_EXT = so
LIB_SUFFIX = _amxx_i386
CFLAGS += -DLINUX
LINK += -shared
endif endif
LINK += -m32 -lm -ldl
CFLAGS += -DPAWN_CELL_SIZE=32 -DJIT -DASM32 -DHAVE_STDINT_H -fno-strict-aliasing -m32 -Wall -Werror
CPPFLAGS += -fno-exceptions -fno-rtti
BINARY = $(PROJECT)$(LIB_SUFFIX).$(LIB_EXT)
ifeq "$(DEBUG)" "true" ifeq "$(DEBUG)" "true"
BIN_DIR = Debug BIN_DIR = Debug
CFLAGS = $(DEBUG_FLAGS) CFLAGS += $(C_DEBUG_FLAGS)
else else
BIN_DIR = Release BIN_DIR = Release
CFLAGS = $(OPT_FLAGS) CFLAGS += $(C_OPT_FLAGS)
LINK += -s
endif endif
CFLAGS += -DNDEBUG -Wall -Wno-non-virtual-dtor -Werror -fno-exceptions -DHAVE_STDINT_H -static-libgcc -fno-rtti -m32 IS_CLANG := $(shell $(CPP) --version | head -1 | grep clang > /dev/null && echo "1" || echo "0")
BINARY = $(NAME)_$(BIN_SUFFIX) ifeq "$(IS_CLANG)" "1"
CFLAGS += -DPAWN_CELL_SIZE=32 -DJIT -DASM32 CPP_MAJOR := $(shell $(CPP) --version | grep clang | sed "s/.*version \([0-9]\)*\.[0-9]*.*/\1/")
OPT_FLAGS += -march=i586 CPP_MINOR := $(shell $(CPP) --version | grep clang | sed "s/.*version [0-9]*\.\([0-9]\)*.*/\1/")
else
CPP_MAJOR := $(shell $(CPP) -dumpversion >&1 | cut -b1)
CPP_MINOR := $(shell $(CPP) -dumpversion >&1 | cut -b3)
endif
OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) # Clang || GCC >= 4
ifeq "$(shell expr $(IS_CLANG) \| $(CPP_MAJOR) \>= 4)" "1"
CFLAGS += $(C_GCC4_FLAGS)
CPPFLAGS += $(CPP_GCC4_FLAGS)
endif
# Clang >= 3 || GCC >= 4.7
ifeq "$(shell expr $(IS_CLANG) \& $(CPP_MAJOR) \>= 3 \| $(CPP_MAJOR) \>= 4 \& $(CPP_MINOR) \>= 7)" "1"
CFLAGS += -Wno-delete-non-virtual-dtor
endif
# OS is Linux and not using clang
ifeq "$(shell expr $(OS) \= Linux \& $(IS_CLANG) \= 0)" "1"
LINK += -static-libgcc
endif
OBJ_BIN := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o)
# This will break if we include other Makefiles, but is fine for now. It allows
# us to make a copy of this file that uses altered paths (ie. Makefile.mine)
# or other changes without mucking up the original.
MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
$(BIN_DIR)/%.o: %.cpp $(BIN_DIR)/%.o: %.cpp
$(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $< $(CPP) $(INCLUDE) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
all: all:
mkdir -p $(BIN_DIR) mkdir -p $(BIN_DIR)
mkdir -p $(BIN_DIR)/sdk mkdir -p $(BIN_DIR)/sdk
$(MAKE) dodx $(MAKE) -f $(MAKEFILE_NAME) $(PROJECT)
dodx: $(OBJ_LINUX) $(PROJECT): $(OBJ_BIN)
$(CPP) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) $(CPP) $(INCLUDE) $(OBJ_BIN) $(LINK) -o $(BIN_DIR)/$(BINARY)
debug: debug:
$(MAKE) all DEBUG=true $(MAKE) -f $(MAKEFILE_NAME) all DEBUG=true
default: all default: all
clean: clean:
rm -rf Release/sdk/*.o rm -rf $(BIN_DIR)/*.o
rm -rf Release/*.o rm -rf $(BIN_DIR)/sdk/*.o
rm -rf Release/$(NAME)_$(BIN_SUFFIX) rm -f $(BIN_DIR)/$(BINARY)
rm -rf Debug/sdk/*.o
rm -rf Debug/*.o
rm -rf Debug/$(NAME)_$(BIN_SUFFIX)

View File

@ -490,7 +490,7 @@ static cell AMX_NATIVE_CALL get_user_team(AMX *amx, cell *params)
if ( params[3] ) if ( params[3] )
{ {
char *szTeam = ""; const char *szTeam = "";
switch(iTeam) switch(iTeam)
{ {
case 1: case 1:

View File

@ -430,7 +430,7 @@ void DispatchKeyValue_Post( edict_t *pentKeyvalue, KeyValueData *pkvd )
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);
} }
void SetClientKeyValue(int id, char *protocol, char *type, char *var) void SetClientKeyValue(int id, char *protocol, const char *type, const char *var)
{ {
// ID: Number // ID: Number
// protocol: \name\Sgt.MEOW\topcolor\1\bottomcolor\1\cl_lw\1\team\axis\model\axis-inf // protocol: \name\Sgt.MEOW\topcolor\1\bottomcolor\1\cl_lw\1\team\axis\model\axis-inf

View File

@ -2240,7 +2240,7 @@ static META_FUNCTIONS g_MetaFunctions_Table =
GetEngineFunctions_Post GetEngineFunctions_Post
}; };
C_DLLEXPORT int Meta_Query(char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs) C_DLLEXPORT int Meta_Query(const char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs)
{ {
if ((int) CVAR_GET_FLOAT("developer") != 0) if ((int) CVAR_GET_FLOAT("developer") != 0)
UTIL_LogPrintf("[%s] dev: called: Meta_Query; version=%s, ours=%s\n", UTIL_LogPrintf("[%s] dev: called: Meta_Query; version=%s, ours=%s\n",
@ -2334,7 +2334,7 @@ C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
// linux prototype // linux prototype
C_DLLEXPORT void GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals ) { C_DLLEXPORT void GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals ) {
@ -3050,7 +3050,7 @@ char* UTIL_VarArgs( char *format, ... )
// UTIL_LogPrintf - Prints a logged message to console. // UTIL_LogPrintf - Prints a logged message to console.
// Preceded by LOG: ( timestamp ) < message > // Preceded by LOG: ( timestamp ) < message >
//========================================================= //=========================================================
void UTIL_LogPrintf( char *fmt, ... ) void UTIL_LogPrintf( const char *fmt, ... )
{ {
va_list argptr; va_list argptr;
static char string[1024]; static char string[1024];

View File

@ -20,11 +20,16 @@
// DLL Export // DLL Export
#undef DLLEXPORT #undef DLLEXPORT
#ifndef __linux__ #if defined(_WIN32)
#define DLLEXPORT __declspec(dllexport) #define DLLEXPORT __declspec(dllexport)
#else #else
#define DLLEXPORT __attribute__((visibility("default"))) #define DLLEXPORT __attribute__((visibility("default")))
#endif
#if defined(__linux__) && !defined(LINUX)
#define LINUX #define LINUX
#elif defined(__APPLE__) && !defined(OSX)
#define OSX
#endif #endif
#undef C_DLLEXPORT #undef C_DLLEXPORT
@ -66,7 +71,7 @@ struct amxx_module_info_s
#if defined HAVE_STDINT_H #if defined HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#else #else
#if defined __LCC__ || defined __DMC__ || defined LINUX #if defined __LCC__ || defined __DMC__ || defined LINUX || defined __APPLE__
#if defined HAVE_INTTYPES_H #if defined HAVE_INTTYPES_H
#include <inttypes.h> #include <inttypes.h>
#else #else
@ -308,7 +313,7 @@ typedef int (AMXAPI *AMX_DEBUG)(struct tagAMX *amx);
#endif #endif
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__ #if defined LINUX || defined __FreeBSD__ || defined __APPLE__
#pragma pack(1) /* structures must be packed (byte-aligned) */ #pragma pack(1) /* structures must be packed (byte-aligned) */
#elif defined MACOS && defined __MWERKS__ #elif defined MACOS && defined __MWERKS__
#pragma options align=mac68k #pragma options align=mac68k
@ -395,7 +400,7 @@ enum {
}; };
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined __linux__ #if defined(__linux__) || defined(__APPLE__)
#pragma pack() /* reset default packing */ #pragma pack() /* reset default packing */
#else #else
#pragma pack(pop) /* reset previous packing */ #pragma pack(pop) /* reset previous packing */
@ -406,7 +411,7 @@ enum {
// ***** declare functions ***** // ***** declare functions *****
#ifdef USE_METAMOD #ifdef USE_METAMOD
void UTIL_LogPrintf( char *fmt, ... ); void UTIL_LogPrintf( const char *fmt, ... );
void UTIL_HudMessage(CBaseEntity *pEntity, const hudtextparms_t &textparms, const char *pMessage); void UTIL_HudMessage(CBaseEntity *pEntity, const hudtextparms_t &textparms, const char *pMessage);
short FixedSigned16( float value, float scale ); short FixedSigned16( float value, float scale );
unsigned short FixedUnsigned16( float value, float scale ); unsigned short FixedUnsigned16( float value, float scale );
@ -833,11 +838,11 @@ int FN_AllowLagCompensation_Post(void);
#ifdef FN_PrecacheModel #ifdef FN_PrecacheModel
int FN_PrecacheModel(char *s); int FN_PrecacheModel(const char *s);
#endif // FN_PrecacheModel #endif // FN_PrecacheModel
#ifdef FN_PrecacheSound #ifdef FN_PrecacheSound
int FN_PrecacheSound(char *s); int FN_PrecacheSound(const char *s);
#endif // FN_PrecacheSound #endif // FN_PrecacheSound
#ifdef FN_SetModel #ifdef FN_SetModel
@ -857,7 +862,7 @@ void FN_SetSize(edict_t *e, const float *rgflMin, const float *rgflMax);
#endif // FN_SetSize #endif // FN_SetSize
#ifdef FN_ChangeLevel #ifdef FN_ChangeLevel
void FN_ChangeLevel(char *s1, char *s2); void FN_ChangeLevel(const char *s1, const char *s2);
#endif // FN_ChangeLevel #endif // FN_ChangeLevel
#ifdef FN_GetSpawnParms #ifdef FN_GetSpawnParms
@ -1261,19 +1266,19 @@ char *FN_GetInfoKeyBuffer(edict_t *e);
#endif // FN_GetInfoKeyBuffer #endif // FN_GetInfoKeyBuffer
#ifdef FN_InfoKeyValue #ifdef FN_InfoKeyValue
char *FN_InfoKeyValue(char *infobuffer, char *key); char *FN_InfoKeyValue(char *infobuffer, const char *key);
#endif // FN_InfoKeyValue #endif // FN_InfoKeyValue
#ifdef FN_SetKeyValue #ifdef FN_SetKeyValue
void FN_SetKeyValue(char *infobuffer, char *key, char *value); void FN_SetKeyValue(char *infobuffer, const char *key, const char *value);
#endif // FN_SetKeyValue #endif // FN_SetKeyValue
#ifdef FN_SetClientKeyValue #ifdef FN_SetClientKeyValue
void FN_SetClientKeyValue(int clientIndex, char *infobuffer, char *key, char *value); void FN_SetClientKeyValue(int clientIndex, char *infobuffer, const char *key, const char *value);
#endif // FN_SetClientKeyValue #endif // FN_SetClientKeyValue
#ifdef FN_IsMapValid #ifdef FN_IsMapValid
int FN_IsMapValid(char *filename); int FN_IsMapValid(const char *filename);
#endif // FN_IsMapValid #endif // FN_IsMapValid
#ifdef FN_StaticDecal #ifdef FN_StaticDecal
@ -1281,7 +1286,7 @@ void FN_StaticDecal(const float *origin, int decalIndex, int entityIndex, int mo
#endif // FN_StaticDecal #endif // FN_StaticDecal
#ifdef FN_PrecacheGeneric #ifdef FN_PrecacheGeneric
int FN_PrecacheGeneric(char *s); int FN_PrecacheGeneric(const char *s);
#endif // FN_PrecacheGeneric #endif // FN_PrecacheGeneric
#ifdef FN_GetPlayerUserId #ifdef FN_GetPlayerUserId
@ -1414,11 +1419,11 @@ const char *FN_GetPlayerAuthId(edict_t *e);
#ifdef FN_PrecacheModel_Post #ifdef FN_PrecacheModel_Post
int FN_PrecacheModel_Post(char *s); int FN_PrecacheModel_Post(const char *s);
#endif // FN_PrecacheModel_Post #endif // FN_PrecacheModel_Post
#ifdef FN_PrecacheSound_Post #ifdef FN_PrecacheSound_Post
int FN_PrecacheSound_Post(char *s); int FN_PrecacheSound_Post(const char *s);
#endif // FN_PrecacheSound_Post #endif // FN_PrecacheSound_Post
#ifdef FN_SetModel_Post #ifdef FN_SetModel_Post
@ -1438,7 +1443,7 @@ void FN_SetSize_Post(edict_t *e, const float *rgflMin, const float *rgflMax);
#endif // FN_SetSize_Post #endif // FN_SetSize_Post
#ifdef FN_ChangeLevel_Post #ifdef FN_ChangeLevel_Post
void FN_ChangeLevel_Post(char *s1, char *s2); void FN_ChangeLevel_Post(const char *s1, const char *s2);
#endif // FN_ChangeLevel_Post #endif // FN_ChangeLevel_Post
#ifdef FN_GetSpawnParms_Post #ifdef FN_GetSpawnParms_Post
@ -1842,19 +1847,19 @@ char *FN_GetInfoKeyBuffer_Post(edict_t *e);
#endif // FN_GetInfoKeyBuffer_Post #endif // FN_GetInfoKeyBuffer_Post
#ifdef FN_InfoKeyValue_Post #ifdef FN_InfoKeyValue_Post
char *FN_InfoKeyValue_Post(char *infobuffer, char *key); char *FN_InfoKeyValue_Post(char *infobuffer, const char *key);
#endif // FN_InfoKeyValue_Post #endif // FN_InfoKeyValue_Post
#ifdef FN_SetKeyValue_Post #ifdef FN_SetKeyValue_Post
void FN_SetKeyValue_Post(char *infobuffer, char *key, char *value); void FN_SetKeyValue_Post(char *infobuffer, const char *key, const char *value);
#endif // FN_SetKeyValue_Post #endif // FN_SetKeyValue_Post
#ifdef FN_SetClientKeyValue_Post #ifdef FN_SetClientKeyValue_Post
void FN_SetClientKeyValue_Post(int clientIndex, char *infobuffer, char *key, char *value); void FN_SetClientKeyValue_Post(int clientIndex, char *infobuffer, const char *key, const char *value);
#endif // FN_SetClientKeyValue_Post #endif // FN_SetClientKeyValue_Post
#ifdef FN_IsMapValid_Post #ifdef FN_IsMapValid_Post
int FN_IsMapValid_Post(char *filename); int FN_IsMapValid_Post(const char *filename);
#endif // FN_IsMapValid_Post #endif // FN_IsMapValid_Post
#ifdef FN_StaticDecal_Post #ifdef FN_StaticDecal_Post
@ -1862,7 +1867,7 @@ void FN_StaticDecal_Post(const float *origin, int decalIndex, int entityIndex, i
#endif // FN_StaticDecal_Post #endif // FN_StaticDecal_Post
#ifdef FN_PrecacheGeneric_Post #ifdef FN_PrecacheGeneric_Post
int FN_PrecacheGeneric_Post(char *s); int FN_PrecacheGeneric_Post(const char *s);
#endif // FN_PrecacheGeneric_Post #endif // FN_PrecacheGeneric_Post
#ifdef FN_GetPlayerUserId_Post #ifdef FN_GetPlayerUserId_Post
@ -2116,7 +2121,7 @@ typedef int (*PFN_ADD_NEW_NATIVES) (const AMX_NATIVE_INFO * /*list*/);
typedef char * (*PFN_BUILD_PATHNAME) (const char * /*format*/, ...); typedef char * (*PFN_BUILD_PATHNAME) (const char * /*format*/, ...);
typedef char * (*PFN_BUILD_PATHNAME_R) (char * /*buffer*/, size_t /* maxlen */, const char * /* format */, ...); typedef char * (*PFN_BUILD_PATHNAME_R) (char * /*buffer*/, size_t /* maxlen */, const char * /* format */, ...);
typedef cell * (*PFN_GET_AMXADDR) (AMX * /*amx*/, cell /*offset*/); typedef cell * (*PFN_GET_AMXADDR) (AMX * /*amx*/, cell /*offset*/);
typedef void (*PFN_PRINT_SRVCONSOLE) (char * /*format*/, ...); typedef void (*PFN_PRINT_SRVCONSOLE) (const char * /*format*/, ...);
typedef const char * (*PFN_GET_MODNAME) (void); typedef const char * (*PFN_GET_MODNAME) (void);
typedef const char * (*PFN_GET_AMXSCRIPTNAME) (int /*id*/); typedef const char * (*PFN_GET_AMXSCRIPTNAME) (int /*id*/);
typedef AMX * (*PFN_GET_AMXSCRIPT) (int /*id*/); typedef AMX * (*PFN_GET_AMXSCRIPT) (int /*id*/);
@ -2175,8 +2180,8 @@ typedef void (*PFN_DEALLOCATOR) (const char* /*filename*/, const unsigned i
typedef int (*PFN_AMX_EXEC) (AMX* /*amx*/, cell* /*return val*/, int /*index*/); typedef int (*PFN_AMX_EXEC) (AMX* /*amx*/, cell* /*return val*/, int /*index*/);
typedef int (*PFN_AMX_EXECV) (AMX* /*amx*/, cell* /*return val*/, int /*index*/, int /*numparams*/, cell[] /*params*/); typedef int (*PFN_AMX_EXECV) (AMX* /*amx*/, cell* /*return val*/, int /*index*/, int /*numparams*/, cell[] /*params*/);
typedef int (*PFN_AMX_ALLOT) (AMX* /*amx*/, int /*length*/, cell* /*amx_addr*/, cell** /*phys_addr*/); typedef int (*PFN_AMX_ALLOT) (AMX* /*amx*/, int /*length*/, cell* /*amx_addr*/, cell** /*phys_addr*/);
typedef int (*PFN_AMX_FINDPUBLIC) (AMX* /*amx*/, char* /*func name*/, int* /*index*/); typedef int (*PFN_AMX_FINDPUBLIC) (AMX* /*amx*/, const char* /*func name*/, int* /*index*/);
typedef int (*PFN_AMX_FINDNATIVE) (AMX* /*amx*/, char* /*func name*/, int* /*index*/); typedef int (*PFN_AMX_FINDNATIVE) (AMX* /*amx*/, const char* /*func name*/, int* /*index*/);
typedef int (*PFN_LOAD_AMXSCRIPT) (AMX* /*amx*/, void** /*code*/, const char* /*path*/, char[64] /*error info*/, int /* debug */); typedef int (*PFN_LOAD_AMXSCRIPT) (AMX* /*amx*/, void** /*code*/, const char* /*path*/, char[64] /*error info*/, int /* debug */);
typedef int (*PFN_UNLOAD_AMXSCRIPT) (AMX* /*amx*/,void** /*code*/); typedef int (*PFN_UNLOAD_AMXSCRIPT) (AMX* /*amx*/,void** /*code*/);
typedef cell (*PFN_REAL_TO_CELL) (REAL /*x*/); typedef cell (*PFN_REAL_TO_CELL) (REAL /*x*/);

View File

@ -1,79 +1,124 @@
#(C)2004-2005 AMX Mod X Development Team # (C)2004-2013 AMX Mod X Development Team
# Makefile written by David "BAILOPAN" Anderson # Makefile written by David "BAILOPAN" Anderson
HLSDK = ../../../hlsdk ###########################################
### EDIT THESE PATHS FOR YOUR OWN SETUP ###
###########################################
HLSDK = ../../../hlsdk/multiplayer
MM_ROOT = ../../../metamod/metamod MM_ROOT = ../../../metamod/metamod
#####################################
### EDIT BELOW FOR OTHER PROJECTS ### ### EDIT BELOW FOR OTHER PROJECTS ###
#####################################
OPT_FLAGS = -O2 -funroll-loops -s -pipe -fomit-frame-pointer -fno-strict-aliasing PROJECT = engine
DEBUG_FLAGS = -g -ggdb3
CPP = gcc-4.1
NAME = engine
BIN_SUFFIX_32 = amxx_i386.so
BIN_SUFFIX_64 = amxx_amd64.so
OBJECTS = sdk/amxxmodule.cpp amxxapi.cpp engine.cpp entity.cpp globals.cpp forwards.cpp \ OBJECTS = sdk/amxxmodule.cpp amxxapi.cpp engine.cpp entity.cpp globals.cpp forwards.cpp \
amxmod_compat.cpp amxmod_compat.cpp
##############################################
### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
##############################################
C_OPT_FLAGS = -DNDEBUG -O2 -funroll-loops -fomit-frame-pointer -pipe
C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3
C_GCC4_FLAGS = -fvisibility=hidden
CPP_GCC4_FLAGS = -fvisibility-inlines-hidden
CPP = gcc
CPP_OSX = clang
LINK = LINK =
INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared -I$(HLSDK)/game_shared \ INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/common -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared \
-I$(MM_ROOT) -I$(HLSDK)/common -Isdk -I$(MM_ROOT) -Isdk
GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) ################################################
### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ###
################################################
ifeq "$(GCC_VERSION)" "4" OS := $(shell uname -s)
OPT_FLAGS += -fvisibility=hidden -fvisibility-inlines-hidden
ifeq "$(OS)" "Darwin"
CPP = $(CPP_OSX)
LIB_EXT = dylib
LIB_SUFFIX = _amxx
CFLAGS += -DOSX
LINK += -dynamiclib -lstdc++ -mmacosx-version-min=10.5
else
LIB_EXT = so
LIB_SUFFIX = _amxx_i386
CFLAGS += -DLINUX
LINK += -shared
endif endif
LINK += -m32 -lm -ldl
CFLAGS += -DPAWN_CELL_SIZE=32 -DJIT -DASM32 -DHAVE_STDINT_H -fno-strict-aliasing -m32 -Wall -Werror
CPPFLAGS += -fno-exceptions -fno-rtti
BINARY = $(PROJECT)$(LIB_SUFFIX).$(LIB_EXT)
ifeq "$(DEBUG)" "true" ifeq "$(DEBUG)" "true"
BIN_DIR = Debug BIN_DIR = Debug
CFLAGS = $(DEBUG_FLAGS) CFLAGS += $(C_DEBUG_FLAGS)
else else
BIN_DIR = Release BIN_DIR = Release
CFLAGS = $(OPT_FLAGS) CFLAGS += $(C_OPT_FLAGS)
LINK += -s
endif endif
CFLAGS += -DNDEBUG -Wall -Wno-non-virtual-dtor -Werror -fno-exceptions -DHAVE_STDINT_H -fno-rtti -static-libgcc -m32 IS_CLANG := $(shell $(CPP) --version | head -1 | grep clang > /dev/null && echo "1" || echo "0")
ifeq "$(AMD64)" "true" ifeq "$(IS_CLANG)" "1"
BINARY = $(NAME)_$(BIN_SUFFIX_64) CPP_MAJOR := $(shell $(CPP) --version | grep clang | sed "s/.*version \([0-9]\)*\.[0-9]*.*/\1/")
CFLAGS += -DPAWN_CELL_SIZE=64 -DHAVE_I64 -m64 CPP_MINOR := $(shell $(CPP) --version | grep clang | sed "s/.*version [0-9]*\.\([0-9]\)*.*/\1/")
else else
BINARY = $(NAME)_$(BIN_SUFFIX_32) CPP_MAJOR := $(shell $(CPP) -dumpversion >&1 | cut -b1)
CFLAGS += -DPAWN_CELL_SIZE=32 -DJIT -DASM32 CPP_MINOR := $(shell $(CPP) -dumpversion >&1 | cut -b3)
OPT_FLAGS += -march=i586
endif endif
OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) # Clang || GCC >= 4
ifeq "$(shell expr $(IS_CLANG) \| $(CPP_MAJOR) \>= 4)" "1"
CFLAGS += $(C_GCC4_FLAGS)
CPPFLAGS += $(CPP_GCC4_FLAGS)
endif
# Clang >= 3 || GCC >= 4.7
ifeq "$(shell expr $(IS_CLANG) \& $(CPP_MAJOR) \>= 3 \| $(CPP_MAJOR) \>= 4 \& $(CPP_MINOR) \>= 7)" "1"
CFLAGS += -Wno-delete-non-virtual-dtor
endif
# OS is Linux and not using clang
ifeq "$(shell expr $(OS) \= Linux \& $(IS_CLANG) \= 0)" "1"
LINK += -static-libgcc
endif
OBJ_BIN := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o)
# This will break if we include other Makefiles, but is fine for now. It allows
# us to make a copy of this file that uses altered paths (ie. Makefile.mine)
# or other changes without mucking up the original.
MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
$(BIN_DIR)/%.o: %.cpp $(BIN_DIR)/%.o: %.cpp
$(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $< $(CPP) $(INCLUDE) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
all: all:
mkdir -p $(BIN_DIR) mkdir -p $(BIN_DIR)
mkdir -p $(BIN_DIR)/sdk mkdir -p $(BIN_DIR)/sdk
$(MAKE) engine $(MAKE) -f $(MAKEFILE_NAME) $(PROJECT)
amd64: $(PROJECT): $(OBJ_BIN)
$(MAKE) all AMD64=true $(CPP) $(INCLUDE) $(OBJ_BIN) $(LINK) -o $(BIN_DIR)/$(BINARY)
engine: $(OBJ_LINUX)
$(CPP) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -shared -ldl -lm -o$(BIN_DIR)/$(BINARY)
debug: debug:
$(MAKE) all DEBUG=true $(MAKE) -f $(MAKEFILE_NAME) all DEBUG=true
default: all default: all
clean: clean:
rm -rf Release/sdk/*.o rm -rf $(BIN_DIR)/*.o
rm -rf Release/*.o rm -rf $(BIN_DIR)/sdk/*.o
rm -rf Release/$(NAME)_$(BIN_SUFFIX_32) rm -f $(BIN_DIR)/$(BINARY)
rm -rf Release/$(NAME)_$(BIN_SUFFIX_64)
rm -rf Debug/sdk/*.o
rm -rf Debug/*.o
rm -rf Debug/$(NAME)_$(BIN_SUFFIX_32)
rm -rf Debug/$(NAME)_$(BIN_SUFFIX_64)

View File

@ -16,8 +16,8 @@ static int gmsgScoreInfo = 0;
BOOL is_breakable(edict_t* pBreak) BOOL is_breakable(edict_t* pBreak)
{ {
if (FStrEq("func_breakable", STRING(pBreak->v.classname)) if (FStrEq("func_breakable", STRING(pBreak->v.classname))
|| FStrEq("func_pushable", STRING(pBreak->v.classname)) || (FStrEq("func_pushable", STRING(pBreak->v.classname))
&& pBreak->v.spawnflags & SF_PUSH_BREAKABLE) && pBreak->v.spawnflags & SF_PUSH_BREAKABLE))
{ {
return true; return true;
} }

View File

@ -1470,7 +1470,7 @@ static cell AMX_NATIVE_CALL find_ent_by_owner(AMX *amx, cell *params) // native
edict_t *entOwner = INDEXENT2(oEnt); edict_t *entOwner = INDEXENT2(oEnt);
//optional fourth parameter is for jghg2 compatibility //optional fourth parameter is for jghg2 compatibility
char* sCategory = NULL; const char* sCategory = NULL;
switch(params[4]){ switch(params[4]){
case 1: sCategory = "target"; break; case 1: sCategory = "target"; break;
case 2: sCategory = "targetname"; break; case 2: sCategory = "targetname"; break;

View File

@ -220,7 +220,7 @@ public:
if (is_space(v[len-1])) if (is_space(v[len-1]))
{ {
for (i=len-1; i>=0; i--) for (i=len-1; i<len; i--)
{ {
if (!is_space(v[i]) if (!is_space(v[i])
|| (is_space(v[i]) && i==0)) || (is_space(v[i]) && i==0))

View File

@ -2240,7 +2240,7 @@ static META_FUNCTIONS g_MetaFunctions_Table =
GetEngineFunctions_Post GetEngineFunctions_Post
}; };
C_DLLEXPORT int Meta_Query(char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs) C_DLLEXPORT int Meta_Query(const char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs)
{ {
if ((int) CVAR_GET_FLOAT("developer") != 0) if ((int) CVAR_GET_FLOAT("developer") != 0)
UTIL_LogPrintf("[%s] dev: called: Meta_Query; version=%s, ours=%s\n", UTIL_LogPrintf("[%s] dev: called: Meta_Query; version=%s, ours=%s\n",
@ -2334,7 +2334,7 @@ C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
// linux prototype // linux prototype
C_DLLEXPORT void GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals ) { C_DLLEXPORT void GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals ) {
@ -3050,7 +3050,7 @@ char* UTIL_VarArgs( char *format, ... )
// UTIL_LogPrintf - Prints a logged message to console. // UTIL_LogPrintf - Prints a logged message to console.
// Preceded by LOG: ( timestamp ) < message > // Preceded by LOG: ( timestamp ) < message >
//========================================================= //=========================================================
void UTIL_LogPrintf( char *fmt, ... ) void UTIL_LogPrintf( const char *fmt, ... )
{ {
va_list argptr; va_list argptr;
static char string[1024]; static char string[1024];

View File

@ -20,11 +20,16 @@
// DLL Export // DLL Export
#undef DLLEXPORT #undef DLLEXPORT
#ifndef __linux__ #if defined(_WIN32)
#define DLLEXPORT __declspec(dllexport) #define DLLEXPORT __declspec(dllexport)
#else #else
#define DLLEXPORT __attribute__((visibility("default"))) #define DLLEXPORT __attribute__((visibility("default")))
#endif
#if defined(__linux__) && !defined(LINUX)
#define LINUX #define LINUX
#elif defined(__APPLE__) && !defined(OSX)
#define OSX
#endif #endif
#undef C_DLLEXPORT #undef C_DLLEXPORT
@ -66,7 +71,7 @@ struct amxx_module_info_s
#if defined HAVE_STDINT_H #if defined HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#else #else
#if defined __LCC__ || defined __DMC__ || defined LINUX #if defined __LCC__ || defined __DMC__ || defined LINUX || defined __APPLE__
#if defined HAVE_INTTYPES_H #if defined HAVE_INTTYPES_H
#include <inttypes.h> #include <inttypes.h>
#else #else
@ -308,7 +313,7 @@ typedef int (AMXAPI *AMX_DEBUG)(struct tagAMX *amx);
#endif #endif
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__ #if defined LINUX || defined __FreeBSD__ || defined __APPLE__
#pragma pack(1) /* structures must be packed (byte-aligned) */ #pragma pack(1) /* structures must be packed (byte-aligned) */
#elif defined MACOS && defined __MWERKS__ #elif defined MACOS && defined __MWERKS__
#pragma options align=mac68k #pragma options align=mac68k
@ -395,7 +400,7 @@ enum {
}; };
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined __linux__ #if defined(__linux__) || defined(__APPLE__)
#pragma pack() /* reset default packing */ #pragma pack() /* reset default packing */
#else #else
#pragma pack(pop) /* reset previous packing */ #pragma pack(pop) /* reset previous packing */
@ -406,7 +411,7 @@ enum {
// ***** declare functions ***** // ***** declare functions *****
#ifdef USE_METAMOD #ifdef USE_METAMOD
void UTIL_LogPrintf( char *fmt, ... ); void UTIL_LogPrintf( const char *fmt, ... );
void UTIL_HudMessage(CBaseEntity *pEntity, const hudtextparms_t &textparms, const char *pMessage); void UTIL_HudMessage(CBaseEntity *pEntity, const hudtextparms_t &textparms, const char *pMessage);
short FixedSigned16( float value, float scale ); short FixedSigned16( float value, float scale );
unsigned short FixedUnsigned16( float value, float scale ); unsigned short FixedUnsigned16( float value, float scale );
@ -833,11 +838,11 @@ int FN_AllowLagCompensation_Post(void);
#ifdef FN_PrecacheModel #ifdef FN_PrecacheModel
int FN_PrecacheModel(char *s); int FN_PrecacheModel(const char *s);
#endif // FN_PrecacheModel #endif // FN_PrecacheModel
#ifdef FN_PrecacheSound #ifdef FN_PrecacheSound
int FN_PrecacheSound(char *s); int FN_PrecacheSound(const char *s);
#endif // FN_PrecacheSound #endif // FN_PrecacheSound
#ifdef FN_SetModel #ifdef FN_SetModel
@ -857,7 +862,7 @@ void FN_SetSize(edict_t *e, const float *rgflMin, const float *rgflMax);
#endif // FN_SetSize #endif // FN_SetSize
#ifdef FN_ChangeLevel #ifdef FN_ChangeLevel
void FN_ChangeLevel(char *s1, char *s2); void FN_ChangeLevel(const char *s1, const char *s2);
#endif // FN_ChangeLevel #endif // FN_ChangeLevel
#ifdef FN_GetSpawnParms #ifdef FN_GetSpawnParms
@ -1261,19 +1266,19 @@ char *FN_GetInfoKeyBuffer(edict_t *e);
#endif // FN_GetInfoKeyBuffer #endif // FN_GetInfoKeyBuffer
#ifdef FN_InfoKeyValue #ifdef FN_InfoKeyValue
char *FN_InfoKeyValue(char *infobuffer, char *key); char *FN_InfoKeyValue(char *infobuffer, const char *key);
#endif // FN_InfoKeyValue #endif // FN_InfoKeyValue
#ifdef FN_SetKeyValue #ifdef FN_SetKeyValue
void FN_SetKeyValue(char *infobuffer, char *key, char *value); void FN_SetKeyValue(char *infobuffer, const char *key, const char *value);
#endif // FN_SetKeyValue #endif // FN_SetKeyValue
#ifdef FN_SetClientKeyValue #ifdef FN_SetClientKeyValue
void FN_SetClientKeyValue(int clientIndex, char *infobuffer, char *key, char *value); void FN_SetClientKeyValue(int clientIndex, char *infobuffer, const char *key, const char *value);
#endif // FN_SetClientKeyValue #endif // FN_SetClientKeyValue
#ifdef FN_IsMapValid #ifdef FN_IsMapValid
int FN_IsMapValid(char *filename); int FN_IsMapValid(const char *filename);
#endif // FN_IsMapValid #endif // FN_IsMapValid
#ifdef FN_StaticDecal #ifdef FN_StaticDecal
@ -1281,7 +1286,7 @@ void FN_StaticDecal(const float *origin, int decalIndex, int entityIndex, int mo
#endif // FN_StaticDecal #endif // FN_StaticDecal
#ifdef FN_PrecacheGeneric #ifdef FN_PrecacheGeneric
int FN_PrecacheGeneric(char *s); int FN_PrecacheGeneric(const char *s);
#endif // FN_PrecacheGeneric #endif // FN_PrecacheGeneric
#ifdef FN_GetPlayerUserId #ifdef FN_GetPlayerUserId
@ -1414,11 +1419,11 @@ const char *FN_GetPlayerAuthId(edict_t *e);
#ifdef FN_PrecacheModel_Post #ifdef FN_PrecacheModel_Post
int FN_PrecacheModel_Post(char *s); int FN_PrecacheModel_Post(const char *s);
#endif // FN_PrecacheModel_Post #endif // FN_PrecacheModel_Post
#ifdef FN_PrecacheSound_Post #ifdef FN_PrecacheSound_Post
int FN_PrecacheSound_Post(char *s); int FN_PrecacheSound_Post(const char *s);
#endif // FN_PrecacheSound_Post #endif // FN_PrecacheSound_Post
#ifdef FN_SetModel_Post #ifdef FN_SetModel_Post
@ -1438,7 +1443,7 @@ void FN_SetSize_Post(edict_t *e, const float *rgflMin, const float *rgflMax);
#endif // FN_SetSize_Post #endif // FN_SetSize_Post
#ifdef FN_ChangeLevel_Post #ifdef FN_ChangeLevel_Post
void FN_ChangeLevel_Post(char *s1, char *s2); void FN_ChangeLevel_Post(const char *s1, const char *s2);
#endif // FN_ChangeLevel_Post #endif // FN_ChangeLevel_Post
#ifdef FN_GetSpawnParms_Post #ifdef FN_GetSpawnParms_Post
@ -1842,19 +1847,19 @@ char *FN_GetInfoKeyBuffer_Post(edict_t *e);
#endif // FN_GetInfoKeyBuffer_Post #endif // FN_GetInfoKeyBuffer_Post
#ifdef FN_InfoKeyValue_Post #ifdef FN_InfoKeyValue_Post
char *FN_InfoKeyValue_Post(char *infobuffer, char *key); char *FN_InfoKeyValue_Post(char *infobuffer, const char *key);
#endif // FN_InfoKeyValue_Post #endif // FN_InfoKeyValue_Post
#ifdef FN_SetKeyValue_Post #ifdef FN_SetKeyValue_Post
void FN_SetKeyValue_Post(char *infobuffer, char *key, char *value); void FN_SetKeyValue_Post(char *infobuffer, const char *key, const char *value);
#endif // FN_SetKeyValue_Post #endif // FN_SetKeyValue_Post
#ifdef FN_SetClientKeyValue_Post #ifdef FN_SetClientKeyValue_Post
void FN_SetClientKeyValue_Post(int clientIndex, char *infobuffer, char *key, char *value); void FN_SetClientKeyValue_Post(int clientIndex, char *infobuffer, const char *key, const char *value);
#endif // FN_SetClientKeyValue_Post #endif // FN_SetClientKeyValue_Post
#ifdef FN_IsMapValid_Post #ifdef FN_IsMapValid_Post
int FN_IsMapValid_Post(char *filename); int FN_IsMapValid_Post(const char *filename);
#endif // FN_IsMapValid_Post #endif // FN_IsMapValid_Post
#ifdef FN_StaticDecal_Post #ifdef FN_StaticDecal_Post
@ -1862,7 +1867,7 @@ void FN_StaticDecal_Post(const float *origin, int decalIndex, int entityIndex, i
#endif // FN_StaticDecal_Post #endif // FN_StaticDecal_Post
#ifdef FN_PrecacheGeneric_Post #ifdef FN_PrecacheGeneric_Post
int FN_PrecacheGeneric_Post(char *s); int FN_PrecacheGeneric_Post(const char *s);
#endif // FN_PrecacheGeneric_Post #endif // FN_PrecacheGeneric_Post
#ifdef FN_GetPlayerUserId_Post #ifdef FN_GetPlayerUserId_Post
@ -2116,7 +2121,7 @@ typedef int (*PFN_ADD_NEW_NATIVES) (const AMX_NATIVE_INFO * /*list*/);
typedef char * (*PFN_BUILD_PATHNAME) (const char * /*format*/, ...); typedef char * (*PFN_BUILD_PATHNAME) (const char * /*format*/, ...);
typedef char * (*PFN_BUILD_PATHNAME_R) (char * /*buffer*/, size_t /* maxlen */, const char * /* format */, ...); typedef char * (*PFN_BUILD_PATHNAME_R) (char * /*buffer*/, size_t /* maxlen */, const char * /* format */, ...);
typedef cell * (*PFN_GET_AMXADDR) (AMX * /*amx*/, cell /*offset*/); typedef cell * (*PFN_GET_AMXADDR) (AMX * /*amx*/, cell /*offset*/);
typedef void (*PFN_PRINT_SRVCONSOLE) (char * /*format*/, ...); typedef void (*PFN_PRINT_SRVCONSOLE) (const char * /*format*/, ...);
typedef const char * (*PFN_GET_MODNAME) (void); typedef const char * (*PFN_GET_MODNAME) (void);
typedef const char * (*PFN_GET_AMXSCRIPTNAME) (int /*id*/); typedef const char * (*PFN_GET_AMXSCRIPTNAME) (int /*id*/);
typedef AMX * (*PFN_GET_AMXSCRIPT) (int /*id*/); typedef AMX * (*PFN_GET_AMXSCRIPT) (int /*id*/);
@ -2175,8 +2180,8 @@ typedef void (*PFN_DEALLOCATOR) (const char* /*filename*/, const unsigned i
typedef int (*PFN_AMX_EXEC) (AMX* /*amx*/, cell* /*return val*/, int /*index*/); typedef int (*PFN_AMX_EXEC) (AMX* /*amx*/, cell* /*return val*/, int /*index*/);
typedef int (*PFN_AMX_EXECV) (AMX* /*amx*/, cell* /*return val*/, int /*index*/, int /*numparams*/, cell[] /*params*/); typedef int (*PFN_AMX_EXECV) (AMX* /*amx*/, cell* /*return val*/, int /*index*/, int /*numparams*/, cell[] /*params*/);
typedef int (*PFN_AMX_ALLOT) (AMX* /*amx*/, int /*length*/, cell* /*amx_addr*/, cell** /*phys_addr*/); typedef int (*PFN_AMX_ALLOT) (AMX* /*amx*/, int /*length*/, cell* /*amx_addr*/, cell** /*phys_addr*/);
typedef int (*PFN_AMX_FINDPUBLIC) (AMX* /*amx*/, char* /*func name*/, int* /*index*/); typedef int (*PFN_AMX_FINDPUBLIC) (AMX* /*amx*/, const char* /*func name*/, int* /*index*/);
typedef int (*PFN_AMX_FINDNATIVE) (AMX* /*amx*/, char* /*func name*/, int* /*index*/); typedef int (*PFN_AMX_FINDNATIVE) (AMX* /*amx*/, const char* /*func name*/, int* /*index*/);
typedef int (*PFN_LOAD_AMXSCRIPT) (AMX* /*amx*/, void** /*code*/, const char* /*path*/, char[64] /*error info*/, int /* debug */); typedef int (*PFN_LOAD_AMXSCRIPT) (AMX* /*amx*/, void** /*code*/, const char* /*path*/, char[64] /*error info*/, int /* debug */);
typedef int (*PFN_UNLOAD_AMXSCRIPT) (AMX* /*amx*/,void** /*code*/); typedef int (*PFN_UNLOAD_AMXSCRIPT) (AMX* /*amx*/,void** /*code*/);
typedef cell (*PFN_REAL_TO_CELL) (REAL /*x*/); typedef cell (*PFN_REAL_TO_CELL) (REAL /*x*/);

View File

@ -1,81 +1,125 @@
#(C)2004-2005 AMX Mod X Development Team # (C)2004-2013 AMX Mod X Development Team
# Makefile written by David "BAILOPAN" Anderson # Makefile written by David "BAILOPAN" Anderson
HLSDK = ../../../hlsdk ###########################################
### EDIT THESE PATHS FOR YOUR OWN SETUP ###
###########################################
HLSDK = ../../../hlsdk/multiplayer
MM_ROOT = ../../../metamod/metamod MM_ROOT = ../../../metamod/metamod
#####################################
### EDIT BELOW FOR OTHER PROJECTS ### ### EDIT BELOW FOR OTHER PROJECTS ###
#####################################
OPT_FLAGS = -O3 -funroll-loops -s -pipe -fno-strict-aliasing -fomit-frame-pointer PROJECT = fakemeta
DEBUG_FLAGS = -g -ggdb3
CPP = gcc-4.1
NAME = fakemeta
BIN_SUFFIX_32 = amxx_i386.so
BIN_SUFFIX_64 = amxx_amd64.so
OBJECTS = sdk/amxxmodule.cpp dllfunc.cpp engfunc.cpp fakemeta_amxx.cpp pdata.cpp forward.cpp \ OBJECTS = sdk/amxxmodule.cpp dllfunc.cpp engfunc.cpp fakemeta_amxx.cpp pdata.cpp forward.cpp \
fm_tr.cpp pev.cpp glb.cpp fm_tr2.cpp misc.cpp fm_tr.cpp pev.cpp glb.cpp fm_tr2.cpp misc.cpp
##############################################
### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
##############################################
C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -fomit-frame-pointer -pipe
C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3
C_GCC4_FLAGS = -fvisibility=hidden
CPP_GCC4_FLAGS = -fvisibility-inlines-hidden
CPP = gcc
CPP_OSX = clang
LINK = LINK =
INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared -I$(HLSDK)/game_shared \ INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/common -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared \
-I$(MM_ROOT) -I$(HLSDK)/common -I$(HLSDK)/pm_shared -Isdk -I$(HLSDK)/pm_shared -I$(MM_ROOT) -Isdk
GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) ################################################
### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ###
################################################
ifeq "$(GCC_VERSION)" "4" OS := $(shell uname -s)
OPT_FLAGS += -fvisibility=hidden -fvisibility-inlines-hidden
ifeq "$(OS)" "Darwin"
CPP = $(CPP_OSX)
LIB_EXT = dylib
LIB_SUFFIX = _amxx
CFLAGS += -DOSX
LINK += -dynamiclib -lstdc++ -mmacosx-version-min=10.5
else
LIB_EXT = so
LIB_SUFFIX = _amxx_i386
CFLAGS += -DLINUX
LINK += -shared
endif endif
LINK += -m32 -lm -ldl
CFLAGS += -DPAWN_CELL_SIZE=32 -DJIT -DASM32 -DHAVE_STDINT_H -fno-strict-aliasing -m32 -Wall -Werror \
-Wno-invalid-offsetof
CPPFLAGS += -fno-exceptions -fno-rtti
BINARY = $(PROJECT)$(LIB_SUFFIX).$(LIB_EXT)
ifeq "$(DEBUG)" "true" ifeq "$(DEBUG)" "true"
BIN_DIR = Debug BIN_DIR = Debug
CFLAGS = $(DEBUG_FLAGS) CFLAGS += $(C_DEBUG_FLAGS)
else else
BIN_DIR = Release BIN_DIR = Release
CFLAGS = $(OPT_FLAGS) CFLAGS += $(C_OPT_FLAGS)
LINK += -s
endif endif
CFLAGS += -DNDEBUG -Wall -Wno-non-virtual-dtor -Werror -fno-exceptions -DHAVE_STDINT_H -static-libgcc -fno-rtti -Wno-invalid-offsetof -m32 IS_CLANG := $(shell $(CPP) --version | head -1 | grep clang > /dev/null && echo "1" || echo "0")
ifeq "$(AMD64)" "true" ifeq "$(IS_CLANG)" "1"
BINARY = $(NAME)_$(BIN_SUFFIX_64) CPP_MAJOR := $(shell $(CPP) --version | grep clang | sed "s/.*version \([0-9]\)*\.[0-9]*.*/\1/")
CFLAGS += -DPAWN_CELL_SIZE=64 -DHAVE_I64 -m64 CPP_MINOR := $(shell $(CPP) --version | grep clang | sed "s/.*version [0-9]*\.\([0-9]\)*.*/\1/")
else else
BINARY = $(NAME)_$(BIN_SUFFIX_32) CPP_MAJOR := $(shell $(CPP) -dumpversion >&1 | cut -b1)
CFLAGS += -DPAWN_CELL_SIZE=32 -DJIT -DASM32 CPP_MINOR := $(shell $(CPP) -dumpversion >&1 | cut -b3)
OPT_FLAGS += -march=i586
endif endif
OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) # Clang || GCC >= 4
ifeq "$(shell expr $(IS_CLANG) \| $(CPP_MAJOR) \>= 4)" "1"
CFLAGS += $(C_GCC4_FLAGS)
CPPFLAGS += $(CPP_GCC4_FLAGS)
endif
# Clang >= 3 || GCC >= 4.7
ifeq "$(shell expr $(IS_CLANG) \& $(CPP_MAJOR) \>= 3 \| $(CPP_MAJOR) \>= 4 \& $(CPP_MINOR) \>= 7)" "1"
CFLAGS += -Wno-delete-non-virtual-dtor
endif
# OS is Linux and not using clang
ifeq "$(shell expr $(OS) \= Linux \& $(IS_CLANG) \= 0)" "1"
LINK += -static-libgcc
endif
OBJ_BIN := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o)
# This will break if we include other Makefiles, but is fine for now. It allows
# us to make a copy of this file that uses altered paths (ie. Makefile.mine)
# or other changes without mucking up the original.
MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
$(BIN_DIR)/%.o: %.cpp $(BIN_DIR)/%.o: %.cpp
$(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $< $(CPP) $(INCLUDE) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
all: all:
mkdir -p $(BIN_DIR) mkdir -p $(BIN_DIR)
mkdir -p $(BIN_DIR)/sdk mkdir -p $(BIN_DIR)/sdk
$(MAKE) fakemeta $(MAKE) -f $(MAKEFILE_NAME) $(PROJECT)
amd64: $(PROJECT): $(OBJ_BIN)
$(MAKE) all AMD64=true $(CPP) $(INCLUDE) $(OBJ_BIN) $(LINK) -o $(BIN_DIR)/$(BINARY)
fakemeta: $(OBJ_LINUX)
$(CPP) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -shared -ldl -lm -o$(BIN_DIR)/$(BINARY)
debug: debug:
$(MAKE) all DEBUG=true $(MAKE) -f $(MAKEFILE_NAME) all DEBUG=true
default: all default: all
clean: clean:
rm -rf Release/sdk/*.o rm -rf $(BIN_DIR)/*.o
rm -rf Release/*.o rm -rf $(BIN_DIR)/sdk/*.o
rm -rf Release/$(NAME)_$(BIN_SUFFIX_32) rm -f $(BIN_DIR)/$(BINARY)
rm -rf Release/$(NAME)_$(BIN_SUFFIX_64)
rm -rf Debug/sdk/*.o
rm -rf Debug/*.o
rm -rf Debug/$(NAME)_$(BIN_SUFFIX_32)
rm -rf Debug/$(NAME)_$(BIN_SUFFIX_64)

View File

@ -7,9 +7,9 @@ static cell AMX_NATIVE_CALL dllfunc(AMX *amx,cell *params)
int index; int index;
int indexb; int indexb;
unsigned char *pset; unsigned char *pset;
char *temp = ""; const char *temp = "";
char *temp2 = ""; const char *temp2 = "";
char *temp3 = ""; const char *temp3 = "";
vec3_t Vec1; vec3_t Vec1;
vec3_t Vec2; vec3_t Vec2;
int iparam1; int iparam1;
@ -105,7 +105,7 @@ static cell AMX_NATIVE_CALL dllfunc(AMX *amx,cell *params)
temp = MF_GetAmxString(amx,params[3],0,&len); temp = MF_GetAmxString(amx,params[3],0,&len);
temp2 = MF_GetAmxString(amx,params[4],1,&len); temp2 = MF_GetAmxString(amx,params[4],1,&len);
//temp3 = GET_AMXSTRING(amx,params[5],2,len); //temp3 = GET_AMXSTRING(amx,params[5],2,len);
iparam1 = MDLL_ClientConnect(INDEXENT2(index),STRING(ALLOC_STRING(temp)),STRING(ALLOC_STRING(temp2)),temp3); iparam1 = MDLL_ClientConnect(INDEXENT2(index),STRING(ALLOC_STRING(temp)),STRING(ALLOC_STRING(temp2)),(char *)temp3);
cRet = MF_GetAmxAddr(amx,params[6]); cRet = MF_GetAmxAddr(amx,params[6]);
MF_SetAmxString(amx,params[5],temp3,cRet[0]); MF_SetAmxString(amx,params[5],temp3,cRet[0]);
return iparam1; return iparam1;

View File

@ -34,15 +34,15 @@ static cell AMX_NATIVE_CALL engfunc(AMX *amx, cell *params)
switch (type) switch (type)
{ {
// pfnPrecacheModel // pfnPrecacheModel
case EngFunc_PrecacheModel: // int ) (char* s); case EngFunc_PrecacheModel: // int ) (const char* s);
temp = MF_GetAmxString(amx,params[2],0,&len); temp = MF_GetAmxString(amx,params[2],0,&len);
if (temp[0]==0) if (temp[0]==0)
return 0; return 0;
return (*g_engfuncs.pfnPrecacheModel)((char*)STRING(ALLOC_STRING(temp))); return (*g_engfuncs.pfnPrecacheModel)((char *)STRING(ALLOC_STRING(temp)));
// pfnPrecacheSound // pfnPrecacheSound
case EngFunc_PrecacheSound: // int ) (char* s); case EngFunc_PrecacheSound: // int ) (const char* s);
temp = MF_GetAmxString(amx,params[2],0,&len); temp = MF_GetAmxString(amx,params[2],0,&len);
if (temp[0]==0) if (temp[0]==0)
return 0; return 0;

View File

@ -83,10 +83,10 @@ static cell AMX_NATIVE_CALL fm_return(AMX *amx, cell *params)
*/ */
// pfnPrecacheModel // pfnPrecacheModel
SIMPLE_INT_HOOK_STRING(PrecacheModel); SIMPLE_INT_HOOK_CONSTSTRING(PrecacheModel);
// pfnPrecacheSound // pfnPrecacheSound
SIMPLE_INT_HOOK_STRING(PrecacheSound); SIMPLE_INT_HOOK_CONSTSTRING(PrecacheSound);
void ClientUserInfoChanged(edict_t *e, char *infobuffer) void ClientUserInfoChanged(edict_t *e, char *infobuffer)
{ {
@ -261,7 +261,7 @@ void KeyValue_post(edict_t* entity, KeyValueData* data)
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);
} }
void AlertMessage(ALERT_TYPE atype, char *szFmt, ...) void AlertMessage(ALERT_TYPE atype, const char *szFmt, ...)
{ {
static char buf[2048]; static char buf[2048];
va_list ap; va_list ap;
@ -272,7 +272,7 @@ void AlertMessage(ALERT_TYPE atype, char *szFmt, ...)
RETURN_META(mswi(lastFmRes)); RETURN_META(mswi(lastFmRes));
} }
void AlertMessage_post(ALERT_TYPE atype, char *szFmt, ...) void AlertMessage_post(ALERT_TYPE atype, const char *szFmt, ...)
{ {
static char buf[2048]; static char buf[2048];
va_list ap; va_list ap;
@ -293,7 +293,7 @@ SIMPLE_INT_HOOK_INT(ModelFrames);
SIMPLE_VOID_HOOK_EDICT_CONSTVECT_CONSTVECT(SetSize); SIMPLE_VOID_HOOK_EDICT_CONSTVECT_CONSTVECT(SetSize);
// pfnChangeLevel // pfnChangeLevel
SIMPLE_VOID_HOOK_STRING_STRING(ChangeLevel); SIMPLE_VOID_HOOK_CONSTSTRING_CONSTSTRING(ChangeLevel);
// pfnVecToYaw // pfnVecToYaw
SIMPLE_FLOAT_HOOK_CONSTVECT(VecToYaw); SIMPLE_FLOAT_HOOK_CONSTVECT(VecToYaw);
@ -507,7 +507,7 @@ SIMPLE_VOID_HOOK_CONSTEDICT_INT_INT_INT_INT(FadeClientVolume);
SIMPLE_VOID_HOOK_CONSTEDICT_FLOAT(SetClientMaxspeed); SIMPLE_VOID_HOOK_CONSTEDICT_FLOAT(SetClientMaxspeed);
// pfnPrecacheGeneric // pfnPrecacheGeneric
SIMPLE_INT_HOOK_STRING(PrecacheGeneric); SIMPLE_INT_HOOK_CONSTSTRING(PrecacheGeneric);
// pfnPrecacheEvent // pfnPrecacheEvent
SIMPLE_USHORT_HOOK_INT_CONSTSTRING(PrecacheEvent); SIMPLE_USHORT_HOOK_INT_CONSTSTRING(PrecacheEvent);
@ -600,17 +600,17 @@ SIMPLE_BOOL_HOOK_INT_INT(Voice_GetClientListening);
// pfnVoice_SetClientListening // pfnVoice_SetClientListening
SIMPLE_BOOL_HOOK_INT_INT_BOOL(Voice_SetClientListening); SIMPLE_BOOL_HOOK_INT_INT_BOOL(Voice_SetClientListening);
SIMPLE_STRING_HOOK_STRING_STRING(InfoKeyValue); SIMPLE_STRING_HOOK_STRING_CONSTSTRING(InfoKeyValue);
SIMPLE_VOID_HOOK_STRING_STRING_STRING(SetKeyValue); SIMPLE_VOID_HOOK_STRING_CONSTSTRING_CONSTSTRING(SetKeyValue);
SIMPLE_VOID_HOOK_INT_STRING_STRING_STRING(SetClientKeyValue); SIMPLE_VOID_HOOK_INT_STRING_CONSTSTRING_CONSTSTRING(SetClientKeyValue);
SIMPLE_CONSTSTRING_HOOK_EDICT(GetPlayerAuthId); SIMPLE_CONSTSTRING_HOOK_EDICT(GetPlayerAuthId);
SIMPLE_UINT_HOOK_EDICT(GetPlayerWONId); SIMPLE_UINT_HOOK_EDICT(GetPlayerWONId);
SIMPLE_INT_HOOK_STRING(IsMapValid); SIMPLE_INT_HOOK_CONSTSTRING(IsMapValid);
int CreateInstancedBaseline(int classname, struct entity_state_s *baseline) int CreateInstancedBaseline(int classname, struct entity_state_s *baseline)
{ {
@ -725,7 +725,7 @@ SIMPLE_VOID_HOOK_EDICT(SpectatorThink);
SIMPLE_VOID_HOOK_CONSTSTRING(Sys_Error); SIMPLE_VOID_HOOK_CONSTSTRING(Sys_Error);
// pfnPM_FindTextureType // pfnPM_FindTextureType
SIMPLE_CHAR_HOOK_STRING(PM_FindTextureType); SIMPLE_CHAR_HOOK_CONSTSTRING(PM_FindTextureType);
// pfnRegisterEncoders // pfnRegisterEncoders
SIMPLE_VOID_HOOK_VOID(RegisterEncoders); SIMPLE_VOID_HOOK_VOID(RegisterEncoders);

View File

@ -75,6 +75,19 @@
RETURN_META(MRES_IGNORED); \ RETURN_META(MRES_IGNORED); \
} }
#define SIMPLE_VOID_HOOK_INT_STRING_CONSTSTRING_CONSTSTRING(call) \
void call (int v,char *c, const char *cb, const char *cc) \
{ \
FM_ENG_HANDLE(FM_##call, (Engine[FM_##call].at(i),(cell)v,c,cb,cc)); \
RETURN_META(mswi(lastFmRes)); \
} \
void call##_post (int v, char *c, const char *cb, const char *cc) \
{ \
FM_ENG_HANDLE_POST(FM_##call, (EnginePost[FM_##call].at(i),(cell)v,c,cb,cc)); \
RETURN_META(MRES_IGNORED); \
}
#define SIMPLE_VOID_HOOK_STRING_STRING_STRING(call) \ #define SIMPLE_VOID_HOOK_STRING_STRING_STRING(call) \
void call (char *c, char *cb, char *cc) \ void call (char *c, char *cb, char *cc) \
{ \ { \
@ -87,6 +100,18 @@
RETURN_META(MRES_IGNORED); \ RETURN_META(MRES_IGNORED); \
} }
#define SIMPLE_VOID_HOOK_STRING_CONSTSTRING_CONSTSTRING(call) \
void call (char *c, const char *cb, const char *cc) \
{ \
FM_ENG_HANDLE(FM_##call, (Engine[FM_##call].at(i),c,cb,cc)); \
RETURN_META(mswi(lastFmRes)); \
} \
void call##_post (char *c, const char *cb, const char *cc) \
{ \
FM_ENG_HANDLE_POST(FM_##call, (EnginePost[FM_##call].at(i),c,cb,cc)); \
RETURN_META(MRES_IGNORED); \
}
#define SIMPLE_STRING_HOOK_STRING_STRING(call) \ #define SIMPLE_STRING_HOOK_STRING_STRING(call) \
char* call (char *c, char *cb) \ char* call (char *c, char *cb) \
{ \ { \
@ -99,6 +124,18 @@
FM_ENG_HANDLE_POST(FM_##call, (EnginePost[FM_##call].at(i),c,cb)); \ FM_ENG_HANDLE_POST(FM_##call, (EnginePost[FM_##call].at(i),c,cb)); \
RETURN_META_VALUE(MRES_IGNORED, (char*)mlStringResult); \ RETURN_META_VALUE(MRES_IGNORED, (char*)mlStringResult); \
} }
#define SIMPLE_STRING_HOOK_STRING_CONSTSTRING(call) \
char* call (char *c, const char *cb) \
{ \
FM_ENG_HANDLE(FM_##call, (Engine[FM_##call].at(i),c,cb)); \
RETURN_META_VALUE(mswi(lastFmRes), (char*)mlStringResult); \
} \
char* call##_post (char *c, const char *cb) \
{ \
origStringRet = META_RESULT_ORIG_RET(char *); \
FM_ENG_HANDLE_POST(FM_##call, (EnginePost[FM_##call].at(i),c,cb)); \
RETURN_META_VALUE(MRES_IGNORED, (char*)mlStringResult); \
}
#define SIMPLE_CONSTSTRING_HOOK_EDICT(call) \ #define SIMPLE_CONSTSTRING_HOOK_EDICT(call) \
const char* call (edict_t *e) \ const char* call (edict_t *e) \
{ \ { \
@ -175,6 +212,19 @@
FM_ENG_HANDLE_POST(FM_##call, (EnginePost[FM_##call].at(i), s)); \ FM_ENG_HANDLE_POST(FM_##call, (EnginePost[FM_##call].at(i), s)); \
RETURN_META_VALUE(MRES_IGNORED, (char)mlCellResult); \ RETURN_META_VALUE(MRES_IGNORED, (char)mlCellResult); \
} }
#define SIMPLE_CHAR_HOOK_CONSTSTRING(call) \
char call (const char *s) \
{ \
FM_ENG_HANDLE(FM_##call, (Engine[FM_##call].at(i), s)); \
RETURN_META_VALUE(mswi(lastFmRes), (char)mlCellResult); \
} \
char call##_post (const char *s) \
{ \
origCellRet = META_RESULT_ORIG_RET(char); \
FM_ENG_HANDLE_POST(FM_##call, (EnginePost[FM_##call].at(i), s)); \
RETURN_META_VALUE(MRES_IGNORED, (char)mlCellResult); \
}
#define SIMPLE_VOID_HOOK_CONSTSTRING(call) \ #define SIMPLE_VOID_HOOK_CONSTSTRING(call) \
void call (const char *s) \ void call (const char *s) \
{ \ { \

View File

@ -1,5 +1,17 @@
#include "fakemeta_amxx.h" #include "fakemeta_amxx.h"
#if defined PAWN_CELL_SIZE
# if PAWN_CELL_SIZE == 16
# define CELL_MIN SHRT_MIN
# elif PAWN_CELL_SIZE == 32
# define CELL_MIN INT_MIN
# elif PAWN_CELL_SIZE == 64
# define CELL_MIN _I64_MIN
# endif
#else
# define CELL_MIN _I32_MIN
#endif
#if defined WIN32 #if defined WIN32
#define WINDOWS_LEAN_AND_MEAN #define WINDOWS_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
@ -24,6 +36,12 @@ static cell AMX_NATIVE_CALL set_pdata_int(AMX *amx, cell *params)
return 1; return 1;
#ifdef __linux__ #ifdef __linux__
iOffset += params[4]; iOffset += params[4];
#elif defined __APPLE__
// Use Linux offset in older plugins
if (params[0] / sizeof(cell) == 4)
iOffset += params[4];
else
iOffset += params[5];
#endif #endif
int iValue=params[3]; int iValue=params[3];
*((int *)INDEXENT2(index)->pvPrivateData + iOffset) = iValue; *((int *)INDEXENT2(index)->pvPrivateData + iOffset) = iValue;
@ -38,7 +56,14 @@ static cell AMX_NATIVE_CALL get_pdata_int(AMX *amx, cell *params)
return 0; return 0;
#ifdef __linux__ #ifdef __linux__
iOffset += params[3]; iOffset += params[3];
#elif defined __APPLE__
// Use Linux offset in older plugins
if (params[0] / sizeof(cell) == 3)
iOffset += params[3];
else
iOffset += params[4];
#endif #endif
return *((int *)INDEXENT2(index)->pvPrivateData + iOffset); return *((int *)INDEXENT2(index)->pvPrivateData + iOffset);
} }
// Float // Float
@ -51,7 +76,14 @@ static cell AMX_NATIVE_CALL set_pdata_float(AMX *amx, cell *params)
return 1; return 1;
#ifdef __linux__ #ifdef __linux__
iOffset += params[4]; iOffset += params[4];
#elif defined __APPLE__
// Use Linux offset in older plugins
if (params[0] / sizeof(cell) == 4)
iOffset += params[4];
else
iOffset += params[5];
#endif #endif
float fValue=amx_ctof(params[3]); float fValue=amx_ctof(params[3]);
*((float *)INDEXENT2(index)->pvPrivateData + iOffset) = fValue; *((float *)INDEXENT2(index)->pvPrivateData + iOffset) = fValue;
return 1; return 1;
@ -65,7 +97,14 @@ static cell AMX_NATIVE_CALL get_pdata_float(AMX *amx, cell *params)
return 1; return 1;
#ifdef __linux__ #ifdef __linux__
iOffset += params[3]; iOffset += params[3];
#elif defined __APPLE__
// Use Linux offset in older plugins
if (params[0] / sizeof(cell) == 3)
iOffset += params[3];
else
iOffset += params[4];
#endif #endif
return amx_ftoc(*((float *)INDEXENT2(index)->pvPrivateData + iOffset)); return amx_ftoc(*((float *)INDEXENT2(index)->pvPrivateData + iOffset));
} }
@ -79,6 +118,12 @@ static cell AMX_NATIVE_CALL get_pdata_string(AMX *amx, cell *params)
return 1; return 1;
#ifdef __linux__ #ifdef __linux__
iOffset += params[6]; iOffset += params[6];
#elif defined __APPLE__
// Use Linux offset in older plugins
if (params[0] / sizeof(cell) == 6 || params[7] == CELL_MIN)
iOffset += params[6];
else
iOffset += params[7];
#endif #endif
edict_t *pEdict = INDEXENT2(index); edict_t *pEdict = INDEXENT2(index);
@ -111,6 +156,12 @@ static cell AMX_NATIVE_CALL set_pdata_string(AMX *amx, cell *params)
return 1; return 1;
#ifdef __linux__ #ifdef __linux__
iOffset += params[5]; iOffset += params[5];
#elif defined __APPLE__
// Use Linux offset in older plugins
if (params[0] / sizeof(cell) == 5 || params[6] == CELL_MIN)
iOffset += params[5];
else
iOffset += params[6];
#endif #endif
edict_t *pEdict = INDEXENT2(index); edict_t *pEdict = INDEXENT2(index);
@ -152,6 +203,12 @@ static cell AMX_NATIVE_CALL get_pdata_ent(AMX *amx, cell *params)
#ifdef __linux__ #ifdef __linux__
iOffset += params[3]; iOffset += params[3];
#elif defined __APPLE__
// Use Linux offset in older plugins
if (params[0] / sizeof(cell) == 3)
iOffset += params[3];
else
iOffset += params[4];
#endif #endif
edict_t *pEdict = *(edict_t **)((char *)(INDEXENT2(index)->pvPrivateData) + iOffset); edict_t *pEdict = *(edict_t **)((char *)(INDEXENT2(index)->pvPrivateData) + iOffset);

Some files were not shown because too many files have changed in this diff Show More