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