Mercurial > mm7
annotate Overlays.cpp @ 2445:b10125a9c772
fix crash in keyboard option
author | Ritor1 |
---|---|
date | Thu, 24 Jul 2014 12:44:14 +0600 |
parents | f4af3b203f65 |
children |
rev | line source |
---|---|
2415 | 1 #define _CRTDBG_MAP_ALLOC |
2 #include <stdlib.h> | |
3 #include <crtdbg.h> | |
4 | |
5 | |
2253
aff7a7b072b7
adding _CRT_SECURE_NO_WARNINGS to get rid of a few hundrer annoying warnings + adding count parameter to swprintf
Grumpy7
parents:
2242
diff
changeset
|
6 #define _CRT_SECURE_NO_WARNINGS |
0 | 7 #include <stdlib.h> |
2336 | 8 #include "ErrorHandling.h" |
0 | 9 |
10 #include "Overlays.h" | |
11 #include "Sprites.h" | |
12 #include "FrameTableInc.h" | |
13 #include "IconFrameTable.h" | |
2044 | 14 #include "Timer.h" |
0 | 15 #include "Party.h" |
16 #include "TurnEngine.h" | |
17 #include "LOD.h" | |
18 #include "Render.h" | |
569 | 19 #include "GUIWindow.h" |
0 | 20 |
21 #include "mm7_data.h" | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 struct OtherOverlayList *pOtherOverlayList = new OtherOverlayList; // idb | |
28 struct OverlayList *pOverlayList = new OverlayList; | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | |
783 | 35 // inlined |
36 //----- (mm6c::0045BD50) -------------------------------------------------- | |
37 void OtherOverlayList::Reset() | |
38 { | |
39 for (uint i = 0; i < 50; ++i) | |
40 pOverlays[i].Reset(); | |
41 } | |
0 | 42 |
43 //----- (004418B1) -------------------------------------------------------- | |
44 int OtherOverlayList::_4418B1(int a2, int a3, int a4, int a5) | |
45 { | |
46 return 0; | |
47 } | |
48 | |
49 //----- (004418B6) -------------------------------------------------------- | |
50 int OtherOverlayList::_4418B6(int uOverlayID, __int16 a3, int a4, int a5, __int16 a6) | |
51 { | |
52 signed int v9; // esi@6 | |
53 __int16 v11; // dx@11 | |
54 | |
2274 | 55 for ( uint i = 0; i < 50; ++i ) |
0 | 56 { |
2274 | 57 if ( this->pOverlays[i].field_6 <= 0 ) |
0 | 58 { |
2274 | 59 this->pOverlays[i].field_0 = 0; |
60 this->pOverlays[i].field_A = 0; | |
61 this->pOverlays[i].field_8 = 0; | |
62 this->pOverlays[i].field_C = a3; | |
63 v9 = 0; | |
64 for ( v9; v9 < (signed int)pOverlayList->uNumOverlays; ++v9 ) | |
65 { | |
66 if ( uOverlayID == pOverlayList->pOverlays[v9].uOverlayID ) | |
67 break; | |
68 } | |
69 this->pOverlays[i].field_2 = v9; | |
70 this->pOverlays[i].field_4 = 0; | |
71 if ( a4 ) | |
72 v11 = a4; | |
73 else | |
74 v11 = 8 * pSpriteFrameTable->pSpriteSFrames[pOverlayList->pOverlays[v9].uSpriteFramesetID].uAnimLength; | |
75 this->pOverlays[i].field_6 = v11; | |
76 this->pOverlays[i].field_10 = a5; | |
77 this->pOverlays[i].field_E = a6; | |
78 bRedraw = true; | |
79 return true; | |
0 | 80 } |
81 } | |
2274 | 82 return 0; |
0 | 83 } |
84 | |
85 //----- (00441964) -------------------------------------------------------- | |
569 | 86 void OtherOverlayList::DrawTurnBasedIcon(int a2) |
0 | 87 { |
2242 | 88 IconFrame *frame; // eax@12 |
0 | 89 unsigned int v5; // [sp-8h] [bp-Ch]@4 |
90 | |
569 | 91 if ( pCurrentScreen != SCREEN_GAME || !pParty->bTurnBasedModeOn) |
92 return; | |
93 | |
2242 | 94 if ( pTurnEngine->turn_stage == TE_MOVEMENT )//все персы отстрелялись(сжатый кулак) |
95 frame = pIconsFrameTable->GetFrame(pIconIDs_Turn[5 - pTurnEngine->uActionPointsLeft / 26], pEventTimer->uStartTime); | |
96 else if ( pTurnEngine->turn_stage == TE_WAIT ) | |
0 | 97 { |
2242 | 98 if ( dword_50C998_turnbased_icon_1A ) |
99 v5 = uIconID_TurnStart;//анимация руки(запуск пошагового режима) | |
100 else | |
101 v5 = uIconID_TurnHour; //группа ожидает(часы) | |
102 frame = pIconsFrameTable->GetFrame(v5, dword_50C994); | |
0 | 103 } |
2242 | 104 else if ( pTurnEngine->turn_stage == TE_ATTACK )//группа атакует(ладонь) |
105 frame = pIconsFrameTable->GetFrame(uIconID_TurnStop, pEventTimer->uStartTime); | |
2154 | 106 //if ( pRenderer->pRenderD3D ) |
2242 | 107 pRenderer->DrawTextureIndexed(394, 288, &pIcons_LOD->pTextures[frame->uTextureID]); |
2154 | 108 /*else |
109 pRenderer->DrawTextureTransparent(0x18Au, 0x120u, v7);*/ | |
0 | 110 if ( dword_50C994 < dword_50C998_turnbased_icon_1A ) |
111 { | |
2242 | 112 dword_50C994 += pEventTimer->uTimeElapsed; |
113 if ( (signed int)dword_50C994 >= dword_50C998_turnbased_icon_1A ) | |
0 | 114 dword_50C998_turnbased_icon_1A = 0; |
115 } | |
116 } | |
117 // 4E28F8: using guessed type int pCurrentScreen; | |
118 // 50C994: using guessed type int dword_50C994; | |
119 // 50C998: using guessed type int dword_50C998_turnbased_icon_1A; | |
120 | |
121 | |
122 //----- (00458D97) -------------------------------------------------------- | |
123 void OverlayList::InitializeSprites() | |
124 { | |
472 | 125 for (uint i = 0; i < uNumOverlays; ++i) |
126 pSpriteFrameTable->InitializeSprite(pOverlays[i].uSpriteFramesetID); | |
0 | 127 } |
128 | |
129 //----- (00458DBC) -------------------------------------------------------- | |
130 void OverlayList::ToFile() | |
131 { | |
132 FILE *v2; // eax@1 | |
2242 | 133 //FILE *v3; // edi@1 |
0 | 134 |
135 v2 = fopen("data\\doverlay.bin", "wb"); | |
2242 | 136 //v3 = v2; |
0 | 137 if ( !v2 ) |
1545 | 138 Error("Unable to save doverlay.bin!"); |
2242 | 139 fwrite(this, 4, 1, v2); |
140 fwrite(this->pOverlays, 8, this->uNumOverlays, v2); | |
141 fclose(v2); | |
0 | 142 } |
143 | |
144 //----- (00458E08) -------------------------------------------------------- | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1340
diff
changeset
|
145 void OverlayList::FromFile(void *data_mm6, void *data_mm7, void *data_mm8) |
0 | 146 { |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1340
diff
changeset
|
147 uint num_mm6_overlays = data_mm6 ? *(int *)data_mm6 : 0, |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1340
diff
changeset
|
148 num_mm7_overlays = data_mm7 ? *(int *)data_mm7 : 0, |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1340
diff
changeset
|
149 num_mm8_overlays = data_mm8 ? *(int *)data_mm8 : 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1340
diff
changeset
|
150 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1340
diff
changeset
|
151 uNumOverlays = num_mm6_overlays + num_mm7_overlays + num_mm8_overlays; |
1545 | 152 Assert(uNumOverlays); |
153 Assert(!num_mm8_overlays); | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1340
diff
changeset
|
154 |
1583 | 155 pOverlays = (OverlayDesc *)malloc(uNumOverlays * sizeof(OverlayDesc)); |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1340
diff
changeset
|
156 memcpy(pOverlays, (char *)data_mm7 + 4, num_mm7_overlays * sizeof(OverlayDesc)); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1340
diff
changeset
|
157 memcpy(pOverlays + num_mm7_overlays, (char *)data_mm6 + 4, num_mm6_overlays * sizeof(OverlayDesc)); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1340
diff
changeset
|
158 memcpy(pOverlays + num_mm6_overlays + num_mm7_overlays, (char *)data_mm8 + 4, num_mm8_overlays * sizeof(OverlayDesc)); |
0 | 159 } |
160 | |
161 //----- (00458E4F) -------------------------------------------------------- | |
162 bool OverlayList::FromFileTxt(const char *Args) | |
163 { | |
164 __int32 v3; // edi@1 | |
165 FILE *v4; // eax@1 | |
166 unsigned int v5; // esi@3 | |
167 void *v7; // eax@9 | |
2274 | 168 //FILE *v8; // ST0C_4@11 |
0 | 169 char *i; // eax@11 |
170 char Buf; // [sp+10h] [bp-2F0h]@3 | |
171 FrameTableTxtLine v18; // [sp+204h] [bp-FCh]@4 | |
172 FrameTableTxtLine v19; // [sp+280h] [bp-80h]@4 | |
173 FILE *File; // [sp+2FCh] [bp-4h]@1 | |
174 unsigned int Argsa; // [sp+308h] [bp+8h]@3 | |
175 | |
1583 | 176 free(this->pOverlays); |
0 | 177 v3 = 0; |
2369
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2336
diff
changeset
|
178 this->pOverlays = nullptr; |
2242 | 179 this->uNumOverlays = 0; |
0 | 180 v4 = fopen(Args, "r"); |
181 File = v4; | |
182 if ( !v4 ) | |
1545 | 183 Error("ObjectDescriptionList::load - Unable to open file: %s."); |
184 | |
0 | 185 v5 = 0; |
186 Argsa = 0; | |
187 if ( fgets(&Buf, 490, v4) ) | |
188 { | |
189 do | |
190 { | |
191 *strchr(&Buf, 10) = 0; | |
703 | 192 memcpy(&v19, txt_file_frametable_parser(&Buf, &v18), sizeof(v19)); |
701 | 193 if ( v19.uPropCount && *v19.pProperties[0] != 47 ) |
0 | 194 ++Argsa; |
195 } | |
196 while ( fgets(&Buf, 490, File) ); | |
197 v5 = Argsa; | |
198 v3 = 0; | |
199 } | |
2242 | 200 this->uNumOverlays = v5; |
1583 | 201 v7 = malloc(8 * v5); |
2242 | 202 this->pOverlays = (OverlayDesc *)v7; |
0 | 203 if ( v7 == (void *)v3 ) |
1545 | 204 Error("OverlayDescriptionList::load - Out of Memory!"); |
205 | |
2242 | 206 memset(v7, v3, 8 * this->uNumOverlays); |
2274 | 207 //v8 = File; |
2242 | 208 this->uNumOverlays = v3; |
2274 | 209 fseek(File, v3, v3); |
0 | 210 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) |
211 { | |
212 *strchr(&Buf, 10) = 0; | |
703 | 213 memcpy(&v19, txt_file_frametable_parser(&Buf, &v18), sizeof(v19)); |
701 | 214 if ( v19.uPropCount && *v19.pProperties[0] != 47 ) |
0 | 215 { |
2242 | 216 this->pOverlays[this->uNumOverlays].uOverlayID = atoi(v19.pProperties[0]); |
217 if ( _stricmp(v19.pProperties[1], "center") ) | |
0 | 218 { |
2242 | 219 if ( !_stricmp(v19.pProperties[1], "transparent") ) |
220 this->pOverlays[this->uNumOverlays].uOverlayType = 2; | |
0 | 221 else |
2242 | 222 this->pOverlays[this->uNumOverlays].uOverlayType = 1; |
0 | 223 } |
224 else | |
2242 | 225 this->pOverlays[this->uNumOverlays].uOverlayType = 0; |
2274 | 226 this->pOverlays[this->uNumOverlays++].uSpriteFramesetID = pSpriteFrameTable->FastFindSprite((char *)v19.pProperties[2]); |
0 | 227 } |
228 } | |
229 fclose(File); | |
230 return 1; | |
231 } | |
232 | |
233 //----- (0045855F) -------------------------------------------------------- | |
234 void OtherOverlay::Reset() | |
235 { | |
2228 | 236 this->field_0 = 0; |
237 this->field_2 = 0; | |
238 this->field_4 = 0; | |
239 this->field_6 = 0; | |
0 | 240 this->field_8 = 0; |
2228 | 241 this->field_A = 0; |
0 | 242 this->field_C = 0; |
243 this->field_E = 0; | |
2228 | 244 this->field_10 = 65536; |
0 | 245 } |
246 | |
247 //----- (004584B8) -------------------------------------------------------- | |
248 OtherOverlay::OtherOverlay() | |
249 { | |
2242 | 250 this->field_0 = 0; |
251 this->field_2 = 0; | |
252 this->field_4 = 0; | |
0 | 253 this->field_6 = 0; |
2242 | 254 this->field_8 = 0; |
255 this->field_A = 0; | |
0 | 256 this->field_C = 0; |
257 this->field_E = 0; | |
258 this->field_10 = 65536; | |
259 } |