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