summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authoreray orçunus <erayorcunus@gmail.com>2019-09-12 02:43:18 +0200
committereray orçunus <erayorcunus@gmail.com>2019-09-12 02:46:15 +0200
commit14c7c1d7ca722935195a20817c96b1af75046359 (patch)
tree0ed77a2bf6d999ff94b8c70aca1795db4b9173c7 /src/core
parentMerge pull request #202 from erorcun/erorcun (diff)
downloadre3-14c7c1d7ca722935195a20817c96b1af75046359.tar
re3-14c7c1d7ca722935195a20817c96b1af75046359.tar.gz
re3-14c7c1d7ca722935195a20817c96b1af75046359.tar.bz2
re3-14c7c1d7ca722935195a20817c96b1af75046359.tar.lz
re3-14c7c1d7ca722935195a20817c96b1af75046359.tar.xz
re3-14c7c1d7ca722935195a20817c96b1af75046359.tar.zst
re3-14c7c1d7ca722935195a20817c96b1af75046359.zip
Diffstat (limited to 'src/core')
-rw-r--r--src/core/CutsceneMgr.cpp1
-rw-r--r--src/core/CutsceneMgr.h3
-rw-r--r--src/core/Messages.cpp1
-rw-r--r--src/core/Messages.h1
-rw-r--r--src/core/PlayerInfo.cpp1
-rw-r--r--src/core/PlayerInfo.h1
-rw-r--r--src/core/World.cpp248
-rw-r--r--src/core/World.h4
-rw-r--r--src/core/config.h1
-rw-r--r--src/core/re3.cpp5
10 files changed, 262 insertions, 4 deletions
diff --git a/src/core/CutsceneMgr.cpp b/src/core/CutsceneMgr.cpp
index 744ef53d..a54e8ff6 100644
--- a/src/core/CutsceneMgr.cpp
+++ b/src/core/CutsceneMgr.cpp
@@ -5,3 +5,4 @@
bool &CCutsceneMgr::ms_running = *(bool*)0x95CCF5;
bool &CCutsceneMgr::ms_cutsceneProcessing = *(bool*)0x95CD9F;
CDirectory *&CCutsceneMgr::ms_pCutsceneDir = *(CDirectory**)0x8F5F88;
+CCutsceneObject *(&CCutsceneMgr::ms_pCutsceneObjects)[NUMCUTSCENEOBJECTS] = *(CCutsceneObject*(*)[NUMCUTSCENEOBJECTS]) *(uintptr*) 0x862170;
diff --git a/src/core/CutsceneMgr.h b/src/core/CutsceneMgr.h
index 89f6ab8d..aa5a2eb2 100644
--- a/src/core/CutsceneMgr.h
+++ b/src/core/CutsceneMgr.h
@@ -1,4 +1,5 @@
#pragma once
+#include "CutsceneObject.h"
class CDirectory;
@@ -6,10 +7,12 @@ class CCutsceneMgr
{
static bool &ms_running;
static bool &ms_cutsceneProcessing;
+ static CCutsceneObject *(&ms_pCutsceneObjects)[NUMCUTSCENEOBJECTS];
public:
static CDirectory *&ms_pCutsceneDir;
static bool IsRunning(void) { return ms_running; }
static bool IsCutsceneProcessing(void) { return ms_cutsceneProcessing; }
+ static CCutsceneObject* GetCutsceneObject(int id) { return ms_pCutsceneObjects[id]; }
};
diff --git a/src/core/Messages.cpp b/src/core/Messages.cpp
index b7b6a738..07784eda 100644
--- a/src/core/Messages.cpp
+++ b/src/core/Messages.cpp
@@ -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::ClearMessages() { EAXJMP(0x529CE0); }
WRAPPER void CMessages::Init() { EAXJMP(0x529310); }
+WRAPPER void CMessages::Process() { EAXJMP(0x529580); }
tPreviousBrief *CMessages::PreviousBriefs = (tPreviousBrief *)0x713C08;
tMessage *CMessages::BriefMessages = (tMessage *)0x8786E0;
tBigMessage *CMessages::BIGMessages = (tBigMessage *)0x773628;
diff --git a/src/core/Messages.h b/src/core/Messages.h
index 1cdcd3b7..3ee5d026 100644
--- a/src/core/Messages.h
+++ b/src/core/Messages.h
@@ -47,4 +47,5 @@ public:
static void AddMessageSoon(wchar* key, uint32 time, uint16 pos);
static void ClearMessages();
static void Init();
+ static void Process();
};
diff --git a/src/core/PlayerInfo.cpp b/src/core/PlayerInfo.cpp
index d9a4c0b0..8c505eb4 100644
--- a/src/core/PlayerInfo.cpp
+++ b/src/core/PlayerInfo.cpp
@@ -8,6 +8,7 @@
WRAPPER void CPlayerInfo::MakePlayerSafe(bool) { EAXJMP(0x4A1400); }
WRAPPER void CPlayerInfo::LoadPlayerSkin() { EAXJMP(0x4A1700); }
WRAPPER void CPlayerInfo::AwardMoneyForExplosion(CVehicle *vehicle) { EAXJMP(0x4A15F0); }
+WRAPPER void CPlayerInfo::Process(void) { EAXJMP(0x49FD30); }
void CPlayerInfo::SetPlayerSkin(char *skin)
{
diff --git a/src/core/PlayerInfo.h b/src/core/PlayerInfo.h
index 5edbc8d0..29290f6e 100644
--- a/src/core/PlayerInfo.h
+++ b/src/core/PlayerInfo.h
@@ -71,6 +71,7 @@ public:
void AwardMoneyForExplosion(CVehicle *vehicle);
void SetPlayerSkin(char* skin);
CVector& GetPos();
+ void Process(void);
};
static_assert(sizeof(CPlayerInfo) == 0x13C, "CPlayerInfo: error");
diff --git a/src/core/World.cpp b/src/core/World.cpp
index 150e87d5..29d0ac18 100644
--- a/src/core/World.cpp
+++ b/src/core/World.cpp
@@ -12,6 +12,13 @@
#include "TempColModels.h"
#include "World.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_listMovingEntityPtrs = *(CPtrList*)0x8F433C;
@@ -31,7 +38,6 @@ bool &CWorld::bProcessCutsceneOnly = *(bool*)0x95CD8B;
bool &CWorld::bDoingCarCollisions = *(bool*)0x95CD8C;
bool &CWorld::bIncludeCarTyres = *(bool*)0x95CDAA;
-WRAPPER void CWorld::Process(void) { EAXJMP(0x4B1A60); }
WRAPPER void CWorld::ShutDown(void) { EAXJMP(0x4AE450); }
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); }
@@ -930,6 +936,244 @@ FindPlayerHeading(void)
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
InjectHook(0x4AE930, CWorld::Add, PATCH_JUMP);
InjectHook(0x4AE9D0, CWorld::Remove, PATCH_JUMP);
@@ -951,4 +1195,6 @@ STARTPATCHES
InjectHook(0x4B3A80, CWorld::FindGroundZForCoord, PATCH_JUMP);
InjectHook(0x4B3AE0, CWorld::FindGroundZFor3DCoord, PATCH_JUMP);
InjectHook(0x4B3B50, CWorld::FindRoofZFor3DCoord, PATCH_JUMP);
+
+ InjectHook(0x4B1A60, CWorld::Process, PATCH_JUMP);
ENDPATCHES
diff --git a/src/core/World.h b/src/core/World.h
index c2ca75c4..b24e66f0 100644
--- a/src/core/World.h
+++ b/src/core/World.h
@@ -114,6 +114,10 @@ public:
static float GetWorldX(int x) { return x*SECTOR_SIZE_X + WORLD_MIN_X; }
static float GetWorldY(int y) { return y*SECTOR_SIZE_Y + WORLD_MIN_Y; }
+ static void RemoveEntityInsteadOfProcessingIt(CEntity* ent);
+ static void RemoveFallenPeds();
+ static void RemoveFallenCars();
+
static void Initialise();
static void ShutDown();
static void Process();
diff --git a/src/core/config.h b/src/core/config.h
index d119fe09..8c7f66c9 100644
--- a/src/core/config.h
+++ b/src/core/config.h
@@ -30,6 +30,7 @@ enum Config {
NUMOBJECTS = 450,
NUMDUMMIES = 2802, // 2368 on PS2
NUMAUDIOSCRIPTOBJECTS = 256,
+ NUMCUTSCENEOBJECTS = 50,
NUMTEMPOBJECTS = 30,
diff --git a/src/core/re3.cpp b/src/core/re3.cpp
index 9737fddb..19b3c691 100644
--- a/src/core/re3.cpp
+++ b/src/core/re3.cpp
@@ -141,10 +141,9 @@ SpawnCar(int id)
static void
LetThemFollowYou(void) {
- CPed* player = (CPed*) FindPlayerPed();
+ CPed *player = (CPed*) FindPlayerPed();
for (int i = 0; i < player->m_numNearPeds; i++) {
-
- CPed* nearPed = player->m_nearPeds[i];
+ CPed *nearPed = player->m_nearPeds[i];
if (nearPed && !nearPed->IsPlayer()) {
nearPed->SetObjective(OBJECTIVE_FOLLOW_PED_IN_FORMATION, (void*)player);
nearPed->m_pedFormation = rand() & 7;