-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch_cs2.sh
More file actions
executable file
·133 lines (112 loc) · 5.01 KB
/
launch_cs2.sh
File metadata and controls
executable file
·133 lines (112 loc) · 5.01 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
#!/bin/sh
SILENT_MODE=true
NOTIFICATIONS=false
TARGET_RESOLUTION="1280x960"
TARGET_REFRESH_RATE=165
TARGET_SCALE_MODE="Default" # Options: Full, Aspect, Center, Default
TARGET_FILTER="Default" # Options: nearest, bilinear, Default
GAME_PROCESS_NAME="cs2"
APP_ID=730
WIDTH=$(echo "$TARGET_RESOLUTION" | cut -d'x' -f1)
HEIGHT=$(echo "$TARGET_RESOLUTION" | cut -d'x' -f2)
LAUNCH_OPTIONS="-novid -nojoy -high -console -noaafonts -nosync -noipx -freq $TARGET_REFRESH_RATE -refresh $TARGET_REFRESH_RATE -w $WIDTH -h $HEIGHT -fullscreen +fps_max $TARGET_REFRESH_RATE -forcenovsync"
send_notification() {
if [ "$NOTIFICATIONS" = true ]; then
notify-send "Game Notification" "$1" --icon=dialog-information
fi
}
SESSION_TYPE="Unknown"
if [ "$XDG_SESSION_TYPE" = "wayland" ]; then
if pgrep -x "Hyprland" > /dev/null; then
SESSION_TYPE="Wayland_Hyprland"
echo "Hyprland (Wayland) is in use."
if command -v notify-send >/dev/null 2>&1; then
NOTIFICATIONS=true
fi
elif pgrep -x "sway" > /dev/null; then
SESSION_TYPE="Wayland_Sway"
echo "Sway (Wayland) is in use."
else
echo "Wayland is in use, but not Hyprland or Sway. Not supported environment."
exit 1
fi
elif [ -n "$DISPLAY" ]; then
SESSION_TYPE="X11"
echo "X11 is in use."
if command -v notify-send >/dev/null 2>&1; then
NOTIFICATIONS=true
fi
else
echo "Not supported environment."
exit 1
fi
echo "Session type: $SESSION_TYPE"
send_notification "CS2 is starting!"
if [ "$SILENT_MODE" = true ]; then
echo "Launching Steam in silent mode..."
steam -silent -vgui -applaunch $APP_ID $LAUNCH_OPTIONS > /dev/null 2>&1 &
else
echo "Launching Steam with logging..."
steam -silent -vgui -applaunch $APP_ID $LAUNCH_OPTIONS &
fi
while ! GAME_PID=$(pgrep -x "$GAME_PROCESS_NAME"); do
sleep 1
done
echo "CS2 process detected. Waiting for it to end..."
if [ "$SESSION_TYPE" = "Wayland_Sway" ]; then
DISP_OUT=$(swaymsg -t get_outputs | jq -r '.[] | select(.active == true) | .name')
CURRENT_RESOLUTION=$(swaymsg -t get_outputs | jq -r --arg DISP "$DISP_OUT" '.[] | select(.name == $DISP) | "\(.current_mode.width)x\(.current_mode.height)"')
echo "Adding custom mode $TARGET_RESOLUTION@$TARGET_REFRESH_RATE on $DISP_OUT..."
swaymsg -- output $DISP_OUT mode --custom $TARGET_RESOLUTION@$TARGET_REFRESH_RATE"Hz"
elif [ "$SESSION_TYPE" = "Wayland_Hyprland" ]; then
MONITOR_INFO=$(hyprctl monitors -j | jq -r '.[0]')
SELECTED_MONITOR=$(echo "$MONITOR_INFO" | jq -r '.name')
CURRENT_WIDTH=$(echo "$MONITOR_INFO" | jq -r '.width')
CURRENT_HEIGHT=$(echo "$MONITOR_INFO" | jq -r '.height')
CURRENT_REFRESH_RATE=$(echo "$MONITOR_INFO" | jq -r '.refreshRate')
CURRENT_RESOLUTION="${CURRENT_WIDTH}x${CURRENT_HEIGHT}"
echo "Selected monitor: $SELECTED_MONITOR"
echo "Current resolution: ${CURRENT_RESOLUTION}@${CURRENT_REFRESH_RATE}Hz"
echo "Setting ${TARGET_RESOLUTION}@${TARGET_REFRESH_RATE} on $SELECTED_MONITOR..."
hyprctl keyword monitor "${SELECTED_MONITOR},${TARGET_RESOLUTION}@${TARGET_REFRESH_RATE},0x0,1"
elif [ "$SESSION_TYPE" = "X11" ]; then
DISP_OUT=$(xrandr | grep " connected" | awk '{print $1}')
CURRENT_RESOLUTION=$(xrandr | grep -A1 "^$DISP_OUT connected" | tail -n1 | awk '{ print $1 }')
TARGET_MODE_NAME="${TARGET_RESOLUTION}_${TARGET_REFRESH_RATE}.00"
TARGET_MODELINE=$(cvt $(echo $TARGET_RESOLUTION | tr 'x' ' ') $TARGET_REFRESH_RATE.00 | grep "Modeline" | cut -d' ' -f3-)
if xrandr --verbose | grep -q "$TARGET_MODE_NAME"; then
echo "Mode $TARGET_MODE_NAME already exists."
else
echo "Adding custom mode $TARGET_RESOLUTION@$TARGET_REFRESH_RATE on $DISP_OUT..."
xrandr --newmode "$TARGET_MODE_NAME" $TARGET_MODELINE
xrandr --addmode $DISP_OUT "$TARGET_MODE_NAME"
fi
if [ "$TARGET_SCALE_MODE" != "Default" ]; then
echo "Setting scaling mode to $TARGET_SCALE_MODE on $DISP_OUT..."
xrandr --output $DISP_OUT --set "scaling mode" "$TARGET_SCALE_MODE"
else
echo "Scaling mode is set to Default. No changes made."
fi
if [ "$TARGET_FILTER" != "Default" ]; then
echo "Setting scaling filter to $TARGET_FILTER on $DISP_OUT..."
xrandr --output $DISP_OUT --filter "$TARGET_FILTER"
else
echo "Scaling filter is set to Default. No changes made."
fi
echo "Setting mode $TARGET_MODE_NAME on $DISP_OUT..."
xrandr --output $DISP_OUT --mode "$TARGET_MODE_NAME"
fi
while kill -0 "$GAME_PID" 2> /dev/null; do
sleep 10
done
echo "CS2 process has ended."
echo "Restoring original res $CURRENT_RESOLUTION on $DISP_OUT..."
if [ "$SESSION_TYPE" = "Wayland_Sway" ]; then
swaymsg -- output $DISP_OUT mode $CURRENT_RESOLUTION
elif [ "$SESSION_TYPE" = "Wayland_Hyprland" ]; then
hyprctl keyword monitor "${SELECTED_MONITOR},${CURRENT_RESOLUTION}@${CURRENT_REFRESH_RATE},0x0,1"
elif [ "$SESSION_TYPE" = "X11" ]; then
xrandr --output $DISP_OUT --mode $CURRENT_RESOLUTION --rate 60
fi
sleep 5
send_notification "CS2 has closed!"