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