forked from sapphyrus/gamesense-lua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaspect_ratio.lua
74 lines (61 loc) · 5.73 KB
/
aspect_ratio.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
--local variables for API functions. Generated using https://github.com/sapphyrus/gamesense-lua/blob/master/generate_api.lua
local client_latency, client_set_clan_tag, client_log, client_timestamp, client_userid_to_entindex, client_trace_line, client_set_event_callback, client_screen_size, client_trace_bullet, client_color_log, client_system_time, client_delay_call, client_visible, client_exec, client_eye_position, client_set_cvar, client_scale_damage, client_draw_hitboxes, client_get_cvar, client_camera_angles, client_draw_debug_text, client_random_int, client_random_float = client.latency, client.set_clan_tag, client.log, client.timestamp, client.userid_to_entindex, client.trace_line, client.set_event_callback, client.screen_size, client.trace_bullet, client.color_log, client.system_time, client.delay_call, client.visible, client.exec, client.eye_position, client.set_cvar, client.scale_damage, client.draw_hitboxes, client.get_cvar, client.camera_angles, client.draw_debug_text, client.random_int, client.random_float
local 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
local globals_realtime, globals_absoluteframetime, globals_tickcount, globals_lastoutgoingcommand, globals_curtime, globals_mapname, globals_tickinterval, globals_framecount, globals_frametime, globals_maxplayers = globals.realtime, globals.absoluteframetime, globals.tickcount, globals.lastoutgoingcommand, globals.curtime, globals.mapname, globals.tickinterval, globals.framecount, globals.frametime, globals.maxplayers
local ui_new_slider, ui_new_combobox, ui_reference, ui_is_menu_open, ui_set_visible, ui_new_textbox, ui_new_color_picker, ui_set_callback, ui_set, ui_new_checkbox, ui_new_hotkey, ui_new_button, ui_new_multiselect, ui_get = ui.new_slider, ui.new_combobox, ui.reference, ui.is_menu_open, ui.set_visible, ui.new_textbox, ui.new_color_picker, ui.set_callback, ui.set, ui.new_checkbox, ui.new_hotkey, ui.new_button, ui.new_multiselect, ui.get
local renderer_circle_outline, renderer_rectangle, renderer_gradient, renderer_circle, renderer_text, renderer_line, renderer_measure_text, renderer_indicator, renderer_world_to_screen = renderer.circle_outline, renderer.rectangle, renderer.gradient, renderer.circle, renderer.text, renderer.line, renderer.measure_text, renderer.indicator, renderer.world_to_screen
local 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
local table_sort, table_remove, table_concat, table_insert = table.sort, table.remove, table.concat, table.insert
local 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
local ipairs, assert, pairs, next, tostring, tonumber, setmetatable, unpack, type, getmetatable, pcall, error = ipairs, assert, pairs, next, tostring, tonumber, setmetatable, unpack, type, getmetatable, pcall, error
--end of local variables
local function set_aspect_ratio(aspect_ratio_multiplier)
local screen_width, screen_height = client_screen_size()
local aspectratio_value = (screen_width*aspect_ratio_multiplier)/screen_height
if aspect_ratio_multiplier == 1 then
aspectratio_value = 0
end
client_set_cvar("r_aspectratio", tonumber(aspectratio_value))
end
local function noop()
end
--greatest common divisor
local function gcd(m, n)
while m ~= 0 do
m, n = math_fmod(n, m), m
end
return n
end
local screen_width, screen_height, aspect_ratio_reference
local function on_aspect_ratio_changed()
local aspect_ratio = ui_get(aspect_ratio_reference)*0.01
aspect_ratio = 2 - aspect_ratio
set_aspect_ratio(aspect_ratio)
end
local multiplier = 0.01
local steps = 200
local function setup(screen_width_temp, screen_height_temp)
screen_width, screen_height = screen_width_temp, screen_height_temp
local aspect_ratio_table = {}
for i=1, steps do
local i2=(steps-i)*multiplier
local divisor = gcd(screen_width*i2, screen_height)
if screen_width*i2/divisor < 100 or i2 == 1 then
aspect_ratio_table[i] = screen_width*i2/divisor .. ":" .. screen_height/divisor
end
end
if aspect_ratio_reference ~= nil then
ui_set_visible(aspect_ratio_reference, false)
ui_set_callback(aspect_ratio_reference, noop)
end
aspect_ratio_reference = ui.new_slider("VISUALS", "Effects", "Force aspect ratio", 0, steps-1, steps/2, true, "%", 1, aspect_ratio_table)
ui_set_callback(aspect_ratio_reference, on_aspect_ratio_changed)
end
setup(client_screen_size())
local function on_paint(ctx)
local screen_width_temp, screen_height_temp = client_screen_size()
if screen_width_temp ~= screen_width or screen_height_temp ~= screen_height then
setup(screen_width_temp, screen_height_temp)
end
end
client.set_event_callback("paint", on_paint)