Mercurial > mm7
annotate SaveLoad.cpp @ 810:f5156b8c61ad
savegame refactoring
author | Gloval |
---|---|
date | Tue, 26 Mar 2013 00:57:54 +0400 |
parents | 90bcfb56c8f9 |
children | 35122475edd7 cfc65feef029 |
rev | line source |
---|---|
0 | 1 #include <io.h> |
2 #include <direct.h> | |
3 #include <assert.h> | |
4 | |
5 #include "SaveLoad.h" | |
6 #include "NPC.h" | |
7 #include "Party.h" | |
8 #include "LOD.h" | |
9 #include "Outdoor.h" | |
10 #include "AudioPlayer.h" | |
11 #include "Actor.h" | |
12 #include "Chest.h" | |
13 #include "Time.h" | |
14 #include "GUIWindow.h" | |
15 #include "GUIFont.h" | |
16 #include "Overlays.h" | |
515
cb0ad52d6a26
LayingItem -> SpriteObject (long-waited rename, old name was inaccurate and confused people)
Nomad
parents:
488
diff
changeset
|
17 #include "SpriteObject.h" |
0 | 18 #include "Viewport.h" |
19 #include "stru123.h" | |
189 | 20 #include "texts.h" |
0 | 21 #include "Log.h" |
22 | |
23 #include "mm7_data.h" | |
24 | |
25 | |
26 | |
810 | 27 struct SaveDataHeader |
28 { | |
29 int Signature; | |
30 char txt_ver[4]; | |
31 int compressed_size; | |
32 int uncompressed_size; | |
33 }; | |
34 | |
35 | |
0 | 36 |
37 | |
38 struct SavegameList *pSavegameList = new SavegameList; | |
39 unsigned int uNumSavegameFiles; | |
40 unsigned int pSavegameUsedSlots[45]; | |
41 struct RGBTexture pSavegameThumbnails[45]; | |
42 SavegameHeader pSavegameHeader[45]; | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 //----- (0045EE8A) -------------------------------------------------------- | |
54 void __fastcall LoadGame(unsigned int uSlot) | |
55 { | |
56 bool v25; // esi@62 | |
57 bool v26; // eax@62 | |
58 int v30; // [sp-Ch] [bp-FCh]@65 | |
59 int v31; // [sp-8h] [bp-F8h]@4 | |
60 SavegameHeader header; // [sp+Ch] [bp-E4h]@23 | |
61 char Str[123]; // [sp+70h] [bp-80h]@25 | |
62 | |
336 | 63 dword_5B65C8_timers_count = 0; |
0 | 64 if (!pSavegameUsedSlots[uSlot]) |
65 { | |
66 pAudioPlayer->PlaySound(SOUND_27, 0, 0, -1, 0, 0, 0, 0); | |
67 Log::Warning(L"LoadGame: slot %u is empty", uSlot); | |
68 return; | |
69 } | |
70 | |
71 for (uint i = 1; i < 5; ++i) | |
72 for (uint j = 1; j < 6; ++j) | |
73 { | |
74 sprintf(pTmpBuf, "data\\lloyd%d%d.pcx", i, j); | |
75 remove(pTmpBuf); | |
76 } | |
77 | |
78 | |
203 | 79 if (SoundSetAction[24][0]) |
0 | 80 for (uint i = 0; i < 4; ++i) |
81 { | |
764 | 82 for (uint j = 0; j < pSoundList->sNumSounds; ++j) |
203 | 83 if (pSoundList->pSounds[j].uSoundID == 2 * (SoundSetAction[24][0] + 50 * pParty->pPlayers[i].uVoiceID) + 4998) |
0 | 84 { |
764 | 85 pSoundList->UnloadSound(j, 1); |
0 | 86 break; |
87 } | |
88 | |
764 | 89 for (uint j = 0; j < pSoundList->sNumSounds; ++j) |
203 | 90 if (pSoundList->pSounds[j].uSoundID == 2 * (SoundSetAction[24][0] + 50 * pParty->pPlayers[i].uVoiceID) + 4999) |
0 | 91 { |
764 | 92 pSoundList->UnloadSound(j, 1); |
0 | 93 break; |
94 } | |
95 } | |
96 | |
382 | 97 sprintf(pTmpBuf, "saves\\%s", pSavegameList->pFileList[uSlot].pSaveFileName); |
0 | 98 |
99 pNew_LOD->CloseWriteFile(); | |
100 if (!CopyFileA(pTmpBuf, "data\\new.lod", 0)) | |
101 int e = GetLastError(); | |
102 | |
103 pNew_LOD->LoadFile("data\\new.lod", 0); | |
104 auto *f = pNew_LOD->FindContainer("header.bin", 1); | |
105 if (!f) | |
106 { | |
107 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 100); | |
108 Log::Warning(L"%S", Str); | |
109 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:549", 0); | |
110 } | |
111 assert(sizeof(SavegameHeader) == 100); | |
112 fread(&header, sizeof(SavegameHeader), 1, f); | |
113 | |
114 f = pNew_LOD->FindContainer("party.bin", 1); | |
115 if (!f) | |
116 { | |
117 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 101); | |
118 Log::Warning(L"%S", Str); | |
119 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:559", 0); | |
120 } | |
121 if (sizeof(Party) != 0x16238) | |
122 Log::Warning(L"class Party: deserialization warning"); | |
123 fread(pParty, 0x16238u, 1, f); | |
124 | |
125 | |
126 f = pNew_LOD->FindContainer("clock.bin", 1); | |
127 if (!f) | |
128 { | |
129 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 102); | |
130 Log::Warning(L"%S", Str); | |
131 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:569", 0); | |
132 } | |
133 if (sizeof(Timer) != 0x28) | |
134 Log::Warning(L"class Timer: deserialization warning"); | |
135 fread(pEventTimer, 0x28u, 1u, f); | |
136 | |
137 f = pNew_LOD->FindContainer("overlay.bin", 1); | |
138 if (!f) | |
139 { | |
140 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 103); | |
141 Log::Warning(L"%S", Str); | |
142 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:579", 0); | |
143 } | |
144 if (sizeof(OtherOverlayList) != 0x3F0) | |
145 Log::Warning(L"class OtherOverlayList: deserialization warning"); | |
146 fread(pOtherOverlayList, 0x3F0, 1, f); | |
147 | |
148 f = pNew_LOD->FindContainer("npcdata.bin", 0); | |
149 if (!f) | |
150 { | |
151 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 104); | |
152 Log::Warning(L"%S", Str); | |
153 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:590", 0); | |
154 } | |
155 if (sizeof(pNPCStats->pNewNPCData) != 0x94BC) | |
156 Log::Warning(L"NPCStats: deserialization warning"); | |
157 fread(pNPCStats->pNewNPCData, 0x94BC, 1, f); | |
158 pNPCStats->_476C60(); | |
159 | |
160 f = pNew_LOD->FindContainer("npcgroup.bin", 0); | |
161 if (!f) | |
162 { | |
163 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 105); | |
164 Log::Warning(L"%S", Str); | |
165 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:600", 0); | |
166 } | |
167 if (sizeof(pNPCStats->pGroups_copy) != 0x66) | |
168 Log::Warning(L"NPCStats: deserialization warning"); | |
169 fread(pNPCStats->pGroups_copy, 0x66, 1, f); | |
170 | |
171 | |
172 uActiveCharacter = 0; | |
173 for (uint i = 0; i < 4; ++i) | |
174 if (pParty->pPlayers[i].CanAct()) | |
175 { | |
176 uActiveCharacter = i + 1; | |
177 break; | |
178 } | |
179 | |
180 for (uint i = 0; i < 4; ++i) | |
181 { | |
182 auto uQuickspell = pParty->pPlayers[i].uQuickSpell; | |
183 if (uQuickspell) | |
184 stru_AA1058[i]._494836(uQuickspell, i + 9 - 8); | |
185 | |
186 for (uint j = 0; j < 2; ++j) | |
187 { | |
188 uint uEquipIdx = pParty->pPlayers[i].pEquipment.pIndices[j]; | |
189 if (uEquipIdx) | |
190 { | |
191 auto uItemID = pParty->pPlayers[i].pInventoryItems[uEquipIdx - 1].uItemID; | |
192 if (pItemsTable->pItems[uItemID].uEquipType == 12) | |
193 { | |
194 __debugbreak(); | |
488 | 195 v31 = *((int *)&pSpellDatas[66].uNormalLevelRecovery + uItemID); |
0 | 196 stru_A750F8[i]._494836(v31, i + 9); |
197 } | |
198 } | |
199 } | |
200 } | |
201 | |
202 | |
203 pGUIWindow_CurrentMenu->Release(); | |
151 | 204 pCurrentScreen = SCREEN_GAME; |
0 | 205 |
206 viewparams->bRedrawGameUI = true; | |
207 | |
373 | 208 SetUserInterface(pParty->alignment, true); |
0 | 209 |
210 pEventTimer->Resume(); | |
211 pEventTimer->StopGameTime(); | |
212 | |
213 v25 = pGames_LOD->DoesContainerExist(header.pLocationName); | |
214 sprintf(pTmpBuf, "levels\\%s", header.pLocationName); | |
215 v26 = _access(pTmpBuf, 4) != -1; | |
216 if ( !v25 && !v26 ) | |
217 { | |
218 sprintf(pTmpBuf, "Unable to find: %s!", header.pLocationName); | |
219 Abortf(pTmpBuf); | |
220 } | |
221 | |
222 strcpy(pCurrentMapName, header.pLocationName); | |
223 dword_6BE364_game_settings_1 |= 0x2001; | |
224 | |
225 for (uint i = 0; i < uNumSavegameFiles; ++i) | |
226 pSavegameThumbnails[i].Release(); | |
227 | |
228 pIcons_LOD->_4114F2(); | |
328 | 229 pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f); |
230 pAudioPlayer->SetMasterVolume(pSoundVolumeLevels[uSoundVolumeMultiplier] * 128.0f); | |
0 | 231 if (uTurnSpeed) |
232 pParty->sRotationY = uTurnSpeed * pParty->sRotationY / (signed int)uTurnSpeed; | |
233 MM7Initialization(); | |
234 bFlashQuestBook = false; | |
235 viewparams->bRedrawGameUI = true; | |
236 } | |
237 | |
238 | |
239 //----- (0045F469) -------------------------------------------------------- | |
810 | 240 void SaveGame( bool IsAutoSAve, bool NotSaveWorld ) |
241 { | |
0 | 242 int result; // eax@1 |
810 | 243 unsigned short *pScreenshot; // edi@5 |
244 int text_pos; // eax@6 | |
0 | 245 int v5; // eax@6 |
246 int v6; // eax@6 | |
247 const char *v7; // edi@8 | |
248 FILE *v8; // edi@24 | |
810 | 249 char* compressed_buf; // edi@30 |
0 | 250 void *v10; // esi@31 |
251 void *v11; // esi@31 | |
252 void *v12; // esi@37 | |
253 void *v13; // esi@37 | |
254 void *v14; // esi@37 | |
255 void *v15; // esi@37 | |
256 void *v16; // esi@37 | |
257 int v17; // esi@37 | |
258 unsigned int v18; // ecx@38 | |
259 unsigned int v19; // esi@39 | |
79 | 260 BSPModel *v20; // edx@39 |
810 | 261 char *data_write_pos; // esi@41 |
0 | 262 void *v22; // esi@41 |
263 BSPModel *v23; // eax@42 | |
264 signed int v24; // edi@42 | |
265 unsigned __int8 v25; // zf@43 | |
266 unsigned __int8 v26; // sf@43 | |
267 signed int v27; // edi@47 | |
268 void *v28; // esi@50 | |
269 void *v29; // esi@50 | |
270 void *v30; // esi@50 | |
271 void *v31; // esi@50 | |
272 int v32; // esi@51 | |
273 int v33; // eax@51 | |
274 DWORD v34; // eax@59 | |
275 //std::string v35; // [sp-18h] [bp-288h]@8 | |
276 const char *v36; // [sp-10h] [bp-280h]@6 | |
277 const char *v37; // [sp-Ch] [bp-27Ch]@6 | |
79 | 278 unsigned int *v38; // [sp-8h] [bp-278h]@8 |
0 | 279 CHAR Buffer; // [sp+Ch] [bp-264h]@59 |
79 | 280 char Dir[255]; // [sp+8Ch] [bp-1E4h]@51 |
281 char Drive[255]; // [sp+ACh] [bp-1C4h]@51 | |
0 | 282 SavegameHeader header; // [sp+CCh] [bp-1A4h]@10 |
283 //int v43; // [sp+CCh] [bp-1A4h]@10 | |
284 //char Dest[20]; // [sp+E0h] [bp-190h]@10 | |
285 //unsigned __int64 pTimePlayed; // [sp+F4h] [bp-17Ch]@10 | |
79 | 286 char Filename[255]; // [sp+130h] [bp-140h]@51 |
287 char Ext[255]; // [sp+150h] [bp-120h]@51 | |
0 | 288 char v48; // [sp+151h] [bp-11Fh]@51 |
289 char Source[32]; // [sp+170h] [bp-100h]@51 | |
290 char Str[120]; // [sp+190h] [bp-E0h]@8 | |
291 int v51; // [sp+208h] [bp-68h]@2 | |
292 int pPositionX; // [sp+20Ch] [bp-64h]@2 | |
293 int v53; // [sp+210h] [bp-60h]@2 | |
294 int v54; // [sp+214h] [bp-5Ch]@2 | |
810 | 295 SaveDataHeader Src; // [sp+218h] [bp-58h]@30 |
0 | 296 char v56; // [sp+21Ch] [bp-54h]@30 |
297 char v57; // [sp+21Dh] [bp-53h]@30 | |
298 char v58; // [sp+21Eh] [bp-52h]@30 | |
299 char v59; // [sp+21Fh] [bp-51h]@30 | |
300 int v60; // [sp+220h] [bp-50h]@30 | |
301 int v61; // [sp+224h] [bp-4Ch]@30 | |
302 int v62; // [sp+228h] [bp-48h]@2 | |
810 | 303 LOD::Directory pLodDirectory; // [sp+22Ch] [bp-44h]@2 |
0 | 304 size_t Size; // [sp+250h] [bp-20h]@26 |
305 __int16 *v66; // [sp+254h] [bp-1Ch]@1 | |
810 | 306 char *uncompressed_buff; // [sp+258h] [bp-18h]@2 |
0 | 307 __int16 *v68; // [sp+25Ch] [bp-14h]@32 |
810 | 308 unsigned int compressed_block_size; // [sp+260h] [bp-10h]@23 |
0 | 309 int v70; // [sp+264h] [bp-Ch]@22 |
310 std::string *v71; // [sp+268h] [bp-8h]@8 | |
311 int a3; // [sp+26Fh] [bp-1h]@8 | |
312 | |
568 | 313 //v66 = a2; |
0 | 314 strcpy(byte_6BE3B0, pCurrentMapName); |
568 | 315 if (!_strcmpi(pCurrentMapName, "d05.blv")) // arena |
810 | 316 return; |
568 | 317 |
810 | 318 uncompressed_buff = (char*)malloc(1000000); |
319 pLodDirectory.Reset(); | |
0 | 320 pPositionX = pParty->vPosition.x; |
321 v51 = pParty->vPosition.y; | |
322 v62 = pParty->vPosition.z; | |
323 v53 = pParty->sRotationY; | |
324 v54 = pParty->sRotationX; | |
325 pParty->vPosition.x = pParty->vPrevPosition.x; | |
326 pParty->vPosition.y = pParty->vPrevPosition.z; | |
327 pParty->vPosition.z = pParty->vPrevPosition.y; | |
328 pParty->uFallStartY = pParty->vPrevPosition.y; | |
329 pParty->sRotationY = pParty->sPrevRotationY; | |
330 pParty->sRotationX = pParty->sPrevRotationX; | |
331 if (uCurrentlyLoadedLevelType == LEVEL_Indoor) | |
332 pIndoor->stru1.uLastVisitDay = pParty->uTimePlayed; | |
333 else | |
810 | 334 pOutdoor->loc_time.uLastVisitDay = pParty->uTimePlayed; |
0 | 335 pScreenshot = MakeScreenshot(150, 112); |
810 | 336 strcpy(pLodDirectory.pFilename, "image.pcx"); |
337 pRenderer->PackPCXpicture(pScreenshot, 150, 112, uncompressed_buff, 1000000, &pLodDirectory.uDataSize); | |
0 | 338 free(pScreenshot); |
151 | 339 if (pCurrentScreen == SCREEN_SAVEGAME) |
0 | 340 { |
568 | 341 pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->GetTexture(uTextureID_loadsave)); |
342 pRenderer->DrawTextureIndexed(18, 141, pIcons_LOD->GetTexture(uTextureID_save_up)); | |
810 | 343 text_pos = pFontSmallnum->AlignText_Center(186, pGlobalTXT_LocalizationStrings[190]); |
344 pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, text_pos + 25, 219, 0, pGlobalTXT_LocalizationStrings[190], 0, 0, 0); //Ñîõðàíåíèå | |
345 text_pos = pFontSmallnum->AlignText_Center(186, pSavegameHeader[uLoadGameUI_SelectedSlot].pName); | |
346 pGUIWindow_CurrentMenu->DrawTextInRect(pFontSmallnum, text_pos + 25, 259, 0, pSavegameHeader[uLoadGameUI_SelectedSlot].pName, 185, 0); | |
347 text_pos = pFontSmallnum->AlignText_Center(186, pGlobalTXT_LocalizationStrings[165]); | |
348 pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, text_pos + 25, 299, 0, pGlobalTXT_LocalizationStrings[165], 0, 0, 0); //Ïîæàëóéñòà, ïîäîæäèòå | |
0 | 349 pRenderer->Present(); |
568 | 350 } |
351 | |
810 | 352 if (pNew_LOD->Write(&pLodDirectory, uncompressed_buff, 0)) |
0 | 353 { |
354 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 200); //Ñîõðàíåííàÿ èãðà ïîâðåæäåíà! Code=%d | |
355 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:773", 0); | |
356 } | |
357 | |
358 assert(sizeof(SavegameHeader) == 100); | |
359 memset(header.pName, 0, 20); | |
360 memset(header.pLocationName, 0, 20); | |
361 memset(header.field_30, 0, 52); | |
362 strcpy(header.pLocationName, pCurrentMapName); | |
363 header.uWordTime = pParty->uTimePlayed; | |
810 | 364 strcpy(pLodDirectory.pFilename, "header.bin"); |
365 pLodDirectory.uDataSize = sizeof(SavegameHeader); | |
366 if (pNew_LOD->Write(&pLodDirectory, &header, 0)) | |
0 | 367 { |
368 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 201); | |
369 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:784", 0); | |
370 } | |
810 | 371 strcpy(pLodDirectory.pFilename, "party.bin"); |
372 pLodDirectory.uDataSize = sizeof(Party); //90680; | |
373 if ( pNew_LOD->Write(&pLodDirectory, pParty, 0) ) | |
0 | 374 { |
375 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 202); | |
376 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:793", 0); | |
377 } | |
810 | 378 strcpy(pLodDirectory.pFilename, "clock.bin"); |
379 pLodDirectory.uDataSize =sizeof(Timer);// 40; | |
380 if ( pNew_LOD->Write(&pLodDirectory, pEventTimer, 0) ) | |
0 | 381 { |
382 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 203); | |
383 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:802", 0); | |
384 } | |
810 | 385 strcpy(pLodDirectory.pFilename, "overlay.bin"); |
386 pLodDirectory.uDataSize =sizeof(OtherOverlayList);// 1008; | |
387 if ( pNew_LOD->Write(&pLodDirectory, pOtherOverlayList, 0) ) | |
0 | 388 { |
389 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 204); | |
390 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:811", 0); | |
391 } | |
810 | 392 strcpy(pLodDirectory.pFilename, "npcdata.bin"); |
393 pLodDirectory.uDataSize = 501 * sizeof(NPCData); | |
394 assert(pLodDirectory.uDataSize == 38076); | |
395 if ( pNew_LOD->Write(&pLodDirectory, pNPCStats->pNewNPCData, 0) ) | |
0 | 396 { |
397 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 205); | |
398 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:820", 0); | |
399 } | |
810 | 400 strcpy(pLodDirectory.pFilename, "npcgroup.bin"); |
401 pLodDirectory.uDataSize = 102; | |
402 if ( pNew_LOD->Write(&pLodDirectory, pNPCStats->pGroups_copy, 0) ) | |
0 | 403 { |
404 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 206); | |
405 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:829", 0); | |
406 } | |
407 for (int i = 1; i <= 4; ++i) // 4 - players | |
408 { | |
409 for (int j = 1; j <= 5; ++j) // 5 - images | |
410 { | |
411 sprintf(Str, "data\\lloyd%d%d.pcx", i, j); | |
412 v8 = fopen(Str, "rb"); | |
413 if ( v8 ) | |
414 { | |
415 __debugbreak(); | |
416 sprintf(Str, "lloyd%d%d.pcx", i, j); | |
417 fseek(v8, 0, 2); | |
810 | 418 pLodDirectory.uDataSize = ftell(v8); |
0 | 419 rewind(v8); |
810 | 420 fread(uncompressed_buff, pLodDirectory.uDataSize, 1, v8); |
421 strcpy((char *)&pLodDirectory, Str); | |
0 | 422 fclose(v8); |
423 remove(Str); | |
810 | 424 if ( pNew_LOD->Write(&pLodDirectory, uncompressed_buff, 0) ) |
0 | 425 { |
426 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 207); | |
427 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:857", 0); | |
428 Size = 5080748; | |
429 } | |
430 } | |
431 } | |
432 } | |
810 | 433 if ( !NotSaveWorld ) |
0 | 434 { |
79 | 435 //__debugbreak(); |
810 | 436 CompactLayingItemsList(); |
437 compressed_buf = (char*)malloc(1000000); | |
438 // v71 = (std::string *)compressed_buf; | |
439 Src.Signature = 91969; | |
440 Src.txt_ver[0] = 'm'; | |
441 Src.txt_ver[1] = 'v'; | |
442 Src.txt_ver[2] = 'i'; | |
443 Src.txt_ver[3] = 'i'; | |
444 Src.compressed_size = 0; | |
445 Src.uncompressed_size = 0; | |
446 data_write_pos = uncompressed_buff; | |
447 memcpy((void *)compressed_buf, &Src, 0x10); | |
0 | 448 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) |
449 { | |
450 pIndoor->dlv.uNumFacesInBModels = pIndoor->uNumFaces; | |
451 pIndoor->dlv.uNumBModels = 0; | |
452 pIndoor->dlv.uNumDecorations = uNumLevelDecorations; | |
810 | 453 memcpy(data_write_pos, &pIndoor->dlv, 0x28); |
454 data_write_pos += 40; | |
455 memcpy(data_write_pos, pIndoor->_visible_outlines, 0x36B); | |
456 data_write_pos += 875; | |
457 | |
458 for (int i = 0; i <(signed int)pIndoor->uNumFaces; ++i) | |
0 | 459 { |
810 | 460 memcpy(data_write_pos, &pIndoor->pFaces[i].uAttributes, 4); |
461 data_write_pos += 4; | |
0 | 462 } |
810 | 463 |
464 for (int i = 0; i <(signed int)uNumLevelDecorations; ++i) | |
0 | 465 { |
810 | 466 memcpy(data_write_pos, &pLevelDecorations[i].field_2, 2); |
467 | |
468 data_write_pos+= 2; | |
0 | 469 } |
810 | 470 memcpy(data_write_pos, &uNumActors, 4); |
471 data_write_pos += 4; | |
472 memcpy(data_write_pos, pActors, 836 * uNumActors); | |
473 data_write_pos += 836 * uNumActors; | |
474 memcpy(data_write_pos, &uNumSpriteObjects, 4); | |
475 data_write_pos += 4; | |
476 memcpy(data_write_pos, pSpriteObjects, 112 * uNumSpriteObjects); | |
477 data_write_pos += 112 * uNumSpriteObjects; | |
478 memcpy(data_write_pos, &uNumChests, 4); | |
479 data_write_pos += 4; | |
480 memcpy(data_write_pos, pChests, 5324 * uNumChests); | |
481 data_write_pos += 5324 * uNumChests; | |
482 memcpy(data_write_pos, pIndoor->pDoors, 0x3E80); | |
483 data_write_pos += 16000; | |
484 memcpy(data_write_pos, pIndoor->ptr_0002B4_doors_ddata, pIndoor->blv.uDoors_ddata_Size); | |
485 data_write_pos += pIndoor->blv.uDoors_ddata_Size; | |
486 memcpy(data_write_pos, &stru_5E4C90, 0xC8); | |
487 data_write_pos += 200; | |
488 memcpy(data_write_pos, &pIndoor->stru1, 0x38); | |
489 data_write_pos += 56; | |
490 | |
0 | 491 } |
492 else | |
493 { | |
494 v18 = 0; | |
495 pOutdoor->ddm.uNumFacesInBModels = 0; | |
810 | 496 for (int i=0; i<pOutdoor->uNumBModels;++i) |
497 { | |
498 v18 +=pOutdoor->pBModels[i].uNumFaces; | |
499 } | |
500 pOutdoor->ddm.uNumFacesInBModels = v18; | |
0 | 501 pOutdoor->ddm.uNumBModels = pOutdoor->uNumBModels; |
502 pOutdoor->ddm.uNumDecorations = uNumLevelDecorations; | |
810 | 503 memcpy(data_write_pos, &pOutdoor->ddm, sizeof(DDM_DLV_Header));//0x28 |
504 data_write_pos += sizeof(DDM_DLV_Header); | |
505 memcpy(data_write_pos, pOutdoor->uUndiscoveredArea, 0x3C8); | |
506 data_write_pos += 968; | |
507 memcpy(data_write_pos, pOutdoor->uDicovered_area, 0x3C8); | |
508 data_write_pos += 968; | |
0 | 509 if ( (signed int)pOutdoor->uNumBModels > 0 ) |
510 { | |
511 v23 = pOutdoor->pBModels; | |
512 v24 = 76; | |
79 | 513 for (int i = 0; i < (signed int)pOutdoor->uNumBModels ; ++i) |
0 | 514 { |
810 | 515 //v25 = v23[i].uNumFaces == 0;//*(int *)&v23->pModelName[v24] == 0; |
516 // v26 = v23[i].uNumFaces < 0;//*(int *)&v23->pModelName[v24] < 0; | |
517 if ( pOutdoor->pBModels[i].uNumFaces>0) | |
0 | 518 { |
519 v68 = 0; | |
79 | 520 for (int j = 0; j < pOutdoor->pBModels[i].uNumFaces;++j)//*(int *)&pOutdoor->pBModels->pModelName[v24]; ++j) |
0 | 521 { |
79 | 522 v38 = &(v23[i].pFaces[j].uAttributes); //(char *)v68 + *(int *)&v23->pModelName[v24 + 8] + 28; |
810 | 523 memcpy(data_write_pos, v38, 4); |
0 | 524 v23 = pOutdoor->pBModels; |
525 v68 += 154; | |
810 | 526 data_write_pos += 4; |
0 | 527 } |
528 } | |
529 v24 += 188; | |
530 } | |
531 } | |
532 if ( (signed int)uNumLevelDecorations > 0 ) | |
533 { | |
534 v66 = &pLevelDecorations[0].field_2; | |
568 | 535 for (int i = 0; i <= (signed int)uNumLevelDecorations; ++i) |
0 | 536 { |
810 | 537 memcpy(data_write_pos, v66, 2); |
0 | 538 v66 += 16; |
810 | 539 data_write_pos += 2; |
0 | 540 } |
541 } | |
810 | 542 memcpy(data_write_pos, &uNumActors, 4); |
543 data_write_pos += 4; | |
544 memcpy(data_write_pos, pActors, 836 * uNumActors); | |
545 data_write_pos += 836 * uNumActors; | |
546 memcpy(data_write_pos, &uNumSpriteObjects, 4); | |
547 data_write_pos += 4; | |
548 memcpy(data_write_pos, pSpriteObjects, 112 * uNumSpriteObjects); | |
549 data_write_pos += 112 * uNumSpriteObjects; | |
550 memcpy(data_write_pos, &uNumChests, 4); | |
551 data_write_pos += 4; | |
552 memcpy(data_write_pos, pChests, 5324 * uNumChests); | |
553 data_write_pos += 5324 * uNumChests; | |
554 memcpy(data_write_pos, &stru_5E4C90, 0xC8); | |
555 data_write_pos += 200; | |
556 memcpy(data_write_pos, &pOutdoor->loc_time, 0x38); | |
557 data_write_pos += 56; | |
558 | |
559 //compressed_buf = (int)v71; | |
0 | 560 } |
561 strcpy(Source, pCurrentMapName); | |
79 | 562 _splitpath(Source, Drive, Dir, Filename, Ext); |
0 | 563 v48 = 100; |
810 | 564 Size = (int)data_write_pos - (int)uncompressed_buff; |
565 compressed_block_size = 999984; | |
566 LOBYTE(v33) = zlib::MemZip((char *)compressed_buf + 16, (unsigned int *)&compressed_block_size, uncompressed_buff,Size); | |
567 if ( v33 || (signed int)compressed_block_size > (signed int)Size ) | |
0 | 568 { |
810 | 569 memcpy((void *)(compressed_buf + 16), uncompressed_buff, Size); |
570 compressed_block_size = Size; | |
0 | 571 } |
810 | 572 compressed_block_size += 16; |
573 memcpy(&((SaveDataHeader *)compressed_buf)->compressed_size, &compressed_block_size, 4); | |
574 memcpy(&((SaveDataHeader *)compressed_buf)->uncompressed_size, &Size, 4); | |
0 | 575 sprintf(Source, "%s%s", &Filename, &Ext); |
810 | 576 strcpy((char *)&pLodDirectory, Source); |
577 pLodDirectory.uDataSize = compressed_block_size; | |
578 if ( pNew_LOD->Write(&pLodDirectory, (const void *)compressed_buf, 0) ) | |
0 | 579 { |
580 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 208); | |
581 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:1071", 0); | |
582 } | |
810 | 583 free((void *)compressed_buf); |
0 | 584 } |
810 | 585 free(uncompressed_buff); |
586 if ( IsAutoSAve ) | |
0 | 587 { |
588 if ( !CopyFileA("data\\new.lod", "saves\\autosave.mm7", 0) ) | |
589 { | |
590 v34 = GetLastError(); | |
591 FormatMessageA(0x1000, 0, v34, 0x400, &Buffer, 0x80, 0); | |
592 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 300); | |
593 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:1097", 0); | |
594 } | |
595 } | |
596 pParty->vPosition.x = pPositionX; | |
597 pParty->vPosition.y = v51; | |
598 pParty->vPosition.z = v62; | |
599 pParty->uFallStartY = v62; | |
600 pParty->sRotationY = v53; | |
601 pParty->sRotationX = v54; | |
602 } | |
603 | |
604 | |
605 //----- (00460078) -------------------------------------------------------- | |
606 void __fastcall DoSavegame(unsigned int uSlot) | |
607 { | |
568 | 608 //unsigned int v1; // esi@1 |
609 //int v2; // esi@2 | |
557 | 610 //RGBTexture *v3; // ebx@3 |
0 | 611 int bNotArena; // [sp+2Ch] [bp-8h]@1 |
568 | 612 //unsigned int v6; // [sp+30h] [bp-4h]@1 |
0 | 613 |
165 | 614 //__debugbreak(); |
0 | 615 |
568 | 616 //v1 = uSlot; |
617 //v6 = uSlot; | |
0 | 618 bNotArena = _strcmpi(pCurrentMapName, "d05.blv"); |
619 if ( bNotArena ) | |
620 { | |
621 LOD::Directory pDir; // [sp+Ch] [bp-28h]@2 | |
622 SaveGame(0, 0); | |
568 | 623 //v2 = 100 * v1; |
624 strcpy(pSavegameHeader[uSlot].pLocationName, pCurrentMapName); | |
625 pSavegameHeader[uSlot].uWordTime = pParty->uTimePlayed; | |
626 strcpy(pDir.pFilename, "header.bin"); | |
0 | 627 pDir.uDataSize = 100; |
568 | 628 pNew_LOD->Write(&pDir, &pSavegameHeader[uSlot], 0); |
629 sprintf(pTmpBuf, "saves\\save%03d.mm7", uSlot); | |
0 | 630 pNew_LOD->CloseWriteFile(); |
631 CopyFileA("data\\new.lod", pTmpBuf, 0); | |
632 } | |
633 GUI_UpdateWindows(); | |
634 pGUIWindow_CurrentMenu->Release(); | |
151 | 635 pCurrentScreen = SCREEN_GAME; |
557 | 636 //v3 = pSavegameThumbnails; |
0 | 637 viewparams->bRedrawGameUI = 1; |
568 | 638 for (uint i = 0; i < 45; i++) |
557 | 639 pSavegameThumbnails[i].Release(); |
640 //while ( (signed int)v3 < (signed int)&unk_6A0758 ); | |
0 | 641 if ( bNotArena ) |
642 pNew_LOD->_4621A7(); | |
643 else | |
644 ShowStatusBarString(pGlobalTXT_LocalizationStrings[583], 2u);// "No saving in the Arena" | |
645 pIcons_LOD->_4355F7(); | |
646 pEventTimer->Resume(); | |
647 ShowStatusBarString(pGlobalTXT_LocalizationStrings[656], 2u);// "Game Saved!" | |
568 | 648 viewparams->bRedrawGameUI = true; |
0 | 649 } |
650 // 4E28F8: using guessed type int pCurrentScreen; | |
651 | |
652 | |
653 | |
654 | |
655 | |
656 | |
657 | |
658 | |
659 | |
660 | |
661 | |
662 //----- (0045E297) -------------------------------------------------------- | |
663 void SavegameList::Initialize(unsigned int bHideEmptySlots) | |
664 { | |
382 | 665 memset(pSavegameList, 0, 0x3138); |
666 // Reset(); | |
4 | 667 uNumSavegameFiles = 0; |
0 | 668 |
669 _chdir("saves"); | |
670 { | |
4 | 671 if (!bHideEmptySlots && _access(pGlobalTXT_LocalizationStrings[613], 0) != -1 ) // AutoSave.MM7 |
382 | 672 strcpy(pSavegameList->pFileList[uNumSavegameFiles++].pSaveFileName, pGlobalTXT_LocalizationStrings[613]); |
0 | 673 |
674 for (uint i = 0; i < 40; ++i) | |
675 { | |
676 sprintf(pTmpBuf, "save%03d.mm7", i); | |
677 if (_access(pTmpBuf, 0) == -1) | |
678 continue; | |
679 | |
680 uint idx = i; | |
681 if (!bHideEmptySlots) | |
682 idx = uNumSavegameFiles; | |
382 | 683 strcpy(pSavegameList->pFileList[idx].pSaveFileName, pTmpBuf); |
0 | 684 |
685 ++uNumSavegameFiles; | |
686 } | |
687 } | |
688 _chdir(".."); | |
689 } |