From 86681c6f18b5741ba25bbbb7319bb832ffa4807a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Wed, 10 Jul 2019 09:06:43 +0300 Subject: Phone start, ped spinning and cop car fix, and some love to CPed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: eray orçunus --- src/control/Phones.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/control/Phones.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) (limited to 'src/control') diff --git a/src/control/Phones.cpp b/src/control/Phones.cpp index fa4f83e5..1d3a9777 100644 --- a/src/control/Phones.cpp +++ b/src/control/Phones.cpp @@ -2,5 +2,42 @@ #include "patcher.h" #include "Phones.h" +CPhoneInfo &gPhoneInfo = * (CPhoneInfo*) * (uintptr*)0x732A20; + +int +CPhoneInfo::FindNearestFreePhone(CVector *pos) +{ + int nearestPhoneId = -1; + float nearestPhoneDist = 60.0f; + + for (int phoneId = 0; phoneId < m_nMax; phoneId++) { + + if (gPhoneInfo.m_aPhones[phoneId].m_nState == 0) { + float phoneDist = (m_aPhones[phoneId].m_vecPos - *pos).Magnitude2D(); + + if (phoneDist < nearestPhoneDist) { + nearestPhoneDist = phoneDist; + nearestPhoneId = phoneId; + } + } + } + return nearestPhoneId; +} + +bool +CPhoneInfo::PhoneAtThisPosition(CVector pos) +{ + for (int phoneId = 0; phoneId < m_nMax; phoneId++) { + if (pos.x == m_aPhones[phoneId].m_vecPos.x && pos.y == m_aPhones[phoneId].m_vecPos.y) + return true; + } + return false; +} + +STARTPATCHES + InjectHook(0x42F720, &CPhoneInfo::FindNearestFreePhone, PATCH_JUMP); + InjectHook(0x42FD50, &CPhoneInfo::PhoneAtThisPosition, PATCH_JUMP); +ENDPATCHES + WRAPPER void PhonePutDownCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x42F570); } WRAPPER void PhonePickUpCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x42F470); } diff --git a/src/control/Phones.h b/src/control/Phones.h index a29043ed..7ac34c3a 100644 --- a/src/control/Phones.h +++ b/src/control/Phones.h @@ -1,6 +1,34 @@ #pragma once +#include "Physical.h" #include "AnimBlendAssociation.h" +struct CPhone +{ + CVector m_vecPos; + uint16 *m_apMessages[6]; + int32 field_24; + CEntity *m_pEntity; + int32 m_nState; + uint8 field_30; +}; + +static_assert(sizeof(CPhone) == 0x34, "CPhone: error"); + +class CPhoneInfo { +public: + int32 m_nMax; + int32 m_nNum; + CPhone m_aPhones[50]; + + CPhoneInfo() { } + ~CPhoneInfo() { } + + int FindNearestFreePhone(CVector*); + bool PhoneAtThisPosition(CVector); +}; + +extern CPhoneInfo &gPhoneInfo; + void PhonePutDownCB(CAnimBlendAssociation *assoc, void *arg); void PhonePickUpCB(CAnimBlendAssociation *assoc, void *arg); \ No newline at end of file -- cgit v1.2.3