Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add message natives #523

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions amxmodx/AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ binary.sources = [
'CGameConfigs.cpp',
'gameconfigs.cpp',
'CoreConfig.cpp',
'msgnatives.cpp',
'tempent.cpp',
]

if builder.target_platform == 'windows':
Expand Down
10 changes: 10 additions & 0 deletions amxmodx/amxmodx.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ extern AMX_NATIVE_INFO g_StackNatives[];
extern AMX_NATIVE_INFO g_TextParserNatives[];
extern AMX_NATIVE_INFO g_CvarNatives[];
extern AMX_NATIVE_INFO g_GameConfigNatives[];
extern AMX_NATIVE_INFO tempent_Natives[];
extern AMX_NATIVE_INFO msgnat_Natives[];

#if defined PLATFORM_WINDOWS
#define DLLOAD(path) (DLHANDLE)LoadLibrary(path)
Expand Down Expand Up @@ -234,6 +236,14 @@ extern int gmsgResetHUD;
extern int gmsgRoundTime;
extern int gmsgSayText;
extern int gmsgInitHUD;
extern int gmsgStatusIcon;
extern int gmsgTrain;
extern int gmsgGeiger;
extern int gmsgHideWeapon;
extern int gmsgCrosshair;
extern int gmsgScreenFade;
extern int gmsgScreenShake;
extern int gmsgSetFOV;

void Client_AmmoPickup(void*);
void Client_AmmoX(void*);
Expand Down
8 changes: 8 additions & 0 deletions amxmodx/emsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ int gmsgResetHUD;
int gmsgRoundTime;
int gmsgSayText;
int gmsgInitHUD;
int gmsgStatusIcon;
int gmsgTrain;
int gmsgGeiger;
int gmsgHideWeapon;
int gmsgCrosshair;
int gmsgScreenFade;
int gmsgScreenShake;
int gmsgSetFOV;

TeamIds g_teamsIds;
WeaponsVault g_weaponsData[MAX_WEAPONS];
Expand Down
30 changes: 30 additions & 0 deletions amxmodx/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,36 @@ bool inhook = false;
bool inblock = false;
enginefuncs_t *g_pEngTable = NULL;

int get_msg_destination(int index, bool reliable)
{
if(index)
return reliable ? MSG_ONE : MSG_ONE_UNRELIABLE;

return reliable ? MSG_ALL : MSG_BROADCAST;
}

int check_msg_receiver(AMX *amx, int index)
{
if(index)
{
if(index < 0 || index > gpGlobals->maxClients)
{
LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index);
return 0;
}

CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);

if(!pPlayer->ingame)
{
LogError(amx, AMX_ERR_NATIVE, "Player %d is not connected", index);
return 0;
}
}

return 1;
}

void ClearMessages()
{
for (size_t i=0; i<MAX_MESSAGES; i++)
Expand Down
2 changes: 2 additions & 0 deletions amxmodx/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ void C_MessageEnd(void);
extern RegisteredMessage msgHooks[256];
extern int msgBlocks[256];

int get_msg_destination(int index, bool reliable);
int check_msg_receiver(AMX *amx, int index);
void ClearMessages();

#endif //_MSGS_INCLUDE_H
Expand Down
8 changes: 8 additions & 0 deletions amxmodx/meta_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,14 @@ struct sUserMsg
{"RoundTime", &gmsgRoundTime, 0, false, false},
{"SayText", &gmsgSayText, 0, false, false},
{"InitHUD", &gmsgInitHUD, Client_InitHUDEnd, true, false},
{"StatusIcon", &gmsgStatusIcon, 0, false, false},
{"Train", &gmsgTrain, 0, false, false},
{"Geiger", &gmsgGeiger, 0, false, false},
{"HideWeapon", &gmsgHideWeapon, 0, false, false},
{"Crosshair", &gmsgCrosshair, 0, false, false},
{"ScreenFade", &gmsgScreenFade, 0, false, false},
{"ScreenShake", &gmsgScreenShake, 0, false, false},
{"SetFOV", &gmsgSetFOV, 0, false, false},
{0, 0, 0, false, false}
};

Expand Down
2 changes: 2 additions & 0 deletions amxmodx/modules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ int set_amxnatives(AMX* amx, char error[128])
amx_Register(amx, g_TextParserNatives, -1);
amx_Register(amx, g_CvarNatives, -1);
amx_Register(amx, g_GameConfigNatives, -1);
amx_Register(amx, tempent_Natives, -1);
amx_Register(amx, msgnat_Natives, -1);

//we're not actually gonna check these here anymore
amx->flags |= AMX_FLAG_PRENIT;
Expand Down
208 changes: 208 additions & 0 deletions amxmodx/msgnatives.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
// vim: set ts=4 sw=4 tw=99 noet:
//
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
// Copyright (C) The AMX Mod X Development Team.
//
// This software is licensed under the GNU General Public License, version 3 or higher.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license

#include <amxmodx.h>
#include <messages.h>

static cell AMX_NATIVE_CALL draw_ammo_pickup_icon(AMX *amx, cell *params)
{
enum args { arg_numargs, arg_id, arg_ammoid, arg_amount, arg_reliable };

int index = params[arg_id];

if(!check_msg_receiver(amx, index))
return 0;

MESSAGE_BEGIN(get_msg_destination(index, params[arg_reliable] != 0), gmsgAmmoPickup, nullptr, index ? TypeConversion.id_to_edict(index) : nullptr);
WRITE_BYTE(params[arg_ammoid]);
WRITE_BYTE(params[arg_amount]);
MESSAGE_END();

return 1;
}

static cell AMX_NATIVE_CALL draw_weapon_pickup_icon(AMX *amx, cell *params)
{
enum args { arg_numargs, arg_id, arg_weaponid, arg_reliable };

int index = params[arg_id];

if(!check_msg_receiver(amx, index))
return 0;

MESSAGE_BEGIN(get_msg_destination(index, params[arg_reliable] != 0), gmsgWeapPickup, nullptr, index ? TypeConversion.id_to_edict(index) : nullptr);
WRITE_BYTE(params[arg_weaponid]);
MESSAGE_END();

return 1;
}

static cell AMX_NATIVE_CALL draw_status_icon(AMX *amx, cell *params)
{
enum args { arg_numargs, arg_id, arg_sprite, arg_status, arg_r, arg_g, arg_b, arg_reliable };

int index = params[arg_id];

if(!check_msg_receiver(amx, index))
return 0;

int len;
int status = params[arg_status];
char* sprite = get_amxstring(amx, params[arg_sprite], 0, len);

MESSAGE_BEGIN(get_msg_destination(index, params[arg_reliable] != 0), gmsgStatusIcon, nullptr, index ? TypeConversion.id_to_edict(index) : nullptr);

WRITE_BYTE(status);

if(status)
{
WRITE_STRING(sprite);
WRITE_BYTE(params[arg_r]);
WRITE_BYTE(params[arg_g]);
WRITE_BYTE(params[arg_b]);
}

MESSAGE_END();

return 1;
}

static cell AMX_NATIVE_CALL draw_train_controls(AMX *amx, cell *params)
{
if(g_bmod_dod)
return 0;

enum args { arg_numargs, arg_id, arg_speed, arg_reliable };

int index = params[arg_id];

if(!check_msg_receiver(amx, index))
return 0;

MESSAGE_BEGIN(get_msg_destination(index, params[arg_reliable] != 0), gmsgTrain, nullptr, index ? TypeConversion.id_to_edict(index) : nullptr);
WRITE_BYTE(params[arg_speed]);
MESSAGE_END();

return 1;
}

static cell AMX_NATIVE_CALL send_geiger_signal(AMX *amx, cell *params)
{
if(g_bmod_dod)
return 0;

enum args { arg_numargs, arg_id, arg_distance, arg_reliable };

int index = params[arg_id];

if(!check_msg_receiver(amx, index))
return 0;

MESSAGE_BEGIN(get_msg_destination(index, params[arg_reliable] != 0), gmsgGeiger, nullptr, index ? TypeConversion.id_to_edict(index) : nullptr);
WRITE_BYTE(params[arg_distance]);
MESSAGE_END();

return 1;
}

static cell AMX_NATIVE_CALL hide_hud_elements(AMX *amx, cell *params)
{
enum args { arg_numargs, arg_id, arg_elements, arg_noadd, arg_reliable };

int index = params[arg_id];

if(!check_msg_receiver(amx, index))
return 0;

int destination = get_msg_destination(index, params[arg_reliable] != 0);
edict_t *receiver = index ? TypeConversion.id_to_edict(index) : nullptr;

MESSAGE_BEGIN(destination, gmsgHideWeapon, nullptr, receiver);
WRITE_BYTE(params[arg_elements]);
MESSAGE_END();

if(params[arg_noadd])
{
MESSAGE_BEGIN(destination, gmsgCrosshair, nullptr, receiver);
WRITE_BYTE(0);
MESSAGE_END();
}

return 1;
}

static cell AMX_NATIVE_CALL fade_user_screen(AMX *amx, cell *params)
{
enum args { arg_numargs, arg_id, arg_duration, arg_fadetime, arg_flags, arg_r, arg_g, arg_b, arg_a, arg_reliable };

int index = params[arg_id];

if(!check_msg_receiver(amx, index))
return 0;

MESSAGE_BEGIN(get_msg_destination(index, params[arg_reliable] != 0), gmsgScreenFade, nullptr, index ? TypeConversion.id_to_edict(index) : nullptr);
WRITE_SHORT(FixedUnsigned16(amx_ctof(params[arg_fadetime]), (1<<12)));
WRITE_SHORT(FixedUnsigned16(amx_ctof(params[arg_duration]), (1<<12)));
WRITE_SHORT(params[arg_flags]);
WRITE_BYTE(params[arg_r]);
WRITE_BYTE(params[arg_g]);
WRITE_BYTE(params[arg_b]);
WRITE_BYTE(params[arg_a]);
MESSAGE_END();

return 1;
}

static cell AMX_NATIVE_CALL shake_user_screen(AMX *amx, cell *params)
{
enum args { arg_numargs, arg_id, arg_amplitude, arg_duration, arg_frequency, arg_reliable };

int index = params[arg_id];

if(!check_msg_receiver(amx, index))
return 0;

MESSAGE_BEGIN(get_msg_destination(index, params[arg_reliable] != 0), gmsgScreenShake, nullptr, index ? TypeConversion.id_to_edict(index) : nullptr);
WRITE_SHORT(FixedUnsigned16(amx_ctof(params[arg_amplitude]), (1<<12)));
WRITE_SHORT(FixedUnsigned16(amx_ctof(params[arg_duration]), (1<<12)));
WRITE_SHORT(FixedUnsigned16(amx_ctof(params[arg_frequency]), (1<<12)));
MESSAGE_END();

return 1;
}

static cell AMX_NATIVE_CALL set_user_fov(AMX *amx, cell *params)
{
enum args { arg_numargs, arg_id, arg_fov, arg_reliable };

int index = params[arg_id];

if(!check_msg_receiver(amx, index))
return 0;

MESSAGE_BEGIN(get_msg_destination(index, params[arg_reliable] != 0), gmsgSetFOV, nullptr, index ? TypeConversion.id_to_edict(index) : nullptr);
WRITE_BYTE(params[arg_fov]);
MESSAGE_END();

return 1;
}

AMX_NATIVE_INFO msgnat_Natives[] =
{
{"draw_ammo_pickup_icon", draw_ammo_pickup_icon},
{"draw_weapon_pickup_icon", draw_weapon_pickup_icon},
{"draw_status_icon", draw_status_icon},
{"draw_train_controls", draw_train_controls},
{"send_geiger_signal", send_geiger_signal},
{"hide_hud_elements", hide_hud_elements},
{"fade_user_screen", fade_user_screen},
{"shake_user_screen", shake_user_screen},
{"set_user_fov", set_user_fov},
{nullptr, nullptr},
};
4 changes: 4 additions & 0 deletions amxmodx/msvc12/amxmodx_mm.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@
<ClCompile Include="..\messages.cpp" />
<ClCompile Include="..\meta_api.cpp" />
<ClCompile Include="..\modules.cpp" />
<ClCompile Include="..\msgnatives.cpp" />
<ClCompile Include="..\natives.cpp" />
<ClCompile Include="..\newmenus.cpp" />
<ClCompile Include="..\nongpl_matches.cpp" />
Expand All @@ -334,6 +335,7 @@
<AssemblerOutput Condition="'$(Configuration)|$(Platform)'=='JITRelease|Win32'">All</AssemblerOutput>
</ClCompile>
<ClCompile Include="..\strptime.cpp" />
<ClCompile Include="..\tempent.cpp" />
<ClCompile Include="..\textparse.cpp" />
<ClCompile Include="..\trie_natives.cpp" />
<ClCompile Include="..\util.cpp" />
Expand Down Expand Up @@ -461,8 +463,10 @@
<None Include="..\..\plugins\include\message_const.inc" />
<None Include="..\..\plugins\include\message_stocks.inc" />
<None Include="..\..\plugins\include\messages.inc" />
<None Include="..\..\plugins\include\msgnatives.inc" />
<None Include="..\..\plugins\include\sorting.inc" />
<None Include="..\..\plugins\include\string.inc" />
<None Include="..\..\plugins\include\tempent.inc" />
<None Include="..\..\plugins\include\time.inc" />
<None Include="..\..\plugins\include\vault.inc" />
<None Include="..\..\plugins\include\vector.inc" />
Expand Down
12 changes: 12 additions & 0 deletions amxmodx/msvc12/amxmodx_mm.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@
<ClCompile Include="..\CTextParsers.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\msgnatives.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\tempent.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\textparse.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -642,12 +648,18 @@
<None Include="..\..\plugins\include\messages.inc">
<Filter>Pawn Includes</Filter>
</None>
<None Include="..\..\plugins\include\msgnatives.inc">
<Filter>Pawn Includes</Filter>
</None>
<None Include="..\..\plugins\include\sorting.inc">
<Filter>Pawn Includes</Filter>
</None>
<None Include="..\..\plugins\include\string.inc">
<Filter>Pawn Includes</Filter>
</None>
<None Include="..\..\plugins\include\tempent.inc">
<Filter>Pawn Includes</Filter>
</None>
<None Include="..\..\plugins\include\time.inc">
<Filter>Pawn Includes</Filter>
</None>
Expand Down
Loading