bool UTIL_FindInSendTable(SendTable *pTable, const char *name, sm_sendprop_info_t *info, unsigned int offset) { const char *pname; int props = pTable->GetNumProps(); SendProp *prop; for (int i=0; i<props; i++) { prop = pTable->GetProp(i); pname = prop->GetName(); if (pname && strcmp(name, pname) == 0) { info->prop = prop; info->actual_offset = offset + info->prop->GetOffset(); return true; } if (prop->GetDataTable()) { if (UTIL_FindInSendTable(prop->GetDataTable(), name, info, offset + prop->GetOffset()) ) { return true; } } } return false; }
SendProp *UTIL_FindSendProp(SendTable *pTable, const char *name) { int count = pTable->GetNumProps(); //SendTable *pTable; SendProp *pProp; for (int i=0; i<count; i++) { pProp = pTable->GetProp(i); if ( g_PrintProps ) Msg("%s\n",pProp->GetName()); if (strcmp(pProp->GetName(), name) == 0) { return pProp; } if (pProp->GetDataTable()) { if ((pProp=UTIL_FindSendProp(pProp->GetDataTable(), name)) != NULL) { return pProp; } } } return NULL; }
void AddSendTable(SendTable* pTable, OffsetsMap& offsets, int offset=0, const char* baseName=NULL) { for (int i=0; i < pTable->GetNumProps(); ++i) { SendProp* pProp = pTable->GetProp(i); if (strcmp(pProp->GetName(), "baseclass") == 0) continue; int currentOffset = offset + pProp->GetOffset(); char* currentName = NULL; if (baseName == NULL) { currentName = (char*) pProp->GetName(); } else { char tempName[256]; sprintf(tempName, "%s.%s", baseName, pProp->GetName()); currentName = strdup(tempName); } if (pProp->GetType() == DPT_DataTable) { AddSendTable(pProp->GetDataTable(), offsets, currentOffset, currentName); } else { offsets.insert(std::make_pair(currentName, currentOffset)); } } }
bool WriteSendTable_R( SendTable *pTable, bf_write &bfWrite, bool bNeedsDecoder ) { if( pTable->GetWriteFlag() ) return true; pTable->SetWriteFlag( true ); // Send the version with the exclude props. bfWrite.WriteOneBit( 1 ); bfWrite.WriteOneBit( bNeedsDecoder?1:0 ); if( !SendTable_WriteInfos( pTable, &bfWrite ) ) return false; for( int i=0; i < pTable->m_nProps; i++ ) { SendProp *pProp = &pTable->m_pProps[i]; if( pProp->m_Type == DPT_DataTable ) if( !WriteSendTable_R( pProp->GetDataTable(), bfWrite, false ) ) return false; } return true; }
bool UTIL_ContainsDataTable(SendTable *pTable, const char *name) { const char *pname = pTable->GetName(); int props = pTable->GetNumProps(); SendProp *prop; SendTable *table; if (pname && strcmp(name, pname) == 0) return true; for (int i=0; i<props; i++) { prop = pTable->GetProp(i); if ((table = prop->GetDataTable()) != NULL) { pname = table->GetName(); if (pname && strcmp(name, pname) == 0) { return true; } if (UTIL_ContainsDataTable(table, name)) { return true; } } } return false; }
void UTIL_DrawSendTable(FILE *fp, SendTable *pTable, int level = 1) { SendProp *pProp; const char *type; for (int i = 0; i < pTable->GetNumProps(); i++) { pProp = pTable->GetProp(i); if (pProp->GetDataTable()) { fprintf(fp, "%*sTable: %s (offset %d) (type %s)\n", level, "", pProp->GetName(), pProp->GetOffset(), pProp->GetDataTable()->GetName()); UTIL_DrawSendTable(fp, pProp->GetDataTable(), level + 1); } else { type = GetDTTypeName(pProp->GetType()); if (type != NULL) { fprintf(fp, "%*sMember: %s (offset %d) (type %s) (bits %d) (%s)\n", level, "", pProp->GetName(), pProp->GetOffset(), type, pProp->m_nBits, UTIL_SendFlagsToString(pProp->GetFlags(), pProp->GetType())); } else { fprintf(fp, "%*sMember: %s (offset %d) (type %d) (bits %d) (%s)\n", level, "", pProp->GetName(), pProp->GetOffset(), pProp->GetType(), pProp->m_nBits, UTIL_SendFlagsToString(pProp->GetFlags(), pProp->GetType())); } } } }
void UTIL_DrawSendTable(FILE *fp, SendTable *pTable, int level) { char spaces[255]; for (int i=0; i<level; i++) spaces[i] = ' '; spaces[level] = '\0'; const char *name, *type; SendProp *pProp; fprintf(fp, "%sSub-Class Table (%d Deep): %s\n", spaces, level, pTable->GetName()); for (int i=0; i<pTable->GetNumProps(); i++) { pProp = pTable->GetProp(i); name = pProp->GetName(); if (pProp->GetDataTable()) { UTIL_DrawSendTable(fp, pProp->GetDataTable(), level + 1); } else { type = GetDTTypeName(pProp->GetType()); if (type != NULL) { fprintf(fp, "%s-Member: %s (offset %d) (type %s) (bits %d)\n", spaces, pProp->GetName(), pProp->GetOffset(), type, pProp->m_nBits); } else { fprintf(fp, "%s-Member: %s (offset %d) (type %d) (bits %d)\n", spaces, pProp->GetName(), pProp->GetOffset(), pProp->GetType(), pProp->m_nBits); } } } }
// ============================================================================ // >> HELPER FUNCTIONS // ============================================================================ SendTable* GetNextSendTable(SendTable* pTable) { for (int i=0; i < pTable->GetNumProps(); ++i) { SendProp* pProp = pTable->GetProp(i); if (strcmp(pProp->GetName(), "baseclass") != 0) continue; return pProp->GetDataTable(); } return NULL; }
bool UTIL_FindInSendTable(SendTable *pTable, const char *name, sm_sendprop_info_t *info, unsigned int offset) { const char *pname; int props = pTable->GetNumProps(); SendProp *prop; for (int i=0; i<props; i++) { prop = pTable->GetProp(i); pname = prop->GetName(); if ( g_PrintProps ) Msg("%d : %s\n",offset + prop->GetOffset(),pname); if (pname && strcmp(name, pname) == 0) { info->prop = prop; // for some reason offset is sometimes negative when it shouldn't be // so take the absolute value info->actual_offset = offset + abs(info->prop->GetOffset()); return true; } if (prop->GetDataTable()) { if (UTIL_FindInSendTable(prop->GetDataTable(), name, info, offset + prop->GetOffset()) ) { return true; } } } return false; }
void DataTable_ClearWriteFlags_R( SendTable *pTable ) { pTable->SetWriteFlag( false ); for(int i=0; i < pTable->m_nProps; i++) { SendProp *pProp = &pTable->m_pProps[i]; if( pProp->m_Type == DPT_DataTable ) { DataTable_ClearWriteFlags_R( pProp->GetDataTable() ); } } }
bool FindNestedDataTable(SendTable *pTable, const char *name) { if (strcmp(pTable->GetName(), name) == 0) { return true; } int props = pTable->GetNumProps(); SendProp *prop; for (int i=0; i<props; i++) { prop = pTable->GetProp(i); if (prop->GetDataTable()) { if (FindNestedDataTable(prop->GetDataTable(), name)) { return true; } } } return false; }
// Calls DataTable_MaybeWriteSendTable recursively. void DataTable_MaybeWriteSendTableBuffer_R( SendTable *pTable, bf_write *pBuf ) { DataTable_MaybeWriteSendTableBuffer( pTable, pBuf, false ); // Make sure we send child send tables.. for(int i=0; i < pTable->m_nProps; i++) { SendProp *pProp = &pTable->m_pProps[i]; if( pProp->m_Type == DPT_DataTable ) { DataTable_MaybeWriteSendTableBuffer_R( pProp->GetDataTable(), pBuf ); } } }
void DataTable_MaybeCreateReceiveTable_R( CUtlVector< SendTable * >& visited, SendTable *pTable ) { DataTable_MaybeCreateReceiveTable( visited, pTable, false ); // Make sure we send child send tables.. for(int i=0; i < pTable->m_nProps; i++) { SendProp *pProp = &pTable->m_pProps[i]; if( pProp->m_Type == DPT_DataTable ) { DataTable_MaybeCreateReceiveTable_R( visited, pProp->GetDataTable() ); } } }
static void SendTable_CalcNextVectorElems( SendTable *pTable ) { for ( int i=0; i < pTable->GetNumProps(); i++ ) { SendProp *pProp = pTable->GetProp( i ); if ( pProp->GetType() == DPT_DataTable ) { SendTable_CalcNextVectorElems( pProp->GetDataTable() ); } else if ( pProp->GetOffset() < 0 ) { pProp->SetOffset( -pProp->GetOffset() ); pProp->SetFlags( pProp->GetFlags() | SPROP_IS_A_VECTOR_ELEM ); } } }
cell_t GetDataTable(IPluginContext *pContext, const cell_t *params) { Handle_t hndl = static_cast<Handle_t>(params[1]); HandleError err; HandleSecurity sec; sec.pOwner = NULL; sec.pIdentity = myself->GetIdentity(); SendProp *pProp; if ((err=g_pHandleSys->ReadHandle(hndl, g_SendTableHandle, &sec, (void **)&pProp)) != HandleError_None) { return pContext->ThrowNativeError("Invalid SendProp handle %x (error %d)", hndl, err); } return g_pHandleSys->CreateHandle(g_SendTableHandle, pProp->GetDataTable(), pContext->GetIdentity(), myself->GetIdentity(), NULL); }
void EntityProp::getOffset(SendTable * table, istringstream & propPathLeft) { // Get the next step into the props table string pathNextStep; getline(propPathLeft, pathNextStep, '.'); //Msg("Scanning %s...\n", propPathLeft.c_str()); int nbrProps = table->GetNumProps(); int i=0; while(i<nbrProps) { SendProp * sProp = table->GetProp(i); if (pathNextStep == sProp->GetName()) { offset += sProp->GetOffset(); switch(sProp->GetType()) { case DPT_Int: case DPT_Float: case DPT_Vector: case DPT_String: case DPT_Array: // Found the prop itself, the offset is up to date i = nbrProps; // break break; case DPT_DataTable: // Step reached, go to the next step getOffset(sProp->GetDataTable(), propPathLeft); break; default: // Prop not found offset = 0; i = nbrProps; // break } } i++; } }
//--------------------------------------------------------------------------------- // Purpose: used by the GetPropOffsetFromTable func to get a specific table //--------------------------------------------------------------------------------- SendTable *GetDataTable( const char *pTableName, SendTable *pTable ) { if (!pTable) return NULL; if ( FStrEq( pTableName, pTable->GetName() ) ) return pTable; int num = pTable->GetNumProps(); for (int i = 0; i < num; i++) { SendProp *pProp = pTable->GetProp(i); if (pProp) { SendTable *pSubTable = GetDataTable( pTableName, pProp->GetDataTable() ); if (pSubTable == NULL) continue; if ( FStrEq(pSubTable->GetName(), pTableName) ) return pSubTable; } } return NULL; }