comparison Game.cpp @ 0:8b8875f5b359

Initial commit
author Nomad
date Fri, 05 Oct 2012 16:07:14 +0200
parents
children 2ca04ccb612a
comparison
equal deleted inserted replaced
-1:000000000000 0:8b8875f5b359
1 #include "Game.h"
2 #include "Party.h"
3 #include "IndoorCamera.h"
4 #include "Math.h"
5 #include "LightmapBuilder.h"
6 #include "Viewport.h"
7 #include "Time.h"
8 #include "Outdoor.h"
9 #include "Overlays.h"
10 #include "stru279.h"
11 #include "AudioPlayer.h"
12 #include "LOD.h"
13 #include "OSInfo.h"
14 #include "GUIWindow.h"
15 #include "Party.h"
16 #include "TurnEngine.h"
17 #include "stru157.h"
18 #include "VideoPlayer.h"
19 #include "Bink_Smacker.h"
20 #include "Events.h"
21 #include "Arcomage.h"
22
23 //#include "MM7.h"
24
25
26
27
28
29
30 Game *pGame;
31
32
33
34
35
36 //----- (00435694) --------------------------------------------------------
37 void Game::ToggleFlags2(unsigned int uFlag)
38 {
39 unsigned int v2; // eax@1
40
41 v2 = this->uFlags2;
42 if ( v2 & uFlag )
43 this->uFlags2 = v2 & ~uFlag;
44 else
45 this->uFlags2 = uFlag | v2;
46 }
47
48 //----- (0044103C) --------------------------------------------------------
49 void Game::Draw()
50 {
51 Render *v0; // esi@3
52 int _null; // ebx@6
53 float v2; // ST24_4@11
54 double v3; // ST28_8@11
55 int v4; // edi@26
56 int v5; // eax@35
57
58 uFlags2 &= 0xFFFFFFFDu;
59 if ( pParty->_497FC5_check_party_perception_against_level() )
60 uFlags2 |= 2u;
61 pIndoorCamera->sRotationX = pParty->sRotationX;
62 pIndoorCamera->sRotationY = pParty->sRotationY;
63 pIndoorCamera->pos.x = pParty->vPosition.x
64 - ((unsigned __int64)(stru_5C6E00->SinCos(pParty->sRotationY)
65 * (signed __int64)pParty->field_18) >> 16);
66 pIndoorCamera->pos.y = pParty->vPosition.z
67 - ((unsigned __int64)(stru_5C6E00->SinCos(
68 pParty->sRotationY - stru_5C6E00->uIntegerHalfPi)
69 * (signed __int64)pParty->field_18) >> 16);
70 pIndoorCamera->pos.z = pParty->vPosition.y + pParty->sEyelevel;
71 pIndoorCamera->Initialize2();
72 pIndoorCameraD3D->CreateWorldMatrixAndSomeStuff();
73 pIndoorCameraD3D->_4374E8_ProllyBuildFrustrum();
74 //v0 = &pRenderer;
75 if ( pVideoPlayer->AnyMovieLoaded() )
76 {
77 _null = 0;
78 if ( pRenderer->pRenderD3D )
79 goto LABEL_22;
80 pRenderer->SetGameRenderStates();
81 pMouse->_469E3B();
82 }
83 else
84 {
85 if ( pParty->vPosition.x != pParty->vPrevPosition.x | pParty->sRotationY != pParty->sPrevRotationY | pParty->vPosition.z != pParty->vPrevPosition.z | pParty->sRotationX != pParty->sPrevRotationX | pParty->vPosition.y != pParty->vPrevPosition.y | pParty->sEyelevel != pParty->sPrevEyelevel )
86 pParty->uFlags |= 2u;
87 pParty->vPrevPosition.x = pParty->vPosition.x;
88 pParty->vPrevPosition.y = pParty->vPosition.y;
89 //v0 = &pRenderer;
90 pParty->sPrevRotationY = pParty->sRotationY;
91 pParty->vPrevPosition.z = pParty->vPosition.z;
92 pParty->sPrevRotationX = pParty->sRotationX;
93 pParty->sPrevEyelevel = pParty->sEyelevel;
94 pRenderer->SetGameRenderStates();
95 _null = 0;
96 if ( !pRenderer->pRenderD3D )
97 pMouse->_469E3B();
98 if ( !sub_4226C2() || viewparams->field_48 == 1 )
99 {
100 if ( pRenderer->pRenderD3D )
101 {
102 v2 = (double)(((signed int)pMiscTimer->uTotalGameTimeElapsed >> 2) & 0x1F) * 0.032258064 * 6.0;
103 v3 = v2 + 6.7553994e15;
104 pRenderer->field_1036A8_bitmapid = LODWORD(v3);
105 }
106
107 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor)
108 pIndoor->Draw();
109 else if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor)
110 pOutdoor->Draw();
111
112 if ( pRenderer->pRenderD3D )
113 {
114 pDecalBuilder->DrawBloodsplats();
115 if ( pRenderer->pRenderD3D )
116 pGame->pLightmapBuilder->DrawLightmaps(2);
117 }
118 }
119 }
120 pRenderer->DrawBillboards_And_MaybeRenderSpecialEffects_And_EndScene();
121 LABEL_22:
122 pRenderer->BeginScene();
123 if ( pRenderer->pRenderD3D != (RenderD3D *)_null )
124 pMouse->_469E3B();
125 if ( pOtherOverlayList->field_3EC != _null )
126 viewparams->bRedrawGameUI = 1;
127 v4 = viewparams->bRedrawGameUI;
128 GameUI_DrawStatusBar();
129 if ( viewparams->bRedrawGameUI == _null )
130 {
131 //nullsub_1();
132 GameUI_DrawRightPanelItems();
133 }
134 else
135 {
136 GameUI_DrawRightPanelFrames();
137 GameUI_DrawStatusBar_2();
138 viewparams->bRedrawGameUI = _null;
139 }
140 if ( pVideoPlayer->pSmackerMovie == (_SMACK *)_null )
141 {
142 GameUI_DrawMinimap(0x1E8u, 0x10u, 0x271u, 0x85u, viewparams->uMinimapZoom, pParty->uFlags & 2);
143 if ( v4 != _null )
144 {
145 if ( !sub_4226C2() && pRenderer->pRenderD3D != (RenderD3D *)_null )
146 pRenderer->FillRect2(
147 _null,
148 pViewport->uViewportX,
149 pViewport->uViewportY,
150 pViewport->uViewportZ - pViewport->uViewportX,
151 pViewport->uViewportW - pViewport->uViewportY + 1,
152 LOWORD(pRenderer->uTargetGMask) | LOWORD(pRenderer->uTargetBMask));
153 viewparams->field_48 = _null;
154 }
155 }
156 v5 = pOtherOverlayList->field_3EC;
157 pOtherOverlayList->field_3EC = _null;
158 viewparams->bRedrawGameUI = v5;
159 GameUI_DrawPartySpells();
160 if ( v4 != _null || pParty->pHirelings[0].evtc != _null || pParty->pHirelings[1].evtc != _null )
161 DrawHiredNPCs();
162 GameUI_DrawPortraits(v4);
163 GameUI_DrawLifeManaBars();
164 GameUI_DrawCharacterSelectionFrame();
165 if ( sub_44100D() )
166 draw_right_panel();
167 if ( !pVideoPlayer->AnyMovieLoaded() )
168 {
169 pStru6Instance->DrawPlayerBuffAnims();
170 pOtherOverlayList->_441964(v4);
171 GameUI_DrawTorchlightAndWizardEye();
172 }
173 GUI_UpdateWindows();
174 pParty->_4909F4();
175 ++stru_51076C.field_8;
176 dword_5B5924 = _null;
177 if ( v4 != _null )
178 pMouse->field_14 = 1;
179 pMouse->_469EA4();
180 pMouse->DrawCursor();
181 pMouse->_469E1C();
182 pRenderer->EndScene();
183 pRenderer->Present();
184 pParty->uFlags &= 0xFFFFFFFDu;
185 }
186 // 5B5924: using guessed type int dword_5B5924;
187
188
189 //----- (0047A815) --------------------------------------------------------
190 void Game::DrawParticles()
191 {
192 pParticleEngine->Draw();
193 }
194
195 //----- (00463149) --------------------------------------------------------
196 void Game::Loop()
197 {
198 signed int v0; // ebp@3
199 signed int v1; // esi@4
200 Render *v2; // edi@7
201 signed int v3; // esi@7
202 signed int v4; // ecx@58
203 char *v5; // eax@59
204 Player *v6; // esi@65
205 OtherOverlay *v7; // esi@67
206 signed int v8; // edi@67
207 int v9; // edi@69
208 int *pHealth; // esi@71
209 signed int v11; // esi@78
210 int v12; // eax@83
211 const char *v13; // [sp-4h] [bp-68h]@74
212 bool bLoading; // [sp+10h] [bp-54h]@1
213 signed int bLoadinga; // [sp+10h] [bp-54h]@19
214 signed int v16; // [sp+14h] [bp-50h]@8
215 int v17[4]; // [sp+18h] [bp-4Ch]@80
216 MSG Msg; // [sp+28h] [bp-3Ch]@20
217 char Source[64]; // [sp+44h] [bp-20h]@76
218
219 bLoading = uCurrentMenuID == MENU_LOAD;
220 SetCurrentMenuID(0xFFFFFFFFu);
221 if ( bLoading )
222 {
223 pParty->Reset();
224 dword_6BE340 = 0;
225 uGameState = 0;
226 LoadGame(uLoadGameUI_SelectedSlot);
227 }
228 v0 = 1;
229 do
230 {
231 v1 = 1;
232 do
233 {
234 sprintfex(pTmpBuf, "data\\lloyd%d%d.pcx", v0, v1);
235 remove(pTmpBuf);
236 ++v1;
237 }
238 while ( v1 < 6 );
239 ++v0;
240 }
241 while ( v0 < 5 );
242 LoadPlayerPortraintsAndVoices();
243 pIcons_LOD->dword_11B84 = pIcons_LOD->uNumLoadedFiles;
244 pAudioPlayer->SetMusicVolume((signed __int64)(pSoundVolumeLevels[(char)uMusicVolimeMultiplier] * 64.0));
245 v2 = pRenderer;
246 v3 = 1;
247 while ( 2 )
248 {
249 v16 = v3;
250 if ( pMessageQueue_50CBD0->uNumMessages )
251 pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
252 pPartyActionQueue->uNumActions = 0;
253 if ( pParty->bTurnBasedModeOn == v3 )
254 {
255 pTurnEngine->End(0);
256 pParty->bTurnBasedModeOn = 0;
257 }
258 DoPrepareWorld(bLoading, v3);
259 pEventTimer->Resume();
260 LOBYTE(dword_6BE364_game_settings_1) = dword_6BE364_game_settings_1 | 0x80;
261 dword_6BE340 = 2;
262 uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions = 0;
263 if ( pAsyncMouse )
264 pAsyncMouse->Resume();
265 if ( LOBYTE(pGame->pKeyboardInstance->bUsingAsynKeyboard) && pAsyncKeyboard )
266 pAsyncKeyboard->Resume();
267 if ( pRenderer->pRenderD3D )
268 pGame->pVisInstance->_4C1A02();
269 bLoadinga = 0;
270 do
271 {
272 while ( PeekMessageA(&Msg, 0, 0, 0, v3) )
273 {
274 if ( Msg.message == WM_QUIT )
275 Game_DeinitializeAndTerminate(0);
276 TranslateMessage(&Msg);
277 DispatchMessageA(&Msg);
278 }
279 if ( BYTE1(dword_6BE364_game_settings_1) & 1 )
280 {
281 WaitMessage();
282 continue;
283 }
284 pGame->_44EEA7();
285 GameUI_WritePointedObjectStatusString();
286 ProcessInputActions();
287 GameUI_MsgProc();
288 if ( pArcomageGame->bGameInProgress )
289 {
290 ArcomageGame::Loop();
291 LABEL_89:
292 v2->Present();
293 continue;
294 }
295 if ( pAsyncMouse )
296 pAsyncMouse->_46B736_consume_click_lists(v3);
297 if ( pVideoPlayer->pSmackerMovie && !SmackWait(pVideoPlayer->pSmackerMovie) )
298 {
299 v2->BeginScene();
300 pMouse->_469E3B();
301 pVideoPlayer->SmackUpdatePalette(pVideoPlayer->hWindow);
302 pMouse->_469EA4();
303 v2->EndScene();
304 }
305 if ( pVideoPlayer->pBinkMovie && !BinkWait(pVideoPlayer->pBinkMovie) )
306 {
307 v2->BeginScene();
308 pMouse->_469E3B();
309 pVideoPlayer->BinkUpdatePalette(pVideoPlayer->hWindow);
310 pMouse->_469EA4();
311 v2->EndScene();
312 }
313 pEventTimer->Update();
314 pMiscTimer->Update();
315 OnTimer(0);
316 GameUI_StatusBar_UpdateTimedString(0);
317 if ( pMiscTimer->bPaused && !pEventTimer->bPaused )
318 pMiscTimer->Resume();
319 if ( pEventTimer->bTackGameTime && !pParty->bTurnBasedModeOn )
320 pEventTimer->bTackGameTime = 0;
321 if ( !pEventTimer->bPaused && !uGameState )
322 {
323 if ( !pEventTimer->bTackGameTime )
324 _494035_timed_effects__water_walking_damage__etc();
325 if ( dword_6BE364_game_settings_1 & 1 )
326 {
327 dword_6BE364_game_settings_1 &= 0xFFFFFFFEu;
328 }
329 else
330 {
331 sub_401A91_AI();
332 sub_46BDC0_UpdateUserInput_and_MapSpecificStuff();
333 }
334 }
335 if ( v16 )
336 {
337 v16 = 0;
338 viewparams->bRedrawGameUI = v3;
339 }
340 pAudioPlayer->_4AAFCF();
341 if ( uGameState == v3 )
342 goto LABEL_96;
343 if ( uGameState == 2 )
344 {
345 pAudioPlayer->StopChannels(-1, -1);
346 PrepareWorld(0);
347 uGameState = 0;
348 continue;
349 }
350 if ( (signed int)uGameState <= 2 )
351 goto LABEL_85;
352 if ( (signed int)uGameState <= 5 || uGameState == 7 )
353 {
354 LABEL_96:
355 bLoadinga = v3;
356 continue;
357 }
358 if ( uGameState != 8 )
359 {
360 if ( uGameState != 9 )
361 {
362 LABEL_85:
363 pGame->Draw();
364 continue;
365 }
366 pRenderer->BeginScene();
367 GUI_UpdateWindows();
368 pRenderer->EndScene();
369 goto LABEL_89;
370 }
371 pAudioPlayer->StopChannels(-1, -1);
372 memset(pParty->pHirelings, 0, 0x4Cu);
373 memset(&pParty->pHirelings[1], 0, 0x4Cu);
374 v4 = 0;
375 if ( (signed int)pNPCStats->uNumNewNPCs > 0 )
376 {
377 v5 = (char *)&pNPCStats->pNewNPCData[0].uFlags;
378 do
379 {
380 if ( *((int *)v5 + 6) )
381 *v5 &= 0x7Fu;
382 ++v4;
383 v5 += 76;
384 }
385 while ( v4 < (signed int)pNPCStats->uNumNewNPCs );
386 }
387 pVideoPlayer->PlayDeathMovie();
388 if ( pVideoPlayer->AnyMovieLoaded() )
389 pVideoPlayer->Unload();
390 SaveGame(0, 0);
391 ++pParty->uNumDeaths;
392 v6 = pParty->pPlayers;
393 do
394 {
395 v6->SetVariable(VAR_Award, 85);
396 ++v6;
397 }
398 while ( (signed int)v6 < (signed int)pParty->pHirelings );
399 pParty->field_764 = 0;
400 pParty->uTimePlayed += 0x276000ui64;
401 LOWORD(pParty->uFlags) &= 0xFDFBu;
402 pParty->SetGold(0);
403 v7 = pOtherOverlayList->pOverlays;
404 v8 = 50;
405 do
406 {
407 v7->Reset();
408 ++v7;
409 --v8;
410 }
411 while ( v8 );
412 memset(pParty->pPartyBuffs, 0, 0x140u);
413 v9 = 1;
414 if ( pParty->bTurnBasedModeOn == 1 )
415 {
416 pTurnEngine->End(1u);
417 pParty->bTurnBasedModeOn = 0;
418 }
419 pHealth = &pParty->pPlayers[0].sHealth;
420 do
421 {
422 memset(pHealth - 0x64F, 0, 0xA0u);
423 memset(pHealth - 0x67, 0, 0x180u);
424 *pHealth = 1;
425 pHealth += 1743;
426 uActiveCharacter = 1;
427 }
428 while ( (signed int)pHealth < (signed int)&pParty->field_871C[567] );
429 if ( (unsigned __int16)_449B57_test_bit(pParty->_award_bits, 136) )
430 {
431 pParty->vPosition.x = -17331; // respawn in harmondale
432 pParty->vPosition.z = 12547;
433 pParty->vPosition.y = 465;
434 pParty->sRotationY = 0;
435 v13 = "out02.odm";
436 }
437 else
438 {
439 pParty->vPosition.x = 12552; // respawn on emerald isle
440 pParty->vPosition.z = 1816;
441 pParty->vPosition.y = 0;
442 pParty->sRotationY = 512;
443 v13 = "out01.odm";
444 }
445 strcpy(Source, v13);
446 pParty->uFallStartY = pParty->vPosition.y;
447 pParty->sRotationX = 0;
448 pParty->uFallSpeed = 0;
449 pParty->field_6E4 = 0;
450 pParty->field_6E0 = 0;
451 if ( _strcmpi(Source, pCurrentMapName) )
452 {
453 strcpy(pCurrentMapName, Source);
454 _5B65A8_npcdata_uflags_or_other = pParty->vPosition.x;
455 _5B65AC_npcdata_fame_or_other = pParty->vPosition.z;
456 _5B65B0_npcdata_rep_or_other = pParty->vPosition.y;
457 _5B65B4_npcdata_loword_house_or_other = pParty->sRotationY;
458 _5B65B8_npcdata_hiword_house_or_other = pParty->sRotationX;
459 dword_5B65C0 = 1;
460 PrepareWorld(1u);
461 }
462 UpdateActors();
463 v11 = 0;
464 do
465 {
466 if ( pPlayers[v9]->CanAct() )
467 v17[v11++] = v9;
468 ++v9;
469 }
470 while ( v9 <= 4 );
471 if ( v11 )
472 {
473 v12 = rand();
474 pPlayers[v17[v12 % v11]]->PlaySound(99, 0);
475 }
476 ShowStatusBarString(pGlobalTXT_LocalizationStrings[524], 2u);// "Once again you've cheated death!.."
477 uGameState = 0;
478 v3 = 1;
479 }
480 while ( !bLoadinga );
481 dword_6BE340 = 0;
482 pEventTimer->Pause();
483 ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows();
484 if ( uGameState == 3 )
485 {
486 sub_491E3A();
487 LoadPlayerPortraintsAndVoices();
488 uGameState = 0;
489 pIcons_LOD->dword_11B84 = pIcons_LOD->uNumLoadedFiles;
490 bLoading = v3;
491 continue;
492 }
493 break;
494 }
495 uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions = 16;
496 sub_491E3A();
497 }
498 // 4D82B8: using guessed type int __stdcall BinkWait(int);
499 // 4D840C: using guessed type int __stdcall SmackWait(int);
500 // 4E28F8: using guessed type int uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions;
501 // 5B65A8: using guessed type int _5B65A8_npcdata_uflags_or_other;
502 // 5B65AC: using guessed type int _5B65AC_npcdata_fame_or_other;
503 // 5B65B0: using guessed type int _5B65B0_npcdata_rep_or_other;
504 // 5B65B4: using guessed type int _5B65B4_npcdata_loword_house_or_other;
505 // 5B65B8: using guessed type int _5B65B8_npcdata_hiword_house_or_other;
506 // 5B65C0: using guessed type int dword_5B65C0;
507 // 6BE340: using guessed type int dword_6BE340;
508 // 6BE364: using guessed type int dword_6BE364_game_settings_1;
509 // 463149: using guessed type int var_4C[4];
510
511
512
513 //----- (0044F192) --------------------------------------------------------
514 void Game::PushStru165s()
515 {
516 Game *v1; // edi@1
517 int v2; // ebx@1
518 float *v3; // esi@2
519
520 auto a1 = this;
521 v1 = a1;
522 v2 = 0;
523 if ( a1->array_708_size > 0 )
524 {
525 v3 = &a1->array_708[0].flt_10;
526 do
527 {
528 pBloodsplatContainer->AddBloodsplat(
529 *(v3 - 4),
530 *(v3 - 3),
531 *(v3 - 2),
532 v3[2],
533 (signed __int64)*(v3 - 1),
534 (signed __int64)*v3,
535 (signed __int64)v3[1]);
536 ++v2;
537 v3 += 7;
538 }
539 while ( v2 < v1->array_708_size );
540 }
541 }
542
543
544 //----- (0044F120) --------------------------------------------------------
545 void Game::PushStationaryLights(int a2)
546 {
547 signed int v3; // ebx@1
548 char *v4; // esi@2
549
550 auto v2 = this;
551 v3 = 0;
552 if ( (signed int)this->uNumStationaryLights > 0 )
553 {
554 v4 = (char *)&this->pStationaryLights[0].vRGBColor.y;
555 do
556 {
557 pStationaryLightsStack->AddLight(
558 (signed __int64)*((float *)v4 - 4),
559 (signed __int64)*((float *)v4 - 3),
560 (signed __int64)*((float *)v4 - 2),
561 (signed __int64)*((float *)v4 + 2),
562 (int *)(signed __int64)*((float *)v4 - 1),
563 (signed __int64)*(float *)v4,
564 (signed __int64)*((float *)v4 + 1),
565 byte_4E94D0);
566 ++v3;
567 v4 += 28;
568 }
569 while ( v3 < (signed int)v2->uNumStationaryLights );
570 }
571 }
572 // 4E94D0: using guessed type char byte_4E94D0;
573
574 //----- (0044F0FD) --------------------------------------------------------
575 void Game::_44F0FD()
576 {
577 ToggleFlags(0x40u);
578
579 if ( !(uFlags & 0x40) )
580 {
581 array_708_size = 0;
582 field_E0C = 0;
583 }
584 }
585
586 //----- (0044F0D8) --------------------------------------------------------
587 void Game::ToggleFlags(uint uMask)
588 {
589 if (uFlags & uMask)
590 uFlags &= ~uMask;
591 else
592 uFlags |= uMask;
593 }
594
595
596 //----- (0044F07B) --------------------------------------------------------
597 bool Game::_44F07B()
598 {
599 if (!pKeyboardInstance->IsKeyBeingHeld(VK_SHIFT) &&
600 !pKeyboardInstance->IsKeyBeingHeld(VK_LSHIFT) &&
601 !pKeyboardInstance->IsKeyBeingHeld(VK_LSHIFT) ||
602
603 (pKeyboardInstance->WasKeyPressed(VK_F11) == 0 &&
604 pKeyboardInstance->WasKeyPressed(VK_F11)))
605 return true;
606 return false;
607 }
608
609 //----- (0044EEA7) --------------------------------------------------------
610 bool Game::_44EEA7()
611 {
612 Game *v1; // esi@1
613 double v2; // st7@2
614 float depth; // ST00_4@9
615 bool result; // eax@9
616 unsigned int v5; // eax@14
617 __int64 v6; // kr00_8@21
618 unsigned int y; // [sp+4h] [bp-24h]@2
619 unsigned int x; // [sp+8h] [bp-20h]@2
620 bool v9; // [sp+Ch] [bp-1Ch]@2
621 stru157 *v10; // [sp+10h] [bp-18h]@2
622 stru157 *v11; // [sp+14h] [bp-14h]@2
623 POINT a2; // [sp+20h] [bp-8h]@1
624
625 v1 = this;
626 ++qword_5C6DF0;
627 pParticleEngine->UpdateParticles();
628 pMouseInstance->GetCursorPos(&a2);
629 if ( sub_4637E0_is_there_popup_onscreen() )
630 {
631 v11 = &a5;
632 v10 = &stru_F93E30;
633 v9 = 0;
634 x = a2.y;
635 y = a2.x;
636 v2 = GetPickDepth();
637 }
638 else
639 {
640 if ( v1->uFlags2 & 0x10 )
641 {
642 v11 = &a5;
643 v10 = &stru_F93E1C;
644 }
645 else
646 {
647 static bool __init_flag = false;
648 static stru157 static_sub_44EEA7_stru157;
649 if (!__init_flag)
650 {
651 __init_flag = true;
652 static_sub_44EEA7_stru157.field_8 = -1;
653 static_sub_44EEA7_stru157.field_0 = 0;
654 static_sub_44EEA7_stru157.field_4 = 2;
655 static_sub_44EEA7_stru157.field_C = 0;
656 static_sub_44EEA7_stru157.field_10 = 0;
657 }
658 v11 = &a5;
659 v10 = &static_sub_44EEA7_stru157;
660 }
661 v2 = 5120.0;
662 v9 = 0;
663 x = a2.y;
664 y = a2.x;
665 }
666 depth = v2;
667
668 PickMouse(depth, y, x, v9, v10, v11);
669 v1->pLightmapBuilder->std__vector_000004_size = 0;
670 v1->pLightmapBuilder->std__vector_183808_size = 0;
671 pDecalBuilder->std__vector_pDecals_size = 0;
672 pDecalBuilder->field_308008 = 0;
673 result = _44F07B();
674 if ( result )
675 {
676 if ( uFlags & 8 )
677 LOBYTE(pStru10Instance->field_4) = 0;
678 if ( pRenderer->pRenderD3D && uCurrentlyLoadedLevelType == LEVEL_Outdoor)
679 {
680 v5 = GetLevelFogColor();
681 LODWORD(pRenderer->uFogColor) = v5 & 0xFFFFFF;
682 }
683 if (uFlags & 0x0400)
684 uFlags2 |= 0x01;
685 if ( !pRenderer->pRenderD3D && uCurrentlyLoadedLevelType == LEVEL_Outdoor && uNumMobileLightsApplied )
686 {
687 uFlags2 |= 0x01;
688 field_E10 = qword_5C6DF0;
689 }
690 v6 = qword_5C6DF0 - v1->field_E10;
691 if ( qword_5C6DF0 - v1->field_E10 == 1 )
692 v1->uFlags2 |= v6;
693 if ( v1->uNumStationaryLights_in_pStationaryLightsStack != uNumStationaryLightsApplied )
694 {
695 v1->uFlags2 |= 1u;
696 v1->uNumStationaryLights_in_pStationaryLightsStack = uNumStationaryLightsApplied;
697 }
698 _44E904();
699 LOBYTE(result) = 1;
700 }
701 return result;
702 }
703 // 519AB4: using guessed type int uNumStationaryLightsApplied;
704 // 5C6DEC: using guessed type char static_sub_44EEA7_byte_5C6DEC__init_flag;
705 // 5C6DF0: using guessed type __int64 qword_5C6DF0;
706 // F93E1C: using guessed type stru157 stru_F93E1C;
707 // F93E30: using guessed type stru157 stru_F93E30;
708
709 //----- (0044EDE4) --------------------------------------------------------
710 bool Game::_44EDE4(BLVFace *pFace, int *a3)
711 {
712 bool result; // eax@1
713
714 result = (bool)pGame;
715 if ( pGame->uFlags2 & 2 && (result = (bool)pFace, pFace->uAttributes & 2) )
716 {
717 result = sub_48A959(*a3, 1.0, this->_E28_timed_gamma_strength, -1.0);
718 *a3 = result;
719 LOBYTE(result) = 1;
720 }
721 else
722 {
723 LOBYTE(result) = 0;
724 }
725 return result;
726 }
727
728 //----- (0044EE30) --------------------------------------------------------
729 bool Game::_44EE30(ODMFace *a2, int a3)
730 {
731 if (uFlags2 & 0x2 && a2->uFaceAttributes & 0x02)
732 {
733 *(int *)a3 = sub_48A959(*(int *)a3, 1.0, _E28_timed_gamma_strength, -1.0);
734 return true;
735 }
736 else
737 return false;
738 }
739
740
741 //----- (004645FA) --------------------------------------------------------
742 void Game::Deinitialize()
743 {
744 struct tagRECT Rect; // [sp+0h] [bp-10h]@6
745
746 if ( pAsyncMouse )
747 pAsyncMouse->Suspend();
748 if ( LOBYTE(pGame->pKeyboardInstance->bUsingAsynKeyboard) && pAsyncKeyboard )
749 pAsyncKeyboard->Suspend();
750 WriteWindowsRegistryInt("startinwindow", pRenderer->bWindowMode);
751 if ( GetWindowRect(hWnd, &Rect) && pRenderer->bWindowMode )
752 {
753 WriteWindowsRegistryInt("window X", Rect.left);
754 WriteWindowsRegistryInt("window Y", Rect.top);
755 }
756 WriteWindowsRegistryInt("debug flags", stru_51076C.registry_debug_flags);
757 WriteWindowsRegistryInt("valAlwaysRun", bAlwaysRun);
758 pItemsTable->Release();
759 pNPCStats->Release();
760 pAsyncKeyboard->Release();
761 pAsyncMouse->Release();
762 if ( pMouse )
763 pMouse->Deactivate();
764 pAudioPlayer->Release();
765 pNew_LOD->FreeSubIndexAndIO();
766 pGames_LOD->FreeSubIndexAndIO();
767 ClipCursor(0);
768 Game::Destroy();
769 }
770
771 //----- (0044EE7C) --------------------------------------------------------
772 bool Game::draw_debug_outlines()
773 {
774 if (uFlags & 0x04)
775 {
776 pLightmapBuilder->DrawDebugOutlines(-1);
777 pDecalBuilder->DrawDecalDebugOutlines();
778 }
779 return true;
780 }
781
782 //----- (0044EC23) --------------------------------------------------------
783 int Game::_44EC23(stru148 *a2, int *a3, signed int a4)
784 {
785 double v4; // st7@4
786 double v5; // ST00_8@4
787 signed int v6; // eax@5
788 double v7; // ST00_8@6
789 signed int result; // eax@8
790 double v9; // ST00_8@9
791 double v10; // ST00_8@11
792 float a2a; // [sp+14h] [bp+8h]@4
793 float a3a; // [sp+18h] [bp+Ch]@4
794 float a3b; // [sp+18h] [bp+Ch]@6
795 float a4a; // [sp+1Ch] [bp+10h]@9
796 float a4b; // [sp+1Ch] [bp+10h]@11
797
798 if ( this->uFlags2 & 2 && a2->field_59 == 5 && a2->pODMFace->uFaceAttributes & 2 )
799 {
800 v4 = (double)a4;
801 a2a = v4;
802 *a3 |= 2u;
803 a3a = (1.0 - this->_E28_timed_gamma_strength) * v4;
804 v5 = a3a + 6.7553994e15;
805 if ( SLODWORD(v5) >= 0 )
806 {
807 a3b = (1.0 - this->_E28_timed_gamma_strength) * a2a;
808 v7 = a3b + 6.7553994e15;
809 v6 = LODWORD(v7);
810 }
811 else
812 {
813 v6 = 0;
814 }
815 if ( a4 >= v6 )
816 {
817 a4a = (1.0 - this->_E28_timed_gamma_strength) * a2a;
818 v9 = a4a + 6.7553994e15;
819 if ( SLODWORD(v9) >= 0 )
820 {
821 a4b = (1.0 - this->_E28_timed_gamma_strength) * a2a;
822 v10 = a4b + 6.7553994e15;
823 result = LODWORD(v10);
824 }
825 else
826 {
827 result = 0;
828 }
829 }
830 else
831 {
832 result = a4;
833 }
834 }
835 else
836 {
837 result = -1;
838 }
839 return result;
840 }
841
842
843
844 //----- (00465C8B) --------------------------------------------------------
845 Game *Game::Create()
846 {
847 return new Game;
848 }
849
850 //----- (00465CF3) --------------------------------------------------------
851 void Game::Destroy()
852 {
853 if (pGame)
854 delete pGame;
855 pGame = nullptr;
856 }
857
858 //----- (0044ED0A) --------------------------------------------------------
859 signed int Game::_44ED0A(BLVFace *a2, int *a3, signed int a4)
860 {
861 double v4; // st7@3
862 double v5; // ST00_8@3
863 signed int v6; // eax@4
864 double v7; // ST00_8@5
865 signed int result; // eax@7
866 double v9; // ST00_8@8
867 double v10; // ST00_8@10
868 float v11; // [sp+14h] [bp+8h]@3
869 float v12; // [sp+18h] [bp+Ch]@3
870 float v13; // [sp+18h] [bp+Ch]@5
871 float v14; // [sp+1Ch] [bp+10h]@8
872 float v15; // [sp+1Ch] [bp+10h]@10
873
874 if ( this->uFlags2 & 2 && a2->uAttributes & 2 )
875 {
876 v4 = (double)a4;
877 v11 = v4;
878 *a3 |= 2u;
879 v12 = (1.0 - this->_E28_timed_gamma_strength) * v4;
880 v5 = v12 + 6.7553994e15;
881 if ( SLODWORD(v5) >= 0 )
882 {
883 v13 = (1.0 - this->_E28_timed_gamma_strength) * v11;
884 v7 = v13 + 6.7553994e15;
885 v6 = LODWORD(v7);
886 }
887 else
888 {
889 v6 = 0;
890 }
891 if ( a4 >= v6 )
892 {
893 v14 = (1.0 - this->_E28_timed_gamma_strength) * v11;
894 v9 = v14 + 6.7553994e15;
895 if ( SLODWORD(v9) >= 0 )
896 {
897 v15 = (1.0 - this->_E28_timed_gamma_strength) * v11;
898 v10 = v15 + 6.7553994e15;
899 result = LODWORD(v10);
900 }
901 else
902 {
903 result = 0;
904 }
905 }
906 else
907 {
908 result = a4;
909 }
910 }
911 else
912 {
913 result = -1;
914 }
915 return result;
916 }
917
918
919 //----- (0044E4B7) --------------------------------------------------------
920 Game::Game()
921 {
922 uNumStationaryLights = 0;
923 array_708_size = 0;
924 field_E0C = 0;
925 field_E10 = 0;
926 uNumStationaryLights_in_pStationaryLightsStack = 0;
927 bGammaControlInitialized = false;
928 uFlags = 0;
929 uFlags2 = 0;
930 uSomeGammaStartTime = 0;
931 uSomeGammaDeltaTime = 0;
932
933 pThreadWardInstance = new ThreadWard;
934 pParticleEngine = new ParticleEngine;
935 pMouseInstance = new Mouse(pThreadWardInstance);
936 pLightmapBuilder = new LightmapBuilder;
937 pVisInstance = new Vis;
938 pStru6Instance = new stru6;
939 pIndoorCameraD3D = new IndoorCameraD3D;
940 pStru9Instance = new stru9;
941 pStru10Instance = new stru10;
942 pStru11Instance = new stru11;
943 pStru12Instance = new stru12(pStru11Instance);
944 pCShow = new CShow;
945 pKeyboardInstance = new Keyboard;
946 pGammaController = new GammaController;
947
948 uFlags |= 0x0800;
949 uFlags2 |= 0x24;
950
951 _44F0FD();
952
953 bWinNT4_0 = false;
954 if (pVersion->pVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT &&
955 pVersion->pVersionInfo.dwMajorVersion == 4)
956 bWinNT4_0 = true;
957 }
958
959 //----- (0044E7F3) --------------------------------------------------------
960 Game::~Game()
961 {
962 if (pGammaController)
963 delete pGammaController;
964 if (pKeyboardInstance)
965 delete pKeyboardInstance;
966 if (pCShow)
967 delete pCShow;
968 if (pStru12Instance)
969 delete pStru12Instance;
970 if (pStru11Instance)
971 delete pStru11Instance;
972 if (pStru10Instance)
973 delete pStru10Instance;
974 if (pStru9Instance)
975 delete pStru9Instance;
976 if (pIndoorCameraD3D)
977 delete pIndoorCameraD3D;
978 if (pStru6Instance)
979 delete pStru6Instance;
980 if (pVisInstance)
981 delete pVisInstance;
982 if (pLightmapBuilder)
983 delete pLightmapBuilder;
984 if (pMouseInstance)
985 delete pMouseInstance;
986 if (pParticleEngine)
987 delete pParticleEngine;
988 if (pThreadWardInstance)
989 delete pThreadWardInstance;
990 }
991
992 //----- (0044E904) --------------------------------------------------------
993 void Game::_44E904()
994 {
995 Game *v1; // esi@1
996 unsigned __int64 v2; // qax@1
997 unsigned int v3; // ecx@1
998 int v4; // edi@1
999 unsigned __int8 v5; // cf@7
1000 double v6; // st7@13
1001 double v7; // st7@15
1002 signed __int64 v8; // [sp+Ch] [bp-8h]@1
1003
1004 v1 = this;
1005 v2 = pEventTimer->Time();
1006 v4 = (v2 - v1->uSomeGammaStartTime) >> 32;
1007 v3 = v2 - LODWORD(v1->uSomeGammaStartTime);
1008 v8 = v2 - v1->uSomeGammaStartTime;
1009 if ( v4 < 0
1010 || SHIDWORD(v2) < ((unsigned int)v2 < LODWORD(v1->uSomeGammaStartTime)) + HIDWORD(v1->uSomeGammaStartTime) | v4 == 0
1011 && v3 <= 0x80 )
1012 {
1013 if ( v4 > 0 || v4 >= 0 )
1014 goto LABEL_12;
1015 v3 = 0;
1016 v4 = 0;
1017 }
1018 else
1019 {
1020 if ( v1->uSomeGammaDeltaTime )
1021 {
1022 LODWORD(v1->uSomeGammaDeltaTime) = 0;
1023 HIDWORD(v1->uSomeGammaDeltaTime) = 0;
1024 }
1025 else
1026 {
1027 LODWORD(v1->uSomeGammaDeltaTime) = v3;
1028 HIDWORD(v1->uSomeGammaDeltaTime) = v4;
1029 }
1030 v5 = __CFADD__(v3, -128);
1031 v3 -= 128;
1032 v4 = v5 + v4 - 1;
1033 }
1034 v1->uSomeGammaStartTime = v2;
1035 v8 = __PAIR__(v4, v3);
1036 LABEL_12:
1037 if ( v1->uSomeGammaDeltaTime )
1038 v6 = (double)(signed __int64)(v1->uSomeGammaDeltaTime - __PAIR__(v4, v3));
1039 else
1040 v6 = (double)v8;
1041 v7 = v6 * 0.0078125;
1042 if ( v7 < 0.0 || v7 <= 1.0 )
1043 {
1044 if ( v7 < 0.0 )
1045 v7 = 0.0;
1046 }
1047 else
1048 {
1049 v7 = 1.0;
1050 }
1051 if ( pRenderer->pRenderD3D )
1052 v1->_E28_timed_gamma_strength = v7;
1053 else
1054 v1->_E28_timed_gamma_strength = (1.0 - 0.5) * v7 + 0.5;
1055 }
1056
1057 //----- (0044EA17) --------------------------------------------------------
1058 bool Game::InitializeGammaController()
1059 {
1060 if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
1061 pVersion->pVersionInfo.dwMajorVersion != 4 )
1062 pGammaController->InitializeFromSurface(pRenderer->pFrontBuffer4);
1063
1064 bGammaControlInitialized = true;
1065 uSomeGammaStartTime = pEventTimer->Time();
1066 return true;
1067 }
1068
1069 //----- (0044EA5E) --------------------------------------------------------
1070 char Game::PickMouse(float fPickDepth, unsigned int uMouseX, unsigned int uMouseY, bool bOutline, stru157 *a5, stru157 *a6)
1071 {
1072 char result; // al@3
1073 std::string v10; // [sp-4h] [bp-24h]@5
1074 float v11; // [sp+4h] [bp-1Ch]@10
1075 float v12; // [sp+8h] [bp-18h]@10
1076 const char *v13; // [sp+Ch] [bp-14h]@5
1077 int v14; // [sp+10h] [bp-10h]@5
1078 std::string *v15; // [sp+18h] [bp-8h]@5
1079 int a3; // [sp+1Fh] [bp-1h]@5
1080
1081 auto v7 = this;
1082 if (!uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions
1083 && pRenderer->pRenderD3D)
1084 {
1085 if (!pVisInstance)
1086 {
1087 MessageBoxW(nullptr, L"The 'Vis' object pointer has not been instatiated, but CGame::Pick() is trying to call through it.", nullptr, 0);
1088 ExitProcess(0);
1089 }
1090
1091 if ( (signed int)uMouseX >= (signed int)pViewport->uScreenX
1092 && (signed int)uMouseX <= (signed int)pViewport->uScreenZ
1093 && (signed int)uMouseY >= (signed int)pViewport->uScreenY
1094 && (signed int)uMouseY <= (signed int)pViewport->uScreenW )
1095 {
1096 v14 = (int)a6;
1097 v12 = (double)(signed int)uMouseY;
1098 v11 = (double)(signed int)uMouseX;
1099 pVisInstance->PickMouse(fPickDepth, v11, v12, a5, a6);
1100
1101 if (bOutline)
1102 OutlineSelection();
1103 }
1104 return true;
1105 }
1106 return false;
1107 }
1108 // 4E28F8: using guessed type int uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions;
1109
1110 //----- (0044EB12) --------------------------------------------------------
1111 bool Game::_44EB12(bool bOutline, stru157 *a3, stru157 *a4)
1112 {
1113 if ( !uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions
1114 && pVisInstance
1115 && pRenderer->pRenderD3D )
1116 {
1117 bool r = pVisInstance->_4C05CC(&pVisInstance->stru1, a3, a4);
1118
1119 if (bOutline)
1120 OutlineSelection();
1121 return r;
1122 }
1123 return false;
1124 }
1125 // 4E28F8: using guessed type int uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions;
1126
1127 //----- (0044EB5A) --------------------------------------------------------
1128 void Game::OutlineSelection()
1129 {
1130 Vis *v1; // eax@1
1131 Vis_stru1_stru0 *v2; // eax@3
1132 void *v3; // edx@9
1133 int v4; // eax@10
1134 int v5; // eax@11
1135 int v6; // eax@14
1136 int v7; // eax@15
1137 const char *v9; // [sp-8h] [bp-14h]@8
1138 int v10; // [sp-4h] [bp-10h]@8
1139 char v11; // [sp+0h] [bp-Ch]@18
1140 int a3; // [sp+Ah] [bp-2h]@8
1141
1142 v1 = this->pVisInstance;
1143 if ( v1 )
1144 {
1145 v2 = (Vis_stru1_stru0 *)((signed int)v1->stru1.uNumPointers <= 0 ? 0 : v1->stru1.array_1804[0]);
1146 if ( v2 )
1147 {
1148 if ( v2->uObjectType == 1 )
1149 {
1150 MessageBoxW(nullptr, L"Sprite outline currently Unsupported", nullptr, 0);
1151 ExitProcess(0);
1152 }
1153
1154 if ( v2->uObjectType == 2 )
1155 {
1156 v3 = v2->pObjectInfo; // TODO 2 objects for indoor/outdoor
1157 // some clues in header for Vis_stru1_stru0
1158 if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
1159 {
1160 v4 = *((int *)v3 + 11);
1161 if ( v4 & 0x10000 )
1162 v5 = v4 & 0xFFFEFFFF;
1163 else
1164 v5 = v4 | 0x10000;
1165 *((int *)v3 + 11) = v5;
1166 }
1167 else
1168 {
1169 v6 = *((int *)v3 + 7);
1170 if ( v6 & 0x10000 )
1171 v7 = v6 & 0xFFFEFFFF;
1172 else
1173 v7 = v6 | 0x10000;
1174 *((int *)v3 + 7) = v7;
1175 }
1176 }
1177 else
1178 {
1179 MessageBoxW(nullptr, L"Undefined CObjectInfo type requested in CGame::outline_selection()", nullptr, 0);
1180 ExitProcess(0);
1181 }
1182 }
1183 }
1184 }