annotate SaveLoad.cpp @ 810:f5156b8c61ad

savegame refactoring
author Gloval
date Tue, 26 Mar 2013 00:57:54 +0400
parents 90bcfb56c8f9
children 35122475edd7 cfc65feef029
rev   line source
0
Ritor1
parents:
diff changeset
1 #include <io.h>
Ritor1
parents:
diff changeset
2 #include <direct.h>
Ritor1
parents:
diff changeset
3 #include <assert.h>
Ritor1
parents:
diff changeset
4
Ritor1
parents:
diff changeset
5 #include "SaveLoad.h"
Ritor1
parents:
diff changeset
6 #include "NPC.h"
Ritor1
parents:
diff changeset
7 #include "Party.h"
Ritor1
parents:
diff changeset
8 #include "LOD.h"
Ritor1
parents:
diff changeset
9 #include "Outdoor.h"
Ritor1
parents:
diff changeset
10 #include "AudioPlayer.h"
Ritor1
parents:
diff changeset
11 #include "Actor.h"
Ritor1
parents:
diff changeset
12 #include "Chest.h"
Ritor1
parents:
diff changeset
13 #include "Time.h"
Ritor1
parents:
diff changeset
14 #include "GUIWindow.h"
Ritor1
parents:
diff changeset
15 #include "GUIFont.h"
Ritor1
parents:
diff changeset
16 #include "Overlays.h"
515
cb0ad52d6a26 LayingItem -> SpriteObject (long-waited rename, old name was inaccurate and confused people)
Nomad
parents: 488
diff changeset
17 #include "SpriteObject.h"
0
Ritor1
parents:
diff changeset
18 #include "Viewport.h"
Ritor1
parents:
diff changeset
19 #include "stru123.h"
189
038a4d09406f new texts file, fix text rendender error
Gloval
parents: 165
diff changeset
20 #include "texts.h"
0
Ritor1
parents:
diff changeset
21 #include "Log.h"
Ritor1
parents:
diff changeset
22
Ritor1
parents:
diff changeset
23 #include "mm7_data.h"
Ritor1
parents:
diff changeset
24
Ritor1
parents:
diff changeset
25
Ritor1
parents:
diff changeset
26
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
27 struct SaveDataHeader
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
28 {
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
29 int Signature;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
30 char txt_ver[4];
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
31 int compressed_size;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
32 int uncompressed_size;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
33 };
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
34
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
35
0
Ritor1
parents:
diff changeset
36
Ritor1
parents:
diff changeset
37
Ritor1
parents:
diff changeset
38 struct SavegameList *pSavegameList = new SavegameList;
Ritor1
parents:
diff changeset
39 unsigned int uNumSavegameFiles;
Ritor1
parents:
diff changeset
40 unsigned int pSavegameUsedSlots[45];
Ritor1
parents:
diff changeset
41 struct RGBTexture pSavegameThumbnails[45];
Ritor1
parents:
diff changeset
42 SavegameHeader pSavegameHeader[45];
Ritor1
parents:
diff changeset
43
Ritor1
parents:
diff changeset
44
Ritor1
parents:
diff changeset
45
Ritor1
parents:
diff changeset
46
Ritor1
parents:
diff changeset
47
Ritor1
parents:
diff changeset
48
Ritor1
parents:
diff changeset
49
Ritor1
parents:
diff changeset
50
Ritor1
parents:
diff changeset
51
Ritor1
parents:
diff changeset
52
Ritor1
parents:
diff changeset
53 //----- (0045EE8A) --------------------------------------------------------
Ritor1
parents:
diff changeset
54 void __fastcall LoadGame(unsigned int uSlot)
Ritor1
parents:
diff changeset
55 {
Ritor1
parents:
diff changeset
56 bool v25; // esi@62
Ritor1
parents:
diff changeset
57 bool v26; // eax@62
Ritor1
parents:
diff changeset
58 int v30; // [sp-Ch] [bp-FCh]@65
Ritor1
parents:
diff changeset
59 int v31; // [sp-8h] [bp-F8h]@4
Ritor1
parents:
diff changeset
60 SavegameHeader header; // [sp+Ch] [bp-E4h]@23
Ritor1
parents:
diff changeset
61 char Str[123]; // [sp+70h] [bp-80h]@25
Ritor1
parents:
diff changeset
62
336
ea55d6414029 Event_proceccor preliminary
Gloval
parents: 328
diff changeset
63 dword_5B65C8_timers_count = 0;
0
Ritor1
parents:
diff changeset
64 if (!pSavegameUsedSlots[uSlot])
Ritor1
parents:
diff changeset
65 {
Ritor1
parents:
diff changeset
66 pAudioPlayer->PlaySound(SOUND_27, 0, 0, -1, 0, 0, 0, 0);
Ritor1
parents:
diff changeset
67 Log::Warning(L"LoadGame: slot %u is empty", uSlot);
Ritor1
parents:
diff changeset
68 return;
Ritor1
parents:
diff changeset
69 }
Ritor1
parents:
diff changeset
70
Ritor1
parents:
diff changeset
71 for (uint i = 1; i < 5; ++i)
Ritor1
parents:
diff changeset
72 for (uint j = 1; j < 6; ++j)
Ritor1
parents:
diff changeset
73 {
Ritor1
parents:
diff changeset
74 sprintf(pTmpBuf, "data\\lloyd%d%d.pcx", i, j);
Ritor1
parents:
diff changeset
75 remove(pTmpBuf);
Ritor1
parents:
diff changeset
76 }
Ritor1
parents:
diff changeset
77
Ritor1
parents:
diff changeset
78
203
0c64754c7fd4 Voices work (at least in party creation screen)
Nomad
parents: 189
diff changeset
79 if (SoundSetAction[24][0])
0
Ritor1
parents:
diff changeset
80 for (uint i = 0; i < 4; ++i)
Ritor1
parents:
diff changeset
81 {
764
90bcfb56c8f9 sound cleaning
Gloval
parents: 752
diff changeset
82 for (uint j = 0; j < pSoundList->sNumSounds; ++j)
203
0c64754c7fd4 Voices work (at least in party creation screen)
Nomad
parents: 189
diff changeset
83 if (pSoundList->pSounds[j].uSoundID == 2 * (SoundSetAction[24][0] + 50 * pParty->pPlayers[i].uVoiceID) + 4998)
0
Ritor1
parents:
diff changeset
84 {
764
90bcfb56c8f9 sound cleaning
Gloval
parents: 752
diff changeset
85 pSoundList->UnloadSound(j, 1);
0
Ritor1
parents:
diff changeset
86 break;
Ritor1
parents:
diff changeset
87 }
Ritor1
parents:
diff changeset
88
764
90bcfb56c8f9 sound cleaning
Gloval
parents: 752
diff changeset
89 for (uint j = 0; j < pSoundList->sNumSounds; ++j)
203
0c64754c7fd4 Voices work (at least in party creation screen)
Nomad
parents: 189
diff changeset
90 if (pSoundList->pSounds[j].uSoundID == 2 * (SoundSetAction[24][0] + 50 * pParty->pPlayers[i].uVoiceID) + 4999)
0
Ritor1
parents:
diff changeset
91 {
764
90bcfb56c8f9 sound cleaning
Gloval
parents: 752
diff changeset
92 pSoundList->UnloadSound(j, 1);
0
Ritor1
parents:
diff changeset
93 break;
Ritor1
parents:
diff changeset
94 }
Ritor1
parents:
diff changeset
95 }
Ritor1
parents:
diff changeset
96
382
a4a5996fea5b Fixed savelist problem
Gloval
parents: 373
diff changeset
97 sprintf(pTmpBuf, "saves\\%s", pSavegameList->pFileList[uSlot].pSaveFileName);
0
Ritor1
parents:
diff changeset
98
Ritor1
parents:
diff changeset
99 pNew_LOD->CloseWriteFile();
Ritor1
parents:
diff changeset
100 if (!CopyFileA(pTmpBuf, "data\\new.lod", 0))
Ritor1
parents:
diff changeset
101 int e = GetLastError();
Ritor1
parents:
diff changeset
102
Ritor1
parents:
diff changeset
103 pNew_LOD->LoadFile("data\\new.lod", 0);
Ritor1
parents:
diff changeset
104 auto *f = pNew_LOD->FindContainer("header.bin", 1);
Ritor1
parents:
diff changeset
105 if (!f)
Ritor1
parents:
diff changeset
106 {
Ritor1
parents:
diff changeset
107 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 100);
Ritor1
parents:
diff changeset
108 Log::Warning(L"%S", Str);
Ritor1
parents:
diff changeset
109 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:549", 0);
Ritor1
parents:
diff changeset
110 }
Ritor1
parents:
diff changeset
111 assert(sizeof(SavegameHeader) == 100);
Ritor1
parents:
diff changeset
112 fread(&header, sizeof(SavegameHeader), 1, f);
Ritor1
parents:
diff changeset
113
Ritor1
parents:
diff changeset
114 f = pNew_LOD->FindContainer("party.bin", 1);
Ritor1
parents:
diff changeset
115 if (!f)
Ritor1
parents:
diff changeset
116 {
Ritor1
parents:
diff changeset
117 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 101);
Ritor1
parents:
diff changeset
118 Log::Warning(L"%S", Str);
Ritor1
parents:
diff changeset
119 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:559", 0);
Ritor1
parents:
diff changeset
120 }
Ritor1
parents:
diff changeset
121 if (sizeof(Party) != 0x16238)
Ritor1
parents:
diff changeset
122 Log::Warning(L"class Party: deserialization warning");
Ritor1
parents:
diff changeset
123 fread(pParty, 0x16238u, 1, f);
Ritor1
parents:
diff changeset
124
Ritor1
parents:
diff changeset
125
Ritor1
parents:
diff changeset
126 f = pNew_LOD->FindContainer("clock.bin", 1);
Ritor1
parents:
diff changeset
127 if (!f)
Ritor1
parents:
diff changeset
128 {
Ritor1
parents:
diff changeset
129 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 102);
Ritor1
parents:
diff changeset
130 Log::Warning(L"%S", Str);
Ritor1
parents:
diff changeset
131 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:569", 0);
Ritor1
parents:
diff changeset
132 }
Ritor1
parents:
diff changeset
133 if (sizeof(Timer) != 0x28)
Ritor1
parents:
diff changeset
134 Log::Warning(L"class Timer: deserialization warning");
Ritor1
parents:
diff changeset
135 fread(pEventTimer, 0x28u, 1u, f);
Ritor1
parents:
diff changeset
136
Ritor1
parents:
diff changeset
137 f = pNew_LOD->FindContainer("overlay.bin", 1);
Ritor1
parents:
diff changeset
138 if (!f)
Ritor1
parents:
diff changeset
139 {
Ritor1
parents:
diff changeset
140 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 103);
Ritor1
parents:
diff changeset
141 Log::Warning(L"%S", Str);
Ritor1
parents:
diff changeset
142 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:579", 0);
Ritor1
parents:
diff changeset
143 }
Ritor1
parents:
diff changeset
144 if (sizeof(OtherOverlayList) != 0x3F0)
Ritor1
parents:
diff changeset
145 Log::Warning(L"class OtherOverlayList: deserialization warning");
Ritor1
parents:
diff changeset
146 fread(pOtherOverlayList, 0x3F0, 1, f);
Ritor1
parents:
diff changeset
147
Ritor1
parents:
diff changeset
148 f = pNew_LOD->FindContainer("npcdata.bin", 0);
Ritor1
parents:
diff changeset
149 if (!f)
Ritor1
parents:
diff changeset
150 {
Ritor1
parents:
diff changeset
151 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 104);
Ritor1
parents:
diff changeset
152 Log::Warning(L"%S", Str);
Ritor1
parents:
diff changeset
153 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:590", 0);
Ritor1
parents:
diff changeset
154 }
Ritor1
parents:
diff changeset
155 if (sizeof(pNPCStats->pNewNPCData) != 0x94BC)
Ritor1
parents:
diff changeset
156 Log::Warning(L"NPCStats: deserialization warning");
Ritor1
parents:
diff changeset
157 fread(pNPCStats->pNewNPCData, 0x94BC, 1, f);
Ritor1
parents:
diff changeset
158 pNPCStats->_476C60();
Ritor1
parents:
diff changeset
159
Ritor1
parents:
diff changeset
160 f = pNew_LOD->FindContainer("npcgroup.bin", 0);
Ritor1
parents:
diff changeset
161 if (!f)
Ritor1
parents:
diff changeset
162 {
Ritor1
parents:
diff changeset
163 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 105);
Ritor1
parents:
diff changeset
164 Log::Warning(L"%S", Str);
Ritor1
parents:
diff changeset
165 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:600", 0);
Ritor1
parents:
diff changeset
166 }
Ritor1
parents:
diff changeset
167 if (sizeof(pNPCStats->pGroups_copy) != 0x66)
Ritor1
parents:
diff changeset
168 Log::Warning(L"NPCStats: deserialization warning");
Ritor1
parents:
diff changeset
169 fread(pNPCStats->pGroups_copy, 0x66, 1, f);
Ritor1
parents:
diff changeset
170
Ritor1
parents:
diff changeset
171
Ritor1
parents:
diff changeset
172 uActiveCharacter = 0;
Ritor1
parents:
diff changeset
173 for (uint i = 0; i < 4; ++i)
Ritor1
parents:
diff changeset
174 if (pParty->pPlayers[i].CanAct())
Ritor1
parents:
diff changeset
175 {
Ritor1
parents:
diff changeset
176 uActiveCharacter = i + 1;
Ritor1
parents:
diff changeset
177 break;
Ritor1
parents:
diff changeset
178 }
Ritor1
parents:
diff changeset
179
Ritor1
parents:
diff changeset
180 for (uint i = 0; i < 4; ++i)
Ritor1
parents:
diff changeset
181 {
Ritor1
parents:
diff changeset
182 auto uQuickspell = pParty->pPlayers[i].uQuickSpell;
Ritor1
parents:
diff changeset
183 if (uQuickspell)
Ritor1
parents:
diff changeset
184 stru_AA1058[i]._494836(uQuickspell, i + 9 - 8);
Ritor1
parents:
diff changeset
185
Ritor1
parents:
diff changeset
186 for (uint j = 0; j < 2; ++j)
Ritor1
parents:
diff changeset
187 {
Ritor1
parents:
diff changeset
188 uint uEquipIdx = pParty->pPlayers[i].pEquipment.pIndices[j];
Ritor1
parents:
diff changeset
189 if (uEquipIdx)
Ritor1
parents:
diff changeset
190 {
Ritor1
parents:
diff changeset
191 auto uItemID = pParty->pPlayers[i].pInventoryItems[uEquipIdx - 1].uItemID;
Ritor1
parents:
diff changeset
192 if (pItemsTable->pItems[uItemID].uEquipType == 12)
Ritor1
parents:
diff changeset
193 {
Ritor1
parents:
diff changeset
194 __debugbreak();
488
Nomad
parents: 382
diff changeset
195 v31 = *((int *)&pSpellDatas[66].uNormalLevelRecovery + uItemID);
0
Ritor1
parents:
diff changeset
196 stru_A750F8[i]._494836(v31, i + 9);
Ritor1
parents:
diff changeset
197 }
Ritor1
parents:
diff changeset
198 }
Ritor1
parents:
diff changeset
199 }
Ritor1
parents:
diff changeset
200 }
Ritor1
parents:
diff changeset
201
Ritor1
parents:
diff changeset
202
Ritor1
parents:
diff changeset
203 pGUIWindow_CurrentMenu->Release();
151
9abdd40a107b pCurrentScreen
Ritor1
parents: 79
diff changeset
204 pCurrentScreen = SCREEN_GAME;
0
Ritor1
parents:
diff changeset
205
Ritor1
parents:
diff changeset
206 viewparams->bRedrawGameUI = true;
Ritor1
parents:
diff changeset
207
373
edd2d8b7e3c4 Interface reloading fix & party alignment enum
Nomad
parents: 336
diff changeset
208 SetUserInterface(pParty->alignment, true);
0
Ritor1
parents:
diff changeset
209
Ritor1
parents:
diff changeset
210 pEventTimer->Resume();
Ritor1
parents:
diff changeset
211 pEventTimer->StopGameTime();
Ritor1
parents:
diff changeset
212
Ritor1
parents:
diff changeset
213 v25 = pGames_LOD->DoesContainerExist(header.pLocationName);
Ritor1
parents:
diff changeset
214 sprintf(pTmpBuf, "levels\\%s", header.pLocationName);
Ritor1
parents:
diff changeset
215 v26 = _access(pTmpBuf, 4) != -1;
Ritor1
parents:
diff changeset
216 if ( !v25 && !v26 )
Ritor1
parents:
diff changeset
217 {
Ritor1
parents:
diff changeset
218 sprintf(pTmpBuf, "Unable to find: %s!", header.pLocationName);
Ritor1
parents:
diff changeset
219 Abortf(pTmpBuf);
Ritor1
parents:
diff changeset
220 }
Ritor1
parents:
diff changeset
221
Ritor1
parents:
diff changeset
222 strcpy(pCurrentMapName, header.pLocationName);
Ritor1
parents:
diff changeset
223 dword_6BE364_game_settings_1 |= 0x2001;
Ritor1
parents:
diff changeset
224
Ritor1
parents:
diff changeset
225 for (uint i = 0; i < uNumSavegameFiles; ++i)
Ritor1
parents:
diff changeset
226 pSavegameThumbnails[i].Release();
Ritor1
parents:
diff changeset
227
Ritor1
parents:
diff changeset
228 pIcons_LOD->_4114F2();
328
8e23edf57e27 little fix
Ritor1
parents: 203
diff changeset
229 pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
8e23edf57e27 little fix
Ritor1
parents: 203
diff changeset
230 pAudioPlayer->SetMasterVolume(pSoundVolumeLevels[uSoundVolumeMultiplier] * 128.0f);
0
Ritor1
parents:
diff changeset
231 if (uTurnSpeed)
Ritor1
parents:
diff changeset
232 pParty->sRotationY = uTurnSpeed * pParty->sRotationY / (signed int)uTurnSpeed;
Ritor1
parents:
diff changeset
233 MM7Initialization();
Ritor1
parents:
diff changeset
234 bFlashQuestBook = false;
Ritor1
parents:
diff changeset
235 viewparams->bRedrawGameUI = true;
Ritor1
parents:
diff changeset
236 }
Ritor1
parents:
diff changeset
237
Ritor1
parents:
diff changeset
238
Ritor1
parents:
diff changeset
239 //----- (0045F469) --------------------------------------------------------
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
240 void SaveGame( bool IsAutoSAve, bool NotSaveWorld )
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
241 {
0
Ritor1
parents:
diff changeset
242 int result; // eax@1
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
243 unsigned short *pScreenshot; // edi@5
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
244 int text_pos; // eax@6
0
Ritor1
parents:
diff changeset
245 int v5; // eax@6
Ritor1
parents:
diff changeset
246 int v6; // eax@6
Ritor1
parents:
diff changeset
247 const char *v7; // edi@8
Ritor1
parents:
diff changeset
248 FILE *v8; // edi@24
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
249 char* compressed_buf; // edi@30
0
Ritor1
parents:
diff changeset
250 void *v10; // esi@31
Ritor1
parents:
diff changeset
251 void *v11; // esi@31
Ritor1
parents:
diff changeset
252 void *v12; // esi@37
Ritor1
parents:
diff changeset
253 void *v13; // esi@37
Ritor1
parents:
diff changeset
254 void *v14; // esi@37
Ritor1
parents:
diff changeset
255 void *v15; // esi@37
Ritor1
parents:
diff changeset
256 void *v16; // esi@37
Ritor1
parents:
diff changeset
257 int v17; // esi@37
Ritor1
parents:
diff changeset
258 unsigned int v18; // ecx@38
Ritor1
parents:
diff changeset
259 unsigned int v19; // esi@39
79
6ad816231528 structure fixes, death crash fix
zipi
parents: 4
diff changeset
260 BSPModel *v20; // edx@39
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
261 char *data_write_pos; // esi@41
0
Ritor1
parents:
diff changeset
262 void *v22; // esi@41
Ritor1
parents:
diff changeset
263 BSPModel *v23; // eax@42
Ritor1
parents:
diff changeset
264 signed int v24; // edi@42
Ritor1
parents:
diff changeset
265 unsigned __int8 v25; // zf@43
Ritor1
parents:
diff changeset
266 unsigned __int8 v26; // sf@43
Ritor1
parents:
diff changeset
267 signed int v27; // edi@47
Ritor1
parents:
diff changeset
268 void *v28; // esi@50
Ritor1
parents:
diff changeset
269 void *v29; // esi@50
Ritor1
parents:
diff changeset
270 void *v30; // esi@50
Ritor1
parents:
diff changeset
271 void *v31; // esi@50
Ritor1
parents:
diff changeset
272 int v32; // esi@51
Ritor1
parents:
diff changeset
273 int v33; // eax@51
Ritor1
parents:
diff changeset
274 DWORD v34; // eax@59
Ritor1
parents:
diff changeset
275 //std::string v35; // [sp-18h] [bp-288h]@8
Ritor1
parents:
diff changeset
276 const char *v36; // [sp-10h] [bp-280h]@6
Ritor1
parents:
diff changeset
277 const char *v37; // [sp-Ch] [bp-27Ch]@6
79
6ad816231528 structure fixes, death crash fix
zipi
parents: 4
diff changeset
278 unsigned int *v38; // [sp-8h] [bp-278h]@8
0
Ritor1
parents:
diff changeset
279 CHAR Buffer; // [sp+Ch] [bp-264h]@59
79
6ad816231528 structure fixes, death crash fix
zipi
parents: 4
diff changeset
280 char Dir[255]; // [sp+8Ch] [bp-1E4h]@51
6ad816231528 structure fixes, death crash fix
zipi
parents: 4
diff changeset
281 char Drive[255]; // [sp+ACh] [bp-1C4h]@51
0
Ritor1
parents:
diff changeset
282 SavegameHeader header; // [sp+CCh] [bp-1A4h]@10
Ritor1
parents:
diff changeset
283 //int v43; // [sp+CCh] [bp-1A4h]@10
Ritor1
parents:
diff changeset
284 //char Dest[20]; // [sp+E0h] [bp-190h]@10
Ritor1
parents:
diff changeset
285 //unsigned __int64 pTimePlayed; // [sp+F4h] [bp-17Ch]@10
79
6ad816231528 structure fixes, death crash fix
zipi
parents: 4
diff changeset
286 char Filename[255]; // [sp+130h] [bp-140h]@51
6ad816231528 structure fixes, death crash fix
zipi
parents: 4
diff changeset
287 char Ext[255]; // [sp+150h] [bp-120h]@51
0
Ritor1
parents:
diff changeset
288 char v48; // [sp+151h] [bp-11Fh]@51
Ritor1
parents:
diff changeset
289 char Source[32]; // [sp+170h] [bp-100h]@51
Ritor1
parents:
diff changeset
290 char Str[120]; // [sp+190h] [bp-E0h]@8
Ritor1
parents:
diff changeset
291 int v51; // [sp+208h] [bp-68h]@2
Ritor1
parents:
diff changeset
292 int pPositionX; // [sp+20Ch] [bp-64h]@2
Ritor1
parents:
diff changeset
293 int v53; // [sp+210h] [bp-60h]@2
Ritor1
parents:
diff changeset
294 int v54; // [sp+214h] [bp-5Ch]@2
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
295 SaveDataHeader Src; // [sp+218h] [bp-58h]@30
0
Ritor1
parents:
diff changeset
296 char v56; // [sp+21Ch] [bp-54h]@30
Ritor1
parents:
diff changeset
297 char v57; // [sp+21Dh] [bp-53h]@30
Ritor1
parents:
diff changeset
298 char v58; // [sp+21Eh] [bp-52h]@30
Ritor1
parents:
diff changeset
299 char v59; // [sp+21Fh] [bp-51h]@30
Ritor1
parents:
diff changeset
300 int v60; // [sp+220h] [bp-50h]@30
Ritor1
parents:
diff changeset
301 int v61; // [sp+224h] [bp-4Ch]@30
Ritor1
parents:
diff changeset
302 int v62; // [sp+228h] [bp-48h]@2
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
303 LOD::Directory pLodDirectory; // [sp+22Ch] [bp-44h]@2
0
Ritor1
parents:
diff changeset
304 size_t Size; // [sp+250h] [bp-20h]@26
Ritor1
parents:
diff changeset
305 __int16 *v66; // [sp+254h] [bp-1Ch]@1
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
306 char *uncompressed_buff; // [sp+258h] [bp-18h]@2
0
Ritor1
parents:
diff changeset
307 __int16 *v68; // [sp+25Ch] [bp-14h]@32
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
308 unsigned int compressed_block_size; // [sp+260h] [bp-10h]@23
0
Ritor1
parents:
diff changeset
309 int v70; // [sp+264h] [bp-Ch]@22
Ritor1
parents:
diff changeset
310 std::string *v71; // [sp+268h] [bp-8h]@8
Ritor1
parents:
diff changeset
311 int a3; // [sp+26Fh] [bp-1h]@8
Ritor1
parents:
diff changeset
312
568
6f7d936edc9b SaveGame/LoadGame sorta works
Nomad
parents: 557
diff changeset
313 //v66 = a2;
0
Ritor1
parents:
diff changeset
314 strcpy(byte_6BE3B0, pCurrentMapName);
568
6f7d936edc9b SaveGame/LoadGame sorta works
Nomad
parents: 557
diff changeset
315 if (!_strcmpi(pCurrentMapName, "d05.blv")) // arena
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
316 return;
568
6f7d936edc9b SaveGame/LoadGame sorta works
Nomad
parents: 557
diff changeset
317
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
318 uncompressed_buff = (char*)malloc(1000000);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
319 pLodDirectory.Reset();
0
Ritor1
parents:
diff changeset
320 pPositionX = pParty->vPosition.x;
Ritor1
parents:
diff changeset
321 v51 = pParty->vPosition.y;
Ritor1
parents:
diff changeset
322 v62 = pParty->vPosition.z;
Ritor1
parents:
diff changeset
323 v53 = pParty->sRotationY;
Ritor1
parents:
diff changeset
324 v54 = pParty->sRotationX;
Ritor1
parents:
diff changeset
325 pParty->vPosition.x = pParty->vPrevPosition.x;
Ritor1
parents:
diff changeset
326 pParty->vPosition.y = pParty->vPrevPosition.z;
Ritor1
parents:
diff changeset
327 pParty->vPosition.z = pParty->vPrevPosition.y;
Ritor1
parents:
diff changeset
328 pParty->uFallStartY = pParty->vPrevPosition.y;
Ritor1
parents:
diff changeset
329 pParty->sRotationY = pParty->sPrevRotationY;
Ritor1
parents:
diff changeset
330 pParty->sRotationX = pParty->sPrevRotationX;
Ritor1
parents:
diff changeset
331 if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
Ritor1
parents:
diff changeset
332 pIndoor->stru1.uLastVisitDay = pParty->uTimePlayed;
Ritor1
parents:
diff changeset
333 else
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
334 pOutdoor->loc_time.uLastVisitDay = pParty->uTimePlayed;
0
Ritor1
parents:
diff changeset
335 pScreenshot = MakeScreenshot(150, 112);
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
336 strcpy(pLodDirectory.pFilename, "image.pcx");
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
337 pRenderer->PackPCXpicture(pScreenshot, 150, 112, uncompressed_buff, 1000000, &pLodDirectory.uDataSize);
0
Ritor1
parents:
diff changeset
338 free(pScreenshot);
151
9abdd40a107b pCurrentScreen
Ritor1
parents: 79
diff changeset
339 if (pCurrentScreen == SCREEN_SAVEGAME)
0
Ritor1
parents:
diff changeset
340 {
568
6f7d936edc9b SaveGame/LoadGame sorta works
Nomad
parents: 557
diff changeset
341 pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->GetTexture(uTextureID_loadsave));
6f7d936edc9b SaveGame/LoadGame sorta works
Nomad
parents: 557
diff changeset
342 pRenderer->DrawTextureIndexed(18, 141, pIcons_LOD->GetTexture(uTextureID_save_up));
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
343 text_pos = pFontSmallnum->AlignText_Center(186, pGlobalTXT_LocalizationStrings[190]);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
344 pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, text_pos + 25, 219, 0, pGlobalTXT_LocalizationStrings[190], 0, 0, 0); //Ñîõðàíåíèå
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
345 text_pos = pFontSmallnum->AlignText_Center(186, pSavegameHeader[uLoadGameUI_SelectedSlot].pName);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
346 pGUIWindow_CurrentMenu->DrawTextInRect(pFontSmallnum, text_pos + 25, 259, 0, pSavegameHeader[uLoadGameUI_SelectedSlot].pName, 185, 0);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
347 text_pos = pFontSmallnum->AlignText_Center(186, pGlobalTXT_LocalizationStrings[165]);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
348 pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, text_pos + 25, 299, 0, pGlobalTXT_LocalizationStrings[165], 0, 0, 0); //Ïîæàëóéñòà, ïîäîæäèòå
0
Ritor1
parents:
diff changeset
349 pRenderer->Present();
568
6f7d936edc9b SaveGame/LoadGame sorta works
Nomad
parents: 557
diff changeset
350 }
6f7d936edc9b SaveGame/LoadGame sorta works
Nomad
parents: 557
diff changeset
351
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
352 if (pNew_LOD->Write(&pLodDirectory, uncompressed_buff, 0))
0
Ritor1
parents:
diff changeset
353 {
Ritor1
parents:
diff changeset
354 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 200); //Ñîõðàíåííàÿ èãðà ïîâðåæäåíà! Code=%d
Ritor1
parents:
diff changeset
355 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:773", 0);
Ritor1
parents:
diff changeset
356 }
Ritor1
parents:
diff changeset
357
Ritor1
parents:
diff changeset
358 assert(sizeof(SavegameHeader) == 100);
Ritor1
parents:
diff changeset
359 memset(header.pName, 0, 20);
Ritor1
parents:
diff changeset
360 memset(header.pLocationName, 0, 20);
Ritor1
parents:
diff changeset
361 memset(header.field_30, 0, 52);
Ritor1
parents:
diff changeset
362 strcpy(header.pLocationName, pCurrentMapName);
Ritor1
parents:
diff changeset
363 header.uWordTime = pParty->uTimePlayed;
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
364 strcpy(pLodDirectory.pFilename, "header.bin");
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
365 pLodDirectory.uDataSize = sizeof(SavegameHeader);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
366 if (pNew_LOD->Write(&pLodDirectory, &header, 0))
0
Ritor1
parents:
diff changeset
367 {
Ritor1
parents:
diff changeset
368 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 201);
Ritor1
parents:
diff changeset
369 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:784", 0);
Ritor1
parents:
diff changeset
370 }
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
371 strcpy(pLodDirectory.pFilename, "party.bin");
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
372 pLodDirectory.uDataSize = sizeof(Party); //90680;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
373 if ( pNew_LOD->Write(&pLodDirectory, pParty, 0) )
0
Ritor1
parents:
diff changeset
374 {
Ritor1
parents:
diff changeset
375 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 202);
Ritor1
parents:
diff changeset
376 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:793", 0);
Ritor1
parents:
diff changeset
377 }
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
378 strcpy(pLodDirectory.pFilename, "clock.bin");
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
379 pLodDirectory.uDataSize =sizeof(Timer);// 40;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
380 if ( pNew_LOD->Write(&pLodDirectory, pEventTimer, 0) )
0
Ritor1
parents:
diff changeset
381 {
Ritor1
parents:
diff changeset
382 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 203);
Ritor1
parents:
diff changeset
383 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:802", 0);
Ritor1
parents:
diff changeset
384 }
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
385 strcpy(pLodDirectory.pFilename, "overlay.bin");
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
386 pLodDirectory.uDataSize =sizeof(OtherOverlayList);// 1008;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
387 if ( pNew_LOD->Write(&pLodDirectory, pOtherOverlayList, 0) )
0
Ritor1
parents:
diff changeset
388 {
Ritor1
parents:
diff changeset
389 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 204);
Ritor1
parents:
diff changeset
390 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:811", 0);
Ritor1
parents:
diff changeset
391 }
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
392 strcpy(pLodDirectory.pFilename, "npcdata.bin");
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
393 pLodDirectory.uDataSize = 501 * sizeof(NPCData);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
394 assert(pLodDirectory.uDataSize == 38076);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
395 if ( pNew_LOD->Write(&pLodDirectory, pNPCStats->pNewNPCData, 0) )
0
Ritor1
parents:
diff changeset
396 {
Ritor1
parents:
diff changeset
397 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 205);
Ritor1
parents:
diff changeset
398 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:820", 0);
Ritor1
parents:
diff changeset
399 }
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
400 strcpy(pLodDirectory.pFilename, "npcgroup.bin");
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
401 pLodDirectory.uDataSize = 102;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
402 if ( pNew_LOD->Write(&pLodDirectory, pNPCStats->pGroups_copy, 0) )
0
Ritor1
parents:
diff changeset
403 {
Ritor1
parents:
diff changeset
404 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 206);
Ritor1
parents:
diff changeset
405 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:829", 0);
Ritor1
parents:
diff changeset
406 }
Ritor1
parents:
diff changeset
407 for (int i = 1; i <= 4; ++i) // 4 - players
Ritor1
parents:
diff changeset
408 {
Ritor1
parents:
diff changeset
409 for (int j = 1; j <= 5; ++j) // 5 - images
Ritor1
parents:
diff changeset
410 {
Ritor1
parents:
diff changeset
411 sprintf(Str, "data\\lloyd%d%d.pcx", i, j);
Ritor1
parents:
diff changeset
412 v8 = fopen(Str, "rb");
Ritor1
parents:
diff changeset
413 if ( v8 )
Ritor1
parents:
diff changeset
414 {
Ritor1
parents:
diff changeset
415 __debugbreak();
Ritor1
parents:
diff changeset
416 sprintf(Str, "lloyd%d%d.pcx", i, j);
Ritor1
parents:
diff changeset
417 fseek(v8, 0, 2);
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
418 pLodDirectory.uDataSize = ftell(v8);
0
Ritor1
parents:
diff changeset
419 rewind(v8);
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
420 fread(uncompressed_buff, pLodDirectory.uDataSize, 1, v8);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
421 strcpy((char *)&pLodDirectory, Str);
0
Ritor1
parents:
diff changeset
422 fclose(v8);
Ritor1
parents:
diff changeset
423 remove(Str);
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
424 if ( pNew_LOD->Write(&pLodDirectory, uncompressed_buff, 0) )
0
Ritor1
parents:
diff changeset
425 {
Ritor1
parents:
diff changeset
426 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 207);
Ritor1
parents:
diff changeset
427 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:857", 0);
Ritor1
parents:
diff changeset
428 Size = 5080748;
Ritor1
parents:
diff changeset
429 }
Ritor1
parents:
diff changeset
430 }
Ritor1
parents:
diff changeset
431 }
Ritor1
parents:
diff changeset
432 }
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
433 if ( !NotSaveWorld )
0
Ritor1
parents:
diff changeset
434 {
79
6ad816231528 structure fixes, death crash fix
zipi
parents: 4
diff changeset
435 //__debugbreak();
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
436 CompactLayingItemsList();
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
437 compressed_buf = (char*)malloc(1000000);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
438 // v71 = (std::string *)compressed_buf;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
439 Src.Signature = 91969;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
440 Src.txt_ver[0] = 'm';
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
441 Src.txt_ver[1] = 'v';
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
442 Src.txt_ver[2] = 'i';
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
443 Src.txt_ver[3] = 'i';
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
444 Src.compressed_size = 0;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
445 Src.uncompressed_size = 0;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
446 data_write_pos = uncompressed_buff;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
447 memcpy((void *)compressed_buf, &Src, 0x10);
0
Ritor1
parents:
diff changeset
448 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
Ritor1
parents:
diff changeset
449 {
Ritor1
parents:
diff changeset
450 pIndoor->dlv.uNumFacesInBModels = pIndoor->uNumFaces;
Ritor1
parents:
diff changeset
451 pIndoor->dlv.uNumBModels = 0;
Ritor1
parents:
diff changeset
452 pIndoor->dlv.uNumDecorations = uNumLevelDecorations;
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
453 memcpy(data_write_pos, &pIndoor->dlv, 0x28);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
454 data_write_pos += 40;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
455 memcpy(data_write_pos, pIndoor->_visible_outlines, 0x36B);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
456 data_write_pos += 875;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
457
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
458 for (int i = 0; i <(signed int)pIndoor->uNumFaces; ++i)
0
Ritor1
parents:
diff changeset
459 {
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
460 memcpy(data_write_pos, &pIndoor->pFaces[i].uAttributes, 4);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
461 data_write_pos += 4;
0
Ritor1
parents:
diff changeset
462 }
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
463
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
464 for (int i = 0; i <(signed int)uNumLevelDecorations; ++i)
0
Ritor1
parents:
diff changeset
465 {
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
466 memcpy(data_write_pos, &pLevelDecorations[i].field_2, 2);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
467
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
468 data_write_pos+= 2;
0
Ritor1
parents:
diff changeset
469 }
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
470 memcpy(data_write_pos, &uNumActors, 4);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
471 data_write_pos += 4;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
472 memcpy(data_write_pos, pActors, 836 * uNumActors);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
473 data_write_pos += 836 * uNumActors;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
474 memcpy(data_write_pos, &uNumSpriteObjects, 4);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
475 data_write_pos += 4;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
476 memcpy(data_write_pos, pSpriteObjects, 112 * uNumSpriteObjects);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
477 data_write_pos += 112 * uNumSpriteObjects;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
478 memcpy(data_write_pos, &uNumChests, 4);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
479 data_write_pos += 4;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
480 memcpy(data_write_pos, pChests, 5324 * uNumChests);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
481 data_write_pos += 5324 * uNumChests;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
482 memcpy(data_write_pos, pIndoor->pDoors, 0x3E80);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
483 data_write_pos += 16000;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
484 memcpy(data_write_pos, pIndoor->ptr_0002B4_doors_ddata, pIndoor->blv.uDoors_ddata_Size);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
485 data_write_pos += pIndoor->blv.uDoors_ddata_Size;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
486 memcpy(data_write_pos, &stru_5E4C90, 0xC8);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
487 data_write_pos += 200;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
488 memcpy(data_write_pos, &pIndoor->stru1, 0x38);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
489 data_write_pos += 56;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
490
0
Ritor1
parents:
diff changeset
491 }
Ritor1
parents:
diff changeset
492 else
Ritor1
parents:
diff changeset
493 {
Ritor1
parents:
diff changeset
494 v18 = 0;
Ritor1
parents:
diff changeset
495 pOutdoor->ddm.uNumFacesInBModels = 0;
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
496 for (int i=0; i<pOutdoor->uNumBModels;++i)
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
497 {
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
498 v18 +=pOutdoor->pBModels[i].uNumFaces;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
499 }
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
500 pOutdoor->ddm.uNumFacesInBModels = v18;
0
Ritor1
parents:
diff changeset
501 pOutdoor->ddm.uNumBModels = pOutdoor->uNumBModels;
Ritor1
parents:
diff changeset
502 pOutdoor->ddm.uNumDecorations = uNumLevelDecorations;
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
503 memcpy(data_write_pos, &pOutdoor->ddm, sizeof(DDM_DLV_Header));//0x28
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
504 data_write_pos += sizeof(DDM_DLV_Header);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
505 memcpy(data_write_pos, pOutdoor->uUndiscoveredArea, 0x3C8);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
506 data_write_pos += 968;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
507 memcpy(data_write_pos, pOutdoor->uDicovered_area, 0x3C8);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
508 data_write_pos += 968;
0
Ritor1
parents:
diff changeset
509 if ( (signed int)pOutdoor->uNumBModels > 0 )
Ritor1
parents:
diff changeset
510 {
Ritor1
parents:
diff changeset
511 v23 = pOutdoor->pBModels;
Ritor1
parents:
diff changeset
512 v24 = 76;
79
6ad816231528 structure fixes, death crash fix
zipi
parents: 4
diff changeset
513 for (int i = 0; i < (signed int)pOutdoor->uNumBModels ; ++i)
0
Ritor1
parents:
diff changeset
514 {
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
515 //v25 = v23[i].uNumFaces == 0;//*(int *)&v23->pModelName[v24] == 0;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
516 // v26 = v23[i].uNumFaces < 0;//*(int *)&v23->pModelName[v24] < 0;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
517 if ( pOutdoor->pBModels[i].uNumFaces>0)
0
Ritor1
parents:
diff changeset
518 {
Ritor1
parents:
diff changeset
519 v68 = 0;
79
6ad816231528 structure fixes, death crash fix
zipi
parents: 4
diff changeset
520 for (int j = 0; j < pOutdoor->pBModels[i].uNumFaces;++j)//*(int *)&pOutdoor->pBModels->pModelName[v24]; ++j)
0
Ritor1
parents:
diff changeset
521 {
79
6ad816231528 structure fixes, death crash fix
zipi
parents: 4
diff changeset
522 v38 = &(v23[i].pFaces[j].uAttributes); //(char *)v68 + *(int *)&v23->pModelName[v24 + 8] + 28;
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
523 memcpy(data_write_pos, v38, 4);
0
Ritor1
parents:
diff changeset
524 v23 = pOutdoor->pBModels;
Ritor1
parents:
diff changeset
525 v68 += 154;
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
526 data_write_pos += 4;
0
Ritor1
parents:
diff changeset
527 }
Ritor1
parents:
diff changeset
528 }
Ritor1
parents:
diff changeset
529 v24 += 188;
Ritor1
parents:
diff changeset
530 }
Ritor1
parents:
diff changeset
531 }
Ritor1
parents:
diff changeset
532 if ( (signed int)uNumLevelDecorations > 0 )
Ritor1
parents:
diff changeset
533 {
Ritor1
parents:
diff changeset
534 v66 = &pLevelDecorations[0].field_2;
568
6f7d936edc9b SaveGame/LoadGame sorta works
Nomad
parents: 557
diff changeset
535 for (int i = 0; i <= (signed int)uNumLevelDecorations; ++i)
0
Ritor1
parents:
diff changeset
536 {
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
537 memcpy(data_write_pos, v66, 2);
0
Ritor1
parents:
diff changeset
538 v66 += 16;
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
539 data_write_pos += 2;
0
Ritor1
parents:
diff changeset
540 }
Ritor1
parents:
diff changeset
541 }
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
542 memcpy(data_write_pos, &uNumActors, 4);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
543 data_write_pos += 4;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
544 memcpy(data_write_pos, pActors, 836 * uNumActors);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
545 data_write_pos += 836 * uNumActors;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
546 memcpy(data_write_pos, &uNumSpriteObjects, 4);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
547 data_write_pos += 4;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
548 memcpy(data_write_pos, pSpriteObjects, 112 * uNumSpriteObjects);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
549 data_write_pos += 112 * uNumSpriteObjects;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
550 memcpy(data_write_pos, &uNumChests, 4);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
551 data_write_pos += 4;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
552 memcpy(data_write_pos, pChests, 5324 * uNumChests);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
553 data_write_pos += 5324 * uNumChests;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
554 memcpy(data_write_pos, &stru_5E4C90, 0xC8);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
555 data_write_pos += 200;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
556 memcpy(data_write_pos, &pOutdoor->loc_time, 0x38);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
557 data_write_pos += 56;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
558
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
559 //compressed_buf = (int)v71;
0
Ritor1
parents:
diff changeset
560 }
Ritor1
parents:
diff changeset
561 strcpy(Source, pCurrentMapName);
79
6ad816231528 structure fixes, death crash fix
zipi
parents: 4
diff changeset
562 _splitpath(Source, Drive, Dir, Filename, Ext);
0
Ritor1
parents:
diff changeset
563 v48 = 100;
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
564 Size = (int)data_write_pos - (int)uncompressed_buff;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
565 compressed_block_size = 999984;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
566 LOBYTE(v33) = zlib::MemZip((char *)compressed_buf + 16, (unsigned int *)&compressed_block_size, uncompressed_buff,Size);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
567 if ( v33 || (signed int)compressed_block_size > (signed int)Size )
0
Ritor1
parents:
diff changeset
568 {
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
569 memcpy((void *)(compressed_buf + 16), uncompressed_buff, Size);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
570 compressed_block_size = Size;
0
Ritor1
parents:
diff changeset
571 }
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
572 compressed_block_size += 16;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
573 memcpy(&((SaveDataHeader *)compressed_buf)->compressed_size, &compressed_block_size, 4);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
574 memcpy(&((SaveDataHeader *)compressed_buf)->uncompressed_size, &Size, 4);
0
Ritor1
parents:
diff changeset
575 sprintf(Source, "%s%s", &Filename, &Ext);
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
576 strcpy((char *)&pLodDirectory, Source);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
577 pLodDirectory.uDataSize = compressed_block_size;
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
578 if ( pNew_LOD->Write(&pLodDirectory, (const void *)compressed_buf, 0) )
0
Ritor1
parents:
diff changeset
579 {
Ritor1
parents:
diff changeset
580 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 208);
Ritor1
parents:
diff changeset
581 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:1071", 0);
Ritor1
parents:
diff changeset
582 }
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
583 free((void *)compressed_buf);
0
Ritor1
parents:
diff changeset
584 }
810
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
585 free(uncompressed_buff);
f5156b8c61ad savegame refactoring
Gloval
parents: 764
diff changeset
586 if ( IsAutoSAve )
0
Ritor1
parents:
diff changeset
587 {
Ritor1
parents:
diff changeset
588 if ( !CopyFileA("data\\new.lod", "saves\\autosave.mm7", 0) )
Ritor1
parents:
diff changeset
589 {
Ritor1
parents:
diff changeset
590 v34 = GetLastError();
Ritor1
parents:
diff changeset
591 FormatMessageA(0x1000, 0, v34, 0x400, &Buffer, 0x80, 0);
Ritor1
parents:
diff changeset
592 sprintf(Str, pGlobalTXT_LocalizationStrings[612], 300);
Ritor1
parents:
diff changeset
593 MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:1097", 0);
Ritor1
parents:
diff changeset
594 }
Ritor1
parents:
diff changeset
595 }
Ritor1
parents:
diff changeset
596 pParty->vPosition.x = pPositionX;
Ritor1
parents:
diff changeset
597 pParty->vPosition.y = v51;
Ritor1
parents:
diff changeset
598 pParty->vPosition.z = v62;
Ritor1
parents:
diff changeset
599 pParty->uFallStartY = v62;
Ritor1
parents:
diff changeset
600 pParty->sRotationY = v53;
Ritor1
parents:
diff changeset
601 pParty->sRotationX = v54;
Ritor1
parents:
diff changeset
602 }
Ritor1
parents:
diff changeset
603
Ritor1
parents:
diff changeset
604
Ritor1
parents:
diff changeset
605 //----- (00460078) --------------------------------------------------------
Ritor1
parents:
diff changeset
606 void __fastcall DoSavegame(unsigned int uSlot)
Ritor1
parents:
diff changeset
607 {
568
6f7d936edc9b SaveGame/LoadGame sorta works
Nomad
parents: 557
diff changeset
608 //unsigned int v1; // esi@1
6f7d936edc9b SaveGame/LoadGame sorta works
Nomad
parents: 557
diff changeset
609 //int v2; // esi@2
557
604d70894002 Saving works partly
zipi
parents: 515
diff changeset
610 //RGBTexture *v3; // ebx@3
0
Ritor1
parents:
diff changeset
611 int bNotArena; // [sp+2Ch] [bp-8h]@1
568
6f7d936edc9b SaveGame/LoadGame sorta works
Nomad
parents: 557
diff changeset
612 //unsigned int v6; // [sp+30h] [bp-4h]@1
0
Ritor1
parents:
diff changeset
613
165
Ritor1
parents: 151
diff changeset
614 //__debugbreak();
0
Ritor1
parents:
diff changeset
615
568
6f7d936edc9b SaveGame/LoadGame sorta works
Nomad
parents: 557
diff changeset
616 //v1 = uSlot;
6f7d936edc9b SaveGame/LoadGame sorta works
Nomad
parents: 557
diff changeset
617 //v6 = uSlot;
0
Ritor1
parents:
diff changeset
618 bNotArena = _strcmpi(pCurrentMapName, "d05.blv");
Ritor1
parents:
diff changeset
619 if ( bNotArena )
Ritor1
parents:
diff changeset
620 {
Ritor1
parents:
diff changeset
621 LOD::Directory pDir; // [sp+Ch] [bp-28h]@2
Ritor1
parents:
diff changeset
622 SaveGame(0, 0);
568
6f7d936edc9b SaveGame/LoadGame sorta works
Nomad
parents: 557
diff changeset
623 //v2 = 100 * v1;
6f7d936edc9b SaveGame/LoadGame sorta works
Nomad
parents: 557
diff changeset
624 strcpy(pSavegameHeader[uSlot].pLocationName, pCurrentMapName);
6f7d936edc9b SaveGame/LoadGame sorta works
Nomad
parents: 557
diff changeset
625 pSavegameHeader[uSlot].uWordTime = pParty->uTimePlayed;
6f7d936edc9b SaveGame/LoadGame sorta works
Nomad
parents: 557
diff changeset
626 strcpy(pDir.pFilename, "header.bin");
0
Ritor1
parents:
diff changeset
627 pDir.uDataSize = 100;
568
6f7d936edc9b SaveGame/LoadGame sorta works
Nomad
parents: 557
diff changeset
628 pNew_LOD->Write(&pDir, &pSavegameHeader[uSlot], 0);
6f7d936edc9b SaveGame/LoadGame sorta works
Nomad
parents: 557
diff changeset
629 sprintf(pTmpBuf, "saves\\save%03d.mm7", uSlot);
0
Ritor1
parents:
diff changeset
630 pNew_LOD->CloseWriteFile();
Ritor1
parents:
diff changeset
631 CopyFileA("data\\new.lod", pTmpBuf, 0);
Ritor1
parents:
diff changeset
632 }
Ritor1
parents:
diff changeset
633 GUI_UpdateWindows();
Ritor1
parents:
diff changeset
634 pGUIWindow_CurrentMenu->Release();
151
9abdd40a107b pCurrentScreen
Ritor1
parents: 79
diff changeset
635 pCurrentScreen = SCREEN_GAME;
557
604d70894002 Saving works partly
zipi
parents: 515
diff changeset
636 //v3 = pSavegameThumbnails;
0
Ritor1
parents:
diff changeset
637 viewparams->bRedrawGameUI = 1;
568
6f7d936edc9b SaveGame/LoadGame sorta works
Nomad
parents: 557
diff changeset
638 for (uint i = 0; i < 45; i++)
557
604d70894002 Saving works partly
zipi
parents: 515
diff changeset
639 pSavegameThumbnails[i].Release();
604d70894002 Saving works partly
zipi
parents: 515
diff changeset
640 //while ( (signed int)v3 < (signed int)&unk_6A0758 );
0
Ritor1
parents:
diff changeset
641 if ( bNotArena )
Ritor1
parents:
diff changeset
642 pNew_LOD->_4621A7();
Ritor1
parents:
diff changeset
643 else
Ritor1
parents:
diff changeset
644 ShowStatusBarString(pGlobalTXT_LocalizationStrings[583], 2u);// "No saving in the Arena"
Ritor1
parents:
diff changeset
645 pIcons_LOD->_4355F7();
Ritor1
parents:
diff changeset
646 pEventTimer->Resume();
Ritor1
parents:
diff changeset
647 ShowStatusBarString(pGlobalTXT_LocalizationStrings[656], 2u);// "Game Saved!"
568
6f7d936edc9b SaveGame/LoadGame sorta works
Nomad
parents: 557
diff changeset
648 viewparams->bRedrawGameUI = true;
0
Ritor1
parents:
diff changeset
649 }
Ritor1
parents:
diff changeset
650 // 4E28F8: using guessed type int pCurrentScreen;
Ritor1
parents:
diff changeset
651
Ritor1
parents:
diff changeset
652
Ritor1
parents:
diff changeset
653
Ritor1
parents:
diff changeset
654
Ritor1
parents:
diff changeset
655
Ritor1
parents:
diff changeset
656
Ritor1
parents:
diff changeset
657
Ritor1
parents:
diff changeset
658
Ritor1
parents:
diff changeset
659
Ritor1
parents:
diff changeset
660
Ritor1
parents:
diff changeset
661
Ritor1
parents:
diff changeset
662 //----- (0045E297) --------------------------------------------------------
Ritor1
parents:
diff changeset
663 void SavegameList::Initialize(unsigned int bHideEmptySlots)
Ritor1
parents:
diff changeset
664 {
382
a4a5996fea5b Fixed savelist problem
Gloval
parents: 373
diff changeset
665 memset(pSavegameList, 0, 0x3138);
a4a5996fea5b Fixed savelist problem
Gloval
parents: 373
diff changeset
666 // Reset();
4
8e33efd39355 15.01.13(work)
Ritor1
parents: 0
diff changeset
667 uNumSavegameFiles = 0;
0
Ritor1
parents:
diff changeset
668
Ritor1
parents:
diff changeset
669 _chdir("saves");
Ritor1
parents:
diff changeset
670 {
4
8e33efd39355 15.01.13(work)
Ritor1
parents: 0
diff changeset
671 if (!bHideEmptySlots && _access(pGlobalTXT_LocalizationStrings[613], 0) != -1 ) // AutoSave.MM7
382
a4a5996fea5b Fixed savelist problem
Gloval
parents: 373
diff changeset
672 strcpy(pSavegameList->pFileList[uNumSavegameFiles++].pSaveFileName, pGlobalTXT_LocalizationStrings[613]);
0
Ritor1
parents:
diff changeset
673
Ritor1
parents:
diff changeset
674 for (uint i = 0; i < 40; ++i)
Ritor1
parents:
diff changeset
675 {
Ritor1
parents:
diff changeset
676 sprintf(pTmpBuf, "save%03d.mm7", i);
Ritor1
parents:
diff changeset
677 if (_access(pTmpBuf, 0) == -1)
Ritor1
parents:
diff changeset
678 continue;
Ritor1
parents:
diff changeset
679
Ritor1
parents:
diff changeset
680 uint idx = i;
Ritor1
parents:
diff changeset
681 if (!bHideEmptySlots)
Ritor1
parents:
diff changeset
682 idx = uNumSavegameFiles;
382
a4a5996fea5b Fixed savelist problem
Gloval
parents: 373
diff changeset
683 strcpy(pSavegameList->pFileList[idx].pSaveFileName, pTmpBuf);
0
Ritor1
parents:
diff changeset
684
Ritor1
parents:
diff changeset
685 ++uNumSavegameFiles;
Ritor1
parents:
diff changeset
686 }
Ritor1
parents:
diff changeset
687 }
Ritor1
parents:
diff changeset
688 _chdir("..");
Ritor1
parents:
diff changeset
689 }