2
0
mirror of https://github.com/rehlds/reapi.git synced 2024-12-28 15:45:31 +03:00

Added new natives: is_entity, rg_round_respawn, rg_send_bartime, rg_send_bartime2, rg_send_audio

Reworked: rg_create_entity, rg_find_ent_by_class
This commit is contained in:
s1lentq 2016-08-02 21:45:28 +07:00
parent 114f64a790
commit 6c7140380f
18 changed files with 431 additions and 128 deletions

View File

@ -47,7 +47,6 @@ void setupToolchain(NativeBinarySpec b) {
)
cfg.compilerOptions.args '/Ob2', '/Oi', '/GF', '/GR-', '/GS-'
cfg.singleDefines('_CRT_SECURE_NO_WARNINGS')
cfg.extraLibs 'ws2_32.lib'
} else if (cfg instanceof GccToolchainConfig) {
cfg.compilerOptions.pchConfig = new GccToolchainConfig.PrecompilerHeaderOptions(
enabled: true,
@ -108,7 +107,7 @@ model {
}
reapi_src(CppSourceSet) {
source {
srcDirs "src", "public", "include/cssdk/public"
srcDirs "src", "include/cssdk/public"
include "**/*.cpp"
exclude "precompiled.cpp"

View File

@ -41,6 +41,9 @@ enum members_tables_e
mt_armoury
};
// is like FNullEnt
#define is_nullent(%0) (is_entity(%0) == false)
#define MAX_REGION_RANGE 1024
#define BEGIN_FUNC_REGION(%0) (any:MAX_REGION_RANGE * hooks_tables_e:ht_%0)
@ -140,10 +143,18 @@ native any:GetHookChainReturn(any:...);
*/
native SetHookChainArg(number, AType:type, any:...);
/*
* Check if the entity is valid
*
* @return true/false
*
*/
native bool:is_entity(const entityIndex);
/*
* Check if the rehlds is available
*
* @return 1/0
* @return true/false
*
*/
native bool:is_rehlds();
@ -151,7 +162,7 @@ native bool:is_rehlds();
/*
* Check if the regamedll is available
*
* @return 1/0
* @return true/false
*
*/
native bool:is_regamedll();
@ -159,7 +170,7 @@ native bool:is_regamedll();
/*
* Check if the reunion is available
*
* @return 1/0
* @return true/false
*
*/
native bool:has_reunion();
@ -167,7 +178,7 @@ native bool:has_reunion();
/*
* Check if the vtc is available
*
* @return 1/0
* @return true/false
*
*/
native bool:has_vtc();

View File

@ -23,10 +23,10 @@ enum client_auth_type
* Checks whether the player is talking at this moment
*
* @param index Client index
* @return 1 if client is speaking, 0 otherwise
* @return true if client is speaking, false otherwise
*
*/
native VTC_IsClientSpeaking(const index);
native bool:VTC_IsClientSpeaking(const index);
/*
* Mutes this player

View File

@ -75,7 +75,7 @@ native rh_reset_mapname();
* @param emitFlags Additional Emit2 flags, look at the defines like SND_EMIT2_*
* @param origin Specify origin and only on "param" entity worldspawn that is 0
*
* @return 1 if successfully sounds are emitted, 0 otherwise
* @return true if successfully sounds are emitted, false otherwise
*
*/
native bool:rh_emit_sound2(const entity, const recipient, const channel, const sample[], Float:vol = VOL_NORM, Float:attn = ATTN_NORM, const flags = 0, const pitch = PITCH_NORM, emitFlags = 0, const Float:origin[3] = {0.0,0.0,0.0});

View File

@ -118,7 +118,7 @@ native rg_set_animation(const index, PLAYER_ANIM:playerAnim);
*
* @noreturn
*/
native rg_add_account(const index, amount, AccountSet:typeSet = AS_ADD, bool:bTrackChange = true);
native rg_add_account(const index, amount, AccountSet:typeSet = AS_ADD, const bool:bTrackChange = true);
/*
* Gives item to player
@ -148,7 +148,7 @@ native rg_give_default_items(const index);
*
* @noreturn
*/
native rg_give_shield(const index, bool:bDeploy = true);
native rg_give_shield(const index, const bool:bDeploy = true);
/*
* Inflicts in a radius from the source position.
@ -260,22 +260,26 @@ native rg_update_teamscores(const iCtsWins = 0, const iTsWins = 0, const bool:bA
* Creates an entity using Counter-Strike's custom CreateNamedEntity wrapper.
*
* @param classname Entity class name
* @param useHashTable Use this only for known game entities.
* NOTE: Do not use this if you use a custom classname.
*
* @return Index of the created entity or 0 otherwise
*
*/
native rg_create_entity(const classname[]);
native rg_create_entity(const classname[], const bool:useHashTable = false);
/*
* Finds an entity in the world using Counter-Strike's custom FindEntityByString wrapper.
*
* @param start_index Entity index to start searching from. -1 to start from the first entity
* @param classname Classname to search for
* @param useHashTable Use this only for known game entities.
* NOTE: Do not use this if you use a custom classname.
*
* @return Entity index > 0 if found, 0 otherwise
*
*/
native rg_find_ent_by_class(start_index, const classname[]);
native rg_find_ent_by_class(start_index, const classname[], const bool:useHashTable = false);
/*
* Finds an entity in the world using Counter-Strike's custom FindEntityByString wrapper, matching by owner.
@ -341,7 +345,7 @@ native rg_set_weapon_info(const {WeaponIdType,_}:weapon_id, WpnInfo:type, any:..
* @noreturn
*
*/
native rg_remove_all_items(const index, bool:bRemoveSuit = false);
native rg_remove_all_items(const index, const bool:bRemoveSuit = false);
/*
* Remove specifed the player's item by class name
@ -389,7 +393,7 @@ native rg_set_user_bpammo(const index, WeaponIdType:weapon, amount);
* @noreturn
*
*/
native rg_give_defusekit(const index, bool:bDefusekit = true, Float:color[] = {0.0, 160.0, 0.0}, const icon[] = "defuser", bool:bFlash = false);
native rg_give_defusekit(const index, const bool:bDefusekit = true, const Float:color[] = {0.0, 160.0, 0.0}, const icon[] = "defuser", const bool:bFlash = false);
/*
* Returns the client's armor value and retrieves the type of armor.
@ -428,7 +432,7 @@ native rg_set_user_armor(const index, armorvalue, ArmorType:armortype);
* @return 1 if successfully, 0 otherwise
*
*/
native rg_set_user_team(const index, {TeamName,_}:team, {ModelName,_}:model = MODEL_AUTO, bool:send_teaminfo = true);
native rg_set_user_team(const index, {TeamName,_}:team, {ModelName,_}:model = MODEL_AUTO, const bool:send_teaminfo = true);
/*
* Sets the client's player model.
@ -440,7 +444,7 @@ native rg_set_user_team(const index, {TeamName,_}:team, {ModelName,_}:model = MO
* @return 1 if successfully, 0 otherwise
*
*/
native rg_set_user_model(const index, const model[], bool:update_index = false);
native rg_set_user_model(const index, const model[], const bool:update_index = false);
/*
* Reset model user
@ -498,7 +502,7 @@ native rg_get_account_rules(const RewardRules:rules_index);
/*
* If the bomb is planted
*
* @return 1 if successfully, 0 otherwise
* @return true if bomb is planted, false otherwise
*
*/
native bool:rg_is_bomb_planted();
@ -566,7 +570,7 @@ native TeamName:rg_get_join_team_priority();
* @param index Client index
* @param attacker Attacker index
*
* @return 1 if successfully then can take a damage, 0 otherwise
* @return true if can take a damage, false otherwise
*
*/
native bool:rg_is_player_can_takedamage(const index, const attacker);
@ -580,3 +584,51 @@ native bool:rg_is_player_can_takedamage(const index, const attacker);
*
*/
native WeaponIdType:rg_get_weaponbox_id(const entity);
/*
* Respawn on round for players/bots
*
* @param index Client index
*
* @noreturn
*
*/
native rg_round_respawn(const index);
/*
* Draws a HUD progress bar which is fills from 0% to 100% for the time duration seconds.
* NOTE: Set Duration to 0 to hide the bar.
*
* @param index Client index
* @param time Duration
* @param observer Send for everyone observer player
*
* @noreturn
*
*/
native rg_send_bartime(const index, const Float:duration, const bool:observer = true);
/*
* Same as BarTime, but StartPercent specifies how much of the bar is (already) filled.
*
* @param index Client index
* @param time Duration
* @param startPercent Start percent
* @param observer Send for everyone observer player
*
* @noreturn
*
*/
native rg_send_bartime2(const index, const Float:duration, const Float:startPercent, const bool:observer = true);
/*
* Sends the message SendAudio - plays the specified audio
*
* @param index Receiver index or use 0 for everyone
* @param sample Sound file to play
* @param pitch Sound pitch
*
* @noreturn
*
*/
native rg_send_audio(const index, const sample[], const pitch = PITCH_NORM);

View File

@ -27,6 +27,12 @@
#define RG_CBasePlayer_SetClientUserInfoName RG_CBasePlayer_SetUserInfoName
#endif
enum UnifiedSignals
{
US_Signal,
US_State
};
enum AccountSet
{
AS_SET, // sets the value of the account
@ -2184,10 +2190,10 @@ enum CBasePlayer_Members
m_tmHandleSignals,
/*
* Description: -
* Description: (0 - signal, 1 - state)
* Member type: class CUnifiedSignals
* Get params: get_member(index, member, signals[2]); (0 - signal, 1 - state)
* Set params: set_member(index, member, value);
* Get params: get_member(index, member, signals[UnifiedSignals]);
* Set params: set_member(index, member, signals[UnifiedSignals]);
*/
m_signals,
@ -3581,16 +3587,16 @@ enum PlayerMove
/*
* Description: -
* Member type: vec3_t [4]
* Get params: get_pmove(const PlayerMove:var, Float:output[3], index);
* Set params: set_pmove(const PlayerMove:var, Float:dest[3], index);
* Get params: get_pmove(const PlayerMove:var, Float:output[3], element);
* Set params: set_pmove(const PlayerMove:var, Float:dest[3], element);
*/
pm_player_mins,
/*
* Description: -
* Member type: vec3_t [4]
* Get params: get_pmove(const PlayerMove:var, Float:output[3], index);
* Set params: set_pmove(const PlayerMove:var, Float:dest[3], index);
* Get params: get_pmove(const PlayerMove:var, Float:output[3], element);
* Set params: set_pmove(const PlayerMove:var, Float:dest[3], element);
*/
pm_player_maxs
};
@ -4219,8 +4225,8 @@ enum CWeaponBox_Members
/*
* Description: -
* Member type: int [32]
* Get params: get_member(member);
* Set params: set_member(member, value, element);
* Get params: get_member(index, member, element);
* Set params: set_member(index, member, value, element);
*/
m_WeaponBox_rgAmmo,

View File

@ -84,7 +84,6 @@
#define MENU_KEY_9 (1<<8)
#define MENU_KEY_0 (1<<9)
#define MAX_AMMO_TYPES 32 // ???
#define MAX_AMMO_SLOTS 32 // not really slots
#define HUD_PRINTNOTIFY 1

View File

@ -251,18 +251,23 @@ enum MaxAmmoType
enum AmmoType
{
AMMO_NONE = -1,
AMMO_BUCKSHOT,
AMMO_9MM,
AMMO_556NATO,
AMMO_556NATOBOX,
AMMO_762NATO,
AMMO_45ACP,
AMMO_50AE,
AMMO_NONE,
AMMO_338MAGNUM,
AMMO_762NATO,
AMMO_556NATOBOX,
AMMO_556NATO,
AMMO_BUCKSHOT,
AMMO_45ACP,
AMMO_57MM,
AMMO_50AE,
AMMO_357SIG,
AMMO_MAX_TYPES,
AMMO_9MM,
AMMO_FLASHBANG,
AMMO_HEGRENADE,
AMMO_SMOKEGRENADE,
AMMO_C4,
AMMO_MAX_TYPES
};
enum WeaponClassType

View File

@ -3,7 +3,7 @@
edict_t* g_pEdicts;
playermove_t* g_pMove;
char g_szMapName[32];
int gmsgSendAudio, gmsgStatusIcon, gmsgArmorType, gmsgItemStatus;
int gmsgSendAudio, gmsgStatusIcon, gmsgArmorType, gmsgItemStatus, gmsgBarTime, gmsgBarTime2;
struct
{
@ -14,6 +14,8 @@ struct
{ "StatusIcon", gmsgStatusIcon },
{ "ArmorType", gmsgArmorType },
{ "ItemStatus", gmsgItemStatus },
{ "BarTime", gmsgBarTime },
{ "BarTime2", gmsgBarTime2 },
};
void OnAmxxAttach()
@ -65,7 +67,7 @@ CGameRules *InstallGameRules(IReGameHook_InstallGameRules *chain)
return g_pGameRules = chain->callNext();
}
int DispatchSpawn(edict_t* pEntity)
int DispatchSpawn(edict_t *pEntity)
{
// save true mapname
strncpy(g_szMapName, STRING(gpGlobals->mapname), sizeof(g_szMapName) - 1);

View File

@ -7,6 +7,8 @@ extern int gmsgSendAudio;
extern int gmsgStatusIcon;
extern int gmsgArmorType;
extern int gmsgItemStatus;
extern int gmsgBarTime;
extern int gmsgBarTime2;
void OnAmxxAttach();
bool OnMetaAttach();

View File

@ -1,6 +1,6 @@
#include "precompiled.h"
#define CLASS_MEMBERS(cx, mx, postf, pref) ((!(postf & (MAX_REGION_RANGE - 1)) ? regmember::current_cell = 1, true : false) || (postf & (MAX_REGION_RANGE - 1)) == regmember::current_cell++) ? regmember([](member_t* ptr){ decltype(##cx::##pref##mx) f = {};ptr->size = getTypeSize(f);ptr->max_size = sizeof(f);ptr->offset = offsetof(##cx, ##pref##mx);ptr->type = getMemberType(f);}) : regmember(#pref#mx)
#define CLASS_MEMBERS(cx, mx, postf, pref) ((!(postf & (MAX_REGION_RANGE - 1)) ? regmember::current_cell = 1, true : false) || (postf & (MAX_REGION_RANGE - 1)) == regmember::current_cell++) ? regmember([](member_t* ptr){ decltype(##cx::##pref##mx) f = {};ptr->size = getTypeSize(f);ptr->max_size = sizeof(f);ptr->offset = offsetof(##cx, ##pref##mx);ptr->type = getMemberType(f);ptr->name = #postf;}) : regmember(#pref#mx)
#define GM_MEMBERS(mx) CLASS_MEMBERS(CHalfLifeMultiplay, mx, mx,)
#define GM_VOICE_MEMBERS(mx) CLASS_MEMBERS(CVoiceGameMgr, mx, mx,)

View File

@ -31,6 +31,7 @@ struct member_t
uint16 size;
uint16 max_size;
uint32 offset;
const char *name;
MType type;
};

View File

@ -4,9 +4,9 @@
* Checks whether the player is talking at this moment
*
* @param index Client index
* @return 1 if client is speaking, 0 otherwise
* @return true if client is speaking, false otherwise
*
* native VTC_IsClientSpeaking(const index);
* native bool:VTC_IsClientSpeaking(const index);
*/
cell AMX_NATIVE_CALL VTC_IsClientSpeaking(AMX *amx, cell *params)
{
@ -14,7 +14,7 @@ cell AMX_NATIVE_CALL VTC_IsClientSpeaking(AMX *amx, cell *params)
CHECK_ISPLAYER(arg_index);
return g_pVoiceTranscoderApi->IsClientSpeaking((size_t)params[arg_index]);
return (cell)g_pVoiceTranscoderApi->IsClientSpeaking((size_t)params[arg_index]);
}
/*
@ -32,7 +32,6 @@ cell AMX_NATIVE_CALL VTC_MuteClient(AMX *amx, cell *params)
CHECK_ISPLAYER(arg_index);
g_pVoiceTranscoderApi->MuteClient((size_t)params[arg_index]);
return FALSE;
}
@ -51,7 +50,6 @@ cell AMX_NATIVE_CALL VTC_UnmuteClient(AMX *amx, cell *params)
CHECK_ISPLAYER(arg_index);
g_pVoiceTranscoderApi->UnmuteClient((size_t)params[arg_index]);
return FALSE;
}

View File

@ -27,16 +27,16 @@ cell AMX_NATIVE_CALL set_member(AMX *amx, cell *params)
return FALSE;
}
return set_member(pPlayer->CSPlayer(), member, element, value);
return set_member(pPlayer->CSPlayer(), member, value, element);
}
return set_member(pEdict->pvPrivateData, member, element, value);
return set_member(pEdict->pvPrivateData, member, value, element);
}
// native any:get_member(_index, any:_member, any:...);
cell AMX_NATIVE_CALL get_member(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_index, arg_member, arg_3, arg_4 };
enum args_e { arg_count, arg_index, arg_member, arg_3, arg_4, arg_5 };
member_t *member = memberlist[params[arg_member]];
if (member == nullptr) {
@ -52,12 +52,22 @@ cell AMX_NATIVE_CALL get_member(AMX *amx, cell *params)
cell* dest;
size_t element;
size_t length;
if (PARAMS_COUNT == 4) {
switch (PARAMS_COUNT)
{
case 5:
dest = getAmxAddr(amx, params[arg_3]);
element = *getAmxAddr(amx, params[arg_4]);
}
else if (PARAMS_COUNT == 3) {
length = *getAmxAddr(amx, params[arg_4]);
element = *getAmxAddr(amx, params[arg_5]);
break;
case 4:
dest = getAmxAddr(amx, params[arg_3]);
length = *getAmxAddr(amx, params[arg_4]);
element = 0;
break;
case 3:
{
cell* arg3 = getAmxAddr(amx, params[arg_3]);
if (isTypeReturnable(member->type)) {
@ -68,10 +78,14 @@ cell AMX_NATIVE_CALL get_member(AMX *amx, cell *params)
dest = arg3;
element = 0;
}
length = 0;
break;
}
else {
default:
dest = nullptr;
element = 0;
length = 0;
break;
}
const auto table = memberlist_t::members_tables_e(params[arg_member] / MAX_REGION_RANGE);
@ -81,10 +95,10 @@ cell AMX_NATIVE_CALL get_member(AMX *amx, cell *params)
return FALSE;
}
return get_member(pPlayer->CSPlayer(), member, element, dest);
return get_member(pPlayer->CSPlayer(), member, dest, element, length);
}
return get_member(pEdict->pvPrivateData, member, element, dest);
return get_member(pEdict->pvPrivateData, member, dest, element, length);
}
// native set_member_game(any:_member, any:...);
@ -103,7 +117,7 @@ cell AMX_NATIVE_CALL set_member_game(AMX *amx, cell *params)
cell* value = getAmxAddr(amx, params[arg_value]);
size_t element = (PARAMS_COUNT == 4) ? *getAmxAddr(amx, params[arg_elem]) : 0;
return set_member(g_pGameRules, member, element, value);
return set_member(g_pGameRules, member, value, element);
}
// native get_member_game(any:_member, any:...);
@ -121,10 +135,12 @@ cell AMX_NATIVE_CALL get_member_game(AMX *amx, cell *params)
cell* dest;
size_t element;
size_t length;
if (PARAMS_COUNT == 4) {
dest = getAmxAddr(amx, params[arg_3]);
element = *getAmxAddr(amx, params[arg_4]);
length = *getAmxAddr(amx, params[arg_4]);
element = 0;
}
else if (PARAMS_COUNT == 3) {
cell* arg3 = getAmxAddr(amx, params[arg_3]);
@ -137,10 +153,12 @@ cell AMX_NATIVE_CALL get_member_game(AMX *amx, cell *params)
dest = arg3;
element = 0;
}
length = 0;
}
else {
dest = nullptr;
element = 0;
length = 0;
}
void* data;
@ -151,7 +169,7 @@ cell AMX_NATIVE_CALL get_member_game(AMX *amx, cell *params)
data = g_pGameRules;
}
return get_member(data, member, element, dest);
return get_member(data, member, dest, element, length);
}
// native set_entvar(const index, const EntVars:var, any:...);
@ -175,7 +193,7 @@ cell AMX_NATIVE_CALL set_entvar(AMX *amx, cell *params)
cell* value = getAmxAddr(amx, params[arg_value]);
size_t element = (PARAMS_COUNT == 4) ? *getAmxAddr(amx, params[arg_elem]) : 0;
return set_member(&pEdict->v, member, element, value);
return set_member(&pEdict->v, member, value, element);
}
// native any:get_entvar(const index, const EntVars:var, any:...);
@ -199,10 +217,12 @@ cell AMX_NATIVE_CALL get_entvar(AMX *amx, cell *params)
cell* dest;
size_t element;
size_t length;
if (PARAMS_COUNT == 4) {
dest = getAmxAddr(amx, params[arg_3]);
element = *getAmxAddr(amx, params[arg_4]);
length = *getAmxAddr(amx, params[arg_4]);
element = 0;
}
else if (PARAMS_COUNT == 3) {
cell* arg3 = getAmxAddr(amx, params[arg_3]);
@ -215,13 +235,16 @@ cell AMX_NATIVE_CALL get_entvar(AMX *amx, cell *params)
dest = arg3;
element = 0;
}
length = 0;
}
else {
dest = nullptr;
element = 0;
length = 0;
}
return get_member(&pEdict->v, member, element, dest);
return get_member(&pEdict->v, member, dest, element, length);
}
// native set_pmove(const PlayerMove:pmove, any:...);
@ -238,7 +261,7 @@ cell AMX_NATIVE_CALL set_pmove(AMX *amx, cell *params)
cell* value = getAmxAddr(amx, params[arg_value]);
size_t element = (PARAMS_COUNT == 4) ? *getAmxAddr(amx, params[arg_elem]) : 0;
return set_member(g_pMove, member, element, value);
return set_member(g_pMove, member, value, element);
}
// native any:get_pmove(const PlayerMove:pmove, any:...);
@ -254,17 +277,26 @@ cell AMX_NATIVE_CALL get_pmove(AMX *amx, cell *params)
cell* dest;
size_t element;
size_t length;
if (PARAMS_COUNT == 3) {
dest = getAmxAddr(amx, params[arg_2]);
element = *getAmxAddr(amx, params[arg_3]);
if (member->type == MEMBER_STRING) {
dest = getAmxAddr(amx, params[arg_2]);
length = *getAmxAddr(amx, params[arg_3]);
element = 0;
} else {
dest = getAmxAddr(amx, params[arg_2]);
element = *getAmxAddr(amx, params[arg_3]);
length = 0;
}
}
else {
dest = nullptr;
element = 0;
length = 0;
}
return get_member(g_pMove, member, element, dest);
return get_member(g_pMove, member, dest, element, length);
}
// native set_movevar(const MoveVars:var, any:...);
@ -279,7 +311,7 @@ cell AMX_NATIVE_CALL set_movevar(AMX *amx, cell *params)
}
cell* value = getAmxAddr(amx, params[arg_value]);
return set_member(g_pMove->movevars, member, 0, value);
return set_member(g_pMove->movevars, member, value, 0);
}
// native any:get_movevar(const MoveVars:var, any:...);
@ -295,17 +327,20 @@ cell AMX_NATIVE_CALL get_movevar(AMX *amx, cell *params)
cell* dest;
size_t element;
size_t length;
if (PARAMS_COUNT == 3) {
dest = getAmxAddr(amx, params[arg_2]);
element = *getAmxAddr(amx, params[arg_3]);
length = *getAmxAddr(amx, params[arg_3]);
element = 0;
}
else {
dest = nullptr;
element = 0;
length = 0;
}
return get_member(g_pMove->movevars, member, element, dest);
return get_member(g_pMove->movevars, member, dest, element, length);
}
// native set_ucmd(const cmd, const UserCmd:var, any:...);
@ -321,7 +356,7 @@ cell AMX_NATIVE_CALL set_ucmd(AMX *amx, cell *params)
cell* cmd = (cell *)params[arg_cmd];
cell* value = getAmxAddr(amx, params[arg_value]);
return set_member(cmd, member, 0, value);
return set_member(cmd, member, value, 0);
}
// native any:get_ucmd(const cmd, const UserCmd:var, any:...);
@ -348,7 +383,7 @@ cell AMX_NATIVE_CALL get_ucmd(AMX *amx, cell *params)
}
cell* cmd = (cell *)params[arg_cmd];
return get_member(cmd, member, element, dest);
return get_member(cmd, member, dest, element);
}
// native set_pmtrace(const tr, const PMTrace:var, any:...);
@ -364,7 +399,7 @@ cell AMX_NATIVE_CALL set_pmtrace(AMX *amx, cell *params)
cell* tr = (cell *)params[arg_tr];
cell* value = getAmxAddr(amx, params[arg_value]);
return set_member(tr, member, 0, value);
return set_member(tr, member, value, 0);
}
// native any:get_pmtrace(const tr, const PMTrace:var, any:...);
@ -391,7 +426,7 @@ cell AMX_NATIVE_CALL get_pmtrace(AMX *amx, cell *params)
}
cell* tr = (cell *)params[arg_tr];
return get_member(tr, member, element, dest);
return get_member(tr, member, dest, element);
}
AMX_NATIVE_INFO EngineVars_Natives[] =
@ -434,7 +469,7 @@ void RegisterNatives_Members()
g_amxxapi.AddNatives(EngineVars_Natives);
}
BOOL set_member(void* pdata, const member_t *member, size_t element, cell* value)
BOOL set_member(void* pdata, const member_t *member, cell* value, size_t element)
{
switch (member->type) {
case MEMBER_CLASSPTR:
@ -488,7 +523,7 @@ BOOL set_member(void* pdata, const member_t *member, size_t element, cell* value
case MEMBER_QSTRING:
{
char *source = getAmxString(value);
string_t newstr = ALLOC_STRING(source);
string_t newstr = (source && source[0] != '\0') ? ALLOC_STRING(source) : 0;
set_member<string_t>(pdata, member->offset, newstr, element);
return TRUE;
}
@ -519,9 +554,15 @@ BOOL set_member(void* pdata, const member_t *member, size_t element, cell* value
}
case MEMBER_SIGNALS:
{
// native set_member(_index, any:_member, _value);
enum { _Signal, _State };
// native set_member(_index, any:_member, signals[UnifiedSignals]);
CUnifiedSignals& signal = get_member<CUnifiedSignals>(pdata, member->offset, element);
signal.Signal(*value);
int *pSignals = value;
signal.m_flSignal = pSignals[_Signal];
signal.m_flState = pSignals[_State];
return TRUE;
}
case MEMBER_DOUBLE:
@ -544,7 +585,7 @@ BOOL set_member(void* pdata, const member_t *member, size_t element, cell* value
return FALSE;
}
cell get_member(void* pdata, const member_t *member, size_t element, cell* dest)
cell get_member(void* pdata, const member_t *member, cell* dest, size_t element, size_t length)
{
switch (member->type)
{
@ -585,7 +626,7 @@ cell get_member(void* pdata, const member_t *member, size_t element, cell* dest)
if (member->max_size > sizeof(char*)) {
// char []
const char *src = get_member_direct<char>(pdata, member->offset);
setAmxString(dest, src, element);
setAmxString(dest, src, length);
} else {
// char *
const char *src = get_member<const char *>(pdata, member->offset);
@ -593,7 +634,7 @@ cell get_member(void* pdata, const member_t *member, size_t element, cell* dest)
setAmxString(dest, "", 1);
return 0;
}
setAmxString(dest, src, element);
setAmxString(dest, src, length);
}
return 1;
@ -603,22 +644,22 @@ cell get_member(void* pdata, const member_t *member, size_t element, cell* dest)
if (!dest)
return 0;
string_t str = get_member<string_t>(pdata, member->offset);
if (str == 0) {
string_t str = get_member<string_t>(pdata, member->offset, element);
if (FStringNull(str)) {
setAmxString(dest, "", 1);
return 0;
}
setAmxString(dest, STRING(str), element);
setAmxString(dest, STRING(str), length);
return 1;
}
case MEMBER_FLOAT:
case MEMBER_INTEGER:
{
auto& ret = get_member<int>(pdata, member->offset, element);
if (dest != nullptr) {
if (dest)
*dest = ret;
}
return ret;
}
case MEMBER_SHORT:
@ -635,7 +676,7 @@ cell get_member(void* pdata, const member_t *member, size_t element, cell* dest)
return get_member<double>(pdata, member->offset, element);
case MEMBER_SIGNALS:
{
enum {_Signal, _State};
enum { _Signal, _State };
// native any:get_member(_index, any:_member, signals[2]);
if (!dest)

View File

@ -2,7 +2,7 @@
void RegisterNatives_Members();
BOOL set_member(void* pdata, const member_t *member, size_t element, cell* value);
cell get_member(void* pdata, const member_t *member, size_t element, cell* dest);
BOOL set_member(void* pdata, const member_t *member, cell* value, size_t element);
cell get_member(void* pdata, const member_t *member, cell* dest, size_t element, size_t length = 0);
bool isTypeReturnable(MType type);

View File

@ -37,7 +37,7 @@ enum AccountSet { AS_SET, AS_ADD };
*
* @noreturn
*
* native rg_add_account(index, amount, AccountSet:typeSet = AS_ADD, bool:bTrackChange = true);
* native rg_add_account(index, amount, AccountSet:typeSet = AS_ADD, const bool:bTrackChange = true);
*/
cell AMX_NATIVE_CALL rg_add_account(AMX *amx, cell *params)
{
@ -153,7 +153,7 @@ cell AMX_NATIVE_CALL rg_give_default_items(AMX *amx, cell *params)
*
* @noreturn
*
* native rg_give_shield(index, bool:bDeploy = true);
* native rg_give_shield(index, const bool:bDeploy = true);
*/
cell AMX_NATIVE_CALL rg_give_shield(AMX *amx, cell *params)
{
@ -327,7 +327,7 @@ cell AMX_NATIVE_CALL rg_fire_bullets(AMX *amx, cell *params)
*
* @return Float:[3] The result spread
*
* native Float:[3] rg_fire_bullets3(inflictor, attacker, Float:vecSrc[3], Float:vecDirShooting[3], Float:vecSpread, Float:flDistance, iPenetration, iBulletType, iDamage, Float:flRangeModifier, bool:bPistol, shared_rand);
* native Float:[3] rg_fire_bullets3(const inflictor, const attacker, Float:vecSrc[3], Float:vecDirShooting[3], const Float:vecSpread, const Float:flDistance, const iPenetration, const Bullet:iBulletType, const iDamage, const Float:flRangeModifier, const bool:bPistol, const shared_rand);
*/
cell AMX_NATIVE_CALL rg_fire_bullets3(AMX *amx, cell *params)
{
@ -440,7 +440,7 @@ cell AMX_NATIVE_CALL rg_round_end(AMX *amx, cell *params)
*
* @noreturn
*
* native rg_update_teamscores(iCtsWins = 0, iTsWins = 0, bool:bAdd = true);
* native rg_update_teamscores(const iCtsWins = 0, const iTsWins = 0, const bool:bAdd = true);
*/
cell AMX_NATIVE_CALL rg_update_teamscores(AMX *amx, cell *params)
{
@ -459,21 +459,27 @@ cell AMX_NATIVE_CALL rg_update_teamscores(AMX *amx, cell *params)
* Creates an entity using Counter-Strike's custom CreateNamedEntity wrapper.
*
* @param classname Entity class name
* @param useHashTable Use this only for known game entities.
* NOTE: Do not use this if you use a custom classname.
*
* @return Index of the created entity or 0 otherwise
*
* native rg_create_entity(const classname[]);
* native rg_create_entity(const classname[], const bool:useHashTable = false);
*/
cell AMX_NATIVE_CALL rg_create_entity(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_classname };
enum args_e { arg_count, arg_classname, arg_hashtable };
string_t iClass = g_engfuncs.pfnAllocString(getAmxString(amx, params[arg_classname]));
edict_t *pEnt = g_ReGameFuncs->CREATE_NAMED_ENTITY2(iClass);
if (pEnt != nullptr)
{
return indexOfEdict(pEnt);
edict_t *pEntity;
if (params[arg_hashtable] != 0)
pEntity = g_ReGameFuncs->CREATE_NAMED_ENTITY2(iClass);
else
pEntity = CREATE_NAMED_ENTITY(iClass);
if (pEntity) {
return indexOfEdict(pEntity);
}
return 0;
@ -484,22 +490,34 @@ cell AMX_NATIVE_CALL rg_create_entity(AMX *amx, cell *params)
*
* @param start_index Entity index to start searching from. -1 to start from the first entity
* @param classname Classname to search for
* @param useHashTable Use this only for known game entities.
* NOTE: Do not use this if you use a custom classname.
*
* @return Entity index > 0 if found, 0 otherwise
*
* native rg_find_ent_by_class(start_index, const classname[]);
* native rg_find_ent_by_class(start_index, const classname[], const bool:useHashTable = false);
*/
cell AMX_NATIVE_CALL rg_find_ent_by_class(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_start_index, arg_classname };
enum args_e { arg_count, arg_start_index, arg_classname, arg_hashtable };
CBaseEntity *pStartEntity = getPrivate<CBaseEntity>(params[arg_start_index]);
const char* value = getAmxString(amx, params[arg_classname]);
CBaseEntity *pEntity = g_ReGameFuncs->UTIL_FindEntityByString(pStartEntity, "classname", value);
if (pEntity != nullptr)
if (params[arg_hashtable] != 0)
{
return indexOfEdict(pEntity->pev);
auto pStartEntity = getPrivate<CBaseEntity>(params[arg_start_index]);
auto pEntity = g_ReGameFuncs->UTIL_FindEntityByString(pStartEntity, "classname", value);
if (pEntity) {
return indexOfEdict(pEntity->pev);
}
return 0;
}
auto pStartEntity = edictByIndexAmx(params[arg_start_index]);
auto pEdict = FIND_ENTITY_BY_STRING(pStartEntity, "classname", value);
if (pEdict) {
return indexOfEdict(pEdict);
}
return 0;
@ -794,7 +812,7 @@ cell AMX_NATIVE_CALL rg_set_weapon_info(AMX *amx, cell *params)
*
* @noreturn
*
* native rg_remove_all_items(const index, bool:bRemoveSuit);
* native rg_remove_all_items(const index, const bool:bRemoveSuit);
*/
cell AMX_NATIVE_CALL rg_remove_all_items(AMX *amx, cell *params)
{
@ -943,7 +961,7 @@ cell AMX_NATIVE_CALL rg_set_user_bpammo(AMX *amx, cell *params)
*
* @noreturn
*
* native rg_give_defusekit(const index, bool:bDefusekit = true, Float:color[] = {0.0, 160.0, 0.0}, const icon[] = "defuser", bool:bFlash = false);
* native rg_give_defusekit(const index, const bool:bDefusekit = true, const Float:color[] = {0.0, 160.0, 0.0}, const icon[] = "defuser", const bool:bFlash = false);
*/
cell AMX_NATIVE_CALL rg_give_defusekit(AMX *amx, cell *params)
{
@ -1066,7 +1084,7 @@ cell AMX_NATIVE_CALL rg_set_user_armor(AMX *amx, cell *params)
*
* @return 1 if successfully, 0 otherwise
*
* native rg_set_user_team(const index, {TeamName,_}:team, {ModelName,_}:model = MODEL_AUTO, bool:send_teaminfo = true);
* native rg_set_user_team(const index, {TeamName,_}:team, {ModelName,_}:model = MODEL_AUTO, const bool:send_teaminfo = true);
*/
cell AMX_NATIVE_CALL rg_set_user_team(AMX *amx, cell *params)
{
@ -1158,7 +1176,7 @@ cell AMX_NATIVE_CALL rg_set_user_team(AMX *amx, cell *params)
*
* @return 1 if successfully, 0 otherwise
*
* native rg_set_user_model(const index, const model[], bool:update_index = false);
* native rg_set_user_model(const index, const model[], const bool:update_index = false);
*/
cell AMX_NATIVE_CALL rg_set_user_model(AMX *amx, cell *params)
{
@ -1346,7 +1364,7 @@ cell AMX_NATIVE_CALL rg_get_account_rules(AMX *amx, cell *params)
/*
* If the bomb is planted
*
* @return 1 if successfully, 0 otherwise
* @return true if bomb is planted, false otherwise
*
* native bool:rg_is_bomb_planted();
*/
@ -1489,7 +1507,7 @@ cell AMX_NATIVE_CALL rg_get_join_team_priority(AMX *amx, cell *params)
* @param index Client index
* @param attacker Attacker index
*
* @return 1 if successfully then can take a damage, 0 otherwise
* @return true if can take a damage, false otherwise
*
* native bool:rg_is_player_can_takedamage(const index, const attacker);
*/
@ -1545,6 +1563,129 @@ cell AMX_NATIVE_CALL rg_get_weaponbox_id(AMX *amx, cell *params)
return WEAPON_NONE;
}
/*
* Respawn on round for players/bots
*
* @param index Client index
*
* @noreturn
*
* native rg_round_respawn(const index);
*/
cell AMX_NATIVE_CALL rg_round_respawn(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_index };
CBasePlayer *pPlayer = g_ReGameFuncs->UTIL_PlayerByIndex(params[arg_index]);
if (pPlayer == nullptr || pPlayer->has_disconnected) {
MF_LogError(amx, AMX_ERR_NATIVE, "%s: player %i is not connected", __FUNCTION__, params[arg_index]);
return FALSE;
}
pPlayer->RoundRespawn();
return TRUE;
}
/*
* Draws a HUD progress bar which is fills from 0% to 100% for the time duration seconds.
* NOTE: Set Duration to 0 to hide the bar.
*
* @param index Client index
* @param time Duration
* @param observer Send for everyone observer player
*
* @noreturn
*
* native rg_send_bartime(const index, const Float:duration, const bool:observer = true);
*/
cell AMX_NATIVE_CALL rg_send_bartime(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_index, arg_time, arg_observer };
CBasePlayer *pPlayer = g_ReGameFuncs->UTIL_PlayerByIndex(params[arg_index]);
if (pPlayer == nullptr || pPlayer->has_disconnected) {
MF_LogError(amx, AMX_ERR_NATIVE, "%s: player %i is not connected", __FUNCTION__, params[arg_index]);
return FALSE;
}
CAmxArgs args(amx, params);
if (!args[arg_observer]) {
EMESSAGE_BEGIN(MSG_ONE_UNRELIABLE, gmsgBarTime, nullptr, pPlayer->edict());
EWRITE_SHORT(args[arg_time]);
EMESSAGE_END();
return TRUE;
}
pPlayer->CSPlayer()->SetProgressBarTime(args[arg_time]);
return TRUE;
}
/*
* Same as BarTime, but StartPercent specifies how much of the bar is (already) filled.
*
* @param index Client index
* @param time Duration
* @param startPercent Start percent
* @param observer Send for everyone observer player
*
* @noreturn
*
* native rg_send_bartime2(const index, const Float:duration, const Float:startPercent, const bool:observer = true);
*/
cell AMX_NATIVE_CALL rg_send_bartime2(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_index, arg_time, arg_start_percent, arg_observer };
CBasePlayer *pPlayer = g_ReGameFuncs->UTIL_PlayerByIndex(params[arg_index]);
if (pPlayer == nullptr || pPlayer->has_disconnected) {
MF_LogError(amx, AMX_ERR_NATIVE, "%s: player %i is not connected", __FUNCTION__, params[arg_index]);
return FALSE;
}
CAmxArgs args(amx, params);
if (!args[arg_observer]) {
EMESSAGE_BEGIN(MSG_ONE_UNRELIABLE, gmsgBarTime2, nullptr, pPlayer->edict());
EWRITE_SHORT(args[arg_time]);
EWRITE_SHORT(args[arg_start_percent]);
EMESSAGE_END();
return TRUE;
}
pPlayer->CSPlayer()->SetProgressBarTime2(args[arg_time], args[arg_start_percent]);
return TRUE;
}
/*
* Sends the message SendAudio - plays the specified audio
*
* @param index Receiver index or use 0 for everyone
* @param sample Sound file to play
* @param pitch Sound pitch
*
* @noreturn
*
* native rg_send_audio(const index, const sample[], const pitch = PITCH_NORM);
*/
cell AMX_NATIVE_CALL rg_send_audio(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_index, arg_sample, arg_pitch };
int nIndex = params[arg_index];
if (nIndex < 0)
nIndex = 0;
const char *szSample = getAmxString(amx, params[arg_sample]);
auto pEdict = (nIndex == 0) ? nullptr : edictByIndexAmx(nIndex);
EMESSAGE_BEGIN(nIndex ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, gmsgSendAudio, nullptr, pEdict);
EWRITE_BYTE(nIndex);
EWRITE_STRING(szSample);
EWRITE_SHORT(params[arg_pitch]);
EMESSAGE_END();
return TRUE;
}
AMX_NATIVE_INFO Misc_Natives_RG[] =
{
{ "rg_set_animation", rg_set_animation },
@ -1604,6 +1745,11 @@ AMX_NATIVE_INFO Misc_Natives_RG[] =
{ "rg_get_join_team_priority", rg_get_join_team_priority },
{ "rg_is_player_can_takedamage", rg_is_player_can_takedamage },
{ "rg_get_weaponbox_id", rg_get_weaponbox_id },
{ "rg_round_respawn", rg_round_respawn },
{ "rg_send_bartime", rg_send_bartime },
{ "rg_send_bartime2", rg_send_bartime2 },
{ "rg_send_audio", rg_send_audio },
{ nullptr, nullptr }
};
@ -1698,7 +1844,7 @@ cell AMX_NATIVE_CALL rh_emit_sound2(AMX *amx, cell *params)
enum args_e { arg_count, arg_entity, arg_recipient, arg_channel, arg_sample, arg_vol, arg_attn, arg_flags, arg_pitch, arg_emitFlags, arg_origin };
CBaseEntity *pRecipient = getPrivate<CBaseEntity>(params[arg_recipient]);
if (pRecipient != nullptr && pRecipient->has_disconnected) {
if (pRecipient && pRecipient->has_disconnected) {
MF_LogError(amx, AMX_ERR_NATIVE, "%s: player %i is not connected", __FUNCTION__, params[arg_recipient]);
return FALSE;
}
@ -1711,7 +1857,7 @@ cell AMX_NATIVE_CALL rh_emit_sound2(AMX *amx, cell *params)
CAmxArgs args(amx, params);
const char *sample = getAmxString(amx, params[arg_sample]);
return g_RehldsFuncs->SV_EmitSound2
return (cell)g_RehldsFuncs->SV_EmitSound2
(
args[arg_entity], // entity
args[arg_recipient], // recipient
@ -1754,12 +1900,41 @@ AMX_NATIVE_INFO Misc_Natives_RH[] =
{ nullptr, nullptr }
};
/*
* Check if the entity is valid
*
* @return true/false
*
* native bool:is_entity(const entityIndex);
*/
cell AMX_NATIVE_CALL is_entity(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_index };
int nIndex = params[arg_index];
if (nIndex < 0 || nIndex > gpGlobals->maxEntities) {
return FALSE;
}
auto pEntity = getPrivate<CBaseEntity>(nIndex);
if (!pEntity) {
return FALSE;
}
// if it is the index of the player
if (pEntity->IsPlayer() && pEntity->has_disconnected) {
return FALSE;
}
return TRUE;
}
/*
* Check if the rehlds is available
*
* @return 1/0
* @return true/false
*
* native is_rehlds();
* native bool:is_rehlds();
*/
cell AMX_NATIVE_CALL is_rehlds(AMX *amx, cell *params)
{
@ -1769,9 +1944,9 @@ cell AMX_NATIVE_CALL is_rehlds(AMX *amx, cell *params)
/*
* Check if the regamedll is available
*
* @return 1/0
* @return true/false
*
* native is_regamedll();
* native bool:is_regamedll();
*/
cell AMX_NATIVE_CALL is_regamedll(AMX *amx, cell *params)
{
@ -1781,9 +1956,9 @@ cell AMX_NATIVE_CALL is_regamedll(AMX *amx, cell *params)
/*
* Check if the reunion is available
*
* @return 1/0
* @return true/false
*
* native is_has_reunion();
* native bool:is_has_reunion();
*/
cell AMX_NATIVE_CALL has_reunion(AMX *amx, cell *params)
{
@ -1793,9 +1968,9 @@ cell AMX_NATIVE_CALL has_reunion(AMX *amx, cell *params)
/*
* Check if the vtc is available
*
* @return 1/0
* @return true/false
*
* native is_has_vtc();
* native bool:is_has_vtc();
*/
cell AMX_NATIVE_CALL has_vtc(AMX *amx, cell *params)
{
@ -1804,6 +1979,7 @@ cell AMX_NATIVE_CALL has_vtc(AMX *amx, cell *params)
AMX_NATIVE_INFO Misc_Natives_Checks[] =
{
{ "is_entity", is_entity },
{ "is_rehlds", is_rehlds },
{ "is_regamedll", is_regamedll },
{ "has_reunion", has_reunion },

View File

@ -5,11 +5,11 @@ void Broadcast(const char *sentence)
char text[128];
snprintf(text, sizeof text, "%!MRAD_%s", sentence);
g_pengfuncsTable->pfnMessageBegin(MSG_BROADCAST, gmsgSendAudio, NULL, NULL);
g_pengfuncsTable->pfnWriteByte(0);
g_pengfuncsTable->pfnWriteString(text);
g_pengfuncsTable->pfnWriteShort(100);
g_pengfuncsTable->pfnMessageEnd();
EMESSAGE_BEGIN(MSG_BROADCAST, gmsgSendAudio);
EWRITE_BYTE(0);
EWRITE_STRING(text);
EWRITE_SHORT(100);
EMESSAGE_END();
}
struct {

View File

@ -7,13 +7,24 @@ char(&ArraySizeHelper(T(&array)[N]))[N];
#define INDEXENT edictByIndex
#define ENTINDEX indexOfEdict
extern enginefuncs_t* g_pengfuncsTable;
extern DLL_FUNCTIONS *g_pFunctionTable;
inline void EMESSAGE_BEGIN(int msg_dest, int msg_type, const float *pOrigin = nullptr, edict_t *ed = nullptr) { (*g_pengfuncsTable->pfnMessageBegin)(msg_dest, msg_type, pOrigin, ed); }
inline void EMESSAGE_END() { (*g_pengfuncsTable->pfnMessageEnd)(); }
inline void EWRITE_BYTE(int iValue) { (*g_pengfuncsTable->pfnWriteByte)(iValue); }
inline void EWRITE_CHAR(int iValue) { (*g_pengfuncsTable->pfnWriteChar)(iValue); }
inline void EWRITE_SHORT(int iValue) { (*g_pengfuncsTable->pfnWriteShort)(iValue); }
inline void EWRITE_LONG(int iValue) { (*g_pengfuncsTable->pfnWriteLong)(iValue); }
inline void EWRITE_ANGLE(float flValue) { (*g_pengfuncsTable->pfnWriteAngle)(flValue); }
inline void EWRITE_COORD(float flValue) { (*g_pengfuncsTable->pfnWriteCoord)(flValue); }
inline void EWRITE_STRING(const char *sz) { (*g_pengfuncsTable->pfnWriteString)(sz); }
inline void EWRITE_ENTITY(int iValue) { (*g_pengfuncsTable->pfnWriteEntity)(iValue); }
#ifndef _WIN32
#define _strlwr(p) for (int i = 0; p[i] != 0; i++) p[i] = tolower(p[i]);
#endif
extern enginefuncs_t* g_pengfuncsTable;
extern DLL_FUNCTIONS *g_pFunctionTable;
inline size_t indexOfEdict(edict_t* ed)
{
return ed - g_pEdicts;