🔥 Remove compatibility stuff from the core

This commit is contained in:
xPaw 2014-06-05 23:00:47 +03:00
parent e3e3d8a255
commit 2696f0af0e
22 changed files with 17 additions and 853 deletions

View File

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

View File

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

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 \ 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 \ 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 \ 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 trie_natives.cpp CDataPack.cpp datapacks.cpp
############################################## ##############################################

View File

@ -322,7 +322,7 @@ enum {
#define AMX_FLAG_COMPACT 0x04 /* compact encoding */ #define AMX_FLAG_COMPACT 0x04 /* compact encoding */
#define AMX_FLAG_BYTEOPC 0x08 /* opcode is a byte (not a cell) */ #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_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_PRENIT 0x100 /* pre-initialized, do not check natives */
#define AMX_FLAG_NTVREG 0x1000 /* all native functions are registered */ #define AMX_FLAG_NTVREG 0x1000 /* all native functions are registered */
#define AMX_FLAG_JITC 0x2000 /* abstract machine is JIT compiled */ #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

@ -1859,18 +1859,6 @@ static cell AMX_NATIVE_CALL server_cmd(AMX *amx, cell *params) /* 1 param */
g_langMngr.SetDefLang(LANG_SERVER); g_langMngr.SetDefLang(LANG_SERVER);
char* cmd = format_amxstring(amx, params, 1, len); 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++] = '\n';
cmd[len] = 0; cmd[len] = 0;
@ -1929,19 +1917,6 @@ static cell AMX_NATIVE_CALL get_cvar_string(AMX *amx, cell *params) /* 3 param *
int ilen; int ilen;
char* sptemp = get_amxstring(amx, params[1], 0, 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); const char *value = CVAR_GET_STRING(sptemp);
return set_amxstring_utf8(amx, params[2], value, strlen(value), params[3] + 1); // + EOS return set_amxstring_utf8(amx, params[2], value, strlen(value), params[3] + 1); // + EOS
} }
@ -1964,19 +1939,6 @@ static cell AMX_NATIVE_CALL get_cvar_float(AMX *amx, cell *params) /* 1 param */
{ {
int ilen; 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)); REAL pFloat = CVAR_GET_FLOAT(get_amxstring(amx, params[1], 0, ilen));
return amx_ftoc(pFloat); return amx_ftoc(pFloat);
@ -2019,18 +1981,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 */ static cell AMX_NATIVE_CALL get_cvar_num(AMX *amx, cell *params) /* 1 param */
{ {
int ilen; 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)); return (int)CVAR_GET_FLOAT(get_amxstring(amx, params[1], 0, ilen));
} }
@ -2627,18 +2577,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 */ static cell AMX_NATIVE_CALL cvar_exists(AMX *amx, cell *params) /* 1 param */
{ {
int ilen; 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); return (CVAR_GET_POINTER(get_amxstring(amx, params[1], 0, ilen)) ? 1 : 0);
} }
@ -3176,19 +3114,6 @@ static cell AMX_NATIVE_CALL get_cvar_flags(AMX *amx, cell *params)
int ilen; int ilen;
char* sCvar = get_amxstring(amx, params[1], 0, 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); cvar_t* pCvar = CVAR_GET_POINTER(sCvar);
return pCvar ? pCvar->flags : 0; return pCvar ? pCvar->flags : 0;

View File

@ -1,7 +1,6 @@
#include "amxmodx.h" #include "amxmodx.h"
#include "format.h" #include "format.h"
#include "datastructs.h" #include "datastructs.h"
#include "amxmod_compat.h"
//Adapted from Quake3's vsprintf //Adapted from Quake3's vsprintf
// thanks to cybermind for linking me to this :) // thanks to cybermind for linking me to this :)
@ -634,24 +633,6 @@ reswitch:
} }
case 's': case 's':
CHECK_ARGS(0); 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); AddString(&buf_p, llen, get_amxaddr(amx, params[arg]), width, prec);
arg++; arg++;
break; 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); 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); 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 #endif //_INCLUDE_FORMATTING_H

View File

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

View File

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

View File

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

View File

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

View File

@ -33,7 +33,6 @@
#include "amxmodx.h" #include "amxmodx.h"
#include "format.h" #include "format.h"
#include "binlog.h" #include "binlog.h"
#include "amxmod_compat.h"
const char* stristr(const char* str, const char* substr) 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; register char *dest = destination;
char *start = dest; char *start = dest;
if ( (amx->flags & AMX_FLAG_OLDFILE) && while (maxlen-- && *source)
(*source & BCOMPAT_TRANSLATE_BITS) ) *dest++=(char)(*source++);
{
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'; *dest = '\0';
@ -536,40 +522,16 @@ static cell AMX_NATIVE_CALL copy(AMX *amx, cell *params) /* 4 param */
cell *src = get_amxaddr(amx, params[3]); cell *src = get_amxaddr(amx, params[3]);
int c = params[2]; int c = params[2];
if (amx->flags & AMX_FLAG_OLDFILE) cell *dest = get_amxaddr(amx, params[1]);
cell *start = dest;
while (c-- && *src)
{ {
if (*src & BCOMPAT_TRANSLATE_BITS) *dest++ = *src++;
{
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;
while (c-- && *src)
{
*dest++ = *src++;
}
*dest = '\0';
return (dest - start);
} }
*dest = '\0';
return (dest - start);
} }
static cell AMX_NATIVE_CALL copyc(AMX *amx, cell *params) /* 4 param */ 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; int param = 4;
size_t total = 0; size_t total = 0;
if (amx->flags & AMX_FLAG_OLDFILE) total = atcprintf(buf, maxlen, fmt, amx, params, &param);
{
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) if (copy)
{ {

View File

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

View File

@ -14,8 +14,7 @@ MM_ROOT = ../../../metamod/metamod
PROJECT = engine PROJECT = engine
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
############################################## ##############################################
### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ### ### 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 "engine.h"
#include "amxmod_compat.h"
struct usercmd_s *g_cmd; struct usercmd_s *g_cmd;
struct PlayerInfo plinfo[33]; struct PlayerInfo plinfo[33];

View File

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

View File

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

View File

@ -262,7 +262,7 @@ enum {
#define AMX_FLAG_COMPACT 0x04 /* compact encoding */ #define AMX_FLAG_COMPACT 0x04 /* compact encoding */
#define AMX_FLAG_BYTEOPC 0x08 /* opcode is a byte (not a cell) */ #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_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_NTVREG 0x1000 /* all native functions are registered */
#define AMX_FLAG_JITC 0x2000 /* abstract machine is JIT compiled */ #define AMX_FLAG_JITC 0x2000 /* abstract machine is JIT compiled */
#define AMX_FLAG_BROWSE 0x4000 /* busy browsing */ #define AMX_FLAG_BROWSE 0x4000 /* busy browsing */