PM: Added 64bit compatibility
dvander: Fixed minor bugs
This commit is contained in:
parent
8e8633a49a
commit
6dc00f64f8
@ -71,6 +71,7 @@ cell CForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
|
||||
if (iter->pPlugin->isExecutable(iter->func))
|
||||
{
|
||||
// handle strings & arrays
|
||||
AMXXLOG_Log("String handling");
|
||||
int i;
|
||||
for (i = 0; i < m_NumParams; ++i)
|
||||
{
|
||||
@ -105,13 +106,16 @@ cell CForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
|
||||
realParams[i] = params[i];
|
||||
}
|
||||
}
|
||||
AMXXLOG_Log("Exec");
|
||||
// exec
|
||||
cell retVal;
|
||||
AMXXLOG_Log("Entering exec");
|
||||
int err = amx_Execv(iter->pPlugin->getAMX(), &retVal, iter->func, m_NumParams, realParams);
|
||||
// log runtime error, if any
|
||||
if (err != AMX_ERR_NONE)
|
||||
AMXXLOG_Log("[AMXX] Run time error %d on line %ld (plugin \"%s\")", err, iter->pPlugin->getAMX()->curline, iter->pPlugin->getName());
|
||||
|
||||
AMXXLOG_Log("Cleanup strings");
|
||||
// cleanup strings & arrays
|
||||
for (i = 0; i < m_NumParams; ++i)
|
||||
{
|
||||
@ -236,6 +240,7 @@ cell CSPForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
|
||||
|
||||
// exec
|
||||
cell retVal;
|
||||
AMXXLOG_Log("Entering exec2");
|
||||
amx_Execv(m_Amx, &retVal, m_Func, m_NumParams, realParams);
|
||||
|
||||
// cleanup strings & arrays
|
||||
@ -479,4 +484,4 @@ cell prepareCharArray(char *ptr, unsigned int size)
|
||||
void unregisterSPForward(int id)
|
||||
{
|
||||
g_forwards.unregisterSPForward(id);
|
||||
}
|
||||
}
|
||||
|
@ -90,6 +90,7 @@ protected:
|
||||
T *m_Data;
|
||||
size_t m_Size;
|
||||
size_t m_CurrentUsedSize;
|
||||
size_t m_CurrentSize;
|
||||
public:
|
||||
class iterator
|
||||
{
|
||||
@ -397,7 +398,7 @@ public:
|
||||
if (where != m_Data)
|
||||
--where;
|
||||
// validate iter
|
||||
if (where < m_Data || where >= (m_Data + m_CurrentSize))
|
||||
if (where < m_Data || where >= (m_Data + m_CurrentUsedSize))
|
||||
return false;
|
||||
|
||||
++m_CurrentUsedSize;
|
||||
@ -415,7 +416,7 @@ public:
|
||||
void erase(iterator where)
|
||||
{
|
||||
// validate iter
|
||||
if (where < m_Data || where >= (m_Data + m_CurrentSize))
|
||||
if (where < m_Data || where >= (m_Data + m_CurrentUsedSize))
|
||||
return false;
|
||||
|
||||
if (m_CurrentUsedSize > 1)
|
||||
@ -437,4 +438,5 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#endif // __CVECTOR_H__
|
||||
#endif // __CVECTOR_H__
|
||||
|
||||
|
@ -3,7 +3,9 @@ SRCFILES = meta_api.cpp CFile.cpp CString.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 srvcmd.cpp strptime.cpp\
|
||||
CForward.cpp CPlugin.cpp CModule.cpp CMenu.cpp emsg.cpp util.cpp \
|
||||
amx.cpp amxcore.cpp amxtime.cpp power.cpp amxxlog.cpp fakemeta.cpp mmgr/mmgr.cpp
|
||||
amxcore.cpp amxtime.cpp power.cpp amxxlog.cpp fakemeta.cpp mmgr/mmgr.cpp \
|
||||
amxxfile.cpp
|
||||
CSRCFILES = amx.c minilzo/minilzo.c
|
||||
|
||||
EXTRA_LIBS_LINUX =
|
||||
EXTRA_LIBS_WIN32 =
|
||||
@ -44,7 +46,7 @@ endif
|
||||
|
||||
|
||||
|
||||
LIBFILE_LINUX = $(MODNAME)_i386.so
|
||||
LIBFILE_LINUX = $(MODNAME)_amd64.so
|
||||
LIBFILE_WIN32 = $(MODNAME).dll
|
||||
TARGET_LINUX = $(OBJDIR_LINUX)/$(LIBFILE_LINUX)
|
||||
TARGET_WIN32 = $(OBJDIR_WIN32)/$(LIBFILE_WIN32)
|
||||
@ -61,7 +63,7 @@ OBJ_WIN32 := $(SRCFILES:%.cpp=$(OBJDIR_WIN32)/%.o)
|
||||
OBJC_WIN32 := $(CSRCFILES:%.c=$(OBJDIR_WIN32)/%.o)
|
||||
|
||||
|
||||
CCOPT = -march=i386 -O2 -s -DNDEBUG
|
||||
CCOPT = -m64 -g -ggdb3 -DHAVE_I64
|
||||
|
||||
INCLUDEDIRS=-I../curl/include -I$(SRCDIR) -I$(METADIR) -I$(SDKSRC)/engine -I$(SDKSRC)/common -I$(SDKSRC)/pm_shared -I$(SDKSRC)/dlls -I$(SDKSRC) $(EXTRA_INCLUDEDIRS)
|
||||
CFLAGS=-Wall -Wno-unknown-pragmas
|
||||
@ -70,7 +72,7 @@ CFLAGS:=$(CCOPT) $(CFLAGS) $(ODEF) $(EXTRA_FLAGS)
|
||||
|
||||
DO_CC_LINUX=$(CC_LINUX) $(CFLAGS) -fPIC $(INCLUDEDIRS) -o $@ -c $<
|
||||
DO_CC_WIN32=$(CC_WIN32) $(CFLAGS) $(INCLUDEDIRS) -o $@ -c $<
|
||||
LINK_LINUX=$(CC_LINUX) $(CFLAGS) -shared -ldl -lm $(OBJ_LINUX) $(OBJC_LINUX) $(EXTRA_LIBDIRS_LINUX) $(EXTRA_LIBS_LINUX) jits.o -o $@
|
||||
LINK_LINUX=$(CC_LINUX) $(CFLAGS) -shared -ldl -lm $(OBJ_LINUX) $(OBJC_LINUX) $(EXTRA_LIBDIRS_LINUX) $(EXTRA_LIBS_LINUX) -o $@
|
||||
LINK_WIN32=$(LD_WINDLL) -mwindows --def $(MODNAME).def --add-stdcall-alias $(OBJ_WIN32) $(OBJC_WIN32) $(EXTRA_LIBDIRS_WIN32) $(EXTRA_LIBS_WIN32) -o $@
|
||||
|
||||
$(OBJDIR_LINUX)/%.o: $(SRCDIR)/%.c
|
||||
|
@ -22,6 +22,7 @@
|
||||
*/
|
||||
|
||||
// not used
|
||||
#include <stdio.h>
|
||||
#define AMX_NODYNALOAD
|
||||
|
||||
// bad bad workaround but we have to prevent a compiler crash :/
|
||||
@ -274,8 +275,8 @@ typedef enum {
|
||||
} OPCODE;
|
||||
|
||||
typedef struct tagFUNCSTUBNT {
|
||||
uint32_t address PACKED;
|
||||
uint32_t nameofs PACKED;
|
||||
ucell address PACKED;
|
||||
ucell nameofs PACKED;
|
||||
} FUNCSTUBNT PACKED;
|
||||
|
||||
#define USENAMETABLE(hdr) \
|
||||
@ -373,7 +374,7 @@ uint16_t *amx_Align16(uint16_t *v)
|
||||
|
||||
uint32_t *amx_Align32(uint32_t *v)
|
||||
{
|
||||
assert(sizeof(cell)==4);
|
||||
assert(sizeof(*v)==4);
|
||||
init_little_endian();
|
||||
if (!amx_LittleEndian)
|
||||
swap32(v);
|
||||
@ -383,7 +384,7 @@ uint32_t *amx_Align32(uint32_t *v)
|
||||
#if defined _I64_MAX || defined HAVE_I64
|
||||
uint64_t *amx_Align64(uint64_t *v)
|
||||
{
|
||||
assert(sizeof(cell)==8);
|
||||
assert(sizeof(*v)==8);
|
||||
init_little_endian();
|
||||
if (!amx_LittleEndian)
|
||||
swap64(v);
|
||||
@ -436,7 +437,6 @@ int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, cell *params)
|
||||
func=GETENTRY(hdr,natives,index);
|
||||
f=(AMX_NATIVE)func->address;
|
||||
assert(f!=NULL);
|
||||
|
||||
/* now that we have found the function, patch the program so that any
|
||||
* subsequent call will call the function directly (bypassing this
|
||||
* callback)
|
||||
@ -466,8 +466,9 @@ int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, cell *params)
|
||||
* etc.
|
||||
*/
|
||||
|
||||
amx->error=AMX_ERR_NONE;
|
||||
*result = f(amx,params);
|
||||
amx->error=AMX_ERR_NONE;
|
||||
*result= f(amx,params);
|
||||
|
||||
return amx->error;
|
||||
}
|
||||
|
||||
@ -949,9 +950,9 @@ int AMXAPI amx_Init(AMX *amx,void *program)
|
||||
assert(hdr->publics<=hdr->natives);
|
||||
num=NUMENTRIES(hdr,publics,natives);
|
||||
for (i=0; i<num; i++) {
|
||||
amx_Align32(&fs->address);
|
||||
amx_AlignCell(&fs->address);
|
||||
if (USENAMETABLE(hdr))
|
||||
amx_Align32(&((FUNCSTUBNT*)fs)->nameofs);
|
||||
amx_AlignCell(&((FUNCSTUBNT*)fs)->nameofs);
|
||||
fs=(AMX_FUNCSTUB*)((unsigned char *)fs+hdr->defsize);
|
||||
} /* for */
|
||||
|
||||
@ -959,9 +960,9 @@ int AMXAPI amx_Init(AMX *amx,void *program)
|
||||
assert(hdr->pubvars<=hdr->tags);
|
||||
num=NUMENTRIES(hdr,pubvars,tags);
|
||||
for (i=0; i<num; i++) {
|
||||
amx_Align32(&fs->address);
|
||||
amx_AlignCell(&fs->address);
|
||||
if (USENAMETABLE(hdr))
|
||||
amx_Align32(&((FUNCSTUBNT*)fs)->nameofs);
|
||||
amx_AlignCell(&((FUNCSTUBNT*)fs)->nameofs);
|
||||
fs=(AMX_FUNCSTUB*)((unsigned char *)fs+hdr->defsize);
|
||||
} /* for */
|
||||
|
||||
@ -974,9 +975,9 @@ int AMXAPI amx_Init(AMX *amx,void *program)
|
||||
num=NUMENTRIES(hdr,tags,nametable);
|
||||
} /* if */
|
||||
for (i=0; i<num; i++) {
|
||||
amx_Align32(&fs->address);
|
||||
amx_AlignCell(&fs->address);
|
||||
if (USENAMETABLE(hdr))
|
||||
amx_Align32(&((FUNCSTUBNT*)fs)->nameofs);
|
||||
amx_AlignCell(&((FUNCSTUBNT*)fs)->nameofs);
|
||||
fs=(AMX_FUNCSTUB*)((unsigned char *)fs+hdr->defsize);
|
||||
} /* for */
|
||||
} /* if */
|
||||
@ -1591,7 +1592,7 @@ int AMXAPI amx_Register(AMX *amx, AMX_NATIVE_INFO *list, int number)
|
||||
/* this function is not yet located */
|
||||
funcptr=(list!=NULL) ? findfunction(GETENTRYNAME(hdr,func),list,number) : NULL;
|
||||
if (funcptr!=NULL)
|
||||
func->address=(uint32_t)funcptr;
|
||||
func->address=(ucell)funcptr;
|
||||
else
|
||||
{
|
||||
no_function = GETENTRYNAME(hdr,func);
|
||||
@ -1788,6 +1789,7 @@ static void *amx_opcodelist_nodebug[] = {
|
||||
amx->debug(amx);
|
||||
} /* if */
|
||||
|
||||
|
||||
/* sanity checks */
|
||||
assert(OP_PUSH_PRI==36);
|
||||
assert(OP_PROC==46);
|
||||
@ -1830,6 +1832,7 @@ static void *amx_opcodelist_nodebug[] = {
|
||||
/* check stack/heap before starting to run */
|
||||
CHKMARGIN();
|
||||
|
||||
|
||||
/* start running */
|
||||
NEXT(cip);
|
||||
|
||||
|
@ -25,6 +25,9 @@
|
||||
#include <sclinux.h>
|
||||
#endif
|
||||
|
||||
#define SMALL_CELL_SIZE 64
|
||||
#undef JIT
|
||||
|
||||
#ifndef AMX_H_INCLUDED
|
||||
#define AMX_H_INCLUDED
|
||||
|
||||
@ -179,7 +182,7 @@ typedef struct {
|
||||
#define sNAMEMAX 31 /* maximum name length of symbol name */
|
||||
|
||||
typedef struct tagAMX_FUNCSTUB {
|
||||
uint32_t address PACKED;
|
||||
ucell address PACKED;
|
||||
const char name[sEXPMAX+1] PACKED;
|
||||
} AMX_FUNCSTUB;
|
||||
|
||||
@ -335,6 +338,13 @@ uint32_t * AMXAPI amx_Align32(uint32_t *v);
|
||||
#if defined _I64_MAX || defined HAVE_I64
|
||||
uint64_t * AMXAPI amx_Align64(uint64_t *v);
|
||||
#endif
|
||||
#if SMALL_CELL_SIZE==32
|
||||
#define amx_AlignCell amx_Align32
|
||||
#elif SMALL_CELL_SIZE==64
|
||||
#define amx_AlignCell amx_Align64
|
||||
#else
|
||||
#error Unsupported cell size
|
||||
#endif
|
||||
int AMXAPI amx_Allot(AMX *amx, int cells, cell *amx_addr, cell **phys_addr);
|
||||
int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, cell *params);
|
||||
int AMXAPI amx_Cleanup(AMX *amx);
|
||||
|
@ -1322,9 +1322,9 @@ static cell AMX_NATIVE_CALL read_data(AMX *amx, cell *params) /* 3 param */
|
||||
return set_amxstring(amx,params[2], g_events.getArgString( params[1] ),*get_amxaddr(amx,params[3]));
|
||||
default:
|
||||
cell *fCell = get_amxaddr(amx,params[2]);
|
||||
float *pFloat = (REAL *)((void *)fCell);
|
||||
*pFloat = g_events.getArgFloat( params[1] );
|
||||
return (int)(*pFloat);
|
||||
REAL pFloat = amx_ctof(fCell);
|
||||
pFloat = g_events.getArgFloat( params[1] );
|
||||
return (int)(pFloat);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1941,8 +1941,8 @@ static cell AMX_NATIVE_CALL get_user_aiming(AMX *amx, cell *params) /* 4 param *
|
||||
cell *cpId = get_amxaddr(amx,params[2]);
|
||||
cell *cpBody = get_amxaddr(amx,params[3]);
|
||||
cell fCell;
|
||||
float *pFloat = (REAL *)((void *)&fCell);
|
||||
*pFloat = 0.0;
|
||||
REAL pFloat = amx_ctof(fCell);
|
||||
pFloat = 0.0;
|
||||
if (pPlayer->ingame) {
|
||||
edict_t* edict = pPlayer->pEdict;
|
||||
Vector v_forward;
|
||||
@ -1967,7 +1967,7 @@ static cell AMX_NATIVE_CALL get_user_aiming(AMX *amx, cell *params) /* 4 param *
|
||||
*cpId = FNullEnt(trEnd.pHit) ? 0 : ENTINDEX(trEnd.pHit);
|
||||
*cpBody = trEnd.iHitgroup;
|
||||
if (trEnd.flFraction < 1.0) {
|
||||
*pFloat = (trEnd.vecEndPos - v_src).Length();
|
||||
pFloat = (trEnd.vecEndPos - v_src).Length();
|
||||
return fCell;
|
||||
}
|
||||
else {
|
||||
|
@ -51,11 +51,15 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef lzo_byte mint8_t;
|
||||
typedef int16_t mint16_t;
|
||||
typedef int32_t mint32_t;
|
||||
|
||||
struct TableEntry
|
||||
{
|
||||
CAmxxReader::mint8_t cellSize PACKED;
|
||||
CAmxxReader::mint32_t origSize PACKED; // contains AMX_HEADER->stp
|
||||
CAmxxReader::mint32_t offset PACKED;
|
||||
mint8_t cellSize PACKED;
|
||||
mint32_t origSize PACKED; // contains AMX_HEADER->stp
|
||||
mint32_t offset PACKED;
|
||||
};
|
||||
|
||||
#define DATAREAD(addr, itemsize, itemcount) \
|
||||
@ -136,7 +140,8 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
|
||||
TableEntry entry;
|
||||
|
||||
m_SectionHdrOffset = 0;
|
||||
for (int i = 0; i < static_cast<int>(numOfPlugins); ++i)
|
||||
int i = 0;
|
||||
for (i = 0; i < static_cast<int>(numOfPlugins); ++i)
|
||||
{
|
||||
DATAREAD(&entry, sizeof(entry), 1);
|
||||
if (entry.cellSize == m_CellSize)
|
||||
@ -154,7 +159,7 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
|
||||
}
|
||||
|
||||
// compute section length
|
||||
if (i < static_cast<int>(numOfPlugins))
|
||||
if ((i+1) < static_cast<int>(numOfPlugins))
|
||||
{
|
||||
// there is a next section
|
||||
TableEntry nextEntry;
|
||||
@ -164,7 +169,7 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
|
||||
else
|
||||
{
|
||||
fseek(m_pFile, 0, SEEK_END);
|
||||
m_SectionLength = ftell(m_pFile) - entry.offset;
|
||||
m_SectionLength = ftell(m_pFile) - (long)entry.offset;
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,4 +270,4 @@ CAmxxReader::Error CAmxxReader::GetSection(void *buffer)
|
||||
return Err_Decompress;
|
||||
}
|
||||
return Err_None;
|
||||
}
|
||||
}
|
||||
|
@ -47,10 +47,6 @@ public:
|
||||
Err_Decompress
|
||||
};
|
||||
|
||||
typedef char mint8_t;
|
||||
typedef short mint16_t;
|
||||
typedef long mint32_t;
|
||||
|
||||
private:
|
||||
Error m_Status;
|
||||
FILE *m_pFile;
|
||||
@ -70,4 +66,5 @@ public:
|
||||
};
|
||||
|
||||
|
||||
#endif // __AMXXFILE_H__
|
||||
#endif // __AMXXFILE_H__
|
||||
|
||||
|
@ -35,7 +35,9 @@
|
||||
// 3 = HL Logs
|
||||
|
||||
#include <time.h>
|
||||
#ifndef __linux__
|
||||
#include <io.h>
|
||||
#endif
|
||||
#include "amxmodx.h"
|
||||
|
||||
CLog::CLog()
|
||||
|
@ -48,4 +48,5 @@ public:
|
||||
void Log(const char *fmt, ...);
|
||||
};
|
||||
|
||||
#endif // __AMXXLOG_H__
|
||||
#endif // __AMXXLOG_H__
|
||||
|
||||
|
@ -225,4 +225,5 @@ public:
|
||||
// defined in meta_api.cpp
|
||||
extern CFakeMeta g_FakeMeta;
|
||||
|
||||
#endif // #ifndef __FAKEMETA_H__
|
||||
#endif // #ifndef __FAKEMETA_H__
|
||||
|
||||
|
@ -390,8 +390,11 @@ void C_ServerActivate_Post( edict_t *pEdictList, int edictCount, int clientMax )
|
||||
pPlayer->Init( pEdictList + i , i );
|
||||
}
|
||||
|
||||
AMXXLOG_Log("BLABLA0");
|
||||
executeForwards(FF_PluginInit);
|
||||
AMXXLOG_Log("BLABLA1");
|
||||
executeForwards(FF_PluginCfg);
|
||||
AMXXLOG_Log("BLABLA2");
|
||||
|
||||
// Correct time in Counter-Strike and other mods (except DOD)
|
||||
if ( !g_bmod_dod) g_game_timeleft = 0;
|
||||
|
@ -90,47 +90,6 @@ void free_amxmemory(void **ptr)
|
||||
|
||||
int load_amxscript(AMX *amx, void **program, const char *filename, char error[64])
|
||||
{
|
||||
/* :TODO: REMOVE
|
||||
FILE *fp;
|
||||
|
||||
AMX_HEADER hdr;
|
||||
|
||||
memset(amx, 0, sizeof(*amx));
|
||||
*program = 0;
|
||||
*error = 0;
|
||||
|
||||
if ( (fp = fopen( filename, "rb" )) == NULL)
|
||||
{
|
||||
strcpy(error,"Plugin file open error");
|
||||
return (amx->error = AMX_ERR_NOTFOUND);
|
||||
}
|
||||
|
||||
fread(&hdr, sizeof(hdr), 1, fp);
|
||||
|
||||
amx_Align16(&hdr.magic);
|
||||
|
||||
if (hdr.magic!=AMX_MAGIC)
|
||||
{
|
||||
strcpy(error,"Invalid plugin");
|
||||
return (amx->error = AMX_ERR_FORMAT);
|
||||
}
|
||||
|
||||
amx_Align32((uint32_t *)&hdr.stp);
|
||||
amx_Align32((uint32_t *)&hdr.size);
|
||||
|
||||
if ( (*program = new unsigned char[ (int)hdr.stp ]) == 0 )
|
||||
//if ( (*program = malloc( (int)hdr.stp )) == 0 )
|
||||
{
|
||||
strcpy(error,"Failed to allocate memory");
|
||||
fclose(fp);
|
||||
return (amx->error = AMX_ERR_MEMORY);
|
||||
}
|
||||
|
||||
rewind(fp);
|
||||
fread(*program, 1, (size_t)hdr.size, fp);
|
||||
fclose(fp);
|
||||
*/
|
||||
|
||||
*error = 0;
|
||||
CAmxxReader reader(filename, SMALL_CELL_SIZE / 8);
|
||||
if (reader.GetStatus() == CAmxxReader::Err_None)
|
||||
@ -242,6 +201,7 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64
|
||||
}
|
||||
|
||||
g_loadedscripts.put( aa );
|
||||
amx->sysreq_d = 0;
|
||||
return set_amxnatives(amx,error);
|
||||
}
|
||||
|
||||
@ -277,7 +237,6 @@ int unload_amxscript(AMX* amx, void** program)
|
||||
CList<CScript,AMX*>::iterator a = g_loadedscripts.find( amx );
|
||||
if ( a ) a.remove();
|
||||
delete[] *program;
|
||||
//free( *program );
|
||||
*program = 0;
|
||||
return AMX_ERR_NONE;
|
||||
}
|
||||
@ -983,3 +942,14 @@ void *Module_ReqFnptr(const char *funcName)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// :TODO: REMOVE!!!!!
|
||||
extern "C" void amxx_print(const char * fmt, ...)
|
||||
{
|
||||
static char string[256];
|
||||
|
||||
va_list argptr;
|
||||
va_start (argptr, fmt);
|
||||
vsnprintf (string, 255, fmt, argptr);
|
||||
va_end (argptr);
|
||||
print_srvconsole(string);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user