-
Notifications
You must be signed in to change notification settings - Fork 1
/
SAMP.ahk
2548 lines (2204 loc) · 100 KB
/
SAMP.ahk
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
; /$$$$$$ /$$$$$$ /$$ /$$ /$$$$$$$ /$$$$$$ /$$ /$$ /$$ /$$
; /$$__ $$ /$$__ $$| $$$ /$$$| $$__ $$ /$$__ $$| $$ | $$| $$ /$$/
;| $$ \__/| $$ \ $$| $$$$ /$$$$| $$ \ $$| $$ \ $$| $$ | $$| $$ /$$/
;| $$$$$$ | $$$$$$$$| $$ $$/$$ $$| $$$$$$$/| $$$$$$$$| $$$$$$$$| $$$$$/
; \____ $$| $$__ $$| $$ $$$| $$| $$____/ | $$__ $$| $$__ $$| $$ $$
; /$$ \ $$| $$ | $$| $$\ $ | $$| $$ | $$ | $$| $$ | $$| $$\ $$
;| $$$$$$/| $$ | $$| $$ \/ | $$| $$ | $$ | $$| $$ | $$| $$ \ $$
; \______/ |__/ |__/|__/ |__/|__/ |__/ |__/|__/ |__/|__/ \__/
;
; ################################
; https://github.com/kessec/SAMPAHK
; ################################
; KEEP THE VERSION TEXT AT LINE 17 OR YOUR MERGE WILL BE CLOSED.
/*
SAMPAHK VERSION: 1.1.0
*/
; ErrorLevels
global ERROR_OK := 0
global ERROR_PROCESS_NOT_FOUND := 1
global ERROR_OPEN_PROCESS := 2
global ERROR_INVALID_HANDLE := 3
global ERROR_MODULE_NOT_FOUND := 4
global ERROR_ENUM_PROCESS_MODULES := 5
global ERROR_ZONE_NOT_FOUND := 6
global ERROR_CITY_NOT_FOUND := 7
global ERROR_READ_MEMORY := 8
global ERROR_WRITE_MEMORY := 9
global ERROR_ALLOC_MEMORY := 10
global ERROR_FREE_MEMORY := 11
global ERROR_WAIT_FOR_OBJECT := 12
global ERROR_CREATE_THREAD := 13
; Address Styling:
; Similar to this: ADDR_POINTER_INFO
; Example: ADDR_CPED_HPOFF is dependent on the CPED pointer and is the offset for HP information.
; GTA Control Block Addresses
global ADDR_CPED_PTR := 0xB6F5F0
global ADDR_VEHICLE_PTR := 0xBA18FC
global ADDR_CVEH_PTR := 0xB6F980
global ADDR_CVEH_PTR2 := 0xB6F3B8
global ADDR_CVEH_CONTROL := 0xB73458
global ADDR_MENU_PTR := 0xBA6748
; GTA CPed Addresses
global ADDR_CPED_HPOFF := 0x540
global ADDR_CPED_ARMOROFF := 0x548
global ADDR_CPED_MONEY := 0xB7CE50
global ADDR_CPED_INTID := 0xA4ACE8
; GTA Car Addresses
global ADDR_VEHICLE_HPOFF := 0x4C0
global ADDR_VEHICLE_DOORSTATE := 0x4F8
global ADDR_VEHICLE_ENGINESTATE := 0x428
global ADDR_VEHICLE_LIGHTSTATE := 0x584
global ADDR_VEHICLE_MODEL := 0x22
global ADDR_VEHICLE_TYPE := 0x590
global ADDR_VEHICLE_DRIVER := 0x460
global ADDR_CVEH_BIKE := 0x6C8
global ADDR_CVEH_BIKE_FTIRE := 0x65E
global ADDR_CVEH_BIKE_RTIRE := 0x65F
; GTA Enviroment Addresses
global ADDR_CURRENT_WEATHER := 0xC81320
global ADDR_CURRENT_GRAVITY := 0x863984
global ADDR_ZONECODE := 0xA49AD4
global ADDR_POSITION_X := 0xB6F2E4
global ADDR_POSITION_Y := 0xB6F2E8
global ADDR_POSITION_Z := 0xB6F2EC
global ADDR_CPED_X_OFF := 0x30
global ADDR_CPED_Y_OFF := 0x34
global ADDR_CPED_Z_OFF := 0x38
global ADDR_CPED_ROTZ := 0x558
; GTA Menu Addresses
global ADDR_MOUSE_SENS := 0xB6EC1C
global ADDR_HBAR_COLOR := 0xBAB22C
global ADDR_MFONT_COLOR := 0xBAB230
global ADDR_MENU_CID := 0x15D
global ADDR_MENU_IHOVER := 0x78D
global ADDR_MENU_SELECT := 0x54
global ADDR_MENU_SWITCH := 0xE9
global ADDR_MENU_LANG := 0x84
global ADDR_MENU_MAPX := 0x68
global ADDR_MENU_MAPY := 0x6C
global ADDR_MENU_PLAYINMENU := 0x5C
; GTA Gun Addresses
global ADDR_GUN_RECOIL := 0x858CEC
global ADDR_CPED_GUN_TYPE := 0x740
global ADDR_CPED_PISTOLAMMO := 0x5E0
global ADDR_CPED_SHOTGUNAMMO := 0x5FC
; global ADDR_GUN_TYPE := 00
; global ADDR_GUN_STATE := 04
; global ADDR_GUN_AMMO := 08
; global ADDR_GUN_RAMMO := 12
; GTA Cheat Addresses
global ADDR_CHEAT_INFRUN := 0xB7CEE4
; GTA Misc. Addresses
global ADDR_GARAGE_DOORSTATE := 0x4D
global oAirplaneModels := [417, 425, 447, 460, 469, 476, 487, 488, 497, 511, 512, 513, 519, 520, 548, 553, 563, 577, 592, 593]
global oBikeModels := [481,509,510]
global ovehicleNames := ["Landstalker","Bravura","Buffalo","Linerunner","Perrenial","Sentinel","Dumper","Firetruck","Trashmaster","Stretch","Manana","Infernus","Voodoo","Pony","Mule","Cheetah","Ambulance","Leviathan","Moonbeam","Esperanto","Taxi","Washington","Bobcat","Whoopee","BFInjection","Hunter","Premier","Enforcer","Securicar","Banshee","Predator","Bus","Rhino","Barracks","Hotknife","Trailer","Previon","Coach","Cabbie","Stallion","Rumpo","RCBandit","Romero","Packer","Monster","Admiral","Squalo","Seasparrow","Pizzaboy","Tram","Trailer","Turismo","Speeder","Reefer","Tropic","Flatbed","Yankee","Caddy","Solair","Berkley'sRCVan","Skimmer","PCJ-600","Faggio","Freeway","RCBaron","RCRaider","Glendale","Oceanic","Sanchez","Sparrow","Patriot","Quad","Coastguard","Dinghy","Hermes","Sabre","Rustler","ZR-350","Walton","Regina","Comet","BMX","Burrito","Camper","Marquis","Baggage","Dozer","Maverick","NewsChopper","Rancher","FBIRancher","Virgo","Greenwood","Jetmax","Hotring","Sandking","BlistaCompact","PoliceMaverick","Boxvillde","Benson","Mesa","RCGoblin","HotringRacerA","HotringRacerB","BloodringBanger","Rancher","SuperGT","Elegant","Journey","Bike","MountainBike","Beagle","Cropduster","Stunt","Tanker","Roadtrain","Nebula","Majestic","Buccaneer","Shamal","hydra","FCR-900","NRG-500","HPV1000","CementTruck","TowTruck","Fortune","Cadrona","FBITruck","Willard","Forklift","Tractor","Combine","Feltzer","Remington","Slamvan","Blade","Freight","Streak","Vortex","Vincent","Bullet","Clover","Sadler","Firetruck","Hustler","Intruder","Primo","Cargobob","Tampa","Sunrise","Merit","Utility","Nevada","Yosemite","Windsor","Monster","Monster","Uranus","Jester","Sultan","Stratum","Elegy","Raindance","RCTiger","Flash","Tahoma","Savanna","Bandito","FreightFlat","StreakCarriage","Kart","Mower","Dune","Sweeper","Broadway","Tornado","AT-400","DFT-30","Huntley","Stafford","BF-400","NewsVan","Tug","Trailer","Emperor","Wayfarer","Euros","Hotdog","Club","FreightBox","Trailer","Andromada","Dodo","RCCam","Launch","PoliceCar","PoliceCar","PoliceCar","PoliceRanger","Picador","S.W.A.T","Alpha","Phoenix","GlendaleShit","SadlerShit","Luggage","Luggage","Stairs","Boxville","Tiller","UtilityTrailer"]
; SAMP Addresses
global ADDR_SAMP_INCHAT_PTR := 0x21A10C
global ADDR_SAMP_INCHAT_PTR_OFF := 0x55
global ADDR_SAMP_USERNAME := 0x219A6F
global ADDR_SAMP_CHATMSG_PTR := 0x21A0E4
global ADDR_SAMP_SHOWDLG_PTR := 0x21A0B8
global FUNC_SAMP_SENDCMD := 0x65C60
global FUNC_SAMP_SENDSAY := 0x57F0
global FUNC_SAMP_ADDTOCHATWND := 0x64520
global FUNC_SAMP_SHOWGAMETEXT := 0x9C2C0
global FUNC_SAMP_PLAYAUDIOSTR := 0x62DA0
global FUNC_SAMP_STOPAUDIOSTR := 0x629A0
global FUNC_SAMP_SHOWDIALOG := 0x6B9C0
global FUNC_UPDATESCOREBOARD := 0x8A10
global SAMP_LAST_CHAT_MESSAGE_OFFSET := 0x62C6
global SAMP_INFO_OFFSET := 0x21A0F8
global SAMP_PPOOLS_OFFSET := 0x3CD
global SAMP_PPOOL_PLAYER_OFFSET := 0x18
global SAMP_SLOCALPLAYERID_OFFSET := 0x4
global SAMP_ISTRLEN_LOCALPLAYERNAME_OFFSET := 0x1A
global SAMP_SZLOCALPLAYERNAME_OFFSET := 0xA
global SAMP_PSZLOCALPLAYERNAME_OFFSET := 0xA
global SAMP_PREMOTEPLAYER_OFFSET := 0x2E
global SAMP_ISTRLENNAME___OFFSET := 0x1C
global SAMP_SZPLAYERNAME_OFFSET := 0xC
global SAMP_PSZPLAYERNAME_OFFSET := 0xC
global SAMP_ILOCALPLAYERPING_OFFSET := 0x26
global SAMP_ILOCALPLAYERSCORE_OFFSET := 0x2A
global SAMP_IPING_OFFSET := 0x28
global SAMP_ISCORE_OFFSET := 0x24
global SAMP_ISNPC_OFFSET := 0x4
global SAMP_SZIP_OFFSET := 0x20
global SAMP_SZHOSTNAME_OFFSET := 0x121
global SAMP_PLAYER_MAX := 1004
; Sizes
global SIZE_SAMP_CHATMSG := 0xFC
; Internal
global hGTA := 0x0
global dwGTAPID := 0x0
global dwSAMP := 0x0
global pMemory := 0x0
global pParam1 := 0x0
global pParam2 := 0x0
global pParam3 := 0x0
global pParam4 := 0x0
global pParam5 := 0x0
global pInjectFunc := 0x0
global nZone := 1
global nCity := 1
global bInitZaC := 0
global iRefreshScoreboard := 0
global oScoreboardData := ""
global iRefreshHandles := 0
global iUpdateTick := 2500 ;time in ms, used for getPlayerNameById etc. to refresh data
global bCheckSizeOnce := 1
; #####################################################################################################################
; # SAMP-Functions: #
; # - isInChat() check if dialog or chatbox is active #
; # - getUsername() get local player name #
; # - getId() get local player id #
; # - sendChatMessage(wText) send a message to the server #
; # - getLastChatMessage() get the last message added to the ChatBox #
; # - addMessageToChatWindow(wText) add a "private" text to the chatbox #
; # - showGameText(wText, dwTime, dwTextsize) show a text on the sreen #
; # - showDialog(dwStyle, wCaption, show a dialog-box #
; # wInfo, wButton1) #
; # - playAudioStream(wUrl) play an "audio stream" #
; # - stopAudioStream() stopp an audio stream #
; # - blockChatInput() call this func to block chat messages to server #
; # - unBlockChatInput() call this func to unblock chat messages to server #
; # ----------------------------------------------------------------------------------------------------------------- #
; # - patchRadio() (internal stuff) #
; # - unPatchRadio() (internal stuff) #
; #####################################################################################################################
; # - getPlayerNameById(dwId) get some player's name #
; # - getPlayerIdByName(wName) get some player's id #
; # - getPlayerScoreById(dwId) get some player's score #
; # - getPlayerPingById(dwId) get some player's ping #
; # - isNPCById(dwId) check if player is a NPC #
; # - getIP() get server ip #
; # - getHostname() get server hostname #
; # - countOnlinePlayers() get players count #
; # - getTargetPed() fetch targeted player #
; # ----------------------------------------------------------------------------------------------------------------- #
; # - updateScoreboardDataEx() (internal stuff) #
; # - updateOScoreboardData() (internal stuff) #
; #####################################################################################################################
; # Player Functions : #
; # - getPlayerHealth() get HP #
; # - getPlayerArmor() get ARMOR #
; # - getPlayerInteriorId() get interior id #
; # - getPlayerMoney() get player money #
; # - getPlayerRotation() get the rotation of the player. #
; #####################################################################################################################
; # Gun Functions : #
; # - editRecoil() changes the recoil/spread #
; # - getGunType() gets the type of gun the local player has in hand. #
; # - getGunAmmo() gets the current ammo in the gun in hand. #
; #####################################################################################################################
; # Gun Functions : #
; # - editRecoil() changes the recoil/spread #
; # - getGunType() gets the type of gun the local player has in hand. #
; # - getGunAmmo() gets the current ammo in the gun in hand. #
; #####################################################################################################################
; # Vehicle Functions: #
; # - isPlayerInAnyVehicle() check if the local player is inside some vehicle #
; # - isPlayerDriver() check if player is driver #
; # - getVehicleHealth() get vehicle health #
; # - getVehicleType() get vehicle type #
; # - getVehicleModelId() get vehicle model id #
; # - getVehicleModelName() get vehicle model name #
; # - getVehicleLightState() get vehicle light state #
; # - getVehicleEngineState() get vehicle engine state #
; # - getVehicleLockState() get vehicle door lock state #
; #####################################################################################################################
; # - GetChatLine(Line, Output, timestamp, color) fetch chat line specified #
; #####################################################################################################################
; # Coordinates: #
; # - getCoordinates() get local player's position #
; # - getTargetPedCoordinates() get targeted player's position #
; # ----------------------------------------------------------------------------------------------------------------- #
; # - calculateZone(X, Y, Z) get zone #
; # - calculateCity(X, Y, Z) get city #
; # - getCurrentZonecode() get zone code (buggy) #
; #####################################################################################################################
; # Internal Functions: #
; # - initZonesAndCities() #
; # - AddZone(Name, X1, Y1, Z1, X2, Y2, Z2) #
; # - AddCity(Name, X1, Y1, Z1, X2, Y2, Z2) #
; #####################################################################################################################
; # Memory Functions: #
; # - checkHandles() #
; # - refreshGTA() #
; # - refreshSAMP() #
; # - refreshMemory() #
; # - getPID(szWindow) #
; # - openProcess(dwPID, dwRights) #
; # - closeProcess(hProcess) #
; # - getModuleBaseAddress(sModule, dwPID) #
; # - readString(hProcess, dwAddress, dwLen) #
; # - readFloat(hProcess, dwAddress) #
; # - readDWORD(hProcess, dwAddress) #
; # - readMem(hProcess, dwAddress, dwLen=4, type="UInt") #
; # - writeString(hProcess, dwAddress, wString) #
; # - writeFloat(hProcess, dwAddress, dwValue) #
; # - writeDWORD(hProcess, dwAddress, dwValue) #
; # - writeMem(hProcess, dwAddress, dwValue, dwLen=4, type="UInt") #
; # - writeRaw(hProcess, dwAddress, data, dwLen) #
; # - callWithParams(hProcess, dwFunc, aParams, bCleanupStack = true) #
; # - virtualAllocEx(hProcess, dwSize, flAllocationType, flProtect) #
; # - virtualFreeEx(hProcess, lpAddress, dwSize, dwFreeType) #
; # - createRemoteThread(hProcess, lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, #
; # dwCreationFlags, lpThreadId) #
; # - waitForSingleObject(hThread, dwMilliseconds) #
; # - __ansiToUnicode(sString, nLen = 0) #
; # - __unicodeToAnsi(wString, nLen = 0) #
; #####################################################################################################################
; # Debug Functions: #
; # - sendToDebug(tString) # #
; #####################################################################################################################
; ##### SAMP-Functions #####
; 1 = chat/dialog open
; 0 = not open
; -1 = error
isInChat() {
if(!checkHandles())
return -1
dwPtr := dwSAMP + ADDR_SAMP_INCHAT_PTR
dwAddress := readDWORD(hGTA, dwPtr) + ADDR_SAMP_INCHAT_PTR_OFF
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return -1
}
dwInChat := readDWORD(hGTA, dwAddress)
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return -1
}
ErrorLevel := ERROR_OK
if(dwInChat > 0) {
return true
} else {
return false
}
}
; get nickname or empty string ""
getUsername() {
if(!checkHandles())
return ""
dwAddress := dwSAMP + ADDR_SAMP_USERNAME
sUsername := readString(hGTA, dwAddress, 25)
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return ""
}
ErrorLevel := ERROR_OK
return sUsername
}
; get local player id or -1 on error
getId() {
s:=getUsername()
return getPlayerIdByName(s)
}
; pass a string to send a chat message to the server
sendChatMessage(wText) {
wText := "" wText
if(!checkHandles())
return false
dwFunc:=0
if(SubStr(wText, 1, 1) == "/") {
dwFunc := dwSAMP + FUNC_SAMP_SENDCMD
} else {
dwFunc := dwSAMP + FUNC_SAMP_SENDSAY
}
callWithParams(hGTA, dwFunc, [["s", wText]], false)
ErrorLevel := ERROR_OK
return true
}
; get the last message added to the ChatBox.
getLastChatMessage(){
if(!checkHandles())
return ""
dwAddress := dwSAMP + ADDR_SAMP_CHATMSG_PTR
currentAddress := readDWORD(hGTA, dwAddress) + SAMP_LAST_CHAT_MESSAGE_OFFSET
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return "Can not read from memory."
}
Message := readString(hGTA, currentAddress, 150)
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return "Can not read from memory."
}
ErrorLevel := ERROR_OK
return Message
}
; similar to: http://wiki.sa-mp.com/wiki/SendClientMessage
; pass a string to add a private message to the chatbox
addMessageToChatWindow(wText) {
wText := "" wText
if(!checkHandles())
return false
dwFunc := dwSAMP + FUNC_SAMP_ADDTOCHATWND
dwChatInfo := readDWORD(hGTA, dwSAMP + ADDR_SAMP_CHATMSG_PTR)
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return false
}
callWithParams(hGTA, dwFunc, [["p", dwChatInfo], ["s", wText]], true)
ErrorLevel := ERROR_OK
return true
}
; similar to: http://wiki.sa-mp.com/wiki/GameTextForPlayer
; wText The text to be displayed.
; dwTime The duration of the text being shown in milliseconds.
; dwStyle The style of text to be displayed.
showGameText(wText, dwTime, dwSize) {
wText := "" wText
dwTime += 0
dwTime := Floor(dwTime)
dwSize += 0
dwSize := Floor(dwSize)
if(!checkHandles())
return false
dwFunc := dwSAMP + FUNC_SAMP_SHOWGAMETEXT
callWithParams(hGTA, dwFunc, [["s", wText], ["i", dwTime], ["i", dwSize]], false)
ErrorLevel := ERROR_OK
return true
}
; similar to: http://wiki.sa-mp.com/wiki/ShowPlayerDialog
; dwStyle The style of the dialog.
; wCaption The title at the top of the dialog. The length of the caption can not exceed more than 64 characters before it starts to cut off.
; wInfo The text to display in the main dialog. Use \n to start a new line and \t to tabulate.
; wButton1 The text on the left button.
showDialog(dwStyle, wCaption, wInfo, wButton1 ) {
dwStyle += 0
dwStyle := Floor(dwStyle)
wCaption := "" wCaption
wInfo := "" wInfo
wButton1 := "" wButton1
if(dwStyle<0 || dwStyle>5 || StrLen(wCaption)>=64 || StrLen(wInfo)>=4096 || StrLen(wButton1)>10)
return false
if(!checkHandles())
return false
dwFunc := dwSAMP + FUNC_SAMP_SHOWDIALOG
dwAddress := readDWORD(hGTA, dwSAMP + ADDR_SAMP_SHOWDLG_PTR)
if(ErrorLevel || dwAddress==0) {
ErrorLevel := ERROR_READ_MEMORY
return false
}
writeString(hGTA, pParam5, wCaption)
if(ErrorLevel)
return false
writeString(hGTA, pParam1, wInfo)
if(ErrorLevel)
return false
writeString(hGTA, pParam5+512, wButton1)
if(ErrorLevel)
return false
;mov + 7*push + call + retn
dwLen := 5 + 7*5 + 5 + 1
VarSetCapacity(injectData, dwLen, 0)
NumPut(0xB9, injectData, 0, "UChar") ;0 + 1 ;mov ecx
NumPut(dwAddress, injectData, 1, "UInt") ;1 + 4
NumPut(0x68, injectData, 5, "UChar") ;5 + 1 ;push 0
NumPut(0, injectData, 6, "UInt") ;6 + 4
NumPut(0x68, injectData, 10, "UChar") ;10 + 1 ;push 0
NumPut(pParam5+StrLen(wCaption), injectData, 11, "UInt") ;11 + 4
NumPut(0x68, injectData, 15, "UChar") ;15 + 1 ;push button1
NumPut(pParam5+512, injectData, 16, "UInt") ;16 + 4
NumPut(0x68, injectData, 20, "UChar") ;20 + 1 ;push info
NumPut(pParam1, injectData, 21, "UInt") ;21 + 4
NumPut(0x68, injectData, 25, "UChar") ;25 + 1 ;push caption
NumPut(pParam5, injectData, 26, "UInt") ;26 + 4
NumPut(0x68, injectData, 30, "UChar") ;30 + 1 ;push style
NumPut(dwStyle, injectData, 31, "UInt") ;31 + 4
NumPut(0x68, injectData, 35, "UChar") ;35 + 1 ;push 1
NumPut(1, injectData, 36, "UInt") ;36 + 4
NumPut(0xE8, injectData, 40, "UChar") ;40 + 1 ;call
offset := dwFunc - (pInjectFunc + 45)
NumPut(offset, injectData, 41, "Int") ;41 + 4
NumPut(0xC3, injectData, 45, "UChar") ;45 + 1 ;retn
writeRaw(hGTA, pInjectFunc, &injectData, dwLen)
if(ErrorLevel)
return false
hThread := createRemoteThread(hGTA, 0, 0, pInjectFunc, 0, 0, 0)
if(ErrorLevel)
return false
waitForSingleObject(hThread, 0xFFFFFFFF)
closeProcess(hThread)
return true
}
; similar to: http://wiki.sa-mp.com/wiki/PlayAudioStreamForPlayer
; pass a url to play some sound
playAudioStream(wUrl) {
wUrl := "" wUrl
if(!checkHandles())
return false
dwFunc := dwSAMP + FUNC_SAMP_PLAYAUDIOSTR
patchRadio()
callWithParams(hGTA, dwFunc, [["s", wUrl], ["i", 0], ["i", 0], ["i", 0], ["i", 0], ["i", 0]], false)
unPatchRadio()
ErrorLevel := ERROR_OK
return true
}
; stop a audio stream
stopAudioStream() {
if(!checkHandles())
return false
dwFunc := dwSAMP + FUNC_SAMP_STOPAUDIOSTR
patchRadio()
callWithParams(hGTA, dwFunc, [["i", 1]], false)
unPatchRadio()
ErrorLevel := ERROR_OK
return true
}
; call this func to block chat messages to server
blockChatInput() {
if(!checkHandles())
return false
VarSetCapacity(nop, 2, 0)
dwFunc := dwSAMP + FUNC_SAMP_SENDSAY
NumPut(0x04C2,nop,0,"Short")
writeRaw(hGTA, dwFunc, &nop, 2)
dwFunc := dwSAMP + FUNC_SAMP_SENDCMD
writeRaw(hGTA, dwFunc, &nop, 2)
return true
}
; call this func to unblock chat messages to server
unBlockChatInput() {
if(!checkHandles())
return false
VarSetCapacity(nop, 2, 0)
dwFunc := dwSAMP + FUNC_SAMP_SENDSAY
NumPut(0xA164,nop,0,"Short")
writeRaw(hGTA, dwFunc, &nop, 2)
dwFunc := dwSAMP + FUNC_SAMP_SENDCMD
writeRaw(hGTA, dwFunc, &nop, 2)
return true
}
; needed for audio stream
patchRadio() {
if(!checkHandles())
return false
VarSetCapacity(nop, 4, 0)
NumPut(0x90909090,nop,0,"UInt")
dwFunc := dwSAMP + FUNC_SAMP_PLAYAUDIOSTR
writeRaw(hGTA, dwFunc, &nop, 4)
writeRaw(hGTA, dwFunc+4, &nop, 1)
dwFunc := dwSAMP + FUNC_SAMP_STOPAUDIOSTR
writeRaw(hGTA, dwFunc, &nop, 4)
writeRaw(hGTA, dwFunc+4, &nop, 1)
return true
}
; needed for audio stream
unPatchRadio() {
if(!checkHandles())
return false
VarSetCapacity(old, 4, 0)
dwFunc := dwSAMP + FUNC_SAMP_PLAYAUDIOSTR
NumPut(0x74003980,old,0,"UInt")
writeRaw(hGTA, dwFunc, &old, 4)
NumPut(0x39,old,0,"UChar")
writeRaw(hGTA, dwFunc+4, &old, 1)
dwFunc := dwSAMP + FUNC_SAMP_STOPAUDIOSTR
NumPut(0x74003980,old,0,"UInt")
writeRaw(hGTA, dwFunc, &old, 4)
NumPut(0x09,old,0,"UChar")
writeRaw(hGTA, dwFunc+4, &old, 1)
return true
}
; pass an id to get nickname
; returns an empty string on error
getPlayerNameById(dwId) {
dwId += 0
dwId := Floor(dwId)
if(dwId < 0 || dwId >= SAMP_PLAYER_MAX)
return ""
if(!updateOScoreboardData())
return ""
if(oScoreboardData[dwId])
return oScoreboardData[dwId].NAME
return ""
}
; pass a nickname or a part of it to get id
; (not case sensivite)
; returns -1 on error
getPlayerIdByName(wName) {
wName := "" wName
if(StrLen(wName) < 1 || StrLen(wName) > 20)
return -1
if(!updateOScoreboardData())
return -1
For i, o in oScoreboardData
{
if(InStr(o.NAME,wName)==1)
return i
}
return -1
}
; pass an id to get score
; returns an empty string on error
getPlayerScoreById(dwId) {
dwId += 0
dwId := Floor(dwId)
if(dwId < 0 || dwId >= SAMP_PLAYER_MAX)
return ""
if(!updateOScoreboardData())
return ""
if(oScoreboardData[dwId])
return oScoreboardData[dwId].SCORE
return ""
}
; pass an id to get ping
; returns -1 on error
getPlayerPingById(dwId) {
dwId += 0
dwId := Floor(dwId)
if(dwId < 0 || dwId >= SAMP_PLAYER_MAX)
return -1
if(!updateOScoreboardData())
return -1
if(oScoreboardData[dwId])
return oScoreboardData[dwId].PING
return -1
}
; pass an id to check if id is a NPC
; 1 = id is a NPC
; 0 = id is a human, usually ;)
; returns -1 on error
isNPCById(dwId) {
dwId += 0
dwId := Floor(dwId)
if(dwId < 0 || dwId >= SAMP_PLAYER_MAX)
return -1
if(!updateOScoreboardData())
return -1
if(oScoreboardData[dwId])
return oScoreboardData[dwId].ISNPC
return -1
}
; returns server ip or empty string on error
getIP() {
if(!checkHandles())
return ""
dwAddress := readDWORD(hGTA, dwSAMP + SAMP_INFO_OFFSET)
if(ErrorLevel || dwAddress==0) {
ErrorLevel := ERROR_READ_MEMORY
return ""
}
ipaddr := readString(hGTA, dwAddress+SAMP_SZIP_OFFSET, 257)
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return ""
}
return ipaddr
}
; returns server hostname or empty string on error
getHostname() {
if(!checkHandles())
return ""
dwAddress := readDWORD(hGTA, dwSAMP + SAMP_INFO_OFFSET)
if(ErrorLevel || dwAddress==0) {
ErrorLevel := ERROR_READ_MEMORY
return ""
}
hostname := readString(hGTA, dwAddress+SAMP_SZHOSTNAME_OFFSET, 259)
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return ""
}
return hostname
}
; returns number of players on server
countOnlinePlayers() {
if(!updateOScoreboardData())
return 0
j := 0
For i, o in oScoreboardData
{
if(isNPCById(i)==0)
j += 1
}
return j
}
; internal stuff
updateScoreboardDataEx() {
if(!checkHandles())
return false
dwAddress := readDWORD(hGTA, dwSAMP + SAMP_INFO_OFFSET) ;g_SAMP
if(ErrorLevel || dwAddress==0) {
ErrorLevel := ERROR_READ_MEMORY
return false
}
dwFunc := dwSAMP + FUNC_UPDATESCOREBOARD
VarSetCapacity(injectData, 11, 0) ;mov + call + retn
NumPut(0xB9, injectData, 0, "UChar")
NumPut(dwAddress, injectData, 1, "UInt")
NumPut(0xE8, injectData, 5, "UChar")
offset := dwFunc - (pInjectFunc + 10)
NumPut(offset, injectData, 6, "Int")
NumPut(0xC3, injectData, 10, "UChar")
writeRaw(hGTA, pInjectFunc, &injectData, 11)
if(ErrorLevel)
return false
hThread := createRemoteThread(hGTA, 0, 0, pInjectFunc, 0, 0, 0)
if(ErrorLevel)
return false
waitForSingleObject(hThread, 0xFFFFFFFF)
closeProcess(hThread)
return true
}
; internal stuff
updateOScoreboardData() {
if(!checkHandles())
return 0
if(iRefreshScoreboard+iUpdateTick > A_TickCount)
return 1
oScoreboardData := []
if(!updateScoreboardDataEx())
return 0
iRefreshScoreboard := A_TickCount
dwAddress := readDWORD(hGTA, dwSAMP + SAMP_INFO_OFFSET)
if(ErrorLevel || dwAddress==0) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
dwAddress := readDWORD(hGTA, dwAddress + SAMP_PPOOLS_OFFSET)
if(ErrorLevel || dwAddress==0) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
dwPlayers := readDWORD(hGTA, dwAddress + SAMP_PPOOL_PLAYER_OFFSET)
if(ErrorLevel || dwPlayers==0) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
wID := readMem(hGTA, dwPlayers + SAMP_SLOCALPLAYERID_OFFSET, 2, "Short") ;sLocalPlayerID
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
dwPing := readMem(hGTA, dwPlayers + SAMP_ILOCALPLAYERPING_OFFSET, 4, "Int")
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
dwScore := readMem(hGTA, dwPlayers + SAMP_ILOCALPLAYERSCORE_OFFSET, 4, "Int")
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
dwTemp := readMem(hGTA, dwPlayers + SAMP_ISTRLEN_LOCALPLAYERNAME_OFFSET, 4, "Int") ;iStrlen_LocalPlayerName
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
sUsername := ""
if(dwTemp <= 0xf) {
sUsername := readString(hGTA, dwPlayers + SAMP_SZLOCALPLAYERNAME_OFFSET, 16) ;szLocalPlayerName
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
}
else {
dwAddress := readDWORD(hGTA, dwPlayers + SAMP_PSZLOCALPLAYERNAME_OFFSET) ;pszLocalPlayerName
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
sUsername := readString(hGTA, dwAddress, 25)
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
}
oScoreboardData[wID] := Object("NAME", sUsername, "ID", wID, "PING", dwPing, "SCORE", dwScore, "ISNPC", 0)
Loop, % SAMP_PLAYER_MAX
{
i := A_Index-1
dwRemoteplayer := readDWORD(hGTA, dwPlayers+SAMP_PREMOTEPLAYER_OFFSET+i*4) ;pRemotePlayer
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
if(dwRemoteplayer==0)
continue
dwPing := readMem(hGTA, dwRemoteplayer + SAMP_IPING_OFFSET, 4, "Int")
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
dwScore := readMem(hGTA, dwRemoteplayer + SAMP_ISCORE_OFFSET, 4, "Int")
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
dwIsNPC := readMem(hGTA, dwRemoteplayer + SAMP_ISNPC_OFFSET, 4, "Int")
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
dwTemp := readMem(hGTA, dwRemoteplayer + SAMP_ISTRLENNAME___OFFSET, 4, "Int")
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
sUsername := ""
if(dwTemp <= 0xf)
{
sUsername := readString(hGTA, dwRemoteplayer+SAMP_SZPLAYERNAME_OFFSET, 16)
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
}
else {
dwAddress := readDWORD(hGTA, dwRemoteplayer + SAMP_PSZPLAYERNAME_OFFSET)
if(ErrorLevel || dwAddress==0) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
sUsername := readString(hGTA, dwAddress, 25)
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return 0
}
}
o := Object("NAME", sUsername, "ID", i, "PING", dwPing, "SCORE", dwScore, "ISNPC", dwIsNPC)
oScoreboardData[i] := o
}
ErrorLevel := ERROR_OK
return 1
}
; ##### Player Functions #####
; return HP or -1 on error
getPlayerHealth() {
if(!checkHandles())
return -1
dwCPedPtr := readDWORD(hGTA, ADDR_CPED_PTR)
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return -1
}
dwAddr := dwCPedPtr + ADDR_CPED_HPOFF
fHealth := readFloat(hGTA, dwAddr)
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return -1
}
ErrorLevel := ERROR_OK
return Round(fHealth)
}
; return ARMOR or -1 on error
getPlayerArmor() {
if(!checkHandles())
return -1
dwCPedPtr := readDWORD(hGTA, ADDR_CPED_PTR)
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return -1
}
dwAddr := dwCPedPtr + ADDR_CPED_ARMOROFF
fHealth := readFloat(hGTA, dwAddr)
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return -1
}
ErrorLevel := ERROR_OK
return Round(fHealth)
}
; returns -1 on error or some interior id
getPlayerInteriorId() {
if(!checkHandles())
return -1
iid := readMem(hGTA, ADDR_CPED_INTID, 4, "Int")
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return -1
}
ErrorLevel := ERROR_OK
return iid
}
; returns local players money or an empty string on error
getPlayerMoney() {
if(!checkHandles())
return ""
money := readMem(hGTA, ADDR_CPED_MONEY, 4, "Int")
if(ErrorLevel) {
ErrorLevel := ERROR_READ_MEMORY
return ""
}