// getVehicleHealth(vehicleid) SQInteger CVehicleNatives::GetHealth(SQVM * pVM) { EntityId vehicleId; sq_getentity(pVM, -1, &vehicleId); CNetworkVehicle * pVehicle = g_pClient->GetVehicleManager()->Get(vehicleId); if(pVehicle) { sq_pushinteger(pVM, pVehicle->GetHealth()); return 1; } sq_pushbool(pVM, false); return 1; }
// getVehicleEngineHealth(vehicleid) SQInteger CVehicleNatives::GetEngineHealth(SQVM * pVM) { EntityId vehicleId; sq_getentity(pVM, -1, &vehicleId); CNetworkVehicle * pVehicle = g_pClient->GetVehicleManager()->Get(vehicleId); if(pVehicle) { CLogFile::Printf("Function getVehicleEngineHealth is depreciated: please use getVehicleHealth."); sq_pushfloat(pVM, (float)pVehicle->GetHealth()); return 1; } sq_pushbool(pVM, false); return 1; }
// Direct3DDevice9::EndScene void Direct3DRender() { // Check for pause menu if(g_pNetworkManager) { if(CGame::IsMenuActive() && CGame::GetState() == GAME_STATE_INGAME && g_pNetworkManager->IsConnected()) CGame::SetState(GAME_STATE_PAUSE_MENU); else if(!CGame::IsMenuActive() && CGame::GetState() == GAME_STATE_PAUSE_MENU && g_pNetworkManager->IsConnected()) CGame::SetState(GAME_STATE_INGAME); } // Are we in the main menu? if(CGame::GetState() == GAME_STATE_MAIN_MENU || CGame::GetState() == GAME_STATE_LOADING) { // Is the main menu shown? if(CGame::IsMenuActive()) { // Clear the screen g_pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 0, 0, 0), 1.0, 0); } } if(g_pMainMenu && CGame::GetState() == GAME_STATE_MAIN_MENU || CGame::GetState() == GAME_STATE_IVMP_PAUSE_MENU) { if(!g_pMainMenu->IsVisible()) { if(g_pNetworkManager && g_pNetworkManager->IsConnected()) { g_pMainMenu->SetDisconnectButtonVisible(true); g_pMainMenu->SetVisible(true); } else { g_pMainMenu->SetDisconnectButtonVisible(false); g_pMainMenu->SetVisible(true); } } } else { if(g_pMainMenu->IsVisible()) g_pMainMenu->SetVisible(false); } if(g_pClientScriptManager && g_pClientScriptManager->GetGUIManager()) { if(CGame::GetState() != GAME_STATE_INGAME) { if(!g_pClientScriptManager->GetGUIManager()->IsHidden()) g_pClientScriptManager->GetGUIManager()->Hide(); } else { if(g_pClientScriptManager->GetGUIManager()->IsHidden()) g_pClientScriptManager->GetGUIManager()->Show(); } } // If our GUI class exists render it if(g_pGUI) g_pGUI->Render(); // If our WebKit class exists render it /* #ifdef IVMP_WEBKIT if(g_pWebkit) { g_pWebkit->RenderAll(); } #endif */ // If our main menu exists process it if(g_pMainMenu) g_pMainMenu->Process(); // if our chat exist draw it if(g_pChatWindow && !CGame::IsMenuActive()) g_pChatWindow->Draw(); // If our fps class exists update it if(g_pFPSCounter) g_pFPSCounter->Pulse(); // If our credits class exists process it if(g_pCredits) g_pCredits->Process(); // If our scripting manager exists, call the frame event if(g_pEvents && !g_pMainMenu->IsVisible()) g_pEvents->Call("frameRender"); // Check if our screen shot write failed if(CScreenShot::IsDone()) { if(CScreenShot::HasSucceeded()) g_pChatWindow->AddInfoMessage("Screen shot written (%s).", CScreenShot::GetWriteName().Get()); else g_pChatWindow->AddInfoMessage("Screen shot write failed (%s).", CScreenShot::GetError().Get()); CScreenShot::Reset(); } // Moving Camera for main menu, problem: g_pCamera->SetLookAt() cause an crash at change /*if(g_pNetworkManager && g_pCamera) { if(!g_pNetworkManager->IsConnected() && CGame::IsGameLoaded()) { if(g_iCameraTime > 500) { if(g_iCameraState == 1) g_iCameraState = 2; else if(g_iCameraState == 2) g_iCameraState = 3; else if(g_iCameraState == 3) g_iCameraState = 1; g_iCameraTime = 0; if(g_iCameraState == 1) { g_pCamera->SetPosition(CVector3(HAPPINESS_CAMERA_POS)); //g_pCamera->SetLookAt(CVector3(HAPPINESS_CAMERA_LOOK_AT)); } if(g_iCameraState == 2) { g_pCamera->SetPosition(CVector3(TRIANGLE_CAMERA_POS)); //g_pCamera->SetLookAt(CVector3(TRIANGLE_CAMERA_LOOK_AT)); } if(g_iCameraState == 3) { g_pCamera->SetPosition(CVector3(TRIANGLE_CAMERA_POS_OLD)); //g_pCamera->SetLookAt(CVector3(TRIANGLE_CAMERA_LOOK_AT_OLD)); } } else { g_iCameraTime++; CVector3 vecPosition; g_pCamera->GetPosition(vecPosition); vecPosition.fX += 0.1f; vecPosition.fY += 0.1f; g_pCamera->SetPosition(vecPosition); } } } if(g_pNetworkManager) { if(!g_pNetworkManager->IsConnected() && CGame::IsGameLoaded()) { if(CGame::GetState() == (eState)3) CGame::SetState(GAME_STATE_IVMP_PAUSE_MENU); if(!g_pMainMenu->IsVisible() && !CGame::IsMenuActive()) CGame::SetState(GAME_STATE_IVMP_PAUSE_MENU); } }*/ // Are we in game? if(CGame::GetState() == GAME_STATE_INGAME) { // Is F4 held down and do we have a network manager? if(GetAsyncKeyState(VK_F4) && g_pNetworkManager) { // Get the network statistics CNetStats * pNetStats = g_pNetworkManager->GetNetClient()->GetNetStats(); // Convert the network statistics to a string char szNetworkStats[10000]; pNetStats->ToString(szNetworkStats, 2); // Create the statistics string String strStats(szNetworkStats); // Append loaded and unloaded model counts to the stats // jenksta: too performance heavy to be done every frame //strStats.AppendF("Models (Loaded/Unload): %d/%d\n", CGame::GetLoadedModelCount(), CGame::GetUnloadedModelCount()); // Append streamed in/out entity counts and streamed in limits to the stats strStats.AppendF("Vehicles (StreamedIn/StreamedInLimit): %d/%d\n", g_pStreamer->GetStreamedInEntityCountOfType(STREAM_ENTITY_VEHICLE), g_pStreamer->GetStreamedInLimitOfType(STREAM_ENTITY_VEHICLE)); strStats.AppendF("Pickups (StreamedIn/StreamedInLimit): %d/%d\n", g_pStreamer->GetStreamedInEntityCountOfType(STREAM_ENTITY_PICKUP), g_pStreamer->GetStreamedInLimitOfType(STREAM_ENTITY_PICKUP)); strStats.AppendF("Objects (StreamedIn/StreamedInLimit): %d/%d\n", g_pStreamer->GetStreamedInEntityCountOfType(STREAM_ENTITY_OBJECT), g_pStreamer->GetStreamedInLimitOfType(STREAM_ENTITY_OBJECT)); strStats.AppendF("Checkpoints (StreamedIn/StreamedInLimit): %d/%d\n", g_pStreamer->GetStreamedInEntityCountOfType(STREAM_ENTITY_CHECKPOINT), g_pStreamer->GetStreamedInLimitOfType(STREAM_ENTITY_CHECKPOINT)); // Draw the string g_pGUI->DrawText(strStats, CEGUI::Vector2(26, 30), (CEGUI::colour)D3DCOLOR_RGBA(255, 255, 255, 255), g_pGUI->GetFont("tahoma-bold", 10)); g_pChatWindow->SetEnabled(false); g_bNetworkStatsDisplayed = true; } else { // If our network stats were displayed if(g_bNetworkStatsDisplayed) { if(g_pChatWindow && !g_pChatWindow->IsEnabled()) g_pChatWindow->SetEnabled(true); g_bNetworkStatsDisplayed = false; } // If our input window exists draw it if(g_pInputWindow) g_pInputWindow->Draw(); } // Update the time if(g_pTime) { // jenksta: Setting this every frame causes the weather to change // rapidly unsigned char ucHour = 0, ucMinute = 0; g_pTime->GetTime(&ucHour, &ucMinute); CGame::SetTime(ucHour, ucMinute); CGame::SetDayOfWeek(g_pTime->GetDayOfWeek()); } /* Vehicle Headlights testcode IVVehicle * pGameVehicle = pVehicle->GetGameVehicle()->GetVehicle(); //*(BYTE *)(pVehicle->GetGameVehicle()->GetVehicle() + 0xF71) |= 1; *((BYTE *)pGameVehicle + 3953) = *((BYTE *)pGameVehicle + 3953) & 0xFE | 2; } CViewportManager + 0x00 = sysArray (CViewport *) CViewport + 0x53C = Viewport ID GET_VIEWPORT_POS_AND_SIZE(unsigned int uiViewportId, float * fPosX, float * fPosY, float * fSizeX, float * fSizeY) (pViewport + 0x10) is always used ((pViewport + 0x10) + 0x298) = float fPosX; (((pViewport + 0x10) + 0x298) + 0x4) = float fPosY; (((pViewport + 0x10) + 0x298) + 0x8) = float fSizeX; (((pViewport + 0x10) + 0x298) + 0xC) = float fSizeY; GET_VIEWPORT_POSITION_OF_COORD(float fCoordX, float fCoordY, float fCoordZ, unsigned int uiViewportId, float * fPosX, float * fPosY) Viewport 1 = CViewportPrimaryOrtho Viewport 2 = CViewportGame Viewport 3 = CViewportRadar */ if(g_pLocalPlayer) { if(g_pLocalPlayer->GetVehicleInfos()) { if(g_pVehicleManager) { CVector3 vecWorldPosition; Vector2 vecScreenPosition; for(EntityId i = 0; i < MAX_VEHICLES; i++) { if(g_pVehicleManager->Exists(i)) { CNetworkVehicle * pVehicle = g_pVehicleManager->Get(i); if(!pVehicle->IsStreamedIn()) continue; if(!pVehicle->IsOnScreen()) continue; pVehicle->GetPosition(vecWorldPosition); CGame::GetScreenPositionFromWorldPosition(vecWorldPosition, vecScreenPosition); //if(g_pGraphics) //{ // CVector3 vecScreen; // g_pGraphics->GetScreenPositionFromWorldPosition(vecWorldPosition, &vecScreen); // if( vecScreen.fZ < 0 ) // return; //} //else // return; int health = pVehicle->GetHealth(); int model = pVehicle->GetEngineState(); float petrol = pVehicle->GetPetrolTankHealth(); CVector3 vecPos; pVehicle->GetPosition(vecPos); CVector3 vecRot; pVehicle->GetRotation(vecRot); g_pGUI->DrawText(String("VehicleId %d, Enginestate: %d, Health: %d, PetrolTankHealth: %f\nPosition(%.3f,%.3f,%.3f), Rot(%.3f,%.3f,%.3f)", i, model, health, petrol, vecPos.fX,vecPos.fY,vecPos.fZ,vecRot.fX,vecRot.fY,vecRot.fZ), CEGUI::Vector2(vecScreenPosition.X, vecScreenPosition.Y)); } } } } } if(g_pNameTags) g_pNameTags->Draw(); } }
void CClient::OnD3DEndScene() { // Check for pause menu if(m_pNetworkManager) { if(CGame::IsMenuActive() && CGame::GetState() == GAME_STATE_INGAME && m_pNetworkManager->IsConnected()) CGame::SetState(GAME_STATE_PAUSE_MENU); else if(!CGame::IsMenuActive() && CGame::GetState() == GAME_STATE_PAUSE_MENU && m_pNetworkManager->IsConnected()) CGame::SetState(GAME_STATE_INGAME); } // Are we in the main menu? if(CGame::GetState() == GAME_STATE_MAIN_MENU || CGame::GetState() == GAME_STATE_LOADING) { // Is the main menu shown? if(CGame::IsMenuActive()) { // Clear the screen m_pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 0, 0, 0), 1.0, 0); } } if(m_pMainMenu && CGame::GetState() == GAME_STATE_MAIN_MENU || CGame::GetState() == GAME_STATE_IVMP_PAUSE_MENU) { if(!m_pMainMenu->IsVisible()) { if(m_pNetworkManager && m_pNetworkManager->IsConnected()) { m_pMainMenu->SetDisconnectButtonVisible(true); m_pMainMenu->SetVisible(true); } else { m_pMainMenu->SetDisconnectButtonVisible(false); m_pMainMenu->SetVisible(true); } if(CGame::GetState() == GAME_STATE_MAIN_MENU) { String strPostPath("/getlatestversion.php"); m_pHttpClient->Get(strPostPath); if(strcmp(m_strConnectHost,"0.0.0.0")) { // Send connect event m_pMainMenu->OnDirectConnect(m_strConnectHost,m_usConnectPort); // Remove current connect entries from xml file CVAR_SET_STRING("currentconnect_server","0.0.0.0"); CVAR_SET_INTEGER("currentconnect_port",9999); } } } } else { if(m_pMainMenu->IsVisible()) { m_pMainMenu->SetVisible(false); m_pChatWindow->SetEnabled(true); } } if(m_pClientScriptManager && m_pClientScriptManager->GetGUIManager()) { if(CGame::GetState() != GAME_STATE_INGAME) { if(!m_pClientScriptManager->GetGUIManager()->IsHidden()) m_pClientScriptManager->GetGUIManager()->Hide(); } else { if(m_pClientScriptManager->GetGUIManager()->IsHidden()) m_pClientScriptManager->GetGUIManager()->Show(); } } // If our GUI class exists render it if(m_pGUI) m_pGUI->Render(); // If our main menu exists process it if(m_pMainMenu) m_pMainMenu->Process(); // If our chat window exist draw it if(m_pChatWindow && !CGame::IsMenuActive()) m_pChatWindow->Draw(); // If our fps class exists update it if(m_pFPSCounter) m_pFPSCounter->Pulse(); // If our credits class exists process it if(m_pCredits) m_pCredits->Process(); if(m_p3DLabelManager) m_p3DLabelManager->Render(); // If our scripting manager exists, call the frame event if(m_pEvents && !m_pMainMenu->IsVisible()) m_pEvents->Call("frameRender"); #ifdef IVMP_DEBUG if(m_pDebugView && m_pGUI && m_pLocalPlayer) m_pDebugView->Draw(); #endif // Check if our screen shot write failed if(CScreenShot::IsDone()) { if(CScreenShot::HasSucceeded()) m_pChatWindow->AddInfoMessage("Screen shot written (%s).", CScreenShot::GetWriteName().Get()); else m_pChatWindow->AddInfoMessage("Screen shot write failed (%s).", CScreenShot::GetError().Get()); CScreenShot::Reset(); } if(CGame::GetState() == GAME_STATE_MAIN_MENU) { if(m_pHttpClient->IsBusy()) m_pHttpClient->Process(); if(m_pHttpClient->GotData()) { // Get the data String * strData = m_pHttpClient->GetData(); // Did we get any data? if(!strData->IsEmpty()) { #ifndef IVMP_DEBUG if(strcmp(strData->Get(), MOD_VERSION_STRING)) { if(m_pGUI) m_pGUI->ShowMessageBox(String("A new version of IV:MP is available (Version %s)", strData->Get()).Get(), "New Version available"); } #endif } } } // Are we in game? if(CGame::GetState() == GAME_STATE_INGAME) { // Is F4 held down and do we have a network manager? if(GetAsyncKeyState(VK_F4) && m_pNetworkManager && m_pActorManager) { // Get the network statistics CNetStats * pNetStats = m_pNetworkManager->GetNetClient()->GetNetStats(); // Convert the network statistics to a string char szNetworkStats[10000]; pNetStats->ToString(szNetworkStats, 2); // Create the statistics string String strStats(szNetworkStats); // Append loaded and unloaded model counts to the stats // jenksta: too performance heavy to be done every frame //strStats.AppendF("Models (Loaded/Unload): %d/%d\n", CGame::GetLoadedModelCount(), CGame::GetUnloadedModelCount()); // Append streamed in/out entity counts and streamed in limits to the stats strStats.AppendF("Players (StreamedIn/StreamedInLimit): %d/%d\n", m_pStreamer->GetStreamedInEntityCountOfType(STREAM_ENTITY_PLAYER)+1, m_pStreamer->GetStreamedInLimitOfType(STREAM_ENTITY_PLAYER)); strStats.AppendF("Vehicles (StreamedIn/StreamedInLimit): %d/%d\n", m_pStreamer->GetStreamedInEntityCountOfType(STREAM_ENTITY_VEHICLE), m_pStreamer->GetStreamedInLimitOfType(STREAM_ENTITY_VEHICLE)); strStats.AppendF("Actors (Actor-Count/Max-Actors): %d/%d\n", m_pActorManager->GetActorCount(), MAX_ACTORS); strStats.AppendF("Pickups (StreamedIn/StreamedInLimit): %d/%d\n", m_pStreamer->GetStreamedInEntityCountOfType(STREAM_ENTITY_PICKUP), m_pStreamer->GetStreamedInLimitOfType(STREAM_ENTITY_PICKUP)); strStats.AppendF("Objects (StreamedIn/StreamedInLimit): %d/%d\n", m_pStreamer->GetStreamedInEntityCountOfType(STREAM_ENTITY_OBJECT), m_pStreamer->GetStreamedInLimitOfType(STREAM_ENTITY_OBJECT)); strStats.AppendF("Checkpoints (StreamedIn/StreamedInLimit): %d/%d\n", m_pStreamer->GetStreamedInEntityCountOfType(STREAM_ENTITY_CHECKPOINT), m_pStreamer->GetStreamedInLimitOfType(STREAM_ENTITY_CHECKPOINT)); // Draw the string m_pGUI->DrawText(strStats, CEGUI::Vector2(26, 30), (CEGUI::colour)D3DCOLOR_RGBA(255, 255, 255, 255), m_pGUI->GetFont("tahoma-bold", 10)); m_pChatWindow->SetEnabled(false); m_bNetworkStatsDisplayed = true; } else { // If our network stats were displayed if(m_bNetworkStatsDisplayed) { if(m_pChatWindow && !m_pChatWindow->IsEnabled()) m_pChatWindow->SetEnabled(true); m_bNetworkStatsDisplayed = false; } // If our input window exists draw it if(m_pInputWindow) m_pInputWindow->Draw(); } // Update the time if(m_pTime) { // jenksta: Setting this every frame causes the weather to change // rapidly unsigned char ucHour = 0, ucMinute = 0; m_pTime->GetTime(&ucHour, &ucMinute); CGame::SetTime(ucHour, ucMinute); CGame::SetDayOfWeek(m_pTime->GetDayOfWeek()); } #ifdef IVMP_DEBUG if(m_pVehicleManager) { CVector3 vecWorldPosition; Vector2 vecScreenPosition; for(EntityId i = 0; i < MAX_VEHICLES; i++) { CNetworkVehicle * pVehicle = m_pVehicleManager->Get(i); if(pVehicle) { if(!pVehicle->IsStreamedIn()) continue; if(!pVehicle->IsOnScreen()) continue; pVehicle->GetPosition(vecWorldPosition); if(!CGame::GetScreenPositionFromWorldPosition(vecWorldPosition, vecScreenPosition)) continue; int iHealth = pVehicle->GetHealth(); int iModel = pVehicle->GetEngineState(); float fPetrol = pVehicle->GetPetrolTankHealth(); CVector3 vecPos; pVehicle->GetPosition(vecPos); CVector3 vecRot; pVehicle->GetRotation(vecRot); m_pGUI->DrawText(String("VehicleId %d, Enginestate: %d, Health: %d, PetrolTankHealth: %f\nPosition(%.3f,%.3f,%.3f), Rot(%.3f,%.3f,%.3f)", i, iModel, iHealth, fPetrol, vecPos.fX,vecPos.fY,vecPos.fZ,vecRot.fX,vecRot.fY,vecRot.fZ), CEGUI::Vector2(vecScreenPosition.fX, vecScreenPosition.fY)); } } } #endif if(m_pNameTags) m_pNameTags->Draw(); } }