diff options
author | Nikolay Korolev <nickvnuk@gmail.com> | 2020-05-02 17:02:17 +0200 |
---|---|---|
committer | Nikolay Korolev <nickvnuk@gmail.com> | 2020-05-02 17:02:17 +0200 |
commit | f372ce156d76350ef4705ecbf488b43484878ca2 (patch) | |
tree | edf87ceceb886b0f8fa9e57a6b357d0f2d670aed /src/core/Pools.cpp | |
parent | Merge remote-tracking branch 'upstream/master' (diff) | |
download | re3-f372ce156d76350ef4705ecbf488b43484878ca2.tar re3-f372ce156d76350ef4705ecbf488b43484878ca2.tar.gz re3-f372ce156d76350ef4705ecbf488b43484878ca2.tar.bz2 re3-f372ce156d76350ef4705ecbf488b43484878ca2.tar.lz re3-f372ce156d76350ef4705ecbf488b43484878ca2.tar.xz re3-f372ce156d76350ef4705ecbf488b43484878ca2.tar.zst re3-f372ce156d76350ef4705ecbf488b43484878ca2.zip |
Diffstat (limited to 'src/core/Pools.cpp')
-rw-r--r-- | src/core/Pools.cpp | 134 |
1 files changed, 59 insertions, 75 deletions
diff --git a/src/core/Pools.cpp b/src/core/Pools.cpp index 011c7af7..4306cf09 100644 --- a/src/core/Pools.cpp +++ b/src/core/Pools.cpp @@ -111,30 +111,27 @@ INITSAVEBUF int32 slot = ReadSaveBuf<int32>(buf); CVehicle* pVehicle; #ifdef COMPATIBLE_SAVES - char* vbuf = new char[Max(sizeof(CAutomobile_FS), sizeof(CBoat_FS))]; + 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); + else + assert(0); + --CCarCtrl::NumRandomCars; + pVehicle->Load(buf); + CWorld::Add(pVehicle); #else - char* vbuf = new char[Max(sizeof(CAutomobile), sizeof(CBoat))]; -#endif + char* vbuf = new char[Max(CAutomobile::nSaveStructSize, CBoat::nSaveStructSize)]; if (type == VEHICLE_TYPE_BOAT) { -#ifdef COMPATIBLE_SAVES - memcpy(vbuf, buf, sizeof(CBoat_FS)); - SkipSaveBuf(buf, sizeof(CBoat_FS)); -#else memcpy(vbuf, buf, sizeof(CBoat)); SkipSaveBuf(buf, sizeof(CBoat)); -#endif CBoat* pBoat = new(slot) CBoat(model, RANDOM_VEHICLE); pVehicle = pBoat; - --CCarCtrl::NumRandomCars; // why? + --CCarCtrl::NumRandomCars; } else if (type == VEHICLE_TYPE_CAR) { -#ifdef COMPATIBLE_SAVES - memcpy(vbuf, buf, sizeof(CAutomobile_FS)); - SkipSaveBuf(buf, sizeof(CAutomobile_FS)); -#else memcpy(vbuf, buf, sizeof(CAutomobile)); SkipSaveBuf(buf, sizeof(CAutomobile)); -#endif CStreaming::RequestModel(model, 0); // is it needed? CStreaming::LoadAllRequestedModels(false); CAutomobile* pAutomobile = new(slot) CAutomobile(model, RANDOM_VEHICLE); @@ -145,10 +142,6 @@ INITSAVEBUF } else assert(0); -#ifdef COMPATIBLE_SAVES - CVehicle_FS* pBufferVehicle = (CVehicle_FS*)vbuf; - pBufferVehicle->Restore(pVehicle); -#else CVehicle* pBufferVehicle = (CVehicle*)vbuf; pVehicle->GetMatrix() = pBufferVehicle->GetMatrix(); pVehicle->VehicleCreatedBy = pBufferVehicle->VehicleCreatedBy; @@ -184,9 +177,9 @@ INITSAVEBUF (pVehicle->GetAddressOfEntityProperties())[0] = (pBufferVehicle->GetAddressOfEntityProperties())[0]; (pVehicle->GetAddressOfEntityProperties())[1] = (pBufferVehicle->GetAddressOfEntityProperties())[1]; pVehicle->AutoPilot = pBufferVehicle->AutoPilot; -#endif CWorld::Add(pVehicle); delete[] vbuf; +#endif } VALIDATESAVEBUF(size) } @@ -213,20 +206,8 @@ INITSAVEBUF ++nNumBoats; } } - *size = nNumCars * (sizeof(uint32) + sizeof(int16) + sizeof(int32) + -#ifdef COMPATIBLE_SAVES - sizeof(CAutomobile_FS)) + -#else - sizeof(CAutomobile)) + -#endif - sizeof(int) + - nNumBoats * (sizeof(uint32) + sizeof(int16) + sizeof(int32) + -#ifdef COMPATIBLE_SAVES - sizeof(CBoat_FS)) + -#else - sizeof(CBoat)) + -#endif - sizeof(int); + *size = nNumCars * (sizeof(uint32) + sizeof(int16) + sizeof(int32) + CAutomobile::nSaveStructSize) + sizeof(int) + + nNumBoats * (sizeof(uint32) + sizeof(int16) + sizeof(int32) + CBoat::nSaveStructSize) + sizeof(int); WriteSaveBuf(buf, nNumCars); WriteSaveBuf(buf, nNumBoats); for (int i = 0; i < nPoolSize; i++) { @@ -239,19 +220,20 @@ INITSAVEBUF bHasPassenger = true; } if (!pVehicle->pDriver && !bHasPassenger) { +#ifdef COMPATIBLE_SAVES + if ((pVehicle->IsCar() || pVehicle->IsBoat()) && pVehicle->VehicleCreatedBy == MISSION_VEHICLE) { + WriteSaveBuf<uint32>(buf, pVehicle->m_vehType); + WriteSaveBuf<int16>(buf, pVehicle->m_modelIndex); + WriteSaveBuf<int32>(buf, GetVehicleRef(pVehicle)); + pVehicle->Save(buf); + } +#else if (pVehicle->IsCar() && pVehicle->VehicleCreatedBy == MISSION_VEHICLE) { WriteSaveBuf(buf, (uint32)pVehicle->m_vehType); WriteSaveBuf(buf, pVehicle->m_modelIndex); WriteSaveBuf(buf, GetVehicleRef(pVehicle)); -#ifdef COMPATIBLE_SAVES - ((CVehicle_FS*)buf)->Store(pVehicle); - SkipSaveBuf(buf, sizeof(CVehicle_FS)); - WriteSaveBuf(buf, ((CAutomobile*)pVehicle)->Damage); - SkipSaveBuf(buf, sizeof(CAutomobile_FS) - sizeof(CVehicle_FS) - sizeof(CDamageManager)); -#else memcpy(buf, pVehicle, sizeof(CAutomobile)); SkipSaveBuf(buf, sizeof(CAutomobile)); -#endif } if (pVehicle->IsBoat() && pVehicle->VehicleCreatedBy == MISSION_VEHICLE) { WriteSaveBuf(buf, (uint32)pVehicle->m_vehType); @@ -260,6 +242,7 @@ INITSAVEBUF memcpy(buf, pVehicle, sizeof(CBoat)); SkipSaveBuf(buf, sizeof(CBoat)); } +#endif } } VALIDATESAVEBUF(*size) @@ -318,9 +301,7 @@ INITSAVEBUF WriteSaveBuf(buf, pObject->m_nSpecialCollisionResponseCases); WriteSaveBuf(buf, pObject->m_nEndOfLifeTime); #ifdef COMPATIBLE_SAVES - CEntityProperties properties; - properties.Store(pObject); - WriteSaveBuf(buf, properties); + pObject->SaveEntityFlags(buf); #else WriteSaveBuf(buf, (pObject->GetAddressOfEntityProperties())[0]); WriteSaveBuf(buf, (pObject->GetAddressOfEntityProperties())[1]); @@ -359,9 +340,7 @@ INITSAVEBUF pBufferObject->m_nCollisionDamageEffect = ReadSaveBuf<uint8>(buf); pBufferObject->m_nSpecialCollisionResponseCases = ReadSaveBuf<uint8>(buf); pBufferObject->m_nEndOfLifeTime = ReadSaveBuf<uint32>(buf); -#ifdef COMPATIBLE_SAVES - CEntityProperties properties = ReadSaveBuf<CEntityProperties>(buf); -#else +#ifndef COMPATIBLE_SAVES (pBufferObject->GetAddressOfEntityProperties())[0] = ReadSaveBuf<uint32>(buf); (pBufferObject->GetAddressOfEntityProperties())[1] = ReadSaveBuf<uint32>(buf); #endif @@ -369,6 +348,9 @@ INITSAVEBUF CPopulation::ConvertToDummyObject(GetObjectPool()->GetSlot(ref >> 8)); CObject* pObject = new(ref) CObject(mi, false); pObject->GetMatrix() = pBufferObject->GetMatrix(); +#ifdef COMPATIBLE_SAVES + pObject->LoadEntityFlags(buf); +#endif pObject->m_fUprootLimit = pBufferObject->m_fUprootLimit; pObject->m_objectMatrix = pBufferObject->m_objectMatrix; pObject->ObjectCreatedBy = pBufferObject->ObjectCreatedBy; @@ -383,9 +365,7 @@ INITSAVEBUF pObject->m_nCollisionDamageEffect = pBufferObject->m_nCollisionDamageEffect; pObject->m_nSpecialCollisionResponseCases = pBufferObject->m_nSpecialCollisionResponseCases; pObject->m_nEndOfLifeTime = pBufferObject->m_nEndOfLifeTime; -#ifdef COMPATIBLE_SAVES - properties.Restore(pObject); -#else +#ifndef COMPATIBLE_SAVES (pObject->GetAddressOfEntityProperties())[0] = (pBufferObject->GetAddressOfEntityProperties())[0]; (pObject->GetAddressOfEntityProperties())[1] = (pBufferObject->GetAddressOfEntityProperties())[1]; #endif @@ -408,12 +388,7 @@ INITSAVEBUF if (!pPed->bInVehicle && pPed->m_nPedType == PEDTYPE_PLAYER1) nNumPeds++; } - *size = sizeof(int) + nNumPeds * (sizeof(uint32) + sizeof(int16) + sizeof(int) + -#ifdef COMPATIBLE_SAVES - sizeof(CPlayerPed_FS) + -#else - sizeof(CPlayerPed) + -#endif + *size = sizeof(int) + nNumPeds * (sizeof(uint32) + sizeof(int16) + sizeof(int) + CPlayerPed::nSaveStructSize + sizeof(CWanted::MaximumWantedLevel) + sizeof(CWanted::nMaximumWantedLevel) + MAX_MODEL_NAME); WriteSaveBuf(buf, nNumPeds); for (int i = 0; i < nPoolSize; i++) { @@ -425,9 +400,7 @@ INITSAVEBUF WriteSaveBuf(buf, pPed->m_modelIndex); WriteSaveBuf(buf, GetPedRef(pPed)); #ifdef COMPATIBLE_SAVES - ((CPlayerPed_FS*)buf)->StorePlayerPed((CPlayerPed*)pPed); - ((CPlayerPed_FS*)buf)->StorePed(pPed); - SkipSaveBuf(buf, sizeof(CPlayerPed_FS)); + pPed->Save(buf); #else memcpy(buf, pPed, sizeof(CPlayerPed)); SkipSaveBuf(buf, sizeof(CPlayerPed)); @@ -450,23 +423,41 @@ INITSAVEBUF int16 model = ReadSaveBuf<int16>(buf); int ref = ReadSaveBuf<int>(buf); #ifdef COMPATIBLE_SAVES - char* pbuf = new char[sizeof(CPlayerPed_FS)]; - CPlayerPed_FS* pBufferPlayer = (CPlayerPed_FS*)buf; + 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) { + CWanted::MaximumWantedLevel = ReadSaveBuf<int32>(buf); + CWanted::nMaximumWantedLevel = ReadSaveBuf<int32>(buf); + SkipSaveBuf(buf, MAX_MODEL_NAME); + } + + if (pedtype == PEDTYPE_PLAYER1) { + pPed->m_wepAccuracy = 100; + CWorld::Players[0].m_pPed = (CPlayerPed*)pPed; + } + CWorld::Add(pPed); #else char* pbuf = new char[sizeof(CPlayerPed)]; CPlayerPed* pBufferPlayer = (CPlayerPed*)pbuf; -#endif 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 -#ifdef COMPATIBLE_SAVES - memcpy(pbuf, buf, sizeof(CPlayerPed_FS)); - SkipSaveBuf(buf, sizeof(CPlayerPed_FS)); -#else memcpy(pbuf, buf, sizeof(CPlayerPed)); SkipSaveBuf(buf, sizeof(CPlayerPed)); -#endif CWanted::MaximumWantedLevel = ReadSaveBuf<int32>(buf); CWanted::nMaximumWantedLevel = ReadSaveBuf<int32>(buf); memcpy(name, buf, MAX_MODEL_NAME); @@ -476,19 +467,11 @@ INITSAVEBUF CStreaming::LoadAllRequestedModels(false); if (pedtype == PEDTYPE_PLAYER1) { CPlayerPed* pPlayerPed = new(ref) CPlayerPed(); -#ifdef COMPATIBLE_SAVES - pBufferPlayer->RestorePlayerPed(pPlayerPed); -#else 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; -#endif pPed = pPlayerPed; } -#ifdef COMPATIBLE_SAVES - pBufferPlayer->RestorePed(pPed); - pPed->m_currentWeapon = 0; -#else pPed->GetPosition() = pBufferPlayer->GetPosition(); pPed->m_fHealth = pBufferPlayer->m_fHealth; pPed->m_fArmour = pBufferPlayer->m_fArmour; @@ -497,13 +480,14 @@ INITSAVEBUF pPed->m_maxWeaponTypeAllowed = pBufferPlayer->m_maxWeaponTypeAllowed; for (int i = 0; i < WEAPONTYPE_TOTAL_INVENTORY_WEAPONS; i++) pPed->m_weapons[i] = pBufferPlayer->m_weapons[i]; -#endif + if (pedtype == PEDTYPE_PLAYER1) { pPed->m_wepAccuracy = 100; CWorld::Players[0].m_pPed = (CPlayerPed*)pPed; } CWorld::Add(pPed); delete[] pbuf; +#endif } VALIDATESAVEBUF(size) } |