2019-05-15 14:52:37 +00:00
|
|
|
#include "common.h"
|
2020-04-17 13:31:11 +00:00
|
|
|
|
2019-05-15 14:52:37 +00:00
|
|
|
#include "Pools.h"
|
2020-04-11 18:01:39 +00:00
|
|
|
|
2020-10-17 15:50:16 +00:00
|
|
|
#include "Bike.h"
|
2020-04-11 18:01:39 +00:00
|
|
|
#include "Boat.h"
|
|
|
|
#include "CarCtrl.h"
|
2020-05-26 21:25:12 +00:00
|
|
|
#ifdef MISSION_REPLAY
|
|
|
|
#include "GenericGameStorage.h"
|
|
|
|
#endif
|
2020-04-11 18:01:39 +00:00
|
|
|
#include "Population.h"
|
2019-10-16 21:53:25 +00:00
|
|
|
#include "ProjectileInfo.h"
|
2020-04-11 18:01:39 +00:00
|
|
|
#include "Streaming.h"
|
|
|
|
#include "Wanted.h"
|
|
|
|
#include "World.h"
|
2020-11-26 15:47:19 +00:00
|
|
|
#include "MemoryHeap.h"
|
2019-05-15 14:52:37 +00:00
|
|
|
|
2020-10-17 15:50:16 +00:00
|
|
|
//--MIAMI: file done
|
|
|
|
|
2020-04-17 05:54:14 +00:00
|
|
|
CCPtrNodePool *CPools::ms_pPtrNodePool;
|
|
|
|
CEntryInfoNodePool *CPools::ms_pEntryInfoNodePool;
|
|
|
|
CPedPool *CPools::ms_pPedPool;
|
|
|
|
CVehiclePool *CPools::ms_pVehiclePool;
|
|
|
|
CBuildingPool *CPools::ms_pBuildingPool;
|
|
|
|
CTreadablePool *CPools::ms_pTreadablePool;
|
|
|
|
CObjectPool *CPools::ms_pObjectPool;
|
|
|
|
CDummyPool *CPools::ms_pDummyPool;
|
|
|
|
CAudioScriptObjectPool *CPools::ms_pAudioScriptObjectPool;
|
2020-08-20 10:53:17 +00:00
|
|
|
CColModelPool *CPools::ms_pColModelPool;
|
2019-05-15 14:52:37 +00:00
|
|
|
|
2020-11-26 15:47:19 +00:00
|
|
|
#ifdef GTA_PS2 // or USE_CUSTOM_ALLOCATOR
|
|
|
|
#define CHECKMEM(msg) CMemCheck::AllocateMemCheckBlock(msg)
|
|
|
|
#else
|
|
|
|
#define CHECKMEM(msg)
|
|
|
|
#endif
|
|
|
|
|
2019-05-15 14:52:37 +00:00
|
|
|
void
|
|
|
|
CPools::Initialise(void)
|
|
|
|
{
|
2020-11-26 15:47:19 +00:00
|
|
|
PUSH_MEMID(MEMID_POOLS);
|
|
|
|
CHECKMEM("before pools");
|
2020-08-20 10:53:17 +00:00
|
|
|
ms_pPtrNodePool = new CCPtrNodePool(NUMPTRNODES, "PtrNode");
|
2020-11-26 15:47:19 +00:00
|
|
|
CHECKMEM("after CPtrNodePool");
|
2020-08-20 10:53:17 +00:00
|
|
|
ms_pEntryInfoNodePool = new CEntryInfoNodePool(NUMENTRYINFOS, "EntryInfoNode");
|
2020-11-26 15:47:19 +00:00
|
|
|
CHECKMEM("after CEntryInfoNodePool");
|
2020-08-20 10:53:17 +00:00
|
|
|
ms_pPedPool = new CPedPool(NUMPEDS, "Peds");
|
2020-11-26 15:47:19 +00:00
|
|
|
CHECKMEM("after CPedPool");
|
2020-08-20 10:53:17 +00:00
|
|
|
ms_pVehiclePool = new CVehiclePool(NUMVEHICLES, "Vehicles");
|
2020-11-26 15:47:19 +00:00
|
|
|
CHECKMEM("after CVehiclePool");
|
2020-08-20 10:53:17 +00:00
|
|
|
ms_pBuildingPool = new CBuildingPool(NUMBUILDINGS, "Buildings");
|
2020-11-26 15:47:19 +00:00
|
|
|
CHECKMEM("after CBuildingPool");
|
2020-08-20 10:53:17 +00:00
|
|
|
ms_pTreadablePool = new CTreadablePool(NUMTREADABLES, "Treadables");
|
2020-11-26 15:47:19 +00:00
|
|
|
CHECKMEM("after CTreadablePool");
|
2020-08-20 10:53:17 +00:00
|
|
|
ms_pObjectPool = new CObjectPool(NUMOBJECTS, "Objects");
|
2020-11-26 15:47:19 +00:00
|
|
|
CHECKMEM("after CObjectPool");
|
2020-08-20 10:53:17 +00:00
|
|
|
ms_pDummyPool = new CDummyPool(NUMDUMMIES, "Dummys");
|
2020-11-26 15:47:19 +00:00
|
|
|
CHECKMEM("after CDummyPool");
|
2020-08-20 10:53:17 +00:00
|
|
|
ms_pAudioScriptObjectPool = new CAudioScriptObjectPool(NUMAUDIOSCRIPTOBJECTS, "AudioScriptObj");
|
2020-12-19 00:21:04 +00:00
|
|
|
CHECKMEM("after cAudioScriptObjectPool");
|
2020-08-20 10:53:17 +00:00
|
|
|
ms_pColModelPool = new CColModelPool(NUMCOLMODELS, "ColModel");
|
2020-11-26 15:47:19 +00:00
|
|
|
CHECKMEM("after pools");
|
|
|
|
POP_MEMID();
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
2019-10-16 21:53:25 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
CPools::ShutDown(void)
|
2020-03-11 03:25:50 +00:00
|
|
|
{
|
|
|
|
debug("PtrNodes left %d\n", ms_pPtrNodePool->GetNoOfUsedSpaces());
|
|
|
|
debug("EntryInfoNodes left %d\n", ms_pEntryInfoNodePool->GetNoOfUsedSpaces());
|
|
|
|
debug("Peds left %d\n", ms_pPedPool->GetNoOfUsedSpaces());
|
|
|
|
debug("Vehicles left %d\n", ms_pVehiclePool->GetNoOfUsedSpaces());
|
|
|
|
debug("Buildings left %d\n", ms_pBuildingPool->GetNoOfUsedSpaces());
|
|
|
|
debug("Treadables left %d\n", ms_pTreadablePool->GetNoOfUsedSpaces());
|
|
|
|
debug("Objects left %d\n", ms_pObjectPool->GetNoOfUsedSpaces());
|
|
|
|
debug("Dummys left %d\n", ms_pDummyPool->GetNoOfUsedSpaces());
|
|
|
|
debug("AudioScriptObjects left %d\n", ms_pAudioScriptObjectPool->GetNoOfUsedSpaces());
|
2020-08-20 10:53:17 +00:00
|
|
|
debug("ColModels left %d\n", ms_pColModelPool->GetNoOfUsedSpaces());
|
2019-10-16 21:53:25 +00:00
|
|
|
printf("Shutdown pool started\n");
|
|
|
|
|
|
|
|
delete ms_pPtrNodePool;
|
|
|
|
delete ms_pEntryInfoNodePool;
|
|
|
|
delete ms_pPedPool;
|
|
|
|
delete ms_pVehiclePool;
|
|
|
|
delete ms_pBuildingPool;
|
|
|
|
delete ms_pTreadablePool;
|
|
|
|
delete ms_pObjectPool;
|
|
|
|
delete ms_pDummyPool;
|
|
|
|
delete ms_pAudioScriptObjectPool;
|
2020-08-20 10:53:17 +00:00
|
|
|
delete ms_pColModelPool;
|
2019-10-16 21:53:25 +00:00
|
|
|
|
|
|
|
printf("Shutdown pool done\n");
|
|
|
|
}
|
2019-07-12 16:01:22 +00:00
|
|
|
|
|
|
|
int32 CPools::GetPedRef(CPed *ped) { return ms_pPedPool->GetIndex(ped); }
|
|
|
|
CPed *CPools::GetPed(int32 handle) { return ms_pPedPool->GetAt(handle); }
|
|
|
|
int32 CPools::GetVehicleRef(CVehicle *vehicle) { return ms_pVehiclePool->GetIndex(vehicle); }
|
|
|
|
CVehicle *CPools::GetVehicle(int32 handle) { return ms_pVehiclePool->GetAt(handle); }
|
|
|
|
int32 CPools::GetObjectRef(CObject *object) { return ms_pObjectPool->GetIndex(object); }
|
|
|
|
CObject *CPools::GetObject(int32 handle) { return ms_pObjectPool->GetAt(handle); }
|
2019-10-16 21:53:25 +00:00
|
|
|
|
2020-03-11 03:25:50 +00:00
|
|
|
void
|
|
|
|
CPools::CheckPoolsEmpty()
|
|
|
|
{
|
|
|
|
assert(ms_pPedPool->GetNoOfUsedSpaces() == 0);
|
|
|
|
assert(ms_pVehiclePool->GetNoOfUsedSpaces() == 0);
|
|
|
|
printf("pools have been cleared\n");
|
2019-10-16 21:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
CPools::MakeSureSlotInObjectPoolIsEmpty(int32 slot)
|
|
|
|
{
|
|
|
|
if (ms_pObjectPool->IsFreeSlot(slot)) return;
|
|
|
|
|
|
|
|
CObject *object = ms_pObjectPool->GetSlot(slot);
|
|
|
|
if (object->ObjectCreatedBy == TEMP_OBJECT) {
|
|
|
|
CWorld::Remove(object);
|
|
|
|
delete object;
|
|
|
|
} else if (!CProjectileInfo::RemoveIfThisIsAProjectile(object)) {
|
|
|
|
// relocate to another slot??
|
2020-04-30 13:52:37 +00:00
|
|
|
CObject *newObject = new CObject(object->GetModelIndex(), false);
|
2019-10-16 21:53:25 +00:00
|
|
|
CWorld::Remove(object);
|
2020-05-13 00:01:42 +00:00
|
|
|
#if 0 // todo better
|
2020-05-11 23:24:57 +00:00
|
|
|
*newObject = *object;
|
|
|
|
#else
|
2019-10-16 21:53:25 +00:00
|
|
|
memcpy(newObject, object, ms_pObjectPool->GetMaxEntrySize());
|
2020-05-11 23:24:57 +00:00
|
|
|
#endif
|
2019-10-16 21:53:25 +00:00
|
|
|
CWorld::Add(newObject);
|
|
|
|
object->m_rwObject = nil;
|
|
|
|
delete object;
|
|
|
|
newObject->m_pFirstReference = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-13 02:31:14 +00:00
|
|
|
#define CopyFromBuf(buf, data) memcpy(&data, buf, sizeof(data)); SkipSaveBuf(buf, sizeof(data));
|
|
|
|
#define CopyToBuf(buf, data) memcpy(buf, &data, sizeof(data)); SkipSaveBuf(buf, sizeof(data));
|
|
|
|
|
2020-04-11 18:01:39 +00:00
|
|
|
void CPools::LoadVehiclePool(uint8* buf, uint32 size)
|
|
|
|
{
|
|
|
|
INITSAVEBUF
|
|
|
|
int nNumCars = ReadSaveBuf<int>(buf);
|
|
|
|
int nNumBoats = ReadSaveBuf<int>(buf);
|
2020-10-17 15:50:16 +00:00
|
|
|
int nNumBikes = ReadSaveBuf<int>(buf);
|
|
|
|
for (int i = 0; i < nNumCars + nNumBoats + nNumBikes; i++) {
|
2020-04-11 18:01:39 +00:00
|
|
|
uint32 type = ReadSaveBuf<uint32>(buf);
|
|
|
|
int16 model = ReadSaveBuf<int16>(buf);
|
|
|
|
CStreaming::RequestModel(model, STREAMFLAGS_DEPENDENCY);
|
|
|
|
CStreaming::LoadAllRequestedModels(false);
|
|
|
|
int32 slot = ReadSaveBuf<int32>(buf);
|
|
|
|
CVehicle* pVehicle;
|
2020-04-26 21:54:43 +00:00
|
|
|
#ifdef COMPATIBLE_SAVES
|
2020-05-02 15:02:17 +00:00
|
|
|
if (type == VEHICLE_TYPE_BOAT)
|
|
|
|
pVehicle = new(slot) CBoat(model, RANDOM_VEHICLE);
|
|
|
|
else if (type == VEHICLE_TYPE_CAR)
|
|
|
|
pVehicle = new(slot) CAutomobile(model, RANDOM_VEHICLE);
|
2020-10-17 15:50:16 +00:00
|
|
|
else if (type == VEHICLE_TYPE_BIKE)
|
|
|
|
pVehicle = new(slot) CBike(model, RANDOM_VEHICLE);
|
2020-05-02 15:02:17 +00:00
|
|
|
else
|
|
|
|
assert(0);
|
|
|
|
--CCarCtrl::NumRandomCars;
|
|
|
|
pVehicle->Load(buf);
|
|
|
|
CWorld::Add(pVehicle);
|
2020-04-26 21:54:43 +00:00
|
|
|
#else
|
2020-10-17 15:50:16 +00:00
|
|
|
char* vbuf = new char[Max(CBike::nSaveStructSize, Max(CAutomobile::nSaveStructSize, CBoat::nSaveStructSize))];
|
2020-04-11 18:01:39 +00:00
|
|
|
if (type == VEHICLE_TYPE_BOAT) {
|
|
|
|
memcpy(vbuf, buf, sizeof(CBoat));
|
|
|
|
SkipSaveBuf(buf, sizeof(CBoat));
|
|
|
|
CBoat* pBoat = new(slot) CBoat(model, RANDOM_VEHICLE);
|
|
|
|
pVehicle = pBoat;
|
2020-05-02 15:02:17 +00:00
|
|
|
--CCarCtrl::NumRandomCars;
|
2020-04-11 18:01:39 +00:00
|
|
|
}
|
|
|
|
else if (type == VEHICLE_TYPE_CAR) {
|
|
|
|
memcpy(vbuf, buf, sizeof(CAutomobile));
|
|
|
|
SkipSaveBuf(buf, sizeof(CAutomobile));
|
|
|
|
CStreaming::RequestModel(model, 0); // is it needed?
|
|
|
|
CStreaming::LoadAllRequestedModels(false);
|
|
|
|
CAutomobile* pAutomobile = new(slot) CAutomobile(model, RANDOM_VEHICLE);
|
|
|
|
pVehicle = pAutomobile;
|
|
|
|
CCarCtrl::NumRandomCars--; // why?
|
|
|
|
pAutomobile->Damage = ((CAutomobile*)vbuf)->Damage;
|
|
|
|
pAutomobile->SetupDamageAfterLoad();
|
|
|
|
}
|
2020-10-17 15:50:16 +00:00
|
|
|
else if (type == VEHICLE_TYPE_BIKE) {
|
|
|
|
#ifdef FIX_BUGS
|
|
|
|
memcpy(vbuf, buf, sizeof(CBike));
|
|
|
|
#else
|
|
|
|
memcpy(vbuf, buf, sizeof(CAutomobile));
|
|
|
|
#endif
|
|
|
|
SkipSaveBuf(buf, sizeof(CBike));
|
|
|
|
CBike* pBike = new(slot) CBike(model, RANDOM_VEHICLE);
|
|
|
|
pVehicle = pBike;
|
|
|
|
--CCarCtrl::NumRandomCars;
|
|
|
|
}
|
2020-04-11 18:01:39 +00:00
|
|
|
else
|
|
|
|
assert(0);
|
|
|
|
CVehicle* pBufferVehicle = (CVehicle*)vbuf;
|
|
|
|
pVehicle->GetMatrix() = pBufferVehicle->GetMatrix();
|
|
|
|
pVehicle->VehicleCreatedBy = pBufferVehicle->VehicleCreatedBy;
|
|
|
|
pVehicle->m_currentColour1 = pBufferVehicle->m_currentColour1;
|
|
|
|
pVehicle->m_currentColour2 = pBufferVehicle->m_currentColour2;
|
|
|
|
pVehicle->m_nAlarmState = pBufferVehicle->m_nAlarmState;
|
|
|
|
pVehicle->m_nNumMaxPassengers = pBufferVehicle->m_nNumMaxPassengers;
|
|
|
|
pVehicle->field_1D0[0] = pBufferVehicle->field_1D0[0];
|
|
|
|
pVehicle->field_1D0[1] = pBufferVehicle->field_1D0[1];
|
|
|
|
pVehicle->field_1D0[2] = pBufferVehicle->field_1D0[2];
|
|
|
|
pVehicle->field_1D0[3] = pBufferVehicle->field_1D0[3];
|
|
|
|
pVehicle->m_fSteerAngle = pBufferVehicle->m_fSteerAngle;
|
|
|
|
pVehicle->m_fGasPedal = pBufferVehicle->m_fGasPedal;
|
|
|
|
pVehicle->m_fBrakePedal = pBufferVehicle->m_fBrakePedal;
|
|
|
|
pVehicle->bIsLawEnforcer = pBufferVehicle->bIsLawEnforcer;
|
|
|
|
pVehicle->bIsLocked = pBufferVehicle->bIsLocked;
|
|
|
|
pVehicle->bEngineOn = pBufferVehicle->bEngineOn;
|
|
|
|
pVehicle->bIsHandbrakeOn = pBufferVehicle->bIsHandbrakeOn;
|
|
|
|
pVehicle->bLightsOn = pBufferVehicle->bLightsOn;
|
|
|
|
pVehicle->bFreebies = pBufferVehicle->bFreebies;
|
|
|
|
pVehicle->m_fHealth = pBufferVehicle->m_fHealth;
|
|
|
|
pVehicle->m_nCurrentGear = pBufferVehicle->m_nCurrentGear;
|
|
|
|
pVehicle->m_fChangeGearTime = pBufferVehicle->m_fChangeGearTime;
|
|
|
|
pVehicle->m_nTimeOfDeath = pBufferVehicle->m_nTimeOfDeath;
|
|
|
|
#ifdef FIX_BUGS //must be copypaste
|
|
|
|
pVehicle->m_nBombTimer = pBufferVehicle->m_nBombTimer;
|
|
|
|
#else
|
|
|
|
pVehicle->m_nTimeOfDeath = pBufferVehicle->m_nTimeOfDeath;
|
|
|
|
#endif
|
|
|
|
pVehicle->m_nDoorLock = pBufferVehicle->m_nDoorLock;
|
2020-04-30 13:45:45 +00:00
|
|
|
pVehicle->SetStatus(pBufferVehicle->GetStatus());
|
|
|
|
pVehicle->SetType(pBufferVehicle->GetType());
|
2020-04-11 18:01:39 +00:00
|
|
|
(pVehicle->GetAddressOfEntityProperties())[0] = (pBufferVehicle->GetAddressOfEntityProperties())[0];
|
|
|
|
(pVehicle->GetAddressOfEntityProperties())[1] = (pBufferVehicle->GetAddressOfEntityProperties())[1];
|
|
|
|
pVehicle->AutoPilot = pBufferVehicle->AutoPilot;
|
2020-10-17 15:50:16 +00:00
|
|
|
CCarCtrl::UpdateCarCount(pVehicle, false);
|
2020-04-11 18:01:39 +00:00
|
|
|
CWorld::Add(pVehicle);
|
|
|
|
delete[] vbuf;
|
2020-05-02 15:02:17 +00:00
|
|
|
#endif
|
2020-04-11 18:01:39 +00:00
|
|
|
}
|
|
|
|
VALIDATESAVEBUF(size)
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPools::SaveVehiclePool(uint8* buf, uint32* size)
|
|
|
|
{
|
|
|
|
INITSAVEBUF
|
|
|
|
int nNumCars = 0;
|
|
|
|
int nNumBoats = 0;
|
2020-10-17 15:50:16 +00:00
|
|
|
int nNumBikes = 0;
|
2020-04-11 18:01:39 +00:00
|
|
|
int nPoolSize = GetVehiclePool()->GetSize();
|
|
|
|
for (int i = 0; i < nPoolSize; i++) {
|
|
|
|
CVehicle* pVehicle = GetVehiclePool()->GetSlot(i);
|
|
|
|
if (!pVehicle)
|
|
|
|
continue;
|
|
|
|
bool bHasPassenger = false;
|
2020-04-13 18:57:13 +00:00
|
|
|
for (int j = 0; j < ARRAY_SIZE(pVehicle->pPassengers); j++) {
|
2020-04-26 21:54:43 +00:00
|
|
|
if (pVehicle->pPassengers[j])
|
2020-04-11 18:01:39 +00:00
|
|
|
bHasPassenger = true;
|
|
|
|
}
|
2020-05-26 21:25:12 +00:00
|
|
|
#ifdef MISSION_REPLAY
|
|
|
|
bool bForceSaving = CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_pMyVehicle == pVehicle && IsQuickSave;
|
|
|
|
#ifdef FIX_BUGS
|
|
|
|
if ((!pVehicle->pDriver && !bHasPassenger) || bForceSaving) {
|
|
|
|
#else
|
|
|
|
if (!pVehicle->pDriver && !bHasPassenger) {
|
|
|
|
#endif
|
|
|
|
if (pVehicle->IsCar() && (pVehicle->VehicleCreatedBy == MISSION_VEHICLE || bForceSaving))
|
|
|
|
++nNumCars;
|
|
|
|
if (pVehicle->IsBoat() && (pVehicle->VehicleCreatedBy == MISSION_VEHICLE || bForceSaving))
|
|
|
|
++nNumBoats;
|
2020-10-17 15:50:16 +00:00
|
|
|
if (pVehicle->IsBike() && (pVehicle->VehicleCreatedBy == MISSION_VEHICLE || bForceSaving))
|
|
|
|
++nNumBoats;
|
2020-05-26 21:25:12 +00:00
|
|
|
#else
|
2020-04-11 18:01:39 +00:00
|
|
|
if (!pVehicle->pDriver && !bHasPassenger) {
|
|
|
|
if (pVehicle->IsCar() && pVehicle->VehicleCreatedBy == MISSION_VEHICLE)
|
|
|
|
++nNumCars;
|
|
|
|
if (pVehicle->IsBoat() && pVehicle->VehicleCreatedBy == MISSION_VEHICLE)
|
|
|
|
++nNumBoats;
|
2020-10-17 15:50:16 +00:00
|
|
|
if (pVehicle->IsBike() && pVehicle->VehicleCreatedBy == MISSION_VEHICLE)
|
|
|
|
++nNumBoats;
|
2020-05-26 21:25:12 +00:00
|
|
|
#endif
|
2020-04-11 18:01:39 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-02 15:02:17 +00:00
|
|
|
*size = nNumCars * (sizeof(uint32) + sizeof(int16) + sizeof(int32) + CAutomobile::nSaveStructSize) + sizeof(int) +
|
2020-10-17 15:50:16 +00:00
|
|
|
nNumBoats * (sizeof(uint32) + sizeof(int16) + sizeof(int32) + CBoat::nSaveStructSize) + sizeof(int) +
|
|
|
|
nNumBikes * (sizeof(uint32) + sizeof(int16) + sizeof(int32) + CBike::nSaveStructSize) + sizeof(int);
|
2020-04-11 18:01:39 +00:00
|
|
|
WriteSaveBuf(buf, nNumCars);
|
|
|
|
WriteSaveBuf(buf, nNumBoats);
|
2020-10-17 15:50:16 +00:00
|
|
|
WriteSaveBuf(buf, nNumBikes);
|
2020-04-11 18:01:39 +00:00
|
|
|
for (int i = 0; i < nPoolSize; i++) {
|
|
|
|
CVehicle* pVehicle = GetVehiclePool()->GetSlot(i);
|
|
|
|
if (!pVehicle)
|
|
|
|
continue;
|
|
|
|
bool bHasPassenger = false;
|
2020-04-13 18:57:13 +00:00
|
|
|
for (int j = 0; j < ARRAY_SIZE(pVehicle->pPassengers); j++) {
|
2020-04-11 18:01:39 +00:00
|
|
|
if (pVehicle->pPassengers[j])
|
|
|
|
bHasPassenger = true;
|
|
|
|
}
|
2020-05-26 21:25:12 +00:00
|
|
|
#ifdef MISSION_REPLAY
|
|
|
|
bool bForceSaving = CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_pMyVehicle == pVehicle && IsQuickSave;
|
|
|
|
#endif
|
|
|
|
#if defined FIX_BUGS && defined MISSION_REPLAY
|
|
|
|
if ((!pVehicle->pDriver && !bHasPassenger) || bForceSaving) {
|
|
|
|
#else
|
2020-04-11 18:01:39 +00:00
|
|
|
if (!pVehicle->pDriver && !bHasPassenger) {
|
2020-05-26 21:25:12 +00:00
|
|
|
#endif
|
2020-05-02 15:02:17 +00:00
|
|
|
#ifdef COMPATIBLE_SAVES
|
2020-05-26 21:25:12 +00:00
|
|
|
#ifdef MISSION_REPLAY
|
2020-10-17 15:50:16 +00:00
|
|
|
if ((pVehicle->IsCar() || pVehicle->IsBoat() || pVehicle->IsBike()) && (pVehicle->VehicleCreatedBy == MISSION_VEHICLE || bForceSaving)) {
|
2020-05-26 21:25:12 +00:00
|
|
|
#else
|
2020-10-17 15:50:16 +00:00
|
|
|
if ((pVehicle->IsCar() || pVehicle->IsBoat() || pVehicle->IsBike()) && pVehicle->VehicleCreatedBy == MISSION_VEHICLE) {
|
2020-05-26 21:25:12 +00:00
|
|
|
#endif
|
2020-05-02 15:02:17 +00:00
|
|
|
WriteSaveBuf<uint32>(buf, pVehicle->m_vehType);
|
2020-05-05 11:48:35 +00:00
|
|
|
WriteSaveBuf<int16>(buf, pVehicle->GetModelIndex());
|
2020-05-02 15:02:17 +00:00
|
|
|
WriteSaveBuf<int32>(buf, GetVehicleRef(pVehicle));
|
|
|
|
pVehicle->Save(buf);
|
|
|
|
}
|
2020-05-26 21:25:12 +00:00
|
|
|
#else
|
|
|
|
#ifdef MISSION_REPLAY
|
|
|
|
if (pVehicle->IsCar() && (pVehicle->VehicleCreatedBy == MISSION_VEHICLE || bForceSaving)) {
|
2020-05-02 15:02:17 +00:00
|
|
|
#else
|
2020-04-11 18:01:39 +00:00
|
|
|
if (pVehicle->IsCar() && pVehicle->VehicleCreatedBy == MISSION_VEHICLE) {
|
2020-05-26 21:25:12 +00:00
|
|
|
#endif
|
2020-04-11 18:01:39 +00:00
|
|
|
WriteSaveBuf(buf, (uint32)pVehicle->m_vehType);
|
2020-05-05 11:48:35 +00:00
|
|
|
WriteSaveBuf(buf, pVehicle->GetModelIndex());
|
2020-04-11 18:01:39 +00:00
|
|
|
WriteSaveBuf(buf, GetVehicleRef(pVehicle));
|
|
|
|
memcpy(buf, pVehicle, sizeof(CAutomobile));
|
|
|
|
SkipSaveBuf(buf, sizeof(CAutomobile));
|
|
|
|
}
|
2020-05-26 21:25:12 +00:00
|
|
|
#ifdef MISSION_REPLAY
|
|
|
|
if (pVehicle->IsBoat() && (pVehicle->VehicleCreatedBy == MISSION_VEHICLE || bForceSaving)) {
|
|
|
|
#else
|
2020-04-11 18:01:39 +00:00
|
|
|
if (pVehicle->IsBoat() && pVehicle->VehicleCreatedBy == MISSION_VEHICLE) {
|
2020-05-26 21:25:12 +00:00
|
|
|
#endif
|
2020-04-11 18:01:39 +00:00
|
|
|
WriteSaveBuf(buf, (uint32)pVehicle->m_vehType);
|
2020-05-05 11:48:35 +00:00
|
|
|
WriteSaveBuf(buf, pVehicle->GetModelIndex());
|
2020-04-11 18:01:39 +00:00
|
|
|
WriteSaveBuf(buf, GetVehicleRef(pVehicle));
|
|
|
|
memcpy(buf, pVehicle, sizeof(CBoat));
|
|
|
|
SkipSaveBuf(buf, sizeof(CBoat));
|
|
|
|
}
|
2020-10-17 15:50:16 +00:00
|
|
|
#ifdef MISSION_REPLAY
|
|
|
|
if (pVehicle->IsBike() && (pVehicle->VehicleCreatedBy == MISSION_VEHICLE || bForceSaving)) {
|
|
|
|
#else
|
|
|
|
if (pVehicle->IsBike() && pVehicle->VehicleCreatedBy == MISSION_VEHICLE) {
|
|
|
|
#endif
|
|
|
|
WriteSaveBuf(buf, (uint32)pVehicle->m_vehType);
|
|
|
|
WriteSaveBuf(buf, pVehicle->GetModelIndex());
|
|
|
|
WriteSaveBuf(buf, GetVehicleRef(pVehicle));
|
|
|
|
memcpy(buf, pVehicle, sizeof(CBike));
|
|
|
|
SkipSaveBuf(buf, sizeof(CBike));
|
|
|
|
}
|
2020-05-02 15:02:17 +00:00
|
|
|
#endif
|
2020-04-11 18:01:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
VALIDATESAVEBUF(*size)
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPools::SaveObjectPool(uint8* buf, uint32* size)
|
|
|
|
{
|
|
|
|
INITSAVEBUF
|
|
|
|
CProjectileInfo::RemoveAllProjectiles();
|
|
|
|
CObject::DeleteAllTempObjects();
|
|
|
|
int nObjects = 0;
|
|
|
|
int nPoolSize = GetObjectPool()->GetSize();
|
|
|
|
for (int i = 0; i < nPoolSize; i++) {
|
|
|
|
CObject* pObject = GetObjectPool()->GetSlot(i);
|
|
|
|
if (!pObject)
|
|
|
|
continue;
|
|
|
|
if (pObject->ObjectCreatedBy == MISSION_OBJECT)
|
|
|
|
++nObjects;
|
|
|
|
}
|
2020-05-13 02:31:14 +00:00
|
|
|
*size = nObjects * (sizeof(int16) + sizeof(int) + sizeof(CCompressedMatrix) +
|
2020-10-17 17:45:07 +00:00
|
|
|
sizeof(float) + sizeof(CCompressedMatrix) + sizeof(int8) + 7 * sizeof(bool) + sizeof(int16) +
|
|
|
|
+ sizeof(int8) * 2 + sizeof(float) + sizeof(int8) + sizeof(int8) +
|
|
|
|
sizeof(uint32) + 2 * sizeof(uint32)) + sizeof(int);
|
2020-05-13 02:31:14 +00:00
|
|
|
CopyToBuf(buf, nObjects);
|
2020-04-11 18:01:39 +00:00
|
|
|
for (int i = 0; i < nPoolSize; i++) {
|
|
|
|
CObject* pObject = GetObjectPool()->GetSlot(i);
|
|
|
|
if (!pObject)
|
|
|
|
continue;
|
|
|
|
if (pObject->ObjectCreatedBy == MISSION_OBJECT) {
|
|
|
|
bool bIsPickup = pObject->bIsPickup;
|
2020-04-19 04:14:13 +00:00
|
|
|
bool bPickupObjWithMessage = pObject->bPickupObjWithMessage;
|
2020-04-11 18:01:39 +00:00
|
|
|
bool bOutOfStock = pObject->bOutOfStock;
|
|
|
|
bool bGlassCracked = pObject->bGlassCracked;
|
|
|
|
bool bGlassBroken = pObject->bGlassBroken;
|
|
|
|
bool bHasBeenDamaged = pObject->bHasBeenDamaged;
|
|
|
|
bool bUseVehicleColours = pObject->bUseVehicleColours;
|
2020-05-13 02:31:14 +00:00
|
|
|
CCompressedMatrix tmp;
|
|
|
|
CopyToBuf(buf, pObject->m_modelIndex);
|
|
|
|
int32 ref = GetObjectRef(pObject);
|
|
|
|
CopyToBuf(buf, ref);
|
2020-04-11 18:01:39 +00:00
|
|
|
tmp.CompressFromFullMatrix(pObject->GetMatrix());
|
2020-05-13 02:31:14 +00:00
|
|
|
CopyToBuf(buf, tmp);
|
|
|
|
CopyToBuf(buf, pObject->m_fUprootLimit);
|
2020-04-11 18:01:39 +00:00
|
|
|
tmp.CompressFromFullMatrix(pObject->m_objectMatrix);
|
2020-05-13 02:31:14 +00:00
|
|
|
CopyToBuf(buf, tmp);
|
|
|
|
CopyToBuf(buf, pObject->ObjectCreatedBy);
|
|
|
|
CopyToBuf(buf, bIsPickup);
|
|
|
|
CopyToBuf(buf, bPickupObjWithMessage);
|
|
|
|
CopyToBuf(buf, bOutOfStock);
|
|
|
|
CopyToBuf(buf, bGlassCracked);
|
|
|
|
CopyToBuf(buf, bGlassBroken);
|
|
|
|
CopyToBuf(buf, bHasBeenDamaged);
|
|
|
|
CopyToBuf(buf, bUseVehicleColours);
|
2020-10-18 09:34:34 +00:00
|
|
|
CopyToBuf(buf, pObject->m_nCostValue);
|
2020-10-17 15:50:16 +00:00
|
|
|
CopyToBuf(buf, pObject->m_nBonusValue);
|
2020-10-17 17:45:07 +00:00
|
|
|
SkipSaveBuf(buf, 1);
|
2020-05-13 02:31:14 +00:00
|
|
|
CopyToBuf(buf, pObject->m_fCollisionDamageMultiplier);
|
|
|
|
CopyToBuf(buf, pObject->m_nCollisionDamageEffect);
|
|
|
|
CopyToBuf(buf, pObject->m_nSpecialCollisionResponseCases);
|
|
|
|
CopyToBuf(buf, pObject->m_nEndOfLifeTime);
|
2020-04-26 21:54:43 +00:00
|
|
|
#ifdef COMPATIBLE_SAVES
|
2020-05-02 15:02:17 +00:00
|
|
|
pObject->SaveEntityFlags(buf);
|
2020-04-26 21:54:43 +00:00
|
|
|
#else
|
2020-05-13 02:31:14 +00:00
|
|
|
CopyToBuf(buf, (pObject->GetAddressOfEntityProperties())[0]);
|
|
|
|
CopyToBuf(buf, (pObject->GetAddressOfEntityProperties())[1]);
|
2020-04-26 21:54:43 +00:00
|
|
|
#endif
|
2020-04-11 18:01:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
VALIDATESAVEBUF(*size)
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPools::LoadObjectPool(uint8* buf, uint32 size)
|
|
|
|
{
|
|
|
|
INITSAVEBUF
|
2020-05-13 02:31:14 +00:00
|
|
|
int nObjects;
|
|
|
|
CopyFromBuf(buf, nObjects);
|
2020-04-11 18:01:39 +00:00
|
|
|
for (int i = 0; i < nObjects; i++) {
|
2020-05-13 02:31:14 +00:00
|
|
|
int16 mi;
|
|
|
|
CopyFromBuf(buf, mi);
|
|
|
|
int ref;
|
|
|
|
CopyFromBuf(buf, ref);
|
2020-04-11 18:01:39 +00:00
|
|
|
char* obuf = new char[sizeof(CObject)];
|
|
|
|
CObject* pBufferObject = (CObject*)obuf;
|
2020-05-13 02:31:14 +00:00
|
|
|
CCompressedMatrix tmp;
|
|
|
|
CopyFromBuf(buf, tmp);
|
2020-04-11 18:01:39 +00:00
|
|
|
tmp.DecompressIntoFullMatrix(pBufferObject->GetMatrix());
|
2020-05-13 02:31:14 +00:00
|
|
|
CopyFromBuf(buf, pBufferObject->m_fUprootLimit);
|
|
|
|
CopyFromBuf(buf, tmp);
|
2020-04-11 18:01:39 +00:00
|
|
|
tmp.DecompressIntoFullMatrix(pBufferObject->m_objectMatrix);
|
2020-05-13 02:31:14 +00:00
|
|
|
CopyFromBuf(buf, pBufferObject->ObjectCreatedBy);
|
|
|
|
int8 bitFlag;
|
|
|
|
CopyFromBuf(buf, bitFlag);
|
|
|
|
pBufferObject->bIsPickup = bitFlag;
|
|
|
|
CopyFromBuf(buf, bitFlag);
|
|
|
|
pBufferObject->bPickupObjWithMessage = bitFlag;
|
|
|
|
CopyFromBuf(buf, bitFlag);
|
|
|
|
pBufferObject->bOutOfStock = bitFlag;
|
|
|
|
CopyFromBuf(buf, bitFlag);
|
|
|
|
pBufferObject->bGlassCracked = bitFlag;
|
|
|
|
CopyFromBuf(buf, bitFlag);
|
|
|
|
pBufferObject->bGlassBroken = bitFlag;
|
|
|
|
CopyFromBuf(buf, bitFlag);
|
|
|
|
pBufferObject->bHasBeenDamaged = bitFlag;
|
|
|
|
CopyFromBuf(buf, bitFlag);
|
|
|
|
pBufferObject->bUseVehicleColours = bitFlag;
|
2020-10-18 09:34:34 +00:00
|
|
|
CopyFromBuf(buf, pBufferObject->m_nCostValue);
|
2020-10-17 15:50:16 +00:00
|
|
|
CopyFromBuf(buf, pBufferObject->m_nBonusValue);
|
|
|
|
SkipSaveBuf(buf, 1);
|
2020-05-13 02:31:14 +00:00
|
|
|
CopyFromBuf(buf, pBufferObject->m_fCollisionDamageMultiplier);
|
|
|
|
CopyFromBuf(buf, pBufferObject->m_nCollisionDamageEffect);
|
|
|
|
CopyFromBuf(buf, pBufferObject->m_nSpecialCollisionResponseCases);
|
|
|
|
CopyFromBuf(buf, pBufferObject->m_nEndOfLifeTime);
|
2020-05-02 15:02:17 +00:00
|
|
|
#ifndef COMPATIBLE_SAVES
|
2020-05-13 02:31:14 +00:00
|
|
|
CopyFromBuf(buf, (pBufferObject->GetAddressOfEntityProperties())[0]);
|
|
|
|
CopyFromBuf(buf, (pBufferObject->GetAddressOfEntityProperties())[1]);
|
2020-04-26 21:54:43 +00:00
|
|
|
#endif
|
2020-04-11 18:01:39 +00:00
|
|
|
if (GetObjectPool()->GetSlot(ref >> 8))
|
|
|
|
CPopulation::ConvertToDummyObject(GetObjectPool()->GetSlot(ref >> 8));
|
|
|
|
CObject* pObject = new(ref) CObject(mi, false);
|
|
|
|
pObject->GetMatrix() = pBufferObject->GetMatrix();
|
2020-05-02 15:02:17 +00:00
|
|
|
#ifdef COMPATIBLE_SAVES
|
|
|
|
pObject->LoadEntityFlags(buf);
|
|
|
|
#endif
|
2020-04-11 18:01:39 +00:00
|
|
|
pObject->m_fUprootLimit = pBufferObject->m_fUprootLimit;
|
|
|
|
pObject->m_objectMatrix = pBufferObject->m_objectMatrix;
|
|
|
|
pObject->ObjectCreatedBy = pBufferObject->ObjectCreatedBy;
|
|
|
|
pObject->bIsPickup = pBufferObject->bIsPickup;
|
2020-04-19 04:14:13 +00:00
|
|
|
pObject->bPickupObjWithMessage = pBufferObject->bPickupObjWithMessage;
|
2020-04-11 18:01:39 +00:00
|
|
|
pObject->bOutOfStock = pBufferObject->bOutOfStock;
|
|
|
|
pObject->bGlassCracked = pBufferObject->bGlassCracked;
|
|
|
|
pObject->bGlassBroken = pBufferObject->bGlassBroken;
|
|
|
|
pObject->bHasBeenDamaged = pBufferObject->bHasBeenDamaged;
|
|
|
|
pObject->bUseVehicleColours = pBufferObject->bUseVehicleColours;
|
|
|
|
pObject->m_fCollisionDamageMultiplier = pBufferObject->m_fCollisionDamageMultiplier;
|
|
|
|
pObject->m_nCollisionDamageEffect = pBufferObject->m_nCollisionDamageEffect;
|
|
|
|
pObject->m_nSpecialCollisionResponseCases = pBufferObject->m_nSpecialCollisionResponseCases;
|
|
|
|
pObject->m_nEndOfLifeTime = pBufferObject->m_nEndOfLifeTime;
|
2020-05-02 15:02:17 +00:00
|
|
|
#ifndef COMPATIBLE_SAVES
|
2020-04-11 18:01:39 +00:00
|
|
|
(pObject->GetAddressOfEntityProperties())[0] = (pBufferObject->GetAddressOfEntityProperties())[0];
|
|
|
|
(pObject->GetAddressOfEntityProperties())[1] = (pBufferObject->GetAddressOfEntityProperties())[1];
|
2020-04-26 21:54:43 +00:00
|
|
|
#endif
|
2020-04-11 18:01:39 +00:00
|
|
|
pObject->bHasCollided = false;
|
2020-10-18 09:34:34 +00:00
|
|
|
pObject->m_nCostValue = pBufferObject->m_nCostValue;
|
2020-10-17 15:50:16 +00:00
|
|
|
pObject->m_nBonusValue = pBufferObject->m_nBonusValue;
|
2020-04-11 18:01:39 +00:00
|
|
|
CWorld::Add(pObject);
|
|
|
|
delete[] obuf;
|
|
|
|
}
|
|
|
|
VALIDATESAVEBUF(size)
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPools::SavePedPool(uint8* buf, uint32* size)
|
|
|
|
{
|
|
|
|
INITSAVEBUF
|
|
|
|
int nNumPeds = 0;
|
|
|
|
int nPoolSize = GetPedPool()->GetSize();
|
|
|
|
for (int i = 0; i < nPoolSize; i++) {
|
|
|
|
CPed* pPed = GetPedPool()->GetSlot(i);
|
|
|
|
if (!pPed)
|
|
|
|
continue;
|
2020-05-26 21:25:12 +00:00
|
|
|
#ifdef MISSION_REPLAY
|
|
|
|
if ((!pPed->bInVehicle || (pPed == CWorld::Players[CWorld::PlayerInFocus].m_pPed && IsQuickSave)) && pPed->m_nPedType == PEDTYPE_PLAYER1)
|
|
|
|
#else
|
2020-04-11 18:01:39 +00:00
|
|
|
if (!pPed->bInVehicle && pPed->m_nPedType == PEDTYPE_PLAYER1)
|
2020-05-26 21:25:12 +00:00
|
|
|
#endif
|
2020-04-11 18:01:39 +00:00
|
|
|
nNumPeds++;
|
|
|
|
}
|
2020-05-02 15:02:17 +00:00
|
|
|
*size = sizeof(int) + nNumPeds * (sizeof(uint32) + sizeof(int16) + sizeof(int) + CPlayerPed::nSaveStructSize +
|
2020-04-11 18:01:39 +00:00
|
|
|
sizeof(CWanted::MaximumWantedLevel) + sizeof(CWanted::nMaximumWantedLevel) + MAX_MODEL_NAME);
|
2020-05-13 02:31:14 +00:00
|
|
|
CopyToBuf(buf, nNumPeds);
|
2020-04-11 18:01:39 +00:00
|
|
|
for (int i = 0; i < nPoolSize; i++) {
|
|
|
|
CPed* pPed = GetPedPool()->GetSlot(i);
|
|
|
|
if (!pPed)
|
|
|
|
continue;
|
2020-05-26 21:25:12 +00:00
|
|
|
#ifdef MISSION_REPLAY
|
|
|
|
if ((!pPed->bInVehicle || (pPed == CWorld::Players[CWorld::PlayerInFocus].m_pPed && IsQuickSave)) && pPed->m_nPedType == PEDTYPE_PLAYER1) {
|
|
|
|
#else
|
2020-04-11 18:01:39 +00:00
|
|
|
if (!pPed->bInVehicle && pPed->m_nPedType == PEDTYPE_PLAYER1) {
|
2020-05-26 21:25:12 +00:00
|
|
|
#endif
|
2020-05-13 02:31:14 +00:00
|
|
|
CopyToBuf(buf, pPed->m_nPedType);
|
|
|
|
CopyToBuf(buf, pPed->m_modelIndex);
|
|
|
|
int32 ref = GetPedRef(pPed);
|
|
|
|
CopyToBuf(buf, ref);
|
2020-04-26 21:54:43 +00:00
|
|
|
#ifdef COMPATIBLE_SAVES
|
2020-05-02 15:02:17 +00:00
|
|
|
pPed->Save(buf);
|
2020-04-26 21:54:43 +00:00
|
|
|
#else
|
2020-04-11 18:01:39 +00:00
|
|
|
memcpy(buf, pPed, sizeof(CPlayerPed));
|
|
|
|
SkipSaveBuf(buf, sizeof(CPlayerPed));
|
2020-04-26 21:54:43 +00:00
|
|
|
#endif
|
2020-05-13 02:31:14 +00:00
|
|
|
CopyToBuf(buf, CWanted::MaximumWantedLevel);
|
|
|
|
CopyToBuf(buf, CWanted::nMaximumWantedLevel);
|
2020-04-11 18:01:39 +00:00
|
|
|
memcpy(buf, CModelInfo::GetModelInfo(pPed->GetModelIndex())->GetName(), MAX_MODEL_NAME);
|
|
|
|
SkipSaveBuf(buf, MAX_MODEL_NAME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VALIDATESAVEBUF(*size);
|
2020-05-13 02:31:14 +00:00
|
|
|
#undef CopyToBuf
|
2020-04-11 18:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPools::LoadPedPool(uint8* buf, uint32 size)
|
|
|
|
{
|
|
|
|
INITSAVEBUF
|
2020-05-13 02:31:14 +00:00
|
|
|
int nPeds;
|
|
|
|
CopyFromBuf(buf, nPeds);
|
2020-04-11 18:01:39 +00:00
|
|
|
for (int i = 0; i < nPeds; i++) {
|
2020-05-13 02:31:14 +00:00
|
|
|
uint32 pedtype;
|
|
|
|
int16 model;
|
|
|
|
int ref;
|
|
|
|
|
|
|
|
CopyFromBuf(buf, pedtype);
|
|
|
|
CopyFromBuf(buf, model);
|
|
|
|
CopyFromBuf(buf, ref);
|
2020-04-26 21:54:43 +00:00
|
|
|
#ifdef COMPATIBLE_SAVES
|
2020-05-02 15:02:17 +00:00
|
|
|
CPed* pPed;
|
|
|
|
|
|
|
|
char name[MAX_MODEL_NAME];
|
|
|
|
// Unfortunate hack: player model is stored after ped structure.
|
|
|
|
// It could be avoided by just using "player" because in practice it is always true.
|
|
|
|
memcpy(name, buf + CPlayerPed::nSaveStructSize + 2 * sizeof(int32), MAX_MODEL_NAME);
|
|
|
|
CStreaming::RequestSpecialModel(model, name, STREAMFLAGS_DONT_REMOVE);
|
|
|
|
CStreaming::LoadAllRequestedModels(false);
|
|
|
|
|
|
|
|
if (pedtype == PEDTYPE_PLAYER1)
|
|
|
|
pPed = new(ref) CPlayerPed();
|
|
|
|
else
|
|
|
|
assert(0);
|
|
|
|
|
|
|
|
pPed->Load(buf);
|
|
|
|
if (pedtype == PEDTYPE_PLAYER1) {
|
2020-05-13 02:31:14 +00:00
|
|
|
CopyFromBuf(buf, CWanted::MaximumWantedLevel);
|
|
|
|
CopyFromBuf(buf, CWanted::nMaximumWantedLevel);
|
2020-05-02 15:02:17 +00:00
|
|
|
SkipSaveBuf(buf, MAX_MODEL_NAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pedtype == PEDTYPE_PLAYER1) {
|
|
|
|
pPed->m_wepAccuracy = 100;
|
|
|
|
CWorld::Players[0].m_pPed = (CPlayerPed*)pPed;
|
|
|
|
}
|
|
|
|
CWorld::Add(pPed);
|
2020-04-26 21:54:43 +00:00
|
|
|
#else
|
2020-04-11 18:01:39 +00:00
|
|
|
char* pbuf = new char[sizeof(CPlayerPed)];
|
|
|
|
CPlayerPed* pBufferPlayer = (CPlayerPed*)pbuf;
|
|
|
|
CPed* pPed;
|
|
|
|
char name[MAX_MODEL_NAME];
|
|
|
|
// the code implies that there was idea to load non-player ped
|
|
|
|
if (pedtype == PEDTYPE_PLAYER1) { // always true
|
|
|
|
memcpy(pbuf, buf, sizeof(CPlayerPed));
|
|
|
|
SkipSaveBuf(buf, sizeof(CPlayerPed));
|
2020-05-13 02:31:14 +00:00
|
|
|
CopyFromBuf(buf, CWanted::MaximumWantedLevel);
|
|
|
|
CopyFromBuf(buf, CWanted::nMaximumWantedLevel);
|
|
|
|
CopyFromBuf(buf, name);
|
2020-04-11 18:01:39 +00:00
|
|
|
}
|
|
|
|
CStreaming::RequestSpecialModel(model, name, STREAMFLAGS_DONT_REMOVE);
|
|
|
|
CStreaming::LoadAllRequestedModels(false);
|
|
|
|
if (pedtype == PEDTYPE_PLAYER1) {
|
|
|
|
CPlayerPed* pPlayerPed = new(ref) CPlayerPed();
|
|
|
|
for (int i = 0; i < ARRAY_SIZE(pPlayerPed->m_nTargettableObjects); i++)
|
|
|
|
pPlayerPed->m_nTargettableObjects[i] = pBufferPlayer->m_nTargettableObjects[i];
|
|
|
|
pPlayerPed->m_fMaxStamina = pBufferPlayer->m_fMaxStamina;
|
|
|
|
pPed = pPlayerPed;
|
|
|
|
}
|
2020-05-13 02:31:14 +00:00
|
|
|
pPed->SetPosition(pBufferPlayer->GetPosition());
|
2020-04-11 18:01:39 +00:00
|
|
|
pPed->m_fHealth = pBufferPlayer->m_fHealth;
|
|
|
|
pPed->m_fArmour = pBufferPlayer->m_fArmour;
|
|
|
|
pPed->CharCreatedBy = pBufferPlayer->CharCreatedBy;
|
|
|
|
pPed->m_currentWeapon = 0;
|
|
|
|
pPed->m_maxWeaponTypeAllowed = pBufferPlayer->m_maxWeaponTypeAllowed;
|
2020-05-15 14:30:25 +00:00
|
|
|
for (int i = 0; i < TOTAL_WEAPON_SLOTS; i++) {
|
|
|
|
if (pBufferPlayer->HasWeaponSlot(i)) {
|
|
|
|
int modelId = CWeaponInfo::GetWeaponInfo(pBufferPlayer->GetWeapon(i).m_eWeaponType)->m_nModelId;
|
|
|
|
if (modelId != -1) {
|
|
|
|
CStreaming::RequestModel(modelId, STREAMFLAGS_DEPENDENCY);
|
|
|
|
int modelId2 = CWeaponInfo::GetWeaponInfo(pBufferPlayer->GetWeapon(i).m_eWeaponType)->m_nModel2Id;
|
|
|
|
if (modelId2 != -1)
|
|
|
|
CStreaming::RequestModel(modelId2, STREAMFLAGS_DEPENDENCY);
|
|
|
|
|
|
|
|
CStreaming::LoadAllRequestedModels(false);
|
|
|
|
}
|
2020-11-13 10:19:54 +00:00
|
|
|
pPed->GiveWeapon(pBufferPlayer->GetWeapon(i).m_eWeaponType, pBufferPlayer->GetWeapon(i).m_nAmmoTotal, false);
|
2020-05-15 14:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-02 15:02:17 +00:00
|
|
|
|
2020-04-11 18:01:39 +00:00
|
|
|
if (pedtype == PEDTYPE_PLAYER1) {
|
|
|
|
pPed->m_wepAccuracy = 100;
|
|
|
|
CWorld::Players[0].m_pPed = (CPlayerPed*)pPed;
|
|
|
|
}
|
|
|
|
CWorld::Add(pPed);
|
|
|
|
delete[] pbuf;
|
2020-05-02 15:02:17 +00:00
|
|
|
#endif
|
2020-04-11 18:01:39 +00:00
|
|
|
}
|
|
|
|
VALIDATESAVEBUF(size)
|
|
|
|
}
|
2020-05-13 02:31:14 +00:00
|
|
|
|
|
|
|
#undef CopyFromBuf
|
|
|
|
#undef CopyToBuf
|