Skip to content

Commit

Permalink
CTaskSimpleDoHandSignal (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pirulax authored Mar 9, 2024
1 parent e3219ae commit a1105b8
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
49 changes: 49 additions & 0 deletions source/game_sa/Tasks/TaskTypes/TaskSimpleDoHandSignal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "StdInc.h"
#include "TaskSimpleDoHandSignal.h"
#include "TaskComplexPlayHandSignalAnim.h"

void CTaskSimpleDoHandSignal::InjectHooks() {
RH_ScopedVirtualClass(CTaskSimpleDoHandSignal, 0x86fa68, 9);
RH_ScopedCategory("Tasks/TaskTypes");

RH_ScopedInstall(Constructor, 0x660880);
RH_ScopedInstall(Destructor, 0x6608B0);

RH_ScopedVMTInstall(Clone, 0x6608C0);
RH_ScopedVMTInstall(GetTaskType, 0x6608A0);
RH_ScopedVMTInstall(MakeAbortable, 0x660930);
RH_ScopedVMTInstall(ProcessPed, 0x660940);
}

CTaskSimpleDoHandSignal::CTaskSimpleDoHandSignal(const CTaskSimpleDoHandSignal& o) :
m_Initialized{ o.m_Initialized }
{
}

// 0x660940
bool CTaskSimpleDoHandSignal::ProcessPed(CPed* ped) {
if (!ped->GetIsOnScreen()) {
return true;
}

const auto animTask = ped->GetTaskManager().GetTaskSecondary(TASK_SECONDARY_PARTIAL_ANIM);

if (m_Initialized) {
return !animTask || !CTask::IsA<TASK_COMPLEX_HANDSIGNAL_ANIM>(animTask);
}

if (animTask) {
if (CTask::IsA<TASK_COMPLEX_HANDSIGNAL_ANIM>(animTask)) {
return true;
}
animTask->MakeAbortable(ped, ABORT_PRIORITY_URGENT, nullptr);
return false;
}

ped->GetTaskManager().SetTaskSecondary(
new CTaskComplexPlayHandSignalAnim{},
TASK_SECONDARY_PARTIAL_ANIM
);
m_Initialized = true;
return false;
}
38 changes: 38 additions & 0 deletions source/game_sa/Tasks/TaskTypes/TaskSimpleDoHandSignal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once

#include "TaskSimple.h"

class CTaskSimpleDoHandSignal;
class CPed;
class CEvent;

class NOTSA_EXPORT_VTABLE CTaskSimpleDoHandSignal : public CTaskSimple {
public:
static void InjectHooks();

static constexpr auto Type = eTaskType::TASK_SIMPLE_DO_HAND_SIGNAL;

CTaskSimpleDoHandSignal() = default;
CTaskSimpleDoHandSignal(const CTaskSimpleDoHandSignal&);
~CTaskSimpleDoHandSignal() = default;

CTask* Clone() const override { return new CTaskSimpleDoHandSignal{*this}; }
eTaskType GetTaskType() const override { return Type; }
bool MakeAbortable(CPed* ped, eAbortPriority priority, CEvent const* event) override { return true; }
bool ProcessPed(CPed* ped) override;

private: // Wrappers for hooks
// 0x660880
CTaskSimpleDoHandSignal* Constructor() {
this->CTaskSimpleDoHandSignal::CTaskSimpleDoHandSignal();
return this;
}
// 0x6608B0
CTaskSimpleDoHandSignal* Destructor() {
this->CTaskSimpleDoHandSignal::~CTaskSimpleDoHandSignal();
return this;
}

protected:
bool m_Initialized{};
};

0 comments on commit a1105b8

Please sign in to comment.