merged bcompat changed into trunk
removed amxmod compat files for now
This commit is contained in:
@ -33,6 +33,7 @@
|
||||
#include "amxmodx.h"
|
||||
#include "CLang.h"
|
||||
#include "format.h"
|
||||
#include "amxmod_compat.h"
|
||||
|
||||
#ifdef __linux__
|
||||
#define _snprintf snprintf
|
||||
@ -287,7 +288,23 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
||||
static char outbuf[4096];
|
||||
cell *addr = get_amxaddr(amx, params[parm++]);
|
||||
|
||||
len = atcprintf(outbuf, sizeof(outbuf)-1, addr, 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;
|
||||
}
|
||||
|
@ -89,6 +89,7 @@ void CModule::clear(bool clearFilename)
|
||||
|
||||
m_DestroyableIndexes.clear();
|
||||
m_Natives.clear();
|
||||
m_NewNatives.clear();
|
||||
}
|
||||
|
||||
bool CModule::attachMetamod(const char *mmfile, PLUG_LOADTIME now)
|
||||
|
@ -117,6 +117,7 @@ public:
|
||||
void CallPluginsUnloading();
|
||||
|
||||
CVector<AMX_NATIVE_INFO*> m_Natives;
|
||||
CVector<AMX_NATIVE_INFO*> m_NewNatives; // Natives for new (AMXX, not AMX) plugins only
|
||||
CVector<size_t> m_DestroyableIndexes;
|
||||
};
|
||||
|
||||
|
@ -447,7 +447,8 @@ 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)
|
||||
if (pl->file->GetStatus() != CAmxxReader::Err_None ||
|
||||
pl->file->IsOldFile())
|
||||
{
|
||||
delete pl->file;
|
||||
delete pl;
|
||||
|
@ -19,7 +19,8 @@ OBJECTS = meta_api.cpp CFile.cpp CVault.cpp vault.cpp float.cpp file.cpp modules
|
||||
srvcmd.cpp strptime.cpp amxcore.cpp amxtime.cpp power.cpp amxxlog.cpp fakemeta.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 \
|
||||
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
|
||||
|
||||
LINK = -lgcc -static-libgcc
|
||||
|
||||
|
136
amxmodx/amxmod_compat.cpp
Normal file
136
amxmodx/amxmod_compat.cpp
Normal file
@ -0,0 +1,136 @@
|
||||
#include "amxmodx.h"
|
||||
#include "amxmod_compat.h"
|
||||
#include "format.h"
|
||||
|
||||
struct translate_result
|
||||
{
|
||||
int suki;
|
||||
int dest;
|
||||
int lang;
|
||||
};
|
||||
|
||||
CVector<translate_result *> g_tr_results;
|
||||
CStack<size_t> g_old_ids;
|
||||
|
||||
bool GetTranslation(int id, int &key, int &dest, int &lang)
|
||||
{
|
||||
if (id < 0 || (unsigned int)id > g_tr_results.size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
translate_result *pRes = g_tr_results[id];
|
||||
|
||||
key = pRes->suki;
|
||||
dest = pRes->dest;
|
||||
lang = pRes->lang;
|
||||
|
||||
g_old_ids.push((size_t)id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ClearTransCache()
|
||||
{
|
||||
for (size_t i=0; i<g_tr_results.size(); i++)
|
||||
{
|
||||
delete g_tr_results[i];
|
||||
}
|
||||
g_tr_results.clear();
|
||||
|
||||
while (!g_old_ids.empty())
|
||||
{
|
||||
g_old_ids.pop();
|
||||
}
|
||||
}
|
||||
|
||||
bool translate_bcompat(AMX *amx, cell *source, const char **_key, const char **_def)
|
||||
{
|
||||
unsigned int trans = static_cast<unsigned int>(*source);
|
||||
trans &= ~BCOMPAT_TRANSLATE_BITS;
|
||||
int key, _dest, lang;
|
||||
if (!GetTranslation(trans, key, _dest, lang))
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
//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);
|
||||
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);
|
||||
|
||||
translate_result *pRes;
|
||||
size_t id;
|
||||
if (g_old_ids.empty())
|
||||
{
|
||||
pRes = new translate_result;
|
||||
id = g_tr_results.size();
|
||||
g_tr_results.push_back(pRes);
|
||||
} else {
|
||||
if (g_tr_results.size() >= BCOMPAT_TRANSLATE_MAX)
|
||||
{
|
||||
LogError(amx, AMX_ERR_NATIVE, "Exceeded bcompat translation limit of %d!", BCOMPAT_TRANSLATE_MAX);
|
||||
return 0;
|
||||
}
|
||||
id = g_old_ids.front();
|
||||
g_old_ids.pop();
|
||||
pRes = g_tr_results[id];
|
||||
}
|
||||
|
||||
pRes->suki = g_langMngr.GetKeyEntry(key);
|
||||
|
||||
//Some AMX Mod plugins do not register everything they need. Prevent a crash.
|
||||
if (pRes->suki == -1)
|
||||
{
|
||||
pRes->suki = g_langMngr.AddKeyEntry(key);
|
||||
}
|
||||
|
||||
pRes->dest = params[2];
|
||||
pRes->lang = params[3];
|
||||
|
||||
return (cell)((unsigned int)BCOMPAT_TRANSLATE_BITS | (unsigned int)id);
|
||||
}
|
||||
|
||||
AMX_NATIVE_INFO g_BcompatNatives[] =
|
||||
{
|
||||
{"translate", amx_translate},
|
||||
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
12
amxmodx/amxmod_compat.h
Normal file
12
amxmodx/amxmod_compat.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef _INCLUDE_AMXMOD_CORE_COMPAT_H
|
||||
#define _INCLUDE_AMXMOD_CORE_COMPAT_H
|
||||
|
||||
#define BCOMPAT_TRANSLATE_BITS 0xFFFFF400
|
||||
#define BCOMPAT_TRANSLATE_MAX 0x400
|
||||
|
||||
bool GetTranslation(int id, int &key, int &dest, int &lang);
|
||||
void ClearTransCache();
|
||||
|
||||
extern AMX_NATIVE_INFO g_BcompatNatives[];
|
||||
|
||||
#endif //_INCLUDE_AMXMOD_CORE_COMPAT_H
|
@ -608,6 +608,7 @@ const char *Debugger::_GetFilename()
|
||||
void Debugger::FmtGenericMsg(AMX *amx, int error, char buffer[], size_t maxLength)
|
||||
{
|
||||
const char *filename = "";
|
||||
char native[sNAMEMAX+1];
|
||||
|
||||
CList<CScript,AMX*>::iterator a = g_loadedscripts.find(amx);
|
||||
if (a)
|
||||
@ -625,6 +626,9 @@ void Debugger::FmtGenericMsg(AMX *amx, int error, char buffer[], size_t maxLengt
|
||||
if (error == AMX_ERR_EXIT)
|
||||
{
|
||||
_snprintf(buffer, maxLength, "Run time error %d (plugin \"%s\") - %s", error, filename, GenericError(AMX_ERR_EXIT));
|
||||
} else if (error == AMX_ERR_NATIVE) {
|
||||
amx_GetNative(amx, (int)amx->usertags[UT_NATIVE], native);
|
||||
_snprintf(buffer, maxLength, "Run time error %d (plugin \"%s\") (native \"%s\") - debug not enabled!", error, filename, native);
|
||||
} else {
|
||||
_snprintf(buffer, maxLength, "Run time error %d (plugin \"%s\") - debug not enabled!", error, filename);
|
||||
}
|
||||
|
@ -424,6 +424,54 @@ static cell AMX_NATIVE_CALL n_floatatan2(AMX *amx, cell *params)
|
||||
return amx_ftoc(fC);
|
||||
}
|
||||
|
||||
#if defined __BORLANDC__ || defined __WATCOMC__
|
||||
#pragma argsused
|
||||
#endif
|
||||
/* Added by DS */
|
||||
static cell AMX_NATIVE_CALL n_floatsinh(AMX *amx, cell *params)
|
||||
{
|
||||
/*
|
||||
* params[1] = angle
|
||||
* params[2] = radix
|
||||
*/
|
||||
REAL fA = amx_ctof(params[1]);
|
||||
fA = ToRadians(fA, params[2]);
|
||||
fA = sinh(fA);
|
||||
return amx_ftoc(fA);
|
||||
}
|
||||
|
||||
#if defined __BORLANDC__ || defined __WATCOMC__
|
||||
#pragma argsused
|
||||
#endif
|
||||
/* Added by DS */
|
||||
static cell AMX_NATIVE_CALL n_floatcosh(AMX *amx, cell *params)
|
||||
{
|
||||
/*
|
||||
* params[1] = angle
|
||||
* params[2] = radix
|
||||
*/
|
||||
REAL fA = amx_ctof(params[1]);
|
||||
fA = ToRadians(fA, params[2]);
|
||||
fA = cosh(fA);
|
||||
return amx_ftoc(fA);
|
||||
}
|
||||
|
||||
#if defined __BORLANDC__ || defined __WATCOMC__
|
||||
#pragma argsused
|
||||
#endif
|
||||
/* Added by DS */
|
||||
static cell AMX_NATIVE_CALL n_floattanh(AMX *amx, cell *params)
|
||||
{
|
||||
/*
|
||||
* params[1] = angle
|
||||
* params[2] = radix
|
||||
*/
|
||||
REAL fA = amx_ctof(params[1]);
|
||||
fA = ToRadians(fA, params[2]);
|
||||
fA = tanh(fA);
|
||||
return amx_ftoc(fA);
|
||||
}
|
||||
|
||||
#if defined __BORLANDC__ || defined __WATCOMC__
|
||||
#pragma argsused
|
||||
#endif
|
||||
@ -456,6 +504,9 @@ AMX_NATIVE_INFO float_Natives[] = {
|
||||
{ "floatacos", n_floatacos },
|
||||
{ "floatatan", n_floatatan },
|
||||
{ "floatatan2", n_floatatan2 },
|
||||
{ "floatsinh", n_floatsinh },
|
||||
{ "floatcosh", n_floatcosh },
|
||||
{ "floattanh", n_floattanh },
|
||||
{ NULL, NULL } /* terminator */
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "amxmodx.h"
|
||||
#include "format.h"
|
||||
#include "amxmod_compat.h"
|
||||
|
||||
//Adapted from Quake3's vsprintf
|
||||
// thanks to cybermind for linking me to this :)
|
||||
@ -422,6 +423,24 @@ reswitch:
|
||||
break;
|
||||
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;
|
||||
|
@ -5,4 +5,7 @@
|
||||
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
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "optimizer.h"
|
||||
#include "libraries.h"
|
||||
#include "messages.h"
|
||||
#include "amxmod_compat.h"
|
||||
|
||||
plugin_info_t Plugin_info =
|
||||
{
|
||||
@ -357,6 +358,14 @@ int C_Spawn(edict_t *pent)
|
||||
get_localinfo("amxx_configsdir", "addons/amxmodx/configs");
|
||||
get_localinfo("amxx_customdir", "addons/amxmodx/custom");
|
||||
|
||||
// make sure bcompat localinfos are set
|
||||
get_localinfo("amx_basedir", "addons/amxmodx");
|
||||
get_localinfo("amx_configdir", "addons/amxmodx/configs");
|
||||
get_localinfo("amx_langdir", "addons/amxmodx/data/amxmod-lang");
|
||||
get_localinfo("amx_modulesdir", "addons/amxmodx/modules");
|
||||
get_localinfo("amx_pluginsdir", "addons/amxmodx/plugins");
|
||||
get_localinfo("amx_logdir", "addons/amxmodx/logs");
|
||||
|
||||
char map_pluginsfile_path[256];
|
||||
|
||||
// ###### Load modules
|
||||
@ -619,6 +628,7 @@ void C_ServerDeactivate_Post()
|
||||
g_xvars.clear();
|
||||
g_plugins.clear();
|
||||
ClearPluginLibraries();
|
||||
ClearTransCache();
|
||||
modules_callPluginsUnloaded();
|
||||
|
||||
ClearMessages();
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include "binlog.h"
|
||||
#include "libraries.h"
|
||||
#include "messages.h"
|
||||
#include "amxmod_compat.h"
|
||||
|
||||
CList<CModule, const char*> g_modules;
|
||||
CList<CScript, AMX*> g_loadedscripts;
|
||||
@ -165,6 +166,7 @@ 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);
|
||||
@ -218,6 +220,8 @@ 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);
|
||||
}
|
||||
@ -369,6 +373,17 @@ 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);
|
||||
@ -542,6 +557,12 @@ int set_amxnatives(AMX* amx, char error[128])
|
||||
{
|
||||
amx_Register(amx, cm->m_Natives[i], -1);
|
||||
}
|
||||
|
||||
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, string_Natives, -1);
|
||||
@ -557,6 +578,11 @@ int set_amxnatives(AMX* amx, char error[128])
|
||||
amx_Register(amx, msg_Natives, -1);
|
||||
amx_Register(amx, vector_Natives, -1);
|
||||
amx_Register(amx, g_SortNatives, -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;
|
||||
@ -1178,6 +1204,18 @@ int MNF_AddNatives(AMX_NATIVE_INFO* natives)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int MNF_AddNewNatives(AMX_NATIVE_INFO *natives)
|
||||
{
|
||||
CList<CModule, const char *>::iterator a = g_modules.begin();
|
||||
|
||||
if (!g_CurrentlyCalledModule || g_ModuleCallReason != ModuleCall_Attach)
|
||||
return FALSE; // may only be called from attach
|
||||
|
||||
g_CurrentlyCalledModule->m_NewNatives.push_back(natives);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
const char *MNF_GetModname(void)
|
||||
{
|
||||
// :TODO: Do we have to do this??
|
||||
@ -1870,6 +1908,7 @@ void Module_CacheFunctions()
|
||||
|
||||
// Natives / Forwards
|
||||
REGISTER_FUNC("AddNatives", MNF_AddNatives)
|
||||
REGISTER_FUNC("AddNewNatives", MNF_AddNewNatives)
|
||||
REGISTER_FUNC("RaiseAmxError", amx_RaiseError)
|
||||
REGISTER_FUNC("RegisterForward", registerForward)
|
||||
REGISTER_FUNC("RegisterSPForward", registerSPForward)
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "amxmodx.h"
|
||||
#include "format.h"
|
||||
#include "binlog.h"
|
||||
#include "amxmod_compat.h"
|
||||
|
||||
const char* stristr(const char* str, const char* substr)
|
||||
{
|
||||
@ -115,8 +116,21 @@ extern "C" size_t get_amxstring_r(AMX *amx, cell amx_addr, char *destination, in
|
||||
register char *dest = destination;
|
||||
char *start = dest;
|
||||
|
||||
while (maxlen-- && *source)
|
||||
*dest++=(char)(*source++);
|
||||
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';
|
||||
|
||||
@ -132,16 +146,29 @@ extern "C" size_t get_amxstring_r(AMX *amx, cell amx_addr, char *destination, in
|
||||
return dest - start;
|
||||
}
|
||||
|
||||
char* get_amxstring(AMX *amx, cell amx_addr, int id, int& len)
|
||||
char *get_amxstring(AMX *amx, cell amx_addr, int id, int& len)
|
||||
{
|
||||
static char buffor[4][3072];
|
||||
register cell* source = (cell *)(amx->base + (int)(((AMX_HEADER *)amx->base)->dat + amx_addr));
|
||||
register char* dest = buffor[id];
|
||||
char* start = dest;
|
||||
|
||||
while ((*dest++=(char)(*source++)));
|
||||
|
||||
len = --dest - start;
|
||||
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 ( (*dest++ = (*def++)) );
|
||||
len = --dest - start;
|
||||
} else {
|
||||
normal_string:
|
||||
while ((*dest++=(char)(*source++)));
|
||||
|
||||
len = --dest - start;
|
||||
}
|
||||
|
||||
#if defined BINLOG_ENABLED
|
||||
if (g_binlog_level & 2)
|
||||
|
Reference in New Issue
Block a user