2463
|
1 #define _CRTDBG_MAP_ALLOC
|
|
2 #include <stdlib.h>
|
|
3 #include <crtdbg.h>
|
|
4
|
|
5 #define _CRT_SECURE_NO_WARNINGS
|
|
6
|
|
7 #include "PlayerFrameTable.h"
|
|
8
|
|
9 #include "ErrorHandling.h"
|
|
10 #include "FrameTableInc.h"
|
|
11 #include "mm7_data.h"
|
|
12
|
|
13
|
|
14 //----- (00494AED) --------------------------------------------------------
|
|
15 unsigned int PlayerFrameTable::GetFrameIdByExpression(CHARACTER_EXPRESSION_ID expression)
|
|
16 {
|
|
17 for (uint i = 0; i < this->uNumFrames; i++)
|
|
18 {
|
|
19 if (this->pFrames[i].expression == expression)
|
|
20 return i;
|
|
21 }
|
|
22 return 0;
|
|
23 }
|
|
24
|
|
25 //----- (00494B10) --------------------------------------------------------
|
|
26 PlayerFrame *PlayerFrameTable::GetFrameBy_x(unsigned int uFramesetID, unsigned int uFrameID)
|
|
27 {
|
|
28 unsigned int v3; // esi@1
|
|
29 __int16 v6; // dx@2
|
|
30 int v7; // edx@3
|
|
31 char *i; // eax@3
|
|
32 int v9; // ecx@5
|
|
33 PlayerFrame *result; // eax@6
|
|
34
|
|
35 v3 = uFramesetID;
|
|
36 if (this->pFrames[uFramesetID].uFlags & 1 && (v6 = this->pFrames[uFramesetID].uAnimLength) != 0)
|
|
37 {
|
|
38 v7 = ((signed int)uFrameID >> 3) % (unsigned __int16)v6;
|
|
39 for (i = (char *)&this->pFrames[uFramesetID].uAnimTime;; i += 10)
|
|
40 {
|
|
41 v9 = *(short *)i;
|
|
42 if (v7 <= v9)
|
|
43 break;
|
|
44 v7 -= v9;
|
|
45 ++v3;
|
|
46 }
|
|
47 result = &this->pFrames[v3];
|
|
48 }
|
|
49 else
|
|
50 result = &this->pFrames[uFramesetID];
|
|
51 return result;
|
|
52 }
|
|
53
|
|
54 //----- (00494B5E) --------------------------------------------------------
|
|
55 PlayerFrame *PlayerFrameTable::GetFrameBy_y(int *pFramesetID, int *pAnimTime, int a4)
|
|
56 {
|
|
57 int v5; // esi@1
|
|
58 int v6; // eax@2
|
|
59
|
|
60 v5 = a4 + *pAnimTime;
|
|
61 if (v5 < 8 * this->pFrames[*pFramesetID].uAnimTime)
|
|
62 *pAnimTime = v5;
|
|
63 else
|
|
64 {
|
|
65 v6 = rand() % 4 + 21;
|
|
66 *pFramesetID = v6;
|
|
67 *pAnimTime = 8 * v5 % this->pFrames[v6].uAnimTime;
|
|
68 }
|
|
69 return &this->pFrames[*pFramesetID];
|
|
70 }
|
|
71
|
|
72 //----- (00494BC3) --------------------------------------------------------
|
|
73 void PlayerFrameTable::ToFile()
|
|
74 {
|
|
75 PlayerFrameTable *v1; // esi@1
|
|
76 FILE *v2; // eax@1
|
|
77 FILE *v3; // edi@1
|
|
78
|
|
79 PlayerFrameTable* Str = this;
|
|
80
|
|
81 v1 = Str;
|
|
82 v2 = fopen("data\\dpft.bin", "wb");
|
|
83 v3 = v2;
|
|
84 if (!v2)
|
|
85 Error("Unable to save dpft.bin");
|
|
86 fwrite(v1, 4, 1, v2);
|
|
87 fwrite(v1->pFrames, 0xAu, v1->uNumFrames, v3);
|
|
88 fclose(v3);
|
|
89 }
|
|
90
|
|
91 //----- (00494C0F) --------------------------------------------------------
|
|
92 void PlayerFrameTable::FromFile(void *data_mm6, void *data_mm7, void *data_mm8)
|
|
93 {
|
|
94 uint num_mm6_frames = data_mm6 ? *(int *)data_mm6 : 0,
|
|
95 num_mm7_frames = data_mm7 ? *(int *)data_mm7 : 0,
|
|
96 num_mm8_frames = data_mm8 ? *(int *)data_mm8 : 0;
|
|
97 uNumFrames = num_mm6_frames + num_mm7_frames + num_mm8_frames;
|
|
98 assert(uNumFrames);
|
|
99 assert(!num_mm8_frames);
|
|
100
|
|
101 pFrames = (PlayerFrame *)malloc(uNumFrames * sizeof(PlayerFrame));
|
|
102 memcpy(pFrames, (char *)data_mm7 + 4, num_mm7_frames * sizeof(PlayerFrame));
|
|
103 memcpy(pFrames + num_mm7_frames, (char *)data_mm6 + 4, num_mm6_frames * sizeof(PlayerFrame));
|
|
104 memcpy(pFrames + num_mm6_frames + num_mm7_frames, (char *)data_mm8 + 4, num_mm8_frames * sizeof(PlayerFrame));
|
|
105 }
|
|
106
|
|
107 //----- (00494C5A) --------------------------------------------------------
|
|
108 int PlayerFrameTable::FromFileTxt(const char *Args)
|
|
109 {
|
|
110 //PlayerFrameTable *v2; // ebx@1
|
|
111 FILE *v3; // eax@1
|
|
112 int v4; // esi@3
|
|
113 void *v5; // eax@10
|
|
114 FILE *v6; // ST0C_4@12
|
|
115 char *i; // eax@12
|
|
116 // __int16 v8; // ax@15
|
|
117 // const char *v9; // ST10_4@15
|
|
118 // unsigned __int16 v10; // ax@15
|
|
119 // const char *v11; // ST0C_4@15
|
|
120 int j; // esi@15
|
|
121 // int v13; // eax@17
|
|
122 int v14; // edx@22
|
|
123 int v15; // ecx@23
|
|
124 int v16; // eax@24
|
|
125 signed int k; // eax@27
|
|
126 //PlayerFrame *v18; // edx@28
|
|
127 int v19; // esi@28
|
|
128 int l; // ecx@29
|
|
129 char Buf; // [sp+Ch] [bp-2F8h]@3
|
|
130 FrameTableTxtLine v23; // [sp+200h] [bp-104h]@4
|
|
131 FrameTableTxtLine v24; // [sp+27Ch] [bp-88h]@4
|
|
132 int v25; // [sp+2F8h] [bp-Ch]@3
|
|
133 int v26; // [sp+2FCh] [bp-8h]@3
|
|
134 FILE *File; // [sp+300h] [bp-4h]@1
|
|
135 int Argsa; // [sp+30Ch] [bp+8h]@28
|
|
136
|
|
137 __debugbreak();//Ritor1;
|
|
138 //TileTable::dtor((TileTable *)this);
|
|
139 v3 = fopen(Args, "r");
|
|
140 File = v3;
|
|
141 if (!v3)
|
|
142 Error("PlayerFrameTable::load - Unable to open file: %s.", Args);
|
|
143 v4 = 0;
|
|
144 v25 = 0;
|
|
145 v26 = 1;
|
|
146 if (fgets(&Buf, 490, v3))
|
|
147 {
|
|
148 do
|
|
149 {
|
|
150 *strchr(&Buf, 10) = 0;
|
|
151 memcpy(&v24, txt_file_frametable_parser(&Buf, &v23), sizeof(v24));
|
|
152 if (v24.uPropCount && *v24.pProperties[0] != 47)
|
|
153 {
|
|
154 if (v24.uPropCount < 3)
|
|
155 Error("PlayerFrameTable::load, too few arguments, %s line %i.", Args, v26);
|
|
156 ++v25;
|
|
157 }
|
|
158 ++v26;
|
|
159 } while (fgets(&Buf, 490, File));
|
|
160 v4 = v25;
|
|
161 }
|
|
162 this->uNumFrames = v4;
|
|
163 v5 = malloc(10 * v4);
|
|
164 this->pFrames = (PlayerFrame *)v5;
|
|
165 if (!v5)
|
|
166 Error("PlayerFrameTable::load - Out of Memory!");
|
|
167 v6 = File;
|
|
168 this->uNumFrames = 0;
|
|
169 fseek(v6, 0, 0);
|
|
170 for (i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File))
|
|
171 {
|
|
172 *strchr(&Buf, 10) = 0;
|
|
173 memcpy(&v24, txt_file_frametable_parser(&Buf, &v23), sizeof(v24));
|
|
174 if (v24.uPropCount && *v24.pProperties[0] != 47)
|
|
175 {
|
|
176 //v8 = atoi(v24.pProperties[0]);
|
|
177 //v9 = v24.pProperties[1];
|
|
178 this->pFrames[this->uNumFrames].expression = (CHARACTER_EXPRESSION_ID)atoi(v24.pProperties[0]);
|
|
179 //v10 = atoi(v9);
|
|
180 //v11 = v24.pProperties[2];
|
|
181 this->pFrames[this->uNumFrames].uTextureID = atoi(v24.pProperties[1]);
|
|
182 this->pFrames[this->uNumFrames].uAnimTime = atoi(v24.pProperties[2]);
|
|
183 this->pFrames[this->uNumFrames].uAnimLength = 0;
|
|
184 this->pFrames[this->uNumFrames].uFlags = 0;
|
|
185 for (j = 3; j < v24.uPropCount; ++j)
|
|
186 {
|
|
187 if (!_stricmp(v24.pProperties[j], "New"))
|
|
188 this->pFrames[this->uNumFrames].uFlags |= 4;
|
|
189 }
|
|
190 ++this->uNumFrames;
|
|
191 }
|
|
192 }
|
|
193 fclose(File);
|
|
194
|
|
195 if ((signed int)(this->uNumFrames - 1) > 0)
|
|
196 {
|
|
197 v15 = 0;
|
|
198 for (v14 = 0; v14 < this->uNumFrames - 1; ++v14)
|
|
199 {
|
|
200 v16 = (int)&this->pFrames[v15];
|
|
201 if (!(*(char *)(v16 + 18) & 4))
|
|
202 this->pFrames[v14].uFlags |= 1;
|
|
203 ++v15;
|
|
204 }
|
|
205 }
|
|
206 for (k = 0; k < (signed int)this->uNumFrames; *(short *)(Argsa + 6) = v19)
|
|
207 {
|
|
208 //v18 = this->pFrames;
|
|
209 Argsa = (int)&this->pFrames[k];
|
|
210 v19 = *(short *)(Argsa + 4);
|
|
211 if (this->pFrames[k].uFlags & 1)
|
|
212 {
|
|
213 ++k;
|
|
214 for (l = (int)&this->pFrames[k]; this->pFrames[k].uFlags & 1; l += 10)
|
|
215 {
|
|
216 v19 += *(short *)(l + 4);
|
|
217 ++k;
|
|
218 }
|
|
219 LOWORD(v19) = this->pFrames[k].uAnimTime + v19;
|
|
220 }
|
|
221 ++k;
|
|
222 }
|
|
223 return 1;
|
|
224 }
|