comparison Engine/SaveLoad.cpp @ 2499:68cdef6879a0

engine folder
author Ritor1
date Fri, 19 Sep 2014 02:57:42 +0600
parents
children a77c34acdbc9
comparison
equal deleted inserted replaced
2498:92eeeb5200f2 2499:68cdef6879a0
1 #define _CRTDBG_MAP_ALLOC
2 #include <stdlib.h>
3 #include <crtdbg.h>
4
5 #define _CRT_SECURE_NO_WARNINGS
6 #include <io.h>
7 #include <direct.h>
8
9 #include "Engine/ErrorHandling.h"
10 #include "ZlibWrapper.h"
11
12 #include "SaveLoad.h"
13 #include "Party.h"
14 #include "LOD.h"
15 #include "Engine/Graphics/Outdoor.h"
16 #include "AudioPlayer.h"
17 #include "Engine/Objects/Actor.h"
18 #include "Engine/Objects/Chest.h"
19 #include "Timer.h"
20 #include "GUIWindow.h"
21 #include "GUIFont.h"
22 #include "Engine/Graphics/Overlays.h"
23 #include "Engine/Objects/SpriteObject.h"
24 #include "Engine/Graphics/Viewport.h"
25 #include "stru123.h"
26 #include "texts.h"
27 #include "Log.h"
28 #include "Engine/Graphics/Level/Decoration.h"
29
30 #include "Game.h"
31
32
33
34 struct SavegameList *pSavegameList = new SavegameList;
35 unsigned int uNumSavegameFiles;
36 std::array<unsigned int, 45> pSavegameUsedSlots;
37 std::array<struct RGBTexture, 45> pSavegameThumbnails;
38 std::array<SavegameHeader, 45> pSavegameHeader;
39
40 //----- (0045EE8A) --------------------------------------------------------
41 void __fastcall LoadGame(unsigned int uSlot)
42 {
43 bool v25; // esi@62
44 bool v26; // eax@62
45 SavegameHeader header; // [sp+Ch] [bp-E4h]@23
46 char Str[123]; // [sp+70h] [bp-80h]@25
47
48 MapsLongTimers_count = 0;
49 if (!pSavegameUsedSlots[uSlot])
50 {
51 pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
52 Log::Warning(L"LoadGame: slot %u is empty", uSlot);
53 return;
54 }
55
56 for (uint i = 1; i < 5; ++i)
57 for (uint j = 1; j < 6; ++j)
58 {
59 sprintf(pTmpBuf.data(), "data\\lloyd%d%d.pcx", i, j);
60 remove(pTmpBuf.data());
61 }
62
63 if (SoundSetAction[24][0])
64 for (uint i = 0; i < 4; ++i)
65 {
66 for (uint j = 0; j < pSoundList->sNumSounds; ++j)
67 if (pSoundList->pSL_Sounds[j].uSoundID == 2 * (SoundSetAction[24][0] + 50 * pParty->pPlayers[i].uVoiceID) + 4998)
68 {
69 pSoundList->UnloadSound(j, 1);
70 break;
71 }
72
73 for (uint j = 0; j < pSoundList->sNumSounds; ++j)
74 if (pSoundList->pSL_Sounds[j].uSoundID == 2 * (SoundSetAction[24][0] + 50 * pParty->pPlayers[i].uVoiceID) + 4999)
75 {
76 pSoundList->UnloadSound(j, 1);
77 break;
78 }
79 }
80
81 sprintf(pTmpBuf.data(), "saves\\%s", pSavegameList->pFileList[uSlot].pSaveFileName);
82
83 pNew_LOD->CloseWriteFile();
84 if (!CopyFileA(pTmpBuf.data(), "data\\new.lod", 0))
85 int e = GetLastError();
86
87 pNew_LOD->LoadFile("data\\new.lod", 0);
88 FILE *file = pNew_LOD->FindContainer("header.bin", 1);
89 if (!file)
90 {
91 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 100);//Сохраненная игра повреждена! Code=%d
92 Log::Warning(L"%S", Str);
93 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:549", 0);
94 }
95 Assert(sizeof(SavegameHeader) == 100);
96 fread(&header, sizeof(SavegameHeader), 1, file);
97
98 file = pNew_LOD->FindContainer("party.bin", 1);
99 if (!file)
100 {
101 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 101);//Сохраненная игра повреждена! Code=%d
102 Log::Warning(L"%S", Str);
103 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:559", 0);
104 }
105 if (sizeof(Party) != 0x16238)
106 Log::Warning(L"class Party: deserialization warning");
107 fread(pParty, sizeof(Party), 1, file);
108
109
110 file = pNew_LOD->FindContainer("clock.bin", 1);
111 if (!file)
112 {
113 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 102);//Сохраненная игра повреждена! Code=%d
114 Log::Warning(L"%S", Str);
115 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:569", 0);
116 }
117 if (sizeof(Timer) != 0x28)
118 Log::Warning(L"class Timer: deserialization warning");
119 fread(pEventTimer, sizeof(Timer), 1, file);
120
121 file = pNew_LOD->FindContainer("overlay.bin", 1);
122 if (!file)
123 {
124 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 103);//Сохраненная игра повреждена! Code=%d
125 Log::Warning(L"%S", Str);
126 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:579", 0);
127 }
128 if (sizeof(OtherOverlayList) != 0x3F0)
129 Log::Warning(L"class OtherOverlayList: deserialization warning");
130 fread(pOtherOverlayList, sizeof(OtherOverlayList), 1, file);
131
132 file = pNew_LOD->FindContainer("npcdata.bin", 0);
133 if (!file)
134 {
135 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 104);//Сохраненная игра повреждена! Code=%d
136 Log::Warning(L"%S", Str);
137 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:590", 0);
138 }
139 if (sizeof(pNPCStats->pNewNPCData) != 0x94BC)
140 Log::Warning(L"NPCStats: deserialization warning");
141 fread(pNPCStats->pNewNPCData, sizeof(pNPCStats->pNewNPCData), 1, file);
142 pNPCStats->_476C60();
143
144 file = pNew_LOD->FindContainer("npcgroup.bin", 0);
145 if (!file)
146 {
147 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 105);//Сохраненная игра повреждена! Code=%d
148 Log::Warning(L"%S", Str);
149 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:600", 0);
150 }
151 if (sizeof(pNPCStats->pGroups_copy) != 0x66)
152 Log::Warning(L"NPCStats: deserialization warning");
153 fread(pNPCStats->pGroups_copy, sizeof(pNPCStats->pGroups_copy), 1, file);
154
155 uActiveCharacter = 0;
156 for (uint i = 0; i < 4; ++i)
157 if (pParty->pPlayers[i].CanAct())
158 {
159 uActiveCharacter = i + 1;
160 break;
161 }
162
163 for (uint i = 0; i < 4; ++i)
164 {
165 if ( pParty->pPlayers[i].uQuickSpell )
166 AA1058_PartyQuickSpellSound[i].AddPartySpellSound(pParty->pPlayers[i].uQuickSpell, i + 1);
167
168 for (uint j = 0; j < 2; ++j)
169 {
170 uint uEquipIdx = pParty->pPlayers[i].pEquipment.pIndices[j];
171 if (uEquipIdx)
172 {
173 int pItemID = pParty->pPlayers[i].pInventoryItemList[uEquipIdx - 1].uItemID;
174 if (pItemsTable->pItems[pItemID].uEquipType == EQUIP_WAND && pItemID )//жезл
175 {
176 __debugbreak(); // looks like offset in player's inventory and wand_lut much like case in 0042ECB5
177 stru_A750F8[i].AddPartySpellSound(wand_spell_ids[pItemID - ITEM_WAND_FIRE], i + 9);
178 }
179 }
180 }
181 }
182
183 pGUIWindow_CurrentMenu->Release();
184 pCurrentScreen = SCREEN_GAME;
185
186 viewparams->bRedrawGameUI = true;
187
188 SetUserInterface(pParty->alignment, true);
189
190 pEventTimer->Resume();
191 pEventTimer->StopGameTime();
192
193 v25 = pGames_LOD->DoesContainerExist(header.pLocationName);
194 sprintf(pTmpBuf.data(), "levels\\%s", header.pLocationName);
195 v26 = _access(pTmpBuf.data(), 4) != -1;
196 if ( !v25 && !v26 )
197 Error("Unable to find: %s!", header.pLocationName);
198
199 strcpy(pCurrentMapName, header.pLocationName);
200 dword_6BE364_game_settings_1 |= GAME_SETTINGS_2000 | GAME_SETTINGS_0001;
201
202 for (uint i = 0; i < uNumSavegameFiles; ++i)
203 pSavegameThumbnails[i].Release();
204
205 pIcons_LOD->RemoveTexturesPackFromTextureList();
206 pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
207 pAudioPlayer->SetMasterVolume(pSoundVolumeLevels[uSoundVolumeMultiplier] * 128.0f);
208 if (uTurnSpeed)
209 pParty->sRotationY = uTurnSpeed * pParty->sRotationY / (signed int)uTurnSpeed;
210 MM7Initialization();
211 bFlashQuestBook = false;
212 viewparams->bRedrawGameUI = true;
213 }
214
215 //----- (0045F469) --------------------------------------------------------
216 void SaveGame( bool IsAutoSAve, bool NotSaveWorld )
217 {
218 int text_pos; // eax@6
219 FILE *pLLoidFile; // edi@24
220 char* compressed_buf; // edi@30
221 char *data_write_pos; // esi@41
222 CHAR Buffer[128]; // [sp+Ch] [bp-264h]@59
223 char Dir[255]; // [sp+8Ch] [bp-1E4h]@51
224 char Drive[255]; // [sp+ACh] [bp-1C4h]@51
225 SavegameHeader save_header; // [sp+CCh] [bp-1A4h]@10
226 char Filename[255]; // [sp+130h] [bp-140h]@51
227 char Ext[255]; // [sp+150h] [bp-120h]@51
228 char Source[32]; // [sp+170h] [bp-100h]@51
229 char work_string[120]; // [sp+190h] [bp-E0h]@8
230 int pPositionY; // [sp+208h] [bp-68h]@2
231 int pPositionX; // [sp+20Ch] [bp-64h]@2
232 int sPRotationY; // [sp+210h] [bp-60h]@2
233 int sPRotationX; // [sp+214h] [bp-5Ch]@2
234 ODMHeader odm_data; // [sp+218h] [bp-58h]@30
235 int res; // [sp+224h] [bp-4Ch]@30
236 int pPositionZ; // [sp+228h] [bp-48h]@2
237 size_t Size; // [sp+250h] [bp-20h]@26
238 char *uncompressed_buff; // [sp+258h] [bp-18h]@2
239 unsigned int compressed_block_size; // [sp+260h] [bp-10h]@23
240
241 //v66 = a2;
242 strcpy(byte_6BE3B0.data(), pCurrentMapName);//byte_6BE3B0 - save_map_name
243 if (!_stricmp(pCurrentMapName, "d05.blv")) // arena
244 return;
245
246 uncompressed_buff = (char*)malloc(1000000);
247
248 LOD::Directory pLodDirectory; // [sp+22Ch] [bp-44h]@2
249 pPositionX = pParty->vPosition.x;
250 pPositionY = pParty->vPosition.y;
251 pPositionZ = pParty->vPosition.z;
252 sPRotationY = pParty->sRotationY;
253 sPRotationX = pParty->sRotationX;
254 pParty->vPosition.x = pParty->vPrevPosition.x;
255 pParty->vPosition.z = pParty->vPrevPosition.z;
256 pParty->vPosition.y = pParty->vPrevPosition.y;
257
258 pParty->uFallStartY = pParty->vPrevPosition.z;
259
260 pParty->sRotationY = pParty->sPrevRotationY;
261 pParty->sRotationX = pParty->sPrevRotationX;
262 if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
263 pIndoor->stru1.uLastVisitDay = pParty->uTimePlayed;
264 else
265 pOutdoor->loc_time.uLastVisitDay = pParty->uTimePlayed;
266
267 pRenderer->PackScreenshot(150, 112, uncompressed_buff, 1000000, &pLodDirectory.uDataSize);//создание скриншота
268 strcpy(pLodDirectory.pFilename, "image.pcx");
269
270 if (pCurrentScreen == SCREEN_SAVEGAME)
271 {
272 pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->GetTexture(uTextureID_loadsave));
273 pRenderer->DrawTextureIndexed(18, 141, pIcons_LOD->GetTexture(uTextureID_save_up));
274 text_pos = pFontSmallnum->AlignText_Center(186, pGlobalTXT_LocalizationStrings[190]);
275 pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, text_pos + 25, 219, 0, pGlobalTXT_LocalizationStrings[190], 0, 0, 0); //Сохранение
276 text_pos = pFontSmallnum->AlignText_Center(186, pSavegameHeader[uLoadGameUI_SelectedSlot].pName);
277 pGUIWindow_CurrentMenu->DrawTextInRect(pFontSmallnum, text_pos + 25, 259, 0, pSavegameHeader[uLoadGameUI_SelectedSlot].pName, 185, 0);
278 text_pos = pFontSmallnum->AlignText_Center(186, pGlobalTXT_LocalizationStrings[165]);
279 pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, text_pos + 25, 299, 0, pGlobalTXT_LocalizationStrings[165], 0, 0, 0); //Пожалуйста, подождите
280 pRenderer->Present();
281 }
282
283 if (pNew_LOD->Write(&pLodDirectory, uncompressed_buff, 0))
284 {
285 sprintf(work_string, pGlobalTXT_LocalizationStrings[612], 200); //Сохраненная игра повреждена! Code=%d
286 MessageBoxA(nullptr, work_string, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:773", 0);
287 }
288
289 Assert(sizeof(SavegameHeader) == 100);
290 memset(save_header.pName, 0, 20);
291 memset(save_header.pLocationName, 0, 20);
292 memset(save_header.field_30, 0, 52);
293 strcpy(save_header.pLocationName, pCurrentMapName);
294 save_header.uWordTime = pParty->uTimePlayed;
295 strcpy(pLodDirectory.pFilename, "header.bin");
296 pLodDirectory.uDataSize = sizeof(SavegameHeader);
297 if (pNew_LOD->Write(&pLodDirectory, &save_header, 0))
298 {
299 sprintf(work_string, pGlobalTXT_LocalizationStrings[612], 201);
300 MessageBoxA(nullptr, work_string, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:784", 0);
301 }
302 strcpy(pLodDirectory.pFilename, "party.bin");
303 pLodDirectory.uDataSize = sizeof(Party); //90680;
304 if ( pNew_LOD->Write(&pLodDirectory, pParty, 0) )
305 {
306 sprintf(work_string, pGlobalTXT_LocalizationStrings[612], 202);//Save game corrupted! Code=%d
307 MessageBoxA(nullptr, work_string, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:793", 0);
308 }
309 strcpy(pLodDirectory.pFilename, "clock.bin");
310 pLodDirectory.uDataSize =sizeof(Timer);// 40;
311 if ( pNew_LOD->Write(&pLodDirectory, pEventTimer, 0) )
312 {
313 sprintf(work_string, pGlobalTXT_LocalizationStrings[612], 203);
314 MessageBoxA(nullptr, work_string, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:802", 0);
315 }
316 strcpy(pLodDirectory.pFilename, "overlay.bin");
317 pLodDirectory.uDataSize =sizeof(OtherOverlayList);// 1008;
318 if ( pNew_LOD->Write(&pLodDirectory, pOtherOverlayList, 0) )
319 {
320 sprintf(work_string, pGlobalTXT_LocalizationStrings[612], 204);
321 MessageBoxA(nullptr, work_string, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:811", 0);
322 }
323 strcpy(pLodDirectory.pFilename, "npcdata.bin");
324 pLodDirectory.uDataSize = 501 * sizeof(NPCData);
325 Assert(pLodDirectory.uDataSize == 38076);
326 if ( pNew_LOD->Write(&pLodDirectory, pNPCStats->pNewNPCData, 0) )
327 {
328 sprintf(work_string, pGlobalTXT_LocalizationStrings[612], 205);
329 MessageBoxA(nullptr, work_string, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:820", 0);
330 }
331 strcpy(pLodDirectory.pFilename, "npcgroup.bin");
332 pLodDirectory.uDataSize = 102;
333 if ( pNew_LOD->Write(&pLodDirectory, pNPCStats->pGroups_copy, 0) )
334 {
335 sprintf(work_string, pGlobalTXT_LocalizationStrings[612], 206);
336 MessageBoxA(nullptr, work_string, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:829", 0);
337 }
338 for (int i = 1; i <= 4; ++i) // 4 - players
339 {
340 for (int j = 1; j <= 5; ++j) // 5 - images
341 {
342 sprintf(work_string, "data\\lloyd%d%d.pcx", i, j);
343 pLLoidFile = fopen(work_string, "rb");
344 if ( pLLoidFile )
345 {
346 __debugbreak();
347 sprintf(work_string, "lloyd%d%d.pcx", i, j);
348 fseek(pLLoidFile, 0, SEEK_END);
349 pLodDirectory.uDataSize = ftell(pLLoidFile);
350 rewind(pLLoidFile);
351 fread(uncompressed_buff, pLodDirectory.uDataSize, 1, pLLoidFile);
352 strcpy(pLodDirectory.pFilename, work_string);
353 fclose(pLLoidFile);
354 remove(work_string);
355 if ( pNew_LOD->Write(&pLodDirectory, uncompressed_buff, 0) )
356 {
357 sprintf(work_string, pGlobalTXT_LocalizationStrings[612], 207);
358 MessageBoxA(nullptr, work_string, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:857", 0);
359 Size = 5080748;
360 }
361 }
362 }
363 }
364 if ( !NotSaveWorld )//autosave for change location
365 {
366 //__debugbreak();
367 CompactLayingItemsList();
368 compressed_buf = (char*)malloc(1000000);
369 odm_data.uVersion = 91969;
370 odm_data.pMagic[0] = 'm';
371 odm_data.pMagic[1] = 'v';
372 odm_data.pMagic[2] = 'i';
373 odm_data.pMagic[3] = 'i';
374 odm_data.uCompressedSize = 0;
375 odm_data.uDecompressedSize = 0;
376 data_write_pos = uncompressed_buff;
377 memcpy((void *)compressed_buf, &odm_data, 0x10);
378 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
379 {
380 pIndoor->dlv.uNumFacesInBModels = pIndoor->uNumFaces;
381 pIndoor->dlv.uNumBModels = 0;
382 pIndoor->dlv.uNumDecorations = uNumLevelDecorations;
383 memcpy(data_write_pos, &pIndoor->dlv,sizeof(DDM_DLV_Header) );//0x28
384 data_write_pos += sizeof(DDM_DLV_Header);
385 memcpy(data_write_pos, pIndoor->_visible_outlines, 0x36B);
386 data_write_pos += 875;
387 for (int i = 0; i <(signed int)pIndoor->uNumFaces; ++i)
388 {
389 memcpy(data_write_pos, &pIndoor->pFaces[i].uAttributes, 4);
390 data_write_pos += 4;
391 }
392
393 for (int i = 0; i <(signed int)uNumLevelDecorations; ++i)
394 {
395 memcpy(data_write_pos, &pLevelDecorations[i].uFlags, 2);
396 data_write_pos += 2;
397 }
398 memcpy(data_write_pos, &uNumActors, 4);
399 data_write_pos += 4;
400 memcpy(data_write_pos, &pActors, uNumActors * sizeof(Actor));
401 data_write_pos += uNumActors * sizeof(Actor);
402 memcpy(data_write_pos, &uNumSpriteObjects, 4);
403 data_write_pos += 4;
404 memcpy(data_write_pos, pSpriteObjects.data(), 112 * uNumSpriteObjects);
405 data_write_pos += 112 * uNumSpriteObjects;
406 memcpy(data_write_pos, &uNumChests, 4);
407 data_write_pos += 4;
408 memcpy(data_write_pos, pChests.data(), sizeof(Chest)*uNumChests);//5324 *
409 data_write_pos += sizeof(Chest)* uNumChests;
410 memcpy(data_write_pos, pIndoor->pDoors, 0x3E80);
411 data_write_pos += 16000;
412 memcpy(data_write_pos, pIndoor->ptr_0002B4_doors_ddata, pIndoor->blv.uDoors_ddata_Size);
413 data_write_pos += pIndoor->blv.uDoors_ddata_Size;
414 memcpy(data_write_pos, &stru_5E4C90_MapPersistVars, 0xC8);
415 data_write_pos += 200;
416 memcpy(data_write_pos, &pIndoor->stru1, 0x38);
417 data_write_pos += 56;
418
419 }
420 else//for Outdoor
421 {
422 pOutdoor->ddm.uNumFacesInBModels = 0;
423 for ( int i = 0; i < pOutdoor->uNumBModels; ++i )
424 pOutdoor->ddm.uNumFacesInBModels += pOutdoor->pBModels[i].uNumFaces;
425 pOutdoor->ddm.uNumBModels = pOutdoor->uNumBModels;
426 pOutdoor->ddm.uNumDecorations = uNumLevelDecorations;
427 memcpy(data_write_pos, &pOutdoor->ddm, sizeof(DDM_DLV_Header));//0x28
428 data_write_pos += sizeof(DDM_DLV_Header);
429 memcpy(data_write_pos, pOutdoor->uFullyRevealedCellOnMap, 0x3C8);
430 data_write_pos += 968;
431 memcpy(data_write_pos, pOutdoor->uPartiallyRevealedCellOnMap, 0x3C8);
432 data_write_pos += 968;
433 for (int i = 0; i < pOutdoor->uNumBModels ; ++i)
434 for (int j = 0; j < pOutdoor->pBModels[i].uNumFaces;++j)//*(int *)&pOutdoor->pBModels->pModelName[v24]; ++j)
435 {
436 memcpy(data_write_pos, &(pOutdoor->pBModels[i].pFaces[j].uAttributes), 4);
437 data_write_pos += 4;
438 }
439
440 for (int i = 0; i < (signed int)uNumLevelDecorations; ++i)
441 {
442 memcpy(data_write_pos, &pLevelDecorations[i].uFlags, 2);
443 data_write_pos += 2;
444 }
445 memcpy(data_write_pos, &uNumActors, 4);
446 data_write_pos += 4;
447 memcpy(data_write_pos, &pActors, uNumActors * sizeof(Actor));
448 data_write_pos += uNumActors * sizeof(Actor);
449 memcpy(data_write_pos, &uNumSpriteObjects, 4);
450 data_write_pos += 4;
451 memcpy(data_write_pos, &pSpriteObjects, uNumSpriteObjects * sizeof(SpriteObject));
452 data_write_pos += uNumSpriteObjects * sizeof(SpriteObject);
453 memcpy(data_write_pos, &uNumChests, 4);
454 data_write_pos += 4;
455 memcpy(data_write_pos, pChests.data(), sizeof(Chest)* uNumChests);
456 data_write_pos += sizeof(Chest) * uNumChests;
457 memcpy(data_write_pos, &stru_5E4C90_MapPersistVars, 0xC8);
458 data_write_pos += 200;
459 memcpy(data_write_pos, &pOutdoor->loc_time, 0x38);
460 data_write_pos += 56;
461 }
462 strcpy(Source, pCurrentMapName);
463 _splitpath(Source, Drive, Dir, Filename, Ext);
464 Ext[1] = 'd';
465
466 Size = (int)data_write_pos - (int)uncompressed_buff;
467 compressed_block_size = 999984;
468 res = zlib::MemZip((char *)compressed_buf + 16, (unsigned int *)&compressed_block_size, uncompressed_buff,Size);
469 if (res || (signed int)compressed_block_size > (signed int)Size )
470 {
471 memcpy((void *)(compressed_buf + 16), uncompressed_buff, Size);
472 compressed_block_size = Size;
473 }
474 compressed_block_size += 16;
475 memcpy(&((ODMHeader *)compressed_buf)->uCompressedSize, &compressed_block_size, 4);
476 memcpy(&((ODMHeader *)compressed_buf)->uDecompressedSize, &Size, 4);
477 sprintf(Source, "%s%s", Filename, Ext);
478 strcpy(pLodDirectory.pFilename, Source);
479 pLodDirectory.uDataSize = compressed_block_size;
480 if ( pNew_LOD->Write(&pLodDirectory, (const void *)compressed_buf, 0) )
481 {
482 sprintf(work_string, pGlobalTXT_LocalizationStrings[612], 208);
483 MessageBoxA(nullptr, work_string, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:1071", 0);
484 }
485 free((void *)compressed_buf);
486 }
487 free(uncompressed_buff);
488 if ( IsAutoSAve )
489 {
490 if ( !CopyFileA("data\\new.lod", "saves\\autosave.mm7", 0) )
491 {
492 FormatMessageA(0x1000, 0, GetLastError(), 0x400, Buffer, 0x80, 0);
493 sprintf(work_string, pGlobalTXT_LocalizationStrings[612], 300);
494 MessageBoxA(nullptr, work_string, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:1097", 0);
495 }
496 }
497 pParty->vPosition.x = pPositionX;
498 pParty->vPosition.y = pPositionY;
499 pParty->vPosition.z = pPositionZ;
500 pParty->uFallStartY = pPositionZ;
501 pParty->sRotationY = sPRotationY;
502 pParty->sRotationX = sPRotationX;
503 }
504
505 //----- (00460078) --------------------------------------------------------
506 void __fastcall DoSavegame(unsigned int uSlot)
507 {
508 if ( _stricmp(pCurrentMapName, "d05.blv") )//Not Arena(не Арена)
509 {
510 LOD::Directory pDir; // [sp+Ch] [bp-28h]@2
511 SaveGame(0, 0);
512 strcpy(pSavegameHeader[uSlot].pLocationName, pCurrentMapName);//дать название карты
513 pSavegameHeader[uSlot].uWordTime = pParty->uTimePlayed;//текущее время
514 strcpy(pDir.pFilename, "header.bin");
515 pDir.uDataSize = 100;
516 pNew_LOD->Write(&pDir, &pSavegameHeader[uSlot], 0);
517 sprintf(pTmpBuf.data(), "saves\\save%03d.mm7", uSlot);
518 pNew_LOD->CloseWriteFile();//закрыть
519 CopyFileA("data\\new.lod", pTmpBuf.data(), 0);//сохранение файла в директорию saves
520 }
521 GUI_UpdateWindows();
522 pGUIWindow_CurrentMenu->Release();
523 pCurrentScreen = SCREEN_GAME;
524 //v3 = pSavegameThumbnails;
525 viewparams->bRedrawGameUI = true;
526 for (uint i = 0; i < 45; i++)
527 pSavegameThumbnails[i].Release();
528
529 if ( _stricmp(pCurrentMapName, "d05.blv") )
530 pNew_LOD->_4621A7();
531 else
532 ShowStatusBarString(pGlobalTXT_LocalizationStrings[583], 2);// "No saving in the Arena"
533 pIcons_LOD->RemoveTexturesFromTextureList();
534 pEventTimer->Resume();
535 ShowStatusBarString(pGlobalTXT_LocalizationStrings[656], 2);// "Game Saved!"
536 viewparams->bRedrawGameUI = true;
537 }
538 // 4E28F8: using guessed type int pCurrentScreen;
539
540 //----- (0045E297) --------------------------------------------------------
541 void SavegameList::Initialize(unsigned int bHideEmptySlots)
542 {
543 //memset(pSavegameList, 0, sizeof(pSavegameList));//Ritor1: вызывает затирание
544 pSavegameList->Reset();
545 uNumSavegameFiles = 0;
546
547 _chdir("saves");
548 {
549 if (!bHideEmptySlots && _access(pGlobalTXT_LocalizationStrings[613], 0) != -1 ) // AutoSave.MM7
550 strcpy(pSavegameList->pFileList[uNumSavegameFiles++].pSaveFileName, pGlobalTXT_LocalizationStrings[613]);
551
552 for (uint i = 0; i < 40; ++i)
553 {
554 sprintf(pTmpBuf.data(), "save%03d.mm7", i);
555 if (_access(pTmpBuf.data(), 0) == -1)
556 continue;
557
558 uint idx = i;
559 if (!bHideEmptySlots)
560 idx = uNumSavegameFiles;
561 strcpy(pSavegameList->pFileList[idx].pSaveFileName, pTmpBuf.data());
562
563 ++uNumSavegameFiles;
564 }
565 }
566 _chdir("..");
567 }
568 //----- (0046086A) --------------------------------------------------------
569 void SaveNewGame()
570 {
571 FILE *file; // eax@7
572 void *pSave; // [sp+170h] [bp-8h]@3
573
574 if ( pMovie_Track )
575 pMediaPlayer->Unload();
576 pSave = malloc(1000000);
577 pNew_LOD->CloseWriteFile();
578 remove("data\\new.lod");//удалить new.lod
579
580 LOD::FileHeader header; // [sp+Ch] [bp-16Ch]@3 заголовок
581 strcpy(header.LodVersion, "MMVII");
582 strcpy(header.LodDescription, "newmaps for MMVII");
583 header.LODSize = 100;
584 header.dword_0000A8 = 0;
585
586 LOD::Directory a3; // [sp+14Ch] [bp-2Ch]@3
587 a3.dword_000018 = 0;
588 a3.word_00001E = 0;
589 strcpy(a3.pFilename, "current");
590 pNew_LOD->CreateNewLod(&header, &a3, "data\\new.lod");//создаётся new.lod в дирректории
591 if (pNew_LOD->LoadFile("data\\new.lod", false))//загрузить файл new.lod(isFileOpened = true)
592 {
593 pNew_LOD->CreateTempFile();//создаётся временный файл OutputFileHandle
594 pNew_LOD->uNumSubDirs = 0;
595
596 LOD::Directory pDir; // [sp+10Ch] [bp-6Ch]@4
597 for (int i = pGames_LOD->uNumSubDirs / 2; i < pGames_LOD->uNumSubDirs; ++i)//копирование файлов с 76 по 151
598 {
599 memcpy(&pDir, &pGames_LOD->pSubIndices[i], sizeof(pDir));//копирование текущего файла в pDir
600 file = pGames_LOD->FindContainer(pGames_LOD->pSubIndices[i].pFilename, 1);
601 fread(pSave, pGames_LOD->pSubIndices[i].uDataSize, 1, file);
602 pNew_LOD->AppendDirectory(&pDir, pSave);
603 }
604
605 LOD::Directory save_game_dir; // [sp+12Ch] [bp-4Ch]@9
606 strcpy(pSavegameHeader[0].pLocationName, "out01.odm");
607 strcpy(save_game_dir.pFilename, "header.bin");
608 save_game_dir.uDataSize = sizeof(SavegameHeader);
609 pNew_LOD->AppendDirectory(&save_game_dir, &pSavegameHeader[0]);
610
611 pNew_LOD->FixDirectoryOffsets();
612
613 pParty->vPrevPosition.x = 12552;
614 pParty->vPrevPosition.y = 1816;
615 pParty->vPrevPosition.z = 0;
616
617 pParty->vPosition.x = 12552;
618 pParty->vPosition.y = 1816;
619 pParty->vPosition.z = 0;
620
621 pParty->uFallStartY = 0;
622
623 pParty->sPrevRotationX = 0;
624 pParty->sPrevRotationY = 512;
625
626 pParty->sRotationX = 0;
627 pParty->sRotationY = 512;
628
629 SaveGame(1, 1);
630 }
631 free(pSave);
632 }
633