Skip to content

Commit

Permalink
fixes for compilation and mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mistrick committed Jun 14, 2018
1 parent ed4bc66 commit 476da95
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 37 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ SPMod is licensed under the General Public License version 3 - see the [LICENSE]

## Acknowledgments

The SPMod uses code from the following libraries:
The SPMod uses code from the following libraries, projects:
- [Printf Implementation](https://github.com/mpaland/printf), The MIT License (MIT)
- [AMX Mod X](https://github.com/alliedmodders/amxmodx), GNU GPLv3
14 changes: 7 additions & 7 deletions scripts/include/messages.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@
#define _messages_included

/**
* Destination types for message_begin()
* Destination types for MessageBegin()
*/
#define MSG_BROADCAST 0 // Unreliable to all
#define MSG_ONE 1 // Reliable to one (msg_entity)
#define MSG_ALL 2 // Reliable to all
#define MSG_INIT 3 // Write to the init string
#define MSG_BROADCAST 0 // Unreliable to all
#define MSG_ONE 1 // Reliable to one (msg_entity)
#define MSG_ALL 2 // Reliable to all
#define MSG_INIT 3 // Write to the init string
#define MSG_PVS 4 // Ents in PVS of org
#define MSG_PAS 5 // Ents in PAS of org
#define MSG_PVS_R 6 // Reliable to PVS
#define MSG_PAS_R 7 // Reliable to PAS
#define MSG_ONE_UNRELIABLE 8 // Send to one client, but don't put in reliable stream, put in unreliable datagram (could be dropped)
#define MSG_SPEC 9 // Sends to all spectator proxies
#define MSG_SPEC 9 // Sends to all spectator proxies

native int GetUserMsgId(const char[] msg_name);

native void GetUserMsgName(int msgid, char[] str, int len);

native void MessageBegin(int dest, int msgid, const int origin[3] = {0,0,0}, int player = 0);

native void MessageBegin(int dest, int msgid, const float origin[3] = {0,0,0}, int player = 0);
native void MessageBeginF(int dest, int msgid, const float origin[3] = {0.0,0.0,0.0}, int player = 0);

native void MessageEnd();

Expand Down
72 changes: 43 additions & 29 deletions src/MessageNatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,24 @@
#include "spmod.hpp"

// int GetUserMsgId(const char[] msgname);
static cell_t GetUserMsgId(SourcePawn::IPluginContext *ctx, const cell_t *params) /* 1 param */
static cell_t GetUserMsgId(SourcePawn::IPluginContext *ctx,
const cell_t *params)
{
enum { arg_msgname = 1 };

char *string;
ctx->LocalToString(params[arg_msgname], &string);

return GET_USER_MSG_ID(PLID, string, NULL);
return GET_USER_MSG_ID(PLID, string, nullptr);
}

// void GetUserMsgName(int msgid, char[] str, int len) = 3 params
static cell_t GetUserMsgName(SourcePawn::IPluginContext *ctx, const cell_t *params)
static cell_t GetUserMsgName(SourcePawn::IPluginContext *ctx,
const cell_t *params)
{
enum { arg_msg = 1, arg_str, arg_len };

const char* string = GET_USER_MSG_NAME(PLID, params[arg_msg], NULL);
const char* string = GET_USER_MSG_NAME(PLID, params[arg_msg], nullptr);
if (string)
{
ctx->StringToLocal(params[arg_str], params[arg_len], string);
Expand All @@ -43,18 +45,19 @@ static cell_t GetUserMsgName(SourcePawn::IPluginContext *ctx, const cell_t *para
return 0;
}

static cell_t MessageBegin_(SourcePawn::IPluginContext *ctx, const cell_t *params, bool useFloat) /* 4 param */
static cell_t MessageBegin_(SourcePawn::IPluginContext *ctx,
const cell_t *params, bool useFloat)
{
enum { arg_dest = 1, arg_msg_type, arg_origin, arg_player };

int numparam = *params / sizeof(cell_t);
int numparam = *params;
float vecOrigin[3];
cell_t *cpOrigin;

if (params[arg_msg_type] < 1 || ((params[arg_msg_type] > 63) // maximal number of engine messages
&& !GET_USER_MSG_NAME(PLID, params[2], NULL)))
&& !GET_USER_MSG_NAME(PLID, params[2], nullptr)))
{
// LogError(amx, AMX_ERR_NATIVE, "Plugin called message_begin with an invalid message id (%d).", params[2]);
ctx->ReportError("Plugin called message_begin with an invalid message id (%d).", params[arg_msg_type]);
return 0;
}

Expand All @@ -64,13 +67,13 @@ static cell_t MessageBegin_(SourcePawn::IPluginContext *ctx, const cell_t *param
case MSG_ALL:
case MSG_SPEC:
case MSG_INIT:
MESSAGE_BEGIN(params[arg_dest], params[arg_msg_type], NULL);
MESSAGE_BEGIN(params[arg_dest], params[arg_msg_type], nullptr);
break;
case MSG_PVS: case MSG_PAS:
case MSG_PVS_R: case MSG_PAS_R:
if (numparam < 3)
{
// LogError(amx, AMX_ERR_NATIVE, "Invalid number of parameters passed");
ctx->ReportError("Invalid number of parameters passed");
return 0;
}

Expand All @@ -96,103 +99,114 @@ static cell_t MessageBegin_(SourcePawn::IPluginContext *ctx, const cell_t *param
case MSG_ONE:
if (numparam < 4)
{
// LogError(amx, AMX_ERR_NATIVE, "Invalid number of parameters passed");
ctx->ReportError("Invalid number of parameters passed");
return 0;
}

MESSAGE_BEGIN(params[arg_dest], params[arg_msg_type], NULL, INDEXENT(params[arg_player]));
MESSAGE_BEGIN(params[arg_dest], params[arg_msg_type], nullptr, INDEXENT(params[arg_player]));
break;
}

return 1;
}

// native void MessageBegin(int dest, int msgid, const int origin[3] = {0,0,0}, int player = 0);
static cell_t MessageBegin(SourcePawn::IPluginContext *ctx, const cell_t *params)
static cell_t MessageBegin(SourcePawn::IPluginContext *ctx,
const cell_t *params)
{
MessageBegin_(ctx, params, false);
return 1;
return MessageBegin_(ctx, params, false);
}

// native void MessageBeginF(int dest, int msgid, const float origin[3] = {0.0,0.0,0.0}, int player = 0);
static cell_t MessageBeginF(SourcePawn::IPluginContext *ctx, const cell_t *params)
static cell_t MessageBeginF(SourcePawn::IPluginContext *ctx,
const cell_t *params)
{
MessageBegin_(ctx, params, true);
return 1;
return MessageBegin_(ctx, params, true);
}

// native void MessageEnd();
static cell_t MessageEnd(SourcePawn::IPluginContext *ctx, const cell_t *params)
static cell_t MessageEnd([[maybe_unused]] SourcePawn::IPluginContext *ctx,
[[maybe_unused]] const cell_t *params)
{
MESSAGE_END();
return 1;
}

// native void WriteByte(int value);
static cell_t WriteByte(SourcePawn::IPluginContext *ctx, const cell_t *params)
static cell_t WriteByte([[maybe_unused]] SourcePawn::IPluginContext *ctx,
const cell_t *params)
{
enum { arg_value = 1 };
WRITE_BYTE(params[arg_value]);
return 1;
}
// native void WriteChar(char value);
static cell_t WriteChar(SourcePawn::IPluginContext *ctx, const cell_t *params)
static cell_t WriteChar([[maybe_unused]] SourcePawn::IPluginContext *ctx,
const cell_t *params)
{
enum { arg_value = 1 };
WRITE_CHAR(params[arg_value]);
return 1;
}
// native void WriteShort(int value);
static cell_t WriteShort(SourcePawn::IPluginContext *ctx, const cell_t *params)
static cell_t WriteShort([[maybe_unused]] SourcePawn::IPluginContext *ctx,
const cell_t *params)
{
enum { arg_value = 1 };
WRITE_SHORT(params[arg_value]);
return 1;
}
// native void WriteLong(int value);
static cell_t WriteLong(SourcePawn::IPluginContext *ctx, const cell_t *params)
static cell_t WriteLong([[maybe_unused]] SourcePawn::IPluginContext *ctx,
const cell_t *params)
{
enum { arg_value = 1 };
WRITE_LONG(params[arg_value]);
return 1;
}
// native void WriteEntity(int value);
static cell_t WriteEntity(SourcePawn::IPluginContext *ctx, const cell_t *params)
static cell_t WriteEntity([[maybe_unused]] SourcePawn::IPluginContext *ctx,
const cell_t *params)
{
enum { arg_value = 1 };
WRITE_ENTITY(params[arg_value]);
return 1;
}
// native void WriteAngle(int value);
static cell_t WriteAngle(SourcePawn::IPluginContext *ctx, const cell_t *params)
static cell_t WriteAngle([[maybe_unused]] SourcePawn::IPluginContext *ctx,
const cell_t *params)
{
enum { arg_value = 1 };
WRITE_ANGLE(static_cast<float>(params[arg_value]));
return 1;
}
// native void WriteAngleF(float value);
static cell_t WriteAngleF(SourcePawn::IPluginContext *ctx, const cell_t *params)
static cell_t WriteAngleF([[maybe_unused]] SourcePawn::IPluginContext *ctx,
const cell_t *params)
{
enum { arg_value = 1 };
WRITE_ANGLE(sp_ctof(params[arg_value]));
return 1;
}
// native void WriteCoord(int value);
static cell_t WriteCoord(SourcePawn::IPluginContext *ctx, const cell_t *params)
static cell_t WriteCoord([[maybe_unused]] SourcePawn::IPluginContext *ctx,
const cell_t *params)
{
enum { arg_value = 1 };
WRITE_COORD(static_cast<float>(params[arg_value]));
return 1;
}
// native void WriteCoordF(float value);
static cell_t WriteCoordF(SourcePawn::IPluginContext *ctx, const cell_t *params)
static cell_t WriteCoordF([[maybe_unused]] SourcePawn::IPluginContext *ctx,
const cell_t *params)
{
enum { arg_value = 1 };
WRITE_COORD(sp_ctof(params[arg_value]));
return 1;
}
// native void WriteString(char[] value);
static cell_t WriteString(SourcePawn::IPluginContext *ctx, const cell_t *params)
static cell_t WriteString(SourcePawn::IPluginContext *ctx,
const cell_t *params)
{
enum { arg_value = 1 };
char *string;
Expand Down

0 comments on commit 476da95

Please sign in to comment.