· 6 years ago · Nov 27, 2019, 04:26 PM
1-- ######
2-- LOCAL VARIABLES FOR LUA API
3-- Generated using https://github.com/sapphyrus/gamesense-lua/blob/master/generate_api.lua
4-- #####
5local client_userid_to_entindex, client_set_event_callback, client_screen_size, client_trace_bullet, client_unix_time, client_color_log, client_reload_active_scripts, client_scale_damage, client_get_cvar, client_key_state, client_create_interface, client_random_int, client_latency, client_set_clan_tag, client_find_signature, client_log, client_timestamp, client_trace_line, client_random_float, client_draw_debug_text, client_visible, client_exec, client_error_log, client_set_cvar, client_camera_position, client_draw_hitboxes, client_eye_position, client_update_player_list, client_camera_angles, client_delay_call, client_unset_event_callback, client_system_time = client.userid_to_entindex, client.set_event_callback, client.screen_size, client.trace_bullet, client.unix_time, client.color_log, client.reload_active_scripts, client.scale_damage, client.get_cvar, client.key_state, client.create_interface, client.random_int, client.latency, client.set_clan_tag, client.find_signature, client.log, client.timestamp, client.trace_line, client.random_float, client.draw_debug_text, client.visible, client.exec, client.error_log, client.set_cvar, client.camera_position, client.draw_hitboxes, client.eye_position, client.update_player_list, client.camera_angles, client.delay_call, client.unset_event_callback, client.system_time
6local entity_get_player_resource, entity_get_local_player, entity_is_enemy, entity_get_bounding_box, entity_is_dormant, entity_get_steam64, entity_get_player_name, entity_hitbox_position, entity_get_game_rules, entity_get_all, entity_set_prop, entity_is_alive, entity_get_player_weapon, entity_get_prop, entity_get_players, entity_get_classname = entity.get_player_resource, entity.get_local_player, entity.is_enemy, entity.get_bounding_box, entity.is_dormant, entity.get_steam64, entity.get_player_name, entity.hitbox_position, entity.get_game_rules, entity.get_all, entity.set_prop, entity.is_alive, entity.get_player_weapon, entity.get_prop, entity.get_players, entity.get_classname
7local globals_realtime, globals_absoluteframetime, globals_chokedcommands, globals_oldcommandack, globals_tickcount, globals_commandack, globals_lastoutgoingcommand, globals_curtime, globals_mapname, globals_tickinterval, globals_framecount, globals_frametime, globals_maxplayers = globals.realtime, globals.absoluteframetime, globals.chokedcommands, globals.oldcommandack, globals.tickcount, globals.commandack, globals.lastoutgoingcommand, globals.curtime, globals.mapname, globals.tickinterval, globals.framecount, globals.frametime, globals.maxplayers
8local ui_new_slider, ui_new_combobox, ui_reference, ui_set_visible, ui_new_textbox, ui_new_color_picker, ui_new_checkbox, ui_mouse_position, ui_new_listbox, ui_new_multiselect, ui_is_menu_open, ui_new_hotkey, ui_set, ui_name, ui_set_callback, ui_new_button, ui_new_label, ui_new_string, ui_get = ui.new_slider, ui.new_combobox, ui.reference, ui.set_visible, ui.new_textbox, ui.new_color_picker, ui.new_checkbox, ui.mouse_position, ui.new_listbox, ui.new_multiselect, ui.is_menu_open, ui.new_hotkey, ui.set, ui.name, ui.set_callback, ui.new_button, ui.new_label, ui.new_string, ui.get
9local renderer_get_text_size, renderer_load_svg, renderer_draw_localized_text, renderer_circle_outline, renderer_rectangle, renderer_world_to_screen, renderer_lock_cursor, renderer_unlock_cursor, renderer_line, renderer_get_mouse_pos, renderer_set_mouse_pos, renderer_localize_string, renderer_draw_outlined_rect, renderer_draw_text, renderer_draw_poly_line, renderer_texture, renderer_load_png, renderer_draw_filled_gradient_rect, renderer_indicator, renderer_create_font, renderer_test_font, renderer_gradient, renderer_circle, renderer_text, renderer_draw_line, renderer_draw_filled_rect, renderer_draw_filled_outlined_rect, renderer_triangle, renderer_measure_text, renderer_load_texture, renderer_draw_outlined_circle, renderer_load_jpg = renderer.get_text_size, renderer.load_svg, renderer.draw_localized_text, renderer.circle_outline, renderer.rectangle, renderer.world_to_screen, renderer.lock_cursor, renderer.unlock_cursor, renderer.line, renderer.get_mouse_pos, renderer.set_mouse_pos, renderer.localize_string, renderer.draw_outlined_rect, renderer.draw_text, renderer.draw_poly_line, renderer.texture, renderer.load_png, renderer.draw_filled_gradient_rect, renderer.indicator, renderer.create_font, renderer.test_font, renderer.gradient, renderer.circle, renderer.text, renderer.draw_line, renderer.draw_filled_rect, renderer.draw_filled_outlined_rect, renderer.triangle, renderer.measure_text, renderer.load_texture, renderer.draw_outlined_circle, renderer.load_jpg
10local math_ceil, math_tan, math_cos, math_sinh, math_pi, math_max, math_atan2, math_floor, math_sqrt, math_deg, math_atan, math_fmod, math_acos, math_pow, math_abs, math_min, math_sin, math_log, math_exp, math_cosh, math_asin, math_rad = math.ceil, math.tan, math.cos, math.sinh, math.pi, math.max, math.atan2, math.floor, math.sqrt, math.deg, math.atan, math.fmod, math.acos, math.pow, math.abs, math.min, math.sin, math.log, math.exp, math.cosh, math.asin, math.rad
11local table_sort, table_remove, table_concat, table_insert = table.sort, table.remove, table.concat, table.insert
12local string_find, string_format, string_gsub, string_len, string_gmatch, string_match, string_reverse, string_upper, string_lower, string_sub = string.find, string.format, string.gsub, string.len, string.gmatch, string.match, string.reverse, string.upper, string.lower, string.sub
13local materialsystem_chams_material, materialsystem_arms_material, materialsystem_find_texture, materialsystem_find_material, materialsystem_override_material, materialsystem_find_materials, materialsystem_get_model_materials = materialsystem.chams_material, materialsystem.arms_material, materialsystem.find_texture, materialsystem.find_material, materialsystem.override_material, materialsystem.find_materials, materialsystem.get_model_materials
14local ipairs, assert, pairs, next, tostring, tonumber, setmetatable, unpack, type, getmetatable, pcall, error = ipairs, assert, pairs, next, tostring, tonumber, setmetatable, unpack, type, getmetatable, pcall, error
15-- #####
16-- END OF LOCAL VARIABLES
17-- #####
18
19--------------------------------------------------------------------------------
20-- Constants and variables
21--------------------------------------------------------------------------------
22local enable_ref
23local config_ref
24local label_ref
25-- local config_ref_visible = true
26
27-- Array of aimbot references
28-- references[IDX_BUILTIN] is an array of references to the built-in menu items
29-- references[IDX_GLOBAL] is an array of references to the global config
30local references = {}
31local IDX_BUILTIN = 1
32local IDX_GLOBAL = 2
33
34local config_idx_to_name = {}
35local config_name_to_idx = {}
36local weapon_id_to_config_idx = {}
37
38-- Active weapon config is managed by the script when the local player is alive
39-- Active weapon config is managed by the user (via the menu) while the local player is dead
40local active_config_idx = nil
41
42local SPECATOR_TEAM_ID = 1
43
44--------------------------------------------------------------------------------
45-- Utility functions
46--------------------------------------------------------------------------------
47local function copy_settings(config_idx_src, config_idx_dst)
48 local src_refs = references[config_idx_src]
49 local dst_refs = references[config_idx_dst]
50 for i=1, #dst_refs do
51 ui.set(dst_refs[i], ui.get(src_refs[i]))
52 end
53end
54
55local function load_config(config_idx)
56 if active_config_idx ~= config_idx then
57 active_config_idx = config_idx
58 copy_settings(config_idx, IDX_BUILTIN)
59 ui.set(label_ref, "Active weapon config: " .. config_idx_to_name[config_idx])
60 end
61end
62
63local function update_config_visibility(state)
64 local display_config = state
65 local script_state = ui.get(enable_ref)
66 if display_config == nil then
67 display_config = entity.is_alive(entity.get_local_player()) == false
68 end
69 local display_label = not display_config
70 -- config_ref_visible = display_config
71 ui.set_visible(config_ref, display_config and script_state)
72 ui.set_visible(label_ref, display_label and script_state)
73 return display_config
74end
75
76local function save_reference(config_idx, setting_idx, ref)
77 references[config_idx][setting_idx] = ref
78 return ref
79end
80
81local function bind(func, ...)
82 local args = {...}
83 return function(ref)
84 func(ref, unpack(args))
85 end
86end
87
88local function delayed_bind(func, delay, ...)
89 local args = {...}
90 return function(ref)
91 client.delay_call(delay, func, ref, unpack(args))
92 end
93end
94
95-- Temporary function for enabling config in the menu
96local function temp_task()
97 update_config_visibility()
98 client.delay_call(5, temp_task)
99end
100--------------------------------------------------------------------------------
101-- Callback functions
102--------------------------------------------------------------------------------
103local function on_setup_command()
104 local local_player = entity.get_local_player()
105 -- Get the local players weapon so we can find its item definition index
106 local weapon = entity.get_player_weapon(local_player)
107 -- Get the weapons item definition and toggle off the 16th bit to get the real item def index
108 local weapon_id = bit.band(entity.get_prop(weapon, "m_iItemDefinitionIndex"), 0xFFFF)
109 -- Use the weapon_id_to_config_idx lookup table to get the new config index and attempt to load the config
110 load_config(weapon_id_to_config_idx[weapon_id] or IDX_GLOBAL)
111end
112
113local function on_player_death(e)
114 if client.userid_to_entindex(e.userid) == entity.get_local_player() then
115 update_config_visibility(true)
116 end
117end
118
119local function on_player_spawn(e)
120 if client.userid_to_entindex(e.userid) == entity.get_local_player() then
121 update_config_visibility(false)
122 end
123end
124
125local function on_player_team_change(e)
126 if client.userid_to_entindex(e.userid) == entity.get_local_player() then
127 -- Check if the team the local player switched to is spectator(1)
128 if e.team == SPECATOR_TEAM_ID then
129 update_config_visibility(true)
130 end
131 end
132end
133
134local function on_game_disconnect(e)
135 update_config_visibility(true)
136end
137
138-- Called when a user selects a different weapon config with the combobox
139local function on_weapon_config_selected(ref)
140 -- If the local player is alive then do nothing and hide this combobox
141 if update_config_visibility() == false then
142 -- This should never happen
143 -- client.error_log("Weapon config selected while local player is alive!")
144 return
145 end
146
147 -- Load settings from the selected weapon config
148 local config_name = ui.get(ref)
149 local config_idx = config_name_to_idx[config_name]
150 load_config(config_idx)
151end
152
153-- Called when a user changes the value of a built-in menu item (e.g. checking "Automatic penetrationn")
154-- Also called when a config is loaded
155local function on_builtin_setting_change(ref, setting_idx)
156 -- Propagate built-in setting changes to the adaptive settings
157 if active_config_idx ~= nil and ui.get(enable_ref) == true then
158 ui.set(references[active_config_idx][setting_idx], ui.get(ref))
159 end
160end
161
162-- Called when a user changes the value of a weapon configs menu item (e.g. checking "Global automatic penetration")
163-- Also called when a config is loaded
164local function on_adaptive_setting_changed(ref, config_idx, setting_idx)
165 -- Propagate adaptive setting changes to the built-in settings
166 if config_idx == active_config_idx and ui.get(enable_ref) == true then
167 ui.set(references[IDX_BUILTIN][setting_idx], ui.get(ref))
168 end
169end
170
171-- Called when a user toggles the main script checkbox
172-- Also called on script load
173local function on_adaptive_config_toggled(ref)
174 local script_state = ui.get(ref)
175 -- Update the configs visibility when the script is toggled
176 update_config_visibility()
177 -- Set / unset event callbacks based on the state of the script so that we aren't just invoking callbacks for no reason
178 local update_callback = script_state and client.set_event_callback or client.unset_event_callback
179 update_callback("setup_command", on_setup_command)
180 update_callback("player_death", on_player_death)
181 update_callback("player_spawn", on_player_spawn)
182 update_callback("player_team", on_player_team_change)
183 update_callback("cs_game_disconnected", on_game_disconnect)
184end
185
186--------------------------------------------------------------------------------
187-- Initialization code
188--------------------------------------------------------------------------------
189local function duplicate(tab, container, name, ui_func, ...)
190 -- This menu item will have the same index across all weapon configs
191 local setting_index = #references[IDX_BUILTIN] + 1
192 -- Create hidden menu items to store values
193 for i=IDX_GLOBAL, #references do
194 local config_name = config_idx_to_name[i]
195 -- Create a duplicate menu item to store settings that can be copied later
196 local ref = save_reference(i, setting_index, ui_func(tab, container, config_name .. " " .. name:lower(), ...))
197 -- Set a default value for the target hitbox as this multiselect cannot be empty
198 if name == "Target hitbox" then
199 ui.set(ref, {"Head"})
200 end
201 ui.set_visible(ref, false)
202 ui.set_callback(ref, bind(on_adaptive_setting_changed, i, setting_index))
203 end
204 local ref = save_reference(IDX_BUILTIN, setting_index, ui.reference(tab, container, name))
205 -- Set a callback on the built-in menu items so that settings are not overwritten whenever we are loading a new config
206 ui.set_callback(ref, delayed_bind(on_builtin_setting_change, 0.01, setting_index))
207end
208
209local function init_config(name, ...)
210 local config_idx = #references + 1
211 references[config_idx] = {}
212 config_idx_to_name[config_idx] = name
213 config_name_to_idx[name] = config_idx
214 -- Populate the weapon_id_to_config_idx lookup table so we can easily get a configs index from a weapon id
215 for _, weapon_id in ipairs({...}) do
216 weapon_id_to_config_idx[weapon_id] = config_idx
217 end
218 return config_idx
219end
220
221local function init()
222 IDX_BUILTIN = init_config("Built-in menu items")
223 init_config("Global")
224 init_config("Auto", 11, 38)
225 init_config("Awp", 9)
226 init_config("Scout", 40)
227 init_config("Desert Eagle", 1)
228 init_config("Revolver", 64)
229 init_config("Pistol", 2, 3, 4, 30, 32, 36, 61, 63)
230 init_config("Rifle", 7, 8, 10, 13, 16, 39, 60)
231 -- init_config("Submachine gun", 17, 19, 23, 24, 26, 33, 34)
232 -- init_config("Machine gun", 14, 28)
233 -- init_config("Shotgun", 25, 27, 29, 35)
234
235 assert(config_idx_to_name[IDX_GLOBAL] == "Global")
236
237 enable_ref = ui.new_checkbox("RAGE", "Other", "Adaptive config")
238 config_ref = ui.new_combobox("RAGE", "Other", "\nAdaptive config", config_idx_to_name)
239 label_ref = ui.new_label("RAGE", "Other", "Active weapon config: " .. ui.get(config_ref))
240
241 duplicate("RAGE", "Aimbot", "Target selection", ui.new_combobox, "Cycle", "Cycle (2x)", "Near crosshair", "Highest damage", "Lowest ping", "Best K/D ratio", "Best hit chance")
242 duplicate("RAGE", "Aimbot", "Target hitbox", ui.new_multiselect, "Head", "Chest", "Stomach", "Arms", "Legs", "Feet")
243 duplicate("RAGE", "Aimbot", "Avoid limbs if moving", ui.new_checkbox)
244 duplicate("RAGE", "Aimbot", "Avoid head if jumping", ui.new_checkbox)
245 duplicate("RAGE", "Aimbot", "Multi-point", ui.new_multiselect, "Head", "Chest", "Stomach", "Arms", "Legs", "Feet")
246 duplicate("RAGE", "Aimbot", "Multi-point scale", ui.new_slider, 24, 100, 24, true, "%", 1, multipoint_override)
247 duplicate("RAGE", "Aimbot", "Dynamic multi-point", ui.new_checkbox)
248 duplicate("RAGE", "Aimbot", "Prefer safe point", ui.new_checkbox)
249 duplicate("RAGE", "Aimbot", "Automatic fire", ui.new_checkbox)
250 duplicate("RAGE", "Aimbot", "Automatic penetration", ui.new_checkbox)
251 duplicate("RAGE", "Aimbot", "Silent aim", ui.new_checkbox)
252 duplicate("RAGE", "Aimbot", "Minimum hit chance", ui.new_slider, 0, 100, 50, true, "%", 1, hitchance_override)
253 duplicate("RAGE", "Aimbot", "Minimum damage", ui.new_slider, 0, 126, 0, true, "%", 1, mindamage_override)
254 duplicate("RAGE", "Aimbot", "Automatic scope", ui.new_checkbox)
255 duplicate("RAGE", "Aimbot", "Maximum FOV", ui.new_slider, 1, 180, 180, true, "°")
256 duplicate("RAGE", "Aimbot", "Extra minimum damage", ui.new_checkbox)
257 duplicate("RAGE", "Aimbot", "Minimum damage indicator", ui.new_checkbox)
258 duplicate("RAGE", "Aimbot", "Visible minimum damage", ui.new_checkbox)
259 duplicate("RAGE", "Aimbot", "- Minimum damage visible", ui.new_slider, 0, 126, 0, true, "", 1, mindamage_override)
260 duplicate("RAGE", "Aimbot", "- Minimum damage on key", ui.new_slider, 0, 126, 0, true, "", 1, mindamage_override)
261 duplicate("RAGE", "Other", "Accuracy boost", ui.new_combobox, "Off", "Low", "Medium", "High", "Maximum")
262 duplicate("RAGE", "Other", "Accuracy boost options", ui.new_multiselect, "Refine shot", "Extended backtrack")
263 duplicate("RAGE", "Other", "Quick stop", ui.new_checkbox)
264 duplicate("RAGE", "Other", "Quick stop options", ui.new_multiselect, "Early", "Slow motion", "Duck", "Move between shots", "Ignore molotov")
265 duplicate("RAGE", "Other", "Prefer body aim", ui.new_checkbox)
266 duplicate("RAGE", "Other", "Prefer body aim disablers", ui.new_multiselect, "Low inaccuracy", "Target shot fired", "Target resolved", "Safe point headshot", "Low damage")
267 duplicate("RAGE", "Other", "Delay shot on peek", ui.new_checkbox)
268
269 ui.set_callback(config_ref, on_weapon_config_selected)
270 ui.set_callback(enable_ref, on_adaptive_config_toggled)
271
272 temp_task()
273 on_adaptive_config_toggled(enable_ref)
274end
275
276init()