forked from TCRoid/Stand-Lua-RScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRScript.lua
More file actions
2972 lines (2527 loc) · 106 KB
/
Copy pathRScript.lua
File metadata and controls
2972 lines (2527 loc) · 106 KB
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
--------------------------------
-- Author: Rostal
--------------------------------
local SCRIPT_START_TIME <const> = util.current_time_millis()
util.require_natives("3095a", "init")
local SCRIPT_VERSION <const> = "2023/12/23"
local SUPPORT_GTAO <const> = 1.68
--------------------------------------
---------- File & Dir ----------
--------------------------------------
-- Store
local STORE_DIR <const> = filesystem.store_dir() .. "RScript\\"
if not filesystem.exists(STORE_DIR) then
filesystem.mkdir(STORE_DIR)
end
-- Resource
local RESOURCE_DIR <const> = filesystem.resources_dir() .. "RScript\\"
Texture = {
file = {
crosshair = RESOURCE_DIR .. "crosshair.png",
},
}
for _, file in pairs(Texture.file) do
if not filesystem.exists(file) then
util.toast("[RScript] 缺少文件: " .. file, TOAST_ALL)
util.toast("脚本已停止运行")
util.stop_script()
end
end
Texture.crosshair = directx.create_texture(Texture.file.crosshair)
-- Lib
local SCRIPT_LIB_DIR <const> = filesystem.scripts_dir() .. "lib\\RScript\\"
local REQUIRED_FILES <const> = {
"Tables.lua",
"variables.lua",
"alternatives.lua",
"functions.lua",
"functions2.lua",
"utils.lua",
"EntityLib.lua",
"Menu\\Entity.lua",
"Menu\\Mission.lua",
"Menu\\Online.lua",
"Menu\\Assistant.lua",
"Menu\\Bodyguard.lua",
"Menu\\Dev.lua",
}
for _, file in pairs(REQUIRED_FILES) do
local file_path = SCRIPT_LIB_DIR .. file
if not filesystem.exists(file_path) then
util.toast("[RScript] 缺少文件: " .. file_path, TOAST_ALL)
util.toast("脚本已停止运行")
util.stop_script()
end
end
-- Require
require "RScript.Tables"
require "RScript.variables"
require "RScript.alternatives"
require "RScript.functions"
require "RScript.functions2"
require "RScript.utils"
require "RScript.EntityLib"
-----------------------------------
---------- Setting ----------
-----------------------------------
Setting = {}
local SETTING_FILE <const> = STORE_DIR .. "setting.txt"
if not filesystem.exists(SETTING_FILE) or not filesystem.is_regular_file(SETTING_FILE) then
-- Default Setting
Setting = {
["Dev Mode"] = false,
["Change Script Entry"] = false,
}
util.write_colons_file(SETTING_FILE, Setting)
else
Setting = util.read_colons_and_tabs_file(SETTING_FILE)
end
---@param key string
---@return boolean|string
function getSetting(key)
local value = Setting[key]
if value == nil then
Setting[key] = false
return false
end
if value == "false" then
return false
end
if value == "true" then
return true
end
return value
end
---@param key string
---@param value boolean|string|number
function setSetting(key, value)
Setting[key] = value
end
DEV_MODE = getSetting("Dev Mode")
-- Backend Loop
Loop_Handler = {
Main = {},
Self = {},
Tunables = {
Cooldown = {},
SpecialCargo = {},
VehicleCargo = {},
Bunker = {},
AirFreight = {},
Biker = {},
AcidLab = {},
Payphone = {},
},
Entity = {
show_info = {},
draw_line = {},
draw_bounding_box = {},
preview_ent = {
ent = 0,
clone_ent = 0,
has_cloned_ent = 0,
camera_distance = 2.0,
},
lock_tp = {},
},
}
-- Transition Finished
Transition_Handler = {
Self = {},
}
util.on_transition_finished(function()
if Transition_Handler.Self.refill_armour then
menu.trigger_commands("refillarmour")
end
end)
---------------------------------------------
---------- Script Menu Start ----------
---------------------------------------------
if not SCRIPT_SILENT_START then
local GTAO = tonumber(NETWORK.GET_ONLINE_VERSION())
if SUPPORT_GTAO ~= GTAO then
util.toast("支持的GTA线上版本: " .. SUPPORT_GTAO .. "\n当前GTA线上版本: " .. GTAO)
end
end
Menu_Root = menu.my_root()
if getSetting("Change Script Entry") then
Menu_Root = menu.attach_before(menu.ref_by_path("Stand>Settings"),
menu.list(menu.shadow_root(), "RScript", { "rscript" }, ""))
menu.action(Menu_Root, "停止脚本", {}, "", function()
menu.trigger_commands("stopluarscript")
end)
menu.divider(menu.my_root(), "RScript")
menu.action(menu.my_root(), "转到脚本", {}, "", function()
menu.trigger_commands("rscript")
end)
end
menu.divider(Menu_Root, "RScript")
----------------------------------------
---------- Self Options ----------
----------------------------------------
local Self_Options <const> = menu.list(Menu_Root, "自我选项", {}, "")
local tSelf = {}
--#region Health & Armour
local Self_HealthArmour <const> = menu.list(Self_Options, "生命与护甲选项", {}, "")
tSelf.HealthArmour = {
defaultHealth = 328,
defaultArmour = 50,
}
menu.toggle_loop(Self_HealthArmour, "信息显示 生命和护甲", {}, "信息显示位置", function()
local current_health = ENTITY.GET_ENTITY_HEALTH(players.user_ped())
local max_health = PED.GET_PED_MAX_HEALTH(players.user_ped())
local current_armour = PED.GET_PED_ARMOUR(players.user_ped())
local max_armour = PLAYER.GET_PLAYER_MAX_ARMOUR(players.user())
local text = string.format("生命: %d/%d\n护甲: %d/%d", current_health, max_health, current_armour, max_armour)
util.draw_debug_text(text)
end)
menu.toggle(Self_HealthArmour, "切换战局自动补满护甲", {}, "", function(toggle)
Transition_Handler.Self.refill_armour = toggle
end)
menu.divider(Self_HealthArmour, "")
menu.slider(Self_HealthArmour, "设置当前生命值", { "set_health" }, "",
0, 100000, tSelf.HealthArmour.defaultHealth, 50, function(value)
SET_ENTITY_HEALTH(players.user_ped(), value)
end)
menu.slider(Self_HealthArmour, "设置当前护甲值", { "set_armour" }, "",
0, 100000, tSelf.HealthArmour.defaultArmour, 50, function(value)
PED.SET_PED_ARMOUR(players.user_ped(), value)
end)
--#endregion Health & Armour
--#region Health Recharge
local Self_HealthRecharge <const> = menu.list(Self_Options, "生命恢复选项", {}, "")
tSelf.HealthRecharge = {
maxPercent = 1.0,
multiplier = 20.0,
}
menu.slider_float(Self_HealthRecharge, "恢复程度", { "self_recharge_percent" }, "",
1, 100, tSelf.HealthRecharge.maxPercent * 100, 10, function(value)
tSelf.HealthRecharge.maxPercent = value * 0.01
end)
menu.slider_float(Self_HealthRecharge, "恢复速度", { "self_recharge_multi" }, "",
1, 10000, tSelf.HealthRecharge.multiplier * 100, 100, function(value)
tSelf.HealthRecharge.multiplier = value * 0.01
end)
menu.toggle_loop(Self_HealthRecharge, "设置生命恢复", { "fast_recharge" }, "", function()
if PLAYER.GET_PLAYER_HEALTH_RECHARGE_MAX_PERCENT(players.user()) ~= tSelf.HealthRecharge.maxPercent then
PLAYER.SET_PLAYER_HEALTH_RECHARGE_MAX_PERCENT(players.user(), tSelf.HealthRecharge.maxPercent)
end
PLAYER.SET_PLAYER_HEALTH_RECHARGE_MULTIPLIER(players.user(), tSelf.HealthRecharge.multiplier)
end, function()
PLAYER.SET_PLAYER_HEALTH_RECHARGE_MAX_PERCENT(players.user(), 0.5)
PLAYER.SET_PLAYER_HEALTH_RECHARGE_MULTIPLIER(players.user(), 1.0)
end)
--#endregion Health Recharge
--#region Wanted
local Self_Wanted <const> = menu.list(Self_Options, "通缉选项", {}, "")
menu.toggle_loop(Self_Wanted, "禁止为玩家调度警察", { "no_dispatch_cops" }, "不会一直刷出新的警察,最好在被通缉前开启",
function()
PLAYER.SET_DISPATCH_COPS_FOR_PLAYER(players.user(), false)
end, function()
PLAYER.SET_DISPATCH_COPS_FOR_PLAYER(players.user(), true)
end)
menu.action(Self_Wanted, "强制进入躲避区域", {}, "警星开始闪烁,警察使用锥形视野搜寻", function()
PLAYER.FORCE_START_HIDDEN_EVASION(players.user())
end)
menu.action(Self_Wanted, "移除当前载具通缉状态", {}, "", function()
local vehicle = entities.get_user_vehicle_as_handle()
if vehicle ~= INVALID_GUID then
VEHICLE.SET_VEHICLE_IS_WANTED(vehicle, false)
VEHICLE.SET_VEHICLE_INFLUENCES_WANTED_LEVEL(vehicle, false)
VEHICLE.SET_VEHICLE_HAS_BEEN_OWNED_BY_PLAYER(vehicle, true)
VEHICLE.SET_VEHICLE_IS_STOLEN(vehicle, false)
VEHICLE.SET_POLICE_FOCUS_WILL_TRACK_VEHICLE(vehicle, false)
end
end)
menu.toggle_loop(Self_Wanted, "Low Wanted Level Multiplier", {},
"Set multiplier to 0.0, default is 1.0", function()
PLAYER.SET_WANTED_LEVEL_MULTIPLIER(0.0)
end, function()
PLAYER.SET_WANTED_LEVEL_MULTIPLIER(1.0)
end)
menu.toggle_loop(Self_Wanted, "Low Wanted Level Difficulty", {},
"Set difficulty to 0.0", function()
PLAYER.SET_WANTED_LEVEL_DIFFICULTY(players.user(), 0.0)
end, function()
PLAYER.RESET_WANTED_LEVEL_DIFFICULTY(players.user())
end)
menu.toggle_loop(Self_Wanted, "Suppress Crime", {},
"Can be use to disable all instances of a crime type on this frame.", function()
for i = 1, 50 do
PLAYER.SUPPRESS_CRIME_THIS_FRAME(players.user(), i)
end
end)
--#endregion Wanted
--#region Fall
local Self_Fall <const> = menu.list(Self_Options, "跌落选项", {}, "")
tSelf.Fall = {
height = 8.0
}
menu.toggle_loop(Self_Fall, "禁止高处跌落直接死亡", {}, "如果血量过低仍然会直接摔死",
function()
PED.SET_DISABLE_HIGH_FALL_DEATH(players.user_ped(), true)
end, function()
PED.SET_DISABLE_HIGH_FALL_DEATH(players.user_ped(), false)
end)
menu.slider_float(Self_Fall, "触发跌落动作高度", { "self_fall_distance" }, "",
0, 10000, tSelf.Fall.height * 100, 100, function(value)
tSelf.Fall.height = value * 0.01
end)
menu.toggle_loop(Self_Fall, "设置触发跌落动作高度", {}, "", function()
PLAYER.SET_PLAYER_FALL_DISTANCE_TO_TRIGGER_RAGDOLL_OVERRIDE(players.user(), tSelf.Fall.height)
end)
--#endregion Fall
--#region Options
menu.toggle_loop(Self_Options, "警察无视", {}, "", function()
PLAYER.SET_POLICE_IGNORE_PLAYER(players.user(), true)
end, function()
PLAYER.SET_POLICE_IGNORE_PLAYER(players.user(), false)
end)
menu.toggle_loop(Self_Options, "所有人无视", {}, "", function()
PLAYER.SET_EVERYONE_IGNORE_PLAYER(players.user(), true)
end, function()
PLAYER.SET_EVERYONE_IGNORE_PLAYER(players.user(), false)
end)
menu.toggle_loop(Self_Options, "行动无声", {}, "", function()
PLAYER.SET_PLAYER_NOISE_MULTIPLIER(players.user(), 0.0)
PLAYER.SET_PLAYER_SNEAKING_NOISE_MULTIPLIER(players.user(), 0.0)
end)
menu.toggle_loop(Self_Options, "不会被帮派骚乱", {}, "", function()
PLAYER.SET_PLAYER_CAN_BE_HASSLED_BY_GANGS(players.user(), false)
end, function()
PLAYER.SET_PLAYER_CAN_BE_HASSLED_BY_GANGS(players.user(), true)
end)
menu.toggle_loop(Self_Options, "载具内不可被射击", {}, "在载具内不会受伤", function()
PED.SET_PED_CAN_BE_SHOT_IN_VEHICLE(players.user_ped(), false)
end, function()
PED.SET_PED_CAN_BE_SHOT_IN_VEHICLE(players.user_ped(), true)
end)
menu.toggle_loop(Self_Options, "禁用NPC伤害", { "no_ai_damage" }, "", function()
PED.SET_AI_WEAPON_DAMAGE_MODIFIER(0.0)
PED.SET_AI_MELEE_WEAPON_DAMAGE_MODIFIER(0.0)
end, function()
PED.RESET_AI_WEAPON_DAMAGE_MODIFIER()
PED.RESET_AI_MELEE_WEAPON_DAMAGE_MODIFIER()
end)
menu.toggle_loop(Self_Options, "只能被玩家伤害", {}, "不会被NPC伤害", function()
ENTITY.SET_ENTITY_ONLY_DAMAGED_BY_PLAYER(players.user_ped(), true)
end, function()
ENTITY.SET_ENTITY_ONLY_DAMAGED_BY_PLAYER(players.user_ped(), false)
end)
menu.toggle_loop(Self_Options, "禁止被爆头一枪击杀", {}, "", function()
PED.SET_PED_SUFFERS_CRITICAL_HITS(players.user_ped(), false)
end, function()
PED.SET_PED_SUFFERS_CRITICAL_HITS(players.user_ped(), true)
end)
menu.toggle_loop(Self_Options, "可以射击队友", {}, "", function()
PED.SET_CAN_ATTACK_FRIENDLY(players.user_ped(), true, false)
end, function()
PED.SET_CAN_ATTACK_FRIENDLY(players.user_ped(), false, false)
end)
Loop_Handler.Self.defense_modifier = {
callback = function(value)
PLAYER.SET_PLAYER_WEAPON_DEFENSE_MODIFIER(players.user(), value)
PLAYER.SET_PLAYER_WEAPON_MINIGUN_DEFENSE_MODIFIER(players.user(), value)
PLAYER.SET_PLAYER_MELEE_WEAPON_DEFENSE_MODIFIER(players.user(), value)
PLAYER.SET_PLAYER_VEHICLE_DEFENSE_MODIFIER(players.user(), value)
PLAYER.SET_PLAYER_WEAPON_TAKEDOWN_DEFENSE_MODIFIER(players.user(), value)
end
}
menu.slider_float(Self_Options, "受伤倍数修改", { "defense_multiplier" }, "数值越低,受到的伤害就越低",
10, 100, 100, 10, function(value)
value = value * 0.01
Loop_Handler.Self.defense_modifier.value = value
Loop_Handler.Self.defense_modifier.callback(value)
end)
--#endregion Options
------------------------------------------
---------- Weapon Options ----------
------------------------------------------
local Weapon_Options <const> = menu.list(Menu_Root, "武器选项", {}, "")
local tWeapon = {}
--#region Weapon Attributes
local Weapon_Attributes <const> = menu.list(Weapon_Options, "武器属性修改", {}, "修改武器属性,应用修改后会一直生效")
local WeaponAttribute = {
BaseInfo = {
["anim_reload_time"] = { offset = 0x134, type = "float" },
["vehicle_reload_time"] = { offset = 0x130, type = "float" },
["time_between_shots"] = { offset = 0x13c, type = "float" },
["alternate_wait_time"] = { offset = 0x150, type = "float" },
["reload_time_mp"] = { offset = 0x128, type = "float" },
["reload_time_sp"] = { offset = 0x12c, type = "float" },
["lock_on_range"] = { offset = 0x288, type = "float" },
["weapon_range"] = { offset = 0x28c, type = "float" },
},
RocketInfo = {
["lifetime"] = { offset = 0x44, type = "float" },
["launch_speed"] = { offset = 0x58, type = "float" },
["forward_drag_coeff"] = { offset = 0x170, type = "float" },
["side_drag_coeff"] = { offset = 0x174, type = "float" },
["time_before_homing"] = { offset = 0x178, type = "float" },
["pitch_change_rate"] = { offset = 0x188, type = "float" },
["yaw_change_rate"] = { offset = 0x18c, type = "float" },
["roll_change_rate"] = { offset = 0x190, type = "float" },
["max_roll_angle_sin"] = { offset = 0x194, type = "float" },
},
HomingParam = {
["should_use_homing_params_from_info"] = { offset = 0x0, type = "byte" },
["time_before_starting_homing"] = { offset = 0x4, type = "float" },
["time_before_homing_angle_break"] = { offset = 0x8, type = "float" },
["turn_rate_modifier"] = { offset = 0xc, type = "float" },
["pitch_yaw_roll_clamp"] = { offset = 0x10, type = "float" },
["default_homing_rocket_break_lock_angle"] = { offset = 0x14, type = "float" },
["default_homing_rocket_break_lock_angle_close"] = { offset = 0x18, type = "float" },
["default_homing_rocket_break_lock_close_distance"] = { offset = 0x1c, type = "float" },
},
Persets = {
ItemList = {
{
menu_name = "载具导弹 无限快速连发",
help_text = "",
weapon_type = 2,
data_list = {
{ "time_between_shots", 0.2, true },
{ "alternate_wait_time", 0.2, true },
{ "reload_time_mp", 0, true },
{ "reload_time_sp", 0, true },
}
},
{
menu_name = "载具机枪 快速射击",
help_text = "",
weapon_type = 2,
data_list = {
{ "time_between_shots", 0, true },
{ "alternate_wait_time", 0, true },
{ "reload_time_mp", 0, true },
{ "reload_time_sp", 0, true },
}
},
{
menu_name = "手持武器 通用设置",
help_text = "换弹动作速度+0.2, 载具内换弹时间=0, 射击间隔时间-0.02",
weapon_type = 1,
data_list = {
{ "anim_reload_time", 0.2, false },
{ "vehicle_reload_time", 0, true },
{ "time_between_shots", -0.02, false },
}
},
{
menu_name = "制导导弹 增强锁定能力",
help_text = "",
weapon_type = 3,
data_list = {
{ "lifetime", 10.0, true },
{ "side_drag_coeff", 10.0, true },
{ "pitch_change_rate", 100.0, true },
{ "yaw_change_rate", 100.0, true },
{ "roll_change_rate", 100.0, true },
{ "should_use_homing_params_from_info", 1, true },
{ "time_before_starting_homing", 0.15, true },
{ "turn_rate_modifier", 100.0, true },
{ "pitch_yaw_roll_clamp", 8.5, true },
{ "default_homing_rocket_break_lock_angle", 0.2, true },
{ "default_homing_rocket_break_lock_angle_close", 0.6, true },
{ "default_homing_rocket_break_lock_close_distance", 20.0, true },
}
},
}
},
Backups = {},
Menus = {},
Index = 0,
}
function WeaponAttribute.CWeaponInfo()
local ped_ptr = entities.handle_to_pointer(players.user_ped())
local weapon_manager = entities.get_weapon_manager(ped_ptr)
local m_weapon_info = weapon_manager + 0x20
local m_vehicle_weapon_info = weapon_manager + 0x70
local CWeaponInfo = memory.read_long(m_weapon_info)
if CWeaponInfo ~= 0 and WEAPON.IS_PED_ARMED(players.user_ped(), 4) then
return CWeaponInfo
end
local CVehicleWeaponInfo = memory.read_long(m_vehicle_weapon_info)
if CVehicleWeaponInfo ~= 0 then
return CVehicleWeaponInfo
end
return 0
end
function WeaponAttribute.CAmmoInfo(CWeaponInfo)
if CWeaponInfo == 0 then return 0 end
if not WeaponAttribute.IsRocket(CWeaponInfo) then
return 0
end
return memory.read_long(CWeaponInfo + 0x60) -- m_ammo_info
end
function WeaponAttribute.CHomingRocketParams(CAmmoInfo)
if CAmmoInfo == 0 then return 0 end
return CAmmoInfo + 0x19c -- m_homing_rocket_params
end
function WeaponAttribute.IsRocket(CWeaponInfo)
local m_damage_type = CWeaponInfo + 0x20
local m_fire_type = CWeaponInfo + 0x54
return memory.read_int(m_damage_type) == 5 and memory.read_int(m_fire_type) == 4
end
function WeaponAttribute.GetWeaponName(weaponHash)
local weaponName = get_weapon_name_by_hash(weaponHash)
if weaponName == "" then
weaponName = util.reverse_joaat(weaponHash)
weaponName = string.gsub(weaponName, "VEHICLE_WEAPON_", "")
end
if weaponName == "" then
weaponName = tostring(weaponHash)
end
return weaponName
end
function WeaponAttribute.GetAttributes(CWeaponInfo, weaponName)
local text = "武器: " .. weaponName
local attr_value = 0
for name, item in pairs(WeaponAttribute.BaseInfo) do
attr_value = memory.read_float(CWeaponInfo + item.offset)
text = text .. "\n" .. name .. ": " .. attr_value
end
local CAmmoInfo = WeaponAttribute.CAmmoInfo(CWeaponInfo)
if CAmmoInfo ~= 0 then
for name, item in pairs(WeaponAttribute.RocketInfo) do
attr_value = memory.read_float(CAmmoInfo + item.offset)
text = text .. "\n" .. name .. ": " .. attr_value
end
end
local CHomingRocketParams = WeaponAttribute.CHomingRocketParams(CAmmoInfo)
if CHomingRocketParams ~= 0 then
for name, item in pairs(WeaponAttribute.HomingParam) do
if item.type == "float" then
attr_value = memory.read_float(CHomingRocketParams + item.offset)
elseif item.type == "byte" then
attr_value = memory.read_byte(CHomingRocketParams + item.offset)
end
text = text .. "\n" .. name .. ": " .. attr_value
end
end
return text
end
function WeaponAttribute.SetAttribute(addr, value, Type, isAddition)
if addr == 0 then return end
local get_value = memory.read_float
local set_value = memory.write_float
if Type == "byte" then
get_value = memory.read_byte
set_value = memory.write_byte
end
local default_value = get_value(addr)
if default_value < -1 then return end
if default_value > 65536 then return end
if isAddition then
value = default_value + value
end
set_value(addr, value)
end
function WeaponAttribute.StoreBackup(CWeaponInfo, weaponHash)
if WeaponAttribute.Backups[weaponHash] then return end
local t = {}
local attr_value = 0
for name, item in pairs(WeaponAttribute.BaseInfo) do
local addr = CWeaponInfo + item.offset
attr_value = memory.read_float(addr)
t[name] = { value = attr_value, type = item.type, addr = addr }
end
local CAmmoInfo = WeaponAttribute.CAmmoInfo(CWeaponInfo)
if CAmmoInfo ~= 0 then
for name, item in pairs(WeaponAttribute.RocketInfo) do
local addr = CAmmoInfo + item.offset
attr_value = memory.read_float(addr)
t[name] = { value = attr_value, type = item.type, addr = addr }
end
end
local CHomingRocketParams = WeaponAttribute.CHomingRocketParams(CAmmoInfo)
if CHomingRocketParams ~= 0 then
for name, item in pairs(WeaponAttribute.HomingParam) do
local addr = CHomingRocketParams + item.offset
if item.type == "float" then
attr_value = memory.read_float(addr)
elseif item.type == "byte" then
attr_value = memory.read_byte(addr)
end
t[name] = { value = attr_value, type = item.type, addr = addr }
end
end
WeaponAttribute.Backups[weaponHash] = t
WeaponAttribute.GenerateMenu(CWeaponInfo, weaponHash)
end
function WeaponAttribute.ClearListData()
for _, value in pairs(WeaponAttribute.Menus) do
if value then
return false
end
end
WeaponAttribute.Menus = {}
WeaponAttribute.Index = 0
end
function WeaponAttribute.GenerateMenu(CWeaponInfo, weaponHash)
if WeaponAttribute.Menus[weaponHash] then return end
local weapon_name = WeaponAttribute.GetWeaponName(weaponHash)
local menu_parent = Weapon_Attributes
-- menu.list 存进表内
local menu_list = menu.list(menu_parent, weapon_name, {}, "")
WeaponAttribute.Menus[weaponHash] = menu_list
menu.textslider_stateful(menu_list, "读取武器属性", {}, "", {
"仅通知", "通知并保存到日志"
}, function(value)
local text = WeaponAttribute.GetAttributes(CWeaponInfo, weapon_name)
util.toast(text)
if value == 2 then
util.log("\n" .. text)
end
end)
menu.action(menu_list, "恢复默认属性", {}, "", function()
for key, item in pairs(WeaponAttribute.Backups[weaponHash]) do
if item.type == "float" then
memory.write_float(item.addr, item.value)
elseif item.type == "byte" then
memory.write_byte(item.addr, item.value)
end
end
util.toast("已恢复默认属性")
end)
menu.action(menu_list, "删除此条记录", {}, "会保存默认属性", function()
menu.delete(menu_list)
WeaponAttribute.Menus[weaponHash] = nil
WeaponAttribute.ClearListData()
end)
menu.divider(menu_list, "属性列表")
for name, item in pairs(WeaponAttribute.BaseInfo) do
local addr = CWeaponInfo + item.offset
local default_value = memory.read_float(addr)
menu.text_input(menu_list, name,
{ "weapon_attr" .. WeaponAttribute.Index .. name },
"", function(value, click_type)
if click_type ~= CLICK_SCRIPTED then
value = tonumber(value)
if value then
memory.write_float(addr, value)
end
end
end, default_value)
end
local CAmmoInfo = WeaponAttribute.CAmmoInfo(CWeaponInfo)
if CAmmoInfo ~= 0 then
menu.divider(menu_list, "RocketInfo")
for name, item in pairs(WeaponAttribute.RocketInfo) do
local addr = CAmmoInfo + item.offset
local default_value = memory.read_float(addr)
menu.text_input(menu_list, name,
{ "weapon_attr" .. WeaponAttribute.Index .. name },
"", function(value, click_type)
if click_type ~= CLICK_SCRIPTED then
value = tonumber(value)
if value then
memory.write_float(addr, value)
end
end
end, default_value)
end
end
local CHomingRocketParams = WeaponAttribute.CHomingRocketParams(CAmmoInfo)
if CHomingRocketParams ~= 0 then
menu.divider(menu_list, "HomingRocketParams")
for name, item in pairs(WeaponAttribute.HomingParam) do
local addr = CHomingRocketParams + item.offset
local default_value = 0
if item.type == "float" then
default_value = memory.read_float(addr)
elseif item.type == "byte" then
default_value = memory.read_byte(addr)
end
menu.text_input(menu_list, name,
{ "weapon_attr" .. WeaponAttribute.Index .. name },
"", function(value, click_type)
if click_type ~= CLICK_SCRIPTED then
value = tonumber(value)
if value then
if item.type == "float" then
memory.write_float(addr, value)
elseif item.type == "byte" then
memory.write_byte(addr, value)
end
end
end
end, default_value)
end
end
-- Index
WeaponAttribute.Index = WeaponAttribute.Index + 1
end
function WeaponAttribute.Persets.Apply(CWeaponInfo, dataList)
if CWeaponInfo == 0 then return false end
local CAmmoInfo = WeaponAttribute.CAmmoInfo(CWeaponInfo)
local CHomingRocketParams = WeaponAttribute.CHomingRocketParams(CAmmoInfo)
for _, item in pairs(dataList) do
local name = item[1]
local value = item[2]
local is_override = item[3]
local info = WeaponAttribute.BaseInfo[name]
if info then
WeaponAttribute.SetAttribute(CWeaponInfo + info.offset, value, info.type, not is_override)
goto continue
end
if CAmmoInfo == 0 then
goto continue
end
info = WeaponAttribute.RocketInfo[name]
if info then
WeaponAttribute.SetAttribute(CAmmoInfo + info.offset, value, info.type, not is_override)
goto continue
end
if CHomingRocketParams == 0 then
goto continue
end
info = WeaponAttribute.HomingParam[name]
if info then
WeaponAttribute.SetAttribute(CHomingRocketParams + info.offset, value, info.type, not is_override)
goto continue
end
::continue::
end
end
menu.textslider_stateful(Weapon_Attributes, "读取当前武器属性", {}, "", {
"仅通知", "通知并保存到日志"
}, function(value)
local CWeaponInfo = WeaponAttribute.CWeaponInfo()
if CWeaponInfo ~= 0 then
local weaponHash = get_ped_current_weapon(players.user_ped())
local weaponName = WeaponAttribute.GetWeaponName(weaponHash)
local text = WeaponAttribute.GetAttributes(CWeaponInfo, weaponName)
util.toast(text)
if value == 2 then
util.log("\n" .. text)
end
else
util.toast("不支持近战武器")
end
end)
menu.action(Weapon_Attributes, "编辑当前武器属性", {}, "", function()
local CWeaponInfo = WeaponAttribute.CWeaponInfo()
if CWeaponInfo ~= 0 then
local weapon_hash = get_ped_current_weapon(players.user_ped())
WeaponAttribute.StoreBackup(CWeaponInfo, weapon_hash)
else
util.toast("不支持近战武器")
end
end)
menu.divider(Weapon_Attributes, "预设属性")
for _, item in pairs(WeaponAttribute.Persets.ItemList) do
menu.action(Weapon_Attributes, item.menu_name, {}, item.help_text, function()
local CWeaponInfo = WeaponAttribute.CWeaponInfo()
if CWeaponInfo ~= 0 then
local weapon_hash, weapon_type = get_ped_current_weapon(players.user_ped())
if item.weapon_type == 3 or weapon_type == item.weapon_type then
WeaponAttribute.StoreBackup(CWeaponInfo, weapon_hash)
if WeaponAttribute.Persets.Apply(CWeaponInfo, item.data_list) then
local weapon_name = WeaponAttribute.GetWeaponName(weapon_hash)
util.toast("武器: " .. weapon_name .. "\n预设属性修改完成")
end
end
end
end)
end
menu.divider(Weapon_Attributes, "保存的武器列表")
--#endregion Weapon Attributes
--#region Weapon Cam Gun
local Weapon_CamGun <const> = menu.list(Weapon_Options, "视野工具枪", {}, "玩家镜头中心的位置")
local CamGun = {
select = 1,
}
menu.toggle_loop(Weapon_CamGun, "开启[按住E键]", { "cam_gun" }, "", function()
Loop_Handler.draw_centred_point(true)
if PAD.IS_CONTROL_PRESSED(0, 51) then
if CamGun.select == 1 then
CamGun.Shoot()
elseif CamGun.select == 2 then
CamGun.Explosion()
elseif CamGun.select == 3 then
CamGun.Fire()
end
end
end, function()
Loop_Handler.draw_centred_point(false)
end)
menu.list_select(Weapon_CamGun, "选择操作", { "cam_gun_select" }, "", {
{ 1, "射击", { "shoot" }, "" },
{ 2, "爆炸", { "explosion" }, "" },
{ 3, "燃烧", { "fire" }, "" },
}, 1, function(value)
CamGun.select = value
end)
menu.divider(Weapon_CamGun, "设置")
--#region Cam Gun Shoot
----------------
-- Shoot
----------------
local CamGun_ShootSetting <const> = menu.list(Weapon_CamGun, "射击", {}, "")
CamGun.ShootSetting = {
shootMethod = 1,
delay = 100,
weaponSelect = 1,
weaponHash = "PLAYER_CURRENT_WEAPON",
vehicleWeaponHash = "VEHICLE_CURRENT_WEAPON",
isOwned = false,
damage = 1000,
speed = 2000,
perfectAccuracy = true,
createTraceVfx = true,
allowRumble = true,
startFromPlayer = false,
offset = v3(0, 0, 2.0),
}
function CamGun.ShootPos(pos, action)
local user_ped = players.user_ped()
local start_pos = v3.new()
if CamGun.ShootSetting.startFromPlayer then
local player_pos = ENTITY.GET_ENTITY_COORDS(user_ped)
start_pos = v3.add(player_pos, CamGun.ShootSetting.offset)
else
start_pos = v3.add(pos, CamGun.ShootSetting.offset)
end
if action == "drawline" then
DRAW_LINE(start_pos, pos)
else
local weaponHash = CamGun.ShootSetting.weaponHash
if CamGun.ShootSetting.weaponSelect == 2 then
weaponHash = CamGun.ShootSetting.vehicleWeaponHash
end
if weaponHash == "PLAYER_CURRENT_WEAPON" then
weaponHash = WEAPON.GET_SELECTED_PED_WEAPON(user_ped)
elseif weaponHash == "VEHICLE_CURRENT_WEAPON" then
local pWeapon = memory.alloc_int()
WEAPON.GET_CURRENT_PED_VEHICLE_WEAPON(user_ped, pWeapon)
weaponHash = memory.read_int(pWeapon)
end
if not WEAPON.HAS_WEAPON_ASSET_LOADED(weaponHash) then
request_weapon_asset(weaponHash)
end
local owner = 0
if CamGun.ShootSetting.isOwned then
owner = user_ped
end
local ignoreEntity = entities.get_user_vehicle_as_handle(false)
if ignoreEntity == INVALID_GUID then
ignoreEntity = user_ped
end
MISC.SHOOT_SINGLE_BULLET_BETWEEN_COORDS_IGNORE_ENTITY(
start_pos.x, start_pos.y, start_pos.z,
pos.x, pos.y, pos.z,
CamGun.ShootSetting.damage,
CamGun.ShootSetting.perfectAccuracy,
weaponHash,
owner,
CamGun.ShootSetting.createTraceVfx,
CamGun.ShootSetting.allowRumble,
CamGun.ShootSetting.speed,
ignoreEntity,
0)
end
end
function CamGun.Shoot()
local cam_pos
if CamGun.ShootSetting.shootMethod == 1 then
local result = get_raycast_result(1500, -1)
if result.didHit then
cam_pos = result.endCoords
end
elseif CamGun.ShootSetting.shootMethod == 2 then
cam_pos = get_offset_from_cam(1500)
end
if cam_pos ~= nil then