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