Merge pull request #31 from xPaw/burn-baby-burn

Remove compatibility stuff from the core
This commit is contained in:
Vincent Herbet 2014-07-27 12:07:58 +02:00
commit d2595b8b92
27 changed files with 30 additions and 955 deletions

View File

@ -87,7 +87,6 @@ binary.sources = [
'libraries.cpp',
'vector.cpp',
'sorting.cpp',
'amxmod_compat.cpp',
'nongpl_matches.cpp',
'CFlagManager.cpp',
'datastructs.cpp',

View File

@ -33,7 +33,7 @@
#include "debugger.h"
#include "binlog.h"
CForward::CForward(const char *name, ForwardExecType et, int numParams, const ForwardParam *paramTypes, int fwd_type)
CForward::CForward(const char *name, ForwardExecType et, int numParams, const ForwardParam *paramTypes)
{
m_FuncName = name;
m_ExecType = et;
@ -47,13 +47,6 @@ CForward::CForward(const char *name, ForwardExecType et, int numParams, const Fo
for (CPluginMngr::iterator iter = g_plugins.begin(); iter; ++iter)
{
if ((fwd_type != FORWARD_ALL) &&
((fwd_type == FORWARD_ONLY_NEW && ((*iter).getAMX()->flags & AMX_FLAG_OLDFILE))
|| (fwd_type == FORWARD_ONLY_OLD && !((*iter).getAMX()->flags & AMX_FLAG_OLDFILE))
))
{
continue;
}
if ((*iter).isValid() && amx_FindPublic((*iter).getAMX(), name, &func) == AMX_ERR_NONE)
{
AMXForward tmp;
@ -367,10 +360,10 @@ cell CSPForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
return retVal;
}
int CForwardMngr::registerForward(const char *funcName, ForwardExecType et, int numParams, const ForwardParam * paramTypes, int fwd_type)
int CForwardMngr::registerForward(const char *funcName, ForwardExecType et, int numParams, const ForwardParam * paramTypes)
{
int retVal = m_Forwards.size() << 1;
CForward *tmp = new CForward(funcName, et, numParams, paramTypes, fwd_type);
CForward *tmp = new CForward(funcName, et, numParams, paramTypes);
if (!tmp)
{
@ -590,7 +583,7 @@ int CForwardMngr::isSameSPForward(int id1, int id2)
&& (fwd1->m_NumParams == fwd2->m_NumParams));
}
int registerForwardC(const char *funcName, ForwardExecType et, cell *list, size_t num, int fwd_type)
int registerForwardC(const char *funcName, ForwardExecType et, cell *list, size_t num)
{
ForwardParam params[FORWARD_MAX_PARAMS];
@ -599,7 +592,7 @@ int registerForwardC(const char *funcName, ForwardExecType et, cell *list, size_
params[i] = static_cast<ForwardParam>(list[i]);
}
return g_forwards.registerForward(funcName, et, num, params, fwd_type);
return g_forwards.registerForward(funcName, et, num, params);
}
int registerForward(const char *funcName, ForwardExecType et, ...)

View File

@ -51,10 +51,6 @@
const int FORWARD_MAX_PARAMS = 32;
#define FORWARD_ONLY_OLD 1
#define FORWARD_ONLY_NEW 2
#define FORWARD_ALL 3
enum ForwardExecType
{
ET_IGNORE = 0, // Ignore return vaue
@ -111,7 +107,7 @@ class CForward
ForwardParam m_ParamTypes[FORWARD_MAX_PARAMS];
public:
CForward(const char *name, ForwardExecType et, int numParams, const ForwardParam * paramTypes, int fwd_type=FORWARD_ALL);
CForward(const char *name, ForwardExecType et, int numParams, const ForwardParam * paramTypes);
CForward() {} // leaves everything unitialized'
cell execute(cell *params, ForwardPreparedArray *preparedArrays);
@ -209,7 +205,7 @@ public:
// Interface
// Register normal forward
int registerForward(const char *funcName, ForwardExecType et, int numParams, const ForwardParam *paramTypes, int fwd_type=FORWARD_ALL);
int registerForward(const char *funcName, ForwardExecType et, int numParams, const ForwardParam *paramTypes);
// Register single plugin forward
int registerSPForward(const char *funcName, AMX *amx, int numParams, const ForwardParam * paramTypes);
int registerSPForward(int func, AMX *amx, int numParams, const ForwardParam * paramTypes);
@ -235,7 +231,7 @@ public:
// (un)register forward
int registerForward(const char *funcName, ForwardExecType et, ...);
int registerForwardC(const char *funcName, ForwardExecType et, cell *list, size_t num, int fwd_type=FORWARD_ALL);
int registerForwardC(const char *funcName, ForwardExecType et, cell *list, size_t num);
int registerSPForwardByName(AMX *amx, const char *funcName, ...);
int registerSPForwardByNameC(AMX *amx, const char *funcName, cell *list, size_t num);
int registerSPForward(AMX *amx, int func, ...);

View File

@ -33,7 +33,6 @@
#include "amxmodx.h"
#include "CLang.h"
#include "format.h"
#include "amxmod_compat.h"
#if defined(__linux__) || defined(__APPLE__)
#define _snprintf snprintf
@ -289,23 +288,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
static char outbuf[4096];
cell *addr = get_amxaddr(amx, params[parm++]);
if (amx->flags & AMX_FLAG_OLDFILE)
{
if (*addr & BCOMPAT_TRANSLATE_BITS)
{
const char *key, *def;
if (!translate_bcompat(amx, addr, &key, &def))
{
goto normal_string;
}
len = atcprintf(outbuf, sizeof(outbuf)-1, def, amx, params, &parm);
} else {
goto normal_string;
}
} else {
normal_string:
len = atcprintf(outbuf, sizeof(outbuf)-1, addr, amx, params, &parm);
}
return outbuf;
}

View File

@ -474,8 +474,7 @@ char *CPluginMngr::ReadIntoOrFromCache(const char *file, size_t &bufsize)
pl->file = new CAmxxReader(file, sizeof(cell));
pl->buffer = NULL;
if (pl->file->GetStatus() != CAmxxReader::Err_None ||
pl->file->IsOldFile())
if (pl->file->GetStatus() != CAmxxReader::Err_None)
{
delete pl->file;
delete pl;

View File

@ -20,7 +20,7 @@ OBJECTS = meta_api.cpp CFile.cpp CVault.cpp vault.cpp float.cpp file.cpp modules
amxxfile.cpp CLang.cpp md5.cpp emsg.cpp CForward.cpp CPlugin.cpp CModule.cpp \
CMenu.cpp util.cpp amx.cpp amxdbg.cpp natives.cpp newmenus.cpp debugger.cpp \
optimizer.cpp format.cpp messages.cpp libraries.cpp vector.cpp sorting.cpp \
amxmod_compat.cpp nongpl_matches.cpp CFlagManager.cpp datastructs.cpp \
nongpl_matches.cpp CFlagManager.cpp datastructs.cpp \
trie_natives.cpp CDataPack.cpp datapacks.cpp
##############################################

View File

@ -322,7 +322,7 @@ enum {
#define AMX_FLAG_COMPACT 0x04 /* compact encoding */
#define AMX_FLAG_BYTEOPC 0x08 /* opcode is a byte (not a cell) */
#define AMX_FLAG_NOCHECKS 0x10 /* no array bounds checking; no STMT opcode */
#define AMX_FLAG_OLDFILE 0x20 /* Old AMX Mod plugin */
/* AMX_FLAG_OLDFILE 0x20 Old AMX Mod plugin */
#define AMX_FLAG_PRENIT 0x100 /* pre-initialized, do not check natives */
#define AMX_FLAG_NTVREG 0x1000 /* all native functions are registered */
#define AMX_FLAG_JITC 0x2000 /* abstract machine is JIT compiled */

View File

@ -1,122 +0,0 @@
#include "amxmodx.h"
#include "amxmod_compat.h"
#include "format.h"
bool GetTranslation(amxtrans_t trans, int &key, int &dest, int &lang)
{
key = (trans & BCOMPAT_TRANSLATE_KEYMASK);
dest = (trans >> BCOMPAT_TRANSLATE_DESTRSH) & BCOMPAT_TRANSLATE_DESTMASK;
lang = (trans >> BCOMPAT_TRANSLATE_LANGRSH) & BCOMPAT_TRANSLATE_LANGMASK;
if (dest == 0x3F)
{
dest = -1;
}
if (lang == 0x1F)
{
lang = -1;
}
return true;
}
bool translate_bcompat(AMX *amx, cell *source, const char **_key, const char **_def)
{
amxtrans_t trans = static_cast<amxtrans_t>(*source);
int key, _dest, lang;
if (!GetTranslation(trans, key, _dest, lang))
{
return false;
}
//not optimized but it works, eh
//if someone cares they can make a translate() wrapper that takes the key # in directly
const char *r_key = g_langMngr.GetKey(key);
if (!r_key)
{
return false;
}
cell amx_addr, *phys_addr;
if (amx_Allot(amx, 3, &amx_addr, &phys_addr) != AMX_ERR_NONE)
{
return false;
}
if (_dest == -1)
{
*phys_addr = LANG_PLAYER;
} else if (_dest == 0) {
*phys_addr = LANG_SERVER;
} else if (lang >= 0 && lang < g_langMngr.GetLangsNum()) {
const char *name = g_langMngr.GetLangName(lang);
phys_addr[0] = static_cast<cell>(name[0]);
phys_addr[1] = static_cast<cell>(name[1]);
phys_addr[2] = static_cast<cell>('\0');
} else {
*phys_addr = LANG_SERVER;
}
const char *def = translate(amx, amx_addr, r_key);
if (!def)
{
def = r_key;
}
amx_Release(amx, amx_addr);
*_key = g_langMngr.GetKey(key);
*_def = def;
return true;
}
static cell AMX_NATIVE_CALL amx_translate(AMX *amx, cell *params)
{
int len;
char *key = get_amxstring(amx, params[1], 0, len);
amxtrans_t trans;
int suki = g_langMngr.GetKeyEntry(key);
//Some AMX Mod plugins do not register everything they need. Prevent a crash.
if (suki == -1)
{
suki = g_langMngr.AddKeyEntry(key);
}
if (suki > BCOMPAT_TRANSLATE_KEYMASK)
{
LogError(amx, AMX_ERR_NATIVE, "Not enough translation space, aborting!");
return 0;
}
trans = suki & BCOMPAT_TRANSLATE_KEYMASK;
int dest = static_cast<int>(params[2]);
int lang = static_cast<int>(params[3]);
if (dest == -1)
{
trans |= (0x3F << BCOMPAT_TRANSLATE_DESTRSH);
} else {
trans |= (dest & BCOMPAT_TRANSLATE_DESTMASK) << BCOMPAT_TRANSLATE_DESTRSH;
}
if (lang == -1)
{
trans |= (0x1F << BCOMPAT_TRANSLATE_LANGRSH);
} else {
trans |= (lang & BCOMPAT_TRANSLATE_LANGMASK) << BCOMPAT_TRANSLATE_LANGRSH;
}
trans |= BCOMPAT_TRANSLATE_BITS;
return static_cast<cell>(trans);
}
AMX_NATIVE_INFO g_BcompatNatives[] =
{
{"translate", amx_translate},
{NULL, NULL},
};

View File

@ -1,28 +0,0 @@
#ifndef _INCLUDE_AMXMOD_CORE_COMPAT_H
#define _INCLUDE_AMXMOD_CORE_COMPAT_H
/**
* New format for translation:
* Note that we only support:
* 4k keys
* 32 languages
* 0000 0000 0000 0000 0000 0000 0000 0000
* | key id |
* | | <- dest id
* | | <- lang id
*/
#define BCOMPAT_TRANSLATE_BITS 0xFF000000
#define BCOMPAT_TRANSLATE_KEYMASK 0xFFF
#define BCOMPAT_TRANSLATE_DESTMASK 0x3F
#define BCOMPAT_TRANSLATE_DESTRSH 12
#define BCOMPAT_TRANSLATE_LANGMASK 0x1F
#define BCOMPAT_TRANSLATE_LANGRSH 18
typedef unsigned int amxtrans_t;
bool GetTranslation(amxtrans_t trans, int &key, int &dest, int &lang);
extern AMX_NATIVE_INFO g_BcompatNatives[];
#endif //_INCLUDE_AMXMOD_CORE_COMPAT_H

View File

@ -1864,18 +1864,6 @@ static cell AMX_NATIVE_CALL server_cmd(AMX *amx, cell *params) /* 1 param */
g_langMngr.SetDefLang(LANG_SERVER);
char* cmd = format_amxstring(amx, params, 1, len);
if (amx->flags & AMX_FLAG_OLDFILE)
{
if (strncmp("meta ",cmd,5)==0)
{
return len+1;
}
if (strncmp("quit", cmd,4)==0)
{
return len+1;
}
}
cmd[len++] = '\n';
cmd[len] = 0;
@ -1934,19 +1922,6 @@ static cell AMX_NATIVE_CALL get_cvar_string(AMX *amx, cell *params) /* 3 param *
int ilen;
char* sptemp = get_amxstring(amx, params[1], 0, ilen);
if (amx->flags & AMX_FLAG_OLDFILE)
{
/* :HACKHACK: Pretend we're invisible to old plugins for backward compatibility */
char *cvar = sptemp;
for (unsigned int i=0; i<5; i++)
{
if (strcmp(cvar, invis_cvar_list[i]) == 0)
{
return 0;
}
}
}
const char *value = CVAR_GET_STRING(sptemp);
return set_amxstring_utf8(amx, params[2], value, strlen(value), params[3] + 1); // + EOS
}
@ -1969,19 +1944,6 @@ static cell AMX_NATIVE_CALL get_cvar_float(AMX *amx, cell *params) /* 1 param */
{
int ilen;
if (amx->flags & AMX_FLAG_OLDFILE)
{
/* :HACKHACK: Pretend we're invisible to old plugins for backward compatibility */
char *cvar = get_amxstring(amx, params[1], 0, ilen);
for (unsigned int i=0; i<5; i++)
{
if (strcmp(cvar, invis_cvar_list[i]) == 0)
{
return 0;
}
}
}
REAL pFloat = CVAR_GET_FLOAT(get_amxstring(amx, params[1], 0, ilen));
return amx_ftoc(pFloat);
@ -2024,18 +1986,6 @@ static cell AMX_NATIVE_CALL get_pcvar_num(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL get_cvar_num(AMX *amx, cell *params) /* 1 param */
{
int ilen;
if (amx->flags & AMX_FLAG_OLDFILE)
{
/* :HACKHACK: Pretend we're invisible to old plugins for backward compatibility */
char *cvar = get_amxstring(amx, params[1], 0, ilen);
for (unsigned int i=0; i<5; i++)
{
if (strcmp(cvar, invis_cvar_list[i]) == 0)
{
return 0;
}
}
}
return (int)CVAR_GET_FLOAT(get_amxstring(amx, params[1], 0, ilen));
}
@ -2632,18 +2582,6 @@ static cell AMX_NATIVE_CALL task_exists(AMX *amx, cell *params) /* 1 param */
static cell AMX_NATIVE_CALL cvar_exists(AMX *amx, cell *params) /* 1 param */
{
int ilen;
if (amx->flags & AMX_FLAG_OLDFILE)
{
/* :HACKHACK: Pretend we're invisible to old plugins for backward compatibility */
char *cvar = get_amxstring(amx, params[1], 0, ilen);
for (unsigned int i=0; i<5; i++)
{
if (strcmp(cvar, invis_cvar_list[i]) == 0)
{
return 0;
}
}
}
return (CVAR_GET_POINTER(get_amxstring(amx, params[1], 0, ilen)) ? 1 : 0);
}
@ -3181,19 +3119,6 @@ static cell AMX_NATIVE_CALL get_cvar_flags(AMX *amx, cell *params)
int ilen;
char* sCvar = get_amxstring(amx, params[1], 0, ilen);
if (amx->flags & AMX_FLAG_OLDFILE)
{
/* :HACKHACK: Pretend we're invisible to old plugins for backward compatibility */
char *cvar = sCvar;
for (unsigned int i=0; i<5; i++)
{
if (strcmp(cvar, invis_cvar_list[i]) == 0)
{
return 0;
}
}
}
cvar_t* pCvar = CVAR_GET_POINTER(sCvar);
return pCvar ? pCvar->flags : 0;
@ -4405,21 +4330,6 @@ static cell AMX_NATIVE_CALL CreateMultiForward(AMX *amx, cell *params)
return registerForwardC(funcname, static_cast<ForwardExecType>(params[2]), ps, count-2);
}
static cell AMX_NATIVE_CALL CreateMultiForwardEx(AMX *amx, cell *params)
{
int len;
char *funcname = get_amxstring(amx, params[1], 0, len);
cell ps[FORWARD_MAX_PARAMS];
cell count = params[0] / sizeof(cell);
for (cell i=4; i<=count; i++)
{
ps[i-4] = *get_amxaddr(amx, params[i]);
}
return registerForwardC(funcname, static_cast<ForwardExecType>(params[2]), ps, count-3, params[3]);
}
static cell AMX_NATIVE_CALL CreateOneForward(AMX *amx, cell *params)
{
CPluginMngr::CPlugin *p = g_plugins.findPlugin(params[1]);
@ -5103,7 +5013,6 @@ AMX_NATIVE_INFO amxmodx_Natives[] =
{"CreateHudSyncObj", CreateHudSyncObj},
{"CreateLangKey", CreateLangKey},
{"CreateMultiForward", CreateMultiForward},
{"CreateMultiForwardEx", CreateMultiForwardEx},
{"CreateOneForward", CreateOneForward},
{"DestroyForward", DestroyForward},
{"ExecuteForward", ExecuteForward},

View File

@ -1,7 +1,6 @@
#include "amxmodx.h"
#include "format.h"
#include "datastructs.h"
#include "amxmod_compat.h"
//Adapted from Quake3's vsprintf
// thanks to cybermind for linking me to this :)
@ -634,24 +633,6 @@ reswitch:
}
case 's':
CHECK_ARGS(0);
if (amx->flags & AMX_FLAG_OLDFILE)
{
cell *addr = get_amxaddr(amx, params[arg]);
if (*addr & BCOMPAT_TRANSLATE_BITS)
{
const char *key, *def;
if (!translate_bcompat(amx, addr, &key, &def))
{
goto break_to_normal_string;
}
arg++;
size_t written = atcprintf(buf_p, llen, def, amx, params, &arg);
buf_p += written;
llen -= written;
break;
}
}
break_to_normal_string:
AddString(&buf_p, llen, get_amxaddr(amx, params[arg]), width, prec);
arg++;
break;

View File

@ -6,6 +6,5 @@ template <typename D, typename S>
size_t atcprintf(D *buffer, size_t maxlen, const S *format, AMX *amx, cell *params, int *param);
const char *translate(AMX *amx, cell amxaddr, const char *key);
bool translate_bcompat(AMX *amx, cell *source, const char **_key, const char **_def);
#endif //_INCLUDE_FORMATTING_H

View File

@ -46,7 +46,6 @@
#include "optimizer.h"
#include "libraries.h"
#include "messages.h"
#include "amxmod_compat.h"
#include "datastructs.h"
#include "CFlagManager.h"

View File

@ -51,7 +51,6 @@
#include "binlog.h"
#include "libraries.h"
#include "messages.h"
#include "amxmod_compat.h"
#include "trie_natives.h"
#include "CDataPack.h"
@ -171,7 +170,6 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64
*error = 0;
size_t bufSize;
*program = (void *)g_plugins.ReadIntoOrFromCache(filename, bufSize);
bool oldfile = false;
if (!*program)
{
CAmxxReader reader(filename, PAWN_CELL_SIZE / 8);
@ -225,8 +223,6 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64
strcpy(error, "Unknown error");
return (amx->error = AMX_ERR_NOTFOUND);
}
oldfile = reader.IsOldFile();
} else {
g_plugins.InvalidateFileInCache(filename, false);
}
@ -381,17 +377,6 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64
}
#endif
if (oldfile)
{
amx->flags |= AMX_FLAG_OLDFILE;
} else {
cell addr;
if (amx_FindPubVar(amx, "__b_old_plugin", &addr) == AMX_ERR_NONE)
{
amx->flags |= AMX_FLAG_OLDFILE;
}
}
CScript* aa = new CScript(amx, *program, filename);
g_loadedscripts.put(aa);
@ -568,7 +553,6 @@ int set_amxnatives(AMX* amx, char error[128])
for (size_t i = 0; i < cm->m_NewNatives.size(); i++)
{
if (!(amx->flags & AMX_FLAG_OLDFILE))
amx_Register(amx, cm->m_NewNatives[i], -1);
}
}
@ -590,11 +574,6 @@ int set_amxnatives(AMX* amx, char error[128])
amx_Register(amx, trie_Natives, -1);
amx_Register(amx, g_DatapackNatives, -1);
if (amx->flags & AMX_FLAG_OLDFILE)
{
amx_Register(amx, g_BcompatNatives, -1);
}
//we're not actually gonna check these here anymore
amx->flags |= AMX_FLAG_PRENIT;

View File

@ -285,7 +285,6 @@
<ClCompile Include="..\amx.cpp" />
<ClCompile Include="..\amxcore.cpp" />
<ClCompile Include="..\amxdbg.cpp" />
<ClCompile Include="..\amxmod_compat.cpp" />
<ClCompile Include="..\amxmodx.cpp" />
<ClCompile Include="..\amxtime.cpp" />
<ClCompile Include="..\amxxfile.cpp" />
@ -350,7 +349,6 @@
<ItemGroup>
<ClInclude Include="..\amx.h" />
<ClInclude Include="..\amxdbg.h" />
<ClInclude Include="..\amxmod_compat.h" />
<ClInclude Include="..\amxmodx.h" />
<ClInclude Include="..\amxxfile.h" />
<ClInclude Include="..\amxxlog.h" />

View File

@ -36,9 +36,6 @@
<ClCompile Include="..\amxdbg.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\amxmod_compat.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\amxmodx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@ -185,9 +182,6 @@
<ClInclude Include="..\amxdbg.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\amxmod_compat.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\amxmodx.h">
<Filter>Header Files</Filter>
</ClInclude>

View File

@ -33,7 +33,6 @@
#include "amxmodx.h"
#include "format.h"
#include "binlog.h"
#include "amxmod_compat.h"
const char* stristr(const char* str, const char* substr)
{
@ -147,21 +146,8 @@ extern "C" size_t get_amxstring_r(AMX *amx, cell amx_addr, char *destination, in
register char *dest = destination;
char *start = dest;
if ( (amx->flags & AMX_FLAG_OLDFILE) &&
(*source & BCOMPAT_TRANSLATE_BITS) )
{
const char *def, *key;
if (!translate_bcompat(amx, source, &key, &def))
{
goto normal_string;
}
while (maxlen-- && *def)
*dest++=(*source++);
} else {
normal_string:
while (maxlen-- && *source)
*dest++=(char)(*source++);
}
*dest = '\0';
@ -536,29 +522,6 @@ static cell AMX_NATIVE_CALL copy(AMX *amx, cell *params) /* 4 param */
cell *src = get_amxaddr(amx, params[3]);
int c = params[2];
if (amx->flags & AMX_FLAG_OLDFILE)
{
if (*src & BCOMPAT_TRANSLATE_BITS)
{
const char *key, *def;
if (!translate_bcompat(amx, src, &key, &def))
{
goto normal_string;
}
cell *dest = get_amxaddr(amx, params[1]);
cell *start = dest;
while (c-- && *def)
{
*dest++ = static_cast<cell>(*def++);
}
*dest = '\0';
return dest-start;
} else {
goto normal_string;
}
} else {
normal_string:
cell *dest = get_amxaddr(amx, params[1]);
cell *start = dest;
@ -570,7 +533,6 @@ normal_string:
return (dest - start);
}
}
static cell AMX_NATIVE_CALL copyc(AMX *amx, cell *params) /* 4 param */
{
@ -688,23 +650,7 @@ static cell AMX_NATIVE_CALL format(AMX *amx, cell *params) /* 3 param */
int param = 4;
size_t total = 0;
if (amx->flags & AMX_FLAG_OLDFILE)
{
if (*fmt & BCOMPAT_TRANSLATE_BITS)
{
const char *key, *def;
if (!translate_bcompat(amx, fmt, &key, &def))
{
goto normal_string;
}
total = atcprintf(buf, maxlen, def, amx, params, &param);
} else {
goto normal_string;
}
} else {
normal_string:
total = atcprintf(buf, maxlen, fmt, amx, params, &param);
}
if (copy)
{

View File

@ -236,15 +236,6 @@ static stringlist includepaths = {NULL, NULL}; /* directory list for include fi
SC_FUNC stringlist *insert_path(char *path)
{
char *extra_path = malloc(strlen(path) + 16);
strcpy(extra_path, path);
#if defined __linux__ || defined __APPLE__
strcat(extra_path, "/amxmod_compat/");
#elif defined WIN32 || defined _WIN32
strcat(extra_path, "\\amxmod_compat\\");
#endif
insert_string(&includepaths, extra_path);
free(extra_path);
return insert_string(&includepaths,path);
}

View File

@ -10,7 +10,6 @@ binary.sources = [
'entity.cpp',
'globals.cpp',
'forwards.cpp',
'amxmod_compat.cpp',
]
AMXX.modules += [builder.Add(binary)]

View File

@ -14,8 +14,7 @@ MM_ROOT = ../../../metamod/metamod
PROJECT = engine
OBJECTS = sdk/amxxmodule.cpp amxxapi.cpp engine.cpp entity.cpp globals.cpp forwards.cpp \
amxmod_compat.cpp
OBJECTS = sdk/amxxmodule.cpp amxxapi.cpp engine.cpp entity.cpp globals.cpp forwards.cpp
##############################################
### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###

View File

@ -1,453 +0,0 @@
#include "engine.h"
#include <cbase.h>
static cvar_t *sv_knockback1 = NULL;
static cvar_t *sv_knockback2 = NULL;
static cvar_t *sv_friendlyfire = NULL;
static bool g_ff_check = false;
static bool g_kb1_check = false;
static bool g_kb2_check = false;
static int gmsgDamage = 0;
static int gmsgDeathMsg = 0;
static int gmsgScoreInfo = 0;
//From VexdUM (AMX Mod 2006.2)
//This is not exposed, and is only provided as a compatibility helper.
BOOL is_breakable(edict_t* pBreak)
{
if (FStrEq("func_breakable", STRING(pBreak->v.classname))
|| (FStrEq("func_pushable", STRING(pBreak->v.classname))
&& pBreak->v.spawnflags & SF_PUSH_BREAKABLE))
{
return true;
}
return false;
}
//From VexdUM (AMX Mod 2006.2)
//This is not exposed, and is only provided as a compatibility helper.
BOOL is_monster(edict_t* pMonster)
{
if(pMonster->v.flags & FL_MONSTER)
{
return true;
}
return false;
}
//From VexdUM (AMX Mod 2006.2)
// Damage Monsters
void hurt_monster(edict_t* pMonster, float dmg, int bit, const float *origin)
{
int mdmg = (int)pMonster->v.health;
pMonster->v.health -= dmg;
// No need to create a trigger_hurt unless we are going to kill the monster ;)
if((int)pMonster->v.health < 1)
{
int hurt = MAKE_STRING("trigger_hurt");
char hbit[16];
char horigin[16];
snprintf(hbit, 15, "%i", bit);
snprintf(horigin, 15, "%f %f %f", origin[0], origin[1], origin[2]);
edict_t* pEntity = CREATE_NAMED_ENTITY(hurt);
KeyValueData pkvd1;
pkvd1.szClassName = "trigger_hurt";
pkvd1.szKeyName = "dmg";
pkvd1.szValue = "1.0";
pkvd1.fHandled = FALSE;
MDLL_KeyValue(pEntity, &pkvd1);
KeyValueData pkvd2;
pkvd2.szClassName = "trigger_hurt";
pkvd2.szKeyName = "damagetype";
pkvd2.szValue = hbit;
pkvd2.fHandled = FALSE;
MDLL_KeyValue(pEntity, &pkvd2);
KeyValueData pkvd3;
pkvd3.szClassName = "trigger_hurt";
pkvd3.szKeyName = "origin";
pkvd3.szValue = horigin;
pkvd3.fHandled = FALSE;
MDLL_KeyValue(pEntity, &pkvd3);
MDLL_Spawn(pEntity);
MDLL_Touch(pEntity, pMonster);
REMOVE_ENTITY(pEntity);
}
mdmg -= (int)pMonster->v.health;
//~dvander - Note, not porting the forward until this function is known to be truly wrapped
//g_forwards.executeForward(FF_MonsterHurt, ENTINDEX(pMonster), ENTINDEX(pMonster->v.dmg_inflictor), mdmg);
}
//From VexdUM (AMX Mod 2006.2)
//This appears to be from the HLSDK CBasePlayer::TakeDamage() function.
//This is not exposed, and is only provided as a compatibility helper.
float ArmorDamage(edict_t* pVictim, float dmg, int bit)
{
float flRatio = 0.2;
float flBonus = 0.5;
if(bit & DMG_BLAST)
{
// blasts damage armor more.
flBonus *= 2;
}
if(pVictim->v.armorvalue && !(bit & (DMG_FALL | DMG_DROWN)))
{
// armor doesn't protect against fall or drown damage!
float flNew = dmg * flRatio;
float flArmor = (dmg - flNew) * flBonus;
// Does this use more armor than we have?
if(flArmor > pVictim->v.armorvalue)
{
flArmor = pVictim->v.armorvalue;
flArmor *= (1/flBonus);
flNew = dmg - flArmor;
pVictim->v.armorvalue = 0;
} else {
pVictim->v.armorvalue -= flArmor;
}
dmg = flNew;
}
// Lets knock the view about abit
pVictim->v.punchangle.x = -4;
return dmg;
}
// Death emulation
//This is not exposed, and is only provided as a compatibility helper.
void Death(edict_t* pVictim, edict_t* pKiller, const char* weapon, int hs)
{
if (!gmsgDeathMsg)
{
gmsgDeathMsg = GET_USER_MSG_ID(PLID, "DeathMsg", NULL);
}
if (!gmsgScoreInfo)
{
gmsgScoreInfo = GET_USER_MSG_ID(PLID, "ScoreInfo", NULL);
}
// Make sure an entity is allowed to take damage
if(pVictim->v.takedamage > DAMAGE_NO)
{
// Breakable Check
if(is_breakable(pVictim))
{
MDLL_Use(pVictim, pKiller);
}
// Monster Check
if (is_monster(pVictim))
{
pVictim->v.dmg_inflictor = pKiller;
float dmg = pVictim->v.health;
int bit = DMG_BULLET;
const float *origin = pVictim->v.origin;
hurt_monster(pVictim, dmg, bit, origin);
}
// Player Check
if (pVictim->v.flags & (FL_CLIENT | FL_FAKECLIENT))
{
pVictim->v.dmg_inflictor = pKiller;
edict_t* inflictor = pKiller->v.owner;
int inflictorId = FNullEnt(inflictor) ? ENTINDEX(inflictor) : 0;
// See if it is a player attacking with a default weapon
if (pKiller->v.flags & (FL_CLIENT | FL_FAKECLIENT))
{
// We only modify the weapon if it = 0, otherwise its been specified
if(strcmp(weapon, "") == 0)
{
char view_weapon[64];
// Get the name from the view model
weapon = STRING(pKiller->v.viewmodel);
// Strip out the beginning of the viewmodel (models/v_)
if(strncmp(weapon, "models/v_", 9) == 0)
{
strcpy(view_weapon, weapon + 9);
}
// Strip out the end of viewmodel (.mdl)
view_weapon[strlen(view_weapon) - 4] = '\0';
weapon = view_weapon;
}
// See if its an entity attacking, if so lets find its owner
} else if (inflictorId >= 1 && inflictorId <= gpGlobals->maxClients) {
// We only modify the weapon if it = 0, otherwise its been specified
if(strcmp(weapon, "") == 0)
{
weapon = STRING(pKiller->v.classname);
// Strip out the default part of weapon name (HLSDK)
if(strncmp(weapon, "weapon_", 7) == 0)
{
weapon += 7;
} else if(strncmp(weapon, "monster_", 8) == 0) {
weapon += 8;
} else if(strncmp(weapon, "func_", 5) == 0) {
weapon += 5;
}
}
// Check to see if the victim is the owner
if(inflictor == pVictim)
{
pKiller = pVictim;
} else {
pKiller = inflictor;
}
}
// Send the Death Event
int killerId = ENTINDEX(pKiller);
int victimId = ENTINDEX(pVictim);
MESSAGE_BEGIN( MSG_ALL, gmsgDeathMsg );
WRITE_BYTE( killerId > gpGlobals->maxClients ? 0 : killerId );
WRITE_BYTE( victimId );
WRITE_BYTE( hs );
WRITE_STRING( weapon );
MESSAGE_END();
// Log this kill
if(pVictim == pKiller)
{
// killed self
UTIL_LogPrintf("\"%s<%i><%s><%s>\" killed self with \"%s\"\n",
STRING( pVictim->v.netname ),
GETPLAYERUSERID( pVictim ),
GETPLAYERAUTHID( pVictim ),
MF_GetPlayerTeam(victimId),
weapon );
// Killed by another player
} else if(pKiller->v.flags & (FL_CLIENT | FL_FAKECLIENT)) {
UTIL_LogPrintf("\"%s<%i><%s><%s>\" killed \"%s<%i><%s><%s>\" with \"%s\"\n",
STRING( pKiller->v.netname ),
GETPLAYERUSERID( pKiller ),
GETPLAYERAUTHID( pKiller ),
MF_GetPlayerTeam(killerId),
STRING( pVictim->v.netname ),
GETPLAYERUSERID( pVictim ),
GETPLAYERAUTHID( pVictim ),
MF_GetPlayerTeam(victimId),
weapon);
int killerTeam = MF_GetPlayerTeamID(killerId);
int victimTeam = MF_GetPlayerTeamID(victimId);
if (killerTeam != victimTeam)
{
// Give Killer credit for this kill
pKiller->v.frags += 1;
} else {
pKiller->v.frags -= 1;
}
// Update the scoreboard for the killer
if (gmsgScoreInfo)
{
MESSAGE_BEGIN(MSG_ALL, gmsgScoreInfo);
WRITE_BYTE( killerId );
WRITE_SHORT( (int)pKiller->v.frags );
WRITE_SHORT( MF_GetPlayerDeaths(killerId) );
WRITE_SHORT( 0 );
WRITE_SHORT( MF_GetPlayerTeamID(killerId) );
MESSAGE_END();
}
// Give Victim back 1 point since they didn't kill themselves
pVictim->v.frags += 1;
}
// Killed by something else?
else {
UTIL_LogPrintf( "\"%s<%i><%s><%s>\" killed by \"%s\"\n",
STRING( pVictim->v.netname ),
GETPLAYERUSERID( pVictim ),
GETPLAYERAUTHID( pVictim ),
MF_GetPlayerTeam(victimId),
weapon );
// Give Victim back 1 point since they didn't commit suicide
pVictim->v.frags += 1;
}
#if 0
//still a todo on this one
gInfo.logBlock = true;
#endif
int opt = BLOCK_ONCE;
MF_MessageBlock(MSGBLOCK_SET, gmsgDeathMsg, &opt);
// Kill the client, since the relevent logging blocks are in place
MDLL_ClientKill(pVictim);
// Restore the old message type
MF_MessageBlock(MSGBLOCK_SET, gmsgDeathMsg, &opt);
// Show the Victim the killing location
pVictim->v.iuser3 = (killerId > gpGlobals->maxClients) ? 0 : killerId;
}
}
}
// Damage emulation
// From VexdUM (AMX Mod 2006.2)
//This is not exposed, and is only provided as a compatibility helper.
void Damage(edict_t *pVictim,
edict_t *pAttacker,
const float *origin,
float dmg,
int bit,
const char *weapon,
int hs)
{
if (!g_ff_check && !sv_friendlyfire)
{
sv_friendlyfire = CVAR_GET_POINTER("sv_friendlyfire");
g_ff_check = true;
}
if (!gmsgDamage)
{
gmsgDamage = GET_USER_MSG_ID(PLID, "Damage", NULL);
}
// Make sure an entity is allowed to take damage
if(pVictim->v.takedamage > DAMAGE_NO)
{
// Breakable Check
if(is_breakable(pVictim) && (int)dmg > 0)
{
MDLL_Use(pVictim, pAttacker);
}
// Monster Check
if(is_monster(pVictim) && (int)dmg > 0)
{
pVictim->v.dmg_inflictor = pAttacker;
hurt_monster(pVictim, dmg, bit, origin);
}
// Player Check
if(pVictim->v.flags & (FL_CLIENT | FL_FAKECLIENT))
{
int AttackerId = ENTINDEX(pAttacker);
int AttackerOwnerId = ENTINDEX(pAttacker->v.owner);
int VictimId = ENTINDEX(pVictim);
int vTeam = MF_GetPlayerTeamID(VictimId);
int aTeam = 0;
if (AttackerId >= 1 && AttackerId <= gpGlobals->maxClients)
{
aTeam = MF_GetPlayerTeamID(AttackerId);
} else if (AttackerOwnerId >= 1 && AttackerOwnerId <= gpGlobals->maxClients) {
aTeam = MF_GetPlayerTeamID(AttackerOwnerId);
}
if((sv_friendlyfire && (int)sv_friendlyfire->value) || (vTeam != aTeam))
{
// Recalculate the damage since we might have armor
dmg = ArmorDamage(pVictim, dmg, bit);
// Only allow damage to process if more than 0.5
if((int)dmg > 0)
{
// Setting to externally flag who last attacked the Victim, pretty neat huh?
pVictim->v.dmg_inflictor = pAttacker;
pVictim->v.dmg_take += dmg;
// Register the Damage Event
MESSAGE_BEGIN( MSG_ONE, gmsgDamage, NULL, pVictim );
WRITE_BYTE( (int)pVictim->v.dmg_save );
WRITE_BYTE( (int)pVictim->v.dmg_take );
WRITE_LONG( bit );
WRITE_COORD( origin[0] );
WRITE_COORD( origin[1] );
WRITE_COORD( origin[2] );
MESSAGE_END();
if((int)dmg >= (int)pVictim->v.health)
{
// Kill the victim
pVictim->v.health = 0.0;
// Send info to Death system
Death(pVictim, pAttacker, weapon, hs);
}else {
// Take health away from victim
pVictim->v.health -= dmg;
}
}
}
}
}
}
// Radius Damage emulation -
// From VexdUM (AMX Mod 2006.2)
//This is not exposed, and is only provided as a compatibility helper.
void RadiusDamage_AMXMod_Base(edict_t *pAttacker,
float dmg,
Vector vecSrc,
float rad,
int bit,
const char *weapon,
int hs)
{
edict_t *pTarget = NULL;
TraceResult tr;
float falloff;
Vector vecSpot;
Vector vecSee;
if (!g_kb1_check && !sv_knockback1)
{
sv_knockback1 = CVAR_GET_POINTER("sv_knockback1");
g_kb1_check = true;
}
if (!g_kb2_check && !sv_knockback2)
{
sv_knockback2 = CVAR_GET_POINTER("sv_knockback2");
g_kb2_check = true;
}
if(rad > 0.0)
{
falloff = dmg / rad;
} else {
falloff = 1.0;
}
vecSrc.z += 1; // In case grenade is lying on the ground
int hitId;
int targetId;
while ((pTarget = UTIL_FindEntityInSphere(pTarget, vecSrc, rad)) != NULL)
{
// Make sure an entity is allowed to take damage
if (pTarget->v.takedamage > DAMAGE_NO)
{
//none of this code was working so I simplified it
//damage doesn't check for visibility now (it probably shouldn't anyway)
//for this to work it seems like an exception needs to be made for world OR
// the spot/see things aren't being calculated right.
#if 0
vecSpot = (pTarget->v.absmin + pTarget->v.absmax) * 0.5;
vecSee = (pAttacker->v.absmin + pAttacker->v.absmax) * 0.5;
TRACE_LINE(vecSee, vecSpot, FALSE, pAttacker, &tr);
// Explosion can 'see' this entity, so hurt them!
#endif
TRACE_LINE(vecSrc, pTarget->v.origin, FALSE, pAttacker, &tr);
hitId = ENTINDEX(tr.pHit);
targetId = ENTINDEX(pTarget);
if(tr.flFraction < 1.0 || (hitId == targetId))
{
// Work out the distance between impact and entity
float dist = (tr.vecEndPos - vecSrc).Length() * falloff;
// Damage algorithm, its just that easy :)
dmg -= dist;
// Knockback Effect
if(pTarget->v.flags & (FL_CLIENT | FL_FAKECLIENT) && (bit & (DMG_BLAST | DMG_CLUB | DMG_SHOCK | DMG_SONIC | DMG_ENERGYBEAM | DMG_MORTAR)))
{
Vector vecPush = (pTarget->v.origin - (pAttacker->v.absmin + pAttacker->v.absmax) * 0.5).Normalize();
if(dmg < 60.0)
{
pTarget->v.velocity = pTarget->v.velocity + vecPush * dmg * (sv_knockback1 ? sv_knockback1->value : 1.0f);
} else {
pTarget->v.velocity = pTarget->v.velocity + vecPush * dmg * (sv_knockback2 ? sv_knockback2->value : 1.0f);
}
}
// Send info to Damage system
Damage(pTarget, pAttacker, vecSrc, dmg, bit, weapon, hs);
}
}
}
pTarget = NULL;
}

View File

@ -1,25 +0,0 @@
#ifndef _INCLUDE_ENGINE_AMXMOD_BCOMPAT_H_
#define _INCLUDE_ENGINE_AMXMOD_BCOMPAT_H_
BOOL is_breakable(edict_t* pBreak);
BOOL is_monster(edict_t* pMonster);
void hurt_monster(edict_t* pMonster, float dmg, int bit, const float *origin);
float ArmorDamage(edict_t* pVictim, float dmg, int bit);
void Death(edict_t* pVictim, edict_t* pKiller, const char* weapon, int hs);
void Damage(edict_t *pVictim,
edict_t *pAttacker,
const float *origin,
float dmg,
int bit,
const char *weapon,
int hs);
void RadiusDamage_AMXMod_Base(edict_t *pAttacker,
float dmg,
Vector vecSrc,
float rad,
int bit,
const char *weapon,
int hs);
#endif //_INCLUDE_ENGINE_AMXMOD_BCOMPAT_H_

View File

@ -1,5 +1,4 @@
#include "engine.h"
#include "amxmod_compat.h"
struct usercmd_s *g_cmd;
struct PlayerInfo plinfo[33];
@ -98,32 +97,10 @@ static cell AMX_NATIVE_CALL halflife_time(AMX *amx, cell *params)
return amx_ftoc(fVal);
}
//This is not exposed, and is only provided as a compatibility helper.
static cell AMX_NATIVE_CALL RadiusDamage_AMXMod(AMX *amx, cell *params)
{
int ent = params[1];
CHECK_ENTITY_SIMPLE(ent);
edict_t* pEntity = INDEXENT(ent);
float dmg = amx_ctof(params[2]);
cell *vInput = MF_GetAmxAddr(amx, params[3]);
float vOrig[3];
vOrig[0] = amx_ctof(vInput[0]);
vOrig[1] = amx_ctof(vInput[1]);
vOrig[2] = amx_ctof(vInput[2]);
float rad = amx_ctof(params[4]);
int bit = params[5];
int iLen;
char *vxWeapon = MF_GetAmxString(amx, params[6], 0, &iLen);
int hs = params[7];
RadiusDamage_AMXMod_Base(pEntity, dmg, vOrig, rad, bit, vxWeapon, hs);
return 1;
}
static cell AMX_NATIVE_CALL RadiusDamage_AMXModX(AMX *amx, cell *params)
// RadiusDamage. Damages players within a certain radius. ToDo: add the
// damage messaging so players know where the damage is coming from
// (the red arrow-like things on the screen).
static cell AMX_NATIVE_CALL RadiusDamage(AMX *amx, cell *params)
{
cell *cAddr = MF_GetAmxAddr(amx,params[1]);
@ -201,24 +178,6 @@ static cell AMX_NATIVE_CALL RadiusDamage_AMXModX(AMX *amx, cell *params)
return 1;
}
// RadiusDamage. Damages players within a certain radius. ToDo: add the
// damage messaging so players know where the damage is coming from
// (the red arrow-like things on the screen).
//(vexd)
static cell AMX_NATIVE_CALL RadiusDamage(AMX *amx, cell *params)
{
cell numParams = params[0] / sizeof(cell);
if (numParams == 3)
{
return RadiusDamage_AMXModX(amx, params);
} else if (numParams == 7) {
return RadiusDamage_AMXMod(amx, params);
}
return 0;
}
static cell AMX_NATIVE_CALL PointContents(AMX *amx, cell *params)
{
cell *cAddr = MF_GetAmxAddr(amx, params[1]);

View File

@ -94,7 +94,6 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\amxmod_compat.cpp" />
<ClCompile Include="..\amxxapi.cpp" />
<ClCompile Include="..\engine.cpp" />
<ClCompile Include="..\entity.cpp" />
@ -103,7 +102,6 @@
<ClCompile Include="..\sdk\amxxmodule.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\amxmod_compat.h" />
<ClInclude Include="..\engine.h" />
<ClInclude Include="..\entity.h" />
<ClInclude Include="..\gpglobals.h" />

View File

@ -23,9 +23,6 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\amxmod_compat.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\amxxapi.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@ -46,9 +43,6 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\amxmod_compat.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\engine.h">
<Filter>Header Files</Filter>
</ClInclude>

View File

@ -272,7 +272,7 @@ enum {
#define AMX_FLAG_COMPACT 0x04 /* compact encoding */
#define AMX_FLAG_BYTEOPC 0x08 /* opcode is a byte (not a cell) */
#define AMX_FLAG_NOCHECKS 0x10 /* no array bounds checking; no STMT opcode */
#define AMX_FLAG_OLDFILE 0x20 /* Old AMX Mod plugin */
/* AMX_FLAG_OLDFILE 0x20 Old AMX Mod plugin */
#define AMX_FLAG_NTVREG 0x1000 /* all native functions are registered */
#define AMX_FLAG_JITC 0x2000 /* abstract machine is JIT compiled */
#define AMX_FLAG_BROWSE 0x4000 /* busy browsing */
@ -312,10 +312,6 @@ enum {
#define FP_STRING 2
#define FP_ARRAY 4
#define FORWARD_ONLY_OLD 1
#define FORWARD_ONLY_NEW 2
#define FORWARD_ALL 3
#define SND_SPAWNING (1<<8) // we're spawing, used in some cases for ambients
#define SND_STOP (1<<5) // stop sound
#define SND_CHANGE_VOL (1<<6) // change sound vol

View File

@ -1086,14 +1086,6 @@ native set_addr_val(addr, val);
*/
native CreateMultiForward(const name[], stop_type, ...);
/**
* Creates a multi-forward plugin that can filter between old/new plugins.
* Old plugins are used by the AMX Mod backwards compatibility layer.
* Stop type must be one of the ET_ values in amxconst.inc
* Forward type must be one of the FORWARD_ values in amxconst.inc.
*/
native CreateMultiForwardEx(const name[], stop_type, forward_type, ...);
/**
* Creates a forward for one plugin.
* Results will be > 0 for success.