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