From 720abca8269dfeb725c58d016eb88f2c124170b9 Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Sat, 17 Oct 2020 20:45:07 +0300 Subject: [PATCH] finished save/load --- src/core/Pools.cpp | 7 ++-- src/core/Radar.cpp | 4 +-- src/core/Radar.h | 2 +- src/peds/PlayerPed.cpp | 2 +- src/render/Hud.cpp | 2 +- src/save/GenericGameStorage.cpp | 61 +++++++++++++++++++-------------- src/save/GenericGameStorage.h | 2 -- src/vehicles/CarGen.cpp | 2 +- 8 files changed, 45 insertions(+), 37 deletions(-) diff --git a/src/core/Pools.cpp b/src/core/Pools.cpp index e0c45982..774f406d 100644 --- a/src/core/Pools.cpp +++ b/src/core/Pools.cpp @@ -345,8 +345,9 @@ INITSAVEBUF ++nObjects; } *size = nObjects * (sizeof(int16) + sizeof(int) + sizeof(CCompressedMatrix) + - sizeof(float) + sizeof(CCompressedMatrix) + sizeof(int8) + 7 * sizeof(bool) + sizeof(float) + - sizeof(int8) + sizeof(int8) + sizeof(uint32) + 2 * sizeof(uint32)) + sizeof(int); + 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); CopyToBuf(buf, nObjects); for (int i = 0; i < nPoolSize; i++) { CObject* pObject = GetObjectPool()->GetSlot(i); @@ -370,7 +371,6 @@ INITSAVEBUF tmp.CompressFromFullMatrix(pObject->m_objectMatrix); CopyToBuf(buf, tmp); CopyToBuf(buf, pObject->ObjectCreatedBy); - SkipSaveBuf(buf, 1); CopyToBuf(buf, bIsPickup); CopyToBuf(buf, bPickupObjWithMessage); CopyToBuf(buf, bOutOfStock); @@ -380,6 +380,7 @@ INITSAVEBUF CopyToBuf(buf, bUseVehicleColours); CopyToBuf(buf, pObject->m_unk); CopyToBuf(buf, pObject->m_nBonusValue); + SkipSaveBuf(buf, 1); CopyToBuf(buf, pObject->m_fCollisionDamageMultiplier); CopyToBuf(buf, pObject->m_nCollisionDamageEffect); CopyToBuf(buf, pObject->m_nSpecialCollisionResponseCases); diff --git a/src/core/Radar.cpp b/src/core/Radar.cpp index 78166252..3ddf8337 100644 --- a/src/core/Radar.cpp +++ b/src/core/Radar.cpp @@ -924,6 +924,7 @@ INITSAVEBUF for (int i = 0; i < NUMRADARBLIPS; i++) { ms_RadarTrace[i].m_nColor = ReadSaveBuf(buf); + ms_RadarTrace[i].m_Radius = ReadSaveBuf(buf); ms_RadarTrace[i].m_eBlipType = ReadSaveBuf(buf); ms_RadarTrace[i].m_nEntityHandle = ReadSaveBuf(buf); ms_RadarTrace[i].m_vec2DPos.x = ReadSaveBuf(buf); // CVector2D @@ -934,7 +935,6 @@ INITSAVEBUF ms_RadarTrace[i].m_bInUse = ReadSaveBuf(buf); ms_RadarTrace[i].m_bShortRange = ReadSaveBuf(buf); ms_RadarTrace[i].m_unused = ReadSaveBuf(buf); - ms_RadarTrace[i].m_Radius = ReadSaveBuf(buf); ms_RadarTrace[i].m_wScale = ReadSaveBuf(buf); ms_RadarTrace[i].m_eBlipDisplay = ReadSaveBuf(buf); ms_RadarTrace[i].m_eRadarSprite = ReadSaveBuf(buf); @@ -961,6 +961,7 @@ INITSAVEBUF sRadarTraceSave *saveStruct = (sRadarTraceSave*) buf; saveStruct->m_nColor = ms_RadarTrace[i].m_nColor; + saveStruct->m_Radius = ms_RadarTrace[i].m_Radius; saveStruct->m_eBlipType = ms_RadarTrace[i].m_eBlipType; saveStruct->m_nEntityHandle = ms_RadarTrace[i].m_nEntityHandle; saveStruct->m_vec2DPos = ms_RadarTrace[i].m_vec2DPos; @@ -970,7 +971,6 @@ INITSAVEBUF saveStruct->m_bInUse = ms_RadarTrace[i].m_bInUse; saveStruct->m_bShortRange = ms_RadarTrace[i].m_bShortRange; saveStruct->m_unused = ms_RadarTrace[i].m_unused; - saveStruct->m_Radius = ms_RadarTrace[i].m_Radius; saveStruct->m_wScale = ms_RadarTrace[i].m_wScale; saveStruct->m_eBlipDisplay = ms_RadarTrace[i].m_eBlipDisplay; saveStruct->m_eRadarSprite = ms_RadarTrace[i].m_eRadarSprite; diff --git a/src/core/Radar.h b/src/core/Radar.h index b5f34f1f..8f2e7069 100644 --- a/src/core/Radar.h +++ b/src/core/Radar.h @@ -137,6 +137,7 @@ struct sRadarTrace struct sRadarTraceSave { uint32 m_nColor; + float m_Radius; uint32 m_eBlipType; // eBlipType int32 m_nEntityHandle; CVector2D m_vec2DPos; @@ -146,7 +147,6 @@ struct sRadarTraceSave bool m_bInUse; bool m_bShortRange; bool m_unused; - float m_Radius; int16 m_wScale; uint16 m_eBlipDisplay; // eBlipDisplay uint16 m_eRadarSprite; // eRadarSprite diff --git a/src/peds/PlayerPed.cpp b/src/peds/PlayerPed.cpp index f43ccead..1f53853f 100644 --- a/src/peds/PlayerPed.cpp +++ b/src/peds/PlayerPed.cpp @@ -1935,7 +1935,7 @@ CPlayerPed::Save(uint8*& buf) CopyToBuf(buf, m_nTargettableObjects[1]); CopyToBuf(buf, m_nTargettableObjects[2]); CopyToBuf(buf, m_nTargettableObjects[3]); - SkipSaveBuf(buf, 116); + SkipSaveBuf(buf, 164); } void diff --git a/src/render/Hud.cpp b/src/render/Hud.cpp index 3ea756fa..753bb42b 100644 --- a/src/render/Hud.cpp +++ b/src/render/Hud.cpp @@ -583,7 +583,7 @@ void CHud::Draw() CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(182.0f), SCREEN_SCALE_Y(65.0f), sPrint); - if (!CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastArmourLoss || CTimer::GetTimeInMilliseconds() > CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastArmourLoss + 2000 || CTimer::GetFrameCounter() & 1) { + if (!CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastArmourLoss || CTimer::GetTimeInMilliseconds() > CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastArmourLoss + 2000 || CTimer::GetFrameCounter() & 4) { // CFont::SetColor(ARMOUR_COLOR); CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(182.0f + 52.0f), SCREEN_SCALE_Y(65.0f), sPrintIcon); } diff --git a/src/save/GenericGameStorage.cpp b/src/save/GenericGameStorage.cpp index 7e89afff..966f353a 100644 --- a/src/save/GenericGameStorage.cpp +++ b/src/save/GenericGameStorage.cpp @@ -41,7 +41,9 @@ #include "Timecycle.h" #include "Fluff.h" -#define BLOCK_COUNT 20 +// --MIAMI: file done + +#define BLOCK_COUNT 22 #define SIZE_OF_SIMPLEVARS 0xE4 const uint32 SIZE_OF_ONE_GAME_IN_BYTES = 201729; @@ -60,7 +62,6 @@ int CheckSum; eLevelName m_LevelToLoad; char SaveFileNameJustSaved[260]; int Slots[SLOT_COUNT]; -CDate CompileDateAndTime; bool b_FoundRecentSavedGameWantToLoad; bool JustLoadedDontFadeInYet; @@ -112,13 +113,14 @@ do {\ buf += size;\ } while (0) -#define WriteSaveDataBlock(save_func)\ +#define WriteSaveDataBlock(save_func, msg)\ do {\ size = 0;\ buf = work_buff;\ reserved = 0;\ MakeSpaceForSizeInBufferPointer(presize, buf, postsize);\ save_func(buf, &size);\ + debug(msg"== %i \n", size);\ CopySizeAndPreparePointer(presize, buf, postsize, reserved, size);\ if (!PcSaveHelper.PcClassSaveRoutine(file, work_buff, buf - work_buff))\ return false;\ @@ -145,9 +147,10 @@ GenericSave(int file) reserved = 0; // Save simple vars - lastMissionPassed = TheText.Get(CStats::LastMissionPassedName); + lastMissionPassed = TheText.Get(CStats::LastMissionPassedName[0] ? CStats::LastMissionPassedName : "ITBEG"); if (lastMissionPassed[0] != '\0') { AsciiToUnicode("...'", suffix); + suffix[3] = L'\0'; #ifdef FIX_BUGS // fix buffer overflow int len = UnicodeStrlen(lastMissionPassed); @@ -221,6 +224,7 @@ GenericSave(int file) buf += 4; postsize = buf; CTheScripts::SaveAllScripts(buf, &size); + debug("ScriptSize== %i \n", size); CopySizeAndPreparePointer(presize, buf, postsize, reserved, size); if (!PcSaveHelper.PcClassSaveRoutine(file, work_buff, buf - work_buff)) return false; @@ -228,28 +232,28 @@ GenericSave(int file) totalSize = buf - work_buff; // Save the rest - WriteSaveDataBlock(CPools::SavePedPool); - WriteSaveDataBlock(CGarages::Save); - WriteSaveDataBlock(CGameLogic::Save); - WriteSaveDataBlock(CPools::SaveVehiclePool); - WriteSaveDataBlock(CPools::SaveObjectPool); - WriteSaveDataBlock(ThePaths.Save); - WriteSaveDataBlock(CCranes::Save); - WriteSaveDataBlock(CPickups::Save); - WriteSaveDataBlock(gPhoneInfo.Save); - WriteSaveDataBlock(CRestart::SaveAllRestartPoints); - WriteSaveDataBlock(CRadar::SaveAllRadarBlips); - WriteSaveDataBlock(CTheZones::SaveAllZones); - WriteSaveDataBlock(CGangs::SaveAllGangData); - WriteSaveDataBlock(CTheCarGenerators::SaveAllCarGenerators); - WriteSaveDataBlock(CParticleObject::SaveParticle); - WriteSaveDataBlock(cAudioScriptObject::SaveAllAudioScriptObjects); - WriteSaveDataBlock(CScriptPaths::Save); - WriteSaveDataBlock(CWorld::Players[CWorld::PlayerInFocus].SavePlayerInfo); - WriteSaveDataBlock(CStats::SaveStats); - WriteSaveDataBlock(CSetPieces::Save); - WriteSaveDataBlock(CStreaming::MemoryCardSave); - WriteSaveDataBlock(CPedType::Save); + WriteSaveDataBlock(CPools::SavePedPool, "PedPoolSize"); + WriteSaveDataBlock(CGarages::Save, "GaragesSize"); + WriteSaveDataBlock(CGameLogic::Save, "GameLogicSize"); + WriteSaveDataBlock(CPools::SaveVehiclePool, "VehPoolSize"); + WriteSaveDataBlock(CPools::SaveObjectPool, "ObjectPoolSize"); + WriteSaveDataBlock(ThePaths.Save, "ThePathsSize"); + WriteSaveDataBlock(CCranes::Save, "CranesSize"); + WriteSaveDataBlock(CPickups::Save, "PickUpsSize"); + WriteSaveDataBlock(gPhoneInfo.Save, "PhoneInfoSize"); + WriteSaveDataBlock(CRestart::SaveAllRestartPoints, "RestartPointsBufferSize"); + WriteSaveDataBlock(CRadar::SaveAllRadarBlips, "RadarBlipsBufferSize"); + WriteSaveDataBlock(CTheZones::SaveAllZones, "AllZonesBufferSize"); + WriteSaveDataBlock(CGangs::SaveAllGangData, "AllGangDataSize"); + WriteSaveDataBlock(CTheCarGenerators::SaveAllCarGenerators, "AllCarGeneratorsSize"); + WriteSaveDataBlock(CParticleObject::SaveParticle, "ParticlesSize"); + WriteSaveDataBlock(cAudioScriptObject::SaveAllAudioScriptObjects, "AllAudioScriptObjectsSize"); + WriteSaveDataBlock(CScriptPaths::Save, "ScriptPathsSize"); + WriteSaveDataBlock(CWorld::Players[CWorld::PlayerInFocus].SavePlayerInfo, "PlayerInfoSize"); + WriteSaveDataBlock(CStats::SaveStats, "StatsSize"); + WriteSaveDataBlock(CSetPieces::Save, "SetPiecesSize"); + WriteSaveDataBlock(CStreaming::MemoryCardSave, "StreamingSize"); + WriteSaveDataBlock(CPedType::Save, "PedTypeSize"); // Write padding for (int i = 0; i < 4; i++) { @@ -458,8 +462,13 @@ CloseFile(int32 file) void DoGameSpecificStuffAfterSucessLoad() { + CCollision::SortOutCollisionAfterLoad(); + CStreaming::LoadSceneCollision(TheCamera.GetPosition()); + CStreaming::LoadScene(TheCamera.GetPosition()); + CGame::TidyUpMemory(true, false); StillToFadeOut = true; JustLoadedDontFadeInYet = true; + TheCamera.Fade(0.0f, 0); CTheScripts::Process(); } diff --git a/src/save/GenericGameStorage.h b/src/save/GenericGameStorage.h index 236e34f5..07aa23ca 100644 --- a/src/save/GenericGameStorage.h +++ b/src/save/GenericGameStorage.h @@ -25,8 +25,6 @@ bool CheckDataNotCorrupt(int32 slot, char *name); bool RestoreForStartLoad(); int align4bytes(int32 size); -extern class CDate CompileDateAndTime; - extern char DefaultPCSaveFileName[260]; extern char ValidSaveName[260]; extern char LoadFileName[256]; diff --git a/src/vehicles/CarGen.cpp b/src/vehicles/CarGen.cpp index 598b8342..77d66cbf 100644 --- a/src/vehicles/CarGen.cpp +++ b/src/vehicles/CarGen.cpp @@ -91,7 +91,7 @@ void CCarGenerator::DoInternalProcessing() pVehicle = pBoat; if (pos.z <= -100.0f) pos.z = CWorld::FindGroundZForCoord(pos.x, pos.y); - pBoat->bExtendedRange = false; + pBoat->bExtendedRange = true; }else{ bool groundFound; pos = m_vecPos;