Mercurial > mm7
annotate ObjectList.cpp @ 2411:4106678916e1
added RenderStruct.h for VS 2012
author | Ritor1 |
---|---|
date | Tue, 15 Jul 2014 20:21:08 +0600 |
parents | bddcaf5d5db2 |
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:
1980
diff
changeset
|
1 #define _CRT_SECURE_NO_WARNINGS |
1296 | 2 #include "ObjectList.h" |
3 #include "mm7_data.h" | |
4 #include "Sprites.h" | |
5 #include "FrameTableInc.h" | |
1545 | 6 #include "ErrorHandling.h" |
1296 | 7 |
8 //----- (0042EB42) -------------------------------------------------------- | |
9 __int16 ObjectList::ObjectIDByItemID(unsigned __int16 uItemID) | |
10 { | |
11 unsigned int v2; // edx@1 | |
12 signed int v3; // eax@1 | |
13 char *v4; // ecx@2 | |
14 | |
15 v2 = this->uNumObjects; | |
16 v3 = 0; | |
17 if ( (signed int)this->uNumObjects <= 0 ) | |
18 { | |
19 LABEL_5: | |
20 LOWORD(v3) = 0; | |
21 } | |
22 else | |
23 { | |
24 v4 = (char *)&this->pObjects->uObjectID; | |
25 while ( uItemID != *(short *)v4 ) | |
26 { | |
27 ++v3; | |
28 v4 += 56; | |
29 if ( v3 >= (signed int)v2 ) | |
30 goto LABEL_5; | |
31 } | |
32 } | |
33 return v3; | |
34 } | |
35 //----- (00459064) -------------------------------------------------------- | |
36 void ObjectList::InitializeSprites() | |
37 { | |
38 for (uint i = 0; i < uNumObjects; ++i) | |
39 pSpriteFrameTable->InitializeSprite(pObjects[i].uSpriteID); | |
40 } | |
41 | |
42 //----- (00459090) -------------------------------------------------------- | |
43 void ObjectList::ToFile() | |
44 { | |
45 ObjectList *v1; // esi@1 | |
46 FILE *v2; // eax@1 | |
47 FILE *v3; // edi@1 | |
48 | |
49 v1 = this; | |
50 v2 = fopen("data\\dobjlist.bin", "wb"); | |
51 v3 = v2; | |
52 if ( !v2 ) | |
1545 | 53 Error("Unable to save dobjlist.bin!"); |
1296 | 54 fwrite(v1, 4u, 1u, v2); |
55 fwrite(v1->pObjects, 0x38u, v1->uNumObjects, v3); | |
56 fclose(v3); | |
57 } | |
58 | |
59 //----- (004590DC) -------------------------------------------------------- | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
60 void ObjectList::FromFile(void *data_mm6, void *data_mm7, void *data_mm8) |
1296 | 61 { |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
62 uint num_mm6_objs = data_mm6 ? *(int *)data_mm6 : 0, |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
63 num_mm7_objs = data_mm7 ? *(int *)data_mm7 : 0, |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
64 num_mm8_objs = data_mm8 ? *(int *)data_mm8 : 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
65 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
66 uNumObjects = num_mm6_objs + num_mm7_objs + num_mm8_objs; |
1545 | 67 Assert(uNumObjects); |
68 Assert(!num_mm8_objs); | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
69 |
1583 | 70 pObjects = (ObjectDesc *)malloc(uNumObjects * sizeof(ObjectDesc)); |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
71 memcpy(pObjects, (char *)data_mm7 + 4, num_mm7_objs * sizeof(ObjectDesc)); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
72 for (uint i = 0; i < num_mm6_objs; ++i) |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
73 { |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
74 auto src = (ObjectDesc_mm6 *)((char *)data_mm6 + 4) + i; |
1980 | 75 ObjectDesc* dst = &pObjects[num_mm7_objs + i]; |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
76 memcpy(dst->field_0, src->field_0, sizeof(dst->field_0)); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
77 dst->uObjectID = src->uObjectID; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
78 dst->uRadius = src->uRadius; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
79 dst->uHeight = src->uHeight; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
80 dst->uFlags = src->uFlags; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
81 dst->uSpriteID = src->uSpriteID; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
82 dst->uLifetime = src->uLifetime; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
83 dst->uParticleTrailColor = src->uParticleTrailColor; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
84 dst->uSpeed = src->uSpeed; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
85 dst->uParticleTrailColorR = src->uParticleTrailColorR; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
86 dst->uParticleTrailColorG = src->uParticleTrailColorG; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
87 dst->uParticleTrailColorB = src->uParticleTrailColorB; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
88 dst->field_35_clr = src->field_35_clr; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
89 dst->field_36_clr = 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
90 dst->field_37_clr = 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
91 } |
1296 | 92 } |
93 | |
94 //----- (00459123) -------------------------------------------------------- | |
95 bool ObjectList::FromFileTxt(const char *Args) | |
96 { | |
97 ObjectList *v2; // ebx@1 | |
98 __int32 v3; // edi@1 | |
99 FILE *v4; // eax@1 | |
100 unsigned int v5; // esi@3 | |
101 void *v6; // eax@9 | |
102 FILE *v7; // ST0C_4@11 | |
103 char *i; // eax@11 | |
104 unsigned __int16 v9; // ax@14 | |
105 const char *v10; // ST20_4@14 | |
106 __int16 v11; // ax@14 | |
107 const char *v12; // ST1C_4@14 | |
108 __int16 v13; // ax@14 | |
109 const char *v14; // ST18_4@14 | |
110 __int16 v15; // ax@14 | |
111 const char *v16; // ST14_4@14 | |
112 __int16 v17; // ax@14 | |
113 const char *v18; // ST10_4@14 | |
114 __int16 v19; // ax@14 | |
115 const char *v20; // ST0C_4@14 | |
116 int v21; // esi@16 | |
117 const char *v22; // edi@16 | |
118 int v23; // eax@17 | |
119 int v24; // eax@19 | |
120 int v25; // eax@21 | |
121 int v26; // eax@21 | |
122 int v27; // eax@21 | |
123 int v28; // eax@23 | |
124 int v29; // eax@25 | |
125 int v30; // eax@27 | |
126 int v31; // eax@29 | |
127 const char *v32; // edi@30 | |
128 const char *v33; // ST20_4@35 | |
129 int v34; // eax@35 | |
130 char v35; // al@35 | |
131 const char *v36; // ST1C_4@35 | |
132 char v37; // al@35 | |
133 const char *v38; // ST18_4@35 | |
134 FrameTableTxtLine v40; // [sp+8h] [bp-460h]@14 | |
135 FrameTableTxtLine v41; // [sp+84h] [bp-3E4h]@12 | |
136 char Dest; // [sp+100h] [bp-368h]@14 | |
137 char Buf; // [sp+178h] [bp-2F0h]@3 | |
138 FrameTableTxtLine v44; // [sp+36Ch] [bp-FCh]@4 | |
139 FrameTableTxtLine v45; // [sp+3E8h] [bp-80h]@4 | |
140 FILE *File; // [sp+464h] [bp-4h]@1 | |
141 unsigned int Argsa; // [sp+470h] [bp+8h]@3 | |
142 int Argsb; // [sp+470h] [bp+8h]@15 | |
143 | |
144 v2 = this; | |
1583 | 145 free(this->pObjects); |
1296 | 146 v3 = 0; |
2369
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2253
diff
changeset
|
147 v2->pObjects = nullptr; |
1296 | 148 v2->uNumObjects = 0; |
149 v4 = fopen(Args, "r"); | |
150 File = v4; | |
151 if ( !v4 ) | |
1545 | 152 Error("ObjectDescriptionList::load - Unable to open file: %s."); |
153 | |
1296 | 154 v5 = 0; |
155 Argsa = 0; | |
156 if ( fgets(&Buf, 490, v4) ) | |
157 { | |
158 do | |
159 { | |
160 *strchr(&Buf, 10) = 0; | |
161 memcpy(&v45, frame_table_txt_parser(&Buf, &v44), sizeof(v45)); | |
162 if ( v45.uPropCount && *v45.pProperties[0] != '/' ) | |
163 ++Argsa; | |
164 } | |
165 while ( fgets(&Buf, 490, File) ); | |
166 v5 = Argsa; | |
167 v3 = 0; | |
168 } | |
169 v2->uNumObjects = v5; | |
1583 | 170 v6 = malloc(56 * v5); |
1296 | 171 v2->pObjects = (ObjectDesc *)v6; |
172 if ( v6 == (void *)v3 ) | |
1545 | 173 Error("ObjectDescriptionList::load - Out of Memory!"); |
174 | |
1296 | 175 memset(v6, v3, 56 * v2->uNumObjects); |
176 v7 = File; | |
177 v2->uNumObjects = v3; | |
178 fseek(v7, v3, v3); | |
179 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) | |
180 { | |
181 *strchr(&Buf, 10) = 0; | |
182 memcpy(&v45, frame_table_txt_parser(&Buf, &v41), sizeof(v45)); | |
183 if ( v45.uPropCount && *v45.pProperties[0] != 47 ) | |
184 { | |
185 strcpy(v2->pObjects[v2->uNumObjects].field_0, v45.pProperties[0]); | |
186 v9 = pSpriteFrameTable->FastFindSprite((char *)v45.pProperties[1]); | |
187 v10 = v45.pProperties[2]; | |
188 v2->pObjects[v2->uNumObjects].uSpriteID = v9; | |
189 v11 = atoi(v10); | |
190 v12 = v45.pProperties[3]; | |
191 v2->pObjects[v2->uNumObjects].uObjectID = v11; | |
192 v13 = atoi(v12); | |
193 v14 = v45.pProperties[4]; | |
194 v2->pObjects[v2->uNumObjects].uRadius = v13; | |
195 v15 = atoi(v14); | |
196 v16 = v45.pProperties[5]; | |
197 v2->pObjects[v2->uNumObjects].uHeight = v15; | |
198 v17 = atoi(v16); | |
199 v18 = v45.pProperties[6]; | |
200 v2->pObjects[v2->uNumObjects].uLifetime = v17; | |
201 v19 = atoi(v18); | |
202 v20 = v45.pProperties[7]; | |
203 v2->pObjects[v2->uNumObjects].uSpeed = v19; | |
204 strcpy(&Dest, v20); | |
205 memcpy(&v44, frame_table_txt_parser(&Dest, &v40), sizeof(v44)); | |
206 if ( v45.uPropCount > 7 ) | |
207 { | |
208 for ( Argsb = 0; Argsb < v44.uPropCount; ++Argsb ) | |
209 { | |
210 v21 = Argsb; | |
211 v22 = v44.pProperties[Argsb]; | |
212 if ( !_stricmp(v44.pProperties[Argsb], "NoDraw") ) | |
213 { | |
214 v23 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
215 *(char *)v23 |= 1u; | |
216 } | |
217 if ( !_stricmp(v22, "Lifetime") ) | |
218 { | |
219 v24 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
220 *(char *)v24 |= 4u; | |
221 } | |
222 if ( !_stricmp(v22, "FTLifetime") ) | |
223 { | |
224 v25 = (int)&v2->pObjects[v2->uNumObjects]; | |
225 *(short *)(v25 + 42) = 8 * pSpriteFrameTable->pSpriteSFrames[*(short *)(v25 + 40)].uAnimLength; | |
226 v26 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
227 *(char *)v26 |= 8u; | |
228 v27 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
229 *(char *)v27 |= 4u; | |
230 } | |
231 if ( !_stricmp(v22, "NoPickup") ) | |
232 { | |
233 v28 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
234 *(char *)v28 |= 0x10u; | |
235 } | |
236 if ( !_stricmp(v22, "NoGravity") ) | |
237 { | |
238 v29 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
239 *(char *)v29 |= 0x20u; | |
240 } | |
241 if ( !_stricmp(v22, "FlagOnIntercept") ) | |
242 { | |
243 v30 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
244 *(char *)v30 |= 0x40u; | |
245 } | |
246 if ( !_stricmp(v22, "Bounce") ) | |
247 { | |
248 v31 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
249 *(char *)v31 |= 0x80u; | |
250 } | |
251 v32 = v45.pProperties[v21]; | |
252 if ( !_stricmp(v45.pProperties[v21], "Fire") ) | |
253 HIBYTE(v2->pObjects[v2->uNumObjects].uFlags) |= 2u; | |
254 if ( !_stricmp(v32, "Lines") ) | |
255 HIBYTE(v2->pObjects[v2->uNumObjects].uFlags) |= 4u; | |
256 if ( !_stricmp(v44.pProperties[v21], "bits") ) | |
257 { | |
258 v33 = v44.pProperties[v21 + 1]; | |
259 v34 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
260 *(char *)(v34 + 1) |= 1u; | |
261 v35 = atoi(v33); | |
262 v36 = v44.pProperties[v21 + 2]; | |
263 v2->pObjects[v2->uNumObjects].uParticleTrailColorR = v35; | |
264 v37 = atoi(v36); | |
265 v38 = v44.pProperties[v21 + 3]; | |
266 v2->pObjects[v2->uNumObjects].uParticleTrailColorG = v37; | |
267 v2->pObjects[v2->uNumObjects].uParticleTrailColorB = atoi(v38); | |
268 } | |
269 } | |
270 } | |
271 ++v2->uNumObjects; | |
272 } | |
273 } | |
274 fclose(File); | |
275 return 1; | |
276 } |