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