#!/bin/bash
# Tickrate overlay: server.cfg with high-rate settings + the tickrate_enabler
# addon (DLL/SO/VDF) from SirPlease/L4D2-Competitive-Rework.
# https://github.com/SirPlease/L4D2-Competitive-Rework/blob/7ecc3a32a5e2180d6607a40119ff2f3c072502a9/cfg/server.cfg#L58-L69
# https://www.programmersought.com/article/513810199514/
set -xeuo pipefail

CFG_DIR="$OVERLAY/left4dead2/cfg"
ADDONS_DIR="$OVERLAY/left4dead2/addons"
mkdir -p "$CFG_DIR" "$ADDONS_DIR"

cat <<'EOF' > "$CFG_DIR/server.cfg"
# https://github.com/SirPlease/L4D2-Competitive-Rework/blob/7ecc3a32a5e2180d6607a40119ff2f3c072502a9/cfg/server.cfg#L58-L69
sv_minrate 100000
sv_maxrate 100000
nb_update_frequency 0.014
net_splitpacket_maxrate 50000
net_maxcleartime 0.0001
fps_max 0
EOF

for file in tickrate_enabler.dll tickrate_enabler.so tickrate_enabler.vdf; do
    curl -fsSL "https://github.com/SirPlease/L4D2-Competitive-Rework/raw/refs/heads/master/addons/${file}" \
        -o "$ADDONS_DIR/${file}"
done
