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