Exemple #1
0
void ContextSwitch(IVPed * pPed, bool bPost)
{
    // Do we have a valid ped pointer?
    if(pPed)
    {
        // Get the game pad
        CIVPad * pPad = g_pClient->GetGame()->GetPad();

        /*CContextData * pTestContextInfo = CContextDataManager::GetContextData((IVPlayerPed *)pPed);
        CIVPad * pTestPad = g_pClient->GetGame()->GetPad();
        bool bLocalPlayer = ((IVPlayerPed *)pPed == CPools::GetPlayerInfoFromIndex(0)->m_pPlayerPed);
        if(!bLocalPlayer && pTestContextInfo)
        {
        	pTestPad = pTestContextInfo->GetPad();
        }
        CClientPadState curPad;
        CClientPadState lasPad;
        pTestPad->GetCurrentClientPadState(curPad);
        pTestPad->GetLastClientPadState(lasPad);
        if(curPad.byteKeys[INPUT_MELEE_KICK] && !lasPad.byteKeys[INPUT_MELEE_KICK])
        {
        	CLogFile::Printf("(%d) Melee kick start hold", bLocalPlayer);
        	if(bLocalPlayer)
        		bRecordHistory = true;
        	else
        		bRecordHistory2 = true;
        }
        if(bRecordHistory || bRecordHistory2)
        {
        	CLogFile::Printf("(%d) Current history taken at %d is %d", bLocalPlayer, pTestPad->GetPad()->m_padData[INPUT_MELEE_KICK].m_pHistory->m_historyItems[pTestPad->GetPad()->m_padData[INPUT_MELEE_KICK].m_byteHistoryIndex].m_dwLastUpdateTime, pTestPad->GetPad()->m_padData[INPUT_MELEE_KICK].m_pHistory->m_historyItems[pTestPad->GetPad()->m_padData[INPUT_MELEE_KICK].m_byteHistoryIndex].m_byteValue);
        }
        if(!curPad.byteKeys[INPUT_MELEE_KICK] && lasPad.byteKeys[INPUT_MELEE_KICK])
        {
        	CLogFile::Printf("(%d) Melee kick end hold", bLocalPlayer);
        	if(bLocalPlayer)
        		bRecordHistory = false;
        	else
        		bRecordHistory2 = false;
        }*/

        // Is this not the local player ped?
        if((IVPlayerPed *)pPed != CPools::GetPlayerInfoFromIndex(0)->m_pPlayerPed)
        {
            if(!bPost && !bInLocalContext)
            {
                CLogFile::Printf("Not switching due to not being in local context!");
                return;
            }

            if(bPost && bInLocalContext)
            {
                CLogFile::Printf("Not switching due to being in local context!");
                return;
            }

            // Get the remote players context info
            CContextData * pContextInfo = CContextDataManager::GetContextData((IVPlayerPed *)pPed);

            // Do we have a valid context info?
            if(pContextInfo)
            {
                //CLogFile::SetUseCallback(false);
                //CLogFile::Printf("ContextSwitch(0x%p, %d) (Player Ped %d)", pPed, bPost, pContextInfo->GetPlayerInfo()->GetPlayerNumber());
                //CLogFile::SetUseCallback(true);

                if(!bPost)
                {
                    // Store the local players index
                    m_uiLocalPlayerIndex = CPools::GetLocalPlayerIndex();

                    // Store the local players pad
                    memcpy(&m_localPad, pPad->GetPad(), sizeof(IVPad));

                    // Store the local players camera matrix
                    GetGameCameraMatrix(&m_matLocalCameraMatrix);

                    // Swap the local player index with the remote players index
                    CPools::SetLocalPlayerIndex(pContextInfo->GetPlayerInfo()->GetPlayerNumber());

                    // Set the history values
                    for(int i = 0; i < INPUT_COUNT; i++)
                    {
                        CPadData * pPadData = &pContextInfo->GetPad()->GetPad()->m_padData[i];

                        if(pPadData->m_pHistory)
                        {
                            pPadData->m_byteHistoryIndex++;

                            if(pPadData->m_byteHistoryIndex >= MAX_HISTORY_ITEMS)
                                pPadData->m_byteHistoryIndex = 0;

                            pPadData->m_pHistory->m_historyItems[pPadData->m_byteHistoryIndex].m_byteValue = pContextInfo->GetPad()->GetPad()->m_padData[i].m_byteLastValue;
                            pPadData->m_pHistory->m_historyItems[pPadData->m_byteHistoryIndex].m_dwLastUpdateTime = g_pClient->GetGame()->GetTime();
                        }
                    }

                    // Swap the local players pad with the remote players pad
                    memcpy(pPad->GetPad(), pContextInfo->GetPad()->GetPad(), sizeof(IVPad));

                    // Swap the local players camera matrix with the remote players camera matrix
                    //SetGameCameraMatrix(pContextInfo->GetCameraMatrix());

                    // Flag ourselves as no longer in local context
                    bInLocalContext = false;
                }
                else
                {
                    // Restore the local players camera matrix
                    SetGameCameraMatrix(&m_matLocalCameraMatrix);

                    // Restore the local players pad
                    memcpy(pPad->GetPad(), &m_localPad, sizeof(IVPad));

                    // Restore the local players index
                    CPools::SetLocalPlayerIndex(m_uiLocalPlayerIndex);

                    // Flag ourselves as back in local context
                    bInLocalContext = true;
                }
            }
            else
                CLogFile::Printf("ContextSwitch Warning: Invalid Player Ped");
        }
    }
}
Exemple #2
0
void ContextSwitch(IVPed * pPed, bool bPost) 
{
	// Do we have a valid ped pointer?
	if(pPed) {
		// Get the remote players context data
		CContextData * pContextData = CContextDataManager::GetContextData((IVPlayerPed *)pPed);

		// Do we have a valid context data?
		if(pContextData) {
			// Is this not the local player?
			if(pContextData->GetPlayerInfo()->GetPlayerNumber() != 0) {
				if(!bPost && !g_bInLocalContext) {
					CLogFile::Printf("Not switching due to not being in local context!");
					return;
				}

				if(bPost && g_bInLocalContext) {
					CLogFile::Printf("Not switching due to being in local context!");
					return;
				}

				// Get the game pad
				CIVPad * pPad = g_pCore->GetGame()->GetPad();

				if(!bPost) {
					// Store the local players index
					g_uiLocalPlayerIndex = g_pCore->GetGame()->GetPools()->GetLocalPlayerIndex();

					// Store the local players pad
					memcpy(&g_localPad, pPad->GetPad(), sizeof(IVPad));

					g_pLocalPlayerInfo = g_pCore->GetGame()->GetPools()->GetPlayerInfoFromIndex(g_uiLocalPlayerIndex);

					g_pCore->GetGame()->GetPools()->SetPlayerInfoAtIndex(g_uiLocalPlayerIndex, pContextData->GetPlayerInfo()->GetPlayerInfo());

					// Set the history values
					for(int i = 0; i < INPUT_COUNT; i++) {
						IVPadData * pPadData = &pContextData->GetPad()->GetPad()->m_padData[i];

						if(pPadData->m_pHistory) {
							pPadData->m_byteHistoryIndex++;

							if(pPadData->m_byteHistoryIndex >= MAX_HISTORY_ITEMS)
								pPadData->m_byteHistoryIndex = 0;

							pPadData->m_pHistory->m_historyItems[pPadData->m_byteHistoryIndex].m_byteValue = pPadData->m_byteLastValue;
							pPadData->m_pHistory->m_historyItems[pPadData->m_byteHistoryIndex].m_dwLastUpdate = CGameFunction::GetTimeOfDay();
						}
					}

					// Swap the local players pad with the remote players pad
					memcpy(pPad->GetPad(), pContextData->GetPad()->GetPad(), sizeof(IVPad));

					// Flag ourselves as no longer in local context
					g_bInLocalContext = false;
				}
				else {
					// Restore the local players pad
					memcpy(pPad->GetPad(), &g_localPad, sizeof(IVPad));

					g_pCore->GetGame()->GetPools()->SetPlayerInfoAtIndex(g_uiLocalPlayerIndex, g_pLocalPlayerInfo);

					// Flag ourselves as back in local context
					g_bInLocalContext = true;
				}
			}
		}
		else
			CLogFile::Printf("ContextSwitch Warning: Invalid Player Ped");
	}
}