2499
|
1 #define _CRTDBG_MAP_ALLOC
|
|
2 #include <stdlib.h>
|
|
3 #include <crtdbg.h>
|
2509
|
4 #include <io.h>
|
2499
|
5 #define _CRT_SECURE_NO_WARNINGS
|
|
6
|
|
7 #include "MMT.h"
|
2502
|
8 #include "GUI/GUIWindow.h"
|
2499
|
9
|
|
10 #include "mm7_data.h"
|
2502
|
11 #include "Media/Audio/AudioPlayer.h"
|
|
12 #include "IO/Mouse.h"
|
2499
|
13 #include "LOD.h"
|
|
14 #include "Engine/Graphics/Render.h"
|
2502
|
15 #include "GUI/GUIFont.h"
|
2499
|
16 #include "lib/libpng/png.h"
|
|
17 #include "Engine/ErrorHandling.h"
|
2502
|
18 #include "Media/Video/Bink_Smacker.h"
|
2499
|
19 #include "Game.h"
|
|
20 #include "Log.h"
|
|
21
|
2509
|
22 bool FileExists(const char *fname)
|
|
23 {
|
|
24 return access(fname, 0) != -1;
|
|
25 }
|
2499
|
26
|
|
27 void ShowLogoVideo()
|
|
28 {
|
|
29 RGBTexture tex; // [sp+Ch] [bp-30h]@1
|
|
30 unsigned int uTrackStartMS; // [sp+34h] [bp-8h]@8
|
|
31 unsigned int uTrackEndMS; // [sp+38h] [bp-4h]@8
|
|
32
|
|
33 pMediaPlayer->bStopBeforeSchedule = false;
|
|
34
|
|
35 // pMediaPlayer->pResetflag = 0;
|
|
36 bGameoverLoop = 1;
|
|
37 if (!bNoVideo)
|
|
38 {
|
|
39 pRenderer->PresentBlackScreen();
|
|
40 pMediaPlayer->PlayFullscreenMovie(MOVIE_3DOLogo, true);
|
|
41 if ( !pMediaPlayer->bStopBeforeSchedule )
|
|
42 {
|
|
43 pMediaPlayer->PlayFullscreenMovie(MOVIE_NWCLogo, true);
|
|
44 if ( !pMediaPlayer->bStopBeforeSchedule )
|
|
45 {
|
|
46
|
|
47 if (for_refactoring)
|
|
48 {
|
|
49 MessageBoxA(nullptr, "Ritor1: MOVIE_JVC crash", "", 0);
|
|
50 __debugbreak();
|
|
51 }
|
|
52
|
|
53 //pMediaPlayer->PlayFullscreenMovie(MOVIE_JVC, true);
|
|
54 //if ( !pMediaPlayer->bStopBeforeSchedule )
|
|
55 if (!use_MMT)
|
|
56 pMediaPlayer->PlayFullscreenMovie(MOVIE_Intro, true);
|
|
57 }
|
|
58 }
|
|
59 }
|
|
60 char pContainerName[64];
|
|
61
|
|
62 if (use_MMT)
|
|
63 {
|
|
64 sprintf(pContainerName, "data\\New_Icons/%s", "MMTTITLE.pcx");
|
|
65 tex.LoadPCXFile(pContainerName, 0);
|
|
66 }
|
|
67 else
|
|
68 tex.Load("mm6title.pcx", 2);
|
|
69
|
|
70 pRenderer->BeginScene();
|
|
71 pRenderer->DrawTextureRGB(0, 0, &tex);
|
|
72 free(tex.pPixels);
|
|
73 tex.pPixels = 0;
|
|
74 MainMenuUI_LoadFontsAndSomeStuff();
|
|
75
|
|
76 if (use_MMT)
|
|
77 DrawMMTCopyrightWindow();//Text message in ÌÌÒ menu
|
|
78 else
|
|
79 DrawMM7CopyrightWindow();
|
|
80
|
|
81 pRenderer->EndScene();
|
|
82 pRenderer->Present();
|
|
83
|
|
84 #ifndef _DEBUG
|
|
85 Sleep(1500); // let the copyright window stay for a while
|
|
86 #endif
|
|
87 if (!use_MMT)
|
|
88 {
|
|
89 if (!bNoSound && pAudioPlayer->hAILRedbook )
|
|
90 {
|
2508
|
91 if ( use_music_folder )
|
|
92 {
|
2509
|
93 if (!FileExists("Music\\14.mp3"))
|
|
94 {
|
|
95 Log::Warning(L"File 14.mp3 in Music\\ folder not found");
|
|
96 return;
|
|
97 }
|
2508
|
98 PlayAudio(L"Music\\14.mp3");
|
|
99 alSourcef (mSourceID, AL_GAIN, pSoundVolumeLevels[uMusicVolimeMultiplier]);
|
|
100 }
|
|
101 else
|
|
102 {
|
|
103 pAudioPlayer->SetMusicVolume((signed __int64)(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0));
|
|
104 AIL_redbook_stop(pAudioPlayer->hAILRedbook);
|
|
105 AIL_redbook_track_info(pAudioPlayer->hAILRedbook, 14, &uTrackStartMS, &uTrackEndMS);
|
|
106 AIL_redbook_play(pAudioPlayer->hAILRedbook, uTrackStartMS + 1, uTrackEndMS);
|
|
107 }
|
2499
|
108 }
|
|
109 }
|
|
110 bGameoverLoop = 0;
|
|
111 }
|
|
112
|
|
113 void abort_(const char * s, ...)
|
|
114 {
|
|
115 va_list args;
|
|
116 va_start(args, s);
|
|
117 vfprintf(stderr, s, args);
|
|
118 fprintf(stderr, "\n");
|
|
119 va_end(args);
|
|
120 abort();
|
|
121 }
|
|
122
|
|
123 Texture *LoadPNG(const char *name)
|
|
124 {
|
|
125 int x, y;
|
|
126 int width, height;
|
|
127 png_byte color_type;
|
|
128 png_byte bit_depth;
|
|
129 png_structp png_ptr;
|
|
130 png_infop info_ptr;
|
|
131 int number_of_passes;
|
|
132 png_bytep * row_pointers;
|
|
133 uint i = 0;
|
|
134 Texture *tex;
|
|
135
|
|
136 char header[8]; // 8 is the maximum size that can be checked
|
|
137
|
|
138 /* open file and test for it being a png */
|
|
139 FILE *fp = fopen(name, "rb");
|
|
140 if (!fp)
|
|
141 abort_("[read_png_file] File %s could not be opened for reading", name);
|
|
142 fread(header, 1, 8, fp);
|
|
143 if (png_sig_cmp((png_bytep)header, 0, 8))
|
|
144 abort_("[read_png_file] File %s is not recognized as a PNG file", name);
|
|
145 /* initialize stuff */
|
|
146 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
|
147
|
|
148 if (!png_ptr)
|
|
149 abort_("[read_png_file] png_create_read_struct failed");
|
|
150 info_ptr = png_create_info_struct(png_ptr);
|
|
151 if (!info_ptr)
|
|
152 abort_("[read_png_file] png_create_info_struct failed");
|
|
153
|
|
154 if (setjmp(png_jmpbuf(png_ptr)))
|
|
155 abort_("[read_png_file] Error during init_io");
|
|
156
|
|
157 png_init_io(png_ptr, fp);
|
|
158 png_set_sig_bytes(png_ptr, 8);
|
|
159
|
|
160 png_read_info(png_ptr, info_ptr);
|
|
161
|
|
162 width = png_get_image_width(png_ptr, info_ptr);
|
|
163 height = png_get_image_height(png_ptr, info_ptr);
|
|
164 color_type = png_get_color_type(png_ptr, info_ptr);
|
|
165 bit_depth = png_get_bit_depth(png_ptr, info_ptr);
|
|
166
|
|
167 number_of_passes = png_set_interlace_handling(png_ptr);
|
|
168 png_read_update_info(png_ptr, info_ptr);
|
|
169
|
|
170 /* read file */
|
|
171 if (setjmp(png_jmpbuf(png_ptr)))
|
|
172 abort_("[read_png_file] Error during read_image");
|
|
173 row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * height);
|
|
174 for (y=0; y<height; y++)
|
|
175 row_pointers[y] = (png_byte*) malloc(png_get_rowbytes(png_ptr,info_ptr));
|
|
176
|
|
177 png_read_image(png_ptr, row_pointers);
|
|
178
|
|
179 fclose(fp);
|
|
180
|
|
181 tex = new Texture;
|
|
182 tex->uTextureHeight = height;
|
|
183 tex->uTextureWidth = width;
|
|
184 tex->uSizeOfMaxLevelOfDetail = png_get_rowbytes(png_ptr, info_ptr);
|
|
185 tex->uTextureSize = png_get_rowbytes(png_ptr, info_ptr);
|
|
186 tex->uDecompressedSize = png_get_rowbytes(png_ptr, info_ptr);
|
|
187 tex->pPalette16 = (unsigned __int16 *) malloc(sizeof(unsigned __int16) * width * height);
|
|
188 tex->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *) malloc(sizeof(unsigned __int8) * width * height);
|
|
189
|
|
190 for (y=0; y<height; y++)
|
|
191 {
|
|
192 png_byte* row = row_pointers[y];
|
|
193 for (x=0; x<width; x++)
|
|
194 {
|
|
195 png_byte* ptr = &(row[x*4]);
|
|
196 //Log::Warning(L"Pixel at position [ %d - %d ] has RGBA values: %d - %d - %d - %d\n",
|
|
197 // x, y, ptr[0], ptr[1], ptr[2], ptr[3]);
|
|
198 png_byte tmp = ptr[2];
|
|
199 ptr[2] = ptr[0];
|
|
200 ptr[0] = ptr[3];
|
|
201 //ptr[3] = 255 - ptr[3]; // alpha mask gradient
|
|
202 ptr[3] = 255 - tmp;
|
|
203 tex->pPalette16[i] = Color16(ptr[0], ptr[1], ptr[2]);
|
|
204 tex->pLevelOfDetail0_prolly_alpha_mask[i] = ptr[3];
|
|
205 i++;
|
|
206 }
|
|
207 }
|
|
208 //Ritor1: temporarily stopped, needed change RGBTexture structure
|
|
209 /*for (int i = 0; i < width * height; ++i)
|
|
210 tex->pPalette16[i] = 0x7FF;
|
|
211 memset(tex->pLevelOfDetail0_prolly_alpha_mask, 1, sizeof(unsigned __int8) * width * height);*/
|
|
212 return tex;
|
|
213 }
|
|
214
|
|
215 void MMT_MainMenu_Loop()
|
|
216 {
|
|
217 GUIButton *pButton; // eax@27
|
|
218 unsigned int pControlParam; // ecx@35
|
|
219 unsigned int pX;
|
|
220 unsigned int pY; // [sp-18h] [bp-54h]@39
|
|
221 Texture *pTexture; // [sp-14h] [bp-50h]@39
|
|
222 char pContainerName[64];
|
|
223 MSG msg;
|
|
224
|
|
225 pCurrentScreen = SCREEN_GAME;
|
|
226
|
|
227 pGUIWindow2 = 0;
|
|
228 pAudioPlayer->StopChannels(-1, -1);
|
|
229
|
2506
|
230 if (!bNoSound )
|
|
231 PlayAudio(L"Sounds\\New_Sounds/Stronghold_Theme.mp3");
|
2499
|
232 //if (!bNoVideo )
|
|
233 //pVideoPlayer->PlayMovie(L"Anims\\New_Video/3DOLOGO.smk");
|
|
234
|
|
235 pMouse->RemoveHoldingItem();
|
|
236
|
|
237 pIcons_LOD->_inlined_sub2();
|
|
238
|
|
239 //Create new window
|
|
240 //WINDOW_MainMenu included in GUIWindow.h
|
|
241 pWindow_MMT_MainMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_MainMenu, 0, 0);
|
|
242
|
|
243 //load buttons
|
|
244 //Texture* MMT_MM6 = pIcons_LOD->LoadTexturePtr("title_new", TEXTURE_16BIT_PALETTE);
|
|
245
|
|
246 sprintf(pContainerName, "data\\New_Icons/%s", "mm6_button_oval.png");
|
|
247 Texture* MMT_MM6 = LoadPNG(pContainerName);
|
|
248
|
|
249 Texture* MMT_MM7 = pIcons_LOD->LoadTexturePtr("title_load", TEXTURE_16BIT_PALETTE);
|
|
250 Texture* MMT_MM8 = pIcons_LOD->LoadTexturePtr("title_cred", TEXTURE_16BIT_PALETTE);
|
|
251 Texture* MMT_Continue = pIcons_LOD->LoadTexturePtr("title_exit", TEXTURE_16BIT_PALETTE);
|
|
252 Texture* MMT_Exit = pIcons_LOD->LoadTexturePtr("title_exit", TEXTURE_16BIT_PALETTE);
|
|
253
|
|
254 pMMT_MainMenu_BtnMM6 = pWindow_MMT_MainMenu->CreateButton(0, 0, MMT_MM6->uTextureWidth, MMT_MM6->uTextureHeight, 1, 0, UIMSG_MMT_MainMenu_MM6, 0, 0, "", MMT_MM6, 0);
|
|
255 pMMT_MainMenu_BtnMM7 = pWindow_MMT_MainMenu->CreateButton(window->GetWidth() - (window->GetWidth() / 4), window->GetHeight() / 4, MMT_MM7->uTextureWidth, MMT_MM7->uTextureHeight, 1, 0, UIMSG_MMT_MainMenu_MM7, 1, 0, "", MMT_MM7, 0);
|
|
256 pMMT_MainMenu_BtnMM8 = pWindow_MMT_MainMenu->CreateButton(window->GetWidth() - (window->GetWidth() / 4), window->GetHeight() - ((window->GetHeight() / 4) + 50), MMT_MM8->uTextureWidth, MMT_MM8->uTextureHeight, 1, 0, UIMSG_MMT_MainMenu_MM8, 2, 0, "", MMT_MM8, 0);
|
|
257 pMMT_MainMenu_BtnContinue = pWindow_MMT_MainMenu->CreateButton((window->GetWidth() / 4) - 100, window->GetHeight() - ((window->GetHeight() / 4) + 50), MMT_Continue->uTextureWidth, MMT_Continue->uTextureHeight, 1, 0, UIMSG_MMT_MainMenu_Continue, 3, 0, "", MMT_Continue, 0);
|
|
258 pMMT_MainMenu_BtnExit = pWindow_MMT_MainMenu->CreateButton(window->GetWidth() - 130, window->GetHeight() - 35, MMT_Exit->uTextureWidth, MMT_Exit->uTextureHeight, 1, 0, UIMSG_ExitToWindows, 4, 0, "", MMT_Exit, 0);
|
|
259
|
|
260 pTexture_PCX.Release();
|
|
261
|
|
262 sprintf(pContainerName, "data\\New_Icons/%s", "MMTTITLE.pcx");
|
|
263 if (pTexture_PCX.LoadPCXFile(pContainerName, 0) == 1)
|
|
264 Error("File not found: %s", pContainerName);
|
|
265
|
|
266 SetCurrentMenuID(MENU_MMT_MAIN_MENU);//included in enum MENU_STATE in GUIWindows.h
|
|
267 SetForegroundWindow(window->GetApiHandle());
|
|
268 SendMessageW(window->GetApiHandle(), WM_ACTIVATEAPP, 1, 0);
|
|
269 while (GetCurrentMenuID() == MENU_MMT_MAIN_MENU )
|
|
270 {
|
|
271 POINT cursor;
|
|
272 pMouse->GetCursorPos(&cursor);
|
|
273
|
|
274 while (PeekMessageW(&msg, 0, 0, 0, PM_REMOVE))
|
|
275 {
|
|
276 if (msg.message == WM_QUIT)
|
|
277 Game_DeinitializeAndTerminate(0);
|
|
278 TranslateMessage(&msg);
|
|
279 DispatchMessageW(&msg);
|
|
280 }
|
|
281
|
|
282 if (dword_6BE364_game_settings_1 & GAME_SETTINGS_APP_INACTIVE)
|
|
283 {
|
|
284 WaitMessage();
|
|
285 continue;
|
|
286 }
|
|
287
|
|
288 pRenderer->BeginScene();
|
|
289 pRenderer->DrawTextureRGB(0, 0, &pTexture_PCX);
|
|
290
|
|
291 MMT_MenuMessageProc();//for ÌÌÒ menu
|
|
292 GUI_UpdateWindows();
|
|
293
|
|
294 if ( !pModalWindow )// ???
|
|
295 {
|
|
296 pButton = pWindow_MMT_MainMenu->pControlsHead;
|
|
297 for ( pButton = pWindow_MMT_MainMenu->pControlsHead; pButton; pButton = pButton->pNext )
|
|
298 {
|
|
299 if ( cursor.x >= (signed int)pButton->uX && cursor.x <= (signed int)pButton->uZ
|
|
300 && cursor.y >= (signed int)pButton->uY && cursor.y <= (signed int)pButton->uW )
|
|
301 {
|
|
302 pControlParam = pButton->msg_param;
|
|
303 switch (pControlParam) // backlight for buttons
|
|
304 {
|
|
305 case 0:
|
|
306 pTexture = MMT_MM6;
|
|
307 pX = 0;
|
|
308 pY = 0;
|
|
309 break;
|
|
310 case 1:
|
|
311 pTexture = MMT_MM7;
|
|
312 pX = window->GetWidth() - (window->GetWidth() / 4);
|
|
313 pY = window->GetHeight() / 4;
|
|
314 break;
|
|
315 case 2:
|
|
316 pTexture = MMT_MM8;
|
|
317 pX = window->GetWidth() - (window->GetWidth() / 4);
|
|
318 pY = window->GetHeight() - ((window->GetHeight() / 4) + 50);
|
|
319 break;
|
|
320 case 3:
|
|
321 pTexture = MMT_Continue;
|
|
322 pX = (window->GetWidth() / 4) - 100;
|
|
323 pY = window->GetHeight() - ((window->GetHeight() / 4) + 50);
|
|
324 break;
|
|
325 case 4:
|
|
326 pTexture = MMT_Exit;
|
|
327 pX = window->GetWidth() - 130;
|
|
328 pY = window->GetHeight() - 35;
|
|
329 break;
|
|
330 }
|
|
331 pRenderer->DrawTextureIndexed(pX, pY, pTexture);
|
|
332 }
|
|
333 }
|
|
334 }
|
|
335 //}
|
|
336 pRenderer->EndScene();
|
|
337 pRenderer->Present();
|
|
338 }
|
|
339 MMT_MenuMessageProc();
|
|
340 pRenderer->BeginScene();
|
|
341 GUI_UpdateWindows();
|
|
342 pRenderer->EndScene();
|
|
343 pRenderer->Present();
|
|
344
|
|
345 //remove resource
|
|
346 pTexture_PCX.Release();
|
|
347 if ( pGUIWindow2 )
|
|
348 {
|
|
349 pGUIWindow2->Release();
|
|
350 pGUIWindow2 = 0;
|
|
351 }
|
|
352 pWindow_MMT_MainMenu->Release();
|
|
353 pIcons_LOD->RemoveTexturesPackFromTextureList();
|
|
354 }
|
|
355
|
|
356 void MMT_MenuMessageProc()
|
|
357 {
|
|
358 int pParam;
|
|
359 int pParam2;
|
|
360 UIMessageType pUIMessageType;
|
|
361
|
|
362 if ( pMessageQueue_50CBD0->uNumMessages )
|
|
363 {
|
|
364 do
|
|
365 {
|
|
366 pMessageQueue_50CBD0->PopMessage(&pUIMessageType, &pParam, &pParam2);
|
|
367
|
|
368 switch (pUIMessageType)
|
|
369 {
|
|
370 case UIMSG_MMT_MainMenu_MM6:
|
|
371 //video
|
|
372 //SetCurrentMenuID(MENU_MAIN_MM6);
|
2506
|
373 alSourcef (mSourceID, AL_GAIN, 0.5f);
|
|
374 pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);//temporarily
|
2499
|
375 break;
|
|
376 case UIMSG_MMT_MainMenu_MM7: //new button for ÌÌ7
|
|
377 //GUIWindow::Create(495, 172, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnNew, 0);
|
|
378 alSourceStop(mSourceID);
|
|
379 pMediaPlayer->ShowMM7IntroVideo_and_LoadingScreen();
|
|
380 SetCurrentMenuID(MENU_MAIN);
|
|
381 break;
|
|
382 case UIMSG_MMT_MainMenu_MM8:
|
|
383 //video
|
|
384 //SetCurrentMenuID(MENU_MAIN_MM8);
|
2506
|
385 alSourcei (mSourceID, AL_LOOPING, 1);
|
|
386 pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);//temporarily
|
2499
|
387 break;
|
|
388 case UIMSG_MMT_MainMenu_Continue:
|
|
389 //video
|
|
390 //SetCurrentMenuID(MENU_MAIN_Continue);
|
2506
|
391 alSourcef (mSourceID, AL_GAIN, 1.0f);
|
|
392 pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);//temporarily
|
2499
|
393 break;
|
|
394 case UIMSG_ExitToWindows:
|
|
395 GUIWindow::Create(495, 337, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnExit, 0);
|
|
396 SetCurrentMenuID(MENU_EXIT_GAME);
|
|
397
|
|
398 default:
|
|
399 break;
|
|
400 }
|
|
401 }
|
|
402 while ( pMessageQueue_50CBD0->uNumMessages );
|
|
403 }
|
|
404 }
|
|
405 void DrawMMTCopyrightWindow()
|
|
406 {
|
|
407 GUIWindow Dst; // [sp+8h] [bp-54h]@1
|
|
408
|
|
409 memset(&Dst, 0, 0x54u);
|
|
410 Dst.uFrameWidth = 624;
|
|
411 Dst.uFrameHeight = 256;
|
|
412 Dst.uFrameX = 8;
|
|
413 Dst.uFrameY = 30;
|
|
414 Dst.uFrameHeight = pFontSmallnum->CalcTextHeight("Text Verification: Here we can write an explanation of the project", &Dst, 24, 0)
|
|
415 + 2 * LOBYTE(pFontSmallnum->uFontHeight)
|
|
416 + 24;
|
|
417 Dst.uFrameY = 470 - Dst.uFrameHeight;
|
|
418 Dst.uFrameZ = Dst.uFrameX + Dst.uFrameWidth - 1;
|
|
419 Dst.uFrameW = 469;
|
|
420 //Dst.Hint = "abcagfdsgsg ljsrengvlkjesnfkjwnef";
|
|
421 Dst.DrawMessageBox(0);
|
|
422
|
|
423 Dst.uFrameWidth -= 24;
|
|
424 Dst.uFrameX += 12;
|
|
425 Dst.uFrameY += 12;
|
|
426 Dst.uFrameHeight -= 12;
|
|
427 Dst.uFrameZ = Dst.uFrameX + Dst.uFrameWidth - 1;
|
|
428 Dst.uFrameW = Dst.uFrameY + Dst.uFrameHeight - 1;
|
|
429 Dst.DrawTitleText(pFontSmallnum, 0, 0xCu, ui_mainmenu_copyright_color, "Text Verification: Here we can write an explanation of the project", 3);
|
|
430 } |