2496
|
1 #define _CRTDBG_MAP_ALLOC
|
|
2 #include <stdlib.h>
|
|
3 #include <crtdbg.h>
|
|
4
|
|
5 #define _CRT_SECURE_NO_WARNINGS
|
|
6 #include <string.h>
|
|
7 #include <algorithm>
|
2499
|
8 #include "../ErrorHandling.h"
|
2496
|
9
|
|
10 #include "Sprites.h"
|
|
11 #include "PaletteManager.h"
|
2499
|
12 #include "../LOD.h"
|
|
13 #include "../Tables/FrameTableInc.h"
|
2496
|
14
|
|
15 #include "Outdoor.h"
|
|
16 #include "DecorationList.h"
|
2499
|
17 #include "../MM7.h"
|
|
18 #include "../Objects/Actor.h"
|
|
19 #include "Level/Decoration.h"
|
|
20 #include "../OurMath.h"
|
2496
|
21
|
|
22
|
|
23
|
|
24 struct SpriteFrameTable *pSpriteFrameTable;
|
|
25
|
|
26
|
|
27
|
|
28
|
|
29 //----- (0044D4D8) --------------------------------------------------------
|
|
30 void SpriteFrameTable::ReleaseSFrames()
|
|
31 {
|
|
32 free(this->pSpriteSFrames);
|
|
33 this->pSpriteSFrames = nullptr;
|
|
34 this->uNumSpriteFrames = 0;
|
|
35 }
|
|
36
|
|
37 //----- (0044D4F6) --------------------------------------------------------
|
|
38 void SpriteFrameTable::ResetSomeSpriteFlags()
|
|
39 {
|
|
40 int v1; // esi@1
|
|
41 signed int i; // edx@1
|
|
42 char *v3; // eax@2
|
|
43
|
|
44 v1 = 0;
|
|
45 for ( i = 0; i < (signed int)this->uNumSpriteFrames; ++i )
|
|
46 {
|
|
47 v3 = (char *)&this->pSpriteSFrames[v1].uFlags;
|
|
48 ++v1;
|
|
49 *v3 &= 0x7Fu;
|
|
50 }
|
|
51 }
|
|
52
|
|
53 //----- (0044D513) --------------------------------------------------------
|
|
54 void SpriteFrameTable::InitializeSprite( signed int uSpriteID )
|
|
55 {
|
|
56 //SpriteFrameTable *v2; // esi@1
|
|
57 unsigned int v3; // ebx@3
|
|
58 //char *v4; // edx@3
|
|
59 //int v5; // eax@3
|
|
60 // SpriteFrame *v6; // ecx@5
|
|
61 // int v7; // eax@5
|
|
62 __int16 v8; // ax@6
|
|
63 //signed int v9; // edx@6
|
|
64 //int v10; // ecx@6
|
|
65 // signed int v11; // edi@10
|
|
66 __int16 v12; // ax@16
|
|
67 // int v13; // ecx@16
|
|
68 size_t v14; // eax@19
|
|
69 // signed int v15; // edi@19
|
|
70 // __int16 v16; // ax@27
|
|
71 // int v17; // ecx@27
|
|
72 // signed int v18; // edi@29
|
|
73 // SpriteFrame *v19; // eax@30
|
|
74 // __int16 v20; // ax@45
|
|
75 // int v21; // ecx@45
|
|
76
|
|
77 char Str[32]; // [sp+Ch] [bp-3Ch]@19
|
|
78 char sprite_name[20]; // [sp+2Ch] [bp-1Ch]@15
|
|
79 char Source[4]; // [sp+40h] [bp-8h]@19
|
|
80
|
|
81
|
|
82 //v2 = this;
|
|
83 if ( uSpriteID <= this->uNumSpriteFrames )
|
|
84 {
|
|
85 if ( uSpriteID >= 0 )
|
|
86 {
|
|
87 v3 = uSpriteID;
|
|
88
|
|
89 int uFlags = pSpriteSFrames[v3].uFlags;
|
|
90 if (!(uFlags & 0x0080)) //not loaded
|
|
91 {
|
|
92 pSpriteSFrames[v3].uFlags |= 0x80; //set loaded
|
|
93 while ( 1 )
|
|
94 {
|
|
95 pSpriteSFrames[v3].uPaletteIndex = pPaletteManager->LoadPalette(pSpriteSFrames[v3].uPaletteID);
|
|
96 if ( uFlags & 0x10 ) //single frame per frame sequence
|
|
97 {
|
|
98 v8 = pSprites_LOD->LoadSprite(pSpriteSFrames[v3].pTextureName, pSpriteSFrames[v3].uPaletteID);
|
|
99 for (uint i = 0; i < 8; ++i)
|
|
100 {
|
|
101
|
|
102 pSpriteSFrames[v3].pHwSpriteIDs[i] = v8;
|
|
103 }
|
|
104
|
|
105 }
|
|
106 else if ( uFlags & 0x10000 )
|
|
107 {
|
|
108 for (uint i = 0; i < 8; ++i)
|
|
109 {
|
|
110 switch ( i )
|
|
111 {
|
|
112 case 3:
|
|
113 case 4:
|
|
114 case 5:
|
|
115 sprintf(sprite_name, "%s4", pSpriteSFrames[v3].pTextureName);
|
|
116 break;
|
|
117 case 2:
|
|
118 case 6:
|
|
119 sprintf(sprite_name, "%s2", pSpriteSFrames[v3].pTextureName);
|
|
120 break;
|
|
121 case 0:
|
|
122 case 1:
|
|
123 case 7:
|
|
124 sprintf(sprite_name, "%s0", pSpriteSFrames[v3].pTextureName);
|
|
125 break;
|
|
126 }
|
|
127 v12 = pSprites_LOD->LoadSprite(sprite_name, pSpriteSFrames[v3].uPaletteID);
|
|
128
|
|
129 pSpriteSFrames[v3].pHwSpriteIDs[i]=v12;
|
|
130 }
|
|
131
|
|
132 }
|
|
133 else if ( uFlags & 0x40 ) //part of monster fidgeting seq
|
|
134 {
|
|
135 strcpy(Source, "stA");
|
|
136 strcpy(Str, pSpriteSFrames[v3].pTextureName);
|
|
137 v14 = strlen(Str);
|
|
138 strcpy(&Str[v14-3], Source);
|
|
139 for (uint i = 0; i < 8; ++i)
|
|
140 {
|
|
141 switch ( i )
|
|
142 {
|
|
143 case 0:
|
|
144 sprintf(sprite_name, "%s0", pSpriteSFrames[v3].pTextureName);
|
|
145 break;
|
|
146 case 4:
|
|
147 sprintf(sprite_name, "%s4",&Str );
|
|
148 break;
|
|
149 case 3:
|
|
150 case 5:
|
|
151 sprintf(sprite_name, "%s3",&Str );
|
|
152 break;
|
|
153 case 2:
|
|
154 case 6:
|
|
155 sprintf(sprite_name, "%s2", pSpriteSFrames[v3].pTextureName);
|
|
156 break;
|
|
157 case 1:
|
|
158 case 7:
|
|
159 sprintf(sprite_name, "%s1", pSpriteSFrames[v3].pTextureName);
|
|
160 break;
|
|
161 }
|
|
162 v12 = pSprites_LOD->LoadSprite(sprite_name, pSpriteSFrames[v3].uPaletteID);
|
|
163 pSpriteSFrames[v3].pHwSpriteIDs[i]=v12;
|
|
164 }
|
|
165 }
|
|
166
|
|
167 else
|
|
168 {
|
|
169 for (uint i = 0; i < 8; ++i)
|
|
170
|
|
171 {
|
|
172
|
|
173 if (((0x0100 << i) & pSpriteSFrames[v3].uFlags) ) //mirrors
|
|
174 {
|
|
175 switch ( i )
|
|
176 {
|
|
177 case 1:
|
|
178 sprintf(sprite_name, "%s7", pSpriteSFrames[v3].pTextureName);
|
|
179 break;
|
|
180 case 2:
|
|
181 sprintf(sprite_name, "%s6", pSpriteSFrames[v3].pTextureName);
|
|
182 break;
|
|
183 case 3:
|
|
184 sprintf(sprite_name, "%s5", pSpriteSFrames[v3].pTextureName);
|
|
185 break;
|
|
186 case 4:
|
|
187 sprintf(sprite_name, "%s4", pSpriteSFrames[v3].pTextureName);
|
|
188 break;
|
|
189
|
|
190 case 5:
|
|
191 sprintf(sprite_name, "%s3", pSpriteSFrames[v3].pTextureName);
|
|
192 break;
|
|
193
|
|
194 case 6:
|
|
195 sprintf(sprite_name, "%s2", pSpriteSFrames[v3].pTextureName);
|
|
196 break;
|
|
197 case 7:
|
|
198 sprintf(sprite_name, "%s1", pSpriteSFrames[v3].pTextureName);
|
|
199 break;
|
|
200 }
|
|
201 }
|
|
202 else
|
|
203 {
|
|
204 sprintf(sprite_name, "%s%i", pSpriteSFrames[v3].pTextureName, i);
|
|
205
|
|
206 }
|
|
207 v12 = pSprites_LOD->LoadSprite(sprite_name, pSpriteSFrames[v3].uPaletteID);
|
|
208 pSpriteSFrames[v3].pHwSpriteIDs[i]=v12;
|
|
209
|
|
210 }
|
|
211 }
|
|
212
|
|
213 if ( !(pSpriteSFrames[v3].uFlags & 1) )
|
|
214 return;
|
|
215 ++v3;
|
|
216 }
|
|
217 }
|
|
218 }
|
|
219 }
|
|
220 }
|
|
221
|
|
222 //----- (0044D813) --------------------------------------------------------
|
|
223 signed int SpriteFrameTable::FastFindSprite( char *pSpriteName )
|
|
224 {
|
|
225 signed int result; // eax@2
|
|
226
|
|
227 int searchResult = BinarySearch(pSpriteName);
|
|
228 if ( searchResult < 0 )
|
|
229 result = 0;
|
|
230 else
|
|
231 result = this->pSpriteEFrames[searchResult];
|
|
232 return result;
|
|
233 }
|
|
234
|
|
235 //----- (0044D83A) --------------------------------------------------------
|
|
236 int SpriteFrameTable::BinarySearch( const char *pSpriteName )
|
|
237 {
|
|
238 int startPos = 0;
|
|
239 int endPos = uNumEFrames;
|
|
240 while ( 1 )
|
|
241 {
|
|
242 int searchRange = endPos - startPos;
|
|
243 int middleFrameIndex = startPos + (endPos - startPos) / 2;
|
|
244 int comparisonResult = _stricmp(pSpriteName, this->pSpritePFrames[middleFrameIndex]->pIconName);
|
|
245 if ( !comparisonResult )
|
|
246 {
|
|
247 return middleFrameIndex;
|
|
248 }
|
|
249 if ( startPos == endPos )
|
|
250 {
|
|
251 return -1;
|
|
252 }
|
|
253 if ( comparisonResult >= 0 )
|
|
254 {
|
|
255 startPos += max(((endPos - startPos) / 2), 1);
|
|
256 }
|
|
257 else{
|
|
258 endPos = max(((endPos - startPos) / 2), 1) + startPos;
|
|
259 }
|
|
260 }
|
|
261 }
|
|
262
|
|
263 //----- (0044D8D0) --------------------------------------------------------
|
|
264 SpriteFrame *SpriteFrameTable::GetFrame(unsigned int uSpriteID, unsigned int uTime)
|
|
265 {
|
|
266 //SpriteFrame *v3; // edi@1
|
|
267 SpriteFrame *v4; // ecx@1
|
|
268 //__int16 v5; // dx@2
|
|
269 //int v6; // edx@3
|
|
270 //unsigned int v7; // eax@3
|
|
271 //char *i; // ecx@3
|
|
272 //int v9; // esi@5
|
|
273 //SpriteFrame *result; // eax@6
|
|
274
|
|
275 v4 = &pSpriteSFrames[uSpriteID];
|
|
276 if (~v4->uFlags & 1 || !v4->uAnimLength)
|
|
277 return pSpriteSFrames + uSpriteID;
|
|
278
|
|
279 for (uint t = (uTime / 8) % v4->uAnimLength; t > v4->uAnimTime; ++v4)
|
|
280 t -= v4->uAnimTime;
|
|
281 return v4;
|
|
282
|
|
283 /*for (v4; v4->uAnimTime <= t; ++v4)
|
|
284
|
|
285 v6 = (uTime / 8) % v4->uAnimLength;
|
|
286 //v7 = uSpriteID;
|
|
287 for ( i = (char *)&v4->uAnimTime; ; i += 60 )
|
|
288 {
|
|
289 v9 = *(short *)i;
|
|
290 if ( v6 <= v9 )
|
|
291 break;
|
|
292 v6 -= v9;
|
|
293 ++v7;
|
|
294 }
|
|
295 return &pSpriteSFrames[v7];*/
|
|
296
|
|
297 }
|
|
298
|
|
299 //----- (0044D91F) --------------------------------------------------------
|
|
300 SpriteFrame *SpriteFrameTable::GetFrameBy_x(unsigned int uSpriteID, signed int a3)
|
|
301 {
|
|
302 SpriteFrame *v3; // edi@1
|
|
303 SpriteFrame *v4; // esi@1
|
|
304 __int16 v5; // ax@2
|
|
305 int v6; // ecx@3
|
|
306 int v7; // edx@3
|
|
307 unsigned int v8; // eax@3
|
|
308 int v9; // ecx@3
|
|
309 char *i; // edx@3
|
|
310 int v11; // esi@5
|
|
311 SpriteFrame *result; // eax@6
|
|
312
|
|
313 v3 = this->pSpriteSFrames;
|
|
314 v4 = &v3[uSpriteID];
|
|
315 if ( v4->uFlags & 1 && (v5 = v4->uAnimLength) != 0 )
|
|
316 {
|
|
317 v6 = v5;
|
|
318 v7 = a3 % v5;
|
|
319 v8 = uSpriteID;
|
|
320 v9 = v6 - v7;
|
|
321 for ( i = (char *)&v4->uAnimTime; ; i += 60 )
|
|
322 {
|
|
323 v11 = *(short *)i;
|
|
324 if ( v9 <= v11 )
|
|
325 break;
|
|
326 v9 -= v11;
|
|
327 ++v8;
|
|
328 }
|
|
329 result = &v3[v8];
|
|
330 }
|
|
331 else
|
|
332 {
|
|
333 result = &v3[uSpriteID];
|
|
334 }
|
|
335 return result;
|
|
336 }
|
|
337
|
|
338 //----- (0044D96D) --------------------------------------------------------
|
|
339 void SpriteFrameTable::ToFile()
|
|
340 {
|
|
341 SpriteFrameTable *v1; // esi@1
|
|
342 FILE *v2; // eax@1
|
|
343 FILE *v3; // edi@1
|
|
344
|
|
345 v1 = this;
|
|
346 v2 = fopen("data\\dsft.bin", "wb");
|
|
347 v3 = v2;
|
|
348 if ( !v2 )
|
|
349 Error("Unable to save dsft.bin!");
|
|
350 fwrite(v1, 4u, 1u, v2);
|
|
351 fwrite(&v1->uNumEFrames, 4u, 1u, v3);
|
|
352 fwrite(v1->pSpriteSFrames, 0x3Cu, v1->uNumSpriteFrames, v3);
|
|
353 fwrite(v1->pSpriteEFrames, 2u, v1->uNumEFrames, v3);
|
|
354 fclose(v3);
|
|
355 }
|
|
356
|
|
357 //----- (0044D9D7) --------------------------------------------------------
|
|
358 void SpriteFrameTable::FromFile(void *data_mm6, void *data_mm7, void *data_mm8)
|
|
359 {
|
|
360 uint num_mm6_frames = 0;
|
|
361 uint num_mm6_eframes = 0;
|
|
362 if (data_mm6)
|
|
363 {
|
|
364 num_mm6_frames = *(int *)data_mm6;
|
|
365 num_mm6_eframes = *((int *)data_mm6 + 1);
|
|
366 }
|
|
367
|
|
368 uint num_mm7_frames = 0;
|
|
369 uint num_mm7_eframes = 0;
|
|
370 if (data_mm7)
|
|
371 {
|
|
372 num_mm7_frames = *(int *)data_mm7;
|
|
373 num_mm7_eframes = *((int *)data_mm7 + 1);
|
|
374 }
|
|
375
|
|
376 uint num_mm8_frames = 0;
|
|
377 uint num_mm8_eframes = 0;
|
|
378 if (data_mm8)
|
|
379 {
|
|
380 num_mm8_frames = *(int *)data_mm8;
|
|
381 num_mm8_eframes = *((int *)data_mm8 + 1);
|
|
382 }
|
|
383
|
|
384 uNumSpriteFrames = num_mm6_frames + num_mm7_frames + num_mm8_frames;
|
|
385 uNumEFrames = num_mm6_eframes + num_mm7_eframes + num_mm8_eframes;
|
|
386
|
|
387 pSpriteSFrames = (SpriteFrame *)malloc(uNumSpriteFrames * sizeof(SpriteFrame));
|
|
388 pSpriteEFrames = (__int16 *)malloc(uNumSpriteFrames * sizeof(short));
|
|
389
|
|
390 pSpritePFrames = (SpriteFrame **)malloc(4 * uNumSpriteFrames);
|
|
391
|
|
392 uint mm7_frames_size = num_mm7_frames * sizeof(SpriteFrame);
|
|
393 memcpy(pSpriteSFrames, (char *)data_mm7 + 8, mm7_frames_size);
|
|
394 memcpy(pSpriteEFrames, (char *)data_mm7 + 8 + mm7_frames_size, 2 * num_mm7_eframes);
|
|
395
|
|
396 uint mm6_frames_size = num_mm6_frames * sizeof(SpriteFrame_mm6);
|
|
397 for (uint i = 0; i < num_mm6_frames; ++i)
|
|
398 {
|
|
399 memcpy(pSpriteSFrames + num_mm7_frames + i, (char *)data_mm6 + 8 + i * sizeof(SpriteFrame_mm6), sizeof(SpriteFrame_mm6));
|
|
400 pSpriteSFrames[num_mm7_frames + i].uAnimLength = 0;
|
|
401 }
|
|
402 memcpy(pSpriteEFrames + num_mm7_frames, (char *)data_mm6 + 8 + mm6_frames_size, 2 * num_mm6_eframes);
|
|
403
|
|
404 uint mm8_frames_size = num_mm8_frames * sizeof(SpriteFrame);
|
|
405 memcpy(pSpriteSFrames + num_mm6_frames + num_mm7_frames, (char *)data_mm8 + 8, mm8_frames_size);
|
|
406 memcpy(pSpriteEFrames + num_mm6_frames + num_mm7_frames, (char *)data_mm8 + 8 + mm8_frames_size, 2 * num_mm8_eframes);
|
|
407
|
|
408 //the original was using num_mmx_frames, but never accessed any element beyond num_mmx_eframes, but boing beyong eframes caused invalid memory accesses
|
|
409 for (uint i = 0; i < num_mm6_eframes + num_mm7_eframes + num_mm8_eframes; ++i)
|
|
410 pSpritePFrames[i] = &pSpriteSFrames[pSpriteEFrames[i]];
|
|
411 }
|
|
412
|
|
413 //----- (0044DA92) --------------------------------------------------------
|
|
414 bool SpriteFrameTable::FromFileTxt(const char *Args)
|
|
415 {
|
|
416 SpriteFrameTable *v2; // ebx@1
|
|
417 FILE *v3; // eax@1
|
|
418 unsigned int v4; // esi@3
|
|
419 signed int result; // eax@10
|
|
420 FILE *v6; // ST18_4@11
|
|
421 char *i; // eax@11
|
|
422 const char *v8; // ST20_4@14
|
|
423 __int16 v9; // ax@14
|
|
424 const char *v10; // ST0C_4@14
|
|
425 double v11; // st7@14
|
|
426 int v12; // eax@14
|
|
427 const char *v13; // ST04_4@14
|
|
428 __int16 v14; // ax@14
|
|
429 const char *v15; // ST00_4@14
|
|
430 int v16; // eax@14
|
|
431 int v17; // eax@17
|
|
432 int v18; // eax@23
|
|
433 int v19; // eax@24
|
|
434 int v20; // eax@25
|
|
435 int v21; // eax@28
|
|
436 int v22; // eax@29
|
|
437 int j; // edi@30
|
|
438 const char *v24; // esi@31
|
|
439 int v25; // eax@32
|
|
440 int v26; // edx@53
|
|
441 int v27; // ecx@54
|
|
442 int v28; // eax@55
|
|
443 signed int k; // edx@58
|
|
444 SpriteFrame *v30; // ecx@59
|
|
445 int v31; // esi@59
|
|
446 int l; // eax@60
|
|
447 signed int v33; // eax@65
|
|
448 int v34; // edi@66
|
|
449 int v35; // esi@66
|
|
450 SpriteFrame **v36; // eax@69
|
|
451 int v37; // ecx@69
|
|
452 SpriteFrame *v38; // edx@69
|
|
453 __int16 *v39; // eax@69
|
|
454 int v40; // ecx@69
|
|
455 char Buf[500]; // [sp+Ch] [bp-2F0h]@3
|
|
456 FrameTableTxtLine v42; // [sp+200h] [bp-FCh]@4
|
|
457 FrameTableTxtLine v43; // [sp+27Ch] [bp-80h]@4
|
|
458 FILE *File; // [sp+2F8h] [bp-4h]@1
|
|
459 unsigned int Argsa; // [sp+304h] [bp+8h]@3
|
|
460 int Argsb; // [sp+304h] [bp+8h]@59
|
|
461 FILE *Argsc; // [sp+304h] [bp+8h]@67
|
|
462
|
|
463 v2 = this;
|
|
464 ReleaseSFrames();
|
|
465 v3 = fopen(Args, "r");
|
|
466 File = v3;
|
|
467 if ( !v3 )
|
|
468 Error("CSpriteFrameTable::load - Unable to open file: %s.", Args);
|
|
469
|
|
470 v4 = 0;
|
|
471 Argsa = 0;
|
|
472 if ( fgets(Buf, 490, v3) )
|
|
473 {
|
|
474 do
|
|
475 {
|
|
476 *strchr(Buf, '\n') = 0;
|
|
477 memcpy(&v43, frame_table_txt_parser(Buf, &v42), sizeof(v43));
|
|
478 if ( v43.uPropCount && *v43.pProperties[0] != '/' )
|
|
479 ++Argsa;
|
|
480 }
|
|
481 while ( fgets(Buf, 490, File) );
|
|
482 v4 = Argsa;
|
|
483 }
|
|
484 v2->uNumSpriteFrames = v4;
|
|
485 v2->pSpriteSFrames = (SpriteFrame *)malloc(60 * v4);
|
|
486 v2->pSpriteEFrames = (__int16 *)malloc(2 * v2->uNumSpriteFrames);
|
|
487 v2->pSpritePFrames = (SpriteFrame **)malloc(4 * v2->uNumSpriteFrames);
|
|
488 if ( v2->pSpriteSFrames )
|
|
489 {
|
|
490 v6 = File;
|
|
491 v2->uNumSpriteFrames = 0;
|
|
492 fseek(v6, 0, 0);
|
|
493 for ( i = fgets(Buf, 490, File); i; i = fgets(Buf, 490, File) )
|
|
494 {
|
|
495 *strchr(Buf, 10) = 0;
|
|
496 memcpy(&v43, frame_table_txt_parser(Buf, &v42), sizeof(v43));
|
|
497 if ( v43.uPropCount && *v43.pProperties[0] != '/' )
|
|
498 {
|
|
499 v8 = v43.pProperties[0];
|
|
500 v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags = 0;
|
|
501 v2->pSpriteSFrames[v2->uNumSpriteFrames].uPaletteIndex = 0;
|
|
502 strcpy(v2->pSpriteSFrames[v2->uNumSpriteFrames].pIconName, v8);
|
|
503 strcpy(v2->pSpriteSFrames[v2->uNumSpriteFrames].pTextureName, v43.pProperties[1]);
|
|
504 v9 = atoi(v43.pProperties[3]);
|
|
505 v10 = v43.pProperties[4];
|
|
506 v2->pSpriteSFrames[v2->uNumSpriteFrames].uPaletteID = v9;
|
|
507 v11 = atof(v10) * 65536.0;
|
|
508 v12 = abs((signed __int64)v11);
|
|
509 v13 = v43.pProperties[5];
|
|
510 v2->pSpriteSFrames[v2->uNumSpriteFrames].scale = v12;
|
|
511 v14 = atoi(v13);
|
|
512 v15 = v43.pProperties[6];
|
|
513 v2->pSpriteSFrames[v2->uNumSpriteFrames].uGlowRadius = v14;
|
|
514 v2->pSpriteSFrames[v2->uNumSpriteFrames].uAnimTime = atoi(v15);
|
|
515 v16 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames];
|
|
516 if ( *(short *)(v16 + 48) )
|
|
517 *(int *)(v16 + 44) |= 2u;
|
|
518 if ( !_stricmp(v43.pProperties[2], "new") )
|
|
519 {
|
|
520 v17 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags;
|
|
521 *(int *)v17 |= 4u;
|
|
522 v2->pSpritePFrames[v2->uNumEFrames] = &v2->pSpriteSFrames[v2->uNumSpriteFrames];
|
|
523 v2->pSpriteEFrames[v2->uNumEFrames++] = LOWORD(v2->uNumSpriteFrames);
|
|
524 }
|
|
525 if ( !_stricmp(v43.pProperties[10], "1") )
|
|
526 BYTE2(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 4u;
|
|
527 if ( !_stricmp(v43.pProperties[11], "1") )
|
|
528 BYTE2(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 2u;
|
|
529 if ( !_stricmp(v43.pProperties[12], "1") )
|
|
530 {
|
|
531 v18 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags;
|
|
532 *(int *)v18 |= 0x20u;
|
|
533 }
|
|
534 v19 = atoi(v43.pProperties[7]) - 1;
|
|
535 if ( v19 )
|
|
536 {
|
|
537 v20 = v19 - 2;
|
|
538 if ( v20 )
|
|
539 {
|
|
540 if ( v20 == 2 )
|
|
541 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 0xE0u;
|
|
542 }
|
|
543 else
|
|
544 {
|
|
545 v21 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags;
|
|
546 *(int *)v21 |= 0x1E000u;
|
|
547 }
|
|
548 }
|
|
549 else
|
|
550 {
|
|
551 v22 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags;
|
|
552 *(int *)v22 |= 0x10u;
|
|
553 }
|
|
554 for ( j = 13; j < v43.uPropCount; ++j )
|
|
555 {
|
|
556 v24 = v43.pProperties[j];
|
|
557 if ( _stricmp(v43.pProperties[j], "Luminous") )
|
|
558 {
|
|
559 if ( _stricmp(v24, "Mirror0") )
|
|
560 {
|
|
561 if ( _stricmp(v24, "Mirror1") )
|
|
562 {
|
|
563 if ( _stricmp(v24, "Mirror2") )
|
|
564 {
|
|
565 if ( _stricmp(v24, "Mirror3") )
|
|
566 {
|
|
567 if ( _stricmp(v24, "Mirror4") )
|
|
568 {
|
|
569 if ( _stricmp(v24, "Mirror5") )
|
|
570 {
|
|
571 if ( _stricmp(v24, "Mirror6") )
|
|
572 {
|
|
573 if ( !_stricmp(v24, "Mirror7") )
|
|
574 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 0x80u;
|
|
575 }
|
|
576 else
|
|
577 {
|
|
578 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 0x40u;
|
|
579 }
|
|
580 }
|
|
581 else
|
|
582 {
|
|
583 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 0x20u;
|
|
584 }
|
|
585 }
|
|
586 else
|
|
587 {
|
|
588 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 0x10u;
|
|
589 }
|
|
590 }
|
|
591 else
|
|
592 {
|
|
593 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 8u;
|
|
594 }
|
|
595 }
|
|
596 else
|
|
597 {
|
|
598 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 4u;
|
|
599 }
|
|
600 }
|
|
601 else
|
|
602 {
|
|
603 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 2u;
|
|
604 }
|
|
605 }
|
|
606 else
|
|
607 {
|
|
608 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 1u;
|
|
609 }
|
|
610 }
|
|
611 else
|
|
612 {
|
|
613 v25 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags;
|
|
614 *(int *)v25 |= 2u;
|
|
615 }
|
|
616 }
|
|
617 ++v2->uNumSpriteFrames;
|
|
618 }
|
|
619 }
|
|
620 fclose(File);
|
|
621 v26 = 0;
|
|
622 if ( (signed int)(v2->uNumSpriteFrames - 1) > 0 )
|
|
623 {
|
|
624 v27 = 0;
|
|
625 do
|
|
626 {
|
|
627 v28 = (int)&v2->pSpriteSFrames[v27];
|
|
628 if ( !(*(char *)(v28 + 104) & 4) )
|
|
629 *(int *)(v28 + 44) |= 1u;
|
|
630 ++v26;
|
|
631 ++v27;
|
|
632 }
|
|
633 while ( v26 < (signed int)(v2->uNumSpriteFrames - 1) );
|
|
634 }
|
|
635 for ( k = 0; k < (signed int)v2->uNumSpriteFrames; *(short *)(Argsb + 56) = v31 )
|
|
636 {
|
|
637 v30 = v2->pSpriteSFrames;
|
|
638 Argsb = (int)&v30[k];
|
|
639 v31 = *(short *)(Argsb + 54);
|
|
640 if ( *(char *)(Argsb + 44) & 1 )
|
|
641 {
|
|
642 ++k;
|
|
643 for ( l = (int)&v30[k]; *(char *)(l + 44) & 1; l += 60 )
|
|
644 {
|
|
645 v31 += *(short *)(l + 54);
|
|
646 ++k;
|
|
647 }
|
|
648 LOWORD(v31) = v30[k].uAnimTime + v31;
|
|
649 }
|
|
650 ++k;
|
|
651 }
|
|
652 v33 = v2->uNumEFrames;
|
|
653 if ( v33 > 0 )
|
|
654 {
|
|
655 v34 = 0;
|
|
656 v35 = 0;
|
|
657 File = (FILE *)1;
|
|
658 do
|
|
659 {
|
|
660 Argsc = File;
|
|
661 if ( (signed int)File < v33 )
|
|
662 {
|
|
663 do
|
|
664 {
|
|
665 if ( _stricmp(v2->pSpritePFrames[(int)Argsc]->pIconName, v2->pSpritePFrames[v35]->pIconName) < 0 )
|
|
666 {
|
|
667 v36 = v2->pSpritePFrames;
|
|
668 v37 = (int)&v36[(int)Argsc];
|
|
669 v38 = *(SpriteFrame **)v37;
|
|
670 *(int *)v37 = (int)v36[v35];
|
|
671 v2->pSpritePFrames[v35] = v38;
|
|
672 v39 = v2->pSpriteEFrames;
|
|
673 v40 = (int)&v39[(int)Argsc];
|
|
674 LOWORD(v38) = *(short *)v40;
|
|
675 *(short *)v40 = v39[v34];
|
|
676 v2->pSpriteEFrames[v34] = (signed __int16)v38;
|
|
677 }
|
|
678 Argsc = (FILE *)((char *)Argsc + 1);
|
|
679 }
|
|
680 while ( (signed int)Argsc < v2->uNumEFrames );
|
|
681 }
|
|
682 File = (FILE *)((char *)File + 1);
|
|
683 v33 = v2->uNumEFrames;
|
|
684 ++v35;
|
|
685 ++v34;
|
|
686 }
|
|
687 while ( (signed int)((char *)File - 1) < v33 );
|
|
688 }
|
|
689 result = 1;
|
|
690 }
|
|
691 else
|
|
692 {
|
|
693 MessageBoxW(nullptr, L"CSpriteFrameTable::load - Out of Memory!", nullptr, 0);
|
|
694 fclose(File);
|
|
695 result = 0;
|
|
696 }
|
|
697 return result;
|
|
698 }
|
|
699 //----- (0046E26D) --------------------------------------------------------
|
|
700 void __fastcall _46E26D_collide_against_sprites(signed int a1, signed int a2)
|
|
701 {
|
|
702 int v2; // edx@5
|
|
703 unsigned __int16 *v3; // eax@5
|
|
704 unsigned __int16 v4; // ax@6
|
|
705 LevelDecoration *v5; // edi@7
|
|
706 DecorationDesc *v6; // esi@8
|
|
707 int v7; // edx@9
|
|
708 int v8; // eax@9
|
|
709 int v9; // ecx@11
|
|
710 int v10; // ebx@13
|
|
711 int v11; // esi@13
|
|
712 int v12; // ebp@15
|
|
713 int v13; // ebx@15
|
|
714 int v14; // esi@16
|
|
715 int v15; // edi@17
|
|
716 int v16; // eax@17
|
|
717 int v17; // esi@19
|
|
718 char v18; // zf@23
|
|
719 int v19; // [sp+0h] [bp-10h]@15
|
|
720 unsigned __int16 *v20; // [sp+4h] [bp-Ch]@5
|
|
721 int v21; // [sp+8h] [bp-8h]@15
|
|
722 int v22; // [sp+Ch] [bp-4h]@13
|
|
723
|
|
724 if ( a1 >= 0 )
|
|
725 {
|
|
726 if ( a1 <= 127 )
|
|
727 {
|
|
728 if ( a2 >= 0 )
|
|
729 {
|
|
730 if ( a2 <= 127 )
|
|
731 {
|
|
732 v2 = a1 + (a2 << 7);
|
|
733 v3 = &pOutdoor->pFaceIDLIST[pOutdoor->pOMAP[v2]];
|
|
734 v20 = &pOutdoor->pFaceIDLIST[pOutdoor->pOMAP[v2]];
|
|
735 if ( v3 )
|
|
736 {
|
|
737 do
|
|
738 {
|
|
739 v4 = *v3;
|
|
740 if ( PID_TYPE(v4) == OBJECT_Decoration)
|
|
741 {
|
|
742 v5 = &pLevelDecorations[(signed __int16)v4 >> 3];
|
|
743 if (!(v5->uFlags & LEVEL_DECORATION_INVISIBLE))
|
|
744 {
|
|
745 v6 = &pDecorationList->pDecorations[v5->uDecorationDescID];
|
|
746 if (!v6->CanMoveThrough())
|
|
747 {
|
|
748 v7 = v6->uRadius;
|
|
749 v8 = v5->vPosition.x;
|
|
750 if ( stru_721530.sMaxX <= v8 + v7 )
|
|
751 {
|
|
752 if ( stru_721530.sMinX >= v8 - v7 )
|
|
753 {
|
|
754 v9 = v5->vPosition.y;
|
|
755 if ( stru_721530.sMaxY <= v9 + v7 )
|
|
756 {
|
|
757 if ( stru_721530.sMinY >= v9 - v7 )
|
|
758 {
|
|
759 v10 = v6->uDecorationHeight;
|
|
760 v11 = v5->vPosition.z;
|
|
761 v22 = v10;
|
|
762 if ( stru_721530.sMaxZ <= v11 + v10 )
|
|
763 {
|
|
764 if ( stru_721530.sMinZ >= v11 )
|
|
765 {
|
|
766 v12 = v8 - stru_721530.normal.x;
|
|
767 v19 = v9 - stru_721530.normal.y;
|
|
768 v13 = stru_721530.prolly_normal_d + v7;
|
|
769 v21 = ((v8 - stru_721530.normal.x) * stru_721530.direction.y
|
|
770 - (v9 - stru_721530.normal.y) * stru_721530.direction.x) >> 16;
|
|
771 if ( abs(v21) <= stru_721530.prolly_normal_d + v7 )
|
|
772 {
|
|
773 v14 = (v12 * stru_721530.direction.x + v19 * stru_721530.direction.y) >> 16;
|
|
774 if ( v14 > 0 )
|
|
775 {
|
|
776 v15 = v5->vPosition.z;
|
|
777 v16 = stru_721530.normal.z + fixpoint_mul(stru_721530.direction.z, v14);
|
|
778 if ( v16 >= v15 )
|
|
779 {
|
|
780 if ( v16 <= v22 + v15 )
|
|
781 {
|
|
782 v17 = v14 - integer_sqrt(v13 * v13 - v21 * v21);
|
|
783 if ( v17 < 0 )
|
|
784 v17 = 0;
|
|
785 if ( v17 < stru_721530.field_7C )
|
|
786 {
|
|
787 stru_721530.field_7C = v17;
|
|
788 stru_721530.uFaceID = (signed __int16)*v20;
|
|
789 }
|
|
790 }
|
|
791 }
|
|
792 }
|
|
793 }
|
|
794 }
|
|
795 }
|
|
796 }
|
|
797 }
|
|
798 }
|
|
799 }
|
|
800 }
|
|
801 }
|
|
802 }
|
|
803 v3 = v20 + 1;
|
|
804 v18 = *v20 == 0;
|
|
805 ++v20;
|
|
806 }
|
|
807 while ( !v18 );
|
|
808 }
|
|
809 }
|
|
810 }
|
|
811 }
|
|
812 }
|
|
813 }
|