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