comparison SaveLoad.cpp @ 810:f5156b8c61ad

savegame refactoring
author Gloval
date Tue, 26 Mar 2013 00:57:54 +0400
parents 90bcfb56c8f9
children 35122475edd7 cfc65feef029
comparison
equal deleted inserted replaced
796:14beae4f1723 810:f5156b8c61ad
22 22
23 #include "mm7_data.h" 23 #include "mm7_data.h"
24 24
25 25
26 26
27 struct SaveDataHeader
28 {
29 int Signature;
30 char txt_ver[4];
31 int compressed_size;
32 int uncompressed_size;
33 };
34
35
27 36
28 37
29 struct SavegameList *pSavegameList = new SavegameList; 38 struct SavegameList *pSavegameList = new SavegameList;
30 unsigned int uNumSavegameFiles; 39 unsigned int uNumSavegameFiles;
31 unsigned int pSavegameUsedSlots[45]; 40 unsigned int pSavegameUsedSlots[45];
226 viewparams->bRedrawGameUI = true; 235 viewparams->bRedrawGameUI = true;
227 } 236 }
228 237
229 238
230 //----- (0045F469) -------------------------------------------------------- 239 //----- (0045F469) --------------------------------------------------------
231 int __fastcall SaveGame(int a1, __int16 *a2) 240 void SaveGame( bool IsAutoSAve, bool NotSaveWorld )
232 { 241 {
233 int result; // eax@1 242 int result; // eax@1
234 void *pScreenshot; // edi@5 243 unsigned short *pScreenshot; // edi@5
235 int v4; // eax@6 244 int text_pos; // eax@6
236 int v5; // eax@6 245 int v5; // eax@6
237 int v6; // eax@6 246 int v6; // eax@6
238 const char *v7; // edi@8 247 const char *v7; // edi@8
239 FILE *v8; // edi@24 248 FILE *v8; // edi@24
240 int v9; // edi@30 249 char* compressed_buf; // edi@30
241 void *v10; // esi@31 250 void *v10; // esi@31
242 void *v11; // esi@31 251 void *v11; // esi@31
243 void *v12; // esi@37 252 void *v12; // esi@37
244 void *v13; // esi@37 253 void *v13; // esi@37
245 void *v14; // esi@37 254 void *v14; // esi@37
247 void *v16; // esi@37 256 void *v16; // esi@37
248 int v17; // esi@37 257 int v17; // esi@37
249 unsigned int v18; // ecx@38 258 unsigned int v18; // ecx@38
250 unsigned int v19; // esi@39 259 unsigned int v19; // esi@39
251 BSPModel *v20; // edx@39 260 BSPModel *v20; // edx@39
252 void *v21; // esi@41 261 char *data_write_pos; // esi@41
253 void *v22; // esi@41 262 void *v22; // esi@41
254 BSPModel *v23; // eax@42 263 BSPModel *v23; // eax@42
255 signed int v24; // edi@42 264 signed int v24; // edi@42
256 unsigned __int8 v25; // zf@43 265 unsigned __int8 v25; // zf@43
257 unsigned __int8 v26; // sf@43 266 unsigned __int8 v26; // sf@43
281 char Str[120]; // [sp+190h] [bp-E0h]@8 290 char Str[120]; // [sp+190h] [bp-E0h]@8
282 int v51; // [sp+208h] [bp-68h]@2 291 int v51; // [sp+208h] [bp-68h]@2
283 int pPositionX; // [sp+20Ch] [bp-64h]@2 292 int pPositionX; // [sp+20Ch] [bp-64h]@2
284 int v53; // [sp+210h] [bp-60h]@2 293 int v53; // [sp+210h] [bp-60h]@2
285 int v54; // [sp+214h] [bp-5Ch]@2 294 int v54; // [sp+214h] [bp-5Ch]@2
286 int Src; // [sp+218h] [bp-58h]@30 295 SaveDataHeader Src; // [sp+218h] [bp-58h]@30
287 char v56; // [sp+21Ch] [bp-54h]@30 296 char v56; // [sp+21Ch] [bp-54h]@30
288 char v57; // [sp+21Dh] [bp-53h]@30 297 char v57; // [sp+21Dh] [bp-53h]@30
289 char v58; // [sp+21Eh] [bp-52h]@30 298 char v58; // [sp+21Eh] [bp-52h]@30
290 char v59; // [sp+21Fh] [bp-51h]@30 299 char v59; // [sp+21Fh] [bp-51h]@30
291 int v60; // [sp+220h] [bp-50h]@30 300 int v60; // [sp+220h] [bp-50h]@30
292 int v61; // [sp+224h] [bp-4Ch]@30 301 int v61; // [sp+224h] [bp-4Ch]@30
293 int v62; // [sp+228h] [bp-48h]@2 302 int v62; // [sp+228h] [bp-48h]@2
294 LOD::Directory pDir; // [sp+22Ch] [bp-44h]@2 303 LOD::Directory pLodDirectory; // [sp+22Ch] [bp-44h]@2
295 size_t Size; // [sp+250h] [bp-20h]@26 304 size_t Size; // [sp+250h] [bp-20h]@26
296 __int16 *v66; // [sp+254h] [bp-1Ch]@1 305 __int16 *v66; // [sp+254h] [bp-1Ch]@1
297 void *DstBuf; // [sp+258h] [bp-18h]@2 306 char *uncompressed_buff; // [sp+258h] [bp-18h]@2
298 __int16 *v68; // [sp+25Ch] [bp-14h]@32 307 __int16 *v68; // [sp+25Ch] [bp-14h]@32
299 unsigned int v69; // [sp+260h] [bp-10h]@23 308 unsigned int compressed_block_size; // [sp+260h] [bp-10h]@23
300 int v70; // [sp+264h] [bp-Ch]@22 309 int v70; // [sp+264h] [bp-Ch]@22
301 std::string *v71; // [sp+268h] [bp-8h]@8 310 std::string *v71; // [sp+268h] [bp-8h]@8
302 int a3; // [sp+26Fh] [bp-1h]@8 311 int a3; // [sp+26Fh] [bp-1h]@8
303 312
304 //v66 = a2; 313 //v66 = a2;
305 strcpy(byte_6BE3B0, pCurrentMapName); 314 strcpy(byte_6BE3B0, pCurrentMapName);
306 if (!_strcmpi(pCurrentMapName, "d05.blv")) // arena 315 if (!_strcmpi(pCurrentMapName, "d05.blv")) // arena
307 return false; 316 return;
308 317
309 DstBuf = malloc(0xF4240); 318 uncompressed_buff = (char*)malloc(1000000);
310 pDir.Reset(); 319 pLodDirectory.Reset();
311 pPositionX = pParty->vPosition.x; 320 pPositionX = pParty->vPosition.x;
312 v51 = pParty->vPosition.y; 321 v51 = pParty->vPosition.y;
313 v62 = pParty->vPosition.z; 322 v62 = pParty->vPosition.z;
314 v53 = pParty->sRotationY; 323 v53 = pParty->sRotationY;
315 v54 = pParty->sRotationX; 324 v54 = pParty->sRotationX;
320 pParty->sRotationY = pParty->sPrevRotationY; 329 pParty->sRotationY = pParty->sPrevRotationY;
321 pParty->sRotationX = pParty->sPrevRotationX; 330 pParty->sRotationX = pParty->sPrevRotationX;
322 if (uCurrentlyLoadedLevelType == LEVEL_Indoor) 331 if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
323 pIndoor->stru1.uLastVisitDay = pParty->uTimePlayed; 332 pIndoor->stru1.uLastVisitDay = pParty->uTimePlayed;
324 else 333 else
325 pOutdoor->uLastVisitDay = pParty->uTimePlayed; 334 pOutdoor->loc_time.uLastVisitDay = pParty->uTimePlayed;
326 pScreenshot = MakeScreenshot(150, 112); 335 pScreenshot = MakeScreenshot(150, 112);
327 strcpy(pDir.pFilename, "image.pcx"); 336 strcpy(pLodDirectory.pFilename, "image.pcx");
328 pRenderer->_49F5A2((int)pScreenshot, 150, 112, DstBuf, 1000000, (int)&pDir.uDataSize); 337 pRenderer->PackPCXpicture(pScreenshot, 150, 112, uncompressed_buff, 1000000, &pLodDirectory.uDataSize);
329 free(pScreenshot); 338 free(pScreenshot);
330 if (pCurrentScreen == SCREEN_SAVEGAME) 339 if (pCurrentScreen == SCREEN_SAVEGAME)
331 { 340 {
332 pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->GetTexture(uTextureID_loadsave)); 341 pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->GetTexture(uTextureID_loadsave));
333 pRenderer->DrawTextureIndexed(18, 141, pIcons_LOD->GetTexture(uTextureID_save_up)); 342 pRenderer->DrawTextureIndexed(18, 141, pIcons_LOD->GetTexture(uTextureID_save_up));
334 v4 = pFontSmallnum->AlignText_Center(0xBA, pGlobalTXT_LocalizationStrings[190]); 343 text_pos = pFontSmallnum->AlignText_Center(186, pGlobalTXT_LocalizationStrings[190]);
335 pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, v4 + 25, 219, 0, pGlobalTXT_LocalizationStrings[190], 0, 0, 0); //Сохранение 344 pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, text_pos + 25, 219, 0, pGlobalTXT_LocalizationStrings[190], 0, 0, 0); //Сохранение
336 v5 = pFontSmallnum->AlignText_Center(0xBA, pSavegameHeader[uLoadGameUI_SelectedSlot].pName); 345 text_pos = pFontSmallnum->AlignText_Center(186, pSavegameHeader[uLoadGameUI_SelectedSlot].pName);
337 pGUIWindow_CurrentMenu->DrawTextInRect(pFontSmallnum, v5 + 25, 0x103u, 0, pSavegameHeader[uLoadGameUI_SelectedSlot].pName, 185, 0); 346 pGUIWindow_CurrentMenu->DrawTextInRect(pFontSmallnum, text_pos + 25, 259, 0, pSavegameHeader[uLoadGameUI_SelectedSlot].pName, 185, 0);
338 v6 = pFontSmallnum->AlignText_Center(0xBA, pGlobalTXT_LocalizationStrings[165]); 347 text_pos = pFontSmallnum->AlignText_Center(186, pGlobalTXT_LocalizationStrings[165]);
339 pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, v6 + 25, 299, 0, pGlobalTXT_LocalizationStrings[165], 0, 0, 0); //Пожалуйста, подождите 348 pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, text_pos + 25, 299, 0, pGlobalTXT_LocalizationStrings[165], 0, 0, 0); //Пожалуйста, подождите
340 pRenderer->Present(); 349 pRenderer->Present();
341 } 350 }
342 351
343 if (pNew_LOD->Write(&pDir, DstBuf, 0)) 352 if (pNew_LOD->Write(&pLodDirectory, uncompressed_buff, 0))
344 { 353 {
345 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 200); //Сохраненная игра повреждена! Code=%d 354 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 200); //Сохраненная игра повреждена! Code=%d
346 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:773", 0); 355 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:773", 0);
347 } 356 }
348 357
350 memset(header.pName, 0, 20); 359 memset(header.pName, 0, 20);
351 memset(header.pLocationName, 0, 20); 360 memset(header.pLocationName, 0, 20);
352 memset(header.field_30, 0, 52); 361 memset(header.field_30, 0, 52);
353 strcpy(header.pLocationName, pCurrentMapName); 362 strcpy(header.pLocationName, pCurrentMapName);
354 header.uWordTime = pParty->uTimePlayed; 363 header.uWordTime = pParty->uTimePlayed;
355 strcpy(pDir.pFilename, "header.bin"); 364 strcpy(pLodDirectory.pFilename, "header.bin");
356 pDir.uDataSize = sizeof(SavegameHeader); 365 pLodDirectory.uDataSize = sizeof(SavegameHeader);
357 if (pNew_LOD->Write(&pDir, &header, 0)) 366 if (pNew_LOD->Write(&pLodDirectory, &header, 0))
358 { 367 {
359 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 201); 368 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 201);
360 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:784", 0); 369 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:784", 0);
361 } 370 }
362 strcpy(pDir.pFilename, "party.bin"); 371 strcpy(pLodDirectory.pFilename, "party.bin");
363 pDir.uDataSize = 90680; 372 pLodDirectory.uDataSize = sizeof(Party); //90680;
364 if ( pNew_LOD->Write(&pDir, pParty, 0) ) 373 if ( pNew_LOD->Write(&pLodDirectory, pParty, 0) )
365 { 374 {
366 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 202); 375 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 202);
367 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:793", 0); 376 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:793", 0);
368 } 377 }
369 strcpy(pDir.pFilename, "clock.bin"); 378 strcpy(pLodDirectory.pFilename, "clock.bin");
370 pDir.uDataSize = 40; 379 pLodDirectory.uDataSize =sizeof(Timer);// 40;
371 if ( pNew_LOD->Write(&pDir, pEventTimer, 0) ) 380 if ( pNew_LOD->Write(&pLodDirectory, pEventTimer, 0) )
372 { 381 {
373 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 203); 382 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 203);
374 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:802", 0); 383 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:802", 0);
375 } 384 }
376 strcpy(pDir.pFilename, "overlay.bin"); 385 strcpy(pLodDirectory.pFilename, "overlay.bin");
377 pDir.uDataSize = 1008; 386 pLodDirectory.uDataSize =sizeof(OtherOverlayList);// 1008;
378 if ( pNew_LOD->Write(&pDir, pOtherOverlayList, 0) ) 387 if ( pNew_LOD->Write(&pLodDirectory, pOtherOverlayList, 0) )
379 { 388 {
380 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 204); 389 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 204);
381 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:811", 0); 390 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:811", 0);
382 } 391 }
383 strcpy(pDir.pFilename, "npcdata.bin"); 392 strcpy(pLodDirectory.pFilename, "npcdata.bin");
384 pDir.uDataSize = 501 * sizeof(NPCData); 393 pLodDirectory.uDataSize = 501 * sizeof(NPCData);
385 assert(pDir.uDataSize == 38076); 394 assert(pLodDirectory.uDataSize == 38076);
386 if ( pNew_LOD->Write(&pDir, pNPCStats->pNewNPCData, 0) ) 395 if ( pNew_LOD->Write(&pLodDirectory, pNPCStats->pNewNPCData, 0) )
387 { 396 {
388 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 205); 397 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 205);
389 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:820", 0); 398 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:820", 0);
390 } 399 }
391 strcpy(pDir.pFilename, "npcgroup.bin"); 400 strcpy(pLodDirectory.pFilename, "npcgroup.bin");
392 pDir.uDataSize = 102; 401 pLodDirectory.uDataSize = 102;
393 if ( pNew_LOD->Write(&pDir, pNPCStats->pGroups_copy, 0) ) 402 if ( pNew_LOD->Write(&pLodDirectory, pNPCStats->pGroups_copy, 0) )
394 { 403 {
395 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 206); 404 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 206);
396 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:829", 0); 405 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:829", 0);
397 } 406 }
398 for (int i = 1; i <= 4; ++i) // 4 - players 407 for (int i = 1; i <= 4; ++i) // 4 - players
404 if ( v8 ) 413 if ( v8 )
405 { 414 {
406 __debugbreak(); 415 __debugbreak();
407 sprintf(Str, "lloyd%d%d.pcx", i, j); 416 sprintf(Str, "lloyd%d%d.pcx", i, j);
408 fseek(v8, 0, 2); 417 fseek(v8, 0, 2);
409 pDir.uDataSize = ftell(v8); 418 pLodDirectory.uDataSize = ftell(v8);
410 rewind(v8); 419 rewind(v8);
411 fread(DstBuf, pDir.uDataSize, 1, v8); 420 fread(uncompressed_buff, pLodDirectory.uDataSize, 1, v8);
412 strcpy((char *)&pDir, Str); 421 strcpy((char *)&pLodDirectory, Str);
413 fclose(v8); 422 fclose(v8);
414 remove(Str); 423 remove(Str);
415 if ( pNew_LOD->Write(&pDir, DstBuf, 0) ) 424 if ( pNew_LOD->Write(&pLodDirectory, uncompressed_buff, 0) )
416 { 425 {
417 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 207); 426 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 207);
418 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:857", 0); 427 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:857", 0);
419 Size = 5080748; 428 Size = 5080748;
420 } 429 }
421 } 430 }
422 } 431 }
423 } 432 }
424 if ( !a2 ) 433 if ( !NotSaveWorld )
425 { 434 {
426 //__debugbreak(); 435 //__debugbreak();
427 sub_42FA22_mess_with_laying_item_list(); 436 CompactLayingItemsList();
428 v9 = (int)malloc(0xF4240); 437 compressed_buf = (char*)malloc(1000000);
429 v71 = (std::string *)v9; 438 // v71 = (std::string *)compressed_buf;
430 Src = 91969; 439 Src.Signature = 91969;
431 v56 = 109; 440 Src.txt_ver[0] = 'm';
432 v57 = 118; 441 Src.txt_ver[1] = 'v';
433 v58 = 105; 442 Src.txt_ver[2] = 'i';
434 v59 = 105; 443 Src.txt_ver[3] = 'i';
435 v60 = 0; 444 Src.compressed_size = 0;
436 v61 = 0; 445 Src.uncompressed_size = 0;
437 memcpy((void *)v9, &Src, 0x10); 446 data_write_pos = uncompressed_buff;
447 memcpy((void *)compressed_buf, &Src, 0x10);
438 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) 448 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
439 { 449 {
440 pIndoor->dlv.uNumFacesInBModels = pIndoor->uNumFaces; 450 pIndoor->dlv.uNumFacesInBModels = pIndoor->uNumFaces;
441 pIndoor->dlv.uNumBModels = 0; 451 pIndoor->dlv.uNumBModels = 0;
442 pIndoor->dlv.uNumDecorations = uNumLevelDecorations; 452 pIndoor->dlv.uNumDecorations = uNumLevelDecorations;
443 memcpy(DstBuf, &pIndoor->dlv, 0x28); 453 memcpy(data_write_pos, &pIndoor->dlv, 0x28);
444 v10 = (char *)DstBuf + 40; 454 data_write_pos += 40;
445 memcpy(v10, pIndoor->_visible_outlines, 0x36B); 455 memcpy(data_write_pos, pIndoor->_visible_outlines, 0x36B);
446 v11 = (char *)v10 + 875; 456 data_write_pos += 875;
447 if ( (signed int)pIndoor->uNumFaces > 0 ) 457
448 { 458 for (int i = 0; i <(signed int)pIndoor->uNumFaces; ++i)
449 v68 = 0; 459 {
450 for (int i = 0; i <= (signed int)pIndoor->uNumFaces; ++i) 460 memcpy(data_write_pos, &pIndoor->pFaces[i].uAttributes, 4);
451 { 461 data_write_pos += 4;
452 v38 = &pIndoor->pFaces[i].uAttributes;//(char *)v68 + (unsigned int)pIndoor->pFaces + 44; 462 }
453 memcpy(v11, v38, 4); 463
454 v68 += 48; 464 for (int i = 0; i <(signed int)uNumLevelDecorations; ++i)
455 v11 = (char *)v11 + 4; 465 {
456 } 466 memcpy(data_write_pos, &pLevelDecorations[i].field_2, 2);
457 } 467
458 if ( (signed int)uNumLevelDecorations > 0 ) 468 data_write_pos+= 2;
459 { 469 }
460 v68 = &pLevelDecorations[0].field_2; 470 memcpy(data_write_pos, &uNumActors, 4);
461 for (int i = 0; i <= (signed int)uNumLevelDecorations; ++i) 471 data_write_pos += 4;
462 { 472 memcpy(data_write_pos, pActors, 836 * uNumActors);
463 memcpy(v11, v68, 2); 473 data_write_pos += 836 * uNumActors;
464 v68 += 16; 474 memcpy(data_write_pos, &uNumSpriteObjects, 4);
465 v11 = (char *)v11 + 2; 475 data_write_pos += 4;
466 } 476 memcpy(data_write_pos, pSpriteObjects, 112 * uNumSpriteObjects);
467 } 477 data_write_pos += 112 * uNumSpriteObjects;
468 memcpy(v11, &uNumActors, 4); 478 memcpy(data_write_pos, &uNumChests, 4);
469 v12 = (char *)v11 + 4; 479 data_write_pos += 4;
470 memcpy(v12, pActors, 836 * uNumActors); 480 memcpy(data_write_pos, pChests, 5324 * uNumChests);
471 v13 = (char *)v12 + 836 * uNumActors; 481 data_write_pos += 5324 * uNumChests;
472 memcpy(v13, &uNumSpriteObjects, 4); 482 memcpy(data_write_pos, pIndoor->pDoors, 0x3E80);
473 v13 = (char *)v13 + 4; 483 data_write_pos += 16000;
474 memcpy(v13, pSpriteObjects, 112 * uNumSpriteObjects); 484 memcpy(data_write_pos, pIndoor->ptr_0002B4_doors_ddata, pIndoor->blv.uDoors_ddata_Size);
475 v14 = (char *)v13 + 112 * uNumSpriteObjects; 485 data_write_pos += pIndoor->blv.uDoors_ddata_Size;
476 memcpy(v14, &uNumChests, 4); 486 memcpy(data_write_pos, &stru_5E4C90, 0xC8);
477 v14 = (char *)v14 + 4; 487 data_write_pos += 200;
478 memcpy(v14, pChests, 5324 * uNumChests); 488 memcpy(data_write_pos, &pIndoor->stru1, 0x38);
479 v15 = (char *)v14 + 5324 * uNumChests; 489 data_write_pos += 56;
480 memcpy(v15, pIndoor->pDoors, 0x3E80); 490
481 v15 = (char *)v15 + 16000;
482 memcpy(v15, pIndoor->ptr_0002B4_doors_ddata, pIndoor->blv.uDoors_ddata_Size);
483 v16 = (char *)v15 + pIndoor->blv.uDoors_ddata_Size;
484 memcpy(v16, &stru_5E4C90, 0xC8);
485 v17 = (int)((char *)v16 + 200);
486 memcpy((void *)v17, &pIndoor->stru1, 0x38);
487 } 491 }
488 else 492 else
489 { 493 {
490 v18 = 0; 494 v18 = 0;
491 pOutdoor->ddm.uNumFacesInBModels = 0; 495 pOutdoor->ddm.uNumFacesInBModels = 0;
492 if ( (signed int)pOutdoor->uNumBModels > 0 ) 496 for (int i=0; i<pOutdoor->uNumBModels;++i)
493 { 497 {
494 v19 = pOutdoor->uNumBModels; 498 v18 +=pOutdoor->pBModels[i].uNumFaces;
495 v20 = &pOutdoor->pBModels[0]; 499 }
496 do 500 pOutdoor->ddm.uNumFacesInBModels = v18;
497 {
498 v18 += v20->uNumFaces;
499 ++v20;
500 --v19;
501 pOutdoor->ddm.uNumFacesInBModels = v18;
502 }
503 while ( v19 );
504 }
505 v21 = DstBuf;
506 pOutdoor->ddm.uNumBModels = pOutdoor->uNumBModels; 501 pOutdoor->ddm.uNumBModels = pOutdoor->uNumBModels;
507 pOutdoor->ddm.uNumDecorations = uNumLevelDecorations; 502 pOutdoor->ddm.uNumDecorations = uNumLevelDecorations;
508 memcpy(DstBuf, &pOutdoor->ddm, 0x28); 503 memcpy(data_write_pos, &pOutdoor->ddm, sizeof(DDM_DLV_Header));//0x28
509 v21 = (char *)v21 + 40; 504 data_write_pos += sizeof(DDM_DLV_Header);
510 memcpy(v21, pOutdoor->uUndiscoveredArea, 0x3C8); 505 memcpy(data_write_pos, pOutdoor->uUndiscoveredArea, 0x3C8);
511 v21 = (char *)v21 + 968; 506 data_write_pos += 968;
512 memcpy(v21, pOutdoor->uDicovered_area, 0x3C8); 507 memcpy(data_write_pos, pOutdoor->uDicovered_area, 0x3C8);
513 v22 = (char *)v21 + 968; 508 data_write_pos += 968;
514 if ( (signed int)pOutdoor->uNumBModels > 0 ) 509 if ( (signed int)pOutdoor->uNumBModels > 0 )
515 { 510 {
516 v23 = pOutdoor->pBModels; 511 v23 = pOutdoor->pBModels;
517 v24 = 76; 512 v24 = 76;
518 for (int i = 0; i < (signed int)pOutdoor->uNumBModels ; ++i) 513 for (int i = 0; i < (signed int)pOutdoor->uNumBModels ; ++i)
519 { 514 {
520 v25 = v23[i].uNumFaces == 0;//*(int *)&v23->pModelName[v24] == 0; 515 //v25 = v23[i].uNumFaces == 0;//*(int *)&v23->pModelName[v24] == 0;
521 v26 = v23[i].uNumFaces < 0;//*(int *)&v23->pModelName[v24] < 0; 516 // v26 = v23[i].uNumFaces < 0;//*(int *)&v23->pModelName[v24] < 0;
522 if ( !(v26 | v25) ) 517 if ( pOutdoor->pBModels[i].uNumFaces>0)
523 { 518 {
524 v68 = 0; 519 v68 = 0;
525 for (int j = 0; j < pOutdoor->pBModels[i].uNumFaces;++j)//*(int *)&pOutdoor->pBModels->pModelName[v24]; ++j) 520 for (int j = 0; j < pOutdoor->pBModels[i].uNumFaces;++j)//*(int *)&pOutdoor->pBModels->pModelName[v24]; ++j)
526 { 521 {
527 v38 = &(v23[i].pFaces[j].uAttributes); //(char *)v68 + *(int *)&v23->pModelName[v24 + 8] + 28; 522 v38 = &(v23[i].pFaces[j].uAttributes); //(char *)v68 + *(int *)&v23->pModelName[v24 + 8] + 28;
528 memcpy(v22, v38, 4); 523 memcpy(data_write_pos, v38, 4);
529 v23 = pOutdoor->pBModels; 524 v23 = pOutdoor->pBModels;
530 v68 += 154; 525 v68 += 154;
531 v22 = (char *)v22 + 4; 526 data_write_pos += 4;
532 } 527 }
533 } 528 }
534 v24 += 188; 529 v24 += 188;
535 } 530 }
536 } 531 }
537 if ( (signed int)uNumLevelDecorations > 0 ) 532 if ( (signed int)uNumLevelDecorations > 0 )
538 { 533 {
539 v66 = &pLevelDecorations[0].field_2; 534 v66 = &pLevelDecorations[0].field_2;
540 for (int i = 0; i <= (signed int)uNumLevelDecorations; ++i) 535 for (int i = 0; i <= (signed int)uNumLevelDecorations; ++i)
541 { 536 {
542 memcpy(v22, v66, 2); 537 memcpy(data_write_pos, v66, 2);
543 v66 += 16; 538 v66 += 16;
544 v22 = (char *)v22 + 2; 539 data_write_pos += 2;
545 } 540 }
546 } 541 }
547 memcpy(v22, &uNumActors, 4); 542 memcpy(data_write_pos, &uNumActors, 4);
548 v28 = (char *)v22 + 4; 543 data_write_pos += 4;
549 memcpy(v28, pActors, 836 * uNumActors); 544 memcpy(data_write_pos, pActors, 836 * uNumActors);
550 v29 = (char *)v28 + 836 * uNumActors; 545 data_write_pos += 836 * uNumActors;
551 memcpy(v29, &uNumSpriteObjects, 4); 546 memcpy(data_write_pos, &uNumSpriteObjects, 4);
552 v29 = (char *)v29 + 4; 547 data_write_pos += 4;
553 memcpy(v29, pSpriteObjects, 112 * uNumSpriteObjects); 548 memcpy(data_write_pos, pSpriteObjects, 112 * uNumSpriteObjects);
554 v30 = (char *)v29 + 112 * uNumSpriteObjects; 549 data_write_pos += 112 * uNumSpriteObjects;
555 memcpy(v30, &uNumChests, 4); 550 memcpy(data_write_pos, &uNumChests, 4);
556 v30 = (char *)v30 + 4; 551 data_write_pos += 4;
557 memcpy(v30, pChests, 5324 * uNumChests); 552 memcpy(data_write_pos, pChests, 5324 * uNumChests);
558 v31 = (char *)v30 + 5324 * uNumChests; 553 data_write_pos += 5324 * uNumChests;
559 memcpy(v31, &stru_5E4C90, 0xC8); 554 memcpy(data_write_pos, &stru_5E4C90, 0xC8);
560 v17 = (int)((char *)v31 + 200); 555 data_write_pos += 200;
561 memcpy((void *)v17, &pOutdoor->uLastVisitDay, 0x38); 556 memcpy(data_write_pos, &pOutdoor->loc_time, 0x38);
562 v9 = (int)v71; 557 data_write_pos += 56;
563 } 558
564 v32 = v17 + 56; 559 //compressed_buf = (int)v71;
560 }
565 strcpy(Source, pCurrentMapName); 561 strcpy(Source, pCurrentMapName);
566 _splitpath(Source, Drive, Dir, Filename, Ext); 562 _splitpath(Source, Drive, Dir, Filename, Ext);
567 v48 = 100; 563 v48 = 100;
568 Size = v32 - (int)DstBuf; 564 Size = (int)data_write_pos - (int)uncompressed_buff;
569 v69 = 999984; 565 compressed_block_size = 999984;
570 LOBYTE(v33) = zlib::MemZip((char *)v9 + 16, (unsigned int *)&v69, DstBuf, v32 - (int)DstBuf); 566 LOBYTE(v33) = zlib::MemZip((char *)compressed_buf + 16, (unsigned int *)&compressed_block_size, uncompressed_buff,Size);
571 if ( v33 || (signed int)v69 > (signed int)Size ) 567 if ( v33 || (signed int)compressed_block_size > (signed int)Size )
572 { 568 {
573 memcpy((void *)(v9 + 16), DstBuf, Size); 569 memcpy((void *)(compressed_buf + 16), uncompressed_buff, Size);
574 v69 = Size; 570 compressed_block_size = Size;
575 } 571 }
576 v69 += 16; 572 compressed_block_size += 16;
577 memcpy((void *)(v9 + 8), &v69, 4); 573 memcpy(&((SaveDataHeader *)compressed_buf)->compressed_size, &compressed_block_size, 4);
578 memcpy((void *)(v9 + 12), &Size, 4); 574 memcpy(&((SaveDataHeader *)compressed_buf)->uncompressed_size, &Size, 4);
579 sprintf(Source, "%s%s", &Filename, &Ext); 575 sprintf(Source, "%s%s", &Filename, &Ext);
580 strcpy((char *)&pDir, Source); 576 strcpy((char *)&pLodDirectory, Source);
581 pDir.uDataSize = v69; 577 pLodDirectory.uDataSize = compressed_block_size;
582 if ( pNew_LOD->Write(&pDir, (const void *)v9, 0) ) 578 if ( pNew_LOD->Write(&pLodDirectory, (const void *)compressed_buf, 0) )
583 { 579 {
584 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 208); 580 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 208);
585 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:1071", 0); 581 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:1071", 0);
586 } 582 }
587 free((void *)v9); 583 free((void *)compressed_buf);
588 } 584 }
589 free(DstBuf); 585 free(uncompressed_buff);
590 if ( a1 ) 586 if ( IsAutoSAve )
591 { 587 {
592 if ( !CopyFileA("data\\new.lod", "saves\\autosave.mm7", 0) ) 588 if ( !CopyFileA("data\\new.lod", "saves\\autosave.mm7", 0) )
593 { 589 {
594 v34 = GetLastError(); 590 v34 = GetLastError();
595 FormatMessageA(0x1000, 0, v34, 0x400, &Buffer, 0x80, 0); 591 FormatMessageA(0x1000, 0, v34, 0x400, &Buffer, 0x80, 0);
600 pParty->vPosition.x = pPositionX; 596 pParty->vPosition.x = pPositionX;
601 pParty->vPosition.y = v51; 597 pParty->vPosition.y = v51;
602 pParty->vPosition.z = v62; 598 pParty->vPosition.z = v62;
603 pParty->uFallStartY = v62; 599 pParty->uFallStartY = v62;
604 pParty->sRotationY = v53; 600 pParty->sRotationY = v53;
605 result = v54;
606 pParty->sRotationX = v54; 601 pParty->sRotationX = v54;
607 return result;
608 } 602 }
609 603
610 604
611 //----- (00460078) -------------------------------------------------------- 605 //----- (00460078) --------------------------------------------------------
612 void __fastcall DoSavegame(unsigned int uSlot) 606 void __fastcall DoSavegame(unsigned int uSlot)