This repository was archived by the owner on Sep 3, 2026. It is now read-only.
forked from Nommy228/Might-and-Magic-Trilogy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecorationList.cpp
More file actions
294 lines (279 loc) · 9.99 KB
/
Copy pathDecorationList.cpp
File metadata and controls
294 lines (279 loc) · 9.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#define _CRT_SECURE_NO_WARNINGS
#include "Sprites.h"
#include "DecorationList.h"
#include "MM7.h"
#include "FrameTableInc.h"
#include "mm7_data.h"
#include "Indoor.h"
#include "ErrorHandling.h"
#include "stru123.h"
#include "Level\Decoration.h"
//----- (0045864C) --------------------------------------------------------
void DecorationList::FromFile(void *data_mm6, void *data_mm7, void *data_mm8)
{
uint num_mm6_decs = data_mm6 ? *(int *)data_mm6 : 0,
num_mm7_decs = data_mm7 ? *(int *)data_mm7 : 0,
num_mm8_decs = data_mm8 ? *(int *)data_mm8 : 0;
uNumDecorations = num_mm6_decs + num_mm7_decs + num_mm8_decs;
Assert(uNumDecorations);
Assert(!num_mm8_decs);
pDecorations = (DecorationDesc *)malloc(uNumDecorations * sizeof(DecorationDesc));
memcpy(pDecorations, (char *)data_mm7 + 4, num_mm7_decs * sizeof(DecorationDesc));
for (uint i = 0; i < num_mm6_decs; ++i)
{
memcpy(pDecorations + num_mm7_decs + i, (char *)data_mm6 + 4 + i * sizeof(DecorationDesc_mm6), sizeof(DecorationDesc_mm6));
pDecorations[num_mm7_decs + i].uColoredLightRed = 255;
pDecorations[num_mm7_decs + i].uColoredLightGreen = 255;
pDecorations[num_mm7_decs + i].uColoredLightBlue = 255;
pDecorations[num_mm7_decs + i].__padding = 255;
}
memcpy(pDecorations + num_mm6_decs + num_mm7_decs, (char *)data_mm8 + 4, num_mm8_decs * sizeof(DecorationDesc));
}
//----- (00458693) --------------------------------------------------------
void DecorationList::InitializeDecorationSprite(unsigned int uDecID)
{
pSpriteFrameTable->InitializeSprite(this->pDecorations[uDecID].uSpriteID);
}
//----- (004586B0) --------------------------------------------------------
bool DecorationList::FromFileTxt(const char *Args)
{
DecorationList *v2; // ebx@1
FILE *v3; // eax@1
unsigned int v4; // esi@3
void *v5; // eax@10
FILE *v6; // ST18_4@12
char *i; // eax@12
unsigned __int16 v8; // ax@16
//const char *v9; // ST20_4@16
//const char *v10; // ST18_4@16
//__int16 v11; // ax@16
//const char *v12; // ST14_4@16
//unsigned __int16 v13; // ax@16
// const char *v14; // ST10_4@16
//__int16 v15; // ax@16
// const char *v16; // ST0C_4@16
// unsigned __int8 v17; // al@16
// const char *v18; // ST08_4@16
// unsigned __int8 v19; // al@16
// const char *v20; // ST04_4@16
// unsigned __int8 v21; // al@16
// const char *v22; // ST00_4@16
unsigned __int8 v23; // zf@16
char v24; // sf@16
unsigned __int8 v25; // of@16
int j; // edi@17
const char *v27; // esi@18
int v29; // eax@21
int v30; // eax@23
int v31; // eax@25
int v32; // eax@27
int v33; // eax@29
int v34; // eax@31
int v35; // eax@33
FrameTableTxtLine v37; // [sp+Ch] [bp-460h]@17
FrameTableTxtLine v38; // [sp+88h] [bp-3E4h]@13
char Dest; // [sp+104h] [bp-368h]@17
char Buf; // [sp+17Ch] [bp-2F0h]@3
FrameTableTxtLine v41; // [sp+370h] [bp-FCh]@4
FrameTableTxtLine v42; // [sp+3ECh] [bp-80h]@4
FILE *File; // [sp+468h] [bp-4h]@1
unsigned int Argsa; // [sp+474h] [bp+8h]@3
v2 = this;
v3 = fopen(Args, "r");
File = v3;
if ( !v3 )
Error("DecorationDescriptionList::load - Unable to open file: %s.");
v4 = 0;
Argsa = 0;
if ( fgets(&Buf, 490, v3) )
{
do
{
*strchr(&Buf, 10) = 0;
memcpy(&v42, frame_table_txt_parser(&Buf, &v41), sizeof(v42));
if ( v42.uPropCount && *v42.pProperties[0] != 47 && v42.uPropCount >= 3 )
++Argsa;
}
while ( fgets(&Buf, 490, File) );
v4 = Argsa;
}
v2->uNumDecorations = v4;
v5 = malloc(84 * v4);
v2->pDecorations = (DecorationDesc *)v5;
if ( !v5 )
Error("DecorationDescriptionList::load - Out of Memory!");
v6 = File;
v2->uNumDecorations = 0;
fseek(v6, 0, 0);
for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) )
{
*strchr(&Buf, 10) = 0;
memcpy(&v42, frame_table_txt_parser(&Buf, &v38), sizeof(v42));
if ( v42.uPropCount && *v42.pProperties[0] != 47 && v42.uPropCount >= 3 )
{
strcpy(v2->pDecorations[v2->uNumDecorations].pName, v42.pProperties[1]);
v8 = pSpriteFrameTable->FastFindSprite(v2->pDecorations[v2->uNumDecorations].pName);
//v9 = v42.pProperties[2];
v2->pDecorations[v2->uNumDecorations].uSpriteID = v8;
strcpy(v2->pDecorations[v2->uNumDecorations].field_20, v42.pProperties[2]);
//v10 = v42.pProperties[3];
v2->pDecorations[v2->uNumDecorations].uType = 0;
//v11 = atoi(v42.pProperties[3]);
//v12 = v42.pProperties[4];
v2->pDecorations[v2->uNumDecorations].uRadius = atoi(v42.pProperties[3]);
//v13 = atoi(v42.pProperties[4]);
//v14 = v42.pProperties[5];
v2->pDecorations[v2->uNumDecorations].uDecorationHeight = atoi(v42.pProperties[4]);
//v15 = atoi(v42.pProperties[5]);
//v16 = v42.pProperties[6];
v2->pDecorations[v2->uNumDecorations].uLightRadius = atoi(v42.pProperties[5]);
//v17 = atoi(v42.pProperties[6]);
//v18 = v42.pProperties[7];
v2->pDecorations[v2->uNumDecorations].uColoredLightRed = atoi(v42.pProperties[6]);
//v19 = atoi(v42.pProperties[7]);
//v20 = v42.pProperties[8];
v2->pDecorations[v2->uNumDecorations].uColoredLightGreen = atoi(v42.pProperties[7]);
//v21 = atoi(v42.pProperties[8]);
//v22 = v42.pProperties[9];
v2->pDecorations[v2->uNumDecorations].uColoredLightBlue = atoi(v42.pProperties[8]);
v2->pDecorations[v2->uNumDecorations].uSoundID = atoi(v42.pProperties[9]);
__debugbreak();//Ritor1: need cleaning
v25 = __OFSUB__(v42.uPropCount, 10);
v23 = v42.uPropCount == 10;
v24 = v42.uPropCount - 10 < 0;
v2->pDecorations[v2->uNumDecorations].uFlags = 0;
if ( !((unsigned __int8)(v24 ^ v25) | v23) )
{
strcpy(&Dest, v42.pProperties[10]);
memcpy(&v41, frame_table_txt_parser(&Dest, &v37), sizeof(v41));
for ( j = 0; j < v41.uPropCount; ++j )
{
v27 = v41.pProperties[j];
if ( _stricmp(v41.pProperties[j], "NBM") )
{
if ( _stricmp(v27, "Invisible") )
{
if ( _stricmp(v27, "FS") )
{
if ( _stricmp(v27, "FM") )
{
if ( _stricmp(v27, "FF") )
{
if ( _stricmp(v27, "Marker") )
{
if ( _stricmp(v27, "LoopSlow") )
{
if ( _stricmp(v27, "EmitFire") )
{
if ( _stricmp(v27, "Dawn") )
{
if ( !_stricmp(v27, "Dusk") )
HIBYTE(v2->pDecorations[v2->uNumDecorations].uFlags) |= 2u;
}
else
{
HIBYTE(v2->pDecorations[v2->uNumDecorations].uFlags) |= 1u;
}
}
else
{
v35 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags;
*(char *)v35 |= 0x80u;
}
}
else
{
v34 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags;
*(char *)v34 |= 0x40u;
}
}
else
{
v33 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags;
*(char *)v33 |= 0x20u;
}
}
else
{
v32 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags;
*(char *)v32 |= 0x10u;
}
}
else
{
v31 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags;
*(char *)v31 |= 8u;
}
}
else
{
v30 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags;
*(char *)v30 |= 4u;
}
}
else
{
v29 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags;
*(char *)v29 |= 2u;
}
}
else
v2->pDecorations[v2->uNumDecorations].uFlags |= 1;
}
}
++v2->uNumDecorations;
}
}
fclose(File);
return 1;
}
//----- (00458600) --------------------------------------------------------
void DecorationList::ToFile()
{
FILE *v2; // eax@1
FILE *v3; // edi@1
v2 = fopen("data\\ddeclist.bin", "wb");
v3 = v2;
if ( !v2 )
Error("Unable to save ddeclist.bin!");
fwrite(this, 4, 1, v2);
fwrite(this->pDecorations, 84, this->uNumDecorations, v3);
fclose(v3);
}
//----- (004488B6) --------------------------------------------------------
unsigned __int16 DecorationList::GetDecorIdByName(const char *pName)
{
if ( pName && (signed int)this->uNumDecorations > 1 )
{
for ( uint uID = 1; uID < (signed int)this->uNumDecorations; ++uID )
{
if ( !_stricmp(pName, this->pDecorations[uID].pName) )
return uID;
}
}
return 0;
}
//----- (00450AAA) --------------------------------------------------------
void RespawnGlobalDecorations()
{
memset(stru_5E4C90_MapPersistVars._decor_events.data(), 0, 125);
uint decorEventIdx = 0;
for (uint i = 0; i < uNumLevelDecorations; ++i)
{
LevelDecoration* decor = &pLevelDecorations[i];
if (!decor->uEventID)
{
if (decor->IsInteractive())
{
if (decorEventIdx < 124)
{
decor->_idx_in_stru123 = decorEventIdx + 75;
stru_5E4C90_MapPersistVars._decor_events[decorEventIdx++] = decor->GetGlobalEvent();
}
}
}
}
}