diff --git a/core/smn_protobuf.cpp b/core/smn_protobuf.cpp index 2188ed35..2485aabe 100644 --- a/core/smn_protobuf.cpp +++ b/core/smn_protobuf.cpp @@ -811,6 +811,38 @@ REGISTER_NATIVES(protobufnatives) {"PbReadMessage", smn_PbReadMessage}, {"PbReadRepeatedMessage", smn_PbReadRepeatedMessage}, {"PbAddMessage", smn_PbAddMessage}, + + // Transitional syntax. + {"Protobuf.ReadInt", smn_PbReadInt}, + {"Protobuf.ReadFloat", smn_PbReadFloat}, + {"Protobuf.ReadBool", smn_PbReadBool}, + {"Protobuf.ReadString", smn_PbReadString}, + {"Protobuf.ReadColor", smn_PbReadColor}, + {"Protobuf.ReadAngle", smn_PbReadAngle}, + {"Protobuf.ReadVector", smn_PbReadVector}, + {"Protobuf.ReadVector2D", smn_PbReadVector2D}, + {"Protobuf.GetRepeatedFieldCount", smn_PbGetRepeatedFieldCount}, + {"Protobuf.SetInt", smn_PbSetInt}, + {"Protobuf.SetFloat", smn_PbSetFloat}, + {"Protobuf.SetBool", smn_PbSetBool}, + {"Protobuf.SetString", smn_PbSetString}, + {"Protobuf.SetColor", smn_PbSetColor}, + {"Protobuf.SetAngle", smn_PbSetAngle}, + {"Protobuf.SetVector", smn_PbSetVector}, + {"Protobuf.SetVector2D", smn_PbSetVector2D}, + {"Protobuf.AddInt", smn_PbAddInt}, + {"Protobuf.AddFloat", smn_PbAddFloat}, + {"Protobuf.AddBool", smn_PbAddBool}, + {"Protobuf.AddString", smn_PbAddString}, + {"Protobuf.AddColor", smn_PbAddColor}, + {"Protobuf.AddAngle", smn_PbAddAngle}, + {"Protobuf.AddVector", smn_PbAddVector}, + {"Protobuf.AddVector2D", smn_PbAddVector2D}, + {"Protobuf.RemoveRepeatedFieldValue", smn_PbRemoveRepeatedFieldValue}, + {"Protobuf.ReadMessage", smn_PbReadMessage}, + {"Protobuf.ReadRepeatedMessage", smn_PbReadRepeatedMessage}, + {"Protobuf.AddMessage", smn_PbAddMessage}, + {NULL, NULL} }; @@ -820,7 +852,7 @@ REGISTER_NATIVES(protobufnatives) @@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@ @@@@@@@@@@@@@ - @@@@@@@@ @@@@@@@@@@@@@ + @@@@@@@@ o @@@@@@@@@@@@@ @@@@@@ @@@@@@@@@@@@@@@ 0000 @@@@@@@@@@@@@@@@@@@@@ 000000000 @@@@@@@@@@@@@@@@@@@ diff --git a/plugins/funcommands/blind.sp b/plugins/funcommands/blind.sp index a7def89d..f0495549 100644 --- a/plugins/funcommands/blind.sp +++ b/plugins/funcommands/blind.sp @@ -53,13 +53,14 @@ PerformBlind(client, target, amount) new color[4] = { 0, 0, 0, 0 }; color[3] = amount; - new Handle:message = StartMessageEx(g_FadeUserMsgId, targets, 1); + Handle message = StartMessageEx(g_FadeUserMsgId, targets, 1); if (GetUserMessageType() == UM_Protobuf) { - PbSetInt(message, "duration", duration); - PbSetInt(message, "hold_time", holdtime); - PbSetInt(message, "flags", flags); - PbSetColor(message, "clr", color); + Protobuf pb = UserMessageToProtobuf(message); + pb.SetInt("duration", duration); + pb.SetInt("hold_time", holdtime); + pb.SetInt("flags", flags); + pb.SetColor("clr", color); } else { diff --git a/plugins/funcommands/drug.sp b/plugins/funcommands/drug.sp index 5b489663..1bd0139d 100644 --- a/plugins/funcommands/drug.sp +++ b/plugins/funcommands/drug.sp @@ -58,14 +58,14 @@ KillDrug(client) new flags = (0x0001 | 0x0010); new color[4] = { 0, 0, 0, 0 }; - new Handle:message = StartMessageEx(g_FadeUserMsgId, clients, 1); - + Handle message = StartMessageEx(g_FadeUserMsgId, clients, 1); if (GetUserMessageType() == UM_Protobuf) { - PbSetInt(message, "duration", duration); - PbSetInt(message, "hold_time", holdtime); - PbSetInt(message, "flags", flags); - PbSetColor(message, "clr", color); + Protobuf pb = UserMessageToProtobuf(message); + pb.SetInt("duration", duration); + pb.SetInt("hold_time", holdtime); + pb.SetInt("flags", flags); + pb.SetColor("clr", color); } else { @@ -177,14 +177,14 @@ public Action:Timer_Drug(Handle:timer, any:client) color[1] = GetRandomInt(0,255); color[2] = GetRandomInt(0,255); - new Handle:message = StartMessageEx(g_FadeUserMsgId, clients, 1); - + Handle message = StartMessageEx(g_FadeUserMsgId, clients, 1); if (GetUserMessageType() == UM_Protobuf) { - PbSetInt(message, "duration", duration); - PbSetInt(message, "hold_time", holdtime); - PbSetInt(message, "flags", flags); - PbSetColor(message, "clr", color); + Protobuf pb = UserMessageToProtobuf(message); + pb.SetInt("duration", duration); + pb.SetInt("hold_time", holdtime); + pb.SetInt("flags", flags); + pb.SetColor("clr", color); } else { diff --git a/plugins/include/core.inc b/plugins/include/core.inc index 00382b10..f13fb032 100644 --- a/plugins/include/core.inc +++ b/plugins/include/core.inc @@ -231,6 +231,36 @@ public __ext_core_SetNTVOptional() MarkNativeAsOptional("PbReadMessage"); MarkNativeAsOptional("PbReadRepeatedMessage"); MarkNativeAsOptional("PbAddMessage"); + + MarkNativeAsOptional("Protobuf.ReadInt"); + MarkNativeAsOptional("Protobuf.ReadFloat"); + MarkNativeAsOptional("Protobuf.ReadBool"); + MarkNativeAsOptional("Protobuf.ReadString"); + MarkNativeAsOptional("Protobuf.ReadColor"); + MarkNativeAsOptional("Protobuf.ReadAngle"); + MarkNativeAsOptional("Protobuf.ReadVector"); + MarkNativeAsOptional("Protobuf.ReadVector2D"); + MarkNativeAsOptional("Protobuf.GetRepeatedFieldCount"); + MarkNativeAsOptional("Protobuf.SetInt"); + MarkNativeAsOptional("Protobuf.SetFloat"); + MarkNativeAsOptional("Protobuf.SetBool"); + MarkNativeAsOptional("Protobuf.SetString"); + MarkNativeAsOptional("Protobuf.SetColor"); + MarkNativeAsOptional("Protobuf.SetAngle"); + MarkNativeAsOptional("Protobuf.SetVector"); + MarkNativeAsOptional("Protobuf.SetVector2D"); + MarkNativeAsOptional("Protobuf.AddInt"); + MarkNativeAsOptional("Protobuf.AddFloat"); + MarkNativeAsOptional("Protobuf.AddBool"); + MarkNativeAsOptional("Protobuf.AddString"); + MarkNativeAsOptional("Protobuf.AddColor"); + MarkNativeAsOptional("Protobuf.AddAngle"); + MarkNativeAsOptional("Protobuf.AddVector"); + MarkNativeAsOptional("Protobuf.AddVector2D"); + MarkNativeAsOptional("Protobuf.RemoveRepeatedFieldValue"); + MarkNativeAsOptional("Protobuf.ReadMessage"); + MarkNativeAsOptional("Protobuf.ReadRepeatedMessage"); + MarkNativeAsOptional("Protobuf.AddMessage"); VerifyCoreVersion(); } diff --git a/plugins/include/protobuf.inc b/plugins/include/protobuf.inc index 976ca88a..1d264b31 100644 --- a/plugins/include/protobuf.inc +++ b/plugins/include/protobuf.inc @@ -1,5 +1,5 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 tw=99 noet : * ============================================================================= * SourceMod (C)2013 AlliedModders LLC. All rights reserved. * ============================================================================= @@ -37,6 +37,232 @@ #define PB_FIELD_NOT_REPEATED -1 +methodmap Protobuf < Handle +{ + // Reads an int32, uint32, sint32, fixed32, sfixed32, or enum value from a protobuf message. + // + // @param field Field name. + // @param index Index into repeated field. + // @return Integer value read. + // @error Non-existent field, or incorrect field type. + public native int ReadInt(const char[] field, int index = PB_FIELD_NOT_REPEATED); + + // Reads a float or downcasted double from a protobuf message. + // + // @param field Field name. + // @param index Index into repeated field. + // @return Float value read. + // @error Non-existent field, or incorrect field type. + public native float ReadFloat(const char[] field, int index = PB_FIELD_NOT_REPEATED); + + // Reads a bool from a protobuf message. + // + // @param field Field name. + // @param index Index into repeated field. + // @return Boolean value read. + // @error Non-existent field, or incorrect field type. + public native bool ReadBool(const char[] field, int index = PB_FIELD_NOT_REPEATED); + + // Reads a string from a protobuf message. + // + // @param field Field name. + // @param buffer Destination string buffer. + // @param maxlength Maximum length of output string buffer. + // @param index Index into repeated field. + // @error Non-existent field, or incorrect field type. + public native void ReadString(const char[] field, char[] buffer, int maxlength, int index = PB_FIELD_NOT_REPEATED); + + // Reads an RGBA color value from a protobuf message. + // + // @param field Field name. + // @param buffer Destination color buffer. + // @param index Index into repeated field. + // @error Non-existent field, or incorrect field type. + public native void ReadColor(const char[] field, int buffer[4], int index = PB_FIELD_NOT_REPEATED); + + // Reads an XYZ angle value from a protobuf message. + // + // @param field Field name. + // @param buffer Destination angle buffer. + // @param index Index into repeated field. + // @error Non-existent field, or incorrect field type. + public native void ReadAngle(const char[] field, float buffer[3], int index = PB_FIELD_NOT_REPEATED); + + // Reads an XYZ vector value from a protobuf message. + // + // @param pb protobuf handle. + // @param field Field name. + // @param buffer Destination vector buffer. + // @param index Index into repeated field. + // @error Non-existent field, or incorrect field type. + public native void ReadVector(const char[] field, float buffer[3], int index = PB_FIELD_NOT_REPEATED); + + // Reads an XY vector value from a protobuf message. + // + // @param field Field name. + // @param buffer Destination vector buffer. + // @param index Index into repeated field. + // @error Non-existent field, or incorrect field type. + public native void ReadVector2D(const char[] field, float buffer[2], int index = PB_FIELD_NOT_REPEATED); + + // Gets the number of elements in a repeated field of a protobuf message. + // + // @param field Field name. + // @return Number of elements in the field. + // @error Non-existent field, or incorrect field type. + public native int GetRepeatedFieldCount(const char[] field); + + // Sets an int32, uint32, sint32, fixed32, sfixed32, or enum value on a protobuf message. + // + // @param field Field name. + // @param value Integer value to set. + // @param index Index into repeated field. + // @error Non-existent field, or incorrect field type. + public native int SetInt(const char[] field, int value, int index = PB_FIELD_NOT_REPEATED); + + // Sets a float or double on a protobuf message. + // + // @param field Field name. + // @param value Float value to set. + // @param index Index into repeated field. + // @error Non-existent field, or incorrect field type. + public native void SetFloat(const char[] field, float value, int index = PB_FIELD_NOT_REPEATED); + + // Sets a bool on a protobuf message. + // + // @param field Field name. + // @param value Boolean value to set. + // @param index Index into repeated field. + // @error Non-existent field, or incorrect field type. + public native void SetBool(const char[] field, bool value, int index = PB_FIELD_NOT_REPEATED); + + // Sets a string on a protobuf message. + // + // @param field Field name. + // @param value String value to set. + // @param index Index into repeated field. + // @error Non-existent field, or incorrect field type. + public native void SetString(const char[] field, const char[] value, int index = PB_FIELD_NOT_REPEATED); + + // Sets an RGBA color on a protobuf message. + // + // @param field Field name. + // @param color Color value to set. + // @param index Index into repeated field. + // @error Non-existent field, or incorrect field type. + public native void SetColor(const char[] field, const int color[4], int index = PB_FIELD_NOT_REPEATED); + + // Sets an XYZ angle on a protobuf message. + // + // @param field Field name. + // @param angle Angle value to set. + // @param index Index into repeated field. + // @error Non-existent field, or incorrect field type. + public native void SetAngle(const char[] field, const float angle[3], int index = PB_FIELD_NOT_REPEATED); + + // Sets an XYZ vector on a protobuf message. + // + // @param field Field name. + // @param vec Vector value to set. + // @param index Index into repeated field. + // @error Non-existent field, or incorrect field type. + public native void SetVector(const char[] field, const float vec[3], int index = PB_FIELD_NOT_REPEATED); + + // Sets an XY vector on a protobuf message. + // + // @param field Field name. + // @param vec Vector value to set. + // @param index Index into repeated field. + // @error Non-existent field, or incorrect field type. + public native void SetVector2D(const char[] field, const float vec[2], int index = PB_FIELD_NOT_REPEATED); + + // Add an int32, uint32, sint32, fixed32, sfixed32, or enum value to a protobuf message repeated field. + // + // @param field Field name. + // @param value Integer value to add. + // @error Non-existent field, or incorrect field type. + public native void AddInt(const char[] field, int value); + + // Add a float or double to a protobuf message repeated field. + // + // @param field Field name. + // @param value Float value to add. + // @error Non-existent field, or incorrect field type. + public native void AddFloat(const char[] field, float value); + + // Add a bool to a protobuf message repeated field. + // + // @param field Field name. + // @param value Boolean value to add. + // @error Non-existent field, or incorrect field type. + public native void AddBool(const char[] field, bool value); + + // Add a string to a protobuf message repeated field. + // + // @param field Field name. + // @param value String value to add. + // @error Non-existent field, or incorrect field type. + public native void AddString(const char[] field, const char[] value); + + // Add an RGBA color to a protobuf message repeated field. + // + // @param field Field name. + // @param color Color value to add. + // @error Non-existent field, or incorrect field type. + public native void AddColor(const char[] field, const int color[4]); + + // Add an XYZ angle to a protobuf message repeated field. + // + // @param field Field name. + // @param angle Angle value to add. + // @error Non-existent field, or incorrect field type. + public native void AddAngle(const char[] field, const float angle[3]); + + // Add an XYZ vector to a protobuf message repeated field. + // + // @param field Field name. + // @param vec Vector value to add. + // @error Non-existent field, or incorrect field type. + public native void AddVector(const char[] field, const float vec[3]); + + // Add an XY vector to a protobuf message repeated field. + // + // @param field Field name. + // @param vec Vector value to add. + // @error Non-existent field, or incorrect field type. + public native void AddVector2D(const char[] field, const float vec[2]); + + // Removes a value by index from a protobuf message repeated field. + // + // @param field Field name. + // @param index Index into repeated field. + // @error Non-existent field, or incorrect field type. + public native void RemoveRepeatedFieldValue(const char[] field, int index); + + // Retrieve a handle to an embedded protobuf message in a protobuf message. + // + // @param field Field name. + // @return Protobuf handle to embedded message. + // @error Non-existent field, or incorrect field type. + public native Protobuf ReadMessage(const char[] field); + + // Retrieve a handle to an embedded protobuf message in a protobuf message + // repeated field. + // + // @param field Field name. + // @param index Index in the repeated field. + // @return Protobuf handle to embedded message. + // @error Non-existent field, or incorrect field type. + public native Protobuf ReadRepeatedMessage(const char[] field, int index); + + // Adds an embedded protobuf message to a protobuf message repeated field. + // + // @param field Field name. + // @return Protobuf handle to added, embedded message. + // @error Non-existent field, or incorrect field type. + public native Protobuf AddMessage(const char[] field); +}; + /** * Reads an int32, uint32, sint32, fixed32, sfixed32, or enum value from a protobuf message. * @@ -46,7 +272,7 @@ * @return Integer value read. * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbReadInt(Handle:pb, const String:field[], index=PB_FIELD_NOT_REPEATED); +native int PbReadInt(Handle pb, const char[] field, int index = PB_FIELD_NOT_REPEATED); /** * Reads a float or downcasted double from a protobuf message. @@ -57,7 +283,7 @@ native PbReadInt(Handle:pb, const String:field[], index=PB_FIELD_NOT_REPEATED); * @return Float value read. * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native Float:PbReadFloat(Handle:pb, const String:field[], index=PB_FIELD_NOT_REPEATED); +native float PbReadFloat(Handle pb, const char[] field, int index = PB_FIELD_NOT_REPEATED); /** * Reads a bool from a protobuf message. @@ -68,7 +294,7 @@ native Float:PbReadFloat(Handle:pb, const String:field[], index=PB_FIELD_NOT_REP * @return Boolean value read. * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native bool:PbReadBool(Handle:pb, const String:field[], index=PB_FIELD_NOT_REPEATED); +native bool PbReadBool(Handle pb, const char[] field, int index = PB_FIELD_NOT_REPEATED); /** * Reads a string from a protobuf message. @@ -78,10 +304,9 @@ native bool:PbReadBool(Handle:pb, const String:field[], index=PB_FIELD_NOT_REPEA * @param buffer Destination string buffer. * @param maxlength Maximum length of output string buffer. * @param index Index into repeated field. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbReadString(Handle:pb, const String:field[], String:buffer[], maxlength, index=PB_FIELD_NOT_REPEATED); +native void PbReadString(Handle pb, const char[] field, String:buffer[], maxlength, int index = PB_FIELD_NOT_REPEATED); /** * Reads an RGBA color value from a protobuf message. @@ -90,10 +315,9 @@ native PbReadString(Handle:pb, const String:field[], String:buffer[], maxlength, * @param field Field name. * @param buffer Destination color buffer. * @param index Index into repeated field. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbReadColor(Handle:pb, const String:field[], buffer[4], index=PB_FIELD_NOT_REPEATED); +native void PbReadColor(Handle pb, const char[] field, buffer[4], int index = PB_FIELD_NOT_REPEATED); /** * Reads an XYZ angle value from a protobuf message. @@ -102,10 +326,9 @@ native PbReadColor(Handle:pb, const String:field[], buffer[4], index=PB_FIELD_NO * @param field Field name. * @param buffer Destination angle buffer. * @param index Index into repeated field. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbReadAngle(Handle:pb, const String:field[], Float:buffer[3], index=PB_FIELD_NOT_REPEATED); +native void PbReadAngle(Handle pb, const char[] field, float buffer[3], int index = PB_FIELD_NOT_REPEATED); /** * Reads an XYZ vector value from a protobuf message. @@ -114,10 +337,9 @@ native PbReadAngle(Handle:pb, const String:field[], Float:buffer[3], index=PB_FI * @param field Field name. * @param buffer Destination vector buffer. * @param index Index into repeated field. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbReadVector(Handle:pb, const String:field[], Float:buffer[3], index=PB_FIELD_NOT_REPEATED); +native void PbReadVector(Handle pb, const char[] field, float buffer[3], int index = PB_FIELD_NOT_REPEATED); /** * Reads an XY vector value from a protobuf message. @@ -126,10 +348,9 @@ native PbReadVector(Handle:pb, const String:field[], Float:buffer[3], index=PB_F * @param field Field name. * @param buffer Destination vector buffer. * @param index Index into repeated field. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbReadVector2D(Handle:pb, const String:field[], Float:buffer[2], index=PB_FIELD_NOT_REPEATED); +native void PbReadVector2D(Handle pb, const char[] field, float buffer[2], int index = PB_FIELD_NOT_REPEATED); /** * Gets the number of elements in a repeated field of a protobuf message. @@ -139,7 +360,7 @@ native PbReadVector2D(Handle:pb, const String:field[], Float:buffer[2], index=PB * @return Number of elements in the field. * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbGetRepeatedFieldCount(Handle:pb, const String:field[]); +native int PbGetRepeatedFieldCount(Handle pb, const char[] field); /** * Sets an int32, uint32, sint32, fixed32, sfixed32, or enum value on a protobuf message. @@ -148,10 +369,9 @@ native PbGetRepeatedFieldCount(Handle:pb, const String:field[]); * @param field Field name. * @param value Integer value to set. * @param index Index into repeated field. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbSetInt(Handle:pb, const String:field[], value, index=PB_FIELD_NOT_REPEATED); +native void PbSetInt(Handle pb, const char[] field, int value, int index = PB_FIELD_NOT_REPEATED); /** * Sets a float or double on a protobuf message. @@ -160,10 +380,9 @@ native PbSetInt(Handle:pb, const String:field[], value, index=PB_FIELD_NOT_REPEA * @param field Field name. * @param value Float value to set. * @param index Index into repeated field. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbSetFloat(Handle:pb, const String:field[], Float:value, index=PB_FIELD_NOT_REPEATED); +native void PbSetFloat(Handle pb, const char[] field, float value, int index = PB_FIELD_NOT_REPEATED); /** * Sets a bool on a protobuf message. @@ -172,10 +391,9 @@ native PbSetFloat(Handle:pb, const String:field[], Float:value, index=PB_FIELD_N * @param field Field name. * @param value Boolean value to set. * @param index Index into repeated field. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbSetBool(Handle:pb, const String:field[], bool:value, index=PB_FIELD_NOT_REPEATED); +native void PbSetBool(Handle pb, const char[] field, bool value, int index = PB_FIELD_NOT_REPEATED); /** * Sets a string on a protobuf message. @@ -184,10 +402,9 @@ native PbSetBool(Handle:pb, const String:field[], bool:value, index=PB_FIELD_NOT * @param field Field name. * @param value String value to set. * @param index Index into repeated field. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbSetString(Handle:pb, const String:field[], const String:value[], index=PB_FIELD_NOT_REPEATED); +native void PbSetString(Handle pb, const char[] field, const char[] value, int index = PB_FIELD_NOT_REPEATED); /** * Sets an RGBA color on a protobuf message. @@ -196,10 +413,9 @@ native PbSetString(Handle:pb, const String:field[], const String:value[], index= * @param field Field name. * @param color Color value to set. * @param index Index into repeated field. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbSetColor(Handle:pb, const String:field[], const color[4], index=PB_FIELD_NOT_REPEATED); +native void PbSetColor(Handle pb, const char[] field, const int color[4], int index = PB_FIELD_NOT_REPEATED); /** * Sets an XYZ angle on a protobuf message. @@ -208,10 +424,9 @@ native PbSetColor(Handle:pb, const String:field[], const color[4], index=PB_FIEL * @param field Field name. * @param angle Angle value to set. * @param index Index into repeated field. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbSetAngle(Handle:pb, const String:field[], const Float:angle[3], index=PB_FIELD_NOT_REPEATED); +native void PbSetAngle(Handle pb, const char[] field, const float angle[3], int index = PB_FIELD_NOT_REPEATED); /** * Sets an XYZ vector on a protobuf message. @@ -220,10 +435,9 @@ native PbSetAngle(Handle:pb, const String:field[], const Float:angle[3], index=P * @param field Field name. * @param vec Vector value to set. * @param index Index into repeated field. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbSetVector(Handle:pb, const String:field[], const Float:vec[3], index=PB_FIELD_NOT_REPEATED); +native void PbSetVector(Handle pb, const char[] field, const float vec[3], int index = PB_FIELD_NOT_REPEATED); /** * Sets an XY vector on a protobuf message. @@ -232,10 +446,9 @@ native PbSetVector(Handle:pb, const String:field[], const Float:vec[3], index=PB * @param field Field name. * @param vec Vector value to set. * @param index Index into repeated field. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbSetVector2D(Handle:pb, const String:field[], const Float:vec[2], index=PB_FIELD_NOT_REPEATED); +native void PbSetVector2D(Handle pb, const char[] field, const float vec[2], int index = PB_FIELD_NOT_REPEATED); /** * Add an int32, uint32, sint32, fixed32, sfixed32, or enum value to a protobuf message repeated field. @@ -243,10 +456,9 @@ native PbSetVector2D(Handle:pb, const String:field[], const Float:vec[2], index= * @param pb protobuf handle. * @param field Field name. * @param value Integer value to add. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbAddInt(Handle:pb, const String:field[], value); +native void PbAddInt(Handle pb, const char[] field, int value); /** * Add a float or double to a protobuf message repeated field. @@ -254,10 +466,9 @@ native PbAddInt(Handle:pb, const String:field[], value); * @param pb protobuf handle. * @param field Field name. * @param value Float value to add. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbAddFloat(Handle:pb, const String:field[], Float:value); +native void PbAddFloat(Handle pb, const char[] field, float value); /** * Add a bool to a protobuf message repeated field. @@ -265,10 +476,9 @@ native PbAddFloat(Handle:pb, const String:field[], Float:value); * @param pb protobuf handle. * @param field Field name. * @param value Boolean value to add. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbAddBool(Handle:pb, const String:field[], bool:value); +native void PbAddBool(Handle pb, const char[] field, bool value); /** * Add a string to a protobuf message repeated field. @@ -276,10 +486,9 @@ native PbAddBool(Handle:pb, const String:field[], bool:value); * @param pb protobuf handle. * @param field Field name. * @param value String value to add. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbAddString(Handle:pb, const String:field[], const String:value[]); +native void PbAddString(Handle pb, const char[] field, const char[] value); /** * Add an RGBA color to a protobuf message repeated field. @@ -287,10 +496,9 @@ native PbAddString(Handle:pb, const String:field[], const String:value[]); * @param pb protobuf handle. * @param field Field name. * @param color Color value to add. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbAddColor(Handle:pb, const String:field[], const color[4]); +native void PbAddColor(Handle pb, const char[] field, const int color[4]); /** * Add an XYZ angle to a protobuf message repeated field. @@ -298,10 +506,9 @@ native PbAddColor(Handle:pb, const String:field[], const color[4]); * @param pb protobuf handle. * @param field Field name. * @param angle Angle value to add. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbAddAngle(Handle:pb, const String:field[], const Float:angle[3]); +native void PbAddAngle(Handle pb, const char[] field, const float angle[3]); /** * Add an XYZ vector to a protobuf message repeated field. @@ -309,10 +516,9 @@ native PbAddAngle(Handle:pb, const String:field[], const Float:angle[3]); * @param pb protobuf handle. * @param field Field name. * @param vec Vector value to add. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbAddVector(Handle:pb, const String:field[], const Float:vec[3]); +native void PbAddVector(Handle pb, const char[] field, const float vec[3]); /** * Add an XY vector to a protobuf message repeated field. @@ -320,10 +526,9 @@ native PbAddVector(Handle:pb, const String:field[], const Float:vec[3]); * @param pb protobuf handle. * @param field Field name. * @param vec Vector value to add. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbAddVector2D(Handle:pb, const String:field[], const Float:vec[2]); +native void PbAddVector2D(Handle pb, const char[] field, const float vec[2]); /** * Removes a value by index from a protobuf message repeated field. @@ -331,10 +536,9 @@ native PbAddVector2D(Handle:pb, const String:field[], const Float:vec[2]); * @param pb protobuf handle. * @param field Field name. * @param index Index into repeated field. - * @noreturn * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native PbRemoveRepeatedFieldValue(Handle:pb, const String:field[], index); +native void PbRemoveRepeatedFieldValue(Handle pb, const char[] field, int index); /** * Retrieve a handle to an embedded protobuf message in a protobuf message. @@ -344,7 +548,7 @@ native PbRemoveRepeatedFieldValue(Handle:pb, const String:field[], index); * @return protobuf handle to embedded message. * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native Handle:PbReadMessage(Handle:pb, const String:field[]); +native Handle PbReadMessage(Handle pb, const char[] field); /** * Retrieve a handle to an embedded protobuf message in a protobuf message repeated field. @@ -355,7 +559,7 @@ native Handle:PbReadMessage(Handle:pb, const String:field[]); * @return protobuf handle to embedded message. * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native Handle:PbReadRepeatedMessage(Handle:pb, const String:field[], index); +native Handle PbReadRepeatedMessage(Handle pb, const char[] field, int index); /** * Adds an embedded protobuf message to a protobuf message repeated field. @@ -365,4 +569,4 @@ native Handle:PbReadRepeatedMessage(Handle:pb, const String:field[], index); * @return protobuf handle to added, embedded message. * @error Invalid or incorrect Handle, non-existent field, or incorrect field type. */ -native Handle:PbAddMessage(Handle:pb, const String:field[]); +native Handle PbAddMessage(Handle pb, const char[] field); diff --git a/plugins/include/usermessages.inc b/plugins/include/usermessages.inc index ce48937b..c18323e7 100644 --- a/plugins/include/usermessages.inc +++ b/plugins/include/usermessages.inc @@ -70,6 +70,13 @@ enum UserMessageType */ native UserMessageType:GetUserMessageType(); +stock Protobuf UserMessageToProtobuf(Handle msg) +{ + if (GetUserMessageType() != UM_Protobuf) + return null; + return Protobuf:msg; +} + /** * Returns the ID of a given message, or -1 on failure. *