Exemplo n.º 1
0
bool Entities::RetrieveClassPropOffset(std::string className, std::vector<std::string> propertyTree) {
	std::string propertyString = ConvertTreeToString(propertyTree);

	if (classPropOffsets[className].find(propertyString) != classPropOffsets[className].end()) {
		return true;
	}

	ClientClass *cc = Interfaces::pClientDLL->GetAllClasses();

	while (cc) {
		if (className.compare(cc->GetName()) == 0) {
			RecvTable *table = cc->m_pRecvTable;

			int offset = 0;
			RecvProp *prop = nullptr;

			if (table) {
				for (auto iterator = propertyTree.begin(); iterator != propertyTree.end(); ++iterator) {
					int subOffset = 0;

					if (prop && prop->GetType() == DPT_DataTable) {
						table = prop->GetDataTable();
					}

					if (!table) {
						return false;
					}

					if (GetSubProp(table, iterator->c_str(), prop, subOffset)) {
						offset += subOffset;
					}
					else {
						return false;
					}

					table = nullptr;
				}

				classPropOffsets[className][propertyString] = offset;

				return true;
			}
		}
		cc = cc->m_pNext;
	}

	return false;
}
// This is called 
void CLocalNetworkBackdoor::InitFastCopy()
{
	if ( !cl.m_NetChannel->IsLoopback() )
		return;


	const CStandardSendProxies *pSendProxies = NULL;

	// If the game server is greater than v4, then it is using the new proxy format.
	if ( g_bServerGameDLLGreaterThanV4 ) // check server version
	{
		pSendProxies = serverGameDLL->GetStandardSendProxies();
	}
	else
	{
		// If the game server is older than v4, it is using the old proxy; we set the new proxy members to the 
		// engine's copy.
		static CStandardSendProxies compatSendProxy = *serverGameDLL->GetStandardSendProxies();

		compatSendProxy.m_DataTableToDataTable = g_StandardSendProxies.m_DataTableToDataTable;
		compatSendProxy.m_SendLocalDataTable = g_StandardSendProxies.m_SendLocalDataTable;
		compatSendProxy.m_ppNonModifiedPointerProxies = g_StandardSendProxies.m_ppNonModifiedPointerProxies;

		pSendProxies = &compatSendProxy;
	} 

	const CStandardRecvProxies *pRecvProxies = g_ClientDLL->GetStandardRecvProxies();

	int nFastCopyProps = 0;
	int nSlowCopyProps = 0;

	for ( int iClass=0; iClass < cl.m_nServerClasses; iClass++ )
	{
		ClientClass *pClientClass = cl.GetClientClass(iClass);
		if ( !pClientClass )
			Error( "InitFastCopy - missing client class %d", iClass );

		ServerClass *pServerClass = SV_FindServerClass( pClientClass->GetName() );
		if ( !pServerClass )
			Error( "InitFastCopy - missing server class %s", pClientClass->GetName() );

		LocalTransfer_InitFastCopy(
			pServerClass->m_pTable,
			pSendProxies,
			pClientClass->m_pRecvTable,
			pRecvProxies,
			nSlowCopyProps,
			nFastCopyProps
			);
	}

	int percentFast = (nFastCopyProps * 100 ) / (nSlowCopyProps + nFastCopyProps + 1);
	if ( percentFast <= 55 )
	{
		// This may not be a real problem, but at the time this code was added, 67% of the
		// properties were able to be copied without proxies. If percentFast goes to 0 or some
		// really low number suddenly, then something probably got screwed up.
		Assert( false );
		Warning( "InitFastCopy: only %d%% fast props. Bug?\n", percentFast );
	}
}