Merge pull request #128 from erorcun/erorcun

Phone start, ped spinning and cop car fix, and some love to CPed
This commit is contained in:
aap 2019-07-10 15:06:08 +02:00 committed by GitHub
commit 80e0409d6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 191 additions and 9 deletions

View File

@ -2,5 +2,42 @@
#include "patcher.h" #include "patcher.h"
#include "Phones.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 PhonePutDownCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x42F570); }
WRAPPER void PhonePickUpCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x42F470); } WRAPPER void PhonePickUpCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x42F470); }

View File

@ -1,6 +1,34 @@
#pragma once #pragma once
#include "Physical.h"
#include "AnimBlendAssociation.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 PhonePutDownCB(CAnimBlendAssociation *assoc, void *arg);
void PhonePickUpCB(CAnimBlendAssociation *assoc, void *arg); void PhonePickUpCB(CAnimBlendAssociation *assoc, void *arg);

View File

@ -564,6 +564,82 @@ CWorld::GetIsLineOfSightSectorListClear(CPtrList &list, const CColLine &line, bo
return true; return true;
} }
void
CWorld::FindObjectsInRangeSectorList(CPtrList &list, CVector &centre, float distance, bool ignoreZ, short *nextObject, short lastObject, CEntity **objects)
{
float distSqr = distance * distance;
float objDistSqr;
for (CPtrNode *node = list.first; node; node = node->next) {
CEntity *object = (CEntity*)node->item;
if (object->m_scanCode != CWorld::GetCurrentScanCode()) {
object->m_scanCode = CWorld::GetCurrentScanCode();
CVector diff = centre - object->GetPosition();
if (ignoreZ)
objDistSqr = diff.MagnitudeSqr2D();
else
objDistSqr = diff.MagnitudeSqr();
if (objDistSqr < distSqr && *nextObject < lastObject) {
if (objects) {
objects[*nextObject] = object;
}
(*nextObject)++;
}
}
}
}
void
CWorld::FindObjectsInRange(CVector &centre, float distance, bool ignoreZ, short *nextObject, short lastObject, CEntity **objects, bool checkBuildings, bool checkVehicles, bool checkPeds, bool checkObjects, bool checkDummies)
{
int minX = GetSectorIndexX(centre.x - distance);
if (minX <= 0)
minX = 0;
int minY = GetSectorIndexY(centre.y - distance);
if (minY <= 0)
minY = 0;
int maxX = GetSectorIndexX(centre.x + distance);
if (maxX >= 100)
maxX = 100;
int maxY = GetSectorIndexY(centre.y + distance);
if (maxY >= 100)
maxY = 100;
AdvanceCurrentScanCode();
*nextObject = 0;
for(int curY = minY; curY <= maxY; curY++) {
for(int curX = minX; curX <= maxX; curX++) {
CSector *sector = GetSector(curX, curY);
if (checkBuildings) {
CWorld::FindObjectsInRangeSectorList(sector->m_lists[ENTITYLIST_BUILDINGS], centre, distance, ignoreZ, nextObject, lastObject, objects);
CWorld::FindObjectsInRangeSectorList(sector->m_lists[ENTITYLIST_BUILDINGS_OVERLAP], centre, distance, ignoreZ, nextObject, lastObject, objects);
}
if (checkVehicles) {
CWorld::FindObjectsInRangeSectorList(sector->m_lists[ENTITYLIST_VEHICLES], centre, distance, ignoreZ, nextObject, lastObject, objects);
CWorld::FindObjectsInRangeSectorList(sector->m_lists[ENTITYLIST_VEHICLES_OVERLAP], centre, distance, ignoreZ, nextObject, lastObject, objects);
}
if (checkPeds) {
CWorld::FindObjectsInRangeSectorList(sector->m_lists[ENTITYLIST_PEDS], centre, distance, ignoreZ, nextObject, lastObject, objects);
CWorld::FindObjectsInRangeSectorList(sector->m_lists[ENTITYLIST_PEDS_OVERLAP], centre, distance, ignoreZ, nextObject, lastObject, objects);
}
if (checkObjects) {
CWorld::FindObjectsInRangeSectorList(sector->m_lists[ENTITYLIST_OBJECTS], centre, distance, ignoreZ, nextObject, lastObject, objects);
CWorld::FindObjectsInRangeSectorList(sector->m_lists[ENTITYLIST_OBJECTS_OVERLAP], centre, distance, ignoreZ, nextObject, lastObject, objects);
}
if (checkDummies) {
CWorld::FindObjectsInRangeSectorList(sector->m_lists[ENTITYLIST_DUMMIES], centre, distance, ignoreZ, nextObject, lastObject, objects);
CWorld::FindObjectsInRangeSectorList(sector->m_lists[ENTITYLIST_DUMMIES_OVERLAP], centre, distance, ignoreZ, nextObject, lastObject, objects);
}
}
}
}
float float
CWorld::FindGroundZForCoord(float x, float y) CWorld::FindGroundZForCoord(float x, float y)
{ {
@ -712,6 +788,8 @@ STARTPATCHES
InjectHook(0x4B2000, CWorld::GetIsLineOfSightSectorClear, PATCH_JUMP); InjectHook(0x4B2000, CWorld::GetIsLineOfSightSectorClear, PATCH_JUMP);
InjectHook(0x4B2160, CWorld::GetIsLineOfSightSectorListClear, PATCH_JUMP); InjectHook(0x4B2160, CWorld::GetIsLineOfSightSectorListClear, PATCH_JUMP);
InjectHook(0x4B2200, CWorld::FindObjectsInRange, PATCH_JUMP);
InjectHook(0x4B2540, CWorld::FindObjectsInRangeSectorList, PATCH_JUMP);
InjectHook(0x4B3A80, CWorld::FindGroundZForCoord, PATCH_JUMP); InjectHook(0x4B3A80, CWorld::FindGroundZForCoord, PATCH_JUMP);
InjectHook(0x4B3AE0, CWorld::FindGroundZFor3DCoord, PATCH_JUMP); InjectHook(0x4B3AE0, CWorld::FindGroundZFor3DCoord, PATCH_JUMP);
InjectHook(0x4B3B50, CWorld::FindRoofZFor3DCoord, PATCH_JUMP); InjectHook(0x4B3B50, CWorld::FindRoofZFor3DCoord, PATCH_JUMP);

View File

@ -94,6 +94,8 @@ public:
static bool GetIsLineOfSightSectorClear(CSector &sector, const CColLine &line, bool checkBuildings, bool checkVehicles, bool checkPeds, bool checkObjects, bool checkDummies, bool ignoreSeeThrough, bool ignoreSomeObjects = false); static bool GetIsLineOfSightSectorClear(CSector &sector, const CColLine &line, bool checkBuildings, bool checkVehicles, bool checkPeds, bool checkObjects, bool checkDummies, bool ignoreSeeThrough, bool ignoreSomeObjects = false);
static bool GetIsLineOfSightSectorListClear(CPtrList &list, const CColLine &line, bool ignoreSeeThrough, bool ignoreSomeObjects = false); static bool GetIsLineOfSightSectorListClear(CPtrList &list, const CColLine &line, bool ignoreSeeThrough, bool ignoreSomeObjects = false);
static void FindObjectsInRangeSectorList(CPtrList&, CVector&, float, bool, short*, short, CEntity**);
static void FindObjectsInRange(CVector&, float, bool, short*, short, CEntity**, bool, bool, bool, bool, bool);
static float FindGroundZForCoord(float x, float y); static float FindGroundZForCoord(float x, float y);
static float FindGroundZFor3DCoord(float x, float y, float z, bool *found); static float FindGroundZFor3DCoord(float x, float y, float z, bool *found);
static float FindRoofZFor3DCoord(float x, float y, float z, bool *found); static float FindRoofZFor3DCoord(float x, float y, float z, bool *found);

View File

@ -33,7 +33,7 @@ CPhysical::CPhysical(void)
m_nCollisionRecords = 0; m_nCollisionRecords = 0;
for(i = 0; i < 6; i++) for(i = 0; i < 6; i++)
m_aCollisionRecords[0] = nil; m_aCollisionRecords[i] = nil;
field_EF = false; field_EF = false;

View File

@ -24,6 +24,7 @@
#include "Lights.h" #include "Lights.h"
#include "PointLights.h" #include "PointLights.h"
#include "Pad.h" #include "Pad.h"
#include "Phones.h"
WRAPPER void CPed::KillPedWithCar(CVehicle *veh, float impulse) { EAXJMP(0x4EC430); } WRAPPER void CPed::KillPedWithCar(CVehicle *veh, float impulse) { EAXJMP(0x4EC430); }
WRAPPER void CPed::Say(uint16 audio) { EAXJMP(0x4E5A10); } WRAPPER void CPed::Say(uint16 audio) { EAXJMP(0x4E5A10); }
@ -44,6 +45,7 @@ WRAPPER void CPed::SetFollowRoute(int16, int16) { EAXJMP(0x4DD690); }
WRAPPER void CPed::SetDuck(uint32) { EAXJMP(0x4E4920); } WRAPPER void CPed::SetDuck(uint32) { EAXJMP(0x4E4920); }
WRAPPER void CPed::RegisterThreatWithGangPeds(CEntity*) { EAXJMP(0x4E3870); } WRAPPER void CPed::RegisterThreatWithGangPeds(CEntity*) { EAXJMP(0x4E3870); }
WRAPPER void CPed::MakeChangesForNewWeapon(int8) { EAXJMP(0x4F2560); } WRAPPER void CPed::MakeChangesForNewWeapon(int8) { EAXJMP(0x4F2560); }
WRAPPER bool CPed::Seek(void) { EAXJMP(0x4D1640); }
bool &CPed::bNastyLimbsCheat = *(bool*)0x95CD44; bool &CPed::bNastyLimbsCheat = *(bool*)0x95CD44;
bool &CPed::bPedCheat2 = *(bool*)0x95CD5A; bool &CPed::bPedCheat2 = *(bool*)0x95CD5A;
@ -1391,7 +1393,7 @@ CPed::PedSetDraggedOutCarCB(CAnimBlendAssociation *dragAssoc, void *arg)
if (ped->m_nPedState != PED_ARRESTED) { if (ped->m_nPedState != PED_ARRESTED) {
ped->m_nLastPedState = PED_NONE; ped->m_nLastPedState = PED_NONE;
if (dragAssoc) if (dragAssoc)
dragAssoc->blendDelta = -1000.0; dragAssoc->blendDelta = -1000.0f;
} }
ped->RestartNonPartialAnims(); ped->RestartNonPartialAnims();
ped->m_pVehicleAnim = nil; ped->m_pVehicleAnim = nil;
@ -2057,6 +2059,7 @@ CPed::SetupLighting(void)
{ {
ActivateDirectional(); ActivateDirectional();
SetAmbientColoursForPedsCarsAndObjects(); SetAmbientColoursForPedsCarsAndObjects();
if (bRenderScorched) { if (bRenderScorched) {
WorldReplaceNormalLightsWithScorched(Scene.world, 0.1f); WorldReplaceNormalLightsWithScorched(Scene.world, 0.1f);
} else { } else {
@ -2698,7 +2701,7 @@ CPed::QuitEnteringCar(void)
if (veh->m_nNumGettingIn != 0) if (veh->m_nNumGettingIn != 0)
veh->m_nNumGettingIn--; veh->m_nNumGettingIn--;
veh->m_nGettingInFlags = GetVehDoorFlag(m_vehEnterType); veh->m_nGettingInFlags = ~GetVehDoorFlag(m_vehEnterType);
} }
bUsesCollision = true; bUsesCollision = true;
@ -2871,6 +2874,38 @@ CPed::Chat(void)
} }
} }
void
CPed::CheckAroundForPossibleCollisions(void)
{
CVector ourCentre, objCentre;
CEntity *objects[8];
int16 maxObject;
if (CTimer::GetTimeInMilliseconds() <= m_nPedStateTimer)
return;
GetBoundCentre(ourCentre);
CWorld::FindObjectsInRange(ourCentre, 10.0f, true, &maxObject, 6, objects, false, true, false, true, false);
for (int i = 0; i < maxObject; i++) {
CEntity *object = objects[i];
if (field_31C) {
if (gPhoneInfo.PhoneAtThisPosition(object->GetPosition()))
break;
}
object->GetBoundCentre(objCentre);
float radius = object->GetBoundRadius();
if (radius > 4.5f || radius < 1.0f)
radius = 1.0f;
// According to code, developers gave up calculating Z diff. later.
float diff = CVector(ourCentre - objCentre).MagnitudeSqr2D();
if (sq(radius + 1.0f) > diff)
m_fRotationDest += DEGTORAD(22.5f);
}
}
WRAPPER void CPed::PedGetupCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4CE810); } WRAPPER void CPed::PedGetupCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4CE810); }
WRAPPER void CPed::PedStaggerCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4CE8D0); } WRAPPER void CPed::PedStaggerCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4CE8D0); }
WRAPPER void CPed::PedEvadeCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4D36E0); } WRAPPER void CPed::PedEvadeCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4D36E0); }
@ -2963,4 +2998,5 @@ STARTPATCHES
InjectHook(0x4D3C80, &CPed::ClearChat, PATCH_JUMP); InjectHook(0x4D3C80, &CPed::ClearChat, PATCH_JUMP);
InjectHook(0x4D1390, &CPed::TurnBody, PATCH_JUMP); InjectHook(0x4D1390, &CPed::TurnBody, PATCH_JUMP);
InjectHook(0x4D3AC0, &CPed::Chat, PATCH_JUMP); InjectHook(0x4D3AC0, &CPed::Chat, PATCH_JUMP);
InjectHook(0x4D0490, &CPed::CheckAroundForPossibleCollisions, PATCH_JUMP);
ENDPATCHES ENDPATCHES

View File

@ -13,7 +13,7 @@
struct CPathNode; struct CPathNode;
enum eWaitState : uint32 { enum eWaitState {
WAITSTATE_FALSE, WAITSTATE_FALSE,
WAITSTATE_TRAFFIC_LIGHTS, WAITSTATE_TRAFFIC_LIGHTS,
WAITSTATE_CROSS_ROAD, WAITSTATE_CROSS_ROAD,
@ -292,10 +292,10 @@ public:
int32 m_nPrevActionState; int32 m_nPrevActionState;
eWaitState m_nWaitState; eWaitState m_nWaitState;
uint32 m_nWaitTimer; uint32 m_nWaitTimer;
void *m_pPathNodesStates[8]; void *m_pPathNodesStates[8]; // seems unused
CVector2D m_stPathNodeStates[10]; CVector2D m_stPathNodeStates[10];
uint16 m_nPathNodes; uint16 m_nPathNodes;
uint8 m_nCurPathNode; int16 m_nCurPathNode;
int8 m_nPathState; int8 m_nPathState;
private: private:
int8 _pad2B5[3]; int8 _pad2B5[3];
@ -324,7 +324,7 @@ public:
CVehicle *m_pMyVehicle; CVehicle *m_pMyVehicle;
bool bInVehicle; bool bInVehicle;
uint8 pad_315[3]; uint8 pad_315[3];
uint32 field_318; float field_318;
uint8 field_31C; uint8 field_31C;
uint8 field_31D; uint8 field_31D;
int16 m_phoneId; int16 m_phoneId;
@ -458,7 +458,8 @@ public:
bool TurnBody(void); bool TurnBody(void);
void Chat(void); void Chat(void);
void MakeChangesForNewWeapon(int8); void MakeChangesForNewWeapon(int8);
void CheckAroundForPossibleCollisions(void);
bool Seek(void);
// Static methods // Static methods
static void GetLocalPositionToOpenCarDoor(CVector *output, CVehicle *veh, uint32 enterType, float offset); static void GetLocalPositionToOpenCarDoor(CVector *output, CVehicle *veh, uint32 enterType, float offset);