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