initial import of the bcompat plugins (userland layer)

This commit is contained in:
David Anderson
2006-09-08 14:49:54 +00:00
parent 38e7b9ff58
commit 8df33abd70
13 changed files with 1995 additions and 0 deletions

View File

@ -0,0 +1,86 @@
/* VexdUM backwards compatibility
*
* by the AMX Mod X Development Team
*
* This file is provided as is (no warranties).
*/
#if !defined _fakemeta_included
#include <fakemeta>
#endif
#if !defined _engine_included
#include <engine>
#endif
#if defined _vexd_bcompat_included
#endinput
#endif
#define _vexd_bcompat_included
#include <VexdUM_const>
native radius_damage(inflictor, Float:dmg, Float:orig[3], Float:rad, bit = DMG_BULLET, wpnName[]="", hs = 0);
native set_user_model(id, const Model[]="");
native DispatchKeyValue(ent, szKey[], szValue[]);
// Trace a line from Start(X, Y, Z) to End(X, Y, Z), will return the point hit in vReturn[3]
// Will return an entindex if an entity is hit.
native trace_line(ent, Float:vStart[3], Float:vEnd[3], Float:vReturn[3]);
native traceline_get_int(iVar);
native traceline_set_int(iVar, iVal);
native Float:traceline_get_float(iVar);
native traceline_set_float(iVar, Float:fVal);
native traceline_get_vector(iVar, Float:vVal[3]);
native traceline_set_vector(iVar, Float:vVal[3]);
native traceline_get_edict(iVar);
native traceline_set_edict(iVar, iEnt);
/* Wrapper around pfn_touch */
forward entity_touch(entity1, entity2);
/* Wrapper around pfn_think */
forward entity_think(entity);
/* Wrapper around pfn_spawn */
forward entity_spawn(entity);
/* Wrapper around client_PreThink */
forward client_prethink(id);
/* Wrapper around client_PostThink */
forward client_postthink(id);
//From AMX Mod:
// Called when an Emitting Sound is played Server-Side
forward emitsound(entity, const sample[]);
//From AMX Mod:
// Called when an Emitting Ambient Sound is played Server-Side
forward emitambientsound(entity, const sample[]);
//From AMX Mod:
// Called when a model spawns
forward set_model(entity, const model[]);
//From AMX Mod:
// Called whatever an entity looks at
forward traceline(entity);
//:TODO: ?
// Called when a monster is hurt by VexdUM damage natives
// forward monster_hurt(monster, attacker, damage);
//From AMX Mod:
// Called when a keyvalue is set on a player
forward setclientkeyvalue(id, key[], value[]);
//From AMX Mod:
// Called when an entity gets a keyvalue set on it from the engine.
// Use copy_keyvalue to get the keyvalue information
forward keyvalue(entity);
#include <VexdUM_stock>

View File

@ -0,0 +1,30 @@
#if defined _vexdum_const_included
#endinput
#endif
#define _vexdum_const_included
// TraceLine Integer
enum {
TR_INT_fAllSolid, // if true, plane is not valid
TR_INT_fStartSolid, // if true, the initial point was in a solid area
TR_INT_fInOpen,
TR_INT_fInWater,
TR_INT_iHitgroup, // 0 == generic, non zero is specific body part
};
// TraceLine Float
enum {
TR_FL_flFraction, // time completed, 1.0 = didn't hit anything
TR_FL_flPlaneDist,
};
// TraceLine Vector
enum {
TR_VEC_vecEndPos, // final position
TR_VEC_vecPlaneNormal, // surface normal at impact
};
// TraceLine Edict
enum {
TR_ENT_pHit, // entity the surface is on
};

View File

@ -0,0 +1,132 @@
/* VexdUM stocks backwards compatibility
*
* by the AMX Mod X Development Team
*
* This file is provided as is (no warranties).
*/
#if defined _vexd_bcompat_stocks_included
#endinput
#endif
#define _vexd_bcompat_stocks_included
#if !defined _engine_included
#include <engine>
#endif
stock is_entity(ent)
{
return pev_valid(ent);
}
stock get_offset_int(ent, offset, linos = 5)
{
return get_pdata_int(ent, offset, linos);
}
stock set_offset_int(ent, offset, value, linos = 5)
{
return set_pdata_int(ent, offset, value, linos);
}
stock in_view_cone(ent, Float:Orig[3])
{
return is_in_viewcone(ent, Orig);
}
stock get_maxentities()
{
return global_get(glb_maxEntities);
}
stock can_see(ent1, ent2)
{
if (is_entity(ent1) && is_entity(ent2))
{
new flags = pev(ent1, pev_flags);
if (flags & EF_NODRAW || flags & FL_NOTARGET)
{
return 0;
}
new Float:lookerOrig[3];
new Float:targetOrig[3];
new Float:temp[3];
pev(ent1, pev_origin, lookerOrig);
pev(ent1, pev_view_ofs, temp);
lookerOrig[0] += temp[0];
lookerOrig[1] += temp[1];
lookerOrig[2] += temp[2];
pev(ent2, pev_origin, targetOrig);
pev(ent2, pev_view_ofs, temp);
targetOrig[0] += temp[0];
targetOrig[1] += temp[1];
targetOrig[2] += temp[2];
engfunc(EngFunc_TraceLine, lookerOrig, targetOrig, 0, ent1, 0);
if (get_tr2(0, TraceResult:TR_InOpen) && get_tr2(0, TraceResult:TR_InWater))
{
return 0;
} else {
new Float:flFraction;
get_tr2(0, TraceResult:TR_Fraction, flFraction);
if (flFraction == 1.0 || (get_tr2(0, TraceResult:TR_Hit) == ent2))
{
return 1;
}
}
}
return 0;
}
//From AMX Mod:
// Find an entity in the world, will return -1 if nothing is found
// type = 0: "classname"
// type = 1: "globalname"
// type = 2: "model"
// type = 3: "target"
// type = 4: "targetname"
// type = 5: "netname"
// type = 6: "message"
// type = 7: "noise"
// type = 8: "noise1"
// type = 9: "noise2"
// type = 10: "noise3"
// type = 11: "viewmodel"
// type = 12: "weaponmodel"
stock find_entity(ent, szValue[], type=0)
{
static _g_FindEntTypes[13][] =
{
"classname",
"globalname",
"model",
"target",
"targetname",
"netname",
"messages",
"noise",
"noise1",
"noise2",
"noise3",
"viewmodel",
"weaponmodel"
};
if (type < 0 || type >= 13)
{
type = 0;
}
return engfunc(EngFunc_FindEntityByString, ent, _g_FindEntTypes[type], szValue);
}
//From AMX Mod:
// Find an entity within a given origin and radius
stock find_entity_sphere(ent, Float:Orig[3], Float:Rad)
{
return engfunc(EngFunc_FindEntityInSphere, ent, Orig, Rad);
}

View File

@ -0,0 +1,104 @@
/* Vexd Utility backwards compatibility
*
* by the AMX Mod X Development Team
*
* This file is provided as is (no warranties).
*/
#if defined _Vexd_Utilities_included
#endinput
#endif
#define _Vexd_Utilities_included
#include <engine>
stock Entvars_Get_Int(iIndex, iVariable)
return entity_get_int(iIndex, iVariable)
stock Entvars_Set_Int(iIndex, iVariable, iNewValue)
return entity_set_int(iIndex, iVariable, iNewValue)
stock Float:Entvars_Get_Float(iIndex, iVariable)
return entity_get_float(iIndex, iVariable)
stock Entvars_Set_Float(iIndex, iVariable, Float:fNewValue)
return entity_set_float(iIndex, iVariable, fNewValue)
stock Entvars_Get_Vector(iIndex, iVariable, Float:vRetVector[3])
return entity_get_vector(iIndex, iVariable, vRetVector)
stock Entvars_Set_Vector(iIndex, iVariable, Float:vNewVector[3])
return entity_set_vector(iIndex, iVariable, vNewVector)
stock Entvars_Get_Edict(iIndex, iVariable)
return entity_get_edict(iIndex, iVariable)
stock Entvars_Set_Edict(iIndex, iVariable, iNewIndex)
return entity_set_edict(iIndex, iVariable, iNewIndex)
stock Entvars_Get_String(iIndex, iVariable, szReturnValue[], iReturnLen)
return entity_get_string(iIndex, iVariable, szReturnValue, iReturnLen)
stock Entvars_Set_String(iIndex, iVariable, szNewValue[])
return entity_set_string(iIndex, iVariable, szNewValue)
stock Entvars_Get_Byte(iIndex, iVariable)
return entity_get_byte(iIndex, iVariable)
stock Entvars_Set_Byte(iIndex, iVariable, iNewValue)
return entity_set_byte(iIndex, iVariable, iNewValue)
stock CreateEntity(szClassname[])
return create_entity(szClassname)
stock ENT_SetModel(iIndex, szModel[])
return entity_set_model(iIndex, szModel)
stock ENT_SetOrigin(iIndex, Float:fNewOrigin[3])
return entity_set_origin(iIndex, fNewOrigin)
stock FindEntity(iIndex, szValue[])
return find_ent_by_class(iIndex, szValue)
stock RemoveEntity(iIndex)
return remove_entity(iIndex)
stock TraceLn(iIgnoreEnt, Float:fStart[3], Float:fEnd[3], Float:vReturn[3])
return trace_line(iIgnoreEnt, fStart, fEnd, vReturn)
stock TraceNormal(iIgnoreEnt, Float:fStart[3], Float:fEnd[3], Float:vReturn[3])
return trace_normal(iIgnoreEnt, fStart, fEnd, vReturn)
stock VecToAngles(Float:fVector[3], Float:vReturn[3])
return vector_to_angle(fVector, vReturn)
stock Float:VecLength(Float:vVector[3])
return vector_length(vVector)
stock Float:VecDist(Float:vVector[3], Float:vVector2[3])
return vector_distance(vVector, vVector2)
stock MessageBlock(iMessage, iMessageFlags)
return set_msg_block(iMessage, iMessageFlags)
stock GetMessageBlock(iMessage)
return get_msg_block(iMessage)
stock Float:HLTime()
return halflife_time()
stock FakeTouch(iToucher, iTouched)
return fake_touch(iToucher, iTouched)
stock AttachView(iIndex, iTargetIndex)
return attach_view(iIndex, iTargetIndex)
stock SetView(iIndex, ViewType)
return set_view(iIndex, ViewType)
stock SetSpeak(iIndex, iSpeakFlags)
return set_speak(iIndex, iSpeakFlags)
forward vexd_pfntouch(pToucher, pTouched)
forward ServerFrame()

View File

@ -0,0 +1,127 @@
/* AMX Mod X Backwards Compatibility
*
* by the AMX Mod X Development Team
*
* This file is provided as is (no warranties).
*/
#if defined _amxmod_included
#endinput
#endif
#define _amxmod_included
#if !defined AMXMOD_BCOMPAT
#define AMXMOD_BCOMPAT
#endif
#include <amxmodx>
#include <cstrike>
#include <engine>
#include <fun>
#include <maths>
stock AMX_VERSION[] = "1.76-BC"
/* Core will identify us as an "old plugin" this way. */
public __b_old_plugin = 1;
public __b_ident_vers()
{
return __b_old_plugin;
}
stock user_spawn(index)
return spawn(index);
stock get_logfile( name[], len )
return get_time("admin%m%d.log",name,len);
stock get_user_money(index)
return cs_get_user_money(index);
stock set_user_money(index,money,flash=1)
return cs_set_user_money(index,money,flash);
stock numtostr(num,string[],len)
return num_to_str(num,string,len);
stock strtonum(const string[])
return str_to_num(string);
stock build_path(path[], len, {Float,_}:... ) {
format_args(path, len, 2)
new pathlen = strlen(path)
new basedir[32]
if(containi(path, "$basedir") != -1) {
get_localinfo("amxx_basedir", basedir, 31)
if(!basedir[0]) copy(basedir, 31, "addons/amxmodx")
if((pathlen+strlen(basedir)-strlen("$basedir")) < len) {
replace(path, len, "$basedir", basedir)
}
}
new dir[64], subdir[63]
if(containi(path, "$configdir") != -1) {
get_localinfo("amxx_configsdir", dir, 63)
if(!dir[0]) format(dir, 63, "%s/configs", basedir)
if((pathlen+strlen(basedir)-strlen("$configdir")) < len) {
replace(path, len, "$configdir", dir)
}
dir[0] = '^0'
}
if(containi(path, "$langdir") != -1) {
get_localinfo("amxx_datadir", subdir, 63)
if(!subdir[0]) format(subdir, 63, "%s/data", basedir)
format(dir, 63, "%s/amxmod-lang", subdir)
if((pathlen+strlen(basedir)-strlen("$langdir")) < len) {
replace(path, len, "$langdir", dir)
}
dir[0] = '^0'
}
if(containi(path, "$modulesdir") != -1) {
get_localinfo("amxx_modules", dir, 63)
if(!dir[0]) format(dir, 63, "%s/modules", basedir)
if((pathlen+strlen(basedir)-strlen("$modulesdir")) < len) {
replace(path, len, "$modulesdir", dir)
}
dir[0] = '^0'
}
if(containi(path, "$pluginsdir") != -1) {
get_localinfo("amx_pluginsdir", dir, 63)
if(!dir[0]) format(dir, 63, "%s/plugins", basedir)
if((pathlen+strlen(basedir)-strlen("$pluginsdir")) < len) {
replace(path, len, "$pluginsdir", dir)
}
dir[0] = '^0'
}
if(containi(path, "$logdir") != -1) {
get_localinfo("amx_logs", dir, 63)
if(!dir[0]) format(dir, 63, "%s/logs", basedir)
if((pathlen+strlen(basedir)-strlen("$logdir")) < len) {
replace(path, len, "$logdir", dir)
}
}
return 1
}
stock is_user_authorized(id)
{
static auth[32];
get_user_authid(id, auth, 31);
if (auth[0] == 0 || equali(auth, "STEAM_ID_PENDING"))
{
return 0;
}
return 1;
}
/* Vector AMX Mod compatibility */
#define ANGLEVECTORS_FORWARD 1
#define ANGLEVECTORS_RIGHT 2
#define ANGLEVECTORS_UP 3
stock angle_to_vector(Float:vector[3], FRU, Float:ret[3])
{
return angle_vector(vector, FRU, ret)
}

View File

@ -0,0 +1,85 @@
/* AMX Mod math functions backwards compatibility
*
* by the AMX Mod X Development Team
*
* This file is provided as is (no warranties).
*/
#if defined _maths_bcompat_included
#endinput
#endif
#define _maths_bcompat_included
#if !defined _float_included
#include <float>
#endif
stock Float:fabs(Float:value)
{
return floatabs(value)
}
stock Float:asin(Float:value)
{
return floatasin(value, radian)
}
stock Float:sin(Float:value)
{
return floatsin(value, radian)
}
stock Float:sinh(Float:value)
{
return floatsinh(value, radian)
}
stock Float:acos(Float:value)
{
return floatacos(value, radian)
}
stock Float:cos(Float:value)
{
return floatcos(value, radian)
}
stock Float:cosh(Float:value)
{
retuen floatcosh(value, radian)
}
stock Float:atan(Float:value)
{
return floatatan(value, radian)
}
stock Float:atan2(Float:value1, Float:value2)
{
return floatatan2(value1, value2, radian)
}
stock Float:tan(Float:value)
{
return floattan(value, radian)
}
stock Float:tanh(Float:value)
{
return floattanh(value, radian)
}
stock Float:fsqroot(Float:value)
{
return floatsqroot(value)
}
stock Float:fpower(Float:value, Float:exponent)
{
return floatpower(value, exponent)
}
stock Float:flog(Float:value, Float:base=10.0)
{
return floatlog(value, base)
}

View File

@ -0,0 +1,20 @@
#if defined _mysql_included
#endinput
#endif
#define _mysql_included
#include <sqlx>
native mysql_connect(host[], user[], pass[], dbname[], error[], maxlength);
native mysql_query(sql, query[], {Float,_}:... );
native mysql_error(sql, dest[], maxlength);
native mysql_close(sql);
native mysql_nextrow(sql);
native mysql_getfield(sql, fieldnum, {Float,_}:... );
native mysql_getresult(sql, field[], {Float,_}:... );
native mysql_affected_rows(sql);
native mysql_num_fields(sql);
native mysql_num_rows(sql);
native mysql_field_name(sql, field, name[], length);
native mysql_insert_id(sql);

View File

@ -0,0 +1,86 @@
/* AMX Mod X Backwards Compatibility
*
* by the AMX Mod X Development Team
*
* This file is provided as is (no warranties).
*/
#if defined _amxmod_translator_included
#endinput
#endif
#define _amxmod_translator_included
#define _translator_included
#include <amxmodx>
#include <amxmod>
#include <amxmisc>
//From AMX Mod. This is implemented in Core due to the nature of the
// translation engine and what AMX Mod did.
/* Translation backend, used by _T (since natives can't return arrays). */
native translate(const string[], destid=-1, forcelang=-1);
stock _T(const string[], destid=-1, forcelang=-1)
{
new TranslationResult[2] = {0, 0}
TranslationResult[0] = translate(string, destid, forcelang)
return TranslationResult
}
stock load_translations(const file[])
{
static dir[255], path[255];
get_datadir(dir, 254);
format(path, 254, "%s/amxmod-lang/%s.txt", dir, file);
new fp
if (!(fp=fopen(path, "r")))
{
abort(AMX_ERR_NATIVE, "Could not find file: %s", path);
return 0;
}
static buffer[1024];
new lang[3];
new TransKey:bad_key = TransKey:-1;
new TransKey:cur_key = bad_key;
new len;
while (!feof(fp))
{
buffer[0] = 0;
fgets(fp, buffer, 1023);
len = strlen(buffer);
if (len == 0)
{
continue;
}
if (isspace(buffer[len-1]))
{
buffer[--len] = 0;
}
if (buffer[0] == '"')
{
remove_quotes(buffer);
cur_key = CreateLangKey(buffer);
AddTranslation("en", cur_key, buffer);
continue;
}
if (isspace(buffer[0]))
{
continue;
}
if ((cur_key != bad_key) && (buffer[2] == ':' && buffer[3] == '"'))
{
lang[0] = buffer[0];
lang[1] = buffer[1];
lang[2] = 0;
remove_quotes(buffer[3]);
AddTranslation(lang, cur_key, buffer[3]);
}
}
fclose(fp);
return 1;
}

View File

@ -0,0 +1,95 @@
/* Xtrafun backwards compatibility
*
* by the AMX Mod X Development Team
* These natives were originally made by SpaceDude, EJ, and JustinHoMi.
*
* This file is provided as is (no warranties).
*/
#if !defined _xtrafun_included
#define _xtrafun_included
#if !defined _engine_included
#include <engine.inc>
#endif
/* Gets the velocity of an entity */
stock get_entity_velocity(index, velocity[3]) {
new Float:vector[3]
entity_get_vector(index, EV_VEC_velocity, vector)
FVecIVec(vector, velocity)
}
/* Sets the velocity of an entity */
stock set_entity_velocity(index, velocity[3]) {
new Float:vector[3]
IVecFVec(velocity, vector)
entity_set_vector(index, EV_VEC_velocity, vector)
}
/* Gets the origin of an entity */
stock get_entity_origin(index, origin[3]) {
new Float:vector[3]
entity_get_vector(index, EV_VEC_origin, vector)
FVecIVec(vector, origin)
}
/* Sets the origin of an entity */
stock set_entity_origin(index, origin[3]) {
new Float:vector[3]
IVecFVec(origin, vector)
entity_set_vector(index, EV_VEC_origin, vector)
}
/* Get the index of the grenade belonging to index.
* Model of grenade is returned in model[].
* Specify the grenadeindex to start searching from,
* or leave it at 0 to search from the start.
* Returns grenade index.
* Paths + models of grenades in Counter-Strike:
* HEGRENADE = "models/w_hegrenade.mdl"
* FLASHBANG = "models/w_flashbang.mdl"
* SMOKEGRENADE = "models/w_smokegrenade.mdl" */
stock get_grenade_index(index, model[], len, grenadeindex = 0) {
new entfind = grenadeindex
new entowner = index
for (;;) {
entfind = find_ent_by_class(entfind, "grenade")
if (entfind && is_valid_ent(entfind)) {
if (entity_get_edict(entFind, EV_ENT_owner) == entowner) {
entity_get_string(entfind, EV_SZ_model, model)
return entfind
}
}
else {
// Eventually comes here if loop fails to find a grenade with specified owner.
return 0;
}
}
}
/* Find the number of entities in the game */
stock current_num_ents() {
return entity_count();
}
enum {
classname = 0,
target,
targetname
}
/* Find an entity ID from start_from_ent id (use 0 to start from
* the beginning, category is either "classname", "target" or
* "targetname", value is the name you are searching for */
stock find_entity(start_from_ent, category, value[]) {
switch (category) {
case target: return find_ent_by_target(start_from_ent, value)
case targetname: return find_ent_by_tname(start_from_ent, value)
}
return find_ent_by_class(start_from_ent, value)
}
#endif // _xtrafun_included