var easing = {
	lerp: function(a, b, percentage) {
		return a + (b - a) * percentage
	}
}

var anti_aimbot = {
	get_desync: function() {
	    var RealYaw = Local.GetRealYaw();
	    var FakeYaw = Local.GetFakeYaw();
	    var delta = Math.min(Math.abs(RealYaw - FakeYaw) / 2, 58).toFixed(1);

	    return delta
	}
}

Render.OutlineStringCustom = function(x, y, alignid, text, color, font) {
    Render.StringCustom(x - 1, y - 1, alignid, text, [0, 0, 0, color[3]], font);
    Render.StringCustom(x - 1, y, alignid, text, [0, 0, 0, color[3]], font); 

    Render.StringCustom(x - 1, y + 1, alignid, text, [0, 0, 0, color[3]], font);   
    Render.StringCustom(x, y + 1, alignid, text, [0, 0, 0, color[3]], font);

    Render.StringCustom(x, y - 1, alignid, text, [0, 0, 0, color[3]], font);
    Render.StringCustom(x + 1, y - 1, alignid, text, [0, 0, 0, color[3]], font);

    Render.StringCustom(x + 1, y, alignid, text, [0, 0, 0, color[3]], font);
    Render.StringCustom(x + 1, y + 1, alignid, text, [0, 0, 0, color[3]], font);

    Render.StringCustom(x, y, alignid, text, color, font);
}

var vars = {
	anim_x_stand: 0,
	anim_y_stand: 0,
	anim_alpha_stand: 0,
	anim_y_os: 0,
	anim_line: 0,
	anim_width_sp: 0,
	default_height: 65,
	default_width: 170
}

UI.AddColorPicker("Main color")

UI.AddSliderInt("Add x", -1000, 1000)
UI.AddSliderInt("Add y", -1000, 1000)

UI.AddCheckbox("Enable line")

UI.SetValue("Script Items", "Add x", -20)
UI.SetValue("Script Items", "Add y", 30)

UI.SetColor("Script Items", "Main color", [255, 255, 255, 255])

var render_holo_panel = function() {
	var local = Entity.GetLocalPlayer()

	var fonts = {
		verdana_7: Render.AddFont("Verdana", 7, 400),
		small_font: Render.AddFont("Small fonts", 5, 400)
	}

	var body_yaw = anti_aimbot.get_desync()

    var hitbox = Entity.GetHitboxPosition(local, 3)
    var world_stand = Render.WorldToScreen(hitbox)

    var color = UI.GetColor("Script Items", "Main color")
    var color_fake = [170 + (154 - 186) * body_yaw / 60 , 0 + (255 - 0) * body_yaw / 60 , 16 + (0 - 16) * body_yaw / 60 , 255]

    if (UI.IsHotkeyActive("Visuals", "World", "View", "Thirdperson")) {
	    vars.anim_x_stand = easing.lerp(vars.anim_x_stand, world_stand[0], Globals.Frametime() * 8)
	    vars.anim_y_stand = easing.lerp(vars.anim_y_stand, world_stand[1], Globals.Frametime() * 8)

	    vars.anim_alpha_stand = easing.lerp(vars.anim_alpha_stand, 1, Globals.Frametime() * 22)
    } else {
	    vars.anim_alpha_stand = easing.lerp(vars.anim_alpha_stand, 0, Globals.Frametime() * 22)

	    if (vars.anim_alpha_stand <= 0) {
		    anim_x_stand = 0
		    anim_y_stand = 0
		}
    }

    if (UI.IsHotkeyActive("Rage", "Exploits", "Doubletap")) {
		vars.default_height = easing.lerp(vars.default_height, 78, Globals.Frametime() * 8)
		vars.anim_y_os = easing.lerp(vars.anim_y_os, 0, Globals.Frametime() * 8)
		vars.anim_line = easing.lerp(vars.anim_line, 75, Globals.Frametime() * 8)
    } else {
		vars.default_height = easing.lerp(vars.default_height, 65, Globals.Frametime() * 8)
		vars.anim_y_os = easing.lerp(vars.anim_y_os, -15, Globals.Frametime() * 8)
		vars.anim_line = easing.lerp(vars.anim_line, 85, Globals.Frametime() * 8)
    }

    vars.anim_width_sp = easing.lerp(vars.anim_width_sp, (28 / 58) * body_yaw, Globals.Frametime() * 4)

	var add_y = UI.GetValue("Script Items", "Add y")
	var add_x = UI.GetValue("Script Items", "Add x")
	var add_line_x = 100

	if (add_x <= -280) {
		add_line_x = 100 + vars.default_width
	}

	Render.FilledRect(vars.anim_x_stand + 100 + add_x, vars.anim_y_stand - 150 + add_y, vars.default_width, vars.default_height, [15, 15, 15, 100 * vars.anim_alpha_stand])
	Render.FilledRect(vars.anim_x_stand + 100 + add_x, vars.anim_y_stand - 150 + add_y, vars.default_width, 2, [color[0], color[1], color[2], 255 * vars.anim_alpha_stand])

	if (UI.GetValue("Script Items", "Enable line")) {
		Render.Line(vars.anim_x_stand, vars.anim_y_stand, vars.anim_x_stand + add_line_x + add_x, vars.anim_y_stand - vars.anim_line + add_y, [255, 255, 255, 125 * vars.anim_alpha_stand]);
	}

    Render.OutlineStringCustom(vars.anim_x_stand + 107 + add_x, vars.anim_y_stand - 143 + add_y, 0, "ANTI-AIMBOT DEBUG", [255, 255, 255, 255 * vars.anim_alpha_stand], fonts.small_font)

    var dec = [ color_fake[0] - (color_fake[0] / 100 * 50), color_fake[1] - (color_fake[1] / 100 * 50), color_fake[2] - (color_fake[2] / 100 * 50) ]

    Render.GradientRect(vars.anim_x_stand + 107 + add_x, vars.anim_y_stand - 125 + add_y - 4, 2, 18 / 2, 0, [dec[0], dec[1], dec[2], 0 * vars.anim_alpha_stand], [color_fake[0], color_fake[1], color_fake[2], 255 * vars.anim_alpha_stand]);
    Render.GradientRect(vars.anim_x_stand + 107 + add_x, vars.anim_y_stand - 125 + add_y + 18 / 2 - 4, 2, 18 / 2, 0, [color_fake[0], color_fake[1], color_fake[2], 255 * vars.anim_alpha_stand], [dec[0], dec[1], dec[2], 0 * vars.anim_alpha_stand]);

    var f_text = "FAKE (" + body_yaw.toString() + ")"
    Render.StringCustom(vars.anim_x_stand + 115 + add_x, vars.anim_y_stand - 122 + add_y - 5, 0, f_text, [255, 255, 255, 255 * vars.anim_alpha_stand], fonts.verdana_7);

    Render.OutlineStringCustom(vars.anim_x_stand + 107 + add_x, vars.anim_y_stand - 102 + add_y, 0, "SP:", [255, 255, 255, 255 * vars.anim_alpha_stand], fonts.small_font)

    Render.FilledRect(vars.anim_x_stand + 123 + add_x, vars.anim_y_stand - 102 + add_y + 2, 28, 7, [15, 15, 15, 100 * vars.anim_alpha_stand])
    Render.FilledRect(vars.anim_x_stand + 123 + 28 + 5 + add_x, vars.anim_y_stand - 102 + add_y + 2, 28, 7, [15, 15, 15, 100 * vars.anim_alpha_stand])

    if (Local.GetRealYaw() - Local.GetFakeYaw() > 0) {
        Render.FilledRect(vars.anim_x_stand + 123 + add_x, vars.anim_y_stand - 102 + add_y + 2, vars.anim_width_sp, 7, [color[0], color[1], color[2], 255 * vars.anim_alpha_stand])
    } else if (Local.GetRealYaw() - Local.GetFakeYaw() < 0){
        Render.FilledRect(vars.anim_x_stand + 123 + 28 + 5 + add_x, vars.anim_y_stand - 102 + 2 + add_y, vars.anim_width_sp, 7, [color[0], color[1], color[2], 255 * vars.anim_alpha_stand])
    }

    var realtime = Globals.Realtime() % 3
    var alpha = Math.floor(Math.sin(realtime * 4) * (255 / 2 - 1) + 255 / 2)

    if (UI.IsHotkeyActive("Rage", "Exploits", "Doubletap")) {
    	Render.OutlineStringCustom(vars.anim_x_stand + 107 + add_x, vars.anim_y_stand - 88 + add_y, 0, "SHIFTING TICKBASE", [255, 255, 255, alpha * vars.anim_alpha_stand], fonts.small_font)
    }

    var state_os = "OFF"
    var os_color = [255, 0, 0, 255]

    if (UI.IsHotkeyActive("Rage", "Exploits", "Hide shots")) {
    	state_os = "ON"
    	os_color = [0, 255, 0, 255]
    }

    Render.OutlineStringCustom(vars.anim_x_stand + 100 + vars.default_width - 13 - Render.TextSizeCustom(state_os, fonts.small_font)[0] / 2 + add_x, vars.anim_y_stand - 88 + vars.anim_y_os + add_y, 0, state_os, [os_color[0], os_color[1], os_color[2], 255 * vars.anim_alpha_stand], fonts.small_font)
    Render.OutlineStringCustom(vars.anim_x_stand + 100 + vars.default_width - 13 - Render.TextSizeCustom(state_os, fonts.small_font)[0] / 2 - 24 + add_x, vars.anim_y_stand - 88 + vars.anim_y_os + add_y, 0, "OSAA:", [255, 255, 255, 255 * vars.anim_alpha_stand], fonts.small_font)
}
Cheat.RegisterCallback("Draw", "render_holo_panel")