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) --------------------------------------------------------
|
|
115 void IconFrameTable::FromFile(void *pSerialized)
|
|
116 {
|
|
117 uNumIcons = *(int *)pSerialized;
|
|
118 pIcons = (IconFrame *)pAllocator->AllocNamedChunk(pIcons, 32 * uNumIcons, "I Frames");
|
|
119 memcpy(pIcons, (char *)pSerialized + 4, 32 * uNumIcons);
|
|
120 }
|
|
121
|
|
122 //----- (0049509D) --------------------------------------------------------
|
|
123 int IconFrameTable::FromFileTxt(const char *Args)
|
|
124 {
|
|
125 IconFrameTable *v2; // ebx@1
|
|
126 FILE *v3; // eax@1
|
|
127 int v4; // esi@3
|
|
128 void *v5; // eax@10
|
|
129 FILE *v6; // ST0C_4@12
|
|
130 char *i; // eax@12
|
|
131 const char *v8; // ST00_4@15
|
|
132 int v9; // eax@16
|
|
133 int v10; // edx@20
|
|
134 int v11; // ecx@21
|
|
135 int v12; // eax@22
|
|
136 signed int j; // edx@25
|
|
137 IconFrame *v14; // ecx@26
|
|
138 int v15; // esi@26
|
|
139 int k; // eax@27
|
|
140 signed int result; // eax@11
|
|
141 char Buf; // [sp+Ch] [bp-2F8h]@3
|
|
142 FrameTableTxtLine v19; // [sp+200h] [bp-104h]@4
|
|
143 FrameTableTxtLine v20; // [sp+27Ch] [bp-88h]@4
|
|
144 int v21; // [sp+2F8h] [bp-Ch]@3
|
|
145 int v22; // [sp+2FCh] [bp-8h]@3
|
|
146 FILE *File; // [sp+300h] [bp-4h]@1
|
|
147 int Argsa; // [sp+30Ch] [bp+8h]@26
|
|
148
|
|
149 v2 = this;
|
|
150 //TileTable::dtor((TileTable *)this);
|
|
151 v3 = fopen(Args, "r");
|
|
152 File = v3;
|
|
153 if ( !v3 )
|
|
154 Abortf("IconFrameTable::load - Unable to open file: %s.", Args);
|
|
155 v4 = 0;
|
|
156 v21 = 0;
|
|
157 v22 = 1;
|
|
158 if ( fgets(&Buf, 490, v3) )
|
|
159 {
|
|
160 do
|
|
161 {
|
|
162 *strchr(&Buf, 10) = 0;
|
|
163 memcpy(&v20, frame_table_txt_parser(&Buf, &v19), sizeof(v20));
|
|
164 if ( v20.uPropCount && *v20.pProperties[0] != 47 )
|
|
165 {
|
|
166 if ( v20.uPropCount < 3 )
|
|
167 Abortf("IconFrameTable::loadText, too few arguments, %s line %i.", Args, v22);
|
|
168 ++v21;
|
|
169 }
|
|
170 ++v22;
|
|
171 }
|
|
172 while ( fgets(&Buf, 490, File) );
|
|
173 v4 = v21;
|
|
174 }
|
|
175 v2->uNumIcons = v4;
|
|
176 v5 = pAllocator->AllocNamedChunk(v2->pIcons, 32 * v4, "I Frames");
|
|
177 v2->pIcons = (IconFrame *)v5;
|
|
178 if ( v5 )
|
|
179 {
|
|
180 v6 = File;
|
|
181 v2->uNumIcons = 0;
|
|
182 fseek(v6, 0, 0);
|
|
183 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) )
|
|
184 {
|
|
185 *strchr(&Buf, 10) = 0;
|
|
186 memcpy(&v20, frame_table_txt_parser(&Buf, &v19), sizeof(v20));
|
|
187 if ( v20.uPropCount && *v20.pProperties[0] != 47 )
|
|
188 {
|
|
189 strcpy(v2->pIcons[v2->uNumIcons].pAnimationName, v20.pProperties[0]);
|
|
190 strcpy(v2->pIcons[v2->uNumIcons].pTextureName, v20.pProperties[1]);
|
|
191 v8 = v20.pProperties[2];
|
|
192 v2->pIcons[v2->uNumIcons].uFlags = 0;
|
|
193 if ( !_stricmp(v8, "new") )
|
|
194 {
|
|
195 v9 = (int)&v2->pIcons[v2->uNumIcons].uFlags;
|
|
196 *(char *)v9 |= 4u;
|
|
197 }
|
|
198 v2->pIcons[v2->uNumIcons].uAnimTime = atoi(v20.pProperties[3]);
|
|
199 v2->pIcons[v2->uNumIcons].uAnimLength = 0;
|
|
200 v2->pIcons[v2->uNumIcons++].uTextureID = 0;
|
|
201 }
|
|
202 }
|
|
203 fclose(File);
|
|
204 v10 = 0;
|
|
205 if ( (signed int)(v2->uNumIcons - 1) > 0 )
|
|
206 {
|
|
207 v11 = 0;
|
|
208 do
|
|
209 {
|
|
210 v12 = (int)&v2->pIcons[v11];
|
|
211 if ( !(*(char *)(v12 + 60) & 4) )
|
|
212 *(char *)(v12 + 28) |= 1u;
|
|
213 ++v10;
|
|
214 ++v11;
|
|
215 }
|
|
216 while ( v10 < (signed int)(v2->uNumIcons - 1) );
|
|
217 }
|
|
218 for ( j = 0; j < (signed int)v2->uNumIcons; *(short *)(Argsa + 26) = v15 )
|
|
219 {
|
|
220 v14 = v2->pIcons;
|
|
221 Argsa = (int)&v14[j];
|
|
222 v15 = *(short *)(Argsa + 24);
|
|
223 if ( *(char *)(Argsa + 28) & 1 )
|
|
224 {
|
|
225 ++j;
|
|
226 for ( k = (int)&v14[j]; *(char *)(k + 28) & 1; k += 32 )
|
|
227 {
|
|
228 v15 += *(short *)(k + 24);
|
|
229 ++j;
|
|
230 }
|
|
231 LOWORD(v15) = v14[j].uAnimTime + v15;
|
|
232 }
|
|
233 ++j;
|
|
234 }
|
|
235 result = 1;
|
|
236 }
|
|
237 else
|
|
238 {
|
|
239 fclose(File);
|
|
240 result = 0;
|
|
241 }
|
|
242 return result;
|
1296
|
243 }
|
|
244 //----- (0042EB78) --------------------------------------------------------
|
|
245 int IconFrameTable::GetIconAnimLength(unsigned int uIconID)
|
|
246 {
|
|
247 return 8 * this->pIcons[uIconID].uAnimLength;
|
1295
|
248 } |