core/UserMessagePBHelpers.h
author Nicholas Hastings <skamonkey@gmail.com>
Thu Aug 15 10:18:27 2013 -0400 (2013-08-15)
changeset 4015 5f1fcac17b60
parent 3896 cb7537c1da4d
child 4293 f61ae385f12e
permissions -rw-r--r--
Fixed chat trigger crash regression on ep1 (bug 5394, r=asherkin).
skamonkey@3743
     1
/**
skamonkey@3743
     2
 * vim: set ts=4 :
skamonkey@3743
     3
 * =============================================================================
skamonkey@3743
     4
 * SourceMod
skamonkey@3743
     5
 * Copyright (C) 2013 AlliedModders LLC.  All rights reserved.
skamonkey@3743
     6
 * =============================================================================
skamonkey@3743
     7
 *
skamonkey@3743
     8
 * This program is free software; you can redistribute it and/or modify it under
skamonkey@3743
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
skamonkey@3743
    10
 * Free Software Foundation.
skamonkey@3743
    11
 * 
skamonkey@3743
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
skamonkey@3743
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
skamonkey@3743
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
skamonkey@3743
    15
 * details.
skamonkey@3743
    16
 *
skamonkey@3743
    17
 * You should have received a copy of the GNU General Public License along with
skamonkey@3743
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
skamonkey@3743
    19
 *
skamonkey@3743
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
skamonkey@3743
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
skamonkey@3743
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
skamonkey@3743
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
skamonkey@3743
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
skamonkey@3743
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
skamonkey@3743
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
skamonkey@3743
    27
 * or <http://www.sourcemod.net/license.php>.
skamonkey@3743
    28
 *
skamonkey@3743
    29
 * Version: $Id$
skamonkey@3743
    30
 */
skamonkey@3743
    31
skamonkey@3743
    32
#ifndef _INCLUDE_SOURCEMOD_SMPBMESSAGE_H_
skamonkey@3743
    33
#define _INCLUDE_SOURCEMOD_SMPBMESSAGE_H_
skamonkey@3743
    34
skamonkey@3743
    35
#include <sh_list.h>
skamonkey@3743
    36
#include <google/protobuf/descriptor.h>
skamonkey@3743
    37
skamonkey@3743
    38
#define GETCHECK_FIELD() \
skamonkey@3743
    39
	const protobuf::FieldDescriptor *field = msg->GetDescriptor()->FindFieldByName(pszFieldName); \
skamonkey@3743
    40
	if (!field)       \
skamonkey@3743
    41
	{                 \
skamonkey@3743
    42
		return false; \
skamonkey@3743
    43
	}
skamonkey@3743
    44
skamonkey@3743
    45
#define CHECK_FIELD_TYPE(type) \
skamonkey@3743
    46
	if (field->cpp_type() != protobuf::FieldDescriptor::CPPTYPE_##type) \
skamonkey@3743
    47
	{                 \
skamonkey@3743
    48
		return false; \
skamonkey@3743
    49
	}
skamonkey@3743
    50
skamonkey@3743
    51
#define CHECK_FIELD_TYPE2(type1, type2) \
skamonkey@3743
    52
	protobuf::FieldDescriptor::CppType fieldType = field->cpp_type(); \
skamonkey@3743
    53
	if (fieldType != protobuf::FieldDescriptor::CPPTYPE_##type1       \
skamonkey@3743
    54
		&& fieldType != protobuf::FieldDescriptor::CPPTYPE_##type2) \
skamonkey@3743
    55
	{                 \
skamonkey@3743
    56
		return false; \
skamonkey@3743
    57
	}
skamonkey@3743
    58
skamonkey@3896
    59
#define CHECK_FIELD_TYPE3(type1, type2, type3) \
skamonkey@3896
    60
	protobuf::FieldDescriptor::CppType fieldType = field->cpp_type(); \
skamonkey@3896
    61
	if (fieldType != protobuf::FieldDescriptor::CPPTYPE_##type1       \
skamonkey@3896
    62
		&& fieldType != protobuf::FieldDescriptor::CPPTYPE_##type2 \
skamonkey@3896
    63
		&& fieldType != protobuf::FieldDescriptor::CPPTYPE_##type3) \
skamonkey@3896
    64
	{                 \
skamonkey@3896
    65
		return false; \
skamonkey@3896
    66
	}
skamonkey@3896
    67
skamonkey@3743
    68
#define CHECK_FIELD_REPEATED() \
skamonkey@3743
    69
	if (field->label() != protobuf::FieldDescriptor::LABEL_REPEATED) \
skamonkey@3743
    70
	{                 \
skamonkey@3743
    71
		return false; \
skamonkey@3743
    72
	}
skamonkey@3743
    73
skamonkey@3743
    74
#define CHECK_FIELD_NOT_REPEATED() \
skamonkey@3743
    75
	if (field->label() == protobuf::FieldDescriptor::LABEL_REPEATED) \
skamonkey@3743
    76
	{                 \
skamonkey@3743
    77
		return false; \
skamonkey@3743
    78
	}
skamonkey@3743
    79
skamonkey@3743
    80
#define CHECK_REPEATED_ELEMENT(idx) \
skamonkey@3743
    81
	int elemCount = msg->GetReflection()->FieldSize(*msg, field); \
skamonkey@3751
    82
	if (elemCount == 0 || idx >= elemCount || idx < 0)        \
skamonkey@3743
    83
	{                                                         \
skamonkey@3743
    84
		return false;                                         \
skamonkey@3743
    85
	}
skamonkey@3743
    86
skamonkey@3743
    87
typedef List<Handle_t> PBHandleList;
skamonkey@3743
    88
skamonkey@3743
    89
class SMProtobufMessage
skamonkey@3743
    90
{
skamonkey@3743
    91
public:
skamonkey@3743
    92
	SMProtobufMessage( protobuf::Message *message )
skamonkey@3743
    93
	{
skamonkey@3743
    94
		msg = message;
skamonkey@3743
    95
	}
skamonkey@3743
    96
skamonkey@3743
    97
	~SMProtobufMessage()
skamonkey@3743
    98
	{
skamonkey@3743
    99
		PBHandleList::iterator iter = childHandles.begin();
skamonkey@3743
   100
		while (iter != childHandles.end())
skamonkey@3743
   101
		{
skamonkey@3743
   102
			Handle_t &hndl = (*iter);
skamonkey@3743
   103
			HandleSecurity sec;
skamonkey@3743
   104
			sec.pIdentity = g_pCoreIdent;
dvander@3875
   105
			handlesys->FreeHandle(hndl, &sec);
skamonkey@3743
   106
			iter = childHandles.erase(iter);
skamonkey@3743
   107
		}
skamonkey@3743
   108
	}
skamonkey@3743
   109
skamonkey@3743
   110
	inline void AddChildHandle(Handle_t hndl)
skamonkey@3743
   111
	{
skamonkey@3743
   112
		childHandles.push_back(hndl);
skamonkey@3743
   113
	}
skamonkey@3743
   114
skamonkey@3743
   115
	inline protobuf::Message *GetProtobufMessage()
skamonkey@3743
   116
	{
skamonkey@3743
   117
		return msg;
skamonkey@3743
   118
	}
skamonkey@3743
   119
skamonkey@3743
   120
	inline bool GetInt32(const char *pszFieldName, int32 *out)
skamonkey@3743
   121
	{
skamonkey@3743
   122
		GETCHECK_FIELD();
skamonkey@3743
   123
		CHECK_FIELD_TYPE(INT32);
skamonkey@3743
   124
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   125
skamonkey@3743
   126
		*out = msg->GetReflection()->GetInt32(*msg, field);
skamonkey@3743
   127
		return true;	
skamonkey@3743
   128
	}
skamonkey@3743
   129
skamonkey@3743
   130
	inline bool SetInt32(const char *pszFieldName, int32 value)
skamonkey@3743
   131
	{
skamonkey@3743
   132
		GETCHECK_FIELD();
skamonkey@3743
   133
		CHECK_FIELD_TYPE(INT32);
skamonkey@3743
   134
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   135
skamonkey@3743
   136
		msg->GetReflection()->SetInt32(msg, field, value);
skamonkey@3743
   137
		return true;
skamonkey@3743
   138
	}
skamonkey@3743
   139
skamonkey@3743
   140
	inline bool GetRepeatedInt32(const char *pszFieldName, int index, int32 *out)
skamonkey@3743
   141
	{
skamonkey@3743
   142
		GETCHECK_FIELD();
skamonkey@3743
   143
		CHECK_FIELD_TYPE(INT32);
skamonkey@3743
   144
		CHECK_FIELD_REPEATED();
skamonkey@3743
   145
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3743
   146
		
skamonkey@3743
   147
		*out = msg->GetReflection()->GetRepeatedInt32(*msg, field, index);
skamonkey@3743
   148
		return true;
skamonkey@3743
   149
	}
skamonkey@3743
   150
skamonkey@3814
   151
	inline bool SetRepeatedInt32(const char *pszFieldName, int index, int32 value)
skamonkey@3814
   152
	{
skamonkey@3814
   153
		GETCHECK_FIELD();
skamonkey@3814
   154
		CHECK_FIELD_TYPE(INT32);
skamonkey@3814
   155
		CHECK_FIELD_REPEATED();
skamonkey@3814
   156
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3814
   157
		
skamonkey@3814
   158
		msg->GetReflection()->SetRepeatedInt32(msg, field, index, value);
skamonkey@3814
   159
		return true;
skamonkey@3814
   160
	}
skamonkey@3814
   161
skamonkey@3743
   162
	inline bool AddInt32(const char *pszFieldName, int32 value)
skamonkey@3743
   163
	{
skamonkey@3743
   164
		GETCHECK_FIELD();
skamonkey@3743
   165
		CHECK_FIELD_TYPE(INT32);
skamonkey@3743
   166
		CHECK_FIELD_REPEATED();
skamonkey@3743
   167
skamonkey@3743
   168
		msg->GetReflection()->AddInt32(msg, field, value);
skamonkey@3743
   169
		return true;
skamonkey@3743
   170
	}
skamonkey@3743
   171
skamonkey@3743
   172
	inline bool GetInt64(const char *pszFieldName, int64 *out)
skamonkey@3743
   173
	{
skamonkey@3743
   174
		GETCHECK_FIELD();
skamonkey@3743
   175
		CHECK_FIELD_TYPE(INT64);
skamonkey@3743
   176
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   177
skamonkey@3743
   178
		*out = msg->GetReflection()->GetInt64(*msg, field);
skamonkey@3743
   179
		return true;	
skamonkey@3743
   180
	}
skamonkey@3743
   181
skamonkey@3743
   182
	inline bool SetInt64(const char *pszFieldName, int64 value)
skamonkey@3743
   183
	{
skamonkey@3743
   184
		GETCHECK_FIELD();
skamonkey@3743
   185
		CHECK_FIELD_TYPE(INT64);
skamonkey@3743
   186
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   187
skamonkey@3743
   188
		msg->GetReflection()->SetInt64(msg, field, value);
skamonkey@3743
   189
		return true;
skamonkey@3743
   190
	}
skamonkey@3743
   191
skamonkey@3743
   192
	inline bool GetRepeatedInt64(const char *pszFieldName, int index, int64 *out)
skamonkey@3743
   193
	{
skamonkey@3743
   194
		GETCHECK_FIELD();
skamonkey@3743
   195
		CHECK_FIELD_TYPE(INT64);
skamonkey@3743
   196
		CHECK_FIELD_REPEATED();
skamonkey@3743
   197
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3743
   198
		
skamonkey@3743
   199
		*out = msg->GetReflection()->GetRepeatedInt64(*msg, field, index);
skamonkey@3743
   200
		return true;
skamonkey@3743
   201
	}
skamonkey@3743
   202
skamonkey@3814
   203
	inline bool SetRepeatedInt64(const char *pszFieldName, int index, int64 value)
skamonkey@3814
   204
	{
skamonkey@3814
   205
		GETCHECK_FIELD();
skamonkey@3814
   206
		CHECK_FIELD_TYPE(INT64);
skamonkey@3814
   207
		CHECK_FIELD_REPEATED();
skamonkey@3814
   208
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3814
   209
		
skamonkey@3814
   210
		msg->GetReflection()->SetRepeatedInt64(msg, field, index, value);
skamonkey@3814
   211
		return true;
skamonkey@3814
   212
	}
skamonkey@3814
   213
skamonkey@3743
   214
	inline bool AddInt64(const char *pszFieldName, int64 value)
skamonkey@3743
   215
	{
skamonkey@3743
   216
		GETCHECK_FIELD();
skamonkey@3743
   217
		CHECK_FIELD_TYPE(INT64);
skamonkey@3743
   218
		CHECK_FIELD_REPEATED();
skamonkey@3743
   219
skamonkey@3743
   220
		msg->GetReflection()->AddInt64(msg, field, value);
skamonkey@3743
   221
		return true;
skamonkey@3743
   222
	}
skamonkey@3743
   223
skamonkey@3743
   224
	inline bool GetUInt32(const char *pszFieldName, uint32 *out)
skamonkey@3743
   225
	{
skamonkey@3743
   226
		GETCHECK_FIELD();
skamonkey@3743
   227
		CHECK_FIELD_TYPE(UINT32);
skamonkey@3743
   228
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   229
skamonkey@3743
   230
		*out = msg->GetReflection()->GetUInt32(*msg, field);
skamonkey@3743
   231
		return true;	
skamonkey@3743
   232
	}
skamonkey@3743
   233
skamonkey@3743
   234
	inline bool SetUInt32(const char *pszFieldName, uint32 value)
skamonkey@3743
   235
	{
skamonkey@3743
   236
		GETCHECK_FIELD();
skamonkey@3743
   237
		CHECK_FIELD_TYPE(UINT32);
skamonkey@3743
   238
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   239
skamonkey@3743
   240
		msg->GetReflection()->SetUInt32(msg, field, value);
skamonkey@3743
   241
		return true;
skamonkey@3743
   242
	}
skamonkey@3743
   243
skamonkey@3743
   244
	inline bool GetRepeatedUInt32(const char *pszFieldName, int index, uint32 *out)
skamonkey@3743
   245
	{
skamonkey@3743
   246
		GETCHECK_FIELD();
skamonkey@3743
   247
		CHECK_FIELD_TYPE(UINT32);
skamonkey@3743
   248
		CHECK_FIELD_REPEATED();
skamonkey@3743
   249
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3743
   250
		
skamonkey@3743
   251
		*out = msg->GetReflection()->GetRepeatedUInt32(*msg, field, index);
skamonkey@3743
   252
		return true;
skamonkey@3743
   253
	}
skamonkey@3743
   254
skamonkey@3814
   255
	inline bool SetRepeatedUInt32(const char *pszFieldName, int index, uint32 value)
skamonkey@3814
   256
	{
skamonkey@3814
   257
		GETCHECK_FIELD();
skamonkey@3814
   258
		CHECK_FIELD_TYPE(UINT32);
skamonkey@3814
   259
		CHECK_FIELD_REPEATED();
skamonkey@3814
   260
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3814
   261
		
skamonkey@3814
   262
		msg->GetReflection()->SetRepeatedUInt32(msg, field, index, value);
skamonkey@3814
   263
		return true;
skamonkey@3814
   264
	}
skamonkey@3814
   265
skamonkey@3743
   266
	inline bool AddUInt32(const char *pszFieldName, uint32 value)
skamonkey@3743
   267
	{
skamonkey@3743
   268
		GETCHECK_FIELD();
skamonkey@3743
   269
		CHECK_FIELD_TYPE(UINT32);
skamonkey@3743
   270
		CHECK_FIELD_REPEATED();
skamonkey@3743
   271
skamonkey@3743
   272
		msg->GetReflection()->AddUInt32(msg, field, value);
skamonkey@3743
   273
		return true;
skamonkey@3743
   274
	}
skamonkey@3743
   275
skamonkey@3743
   276
	inline bool GetUInt64(const char *pszFieldName, uint64 *out)
skamonkey@3743
   277
	{
skamonkey@3743
   278
		GETCHECK_FIELD();
skamonkey@3743
   279
		CHECK_FIELD_TYPE(UINT64);
skamonkey@3743
   280
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   281
skamonkey@3743
   282
		*out = msg->GetReflection()->GetUInt64(*msg, field);
skamonkey@3743
   283
		return true;	
skamonkey@3743
   284
	}
skamonkey@3743
   285
skamonkey@3743
   286
	inline bool SetUInt64(const char *pszFieldName, uint64 value)
skamonkey@3743
   287
	{
skamonkey@3743
   288
		GETCHECK_FIELD();
skamonkey@3743
   289
		CHECK_FIELD_TYPE(UINT64);
skamonkey@3743
   290
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   291
skamonkey@3743
   292
		msg->GetReflection()->SetUInt64(msg, field, value);
skamonkey@3743
   293
		return true;
skamonkey@3743
   294
	}
skamonkey@3743
   295
skamonkey@3743
   296
	inline bool GetRepeatedUInt64(const char *pszFieldName, int index, uint64 *out)
skamonkey@3743
   297
	{
skamonkey@3743
   298
		GETCHECK_FIELD();
skamonkey@3743
   299
		CHECK_FIELD_TYPE(UINT64);
skamonkey@3743
   300
		CHECK_FIELD_REPEATED();
skamonkey@3743
   301
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3743
   302
		
skamonkey@3743
   303
		*out = msg->GetReflection()->GetRepeatedUInt64(*msg, field, index);
skamonkey@3743
   304
		return true;
skamonkey@3743
   305
	}
skamonkey@3743
   306
skamonkey@3814
   307
	inline bool SetRepeatedUInt64(const char *pszFieldName, int index, uint64 value)
skamonkey@3814
   308
	{
skamonkey@3814
   309
		GETCHECK_FIELD();
skamonkey@3814
   310
		CHECK_FIELD_TYPE(UINT64);
skamonkey@3814
   311
		CHECK_FIELD_REPEATED();
skamonkey@3814
   312
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3814
   313
		
skamonkey@3814
   314
		msg->GetReflection()->SetRepeatedUInt64(msg, field, index, value);
skamonkey@3814
   315
		return true;
skamonkey@3814
   316
	}
skamonkey@3814
   317
skamonkey@3743
   318
	inline bool AddUInt64(const char *pszFieldName, uint64 value)
skamonkey@3743
   319
	{
skamonkey@3743
   320
		GETCHECK_FIELD();
skamonkey@3743
   321
		CHECK_FIELD_TYPE(UINT64);
skamonkey@3743
   322
		CHECK_FIELD_REPEATED();
skamonkey@3743
   323
skamonkey@3743
   324
		msg->GetReflection()->AddUInt32(msg, field, value);
skamonkey@3743
   325
		return true;
skamonkey@3743
   326
	}
skamonkey@3743
   327
skamonkey@3896
   328
	inline bool GetInt32OrUnsignedOrEnum(const char *pszFieldName, int32 *out)
skamonkey@3743
   329
	{
skamonkey@3743
   330
		GETCHECK_FIELD();
skamonkey@3896
   331
		CHECK_FIELD_TYPE3(INT32, UINT32, ENUM);
skamonkey@3743
   332
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   333
skamonkey@3743
   334
		if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
skamonkey@3743
   335
			*out = (int32)msg->GetReflection()->GetUInt32(*msg, field);
skamonkey@3896
   336
		else if (fieldType == protobuf::FieldDescriptor::CPPTYPE_INT32)
skamonkey@3743
   337
			*out = msg->GetReflection()->GetInt32(*msg, field);
skamonkey@3896
   338
		else // CPPTYPE_ENUM
skamonkey@3896
   339
			*out = msg->GetReflection()->GetEnum(*msg, field)->number();
skamonkey@3743
   340
skamonkey@3743
   341
		return true;	
skamonkey@3743
   342
	}
skamonkey@3743
   343
skamonkey@3896
   344
	inline bool SetInt32OrUnsignedOrEnum(const char *pszFieldName, int32 value)
skamonkey@3743
   345
	{
skamonkey@3743
   346
		GETCHECK_FIELD();
skamonkey@3896
   347
		CHECK_FIELD_TYPE3(INT32, UINT32, ENUM);
skamonkey@3743
   348
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   349
skamonkey@3743
   350
		if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
skamonkey@3896
   351
		{
skamonkey@3743
   352
			msg->GetReflection()->SetUInt32(msg, field, (uint32)value);
skamonkey@3896
   353
		}
skamonkey@3896
   354
		else if (fieldType == protobuf::FieldDescriptor::CPPTYPE_INT32)
skamonkey@3896
   355
		{
skamonkey@3743
   356
			msg->GetReflection()->SetInt32(msg, field, value);
skamonkey@3896
   357
		}
skamonkey@3896
   358
		else // CPPTYPE_ENUM
skamonkey@3896
   359
		{
skamonkey@3896
   360
			const protobuf::EnumValueDescriptor *pEnumValue = field->enum_type()->FindValueByNumber(value);
skamonkey@3896
   361
			if (!pEnumValue)
skamonkey@3896
   362
				return false;
skamonkey@3896
   363
skamonkey@3896
   364
			msg->GetReflection()->SetEnum(msg, field, pEnumValue);
skamonkey@3896
   365
		}
skamonkey@3743
   366
skamonkey@3743
   367
		return true;
skamonkey@3743
   368
	}
skamonkey@3743
   369
skamonkey@3896
   370
	inline bool GetRepeatedInt32OrUnsignedOrEnum(const char *pszFieldName, int index, int32 *out)
skamonkey@3743
   371
	{
skamonkey@3743
   372
		GETCHECK_FIELD();
skamonkey@3896
   373
		CHECK_FIELD_TYPE3(INT32, UINT32, ENUM);
skamonkey@3743
   374
		CHECK_FIELD_REPEATED();
skamonkey@3743
   375
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3743
   376
		
skamonkey@3743
   377
		if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
skamonkey@3743
   378
			*out = (int32)msg->GetReflection()->GetRepeatedUInt32(*msg, field, index);
skamonkey@3896
   379
		else if (fieldType == protobuf::FieldDescriptor::CPPTYPE_INT32)
skamonkey@3743
   380
			*out = msg->GetReflection()->GetRepeatedInt32(*msg, field, index);
skamonkey@3896
   381
		else // CPPTYPE_ENUM
skamonkey@3896
   382
			*out = msg->GetReflection()->GetRepeatedEnum(*msg, field, index)->number();
skamonkey@3743
   383
skamonkey@3743
   384
		return true;
skamonkey@3743
   385
	}
skamonkey@3743
   386
skamonkey@3896
   387
	inline bool SetRepeatedInt32OrUnsignedOrEnum(const char *pszFieldName, int index, int32 value)
skamonkey@3814
   388
	{
skamonkey@3814
   389
		GETCHECK_FIELD();
skamonkey@3896
   390
		CHECK_FIELD_TYPE3(INT32, UINT32, ENUM);
skamonkey@3814
   391
		CHECK_FIELD_REPEATED();
skamonkey@3814
   392
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3814
   393
		
skamonkey@3814
   394
		if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
skamonkey@3896
   395
		{
skamonkey@3814
   396
			msg->GetReflection()->SetRepeatedUInt32(msg, field, index, (uint32)value);
skamonkey@3896
   397
		}
skamonkey@3896
   398
		else if (fieldType == protobuf::FieldDescriptor::CPPTYPE_INT32)
skamonkey@3896
   399
		{
skamonkey@3814
   400
			msg->GetReflection()->SetRepeatedInt32(msg, field, index, value);
skamonkey@3896
   401
		}
skamonkey@3896
   402
		else // CPPTYPE_ENUM
skamonkey@3896
   403
		{
skamonkey@3896
   404
			const protobuf::EnumValueDescriptor *pEnumValue = field->enum_type()->FindValueByNumber(value);
skamonkey@3896
   405
			if (!pEnumValue)
skamonkey@3896
   406
				return false;
skamonkey@3896
   407
skamonkey@3896
   408
			msg->GetReflection()->SetRepeatedEnum(msg, field, index, pEnumValue);
skamonkey@3896
   409
		}
skamonkey@3814
   410
skamonkey@3814
   411
		return true;
skamonkey@3814
   412
	}
skamonkey@3814
   413
skamonkey@3896
   414
	inline bool AddInt32OrUnsignedOrEnum(const char *pszFieldName, int32 value)
skamonkey@3743
   415
	{
skamonkey@3743
   416
		GETCHECK_FIELD();
skamonkey@3896
   417
		CHECK_FIELD_TYPE3(INT32, UINT32, ENUM);
skamonkey@3743
   418
		CHECK_FIELD_REPEATED();
skamonkey@3743
   419
skamonkey@3743
   420
		if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
skamonkey@3896
   421
		{
skamonkey@3743
   422
			msg->GetReflection()->AddUInt32(msg, field, (uint32)value);
skamonkey@3896
   423
		}
skamonkey@3896
   424
		else if (fieldType == protobuf::FieldDescriptor::CPPTYPE_INT32)
skamonkey@3896
   425
		{
skamonkey@3743
   426
			msg->GetReflection()->AddInt32(msg, field, value);
skamonkey@3896
   427
		}
skamonkey@3896
   428
		else // CPPTYPE_ENUM
skamonkey@3896
   429
		{
skamonkey@3896
   430
			const protobuf::EnumValueDescriptor *pEnumValue = field->enum_type()->FindValueByNumber(value);
skamonkey@3896
   431
			if (!pEnumValue)
skamonkey@3896
   432
				return false;
skamonkey@3896
   433
skamonkey@3896
   434
			msg->GetReflection()->AddEnum(msg, field, pEnumValue);
skamonkey@3896
   435
		}
skamonkey@3743
   436
skamonkey@3743
   437
		return true;
skamonkey@3743
   438
	}
skamonkey@3743
   439
skamonkey@3743
   440
	inline bool GetBool(const char *pszFieldName, bool *out)
skamonkey@3743
   441
	{
skamonkey@3743
   442
		GETCHECK_FIELD();
skamonkey@3743
   443
		CHECK_FIELD_TYPE(BOOL);
skamonkey@3743
   444
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   445
skamonkey@3743
   446
		*out = msg->GetReflection()->GetBool(*msg, field);
skamonkey@3743
   447
		return true;	
skamonkey@3743
   448
	}
skamonkey@3743
   449
skamonkey@3743
   450
	inline bool SetBool(const char *pszFieldName, bool value)
skamonkey@3743
   451
	{
skamonkey@3743
   452
		GETCHECK_FIELD();
skamonkey@3743
   453
		CHECK_FIELD_TYPE(BOOL);
skamonkey@3743
   454
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   455
skamonkey@3743
   456
		msg->GetReflection()->SetBool(msg, field, value);
skamonkey@3743
   457
		return true;
skamonkey@3743
   458
	}
skamonkey@3743
   459
skamonkey@3743
   460
	inline bool GetRepeatedBool(const char *pszFieldName, int index, bool *out)
skamonkey@3743
   461
	{
skamonkey@3743
   462
		GETCHECK_FIELD();
skamonkey@3743
   463
		CHECK_FIELD_TYPE(BOOL);
skamonkey@3743
   464
		CHECK_FIELD_REPEATED();
skamonkey@3743
   465
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3743
   466
		
skamonkey@3743
   467
		*out = msg->GetReflection()->GetRepeatedBool(*msg, field, index);
skamonkey@3743
   468
		return true;
skamonkey@3743
   469
	}
skamonkey@3743
   470
skamonkey@3814
   471
	inline bool SetRepeatedBool(const char *pszFieldName, int index, bool value)
skamonkey@3814
   472
	{
skamonkey@3814
   473
		GETCHECK_FIELD();
skamonkey@3814
   474
		CHECK_FIELD_TYPE(BOOL);
skamonkey@3814
   475
		CHECK_FIELD_REPEATED();
skamonkey@3814
   476
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3814
   477
		
skamonkey@3814
   478
		msg->GetReflection()->SetRepeatedBool(msg, field, index, value);
skamonkey@3814
   479
		return true;
skamonkey@3814
   480
	}
skamonkey@3814
   481
skamonkey@3743
   482
	inline bool AddBool(const char *pszFieldName, bool value)
skamonkey@3743
   483
	{
skamonkey@3743
   484
		GETCHECK_FIELD();
skamonkey@3743
   485
		CHECK_FIELD_TYPE(BOOL);
skamonkey@3743
   486
		CHECK_FIELD_REPEATED();
skamonkey@3743
   487
skamonkey@3743
   488
		msg->GetReflection()->AddBool(msg, field, value);
skamonkey@3743
   489
		return true;
skamonkey@3743
   490
	}
skamonkey@3743
   491
skamonkey@3743
   492
	inline bool GetFloat(const char *pszFieldName, float *out)
skamonkey@3743
   493
	{
skamonkey@3743
   494
		GETCHECK_FIELD();
skamonkey@3743
   495
		CHECK_FIELD_TYPE(FLOAT);
skamonkey@3743
   496
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   497
skamonkey@3743
   498
		*out = msg->GetReflection()->GetFloat(*msg, field);
skamonkey@3743
   499
		return true;	
skamonkey@3743
   500
	}
skamonkey@3743
   501
skamonkey@3743
   502
	inline bool SetFloat(const char *pszFieldName, float value)
skamonkey@3743
   503
	{
skamonkey@3743
   504
		GETCHECK_FIELD();
skamonkey@3743
   505
		CHECK_FIELD_TYPE(FLOAT);
skamonkey@3743
   506
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   507
skamonkey@3743
   508
		msg->GetReflection()->SetFloat(msg, field, value);
skamonkey@3743
   509
		return true;
skamonkey@3743
   510
	}
skamonkey@3743
   511
skamonkey@3743
   512
	inline bool GetRepeatedFloat(const char *pszFieldName, int index, float *out)
skamonkey@3743
   513
	{
skamonkey@3743
   514
		GETCHECK_FIELD();
skamonkey@3743
   515
		CHECK_FIELD_TYPE(FLOAT);
skamonkey@3743
   516
		CHECK_FIELD_REPEATED();
skamonkey@3743
   517
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3743
   518
		
skamonkey@3743
   519
		*out = msg->GetReflection()->GetRepeatedFloat(*msg, field, index);
skamonkey@3743
   520
		return true;
skamonkey@3743
   521
	}
skamonkey@3743
   522
skamonkey@3814
   523
	inline bool SetRepeatedFloat(const char *pszFieldName, int index, float value)
skamonkey@3814
   524
	{
skamonkey@3814
   525
		GETCHECK_FIELD();
skamonkey@3814
   526
		CHECK_FIELD_TYPE(FLOAT);
skamonkey@3814
   527
		CHECK_FIELD_REPEATED();
skamonkey@3814
   528
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3814
   529
		
skamonkey@3814
   530
		msg->GetReflection()->SetRepeatedFloat(msg, field, index, value);
skamonkey@3814
   531
		return true;
skamonkey@3814
   532
	}
skamonkey@3814
   533
skamonkey@3743
   534
	inline bool AddFloat(const char *pszFieldName, float value)
skamonkey@3743
   535
	{
skamonkey@3743
   536
		GETCHECK_FIELD();
skamonkey@3743
   537
		CHECK_FIELD_TYPE(FLOAT);
skamonkey@3743
   538
		CHECK_FIELD_REPEATED();
skamonkey@3743
   539
skamonkey@3743
   540
		msg->GetReflection()->AddFloat(msg, field, value);
skamonkey@3743
   541
		return true;
skamonkey@3743
   542
	}
skamonkey@3743
   543
skamonkey@3743
   544
	inline bool GetDouble(const char *pszFieldName, double *out)
skamonkey@3743
   545
	{
skamonkey@3743
   546
		GETCHECK_FIELD();
skamonkey@3743
   547
		CHECK_FIELD_TYPE(DOUBLE);
skamonkey@3743
   548
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   549
skamonkey@3743
   550
		*out = msg->GetReflection()->GetDouble(*msg, field);
skamonkey@3743
   551
		return true;	
skamonkey@3743
   552
	}
skamonkey@3743
   553
skamonkey@3743
   554
	inline bool SetDouble(const char *pszFieldName, double value)
skamonkey@3743
   555
	{
skamonkey@3743
   556
		GETCHECK_FIELD();
skamonkey@3743
   557
		CHECK_FIELD_TYPE(DOUBLE);
skamonkey@3743
   558
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   559
skamonkey@3743
   560
		msg->GetReflection()->SetDouble(msg, field, value);
skamonkey@3743
   561
		return true;
skamonkey@3743
   562
	}
skamonkey@3743
   563
skamonkey@3743
   564
	inline bool GetRepeatedDouble(const char *pszFieldName, int index, double *out)
skamonkey@3743
   565
	{
skamonkey@3743
   566
		GETCHECK_FIELD();
skamonkey@3743
   567
		CHECK_FIELD_TYPE(DOUBLE);
skamonkey@3743
   568
		CHECK_FIELD_REPEATED();
skamonkey@3743
   569
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3743
   570
		
skamonkey@3743
   571
		*out = msg->GetReflection()->GetRepeatedDouble(*msg, field, index);
skamonkey@3743
   572
		return true;
skamonkey@3743
   573
	}
skamonkey@3743
   574
skamonkey@3814
   575
	inline bool SetRepeatedDouble(const char *pszFieldName, int index, double value)
skamonkey@3814
   576
	{
skamonkey@3814
   577
		GETCHECK_FIELD();
skamonkey@3814
   578
		CHECK_FIELD_TYPE(DOUBLE);
skamonkey@3814
   579
		CHECK_FIELD_REPEATED();
skamonkey@3814
   580
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3814
   581
		
skamonkey@3814
   582
		msg->GetReflection()->SetRepeatedDouble(msg, field, index, value);
skamonkey@3814
   583
		return true;
skamonkey@3814
   584
	}
skamonkey@3814
   585
skamonkey@3743
   586
	inline bool AddDouble(const char *pszFieldName, double value)
skamonkey@3743
   587
	{
skamonkey@3743
   588
		GETCHECK_FIELD();
skamonkey@3743
   589
		CHECK_FIELD_TYPE(DOUBLE);
skamonkey@3743
   590
		CHECK_FIELD_REPEATED();
skamonkey@3743
   591
skamonkey@3743
   592
		msg->GetReflection()->AddDouble(msg, field, value);
skamonkey@3743
   593
		return true;
skamonkey@3743
   594
	}
skamonkey@3743
   595
skamonkey@3743
   596
	inline bool GetFloatOrDouble(const char *pszFieldName, float *out)
skamonkey@3743
   597
	{
skamonkey@3743
   598
		GETCHECK_FIELD();
skamonkey@3743
   599
		CHECK_FIELD_TYPE2(FLOAT, DOUBLE);
skamonkey@3743
   600
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   601
skamonkey@3743
   602
		if (fieldType == protobuf::FieldDescriptor::CPPTYPE_DOUBLE)
skamonkey@3743
   603
			*out = (float)msg->GetReflection()->GetDouble(*msg, field);
skamonkey@3743
   604
		else
skamonkey@3743
   605
			*out = msg->GetReflection()->GetFloat(*msg, field);
skamonkey@3743
   606
skamonkey@3743
   607
		return true;	
skamonkey@3743
   608
	}
skamonkey@3743
   609
skamonkey@3743
   610
	inline bool SetFloatOrDouble(const char *pszFieldName, float value)
skamonkey@3743
   611
	{
skamonkey@3743
   612
		GETCHECK_FIELD();
skamonkey@3743
   613
		CHECK_FIELD_TYPE2(FLOAT, DOUBLE);
skamonkey@3743
   614
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   615
skamonkey@3743
   616
		if (fieldType == protobuf::FieldDescriptor::CPPTYPE_DOUBLE)
skamonkey@3743
   617
			msg->GetReflection()->SetDouble(msg, field, (double)value);
skamonkey@3743
   618
		else
skamonkey@3743
   619
			msg->GetReflection()->SetFloat(msg, field, value);
skamonkey@3743
   620
skamonkey@3743
   621
		return true;
skamonkey@3743
   622
	}
skamonkey@3743
   623
skamonkey@3743
   624
	inline bool GetRepeatedFloatOrDouble(const char *pszFieldName, int index, float *out)
skamonkey@3743
   625
	{
skamonkey@3743
   626
		GETCHECK_FIELD();
skamonkey@3743
   627
		CHECK_FIELD_TYPE2(FLOAT, DOUBLE);
skamonkey@3743
   628
		CHECK_FIELD_REPEATED();
skamonkey@3743
   629
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3743
   630
		
skamonkey@3743
   631
		if (fieldType == protobuf::FieldDescriptor::CPPTYPE_DOUBLE)
skamonkey@3743
   632
			*out = (float)msg->GetReflection()->GetRepeatedDouble(*msg, field, index);
skamonkey@3743
   633
		else
skamonkey@3743
   634
			*out = msg->GetReflection()->GetRepeatedFloat(*msg, field, index);
skamonkey@3743
   635
skamonkey@3743
   636
		return true;
skamonkey@3743
   637
	}
skamonkey@3743
   638
skamonkey@3814
   639
	inline bool SetRepeatedFloatOrDouble(const char *pszFieldName, int index, float value)
skamonkey@3814
   640
	{
skamonkey@3814
   641
		GETCHECK_FIELD();
skamonkey@3814
   642
		CHECK_FIELD_TYPE2(FLOAT, DOUBLE);
skamonkey@3814
   643
		CHECK_FIELD_REPEATED();
skamonkey@3814
   644
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3814
   645
		
skamonkey@3814
   646
		if (fieldType == protobuf::FieldDescriptor::CPPTYPE_DOUBLE)
skamonkey@3814
   647
			msg->GetReflection()->SetRepeatedDouble(msg, field, index, (double)value);
skamonkey@3814
   648
		else
skamonkey@3814
   649
			msg->GetReflection()->SetRepeatedFloat(msg, field, index, value);
skamonkey@3814
   650
skamonkey@3814
   651
		return true;
skamonkey@3814
   652
	}
skamonkey@3814
   653
skamonkey@3743
   654
	inline bool AddFloatOrDouble(const char *pszFieldName, float value)
skamonkey@3743
   655
	{
skamonkey@3743
   656
		GETCHECK_FIELD();
skamonkey@3743
   657
		CHECK_FIELD_TYPE2(FLOAT, DOUBLE);
skamonkey@3743
   658
		CHECK_FIELD_REPEATED();
skamonkey@3743
   659
skamonkey@3743
   660
		if (fieldType == protobuf::FieldDescriptor::CPPTYPE_DOUBLE)
skamonkey@3743
   661
			msg->GetReflection()->AddDouble(msg, field, (double)value);
skamonkey@3743
   662
		else
skamonkey@3743
   663
			msg->GetReflection()->AddFloat(msg, field, value);
skamonkey@3743
   664
skamonkey@3743
   665
		return true;
skamonkey@3743
   666
	}
skamonkey@3743
   667
skamonkey@3743
   668
	inline bool GetString(const char *pszFieldName, char *out, int size)
skamonkey@3743
   669
	{
skamonkey@3743
   670
		GETCHECK_FIELD();
skamonkey@3743
   671
		CHECK_FIELD_TYPE(STRING);
skamonkey@3743
   672
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   673
skamonkey@3743
   674
		std::string scratch;
skamonkey@3746
   675
		strncopy(out, msg->GetReflection()->GetStringReference(*msg, field, &scratch).c_str(), size);
skamonkey@3743
   676
skamonkey@3743
   677
		return true;	
skamonkey@3743
   678
	}
skamonkey@3743
   679
skamonkey@3743
   680
	inline bool SetString(const char *pszFieldName, const char *value)
skamonkey@3743
   681
	{
skamonkey@3743
   682
		GETCHECK_FIELD();
skamonkey@3743
   683
		CHECK_FIELD_TYPE(STRING);
skamonkey@3743
   684
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   685
skamonkey@3743
   686
		msg->GetReflection()->SetString(msg, field, value);
skamonkey@3743
   687
		return true;
skamonkey@3743
   688
	}
skamonkey@3743
   689
skamonkey@3743
   690
	inline bool GetRepeatedString(const char *pszFieldName, int index, char *out, int size)
skamonkey@3743
   691
	{
skamonkey@3743
   692
		GETCHECK_FIELD();
skamonkey@3743
   693
		CHECK_FIELD_TYPE(STRING);
skamonkey@3743
   694
		CHECK_FIELD_REPEATED();
skamonkey@3743
   695
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3743
   696
		
skamonkey@3743
   697
		std::string scratch;
skamonkey@3743
   698
		strncopy(out, msg->GetReflection()->GetRepeatedStringReference(*msg, field, index, &scratch).c_str(), size);
skamonkey@3743
   699
skamonkey@3743
   700
		return true;
skamonkey@3743
   701
	}
skamonkey@3743
   702
skamonkey@3814
   703
	inline bool SetRepeatedString(const char *pszFieldName, int index, const char *value)
skamonkey@3814
   704
	{
skamonkey@3814
   705
		GETCHECK_FIELD();
skamonkey@3814
   706
		CHECK_FIELD_TYPE(STRING);
skamonkey@3814
   707
		CHECK_FIELD_REPEATED();
skamonkey@3814
   708
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3814
   709
		
skamonkey@3814
   710
		msg->GetReflection()->SetRepeatedString(msg, field, index, value);
skamonkey@3814
   711
skamonkey@3814
   712
		return true;
skamonkey@3814
   713
	}
skamonkey@3814
   714
skamonkey@3743
   715
	inline bool AddString(const char *pszFieldName, const char *value)
skamonkey@3743
   716
	{
skamonkey@3743
   717
		GETCHECK_FIELD();
skamonkey@3743
   718
		CHECK_FIELD_TYPE(STRING);
skamonkey@3743
   719
		CHECK_FIELD_REPEATED();
skamonkey@3743
   720
skamonkey@3743
   721
		msg->GetReflection()->AddString(msg, field, value);
skamonkey@3743
   722
		return true;
skamonkey@3743
   723
	}
skamonkey@3743
   724
skamonkey@3743
   725
	inline bool GetColor(const char *pszFieldName, Color *out)
skamonkey@3743
   726
	{
skamonkey@3855
   727
#if SOURCE_ENGINE != SE_CSGO
skamonkey@3855
   728
		return false;
skamonkey@3855
   729
#else
skamonkey@3743
   730
		GETCHECK_FIELD();
skamonkey@3743
   731
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3743
   732
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   733
skamonkey@3743
   734
		const CMsgRGBA &msgRGBA = (const CMsgRGBA &)msg->GetReflection()->GetMessage(*msg, field);
skamonkey@3743
   735
		out->SetColor(
skamonkey@3743
   736
			msgRGBA.r(),
skamonkey@3743
   737
			msgRGBA.g(),
skamonkey@3743
   738
			msgRGBA.b(),
skamonkey@3743
   739
			msgRGBA.a()
skamonkey@3743
   740
			);
skamonkey@3743
   741
skamonkey@3743
   742
		return true;
skamonkey@3855
   743
#endif
skamonkey@3743
   744
	}
skamonkey@3743
   745
skamonkey@3743
   746
	inline bool SetColor(const char *pszFieldName, const Color &value)
skamonkey@3743
   747
	{
skamonkey@3855
   748
#if SOURCE_ENGINE != SE_CSGO
skamonkey@3855
   749
		return false;
skamonkey@3855
   750
#else
skamonkey@3743
   751
		GETCHECK_FIELD();
skamonkey@3743
   752
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3743
   753
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   754
skamonkey@3743
   755
		CMsgRGBA *msgRGBA = (CMsgRGBA *)msg->GetReflection()->MutableMessage(msg, field);
skamonkey@3743
   756
		msgRGBA->set_r(value.r());
skamonkey@3743
   757
		msgRGBA->set_g(value.g());
skamonkey@3743
   758
		msgRGBA->set_b(value.b());
skamonkey@3743
   759
		msgRGBA->set_a(value.a());
skamonkey@3743
   760
skamonkey@3743
   761
		return true;
skamonkey@3855
   762
#endif
skamonkey@3743
   763
	}
skamonkey@3743
   764
skamonkey@3743
   765
	inline bool GetRepeatedColor(const char *pszFieldName, int index, Color *out)
skamonkey@3743
   766
	{
skamonkey@3855
   767
#if SOURCE_ENGINE != SE_CSGO
skamonkey@3855
   768
		return false;
skamonkey@3855
   769
#else
skamonkey@3743
   770
		GETCHECK_FIELD();
skamonkey@3743
   771
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3743
   772
		CHECK_FIELD_REPEATED();
skamonkey@3743
   773
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3743
   774
skamonkey@3743
   775
		const CMsgRGBA &msgRGBA = (const CMsgRGBA &)msg->GetReflection()->GetRepeatedMessage(*msg, field, index);
skamonkey@3743
   776
		out->SetColor(
skamonkey@3743
   777
			msgRGBA.r(),
skamonkey@3743
   778
			msgRGBA.g(),
skamonkey@3743
   779
			msgRGBA.b(),
skamonkey@3743
   780
			msgRGBA.a()
skamonkey@3743
   781
			);
skamonkey@3743
   782
skamonkey@3743
   783
		return true;
skamonkey@3855
   784
#endif
skamonkey@3743
   785
	}
skamonkey@3743
   786
skamonkey@3814
   787
	inline bool SetRepeatedColor(const char *pszFieldName, int index, const Color &value)
skamonkey@3814
   788
	{
skamonkey@3855
   789
#if SOURCE_ENGINE != SE_CSGO
skamonkey@3855
   790
		return false;
skamonkey@3855
   791
#else
skamonkey@3814
   792
		GETCHECK_FIELD();
skamonkey@3814
   793
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3814
   794
		CHECK_FIELD_REPEATED();
skamonkey@3814
   795
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3814
   796
skamonkey@3814
   797
		CMsgRGBA *msgRGBA = (CMsgRGBA *)msg->GetReflection()->MutableRepeatedMessage(msg, field, index);
skamonkey@3814
   798
		msgRGBA->set_r(value.r());
skamonkey@3814
   799
		msgRGBA->set_g(value.g());
skamonkey@3814
   800
		msgRGBA->set_b(value.b());
skamonkey@3814
   801
		msgRGBA->set_a(value.a());
skamonkey@3814
   802
skamonkey@3814
   803
		return true;
skamonkey@3855
   804
#endif
skamonkey@3814
   805
	}
skamonkey@3814
   806
skamonkey@3743
   807
	inline bool AddColor(const char *pszFieldName, const Color &value)
skamonkey@3743
   808
	{
skamonkey@3855
   809
#if SOURCE_ENGINE != SE_CSGO
skamonkey@3855
   810
		return false;
skamonkey@3855
   811
#else
skamonkey@3743
   812
		GETCHECK_FIELD();
skamonkey@3743
   813
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3743
   814
		CHECK_FIELD_REPEATED();
skamonkey@3743
   815
skamonkey@3743
   816
		CMsgRGBA *msgRGBA = (CMsgRGBA *)msg->GetReflection()->AddMessage(msg, field);
skamonkey@3743
   817
		msgRGBA->set_r(value.r());
skamonkey@3743
   818
		msgRGBA->set_g(value.g());
skamonkey@3743
   819
		msgRGBA->set_b(value.b());
skamonkey@3743
   820
		msgRGBA->set_a(value.a());
skamonkey@3743
   821
skamonkey@3743
   822
		return true;
skamonkey@3855
   823
#endif
skamonkey@3743
   824
	}
skamonkey@3743
   825
skamonkey@3743
   826
	inline bool GetVector2D(const char *pszFieldName, Vector2D *out)
skamonkey@3743
   827
	{
skamonkey@3743
   828
		GETCHECK_FIELD();
skamonkey@3743
   829
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3743
   830
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   831
skamonkey@3743
   832
		const CMsgVector2D &msgVec2d = (const CMsgVector2D &)msg->GetReflection()->GetMessage(*msg, field);
skamonkey@3743
   833
		out->Init(
skamonkey@3743
   834
			msgVec2d.x(),
skamonkey@3743
   835
			msgVec2d.y()
skamonkey@3743
   836
			);
skamonkey@3743
   837
skamonkey@3743
   838
		return true;
skamonkey@3743
   839
	}
skamonkey@3743
   840
skamonkey@3743
   841
	inline bool SetVector2D(const char *pszFieldName, Vector2D &vec)
skamonkey@3743
   842
	{
skamonkey@3743
   843
		GETCHECK_FIELD();
skamonkey@3743
   844
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3743
   845
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   846
skamonkey@3743
   847
		CMsgVector2D *msgVec2d = (CMsgVector2D *)msg->GetReflection()->MutableMessage(msg, field);
skamonkey@3743
   848
		msgVec2d->set_x(vec.x);
skamonkey@3743
   849
		msgVec2d->set_y(vec.y);
skamonkey@3743
   850
skamonkey@3743
   851
		return true;
skamonkey@3743
   852
	}
skamonkey@3743
   853
skamonkey@3743
   854
	inline bool GetRepeatedVector2D(const char *pszFieldName, int index, Vector2D *out)
skamonkey@3743
   855
	{
skamonkey@3743
   856
		GETCHECK_FIELD();
skamonkey@3743
   857
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3743
   858
		CHECK_FIELD_REPEATED();
skamonkey@3743
   859
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3743
   860
skamonkey@3743
   861
		const CMsgVector2D &msgVec2d = (const CMsgVector2D &)msg->GetReflection()->GetRepeatedMessage(*msg, field, index);
skamonkey@3743
   862
		out->Init(
skamonkey@3743
   863
			msgVec2d.x(),
skamonkey@3743
   864
			msgVec2d.y()
skamonkey@3743
   865
			);
skamonkey@3743
   866
skamonkey@3743
   867
		return true;
skamonkey@3743
   868
	}
skamonkey@3743
   869
skamonkey@3814
   870
	inline bool SetRepeatedVector2D(const char *pszFieldName, int index, Vector2D &vec)
skamonkey@3814
   871
	{
skamonkey@3814
   872
		GETCHECK_FIELD();
skamonkey@3814
   873
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3814
   874
		CHECK_FIELD_REPEATED();
skamonkey@3814
   875
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3814
   876
skamonkey@3814
   877
		CMsgVector2D *msgVec2d = (CMsgVector2D *)msg->GetReflection()->MutableRepeatedMessage(msg, field, index);
skamonkey@3814
   878
		msgVec2d->set_x(vec.x);
skamonkey@3814
   879
		msgVec2d->set_y(vec.y);
skamonkey@3814
   880
skamonkey@3814
   881
		return true;
skamonkey@3814
   882
	}
skamonkey@3814
   883
skamonkey@3743
   884
	inline bool AddVector2D(const char *pszFieldName, Vector2D &vec)
skamonkey@3743
   885
	{
skamonkey@3743
   886
		GETCHECK_FIELD();
skamonkey@3743
   887
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3743
   888
		CHECK_FIELD_REPEATED();
skamonkey@3743
   889
skamonkey@3743
   890
		CMsgVector2D *msgVec2d = (CMsgVector2D *)msg->GetReflection()->AddMessage(msg, field);
skamonkey@3743
   891
		msgVec2d->set_x(vec.x);
skamonkey@3743
   892
		msgVec2d->set_y(vec.y);
skamonkey@3743
   893
skamonkey@3743
   894
		return true;
skamonkey@3743
   895
	}
skamonkey@3743
   896
skamonkey@3743
   897
	inline bool GetVector(const char *pszFieldName, Vector *out)
skamonkey@3743
   898
	{
skamonkey@3743
   899
		GETCHECK_FIELD();
skamonkey@3743
   900
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3743
   901
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   902
skamonkey@3743
   903
		const CMsgVector &msgVec = (const CMsgVector &)msg->GetReflection()->GetMessage(*msg, field);
skamonkey@3743
   904
		out->Init(
skamonkey@3743
   905
			msgVec.x(),
skamonkey@3743
   906
			msgVec.y(),
skamonkey@3743
   907
			msgVec.z()
skamonkey@3743
   908
			);
skamonkey@3743
   909
skamonkey@3743
   910
		return true;
skamonkey@3743
   911
	}
skamonkey@3743
   912
skamonkey@3743
   913
	inline bool SetVector(const char *pszFieldName, Vector &vec)
skamonkey@3743
   914
	{
skamonkey@3743
   915
		GETCHECK_FIELD();
skamonkey@3743
   916
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3743
   917
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   918
skamonkey@3743
   919
		CMsgVector *msgVec = (CMsgVector *)msg->GetReflection()->MutableMessage(msg, field);
skamonkey@3743
   920
		msgVec->set_x(vec.x);
skamonkey@3743
   921
		msgVec->set_y(vec.y);
skamonkey@3743
   922
		msgVec->set_z(vec.z);
skamonkey@3743
   923
skamonkey@3743
   924
		return true;
skamonkey@3743
   925
	}
skamonkey@3743
   926
skamonkey@3743
   927
	inline bool GetRepeatedVector(const char *pszFieldName, int index, Vector *out)
skamonkey@3743
   928
	{
skamonkey@3743
   929
		GETCHECK_FIELD();
skamonkey@3743
   930
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3743
   931
		CHECK_FIELD_REPEATED();
skamonkey@3743
   932
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3743
   933
skamonkey@3743
   934
		const CMsgVector &msgVec = (const CMsgVector &)msg->GetReflection()->GetRepeatedMessage(*msg, field, index);
skamonkey@3743
   935
		out->Init(
skamonkey@3743
   936
			msgVec.x(),
skamonkey@3743
   937
			msgVec.y(),
skamonkey@3743
   938
			msgVec.z()
skamonkey@3743
   939
			);
skamonkey@3743
   940
skamonkey@3743
   941
		return true;
skamonkey@3743
   942
	}
skamonkey@3743
   943
skamonkey@3814
   944
	inline bool SetRepeatedVector(const char *pszFieldName, int index, Vector &vec)
skamonkey@3814
   945
	{
skamonkey@3814
   946
		GETCHECK_FIELD();
skamonkey@3814
   947
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3814
   948
		CHECK_FIELD_REPEATED();
skamonkey@3814
   949
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3814
   950
skamonkey@3814
   951
		CMsgVector *msgVec = (CMsgVector *)msg->GetReflection()->MutableRepeatedMessage(msg, field, index);
skamonkey@3814
   952
		msgVec->set_x(vec.x);
skamonkey@3814
   953
		msgVec->set_y(vec.y);
skamonkey@3814
   954
		msgVec->set_z(vec.z);
skamonkey@3814
   955
skamonkey@3814
   956
		return true;
skamonkey@3814
   957
	}
skamonkey@3814
   958
skamonkey@3743
   959
	inline bool AddVector(const char *pszFieldName, Vector &vec)
skamonkey@3743
   960
	{
skamonkey@3743
   961
		GETCHECK_FIELD();
skamonkey@3743
   962
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3743
   963
		CHECK_FIELD_REPEATED();
skamonkey@3743
   964
skamonkey@3743
   965
		CMsgVector *msgVec = (CMsgVector *)msg->GetReflection()->AddMessage(msg, field);
skamonkey@3743
   966
		msgVec->set_x(vec.x);
skamonkey@3743
   967
		msgVec->set_y(vec.y);
skamonkey@3743
   968
		msgVec->set_z(vec.z);
skamonkey@3743
   969
skamonkey@3743
   970
		return true;
skamonkey@3743
   971
	}
skamonkey@3743
   972
skamonkey@3743
   973
	inline bool GetQAngle(const char *pszFieldName, QAngle *out)
skamonkey@3743
   974
	{
skamonkey@3743
   975
		GETCHECK_FIELD();
skamonkey@3743
   976
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3743
   977
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   978
skamonkey@3743
   979
		const CMsgQAngle &msgAng = (const CMsgQAngle &)msg->GetReflection()->GetMessage(*msg, field);
skamonkey@3743
   980
		out->Init(
skamonkey@3743
   981
			msgAng.x(),
skamonkey@3743
   982
			msgAng.y(),
skamonkey@3743
   983
			msgAng.z()
skamonkey@3743
   984
			);
skamonkey@3743
   985
skamonkey@3743
   986
		return true;
skamonkey@3743
   987
	}
skamonkey@3743
   988
skamonkey@3743
   989
	inline bool SetQAngle(const char *pszFieldName, QAngle &vec)
skamonkey@3743
   990
	{
skamonkey@3743
   991
		GETCHECK_FIELD();
skamonkey@3743
   992
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3743
   993
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
   994
skamonkey@3743
   995
		CMsgQAngle *msgAng = (CMsgQAngle *)msg->GetReflection()->MutableMessage(msg, field);
skamonkey@3743
   996
		msgAng->set_x(vec.x);
skamonkey@3743
   997
		msgAng->set_y(vec.y);
skamonkey@3743
   998
		msgAng->set_z(vec.z);
skamonkey@3743
   999
skamonkey@3743
  1000
		return true;
skamonkey@3743
  1001
	}
skamonkey@3743
  1002
skamonkey@3743
  1003
	inline bool GetRepeatedQAngle(const char *pszFieldName, int index, QAngle *out)
skamonkey@3743
  1004
	{
skamonkey@3743
  1005
		GETCHECK_FIELD();
skamonkey@3743
  1006
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3743
  1007
		CHECK_FIELD_REPEATED();
skamonkey@3743
  1008
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3743
  1009
skamonkey@3743
  1010
		const CMsgQAngle &msgAng = (const CMsgQAngle &)msg->GetReflection()->GetRepeatedMessage(*msg, field, index);
skamonkey@3743
  1011
		out->Init(
skamonkey@3743
  1012
			msgAng.x(),
skamonkey@3743
  1013
			msgAng.y(),
skamonkey@3743
  1014
			msgAng.z()
skamonkey@3743
  1015
			);
skamonkey@3743
  1016
skamonkey@3743
  1017
		return true;
skamonkey@3743
  1018
	}
skamonkey@3743
  1019
skamonkey@3814
  1020
	inline bool SetRepeatedQAngle(const char *pszFieldName, int index, QAngle &vec)
skamonkey@3814
  1021
	{
skamonkey@3814
  1022
		GETCHECK_FIELD();
skamonkey@3814
  1023
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3814
  1024
		CHECK_FIELD_REPEATED();
skamonkey@3814
  1025
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3814
  1026
skamonkey@3814
  1027
		CMsgQAngle *msgAng = (CMsgQAngle *)msg->GetReflection()->MutableRepeatedMessage(msg, field, index);
skamonkey@3814
  1028
		msgAng->set_x(vec.x);
skamonkey@3814
  1029
		msgAng->set_y(vec.y);
skamonkey@3814
  1030
		msgAng->set_z(vec.z);
skamonkey@3814
  1031
skamonkey@3814
  1032
		return true;
skamonkey@3814
  1033
	}
skamonkey@3814
  1034
skamonkey@3743
  1035
	inline bool AddQAngle(const char *pszFieldName, QAngle &vec)
skamonkey@3743
  1036
	{
skamonkey@3743
  1037
		GETCHECK_FIELD();
skamonkey@3743
  1038
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3743
  1039
		CHECK_FIELD_REPEATED();
skamonkey@3743
  1040
skamonkey@3743
  1041
		CMsgQAngle *msgAng = (CMsgQAngle *)msg->GetReflection()->AddMessage(msg, field);
skamonkey@3743
  1042
		msgAng->set_x(vec.x);
skamonkey@3743
  1043
		msgAng->set_y(vec.y);
skamonkey@3743
  1044
		msgAng->set_z(vec.z);
skamonkey@3743
  1045
skamonkey@3743
  1046
		return true;
skamonkey@3743
  1047
	}
skamonkey@3743
  1048
skamonkey@3743
  1049
	inline bool GetMessage(const char *pszFieldName, protobuf::Message **message)
skamonkey@3743
  1050
	{
skamonkey@3743
  1051
		GETCHECK_FIELD();
skamonkey@3743
  1052
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3743
  1053
		CHECK_FIELD_NOT_REPEATED();
skamonkey@3743
  1054
skamonkey@3743
  1055
		*message = msg->GetReflection()->MutableMessage(msg, field);
skamonkey@3743
  1056
skamonkey@3743
  1057
		return true;
skamonkey@3743
  1058
	}
skamonkey@3743
  1059
skamonkey@3743
  1060
	inline bool GetRepeatedMessage(const char *pszFieldName, int index, const protobuf::Message **message)
skamonkey@3743
  1061
	{
skamonkey@3743
  1062
		GETCHECK_FIELD();
skamonkey@3743
  1063
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3743
  1064
		CHECK_FIELD_REPEATED();
skamonkey@3743
  1065
		CHECK_REPEATED_ELEMENT(index);
skamonkey@3743
  1066
skamonkey@3743
  1067
		const protobuf::Message *m = &msg->GetReflection()->GetRepeatedMessage(*msg, field, index);
skamonkey@3743
  1068
		*message = m;
skamonkey@3743
  1069
skamonkey@3743
  1070
		return true;
skamonkey@3743
  1071
	}
skamonkey@3743
  1072
skamonkey@3743
  1073
	inline bool AddMessage(const char *pszFieldName, protobuf::Message **message)
skamonkey@3743
  1074
	{
skamonkey@3743
  1075
		GETCHECK_FIELD();
skamonkey@3743
  1076
		CHECK_FIELD_TYPE(MESSAGE);
skamonkey@3743
  1077
		CHECK_FIELD_REPEATED();
skamonkey@3743
  1078
skamonkey@3743
  1079
		*message = msg->GetReflection()->AddMessage(msg, field);
skamonkey@3743
  1080
skamonkey@3743
  1081
		return true;
skamonkey@3743
  1082
	}
skamonkey@3743
  1083
skamonkey@3743
  1084
	inline int GetRepeatedFieldCount(const char *pszFieldName)
skamonkey@3743
  1085
	{
skamonkey@3743
  1086
		const protobuf::FieldDescriptor *field = msg->GetDescriptor()->FindFieldByName(pszFieldName); \
skamonkey@3743
  1087
		if (!field)
skamonkey@3743
  1088
			return -1;
skamonkey@3743
  1089
skamonkey@3743
  1090
		if (field->label() != protobuf::FieldDescriptor::LABEL_REPEATED)
skamonkey@3743
  1091
			return -1;
skamonkey@3743
  1092
skamonkey@3743
  1093
		return msg->GetReflection()->FieldSize(*msg, field);
skamonkey@3743
  1094
	}
skamonkey@3743
  1095
skamonkey@3743
  1096
private:
skamonkey@3743
  1097
	protobuf::Message *msg;
skamonkey@3743
  1098
	PBHandleList childHandles;
skamonkey@3743
  1099
};
skamonkey@3743
  1100
skamonkey@3743
  1101
#endif // _INCLUDE_SOURCEMOD_SMPBMESSAGE_H_