Mercurial > mm7
annotate IconFrameTable.cpp @ 2342:d7f4dac06dc0
Adding Registry.h/.cpp to project
author | Grumpy7 |
---|---|
date | Sun, 06 Apr 2014 12:57:04 +0200 |
parents | d6887ee81068 |
children | f4af3b203f65 |
rev | line source |
---|---|
2253
aff7a7b072b7
adding _CRT_SECURE_NO_WARNINGS to get rid of a few hundrer annoying warnings + adding count parameter to swprintf
Grumpy7
parents:
2098
diff
changeset
|
1 #define _CRT_SECURE_NO_WARNINGS |
2336 | 2 #include "ErrorHandling.h" |
1295 | 3 #include "IconFrameTable.h" |
4 #include "LOD.h" | |
5 #include "mm7_data.h" | |
6 #include "FrameTableInc.h" | |
7 | |
8 //----- (00494F3A) -------------------------------------------------------- | |
9 unsigned int IconFrameTable::FindIcon(const char *pIconName) | |
10 { | |
2273 | 11 for ( uint i = 0; i < (signed int)this->uNumIcons; i++ ) |
1295 | 12 { |
2273 | 13 if ( !_stricmp(pIconName, this->pIcons[i].pAnimationName) ) |
14 return i; | |
1295 | 15 } |
2273 | 16 return 0; |
1295 | 17 } |
18 | |
19 //----- (00494F70) -------------------------------------------------------- | |
20 IconFrame *IconFrameTable::GetFrame(unsigned int uIconID, unsigned int uFrameID) | |
21 { | |
22 int v6; // edx@3 | |
2273 | 23 uint i; |
1295 | 24 |
2273 | 25 if ( this->pIcons[uIconID].uFlags & 1 && this->pIcons[uIconID].uAnimLength != 0 ) |
1295 | 26 { |
2273 | 27 v6 = ((signed int)uFrameID >> 3) % (unsigned __int16)this->pIcons[uIconID].uAnimLength; |
28 for ( i = uIconID; v6 > this->pIcons[i].uAnimTime; i++ ) | |
29 v6 -= this->pIcons[i].uAnimTime; | |
30 return &this->pIcons[i]; | |
1295 | 31 } |
32 else | |
2273 | 33 return &this->pIcons[uIconID]; |
1295 | 34 } |
35 | |
36 //----- (00494FBF) -------------------------------------------------------- | |
37 void IconFrameTable::InitializeAnimation(unsigned int uIconID) | |
38 { | |
39 unsigned int v3; // edi@3 | |
40 const char *i; // eax@3 | |
41 | |
42 if ( (signed int)uIconID <= (signed int)this->uNumIcons && (uIconID & 0x80000000u) == 0 ) | |
43 { | |
44 v3 = uIconID; | |
2273 | 45 for ( i = this->pIcons[uIconID].pTextureName; ; i = this->pIcons[v3].pTextureName ) |
1295 | 46 { |
2273 | 47 this->pIcons[v3].uTextureID = pIcons_LOD->LoadTexture(i, TEXTURE_16BIT_PALETTE); |
48 if ( !(this->pIcons[v3].uFlags & 1) ) | |
1295 | 49 break; |
50 ++v3; | |
51 } | |
52 } | |
53 } | |
54 | |
55 //----- (0049500A) -------------------------------------------------------- | |
56 void IconFrameTable::ToFile() | |
57 { | |
2273 | 58 //IconFrameTable *v1; // esi@1 |
1295 | 59 FILE *v2; // eax@1 |
2273 | 60 //FILE *v3; // edi@1 |
1295 | 61 |
2273 | 62 //IconFrameTable* Str = this; |
1295 | 63 |
2273 | 64 //v1 = Str; |
1295 | 65 v2 = fopen("data\\dift.bin", "wb"); |
2273 | 66 //v3 = v2; |
1295 | 67 if ( !v2 ) |
1545 | 68 Error("Unable to save dift.bin!"); |
2273 | 69 fwrite(this, 4, 1, v2); |
70 fwrite(this->pIcons, 0x20u, this->uNumIcons, v2); | |
71 fclose(v2); | |
1295 | 72 } |
73 | |
74 //----- (00495056) -------------------------------------------------------- | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
75 void IconFrameTable::FromFile(void *data_mm6, void *data_mm7, void *data_mm8) |
1295 | 76 { |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
77 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
|
78 num_mm7_frames = data_mm7 ? *(int *)data_mm7 : 0, |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
79 num_mm8_frames = data_mm8 ? *(int *)data_mm8 : 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
80 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
81 uNumIcons = num_mm6_frames + num_mm7_frames + num_mm8_frames; |
1545 | 82 Assert(uNumIcons); |
83 Assert(!num_mm8_frames); | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
84 |
1583 | 85 pIcons = (IconFrame *)malloc(uNumIcons * sizeof(IconFrame)); |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
86 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
|
87 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
|
88 memcpy(pIcons + num_mm6_frames + num_mm7_frames, (char *)data_mm8 + 4, num_mm8_frames * sizeof(IconFrame)); |
1295 | 89 } |
90 | |
91 //----- (0049509D) -------------------------------------------------------- | |
92 int IconFrameTable::FromFileTxt(const char *Args) | |
93 { | |
2273 | 94 //IconFrameTable *v2; // ebx@1 |
1295 | 95 FILE *v3; // eax@1 |
96 int v4; // esi@3 | |
97 void *v5; // eax@10 | |
98 FILE *v6; // ST0C_4@12 | |
99 char *i; // eax@12 | |
100 const char *v8; // ST00_4@15 | |
101 int v9; // eax@16 | |
102 int v10; // edx@20 | |
103 int v11; // ecx@21 | |
104 int v12; // eax@22 | |
105 signed int j; // edx@25 | |
106 IconFrame *v14; // ecx@26 | |
107 int v15; // esi@26 | |
108 int k; // eax@27 | |
109 signed int result; // eax@11 | |
110 char Buf; // [sp+Ch] [bp-2F8h]@3 | |
111 FrameTableTxtLine v19; // [sp+200h] [bp-104h]@4 | |
112 FrameTableTxtLine v20; // [sp+27Ch] [bp-88h]@4 | |
113 int v21; // [sp+2F8h] [bp-Ch]@3 | |
114 int v22; // [sp+2FCh] [bp-8h]@3 | |
115 FILE *File; // [sp+300h] [bp-4h]@1 | |
116 int Argsa; // [sp+30Ch] [bp+8h]@26 | |
117 | |
2273 | 118 //v2 = this; |
1295 | 119 //TileTable::dtor((TileTable *)this); |
2273 | 120 __debugbreak();//Ritor1: this function not used |
1295 | 121 v3 = fopen(Args, "r"); |
122 File = v3; | |
123 if ( !v3 ) | |
1545 | 124 Error("IconFrameTable::load - Unable to open file: %s.", Args); |
1295 | 125 v4 = 0; |
126 v21 = 0; | |
127 v22 = 1; | |
128 if ( fgets(&Buf, 490, v3) ) | |
129 { | |
130 do | |
131 { | |
132 *strchr(&Buf, 10) = 0; | |
133 memcpy(&v20, frame_table_txt_parser(&Buf, &v19), sizeof(v20)); | |
134 if ( v20.uPropCount && *v20.pProperties[0] != 47 ) | |
135 { | |
136 if ( v20.uPropCount < 3 ) | |
1545 | 137 Error("IconFrameTable::loadText, too few arguments, %s line %i.", Args, v22); |
1295 | 138 ++v21; |
139 } | |
140 ++v22; | |
141 } | |
142 while ( fgets(&Buf, 490, File) ); | |
143 v4 = v21; | |
144 } | |
2273 | 145 this->uNumIcons = v4; |
1583 | 146 v5 = malloc(32 * v4);//, "I Frames"); |
2273 | 147 this->pIcons = (IconFrame *)v5; |
1295 | 148 if ( v5 ) |
149 { | |
150 v6 = File; | |
2273 | 151 this->uNumIcons = 0; |
1295 | 152 fseek(v6, 0, 0); |
153 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) | |
154 { | |
155 *strchr(&Buf, 10) = 0; | |
156 memcpy(&v20, frame_table_txt_parser(&Buf, &v19), sizeof(v20)); | |
157 if ( v20.uPropCount && *v20.pProperties[0] != 47 ) | |
158 { | |
2273 | 159 strcpy(this->pIcons[this->uNumIcons].pAnimationName, v20.pProperties[0]); |
160 strcpy(this->pIcons[this->uNumIcons].pTextureName, v20.pProperties[1]); | |
1295 | 161 v8 = v20.pProperties[2]; |
2273 | 162 this->pIcons[this->uNumIcons].uFlags = 0; |
1295 | 163 if ( !_stricmp(v8, "new") ) |
164 { | |
2273 | 165 v9 = (int)&this->pIcons[this->uNumIcons].uFlags; |
1295 | 166 *(char *)v9 |= 4u; |
167 } | |
2273 | 168 this->pIcons[this->uNumIcons].uAnimTime = atoi(v20.pProperties[3]); |
169 this->pIcons[this->uNumIcons].uAnimLength = 0; | |
170 this->pIcons[this->uNumIcons++].uTextureID = 0; | |
1295 | 171 } |
172 } | |
173 fclose(File); | |
174 v10 = 0; | |
2273 | 175 if ( (signed int)(this->uNumIcons - 1) > 0 ) |
1295 | 176 { |
177 v11 = 0; | |
178 do | |
179 { | |
2273 | 180 v12 = (int)&this->pIcons[v11]; |
1295 | 181 if ( !(*(char *)(v12 + 60) & 4) ) |
182 *(char *)(v12 + 28) |= 1u; | |
183 ++v10; | |
184 ++v11; | |
185 } | |
2273 | 186 while ( v10 < (signed int)(this->uNumIcons - 1) ); |
1295 | 187 } |
2273 | 188 for ( j = 0; j < (signed int)this->uNumIcons; *(short *)(Argsa + 26) = v15 ) |
1295 | 189 { |
2273 | 190 v14 = this->pIcons; |
1295 | 191 Argsa = (int)&v14[j]; |
192 v15 = *(short *)(Argsa + 24); | |
193 if ( *(char *)(Argsa + 28) & 1 ) | |
194 { | |
195 ++j; | |
196 for ( k = (int)&v14[j]; *(char *)(k + 28) & 1; k += 32 ) | |
197 { | |
198 v15 += *(short *)(k + 24); | |
199 ++j; | |
200 } | |
201 LOWORD(v15) = v14[j].uAnimTime + v15; | |
202 } | |
203 ++j; | |
204 } | |
205 result = 1; | |
206 } | |
207 else | |
208 { | |
209 fclose(File); | |
210 result = 0; | |
211 } | |
212 return result; | |
1296 | 213 } |
214 //----- (0042EB78) -------------------------------------------------------- | |
215 int IconFrameTable::GetIconAnimLength(unsigned int uIconID) | |
216 { | |
217 return 8 * this->pIcons[uIconID].uAnimLength; | |
1295 | 218 } |