Mercurial > mm7
annotate SaveLoad.cpp @ 2161:86c9c8e207d5
remove TestClass.h
author | Ritor1 |
---|---|
date | Mon, 13 Jan 2014 17:32:00 +0600 |
parents | 9bd7522cdbbb |
children | daa61976637d |
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 | |
764 | 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); | |
1980 | 97 FILE *f = pNew_LOD->FindContainer("header.bin", 1); |
0 | 98 if (!f) |
99 { | |
100 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 100); | |
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); |
0 | 105 fread(&header, sizeof(SavegameHeader), 1, f); |
106 | |
107 f = pNew_LOD->FindContainer("party.bin", 1); | |
108 if (!f) | |
109 { | |
110 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 101); | |
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"); | |
116 fread(pParty, 0x16238u, 1, f); | |
117 | |
118 | |
119 f = pNew_LOD->FindContainer("clock.bin", 1); | |
120 if (!f) | |
121 { | |
122 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 102); | |
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"); | |
128 fread(pEventTimer, 0x28u, 1u, f); | |
129 | |
130 f = pNew_LOD->FindContainer("overlay.bin", 1); | |
131 if (!f) | |
132 { | |
133 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 103); | |
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"); | |
139 fread(pOtherOverlayList, 0x3F0, 1, f); | |
140 | |
141 f = pNew_LOD->FindContainer("npcdata.bin", 0); | |
142 if (!f) | |
143 { | |
144 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 104); | |
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"); | |
150 fread(pNPCStats->pNewNPCData, 0x94BC, 1, f); | |
151 pNPCStats->_476C60(); | |
152 | |
153 f = pNew_LOD->FindContainer("npcgroup.bin", 0); | |
154 if (!f) | |
155 { | |
156 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 105); | |
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"); | |
162 fread(pNPCStats->pGroups_copy, 0x66, 1, f); | |
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; |
0 | 185 if (pItemsTable->pItems[uItemID].uEquipType == 12) |
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 | |
196 pGUIWindow_CurrentMenu->Release(); | |
151 | 197 pCurrentScreen = SCREEN_GAME; |
0 | 198 |
199 viewparams->bRedrawGameUI = true; | |
200 | |
373 | 201 SetUserInterface(pParty->alignment, true); |
0 | 202 |
203 pEventTimer->Resume(); | |
204 pEventTimer->StopGameTime(); | |
205 | |
206 v25 = pGames_LOD->DoesContainerExist(header.pLocationName); | |
1205
8c02e6f74b29
arrays to std::arrays phase 2 - mm7_data.h converted
Grumpy7
parents:
1202
diff
changeset
|
207 sprintf(pTmpBuf.data(), "levels\\%s", header.pLocationName); |
8c02e6f74b29
arrays to std::arrays phase 2 - mm7_data.h converted
Grumpy7
parents:
1202
diff
changeset
|
208 v26 = _access(pTmpBuf.data(), 4) != -1; |
0 | 209 if ( !v25 && !v26 ) |
1545 | 210 Error("Unable to find: %s!", header.pLocationName); |
0 | 211 |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
212 strcpy(pCurrentMapName, header.pLocationName); |
2061 | 213 dword_6BE364_game_settings_1 |= GAME_SETTINGS_2000 | GAME_SETTINGS_0001; |
0 | 214 |
215 for (uint i = 0; i < uNumSavegameFiles; ++i) | |
216 pSavegameThumbnails[i].Release(); | |
217 | |
1405
c0b273d33338
RemoveTexturesPackFromTextureList and RemoveTexturesFromTextureList
Ritor1
parents:
1404
diff
changeset
|
218 pIcons_LOD->RemoveTexturesPackFromTextureList(); |
328 | 219 pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f); |
220 pAudioPlayer->SetMasterVolume(pSoundVolumeLevels[uSoundVolumeMultiplier] * 128.0f); | |
0 | 221 if (uTurnSpeed) |
222 pParty->sRotationY = uTurnSpeed * pParty->sRotationY / (signed int)uTurnSpeed; | |
223 MM7Initialization(); | |
224 bFlashQuestBook = false; | |
225 viewparams->bRedrawGameUI = true; | |
226 } | |
227 | |
228 | |
229 //----- (0045F469) -------------------------------------------------------- | |
810 | 230 void SaveGame( bool IsAutoSAve, bool NotSaveWorld ) |
982 | 231 { |
2154 | 232 //unsigned short *pScreenshot; // edi@5 |
810 | 233 int text_pos; // eax@6 |
847 | 234 FILE *pLLoidFile; // edi@24 |
810 | 235 char* compressed_buf; // edi@30 |
236 char *data_write_pos; // esi@41 | |
847 | 237 CHAR Buffer[128]; // [sp+Ch] [bp-264h]@59 |
79 | 238 char Dir[255]; // [sp+8Ch] [bp-1E4h]@51 |
239 char Drive[255]; // [sp+ACh] [bp-1C4h]@51 | |
837 | 240 SavegameHeader save_header; // [sp+CCh] [bp-1A4h]@10 |
79 | 241 char Filename[255]; // [sp+130h] [bp-140h]@51 |
242 char Ext[255]; // [sp+150h] [bp-120h]@51 | |
0 | 243 char Source[32]; // [sp+170h] [bp-100h]@51 |
847 | 244 char work_string[120]; // [sp+190h] [bp-E0h]@8 |
245 int pPositionY; // [sp+208h] [bp-68h]@2 | |
0 | 246 int pPositionX; // [sp+20Ch] [bp-64h]@2 |
847 | 247 int sPRotationY; // [sp+210h] [bp-60h]@2 |
248 int sPRotationX; // [sp+214h] [bp-5Ch]@2 | |
837 | 249 ODMHeader odm_data; // [sp+218h] [bp-58h]@30 |
847 | 250 int res; // [sp+224h] [bp-4Ch]@30 |
251 int pPositionZ; // [sp+228h] [bp-48h]@2 | |
0 | 252 size_t Size; // [sp+250h] [bp-20h]@26 |
810 | 253 char *uncompressed_buff; // [sp+258h] [bp-18h]@2 |
254 unsigned int compressed_block_size; // [sp+260h] [bp-10h]@23 | |
847 | 255 |
568 | 256 //v66 = a2; |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
257 strcpy(byte_6BE3B0.data(), pCurrentMapName); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
258 if (!_stricmp(pCurrentMapName, "d05.blv")) // arena |
810 | 259 return; |
568 | 260 |
810 | 261 uncompressed_buff = (char*)malloc(1000000); |
982 | 262 |
263 LOD::Directory pLodDirectory; // [sp+22Ch] [bp-44h]@2 | |
0 | 264 pPositionX = pParty->vPosition.x; |
847 | 265 pPositionY = pParty->vPosition.y; |
266 pPositionZ = pParty->vPosition.z; | |
267 sPRotationY = pParty->sRotationY; | |
268 sPRotationX = pParty->sRotationX; | |
0 | 269 pParty->vPosition.x = pParty->vPrevPosition.x; |
847 | 270 pParty->vPosition.z = pParty->vPrevPosition.z; |
271 pParty->vPosition.y = pParty->vPrevPosition.y; | |
272 | |
273 pParty->uFallStartY = pParty->vPrevPosition.z; | |
274 | |
0 | 275 pParty->sRotationY = pParty->sPrevRotationY; |
276 pParty->sRotationX = pParty->sPrevRotationX; | |
277 if (uCurrentlyLoadedLevelType == LEVEL_Indoor) | |
278 pIndoor->stru1.uLastVisitDay = pParty->uTimePlayed; | |
279 else | |
810 | 280 pOutdoor->loc_time.uLastVisitDay = pParty->uTimePlayed; |
2154 | 281 |
282 pRenderer->PackScreenshot(150, 112, uncompressed_buff, 1000000, &pLodDirectory.uDataSize); | |
810 | 283 strcpy(pLodDirectory.pFilename, "image.pcx"); |
2154 | 284 |
151 | 285 if (pCurrentScreen == SCREEN_SAVEGAME) |
0 | 286 { |
568 | 287 pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->GetTexture(uTextureID_loadsave)); |
288 pRenderer->DrawTextureIndexed(18, 141, pIcons_LOD->GetTexture(uTextureID_save_up)); | |
810 | 289 text_pos = pFontSmallnum->AlignText_Center(186, pGlobalTXT_LocalizationStrings[190]); |
290 pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, text_pos + 25, 219, 0, pGlobalTXT_LocalizationStrings[190], 0, 0, 0); //Ñîõðàíåíèå | |
291 text_pos = pFontSmallnum->AlignText_Center(186, pSavegameHeader[uLoadGameUI_SelectedSlot].pName); | |
292 pGUIWindow_CurrentMenu->DrawTextInRect(pFontSmallnum, text_pos + 25, 259, 0, pSavegameHeader[uLoadGameUI_SelectedSlot].pName, 185, 0); | |
293 text_pos = pFontSmallnum->AlignText_Center(186, pGlobalTXT_LocalizationStrings[165]); | |
294 pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, text_pos + 25, 299, 0, pGlobalTXT_LocalizationStrings[165], 0, 0, 0); //Ïîæàëóéñòà, ïîäîæäèòå | |
0 | 295 pRenderer->Present(); |
568 | 296 } |
297 | |
810 | 298 if (pNew_LOD->Write(&pLodDirectory, uncompressed_buff, 0)) |
0 | 299 { |
847 | 300 sprintf(work_string, pGlobalTXT_LocalizationStrings[612], 200); //Ñîõðàíåííàÿ èãðà ïîâðåæäåíà! Code=%d |
301 MessageBoxA(nullptr, work_string, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:773", 0); | |
0 | 302 } |
303 | |
1545 | 304 Assert(sizeof(SavegameHeader) == 100); |
837 | 305 memset(save_header.pName, 0, 20); |
306 memset(save_header.pLocationName, 0, 20); | |
307 memset(save_header.field_30, 0, 52); | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
308 strcpy(save_header.pLocationName, pCurrentMapName); |
837 | 309 save_header.uWordTime = pParty->uTimePlayed; |
810 | 310 strcpy(pLodDirectory.pFilename, "header.bin"); |
311 pLodDirectory.uDataSize = sizeof(SavegameHeader); | |
837 | 312 if (pNew_LOD->Write(&pLodDirectory, &save_header, 0)) |
0 | 313 { |
847 | 314 sprintf(work_string, pGlobalTXT_LocalizationStrings[612], 201); |
315 MessageBoxA(nullptr, work_string, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:784", 0); | |
0 | 316 } |
810 | 317 strcpy(pLodDirectory.pFilename, "party.bin"); |
318 pLodDirectory.uDataSize = sizeof(Party); //90680; | |
319 if ( pNew_LOD->Write(&pLodDirectory, pParty, 0) ) | |
0 | 320 { |
2127 | 321 sprintf(work_string, pGlobalTXT_LocalizationStrings[612], 202);//Save game corrupted! Code=%d |
847 | 322 MessageBoxA(nullptr, work_string, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:793", 0); |
0 | 323 } |
810 | 324 strcpy(pLodDirectory.pFilename, "clock.bin"); |
325 pLodDirectory.uDataSize =sizeof(Timer);// 40; | |
326 if ( pNew_LOD->Write(&pLodDirectory, pEventTimer, 0) ) | |
0 | 327 { |
847 | 328 sprintf(work_string, pGlobalTXT_LocalizationStrings[612], 203); |
329 MessageBoxA(nullptr, work_string, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:802", 0); | |
0 | 330 } |
810 | 331 strcpy(pLodDirectory.pFilename, "overlay.bin"); |
332 pLodDirectory.uDataSize =sizeof(OtherOverlayList);// 1008; | |
333 if ( pNew_LOD->Write(&pLodDirectory, pOtherOverlayList, 0) ) | |
0 | 334 { |
847 | 335 sprintf(work_string, pGlobalTXT_LocalizationStrings[612], 204); |
336 MessageBoxA(nullptr, work_string, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:811", 0); | |
0 | 337 } |
810 | 338 strcpy(pLodDirectory.pFilename, "npcdata.bin"); |
339 pLodDirectory.uDataSize = 501 * sizeof(NPCData); | |
1545 | 340 Assert(pLodDirectory.uDataSize == 38076); |
810 | 341 if ( pNew_LOD->Write(&pLodDirectory, pNPCStats->pNewNPCData, 0) ) |
0 | 342 { |
847 | 343 sprintf(work_string, pGlobalTXT_LocalizationStrings[612], 205); |
344 MessageBoxA(nullptr, work_string, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:820", 0); | |
0 | 345 } |
810 | 346 strcpy(pLodDirectory.pFilename, "npcgroup.bin"); |
347 pLodDirectory.uDataSize = 102; | |
348 if ( pNew_LOD->Write(&pLodDirectory, pNPCStats->pGroups_copy, 0) ) | |
0 | 349 { |
847 | 350 sprintf(work_string, pGlobalTXT_LocalizationStrings[612], 206); |
351 MessageBoxA(nullptr, work_string, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:829", 0); | |
0 | 352 } |
353 for (int i = 1; i <= 4; ++i) // 4 - players | |
354 { | |
355 for (int j = 1; j <= 5; ++j) // 5 - images | |
356 { | |
847 | 357 sprintf(work_string, "data\\lloyd%d%d.pcx", i, j); |
358 pLLoidFile = fopen(work_string, "rb"); | |
359 if ( pLLoidFile ) | |
0 | 360 { |
361 __debugbreak(); | |
847 | 362 sprintf(work_string, "lloyd%d%d.pcx", i, j); |
363 fseek(pLLoidFile, 0, SEEK_END); | |
364 pLodDirectory.uDataSize = ftell(pLLoidFile); | |
365 rewind(pLLoidFile); | |
366 fread(uncompressed_buff, pLodDirectory.uDataSize, 1, pLLoidFile); | |
367 strcpy(pLodDirectory.pFilename, work_string); | |
368 fclose(pLLoidFile); | |
369 remove(work_string); | |
810 | 370 if ( pNew_LOD->Write(&pLodDirectory, uncompressed_buff, 0) ) |
0 | 371 { |
847 | 372 sprintf(work_string, pGlobalTXT_LocalizationStrings[612], 207); |
373 MessageBoxA(nullptr, work_string, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:857", 0); | |
0 | 374 Size = 5080748; |
375 } | |
376 } | |
377 } | |
378 } | |
2124 | 379 if ( !NotSaveWorld )//autosave for change location |
0 | 380 { |
79 | 381 //__debugbreak(); |
810 | 382 CompactLayingItemsList(); |
383 compressed_buf = (char*)malloc(1000000); | |
837 | 384 odm_data.uVersion = 91969; |
385 odm_data.pMagic[0] = 'm'; | |
386 odm_data.pMagic[1] = 'v'; | |
387 odm_data.pMagic[2] = 'i'; | |
388 odm_data.pMagic[3] = 'i'; | |
389 odm_data.uCompressedSize = 0; | |
390 odm_data.uDecompressedSize = 0; | |
810 | 391 data_write_pos = uncompressed_buff; |
837 | 392 memcpy((void *)compressed_buf, &odm_data, 0x10); |
0 | 393 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) |
394 { | |
395 pIndoor->dlv.uNumFacesInBModels = pIndoor->uNumFaces; | |
396 pIndoor->dlv.uNumBModels = 0; | |
397 pIndoor->dlv.uNumDecorations = uNumLevelDecorations; | |
837 | 398 memcpy(data_write_pos, &pIndoor->dlv,sizeof(DDM_DLV_Header) );//0x28 |
399 data_write_pos += sizeof(DDM_DLV_Header); | |
810 | 400 memcpy(data_write_pos, pIndoor->_visible_outlines, 0x36B); |
401 data_write_pos += 875; | |
402 | |
403 for (int i = 0; i <(signed int)pIndoor->uNumFaces; ++i) | |
0 | 404 { |
810 | 405 memcpy(data_write_pos, &pIndoor->pFaces[i].uAttributes, 4); |
406 data_write_pos += 4; | |
0 | 407 } |
810 | 408 |
409 for (int i = 0; i <(signed int)uNumLevelDecorations; ++i) | |
0 | 410 { |
1489 | 411 memcpy(data_write_pos, &pLevelDecorations[i].uFlags, 2); |
810 | 412 |
413 data_write_pos+= 2; | |
0 | 414 } |
810 | 415 memcpy(data_write_pos, &uNumActors, 4); |
416 data_write_pos += 4; | |
1202 | 417 memcpy(data_write_pos, pActors.data(), 836 * uNumActors); |
810 | 418 data_write_pos += 836 * uNumActors; |
419 memcpy(data_write_pos, &uNumSpriteObjects, 4); | |
420 data_write_pos += 4; | |
1207
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1206
diff
changeset
|
421 memcpy(data_write_pos, pSpriteObjects.data(), 112 * uNumSpriteObjects); |
810 | 422 data_write_pos += 112 * uNumSpriteObjects; |
423 memcpy(data_write_pos, &uNumChests, 4); | |
424 data_write_pos += 4; | |
1202 | 425 memcpy(data_write_pos, pChests.data(), sizeof(Chest)*uNumChests);//5324 * |
847 | 426 data_write_pos += sizeof(Chest)* uNumChests; |
810 | 427 memcpy(data_write_pos, pIndoor->pDoors, 0x3E80); |
428 data_write_pos += 16000; | |
429 memcpy(data_write_pos, pIndoor->ptr_0002B4_doors_ddata, pIndoor->blv.uDoors_ddata_Size); | |
430 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
|
431 memcpy(data_write_pos, &stru_5E4C90_MapPersistVars, 0xC8); |
810 | 432 data_write_pos += 200; |
433 memcpy(data_write_pos, &pIndoor->stru1, 0x38); | |
434 data_write_pos += 56; | |
435 | |
0 | 436 } |
437 else | |
438 { | |
439 pOutdoor->ddm.uNumFacesInBModels = 0; | |
810 | 440 for (int i=0; i<pOutdoor->uNumBModels;++i) |
441 { | |
837 | 442 pOutdoor->ddm.uNumFacesInBModels +=pOutdoor->pBModels[i].uNumFaces; |
810 | 443 } |
0 | 444 pOutdoor->ddm.uNumBModels = pOutdoor->uNumBModels; |
445 pOutdoor->ddm.uNumDecorations = uNumLevelDecorations; | |
810 | 446 memcpy(data_write_pos, &pOutdoor->ddm, sizeof(DDM_DLV_Header));//0x28 |
447 data_write_pos += sizeof(DDM_DLV_Header); | |
448 memcpy(data_write_pos, pOutdoor->uUndiscoveredArea, 0x3C8); | |
449 data_write_pos += 968; | |
450 memcpy(data_write_pos, pOutdoor->uDicovered_area, 0x3C8); | |
451 data_write_pos += 968; | |
837 | 452 for (int i = 0; i < pOutdoor->uNumBModels ; ++i) |
79 | 453 for (int j = 0; j < pOutdoor->pBModels[i].uNumFaces;++j)//*(int *)&pOutdoor->pBModels->pModelName[v24]; ++j) |
837 | 454 { |
455 memcpy(data_write_pos, &(pOutdoor->pBModels[i].pFaces[j].uAttributes), 4); | |
810 | 456 data_write_pos += 4; |
0 | 457 } |
837 | 458 |
1084
5a59b5b2699f
SaveGame "for" cycle fix - orignal disassembly code has "i < uNumLevelDecorations"
Grumpy7
parents:
1016
diff
changeset
|
459 for (int i = 0; i < (signed int)uNumLevelDecorations; ++i) |
0 | 460 { |
1489 | 461 memcpy(data_write_pos, &pLevelDecorations[i].uFlags, 2); |
810 | 462 data_write_pos += 2; |
0 | 463 } |
810 | 464 memcpy(data_write_pos, &uNumActors, 4); |
465 data_write_pos += 4; | |
1202 | 466 memcpy(data_write_pos, pActors.data(), 836 * uNumActors); |
810 | 467 data_write_pos += 836 * uNumActors; |
468 memcpy(data_write_pos, &uNumSpriteObjects, 4); | |
469 data_write_pos += 4; | |
1207
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1206
diff
changeset
|
470 memcpy(data_write_pos, pSpriteObjects.data(), 112 * uNumSpriteObjects); |
810 | 471 data_write_pos += 112 * uNumSpriteObjects; |
472 memcpy(data_write_pos, &uNumChests, 4); | |
473 data_write_pos += 4; | |
1202 | 474 memcpy(data_write_pos, pChests.data(), sizeof(Chest)* uNumChests); |
847 | 475 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
|
476 memcpy(data_write_pos, &stru_5E4C90_MapPersistVars, 0xC8); |
810 | 477 data_write_pos += 200; |
478 memcpy(data_write_pos, &pOutdoor->loc_time, 0x38); | |
479 data_write_pos += 56; | |
0 | 480 } |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
481 strcpy(Source, pCurrentMapName); |
79 | 482 _splitpath(Source, Drive, Dir, Filename, Ext); |
847 | 483 |
810 | 484 Size = (int)data_write_pos - (int)uncompressed_buff; |
485 compressed_block_size = 999984; | |
847 | 486 res = zlib::MemZip((char *)compressed_buf + 16, (unsigned int *)&compressed_block_size, uncompressed_buff,Size); |
487 if (res || (signed int)compressed_block_size > (signed int)Size ) | |
0 | 488 { |
810 | 489 memcpy((void *)(compressed_buf + 16), uncompressed_buff, Size); |
490 compressed_block_size = Size; | |
0 | 491 } |
810 | 492 compressed_block_size += 16; |
814 | 493 memcpy(&((ODMHeader *)compressed_buf)->uCompressedSize, &compressed_block_size, 4); |
494 memcpy(&((ODMHeader *)compressed_buf)->uDecompressedSize, &Size, 4); | |
0 | 495 sprintf(Source, "%s%s", &Filename, &Ext); |
847 | 496 strcpy(pLodDirectory.pFilename, Source); |
810 | 497 pLodDirectory.uDataSize = compressed_block_size; |
498 if ( pNew_LOD->Write(&pLodDirectory, (const void *)compressed_buf, 0) ) | |
0 | 499 { |
847 | 500 sprintf(work_string, pGlobalTXT_LocalizationStrings[612], 208); |
501 MessageBoxA(nullptr, work_string, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:1071", 0); | |
0 | 502 } |
810 | 503 free((void *)compressed_buf); |
0 | 504 } |
810 | 505 free(uncompressed_buff); |
506 if ( IsAutoSAve ) | |
0 | 507 { |
508 if ( !CopyFileA("data\\new.lod", "saves\\autosave.mm7", 0) ) | |
509 { | |
847 | 510 FormatMessageA(0x1000, 0, GetLastError(), 0x400, Buffer, 0x80, 0); |
511 sprintf(work_string, pGlobalTXT_LocalizationStrings[612], 300); | |
512 MessageBoxA(nullptr, work_string, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:1097", 0); | |
0 | 513 } |
514 } | |
515 pParty->vPosition.x = pPositionX; | |
847 | 516 pParty->vPosition.y = pPositionY; |
517 pParty->vPosition.z = pPositionZ; | |
518 pParty->uFallStartY = pPositionZ; | |
519 pParty->sRotationY = sPRotationY; | |
520 pParty->sRotationX = sPRotationX; | |
0 | 521 } |
522 | |
523 | |
524 //----- (00460078) -------------------------------------------------------- | |
525 void __fastcall DoSavegame(unsigned int uSlot) | |
526 { | |
568 | 527 //unsigned int v1; // esi@1 |
528 //int v2; // esi@2 | |
557 | 529 //RGBTexture *v3; // ebx@3 |
0 | 530 int bNotArena; // [sp+2Ch] [bp-8h]@1 |
568 | 531 //unsigned int v6; // [sp+30h] [bp-4h]@1 |
0 | 532 |
165 | 533 //__debugbreak(); |
0 | 534 |
568 | 535 //v1 = uSlot; |
536 //v6 = uSlot; | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
537 bNotArena = _stricmp(pCurrentMapName, "d05.blv"); |
0 | 538 if ( bNotArena ) |
539 { | |
540 LOD::Directory pDir; // [sp+Ch] [bp-28h]@2 | |
541 SaveGame(0, 0); | |
568 | 542 //v2 = 100 * v1; |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
543 strcpy(pSavegameHeader[uSlot].pLocationName, pCurrentMapName); |
568 | 544 pSavegameHeader[uSlot].uWordTime = pParty->uTimePlayed; |
545 strcpy(pDir.pFilename, "header.bin"); | |
0 | 546 pDir.uDataSize = 100; |
568 | 547 pNew_LOD->Write(&pDir, &pSavegameHeader[uSlot], 0); |
1205
8c02e6f74b29
arrays to std::arrays phase 2 - mm7_data.h converted
Grumpy7
parents:
1202
diff
changeset
|
548 sprintf(pTmpBuf.data(), "saves\\save%03d.mm7", uSlot); |
0 | 549 pNew_LOD->CloseWriteFile(); |
1205
8c02e6f74b29
arrays to std::arrays phase 2 - mm7_data.h converted
Grumpy7
parents:
1202
diff
changeset
|
550 CopyFileA("data\\new.lod", pTmpBuf.data(), 0); |
0 | 551 } |
552 GUI_UpdateWindows(); | |
553 pGUIWindow_CurrentMenu->Release(); | |
151 | 554 pCurrentScreen = SCREEN_GAME; |
557 | 555 //v3 = pSavegameThumbnails; |
0 | 556 viewparams->bRedrawGameUI = 1; |
568 | 557 for (uint i = 0; i < 45; i++) |
557 | 558 pSavegameThumbnails[i].Release(); |
2154 | 559 |
0 | 560 if ( bNotArena ) |
561 pNew_LOD->_4621A7(); | |
562 else | |
563 ShowStatusBarString(pGlobalTXT_LocalizationStrings[583], 2u);// "No saving in the Arena" | |
1405
c0b273d33338
RemoveTexturesPackFromTextureList and RemoveTexturesFromTextureList
Ritor1
parents:
1404
diff
changeset
|
564 pIcons_LOD->RemoveTexturesFromTextureList(); |
0 | 565 pEventTimer->Resume(); |
566 ShowStatusBarString(pGlobalTXT_LocalizationStrings[656], 2u);// "Game Saved!" | |
568 | 567 viewparams->bRedrawGameUI = true; |
0 | 568 } |
569 // 4E28F8: using guessed type int pCurrentScreen; | |
570 | |
571 | |
572 | |
573 | |
574 | |
575 | |
576 | |
577 | |
578 | |
579 | |
580 | |
581 //----- (0045E297) -------------------------------------------------------- | |
582 void SavegameList::Initialize(unsigned int bHideEmptySlots) | |
583 { | |
382 | 584 memset(pSavegameList, 0, 0x3138); |
585 // Reset(); | |
4 | 586 uNumSavegameFiles = 0; |
0 | 587 |
588 _chdir("saves"); | |
589 { | |
4 | 590 if (!bHideEmptySlots && _access(pGlobalTXT_LocalizationStrings[613], 0) != -1 ) // AutoSave.MM7 |
382 | 591 strcpy(pSavegameList->pFileList[uNumSavegameFiles++].pSaveFileName, pGlobalTXT_LocalizationStrings[613]); |
0 | 592 |
593 for (uint i = 0; i < 40; ++i) | |
594 { | |
1205
8c02e6f74b29
arrays to std::arrays phase 2 - mm7_data.h converted
Grumpy7
parents:
1202
diff
changeset
|
595 sprintf(pTmpBuf.data(), "save%03d.mm7", i); |
8c02e6f74b29
arrays to std::arrays phase 2 - mm7_data.h converted
Grumpy7
parents:
1202
diff
changeset
|
596 if (_access(pTmpBuf.data(), 0) == -1) |
0 | 597 continue; |
598 | |
599 uint idx = i; | |
600 if (!bHideEmptySlots) | |
601 idx = uNumSavegameFiles; | |
1205
8c02e6f74b29
arrays to std::arrays phase 2 - mm7_data.h converted
Grumpy7
parents:
1202
diff
changeset
|
602 strcpy(pSavegameList->pFileList[idx].pSaveFileName, pTmpBuf.data()); |
0 | 603 |
604 ++uNumSavegameFiles; | |
605 } | |
606 } | |
607 _chdir(".."); | |
1297 | 608 } |
609 //----- (0046086A) -------------------------------------------------------- | |
610 void SaveNewGame() | |
611 { | |
612 FILE *v3; // eax@7 | |
613 void *pSave; // [sp+170h] [bp-8h]@3 | |
614 | |
615 if ( pVideoPlayer->AnyMovieLoaded() ) | |
616 pVideoPlayer->Unload(); | |
1583 | 617 pSave = malloc(1000000); |
1297 | 618 pNew_LOD->CloseWriteFile(); |
619 remove("data\\new.lod"); | |
620 | |
621 LOD::FileHeader this_; // [sp+Ch] [bp-16Ch]@3 | |
622 strcpy(this_.LodVersion, "MMVII"); | |
623 strcpy(this_.LodDescription, "newmaps for MMVII"); | |
624 this_.LODSize = 100; | |
625 this_.dword_0000A8 = 0; | |
626 | |
627 LOD::Directory a3; // [sp+14Ch] [bp-2Ch]@3 | |
628 a3.dword_000018 = 0; | |
629 a3.word_00001E = 0; | |
630 strcpy(a3.pFilename, "current"); | |
631 pNew_LOD->CreateNewLod(&this_, &a3, "data\\new.lod"); | |
632 if (pNew_LOD->LoadFile("data\\new.lod", false)) | |
633 { | |
634 pNew_LOD->CreateTempFile(); | |
635 pNew_LOD->uNumSubDirs = 0; | |
636 | |
637 LOD::Directory pDir; // [sp+10Ch] [bp-6Ch]@4 | |
638 for (int i = pGames_LOD->uNumSubDirs / 2; i < pGames_LOD->uNumSubDirs; ++i) | |
639 { | |
640 memcpy(&pDir, &pGames_LOD->pSubIndices[i], sizeof(pDir)); | |
641 v3 = pGames_LOD->FindContainer(pGames_LOD->pSubIndices[i].pFilename, 1); | |
642 fread(pSave, pGames_LOD->pSubIndices[i].uDataSize, 1, v3); | |
643 pNew_LOD->AppendDirectory(&pDir, pSave); | |
644 } | |
645 | |
646 LOD::Directory save_game_dir; // [sp+12Ch] [bp-4Ch]@9 | |
647 strcpy(pSavegameHeader[0].pLocationName, "out01.odm"); | |
648 strcpy(save_game_dir.pFilename, "header.bin"); | |
649 save_game_dir.uDataSize = sizeof(SavegameHeader); | |
650 pNew_LOD->AppendDirectory(&save_game_dir, &pSavegameHeader[0]); | |
651 | |
652 pNew_LOD->FixDirectoryOffsets(); | |
653 pParty->vPrevPosition.y = 0; | |
654 pParty->vPrevPosition.x = 12552; | |
655 pParty->vPosition.x = 12552; | |
656 pParty->vPosition.z = 0; | |
657 pParty->uFallStartY = 0; | |
658 pParty->sPrevRotationX = 0; | |
659 pParty->sRotationX = 0; | |
660 pParty->vPrevPosition.z = 1816; | |
661 pParty->vPosition.y = 1816; | |
662 pParty->sPrevRotationY = 512; | |
663 pParty->sRotationY = 512; | |
664 SaveGame(1, 1); | |
665 } | |
1583 | 666 free(pSave); |
1297 | 667 } |
668 |