Skip to content

Commit

Permalink
Cancel CVehicle::UpdateTractorLink and minor edits
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladik01-11 committed Sep 24, 2024
1 parent 718bdb6 commit 57eb002
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 54 deletions.
5 changes: 2 additions & 3 deletions source/game_sa/CarEnterExit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ bool CCarEnterExit::CarHasOpenableDoor(const CVehicle* vehicle, int32 doorId_Unu

// 0x64EE70
bool CCarEnterExit::CarHasPartiallyOpenDoor(const CVehicle* vehicle, int32 doorId) {
auto& veh = const_cast<CVehicle&>(*vehicle);
auto& veh = const_cast<CVehicle&>(*vehicle); // TODO: Fix
return !veh.IsDoorMissingU32((uint32)doorId)
&& !veh.IsDoorFullyOpenU32((uint32)doorId)
&& !veh.IsDoorClosedU32((uint32)doorId);
Expand Down Expand Up @@ -417,7 +417,7 @@ bool CCarEnterExit::IsCarDoorInUse(const CVehicle* vehicle, int32 firstDoorId, i
// 0x64ED90
bool CCarEnterExit::IsCarDoorReady(const CVehicle* vehicle, int32 doorId) {
// TODO: Make IsDoorReadyU32 a const member function to avoid const_cast
auto& veh = const_cast<CVehicle&>(*vehicle);
auto& veh = const_cast<CVehicle&>(*vehicle); // TODO: Fix
return veh.IsDoorReadyU32((uint32)doorId)
|| veh.IsDoorFullyOpenU32((uint32)doorId);
}
Expand Down Expand Up @@ -470,7 +470,6 @@ bool CCarEnterExit::IsCarSlowJackRequired(const CVehicle* vehicle, int32 doorId)
return false;
}
}

return false;
}

Expand Down
53 changes: 3 additions & 50 deletions source/game_sa/Entity/Vehicle/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void CVehicle::InjectHooks() {
// RH_ScopedInstall(RemoveVehicleUpgrade, 0x6DF930);
// RH_ScopedInstall(AddUpgrade, 0x6DFA20);
// RH_ScopedInstall(UpdateTrailerLink, 0x6DFC50);
RH_ScopedInstall(UpdateTractorLink, 0x6E0050);
// RH_ScopedInstall(UpdateTractorLink, 0x6E0050);
// RH_ScopedInstall(ScanAndMarkTargetForHeatSeekingMissile, 0x6E0400);
// RH_ScopedInstall(FireHeatSeakingMissile, 0x6E05C0);
// RH_ScopedInstall(PossiblyDropFreeFallBombForPlayer, 0x6E07E0);
Expand Down Expand Up @@ -4242,55 +4242,8 @@ void CVehicle::UpdateTrailerLink(bool arg0, bool arg1) {
}

// 0x6E0050
void CVehicle::UpdateTractorLink(bool applyFullVelocityAtHookUp, bool applyDistToSpeed) {
if (!m_pTrailer) {
return;
}
CVector hitchPos{};
if (!m_pTrailer->GetTowHitchPos(hitchPos, true, this)) {
return;
}
CVector towBarPos{};
if (!GetTowBarPos(towBarPos, true, m_pTrailer)) {
return;
}
switch (m_nModelIndex) {
case MODEL_TOWTRUCK:
case MODEL_TRACTOR: {
if (AsAutomobile()->m_wMiscComponentAngle > TOWTRUCK_HOIST_DOWN_LIMIT - 100) {
return;
}
}
}

// 0x6E01EF
auto trailerAngularForce = m_pTrailer->GetSpeed(hitchPos - m_pTrailer->GetPosition()) - GetSpeed(towBarPos - GetPosition());
if (!applyFullVelocityAtHookUp) {
trailerAngularForce *= (1.f - m_fMass / (m_pTrailer->m_fMass + m_fMass)) / 2.f;
if (applyDistToSpeed) {
const auto distVel = (hitchPos - towBarPos) * (0.1f / std::max(1.f, CTimer::ms_fTimeStep));
// BUG: //TODO: Pirulax: I'm quite positive this was meant to be +=
if constexpr (notsa::IsFixBugs()) {
trailerAngularForce += distVel;
} else {
trailerAngularForce = distVel;
}
}
}
if (m_pTrailer->IsSubTrailer() && m_pTrailer->AsTrailer()->m_fTrailerTowedRatio == -1000.f) {
trailerAngularForce -= trailerAngularForce.ProjectOnToNormal(m_pTrailer->GetMatrix().GetUp());
}

// 0x6E03EA
ApplyForce(
trailerAngularForce * GetMass( // 0x6E0354
towBarPos - GetMatrix().TransformPoint(m_vecCentreOfMass), // NOTE: Same logic here, but less code
trailerAngularForce.Normalized()
),
towBarPos,
true
);
m_nFakePhysics = false;
void CVehicle::UpdateTractorLink(bool arg0, bool arg1) {
((void(__thiscall*)(CVehicle*, bool, bool))0x6E0050)(this, arg0, arg1);
}

// 0x6E0400
Expand Down
2 changes: 1 addition & 1 deletion source/game_sa/Events/GroupEventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ CTaskAllocator* CGroupEventHandler::ComputeResponseDraggedOutCar(const CEventDra
if (!e.m_CarJacker) {
return nullptr;
}
assert(!e.m_CarJacker->IsPed()); // Original code just `returns nullptr` in this case, but but since `m_CarJacker` is typed as `CPed*` it *should* be at least a `CPed*`
assert(e.m_CarJacker->IsPed()); // Original code just `returns nullptr` in this case, but but since `m_CarJacker` is typed as `CPed*` it *should* be at least a `CPed*`
switch (e.m_taskId) {
case TASK_GROUP_KILL_THREATS_BASIC:
return e.m_CarJacker->IsPlayer() && originator && originator->GetIntelligence()->Respects(e.m_CarJacker) && !pg->m_bIsMissionGroup
Expand Down
2 changes: 2 additions & 0 deletions source/toolsmenu/DebugModules/PedDebugModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ void PedDebugModule::RenderWindow() {
return std::vector<elem_t>{r.begin(), r.end()};
};

if (!GetPedPool()) return;

auto peds = to_vector(
GetPedPool()->GetAllValid()
| rng::views::transform([this](CPed& ped) -> std::optional<PedInfo> {
Expand Down

0 comments on commit 57eb002

Please sign in to comment.