-
Notifications
You must be signed in to change notification settings - Fork 46
/
proxyIDirect3DDevice9.cpp
4800 lines (4068 loc) · 155 KB
/
proxyIDirect3DDevice9.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
PROJECT: mod_sa
LICENSE: See LICENSE in the top level directory
COPYRIGHT: Copyright we_sux, BlastHack
mod_sa is available from https://github.com/BlastHackNet/mod_s0beit_sa/
mod_sa is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
mod_sa is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with mod_sa. If not, see <http://www.gnu.org/licenses/>.
*/
#include "main.h"
// externals
unsigned long ulFullScreenRefreshRate;
extern D3DC9 orig_Direct3DCreate9 = NULL;;
// externals
#pragma data_seg( ".d3d9_shared" )
proxyIDirect3DDevice9 *pDirect3DDevice9 = NULL;
HRESULT_VOID orig_Direct3DShaderValidatorCreate9 = NULL;
IDirect3DDevice9 *origIDirect3DDevice9;
IDirect3DDevice9 *pRwD3DDevice = (IDirect3DDevice9 *) * (DWORD *)__RwD3DDevice;
IDirect3DTexture9 *pSpriteTexture;
D3DPRESENT_PARAMETERS pPresentParam;
D3DMATRIX m_mViewMatrix, m_mProjMatrix, m_mWorldMatrix;
CDirect3DData *pD3DData = new CDirect3DData();
#pragma data_seg()
bool bD3DRenderInit;
bool bD3DWindowModeSet;
bool g_isRequestingWindowModeToggle;
bool g_isRequesting_RwD3D9ChangeVideoMode;
IDirect3DPixelShader9 *chams_green;
IDirect3DPixelShader9 *chams_blue;
IDirect3DPixelShader9 *chams_red;
D3DXVECTOR3 speedoPos;
D3DXVECTOR2 needlePos;
IDirect3DTexture9 *tSpeedoPNG;
ID3DXSprite *sSpeedoPNG;
IDirect3DTexture9 *tNeedlePNG;
ID3DXSprite *sNeedlePNG;
// create a render object
CD3DRender *render = new CD3DRender( 128 );
// create font objects
// also HUD somehow, the HUD comment below isn't totally right
CD3DFont *pD3DFont = new CD3DFont( "Tahoma", 10, FCR_BORDER );
//pd3dFont_sampStuff = player info list, player score list, player ESP
CD3DFont *pD3DFont_sampStuff = new CD3DFont( "Tahoma", 10, FCR_BORDER );
//pD3DFontFixed = cheat_state_msg, HUD
CD3DFont *pD3DFontFixed = new CD3DFont( "Small Fonts", 8, FCR_BORDER );
//pD3DFontFixedSmall = health under bars (cars, players), vehicle ESP
CD3DFont *pD3DFontFixedSmall = new CD3DFont( "Small Fonts", 8, FCR_BORDER );
//pD3DFontChat = chat, kill list
//CD3DFont *pD3DFontChat = new CD3DFont( "Tahoma", 10, FCR_NONE );
CD3DFont *pD3DFontChat = new CD3DFont( "Tahoma", 11, FCR_BOLD | FCR_BORDER );
//pD3DFontDebugWnd = debug window
CD3DFont *pD3DFontDebugWnd = new CD3DFont("Lucida Console", 8, FCR_BORDER );
struct gui *hud_bar = &set.guiset[0];
struct gui *menu_titlebar_background = &set.guiset[2];
struct gui *menu_background = &set.guiset[3];
struct gui *menu_selected_item_bar = &set.guiset[4];
struct gui *menu_selected_item_text = &set.guiset[5];
struct gui *gta_hp_bar = &set.guiset[6];
struct gui *gta_money_hud = &set.guiset[7];
extern int iClickWarpEnabled;
///////////////////////////////////////////////////////////////////////////////
// Common D3D functions.
///////////////////////////////////////////////////////////////////////////////
// Function taken from the MTA:SA source code (MTA10/core/CGraphics.cpp)
void CalcScreenCoors ( D3DXVECTOR3 *vecWorld, D3DXVECTOR3 *vecScreen )
{
traceLastFunc( "CalcScreenCoors()" );
/** C++-ifyed function 0x71DA00, formerly called by CHudSA::CalcScreenCoors **/
// Get the static view matrix as D3DXMATRIX
D3DXMATRIX m ( (float *)(0xB6FA2C) );
// Get the static virtual screen (x,y)-sizes
DWORD *dwLenX = ( DWORD * ) ( 0xC17044 );
DWORD *dwLenY = ( DWORD * ) ( 0xC17048 );
//DWORD *dwLenZ = (DWORD*)(0xC1704C);
//double aspectRatio = (*dwLenX) / (*dwLenY);
// Do a transformation
vecScreen->x = ( vecWorld->z * m._31 ) + ( vecWorld->y * m._21 ) + ( vecWorld->x * m._11 ) + m._41;
vecScreen->y = ( vecWorld->z * m._32 ) + ( vecWorld->y * m._22 ) + ( vecWorld->x * m._12 ) + m._42;
vecScreen->z = ( vecWorld->z * m._33 ) + ( vecWorld->y * m._23 ) + ( vecWorld->x * m._13 ) + m._43;
// Get the correct screen coordinates
double fRecip = (double)1.0 / vecScreen->z; //(vecScreen->z - (*dwLenZ));
vecScreen->x *= (float)( fRecip * (*dwLenX) );
vecScreen->y *= (float)( fRecip * (*dwLenY) );
}
void CalcWorldCoors ( D3DXVECTOR3 *vecScreen, D3DXVECTOR3 *vecWorld )
{
traceLastFunc( "CalcWorldCoors()" );
// Get the static view matrix as D3DXMATRIX
D3DXMATRIX m ( (float *)(0xB6FA2C) );
// Invert the view matrix
D3DXMATRIX minv;
memset ( &minv, 0, sizeof ( D3DXMATRIX ) );
m._44 = 1.0f;
D3DXMatrixInverse ( &minv, NULL, &m );
DWORD *dwLenX = ( DWORD * ) ( 0xC17044 );
DWORD *dwLenY = ( DWORD * ) ( 0xC17048 );
// Reverse screen coordinates
double fRecip = (double)1.0 / vecScreen->z;
vecScreen->x /= (float)(fRecip * (*dwLenX) );
vecScreen->y /= (float)(fRecip * (*dwLenY) );
// Do an (inverse) transformation
vecWorld->x = ( vecScreen->z * minv._31 ) + ( vecScreen->y * minv._21 ) + ( vecScreen->x * minv._11 ) + minv._41;
vecWorld->y = ( vecScreen->z * minv._32 ) + ( vecScreen->y * minv._22 ) + ( vecScreen->x * minv._12 ) + minv._42;
vecWorld->z = ( vecScreen->z * minv._33 ) + ( vecScreen->y * minv._23 ) + ( vecScreen->x * minv._13 ) + minv._43;
}
static WCHAR *ToWChar ( char *str )
{
traceLastFunc( "ToWChar()" );
static WCHAR buffer[1024];
_wcsset( buffer, 0 );
MultiByteToWideChar( CP_ACP, 0, str, strlen(str), buffer, 1024 );
return buffer;
}
// by s0beit, GHOSTER, Azorbix
HRESULT GenerateShader ( IDirect3DDevice9 *Device, IDirect3DPixelShader9 **pShader, float alpha, float red, float green,
float blue )
{
traceLastFunc( "GenerateShader()" );
char szShader[256];
ID3DXBuffer *pShaderBuffer = NULL;
sprintf_s( szShader, sizeof(szShader), "ps.1.1\ndef c0, %f, %f, %f, %f\nmov r0,c0", red, green, blue, alpha );
if ( FAILED(D3DXAssembleShader(szShader, sizeof(szShader), NULL, NULL, 0, &pShaderBuffer, NULL)) )
{
// Log( "Shader fail." ); - yeah it does sometimes
return E_FAIL;
}
if ( FAILED(Device->CreatePixelShader((const DWORD *)pShaderBuffer->GetBufferPointer(), pShader)) )
{
return E_FAIL;
}
return S_OK;
}
void LoadSpriteTexture ( void )
{
traceLastFunc( "LoadSpriteTexture()" );
char filename[MAX_PATH];
D3DLOCKED_RECT d3dlr;
FILE *fd = NULL;
int x, y;
uint8_t *surface;
SAFE_RELEASE( pSpriteTexture );
pSpriteTexture = NULL;
/* XXX use a different texture format */
if ( FAILED(origIDirect3DDevice9->CreateTexture(256, 256, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pSpriteTexture,
NULL)) )
{
Log( "Failed to create sprite texture!" );
goto out;
}
snprintf( filename, sizeof(filename), "%s\\" M0D_FOLDER "%s", g_szWorkingDirectory, RAW_TEX_FILE );
if ( (fd = fopen(filename, "rb")) == NULL )
{
Log( "Failed to open %s!", filename );
goto out;
}
if ( FAILED(pSpriteTexture->LockRect(0, &d3dlr, 0, 0)) )
{
Log( "Failed to lock texture!" );
goto out;
}
surface = (uint8_t *)d3dlr.pBits;
for ( y = 0; y < 120; y++ )
{
uint8_t data[240];
fread( data, 240, 1, fd );
for ( x = 0; x < 240; x++ )
{
uint8_t alpha = ( data[x] & 7 ) << 5;
uint8_t value = data[x] &~7;
surface[x * 4 + 0] = value;
surface[x * 4 + 1] = value;
surface[x * 4 + 2] = value;
surface[x * 4 + 3] = alpha;
}
surface += d3dlr.Pitch;
}
pSpriteTexture->UnlockRect( 0 );
fclose( fd );
//Log("Sprite texture loaded.");
return;
out: ;
SAFE_RELEASE( pSpriteTexture ) if ( fd != NULL )
fclose( fd );
return;
}
static void mmm_yummy_poop ( const void *info, int *enabled, int *prev_enabled, int *render, const char *teh_name )
{
traceLastFunc( "mmm_yummy_poop()" );
if ( info == NULL )
{
*prev_enabled = -1;
*render = 0;
}
else
{
if ( *prev_enabled == -1 )
{
*prev_enabled = *enabled;
*render = !*enabled;
}
if ( !*prev_enabled && *enabled && *render )
{
*enabled = 0;
*prev_enabled = 0;
*render = 0;
cheat_state_text( "Disabled %s", teh_name );
}
else if ( *prev_enabled && !*enabled )
{
cheat_state_text( "Switched to s0beit %s", teh_name );
*render = 1;
}
else if ( !*prev_enabled && *enabled )
{
cheat_state_text( "Switched to SA:MP %s", teh_name );
*render = 0;
}
*prev_enabled = *enabled;
}
}
void RenderDebug ( void )
{
traceLastFunc( "RenderDebug()" );
static const int ROW_HEIGHT = (int)ceilf( pD3DFontDebugWnd->DrawHeight() );
static const int CHAR_WIDTH = (int)ceilf( pD3DFontDebugWnd->DrawLength("W") );
static const int ROWS = DEBUG_DATA_SIZE / 16;
static const int data_size[4] = { 1, 2, 4, 4 };
struct debug_info *debug = &cheat_state->debug;
static char str_data[17], str[256];
int x, y, row, col, i;
int offset, offset16;
uint8_t *ptr, *data;
ptr = debug->ptr[debug->hist_pos] - DEBUG_DATA_SIZE;
offset = debug->offset[debug->hist_pos];
offset16 = (unsigned int)offset % 16;
ptr += offset - offset16 + DEBUG_DATA_SIZE / 2;
memset( debug->data, 0, DEBUG_DATA_SIZE );
memcpy_safe( debug->data, ptr, DEBUG_DATA_SIZE );
if ( !debug->data_prev_clear )
{
for ( i = 0; i < DEBUG_DATA_SIZE; i++ )
{
if ( debug->data[i] != debug->data_prev[i] )
debug->modify_time[i] = time_get();
}
}
else
{
memset( debug->modify_time, 0, sizeof(debug->modify_time) );
}
debug->data_prev_clear = 0;
x = 324;
y = 4;
/* blue box */
render->D3DBoxi( x - 2, y - 2, CHAR_WIDTH * 75 + 4, ROW_HEIGHT * 27 + 4, D3DCOLOR_ARGB(180, 0, 0, 150), NULL );
/* render selection */
for ( row = offset16; row < offset16 + data_size[debug->data_type]; row++ )
{
col = ( ROWS / 2 ) + row / 16;
render->D3DBoxi( x + CHAR_WIDTH * (10 + (row % 16) * 3), y + ROW_HEIGHT * col, CHAR_WIDTH * 3, ROW_HEIGHT,
D3DCOLOR_ARGB(127, 0, 255, 0), NULL );
render->D3DBoxi( x + CHAR_WIDTH * (59 + (row % 16)), y + ROW_HEIGHT * col, CHAR_WIDTH, ROW_HEIGHT,
D3DCOLOR_ARGB(127, 0, 255, 0), NULL );
}
/* render hex view */
for ( row = 0; row < ROWS; row++ )
{
int red_text = 0;
int len = 10;
int xpos = x;
snprintf( str, sizeof(str), "%p ", ptr + row * 16 );
for ( col = 0; col < 16; col++ )
{
uint32_t mod_time = debug->modify_time[row * 16 + col];
uint8_t ch = debug->data[row * 16 + col];
int color_switch = 0;
if ( mod_time != 0 && time_get() < mod_time + MSEC_TO_TIME(2000) )
color_switch = !red_text; /* switch color, unless red_text == 1 */
else if ( red_text )
color_switch = 1;
if ( color_switch )
{
pD3DFontDebugWnd->PrintShadow( (float)xpos, (float)y,
red_text ? D3DCOLOR_XRGB(255, 31, 31) : D3DCOLOR_XRGB(191, 191, 191), str );
xpos += CHAR_WIDTH * len;
str[0] = 0;
len = 0;
red_text ^= 1;
}
snprintf( str + len, sizeof(str) - len, "%02x ", debug->data[row * 16 + col] );
len += 3;
str_data[col] = (char)( (ch < 32) ? '.' : ch );
}
pD3DFontDebugWnd->PrintShadow( (float)xpos, (float)y, red_text ? D3DCOLOR_XRGB(255, 31, 31) : D3DCOLOR_XRGB(191, 191, 191),
str );
pD3DFontDebugWnd->PrintShadow( (float)x + CHAR_WIDTH * 59, (float)y, D3DCOLOR_XRGB(191, 191, 191), str_data );
y += ROW_HEIGHT;
}
/* everything else \o/ */
data = &debug->data[DEBUG_DATA_SIZE / 2 + offset16];
memcpy( debug->cursor_data, data, sizeof(debug->cursor_data) );
/* data type info */
snprintf( str, sizeof(str), "=>%c%02x(%-3d),%c%04x(%-5d),%c%08x(%d),%c%.4f, %s ptr", (debug->data_type == 0) ? '*' : ' ',
*(uint8_t *)data, *(uint8_t *)data, (debug->data_type == 1) ? '*' : ' ', *(uint16_t *)data,
*(uint16_t *)data, (debug->data_type == 2) ? '*' : ' ', *(uint32_t *)data, *(uint32_t *)data,
(debug->data_type == 3) ? '*' : ' ', *(float *)data, isBadPtr_readAny(*(void **)data, 1) ? "Bad" : "OK" );
pD3DFontDebugWnd->PrintShadow( (float)x, (float)y, D3DCOLOR_XRGB(191, 191, 191), str );
y += ROW_HEIGHT;
/* ptr info */
snprintf( str, sizeof(str), "Viewing: %s", debug_classify_pointer((void *)(debug->ptr[debug->hist_pos] + offset)) );
pD3DFontDebugWnd->PrintShadow( (float)x, (float)y, D3DCOLOR_XRGB(191, 191, 191), str );
y += ROW_HEIGHT;
snprintf( str, sizeof(str), "Pointer: %s", debug_classify_pointer(*(void **)data) );
pD3DFontDebugWnd->PrintShadow( (float)x, (float)y, D3DCOLOR_XRGB(191, 191, 191), str );
y += ROW_HEIGHT;
/* ptr stack info */
snprintf( debug->ptr_hist_str, sizeof(debug->ptr_hist_str), "Ptr stack (%d): %s", debug->hist_pos,
debug->hist_pos > 2 ? "... " : "" );
for ( i = debug->hist_pos - 2; i <= debug->hist_pos; i++ )
{
int len = (int)strlen( debug->ptr_hist_str );
if ( i < 0 )
continue;
snprintf( debug->ptr_hist_str + len, sizeof(debug->ptr_hist_str) - len, "%p+0x%x -> ", debug->ptr[i],
debug->offset[i] );
}
debug->ptr_hist_str[strlen( debug->ptr_hist_str ) - 4] = 0;
pD3DFontDebugWnd->PrintShadow( (float)x, (float)y, D3DCOLOR_XRGB(191, 191, 191), debug->ptr_hist_str );
y += ROW_HEIGHT * 2;
/* print help */
pD3DFontDebugWnd->PrintShadow( (float)x, (float)y, D3DCOLOR_XRGB(191, 191, 191),
"np4/6,8/2,9/3 = move np7 = return np1 = go to pointer" );
y += ROW_HEIGHT;
pD3DFontDebugWnd->PrintShadow( (float)x, (float)y, D3DCOLOR_XRGB(191, 191, 191),
"np/ = data type np-/+ = inc/dec np* = ptr stack to clipboard" );
memcpy( debug->data_prev, debug->data, DEBUG_DATA_SIZE );
}
void RenderMenu ( void )
{
traceLastFunc( "RenderMenu()" );
static const int ROW_HEIGHT = (int)ceilf( pD3DFont->DrawHeight() );
static const int MENU_HEIGHT = (int)ceilf( pD3DFont->DrawHeight() * (float)MENU_ROWS ) + 2;
char title[256] = NAME;
struct menu_item *item;
struct menu *menu;
int left, top;
float x, y;
int pos, top_pos, i;
float tdlen;
if ( menu_active == NULL )
return;
/* find root menu */
for ( menu = menu_active; menu->parent != NULL; menu = menu->parent );
while ( menu != NULL )
{
if ( menu->pos < 0 || menu->pos >= menu->count )
break;
item = &menu->item[menu->pos];
if ( item->submenu == NULL || menu == menu_active )
break;
snprintf( title + strlen(title), sizeof(title) - strlen(title), " > %s", item->name );
menu = item->submenu;
}
/* draw titlebar */
left = pPresentParam.BackBufferWidth / 2 - MENU_WIDTH / 2;
top = pPresentParam.BackBufferHeight - MENU_HEIGHT - ROW_HEIGHT - 2 - 20 - 2;
tdlen = pD3DFont->DrawLength(title);
tdlen -= MENU_WIDTH;
if (tdlen < 0.0f)
tdlen = 0.0f;
int cp = pD3DFont->GetCharPos(title, tdlen); // child p... char pos
if (cp > 0) ++cp;
render->D3DBoxBorderi( left, top, MENU_WIDTH, ROW_HEIGHT + 2,
D3DCOLOR_ARGB(223, 91, 91, 91), D3DCOLOR_ARGB(menu_titlebar_background->alpha,
menu_titlebar_background->red, menu_titlebar_background->green,
menu_titlebar_background->blue) );
pD3DFont->PrintShadow( (float)(left + 1), (float)(top + 1), D3DCOLOR_XRGB(223, 223, 223), &title[cp] );
/* draw window */
left = pPresentParam.BackBufferWidth / 2 - MENU_WIDTH / 2;
top = pPresentParam.BackBufferHeight - MENU_HEIGHT - 1 - 20;
render->D3DBoxBorderi( left, top, MENU_WIDTH, MENU_HEIGHT, D3DCOLOR_ARGB(223, 63, 63, 63),
D3DCOLOR_ARGB(menu_background->alpha, menu_background->red, menu_background->green, menu_background->blue) );
/* calculate positions */
pos = menu_active->pos;
top_pos = menu_active->top_pos;
if ( pos - MENU_ROWS >= top_pos )
top_pos = pos - MENU_ROWS + 1;
if ( pos < top_pos )
top_pos = pos;
if ( top_pos < 0 )
top_pos = 0;
else if ( top_pos >= menu_active->count )
top_pos = menu_active->count - 1;
menu_active->top_pos = top_pos;
/* draw menu items */
y = (float)top;
x = (float)( left + 2 );
for ( i = top_pos; i < top_pos + MENU_ROWS; i++, y += pD3DFont->DrawHeight() )
{
int enabled;
if ( i < 0 || i >= menu_active->count )
continue;
item = &menu_active->item[i];
enabled = menu_active->callback( MENU_OP_ENABLED, item );
if ( i == pos )
{
render->D3DBoxi( left + 1, (int)floorf(y) + 1, MENU_WIDTH - 1, ROW_HEIGHT + 1, D3DCOLOR_ARGB(
menu_selected_item_bar->alpha, menu_selected_item_bar->red,
menu_selected_item_bar->green, menu_selected_item_bar->blue), NULL );
}
if ( i == menu_mouseover )
{
render->D3DBoxi( left + 1, (int)floorf(y) + 1, MENU_WIDTH - 1, ROW_HEIGHT + 1, D3DCOLOR_ARGB(
menu_selected_item_bar->alpha / 2, menu_selected_item_bar->red,
menu_selected_item_bar->green, menu_selected_item_bar->blue), NULL );
}
if ( item->name[0] == '\t' )
{
pD3DFont->PrintShadow( x, y, item->color, item->name + 1 );
render->D3DBoxi( left + 2, (int)floorf(y) + ROW_HEIGHT - 1, (int)ceilf(pD3DFont->DrawLength(item->name + 1)),
1, D3DCOLOR_ARGB(191, 127, 127, 127), NULL );
}
else
{
/* XXX ... */
pD3DFont->PrintShadow( x, y, enabled ? D3DCOLOR_XRGB(menu_selected_item_text->red,
menu_selected_item_text->green, menu_selected_item_text->blue) : item->color,
item->name );
}
if ( item->submenu != NULL )
{
pD3DFont->PrintShadow( x + (float)MENU_WIDTH - pD3DFont->DrawLength(">") - 4, y,
D3DCOLOR_ARGB(191, 127, 127, 127), ">" );
}
}
}
void RenderMapDot ( const float self_pos[3], const float pos[16], DWORD color, const char *name )
{
traceLastFunc( "RenderMapDot()" );
static int init;
float vect[3], rvect[2];
float a, x, y;
vect3_vect3_sub( pos, self_pos, vect );
if ( vect3_length(vect) > 1000.0f )
return;
color = ( color & 0x00FFFFFF ) | 0xDF000000;
a = -atan2f( cam_matrix[4 * 0 + 0], cam_matrix[4 * 0 + 1] ) - M_PI / 2.0f;
rvect[0] = vect[0] * cosf( a ) - -vect[1] * sinf( a );
rvect[1] = vect[0] * sinf( a ) + -vect[1] * cosf( a );
rvect[1] /= pPresentParam.BackBufferWidth / pPresentParam.BackBufferHeight;
x = (float)pPresentParam.BackBufferWidth / 2 + roundf( rvect[0] );
y = (float)pPresentParam.BackBufferHeight / 2 + roundf( rvect[1] );
if (x < 0.0f || x > pPresentParam.BackBufferWidth || y < 0.0f || y > pPresentParam.BackBufferHeight)
return;
if (set.map_draw_lines && vect3_length(vect) > 5.0f)
render->D3DLine(x, y, pPresentParam.BackBufferWidth / 2, pPresentParam.BackBufferHeight / 2, color);
/* the "^ v o" icons are 9x9 large, and located at 168x98 in the texture */
if ( pSpriteTexture != NULL )
{
float u, v, ts;
if ( name != NULL )
pD3DFontFixed->PrintShadow( floor(x - pD3DFontFixed->DrawLength(name) / 2.0f), floor(y - 14.0f), color, name );
u = 168.0f;
v = 98.0f;
if ( vect[2] < -4.0f )
u += 9.0f;
else if ( vect[2] <= 4.0f )
u += 18.0f;
u /= 256.0f;
v /= 256.0f;
ts = 9.0f / 256.0f;
render->D3DBindTexture( pSpriteTexture );
render->D3DTexQuad( x - 4.5f, y - 4.5f, x + 4.5f, y + 4.5f, u, v, u + ts, v + ts );
render->D3DBindTexture( NULL );
}
else
{
if ( name != NULL )
pD3DFont->PrintShadow( floor(x - pD3DFontFixed->DrawLength(name) / 2.0f), floor(y - 14.0f), color, name );
if ( vect[2] < -4.0f )
{
pD3DFont->PrintShadow( floor(x - 4.5f), floor(y - 4.5f), color, "v" );
return;
}
else if ( vect[2] <= 4.0f )
{
pD3DFont->PrintShadow( floor(x - 4.5f), floor(y - 4.5f), color, "o" );
return;
}
else if ( vect[2] > 4.0f )
{
pD3DFont->PrintShadow( floor(x - 4.5f), floor(y - 4.5f), color, "^" );
return;
}
}
}
void RenderMap ( void )
{
traceLastFunc( "renderMap()" );
// don't run in the menu
if ( gta_menu_active() )
return;
if ( g_SAMP != NULL )
{
// showing scorelist?
if ( (GetAsyncKeyState(VK_TAB) < 0 && set.d3dtext_score)
|| g_Scoreboard->iIsEnabled )
return;
if ( GetAsyncKeyState(VK_F1) < 0 )
return;
if ( GetAsyncKeyState(VK_F5) < 0 )
return;
if ( GetAsyncKeyState(VK_F10) < 0 )
return;
}
struct actor_info *self = actor_info_get( ACTOR_SELF, ACTOR_ALIVE );
if ( self == NULL )
return;
const struct vehicle_entry *vehicle;
float pos[3];
char buf[256];
int i;
if ( pool_actor != NULL )
{
if ( g_SAMP != NULL )
{
for ( i = 0; i < SAMP_MAX_PLAYERS; i++ )
{
if ( !getPlayerPos(i, pos) )
continue;
if ( g_Players->pRemotePlayer[i] == NULL )
continue;
_snprintf_s( buf, sizeof(buf)-1, "%s(%d)", getPlayerName(i), i );
RenderMapDot( &self->base.matrix[4 * 3], pos, samp_color_get(i), buf );
}
}
else
{
CPoolsSA::pedPool_t::mapType::iterator it = ((CPoolsSA *)pGameInterface->GetPools())->m_pedPool.map.begin();
for (; it.pos < it.end; it++)
{
CPedSA *ped = it.pos->second;
if (ped == nullptr)
continue;
if (ped == pPedSelf)
continue;
_snprintf_s(buf, sizeof(buf)-1, "%d", ped->GetArrayID());
RenderMapDot(&self->base.matrix[4 * 3], &ped->GetPosition()->fX, D3DCOLOR_XRGB(255, 255, 255), buf);
}
}
}
if ( cheat_state->_generic.map_vehicles )
{
if ( g_SAMP != NULL )
{
if ( g_Vehicles != NULL )
{
for ( i = 0; i < SAMP_MAX_VEHICLES; i++ )
{
if ( g_Vehicles->iIsListed[i] != 1 )
continue;
if ( g_Vehicles->pSAMP_Vehicle[i] == NULL )
continue;
if ( g_Vehicles->pSAMP_Vehicle[i]->pGTA_Vehicle != NULL )
{
vehicle = gta_vehicle_get_by_id( g_Vehicles->pSAMP_Vehicle[i]->pGTA_Vehicle->base.model_alt_id );
if ( g_Players->pLocalPlayer->sCurrentVehicleID == i )
continue;
RwColor color = getVehicleColorRGB(vehicle_getColor0(g_Vehicles->pSAMP_Vehicle[i]->pGTA_Vehicle));
_snprintf_s( buf, sizeof(buf)-1, "%s(%d)", vehicle->name, i );
RenderMapDot( &self->base.matrix[4 * 3],
&g_Vehicles->pSAMP_Vehicle[i]->pGTA_Vehicle->base.matrix[4 * 3],
D3DCOLOR_XRGB(color.r, color.g, color.b), buf );
}
}
}
}
else
{
for ( i = 0; i < pool_vehicle->size; i++ )
{
struct vehicle_info *vehs = vehicle_info_get( i, VEHICLE_ALIVE );
if ( vehs == NULL )
continue;
RwColor color = getVehicleColorRGB(vehicle_getColor0(vehs));
vehicle = gta_vehicle_get_by_id( vehs->base.model_alt_id );
_snprintf_s( buf, sizeof(buf)-1, "%s (%d)", vehicle->name, i );
RenderMapDot( &self->base.matrix[4 * 3], &vehs->base.matrix[4 * 3], D3DCOLOR_XRGB(color.r, color.g, color.b), buf );
}
}
}
if ( cheat_state->_generic.teletext )
{
for ( i = 0; i < TELEPORT_MAX; i++ )
{
vect3_copy( &cheat_state->teleport[i].matrix[4 * 3], pos );
if ( vect3_near_zero(pos) )
continue;
_snprintf_s( buf, sizeof(buf)-1, "Teleport %d (%0.1f)", i, vect3_dist(&self->base.matrix[4 * 3], pos) );
RenderMapDot( &self->base.matrix[4 * 3], pos, D3DCOLOR_XRGB(0, 200, 200), buf );
}
}
// self
RenderMapDot( &self->base.matrix[4 * 3], &self->base.matrix[4 * 3], D3DCOLOR_XRGB(255, 255, 255), NULL );
}
void RenderPedHPBar ( void )
{
traceLastFunc( "RenderPedHPBar()" );
if ( !set.left_bottom_bars_enable )
return;
struct actor_info *info = actor_info_get( ACTOR_SELF, 0 );
char text[32];
int bottom, fontHeight;
if ( info == NULL )
return;
bottom = pPresentParam.BackBufferHeight;
fontHeight = (int)pD3DFontFixed->DrawHeight() - 1;
render->D3DBoxi( 0, bottom - fontHeight, 101, fontHeight, D3DCOLOR_ARGB(127, 0, 0, 0), NULL );
render->D3DBoxi( 0, bottom - fontHeight + 1, (int)info->hitpoints, fontHeight - 2, D3DCOLOR_ARGB(127, 191, 0, 0), 100 );
_snprintf_s( text, sizeof(text)-1, "Health: %d", (int)info->hitpoints );
pD3DFontFixed->PrintShadow( (float)(2), (float)(bottom - fontHeight), D3DCOLOR_XRGB(255, 255, 255), text );
render->D3DBoxi( 0, bottom - 20, 101, 10, D3DCOLOR_ARGB(127, 0, 0, 0), NULL );
if ( info->armor == NULL )
{
pD3DFontFixed->PrintShadow( (float)(2), (float)(bottom - (fontHeight*2)), D3DCOLOR_XRGB(255, 255, 255), "No armor" );
}
else
{
render->D3DBoxi( 0, bottom - (fontHeight*2) + 1, (int)info->armor, fontHeight - 2, D3DCOLOR_ARGB(127, 255, 255, 255), 100 );
_snprintf_s( text, sizeof(text)-1, "Armor: %d", (int)info->armor );
pD3DFontFixed->PrintShadow( (float)(2), (float)(bottom - (fontHeight*2)), D3DCOLOR_XRGB(255, 255, 255), text );
}
}
void RenderVehicleHPBar ( void )
{
traceLastFunc( "RenderVehicleHPBar()" );
if ( !set.left_bottom_bars_enable )
return;
struct actor_info *pinfo = actor_info_get( ACTOR_SELF, 0 );
struct vehicle_info *vinfo = vehicle_info_get( VEHICLE_SELF, 0 );
char text[32];
int hp, bottom, barHeight, fontHeight;
float speed;
if ( vinfo == NULL )
return;
if ( pinfo == NULL )
return;
bottom = pPresentParam.BackBufferHeight;
barHeight = (int)pD3DFont->DrawHeight() - 5;
fontHeight = (int)pD3DFontFixed->DrawHeight() - 2;
if ( vinfo->hitpoints > 1000.0f )
hp = 100;
else
hp = (int)( vinfo->hitpoints / 10.0f );
render->D3DBoxi( 0, bottom - fontHeight, 101, fontHeight + 2, D3DCOLOR_ARGB(127, 0, 0, 0), NULL );
render->D3DBoxi( 0, bottom - fontHeight + 1, hp, fontHeight, D3DCOLOR_ARGB(127, 191, 0, 0), 1000 );
_snprintf_s( text, sizeof(text)-1, "VHealth: %d", hp );
pD3DFontFixed->PrintShadow( (float)(2), (float)(bottom - fontHeight - 1), D3DCOLOR_XRGB(255, 255, 255), text );
if ( !set.speedometer_old_enable )
{
render->D3DBoxi( 0, bottom - (fontHeight*2), 101, fontHeight + 2, D3DCOLOR_ARGB(127, 0, 0, 0), NULL );
render->D3DBoxi( 0, bottom - (fontHeight*2) + 1, (int)pinfo->hitpoints, fontHeight, D3DCOLOR_ARGB(127, 191, 0, 0), 100 );
if ( pinfo->armor != NULL )
render->D3DBoxi( 0, bottom - (fontHeight*2), (int)pinfo->armor, 8, D3DCOLOR_ARGB(127, 255, 255, 255), 100 );
_snprintf_s( text, sizeof(text)-1, "PHealth: %d", (int)pinfo->hitpoints );
pD3DFontFixed->PrintShadow( (float)(2), (float)(bottom - (fontHeight*2) - 1), D3DCOLOR_XRGB(255, 255, 255), text );
}
else if ( !cheat_state->vehicle.air_brake )
{
float spood = vect3_length( vinfo->speed );
render->D3DBoxi( 0, bottom - barHeight - fontHeight, 101, 10, D3DCOLOR_ARGB(127, 0, 0, 0), NULL );
render->D3DBoxi( 0, bottom - barHeight - fontHeight + 1, (int)(spood * 64), 8, D3DCOLOR_ARGB(127, 191, 191, 0), 100 );
_snprintf_s( text, sizeof(text)-1, "%0.2f km/h", (float)(spood * 170) );
pD3DFontFixed->PrintShadow( (float)(2), (float)(bottom - (fontHeight*2) - 1), D3DCOLOR_XRGB(255, 255, 255), text );
}
// acceleration/distance speed
static float speed_last;
static float speed_lastVect[3];
static float speed_nowVect[3];
static float speed_dist;
static float speed_secondsLastCheck = 0.0f;
static float speed_now;
static float speed_acceleration;
// update our data about position, speed, acceleration
if ( (TIME_TO_DOUBLE(time_get()) - speed_secondsLastCheck) > 0.10f )
{
////////////////////
// distance speed //
////////////////////
vect3_copy( speed_nowVect, speed_lastVect );
vect3_copy( &vinfo->base.matrix[4 * 3], speed_nowVect );
speed_dist = vect3_dist( speed_lastVect, speed_nowVect ) / ( TIME_TO_DOUBLE(time_get()) - (float)speed_secondsLastCheck );
//////////
// m/ss //
//////////
speed_last = speed_now;
speed_now = ( vect3_length(vinfo->speed) * 170.0f ) / 3.6f;
speed_acceleration = ( speed_now - speed_last ) / ( TIME_TO_DOUBLE(time_get()) - speed_secondsLastCheck );
speed_secondsLastCheck = TIME_TO_DOUBLE( time_get() );
}
// distance speed while air braking
if ( cheat_state->vehicle.air_brake )
{
// speedometer - analog (needle)
speed = speed_dist * ( 3.43f / 170.0f );
// speedometer - digital (numbers above health)
if ( set.speedometer_old_enable )
{
render->D3DBoxi( 0, bottom - barHeight - fontHeight, 101, 10, D3DCOLOR_ARGB(127, 0, 0, 0), NULL );
render->D3DBoxi( 0, bottom - barHeight - fontHeight + 1, (int)(speed_dist * 1.3f), 8, D3DCOLOR_ARGB(127, 191, 191, 0), 100 );
_snprintf_s( text, sizeof(text)-1, "%0.2f km/h", (float)(speed_dist * 3.43f) );
pD3DFontFixed->PrintShadow( (float)(2), (float)(bottom - (fontHeight*2) - 1), D3DCOLOR_XRGB(255, 255, 255), text );
}
}
else
{
// air brake deactivated - set the speedometer speed to real speed
speed = vect3_length( vinfo->speed );
}
if ( set.speedometer_enable )
{
if ( speed > 260.0f )
speed = 260.0f;
static float mult = set.speedometer_multiplier;
float rotationNeedle = 0.0f;
D3DXMATRIX mat;
rotationNeedle = DEGTORAD( (90.0f / 100.0f) * ((speed * mult) * 1.55f) );
rotationNeedle /= 2;
if ( rotationNeedle > 3.29f )
rotationNeedle = 3.29f;
D3DXVECTOR2 axisSpeedo = D3DXVECTOR2( speedoPos.x, speedoPos.y );
D3DXVECTOR2 axisNeedle = D3DXVECTOR2( (130.00f * needlePos.x), (152.00f * needlePos.y) );
if ( !gta_menu_active() && !KEY_DOWN(VK_TAB) )
{
if ( (sSpeedoPNG) && (tSpeedoPNG) && (sNeedlePNG) && (tNeedlePNG) )
{
D3DXMatrixTransformation2D( &mat, NULL, 0.0f, &needlePos, &axisNeedle, 0.0f, &axisSpeedo );
sSpeedoPNG->Begin( D3DXSPRITE_ALPHABLEND );
sSpeedoPNG->SetTransform( &mat );
sSpeedoPNG->Draw( tSpeedoPNG, NULL, NULL, NULL, 0xCCFFFFFF );
sSpeedoPNG->End();
D3DXMatrixTransformation2D( &mat, NULL, 0.0f, &needlePos, &axisNeedle, rotationNeedle, &axisSpeedo );
sNeedlePNG->Begin( D3DXSPRITE_ALPHABLEND );
sNeedlePNG->SetTransform( &mat );
sNeedlePNG->Draw( tNeedlePNG, NULL, NULL, NULL, 0xCCFFFFFF );
sNeedlePNG->End();
}
}
}
// acceleration meter
render->D3DBoxi( 0, bottom - 30, 101, 10, D3DCOLOR_ARGB(127, 0, 0, 0), NULL );
if ( speed_acceleration <= -0.01f )
render->D3DBoxi( 0, bottom - barHeight - 19, (int)(speed_acceleration * -4.8f), 8, D3DCOLOR_ARGB(127, 191, 191, 0), 100 );
else
render->D3DBoxi( 0, bottom - barHeight - 19, (int)(speed_acceleration * 4.8f), 8, D3DCOLOR_ARGB(127, 191, 191, 0), 100 );
_snprintf_s( text, sizeof(text)-1, "%0.2f m/ss", (float)(speed_acceleration) );
pD3DFontFixed->PrintShadow( (float)(2), (float)(bottom - barHeight - 21), D3DCOLOR_XRGB(255, 255, 255), text );
}
// for renderPlayerTags()
struct playerTagInfo
{
#pragma pack( 1 )
CVector tagPosition;
float tagOffsetY;
bool isStairStacked;
float stairStackedOffset;
bool isPastMaxDistance;
} g_playerTagInfo[SAMP_MAX_PLAYERS];
// new "Air Ride" player ESP by nuckfuts
// this is optimized to all hell, so please don't
// mess with it unless you completely understand it
void renderPlayerTags ( void )
{
traceLastFunc( "renderPlayerTags()" );
// don't run in the menu
if ( gta_menu_active() )
return;
// Exit this function and enable samp nametags, if panic key
if ( cheat_state->_generic.cheat_panic_enabled || !cheat_state->render_player_tags )
{
if ( g_dwSAMP_Addr && g_SAMP )
{
sampPatchDisableNameTags( 0 );
}
return;
}
// don't run during certain samp events
if ( g_dwSAMP_Addr && g_SAMP )
{
if (
// Scoreboard open?
( GetAsyncKeyState(VK_TAB) < 0 && set.d3dtext_score )
|| g_Scoreboard->iIsEnabled
// F10 key down?
|| GetAsyncKeyState(VK_F10) < 0
)
{
return;
}
// Disable samp Nametags
sampPatchDisableNameTags( 1 );
}
// don't run if the CGameSA doesn't exist
if ( !pGameInterface )
return;
// don't run if we don't exist
if (isBadPtr_GTA_pPed(pPedSelf))
return;
// for tracking player states as we iterate through
bool isPedESPCollided[SAMP_MAX_PLAYERS];
bool isPedESPStairStacked[SAMP_MAX_PLAYERS];
memset( isPedESPCollided, false, sizeof(bool) * SAMP_MAX_PLAYERS );
memset( isPedESPStairStacked, true, sizeof(bool) * SAMP_MAX_PLAYERS );