#!/system/bin/sh

# 1. Wait for system stability
while [ "$(getprop sys.boot_completed)" != "1" ]; do
    sleep 5
done
sleep 60

# 2. THE PERPETUAL ENFORCER (Hybrid Power Mode)
(
while true; do
    # Optimized VM Ratios for High-End Performance
    chmod 666 /proc/sys/vm/dirty_ratio 2>/dev/null
    echo "60" > /proc/sys/vm/dirty_ratio 2>/dev/null
    
    chmod 666 /proc/sys/vm/dirty_background_ratio 2>/dev/null
    echo "30" > /proc/sys/vm/dirty_background_ratio 2>/dev/null
    
    chmod 666 /proc/sys/vm/vfs_cache_pressure 2>/dev/null
    echo "140" > /proc/sys/vm/vfs_cache_pressure 2>/dev/null
    
    # Extra free kbytes for instant response
    chmod 666 /proc/sys/vm/extra_free_kbytes 2>/dev/null
    echo "2048" > /proc/sys/vm/extra_free_kbytes 2>/dev/null
    
    # ZRAM Speed
    chmod 666 /proc/sys/vm/page-cluster 2>/dev/null
    echo "0" > /proc/sys/vm/page-cluster 2>/dev/null
    
    sleep 10
done
) &

# 3. LMKD & PERFORMANCE PROPS
setprop ro.lmk.kill_heaviest_task true
setprop ro.lmk.enable_userspace_lmk true
setprop ro.lmk.vmpressure_loc_critical 100

# 4. EMERGENCY SYNC & FLUSH (Safety Guard)
(
while true; do
    # Commit data to disk periodically to prevent loss
    sync
    # Drop only clean caches to keep things snappy
    echo "1" > /proc/sys/vm/drop_caches
    sleep 300
done
) &

# 5. Notification
su -lp 2000 -c "cmd notification post -S bigtext -t 'Waguri-san Project' -i file:///data/local/tmp/logo_waguri.png -I file:///data/local/tmp/logo_waguri.png TagWaguri '🌸 BEAST MODE ACTIVE! Memory tiering is running at full power.'"
