Exemplo n.º 1
0
	//---------------------------------------------------------------------------------
	// Purpose: returns the specified prop offset relative to the table provided.
	//			if offset or table not found, bErr returns true and offset returned is 0
	//---------------------------------------------------------------------------------
	unsigned int GetPropOffsetFromTable(const char *pTableName, const char *pPropName)
	{
		ServerClass *pClass = pServerDLL->GetAllServerClasses();
		if (!pClass)
		{
			Warning("servergamedll->GetAllServerClasses() returned null\n");
			return 0;
		}
		while (pClass)
		{
			SendTable *pTable = GetDataTable( pTableName, pClass->m_pTable );
			if (pTable == NULL)
			{
				pClass = pClass->m_pNext;
				continue;
			}
			int num = pTable->GetNumProps();
			for (int i = 0; i < num; i++)
			{
				SendProp *pProp = pTable->GetProp(i);
				if ( FStrEq( pPropName, pProp->GetName() ) )
				{
					return pProp->GetOffset();
				}
			}
			pClass = pClass->m_pNext;
		}
		Warning("prop %s not found in %s or table name incorrect\n", pPropName, pTableName);
		return 0;
	}
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));
		}
	}
}
Exemplo n.º 3
0
static cell_t GetTeamName(IPluginContext *pContext, const cell_t *params)
{
	int teamindex = params[1];
	if (teamindex >= (int)g_Teams.size() || !g_Teams[teamindex].ClassName)
	{
		return pContext->ThrowNativeError("Team index %d is invalid", teamindex);
	}

	if (g_teamname_offset == 0)
	{
		return pContext->ThrowNativeError("Team names are not available on this game.");
	}

	if (g_teamname_offset == -1)
	{
		SendProp *prop = g_pGameHelpers->FindInSendTable(g_Teams[teamindex].ClassName, "m_szTeamname");

		if (prop == NULL)
		{
			g_teamname_offset = 0;
			return pContext->ThrowNativeError("Team names are not available on this game.");
		}

		g_teamname_offset = prop->GetOffset();
	}

	char *name = (char *)((unsigned char *)g_Teams[teamindex].pEnt + g_teamname_offset);

	pContext->StringToLocalUTF8(params[2], params[3], name, NULL);

	return 1;
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
static cell_t GetTeamScore(IPluginContext *pContext, const cell_t *params)
{
	int teamindex = params[1];
	if (teamindex >= (int)g_Teams.size() || !g_Teams[teamindex].ClassName)
	{
		return pContext->ThrowNativeError("Team index %d is invalid", teamindex);
	}

	if (!m_iScore)
	{
		m_iScore = g_pGameConf->GetKeyValue("m_iScore");
		if (!m_iScore)
		{
			return pContext->ThrowNativeError("Failed to get m_iScore key");
		}
	}

	static int offset = -1;

	if (offset == -1)
	{
		SendProp *prop = g_pGameHelpers->FindInSendTable(g_Teams[teamindex].ClassName, m_iScore);
		if (!prop)
		{
			return pContext->ThrowNativeError("Failed to get m_iScore prop");
		}
		offset = prop->GetOffset();
	}


	return *(int *)((unsigned char *)g_Teams[teamindex].pEnt + offset);
}
Exemplo n.º 6
0
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()));
			}
		}
	}
}
Exemplo n.º 7
0
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);
			}
		}
	}
}
Exemplo n.º 8
0
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 );
		}
	}
}
Exemplo n.º 9
0
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;
}
Exemplo n.º 10
0
cell_t GetOffset(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 pProp->GetOffset();
}
Exemplo n.º 11
0
void UTIL_DrawSendTable_XML(FILE *fp, SendTable *pTable, int space_count)
{
	char spaces[255];

	for (int i = 0; i < space_count; i++)
	{
		spaces[i] = ' ';
	}
	spaces[space_count] = '\0';

	const char *type_name;
	SendTable *pOtherTable;
	SendProp *pProp;

	fprintf(fp, " %s<sendtable name=\"%s\">\n", spaces, pTable->GetName());
	for (int i = 0; i < pTable->GetNumProps(); i++)
	{
		pProp = pTable->GetProp(i);

		fprintf(fp, "  %s<property name=\"%s\">\n", spaces, pProp->GetName());

		if ((type_name = GetDTTypeName(pProp->GetType())) != NULL)
		{
			fprintf(fp, "   %s<type>%s</type>\n", spaces, type_name);
		}
		else
		{
			fprintf(fp, "   %s<type>%d</type>\n", spaces, pProp->GetType());
		}

		fprintf(fp, "   %s<offset>%d</offset>\n", spaces, pProp->GetOffset());
		fprintf(fp, "   %s<bits>%d</bits>\n", spaces, pProp->m_nBits);
		fprintf(fp, "   %s<flags>%s</flags>\n", spaces, UTIL_SendFlagsToString(pProp->GetFlags(), pProp->GetType()));

		if ((pOtherTable = pTable->GetProp(i)->GetDataTable()) != NULL)
		{
			UTIL_DrawSendTable_XML(fp, pOtherTable, space_count + 3);
		}

		fprintf(fp, "  %s</property>\n", spaces);
	}
	fprintf(fp, " %s</sendtable>\n", spaces);
}
Exemplo n.º 12
0
const char *tools_GetTeamName(int team)
{
	if (size_t(team) >= g_Teams.size())
		return NULL;
	if (g_teamname_offset == 0)
		return NULL;
	if (g_teamname_offset == -1)
	{
		SendProp *prop = g_pGameHelpers->FindInSendTable(g_Teams[team].ClassName, "m_szTeamname");
		if (prop == NULL)
		{
			g_teamname_offset = 0;
			return NULL;
		}
		g_teamname_offset = prop->GetOffset();
	}

	return (const char *)((unsigned char *)g_Teams[team].pEnt + g_teamname_offset);
}
Exemplo n.º 13
0
static cell_t SetTeamScore(IPluginContext *pContext, const cell_t *params)
{
	if (!g_pSM->IsMapRunning())
	{
		return pContext->ThrowNativeError("Cannot set team score when no map is running");
	}
	
	int teamindex = params[1];
	if (teamindex >= (int)g_Teams.size() || !g_Teams[teamindex].ClassName)
	{
		return pContext->ThrowNativeError("Team index %d is invalid", teamindex);
	}

	if (m_iScore == NULL)
	{
		m_iScore = g_pGameConf->GetKeyValue("m_iScore");
		if (m_iScore == NULL)
		{
			return pContext->ThrowNativeError("Failed to get m_iScore key");
		}
	}

	static int offset = -1;

	if (offset == -1)
	{
		SendProp *prop = g_pGameHelpers->FindInSendTable(g_Teams[teamindex].ClassName, m_iScore);
		if (!prop)
		{
			return pContext->ThrowNativeError("Failed to get m_iScore prop");
		}
		offset = prop->GetOffset();
	}

	CBaseEntity *pTeam = g_Teams[teamindex].pEnt;
	*(int *)((unsigned char *)pTeam + offset) = params[2];

	edict_t *pEdict = gameents->BaseEntityToEdict(pTeam);
	gamehelpers->SetEdictStateChanged(pEdict, offset);

	return 1;
}
Exemplo n.º 14
0
void InitTeamNatives()
{
	g_Teams.clear();
	g_Teams.resize(1);

	int edictCount = gpGlobals->maxEntities;

	for (int i=0; i<edictCount; i++)
	{
		edict_t *pEdict = PEntityOfEntIndex(i);
		if (!pEdict || pEdict->IsFree())
		{
			continue;
		}
		if (!pEdict->GetNetworkable())
		{
			continue;
		}

		ServerClass *pClass = pEdict->GetNetworkable()->GetServerClass();
		if (FindNestedDataTable(pClass->m_pTable, "DT_Team"))
		{
			SendProp *pTeamNumProp = g_pGameHelpers->FindInSendTable(pClass->GetName(), "m_iTeamNum");

			if (pTeamNumProp != NULL)
			{
				int offset = pTeamNumProp->GetOffset();
				CBaseEntity *pEnt = pEdict->GetUnknown()->GetBaseEntity();
				int TeamIndex = *(int *)((unsigned char *)pEnt + offset);

				if (TeamIndex >= (int)g_Teams.size())
				{
					g_Teams.resize(TeamIndex+1);
				}
				g_Teams[TeamIndex].ClassName = pClass->GetName();
				g_Teams[TeamIndex].pEnt = pEnt;
			}
		}
	}
}
Exemplo n.º 15
0
void Array_Encode( const unsigned char *pStruct, DVariant *pVar, const SendProp *pProp, bf_write *pOut, int objectID )
{
	SendProp *pArrayProp = pProp->GetArrayProp();
	AssertMsg( pArrayProp, ("Array_Encode: missing m_pArrayProp for SendProp '%s'.", pProp->m_pVarName) );
	
	int nElements = Array_GetLength( pStruct, pProp, objectID );

	// Write the number of elements.
	pOut->WriteUBitLong( nElements, pProp->GetNumArrayLengthBits() );

	unsigned char *pCurStructOffset = (unsigned char*)pStruct + pArrayProp->GetOffset();
	for ( int iElement=0; iElement < nElements; iElement++ )
	{
		DVariant var;

		// Call the proxy to get the value, then encode.
		pArrayProp->GetProxyFn()( pArrayProp, pStruct, pCurStructOffset, &var, iElement, objectID );
		g_PropTypeFns[pArrayProp->GetType()].Encode( pStruct, &var, pArrayProp, pOut, objectID ); 
		
		pCurStructOffset += pProp->GetElementStride();
	}
}
Exemplo n.º 16
0
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++;
    }
}
Exemplo n.º 17
0
void SDKTools::OnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax)
{
	g_Teams.clear();
	g_Teams.resize(1);

	for (int i=0; i<edictCount; i++)
	{
		edict_t *pEdict = engine->PEntityOfEntIndex(i);
		if (!pEdict || pEdict->IsFree())
		{
			continue;
		}
		if (!pEdict->GetNetworkable())
		{
			continue;
		}

		ServerClass *pClass = pEdict->GetNetworkable()->GetServerClass();
		if (FindTeamEntities(pClass->m_pTable, "DT_Team"))
		{
			SendProp *pTeamNumProp = g_pGameHelpers->FindInSendTable(pClass->GetName(), "m_iTeamNum");

			if (pTeamNumProp != NULL)
			{
				int offset = pTeamNumProp->GetOffset();
				CBaseEntity *pEnt = pEdict->GetUnknown()->GetBaseEntity();
				int TeamIndex = *(int *)((unsigned char *)pEnt + offset);

				if (TeamIndex >= (int)g_Teams.size())
				{
					g_Teams.resize(TeamIndex+1);
				}
				g_Teams[TeamIndex].ClassName = pClass->GetName();
				g_Teams[TeamIndex].pEnt = pEnt;
			}
		}
	}
}
Exemplo n.º 18
0
bool MyPlugin::Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory)
{
	serverGameDLL = (IServerGameDLL *)gameServerFactory(INTERFACEVERSION_SERVERGAMEDLL, NULL);
	if (serverGameDLL)
	{
		ServerClass *svrclass = serverGameDLL->GetAllServerClasses();
		while (svrclass)
		{
			const char *classname = svrclass->GetName();
			Msg("[%s]\n", classname);
			if (strcmp(classname, "CBasePlayer") == 0)
			{
				SendTable *st = svrclass->m_pTable;
				for (int i = 0; i < st->m_nProps; i++)
				{
					SendProp *sp = st->GetProp(i);
					const char *propname = sp->GetName();
					Msg("Prop name: %s | Prop Offset: %d | Type: %d | IsSigned: %d\n", propname, sp->GetOffset(), sp->GetType(), sp->IsSigned());
					
					if (strcmp(propname, "m_fFlags") == 0)
					{
						m_fFlags_off = sp->GetOffset();
						continue;
					}
					
					if (strcmp(propname, "m_iHealth") == 0)
					{
						m_iHealth_off = sp->GetOffset();
						continue;
					}
				}
			}
			
			if (strcmp(classname, "CBaseEntity") == 0)
			{
				SendTable *st = svrclass->m_pTable;
				for (int i = 0; i < st->m_nProps; i++)
				{
					SendProp *sp = st->GetProp(i);
					const char *propname = sp->GetName();
					Msg("Prop name: %s | Prop Offset: %d | Type: %d | IsSigned: %d\n", propname, sp->GetOffset(), sp->GetType(), sp->IsSigned());
					
					if (strcmp(propname, "m_iTeamNum") == 0)
					{
						m_iTeamNum_off = sp->GetOffset();
						continue;
					}
					
					if (strcmp(propname, "m_iPendingTeamNum") == 0)
					{
						m_iPendingTeamNum_off = sp->GetOffset();
						continue;
					}
					
					if (strcmp(propname, "m_fEffects") == 0)
					{
						m_fEffects_off = sp->GetOffset();
						continue;
					}
					
					if (strcmp(propname, "m_nRenderMode") == 0)
					{
						m_nRenderMode_off = sp->GetOffset();
						continue;
					}
				}
			}
			
			/*if (strcmp(classname, "CBaseCombatWeapon") == 0)
			{
				SendTable *st = svrclass->m_pTable;
				for (int i = 0; i < st->m_nProps; i++)
				{
					SendProp *sp = st->GetProp(i);
					const char *propname = sp->GetName();
					Msg("Prop name: %s | Prop Offset: %d | Type: %d | IsSigned: %d\n", propname, sp->GetOffset(), sp->GetType(), sp->IsSigned());
				}
			}*/
			svrclass = svrclass->m_pNext;
		}
	}
	else
	{
		Warning("Unable to load IServerGameDLL.\n");
		return false;
	}

	serverGameEnts = (IServerGameEnts *)gameServerFactory(INTERFACEVERSION_SERVERGAMEENTS, NULL);
	if (!serverGameEnts)
	{
		Warning("Unable to load IServerGameEnts.\n");
		return false;
	}

	playerInfoManager = (IPlayerInfoManager *)gameServerFactory(INTERFACEVERSION_PLAYERINFOMANAGER, NULL);
	if (playerInfoManager)
	{
		globalVars = playerInfoManager->GetGlobalVars();
	}
	else
	{
		Warning("Unable to load IPlayerInfoManager.\n");
		return false;
	}
	
	g_pCVar = (ICvar *)interfaceFactory(CVAR_INTERFACE_VERSION, NULL);
	if (g_pCVar)
	{
		ICvar::Iterator iter(g_pCVar);
		for (iter.SetFirst(); iter.IsValid(); iter.Next())
		{
			ConCommandBase *cmd = iter.Get();
			if (cmd->IsCommand())
				continue;
			const char *cmdname = cmd->GetName();
			ConVar *cvar = (ConVar *)cmd;
			if (strcmp(cmdname, "net_maxcleartime") == 0)
				cvar->SetValue(0.001f);

			/*if (strcmp(cmdname, "net_minroutable") == 0)
				cvar->SetValue(1000);*/
		}
	}
	else
	{
		Warning("Unable to load ICVar.\n");
		return false;
	}
	
	gameEventManager2 = (IGameEventManager2 *)interfaceFactory(INTERFACEVERSION_GAMEEVENTSMANAGER2, NULL);
	if (!gameEventManager2)
	{
		Warning("Unable to load IGameEventManager2.\n");
		return false;
	}

	vEngineServer = (IVEngineServer *)interfaceFactory(INTERFACEVERSION_VENGINESERVER, NULL);
	if (!vEngineServer)
	{
		Warning("Unable to load IVEngineServer.\n");
		return false;
	}

	serverTools = (IServerTools *)gameServerFactory(VSERVERTOOLS_INTERFACE_VERSION, NULL);
	if (!serverTools)
	{
		Warning("Unable to load IServerTools.\n");
		return false;
	}

	serverPluginHelpers = (IServerPluginHelpers *)interfaceFactory(INTERFACEVERSION_ISERVERPLUGINHELPERS, NULL);
	if (!serverPluginHelpers)
	{
		Warning("Unable to load IServerPluginHelpers.\n");
		return false;
	}

	//playerDeathEvent = new PlayerDeathEvent();
	//playerSayEvent = new PlayerSayEvent();
	//playerConnectEvent = new PlayerConnectEvent();
	//playerDisconnectEvent = new PlayerDisconnectEvent();
	roundStartEvent = new RoundStartEvent();
	//itemPickupEvent = new ItemPickupEvent();
	//playerSpawnEvent = new PlayerSpawnEvent();
	//playerSpawnedEvent = new PlayerSpawnedEvent();
	//announphaseendevent = new AnnouncePhaseEndEvent();

	return true;
}