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