Skip to content

Commit

Permalink
Rework message hook/natives
Browse files Browse the repository at this point in the history
  • Loading branch information
s1lentq committed May 26, 2024
1 parent 06743d6 commit ab14d37
Show file tree
Hide file tree
Showing 9 changed files with 860 additions and 228 deletions.
100 changes: 70 additions & 30 deletions reapi/extra/amxmodx/scripting/include/reapi_engine.inc
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,13 @@ enum MessageHook
* @param callback The name of the callback function.
* @param post Whether the callback should be invoked before or after processing the message. (optional)
*
* @note You can modify the message content using SetMessageParam native before the original function is invoked.
* Also can reading the message content using GetMessageParam native.
* @note The callback arguments have:
* msg_id - Message id
* msg_dest - Destination type (see MSG_* constants in messages_const.inc)
* msg_entity - Entity receiving the message
*
* @note You can modify the message content using SetMessageData native before the original function is invoked.
* Also can reading the message content using GetMessageData native.
*
* In the callback function, use the return values from Hookchain return types, such as HC_CONTINUE, HC_SUPERCEDE, etc.
* to control the flow of message processing.
Expand Down Expand Up @@ -318,56 +323,50 @@ native bool:EnableHookMessage(const MessageHook:handle);
native bool:DisableHookMessage(const MessageHook:handle);

/**
* Sets the parameter value for the specified index in the current game message.
* Sets the message data in the current game message.
*
* @param index The index of the parameter to set.
* @param value The value to set for the parameter.
* @param type The type of the message data that can be changed
* @param ... Additional args depending on the type of the message argument being retrieved (For more details, look at the enum MsgArgType)
*
* @return Returns true if the parameter value is successfully set, otherwise false.
* @return Returns true if the message data is successfully set, otherwise false.
*/
native bool:SetMessageParam(const number, any:...);
native bool:SetMessageData(const MsgDataType:type, any:...);

/**
* Retrieves the parameter value for the specified index in the current game message.
* Gets the message data value in the current game message
*
* @param index The index of the parameter to retrieve.
* @param ... Additional parameters depending on the type of the parameter being retrieved.
* @param type The type of message data that can be get
* @param ... Additional args depending on the type of the message argument being retrieved (For more details, look at the enum MsgArgType)
*
* @return Returns the retrieved parameter value.
* @return Returns value of argument in the current message
*/
native any:GetMessageParam(const number, any:...);
native any:GetMessageData(const MsgDataType:type, any:...);

/**
* Retrieves the type of the parameter at the specified index in the current game message.
*
* @param index The index of the parameter to retrieve the type for.
* Gets the message data original value in the current game message.
*
* @return Returns the type of the parameter, look at the enum MsgParamType
*/
native MsgParamType:GetMessageParamType(const number);

/**
* Retrieves the number of parameters in the current game message.
* @param type The type of message data that can be get
* @param ... Additional args depending on the type of the message argument being retrieved (For more details, look at the enum MsgArgType)
*
* @return Returns the number of parameters in the current game message.
* @return Returns original value of argument in the current message
*/
native GetMessageParamCount();
native any:GetMessageOrigData(const MsgDataType:type, any:...);

/**
* Retrieves the origin of the current game message.
* Retrieves the type of the argument at the specified number in the current game message.
*
* @param origin An array to store the origin coordinates of the game message.
* @param number The number of the argument to retrieve the type for.
*
* @return Returns true if the origin is successfully retrieved, otherwise false.
* @return Returns the type of the argument, look at the enum MsgArgType
*/
native bool:GetMessageOrigin(Float:origin[3]);
native MsgArgType:GetMessageArgType(const number);

/**
* Retrieves the destination of the current message.
* Retrieves the number of argument in the current game message.
*
* @return Returns the destination of the current message.
* @return Returns the number of argument in the current game message.
*/
native GetMessageDest();
native GetMessageArgsNum();

/**
* Sets the block type for the specified message ID.
Expand All @@ -387,3 +386,44 @@ native bool:SetMessageBlock(const msgid, MsgBlockType:type);
* @return Returns the block type of the specified message, look at the enum MsgBlockType
*/
native MsgBlockType:GetMessageBlock(const msgid);

/**
* Checks if the specified type of message data has been modified
*
* This native allows you to check if any part of the message data, such as its
* destination, type, origin, receiver, or any the specific argument of the message, has been modified
*
* @param type The type of the data to check for modification
* This can be one of the following:
* - MsgAny: Check if any part of the message has been modified
* - MsgDest: Check if the destination has been modified
* - MsgIndex: Check if the message ID has been modified
* - MsgOrigin: Check if the origin has been modified
* - MsgTargetId: Check if the index of the recipient client has been modified
* - MsgArg: Check if a specific argument of the message has been modified
*
* @param number The number of the argument to check for modification (used only when type is MsgDataType:MsgArg)
* Default value is -1, which means the argument number is not applicable
*
* @return Returns true if the specified data type has been modified, false otherwise
*/
native bool:IsMessageDataModified(MsgDataType:type = MsgAny, const number = -1);

/**
* Resets a specific type of message data to its original value
*
* @param type The type of the data to check for modification
* This can be one of the following:
* - MsgAny: Reset all modified message data to its original values
* - MsgDest: Reset the destination to its original value
* - MsgIndex: Reset the message ID to its original value
* - MsgOrigin: Reset the origin to its original value
* - MsgTargetId: Reset the index of the recipient client to its original value
* - MsgArg: Reset a specific argument of the message to its original value
*
* @param number The number of the argument to reset (used only when type is MsgDataType:MsgArg)
* Default value is -1, which means all arguments will be reset.
*
* @return Returns true if the modified data type was reset, otherwise false.
*/
native bool:ResetModifiedMessageData(MsgDataType:type = MsgAny, const number = -1);
81 changes: 71 additions & 10 deletions reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1323,18 +1323,79 @@ enum NetAdrVars
};

/**
* Message param types used with GetMessageParamType()
* Message argument types used with GetMessageArgType()
*/
enum MsgParamType
enum MsgArgType
{
ParamByte,
ParamChar,
ParamShort,
ParamLong,
ParamAngle,
ParamCoord,
ParamString,
ParamEntity,
ArgByte,
ArgChar,
ArgShort,
ArgLong,
ArgAngle,
ArgCoord,
ArgString,
ArgEntity,
};

/**
* Message data types used with SetMessageData()/GetMessageData()
* HasModifiedMessageData()/ResetModifiedMessageData()
*/
enum MsgDataType
{
/*
* Description: Any part of the message
*/
MsgAny,

/*
* Description: The destination of the message
* Return type: integer
* Get params: new dest = GetMessageData(MsgDest);
* Set params: SetMessageData(MsgDest, MSG_ALL);
*/
MsgDest,

/*
* Description: The index of the message
* Return type: integer
* Get params: new msg_id = GetMessageData(MsgMsgId);
* Set params: SetMessageData(MsgMsgId, const msg_id);
*/
MsgMsgId,

/*
* Description: The origin of the message
* Return type: float [3]
* Get params: GetMessageData(MsgOrigin, Float:dstVector[3]);
* Set params: SetMessageData(MsgOrigin, Float:srcVector[3]);
*/
MsgOrigin,

/*
* Description: The index of the recipient client
* Return type: integer
* Get params: new targetId = GetMessageData(MsgTargetId);
* Set params: SetMessageData(MsgTargetId, const targetId); (acceptable indexes 0-32, 0 index also as -1 means NULLENT)
*/
MsgTargetId,

/*
* Description: The arguments of the message
*
* Arg type: string (MSG_ARG_String)
* Get params: bool:GetMessageData(MsgArg, const argnumber, value[], const maxlen);
* Set params: bool:SetMessageData(MsgArg, const argnumber, const value[]);
*
* Arg type: float (MSG_ARG_Angle, MSG_ARG_Coord)
* Get params: Float:GetMessageData(MsgArg, const argnumber, &Float:value = 0.0);
* Set params: bool:SetMessageData(MsgArg, const argnumber, const Float:value);
*
* Arg type: integer (MSG_ARG_Byte, MSG_ARG_Char, MSG_ARG_Short, MSG_ARG_Long, MSG_ARG_Entity)
* Get params: GetMessageData(MsgArg, const argnumber);
* Set params: bool:SetMessageData(MsgArg, const argnumber, const value);
*/
MsgArg
};

/**
Expand Down
Loading

0 comments on commit ab14d37

Please sign in to comment.