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