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