3 * =============================================================================
5 * Copyright (C) 2013 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #include "logic_bridge.h"
33 #include "UserMessagePBHelpers.h"
34 #include "smn_usermsgs.h"
36 // Assumes pbuf message handle is param 1, gets message as msg
37 #define GET_MSG_FROM_HANDLE_OR_ERR() \
38 Handle_t hndl = static_cast<Handle_t>(params[1]); \
41 SMProtobufMessage *msg; \
44 sec.pIdentity = g_pCoreIdent; \
46 if ((herr=handlesys->ReadHandle(hndl, g_ProtobufType, &sec, (void **)&msg)) \
47 != HandleError_None) \
49 return pCtx->ThrowNativeError("Invalid protobuf message handle %x (error %d)", hndl, herr); \
52 // Assumes message field name is param 2, gets as strField
53 #define GET_FIELD_NAME_OR_ERR() \
56 if ((err=pCtx->LocalToString(params[2], &strField)) != SP_ERROR_NONE) \
58 pCtx->ThrowNativeErrorEx(err, NULL); \
62 static cell_t smn_PbReadInt(IPluginContext *pCtx, const cell_t *params)
64 GET_MSG_FROM_HANDLE_OR_ERR();
65 GET_FIELD_NAME_OR_ERR();
69 int index = params[0] >= 3 ? params[3] : -1;
72 if (!msg->GetInt32OrUnsigned(strField, &ret))
74 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
79 if (!msg->GetRepeatedInt32OrUnsigned(strField, index, &ret))
81 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, index, msg->GetProtobufMessage()->GetTypeName().c_str());
88 static cell_t smn_PbReadFloat(IPluginContext *pCtx, const cell_t *params)
90 GET_MSG_FROM_HANDLE_OR_ERR();
91 GET_FIELD_NAME_OR_ERR();
95 int index = params[0] >= 3 ? params[3] : -1;
98 if (!msg->GetFloatOrDouble(strField, &ret))
100 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
105 if (!msg->GetRepeatedFloatOrDouble(strField, index, &ret))
107 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, index, msg->GetProtobufMessage()->GetTypeName().c_str());
114 static cell_t smn_PbReadBool(IPluginContext *pCtx, const cell_t *params)
116 GET_MSG_FROM_HANDLE_OR_ERR();
117 GET_FIELD_NAME_OR_ERR();
121 int index = params[0] >= 3 ? params[3] : -1;
124 if (!msg->GetBool(strField, &ret))
126 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
131 if (!msg->GetRepeatedBool(strField, index, &ret))
133 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, index, msg->GetProtobufMessage()->GetTypeName().c_str());
140 static cell_t smn_PbReadString(IPluginContext *pCtx, const cell_t *params)
142 GET_MSG_FROM_HANDLE_OR_ERR();
143 GET_FIELD_NAME_OR_ERR();
146 pCtx->LocalToPhysAddr(params[3], (cell_t **)&buf);
148 int index = params[0] >= 5 ? params[5] : -1;
152 if (!msg->GetString(strField, buf, params[4]))
154 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
159 if (!msg->GetRepeatedString(strField, index, buf, params[4]))
161 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, index, msg->GetProtobufMessage()->GetTypeName().c_str());
168 static cell_t smn_PbReadColor(IPluginContext *pCtx, const cell_t *params)
170 GET_MSG_FROM_HANDLE_OR_ERR();
171 GET_FIELD_NAME_OR_ERR();
174 pCtx->LocalToPhysAddr(params[3], &out);
177 int index = params[0] >= 4 ? params[4] : -1;
180 if (!msg->GetColor(strField, &clr))
182 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
187 if (!msg->GetRepeatedColor(strField, index, &clr))
189 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, index, msg->GetProtobufMessage()->GetTypeName().c_str());
201 static cell_t smn_PbReadAngle(IPluginContext *pCtx, const cell_t *params)
203 GET_MSG_FROM_HANDLE_OR_ERR();
204 GET_FIELD_NAME_OR_ERR();
207 pCtx->LocalToPhysAddr(params[3], &out);
210 int index = params[0] >= 4 ? params[4] : -1;
213 if (!msg->GetQAngle(strField, &ang))
215 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
220 if (!msg->GetRepeatedQAngle(strField, index, &ang))
222 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, index, msg->GetProtobufMessage()->GetTypeName().c_str());
226 out[0] = sp_ftoc(ang.x);
227 out[1] = sp_ftoc(ang.y);
228 out[2] = sp_ftoc(ang.z);
233 static cell_t smn_PbReadVector(IPluginContext *pCtx, const cell_t *params)
235 GET_MSG_FROM_HANDLE_OR_ERR();
236 GET_FIELD_NAME_OR_ERR();
239 pCtx->LocalToPhysAddr(params[3], &out);
242 int index = params[0] >= 4 ? params[4] : -1;
245 if (!msg->GetVector(strField, &vec))
247 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
252 if (!msg->GetRepeatedVector(strField, index, &vec))
254 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, index, msg->GetProtobufMessage()->GetTypeName().c_str());
258 out[0] = sp_ftoc(vec.x);
259 out[1] = sp_ftoc(vec.y);
260 out[2] = sp_ftoc(vec.z);
265 static cell_t smn_PbReadVector2D(IPluginContext *pCtx, const cell_t *params)
267 GET_MSG_FROM_HANDLE_OR_ERR();
268 GET_FIELD_NAME_OR_ERR();
271 pCtx->LocalToPhysAddr(params[3], &out);
274 int index = params[0] >= 4 ? params[4] : -1;
277 if (!msg->GetVector2D(strField, &vec))
279 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
284 if (!msg->GetRepeatedVector2D(strField, index, &vec))
286 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, index, msg->GetProtobufMessage()->GetTypeName().c_str());
290 out[0] = sp_ftoc(vec.x);
291 out[1] = sp_ftoc(vec.y);
296 static cell_t smn_PbGetRepeatedFieldCount(IPluginContext *pCtx, const cell_t *params)
298 GET_MSG_FROM_HANDLE_OR_ERR();
299 GET_FIELD_NAME_OR_ERR();
301 int cnt = msg->GetRepeatedFieldCount(strField);
304 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
310 static cell_t smn_PbReadRepeatedInt(IPluginContext *pCtx, const cell_t *params)
312 GET_MSG_FROM_HANDLE_OR_ERR();
313 GET_FIELD_NAME_OR_ERR();
316 if (!msg->GetRepeatedInt32OrUnsigned(strField, params[3], &ret))
318 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, params[3], msg->GetProtobufMessage()->GetTypeName().c_str());
324 static cell_t smn_PbReadRepeatedFloat(IPluginContext *pCtx, const cell_t *params)
326 GET_MSG_FROM_HANDLE_OR_ERR();
327 GET_FIELD_NAME_OR_ERR();
330 if (!msg->GetRepeatedFloatOrDouble(strField, params[3], &ret))
332 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, params[3], msg->GetProtobufMessage()->GetTypeName().c_str());
338 static cell_t smn_PbReadRepeatedBool(IPluginContext *pCtx, const cell_t *params)
340 GET_MSG_FROM_HANDLE_OR_ERR();
341 GET_FIELD_NAME_OR_ERR();
344 if (!msg->GetRepeatedBool(strField, params[3], &ret))
346 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, params[3], msg->GetProtobufMessage()->GetTypeName().c_str());
352 static cell_t smn_PbReadRepeatedString(IPluginContext *pCtx, const cell_t *params)
354 GET_MSG_FROM_HANDLE_OR_ERR();
355 GET_FIELD_NAME_OR_ERR();
358 pCtx->LocalToPhysAddr(params[4], (cell_t **)&buf);
360 if (!msg->GetRepeatedString(strField, params[3], buf, params[5]))
362 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, params[3], msg->GetProtobufMessage()->GetTypeName().c_str());
368 static cell_t smn_PbReadRepeatedColor(IPluginContext *pCtx, const cell_t *params)
370 GET_MSG_FROM_HANDLE_OR_ERR();
371 GET_FIELD_NAME_OR_ERR();
374 pCtx->LocalToPhysAddr(params[4], &out);
377 if (!msg->GetRepeatedColor(strField, params[3], &clr))
379 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, params[3], msg->GetProtobufMessage()->GetTypeName().c_str());
390 static cell_t smn_PbReadRepeatedAngle(IPluginContext *pCtx, const cell_t *params)
392 GET_MSG_FROM_HANDLE_OR_ERR();
393 GET_FIELD_NAME_OR_ERR();
396 pCtx->LocalToPhysAddr(params[4], &out);
399 if (!msg->GetRepeatedQAngle(strField, params[3], &ang))
401 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, params[3], msg->GetProtobufMessage()->GetTypeName().c_str());
404 out[0] = sp_ftoc(ang.x);
405 out[1] = sp_ftoc(ang.y);
406 out[2] = sp_ftoc(ang.z);
411 static cell_t smn_PbReadRepeatedVector(IPluginContext *pCtx, const cell_t *params)
413 GET_MSG_FROM_HANDLE_OR_ERR();
414 GET_FIELD_NAME_OR_ERR();
417 pCtx->LocalToPhysAddr(params[4], &out);
420 if (!msg->GetRepeatedVector(strField, params[3], &vec))
422 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, params[3], msg->GetProtobufMessage()->GetTypeName().c_str());
425 out[0] = sp_ftoc(vec.x);
426 out[1] = sp_ftoc(vec.y);
427 out[2] = sp_ftoc(vec.z);
432 static cell_t smn_PbReadRepeatedVector2D(IPluginContext *pCtx, const cell_t *params)
434 GET_MSG_FROM_HANDLE_OR_ERR();
435 GET_FIELD_NAME_OR_ERR();
438 pCtx->LocalToPhysAddr(params[4], &out);
441 if (!msg->GetRepeatedVector2D(strField, params[3], &vec))
443 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, params[3], msg->GetProtobufMessage()->GetTypeName().c_str());
446 out[0] = sp_ftoc(vec.x);
447 out[1] = sp_ftoc(vec.y);
452 static cell_t smn_PbSetInt(IPluginContext *pCtx, const cell_t *params)
454 GET_MSG_FROM_HANDLE_OR_ERR();
455 GET_FIELD_NAME_OR_ERR();
457 int index = params[0] >= 4 ? params[4] : -1;
460 if (!msg->SetInt32OrUnsigned(strField, params[3]))
462 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
467 if (!msg->SetRepeatedInt32OrUnsigned(strField, index, params[3]))
469 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, index, msg->GetProtobufMessage()->GetTypeName().c_str());
476 static cell_t smn_PbSetFloat(IPluginContext *pCtx, const cell_t *params)
478 GET_MSG_FROM_HANDLE_OR_ERR();
479 GET_FIELD_NAME_OR_ERR();
481 int index = params[0] >= 4 ? params[4] : -1;
484 if (!msg->SetFloatOrDouble(strField, sp_ctof(params[3])))
486 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
491 if (!msg->SetRepeatedFloatOrDouble(strField, index, sp_ctof(params[3])))
493 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, index, msg->GetProtobufMessage()->GetTypeName().c_str());
500 static cell_t smn_PbSetBool(IPluginContext *pCtx, const cell_t *params)
502 GET_MSG_FROM_HANDLE_OR_ERR();
503 GET_FIELD_NAME_OR_ERR();
505 bool value = (params[3] == 0 ? false : true);
506 int index = params[0] >= 4 ? params[4] : -1;
509 if (!msg->SetBool(strField, value))
511 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
516 if (!msg->SetRepeatedBool(strField, index, value))
518 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, index, msg->GetProtobufMessage()->GetTypeName().c_str());
525 static cell_t smn_PbSetString(IPluginContext *pCtx, const cell_t *params)
527 GET_MSG_FROM_HANDLE_OR_ERR();
528 GET_FIELD_NAME_OR_ERR();
531 if ((err=pCtx->LocalToString(params[3], &strValue)) != SP_ERROR_NONE)
533 pCtx->ThrowNativeErrorEx(err, NULL);
537 int index = params[0] >= 4 ? params[4] : -1;
540 if (!msg->SetString(strField, strValue))
542 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
547 if (!msg->SetRepeatedString(strField, index, strValue))
549 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, index, msg->GetProtobufMessage()->GetTypeName().c_str());
556 static cell_t smn_PbSetColor(IPluginContext *pCtx, const cell_t *params)
558 GET_MSG_FROM_HANDLE_OR_ERR();
559 GET_FIELD_NAME_OR_ERR();
562 if ((err=pCtx->LocalToPhysAddr(params[3], &clrParams)) != SP_ERROR_NONE)
564 pCtx->ThrowNativeErrorEx(err, NULL);
574 int index = params[0] >= 4 ? params[4] : -1;
577 if (!msg->SetColor(strField, clr))
579 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
584 if (!msg->SetRepeatedColor(strField, index, clr))
586 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, index, msg->GetProtobufMessage()->GetTypeName().c_str());
593 static cell_t smn_PbSetAngle(IPluginContext *pCtx, const cell_t *params)
595 GET_MSG_FROM_HANDLE_OR_ERR();
596 GET_FIELD_NAME_OR_ERR();
599 if ((err=pCtx->LocalToPhysAddr(params[3], &angParams)) != SP_ERROR_NONE)
601 pCtx->ThrowNativeErrorEx(err, NULL);
606 sp_ctof(angParams[0]),
607 sp_ctof(angParams[1]),
608 sp_ctof(angParams[2]));
610 int index = params[0] >= 4 ? params[4] : -1;
613 if (!msg->SetQAngle(strField, ang))
615 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
620 if (!msg->SetRepeatedQAngle(strField, index, ang))
622 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, index, msg->GetProtobufMessage()->GetTypeName().c_str());
629 static cell_t smn_PbSetVector(IPluginContext *pCtx, const cell_t *params)
631 GET_MSG_FROM_HANDLE_OR_ERR();
632 GET_FIELD_NAME_OR_ERR();
635 if ((err=pCtx->LocalToPhysAddr(params[3], &vecParams)) != SP_ERROR_NONE)
637 pCtx->ThrowNativeErrorEx(err, NULL);
642 sp_ctof(vecParams[0]),
643 sp_ctof(vecParams[1]),
644 sp_ctof(vecParams[2]));
646 int index = params[0] >= 4 ? params[4] : -1;
649 if (!msg->SetVector(strField, vec))
651 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
656 if (!msg->SetRepeatedVector(strField, index, vec))
658 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, index, msg->GetProtobufMessage()->GetTypeName().c_str());
665 static cell_t smn_PbSetVector2D(IPluginContext *pCtx, const cell_t *params)
667 GET_MSG_FROM_HANDLE_OR_ERR();
668 GET_FIELD_NAME_OR_ERR();
671 if ((err=pCtx->LocalToPhysAddr(params[3], &vecParams)) != SP_ERROR_NONE)
673 pCtx->ThrowNativeErrorEx(err, NULL);
678 sp_ctof(vecParams[0]),
679 sp_ctof(vecParams[1]));
681 int index = params[0] >= 4 ? params[4] : -1;
684 if (!msg->SetVector2D(strField, vec))
686 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
691 if (!msg->SetRepeatedVector2D(strField, index, vec))
693 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, index, msg->GetProtobufMessage()->GetTypeName().c_str());
700 static cell_t smn_PbAddInt(IPluginContext *pCtx, const cell_t *params)
702 GET_MSG_FROM_HANDLE_OR_ERR();
703 GET_FIELD_NAME_OR_ERR();
705 if (!msg->AddInt32OrUnsigned(strField, params[3]))
707 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
713 static cell_t smn_PbAddFloat(IPluginContext *pCtx, const cell_t *params)
715 GET_MSG_FROM_HANDLE_OR_ERR();
716 GET_FIELD_NAME_OR_ERR();
718 if (!msg->AddFloatOrDouble(strField, sp_ctof(params[3])))
720 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
726 static cell_t smn_PbAddBool(IPluginContext *pCtx, const cell_t *params)
728 GET_MSG_FROM_HANDLE_OR_ERR();
729 GET_FIELD_NAME_OR_ERR();
731 bool value = (params[3] == 0 ? false : true);
732 if (!msg->AddBool(strField, value))
734 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
740 static cell_t smn_PbAddString(IPluginContext *pCtx, const cell_t *params)
742 GET_MSG_FROM_HANDLE_OR_ERR();
743 GET_FIELD_NAME_OR_ERR();
746 if ((err=pCtx->LocalToString(params[3], &strValue)) != SP_ERROR_NONE)
748 pCtx->ThrowNativeErrorEx(err, NULL);
752 if (!msg->AddString(strField, strValue))
754 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
760 static cell_t smn_PbAddColor(IPluginContext *pCtx, const cell_t *params)
762 GET_MSG_FROM_HANDLE_OR_ERR();
763 GET_FIELD_NAME_OR_ERR();
766 if ((err=pCtx->LocalToPhysAddr(params[3], &clrParams)) != SP_ERROR_NONE)
768 pCtx->ThrowNativeErrorEx(err, NULL);
778 if (!msg->AddColor(strField, clr))
780 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
786 static cell_t smn_PbAddAngle(IPluginContext *pCtx, const cell_t *params)
788 GET_MSG_FROM_HANDLE_OR_ERR();
789 GET_FIELD_NAME_OR_ERR();
792 if ((err=pCtx->LocalToPhysAddr(params[3], &angParams)) != SP_ERROR_NONE)
794 pCtx->ThrowNativeErrorEx(err, NULL);
799 sp_ctof(angParams[0]),
800 sp_ctof(angParams[1]),
801 sp_ctof(angParams[2]));
803 if (!msg->AddQAngle(strField, ang))
805 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
811 static cell_t smn_PbAddVector(IPluginContext *pCtx, const cell_t *params)
813 GET_MSG_FROM_HANDLE_OR_ERR();
814 GET_FIELD_NAME_OR_ERR();
817 if ((err=pCtx->LocalToPhysAddr(params[3], &vecParams)) != SP_ERROR_NONE)
819 pCtx->ThrowNativeErrorEx(err, NULL);
824 sp_ctof(vecParams[0]),
825 sp_ctof(vecParams[1]),
826 sp_ctof(vecParams[2]));
828 if (!msg->AddVector(strField, vec))
830 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
836 static cell_t smn_PbAddVector2D(IPluginContext *pCtx, const cell_t *params)
838 GET_MSG_FROM_HANDLE_OR_ERR();
839 GET_FIELD_NAME_OR_ERR();
842 if ((err=pCtx->LocalToPhysAddr(params[3], &vecParams)) != SP_ERROR_NONE)
844 pCtx->ThrowNativeErrorEx(err, NULL);
849 sp_ctof(vecParams[0]),
850 sp_ctof(vecParams[1]));
852 if (!msg->AddVector2D(strField, vec))
854 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
860 static cell_t smn_PbReadMessage(IPluginContext *pCtx, const cell_t *params)
862 GET_MSG_FROM_HANDLE_OR_ERR();
863 GET_FIELD_NAME_OR_ERR();
865 protobuf::Message *innerMsg;
866 if (!msg->GetMessage(strField, &innerMsg))
868 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
871 Handle_t outHndl = handlesys->CreateHandle(g_ProtobufType, new SMProtobufMessage(innerMsg), NULL, g_pCoreIdent, NULL);
872 msg->AddChildHandle(outHndl);
877 static cell_t smn_PbReadRepeatedMessage(IPluginContext *pCtx, const cell_t *params)
879 GET_MSG_FROM_HANDLE_OR_ERR();
880 GET_FIELD_NAME_OR_ERR();
882 const protobuf::Message *innerMsg;
883 if (!msg->GetRepeatedMessage(strField, params[3], &innerMsg))
885 return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, params[3], msg->GetProtobufMessage()->GetTypeName().c_str());
888 Handle_t outHndl = handlesys->CreateHandle(g_ProtobufType, new SMProtobufMessage(const_cast<protobuf::Message *>(innerMsg)), NULL, g_pCoreIdent, NULL);
889 msg->AddChildHandle(outHndl);
894 static cell_t smn_PbAddMessage(IPluginContext *pCtx, const cell_t *params)
896 GET_MSG_FROM_HANDLE_OR_ERR();
897 GET_FIELD_NAME_OR_ERR();
899 protobuf::Message *innerMsg;
900 if (!msg->AddMessage(strField, &innerMsg))
902 return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str());
905 Handle_t outHndl = handlesys->CreateHandle(g_ProtobufType, new SMProtobufMessage(innerMsg), NULL, g_pCoreIdent, NULL);
906 msg->AddChildHandle(outHndl);
911 REGISTER_NATIVES(protobufnatives)
913 {"PbReadInt", smn_PbReadInt},
914 {"PbReadFloat", smn_PbReadFloat},
915 {"PbReadBool", smn_PbReadBool},
916 {"PbReadString", smn_PbReadString},
917 {"PbReadColor", smn_PbReadColor},
918 {"PbReadAngle", smn_PbReadAngle},
919 {"PbReadVector", smn_PbReadVector},
920 {"PbReadVector2D", smn_PbReadVector2D},
921 {"PbGetRepeatedFieldCount", smn_PbGetRepeatedFieldCount},
922 {"PbReadRepeatedInt", smn_PbReadRepeatedInt},
923 {"PbReadRepeatedFloat", smn_PbReadRepeatedFloat},
924 {"PbReadRepeatedBool", smn_PbReadRepeatedBool},
925 {"PbReadRepeatedString", smn_PbReadRepeatedString},
926 {"PbReadRepeatedColor", smn_PbReadRepeatedColor},
927 {"PbReadRepeatedAngle", smn_PbReadRepeatedAngle},
928 {"PbReadRepeatedVector", smn_PbReadRepeatedVector},
929 {"PbReadRepeatedVector2D", smn_PbReadRepeatedVector2D},
930 {"PbSetInt", smn_PbSetInt},
931 {"PbSetFloat", smn_PbSetFloat},
932 {"PbSetBool", smn_PbSetBool},
933 {"PbSetString", smn_PbSetString},
934 {"PbSetColor", smn_PbSetColor},
935 {"PbSetAngle", smn_PbSetAngle},
936 {"PbSetVector", smn_PbSetVector},
937 {"PbSetVector2D", smn_PbSetVector2D},
938 {"PbAddInt", smn_PbAddInt},
939 {"PbAddFloat", smn_PbAddFloat},
940 {"PbAddBool", smn_PbAddBool},
941 {"PbAddString", smn_PbAddString},
942 {"PbAddColor", smn_PbAddColor},
943 {"PbAddAngle", smn_PbAddAngle},
944 {"PbAddVector", smn_PbAddVector},
945 {"PbAddVector2D", smn_PbAddVector2D},
946 {"PbReadMessage", smn_PbReadMessage},
947 {"PbReadRepeatedMessage", smn_PbReadRepeatedMessage},
948 {"PbAddMessage", smn_PbAddMessage},
955 @@@@@@@@@@@@@@@@@@@@@
956 @@@@@@@@@@@@@@@@@@@@@@@@
957 @@@@@@@@ @@@@@@@@@@@@@
958 @@@@@@@@ @@@@@@@@@@@@@
959 @@@@@@ @@@@@@@@@@@@@@@
960 0000 @@@@@@@@@@@@@@@@@@@@@
961 000000000 @@@@@@@@@@@@@@@@@@@
962 0000000000000000000 @@@@@@@@@@@@@@@
963 00000000000000000000 @@@@@@@@@@@@@@@
964 000000000 @@@@@@@@@@@@@@@
968 @@@@@@@@@@@@@@@@@@ @@@@
969 @@@@@@@@@@@@@@@@@@@ @@@@@@@
970 @@@ @@@@ @@@ @@@@@@@@@@
971 @@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@ @@@@@
972 @@@@@@@@@@@@@@@@@@@@@@@@@@ @@@ @@@@@@@@ @@ @@@@@@@@@@@@@@@
973 @@@@@@@@@@@@@@@@@@@@@@@@@@ @@ @@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@ @@ @@@@@@@@@
974 @@@@@@@@@@@@@@@@@@@@@@@ @@@@ @@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@ @@ @@@@@@@@@@@@@
975 @@@@@@@@@@@@@@@@@@@@@ @@@@ @@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@ @@@ @@@@@@@@@@@@
976 @@@@@@@@@@@@@@@@@@@@ @@@@@@ @@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@ @@@@ @@@@@@@@@@@
977 @@@@@@@@@@@@@@@@@ @@@@@@ @@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@ @@@@@ @@@@@@
978 @@@@@@@@@ @@@@@@@@@ @@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@ @@ @@@@@ @@@@@@@@
979 @@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@ @@@@@@ @@@@ @@@@@@
980 @@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@ @@@@@@ @@@@@@ @@@@@@
981 @@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@ @@@@@@@@ @@@@
982 @@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@ @ @@@@@
983 @@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@ @@@@@ @@@@ ////
984 //////////// @@@@@@@@@@@ @@@@@@ @@@@@@@@@@@@@@@@@@@@ @@ @@@@@@@@@ @@@@ //// ////////////
985 ///////////////// /// @@@@@ @@@@ @@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@ @@@@ ///// /////// /////////
986 ///////////////////// ///// @@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@ @@@@@@@ @ @@@@ ////// /////// ///////////////
987 ///////////////////////// /////// @@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@ @@@@@ @@@@ ////// //////// ////////////////////
988 //////////////////////////// ////////// @@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@ @@@@@@@@@ @@@ ////// ////////// ////////////////////////
989 //////////////////// ////////// /////////// @@@@@@@@@@@@@@@@@ @@@@@@@@ @@@ @@@@@@ ////// //////////// //////////////////////////
990 //////////////////// //////////// /////////// @@@@@@@@@@@@@@@@ @@@@ ///////////////////// /////////////////////////////
991 ///////////////////// ////////////// ////// @@@@@@@@@ ///////////////////////////////////////////////////////////
992 //////////////////// ///////////////////////////////////// ///////////////////////////////////////////////////////////////////////
993 ///////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
994 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
995 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
996 /////////////////////////////////////////////////////////////////////////////////////////
997 //////////////////////////////////////////////////////////