#!/system/bin/sh
# ULTIMATUM v5.0 - UNIVERSAL MTK PERFORMANCE ENGINE 🐉
rm -rf /sdcard/UltimatumEngine.log
setvalue() {
    if [ -e "$1" ] && [ -w "$1" ]; then echo "$2" > "$1" 2>/dev/null; fi
}
echo "Ultimatum MTK Performance is running!"
{
stop mtk_thermal
stop thermalloadalgod
stop thermald
setvalue /proc/driver/thermal/cl_mcdi_enable 0

for cpu in /sys/devices/system/cpu/cpu[0-9]*; do
    if [ -f "$cpu/cpufreq/cpuinfo_max_freq" ]; then
        MAX_FREQ=$(cat "$cpu/cpufreq/cpuinfo_max_freq" 2>/dev/null)
        chmod 644 "$cpu/cpufreq/scaling_max_freq" 2>/dev/null
        setvalue "$cpu/cpufreq/scaling_max_freq" "$MAX_FREQ"
        chmod 644 "$cpu/cpufreq/scaling_governor" 2>/dev/null
        setvalue "$cpu/cpufreq/scaling_governor" "performance"
    fi
done

setvalue /sys/devices/system/cpu/cpufreq/mtk_cpufreq_set/core_ctl_enable 0

if [ -d /sys/class/misc/mali0/device/devfreq/mali ]; then
    setvalue /sys/class/misc/mali0/device/devfreq/mali/governor "performance"
elif [ -d /sys/devices/platform/13040000.mali ]; then
    setvalue /sys/devices/platform/13040000.mali/devfreq/13040000.mali/governor "performance"
fi

setvalue /sys/module/ged/parameters/gx_force_cpu_boost 1
setvalue /sys/module/ged/parameters/gx_game_mode 1
} 2>&1 | tee -a /sdcard/UltimatumEngine.log
