-
Notifications
You must be signed in to change notification settings - Fork 2
/
mradar_main_client.lua
1357 lines (1041 loc) · 39.8 KB
/
mradar_main_client.lua
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
local camera = getCamera()
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
local SCREEN_WIDTH, SCREEN_HEIGHT = guiGetScreenSize()
local TEXTURE_QUALITY_FORMAT = "dxt3"
local TEXTURE_FILE_FORMAT = ".png"
local TEXTURE_MIPMAPS = false
local TEXTURE_EDGE = "clamp"
local TEXTURE_PATH = "txd/"
local FONT_PATH = "font/"
local FONT_QUALITY = "antialiased"
local MAP_WORLD_SIZE = 6000
local MAP_WORLD_SIZE_HALF = MAP_WORLD_SIZE / 2
local MAP_TILES_SIZE = 12;
local MAP_TILES_SIZE_HALF = MAP_TILES_SIZE / 2
local MAP_TILE_WORLD_SIZE = MAP_WORLD_SIZE / MAP_TILES_SIZE
local MAP_TILE_COLOR = tocolor(255, 255, 255, 255)
local MAP_TILE_INTERIOR_COLOR = tocolor(0, 0, 0, 0)
local MAP_TILE_TEXTURES_PATH = TEXTURE_PATH .. "radar/"
-- Here are GTA:IV sizes
local RADAR_SIZE = (math.min(SCREEN_WIDTH, SCREEN_HEIGHT)) / 5 -- WideScreenFix: 0.1875
local RADAR_SIZE_HALF = RADAR_SIZE / 2
local RADAR_BOTTOM_OFFSET = RADAR_SIZE / 4
local RADAR_LEFT_OFFSET = RADAR_BOTTOM_OFFSET * (11 / 6)
local RADAR_SCREEN_X = RADAR_LEFT_OFFSET
local RADAR_SCREEN_Y = SCREEN_HEIGHT - RADAR_BOTTOM_OFFSET - RADAR_SIZE
-- TODO: drawing circle on RT instead of using texture? (bugged dxDrawCircle)
local RADAR_BORDER_WIDTH = RADAR_SIZE_HALF / 8 -- depends on radar disc texture
local RADAR_BORDER_MARGIN = RADAR_BORDER_WIDTH / 8 -- depends on radar disc texture
local RADAR_BORDER_COLOR = tocolor(0, 0, 0, 255)
local RADAR_SPRITE_TEXTURES_PATH = TEXTURE_PATH .. "hud/"
local RADAR_MAP_MASK_RADIUS = RADAR_SIZE_HALF - RADAR_BORDER_WIDTH + (RADAR_BORDER_MARGIN * 2)
local RADAR_MAP_DRAW_TILES_RADIUS = 1
local RADAR_MAP_MIN_RANGE = 180.0 -- Radar.cpp: RADAR_MIN_RANGE
local RADAR_MAP_MAX_RANGE = 350.0 -- Radar.cpp: RADAR_MAX_RANGE
local RADAR_MAP_MIN_RANGE_SPEED = 0.3 -- Radar.cpp: RADAR_MIN_SPEED
local RADAR_MAP_MAX_RANGE_SPEED = 0.9 -- Radar.cpp: RADAR_MAX_SPEED
local RADAR_MAP_SHOW_IN_INTERIOR = false
local RING_PLANE_SPRITE_COLOR = tocolor(255, 255, 255, 255)
local ARTIFICIAL_HORIZON_SKY_COLOR = tocolor(0, 0, 0, 0)
local ARTIFICIAL_HORIZON_GROUND_COLOR = tocolor(20, 175, 20, 200)
local ALTIMETER_BG_COLOR = tocolor(10, 10, 10, 100)
local ALTIMETER_BG_WIDTH = RADAR_SIZE / 16
local ALTIMETER_BG_HEIGHT = RADAR_SIZE - (RADAR_BORDER_WIDTH * 2)
local ALTIMETER_BG_SCREEN_X = RADAR_SCREEN_X + RADAR_SIZE + (ALTIMETER_BG_WIDTH * 2)
local ALTIMETER_BG_SCREEN_Y = RADAR_SCREEN_Y + (RADAR_SIZE / 2) - (ALTIMETER_BG_HEIGHT / 2)
local ALTIMETER_COLOR = tocolor(200, 200, 200, 255)
local ALTIMETER_WIDTH = ALTIMETER_BG_WIDTH * 2
local ALTIMETER_HEIGHT = ALTIMETER_WIDTH / 16
local ALTIMETER_SCREEN_X = ALTIMETER_BG_SCREEN_X + (ALTIMETER_BG_WIDTH / 2) - (ALTIMETER_WIDTH / 2)
local ALTIMETER_WORLD_HEIGHT_MAX = 950
local ALTIMETER_WORLD_HEIGHT_LOW = 200
local RADAR_BLIP_SIZE = RADAR_SIZE * 0.15
local RADAR_BLIP_SIZE_GTASA_DEFAULT = 2
local RADAR_BLIP_ALPHA_MULTIPLIER = 1
local RADAR_BLIP_VECTOR_MAX_LENGTH = RADAR_SIZE_HALF - (RADAR_BORDER_WIDTH / 2)
local RADAR_BLIP_TRACE_TEXTURES_PATH = TEXTURE_PATH .. "trace/"
local RADAR_BLIP_CENTRE_SIZE_MULTIPLIER = 0.9
local RADAR_BLIP_TRACE_SIZE_MULTIPLIER = 0.5
local RADAR_BLIP_TRACE_LOW_HEIGHT_DIFF = -4.0
local RADAR_BLIP_TRACE_HIGH_HEIGHT_DIFF = 2
-- F11 map
local BIGMAP_CURSOR_ENABLED = true
local BIGMAP_HIDE_CHAT = true
local BIGMAP_SIZE = math.max(SCREEN_WIDTH, SCREEN_HEIGHT)
local BIGMAP_ZOOM_SCALE_MAX = 4
local BIGMAP_ZOOM_SCALE_MIN = 0.9
local BIGMAP_ZOOM_SCALE_STEP = 0.05
local BIGMAP_ZOOM_SCALE_DEFAULT = 1
local BIGMAP_CHANGE_OPACITY_STEP = 0.05
local BIGMAP_OPACITY_DEFAULT = 0.8
local BIGMAP_MOVE_STEP = math.min(SCREEN_WIDTH, SCREEN_HEIGHT) / 20
local BIGMAP_BLIP_HERE_SIZE = 6
local BIGMAP_TEXT_WINDOW_BG_COLOR = tocolor(0, 0, 0, 190)
local BIGMAP_TEXT_WINDOW_CONTENT_MARGIN = 10
local BIGMAP_HELP_TEXT_COLOR = tocolor(241, 241, 241, 255)
local BIGMAP_HELP_TEXT_FONT = dxCreateFont(FONT_PATH .. "sabankgothic.ttf", 14, false, FONT_QUALITY)
local BIGMAP_LEGEND_ENABLED = true
local BIGMAP_LEGEND_COLUMNS = 3
local BIGMAP_LEGEND_TEXT_COLOR = tocolor(172, 203, 241, 255)
local BIGMAP_LEGEND_TEXT_FONT = dxCreateFont(FONT_PATH .. "sabankgothic.ttf", 16, false, FONT_QUALITY)
local BIGMAP_SWITCH_COMMAND = "radar"
local BIGMAP_ZOOM_IN_COMMAND = "radar_zoom_in"
local BIGMAP_ZOOM_OUT_COMMAND = "radar_zoom_out"
local BIGMAP_OPACITY_UP_COMMAND = "radar_opacity_up"
local BIGMAP_OPACITY_DOWN_COMMAND = "radar_opacity_down"
local BIGMAP_MOVE_NORTH_COMMAND = "radar_move_north"
local BIGMAP_MOVE_SOUTH_COMMAND = "radar_move_south"
local BIGMAP_MOVE_EAST_COMMAND = "radar_move_east"
local BIGMAP_MOVE_WEST_COMMAND = "radar_move_west"
local BIGMAP_SWITCH_HELP_COMMAND = "radar_help"
local BIGMAP_SWITCH_LEGEND_KEY = "l"
local BIGMAP_MOVE_MOUSE_KEY = "mouse1"
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
local drawData = {}
drawData.mapTileTextures = {} -- Radar.cpp: std::array<std::array<int32, MAX_RADAR_WIDTH_TILES>, MAX_RADAR_HEIGHT_TILES>& gRadarTextures
drawData.hudSpriteTextures = {} -- Hud.h: CSprite2d (&Sprites)[6]
drawData.radarSpriteTextures = {} -- Radar.h: std::array<CSprite2d, MAX_RADAR_SPRITES>& RadarBlipSprites
drawData.radarSpriteBlipTraceTextures = {} -- custom textures (instead of drawing polygons)
drawData.radarMaskTexture = nil
drawData.areRenderTargetsReady = false
drawData.radarMaskShader = dxCreateShader("radar.fx")
drawData.radarMapMaskRt = dxCreateRenderTarget(RADAR_SIZE, RADAR_SIZE, true)
drawData.radarBorderRt = dxCreateRenderTarget(RADAR_SIZE, RADAR_SIZE, true)
drawData.radarMapTilesRt = dxCreateRenderTarget(RADAR_SIZE, RADAR_SIZE, true)
drawData.radarOverlayRt = dxCreateRenderTarget(RADAR_SIZE, RADAR_SIZE, true)
drawData.cursorPrevPos = { 0, 0 }
drawData.cursorCurrPos = { 0, 0 }
drawData.cursorOnGui = false
drawData.playerElement = nil
drawData.playerElementMatrix = nil -- Radar.h: CVector2D& vec2DRadarOrigin
drawData.playerCameraAngle = 0 -- Radar.h: float& m_fRadarOrientation
drawData.playerInterior = nil
drawData.playerDimension = nil
drawData.flashingRadarAreaAlphaMultiplier = 0
drawData.showRadar = true
drawData.radarMapRtView = nil
drawData.radarMapRtRotView = nil -- Radar.h: float& cachedCos; float& cachedSin
drawData.showBigMap = false
drawData.showBigMapHelp = true
drawData.showBigMapLegend = false
drawData.bigMapAlphaMultiplier = BIGMAP_OPACITY_DEFAULT
drawData.bigMapDrawnSprites = {}
drawData.bigMapScreenViewTransform = transform2.scale(BIGMAP_ZOOM_SCALE_DEFAULT, BIGMAP_ZOOM_SCALE_DEFAULT)
drawData.bigMapScreenViewResult = transform2.move(0, 0)
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
local function math_clamp(value, min, max)
return value < min and min or value > max and max or value
end
local function fromcolor(color)
return
bitExtract(color, 16, 8),
bitExtract(color, 8, 8),
bitExtract(color, 0, 8),
bitExtract(color, 24, 8)
end
-- same as matrix multiplication but ignoring result rotation
local function getPositionFromMatrixOffset2D(m, x, y)
local m1 = m[1]
local m2 = m[2]
local m3 = m[3]
return
x * m1[1] + y * m2[1] + m3[1],
x * m1[2] + y * m2[2] + m3[2]
end
local function getDistanceBetweenPoints3D(x1, y1, z1, x2, y2, z2)
local dx = x2 - x1
local dy = y2 - y1
local dz = z2 - z1
return math.sqrt(dx * dx + dy * dy + dz * dz)
end
local function getDistanceBetweenPoints2D(x1, y1, x2, y2)
local dx = x2 - x1
local dy = y2 - y1
return math.sqrt(dx * dx + dy * dy)
end
local function getCursorAbsolutePosition()
local cx, cy = getCursorPosition()
return cx and (SCREEN_WIDTH * cx), cy and (SCREEN_HEIGHT * cy)
end
local function getVehicleRealType(vehicle)
-- defines "Vortex" model as custom "Hovercraft" type (instead of "Plane" type)
if getElementModel(vehicle) == 539 then
return VEHICLE_REAL_TYPE.HOVERCRAFT
end
return getVehicleType(vehicle)
end
local function getBlipsByInteriorDimensionOrdered(int, dim)
local orderings = {}
local blips = {}
local number = 0
for _, blip in ipairs(getElementsByType("blip")) do
if getElementInterior(blip) == int and getElementDimension(blip) == dim then
number = number + 1
blips[number] = blip
orderings[blip] = getBlipOrdering(blip)
end
end
if number <= 1 then return blips end
table.sort(blips, function(a, b) return orderings[a] < orderings[b] end)
return blips
end
function dxDrawTextWithShadow(text, x, y, rightX, bottomY, color, scaleXY, scaleY, font, ...)
x = math.floor(x)
y = math.floor(y)
local off = math.floor(dxGetFontHeight(scaleY or scaleXY, font) / 1.75 / 6)
dxDrawText(text, x + off, y + off, rightX, bottomY, tocolor(0, 0, 0, 255), scaleXY, scaleY, font, ...)
dxDrawText(text, x, y, rightX, bottomY, color, scaleXY, scaleY, font, ...)
end
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
-- CRadar::TransformRadarPointToScreenSpace(CVector2D& out, const CVector2D& in) // 0x583480
local function transformWorldToRadarMapRtView(x, y)
return getPositionFromMatrixOffset2D(drawData.radarMapRtView, x, y)
end
-- Radar.cpp: CRadar::LoadTextures() // 0x5827D0
-- Hud.cpp: CHud::Initialise() // 0x5BA850
local function loadTextures()
for id, name in pairs(RADAR_SPRITE_TEXTURE_NAMES) do
drawData.radarSpriteTextures[id] = dxCreateTexture(
RADAR_SPRITE_TEXTURES_PATH .. name .. TEXTURE_FILE_FORMAT,
TEXTURE_QUALITY_FORMAT,
TEXTURE_MIPMAPS,
TEXTURE_EDGE
)
end
for id, name in pairs(RADAR_TRACE_TEXTURE_NAMES) do
drawData.radarSpriteBlipTraceTextures[id] = dxCreateTexture(
RADAR_BLIP_TRACE_TEXTURES_PATH .. name .. TEXTURE_FILE_FORMAT,
TEXTURE_QUALITY_FORMAT,
TEXTURE_MIPMAPS,
TEXTURE_EDGE
)
end
for id, name in pairs(HUD_SPRITE_TEXTURE_NAMES) do
drawData.hudSpriteTextures[id] = dxCreateTexture(
RADAR_SPRITE_TEXTURES_PATH .. name .. TEXTURE_FILE_FORMAT,
TEXTURE_QUALITY_FORMAT,
TEXTURE_MIPMAPS,
TEXTURE_EDGE
)
end
for y = 0, MAP_TILES_SIZE - 1 do
drawData.mapTileTextures[y] = {}
for x = 0, MAP_TILES_SIZE - 1 do
drawData.mapTileTextures[y][x] = dxCreateTexture(
MAP_TILE_TEXTURES_PATH .. "radar" .. string.format("%02d", (y * MAP_TILES_SIZE + x)) .. TEXTURE_FILE_FORMAT,
TEXTURE_QUALITY_FORMAT,
TEXTURE_MIPMAPS,
TEXTURE_EDGE
)
end
end
-- custom texture
drawData.radarMaskTexture = dxCreateTexture(
RADAR_SPRITE_TEXTURES_PATH .. HUD_SPRITE_TEXTURE_NAMES[HUD_SPRITE.RADAR_DISC] .. "_mask" .. TEXTURE_FILE_FORMAT,
TEXTURE_QUALITY_FORMAT,
TEXTURE_MIPMAPS,
TEXTURE_EDGE
)
return true
end
-- Radar.cpp: CRadar::Initialise() // 0x587FB0
local function init()
loadTextures()
setPlayerHudComponentVisible("radar", false)
toggleControl("radar", false)
toggleControl("radar_zoom_in", false)
toggleControl("radar_zoom_out", false)
toggleControl("radar_move_north", false)
toggleControl("radar_move_south", false)
toggleControl("radar_move_east", false)
toggleControl("radar_move_west", false)
toggleControl("radar_opacity_down", false)
toggleControl("radar_opacity_up", false)
toggleControl("radar_help", false)
return true
end
local function term()
setPlayerHudComponentVisible("radar", true)
toggleControl("radar", true)
toggleControl("radar_zoom_in", true)
toggleControl("radar_zoom_out", true)
toggleControl("radar_move_north", true)
toggleControl("radar_move_south", true)
toggleControl("radar_move_east", true)
toggleControl("radar_move_west", true)
toggleControl("radar_opacity_down", true)
toggleControl("radar_opacity_up", true)
toggleControl("radar_help", true)
return true
end
-- Radar.cpp: CRadar::DrawMap() // 0x586B00
local function calcRadarMapRange(element, matrix)
if getElementType(element) ~= "vehicle" then return RADAR_MAP_MIN_RANGE end
local speed = 0
if getVehicleRealType(element) == VEHICLE_REAL_TYPE.PLANE then
-- actually this is height ratio, not speed
speed = matrix[4][3] / ALTIMETER_WORLD_HEIGHT_LOW
else
local vx, vy, vz = getElementVelocity(element)
speed = getDistanceBetweenPoints3D(0, 0, 0, vx, vy, vz)
end
if speed < RADAR_MAP_MIN_RANGE_SPEED then
return RADAR_MAP_MIN_RANGE -- original plane's min range value is (RADAR_MAX_RANGE - 10.0)
end
if speed >= RADAR_MAP_MAX_RANGE_SPEED then
return RADAR_MAP_MAX_RANGE
end
return (speed - RADAR_MAP_MIN_RANGE_SPEED)
/ (RADAR_MAP_MAX_RANGE_SPEED - RADAR_MAP_MIN_RANGE_SPEED)
* (RADAR_MAP_MAX_RANGE - RADAR_MAP_MIN_RANGE)
+ RADAR_MAP_MIN_RANGE
end
local function prepareRadarMaskRt()
dxSetRenderTarget(drawData.radarMapMaskRt, true)
local offset = RADAR_SIZE_HALF - RADAR_MAP_MASK_RADIUS
for y = 0, 1 do
for x = 0, 1 do
dxDrawImage(
offset + RADAR_MAP_MASK_RADIUS * x,
offset + RADAR_MAP_MASK_RADIUS * y,
RADAR_MAP_MASK_RADIUS,
RADAR_MAP_MASK_RADIUS,
drawData.radarMaskTexture,
(-2 * x * y + x - y) * 90, 0, 0
)
end
end
dxSetRenderTarget()
dxSetShaderValue(drawData.radarMaskShader, "sMaskTexture", drawData.radarMapMaskRt)
return true
end
local function prepareRadarBorderRt()
dxSetRenderTarget(drawData.radarBorderRt, true)
dxSetBlendMode("overwrite")
local texture = drawData.hudSpriteTextures[HUD_SPRITE.RADAR_DISC]
for y = 0, 1 do
for x = 0, 1 do
dxDrawImage(
RADAR_SIZE_HALF * x,
RADAR_SIZE_HALF * y,
RADAR_SIZE / 2,
RADAR_SIZE / 2,
texture,
(-2 * x * y + x - y) * 90, 0, 0
)
end
end
dxSetBlendMode("blend")
dxSetRenderTarget()
return true
end
-- Radar.h: IsMapSectionInBounds(int32 x, int32 y)
local function isMapTileInBounds(x, y)
return x >= 0 and x < MAP_TILES_SIZE and y >= 0 and y < MAP_TILES_SIZE;
end
-- Radar.cpp: CRadar::DrawRadarSection(int32 x, int32 y) // 0x586110
local function drawRadarMapTile(tx, ty)
-- Radar.cpp: GetTextureCorners(int32 x, int32 y, CVector2D* corners) // 0x584D90
-- Top left tile world corner
local wx = MAP_TILE_WORLD_SIZE * (tx - MAP_TILES_SIZE_HALF)
local wy = MAP_TILE_WORLD_SIZE * (MAP_TILES_SIZE_HALF - ty)
-- Move by player position and scale
local rtx, rty = transformWorldToRadarMapRtView(wx, wy)
local rtx2, rty2 = transformWorldToRadarMapRtView(wx + MAP_TILE_WORLD_SIZE, wy - MAP_TILE_WORLD_SIZE)
if RADAR_MAP_SHOW_IN_INTERIOR or drawData.playerInterior == 0 then
if isMapTileInBounds(tx, ty) then
dxDrawImage(
rtx, rty,
rtx2 - rtx, rty2 - rty,
drawData.mapTileTextures[ty][tx],
0, 0, 0,
MAP_TILE_COLOR
)
else
-- as sea draws first pixel of top left tile
dxDrawImageSection(
rtx, rty,
rtx2 - rtx, rty2 - rty,
0, 0, 1, 1,
drawData.mapTileTextures[0][0],
0, 0, 0,
MAP_TILE_COLOR
)
end
else
dxDrawRectangle(
rtx, rty,
rtx2 - rtx, rty2 - rty,
MAP_TILE_INTERIOR_COLOR,
false,
true
)
end
return true
end
local function drawRadarMapTiles()
local x = math.floor((drawData.playerElementMatrix[4][1] + MAP_WORLD_SIZE_HALF) / MAP_TILE_WORLD_SIZE)
local y = math.ceil(MAP_TILES_SIZE - 1 - (drawData.playerElementMatrix[4][2] + MAP_WORLD_SIZE_HALF) / MAP_TILE_WORLD_SIZE)
dxSetRenderTarget(drawData.radarMapTilesRt)
dxSetBlendMode("modulate_add")
for dy = -RADAR_MAP_DRAW_TILES_RADIUS, RADAR_MAP_DRAW_TILES_RADIUS do
for dx = -RADAR_MAP_DRAW_TILES_RADIUS, RADAR_MAP_DRAW_TILES_RADIUS do
drawRadarMapTile(x + dx, y + dy);
end
end
dxSetBlendMode("blend")
dxSetRenderTarget()
return true
end
local function calcFlashingRadarAreaAlphaMultiplier()
return (math.sin((getTickCount() % 1024) / (1024 / (math.pi * 2))) + 1.0) / 2.0
end
local function drawRadarArea(area)
local dim = getElementDimension(area)
if dim ~= drawData.playerDimension then return false end
local int = getElementInterior(area)
if int ~= drawData.playerInterior then return false end
local x, y, _ = getElementPosition(area)
local width, height = getRadarAreaSize(area)
local x1, y1 = transformWorldToRadarMapRtView(x, y)
local x2, y2 = transformWorldToRadarMapRtView(x + width, y + height)
local r, g, b, a = getRadarAreaColor(area)
if isRadarAreaFlashing(area) then
a = a * drawData.flashingRadarAreaAlphaMultiplier
end
dxDrawRectangle(
x1, y1,
x2 - x1, y2 - y1,
tocolor(r, g, b, a),
false,
true
)
return true
end
-- Radar.cpp: CRadar::DrawRadarGangOverlay(bool inMenu) // 0x586650
local function drawRadarAreas()
dxSetRenderTarget(drawData.radarMapTilesRt)
dxSetBlendMode("modulate_add")
for i, area in ipairs(getElementsByType("radararea")) do
drawRadarArea(area)
end
dxSetBlendMode("blend")
dxSetRenderTarget()
return true
end
local function drawArtificialHorizon()
if getElementType(drawData.playerElement) ~= "vehicle" then return false end
if getVehicleRealType(drawData.playerElement) ~= VEHICLE_REAL_TYPE.PLANE then return false end
dxSetRenderTarget(drawData.radarOverlayRt)
dxSetBlendMode("modulate_add")
local pitch = math.atan2(-drawData.playerElementMatrix[2][3], drawData.playerElementMatrix[3][3]);
local horizon = RADAR_SIZE_HALF - (RADAR_SIZE_HALF * (pitch / math.pi))
dxDrawRectangle(
0, 0,
RADAR_SIZE, horizon,
ARTIFICIAL_HORIZON_SKY_COLOR,
false,
true
)
dxDrawRectangle(
0, horizon,
RADAR_SIZE, RADAR_SIZE,
ARTIFICIAL_HORIZON_GROUND_COLOR,
false,
true
)
local roll = math.atan2(-drawData.playerElementMatrix[1][3], drawData.playerElementMatrix[3][3])
dxDrawImage(
0, 0,
RADAR_SIZE, RADAR_SIZE,
drawData.hudSpriteTextures[HUD_SPRITE.RADAR_RING_PLANE],
math.deg(roll), 0, 0,
RING_PLANE_SPRITE_COLOR
)
dxSetBlendMode("blend")
dxSetRenderTarget()
return true
end
local function drawAltimeter()
if getElementType(drawData.playerElement) ~= "vehicle" then return true end
local vehicleRealType = getVehicleRealType(drawData.playerElement)
if not (vehicleRealType == VEHICLE_REAL_TYPE.PLANE or vehicleRealType == VEHICLE_REAL_TYPE.HELICOPTER) then return true end
dxDrawRectangle(
ALTIMETER_BG_SCREEN_X, ALTIMETER_BG_SCREEN_Y,
ALTIMETER_BG_WIDTH, ALTIMETER_BG_HEIGHT,
ALTIMETER_BG_COLOR
)
local height = drawData.playerElementMatrix[4][3]
local limit = ALTIMETER_WORLD_HEIGHT_MAX
if height <= ALTIMETER_WORLD_HEIGHT_LOW then
limit = ALTIMETER_WORLD_HEIGHT_LOW
end
dxDrawRectangle(
ALTIMETER_SCREEN_X,
ALTIMETER_BG_SCREEN_Y + ALTIMETER_BG_HEIGHT * (math_clamp(1 - height / limit, 0, 1)),
ALTIMETER_WIDTH,
ALTIMETER_HEIGHT,
ALTIMETER_COLOR,
false,
true
)
return true
end
local function drawRadarMaskShader()
dxSetShaderValue(drawData.radarMaskShader, "sMapTexture", drawData.radarMapTilesRt)
dxSetShaderValue(drawData.radarMaskShader, "sOverlayTexture", drawData.radarOverlayRt)
dxSetShaderValue(drawData.radarMaskShader, "sMaskTexture", drawData.radarMapMaskRt)
dxSetShaderValue(drawData.radarMaskShader, "gUVRotAngle", -drawData.playerCameraAngle)
dxDrawImage(RADAR_SCREEN_X, RADAR_SCREEN_Y, RADAR_SIZE, RADAR_SIZE, drawData.radarMaskShader)
return true
end
local function drawRadarBorder()
dxDrawImage(
RADAR_SCREEN_X, RADAR_SCREEN_Y,
RADAR_SIZE, RADAR_SIZE,
drawData.radarBorderRt,
0, 0, 0,
RADAR_BORDER_COLOR
)
return true
end
-- Radar.cpp: CRadar::LimitRadarPoint(CVector2D& point) // 0x5832F0
local function limitVectorLength(x1, y1, x2, y2, limit)
local length = getDistanceBetweenPoints2D(x1, y1, x2, y2)
if length > limit then
local k = limit / length
x2, y2 = (x2 - x1) * k + x1, (y2 - y1) * k + y1
end
return x2, y2
end
-- Radar.cpp: GetRadarAndScreenPos(float* radarPointDist)
-- Radar.h: CachedRotateClockwise(const CVector2D& point)
local function transformWorldToRadarMapBlipView(x, y)
x, y = getPositionFromMatrixOffset2D(drawData.radarMapRtRotView, x, y)
return limitVectorLength(RADAR_SIZE_HALF, RADAR_SIZE_HALF, x, y, RADAR_BLIP_VECTOR_MAX_LENGTH)
end
local function getRadarSpriteBlipTraceFromHeight(z)
local diff = z - drawData.playerElementMatrix[4][3]
if diff > RADAR_BLIP_TRACE_HIGH_HEIGHT_DIFF then return RADAR_TRACE.HIGH end
if diff < RADAR_BLIP_TRACE_LOW_HEIGHT_DIFF then return RADAR_TRACE.LOW; end
return RADAR_TRACE.NORMAL
end
local function getRadarSpriteBlipSize(spriteId, size)
size = size / RADAR_BLIP_SIZE_GTASA_DEFAULT * RADAR_BLIP_SIZE
if spriteId == RADAR_SPRITE.CENTRE then return size * RADAR_BLIP_CENTRE_SIZE_MULTIPLIER end
if spriteId == RADAR_SPRITE.NONE then return size * RADAR_BLIP_TRACE_SIZE_MULTIPLIER end
return size
end
-- Radar.cpp: CRadar::DrawRadarSprite(eRadarSprite spriteId, float x, float y, uint8 alpha) // 0x585FF0
local function drawRadarSprite(spriteId, x, y, z, r, g, b, a, size, rot)
x, y = transformWorldToRadarMapBlipView(x, y)
rot = rot and (math.deg(drawData.playerCameraAngle) - rot) or 0
size = getRadarSpriteBlipSize(spriteId, size)
a = a * RADAR_BLIP_ALPHA_MULTIPLIER
local texture = drawData.radarSpriteTextures[spriteId]
if spriteId == RADAR_SPRITE.NONE then
texture = drawData.radarSpriteBlipTraceTextures[getRadarSpriteBlipTraceFromHeight(z)]
end
if not texture then return false end
dxDrawImage(
RADAR_SCREEN_X + x - (size / 2), RADAR_SCREEN_Y + y - (size / 2),
math.floor(size), math.floor(size),
texture,
rot, 0, 0,
tocolor(r, g, b, a)
)
return true
end
-- Radar.cpp: CRadar::DrawCoordBlip(int32 blipIndex, bool isSprite) // 0x586D60
local function drawRadarBlip(blip)
local x, y, z = getElementPosition(blip)
local limit = getBlipVisibleDistance(blip)
if limit <= 0 then return false end
if limit < MAP_WORLD_SIZE then
local dis = getDistanceBetweenPoints2D(
drawData.playerElementMatrix[4][1], drawData.playerElementMatrix[4][2],
x, y)
if dis > limit then return false end
end
local r, g, b, a = getBlipColor(blip)
drawRadarSprite(getBlipIcon(blip), x, y, z, r, g, b, a, getBlipSize(blip));
return true
end
-- Radar.cpp: CRadar::DrawBlips() // 0x588050
local function drawRadarBlips()
drawRadarSprite(
RADAR_SPRITE.NORTH,
drawData.playerElementMatrix[4][1],
drawData.playerElementMatrix[4][2] + MAP_WORLD_SIZE,
drawData.playerElementMatrix[4][3],
255, 255, 255, 255,
RADAR_BLIP_SIZE_GTASA_DEFAULT)
for _, blip in ipairs(getBlipsByInteriorDimensionOrdered(drawData.playerInterior, drawData.playerDimension)) do
drawRadarBlip(blip)
end
if not (getElementType(drawData.playerElement) == "vehicle" and getVehicleRealType(drawData.playerElement) == VEHICLE_REAL_TYPE.PLANE) then
drawRadarSprite(
RADAR_SPRITE.CENTRE,
drawData.playerElementMatrix[4][1],
drawData.playerElementMatrix[4][2],
drawData.playerElementMatrix[4][3],
255, 255, 255, 255,
RADAR_BLIP_SIZE_GTASA_DEFAULT,
math.deg(math.atan2(-drawData.playerElementMatrix[2][1], drawData.playerElementMatrix[2][2]))
)
end
return true
end
local function updateRadarMapRtViews()
-- Radar.h: float& m_radarRange (radar world radius)
local radarMapRange = calcRadarMapRange(drawData.playerElement, drawData.playerElementMatrix)
local worldToRtRelView = transform2.mul(
transform2.move(-drawData.playerElementMatrix[4][1], -drawData.playerElementMatrix[4][2]),
transform2.scale(1 / radarMapRange, 1 / radarMapRange))
local rtRelToRtAbsView = transform2.mul(transform2.mul(
transform2.scale(1, -1),
transform2.move(1, 1)),
transform2.scale(RADAR_SIZE_HALF, RADAR_SIZE_HALF))
drawData.radarMapRtView = transform2.mul(
worldToRtRelView,
rtRelToRtAbsView)
drawData.radarMapRtRotView = transform2.mul(transform2.mul(
worldToRtRelView,
transform2.rotate(-drawData.playerCameraAngle)),
rtRelToRtAbsView)
return true
end
-- Hud.cpp: CHud::DrawRadar() // 0x58A330
local function drawRadar()
if not drawData.showRadar then return true end
if drawData.showBigMap then return true end
updateRadarMapRtViews()
-- reset RT
dxSetRenderTarget(drawData.radarMapTilesRt, true)
dxSetRenderTarget(drawData.radarOverlayRt, true)
dxSetRenderTarget()
if not drawData.areRenderTargetsReady then
prepareRadarMaskRt()
prepareRadarBorderRt()
drawData.areRenderTargetsReady = true
end
drawRadarMapTiles()
drawRadarAreas()
drawArtificialHorizon()
drawAltimeter()
drawRadarMaskShader()
drawRadarBorder()
drawRadarBlips()
return true
end
local function transformWorldToBigMapScreenView(x, y)
return getPositionFromMatrixOffset2D(drawData.bigMapScreenViewResult, x, y)
end
local function moveBigMap(x, y)
drawData.bigMapScreenViewTransform = transform2.mul(
drawData.bigMapScreenViewTransform,
transform2.move(x, y))
-- TODO: refactor
local scale = drawData.bigMapScreenViewTransform[1][1]
local bigMapSize = BIGMAP_SIZE * scale
local bigMapSizeBordered = bigMapSize / BIGMAP_ZOOM_SCALE_MIN
local x0 = (SCREEN_WIDTH - bigMapSize) / 2
local y0 = (SCREEN_HEIGHT - bigMapSize) / 2
local dx = math.max(0, (bigMapSizeBordered - SCREEN_WIDTH) / 2)
local dy = math.max(0, (bigMapSizeBordered - SCREEN_HEIGHT) / 2)
drawData.bigMapScreenViewTransform[3][1] = math_clamp(drawData.bigMapScreenViewTransform[3][1], x0 - dx, x0 + dx)
drawData.bigMapScreenViewTransform[3][2] = math_clamp(drawData.bigMapScreenViewTransform[3][2], y0 - dy, y0 + dy)
return true
end
local function updateBigMapCursorMoving()
if not BIGMAP_CURSOR_ENABLED then return end
if not drawData.showBigMap then return end
if not isCursorShowing() then return end
if not getKeyState(BIGMAP_MOVE_MOUSE_KEY) then return end
if guiGetInputEnabled() then return end
if isMTAWindowActive() then return end
if drawData.cursorOnGui then return end
moveBigMap(
drawData.cursorCurrPos[1] - drawData.cursorPrevPos[1],
drawData.cursorCurrPos[2] - drawData.cursorPrevPos[2])
return true
end
local function updateBigMapScreenView()
drawData.bigMapScreenViewResult = transform2.mul(transform2.mul(transform2.mul(
transform2.scale(1 / MAP_WORLD_SIZE, -1 / MAP_WORLD_SIZE),
transform2.move(0.5, 0.5)),
transform2.scale(BIGMAP_SIZE, BIGMAP_SIZE)),
drawData.bigMapScreenViewTransform)
return true
end
local function drawBigMapTiles()
local sx1, sy1 = transformWorldToBigMapScreenView(-MAP_WORLD_SIZE_HALF, MAP_WORLD_SIZE_HALF)
local sx2, sy2 = transformWorldToBigMapScreenView(MAP_WORLD_SIZE_HALF, -MAP_WORLD_SIZE_HALF)
local size = (sx2 - sx1) / MAP_TILES_SIZE
local r, g, b, a = fromcolor(MAP_TILE_COLOR)
a = a * drawData.bigMapAlphaMultiplier
local color = tocolor(r, g, b, a)
for ty = 0, MAP_TILES_SIZE - 1 do
for tx = 0, MAP_TILES_SIZE - 1 do
dxDrawImage(
sx1 + (tx * size), sy1 + (ty * size),
size, size,
drawData.mapTileTextures[ty][tx],
0, 0, 0,
color
)
end
end
-- draws sea background
dxDrawImageSection(
0, 0,
sx1, SCREEN_HEIGHT,
0, 0, 1, 1,
drawData.mapTileTextures[0][0],
0, 0, 0,
color
)
dxDrawImageSection(
sx2, 0,
SCREEN_WIDTH - sx2, SCREEN_HEIGHT,
0, 0, 1, 1,
drawData.mapTileTextures[0][0],
0, 0, 0,
color
)
dxDrawImageSection(
sx1, 0,
sx2 - sx1, sy1,
0, 0, 1, 1,
drawData.mapTileTextures[0][0],
0, 0, 0,
color
)
dxDrawImageSection(
sx1, sy2,
sx2 - sx1, SCREEN_HEIGHT - sy2,
0, 0, 1, 1,
drawData.mapTileTextures[0][0],
0, 0, 0,
color
)
return true
end
local function drawBigMapRadarArea(area)
local dim = getElementDimension(area)
if dim ~= drawData.playerDimension then return false end
local int = getElementInterior(area)
if int ~= drawData.playerInterior then return false end
local x, y, _ = getElementPosition(area)
local width, height = getRadarAreaSize(area)
local x1, y1 = transformWorldToBigMapScreenView(x, y + height)
local x2, y2 = transformWorldToBigMapScreenView(x + width, y)
local r, g, b, a = getRadarAreaColor(area)
a = a * drawData.bigMapAlphaMultiplier
if isRadarAreaFlashing(area) then
a = a * drawData.flashingRadarAreaAlphaMultiplier
end
dxDrawRectangle(
x1, y1,
x2 - x1, y2 - y1,
tocolor(r, g, b, a),
false,
true
)
return true
end
local function drawBigMapRadarAreas()
for i, area in ipairs(getElementsByType("radararea")) do
drawBigMapRadarArea(area)
end
return true
end
local function drawBigMapSprite(spriteId, x, y, z, r, g, b, a, size, rot)
x, y = transformWorldToBigMapScreenView(x, y)
rot = rot and (-rot) or 0
size = getRadarSpriteBlipSize(spriteId, size)
a = a * drawData.bigMapAlphaMultiplier
local texture = drawData.radarSpriteTextures[spriteId]
if spriteId == RADAR_SPRITE.NONE then
texture = drawData.radarSpriteBlipTraceTextures[getRadarSpriteBlipTraceFromHeight(z)]
end
if not texture then return false end
-- for MAP_HERE blip center is upper
if spriteId == RADAR_SPRITE.MAP_HERE then
dxDrawImage(
x - (size / 2), y,
size, size,
texture,
rot, 0, -size / 2,