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