From 8cc4a0513cecaed1aa1c443618025929619258b6 Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Thu, 7 Oct 2021 18:30:44 +0600 Subject: [PATCH] Add enter vehicle as passenger (vc) --- src/hook.cpp | 2 +- src/vehicle.cpp | 56 +++++++++++++++++++++++++++++++++++-------------- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/hook.cpp b/src/hook.cpp index 1845998..ebe381f 100644 --- a/src/hook.cpp +++ b/src/hook.cpp @@ -157,7 +157,7 @@ HRESULT Hook::Dx11Handler(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Fl void Hook::ShowMouse(bool state) { -// Disable player controls for controllers + // Disable player controls for controllers bool bMouseDisabled = false; if (patch::Get(BY_GAME(0xBA6818, 0x86968B)) && (m_bShowMouse || bMouseDisabled)) { diff --git a/src/vehicle.cpp b/src/vehicle.cpp index f88202f..832bfb0 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -276,6 +276,42 @@ int Vehicle::GetRandomTrainIdForModel(int model) int id = Random(_start, _end); return train_ids[id]; } +#elif GTAVC +void WarpPlayerIntoVehicle(CVehicle *pVeh, int seatId) +{ + CPlayerPed *pPlayer = FindPlayerPed(); + + pPlayer->m_bInVehicle = true; + pPlayer->m_pVehicle = pVeh; + pPlayer->RegisterReference((CEntity**)&pPlayer->m_pVehicle); + pPlayer->m_pObjectiveVehicle = pVeh; + pPlayer->RegisterReference((CEntity**)&pPlayer->m_pObjectiveVehicle); + pPlayer->m_dwAction = ePedAction::Driving; + pPlayer->m_dwObjective = OBJECTIVE_NO_OBJ; + + if (pVeh->m_passengers[seatId]) + { + pVeh->m_passengers[seatId]->Remove(); + } + pVeh->m_passengers[seatId] = pPlayer; + pVeh->RegisterReference((CEntity**)&pVeh->m_passengers[seatId]); + + patch::Set(0x7838CD, 1); // player got in car flag + Call<0x41D370>(pVeh); // CCarCtrl::RegisterVehicleOfInterest + + CWorld::Remove(pPlayer); + pPlayer->m_placement.pos.x = pVeh->m_placement.pos.x; + pPlayer->m_placement.pos.y = pVeh->m_placement.pos.y; + pPlayer->m_placement.pos.z = pVeh->m_placement.pos.z; + CWorld::Add(pPlayer); + + pPlayer->m_nFlags.bUseCollision = false; + pPlayer->m_nPedFlags.bIsStanding = false; + pPlayer->m_nPedFlags.b03 = 0; + RpAnimBlendClumpSetBlendDeltas(pPlayer->m_pRwClump, 16, -1000); + pPlayer->AddInCarAnims(pVeh, false); + CallMethod<0x4FF6A0>(pPlayer); // char __thiscall RemoveWeaponWhenEnteringVehicle(CPed*) +} #endif #ifdef GTASA @@ -749,7 +785,6 @@ void Vehicle::Draw() Command(hplayer, pClosestVeh); } -#ifdef GTASA for (int i = 0; i < seats; ++i) { if (i % 2 != 1) @@ -760,24 +795,13 @@ void Vehicle::Draw() if (ImGui::Button((std::string("Passenger ") + std::to_string(i + 1)).c_str(), ImVec2(Ui::GetSize(2)))) { +#ifdef GTASA Command(hplayer, pClosestVeh, i); +#elif GTAVC + WarpPlayerIntoVehicle(pClosestVeh, i); +#endif } } -#elif GTAVC - // ImGui::SameLine(); - // if (ImGui::Button("Passenger", ImVec2(Ui::GetSize(2)))) - // { - // if (pPlayer->m_bInVehicle) - // { - // CVector pos = pClosestVeh->GetPosition(); - // Command(hplayer, pos.x, pos.y, pos.z); - // } - - // pPlayer->SetObjective(OBJECTIVE_ENTER_CAR_AS_PASSENGER); - // pPlayer->WarpPedIntoCar(pClosestVeh); - // // Command(CPools::GetVehicleRef(pClosestVeh), 0); - // } -#endif } else {