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