0
|
1 #include "OSAPI.h"
|
|
2
|
1016
|
3 #include "VideoPlayer.h"
|
|
4 #include "Vis.h"
|
0
|
5 #include "Mouse.h"
|
|
6 #include "Items.h"
|
|
7 #include "Party.h"
|
|
8 #include "LOD.h"
|
|
9 #include "Game.h"
|
|
10
|
1016
|
11 #include "stru11.h"
|
0
|
12
|
|
13
|
|
14
|
|
15
|
|
16
|
|
17 Mouse *pMouse;
|
|
18
|
|
19
|
|
20
|
|
21
|
|
22
|
|
23 //----- (00469860) --------------------------------------------------------
|
|
24 void Mouse::GetClickPos(unsigned int *pX, unsigned int *pY)
|
|
25 {
|
1038
|
26 *pX = uMouseClickX;
|
|
27 *pY = uMouseClickY;
|
0
|
28 }
|
|
29
|
|
30 //----- (004698A6) --------------------------------------------------------
|
|
31 void Mouse::RemoveHoldingItem()
|
|
32 {
|
|
33 pParty->pPickedItem.Reset();
|
|
34 if (strcmpi(pCurrentCursorName, "MICON2"))
|
|
35 SetCursorBitmap("MICON1");
|
|
36 }
|
|
37
|
|
38 //----- (004698D8) --------------------------------------------------------
|
|
39 void Mouse::SetCursorBitmapFromItemID(unsigned int uItemID)
|
|
40 {
|
|
41 pMouse->SetCursorBitmap(pItemsTable->pItems[uItemID].pIconName);
|
|
42 }
|
|
43
|
|
44 //----- (004698F6) --------------------------------------------------------
|
|
45 void Mouse::SetCurrentCursorBitmap()
|
|
46 {
|
|
47 SetCursorBitmap(pCurrentCursorName);
|
|
48 }
|
|
49
|
|
50 //----- (00469903) --------------------------------------------------------
|
|
51 void Mouse::SetCursorBitmap(const char *pName)
|
|
52 {
|
|
53 Mouse *v2; // esi@1
|
|
54 HCURSOR v3; // eax@10
|
1038
|
55 //int v4; // ecx@10
|
0
|
56 double v5; // st7@11
|
|
57 float v6; // ST04_4@12
|
|
58 LONG v7; // eax@14
|
|
59 LONG v8; // eax@17
|
|
60 unsigned int v9; // eax@21
|
|
61 float v10; // [sp+4h] [bp-18h]@11
|
|
62 struct tagPOINT Point; // [sp+14h] [bp-8h]@20
|
|
63
|
|
64 v2 = this;
|
|
65 if ( !this->bInitialized || !pName )
|
|
66 return;
|
|
67 if ( _strcmpi("MICON2", pName) )
|
|
68 pGame->uFlags2 &= 0xFFFFFFEFu;
|
|
69 else
|
|
70 pGame->uFlags2 |= 0x10u;
|
|
71 if ( _strcmpi(v2->pCurrentCursorName, pName) )
|
|
72 strcpy(v2->pCurrentCursorName, pName);
|
|
73 ClearCursor();
|
|
74 if ( _strnicmp(pName, "MICON1", 5u) )
|
|
75 {
|
|
76 v9 = pIcons_LOD->LoadTexture(pName, TEXTURE_16BIT_PALETTE);
|
|
77 v2->uCursorTextureID = v9;
|
|
78 v2->uCursorTextureID_2 = v9;
|
|
79 v2->AllocCursorSystemMem();
|
|
80 v2->field_C = 0;
|
791
|
81 v2->bRedraw = 1;
|
0
|
82 v2->bActive = 1;
|
|
83 if ( !areWeLoadingTexture )
|
|
84 {
|
|
85 if (uCursorTextureID != -1)
|
|
86 pIcons_LOD->pTextures[uCursorTextureID].Release();
|
1006
|
87 pIcons_LOD->SyncLoadedFilesCount();
|
0
|
88 }
|
|
89 return;
|
|
90 }
|
|
91 v2->bActive = 0;
|
|
92 v2->field_C = 1;
|
|
93 if ( !strcmp(pName, "MICON1") )
|
|
94 {
|
|
95 v3 = LoadCursorA(GetModuleHandleW(nullptr), "Arrow");
|
|
96 SetClassLongA(hWnd, GCL_HCURSOR, (LONG)v3);
|
|
97 }
|
1068
|
98 else if ( !strcmp(pName, "MICON2") )
|
0
|
99 {
|
|
100 v7 = (LONG)LoadCursorA(GetModuleHandleW(nullptr), "Target");
|
|
101 SetClassLongA(hWnd, -12, v7);
|
|
102 }
|
1068
|
103 else if ( !strcmp(pName, "MICON3") )
|
0
|
104 {
|
|
105 v8 = (LONG)LoadCursorA(0, (LPCSTR)IDC_WAIT);
|
|
106 SetClassLongA(hWnd, -12, v8);
|
|
107 }
|
779
|
108 //LABEL_18:
|
1038
|
109
|
779
|
110 GetCursorPos(&Point);
|
1068
|
111 ClientToScreen(hWnd,&Point);
|
779
|
112 SetCursorPos(Point.x, Point.y);
|
0
|
113 }
|
|
114 // 506128: using guessed type int areWeLoadingTexture;
|
|
115
|
|
116 //----- (00469AE4) --------------------------------------------------------
|
|
117 LONG Mouse::_469AE4()
|
|
118 {
|
|
119 Mouse *v1; // esi@1
|
|
120 LONG v2; // ecx@2
|
|
121 LONG result; // eax@2
|
|
122 struct tagPOINT Point; // [sp+Ch] [bp-8h]@2
|
|
123
|
|
124 v1 = this;
|
|
125 this->field_8 = 1;
|
1038
|
126 /*if (pAsyncMouse)
|
0
|
127 {
|
|
128 v2 = *((int *)pAsyncMouse + 6);
|
|
129 Point.x = *((int *)pAsyncMouse + 6);
|
|
130 result = *((int *)pAsyncMouse + 7);
|
|
131 }
|
|
132 else
|
1038
|
133 {*/
|
0
|
134 GetCursorPos(&Point);
|
|
135 if ( pRenderer->bWindowMode )
|
|
136 ScreenToClient(hWnd, &Point);
|
|
137 result = Point.y;
|
|
138 v2 = Point.x;
|
1038
|
139 //}
|
0
|
140 v1->uMouseClickX = v2;
|
|
141 v1->uMouseClickY = result;
|
|
142 if ( pRenderer->bWindowMode )
|
|
143 goto LABEL_16;
|
1038
|
144 //if (pAsyncMouse)
|
|
145 // goto LABEL_24;
|
0
|
146 if ( v2 < 0 )
|
|
147 v2 = 0;
|
|
148 if ( result < 0 )
|
|
149 result = 0;
|
|
150 if ( v2 > 639 )
|
|
151 v2 = 639;
|
|
152 if ( result > 479 )
|
|
153 {
|
|
154 result = 479;
|
|
155 LABEL_16:
|
1038
|
156 //if (pAsyncMouse)
|
|
157 // goto LABEL_24;
|
0
|
158 if ( pRenderer->bWindowMode && (v2 < 0 || result < 0 || v2 > 639 || result > 479) )
|
|
159 goto LABEL_23;
|
|
160 }
|
|
161 if ( v1->field_C )
|
|
162 LABEL_23:
|
|
163 v1->bActive = 0;
|
|
164 LABEL_24:
|
|
165 v1->field_8 = 0;
|
|
166 return result;
|
|
167 }
|
|
168
|
|
169 //----- (00469BA3) --------------------------------------------------------
|
|
170 void Mouse::ClearCursor()
|
|
171 {
|
|
172 Mouse *v1; // esi@1
|
|
173 void *v2; // eax@1
|
|
174 void **v3; // esi@5
|
|
175
|
|
176 v1 = this;
|
|
177 v2 = this->pCursorBitmap_sysmem;
|
|
178 this->bActive = 0;
|
|
179 if ( v2 )
|
|
180 {
|
|
181 free(v2);
|
|
182 v1->pCursorBitmap_sysmem = 0;
|
|
183 }
|
|
184 if ( v1->pCursorBitmap2_sysmem )
|
|
185 {
|
|
186 free(v1->pCursorBitmap2_sysmem);
|
|
187 v1->pCursorBitmap2_sysmem = 0;
|
|
188 }
|
|
189 v3 = &v1->ptr_90;
|
|
190 if ( *v3 )
|
|
191 free(*v3);
|
|
192 *v3 = 0;
|
|
193 }
|
|
194
|
|
195 //----- (00469BE6) --------------------------------------------------------
|
|
196 void Mouse::AllocCursorSystemMem()
|
|
197 {
|
|
198 bActive = 0;
|
|
199 if (!pCursorBitmap_sysmem)
|
|
200 pCursorBitmap_sysmem = (unsigned __int16 *)DoAllocCursorMem();
|
|
201 if (!pCursorBitmap2_sysmem)
|
|
202 pCursorBitmap2_sysmem = (unsigned __int8 *)DoAllocCursorMem();
|
|
203 }
|
|
204
|
|
205 //----- (00469C0D) --------------------------------------------------------
|
|
206 void *Mouse::DoAllocCursorMem()
|
|
207 {
|
973
|
208 auto tex = pIcons_LOD->GetTexture(uCursorTextureID);
|
|
209 return malloc(4 * tex->uTextureWidth * tex->uTextureHeight);
|
0
|
210 }
|
|
211
|
|
212 //----- (00469C39) --------------------------------------------------------
|
|
213 POINT *Mouse::GetCursorPos(POINT *a2)
|
|
214 {
|
1038
|
215 a2->x = this->uMouseClickX;
|
|
216 a2->y = this->uMouseClickY;
|
|
217 return a2;
|
0
|
218 }
|
|
219
|
|
220 //----- (00469C65) --------------------------------------------------------
|
|
221 void Mouse::Initialize(HWND hWnd)
|
|
222 {
|
|
223 this->hWnd = hWnd;
|
|
224 this->bActive = 0;
|
|
225 this->bInitialized = 1;
|
|
226 this->pCursorBitmapPos.x = 0;
|
|
227 this->pCursorBitmapPos.y = 0;
|
|
228 this->uMouseClickX = 0;
|
|
229 this->uMouseClickY = 0;
|
|
230 this->pCursorBitmap_sysmem = 0;
|
|
231 this->field_34 = 0;
|
|
232 this->pCursorBitmap2_sysmem = 0;
|
|
233
|
|
234 SetCursorBitmap("MICON3");
|
|
235 SetCursorBitmap("MICON2");
|
|
236 SetCursorBitmap("MICON1");
|
|
237 }
|
|
238
|
762
|
239 // inlined
|
|
240 //----- (0045FE00) mm6 chinese --------------------------------------------
|
|
241 void Mouse::SetActive(bool active)
|
|
242 {
|
|
243 bActive = active;
|
|
244 }
|
|
245
|
0
|
246 //----- (00469CC2) --------------------------------------------------------
|
|
247 void Mouse::Deactivate()
|
|
248 {
|
|
249 if (bInitialized)
|
762
|
250 SetActive(false);
|
0
|
251 }
|
|
252
|
|
253 //----- (00469CCD) --------------------------------------------------------
|
|
254 void Mouse::DrawCursor()
|
|
255 {
|
|
256 Mouse *v1; // esi@1
|
|
257 char v11; // zf@6
|
|
258 signed int v3; // eax@6
|
|
259 signed int v4; // ecx@6
|
|
260 Vec4_int_ *v5; // edx@21
|
|
261 int v6; // edi@21
|
|
262 int v7; // ebx@21
|
|
263 int v8; // eax@29
|
|
264 unsigned int v9; // eax@31
|
|
265
|
|
266 v1 = this;
|
|
267 if ( this->bInitialized )
|
|
268 {
|
|
269 if ( !this->field_8 && this->bActive && !this->field_C )
|
|
270 pMouse->_469AE4();
|
|
271 v11 = v1->field_C == 0;
|
|
272 v3 = v1->uMouseClickX;
|
|
273 v4 = v1->uMouseClickY;
|
|
274 v1->field_F4 = 1;
|
|
275 if ( !v11 )
|
|
276 goto LABEL_12;
|
|
277 if ( pRenderer->bWindowMode )
|
|
278 {
|
|
279 if ( v3 < 0 || v4 < 0 || v3 > 639 || v4 > 479 )
|
|
280 {
|
|
281 LABEL_12:
|
|
282 v1->field_F4 = 0;
|
|
283 return;
|
|
284 }
|
|
285 }
|
|
286 else
|
|
287 {
|
|
288 if ( v3 < 0 )
|
|
289 v3 = 0;
|
|
290 if ( v4 < 0 )
|
|
291 v4 = 0;
|
|
292 if ( v3 > 639 )
|
|
293 v3 = 639;
|
|
294 if ( v4 > 479 )
|
|
295 v4 = 479;
|
|
296 }
|
|
297 v5 = &v1->pCursorBitmapRect;
|
|
298 v6 = v3 + v1->uCursorBitmapPitch;
|
|
299 v7 = v4 + v1->field_5C[0];
|
|
300 v1->pCursorBitmapRect.y = v4;
|
|
301 v1->pCursorBitmapRect.x = v3;
|
|
302 v1->pCursorBitmapRect.z = v6;
|
|
303 v1->pCursorBitmapRect.w = v7;
|
|
304 if ( v3 < 0 )
|
|
305 v5->x = 0;
|
|
306 if ( v4 < 0 )
|
|
307 v1->pCursorBitmapRect.y = 0;
|
|
308 if ( v6 > 640 )
|
|
309 v1->pCursorBitmapRect.z = 640;
|
|
310 if ( v7 > 480 )
|
|
311 v1->pCursorBitmapRect.w = 480;
|
|
312 v8 = v1->pCursorBitmapRect.z;
|
|
313 v1->bActive = 0;
|
|
314 v1->uCursorBitmapWidth = v8 - v5->x;
|
791
|
315 v11 = v1->bRedraw == 0;
|
0
|
316 v1->uCursorBitmapHeight = v1->pCursorBitmapRect.w - v1->pCursorBitmapRect.y;
|
|
317 if ( !v11 )
|
|
318 {
|
|
319 if ( pMouse->ptr_90 )
|
|
320 v9 = 2 * pMouse->uCursorBitmapPitch;
|
|
321 else
|
|
322 v9 = 0;
|
|
323 pRenderer->_4A6DF5(
|
|
324 v1->pCursorBitmap_sysmem,
|
|
325 v9,
|
|
326 &v1->pCursorBitmapPos,
|
|
327 pRenderer->pTargetSurface,
|
|
328 pRenderer->uTargetSurfacePitch,
|
|
329 &v1->pCursorBitmapRect);
|
791
|
330 v1->bRedraw = false;
|
0
|
331 }
|
|
332 }
|
|
333 }
|
|
334
|
|
335 //----- (00469E1C) --------------------------------------------------------
|
|
336 void Mouse::_469E1C()
|
|
337 {
|
|
338 bActive = true;
|
|
339 }
|
|
340
|
|
341 //----- (00469E24) --------------------------------------------------------
|
|
342 void Mouse::_469E24()
|
|
343 {
|
|
344 if (pCursorBitmap3_sysmembits_16bit)
|
|
345 {
|
|
346 free(pCursorBitmap3_sysmembits_16bit);
|
|
347 pCursorBitmap3_sysmembits_16bit = 0;
|
|
348 }
|
|
349 }
|
|
350
|
|
351 //----- (00469E3B) --------------------------------------------------------
|
|
352 void Mouse::DrawCursorToTarget()
|
|
353 {
|
|
354 if (!pCursorBitmap3_sysmembits_16bit)
|
|
355 return;
|
|
356
|
|
357 auto pSrc = pCursorBitmap3_sysmembits_16bit;
|
|
358 for (uint y = field_44; y < field_4C; ++y)
|
|
359 for (uint x = field_40; x < field_48; ++x)
|
|
360 pRenderer->pTargetSurface[y * pRenderer->uTargetSurfacePitch + x] = *pSrc++;
|
|
361 }
|
|
362
|
|
363 //----- (00469EA4) --------------------------------------------------------
|
|
364 void Mouse::_469EA4()
|
|
365 {
|
920
|
366 //Mouse *v1; // esi@1
|
|
367 unsigned int pTextureID; // eax@2
|
|
368 Texture *pTexture; // edi@2
|
0
|
369 unsigned int v4; // ecx@3
|
|
370 unsigned int v5; // eax@3
|
|
371 unsigned int v6; // ebx@5
|
|
372 int v7; // ecx@15
|
|
373 int v8; // ecx@25
|
|
374 int v9; // ebx@26
|
|
375 unsigned int v10; // eax@26
|
|
376 int v11; // edx@27
|
|
377 unsigned __int16 *v12; // edx@29
|
|
378 unsigned __int16 *v13; // ebx@29
|
|
379 unsigned int a2; // [sp+Ch] [bp-1Ch]@5
|
|
380 unsigned int v15; // [sp+10h] [bp-18h]@5
|
|
381 unsigned int v16; // [sp+14h] [bp-14h]@25
|
|
382 unsigned __int16 *v17; // [sp+18h] [bp-10h]@25
|
|
383 int v18; // [sp+1Ch] [bp-Ch]@27
|
|
384 int v19; // [sp+20h] [bp-8h]@15
|
|
385 unsigned __int16 *v20; // [sp+20h] [bp-8h]@28
|
920
|
386 int pTextureWidth; // [sp+24h] [bp-4h]@12
|
0
|
387 unsigned __int16 *v22; // [sp+24h] [bp-4h]@25
|
|
388
|
920
|
389 //v1 = this;
|
0
|
390 if ( pParty->pPickedItem.uItemID )
|
|
391 {
|
920
|
392 pTextureID = pIcons_LOD->LoadTexture(pItemsTable->pItems[pParty->pPickedItem.uItemID].pIconName, TEXTURE_16BIT_PALETTE);
|
|
393 pTexture = (Texture *)(pTextureID != -1 ? (int)&pIcons_LOD->pTextures[pTextureID] : 0);
|
1038
|
394
|
0
|
395 v4 = pMouse->uMouseClickX;
|
|
396 v5 = pMouse->uMouseClickY;
|
1038
|
397
|
0
|
398 v6 = v5;
|
|
399 a2 = v4;
|
|
400 v15 = v5;
|
|
401 if ( (signed int)v4 <= 639 && (signed int)v5 <= 479 )
|
|
402 {
|
|
403 if ( (v4 & 0x80000000u) != 0 )
|
|
404 a2 = 0;
|
|
405 if ( (v5 & 0x80000000u) != 0 )
|
|
406 {
|
|
407 v6 = 0;
|
|
408 v15 = 0;
|
|
409 }
|
920
|
410 if ( (signed int)(pTexture->uTextureWidth + a2) <= 640 )
|
|
411 pTextureWidth = pTexture->uTextureWidth;
|
0
|
412 else
|
920
|
413 pTextureWidth = 640 - a2;
|
|
414 if ( (signed int)(pTexture->uTextureHeight + v6) <= 480 )
|
0
|
415 {
|
920
|
416 v19 = pTexture->uTextureHeight;
|
|
417 v7 = pTexture->uTextureHeight;
|
0
|
418 }
|
|
419 else
|
|
420 {
|
|
421 v7 = 480 - v6;
|
|
422 v19 = 480 - v6;
|
|
423 }
|
920
|
424 if ( !this->pCursorBitmap3_sysmembits_16bit
|
|
425 || a2 != this->field_40
|
|
426 || v6 != this->field_44
|
|
427 || a2 + pTextureWidth != this->field_48
|
|
428 || v6 + v7 != this->field_4C )
|
0
|
429 {
|
920
|
430 if ( this->pCursorBitmap3_sysmembits_16bit )
|
|
431 free(this->pCursorBitmap3_sysmembits_16bit);
|
|
432 this->pCursorBitmap3_sysmembits_16bit = (unsigned __int16 *)operator new(2 * pTexture->uTextureHeight * pTexture->uTextureWidth);
|
|
433 this->field_40 = a2;
|
|
434 this->field_48 = a2 + pTextureWidth;
|
|
435 this->field_44 = v6;
|
|
436 this->field_4C = v6 + v19;
|
0
|
437 }
|
920
|
438 v8 = this->field_44;
|
|
439 v22 = this->pCursorBitmap3_sysmembits_16bit;
|
0
|
440 v17 = pRenderer->pTargetSurface;
|
|
441 v16 = pRenderer->uTargetSurfacePitch;
|
920
|
442 if ( v8 < this->field_4C )
|
0
|
443 {
|
920
|
444 v9 = this->field_48;
|
0
|
445 v10 = pRenderer->uTargetSurfacePitch * v8;
|
|
446 do
|
|
447 {
|
920
|
448 v11 = this->field_40;
|
|
449 v18 = this->field_40;
|
0
|
450 if ( v11 < v9 )
|
|
451 {
|
|
452 v20 = &v17[v10 + v11];
|
|
453 do
|
|
454 {
|
|
455 v12 = v20;
|
|
456 v13 = v22;
|
|
457 ++v18;
|
|
458 ++v20;
|
|
459 ++v22;
|
|
460 *v13 = *v12;
|
920
|
461 v9 = this->field_48;
|
0
|
462 }
|
|
463 while ( v18 < v9 );
|
|
464 }
|
|
465 v10 += v16;
|
|
466 ++v8;
|
|
467 }
|
920
|
468 while ( v8 < this->field_4C );
|
0
|
469 v6 = v15;
|
|
470 }
|
315
|
471 if (pParty->pPickedItem.Broken())
|
920
|
472 pRenderer->DrawTransparentRedShade(a2, v6, pTexture);
|
315
|
473 else if (!pParty->pPickedItem.Identified())
|
920
|
474 pRenderer->DrawTransparentGreenShade(a2, v6, pTexture);
|
0
|
475 else
|
920
|
476 pRenderer->DrawTextureTransparent(a2, v6, pTexture);
|
0
|
477 }
|
|
478 }
|
|
479 else
|
|
480 {
|
|
481 if ( this->pCursorBitmap3_sysmembits_16bit )
|
|
482 {
|
|
483 free(this->pCursorBitmap3_sysmembits_16bit);
|
920
|
484 this->pCursorBitmap3_sysmembits_16bit = 0;
|
0
|
485 }
|
|
486 }
|
|
487 }
|
|
488
|
|
489 //----- (0046A080) --------------------------------------------------------
|
|
490 void Mouse::Activate(int bActive)
|
|
491 {
|
|
492 bActive = bActive;
|
|
493 }
|
|
494
|
|
495 //----- (0046A08A) --------------------------------------------------------
|
|
496 void Mouse::SetMouseClick(int x, int y)
|
|
497 {
|
|
498 uMouseClickX = x;
|
|
499 uMouseClickY = y;
|
|
500 }
|
|
501
|