Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Merge pull request #204 from erorcun/erorcun
World and Peds
  • Loading branch information
aap committed Sep 12, 2019
2 parents 7f81eb8 + 14c7c1d commit 4299e307d606da8c40a4d28c08628ff0da54a6d8
@@ -34,6 +34,7 @@ CAnimBlendAssociation *RpAnimBlendClumpGetMainAssociation_N(RpClump *clump, int
CAnimBlendAssociation *RpAnimBlendClumpGetMainPartialAssociation_N(RpClump *clump, int n); CAnimBlendAssociation *RpAnimBlendClumpGetMainPartialAssociation_N(RpClump *clump, int n);
CAnimBlendAssociation *RpAnimBlendClumpGetFirstAssociation(RpClump *clump, uint32 mask); CAnimBlendAssociation *RpAnimBlendClumpGetFirstAssociation(RpClump *clump, uint32 mask);
CAnimBlendAssociation *RpAnimBlendClumpGetFirstAssociation(RpClump *clump); CAnimBlendAssociation *RpAnimBlendClumpGetFirstAssociation(RpClump *clump);
void RpAnimBlendClumpUpdateAnimations(RpClump* clump, float timeDelta);




extern CAnimBlendClumpData *&gpAnimBlendClump; extern CAnimBlendClumpData *&gpAnimBlendClump;
@@ -1,6 +1,8 @@
#include "common.h" #include "common.h"
#include "patcher.h" #include "patcher.h"
#include "Game.h" #include "Game.h"
#include "World.h"
#include "Entity.h"
#include "Population.h" #include "Population.h"


PedGroup *CPopulation::ms_pPedGroups = (PedGroup*)0x6E9248; PedGroup *CPopulation::ms_pPedGroups = (PedGroup*)0x6E9248;
@@ -14,3 +16,10 @@ WRAPPER void CPopulation::UpdatePedCount(uint32, bool) { EAXJMP(0x4F5A60); }
WRAPPER void CPopulation::DealWithZoneChange(eLevelName oldLevel, eLevelName newLevel, bool) { EAXJMP(0x4F6200); } WRAPPER void CPopulation::DealWithZoneChange(eLevelName oldLevel, eLevelName newLevel, bool) { EAXJMP(0x4F6200); }
WRAPPER CPed *CPopulation::AddPedInCar(CVehicle *vehicle) { EAXJMP(0x4F5800); } WRAPPER CPed *CPopulation::AddPedInCar(CVehicle *vehicle) { EAXJMP(0x4F5800); }
WRAPPER bool CPopulation::IsPointInSafeZone(CVector *coors) { EAXJMP(0x4F60C0); } WRAPPER bool CPopulation::IsPointInSafeZone(CVector *coors) { EAXJMP(0x4F60C0); }

void
CPopulation::RemovePed(CEntity* ent)
{
CWorld::Remove(ent);
delete ent;
}
@@ -24,4 +24,5 @@ class CPopulation
static void DealWithZoneChange(eLevelName oldLevel, eLevelName newLevel, bool); static void DealWithZoneChange(eLevelName oldLevel, eLevelName newLevel, bool);
static CPed *AddPedInCar(CVehicle *vehicle); static CPed *AddPedInCar(CVehicle *vehicle);
static bool IsPointInSafeZone(CVector *coors); static bool IsPointInSafeZone(CVector *coors);
static void RemovePed(CEntity* ent);
}; };
@@ -1,6 +1,10 @@
#include "common.h" #include "common.h"
#include "patcher.h"
#include "Record.h" #include "Record.h"


uint16 &CRecordDataForGame::RecordingState = *(uint16*)0x95CC24; uint16 &CRecordDataForGame::RecordingState = *(uint16*)0x95CC24;


uint8 &CRecordDataForChase::Status = *(uint8*)0x95CDCE; uint8 &CRecordDataForChase::Status = *(uint8*)0x95CDCE;

WRAPPER void CRecordDataForChase::ProcessControlCars(void) { EAXJMP(0x435540); }
WRAPPER void CRecordDataForChase::SaveOrRetrieveCarPositions(void) { EAXJMP(0x434B20); }
@@ -6,14 +6,18 @@ enum {
RECORDSTATE_2, RECORDSTATE_2,
}; };


class CRecordDataForGame class CRecordDataForChase
{ {
public: public:
static uint16 &RecordingState; static uint8 &Status;

static void ProcessControlCars(void);
static void SaveOrRetrieveCarPositions(void);
}; };


class CRecordDataForChase
class CRecordDataForGame
{ {
public: public:
static uint8 &Status; static uint16 &RecordingState;
}; };
@@ -5,3 +5,4 @@
bool &CCutsceneMgr::ms_running = *(bool*)0x95CCF5; bool &CCutsceneMgr::ms_running = *(bool*)0x95CCF5;
bool &CCutsceneMgr::ms_cutsceneProcessing = *(bool*)0x95CD9F; bool &CCutsceneMgr::ms_cutsceneProcessing = *(bool*)0x95CD9F;
CDirectory *&CCutsceneMgr::ms_pCutsceneDir = *(CDirectory**)0x8F5F88; CDirectory *&CCutsceneMgr::ms_pCutsceneDir = *(CDirectory**)0x8F5F88;
CCutsceneObject *(&CCutsceneMgr::ms_pCutsceneObjects)[NUMCUTSCENEOBJECTS] = *(CCutsceneObject*(*)[NUMCUTSCENEOBJECTS]) *(uintptr*) 0x862170;
@@ -1,15 +1,18 @@
#pragma once #pragma once
#include "CutsceneObject.h"


class CDirectory; class CDirectory;


class CCutsceneMgr class CCutsceneMgr
{ {
static bool &ms_running; static bool &ms_running;
static bool &ms_cutsceneProcessing; static bool &ms_cutsceneProcessing;
static CCutsceneObject *(&ms_pCutsceneObjects)[NUMCUTSCENEOBJECTS];


public: public:
static CDirectory *&ms_pCutsceneDir; static CDirectory *&ms_pCutsceneDir;


static bool IsRunning(void) { return ms_running; } static bool IsRunning(void) { return ms_running; }
static bool IsCutsceneProcessing(void) { return ms_cutsceneProcessing; } static bool IsCutsceneProcessing(void) { return ms_cutsceneProcessing; }
static CCutsceneObject* GetCutsceneObject(int id) { return ms_pCutsceneObjects[id]; }
}; };
@@ -15,6 +15,7 @@ WRAPPER void CMessages::AddMessageJumpQ(wchar* key, uint32 time, uint16 pos) { E
WRAPPER void CMessages::AddMessageSoon(wchar* key, uint32 time, uint16 pos) { EAXJMP(0x529AF0); } WRAPPER void CMessages::AddMessageSoon(wchar* key, uint32 time, uint16 pos) { EAXJMP(0x529AF0); }
WRAPPER void CMessages::ClearMessages() { EAXJMP(0x529CE0); } WRAPPER void CMessages::ClearMessages() { EAXJMP(0x529CE0); }
WRAPPER void CMessages::Init() { EAXJMP(0x529310); } WRAPPER void CMessages::Init() { EAXJMP(0x529310); }
WRAPPER void CMessages::Process() { EAXJMP(0x529580); }
tPreviousBrief *CMessages::PreviousBriefs = (tPreviousBrief *)0x713C08; tPreviousBrief *CMessages::PreviousBriefs = (tPreviousBrief *)0x713C08;
tMessage *CMessages::BriefMessages = (tMessage *)0x8786E0; tMessage *CMessages::BriefMessages = (tMessage *)0x8786E0;
tBigMessage *CMessages::BIGMessages = (tBigMessage *)0x773628; tBigMessage *CMessages::BIGMessages = (tBigMessage *)0x773628;
@@ -47,4 +47,5 @@ class CMessages
static void AddMessageSoon(wchar* key, uint32 time, uint16 pos); static void AddMessageSoon(wchar* key, uint32 time, uint16 pos);
static void ClearMessages(); static void ClearMessages();
static void Init(); static void Init();
static void Process();
}; };
@@ -8,6 +8,7 @@
WRAPPER void CPlayerInfo::MakePlayerSafe(bool) { EAXJMP(0x4A1400); } WRAPPER void CPlayerInfo::MakePlayerSafe(bool) { EAXJMP(0x4A1400); }
WRAPPER void CPlayerInfo::LoadPlayerSkin() { EAXJMP(0x4A1700); } WRAPPER void CPlayerInfo::LoadPlayerSkin() { EAXJMP(0x4A1700); }
WRAPPER void CPlayerInfo::AwardMoneyForExplosion(CVehicle *vehicle) { EAXJMP(0x4A15F0); } WRAPPER void CPlayerInfo::AwardMoneyForExplosion(CVehicle *vehicle) { EAXJMP(0x4A15F0); }
WRAPPER void CPlayerInfo::Process(void) { EAXJMP(0x49FD30); }


void CPlayerInfo::SetPlayerSkin(char *skin) void CPlayerInfo::SetPlayerSkin(char *skin)
{ {
@@ -71,6 +71,7 @@ class CPlayerInfo
void AwardMoneyForExplosion(CVehicle *vehicle); void AwardMoneyForExplosion(CVehicle *vehicle);
void SetPlayerSkin(char* skin); void SetPlayerSkin(char* skin);
CVector& GetPos(); CVector& GetPos();
void Process(void);
}; };


static_assert(sizeof(CPlayerInfo) == 0x13C, "CPlayerInfo: error"); static_assert(sizeof(CPlayerInfo) == 0x13C, "CPlayerInfo: error");
@@ -12,6 +12,13 @@
#include "TempColModels.h" #include "TempColModels.h"
#include "World.h" #include "World.h"
#include "ModelIndices.h" #include "ModelIndices.h"
#include "References.h"
#include "CutsceneMgr.h"
#include "Record.h"
#include "RpAnimBlend.h"
#include "Messages.h"
#include "Replay.h"
#include "Population.h"


CPtrList *CWorld::ms_bigBuildingsList = (CPtrList*)0x6FAB60; CPtrList *CWorld::ms_bigBuildingsList = (CPtrList*)0x6FAB60;
CPtrList &CWorld::ms_listMovingEntityPtrs = *(CPtrList*)0x8F433C; CPtrList &CWorld::ms_listMovingEntityPtrs = *(CPtrList*)0x8F433C;
@@ -31,7 +38,6 @@ bool &CWorld::bProcessCutsceneOnly = *(bool*)0x95CD8B;
bool &CWorld::bDoingCarCollisions = *(bool*)0x95CD8C; bool &CWorld::bDoingCarCollisions = *(bool*)0x95CD8C;
bool &CWorld::bIncludeCarTyres = *(bool*)0x95CDAA; bool &CWorld::bIncludeCarTyres = *(bool*)0x95CDAA;


WRAPPER void CWorld::Process(void) { EAXJMP(0x4B1A60); }
WRAPPER void CWorld::ShutDown(void) { EAXJMP(0x4AE450); } WRAPPER void CWorld::ShutDown(void) { EAXJMP(0x4AE450); }
WRAPPER void CWorld::RemoveReferencesToDeletedObject(CEntity*) { EAXJMP(0x4B3BF0); } WRAPPER void CWorld::RemoveReferencesToDeletedObject(CEntity*) { EAXJMP(0x4B3BF0); }
WRAPPER void CWorld::FindObjectsKindaColliding(const CVector &, float, bool, int16*, int16, CEntity **, bool, bool, bool, bool, bool){ EAXJMP(0x4B2A30); } WRAPPER void CWorld::FindObjectsKindaColliding(const CVector &, float, bool, int16*, int16, CEntity **, bool, bool, bool, bool, bool){ EAXJMP(0x4B2A30); }
@@ -930,6 +936,244 @@ FindPlayerHeading(void)
return CWorld::Players[CWorld::PlayerInFocus].m_pPed->GetForward().Heading(); return CWorld::Players[CWorld::PlayerInFocus].m_pPed->GetForward().Heading();
} }


void
CWorld::RemoveEntityInsteadOfProcessingIt(CEntity* ent)
{
if (ent->IsPed()) {
if (FindPlayerPed() == ent)
CWorld::Remove(ent);
else
CPopulation::RemovePed(ent);
} else {
CWorld::Remove(ent);
delete ent;
}
}

void
CWorld::RemoveFallenPeds(void)
{
int poolSize = CPools::GetPedPool()->GetSize();
for(int poolIndex = poolSize-1; poolIndex >= 0; poolIndex--) {
CPed *ped = CPools::GetPedPool()->GetSlot(poolIndex);
if (ped) {
if (ped->GetPosition().z < -100.0f) {
if (ped->CharCreatedBy != RANDOM_CHAR || ped->IsPlayer()) {
int closestNode = ThePaths.FindNodeClosestToCoors(ped->GetPosition(), PATH_PED, 999999.9f, false, false);
CVector newPos = ThePaths.m_pathNodes[closestNode].pos;
newPos.z += 2.0f;
ped->Teleport(newPos);
ped->m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f);
} else {
CPopulation::RemovePed(ped);
}
}
}
}
}

void
CWorld::RemoveFallenCars(void)
{
int poolSize = CPools::GetVehiclePool()->GetSize();
for (int poolIndex = poolSize - 1; poolIndex >= 0; poolIndex--) {
CVehicle* veh = CPools::GetVehiclePool()->GetSlot(poolIndex);
if (veh) {
if (veh->GetPosition().z < -100.0f) {
if (veh->VehicleCreatedBy == MISSION_VEHICLE || veh == FindPlayerVehicle() || (veh->pDriver && veh->pDriver->IsPlayer())) {
int closestNode = ThePaths.FindNodeClosestToCoors(veh->GetPosition(), PATH_CAR, 999999.9f, false, false);
CVector newPos = ThePaths.m_pathNodes[closestNode].pos;
newPos.z += 3.0f;
veh->Teleport(newPos);
veh->m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f);
} else if (veh->VehicleCreatedBy == RANDOM_VEHICLE || veh->VehicleCreatedBy == PARKED_VEHICLE) {
CWorld::Remove(veh);
delete veh;
}
}
}
}
}

void
CWorld::Process(void)
{
if (!(CTimer::GetFrameCounter() & 63))
CReferences::PruneAllReferencesInWorld();

if (CWorld::bProcessCutsceneOnly) {
for (int i = 0; i < NUMCUTSCENEOBJECTS; i++) {
CCutsceneObject *csObj = CCutsceneMgr::GetCutsceneObject(i);
if (csObj && csObj->m_entryInfoList.first) {
if (csObj->m_rwObject && RwObjectGetType(csObj->m_rwObject) == rpCLUMP
&& RpAnimBlendClumpGetFirstAssociation(csObj->GetClump())) {
RpAnimBlendClumpUpdateAnimations(csObj->GetClump(), 0.02f * (csObj->m_type == ENTITY_TYPE_OBJECT ? CTimer::GetTimeStepNonClipped() : CTimer::GetTimeStep()));
}
csObj->ProcessControl();
csObj->ProcessCollision();
csObj->GetMatrix().UpdateRW();
csObj->UpdateRwFrame();
}
}
CRecordDataForChase::ProcessControlCars();
CRecordDataForChase::SaveOrRetrieveCarPositions();
} else {
for (CPtrNode *node = ms_listMovingEntityPtrs.first; node; node = node->next) {
CEntity *movingEnt = (CEntity*)node->item;
if (movingEnt->m_rwObject && RwObjectGetType(movingEnt->m_rwObject) == rpCLUMP
&& RpAnimBlendClumpGetFirstAssociation(movingEnt->GetClump())) {
RpAnimBlendClumpUpdateAnimations(movingEnt->GetClump(), 0.02f * (movingEnt->m_type == ENTITY_TYPE_OBJECT ? CTimer::GetTimeStepNonClipped() : CTimer::GetTimeStep()));
}
}
for (CPtrNode* node = ms_listMovingEntityPtrs.first; node; node = node->next) {
CPhysical* movingEnt = (CPhysical*)node->item;
if (movingEnt->bRemoveFromWorld) {
RemoveEntityInsteadOfProcessingIt(movingEnt);
} else {
movingEnt->ProcessControl();
if (movingEnt->bIsStatic) {
movingEnt->RemoveFromMovingList();
}
}
}
CWorld::bForceProcessControl = 1;
for (CPtrNode* node = ms_listMovingEntityPtrs.first; node; node = node->next) {
CPhysical* movingEnt = (CPhysical*)node->item;
if (movingEnt->bWasPostponed) {
if (movingEnt->bRemoveFromWorld) {
RemoveEntityInsteadOfProcessingIt(movingEnt);
} else {
movingEnt->ProcessControl();
if (movingEnt->bIsStatic) {
movingEnt->RemoveFromMovingList();
}
}
}
}
CWorld::bForceProcessControl = 0;
if (CReplay::IsPlayingBack()) {
for (CPtrNode* node = ms_listMovingEntityPtrs.first; node; node = node->next) {
CEntity* movingEnt = (CEntity*)node->item;
movingEnt->bIsInSafePosition = true;
movingEnt->GetMatrix().UpdateRW();
movingEnt->UpdateRwFrame();
}
} else {
CWorld::bNoMoreCollisionTorque = 0;
for (CPtrNode* node = ms_listMovingEntityPtrs.first; node; node = node->next) {
CEntity* movingEnt = (CEntity*)node->item;
if (!movingEnt->bIsInSafePosition) {
movingEnt->ProcessCollision();
movingEnt->GetMatrix().UpdateRW();
movingEnt->UpdateRwFrame();
}
}
CWorld::bNoMoreCollisionTorque = 1;
for (int i = 0; i < 4; i++) {
for (CPtrNode* node = ms_listMovingEntityPtrs.first; node; node = node->next) {
CEntity* movingEnt = (CEntity*)node->item;
if (!movingEnt->bIsInSafePosition) {
movingEnt->ProcessCollision();
movingEnt->GetMatrix().UpdateRW();
movingEnt->UpdateRwFrame();
}
}
}
for (CPtrNode* node = ms_listMovingEntityPtrs.first; node; node = node->next) {
CEntity* movingEnt = (CEntity*)node->item;
if (!movingEnt->bIsInSafePosition) {
movingEnt->bIsStuck = true;
movingEnt->ProcessCollision();
movingEnt->GetMatrix().UpdateRW();
movingEnt->UpdateRwFrame();
if (!movingEnt->bIsInSafePosition) {
movingEnt->bIsStuck = true;
}
}
}
CWorld::bSecondShift = 0;
for (CPtrNode* node = ms_listMovingEntityPtrs.first; node; node = node->next) {
CEntity* movingEnt = (CEntity*)node->item;
if (!movingEnt->bIsInSafePosition) {
movingEnt->ProcessShift();
movingEnt->GetMatrix().UpdateRW();
movingEnt->UpdateRwFrame();
if (!movingEnt->bIsInSafePosition) {
movingEnt->bIsStuck = true;
}
}
}
CWorld::bSecondShift = 1;
for (CPtrNode* node = ms_listMovingEntityPtrs.first; node; node = node->next) {
CPhysical* movingEnt = (CPhysical*)node->item;
if (!movingEnt->bIsInSafePosition) {
movingEnt->ProcessShift();
movingEnt->GetMatrix().UpdateRW();
movingEnt->UpdateRwFrame();
if (!movingEnt->bIsInSafePosition) {
movingEnt->bIsStuck = true;
if (movingEnt->m_status == STATUS_PLAYER) {
printf("STUCK: Final Step: Player Entity %d Is Stuck\n", movingEnt->m_modelIndex);
movingEnt->m_vecMoveSpeed *= 3.0f;
movingEnt->ApplyMoveSpeed();
movingEnt->ApplyTurnSpeed();
}
}
}
}
}
for (CPtrNode* node = ms_listMovingEntityPtrs.first; node; node = node->next) {
CPed* movingPed = (CPed*)node->item;
if (movingPed->IsPed()) {
if (movingPed->bInVehicle && movingPed->m_nPedState != PED_EXIT_TRAIN
|| movingPed->m_nPedState == PED_ENTER_CAR || movingPed->m_nPedState == PED_CARJACK) {
CVehicle *movingCar = movingPed->m_pMyVehicle;
if (movingCar) {
if (movingCar->IsTrain()) {
movingPed->SetPedPositionInTrain();
} else {
switch (movingPed->m_nPedState) {
case PED_ENTER_CAR:
case PED_CARJACK:
movingPed->EnterCar();
break;
case PED_DRAG_FROM_CAR:
movingPed->BeingDraggedFromCar();
break;
case PED_EXIT_CAR:
movingPed->ExitCar();
break;
case PED_ARRESTED:
if (movingPed->m_nLastPedState == PED_DRAG_FROM_CAR) {
movingPed->BeingDraggedFromCar();
break;
}
// fall through
default:
movingPed->SetPedPositionInCar();
break;
}
}
movingPed->GetMatrix().UpdateRW();
movingPed->UpdateRwFrame();
} else {
movingPed->bInVehicle = false;
movingPed->QuitEnteringCar();
}
}
}
}
CMessages::Process();
Players[PlayerInFocus].Process();
CRecordDataForChase::SaveOrRetrieveCarPositions();
if ((CTimer::GetFrameCounter() & 7) == 1) {
CWorld::RemoveFallenPeds();
} else if ((CTimer::GetFrameCounter() & 7) == 5) {
CWorld::RemoveFallenCars();
}
}
}

STARTPATCHES STARTPATCHES
InjectHook(0x4AE930, CWorld::Add, PATCH_JUMP); InjectHook(0x4AE930, CWorld::Add, PATCH_JUMP);
InjectHook(0x4AE9D0, CWorld::Remove, PATCH_JUMP); InjectHook(0x4AE9D0, CWorld::Remove, PATCH_JUMP);
@@ -951,4 +1195,6 @@ STARTPATCHES
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);

InjectHook(0x4B1A60, CWorld::Process, PATCH_JUMP);
ENDPATCHES ENDPATCHES

0 comments on commit 4299e30

Please sign in to comment.