Mercurial > mm7
annotate IconFrameTable.cpp @ 1549:5a3afcaa6717
Player::CalculateMeleeDamageTo removed labels, ifdowhile patterns changed to for cycles, magic numbers to enum values, fixing gibbet being only undead slaying
author | Grumpy7 |
---|---|
date | Sat, 07 Sep 2013 09:16:55 +0200 |
parents | 7ef4b64f6329 |
children | c4ab816fcc5e |
rev | line source |
---|---|
1295 | 1 #include "IconFrameTable.h" |
2 #include "LOD.h" | |
3 #include "mm7_data.h" | |
4 #include "Allocator.h" | |
5 #include "FrameTableInc.h" | |
6 | |
7 //----- (00494F3A) -------------------------------------------------------- | |
8 unsigned int IconFrameTable::FindIcon(const char *pIconName) | |
9 { | |
10 IconFrameTable *v2; // esi@1 | |
11 int v3; // ebx@1 | |
12 unsigned int uID; // edi@1 | |
13 unsigned int result; // eax@4 | |
14 | |
15 v2 = this; | |
16 v3 = 0; | |
17 uID = 0; | |
18 if ( (signed int)this->uNumIcons <= 0 ) | |
19 { | |
20 LABEL_4: | |
21 result = 0; | |
22 } | |
23 else | |
24 { | |
25 while ( _stricmp(pIconName, v2->pIcons[v3].pAnimationName) ) | |
26 { | |
27 ++uID; | |
28 ++v3; | |
29 if ( (signed int)uID >= (signed int)v2->uNumIcons ) | |
30 goto LABEL_4; | |
31 } | |
32 result = uID; | |
33 } | |
34 return result; | |
35 } | |
36 | |
37 //----- (00494F70) -------------------------------------------------------- | |
38 IconFrame *IconFrameTable::GetFrame(unsigned int uIconID, unsigned int uFrameID) | |
39 { | |
40 IconFrame *v3; // edi@1 | |
41 IconFrame *v4; // ecx@1 | |
42 __int16 v5; // dx@2 | |
43 int v6; // edx@3 | |
44 unsigned int v7; // eax@3 | |
45 char *i; // ecx@3 | |
46 int v9; // esi@5 | |
47 IconFrame *result; // eax@6 | |
48 | |
49 v3 = this->pIcons; | |
50 v4 = &v3[uIconID]; | |
51 if ( v4->uFlags & 1 && (v5 = v4->uAnimLength) != 0 ) | |
52 { | |
53 v6 = ((signed int)uFrameID >> 3) % (unsigned __int16)v5; | |
54 v7 = uIconID; | |
55 for ( i = (char *)&v4->uAnimTime; ; i += 32 ) | |
56 { | |
57 v9 = *(short *)i; | |
58 if ( v6 <= v9 ) | |
59 break; | |
60 v6 -= v9; | |
61 ++v7; | |
62 } | |
63 result = &v3[v7]; | |
64 } | |
65 else | |
66 { | |
67 result = &v3[uIconID]; | |
68 } | |
69 return result; | |
70 } | |
71 | |
72 //----- (00494FBF) -------------------------------------------------------- | |
73 void IconFrameTable::InitializeAnimation(unsigned int uIconID) | |
74 { | |
75 IconFrameTable *v2; // esi@1 | |
76 unsigned int v3; // edi@3 | |
77 const char *i; // eax@3 | |
78 IconFrame *v5; // eax@5 | |
79 | |
80 v2 = this; | |
81 if ( (signed int)uIconID <= (signed int)this->uNumIcons && (uIconID & 0x80000000u) == 0 ) | |
82 { | |
83 v3 = uIconID; | |
84 for ( i = this->pIcons[uIconID].pTextureName; ; i = v5[v3].pTextureName ) | |
85 { | |
86 v2->pIcons[v3].uTextureID = pIcons_LOD->LoadTexture(i, TEXTURE_16BIT_PALETTE); | |
87 v5 = v2->pIcons; | |
88 if ( !(v5[v3].uFlags & 1) ) | |
89 break; | |
90 ++v3; | |
91 } | |
92 } | |
93 } | |
94 | |
95 //----- (0049500A) -------------------------------------------------------- | |
96 void IconFrameTable::ToFile() | |
97 { | |
98 IconFrameTable *v1; // esi@1 | |
99 FILE *v2; // eax@1 | |
100 FILE *v3; // edi@1 | |
101 | |
102 auto Str = this; | |
103 | |
104 v1 = Str; | |
105 v2 = fopen("data\\dift.bin", "wb"); | |
106 v3 = v2; | |
107 if ( !v2 ) | |
108 Abortf("Unable to save dift.bin!"); | |
109 fwrite(v1, 4u, 1u, v2); | |
110 fwrite(v1->pIcons, 0x20u, v1->uNumIcons, v3); | |
111 fclose(v3); | |
112 } | |
113 | |
114 //----- (00495056) -------------------------------------------------------- | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
115 void IconFrameTable::FromFile(void *data_mm6, void *data_mm7, void *data_mm8) |
1295 | 116 { |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
117 uint num_mm6_frames = data_mm6 ? *(int *)data_mm6 : 0, |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
118 num_mm7_frames = data_mm7 ? *(int *)data_mm7 : 0, |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
119 num_mm8_frames = data_mm8 ? *(int *)data_mm8 : 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
120 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
121 uNumIcons = num_mm6_frames + num_mm7_frames + num_mm8_frames; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
122 assert(uNumIcons); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
123 assert(!num_mm8_frames); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
124 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
125 pIcons = (IconFrame *)pAllocator->AllocNamedChunk(pIcons, uNumIcons * sizeof(IconFrame), "I Frames"); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
126 memcpy(pIcons, (char *)data_mm7 + 4, num_mm7_frames * sizeof(IconFrame)); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
127 memcpy(pIcons + num_mm7_frames, (char *)data_mm6 + 4, num_mm6_frames * sizeof(IconFrame)); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
128 memcpy(pIcons + num_mm6_frames + num_mm7_frames, (char *)data_mm8 + 4, num_mm8_frames * sizeof(IconFrame)); |
1295 | 129 } |
130 | |
131 //----- (0049509D) -------------------------------------------------------- | |
132 int IconFrameTable::FromFileTxt(const char *Args) | |
133 { | |
134 IconFrameTable *v2; // ebx@1 | |
135 FILE *v3; // eax@1 | |
136 int v4; // esi@3 | |
137 void *v5; // eax@10 | |
138 FILE *v6; // ST0C_4@12 | |
139 char *i; // eax@12 | |
140 const char *v8; // ST00_4@15 | |
141 int v9; // eax@16 | |
142 int v10; // edx@20 | |
143 int v11; // ecx@21 | |
144 int v12; // eax@22 | |
145 signed int j; // edx@25 | |
146 IconFrame *v14; // ecx@26 | |
147 int v15; // esi@26 | |
148 int k; // eax@27 | |
149 signed int result; // eax@11 | |
150 char Buf; // [sp+Ch] [bp-2F8h]@3 | |
151 FrameTableTxtLine v19; // [sp+200h] [bp-104h]@4 | |
152 FrameTableTxtLine v20; // [sp+27Ch] [bp-88h]@4 | |
153 int v21; // [sp+2F8h] [bp-Ch]@3 | |
154 int v22; // [sp+2FCh] [bp-8h]@3 | |
155 FILE *File; // [sp+300h] [bp-4h]@1 | |
156 int Argsa; // [sp+30Ch] [bp+8h]@26 | |
157 | |
158 v2 = this; | |
159 //TileTable::dtor((TileTable *)this); | |
160 v3 = fopen(Args, "r"); | |
161 File = v3; | |
162 if ( !v3 ) | |
163 Abortf("IconFrameTable::load - Unable to open file: %s.", Args); | |
164 v4 = 0; | |
165 v21 = 0; | |
166 v22 = 1; | |
167 if ( fgets(&Buf, 490, v3) ) | |
168 { | |
169 do | |
170 { | |
171 *strchr(&Buf, 10) = 0; | |
172 memcpy(&v20, frame_table_txt_parser(&Buf, &v19), sizeof(v20)); | |
173 if ( v20.uPropCount && *v20.pProperties[0] != 47 ) | |
174 { | |
175 if ( v20.uPropCount < 3 ) | |
176 Abortf("IconFrameTable::loadText, too few arguments, %s line %i.", Args, v22); | |
177 ++v21; | |
178 } | |
179 ++v22; | |
180 } | |
181 while ( fgets(&Buf, 490, File) ); | |
182 v4 = v21; | |
183 } | |
184 v2->uNumIcons = v4; | |
185 v5 = pAllocator->AllocNamedChunk(v2->pIcons, 32 * v4, "I Frames"); | |
186 v2->pIcons = (IconFrame *)v5; | |
187 if ( v5 ) | |
188 { | |
189 v6 = File; | |
190 v2->uNumIcons = 0; | |
191 fseek(v6, 0, 0); | |
192 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) | |
193 { | |
194 *strchr(&Buf, 10) = 0; | |
195 memcpy(&v20, frame_table_txt_parser(&Buf, &v19), sizeof(v20)); | |
196 if ( v20.uPropCount && *v20.pProperties[0] != 47 ) | |
197 { | |
198 strcpy(v2->pIcons[v2->uNumIcons].pAnimationName, v20.pProperties[0]); | |
199 strcpy(v2->pIcons[v2->uNumIcons].pTextureName, v20.pProperties[1]); | |
200 v8 = v20.pProperties[2]; | |
201 v2->pIcons[v2->uNumIcons].uFlags = 0; | |
202 if ( !_stricmp(v8, "new") ) | |
203 { | |
204 v9 = (int)&v2->pIcons[v2->uNumIcons].uFlags; | |
205 *(char *)v9 |= 4u; | |
206 } | |
207 v2->pIcons[v2->uNumIcons].uAnimTime = atoi(v20.pProperties[3]); | |
208 v2->pIcons[v2->uNumIcons].uAnimLength = 0; | |
209 v2->pIcons[v2->uNumIcons++].uTextureID = 0; | |
210 } | |
211 } | |
212 fclose(File); | |
213 v10 = 0; | |
214 if ( (signed int)(v2->uNumIcons - 1) > 0 ) | |
215 { | |
216 v11 = 0; | |
217 do | |
218 { | |
219 v12 = (int)&v2->pIcons[v11]; | |
220 if ( !(*(char *)(v12 + 60) & 4) ) | |
221 *(char *)(v12 + 28) |= 1u; | |
222 ++v10; | |
223 ++v11; | |
224 } | |
225 while ( v10 < (signed int)(v2->uNumIcons - 1) ); | |
226 } | |
227 for ( j = 0; j < (signed int)v2->uNumIcons; *(short *)(Argsa + 26) = v15 ) | |
228 { | |
229 v14 = v2->pIcons; | |
230 Argsa = (int)&v14[j]; | |
231 v15 = *(short *)(Argsa + 24); | |
232 if ( *(char *)(Argsa + 28) & 1 ) | |
233 { | |
234 ++j; | |
235 for ( k = (int)&v14[j]; *(char *)(k + 28) & 1; k += 32 ) | |
236 { | |
237 v15 += *(short *)(k + 24); | |
238 ++j; | |
239 } | |
240 LOWORD(v15) = v14[j].uAnimTime + v15; | |
241 } | |
242 ++j; | |
243 } | |
244 result = 1; | |
245 } | |
246 else | |
247 { | |
248 fclose(File); | |
249 result = 0; | |
250 } | |
251 return result; | |
1296 | 252 } |
253 //----- (0042EB78) -------------------------------------------------------- | |
254 int IconFrameTable::GetIconAnimLength(unsigned int uIconID) | |
255 { | |
256 return 8 * this->pIcons[uIconID].uAnimLength; | |
1295 | 257 } |