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